aboutsummaryrefslogtreecommitdiff
path: root/backend/lib/Target/RISCV/RISCVFinalizeISel.cpp
diff options
context:
space:
mode:
authorRichard-Qin-X <richard.qin.001@gmail.com>2026-08-28 13:45:07 +0800
committerRichard-Qin-X <richard.qin.001@gmail.com>2026-08-28 13:45:07 +0800
commite72ad2cd524ff38f162a23d69da5f78494d337ae (patch)
tree2e590806b0f610e4392f25f6e8cdff57d2f5a929 /backend/lib/Target/RISCV/RISCVFinalizeISel.cpp
parent3b14bd4d5324b5a280c1ee5567b5526b59e60c5b (diff)
downloadrcc-project-e72ad2cd524ff38f162a23d69da5f78494d337ae.tar.gz
rcc-project-e72ad2cd524ff38f162a23d69da5f78494d337ae.tar.xz
[CodeGen] Centralize machine instruction erasure
Diffstat (limited to 'backend/lib/Target/RISCV/RISCVFinalizeISel.cpp')
-rw-r--r--backend/lib/Target/RISCV/RISCVFinalizeISel.cpp18
1 files changed, 4 insertions, 14 deletions
diff --git a/backend/lib/Target/RISCV/RISCVFinalizeISel.cpp b/backend/lib/Target/RISCV/RISCVFinalizeISel.cpp
index 784490d..e2d99b3 100644
--- a/backend/lib/Target/RISCV/RISCVFinalizeISel.cpp
+++ b/backend/lib/Target/RISCV/RISCVFinalizeISel.cpp
@@ -254,10 +254,7 @@ buildPhi(MachineFunction &Function, const TargetDescription &Target, MachineBasi
[[nodiscard]] Expected<void> moveInstructionToEnd(MachineInstr &Instruction,
MachineBasicBlock &Destination) {
- MachineBasicBlock *Source = Instruction.parent();
- if (Source == nullptr)
- return makeUnexpected(ErrorCode::InternalError, "moved instruction is detached");
- if (auto Removed = Source->removeInstruction(Instruction); !Removed)
+ if (auto Removed = Instruction.eraseFromParent(); !Removed)
return std::unexpected(Removed.error());
return Destination.appendInstruction(Instruction);
}
@@ -326,11 +323,7 @@ buildPhi(MachineFunction &Function, const TargetDescription &Target, MachineBasi
return std::unexpected(Phi.error());
}
for (MachineInstr *Select : Sequence->Selects) {
- MachineBasicBlock *Parent = Select->parent();
- if (Parent == nullptr)
- return makeUnexpected(ErrorCode::InternalError,
- "RISC-V custom select became detached during expansion");
- if (auto Removed = Parent->removeInstruction(*Select); !Removed)
+ if (auto Removed = Select->eraseFromParent(); !Removed)
return std::unexpected(Removed.error());
}
Function.properties().clear(MachineFunctionProperty::NoPHIs);
@@ -468,12 +461,9 @@ emitCascadedSelect(MachineInstr &First, MachineInstr &Second, MachineBasicBlock
if (!Phi)
return std::unexpected(Phi.error());
- if (auto Removed = Head.removeInstruction(First); !Removed)
+ if (auto Removed = First.eraseFromParent(); !Removed)
return std::unexpected(Removed.error());
- MachineBasicBlock *SecondParent = Second.parent();
- if (SecondParent == nullptr)
- return makeUnexpected(ErrorCode::InternalError, "cascaded select became detached");
- if (auto Removed = SecondParent->removeInstruction(Second); !Removed)
+ if (auto Removed = Second.eraseFromParent(); !Removed)
return std::unexpected(Removed.error());
Function.properties().clear(MachineFunctionProperty::NoPHIs);
return Sink;