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/Target/RISCV/RISCVInstrInfo.cpp | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) (limited to 'backend/lib/Target/RISCV/RISCVInstrInfo.cpp') diff --git a/backend/lib/Target/RISCV/RISCVInstrInfo.cpp b/backend/lib/Target/RISCV/RISCVInstrInfo.cpp index 11387c1..6e356a6 100644 --- a/backend/lib/Target/RISCV/RISCVInstrInfo.cpp +++ b/backend/lib/Target/RISCV/RISCVInstrInfo.cpp @@ -218,15 +218,6 @@ constexpr std::uint32_t PCRelativeLowFlag = 4; return Operand->setBasicBlock(TargetBlock); } -[[nodiscard]] Expected removeInstruction(MachineInstr &Instruction) { - MachineBasicBlock *Block = Instruction.parent(); - if (Block == nullptr) { - return makeUnexpected(ErrorCode::InvalidArgument, - "RISC-V branch instruction is not linked to a block"); - } - return Block->removeInstruction(Instruction); -} - [[nodiscard]] Expected buildJAL(MachineFunction &Function, const TargetDescription &Target, MachineBasicBlock &Block, MachineInstr *Before, PhysicalRegister Destination, MachineBasicBlock &TargetBlock) { @@ -380,7 +371,7 @@ selectLongBranchScratch(const MachineInstr &Instruction, const MachineBasicBlock auto Annotations = copySingleInstructionAnnotations(Instruction, **Replacement); if (!Annotations) return std::unexpected(Annotations.error()); - auto Removed = removeInstruction(Instruction); + auto Removed = Instruction.eraseFromParent(); if (!Removed) return std::unexpected(Removed.error()); return true; @@ -415,7 +406,7 @@ selectLongBranchScratch(const MachineInstr &Instruction, const MachineBasicBlock auto Annotations = copySingleInstructionAnnotations(Instruction, **Replacement); if (!Annotations) return std::unexpected(Annotations.error()); - auto Removed = removeInstruction(Instruction); + auto Removed = Instruction.eraseFromParent(); if (!Removed) return std::unexpected(Removed.error()); return true; @@ -436,7 +427,7 @@ selectLongBranchScratch(const MachineInstr &Instruction, const MachineBasicBlock if (!FalseTarget) return std::unexpected(FalseTarget.error()); if (*FalseTarget == *TrueTarget) { - auto Removed = removeInstruction(Instruction); + auto Removed = Instruction.eraseFromParent(); if (!Removed) return std::unexpected(Removed.error()); return true; @@ -589,7 +580,7 @@ selectLongBranchScratch(const MachineInstr &Instruction, const MachineBasicBlock LowFlags.clear(MachineInstrFlag::BundledWithPred); LowFlags.set(MachineInstrFlag::BundledWithPred); (*Low)->setFlags(LowFlags); - auto Removed = removeInstruction(Instruction); + auto Removed = Instruction.eraseFromParent(); if (!Removed) return std::unexpected(Removed.error()); return true; @@ -798,7 +789,7 @@ public: if (&Branch.function() != &Function) return makeUnexpected(ErrorCode::InvalidArgument, "RISC-V branch removal references another function"); - return removeInstruction(Branch); + return Branch.eraseFromParent(); } [[nodiscard]] Expected rewriteBranchTarget(MachineBasicBlock &Block, -- cgit v1.2.3