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/GlobalISel/Utils.cpp | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) (limited to 'backend/lib/CodeGen/GlobalISel/Utils.cpp') 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 makeVectorType(std::uint64_t ElementCount, bool IsScalable, @@ -248,8 +245,9 @@ Expected eraseInstrs(std::span Instructions, MachineR const TargetDescription &Target) { std::vector 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 eraseInstrs(std::span 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) -- cgit v1.2.3