[llvm] [RFC][GlobalISel] InstructionSelect: Allow arbitrary instruction erasure (PR #97670)

Amara Emerson via llvm-commits llvm-commits at lists.llvm.org
Mon Jul 8 15:01:02 PDT 2024


================
@@ -62,6 +64,52 @@ INITIALIZE_PASS_END(InstructionSelect, DEBUG_TYPE,
                     "Select target instructions out of generic instructions",
                     false, false)
 
+/// This class observes instruction insertions/removals.
+/// InstructionSelect stores an iterator of the instruction prior to the one
+/// that is currently being selected to determine which instruction to select
+/// next. Previously this meant that selecting multiple instructions at once was
+/// illegal behavior due to potential invalidation of this iterator. This is
+/// a non-obvious limitation for selector implementers. Therefore, to allow
+/// deletion of arbitrary instructions, we detect this case and continue
+/// selection with the predecessor of the deleted instruction.
+class InstructionSelect::MIIteratorMaintainer
+    : public MachineFunction::Delegate {
+#ifndef NDEBUG
+  SetVector<const MachineInstr *> CreatedInstrs;
----------------
aemerson wrote:

`SetVector` has a max static size of 32, which I think we should use here to reduce the chance of heap allocations.

https://github.com/llvm/llvm-project/pull/97670


More information about the llvm-commits mailing list