From 8553df97bbc6154dae9d0ad861857e71a0efa420 Mon Sep 17 00:00:00 2001 From: Richard-Qin-X Date: Sat, 1 Aug 2026 13:09:30 +0800 Subject: [CodeGen] Add transactional MachineIR builder Validate insertion cursors, operand ownership, descriptor constraints, ties, implicit registers, and memory operands before allocating or publishing an instruction. Share instruction legality checks with the verifier path and preserve deterministic insertion order. --- .../include/rcc/CodeGen/InstructionDescriptor.h | 26 ++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'backend/include/rcc/CodeGen/InstructionDescriptor.h') diff --git a/backend/include/rcc/CodeGen/InstructionDescriptor.h b/backend/include/rcc/CodeGen/InstructionDescriptor.h index c6049b9..94ea374 100644 --- a/backend/include/rcc/CodeGen/InstructionDescriptor.h +++ b/backend/include/rcc/CodeGen/InstructionDescriptor.h @@ -23,6 +23,7 @@ namespace rcc { class MachineInstr; +class MachineMemOperand; class MachineRegisterInfo; class OperandKindSet final { @@ -217,6 +218,13 @@ struct ImmediatePredicate final { std::function Predicate; }; +struct MachineOperandTie final { + std::size_t DefOperand; + std::size_t UseOperand; + + friend bool operator==(MachineOperandTie Left, MachineOperandTie Right) noexcept = default; +}; + class InstructionSet final { public: [[nodiscard]] static Expected @@ -232,6 +240,15 @@ public: [[nodiscard]] Expected validateExplicitOperands(Opcode InstructionOpcode, std::span Operands, const MachineRegisterInfo &RegInfo) const; + [[nodiscard]] Expected validateOperandTies(Opcode InstructionOpcode, + std::span ExplicitOperands, + std::span Ties) const; + [[nodiscard]] Expected + validateImplicitOperands(Opcode InstructionOpcode, + std::span ImplicitOperands) const; + [[nodiscard]] Expected + validateMemOperands(Opcode InstructionOpcode, + std::span MemOperands) const; [[nodiscard]] Expected validateInstruction(const MachineInstr &Instruction, const MachineRegisterInfo &RegInfo) const; @@ -248,6 +265,15 @@ private: [[nodiscard]] Expected validateExplicitOperands(const InstructionDescriptor &Descriptor, std::span Operands, const MachineRegisterInfo &RegInfo) const; + [[nodiscard]] Expected validateOperandTies(const InstructionDescriptor &Descriptor, + std::span ExplicitOperands, + std::span Ties) const; + [[nodiscard]] Expected + validateImplicitOperands(const InstructionDescriptor &Descriptor, + std::span ImplicitOperands) const; + [[nodiscard]] Expected + validateMemOperands(const InstructionDescriptor &Descriptor, + std::span MemOperands) const; [[nodiscard]] Expected validateOperand(const OperandDescriptor &Descriptor, const MachineOperand &Operand, const MachineRegisterInfo &RegInfo) const; -- cgit v1.2.3