Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Roblox
GitHub Repository: Roblox/luau
Path: blob/master/CodeGen/src/IrRegAllocA64.h
2725 views
1
// This file is part of the Luau programming language and is licensed under MIT License; see LICENSE.txt for details
2
#pragma once
3
4
#include "Luau/IrData.h"
5
#include "Luau/RegisterA64.h"
6
7
#include <initializer_list>
8
#include <utility>
9
#include <vector>
10
11
namespace Luau
12
{
13
namespace CodeGen
14
{
15
16
struct LoweringStats;
17
18
namespace A64
19
{
20
21
class AssemblyBuilderA64;
22
23
struct IrRegAllocA64
24
{
25
IrRegAllocA64(
26
AssemblyBuilderA64& build,
27
IrFunction& function,
28
LoweringStats* stats,
29
std::initializer_list<std::pair<RegisterA64, RegisterA64>> regs
30
);
31
32
RegisterA64 allocReg(KindA64 kind, uint32_t index);
33
RegisterA64 allocTemp(KindA64 kind);
34
RegisterA64 allocReuse(KindA64 kind, uint32_t index, std::initializer_list<IrOp> oprefs);
35
36
RegisterA64 takeReg(RegisterA64 reg, uint32_t index);
37
38
void freeReg(RegisterA64 reg);
39
40
void freeLastUseReg(IrInst& target, uint32_t index);
41
void freeLastUseRegs(const IrInst& inst, uint32_t index);
42
43
void freeTemp(RegisterA64 reg);
44
void freeTempRegs();
45
46
// Spills all live registers that outlive current instruction; all allocated registers are assumed to be undefined
47
size_t spill(uint32_t index, std::initializer_list<RegisterA64> live = {});
48
49
// Restores registers starting from the offset returned by spill(); all spills will be restored to the original registers
50
void restore(size_t start);
51
52
// Restores register for a single instruction; may not assign the previously used register!
53
void restoreReg(IrInst& inst);
54
55
struct Set
56
{
57
// which registers are in the set that the allocator manages (initialized at construction)
58
uint32_t base = 0;
59
60
// which subset of initial set is free
61
uint32_t free = 0;
62
63
// which subset of initial set is allocated as temporary
64
uint32_t temp = 0;
65
66
// which instruction is defining which register (for spilling); only valid if not free and not temp
67
uint32_t defs[32];
68
};
69
70
struct Spill
71
{
72
uint32_t inst;
73
74
RegisterA64 origin;
75
int8_t slot;
76
};
77
78
void restore(const Spill& s, RegisterA64 reg);
79
80
// Spills the selected register
81
void spill(Set& set, uint32_t index, uint32_t targetInstIdx);
82
83
uint32_t findInstructionWithFurthestNextUse(Set& set) const;
84
85
bool isExtraSpillSlot(unsigned slot) const;
86
int getExtraSpillAddressOffset(unsigned slot) const;
87
88
Set& getSet(KindA64 kind);
89
90
AssemblyBuilderA64& build;
91
IrFunction& function;
92
LoweringStats* stats = nullptr;
93
94
uint32_t currInstIdx = kInvalidInstIdx;
95
96
Set gpr, simd;
97
98
std::vector<Spill> spills;
99
100
// which 8-byte slots are free
101
uint64_t freeSpillSlots = 0;
102
103
bool error = false;
104
};
105
106
} // namespace A64
107
} // namespace CodeGen
108
} // namespace Luau
109
110