|
Lines 1-5
Source/JavaScriptCore/dfg/DFGVariableAccessData.h_sec1
|
| 1 |
/* |
1 |
/* |
| 2 |
* Copyright (C) 2011, 2012, 2013 Apple Inc. All rights reserved. |
2 |
* Copyright (C) 2011-2014 Apple Inc. All rights reserved. |
| 3 |
* |
3 |
* |
| 4 |
* Redistribution and use in source and binary forms, with or without |
4 |
* Redistribution and use in source and binary forms, with or without |
| 5 |
* modification, are permitted provided that the following conditions |
5 |
* modification, are permitted provided that the following conditions |
|
Lines 26-31
Source/JavaScriptCore/dfg/DFGVariableAccessData.h_sec2
|
| 26 |
#ifndef DFGVariableAccessData_h |
26 |
#ifndef DFGVariableAccessData_h |
| 27 |
#define DFGVariableAccessData_h |
27 |
#define DFGVariableAccessData_h |
| 28 |
|
28 |
|
|
|
29 |
#if ENABLE(DFG_JIT) |
| 30 |
|
| 29 |
#include "DFGCommon.h" |
31 |
#include "DFGCommon.h" |
| 30 |
#include "DFGDoubleFormatState.h" |
32 |
#include "DFGDoubleFormatState.h" |
| 31 |
#include "DFGFlushFormat.h" |
33 |
#include "DFGFlushFormat.h" |
|
Lines 45-83
enum DoubleBallot { VoteValue, VoteDoubl
Source/JavaScriptCore/dfg/DFGVariableAccessData.h_sec3
|
| 45 |
|
47 |
|
| 46 |
class VariableAccessData : public UnionFind<VariableAccessData> { |
48 |
class VariableAccessData : public UnionFind<VariableAccessData> { |
| 47 |
public: |
49 |
public: |
| 48 |
VariableAccessData() |
50 |
VariableAccessData(); |
| 49 |
: m_local(static_cast<VirtualRegister>(std::numeric_limits<int>::min())) |
51 |
VariableAccessData(VirtualRegister local, bool isCaptured); |
| 50 |
, m_prediction(SpecNone) |
|
|
| 51 |
, m_argumentAwarePrediction(SpecNone) |
| 52 |
, m_flags(0) |
| 53 |
, m_isCaptured(false) |
| 54 |
, m_shouldNeverUnbox(false) |
| 55 |
, m_isArgumentsAlias(false) |
| 56 |
, m_structureCheckHoistingFailed(false) |
| 57 |
, m_checkArrayHoistingFailed(false) |
| 58 |
, m_isProfitableToUnbox(false) |
| 59 |
, m_isLoadedFrom(false) |
| 60 |
, m_doubleFormatState(EmptyDoubleFormatState) |
| 61 |
{ |
| 62 |
clearVotes(); |
| 63 |
} |
| 64 |
|
| 65 |
VariableAccessData(VirtualRegister local, bool isCaptured) |
| 66 |
: m_local(local) |
| 67 |
, m_prediction(SpecNone) |
| 68 |
, m_argumentAwarePrediction(SpecNone) |
| 69 |
, m_flags(0) |
| 70 |
, m_isCaptured(isCaptured) |
| 71 |
, m_shouldNeverUnbox(isCaptured) |
| 72 |
, m_isArgumentsAlias(false) |
| 73 |
, m_structureCheckHoistingFailed(false) |
| 74 |
, m_checkArrayHoistingFailed(false) |
| 75 |
, m_isProfitableToUnbox(false) |
| 76 |
, m_isLoadedFrom(false) |
| 77 |
, m_doubleFormatState(EmptyDoubleFormatState) |
| 78 |
{ |
| 79 |
clearVotes(); |
| 80 |
} |
| 81 |
|
52 |
|
| 82 |
VirtualRegister local() |
53 |
VirtualRegister local() |
| 83 |
{ |
54 |
{ |
|
Lines 91-101
public:
Source/JavaScriptCore/dfg/DFGVariableAccessData.h_sec4
|
| 91 |
return m_machineLocal; |
62 |
return m_machineLocal; |
| 92 |
} |
63 |
} |
| 93 |
|
64 |
|
| 94 |
bool mergeIsCaptured(bool isCaptured) |
65 |
bool mergeIsCaptured(bool isCaptured); |
| 95 |
{ |
|
|
| 96 |
return checkAndSet(m_shouldNeverUnbox, m_shouldNeverUnbox | isCaptured) |
| 97 |
| checkAndSet(m_isCaptured, m_isCaptured | isCaptured); |
| 98 |
} |
| 99 |
|
66 |
|
| 100 |
bool isCaptured() |
67 |
bool isCaptured() |
| 101 |
{ |
68 |
{ |
|
Lines 112-125
public:
Source/JavaScriptCore/dfg/DFGVariableAccessData.h_sec5
|
| 112 |
return m_isProfitableToUnbox; |
79 |
return m_isProfitableToUnbox; |
| 113 |
} |
80 |
} |
| 114 |
|
81 |
|
| 115 |
bool mergeShouldNeverUnbox(bool shouldNeverUnbox) |
82 |
bool mergeShouldNeverUnbox(bool shouldNeverUnbox); |
| 116 |
{ |
|
|
| 117 |
bool newShouldNeverUnbox = m_shouldNeverUnbox | shouldNeverUnbox; |
| 118 |
if (newShouldNeverUnbox == m_shouldNeverUnbox) |
| 119 |
return false; |
| 120 |
m_shouldNeverUnbox = newShouldNeverUnbox; |
| 121 |
return true; |
| 122 |
} |
| 123 |
|
83 |
|
| 124 |
// Returns true if it would be unsound to store the value in an unboxed fashion. |
84 |
// Returns true if it would be unsound to store the value in an unboxed fashion. |
| 125 |
// If this returns false, it simply means that it is sound to unbox; it doesn't |
85 |
// If this returns false, it simply means that it is sound to unbox; it doesn't |
|
Lines 183-196
public:
Source/JavaScriptCore/dfg/DFGVariableAccessData.h_sec6
|
| 183 |
return m_isLoadedFrom; |
143 |
return m_isLoadedFrom; |
| 184 |
} |
144 |
} |
| 185 |
|
145 |
|
| 186 |
bool predict(SpeculatedType prediction) |
146 |
bool predict(SpeculatedType prediction); |
| 187 |
{ |
|
|
| 188 |
VariableAccessData* self = find(); |
| 189 |
bool result = mergeSpeculation(self->m_prediction, prediction); |
| 190 |
if (result) |
| 191 |
mergeSpeculation(m_argumentAwarePrediction, m_prediction); |
| 192 |
return result; |
| 193 |
} |
| 194 |
|
147 |
|
| 195 |
SpeculatedType nonUnifiedPrediction() |
148 |
SpeculatedType nonUnifiedPrediction() |
| 196 |
{ |
149 |
{ |
|
Lines 207-216
public:
Source/JavaScriptCore/dfg/DFGVariableAccessData.h_sec7
|
| 207 |
return find()->m_argumentAwarePrediction; |
160 |
return find()->m_argumentAwarePrediction; |
| 208 |
} |
161 |
} |
| 209 |
|
162 |
|
| 210 |
bool mergeArgumentAwarePrediction(SpeculatedType prediction) |
163 |
bool mergeArgumentAwarePrediction(SpeculatedType prediction); |
| 211 |
{ |
|
|
| 212 |
return mergeSpeculation(find()->m_argumentAwarePrediction, prediction); |
| 213 |
} |
| 214 |
|
164 |
|
| 215 |
void clearVotes() |
165 |
void clearVotes() |
| 216 |
{ |
166 |
{ |
|
Lines 219-228
public:
Source/JavaScriptCore/dfg/DFGVariableAccessData.h_sec8
|
| 219 |
m_votes[1] = 0; |
169 |
m_votes[1] = 0; |
| 220 |
} |
170 |
} |
| 221 |
|
171 |
|
| 222 |
void vote(unsigned ballot) |
172 |
void vote(unsigned ballot, float weight = 1) |
| 223 |
{ |
173 |
{ |
| 224 |
ASSERT(ballot < 2); |
174 |
ASSERT(ballot < 2); |
| 225 |
m_votes[ballot]++; |
175 |
m_votes[ballot] += weight; |
| 226 |
} |
176 |
} |
| 227 |
|
177 |
|
| 228 |
double voteRatio() |
178 |
double voteRatio() |
|
Lines 231-269
public:
Source/JavaScriptCore/dfg/DFGVariableAccessData.h_sec9
|
| 231 |
return static_cast<double>(m_votes[1]) / m_votes[0]; |
181 |
return static_cast<double>(m_votes[1]) / m_votes[0]; |
| 232 |
} |
182 |
} |
| 233 |
|
183 |
|
| 234 |
bool shouldUseDoubleFormatAccordingToVote() |
184 |
bool shouldUseDoubleFormatAccordingToVote(); |
| 235 |
{ |
|
|
| 236 |
// We don't support this facility for arguments, yet. |
| 237 |
// FIXME: make this work for arguments. |
| 238 |
if (local().isArgument()) |
| 239 |
return false; |
| 240 |
|
| 241 |
// If the variable is not a number prediction, then this doesn't |
| 242 |
// make any sense. |
| 243 |
if (!isFullNumberSpeculation(prediction())) { |
| 244 |
// FIXME: we may end up forcing a local in inlined argument position to be a double even |
| 245 |
// if it is sometimes not even numeric, since this never signals the fact that it doesn't |
| 246 |
// want doubles. https://bugs.webkit.org/show_bug.cgi?id=109511 |
| 247 |
return false; |
| 248 |
} |
| 249 |
|
| 250 |
// If the variable is predicted to hold only doubles, then it's a |
| 251 |
// no-brainer: it should be formatted as a double. |
| 252 |
if (isDoubleSpeculation(prediction())) |
| 253 |
return true; |
| 254 |
|
| 255 |
// If the variable is known to be used as an integer, then be safe - |
| 256 |
// don't force it to be a double. |
| 257 |
if (flags() & NodeBytecodeUsesAsInt) |
| 258 |
return false; |
| 259 |
|
| 260 |
// If the variable has been voted to become a double, then make it a |
| 261 |
// double. |
| 262 |
if (voteRatio() >= Options::doubleVoteRatioForDoubleFormat()) |
| 263 |
return true; |
| 264 |
|
| 265 |
return false; |
| 266 |
} |
| 267 |
|
185 |
|
| 268 |
DoubleFormatState doubleFormatState() |
186 |
DoubleFormatState doubleFormatState() |
| 269 |
{ |
187 |
{ |
|
Lines 279-326
public:
Source/JavaScriptCore/dfg/DFGVariableAccessData.h_sec10
|
| 279 |
return doubleState && isProfitableToUnbox(); |
197 |
return doubleState && isProfitableToUnbox(); |
| 280 |
} |
198 |
} |
| 281 |
|
199 |
|
| 282 |
bool tallyVotesForShouldUseDoubleFormat() |
200 |
bool tallyVotesForShouldUseDoubleFormat(); |
| 283 |
{ |
|
|
| 284 |
ASSERT(isRoot()); |
| 285 |
|
| 286 |
if (local().isArgument() || shouldNeverUnbox()) |
| 287 |
return DFG::mergeDoubleFormatState(m_doubleFormatState, NotUsingDoubleFormat); |
| 288 |
|
| 289 |
if (m_doubleFormatState == CantUseDoubleFormat) |
| 290 |
return false; |
| 291 |
|
| 292 |
bool newValueOfShouldUseDoubleFormat = shouldUseDoubleFormatAccordingToVote(); |
| 293 |
if (!newValueOfShouldUseDoubleFormat) { |
| 294 |
// We monotonically convert to double. Hence, if the fixpoint leads us to conclude that we should |
| 295 |
// switch back to int, we instead ignore this and stick with double. |
| 296 |
return false; |
| 297 |
} |
| 298 |
|
| 299 |
if (m_doubleFormatState == UsingDoubleFormat) |
| 300 |
return false; |
| 301 |
|
| 302 |
return DFG::mergeDoubleFormatState(m_doubleFormatState, UsingDoubleFormat); |
| 303 |
} |
| 304 |
|
201 |
|
| 305 |
bool mergeDoubleFormatState(DoubleFormatState doubleFormatState) |
202 |
bool mergeDoubleFormatState(DoubleFormatState doubleFormatState); |
| 306 |
{ |
|
|
| 307 |
return DFG::mergeDoubleFormatState(find()->m_doubleFormatState, doubleFormatState); |
| 308 |
} |
| 309 |
|
203 |
|
| 310 |
bool makePredictionForDoubleFormat() |
204 |
bool makePredictionForDoubleFormat(); |
| 311 |
{ |
|
|
| 312 |
ASSERT(isRoot()); |
| 313 |
|
| 314 |
if (m_doubleFormatState != UsingDoubleFormat) |
| 315 |
return false; |
| 316 |
|
| 317 |
SpeculatedType type = m_prediction; |
| 318 |
if (type & ~SpecBytecodeNumber) |
| 319 |
type |= SpecDoublePureNaN; |
| 320 |
if (type & SpecMachineInt) |
| 321 |
type |= SpecInt52AsDouble; |
| 322 |
return checkAndSet(m_prediction, type); |
| 323 |
} |
| 324 |
|
205 |
|
| 325 |
NodeFlags flags() const { return m_flags; } |
206 |
NodeFlags flags() const { return m_flags; } |
| 326 |
|
207 |
|
|
Lines 329-362
public:
Source/JavaScriptCore/dfg/DFGVariableAccessData.h_sec11
|
| 329 |
return checkAndSet(m_flags, m_flags | newFlags); |
210 |
return checkAndSet(m_flags, m_flags | newFlags); |
| 330 |
} |
211 |
} |
| 331 |
|
212 |
|
| 332 |
FlushFormat flushFormat() |
213 |
FlushFormat flushFormat(); |
| 333 |
{ |
|
|
| 334 |
ASSERT(find() == this); |
| 335 |
|
| 336 |
if (isArgumentsAlias()) |
| 337 |
return FlushedArguments; |
| 338 |
|
| 339 |
if (!shouldUnboxIfPossible()) |
| 340 |
return FlushedJSValue; |
| 341 |
|
| 342 |
if (shouldUseDoubleFormat()) |
| 343 |
return FlushedDouble; |
| 344 |
|
| 345 |
SpeculatedType prediction = argumentAwarePrediction(); |
| 346 |
if (isInt32Speculation(prediction)) |
| 347 |
return FlushedInt32; |
| 348 |
|
| 349 |
if (enableInt52() && !m_local.isArgument() && isMachineIntSpeculation(prediction)) |
| 350 |
return FlushedInt52; |
| 351 |
|
| 352 |
if (isCellSpeculation(prediction)) |
| 353 |
return FlushedCell; |
| 354 |
|
| 355 |
if (isBooleanSpeculation(prediction)) |
| 356 |
return FlushedBoolean; |
| 357 |
|
| 358 |
return FlushedJSValue; |
| 359 |
} |
| 360 |
|
214 |
|
| 361 |
FlushedAt flushedAt() |
215 |
FlushedAt flushedAt() |
| 362 |
{ |
216 |
{ |
|
Lines 389-392
private:
Source/JavaScriptCore/dfg/DFGVariableAccessData.h_sec12
|
| 389 |
|
243 |
|
| 390 |
} } // namespace JSC::DFG |
244 |
} } // namespace JSC::DFG |
| 391 |
|
245 |
|
|
|
246 |
#endif // ENABLE(DFG_JIT) |
| 247 |
|
| 392 |
#endif // DFGVariableAccessData_h |
248 |
#endif // DFGVariableAccessData_h |