[llvm] 386f390 - [MachineBasicBlock] Fix SlotIndexUpdater for insertion order (#69424)
via llvm-commits
llvm-commits at lists.llvm.org
Sat Oct 21 00:31:23 PDT 2023
Author: Carl Ritson
Date: 2023-10-21T16:31:19+09:00
New Revision: 386f3903910aa1897c424ced8e1af7993a6df5ce
URL: https://github.com/llvm/llvm-project/commit/386f3903910aa1897c424ced8e1af7993a6df5ce
DIFF: https://github.com/llvm/llvm-project/commit/386f3903910aa1897c424ced8e1af7993a6df5ce.diff
LOG: [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.
Added:
Modified:
llvm/lib/CodeGen/MachineBasicBlock.cpp
Removed:
################################################################################
diff --git a/llvm/lib/CodeGen/MachineBasicBlock.cpp b/llvm/lib/CodeGen/MachineBasicBlock.cpp
index 14d9bb292ddf2e8..5f9e4a66c0d22ed 100644
--- a/llvm/lib/CodeGen/MachineBasicBlock.cpp
+++ b/llvm/lib/CodeGen/MachineBasicBlock.cpp
@@ -1101,6 +1101,7 @@ class SlotIndexUpdateDelegate : public MachineFunction::Delegate {
private:
MachineFunction &MF;
SlotIndexes *Indexes;
+ SmallSetVector<MachineInstr *, 2> Insertions;
public:
SlotIndexUpdateDelegate(MachineFunction &MF, SlotIndexes *Indexes)
@@ -1108,15 +1109,20 @@ class SlotIndexUpdateDelegate : public MachineFunction::Delegate {
MF.setDelegate(this);
}
- ~SlotIndexUpdateDelegate() { MF.resetDelegate(this); }
+ ~SlotIndexUpdateDelegate() {
+ MF.resetDelegate(this);
+ for (auto MI : Insertions)
+ Indexes->insertMachineInstrInMaps(*MI);
+ }
void MF_HandleInsertion(MachineInstr &MI) override {
+ // This is called before MI is inserted into block so defer index update.
if (Indexes)
- Indexes->insertMachineInstrInMaps(MI);
+ Insertions.insert(&MI);
}
void MF_HandleRemoval(MachineInstr &MI) override {
- if (Indexes)
+ if (Indexes && !Insertions.remove(&MI))
Indexes->removeMachineInstrFromMaps(MI);
}
};
More information about the llvm-commits
mailing list