Rename activation to be more in line with spec language
[WebKit-https.git] / Source / JavaScriptCore / dfg / DFGByteCodeParser.cpp
1  /*
2  * Copyright (C) 2011, 2012, 2013, 2014 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 "DFGByteCodeParser.h"
28
29 #if ENABLE(DFG_JIT)
30
31 #include "ArrayConstructor.h"
32 #include "CallLinkStatus.h"
33 #include "CodeBlock.h"
34 #include "CodeBlockWithJITType.h"
35 #include "DFGArrayMode.h"
36 #include "DFGCapabilities.h"
37 #include "DFGJITCode.h"
38 #include "GetByIdStatus.h"
39 #include "Heap.h"
40 #include "JSLexicalEnvironment.h"
41 #include "JSCInlines.h"
42 #include "PreciseJumpTargets.h"
43 #include "PutByIdStatus.h"
44 #include "StackAlignment.h"
45 #include "StringConstructor.h"
46 #include <wtf/CommaPrinter.h>
47 #include <wtf/HashMap.h>
48 #include <wtf/MathExtras.h>
49 #include <wtf/StdLibExtras.h>
50
51 namespace JSC { namespace DFG {
52
53 static const bool verbose = false;
54
55 class ConstantBufferKey {
56 public:
57     ConstantBufferKey()
58         : m_codeBlock(0)
59         , m_index(0)
60     {
61     }
62     
63     ConstantBufferKey(WTF::HashTableDeletedValueType)
64         : m_codeBlock(0)
65         , m_index(1)
66     {
67     }
68     
69     ConstantBufferKey(CodeBlock* codeBlock, unsigned index)
70         : m_codeBlock(codeBlock)
71         , m_index(index)
72     {
73     }
74     
75     bool operator==(const ConstantBufferKey& other) const
76     {
77         return m_codeBlock == other.m_codeBlock
78             && m_index == other.m_index;
79     }
80     
81     unsigned hash() const
82     {
83         return WTF::PtrHash<CodeBlock*>::hash(m_codeBlock) ^ m_index;
84     }
85     
86     bool isHashTableDeletedValue() const
87     {
88         return !m_codeBlock && m_index;
89     }
90     
91     CodeBlock* codeBlock() const { return m_codeBlock; }
92     unsigned index() const { return m_index; }
93     
94 private:
95     CodeBlock* m_codeBlock;
96     unsigned m_index;
97 };
98
99 struct ConstantBufferKeyHash {
100     static unsigned hash(const ConstantBufferKey& key) { return key.hash(); }
101     static bool equal(const ConstantBufferKey& a, const ConstantBufferKey& b)
102     {
103         return a == b;
104     }
105     
106     static const bool safeToCompareToEmptyOrDeleted = true;
107 };
108
109 } } // namespace JSC::DFG
110
111 namespace WTF {
112
113 template<typename T> struct DefaultHash;
114 template<> struct DefaultHash<JSC::DFG::ConstantBufferKey> {
115     typedef JSC::DFG::ConstantBufferKeyHash Hash;
116 };
117
118 template<typename T> struct HashTraits;
119 template<> struct HashTraits<JSC::DFG::ConstantBufferKey> : SimpleClassHashTraits<JSC::DFG::ConstantBufferKey> { };
120
121 } // namespace WTF
122
123 namespace JSC { namespace DFG {
124
125 // === ByteCodeParser ===
126 //
127 // This class is used to compile the dataflow graph from a CodeBlock.
128 class ByteCodeParser {
129 public:
130     ByteCodeParser(Graph& graph)
131         : m_vm(&graph.m_vm)
132         , m_codeBlock(graph.m_codeBlock)
133         , m_profiledBlock(graph.m_profiledBlock)
134         , m_graph(graph)
135         , m_currentBlock(0)
136         , m_currentIndex(0)
137         , m_constantUndefined(graph.freeze(jsUndefined()))
138         , m_constantNull(graph.freeze(jsNull()))
139         , m_constantNaN(graph.freeze(jsNumber(PNaN)))
140         , m_constantOne(graph.freeze(jsNumber(1)))
141         , m_numArguments(m_codeBlock->numParameters())
142         , m_numLocals(m_codeBlock->m_numCalleeRegisters)
143         , m_parameterSlots(0)
144         , m_numPassedVarArgs(0)
145         , m_inlineStackTop(0)
146         , m_haveBuiltOperandMaps(false)
147         , m_currentInstruction(0)
148     {
149         ASSERT(m_profiledBlock);
150     }
151     
152     // Parse a full CodeBlock of bytecode.
153     bool parse();
154     
155 private:
156     struct InlineStackEntry;
157
158     // Just parse from m_currentIndex to the end of the current CodeBlock.
159     void parseCodeBlock();
160     
161     void ensureLocals(unsigned newNumLocals)
162     {
163         if (newNumLocals <= m_numLocals)
164             return;
165         m_numLocals = newNumLocals;
166         for (size_t i = 0; i < m_graph.numBlocks(); ++i)
167             m_graph.block(i)->ensureLocals(newNumLocals);
168     }
169
170     // Helper for min and max.
171     bool handleMinMax(int resultOperand, NodeType op, int registerOffset, int argumentCountIncludingThis);
172     
173     // Handle calls. This resolves issues surrounding inlining and intrinsics.
174     void handleCall(
175         int result, NodeType op, InlineCallFrame::Kind, unsigned instructionSize,
176         Node* callTarget, int argCount, int registerOffset, CallLinkStatus,
177         SpeculatedType prediction);
178     void handleCall(
179         int result, NodeType op, InlineCallFrame::Kind, unsigned instructionSize,
180         Node* callTarget, int argCount, int registerOffset, CallLinkStatus);
181     void handleCall(int result, NodeType op, CodeSpecializationKind, unsigned instructionSize, int callee, int argCount, int registerOffset);
182     void handleCall(Instruction* pc, NodeType op, CodeSpecializationKind);
183     void emitFunctionChecks(CallVariant, Node* callTarget, int registerOffset, CodeSpecializationKind);
184     void undoFunctionChecks(CallVariant);
185     void emitArgumentPhantoms(int registerOffset, int argumentCountIncludingThis, CodeSpecializationKind);
186     unsigned inliningCost(CallVariant, int argumentCountIncludingThis, CodeSpecializationKind); // Return UINT_MAX if it's not an inlining candidate. By convention, intrinsics have a cost of 1.
187     // Handle inlining. Return true if it succeeded, false if we need to plant a call.
188     bool handleInlining(Node* callTargetNode, int resultOperand, const CallLinkStatus&, int registerOffset, int argumentCountIncludingThis, unsigned nextOffset, NodeType callOp, InlineCallFrame::Kind, SpeculatedType prediction);
189     enum CallerLinkability { CallerDoesNormalLinking, CallerLinksManually };
190     bool attemptToInlineCall(Node* callTargetNode, int resultOperand, CallVariant, int registerOffset, int argumentCountIncludingThis, unsigned nextOffset, InlineCallFrame::Kind, CallerLinkability, SpeculatedType prediction, unsigned& inliningBalance);
191     void inlineCall(Node* callTargetNode, int resultOperand, CallVariant, int registerOffset, int argumentCountIncludingThis, unsigned nextOffset, InlineCallFrame::Kind, CallerLinkability);
192     void cancelLinkingForBlock(InlineStackEntry*, BasicBlock*); // Only works when the given block is the last one to have been added for that inline stack entry.
193     // Handle intrinsic functions. Return true if it succeeded, false if we need to plant a call.
194     bool handleIntrinsic(int resultOperand, Intrinsic, int registerOffset, int argumentCountIncludingThis, SpeculatedType prediction);
195     bool handleTypedArrayConstructor(int resultOperand, InternalFunction*, int registerOffset, int argumentCountIncludingThis, TypedArrayType);
196     bool handleConstantInternalFunction(int resultOperand, InternalFunction*, int registerOffset, int argumentCountIncludingThis, CodeSpecializationKind);
197     Node* handlePutByOffset(Node* base, unsigned identifier, PropertyOffset, Node* value);
198     Node* handleGetByOffset(SpeculatedType, Node* base, const StructureSet&, unsigned identifierNumber, PropertyOffset, NodeType op = GetByOffset);
199     void handleGetById(
200         int destinationOperand, SpeculatedType, Node* base, unsigned identifierNumber,
201         const GetByIdStatus&);
202     void emitPutById(
203         Node* base, unsigned identifierNumber, Node* value,  const PutByIdStatus&, bool isDirect);
204     void handlePutById(
205         Node* base, unsigned identifierNumber, Node* value, const PutByIdStatus&,
206         bool isDirect);
207     void emitChecks(const ConstantStructureCheckVector&);
208
209     Node* getScope(unsigned skipCount);
210     
211     void prepareToParseBlock();
212     void clearCaches();
213
214     // Parse a single basic block of bytecode instructions.
215     bool parseBlock(unsigned limit);
216     // Link block successors.
217     void linkBlock(BasicBlock*, Vector<BasicBlock*>& possibleTargets);
218     void linkBlocks(Vector<UnlinkedBlock>& unlinkedBlocks, Vector<BasicBlock*>& possibleTargets);
219     
220     VariableAccessData* newVariableAccessData(VirtualRegister operand, bool isCaptured)
221     {
222         ASSERT(!operand.isConstant());
223         
224         m_graph.m_variableAccessData.append(VariableAccessData(operand, isCaptured));
225         return &m_graph.m_variableAccessData.last();
226     }
227     
228     // Get/Set the operands/result of a bytecode instruction.
229     Node* getDirect(VirtualRegister operand)
230     {
231         ASSERT(!operand.isConstant());
232
233         // Is this an argument?
234         if (operand.isArgument())
235             return getArgument(operand);
236
237         // Must be a local.
238         return getLocal(operand);
239     }
240
241     Node* get(VirtualRegister operand)
242     {
243         if (operand.isConstant()) {
244             unsigned constantIndex = operand.toConstantIndex();
245             unsigned oldSize = m_constants.size();
246             if (constantIndex >= oldSize || !m_constants[constantIndex]) {
247                 JSValue value = m_inlineStackTop->m_codeBlock->getConstant(operand.offset());
248                 if (constantIndex >= oldSize) {
249                     m_constants.grow(constantIndex + 1);
250                     for (unsigned i = oldSize; i < m_constants.size(); ++i)
251                         m_constants[i] = nullptr;
252                 }
253                 m_constants[constantIndex] =
254                     addToGraph(JSConstant, OpInfo(m_graph.freezeStrong(value)));
255             }
256             ASSERT(m_constants[constantIndex]);
257             return m_constants[constantIndex];
258         }
259         
260         if (inlineCallFrame()) {
261             if (!inlineCallFrame()->isClosureCall) {
262                 JSFunction* callee = inlineCallFrame()->calleeConstant();
263                 if (operand.offset() == JSStack::Callee)
264                     return weakJSConstant(callee);
265                 if (operand.offset() == JSStack::ScopeChain)
266                     return weakJSConstant(callee->scope());
267             }
268         } else if (operand.offset() == JSStack::Callee)
269             return addToGraph(GetCallee);
270         else if (operand.offset() == JSStack::ScopeChain)
271             return addToGraph(GetMyScope);
272         
273         return getDirect(m_inlineStackTop->remapOperand(operand));
274     }
275     
276     enum SetMode {
277         // A normal set which follows a two-phase commit that spans code origins. During
278         // the current code origin it issues a MovHint, and at the start of the next
279         // code origin there will be a SetLocal. If the local needs flushing, the second
280         // SetLocal will be preceded with a Flush.
281         NormalSet,
282         
283         // A set where the SetLocal happens immediately and there is still a Flush. This
284         // is relevant when assigning to a local in tricky situations for the delayed
285         // SetLocal logic but where we know that we have not performed any side effects
286         // within this code origin. This is a safe replacement for NormalSet anytime we
287         // know that we have not yet performed side effects in this code origin.
288         ImmediateSetWithFlush,
289         
290         // A set where the SetLocal happens immediately and we do not Flush it even if
291         // this is a local that is marked as needing it. This is relevant when
292         // initializing locals at the top of a function.
293         ImmediateNakedSet
294     };
295     Node* setDirect(VirtualRegister operand, Node* value, SetMode setMode = NormalSet)
296     {
297         addToGraph(MovHint, OpInfo(operand.offset()), value);
298         
299         DelayedSetLocal delayed = DelayedSetLocal(operand, value);
300         
301         if (setMode == NormalSet) {
302             m_setLocalQueue.append(delayed);
303             return 0;
304         }
305         
306         return delayed.execute(this, setMode);
307     }
308     
309     void processSetLocalQueue()
310     {
311         for (unsigned i = 0; i < m_setLocalQueue.size(); ++i)
312             m_setLocalQueue[i].execute(this);
313         m_setLocalQueue.resize(0);
314     }
315
316     Node* set(VirtualRegister operand, Node* value, SetMode setMode = NormalSet)
317     {
318         return setDirect(m_inlineStackTop->remapOperand(operand), value, setMode);
319     }
320     
321     Node* injectLazyOperandSpeculation(Node* node)
322     {
323         ASSERT(node->op() == GetLocal);
324         ASSERT(node->origin.semantic.bytecodeIndex == m_currentIndex);
325         ConcurrentJITLocker locker(m_inlineStackTop->m_profiledBlock->m_lock);
326         LazyOperandValueProfileKey key(m_currentIndex, node->local());
327         SpeculatedType prediction = m_inlineStackTop->m_lazyOperands.prediction(locker, key);
328         node->variableAccessData()->predict(prediction);
329         return node;
330     }
331
332     // Used in implementing get/set, above, where the operand is a local variable.
333     Node* getLocal(VirtualRegister operand)
334     {
335         unsigned local = operand.toLocal();
336
337         if (local < m_localWatchpoints.size()) {
338             if (VariableWatchpointSet* set = m_localWatchpoints[local]) {
339                 if (JSValue value = set->inferredValue()) {
340                     addToGraph(FunctionReentryWatchpoint, OpInfo(m_codeBlock->symbolTable()));
341                     addToGraph(VariableWatchpoint, OpInfo(set));
342                     return weakJSConstant(value);
343                 }
344             }
345         }
346
347         Node* node = m_currentBlock->variablesAtTail.local(local);
348         bool isCaptured = m_codeBlock->isCaptured(operand, inlineCallFrame());
349         
350         // This has two goals: 1) link together variable access datas, and 2)
351         // try to avoid creating redundant GetLocals. (1) is required for
352         // correctness - no other phase will ensure that block-local variable
353         // access data unification is done correctly. (2) is purely opportunistic
354         // and is meant as an compile-time optimization only.
355         
356         VariableAccessData* variable;
357         
358         if (node) {
359             variable = node->variableAccessData();
360             variable->mergeIsCaptured(isCaptured);
361             
362             if (!isCaptured) {
363                 switch (node->op()) {
364                 case GetLocal:
365                     return node;
366                 case SetLocal:
367                     return node->child1().node();
368                 default:
369                     break;
370                 }
371             }
372         } else
373             variable = newVariableAccessData(operand, isCaptured);
374         
375         node = injectLazyOperandSpeculation(addToGraph(GetLocal, OpInfo(variable)));
376         m_currentBlock->variablesAtTail.local(local) = node;
377         return node;
378     }
379
380     Node* setLocal(VirtualRegister operand, Node* value, SetMode setMode = NormalSet)
381     {
382         unsigned local = operand.toLocal();
383         bool isCaptured = m_codeBlock->isCaptured(operand, inlineCallFrame());
384         
385         if (setMode != ImmediateNakedSet) {
386             ArgumentPosition* argumentPosition = findArgumentPositionForLocal(operand);
387             if (isCaptured || argumentPosition)
388                 flushDirect(operand, argumentPosition);
389         }
390
391         VariableAccessData* variableAccessData = newVariableAccessData(operand, isCaptured);
392         variableAccessData->mergeStructureCheckHoistingFailed(
393             m_inlineStackTop->m_exitProfile.hasExitSite(m_currentIndex, BadCache));
394         variableAccessData->mergeCheckArrayHoistingFailed(
395             m_inlineStackTop->m_exitProfile.hasExitSite(m_currentIndex, BadIndexingType));
396         Node* node = addToGraph(SetLocal, OpInfo(variableAccessData), value);
397         m_currentBlock->variablesAtTail.local(local) = node;
398         return node;
399     }
400
401     // Used in implementing get/set, above, where the operand is an argument.
402     Node* getArgument(VirtualRegister operand)
403     {
404         unsigned argument = operand.toArgument();
405         ASSERT(argument < m_numArguments);
406         
407         Node* node = m_currentBlock->variablesAtTail.argument(argument);
408         bool isCaptured = m_codeBlock->isCaptured(operand);
409
410         VariableAccessData* variable;
411         
412         if (node) {
413             variable = node->variableAccessData();
414             variable->mergeIsCaptured(isCaptured);
415             
416             switch (node->op()) {
417             case GetLocal:
418                 return node;
419             case SetLocal:
420                 return node->child1().node();
421             default:
422                 break;
423             }
424         } else
425             variable = newVariableAccessData(operand, isCaptured);
426         
427         node = injectLazyOperandSpeculation(addToGraph(GetLocal, OpInfo(variable)));
428         m_currentBlock->variablesAtTail.argument(argument) = node;
429         return node;
430     }
431     Node* setArgument(VirtualRegister operand, Node* value, SetMode setMode = NormalSet)
432     {
433         unsigned argument = operand.toArgument();
434         ASSERT(argument < m_numArguments);
435         
436         bool isCaptured = m_codeBlock->isCaptured(operand);
437
438         VariableAccessData* variableAccessData = newVariableAccessData(operand, isCaptured);
439
440         // Always flush arguments, except for 'this'. If 'this' is created by us,
441         // then make sure that it's never unboxed.
442         if (argument) {
443             if (setMode != ImmediateNakedSet)
444                 flushDirect(operand);
445         } else if (m_codeBlock->specializationKind() == CodeForConstruct)
446             variableAccessData->mergeShouldNeverUnbox(true);
447         
448         variableAccessData->mergeStructureCheckHoistingFailed(
449             m_inlineStackTop->m_exitProfile.hasExitSite(m_currentIndex, BadCache));
450         variableAccessData->mergeCheckArrayHoistingFailed(
451             m_inlineStackTop->m_exitProfile.hasExitSite(m_currentIndex, BadIndexingType));
452         Node* node = addToGraph(SetLocal, OpInfo(variableAccessData), value);
453         m_currentBlock->variablesAtTail.argument(argument) = node;
454         return node;
455     }
456     
457     ArgumentPosition* findArgumentPositionForArgument(int argument)
458     {
459         InlineStackEntry* stack = m_inlineStackTop;
460         while (stack->m_inlineCallFrame)
461             stack = stack->m_caller;
462         return stack->m_argumentPositions[argument];
463     }
464     
465     ArgumentPosition* findArgumentPositionForLocal(VirtualRegister operand)
466     {
467         for (InlineStackEntry* stack = m_inlineStackTop; ; stack = stack->m_caller) {
468             InlineCallFrame* inlineCallFrame = stack->m_inlineCallFrame;
469             if (!inlineCallFrame)
470                 break;
471             if (operand.offset() < static_cast<int>(inlineCallFrame->stackOffset + JSStack::CallFrameHeaderSize))
472                 continue;
473             if (operand.offset() == inlineCallFrame->stackOffset + CallFrame::thisArgumentOffset())
474                 continue;
475             if (operand.offset() >= static_cast<int>(inlineCallFrame->stackOffset + CallFrame::thisArgumentOffset() + inlineCallFrame->arguments.size()))
476                 continue;
477             int argument = VirtualRegister(operand.offset() - inlineCallFrame->stackOffset).toArgument();
478             return stack->m_argumentPositions[argument];
479         }
480         return 0;
481     }
482     
483     ArgumentPosition* findArgumentPosition(VirtualRegister operand)
484     {
485         if (operand.isArgument())
486             return findArgumentPositionForArgument(operand.toArgument());
487         return findArgumentPositionForLocal(operand);
488     }
489
490     void flush(VirtualRegister operand)
491     {
492         flushDirect(m_inlineStackTop->remapOperand(operand));
493     }
494     
495     void flushDirect(VirtualRegister operand)
496     {
497         flushDirect(operand, findArgumentPosition(operand));
498     }
499     
500     void flushDirect(VirtualRegister operand, ArgumentPosition* argumentPosition)
501     {
502         bool isCaptured = m_codeBlock->isCaptured(operand, inlineCallFrame());
503         
504         ASSERT(!operand.isConstant());
505         
506         Node* node = m_currentBlock->variablesAtTail.operand(operand);
507         
508         VariableAccessData* variable;
509         
510         if (node) {
511             variable = node->variableAccessData();
512             variable->mergeIsCaptured(isCaptured);
513         } else
514             variable = newVariableAccessData(operand, isCaptured);
515         
516         node = addToGraph(Flush, OpInfo(variable));
517         m_currentBlock->variablesAtTail.operand(operand) = node;
518         if (argumentPosition)
519             argumentPosition->addVariable(variable);
520     }
521     
522     void flush(InlineStackEntry* inlineStackEntry)
523     {
524         int numArguments;
525         if (InlineCallFrame* inlineCallFrame = inlineStackEntry->m_inlineCallFrame) {
526             numArguments = inlineCallFrame->arguments.size();
527             if (inlineCallFrame->isClosureCall) {
528                 flushDirect(inlineStackEntry->remapOperand(VirtualRegister(JSStack::Callee)));
529                 flushDirect(inlineStackEntry->remapOperand(VirtualRegister(JSStack::ScopeChain)));
530             }
531         } else
532             numArguments = inlineStackEntry->m_codeBlock->numParameters();
533         for (unsigned argument = numArguments; argument-- > 1;)
534             flushDirect(inlineStackEntry->remapOperand(virtualRegisterForArgument(argument)));
535         for (int local = 0; local < inlineStackEntry->m_codeBlock->m_numVars; ++local) {
536             if (!inlineStackEntry->m_codeBlock->isCaptured(virtualRegisterForLocal(local)))
537                 continue;
538             flushDirect(inlineStackEntry->remapOperand(virtualRegisterForLocal(local)));
539         }
540     }
541
542     void flushForTerminal()
543     {
544         for (InlineStackEntry* inlineStackEntry = m_inlineStackTop; inlineStackEntry; inlineStackEntry = inlineStackEntry->m_caller)
545             flush(inlineStackEntry);
546     }
547
548     void flushForReturn()
549     {
550         flush(m_inlineStackTop);
551     }
552     
553     void flushIfTerminal(SwitchData& data)
554     {
555         if (data.fallThrough.bytecodeIndex() > m_currentIndex)
556             return;
557         
558         for (unsigned i = data.cases.size(); i--;) {
559             if (data.cases[i].target.bytecodeIndex() > m_currentIndex)
560                 return;
561         }
562         
563         flushForTerminal();
564     }
565
566     // Assumes that the constant should be strongly marked.
567     Node* jsConstant(JSValue constantValue)
568     {
569         return addToGraph(JSConstant, OpInfo(m_graph.freezeStrong(constantValue)));
570     }
571
572     Node* weakJSConstant(JSValue constantValue)
573     {
574         return addToGraph(JSConstant, OpInfo(m_graph.freeze(constantValue)));
575     }
576
577     // Helper functions to get/set the this value.
578     Node* getThis()
579     {
580         return get(m_inlineStackTop->m_codeBlock->thisRegister());
581     }
582
583     void setThis(Node* value)
584     {
585         set(m_inlineStackTop->m_codeBlock->thisRegister(), value);
586     }
587
588     InlineCallFrame* inlineCallFrame()
589     {
590         return m_inlineStackTop->m_inlineCallFrame;
591     }
592
593     CodeOrigin currentCodeOrigin()
594     {
595         return CodeOrigin(m_currentIndex, inlineCallFrame());
596     }
597     
598     BranchData* branchData(unsigned taken, unsigned notTaken)
599     {
600         // We assume that branches originating from bytecode always have a fall-through. We
601         // use this assumption to avoid checking for the creation of terminal blocks.
602         ASSERT((taken > m_currentIndex) || (notTaken > m_currentIndex));
603         BranchData* data = m_graph.m_branchData.add();
604         *data = BranchData::withBytecodeIndices(taken, notTaken);
605         return data;
606     }
607     
608     Node* addToGraph(NodeType op, Node* child1 = 0, Node* child2 = 0, Node* child3 = 0)
609     {
610         Node* result = m_graph.addNode(
611             SpecNone, op, NodeOrigin(currentCodeOrigin()), Edge(child1), Edge(child2),
612             Edge(child3));
613         ASSERT(op != Phi);
614         m_currentBlock->append(result);
615         return result;
616     }
617     Node* addToGraph(NodeType op, Edge child1, Edge child2 = Edge(), Edge child3 = Edge())
618     {
619         Node* result = m_graph.addNode(
620             SpecNone, op, NodeOrigin(currentCodeOrigin()), child1, child2, child3);
621         ASSERT(op != Phi);
622         m_currentBlock->append(result);
623         return result;
624     }
625     Node* addToGraph(NodeType op, OpInfo info, Node* child1 = 0, Node* child2 = 0, Node* child3 = 0)
626     {
627         Node* result = m_graph.addNode(
628             SpecNone, op, NodeOrigin(currentCodeOrigin()), info, Edge(child1), Edge(child2),
629             Edge(child3));
630         ASSERT(op != Phi);
631         m_currentBlock->append(result);
632         return result;
633     }
634     Node* addToGraph(NodeType op, OpInfo info1, OpInfo info2, Node* child1 = 0, Node* child2 = 0, Node* child3 = 0)
635     {
636         Node* result = m_graph.addNode(
637             SpecNone, op, NodeOrigin(currentCodeOrigin()), info1, info2,
638             Edge(child1), Edge(child2), Edge(child3));
639         ASSERT(op != Phi);
640         m_currentBlock->append(result);
641         return result;
642     }
643     
644     Node* addToGraph(Node::VarArgTag, NodeType op, OpInfo info1, OpInfo info2)
645     {
646         Node* result = m_graph.addNode(
647             SpecNone, Node::VarArg, op, NodeOrigin(currentCodeOrigin()), info1, info2,
648             m_graph.m_varArgChildren.size() - m_numPassedVarArgs, m_numPassedVarArgs);
649         ASSERT(op != Phi);
650         m_currentBlock->append(result);
651         
652         m_numPassedVarArgs = 0;
653         
654         return result;
655     }
656     
657     void removeLastNodeFromGraph(NodeType expectedNodeType)
658     {
659         Node* node = m_currentBlock->takeLast();
660         RELEASE_ASSERT(node->op() == expectedNodeType);
661         m_graph.m_allocator.free(node);
662     }
663
664     void addVarArgChild(Node* child)
665     {
666         m_graph.m_varArgChildren.append(Edge(child));
667         m_numPassedVarArgs++;
668     }
669     
670     Node* addCallWithoutSettingResult(
671         NodeType op, OpInfo opInfo, Node* callee, int argCount, int registerOffset,
672         SpeculatedType prediction)
673     {
674         addVarArgChild(callee);
675         size_t parameterSlots = JSStack::CallFrameHeaderSize - JSStack::CallerFrameAndPCSize + argCount;
676         if (parameterSlots > m_parameterSlots)
677             m_parameterSlots = parameterSlots;
678
679         int dummyThisArgument = op == Call || op == NativeCall || op == ProfiledCall ? 0 : 1;
680         for (int i = 0 + dummyThisArgument; i < argCount; ++i)
681             addVarArgChild(get(virtualRegisterForArgument(i, registerOffset)));
682
683         return addToGraph(Node::VarArg, op, opInfo, OpInfo(prediction));
684     }
685     
686     Node* addCall(
687         int result, NodeType op, OpInfo opInfo, Node* callee, int argCount, int registerOffset,
688         SpeculatedType prediction)
689     {
690         Node* call = addCallWithoutSettingResult(
691             op, opInfo, callee, argCount, registerOffset, prediction);
692         VirtualRegister resultReg(result);
693         if (resultReg.isValid())
694             set(VirtualRegister(result), call);
695         return call;
696     }
697     
698     Node* cellConstantWithStructureCheck(JSCell* object, Structure* structure)
699     {
700         Node* objectNode = weakJSConstant(object);
701         addToGraph(CheckStructure, OpInfo(m_graph.addStructureSet(structure)), objectNode);
702         return objectNode;
703     }
704     
705     SpeculatedType getPredictionWithoutOSRExit(unsigned bytecodeIndex)
706     {
707         ConcurrentJITLocker locker(m_inlineStackTop->m_profiledBlock->m_lock);
708         return m_inlineStackTop->m_profiledBlock->valueProfilePredictionForBytecodeOffset(locker, bytecodeIndex);
709     }
710
711     SpeculatedType getPrediction(unsigned bytecodeIndex)
712     {
713         SpeculatedType prediction = getPredictionWithoutOSRExit(bytecodeIndex);
714         
715         if (prediction == SpecNone) {
716             // We have no information about what values this node generates. Give up
717             // on executing this code, since we're likely to do more damage than good.
718             addToGraph(ForceOSRExit);
719         }
720         
721         return prediction;
722     }
723     
724     SpeculatedType getPredictionWithoutOSRExit()
725     {
726         return getPredictionWithoutOSRExit(m_currentIndex);
727     }
728     
729     SpeculatedType getPrediction()
730     {
731         return getPrediction(m_currentIndex);
732     }
733     
734     ArrayMode getArrayMode(ArrayProfile* profile, Array::Action action)
735     {
736         ConcurrentJITLocker locker(m_inlineStackTop->m_profiledBlock->m_lock);
737         profile->computeUpdatedPrediction(locker, m_inlineStackTop->m_profiledBlock);
738         return ArrayMode::fromObserved(locker, profile, action, false);
739     }
740     
741     ArrayMode getArrayMode(ArrayProfile* profile)
742     {
743         return getArrayMode(profile, Array::Read);
744     }
745     
746     ArrayMode getArrayModeConsideringSlowPath(ArrayProfile* profile, Array::Action action)
747     {
748         ConcurrentJITLocker locker(m_inlineStackTop->m_profiledBlock->m_lock);
749         
750         profile->computeUpdatedPrediction(locker, m_inlineStackTop->m_profiledBlock);
751         
752         bool makeSafe =
753             m_inlineStackTop->m_profiledBlock->likelyToTakeSlowCase(m_currentIndex)
754             || profile->outOfBounds(locker);
755         
756         ArrayMode result = ArrayMode::fromObserved(locker, profile, action, makeSafe);
757         
758         return result;
759     }
760     
761     Node* makeSafe(Node* node)
762     {
763         if (m_inlineStackTop->m_exitProfile.hasExitSite(m_currentIndex, Overflow))
764             node->mergeFlags(NodeMayOverflowInDFG);
765         if (m_inlineStackTop->m_exitProfile.hasExitSite(m_currentIndex, NegativeZero))
766             node->mergeFlags(NodeMayNegZeroInDFG);
767         
768         if (!isX86() && node->op() == ArithMod)
769             return node;
770
771         if (!m_inlineStackTop->m_profiledBlock->likelyToTakeSlowCase(m_currentIndex))
772             return node;
773         
774         switch (node->op()) {
775         case UInt32ToNumber:
776         case ArithAdd:
777         case ArithSub:
778         case ValueAdd:
779         case ArithMod: // for ArithMod "MayOverflow" means we tried to divide by zero, or we saw double.
780             node->mergeFlags(NodeMayOverflowInBaseline);
781             break;
782             
783         case ArithNegate:
784             // Currently we can't tell the difference between a negation overflowing
785             // (i.e. -(1 << 31)) or generating negative zero (i.e. -0). If it took slow
786             // path then we assume that it did both of those things.
787             node->mergeFlags(NodeMayOverflowInBaseline);
788             node->mergeFlags(NodeMayNegZeroInBaseline);
789             break;
790
791         case ArithMul:
792             // FIXME: We should detect cases where we only overflowed but never created
793             // negative zero.
794             // https://bugs.webkit.org/show_bug.cgi?id=132470
795             if (m_inlineStackTop->m_profiledBlock->likelyToTakeDeepestSlowCase(m_currentIndex)
796                 || m_inlineStackTop->m_exitProfile.hasExitSite(m_currentIndex, Overflow))
797                 node->mergeFlags(NodeMayOverflowInBaseline | NodeMayNegZeroInBaseline);
798             else if (m_inlineStackTop->m_profiledBlock->likelyToTakeSlowCase(m_currentIndex)
799                 || m_inlineStackTop->m_exitProfile.hasExitSite(m_currentIndex, NegativeZero))
800                 node->mergeFlags(NodeMayNegZeroInBaseline);
801             break;
802             
803         default:
804             RELEASE_ASSERT_NOT_REACHED();
805             break;
806         }
807         
808         return node;
809     }
810     
811     Node* makeDivSafe(Node* node)
812     {
813         ASSERT(node->op() == ArithDiv);
814         
815         if (m_inlineStackTop->m_exitProfile.hasExitSite(m_currentIndex, Overflow))
816             node->mergeFlags(NodeMayOverflowInDFG);
817         if (m_inlineStackTop->m_exitProfile.hasExitSite(m_currentIndex, NegativeZero))
818             node->mergeFlags(NodeMayNegZeroInDFG);
819         
820         // The main slow case counter for op_div in the old JIT counts only when
821         // the operands are not numbers. We don't care about that since we already
822         // have speculations in place that take care of that separately. We only
823         // care about when the outcome of the division is not an integer, which
824         // is what the special fast case counter tells us.
825         
826         if (!m_inlineStackTop->m_profiledBlock->couldTakeSpecialFastCase(m_currentIndex))
827             return node;
828         
829         // FIXME: It might be possible to make this more granular.
830         node->mergeFlags(NodeMayOverflowInBaseline | NodeMayNegZeroInBaseline);
831         
832         return node;
833     }
834     
835     void buildOperandMapsIfNecessary();
836     
837     VM* m_vm;
838     CodeBlock* m_codeBlock;
839     CodeBlock* m_profiledBlock;
840     Graph& m_graph;
841
842     // The current block being generated.
843     BasicBlock* m_currentBlock;
844     // The bytecode index of the current instruction being generated.
845     unsigned m_currentIndex;
846
847     FrozenValue* m_constantUndefined;
848     FrozenValue* m_constantNull;
849     FrozenValue* m_constantNaN;
850     FrozenValue* m_constantOne;
851     Vector<Node*, 16> m_constants;
852
853     // The number of arguments passed to the function.
854     unsigned m_numArguments;
855     // The number of locals (vars + temporaries) used in the function.
856     unsigned m_numLocals;
857     // The number of slots (in units of sizeof(Register)) that we need to
858     // preallocate for arguments to outgoing calls from this frame. This
859     // number includes the CallFrame slots that we initialize for the callee
860     // (but not the callee-initialized CallerFrame and ReturnPC slots).
861     // This number is 0 if and only if this function is a leaf.
862     unsigned m_parameterSlots;
863     // The number of var args passed to the next var arg node.
864     unsigned m_numPassedVarArgs;
865
866     HashMap<ConstantBufferKey, unsigned> m_constantBufferCache;
867     
868     Vector<VariableWatchpointSet*, 16> m_localWatchpoints;
869     
870     struct InlineStackEntry {
871         ByteCodeParser* m_byteCodeParser;
872         
873         CodeBlock* m_codeBlock;
874         CodeBlock* m_profiledBlock;
875         InlineCallFrame* m_inlineCallFrame;
876         
877         ScriptExecutable* executable() { return m_codeBlock->ownerExecutable(); }
878         
879         QueryableExitProfile m_exitProfile;
880         
881         // Remapping of identifier and constant numbers from the code block being
882         // inlined (inline callee) to the code block that we're inlining into
883         // (the machine code block, which is the transitive, though not necessarily
884         // direct, caller).
885         Vector<unsigned> m_identifierRemap;
886         Vector<unsigned> m_constantBufferRemap;
887         Vector<unsigned> m_switchRemap;
888         
889         // Blocks introduced by this code block, which need successor linking.
890         // May include up to one basic block that includes the continuation after
891         // the callsite in the caller. These must be appended in the order that they
892         // are created, but their bytecodeBegin values need not be in order as they
893         // are ignored.
894         Vector<UnlinkedBlock> m_unlinkedBlocks;
895         
896         // Potential block linking targets. Must be sorted by bytecodeBegin, and
897         // cannot have two blocks that have the same bytecodeBegin.
898         Vector<BasicBlock*> m_blockLinkingTargets;
899         
900         // If the callsite's basic block was split into two, then this will be
901         // the head of the callsite block. It needs its successors linked to the
902         // m_unlinkedBlocks, but not the other way around: there's no way for
903         // any blocks in m_unlinkedBlocks to jump back into this block.
904         BasicBlock* m_callsiteBlockHead;
905         
906         // Does the callsite block head need linking? This is typically true
907         // but will be false for the machine code block's inline stack entry
908         // (since that one is not inlined) and for cases where an inline callee
909         // did the linking for us.
910         bool m_callsiteBlockHeadNeedsLinking;
911         
912         VirtualRegister m_returnValue;
913         
914         // Speculations about variable types collected from the profiled code block,
915         // which are based on OSR exit profiles that past DFG compilatins of this
916         // code block had gathered.
917         LazyOperandValueProfileParser m_lazyOperands;
918         
919         CallLinkInfoMap m_callLinkInfos;
920         StubInfoMap m_stubInfos;
921         
922         // Did we see any returns? We need to handle the (uncommon but necessary)
923         // case where a procedure that does not return was inlined.
924         bool m_didReturn;
925         
926         // Did we have any early returns?
927         bool m_didEarlyReturn;
928         
929         // Pointers to the argument position trackers for this slice of code.
930         Vector<ArgumentPosition*> m_argumentPositions;
931         
932         InlineStackEntry* m_caller;
933         
934         InlineStackEntry(
935             ByteCodeParser*,
936             CodeBlock*,
937             CodeBlock* profiledBlock,
938             BasicBlock* callsiteBlockHead,
939             JSFunction* callee, // Null if this is a closure call.
940             VirtualRegister returnValueVR,
941             VirtualRegister inlineCallFrameStart,
942             int argumentCountIncludingThis,
943             InlineCallFrame::Kind);
944         
945         ~InlineStackEntry()
946         {
947             m_byteCodeParser->m_inlineStackTop = m_caller;
948         }
949         
950         VirtualRegister remapOperand(VirtualRegister operand) const
951         {
952             if (!m_inlineCallFrame)
953                 return operand;
954             
955             ASSERT(!operand.isConstant());
956
957             return VirtualRegister(operand.offset() + m_inlineCallFrame->stackOffset);
958         }
959     };
960     
961     InlineStackEntry* m_inlineStackTop;
962     
963     struct DelayedSetLocal {
964         VirtualRegister m_operand;
965         Node* m_value;
966         
967         DelayedSetLocal() { }
968         DelayedSetLocal(VirtualRegister operand, Node* value)
969             : m_operand(operand)
970             , m_value(value)
971         {
972         }
973         
974         Node* execute(ByteCodeParser* parser, SetMode setMode = NormalSet)
975         {
976             if (m_operand.isArgument())
977                 return parser->setArgument(m_operand, m_value, setMode);
978             return parser->setLocal(m_operand, m_value, setMode);
979         }
980     };
981     
982     Vector<DelayedSetLocal, 2> m_setLocalQueue;
983
984     // Have we built operand maps? We initialize them lazily, and only when doing
985     // inlining.
986     bool m_haveBuiltOperandMaps;
987     // Mapping between identifier names and numbers.
988     BorrowedIdentifierMap m_identifierMap;
989     
990     CodeBlock* m_dfgCodeBlock;
991     CallLinkStatus::ContextMap m_callContextMap;
992     StubInfoMap m_dfgStubInfos;
993     
994     Instruction* m_currentInstruction;
995 };
996
997 #define NEXT_OPCODE(name) \
998     m_currentIndex += OPCODE_LENGTH(name); \
999     continue
1000
1001 #define LAST_OPCODE(name) \
1002     m_currentIndex += OPCODE_LENGTH(name); \
1003     return shouldContinueParsing
1004
1005 void ByteCodeParser::handleCall(Instruction* pc, NodeType op, CodeSpecializationKind kind)
1006 {
1007     ASSERT(OPCODE_LENGTH(op_call) == OPCODE_LENGTH(op_construct));
1008     handleCall(
1009         pc[1].u.operand, op, kind, OPCODE_LENGTH(op_call),
1010         pc[2].u.operand, pc[3].u.operand, -pc[4].u.operand);
1011 }
1012
1013 void ByteCodeParser::handleCall(
1014     int result, NodeType op, CodeSpecializationKind kind, unsigned instructionSize,
1015     int callee, int argumentCountIncludingThis, int registerOffset)
1016 {
1017     Node* callTarget = get(VirtualRegister(callee));
1018     
1019     CallLinkStatus callLinkStatus = CallLinkStatus::computeFor(
1020         m_inlineStackTop->m_profiledBlock, currentCodeOrigin(),
1021         m_inlineStackTop->m_callLinkInfos, m_callContextMap);
1022     
1023     handleCall(
1024         result, op, InlineCallFrame::kindFor(kind), instructionSize, callTarget,
1025         argumentCountIncludingThis, registerOffset, callLinkStatus);
1026 }
1027     
1028 void ByteCodeParser::handleCall(
1029     int result, NodeType op, InlineCallFrame::Kind kind, unsigned instructionSize,
1030     Node* callTarget, int argumentCountIncludingThis, int registerOffset,
1031     CallLinkStatus callLinkStatus)
1032 {
1033     handleCall(
1034         result, op, kind, instructionSize, callTarget, argumentCountIncludingThis,
1035         registerOffset, callLinkStatus, getPrediction());
1036 }
1037
1038 void ByteCodeParser::handleCall(
1039     int result, NodeType op, InlineCallFrame::Kind kind, unsigned instructionSize,
1040     Node* callTarget, int argumentCountIncludingThis, int registerOffset,
1041     CallLinkStatus callLinkStatus, SpeculatedType prediction)
1042 {
1043     ASSERT(registerOffset <= 0);
1044     
1045     if (callTarget->hasConstant())
1046         callLinkStatus = CallLinkStatus(callTarget->asJSValue()).setIsProved(true);
1047     
1048     if ((!callLinkStatus.canOptimize() || callLinkStatus.size() != 1)
1049         && !isFTL(m_graph.m_plan.mode) && Options::useFTLJIT()
1050         && InlineCallFrame::isNormalCall(kind)
1051         && CallEdgeLog::isEnabled()
1052         && Options::dfgDoesCallEdgeProfiling()) {
1053         ASSERT(op == Call || op == Construct);
1054         if (op == Call)
1055             op = ProfiledCall;
1056         else
1057             op = ProfiledConstruct;
1058     }
1059     
1060     if (!callLinkStatus.canOptimize()) {
1061         // Oddly, this conflates calls that haven't executed with calls that behaved sufficiently polymorphically
1062         // that we cannot optimize them.
1063         
1064         addCall(result, op, OpInfo(), callTarget, argumentCountIncludingThis, registerOffset, prediction);
1065         return;
1066     }
1067     
1068     unsigned nextOffset = m_currentIndex + instructionSize;
1069     
1070     OpInfo callOpInfo;
1071     
1072     if (handleInlining(callTarget, result, callLinkStatus, registerOffset, argumentCountIncludingThis, nextOffset, op, kind, prediction)) {
1073         if (m_graph.compilation())
1074             m_graph.compilation()->noticeInlinedCall();
1075         return;
1076     }
1077     
1078 #if ENABLE(FTL_NATIVE_CALL_INLINING)
1079     if (isFTL(m_graph.m_plan.mode) && Options::optimizeNativeCalls() && callLinkStatus.size() == 1 && !callLinkStatus.couldTakeSlowPath()) {
1080         CallVariant callee = callLinkStatus[0].callee();
1081         JSFunction* function = callee.function();
1082         CodeSpecializationKind specializationKind = InlineCallFrame::specializationKindFor(kind);
1083         if (function && function->isHostFunction()) {
1084             emitFunctionChecks(callee, callTarget, registerOffset, specializationKind);
1085             callOpInfo = OpInfo(m_graph.freeze(function));
1086
1087             if (op == Call || op == ProfiledCall)
1088                 op = NativeCall;
1089             else {
1090                 ASSERT(op == Construct || op == ProfiledConstruct);
1091                 op = NativeConstruct;
1092             }
1093         }
1094     }
1095 #endif
1096     
1097     addCall(result, op, callOpInfo, callTarget, argumentCountIncludingThis, registerOffset, prediction);
1098 }
1099
1100 void ByteCodeParser::emitFunctionChecks(CallVariant callee, Node* callTarget, int registerOffset, CodeSpecializationKind kind)
1101 {
1102     Node* thisArgument;
1103     if (kind == CodeForCall)
1104         thisArgument = get(virtualRegisterForArgument(0, registerOffset));
1105     else
1106         thisArgument = 0;
1107
1108     JSCell* calleeCell;
1109     Node* callTargetForCheck;
1110     if (callee.isClosureCall()) {
1111         calleeCell = callee.executable();
1112         callTargetForCheck = addToGraph(GetExecutable, callTarget);
1113     } else {
1114         calleeCell = callee.nonExecutableCallee();
1115         callTargetForCheck = callTarget;
1116     }
1117     
1118     ASSERT(calleeCell);
1119     addToGraph(CheckCell, OpInfo(m_graph.freeze(calleeCell)), callTargetForCheck, thisArgument);
1120 }
1121
1122 void ByteCodeParser::undoFunctionChecks(CallVariant callee)
1123 {
1124     removeLastNodeFromGraph(CheckCell);
1125     if (callee.isClosureCall())
1126         removeLastNodeFromGraph(GetExecutable);
1127 }
1128
1129 void ByteCodeParser::emitArgumentPhantoms(int registerOffset, int argumentCountIncludingThis, CodeSpecializationKind kind)
1130 {
1131     for (int i = kind == CodeForCall ? 0 : 1; i < argumentCountIncludingThis; ++i)
1132         addToGraph(Phantom, get(virtualRegisterForArgument(i, registerOffset)));
1133 }
1134
1135 unsigned ByteCodeParser::inliningCost(CallVariant callee, int argumentCountIncludingThis, CodeSpecializationKind kind)
1136 {
1137     if (verbose)
1138         dataLog("Considering inlining ", callee, " into ", currentCodeOrigin(), "\n");
1139     
1140     FunctionExecutable* executable = callee.functionExecutable();
1141     if (!executable) {
1142         if (verbose)
1143             dataLog("    Failing because there is no function executable.");
1144         return UINT_MAX;
1145     }
1146     
1147     // Does the number of arguments we're passing match the arity of the target? We currently
1148     // inline only if the number of arguments passed is greater than or equal to the number
1149     // arguments expected.
1150     if (static_cast<int>(executable->parameterCount()) + 1 > argumentCountIncludingThis) {
1151         if (verbose)
1152             dataLog("    Failing because of arity mismatch.\n");
1153         return UINT_MAX;
1154     }
1155     
1156     // Do we have a code block, and does the code block's size match the heuristics/requirements for
1157     // being an inline candidate? We might not have a code block if code was thrown away or if we
1158     // simply hadn't actually made this call yet. We could still theoretically attempt to inline it
1159     // if we had a static proof of what was being called; this might happen for example if you call a
1160     // global function, where watchpointing gives us static information. Overall, it's a rare case
1161     // because we expect that any hot callees would have already been compiled.
1162     CodeBlock* codeBlock = executable->baselineCodeBlockFor(kind);
1163     if (!codeBlock) {
1164         if (verbose)
1165             dataLog("    Failing because no code block available.\n");
1166         return UINT_MAX;
1167     }
1168     CapabilityLevel capabilityLevel = inlineFunctionForCapabilityLevel(
1169         codeBlock, kind, callee.isClosureCall());
1170     if (!canInline(capabilityLevel)) {
1171         if (verbose)
1172             dataLog("    Failing because the function is not inlineable.\n");
1173         return UINT_MAX;
1174     }
1175     
1176     // Check if the caller is already too large. We do this check here because that's just
1177     // where we happen to also have the callee's code block, and we want that for the
1178     // purpose of unsetting SABI.
1179     if (!isSmallEnoughToInlineCodeInto(m_codeBlock)) {
1180         codeBlock->m_shouldAlwaysBeInlined = false;
1181         if (verbose)
1182             dataLog("    Failing because the caller is too large.\n");
1183         return UINT_MAX;
1184     }
1185     
1186     // FIXME: this should be better at predicting how much bloat we will introduce by inlining
1187     // this function.
1188     // https://bugs.webkit.org/show_bug.cgi?id=127627
1189     
1190     // Have we exceeded inline stack depth, or are we trying to inline a recursive call to
1191     // too many levels? If either of these are detected, then don't inline. We adjust our
1192     // heuristics if we are dealing with a function that cannot otherwise be compiled.
1193     
1194     unsigned depth = 0;
1195     unsigned recursion = 0;
1196     
1197     for (InlineStackEntry* entry = m_inlineStackTop; entry; entry = entry->m_caller) {
1198         ++depth;
1199         if (depth >= Options::maximumInliningDepth()) {
1200             if (verbose)
1201                 dataLog("    Failing because depth exceeded.\n");
1202             return UINT_MAX;
1203         }
1204         
1205         if (entry->executable() == executable) {
1206             ++recursion;
1207             if (recursion >= Options::maximumInliningRecursion()) {
1208                 if (verbose)
1209                     dataLog("    Failing because recursion detected.\n");
1210                 return UINT_MAX;
1211             }
1212         }
1213     }
1214     
1215     if (verbose)
1216         dataLog("    Inlining should be possible.\n");
1217     
1218     // It might be possible to inline.
1219     return codeBlock->instructionCount();
1220 }
1221
1222 void ByteCodeParser::inlineCall(Node* callTargetNode, int resultOperand, CallVariant callee, int registerOffset, int argumentCountIncludingThis, unsigned nextOffset, InlineCallFrame::Kind kind, CallerLinkability callerLinkability)
1223 {
1224     CodeSpecializationKind specializationKind = InlineCallFrame::specializationKindFor(kind);
1225     
1226     ASSERT(inliningCost(callee, argumentCountIncludingThis, specializationKind) != UINT_MAX);
1227     
1228     CodeBlock* codeBlock = callee.functionExecutable()->baselineCodeBlockFor(specializationKind);
1229
1230     // FIXME: Don't flush constants!
1231     
1232     int inlineCallFrameStart = m_inlineStackTop->remapOperand(VirtualRegister(registerOffset)).offset() + JSStack::CallFrameHeaderSize;
1233     
1234     ensureLocals(
1235         VirtualRegister(inlineCallFrameStart).toLocal() + 1 +
1236         JSStack::CallFrameHeaderSize + codeBlock->m_numCalleeRegisters);
1237     
1238     size_t argumentPositionStart = m_graph.m_argumentPositions.size();
1239
1240     VirtualRegister resultReg(resultOperand);
1241     if (resultReg.isValid())
1242         resultReg = m_inlineStackTop->remapOperand(resultReg);
1243     
1244     InlineStackEntry inlineStackEntry(
1245         this, codeBlock, codeBlock, m_graph.lastBlock(), callee.function(), resultReg,
1246         (VirtualRegister)inlineCallFrameStart, argumentCountIncludingThis, kind);
1247     
1248     // This is where the actual inlining really happens.
1249     unsigned oldIndex = m_currentIndex;
1250     m_currentIndex = 0;
1251
1252     InlineVariableData inlineVariableData;
1253     inlineVariableData.inlineCallFrame = m_inlineStackTop->m_inlineCallFrame;
1254     inlineVariableData.argumentPositionStart = argumentPositionStart;
1255     inlineVariableData.calleeVariable = 0;
1256     
1257     RELEASE_ASSERT(
1258         m_inlineStackTop->m_inlineCallFrame->isClosureCall
1259         == callee.isClosureCall());
1260     if (callee.isClosureCall()) {
1261         VariableAccessData* calleeVariable =
1262             set(VirtualRegister(JSStack::Callee), callTargetNode, ImmediateNakedSet)->variableAccessData();
1263         VariableAccessData* scopeVariable =
1264             set(VirtualRegister(JSStack::ScopeChain), addToGraph(GetScope, callTargetNode), ImmediateNakedSet)->variableAccessData();
1265         
1266         calleeVariable->mergeShouldNeverUnbox(true);
1267         scopeVariable->mergeShouldNeverUnbox(true);
1268         
1269         inlineVariableData.calleeVariable = calleeVariable;
1270     }
1271     
1272     m_graph.m_inlineVariableData.append(inlineVariableData);
1273     
1274     parseCodeBlock();
1275     clearCaches(); // Reset our state now that we're back to the outer code.
1276     
1277     m_currentIndex = oldIndex;
1278     
1279     // If the inlined code created some new basic blocks, then we have linking to do.
1280     if (inlineStackEntry.m_callsiteBlockHead != m_graph.lastBlock()) {
1281         
1282         ASSERT(!inlineStackEntry.m_unlinkedBlocks.isEmpty());
1283         if (inlineStackEntry.m_callsiteBlockHeadNeedsLinking)
1284             linkBlock(inlineStackEntry.m_callsiteBlockHead, inlineStackEntry.m_blockLinkingTargets);
1285         else
1286             ASSERT(inlineStackEntry.m_callsiteBlockHead->isLinked);
1287         
1288         if (callerLinkability == CallerDoesNormalLinking)
1289             cancelLinkingForBlock(inlineStackEntry.m_caller, inlineStackEntry.m_callsiteBlockHead);
1290         
1291         linkBlocks(inlineStackEntry.m_unlinkedBlocks, inlineStackEntry.m_blockLinkingTargets);
1292     } else
1293         ASSERT(inlineStackEntry.m_unlinkedBlocks.isEmpty());
1294     
1295     BasicBlock* lastBlock = m_graph.lastBlock();
1296     // If there was a return, but no early returns, then we're done. We allow parsing of
1297     // the caller to continue in whatever basic block we're in right now.
1298     if (!inlineStackEntry.m_didEarlyReturn && inlineStackEntry.m_didReturn) {
1299         ASSERT(lastBlock->isEmpty() || !lastBlock->last()->isTerminal());
1300         
1301         // If we created new blocks then the last block needs linking, but in the
1302         // caller. It doesn't need to be linked to, but it needs outgoing links.
1303         if (!inlineStackEntry.m_unlinkedBlocks.isEmpty()) {
1304             // For debugging purposes, set the bytecodeBegin. Note that this doesn't matter
1305             // for release builds because this block will never serve as a potential target
1306             // in the linker's binary search.
1307             lastBlock->bytecodeBegin = m_currentIndex;
1308             if (callerLinkability == CallerDoesNormalLinking) {
1309                 if (verbose)
1310                     dataLog("Adding unlinked block ", RawPointer(m_graph.lastBlock()), " (one return)\n");
1311                 m_inlineStackTop->m_caller->m_unlinkedBlocks.append(UnlinkedBlock(m_graph.lastBlock()));
1312             }
1313         }
1314         
1315         m_currentBlock = m_graph.lastBlock();
1316         return;
1317     }
1318     
1319     // If we get to this point then all blocks must end in some sort of terminals.
1320     ASSERT(lastBlock->last()->isTerminal());
1321
1322     // Need to create a new basic block for the continuation at the caller.
1323     RefPtr<BasicBlock> block = adoptRef(new BasicBlock(nextOffset, m_numArguments, m_numLocals, PNaN));
1324
1325     // Link the early returns to the basic block we're about to create.
1326     for (size_t i = 0; i < inlineStackEntry.m_unlinkedBlocks.size(); ++i) {
1327         if (!inlineStackEntry.m_unlinkedBlocks[i].m_needsEarlyReturnLinking)
1328             continue;
1329         BasicBlock* blockToLink = inlineStackEntry.m_unlinkedBlocks[i].m_block;
1330         ASSERT(!blockToLink->isLinked);
1331         Node* node = blockToLink->last();
1332         ASSERT(node->op() == Jump);
1333         ASSERT(!node->targetBlock());
1334         node->targetBlock() = block.get();
1335         inlineStackEntry.m_unlinkedBlocks[i].m_needsEarlyReturnLinking = false;
1336         if (verbose)
1337             dataLog("Marking ", RawPointer(blockToLink), " as linked (jumps to return)\n");
1338         blockToLink->didLink();
1339     }
1340     
1341     m_currentBlock = block.get();
1342     ASSERT(m_inlineStackTop->m_caller->m_blockLinkingTargets.isEmpty() || m_inlineStackTop->m_caller->m_blockLinkingTargets.last()->bytecodeBegin < nextOffset);
1343     if (verbose)
1344         dataLog("Adding unlinked block ", RawPointer(block.get()), " (many returns)\n");
1345     if (callerLinkability == CallerDoesNormalLinking) {
1346         m_inlineStackTop->m_caller->m_unlinkedBlocks.append(UnlinkedBlock(block.get()));
1347         m_inlineStackTop->m_caller->m_blockLinkingTargets.append(block.get());
1348     }
1349     m_graph.appendBlock(block);
1350     prepareToParseBlock();
1351 }
1352
1353 void ByteCodeParser::cancelLinkingForBlock(InlineStackEntry* inlineStackEntry, BasicBlock* block)
1354 {
1355     // It's possible that the callsite block head is not owned by the caller.
1356     if (!inlineStackEntry->m_unlinkedBlocks.isEmpty()) {
1357         // It's definitely owned by the caller, because the caller created new blocks.
1358         // Assert that this all adds up.
1359         ASSERT_UNUSED(block, inlineStackEntry->m_unlinkedBlocks.last().m_block == block);
1360         ASSERT(inlineStackEntry->m_unlinkedBlocks.last().m_needsNormalLinking);
1361         inlineStackEntry->m_unlinkedBlocks.last().m_needsNormalLinking = false;
1362     } else {
1363         // It's definitely not owned by the caller. Tell the caller that he does not
1364         // need to link his callsite block head, because we did it for him.
1365         ASSERT(inlineStackEntry->m_callsiteBlockHeadNeedsLinking);
1366         ASSERT_UNUSED(block, inlineStackEntry->m_callsiteBlockHead == block);
1367         inlineStackEntry->m_callsiteBlockHeadNeedsLinking = false;
1368     }
1369 }
1370
1371 bool ByteCodeParser::attemptToInlineCall(Node* callTargetNode, int resultOperand, CallVariant callee, int registerOffset, int argumentCountIncludingThis, unsigned nextOffset, InlineCallFrame::Kind kind, CallerLinkability callerLinkability, SpeculatedType prediction, unsigned& inliningBalance)
1372 {
1373     CodeSpecializationKind specializationKind = InlineCallFrame::specializationKindFor(kind);
1374     
1375     if (!inliningBalance)
1376         return false;
1377     
1378     if (InternalFunction* function = callee.internalFunction()) {
1379         if (handleConstantInternalFunction(resultOperand, function, registerOffset, argumentCountIncludingThis, specializationKind)) {
1380             addToGraph(Phantom, callTargetNode);
1381             emitArgumentPhantoms(registerOffset, argumentCountIncludingThis, specializationKind);
1382             inliningBalance--;
1383             return true;
1384         }
1385         return false;
1386     }
1387     
1388     Intrinsic intrinsic = callee.intrinsicFor(specializationKind);
1389     if (intrinsic != NoIntrinsic) {
1390         if (handleIntrinsic(resultOperand, intrinsic, registerOffset, argumentCountIncludingThis, prediction)) {
1391             addToGraph(Phantom, callTargetNode);
1392             emitArgumentPhantoms(registerOffset, argumentCountIncludingThis, specializationKind);
1393             inliningBalance--;
1394             return true;
1395         }
1396         return false;
1397     }
1398     
1399     unsigned myInliningCost = inliningCost(callee, argumentCountIncludingThis, specializationKind);
1400     if (myInliningCost > inliningBalance)
1401         return false;
1402     
1403     inlineCall(callTargetNode, resultOperand, callee, registerOffset, argumentCountIncludingThis, nextOffset, kind, callerLinkability);
1404     inliningBalance -= myInliningCost;
1405     return true;
1406 }
1407
1408 bool ByteCodeParser::handleInlining(Node* callTargetNode, int resultOperand, const CallLinkStatus& callLinkStatus, int registerOffset, int argumentCountIncludingThis, unsigned nextOffset, NodeType callOp, InlineCallFrame::Kind kind, SpeculatedType prediction)
1409 {
1410     if (verbose) {
1411         dataLog("Handling inlining...\n");
1412         dataLog("Stack: ", currentCodeOrigin(), "\n");
1413     }
1414     CodeSpecializationKind specializationKind = InlineCallFrame::specializationKindFor(kind);
1415     
1416     if (!callLinkStatus.size()) {
1417         if (verbose)
1418             dataLog("Bailing inlining.\n");
1419         return false;
1420     }
1421     
1422     unsigned inliningBalance = Options::maximumFunctionForCallInlineCandidateInstructionCount();
1423     if (specializationKind == CodeForConstruct)
1424         inliningBalance = std::min(inliningBalance, Options::maximumFunctionForConstructInlineCandidateInstructionCount());
1425     if (callLinkStatus.isClosureCall())
1426         inliningBalance = std::min(inliningBalance, Options::maximumFunctionForClosureCallInlineCandidateInstructionCount());
1427     
1428     // First check if we can avoid creating control flow. Our inliner does some CFG
1429     // simplification on the fly and this helps reduce compile times, but we can only leverage
1430     // this in cases where we don't need control flow diamonds to check the callee.
1431     if (!callLinkStatus.couldTakeSlowPath() && callLinkStatus.size() == 1) {
1432         emitFunctionChecks(
1433             callLinkStatus[0].callee(), callTargetNode, registerOffset, specializationKind);
1434         bool result = attemptToInlineCall(
1435             callTargetNode, resultOperand, callLinkStatus[0].callee(), registerOffset,
1436             argumentCountIncludingThis, nextOffset, kind, CallerDoesNormalLinking, prediction,
1437             inliningBalance);
1438         if (!result && !callLinkStatus.isProved())
1439             undoFunctionChecks(callLinkStatus[0].callee());
1440         if (verbose) {
1441             dataLog("Done inlining (simple).\n");
1442             dataLog("Stack: ", currentCodeOrigin(), "\n");
1443         }
1444         return result;
1445     }
1446     
1447     // We need to create some kind of switch over callee. For now we only do this if we believe that
1448     // we're in the top tier. We have two reasons for this: first, it provides us an opportunity to
1449     // do more detailed polyvariant/polymorphic profiling; and second, it reduces compile times in
1450     // the DFG. And by polyvariant profiling we mean polyvariant profiling of *this* call. Note that
1451     // we could improve that aspect of this by doing polymorphic inlining but having the profiling
1452     // also. Currently we opt against this, but it could be interesting. That would require having a
1453     // separate node for call edge profiling.
1454     // FIXME: Introduce the notion of a separate call edge profiling node.
1455     // https://bugs.webkit.org/show_bug.cgi?id=136033
1456     if (!isFTL(m_graph.m_plan.mode) || !Options::enablePolymorphicCallInlining()) {
1457         if (verbose) {
1458             dataLog("Bailing inlining (hard).\n");
1459             dataLog("Stack: ", currentCodeOrigin(), "\n");
1460         }
1461         return false;
1462     }
1463     
1464     unsigned oldOffset = m_currentIndex;
1465     
1466     bool allAreClosureCalls = true;
1467     bool allAreDirectCalls = true;
1468     for (unsigned i = callLinkStatus.size(); i--;) {
1469         if (callLinkStatus[i].callee().isClosureCall())
1470             allAreDirectCalls = false;
1471         else
1472             allAreClosureCalls = false;
1473     }
1474     
1475     Node* thingToSwitchOn;
1476     if (allAreDirectCalls)
1477         thingToSwitchOn = callTargetNode;
1478     else if (allAreClosureCalls)
1479         thingToSwitchOn = addToGraph(GetExecutable, callTargetNode);
1480     else {
1481         // FIXME: We should be able to handle this case, but it's tricky and we don't know of cases
1482         // where it would be beneficial. Also, CallLinkStatus would make all callees appear like
1483         // closure calls if any calls were closure calls - except for calls to internal functions.
1484         // So this will only arise if some callees are internal functions and others are closures.
1485         // https://bugs.webkit.org/show_bug.cgi?id=136020
1486         if (verbose) {
1487             dataLog("Bailing inlining (mix).\n");
1488             dataLog("Stack: ", currentCodeOrigin(), "\n");
1489         }
1490         return false;
1491     }
1492     
1493     if (verbose) {
1494         dataLog("Doing hard inlining...\n");
1495         dataLog("Stack: ", currentCodeOrigin(), "\n");
1496     }
1497     
1498     // This makes me wish that we were in SSA all the time. We need to pick a variable into which to
1499     // store the callee so that it will be accessible to all of the blocks we're about to create. We
1500     // get away with doing an immediate-set here because we wouldn't have performed any side effects
1501     // yet.
1502     if (verbose)
1503         dataLog("Register offset: ", registerOffset);
1504     VirtualRegister calleeReg(registerOffset + JSStack::Callee);
1505     calleeReg = m_inlineStackTop->remapOperand(calleeReg);
1506     if (verbose)
1507         dataLog("Callee is going to be ", calleeReg, "\n");
1508     setDirect(calleeReg, callTargetNode, ImmediateSetWithFlush);
1509     
1510     SwitchData& data = *m_graph.m_switchData.add();
1511     data.kind = SwitchCell;
1512     addToGraph(Switch, OpInfo(&data), thingToSwitchOn);
1513     
1514     BasicBlock* originBlock = m_currentBlock;
1515     if (verbose)
1516         dataLog("Marking ", RawPointer(originBlock), " as linked (origin of poly inline)\n");
1517     originBlock->didLink();
1518     cancelLinkingForBlock(m_inlineStackTop, originBlock);
1519     
1520     // Each inlined callee will have a landing block that it returns at. They should all have jumps
1521     // to the continuation block, which we create last.
1522     Vector<BasicBlock*> landingBlocks;
1523     
1524     // We make force this true if we give up on inlining any of the edges.
1525     bool couldTakeSlowPath = callLinkStatus.couldTakeSlowPath();
1526     
1527     if (verbose)
1528         dataLog("About to loop over functions at ", currentCodeOrigin(), ".\n");
1529     
1530     for (unsigned i = 0; i < callLinkStatus.size(); ++i) {
1531         m_currentIndex = oldOffset;
1532         RefPtr<BasicBlock> block = adoptRef(new BasicBlock(UINT_MAX, m_numArguments, m_numLocals, PNaN));
1533         m_currentBlock = block.get();
1534         m_graph.appendBlock(block);
1535         prepareToParseBlock();
1536         
1537         Node* myCallTargetNode = getDirect(calleeReg);
1538         
1539         bool inliningResult = attemptToInlineCall(
1540             myCallTargetNode, resultOperand, callLinkStatus[i].callee(), registerOffset,
1541             argumentCountIncludingThis, nextOffset, kind, CallerLinksManually, prediction,
1542             inliningBalance);
1543         
1544         if (!inliningResult) {
1545             // That failed so we let the block die. Nothing interesting should have been added to
1546             // the block. We also give up on inlining any of the (less frequent) callees.
1547             ASSERT(m_currentBlock == block.get());
1548             ASSERT(m_graph.m_blocks.last() == block);
1549             m_graph.killBlockAndItsContents(block.get());
1550             m_graph.m_blocks.removeLast();
1551             
1552             // The fact that inlining failed means we need a slow path.
1553             couldTakeSlowPath = true;
1554             break;
1555         }
1556         
1557         JSCell* thingToCaseOn;
1558         if (allAreDirectCalls)
1559             thingToCaseOn = callLinkStatus[i].callee().nonExecutableCallee();
1560         else {
1561             ASSERT(allAreClosureCalls);
1562             thingToCaseOn = callLinkStatus[i].callee().executable();
1563         }
1564         data.cases.append(SwitchCase(m_graph.freeze(thingToCaseOn), block.get()));
1565         m_currentIndex = nextOffset;
1566         processSetLocalQueue(); // This only comes into play for intrinsics, since normal inlined code will leave an empty queue.
1567         addToGraph(Jump);
1568         if (verbose)
1569             dataLog("Marking ", RawPointer(m_currentBlock), " as linked (tail of poly inlinee)\n");
1570         m_currentBlock->didLink();
1571         landingBlocks.append(m_currentBlock);
1572
1573         if (verbose)
1574             dataLog("Finished inlining ", callLinkStatus[i].callee(), " at ", currentCodeOrigin(), ".\n");
1575     }
1576     
1577     RefPtr<BasicBlock> slowPathBlock = adoptRef(
1578         new BasicBlock(UINT_MAX, m_numArguments, m_numLocals, PNaN));
1579     m_currentIndex = oldOffset;
1580     data.fallThrough = BranchTarget(slowPathBlock.get());
1581     m_graph.appendBlock(slowPathBlock);
1582     if (verbose)
1583         dataLog("Marking ", RawPointer(slowPathBlock.get()), " as linked (slow path block)\n");
1584     slowPathBlock->didLink();
1585     prepareToParseBlock();
1586     m_currentBlock = slowPathBlock.get();
1587     Node* myCallTargetNode = getDirect(calleeReg);
1588     if (couldTakeSlowPath) {
1589         addCall(
1590             resultOperand, callOp, OpInfo(), myCallTargetNode, argumentCountIncludingThis,
1591             registerOffset, prediction);
1592     } else {
1593         addToGraph(CheckBadCell);
1594         addToGraph(Phantom, myCallTargetNode);
1595         emitArgumentPhantoms(registerOffset, argumentCountIncludingThis, specializationKind);
1596         
1597         set(VirtualRegister(resultOperand), addToGraph(BottomValue));
1598     }
1599
1600     m_currentIndex = nextOffset;
1601     processSetLocalQueue();
1602     addToGraph(Jump);
1603     landingBlocks.append(m_currentBlock);
1604     
1605     RefPtr<BasicBlock> continuationBlock = adoptRef(
1606         new BasicBlock(UINT_MAX, m_numArguments, m_numLocals, PNaN));
1607     m_graph.appendBlock(continuationBlock);
1608     if (verbose)
1609         dataLog("Adding unlinked block ", RawPointer(continuationBlock.get()), " (continuation)\n");
1610     m_inlineStackTop->m_unlinkedBlocks.append(UnlinkedBlock(continuationBlock.get()));
1611     prepareToParseBlock();
1612     m_currentBlock = continuationBlock.get();
1613     
1614     for (unsigned i = landingBlocks.size(); i--;)
1615         landingBlocks[i]->last()->targetBlock() = continuationBlock.get();
1616     
1617     m_currentIndex = oldOffset;
1618     
1619     if (verbose) {
1620         dataLog("Done inlining (hard).\n");
1621         dataLog("Stack: ", currentCodeOrigin(), "\n");
1622     }
1623     return true;
1624 }
1625
1626 bool ByteCodeParser::handleMinMax(int resultOperand, NodeType op, int registerOffset, int argumentCountIncludingThis)
1627 {
1628     if (argumentCountIncludingThis == 1) { // Math.min()
1629         set(VirtualRegister(resultOperand), addToGraph(JSConstant, OpInfo(m_constantNaN)));
1630         return true;
1631     }
1632      
1633     if (argumentCountIncludingThis == 2) { // Math.min(x)
1634         Node* result = get(VirtualRegister(virtualRegisterForArgument(1, registerOffset)));
1635         addToGraph(Phantom, Edge(result, NumberUse));
1636         set(VirtualRegister(resultOperand), result);
1637         return true;
1638     }
1639     
1640     if (argumentCountIncludingThis == 3) { // Math.min(x, y)
1641         set(VirtualRegister(resultOperand), addToGraph(op, get(virtualRegisterForArgument(1, registerOffset)), get(virtualRegisterForArgument(2, registerOffset))));
1642         return true;
1643     }
1644     
1645     // Don't handle >=3 arguments for now.
1646     return false;
1647 }
1648
1649 bool ByteCodeParser::handleIntrinsic(int resultOperand, Intrinsic intrinsic, int registerOffset, int argumentCountIncludingThis, SpeculatedType prediction)
1650 {
1651     switch (intrinsic) {
1652     case AbsIntrinsic: {
1653         if (argumentCountIncludingThis == 1) { // Math.abs()
1654             set(VirtualRegister(resultOperand), addToGraph(JSConstant, OpInfo(m_constantNaN)));
1655             return true;
1656         }
1657
1658         if (!MacroAssembler::supportsFloatingPointAbs())
1659             return false;
1660
1661         Node* node = addToGraph(ArithAbs, get(virtualRegisterForArgument(1, registerOffset)));
1662         if (m_inlineStackTop->m_exitProfile.hasExitSite(m_currentIndex, Overflow))
1663             node->mergeFlags(NodeMayOverflowInDFG);
1664         set(VirtualRegister(resultOperand), node);
1665         return true;
1666     }
1667
1668     case MinIntrinsic:
1669         return handleMinMax(resultOperand, ArithMin, registerOffset, argumentCountIncludingThis);
1670         
1671     case MaxIntrinsic:
1672         return handleMinMax(resultOperand, ArithMax, registerOffset, argumentCountIncludingThis);
1673         
1674     case SqrtIntrinsic:
1675     case CosIntrinsic:
1676     case SinIntrinsic: {
1677         if (argumentCountIncludingThis == 1) {
1678             set(VirtualRegister(resultOperand), addToGraph(JSConstant, OpInfo(m_constantNaN)));
1679             return true;
1680         }
1681         
1682         switch (intrinsic) {
1683         case SqrtIntrinsic:
1684             if (!MacroAssembler::supportsFloatingPointSqrt())
1685                 return false;
1686             
1687             set(VirtualRegister(resultOperand), addToGraph(ArithSqrt, get(virtualRegisterForArgument(1, registerOffset))));
1688             return true;
1689             
1690         case CosIntrinsic:
1691             set(VirtualRegister(resultOperand), addToGraph(ArithCos, get(virtualRegisterForArgument(1, registerOffset))));
1692             return true;
1693             
1694         case SinIntrinsic:
1695             set(VirtualRegister(resultOperand), addToGraph(ArithSin, get(virtualRegisterForArgument(1, registerOffset))));
1696             return true;
1697             
1698         default:
1699             RELEASE_ASSERT_NOT_REACHED();
1700             return false;
1701         }
1702     }
1703         
1704     case ArrayPushIntrinsic: {
1705         if (argumentCountIncludingThis != 2)
1706             return false;
1707         
1708         ArrayMode arrayMode = getArrayMode(m_currentInstruction[OPCODE_LENGTH(op_call) - 2].u.arrayProfile);
1709         if (!arrayMode.isJSArray())
1710             return false;
1711         switch (arrayMode.type()) {
1712         case Array::Undecided:
1713         case Array::Int32:
1714         case Array::Double:
1715         case Array::Contiguous:
1716         case Array::ArrayStorage: {
1717             Node* arrayPush = addToGraph(ArrayPush, OpInfo(arrayMode.asWord()), OpInfo(prediction), get(virtualRegisterForArgument(0, registerOffset)), get(virtualRegisterForArgument(1, registerOffset)));
1718             set(VirtualRegister(resultOperand), arrayPush);
1719             
1720             return true;
1721         }
1722             
1723         default:
1724             return false;
1725         }
1726     }
1727         
1728     case ArrayPopIntrinsic: {
1729         if (argumentCountIncludingThis != 1)
1730             return false;
1731         
1732         ArrayMode arrayMode = getArrayMode(m_currentInstruction[OPCODE_LENGTH(op_call) - 2].u.arrayProfile);
1733         if (!arrayMode.isJSArray())
1734             return false;
1735         switch (arrayMode.type()) {
1736         case Array::Int32:
1737         case Array::Double:
1738         case Array::Contiguous:
1739         case Array::ArrayStorage: {
1740             Node* arrayPop = addToGraph(ArrayPop, OpInfo(arrayMode.asWord()), OpInfo(prediction), get(virtualRegisterForArgument(0, registerOffset)));
1741             set(VirtualRegister(resultOperand), arrayPop);
1742             return true;
1743         }
1744             
1745         default:
1746             return false;
1747         }
1748     }
1749
1750     case CharCodeAtIntrinsic: {
1751         if (argumentCountIncludingThis != 2)
1752             return false;
1753
1754         VirtualRegister thisOperand = virtualRegisterForArgument(0, registerOffset);
1755         VirtualRegister indexOperand = virtualRegisterForArgument(1, registerOffset);
1756         Node* charCode = addToGraph(StringCharCodeAt, OpInfo(ArrayMode(Array::String).asWord()), get(thisOperand), get(indexOperand));
1757
1758         set(VirtualRegister(resultOperand), charCode);
1759         return true;
1760     }
1761
1762     case CharAtIntrinsic: {
1763         if (argumentCountIncludingThis != 2)
1764             return false;
1765
1766         VirtualRegister thisOperand = virtualRegisterForArgument(0, registerOffset);
1767         VirtualRegister indexOperand = virtualRegisterForArgument(1, registerOffset);
1768         Node* charCode = addToGraph(StringCharAt, OpInfo(ArrayMode(Array::String).asWord()), get(thisOperand), get(indexOperand));
1769
1770         set(VirtualRegister(resultOperand), charCode);
1771         return true;
1772     }
1773     case FromCharCodeIntrinsic: {
1774         if (argumentCountIncludingThis != 2)
1775             return false;
1776
1777         VirtualRegister indexOperand = virtualRegisterForArgument(1, registerOffset);
1778         Node* charCode = addToGraph(StringFromCharCode, get(indexOperand));
1779
1780         set(VirtualRegister(resultOperand), charCode);
1781
1782         return true;
1783     }
1784
1785     case RegExpExecIntrinsic: {
1786         if (argumentCountIncludingThis != 2)
1787             return false;
1788         
1789         Node* regExpExec = addToGraph(RegExpExec, OpInfo(0), OpInfo(prediction), get(virtualRegisterForArgument(0, registerOffset)), get(virtualRegisterForArgument(1, registerOffset)));
1790         set(VirtualRegister(resultOperand), regExpExec);
1791         
1792         return true;
1793     }
1794         
1795     case RegExpTestIntrinsic: {
1796         if (argumentCountIncludingThis != 2)
1797             return false;
1798         
1799         Node* regExpExec = addToGraph(RegExpTest, OpInfo(0), OpInfo(prediction), get(virtualRegisterForArgument(0, registerOffset)), get(virtualRegisterForArgument(1, registerOffset)));
1800         set(VirtualRegister(resultOperand), regExpExec);
1801         
1802         return true;
1803     }
1804
1805     case IMulIntrinsic: {
1806         if (argumentCountIncludingThis != 3)
1807             return false;
1808         VirtualRegister leftOperand = virtualRegisterForArgument(1, registerOffset);
1809         VirtualRegister rightOperand = virtualRegisterForArgument(2, registerOffset);
1810         Node* left = get(leftOperand);
1811         Node* right = get(rightOperand);
1812         set(VirtualRegister(resultOperand), addToGraph(ArithIMul, left, right));
1813         return true;
1814     }
1815         
1816     case FRoundIntrinsic: {
1817         if (argumentCountIncludingThis != 2)
1818             return false;
1819         VirtualRegister operand = virtualRegisterForArgument(1, registerOffset);
1820         set(VirtualRegister(resultOperand), addToGraph(ArithFRound, get(operand)));
1821         return true;
1822     }
1823         
1824     case DFGTrueIntrinsic: {
1825         set(VirtualRegister(resultOperand), jsConstant(jsBoolean(true)));
1826         return true;
1827     }
1828         
1829     case OSRExitIntrinsic: {
1830         addToGraph(ForceOSRExit);
1831         set(VirtualRegister(resultOperand), addToGraph(JSConstant, OpInfo(m_constantUndefined)));
1832         return true;
1833     }
1834         
1835     case IsFinalTierIntrinsic: {
1836         set(VirtualRegister(resultOperand),
1837             jsConstant(jsBoolean(Options::useFTLJIT() ? isFTL(m_graph.m_plan.mode) : true)));
1838         return true;
1839     }
1840         
1841     case SetInt32HeapPredictionIntrinsic: {
1842         for (int i = 1; i < argumentCountIncludingThis; ++i) {
1843             Node* node = get(virtualRegisterForArgument(i, registerOffset));
1844             if (node->hasHeapPrediction())
1845                 node->setHeapPrediction(SpecInt32);
1846         }
1847         set(VirtualRegister(resultOperand), addToGraph(JSConstant, OpInfo(m_constantUndefined)));
1848         return true;
1849     }
1850         
1851     case FiatInt52Intrinsic: {
1852         if (argumentCountIncludingThis != 2)
1853             return false;
1854         VirtualRegister operand = virtualRegisterForArgument(1, registerOffset);
1855         if (enableInt52())
1856             set(VirtualRegister(resultOperand), addToGraph(FiatInt52, get(operand)));
1857         else
1858             set(VirtualRegister(resultOperand), get(operand));
1859         return true;
1860     }
1861         
1862     default:
1863         return false;
1864     }
1865 }
1866
1867 bool ByteCodeParser::handleTypedArrayConstructor(
1868     int resultOperand, InternalFunction* function, int registerOffset,
1869     int argumentCountIncludingThis, TypedArrayType type)
1870 {
1871     if (!isTypedView(type))
1872         return false;
1873     
1874     if (function->classInfo() != constructorClassInfoForType(type))
1875         return false;
1876     
1877     if (function->globalObject() != m_inlineStackTop->m_codeBlock->globalObject())
1878         return false;
1879     
1880     // We only have an intrinsic for the case where you say:
1881     //
1882     // new FooArray(blah);
1883     //
1884     // Of course, 'blah' could be any of the following:
1885     //
1886     // - Integer, indicating that you want to allocate an array of that length.
1887     //   This is the thing we're hoping for, and what we can actually do meaningful
1888     //   optimizations for.
1889     //
1890     // - Array buffer, indicating that you want to create a view onto that _entire_
1891     //   buffer.
1892     //
1893     // - Non-buffer object, indicating that you want to create a copy of that
1894     //   object by pretending that it quacks like an array.
1895     //
1896     // - Anything else, indicating that you want to have an exception thrown at
1897     //   you.
1898     //
1899     // The intrinsic, NewTypedArray, will behave as if it could do any of these
1900     // things up until we do Fixup. Thereafter, if child1 (i.e. 'blah') is
1901     // predicted Int32, then we lock it in as a normal typed array allocation.
1902     // Otherwise, NewTypedArray turns into a totally opaque function call that
1903     // may clobber the world - by virtue of it accessing properties on what could
1904     // be an object.
1905     //
1906     // Note that although the generic form of NewTypedArray sounds sort of awful,
1907     // it is actually quite likely to be more efficient than a fully generic
1908     // Construct. So, we might want to think about making NewTypedArray variadic,
1909     // or else making Construct not super slow.
1910     
1911     if (argumentCountIncludingThis != 2)
1912         return false;
1913     
1914     set(VirtualRegister(resultOperand),
1915         addToGraph(NewTypedArray, OpInfo(type), get(virtualRegisterForArgument(1, registerOffset))));
1916     return true;
1917 }
1918
1919 bool ByteCodeParser::handleConstantInternalFunction(
1920     int resultOperand, InternalFunction* function, int registerOffset,
1921     int argumentCountIncludingThis, CodeSpecializationKind kind)
1922 {
1923     // If we ever find that we have a lot of internal functions that we specialize for,
1924     // then we should probably have some sort of hashtable dispatch, or maybe even
1925     // dispatch straight through the MethodTable of the InternalFunction. But for now,
1926     // it seems that this case is hit infrequently enough, and the number of functions
1927     // we know about is small enough, that having just a linear cascade of if statements
1928     // is good enough.
1929     
1930     if (function->classInfo() == ArrayConstructor::info()) {
1931         if (function->globalObject() != m_inlineStackTop->m_codeBlock->globalObject())
1932             return false;
1933         
1934         if (argumentCountIncludingThis == 2) {
1935             set(VirtualRegister(resultOperand),
1936                 addToGraph(NewArrayWithSize, OpInfo(ArrayWithUndecided), get(virtualRegisterForArgument(1, registerOffset))));
1937             return true;
1938         }
1939         
1940         for (int i = 1; i < argumentCountIncludingThis; ++i)
1941             addVarArgChild(get(virtualRegisterForArgument(i, registerOffset)));
1942         set(VirtualRegister(resultOperand),
1943             addToGraph(Node::VarArg, NewArray, OpInfo(ArrayWithUndecided), OpInfo(0)));
1944         return true;
1945     }
1946     
1947     if (function->classInfo() == StringConstructor::info()) {
1948         Node* result;
1949         
1950         if (argumentCountIncludingThis <= 1)
1951             result = jsConstant(m_vm->smallStrings.emptyString());
1952         else
1953             result = addToGraph(ToString, get(virtualRegisterForArgument(1, registerOffset)));
1954         
1955         if (kind == CodeForConstruct)
1956             result = addToGraph(NewStringObject, OpInfo(function->globalObject()->stringObjectStructure()), result);
1957         
1958         set(VirtualRegister(resultOperand), result);
1959         return true;
1960     }
1961     
1962     for (unsigned typeIndex = 0; typeIndex < NUMBER_OF_TYPED_ARRAY_TYPES; ++typeIndex) {
1963         bool result = handleTypedArrayConstructor(
1964             resultOperand, function, registerOffset, argumentCountIncludingThis,
1965             indexToTypedArrayType(typeIndex));
1966         if (result)
1967             return true;
1968     }
1969     
1970     return false;
1971 }
1972
1973 Node* ByteCodeParser::handleGetByOffset(SpeculatedType prediction, Node* base, const StructureSet& structureSet, unsigned identifierNumber, PropertyOffset offset, NodeType op)
1974 {
1975     if (base->hasConstant()) {
1976         if (JSValue constant = m_graph.tryGetConstantProperty(base->asJSValue(), structureSet, offset)) {
1977             addToGraph(Phantom, base);
1978             return weakJSConstant(constant);
1979         }
1980     }
1981     
1982     Node* propertyStorage;
1983     if (isInlineOffset(offset))
1984         propertyStorage = base;
1985     else
1986         propertyStorage = addToGraph(GetButterfly, base);
1987     Node* getByOffset = addToGraph(op, OpInfo(m_graph.m_storageAccessData.size()), OpInfo(prediction), propertyStorage, base);
1988
1989     StorageAccessData storageAccessData;
1990     storageAccessData.offset = offset;
1991     storageAccessData.identifierNumber = identifierNumber;
1992     m_graph.m_storageAccessData.append(storageAccessData);
1993
1994     return getByOffset;
1995 }
1996
1997 Node* ByteCodeParser::handlePutByOffset(Node* base, unsigned identifier, PropertyOffset offset, Node* value)
1998 {
1999     Node* propertyStorage;
2000     if (isInlineOffset(offset))
2001         propertyStorage = base;
2002     else
2003         propertyStorage = addToGraph(GetButterfly, base);
2004     Node* result = addToGraph(PutByOffset, OpInfo(m_graph.m_storageAccessData.size()), propertyStorage, base, value);
2005     
2006     StorageAccessData storageAccessData;
2007     storageAccessData.offset = offset;
2008     storageAccessData.identifierNumber = identifier;
2009     m_graph.m_storageAccessData.append(storageAccessData);
2010
2011     return result;
2012 }
2013
2014 void ByteCodeParser::emitChecks(const ConstantStructureCheckVector& vector)
2015 {
2016     for (unsigned i = 0; i < vector.size(); ++i)
2017         cellConstantWithStructureCheck(vector[i].constant(), vector[i].structure());
2018 }
2019
2020 void ByteCodeParser::handleGetById(
2021     int destinationOperand, SpeculatedType prediction, Node* base, unsigned identifierNumber,
2022     const GetByIdStatus& getByIdStatus)
2023 {
2024     NodeType getById = getByIdStatus.makesCalls() ? GetByIdFlush : GetById;
2025     
2026     if (!getByIdStatus.isSimple() || !Options::enableAccessInlining()) {
2027         set(VirtualRegister(destinationOperand),
2028             addToGraph(getById, OpInfo(identifierNumber), OpInfo(prediction), base));
2029         return;
2030     }
2031     
2032     if (getByIdStatus.numVariants() > 1) {
2033         if (getByIdStatus.makesCalls() || !isFTL(m_graph.m_plan.mode)
2034             || !Options::enablePolymorphicAccessInlining()) {
2035             set(VirtualRegister(destinationOperand),
2036                 addToGraph(getById, OpInfo(identifierNumber), OpInfo(prediction), base));
2037             return;
2038         }
2039         
2040         if (m_graph.compilation())
2041             m_graph.compilation()->noticeInlinedGetById();
2042     
2043         // 1) Emit prototype structure checks for all chains. This could sort of maybe not be
2044         //    optimal, if there is some rarely executed case in the chain that requires a lot
2045         //    of checks and those checks are not watchpointable.
2046         for (unsigned variantIndex = getByIdStatus.numVariants(); variantIndex--;)
2047             emitChecks(getByIdStatus[variantIndex].constantChecks());
2048         
2049         // 2) Emit a MultiGetByOffset
2050         MultiGetByOffsetData* data = m_graph.m_multiGetByOffsetData.add();
2051         data->variants = getByIdStatus.variants();
2052         data->identifierNumber = identifierNumber;
2053         set(VirtualRegister(destinationOperand),
2054             addToGraph(MultiGetByOffset, OpInfo(data), OpInfo(prediction), base));
2055         return;
2056     }
2057     
2058     ASSERT(getByIdStatus.numVariants() == 1);
2059     GetByIdVariant variant = getByIdStatus[0];
2060                 
2061     if (m_graph.compilation())
2062         m_graph.compilation()->noticeInlinedGetById();
2063     
2064     Node* originalBase = base;
2065                 
2066     addToGraph(CheckStructure, OpInfo(m_graph.addStructureSet(variant.structureSet())), base);
2067     
2068     emitChecks(variant.constantChecks());
2069
2070     if (variant.alternateBase())
2071         base = weakJSConstant(variant.alternateBase());
2072     
2073     // Unless we want bugs like https://bugs.webkit.org/show_bug.cgi?id=88783, we need to
2074     // ensure that the base of the original get_by_id is kept alive until we're done with
2075     // all of the speculations. We only insert the Phantom if there had been a CheckStructure
2076     // on something other than the base following the CheckStructure on base.
2077     if (originalBase != base)
2078         addToGraph(Phantom, originalBase);
2079     
2080     Node* loadedValue = handleGetByOffset(
2081         variant.callLinkStatus() ? SpecCellOther : prediction,
2082         base, variant.baseStructure(), identifierNumber, variant.offset(),
2083         variant.callLinkStatus() ? GetGetterSetterByOffset : GetByOffset);
2084     
2085     if (!variant.callLinkStatus()) {
2086         set(VirtualRegister(destinationOperand), loadedValue);
2087         return;
2088     }
2089     
2090     Node* getter = addToGraph(GetGetter, loadedValue);
2091     
2092     // Make a call. We don't try to get fancy with using the smallest operand number because
2093     // the stack layout phase should compress the stack anyway.
2094     
2095     unsigned numberOfParameters = 0;
2096     numberOfParameters++; // The 'this' argument.
2097     numberOfParameters++; // True return PC.
2098     
2099     // Start with a register offset that corresponds to the last in-use register.
2100     int registerOffset = virtualRegisterForLocal(
2101         m_inlineStackTop->m_profiledBlock->m_numCalleeRegisters - 1).offset();
2102     registerOffset -= numberOfParameters;
2103     registerOffset -= JSStack::CallFrameHeaderSize;
2104     
2105     // Get the alignment right.
2106     registerOffset = -WTF::roundUpToMultipleOf(
2107         stackAlignmentRegisters(),
2108         -registerOffset);
2109     
2110     ensureLocals(
2111         m_inlineStackTop->remapOperand(
2112             VirtualRegister(registerOffset)).toLocal());
2113     
2114     // Issue SetLocals. This has two effects:
2115     // 1) That's how handleCall() sees the arguments.
2116     // 2) If we inline then this ensures that the arguments are flushed so that if you use
2117     //    the dreaded arguments object on the getter, the right things happen. Well, sort of -
2118     //    since we only really care about 'this' in this case. But we're not going to take that
2119     //    shortcut.
2120     int nextRegister = registerOffset + JSStack::CallFrameHeaderSize;
2121     set(VirtualRegister(nextRegister++), originalBase, ImmediateNakedSet);
2122     
2123     handleCall(
2124         destinationOperand, Call, InlineCallFrame::GetterCall, OPCODE_LENGTH(op_get_by_id),
2125         getter, numberOfParameters - 1, registerOffset, *variant.callLinkStatus(), prediction);
2126 }
2127
2128 void ByteCodeParser::emitPutById(
2129     Node* base, unsigned identifierNumber, Node* value, const PutByIdStatus& putByIdStatus, bool isDirect)
2130 {
2131     if (isDirect)
2132         addToGraph(PutByIdDirect, OpInfo(identifierNumber), base, value);
2133     else
2134         addToGraph(putByIdStatus.makesCalls() ? PutByIdFlush : PutById, OpInfo(identifierNumber), base, value);
2135 }
2136
2137 void ByteCodeParser::handlePutById(
2138     Node* base, unsigned identifierNumber, Node* value,
2139     const PutByIdStatus& putByIdStatus, bool isDirect)
2140 {
2141     if (!putByIdStatus.isSimple() || !Options::enableAccessInlining()) {
2142         if (!putByIdStatus.isSet())
2143             addToGraph(ForceOSRExit);
2144         emitPutById(base, identifierNumber, value, putByIdStatus, isDirect);
2145         return;
2146     }
2147     
2148     if (putByIdStatus.numVariants() > 1) {
2149         if (!isFTL(m_graph.m_plan.mode) || putByIdStatus.makesCalls()
2150             || !Options::enablePolymorphicAccessInlining()) {
2151             emitPutById(base, identifierNumber, value, putByIdStatus, isDirect);
2152             return;
2153         }
2154         
2155         if (m_graph.compilation())
2156             m_graph.compilation()->noticeInlinedPutById();
2157         
2158         if (!isDirect) {
2159             for (unsigned variantIndex = putByIdStatus.numVariants(); variantIndex--;) {
2160                 if (putByIdStatus[variantIndex].kind() != PutByIdVariant::Transition)
2161                     continue;
2162                 emitChecks(putByIdStatus[variantIndex].constantChecks());
2163             }
2164         }
2165         
2166         MultiPutByOffsetData* data = m_graph.m_multiPutByOffsetData.add();
2167         data->variants = putByIdStatus.variants();
2168         data->identifierNumber = identifierNumber;
2169         addToGraph(MultiPutByOffset, OpInfo(data), base, value);
2170         return;
2171     }
2172     
2173     ASSERT(putByIdStatus.numVariants() == 1);
2174     const PutByIdVariant& variant = putByIdStatus[0];
2175     
2176     switch (variant.kind()) {
2177     case PutByIdVariant::Replace: {
2178         addToGraph(CheckStructure, OpInfo(m_graph.addStructureSet(variant.structure())), base);
2179         handlePutByOffset(base, identifierNumber, variant.offset(), value);
2180         if (m_graph.compilation())
2181             m_graph.compilation()->noticeInlinedPutById();
2182         return;
2183     }
2184     
2185     case PutByIdVariant::Transition: {
2186         addToGraph(CheckStructure, OpInfo(m_graph.addStructureSet(variant.oldStructure())), base);
2187         emitChecks(variant.constantChecks());
2188
2189         ASSERT(variant.oldStructureForTransition()->transitionWatchpointSetHasBeenInvalidated());
2190     
2191         Node* propertyStorage;
2192         Transition* transition = m_graph.m_transitions.add(
2193             variant.oldStructureForTransition(), variant.newStructure());
2194
2195         if (variant.reallocatesStorage()) {
2196
2197             // If we're growing the property storage then it must be because we're
2198             // storing into the out-of-line storage.
2199             ASSERT(!isInlineOffset(variant.offset()));
2200
2201             if (!variant.oldStructureForTransition()->outOfLineCapacity()) {
2202                 propertyStorage = addToGraph(
2203                     AllocatePropertyStorage, OpInfo(transition), base);
2204             } else {
2205                 propertyStorage = addToGraph(
2206                     ReallocatePropertyStorage, OpInfo(transition),
2207                     base, addToGraph(GetButterfly, base));
2208             }
2209         } else {
2210             if (isInlineOffset(variant.offset()))
2211                 propertyStorage = base;
2212             else
2213                 propertyStorage = addToGraph(GetButterfly, base);
2214         }
2215
2216         addToGraph(PutStructure, OpInfo(transition), base);
2217
2218         addToGraph(
2219             PutByOffset,
2220             OpInfo(m_graph.m_storageAccessData.size()),
2221             propertyStorage,
2222             base,
2223             value);
2224
2225         StorageAccessData storageAccessData;
2226         storageAccessData.offset = variant.offset();
2227         storageAccessData.identifierNumber = identifierNumber;
2228         m_graph.m_storageAccessData.append(storageAccessData);
2229
2230         if (m_graph.compilation())
2231             m_graph.compilation()->noticeInlinedPutById();
2232         return;
2233     }
2234         
2235     case PutByIdVariant::Setter: {
2236         Node* originalBase = base;
2237         
2238         addToGraph(
2239             CheckStructure, OpInfo(m_graph.addStructureSet(variant.structure())), base);
2240         
2241         emitChecks(variant.constantChecks());
2242         
2243         if (variant.alternateBase())
2244             base = weakJSConstant(variant.alternateBase());
2245         
2246         Node* loadedValue = handleGetByOffset(
2247             SpecCellOther, base, variant.baseStructure(), identifierNumber, variant.offset(),
2248             GetGetterSetterByOffset);
2249         
2250         Node* setter = addToGraph(GetSetter, loadedValue);
2251         
2252         // Make a call. We don't try to get fancy with using the smallest operand number because
2253         // the stack layout phase should compress the stack anyway.
2254     
2255         unsigned numberOfParameters = 0;
2256         numberOfParameters++; // The 'this' argument.
2257         numberOfParameters++; // The new value.
2258         numberOfParameters++; // True return PC.
2259     
2260         // Start with a register offset that corresponds to the last in-use register.
2261         int registerOffset = virtualRegisterForLocal(
2262             m_inlineStackTop->m_profiledBlock->m_numCalleeRegisters - 1).offset();
2263         registerOffset -= numberOfParameters;
2264         registerOffset -= JSStack::CallFrameHeaderSize;
2265     
2266         // Get the alignment right.
2267         registerOffset = -WTF::roundUpToMultipleOf(
2268             stackAlignmentRegisters(),
2269             -registerOffset);
2270     
2271         ensureLocals(
2272             m_inlineStackTop->remapOperand(
2273                 VirtualRegister(registerOffset)).toLocal());
2274     
2275         int nextRegister = registerOffset + JSStack::CallFrameHeaderSize;
2276         set(VirtualRegister(nextRegister++), originalBase, ImmediateNakedSet);
2277         set(VirtualRegister(nextRegister++), value, ImmediateNakedSet);
2278     
2279         handleCall(
2280             VirtualRegister().offset(), Call, InlineCallFrame::SetterCall,
2281             OPCODE_LENGTH(op_put_by_id), setter, numberOfParameters - 1, registerOffset,
2282             *variant.callLinkStatus(), SpecOther);
2283         return;
2284     }
2285     
2286     default: {
2287         emitPutById(base, identifierNumber, value, putByIdStatus, isDirect);
2288         return;
2289     } }
2290 }
2291
2292 void ByteCodeParser::prepareToParseBlock()
2293 {
2294     clearCaches();
2295     ASSERT(m_setLocalQueue.isEmpty());
2296 }
2297
2298 void ByteCodeParser::clearCaches()
2299 {
2300     m_constants.resize(0);
2301 }
2302
2303 Node* ByteCodeParser::getScope(unsigned skipCount)
2304 {
2305     Node* localBase = get(VirtualRegister(JSStack::ScopeChain));
2306     for (unsigned n = skipCount; n--;)
2307         localBase = addToGraph(SkipScope, localBase);
2308     return localBase;
2309 }
2310
2311 bool ByteCodeParser::parseBlock(unsigned limit)
2312 {
2313     bool shouldContinueParsing = true;
2314
2315     Interpreter* interpreter = m_vm->interpreter;
2316     Instruction* instructionsBegin = m_inlineStackTop->m_codeBlock->instructions().begin();
2317     unsigned blockBegin = m_currentIndex;
2318     
2319     // If we are the first basic block, introduce markers for arguments. This allows
2320     // us to track if a use of an argument may use the actual argument passed, as
2321     // opposed to using a value we set explicitly.
2322     if (m_currentBlock == m_graph.block(0) && !inlineCallFrame()) {
2323         m_graph.m_arguments.resize(m_numArguments);
2324         for (unsigned argument = 0; argument < m_numArguments; ++argument) {
2325             VariableAccessData* variable = newVariableAccessData(
2326                 virtualRegisterForArgument(argument), m_codeBlock->isCaptured(virtualRegisterForArgument(argument)));
2327             variable->mergeStructureCheckHoistingFailed(
2328                 m_inlineStackTop->m_exitProfile.hasExitSite(m_currentIndex, BadCache));
2329             variable->mergeCheckArrayHoistingFailed(
2330                 m_inlineStackTop->m_exitProfile.hasExitSite(m_currentIndex, BadIndexingType));
2331             
2332             Node* setArgument = addToGraph(SetArgument, OpInfo(variable));
2333             m_graph.m_arguments[argument] = setArgument;
2334             m_currentBlock->variablesAtTail.setArgumentFirstTime(argument, setArgument);
2335         }
2336     }
2337
2338     while (true) {
2339         processSetLocalQueue();
2340         
2341         // Don't extend over jump destinations.
2342         if (m_currentIndex == limit) {
2343             // Ordinarily we want to plant a jump. But refuse to do this if the block is
2344             // empty. This is a special case for inlining, which might otherwise create
2345             // some empty blocks in some cases. When parseBlock() returns with an empty
2346             // block, it will get repurposed instead of creating a new one. Note that this
2347             // logic relies on every bytecode resulting in one or more nodes, which would
2348             // be true anyway except for op_loop_hint, which emits a Phantom to force this
2349             // to be true.
2350             if (!m_currentBlock->isEmpty())
2351                 addToGraph(Jump, OpInfo(m_currentIndex));
2352             return shouldContinueParsing;
2353         }
2354         
2355         // Switch on the current bytecode opcode.
2356         Instruction* currentInstruction = instructionsBegin + m_currentIndex;
2357         m_currentInstruction = currentInstruction; // Some methods want to use this, and we'd rather not thread it through calls.
2358         OpcodeID opcodeID = interpreter->getOpcodeID(currentInstruction->u.opcode);
2359         
2360         if (Options::verboseDFGByteCodeParsing())
2361             dataLog("    parsing ", currentCodeOrigin(), "\n");
2362         
2363         if (m_graph.compilation()) {
2364             addToGraph(CountExecution, OpInfo(m_graph.compilation()->executionCounterFor(
2365                 Profiler::OriginStack(*m_vm->m_perBytecodeProfiler, m_codeBlock, currentCodeOrigin()))));
2366         }
2367         
2368         switch (opcodeID) {
2369
2370         // === Function entry opcodes ===
2371
2372         case op_enter: {
2373             Node* undefined = addToGraph(JSConstant, OpInfo(m_constantUndefined));
2374             // Initialize all locals to undefined.
2375             for (int i = 0; i < m_inlineStackTop->m_codeBlock->m_numVars; ++i)
2376                 set(virtualRegisterForLocal(i), undefined, ImmediateNakedSet);
2377             if (m_inlineStackTop->m_codeBlock->specializationKind() == CodeForConstruct)
2378                 set(virtualRegisterForArgument(0), undefined, ImmediateNakedSet);
2379             NEXT_OPCODE(op_enter);
2380         }
2381             
2382         case op_touch_entry:
2383             if (m_inlineStackTop->m_codeBlock->symbolTable()->m_functionEnteredOnce.isStillValid())
2384                 addToGraph(ForceOSRExit);
2385             NEXT_OPCODE(op_touch_entry);
2386             
2387         case op_to_this: {
2388             Node* op1 = getThis();
2389             if (op1->op() != ToThis) {
2390                 Structure* cachedStructure = currentInstruction[2].u.structure.get();
2391                 if (currentInstruction[2].u.toThisStatus != ToThisOK
2392                     || !cachedStructure
2393                     || cachedStructure->classInfo()->methodTable.toThis != JSObject::info()->methodTable.toThis
2394                     || m_inlineStackTop->m_profiledBlock->couldTakeSlowCase(m_currentIndex)
2395                     || m_inlineStackTop->m_exitProfile.hasExitSite(m_currentIndex, BadCache)
2396                     || (op1->op() == GetLocal && op1->variableAccessData()->structureCheckHoistingFailed())) {
2397                     setThis(addToGraph(ToThis, op1));
2398                 } else {
2399                     addToGraph(
2400                         CheckStructure,
2401                         OpInfo(m_graph.addStructureSet(cachedStructure)),
2402                         op1);
2403                 }
2404             }
2405             NEXT_OPCODE(op_to_this);
2406         }
2407
2408         case op_create_this: {
2409             int calleeOperand = currentInstruction[2].u.operand;
2410             Node* callee = get(VirtualRegister(calleeOperand));
2411             bool alreadyEmitted = false;
2412             if (JSFunction* function = callee->dynamicCastConstant<JSFunction*>()) {
2413                 if (Structure* structure = function->allocationStructure()) {
2414                     addToGraph(AllocationProfileWatchpoint, OpInfo(m_graph.freeze(function)));
2415                     // The callee is still live up to this point.
2416                     addToGraph(Phantom, callee);
2417                     set(VirtualRegister(currentInstruction[1].u.operand), addToGraph(NewObject, OpInfo(structure)));
2418                     alreadyEmitted = true;
2419                 }
2420             }
2421             if (!alreadyEmitted) {
2422                 set(VirtualRegister(currentInstruction[1].u.operand),
2423                     addToGraph(CreateThis, OpInfo(currentInstruction[3].u.operand), callee));
2424             }
2425             NEXT_OPCODE(op_create_this);
2426         }
2427
2428         case op_new_object: {
2429             set(VirtualRegister(currentInstruction[1].u.operand),
2430                 addToGraph(NewObject,
2431                     OpInfo(currentInstruction[3].u.objectAllocationProfile->structure())));
2432             NEXT_OPCODE(op_new_object);
2433         }
2434             
2435         case op_new_array: {
2436             int startOperand = currentInstruction[2].u.operand;
2437             int numOperands = currentInstruction[3].u.operand;
2438             ArrayAllocationProfile* profile = currentInstruction[4].u.arrayAllocationProfile;
2439             for (int operandIdx = startOperand; operandIdx > startOperand - numOperands; --operandIdx)
2440                 addVarArgChild(get(VirtualRegister(operandIdx)));
2441             set(VirtualRegister(currentInstruction[1].u.operand), addToGraph(Node::VarArg, NewArray, OpInfo(profile->selectIndexingType()), OpInfo(0)));
2442             NEXT_OPCODE(op_new_array);
2443         }
2444             
2445         case op_new_array_with_size: {
2446             int lengthOperand = currentInstruction[2].u.operand;
2447             ArrayAllocationProfile* profile = currentInstruction[3].u.arrayAllocationProfile;
2448             set(VirtualRegister(currentInstruction[1].u.operand), addToGraph(NewArrayWithSize, OpInfo(profile->selectIndexingType()), get(VirtualRegister(lengthOperand))));
2449             NEXT_OPCODE(op_new_array_with_size);
2450         }
2451             
2452         case op_new_array_buffer: {
2453             int startConstant = currentInstruction[2].u.operand;
2454             int numConstants = currentInstruction[3].u.operand;
2455             ArrayAllocationProfile* profile = currentInstruction[4].u.arrayAllocationProfile;
2456             NewArrayBufferData data;
2457             data.startConstant = m_inlineStackTop->m_constantBufferRemap[startConstant];
2458             data.numConstants = numConstants;
2459             data.indexingType = profile->selectIndexingType();
2460
2461             // If this statement has never executed, we'll have the wrong indexing type in the profile.
2462             for (int i = 0; i < numConstants; ++i) {
2463                 data.indexingType =
2464                     leastUpperBoundOfIndexingTypeAndValue(
2465                         data.indexingType,
2466                         m_codeBlock->constantBuffer(data.startConstant)[i]);
2467             }
2468             
2469             m_graph.m_newArrayBufferData.append(data);
2470             set(VirtualRegister(currentInstruction[1].u.operand), addToGraph(NewArrayBuffer, OpInfo(&m_graph.m_newArrayBufferData.last())));
2471             NEXT_OPCODE(op_new_array_buffer);
2472         }
2473             
2474         case op_new_regexp: {
2475             set(VirtualRegister(currentInstruction[1].u.operand), addToGraph(NewRegexp, OpInfo(currentInstruction[2].u.operand)));
2476             NEXT_OPCODE(op_new_regexp);
2477         }
2478             
2479         case op_get_callee: {
2480             JSCell* cachedFunction = currentInstruction[2].u.jsCell.get();
2481             if (!cachedFunction 
2482                 || m_inlineStackTop->m_profiledBlock->couldTakeSlowCase(m_currentIndex)
2483                 || m_inlineStackTop->m_exitProfile.hasExitSite(m_currentIndex, BadCell)) {
2484                 set(VirtualRegister(currentInstruction[1].u.operand), get(VirtualRegister(JSStack::Callee)));
2485             } else {
2486                 FrozenValue* frozen = m_graph.freeze(cachedFunction);
2487                 ASSERT(cachedFunction->inherits(JSFunction::info()));
2488                 Node* actualCallee = get(VirtualRegister(JSStack::Callee));
2489                 addToGraph(CheckCell, OpInfo(frozen), actualCallee);
2490                 set(VirtualRegister(currentInstruction[1].u.operand), addToGraph(JSConstant, OpInfo(frozen)));
2491             }
2492             NEXT_OPCODE(op_get_callee);
2493         }
2494
2495         // === Bitwise operations ===
2496
2497         case op_bitand: {
2498             Node* op1 = get(VirtualRegister(currentInstruction[2].u.operand));
2499             Node* op2 = get(VirtualRegister(currentInstruction[3].u.operand));
2500             set(VirtualRegister(currentInstruction[1].u.operand), addToGraph(BitAnd, op1, op2));
2501             NEXT_OPCODE(op_bitand);
2502         }
2503
2504         case op_bitor: {
2505             Node* op1 = get(VirtualRegister(currentInstruction[2].u.operand));
2506             Node* op2 = get(VirtualRegister(currentInstruction[3].u.operand));
2507             set(VirtualRegister(currentInstruction[1].u.operand), addToGraph(BitOr, op1, op2));
2508             NEXT_OPCODE(op_bitor);
2509         }
2510
2511         case op_bitxor: {
2512             Node* op1 = get(VirtualRegister(currentInstruction[2].u.operand));
2513             Node* op2 = get(VirtualRegister(currentInstruction[3].u.operand));
2514             set(VirtualRegister(currentInstruction[1].u.operand), addToGraph(BitXor, op1, op2));
2515             NEXT_OPCODE(op_bitxor);
2516         }
2517
2518         case op_rshift: {
2519             Node* op1 = get(VirtualRegister(currentInstruction[2].u.operand));
2520             Node* op2 = get(VirtualRegister(currentInstruction[3].u.operand));
2521             set(VirtualRegister(currentInstruction[1].u.operand),
2522                 addToGraph(BitRShift, op1, op2));
2523             NEXT_OPCODE(op_rshift);
2524         }
2525
2526         case op_lshift: {
2527             Node* op1 = get(VirtualRegister(currentInstruction[2].u.operand));
2528             Node* op2 = get(VirtualRegister(currentInstruction[3].u.operand));
2529             set(VirtualRegister(currentInstruction[1].u.operand),
2530                 addToGraph(BitLShift, op1, op2));
2531             NEXT_OPCODE(op_lshift);
2532         }
2533
2534         case op_urshift: {
2535             Node* op1 = get(VirtualRegister(currentInstruction[2].u.operand));
2536             Node* op2 = get(VirtualRegister(currentInstruction[3].u.operand));
2537             set(VirtualRegister(currentInstruction[1].u.operand),
2538                 addToGraph(BitURShift, op1, op2));
2539             NEXT_OPCODE(op_urshift);
2540         }
2541             
2542         case op_unsigned: {
2543             set(VirtualRegister(currentInstruction[1].u.operand),
2544                 makeSafe(addToGraph(UInt32ToNumber, get(VirtualRegister(currentInstruction[2].u.operand)))));
2545             NEXT_OPCODE(op_unsigned);
2546         }
2547
2548         // === Increment/Decrement opcodes ===
2549
2550         case op_inc: {
2551             int srcDst = currentInstruction[1].u.operand;
2552             VirtualRegister srcDstVirtualRegister = VirtualRegister(srcDst);
2553             Node* op = get(srcDstVirtualRegister);
2554             set(srcDstVirtualRegister, makeSafe(addToGraph(ArithAdd, op, addToGraph(JSConstant, OpInfo(m_constantOne)))));
2555             NEXT_OPCODE(op_inc);
2556         }
2557
2558         case op_dec: {
2559             int srcDst = currentInstruction[1].u.operand;
2560             VirtualRegister srcDstVirtualRegister = VirtualRegister(srcDst);
2561             Node* op = get(srcDstVirtualRegister);
2562             set(srcDstVirtualRegister, makeSafe(addToGraph(ArithSub, op, addToGraph(JSConstant, OpInfo(m_constantOne)))));
2563             NEXT_OPCODE(op_dec);
2564         }
2565
2566         // === Arithmetic operations ===
2567
2568         case op_add: {
2569             Node* op1 = get(VirtualRegister(currentInstruction[2].u.operand));
2570             Node* op2 = get(VirtualRegister(currentInstruction[3].u.operand));
2571             if (op1->hasNumberResult() && op2->hasNumberResult())
2572                 set(VirtualRegister(currentInstruction[1].u.operand), makeSafe(addToGraph(ArithAdd, op1, op2)));
2573             else
2574                 set(VirtualRegister(currentInstruction[1].u.operand), makeSafe(addToGraph(ValueAdd, op1, op2)));
2575             NEXT_OPCODE(op_add);
2576         }
2577
2578         case op_sub: {
2579             Node* op1 = get(VirtualRegister(currentInstruction[2].u.operand));
2580             Node* op2 = get(VirtualRegister(currentInstruction[3].u.operand));
2581             set(VirtualRegister(currentInstruction[1].u.operand), makeSafe(addToGraph(ArithSub, op1, op2)));
2582             NEXT_OPCODE(op_sub);
2583         }
2584
2585         case op_negate: {
2586             Node* op1 = get(VirtualRegister(currentInstruction[2].u.operand));
2587             set(VirtualRegister(currentInstruction[1].u.operand), makeSafe(addToGraph(ArithNegate, op1)));
2588             NEXT_OPCODE(op_negate);
2589         }
2590
2591         case op_mul: {
2592             // Multiply requires that the inputs are not truncated, unfortunately.
2593             Node* op1 = get(VirtualRegister(currentInstruction[2].u.operand));
2594             Node* op2 = get(VirtualRegister(currentInstruction[3].u.operand));
2595             set(VirtualRegister(currentInstruction[1].u.operand), makeSafe(addToGraph(ArithMul, op1, op2)));
2596             NEXT_OPCODE(op_mul);
2597         }
2598
2599         case op_mod: {
2600             Node* op1 = get(VirtualRegister(currentInstruction[2].u.operand));
2601             Node* op2 = get(VirtualRegister(currentInstruction[3].u.operand));
2602             set(VirtualRegister(currentInstruction[1].u.operand), makeSafe(addToGraph(ArithMod, op1, op2)));
2603             NEXT_OPCODE(op_mod);
2604         }
2605
2606         case op_div: {
2607             Node* op1 = get(VirtualRegister(currentInstruction[2].u.operand));
2608             Node* op2 = get(VirtualRegister(currentInstruction[3].u.operand));
2609             set(VirtualRegister(currentInstruction[1].u.operand), makeDivSafe(addToGraph(ArithDiv, op1, op2)));
2610             NEXT_OPCODE(op_div);
2611         }
2612
2613         // === Misc operations ===
2614
2615         case op_debug:
2616             addToGraph(Breakpoint);
2617             NEXT_OPCODE(op_debug);
2618
2619         case op_profile_will_call: {
2620             addToGraph(ProfileWillCall);
2621             NEXT_OPCODE(op_profile_will_call);
2622         }
2623
2624         case op_profile_did_call: {
2625             addToGraph(ProfileDidCall);
2626             NEXT_OPCODE(op_profile_did_call);
2627         }
2628
2629         case op_mov: {
2630             Node* op = get(VirtualRegister(currentInstruction[2].u.operand));
2631             set(VirtualRegister(currentInstruction[1].u.operand), op);
2632             NEXT_OPCODE(op_mov);
2633         }
2634             
2635         case op_captured_mov: {
2636             Node* op = get(VirtualRegister(currentInstruction[2].u.operand));
2637             if (VariableWatchpointSet* set = currentInstruction[3].u.watchpointSet) {
2638                 if (set->state() != IsInvalidated)
2639                     addToGraph(NotifyWrite, OpInfo(set), op);
2640             }
2641             set(VirtualRegister(currentInstruction[1].u.operand), op);
2642             NEXT_OPCODE(op_captured_mov);
2643         }
2644
2645         case op_check_has_instance:
2646             addToGraph(CheckHasInstance, get(VirtualRegister(currentInstruction[3].u.operand)));
2647             NEXT_OPCODE(op_check_has_instance);
2648
2649         case op_instanceof: {
2650             Node* value = get(VirtualRegister(currentInstruction[2].u.operand));
2651             Node* prototype = get(VirtualRegister(currentInstruction[3].u.operand));
2652             set(VirtualRegister(currentInstruction[1].u.operand), addToGraph(InstanceOf, value, prototype));
2653             NEXT_OPCODE(op_instanceof);
2654         }
2655             
2656         case op_is_undefined: {
2657             Node* value = get(VirtualRegister(currentInstruction[2].u.operand));
2658             set(VirtualRegister(currentInstruction[1].u.operand), addToGraph(IsUndefined, value));
2659             NEXT_OPCODE(op_is_undefined);
2660         }
2661
2662         case op_is_boolean: {
2663             Node* value = get(VirtualRegister(currentInstruction[2].u.operand));
2664             set(VirtualRegister(currentInstruction[1].u.operand), addToGraph(IsBoolean, value));
2665             NEXT_OPCODE(op_is_boolean);
2666         }
2667
2668         case op_is_number: {
2669             Node* value = get(VirtualRegister(currentInstruction[2].u.operand));
2670             set(VirtualRegister(currentInstruction[1].u.operand), addToGraph(IsNumber, value));
2671             NEXT_OPCODE(op_is_number);
2672         }
2673
2674         case op_is_string: {
2675             Node* value = get(VirtualRegister(currentInstruction[2].u.operand));
2676             set(VirtualRegister(currentInstruction[1].u.operand), addToGraph(IsString, value));
2677             NEXT_OPCODE(op_is_string);
2678         }
2679
2680         case op_is_object: {
2681             Node* value = get(VirtualRegister(currentInstruction[2].u.operand));
2682             set(VirtualRegister(currentInstruction[1].u.operand), addToGraph(IsObject, value));
2683             NEXT_OPCODE(op_is_object);
2684         }
2685
2686         case op_is_function: {
2687             Node* value = get(VirtualRegister(currentInstruction[2].u.operand));
2688             set(VirtualRegister(currentInstruction[1].u.operand), addToGraph(IsFunction, value));
2689             NEXT_OPCODE(op_is_function);
2690         }
2691
2692         case op_not: {
2693             Node* value = get(VirtualRegister(currentInstruction[2].u.operand));
2694             set(VirtualRegister(currentInstruction[1].u.operand), addToGraph(LogicalNot, value));
2695             NEXT_OPCODE(op_not);
2696         }
2697             
2698         case op_to_primitive: {
2699             Node* value = get(VirtualRegister(currentInstruction[2].u.operand));
2700             set(VirtualRegister(currentInstruction[1].u.operand), addToGraph(ToPrimitive, value));
2701             NEXT_OPCODE(op_to_primitive);
2702         }
2703             
2704         case op_strcat: {
2705             int startOperand = currentInstruction[2].u.operand;
2706             int numOperands = currentInstruction[3].u.operand;
2707 #if CPU(X86)
2708             // X86 doesn't have enough registers to compile MakeRope with three arguments.
2709             // Rather than try to be clever, we just make MakeRope dumber on this processor.
2710             const unsigned maxRopeArguments = 2;
2711 #else
2712             const unsigned maxRopeArguments = 3;
2713 #endif
2714             auto toStringNodes = std::make_unique<Node*[]>(numOperands);
2715             for (int i = 0; i < numOperands; i++)
2716                 toStringNodes[i] = addToGraph(ToString, get(VirtualRegister(startOperand - i)));
2717
2718             for (int i = 0; i < numOperands; i++)
2719                 addToGraph(Phantom, toStringNodes[i]);
2720
2721             Node* operands[AdjacencyList::Size];
2722             unsigned indexInOperands = 0;
2723             for (unsigned i = 0; i < AdjacencyList::Size; ++i)
2724                 operands[i] = 0;
2725             for (int operandIdx = 0; operandIdx < numOperands; ++operandIdx) {
2726                 if (indexInOperands == maxRopeArguments) {
2727                     operands[0] = addToGraph(MakeRope, operands[0], operands[1], operands[2]);
2728                     for (unsigned i = 1; i < AdjacencyList::Size; ++i)
2729                         operands[i] = 0;
2730                     indexInOperands = 1;
2731                 }
2732                 
2733                 ASSERT(indexInOperands < AdjacencyList::Size);
2734                 ASSERT(indexInOperands < maxRopeArguments);
2735                 operands[indexInOperands++] = toStringNodes[operandIdx];
2736             }
2737             set(VirtualRegister(currentInstruction[1].u.operand),
2738                 addToGraph(MakeRope, operands[0], operands[1], operands[2]));
2739             NEXT_OPCODE(op_strcat);
2740         }
2741
2742         case op_less: {
2743             Node* op1 = get(VirtualRegister(currentInstruction[2].u.operand));
2744             Node* op2 = get(VirtualRegister(currentInstruction[3].u.operand));
2745             set(VirtualRegister(currentInstruction[1].u.operand), addToGraph(CompareLess, op1, op2));
2746             NEXT_OPCODE(op_less);
2747         }
2748
2749         case op_lesseq: {
2750             Node* op1 = get(VirtualRegister(currentInstruction[2].u.operand));
2751             Node* op2 = get(VirtualRegister(currentInstruction[3].u.operand));
2752             set(VirtualRegister(currentInstruction[1].u.operand), addToGraph(CompareLessEq, op1, op2));
2753             NEXT_OPCODE(op_lesseq);
2754         }
2755
2756         case op_greater: {
2757             Node* op1 = get(VirtualRegister(currentInstruction[2].u.operand));
2758             Node* op2 = get(VirtualRegister(currentInstruction[3].u.operand));
2759             set(VirtualRegister(currentInstruction[1].u.operand), addToGraph(CompareGreater, op1, op2));
2760             NEXT_OPCODE(op_greater);
2761         }
2762
2763         case op_greatereq: {
2764             Node* op1 = get(VirtualRegister(currentInstruction[2].u.operand));
2765             Node* op2 = get(VirtualRegister(currentInstruction[3].u.operand));
2766             set(VirtualRegister(currentInstruction[1].u.operand), addToGraph(CompareGreaterEq, op1, op2));
2767             NEXT_OPCODE(op_greatereq);
2768         }
2769
2770         case op_eq: {
2771             Node* op1 = get(VirtualRegister(currentInstruction[2].u.operand));
2772             Node* op2 = get(VirtualRegister(currentInstruction[3].u.operand));
2773             set(VirtualRegister(currentInstruction[1].u.operand), addToGraph(CompareEq, op1, op2));
2774             NEXT_OPCODE(op_eq);
2775         }
2776
2777         case op_eq_null: {
2778             Node* value = get(VirtualRegister(currentInstruction[2].u.operand));
2779             set(VirtualRegister(currentInstruction[1].u.operand), addToGraph(CompareEqConstant, value, addToGraph(JSConstant, OpInfo(m_constantNull))));
2780             NEXT_OPCODE(op_eq_null);
2781         }
2782
2783         case op_stricteq: {
2784             Node* op1 = get(VirtualRegister(currentInstruction[2].u.operand));
2785             Node* op2 = get(VirtualRegister(currentInstruction[3].u.operand));
2786             set(VirtualRegister(currentInstruction[1].u.operand), addToGraph(CompareStrictEq, op1, op2));
2787             NEXT_OPCODE(op_stricteq);
2788         }
2789
2790         case op_neq: {
2791             Node* op1 = get(VirtualRegister(currentInstruction[2].u.operand));
2792             Node* op2 = get(VirtualRegister(currentInstruction[3].u.operand));
2793             set(VirtualRegister(currentInstruction[1].u.operand), addToGraph(LogicalNot, addToGraph(CompareEq, op1, op2)));
2794             NEXT_OPCODE(op_neq);
2795         }
2796
2797         case op_neq_null: {
2798             Node* value = get(VirtualRegister(currentInstruction[2].u.operand));
2799             set(VirtualRegister(currentInstruction[1].u.operand), addToGraph(LogicalNot, addToGraph(CompareEqConstant, value, addToGraph(JSConstant, OpInfo(m_constantNull)))));
2800             NEXT_OPCODE(op_neq_null);
2801         }
2802
2803         case op_nstricteq: {
2804             Node* op1 = get(VirtualRegister(currentInstruction[2].u.operand));
2805             Node* op2 = get(VirtualRegister(currentInstruction[3].u.operand));
2806             Node* invertedResult;
2807             invertedResult = addToGraph(CompareStrictEq, op1, op2);
2808             set(VirtualRegister(currentInstruction[1].u.operand), addToGraph(LogicalNot, invertedResult));
2809             NEXT_OPCODE(op_nstricteq);
2810         }
2811
2812         // === Property access operations ===
2813
2814         case op_get_by_val: {
2815             SpeculatedType prediction = getPredictionWithoutOSRExit();
2816             
2817             Node* base = get(VirtualRegister(currentInstruction[2].u.operand));
2818             ArrayMode arrayMode = getArrayModeConsideringSlowPath(currentInstruction[4].u.arrayProfile, Array::Read);
2819             Node* property = get(VirtualRegister(currentInstruction[3].u.operand));
2820             Node* getByVal = addToGraph(GetByVal, OpInfo(arrayMode.asWord()), OpInfo(prediction), base, property);
2821             set(VirtualRegister(currentInstruction[1].u.operand), getByVal);
2822
2823             NEXT_OPCODE(op_get_by_val);
2824         }
2825
2826         case op_put_by_val_direct:
2827         case op_put_by_val: {
2828             Node* base = get(VirtualRegister(currentInstruction[1].u.operand));
2829
2830             ArrayMode arrayMode = getArrayModeConsideringSlowPath(currentInstruction[4].u.arrayProfile, Array::Write);
2831             
2832             Node* property = get(VirtualRegister(currentInstruction[2].u.operand));
2833             Node* value = get(VirtualRegister(currentInstruction[3].u.operand));
2834             
2835             addVarArgChild(base);
2836             addVarArgChild(property);
2837             addVarArgChild(value);
2838             addVarArgChild(0); // Leave room for property storage.
2839             addVarArgChild(0); // Leave room for length.
2840             addToGraph(Node::VarArg, opcodeID == op_put_by_val_direct ? PutByValDirect : PutByVal, OpInfo(arrayMode.asWord()), OpInfo(0));
2841
2842             NEXT_OPCODE(op_put_by_val);
2843         }
2844             
2845         case op_get_by_id:
2846         case op_get_by_id_out_of_line:
2847         case op_get_array_length: {
2848             SpeculatedType prediction = getPrediction();
2849             
2850             Node* base = get(VirtualRegister(currentInstruction[2].u.operand));
2851             unsigned identifierNumber = m_inlineStackTop->m_identifierRemap[currentInstruction[3].u.operand];
2852             
2853             StringImpl* uid = m_graph.identifiers()[identifierNumber];
2854             GetByIdStatus getByIdStatus = GetByIdStatus::computeFor(
2855                 m_inlineStackTop->m_profiledBlock, m_dfgCodeBlock,
2856                 m_inlineStackTop->m_stubInfos, m_dfgStubInfos,
2857                 currentCodeOrigin(), uid);
2858             
2859             handleGetById(
2860                 currentInstruction[1].u.operand, prediction, base, identifierNumber, getByIdStatus);
2861
2862             NEXT_OPCODE(op_get_by_id);
2863         }
2864         case op_put_by_id:
2865         case op_put_by_id_out_of_line:
2866         case op_put_by_id_transition_direct:
2867         case op_put_by_id_transition_normal:
2868         case op_put_by_id_transition_direct_out_of_line:
2869         case op_put_by_id_transition_normal_out_of_line: {
2870             Node* value = get(VirtualRegister(currentInstruction[3].u.operand));
2871             Node* base = get(VirtualRegister(currentInstruction[1].u.operand));
2872             unsigned identifierNumber = m_inlineStackTop->m_identifierRemap[currentInstruction[2].u.operand];
2873             bool direct = currentInstruction[8].u.operand;
2874
2875             PutByIdStatus putByIdStatus = PutByIdStatus::computeFor(
2876                 m_inlineStackTop->m_profiledBlock, m_dfgCodeBlock,
2877                 m_inlineStackTop->m_stubInfos, m_dfgStubInfos,
2878                 currentCodeOrigin(), m_graph.identifiers()[identifierNumber]);
2879             
2880             handlePutById(base, identifierNumber, value, putByIdStatus, direct);
2881             NEXT_OPCODE(op_put_by_id);
2882         }
2883
2884         case op_init_global_const_nop: {
2885             NEXT_OPCODE(op_init_global_const_nop);
2886         }
2887
2888         case op_init_global_const: {
2889             Node* value = get(VirtualRegister(currentInstruction[2].u.operand));
2890             addToGraph(
2891                 PutGlobalVar,
2892                 OpInfo(m_inlineStackTop->m_codeBlock->globalObject()->assertRegisterIsInThisObject(currentInstruction[1].u.registerPointer)),
2893                 value);
2894             NEXT_OPCODE(op_init_global_const);
2895         }
2896
2897         // === Block terminators. ===
2898
2899         case op_jmp: {
2900             int relativeOffset = currentInstruction[1].u.operand;
2901             if (relativeOffset <= 0)
2902                 flushForTerminal();
2903             addToGraph(Jump, OpInfo(m_currentIndex + relativeOffset));
2904             LAST_OPCODE(op_jmp);
2905         }
2906
2907         case op_jtrue: {
2908             unsigned relativeOffset = currentInstruction[2].u.operand;
2909             Node* condition = get(VirtualRegister(currentInstruction[1].u.operand));
2910             addToGraph(Branch, OpInfo(branchData(m_currentIndex + relativeOffset, m_currentIndex + OPCODE_LENGTH(op_jtrue))), condition);
2911             LAST_OPCODE(op_jtrue);
2912         }
2913
2914         case op_jfalse: {
2915             unsigned relativeOffset = currentInstruction[2].u.operand;
2916             Node* condition = get(VirtualRegister(currentInstruction[1].u.operand));
2917             addToGraph(Branch, OpInfo(branchData(m_currentIndex + OPCODE_LENGTH(op_jfalse), m_currentIndex + relativeOffset)), condition);
2918             LAST_OPCODE(op_jfalse);
2919         }
2920
2921         case op_jeq_null: {
2922             unsigned relativeOffset = currentInstruction[2].u.operand;
2923             Node* value = get(VirtualRegister(currentInstruction[1].u.operand));
2924             Node* condition = addToGraph(CompareEqConstant, value, addToGraph(JSConstant, OpInfo(m_constantNull)));
2925             addToGraph(Branch, OpInfo(branchData(m_currentIndex + relativeOffset, m_currentIndex + OPCODE_LENGTH(op_jeq_null))), condition);
2926             LAST_OPCODE(op_jeq_null);
2927         }
2928
2929         case op_jneq_null: {
2930             unsigned relativeOffset = currentInstruction[2].u.operand;
2931             Node* value = get(VirtualRegister(currentInstruction[1].u.operand));
2932             Node* condition = addToGraph(CompareEqConstant, value, addToGraph(JSConstant, OpInfo(m_constantNull)));
2933             addToGraph(Branch, OpInfo(branchData(m_currentIndex + OPCODE_LENGTH(op_jneq_null), m_currentIndex + relativeOffset)), condition);
2934             LAST_OPCODE(op_jneq_null);
2935         }
2936
2937         case op_jless: {
2938             unsigned relativeOffset = currentInstruction[3].u.operand;
2939             Node* op1 = get(VirtualRegister(currentInstruction[1].u.operand));
2940             Node* op2 = get(VirtualRegister(currentInstruction[2].u.operand));
2941             Node* condition = addToGraph(CompareLess, op1, op2);
2942             addToGraph(Branch, OpInfo(branchData(m_currentIndex + relativeOffset, m_currentIndex + OPCODE_LENGTH(op_jless))), condition);
2943             LAST_OPCODE(op_jless);
2944         }
2945
2946         case op_jlesseq: {
2947             unsigned relativeOffset = currentInstruction[3].u.operand;
2948             Node* op1 = get(VirtualRegister(currentInstruction[1].u.operand));
2949             Node* op2 = get(VirtualRegister(currentInstruction[2].u.operand));
2950             Node* condition = addToGraph(CompareLessEq, op1, op2);
2951             addToGraph(Branch, OpInfo(branchData(m_currentIndex + relativeOffset, m_currentIndex + OPCODE_LENGTH(op_jlesseq))), condition);
2952             LAST_OPCODE(op_jlesseq);
2953         }
2954
2955         case op_jgreater: {
2956             unsigned relativeOffset = currentInstruction[3].u.operand;
2957             Node* op1 = get(VirtualRegister(currentInstruction[1].u.operand));
2958             Node* op2 = get(VirtualRegister(currentInstruction[2].u.operand));
2959             Node* condition = addToGraph(CompareGreater, op1, op2);
2960             addToGraph(Branch, OpInfo(branchData(m_currentIndex + relativeOffset, m_currentIndex + OPCODE_LENGTH(op_jgreater))), condition);
2961             LAST_OPCODE(op_jgreater);
2962         }
2963
2964         case op_jgreatereq: {
2965             unsigned relativeOffset = currentInstruction[3].u.operand;
2966             Node* op1 = get(VirtualRegister(currentInstruction[1].u.operand));
2967             Node* op2 = get(VirtualRegister(currentInstruction[2].u.operand));
2968             Node* condition = addToGraph(CompareGreaterEq, op1, op2);
2969             addToGraph(Branch, OpInfo(branchData(m_currentIndex + relativeOffset, m_currentIndex + OPCODE_LENGTH(op_jgreatereq))), condition);
2970             LAST_OPCODE(op_jgreatereq);
2971         }
2972
2973         case op_jnless: {
2974             unsigned relativeOffset = currentInstruction[3].u.operand;
2975             Node* op1 = get(VirtualRegister(currentInstruction[1].u.operand));
2976             Node* op2 = get(VirtualRegister(currentInstruction[2].u.operand));
2977             Node* condition = addToGraph(CompareLess, op1, op2);
2978             addToGraph(Branch, OpInfo(branchData(m_currentIndex + OPCODE_LENGTH(op_jnless), m_currentIndex + relativeOffset)), condition);
2979             LAST_OPCODE(op_jnless);
2980         }
2981
2982         case op_jnlesseq: {
2983             unsigned relativeOffset = currentInstruction[3].u.operand;
2984             Node* op1 = get(VirtualRegister(currentInstruction[1].u.operand));
2985             Node* op2 = get(VirtualRegister(currentInstruction[2].u.operand));
2986             Node* condition = addToGraph(CompareLessEq, op1, op2);
2987             addToGraph(Branch, OpInfo(branchData(m_currentIndex + OPCODE_LENGTH(op_jnlesseq), m_currentIndex + relativeOffset)), condition);
2988             LAST_OPCODE(op_jnlesseq);
2989         }
2990
2991         case op_jngreater: {
2992             unsigned relativeOffset = currentInstruction[3].u.operand;
2993             Node* op1 = get(VirtualRegister(currentInstruction[1].u.operand));
2994             Node* op2 = get(VirtualRegister(currentInstruction[2].u.operand));
2995             Node* condition = addToGraph(CompareGreater, op1, op2);
2996             addToGraph(Branch, OpInfo(branchData(m_currentIndex + OPCODE_LENGTH(op_jngreater), m_currentIndex + relativeOffset)), condition);
2997             LAST_OPCODE(op_jngreater);
2998         }
2999
3000         case op_jngreatereq: {
3001             unsigned relativeOffset = currentInstruction[3].u.operand;
3002             Node* op1 = get(VirtualRegister(currentInstruction[1].u.operand));
3003             Node* op2 = get(VirtualRegister(currentInstruction[2].u.operand));
3004             Node* condition = addToGraph(CompareGreaterEq, op1, op2);
3005             addToGraph(Branch, OpInfo(branchData(m_currentIndex + OPCODE_LENGTH(op_jngreatereq), m_currentIndex + relativeOffset)), condition);
3006             LAST_OPCODE(op_jngreatereq);
3007         }
3008             
3009         case op_switch_imm: {
3010             SwitchData& data = *m_graph.m_switchData.add();
3011             data.kind = SwitchImm;
3012             data.switchTableIndex = m_inlineStackTop->m_switchRemap[currentInstruction[1].u.operand];
3013             data.fallThrough.setBytecodeIndex(m_currentIndex + currentInstruction[2].u.operand);
3014             SimpleJumpTable& table = m_codeBlock->switchJumpTable(data.switchTableIndex);
3015             for (unsigned i = 0; i < table.branchOffsets.size(); ++i) {
3016                 if (!table.branchOffsets[i])
3017                     continue;
3018                 unsigned target = m_currentIndex + table.branchOffsets[i];
3019                 if (target == data.fallThrough.bytecodeIndex())
3020                     continue;
3021                 data.cases.append(SwitchCase::withBytecodeIndex(m_graph.freeze(jsNumber(static_cast<int32_t>(table.min + i))), target));
3022             }
3023             flushIfTerminal(data);
3024             addToGraph(Switch, OpInfo(&data), get(VirtualRegister(currentInstruction[3].u.operand)));
3025             LAST_OPCODE(op_switch_imm);
3026         }
3027             
3028         case op_switch_char: {
3029             SwitchData& data = *m_graph.m_switchData.add();
3030             data.kind = SwitchChar;
3031             data.switchTableIndex = m_inlineStackTop->m_switchRemap[currentInstruction[1].u.operand];
3032             data.fallThrough.setBytecodeIndex(m_currentIndex + currentInstruction[2].u.operand);
3033             SimpleJumpTable& table = m_codeBlock->switchJumpTable(data.switchTableIndex);
3034             for (unsigned i = 0; i < table.branchOffsets.size(); ++i) {
3035                 if (!table.branchOffsets[i])
3036                     continue;
3037                 unsigned target = m_currentIndex + table.branchOffsets[i];
3038                 if (target == data.fallThrough.bytecodeIndex())
3039                     continue;
3040                 data.cases.append(
3041                     SwitchCase::withBytecodeIndex(LazyJSValue::singleCharacterString(table.min + i), target));
3042             }
3043             flushIfTerminal(data);
3044             addToGraph(Switch, OpInfo(&data), get(VirtualRegister(currentInstruction[3].u.operand)));
3045             LAST_OPCODE(op_switch_char);
3046         }
3047
3048         case op_switch_string: {
3049             SwitchData& data = *m_graph.m_switchData.add();
3050             data.kind = SwitchString;
3051             data.switchTableIndex = currentInstruction[1].u.operand;
3052             data.fallThrough.setBytecodeIndex(m_currentIndex + currentInstruction[2].u.operand);
3053             StringJumpTable& table = m_codeBlock->stringSwitchJumpTable(data.switchTableIndex);
3054             StringJumpTable::StringOffsetTable::iterator iter;
3055             StringJumpTable::StringOffsetTable::iterator end = table.offsetTable.end();
3056             for (iter = table.offsetTable.begin(); iter != end; ++iter) {
3057                 unsigned target = m_currentIndex + iter->value.branchOffset;
3058                 if (target == data.fallThrough.bytecodeIndex())
3059                     continue;
3060                 data.cases.append(
3061                     SwitchCase::withBytecodeIndex(LazyJSValue::knownStringImpl(iter->key.get()), target));
3062             }
3063             flushIfTerminal(data);
3064             addToGraph(Switch, OpInfo(&data), get(VirtualRegister(currentInstruction[3].u.operand)));
3065             LAST_OPCODE(op_switch_string);
3066         }
3067
3068         case op_ret:
3069             flushForReturn();
3070             if (inlineCallFrame()) {
3071                 if (m_inlineStackTop->m_returnValue.isValid())
3072                     setDirect(m_inlineStackTop->m_returnValue, get(VirtualRegister(currentInstruction[1].u.operand)), ImmediateSetWithFlush);
3073                 m_inlineStackTop->m_didReturn = true;
3074                 if (m_inlineStackTop->m_unlinkedBlocks.isEmpty()) {
3075                     // If we're returning from the first block, then we're done parsing.
3076                     ASSERT(m_inlineStackTop->m_callsiteBlockHead == m_graph.lastBlock());
3077                     shouldContinueParsing = false;
3078                     LAST_OPCODE(op_ret);
3079                 } else {
3080                     // If inlining created blocks, and we're doing a return, then we need some
3081                     // special linking.
3082                     ASSERT(m_inlineStackTop->m_unlinkedBlocks.last().m_block == m_graph.lastBlock());
3083                     m_inlineStackTop->m_unlinkedBlocks.last().m_needsNormalLinking = false;
3084                 }
3085                 if (m_currentIndex + OPCODE_LENGTH(op_ret) != m_inlineStackTop->m_codeBlock->instructions().size() || m_inlineStackTop->m_didEarlyReturn) {
3086                     ASSERT(m_currentIndex + OPCODE_LENGTH(op_ret) <= m_inlineStackTop->m_codeBlock->instructions().size());
3087                     addToGraph(Jump, OpInfo(0));
3088                     m_inlineStackTop->m_unlinkedBlocks.last().m_needsEarlyReturnLinking = true;
3089                     m_inlineStackTop->m_didEarlyReturn = true;
3090                 }
3091                 LAST_OPCODE(op_ret);
3092             }
3093             addToGraph(Return, get(VirtualRegister(currentInstruction[1].u.operand)));
3094             LAST_OPCODE(op_ret);
3095             
3096         case op_end:
3097             flushForReturn();
3098             ASSERT(!inlineCallFrame());
3099             addToGraph(Return, get(VirtualRegister(currentInstruction[1].u.operand)));
3100             LAST_OPCODE(op_end);
3101
3102         case op_throw:
3103             addToGraph(Throw, get(VirtualRegister(currentInstruction[1].u.operand)));
3104             flushForTerminal();
3105             addToGraph(Unreachable);
3106             LAST_OPCODE(op_throw);
3107             
3108         case op_throw_static_error:
3109             addToGraph(ThrowReferenceError);
3110             flushForTerminal();
3111             addToGraph(Unreachable);
3112             LAST_OPCODE(op_throw_static_error);
3113             
3114         case op_call:
3115             handleCall(currentInstruction, Call, CodeForCall);
3116             NEXT_OPCODE(op_call);
3117             
3118         case op_construct:
3119             handleCall(currentInstruction, Construct, CodeForConstruct);
3120             NEXT_OPCODE(op_construct);
3121             
3122         case op_call_varargs: {
3123             int result = currentInstruction[1].u.operand;
3124             int callee = currentInstruction[2].u.operand;
3125             int thisReg = currentInstruction[3].u.operand;
3126             int arguments = currentInstruction[4].u.operand;
3127             int firstFreeReg = currentInstruction[5].u.operand;
3128             
3129             ASSERT(inlineCallFrame());
3130             ASSERT_UNUSED(arguments, arguments == m_inlineStackTop->m_codeBlock->argumentsRegister().offset());
3131             ASSERT(!m_inlineStackTop->m_codeBlock->symbolTable()->slowArguments());
3132
3133             addToGraph(CheckArgumentsNotCreated);
3134
3135             unsigned argCount = inlineCallFrame()->arguments.size();
3136             
3137             // Let's compute the register offset. We start with the last used register, and
3138             // then adjust for the things we want in the call frame.
3139             int registerOffset = firstFreeReg + 1;
3140             registerOffset -= argCount; // We will be passing some arguments.
3141             registerOffset -= JSStack::CallFrameHeaderSize; // We will pretend to have a call frame header.
3142             
3143             // Get the alignment right.
3144             registerOffset = -WTF::roundUpToMultipleOf(
3145                 stackAlignmentRegisters(),
3146                 -registerOffset);
3147
3148             ensureLocals(
3149                 m_inlineStackTop->remapOperand(