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
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
|
/*
* Copyright (C) 2015-2016 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef B3ValueRep_h
#define B3ValueRep_h
#if ENABLE(B3_JIT)
#include "FPRInfo.h"
#include "GPRInfo.h"
#include "JSCJSValue.h"
#include "Reg.h"
#include "RegisterSet.h"
#include "ValueRecovery.h"
#include <wtf/PrintStream.h>
namespace JSC {
class AssemblyHelpers;
namespace B3 {
// We use this class to describe value representations at stackmaps. It's used both to force a
// representation and to get the representation. When the B3 client forces a representation, we say
// that it's an input. When B3 tells the client what representation it picked, we say that it's an
// output.
class ValueRep {
public:
enum Kind {
// As an input representation, this means that B3 can pick any representation. As an output
// representation, this means that we don't know. This will only arise as an output
// representation for the active arguments of Check/CheckAdd/CheckSub/CheckMul.
WarmAny,
// Same as WarmAny, but implies that the use is cold. A cold use is not counted as a use for
// computing the priority of the used temporary.
ColdAny,
// Same as ColdAny, but also implies that the use occurs after all other effects of the stackmap
// value.
LateColdAny,
// As an input representation, this means that B3 should pick some register. It could be a
// register that this claims to clobber!
SomeRegister,
// As an input representation, this forces a particular register. As an output
// representation, this tells us what register B3 picked.
Register,
// As an output representation, this tells us what stack slot B3 picked. It's not a valid
// input representation.
Stack,
// As an input representation, this forces the value to end up in the argument area at some
// offset.
StackArgument,
// As an output representation, this tells us that B3 constant-folded the value.
Constant
};
ValueRep()
: m_kind(WarmAny)
{
}
explicit ValueRep(Reg reg)
: m_kind(Register)
{
u.reg = reg;
}
ValueRep(Kind kind)
: m_kind(kind)
{
ASSERT(kind == WarmAny || kind == ColdAny || kind == LateColdAny || kind == SomeRegister);
}
static ValueRep reg(Reg reg)
{
return ValueRep(reg);
}
static ValueRep stack(intptr_t offsetFromFP)
{
ValueRep result;
result.m_kind = Stack;
result.u.offsetFromFP = offsetFromFP;
return result;
}
static ValueRep stackArgument(intptr_t offsetFromSP)
{
ValueRep result;
result.m_kind = StackArgument;
result.u.offsetFromSP = offsetFromSP;
return result;
}
static ValueRep constant(int64_t value)
{
ValueRep result;
result.m_kind = Constant;
result.u.value = value;
return result;
}
static ValueRep constantDouble(double value)
{
return ValueRep::constant(bitwise_cast<int64_t>(value));
}
Kind kind() const { return m_kind; }
bool operator==(const ValueRep& other) const
{
if (kind() != other.kind())
return false;
switch (kind()) {
case Register:
return u.reg == other.u.reg;
case Stack:
return u.offsetFromFP == other.u.offsetFromFP;
case StackArgument:
return u.offsetFromSP == other.u.offsetFromSP;
case Constant:
return u.value == other.u.value;
default:
return true;
}
}
bool operator!=(const ValueRep& other) const
{
return !(*this == other);
}
explicit operator bool() const { return kind() != WarmAny; }
bool isAny() const { return kind() == WarmAny || kind() == ColdAny || kind() == LateColdAny; }
bool isSomeRegister() const { return kind() == SomeRegister; }
bool isReg() const { return kind() == Register; }
Reg reg() const
{
ASSERT(isReg());
return u.reg;
}
bool isGPR() const { return isReg() && reg().isGPR(); }
bool isFPR() const { return isReg() && reg().isFPR(); }
GPRReg gpr() const { return reg().gpr(); }
FPRReg fpr() const { return reg().fpr(); }
bool isStack() const { return kind() == Stack; }
intptr_t offsetFromFP() const
{
ASSERT(isStack());
return u.offsetFromFP;
}
bool isStackArgument() const { return kind() == StackArgument; }
intptr_t offsetFromSP() const
{
ASSERT(isStackArgument());
return u.offsetFromSP;
}
bool isConstant() const { return kind() == Constant; }
int64_t value() const
{
ASSERT(isConstant());
return u.value;
}
double doubleValue() const
{
return bitwise_cast<double>(value());
}
ValueRep withOffset(intptr_t offset) const
{
switch (kind()) {
case Stack:
return stack(offsetFromFP() + offset);
case StackArgument:
return stackArgument(offsetFromSP() + offset);
default:
return *this;
}
}
void addUsedRegistersTo(RegisterSet&) const;
RegisterSet usedRegisters() const;
// Get the used registers for a vector of ValueReps.
template<typename VectorType>
static RegisterSet usedRegisters(const VectorType& vector)
{
RegisterSet result;
for (const ValueRep& value : vector)
value.addUsedRegistersTo(result);
return result;
}
JS_EXPORT_PRIVATE void dump(PrintStream&) const;
// This has a simple contract: it emits code to restore the value into the given register. This
// will work even if it requires moving between bits a GPR and a FPR.
void emitRestore(AssemblyHelpers&, Reg) const;
// Computes the ValueRecovery assuming that the Value* was for a JSValue (i.e. Int64).
// NOTE: We should avoid putting JSValue-related methods in B3, but this was hard to avoid
// because some parts of JSC use ValueRecovery like a general "where my bits at" object, almost
// exactly like ValueRep.
ValueRecovery recoveryForJSValue() const;
private:
Kind m_kind;
union U {
Reg reg;
intptr_t offsetFromFP;
intptr_t offsetFromSP;
int64_t value;
U()
{
memset(this, 0, sizeof(*this));
}
} u;
};
} } // namespace JSC::B3
namespace WTF {
void printInternal(PrintStream&, JSC::B3::ValueRep::Kind);
} // namespace WTF
#endif // ENABLE(B3_JIT)
#endif // B3ValueRep_h
|