[JSC] Implement optimized WeakMap and WeakSet
[WebKit-https.git] / Source / JavaScriptCore / dfg / DFGFixupPhase.cpp
1 /*
2  * Copyright (C) 2012-2017 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 #include "config.h"
27 #include "DFGFixupPhase.h"
28
29 #if ENABLE(DFG_JIT)
30
31 #include "ArrayPrototype.h"
32 #include "DFGGraph.h"
33 #include "DFGInferredTypeCheck.h"
34 #include "DFGInsertionSet.h"
35 #include "DFGPhase.h"
36 #include "DFGPredictionPropagationPhase.h"
37 #include "DFGVariableAccessDataDump.h"
38 #include "JSCInlines.h"
39 #include "TypeLocation.h"
40
41 namespace JSC { namespace DFG {
42
43 class FixupPhase : public Phase {
44 public:
45     FixupPhase(Graph& graph)
46         : Phase(graph, "fixup")
47         , m_insertionSet(graph)
48     {
49     }
50     
51     bool run()
52     {
53         ASSERT(m_graph.m_fixpointState == BeforeFixpoint);
54         ASSERT(m_graph.m_form == ThreadedCPS);
55         
56         m_profitabilityChanged = false;
57         for (BlockIndex blockIndex = 0; blockIndex < m_graph.numBlocks(); ++blockIndex)
58             fixupBlock(m_graph.block(blockIndex));
59         
60         while (m_profitabilityChanged) {
61             m_profitabilityChanged = false;
62             
63             for (unsigned i = m_graph.m_argumentPositions.size(); i--;)
64                 m_graph.m_argumentPositions[i].mergeArgumentUnboxingAwareness();
65             
66             for (BlockIndex blockIndex = 0; blockIndex < m_graph.numBlocks(); ++blockIndex)
67                 fixupGetAndSetLocalsInBlock(m_graph.block(blockIndex));
68         }
69         
70         for (BlockIndex blockIndex = 0; blockIndex < m_graph.numBlocks(); ++blockIndex)
71             fixupChecksInBlock(m_graph.block(blockIndex));
72
73         m_graph.m_planStage = PlanStage::AfterFixup;
74
75         return true;
76     }
77
78 private:
79     void fixupBlock(BasicBlock* block)
80     {
81         if (!block)
82             return;
83         ASSERT(block->isReachable);
84         m_block = block;
85         for (m_indexInBlock = 0; m_indexInBlock < block->size(); ++m_indexInBlock) {
86             m_currentNode = block->at(m_indexInBlock);
87             fixupNode(m_currentNode);
88         }
89         m_insertionSet.execute(block);
90     }
91     
92     void fixupNode(Node* node)
93     {
94         NodeType op = node->op();
95
96         switch (op) {
97         case SetLocal: {
98             // This gets handled by fixupGetAndSetLocalsInBlock().
99             return;
100         }
101             
102         case BitAnd:
103         case BitOr:
104         case BitXor:
105         case BitRShift:
106         case BitLShift:
107         case BitURShift: {
108             if (Node::shouldSpeculateUntypedForBitOps(node->child1().node(), node->child2().node())) {
109                 fixEdge<UntypedUse>(node->child1());
110                 fixEdge<UntypedUse>(node->child2());
111                 break;
112             }
113             fixIntConvertingEdge(node->child1());
114             fixIntConvertingEdge(node->child2());
115             break;
116         }
117
118         case ArithIMul: {
119             fixIntConvertingEdge(node->child1());
120             fixIntConvertingEdge(node->child2());
121             node->setOp(ArithMul);
122             node->setArithMode(Arith::Unchecked);
123             node->child1().setUseKind(Int32Use);
124             node->child2().setUseKind(Int32Use);
125             break;
126         }
127
128         case ArithClz32: {
129             if (node->child1()->shouldSpeculateNotCell()) {
130                 fixIntConvertingEdge(node->child1());
131                 node->clearFlags(NodeMustGenerate);
132             } else
133                 fixEdge<UntypedUse>(node->child1());
134             break;
135         }
136             
137         case UInt32ToNumber: {
138             fixIntConvertingEdge(node->child1());
139             if (bytecodeCanTruncateInteger(node->arithNodeFlags()))
140                 node->convertToIdentity();
141             else if (node->canSpeculateInt32(FixupPass))
142                 node->setArithMode(Arith::CheckOverflow);
143             else {
144                 node->setArithMode(Arith::DoOverflow);
145                 node->setResult(enableInt52() ? NodeResultInt52 : NodeResultDouble);
146             }
147             break;
148         }
149             
150         case ValueAdd: {
151             if (attemptToMakeIntegerAdd(node)) {
152                 node->setOp(ArithAdd);
153                 break;
154             }
155             if (Node::shouldSpeculateNumberOrBooleanExpectingDefined(node->child1().node(), node->child2().node())) {
156                 fixDoubleOrBooleanEdge(node->child1());
157                 fixDoubleOrBooleanEdge(node->child2());
158                 node->setOp(ArithAdd);
159                 node->setResult(NodeResultDouble);
160                 break;
161             }
162             
163             if (attemptToMakeFastStringAdd(node))
164                 break;
165
166             Edge& child1 = node->child1();
167             Edge& child2 = node->child2();
168             if (child1->shouldSpeculateString() || child2->shouldSpeculateString()) {
169                 if (child1->shouldSpeculateInt32() || child2->shouldSpeculateInt32()) {
170                     auto convertString = [&](Node* node, Edge& edge) {
171                         if (edge->shouldSpeculateInt32())
172                             convertStringAddUse<Int32Use>(node, edge);
173                         else {
174                             ASSERT(edge->shouldSpeculateString());
175                             convertStringAddUse<StringUse>(node, edge);
176                         }
177                     };
178                     convertString(node, child1);
179                     convertString(node, child2);
180                     convertToMakeRope(node);
181                     break;
182                 }
183             }
184
185             fixEdge<UntypedUse>(child1);
186             fixEdge<UntypedUse>(child2);
187             node->setResult(NodeResultJS);
188             break;
189         }
190
191         case StrCat: {
192             if (attemptToMakeFastStringAdd(node))
193                 break;
194
195             // FIXME: Remove empty string arguments and possibly turn this into a ToString operation. That
196             // would require a form of ToString that takes a KnownPrimitiveUse. This is necessary because
197             // the implementation of StrCat doesn't dynamically optimize for empty strings.
198             // https://bugs.webkit.org/show_bug.cgi?id=148540
199             m_graph.doToChildren(
200                 node,
201                 [&] (Edge& edge) {
202                     fixEdge<KnownPrimitiveUse>(edge);
203                     // StrCat automatically coerces the values into strings before concatenating them.
204                     // The ECMA spec says that we're not allowed to automatically coerce a Symbol into
205                     // a string. If a Symbol is encountered, a TypeError will be thrown. As a result,
206                     // our runtime functions for this slow path expect that they will never be passed
207                     // Symbols.
208                     m_insertionSet.insertNode(
209                         m_indexInBlock, SpecNone, Check, node->origin,
210                         Edge(edge.node(), NotSymbolUse));
211                 });
212             break;
213         }
214             
215         case MakeRope: {
216             fixupMakeRope(node);
217             break;
218         }
219             
220         case ArithAdd:
221         case ArithSub: {
222             if (op == ArithSub
223                 && Node::shouldSpeculateUntypedForArithmetic(node->child1().node(), node->child2().node())) {
224                 fixEdge<UntypedUse>(node->child1());
225                 fixEdge<UntypedUse>(node->child2());
226                 node->setResult(NodeResultJS);
227                 break;
228             }
229             if (attemptToMakeIntegerAdd(node))
230                 break;
231             fixDoubleOrBooleanEdge(node->child1());
232             fixDoubleOrBooleanEdge(node->child2());
233             node->setResult(NodeResultDouble);
234             break;
235         }
236             
237         case ArithNegate: {
238             if (node->child1()->shouldSpeculateInt32OrBoolean() && node->canSpeculateInt32(FixupPass)) {
239                 fixIntOrBooleanEdge(node->child1());
240                 if (bytecodeCanTruncateInteger(node->arithNodeFlags()))
241                     node->setArithMode(Arith::Unchecked);
242                 else if (bytecodeCanIgnoreNegativeZero(node->arithNodeFlags()))
243                     node->setArithMode(Arith::CheckOverflow);
244                 else
245                     node->setArithMode(Arith::CheckOverflowAndNegativeZero);
246                 node->setResult(NodeResultInt32);
247                 node->clearFlags(NodeMustGenerate);
248                 break;
249             }
250             if (m_graph.unaryArithShouldSpeculateAnyInt(node, FixupPass)) {
251                 fixEdge<Int52RepUse>(node->child1());
252                 if (bytecodeCanIgnoreNegativeZero(node->arithNodeFlags()))
253                     node->setArithMode(Arith::CheckOverflow);
254                 else
255                     node->setArithMode(Arith::CheckOverflowAndNegativeZero);
256                 node->setResult(NodeResultInt52);
257                 node->clearFlags(NodeMustGenerate);
258                 break;
259             }
260             if (node->child1()->shouldSpeculateNotCell()) {
261                 fixDoubleOrBooleanEdge(node->child1());
262                 node->setResult(NodeResultDouble);
263                 node->clearFlags(NodeMustGenerate);
264             } else
265                 fixEdge<UntypedUse>(node->child1());
266             break;
267         }
268             
269         case ArithMul: {
270             Edge& leftChild = node->child1();
271             Edge& rightChild = node->child2();
272             if (Node::shouldSpeculateUntypedForArithmetic(leftChild.node(), rightChild.node())) {
273                 fixEdge<UntypedUse>(leftChild);
274                 fixEdge<UntypedUse>(rightChild);
275                 node->setResult(NodeResultJS);
276                 break;
277             }
278             if (m_graph.binaryArithShouldSpeculateInt32(node, FixupPass)) {
279                 fixIntOrBooleanEdge(leftChild);
280                 fixIntOrBooleanEdge(rightChild);
281                 if (bytecodeCanTruncateInteger(node->arithNodeFlags()))
282                     node->setArithMode(Arith::Unchecked);
283                 else if (bytecodeCanIgnoreNegativeZero(node->arithNodeFlags())
284                     || leftChild.node() == rightChild.node())
285                     node->setArithMode(Arith::CheckOverflow);
286                 else
287                     node->setArithMode(Arith::CheckOverflowAndNegativeZero);
288                 break;
289             }
290             if (m_graph.binaryArithShouldSpeculateAnyInt(node, FixupPass)) {
291                 fixEdge<Int52RepUse>(leftChild);
292                 fixEdge<Int52RepUse>(rightChild);
293                 if (bytecodeCanIgnoreNegativeZero(node->arithNodeFlags())
294                     || leftChild.node() == rightChild.node())
295                     node->setArithMode(Arith::CheckOverflow);
296                 else
297                     node->setArithMode(Arith::CheckOverflowAndNegativeZero);
298                 node->setResult(NodeResultInt52);
299                 break;
300             }
301             fixDoubleOrBooleanEdge(leftChild);
302             fixDoubleOrBooleanEdge(rightChild);
303             node->setResult(NodeResultDouble);
304             break;
305         }
306
307         case ArithDiv:
308         case ArithMod: {
309             Edge& leftChild = node->child1();
310             Edge& rightChild = node->child2();
311             if (op == ArithDiv
312                 && Node::shouldSpeculateUntypedForArithmetic(leftChild.node(), rightChild.node())
313                 && m_graph.hasExitSite(node->origin.semantic, BadType)) {
314                 fixEdge<UntypedUse>(leftChild);
315                 fixEdge<UntypedUse>(rightChild);
316                 node->setResult(NodeResultJS);
317                 break;
318             }
319             if (m_graph.binaryArithShouldSpeculateInt32(node, FixupPass)) {
320                 if (optimizeForX86() || optimizeForARM64() || optimizeForARMv7IDIVSupported()) {
321                     fixIntOrBooleanEdge(leftChild);
322                     fixIntOrBooleanEdge(rightChild);
323                     if (bytecodeCanTruncateInteger(node->arithNodeFlags()))
324                         node->setArithMode(Arith::Unchecked);
325                     else if (bytecodeCanIgnoreNegativeZero(node->arithNodeFlags()))
326                         node->setArithMode(Arith::CheckOverflow);
327                     else
328                         node->setArithMode(Arith::CheckOverflowAndNegativeZero);
329                     break;
330                 }
331                 
332                 // This will cause conversion nodes to be inserted later.
333                 fixDoubleOrBooleanEdge(leftChild);
334                 fixDoubleOrBooleanEdge(rightChild);
335                 
336                 // We don't need to do ref'ing on the children because we're stealing them from
337                 // the original division.
338                 Node* newDivision = m_insertionSet.insertNode(
339                     m_indexInBlock, SpecBytecodeDouble, *node);
340                 newDivision->setResult(NodeResultDouble);
341                 
342                 node->setOp(DoubleAsInt32);
343                 node->children.initialize(Edge(newDivision, DoubleRepUse), Edge(), Edge());
344                 if (bytecodeCanIgnoreNegativeZero(node->arithNodeFlags()))
345                     node->setArithMode(Arith::CheckOverflow);
346                 else
347                     node->setArithMode(Arith::CheckOverflowAndNegativeZero);
348                 break;
349             }
350             fixDoubleOrBooleanEdge(leftChild);
351             fixDoubleOrBooleanEdge(rightChild);
352             node->setResult(NodeResultDouble);
353             break;
354         }
355             
356         case ArithMin:
357         case ArithMax: {
358             if (m_graph.binaryArithShouldSpeculateInt32(node, FixupPass)) {
359                 fixIntOrBooleanEdge(node->child1());
360                 fixIntOrBooleanEdge(node->child2());
361                 break;
362             }
363             fixDoubleOrBooleanEdge(node->child1());
364             fixDoubleOrBooleanEdge(node->child2());
365             node->setResult(NodeResultDouble);
366             break;
367         }
368             
369         case ArithAbs: {
370             if (node->child1()->shouldSpeculateInt32OrBoolean()
371                 && node->canSpeculateInt32(FixupPass)) {
372                 fixIntOrBooleanEdge(node->child1());
373                 if (bytecodeCanTruncateInteger(node->arithNodeFlags()))
374                     node->setArithMode(Arith::Unchecked);
375                 else
376                     node->setArithMode(Arith::CheckOverflow);
377                 node->clearFlags(NodeMustGenerate);
378                 node->setResult(NodeResultInt32);
379                 break;
380             }
381
382             if (node->child1()->shouldSpeculateNotCell()) {
383                 fixDoubleOrBooleanEdge(node->child1());
384                 node->clearFlags(NodeMustGenerate);
385             } else
386                 fixEdge<UntypedUse>(node->child1());
387             node->setResult(NodeResultDouble);
388             break;
389         }
390
391         case ArithPow: {
392             if (node->child2()->shouldSpeculateInt32OrBooleanForArithmetic()) {
393                 fixDoubleOrBooleanEdge(node->child1());
394                 fixIntOrBooleanEdge(node->child2());
395                 break;
396             }
397
398             fixDoubleOrBooleanEdge(node->child1());
399             fixDoubleOrBooleanEdge(node->child2());
400             break;
401         }
402
403         case ArithRandom: {
404             node->setResult(NodeResultDouble);
405             break;
406         }
407
408         case ArithRound:
409         case ArithFloor:
410         case ArithCeil:
411         case ArithTrunc: {
412             if (node->child1()->shouldSpeculateInt32OrBoolean() && m_graph.roundShouldSpeculateInt32(node, FixupPass)) {
413                 fixIntOrBooleanEdge(node->child1());
414                 insertCheck<Int32Use>(node->child1().node());
415                 node->convertToIdentity();
416                 break;
417             }
418             if (node->child1()->shouldSpeculateNotCell()) {
419                 fixDoubleOrBooleanEdge(node->child1());
420
421                 if (isInt32OrBooleanSpeculation(node->getHeapPrediction()) && m_graph.roundShouldSpeculateInt32(node, FixupPass)) {
422                     node->setResult(NodeResultInt32);
423                     if (bytecodeCanIgnoreNegativeZero(node->arithNodeFlags()))
424                         node->setArithRoundingMode(Arith::RoundingMode::Int32);
425                     else
426                         node->setArithRoundingMode(Arith::RoundingMode::Int32WithNegativeZeroCheck);
427                 } else {
428                     node->setResult(NodeResultDouble);
429                     node->setArithRoundingMode(Arith::RoundingMode::Double);
430                 }
431                 node->clearFlags(NodeMustGenerate);
432             } else
433                 fixEdge<UntypedUse>(node->child1());
434             break;
435         }
436
437         case ArithFRound:
438         case ArithSqrt:
439         case ArithUnary: {
440             Edge& child1 = node->child1();
441             if (child1->shouldSpeculateNotCell()) {
442                 fixDoubleOrBooleanEdge(child1);
443                 node->clearFlags(NodeMustGenerate);
444             } else
445                 fixEdge<UntypedUse>(child1);
446             break;
447         }
448             
449         case LogicalNot: {
450             if (node->child1()->shouldSpeculateBoolean()) {
451                 if (node->child1()->result() == NodeResultBoolean) {
452                     // This is necessary in case we have a bytecode instruction implemented by:
453                     //
454                     // a: CompareEq(...)
455                     // b: LogicalNot(@a)
456                     //
457                     // In that case, CompareEq might have a side-effect. Then, we need to make
458                     // sure that we know that Branch does not exit.
459                     fixEdge<KnownBooleanUse>(node->child1());
460                 } else
461                     fixEdge<BooleanUse>(node->child1());
462             } else if (node->child1()->shouldSpeculateObjectOrOther())
463                 fixEdge<ObjectOrOtherUse>(node->child1());
464             else if (node->child1()->shouldSpeculateInt32OrBoolean())
465                 fixIntOrBooleanEdge(node->child1());
466             else if (node->child1()->shouldSpeculateNumber())
467                 fixEdge<DoubleRepUse>(node->child1());
468             else if (node->child1()->shouldSpeculateString())
469                 fixEdge<StringUse>(node->child1());
470             else if (node->child1()->shouldSpeculateStringOrOther())
471                 fixEdge<StringOrOtherUse>(node->child1());
472             else {
473                 WatchpointSet* masqueradesAsUndefinedWatchpoint = m_graph.globalObjectFor(node->origin.semantic)->masqueradesAsUndefinedWatchpoint();
474                 if (masqueradesAsUndefinedWatchpoint->isStillValid())
475                     m_graph.watchpoints().addLazily(masqueradesAsUndefinedWatchpoint);
476             }
477             break;
478         }
479
480         case CompareEq:
481         case CompareLess:
482         case CompareLessEq:
483         case CompareGreater:
484         case CompareGreaterEq: {
485             if (node->op() == CompareEq
486                 && Node::shouldSpeculateBoolean(node->child1().node(), node->child2().node())) {
487                 fixEdge<BooleanUse>(node->child1());
488                 fixEdge<BooleanUse>(node->child2());
489                 node->clearFlags(NodeMustGenerate);
490                 break;
491             }
492             if (Node::shouldSpeculateInt32OrBoolean(node->child1().node(), node->child2().node())) {
493                 fixIntOrBooleanEdge(node->child1());
494                 fixIntOrBooleanEdge(node->child2());
495                 node->clearFlags(NodeMustGenerate);
496                 break;
497             }
498             if (enableInt52()
499                 && Node::shouldSpeculateAnyInt(node->child1().node(), node->child2().node())) {
500                 fixEdge<Int52RepUse>(node->child1());
501                 fixEdge<Int52RepUse>(node->child2());
502                 node->clearFlags(NodeMustGenerate);
503                 break;
504             }
505             if (Node::shouldSpeculateNumberOrBoolean(node->child1().node(), node->child2().node())) {
506                 fixDoubleOrBooleanEdge(node->child1());
507                 fixDoubleOrBooleanEdge(node->child2());
508             }
509             if (node->op() != CompareEq
510                 && node->child1()->shouldSpeculateNotCell()
511                 && node->child2()->shouldSpeculateNotCell()) {
512                 if (node->child1()->shouldSpeculateNumberOrBoolean())
513                     fixDoubleOrBooleanEdge(node->child1());
514                 else
515                     fixEdge<DoubleRepUse>(node->child1());
516                 if (node->child2()->shouldSpeculateNumberOrBoolean())
517                     fixDoubleOrBooleanEdge(node->child2());
518                 else
519                     fixEdge<DoubleRepUse>(node->child2());
520                 node->clearFlags(NodeMustGenerate);
521                 break;
522             }
523             if (node->child1()->shouldSpeculateStringIdent() && node->child2()->shouldSpeculateStringIdent()) {
524                 fixEdge<StringIdentUse>(node->child1());
525                 fixEdge<StringIdentUse>(node->child2());
526                 node->clearFlags(NodeMustGenerate);
527                 break;
528             }
529             if (node->child1()->shouldSpeculateString() && node->child2()->shouldSpeculateString() && GPRInfo::numberOfRegisters >= 7) {
530                 fixEdge<StringUse>(node->child1());
531                 fixEdge<StringUse>(node->child2());
532                 node->clearFlags(NodeMustGenerate);
533                 break;
534             }
535
536             if (node->op() != CompareEq)
537                 break;
538             if (Node::shouldSpeculateSymbol(node->child1().node(), node->child2().node())) {
539                 fixEdge<SymbolUse>(node->child1());
540                 fixEdge<SymbolUse>(node->child2());
541                 node->clearFlags(NodeMustGenerate);
542                 break;
543             }
544             if (node->child1()->shouldSpeculateObject() && node->child2()->shouldSpeculateObject()) {
545                 fixEdge<ObjectUse>(node->child1());
546                 fixEdge<ObjectUse>(node->child2());
547                 node->clearFlags(NodeMustGenerate);
548                 break;
549             }
550
551             // If either child can be proved to be Null or Undefined, comparing them is greatly simplified.
552             bool oneArgumentIsUsedAsSpecOther = false;
553             if (node->child1()->isUndefinedOrNullConstant()) {
554                 fixEdge<OtherUse>(node->child1());
555                 oneArgumentIsUsedAsSpecOther = true;
556             } else if (node->child1()->shouldSpeculateOther()) {
557                 m_insertionSet.insertNode(m_indexInBlock, SpecNone, Check, node->origin,
558                     Edge(node->child1().node(), OtherUse));
559                 fixEdge<OtherUse>(node->child1());
560                 oneArgumentIsUsedAsSpecOther = true;
561             }
562             if (node->child2()->isUndefinedOrNullConstant()) {
563                 fixEdge<OtherUse>(node->child2());
564                 oneArgumentIsUsedAsSpecOther = true;
565             } else if (node->child2()->shouldSpeculateOther()) {
566                 m_insertionSet.insertNode(m_indexInBlock, SpecNone, Check, node->origin,
567                     Edge(node->child2().node(), OtherUse));
568                 fixEdge<OtherUse>(node->child2());
569                 oneArgumentIsUsedAsSpecOther = true;
570             }
571             if (oneArgumentIsUsedAsSpecOther) {
572                 node->clearFlags(NodeMustGenerate);
573                 break;
574             }
575
576             if (node->child1()->shouldSpeculateObject() && node->child2()->shouldSpeculateObjectOrOther()) {
577                 fixEdge<ObjectUse>(node->child1());
578                 fixEdge<ObjectOrOtherUse>(node->child2());
579                 node->clearFlags(NodeMustGenerate);
580                 break;
581             }
582             if (node->child1()->shouldSpeculateObjectOrOther() && node->child2()->shouldSpeculateObject()) {
583                 fixEdge<ObjectOrOtherUse>(node->child1());
584                 fixEdge<ObjectUse>(node->child2());
585                 node->clearFlags(NodeMustGenerate);
586                 break;
587             }
588
589             break;
590         }
591             
592         case CompareStrictEq: {
593             if (Node::shouldSpeculateBoolean(node->child1().node(), node->child2().node())) {
594                 fixEdge<BooleanUse>(node->child1());
595                 fixEdge<BooleanUse>(node->child2());
596                 break;
597             }
598             if (Node::shouldSpeculateInt32(node->child1().node(), node->child2().node())) {
599                 fixEdge<Int32Use>(node->child1());
600                 fixEdge<Int32Use>(node->child2());
601                 break;
602             }
603             if (enableInt52()
604                 && Node::shouldSpeculateAnyInt(node->child1().node(), node->child2().node())) {
605                 fixEdge<Int52RepUse>(node->child1());
606                 fixEdge<Int52RepUse>(node->child2());
607                 break;
608             }
609             if (Node::shouldSpeculateNumber(node->child1().node(), node->child2().node())) {
610                 fixEdge<DoubleRepUse>(node->child1());
611                 fixEdge<DoubleRepUse>(node->child2());
612                 break;
613             }
614             if (Node::shouldSpeculateSymbol(node->child1().node(), node->child2().node())) {
615                 fixEdge<SymbolUse>(node->child1());
616                 fixEdge<SymbolUse>(node->child2());
617                 break;
618             }
619             if (node->child1()->shouldSpeculateStringIdent() && node->child2()->shouldSpeculateStringIdent()) {
620                 fixEdge<StringIdentUse>(node->child1());
621                 fixEdge<StringIdentUse>(node->child2());
622                 break;
623             }
624             if (node->child1()->shouldSpeculateString() && node->child2()->shouldSpeculateString() && ((GPRInfo::numberOfRegisters >= 7) || isFTL(m_graph.m_plan.mode))) {
625                 fixEdge<StringUse>(node->child1());
626                 fixEdge<StringUse>(node->child2());
627                 break;
628             }
629             WatchpointSet* masqueradesAsUndefinedWatchpoint = m_graph.globalObjectFor(node->origin.semantic)->masqueradesAsUndefinedWatchpoint();
630             if (masqueradesAsUndefinedWatchpoint->isStillValid()) {
631                 
632                 if (node->child1()->shouldSpeculateObject()) {
633                     m_graph.watchpoints().addLazily(masqueradesAsUndefinedWatchpoint);
634                     fixEdge<ObjectUse>(node->child1());
635                     break;
636                 }
637                 if (node->child2()->shouldSpeculateObject()) {
638                     m_graph.watchpoints().addLazily(masqueradesAsUndefinedWatchpoint);
639                     fixEdge<ObjectUse>(node->child2());
640                     break;
641                 }
642                 
643             } else if (node->child1()->shouldSpeculateObject() && node->child2()->shouldSpeculateObject()) {
644                 fixEdge<ObjectUse>(node->child1());
645                 fixEdge<ObjectUse>(node->child2());
646                 break;
647             }
648             if (node->child1()->shouldSpeculateSymbol()) {
649                 fixEdge<SymbolUse>(node->child1());
650                 break;
651             }
652             if (node->child2()->shouldSpeculateSymbol()) {
653                 fixEdge<SymbolUse>(node->child2());
654                 break;
655             }
656             if (node->child1()->shouldSpeculateMisc()) {
657                 fixEdge<MiscUse>(node->child1());
658                 break;
659             }
660             if (node->child2()->shouldSpeculateMisc()) {
661                 fixEdge<MiscUse>(node->child2());
662                 break;
663             }
664             if (node->child1()->shouldSpeculateStringIdent()
665                 && node->child2()->shouldSpeculateNotStringVar()) {
666                 fixEdge<StringIdentUse>(node->child1());
667                 fixEdge<NotStringVarUse>(node->child2());
668                 break;
669             }
670             if (node->child2()->shouldSpeculateStringIdent()
671                 && node->child1()->shouldSpeculateNotStringVar()) {
672                 fixEdge<StringIdentUse>(node->child2());
673                 fixEdge<NotStringVarUse>(node->child1());
674                 break;
675             }
676             if (node->child1()->shouldSpeculateString() && ((GPRInfo::numberOfRegisters >= 8) || isFTL(m_graph.m_plan.mode))) {
677                 fixEdge<StringUse>(node->child1());
678                 break;
679             }
680             if (node->child2()->shouldSpeculateString() && ((GPRInfo::numberOfRegisters >= 8) || isFTL(m_graph.m_plan.mode))) {
681                 fixEdge<StringUse>(node->child2());
682                 break;
683             }
684             break;
685         }
686             
687         case StringFromCharCode:
688             if (node->child1()->shouldSpeculateInt32())
689                 fixEdge<Int32Use>(node->child1());
690             else
691                 fixEdge<UntypedUse>(node->child1());
692             break;
693
694         case StringCharAt:
695         case StringCharCodeAt: {
696             // Currently we have no good way of refining these.
697             ASSERT(node->arrayMode() == ArrayMode(Array::String));
698             blessArrayOperation(node->child1(), node->child2(), node->child3());
699             fixEdge<KnownCellUse>(node->child1());
700             fixEdge<Int32Use>(node->child2());
701             break;
702         }
703
704         case GetByVal: {
705             if (!node->prediction()) {
706                 m_insertionSet.insertNode(
707                     m_indexInBlock, SpecNone, ForceOSRExit, node->origin);
708             }
709             
710             node->setArrayMode(
711                 node->arrayMode().refine(
712                     m_graph, node,
713                     node->child1()->prediction(),
714                     node->child2()->prediction(),
715                     SpecNone));
716             
717             blessArrayOperation(node->child1(), node->child2(), node->child3());
718             
719             ArrayMode arrayMode = node->arrayMode();
720             switch (arrayMode.type()) {
721             case Array::Contiguous:
722             case Array::Double:
723                 if (arrayMode.arrayClass() == Array::OriginalArray
724                     && arrayMode.speculation() == Array::InBounds) {
725                     JSGlobalObject* globalObject = m_graph.globalObjectFor(node->origin.semantic);
726                     if (globalObject->arrayPrototypeChainIsSane()) {
727                         // Check if SaneChain will work on a per-type basis. Note that:
728                         //
729                         // 1) We don't want double arrays to sometimes return undefined, since
730                         // that would require a change to the return type and it would pessimise
731                         // things a lot. So, we'd only want to do that if we actually had
732                         // evidence that we could read from a hole. That's pretty annoying.
733                         // Likely the best way to handle that case is with an equivalent of
734                         // SaneChain for OutOfBounds. For now we just detect when Undefined and
735                         // NaN are indistinguishable according to backwards propagation, and just
736                         // use SaneChain in that case. This happens to catch a lot of cases.
737                         //
738                         // 2) We don't want int32 array loads to have to do a hole check just to
739                         // coerce to Undefined, since that would mean twice the checks.
740                         //
741                         // This has two implications. First, we have to do more checks than we'd
742                         // like. It's unfortunate that we have to do the hole check. Second,
743                         // some accesses that hit a hole will now need to take the full-blown
744                         // out-of-bounds slow path. We can fix that with:
745                         // https://bugs.webkit.org/show_bug.cgi?id=144668
746                         
747                         bool canDoSaneChain = false;
748                         switch (arrayMode.type()) {
749                         case Array::Contiguous:
750                             // This is happens to be entirely natural. We already would have
751                             // returned any JSValue, and now we'll return Undefined. We still do
752                             // the check but it doesn't require taking any kind of slow path.
753                             canDoSaneChain = true;
754                             break;
755                             
756                         case Array::Double:
757                             if (!(node->flags() & NodeBytecodeUsesAsOther)) {
758                                 // Holes look like NaN already, so if the user doesn't care
759                                 // about the difference between Undefined and NaN then we can
760                                 // do this.
761                                 canDoSaneChain = true;
762                             }
763                             break;
764                             
765                         default:
766                             break;
767                         }
768                         
769                         if (canDoSaneChain) {
770                             m_graph.registerAndWatchStructureTransition(globalObject->arrayPrototype()->structure());
771                             m_graph.registerAndWatchStructureTransition(globalObject->objectPrototype()->structure());
772                             if (globalObject->arrayPrototypeChainIsSane())
773                                 node->setArrayMode(arrayMode.withSpeculation(Array::SaneChain));
774                         }
775                     }
776                 }
777                 break;
778                 
779             case Array::String:
780                 if ((node->prediction() & ~SpecString)
781                     || m_graph.hasExitSite(node->origin.semantic, OutOfBounds))
782                     node->setArrayMode(arrayMode.withSpeculation(Array::OutOfBounds));
783                 break;
784                 
785             default:
786                 break;
787             }
788             
789             arrayMode = node->arrayMode();
790             switch (arrayMode.type()) {
791             case Array::SelectUsingPredictions:
792             case Array::Unprofiled:
793                 RELEASE_ASSERT_NOT_REACHED();
794                 break;
795             case Array::Generic:
796                 if (node->child1()->shouldSpeculateObject()) {
797                     if (node->child2()->shouldSpeculateString()) {
798                         fixEdge<ObjectUse>(node->child1());
799                         fixEdge<StringUse>(node->child2());
800                         break;
801                     }
802
803                     if (node->child2()->shouldSpeculateSymbol()) {
804                         fixEdge<ObjectUse>(node->child1());
805                         fixEdge<SymbolUse>(node->child2());
806                         break;
807                     }
808                 }
809 #if USE(JSVALUE32_64)
810                 fixEdge<CellUse>(node->child1()); // Speculating cell due to register pressure on 32-bit.
811 #endif
812                 break;
813             case Array::ForceExit:
814                 break;
815             default:
816                 fixEdge<KnownCellUse>(node->child1());
817                 fixEdge<Int32Use>(node->child2());
818                 break;
819             }
820             
821             switch (arrayMode.type()) {
822             case Array::Double:
823                 if (!arrayMode.isOutOfBounds())
824                     node->setResult(NodeResultDouble);
825                 break;
826                 
827             case Array::Float32Array:
828             case Array::Float64Array:
829                 node->setResult(NodeResultDouble);
830                 break;
831                 
832             case Array::Uint32Array:
833                 if (node->shouldSpeculateInt32())
834                     break;
835                 if (node->shouldSpeculateAnyInt() && enableInt52())
836                     node->setResult(NodeResultInt52);
837                 else
838                     node->setResult(NodeResultDouble);
839                 break;
840                 
841             default:
842                 break;
843             }
844             
845             break;
846         }
847
848         case PutByValDirect:
849         case PutByVal:
850         case PutByValAlias: {
851             Edge& child1 = m_graph.varArgChild(node, 0);
852             Edge& child2 = m_graph.varArgChild(node, 1);
853             Edge& child3 = m_graph.varArgChild(node, 2);
854
855             node->setArrayMode(
856                 node->arrayMode().refine(
857                     m_graph, node,
858                     child1->prediction(),
859                     child2->prediction(),
860                     child3->prediction()));
861             
862             blessArrayOperation(child1, child2, m_graph.varArgChild(node, 3));
863             
864             switch (node->arrayMode().modeForPut().type()) {
865             case Array::SelectUsingPredictions:
866             case Array::SelectUsingArguments:
867             case Array::Unprofiled:
868             case Array::Undecided:
869                 RELEASE_ASSERT_NOT_REACHED();
870                 break;
871             case Array::ForceExit:
872             case Array::Generic:
873                 if (child1->shouldSpeculateCell()) {
874                     if (child2->shouldSpeculateString()) {
875                         fixEdge<CellUse>(child1);
876                         fixEdge<StringUse>(child2);
877                         break;
878                     }
879
880                     if (child2->shouldSpeculateSymbol()) {
881                         fixEdge<CellUse>(child1);
882                         fixEdge<SymbolUse>(child2);
883                         break;
884                     }
885                 }
886 #if USE(JSVALUE32_64)
887                 // Due to register pressure on 32-bit, we speculate cell and
888                 // ignore the base-is-not-cell case entirely by letting the
889                 // baseline JIT handle it.
890                 fixEdge<CellUse>(child1);
891 #endif
892                 break;
893             case Array::Int32:
894                 fixEdge<KnownCellUse>(child1);
895                 fixEdge<Int32Use>(child2);
896                 fixEdge<Int32Use>(child3);
897                 break;
898             case Array::Double:
899                 fixEdge<KnownCellUse>(child1);
900                 fixEdge<Int32Use>(child2);
901                 fixEdge<DoubleRepRealUse>(child3);
902                 break;
903             case Array::Int8Array:
904             case Array::Int16Array:
905             case Array::Int32Array:
906             case Array::Uint8Array:
907             case Array::Uint8ClampedArray:
908             case Array::Uint16Array:
909             case Array::Uint32Array:
910                 fixEdge<KnownCellUse>(child1);
911                 fixEdge<Int32Use>(child2);
912                 if (child3->shouldSpeculateInt32())
913                     fixIntOrBooleanEdge(child3);
914                 else if (child3->shouldSpeculateAnyInt())
915                     fixEdge<Int52RepUse>(child3);
916                 else
917                     fixDoubleOrBooleanEdge(child3);
918                 break;
919             case Array::Float32Array:
920             case Array::Float64Array:
921                 fixEdge<KnownCellUse>(child1);
922                 fixEdge<Int32Use>(child2);
923                 fixDoubleOrBooleanEdge(child3);
924                 break;
925             case Array::Contiguous:
926             case Array::ArrayStorage:
927             case Array::SlowPutArrayStorage:
928                 fixEdge<KnownCellUse>(child1);
929                 fixEdge<Int32Use>(child2);
930                 speculateForBarrier(child3);
931                 break;
932             default:
933                 fixEdge<KnownCellUse>(child1);
934                 fixEdge<Int32Use>(child2);
935                 break;
936             }
937             break;
938         }
939             
940         case AtomicsAdd:
941         case AtomicsAnd:
942         case AtomicsCompareExchange:
943         case AtomicsExchange:
944         case AtomicsLoad:
945         case AtomicsOr:
946         case AtomicsStore:
947         case AtomicsSub:
948         case AtomicsXor: {
949             Edge& base = m_graph.child(node, 0);
950             Edge& index = m_graph.child(node, 1);
951             
952             bool badNews = false;
953             for (unsigned i = numExtraAtomicsArgs(node->op()); i--;) {
954                 Edge& child = m_graph.child(node, 2 + i);
955                 // NOTE: DFG is not smart enough to handle double->int conversions in atomics. So, we
956                 // just call the function when that happens. But the FTL is totally cool with those
957                 // conversions.
958                 if (!child->shouldSpeculateInt32()
959                     && !child->shouldSpeculateAnyInt()
960                     && !(child->shouldSpeculateNumberOrBoolean() && isFTL(m_graph.m_plan.mode)))
961                     badNews = true;
962             }
963             
964             if (badNews) {
965                 node->setArrayMode(ArrayMode(Array::Generic));
966                 break;
967             }
968             
969             node->setArrayMode(
970                 node->arrayMode().refine(
971                     m_graph, node, base->prediction(), index->prediction()));
972             
973             if (node->arrayMode().type() == Array::Generic)
974                 break;
975             
976             for (unsigned i = numExtraAtomicsArgs(node->op()); i--;) {
977                 Edge& child = m_graph.child(node, 2 + i);
978                 if (child->shouldSpeculateInt32())
979                     fixIntOrBooleanEdge(child);
980                 else if (child->shouldSpeculateAnyInt())
981                     fixEdge<Int52RepUse>(child);
982                 else {
983                     RELEASE_ASSERT(child->shouldSpeculateNumberOrBoolean() && isFTL(m_graph.m_plan.mode));
984                     fixDoubleOrBooleanEdge(child);
985                 }
986             }
987             
988             blessArrayOperation(base, index, m_graph.child(node, 2 + numExtraAtomicsArgs(node->op())));
989             fixEdge<CellUse>(base);
990             fixEdge<Int32Use>(index);
991             
992             if (node->arrayMode().type() == Array::Uint32Array) {
993                 // NOTE: This means basically always doing Int52.
994                 if (node->shouldSpeculateAnyInt() && enableInt52())
995                     node->setResult(NodeResultInt52);
996                 else
997                     node->setResult(NodeResultDouble);
998             }
999             break;
1000         }
1001             
1002         case AtomicsIsLockFree:
1003             if (node->child1()->shouldSpeculateInt32())
1004                 fixIntOrBooleanEdge(node->child1());
1005             break;
1006             
1007         case ArrayPush: {
1008             // May need to refine the array mode in case the value prediction contravenes
1009             // the array prediction. For example, we may have evidence showing that the
1010             // array is in Int32 mode, but the value we're storing is likely to be a double.
1011             // Then we should turn this into a conversion to Double array followed by the
1012             // push. On the other hand, we absolutely don't want to refine based on the
1013             // base prediction. If it has non-cell garbage in it, then we want that to be
1014             // ignored. That's because ArrayPush can't handle any array modes that aren't
1015             // array-related - so if refine() turned this into a "Generic" ArrayPush then
1016             // that would break things.
1017             Edge& storageEdge = m_graph.varArgChild(node, 0);
1018             Edge& arrayEdge = m_graph.varArgChild(node, 1);
1019             unsigned elementOffset = 2;
1020             unsigned elementCount = node->numChildren() - elementOffset;
1021             for (unsigned i = 0; i < elementCount; ++i) {
1022                 Edge& element = m_graph.varArgChild(node, i + elementOffset);
1023                 node->setArrayMode(
1024                     node->arrayMode().refine(
1025                         m_graph, node,
1026                         arrayEdge->prediction() & SpecCell,
1027                         SpecInt32Only,
1028                         element->prediction()));
1029             }
1030             blessArrayOperation(arrayEdge, Edge(), storageEdge);
1031             fixEdge<KnownCellUse>(arrayEdge);
1032
1033             // Convert `array.push()` to GetArrayLength.
1034             if (!elementCount && node->arrayMode().supportsSelfLength()) {
1035                 node->setOpAndDefaultFlags(GetArrayLength);
1036                 node->child1() = arrayEdge;
1037                 node->child2() = storageEdge;
1038                 fixEdge<KnownCellUse>(node->child1());
1039                 break;
1040             }
1041
1042             // We do not want to perform osr exit and retry for ArrayPush. We insert Check with appropriate type,
1043             // and ArrayPush uses the edge as known typed edge. Therefore, ArrayPush do not need to perform type checks.
1044             for (unsigned i = 0; i < elementCount; ++i) {
1045                 Edge& element = m_graph.varArgChild(node, i + elementOffset);
1046                 switch (node->arrayMode().type()) {
1047                 case Array::Int32:
1048                     insertCheck<Int32Use>(element.node());
1049                     fixEdge<KnownInt32Use>(element);
1050                     break;
1051                 case Array::Double:
1052                     insertCheck<DoubleRepRealUse>(element.node());
1053                     fixEdge<DoubleRepUse>(element);
1054                     break;
1055                 case Array::Contiguous:
1056                 case Array::ArrayStorage:
1057                     speculateForBarrier(element);
1058                     break;
1059                 default:
1060                     break;
1061                 }
1062                 ASSERT(shouldNotHaveTypeCheck(element.useKind()));
1063             }
1064             break;
1065         }
1066             
1067         case ArrayPop: {
1068             blessArrayOperation(node->child1(), Edge(), node->child2());
1069             fixEdge<KnownCellUse>(node->child1());
1070             break;
1071         }
1072
1073         case ArraySlice: {
1074             fixEdge<KnownCellUse>(m_graph.varArgChild(node, 0));
1075             fixEdge<Int32Use>(m_graph.varArgChild(node, 1));
1076             if (node->numChildren() == 4)
1077                 fixEdge<Int32Use>(m_graph.varArgChild(node, 2));
1078             break;
1079         }
1080
1081         case ArrayIndexOf:
1082             fixupArrayIndexOf(node);
1083             break;
1084             
1085         case RegExpExec:
1086         case RegExpTest: {
1087             fixEdge<KnownCellUse>(node->child1());
1088             
1089             if (node->child2()->shouldSpeculateRegExpObject()) {
1090                 fixEdge<RegExpObjectUse>(node->child2());
1091
1092                 if (node->child3()->shouldSpeculateString())
1093                     fixEdge<StringUse>(node->child3());
1094             }
1095             break;
1096         }
1097
1098         case StringReplace:
1099         case StringReplaceRegExp: {
1100             if (node->child2()->shouldSpeculateString()) {
1101                 m_insertionSet.insertNode(
1102                     m_indexInBlock, SpecNone, Check, node->origin,
1103                     Edge(node->child2().node(), StringUse));
1104                 fixEdge<StringUse>(node->child2());
1105             } else if (op == StringReplace) {
1106                 if (node->child2()->shouldSpeculateRegExpObject())
1107                     addStringReplacePrimordialChecks(node->child2().node());
1108                 else 
1109                     m_insertionSet.insertNode(
1110                         m_indexInBlock, SpecNone, ForceOSRExit, node->origin);
1111             }
1112
1113             if (node->child1()->shouldSpeculateString()
1114                 && node->child2()->shouldSpeculateRegExpObject()
1115                 && node->child3()->shouldSpeculateString()) {
1116
1117                 fixEdge<StringUse>(node->child1());
1118                 fixEdge<RegExpObjectUse>(node->child2());
1119                 fixEdge<StringUse>(node->child3());
1120                 break;
1121             }
1122             break;
1123         }
1124             
1125         case Branch: {
1126             if (node->child1()->shouldSpeculateBoolean()) {
1127                 if (node->child1()->result() == NodeResultBoolean) {
1128                     // This is necessary in case we have a bytecode instruction implemented by:
1129                     //
1130                     // a: CompareEq(...)
1131                     // b: Branch(@a)
1132                     //
1133                     // In that case, CompareEq might have a side-effect. Then, we need to make
1134                     // sure that we know that Branch does not exit.
1135                     fixEdge<KnownBooleanUse>(node->child1());
1136                 } else
1137                     fixEdge<BooleanUse>(node->child1());
1138             } else if (node->child1()->shouldSpeculateObjectOrOther())
1139                 fixEdge<ObjectOrOtherUse>(node->child1());
1140             else if (node->child1()->shouldSpeculateInt32OrBoolean())
1141                 fixIntOrBooleanEdge(node->child1());
1142             else if (node->child1()->shouldSpeculateNumber())
1143                 fixEdge<DoubleRepUse>(node->child1());
1144             else if (node->child1()->shouldSpeculateString())
1145                 fixEdge<StringUse>(node->child1());
1146             else if (node->child1()->shouldSpeculateStringOrOther())
1147                 fixEdge<StringOrOtherUse>(node->child1());
1148             else {
1149                 WatchpointSet* masqueradesAsUndefinedWatchpoint = m_graph.globalObjectFor(node->origin.semantic)->masqueradesAsUndefinedWatchpoint();
1150                 if (masqueradesAsUndefinedWatchpoint->isStillValid())
1151                     m_graph.watchpoints().addLazily(masqueradesAsUndefinedWatchpoint);
1152             }
1153             break;
1154         }
1155             
1156         case Switch: {
1157             SwitchData* data = node->switchData();
1158             switch (data->kind) {
1159             case SwitchImm:
1160                 if (node->child1()->shouldSpeculateInt32())
1161                     fixEdge<Int32Use>(node->child1());
1162                 break;
1163             case SwitchChar:
1164                 if (node->child1()->shouldSpeculateString())
1165                     fixEdge<StringUse>(node->child1());
1166                 break;
1167             case SwitchString:
1168                 if (node->child1()->shouldSpeculateStringIdent())
1169                     fixEdge<StringIdentUse>(node->child1());
1170                 else if (node->child1()->shouldSpeculateString())
1171                     fixEdge<StringUse>(node->child1());
1172                 break;
1173             case SwitchCell:
1174                 if (node->child1()->shouldSpeculateCell())
1175                     fixEdge<CellUse>(node->child1());
1176                 // else it's fine for this to have UntypedUse; we will handle this by just making
1177                 // non-cells take the default case.
1178                 break;
1179             }
1180             break;
1181         }
1182             
1183         case ToPrimitive: {
1184             fixupToPrimitive(node);
1185             break;
1186         }
1187
1188         case ToNumber: {
1189             fixupToNumber(node);
1190             break;
1191         }
1192             
1193         case ToString:
1194         case CallStringConstructor: {
1195             fixupToStringOrCallStringConstructor(node);
1196             break;
1197         }
1198             
1199         case NewStringObject: {
1200             fixEdge<KnownStringUse>(node->child1());
1201             break;
1202         }
1203
1204         case NewArrayWithSpread: {
1205             watchHavingABadTime(node);
1206             
1207             BitVector* bitVector = node->bitVector();
1208             for (unsigned i = node->numChildren(); i--;) {
1209                 if (bitVector->get(i))
1210                     fixEdge<KnownCellUse>(m_graph.m_varArgChildren[node->firstChild() + i]);
1211                 else
1212                     fixEdge<UntypedUse>(m_graph.m_varArgChildren[node->firstChild() + i]);
1213             }
1214
1215             break;
1216         }
1217
1218         case Spread: {
1219             // Note: We care about performing the protocol on our child's global object, not necessarily ours.
1220             
1221             watchHavingABadTime(node->child1().node());
1222
1223             JSGlobalObject* globalObject = m_graph.globalObjectFor(node->child1()->origin.semantic);
1224             // When we go down the fast path, we don't consult the prototype chain, so we must prove
1225             // that it doesn't contain any indexed properties, and that any holes will result in
1226             // jsUndefined().
1227             Structure* arrayPrototypeStructure = globalObject->arrayPrototype()->structure();
1228             Structure* objectPrototypeStructure = globalObject->objectPrototype()->structure();
1229             if (node->child1()->shouldSpeculateArray()
1230                 && arrayPrototypeStructure->transitionWatchpointSetIsStillValid()
1231                 && objectPrototypeStructure->transitionWatchpointSetIsStillValid()
1232                 && globalObject->arrayPrototypeChainIsSane()
1233                 && m_graph.isWatchingArrayIteratorProtocolWatchpoint(node->child1().node())
1234                 && m_graph.isWatchingHavingABadTimeWatchpoint(node->child1().node())) {
1235                 m_graph.registerAndWatchStructureTransition(objectPrototypeStructure);
1236                 m_graph.registerAndWatchStructureTransition(arrayPrototypeStructure);
1237                 fixEdge<ArrayUse>(node->child1());
1238             } else
1239                 fixEdge<CellUse>(node->child1());
1240             break;
1241         }
1242             
1243         case NewArray: {
1244             watchHavingABadTime(node);
1245             
1246             for (unsigned i = m_graph.varArgNumChildren(node); i--;) {
1247                 node->setIndexingType(
1248                     leastUpperBoundOfIndexingTypeAndType(
1249                         node->indexingType(), m_graph.varArgChild(node, i)->prediction()));
1250             }
1251             switch (node->indexingType()) {
1252             case ALL_BLANK_INDEXING_TYPES:
1253                 CRASH();
1254                 break;
1255             case ALL_UNDECIDED_INDEXING_TYPES:
1256                 if (node->numChildren()) {
1257                     // This will only happen if the children have no type predictions. We
1258                     // would have already exited by now, but insert a forced exit just to
1259                     // be safe.
1260                     m_insertionSet.insertNode(
1261                         m_indexInBlock, SpecNone, ForceOSRExit, node->origin);
1262                 }
1263                 break;
1264             case ALL_INT32_INDEXING_TYPES:
1265                 for (unsigned operandIndex = 0; operandIndex < node->numChildren(); ++operandIndex)
1266                     fixEdge<Int32Use>(m_graph.m_varArgChildren[node->firstChild() + operandIndex]);
1267                 break;
1268             case ALL_DOUBLE_INDEXING_TYPES:
1269                 for (unsigned operandIndex = 0; operandIndex < node->numChildren(); ++operandIndex)
1270                     fixEdge<DoubleRepRealUse>(m_graph.m_varArgChildren[node->firstChild() + operandIndex]);
1271                 break;
1272             case ALL_CONTIGUOUS_INDEXING_TYPES:
1273             case ALL_ARRAY_STORAGE_INDEXING_TYPES:
1274                 break;
1275             default:
1276                 CRASH();
1277                 break;
1278             }
1279             break;
1280         }
1281             
1282         case NewTypedArray: {
1283             watchHavingABadTime(node);
1284             
1285             if (node->child1()->shouldSpeculateInt32()) {
1286                 fixEdge<Int32Use>(node->child1());
1287                 node->clearFlags(NodeMustGenerate);
1288                 break;
1289             }
1290             break;
1291         }
1292             
1293         case NewArrayWithSize: {
1294             watchHavingABadTime(node);
1295             fixEdge<Int32Use>(node->child1());
1296             break;
1297         }
1298
1299         case NewArrayBuffer: {
1300             watchHavingABadTime(node);
1301             break;
1302         }
1303
1304         case ToObject: {
1305             fixupToObject(node);
1306             break;
1307         }
1308
1309         case CallObjectConstructor: {
1310             fixupCallObjectConstructor(node);
1311             break;
1312         }
1313
1314         case ToThis: {
1315             fixupToThis(node);
1316             break;
1317         }
1318             
1319         case PutStructure: {
1320             fixEdge<KnownCellUse>(node->child1());
1321             break;
1322         }
1323             
1324         case GetClosureVar:
1325         case GetFromArguments: {
1326             fixEdge<KnownCellUse>(node->child1());
1327             break;
1328         }
1329
1330         case PutClosureVar:
1331         case PutToArguments: {
1332             fixEdge<KnownCellUse>(node->child1());
1333             speculateForBarrier(node->child2());
1334             break;
1335         }
1336
1337         case SkipScope:
1338         case GetScope:
1339         case GetGetter:
1340         case GetSetter:
1341         case GetGlobalObject: {
1342             fixEdge<KnownCellUse>(node->child1());
1343             break;
1344         }
1345             
1346         case AllocatePropertyStorage:
1347         case ReallocatePropertyStorage: {
1348             fixEdge<KnownCellUse>(node->child1());
1349             break;
1350         }
1351             
1352         case NukeStructureAndSetButterfly: {
1353             fixEdge<KnownCellUse>(node->child1());
1354             break;
1355         }
1356
1357         case TryGetById: {
1358             if (node->child1()->shouldSpeculateCell())
1359                 fixEdge<CellUse>(node->child1());
1360             break;
1361         }
1362
1363         case GetById:
1364         case GetByIdFlush: {
1365             // FIXME: This should be done in the ByteCodeParser based on reading the
1366             // PolymorphicAccess, which will surely tell us that this is a AccessCase::ArrayLength.
1367             // https://bugs.webkit.org/show_bug.cgi?id=154990
1368             auto uid = m_graph.identifiers()[node->identifierNumber()];
1369             if (node->child1()->shouldSpeculateCellOrOther()
1370                 && !m_graph.hasExitSite(node->origin.semantic, BadType)
1371                 && !m_graph.hasExitSite(node->origin.semantic, BadCache)
1372                 && !m_graph.hasExitSite(node->origin.semantic, BadIndexingType)
1373                 && !m_graph.hasExitSite(node->origin.semantic, ExoticObjectMode)) {
1374                 
1375                 if (uid == vm().propertyNames->length.impl()) {
1376                     attemptToMakeGetArrayLength(node);
1377                     break;
1378                 }
1379
1380                 if (uid == vm().propertyNames->lastIndex.impl()
1381                     && node->child1()->shouldSpeculateRegExpObject()) {
1382                     node->setOp(GetRegExpObjectLastIndex);
1383                     node->clearFlags(NodeMustGenerate);
1384                     fixEdge<RegExpObjectUse>(node->child1());
1385                     break;
1386                 }
1387             }
1388
1389             if (node->child1()->shouldSpeculateNumber()) {
1390                 if (uid == vm().propertyNames->toString.impl()) {
1391                     if (m_graph.isWatchingNumberToStringWatchpoint(node)) {
1392                         JSGlobalObject* globalObject = m_graph.globalObjectFor(node->origin.semantic);
1393                         if (node->child1()->shouldSpeculateInt32()) {
1394                             insertCheck<Int32Use>(node->child1().node());
1395                             m_graph.convertToConstant(node, m_graph.freeze(globalObject->numberProtoToStringFunction()));
1396                             break;
1397                         }
1398
1399                         if (enableInt52() && node->child1()->shouldSpeculateAnyInt()) {
1400                             insertCheck<Int52RepUse>(node->child1().node());
1401                             m_graph.convertToConstant(node, m_graph.freeze(globalObject->numberProtoToStringFunction()));
1402                             break;
1403                         }
1404
1405                         ASSERT(node->child1()->shouldSpeculateNumber());
1406                         insertCheck<DoubleRepUse>(node->child1().node());
1407                         m_graph.convertToConstant(node, m_graph.freeze(globalObject->numberProtoToStringFunction()));
1408                         break;
1409                     }
1410                 }
1411             }
1412
1413             if (node->child1()->shouldSpeculateCell())
1414                 fixEdge<CellUse>(node->child1());
1415             break;
1416         }
1417         
1418         case GetByIdWithThis: {
1419             if (node->child1()->shouldSpeculateCell() && node->child2()->shouldSpeculateCell()) {
1420                 fixEdge<CellUse>(node->child1());
1421                 fixEdge<CellUse>(node->child2());
1422             }
1423             break;
1424         }
1425
1426         case PutById:
1427         case PutByIdFlush:
1428         case PutByIdDirect: {
1429             if (node->child1()->shouldSpeculateCellOrOther()
1430                 && !m_graph.hasExitSite(node->origin.semantic, BadType)
1431                 && !m_graph.hasExitSite(node->origin.semantic, BadCache)
1432                 && !m_graph.hasExitSite(node->origin.semantic, BadIndexingType)
1433                 && !m_graph.hasExitSite(node->origin.semantic, ExoticObjectMode)) {
1434                 
1435                 auto uid = m_graph.identifiers()[node->identifierNumber()];
1436                 
1437                 if (uid == vm().propertyNames->lastIndex.impl()
1438                     && node->child1()->shouldSpeculateRegExpObject()) {
1439                     node->setOp(SetRegExpObjectLastIndex);
1440                     fixEdge<RegExpObjectUse>(node->child1());
1441                     speculateForBarrier(node->child2());
1442                     break;
1443                 }
1444             }
1445             
1446             fixEdge<CellUse>(node->child1());
1447             break;
1448         }
1449
1450         case PutGetterById:
1451         case PutSetterById: {
1452             fixEdge<KnownCellUse>(node->child1());
1453             fixEdge<KnownCellUse>(node->child2());
1454             break;
1455         }
1456
1457         case PutGetterSetterById: {
1458             fixEdge<KnownCellUse>(node->child1());
1459             break;
1460         }
1461
1462         case PutGetterByVal:
1463         case PutSetterByVal: {
1464             fixEdge<KnownCellUse>(node->child1());
1465             fixEdge<KnownCellUse>(node->child3());
1466             break;
1467         }
1468
1469         case GetExecutable: {
1470             fixEdge<FunctionUse>(node->child1());
1471             break;
1472         }
1473
1474         case OverridesHasInstance:
1475         case CheckStructure:
1476         case CheckCell:
1477         case CreateThis:
1478         case GetButterfly: {
1479             fixEdge<CellUse>(node->child1());
1480             break;
1481         }
1482
1483         case CheckStringIdent: {
1484             fixEdge<StringIdentUse>(node->child1());
1485             break;
1486         }
1487             
1488         case Arrayify:
1489         case ArrayifyToStructure: {
1490             fixEdge<CellUse>(node->child1());
1491             if (node->child2())
1492                 fixEdge<Int32Use>(node->child2());
1493             break;
1494         }
1495             
1496         case GetByOffset:
1497         case GetGetterSetterByOffset: {
1498             if (!node->child1()->hasStorageResult())
1499                 fixEdge<KnownCellUse>(node->child1());
1500             fixEdge<KnownCellUse>(node->child2());
1501             break;
1502         }
1503             
1504         case MultiGetByOffset: {
1505             fixEdge<CellUse>(node->child1());
1506             break;
1507         }
1508             
1509         case PutByOffset: {
1510             if (!node->child1()->hasStorageResult())
1511                 fixEdge<KnownCellUse>(node->child1());
1512             fixEdge<KnownCellUse>(node->child2());
1513             unsigned index = indexForChecks();
1514             insertInferredTypeCheck(
1515                 m_insertionSet, index, originForCheck(index), node->child3().node(),
1516                 node->storageAccessData().inferredType);
1517             speculateForBarrier(node->child3());
1518             break;
1519         }
1520             
1521         case MultiPutByOffset: {
1522             fixEdge<CellUse>(node->child1());
1523             break;
1524         }
1525             
1526         case InstanceOf: {
1527             if (!(node->child1()->prediction() & ~SpecCell))
1528                 fixEdge<CellUse>(node->child1());
1529             fixEdge<CellUse>(node->child2());
1530             break;
1531         }
1532
1533         case InstanceOfCustom:
1534             fixEdge<CellUse>(node->child2());
1535             break;
1536
1537         case In: {
1538             if (node->child2()->shouldSpeculateInt32()) {
1539                 convertToHasIndexedProperty(node);
1540                 break;
1541             }
1542
1543             fixEdge<CellUse>(node->child1());
1544             break;
1545         }
1546
1547         case HasOwnProperty: {
1548             fixEdge<ObjectUse>(node->child1());
1549 #if (CPU(X86) || CPU(MIPS)) && USE(JSVALUE32_64)
1550             // We don't have enough registers to do anything interesting on x86 and mips.
1551             fixEdge<UntypedUse>(node->child2());
1552 #else
1553             if (node->child2()->shouldSpeculateString())
1554                 fixEdge<StringUse>(node->child2());
1555             else if (node->child2()->shouldSpeculateSymbol())
1556                 fixEdge<SymbolUse>(node->child2());
1557             else
1558                 fixEdge<UntypedUse>(node->child2());
1559 #endif
1560             break;
1561         }
1562
1563         case Check: {
1564             m_graph.doToChildren(
1565                 node,
1566                 [&] (Edge& edge) {
1567                     switch (edge.useKind()) {
1568                     case NumberUse:
1569                         if (edge->shouldSpeculateInt32ForArithmetic())
1570                             edge.setUseKind(Int32Use);
1571                         break;
1572                     default:
1573                         break;
1574                     }
1575                     observeUseKindOnEdge(edge);
1576                 });
1577             break;
1578         }
1579
1580         case Phantom:
1581             // Phantoms are meaningless past Fixup. We recreate them on-demand in the backend.
1582             node->remove();
1583             break;
1584
1585         case FiatInt52: {
1586             RELEASE_ASSERT(enableInt52());
1587             node->convertToIdentity();
1588             fixEdge<Int52RepUse>(node->child1());
1589             node->setResult(NodeResultInt52);
1590             break;
1591         }
1592
1593         case GetArrayLength: {
1594             fixEdge<KnownCellUse>(node->child1());
1595             break;
1596         }
1597
1598         case GetTypedArrayByteOffset: {
1599             fixEdge<KnownCellUse>(node->child1());
1600             break;
1601         }
1602
1603         case CompareBelow:
1604         case CompareBelowEq: {
1605             fixEdge<Int32Use>(node->child1());
1606             fixEdge<Int32Use>(node->child2());
1607             break;
1608         }
1609
1610         case GetPrototypeOf: {
1611             fixupGetPrototypeOf(node);
1612             break;
1613         }
1614
1615         case Phi:
1616         case Upsilon:
1617         case EntrySwitch:
1618         case GetIndexedPropertyStorage:
1619         case LastNodeType:
1620         case CheckTierUpInLoop:
1621         case CheckTierUpAtReturn:
1622         case CheckTierUpAndOSREnter:
1623         case InvalidationPoint:
1624         case CheckArray:
1625         case CheckInBounds:
1626         case ConstantStoragePointer:
1627         case DoubleAsInt32:
1628         case ValueToInt32:
1629         case DoubleRep:
1630         case ValueRep:
1631         case Int52Rep:
1632         case Int52Constant:
1633         case Identity: // This should have been cleaned up.
1634         case BooleanToNumber:
1635         case PhantomNewObject:
1636         case PhantomNewFunction:
1637         case PhantomNewGeneratorFunction:
1638         case PhantomNewAsyncGeneratorFunction:
1639         case PhantomNewAsyncFunction:
1640         case PhantomCreateActivation:
1641         case PhantomDirectArguments:
1642         case PhantomCreateRest:
1643         case PhantomSpread:
1644         case PhantomNewArrayWithSpread:
1645         case PhantomClonedArguments:
1646         case GetMyArgumentByVal:
1647         case GetMyArgumentByValOutOfBounds:
1648         case GetVectorLength:
1649         case PutHint:
1650         case CheckStructureImmediate:
1651         case CheckStructureOrEmpty:
1652         case MaterializeNewObject:
1653         case MaterializeCreateActivation:
1654         case PutStack:
1655         case KillStack:
1656         case GetStack:
1657         case StoreBarrier:
1658         case FencedStoreBarrier:
1659         case GetRegExpObjectLastIndex:
1660         case SetRegExpObjectLastIndex:
1661         case RecordRegExpCachedResult:
1662             // These are just nodes that we don't currently expect to see during fixup.
1663             // If we ever wanted to insert them prior to fixup, then we just have to create
1664             // fixup rules for them.
1665             DFG_CRASH(m_graph, node, "Unexpected node during fixup");
1666             break;
1667
1668         case PutGlobalVariable: {
1669             fixEdge<CellUse>(node->child1());
1670             speculateForBarrier(node->child2());
1671             break;
1672         }
1673
1674         case IsObject:
1675             if (node->child1()->shouldSpeculateObject()) {
1676                 m_insertionSet.insertNode(
1677                     m_indexInBlock, SpecNone, Check, node->origin,
1678                     Edge(node->child1().node(), ObjectUse));
1679                 m_graph.convertToConstant(node, jsBoolean(true));
1680                 observeUseKindOnNode<ObjectUse>(node);
1681             }
1682             break;
1683
1684         case IsCellWithType: {
1685             fixupIsCellWithType(node);
1686             break;
1687         }
1688
1689         case GetEnumerableLength: {
1690             fixEdge<CellUse>(node->child1());
1691             break;
1692         }
1693         case HasGenericProperty: {
1694             fixEdge<CellUse>(node->child2());
1695             break;
1696         }
1697         case HasStructureProperty: {
1698             fixEdge<StringUse>(node->child2());
1699             fixEdge<KnownCellUse>(node->child3());
1700             break;
1701         }
1702         case HasIndexedProperty: {
1703             node->setArrayMode(
1704                 node->arrayMode().refine(
1705                     m_graph, node,
1706                     node->child1()->prediction(),
1707                     node->child2()->prediction(),
1708                     SpecNone));
1709             
1710             blessArrayOperation(node->child1(), node->child2(), node->child3());
1711             fixEdge<CellUse>(node->child1());
1712             fixEdge<KnownInt32Use>(node->child2());
1713             break;
1714         }
1715         case GetDirectPname: {
1716             Edge& base = m_graph.varArgChild(node, 0);
1717             Edge& property = m_graph.varArgChild(node, 1);
1718             Edge& index = m_graph.varArgChild(node, 2);
1719             Edge& enumerator = m_graph.varArgChild(node, 3);
1720             fixEdge<CellUse>(base);
1721             fixEdge<KnownCellUse>(property);
1722             fixEdge<KnownInt32Use>(index);
1723             fixEdge<KnownCellUse>(enumerator);
1724             break;
1725         }
1726         case GetPropertyEnumerator: {
1727             fixEdge<CellUse>(node->child1());
1728             break;
1729         }
1730         case GetEnumeratorStructurePname: {
1731             fixEdge<KnownCellUse>(node->child1());
1732             fixEdge<KnownInt32Use>(node->child2());
1733             break;
1734         }
1735         case GetEnumeratorGenericPname: {
1736             fixEdge<KnownCellUse>(node->child1());
1737             fixEdge<KnownInt32Use>(node->child2());
1738             break;
1739         }
1740         case ToIndexString: {
1741             fixEdge<KnownInt32Use>(node->child1());
1742             break;
1743         }
1744         case ProfileType: {
1745             // We want to insert type checks based on the instructionTypeSet of the TypeLocation, not the globalTypeSet.
1746             // Because the instructionTypeSet is contained in globalTypeSet, if we produce a type check for
1747             // type T for the instructionTypeSet, the global type set must also have information for type T.
1748             // So if it the type check succeeds for type T in the instructionTypeSet, a type check for type T 
1749             // in the globalTypeSet would've also succeeded.
1750             // (The other direction does not hold in general).
1751
1752             RefPtr<TypeSet> typeSet = node->typeLocation()->m_instructionTypeSet;
1753             RuntimeTypeMask seenTypes = typeSet->seenTypes();
1754             if (typeSet->doesTypeConformTo(TypeAnyInt)) {
1755                 if (node->child1()->shouldSpeculateInt32()) {
1756                     fixEdge<Int32Use>(node->child1());
1757                     node->remove();
1758                     break;
1759                 }
1760
1761                 if (enableInt52()) {
1762                     fixEdge<AnyIntUse>(node->child1());
1763                     node->remove();
1764                     break;
1765                 }
1766
1767                 // Must not perform fixEdge<NumberUse> here since the type set only includes TypeAnyInt. Double values should be logged.
1768             }
1769
1770             if (typeSet->doesTypeConformTo(TypeNumber | TypeAnyInt)) {
1771                 fixEdge<NumberUse>(node->child1());
1772                 node->remove();
1773             } else if (typeSet->doesTypeConformTo(TypeString)) {
1774                 fixEdge<StringUse>(node->child1());
1775                 node->remove();
1776             } else if (typeSet->doesTypeConformTo(TypeBoolean)) {
1777                 fixEdge<BooleanUse>(node->child1());
1778                 node->remove();
1779             } else if (typeSet->doesTypeConformTo(TypeUndefined | TypeNull) && (seenTypes & TypeUndefined) && (seenTypes & TypeNull)) {
1780                 fixEdge<OtherUse>(node->child1());
1781                 node->remove();
1782             } else if (typeSet->doesTypeConformTo(TypeObject)) {
1783                 StructureSet set;
1784                 {
1785                     ConcurrentJSLocker locker(typeSet->m_lock);
1786                     set = typeSet->structureSet(locker);
1787                 }
1788                 if (!set.isEmpty()) {
1789                     fixEdge<CellUse>(node->child1());
1790                     node->convertToCheckStructure(m_graph.addStructureSet(set));
1791                 }
1792             }
1793
1794             break;
1795         }
1796
1797         case CreateClonedArguments: {
1798             watchHavingABadTime(node);
1799             break;
1800         }
1801
1802         case CreateScopedArguments:
1803         case CreateActivation:
1804         case NewFunction:
1805         case NewGeneratorFunction:
1806         case NewAsyncGeneratorFunction:
1807         case NewAsyncFunction: {
1808             // Child 1 is always the current scope, which is guaranteed to be an object
1809             // FIXME: should be KnownObjectUse once that exists (https://bugs.webkit.org/show_bug.cgi?id=175689)
1810             fixEdge<KnownCellUse>(node->child1());
1811             break;
1812         }
1813
1814         case PushWithScope: {
1815             // Child 1 is always the current scope, which is guaranteed to be an object
1816             // FIXME: should be KnownObjectUse once that exists (https://bugs.webkit.org/show_bug.cgi?id=175689)
1817             fixEdge<KnownCellUse>(node->child1());
1818             if (node->child2()->shouldSpeculateObject())
1819                 fixEdge<ObjectUse>(node->child2());
1820             break;
1821         }
1822
1823         case SetFunctionName: {
1824             // The first child is guaranteed to be a cell because op_set_function_name is only used
1825             // on a newly instantiated function object (the first child).
1826             fixEdge<KnownCellUse>(node->child1());
1827             fixEdge<UntypedUse>(node->child2());
1828             break;
1829         }
1830
1831         case CreateRest: {
1832             watchHavingABadTime(node);
1833             fixEdge<KnownInt32Use>(node->child1());
1834             break;
1835         }
1836
1837         case ResolveScopeForHoistingFuncDeclInEval: {
1838             fixEdge<KnownCellUse>(node->child1());
1839             break;
1840         }
1841         case ResolveScope:
1842         case GetDynamicVar:
1843         case PutDynamicVar: {
1844             fixEdge<KnownCellUse>(node->child1());
1845             break;
1846         }
1847
1848         case LogShadowChickenPrologue: {
1849             fixEdge<KnownCellUse>(node->child1());
1850             break;
1851         }
1852         case LogShadowChickenTail: {
1853             fixEdge<UntypedUse>(node->child1());
1854             fixEdge<KnownCellUse>(node->child2());
1855             break;
1856         }
1857
1858         case GetMapBucket:
1859             if (node->child1().useKind() == MapObjectUse)
1860                 fixEdge<MapObjectUse>(node->child1());
1861             else if (node->child1().useKind() == SetObjectUse)
1862                 fixEdge<SetObjectUse>(node->child1());
1863             else
1864                 RELEASE_ASSERT_NOT_REACHED();
1865
1866 #if USE(JSVALUE64)
1867             if (node->child2()->shouldSpeculateBoolean())
1868                 fixEdge<BooleanUse>(node->child2());
1869             else if (node->child2()->shouldSpeculateInt32())
1870                 fixEdge<Int32Use>(node->child2());
1871             else if (node->child2()->shouldSpeculateSymbol())
1872                 fixEdge<SymbolUse>(node->child2());
1873             else if (node->child2()->shouldSpeculateObject())
1874                 fixEdge<ObjectUse>(node->child2());
1875             else if (node->child2()->shouldSpeculateString())
1876                 fixEdge<StringUse>(node->child2());
1877             else if (node->child2()->shouldSpeculateCell())
1878                 fixEdge<CellUse>(node->child2());
1879             else
1880                 fixEdge<UntypedUse>(node->child2());
1881 #else
1882             fixEdge<UntypedUse>(node->child2());
1883 #endif // USE(JSVALUE64)
1884
1885             fixEdge<Int32Use>(node->child3());
1886             break;
1887
1888         case GetMapBucketHead:
1889             if (node->child1().useKind() == MapObjectUse)
1890                 fixEdge<MapObjectUse>(node->child1());
1891             else if (node->child1().useKind() == SetObjectUse)
1892                 fixEdge<SetObjectUse>(node->child1());
1893             else
1894                 RELEASE_ASSERT_NOT_REACHED();
1895             break;
1896
1897         case GetMapBucketNext:
1898         case LoadKeyFromMapBucket:
1899         case LoadValueFromMapBucket:
1900             fixEdge<CellUse>(node->child1());
1901             break;
1902
1903         case MapHash: {
1904 #if USE(JSVALUE64)
1905             if (node->child1()->shouldSpeculateBoolean()) {
1906                 fixEdge<BooleanUse>(node->child1());
1907                 break;
1908             }
1909
1910             if (node->child1()->shouldSpeculateInt32()) {
1911                 fixEdge<Int32Use>(node->child1());
1912                 break;
1913             }
1914
1915             if (node->child1()->shouldSpeculateSymbol()) {
1916                 fixEdge<SymbolUse>(node->child1());
1917                 break;
1918             }
1919
1920             if (node->child1()->shouldSpeculateObject()) {
1921                 fixEdge<ObjectUse>(node->child1());
1922                 break;
1923             }
1924
1925             if (node->child1()->shouldSpeculateString()) {
1926                 fixEdge<StringUse>(node->child1());
1927                 break;
1928             }
1929
1930             if (node->child1()->shouldSpeculateCell()) {
1931                 fixEdge<CellUse>(node->child1());
1932                 break;
1933             }
1934
1935             fixEdge<UntypedUse>(node->child1());
1936 #else
1937             fixEdge<UntypedUse>(node->child1());
1938 #endif // USE(JSVALUE64)
1939             break;
1940         }
1941
1942         case NormalizeMapKey: {
1943             fixupNormalizeMapKey(node);
1944             break;
1945         }
1946
1947         case WeakMapGet: {
1948             if (node->child1().useKind() == WeakMapObjectUse)
1949                 fixEdge<WeakMapObjectUse>(node->child1());
1950             else if (node->child1().useKind() == WeakSetObjectUse)
1951                 fixEdge<WeakSetObjectUse>(node->child1());
1952             else
1953                 RELEASE_ASSERT_NOT_REACHED();
1954             fixEdge<ObjectUse>(node->child2());
1955             fixEdge<Int32Use>(node->child3());
1956             break;
1957         }
1958
1959         case SetAdd: {
1960             fixEdge<SetObjectUse>(node->child1());
1961             fixEdge<Int32Use>(node->child3());
1962             break;
1963         }
1964
1965         case MapSet: {
1966             fixEdge<MapObjectUse>(m_graph.varArgChild(node, 0));
1967             fixEdge<Int32Use>(m_graph.varArgChild(node, 3));
1968             break;
1969         }
1970
1971         case DefineDataProperty: {
1972             fixEdge<CellUse>(m_graph.varArgChild(node, 0));
1973             Edge& propertyEdge = m_graph.varArgChild(node, 1);
1974             if (propertyEdge->shouldSpeculateSymbol())
1975                 fixEdge<SymbolUse>(propertyEdge);
1976             else if (propertyEdge->shouldSpeculateStringIdent())
1977                 fixEdge<StringIdentUse>(propertyEdge);
1978             else if (propertyEdge->shouldSpeculateString())
1979                 fixEdge<StringUse>(propertyEdge);
1980             else
1981                 fixEdge<UntypedUse>(propertyEdge);
1982             fixEdge<UntypedUse>(m_graph.varArgChild(node, 2));
1983             fixEdge<KnownInt32Use>(m_graph.varArgChild(node, 3));
1984             break;
1985         }
1986
1987         case StringSlice: {
1988             fixEdge<StringUse>(node->child1());
1989             fixEdge<Int32Use>(node->child2());
1990             if (node->child3())
1991                 fixEdge<Int32Use>(node->child3());
1992             break;
1993         }
1994
1995         case ToLowerCase: {
1996             // We currently only support StringUse since that will ensure that
1997             // ToLowerCase is a pure operation. If we decide to update this with
1998             // more types in the future, we need to ensure that the clobberize rules
1999             // are correct.
2000             fixEdge<StringUse>(node->child1());
2001             break;
2002         }
2003
2004         case NumberToStringWithRadix: {
2005             if (node->child1()->shouldSpeculateInt32())
2006                 fixEdge<Int32Use>(node->child1());
2007             else if (enableInt52() && node->child1()->shouldSpeculateAnyInt())
2008                 fixEdge<Int52RepUse>(node->child1());
2009             else
2010                 fixEdge<DoubleRepUse>(node->child1());
2011             fixEdge<Int32Use>(node->child2());
2012             break;
2013         }
2014
2015         case DefineAccessorProperty: {
2016             fixEdge<CellUse>(m_graph.varArgChild(node, 0));
2017             Edge& propertyEdge = m_graph.varArgChild(node, 1);
2018             if (propertyEdge->shouldSpeculateSymbol())
2019                 fixEdge<SymbolUse>(propertyEdge);
2020             else if (propertyEdge->shouldSpeculateStringIdent())
2021                 fixEdge<StringIdentUse>(propertyEdge);
2022             else if (propertyEdge->shouldSpeculateString())
2023                 fixEdge<StringUse>(propertyEdge);
2024             else
2025                 fixEdge<UntypedUse>(propertyEdge);
2026             fixEdge<CellUse>(m_graph.varArgChild(node, 2));
2027             fixEdge<CellUse>(m_graph.varArgChild(node, 3));
2028             fixEdge<KnownInt32Use>(m_graph.varArgChild(node, 4));
2029             break;
2030         }
2031
2032         case CheckSubClass: {
2033             fixupCheckSubClass(node);
2034             break;
2035         }
2036
2037         case CallDOMGetter: {
2038             DOMJIT::CallDOMGetterSnippet* snippet = node->callDOMGetterData()->snippet;
2039             fixEdge<CellUse>(node->child1()); // DOM.
2040             if (snippet && snippet->requireGlobalObject)
2041                 fixEdge<KnownCellUse>(node->child2()); // GlobalObject.
2042             break;
2043         }
2044
2045         case CallDOM: {
2046             fixupCallDOM(node);
2047             break;
2048         }
2049
2050         case Call: {
2051             attemptToMakeCallDOM(node);
2052             break;
2053         }
2054
2055         case ParseInt: {
2056             if (node->child1()->shouldSpeculateInt32() && !node->child2()) {
2057                 fixEdge<Int32Use>(node->child1());
2058                 node->convertToIdentity();
2059                 break;
2060             }
2061
2062             if (node->child1()->shouldSpeculateString()) {
2063                 fixEdge<StringUse>(node->child1());
2064                 node->clearFlags(NodeMustGenerate);
2065             }
2066
2067             if (node->child2())
2068                 fixEdge<Int32Use>(node->child2());
2069
2070             break;
2071         }
2072
2073         case IdentityWithProfile: {
2074             node->clearFlags(NodeMustGenerate);
2075             break;
2076         }
2077
2078         case ThrowStaticError:
2079             fixEdge<StringUse>(node->child1());
2080             break;
2081
2082 #if !ASSERT_DISABLED
2083         // Have these no-op cases here to ensure that nobody forgets to add handlers for new opcodes.
2084         case SetArgument:
2085         case JSConstant:
2086         case LazyJSConstant:
2087         case DoubleConstant:
2088         case GetLocal:
2089         case GetCallee:
2090         case GetArgumentCountIncludingThis:
2091         case GetRestLength:
2092         case GetArgument:
2093         case Flush:
2094         case PhantomLocal:
2095         case GetGlobalVar:
2096         case GetGlobalLexicalVariable:
2097         case NotifyWrite:
2098         case DirectCall:
2099         case CheckTypeInfoFlags:
2100         case TailCallInlinedCaller:
2101         case DirectTailCallInlinedCaller:
2102         case Construct:
2103         case DirectConstruct:
2104         case CallVarargs:
2105         case CallEval:
2106         case TailCallVarargsInlinedCaller:
2107         case ConstructVarargs:
2108         case CallForwardVarargs:
2109         case ConstructForwardVarargs:
2110         case TailCallForwardVarargs:
2111         case TailCallForwardVarargsInlinedCaller:
2112         case LoadVarargs:
2113         case ForwardVarargs:
2114         case ProfileControlFlow:
2115         case NewObject:
2116         case NewRegexp:
2117         case DeleteById:
2118         case DeleteByVal:
2119         case IsTypedArrayView:
2120         case IsEmpty:
2121         case IsUndefined:
2122         case IsBoolean:
2123         case IsNumber:
2124         case IsObjectOrNull:
2125         case IsFunction:
2126         case CreateDirectArguments:
2127         case Jump:
2128         case Return:
2129         case TailCall:
2130         case DirectTailCall:
2131         case TailCallVarargs:
2132         case Throw:
2133         case CountExecution:
2134         case SuperSamplerBegin:
2135         case SuperSamplerEnd:
2136         case ForceOSRExit:
2137         case CheckBadCell:
2138         case CheckNotEmpty:
2139         case CheckTraps:
2140         case Unreachable:
2141         case ExtractOSREntryLocal:
2142         case ExtractCatchLocal:
2143         case LoopHint:
2144         case MovHint:
2145         case InitializeEntrypointArguments:
2146         case ZombieHint:
2147         case ExitOK:
2148         case BottomValue:
2149         case TypeOf:
2150         case PutByIdWithThis:
2151         case PutByValWithThis:
2152         case GetByValWithThis:
2153         case CompareEqPtr:
2154         case NumberToStringWithValidRadixConstant:
2155         case GetGlobalThis:
2156         case ExtractValueFromWeakMapGet:
2157         case CPUIntrinsic:
2158             break;
2159 #else
2160         default:
2161             break;
2162 #endif
2163         }
2164     }
2165
2166     void watchHavingABadTime(Node* node)
2167     {
2168         JSGlobalObject* globalObject = m_graph.globalObjectFor(node->origin.semantic);
2169
2170         // If this global object is not having a bad time, watch it. We go down this path anytime the code
2171         // does an array allocation. The types of array allocations may change if we start to have a bad
2172         // time. It's easier to reason about this if we know that whenever the types change after we start
2173         // optimizing, the code just gets thrown out. Doing this at FixupPhase is just early enough, since
2174         // prior to this point nobody should have been doing optimizations based on the indexing type of
2175         // the allocation.
2176         if (!globalObject->isHavingABadTime()) {
2177             m_graph.watchpoints().addLazily(globalObject->havingABadTimeWatchpoint());
2178             m_graph.freeze(globalObject);
2179         }
2180     }
2181     
2182     template<UseKind useKind>
2183     void createToString(Node* node, Edge& edge)
2184     {
2185         Node* toString = m_insertionSet.insertNode(
2186             m_indexInBlock, SpecString, ToString, node->origin,
2187             Edge(edge.node(), useKind));
2188         switch (useKind) {
2189         case Int32Use:
2190         case Int52RepUse:
2191         case DoubleRepUse:
2192         case NotCellUse:
2193             toString->clearFlags(NodeMustGenerate);
2194             break;
2195         default:
2196             break;
2197         }
2198         edge.setNode(toString);
2199     }
2200     
2201     template<UseKind useKind>
2202     void attemptToForceStringArrayModeByToStringConversion(ArrayMode& arrayMode, Node* node)
2203     {
2204         ASSERT(arrayMode == ArrayMode(Array::Generic));
2205         
2206         if (!m_graph.canOptimizeStringObjectAccess(node->origin.semantic))
2207             return;
2208         
2209         createToString<useKind>(node, node->child1());
2210         arrayMode = ArrayMode(Array::String);
2211     }
2212     
2213     template<UseKind useKind>
2214     bool isStringObjectUse()
2215     {
2216         switch (useKind) {
2217         case StringObjectUse:
2218         case StringOrStringObjectUse:
2219             return true;
2220         default:
2221             return false;
2222         }
2223     }
2224     
2225     template<UseKind useKind>
2226     void convertStringAddUse(Node* node, Edge& edge)
2227     {
2228         if (useKind == StringUse) {
2229             observeUseKindOnNode<StringUse>(edge.node());
2230             m_insertionSet.insertNode(
2231                 m_indexInBlock, SpecNone, Check, node->origin,
2232                 Edge(edge.node(), StringUse));
2233             edge.setUseKind(KnownStringUse);
2234             return;
2235         }
2236         
2237         observeUseKindOnNode<useKind>(edge.node());
2238         createToString<useKind>(node, edge);
2239     }
2240     
2241     void convertToMakeRope(Node* node)
2242     {
2243         node->setOpAndDefaultFlags(MakeRope);
2244         fixupMakeRope(node);
2245     }
2246     
2247     void fixupMakeRope(Node* node)
2248     {
2249         for (unsigned i = 0; i < AdjacencyList::Size; ++i) {
2250             Edge& edge = node->children.child(i);
2251             if (!edge)
2252                 break;
2253             edge.setUseKind(KnownStringUse);
2254             JSString* string = edge->dynamicCastConstant<JSString*>(vm());
2255             if (!string)
2256                 continue;
2257             if (string->length())
2258                 continue;
2259             
2260             // Don't allow the MakeRope to have zero children.
2261             if (!i && !node->child2())
2262                 break;
2263             
2264             node->children.removeEdge(i--);
2265         }
2266         
2267         if (!node->child2()) {
2268             ASSERT(!node->child3());
2269             node->convertToIdentity();
2270         }
2271     }
2272
2273     void fixupIsCellWithType(Node* node)
2274     {
2275         switch (node->speculatedTypeForQuery()) {
2276         case SpecString:
2277             if (node->child1()->shouldSpeculateString()) {
2278                 m_insertionSet.insertNode(
2279                     m_indexInBlock, SpecNone, Check, node->origin,
2280                     Edge(node->child1().node(), StringUse));
2281                 m_graph.convertToConstant(node, jsBoolean(true));
2282                 observeUseKindOnNode<StringUse>(node);
2283                 return;
2284             }
2285             break;
2286
2287         case SpecProxyObject:
2288             if (node->child1()->shouldSpeculateProxyObject()) {
2289                 m_insertionSet.insertNode(
2290                     m_indexInBlock, SpecNone, Check, node->origin,
2291                     Edge(node->child1().node(), ProxyObjectUse));
2292                 m_graph.convertToConstant(node, jsBoolean(true));
2293                 observeUseKindOnNode<ProxyObjectUse>(node);
2294                 return;
2295             }
2296             break;
2297
2298         case SpecRegExpObject:
2299             if (node->child1()->shouldSpeculateRegExpObject()) {
2300                 m_insertionSet.insertNode(
2301                     m_indexInBlock, SpecNone, Check, node->origin,
2302                     Edge(node->child1().node(), RegExpObjectUse));
2303                 m_graph.convertToConstant(node, jsBoolean(true));
2304                 observeUseKindOnNode<RegExpObjectUse>(node);
2305                 return;
2306             }
2307             break;
2308
2309         case SpecArray:
2310             if (node->child1()->shouldSpeculateArray()) {
2311                 m_insertionSet.insertNode(
2312                     m_indexInBlock, SpecNone, Check, node->origin,
2313                     Edge(node->child1().node(), ArrayUse));
2314                 m_graph.convertToConstant(node, jsBoolean(true));
2315                 observeUseKindOnNode<ArrayUse>(node);
2316                 return;
2317             }
2318             break;
2319
2320         case SpecDerivedArray:
2321             if (node->child1()->shouldSpeculateDerivedArray()) {
2322                 m_insertionSet.insertNode(
2323                     m_indexInBlock, SpecNone, Check, node->origin,
2324                     Edge(node->child1().node(), DerivedArrayUse));
2325                 m_graph.convertToConstant(node, jsBoolean(true));
2326                 observeUseKindOnNode<DerivedArrayUse>(node);
2327                 return;
2328             }
2329             break;
2330         }
2331
2332         if (node->child1()->shouldSpeculateCell()) {
2333             fixEdge<CellUse>(node->child1());
2334             return;
2335         }
2336
2337         if (node->child1()->shouldSpeculateNotCell()) {
2338             m_insertionSet.insertNode(
2339                 m_indexInBlock, SpecNone, Check, node->origin,
2340                 Edge(node->child1().node(), NotCellUse));
2341             m_graph.convertToConstant(node, jsBoolean(false));
2342             observeUseKindOnNode<NotCellUse>(node);
2343             return;
2344         }
2345     }
2346
2347     void fixupGetPrototypeOf(Node* node)
2348     {
2349         // Reflect.getPrototypeOf only accepts Objects. For Reflect.getPrototypeOf, ByteCodeParser attaches ObjectUse edge filter before fixup phase.
2350         if (node->child1().useKind() != ObjectUse) {
2351             if (node->child1()->shouldSpeculateString()) {
2352                 insertCheck<StringUse>(node->child1().node());
2353                 m_graph.convertToConstant(node, m_graph.freeze(m_graph.globalObjectFor(node->origin.semantic)->stringPrototype()));
2354                 return;
2355             }
2356             if (node->child1()->shouldSpeculateInt32()) {
2357                 insertCheck<Int32Use>(node->child1().node());
2358                 m_graph.convertToConstant(node, m_graph.freeze(m_graph.globalObjectFor(node->origin.semantic)->numberPrototype()));
2359                 return;
2360             }
2361             if (enableInt52() && node->child1()->shouldSpeculateAnyInt()) {
2362                 insertCheck<Int52RepUse>(node->child1().node());
2363                 m_graph.convertToConstant(node, m_graph.freeze(m_graph.globalObjectFor(node->origin.semantic)->numberPrototype()));
2364                 return;
2365             }
2366             if (node->child1()->shouldSpeculateNumber()) {
2367                 insertCheck<NumberUse>(node->child1().node());
2368                 m_graph.convertToConstant(node, m_graph.freeze(m_graph.globalObjectFor(node->origin.semantic)->numberPrototype()));
2369                 return;
2370             }
2371             if (node->child1()->shouldSpeculateSymbol()) {
2372                 insertCheck<SymbolUse>(node->child1().node());
2373                 m_graph.convertToConstant(node, m_graph.freeze(m_graph.globalObjectFor(node->origin.semantic)->symbolPrototype()));
2374                 return;
2375             }
2376             if (node->child1()->shouldSpeculateBoolean()) {
2377                 insertCheck<BooleanUse>(node->child1().node());
2378                 m_graph.convertToConstant(node, m_graph.freeze(m_graph.globalObjectFor(node->origin.semantic)->booleanPrototype()));
2379                 return;
2380             }
2381         }
2382
2383         if (node->child1()->shouldSpeculateFinalObject()) {
2384             fixEdge<FinalObjectUse>(node->child1());
2385             node->clearFlags(NodeMustGenerate);
2386             return;
2387         }
2388         if (node->child1()->shouldSpeculateArray()) {
2389             fixEdge<ArrayUse>(node->child1());
2390             node->clearFlags(NodeMustGenerate);
2391             return;
2392         }
2393         if (node->child1()->shouldSpeculateFunction()) {
2394             fixEdge<FunctionUse>(node->child1());
2395             node->clearFlags(NodeMustGenerate);
2396             return;
2397         }
2398     }
2399
2400     void fixupToThis(Node* node)
2401     {
2402         ECMAMode ecmaMode = m_graph.executableFor(node->origin.semantic)->isStrictMode() ? StrictMode : NotStrictMode;
2403
2404         if (ecmaMode == StrictMode) {
2405             if (node->child1()->shouldSpeculateBoolean()) {
2406                 fixEdge<BooleanUse>(node->child1());
2407                 node->convertToIdentity();
2408                 return;
2409             }
2410
2411             if (node->child1()->shouldSpeculateInt32()) {
2412                 fixEdge<Int32Use>(node->child1());
2413                 node->convertToIdentity();
2414                 return;
2415             }
2416
2417             if (enableInt52() && node->child1()->shouldSpeculateAnyInt()) {
2418                 fixEdge<Int52RepUse>(node->child1());
2419                 node->convertToIdentity();
2420                 node->setResult(NodeResultInt52);
2421                 return;
2422             }
2423
2424             if (node->child1()->shouldSpeculateNumber()) {
2425                 fixEdge<DoubleRepUse>(node->child1());
2426                 node->convertToIdentity();
2427                 node->setResult(NodeResultDouble);
2428                 return;
2429             }
2430
2431             if (node->child1()->shouldSpeculateSymbol()) {
2432                 fixEdge<SymbolUse>(node->child1());
2433                 node->convertToIdentity();
2434                 return;
2435             }
2436
2437             if (node->child1()->shouldSpeculateStringIdent()) {
2438                 fixEdge<StringIdentUse>(node->child1());
2439                 node->convertToIdentity();
2440                 return;
2441             }
2442
2443             if (node->child1()->shouldSpeculateString()) {
2444                 fixEdge<StringUse>(node->child1());
2445                 node->convertToIdentity();
2446                 return;
2447             }
2448         }
2449
2450         if (node->child1()->shouldSpeculateOther()) {
2451             if (ecmaMode == StrictMode) {
2452                 fixEdge<OtherUse>(node->child1());
2453                 node->convertToIdentity();
2454                 return;
2455             }
2456
2457             m_insertionSet.insertNode(
2458                 m_indexInBlock, SpecNone, Check, node->origin,
2459                 Edge(node->child1().node(), OtherUse));
2460             observeUseKindOnNode<OtherUse>(node->child1().node());
2461             m_graph.convertToConstant(
2462                 node, m_graph.globalThisObjectFor(node->origin.semantic));
2463             return;
2464         }
2465
2466         // FIXME: This should cover other use cases but we don't have use kinds for them. It's not critical,
2467         // however, since we cover all the missing cases in constant folding.
2468         // https://bugs.webkit.org/show_bug.cgi?id=157213
2469         if (node->child1()->shouldSpeculateStringObject()) {
2470             fixEdge<StringObjectUse>(node->child1());
2471             node->convertToIdentity();
2472             return;
2473         }
2474
2475         if (isFinalObjectSpeculation(node->child1()->prediction())) {
2476             fixEdge<FinalObjectUse>(node->child1());
2477             node->convertToIdentity();
2478             return;
2479         }
2480     }
2481     
2482     void fixupToPrimitive(Node* node)
2483     {
2484         if (node->child1()->shouldSpeculateInt32()) {
2485             fixEdge<Int32Use>(node->child1());
2486             node->convertToIdentity();
2487             return;
2488         }
2489         
2490         if (node->child1()->shouldSpeculateString()) {
2491             fixEdge<StringUse>(node->child1());
2492             node->convertToIdentity();
2493             return;
2494         }
2495         
2496         if (node->child1()->shouldSpeculateStringObject()
2497             && m_graph.canOptimizeStringObjectAccess(node->origin.semantic)) {
2498             fixEdge<StringObjectUse>(node->child1());
2499             node->convertToToString();
2500             return;
2501         }
2502         
2503         if (node->child1()->shouldSpeculateStringOrStringObject()
2504             && m_graph.canOptimizeStringObjectAccess(node->origin.semantic)) {
2505             fixEdge<StringOrStringObjectUse>(node->child1());
2506             node->convertToToString();
2507             return;
2508         }
2509     }
2510
2511     void fixupToNumber(Node* node)
2512     {
2513         // If the prediction of the child is Number, we attempt to convert ToNumber to Identity.
2514         if (node->child1()->shouldSpeculateNumber()) {
2515             if (isInt32Speculation(node->getHeapPrediction())) {
2516                 // If the both predictions of this node and the child is Int32, we just convert ToNumber to Identity, that's simple.
2517                 if (node->child1()->shouldSpeculateInt32()) {
2518                     fixEdge<Int32Use>(node->child1());
2519                     node->convertToIdentity();
2520                     return;
2521                 }
2522
2523                 // The another case is that the predicted type of the child is Int32, but the heap prediction tell the users that this will produce non Int32 values.
2524                 // In that case, let's receive the child value as a Double value and convert it to Int32. This case happens in misc-bugs-847389-jpeg2000.
2525                 fixEdge<DoubleRepUse>(node->child1());
2526                 node->setOp(DoubleAsInt32);
2527                 if (bytecodeCanIgnoreNegativeZero(node->arithNodeFlags()))
2528                     node->setArithMode(Arith::CheckOverflow);
2529                 else
2530                     node->setArithMode(Arith::CheckOverflowAndNegativeZero);
2531                 return;
2532             }
2533
2534             fixEdge<DoubleRepUse>(node->child1());
2535             node->convertToIdentity();
2536             node->setResult(NodeResultDouble);
2537             return;
2538         }
2539
2540         fixEdge<UntypedUse>(node->child1());
2541         node->setResult(NodeResultJS);
2542     }
2543
2544     void fixupToObject(Node* node)
2545     {
2546         if (node->child1()->shouldSpeculateObject()) {
2547             fixEdge<ObjectUse>(node->child1());
2548             node->convertToIdentity();
2549             return;
2550         }
2551
2552         // ToObject(Null/Undefined) can throw an error. We can emit filters to convert ToObject to CallObjectConstructor.
2553
2554         JSGlobalObject* globalObject = m_graph.globalObjectFor(node->origin.semantic);
2555
2556         if (node->child1()->shouldSpeculateString()) {
2557             insertCheck<StringUse>(node->child1().node());
2558             fixEdge<KnownStringUse>(node->child1());
2559             node->convertToNewStringObject(m_graph.registerStructure(globalObject->stringObjectStructure()));
2560             return;
2561         }
2562
2563         if (node->child1()->shouldSpeculateSymbol()) {
2564             insertCheck<SymbolUse>(node->child1().node());
2565             node->convertToCallObjectConstructor(m_graph.freeze(globalObject));
2566             return;
2567         }
2568
2569         if (node->child1()->shouldSpeculateNumber()) {
2570             insertCheck<NumberUse>(node->child1().node());
2571             node->convertToCallObjectConstructor(m_graph.freeze(globalObject));
2572             return;
2573         }
2574
2575         if (node->child1()->shouldSpeculateBoolean()) {
2576             insertCheck<BooleanUse>(node->child1().node());
2577             node->convertToCallObjectConstructor(m_graph.freeze(globalObject));
2578             return;
2579         }
2580
2581         fixEdge<UntypedUse>(node->child1());
2582     }
2583
2584     void fixupCallObjectConstructor(Node* node)
2585     {
2586         if (node->child1()->shouldSpeculateObject()) {
2587             fixEdge<ObjectUse>(node->child1());
2588             node->convertToIdentity();
2589             return;
2590         }
2591
2592         if (node->child1()->shouldSpeculateString()) {
2593             auto* globalObject = jsCast<JSGlobalObject*>(node->cellOperand()->cell());
2594             insertCheck<StringUse>(node->child1().node());
2595             fixEdge<KnownStringUse>(node->child1());
2596             node->convertToNewStringObject(m_graph.registerStructure(globalObject->stringObjectStructure()));
2597             return;
2598         }
2599
2600         // While ToObject(Null/Undefined) throws an error, CallObjectConstructor(Null/Undefined) generates a new empty object.
2601         if (node->child1()->shouldSpeculateOther()) {
2602             insertCheck<OtherUse>(node->child1().node());
2603             node->convertToNewObject(m_graph.registerStructure(jsCast<JSGlobalObject*>(node->cellOperand()->cell())->objectStructureForObjectConstructor()));
2604             return;
2605         }
2606
2607         fixEdge<UntypedUse>(node->child1());
2608     }
2609     
2610     void fixupToStringOrCallStringConstructor(Node* node)
2611     {
2612         if (node->child1()->shouldSpeculateString()) {
2613             fixEdge<StringUse>(node->child1());
2614             node->convertToIdentity();
2615             return;
2616         }
2617         
2618         if (node->child1()->shouldSpeculateStringObject()
2619             && m_graph.canOptimizeStringObjectAccess(node->origin.semantic)) {
2620             fixEdge<StringObjectUse>(node->child1());
2621             return;
2622         }
2623         
2624         if (node->child1()->shouldSpeculateStringOrStringObject()
2625             && m_graph.canOptimizeStringObjectAccess(node->origin.semantic)) {
2626             fixEdge<StringOrStringObjectUse>(node->child1());
2627             return;
2628         }
2629         
2630         if (node->child1()->shouldSpeculateCell()) {
2631             fixEdge<CellUse>(node->child1());
2632             return;
2633         }
2634
2635         if (node->child1()->shouldSpeculateInt32()) {
2636             fixEdge<Int32Use>(node->child1());
2637             node->clearFlags(NodeMustGenerate);
2638             return;
2639         }
2640
2641         if (enableInt52() && node->child1()->shouldSpeculateAnyInt()) {
2642             fixEdge<Int52RepUse>(node->child1());
2643             node->clearFlags(NodeMustGenerate);
2644             return;
2645         }
2646
2647         if (node->child1()->shouldSpeculateNumber()) {
2648             fixEdge<DoubleRepUse>(node->child1());
2649             node->clearFlags(NodeMustGenerate);
2650             return;
2651         }
2652
2653         // ToString(Symbol) throws an error. So if the child1 can include Symbols,
2654         // we need to care about it in the clobberize. In the following case,
2655         // since NotCellUse edge filter is used and this edge filters Symbols,
2656         // we can say that ToString never throws an error!
2657         if (node->child1()->shouldSpeculateNotCell()) {
2658             fixEdge<NotCellUse>(node->child1());
2659             node->clearFlags(NodeMustGenerate);
2660             return;
2661         }
2662     }
2663
2664     bool attemptToMakeFastStringAdd(Node* node)
2665     {
2666         bool goodToGo = true;
2667         m_graph.doToChildren(
2668             node,
2669             [&] (Edge& edge) {
2670                 if (edge->shouldSpeculateString())
2671                     return;
2672                 if (m_graph.canOptimizeStringObjectAccess(node->origin.semantic)) {
2673                     if (edge->shouldSpeculateStringObject())
2674                         return;
2675                     if (edge->shouldSpeculateStringOrStringObject())
2676                         return;
2677                 }
2678                 goodToGo = false;
2679             });
2680         if (!goodToGo)
2681             return false;
2682
2683         m_graph.doToChildren(
2684             node,
2685             [&] (Edge& edge) {
2686                 if (edge->shouldSpeculateString()) {
2687                     convertStringAddUse<StringUse>(node, edge);
2688                     return;
2689                 }
2690                 ASSERT(m_graph.canOptimizeStringObjectAccess(node->origin.semantic));
2691                 if (edge->shouldSpeculateStringObject()) {
2692                     convertStringAddUse<StringObjectUse>(node, edge);
2693                     return;
2694                 }
2695                 if (edge->shouldSpeculateStringOrStringObject()) {
2696                     convertStringAddUse<StringOrStringObjectUse>(node, edge);
2697                     return;
2698                 }
2699                 RELEASE_ASSERT_NOT_REACHED();
2700             });
2701         
2702         convertToMakeRope(node);
2703         return true;
2704     }
2705
2706     void fixupGetAndSetLocalsInBlock(BasicBlock* block)
2707     {
2708         if (!block)
2709             return;
2710         ASSERT(block->isReachable);
2711         m_block = block;
2712         for (m_indexInBlock = 0; m_indexInBlock < block->size(); ++m_indexInBlock) {
2713             Node* node = m_currentNode = block->at(m_indexInBlock);
2714             if (node->op() != SetLocal && node->op() != GetLocal)
2715                 continue;
2716             
2717             VariableAccessData* variable = node->variableAccessData();
2718             switch (node->op()) {
2719             case GetLocal:
2720                 switch (variable->flushFormat()) {
2721                 case FlushedDouble:
2722                     node->setResult(NodeResultDouble);
2723                     break;
2724                 case FlushedInt52:
2725                     node->setResult(NodeResultInt52);
2726                     break;
2727                 default:
2728                     break;
2729                 }
2730                 break;
2731                 
2732             case SetLocal:
2733                 // NOTE: Any type checks we put here may get hoisted by fixupChecksInBlock(). So, if we
2734                 // add new type checking use kind for SetLocals, we need to modify that code as well.
2735                 
2736                 switch (variable->flushFormat()) {
2737                 case FlushedJSValue:
2738                     break;
2739                 case FlushedDouble:
2740                     fixEdge<DoubleRepUse>(node->child1());
2741                     break;
2742                 case FlushedInt32:
2743                     fixEdge<Int32Use>(node->child1());
2744                     break;
2745                 case FlushedInt52:
2746                     fixEdge<Int52RepUse>(node->child1());
2747                     break;
2748                 case FlushedCell:
2749                     fixEdge<CellUse>(node->child1());
2750                     break;
2751                 case FlushedBoolean:
2752                     fixEdge<BooleanUse>(node->child1());
2753                     break;
2754                 default:
2755                     RELEASE_ASSERT_NOT_REACHED();
2756                     break;
2757                 }
2758                 break;
2759                 
2760             default:
2761                 RELEASE_ASSERT_NOT_REACHED();
2762                 break;
2763             }
2764         }
2765         m_insertionSet.execute(block);
2766     }
2767     
2768     void addStringReplacePrimordialChecks(Node* searchRegExp)
2769     {
2770         Node* node = m_currentNode;
2771
2772         // Check that structure of searchRegExp is RegExp object
2773         m_insertionSet.insertNode(
2774             m_indexInBlock, SpecNone, Check, node->origin,
2775             Edge(searchRegExp, RegExpObjectUse));
2776
2777         auto emitPrimordialCheckFor = [&] (JSValue primordialProperty, UniquedStringImpl* propertyUID) {
2778             unsigned index = m_graph.identifiers().ensure(propertyUID);
2779
2780             Node* actualProperty = m_insertionSet.insertNode(
2781                 m_indexInBlock, SpecNone, TryGetById, node->origin,
2782                 OpInfo(index), OpInfo(SpecFunction), Edge(searchRegExp, CellUse));
2783
2784             m_insertionSet.insertNode(
2785                 m_indexInBlock, SpecNone, CheckCell, node->origin,
2786                 OpInfo(m_graph.freeze(primordialProperty)), Edge(actualProperty, CellUse));
2787         };
2788
2789         JSGlobalObject* globalObject = m_graph.globalObjectFor(node->origin.semantic);
2790
2791         // Check that searchRegExp.exec is the primordial RegExp.prototype.exec
2792         emitPrimordialCheckFor(globalObject->regExpProtoExecFunction(), vm().propertyNames->exec.impl());
2793         // Check that searchRegExp.global is the primordial RegExp.prototype.global
2794         emitPrimordialCheckFor(globalObject->regExpProtoGlobalGetter(), vm().propertyNames->global.impl());
2795         // Check that searchRegExp.unicode is the primordial RegExp.prototype.unicode
2796         emitPrimordialCheckFor(globalObject->regExpProtoUnicodeGetter(), vm().propertyNames->unicode.impl());
2797         // Check that searchRegExp[Symbol.match] is the primordial RegExp.prototype[Symbol.replace]
2798         emitPrimordialCheckFor(globalObject->regExpProtoSymbolReplaceFunction(), vm().propertyNames->replaceSymbol.impl());
2799     }
2800
2801     Node* checkArray(ArrayMode arrayMode, const NodeOrigin& origin, Node* array, Node* index, bool (*storageCheck)(const ArrayMode&) = canCSEStorage)
2802     {
2803         ASSERT(arrayMode.isSpecific());
2804         
2805         if (arrayMode.type() == Array::String) {
2806             m_insertionSet.insertNode(
2807                 m_indexInBlock, SpecNone, Check, origin, Edge(array, StringUse));
2808         } else {
2809             // Note that we only need to be using a structure check if we opt for SaneChain, since
2810             // that needs to protect against JSArray's __proto__ being changed.
2811             Structure* structure = arrayMode.originalArrayStructure(m_graph, origin.semantic);
2812         
2813             Edge indexEdge = index ? Edge(index, Int32Use) : Edge();
2814             
2815             if (arrayMode.doesConversion()) {
2816                 if (structure) {
2817                     m_insertionSet.insertNode(
2818                         m_indexInBlock, SpecNone, ArrayifyToStructure, origin,
2819                         OpInfo(m_graph.registerStructure(structure)), OpInfo(arrayMode.asWord()), Edge(array, CellUse), indexEdge);
2820                 } else {
2821                     m_insertionSet.insertNode(
2822                         m_indexInBlock, SpecNone, Arrayify, origin,
2823                         OpInfo(arrayMode.asWord()), Edge(array, CellUse), indexEdge);
2824                 }
2825             } else {
2826                 if (structure) {
2827                     m_insertionSet.insertNode(
2828                         m_indexInBlock, SpecNone, CheckStructure, origin,
2829                         OpInfo(m_graph.addStructureSet(structure)), Edge(array, CellUse));
2830                 } else {
2831                     m_insertionSet.insertNode(
2832                         m_indexInBlock, SpecNone, CheckArray, origin,
2833                         OpInfo(arrayMode.asWord()), Edge(array, CellUse));
2834                 }
2835             }
2836         }
2837         
2838         if (!storageCheck(arrayMode))
2839             return nullptr;
2840         
2841         if (arrayMode.usesButterfly()) {
2842             return m_insertionSet.insertNode(
2843                 m_indexInBlock, SpecNone, GetButterfly, origin, Edge(array, CellUse));
2844         }
2845         
2846         return m_insertionSet.insertNode(
2847             m_indexInBlock, SpecNone, GetIndexedPropertyStorage, origin,
2848             OpInfo(arrayMode.asWord()), Edge(array, KnownCellUse));
2849     }
2850     
2851     void blessArrayOperation(Edge base, Edge index, Edge& storageChild)
2852     {
2853         Node* node = m_currentNode;
2854         
2855         switch (node->arrayMode().type()) {
2856         case Array::ForceExit: {
2857             m_insertionSet.insertNode(
2858                 m_indexInBlock, SpecNone, ForceOSRExit, node->origin);
2859             return;
2860         }
2861             
2862         case Array::SelectUsingPredictions:
2863         case Array::Unprofiled:
2864             RELEASE_ASSERT_NOT_REACHED();
2865             return;
2866             
2867         case Array::Generic:
2868             return;
2869             
2870         default: {
2871             Node* storage = checkArray(node->arrayMode(), node->origin, base.node(), index.node());
2872             if (!storage)
2873                 return;
2874             
2875             storageChild = Edge(storage);
2876             return;
2877         } }
2878     }
2879     
2880     bool alwaysUnboxSimplePrimitives()
2881     {
2882 #if USE(JSVALUE64)
2883         return false;
2884 #else
2885         // Any boolean, int, or cell value is profitable to unbox on 32-bit because it
2886         // reduces traffic.
2887         return true;
2888 #endif
2889     }
2890
2891     template<UseKind useKind>
2892     void observeUseKindOnNode(Node* node)
2893     {
2894         if (useKind == UntypedUse)
2895             return;
2896         observeUseKindOnNode(node, useKind);
2897     }
2898
2899     void observeUseKindOnEdge(Edge edge)
2900     {
2901         observeUseKindOnNode(edge.node(), edge.useKind());
2902     }
2903
2904     void observeUseKindOnNode(Node* node, UseKind useKind)
2905     {
2906         if (node->op() != GetLocal)
2907             return;
2908         
2909         // FIXME: The way this uses alwaysUnboxSimplePrimitives() is suspicious.
2910         // https://bugs.webkit.org/show_bug.cgi?id=121518
2911         
2912         VariableAccessData* variable = node->variableAccessData();
2913         switch (useKind) {
2914         case Int32Use:
2915         case KnownInt32Use:
2916             if (alwaysUnboxSimplePrimitives()
2917                 || isInt32Speculation(variable->prediction()))
2918                 m_profitabilityChanged |= variable->mergeIsProfitableToUnbox(true);
2919             break;
2920         case NumberUse:
2921         case RealNumberUse:
2922         case DoubleRepUse:
2923         case DoubleRepRealUse:
2924             if (variable->doubleFormatState() == UsingDoubleFormat)
2925                 m_profitabilityChanged |= variable->mergeIsProfitableToUnbox(true);
2926             break;
2927         case BooleanUse:
2928         case KnownBooleanUse:
2929             if (alwaysUnboxSimplePrimitives()
2930                 || isBooleanSpeculation(variable->prediction()))
2931                 m_profitabilityChanged |= variable->mergeIsProfitableToUnbox(true);
2932             break;
2933         case Int52RepUse:
2934             if (isAnyIntSpeculation(variable->prediction()))
2935                 m_profitabilityChanged |= variable->mergeIsProfitableToUnbox(true);
2936             break;
2937         case CellUse:
2938         case KnownCellUse:
2939         case ObjectUse:
2940         case FunctionUse:
2941         case StringUse:
2942         case KnownStringUse:
2943         case SymbolUse:
2944         case StringObjectUse:
2945         case StringOrStringObjectUse:
2946             if (alwaysUnboxSimplePrimitives()
2947                 || isCellSpeculation(variable->prediction()))
2948                 m_profitabilityChanged |= variable->mergeIsProfitableToUnbox(true);
2949             break;
2950         default:
2951             break;
2952         }
2953     }
2954     
2955     template<UseKind useKind>
2956     void fixEdge(Edge& edge)
2957     {
2958         observeUseKindOnNode<useKind>(edge.node());
2959         edge.setUseKind(useKind);
2960     }
2961     
2962     unsigned indexForChecks()
2963     {
2964         unsigned index = m_indexInBlock;
2965         while (!m_block->at(index)->origin.exitOK)
2966             index--;
2967         return index;
2968     }
2969     
2970     NodeOrigin originForCheck(unsigned index)
2971     {
2972         return m_block->at(index)->origin.withSemantic(m_currentNode->origin.semantic);
2973     }
2974     
2975     void speculateForBarrier(Edge value)
2976     {
2977         // Currently, the DFG won't take advantage of this speculation. But, we want to do it in
2978         // the DFG anyway because if such a speculation would be wrong, we want to know before
2979         // we do an expensive compile.
2980         
2981         if (value->shouldSpeculateInt32()) {
2982             insertCheck<Int32Use>(value.node());
2983             return;
2984         }
2985             
2986         if (value->shouldSpeculateBoolean()) {
2987             insertCheck<BooleanUse>(value.node());
2988             return;
2989         }
2990             
2991         if (value->shouldSpeculateOther()) {
2992             insertCheck<OtherUse>(value.node());
2993             return;
2994         }
2995             
2996         if (value->shouldSpeculateNumber()) {
2997             insertCheck<NumberUse>(value.node());
2998             return;
2999         }
3000             
3001         if (value->shouldSpeculateNotCell()) {
3002             insertCheck<NotCellUse>(value.node());
3003             return;
3004         }
3005     }
3006     
3007     template<UseKind useKind>
3008     void insertCheck(Node* node)
3009     {
3010         observeUseKindOnNode<useKind>(node);
3011         unsigned index = indexForChecks();
3012         m_insertionSet.insertNode(index, SpecNone, Check, originForCheck(index), Edge(node, useKind));
3013     }
3014
3015     void fixIntConvertingEdge(Edge& edge)
3016     {
3017         Node* node = edge.node();
3018         if (node->shouldSpeculateInt32OrBoolean()) {
3019             fixIntOrBooleanEdge(edge);
3020             return;
3021         }
3022         
3023         UseKind useKind;
3024         if (node->shouldSpeculateAnyInt())
3025             useKind = Int52RepUse;
3026         else if (node->shouldSpeculateNumber())
3027             useKind = DoubleRepUse;
3028         else
3029             useKind = NotCellUse;
3030         Node* newNode = m_insertionSet.insertNode(
3031             m_indexInBlock, SpecInt32Only, ValueToInt32, m_currentNode->origin,
3032             Edge(node, useKind));
3033         observeUseKindOnNode(node, useKind);
3034         
3035         edge = Edge(newNode, KnownInt32Use);
3036     }
3037     
3038     void fixIntOrBooleanEdge(Edge& edge)
3039     {
3040         Node* node = edge.node();
3041         if (!node->sawBooleans()) {
3042             fixEdge<Int32Use>(edge);
3043             return;
3044         }
3045         
3046         UseKind useKind;
3047         if (node->shouldSpeculateBoolean())
3048             useKind = BooleanUse;
3049         else
3050             useKind = UntypedUse;
3051         Node* newNode = m_insertionSet.insertNode(
3052             m_indexInBlock, SpecInt32Only, BooleanToNumber, m_currentNode->origin,
3053             Edge(node, useKind));
3054         observeUseKindOnNode(node, useKind);
3055         
3056         edge = Edge(newNode, Int32Use);
3057     }
3058     
3059     void fixDoubleOrBooleanEdge(Edge& edge)
3060     {
3061         Node* node = edge.node();
3062         if (!node->sawBooleans()) {
3063             fixEdge<DoubleRepUse>(edge);
3064             return;
3065         }
3066         
3067         UseKind useKind;
3068         if (node->shouldSpeculateBoolean())
3069             useKind = BooleanUse;
3070         else
3071             useKind = UntypedUse;
3072         Node* newNode = m_insertionSet.insertNode(
3073             m_indexInBlock, SpecInt32Only, BooleanToNumber, m_currentNode->origin,
3074             Edge(node, useKind));
3075         observeUseKindOnNode(node, useKind);
3076         
3077         edge = Edge(newNode, DoubleRepUse);
3078     }
3079     
3080     void truncateConstantToInt32(Edge& edge)
3081     {
3082         Node* oldNode = edge.node();
3083         
3084         JSValue value = oldNode->asJSValue();
3085         if (value.isInt32())
3086             return;
3087         
3088         value = jsNumber(JSC::toInt32(value.asNumber()));
3089         ASSERT(value.isInt32());
3090         edge.setNode(m_insertionSet.insertNode(
3091             m_indexInBlock, SpecInt32Only, JSConstant, m_currentNode->origin,
3092             OpInfo(m_graph.freeze(value))));
3093     }
3094     
3095     void truncateConstantsIfNecessary(Node* node, AddSpeculationMode mode)
3096     {
3097         if (mode != SpeculateInt32AndTruncateConstants)
3098             return;
3099         
3100         ASSERT(node->child1()->hasConstant() || node->child2()->hasConstant());
3101         if (node->child1()->hasConstant())
3102             truncateConstantToInt32(node->child1());
3103         else
3104             truncateConstantToInt32(node->child2());
3105     }
3106
3107     bool attemptToMakeIntegerAdd(Node* node)
3108     {
3109         AddSpeculationMode mode = m_graph.addSpeculationMode(node, FixupPass);
3110         if (mode != DontSpeculateInt32) {
3111             truncateConstantsIfNecessary(node, mode);
3112             fixIntOrBooleanEdge(node->child1());
3113             fixIntOrBooleanEdge(node->child2());
3114             if (bytecodeCanTruncateInteger(node->arithNodeFlags()))
3115                 node->setArithMode(Arith::Unchecked);
3116             else
3117                 node->setArithMode(Arith::CheckOverflow);
3118             return true;
3119         }
3120         
3121         if (m_graph.addShouldSpeculateAnyInt(node)) {
3122             fixEdge<Int52RepUse>(node->child1());
3123             fixEdge<Int52RepUse>(node->child2());
3124             node->setArithMode(Arith::CheckOverflow);
3125             node->setResult(NodeResultInt52);
3126             return true;
3127         }
3128         
3129         return false;
3130     }
3131     
3132     bool attemptToMakeGetArrayLength(Node* node)
3133     {
3134         if (!isInt32Speculation(node->prediction()))
3135             return false;
3136         CodeBlock* profiledBlock = m_graph.baselineCodeBlockFor(node->origin.semantic);
3137         ArrayProfile* arrayProfile = 
3138             profiledBlock->getArrayProfile(node->origin.semantic.bytecodeIndex);
3139         ArrayMode arrayMode = ArrayMode(Array::SelectUsingPredictions);
3140         if (arrayProfile) {
3141             ConcurrentJSLocker locker(profiledBlock->m_lock);
3142             arrayProfile->computeUpdatedPrediction(locker, profiledBlock);
3143             arrayMode = ArrayMode::fromObserved(locker, arrayProfile, Array::Read, false);
3144             if (arrayMode.type() == Array::Unprofiled) {
3145                 // For normal array operations, it makes sense to treat Unprofiled
3146                 // accesses as ForceExit and get more data rather than using
3147                 // predictions and then possibly ending up with a Generic. But here,
3148                 // we treat anything that is Unprofiled as Generic and keep the
3149                 // GetById. I.e. ForceExit = Generic. So, there is no harm - and only
3150                 // profit - from treating the Unprofiled case as
3151                 // SelectUsingPredictions.
3152                 arrayMode = ArrayMode(Array::SelectUsingPredictions);
3153             }
3154         }
3155             
3156         arrayMode = arrayMode.refine(
3157             m_graph, node, node->child1()->prediction(), node->prediction());
3158             
3159         if (arrayMode.type() == Array::Generic) {
3160             // Check if the input is something that we can't get array length for, but for which we
3161             // could insert some conversions in order to transform it into something that we can do it
3162             // for.
3163             if (node->child1()->shouldSpeculateStringObject())
3164                 attemptToForceStringArrayModeByToStringConversion<StringObjectUse>(arrayMode, node);
3165             else if (node->child1()->shouldSpeculateStringOrStringObject())
3166                 attemptToForceStringArrayModeByToStringConversion<StringOrStringObjectUse>(arrayMode, node);
3167         }
3168             
3169         if (!arrayMode.supportsSelfLength())
3170             return false;
3171         
3172         convertToGetArrayLength(node, arrayMode);
3173         return true;
3174     }
3175
3176     void convertToGetArrayLength(Node* node, ArrayMode arrayMode)
3177     {
3178         node->setOp(GetArrayLength);
3179         node->clearFlags(NodeMustGenerate);
3180         fixEdge<KnownCellUse>(node->child1());
3181         node->setArrayMode(arrayMode);
3182             
3183         Node* storage = checkArray(arrayMode, node->origin, node->child1().node(), 0, lengthNeedsStorage);
3184         if (!storage)
3185             return;
3186             
3187         node->child2() = Edge(storage);
3188     }
3189     
3190     Node* prependGetArrayLength(NodeOrigin origin, Node* child, ArrayMode arrayMode)
3191     {
3192         Node* storage = checkArray(arrayMode, origin, child, 0, lengthNeedsStorage);
3193         return m_insertionSet.insertNode(
3194             m_indexInBlock, SpecInt32Only, GetArrayLength, origin,
3195             OpInfo(arrayMode.asWord()), Edge(child, KnownCellUse), Edge(storage));
3196     }
3197
3198     void convertToHasIndexedProperty(Node* node)
3199     {
3200         node->setOp(HasIndexedProperty);
3201         node->clearFlags(NodeMustGenerate);
3202         node->setArrayMode(
3203             node->arrayMode().refine(
3204                 m_graph, node,
3205                 node->child1()->prediction(),
3206                 node->child2()->prediction(),
3207                 SpecNone));
3208         node->setInternalMethodType(PropertySlot::InternalMethodType::HasProperty);
3209
3210         blessArrayOperation(node->child1(), node->child2(), node->child3());
3211
3212         fixEdge<CellUse>(node->child1());
3213         fixEdge<Int32Use>(node->child2());
3214     }
3215
3216     void fixupNormalizeMapKey(Node* node)
3217     {
3218         if (node->child1()->shouldSpeculateBoolean()) {
3219             fixEdge<BooleanUse>(node->child1());
3220             node->convertToIdentity();
3221             return;
3222         }
3223
3224         if (node->child1()->shouldSpeculateInt32()) {
3225             fixEdge<Int32Use>(node->child1());
3226             node->convertToIdentity();
3227             return;
3228         }
3229
3230         if (node->child1()->shouldSpeculateSymbol()) {
3231             fixEdge<SymbolUse>(node->child1());
3232             node->convertToIdentity();
3233             return;
3234         }
3235
3236         if (node->child1()->shouldSpeculateObject()) {
3237             fixEdge<ObjectUse>(node->child1());
3238             node->convertToIdentity();
3239             return;
3240         }
3241
3242         if (node->child1()->shouldSpeculateString()) {
3243             fixEdge<StringUse>(node->child1());
3244             node->convertToIdentity();
3245             return;
3246         }
3247
3248         if (node->child1()->shouldSpeculateCell()) {
3249             fixEdge<CellUse>(node->child1());
3250             node->convertToIdentity();
3251             return;
3252         }
3253
3254         fixEdge<UntypedUse>(node->child1());
3255     }
3256
3257     bool attemptToMakeCallDOM(Node* node)
3258     {
3259         if (m_graph.hasExitSite(node->origin.semantic, BadType))
3260             return false;
3261
3262         const DOMJIT::Signature* signature = node->signature();
3263         if (!signature)
3264             return false;
3265
3266         {
3267             unsigned index = 0;
3268             bool shouldConvertToCallDOM = true;
3269             m_graph.doToChildren(node, [&](Edge& edge) {
3270                 // Callee. Ignore this. DFGByteCodeParser already emit appropriate checks.
3271                 if (!index)
3272                     return;
3273
3274                 if (index == 1) {
3275                     // DOM node case.
3276                     if (edge->shouldSpeculateNotCell())
3277                         shouldConvertToCallDOM = false;
3278                 } else {
3279                     switch (signature->arguments[index - 2]) {
3280                     case SpecString:
3281                         if (edge->shouldSpeculateNotString())
3282                             shouldConvertToCallDOM = false;
3283                         break;
3284                     case SpecInt32Only:
3285                         if (edge->shouldSpeculateNotInt32())
3286                             shouldConvertToCallDOM = false;
3287                         break;
3288                     case SpecBoolean:
3289                         if (edge->shouldSpeculateNotBoolean())
3290                             shouldConvertToCallDOM = false;
3291                         break;
3292                     default:
3293                         RELEASE_ASSERT_NOT_REACHED();
3294                         break;
3295                     }
3296                 }
3297                 ++index;
3298             });
3299             if (!shouldConvertToCallDOM)
3300                 return false;
3301         }
3302
3303         Node* thisNode = m_graph.varArgChild(node, 1).node();
3304         Node* checkSubClass = m_insertionSet.insertNode(m_indexInBlock, SpecNone, CheckSubClass, node->origin, OpInfo(signature->classInfo), Edge(thisNode));
3305         node->convertToCallDOM(m_graph);
3306         fixupCheckSubClass(checkSubClass);
3307         fixupCallDOM(node);
3308         return true;
3309     }
3310
3311     void fixupCheckSubClass(Node* node)
3312     {
3313         fixEdge<CellUse>(node->child1());
3314     }
3315
3316     void fixupCallDOM(Node* node)
3317     {
3318         const DOMJIT::Signature* signature = node->signature();
3319         auto fixup = [&](Edge& edge, unsigned argumentIndex) {
3320             if (!edge)
3321                 return;
3322             switch (signature->arguments[argumentIndex]) {
3323             case SpecString:
3324                 fixEdge<StringUse>(edge);
3325                 break;
3326             case SpecInt32Only:
3327                 fixEdge<Int32Use>(edge);
3328                 break;
3329             case SpecBoolean:
3330                 fixEdge<BooleanUse>(edge);
3331                 break;
3332             default:
3333                 RELEASE_ASSERT_NOT_REACHED();
3334                 break;
3335             }
3336         };
3337         fixEdge<CellUse>(node->child1()); // DOM.
3338         fixup(node->child2(), 0);
3339         fixup(node->child3(), 1);
3340     }
3341
3342     void fixupArrayIndexOf(Node* node)
3343     {
3344         Edge& array = m_graph.varArgChild(node, 0);
3345         Edge& storage = m_graph.varArgChild(node, node->numChildren() == 3 ? 2 : 3);
3346         blessArrayOperation(array, Edge(), storage);
3347         ASSERT_WITH_MESSAGE(storage.node(), "blessArrayOperation for ArrayIndexOf must set Butterfly for storage edge.");
3348
3349         Edge& searchElement = m_graph.varArgChild(node, 1);
3350
3351         // Constant folding.
3352         switch (node->arrayMode().type()) {
3353         case Array::Double:
3354         case Array::Int32: {
3355             if (searchElement->shouldSpeculateCell()) {
3356                 m_insertionSet.insertNode(m_indexInBlock, SpecNone, Check, node->origin, Edge(searchElement.node(), CellUse));
3357                 m_graph.convertToConstant(node, jsNumber(-1));
3358                 observeUseKindOnNode<CellUse>(searchElement.node());
3359                 return;
3360             }
3361
3362             if (searchElement->shouldSpeculateOther()) {
3363                 m_insertionSet.insertNode(m_indexInBlock, SpecNone, Check, node->origin, Edge(searchElement.node(), OtherUse));
3364                 m_graph.convertToConstant(node, jsNumber(-1));
3365                 observeUseKindOnNode<OtherUse>(searchElement.node());
3366                 return;
3367             }
3368
3369             if (searchElement->shouldSpeculateBoolean()) {
3370                 m_insertionSet.insertNode(m_indexInBlock, SpecNone, Check, node->origin, Edge(searchElement.node(), BooleanUse));
3371                 m_graph.convertToConstant(node, jsNumber(-1));
3372                 observeUseKindOnNode<BooleanUse>(searchElement.node());
3373                 return;
3374             }
3375             break;
3376         }
3377         default:
3378             break;
3379         }
3380
3381         fixEdge<KnownCellUse>(array);
3382         if (node->numChildren() == 4)
3383             fixEdge<Int32Use>(m_graph.varArgChild(node, 2));
3384
3385         switch (node->arrayMode().type()) {
3386         case Array::Double: {
3387             if (searchElement->shouldSpeculateNumber())
3388                 fixEdge<DoubleRepUse>(searchElement);
3389             return;
3390         }
3391         case Array::Int32: {
3392             if (searchElement->shouldSpeculateInt32())
3393                 fixEdge<Int32Use>(searchElement);
3394             return;
3395         }
3396         case Array::Contiguous: {
3397             if (searchElement->shouldSpeculateString())
3398                 fixEdge<StringUse>(searchElement);
3399             else if (searchElement->shouldSpeculateSymbol())
3400                 fixEdge<SymbolUse>(searchElement);
3401             else if (searchElement->shouldSpeculateOther())
3402                 fixEdge<OtherUse>(searchElement);
3403             else if (searchElement->shouldSpeculateObject())
3404                 fixEdge<ObjectUse>(searchElement);
3405             return;
3406         }
3407         default:
3408             RELEASE_ASSERT_NOT_REACHED();
3409             return;
3410         }
3411     }
3412
3413     void fixupChecksInBlock(BasicBlock* block)
3414     {
3415         if (!block)
3416             return;
3417         ASSERT(block->isReachable);
3418         m_block = block;
3419         unsigned indexForChecks = UINT_MAX;
3420         NodeOrigin originForChecks;
3421         for (unsigned indexInBlock = 0; indexInBlock < block->size(); ++indexInBlock) {
3422             Node* node = block->at(indexInBlock);
3423
3424             // If this is a node at which we could exit, then save its index. If nodes after this one
3425             // cannot exit, then we will hoist checks to here.
3426             if (node->origin.exitOK) {
3427                 indexForChecks = indexInBlock;
3428                 originForChecks = node->origin;
3429             }
3430
3431             originForChecks = originForChecks.withSemantic(node->origin.semantic);
3432             
3433             // First, try to relax the representational demands of each node, in order to have
3434             // fewer conversions.
3435             switch (node->op()) {
3436             case MovHint:
3437             case Check:
3438                 m_graph.doToChildren(
3439                     node,
3440                     [&] (Edge& edge) {
3441                         switch (edge.useKind()) {
3442                         case DoubleRepUse:
3443                         case DoubleRepRealUse:
3444                             if (edge->hasDoubleResult())
3445                                 break;
3446             
3447                             if (edge->hasInt52Result())
3448                                 edge.setUseKind(Int52RepUse);
3449                             else if (edge.useKind() == DoubleRepUse)
3450                                 edge.setUseKind(NumberUse);
3451                             break;
3452             
3453                         case Int52RepUse:
3454                             // Nothing we can really do.
3455                             break;
3456             
3457                         case UntypedUse:
3458                         case NumberUse:
3459                             if (edge->hasDoubleResult())
3460                                 edge.setUseKind(DoubleRepUse);
3461                             else if (edge->hasInt52Result())
3462                                 edge.setUseKind(Int52RepUse);
3463                             break;
3464             
3465                         case RealNumberUse:
3466                             if (edge->hasDoubleResult())
3467                                 edge.setUseKind(DoubleRepRealUse);
3468                             else if (edge->hasInt52Result())
3469                                 edge.setUseKind(Int52RepUse);
3470                             break;
3471             
3472                         default:
3473                             break;
3474                         }
3475                     });
3476                 break;
3477                 
3478             case ValueToInt32:
3479                 if (node->child1().useKind() == DoubleRepUse
3480                     && !node->child1()->hasDoubleResult()) {
3481                     node->child1().setUseKind(NumberUse);
3482                     break;
3483                 }
3484                 break;
3485                 
3486             default:
3487                 break;
3488             }
3489
3490             // Now, insert type conversions if necessary.
3491             m_graph.doToChildren(
3492                 node,
3493                 [&] (Edge& edge) {
3494                     Node* result = nullptr;
3495
3496                     switch (edge.useKind()) {
3497                     case DoubleRepUse:
3498                     case DoubleRepRealUse:
3499                     case DoubleRepAnyIntUse: {
3500                         if (edge->hasDoubleResult())
3501                             break;
3502             
3503                         ASSERT(indexForChecks != UINT_MAX);
3504                         if (edge->isNumberConstant()) {
3505                             result = m_insertionSet.insertNode(
3506                                 indexForChecks, SpecBytecodeDouble, DoubleConstant, originForChecks,
3507                                 OpInfo(m_graph.freeze(jsDoubleNumber(edge->asNumber()))));
3508                         } else if (edge->hasInt52Result()) {
3509                             result = m_insertionSet.insertNode(
3510                                 indexForChecks, SpecAnyIntAsDouble, DoubleRep, originForChecks,
3511                                 Edge(edge.node(), Int52RepUse));
3512                         } else {
3513                             UseKind useKind;