[DFG] DFG should handle String#toString
[WebKit-https.git] / Source / JavaScriptCore / dfg / DFGClobberize.h
1 /*
2  * Copyright (C) 2013-2018 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 #pragma once
27
28 #if ENABLE(DFG_JIT)
29
30 #include "DFGAbstractHeap.h"
31 #include "DFGEdgeUsesStructure.h"
32 #include "DFGGraph.h"
33 #include "DFGHeapLocation.h"
34 #include "DFGLazyNode.h"
35 #include "DFGPureValue.h"
36 #include "DOMJITCallDOMGetterSnippet.h"
37 #include "DOMJITSignature.h"
38 #include "InlineCallFrame.h"
39 #include "JSFixedArray.h"
40 #include "JSImmutableButterfly.h"
41
42 namespace JSC { namespace DFG {
43
44 template<typename ReadFunctor, typename WriteFunctor, typename DefFunctor>
45 void clobberize(Graph& graph, Node* node, const ReadFunctor& read, const WriteFunctor& write, const DefFunctor& def)
46 {
47     // Some notes:
48     //
49     // - The canonical way of clobbering the world is to read world and write
50     //   heap. This is because World subsumes Heap and Stack, and Stack can be
51     //   read by anyone but only written to by explicit stack writing operations.
52     //   Of course, claiming to also write World is not wrong; it'll just
53     //   pessimise some important optimizations.
54     //
55     // - We cannot hoist, or sink, anything that has effects. This means that the
56     //   easiest way of indicating that something cannot be hoisted is to claim
57     //   that it side-effects some miscellaneous thing.
58     //
59     // - We cannot hoist forward-exiting nodes without some additional effort. I
60     //   believe that what it comes down to is that forward-exiting generally have
61     //   their NodeExitsForward cleared upon hoist, except for forward-exiting
62     //   nodes that take bogus state as their input. Those are substantially
63     //   harder. We disable it for now. In the future we could enable it by having
64     //   versions of those nodes that backward-exit instead, but I'm not convinced
65     //   of the soundness.
66     //
67     // - Some nodes lie, and claim that they do not read the JSCell_structureID,
68     //   JSCell_typeInfoFlags, etc. These are nodes that use the structure in a way
69     //   that does not depend on things that change under structure transitions.
70     //
71     // - It's implicitly understood that OSR exits read the world. This is why we
72     //   generally don't move or eliminate stores. Every node can exit, so the
73     //   read set does not reflect things that would be read if we exited.
74     //   Instead, the read set reflects what the node will have to read if it
75     //   *doesn't* exit.
76     //
77     // - Broadly, we don't say that we're reading something if that something is
78     //   immutable.
79     //
80     // - This must be sound even prior to type inference. We use this as early as
81     //   bytecode parsing to determine at which points in the program it's legal to
82     //   OSR exit.
83     //
84     // - If you do read(Stack) or read(World), then make sure that readTop() in
85     //   PreciseLocalClobberize is correct.
86     
87     // While read() and write() are fairly self-explanatory - they track what sorts of things the
88     // node may read or write - the def() functor is more tricky. It tells you the heap locations
89     // (not just abstract heaps) that are defined by a node. A heap location comprises an abstract
90     // heap, some nodes, and a LocationKind. Briefly, a location defined by a node is a location
91     // whose value can be deduced from looking at the node itself. The locations returned must obey
92     // the following properties:
93     //
94     // - If someone wants to CSE a load from the heap, then a HeapLocation object should be
95     //   sufficient to find a single matching node.
96     //
97     // - The abstract heap is the only abstract heap that could be clobbered to invalidate any such
98     //   CSE attempt. I.e. if clobberize() reports that on every path between some node and a node
99     //   that defines a HeapLocation that it wanted, there were no writes to any abstract heap that
100     //   overlap the location's heap, then we have a sound match. Effectively, the semantics of
101     //   write() and def() are intertwined such that for them to be sound they must agree on what
102     //   is CSEable.
103     //
104     // read(), write(), and def() for heap locations is enough to do GCSE on effectful things. To
105     // keep things simple, this code will also def() pure things. def() must be overloaded to also
106     // accept PureValue. This way, a client of clobberize() can implement GCSE entirely using the
107     // information that clobberize() passes to write() and def(). Other clients of clobberize() can
108     // just ignore def() by using a NoOpClobberize functor.
109
110     if (edgesUseStructure(graph, node))
111         read(JSCell_structureID);
112     
113     // We allow the runtime to perform a stack scan at any time. We don't model which nodes get implemented
114     // by calls into the runtime. For debugging we might replace the implementation of any node with a call
115     // to the runtime, and that call may walk stack. Therefore, each node must read() anything that a stack
116     // scan would read. That's what this does.
117     for (InlineCallFrame* inlineCallFrame = node->origin.semantic.inlineCallFrame; inlineCallFrame; inlineCallFrame = inlineCallFrame->directCaller.inlineCallFrame) {
118         if (inlineCallFrame->isClosureCall)
119             read(AbstractHeap(Stack, inlineCallFrame->stackOffset + CallFrameSlot::callee));
120         if (inlineCallFrame->isVarargs())
121             read(AbstractHeap(Stack, inlineCallFrame->stackOffset + CallFrameSlot::argumentCount));
122     }
123
124     // We don't want to specifically account which nodes can read from the scope
125     // when the debugger is enabled. It's helpful to just claim all nodes do.
126     // Specifically, if a node allocates, this may call into the debugger's machinery.
127     // The debugger's machinery is free to take a stack trace and try to read from
128     // a scope which is expected to be flushed to the stack.
129     if (graph.hasDebuggerEnabled()) {
130         ASSERT(!node->origin.semantic.inlineCallFrame);
131         read(AbstractHeap(Stack, graph.m_codeBlock->scopeRegister()));
132     }
133     
134     switch (node->op()) {
135     case JSConstant:
136     case DoubleConstant:
137     case Int52Constant:
138         def(PureValue(node, node->constant()));
139         return;
140
141     case Identity:
142     case IdentityWithProfile:
143     case Phantom:
144     case Check:
145     case CheckVarargs:
146     case ExtractOSREntryLocal:
147     case CheckStructureImmediate:
148         return;
149
150     case ExtractCatchLocal:
151         read(AbstractHeap(CatchLocals, node->catchOSREntryIndex()));
152         return;
153
154     case ClearCatchLocals:
155         write(CatchLocals);
156         return;
157         
158     case LazyJSConstant:
159         // We should enable CSE of LazyJSConstant. It's a little annoying since LazyJSValue has
160         // more bits than we currently have in PureValue.
161         return;
162
163     case CompareEqPtr:
164         def(PureValue(node, node->cellOperand()->cell()));
165         return;
166         
167     case ArithIMul:
168     case ArithMin:
169     case ArithMax:
170     case ArithPow:
171     case GetScope:
172     case SkipScope:
173     case GetGlobalObject:
174     case StringCharCodeAt:
175     case CompareStrictEq:
176     case SameValue:
177     case IsEmpty:
178     case IsUndefined:
179     case IsBoolean:
180     case IsNumber:
181     case NumberIsInteger:
182     case IsObject:
183     case IsTypedArrayView:
184     case LogicalNot:
185     case CheckInBounds:
186     case DoubleRep:
187     case ValueRep:
188     case Int52Rep:
189     case BooleanToNumber:
190     case FiatInt52:
191     case MakeRope:
192     case StrCat:
193     case ValueToInt32:
194     case GetExecutable:
195     case BottomValue:
196     case TypeOf:
197         def(PureValue(node));
198         return;
199
200     case GetGlobalThis:
201         read(World);
202         return;
203
204     case AtomicsIsLockFree:
205         if (node->child1().useKind() == Int32Use)
206             def(PureValue(node));
207         else {
208             read(World);
209             write(Heap);
210         }
211         return;
212         
213     case ArithUnary:
214         if (node->child1().useKind() == DoubleRepUse)
215             def(PureValue(node, static_cast<std::underlying_type<Arith::UnaryType>::type>(node->arithUnaryType())));
216         else {
217             read(World);
218             write(Heap);
219         }
220         return;
221
222     case ArithFRound:
223     case ArithSqrt:
224         if (node->child1().useKind() == DoubleRepUse)
225             def(PureValue(node));
226         else {
227             read(World);
228             write(Heap);
229         }
230         return;
231
232     case ArithAbs:
233         if (node->child1().useKind() == Int32Use || node->child1().useKind() == DoubleRepUse)
234             def(PureValue(node));
235         else {
236             read(World);
237             write(Heap);
238         }
239         return;
240
241     case ArithClz32:
242         if (node->child1().useKind() == Int32Use || node->child1().useKind() == KnownInt32Use)
243             def(PureValue(node));
244         else {
245             read(World);
246             write(Heap);
247         }
248         return;
249
250     case ArithNegate:
251         if (node->child1().useKind() == Int32Use
252             || node->child1().useKind() == DoubleRepUse
253             || node->child1().useKind() == Int52RepUse)
254             def(PureValue(node));
255         else {
256             read(World);
257             write(Heap);
258         }
259         return;
260
261     case IsCellWithType:
262         def(PureValue(node, node->queriedType()));
263         return;
264
265     case BitAnd:
266     case BitOr:
267     case BitXor:
268     case BitLShift:
269     case BitRShift:
270     case BitURShift:
271         if (node->child1().useKind() == UntypedUse || node->child2().useKind() == UntypedUse) {
272             read(World);
273             write(Heap);
274             return;
275         }
276         def(PureValue(node));
277         return;
278
279     case ArithRandom:
280         read(MathDotRandomState);
281         write(MathDotRandomState);
282         return;
283
284     case GetEnumerableLength: {
285         read(Heap);
286         write(SideState);
287         return;
288     }
289
290     case ToIndexString:
291     case GetEnumeratorStructurePname:
292     case GetEnumeratorGenericPname: {
293         def(PureValue(node));
294         return;
295     }
296
297     case HasIndexedProperty: {
298         read(JSObject_butterfly);
299         ArrayMode mode = node->arrayMode();
300         switch (mode.type()) {
301         case Array::ForceExit: {
302             write(SideState);
303             return;
304         }
305         case Array::Int32: {
306             if (mode.isInBounds()) {
307                 read(Butterfly_publicLength);
308                 read(IndexedInt32Properties);
309                 def(HeapLocation(HasIndexedPropertyLoc, IndexedInt32Properties, node->child1(), node->child2()), LazyNode(node));
310                 return;
311             }
312             read(Heap);
313             return;
314         }
315             
316         case Array::Double: {
317             if (mode.isInBounds()) {
318                 read(Butterfly_publicLength);
319                 read(IndexedDoubleProperties);
320                 def(HeapLocation(HasIndexedPropertyLoc, IndexedDoubleProperties, node->child1(), node->child2()), LazyNode(node));
321                 return;
322             }
323             read(Heap);
324             return;
325         }
326             
327         case Array::Contiguous: {
328             if (mode.isInBounds()) {
329                 read(Butterfly_publicLength);
330                 read(IndexedContiguousProperties);
331                 def(HeapLocation(HasIndexedPropertyLoc, IndexedContiguousProperties, node->child1(), node->child2()), LazyNode(node));
332                 return;
333             }
334             read(Heap);
335             return;
336         }
337
338         case Array::ArrayStorage: {
339             if (mode.isInBounds()) {
340                 read(Butterfly_vectorLength);
341                 read(IndexedArrayStorageProperties);
342                 return;
343             }
344             read(Heap);
345             return;
346         }
347
348         default: {
349             read(World);
350             write(Heap);
351             return;
352         }
353         }
354         RELEASE_ASSERT_NOT_REACHED();
355         return;
356     }
357
358     case StringFromCharCode:
359         switch (node->child1().useKind()) {
360         case Int32Use:
361             def(PureValue(node));
362             return;
363         case UntypedUse:
364             read(World);
365             write(Heap);
366             return;
367         default:
368             DFG_CRASH(graph, node, "Bad use kind");
369         }
370         return;
371
372     case ArithAdd:
373     case ArithMod:
374     case DoubleAsInt32:
375     case UInt32ToNumber:
376         def(PureValue(node, node->arithMode()));
377         return;
378
379     case ArithDiv:
380     case ArithMul:
381     case ArithSub:
382         switch (node->binaryUseKind()) {
383         case Int32Use:
384         case Int52RepUse:
385         case DoubleRepUse:
386             def(PureValue(node, node->arithMode()));
387             return;
388         case UntypedUse:
389             read(World);
390             write(Heap);
391             return;
392         default:
393             DFG_CRASH(graph, node, "Bad use kind");
394         }
395
396     case ArithRound:
397     case ArithFloor:
398     case ArithCeil:
399     case ArithTrunc:
400         if (node->child1().useKind() == DoubleRepUse)
401             def(PureValue(node, static_cast<uintptr_t>(node->arithRoundingMode())));
402         else {
403             read(World);
404             write(Heap);
405         }
406         return;
407
408     case CheckCell:
409         def(PureValue(CheckCell, AdjacencyList(AdjacencyList::Fixed, node->child1()), node->cellOperand()));
410         return;
411
412     case CheckNotEmpty:
413         def(PureValue(CheckNotEmpty, AdjacencyList(AdjacencyList::Fixed, node->child1())));
414         return;
415
416     case AssertNotEmpty:
417         write(SideState);
418         return;
419
420     case CheckStringIdent:
421         def(PureValue(CheckStringIdent, AdjacencyList(AdjacencyList::Fixed, node->child1()), node->uidOperand()));
422         return;
423
424     case ConstantStoragePointer:
425         def(PureValue(node, node->storagePointer()));
426         return;
427
428     case KillStack:
429         write(AbstractHeap(Stack, node->unlinkedLocal()));
430         return;
431          
432     case MovHint:
433     case ZombieHint:
434     case ExitOK:
435     case Upsilon:
436     case Phi:
437     case PhantomLocal:
438     case SetArgument:
439     case Jump:
440     case Branch:
441     case Switch:
442     case EntrySwitch:
443     case ForceOSRExit:
444     case CPUIntrinsic:
445     case CheckBadCell:
446     case Return:
447     case Unreachable:
448     case CheckTierUpInLoop:
449     case CheckTierUpAtReturn:
450     case CheckTierUpAndOSREnter:
451     case LoopHint:
452     case ProfileType:
453     case ProfileControlFlow:
454     case PutHint:
455     case InitializeEntrypointArguments:
456     case FilterCallLinkStatus:
457     case FilterGetByIdStatus:
458     case FilterPutByIdStatus:
459     case FilterInByIdStatus:
460         write(SideState);
461         return;
462         
463     case StoreBarrier:
464         read(JSCell_cellState);
465         write(JSCell_cellState);
466         return;
467         
468     case FencedStoreBarrier:
469         read(Heap);
470         write(JSCell_cellState);
471         return;
472
473     case CheckTraps:
474         read(InternalState);
475         write(InternalState);
476         return;
477
478     case InvalidationPoint:
479         write(SideState);
480         def(HeapLocation(InvalidationPointLoc, Watchpoint_fire), LazyNode(node));
481         return;
482
483     case Flush:
484         read(AbstractHeap(Stack, node->local()));
485         write(SideState);
486         return;
487
488     case NotifyWrite:
489         write(Watchpoint_fire);
490         write(SideState);
491         return;
492
493     case PushWithScope: {
494         read(World);
495         write(HeapObjectCount);
496         return;
497     }
498
499     case CreateActivation: {
500         SymbolTable* table = node->castOperand<SymbolTable*>();
501         if (table->singletonScope()->isStillValid())
502             write(Watchpoint_fire);
503         read(HeapObjectCount);
504         write(HeapObjectCount);
505         return;
506     }
507
508     case CreateDirectArguments:
509     case CreateScopedArguments:
510     case CreateClonedArguments:
511         read(Stack);
512         read(HeapObjectCount);
513         write(HeapObjectCount);
514         return;
515
516     case PhantomDirectArguments:
517     case PhantomClonedArguments:
518         // DFG backend requires that the locals that this reads are flushed. FTL backend can handle those
519         // locals being promoted.
520         if (!graph.m_plan.isFTL())
521             read(Stack);
522         
523         // Even though it's phantom, it still has the property that one can't be replaced with another.
524         read(HeapObjectCount);
525         write(HeapObjectCount);
526         return;
527
528     case PhantomSpread:
529     case PhantomNewArrayWithSpread:
530     case PhantomNewArrayBuffer:
531     case PhantomCreateRest:
532         // Even though it's phantom, it still has the property that one can't be replaced with another.
533         read(HeapObjectCount);
534         write(HeapObjectCount);
535         return;
536
537     case CallObjectConstructor:
538         read(HeapObjectCount);
539         write(HeapObjectCount);
540         return;
541
542     case ToThis:
543         read(MiscFields);
544         read(HeapObjectCount);
545         write(HeapObjectCount);
546         return;
547
548     case IsObjectOrNull:
549         read(MiscFields);
550         def(HeapLocation(IsObjectOrNullLoc, MiscFields, node->child1()), LazyNode(node));
551         return;
552         
553     case IsFunction:
554         read(MiscFields);
555         def(HeapLocation(IsFunctionLoc, MiscFields, node->child1()), LazyNode(node));
556         return;
557         
558     case MatchStructure:
559         read(JSCell_structureID);
560         return;
561
562     case ArraySlice:
563         read(MiscFields);
564         read(JSCell_indexingType);
565         read(JSCell_structureID);
566         read(JSObject_butterfly);
567         read(Butterfly_publicLength);
568         read(IndexedDoubleProperties);
569         read(IndexedInt32Properties);
570         read(IndexedContiguousProperties);
571         read(HeapObjectCount);
572         write(HeapObjectCount);
573         return;
574
575     case ArrayIndexOf: {
576         // FIXME: Should support a CSE rule.
577         // https://bugs.webkit.org/show_bug.cgi?id=173173
578         read(MiscFields);
579         read(JSCell_indexingType);
580         read(JSCell_structureID);
581         read(JSObject_butterfly);
582         read(Butterfly_publicLength);
583         switch (node->arrayMode().type()) {
584         case Array::Double:
585             read(IndexedDoubleProperties);
586             return;
587         case Array::Int32:
588             read(IndexedInt32Properties);
589             return;
590         case Array::Contiguous:
591             read(IndexedContiguousProperties);
592             return;
593         default:
594             RELEASE_ASSERT_NOT_REACHED();
595             return;
596         }
597         return;
598     }
599         
600     case GetById:
601     case GetByIdFlush:
602     case GetByIdWithThis:
603     case GetByIdDirect:
604     case GetByIdDirectFlush:
605     case GetByValWithThis:
606     case PutById:
607     case PutByIdWithThis:
608     case PutByValWithThis:
609     case PutByIdFlush:
610     case PutByIdDirect:
611     case PutGetterById:
612     case PutSetterById:
613     case PutGetterSetterById:
614     case PutGetterByVal:
615     case PutSetterByVal:
616     case DefineDataProperty:
617     case DefineAccessorProperty:
618     case DeleteById:
619     case DeleteByVal:
620     case ArrayPush:
621     case ArrayPop:
622     case Call:
623     case DirectCall:
624     case TailCallInlinedCaller:
625     case DirectTailCallInlinedCaller:
626     case Construct:
627     case DirectConstruct:
628     case CallVarargs:
629     case CallForwardVarargs:
630     case TailCallVarargsInlinedCaller:
631     case TailCallForwardVarargsInlinedCaller:
632     case ConstructVarargs:
633     case ConstructForwardVarargs:
634     case ToPrimitive:
635     case InByVal:
636     case InById:
637     case HasOwnProperty:
638     case ValueNegate:
639     case ValueAdd:
640     case SetFunctionName:
641     case GetDynamicVar:
642     case PutDynamicVar:
643     case ResolveScopeForHoistingFuncDeclInEval:
644     case ResolveScope:
645     case ToObject:
646     case HasGenericProperty:
647     case HasStructureProperty:
648     case GetPropertyEnumerator:
649     case GetDirectPname:
650     case InstanceOfCustom:
651     case ToNumber:
652     case NumberToStringWithRadix:
653     case CreateThis:
654     case InstanceOf:
655     case StringValueOf:
656         read(World);
657         write(Heap);
658         return;
659
660     case AtomicsAdd:
661     case AtomicsAnd:
662     case AtomicsCompareExchange:
663     case AtomicsExchange:
664     case AtomicsLoad:
665     case AtomicsOr:
666     case AtomicsStore:
667     case AtomicsSub:
668     case AtomicsXor: {
669         unsigned numExtraArgs = numExtraAtomicsArgs(node->op());
670         Edge storageEdge = graph.child(node, 2 + numExtraArgs);
671         if (!storageEdge) {
672             read(World);
673             write(Heap);
674             return;
675         }
676         read(TypedArrayProperties);
677         read(MiscFields);
678         write(TypedArrayProperties);
679         return;
680     }
681
682     case CallEval:
683         ASSERT(!node->origin.semantic.inlineCallFrame);
684         read(AbstractHeap(Stack, graph.m_codeBlock->scopeRegister()));
685         read(AbstractHeap(Stack, virtualRegisterForArgument(0)));
686         read(World);
687         write(Heap);
688         return;
689
690     case Throw:
691     case ThrowStaticError:
692     case TailCall:
693     case DirectTailCall:
694     case TailCallVarargs:
695     case TailCallForwardVarargs:
696         read(World);
697         write(SideState);
698         return;
699         
700     case GetGetter:
701         read(GetterSetter_getter);
702         def(HeapLocation(GetterLoc, GetterSetter_getter, node->child1()), LazyNode(node));
703         return;
704         
705     case GetSetter:
706         read(GetterSetter_setter);
707         def(HeapLocation(SetterLoc, GetterSetter_setter, node->child1()), LazyNode(node));
708         return;
709         
710     case GetCallee:
711         read(AbstractHeap(Stack, CallFrameSlot::callee));
712         def(HeapLocation(StackLoc, AbstractHeap(Stack, CallFrameSlot::callee)), LazyNode(node));
713         return;
714
715     case SetCallee:
716         write(AbstractHeap(Stack, CallFrameSlot::callee));
717         return;
718         
719     case GetArgumentCountIncludingThis: {
720         auto heap = AbstractHeap(Stack, remapOperand(node->argumentsInlineCallFrame(), VirtualRegister(CallFrameSlot::argumentCount)));
721         read(heap);
722         def(HeapLocation(StackPayloadLoc, heap), LazyNode(node));
723         return;
724     }
725
726     case SetArgumentCountIncludingThis:
727         write(AbstractHeap(Stack, CallFrameSlot::argumentCount));
728         return;
729
730     case GetRestLength:
731         read(Stack);
732         return;
733         
734     case GetLocal:
735         read(AbstractHeap(Stack, node->local()));
736         def(HeapLocation(StackLoc, AbstractHeap(Stack, node->local())), LazyNode(node));
737         return;
738         
739     case SetLocal:
740         write(AbstractHeap(Stack, node->local()));
741         def(HeapLocation(StackLoc, AbstractHeap(Stack, node->local())), LazyNode(node->child1().node()));
742         return;
743         
744     case GetStack: {
745         AbstractHeap heap(Stack, node->stackAccessData()->local);
746         read(heap);
747         def(HeapLocation(StackLoc, heap), LazyNode(node));
748         return;
749     }
750         
751     case PutStack: {
752         AbstractHeap heap(Stack, node->stackAccessData()->local);
753         write(heap);
754         def(HeapLocation(StackLoc, heap), LazyNode(node->child1().node()));
755         return;
756     }
757         
758     case LoadVarargs: {
759         read(World);
760         write(Heap);
761         LoadVarargsData* data = node->loadVarargsData();
762         write(AbstractHeap(Stack, data->count.offset()));
763         for (unsigned i = data->limit; i--;)
764             write(AbstractHeap(Stack, data->start.offset() + static_cast<int>(i)));
765         return;
766     }
767         
768     case ForwardVarargs: {
769         // We could be way more precise here.
770         read(Stack);
771         
772         LoadVarargsData* data = node->loadVarargsData();
773         write(AbstractHeap(Stack, data->count.offset()));
774         for (unsigned i = data->limit; i--;)
775             write(AbstractHeap(Stack, data->start.offset() + static_cast<int>(i)));
776         return;
777     }
778         
779     case GetByVal: {
780         ArrayMode mode = node->arrayMode();
781         LocationKind indexedPropertyLoc = indexedPropertyLocForResultType(node->result());
782         switch (mode.type()) {
783         case Array::SelectUsingPredictions:
784         case Array::Unprofiled:
785         case Array::SelectUsingArguments:
786             // Assume the worst since we don't have profiling yet.
787             read(World);
788             write(Heap);
789             return;
790             
791         case Array::ForceExit:
792             write(SideState);
793             return;
794             
795         case Array::Generic:
796             read(World);
797             write(Heap);
798             return;
799             
800         case Array::String:
801             if (mode.isOutOfBounds()) {
802                 read(World);
803                 write(Heap);
804                 return;
805             }
806             // This appears to read nothing because it's only reading immutable data.
807             def(PureValue(graph, node, mode.asWord()));
808             return;
809             
810         case Array::DirectArguments:
811             if (mode.isInBounds()) {
812                 read(DirectArgumentsProperties);
813                 def(HeapLocation(indexedPropertyLoc, DirectArgumentsProperties, graph.varArgChild(node, 0), graph.varArgChild(node, 1)), LazyNode(node));
814                 return;
815             }
816             read(World);
817             write(Heap);
818             return;
819             
820         case Array::ScopedArguments:
821             read(ScopeProperties);
822             def(HeapLocation(indexedPropertyLoc, ScopeProperties, graph.varArgChild(node, 0), graph.varArgChild(node, 1)), LazyNode(node));
823             return;
824             
825         case Array::Int32:
826             if (mode.isInBounds()) {
827                 read(Butterfly_publicLength);
828                 read(IndexedInt32Properties);
829                 def(HeapLocation(indexedPropertyLoc, IndexedInt32Properties, graph.varArgChild(node, 0), graph.varArgChild(node, 1)), LazyNode(node));
830                 return;
831             }
832             read(World);
833             write(Heap);
834             return;
835             
836         case Array::Double:
837             if (mode.isInBounds()) {
838                 read(Butterfly_publicLength);
839                 read(IndexedDoubleProperties);
840                 LocationKind kind = mode.isSaneChain() ? IndexedPropertyDoubleSaneChainLoc : IndexedPropertyDoubleLoc;
841                 def(HeapLocation(kind, IndexedDoubleProperties, graph.varArgChild(node, 0), graph.varArgChild(node, 1)), LazyNode(node));
842                 return;
843             }
844             read(World);
845             write(Heap);
846             return;
847             
848         case Array::Contiguous:
849             if (mode.isInBounds()) {
850                 read(Butterfly_publicLength);
851                 read(IndexedContiguousProperties);
852                 def(HeapLocation(indexedPropertyLoc, IndexedContiguousProperties, graph.varArgChild(node, 0), graph.varArgChild(node, 1)), LazyNode(node));
853                 return;
854             }
855             read(World);
856             write(Heap);
857             return;
858
859         case Array::Undecided:
860             def(PureValue(graph, node));
861             return;
862             
863         case Array::ArrayStorage:
864         case Array::SlowPutArrayStorage:
865             if (mode.isInBounds()) {
866                 read(Butterfly_vectorLength);
867                 read(IndexedArrayStorageProperties);
868                 return;
869             }
870             read(World);
871             write(Heap);
872             return;
873             
874         case Array::Int8Array:
875         case Array::Int16Array:
876         case Array::Int32Array:
877         case Array::Uint8Array:
878         case Array::Uint8ClampedArray:
879         case Array::Uint16Array:
880         case Array::Uint32Array:
881         case Array::Float32Array:
882         case Array::Float64Array:
883             read(TypedArrayProperties);
884             read(MiscFields);
885             def(HeapLocation(indexedPropertyLoc, TypedArrayProperties, graph.varArgChild(node, 0), graph.varArgChild(node, 1)), LazyNode(node));
886             return;
887         // We should not get an AnyTypedArray in a GetByVal as AnyTypedArray is only created from intrinsics, which
888         // are only added from Inline Caching a GetById.
889         case Array::AnyTypedArray:
890             DFG_CRASH(graph, node, "impossible array mode for get");
891             return;
892         }
893         RELEASE_ASSERT_NOT_REACHED();
894         return;
895     }
896         
897     case GetMyArgumentByVal:
898     case GetMyArgumentByValOutOfBounds: {
899         read(Stack);
900         // FIXME: It would be trivial to have a def here.
901         // https://bugs.webkit.org/show_bug.cgi?id=143077
902         return;
903     }
904
905     case PutByValDirect:
906     case PutByVal:
907     case PutByValAlias: {
908         ArrayMode mode = node->arrayMode();
909         Node* base = graph.varArgChild(node, 0).node();
910         Node* index = graph.varArgChild(node, 1).node();
911         Node* value = graph.varArgChild(node, 2).node();
912         LocationKind indexedPropertyLoc = indexedPropertyLocForResultType(node->result());
913
914         switch (mode.modeForPut().type()) {
915         case Array::SelectUsingPredictions:
916         case Array::SelectUsingArguments:
917         case Array::Unprofiled:
918         case Array::Undecided:
919             // Assume the worst since we don't have profiling yet.
920             read(World);
921             write(Heap);
922             return;
923             
924         case Array::ForceExit:
925             write(SideState);
926             return;
927             
928         case Array::Generic:
929             read(World);
930             write(Heap);
931             return;
932             
933         case Array::Int32:
934             if (node->arrayMode().isOutOfBounds()) {
935                 read(World);
936                 write(Heap);
937                 return;
938             }
939             read(Butterfly_publicLength);
940             read(Butterfly_vectorLength);
941             read(IndexedInt32Properties);
942             write(IndexedInt32Properties);
943             if (node->arrayMode().mayStoreToHole())
944                 write(Butterfly_publicLength);
945             def(HeapLocation(indexedPropertyLoc, IndexedInt32Properties, base, index), LazyNode(value));
946             return;
947             
948         case Array::Double:
949             if (node->arrayMode().isOutOfBounds()) {
950                 read(World);
951                 write(Heap);
952                 return;
953             }
954             read(Butterfly_publicLength);
955             read(Butterfly_vectorLength);
956             read(IndexedDoubleProperties);
957             write(IndexedDoubleProperties);
958             if (node->arrayMode().mayStoreToHole())
959                 write(Butterfly_publicLength);
960             def(HeapLocation(IndexedPropertyDoubleLoc, IndexedDoubleProperties, base, index), LazyNode(value));
961             def(HeapLocation(IndexedPropertyDoubleSaneChainLoc, IndexedDoubleProperties, base, index), LazyNode(value));
962             return;
963             
964         case Array::Contiguous:
965             if (node->arrayMode().isOutOfBounds()) {
966                 read(World);
967                 write(Heap);
968                 return;
969             }
970             read(Butterfly_publicLength);
971             read(Butterfly_vectorLength);
972             read(IndexedContiguousProperties);
973             write(IndexedContiguousProperties);
974             if (node->arrayMode().mayStoreToHole())
975                 write(Butterfly_publicLength);
976             def(HeapLocation(indexedPropertyLoc, IndexedContiguousProperties, base, index), LazyNode(value));
977             return;
978             
979         case Array::ArrayStorage:
980             if (node->arrayMode().isOutOfBounds()) {
981                 read(World);
982                 write(Heap);
983                 return;
984             }
985             read(Butterfly_publicLength);
986             read(Butterfly_vectorLength);
987             read(ArrayStorageProperties);
988             write(ArrayStorageProperties);
989             if (node->arrayMode().mayStoreToHole())
990                 write(Butterfly_publicLength);
991             return;
992
993         case Array::SlowPutArrayStorage:
994             if (node->arrayMode().mayStoreToHole()) {
995                 read(World);
996                 write(Heap);
997                 return;
998             }
999             read(Butterfly_publicLength);
1000             read(Butterfly_vectorLength);
1001             read(ArrayStorageProperties);
1002             write(ArrayStorageProperties);
1003             return;
1004
1005         case Array::Int8Array:
1006         case Array::Int16Array:
1007         case Array::Int32Array:
1008         case Array::Uint8Array:
1009         case Array::Uint8ClampedArray:
1010         case Array::Uint16Array:
1011         case Array::Uint32Array:
1012         case Array::Float32Array:
1013         case Array::Float64Array:
1014             read(MiscFields);
1015             write(TypedArrayProperties);
1016             // FIXME: We can't def() anything here because these operations truncate their inputs.
1017             // https://bugs.webkit.org/show_bug.cgi?id=134737
1018             return;
1019         case Array::AnyTypedArray:
1020         case Array::String:
1021         case Array::DirectArguments:
1022         case Array::ScopedArguments:
1023             DFG_CRASH(graph, node, "impossible array mode for put");
1024             return;
1025         }
1026         RELEASE_ASSERT_NOT_REACHED();
1027         return;
1028     }
1029         
1030     case CheckStructureOrEmpty:
1031     case CheckStructure:
1032         read(JSCell_structureID);
1033         return;
1034
1035     case CheckArray:
1036         read(JSCell_indexingType);
1037         read(JSCell_typeInfoType);
1038         read(JSCell_structureID);
1039         return;
1040
1041     case CheckTypeInfoFlags:
1042         read(JSCell_typeInfoFlags);
1043         def(HeapLocation(CheckTypeInfoFlagsLoc, JSCell_typeInfoFlags, node->child1()), LazyNode(node));
1044         return;
1045
1046     case ParseInt:
1047         // Note: We would have eliminated a ParseInt that has just a single child as an Int32Use inside fixup.
1048         if (node->child1().useKind() == StringUse && (!node->child2() || node->child2().useKind() == Int32Use)) {
1049             def(PureValue(node));
1050             return;
1051         }
1052
1053         read(World);
1054         write(Heap);
1055         return;
1056
1057     case OverridesHasInstance:
1058         read(JSCell_typeInfoFlags);
1059         def(HeapLocation(OverridesHasInstanceLoc, JSCell_typeInfoFlags, node->child1()), LazyNode(node));
1060         return;
1061
1062     case PutStructure:
1063         read(JSObject_butterfly);
1064         write(JSCell_structureID);
1065         write(JSCell_typeInfoType);
1066         write(JSCell_typeInfoFlags);
1067         write(JSCell_indexingType);
1068         return;
1069         
1070     case AllocatePropertyStorage:
1071     case ReallocatePropertyStorage:
1072         read(HeapObjectCount);
1073         write(HeapObjectCount);
1074         return;
1075         
1076     case NukeStructureAndSetButterfly:
1077         write(JSObject_butterfly);
1078         write(JSCell_structureID);
1079         def(HeapLocation(ButterflyLoc, JSObject_butterfly, node->child1()), LazyNode(node->child2().node()));
1080         return;
1081         
1082     case GetButterfly:
1083         read(JSObject_butterfly);
1084         def(HeapLocation(ButterflyLoc, JSObject_butterfly, node->child1()), LazyNode(node));
1085         return;
1086
1087     case CheckSubClass:
1088         def(PureValue(node, node->classInfo()));
1089         return;
1090
1091     case CallDOMGetter: {
1092         DOMJIT::CallDOMGetterSnippet* snippet = node->callDOMGetterData()->snippet;
1093         if (!snippet) {
1094             read(World);
1095             write(Heap);
1096             return;
1097         }
1098         DOMJIT::Effect effect = snippet->effect;
1099         if (effect.reads) {
1100             if (effect.reads == DOMJIT::HeapRange::top())
1101                 read(World);
1102             else
1103                 read(AbstractHeap(DOMState, effect.reads.rawRepresentation()));
1104         }
1105         if (effect.writes) {
1106             if (effect.writes == DOMJIT::HeapRange::top())
1107                 write(Heap);
1108             else
1109                 write(AbstractHeap(DOMState, effect.writes.rawRepresentation()));
1110         }
1111         if (effect.def != DOMJIT::HeapRange::top()) {
1112             DOMJIT::HeapRange range = effect.def;
1113             if (range == DOMJIT::HeapRange::none())
1114                 def(PureValue(node, bitwise_cast<uintptr_t>(node->callDOMGetterData()->customAccessorGetter)));
1115             else {
1116                 // Def with heap location. We do not include "GlobalObject" for that since this information is included in the base node.
1117                 // We only see the DOMJIT getter here. So just including "base" is ok.
1118                 def(HeapLocation(DOMStateLoc, AbstractHeap(DOMState, range.rawRepresentation()), node->child1()), LazyNode(node));
1119             }
1120         }
1121         return;
1122     }
1123
1124     case CallDOM: {
1125         const DOMJIT::Signature* signature = node->signature();
1126         DOMJIT::Effect effect = signature->effect;
1127         if (effect.reads) {
1128             if (effect.reads == DOMJIT::HeapRange::top())
1129                 read(World);
1130             else
1131                 read(AbstractHeap(DOMState, effect.reads.rawRepresentation()));
1132         }
1133         if (effect.writes) {
1134             if (effect.writes == DOMJIT::HeapRange::top())
1135                 write(Heap);
1136             else
1137                 write(AbstractHeap(DOMState, effect.writes.rawRepresentation()));
1138         }
1139         ASSERT_WITH_MESSAGE(effect.def == DOMJIT::HeapRange::top(), "Currently, we do not accept any def for CallDOM.");
1140         return;
1141     }
1142
1143     case Arrayify:
1144     case ArrayifyToStructure:
1145         read(JSCell_structureID);
1146         read(JSCell_indexingType);
1147         read(JSObject_butterfly);
1148         write(JSCell_structureID);
1149         write(JSCell_indexingType);
1150         write(JSObject_butterfly);
1151         write(Watchpoint_fire);
1152         return;
1153         
1154     case GetIndexedPropertyStorage:
1155         if (node->arrayMode().type() == Array::String) {
1156             def(PureValue(node, node->arrayMode().asWord()));
1157             return;
1158         }
1159         read(MiscFields);
1160         def(HeapLocation(IndexedPropertyStorageLoc, MiscFields, node->child1()), LazyNode(node));
1161         return;
1162         
1163     case GetTypedArrayByteOffset:
1164         read(MiscFields);
1165         def(HeapLocation(TypedArrayByteOffsetLoc, MiscFields, node->child1()), LazyNode(node));
1166         return;
1167
1168     case GetPrototypeOf: {
1169         switch (node->child1().useKind()) {
1170         case ArrayUse:
1171         case FunctionUse:
1172         case FinalObjectUse:
1173             read(JSCell_structureID);
1174             read(JSObject_butterfly);
1175             read(NamedProperties); // Poly proto could load prototype from its slot.
1176             def(HeapLocation(PrototypeLoc, NamedProperties, node->child1()), LazyNode(node));
1177             return;
1178         default:
1179             read(World);
1180             write(Heap);
1181             return;
1182         }
1183     }
1184         
1185     case GetByOffset:
1186     case GetGetterSetterByOffset: {
1187         unsigned identifierNumber = node->storageAccessData().identifierNumber;
1188         AbstractHeap heap(NamedProperties, identifierNumber);
1189         read(heap);
1190         def(HeapLocation(NamedPropertyLoc, heap, node->child2()), LazyNode(node));
1191         return;
1192     }
1193
1194     case TryGetById: {
1195         read(Heap);
1196         return;
1197     }
1198
1199     case MultiGetByOffset: {
1200         read(JSCell_structureID);
1201         read(JSObject_butterfly);
1202         AbstractHeap heap(NamedProperties, node->multiGetByOffsetData().identifierNumber);
1203         read(heap);
1204         def(HeapLocation(NamedPropertyLoc, heap, node->child1()), LazyNode(node));
1205         return;
1206     }
1207         
1208     case MultiPutByOffset: {
1209         read(JSCell_structureID);
1210         read(JSObject_butterfly);
1211         AbstractHeap heap(NamedProperties, node->multiPutByOffsetData().identifierNumber);
1212         write(heap);
1213         if (node->multiPutByOffsetData().writesStructures())
1214             write(JSCell_structureID);
1215         if (node->multiPutByOffsetData().reallocatesStorage())
1216             write(JSObject_butterfly);
1217         def(HeapLocation(NamedPropertyLoc, heap, node->child1()), LazyNode(node->child2().node()));
1218         return;
1219     }
1220         
1221     case PutByOffset: {
1222         unsigned identifierNumber = node->storageAccessData().identifierNumber;
1223         AbstractHeap heap(NamedProperties, identifierNumber);
1224         write(heap);
1225         def(HeapLocation(NamedPropertyLoc, heap, node->child2()), LazyNode(node->child3().node()));
1226         return;
1227     }
1228         
1229     case GetArrayLength: {
1230         ArrayMode mode = node->arrayMode();
1231         switch (mode.type()) {
1232         case Array::Undecided:
1233         case Array::Int32:
1234         case Array::Double:
1235         case Array::Contiguous:
1236         case Array::ArrayStorage:
1237         case Array::SlowPutArrayStorage:
1238             read(Butterfly_publicLength);
1239             def(HeapLocation(ArrayLengthLoc, Butterfly_publicLength, node->child1()), LazyNode(node));
1240             return;
1241             
1242         case Array::String:
1243             def(PureValue(node, mode.asWord()));
1244             return;
1245
1246         case Array::DirectArguments:
1247         case Array::ScopedArguments:
1248             read(MiscFields);
1249             def(HeapLocation(ArrayLengthLoc, MiscFields, node->child1()), LazyNode(node));
1250             return;
1251
1252         default:
1253             ASSERT(mode.isSomeTypedArrayView());
1254             read(MiscFields);
1255             def(HeapLocation(ArrayLengthLoc, MiscFields, node->child1()), LazyNode(node));
1256             return;
1257         }
1258     }
1259
1260     case GetVectorLength: {
1261         ArrayMode mode = node->arrayMode();
1262         switch (mode.type()) {
1263         case Array::ArrayStorage:
1264         case Array::SlowPutArrayStorage:
1265             read(Butterfly_vectorLength);
1266             def(HeapLocation(VectorLengthLoc, Butterfly_vectorLength, node->child1()), LazyNode(node));
1267             return;
1268
1269         default:
1270             RELEASE_ASSERT_NOT_REACHED();
1271             return;
1272         }
1273     }
1274         
1275     case GetClosureVar:
1276         read(AbstractHeap(ScopeProperties, node->scopeOffset().offset()));
1277         def(HeapLocation(ClosureVariableLoc, AbstractHeap(ScopeProperties, node->scopeOffset().offset()), node->child1()), LazyNode(node));
1278         return;
1279         
1280     case PutClosureVar:
1281         write(AbstractHeap(ScopeProperties, node->scopeOffset().offset()));
1282         def(HeapLocation(ClosureVariableLoc, AbstractHeap(ScopeProperties, node->scopeOffset().offset()), node->child1()), LazyNode(node->child2().node()));
1283         return;
1284
1285     case GetRegExpObjectLastIndex:
1286         read(RegExpObject_lastIndex);
1287         def(HeapLocation(RegExpObjectLastIndexLoc, RegExpObject_lastIndex, node->child1()), LazyNode(node));
1288         return;
1289
1290     case SetRegExpObjectLastIndex:
1291         write(RegExpObject_lastIndex);
1292         def(HeapLocation(RegExpObjectLastIndexLoc, RegExpObject_lastIndex, node->child1()), LazyNode(node->child2().node()));
1293         return;
1294
1295     case RecordRegExpCachedResult:
1296         write(RegExpState);
1297         return;
1298         
1299     case GetFromArguments: {
1300         AbstractHeap heap(DirectArgumentsProperties, node->capturedArgumentsOffset().offset());
1301         read(heap);
1302         def(HeapLocation(DirectArgumentsLoc, heap, node->child1()), LazyNode(node));
1303         return;
1304     }
1305         
1306     case PutToArguments: {
1307         AbstractHeap heap(DirectArgumentsProperties, node->capturedArgumentsOffset().offset());
1308         write(heap);
1309         def(HeapLocation(DirectArgumentsLoc, heap, node->child1()), LazyNode(node->child2().node()));
1310         return;
1311     }
1312
1313     case GetArgument: {
1314         read(Stack);
1315         // FIXME: It would be trivial to have a def here.
1316         // https://bugs.webkit.org/show_bug.cgi?id=143077
1317         return;
1318     }
1319         
1320     case GetGlobalVar:
1321     case GetGlobalLexicalVariable:
1322         read(AbstractHeap(Absolute, node->variablePointer()));
1323         def(HeapLocation(GlobalVariableLoc, AbstractHeap(Absolute, node->variablePointer())), LazyNode(node));
1324         return;
1325         
1326     case PutGlobalVariable:
1327         write(AbstractHeap(Absolute, node->variablePointer()));
1328         def(HeapLocation(GlobalVariableLoc, AbstractHeap(Absolute, node->variablePointer())), LazyNode(node->child2().node()));
1329         return;
1330
1331     case NewArrayWithSize:
1332         read(HeapObjectCount);
1333         write(HeapObjectCount);
1334         return;
1335
1336     case NewTypedArray:
1337         switch (node->child1().useKind()) {
1338         case Int32Use:
1339             read(HeapObjectCount);
1340             write(HeapObjectCount);
1341             return;
1342         case UntypedUse:
1343             read(World);
1344             write(Heap);
1345             return;
1346         default:
1347             DFG_CRASH(graph, node, "Bad use kind");
1348         }
1349         break;
1350
1351     case NewArrayWithSpread: {
1352         // This also reads from JSFixedArray's data store, but we don't have any way of describing that yet.
1353         read(HeapObjectCount);
1354         for (unsigned i = 0; i < node->numChildren(); i++) {
1355             Node* child = graph.varArgChild(node, i).node();
1356             if (child->op() == PhantomSpread) {
1357                 read(Stack);
1358                 break;
1359             }
1360         }
1361         write(HeapObjectCount);
1362         return;
1363     }
1364
1365     case Spread: {
1366         if (node->child1()->op() == PhantomNewArrayBuffer) {
1367             read(MiscFields);
1368             return;
1369         }
1370
1371         if (node->child1()->op() == PhantomCreateRest) {
1372             read(Stack);
1373             write(HeapObjectCount);
1374             return;
1375         }
1376
1377         read(World);
1378         write(Heap);
1379         return;
1380     }
1381
1382     case NewArray: {
1383         read(HeapObjectCount);
1384         write(HeapObjectCount);
1385
1386         unsigned numElements = node->numChildren();
1387
1388         def(HeapLocation(ArrayLengthLoc, Butterfly_publicLength, node),
1389             LazyNode(graph.freeze(jsNumber(numElements))));
1390
1391         if (!numElements)
1392             return;
1393
1394         AbstractHeap heap;
1395         LocationKind indexedPropertyLoc;
1396         switch (node->indexingType()) {
1397         case ALL_DOUBLE_INDEXING_TYPES:
1398             heap = IndexedDoubleProperties;
1399             indexedPropertyLoc = IndexedPropertyDoubleLoc;
1400             break;
1401
1402         case ALL_INT32_INDEXING_TYPES:
1403             heap = IndexedInt32Properties;
1404             indexedPropertyLoc = IndexedPropertyJSLoc;
1405             break;
1406
1407         case ALL_CONTIGUOUS_INDEXING_TYPES:
1408             heap = IndexedContiguousProperties;
1409             indexedPropertyLoc = IndexedPropertyJSLoc;
1410             break;
1411
1412         default:
1413             return;
1414         }
1415
1416         if (numElements < graph.m_uint32ValuesInUse.size()) {
1417             for (unsigned operandIdx = 0; operandIdx < numElements; ++operandIdx) {
1418                 Edge use = graph.m_varArgChildren[node->firstChild() + operandIdx];
1419                 def(HeapLocation(indexedPropertyLoc, heap, node, LazyNode(graph.freeze(jsNumber(operandIdx)))),
1420                     LazyNode(use.node()));
1421             }
1422         } else {
1423             for (uint32_t operandIdx : graph.m_uint32ValuesInUse) {
1424                 if (operandIdx >= numElements)
1425                     continue;
1426                 Edge use = graph.m_varArgChildren[node->firstChild() + operandIdx];
1427                 // operandIdx comes from graph.m_uint32ValuesInUse and thus is guaranteed to be already frozen
1428                 def(HeapLocation(indexedPropertyLoc, heap, node, LazyNode(graph.freeze(jsNumber(operandIdx)))),
1429                     LazyNode(use.node()));
1430             }
1431         }
1432         return;
1433     }
1434
1435     case NewArrayBuffer: {
1436         read(HeapObjectCount);
1437         write(HeapObjectCount);
1438
1439         auto* array = node->castOperand<JSImmutableButterfly*>();
1440         unsigned numElements = array->length();
1441         def(HeapLocation(ArrayLengthLoc, Butterfly_publicLength, node),
1442             LazyNode(graph.freeze(jsNumber(numElements))));
1443
1444         AbstractHeap heap;
1445         LocationKind indexedPropertyLoc;
1446         NodeType op = JSConstant;
1447         switch (node->indexingType()) {
1448         case ALL_DOUBLE_INDEXING_TYPES:
1449             heap = IndexedDoubleProperties;
1450             indexedPropertyLoc = IndexedPropertyDoubleLoc;
1451             op = DoubleConstant;
1452             break;
1453
1454         case ALL_INT32_INDEXING_TYPES:
1455             heap = IndexedInt32Properties;
1456             indexedPropertyLoc = IndexedPropertyJSLoc;
1457             break;
1458
1459         case ALL_CONTIGUOUS_INDEXING_TYPES:
1460             heap = IndexedContiguousProperties;
1461             indexedPropertyLoc = IndexedPropertyJSLoc;
1462             break;
1463
1464         default:
1465             return;
1466         }
1467
1468         if (numElements < graph.m_uint32ValuesInUse.size()) {
1469             for (unsigned index = 0; index < numElements; ++index) {
1470                 def(HeapLocation(indexedPropertyLoc, heap, node, LazyNode(graph.freeze(jsNumber(index)))),
1471                     LazyNode(graph.freeze(array->get(index)), op));
1472             }
1473         } else {
1474             Vector<uint32_t> possibleIndices;
1475             for (uint32_t index : graph.m_uint32ValuesInUse) {
1476                 if (index >= numElements)
1477                     continue;
1478                 possibleIndices.append(index);
1479             }
1480             for (uint32_t index : possibleIndices) {
1481                 def(HeapLocation(indexedPropertyLoc, heap, node, LazyNode(graph.freeze(jsNumber(index)))),
1482                     LazyNode(graph.freeze(array->get(index)), op));
1483             }
1484         }
1485         return;
1486     }
1487
1488     case CreateRest: {
1489         if (!graph.isWatchingHavingABadTimeWatchpoint(node)) {
1490             // This means we're already having a bad time.
1491             read(World);
1492             write(Heap);
1493             return;
1494         }
1495         read(Stack);
1496         read(HeapObjectCount);
1497         write(HeapObjectCount);
1498         return;
1499     }
1500
1501     case ObjectCreate: {
1502         switch (node->child1().useKind()) {
1503         case ObjectUse:
1504             read(HeapObjectCount);
1505             write(HeapObjectCount);
1506             return;
1507         case UntypedUse:
1508             read(World);
1509             write(Heap);
1510             return;
1511         default:
1512             RELEASE_ASSERT_NOT_REACHED();
1513             return;
1514         }
1515     }
1516
1517
1518     case NewObject:
1519     case NewRegexp:
1520     case NewStringObject:
1521     case PhantomNewObject:
1522     case MaterializeNewObject:
1523     case PhantomNewFunction:
1524     case PhantomNewGeneratorFunction:
1525     case PhantomNewAsyncFunction:
1526     case PhantomNewAsyncGeneratorFunction:
1527     case PhantomCreateActivation:
1528     case MaterializeCreateActivation:
1529     case PhantomNewRegexp:
1530         read(HeapObjectCount);
1531         write(HeapObjectCount);
1532         return;
1533
1534     case NewFunction:
1535     case NewGeneratorFunction:
1536     case NewAsyncGeneratorFunction:
1537     case NewAsyncFunction:
1538         if (node->castOperand<FunctionExecutable*>()->singletonFunction()->isStillValid())
1539             write(Watchpoint_fire);
1540         read(HeapObjectCount);
1541         write(HeapObjectCount);
1542         return;
1543
1544     case RegExpExec:
1545     case RegExpTest:
1546         // Even if we've proven known input types as RegExpObject and String,
1547         // accessing lastIndex is effectful if it's a global regexp.
1548         read(World);
1549         write(Heap);
1550         return;
1551
1552     case RegExpMatchFast:
1553         read(RegExpState);
1554         read(RegExpObject_lastIndex);
1555         write(RegExpState);
1556         write(RegExpObject_lastIndex);
1557         return;
1558
1559     case RegExpExecNonGlobalOrSticky:
1560     case RegExpMatchFastGlobal:
1561         read(RegExpState);
1562         write(RegExpState);
1563         return;
1564
1565     case StringReplace:
1566     case StringReplaceRegExp:
1567         if (node->child1().useKind() == StringUse
1568             && node->child2().useKind() == RegExpObjectUse
1569             && node->child3().useKind() == StringUse) {
1570             read(RegExpState);
1571             read(RegExpObject_lastIndex);
1572             write(RegExpState);
1573             write(RegExpObject_lastIndex);
1574             return;
1575         }
1576         read(World);
1577         write(Heap);
1578         return;
1579
1580     case StringCharAt:
1581         if (node->arrayMode().isOutOfBounds()) {
1582             read(World);
1583             write(Heap);
1584             return;
1585         }
1586         def(PureValue(node));
1587         return;
1588
1589     case CompareBelow:
1590     case CompareBelowEq:
1591         def(PureValue(node));
1592         return;
1593         
1594     case CompareEq:
1595     case CompareLess:
1596     case CompareLessEq:
1597     case CompareGreater:
1598     case CompareGreaterEq:
1599         if (node->isBinaryUseKind(StringUse)) {
1600             read(HeapObjectCount);
1601             write(HeapObjectCount);
1602             return;
1603         }
1604
1605         if (node->isBinaryUseKind(UntypedUse)) {
1606             read(World);
1607             write(Heap);
1608             return;
1609         }
1610
1611         def(PureValue(node));
1612         return;
1613
1614     case ToString:
1615     case CallStringConstructor:
1616         switch (node->child1().useKind()) {
1617         case StringObjectUse:
1618         case StringOrStringObjectUse:
1619             // These don't def a pure value, unfortunately. I'll avoid load-eliminating these for
1620             // now.
1621             return;
1622             
1623         case CellUse:
1624         case UntypedUse:
1625             read(World);
1626             write(Heap);
1627             return;
1628
1629         case Int32Use:
1630         case Int52RepUse:
1631         case DoubleRepUse:
1632         case NotCellUse:
1633             def(PureValue(node));
1634             return;
1635             
1636         default:
1637             RELEASE_ASSERT_NOT_REACHED();
1638             return;
1639         }
1640         
1641     case CountExecution:
1642     case SuperSamplerBegin:
1643     case SuperSamplerEnd:
1644         read(InternalState);
1645         write(InternalState);
1646         return;
1647         
1648     case LogShadowChickenPrologue:
1649     case LogShadowChickenTail:
1650         write(SideState);
1651         return;
1652
1653     case MapHash:
1654         def(PureValue(node));
1655         return;
1656
1657     case NormalizeMapKey:
1658         def(PureValue(node));
1659         return;
1660
1661     case GetMapBucket: {
1662         Edge& mapEdge = node->child1();
1663         Edge& keyEdge = node->child2();
1664         AbstractHeapKind heap = (mapEdge.useKind() == MapObjectUse) ? JSMapFields : JSSetFields;
1665         read(heap);
1666         def(HeapLocation(MapBucketLoc, heap, mapEdge, keyEdge), LazyNode(node));
1667         return;
1668     }
1669
1670     case GetMapBucketHead: {
1671         Edge& mapEdge = node->child1();
1672         AbstractHeapKind heap = (mapEdge.useKind() == MapObjectUse) ? JSMapFields : JSSetFields;
1673         read(heap);
1674         def(HeapLocation(MapBucketHeadLoc, heap, mapEdge), LazyNode(node));
1675         return;
1676     }
1677
1678     case GetMapBucketNext: {
1679         AbstractHeapKind heap = (node->bucketOwnerType() == BucketOwnerType::Map) ? JSMapFields : JSSetFields;
1680         read(heap);
1681         Edge& bucketEdge = node->child1();
1682         def(HeapLocation(MapBucketNextLoc, heap, bucketEdge), LazyNode(node));
1683         return;
1684     }
1685
1686     case LoadKeyFromMapBucket: {
1687         AbstractHeapKind heap = (node->bucketOwnerType() == BucketOwnerType::Map) ? JSMapFields : JSSetFields;
1688         read(heap);
1689         Edge& bucketEdge = node->child1();
1690         def(HeapLocation(MapBucketKeyLoc, heap, bucketEdge), LazyNode(node));
1691         return;
1692     }
1693
1694     case LoadValueFromMapBucket: {
1695         AbstractHeapKind heap = (node->bucketOwnerType() == BucketOwnerType::Map) ? JSMapFields : JSSetFields;
1696         read(heap);
1697         Edge& bucketEdge = node->child1();
1698         def(HeapLocation(MapBucketValueLoc, heap, bucketEdge), LazyNode(node));
1699         return;
1700     }
1701
1702     case WeakMapGet: {
1703         Edge& mapEdge = node->child1();
1704         Edge& keyEdge = node->child2();
1705         AbstractHeapKind heap = (mapEdge.useKind() == WeakMapObjectUse) ? JSWeakMapFields : JSWeakSetFields;
1706         read(heap);
1707         def(HeapLocation(WeakMapGetLoc, heap, mapEdge, keyEdge), LazyNode(node));
1708         return;
1709     }
1710
1711     case SetAdd: {
1712         Edge& mapEdge = node->child1();
1713         Edge& keyEdge = node->child2();
1714         write(JSSetFields);
1715         def(HeapLocation(MapBucketLoc, JSSetFields, mapEdge, keyEdge), LazyNode(node));
1716         return;
1717     }
1718
1719     case MapSet: {
1720         Edge& mapEdge = graph.varArgChild(node, 0);
1721         Edge& keyEdge = graph.varArgChild(node, 1);
1722         write(JSMapFields);
1723         def(HeapLocation(MapBucketLoc, JSMapFields, mapEdge, keyEdge), LazyNode(node));
1724         return;
1725     }
1726
1727     case WeakSetAdd: {
1728         Edge& mapEdge = node->child1();
1729         Edge& keyEdge = node->child2();
1730         write(JSWeakSetFields);
1731         def(HeapLocation(WeakMapGetLoc, JSWeakSetFields, mapEdge, keyEdge), LazyNode(keyEdge.node()));
1732         return;
1733     }
1734
1735     case WeakMapSet: {
1736         Edge& mapEdge = graph.varArgChild(node, 0);
1737         Edge& keyEdge = graph.varArgChild(node, 1);
1738         Edge& valueEdge = graph.varArgChild(node, 2);
1739         write(JSWeakMapFields);
1740         def(HeapLocation(WeakMapGetLoc, JSWeakMapFields, mapEdge, keyEdge), LazyNode(valueEdge.node()));
1741         return;
1742     }
1743
1744     case ExtractValueFromWeakMapGet:
1745         def(PureValue(node));
1746         return;
1747
1748     case StringSlice:
1749         def(PureValue(node));
1750         return;
1751
1752     case ToLowerCase:
1753         def(PureValue(node));
1754         return;
1755
1756     case NumberToStringWithValidRadixConstant:
1757         def(PureValue(node, node->validRadixConstant()));
1758         return;
1759
1760     case DataViewGetFloat:
1761     case DataViewGetInt: {
1762         read(MiscFields);
1763         read(TypedArrayProperties);
1764         LocationKind indexedPropertyLoc = indexedPropertyLocForResultType(node->result());
1765         def(HeapLocation(indexedPropertyLoc, AbstractHeap(TypedArrayProperties, node->dataViewData().asQuadWord),
1766             node->child1(), node->child2(), node->child3()), LazyNode(node));
1767         return;
1768     }
1769
1770     case DataViewSet: {
1771         read(MiscFields);
1772         read(TypedArrayProperties);
1773         write(TypedArrayProperties);
1774         return;
1775     }
1776
1777     case LastNodeType:
1778         RELEASE_ASSERT_NOT_REACHED();
1779         return;
1780     }
1781     
1782     DFG_CRASH(graph, node, toCString("Unrecognized node type: ", Graph::opName(node->op())).data());
1783 }
1784
1785 class NoOpClobberize {
1786 public:
1787     NoOpClobberize() { }
1788     template<typename... T>
1789     void operator()(T...) const { }
1790 };
1791
1792 class CheckClobberize {
1793 public:
1794     CheckClobberize()
1795         : m_result(false)
1796     {
1797     }
1798     
1799     template<typename... T>
1800     void operator()(T...) const { m_result = true; }
1801     
1802     bool result() const { return m_result; }
1803     
1804 private:
1805     mutable bool m_result;
1806 };
1807
1808 bool doesWrites(Graph&, Node*);
1809
1810 class AbstractHeapOverlaps {
1811 public:
1812     AbstractHeapOverlaps(AbstractHeap heap)
1813         : m_heap(heap)
1814         , m_result(false)
1815     {
1816     }
1817     
1818     void operator()(AbstractHeap otherHeap) const
1819     {
1820         if (m_result)
1821             return;
1822         m_result = m_heap.overlaps(otherHeap);
1823     }
1824     
1825     bool result() const { return m_result; }
1826
1827 private:
1828     AbstractHeap m_heap;
1829     mutable bool m_result;
1830 };
1831
1832 bool accessesOverlap(Graph&, Node*, AbstractHeap);
1833 bool writesOverlap(Graph&, Node*, AbstractHeap);
1834
1835 bool clobbersHeap(Graph&, Node*);
1836
1837 // We would have used bind() for these, but because of the overlaoding that we are doing,
1838 // it's quite a bit of clearer to just write this out the traditional way.
1839
1840 template<typename T>
1841 class ReadMethodClobberize {
1842 public:
1843     ReadMethodClobberize(T& value)
1844         : m_value(value)
1845     {
1846     }
1847     
1848     void operator()(AbstractHeap heap) const
1849     {
1850         m_value.read(heap);
1851     }
1852 private:
1853     T& m_value;
1854 };
1855
1856 template<typename T>
1857 class WriteMethodClobberize {
1858 public:
1859     WriteMethodClobberize(T& value)
1860         : m_value(value)
1861     {
1862     }
1863     
1864     void operator()(AbstractHeap heap) const
1865     {
1866         m_value.write(heap);
1867     }
1868 private:
1869     T& m_value;
1870 };
1871
1872 template<typename T>
1873 class DefMethodClobberize {
1874 public:
1875     DefMethodClobberize(T& value)
1876         : m_value(value)
1877     {
1878     }
1879     
1880     void operator()(PureValue value) const
1881     {
1882         m_value.def(value);
1883     }
1884     
1885     void operator()(HeapLocation location, LazyNode node) const
1886     {
1887         m_value.def(location, node);
1888     }
1889
1890 private:
1891     T& m_value;
1892 };
1893
1894 template<typename Adaptor>
1895 void clobberize(Graph& graph, Node* node, Adaptor& adaptor)
1896 {
1897     ReadMethodClobberize<Adaptor> read(adaptor);
1898     WriteMethodClobberize<Adaptor> write(adaptor);
1899     DefMethodClobberize<Adaptor> def(adaptor);
1900     clobberize(graph, node, read, write, def);
1901 }
1902
1903 } } // namespace JSC::DFG
1904
1905 #endif // ENABLE(DFG_JIT)