2023-02-24 21:49:38 +00: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/RegisterX64.h"
|
|
|
|
|
|
|
|
#include <array>
|
|
|
|
#include <initializer_list>
|
|
|
|
|
|
|
|
namespace Luau
|
|
|
|
{
|
|
|
|
namespace CodeGen
|
|
|
|
{
|
2023-03-03 20:21:14 +00:00
|
|
|
namespace X64
|
|
|
|
{
|
2023-02-24 21:49:38 +00:00
|
|
|
|
|
|
|
struct IrRegAllocX64
|
|
|
|
{
|
|
|
|
IrRegAllocX64(IrFunction& function);
|
|
|
|
|
|
|
|
RegisterX64 allocGprReg(SizeX64 preferredSize);
|
|
|
|
RegisterX64 allocXmmReg();
|
|
|
|
|
|
|
|
RegisterX64 allocGprRegOrReuse(SizeX64 preferredSize, uint32_t index, std::initializer_list<IrOp> oprefs);
|
|
|
|
RegisterX64 allocXmmRegOrReuse(uint32_t index, std::initializer_list<IrOp> oprefs);
|
|
|
|
|
2023-03-31 19:42:49 +01:00
|
|
|
RegisterX64 takeReg(RegisterX64 reg);
|
2023-03-03 20:21:14 +00:00
|
|
|
|
2023-02-24 21:49:38 +00:00
|
|
|
void freeReg(RegisterX64 reg);
|
|
|
|
void freeLastUseReg(IrInst& target, uint32_t index);
|
|
|
|
void freeLastUseRegs(const IrInst& inst, uint32_t index);
|
|
|
|
|
2023-03-31 19:42:49 +01:00
|
|
|
bool isLastUseReg(const IrInst& target, uint32_t index) const;
|
|
|
|
|
|
|
|
bool shouldFreeGpr(RegisterX64 reg) const;
|
|
|
|
|
|
|
|
void assertFree(RegisterX64 reg) const;
|
2023-03-03 20:21:14 +00:00
|
|
|
void assertAllFree() const;
|
|
|
|
|
2023-02-24 21:49:38 +00:00
|
|
|
IrFunction& function;
|
|
|
|
|
|
|
|
std::array<bool, 16> freeGprMap;
|
|
|
|
std::array<bool, 16> freeXmmMap;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct ScopedRegX64
|
|
|
|
{
|
2023-03-10 20:21:07 +00:00
|
|
|
explicit ScopedRegX64(IrRegAllocX64& owner);
|
2023-02-24 21:49:38 +00:00
|
|
|
ScopedRegX64(IrRegAllocX64& owner, SizeX64 size);
|
|
|
|
ScopedRegX64(IrRegAllocX64& owner, RegisterX64 reg);
|
|
|
|
~ScopedRegX64();
|
|
|
|
|
|
|
|
ScopedRegX64(const ScopedRegX64&) = delete;
|
|
|
|
ScopedRegX64& operator=(const ScopedRegX64&) = delete;
|
|
|
|
|
2023-03-10 20:21:07 +00:00
|
|
|
void alloc(SizeX64 size);
|
2023-02-24 21:49:38 +00:00
|
|
|
void free();
|
|
|
|
|
2023-03-31 19:42:49 +01:00
|
|
|
RegisterX64 release();
|
|
|
|
|
2023-02-24 21:49:38 +00:00
|
|
|
IrRegAllocX64& owner;
|
|
|
|
RegisterX64 reg;
|
|
|
|
};
|
|
|
|
|
2023-03-03 20:21:14 +00:00
|
|
|
} // namespace X64
|
2023-02-24 21:49:38 +00:00
|
|
|
} // namespace CodeGen
|
|
|
|
} // namespace Luau
|