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