-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
Copy pathInlineeFrameInfo.h
205 lines (175 loc) · 6.11 KB
/
InlineeFrameInfo.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
//-------------------------------------------------------------------------------------------------------
// Copyright (C) Microsoft Corporation and contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
//-------------------------------------------------------------------------------------------------------
#pragma once
class Value;
struct BailoutConstantValue {
public:
void InitIntConstValue(int32 value) { this->type = TyInt32; this->u.intConst.value = (IntConstType)value; };
void InitIntConstValue(IntConstType value, IRType type) {
Assert(IRType_IsSignedInt(type));
this->type = type; this->u.intConst.value = value;
};
void InitVarConstValue(Js::Var value);
void InitFloatConstValue(FloatConstType value) { this->type = TyFloat64; this->u.floatConst.value = value; }
bool IsEqual(const BailoutConstantValue & bailoutConstValue);
public:
IRType type;
union
{
struct sIntConst
{
IntConstType value;
} intConst;
struct sVarConst
{
Js::Var value;
} varConst;
struct sFloatConst
{
FloatConstType value;
} floatConst;
} u;
Js::Var ToVar(Func* func) const;
};
enum InlineeFrameInfoValueType
{
InlineeFrameInfoValueType_None,
InlineeFrameInfoValueType_Sym,
InlineeFrameInfoValueType_Const
};
struct InlineFrameInfoValue
{
InlineeFrameInfoValueType type;
union
{
StackSym* sym;
BailoutConstantValue constValue;
};
bool IsConst() { return this->type == InlineeFrameInfoValueType_Const; }
InlineFrameInfoValue() : type(InlineeFrameInfoValueType_None), sym(nullptr) {}
InlineFrameInfoValue(StackSym* sym) : type(InlineeFrameInfoValueType_Sym), sym(sym) {}
InlineFrameInfoValue(BailoutConstantValue value) : type(InlineeFrameInfoValueType_Const), constValue(value) {}
};
struct InlineeFrameInfo;
struct InlineeFrameRecord
{
int functionOffset;
int inlineDepth;
uint inlineeStartOffset;
int* argOffsets;
Js::Var * constants;
InlineeFrameRecord* parent;
uint argCount;
BVUnit floatArgs;
BVUnit losslessInt32Args;
template<class Fnc>
void MapOffsets(Fnc callback)
{
callback(functionOffset);
for (uint i = 0; i < argCount; i++)
{
callback(argOffsets[i]);
}
}
#if DBG_DUMP
uint constantCount;
Js::FunctionBody* functionBody;
InlineeFrameInfo* frameInfo;
#endif
// Fields are zero initialized any way
InlineeFrameRecord(uint argCount, Js::FunctionBody* functionBody, InlineeFrameInfo* frameInfo) : argCount(argCount)
#if DBG_DUMP
, functionBody(functionBody)
, frameInfo(frameInfo)
#endif
{}
static InlineeFrameRecord* New(NativeCodeData::Allocator* alloc, uint argCount, uint constantCount, intptr_t functionBodyAddr, InlineeFrameInfo* frameInfo)
{
InlineeFrameRecord* record = NativeCodeDataNewZ(alloc, InlineeFrameRecord, argCount, (Js::FunctionBody*)functionBodyAddr, frameInfo);
record->argOffsets = (int*)NativeCodeDataNewArrayNoFixup(alloc, IntType<DataDesc_InlineeFrameRecord_ArgOffsets>, argCount);
record->constants = (Js::Var*)NativeCodeDataNewArrayNoFixup(alloc, VarType<DataDesc_InlineeFrameRecord_Constants>, constantCount);
DebugOnly(record->constantCount = constantCount);
return record;
}
void PopulateParent(Func* func);
void RestoreFrames(Js::FunctionBody* functionBody, InlinedFrameLayout* outerMostInlinee, Js::JavascriptCallStackLayout* callstack, bool boxValues);
void Finalize(Func* inlinee, uint currentOffset);
#if DBG_DUMP
void Dump() const;
void DumpOffset(int offset) const;
#endif
void Fixup(NativeCodeData::DataChunk* chunkList)
{
FixupNativeDataPointer(argOffsets, chunkList);
FixupNativeDataPointer(constants, chunkList);
FixupNativeDataPointer(parent, chunkList);
}
private:
void Restore(Js::FunctionBody* functionBody, InlinedFrameLayout *outerMostFrame, Js::JavascriptCallStackLayout * layout, bool boxValues) const;
Js::Var Restore(int offset, bool isFloat64, bool isInt32, Js::JavascriptCallStackLayout * layout, Js::FunctionBody* functionBody, bool boxValue) const;
InlineeFrameRecord* Reverse();
};
struct NativeOffsetInlineeFramePair
{
uint32 offset;
InlineeFrameRecord* record;
};
struct NativeOffsetInlineeFrameRecordOffset
{
uint32 offset;
uint32 recordOffset;
static uint32 InvalidRecordOffset;
};
struct InlineeFrameInfo
{
typedef JsUtil::List<InlineFrameInfoValue, JitArenaAllocator, /*isLeaf*/ false> ArgList;
InlineFrameInfoValue function;
ArgList* arguments;
InlineeFrameRecord* record;
BVSparse<JitArenaAllocator>* floatSyms;
BVSparse<JitArenaAllocator>* intSyms;
BVSparse<JitArenaAllocator>* varSyms;
Value* functionSymStartValue;
bool isRecorded;
static InlineeFrameInfo* New(JitArenaAllocator* alloc)
{
InlineeFrameInfo* frameInfo = JitAnewStructZ(alloc, InlineeFrameInfo);
frameInfo->arguments = JitAnew(alloc, ArgList, alloc);
return frameInfo;
}
template<class Fn>
void IterateSyms(Fn callback, bool inReverse = false)
{
auto iterator = [=](uint index, InlineFrameInfoValue& value)
{
if (value.type == InlineeFrameInfoValueType_Sym)
{
callback(value.sym);
}
Assert(value.type != InlineeFrameInfoValueType_None);
};
if (inReverse && function.type == InlineeFrameInfoValueType_Sym)
{
callback(function.sym);
}
if (inReverse)
{
arguments->ReverseMap(iterator);
}
else
{
arguments->Map(iterator);
}
Assert(function.type != InlineeFrameInfoValueType_None);
if (!inReverse && function.type == InlineeFrameInfoValueType_Sym)
{
callback(function.sym);
}
}
void AllocateRecord(Func* func, intptr_t functionBodyAddr);
#if DBG_DUMP
void Dump() const;
#endif
};