llvm.org GIT mirror llvm / abbac34
[globalisel] Rename GISelChangeObserver's erasedInstr() to erasingInstr() and related nits. NFC Summary: There's little of interest that can be done to an already-erased instruction. You can't inspect it, write it to a debug log, etc. It ought to be notification that we're about to erase it. Rename the function to clarify the timing of the event and reflect current usage. Also fixed one case where we were trying to print an erased instruction. Reviewers: aditya_nandakumar Reviewed By: aditya_nandakumar Subscribers: rovka, kristof.beyls, llvm-commits Differential Revision: https://reviews.llvm.org/D55611 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@348976 91177308-0d34-0410-b5e6-96231b3b80d8 Daniel Sanders 1 year, 10 months ago
6 changed file(s) with 11 addition(s) and 14 deletion(s). Raw diff Collapse all Expand all
2929 MachineRegisterInfo &MRI;
3030 GISelChangeObserver &Observer;
3131
32 void eraseInstr(MachineInstr &MI);
3332 void scheduleForVisit(MachineInstr &MI);
3433
3534 public:
1717 namespace llvm {
1818 /// Abstract class that contains various methods for clients to notify about
1919 /// changes. This should be the preferred way for APIs to notify changes.
20 /// Typically calling erasedInstr/createdInstr multiple times should not affect
20 /// Typically calling erasingInstr/createdInstr multiple times should not affect
2121 /// the result. The observer would likely need to check if it was already
2222 /// notified earlier (consider using GISelWorkList).
2323 class MachineInstr;
2525 public:
2626 virtual ~GISelChangeObserver() {}
2727
28 /// An instruction was erased.
29 virtual void erasedInstr(MachineInstr &MI) = 0;
28 /// An instruction is about to be erased.
29 virtual void erasingInstr(MachineInstr &MI) = 0;
3030 /// An instruction was created and inserted into the function.
3131 virtual void createdInstr(MachineInstr &MI) = 0;
3232 /// This instruction was mutated in some way.
4242 WorkListMaintainer(WorkListTy &WorkList) : WorkList(WorkList) {}
4343 virtual ~WorkListMaintainer() {}
4444
45 void erasedInstr(MachineInstr &MI) override {
45 void erasingInstr(MachineInstr &MI) override {
4646 LLVM_DEBUG(dbgs() << "Erased: "; MI.print(dbgs()); dbgs() << "\n");
4747 WorkList.remove(&MI);
4848 }
2222 MachineIRBuilder &B)
2323 : Builder(B), MRI(Builder.getMF().getRegInfo()), Observer(Observer) {}
2424
25 void CombinerHelper::eraseInstr(MachineInstr &MI) {
26 Observer.erasedInstr(MI);
27 }
2825 void CombinerHelper::scheduleForVisit(MachineInstr &MI) {
2926 Observer.createdInstr(MI);
3027 }
298295 Observer.createdInstr(*NewMI);
299296 }
300297 for (auto &EraseMI : ScheduleForErase) {
298 Observer.erasingInstr(*EraseMI);
301299 EraseMI->eraseFromParent();
302 Observer.erasedInstr(*EraseMI);
303300 }
304301 MI.getOperand(0).setReg(ChosenDstReg);
305302
9393 LLVM_DEBUG(dbgs() << ".. .. New MI: " << MI;);
9494 }
9595
96 void erasedInstr(MachineInstr &MI) override {
96 void erasingInstr(MachineInstr &MI) override {
97 LLVM_DEBUG(dbgs() << ".. .. Erasing: " << MI;);
9798 InstList.remove(&MI);
9899 ArtifactList.remove(&MI);
99100 }
145146 const LegalizerInfo &LInfo(Helper.getLegalizerInfo());
146147 LegalizationArtifactCombiner ArtCombiner(Helper.MIRBuilder, MF.getRegInfo(), LInfo);
147148 auto RemoveDeadInstFromLists = [&WorkListObserver](MachineInstr *DeadMI) {
148 WorkListObserver.erasedInstr(*DeadMI);
149 WorkListObserver.erasingInstr(*DeadMI);
149150 };
150151 bool Changed = false;
151152 do {
174175 MachineInstr &MI = *ArtifactList.pop_back_val();
175176 assert(isPreISelGenericOpcode(MI.getOpcode()) && "Expecting generic opcode");
176177 if (isTriviallyDead(MI, MRI)) {
177 LLVM_DEBUG(dbgs() << MI << "Is dead; erasing.\n");
178 LLVM_DEBUG(dbgs() << MI << "Is dead\n");
178179 RemoveDeadInstFromLists(&MI);
179180 MI.eraseFromParentAndMarkDBGValuesForRemoval();
180181 continue;
182183 SmallVector DeadInstructions;
183184 if (ArtCombiner.tryCombineInstruction(MI, DeadInstructions)) {
184185 for (auto *DeadMI : DeadInstructions) {
185 LLVM_DEBUG(dbgs() << ".. Erasing Dead Instruction " << *DeadMI);
186 LLVM_DEBUG(dbgs() << *DeadMI << "Is dead\n");
186187 RemoveDeadInstFromLists(DeadMI);
187188 DeadMI->eraseFromParentAndMarkDBGValuesForRemoval();
188189 }
1414 public:
1515 void changedInstr(MachineInstr &MI) override {}
1616 void createdInstr(MachineInstr &MI) override {}
17 void erasedInstr(MachineInstr &MI) override {}
17 void erasingInstr(MachineInstr &MI) override {}
1818 };
1919
2020 // Test CTTZ expansion when CTTZ_ZERO_UNDEF is legal or custom,