Skip to content

[GlobalISel] Don't remove from unfinalized GISelWorkList #102158

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions llvm/include/llvm/CodeGen/GlobalISel/GISelChangeObserver.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ class GISelObserverWrapper : public MachineFunction::Delegate,
if (It != Observers.end())
Observers.erase(It);
}
// Removes all observers
void clearObservers() { Observers.clear(); }

// API for Observer.
void erasingInstr(MachineInstr &MI) override {
for (auto &O : Observers)
Expand Down
2 changes: 1 addition & 1 deletion llvm/include/llvm/CodeGen/GlobalISel/GISelWorkList.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ class GISelWorkList {
/// Remove I from the worklist if it exists.
void remove(const MachineInstr *I) {
#if LLVM_ENABLE_ABI_BREAKING_CHECKS
assert((Finalized || WorklistMap.empty()) && "Neither finalized nor empty");
assert(Finalized && "GISelWorkList used without finalizing");
#endif
auto It = WorklistMap.find(I);
if (It == WorklistMap.end())
Expand Down
11 changes: 6 additions & 5 deletions llvm/lib/CodeGen/GlobalISel/Combiner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,6 @@ Combiner::Combiner(MachineFunction &MF, CombinerInfo &CInfo,
if (CSEInfo)
B.setCSEInfo(CSEInfo);

// Setup observer.
ObserverWrapper->addObserver(WLObserver.get());
if (CSEInfo)
ObserverWrapper->addObserver(CSEInfo);

B.setChangeObserver(*ObserverWrapper);
}

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

WorkList.clear();
ObserverWrapper->clearObservers();
if (CSEInfo)
ObserverWrapper->addObserver(CSEInfo);

// Collect all instructions. Do a post order traversal for basic blocks and
// insert with list bottom up, so while we pop_back_val, we'll traverse top
Expand All @@ -168,6 +166,9 @@ bool Combiner::combineMachineInstrs() {
}
}
WorkList.finalize();

// Only notify WLObserver during actual combines
ObserverWrapper->addObserver(WLObserver.get());
// Main Loop. Process the instructions here.
while (!WorkList.empty()) {
MachineInstr *CurrInst = WorkList.pop_back_val();
Expand Down
Loading