From da8bc76b4bf7d1a7b025d6c8ef5809551467dcc7 Mon Sep 17 00:00:00 2001 From: Richard-Qin-X Date: Sun, 9 Aug 2026 13:23:48 +0800 Subject: [CodeGen] Implement RV64GC frame lowering --- backend/lib/CodeGen/RegAllocFast.cpp | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'backend/lib/CodeGen/RegAllocFast.cpp') diff --git a/backend/lib/CodeGen/RegAllocFast.cpp b/backend/lib/CodeGen/RegAllocFast.cpp index 9b087cc..897f217 100644 --- a/backend/lib/CodeGen/RegAllocFast.cpp +++ b/backend/lib/CodeGen/RegAllocFast.cpp @@ -266,7 +266,7 @@ private: return std::unexpected(Evicted.error()); } - auto Candidates = regalloc_detail::allocationOrder(Function, Target, Reg); + auto Candidates = regalloc_detail::allocationOrder(Function, Target, TargetInfo, Reg); if (!Candidates) return std::unexpected(Candidates.error()); for (const PhysicalRegister Candidate : *Candidates) { @@ -319,7 +319,7 @@ private: const Register Reg = *LiveIn.InitialVirtualRegister; if (!Function.registerInfo().isKnownVirtualRegister(Reg)) continue; - auto Candidates = regalloc_detail::allocationOrder(Function, Target, Reg); + auto Candidates = regalloc_detail::allocationOrder(Function, Target, TargetInfo, Reg); if (!Candidates) return std::unexpected(Candidates.error()); if (std::ranges::find(*Candidates, LiveIn.PhysReg) == Candidates->end()) { @@ -577,6 +577,12 @@ Expected FastAllocatorPass::run(MachineFunction &Function, auto Trial = regalloc_detail::cloneForAllocation(Function, Target); if (!Trial) return std::unexpected(Trial.error()); + const std::vector FunctionReserved = + regalloc_detail::functionReservedRegisters(Function, Target, *Info); + auto TrialReserved = + regalloc_detail::reserveFunctionRegisters(*Trial->ClonedFunction, FunctionReserved); + if (!TrialReserved) + return std::unexpected(TrialReserved.error()); MachineAnalysisManager TrialAnalyses; auto Registered = registerStage11MachineAnalyses(TrialAnalyses); if (!Registered) @@ -602,6 +608,10 @@ Expected FastAllocatorPass::run(MachineFunction &Function, return std::unexpected(regalloc_detail::withPrefix( Allocated.error(), "FastAllocator diverged after a successful transaction preflight: ")); } + auto Reserved = regalloc_detail::reserveFunctionRegisters(Function, FunctionReserved); + if (!Reserved) + return std::unexpected(Reserved.error()); + Allocated->Changed |= *Reserved; return regalloc_detail::passResult(*Allocated); } -- cgit v1.2.3