aboutsummaryrefslogtreecommitdiff
path: root/backend/include/rcc/CodeGen/TargetRegisterAllocationInfo.h
diff options
context:
space:
mode:
authorRichard-Qin-X <richard.qin.001@gmail.com>2026-08-09 04:40:17 +0800
committerRichard-Qin-X <richard.qin.001@gmail.com>2026-08-09 04:40:17 +0800
commite5fdceb9b869f010a2a75638fd38aaf1867f3008 (patch)
tree023d3e18960956f5ce369739c68aaa2a3e8400e7 /backend/include/rcc/CodeGen/TargetRegisterAllocationInfo.h
parent6c7cecc81a4c7e06e26027e21edd2cfd95a37a0b (diff)
downloadrcc-project-e5fdceb9b869f010a2a75638fd38aaf1867f3008.tar.gz
rcc-project-e5fdceb9b869f010a2a75638fd38aaf1867f3008.tar.xz
[CodeGen] Complete register allocation infrastructure
Diffstat (limited to 'backend/include/rcc/CodeGen/TargetRegisterAllocationInfo.h')
-rw-r--r--backend/include/rcc/CodeGen/TargetRegisterAllocationInfo.h58
1 files changed, 58 insertions, 0 deletions
diff --git a/backend/include/rcc/CodeGen/TargetRegisterAllocationInfo.h b/backend/include/rcc/CodeGen/TargetRegisterAllocationInfo.h
new file mode 100644
index 0000000..6e25465
--- /dev/null
+++ b/backend/include/rcc/CodeGen/TargetRegisterAllocationInfo.h
@@ -0,0 +1,58 @@
+// SPDX-License-Identifier: GPL-3.0-or-later
+
+#ifndef RCC_CODEGEN_TARGETREGISTERALLOCATIONINFO_H
+#define RCC_CODEGEN_TARGETREGISTERALLOCATIONINFO_H
+
+#include "rcc/CodeGen/MachineFrameInfo.h"
+#include "rcc/CodeGen/MachineLiveness.h"
+#include "rcc/CodeGen/TargetRegisterInfo.h"
+
+#include <cstdint>
+
+namespace rcc {
+
+class MachineIRBuilder;
+class MachineInstr;
+class TargetDescription;
+
+class TargetRegisterAllocationInfo {
+public:
+ virtual ~TargetRegisterAllocationInfo() = default;
+
+ [[nodiscard]] virtual Expected<void>
+ validateSpillReload(RegisterClassID Class, const TargetDescription &Target) const = 0;
+ [[nodiscard]] virtual Expected<MachineInstr *>
+ emitReload(MachineIRBuilder &Builder, Register Destination, RegisterClassID Class,
+ FrameIndex StackSlot, LaneMask Lanes) const = 0;
+ [[nodiscard]] virtual Expected<MachineInstr *> emitSpill(MachineIRBuilder &Builder,
+ Register Source, RegisterClassID Class,
+ FrameIndex StackSlot,
+ LaneMask Lanes) const = 0;
+
+ [[nodiscard]] virtual Expected<bool> isRematerializable(const MachineInstr &, Register,
+ const MachineFunction &,
+ const TargetDescription &) const {
+ return false;
+ }
+ [[nodiscard]] virtual Expected<MachineInstr *> rematerialize(MachineIRBuilder &,
+ const MachineInstr &, Register,
+ Register,
+ const TargetDescription &) const {
+ return makeUnexpected(ErrorCode::InternalError,
+ "target accepted rematerialization without implementing it");
+ }
+
+ [[nodiscard]] virtual std::uint64_t physicalRegisterCost(const MachineFunction &, Register,
+ PhysicalRegister, RegisterClassID,
+ bool) const noexcept {
+ return 0;
+ }
+ [[nodiscard]] virtual std::uint64_t spillCost(const MachineFunction &, const LiveInterval &,
+ RegisterClassID) const noexcept {
+ return 1;
+ }
+};
+
+} // namespace rcc
+
+#endif // RCC_CODEGEN_TARGETREGISTERALLOCATIONINFO_H