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