luau/tests/IrRegAllocX64.test.cpp

59 lines
1.4 KiB
C++
Raw Normal View History

2023-04-22 05:41:03 +08: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-16 00:27:45 +08:00
, regs(build, function, nullptr)
2023-04-22 05:41:03 +08: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"(
2023-09-02 00:38:53 +08:00
vmovsd qword ptr [rsp+048h],rax
vmovsd qword ptr [rsp+050h],rax
vmovsd rax,qword ptr [rsp+048h]
2023-04-22 05:41:03 +08:00
)");
}
TEST_SUITE_END();