Add support for Symbol.isConcatSpreadable (round 2)
[WebKit-https.git] / Source / JavaScriptCore / dfg / DFGFixupPhase.cpp
1 /*
2  * Copyright (C) 2012-2016 Apple Inc. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  * 1. Redistributions of source code must retain the above copyright
8  *    notice, this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright
10  *    notice, this list of conditions and the following disclaimer in the
11  *    documentation and/or other materials provided with the distribution.
12  *
13  * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
14  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
17  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
24  */
25
26 #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             fixIntConvertingEdge(node->child1());
130             node->setArithMode(Arith::Unchecked);
131             break;
132         }
133             
134         case UInt32ToNumber: {
135             fixIntConvertingEdge(node->child1());
136             if (bytecodeCanTruncateInteger(node->arithNodeFlags()))
137                 node->convertToIdentity();
138             else if (node->canSpeculateInt32(FixupPass))
139                 node->setArithMode(Arith::CheckOverflow);
140             else {
141                 node->setArithMode(Arith::DoOverflow);
142                 node->clearFlags(NodeMustGenerate);
143                 node->setResult(enableInt52() ? NodeResultInt52 : NodeResultDouble);
144             }
145             break;
146         }
147             
148         case ValueAdd: {
149             if (attemptToMakeIntegerAdd(node)) {
150                 node->setOp(ArithAdd);
151                 break;
152             }
153             if (Node::shouldSpeculateNumberOrBooleanExpectingDefined(node->child1().node(), node->child2().node())) {
154                 fixDoubleOrBooleanEdge(node->child1());
155                 fixDoubleOrBooleanEdge(node->child2());
156                 node->setOp(ArithAdd);
157                 node->setResult(NodeResultDouble);
158                 break;
159             }
160             
161             if (attemptToMakeFastStringAdd(node))
162                 break;
163
164             fixEdge<UntypedUse>(node->child1());
165             fixEdge<UntypedUse>(node->child2());
166             node->setResult(NodeResultJS);
167             break;
168         }
169
170         case StrCat: {
171             if (attemptToMakeFastStringAdd(node))
172                 break;
173
174             // FIXME: Remove empty string arguments and possibly turn this into a ToString operation. That
175             // would require a form of ToString that takes a KnownPrimitiveUse. This is necessary because
176             // the implementation of StrCat doesn't dynamically optimize for empty strings.
177             // https://bugs.webkit.org/show_bug.cgi?id=148540
178             m_graph.doToChildren(
179                 node,
180                 [&] (Edge& edge) {
181                     fixEdge<KnownPrimitiveUse>(edge);
182                 });
183             break;
184         }
185             
186         case MakeRope: {
187             fixupMakeRope(node);
188             break;
189         }
190             
191         case ArithAdd:
192         case ArithSub: {
193             if (op == ArithSub
194                 && Node::shouldSpeculateUntypedForArithmetic(node->child1().node(), node->child2().node())) {
195                 fixEdge<UntypedUse>(node->child1());
196                 fixEdge<UntypedUse>(node->child2());
197                 node->setResult(NodeResultJS);
198                 break;
199             }
200             if (attemptToMakeIntegerAdd(node))
201                 break;
202             fixDoubleOrBooleanEdge(node->child1());
203             fixDoubleOrBooleanEdge(node->child2());
204             node->setResult(NodeResultDouble);
205             break;
206         }
207             
208         case ArithNegate: {
209             if (m_graph.unaryArithShouldSpeculateInt32(node, FixupPass)) {
210                 fixIntOrBooleanEdge(node->child1());
211                 if (bytecodeCanTruncateInteger(node->arithNodeFlags()))
212                     node->setArithMode(Arith::Unchecked);
213                 else if (bytecodeCanIgnoreNegativeZero(node->arithNodeFlags()))
214                     node->setArithMode(Arith::CheckOverflow);
215                 else
216                     node->setArithMode(Arith::CheckOverflowAndNegativeZero);
217                 break;
218             }
219             if (m_graph.unaryArithShouldSpeculateAnyInt(node, FixupPass)) {
220                 fixEdge<Int52RepUse>(node->child1());
221                 if (bytecodeCanIgnoreNegativeZero(node->arithNodeFlags()))
222                     node->setArithMode(Arith::CheckOverflow);
223                 else
224                     node->setArithMode(Arith::CheckOverflowAndNegativeZero);
225                 node->setResult(NodeResultInt52);
226                 break;
227             }
228             fixDoubleOrBooleanEdge(node->child1());
229             node->setResult(NodeResultDouble);
230             break;
231         }
232             
233         case ArithMul: {
234             Edge& leftChild = node->child1();
235             Edge& rightChild = node->child2();
236             if (Node::shouldSpeculateUntypedForArithmetic(leftChild.node(), rightChild.node())) {
237                 fixEdge<UntypedUse>(leftChild);
238                 fixEdge<UntypedUse>(rightChild);
239                 node->setResult(NodeResultJS);
240                 break;
241             }
242             if (m_graph.binaryArithShouldSpeculateInt32(node, FixupPass)) {
243                 fixIntOrBooleanEdge(leftChild);
244                 fixIntOrBooleanEdge(rightChild);
245                 if (bytecodeCanTruncateInteger(node->arithNodeFlags()))
246                     node->setArithMode(Arith::Unchecked);
247                 else if (bytecodeCanIgnoreNegativeZero(node->arithNodeFlags())
248                     || leftChild.node() == rightChild.node())
249                     node->setArithMode(Arith::CheckOverflow);
250                 else
251                     node->setArithMode(Arith::CheckOverflowAndNegativeZero);
252                 break;
253             }
254             if (m_graph.binaryArithShouldSpeculateAnyInt(node, FixupPass)) {
255                 fixEdge<Int52RepUse>(leftChild);
256                 fixEdge<Int52RepUse>(rightChild);
257                 if (bytecodeCanIgnoreNegativeZero(node->arithNodeFlags())
258                     || leftChild.node() == rightChild.node())
259                     node->setArithMode(Arith::CheckOverflow);
260                 else
261                     node->setArithMode(Arith::CheckOverflowAndNegativeZero);
262                 node->setResult(NodeResultInt52);
263                 break;
264             }
265             fixDoubleOrBooleanEdge(leftChild);
266             fixDoubleOrBooleanEdge(rightChild);
267             node->setResult(NodeResultDouble);
268             break;
269         }
270
271         case ArithDiv:
272         case ArithMod: {
273             Edge& leftChild = node->child1();
274             Edge& rightChild = node->child2();
275             if (op == ArithDiv
276                 && Node::shouldSpeculateUntypedForArithmetic(leftChild.node(), rightChild.node())
277                 && m_graph.hasExitSite(node->origin.semantic, BadType)) {
278                 fixEdge<UntypedUse>(leftChild);
279                 fixEdge<UntypedUse>(rightChild);
280                 node->setResult(NodeResultJS);
281                 break;
282             }
283             if (m_graph.binaryArithShouldSpeculateInt32(node, FixupPass)) {
284                 if (optimizeForX86() || optimizeForARM64() || optimizeForARMv7IDIVSupported()) {
285                     fixIntOrBooleanEdge(leftChild);
286                     fixIntOrBooleanEdge(rightChild);
287                     if (bytecodeCanTruncateInteger(node->arithNodeFlags()))
288                         node->setArithMode(Arith::Unchecked);
289                     else if (bytecodeCanIgnoreNegativeZero(node->arithNodeFlags()))
290                         node->setArithMode(Arith::CheckOverflow);
291                     else
292                         node->setArithMode(Arith::CheckOverflowAndNegativeZero);
293                     break;
294                 }
295                 
296                 // This will cause conversion nodes to be inserted later.
297                 fixDoubleOrBooleanEdge(leftChild);
298                 fixDoubleOrBooleanEdge(rightChild);
299                 
300                 // We don't need to do ref'ing on the children because we're stealing them from
301                 // the original division.
302                 Node* newDivision = m_insertionSet.insertNode(
303                     m_indexInBlock, SpecBytecodeDouble, *node);
304                 newDivision->setResult(NodeResultDouble);
305                 
306                 node->setOp(DoubleAsInt32);
307                 node->children.initialize(Edge(newDivision, DoubleRepUse), Edge(), Edge());
308                 if (bytecodeCanIgnoreNegativeZero(node->arithNodeFlags()))
309                     node->setArithMode(Arith::CheckOverflow);
310                 else
311                     node->setArithMode(Arith::CheckOverflowAndNegativeZero);
312                 break;
313             }
314             fixDoubleOrBooleanEdge(leftChild);
315             fixDoubleOrBooleanEdge(rightChild);
316             node->setResult(NodeResultDouble);
317             break;
318         }
319             
320         case ArithMin:
321         case ArithMax: {
322             if (m_graph.binaryArithShouldSpeculateInt32(node, FixupPass)) {
323                 fixIntOrBooleanEdge(node->child1());
324                 fixIntOrBooleanEdge(node->child2());
325                 break;
326             }
327             fixDoubleOrBooleanEdge(node->child1());
328             fixDoubleOrBooleanEdge(node->child2());
329             node->setResult(NodeResultDouble);
330             break;
331         }
332             
333         case ArithAbs: {
334             if (m_graph.unaryArithShouldSpeculateInt32(node, FixupPass)) {
335                 fixIntOrBooleanEdge(node->child1());
336                 if (bytecodeCanTruncateInteger(node->arithNodeFlags()))
337                     node->setArithMode(Arith::Unchecked);
338                 else
339                     node->setArithMode(Arith::CheckOverflow);
340                 break;
341             }
342             fixDoubleOrBooleanEdge(node->child1());
343             node->setResult(NodeResultDouble);
344             break;
345         }
346
347         case ArithPow: {
348             if (node->child2()->shouldSpeculateInt32OrBooleanForArithmetic()) {
349                 fixDoubleOrBooleanEdge(node->child1());
350                 fixIntOrBooleanEdge(node->child2());
351                 break;
352             }
353
354             fixDoubleOrBooleanEdge(node->child1());
355             fixDoubleOrBooleanEdge(node->child2());
356             break;
357         }
358
359         case ArithRandom: {
360             node->setResult(NodeResultDouble);
361             break;
362         }
363
364         case ArithRound:
365         case ArithFloor:
366         case ArithCeil:
367         case ArithTrunc: {
368             if (m_graph.unaryArithShouldSpeculateInt32(node, FixupPass)) {
369                 fixIntOrBooleanEdge(node->child1());
370                 insertCheck<Int32Use>(m_indexInBlock, node->child1().node());
371                 node->convertToIdentity();
372                 break;
373             }
374             fixDoubleOrBooleanEdge(node->child1());
375
376             if (isInt32OrBooleanSpeculation(node->getHeapPrediction()) && m_graph.roundShouldSpeculateInt32(node, FixupPass)) {
377                 node->setResult(NodeResultInt32);
378                 if (bytecodeCanIgnoreNegativeZero(node->arithNodeFlags()))
379                     node->setArithRoundingMode(Arith::RoundingMode::Int32);
380                 else
381                     node->setArithRoundingMode(Arith::RoundingMode::Int32WithNegativeZeroCheck);
382             } else {
383                 node->setResult(NodeResultDouble);
384                 node->setArithRoundingMode(Arith::RoundingMode::Double);
385             }
386             break;
387         }
388             
389         case ArithSqrt:
390         case ArithFRound:
391         case ArithSin:
392         case ArithCos:
393         case ArithLog: {
394             fixDoubleOrBooleanEdge(node->child1());
395             node->setResult(NodeResultDouble);
396             break;
397         }
398             
399         case LogicalNot: {
400             if (node->child1()->shouldSpeculateBoolean()) {
401                 if (node->child1()->result() == NodeResultBoolean) {
402                     // This is necessary in case we have a bytecode instruction implemented by:
403                     //
404                     // a: CompareEq(...)
405                     // b: LogicalNot(@a)
406                     //
407                     // In that case, CompareEq might have a side-effect. Then, we need to make
408                     // sure that we know that Branch does not exit.
409                     fixEdge<KnownBooleanUse>(node->child1());
410                 } else
411                     fixEdge<BooleanUse>(node->child1());
412             } else if (node->child1()->shouldSpeculateObjectOrOther())
413                 fixEdge<ObjectOrOtherUse>(node->child1());
414             else if (node->child1()->shouldSpeculateInt32OrBoolean())
415                 fixIntOrBooleanEdge(node->child1());
416             else if (node->child1()->shouldSpeculateNumber())
417                 fixEdge<DoubleRepUse>(node->child1());
418             else if (node->child1()->shouldSpeculateString())
419                 fixEdge<StringUse>(node->child1());
420             else if (node->child1()->shouldSpeculateStringOrOther())
421                 fixEdge<StringOrOtherUse>(node->child1());
422             break;
423         }
424
425         case CompareEq:
426         case CompareLess:
427         case CompareLessEq:
428         case CompareGreater:
429         case CompareGreaterEq: {
430             if (node->op() == CompareEq
431                 && Node::shouldSpeculateBoolean(node->child1().node(), node->child2().node())) {
432                 fixEdge<BooleanUse>(node->child1());
433                 fixEdge<BooleanUse>(node->child2());
434                 node->clearFlags(NodeMustGenerate);
435                 break;
436             }
437             if (Node::shouldSpeculateInt32OrBoolean(node->child1().node(), node->child2().node())) {
438                 fixIntOrBooleanEdge(node->child1());
439                 fixIntOrBooleanEdge(node->child2());
440                 node->clearFlags(NodeMustGenerate);
441                 break;
442             }
443             if (enableInt52()
444                 && Node::shouldSpeculateAnyInt(node->child1().node(), node->child2().node())) {
445                 fixEdge<Int52RepUse>(node->child1());
446                 fixEdge<Int52RepUse>(node->child2());
447                 node->clearFlags(NodeMustGenerate);
448                 break;
449             }
450             if (Node::shouldSpeculateNumberOrBoolean(node->child1().node(), node->child2().node())) {
451                 fixDoubleOrBooleanEdge(node->child1());
452                 fixDoubleOrBooleanEdge(node->child2());
453             }
454             if (node->op() != CompareEq
455                 && node->child1()->shouldSpeculateNotCell()
456                 && node->child2()->shouldSpeculateNotCell()) {
457                 if (node->child1()->shouldSpeculateNumberOrBoolean())
458                     fixDoubleOrBooleanEdge(node->child1());
459                 else
460                     fixEdge<DoubleRepUse>(node->child1());
461                 if (node->child2()->shouldSpeculateNumberOrBoolean())
462                     fixDoubleOrBooleanEdge(node->child2());
463                 else
464                     fixEdge<DoubleRepUse>(node->child2());
465                 node->clearFlags(NodeMustGenerate);
466                 break;
467             }
468             if (node->child1()->shouldSpeculateStringIdent() && node->child2()->shouldSpeculateStringIdent()) {
469                 fixEdge<StringIdentUse>(node->child1());
470                 fixEdge<StringIdentUse>(node->child2());
471                 node->clearFlags(NodeMustGenerate);
472                 break;
473             }
474             if (node->child1()->shouldSpeculateString() && node->child2()->shouldSpeculateString() && GPRInfo::numberOfRegisters >= 7) {
475                 fixEdge<StringUse>(node->child1());
476                 fixEdge<StringUse>(node->child2());
477                 node->clearFlags(NodeMustGenerate);
478                 break;
479             }
480
481             if (node->op() != CompareEq)
482                 break;
483             if (Node::shouldSpeculateSymbol(node->child1().node(), node->child2().node())) {
484                 fixEdge<SymbolUse>(node->child1());
485                 fixEdge<SymbolUse>(node->child2());
486                 node->clearFlags(NodeMustGenerate);
487                 break;
488             }
489             if (node->child1()->shouldSpeculateObject() && node->child2()->shouldSpeculateObject()) {
490                 fixEdge<ObjectUse>(node->child1());
491                 fixEdge<ObjectUse>(node->child2());
492                 node->clearFlags(NodeMustGenerate);
493                 break;
494             }
495
496             // If either child can be proved to be Null or Undefined, comparing them is greatly simplified.
497             bool oneArgumentIsUsedAsSpecOther = false;
498             if (node->child1()->isUndefinedOrNullConstant()) {
499                 fixEdge<OtherUse>(node->child1());
500                 oneArgumentIsUsedAsSpecOther = true;
501             } else if (node->child1()->shouldSpeculateOther()) {
502                 m_insertionSet.insertNode(m_indexInBlock, SpecNone, Check, node->origin,
503                     Edge(node->child1().node(), OtherUse));
504                 fixEdge<OtherUse>(node->child1());
505                 oneArgumentIsUsedAsSpecOther = true;
506             }
507             if (node->child2()->isUndefinedOrNullConstant()) {
508                 fixEdge<OtherUse>(node->child2());
509                 oneArgumentIsUsedAsSpecOther = true;
510             } else if (node->child2()->shouldSpeculateOther()) {
511                 m_insertionSet.insertNode(m_indexInBlock, SpecNone, Check, node->origin,
512                     Edge(node->child2().node(), OtherUse));
513                 fixEdge<OtherUse>(node->child2());
514                 oneArgumentIsUsedAsSpecOther = true;
515             }
516             if (oneArgumentIsUsedAsSpecOther) {
517                 node->clearFlags(NodeMustGenerate);
518                 break;
519             }
520
521             if (node->child1()->shouldSpeculateObject() && node->child2()->shouldSpeculateObjectOrOther()) {
522                 fixEdge<ObjectUse>(node->child1());
523                 fixEdge<ObjectOrOtherUse>(node->child2());
524                 node->clearFlags(NodeMustGenerate);
525                 break;
526             }
527             if (node->child1()->shouldSpeculateObjectOrOther() && node->child2()->shouldSpeculateObject()) {
528                 fixEdge<ObjectOrOtherUse>(node->child1());
529                 fixEdge<ObjectUse>(node->child2());
530                 node->clearFlags(NodeMustGenerate);
531                 break;
532             }
533
534             break;
535         }
536             
537         case CompareStrictEq: {
538             if (Node::shouldSpeculateBoolean(node->child1().node(), node->child2().node())) {
539                 fixEdge<BooleanUse>(node->child1());
540                 fixEdge<BooleanUse>(node->child2());
541                 break;
542             }
543             if (Node::shouldSpeculateInt32(node->child1().node(), node->child2().node())) {
544                 fixEdge<Int32Use>(node->child1());
545                 fixEdge<Int32Use>(node->child2());
546                 break;
547             }
548             if (enableInt52()
549                 && Node::shouldSpeculateAnyInt(node->child1().node(), node->child2().node())) {
550                 fixEdge<Int52RepUse>(node->child1());
551                 fixEdge<Int52RepUse>(node->child2());
552                 break;
553             }
554             if (Node::shouldSpeculateNumber(node->child1().node(), node->child2().node())) {
555                 fixEdge<DoubleRepUse>(node->child1());
556                 fixEdge<DoubleRepUse>(node->child2());
557                 break;
558             }
559             if (Node::shouldSpeculateSymbol(node->child1().node(), node->child2().node())) {
560                 fixEdge<SymbolUse>(node->child1());
561                 fixEdge<SymbolUse>(node->child2());
562                 break;
563             }
564             if (node->child1()->shouldSpeculateStringIdent() && node->child2()->shouldSpeculateStringIdent()) {
565                 fixEdge<StringIdentUse>(node->child1());
566                 fixEdge<StringIdentUse>(node->child2());
567                 break;
568             }
569             if (node->child1()->shouldSpeculateString() && node->child2()->shouldSpeculateString() && ((GPRInfo::numberOfRegisters >= 7) || isFTL(m_graph.m_plan.mode))) {
570                 fixEdge<StringUse>(node->child1());
571                 fixEdge<StringUse>(node->child2());
572                 break;
573             }
574             WatchpointSet* masqueradesAsUndefinedWatchpoint = m_graph.globalObjectFor(node->origin.semantic)->masqueradesAsUndefinedWatchpoint();
575             if (masqueradesAsUndefinedWatchpoint->isStillValid()) {
576                 
577                 if (node->child1()->shouldSpeculateObject()) {
578                     m_graph.watchpoints().addLazily(masqueradesAsUndefinedWatchpoint);
579                     fixEdge<ObjectUse>(node->child1());
580                     break;
581                 }
582                 if (node->child2()->shouldSpeculateObject()) {
583                     m_graph.watchpoints().addLazily(masqueradesAsUndefinedWatchpoint);
584                     fixEdge<ObjectUse>(node->child2());
585                     break;
586                 }
587                 
588             } else if (node->child1()->shouldSpeculateObject() && node->child2()->shouldSpeculateObject()) {
589                 fixEdge<ObjectUse>(node->child1());
590                 fixEdge<ObjectUse>(node->child2());
591                 break;
592             }
593             if (node->child1()->shouldSpeculateMisc()) {
594                 fixEdge<MiscUse>(node->child1());
595                 break;
596             }
597             if (node->child2()->shouldSpeculateMisc()) {
598                 fixEdge<MiscUse>(node->child2());
599                 break;
600             }
601             if (node->child1()->shouldSpeculateStringIdent()
602                 && node->child2()->shouldSpeculateNotStringVar()) {
603                 fixEdge<StringIdentUse>(node->child1());
604                 fixEdge<NotStringVarUse>(node->child2());
605                 break;
606             }
607             if (node->child2()->shouldSpeculateStringIdent()
608                 && node->child1()->shouldSpeculateNotStringVar()) {
609                 fixEdge<StringIdentUse>(node->child2());
610                 fixEdge<NotStringVarUse>(node->child1());
611                 break;
612             }
613             if (node->child1()->shouldSpeculateString() && ((GPRInfo::numberOfRegisters >= 8) || isFTL(m_graph.m_plan.mode))) {
614                 fixEdge<StringUse>(node->child1());
615                 break;
616             }
617             if (node->child2()->shouldSpeculateString() && ((GPRInfo::numberOfRegisters >= 8) || isFTL(m_graph.m_plan.mode))) {
618                 fixEdge<StringUse>(node->child2());
619                 break;
620             }
621             break;
622         }
623
624         case StringFromCharCode:
625             if (node->child1()->shouldSpeculateInt32())
626                 fixEdge<Int32Use>(node->child1());
627             else
628                 fixEdge<UntypedUse>(node->child1());
629             break;
630
631         case StringCharAt:
632         case StringCharCodeAt: {
633             // Currently we have no good way of refining these.
634             ASSERT(node->arrayMode() == ArrayMode(Array::String));
635             blessArrayOperation(node->child1(), node->child2(), node->child3());
636             fixEdge<KnownCellUse>(node->child1());
637             fixEdge<Int32Use>(node->child2());
638             break;
639         }
640
641         case GetByVal: {
642             if (!node->prediction()) {
643                 m_insertionSet.insertNode(
644                     m_indexInBlock, SpecNone, ForceOSRExit, node->origin);
645             }
646             
647             node->setArrayMode(
648                 node->arrayMode().refine(
649                     m_graph, node,
650                     node->child1()->prediction(),
651                     node->child2()->prediction(),
652                     SpecNone));
653             
654             blessArrayOperation(node->child1(), node->child2(), node->child3());
655             
656             ArrayMode arrayMode = node->arrayMode();
657             switch (arrayMode.type()) {
658             case Array::Contiguous:
659             case Array::Double:
660                 if (arrayMode.arrayClass() == Array::OriginalArray
661                     && arrayMode.speculation() == Array::InBounds) {
662                     JSGlobalObject* globalObject = m_graph.globalObjectFor(node->origin.semantic);
663                     if (globalObject->arrayPrototypeChainIsSane()) {
664                         // Check if SaneChain will work on a per-type basis. Note that:
665                         //
666                         // 1) We don't want double arrays to sometimes return undefined, since
667                         // that would require a change to the return type and it would pessimise
668                         // things a lot. So, we'd only want to do that if we actually had
669                         // evidence that we could read from a hole. That's pretty annoying.
670                         // Likely the best way to handle that case is with an equivalent of
671                         // SaneChain for OutOfBounds. For now we just detect when Undefined and
672                         // NaN are indistinguishable according to backwards propagation, and just
673                         // use SaneChain in that case. This happens to catch a lot of cases.
674                         //
675                         // 2) We don't want int32 array loads to have to do a hole check just to
676                         // coerce to Undefined, since that would mean twice the checks.
677                         //
678                         // This has two implications. First, we have to do more checks than we'd
679                         // like. It's unfortunate that we have to do the hole check. Second,
680                         // some accesses that hit a hole will now need to take the full-blown
681                         // out-of-bounds slow path. We can fix that with:
682                         // https://bugs.webkit.org/show_bug.cgi?id=144668
683                         
684                         bool canDoSaneChain = false;
685                         switch (arrayMode.type()) {
686                         case Array::Contiguous:
687                             // This is happens to be entirely natural. We already would have
688                             // returned any JSValue, and now we'll return Undefined. We still do
689                             // the check but it doesn't require taking any kind of slow path.
690                             canDoSaneChain = true;
691                             break;
692                             
693                         case Array::Double:
694                             if (!(node->flags() & NodeBytecodeUsesAsOther)) {
695                                 // Holes look like NaN already, so if the user doesn't care
696                                 // about the difference between Undefined and NaN then we can
697                                 // do this.
698                                 canDoSaneChain = true;
699                             }
700                             break;
701                             
702                         default:
703                             break;
704                         }
705                         
706                         if (canDoSaneChain) {
707                             m_graph.watchpoints().addLazily(
708                                 globalObject->arrayPrototype()->structure()->transitionWatchpointSet());
709                             m_graph.watchpoints().addLazily(
710                                 globalObject->objectPrototype()->structure()->transitionWatchpointSet());
711                             if (globalObject->arrayPrototypeChainIsSane())
712                                 node->setArrayMode(arrayMode.withSpeculation(Array::SaneChain));
713                         }
714                     }
715                 }
716                 break;
717                 
718             case Array::String:
719                 if ((node->prediction() & ~SpecString)
720                     || m_graph.hasExitSite(node->origin.semantic, OutOfBounds))
721                     node->setArrayMode(arrayMode.withSpeculation(Array::OutOfBounds));
722                 break;
723                 
724             default:
725                 break;
726             }
727             
728             arrayMode = node->arrayMode();
729             switch (arrayMode.type()) {
730             case Array::SelectUsingPredictions:
731             case Array::Unprofiled:
732                 RELEASE_ASSERT_NOT_REACHED();
733                 break;
734             case Array::Generic:
735 #if USE(JSVALUE32_64)
736                 fixEdge<CellUse>(node->child1()); // Speculating cell due to register pressure on 32-bit.
737 #endif
738                 break;
739             case Array::ForceExit:
740                 break;
741             default:
742                 fixEdge<KnownCellUse>(node->child1());
743                 fixEdge<Int32Use>(node->child2());
744                 break;
745             }
746             
747             switch (arrayMode.type()) {
748             case Array::Double:
749                 if (!arrayMode.isOutOfBounds())
750                     node->setResult(NodeResultDouble);
751                 break;
752                 
753             case Array::Float32Array:
754             case Array::Float64Array:
755                 node->setResult(NodeResultDouble);
756                 break;
757                 
758             case Array::Uint32Array:
759                 if (node->shouldSpeculateInt32())
760                     break;
761                 if (node->shouldSpeculateAnyInt() && enableInt52())
762                     node->setResult(NodeResultInt52);
763                 else
764                     node->setResult(NodeResultDouble);
765                 break;
766                 
767             default:
768                 break;
769             }
770             
771             break;
772         }
773
774         case PutByValDirect:
775         case PutByVal:
776         case PutByValAlias: {
777             Edge& child1 = m_graph.varArgChild(node, 0);
778             Edge& child2 = m_graph.varArgChild(node, 1);
779             Edge& child3 = m_graph.varArgChild(node, 2);
780
781             node->setArrayMode(
782                 node->arrayMode().refine(
783                     m_graph, node,
784                     child1->prediction(),
785                     child2->prediction(),
786                     child3->prediction()));
787             
788             blessArrayOperation(child1, child2, m_graph.varArgChild(node, 3));
789             
790             switch (node->arrayMode().modeForPut().type()) {
791             case Array::SelectUsingPredictions:
792             case Array::SelectUsingArguments:
793             case Array::Unprofiled:
794             case Array::Undecided:
795                 RELEASE_ASSERT_NOT_REACHED();
796                 break;
797             case Array::ForceExit:
798             case Array::Generic:
799 #if USE(JSVALUE32_64)
800                 // Due to register pressure on 32-bit, we speculate cell and
801                 // ignore the base-is-not-cell case entirely by letting the
802                 // baseline JIT handle it.
803                 fixEdge<CellUse>(child1);
804 #endif
805                 break;
806             case Array::Int32:
807                 fixEdge<KnownCellUse>(child1);
808                 fixEdge<Int32Use>(child2);
809                 fixEdge<Int32Use>(child3);
810                 break;
811             case Array::Double:
812                 fixEdge<KnownCellUse>(child1);
813                 fixEdge<Int32Use>(child2);
814                 fixEdge<DoubleRepRealUse>(child3);
815                 break;
816             case Array::Int8Array:
817             case Array::Int16Array:
818             case Array::Int32Array:
819             case Array::Uint8Array:
820             case Array::Uint8ClampedArray:
821             case Array::Uint16Array:
822             case Array::Uint32Array:
823                 fixEdge<KnownCellUse>(child1);
824                 fixEdge<Int32Use>(child2);
825                 if (child3->shouldSpeculateInt32())
826                     fixIntOrBooleanEdge(child3);
827                 else if (child3->shouldSpeculateAnyInt())
828                     fixEdge<Int52RepUse>(child3);
829                 else
830                     fixDoubleOrBooleanEdge(child3);
831                 break;
832             case Array::Float32Array:
833             case Array::Float64Array:
834                 fixEdge<KnownCellUse>(child1);
835                 fixEdge<Int32Use>(child2);
836                 fixDoubleOrBooleanEdge(child3);
837                 break;
838             case Array::Contiguous:
839             case Array::ArrayStorage:
840             case Array::SlowPutArrayStorage:
841                 fixEdge<KnownCellUse>(child1);
842                 fixEdge<Int32Use>(child2);
843                 speculateForBarrier(child3);
844                 break;
845             default:
846                 fixEdge<KnownCellUse>(child1);
847                 fixEdge<Int32Use>(child2);
848                 break;
849             }
850             break;
851         }
852             
853         case ArrayPush: {
854             // May need to refine the array mode in case the value prediction contravenes
855             // the array prediction. For example, we may have evidence showing that the
856             // array is in Int32 mode, but the value we're storing is likely to be a double.
857             // Then we should turn this into a conversion to Double array followed by the
858             // push. On the other hand, we absolutely don't want to refine based on the
859             // base prediction. If it has non-cell garbage in it, then we want that to be
860             // ignored. That's because ArrayPush can't handle any array modes that aren't
861             // array-related - so if refine() turned this into a "Generic" ArrayPush then
862             // that would break things.
863             node->setArrayMode(
864                 node->arrayMode().refine(
865                     m_graph, node,
866                     node->child1()->prediction() & SpecCell,
867                     SpecInt32Only,
868                     node->child2()->prediction()));
869             blessArrayOperation(node->child1(), Edge(), node->child3());
870             fixEdge<KnownCellUse>(node->child1());
871             
872             switch (node->arrayMode().type()) {
873             case Array::Int32:
874                 fixEdge<Int32Use>(node->child2());
875                 break;
876             case Array::Double:
877                 fixEdge<DoubleRepRealUse>(node->child2());
878                 break;
879             case Array::Contiguous:
880             case Array::ArrayStorage:
881                 speculateForBarrier(node->child2());
882                 break;
883             default:
884                 break;
885             }
886             break;
887         }
888             
889         case ArrayPop: {
890             blessArrayOperation(node->child1(), Edge(), node->child2());
891             fixEdge<KnownCellUse>(node->child1());
892             break;
893         }
894             
895         case RegExpExec:
896         case RegExpTest: {
897             fixEdge<KnownCellUse>(node->child1());
898             
899             if (node->child2()->shouldSpeculateRegExpObject()) {
900                 fixEdge<RegExpObjectUse>(node->child2());
901
902                 if (node->child3()->shouldSpeculateString())
903                     fixEdge<StringUse>(node->child3());
904             }
905             break;
906         }
907
908         case StringReplace:
909         case StringReplaceRegExp: {
910             if (node->child2()->shouldSpeculateString()) {
911                 m_insertionSet.insertNode(
912                     m_indexInBlock, SpecNone, Check, node->origin,
913                     Edge(node->child2().node(), StringUse));
914                 fixEdge<StringUse>(node->child2());
915             } else if (op == StringReplace) {
916                 if (node->child2()->shouldSpeculateRegExpObject())
917                     addStringReplacePrimordialChecks(node->child2().node());
918                 else 
919                     m_insertionSet.insertNode(
920                         m_indexInBlock, SpecNone, ForceOSRExit, node->origin);
921             }
922
923             if (node->child1()->shouldSpeculateString()
924                 && node->child2()->shouldSpeculateRegExpObject()
925                 && node->child3()->shouldSpeculateString()) {
926
927                 fixEdge<StringUse>(node->child1());
928                 fixEdge<RegExpObjectUse>(node->child2());
929                 fixEdge<StringUse>(node->child3());
930                 break;
931             }
932             break;
933         }
934             
935         case Branch: {
936             if (node->child1()->shouldSpeculateBoolean()) {
937                 if (node->child1()->result() == NodeResultBoolean) {
938                     // This is necessary in case we have a bytecode instruction implemented by:
939                     //
940                     // a: CompareEq(...)
941                     // b: Branch(@a)
942                     //
943                     // In that case, CompareEq might have a side-effect. Then, we need to make
944                     // sure that we know that Branch does not exit.
945                     fixEdge<KnownBooleanUse>(node->child1());
946                 } else
947                     fixEdge<BooleanUse>(node->child1());
948             } else if (node->child1()->shouldSpeculateObjectOrOther())
949                 fixEdge<ObjectOrOtherUse>(node->child1());
950             else if (node->child1()->shouldSpeculateInt32OrBoolean())
951                 fixIntOrBooleanEdge(node->child1());
952             else if (node->child1()->shouldSpeculateNumber())
953                 fixEdge<DoubleRepUse>(node->child1());
954             else if (node->child1()->shouldSpeculateString())
955                 fixEdge<StringUse>(node->child1());
956             else if (node->child1()->shouldSpeculateStringOrOther())
957                 fixEdge<StringOrOtherUse>(node->child1());
958             break;
959         }
960             
961         case Switch: {
962             SwitchData* data = node->switchData();
963             switch (data->kind) {
964             case SwitchImm:
965                 if (node->child1()->shouldSpeculateInt32())
966                     fixEdge<Int32Use>(node->child1());
967                 break;
968             case SwitchChar:
969                 if (node->child1()->shouldSpeculateString())
970                     fixEdge<StringUse>(node->child1());
971                 break;
972             case SwitchString:
973                 if (node->child1()->shouldSpeculateStringIdent())
974                     fixEdge<StringIdentUse>(node->child1());
975                 else if (node->child1()->shouldSpeculateString())
976                     fixEdge<StringUse>(node->child1());
977                 break;
978             case SwitchCell:
979                 if (node->child1()->shouldSpeculateCell())
980                     fixEdge<CellUse>(node->child1());
981                 // else it's fine for this to have UntypedUse; we will handle this by just making
982                 // non-cells take the default case.
983                 break;
984             }
985             break;
986         }
987             
988         case ToPrimitive: {
989             fixupToPrimitive(node);
990             break;
991         }
992             
993         case ToString:
994         case CallStringConstructor: {
995             fixupToStringOrCallStringConstructor(node);
996             break;
997         }
998             
999         case NewStringObject: {
1000             fixEdge<KnownStringUse>(node->child1());
1001             break;
1002         }
1003             
1004         case NewArray: {
1005             watchHavingABadTime(node);
1006             
1007             for (unsigned i = m_graph.varArgNumChildren(node); i--;) {
1008                 node->setIndexingType(
1009                     leastUpperBoundOfIndexingTypeAndType(
1010                         node->indexingType(), m_graph.varArgChild(node, i)->prediction()));
1011             }
1012             switch (node->indexingType()) {
1013             case ALL_BLANK_INDEXING_TYPES:
1014                 CRASH();
1015                 break;
1016             case ALL_UNDECIDED_INDEXING_TYPES:
1017                 if (node->numChildren()) {
1018                     // This will only happen if the children have no type predictions. We
1019                     // would have already exited by now, but insert a forced exit just to
1020                     // be safe.
1021                     m_insertionSet.insertNode(
1022                         m_indexInBlock, SpecNone, ForceOSRExit, node->origin);
1023                 }
1024                 break;
1025             case ALL_INT32_INDEXING_TYPES:
1026                 for (unsigned operandIndex = 0; operandIndex < node->numChildren(); ++operandIndex)
1027                     fixEdge<Int32Use>(m_graph.m_varArgChildren[node->firstChild() + operandIndex]);
1028                 break;
1029             case ALL_DOUBLE_INDEXING_TYPES:
1030                 for (unsigned operandIndex = 0; operandIndex < node->numChildren(); ++operandIndex)
1031                     fixEdge<DoubleRepRealUse>(m_graph.m_varArgChildren[node->firstChild() + operandIndex]);
1032                 break;
1033             case ALL_CONTIGUOUS_INDEXING_TYPES:
1034             case ALL_ARRAY_STORAGE_INDEXING_TYPES:
1035                 break;
1036             default:
1037                 CRASH();
1038                 break;
1039             }
1040             break;
1041         }
1042             
1043         case NewTypedArray: {
1044             watchHavingABadTime(node);
1045             
1046             if (node->child1()->shouldSpeculateInt32()) {
1047                 fixEdge<Int32Use>(node->child1());
1048                 node->clearFlags(NodeMustGenerate);
1049                 break;
1050             }
1051             break;
1052         }
1053             
1054         case NewArrayWithSize: {
1055             watchHavingABadTime(node);
1056             fixEdge<Int32Use>(node->child1());
1057             break;
1058         }
1059
1060         case CallObjectConstructor: {
1061             if (node->child1()->shouldSpeculateObject()) {
1062                 fixEdge<ObjectUse>(node->child1());
1063                 node->convertToIdentity();
1064                 break;
1065             }
1066
1067             fixEdge<UntypedUse>(node->child1());
1068             break;
1069         }
1070
1071         case ToThis: {
1072             fixupToThis(node);
1073             break;
1074         }
1075             
1076         case PutStructure: {
1077             fixEdge<KnownCellUse>(node->child1());
1078             break;
1079         }
1080             
1081         case GetClosureVar:
1082         case GetFromArguments: {
1083             fixEdge<KnownCellUse>(node->child1());
1084             break;
1085         }
1086
1087         case PutClosureVar:
1088         case PutToArguments: {
1089             fixEdge<KnownCellUse>(node->child1());
1090             speculateForBarrier(node->child2());
1091             break;
1092         }
1093
1094         case SkipScope:
1095         case GetScope:
1096         case GetGetter:
1097         case GetSetter:
1098         case GetGlobalObject: {
1099             fixEdge<KnownCellUse>(node->child1());
1100             break;
1101         }
1102             
1103         case AllocatePropertyStorage:
1104         case ReallocatePropertyStorage: {
1105             fixEdge<KnownCellUse>(node->child1());
1106             break;
1107         }
1108
1109         case TryGetById: {
1110             if (node->child1()->shouldSpeculateCell())
1111                 fixEdge<CellUse>(node->child1());
1112             break;
1113         }
1114
1115         case GetById:
1116         case GetByIdFlush: {
1117             // FIXME: This should be done in the ByteCodeParser based on reading the
1118             // PolymorphicAccess, which will surely tell us that this is a AccessCase::ArrayLength.
1119             // https://bugs.webkit.org/show_bug.cgi?id=154990
1120             if (node->child1()->shouldSpeculateCellOrOther()
1121                 && !m_graph.hasExitSite(node->origin.semantic, BadType)
1122                 && !m_graph.hasExitSite(node->origin.semantic, BadCache)
1123                 && !m_graph.hasExitSite(node->origin.semantic, BadIndexingType)
1124                 && !m_graph.hasExitSite(node->origin.semantic, ExoticObjectMode)) {
1125                 
1126                 auto uid = m_graph.identifiers()[node->identifierNumber()];
1127                 
1128                 if (uid == vm().propertyNames->length.impl()) {
1129                     attemptToMakeGetArrayLength(node);
1130                     break;
1131                 }
1132
1133                 if (uid == vm().propertyNames->lastIndex.impl()
1134                     && node->child1()->shouldSpeculateRegExpObject()) {
1135                     node->setOp(GetRegExpObjectLastIndex);
1136                     node->clearFlags(NodeMustGenerate);
1137                     fixEdge<RegExpObjectUse>(node->child1());
1138                     break;
1139                 }
1140             }
1141
1142             if (node->child1()->shouldSpeculateCell())
1143                 fixEdge<CellUse>(node->child1());
1144             break;
1145         }
1146
1147         case PutById:
1148         case PutByIdFlush:
1149         case PutByIdDirect: {
1150             if (node->child1()->shouldSpeculateCellOrOther()
1151                 && !m_graph.hasExitSite(node->origin.semantic, BadType)
1152                 && !m_graph.hasExitSite(node->origin.semantic, BadCache)
1153                 && !m_graph.hasExitSite(node->origin.semantic, BadIndexingType)
1154                 && !m_graph.hasExitSite(node->origin.semantic, ExoticObjectMode)) {
1155                 
1156                 auto uid = m_graph.identifiers()[node->identifierNumber()];
1157                 
1158                 if (uid == vm().propertyNames->lastIndex.impl()
1159                     && node->child1()->shouldSpeculateRegExpObject()) {
1160                     node->setOp(SetRegExpObjectLastIndex);
1161                     fixEdge<RegExpObjectUse>(node->child1());
1162                     speculateForBarrier(node->child2());
1163                     break;
1164                 }
1165             }
1166             
1167             fixEdge<CellUse>(node->child1());
1168             break;
1169         }
1170
1171         case PutGetterById:
1172         case PutSetterById: {
1173             fixEdge<KnownCellUse>(node->child1());
1174             fixEdge<KnownCellUse>(node->child2());
1175             break;
1176         }
1177
1178         case PutGetterSetterById: {
1179             fixEdge<KnownCellUse>(node->child1());
1180             break;
1181         }
1182
1183         case PutGetterByVal:
1184         case PutSetterByVal: {
1185             fixEdge<KnownCellUse>(node->child1());
1186             fixEdge<KnownCellUse>(node->child3());
1187             break;
1188         }
1189
1190         case GetExecutable: {
1191             fixEdge<FunctionUse>(node->child1());
1192             break;
1193         }
1194
1195         case OverridesHasInstance:
1196         case CheckStructure:
1197         case CheckCell:
1198         case CreateThis:
1199         case GetButterfly: {
1200             fixEdge<CellUse>(node->child1());
1201             break;
1202         }
1203
1204         case CheckIdent: {
1205             UniquedStringImpl* uid = node->uidOperand();
1206             if (uid->isSymbol())
1207                 fixEdge<SymbolUse>(node->child1());
1208             else
1209                 fixEdge<StringIdentUse>(node->child1());
1210             break;
1211         }
1212             
1213         case Arrayify:
1214         case ArrayifyToStructure: {
1215             fixEdge<CellUse>(node->child1());
1216             if (node->child2())
1217                 fixEdge<Int32Use>(node->child2());
1218             break;
1219         }
1220             
1221         case GetByOffset:
1222         case GetGetterSetterByOffset: {
1223             if (!node->child1()->hasStorageResult())
1224                 fixEdge<KnownCellUse>(node->child1());
1225             fixEdge<KnownCellUse>(node->child2());
1226             break;
1227         }
1228             
1229         case MultiGetByOffset: {
1230             fixEdge<CellUse>(node->child1());
1231             break;
1232         }
1233             
1234         case PutByOffset: {
1235             if (!node->child1()->hasStorageResult())
1236                 fixEdge<KnownCellUse>(node->child1());
1237             fixEdge<KnownCellUse>(node->child2());
1238             insertInferredTypeCheck(
1239                 m_insertionSet, m_indexInBlock, node->origin, node->child3().node(),
1240                 node->storageAccessData().inferredType);
1241             speculateForBarrier(node->child3());
1242             break;
1243         }
1244             
1245         case MultiPutByOffset: {
1246             fixEdge<CellUse>(node->child1());
1247             speculateForBarrier(node->child2());
1248             break;
1249         }
1250             
1251         case InstanceOf: {
1252             if (!(node->child1()->prediction() & ~SpecCell))
1253                 fixEdge<CellUse>(node->child1());
1254             fixEdge<CellUse>(node->child2());
1255             break;
1256         }
1257
1258         case InstanceOfCustom:
1259             fixEdge<CellUse>(node->child2());
1260             break;
1261
1262         case In: {
1263             // FIXME: We should at some point have array profiling on op_in, in which
1264             // case we would be able to turn this into a kind of GetByVal.
1265             
1266             fixEdge<CellUse>(node->child2());
1267             break;
1268         }
1269
1270         case Check: {
1271             m_graph.doToChildren(
1272                 node,
1273                 [&] (Edge& edge) {
1274                     switch (edge.useKind()) {
1275                     case NumberUse:
1276                         if (edge->shouldSpeculateInt32ForArithmetic())
1277                             edge.setUseKind(Int32Use);
1278                         break;
1279                     default:
1280                         break;
1281                     }
1282                     observeUseKindOnEdge(edge);
1283                 });
1284             break;
1285         }
1286
1287         case Phantom:
1288             // Phantoms are meaningless past Fixup. We recreate them on-demand in the backend.
1289             node->remove();
1290             break;
1291
1292         case FiatInt52: {
1293             RELEASE_ASSERT(enableInt52());
1294             node->convertToIdentity();
1295             fixEdge<Int52RepUse>(node->child1());
1296             node->setResult(NodeResultInt52);
1297             break;
1298         }
1299
1300         case GetArrayLength: {
1301             fixEdge<KnownCellUse>(node->child1());
1302             break;
1303         }
1304
1305         case GetTypedArrayByteOffset: {
1306             fixEdge<KnownCellUse>(node->child1());
1307             break;
1308         }
1309
1310         case Phi:
1311         case Upsilon:
1312         case GetIndexedPropertyStorage:
1313         case LastNodeType:
1314         case CheckTierUpInLoop:
1315         case CheckTierUpAtReturn:
1316         case CheckTierUpAndOSREnter:
1317         case InvalidationPoint:
1318         case CheckArray:
1319         case CheckInBounds:
1320         case ConstantStoragePointer:
1321         case DoubleAsInt32:
1322         case ValueToInt32:
1323         case DoubleRep:
1324         case ValueRep:
1325         case Int52Rep:
1326         case Int52Constant:
1327         case Identity: // This should have been cleaned up.
1328         case BooleanToNumber:
1329         case PhantomNewObject:
1330         case PhantomNewFunction:
1331         case PhantomNewGeneratorFunction:
1332         case PhantomCreateActivation:
1333         case PhantomDirectArguments:
1334         case PhantomClonedArguments:
1335         case GetMyArgumentByVal:
1336         case GetMyArgumentByValOutOfBounds:
1337         case PutHint:
1338         case CheckStructureImmediate:
1339         case MaterializeNewObject:
1340         case MaterializeCreateActivation:
1341         case PutStack:
1342         case KillStack:
1343         case GetStack:
1344         case StoreBarrier:
1345         case GetRegExpObjectLastIndex:
1346         case SetRegExpObjectLastIndex:
1347         case RecordRegExpCachedResult:
1348             // These are just nodes that we don't currently expect to see during fixup.
1349             // If we ever wanted to insert them prior to fixup, then we just have to create
1350             // fixup rules for them.
1351             DFG_CRASH(m_graph, node, "Unexpected node during fixup");
1352             break;
1353         
1354         case PutGlobalVariable: {
1355             fixEdge<CellUse>(node->child1());
1356             speculateForBarrier(node->child2());
1357             break;
1358         }
1359
1360         case IsString:
1361             if (node->child1()->shouldSpeculateString()) {
1362                 m_insertionSet.insertNode(
1363                     m_indexInBlock, SpecNone, Check, node->origin,
1364                     Edge(node->child1().node(), StringUse));
1365                 m_graph.convertToConstant(node, jsBoolean(true));
1366                 observeUseKindOnNode<StringUse>(node);
1367             }
1368             break;
1369
1370         case IsObject:
1371             if (node->child1()->shouldSpeculateObject()) {
1372                 m_insertionSet.insertNode(
1373                     m_indexInBlock, SpecNone, Check, node->origin,
1374                     Edge(node->child1().node(), ObjectUse));
1375                 m_graph.convertToConstant(node, jsBoolean(true));
1376                 observeUseKindOnNode<ObjectUse>(node);
1377             }
1378             break;
1379
1380         case GetEnumerableLength: {
1381             fixEdge<CellUse>(node->child1());
1382             break;
1383         }
1384         case HasGenericProperty: {
1385             fixEdge<CellUse>(node->child2());
1386             break;
1387         }
1388         case HasStructureProperty: {
1389             fixEdge<StringUse>(node->child2());
1390             fixEdge<KnownCellUse>(node->child3());
1391             break;
1392         }
1393         case HasIndexedProperty: {
1394             node->setArrayMode(
1395                 node->arrayMode().refine(
1396                     m_graph, node,
1397                     node->child1()->prediction(),
1398                     node->child2()->prediction(),
1399                     SpecNone));
1400             
1401             blessArrayOperation(node->child1(), node->child2(), node->child3());
1402             fixEdge<CellUse>(node->child1());
1403             fixEdge<KnownInt32Use>(node->child2());
1404             break;
1405         }
1406         case GetDirectPname: {
1407             Edge& base = m_graph.varArgChild(node, 0);
1408             Edge& property = m_graph.varArgChild(node, 1);
1409             Edge& index = m_graph.varArgChild(node, 2);
1410             Edge& enumerator = m_graph.varArgChild(node, 3);
1411             fixEdge<CellUse>(base);
1412             fixEdge<KnownCellUse>(property);
1413             fixEdge<KnownInt32Use>(index);
1414             fixEdge<KnownCellUse>(enumerator);
1415             break;
1416         }
1417         case GetPropertyEnumerator: {
1418             fixEdge<CellUse>(node->child1());
1419             break;
1420         }
1421         case GetEnumeratorStructurePname: {
1422             fixEdge<KnownCellUse>(node->child1());
1423             fixEdge<KnownInt32Use>(node->child2());
1424             break;
1425         }
1426         case GetEnumeratorGenericPname: {
1427             fixEdge<KnownCellUse>(node->child1());
1428             fixEdge<KnownInt32Use>(node->child2());
1429             break;
1430         }
1431         case ToIndexString: {
1432             fixEdge<KnownInt32Use>(node->child1());
1433             break;
1434         }
1435         case ProfileType: {
1436             // We want to insert type checks based on the instructionTypeSet of the TypeLocation, not the globalTypeSet.
1437             // Because the instructionTypeSet is contained in globalTypeSet, if we produce a type check for
1438             // type T for the instructionTypeSet, the global type set must also have information for type T.
1439             // So if it the type check succeeds for type T in the instructionTypeSet, a type check for type T 
1440             // in the globalTypeSet would've also succeeded.
1441             // (The other direction does not hold in general).
1442
1443             RefPtr<TypeSet> typeSet = node->typeLocation()->m_instructionTypeSet;
1444             RuntimeTypeMask seenTypes = typeSet->seenTypes();
1445             if (typeSet->doesTypeConformTo(TypeAnyInt)) {
1446                 if (node->child1()->shouldSpeculateInt32())
1447                     fixEdge<Int32Use>(node->child1());
1448                 else
1449                     fixEdge<AnyIntUse>(node->child1());
1450                 node->remove();
1451             } else if (typeSet->doesTypeConformTo(TypeNumber | TypeAnyInt)) {
1452                 fixEdge<NumberUse>(node->child1());
1453                 node->remove();
1454             } else if (typeSet->doesTypeConformTo(TypeString)) {
1455                 fixEdge<StringUse>(node->child1());
1456                 node->remove();
1457             } else if (typeSet->doesTypeConformTo(TypeBoolean)) {
1458                 fixEdge<BooleanUse>(node->child1());
1459                 node->remove();
1460             } else if (typeSet->doesTypeConformTo(TypeUndefined | TypeNull) && (seenTypes & TypeUndefined) && (seenTypes & TypeNull)) {
1461                 fixEdge<OtherUse>(node->child1());
1462                 node->remove();
1463             } else if (typeSet->doesTypeConformTo(TypeObject)) {
1464                 StructureSet set = typeSet->structureSet();
1465                 if (!set.isEmpty()) {
1466                     fixEdge<CellUse>(node->child1());
1467                     node->convertToCheckStructure(m_graph.addStructureSet(set));
1468                 }
1469             }
1470
1471             break;
1472         }
1473
1474         case CreateScopedArguments:
1475         case CreateActivation:
1476         case NewFunction:
1477         case NewGeneratorFunction: {
1478             fixEdge<CellUse>(node->child1());
1479             break;
1480         }
1481
1482         case SetFunctionName: {
1483             // The first child is guaranteed to be a cell because op_set_function_name is only used
1484             // on a newly instantiated function object (the first child).
1485             fixEdge<KnownCellUse>(node->child1());
1486             fixEdge<UntypedUse>(node->child2());
1487             break;
1488         }
1489
1490         case CopyRest: {
1491             fixEdge<KnownCellUse>(node->child1());
1492             fixEdge<KnownInt32Use>(node->child2());
1493             break;
1494         }
1495
1496         case ResolveScope:
1497         case GetDynamicVar:
1498         case PutDynamicVar: {
1499             fixEdge<KnownCellUse>(node->child1());
1500             break;
1501         }
1502
1503         case LogShadowChickenPrologue: {
1504             fixEdge<KnownCellUse>(node->child1());
1505             break;
1506         }
1507         case LogShadowChickenTail: {
1508             fixEdge<UntypedUse>(node->child1());
1509             fixEdge<KnownCellUse>(node->child2());
1510             break;
1511         }
1512
1513 #if !ASSERT_DISABLED
1514         // Have these no-op cases here to ensure that nobody forgets to add handlers for new opcodes.
1515         case SetArgument:
1516         case JSConstant:
1517         case LazyJSConstant:
1518         case DoubleConstant:
1519         case GetLocal:
1520         case GetCallee:
1521         case GetArgumentCountIncludingThis:
1522         case GetRestLength:
1523         case Flush:
1524         case PhantomLocal:
1525         case GetLocalUnlinked:
1526         case GetGlobalVar:
1527         case GetGlobalLexicalVariable:
1528         case NotifyWrite:
1529         case VarInjectionWatchpoint:
1530         case Call:
1531         case CheckTypeInfoFlags:
1532         case TailCallInlinedCaller:
1533         case Construct:
1534         case CallVarargs:
1535         case TailCallVarargsInlinedCaller:
1536         case ConstructVarargs:
1537         case CallForwardVarargs:
1538         case ConstructForwardVarargs:
1539         case TailCallForwardVarargs:
1540         case TailCallForwardVarargsInlinedCaller:
1541         case LoadVarargs:
1542         case ForwardVarargs:
1543         case ProfileControlFlow:
1544         case NewObject:
1545         case NewArrayBuffer:
1546         case NewRegexp:
1547         case DeleteById:
1548         case DeleteByVal:
1549         case IsJSArray:
1550         case IsEmpty:
1551         case IsUndefined:
1552         case IsBoolean:
1553         case IsNumber:
1554         case IsObjectOrNull:
1555         case IsFunction:
1556         case IsRegExpObject:
1557         case CreateDirectArguments:
1558         case CreateClonedArguments:
1559         case Jump:
1560         case Return:
1561         case TailCall:
1562         case TailCallVarargs:
1563         case Throw:
1564         case ThrowReferenceError:
1565         case CountExecution:
1566         case ForceOSRExit:
1567         case CheckBadCell:
1568         case CheckNotEmpty:
1569         case CheckWatchdogTimer:
1570         case Unreachable:
1571         case ExtractOSREntryLocal:
1572         case LoopHint:
1573         case MovHint:
1574         case ZombieHint:
1575         case ExitOK:
1576         case BottomValue:
1577         case TypeOf:
1578         case GetByIdWithThis:
1579         case PutByIdWithThis:
1580         case PutByValWithThis:
1581         case GetByValWithThis:
1582             break;
1583             
1584             break;
1585 #else
1586         default:
1587             break;
1588 #endif
1589         }
1590     }
1591
1592     void watchHavingABadTime(Node* node)
1593     {
1594         JSGlobalObject* globalObject = m_graph.globalObjectFor(node->origin.semantic);
1595
1596         // If this global object is not having a bad time, watch it. We go down this path anytime the code
1597         // does an array allocation. The types of array allocations may change if we start to have a bad
1598         // time. It's easier to reason about this if we know that whenever the types change after we start
1599         // optimizing, the code just gets thrown out. Doing this at FixupPhase is just early enough, since
1600         // prior to this point nobody should have been doing optimizations based on the indexing type of
1601         // the allocation.
1602         if (!globalObject->isHavingABadTime())
1603             m_graph.watchpoints().addLazily(globalObject->havingABadTimeWatchpoint());
1604     }
1605     
1606     template<UseKind useKind>
1607     void createToString(Node* node, Edge& edge)
1608     {
1609         edge.setNode(m_insertionSet.insertNode(
1610             m_indexInBlock, SpecString, ToString, node->origin,
1611             Edge(edge.node(), useKind)));
1612     }
1613     
1614     template<UseKind useKind>
1615     void attemptToForceStringArrayModeByToStringConversion(ArrayMode& arrayMode, Node* node)
1616     {
1617         ASSERT(arrayMode == ArrayMode(Array::Generic));
1618         
1619         if (!m_graph.canOptimizeStringObjectAccess(node->origin.semantic))
1620             return;
1621         
1622         createToString<useKind>(node, node->child1());
1623         arrayMode = ArrayMode(Array::String);
1624     }
1625     
1626     template<UseKind useKind>
1627     bool isStringObjectUse()
1628     {
1629         switch (useKind) {
1630         case StringObjectUse:
1631         case StringOrStringObjectUse:
1632             return true;
1633         default:
1634             return false;
1635         }
1636     }
1637     
1638     template<UseKind useKind>
1639     void convertStringAddUse(Node* node, Edge& edge)
1640     {
1641         if (useKind == StringUse) {
1642             observeUseKindOnNode<StringUse>(edge.node());
1643             m_insertionSet.insertNode(
1644                 m_indexInBlock, SpecNone, Check, node->origin,
1645                 Edge(edge.node(), StringUse));
1646             edge.setUseKind(KnownStringUse);
1647             return;
1648         }
1649         
1650         observeUseKindOnNode<useKind>(edge.node());
1651         createToString<useKind>(node, edge);
1652     }
1653     
1654     void convertToMakeRope(Node* node)
1655     {
1656         node->setOpAndDefaultFlags(MakeRope);
1657         fixupMakeRope(node);
1658     }
1659     
1660     void fixupMakeRope(Node* node)
1661     {
1662         for (unsigned i = 0; i < AdjacencyList::Size; ++i) {
1663             Edge& edge = node->children.child(i);
1664             if (!edge)
1665                 break;
1666             edge.setUseKind(KnownStringUse);
1667             JSString* string = edge->dynamicCastConstant<JSString*>();
1668             if (!string)
1669                 continue;
1670             if (string->length())
1671                 continue;
1672             
1673             // Don't allow the MakeRope to have zero children.
1674             if (!i && !node->child2())
1675                 break;
1676             
1677             node->children.removeEdge(i--);
1678         }
1679         
1680         if (!node->child2()) {
1681             ASSERT(!node->child3());
1682             node->convertToIdentity();
1683         }
1684     }
1685
1686     void fixupToThis(Node* node)
1687     {
1688         ECMAMode ecmaMode = m_graph.executableFor(node->origin.semantic)->isStrictMode() ? StrictMode : NotStrictMode;
1689
1690         if (ecmaMode == StrictMode) {
1691             if (node->child1()->shouldSpeculateBoolean()) {
1692                 fixEdge<BooleanUse>(node->child1());
1693                 node->convertToIdentity();
1694                 return;
1695             }
1696
1697             if (node->child1()->shouldSpeculateInt32()) {
1698                 fixEdge<Int32Use>(node->child1());
1699                 node->convertToIdentity();
1700                 return;
1701             }
1702
1703             if (enableInt52() && node->child1()->shouldSpeculateAnyInt()) {
1704                 fixEdge<Int52RepUse>(node->child1());
1705                 node->convertToIdentity();
1706                 node->setResult(NodeResultInt52);
1707                 return;
1708             }
1709
1710             if (node->child1()->shouldSpeculateNumber()) {
1711                 fixEdge<DoubleRepUse>(node->child1());
1712                 node->convertToIdentity();
1713                 node->setResult(NodeResultDouble);
1714                 return;
1715             }
1716
1717             if (node->child1()->shouldSpeculateSymbol()) {
1718                 fixEdge<SymbolUse>(node->child1());
1719                 node->convertToIdentity();
1720                 return;
1721             }
1722
1723             if (node->child1()->shouldSpeculateStringIdent()) {
1724                 fixEdge<StringIdentUse>(node->child1());
1725                 node->convertToIdentity();
1726                 return;
1727             }
1728
1729             if (node->child1()->shouldSpeculateString()) {
1730                 fixEdge<StringUse>(node->child1());
1731                 node->convertToIdentity();
1732                 return;
1733             }
1734         }
1735
1736         if (node->child1()->shouldSpeculateOther()) {
1737             if (ecmaMode == StrictMode) {
1738                 fixEdge<OtherUse>(node->child1());
1739                 node->convertToIdentity();
1740                 return;
1741             }
1742
1743             m_insertionSet.insertNode(
1744                 m_indexInBlock, SpecNone, Check, node->origin,
1745                 Edge(node->child1().node(), OtherUse));
1746             observeUseKindOnNode<OtherUse>(node->child1().node());
1747             m_graph.convertToConstant(
1748                 node, m_graph.globalThisObjectFor(node->origin.semantic));
1749             return;
1750         }
1751
1752         // FIXME: This should cover other use cases but we don't have use kinds for them. It's not critical,
1753         // however, since we cover all the missing cases in constant folding.
1754         // https://bugs.webkit.org/show_bug.cgi?id=157213
1755         if (node->child1()->shouldSpeculateStringObject()) {
1756             fixEdge<StringObjectUse>(node->child1());
1757             node->convertToIdentity();
1758             return;
1759         }
1760
1761         if (isFinalObjectSpeculation(node->child1()->prediction())) {
1762             fixEdge<FinalObjectUse>(node->child1());
1763             node->convertToIdentity();
1764             return;
1765         }
1766     }
1767     
1768     void fixupToPrimitive(Node* node)
1769     {
1770         if (node->child1()->shouldSpeculateInt32()) {
1771             fixEdge<Int32Use>(node->child1());
1772             node->convertToIdentity();
1773             return;
1774         }
1775         
1776         if (node->child1()->shouldSpeculateString()) {
1777             fixEdge<StringUse>(node->child1());
1778             node->convertToIdentity();
1779             return;
1780         }
1781         
1782         if (node->child1()->shouldSpeculateStringObject()
1783             && m_graph.canOptimizeStringObjectAccess(node->origin.semantic)) {
1784             fixEdge<StringObjectUse>(node->child1());
1785             node->convertToToString();
1786             return;
1787         }
1788         
1789         if (node->child1()->shouldSpeculateStringOrStringObject()
1790             && m_graph.canOptimizeStringObjectAccess(node->origin.semantic)) {
1791             fixEdge<StringOrStringObjectUse>(node->child1());
1792             node->convertToToString();
1793             return;
1794         }
1795     }
1796     
1797     void fixupToStringOrCallStringConstructor(Node* node)
1798     {
1799         if (node->child1()->shouldSpeculateString()) {
1800             fixEdge<StringUse>(node->child1());
1801             node->convertToIdentity();
1802             return;
1803         }
1804         
1805         if (node->child1()->shouldSpeculateStringObject()
1806             && m_graph.canOptimizeStringObjectAccess(node->origin.semantic)) {
1807             fixEdge<StringObjectUse>(node->child1());
1808             return;
1809         }
1810         
1811         if (node->child1()->shouldSpeculateStringOrStringObject()
1812             && m_graph.canOptimizeStringObjectAccess(node->origin.semantic)) {
1813             fixEdge<StringOrStringObjectUse>(node->child1());
1814             return;
1815         }
1816         
1817         if (node->child1()->shouldSpeculateCell()) {
1818             fixEdge<CellUse>(node->child1());
1819             return;
1820         }
1821     }
1822
1823     bool attemptToMakeFastStringAdd(Node* node)
1824     {
1825         bool goodToGo = true;
1826         m_graph.doToChildren(
1827             node,
1828             [&] (Edge& edge) {
1829                 if (edge->shouldSpeculateString())
1830                     return;
1831                 if (m_graph.canOptimizeStringObjectAccess(node->origin.semantic)) {
1832                     if (edge->shouldSpeculateStringObject())
1833                         return;
1834                     if (edge->shouldSpeculateStringOrStringObject())
1835                         return;
1836                 }
1837                 goodToGo = false;
1838             });
1839         if (!goodToGo)
1840             return false;
1841
1842         m_graph.doToChildren(
1843             node,
1844             [&] (Edge& edge) {
1845                 if (edge->shouldSpeculateString()) {
1846                     convertStringAddUse<StringUse>(node, edge);
1847                     return;
1848                 }
1849                 ASSERT(m_graph.canOptimizeStringObjectAccess(node->origin.semantic));
1850                 if (edge->shouldSpeculateStringObject()) {
1851                     convertStringAddUse<StringObjectUse>(node, edge);
1852                     return;
1853                 }
1854                 if (edge->shouldSpeculateStringOrStringObject()) {
1855                     convertStringAddUse<StringOrStringObjectUse>(node, edge);
1856                     return;
1857                 }
1858                 RELEASE_ASSERT_NOT_REACHED();
1859             });
1860         
1861         convertToMakeRope(node);
1862         return true;
1863     }
1864
1865     void fixupGetAndSetLocalsInBlock(BasicBlock* block)
1866     {
1867         if (!block)
1868             return;
1869         ASSERT(block->isReachable);
1870         m_block = block;
1871         for (m_indexInBlock = 0; m_indexInBlock < block->size(); ++m_indexInBlock) {
1872             Node* node = m_currentNode = block->at(m_indexInBlock);
1873             if (node->op() != SetLocal && node->op() != GetLocal)
1874                 continue;
1875             
1876             VariableAccessData* variable = node->variableAccessData();
1877             switch (node->op()) {
1878             case GetLocal:
1879                 switch (variable->flushFormat()) {
1880                 case FlushedDouble:
1881                     node->setResult(NodeResultDouble);
1882                     break;
1883                 case FlushedInt52:
1884                     node->setResult(NodeResultInt52);
1885                     break;
1886                 default:
1887                     break;
1888                 }
1889                 break;
1890                 
1891             case SetLocal:
1892                 // NOTE: Any type checks we put here may get hoisted by fixupChecksInBlock(). So, if we
1893                 // add new type checking use kind for SetLocals, we need to modify that code as well.
1894                 
1895                 switch (variable->flushFormat()) {
1896                 case FlushedJSValue:
1897                     break;
1898                 case FlushedDouble:
1899                     fixEdge<DoubleRepUse>(node->child1());
1900                     break;
1901                 case FlushedInt32:
1902                     fixEdge<Int32Use>(node->child1());
1903                     break;
1904                 case FlushedInt52:
1905                     fixEdge<Int52RepUse>(node->child1());
1906                     break;
1907                 case FlushedCell:
1908                     fixEdge<CellUse>(node->child1());
1909                     break;
1910                 case FlushedBoolean:
1911                     fixEdge<BooleanUse>(node->child1());
1912                     break;
1913                 default:
1914                     RELEASE_ASSERT_NOT_REACHED();
1915                     break;
1916                 }
1917                 break;
1918                 
1919             default:
1920                 RELEASE_ASSERT_NOT_REACHED();
1921                 break;
1922             }
1923         }
1924         m_insertionSet.execute(block);
1925     }
1926     
1927     void addStringReplacePrimordialChecks(Node* searchRegExp)
1928     {
1929         Node* node = m_currentNode;
1930
1931         // Check that structure of searchRegExp is RegExp object
1932         m_insertionSet.insertNode(
1933             m_indexInBlock, SpecNone, Check, node->origin,
1934             Edge(searchRegExp, RegExpObjectUse));
1935
1936         auto emitPrimordialCheckFor = [&] (JSValue primordialProperty, UniquedStringImpl* propertyUID) {
1937             unsigned index = m_graph.identifiers().ensure(propertyUID);
1938
1939             Node* actualProperty = m_insertionSet.insertNode(
1940                 m_indexInBlock, SpecNone, TryGetById, node->origin,
1941                 OpInfo(index), OpInfo(SpecFunction), Edge(searchRegExp, CellUse));
1942
1943             m_insertionSet.insertNode(
1944                 m_indexInBlock, SpecNone, CheckCell, node->origin,
1945                 OpInfo(m_graph.freeze(primordialProperty)), Edge(actualProperty, CellUse));
1946         };
1947
1948         JSGlobalObject* globalObject = m_graph.globalObjectFor(node->origin.semantic);
1949
1950         // Check that searchRegExp.exec is the primordial RegExp.prototype.exec
1951         emitPrimordialCheckFor(globalObject->regExpProtoExecFunction(), vm().propertyNames->exec.impl());
1952         // Check that searchRegExp.global is the primordial RegExp.prototype.global
1953         emitPrimordialCheckFor(globalObject->regExpProtoGlobalGetter(), vm().propertyNames->global.impl());
1954         // Check that searchRegExp.unicode is the primordial RegExp.prototype.unicode
1955         emitPrimordialCheckFor(globalObject->regExpProtoUnicodeGetter(), vm().propertyNames->unicode.impl());
1956         // Check that searchRegExp[Symbol.match] is the primordial RegExp.prototype[Symbol.replace]
1957         emitPrimordialCheckFor(globalObject->regExpProtoSymbolReplaceFunction(), vm().propertyNames->replaceSymbol.impl());
1958     }
1959
1960     Node* checkArray(ArrayMode arrayMode, const NodeOrigin& origin, Node* array, Node* index, bool (*storageCheck)(const ArrayMode&) = canCSEStorage)
1961     {
1962         ASSERT(arrayMode.isSpecific());
1963         
1964         if (arrayMode.type() == Array::String) {
1965             m_insertionSet.insertNode(
1966                 m_indexInBlock, SpecNone, Check, origin, Edge(array, StringUse));
1967         } else {
1968             // Note that we only need to be using a structure check if we opt for SaneChain, since
1969             // that needs to protect against JSArray's __proto__ being changed.
1970             Structure* structure = arrayMode.originalArrayStructure(m_graph, origin.semantic);
1971         
1972             Edge indexEdge = index ? Edge(index, Int32Use) : Edge();
1973             
1974             if (arrayMode.doesConversion()) {
1975                 if (structure) {
1976                     m_insertionSet.insertNode(
1977                         m_indexInBlock, SpecNone, ArrayifyToStructure, origin,
1978                         OpInfo(structure), OpInfo(arrayMode.asWord()), Edge(array, CellUse), indexEdge);
1979                 } else {
1980                     m_insertionSet.insertNode(
1981                         m_indexInBlock, SpecNone, Arrayify, origin,
1982                         OpInfo(arrayMode.asWord()), Edge(array, CellUse), indexEdge);
1983                 }
1984             } else {
1985                 if (structure) {
1986                     m_insertionSet.insertNode(
1987                         m_indexInBlock, SpecNone, CheckStructure, origin,
1988                         OpInfo(m_graph.addStructureSet(structure)), Edge(array, CellUse));
1989                 } else {
1990                     m_insertionSet.insertNode(
1991                         m_indexInBlock, SpecNone, CheckArray, origin,
1992                         OpInfo(arrayMode.asWord()), Edge(array, CellUse));
1993                 }
1994             }
1995         }
1996         
1997         if (!storageCheck(arrayMode))
1998             return 0;
1999         
2000         if (arrayMode.usesButterfly()) {
2001             return m_insertionSet.insertNode(
2002                 m_indexInBlock, SpecNone, GetButterfly, origin, Edge(array, CellUse));
2003         }
2004         
2005         return m_insertionSet.insertNode(
2006             m_indexInBlock, SpecNone, GetIndexedPropertyStorage, origin,
2007             OpInfo(arrayMode.asWord()), Edge(array, KnownCellUse));
2008     }
2009     
2010     void blessArrayOperation(Edge base, Edge index, Edge& storageChild)
2011     {
2012         Node* node = m_currentNode;
2013         
2014         switch (node->arrayMode().type()) {
2015         case Array::ForceExit: {
2016             m_insertionSet.insertNode(
2017                 m_indexInBlock, SpecNone, ForceOSRExit, node->origin);
2018             return;
2019         }
2020             
2021         case Array::SelectUsingPredictions:
2022         case Array::Unprofiled:
2023             RELEASE_ASSERT_NOT_REACHED();
2024             return;
2025             
2026         case Array::Generic:
2027             return;
2028             
2029         default: {
2030             Node* storage = checkArray(node->arrayMode(), node->origin, base.node(), index.node());
2031             if (!storage)
2032                 return;
2033             
2034             storageChild = Edge(storage);
2035             return;
2036         } }
2037     }
2038     
2039     bool alwaysUnboxSimplePrimitives()
2040     {
2041 #if USE(JSVALUE64)
2042         return false;
2043 #else
2044         // Any boolean, int, or cell value is profitable to unbox on 32-bit because it
2045         // reduces traffic.
2046         return true;
2047 #endif
2048     }
2049
2050     template<UseKind useKind>
2051     void observeUseKindOnNode(Node* node)
2052     {
2053         if (useKind == UntypedUse)
2054             return;
2055         observeUseKindOnNode(node, useKind);
2056     }
2057
2058     void observeUseKindOnEdge(Edge edge)
2059     {
2060         observeUseKindOnNode(edge.node(), edge.useKind());
2061     }
2062
2063     void observeUseKindOnNode(Node* node, UseKind useKind)
2064     {
2065         if (node->op() != GetLocal)
2066             return;
2067         
2068         // FIXME: The way this uses alwaysUnboxSimplePrimitives() is suspicious.
2069         // https://bugs.webkit.org/show_bug.cgi?id=121518
2070         
2071         VariableAccessData* variable = node->variableAccessData();
2072         switch (useKind) {
2073         case Int32Use:
2074         case KnownInt32Use:
2075             if (alwaysUnboxSimplePrimitives()
2076                 || isInt32Speculation(variable->prediction()))
2077                 m_profitabilityChanged |= variable->mergeIsProfitableToUnbox(true);
2078             break;
2079         case NumberUse:
2080         case RealNumberUse:
2081         case DoubleRepUse:
2082         case DoubleRepRealUse:
2083             if (variable->doubleFormatState() == UsingDoubleFormat)
2084                 m_profitabilityChanged |= variable->mergeIsProfitableToUnbox(true);
2085             break;
2086         case BooleanUse:
2087         case KnownBooleanUse:
2088             if (alwaysUnboxSimplePrimitives()
2089                 || isBooleanSpeculation(variable->prediction()))
2090                 m_profitabilityChanged |= variable->mergeIsProfitableToUnbox(true);
2091             break;
2092         case Int52RepUse:
2093             if (isAnyIntSpeculation(variable->prediction()))
2094                 m_profitabilityChanged |= variable->mergeIsProfitableToUnbox(true);
2095             break;
2096         case CellUse:
2097         case KnownCellUse:
2098         case ObjectUse:
2099         case FunctionUse:
2100         case StringUse:
2101         case KnownStringUse:
2102         case SymbolUse:
2103         case StringObjectUse:
2104         case StringOrStringObjectUse:
2105             if (alwaysUnboxSimplePrimitives()
2106                 || isCellSpeculation(variable->prediction()))
2107                 m_profitabilityChanged |= variable->mergeIsProfitableToUnbox(true);
2108             break;
2109         default:
2110             break;
2111         }
2112     }
2113     
2114     template<UseKind useKind>
2115     void fixEdge(Edge& edge)
2116     {
2117         observeUseKindOnNode<useKind>(edge.node());
2118         edge.setUseKind(useKind);
2119     }
2120     
2121     void speculateForBarrier(Edge value)
2122     {
2123         // Currently, the DFG won't take advantage of this speculation. But, we want to do it in
2124         // the DFG anyway because if such a speculation would be wrong, we want to know before
2125         // we do an expensive compile.
2126         
2127         if (value->shouldSpeculateInt32()) {
2128             insertCheck<Int32Use>(m_indexInBlock, value.node());
2129             return;
2130         }
2131             
2132         if (value->shouldSpeculateBoolean()) {
2133             insertCheck<BooleanUse>(m_indexInBlock, value.node());
2134             return;
2135         }
2136             
2137         if (value->shouldSpeculateOther()) {
2138             insertCheck<OtherUse>(m_indexInBlock, value.node());
2139             return;
2140         }
2141             
2142         if (value->shouldSpeculateNumber()) {
2143             insertCheck<NumberUse>(m_indexInBlock, value.node());
2144             return;
2145         }
2146             
2147         if (value->shouldSpeculateNotCell()) {
2148             insertCheck<NotCellUse>(m_indexInBlock, value.node());
2149             return;
2150         }
2151     }
2152     
2153     template<UseKind useKind>
2154     void insertCheck(unsigned indexInBlock, Node* node)
2155     {
2156         observeUseKindOnNode<useKind>(node);
2157         m_insertionSet.insertNode(
2158             indexInBlock, SpecNone, Check, m_currentNode->origin, Edge(node, useKind));
2159     }
2160
2161     void fixIntConvertingEdge(Edge& edge)
2162     {
2163         Node* node = edge.node();
2164         if (node->shouldSpeculateInt32OrBoolean()) {
2165             fixIntOrBooleanEdge(edge);
2166             return;
2167         }
2168         
2169         UseKind useKind;
2170         if (node->shouldSpeculateAnyInt())
2171             useKind = Int52RepUse;
2172         else if (node->shouldSpeculateNumber())
2173             useKind = DoubleRepUse;
2174         else
2175             useKind = NotCellUse;
2176         Node* newNode = m_insertionSet.insertNode(
2177             m_indexInBlock, SpecInt32Only, ValueToInt32, m_currentNode->origin,
2178             Edge(node, useKind));
2179         observeUseKindOnNode(node, useKind);
2180         
2181         edge = Edge(newNode, KnownInt32Use);
2182     }
2183     
2184     void fixIntOrBooleanEdge(Edge& edge)
2185     {
2186         Node* node = edge.node();
2187         if (!node->sawBooleans()) {
2188             fixEdge<Int32Use>(edge);
2189             return;
2190         }
2191         
2192         UseKind useKind;
2193         if (node->shouldSpeculateBoolean())
2194             useKind = BooleanUse;
2195         else
2196             useKind = UntypedUse;
2197         Node* newNode = m_insertionSet.insertNode(
2198             m_indexInBlock, SpecInt32Only, BooleanToNumber, m_currentNode->origin,
2199             Edge(node, useKind));
2200         observeUseKindOnNode(node, useKind);
2201         
2202         edge = Edge(newNode, Int32Use);
2203     }
2204     
2205     void fixDoubleOrBooleanEdge(Edge& edge)
2206     {
2207         Node* node = edge.node();
2208         if (!node->sawBooleans()) {
2209             fixEdge<DoubleRepUse>(edge);
2210             return;
2211         }
2212         
2213         UseKind useKind;
2214         if (node->shouldSpeculateBoolean())
2215             useKind = BooleanUse;
2216         else
2217             useKind = UntypedUse;
2218         Node* newNode = m_insertionSet.insertNode(
2219             m_indexInBlock, SpecInt32Only, BooleanToNumber, m_currentNode->origin,
2220             Edge(node, useKind));
2221         observeUseKindOnNode(node, useKind);
2222         
2223         edge = Edge(newNode, DoubleRepUse);
2224     }
2225     
2226     void truncateConstantToInt32(Edge& edge)
2227     {
2228         Node* oldNode = edge.node();
2229         
2230         JSValue value = oldNode->asJSValue();
2231         if (value.isInt32())
2232             return;
2233         
2234         value = jsNumber(JSC::toInt32(value.asNumber()));
2235         ASSERT(value.isInt32());
2236         edge.setNode(m_insertionSet.insertNode(
2237             m_indexInBlock, SpecInt32Only, JSConstant, m_currentNode->origin,
2238             OpInfo(m_graph.freeze(value))));
2239     }
2240     
2241     void truncateConstantsIfNecessary(Node* node, AddSpeculationMode mode)
2242     {
2243         if (mode != SpeculateInt32AndTruncateConstants)
2244             return;
2245         
2246         ASSERT(node->child1()->hasConstant() || node->child2()->hasConstant());
2247         if (node->child1()->hasConstant())
2248             truncateConstantToInt32(node->child1());
2249         else
2250             truncateConstantToInt32(node->child2());
2251     }
2252     
2253     bool attemptToMakeIntegerAdd(Node* node)
2254     {
2255         AddSpeculationMode mode = m_graph.addSpeculationMode(node, FixupPass);
2256         if (mode != DontSpeculateInt32) {
2257             truncateConstantsIfNecessary(node, mode);
2258             fixIntOrBooleanEdge(node->child1());
2259             fixIntOrBooleanEdge(node->child2());
2260             if (bytecodeCanTruncateInteger(node->arithNodeFlags()))
2261                 node->setArithMode(Arith::Unchecked);
2262             else
2263                 node->setArithMode(Arith::CheckOverflow);
2264             return true;
2265         }
2266         
2267         if (m_graph.addShouldSpeculateAnyInt(node)) {
2268             fixEdge<Int52RepUse>(node->child1());
2269             fixEdge<Int52RepUse>(node->child2());
2270             node->setArithMode(Arith::CheckOverflow);
2271             node->setResult(NodeResultInt52);
2272             return true;
2273         }
2274         
2275         return false;
2276     }
2277     
2278     bool attemptToMakeGetArrayLength(Node* node)
2279     {
2280         if (!isInt32Speculation(node->prediction()))
2281             return false;
2282         CodeBlock* profiledBlock = m_graph.baselineCodeBlockFor(node->origin.semantic);
2283         ArrayProfile* arrayProfile = 
2284             profiledBlock->getArrayProfile(node->origin.semantic.bytecodeIndex);
2285         ArrayMode arrayMode = ArrayMode(Array::SelectUsingPredictions);
2286         if (arrayProfile) {
2287             ConcurrentJITLocker locker(profiledBlock->m_lock);
2288             arrayProfile->computeUpdatedPrediction(locker, profiledBlock);
2289             arrayMode = ArrayMode::fromObserved(locker, arrayProfile, Array::Read, false);
2290             if (arrayMode.type() == Array::Unprofiled) {
2291                 // For normal array operations, it makes sense to treat Unprofiled
2292                 // accesses as ForceExit and get more data rather than using
2293                 // predictions and then possibly ending up with a Generic. But here,
2294                 // we treat anything that is Unprofiled as Generic and keep the
2295                 // GetById. I.e. ForceExit = Generic. So, there is no harm - and only
2296                 // profit - from treating the Unprofiled case as
2297                 // SelectUsingPredictions.
2298                 arrayMode = ArrayMode(Array::SelectUsingPredictions);
2299             }
2300         }
2301             
2302         arrayMode = arrayMode.refine(
2303             m_graph, node, node->child1()->prediction(), node->prediction());
2304             
2305         if (arrayMode.type() == Array::Generic) {
2306             // Check if the input is something that we can't get array length for, but for which we
2307             // could insert some conversions in order to transform it into something that we can do it
2308             // for.
2309             if (node->child1()->shouldSpeculateStringObject())
2310                 attemptToForceStringArrayModeByToStringConversion<StringObjectUse>(arrayMode, node);
2311             else if (node->child1()->shouldSpeculateStringOrStringObject())
2312                 attemptToForceStringArrayModeByToStringConversion<StringOrStringObjectUse>(arrayMode, node);
2313         }
2314             
2315         if (!arrayMode.supportsSelfLength())
2316             return false;
2317         
2318         convertToGetArrayLength(node, arrayMode);
2319         return true;
2320     }
2321
2322     void convertToGetArrayLength(Node* node, ArrayMode arrayMode)
2323     {
2324         node->setOp(GetArrayLength);
2325         node->clearFlags(NodeMustGenerate);
2326         fixEdge<KnownCellUse>(node->child1());
2327         node->setArrayMode(arrayMode);
2328             
2329         Node* storage = checkArray(arrayMode, node->origin, node->child1().node(), 0, lengthNeedsStorage);
2330         if (!storage)
2331             return;
2332             
2333         node->child2() = Edge(storage);
2334     }
2335     
2336     Node* prependGetArrayLength(NodeOrigin origin, Node* child, ArrayMode arrayMode)
2337     {
2338         Node* storage = checkArray(arrayMode, origin, child, 0, lengthNeedsStorage);
2339         return m_insertionSet.insertNode(
2340             m_indexInBlock, SpecInt32Only, GetArrayLength, origin,
2341             OpInfo(arrayMode.asWord()), Edge(child, KnownCellUse), Edge(storage));
2342     }
2343     
2344     void fixupChecksInBlock(BasicBlock* block)
2345     {
2346         if (!block)
2347             return;
2348         ASSERT(block->isReachable);
2349         m_block = block;
2350         unsigned indexForChecks = UINT_MAX;
2351         NodeOrigin originForChecks;
2352         for (unsigned indexInBlock = 0; indexInBlock < block->size(); ++indexInBlock) {
2353             Node* node = block->at(indexInBlock);
2354
2355             // If this is a node at which we could exit, then save its index. If nodes after this one
2356             // cannot exit, then we will hoist checks to here.
2357             if (node->origin.exitOK) {
2358                 indexForChecks = indexInBlock;
2359                 originForChecks = node->origin;
2360             }
2361
2362             originForChecks = originForChecks.withSemantic(node->origin.semantic);
2363
2364             // First, try to relax the representational demands of each node, in order to have
2365             // fewer conversions.
2366             switch (node->op()) {
2367             case MovHint:
2368             case Check:
2369                 m_graph.doToChildren(
2370                     node,
2371                     [&] (Edge& edge) {
2372                         switch (edge.useKind()) {
2373                         case DoubleRepUse:
2374                         case DoubleRepRealUse:
2375                             if (edge->hasDoubleResult())
2376                                 break;
2377             
2378                             if (edge->hasInt52Result())
2379                                 edge.setUseKind(Int52RepUse);
2380                             else if (edge.useKind() == DoubleRepUse)
2381                                 edge.setUseKind(NumberUse);
2382                             break;
2383             
2384                         case Int52RepUse:
2385                             // Nothing we can really do.
2386                             break;
2387             
2388                         case UntypedUse:
2389                         case NumberUse:
2390                             if (edge->hasDoubleResult())
2391                                 edge.setUseKind(DoubleRepUse);
2392                             else if (edge->hasInt52Result())
2393                                 edge.setUseKind(Int52RepUse);
2394                             break;
2395             
2396                         case RealNumberUse:
2397                             if (edge->hasDoubleResult())
2398                                 edge.setUseKind(DoubleRepRealUse);
2399                             else if (edge->hasInt52Result())
2400                                 edge.setUseKind(Int52RepUse);
2401                             break;
2402             
2403                         default:
2404                             break;
2405                         }
2406                     });
2407                 break;
2408                 
2409             case ValueToInt32:
2410                 if (node->child1().useKind() == DoubleRepUse
2411                     && !node->child1()->hasDoubleResult()) {
2412                     node->child1().setUseKind(NumberUse);
2413                     break;
2414                 }
2415                 break;
2416                 
2417             default:
2418                 break;
2419             }
2420
2421             // Now, insert type conversions if necessary.
2422             m_graph.doToChildren(
2423                 node,
2424                 [&] (Edge& edge) {
2425                     Node* result = nullptr;
2426
2427                     switch (edge.useKind()) {
2428                     case DoubleRepUse:
2429                     case DoubleRepRealUse:
2430                     case DoubleRepAnyIntUse: {
2431                         if (edge->hasDoubleResult())
2432                             break;
2433             
2434                         if (edge->isNumberConstant()) {
2435                             result = m_insertionSet.insertNode(
2436                                 indexForChecks, SpecBytecodeDouble, DoubleConstant, originForChecks,
2437                                 OpInfo(m_graph.freeze(jsDoubleNumber(edge->asNumber()))));
2438                         } else if (edge->hasInt52Result()) {
2439                             result = m_insertionSet.insertNode(
2440                                 indexForChecks, SpecAnyIntAsDouble, DoubleRep, originForChecks,
2441                                 Edge(edge.node(), Int52RepUse));
2442                         } else {
2443                             UseKind useKind;
2444                             if (edge->shouldSpeculateDoubleReal())
2445                                 useKind = RealNumberUse;
2446                             else if (edge->shouldSpeculateNumber())
2447                                 useKind = NumberUse;
2448                             else
2449                                 useKind = NotCellUse;
2450
2451                             result = m_insertionSet.insertNode(
2452                                 indexForChecks, SpecBytecodeDouble, DoubleRep, originForChecks,
2453                                 Edge(edge.node(), useKind));
2454                         }
2455
2456                         edge.setNode(result);
2457                         break;
2458                     }
2459             
2460                     case Int52RepUse: {
2461                         if (edge->hasInt52Result())
2462                             break;
2463             
2464                         if (edge->isAnyIntConstant()) {
2465                             result = m_insertionSet.insertNode(
2466                                 indexForChecks, SpecAnyInt, Int52Constant, originForChecks,
2467                                 OpInfo(edge->constant()));
2468                         } else if (edge->hasDoubleResult()) {
2469                             result = m_insertionSet.insertNode(
2470                                 indexForChecks, SpecAnyInt, Int52Rep, originForChecks,
2471                                 Edge(edge.node(), DoubleRepAnyIntUse));
2472                         } else if (edge->shouldSpeculateInt32ForArithmetic()) {
2473                             result = m_insertionSet.insertNode(
2474                                 indexForChecks, SpecInt32Only, Int52Rep, originForChecks,
2475                                 Edge(edge.node(), Int32Use));
2476                         } else {
2477                             result = m_insertionSet.insertNode(
2478                                 indexForChecks, SpecAnyInt, Int52Rep, originForChecks,
2479                                 Edge(edge.node(), AnyIntUse));
2480                         }
2481
2482                         edge.setNode(result);
2483                         break;
2484                     }
2485
2486                     default: {
2487                         if (!edge->hasDoubleResult() && !edge->hasInt52Result())
2488                             break;
2489             
2490                         if (edge->hasDoubleResult()) {
2491                             result = m_insertionSet.insertNode(
2492                                 indexForChecks, SpecBytecodeDouble, ValueRep, originForChecks,
2493                                 Edge(edge.node(), DoubleRepUse));
2494                         } else {
2495                             result = m_insertionSet.insertNode(
2496                                 indexForChecks, SpecInt32Only | SpecAnyIntAsDouble, ValueRep,
2497                                 originForChecks, Edge(edge.node(), Int52RepUse));
2498                         }
2499
2500                         edge.setNode(result);
2501                         break;
2502                     } }
2503
2504                     // It's remotely possible that this node cannot do type checks, but we now have a
2505                     // type check on this node. We don't have to handle the general form of this
2506                     // problem. It only arises when ByteCodeParser emits an immediate SetLocal, rather
2507                     // than a delayed one. So, we only worry about those checks that we may have put on
2508                     // a SetLocal. Note that "indexForChecks != indexInBlock" is just another way of
2509                     // saying "!node->origin.exitOK".
2510                     if (indexForChecks != indexInBlock && mayHaveTypeCheck(edge.useKind())) {
2511                         UseKind knownUseKind;
2512                         
2513                         switch (edge.useKind()) {
2514                         case Int32Use:
2515                             knownUseKind = KnownInt32Use;
2516                             break;
2517                         case CellUse:
2518                             knownUseKind = KnownCellUse;
2519                             break;
2520                         case BooleanUse:
2521                             knownUseKind = KnownBooleanUse;
2522                             break;
2523                         default:
2524                             // This can only arise if we have a Check node, and in that case, we can
2525                             // just remove the original check.
2526                             DFG_ASSERT(m_graph, node, node->op() == Check);
2527                             knownUseKind = UntypedUse;
2528                             break;
2529                         }
2530
2531                         m_insertionSet.insertNode(
2532                             indexForChecks, SpecNone, Check, originForChecks, edge);
2533
2534                         edge.setUseKind(knownUseKind);
2535                     }
2536                 });
2537         }
2538         
2539         m_insertionSet.execute(block);
2540     }
2541     
2542     BasicBlock* m_block;
2543     unsigned m_indexInBlock;
2544     Node* m_currentNode;
2545     InsertionSet m_insertionSet;
2546     bool m_profitabilityChanged;
2547 };
2548     
2549 bool performFixup(Graph& graph)
2550 {
2551     return runPhase<FixupPhase>(graph);
2552 }
2553
2554 } } // namespace JSC::DFG
2555
2556 #endif // ENABLE(DFG_JIT)
2557