Skip to content

Commit 386f390

Browse files
authored
[MachineBasicBlock] Fix SlotIndexUpdater for insertion order (#69424)
Follow up fix for #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 af447dd commit 386f390

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

llvm/lib/CodeGen/MachineBasicBlock.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1101,22 +1101,28 @@ 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+
for (auto MI : Insertions)
1115+
Indexes->insertMachineInstrInMaps(*MI);
1116+
}
11121117

11131118
void MF_HandleInsertion(MachineInstr &MI) override {
1119+
// This is called before MI is inserted into block so defer index update.
11141120
if (Indexes)
1115-
Indexes->insertMachineInstrInMaps(MI);
1121+
Insertions.insert(&MI);
11161122
}
11171123

11181124
void MF_HandleRemoval(MachineInstr &MI) override {
1119-
if (Indexes)
1125+
if (Indexes && !Insertions.remove(&MI))
11201126
Indexes->removeMachineInstrFromMaps(MI);
11211127
}
11221128
};

0 commit comments

Comments
 (0)