aboutsummaryrefslogtreecommitdiff
path: root/backend/lib/CodeGen/LiveVariables.cpp
diff options
context:
space:
mode:
authorRichard-Qin-X <richard.qin.001@gmail.com>2026-08-25 03:11:23 +0800
committerRichard-Qin-X <richard.qin.001@gmail.com>2026-08-25 03:11:23 +0800
commitf5d9ddc085055d28d6f9fb3730c3566097f43fb2 (patch)
treed1ca89a409a0d1a167e79e3d1693c22bcfd823a9 /backend/lib/CodeGen/LiveVariables.cpp
parentc3932f55208e3fe2019d26a0e5af421c0b644872 (diff)
downloadrcc-project-f5d9ddc085055d28d6f9fb3730c3566097f43fb2.tar.gz
rcc-project-f5d9ddc085055d28d6f9fb3730c3566097f43fb2.tar.xz
[CodeGen] Implement the greedy register allocator pipeline
Diffstat (limited to 'backend/lib/CodeGen/LiveVariables.cpp')
-rw-r--r--backend/lib/CodeGen/LiveVariables.cpp21
1 files changed, 18 insertions, 3 deletions
diff --git a/backend/lib/CodeGen/LiveVariables.cpp b/backend/lib/CodeGen/LiveVariables.cpp
index 8bdd23e..601fd05 100644
--- a/backend/lib/CodeGen/LiveVariables.cpp
+++ b/backend/lib/CodeGen/LiveVariables.cpp
@@ -13,6 +13,7 @@
#include "rcc/CodeGen/SlotIndexes.h"
#include "rcc/CodeGen/TargetDescription.h"
#include "rcc/CodeGen/TargetRegisterInfo.h"
+#include "rcc/CodeGen/VirtRegMap.h"
#include <algorithm>
#include <array>
@@ -655,9 +656,14 @@ buildLivenessRebuildPlan(const MachineFunction &Function, const TargetDescriptio
}
continue;
}
- const bool IsSemanticUse = !Operand->isDebugUse() &&
- !Operand->registerFlags().has(RegisterOperandFlag::Undef) &&
- !Operand->registerValue()->isNoRegister();
+ const Register OperandRegister = *Operand->registerValue();
+ const auto PhysicalRegister = OperandRegister.physicalRegister();
+ const PhysicalRegisterDesc *PhysicalDescription =
+ PhysicalRegister ? Target.registers().physicalRegister(*PhysicalRegister) : nullptr;
+ const bool IsSemanticUse =
+ !Operand->isDebugUse() && !Operand->registerFlags().has(RegisterOperandFlag::Undef) &&
+ !OperandRegister.isNoRegister() &&
+ (PhysicalDescription == nullptr || !PhysicalDescription->IsConstant);
bool IsKill = false;
if (IsSemanticUse) {
auto IsLive = liveSetIntersects(*Operand, Virtual, Physical, Function, Target);
@@ -985,6 +991,7 @@ Expected<void> registerStage11MachineAnalyses(MachineFunctionAnalysisManager &An
MachineFunctionAnalysisManager::id<SlotIndexesAnalysis>(),
MachineFunctionAnalysisManager::id<LiveVariablesAnalysis>(),
MachineFunctionAnalysisManager::id<LiveIntervalsAnalysis>(),
+ MachineFunctionAnalysisManager::id<VirtRegMapAnalysis>(),
};
const std::size_t Registered = static_cast<std::size_t>(
std::ranges::count_if(IDs, [&Analyses](AnalysisID ID) { return Analyses.isRegistered(ID); }));
@@ -1028,6 +1035,14 @@ Expected<void> registerStage11MachineAnalyses(MachineFunctionAnalysisManager &An
});
if (!Intervals)
return std::unexpected(Intervals.error());
+ auto Mapping = Staging.registerAnalysis<VirtRegMapAnalysis>({
+ .Name = "VirtRegMap",
+ .Dependencies = {},
+ .InvalidatedBy = MachinePassChanges::all(),
+ .ThreadSafety = PassThreadSafety::ThreadSafe,
+ });
+ if (!Mapping)
+ return std::unexpected(Mapping.error());
return Analyses.replaceRegistrations(std::move(Staging));
}