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