aboutsummaryrefslogtreecommitdiff
path: root/backend/include/rcc/CodeGen/Spiller.h
diff options
context:
space:
mode:
Diffstat (limited to 'backend/include/rcc/CodeGen/Spiller.h')
-rw-r--r--backend/include/rcc/CodeGen/Spiller.h41
1 files changed, 41 insertions, 0 deletions
diff --git a/backend/include/rcc/CodeGen/Spiller.h b/backend/include/rcc/CodeGen/Spiller.h
new file mode 100644
index 0000000..3d1fc66
--- /dev/null
+++ b/backend/include/rcc/CodeGen/Spiller.h
@@ -0,0 +1,41 @@
+// SPDX-License-Identifier: GPL-3.0-or-later
+
+#ifndef RCC_CODEGEN_SPILLER_H
+#define RCC_CODEGEN_SPILLER_H
+
+#include "rcc/CodeGen/LiveRangeEdit.h"
+#include "rcc/CodeGen/TargetRegisterAllocationInfo.h"
+
+#include <optional>
+#include <vector>
+
+namespace rcc {
+
+class Spiller final {
+public:
+ Spiller(MachineFunction &Function, const TargetDescription &Target,
+ const TargetRegisterAllocationInfo &TargetInfo, VirtRegMap &Mapping,
+ bool EnableRematerialization = true)
+ : Function(&Function), Target(&Target), TargetInfo(&TargetInfo), Mapping(&Mapping),
+ Edit(Function, Target, Mapping), EnableRematerialization(EnableRematerialization) {}
+
+ [[nodiscard]] Expected<std::vector<Register>> spill(Register VirtualReg);
+
+private:
+ [[nodiscard]] Expected<std::vector<Register>> spillAtInstructions(Register VirtualReg);
+ [[nodiscard]] Expected<void> spillLiveIn(Register VirtualReg, RegisterClassID Class,
+ FrameIndex StackSlot);
+ [[nodiscard]] Expected<std::optional<std::vector<Register>>>
+ tryRematerialize(Register VirtualReg);
+
+ MachineFunction *Function;
+ const TargetDescription *Target;
+ const TargetRegisterAllocationInfo *TargetInfo;
+ VirtRegMap *Mapping;
+ LiveRangeEdit Edit;
+ bool EnableRematerialization;
+};
+
+} // namespace rcc
+
+#endif // RCC_CODEGEN_SPILLER_H