Skip to content

Commit 00e5553

Browse files
author
Aditya Nandakumar
committed
[GISel][CSE][NFC]: Handle mutual recursion when inserting node
GISel's CSE mechanism lazily inserts instructions into the CSE List to improve on efficiency as well as efficacy of CSE (for allowing partially built instructions to be fully built). There's unfortunately a mutual recursion via `handleRecordedInsts -> handleRecordedInst -> insertNode-> handleRecordedInsts`. So this change simply records that we're already draining this list so we can just bail out on the recursion. No changes to codegen are expected as we're still draining/handling the temporary list via pop_back and we should get the same sequence of instructions whether we call pop_back in a loop at the top level or recursive. https://reviews.llvm.org/D145006 reviewed by: dsanders
1 parent b98c190 commit 00e5553

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

llvm/include/llvm/CodeGen/GlobalISel/CSEInfo.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,8 @@ class GISelCSEInfo : public GISelChangeObserver {
111111
/// into the CSEMap. MI should return true for shouldCSE(MI->getOpcode())
112112
void insertInstr(MachineInstr *MI, void *InsertPos = nullptr);
113113

114+
bool HandlingRecordedInstrs = false;
115+
114116
public:
115117
GISelCSEInfo() = default;
116118

llvm/lib/CodeGen/GlobalISel/CSEInfo.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,10 +217,14 @@ void GISelCSEInfo::handleRemoveInst(MachineInstr *MI) {
217217
}
218218

219219
void GISelCSEInfo::handleRecordedInsts() {
220+
if (HandlingRecordedInstrs)
221+
return;
222+
HandlingRecordedInstrs = true;
220223
while (!TemporaryInsts.empty()) {
221224
auto *MI = TemporaryInsts.pop_back_val();
222225
handleRecordedInst(MI);
223226
}
227+
HandlingRecordedInstrs = false;
224228
}
225229

226230
bool GISelCSEInfo::shouldCSE(unsigned Opc) const {

0 commit comments

Comments
 (0)