[llvm] [CodeGen] Move rollback capabilities outside of the rematerializer (PR #184341)
Quentin Colombet via llvm-commits
llvm-commits at lists.llvm.org
Wed Apr 1 16:55:04 PDT 2026
================
@@ -520,12 +499,50 @@ class Rematerializer {
/// Deletes rematerializable register \p RegIdx from the DAG and relevant
/// internal state.
void deleteReg(RegisterIdx RegIdx);
+};
- /// If \p MI's first operand defines a register and that register is a
- /// rematerializable register tracked by the rematerializer, returns its
- /// index in the \ref Regs vector. Otherwise returns \ref
- /// Rematerializer::NoReg.
- RegisterIdx getDefRegIdx(const MachineInstr &MI) const;
+/// Rematerializer listener with the ability to re-create deleted registers and
+/// rollback rematerializations. Starts recording register deletions and
+/// rematerializations as soon as it is attached to the rematerializer.
+class Rollbacker : public Rematerializer::Listener {
+public:
+ Rollbacker() = default;
+
+ /// Re-creates all deleted registers and rolls back all rematerializations
+ /// that were recorded.
+ void rollback(Rematerializer &Remater);
+
+ void rematerializerNoteRegCreated(const Rematerializer &Remater,
+ RegisterIdx RegIdx) override;
+
+ void rematerializerNoteRegDeleted(const Rematerializer &Remater,
+ RegisterIdx RegIdx) override;
+
+private:
+ struct RollbackInfo {
+ /// Original register.
+ Register DefReg;
+ /// Original defining region.
+ unsigned DefRegion;
+ /// Original dependencies.
+ SmallVector<Rematerializer::Reg::Dependency, 2> Dependencies;
+ /// Position to re-insert the defining MI before in case of rollback.
+ MachineBasicBlock::iterator InsertPos;
----------------
qcolombet wrote:
How do you make sure that the insertion point remains valid as you rematerialize things around?
https://github.com/llvm/llvm-project/pull/184341
More information about the llvm-commits
mailing list