diff options
| author | Richard-Qin-X <richard.qin.001@gmail.com> | 2026-08-28 13:45:07 +0800 |
|---|---|---|
| committer | Richard-Qin-X <richard.qin.001@gmail.com> | 2026-08-28 13:45:07 +0800 |
| commit | e72ad2cd524ff38f162a23d69da5f78494d337ae (patch) | |
| tree | 2e590806b0f610e4392f25f6e8cdff57d2f5a929 /backend/lib/Target/RISCV/RISCVInstrInfo.cpp | |
| parent | 3b14bd4d5324b5a280c1ee5567b5526b59e60c5b (diff) | |
| download | rcc-project-e72ad2cd524ff38f162a23d69da5f78494d337ae.tar.gz rcc-project-e72ad2cd524ff38f162a23d69da5f78494d337ae.tar.xz | |
[CodeGen] Centralize machine instruction erasure
Diffstat (limited to 'backend/lib/Target/RISCV/RISCVInstrInfo.cpp')
| -rw-r--r-- | backend/lib/Target/RISCV/RISCVInstrInfo.cpp | 19 |
1 files changed, 5 insertions, 14 deletions
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<void> 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<MachineInstr *> 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<bool> rewriteBranchTarget(MachineBasicBlock &Block, |
