From 3eb34f8b7d06851cb2cb2b5ca04b411a3eecda20 Mon Sep 17 00:00:00 2001 From: Richard-Qin-X Date: Tue, 11 Aug 2026 19:05:56 +0800 Subject: [CodeGen] Revisit instructions invalidated by legalization --- backend/lib/CodeGen/MachinePipelinePasses.cpp | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) (limited to 'backend/lib/CodeGen/MachinePipelinePasses.cpp') diff --git a/backend/lib/CodeGen/MachinePipelinePasses.cpp b/backend/lib/CodeGen/MachinePipelinePasses.cpp index 9c42bdb..9bde291 100644 --- a/backend/lib/CodeGen/MachinePipelinePasses.cpp +++ b/backend/lib/CodeGen/MachinePipelinePasses.cpp @@ -352,11 +352,13 @@ Expected LegalizerPass::runImplementation(MachineFunction &Fu std::unordered_set SeenStates; std::vector Worklist = layoutInstructions(Function); - std::unordered_set DiscoveredInstructions; + std::unordered_set PendingInstructions; for (const MachineInstr *Instruction : Worklist) - DiscoveredInstructions.insert(Instruction->stableID()); + PendingInstructions.insert(Instruction->stableID()); for (std::size_t Index = 0; Index < Worklist.size(); ++Index) { MachineInstr *Instruction = Worklist[Index]; + if (Instruction != nullptr) + PendingInstructions.erase(Instruction->stableID()); if (Instruction == nullptr || Instruction->parent() == nullptr) continue; @@ -418,19 +420,16 @@ Expected LegalizerPass::runImplementation(MachineFunction &Fu Result.Changed = true; Result.Changes.add(MachinePassChange::Instructions); - if (!InstructionWasErased) { - const InstructionDescriptor *LoweredDescriptor = - Target.instructionDescriptor(Instruction->opcode()); - if (LoweredDescriptor == nullptr) - return std::unexpected( - passFailure("legalizer produced an unknown instruction descriptor")); - if (LoweredDescriptor->Flags.has(InstructionFlag::Generic)) - Worklist.push_back(Instruction); - } const std::vector Current = layoutInstructions(Function); for (MachineInstr *Candidate : Current) { - if (DiscoveredInstructions.insert(Candidate->stableID()).second) + const InstructionDescriptor *CandidateDescriptor = + Target.instructionDescriptor(Candidate->opcode()); + if (CandidateDescriptor == nullptr) + return std::unexpected(passFailure("legalizer produced an unknown instruction descriptor")); + if (CandidateDescriptor->Flags.has(InstructionFlag::Generic) && + PendingInstructions.insert(Candidate->stableID()).second) { Worklist.push_back(Candidate); + } } } -- cgit v1.2.3