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/include/rcc/CodeGen/RegAllocCommon.h | 3 +++ backend/include/rcc/CodeGen/VirtRegMap.h | 18 +++++++++++++----- 2 files changed, 16 insertions(+), 5 deletions(-) (limited to 'backend/include') diff --git a/backend/include/rcc/CodeGen/RegAllocCommon.h b/backend/include/rcc/CodeGen/RegAllocCommon.h index ac3aa56..5994d64 100644 --- a/backend/include/rcc/CodeGen/RegAllocCommon.h +++ b/backend/include/rcc/CodeGen/RegAllocCommon.h @@ -19,6 +19,9 @@ struct RegisterAllocationOptions final { [[nodiscard]] std::unique_ptr createBasicAllocatorPass(const TargetRegisterAllocationInfo &Info, RegisterAllocationOptions Options = {}); +[[nodiscard]] std::unique_ptr +createGreedyAllocatorPass(const TargetRegisterAllocationInfo &Info, + RegisterAllocationOptions Options = {}); } // namespace rcc diff --git a/backend/include/rcc/CodeGen/VirtRegMap.h b/backend/include/rcc/CodeGen/VirtRegMap.h index 30ef450..eda71c2 100644 --- a/backend/include/rcc/CodeGen/VirtRegMap.h +++ b/backend/include/rcc/CodeGen/VirtRegMap.h @@ -9,6 +9,7 @@ #include #include +#include #include #include @@ -75,17 +76,24 @@ private: const TargetDescription &Target, const VirtRegMap &Mapping); -class VirtualRegisterRewritePass final : public MachineFunctionPass { +class VirtRegMapAnalysis final { public: - explicit VirtualRegisterRewritePass(const VirtRegMap &Mapping) noexcept : Mapping(&Mapping) {} + using Result = VirtRegMap; + + [[nodiscard]] static constexpr std::string_view name() noexcept { + return "VirtRegMap"; + } + [[nodiscard]] static Expected run(MachineFunction &Function, + const TargetDescription &Target, + MachineFunctionAnalysisManager &Analyses); +}; +class VirtualRegisterRewritePass final : public MachineFunctionPass { +public: [[nodiscard]] const MachinePassContract &contract() const noexcept override; [[nodiscard]] Expected run(MachineFunction &Function, const TargetDescription &Target, MachineFunctionAnalysisManager &Analyses) override; - -private: - const VirtRegMap *Mapping; }; } // namespace rcc -- cgit v1.2.3