diff options
author | Carl Ritson <carl.ritson@amd.com> | 2023-10-21 16:31:19 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-10-21 16:31:19 +0900 |
commit | 386f3903910aa1897c424ced8e1af7993a6df5ce (patch) | |
tree | 13e193b7c2d9273f897b8db726252b7e74c26383 /llvm/lib/CodeGen/MachineBasicBlock.cpp | |
parent | af447dde5e723e925b9c8fdc6715b07f0caf6161 (diff) | |
download | llvm-386f3903910aa1897c424ced8e1af7993a6df5ce.zip llvm-386f3903910aa1897c424ced8e1af7993a6df5ce.tar.gz llvm-386f3903910aa1897c424ced8e1af7993a6df5ce.tar.bz2 |
[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.
Diffstat (limited to 'llvm/lib/CodeGen/MachineBasicBlock.cpp')
-rw-r--r-- | llvm/lib/CodeGen/MachineBasicBlock.cpp | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/llvm/lib/CodeGen/MachineBasicBlock.cpp b/llvm/lib/CodeGen/MachineBasicBlock.cpp index 14d9bb29..5f9e4a6 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 @@ public: 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); } }; |