[JSC] DFG should support relational comparisons of Number and Other
[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 CheckStructure: {
2095         AbstractValue& value = forNode(node->child1());
2096
2097         StructureSet& set = node->structureSet();
2098         
2099         // It's interesting that we could have proven that the object has a larger structure set
2100         // that includes the set we're testing. In that case we could make the structure check
2101         // more efficient. We currently don't.
2102         
2103         if (value.m_structure.isSubsetOf(set))
2104             m_state.setFoundConstants(true);
2105
2106         SpeculatedType admittedTypes = SpecNone;
2107         switch (node->child1().useKind()) {
2108         case CellUse:
2109         case KnownCellUse:
2110             admittedTypes = SpecNone;
2111             break;
2112         case CellOrOtherUse:
2113             admittedTypes = SpecOther;
2114             break;
2115         default:
2116             DFG_CRASH(m_graph, node, "Bad use kind");
2117             break;
2118         }
2119         
2120         filter(value, set, admittedTypes);
2121         break;
2122     }
2123         
2124     case CheckStructureImmediate: {
2125         // FIXME: This currently can only reason about one structure at a time.
2126         // https://bugs.webkit.org/show_bug.cgi?id=136988
2127         
2128         AbstractValue& value = forNode(node->child1());
2129         StructureSet& set = node->structureSet();
2130         
2131         if (value.value()) {
2132             if (Structure* structure = jsDynamicCast<Structure*>(value.value())) {
2133                 if (set.contains(structure)) {
2134                     m_state.setFoundConstants(true);
2135                     break;
2136                 }
2137             }
2138             m_state.setIsValid(false);
2139             break;
2140         }
2141         
2142         if (m_phiChildren) {
2143             bool allGood = true;
2144             m_phiChildren->forAllTransitiveIncomingValues(
2145                 node,
2146                 [&] (Node* incoming) {
2147                     if (Structure* structure = incoming->dynamicCastConstant<Structure*>()) {
2148                         if (set.contains(structure))
2149                             return;
2150                     }
2151                     allGood = false;
2152                 });
2153             if (allGood) {
2154                 m_state.setFoundConstants(true);
2155                 break;
2156             }
2157         }
2158             
2159         if (Structure* structure = set.onlyStructure()) {
2160             filterByValue(node->child1(), *m_graph.freeze(structure));
2161             break;
2162         }
2163         
2164         // Aw shucks, we can't do anything!
2165         break;
2166     }
2167         
2168     case PutStructure:
2169         if (!forNode(node->child1()).m_structure.isClear()) {
2170             if (forNode(node->child1()).m_structure.onlyStructure() == node->transition()->next)
2171                 m_state.setFoundConstants(true);
2172             else {
2173                 observeTransition(
2174                     clobberLimit, node->transition()->previous, node->transition()->next);
2175                 forNode(node->child1()).changeStructure(m_graph, node->transition()->next);
2176             }
2177         }
2178         break;
2179     case GetButterfly:
2180     case AllocatePropertyStorage:
2181     case ReallocatePropertyStorage:
2182         forNode(node).clear(); // The result is not a JS value.
2183         break;
2184     case CheckArray: {
2185         if (node->arrayMode().alreadyChecked(m_graph, node, forNode(node->child1()))) {
2186             m_state.setFoundConstants(true);
2187             break;
2188         }
2189         switch (node->arrayMode().type()) {
2190         case Array::String:
2191             filter(node->child1(), SpecString);
2192             break;
2193         case Array::Int32:
2194         case Array::Double:
2195         case Array::Contiguous:
2196         case Array::Undecided:
2197         case Array::ArrayStorage:
2198         case Array::SlowPutArrayStorage:
2199             break;
2200         case Array::DirectArguments:
2201             filter(node->child1(), SpecDirectArguments);
2202             break;
2203         case Array::ScopedArguments:
2204             filter(node->child1(), SpecScopedArguments);
2205             break;
2206         case Array::Int8Array:
2207             filter(node->child1(), SpecInt8Array);
2208             break;
2209         case Array::Int16Array:
2210             filter(node->child1(), SpecInt16Array);
2211             break;
2212         case Array::Int32Array:
2213             filter(node->child1(), SpecInt32Array);
2214             break;
2215         case Array::Uint8Array:
2216             filter(node->child1(), SpecUint8Array);
2217             break;
2218         case Array::Uint8ClampedArray:
2219             filter(node->child1(), SpecUint8ClampedArray);
2220             break;
2221         case Array::Uint16Array:
2222             filter(node->child1(), SpecUint16Array);
2223             break;
2224         case Array::Uint32Array:
2225             filter(node->child1(), SpecUint32Array);
2226             break;
2227         case Array::Float32Array:
2228             filter(node->child1(), SpecFloat32Array);
2229             break;
2230         case Array::Float64Array:
2231             filter(node->child1(), SpecFloat64Array);
2232             break;
2233         case Array::AnyTypedArray:
2234             filter(node->child1(), SpecTypedArrayView);
2235             break;
2236         default:
2237             RELEASE_ASSERT_NOT_REACHED();
2238             break;
2239         }
2240         filterArrayModes(node->child1(), node->arrayMode().arrayModesThatPassFiltering());
2241         break;
2242     }
2243     case Arrayify: {
2244         if (node->arrayMode().alreadyChecked(m_graph, node, forNode(node->child1()))) {
2245             m_state.setFoundConstants(true);
2246             break;
2247         }
2248         ASSERT(node->arrayMode().conversion() == Array::Convert);
2249         clobberStructures(clobberLimit);
2250         filterArrayModes(node->child1(), node->arrayMode().arrayModesThatPassFiltering());
2251         break;
2252     }
2253     case ArrayifyToStructure: {
2254         AbstractValue& value = forNode(node->child1());
2255         if (value.m_structure.isSubsetOf(StructureSet(node->structure())))
2256             m_state.setFoundConstants(true);
2257         clobberStructures(clobberLimit);
2258         
2259         // We have a bunch of options of how to express the abstract set at this point. Let set S
2260         // be the set of structures that the value had before clobbering and assume that all of
2261         // them are watchable. The new value should be the least expressible upper bound of the
2262         // intersection of "values that currently have structure = node->structure()" and "values
2263         // that have structure in S plus any structure transition-reachable from S". Assume that
2264         // node->structure() is not in S but it is transition-reachable from S. Then we would
2265         // like to say that the result is "values that have structure = node->structure() until
2266         // we invalidate", but there is no way to express this using the AbstractValue syntax. So
2267         // we must choose between:
2268         //
2269         // 1) "values that currently have structure = node->structure()". This is a valid
2270         //    superset of the value that we really want, and it's specific enough to satisfy the
2271         //    preconditions of the array access that this is guarding. It's also specific enough
2272         //    to allow relevant optimizations in the case that we didn't have a contradiction
2273         //    like in this example. Notice that in the abscence of any contradiction, this result
2274         //    is precise rather than being a conservative LUB.
2275         //
2276         // 2) "values that currently hava structure in S plus any structure transition-reachable
2277         //    from S". This is also a valid superset of the value that we really want, but it's
2278         //    not specific enough to satisfy the preconditions of the array access that this is
2279         //    guarding - so playing such shenanigans would preclude us from having assertions on
2280         //    the typing preconditions of any array accesses. This would also not be a desirable
2281         //    answer in the absence of a contradiction.
2282         //
2283         // Note that it's tempting to simply say that the resulting value is BOTTOM because of
2284         // the contradiction. That would be wrong, since we haven't hit an invalidation point,
2285         // yet.
2286         value.set(m_graph, node->structure());
2287         break;
2288     }
2289     case GetIndexedPropertyStorage: {
2290         JSArrayBufferView* view = m_graph.tryGetFoldableView(
2291             forNode(node->child1()).m_value, node->arrayMode());
2292         if (view)
2293             m_state.setFoundConstants(true);
2294         forNode(node).clear();
2295         break;
2296     }
2297     case ConstantStoragePointer: {
2298         forNode(node).clear();
2299         break; 
2300     }
2301         
2302     case GetTypedArrayByteOffset: {
2303         JSArrayBufferView* view = m_graph.tryGetFoldableView(forNode(node->child1()).m_value);
2304         if (view) {
2305             setConstant(node, jsNumber(view->byteOffset()));
2306             break;
2307         }
2308         forNode(node).setType(SpecInt32);
2309         break;
2310     }
2311         
2312     case GetByOffset: {
2313         StorageAccessData& data = node->storageAccessData();
2314         UniquedStringImpl* uid = m_graph.identifiers()[data.identifierNumber];
2315
2316         // FIXME: The part of this that handles inferred property types relies on AI knowing the structure
2317         // right now. That's probably not optimal. In some cases, we may perform an optimization (usually
2318         // by something other than AI, maybe by CSE for example) that obscures AI's view of the structure
2319         // at the point where GetByOffset runs. Currently, when that happens, we'll have to rely entirely
2320         // on the type that ByteCodeParser was able to prove.
2321         AbstractValue value = m_graph.inferredValueForProperty(
2322             forNode(node->child2()), uid, data.offset, m_state.structureClobberState());
2323
2324         // It's possible that the type that ByteCodeParser came up with is better.
2325         AbstractValue typeFromParsing;
2326         typeFromParsing.set(m_graph, data.inferredType, m_state.structureClobberState());
2327         value.filter(typeFromParsing);
2328
2329         // If we decide that there does not exist any value that this can return, then it's probably
2330         // because the compilation was already invalidated.
2331         if (value.isClear())
2332             m_state.setIsValid(false);
2333
2334         forNode(node) = value;
2335         if (value.m_value)
2336             m_state.setFoundConstants(true);
2337         break;
2338     }
2339         
2340     case GetGetterSetterByOffset: {
2341         StorageAccessData& data = node->storageAccessData();
2342         JSValue result = m_graph.tryGetConstantProperty(forNode(node->child2()), data.offset);
2343         if (result && jsDynamicCast<GetterSetter*>(result)) {
2344             setConstant(node, *m_graph.freeze(result));
2345             break;
2346         }
2347         
2348         forNode(node).set(m_graph, m_graph.m_vm.getterSetterStructure.get());
2349         break;
2350     }
2351         
2352     case MultiGetByOffset: {
2353         // This code will filter the base value in a manner that is possibly different (either more
2354         // or less precise) than the way it would be filtered if this was strength-reduced to a
2355         // CheckStructure. This is fine. It's legal for different passes over the code to prove
2356         // different things about the code, so long as all of them are sound. That even includes
2357         // one guy proving that code should never execute (due to a contradiction) and another guy
2358         // not finding that contradiction. If someone ever proved that there would be a
2359         // contradiction then there must always be a contradiction even if subsequent passes don't
2360         // realize it. This is the case here.
2361         
2362         // Ordinarily you have to be careful with calling setFoundConstants()
2363         // because of the effect on compile times, but this node is FTL-only.
2364         m_state.setFoundConstants(true);
2365         
2366         UniquedStringImpl* uid = m_graph.identifiers()[node->multiGetByOffsetData().identifierNumber];
2367
2368         AbstractValue base = forNode(node->child1());
2369         StructureSet baseSet;
2370         AbstractValue result;
2371         for (const MultiGetByOffsetCase& getCase : node->multiGetByOffsetData().cases) {
2372             StructureSet set = getCase.set();
2373             set.filter(base);
2374             if (set.isEmpty())
2375                 continue;
2376             baseSet.merge(set);
2377
2378             switch (getCase.method().kind()) {
2379             case GetByOffsetMethod::Constant: {
2380                 AbstractValue thisResult;
2381                 thisResult.set(
2382                     m_graph,
2383                     *getCase.method().constant(),
2384                     m_state.structureClobberState());
2385                 result.merge(thisResult);
2386                 break;
2387             }
2388
2389             case GetByOffsetMethod::Load: {
2390                 result.merge(
2391                     m_graph.inferredValueForProperty(
2392                         set, uid, m_state.structureClobberState()));
2393                 break;
2394             }
2395
2396             default: {
2397                 result.makeHeapTop();
2398                 break;
2399             } }
2400         }
2401         
2402         if (forNode(node->child1()).changeStructure(m_graph, baseSet) == Contradiction)
2403             m_state.setIsValid(false);
2404         
2405         forNode(node) = result;
2406         break;
2407     }
2408             
2409     case PutByOffset: {
2410         break;
2411     }
2412         
2413     case MultiPutByOffset: {
2414         StructureSet newSet;
2415         TransitionVector transitions;
2416         
2417         // Ordinarily you have to be careful with calling setFoundConstants()
2418         // because of the effect on compile times, but this node is FTL-only.
2419         m_state.setFoundConstants(true);
2420         
2421         AbstractValue base = forNode(node->child1());
2422         AbstractValue originalValue = forNode(node->child2());
2423         AbstractValue resultingValue;
2424         
2425         for (unsigned i = node->multiPutByOffsetData().variants.size(); i--;) {
2426             const PutByIdVariant& variant = node->multiPutByOffsetData().variants[i];
2427             StructureSet thisSet = variant.oldStructure();
2428             thisSet.filter(base);
2429             if (thisSet.isEmpty())
2430                 continue;
2431
2432             AbstractValue thisValue = originalValue;
2433             thisValue.filter(m_graph, variant.requiredType());
2434             resultingValue.merge(thisValue);
2435             
2436             if (variant.kind() == PutByIdVariant::Transition) {
2437                 if (thisSet.onlyStructure() != variant.newStructure()) {
2438                     transitions.append(
2439                         Transition(variant.oldStructureForTransition(), variant.newStructure()));
2440                 } // else this is really a replace.
2441                 newSet.add(variant.newStructure());
2442             } else {
2443                 ASSERT(variant.kind() == PutByIdVariant::Replace);
2444                 newSet.merge(thisSet);
2445             }
2446         }
2447         
2448         observeTransitions(clobberLimit, transitions);
2449         if (forNode(node->child1()).changeStructure(m_graph, newSet) == Contradiction)
2450             m_state.setIsValid(false);
2451         forNode(node->child2()) = resultingValue;
2452         if (!!originalValue && !resultingValue)
2453             m_state.setIsValid(false);
2454         break;
2455     }
2456         
2457     case GetExecutable: {
2458         JSValue value = forNode(node->child1()).value();
2459         if (value) {
2460             JSFunction* function = jsDynamicCast<JSFunction*>(value);
2461             if (function) {
2462                 setConstant(node, *m_graph.freeze(function->executable()));
2463                 break;
2464             }
2465         }
2466         forNode(node).setType(m_graph, SpecCellOther);
2467         break;
2468     }
2469     
2470     case CheckCell: {
2471         JSValue value = forNode(node->child1()).value();
2472         if (value == node->cellOperand()->value()) {
2473             m_state.setFoundConstants(true);
2474             ASSERT(value);
2475             break;
2476         }
2477         filterByValue(node->child1(), *node->cellOperand());
2478         break;
2479     }
2480
2481     case CheckNotEmpty: {
2482         AbstractValue& value = forNode(node->child1());
2483         if (!(value.m_type & SpecEmpty)) {
2484             m_state.setFoundConstants(true);
2485             break;
2486         }
2487         
2488         filter(value, ~SpecEmpty);
2489         break;
2490     }
2491
2492     case CheckIdent: {
2493         AbstractValue& value = forNode(node->child1());
2494         UniquedStringImpl* uid = node->uidOperand();
2495         ASSERT(uid->isSymbol() ? !(value.m_type & ~SpecSymbol) : !(value.m_type & ~SpecStringIdent)); // Edge filtering should have already ensured this.
2496
2497         JSValue childConstant = value.value();
2498         if (childConstant) {
2499             if (uid->isSymbol()) {
2500                 ASSERT(childConstant.isSymbol());
2501                 if (asSymbol(childConstant)->privateName().uid() == uid) {
2502                     m_state.setFoundConstants(true);
2503                     break;
2504                 }
2505             } else {
2506                 ASSERT(childConstant.isString());
2507                 if (asString(childConstant)->tryGetValueImpl() == uid) {
2508                     m_state.setFoundConstants(true);
2509                     break;
2510                 }
2511             }
2512         }
2513
2514         filter(value, uid->isSymbol() ? SpecSymbol : SpecStringIdent);
2515         break;
2516     }
2517
2518     case CheckInBounds: {
2519         JSValue left = forNode(node->child1()).value();
2520         JSValue right = forNode(node->child2()).value();
2521         if (left && right && left.isInt32() && right.isInt32()
2522             && static_cast<uint32_t>(left.asInt32()) < static_cast<uint32_t>(right.asInt32())) {
2523             m_state.setFoundConstants(true);
2524             break;
2525         }
2526         break;
2527     }
2528         
2529     case PutById:
2530     case PutByIdFlush:
2531     case PutByIdDirect: {
2532         AbstractValue& value = forNode(node->child1());
2533         if (value.m_structure.isFinite()) {
2534             PutByIdStatus status = PutByIdStatus::computeFor(
2535                 m_graph.globalObjectFor(node->origin.semantic),
2536                 value.m_structure.set(),
2537                 m_graph.identifiers()[node->identifierNumber()],
2538                 node->op() == PutByIdDirect);
2539
2540             if (status.isSimple()) {
2541                 StructureSet newSet;
2542                 TransitionVector transitions;
2543                 
2544                 for (unsigned i = status.numVariants(); i--;) {
2545                     const PutByIdVariant& variant = status[i];
2546                     if (variant.kind() == PutByIdVariant::Transition) {
2547                         transitions.append(
2548                             Transition(
2549                                 variant.oldStructureForTransition(), variant.newStructure()));
2550                         m_graph.registerStructure(variant.newStructure());
2551                         newSet.add(variant.newStructure());
2552                     } else {
2553                         ASSERT(variant.kind() == PutByIdVariant::Replace);
2554                         newSet.merge(variant.oldStructure());
2555                     }
2556                 }
2557                 
2558                 if (status.numVariants() == 1 || isFTL(m_graph.m_plan.mode))
2559                     m_state.setFoundConstants(true);
2560                 
2561                 observeTransitions(clobberLimit, transitions);
2562                 if (forNode(node->child1()).changeStructure(m_graph, newSet) == Contradiction)
2563                     m_state.setIsValid(false);
2564                 break;
2565             }
2566         }
2567         
2568         clobberWorld(node->origin.semantic, clobberLimit);
2569         break;
2570     }
2571
2572     case PutGetterById:
2573     case PutSetterById:
2574     case PutGetterSetterById:
2575     case PutGetterByVal:
2576     case PutSetterByVal: {
2577         clobberWorld(node->origin.semantic, clobberLimit);
2578         break;
2579     }
2580         
2581     case In: {
2582         // FIXME: We can determine when the property definitely exists based on abstract
2583         // value information.
2584         clobberWorld(node->origin.semantic, clobberLimit);
2585         forNode(node).setType(SpecBoolean);
2586         break;
2587     }
2588             
2589     case GetEnumerableLength: {
2590         forNode(node).setType(SpecInt32);
2591         break;
2592     }
2593     case HasGenericProperty: {
2594         forNode(node).setType(SpecBoolean);
2595         break;
2596     }
2597     case HasStructureProperty: {
2598         forNode(node).setType(SpecBoolean);
2599         break;
2600     }
2601     case HasIndexedProperty: {
2602         ArrayMode mode = node->arrayMode();
2603         switch (mode.type()) {
2604         case Array::Int32:
2605         case Array::Double:
2606         case Array::Contiguous:
2607         case Array::ArrayStorage: {
2608             break;
2609         }
2610         default: {
2611             clobberWorld(node->origin.semantic, clobberLimit);
2612             break;
2613         }
2614         }
2615         forNode(node).setType(SpecBoolean);
2616         break;
2617     }
2618     case GetDirectPname: {
2619         clobberWorld(node->origin.semantic, clobberLimit);
2620         forNode(node).makeHeapTop();
2621         break;
2622     }
2623     case GetPropertyEnumerator: {
2624         forNode(node).setType(m_graph, SpecCell);
2625         break;
2626     }
2627     case GetEnumeratorStructurePname: {
2628         forNode(node).setType(m_graph, SpecString | SpecOther);
2629         break;
2630     }
2631     case GetEnumeratorGenericPname: {
2632         forNode(node).setType(m_graph, SpecString | SpecOther);
2633         break;
2634     }
2635     case ToIndexString: {
2636         forNode(node).setType(m_graph, SpecString);
2637         break;
2638     }
2639
2640     case GetGlobalVar:
2641         forNode(node).makeHeapTop();
2642         break;
2643     case GetGlobalLexicalVariable:
2644         forNode(node).makeBytecodeTop();
2645         break;
2646         
2647     case VarInjectionWatchpoint:
2648     case PutGlobalVariable:
2649     case NotifyWrite:
2650         break;
2651             
2652     case OverridesHasInstance:
2653         forNode(node).setType(SpecBoolean);
2654         break;
2655             
2656     case InstanceOf:
2657         // Sadly, we don't propagate the fact that we've done InstanceOf
2658         forNode(node).setType(SpecBoolean);
2659         break;
2660
2661     case InstanceOfCustom:
2662         clobberWorld(node->origin.semantic, clobberLimit);
2663         forNode(node).setType(SpecBoolean);
2664         break;
2665             
2666     case Phi:
2667         RELEASE_ASSERT(m_graph.m_form == SSA);
2668         // The state of this node would have already been decided, but it may have become a
2669         // constant, in which case we'd like to know.
2670         if (forNode(node).m_value)
2671             m_state.setFoundConstants(true);
2672         break;
2673         
2674     case Upsilon: {
2675         m_state.createValueForNode(node->phi());
2676         forNode(node->phi()) = forNode(node->child1());
2677         break;
2678     }
2679         
2680     case Flush:
2681     case PhantomLocal:
2682         break;
2683             
2684     case Call:
2685     case TailCallInlinedCaller:
2686     case Construct:
2687     case CallVarargs:
2688     case CallForwardVarargs:
2689     case TailCallVarargsInlinedCaller:
2690     case ConstructVarargs:
2691     case ConstructForwardVarargs:
2692     case TailCallForwardVarargsInlinedCaller:
2693         clobberWorld(node->origin.semantic, clobberLimit);
2694         forNode(node).makeHeapTop();
2695         break;
2696
2697     case ForceOSRExit:
2698     case CheckBadCell:
2699         m_state.setIsValid(false);
2700         break;
2701         
2702     case InvalidationPoint:
2703         forAllValues(clobberLimit, AbstractValue::observeInvalidationPointFor);
2704         m_state.setStructureClobberState(StructuresAreWatched);
2705         break;
2706
2707     case CheckWatchdogTimer:
2708     case LogShadowChickenPrologue:
2709     case LogShadowChickenTail:
2710         break;
2711
2712     case ProfileWillCall:
2713     case ProfileDidCall:
2714     case ProfileType:
2715     case ProfileControlFlow:
2716     case Phantom:
2717     case CountExecution:
2718     case CheckTierUpInLoop:
2719     case CheckTierUpAtReturn:
2720     case CheckTypeInfoFlags:
2721         break;
2722
2723     case CopyRest:
2724         break;
2725             
2726     case Check: {
2727         // Simplify out checks that don't actually do checking.
2728         for (unsigned i = 0; i < AdjacencyList::Size; ++i) {
2729             Edge edge = node->children.child(i);
2730             if (!edge)
2731                 break;
2732             if (edge.isProved() || edge.willNotHaveCheck()) {
2733                 m_state.setFoundConstants(true);
2734                 break;
2735             }
2736         }
2737         break;
2738     }
2739
2740     case SetFunctionName: {
2741         clobberWorld(node->origin.semantic, clobberLimit);
2742         break;
2743     }
2744
2745     case StoreBarrier: {
2746         filter(node->child1(), SpecCell);
2747         break;
2748     }
2749
2750     case CheckTierUpAndOSREnter:
2751     case LoopHint:
2752     case ZombieHint:
2753     case ExitOK:
2754         break;
2755
2756     case Unreachable:
2757     case LastNodeType:
2758     case ArithIMul:
2759     case FiatInt52:
2760         DFG_CRASH(m_graph, node, "Unexpected node type");
2761         break;
2762     }
2763     
2764     return m_state.isValid();
2765 }
2766
2767 template<typename AbstractStateType>
2768 bool AbstractInterpreter<AbstractStateType>::executeEffects(unsigned indexInBlock)
2769 {
2770     return executeEffects(indexInBlock, m_state.block()->at(indexInBlock));
2771 }
2772
2773 template<typename AbstractStateType>
2774 bool AbstractInterpreter<AbstractStateType>::execute(unsigned indexInBlock)
2775 {
2776     Node* node = m_state.block()->at(indexInBlock);
2777     
2778     startExecuting();
2779     executeEdges(node);
2780     return executeEffects(indexInBlock, node);
2781 }
2782
2783 template<typename AbstractStateType>
2784 bool AbstractInterpreter<AbstractStateType>::execute(Node* node)
2785 {
2786     startExecuting();
2787     executeEdges(node);
2788     return executeEffects(UINT_MAX, node);
2789 }
2790
2791 template<typename AbstractStateType>
2792 void AbstractInterpreter<AbstractStateType>::clobberWorld(
2793     const CodeOrigin&, unsigned clobberLimit)
2794 {
2795     clobberStructures(clobberLimit);
2796 }
2797
2798 template<typename AbstractStateType>
2799 template<typename Functor>
2800 void AbstractInterpreter<AbstractStateType>::forAllValues(
2801     unsigned clobberLimit, Functor& functor)
2802 {
2803     if (clobberLimit >= m_state.block()->size())
2804         clobberLimit = m_state.block()->size();
2805     else
2806         clobberLimit++;
2807     ASSERT(clobberLimit <= m_state.block()->size());
2808     for (size_t i = clobberLimit; i--;)
2809         functor(forNode(m_state.block()->at(i)));
2810     if (m_graph.m_form == SSA) {
2811         HashSet<Node*>::iterator iter = m_state.block()->ssa->liveAtHead.begin();
2812         HashSet<Node*>::iterator end = m_state.block()->ssa->liveAtHead.end();
2813         for (; iter != end; ++iter)
2814             functor(forNode(*iter));
2815     }
2816     for (size_t i = m_state.variables().numberOfArguments(); i--;)
2817         functor(m_state.variables().argument(i));
2818     for (size_t i = m_state.variables().numberOfLocals(); i--;)
2819         functor(m_state.variables().local(i));
2820 }
2821
2822 template<typename AbstractStateType>
2823 void AbstractInterpreter<AbstractStateType>::clobberStructures(unsigned clobberLimit)
2824 {
2825     forAllValues(clobberLimit, AbstractValue::clobberStructuresFor);
2826     setDidClobber();
2827 }
2828
2829 template<typename AbstractStateType>
2830 void AbstractInterpreter<AbstractStateType>::observeTransition(
2831     unsigned clobberLimit, Structure* from, Structure* to)
2832 {
2833     AbstractValue::TransitionObserver transitionObserver(from, to);
2834     forAllValues(clobberLimit, transitionObserver);
2835     
2836     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.
2837 }
2838
2839 template<typename AbstractStateType>
2840 void AbstractInterpreter<AbstractStateType>::observeTransitions(
2841     unsigned clobberLimit, const TransitionVector& vector)
2842 {
2843     AbstractValue::TransitionsObserver transitionsObserver(vector);
2844     forAllValues(clobberLimit, transitionsObserver);
2845     
2846     if (!ASSERT_DISABLED) {
2847         // We don't need to claim to be in a clobbered state because none of the Transition::previous structures are watchable.
2848         for (unsigned i = vector.size(); i--;)
2849             ASSERT(!vector[i].previous->dfgShouldWatch());
2850     }
2851 }
2852
2853 template<typename AbstractStateType>
2854 void AbstractInterpreter<AbstractStateType>::setDidClobber()
2855 {
2856     m_state.setDidClobber(true);
2857     m_state.setStructureClobberState(StructuresAreClobbered);
2858 }
2859
2860 template<typename AbstractStateType>
2861 void AbstractInterpreter<AbstractStateType>::dump(PrintStream& out) const
2862 {
2863     const_cast<AbstractInterpreter<AbstractStateType>*>(this)->dump(out);
2864 }
2865
2866 template<typename AbstractStateType>
2867 void AbstractInterpreter<AbstractStateType>::dump(PrintStream& out)
2868 {
2869     CommaPrinter comma(" ");
2870     HashSet<Node*> seen;
2871     if (m_graph.m_form == SSA) {
2872         HashSet<Node*>::iterator iter = m_state.block()->ssa->liveAtHead.begin();
2873         HashSet<Node*>::iterator end = m_state.block()->ssa->liveAtHead.end();
2874         for (; iter != end; ++iter) {
2875             Node* node = *iter;
2876             seen.add(node);
2877             AbstractValue& value = forNode(node);
2878             if (value.isClear())
2879                 continue;
2880             out.print(comma, node, ":", value);
2881         }
2882     }
2883     for (size_t i = 0; i < m_state.block()->size(); ++i) {
2884         Node* node = m_state.block()->at(i);
2885         seen.add(node);
2886         AbstractValue& value = forNode(node);
2887         if (value.isClear())
2888             continue;
2889         out.print(comma, node, ":", value);
2890     }
2891     if (m_graph.m_form == SSA) {
2892         HashSet<Node*>::iterator iter = m_state.block()->ssa->liveAtTail.begin();
2893         HashSet<Node*>::iterator end = m_state.block()->ssa->liveAtTail.end();
2894         for (; iter != end; ++iter) {
2895             Node* node = *iter;
2896             if (seen.contains(node))
2897                 continue;
2898             AbstractValue& value = forNode(node);
2899             if (value.isClear())
2900                 continue;
2901             out.print(comma, node, ":", value);
2902         }
2903     }
2904 }
2905
2906 template<typename AbstractStateType>
2907 FiltrationResult AbstractInterpreter<AbstractStateType>::filter(
2908     AbstractValue& value, const StructureSet& set, SpeculatedType admittedTypes)
2909 {
2910     if (value.filter(m_graph, set, admittedTypes) == FiltrationOK)
2911         return FiltrationOK;
2912     m_state.setIsValid(false);
2913     return Contradiction;
2914 }
2915
2916 template<typename AbstractStateType>
2917 FiltrationResult AbstractInterpreter<AbstractStateType>::filterArrayModes(
2918     AbstractValue& value, ArrayModes arrayModes)
2919 {
2920     if (value.filterArrayModes(arrayModes) == FiltrationOK)
2921         return FiltrationOK;
2922     m_state.setIsValid(false);
2923     return Contradiction;
2924 }
2925
2926 template<typename AbstractStateType>
2927 FiltrationResult AbstractInterpreter<AbstractStateType>::filter(
2928     AbstractValue& value, SpeculatedType type)
2929 {
2930     if (value.filter(type) == FiltrationOK)
2931         return FiltrationOK;
2932     m_state.setIsValid(false);
2933     return Contradiction;
2934 }
2935
2936 template<typename AbstractStateType>
2937 FiltrationResult AbstractInterpreter<AbstractStateType>::filterByValue(
2938     AbstractValue& abstractValue, FrozenValue concreteValue)
2939 {
2940     if (abstractValue.filterByValue(concreteValue) == FiltrationOK)
2941         return FiltrationOK;
2942     m_state.setIsValid(false);
2943     return Contradiction;
2944 }
2945
2946 } } // namespace JSC::DFG
2947
2948 #endif // ENABLE(DFG_JIT)
2949
2950 #endif // DFGAbstractInterpreterInlines_h
2951