Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Roblox
GitHub Repository: Roblox/luau
Path: blob/master/CodeGen/src/IrLoweringA64.h
2725 views
1
// This file is part of the Luau programming language and is licensed under MIT License; see LICENSE.txt for details
2
#pragma once
3
4
#include "Luau/AssemblyBuilderA64.h"
5
#include "Luau/CodeGenOptions.h"
6
#include "Luau/DenseHash.h"
7
#include "Luau/IrData.h"
8
9
#include "IrRegAllocA64.h"
10
#include "IrValueLocationTracking.h"
11
12
#include <vector>
13
14
namespace Luau
15
{
16
namespace CodeGen
17
{
18
19
struct ModuleHelpers;
20
struct AssemblyOptions;
21
struct LoweringStats;
22
enum class CodeGenCounter : unsigned;
23
24
namespace A64
25
{
26
27
struct IrLoweringA64
28
{
29
IrLoweringA64(AssemblyBuilderA64& build, ModuleHelpers& helpers, IrFunction& function, LoweringStats* stats);
30
31
void lowerInst(IrInst& inst, uint32_t index, const IrBlock& next);
32
void startBlock(const IrBlock& curr);
33
void finishBlock(const IrBlock& curr, const IrBlock& next);
34
void finishFunction();
35
36
bool hasError() const;
37
38
bool isFallthroughBlock(const IrBlock& target, const IrBlock& next);
39
void jumpOrFallthrough(IrBlock& target, const IrBlock& next);
40
41
Label& getTargetLabel(IrOp op, Label& fresh);
42
void finalizeTargetLabel(IrOp op, Label& fresh);
43
44
void checkSafeEnv(IrOp target, const IrBlock& next);
45
46
void allocAndIncrementCounterAt(CodeGenCounter kind, uint32_t pcpos);
47
void incrementCounterAt(size_t offset);
48
49
void checkObjectBarrierConditions(RegisterA64 object, RegisterA64 temp, RegisterA64 ra, IrOp raOp, int ratag, Label& skip);
50
51
// Operand data build helpers
52
// May emit data/address synthesis instructions
53
RegisterA64 tempDouble(IrOp op);
54
RegisterA64 tempFloat(IrOp op);
55
RegisterA64 tempInt(IrOp op);
56
RegisterA64 tempUint(IrOp op);
57
AddressA64 tempAddr(IrOp op, int offset, RegisterA64 tempStorage = noreg); // Existing temporary register can be provided
58
AddressA64 tempAddrBuffer(IrOp bufferOp, IrOp indexOp, uint8_t tag);
59
60
// May emit restore instructions
61
RegisterA64 regOp(IrOp op);
62
63
// Operand data lookup helpers
64
IrConst constOp(IrOp op) const;
65
uint8_t tagOp(IrOp op) const;
66
int intOp(IrOp op) const;
67
unsigned uintOp(IrOp op) const;
68
unsigned importOp(IrOp op) const;
69
double doubleOp(IrOp op) const;
70
71
IrBlock& blockOp(IrOp op) const;
72
Label& labelOp(IrOp op) const;
73
74
struct InterruptHandler
75
{
76
Label self;
77
unsigned int pcpos;
78
Label next;
79
};
80
81
struct ExitHandler
82
{
83
Label self;
84
unsigned int pcpos;
85
};
86
87
AssemblyBuilderA64& build;
88
ModuleHelpers& helpers;
89
90
IrFunction& function;
91
LoweringStats* stats = nullptr;
92
93
IrRegAllocA64 regs;
94
95
IrValueLocationTracking valueTracker;
96
97
std::vector<InterruptHandler> interruptHandlers;
98
std::vector<ExitHandler> exitHandlers;
99
DenseHashMap<uint32_t, uint32_t> exitHandlerMap;
100
101
bool error = false;
102
};
103
104
} // namespace A64
105
} // namespace CodeGen
106
} // namespace Luau
107
108