Skip to content

Commit e6162cf

Browse files
committed
[MachineBasicBlock] Fix SlotIndexUpdater for insertion order
Follow up fix for llvm#68786 to address that MachineFunction handleInsertion is actually called before a new instruction has been inserted into the block. Hence new instructions must be recorded and SlotIndex updates performed after the delegate call.
1 parent ed1d290 commit e6162cf

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

llvm/lib/CodeGen/MachineBasicBlock.cpp

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1101,22 +1101,31 @@ class SlotIndexUpdateDelegate : public MachineFunction::Delegate {
11011101
private:
11021102
MachineFunction &MF;
11031103
SlotIndexes *Indexes;
1104+
SmallSetVector<MachineInstr *, 2> Insertions;
11041105

11051106
public:
11061107
SlotIndexUpdateDelegate(MachineFunction &MF, SlotIndexes *Indexes)
11071108
: MF(MF), Indexes(Indexes) {
11081109
MF.setDelegate(this);
11091110
}
11101111

1111-
~SlotIndexUpdateDelegate() { MF.resetDelegate(this); }
1112+
~SlotIndexUpdateDelegate() {
1113+
MF.resetDelegate(this);
1114+
if (Indexes) {
1115+
for (auto MI : Insertions)
1116+
Indexes->insertMachineInstrInMaps(*MI);
1117+
}
1118+
}
11121119

11131120
void MF_HandleInsertion(MachineInstr &MI) override {
1114-
if (Indexes)
1115-
Indexes->insertMachineInstrInMaps(MI);
1121+
// This is called before MI is inserted into block so defer index update.
1122+
Insertions.insert(&MI);
11161123
}
11171124

11181125
void MF_HandleRemoval(MachineInstr &MI) override {
1119-
if (Indexes)
1126+
if (Insertions.count(&MI))
1127+
Insertions.remove(&MI);
1128+
else if (Indexes)
11201129
Indexes->removeMachineInstrFromMaps(MI);
11211130
}
11221131
};

0 commit comments

Comments
 (0)