2023-03-31 19:42:49 +01:00
|
|
|
// This file is part of the Luau programming language and is licensed under MIT License; see LICENSE.txt for details
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "Luau/IrData.h"
|
|
|
|
#include "Luau/RegisterA64.h"
|
|
|
|
|
|
|
|
#include <initializer_list>
|
|
|
|
#include <utility>
|
2023-04-21 23:14:26 +01:00
|
|
|
#include <vector>
|
2023-03-31 19:42:49 +01:00
|
|
|
|
|
|
|
namespace Luau
|
|
|
|
{
|
|
|
|
namespace CodeGen
|
|
|
|
{
|
2023-09-15 18:26:59 +01:00
|
|
|
|
|
|
|
struct LoweringStats;
|
|
|
|
|
2023-03-31 19:42:49 +01:00
|
|
|
namespace A64
|
|
|
|
{
|
|
|
|
|
2023-04-21 23:14:26 +01:00
|
|
|
class AssemblyBuilderA64;
|
|
|
|
|
2023-03-31 19:42:49 +01:00
|
|
|
struct IrRegAllocA64
|
|
|
|
{
|
2023-09-15 18:26:59 +01:00
|
|
|
IrRegAllocA64(IrFunction& function, LoweringStats* stats, std::initializer_list<std::pair<RegisterA64, RegisterA64>> regs);
|
2023-03-31 19:42:49 +01:00
|
|
|
|
2023-04-21 23:14:26 +01:00
|
|
|
RegisterA64 allocReg(KindA64 kind, uint32_t index);
|
2023-03-31 19:42:49 +01:00
|
|
|
RegisterA64 allocTemp(KindA64 kind);
|
|
|
|
RegisterA64 allocReuse(KindA64 kind, uint32_t index, std::initializer_list<IrOp> oprefs);
|
|
|
|
|
2023-04-21 23:14:26 +01:00
|
|
|
RegisterA64 takeReg(RegisterA64 reg, uint32_t index);
|
|
|
|
|
2023-03-31 19:42:49 +01:00
|
|
|
void freeReg(RegisterA64 reg);
|
|
|
|
|
|
|
|
void freeLastUseReg(IrInst& target, uint32_t index);
|
|
|
|
void freeLastUseRegs(const IrInst& inst, uint32_t index);
|
|
|
|
|
|
|
|
void freeTempRegs();
|
|
|
|
|
2023-04-21 23:14:26 +01:00
|
|
|
// Spills all live registers that outlive current instruction; all allocated registers are assumed to be undefined
|
|
|
|
size_t spill(AssemblyBuilderA64& build, uint32_t index, std::initializer_list<RegisterA64> live = {});
|
2023-03-31 19:42:49 +01:00
|
|
|
|
2023-04-21 23:14:26 +01:00
|
|
|
// Restores registers starting from the offset returned by spill(); all spills will be restored to the original registers
|
|
|
|
void restore(AssemblyBuilderA64& build, size_t start);
|
|
|
|
|
|
|
|
// Restores register for a single instruction; may not assign the previously used register!
|
|
|
|
void restoreReg(AssemblyBuilderA64& build, IrInst& inst);
|
|
|
|
|
2023-03-31 19:42:49 +01:00
|
|
|
struct Set
|
|
|
|
{
|
|
|
|
// which registers are in the set that the allocator manages (initialized at construction)
|
|
|
|
uint32_t base = 0;
|
|
|
|
|
|
|
|
// which subset of initial set is free
|
|
|
|
uint32_t free = 0;
|
|
|
|
|
|
|
|
// which subset of initial set is allocated as temporary
|
|
|
|
uint32_t temp = 0;
|
2023-04-21 23:14:26 +01:00
|
|
|
|
|
|
|
// which instruction is defining which register (for spilling); only valid if not free and not temp
|
|
|
|
uint32_t defs[32];
|
2023-03-31 19:42:49 +01:00
|
|
|
};
|
|
|
|
|
2023-04-21 23:14:26 +01:00
|
|
|
struct Spill
|
|
|
|
{
|
|
|
|
uint32_t inst;
|
|
|
|
|
|
|
|
RegisterA64 origin;
|
2023-04-28 20:55:13 +01:00
|
|
|
int8_t slot;
|
2023-04-21 23:14:26 +01:00
|
|
|
};
|
2023-03-31 19:42:49 +01:00
|
|
|
|
|
|
|
Set& getSet(KindA64 kind);
|
2023-04-21 23:14:26 +01:00
|
|
|
|
|
|
|
IrFunction& function;
|
2023-09-15 18:26:59 +01:00
|
|
|
LoweringStats* stats = nullptr;
|
2023-04-21 23:14:26 +01:00
|
|
|
Set gpr, simd;
|
|
|
|
|
|
|
|
std::vector<Spill> spills;
|
|
|
|
|
|
|
|
// which 8-byte slots are free
|
|
|
|
uint32_t freeSpillSlots = 0;
|
2023-07-07 21:10:48 +01:00
|
|
|
|
|
|
|
bool error = false;
|
2023-03-31 19:42:49 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace A64
|
|
|
|
} // namespace CodeGen
|
|
|
|
} // namespace Luau
|