Skip to content

Commit 65c7213

Browse files
[GlobalISel] Don't remove from unfinalized GISelWorkList
Remove a hack from GISelWorkList caused by the Combiner removing instructions from an unfinalized GISelWorkList during the DCE phase. This is in preparation for larger changes to the WorkListMaintainer. Pull Request: #102158
1 parent fe59b84 commit 65c7213

File tree

3 files changed

+10
-6
lines changed

3 files changed

+10
-6
lines changed

llvm/include/llvm/CodeGen/GlobalISel/GISelChangeObserver.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,9 @@ class GISelObserverWrapper : public MachineFunction::Delegate,
7979
if (It != Observers.end())
8080
Observers.erase(It);
8181
}
82+
// Removes all observers
83+
void clearObservers() { Observers.clear(); }
84+
8285
// API for Observer.
8386
void erasingInstr(MachineInstr &MI) override {
8487
for (auto &O : Observers)

llvm/include/llvm/CodeGen/GlobalISel/GISelWorkList.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ class GISelWorkList {
8282
/// Remove I from the worklist if it exists.
8383
void remove(const MachineInstr *I) {
8484
#if LLVM_ENABLE_ABI_BREAKING_CHECKS
85-
assert((Finalized || WorklistMap.empty()) && "Neither finalized nor empty");
85+
assert(Finalized && "GISelWorkList used without finalizing");
8686
#endif
8787
auto It = WorklistMap.find(I);
8888
if (It == WorklistMap.end())

llvm/lib/CodeGen/GlobalISel/Combiner.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -110,11 +110,6 @@ Combiner::Combiner(MachineFunction &MF, CombinerInfo &CInfo,
110110
if (CSEInfo)
111111
B.setCSEInfo(CSEInfo);
112112

113-
// Setup observer.
114-
ObserverWrapper->addObserver(WLObserver.get());
115-
if (CSEInfo)
116-
ObserverWrapper->addObserver(CSEInfo);
117-
118113
B.setChangeObserver(*ObserverWrapper);
119114
}
120115

@@ -147,6 +142,9 @@ bool Combiner::combineMachineInstrs() {
147142
LLVM_DEBUG(dbgs() << "\n\nCombiner iteration #" << Iteration << '\n');
148143

149144
WorkList.clear();
145+
ObserverWrapper->clearObservers();
146+
if (CSEInfo)
147+
ObserverWrapper->addObserver(CSEInfo);
150148

151149
// Collect all instructions. Do a post order traversal for basic blocks and
152150
// insert with list bottom up, so while we pop_back_val, we'll traverse top
@@ -168,6 +166,9 @@ bool Combiner::combineMachineInstrs() {
168166
}
169167
}
170168
WorkList.finalize();
169+
170+
// Only notify WLObserver during actual combines
171+
ObserverWrapper->addObserver(WLObserver.get());
171172
// Main Loop. Process the instructions here.
172173
while (!WorkList.empty()) {
173174
MachineInstr *CurrInst = WorkList.pop_back_val();

0 commit comments

Comments
 (0)