5a82c126aece15027df49ecf4e0d4e9ae359b1e5
[WebKit-https.git] / Source / JavaScriptCore / dfg / DFGValidate.cpp
1 /*
2  * Copyright (C) 2012-2015 Apple Inc. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  * 1. Redistributions of source code must retain the above copyright
8  *    notice, this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright
10  *    notice, this list of conditions and the following disclaimer in the
11  *    documentation and/or other materials provided with the distribution.
12  *
13  * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
14  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
17  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
24  */
25
26 #include "config.h"
27 #include "DFGValidate.h"
28
29 #if ENABLE(DFG_JIT)
30
31 #include "CodeBlockWithJITType.h"
32 #include "DFGClobberize.h"
33 #include "DFGClobbersExitState.h"
34 #include "DFGMayExit.h"
35 #include "JSCInlines.h"
36 #include <wtf/Assertions.h>
37 #include <wtf/BitVector.h>
38
39 namespace JSC { namespace DFG {
40
41 namespace {
42
43 class Validate {
44 public:
45     Validate(Graph& graph, GraphDumpMode graphDumpMode, CString graphDumpBeforePhase)
46         : m_graph(graph)
47         , m_graphDumpMode(graphDumpMode)
48         , m_graphDumpBeforePhase(graphDumpBeforePhase)
49     {
50     }
51     
52     #define VALIDATE(context, assertion) do { \
53         if (!(assertion)) { \
54             startCrashing(); \
55             dataLogF("\n\n\nAt "); \
56             reportValidationContext context; \
57             dataLogF(": validation failed: %s (%s:%d).\n", #assertion, __FILE__, __LINE__); \
58             dumpGraphIfAppropriate(); \
59             WTFReportAssertionFailure(__FILE__, __LINE__, WTF_PRETTY_FUNCTION, #assertion); \
60             CRASH(); \
61         } \
62     } while (0)
63     
64     #define V_EQUAL(context, left, right) do { \
65         if (left != right) { \
66             startCrashing(); \
67             dataLogF("\n\n\nAt "); \
68             reportValidationContext context; \
69             dataLogF(": validation failed: (%s = ", #left); \
70             dataLog(left); \
71             dataLogF(") == (%s = ", #right); \
72             dataLog(right); \
73             dataLogF(") (%s:%d).\n", __FILE__, __LINE__); \
74             dumpGraphIfAppropriate(); \
75             WTFReportAssertionFailure(__FILE__, __LINE__, WTF_PRETTY_FUNCTION, #left " == " #right); \
76             CRASH(); \
77         } \
78     } while (0)
79
80     #define notSet (static_cast<size_t>(-1))
81         
82     void validate()
83     {
84         // NB. This code is not written for performance, since it is not intended to run
85         // in release builds.
86
87         // Validate that all local variables at the head of the root block are dead.
88         BasicBlock* root = m_graph.block(0);
89         for (unsigned i = 0; i < root->variablesAtHead.numberOfLocals(); ++i)
90             V_EQUAL((virtualRegisterForLocal(i), root), static_cast<Node*>(0), root->variablesAtHead.local(i));
91         
92         // Validate ref counts and uses.
93         for (BlockIndex blockIndex = 0; blockIndex < m_graph.numBlocks(); ++blockIndex) {
94             BasicBlock* block = m_graph.block(blockIndex);
95             if (!block)
96                 continue;
97             VALIDATE((block), block->isReachable);
98             for (size_t i = 0; i < block->numNodes(); ++i)
99                 m_myRefCounts.add(block->node(i), 0);
100         }
101         for (BlockIndex blockIndex = 0; blockIndex < m_graph.numBlocks(); ++blockIndex) {
102             BasicBlock* block = m_graph.block(blockIndex);
103             if (!block)
104                 continue;
105             for (size_t i = 0; i < block->numNodes(); ++i) {
106                 Node* node = block->node(i);
107                 m_acceptableNodes.add(node);
108                 if (!node->shouldGenerate())
109                     continue;
110                 if (node->op() == Upsilon) {
111                     VALIDATE((node), m_graph.m_form == SSA);
112                     if (node->phi()->shouldGenerate())
113                         m_myRefCounts.find(node)->value++;
114                 }
115                 for (unsigned j = 0; j < m_graph.numChildren(node); ++j) {
116                     // Phi children in LoadStore form are invalid.
117                     if (m_graph.m_form == LoadStore && block->isPhiIndex(i))
118                         continue;
119                     
120                     Edge edge = m_graph.child(node, j);
121                     if (!edge)
122                         continue;
123                     
124                     m_myRefCounts.find(edge.node())->value++;
125
126                     validateEdgeWithDoubleResultIfNecessary(node, edge);
127                     VALIDATE((node, edge), edge->hasInt52Result() == (edge.useKind() == Int52RepUse));
128                     
129                     if (m_graph.m_form == SSA) {
130                         // In SSA, all edges must hasResult().
131                         VALIDATE((node, edge), edge->hasResult());
132                         continue;
133                     }
134                     
135                     // Unless I'm a Flush, Phantom, GetLocal, or Phi, my children should hasResult().
136                     switch (node->op()) {
137                     case Flush:
138                     case GetLocal:
139                         VALIDATE((node, edge), edge->hasVariableAccessData(m_graph));
140                         VALIDATE((node, edge), edge->variableAccessData() == node->variableAccessData());
141                         break;
142                     case PhantomLocal:
143                         VALIDATE((node, edge), edge->hasVariableAccessData(m_graph));
144                         VALIDATE((node, edge), edge->variableAccessData() == node->variableAccessData());
145                         VALIDATE((node, edge), edge->op() != SetLocal);
146                         break;
147                     case Phi:
148                         VALIDATE((node, edge), edge->hasVariableAccessData(m_graph));
149                         if (m_graph.m_unificationState == LocallyUnified)
150                             break;
151                         VALIDATE((node, edge), edge->variableAccessData() == node->variableAccessData());
152                         break;
153                     default:
154                         VALIDATE((node, edge), edge->hasResult());
155                         break;
156                     }
157                 }
158             }
159         }
160         
161         for (BlockIndex blockIndex = 0; blockIndex < m_graph.numBlocks(); ++blockIndex) {
162             BasicBlock* block = m_graph.block(blockIndex);
163             if (!block)
164                 continue;
165             for (size_t i = 0; i < block->numNodes(); ++i) {
166                 Node* node = block->node(i);
167                 if (m_graph.m_refCountState == ExactRefCount)
168                     V_EQUAL((node), m_myRefCounts.get(node), node->adjustedRefCount());
169             }
170             
171             bool foundTerminal = false;
172             for (size_t i = 0 ; i < block->size(); ++i) {
173                 Node* node = block->at(i);
174                 if (node->isTerminal()) {
175                     foundTerminal = true;
176                     for (size_t j = i + 1; j < block->size(); ++j) {
177                         node = block->at(j);
178                         VALIDATE((node), node->op() == Phantom || node->op() == PhantomLocal || node->op() == Flush || node->op() == Check);
179                         m_graph.doToChildren(
180                             node,
181                             [&] (Edge edge) {
182                                 VALIDATE((node, edge), shouldNotHaveTypeCheck(edge.useKind()));
183                             });
184                     }
185                     break;
186                 }
187             }
188             VALIDATE((block), foundTerminal);
189             
190             for (size_t i = 0; i < block->size(); ++i) {
191                 Node* node = block->at(i);
192
193                 VALIDATE((node), node->origin.isSet());
194                 VALIDATE((node), node->origin.semantic.isSet() == node->origin.forExit.isSet());
195                 VALIDATE((node), !(!node->origin.forExit.isSet() && node->origin.exitOK));
196                 VALIDATE((node), !(mayExit(m_graph, node) == Exits && !node->origin.exitOK));
197
198                 if (i) {
199                     Node* previousNode = block->at(i - 1);
200                     VALIDATE(
201                         (node),
202                         !clobbersExitState(m_graph, previousNode)
203                         || !node->origin.exitOK
204                         || node->op() == ExitOK
205                         || node->origin.forExit != previousNode->origin.forExit);
206                     VALIDATE(
207                         (node),
208                         !(!previousNode->origin.exitOK && node->origin.exitOK)
209                         || node->op() == ExitOK
210                         || node->origin.forExit != previousNode->origin.forExit);
211                 }
212                 
213                 VALIDATE((node), !node->hasStructure() || !!node->structure());
214                 VALIDATE((node), !node->hasCellOperand() || node->cellOperand()->value().isCell());
215                 VALIDATE((node), !node->hasCellOperand() || !!node->cellOperand()->value());
216                 
217                 if (!(node->flags() & NodeHasVarArgs)) {
218                     if (!node->child2())
219                         VALIDATE((node), !node->child3());
220                     if (!node->child1())
221                         VALIDATE((node), !node->child2());
222                 }
223                  
224                 switch (node->op()) {
225                 case Identity:
226                     VALIDATE((node), canonicalResultRepresentation(node->result()) == canonicalResultRepresentation(node->child1()->result()));
227                     break;
228                 case SetLocal:
229                 case PutStack:
230                 case Upsilon:
231                     VALIDATE((node), !!node->child1());
232                     switch (node->child1().useKind()) {
233                     case UntypedUse:
234                     case CellUse:
235                     case KnownCellUse:
236                     case Int32Use:
237                     case KnownInt32Use:
238                     case Int52RepUse:
239                     case DoubleRepUse:
240                     case BooleanUse:
241                     case KnownBooleanUse:
242                         break;
243                     default:
244                         VALIDATE((node), !"Bad use kind");
245                         break;
246                     }
247                     break;
248                 case MakeRope:
249                 case ValueAdd:
250                 case ArithAdd:
251                 case ArithSub:
252                 case ArithMul:
253                 case ArithIMul:
254                 case ArithDiv:
255                 case ArithMod:
256                 case ArithMin:
257                 case ArithMax:
258                 case ArithPow:
259                 case CompareLess:
260                 case CompareLessEq:
261                 case CompareGreater:
262                 case CompareGreaterEq:
263                 case CompareEq:
264                 case CompareStrictEq:
265                 case StrCat:
266                     VALIDATE((node), !!node->child1());
267                     VALIDATE((node), !!node->child2());
268                     break;
269                 case CheckStructure:
270                 case StringFromCharCode:
271                     VALIDATE((node), !!node->child1());
272                     break;
273                 case PutStructure:
274                     VALIDATE((node), !node->transition()->previous->dfgShouldWatch());
275                     break;
276                 case MultiPutByOffset:
277                     for (unsigned i = node->multiPutByOffsetData().variants.size(); i--;) {
278                         const PutByIdVariant& variant = node->multiPutByOffsetData().variants[i];
279                         if (variant.kind() != PutByIdVariant::Transition)
280                             continue;
281                         VALIDATE((node), !variant.oldStructureForTransition()->dfgShouldWatch());
282                     }
283                     break;
284                 case DoubleConstant:
285                 case Int52Constant:
286                     VALIDATE((node), node->isNumberConstant());
287                     break;
288                 default:
289                     break;
290                 }
291             }
292         }
293         
294         switch (m_graph.m_form) {
295         case LoadStore:
296         case ThreadedCPS:
297             validateCPS();
298             break;
299             
300         case SSA:
301             validateSSA();
302             break;
303         }
304
305         // Validate clobbered states.
306         struct DefLambdaAdaptor {
307             std::function<void(PureValue)> pureValue;
308             std::function<void(HeapLocation, LazyNode)> locationAndNode;
309
310             void operator()(PureValue value) const
311             {
312                 pureValue(value);
313             }
314
315             void operator()(HeapLocation location, LazyNode node) const
316             {
317                 locationAndNode(location, node);
318             }
319         };
320         for (BasicBlock* block : m_graph.blocksInNaturalOrder()) {
321             for (Node* node : *block) {
322                 clobberize(m_graph, node,
323                     [&] (AbstractHeap) { },
324                     [&] (AbstractHeap heap)
325                     {
326                         // CSE assumes that HEAP TOP is never written.
327                         // If this assumption is weakened, you need to update clobbering
328                         // in CSE accordingly.
329                         if (heap.kind() == Stack)
330                             VALIDATE((node), !heap.payload().isTop());
331                     },
332                     DefLambdaAdaptor {
333                         [&] (PureValue) { },
334                         [&] (HeapLocation location, LazyNode)
335                         {
336                             VALIDATE((node), location.heap().kind() != SideState);
337
338                             // More specific kinds should be used instead.
339                             VALIDATE((node), location.heap().kind() != World);
340                             VALIDATE((node), location.heap().kind() != Heap);
341                         }
342                 });
343             }
344         }
345     }
346     
347 private:
348     Graph& m_graph;
349     GraphDumpMode m_graphDumpMode;
350     CString m_graphDumpBeforePhase;
351     
352     HashMap<Node*, unsigned> m_myRefCounts;
353     HashSet<Node*> m_acceptableNodes;
354     
355     void validateCPS()
356     {
357         for (BlockIndex blockIndex = 0; blockIndex < m_graph.numBlocks(); ++blockIndex) {
358             BasicBlock* block = m_graph.block(blockIndex);
359             if (!block)
360                 continue;
361             
362             HashSet<Node*> phisInThisBlock;
363             HashSet<Node*> nodesInThisBlock;
364             
365             for (size_t i = 0; i < block->numNodes(); ++i) {
366                 Node* node = block->node(i);
367                 nodesInThisBlock.add(node);
368                 if (block->isPhiIndex(i))
369                     phisInThisBlock.add(node);
370                 for (unsigned j = 0; j < m_graph.numChildren(node); ++j) {
371                     Edge edge = m_graph.child(node, j);
372                     if (!edge)
373                         continue;
374                     VALIDATE((node, edge), m_acceptableNodes.contains(edge.node()));
375                 }
376             }
377             
378             for (size_t i = 0; i < block->phis.size(); ++i) {
379                 Node* node = block->phis[i];
380                 ASSERT(phisInThisBlock.contains(node));
381                 VALIDATE((node), node->op() == Phi);
382                 VirtualRegister local = node->local();
383                 for (unsigned j = 0; j < m_graph.numChildren(node); ++j) {
384                     // Phi children in LoadStore form are invalid.
385                     if (m_graph.m_form == LoadStore && block->isPhiIndex(i))
386                         continue;
387                     
388                     Edge edge = m_graph.child(node, j);
389                     if (!edge)
390                         continue;
391                     
392                     VALIDATE(
393                         (node, edge),
394                         edge->op() == SetLocal
395                         || edge->op() == SetArgument
396                         || edge->op() == Flush
397                         || edge->op() == Phi);
398                     
399                     if (phisInThisBlock.contains(edge.node()))
400                         continue;
401                     
402                     if (nodesInThisBlock.contains(edge.node())) {
403                         VALIDATE(
404                             (node, edge),
405                             edge->op() == SetLocal
406                             || edge->op() == SetArgument
407                             || edge->op() == Flush);
408                         
409                         continue;
410                     }
411                     
412                     // There must exist a predecessor block that has this node index in
413                     // its tail variables.
414                     bool found = false;
415                     for (unsigned k = 0; k < block->predecessors.size(); ++k) {
416                         BasicBlock* prevBlock = block->predecessors[k];
417                         VALIDATE((block->predecessors[k]), prevBlock);
418                         Node* prevNode = prevBlock->variablesAtTail.operand(local);
419                         // If we have a Phi that is not referring to *this* block then all predecessors
420                         // must have that local available.
421                         VALIDATE((local, block, block->predecessors[k]), prevNode);
422                         switch (prevNode->op()) {
423                         case GetLocal:
424                         case Flush:
425                         case PhantomLocal:
426                             prevNode = prevNode->child1().node();
427                             break;
428                         default:
429                             break;
430                         }
431                         if (node->shouldGenerate()) {
432                             VALIDATE((local, block->predecessors[k], prevNode),
433                                      prevNode->shouldGenerate());
434                         }
435                         VALIDATE(
436                             (local, block->predecessors[k], prevNode),
437                             prevNode->op() == SetLocal
438                             || prevNode->op() == SetArgument
439                             || prevNode->op() == Phi);
440                         if (prevNode == edge.node()) {
441                             found = true;
442                             break;
443                         }
444                         // At this point it cannot refer into this block.
445                         VALIDATE((local, block->predecessors[k], prevNode), !prevBlock->isInBlock(edge.node()));
446                     }
447                     
448                     VALIDATE((node, edge), found);
449                 }
450             }
451             
452             Operands<size_t> getLocalPositions(
453                 block->variablesAtHead.numberOfArguments(),
454                 block->variablesAtHead.numberOfLocals());
455             Operands<size_t> setLocalPositions(
456                 block->variablesAtHead.numberOfArguments(),
457                 block->variablesAtHead.numberOfLocals());
458             
459             for (size_t i = 0; i < block->variablesAtHead.numberOfArguments(); ++i) {
460                 VALIDATE((virtualRegisterForArgument(i), block), !block->variablesAtHead.argument(i) || block->variablesAtHead.argument(i)->hasVariableAccessData(m_graph));
461                 if (m_graph.m_form == ThreadedCPS)
462                     VALIDATE((virtualRegisterForArgument(i), block), !block->variablesAtTail.argument(i) || block->variablesAtTail.argument(i)->hasVariableAccessData(m_graph));
463                 
464                 getLocalPositions.argument(i) = notSet;
465                 setLocalPositions.argument(i) = notSet;
466             }
467             for (size_t i = 0; i < block->variablesAtHead.numberOfLocals(); ++i) {
468                 VALIDATE((virtualRegisterForLocal(i), block), !block->variablesAtHead.local(i) || block->variablesAtHead.local(i)->hasVariableAccessData(m_graph));
469                 if (m_graph.m_form == ThreadedCPS)
470                     VALIDATE((virtualRegisterForLocal(i), block), !block->variablesAtTail.local(i) || block->variablesAtTail.local(i)->hasVariableAccessData(m_graph));
471
472                 getLocalPositions.local(i) = notSet;
473                 setLocalPositions.local(i) = notSet;
474             }
475             
476             for (size_t i = 0; i < block->size(); ++i) {
477                 Node* node = block->at(i);
478                 ASSERT(nodesInThisBlock.contains(node));
479                 VALIDATE((node), node->op() != Phi);
480                 VALIDATE((node), node->origin.forExit.isSet());
481                 for (unsigned j = 0; j < m_graph.numChildren(node); ++j) {
482                     Edge edge = m_graph.child(node, j);
483                     if (!edge)
484                         continue;
485                     VALIDATE((node, edge), nodesInThisBlock.contains(edge.node()));
486                     switch (node->op()) {
487                     case PhantomLocal:
488                     case GetLocal:
489                     case Flush:
490                         break;
491                     default:
492                         VALIDATE((node, edge), !phisInThisBlock.contains(edge.node()));
493                         break;
494                     }
495                 }
496                 
497                 switch (node->op()) {
498                 case Phi:
499                 case Upsilon:
500                 case CheckInBounds:
501                 case PhantomNewObject:
502                 case PhantomNewFunction:
503                 case PhantomNewGeneratorFunction:
504                 case PhantomCreateActivation:
505                 case GetMyArgumentByVal:
506                 case PutHint:
507                 case CheckStructureImmediate:
508                 case MaterializeNewObject:
509                 case MaterializeCreateActivation:
510                 case PutStack:
511                 case KillStack:
512                 case GetStack:
513                     VALIDATE((node), !"unexpected node type in CPS");
514                     break;
515                 case Phantom:
516                     VALIDATE((node), m_graph.m_fixpointState != FixpointNotConverged);
517                     break;
518                 default:
519                     break;
520                 }
521                 
522                 if (!node->shouldGenerate())
523                     continue;
524                 switch (node->op()) {
525                 case GetLocal:
526                     // Ignore GetLocal's that we know to be dead, but that the graph
527                     // doesn't yet know to be dead.
528                     if (!m_myRefCounts.get(node))
529                         break;
530                     if (m_graph.m_form == ThreadedCPS) {
531                         VALIDATE((node, block), getLocalPositions.operand(node->local()) == notSet);
532                         VALIDATE((node, block), !!node->child1());
533                     }
534                     getLocalPositions.operand(node->local()) = i;
535                     break;
536                 case SetLocal:
537                     // Only record the first SetLocal. There may be multiple SetLocals
538                     // because of flushing.
539                     if (setLocalPositions.operand(node->local()) != notSet)
540                         break;
541                     setLocalPositions.operand(node->local()) = i;
542                     break;
543                 case SetArgument:
544                     // This acts like a reset. It's ok to have a second GetLocal for a local in the same
545                     // block if we had a SetArgument for that local.
546                     getLocalPositions.operand(node->local()) = notSet;
547                     setLocalPositions.operand(node->local()) = notSet;
548                     break;
549                 default:
550                     break;
551                 }
552             }
553             
554             if (m_graph.m_form == LoadStore)
555                 continue;
556             
557             for (size_t i = 0; i < block->variablesAtHead.numberOfArguments(); ++i) {
558                 checkOperand(
559                     block, getLocalPositions, setLocalPositions, virtualRegisterForArgument(i));
560             }
561             for (size_t i = 0; i < block->variablesAtHead.numberOfLocals(); ++i) {
562                 checkOperand(
563                     block, getLocalPositions, setLocalPositions, virtualRegisterForLocal(i));
564             }
565         }
566     }
567     
568     void validateSSA()
569     {
570         // FIXME: Add more things here.
571         // https://bugs.webkit.org/show_bug.cgi?id=123471
572         
573         for (BlockIndex blockIndex = 0; blockIndex < m_graph.numBlocks(); ++blockIndex) {
574             BasicBlock* block = m_graph.block(blockIndex);
575             if (!block)
576                 continue;
577             
578             VALIDATE((block), block->phis.isEmpty());
579
580             bool didSeeExitOK = false;
581             
582             for (unsigned nodeIndex = 0; nodeIndex < block->size(); ++nodeIndex) {
583                 Node* node = block->at(nodeIndex);
584                 didSeeExitOK |= node->origin.exitOK;
585                 switch (node->op()) {
586                 case Phi:
587                     // Phi cannot exit, and it would be wrong to hoist anything to the Phi that could
588                     // exit.
589                     VALIDATE((node), !node->origin.exitOK);
590
591                     // It never makes sense to have exitOK anywhere in the block before a Phi. It's only
592                     // OK to exit after all Phis are done.
593                     VALIDATE((node), !didSeeExitOK);
594                     break;
595                     
596                 case GetLocal:
597                 case SetLocal:
598                 case GetLocalUnlinked:
599                 case SetArgument:
600                 case Phantom:
601                     VALIDATE((node), !"bad node type for SSA");
602                     break;
603
604                 default:
605                     // FIXME: Add more things here.
606                     // https://bugs.webkit.org/show_bug.cgi?id=123471
607                     break;
608                 }
609                 switch (node->op()) {
610                 case PhantomNewObject:
611                 case PhantomNewFunction:
612                 case PhantomNewGeneratorFunction:
613                 case PhantomCreateActivation:
614                 case PhantomDirectArguments:
615                 case PhantomClonedArguments:
616                 case MovHint:
617                 case Upsilon:
618                 case ForwardVarargs:
619                 case CallForwardVarargs:
620                 case TailCallForwardVarargs:
621                 case TailCallForwardVarargsInlinedCaller:
622                 case ConstructForwardVarargs:
623                 case GetMyArgumentByVal:
624                     break;
625
626                 case Check:
627                     // FIXME: This is probably not correct.
628                     break;
629
630                 case PutHint:
631                     VALIDATE((node), node->child1()->isPhantomAllocation());
632                     break;
633
634                 default:
635                     m_graph.doToChildren(
636                         node,
637                         [&] (const Edge& edge) {
638                             VALIDATE((node), !edge->isPhantomAllocation());
639                         });
640                     break;
641                 }
642             }
643         }
644     }
645
646     void validateEdgeWithDoubleResultIfNecessary(Node* node, Edge edge)
647     {
648         if (!edge->hasDoubleResult())
649             return;
650
651         if (m_graph.m_planStage < PlanStage::AfterFixup)
652             return;
653         
654         VALIDATE((node, edge), edge.useKind() == DoubleRepUse || edge.useKind() == DoubleRepRealUse || edge.useKind() == DoubleRepMachineIntUse);
655     }
656
657     void checkOperand(
658         BasicBlock* block, Operands<size_t>& getLocalPositions,
659         Operands<size_t>& setLocalPositions, VirtualRegister operand)
660     {
661         if (getLocalPositions.operand(operand) == notSet)
662             return;
663         if (setLocalPositions.operand(operand) == notSet)
664             return;
665         
666         VALIDATE(
667             (block->at(getLocalPositions.operand(operand)),
668              block->at(setLocalPositions.operand(operand)),
669              block),
670             getLocalPositions.operand(operand) < setLocalPositions.operand(operand));
671     }
672     
673     void reportValidationContext(Node* node)
674     {
675         dataLogF("@%u", node->index());
676     }
677     
678     void reportValidationContext(BasicBlock* block)
679     {
680         dataLog("Block ", *block);
681     }
682     
683     void reportValidationContext(Node* node, Edge edge)
684     {
685         dataLog(node, " -> ", edge);
686     }
687     
688     void reportValidationContext(VirtualRegister local, BasicBlock* block)
689     {
690         if (!block) {
691             dataLog(local, " in null Block ");
692             return;
693         }
694
695         dataLog(local, " in Block ", *block);
696     }
697     
698     void reportValidationContext(
699         VirtualRegister local, BasicBlock* sourceBlock, BasicBlock* destinationBlock)
700     {
701         dataLog(local, " in Block ", *sourceBlock, " -> ", *destinationBlock);
702     }
703     
704     void reportValidationContext(
705         VirtualRegister local, BasicBlock* sourceBlock, Node* prevNode)
706     {
707         dataLog(prevNode, " for ", local, " in Block ", *sourceBlock);
708     }
709     
710     void reportValidationContext(Node* node, BasicBlock* block)
711     {
712         dataLog(node, " in Block ", *block);
713     }
714     
715     void reportValidationContext(Node* node, Node* node2, BasicBlock* block)
716     {
717         dataLog(node, " and ", node2, " in Block ", *block);
718     }
719     
720     void reportValidationContext(
721         Node* node, BasicBlock* block, Node* expectedNode, Edge incomingEdge)
722     {
723         dataLog(node, " in Block ", *block, ", searching for ", expectedNode, " from ", incomingEdge);
724     }
725     
726     void dumpGraphIfAppropriate()
727     {
728         if (m_graphDumpMode == DontDumpGraph)
729             return;
730         dataLog("\n");
731         if (!m_graphDumpBeforePhase.isNull()) {
732             dataLog("Before phase:\n");
733             dataLog(m_graphDumpBeforePhase);
734         }
735         dataLog("At time of failure:\n");
736         m_graph.dump();
737     }
738 };
739
740 } // End anonymous namespace.
741
742 void validate(Graph& graph, GraphDumpMode graphDumpMode, CString graphDumpBeforePhase)
743 {
744     Validate validationObject(graph, graphDumpMode, graphDumpBeforePhase);
745     validationObject.validate();
746 }
747
748 } } // namespace JSC::DFG
749
750 #endif // ENABLE(DFG_JIT)
751