Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Roblox
GitHub Repository: Roblox/luau
Path: blob/master/tests/IrRegAllocX64.test.cpp
2723 views
1
// This file is part of the Luau programming language and is licensed under MIT License; see LICENSE.txt for details
2
#include "Luau/IrRegAllocX64.h"
3
4
#include "doctest.h"
5
6
using namespace Luau::CodeGen;
7
using namespace Luau::CodeGen::X64;
8
9
class IrRegAllocX64Fixture
10
{
11
public:
12
IrRegAllocX64Fixture()
13
: build(/* logText */ true, ABIX64::Windows)
14
, regs(build, function, nullptr)
15
{
16
}
17
18
void checkMatch(std::string expected)
19
{
20
build.finalize();
21
22
CHECK("\n" + build.text == expected);
23
}
24
25
AssemblyBuilderX64 build;
26
IrFunction function;
27
IrRegAllocX64 regs;
28
};
29
30
TEST_SUITE_BEGIN("IrRegAllocX64");
31
32
TEST_CASE_FIXTURE(IrRegAllocX64Fixture, "RelocateFix")
33
{
34
IrInst irInst0{IrCmd::LOAD_DOUBLE};
35
irInst0.lastUse = 2;
36
function.instructions.push_back(irInst0);
37
38
IrInst irInst1{IrCmd::LOAD_DOUBLE};
39
irInst1.lastUse = 2;
40
function.instructions.push_back(irInst1);
41
42
function.instructions[0].regX64 = regs.takeReg(rax, 0);
43
regs.preserve(function.instructions[0]);
44
45
function.instructions[1].regX64 = regs.takeReg(rax, 1);
46
regs.restore(function.instructions[0], true);
47
48
LUAU_ASSERT(function.instructions[0].regX64 == rax);
49
LUAU_ASSERT(function.instructions[1].spilled);
50
51
checkMatch(R"(
52
vmovsd qword ptr [rsp+048h],rax
53
vmovsd qword ptr [rsp+050h],rax
54
vmovsd rax,qword ptr [rsp+048h]
55
)");
56
}
57
58
TEST_SUITE_END();
59
60