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/CodeGen/GlobalISel/Utils.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/CodeGen/GlobalISel/Utils.cpp')
| -rw-r--r-- | backend/lib/CodeGen/GlobalISel/Utils.cpp | 13 |
1 files changed, 5 insertions, 8 deletions
diff --git a/backend/lib/CodeGen/GlobalISel/Utils.cpp b/backend/lib/CodeGen/GlobalISel/Utils.cpp index 7e594ce..0f8d638 100644 --- a/backend/lib/CodeGen/GlobalISel/Utils.cpp +++ b/backend/lib/CodeGen/GlobalISel/Utils.cpp @@ -65,10 +65,7 @@ namespace { if (Definition != nullptr && Definition != &Instruction) DeadChain.push_back(Definition); } - MachineBasicBlock *Block = Instruction.parent(); - if (Block == nullptr) - return {}; - return Block->removeInstruction(Instruction); + return Instruction.eraseFromParent(); } [[nodiscard]] Expected<LowLevelType> makeVectorType(std::uint64_t ElementCount, bool IsScalable, @@ -248,8 +245,9 @@ Expected<void> eraseInstrs(std::span<MachineInstr *const> Instructions, MachineR const TargetDescription &Target) { std::vector<MachineInstr *> DeadChain; for (MachineInstr *Instruction : Instructions) { - if (Instruction == nullptr || Instruction->parent() == nullptr) - continue; + if (Instruction == nullptr) + return makeUnexpected(ErrorCode::InvalidArgument, + "instruction erasure list contains a null instruction"); auto Removed = saveUsesAndErase(*Instruction, MRI, DeadChain); if (!Removed) return std::unexpected(Removed.error()); @@ -258,8 +256,7 @@ Expected<void> eraseInstrs(std::span<MachineInstr *const> Instructions, MachineR while (!DeadChain.empty()) { MachineInstr *Instruction = DeadChain.back(); DeadChain.pop_back(); - if (Instruction == nullptr || Instruction->parent() == nullptr || - !isTriviallyDead(*Instruction, MRI, Target)) + if (Instruction->parent() == nullptr || !isTriviallyDead(*Instruction, MRI, Target)) continue; auto Removed = saveUsesAndErase(*Instruction, MRI, DeadChain); if (!Removed) |
