4e6358ef57e266d95ff034588860ba695b48beba
[WebKit-https.git] / Source / JavaScriptCore / dfg / DFGAbstractInterpreterInlines.h
1 /*
2  * Copyright (C) 2013-2016 Apple Inc. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
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.
12  *
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. 
24  */
25
26 #ifndef DFGAbstractInterpreterInlines_h
27 #define DFGAbstractInterpreterInlines_h
28
29 #if ENABLE(DFG_JIT)
30
31 #include "ArrayConstructor.h"
32 #include "DFGAbstractInterpreter.h"
33 #include "GetByIdStatus.h"
34 #include "GetterSetter.h"
35 #include "JITOperations.h"
36 #include "MathCommon.h"
37 #include "Operations.h"
38 #include "PutByIdStatus.h"
39 #include "StringObject.h"
40
41 namespace JSC { namespace DFG {
42
43 template<typename AbstractStateType>
44 AbstractInterpreter<AbstractStateType>::AbstractInterpreter(Graph& graph, AbstractStateType& state)
45     : m_codeBlock(graph.m_codeBlock)
46     , m_graph(graph)
47     , m_state(state)
48 {
49     if (m_graph.m_form == SSA)
50         m_phiChildren = std::make_unique<PhiChildren>(m_graph);
51 }
52
53 template<typename AbstractStateType>
54 AbstractInterpreter<AbstractStateType>::~AbstractInterpreter()
55 {
56 }
57
58 template<typename AbstractStateType>
59 typename AbstractInterpreter<AbstractStateType>::BooleanResult
60 AbstractInterpreter<AbstractStateType>::booleanResult(
61     Node* node, AbstractValue& value)
62 {
63     JSValue childConst = value.value();
64     if (childConst) {
65         if (childConst.toBoolean(m_codeBlock->globalObjectFor(node->origin.semantic)->globalExec()))
66             return DefinitelyTrue;
67         return DefinitelyFalse;
68     }
69
70     // Next check if we can fold because we know that the source is an object or string and does not equal undefined.
71     if (isCellSpeculation(value.m_type) && !value.m_structure.isTop()) {
72         bool allTrue = true;
73         for (unsigned i = value.m_structure.size(); i--;) {
74             Structure* structure = value.m_structure[i];
75             if (structure->masqueradesAsUndefined(m_codeBlock->globalObjectFor(node->origin.semantic))
76                 || structure->typeInfo().type() == StringType) {
77                 allTrue = false;
78                 break;
79             }
80         }
81         if (allTrue)
82             return DefinitelyTrue;
83     }
84     
85     return UnknownBooleanResult;
86 }
87
88 template<typename AbstractStateType>
89 void AbstractInterpreter<AbstractStateType>::startExecuting()
90 {
91     ASSERT(m_state.block());
92     ASSERT(m_state.isValid());
93     
94     m_state.setDidClobber(false);
95 }
96
97 template<typename AbstractStateType>
98 void AbstractInterpreter<AbstractStateType>::executeEdges(Node* node)
99 {
100     DFG_NODE_DO_TO_CHILDREN(m_graph, node, filterEdgeByUse);
101 }
102
103 template<typename AbstractStateType>
104 void AbstractInterpreter<AbstractStateType>::executeEdges(unsigned indexInBlock)
105 {
106     executeEdges(m_state.block()->at(indexInBlock));
107 }
108
109 template<typename AbstractStateType>
110 void AbstractInterpreter<AbstractStateType>::verifyEdge(Node* node, Edge edge)
111 {
112     // Some use kinds are required to not have checks, because we know somehow that the incoming
113     // value will already have the type we want. In those cases, AI may not be smart enough to
114     // prove that this is indeed the case.
115     if (shouldNotHaveTypeCheck(edge.useKind()))
116         return;
117     
118     if (!(forNode(edge).m_type & ~typeFilterFor(edge.useKind())))
119         return;
120     
121     DFG_CRASH(m_graph, node, toCString("Edge verification error: ", node, "->", edge, " was expected to have type ", SpeculationDump(typeFilterFor(edge.useKind())), " but has type ", SpeculationDump(forNode(edge).m_type), " (", forNode(edge).m_type, ")").data());
122 }
123
124 template<typename AbstractStateType>
125 void AbstractInterpreter<AbstractStateType>::verifyEdges(Node* node)
126 {
127     DFG_NODE_DO_TO_CHILDREN(m_graph, node, verifyEdge);
128 }
129
130 template<typename AbstractStateType>
131 bool AbstractInterpreter<AbstractStateType>::executeEffects(unsigned clobberLimit, Node* node)
132 {
133     if (!ASSERT_DISABLED)
134         verifyEdges(node);
135     
136     m_state.createValueForNode(node);
137     
138     switch (node->op()) {
139     case JSConstant:
140     case DoubleConstant:
141     case Int52Constant: {
142         setBuiltInConstant(node, *node->constant());
143         break;
144     }
145
146     case LazyJSConstant: {
147         LazyJSValue value = node->lazyJSValue();
148         switch (value.kind()) {
149         case LazyJSValue::KnownValue:
150             setConstant(node, value.value()->value());
151             break;
152         case LazyJSValue::SingleCharacterString:
153         case LazyJSValue::KnownStringImpl:
154         case LazyJSValue::NewStringImpl:
155             forNode(node).setType(m_graph, SpecString);
156             break;
157         }
158         break;
159     }
160         
161     case Identity: {
162         forNode(node) = forNode(node->child1());
163         if (forNode(node).value())
164             m_state.setFoundConstants(true);
165         break;
166     }
167         
168     case ExtractOSREntryLocal: {
169         forNode(node).makeBytecodeTop();
170         break;
171     }
172             
173     case GetLocal: {
174         VariableAccessData* variableAccessData = node->variableAccessData();
175         AbstractValue value = m_state.variables().operand(variableAccessData->local().offset());
176         // The value in the local should already be checked.
177         DFG_ASSERT(m_graph, node, value.isType(typeFilterFor(variableAccessData->flushFormat())));
178         if (value.value())
179             m_state.setFoundConstants(true);
180         forNode(node) = value;
181         break;
182     }
183         
184     case GetStack: {
185         StackAccessData* data = node->stackAccessData();
186         AbstractValue value = m_state.variables().operand(data->local);
187         // The value in the local should already be checked.
188         DFG_ASSERT(m_graph, node, value.isType(typeFilterFor(data->format)));
189         if (value.value())
190             m_state.setFoundConstants(true);
191         forNode(node) = value;
192         break;
193     }
194         
195     case GetLocalUnlinked: {
196         AbstractValue value = m_state.variables().operand(node->unlinkedLocal().offset());
197         if (value.value())
198             m_state.setFoundConstants(true);
199         forNode(node) = value;
200         break;
201     }
202         
203     case SetLocal: {
204         m_state.variables().operand(node->local()) = forNode(node->child1());
205         break;
206     }
207         
208     case PutStack: {
209         m_state.variables().operand(node->stackAccessData()->local) = forNode(node->child1());
210         break;
211     }
212         
213     case MovHint: {
214         // Don't need to do anything. A MovHint only informs us about what would have happened
215         // in bytecode, but this code is just concerned with what is actually happening during
216         // DFG execution.
217         break;
218     }
219         
220     case KillStack: {
221         // This is just a hint telling us that the OSR state of the local is no longer inside the
222         // flushed data.
223         break;
224     }
225         
226     case SetArgument:
227         // Assert that the state of arguments has been set. SetArgument means that someone set
228         // the argument values out-of-band, and currently this always means setting to a
229         // non-clear value.
230         ASSERT(!m_state.variables().operand(node->local()).isClear());
231         break;
232         
233     case LoadVarargs:
234     case ForwardVarargs: {
235         // FIXME: ForwardVarargs should check if the count becomes known, and if it does, it should turn
236         // itself into a straight-line sequence of GetStack/PutStack.
237         // https://bugs.webkit.org/show_bug.cgi?id=143071
238         clobberWorld(node->origin.semantic, clobberLimit);
239         LoadVarargsData* data = node->loadVarargsData();
240         m_state.variables().operand(data->count).setType(SpecInt32);
241         for (unsigned i = data->limit - 1; i--;)
242             m_state.variables().operand(data->start.offset() + i).makeHeapTop();
243         break;
244     }
245             
246     case BitAnd:
247     case BitOr:
248     case BitXor:
249     case BitRShift:
250     case BitLShift:
251     case BitURShift: {
252         if (node->child1().useKind() == UntypedUse || node->child2().useKind() == UntypedUse) {
253             clobberWorld(node->origin.semantic, clobberLimit);
254             forNode(node).setType(m_graph, SpecInt32);
255             break;
256         }
257
258         JSValue left = forNode(node->child1()).value();
259         JSValue right = forNode(node->child2()).value();
260         if (left && right && left.isInt32() && right.isInt32()) {
261             int32_t a = left.asInt32();
262             int32_t b = right.asInt32();
263             switch (node->op()) {
264             case BitAnd:
265                 setConstant(node, JSValue(a & b));
266                 break;
267             case BitOr:
268                 setConstant(node, JSValue(a | b));
269                 break;
270             case BitXor:
271                 setConstant(node, JSValue(a ^ b));
272                 break;
273             case BitRShift:
274                 setConstant(node, JSValue(a >> static_cast<uint32_t>(b)));
275                 break;
276             case BitLShift:
277                 setConstant(node, JSValue(a << static_cast<uint32_t>(b)));
278                 break;
279             case BitURShift:
280                 setConstant(node, JSValue(static_cast<uint32_t>(a) >> static_cast<uint32_t>(b)));
281                 break;
282             default:
283                 RELEASE_ASSERT_NOT_REACHED();
284                 break;
285             }
286             break;
287         }
288         
289         if (node->op() == BitAnd
290             && (isBoolInt32Speculation(forNode(node->child1()).m_type) ||
291                 isBoolInt32Speculation(forNode(node->child2()).m_type))) {
292             forNode(node).setType(SpecBoolInt32);
293             break;
294         }
295         
296         forNode(node).setType(SpecInt32);
297         break;
298     }
299         
300     case UInt32ToNumber: {
301         JSValue child = forNode(node->child1()).value();
302         if (doesOverflow(node->arithMode())) {
303             if (enableInt52()) {
304                 if (child && child.isMachineInt()) {
305                     setConstant(node, jsNumber(child.asMachineInt()));
306                     break;
307                 }
308                 forNode(node).setType(SpecMachineInt);
309                 break;
310             }
311             if (child && child.isInt32()) {
312                 uint32_t value = child.asInt32();
313                 setConstant(node, jsNumber(value));
314                 break;
315             }
316             forNode(node).setType(SpecInt52AsDouble);
317             break;
318         }
319         if (child && child.isInt32()) {
320             int32_t value = child.asInt32();
321             if (value >= 0) {
322                 setConstant(node, jsNumber(value));
323                 break;
324             }
325         }
326         forNode(node).setType(SpecInt32);
327         break;
328     }
329         
330     case BooleanToNumber: {
331         JSValue concreteValue = forNode(node->child1()).value();
332         if (concreteValue) {
333             if (concreteValue.isBoolean())
334                 setConstant(node, jsNumber(concreteValue.asBoolean()));
335             else
336                 setConstant(node, *m_graph.freeze(concreteValue));
337             break;
338         }
339         AbstractValue& value = forNode(node);
340         value = forNode(node->child1());
341         if (node->child1().useKind() == UntypedUse && !(value.m_type & ~SpecBoolean))
342             m_state.setFoundConstants(true);
343         if (value.m_type & SpecBoolean) {
344             value.merge(SpecBoolInt32);
345             value.filter(~SpecBoolean);
346         }
347         break;
348     }
349             
350     case DoubleAsInt32: {
351         JSValue child = forNode(node->child1()).value();
352         if (child && child.isNumber()) {
353             double asDouble = child.asNumber();
354             int32_t asInt = JSC::toInt32(asDouble);
355             if (bitwise_cast<int64_t>(static_cast<double>(asInt)) == bitwise_cast<int64_t>(asDouble)) {
356                 setConstant(node, JSValue(asInt));
357                 break;
358             }
359         }
360         forNode(node).setType(SpecInt32);
361         break;
362     }
363             
364     case ValueToInt32: {
365         JSValue child = forNode(node->child1()).value();
366         if (child) {
367             if (child.isNumber()) {
368                 if (child.isInt32())
369                     setConstant(node, child);
370                 else
371                     setConstant(node, JSValue(JSC::toInt32(child.asDouble())));
372                 break;
373             }
374             if (child.isBoolean()) {
375                 setConstant(node, jsNumber(child.asBoolean()));
376                 break;
377             }
378             if (child.isUndefinedOrNull()) {
379                 setConstant(node, jsNumber(0));
380                 break;
381             }
382         }
383         
384         if (isBooleanSpeculation(forNode(node->child1()).m_type)) {
385             forNode(node).setType(SpecBoolInt32);
386             break;
387         }
388         
389         forNode(node).setType(SpecInt32);
390         break;
391     }
392         
393     case DoubleRep: {
394         JSValue child = forNode(node->child1()).value();
395         if (child) {
396             if (child.isNumber()) {
397                 setConstant(node, jsDoubleNumber(child.asNumber()));
398                 break;
399             }
400             if (child.isUndefined()) {
401                 setConstant(node, jsDoubleNumber(PNaN));
402                 break;
403             }
404             if (child.isNull() || child.isFalse()) {
405                 setConstant(node, jsDoubleNumber(0));
406                 break;
407             }
408             if (child.isTrue()) {
409                 setConstant(node, jsDoubleNumber(1));
410                 break;
411             }
412         }
413
414         SpeculatedType type = forNode(node->child1()).m_type;
415         switch (node->child1().useKind()) {
416         case NotCellUse: {
417             if (type & SpecOther) {
418                 type &= ~SpecOther;
419                 type |= SpecDoublePureNaN | SpecBoolInt32; // Null becomes zero, undefined becomes NaN.
420             }
421             if (type & SpecBoolean) {
422                 type &= ~SpecBoolean;
423                 type |= SpecBoolInt32; // True becomes 1, false becomes 0.
424             }
425             type &= SpecBytecodeNumber;
426             break;
427         }
428
429         case Int52RepUse:
430         case NumberUse:
431         case RealNumberUse:
432             break;
433
434         default:
435             RELEASE_ASSERT_NOT_REACHED();
436         }
437         forNode(node).setType(type);
438         forNode(node).fixTypeForRepresentation(m_graph, node);
439         break;
440     }
441         
442     case Int52Rep: {
443         JSValue child = forNode(node->child1()).value();
444         if (child && child.isMachineInt()) {
445             setConstant(node, child);
446             break;
447         }
448         
449         forNode(node).setType(SpecInt32);
450         break;
451     }
452         
453     case ValueRep: {
454         JSValue value = forNode(node->child1()).value();
455         if (value) {
456             setConstant(node, value);
457             break;
458         }
459         
460         forNode(node).setType(m_graph, forNode(node->child1()).m_type & ~SpecDoubleImpureNaN);
461         forNode(node).fixTypeForRepresentation(m_graph, node);
462         break;
463     }
464         
465     case ValueAdd: {
466         ASSERT(node->binaryUseKind() == UntypedUse);
467         clobberWorld(node->origin.semantic, clobberLimit);
468         forNode(node).setType(m_graph, SpecString | SpecBytecodeNumber);
469         break;
470     }
471
472     case StrCat: {
473         forNode(node).setType(m_graph, SpecString);
474         break;
475     }
476         
477     case ArithAdd: {
478         JSValue left = forNode(node->child1()).value();
479         JSValue right = forNode(node->child2()).value();
480         switch (node->binaryUseKind()) {
481         case Int32Use:
482             if (left && right && left.isInt32() && right.isInt32()) {
483                 if (!shouldCheckOverflow(node->arithMode())) {
484                     setConstant(node, jsNumber(left.asInt32() + right.asInt32()));
485                     break;
486                 }
487                 JSValue result = jsNumber(left.asNumber() + right.asNumber());
488                 if (result.isInt32()) {
489                     setConstant(node, result);
490                     break;
491                 }
492             }
493             forNode(node).setType(SpecInt32);
494             break;
495         case Int52RepUse:
496             if (left && right && left.isMachineInt() && right.isMachineInt()) {
497                 JSValue result = jsNumber(left.asMachineInt() + right.asMachineInt());
498                 if (result.isMachineInt()) {
499                     setConstant(node, result);
500                     break;
501                 }
502             }
503             forNode(node).setType(SpecMachineInt);
504             break;
505         case DoubleRepUse:
506             if (left && right && left.isNumber() && right.isNumber()) {
507                 setConstant(node, jsDoubleNumber(left.asNumber() + right.asNumber()));
508                 break;
509             }
510             forNode(node).setType(
511                 typeOfDoubleSum(
512                     forNode(node->child1()).m_type, forNode(node->child2()).m_type));
513             break;
514         default:
515             RELEASE_ASSERT_NOT_REACHED();
516             break;
517         }
518         break;
519     }
520
521     case ArithClz32: {
522         JSValue operand = forNode(node->child1()).value();
523         if (operand && operand.isNumber()) {
524             uint32_t value = toUInt32(operand.asNumber());
525             setConstant(node, jsNumber(clz32(value)));
526             break;
527         }
528         forNode(node).setType(SpecInt32);
529         break;
530     }
531
532     case MakeRope: {
533         forNode(node).set(m_graph, m_graph.m_vm.stringStructure.get());
534         break;
535     }
536             
537     case ArithSub: {
538         JSValue left = forNode(node->child1()).value();
539         JSValue right = forNode(node->child2()).value();
540         switch (node->binaryUseKind()) {
541         case Int32Use:
542             if (left && right && left.isInt32() && right.isInt32()) {
543                 if (!shouldCheckOverflow(node->arithMode())) {
544                     setConstant(node, jsNumber(left.asInt32() - right.asInt32()));
545                     break;
546                 }
547                 JSValue result = jsNumber(left.asNumber() - right.asNumber());
548                 if (result.isInt32()) {
549                     setConstant(node, result);
550                     break;
551                 }
552             }
553             forNode(node).setType(SpecInt32);
554             break;
555         case Int52RepUse:
556             if (left && right && left.isMachineInt() && right.isMachineInt()) {
557                 JSValue result = jsNumber(left.asMachineInt() - right.asMachineInt());
558                 if (result.isMachineInt() || !shouldCheckOverflow(node->arithMode())) {
559                     setConstant(node, result);
560                     break;
561                 }
562             }
563             forNode(node).setType(SpecMachineInt);
564             break;
565         case DoubleRepUse:
566             if (left && right && left.isNumber() && right.isNumber()) {
567                 setConstant(node, jsDoubleNumber(left.asNumber() - right.asNumber()));
568                 break;
569             }
570             forNode(node).setType(
571                 typeOfDoubleDifference(
572                     forNode(node->child1()).m_type, forNode(node->child2()).m_type));
573             break;
574         case UntypedUse:
575             clobberWorld(node->origin.semantic, clobberLimit);
576             forNode(node).setType(m_graph, SpecBytecodeNumber);
577             break;
578         default:
579             RELEASE_ASSERT_NOT_REACHED();
580             break;
581         }
582         break;
583     }
584         
585     case ArithNegate: {
586         JSValue child = forNode(node->child1()).value();
587         switch (node->child1().useKind()) {
588         case Int32Use:
589             if (child && child.isInt32()) {
590                 if (!shouldCheckOverflow(node->arithMode())) {
591                     setConstant(node, jsNumber(-child.asInt32()));
592                     break;
593                 }
594                 double doubleResult;
595                 if (shouldCheckNegativeZero(node->arithMode()))
596                     doubleResult = -child.asNumber();
597                 else
598                     doubleResult = 0 - child.asNumber();
599                 JSValue valueResult = jsNumber(doubleResult);
600                 if (valueResult.isInt32()) {
601                     setConstant(node, valueResult);
602                     break;
603                 }
604             }
605             forNode(node).setType(SpecInt32);
606             break;
607         case Int52RepUse:
608             if (child && child.isMachineInt()) {
609                 double doubleResult;
610                 if (shouldCheckNegativeZero(node->arithMode()))
611                     doubleResult = -child.asNumber();
612                 else
613                     doubleResult = 0 - child.asNumber();
614                 JSValue valueResult = jsNumber(doubleResult);
615                 if (valueResult.isMachineInt()) {
616                     setConstant(node, valueResult);
617                     break;
618                 }
619             }
620             forNode(node).setType(SpecMachineInt);
621             break;
622         case DoubleRepUse:
623             if (child && child.isNumber()) {
624                 setConstant(node, jsDoubleNumber(-child.asNumber()));
625                 break;
626             }
627             forNode(node).setType(
628                 typeOfDoubleNegation(
629                     forNode(node->child1()).m_type));
630             break;
631         default:
632             RELEASE_ASSERT_NOT_REACHED();
633             break;
634         }
635         break;
636     }
637         
638     case ArithMul: {
639         JSValue left = forNode(node->child1()).value();
640         JSValue right = forNode(node->child2()).value();
641         switch (node->binaryUseKind()) {
642         case Int32Use:
643             if (left && right && left.isInt32() && right.isInt32()) {
644                 if (!shouldCheckOverflow(node->arithMode())) {
645                     setConstant(node, jsNumber(left.asInt32() * right.asInt32()));
646                     break;
647                 }
648                 double doubleResult = left.asNumber() * right.asNumber();
649                 if (!shouldCheckNegativeZero(node->arithMode()))
650                     doubleResult += 0; // Sanitizes zero.
651                 JSValue valueResult = jsNumber(doubleResult);
652                 if (valueResult.isInt32()) {
653                     setConstant(node, valueResult);
654                     break;
655                 }
656             }
657             forNode(node).setType(SpecInt32);
658             break;
659         case Int52RepUse:
660             if (left && right && left.isMachineInt() && right.isMachineInt()) {
661                 double doubleResult = left.asNumber() * right.asNumber();
662                 if (!shouldCheckNegativeZero(node->arithMode()))
663                     doubleResult += 0;
664                 JSValue valueResult = jsNumber(doubleResult);
665                 if (valueResult.isMachineInt()) {
666                     setConstant(node, valueResult);
667                     break;
668                 }
669             }
670             forNode(node).setType(SpecMachineInt);
671             break;
672         case DoubleRepUse:
673             if (left && right && left.isNumber() && right.isNumber()) {
674                 setConstant(node, jsDoubleNumber(left.asNumber() * right.asNumber()));
675                 break;
676             }
677             forNode(node).setType(
678                 typeOfDoubleProduct(
679                     forNode(node->child1()).m_type, forNode(node->child2()).m_type));
680             break;
681         case UntypedUse:
682             clobberWorld(node->origin.semantic, clobberLimit);
683             forNode(node).setType(m_graph, SpecBytecodeNumber);
684             break;
685         default:
686             RELEASE_ASSERT_NOT_REACHED();
687             break;
688         }
689         break;
690     }
691         
692     case ArithDiv: {
693         JSValue left = forNode(node->child1()).value();
694         JSValue right = forNode(node->child2()).value();
695         switch (node->binaryUseKind()) {
696         case Int32Use:
697             if (left && right && left.isInt32() && right.isInt32()) {
698                 double doubleResult = left.asNumber() / right.asNumber();
699                 if (!shouldCheckOverflow(node->arithMode()))
700                     doubleResult = toInt32(doubleResult);
701                 else if (!shouldCheckNegativeZero(node->arithMode()))
702                     doubleResult += 0; // Sanitizes zero.
703                 JSValue valueResult = jsNumber(doubleResult);
704                 if (valueResult.isInt32()) {
705                     setConstant(node, valueResult);
706                     break;
707                 }
708             }
709             forNode(node).setType(SpecInt32);
710             break;
711         case DoubleRepUse:
712             if (left && right && left.isNumber() && right.isNumber()) {
713                 setConstant(node, jsDoubleNumber(left.asNumber() / right.asNumber()));
714                 break;
715             }
716             forNode(node).setType(
717                 typeOfDoubleQuotient(
718                     forNode(node->child1()).m_type, forNode(node->child2()).m_type));
719             break;
720         case UntypedUse:
721             clobberWorld(node->origin.semantic, clobberLimit);
722             forNode(node).setType(m_graph, SpecBytecodeNumber);
723             break;
724         default:
725             RELEASE_ASSERT_NOT_REACHED();
726             break;
727         }
728         break;
729     }
730
731     case ArithMod: {
732         JSValue left = forNode(node->child1()).value();
733         JSValue right = forNode(node->child2()).value();
734         switch (node->binaryUseKind()) {
735         case Int32Use:
736             if (left && right && left.isInt32() && right.isInt32()) {
737                 double doubleResult = fmod(left.asNumber(), right.asNumber());
738                 if (!shouldCheckOverflow(node->arithMode()))
739                     doubleResult = toInt32(doubleResult);
740                 else if (!shouldCheckNegativeZero(node->arithMode()))
741                     doubleResult += 0; // Sanitizes zero.
742                 JSValue valueResult = jsNumber(doubleResult);
743                 if (valueResult.isInt32()) {
744                     setConstant(node, valueResult);
745                     break;
746                 }
747             }
748             forNode(node).setType(SpecInt32);
749             break;
750         case DoubleRepUse:
751             if (left && right && left.isNumber() && right.isNumber()) {
752                 setConstant(node, jsDoubleNumber(fmod(left.asNumber(), right.asNumber())));
753                 break;
754             }
755             forNode(node).setType(
756                 typeOfDoubleBinaryOp(
757                     forNode(node->child1()).m_type, forNode(node->child2()).m_type));
758             break;
759         default:
760             RELEASE_ASSERT_NOT_REACHED();
761             break;
762         }
763         break;
764     }
765
766     case ArithMin: {
767         JSValue left = forNode(node->child1()).value();
768         JSValue right = forNode(node->child2()).value();
769         switch (node->binaryUseKind()) {
770         case Int32Use:
771             if (left && right && left.isInt32() && right.isInt32()) {
772                 setConstant(node, jsNumber(std::min(left.asInt32(), right.asInt32())));
773                 break;
774             }
775             forNode(node).setType(SpecInt32);
776             break;
777         case DoubleRepUse:
778             if (left && right && left.isNumber() && right.isNumber()) {
779                 double a = left.asNumber();
780                 double b = right.asNumber();
781                 setConstant(node, jsDoubleNumber(a < b ? a : (b <= a ? b : a + b)));
782                 break;
783             }
784             forNode(node).setType(
785                 typeOfDoubleMinMax(
786                     forNode(node->child1()).m_type, forNode(node->child2()).m_type));
787             break;
788         default:
789             RELEASE_ASSERT_NOT_REACHED();
790             break;
791         }
792         break;
793     }
794             
795     case ArithMax: {
796         JSValue left = forNode(node->child1()).value();
797         JSValue right = forNode(node->child2()).value();
798         switch (node->binaryUseKind()) {
799         case Int32Use:
800             if (left && right && left.isInt32() && right.isInt32()) {
801                 setConstant(node, jsNumber(std::max(left.asInt32(), right.asInt32())));
802                 break;
803             }
804             forNode(node).setType(SpecInt32);
805             break;
806         case DoubleRepUse:
807             if (left && right && left.isNumber() && right.isNumber()) {
808                 double a = left.asNumber();
809                 double b = right.asNumber();
810                 setConstant(node, jsDoubleNumber(a > b ? a : (b >= a ? b : a + b)));
811                 break;
812             }
813             forNode(node).setType(
814                 typeOfDoubleMinMax(
815                     forNode(node->child1()).m_type, forNode(node->child2()).m_type));
816             break;
817         default:
818             RELEASE_ASSERT_NOT_REACHED();
819             break;
820         }
821         break;
822     }
823             
824     case ArithAbs: {
825         JSValue child = forNode(node->child1()).value();
826         switch (node->child1().useKind()) {
827         case Int32Use:
828             if (child && child.isInt32()) {
829                 JSValue result = jsNumber(fabs(child.asNumber()));
830                 if (result.isInt32()) {
831                     setConstant(node, result);
832                     break;
833                 }
834             }
835             forNode(node).setType(SpecInt32);
836             break;
837         case DoubleRepUse:
838             if (child && child.isNumber()) {
839                 setConstant(node, jsDoubleNumber(fabs(child.asNumber())));
840                 break;
841             }
842             forNode(node).setType(typeOfDoubleAbs(forNode(node->child1()).m_type));
843             break;
844         default:
845             RELEASE_ASSERT_NOT_REACHED();
846             break;
847         }
848         break;
849     }
850
851     case ArithPow: {
852         JSValue childY = forNode(node->child2()).value();
853         if (childY && childY.isNumber()) {
854             if (!childY.asNumber()) {
855                 setConstant(node, jsDoubleNumber(1));
856                 break;
857             }
858
859             JSValue childX = forNode(node->child1()).value();
860             if (childX && childX.isNumber()) {
861                 setConstant(node, jsDoubleNumber(operationMathPow(childX.asNumber(), childY.asNumber())));
862                 break;
863             }
864         }
865         forNode(node).setType(typeOfDoublePow(forNode(node->child1()).m_type, forNode(node->child2()).m_type));
866         break;
867     }
868
869     case ArithRandom: {
870         forNode(node).setType(m_graph, SpecDoubleReal);
871         break;
872     }
873
874     case ArithRound:
875     case ArithFloor:
876     case ArithCeil:
877     case ArithTrunc: {
878         JSValue operand = forNode(node->child1()).value();
879         if (operand && operand.isNumber()) {
880             double roundedValue = 0;
881             if (node->op() == ArithRound)
882                 roundedValue = jsRound(operand.asNumber());
883             else if (node->op() == ArithFloor)
884                 roundedValue = floor(operand.asNumber());
885             else if (node->op() == ArithCeil)
886                 roundedValue = ceil(operand.asNumber());
887             else {
888                 ASSERT(node->op() == ArithTrunc);
889                 roundedValue = trunc(operand.asNumber());
890             }
891
892             if (producesInteger(node->arithRoundingMode())) {
893                 int32_t roundedValueAsInt32 = static_cast<int32_t>(roundedValue);
894                 if (roundedValueAsInt32 == roundedValue) {
895                     if (shouldCheckNegativeZero(node->arithRoundingMode())) {
896                         if (roundedValueAsInt32 || !std::signbit(roundedValue)) {
897                             setConstant(node, jsNumber(roundedValueAsInt32));
898                             break;
899                         }
900                     } else {
901                         setConstant(node, jsNumber(roundedValueAsInt32));
902                         break;
903                     }
904                 }
905             } else {
906                 setConstant(node, jsDoubleNumber(roundedValue));
907                 break;
908             }
909         }
910         if (producesInteger(node->arithRoundingMode()))
911             forNode(node).setType(SpecInt32);
912         else
913             forNode(node).setType(typeOfDoubleRounding(forNode(node->child1()).m_type));
914         break;
915     }
916             
917     case ArithSqrt: {
918         JSValue child = forNode(node->child1()).value();
919         if (child && child.isNumber()) {
920             setConstant(node, jsDoubleNumber(sqrt(child.asNumber())));
921             break;
922         }
923         forNode(node).setType(typeOfDoubleUnaryOp(forNode(node->child1()).m_type));
924         break;
925     }
926         
927     case ArithFRound: {
928         JSValue child = forNode(node->child1()).value();
929         if (child && child.isNumber()) {
930             setConstant(node, jsDoubleNumber(static_cast<float>(child.asNumber())));
931             break;
932         }
933         forNode(node).setType(typeOfDoubleRounding(forNode(node->child1()).m_type));
934         break;
935     }
936         
937     case ArithSin: {
938         JSValue child = forNode(node->child1()).value();
939         if (child && child.isNumber()) {
940             setConstant(node, jsDoubleNumber(sin(child.asNumber())));
941             break;
942         }
943         forNode(node).setType(typeOfDoubleUnaryOp(forNode(node->child1()).m_type));
944         break;
945     }
946     
947     case ArithCos: {
948         JSValue child = forNode(node->child1()).value();
949         if (child && child.isNumber()) {
950             setConstant(node, jsDoubleNumber(cos(child.asNumber())));
951             break;
952         }
953         forNode(node).setType(typeOfDoubleUnaryOp(forNode(node->child1()).m_type));
954         break;
955     }
956
957     case ArithLog: {
958         JSValue child = forNode(node->child1()).value();
959         if (child && child.isNumber()) {
960             setConstant(node, jsDoubleNumber(log(child.asNumber())));
961             break;
962         }
963         forNode(node).setType(typeOfDoubleUnaryOp(forNode(node->child1()).m_type));
964         break;
965     }
966             
967     case LogicalNot: {
968         switch (booleanResult(node, forNode(node->child1()))) {
969         case DefinitelyTrue:
970             setConstant(node, jsBoolean(false));
971             break;
972         case DefinitelyFalse:
973             setConstant(node, jsBoolean(true));
974             break;
975         default:
976             forNode(node).setType(SpecBoolean);
977             break;
978         }
979         break;
980     }
981
982     case IsArrayObject:
983     case IsJSArray:
984     case IsArrayConstructor:
985     case IsUndefined:
986     case IsBoolean:
987     case IsNumber:
988     case IsString:
989     case IsObject:
990     case IsObjectOrNull:
991     case IsFunction: {
992         AbstractValue child = forNode(node->child1());
993         if (child.value()) {
994             bool constantWasSet = true;
995             switch (node->op()) {
996             case IsArrayObject:
997                 if (child.value().isObject()) {
998                     if (child.value().getObject()->type() == ArrayType) {
999                         setConstant(node, jsBoolean(true));
1000                         break;
1001                     }
1002
1003                     if (child.value().getObject()->type() == ProxyObjectType) {
1004                         // We have no way of knowing what type we are proxing yet.
1005                         constantWasSet = false;
1006                         break;
1007                     }
1008                 }
1009
1010                 setConstant(node, jsBoolean(false));
1011                 break;
1012             case IsJSArray:
1013                 setConstant(node, jsBoolean(child.value().isObject() && child.value().getObject()->type() == ArrayType));
1014                 break;
1015             case IsArrayConstructor:
1016                 setConstant(node, jsBoolean(child.value().isObject() && child.value().getObject()->classInfo() == ArrayConstructor::info()));
1017                 break;
1018             case IsUndefined:
1019                 setConstant(node, jsBoolean(
1020                     child.value().isCell()
1021                     ? child.value().asCell()->structure()->masqueradesAsUndefined(m_codeBlock->globalObjectFor(node->origin.semantic))
1022                     : child.value().isUndefined()));
1023                 break;
1024             case IsBoolean:
1025                 setConstant(node, jsBoolean(child.value().isBoolean()));
1026                 break;
1027             case IsNumber:
1028                 setConstant(node, jsBoolean(child.value().isNumber()));
1029                 break;
1030             case IsString:
1031                 setConstant(node, jsBoolean(isJSString(child.value())));
1032                 break;
1033             case IsObject:
1034                 setConstant(node, jsBoolean(child.value().isObject()));
1035                 break;
1036             case IsObjectOrNull:
1037                 if (child.value().isObject()) {
1038                     JSObject* object = asObject(child.value());
1039                     if (object->type() == JSFunctionType)
1040                         setConstant(node, jsBoolean(false));
1041                     else if (!(object->inlineTypeFlags() & TypeOfShouldCallGetCallData))
1042                         setConstant(node, jsBoolean(!child.value().asCell()->structure()->masqueradesAsUndefined(m_codeBlock->globalObjectFor(node->origin.semantic))));
1043                     else {
1044                         // FIXME: This could just call getCallData.
1045                         // https://bugs.webkit.org/show_bug.cgi?id=144457
1046                         constantWasSet = false;
1047                     }
1048                 } else
1049                     setConstant(node, jsBoolean(child.value().isNull()));
1050                 break;
1051             case IsFunction:
1052                 if (child.value().isObject()) {
1053                     JSObject* object = asObject(child.value());
1054                     if (object->type() == JSFunctionType)
1055                         setConstant(node, jsBoolean(true));
1056                     else if (!(object->inlineTypeFlags() & TypeOfShouldCallGetCallData))
1057                         setConstant(node, jsBoolean(false));
1058                     else {
1059                         // FIXME: This could just call getCallData.
1060                         // https://bugs.webkit.org/show_bug.cgi?id=144457
1061                         constantWasSet = false;
1062                     }
1063                 } else
1064                     setConstant(node, jsBoolean(false));
1065                 break;
1066             default:
1067                 constantWasSet = false;
1068                 break;
1069             }
1070             if (constantWasSet)
1071                 break;
1072         }
1073         
1074         // FIXME: This code should really use AbstractValue::isType() and
1075         // AbstractValue::couldBeType().
1076         // https://bugs.webkit.org/show_bug.cgi?id=146870
1077         
1078         bool constantWasSet = false;
1079         switch (node->op()) {
1080         case IsJSArray:
1081         case IsArrayObject:
1082             // We don't have a SpeculatedType for Proxies yet so we can't do better at proving false.
1083             if (!(child.m_type & ~SpecArray)) {
1084                 setConstant(node, jsBoolean(true));
1085                 constantWasSet = true;
1086                 break;
1087             }
1088
1089             if (!(child.m_type & SpecObject)) {
1090                 setConstant(node, jsBoolean(false));
1091                 constantWasSet = true;
1092                 break;
1093             }
1094
1095             break;
1096         case IsUndefined:
1097             // FIXME: Use the masquerades-as-undefined watchpoint thingy.
1098             // https://bugs.webkit.org/show_bug.cgi?id=144456
1099             
1100             if (!(child.m_type & (SpecOther | SpecObjectOther))) {
1101                 setConstant(node, jsBoolean(false));
1102                 constantWasSet = true;
1103                 break;
1104             }
1105             
1106             break;
1107         case IsBoolean:
1108             if (!(child.m_type & ~SpecBoolean)) {
1109                 setConstant(node, jsBoolean(true));
1110                 constantWasSet = true;
1111                 break;
1112             }
1113             
1114             if (!(child.m_type & SpecBoolean)) {
1115                 setConstant(node, jsBoolean(false));
1116                 constantWasSet = true;
1117                 break;
1118             }
1119             
1120             break;
1121         case IsNumber:
1122             if (!(child.m_type & ~SpecFullNumber)) {
1123                 setConstant(node, jsBoolean(true));
1124                 constantWasSet = true;
1125                 break;
1126             }
1127             
1128             if (!(child.m_type & SpecFullNumber)) {
1129                 setConstant(node, jsBoolean(false));
1130                 constantWasSet = true;
1131                 break;
1132             }
1133             
1134             break;
1135         case IsString:
1136             if (!(child.m_type & ~SpecString)) {
1137                 setConstant(node, jsBoolean(true));
1138                 constantWasSet = true;
1139                 break;
1140             }
1141             
1142             if (!(child.m_type & SpecString)) {
1143                 setConstant(node, jsBoolean(false));
1144                 constantWasSet = true;
1145                 break;
1146             }
1147             
1148             break;
1149         case IsObject:
1150             if (!(child.m_type & ~SpecObject)) {
1151                 setConstant(node, jsBoolean(true));
1152                 constantWasSet = true;
1153                 break;
1154             }
1155             
1156             if (!(child.m_type & SpecObject)) {
1157                 setConstant(node, jsBoolean(false));
1158                 constantWasSet = true;
1159                 break;
1160             }
1161             
1162             break;
1163         case IsObjectOrNull:
1164             // FIXME: Use the masquerades-as-undefined watchpoint thingy.
1165             // https://bugs.webkit.org/show_bug.cgi?id=144456
1166             
1167             // These expressions are complicated to parse. A helpful way to parse this is that
1168             // "!(T & ~S)" means "T is a subset of S". Conversely, "!(T & S)" means "T is a
1169             // disjoint set from S". Things like "T - S" means that, provided that S is a
1170             // subset of T, it's the "set of all things in T but not in S". Things like "T | S"
1171             // mean the "union of T and S".
1172             
1173             // Is the child's type an object that isn't an other-object (i.e. object that could
1174             // have masquaredes-as-undefined traps) and isn't a function?  Then: we should fold
1175             // this to true.
1176             if (!(child.m_type & ~(SpecObject - SpecObjectOther - SpecFunction))) {
1177                 setConstant(node, jsBoolean(true));
1178                 constantWasSet = true;
1179                 break;
1180             }
1181             
1182             // Is the child's type definitely not either of: an object that isn't a function,
1183             // or either undefined or null?  Then: we should fold this to false.  This means
1184             // for example that if it's any non-function object, including those that have
1185             // masquerades-as-undefined traps, then we don't fold. It also means we won't fold
1186             // if it's undefined-or-null, since the type bits don't distinguish between
1187             // undefined (which should fold to false) and null (which should fold to true).
1188             if (!(child.m_type & ((SpecObject - SpecFunction) | SpecOther))) {
1189                 setConstant(node, jsBoolean(false));
1190                 constantWasSet = true;
1191                 break;
1192             }
1193             
1194             break;
1195         case IsFunction:
1196             if (!(child.m_type & ~SpecFunction)) {
1197                 setConstant(node, jsBoolean(true));
1198                 constantWasSet = true;
1199                 break;
1200             }
1201             
1202             if (!(child.m_type & (SpecFunction | SpecObjectOther))) {
1203                 setConstant(node, jsBoolean(false));
1204                 constantWasSet = true;
1205                 break;
1206             }
1207             break;
1208         default:
1209             break;
1210         }
1211         if (constantWasSet)
1212             break;
1213         
1214         forNode(node).setType(SpecBoolean);
1215         break;
1216     }
1217
1218     case TypeOf: {
1219         VM* vm = m_codeBlock->vm();
1220         JSValue child = forNode(node->child1()).value();
1221         AbstractValue& abstractChild = forNode(node->child1());
1222         if (child) {
1223             JSValue typeString = jsTypeStringForValue(*vm, m_codeBlock->globalObjectFor(node->origin.semantic), child);
1224             setConstant(node, *m_graph.freeze(typeString));
1225             break;
1226         }
1227         
1228         if (isFullNumberSpeculation(abstractChild.m_type)) {
1229             setConstant(node, *m_graph.freeze(vm->smallStrings.numberString()));
1230             break;
1231         }
1232         
1233         if (isStringSpeculation(abstractChild.m_type)) {
1234             setConstant(node, *m_graph.freeze(vm->smallStrings.stringString()));
1235             break;
1236         }
1237
1238         // FIXME: We could use the masquerades-as-undefined watchpoint here.
1239         // https://bugs.webkit.org/show_bug.cgi?id=144456
1240         if (!(abstractChild.m_type & ~(SpecObject - SpecObjectOther - SpecFunction))) {
1241             setConstant(node, *m_graph.freeze(vm->smallStrings.objectString()));
1242             break;
1243         }
1244         
1245         if (isFunctionSpeculation(abstractChild.m_type)) {
1246             setConstant(node, *m_graph.freeze(vm->smallStrings.functionString()));
1247             break;
1248         }
1249         
1250         if (isBooleanSpeculation(abstractChild.m_type)) {
1251             setConstant(node, *m_graph.freeze(vm->smallStrings.booleanString()));
1252             break;
1253         }
1254
1255         if (isSymbolSpeculation(abstractChild.m_type)) {
1256             setConstant(node, *m_graph.freeze(vm->smallStrings.symbolString()));
1257             break;
1258         }
1259
1260         forNode(node).setType(m_graph, SpecStringIdent);
1261         break;
1262     }
1263             
1264     case CompareLess:
1265     case CompareLessEq:
1266     case CompareGreater:
1267     case CompareGreaterEq:
1268     case CompareEq: {
1269         JSValue leftConst = forNode(node->child1()).value();
1270         JSValue rightConst = forNode(node->child2()).value();
1271         if (leftConst && rightConst) {
1272             if (leftConst.isNumber() && rightConst.isNumber()) {
1273                 double a = leftConst.asNumber();
1274                 double b = rightConst.asNumber();
1275                 switch (node->op()) {
1276                 case CompareLess:
1277                     setConstant(node, jsBoolean(a < b));
1278                     break;
1279                 case CompareLessEq:
1280                     setConstant(node, jsBoolean(a <= b));
1281                     break;
1282                 case CompareGreater:
1283                     setConstant(node, jsBoolean(a > b));
1284                     break;
1285                 case CompareGreaterEq:
1286                     setConstant(node, jsBoolean(a >= b));
1287                     break;
1288                 case CompareEq:
1289                     setConstant(node, jsBoolean(a == b));
1290                     break;
1291                 default:
1292                     RELEASE_ASSERT_NOT_REACHED();
1293                     break;
1294                 }
1295                 break;
1296             }
1297             
1298             if (node->op() == CompareEq && leftConst.isString() && rightConst.isString()) {
1299                 const StringImpl* a = asString(leftConst)->tryGetValueImpl();
1300                 const StringImpl* b = asString(rightConst)->tryGetValueImpl();
1301                 if (a && b) {
1302                     setConstant(node, jsBoolean(WTF::equal(a, b)));
1303                     break;
1304                 }
1305             }
1306
1307             if (node->op() == CompareEq && leftConst.isSymbol() && rightConst.isSymbol()) {
1308                 setConstant(node, jsBoolean(asSymbol(leftConst)->privateName() == asSymbol(rightConst)->privateName()));
1309                 break;
1310             }
1311         }
1312         
1313         if (node->op() == CompareEq) {
1314             SpeculatedType leftType = forNode(node->child1()).m_type;
1315             SpeculatedType rightType = forNode(node->child2()).m_type;
1316             if (!valuesCouldBeEqual(leftType, rightType)) {
1317                 setConstant(node, jsBoolean(false));
1318                 break;
1319             }
1320
1321             if (leftType == SpecOther)
1322                 std::swap(leftType, rightType);
1323             if (rightType == SpecOther) {
1324                 // Undefined and Null are always equal when compared to eachother.
1325                 if (!(leftType & ~SpecOther)) {
1326                     setConstant(node, jsBoolean(true));
1327                     break;
1328                 }
1329
1330                 // Any other type compared to Null or Undefined is always false
1331                 // as long as the MasqueradesAsUndefined watchpoint is valid.
1332                 //
1333                 // MasqueradesAsUndefined only matters for SpecObjectOther, other
1334                 // cases are always "false".
1335                 if (!(leftType & (SpecObjectOther | SpecOther))) {
1336                     setConstant(node, jsBoolean(false));
1337                     break;
1338                 }
1339
1340                 if (!(leftType & SpecOther) && m_graph.masqueradesAsUndefinedWatchpointIsStillValid(node->origin.semantic)) {
1341                     JSGlobalObject* globalObject = m_graph.globalObjectFor(node->origin.semantic);
1342                     m_graph.watchpoints().addLazily(globalObject->masqueradesAsUndefinedWatchpoint());
1343                     setConstant(node, jsBoolean(false));
1344                     break;
1345                 }
1346             }
1347         }
1348         
1349         if (node->child1() == node->child2()) {
1350             if (node->isBinaryUseKind(Int32Use) ||
1351                 node->isBinaryUseKind(Int52RepUse) ||
1352                 node->isBinaryUseKind(StringUse) ||
1353                 node->isBinaryUseKind(BooleanUse) ||
1354                 node->isBinaryUseKind(SymbolUse) ||
1355                 node->isBinaryUseKind(StringIdentUse) ||
1356                 node->isBinaryUseKind(ObjectUse) ||
1357                 node->isBinaryUseKind(ObjectUse, ObjectOrOtherUse) ||
1358                 node->isBinaryUseKind(ObjectOrOtherUse, ObjectUse)) {
1359                 switch (node->op()) {
1360                 case CompareLess:
1361                 case CompareGreater:
1362                     setConstant(node, jsBoolean(false));
1363                     break;
1364                 case CompareLessEq:
1365                 case CompareGreaterEq:
1366                 case CompareEq:
1367                     setConstant(node, jsBoolean(true));
1368                     break;
1369                 default:
1370                     DFG_CRASH(m_graph, node, "Unexpected node type");
1371                     break;
1372                 }
1373                 break;
1374             }
1375         }
1376         
1377         forNode(node).setType(SpecBoolean);
1378         break;
1379     }
1380             
1381     case CompareStrictEq: {
1382         Node* leftNode = node->child1().node();
1383         Node* rightNode = node->child2().node();
1384         JSValue left = forNode(leftNode).value();
1385         JSValue right = forNode(rightNode).value();
1386         if (left && right) {
1387             if (left.isString() && right.isString()) {
1388                 // We need this case because JSValue::strictEqual is otherwise too racy for
1389                 // string comparisons.
1390                 const StringImpl* a = asString(left)->tryGetValueImpl();
1391                 const StringImpl* b = asString(right)->tryGetValueImpl();
1392                 if (a && b) {
1393                     setConstant(node, jsBoolean(WTF::equal(a, b)));
1394                     break;
1395                 }
1396             } else {
1397                 setConstant(node, jsBoolean(JSValue::strictEqual(0, left, right)));
1398                 break;
1399             }
1400         }
1401         
1402         SpeculatedType leftLUB = leastUpperBoundOfStrictlyEquivalentSpeculations(forNode(leftNode).m_type);
1403         SpeculatedType rightLUB = leastUpperBoundOfStrictlyEquivalentSpeculations(forNode(rightNode).m_type);
1404         if (!(leftLUB & rightLUB)) {
1405             setConstant(node, jsBoolean(false));
1406             break;
1407         }
1408         
1409         if (node->child1() == node->child2()) {
1410             if (node->isBinaryUseKind(BooleanUse) ||
1411                 node->isBinaryUseKind(Int32Use) ||
1412                 node->isBinaryUseKind(Int52RepUse) ||
1413                 node->isBinaryUseKind(StringUse) ||
1414                 node->isBinaryUseKind(StringIdentUse) ||
1415                 node->isBinaryUseKind(SymbolUse) ||
1416                 node->isBinaryUseKind(ObjectUse) ||
1417                 node->isBinaryUseKind(MiscUse, UntypedUse) ||
1418                 node->isBinaryUseKind(UntypedUse, MiscUse) ||
1419                 node->isBinaryUseKind(StringIdentUse, NotStringVarUse) ||
1420                 node->isBinaryUseKind(NotStringVarUse, StringIdentUse) ||
1421                 node->isBinaryUseKind(StringUse, UntypedUse) ||
1422                 node->isBinaryUseKind(UntypedUse, StringUse)) {
1423                 setConstant(node, jsBoolean(true));
1424                 break;
1425             }
1426         }
1427
1428         forNode(node).setType(SpecBoolean);
1429         break;
1430     }
1431         
1432     case StringCharCodeAt:
1433         forNode(node).setType(SpecInt32);
1434         break;
1435         
1436     case StringFromCharCode:
1437         forNode(node).setType(m_graph, SpecString);
1438         break;
1439
1440     case StringCharAt:
1441         forNode(node).set(m_graph, m_graph.m_vm.stringStructure.get());
1442         break;
1443             
1444     case GetByVal: {
1445         switch (node->arrayMode().type()) {
1446         case Array::SelectUsingPredictions:
1447         case Array::Unprofiled:
1448         case Array::SelectUsingArguments:
1449             RELEASE_ASSERT_NOT_REACHED();
1450             break;
1451         case Array::ForceExit:
1452             m_state.setIsValid(false);
1453             break;
1454         case Array::Undecided: {
1455             JSValue index = forNode(node->child2()).value();
1456             if (index && index.isInt32() && index.asInt32() >= 0) {
1457                 setConstant(node, jsUndefined());
1458                 break;
1459             }
1460             forNode(node).setType(SpecOther);
1461             break;
1462         }
1463         case Array::Generic:
1464             clobberWorld(node->origin.semantic, clobberLimit);
1465             forNode(node).makeHeapTop();
1466             break;
1467         case Array::String:
1468             if (node->arrayMode().isOutOfBounds()) {
1469                 // If the watchpoint was still valid we could totally set this to be
1470                 // SpecString | SpecOther. Except that we'd have to be careful. If we
1471                 // tested the watchpoint state here then it could change by the time
1472                 // we got to the backend. So to do this right, we'd have to get the
1473                 // fixup phase to check the watchpoint state and then bake into the
1474                 // GetByVal operation the fact that we're using a watchpoint, using
1475                 // something like Array::SaneChain (except not quite, because that
1476                 // implies an in-bounds access). None of this feels like it's worth it,
1477                 // so we're going with TOP for now. The same thing applies to
1478                 // clobbering the world.
1479                 clobberWorld(node->origin.semantic, clobberLimit);
1480                 forNode(node).makeHeapTop();
1481             } else
1482                 forNode(node).set(m_graph, m_graph.m_vm.stringStructure.get());
1483             break;
1484         case Array::DirectArguments:
1485         case Array::ScopedArguments:
1486             forNode(node).makeHeapTop();
1487             break;
1488         case Array::Int32:
1489             if (node->arrayMode().isOutOfBounds()) {
1490                 clobberWorld(node->origin.semantic, clobberLimit);
1491                 forNode(node).makeHeapTop();
1492             } else
1493                 forNode(node).setType(SpecInt32);
1494             break;
1495         case Array::Double:
1496             if (node->arrayMode().isOutOfBounds()) {
1497                 clobberWorld(node->origin.semantic, clobberLimit);
1498                 forNode(node).makeHeapTop();
1499             } else if (node->arrayMode().isSaneChain())
1500                 forNode(node).setType(SpecBytecodeDouble);
1501             else
1502                 forNode(node).setType(SpecDoubleReal);
1503             break;
1504         case Array::Contiguous:
1505         case Array::ArrayStorage:
1506         case Array::SlowPutArrayStorage:
1507             if (node->arrayMode().isOutOfBounds())
1508                 clobberWorld(node->origin.semantic, clobberLimit);
1509             forNode(node).makeHeapTop();
1510             break;
1511         case Array::Int8Array:
1512             forNode(node).setType(SpecInt32);
1513             break;
1514         case Array::Int16Array:
1515             forNode(node).setType(SpecInt32);
1516             break;
1517         case Array::Int32Array:
1518             forNode(node).setType(SpecInt32);
1519             break;
1520         case Array::Uint8Array:
1521             forNode(node).setType(SpecInt32);
1522             break;
1523         case Array::Uint8ClampedArray:
1524             forNode(node).setType(SpecInt32);
1525             break;
1526         case Array::Uint16Array:
1527             forNode(node).setType(SpecInt32);
1528             break;
1529         case Array::Uint32Array:
1530             if (node->shouldSpeculateInt32())
1531                 forNode(node).setType(SpecInt32);
1532             else if (enableInt52() && node->shouldSpeculateMachineInt())
1533                 forNode(node).setType(SpecInt52);
1534             else
1535                 forNode(node).setType(SpecInt52AsDouble);
1536             break;
1537         case Array::Float32Array:
1538             forNode(node).setType(SpecFullDouble);
1539             break;
1540         case Array::Float64Array:
1541             forNode(node).setType(SpecFullDouble);
1542             break;
1543         default:
1544             RELEASE_ASSERT_NOT_REACHED();
1545             break;
1546         }
1547         break;
1548     }
1549             
1550     case PutByValDirect:
1551     case PutByVal:
1552     case PutByValAlias: {
1553         switch (node->arrayMode().modeForPut().type()) {
1554         case Array::ForceExit:
1555             m_state.setIsValid(false);
1556             break;
1557         case Array::Generic:
1558             clobberWorld(node->origin.semantic, clobberLimit);
1559             break;
1560         case Array::Int32:
1561             if (node->arrayMode().isOutOfBounds())
1562                 clobberWorld(node->origin.semantic, clobberLimit);
1563             break;
1564         case Array::Double:
1565             if (node->arrayMode().isOutOfBounds())
1566                 clobberWorld(node->origin.semantic, clobberLimit);
1567             break;
1568         case Array::Contiguous:
1569         case Array::ArrayStorage:
1570             if (node->arrayMode().isOutOfBounds())
1571                 clobberWorld(node->origin.semantic, clobberLimit);
1572             break;
1573         case Array::SlowPutArrayStorage:
1574             if (node->arrayMode().mayStoreToHole())
1575                 clobberWorld(node->origin.semantic, clobberLimit);
1576             break;
1577         default:
1578             break;
1579         }
1580         break;
1581     }
1582             
1583     case ArrayPush:
1584         clobberWorld(node->origin.semantic, clobberLimit);
1585         forNode(node).setType(SpecBytecodeNumber);
1586         break;
1587             
1588     case ArrayPop:
1589         clobberWorld(node->origin.semantic, clobberLimit);
1590         forNode(node).makeHeapTop();
1591         break;
1592         
1593     case GetMyArgumentByVal: {
1594         JSValue index = forNode(node->child2()).m_value;
1595         InlineCallFrame* inlineCallFrame = node->child1()->origin.semantic.inlineCallFrame;
1596
1597         if (index && index.isInt32()) {
1598             // This pretends to return TOP for accesses that are actually proven out-of-bounds because
1599             // that's the conservative thing to do. Otherwise we'd need to write more code to mark such
1600             // paths as unreachable, and it's almost certainly not worth the effort.
1601             
1602             if (inlineCallFrame) {
1603                 if (index.asUInt32() < inlineCallFrame->arguments.size() - 1) {
1604                     forNode(node) = m_state.variables().operand(
1605                         virtualRegisterForArgument(index.asInt32() + 1) + inlineCallFrame->stackOffset);
1606                     m_state.setFoundConstants(true);
1607                     break;
1608                 }
1609             } else {
1610                 if (index.asUInt32() < m_state.variables().numberOfArguments() - 1) {
1611                     forNode(node) = m_state.variables().argument(index.asInt32() + 1);
1612                     m_state.setFoundConstants(true);
1613                     break;
1614                 }
1615             }
1616         }
1617         
1618         if (inlineCallFrame) {
1619             // We have a bound on the types even though it's random access. Take advantage of this.
1620             
1621             AbstractValue result;
1622             for (unsigned i = inlineCallFrame->arguments.size(); i-- > 1;) {
1623                 result.merge(
1624                     m_state.variables().operand(
1625                         virtualRegisterForArgument(i) + inlineCallFrame->stackOffset));
1626             }
1627             
1628             if (result.value())
1629                 m_state.setFoundConstants(true);
1630             forNode(node) = result;
1631             break;
1632         }
1633         
1634         forNode(node).makeHeapTop();
1635         break;
1636     }
1637             
1638     case RegExpExec:
1639         if (node->child2().useKind() == RegExpObjectUse
1640             && node->child3().useKind() == StringUse) {
1641             // This doesn't clobber the world since there are no conversions to perform.
1642         } else
1643             clobberWorld(node->origin.semantic, clobberLimit);
1644         if (JSValue globalObjectValue = forNode(node->child1()).m_value) {
1645             if (JSGlobalObject* globalObject = jsDynamicCast<JSGlobalObject*>(globalObjectValue)) {
1646                 if (!globalObject->isHavingABadTime()) {
1647                     m_graph.watchpoints().addLazily(globalObject->havingABadTimeWatchpoint());
1648                     Structure* structure = globalObject->regExpMatchesArrayStructure();
1649                     m_graph.registerStructure(structure);
1650                     forNode(node).set(m_graph, structure);
1651                     forNode(node).merge(SpecOther);
1652                     break;
1653                 }
1654             }
1655         }
1656         forNode(node).setType(m_graph, SpecOther | SpecArray);
1657         break;
1658
1659     case RegExpTest:
1660         if (node->child2().useKind() == RegExpObjectUse
1661             && node->child3().useKind() == StringUse) {
1662             // This doesn't clobber the world since there are no conversions to perform.
1663         } else
1664             clobberWorld(node->origin.semantic, clobberLimit);
1665         forNode(node).setType(SpecBoolean);
1666         break;
1667             
1668     case StringReplace:
1669         if (node->child1().useKind() == StringUse
1670             && node->child2().useKind() == RegExpObjectUse
1671             && node->child3().useKind() == StringUse) {
1672             // This doesn't clobber the world. It just reads and writes regexp state.
1673         } else
1674             clobberWorld(node->origin.semantic, clobberLimit);
1675         forNode(node).set(m_graph, m_graph.m_vm.stringStructure.get());
1676         break;
1677
1678     case Jump:
1679         break;
1680             
1681     case Branch: {
1682         Node* child = node->child1().node();
1683         BooleanResult result = booleanResult(node, forNode(child));
1684         if (result == DefinitelyTrue) {
1685             m_state.setBranchDirection(TakeTrue);
1686             break;
1687         }
1688         if (result == DefinitelyFalse) {
1689             m_state.setBranchDirection(TakeFalse);
1690             break;
1691         }
1692         // FIXME: The above handles the trivial cases of sparse conditional
1693         // constant propagation, but we can do better:
1694         // We can specialize the source variable's value on each direction of
1695         // the branch.
1696         m_state.setBranchDirection(TakeBoth);
1697         break;
1698     }
1699         
1700     case Switch: {
1701         // Nothing to do for now.
1702         // FIXME: Do sparse conditional things.
1703         break;
1704     }
1705             
1706     case Return:
1707         m_state.setIsValid(false);
1708         break;
1709
1710     case TailCall:
1711     case TailCallVarargs:
1712     case TailCallForwardVarargs:
1713         clobberWorld(node->origin.semantic, clobberLimit);
1714         m_state.setIsValid(false);
1715         break;
1716         
1717     case Throw:
1718     case ThrowReferenceError:
1719         m_state.setIsValid(false);
1720         break;
1721             
1722     case ToPrimitive: {
1723         JSValue childConst = forNode(node->child1()).value();
1724         if (childConst && childConst.isNumber()) {
1725             setConstant(node, childConst);
1726             break;
1727         }
1728         
1729         ASSERT(node->child1().useKind() == UntypedUse);
1730         
1731         if (!forNode(node->child1()).m_type) {
1732             m_state.setIsValid(false);
1733             break;
1734         }
1735         
1736         if (!(forNode(node->child1()).m_type & ~(SpecFullNumber | SpecBoolean | SpecString | SpecSymbol))) {
1737             m_state.setFoundConstants(true);
1738             forNode(node) = forNode(node->child1());
1739             break;
1740         }
1741         
1742         clobberWorld(node->origin.semantic, clobberLimit);
1743         
1744         forNode(node).setType(m_graph, SpecHeapTop & ~SpecObject);
1745         break;
1746     }
1747         
1748     case ToString:
1749     case CallStringConstructor: {
1750         switch (node->child1().useKind()) {
1751         case StringObjectUse:
1752             // This also filters that the StringObject has the primordial StringObject
1753             // structure.
1754             filter(
1755                 node->child1(),
1756                 m_graph.globalObjectFor(node->origin.semantic)->stringObjectStructure());
1757             break;
1758         case StringOrStringObjectUse:
1759             break;
1760         case CellUse:
1761         case UntypedUse:
1762             clobberWorld(node->origin.semantic, clobberLimit);
1763             break;
1764         default:
1765             RELEASE_ASSERT_NOT_REACHED();
1766             break;
1767         }
1768         forNode(node).set(m_graph, m_graph.m_vm.stringStructure.get());
1769         break;
1770     }
1771         
1772     case NewStringObject: {
1773         ASSERT(node->structure()->classInfo() == StringObject::info());
1774         forNode(node).set(m_graph, node->structure());
1775         break;
1776     }
1777             
1778     case NewArray:
1779         forNode(node).set(
1780             m_graph,
1781             m_graph.globalObjectFor(node->origin.semantic)->arrayStructureForIndexingTypeDuringAllocation(node->indexingType()));
1782         break;
1783         
1784     case NewArrayBuffer:
1785         forNode(node).set(
1786             m_graph,
1787             m_graph.globalObjectFor(node->origin.semantic)->arrayStructureForIndexingTypeDuringAllocation(node->indexingType()));
1788         break;
1789
1790     case NewArrayWithSize:
1791         forNode(node).setType(m_graph, SpecArray);
1792         break;
1793         
1794     case NewTypedArray:
1795         switch (node->child1().useKind()) {
1796         case Int32Use:
1797             break;
1798         case UntypedUse:
1799             clobberWorld(node->origin.semantic, clobberLimit);
1800             break;
1801         default:
1802             RELEASE_ASSERT_NOT_REACHED();
1803             break;
1804         }
1805         forNode(node).set(
1806             m_graph,
1807             m_graph.globalObjectFor(node->origin.semantic)->typedArrayStructure(
1808                 node->typedArrayType()));
1809         break;
1810         
1811     case NewRegexp:
1812         forNode(node).set(m_graph, m_graph.globalObjectFor(node->origin.semantic)->regExpStructure());
1813         break;
1814             
1815     case ToThis: {
1816         AbstractValue& source = forNode(node->child1());
1817         AbstractValue& destination = forNode(node);
1818
1819         if (source.m_type == SpecStringObject) {
1820             m_state.setFoundConstants(true);
1821             destination = source;
1822             break;
1823         }
1824
1825         if (m_graph.executableFor(node->origin.semantic)->isStrictMode()) {
1826             if (!(source.m_type & ~(SpecFullNumber | SpecBoolean | SpecString | SpecSymbol))) {
1827                 m_state.setFoundConstants(true);
1828                 destination = source;
1829                 break;
1830             }
1831             destination.makeHeapTop();
1832         } else {
1833             destination = source;
1834             destination.merge(SpecObject);
1835         }
1836         break;
1837     }
1838
1839     case CreateThis: {
1840         // FIXME: We can fold this to NewObject if the incoming callee is a constant.
1841         forNode(node).setType(m_graph, SpecFinalObject);
1842         break;
1843     }
1844         
1845     case NewObject:
1846         ASSERT(node->structure());
1847         forNode(node).set(m_graph, node->structure());
1848         break;
1849
1850     case CallObjectConstructor: {
1851         AbstractValue& source = forNode(node->child1());
1852         AbstractValue& destination = forNode(node);
1853
1854         if (!(source.m_type & ~SpecObject)) {
1855             m_state.setFoundConstants(true);
1856             destination = source;
1857             break;
1858         }
1859
1860         forNode(node).setType(m_graph, SpecObject);
1861         break;
1862     }
1863
1864     case PhantomNewObject:
1865     case PhantomNewFunction:
1866     case PhantomNewGeneratorFunction:
1867     case PhantomCreateActivation:
1868     case PhantomDirectArguments:
1869     case PhantomClonedArguments:
1870     case BottomValue:
1871         m_state.setDidClobber(true); // Prevent constant folding.
1872         // This claims to return bottom.
1873         break;
1874         
1875     case PutHint:
1876         break;
1877         
1878     case MaterializeNewObject: {
1879         StructureSet set;
1880         
1881         m_phiChildren->forAllTransitiveIncomingValues(
1882             m_graph.varArgChild(node, 0).node(),
1883             [&] (Node* incoming) {
1884                 set.add(incoming->castConstant<Structure*>());
1885             });
1886         
1887         forNode(node).set(m_graph, set);
1888         break;
1889     }
1890
1891     case CreateActivation:
1892     case MaterializeCreateActivation:
1893         forNode(node).set(
1894             m_graph, m_codeBlock->globalObjectFor(node->origin.semantic)->activationStructure());
1895         break;
1896         
1897     case CreateDirectArguments:
1898         forNode(node).set(m_graph, m_codeBlock->globalObjectFor(node->origin.semantic)->directArgumentsStructure());
1899         break;
1900         
1901     case CreateScopedArguments:
1902         forNode(node).set(m_graph, m_codeBlock->globalObjectFor(node->origin.semantic)->scopedArgumentsStructure());
1903         break;
1904         
1905     case CreateClonedArguments:
1906         forNode(node).set(m_graph, m_codeBlock->globalObjectFor(node->origin.semantic)->clonedArgumentsStructure());
1907         break;
1908
1909     case NewGeneratorFunction:
1910         forNode(node).set(
1911             m_graph, m_codeBlock->globalObjectFor(node->origin.semantic)->generatorFunctionStructure());
1912         break;
1913
1914     case NewFunction:
1915         forNode(node).set(
1916             m_graph, m_codeBlock->globalObjectFor(node->origin.semantic)->functionStructure());
1917         break;
1918         
1919     case GetCallee:
1920         if (FunctionExecutable* executable = jsDynamicCast<FunctionExecutable*>(m_codeBlock->ownerExecutable())) {
1921             InferredValue* singleton = executable->singletonFunction();
1922             if (JSValue value = singleton->inferredValue()) {
1923                 m_graph.watchpoints().addLazily(singleton);
1924                 JSFunction* function = jsCast<JSFunction*>(value);
1925                 setConstant(node, *m_graph.freeze(function));
1926                 break;
1927             }
1928         }
1929         forNode(node).setType(m_graph, SpecFunction);
1930         break;
1931         
1932     case GetArgumentCount:
1933         forNode(node).setType(SpecInt32);
1934         break;
1935         
1936     case GetRestLength:
1937         forNode(node).setType(SpecInt32);
1938         break;
1939         
1940     case GetGetter: {
1941         JSValue base = forNode(node->child1()).m_value;
1942         if (base) {
1943             GetterSetter* getterSetter = jsCast<GetterSetter*>(base);
1944             if (!getterSetter->isGetterNull()) {
1945                 setConstant(node, *m_graph.freeze(getterSetter->getterConcurrently()));
1946                 break;
1947             }
1948         }
1949         
1950         forNode(node).setType(m_graph, SpecObject);
1951         break;
1952     }
1953         
1954     case GetSetter: {
1955         JSValue base = forNode(node->child1()).m_value;
1956         if (base) {
1957             GetterSetter* getterSetter = jsCast<GetterSetter*>(base);
1958             if (!getterSetter->isSetterNull()) {
1959                 setConstant(node, *m_graph.freeze(getterSetter->setterConcurrently()));
1960                 break;
1961             }
1962         }
1963         
1964         forNode(node).setType(m_graph, SpecObject);
1965         break;
1966     }
1967         
1968     case GetScope:
1969         if (JSValue base = forNode(node->child1()).m_value) {
1970             if (JSFunction* function = jsDynamicCast<JSFunction*>(base)) {
1971                 setConstant(node, *m_graph.freeze(function->scope()));
1972                 break;
1973             }
1974         }
1975         forNode(node).setType(m_graph, SpecObjectOther);
1976         break;
1977
1978     case SkipScope: {
1979         JSValue child = forNode(node->child1()).value();
1980         if (child) {
1981             setConstant(node, *m_graph.freeze(JSValue(jsCast<JSScope*>(child.asCell())->next())));
1982             break;
1983         }
1984         forNode(node).setType(m_graph, SpecObjectOther);
1985         break;
1986     }
1987
1988     case GetGlobalObject: {
1989         JSValue child = forNode(node->child1()).value();
1990         if (child) {
1991             setConstant(node, *m_graph.freeze(JSValue(asObject(child)->globalObject())));
1992             break;
1993         }
1994
1995         if (forNode(node->child1()).m_structure.isFinite()) {
1996             JSGlobalObject* globalObject = nullptr;
1997             bool ok = true;
1998             forNode(node->child1()).m_structure.forEach(
1999                 [&] (Structure* structure) {
2000                     if (!globalObject)
2001                         globalObject = structure->globalObject();
2002                     else if (globalObject != structure->globalObject())
2003                         ok = false;
2004                 });
2005             if (globalObject && ok) {
2006                 setConstant(node, *m_graph.freeze(JSValue(globalObject)));
2007                 break;
2008             }
2009         }
2010
2011         forNode(node).setType(m_graph, SpecObjectOther);
2012         break;
2013     }
2014
2015     case GetClosureVar:
2016         if (JSValue value = m_graph.tryGetConstantClosureVar(forNode(node->child1()), node->scopeOffset())) {
2017             setConstant(node, *m_graph.freeze(value));
2018             break;
2019         }
2020         forNode(node).makeBytecodeTop();
2021         break;
2022             
2023     case PutClosureVar:
2024         break;
2025
2026     case GetRegExpObjectLastIndex:
2027         forNode(node).makeHeapTop();
2028         break;
2029
2030     case SetRegExpObjectLastIndex:
2031     case RecordRegExpCachedResult:
2032         break;
2033         
2034     case GetFromArguments:
2035         forNode(node).makeHeapTop();
2036         break;
2037         
2038     case PutToArguments:
2039         break;
2040
2041     case TryGetById:
2042         // FIXME: This should constant fold at least as well as the normal GetById case.
2043         // https://bugs.webkit.org/show_bug.cgi?id=156422
2044         forNode(node).makeHeapTop();
2045         break;
2046
2047     case GetById:
2048     case GetByIdFlush: {
2049         if (!node->prediction()) {
2050             m_state.setIsValid(false);
2051             break;
2052         }
2053         
2054         AbstractValue& value = forNode(node->child1());
2055         if (value.m_structure.isFinite()
2056             && (node->child1().useKind() == CellUse || !(value.m_type & ~SpecCell))) {
2057             UniquedStringImpl* uid = m_graph.identifiers()[node->identifierNumber()];
2058             GetByIdStatus status = GetByIdStatus::computeFor(value.m_structure.set(), uid);
2059             if (status.isSimple()) {
2060                 // Figure out what the result is going to be - is it TOP, a constant, or maybe
2061                 // something more subtle?
2062                 AbstractValue result;
2063                 for (unsigned i = status.numVariants(); i--;) {
2064                     // This thing won't give us a variant that involves prototypes. If it did, we'd
2065                     // have more work to do here.
2066                     DFG_ASSERT(m_graph, node, status[i].conditionSet().isEmpty());
2067
2068                     result.merge(
2069                         m_graph.inferredValueForProperty(
2070                             value, uid, status[i].offset(), m_state.structureClobberState()));
2071                 }
2072                 m_state.setFoundConstants(true);
2073                 forNode(node) = result;
2074                 break;
2075             }
2076         }
2077
2078         clobberWorld(node->origin.semantic, clobberLimit);
2079         forNode(node).makeHeapTop();
2080         break;
2081     }
2082             
2083     case GetArrayLength: {
2084         JSArrayBufferView* view = m_graph.tryGetFoldableView(
2085             forNode(node->child1()).m_value, node->arrayMode());
2086         if (view) {
2087             setConstant(node, jsNumber(view->length()));
2088             break;
2089         }
2090         forNode(node).setType(SpecInt32);
2091         break;
2092     }
2093
2094     case DeleteById: {
2095         // FIXME: This could decide if the delete will be successful based on the set of structures that
2096         // we get from our base value. https://bugs.webkit.org/show_bug.cgi?id=156611
2097         clobberWorld(node->origin.semantic, clobberLimit);
2098         forNode(node).setType(SpecBoolean);
2099         break;
2100     }
2101         
2102     case CheckStructure: {
2103         AbstractValue& value = forNode(node->child1());
2104
2105         StructureSet& set = node->structureSet();
2106         
2107         // It's interesting that we could have proven that the object has a larger structure set
2108         // that includes the set we're testing. In that case we could make the structure check
2109         // more efficient. We currently don't.
2110         
2111         if (value.m_structure.isSubsetOf(set))
2112             m_state.setFoundConstants(true);
2113
2114         SpeculatedType admittedTypes = SpecNone;
2115         switch (node->child1().useKind()) {
2116         case CellUse:
2117         case KnownCellUse:
2118             admittedTypes = SpecNone;
2119             break;
2120         case CellOrOtherUse:
2121             admittedTypes = SpecOther;
2122             break;
2123         default:
2124             DFG_CRASH(m_graph, node, "Bad use kind");
2125             break;
2126         }
2127         
2128         filter(value, set, admittedTypes);
2129         break;
2130     }
2131         
2132     case CheckStructureImmediate: {
2133         // FIXME: This currently can only reason about one structure at a time.
2134         // https://bugs.webkit.org/show_bug.cgi?id=136988
2135         
2136         AbstractValue& value = forNode(node->child1());
2137         StructureSet& set = node->structureSet();
2138         
2139         if (value.value()) {
2140             if (Structure* structure = jsDynamicCast<Structure*>(value.value())) {
2141                 if (set.contains(structure)) {
2142                     m_state.setFoundConstants(true);
2143                     break;
2144                 }
2145             }
2146             m_state.setIsValid(false);
2147             break;
2148         }
2149         
2150         if (m_phiChildren) {
2151             bool allGood = true;
2152             m_phiChildren->forAllTransitiveIncomingValues(
2153                 node,
2154                 [&] (Node* incoming) {
2155                     if (Structure* structure = incoming->dynamicCastConstant<Structure*>()) {
2156                         if (set.contains(structure))
2157                             return;
2158                     }
2159                     allGood = false;
2160                 });
2161             if (allGood) {
2162                 m_state.setFoundConstants(true);
2163                 break;
2164             }
2165         }
2166             
2167         if (Structure* structure = set.onlyStructure()) {
2168             filterByValue(node->child1(), *m_graph.freeze(structure));
2169             break;
2170         }
2171         
2172         // Aw shucks, we can't do anything!
2173         break;
2174     }
2175         
2176     case PutStructure:
2177         if (!forNode(node->child1()).m_structure.isClear()) {
2178             if (forNode(node->child1()).m_structure.onlyStructure() == node->transition()->next)
2179                 m_state.setFoundConstants(true);
2180             else {
2181                 observeTransition(
2182                     clobberLimit, node->transition()->previous, node->transition()->next);
2183                 forNode(node->child1()).changeStructure(m_graph, node->transition()->next);
2184             }
2185         }
2186         break;
2187     case GetButterfly:
2188     case AllocatePropertyStorage:
2189     case ReallocatePropertyStorage:
2190         forNode(node).clear(); // The result is not a JS value.
2191         break;
2192     case CheckArray: {
2193         if (node->arrayMode().alreadyChecked(m_graph, node, forNode(node->child1()))) {
2194             m_state.setFoundConstants(true);
2195             break;
2196         }
2197         switch (node->arrayMode().type()) {
2198         case Array::String:
2199             filter(node->child1(), SpecString);
2200             break;
2201         case Array::Int32:
2202         case Array::Double:
2203         case Array::Contiguous:
2204         case Array::Undecided:
2205         case Array::ArrayStorage:
2206         case Array::SlowPutArrayStorage:
2207             break;
2208         case Array::DirectArguments:
2209             filter(node->child1(), SpecDirectArguments);
2210             break;
2211         case Array::ScopedArguments:
2212             filter(node->child1(), SpecScopedArguments);
2213             break;
2214         case Array::Int8Array:
2215             filter(node->child1(), SpecInt8Array);
2216             break;
2217         case Array::Int16Array:
2218             filter(node->child1(), SpecInt16Array);
2219             break;
2220         case Array::Int32Array:
2221             filter(node->child1(), SpecInt32Array);
2222             break;
2223         case Array::Uint8Array:
2224             filter(node->child1(), SpecUint8Array);
2225             break;
2226         case Array::Uint8ClampedArray:
2227             filter(node->child1(), SpecUint8ClampedArray);
2228             break;
2229         case Array::Uint16Array:
2230             filter(node->child1(), SpecUint16Array);
2231             break;
2232         case Array::Uint32Array:
2233             filter(node->child1(), SpecUint32Array);
2234             break;
2235         case Array::Float32Array:
2236             filter(node->child1(), SpecFloat32Array);
2237             break;
2238         case Array::Float64Array:
2239             filter(node->child1(), SpecFloat64Array);
2240             break;
2241         case Array::AnyTypedArray:
2242             filter(node->child1(), SpecTypedArrayView);
2243             break;
2244         default:
2245             RELEASE_ASSERT_NOT_REACHED();
2246             break;
2247         }
2248         filterArrayModes(node->child1(), node->arrayMode().arrayModesThatPassFiltering());
2249         break;
2250     }
2251     case Arrayify: {
2252         if (node->arrayMode().alreadyChecked(m_graph, node, forNode(node->child1()))) {
2253             m_state.setFoundConstants(true);
2254             break;
2255         }
2256         ASSERT(node->arrayMode().conversion() == Array::Convert);
2257         clobberStructures(clobberLimit);
2258         filterArrayModes(node->child1(), node->arrayMode().arrayModesThatPassFiltering());
2259         break;
2260     }
2261     case ArrayifyToStructure: {
2262         AbstractValue& value = forNode(node->child1());
2263         if (value.m_structure.isSubsetOf(StructureSet(node->structure())))
2264             m_state.setFoundConstants(true);
2265         clobberStructures(clobberLimit);
2266         
2267         // We have a bunch of options of how to express the abstract set at this point. Let set S
2268         // be the set of structures that the value had before clobbering and assume that all of
2269         // them are watchable. The new value should be the least expressible upper bound of the
2270         // intersection of "values that currently have structure = node->structure()" and "values
2271         // that have structure in S plus any structure transition-reachable from S". Assume that
2272         // node->structure() is not in S but it is transition-reachable from S. Then we would
2273         // like to say that the result is "values that have structure = node->structure() until
2274         // we invalidate", but there is no way to express this using the AbstractValue syntax. So
2275         // we must choose between:
2276         //
2277         // 1) "values that currently have structure = node->structure()". This is a valid
2278         //    superset of the value that we really want, and it's specific enough to satisfy the
2279         //    preconditions of the array access that this is guarding. It's also specific enough
2280         //    to allow relevant optimizations in the case that we didn't have a contradiction
2281         //    like in this example. Notice that in the abscence of any contradiction, this result
2282         //    is precise rather than being a conservative LUB.
2283         //
2284         // 2) "values that currently hava structure in S plus any structure transition-reachable
2285         //    from S". This is also a valid superset of the value that we really want, but it's
2286         //    not specific enough to satisfy the preconditions of the array access that this is
2287         //    guarding - so playing such shenanigans would preclude us from having assertions on
2288         //    the typing preconditions of any array accesses. This would also not be a desirable
2289         //    answer in the absence of a contradiction.
2290         //
2291         // Note that it's tempting to simply say that the resulting value is BOTTOM because of
2292         // the contradiction. That would be wrong, since we haven't hit an invalidation point,
2293         // yet.
2294         value.set(m_graph, node->structure());
2295         break;
2296     }
2297     case GetIndexedPropertyStorage: {
2298         JSArrayBufferView* view = m_graph.tryGetFoldableView(
2299             forNode(node->child1()).m_value, node->arrayMode());
2300         if (view)
2301             m_state.setFoundConstants(true);
2302         forNode(node).clear();
2303         break;
2304     }
2305     case ConstantStoragePointer: {
2306         forNode(node).clear();
2307         break; 
2308     }
2309         
2310     case GetTypedArrayByteOffset: {
2311         JSArrayBufferView* view = m_graph.tryGetFoldableView(forNode(node->child1()).m_value);
2312         if (view) {
2313             setConstant(node, jsNumber(view->byteOffset()));
2314             break;
2315         }
2316         forNode(node).setType(SpecInt32);
2317         break;
2318     }
2319         
2320     case GetByOffset: {
2321         StorageAccessData& data = node->storageAccessData();
2322         UniquedStringImpl* uid = m_graph.identifiers()[data.identifierNumber];
2323
2324         // FIXME: The part of this that handles inferred property types relies on AI knowing the structure
2325         // right now. That's probably not optimal. In some cases, we may perform an optimization (usually
2326         // by something other than AI, maybe by CSE for example) that obscures AI's view of the structure
2327         // at the point where GetByOffset runs. Currently, when that happens, we'll have to rely entirely
2328         // on the type that ByteCodeParser was able to prove.
2329         AbstractValue value = m_graph.inferredValueForProperty(
2330             forNode(node->child2()), uid, data.offset, m_state.structureClobberState());
2331
2332         // It's possible that the type that ByteCodeParser came up with is better.
2333         AbstractValue typeFromParsing;
2334         typeFromParsing.set(m_graph, data.inferredType, m_state.structureClobberState());
2335         value.filter(typeFromParsing);
2336
2337         // If we decide that there does not exist any value that this can return, then it's probably
2338         // because the compilation was already invalidated.
2339         if (value.isClear())
2340             m_state.setIsValid(false);
2341
2342         forNode(node) = value;
2343         if (value.m_value)
2344             m_state.setFoundConstants(true);
2345         break;
2346     }
2347         
2348     case GetGetterSetterByOffset: {
2349         StorageAccessData& data = node->storageAccessData();
2350         JSValue result = m_graph.tryGetConstantProperty(forNode(node->child2()), data.offset);
2351         if (result && jsDynamicCast<GetterSetter*>(result)) {
2352             setConstant(node, *m_graph.freeze(result));
2353             break;
2354         }
2355         
2356         forNode(node).set(m_graph, m_graph.m_vm.getterSetterStructure.get());
2357         break;
2358     }
2359         
2360     case MultiGetByOffset: {
2361         // This code will filter the base value in a manner that is possibly different (either more
2362         // or less precise) than the way it would be filtered if this was strength-reduced to a
2363         // CheckStructure. This is fine. It's legal for different passes over the code to prove
2364         // different things about the code, so long as all of them are sound. That even includes
2365         // one guy proving that code should never execute (due to a contradiction) and another guy
2366         // not finding that contradiction. If someone ever proved that there would be a
2367         // contradiction then there must always be a contradiction even if subsequent passes don't
2368         // realize it. This is the case here.
2369         
2370         // Ordinarily you have to be careful with calling setFoundConstants()
2371         // because of the effect on compile times, but this node is FTL-only.
2372         m_state.setFoundConstants(true);
2373         
2374         UniquedStringImpl* uid = m_graph.identifiers()[node->multiGetByOffsetData().identifierNumber];
2375
2376         AbstractValue base = forNode(node->child1());
2377         StructureSet baseSet;
2378         AbstractValue result;
2379         for (const MultiGetByOffsetCase& getCase : node->multiGetByOffsetData().cases) {
2380             StructureSet set = getCase.set();
2381             set.filter(base);
2382             if (set.isEmpty())
2383                 continue;
2384             baseSet.merge(set);
2385
2386             switch (getCase.method().kind()) {
2387             case GetByOffsetMethod::Constant: {
2388                 AbstractValue thisResult;
2389                 thisResult.set(
2390                     m_graph,
2391                     *getCase.method().constant(),
2392                     m_state.structureClobberState());
2393                 result.merge(thisResult);
2394                 break;
2395             }
2396
2397             case GetByOffsetMethod::Load: {
2398                 result.merge(
2399                     m_graph.inferredValueForProperty(
2400                         set, uid, m_state.structureClobberState()));
2401                 break;
2402             }
2403
2404             default: {
2405                 result.makeHeapTop();
2406                 break;
2407             } }
2408         }
2409         
2410         if (forNode(node->child1()).changeStructure(m_graph, baseSet) == Contradiction)
2411             m_state.setIsValid(false);
2412         
2413         forNode(node) = result;
2414         break;
2415     }
2416             
2417     case PutByOffset: {
2418         break;
2419     }
2420         
2421     case MultiPutByOffset: {
2422         StructureSet newSet;
2423         TransitionVector transitions;
2424         
2425         // Ordinarily you have to be careful with calling setFoundConstants()
2426         // because of the effect on compile times, but this node is FTL-only.
2427         m_state.setFoundConstants(true);
2428         
2429         AbstractValue base = forNode(node->child1());
2430         AbstractValue originalValue = forNode(node->child2());
2431         AbstractValue resultingValue;
2432         
2433         for (unsigned i = node->multiPutByOffsetData().variants.size(); i--;) {
2434             const PutByIdVariant& variant = node->multiPutByOffsetData().variants[i];
2435             StructureSet thisSet = variant.oldStructure();
2436             thisSet.filter(base);
2437             if (thisSet.isEmpty())
2438                 continue;
2439
2440             AbstractValue thisValue = originalValue;
2441             thisValue.filter(m_graph, variant.requiredType());
2442             resultingValue.merge(thisValue);
2443             
2444             if (variant.kind() == PutByIdVariant::Transition) {
2445                 if (thisSet.onlyStructure() != variant.newStructure()) {
2446                     transitions.append(
2447                         Transition(variant.oldStructureForTransition(), variant.newStructure()));
2448                 } // else this is really a replace.
2449                 newSet.add(variant.newStructure());
2450             } else {
2451                 ASSERT(variant.kind() == PutByIdVariant::Replace);
2452                 newSet.merge(thisSet);
2453             }
2454         }
2455         
2456         observeTransitions(clobberLimit, transitions);
2457         if (forNode(node->child1()).changeStructure(m_graph, newSet) == Contradiction)
2458             m_state.setIsValid(false);
2459         forNode(node->child2()) = resultingValue;
2460         if (!!originalValue && !resultingValue)
2461             m_state.setIsValid(false);
2462         break;
2463     }
2464         
2465     case GetExecutable: {
2466         JSValue value = forNode(node->child1()).value();
2467         if (value) {
2468             JSFunction* function = jsDynamicCast<JSFunction*>(value);
2469             if (function) {
2470                 setConstant(node, *m_graph.freeze(function->executable()));
2471                 break;
2472             }
2473         }
2474         forNode(node).setType(m_graph, SpecCellOther);
2475         break;
2476     }
2477     
2478     case CheckCell: {
2479         JSValue value = forNode(node->child1()).value();
2480         if (value == node->cellOperand()->value()) {
2481             m_state.setFoundConstants(true);
2482             ASSERT(value);
2483             break;
2484         }
2485         filterByValue(node->child1(), *node->cellOperand());
2486         break;
2487     }
2488
2489     case CheckNotEmpty: {
2490         AbstractValue& value = forNode(node->child1());
2491         if (!(value.m_type & SpecEmpty)) {
2492             m_state.setFoundConstants(true);
2493             break;
2494         }
2495         
2496         filter(value, ~SpecEmpty);
2497         break;
2498     }
2499
2500     case CheckIdent: {
2501         AbstractValue& value = forNode(node->child1());
2502         UniquedStringImpl* uid = node->uidOperand();
2503         ASSERT(uid->isSymbol() ? !(value.m_type & ~SpecSymbol) : !(value.m_type & ~SpecStringIdent)); // Edge filtering should have already ensured this.
2504
2505         JSValue childConstant = value.value();
2506         if (childConstant) {
2507             if (uid->isSymbol()) {
2508                 ASSERT(childConstant.isSymbol());
2509                 if (asSymbol(childConstant)->privateName().uid() == uid) {
2510                     m_state.setFoundConstants(true);
2511                     break;
2512                 }
2513             } else {
2514                 ASSERT(childConstant.isString());
2515                 if (asString(childConstant)->tryGetValueImpl() == uid) {
2516                     m_state.setFoundConstants(true);
2517                     break;
2518                 }
2519             }
2520         }
2521
2522         filter(value, uid->isSymbol() ? SpecSymbol : SpecStringIdent);
2523         break;
2524     }
2525
2526     case CheckInBounds: {
2527         JSValue left = forNode(node->child1()).value();
2528         JSValue right = forNode(node->child2()).value();
2529         if (left && right && left.isInt32() && right.isInt32()
2530             && static_cast<uint32_t>(left.asInt32()) < static_cast<uint32_t>(right.asInt32())) {
2531             m_state.setFoundConstants(true);
2532             break;
2533         }
2534         break;
2535     }
2536         
2537     case PutById:
2538     case PutByIdFlush:
2539     case PutByIdDirect: {
2540         AbstractValue& value = forNode(node->child1());
2541         if (value.m_structure.isFinite()) {
2542             PutByIdStatus status = PutByIdStatus::computeFor(
2543                 m_graph.globalObjectFor(node->origin.semantic),
2544                 value.m_structure.set(),
2545                 m_graph.identifiers()[node->identifierNumber()],
2546                 node->op() == PutByIdDirect);
2547
2548             if (status.isSimple()) {
2549                 StructureSet newSet;
2550                 TransitionVector transitions;
2551                 
2552                 for (unsigned i = status.numVariants(); i--;) {
2553                     const PutByIdVariant& variant = status[i];
2554                     if (variant.kind() == PutByIdVariant::Transition) {
2555                         transitions.append(
2556                             Transition(
2557                                 variant.oldStructureForTransition(), variant.newStructure()));
2558                         m_graph.registerStructure(variant.newStructure());
2559                         newSet.add(variant.newStructure());
2560                     } else {
2561                         ASSERT(variant.kind() == PutByIdVariant::Replace);
2562                         newSet.merge(variant.oldStructure());
2563                     }
2564                 }
2565                 
2566                 if (status.numVariants() == 1 || isFTL(m_graph.m_plan.mode))
2567                     m_state.setFoundConstants(true);
2568                 
2569                 observeTransitions(clobberLimit, transitions);
2570                 if (forNode(node->child1()).changeStructure(m_graph, newSet) == Contradiction)
2571                     m_state.setIsValid(false);
2572                 break;
2573             }
2574         }
2575         
2576         clobberWorld(node->origin.semantic, clobberLimit);
2577         break;
2578     }
2579
2580     case PutGetterById:
2581     case PutSetterById:
2582     case PutGetterSetterById:
2583     case PutGetterByVal:
2584     case PutSetterByVal: {
2585         clobberWorld(node->origin.semantic, clobberLimit);
2586         break;
2587     }
2588         
2589     case In: {
2590         // FIXME: We can determine when the property definitely exists based on abstract
2591         // value information.
2592         clobberWorld(node->origin.semantic, clobberLimit);
2593         forNode(node).setType(SpecBoolean);
2594         break;
2595     }
2596             
2597     case GetEnumerableLength: {
2598         forNode(node).setType(SpecInt32);
2599         break;
2600     }
2601     case HasGenericProperty: {
2602         forNode(node).setType(SpecBoolean);
2603         break;
2604     }
2605     case HasStructureProperty: {
2606         forNode(node).setType(SpecBoolean);
2607         break;
2608     }
2609     case HasIndexedProperty: {
2610         ArrayMode mode = node->arrayMode();
2611         switch (mode.type()) {
2612         case Array::Int32:
2613         case Array::Double:
2614         case Array::Contiguous:
2615         case Array::ArrayStorage: {
2616             break;
2617         }
2618         default: {
2619             clobberWorld(node->origin.semantic, clobberLimit);
2620             break;
2621         }
2622         }
2623         forNode(node).setType(SpecBoolean);
2624         break;
2625     }
2626     case GetDirectPname: {
2627         clobberWorld(node->origin.semantic, clobberLimit);
2628         forNode(node).makeHeapTop();
2629         break;
2630     }
2631     case GetPropertyEnumerator: {
2632         forNode(node).setType(m_graph, SpecCell);
2633         break;
2634     }
2635     case GetEnumeratorStructurePname: {
2636         forNode(node).setType(m_graph, SpecString | SpecOther);
2637         break;
2638     }
2639     case GetEnumeratorGenericPname: {
2640         forNode(node).setType(m_graph, SpecString | SpecOther);
2641         break;
2642     }
2643     case ToIndexString: {
2644         forNode(node).setType(m_graph, SpecString);
2645         break;
2646     }
2647
2648     case GetGlobalVar:
2649         forNode(node).makeHeapTop();
2650         break;
2651     case GetGlobalLexicalVariable:
2652         forNode(node).makeBytecodeTop();
2653         break;
2654         
2655     case VarInjectionWatchpoint:
2656     case PutGlobalVariable:
2657     case NotifyWrite:
2658         break;
2659             
2660     case OverridesHasInstance:
2661         forNode(node).setType(SpecBoolean);
2662         break;
2663             
2664     case InstanceOf:
2665         // Sadly, we don't propagate the fact that we've done InstanceOf
2666         forNode(node).setType(SpecBoolean);
2667         break;
2668
2669     case InstanceOfCustom:
2670         clobberWorld(node->origin.semantic, clobberLimit);
2671         forNode(node).setType(SpecBoolean);
2672         break;
2673             
2674     case Phi:
2675         RELEASE_ASSERT(m_graph.m_form == SSA);
2676         // The state of this node would have already been decided, but it may have become a
2677         // constant, in which case we'd like to know.
2678         if (forNode(node).m_value)
2679             m_state.setFoundConstants(true);
2680         break;
2681         
2682     case Upsilon: {
2683         m_state.createValueForNode(node->phi());
2684         forNode(node->phi()) = forNode(node->child1());
2685         break;
2686     }
2687         
2688     case Flush:
2689     case PhantomLocal:
2690         break;
2691             
2692     case Call:
2693     case TailCallInlinedCaller:
2694     case Construct:
2695     case CallVarargs:
2696     case CallForwardVarargs:
2697     case TailCallVarargsInlinedCaller:
2698     case ConstructVarargs:
2699     case ConstructForwardVarargs:
2700     case TailCallForwardVarargsInlinedCaller:
2701         clobberWorld(node->origin.semantic, clobberLimit);
2702         forNode(node).makeHeapTop();
2703         break;
2704
2705     case ForceOSRExit:
2706     case CheckBadCell:
2707         m_state.setIsValid(false);
2708         break;
2709         
2710     case InvalidationPoint:
2711         forAllValues(clobberLimit, AbstractValue::observeInvalidationPointFor);
2712         m_state.setStructureClobberState(StructuresAreWatched);
2713         break;
2714
2715     case CheckWatchdogTimer:
2716     case LogShadowChickenPrologue:
2717     case LogShadowChickenTail:
2718         break;
2719
2720     case ProfileWillCall:
2721     case ProfileDidCall:
2722     case ProfileType:
2723     case ProfileControlFlow:
2724     case Phantom:
2725     case CountExecution:
2726     case CheckTierUpInLoop:
2727     case CheckTierUpAtReturn:
2728     case CheckTypeInfoFlags:
2729         break;
2730
2731     case CopyRest:
2732         break;
2733             
2734     case Check: {
2735         // Simplify out checks that don't actually do checking.
2736         for (unsigned i = 0; i < AdjacencyList::Size; ++i) {
2737             Edge edge = node->children.child(i);
2738             if (!edge)
2739                 break;
2740             if (edge.isProved() || edge.willNotHaveCheck()) {
2741                 m_state.setFoundConstants(true);
2742                 break;
2743             }
2744         }
2745         break;
2746     }
2747
2748     case SetFunctionName: {
2749         clobberWorld(node->origin.semantic, clobberLimit);
2750         break;
2751     }
2752
2753     case StoreBarrier: {
2754         filter(node->child1(), SpecCell);
2755         break;
2756     }
2757
2758     case CheckTierUpAndOSREnter:
2759     case LoopHint:
2760     case ZombieHint:
2761     case ExitOK:
2762         break;
2763
2764     case Unreachable:
2765     case LastNodeType:
2766     case ArithIMul:
2767     case FiatInt52:
2768         DFG_CRASH(m_graph, node, "Unexpected node type");
2769         break;
2770     }
2771     
2772     return m_state.isValid();
2773 }
2774
2775 template<typename AbstractStateType>
2776 bool AbstractInterpreter<AbstractStateType>::executeEffects(unsigned indexInBlock)
2777 {
2778     return executeEffects(indexInBlock, m_state.block()->at(indexInBlock));
2779 }
2780
2781 template<typename AbstractStateType>
2782 bool AbstractInterpreter<AbstractStateType>::execute(unsigned indexInBlock)
2783 {
2784     Node* node = m_state.block()->at(indexInBlock);
2785     
2786     startExecuting();
2787     executeEdges(node);
2788     return executeEffects(indexInBlock, node);
2789 }
2790
2791 template<typename AbstractStateType>
2792 bool AbstractInterpreter<AbstractStateType>::execute(Node* node)
2793 {
2794     startExecuting();
2795     executeEdges(node);
2796     return executeEffects(UINT_MAX, node);
2797 }
2798
2799 template<typename AbstractStateType>
2800 void AbstractInterpreter<AbstractStateType>::clobberWorld(
2801     const CodeOrigin&, unsigned clobberLimit)
2802 {
2803     clobberStructures(clobberLimit);
2804 }
2805
2806 template<typename AbstractStateType>
2807 template<typename Functor>
2808 void AbstractInterpreter<AbstractStateType>::forAllValues(
2809     unsigned clobberLimit, Functor& functor)
2810 {
2811     if (clobberLimit >= m_state.block()->size())
2812         clobberLimit = m_state.block()->size();
2813     else
2814         clobberLimit++;
2815     ASSERT(clobberLimit <= m_state.block()->size());
2816     for (size_t i = clobberLimit; i--;)
2817         functor(forNode(m_state.block()->at(i)));
2818     if (m_graph.m_form == SSA) {
2819         HashSet<Node*>::iterator iter = m_state.block()->ssa->liveAtHead.begin();
2820         HashSet<Node*>::iterator end = m_state.block()->ssa->liveAtHead.end();
2821         for (; iter != end; ++iter)
2822             functor(forNode(*iter));
2823     }
2824     for (size_t i = m_state.variables().numberOfArguments(); i--;)
2825         functor(m_state.variables().argument(i));
2826     for (size_t i = m_state.variables().numberOfLocals(); i--;)
2827         functor(m_state.variables().local(i));
2828 }
2829
2830 template<typename AbstractStateType>
2831 void AbstractInterpreter<AbstractStateType>::clobberStructures(unsigned clobberLimit)
2832 {
2833     forAllValues(clobberLimit, AbstractValue::clobberStructuresFor);
2834     setDidClobber();
2835 }
2836
2837 template<typename AbstractStateType>
2838 void AbstractInterpreter<AbstractStateType>::observeTransition(
2839     unsigned clobberLimit, Structure* from, Structure* to)
2840 {
2841     AbstractValue::TransitionObserver transitionObserver(from, to);
2842     forAllValues(clobberLimit, transitionObserver);
2843     
2844     ASSERT(!from->dfgShouldWatch()); // We don't need to claim to be in a clobbered state because 'from' was never watchable (during the time we were compiling), hence no constants ever introduced into the DFG IR that ever had a watchable structure would ever have the same structure as from.
2845 }
2846
2847 template<typename AbstractStateType>
2848 void AbstractInterpreter<AbstractStateType>::observeTransitions(
2849     unsigned clobberLimit, const TransitionVector& vector)
2850 {
2851     AbstractValue::TransitionsObserver transitionsObserver(vector);
2852     forAllValues(clobberLimit, transitionsObserver);
2853     
2854     if (!ASSERT_DISABLED) {
2855         // We don't need to claim to be in a clobbered state because none of the Transition::previous structures are watchable.
2856         for (unsigned i = vector.size(); i--;)
2857             ASSERT(!vector[i].previous->dfgShouldWatch());
2858     }
2859 }
2860
2861 template<typename AbstractStateType>
2862 void AbstractInterpreter<AbstractStateType>::setDidClobber()
2863 {
2864     m_state.setDidClobber(true);
2865     m_state.setStructureClobberState(StructuresAreClobbered);
2866 }
2867
2868 template<typename AbstractStateType>
2869 void AbstractInterpreter<AbstractStateType>::dump(PrintStream& out) const
2870 {
2871     const_cast<AbstractInterpreter<AbstractStateType>*>(this)->dump(out);
2872 }
2873
2874 template<typename AbstractStateType>
2875 void AbstractInterpreter<AbstractStateType>::dump(PrintStream& out)
2876 {
2877     CommaPrinter comma(" ");
2878     HashSet<Node*> seen;
2879     if (m_graph.m_form == SSA) {
2880         HashSet<Node*>::iterator iter = m_state.block()->ssa->liveAtHead.begin();
2881         HashSet<Node*>::iterator end = m_state.block()->ssa->liveAtHead.end();
2882         for (; iter != end; ++iter) {
2883             Node* node = *iter;
2884             seen.add(node);
2885             AbstractValue& value = forNode(node);
2886             if (value.isClear())
2887                 continue;
2888             out.print(comma, node, ":", value);
2889         }
2890     }
2891     for (size_t i = 0; i < m_state.block()->size(); ++i) {
2892         Node* node = m_state.block()->at(i);
2893         seen.add(node);
2894         AbstractValue& value = forNode(node);
2895         if (value.isClear())
2896             continue;
2897         out.print(comma, node, ":", value);
2898     }
2899     if (m_graph.m_form == SSA) {
2900         HashSet<Node*>::iterator iter = m_state.block()->ssa->liveAtTail.begin();
2901         HashSet<Node*>::iterator end = m_state.block()->ssa->liveAtTail.end();
2902         for (; iter != end; ++iter) {
2903             Node* node = *iter;
2904             if (seen.contains(node))
2905                 continue;
2906             AbstractValue& value = forNode(node);
2907             if (value.isClear())
2908                 continue;
2909             out.print(comma, node, ":", value);
2910         }
2911     }
2912 }
2913
2914 template<typename AbstractStateType>
2915 FiltrationResult AbstractInterpreter<AbstractStateType>::filter(
2916     AbstractValue& value, const StructureSet& set, SpeculatedType admittedTypes)
2917 {
2918     if (value.filter(m_graph, set, admittedTypes) == FiltrationOK)
2919         return FiltrationOK;
2920     m_state.setIsValid(false);
2921     return Contradiction;
2922 }
2923
2924 template<typename AbstractStateType>
2925 FiltrationResult AbstractInterpreter<AbstractStateType>::filterArrayModes(
2926     AbstractValue& value, ArrayModes arrayModes)
2927 {
2928     if (value.filterArrayModes(arrayModes) == FiltrationOK)
2929         return FiltrationOK;
2930     m_state.setIsValid(false);
2931     return Contradiction;
2932 }
2933
2934 template<typename AbstractStateType>
2935 FiltrationResult AbstractInterpreter<AbstractStateType>::filter(
2936     AbstractValue& value, SpeculatedType type)
2937 {
2938     if (value.filter(type) == FiltrationOK)
2939         return FiltrationOK;
2940     m_state.setIsValid(false);
2941     return Contradiction;
2942 }
2943
2944 template<typename AbstractStateType>
2945 FiltrationResult AbstractInterpreter<AbstractStateType>::filterByValue(
2946     AbstractValue& abstractValue, FrozenValue concreteValue)
2947 {
2948     if (abstractValue.filterByValue(concreteValue) == FiltrationOK)
2949         return FiltrationOK;
2950     m_state.setIsValid(false);
2951     return Contradiction;
2952 }
2953
2954 } } // namespace JSC::DFG
2955
2956 #endif // ENABLE(DFG_JIT)
2957
2958 #endif // DFGAbstractInterpreterInlines_h
2959