2023-04-21 23:14:26 +01:00
|
|
|
// This file is part of the Luau programming language and is licensed under MIT License; see LICENSE.txt for details
|
|
|
|
#include "Luau/IrRegAllocX64.h"
|
|
|
|
|
|
|
|
#include "doctest.h"
|
|
|
|
|
|
|
|
using namespace Luau::CodeGen;
|
|
|
|
using namespace Luau::CodeGen::X64;
|
|
|
|
|
|
|
|
class IrRegAllocX64Fixture
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
IrRegAllocX64Fixture()
|
|
|
|
: build(/* logText */ true, ABIX64::Windows)
|
2023-09-15 18:26:59 +01:00
|
|
|
, regs(build, function, nullptr)
|
2023-04-21 23:14:26 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void checkMatch(std::string expected)
|
|
|
|
{
|
|
|
|
build.finalize();
|
|
|
|
|
|
|
|
CHECK("\n" + build.text == expected);
|
|
|
|
}
|
|
|
|
|
|
|
|
AssemblyBuilderX64 build;
|
|
|
|
IrFunction function;
|
|
|
|
IrRegAllocX64 regs;
|
|
|
|
};
|
|
|
|
|
|
|
|
TEST_SUITE_BEGIN("IrRegAllocX64");
|
|
|
|
|
|
|
|
TEST_CASE_FIXTURE(IrRegAllocX64Fixture, "RelocateFix")
|
|
|
|
{
|
|
|
|
IrInst irInst0{IrCmd::LOAD_DOUBLE};
|
|
|
|
irInst0.lastUse = 2;
|
|
|
|
function.instructions.push_back(irInst0);
|
|
|
|
|
|
|
|
IrInst irInst1{IrCmd::LOAD_DOUBLE};
|
|
|
|
irInst1.lastUse = 2;
|
|
|
|
function.instructions.push_back(irInst1);
|
|
|
|
|
|
|
|
function.instructions[0].regX64 = regs.takeReg(rax, 0);
|
|
|
|
regs.preserve(function.instructions[0]);
|
|
|
|
|
|
|
|
function.instructions[1].regX64 = regs.takeReg(rax, 1);
|
|
|
|
regs.restore(function.instructions[0], true);
|
|
|
|
|
|
|
|
LUAU_ASSERT(function.instructions[0].regX64 == rax);
|
|
|
|
LUAU_ASSERT(function.instructions[1].spilled);
|
|
|
|
|
|
|
|
checkMatch(R"(
|
|
|
|
vmovsd qword ptr [rsp+048h],rax
|
|
|
|
vmovsd qword ptr [rsp+050h],rax
|
|
|
|
vmovsd rax,qword ptr [rsp+048h]
|
|
|
|
)");
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_SUITE_END();
|