2 * Copyright (C) 2013-2015 Apple Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 #ifndef DFGSafeToExecute_h
27 #define DFGSafeToExecute_h
33 namespace JSC
{ namespace DFG
{
35 template<typename AbstractStateType
>
36 class SafeToExecuteEdge
{
38 SafeToExecuteEdge(AbstractStateType
& state
)
44 void operator()(Node
*, Edge edge
)
46 switch (edge
.useKind()) {
50 case DoubleRepRealUse
:
59 case ObjectOrOtherUse
:
63 case StringOrStringObjectUse
:
69 case DoubleRepMachineIntUse
:
73 if (m_state
.forNode(edge
).m_type
& ~SpecInt32
)
78 if (m_state
.forNode(edge
).m_type
& ~SpecCell
)
83 if (m_state
.forNode(edge
).m_type
& ~SpecString
)
88 RELEASE_ASSERT_NOT_REACHED();
91 RELEASE_ASSERT_NOT_REACHED();
94 bool result() const { return m_result
; }
96 AbstractStateType
& m_state
;
100 // Determines if it's safe to execute a node within the given abstract state. This may
101 // return false conservatively. If it returns true, then you can hoist the given node
102 // up to the given point and expect that it will not crash. This doesn't guarantee that
103 // the node will produce the result you wanted other than not crashing.
104 template<typename AbstractStateType
>
105 bool safeToExecute(AbstractStateType
& state
, Graph
& graph
, Node
* node
)
107 SafeToExecuteEdge
<AbstractStateType
> safeToExecuteEdge(state
);
108 DFG_NODE_DO_TO_CHILDREN(graph
, node
, safeToExecuteEdge
);
109 if (!safeToExecuteEdge
.result())
112 switch (node
->op()) {
120 case GetArgumentCount
:
133 case GetLocalUnlinked
:
173 case ArrayifyToStructure
:
180 case VarInjectionWatchpoint
:
189 case CompareGreaterEq
:
191 case CompareEqConstant
:
192 case CompareStrictEq
:
196 case ConstructVarargs
:
198 case CallForwardVarargs
:
199 case ConstructForwardVarargs
:
202 case NewArrayWithSize
:
206 case ProfileWillCall
:
209 case ProfileControlFlow
:
210 case CheckHasInstance
:
223 case CallStringConstructor
:
224 case NewStringObject
:
227 case CreateActivation
:
228 case CreateDirectArguments
:
229 case CreateScopedArguments
:
230 case CreateClonedArguments
:
231 case GetFromArguments
:
239 case ThrowReferenceError
:
242 case CheckWatchdogTimer
:
243 case StringFromCharCode
:
246 case ExtractOSREntryLocal
:
247 case CheckTierUpInLoop
:
248 case CheckTierUpAtReturn
:
249 case CheckTierUpAndOSREnter
:
250 case CheckTierUpWithNestedTriggerAndOSREnter
:
253 case InvalidationPoint
:
256 case ConstantStoragePointer
:
258 case MultiGetByOffset
:
259 case MultiPutByOffset
:
263 case BooleanToNumber
:
267 case GetEnumerableLength
:
268 case HasGenericProperty
:
269 case HasStructureProperty
:
270 case HasIndexedProperty
:
272 case GetPropertyEnumerator
:
273 case GetEnumeratorStructurePname
:
274 case GetEnumeratorGenericPname
:
276 case PhantomNewObject
:
277 case PhantomNewFunction
:
278 case PhantomCreateActivation
:
280 case CheckStructureImmediate
:
281 case MaterializeNewObject
:
282 case MaterializeCreateActivation
:
283 case PhantomDirectArguments
:
284 case PhantomClonedArguments
:
285 case GetMyArgumentByVal
:
290 case NativeConstruct
:
291 return false; // TODO: add a check for already checked. https://bugs.webkit.org/show_bug.cgi?id=133769
294 // If in doubt, assume that this isn't safe to execute, just because we have no way of
295 // compiling this node.
299 case GetIndexedPropertyStorage
:
304 case StringCharCodeAt
:
305 return node
->arrayMode().alreadyChecked(graph
, node
, state
.forNode(node
->child1()));
307 case GetTypedArrayByteOffset
:
308 return !(state
.forNode(node
->child1()).m_type
& ~(SpecTypedArrayView
));
313 return node
->arrayMode().modeForPut().alreadyChecked(
314 graph
, node
, state
.forNode(graph
.varArgChild(node
, 0)));
317 case AllocatePropertyStorage
:
318 case ReallocatePropertyStorage
:
319 return state
.forNode(node
->child1()).m_structure
.isSubsetOf(
320 StructureSet(node
->transition()->previous
));
323 case GetGetterSetterByOffset
:
325 StructureAbstractValue
& value
= state
.forNode(node
->child1()).m_structure
;
328 PropertyOffset offset
= node
->storageAccessData().offset
;
329 for (unsigned i
= value
.size(); i
--;) {
330 if (!value
[i
]->isValidOffset(offset
))
337 RELEASE_ASSERT_NOT_REACHED();
341 RELEASE_ASSERT_NOT_REACHED();
345 } } // namespace JSC::DFG
347 #endif // ENABLE(DFG_JIT)
349 #endif // DFGSafeToExecute_h