From f5d9ddc085055d28d6f9fb3730c3566097f43fb2 Mon Sep 17 00:00:00 2001 From: Richard-Qin-X Date: Tue, 25 Aug 2026 03:11:23 +0800 Subject: [CodeGen] Implement the greedy register allocator pipeline --- backend/lib/CodeGen/RegAllocBasic.cpp | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) (limited to 'backend/lib/CodeGen/RegAllocBasic.cpp') diff --git a/backend/lib/CodeGen/RegAllocBasic.cpp b/backend/lib/CodeGen/RegAllocBasic.cpp index c3ed98b..2e2222f 100644 --- a/backend/lib/CodeGen/RegAllocBasic.cpp +++ b/backend/lib/CodeGen/RegAllocBasic.cpp @@ -78,10 +78,11 @@ private: .Requires = {MachineFunctionProperty::Selected, MachineFunctionProperty::NoPHIs, MachineFunctionProperty::TiedOpsRewritten, MachineFunctionProperty::TracksLiveness}, - .Sets = {MachineFunctionProperty::NoVRegs}, - .Clears = {}, - .RequiredAnalyses = {MachineFunctionAnalysisManager::id()}, - .VerificationStage = PipelineStage::RegisterAllocated, + .Sets = {}, + .Clears = {MachineFunctionProperty::IsSSA}, + .RequiredAnalyses = {MachineFunctionAnalysisManager::id(), + MachineFunctionAnalysisManager::id()}, + .VerificationStage = std::nullopt, }; Value.ThreadSafety = PassThreadSafety::ThreadSafe; return Value; @@ -118,7 +119,8 @@ Expected BasicAllocatorPass::run(MachineFunction &Function, return std::unexpected(Registered.error()); BasicAllocatorEngine TrialAllocator(*Trial->ClonedFunction, Target, *Info, TrialAnalyses, Options); - auto TrialRun = TrialAllocator.run(); + VirtRegMap TrialMapping(*Trial->ClonedFunction); + auto TrialRun = TrialAllocator.run(TrialMapping); if (!TrialRun) return std::unexpected(TrialRun.error()); auto TrialVerification = @@ -126,7 +128,10 @@ Expected BasicAllocatorPass::run(MachineFunction &Function, if (!TrialVerification) return std::unexpected(TrialVerification.error()); BasicAllocatorEngine Allocator(Function, Target, *Info, Analyses, Options); - auto Allocated = Allocator.run(); + auto Mapping = Analyses.getResult(Function, Target); + if (!Mapping) + return std::unexpected(Mapping.error()); + auto Allocated = Allocator.run(**Mapping); if (!Allocated) { return std::unexpected(withErrorContext( Allocated.error(), "BasicAllocator diverged after a successful transaction preflight: ")); @@ -135,7 +140,9 @@ Expected BasicAllocatorPass::run(MachineFunction &Function, if (!Reserved) return std::unexpected(Reserved.error()); Allocated->Changed |= *Reserved; - return regalloc_detail::passResult(*Allocated); + MachinePassResult Result = regalloc_detail::passResult(*Allocated); + Result.Preserved.preserve(); + return Result; } std::unique_ptr -- cgit v1.2.3