From e72ad2cd524ff38f162a23d69da5f78494d337ae Mon Sep 17 00:00:00 2001 From: Richard-Qin-X Date: Fri, 28 Aug 2026 13:45:07 +0800 Subject: [CodeGen] Centralize machine instruction erasure --- backend/lib/CodeGen/TwoAddressInstructionPass.cpp | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) (limited to 'backend/lib/CodeGen/TwoAddressInstructionPass.cpp') diff --git a/backend/lib/CodeGen/TwoAddressInstructionPass.cpp b/backend/lib/CodeGen/TwoAddressInstructionPass.cpp index 80da2e8..d7a5ef1 100644 --- a/backend/lib/CodeGen/TwoAddressInstructionPass.cpp +++ b/backend/lib/CodeGen/TwoAddressInstructionPass.cpp @@ -175,13 +175,6 @@ buildImplicitDef(MachineFunction &Function, const TargetDescription &Target, return *Composed; } -[[nodiscard]] Expected removeInstruction(MachineInstr &Instruction) { - MachineBasicBlock *Block = Instruction.parent(); - if (Block == nullptr) - return makeUnexpected(ErrorCode::InternalError, "rewritten instruction is not linked"); - return Block->removeInstruction(Instruction); -} - [[nodiscard]] Expected expandRegSequence(MachineInstr &Instruction, MachineFunction &Function, const TargetDescription &Target, const TargetInstrInfo &TargetInfo) { @@ -240,7 +233,7 @@ buildImplicitDef(MachineFunction &Function, const TargetDescription &Target, if (!Copy) return std::unexpected(Copy.error()); } - return removeInstruction(Instruction); + return Instruction.eraseFromParent(); } [[nodiscard]] Expected expandInsertSubreg(MachineInstr &Instruction, @@ -309,7 +302,7 @@ buildImplicitDef(MachineFunction &Function, const TargetDescription &Target, if (!Copy) return std::unexpected(Copy.error()); } - return removeInstruction(Instruction); + return Instruction.eraseFromParent(); } [[nodiscard]] Expected swapRegisterUses(MachineOperand &Left, MachineOperand &Right) { @@ -450,9 +443,10 @@ TwoAddressInstructionPass::run(MachineFunction &Function, const TargetDescriptio return runImplementation(Function, Target, Analyses); } -Expected TwoAddressInstructionPass::runImplementation( - MachineFunction &Function, const TargetDescription &Target, - MachineFunctionAnalysisManager &Analyses) { +Expected +TwoAddressInstructionPass::runImplementation(MachineFunction &Function, + const TargetDescription &Target, + MachineFunctionAnalysisManager &Analyses) { MachinePassResult Result; const std::vector Instructions(Function.allInstructions().begin(), Function.allInstructions().end()); -- cgit v1.2.3