Use constexpr instead of const in symbol definitions that are obviously constexpr.
[WebKit-https.git] / Source / JavaScriptCore / ftl / FTLLowerDFGToB3.cpp
1 /*
2  * Copyright (C) 2013-2019 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 "FTLLowerDFGToB3.h"
28
29 #if ENABLE(FTL_JIT)
30
31 #include "AirCode.h"
32 #include "AirGenerationContext.h"
33 #include "AllowMacroScratchRegisterUsage.h"
34 #include "AllowMacroScratchRegisterUsageIf.h"
35 #include "AtomicsObject.h"
36 #include "B3CheckValue.h"
37 #include "B3FenceValue.h"
38 #include "B3PatchpointValue.h"
39 #include "B3SlotBaseValue.h"
40 #include "B3StackmapGenerationParams.h"
41 #include "B3ValueInlines.h"
42 #include "CallFrameShuffler.h"
43 #include "CodeBlockWithJITType.h"
44 #include "DFGAbstractInterpreterInlines.h"
45 #include "DFGCapabilities.h"
46 #include "DFGDoesGC.h"
47 #include "DFGDominators.h"
48 #include "DFGInPlaceAbstractState.h"
49 #include "DFGLivenessAnalysisPhase.h"
50 #include "DFGMayExit.h"
51 #include "DFGOSRAvailabilityAnalysisPhase.h"
52 #include "DFGOSRExitFuzz.h"
53 #include "DirectArguments.h"
54 #include "FTLAbstractHeapRepository.h"
55 #include "FTLAvailableRecovery.h"
56 #include "FTLExceptionTarget.h"
57 #include "FTLForOSREntryJITCode.h"
58 #include "FTLFormattedValue.h"
59 #include "FTLLazySlowPathCall.h"
60 #include "FTLLoweredNodeValue.h"
61 #include "FTLOperations.h"
62 #include "FTLOutput.h"
63 #include "FTLPatchpointExceptionHandle.h"
64 #include "FTLSnippetParams.h"
65 #include "FTLThunks.h"
66 #include "FTLWeightedTarget.h"
67 #include "JITAddGenerator.h"
68 #include "JITBitAndGenerator.h"
69 #include "JITBitOrGenerator.h"
70 #include "JITBitXorGenerator.h"
71 #include "JITDivGenerator.h"
72 #include "JITInlineCacheGenerator.h"
73 #include "JITLeftShiftGenerator.h"
74 #include "JITMathIC.h"
75 #include "JITMulGenerator.h"
76 #include "JITRightShiftGenerator.h"
77 #include "JITSubGenerator.h"
78 #include "JSAsyncFunction.h"
79 #include "JSAsyncGeneratorFunction.h"
80 #include "JSCInlines.h"
81 #include "JSGeneratorFunction.h"
82 #include "JSImmutableButterfly.h"
83 #include "JSLexicalEnvironment.h"
84 #include "JSMap.h"
85 #include "OperandsInlines.h"
86 #include "ProbeContext.h"
87 #include "RegExpObject.h"
88 #include "ScopedArguments.h"
89 #include "ScopedArgumentsTable.h"
90 #include "ScratchRegisterAllocator.h"
91 #include "SetupVarargsFrame.h"
92 #include "ShadowChicken.h"
93 #include "StructureStubInfo.h"
94 #include "SuperSampler.h"
95 #include "ThunkGenerators.h"
96 #include "VirtualRegister.h"
97 #include "Watchdog.h"
98 #include <atomic>
99 #include <wtf/Box.h>
100 #include <wtf/Gigacage.h>
101 #include <wtf/RecursableLambda.h>
102 #include <wtf/StdUnorderedSet.h>
103
104 #undef RELEASE_ASSERT
105 #define RELEASE_ASSERT(assertion) do { \
106     if (!(assertion)) { \
107         WTFReportAssertionFailure(__FILE__, __LINE__, WTF_PRETTY_FUNCTION, #assertion); \
108         CRASH(); \
109     } \
110 } while (0)
111
112 namespace JSC { namespace FTL {
113
114 using namespace B3;
115 using namespace DFG;
116
117 namespace {
118
119 std::atomic<int> compileCounter;
120
121 #if !ASSERT_DISABLED
122 NO_RETURN_DUE_TO_CRASH static void ftlUnreachable(
123     CodeBlock* codeBlock, BlockIndex blockIndex, unsigned nodeIndex)
124 {
125     dataLog("Crashing in thought-to-be-unreachable FTL-generated code for ", pointerDump(codeBlock), " at basic block #", blockIndex);
126     if (nodeIndex != UINT_MAX)
127         dataLog(", node @", nodeIndex);
128     dataLog(".\n");
129     CRASH();
130 }
131 #endif
132
133 // Using this instead of typeCheck() helps to reduce the load on B3, by creating
134 // significantly less dead code.
135 #define FTL_TYPE_CHECK_WITH_EXIT_KIND(exitKind, lowValue, highValue, typesPassedThrough, failCondition) do { \
136         FormattedValue _ftc_lowValue = (lowValue);                      \
137         Edge _ftc_highValue = (highValue);                              \
138         SpeculatedType _ftc_typesPassedThrough = (typesPassedThrough);  \
139         if (!m_interpreter.needsTypeCheck(_ftc_highValue, _ftc_typesPassedThrough)) \
140             break;                                                      \
141         typeCheck(_ftc_lowValue, _ftc_highValue, _ftc_typesPassedThrough, (failCondition), exitKind); \
142     } while (false)
143
144 #define FTL_TYPE_CHECK(lowValue, highValue, typesPassedThrough, failCondition) \
145     FTL_TYPE_CHECK_WITH_EXIT_KIND(BadType, lowValue, highValue, typesPassedThrough, failCondition)
146
147 class LowerDFGToB3 {
148     WTF_MAKE_NONCOPYABLE(LowerDFGToB3);
149 public:
150     LowerDFGToB3(State& state)
151         : m_graph(state.graph)
152         , m_ftlState(state)
153         , m_out(state)
154         , m_proc(*state.proc)
155         , m_availabilityCalculator(m_graph)
156         , m_state(state.graph)
157         , m_interpreter(state.graph, m_state)
158         , m_indexMaskingMode(Options::enableSpectreMitigations() ?  IndexMaskingEnabled : IndexMaskingDisabled)
159     {
160         if (Options::validateAbstractInterpreterState()) {
161             performLivenessAnalysis(m_graph);
162
163             // We only use node liveness here, not combined liveness, as we only track
164             // AI state for live nodes.
165             for (DFG::BasicBlock* block : m_graph.blocksInNaturalOrder()) {
166                 NodeSet live;
167
168                 for (NodeFlowProjection node : block->ssa->liveAtTail) {
169                     if (node.kind() == NodeFlowProjection::Primary)
170                         live.addVoid(node.node());
171                 }
172
173                 for (unsigned i = block->size(); i--; ) {
174                     Node* node = block->at(i);
175                     live.remove(node);
176                     m_graph.doToChildren(node, [&] (Edge child) {
177                         live.addVoid(child.node());
178                     });
179                     m_liveInToNode.add(node, live);
180                 }
181             }
182         }
183     }
184     
185     void lower()
186     {
187         State* state = &m_ftlState;
188         
189         CString name;
190         if (verboseCompilationEnabled()) {
191             name = toCString(
192                 "jsBody_", ++compileCounter, "_", codeBlock()->inferredName(),
193                 "_", codeBlock()->hash());
194         } else
195             name = "jsBody";
196
197         {
198             m_proc.setNumEntrypoints(m_graph.m_numberOfEntrypoints);
199             CodeBlock* codeBlock = m_graph.m_codeBlock;
200
201             Ref<B3::Air::PrologueGenerator> catchPrologueGenerator = createSharedTask<B3::Air::PrologueGeneratorFunction>(
202                 [codeBlock] (CCallHelpers& jit, B3::Air::Code& code) {
203                     AllowMacroScratchRegisterUsage allowScratch(jit);
204                     jit.addPtr(CCallHelpers::TrustedImm32(-code.frameSize()), GPRInfo::callFrameRegister, CCallHelpers::stackPointerRegister);
205                     if (Options::zeroStackFrame())
206                         jit.clearStackFrame(GPRInfo::callFrameRegister, CCallHelpers::stackPointerRegister, GPRInfo::regT0, code.frameSize());
207
208                     jit.emitSave(code.calleeSaveRegisterAtOffsetList());
209                     jit.emitPutToCallFrameHeader(codeBlock, CallFrameSlot::codeBlock);
210                 });
211
212             for (unsigned catchEntrypointIndex : m_graph.m_entrypointIndexToCatchBytecodeOffset.keys()) {
213                 RELEASE_ASSERT(catchEntrypointIndex != 0);
214                 m_proc.code().setPrologueForEntrypoint(catchEntrypointIndex, catchPrologueGenerator.copyRef());
215             }
216
217             if (m_graph.m_maxLocalsForCatchOSREntry) {
218                 uint32_t numberOfLiveLocals = std::max(*m_graph.m_maxLocalsForCatchOSREntry, 1u); // Make sure we always allocate a non-null catchOSREntryBuffer.
219                 m_ftlState.jitCode->common.catchOSREntryBuffer = m_graph.m_vm.scratchBufferForSize(sizeof(JSValue) * numberOfLiveLocals);
220             }
221         }
222         
223         m_graph.ensureSSADominators();
224
225         if (verboseCompilationEnabled())
226             dataLog("Function ready, beginning lowering.\n");
227
228         m_out.initialize(m_heaps);
229
230         // We use prologue frequency for all of the initialization code.
231         m_out.setFrequency(1);
232         
233         bool hasMultipleEntrypoints = m_graph.m_numberOfEntrypoints > 1;
234     
235         LBasicBlock prologue = m_out.newBlock();
236         LBasicBlock callEntrypointArgumentSpeculations = hasMultipleEntrypoints ? m_out.newBlock() : nullptr;
237         m_handleExceptions = m_out.newBlock();
238
239         for (BlockIndex blockIndex = 0; blockIndex < m_graph.numBlocks(); ++blockIndex) {
240             m_highBlock = m_graph.block(blockIndex);
241             if (!m_highBlock)
242                 continue;
243             m_out.setFrequency(m_highBlock->executionCount);
244             m_blocks.add(m_highBlock, m_out.newBlock());
245         }
246
247         // Back to prologue frequency for any bocks that get sneakily created in the initialization code.
248         m_out.setFrequency(1);
249         
250         m_out.appendTo(prologue, hasMultipleEntrypoints ? callEntrypointArgumentSpeculations : m_handleExceptions);
251         m_out.initializeConstants(m_proc, prologue);
252         createPhiVariables();
253
254         size_t sizeOfCaptured = sizeof(JSValue) * m_graph.m_nextMachineLocal;
255         B3::SlotBaseValue* capturedBase = m_out.lockedStackSlot(sizeOfCaptured);
256         m_captured = m_out.add(capturedBase, m_out.constIntPtr(sizeOfCaptured));
257         state->capturedValue = capturedBase->slot();
258
259         auto preOrder = m_graph.blocksInPreOrder();
260
261         m_callFrame = m_out.framePointer();
262         m_tagTypeNumber = m_out.constInt64(TagTypeNumber);
263         m_tagMask = m_out.constInt64(TagMask);
264
265         // Make sure that B3 knows that we really care about the mask registers. This forces the
266         // constants to be materialized in registers.
267         m_proc.addFastConstant(m_tagTypeNumber->key());
268         m_proc.addFastConstant(m_tagMask->key());
269         
270         // We don't want the CodeBlock to have a weak pointer to itself because
271         // that would cause it to always get collected.
272         m_out.storePtr(m_out.constIntPtr(bitwise_cast<intptr_t>(codeBlock())), addressFor(CallFrameSlot::codeBlock));
273
274         VM* vm = &this->vm();
275
276         // Stack Overflow Check.
277         unsigned exitFrameSize = m_graph.requiredRegisterCountForExit() * sizeof(Register);
278         MacroAssembler::AbsoluteAddress addressOfStackLimit(vm->addressOfSoftStackLimit());
279         PatchpointValue* stackOverflowHandler = m_out.patchpoint(Void);
280         CallSiteIndex callSiteIndex = callSiteIndexForCodeOrigin(m_ftlState, CodeOrigin(0));
281         stackOverflowHandler->appendSomeRegister(m_callFrame);
282         stackOverflowHandler->clobber(RegisterSet::macroScratchRegisters());
283         stackOverflowHandler->numGPScratchRegisters = 1;
284         stackOverflowHandler->setGenerator(
285             [=] (CCallHelpers& jit, const StackmapGenerationParams& params) {
286                 AllowMacroScratchRegisterUsage allowScratch(jit);
287                 GPRReg fp = params[0].gpr();
288                 GPRReg scratch = params.gpScratch(0);
289
290                 unsigned ftlFrameSize = params.proc().frameSize();
291                 unsigned maxFrameSize = std::max(exitFrameSize, ftlFrameSize);
292
293                 jit.addPtr(MacroAssembler::TrustedImm32(-maxFrameSize), fp, scratch);
294                 MacroAssembler::JumpList stackOverflow;
295                 if (UNLIKELY(maxFrameSize > Options::reservedZoneSize()))
296                     stackOverflow.append(jit.branchPtr(MacroAssembler::Above, scratch, fp));
297                 stackOverflow.append(jit.branchPtr(MacroAssembler::Above, addressOfStackLimit, scratch));
298
299                 params.addLatePath([=] (CCallHelpers& jit) {
300                     AllowMacroScratchRegisterUsage allowScratch(jit);
301
302                     stackOverflow.link(&jit);
303                     
304                     // FIXME: We would not have to do this if the stack check was part of the Air
305                     // prologue. Then, we would know that there is no way for the callee-saves to
306                     // get clobbered.
307                     // https://bugs.webkit.org/show_bug.cgi?id=172456
308                     jit.emitRestore(params.proc().calleeSaveRegisterAtOffsetList());
309                     
310                     jit.store32(
311                         MacroAssembler::TrustedImm32(callSiteIndex.bits()),
312                         CCallHelpers::tagFor(VirtualRegister(CallFrameSlot::argumentCount)));
313                     jit.copyCalleeSavesToEntryFrameCalleeSavesBuffer(vm->topEntryFrame);
314
315                     jit.move(GPRInfo::callFrameRegister, GPRInfo::argumentGPR0);
316                     jit.move(CCallHelpers::TrustedImmPtr(jit.codeBlock()), GPRInfo::argumentGPR1);
317                     CCallHelpers::Call throwCall = jit.call(OperationPtrTag);
318
319                     jit.move(CCallHelpers::TrustedImmPtr(vm), GPRInfo::argumentGPR0);
320                     jit.move(GPRInfo::callFrameRegister, GPRInfo::argumentGPR1);
321                     CCallHelpers::Call lookupExceptionHandlerCall = jit.call(OperationPtrTag);
322                     jit.jumpToExceptionHandler(*vm);
323
324                     jit.addLinkTask(
325                         [=] (LinkBuffer& linkBuffer) {
326                             linkBuffer.link(throwCall, FunctionPtr<OperationPtrTag>(operationThrowStackOverflowError));
327                             linkBuffer.link(lookupExceptionHandlerCall, FunctionPtr<OperationPtrTag>(lookupExceptionHandlerFromCallerFrame));
328                     });
329                 });
330             });
331
332         LBasicBlock firstDFGBasicBlock = lowBlock(m_graph.block(0));
333
334         {
335             if (hasMultipleEntrypoints) {
336                 Vector<LBasicBlock> successors(m_graph.m_numberOfEntrypoints);
337                 successors[0] = callEntrypointArgumentSpeculations;
338                 for (unsigned i = 1; i < m_graph.m_numberOfEntrypoints; ++i) {
339                     // Currently, the only other entrypoint is an op_catch entrypoint.
340                     // We do OSR entry at op_catch, and we prove argument formats before
341                     // jumping to FTL code, so we don't need to check argument types here
342                     // for these entrypoints.
343                     successors[i] = firstDFGBasicBlock;
344                 }
345                 
346                 m_out.entrySwitch(successors);
347                 m_out.appendTo(callEntrypointArgumentSpeculations, m_handleExceptions);
348             }
349
350             m_node = nullptr;
351             m_origin = NodeOrigin(CodeOrigin(0), CodeOrigin(0), true);
352
353             // Check Arguments.
354             availabilityMap().clear();
355             availabilityMap().m_locals = Operands<Availability>(codeBlock()->numParameters(), 0);
356             for (unsigned i = codeBlock()->numParameters(); i--;) {
357                 availabilityMap().m_locals.argument(i) =
358                     Availability(FlushedAt(FlushedJSValue, virtualRegisterForArgument(i)));
359             }
360
361             for (unsigned i = codeBlock()->numParameters(); i--;) {
362                 MethodOfGettingAValueProfile profile(&m_graph.m_profiledBlock->valueProfileForArgument(i));
363                 VirtualRegister operand = virtualRegisterForArgument(i);
364                 LValue jsValue = m_out.load64(addressFor(operand));
365                 
366                 switch (m_graph.m_argumentFormats[0][i]) {
367                 case FlushedInt32:
368                     speculate(BadType, jsValueValue(jsValue), profile, isNotInt32(jsValue));
369                     break;
370                 case FlushedBoolean:
371                     speculate(BadType, jsValueValue(jsValue), profile, isNotBoolean(jsValue));
372                     break;
373                 case FlushedCell:
374                     speculate(BadType, jsValueValue(jsValue), profile, isNotCell(jsValue));
375                     break;
376                 case FlushedJSValue:
377                     break;
378                 default:
379                     DFG_CRASH(m_graph, nullptr, "Bad flush format for argument");
380                     break;
381                 }
382             }
383             m_out.jump(firstDFGBasicBlock);
384         }
385
386
387         m_out.appendTo(m_handleExceptions, firstDFGBasicBlock);
388         Box<CCallHelpers::Label> exceptionHandler = state->exceptionHandler;
389         m_out.patchpoint(Void)->setGenerator(
390             [=] (CCallHelpers& jit, const StackmapGenerationParams&) {
391                 CCallHelpers::Jump jump = jit.jump();
392                 jit.addLinkTask(
393                     [=] (LinkBuffer& linkBuffer) {
394                         linkBuffer.link(jump, linkBuffer.locationOf<ExceptionHandlerPtrTag>(*exceptionHandler));
395                     });
396             });
397         m_out.unreachable();
398
399         for (DFG::BasicBlock* block : preOrder)
400             compileBlock(block);
401
402         // Make sure everything is decorated. This does a bunch of deferred decorating. This has
403         // to happen last because our abstract heaps are generated lazily. They have to be
404         // generated lazily because we have an infinite number of numbered, indexed, and
405         // absolute heaps. We only become aware of the ones we actually mention while lowering.
406         m_heaps.computeRangesAndDecorateInstructions();
407
408         // We create all Phi's up front, but we may then decide not to compile the basic block
409         // that would have contained one of them. So this creates orphans, which triggers B3
410         // validation failures. Calling this fixes the issue.
411         //
412         // Note that you should avoid the temptation to make this call conditional upon
413         // validation being enabled. B3 makes no guarantees of any kind of correctness when
414         // dealing with IR that would have failed validation. For example, it would be valid to
415         // write a B3 phase that so aggressively assumes the lack of orphans that it would crash
416         // if any orphans were around. We might even have such phases already.
417         m_proc.deleteOrphans();
418
419         // We put the blocks into the B3 procedure in a super weird order. Now we reorder them.
420         m_out.applyBlockOrder();
421     }
422
423 private:
424     
425     void createPhiVariables()
426     {
427         for (BlockIndex blockIndex = m_graph.numBlocks(); blockIndex--;) {
428             DFG::BasicBlock* block = m_graph.block(blockIndex);
429             if (!block)
430                 continue;
431             for (unsigned nodeIndex = block->size(); nodeIndex--;) {
432                 Node* node = block->at(nodeIndex);
433                 if (node->op() != DFG::Phi)
434                     continue;
435                 LType type;
436                 switch (node->flags() & NodeResultMask) {
437                 case NodeResultDouble:
438                     type = Double;
439                     break;
440                 case NodeResultInt32:
441                     type = Int32;
442                     break;
443                 case NodeResultInt52:
444                     type = Int64;
445                     break;
446                 case NodeResultBoolean:
447                     type = Int32;
448                     break;
449                 case NodeResultJS:
450                     type = Int64;
451                     break;
452                 default:
453                     DFG_CRASH(m_graph, node, "Bad Phi node result type");
454                     break;
455                 }
456                 m_phis.add(node, m_proc.add<Value>(B3::Phi, type, Origin(node)));
457             }
458         }
459     }
460     
461     void compileBlock(DFG::BasicBlock* block)
462     {
463         if (!block)
464             return;
465         
466         if (verboseCompilationEnabled())
467             dataLog("Compiling block ", *block, "\n");
468         
469         m_highBlock = block;
470         
471         // Make sure that any blocks created while lowering code in the high block have the frequency of
472         // the high block. This is appropriate because B3 doesn't need precise frequencies. It just needs
473         // something roughly approximate for things like register allocation.
474         m_out.setFrequency(m_highBlock->executionCount);
475         
476         LBasicBlock lowBlock = m_blocks.get(m_highBlock);
477         
478         m_nextHighBlock = 0;
479         for (BlockIndex nextBlockIndex = m_highBlock->index + 1; nextBlockIndex < m_graph.numBlocks(); ++nextBlockIndex) {
480             m_nextHighBlock = m_graph.block(nextBlockIndex);
481             if (m_nextHighBlock)
482                 break;
483         }
484         m_nextLowBlock = m_nextHighBlock ? m_blocks.get(m_nextHighBlock) : 0;
485         
486         // All of this effort to find the next block gives us the ability to keep the
487         // generated IR in roughly program order. This ought not affect the performance
488         // of the generated code (since we expect B3 to reorder things) but it will
489         // make IR dumps easier to read.
490         m_out.appendTo(lowBlock, m_nextLowBlock);
491         
492         if (Options::ftlCrashes())
493             m_out.trap();
494         
495         if (!m_highBlock->cfaHasVisited) {
496             if (verboseCompilationEnabled())
497                 dataLog("Bailing because CFA didn't reach.\n");
498             crash(m_highBlock, nullptr);
499             return;
500         }
501
502         m_aiCheckedNodes.clear();
503         
504         m_availabilityCalculator.beginBlock(m_highBlock);
505         
506         m_state.reset();
507         m_state.beginBasicBlock(m_highBlock);
508         
509         for (m_nodeIndex = 0; m_nodeIndex < m_highBlock->size(); ++m_nodeIndex) {
510             if (!compileNode(m_nodeIndex))
511                 break;
512         }
513     }
514
515     void safelyInvalidateAfterTermination()
516     {
517         if (verboseCompilationEnabled())
518             dataLog("Bailing.\n");
519         crash();
520
521         // Invalidate dominated blocks. Under normal circumstances we would expect
522         // them to be invalidated already. But you can have the CFA become more
523         // precise over time because the structures of objects change on the main
524         // thread. Failing to do this would result in weird crashes due to a value
525         // being used but not defined. Race conditions FTW!
526         for (BlockIndex blockIndex = m_graph.numBlocks(); blockIndex--;) {
527             DFG::BasicBlock* target = m_graph.block(blockIndex);
528             if (!target)
529                 continue;
530             if (m_graph.m_ssaDominators->dominates(m_highBlock, target)) {
531                 if (verboseCompilationEnabled())
532                     dataLog("Block ", *target, " will bail also.\n");
533                 target->cfaHasVisited = false;
534             }
535         }
536     }
537
538     void validateAIState(Node* node)
539     {
540         if (!m_graphDump) {
541             StringPrintStream out;
542             m_graph.dump(out);
543             m_graphDump = out.toString();
544         }
545
546         switch (node->op()) {
547         case MovHint:
548         case ZombieHint:
549         case JSConstant:
550         case LazyJSConstant:
551         case DoubleConstant:
552         case Int52Constant:
553         case GetStack:
554         case PutStack:
555         case KillStack:
556         case ExitOK:
557             return;
558         default:
559             break;
560         }
561
562         // Before we execute node.
563         NodeSet& live = m_liveInToNode.find(node)->value;
564         unsigned highParentIndex = node->index();
565         {
566             uint64_t hash = WTF::intHash(highParentIndex);
567             if (hash >= static_cast<uint64_t>((static_cast<double>(std::numeric_limits<unsigned>::max()) + 1) * Options::validateAbstractInterpreterStateProbability()))
568                 return;
569         }
570
571         for (Node* node : live) {
572             if (node->isPhantomAllocation())
573                 continue;
574
575             if (node->op() == CheckInBounds)
576                 continue;
577
578             AbstractValue value = m_interpreter.forNode(node);
579             {
580                 auto iter = m_aiCheckedNodes.find(node);
581                 if (iter != m_aiCheckedNodes.end()) {
582                     AbstractValue checkedValue = iter->value;
583                     if (checkedValue == value) {
584                         if (!(value.m_type & SpecCell))
585                             continue;
586                     }
587                 }
588                 m_aiCheckedNodes.set(node, value);
589             }
590
591             FlushFormat flushFormat;
592             LValue input;
593             if (node->hasJSResult()) {
594                 input = lowJSValue(Edge(node, UntypedUse));
595                 flushFormat = FlushedJSValue;
596             } else if (node->hasDoubleResult()) {
597                 input = lowDouble(Edge(node, DoubleRepUse));
598                 flushFormat = FlushedDouble;
599             } else if (node->hasInt52Result()) {
600                 input = strictInt52ToJSValue(lowStrictInt52(Edge(node, Int52RepUse)));
601                 flushFormat = FlushedInt52;
602             } else
603                 continue;
604
605             unsigned highChildIndex = node->index();
606
607             String graphDump = m_graphDump;
608
609             PatchpointValue* patchpoint = m_out.patchpoint(Void);
610             patchpoint->effects = Effects::none();
611             patchpoint->effects.writesLocalState = true;
612             patchpoint->appendSomeRegister(input);
613             patchpoint->setGenerator([=] (CCallHelpers& jit, const StackmapGenerationParams& params) {
614                 GPRReg reg = InvalidGPRReg;
615                 FPRReg fpReg = InvalidFPRReg;
616                 if (flushFormat == FlushedDouble)
617                     fpReg = params[0].fpr();
618                 else
619                     reg = params[0].gpr();
620                 jit.probe([=] (Probe::Context& context) {
621                     JSValue input;
622                     double doubleInput;
623
624                     auto dumpAndCrash = [&] {
625                         dataLogLn("Validation failed at node: @", highParentIndex);
626                         dataLogLn("Failed validating live value: @", highChildIndex);
627                         dataLogLn();
628                         dataLogLn("Expected AI value = ", value);
629                         if (flushFormat != FlushedDouble)
630                             dataLogLn("Unexpected value = ", input);
631                         else
632                             dataLogLn("Unexpected double value = ", doubleInput);
633                         dataLogLn();
634                         dataLogLn(graphDump);
635                         CRASH();
636                     };
637
638                     if (flushFormat == FlushedDouble) {
639                         doubleInput = context.fpr(fpReg);
640                         SpeculatedType type;
641                         if (!std::isnan(doubleInput))
642                             type = speculationFromValue(jsDoubleNumber(doubleInput));
643                         else if (isImpureNaN(doubleInput))
644                             type = SpecDoubleImpureNaN;
645                         else
646                             type = SpecDoublePureNaN;
647
648                         if (!value.couldBeType(type))
649                             dumpAndCrash();
650                     } else {
651                         input = JSValue::decode(context.gpr(reg)); 
652                         if (flushFormat == FlushedInt52) {
653                             RELEASE_ASSERT(input.isAnyInt());
654                             input = jsDoubleNumber(input.asAnyInt());
655                         }
656                         if (!value.validateOSREntryValue(input, flushFormat))
657                             dumpAndCrash();
658                     }
659
660                 });
661             });
662         }
663     }
664
665     bool compileNode(unsigned nodeIndex)
666     {
667         if (!m_state.isValid()) {
668             safelyInvalidateAfterTermination();
669             return false;
670         }
671         
672         m_node = m_highBlock->at(nodeIndex);
673         m_origin = m_node->origin;
674         m_out.setOrigin(m_node);
675         
676         if (verboseCompilationEnabled())
677             dataLog("Lowering ", m_node, "\n");
678         
679         m_interpreter.startExecuting();
680         m_interpreter.executeKnownEdgeTypes(m_node);
681
682         if (Options::validateAbstractInterpreterState())
683             validateAIState(m_node);
684
685         if (validateDFGDoesGC) {
686             bool expectDoesGC = doesGC(m_graph, m_node);
687             m_out.store(m_out.constBool(expectDoesGC), m_out.absolute(vm().heap.addressOfExpectDoesGC()));
688         }
689
690         switch (m_node->op()) {
691         case DFG::Upsilon:
692             compileUpsilon();
693             break;
694         case DFG::Phi:
695             compilePhi();
696             break;
697         case JSConstant:
698             break;
699         case DoubleConstant:
700             compileDoubleConstant();
701             break;
702         case Int52Constant:
703             compileInt52Constant();
704             break;
705         case LazyJSConstant:
706             compileLazyJSConstant();
707             break;
708         case DoubleRep:
709             compileDoubleRep();
710             break;
711         case DoubleAsInt32:
712             compileDoubleAsInt32();
713             break;
714         case DFG::ValueRep:
715             compileValueRep();
716             break;
717         case Int52Rep:
718             compileInt52Rep();
719             break;
720         case ValueToInt32:
721             compileValueToInt32();
722             break;
723         case BooleanToNumber:
724             compileBooleanToNumber();
725             break;
726         case ExtractOSREntryLocal:
727             compileExtractOSREntryLocal();
728             break;
729         case ExtractCatchLocal:
730             compileExtractCatchLocal();
731             break;
732         case ClearCatchLocals:
733             compileClearCatchLocals();
734             break;
735         case GetStack:
736             compileGetStack();
737             break;
738         case PutStack:
739             compilePutStack();
740             break;
741         case DFG::Check:
742         case CheckVarargs:
743             compileNoOp();
744             break;
745         case ToObject:
746         case CallObjectConstructor:
747             compileToObjectOrCallObjectConstructor();
748             break;
749         case ToThis:
750             compileToThis();
751             break;
752         case ValueNegate:
753             compileValueNegate();
754             break;
755         case ValueAdd:
756             compileValueAdd();
757             break;
758         case ValueSub:
759             compileValueSub();
760             break;
761         case ValueMul:
762             compileValueMul();
763             break;
764         case StrCat:
765             compileStrCat();
766             break;
767         case ArithAdd:
768         case ArithSub:
769             compileArithAddOrSub();
770             break;
771         case ArithClz32:
772             compileArithClz32();
773             break;
774         case ArithMul:
775             compileArithMul();
776             break;
777         case ValueDiv:
778             compileValueDiv();
779             break;
780         case ArithDiv:
781             compileArithDiv();
782             break;
783         case ValueMod:
784             compileValueMod();
785             break;
786         case ArithMod:
787             compileArithMod();
788             break;
789         case ArithMin:
790         case ArithMax:
791             compileArithMinOrMax();
792             break;
793         case ArithAbs:
794             compileArithAbs();
795             break;
796         case ValuePow:
797             compileValuePow();
798             break;
799         case ArithPow:
800             compileArithPow();
801             break;
802         case ArithRandom:
803             compileArithRandom();
804             break;
805         case ArithRound:
806             compileArithRound();
807             break;
808         case ArithFloor:
809             compileArithFloor();
810             break;
811         case ArithCeil:
812             compileArithCeil();
813             break;
814         case ArithTrunc:
815             compileArithTrunc();
816             break;
817         case ArithSqrt:
818             compileArithSqrt();
819             break;
820         case ArithFRound:
821             compileArithFRound();
822             break;
823         case ArithNegate:
824             compileArithNegate();
825             break;
826         case ArithUnary:
827             compileArithUnary();
828             break;
829         case ValueBitNot:
830             compileValueBitNot();
831             break;
832         case ArithBitNot:
833             compileArithBitNot();
834             break;
835         case ValueBitAnd:
836             compileValueBitAnd();
837             break;
838         case ArithBitAnd:
839             compileArithBitAnd();
840             break;
841         case ValueBitOr:
842             compileValueBitOr();
843             break;
844         case ArithBitOr:
845             compileArithBitOr();
846             break;
847         case ArithBitXor:
848             compileArithBitXor();
849             break;
850         case ValueBitXor:
851             compileValueBitXor();
852             break;
853         case BitRShift:
854             compileBitRShift();
855             break;
856         case ArithBitLShift:
857             compileArithBitLShift();
858             break;
859         case ValueBitLShift:
860             compileValueBitLShift();
861             break;
862         case BitURShift:
863             compileBitURShift();
864             break;
865         case UInt32ToNumber:
866             compileUInt32ToNumber();
867             break;
868         case CheckStructure:
869             compileCheckStructure();
870             break;
871         case CheckStructureOrEmpty:
872             compileCheckStructureOrEmpty();
873             break;
874         case CheckCell:
875             compileCheckCell();
876             break;
877         case CheckNotEmpty:
878             compileCheckNotEmpty();
879             break;
880         case AssertNotEmpty:
881             compileAssertNotEmpty();
882             break;
883         case CheckBadCell:
884             compileCheckBadCell();
885             break;
886         case CheckStringIdent:
887             compileCheckStringIdent();
888             break;
889         case GetExecutable:
890             compileGetExecutable();
891             break;
892         case Arrayify:
893         case ArrayifyToStructure:
894             compileArrayify();
895             break;
896         case PutStructure:
897             compilePutStructure();
898             break;
899         case TryGetById:
900             compileGetById(AccessType::TryGet);
901             break;
902         case GetById:
903         case GetByIdFlush:
904             compileGetById(AccessType::Get);
905             break;
906         case GetByIdWithThis:
907             compileGetByIdWithThis();
908             break;
909         case GetByIdDirect:
910         case GetByIdDirectFlush:
911             compileGetById(AccessType::GetDirect);
912             break;
913         case InById:
914             compileInById();
915             break;
916         case InByVal:
917             compileInByVal();
918             break;
919         case HasOwnProperty:
920             compileHasOwnProperty();
921             break;
922         case PutById:
923         case PutByIdDirect:
924         case PutByIdFlush:
925             compilePutById();
926             break;
927         case PutByIdWithThis:
928             compilePutByIdWithThis();
929             break;
930         case PutGetterById:
931         case PutSetterById:
932             compilePutAccessorById();
933             break;
934         case PutGetterSetterById:
935             compilePutGetterSetterById();
936             break;
937         case PutGetterByVal:
938         case PutSetterByVal:
939             compilePutAccessorByVal();
940             break;
941         case DeleteById:
942             compileDeleteById();
943             break;
944         case DeleteByVal:
945             compileDeleteByVal();
946             break;
947         case GetButterfly:
948             compileGetButterfly();
949             break;
950         case ConstantStoragePointer:
951             compileConstantStoragePointer();
952             break;
953         case GetIndexedPropertyStorage:
954             compileGetIndexedPropertyStorage();
955             break;
956         case CheckArray:
957             compileCheckArray();
958             break;
959         case GetArrayLength:
960             compileGetArrayLength();
961             break;
962         case GetVectorLength:
963             compileGetVectorLength();
964             break;
965         case CheckInBounds:
966             compileCheckInBounds();
967             break;
968         case GetByVal:
969             compileGetByVal();
970             break;
971         case GetMyArgumentByVal:
972         case GetMyArgumentByValOutOfBounds:
973             compileGetMyArgumentByVal();
974             break;
975         case GetByValWithThis:
976             compileGetByValWithThis();
977             break;
978         case PutByVal:
979         case PutByValAlias:
980         case PutByValDirect:
981             compilePutByVal();
982             break;
983         case PutByValWithThis:
984             compilePutByValWithThis();
985             break;
986         case AtomicsAdd:
987         case AtomicsAnd:
988         case AtomicsCompareExchange:
989         case AtomicsExchange:
990         case AtomicsLoad:
991         case AtomicsOr:
992         case AtomicsStore:
993         case AtomicsSub:
994         case AtomicsXor:
995             compileAtomicsReadModifyWrite();
996             break;
997         case AtomicsIsLockFree:
998             compileAtomicsIsLockFree();
999             break;
1000         case DefineDataProperty:
1001             compileDefineDataProperty();
1002             break;
1003         case DefineAccessorProperty:
1004             compileDefineAccessorProperty();
1005             break;
1006         case ArrayPush:
1007             compileArrayPush();
1008             break;
1009         case ArrayPop:
1010             compileArrayPop();
1011             break;
1012         case ArraySlice:
1013             compileArraySlice();
1014             break;
1015         case ArrayIndexOf:
1016             compileArrayIndexOf();
1017             break;
1018         case CreateActivation:
1019             compileCreateActivation();
1020             break;
1021         case PushWithScope:
1022             compilePushWithScope();
1023             break;
1024         case NewFunction:
1025         case NewGeneratorFunction:
1026         case NewAsyncGeneratorFunction:
1027         case NewAsyncFunction:
1028             compileNewFunction();
1029             break;
1030         case CreateDirectArguments:
1031             compileCreateDirectArguments();
1032             break;
1033         case CreateScopedArguments:
1034             compileCreateScopedArguments();
1035             break;
1036         case CreateClonedArguments:
1037             compileCreateClonedArguments();
1038             break;
1039         case ObjectCreate:
1040             compileObjectCreate();
1041             break;
1042         case ObjectKeys:
1043             compileObjectKeys();
1044             break;
1045         case NewObject:
1046             compileNewObject();
1047             break;
1048         case NewPromise:
1049             compileNewPromise();
1050             break;
1051         case NewStringObject:
1052             compileNewStringObject();
1053             break;
1054         case NewSymbol:
1055             compileNewSymbol();
1056             break;
1057         case NewArray:
1058             compileNewArray();
1059             break;
1060         case NewArrayWithSpread:
1061             compileNewArrayWithSpread();
1062             break;
1063         case CreateThis:
1064             compileCreateThis();
1065             break;
1066         case CreatePromise:
1067             compileCreatePromise();
1068             break;
1069         case Spread:
1070             compileSpread();
1071             break;
1072         case NewArrayBuffer:
1073             compileNewArrayBuffer();
1074             break;
1075         case NewArrayWithSize:
1076             compileNewArrayWithSize();
1077             break;
1078         case NewTypedArray:
1079             compileNewTypedArray();
1080             break;
1081         case GetTypedArrayByteOffset:
1082             compileGetTypedArrayByteOffset();
1083             break;
1084         case GetPrototypeOf:
1085             compileGetPrototypeOf();
1086             break;
1087         case AllocatePropertyStorage:
1088             compileAllocatePropertyStorage();
1089             break;
1090         case ReallocatePropertyStorage:
1091             compileReallocatePropertyStorage();
1092             break;
1093         case NukeStructureAndSetButterfly:
1094             compileNukeStructureAndSetButterfly();
1095             break;
1096         case ToNumber:
1097             compileToNumber();
1098             break;
1099         case ToString:
1100         case CallStringConstructor:
1101         case StringValueOf:
1102             compileToStringOrCallStringConstructorOrStringValueOf();
1103             break;
1104         case ToPrimitive:
1105             compileToPrimitive();
1106             break;
1107         case MakeRope:
1108             compileMakeRope();
1109             break;
1110         case StringCharAt:
1111             compileStringCharAt();
1112             break;
1113         case StringCharCodeAt:
1114             compileStringCharCodeAt();
1115             break;
1116         case StringCodePointAt:
1117             compileStringCodePointAt();
1118             break;
1119         case StringFromCharCode:
1120             compileStringFromCharCode();
1121             break;
1122         case GetByOffset:
1123         case GetGetterSetterByOffset:
1124             compileGetByOffset();
1125             break;
1126         case GetGetter:
1127             compileGetGetter();
1128             break;
1129         case GetSetter:
1130             compileGetSetter();
1131             break;
1132         case MultiGetByOffset:
1133             compileMultiGetByOffset();
1134             break;
1135         case PutByOffset:
1136             compilePutByOffset();
1137             break;
1138         case MultiPutByOffset:
1139             compileMultiPutByOffset();
1140             break;
1141         case MatchStructure:
1142             compileMatchStructure();
1143             break;
1144         case GetGlobalVar:
1145         case GetGlobalLexicalVariable:
1146             compileGetGlobalVariable();
1147             break;
1148         case PutGlobalVariable:
1149             compilePutGlobalVariable();
1150             break;
1151         case NotifyWrite:
1152             compileNotifyWrite();
1153             break;
1154         case GetCallee:
1155             compileGetCallee();
1156             break;
1157         case SetCallee:
1158             compileSetCallee();
1159             break;
1160         case GetArgumentCountIncludingThis:
1161             compileGetArgumentCountIncludingThis();
1162             break;
1163         case SetArgumentCountIncludingThis:
1164             compileSetArgumentCountIncludingThis();
1165             break;
1166         case GetScope:
1167             compileGetScope();
1168             break;
1169         case SkipScope:
1170             compileSkipScope();
1171             break;
1172         case GetGlobalObject:
1173             compileGetGlobalObject();
1174             break;
1175         case GetGlobalThis:
1176             compileGetGlobalThis();
1177             break;
1178         case GetClosureVar:
1179             compileGetClosureVar();
1180             break;
1181         case PutClosureVar:
1182             compilePutClosureVar();
1183             break;
1184         case GetInternalField:
1185             compileGetInternalField();
1186             break;
1187         case PutInternalField:
1188             compilePutInternalField();
1189             break;
1190         case GetFromArguments:
1191             compileGetFromArguments();
1192             break;
1193         case PutToArguments:
1194             compilePutToArguments();
1195             break;
1196         case GetArgument:
1197             compileGetArgument();
1198             break;
1199         case CompareEq:
1200             compileCompareEq();
1201             break;
1202         case CompareStrictEq:
1203             compileCompareStrictEq();
1204             break;
1205         case CompareLess:
1206             compileCompareLess();
1207             break;
1208         case CompareLessEq:
1209             compileCompareLessEq();
1210             break;
1211         case CompareGreater:
1212             compileCompareGreater();
1213             break;
1214         case CompareGreaterEq:
1215             compileCompareGreaterEq();
1216             break;
1217         case CompareBelow:
1218             compileCompareBelow();
1219             break;
1220         case CompareBelowEq:
1221             compileCompareBelowEq();
1222             break;
1223         case CompareEqPtr:
1224             compileCompareEqPtr();
1225             break;
1226         case SameValue:
1227             compileSameValue();
1228             break;
1229         case LogicalNot:
1230             compileLogicalNot();
1231             break;
1232         case Call:
1233         case TailCallInlinedCaller:
1234         case Construct:
1235             compileCallOrConstruct();
1236             break;
1237         case DirectCall:
1238         case DirectTailCallInlinedCaller:
1239         case DirectConstruct:
1240         case DirectTailCall:
1241             compileDirectCallOrConstruct();
1242             break;
1243         case TailCall:
1244             compileTailCall();
1245             break;
1246         case CallVarargs:
1247         case CallForwardVarargs:
1248         case TailCallVarargs:
1249         case TailCallVarargsInlinedCaller:
1250         case TailCallForwardVarargs:
1251         case TailCallForwardVarargsInlinedCaller:
1252         case ConstructVarargs:
1253         case ConstructForwardVarargs:
1254             compileCallOrConstructVarargs();
1255             break;
1256         case CallEval:
1257             compileCallEval();
1258             break;
1259         case LoadVarargs:
1260             compileLoadVarargs();
1261             break;
1262         case ForwardVarargs:
1263             compileForwardVarargs();
1264             break;
1265         case DFG::Jump:
1266             compileJump();
1267             break;
1268         case DFG::Branch:
1269             compileBranch();
1270             break;
1271         case DFG::Switch:
1272             compileSwitch();
1273             break;
1274         case DFG::EntrySwitch:
1275             compileEntrySwitch();
1276             break;
1277         case DFG::Return:
1278             compileReturn();
1279             break;
1280         case ForceOSRExit:
1281             compileForceOSRExit();
1282             break;
1283         case CPUIntrinsic:
1284 #if CPU(X86_64)
1285             compileCPUIntrinsic();
1286 #else
1287             RELEASE_ASSERT_NOT_REACHED();
1288 #endif
1289             break;
1290         case Throw:
1291             compileThrow();
1292             break;
1293         case ThrowStaticError:
1294             compileThrowStaticError();
1295             break;
1296         case InvalidationPoint:
1297             compileInvalidationPoint();
1298             break;
1299         case IsEmpty:
1300             compileIsEmpty();
1301             break;
1302         case IsUndefined:
1303             compileIsUndefined();
1304             break;
1305         case IsUndefinedOrNull:
1306             compileIsUndefinedOrNull();
1307             break;
1308         case IsBoolean:
1309             compileIsBoolean();
1310             break;
1311         case IsNumber:
1312             compileIsNumber();
1313             break;
1314         case NumberIsInteger:
1315             compileNumberIsInteger();
1316             break;
1317         case IsCellWithType:
1318             compileIsCellWithType();
1319             break;
1320         case MapHash:
1321             compileMapHash();
1322             break;
1323         case NormalizeMapKey:
1324             compileNormalizeMapKey();
1325             break;
1326         case GetMapBucket:
1327             compileGetMapBucket();
1328             break;
1329         case GetMapBucketHead:
1330             compileGetMapBucketHead();
1331             break;
1332         case GetMapBucketNext:
1333             compileGetMapBucketNext();
1334             break;
1335         case LoadKeyFromMapBucket:
1336             compileLoadKeyFromMapBucket();
1337             break;
1338         case LoadValueFromMapBucket:
1339             compileLoadValueFromMapBucket();
1340             break;
1341         case ExtractValueFromWeakMapGet:
1342             compileExtractValueFromWeakMapGet();
1343             break;
1344         case SetAdd:
1345             compileSetAdd();
1346             break;
1347         case MapSet:
1348             compileMapSet();
1349             break;
1350         case WeakMapGet:
1351             compileWeakMapGet();
1352             break;
1353         case WeakSetAdd:
1354             compileWeakSetAdd();
1355             break;
1356         case WeakMapSet:
1357             compileWeakMapSet();
1358             break;
1359         case IsObject:
1360             compileIsObject();
1361             break;
1362         case IsObjectOrNull:
1363             compileIsObjectOrNull();
1364             break;
1365         case IsFunction:
1366             compileIsFunction();
1367             break;
1368         case IsTypedArrayView:
1369             compileIsTypedArrayView();
1370             break;
1371         case ParseInt:
1372             compileParseInt();
1373             break;
1374         case TypeOf:
1375             compileTypeOf();
1376             break;
1377         case CheckTypeInfoFlags:
1378             compileCheckTypeInfoFlags();
1379             break;
1380         case OverridesHasInstance:
1381             compileOverridesHasInstance();
1382             break;
1383         case InstanceOf:
1384             compileInstanceOf();
1385             break;
1386         case InstanceOfCustom:
1387             compileInstanceOfCustom();
1388             break;
1389         case CountExecution:
1390             compileCountExecution();
1391             break;
1392         case SuperSamplerBegin:
1393             compileSuperSamplerBegin();
1394             break;
1395         case SuperSamplerEnd:
1396             compileSuperSamplerEnd();
1397             break;
1398         case StoreBarrier:
1399         case FencedStoreBarrier:
1400             compileStoreBarrier();
1401             break;
1402         case HasIndexedProperty:
1403             compileHasIndexedProperty();
1404             break;
1405         case HasGenericProperty:
1406             compileHasGenericProperty();
1407             break;
1408         case HasStructureProperty:
1409             compileHasStructureProperty();
1410             break;
1411         case GetDirectPname:
1412             compileGetDirectPname();
1413             break;
1414         case GetEnumerableLength:
1415             compileGetEnumerableLength();
1416             break;
1417         case GetPropertyEnumerator:
1418             compileGetPropertyEnumerator();
1419             break;
1420         case GetEnumeratorStructurePname:
1421             compileGetEnumeratorStructurePname();
1422             break;
1423         case GetEnumeratorGenericPname:
1424             compileGetEnumeratorGenericPname();
1425             break;
1426         case ToIndexString:
1427             compileToIndexString();
1428             break;
1429         case CheckStructureImmediate:
1430             compileCheckStructureImmediate();
1431             break;
1432         case MaterializeNewObject:
1433             compileMaterializeNewObject();
1434             break;
1435         case MaterializeCreateActivation:
1436             compileMaterializeCreateActivation();
1437             break;
1438         case CheckTraps:
1439             compileCheckTraps();
1440             break;
1441         case CreateRest:
1442             compileCreateRest();
1443             break;
1444         case GetRestLength:
1445             compileGetRestLength();
1446             break;
1447         case RegExpExec:
1448             compileRegExpExec();
1449             break;
1450         case RegExpExecNonGlobalOrSticky:
1451             compileRegExpExecNonGlobalOrSticky();
1452             break;
1453         case RegExpTest:
1454             compileRegExpTest();
1455             break;
1456         case RegExpMatchFast:
1457             compileRegExpMatchFast();
1458             break;
1459         case RegExpMatchFastGlobal:
1460             compileRegExpMatchFastGlobal();
1461             break;
1462         case NewRegexp:
1463             compileNewRegexp();
1464             break;
1465         case SetFunctionName:
1466             compileSetFunctionName();
1467             break;
1468         case StringReplace:
1469         case StringReplaceRegExp:
1470             compileStringReplace();
1471             break;
1472         case GetRegExpObjectLastIndex:
1473             compileGetRegExpObjectLastIndex();
1474             break;
1475         case SetRegExpObjectLastIndex:
1476             compileSetRegExpObjectLastIndex();
1477             break;
1478         case LogShadowChickenPrologue:
1479             compileLogShadowChickenPrologue();
1480             break;
1481         case LogShadowChickenTail:
1482             compileLogShadowChickenTail();
1483             break;
1484         case RecordRegExpCachedResult:
1485             compileRecordRegExpCachedResult();
1486             break;
1487         case ResolveScopeForHoistingFuncDeclInEval:
1488             compileResolveScopeForHoistingFuncDeclInEval();
1489             break;
1490         case ResolveScope:
1491             compileResolveScope();
1492             break;
1493         case GetDynamicVar:
1494             compileGetDynamicVar();
1495             break;
1496         case PutDynamicVar:
1497             compilePutDynamicVar();
1498             break;
1499         case Unreachable:
1500             compileUnreachable();
1501             break;
1502         case StringSlice:
1503             compileStringSlice();
1504             break;
1505         case ToLowerCase:
1506             compileToLowerCase();
1507             break;
1508         case NumberToStringWithRadix:
1509             compileNumberToStringWithRadix();
1510             break;
1511         case NumberToStringWithValidRadixConstant:
1512             compileNumberToStringWithValidRadixConstant();
1513             break;
1514         case CheckSubClass:
1515             compileCheckSubClass();
1516             break;
1517         case CallDOM:
1518             compileCallDOM();
1519             break;
1520         case CallDOMGetter:
1521             compileCallDOMGetter();
1522             break;
1523         case FilterCallLinkStatus:
1524         case FilterGetByIdStatus:
1525         case FilterPutByIdStatus:
1526         case FilterInByIdStatus:
1527             compileFilterICStatus();
1528             break;
1529         case DataViewGetInt:
1530         case DataViewGetFloat:
1531             compileDataViewGet();
1532             break;
1533         case DataViewSet:
1534             compileDataViewSet();
1535             break;
1536
1537         case PhantomLocal:
1538         case LoopHint:
1539         case MovHint:
1540         case ZombieHint:
1541         case ExitOK:
1542         case PhantomNewObject:
1543         case PhantomNewFunction:
1544         case PhantomNewGeneratorFunction:
1545         case PhantomNewAsyncGeneratorFunction:
1546         case PhantomNewAsyncFunction:
1547         case PhantomCreateActivation:
1548         case PhantomDirectArguments:
1549         case PhantomCreateRest:
1550         case PhantomSpread:
1551         case PhantomNewArrayWithSpread:
1552         case PhantomNewArrayBuffer:
1553         case PhantomClonedArguments:
1554         case PhantomNewRegexp:
1555         case PutHint:
1556         case BottomValue:
1557         case KillStack:
1558         case InitializeEntrypointArguments:
1559             break;
1560         default:
1561             DFG_CRASH(m_graph, m_node, "Unrecognized node in FTL backend");
1562             break;
1563         }
1564         
1565         if (m_node->isTerminal())
1566             return false;
1567         
1568         if (!m_state.isValid()) {
1569             safelyInvalidateAfterTermination();
1570             return false;
1571         }
1572
1573         m_availabilityCalculator.executeNode(m_node);
1574         m_interpreter.executeEffects(nodeIndex);
1575         
1576         return true;
1577     }
1578
1579     void compileUpsilon()
1580     {
1581         LValue upsilonValue = nullptr;
1582         switch (m_node->child1().useKind()) {
1583         case DoubleRepUse:
1584             upsilonValue = lowDouble(m_node->child1());
1585             break;
1586         case Int32Use:
1587         case KnownInt32Use:
1588             upsilonValue = lowInt32(m_node->child1());
1589             break;
1590         case Int52RepUse:
1591             upsilonValue = lowInt52(m_node->child1());
1592             break;
1593         case BooleanUse:
1594         case KnownBooleanUse:
1595             upsilonValue = lowBoolean(m_node->child1());
1596             break;
1597         case CellUse:
1598         case KnownCellUse:
1599             upsilonValue = lowCell(m_node->child1());
1600             break;
1601         case UntypedUse:
1602             upsilonValue = lowJSValue(m_node->child1());
1603             break;
1604         default:
1605             DFG_CRASH(m_graph, m_node, "Bad use kind");
1606             break;
1607         }
1608         ValueFromBlock upsilon = m_out.anchor(upsilonValue);
1609         LValue phiNode = m_phis.get(m_node->phi());
1610         m_out.addIncomingToPhi(phiNode, upsilon);
1611     }
1612     
1613     void compilePhi()
1614     {
1615         LValue phi = m_phis.get(m_node);
1616         m_out.m_block->append(phi);
1617
1618         switch (m_node->flags() & NodeResultMask) {
1619         case NodeResultDouble:
1620             setDouble(phi);
1621             break;
1622         case NodeResultInt32:
1623             setInt32(phi);
1624             break;
1625         case NodeResultInt52:
1626             setInt52(phi);
1627             break;
1628         case NodeResultBoolean:
1629             setBoolean(phi);
1630             break;
1631         case NodeResultJS:
1632             setJSValue(phi);
1633             break;
1634         default:
1635             DFG_CRASH(m_graph, m_node, "Bad result type");
1636             break;
1637         }
1638     }
1639     
1640     void compileDoubleConstant()
1641     {
1642         setDouble(m_out.constDouble(m_node->asNumber()));
1643     }
1644     
1645     void compileInt52Constant()
1646     {
1647         int64_t value = m_node->asAnyInt();
1648         
1649         setInt52(m_out.constInt64(value << JSValue::int52ShiftAmount));
1650         setStrictInt52(m_out.constInt64(value));
1651     }
1652
1653     void compileLazyJSConstant()
1654     {
1655         PatchpointValue* patchpoint = m_out.patchpoint(Int64);
1656         LazyJSValue value = m_node->lazyJSValue();
1657         patchpoint->setGenerator(
1658             [=] (CCallHelpers& jit, const StackmapGenerationParams& params) {
1659                 value.emit(jit, JSValueRegs(params[0].gpr()));
1660             });
1661         patchpoint->effects = Effects::none();
1662         setJSValue(patchpoint);
1663     }
1664
1665     void compileDoubleRep()
1666     {
1667         switch (m_node->child1().useKind()) {
1668         case RealNumberUse: {
1669             LValue value = lowJSValue(m_node->child1(), ManualOperandSpeculation);
1670             
1671             LValue doubleValue = unboxDouble(value);
1672             
1673             LBasicBlock intCase = m_out.newBlock();
1674             LBasicBlock continuation = m_out.newBlock();
1675             
1676             ValueFromBlock fastResult = m_out.anchor(doubleValue);
1677             m_out.branch(
1678                 m_out.doubleEqual(doubleValue, doubleValue),
1679                 usually(continuation), rarely(intCase));
1680             
1681             LBasicBlock lastNext = m_out.appendTo(intCase, continuation);
1682
1683             FTL_TYPE_CHECK(
1684                 jsValueValue(value), m_node->child1(), SpecBytecodeRealNumber,
1685                 isNotInt32(value, provenType(m_node->child1()) & ~SpecDoubleReal));
1686             ValueFromBlock slowResult = m_out.anchor(m_out.intToDouble(unboxInt32(value)));
1687             m_out.jump(continuation);
1688             
1689             m_out.appendTo(continuation, lastNext);
1690             
1691             setDouble(m_out.phi(Double, fastResult, slowResult));
1692             return;
1693         }
1694             
1695         case NotCellUse:
1696         case NumberUse: {
1697             bool shouldConvertNonNumber = m_node->child1().useKind() == NotCellUse;
1698             
1699             LValue value = lowJSValue(m_node->child1(), ManualOperandSpeculation);
1700
1701             LBasicBlock intCase = m_out.newBlock();
1702             LBasicBlock doubleTesting = m_out.newBlock();
1703             LBasicBlock doubleCase = m_out.newBlock();
1704             LBasicBlock nonDoubleCase = m_out.newBlock();
1705             LBasicBlock continuation = m_out.newBlock();
1706             
1707             m_out.branch(
1708                 isNotInt32(value, provenType(m_node->child1())),
1709                 unsure(doubleTesting), unsure(intCase));
1710             
1711             LBasicBlock lastNext = m_out.appendTo(intCase, doubleTesting);
1712             
1713             ValueFromBlock intToDouble = m_out.anchor(
1714                 m_out.intToDouble(unboxInt32(value)));
1715             m_out.jump(continuation);
1716             
1717             m_out.appendTo(doubleTesting, doubleCase);
1718             LValue valueIsNumber = isNumber(value, provenType(m_node->child1()));
1719             m_out.branch(valueIsNumber, usually(doubleCase), rarely(nonDoubleCase));
1720
1721             m_out.appendTo(doubleCase, nonDoubleCase);
1722             ValueFromBlock unboxedDouble = m_out.anchor(unboxDouble(value));
1723             m_out.jump(continuation);
1724
1725             if (shouldConvertNonNumber) {
1726                 LBasicBlock undefinedCase = m_out.newBlock();
1727                 LBasicBlock testNullCase = m_out.newBlock();
1728                 LBasicBlock nullCase = m_out.newBlock();
1729                 LBasicBlock testBooleanTrueCase = m_out.newBlock();
1730                 LBasicBlock convertBooleanTrueCase = m_out.newBlock();
1731                 LBasicBlock convertBooleanFalseCase = m_out.newBlock();
1732
1733                 m_out.appendTo(nonDoubleCase, undefinedCase);
1734                 LValue valueIsUndefined = m_out.equal(value, m_out.constInt64(ValueUndefined));
1735                 m_out.branch(valueIsUndefined, unsure(undefinedCase), unsure(testNullCase));
1736
1737                 m_out.appendTo(undefinedCase, testNullCase);
1738                 ValueFromBlock convertedUndefined = m_out.anchor(m_out.constDouble(PNaN));
1739                 m_out.jump(continuation);
1740
1741                 m_out.appendTo(testNullCase, nullCase);
1742                 LValue valueIsNull = m_out.equal(value, m_out.constInt64(ValueNull));
1743                 m_out.branch(valueIsNull, unsure(nullCase), unsure(testBooleanTrueCase));
1744
1745                 m_out.appendTo(nullCase, testBooleanTrueCase);
1746                 ValueFromBlock convertedNull = m_out.anchor(m_out.constDouble(0));
1747                 m_out.jump(continuation);
1748
1749                 m_out.appendTo(testBooleanTrueCase, convertBooleanTrueCase);
1750                 LValue valueIsBooleanTrue = m_out.equal(value, m_out.constInt64(ValueTrue));
1751                 m_out.branch(valueIsBooleanTrue, unsure(convertBooleanTrueCase), unsure(convertBooleanFalseCase));
1752
1753                 m_out.appendTo(convertBooleanTrueCase, convertBooleanFalseCase);
1754                 ValueFromBlock convertedTrue = m_out.anchor(m_out.constDouble(1));
1755                 m_out.jump(continuation);
1756
1757                 m_out.appendTo(convertBooleanFalseCase, continuation);
1758
1759                 LValue valueIsNotBooleanFalse = m_out.notEqual(value, m_out.constInt64(ValueFalse));
1760                 FTL_TYPE_CHECK(jsValueValue(value), m_node->child1(), ~SpecCellCheck, valueIsNotBooleanFalse);
1761                 ValueFromBlock convertedFalse = m_out.anchor(m_out.constDouble(0));
1762                 m_out.jump(continuation);
1763
1764                 m_out.appendTo(continuation, lastNext);
1765                 setDouble(m_out.phi(Double, intToDouble, unboxedDouble, convertedUndefined, convertedNull, convertedTrue, convertedFalse));
1766                 return;
1767             }
1768             m_out.appendTo(nonDoubleCase, continuation);
1769             FTL_TYPE_CHECK(jsValueValue(value), m_node->child1(), SpecBytecodeNumber, m_out.booleanTrue);
1770             m_out.unreachable();
1771
1772             m_out.appendTo(continuation, lastNext);
1773
1774             setDouble(m_out.phi(Double, intToDouble, unboxedDouble));
1775             return;
1776         }
1777             
1778         case Int52RepUse: {
1779             setDouble(strictInt52ToDouble(lowStrictInt52(m_node->child1())));
1780             return;
1781         }
1782             
1783         default:
1784             DFG_CRASH(m_graph, m_node, "Bad use kind");
1785         }
1786     }
1787
1788     void compileDoubleAsInt32()
1789     {
1790         LValue integerValue = convertDoubleToInt32(lowDouble(m_node->child1()), shouldCheckNegativeZero(m_node->arithMode()));
1791         setInt32(integerValue);
1792     }
1793
1794     void compileValueRep()
1795     {
1796         switch (m_node->child1().useKind()) {
1797         case DoubleRepUse: {
1798             LValue value = lowDouble(m_node->child1());
1799             
1800             if (m_interpreter.needsTypeCheck(m_node->child1(), ~SpecDoubleImpureNaN)) {
1801                 value = m_out.select(
1802                     m_out.doubleEqual(value, value), value, m_out.constDouble(PNaN));
1803             }
1804             
1805             setJSValue(boxDouble(value));
1806             return;
1807         }
1808             
1809         case Int52RepUse: {
1810             setJSValue(strictInt52ToJSValue(lowStrictInt52(m_node->child1())));
1811             return;
1812         }
1813             
1814         default:
1815             DFG_CRASH(m_graph, m_node, "Bad use kind");
1816         }
1817     }
1818     
1819     void compileInt52Rep()
1820     {
1821         switch (m_node->child1().useKind()) {
1822         case Int32Use:
1823             setStrictInt52(m_out.signExt32To64(lowInt32(m_node->child1())));
1824             return;
1825             
1826         case AnyIntUse:
1827             setStrictInt52(
1828                 jsValueToStrictInt52(
1829                     m_node->child1(), lowJSValue(m_node->child1(), ManualOperandSpeculation)));
1830             return;
1831             
1832         case DoubleRepAnyIntUse:
1833             setStrictInt52(
1834                 doubleToStrictInt52(
1835                     m_node->child1(), lowDouble(m_node->child1())));
1836             return;
1837             
1838         default:
1839             RELEASE_ASSERT_NOT_REACHED();
1840         }
1841     }
1842     
1843     void compileValueToInt32()
1844     {
1845         switch (m_node->child1().useKind()) {
1846         case Int52RepUse:
1847             setInt32(m_out.castToInt32(lowStrictInt52(m_node->child1())));
1848             break;
1849             
1850         case DoubleRepUse:
1851             setInt32(doubleToInt32(lowDouble(m_node->child1())));
1852             break;
1853             
1854         case NumberUse:
1855         case NotCellUse: {
1856             LoweredNodeValue value = m_int32Values.get(m_node->child1().node());
1857             if (isValid(value)) {
1858                 setInt32(value.value());
1859                 break;
1860             }
1861             
1862             value = m_jsValueValues.get(m_node->child1().node());
1863             if (isValid(value)) {
1864                 setInt32(numberOrNotCellToInt32(m_node->child1(), value.value()));
1865                 break;
1866             }
1867             
1868             // We'll basically just get here for constants. But it's good to have this
1869             // catch-all since we often add new representations into the mix.
1870             setInt32(
1871                 numberOrNotCellToInt32(
1872                     m_node->child1(),
1873                     lowJSValue(m_node->child1(), ManualOperandSpeculation)));
1874             break;
1875         }
1876             
1877         default:
1878             DFG_CRASH(m_graph, m_node, "Bad use kind");
1879             break;
1880         }
1881     }
1882     
1883     void compileBooleanToNumber()
1884     {
1885         switch (m_node->child1().useKind()) {
1886         case BooleanUse: {
1887             setInt32(m_out.zeroExt(lowBoolean(m_node->child1()), Int32));
1888             return;
1889         }
1890             
1891         case UntypedUse: {
1892             LValue value = lowJSValue(m_node->child1());
1893             
1894             if (!m_interpreter.needsTypeCheck(m_node->child1(), SpecBoolInt32 | SpecBoolean)) {
1895                 setInt32(m_out.bitAnd(m_out.castToInt32(value), m_out.int32One));
1896                 return;
1897             }
1898             
1899             LBasicBlock booleanCase = m_out.newBlock();
1900             LBasicBlock continuation = m_out.newBlock();
1901             
1902             ValueFromBlock notBooleanResult = m_out.anchor(value);
1903             m_out.branch(
1904                 isBoolean(value, provenType(m_node->child1())),
1905                 unsure(booleanCase), unsure(continuation));
1906             
1907             LBasicBlock lastNext = m_out.appendTo(booleanCase, continuation);
1908             ValueFromBlock booleanResult = m_out.anchor(m_out.bitOr(
1909                 m_out.zeroExt(unboxBoolean(value), Int64), m_tagTypeNumber));
1910             m_out.jump(continuation);
1911             
1912             m_out.appendTo(continuation, lastNext);
1913             setJSValue(m_out.phi(Int64, booleanResult, notBooleanResult));
1914             return;
1915         }
1916             
1917         default:
1918             RELEASE_ASSERT_NOT_REACHED();
1919             return;
1920         }
1921     }
1922
1923     void compileExtractOSREntryLocal()
1924     {
1925         EncodedJSValue* buffer = static_cast<EncodedJSValue*>(
1926             m_ftlState.jitCode->ftlForOSREntry()->entryBuffer()->dataBuffer());
1927         setJSValue(m_out.load64(m_out.absolute(buffer + m_node->unlinkedLocal().toLocal())));
1928     }
1929
1930     void compileExtractCatchLocal()
1931     {
1932         EncodedJSValue* buffer = static_cast<EncodedJSValue*>(m_ftlState.jitCode->common.catchOSREntryBuffer->dataBuffer());
1933         setJSValue(m_out.load64(m_out.absolute(buffer + m_node->catchOSREntryIndex())));
1934     }
1935
1936     void compileClearCatchLocals()
1937     {
1938         ScratchBuffer* scratchBuffer = m_ftlState.jitCode->common.catchOSREntryBuffer;
1939         ASSERT(scratchBuffer);
1940         m_out.storePtr(m_out.constIntPtr(0), m_out.absolute(scratchBuffer->addressOfActiveLength()));
1941     }
1942     
1943     void compileGetStack()
1944     {
1945         StackAccessData* data = m_node->stackAccessData();
1946         AbstractValue& value = m_state.operand(data->local);
1947         
1948         DFG_ASSERT(m_graph, m_node, isConcrete(data->format), data->format);
1949         
1950         switch (data->format) {
1951         case FlushedDouble:
1952             setDouble(m_out.loadDouble(addressFor(data->machineLocal)));
1953             break;
1954         case FlushedInt52:
1955             setInt52(m_out.load64(addressFor(data->machineLocal)));
1956             break;
1957         default:
1958             if (isInt32Speculation(value.m_type))
1959                 setInt32(m_out.load32(payloadFor(data->machineLocal)));
1960             else
1961                 setJSValue(m_out.load64(addressFor(data->machineLocal)));
1962             break;
1963         }
1964     }
1965     
1966     void compilePutStack()
1967     {
1968         StackAccessData* data = m_node->stackAccessData();
1969         switch (data->format) {
1970         case FlushedJSValue: {
1971             LValue value = lowJSValue(m_node->child1());
1972             m_out.store64(value, addressFor(data->machineLocal));
1973             break;
1974         }
1975             
1976         case FlushedDouble: {
1977             LValue value = lowDouble(m_node->child1());
1978             m_out.storeDouble(value, addressFor(data->machineLocal));
1979             break;
1980         }
1981             
1982         case FlushedInt32: {
1983             LValue value = lowInt32(m_node->child1());
1984             m_out.store32(value, payloadFor(data->machineLocal));
1985             break;
1986         }
1987             
1988         case FlushedInt52: {
1989             LValue value = lowInt52(m_node->child1());
1990             m_out.store64(value, addressFor(data->machineLocal));
1991             break;
1992         }
1993             
1994         case FlushedCell: {
1995             LValue value = lowCell(m_node->child1());
1996             m_out.store64(value, addressFor(data->machineLocal));
1997             break;
1998         }
1999             
2000         case FlushedBoolean: {
2001             speculateBoolean(m_node->child1());
2002             m_out.store64(
2003                 lowJSValue(m_node->child1(), ManualOperandSpeculation),
2004                 addressFor(data->machineLocal));
2005             break;
2006         }
2007             
2008         default:
2009             DFG_CRASH(m_graph, m_node, "Bad flush format");
2010             break;
2011         }
2012     }
2013     
2014     void compileNoOp()
2015     {
2016         DFG_NODE_DO_TO_CHILDREN(m_graph, m_node, speculate);
2017     }
2018
2019     void compileToObjectOrCallObjectConstructor()
2020     {
2021         LValue value = lowJSValue(m_node->child1());
2022
2023         LBasicBlock isCellCase = m_out.newBlock();
2024         LBasicBlock slowCase = m_out.newBlock();
2025         LBasicBlock continuation = m_out.newBlock();
2026
2027         m_out.branch(isCell(value, provenType(m_node->child1())), usually(isCellCase), rarely(slowCase));
2028
2029         LBasicBlock lastNext = m_out.appendTo(isCellCase, slowCase);
2030         ValueFromBlock fastResult = m_out.anchor(value);
2031         m_out.branch(isObject(value), usually(continuation), rarely(slowCase));
2032
2033         m_out.appendTo(slowCase, continuation);
2034
2035         ValueFromBlock slowResult;
2036         if (m_node->op() == ToObject) {
2037             auto* globalObject = m_graph.globalObjectFor(m_node->origin.semantic);
2038             slowResult = m_out.anchor(vmCall(Int64, m_out.operation(operationToObject), m_callFrame, weakPointer(globalObject), value, m_out.constIntPtr(m_graph.identifiers()[m_node->identifierNumber()])));
2039         } else
2040             slowResult = m_out.anchor(vmCall(Int64, m_out.operation(operationCallObjectConstructor), m_callFrame, frozenPointer(m_node->cellOperand()), value));
2041         m_out.jump(continuation);
2042
2043         m_out.appendTo(continuation, lastNext);
2044         setJSValue(m_out.phi(Int64, fastResult, slowResult));
2045     }
2046     
2047     void compileToThis()
2048     {
2049         LValue value = lowJSValue(m_node->child1());
2050         
2051         LBasicBlock isCellCase = m_out.newBlock();
2052         LBasicBlock slowCase = m_out.newBlock();
2053         LBasicBlock continuation = m_out.newBlock();
2054         
2055         m_out.branch(
2056             isCell(value, provenType(m_node->child1())), usually(isCellCase), rarely(slowCase));
2057         
2058         LBasicBlock lastNext = m_out.appendTo(isCellCase, slowCase);
2059         ValueFromBlock fastResult = m_out.anchor(value);
2060         m_out.branch(
2061             m_out.testIsZero32(
2062                 m_out.load8ZeroExt32(value, m_heaps.JSCell_typeInfoFlags),
2063                 m_out.constInt32(OverridesToThis)),
2064             usually(continuation), rarely(slowCase));
2065         
2066         m_out.appendTo(slowCase, continuation);
2067         J_JITOperation_EJ function;
2068         if (m_graph.isStrictModeFor(m_node->origin.semantic))
2069             function = operationToThisStrict;
2070         else
2071             function = operationToThis;
2072         ValueFromBlock slowResult = m_out.anchor(
2073             vmCall(Int64, m_out.operation(function), m_callFrame, value));
2074         m_out.jump(continuation);
2075         
2076         m_out.appendTo(continuation, lastNext);
2077         setJSValue(m_out.phi(Int64, fastResult, slowResult));
2078     }
2079
2080     void compileValueAdd()
2081     {
2082         if (m_node->isBinaryUseKind(BigIntUse)) {
2083             LValue left = lowBigInt(m_node->child1());
2084             LValue right = lowBigInt(m_node->child2());
2085
2086             LValue result = vmCall(pointerType(), m_out.operation(operationAddBigInt), m_callFrame, left, right);
2087             setJSValue(result);
2088             return;
2089         }
2090
2091         CodeBlock* baselineCodeBlock = m_ftlState.graph.baselineCodeBlockFor(m_node->origin.semantic);
2092         unsigned bytecodeIndex = m_node->origin.semantic.bytecodeIndex();
2093         ArithProfile* arithProfile = baselineCodeBlock->arithProfileForBytecodeOffset(bytecodeIndex);
2094         auto repatchingFunction = operationValueAddOptimize;
2095         auto nonRepatchingFunction = operationValueAdd;
2096         compileBinaryMathIC<JITAddGenerator>(arithProfile, repatchingFunction, nonRepatchingFunction);
2097     }
2098
2099     void compileValueSub()
2100     {
2101         if (m_node->isBinaryUseKind(BigIntUse)) {
2102             LValue left = lowBigInt(m_node->child1());
2103             LValue right = lowBigInt(m_node->child2());
2104             
2105             LValue result = vmCall(pointerType(), m_out.operation(operationSubBigInt), m_callFrame, left, right);
2106             setJSValue(result);
2107             return;
2108         }
2109
2110         CodeBlock* baselineCodeBlock = m_ftlState.graph.baselineCodeBlockFor(m_node->origin.semantic);
2111         unsigned bytecodeIndex = m_node->origin.semantic.bytecodeIndex();
2112         ArithProfile* arithProfile = baselineCodeBlock->arithProfileForBytecodeOffset(bytecodeIndex);
2113         auto repatchingFunction = operationValueSubOptimize;
2114         auto nonRepatchingFunction = operationValueSub;
2115         compileBinaryMathIC<JITSubGenerator>(arithProfile, repatchingFunction, nonRepatchingFunction);
2116     }
2117
2118     void compileValueMul()
2119     {
2120         if (m_node->isBinaryUseKind(BigIntUse)) {
2121             LValue left = lowBigInt(m_node->child1());
2122             LValue right = lowBigInt(m_node->child2());
2123             
2124             LValue result = vmCall(Int64, m_out.operation(operationMulBigInt), m_callFrame, left, right);
2125             setJSValue(result);
2126             return;
2127         }
2128
2129         CodeBlock* baselineCodeBlock = m_ftlState.graph.baselineCodeBlockFor(m_node->origin.semantic);
2130         unsigned bytecodeIndex = m_node->origin.semantic.bytecodeIndex();
2131         ArithProfile* arithProfile = baselineCodeBlock->arithProfileForBytecodeOffset(bytecodeIndex);
2132         auto repatchingFunction = operationValueMulOptimize;
2133         auto nonRepatchingFunction = operationValueMul;
2134         compileBinaryMathIC<JITMulGenerator>(arithProfile, repatchingFunction, nonRepatchingFunction);
2135     }
2136
2137     template <typename Generator, typename Func1, typename Func2,
2138         typename = std::enable_if_t<std::is_function<typename std::remove_pointer<Func1>::type>::value && std::is_function<typename std::remove_pointer<Func2>::type>::value>>
2139     void compileUnaryMathIC(ArithProfile* arithProfile, Func1 repatchingFunction, Func2 nonRepatchingFunction)
2140     {
2141         Node* node = m_node;
2142
2143         LValue operand = lowJSValue(node->child1());
2144
2145         PatchpointValue* patchpoint = m_out.patchpoint(Int64);
2146         patchpoint->appendSomeRegister(operand);
2147         patchpoint->append(m_tagMask, ValueRep::lateReg(GPRInfo::tagMaskRegister));
2148         patchpoint->append(m_tagTypeNumber, ValueRep::lateReg(GPRInfo::tagTypeNumberRegister));
2149         RefPtr<PatchpointExceptionHandle> exceptionHandle = preparePatchpointForExceptions(patchpoint);
2150         patchpoint->numGPScratchRegisters = 1;
2151         patchpoint->clobber(RegisterSet::macroScratchRegisters());
2152         State* state = &m_ftlState;
2153         patchpoint->setGenerator(
2154             [=] (CCallHelpers& jit, const StackmapGenerationParams& params) {
2155                 AllowMacroScratchRegisterUsage allowScratch(jit);
2156
2157                 Box<CCallHelpers::JumpList> exceptions =
2158                     exceptionHandle->scheduleExitCreation(params)->jumps(jit);
2159
2160 #if ENABLE(MATH_IC_STATS)
2161                 auto inlineStart = jit.label();
2162 #endif
2163
2164                 Box<MathICGenerationState> mathICGenerationState = Box<MathICGenerationState>::create();
2165                 JITUnaryMathIC<Generator>* mathIC = jit.codeBlock()->addMathIC<Generator>(arithProfile);
2166                 mathIC->m_generator = Generator(JSValueRegs(params[0].gpr()), JSValueRegs(params[1].gpr()), params.gpScratch(0));
2167
2168                 bool shouldEmitProfiling = false;
2169                 bool generatedInline = mathIC->generateInline(jit, *mathICGenerationState, shouldEmitProfiling);
2170
2171                 if (generatedInline) {
2172                     ASSERT(!mathICGenerationState->slowPathJumps.empty());
2173                     auto done = jit.label();
2174                     params.addLatePath([=] (CCallHelpers& jit) {
2175                         AllowMacroScratchRegisterUsage allowScratch(jit);
2176                         mathICGenerationState->slowPathJumps.link(&jit);
2177                         mathICGenerationState->slowPathStart = jit.label();
2178 #if ENABLE(MATH_IC_STATS)
2179                         auto slowPathStart = jit.label();
2180 #endif
2181
2182                         if (mathICGenerationState->shouldSlowPathRepatch) {
2183                             SlowPathCall call = callOperation(*state, params.unavailableRegisters(), jit, node->origin.semantic, exceptions.get(),
2184                                 repatchingFunction, params[0].gpr(), params[1].gpr(), CCallHelpers::TrustedImmPtr(mathIC));
2185                             mathICGenerationState->slowPathCall = call.call();
2186                         } else {
2187                             SlowPathCall call = callOperation(*state, params.unavailableRegisters(), jit, node->origin.semantic,
2188                                 exceptions.get(), nonRepatchingFunction, params[0].gpr(), params[1].gpr());
2189                             mathICGenerationState->slowPathCall = call.call();
2190                         }
2191                         jit.jump().linkTo(done, &jit);
2192
2193                         jit.addLinkTask([=] (LinkBuffer& linkBuffer) {
2194                             mathIC->finalizeInlineCode(*mathICGenerationState, linkBuffer);
2195                         });
2196
2197 #if ENABLE(MATH_IC_STATS)
2198                         auto slowPathEnd = jit.label();
2199                         jit.addLinkTask([=] (LinkBuffer& linkBuffer) {
2200                             size_t size = linkBuffer.locationOf(slowPathEnd).executableAddress<char*>() - linkBuffer.locationOf(slowPathStart).executableAddress<char*>();
2201                             mathIC->m_generatedCodeSize += size;
2202                         });
2203 #endif
2204                     });
2205                 } else {
2206                     callOperation(
2207                         *state, params.unavailableRegisters(), jit, node->origin.semantic, exceptions.get(),
2208                         nonRepatchingFunction, params[0].gpr(), params[1].gpr());
2209                 }
2210
2211 #if ENABLE(MATH_IC_STATS)
2212                 auto inlineEnd = jit.label();
2213                 jit.addLinkTask([=] (LinkBuffer& linkBuffer) {
2214                     size_t size = linkBuffer.locationOf(inlineEnd).executableAddress<char*>() - linkBuffer.locationOf(inlineStart).executableAddress<char*>();
2215                     mathIC->m_generatedCodeSize += size;
2216                 });
2217 #endif
2218             });
2219
2220         setJSValue(patchpoint);
2221     }
2222
2223     template <typename Generator, typename Func1, typename Func2,
2224         typename = std::enable_if_t<std::is_function<typename std::remove_pointer<Func1>::type>::value && std::is_function<typename std::remove_pointer<Func2>::type>::value>>
2225     void compileBinaryMathIC(ArithProfile* arithProfile, Func1 repatchingFunction, Func2 nonRepatchingFunction)
2226     {
2227         Node* node = m_node;
2228         
2229         LValue left = lowJSValue(node->child1());
2230         LValue right = lowJSValue(node->child2());
2231
2232         SnippetOperand leftOperand(m_state.forNode(node->child1()).resultType());
2233         SnippetOperand rightOperand(m_state.forNode(node->child2()).resultType());
2234             
2235         PatchpointValue* patchpoint = m_out.patchpoint(Int64);
2236         patchpoint->appendSomeRegister(left);
2237         patchpoint->appendSomeRegister(right);
2238         patchpoint->append(m_tagMask, ValueRep::lateReg(GPRInfo::tagMaskRegister));
2239         patchpoint->append(m_tagTypeNumber, ValueRep::lateReg(GPRInfo::tagTypeNumberRegister));
2240         RefPtr<PatchpointExceptionHandle> exceptionHandle =
2241             preparePatchpointForExceptions(patchpoint);
2242         patchpoint->numGPScratchRegisters = 1;
2243         patchpoint->numFPScratchRegisters = 2;
2244         patchpoint->clobber(RegisterSet::macroScratchRegisters());
2245         State* state = &m_ftlState;
2246         patchpoint->setGenerator(
2247             [=] (CCallHelpers& jit, const StackmapGenerationParams& params) {
2248                 AllowMacroScratchRegisterUsage allowScratch(jit);
2249
2250
2251                 Box<CCallHelpers::JumpList> exceptions =
2252                     exceptionHandle->scheduleExitCreation(params)->jumps(jit);
2253
2254 #if ENABLE(MATH_IC_STATS)
2255                 auto inlineStart = jit.label();
2256 #endif
2257
2258                 Box<MathICGenerationState> mathICGenerationState = Box<MathICGenerationState>::create();
2259                 JITBinaryMathIC<Generator>* mathIC = jit.codeBlock()->addMathIC<Generator>(arithProfile);
2260                 mathIC->m_generator = Generator(leftOperand, rightOperand, JSValueRegs(params[0].gpr()),
2261                     JSValueRegs(params[1].gpr()), JSValueRegs(params[2].gpr()), params.fpScratch(0),
2262                     params.fpScratch(1), params.gpScratch(0), InvalidFPRReg);
2263
2264                 bool shouldEmitProfiling = false;
2265                 bool generatedInline = mathIC->generateInline(jit, *mathICGenerationState, shouldEmitProfiling);
2266
2267                 if (generatedInline) {
2268                     ASSERT(!mathICGenerationState->slowPathJumps.empty());
2269                     auto done = jit.label();
2270                     params.addLatePath([=] (CCallHelpers& jit) {
2271                         AllowMacroScratchRegisterUsage allowScratch(jit);
2272                         mathICGenerationState->slowPathJumps.link(&jit);
2273                         mathICGenerationState->slowPathStart = jit.label();
2274 #if ENABLE(MATH_IC_STATS)
2275                         auto slowPathStart = jit.label();
2276 #endif
2277
2278                         if (mathICGenerationState->shouldSlowPathRepatch) {
2279                             SlowPathCall call = callOperation(*state, params.unavailableRegisters(), jit, node->origin.semantic, exceptions.get(),
2280                                 repatchingFunction, params[0].gpr(), params[1].gpr(), params[2].gpr(), CCallHelpers::TrustedImmPtr(mathIC));
2281                             mathICGenerationState->slowPathCall = call.call();
2282                         } else {
2283                             SlowPathCall call = callOperation(*state, params.unavailableRegisters(), jit, node->origin.semantic,
2284                                 exceptions.get(), nonRepatchingFunction, params[0].gpr(), params[1].gpr(), params[2].gpr());
2285                             mathICGenerationState->slowPathCall = call.call();
2286                         }
2287                         jit.jump().linkTo(done, &jit);
2288
2289                         jit.addLinkTask([=] (LinkBuffer& linkBuffer) {
2290                             mathIC->finalizeInlineCode(*mathICGenerationState, linkBuffer);
2291                         });
2292
2293 #if ENABLE(MATH_IC_STATS)
2294                         auto slowPathEnd = jit.label();
2295                         jit.addLinkTask([=] (LinkBuffer& linkBuffer) {
2296                             size_t size = linkBuffer.locationOf(slowPathEnd).executableAddress<char*>() - linkBuffer.locationOf(slowPathStart).executableAddress<char*>();
2297                             mathIC->m_generatedCodeSize += size;
2298                         });
2299 #endif
2300                     });
2301                 } else {
2302                     callOperation(
2303                         *state, params.unavailableRegisters(), jit, node->origin.semantic, exceptions.get(),
2304                         nonRepatchingFunction, params[0].gpr(), params[1].gpr(), params[2].gpr());
2305                 }
2306
2307 #if ENABLE(MATH_IC_STATS)
2308                 auto inlineEnd = jit.label();
2309                 jit.addLinkTask([=] (LinkBuffer& linkBuffer) {
2310                     size_t size = linkBuffer.locationOf(inlineEnd).executableAddress<char*>() - linkBuffer.locationOf(inlineStart).executableAddress<char*>();
2311                     mathIC->m_generatedCodeSize += size;
2312                 });
2313 #endif
2314             });
2315
2316         setJSValue(patchpoint);
2317     }
2318     
2319     void compileStrCat()
2320     {
2321         LValue result;
2322         if (m_node->child3()) {
2323             result = vmCall(
2324                 Int64, m_out.operation(operationStrCat3), m_callFrame,
2325                 lowJSValue(m_node->child1(), ManualOperandSpeculation),
2326                 lowJSValue(m_node->child2(), ManualOperandSpeculation),
2327                 lowJSValue(m_node->child3(), ManualOperandSpeculation));
2328         } else {
2329             result = vmCall(
2330                 Int64, m_out.operation(operationStrCat2), m_callFrame,
2331                 lowJSValue(m_node->child1(), ManualOperandSpeculation),
2332                 lowJSValue(m_node->child2(), ManualOperandSpeculation));
2333         }
2334         setJSValue(result);
2335     }
2336     
2337     void compileArithAddOrSub()
2338     {
2339         bool isSub =  m_node->op() == ArithSub;
2340         switch (m_node->binaryUseKind()) {
2341         case Int32Use: {
2342             LValue left = lowInt32(m_node->child1());
2343             LValue right = lowInt32(m_node->child2());
2344
2345             if (!shouldCheckOverflow(m_node->arithMode())) {
2346                 setInt32(isSub ? m_out.sub(left, right) : m_out.add(left, right));
2347                 break;
2348             }
2349
2350             CheckValue* result =
2351                 isSub ? m_out.speculateSub(left, right) : m_out.speculateAdd(left, right);
2352             blessSpeculation(result, Overflow, noValue(), nullptr, m_origin);
2353             setInt32(result);
2354             break;
2355         }
2356             
2357         case Int52RepUse: {
2358             if (!abstractValue(m_node->child1()).couldBeType(SpecNonInt32AsInt52)
2359                 && !abstractValue(m_node->child2()).couldBeType(SpecNonInt32AsInt52)) {
2360                 Int52Kind kind;
2361                 LValue left = lowWhicheverInt52(m_node->child1(), kind);
2362                 LValue right = lowInt52(m_node->child2(), kind);
2363                 setInt52(isSub ? m_out.sub(left, right) : m_out.add(left, right), kind);
2364                 break;
2365             }
2366
2367             LValue left = lowInt52(m_node->child1());
2368             LValue right = lowInt52(m_node->child2());
2369             CheckValue* result =
2370                 isSub ? m_out.speculateSub(left, right) : m_out.speculateAdd(left, right);
2371             blessSpeculation(result, Overflow, noValue(), nullptr, m_origin);
2372             setInt52(result);
2373             break;
2374         }
2375             
2376         case DoubleRepUse: {
2377             LValue C1 = lowDouble(m_node->child1());
2378             LValue C2 = lowDouble(m_node->child2());
2379
2380             setDouble(isSub ? m_out.doubleSub(C1, C2) : m_out.doubleAdd(C1, C2));
2381             break;
2382         }
2383
2384         case UntypedUse: {
2385             if (!isSub) {
2386                 DFG_CRASH(m_graph, m_node, "Bad use kind");
2387                 break;
2388             }
2389
2390             CodeBlock* baselineCodeBlock = m_ftlState.graph.baselineCodeBlockFor(m_node->origin.semantic);
2391             unsigned bytecodeIndex = m_node->origin.semantic.bytecodeIndex();
2392             ArithProfile* arithProfile = baselineCodeBlock->arithProfileForBytecodeOffset(bytecodeIndex);
2393             auto repatchingFunction = operationValueSubOptimize;
2394             auto nonRepatchingFunction = operationValueSub;
2395             compileBinaryMathIC<JITSubGenerator>(arithProfile, repatchingFunction, nonRepatchingFunction);
2396             break;
2397         }
2398
2399         default:
2400             DFG_CRASH(m_graph, m_node, "Bad use kind");
2401             break;
2402         }
2403     }
2404
2405     void compileArithClz32()
2406     {
2407         if (m_node->child1().useKind() == Int32Use || m_node->child1().useKind() == KnownInt32Use) {
2408             LValue operand = lowInt32(m_node->child1());
2409             setInt32(m_out.ctlz32(operand));
2410             return;
2411         }
2412         DFG_ASSERT(m_graph, m_node, m_node->child1().useKind() == UntypedUse, m_node->child1().useKind());
2413         LValue argument = lowJSValue(m_node->child1());
2414         LValue result = vmCall(Int32, m_out.operation(operationArithClz32), m_callFrame, argument);
2415         setInt32(result);
2416     }
2417     
2418     void compileArithMul()
2419     {
2420         switch (m_node->binaryUseKind()) {
2421         case Int32Use: {
2422             LValue left = lowInt32(m_node->child1());
2423             LValue right = lowInt32(m_node->child2());
2424             
2425             LValue result;
2426
2427             if (!shouldCheckOverflow(m_node->arithMode()))
2428                 result = m_out.mul(left, right);
2429             else {
2430                 CheckValue* speculation = m_out.speculateMul(left, right);
2431                 blessSpeculation(speculation, Overflow, noValue(), nullptr, m_origin);
2432                 result = speculation;
2433             }
2434             
2435             if (shouldCheckNegativeZero(m_node->arithMode())) {
2436                 LBasicBlock slowCase = m_out.newBlock();
2437                 LBasicBlock continuation = m_out.newBlock();
2438                 
2439                 m_out.branch(
2440                     m_out.notZero32(result), usually(continuation), rarely(slowCase));
2441                 
2442                 LBasicBlock lastNext = m_out.appendTo(slowCase, continuation);
2443                 speculate(NegativeZero, noValue(), nullptr, m_out.lessThan(left, m_out.int32Zero));
2444                 speculate(NegativeZero, noValue(), nullptr, m_out.lessThan(right, m_out.int32Zero));
2445                 m_out.jump(continuation);
2446                 m_out.appendTo(continuation, lastNext);
2447             }
2448             
2449             setInt32(result);
2450             break;
2451         }
2452             
2453         case Int52RepUse: {
2454             Int52Kind kind;
2455             LValue left = lowWhicheverInt52(m_node->child1(), kind);
2456             LValue right = lowInt52(m_node->child2(), opposite(kind));
2457
2458             CheckValue* result = m_out.speculateMul(left, right);
2459             blessSpeculation(result, Overflow, noValue(), nullptr, m_origin);
2460
2461             if (shouldCheckNegativeZero(m_node->arithMode())) {
2462                 LBasicBlock slowCase = m_out.newBlock();
2463                 LBasicBlock continuation = m_out.newBlock();
2464                 
2465                 m_out.branch(
2466                     m_out.notZero64(result), usually(continuation), rarely(slowCase));
2467                 
2468                 LBasicBlock lastNext = m_out.appendTo(slowCase, continuation);
2469                 speculate(NegativeZero, noValue(), nullptr, m_out.lessThan(left, m_out.int64Zero));
2470                 speculate(NegativeZero, noValue(), nullptr, m_out.lessThan(right, m_out.int64Zero));
2471                 m_out.jump(continuation);
2472                 m_out.appendTo(continuation, lastNext);
2473             }
2474             
2475             setInt52(result);
2476             break;
2477         }
2478             
2479         case DoubleRepUse: {
2480             setDouble(
2481                 m_out.doubleMul(lowDouble(m_node->child1()), lowDouble(m_node->child2())));
2482             break;
2483         }
2484
2485         default:
2486             DFG_CRASH(m_graph, m_node, "Bad use kind");
2487             break;
2488         }
2489     }
2490
2491     void compileValueDiv()
2492     {
2493         if (m_node->isBinaryUseKind(BigIntUse)) {
2494             LValue left = lowBigInt(m_node->child1());
2495             LValue right = lowBigInt(m_node->child2());
2496             
2497             LValue result = vmCall(pointerType(), m_out.operation(operationDivBigInt), m_callFrame, left, right);
2498             setJSValue(result);
2499             return;
2500         }
2501
2502         emitBinarySnippet<JITDivGenerator, NeedScratchFPR>(operationValueDiv);
2503     }
2504
2505     void compileArithDiv()
2506     {
2507         switch (m_node->binaryUseKind()) {
2508         case Int32Use: {
2509             LValue numerator = lowInt32(m_node->child1());
2510             LValue denominator = lowInt32(m_node->child2());
2511
2512             if (shouldCheckNegativeZero(m_node->arithMode())) {
2513                 LBasicBlock zeroNumerator = m_out.newBlock();
2514                 LBasicBlock numeratorContinuation = m_out.newBlock();
2515
2516                 m_out.branch(
2517                     m_out.isZero32(numerator),
2518                     rarely(zeroNumerator), usually(numeratorContinuation));
2519
2520                 LBasicBlock innerLastNext = m_out.appendTo(zeroNumerator, numeratorContinuation);
2521
2522                 speculate(
2523                     NegativeZero, noValue(), 0, m_out.lessThan(denominator, m_out.int32Zero));
2524
2525                 m_out.jump(numeratorContinuation);
2526
2527                 m_out.appendTo(numeratorContinuation, innerLastNext);
2528             }
2529             
2530             if (shouldCheckOverflow(m_node->arithMode())) {
2531                 LBasicBlock unsafeDenominator = m_out.newBlock();
2532                 LBasicBlock continuation = m_out.newBlock();
2533
2534                 LValue adjustedDenominator = m_out.add(denominator, m_out.int32One);
2535                 m_out.branch(
2536                     m_out.above(adjustedDenominator, m_out.int32One),
2537                     usually(continuation), rarely(unsafeDenominator));
2538
2539                 LBasicBlock lastNext = m_out.appendTo(unsafeDenominator, continuation);
2540                 LValue neg2ToThe31 = m_out.constInt32(-2147483647-1);
2541                 speculate(Overflow, noValue(), nullptr, m_out.isZero32(denominator));
2542                 speculate(Overflow, noValue(), nullptr, m_out.equal(numerator, neg2ToThe31));
2543                 m_out.jump(continuation);
2544
2545                 m_out.appendTo(continuation, lastNext);
2546                 LValue result = m_out.div(numerator, denominator);
2547                 speculate(
2548                     Overflow, noValue(), 0,
2549                     m_out.notEqual(m_out.mul(result, denominator), numerator));
2550                 setInt32(result);
2551             } else
2552                 setInt32(m_out.chillDiv(numerator, denominator));
2553
2554             break;
2555         }
2556             
2557         case DoubleRepUse: {
2558             setDouble(m_out.doubleDiv(
2559                 lowDouble(m_node->child1()), lowDouble(m_node->child2())));
2560             break;
2561         }
2562
2563         default:
2564             DFG_CRASH(m_graph, m_node, "Bad use kind");
2565             break;
2566         }
2567     }
2568     
2569     void compileValueMod()
2570     {
2571         if (m_node->binaryUseKind() == BigIntUse) {
2572             LValue left = lowBigInt(m_node->child1());
2573             LValue right = lowBigInt(m_node->child2());
2574
2575             LValue result = vmCall(pointerType(), m_out.operation(operationModBigInt), m_callFrame, left, right);
2576             setJSValue(result);
2577             return;
2578         }
2579
2580         DFG_ASSERT(m_graph, m_node, m_node->binaryUseKind() == UntypedUse, m_node->binaryUseKind());
2581         LValue left = lowJSValue(m_node->child1());
2582         LValue right = lowJSValue(m_node->child2());
2583         LValue result = vmCall(Int64, m_out.operation(operationValueMod), m_callFrame, left, right);
2584         setJSValue(result);
2585     }
2586
2587     void compileArithMod()
2588     {
2589         switch (m_node->binaryUseKind()) {
2590         case Int32Use: {
2591             LValue numerator = lowInt32(m_node->child1());
2592             LValue denominator = lowInt32(m_node->child2());
2593
2594             LValue remainder;
2595             if (shouldCheckOverflow(m_node->arithMode())) {
2596                 LBasicBlock unsafeDenominator = m_out.newBlock();
2597                 LBasicBlock continuation = m_out.newBlock();
2598
2599                 LValue adjustedDenominator = m_out.add(denominator, m_out.int32One);
2600                 m_out.branch(
2601                     m_out.above(adjustedDenominator, m_out.int32One),
2602                     usually(continuation), rarely(unsafeDenominator));
2603
2604                 LBasicBlock lastNext = m_out.appendTo(unsafeDenominator, continuation);
2605                 LValue neg2ToThe31 = m_out.constInt32(-2147483647-1);
2606                 speculate(Overflow, noValue(), nullptr, m_out.isZero32(denominator));
2607                 speculate(Overflow, noValue(), nullptr, m_out.equal(numerator, neg2ToThe31));
2608                 m_out.jump(continuation);
2609
2610                 m_out.appendTo(continuation, lastNext);
2611                 LValue result = m_out.mod(numerator, denominator);
2612                 remainder = result;
2613             } else
2614                 remainder = m_out.chillMod(numerator, denominator);
2615
2616             if (shouldCheckNegativeZero(m_node->arithMode())) {
2617                 LBasicBlock negativeNumerator = m_out.newBlock();
2618                 LBasicBlock numeratorContinuation = m_out.newBlock();
2619
2620                 m_out.branch(
2621                     m_out.lessThan(numerator, m_out.int32Zero),
2622                     unsure(negativeNumerator), unsure(numeratorContinuation));
2623
2624                 LBasicBlock innerLastNext = m_out.appendTo(negativeNumerator, numeratorContinuation);
2625
2626                 speculate(NegativeZero, noValue(), 0, m_out.isZero32(remainder));
2627
2628                 m_out.jump(numeratorContinuation);
2629
2630                 m_out.appendTo(numeratorContinuation, innerLastNext);
2631             }
2632
2633             setInt32(remainder);
2634             break;
2635         }
2636             
2637         case DoubleRepUse: {
2638             setDouble(
2639                 m_out.doubleMod(lowDouble(m_node->child1()), lowDouble(m_node->child2())));
2640             break;
2641         }
2642             
2643         default:
2644             DFG_CRASH(m_graph, m_node, "Bad use kind");
2645             break;
2646         }
2647     }
2648
2649     void compileArithMinOrMax()
2650     {
2651         switch (m_node->binaryUseKind()) {
2652         case Int32Use: {
2653             LValue left = lowInt32(m_node->child1());
2654             LValue right = lowInt32(m_node->child2());
2655             
2656             setInt32(
2657                 m_out.select(
2658                     m_node->op() == ArithMin
2659                         ? m_out.lessThan(left, right)
2660                         : m_out.lessThan(right, left),
2661                     left, right));
2662             break;
2663         }
2664             
2665         case DoubleRepUse: {
2666             LValue left = lowDouble(m_node->child1());
2667             LValue right = lowDouble(m_node->child2());
2668             
2669             LBasicBlock notLessThan = m_out.newBlock();
2670             LBasicBlock continuation = m_out.newBlock();
2671             
2672             Vector<ValueFromBlock, 2> results;
2673             
2674             results.append(m_out.anchor(left));
2675             m_out.branch(
2676                 m_node->op() == ArithMin
2677                     ? m_out.doubleLessThan(left, right)
2678                     : m_out.doubleGreaterThan(left, right),
2679                 unsure(continuation), unsure(notLessThan));
2680             
2681             LBasicBlock lastNext = m_out.appendTo(notLessThan, continuation);
2682             results.append(m_out.anchor(m_out.select(
2683                 m_node->op() == ArithMin
2684                     ? m_out.doubleGreaterThanOrEqual(left, right)
2685                     : m_out.doubleLessThanOrEqual(left, right),
2686                 right, m_out.constDouble(PNaN))));
2687             m_out.jump(continuation);
2688             
2689             m_out.appendTo(continuation, lastNext);
2690             setDouble(m_out.phi(Double, results));
2691             break;
2692         }
2693             
2694         default:
2695             DFG_CRASH(m_graph, m_node, "Bad use kind");
2696             break;
2697         }
2698     }
2699     
2700     void compileArithAbs()
2701     {
2702         switch (m_node->child1().useKind()) {
2703         case Int32Use: {
2704             LValue value = lowInt32(m_node->child1());
2705
2706             LValue mask = m_out.aShr(value, m_out.constInt32(31));
2707             LValue result = m_out.bitXor(mask, m_out.add(mask, value));
2708
2709             if (shouldCheckOverflow(m_node->arithMode()))
2710                 speculate(Overflow, noValue(), 0, m_out.lessThan(result, m_out.int32Zero));
2711
2712             setInt32(result);
2713             break;
2714         }
2715             
2716         case DoubleRepUse: {
2717             setDouble(m_out.doubleAbs(lowDouble(m_node->child1())));
2718             break;
2719         }
2720             
2721         default: {
2722             DFG_ASSERT(m_graph, m_node, m_node->child1().useKind() == UntypedUse, m_node->child1().useKind());
2723             LValue argument = lowJSValue(m_node->child1());
2724             LValue result = vmCall(Double, m_out.operation(operationArithAbs), m_callFrame, argument);
2725             setDouble(result);
2726             break;
2727         }
2728         }
2729     }
2730
2731     void compileArithUnary()
2732     {
2733         if (m_node->child1().useKind() == DoubleRepUse) {
2734             setDouble(m_out.doubleUnary(m_node->arithUnaryType(), lowDouble(m_node->child1())));
2735             return;
2736         }
2737         LValue argument = lowJSValue(m_node->child1());
2738         LValue result = vmCall(Double, m_out.operation(DFG::arithUnaryOperation(m_node->arithUnaryType())), m_callFrame, argument);
2739         setDouble(result);
2740     }
2741
2742     void compileValuePow()
2743     {
2744         if (m_node->isBinaryUseKind(BigIntUse)) {
2745             LValue base = lowBigInt(m_node->child1());
2746             LValue exponent = lowBigInt(m_node->child2());
2747             
2748             LValue result = vmCall(pointerType(), m_out.operation(operationPowBigInt), m_callFrame, base, exponent);
2749             setJSValue(result);
2750             return;
2751         }
2752
2753         LValue base = lowJSValue(m_node->child1());
2754         LValue exponent = lowJSValue(m_node->child2());
2755         LValue result = vmCall(Int64, m_out.operation(operationValuePow), m_callFrame, base, exponent);
2756         setJSValue(result);
2757     }
2758
2759     void compileArithPow()
2760     {
2761         if (m_node->child2().useKind() == Int32Use)
2762             setDouble(m_out.doublePowi(lowDouble(m_node->child1()), lowInt32(m_node->child2())));
2763         else {
2764             LValue base = lowDouble(m_node->child1());
2765             LValue exponent = lowDouble(m_node->child2());
2766
2767             LBasicBlock integerExponentIsSmallBlock = m_out.newBlock();
2768             LBasicBlock integerExponentPowBlock = m_out.newBlock();
2769             LBasicBlock doubleExponentPowBlockEntry = m_out.newBlock();
2770             LBasicBlock nanExceptionBaseIsOne = m_out.newBlock();
2771             LBasicBlock nanExceptionExponentIsInfinity = m_out.newBlock();
2772             LBasicBlock testExponentIsOneHalf = m_out.newBlock();
2773             LBasicBlock handleBaseZeroExponentIsOneHalf = m_out.newBlock();
2774             LBasicBlock handleInfinityForExponentIsOneHalf = m_out.newBlock();
2775             LBasicBlock exponentIsOneHalfNormal = m_out.newBlock();
2776             LBasicBlock exponentIsOneHalfInfinity = m_out.newBlock();
2777             LBasicBlock testExponentIsNegativeOneHalf = m_out.newBlock();
2778             LBasicBlock testBaseZeroExponentIsNegativeOneHalf = m_out.newBlock();
2779             LBasicBlock handleBaseZeroExponentIsNegativeOneHalf = m_out.newBlock();
2780             LBasicBlock handleInfinityForExponentIsNegativeOneHalf = m_out.newBlock();
2781             LBasicBlock exponentIsNegativeOneHalfNormal = m_out.newBlock();
2782             LBasicBlock exponentIsNegativeOneHalfInfinity = m_out.newBlock();
2783             LBasicBlock powBlock = m_out.newBlock();
2784             LBasicBlock nanExceptionResultIsNaN = m_out.newBlock();
2785             LBasicBlock continuation = m_out.newBlock();
2786
2787             LValue integerExponent = m_out.doubleToInt(exponent);
2788             LValue integerExponentConvertedToDouble = m_out.intToDouble(integerExponent);
2789             LValue exponentIsInteger = m_out.doubleEqual(exponent, integerExponentConvertedToDouble);
2790             m_out.branch(exponentIsInteger, unsure(integerExponentIsSmallBlock), unsure(doubleExponentPowBlockEntry));
2791
2792             LBasicBlock lastNext = m_out.appendTo(integerExponentIsSmallBlock, integerExponentPowBlock);
2793             LValue integerExponentBelowMax = m_out.belowOrEqual(integerExponent, m_out.constInt32(maxExponentForIntegerMathPow));
2794             m_out.branch(integerExponentBelowMax, usually(integerExponentPowBlock), rarely(doubleExponentPowBlockEntry));
2795
2796             m_out.appendTo(integerExponentPowBlock, doubleExponentPowBlockEntry);
2797             ValueFromBlock powDoubleIntResult = m_out.anchor(m_out.doublePowi(base, integerExponent));
2798             m_out.jump(continuation);
2799
2800             // If y is NaN, the result is NaN.
2801             m_out.appendTo(doubleExponentPowBlockEntry, nanExceptionBaseIsOne);
2802             LValue exponentIsNaN;
2803             if (provenType(m_node->child2()) & SpecDoubleNaN)
2804                 exponentIsNaN = m_out.doubleNotEqualOrUnordered(exponent, exponent);
2805             else
2806                 exponentIsNaN = m_out.booleanFalse;
2807             m_out.branch(exponentIsNaN, rarely(nanExceptionResultIsNaN), usually(nanExceptionBaseIsOne));
2808
2809             // If abs(x) is 1 and y is +infinity, the result is NaN.
2810             // If abs(x) is 1 and y is -infinity, the result is NaN.
2811
2812             //     Test if base == 1.
2813             m_out.appendTo(nanExceptionBaseIsOne, nanExceptionExponentIsInfinity);
2814             LValue absoluteBase = m_out.doubleAbs(base);
2815             LValue absoluteBaseIsOne = m_out.doubleEqual(absoluteBase, m_out.constDouble(1));
2816             m_out.branch(absoluteBaseIsOne, rarely(nanExceptionExponentIsInfinity), usually(testExponentIsOneHalf));
2817
2818             //     Test if abs(y) == Infinity.
2819             m_out.appendTo(nanExceptionExponentIsInfinity, testExponentIsOneHalf);
2820             LValue absoluteExponent = m_out.doubleAbs(exponent);
2821             LValue absoluteExponentIsInfinity = m_out.doubleEqual(absoluteExponent, m_out.constDouble(std::numeric_limits<double>::infinity()));
2822             m_out.branch(absoluteExponentIsInfinity, rarely(nanExceptionResultIsNaN), usually(testExponentIsOneHalf));
2823
2824             // If y == 0.5 or y == -0.5, handle it through SQRT.
2825             // We have be carefuly with -0 and -Infinity.
2826
2827             //     Test if y == 0.5
2828             m_out.appendTo(testExponentIsOneHalf, handleBaseZeroExponentIsOneHalf);
2829             LValue exponentIsOneHalf = m_out.doubleEqual(exponent, m_out.constDouble(0.5));
2830             m_out.branch(exponentIsOneHalf, rarely(handleBaseZeroExponentIsOneHalf), usually(testExponentIsNegativeOneHalf));
2831
2832             //     Handle x == -0.
2833             m_out.appendTo(handleBaseZeroExponentIsOneHalf, handleInfinityForExponentIsOneHalf);
2834             LValue baseIsZeroExponentIsOneHalf = m_out.doubleEqual(base, m_out.doubleZero);
2835             ValueFromBlock zeroResultExponentIsOneHalf = m_out.anchor(m_out.doubleZero);
2836             m_out.branch(baseIsZeroExponentIsOneHalf, rarely(continuation), usually(handleInfinityForExponentIsOneHalf));
2837
2838             //     Test if abs(x) == Infinity.
2839             m_out.appendTo(handleInfinityForExponentIsOneHalf, exponentIsOneHalfNormal);
2840             LValue absoluteBaseIsInfinityOneHalf = m_out.doubleEqual(absoluteBase, m_out.constDouble(std::numeric_limits<double>::infinity()));
2841             m_out.branch(absoluteBaseIsInfinityOneHalf, rarely(exponentIsOneHalfInfinity), usually(exponentIsOneHalfNormal));
2842
2843             //     The exponent is 0.5, the base is finite or NaN, we can use SQRT.
2844             m_out.appendTo(exponentIsOneHalfNormal, exponentIsOneHalfInfinity);
2845             ValueFromBlock sqrtResult = m_out.anchor(m_out.doubleSqrt(base));
2846             m_out.jump(continuation);
2847
2848             //     The exponent is 0.5, the base is infinite, the result is always infinite.
2849             m_out.appendTo(exponentIsOneHalfInfinity, testExponentIsNegativeOneHalf);
2850             ValueFromBlock sqrtInfinityResult = m_out.anchor(m_out.constDouble(std::numeric_limits<double>::infinity()));
2851             m_out.jump(continuation);
2852
2853             //     Test if y == -0.5
2854             m_out.appendTo(testExponentIsNegativeOneHalf, testBaseZeroExponentIsNegativeOneHalf);
2855             LValue exponentIsNegativeOneHalf = m_out.doubleEqual(exponent, m_out.constDouble(-0.5));
2856             m_out.branch(exponentIsNegativeOneHalf, rarely(testBaseZeroExponentIsNegativeOneHalf), usually(powBlock));
2857
2858             //     Handle x == -0.
2859             m_out.appendTo(testBaseZeroExponentIsNegativeOneHalf, handleBaseZeroExponentIsNegativeOneHalf);
2860             LValue baseIsZeroExponentIsNegativeOneHalf = m_out.doubleEqual(base, m_out.doubleZero);
2861             m_out.branch(baseIsZeroExponentIsNegativeOneHalf, rarely(handleBaseZeroExponentIsNegativeOneHalf), usually(handleInfinityForExponentIsNegativeOneHalf));
2862
2863             m_out.appendTo(handleBaseZeroExponentIsNegativeOneHalf, handleInfinityForExponentIsNegativeOneHalf);
2864             ValueFromBlock oneOverSqrtZeroResult = m_out.anchor(m_out.constDouble(std::numeric_limits<double>::infinity()));
2865             m_out.jump(continuation);
2866
2867             //     Test if abs(x) == Infinity.
2868             m_out.appendTo(handleInfinityForExponentIsNegativeOneHalf, exponentIsNegativeOneHalfNormal);
2869             LValue absoluteBaseIsInfinityNegativeOneHalf = m_out.doubleEqual(absoluteBase, m_out.constDouble(std::numeric_limits<double>::infinity()));
2870             m_out.branch(absoluteBaseIsInfinityNegativeOneHalf, rarely(exponentIsNegativeOneHalfInfinity), usually(exponentIsNegativeOneHalfNormal));
2871
2872             //     The exponent is -0.5, the base is finite or NaN, we can use 1/SQRT.
2873             m_out.appendTo(exponentIsNegativeOneHalfNormal, exponentIsNegativeOneHalfInfinity);
2874             LValue sqrtBase = m_out.doubleSqrt(base);
2875             ValueFromBlock oneOverSqrtResult = m_out.anchor(m_out.div(m_out.constDouble(1.), sqrtBase));
2876             m_out.jump(continuation);
2877
2878             //     The exponent is -0.5, the base is infinite, the result is always zero.
2879             m_out.appendTo(exponentIsNegativeOneHalfInfinity, powBlock);
2880             ValueFromBlock oneOverSqrtInfinityResult = m_out.anchor(m_out.doubleZero);
2881             m_out.jump(continuation);
2882
2883             m_out.appendTo(powBlock, nanExceptionResultIsNaN);
2884             ValueFromBlock powResult = m_out.anchor(m_out.doublePow(base, exponent));
2885             m_out.jump(continuation);
2886
2887             m_out.appendTo(nanExceptionResultIsNaN, continuation);
2888             ValueFromBlock pureNan = m_out.anchor(m_out.constDouble(PNaN));
2889             m_out.jump(continuation);
2890
2891             m_out.appendTo(continuation, lastNext);
2892             setDouble(m_out.phi(Double, powDoubleIntResult, zeroResultExponentIsOneHalf, sqrtResult, sqrtInfinityResult, oneOverSqrtZeroResult, oneOverSqrtResult, oneOverSqrtInfinityResult, powResult, pureNan));
2893         }
2894     }
2895
2896     void compileArithRandom()
2897     {
2898         JSGlobalObject* globalObject = m_graph.globalObjectFor(m_node->origin.semantic);
2899
2900         // Inlined WeakRandom::advance().
2901         // uint64_t x = m_low;
2902         void* lowAddress = reinterpret_cast<uint8_t*>(globalObject) + JSGlobalObject::weakRandomOffset() + WeakRandom::lowOffset();
2903         LValue low = m_out.load64(m_out.absolute(lowAddress));
2904         // uint64_t y = m_high;
2905         void* highAddress = reinterpret_cast<uint8_t*>(globalObject) + JSGlobalObject::weakRandomOffset() + WeakRandom::highOffset();
2906         LValue high = m_out.load64(m_out.absolute(highAddress));
2907         // m_low = y;
2908         m_out.store64(high, m_out.absolute(lowAddress));
2909
2910         // x ^= x << 23;
2911         LValue phase1 = m_out.bitXor(m_out.shl(low, m_out.constInt64(23)), low);
2912
2913         // x ^= x >> 17;
2914         LValue phase2 = m_out.bitXor(m_out.lShr(phase1, m_out.constInt64(17)), phase1);
2915
2916         // x ^= y ^ (y >> 26);
2917         LValue phase3 = m_out.bitXor(m_out.bitXor(high, m_out.lShr(high, m_out.constInt64(26))), phase2);
2918
2919         // m_high = x;
2920         m_out.store64(phase3, m_out.absolute(highAddress));
2921
2922         // return x + y;
2923         LValue random64 = m_out.add(phase3, high);
2924
2925         // Extract random 53bit. [0, 53] bit is safe integer number ranges in double representation.
2926         LValue random53 = m_out.bitAnd(random64, m_out.constInt64((1ULL << 53) - 1));
2927
2928         LValue double53Integer = m_out.intToDouble(random53);
2929
2930         // Convert `(53bit double integer value) / (1 << 53)` to `(53bit double integer value) * (1.0 / (1 << 53))`.
2931         // In latter case, `1.0 / (1 << 53)` will become a double value represented as (mantissa = 0 & exp = 970, it means 1e-(2**54)).
2932         static constexpr double scale = 1.0 / (1ULL << 53);
2933
2934         // Multiplying 1e-(2**54) with the double integer does not change anything of the mantissa part of the double integer.
2935         // It just reduces the exp part of the given 53bit double integer.
2936         // (Except for 0.0. This is specially handled and in this case, exp just becomes 0.)
2937         // Now we get 53bit precision random double value in [0, 1).
2938         LValue result = m_out.doubleMul(double53Integer, m_out.constDouble(scale));
2939
2940         setDouble(result);
2941     }
2942
2943     void compileArithRound()
2944     {
2945         if (m_node->child1().useKind() == DoubleRepUse) {
2946             LValue result = nullptr;
2947             if (producesInteger(m_node->arithRoundingMode()) && !shouldCheckNegativeZero(m_node->arithRoundingMode())) {
2948                 LValue value = lowDouble(m_node->child1());
2949                 result = m_out.doubleFloor(m_out.doubleAdd(value, m_out.constDouble(0.5)));
2950             } else {
2951                 LBasicBlock shouldRoundDown = m_out.newBlock();
2952                 LBasicBlock continuation = m_out.newBlock();
2953
2954                 LValue value = lowDouble(m_node->child1());
2955                 LValue integerValue = m_out.doubleCeil(value);
2956                 ValueFromBlock integerValueResult = m_out.anchor(integerValue);
2957
2958                 LValue ceilMinusHalf = m_out.doubleSub(integerValue, m_out.constDouble(0.5));
2959                 m_out.branch(m_out.doubleGreaterThanOrUnordered(ceilMinusHalf, value), unsure(shouldRoundDown), unsure(continuation));
2960
2961                 LBasicBlock lastNext = m_out.appendTo(shouldRoundDown, continuation);
2962                 LValue integerValueRoundedDown = m_out.doubleSub(integerValue, m_out.constDouble(1));
2963                 ValueFromBlock integerValueRoundedDownResult = m_out.anchor(integerValueRoundedDown);
2964                 m_out.jump(continuation);
2965                 m_out.appendTo(continuation, lastNext);
2966
2967                 result = m_out.phi(Double, integerValueResult, integerValueRoundedDownResult);
2968             }
2969
2970             if (producesInteger(m_node->arithRoundingMode())) {
2971                 LValue integerValue = convertDoubleToInt32(result, shouldCheckNegativeZero(m_node->arithRoundingMode()));
2972                 setInt32(integerValue);
2973             } else
2974                 setDouble(result);
2975             return;
2976         }
2977
2978         DFG_ASSERT(m_graph, m_node, m_node->child1().useKind() == UntypedUse, m_node->child1().useKind());
2979         LValue argument = lowJSValue(m_node->child1());
2980         setJSValue(vmCall(Int64, m_out.operation(operationArithRound), m_callFrame, argument));
2981     }
2982
2983     void compileArithFloor()
2984     {
2985         if (m_node->child1().useKind() == DoubleRepUse) {
2986             LValue value = lowDouble(m_node->child1());
2987             LValue integerValue = m_out.doubleFloor(value);
2988             if (producesInteger(m_node->arithRoundingMode()))
2989                 setInt32(convertDoubleToInt32(integerValue, shouldCheckNegativeZero(m_node->arithRoundingMode())));
2990             else
2991                 setDouble(integerValue);
2992             return;
2993         }
2994         DFG_ASSERT(m_graph, m_node, m_node->child1().useKind() == UntypedUse, m_node->child1().useKind());
2995         LValue argument = lowJSValue(m_node->child1());
2996         setJSValue(vmCall(Int64, m_out.operation(operationArithFloor), m_callFrame, argument));
2997     }
2998
2999     void compileArithCeil()
3000     {
3001         if (m_node->child1().useKind() == DoubleRepUse) {
3002             LValue value = lowDouble(m_node->child1());
3003             LValue integerValue = m_out.doubleCeil(value);
3004             if (producesInteger(m_node->arithRoundingMode()))
3005                 setInt32(convertDoubleToInt32(integerValue, shouldCheckNegativeZero(m_node->arithRoundingMode())));
3006             else
3007                 setDouble(integerValue);
3008             return;
3009         }
3010         DFG_ASSERT(m_graph, m_node, m_node->child1().useKind() == UntypedUse, m_node->child1().useKind());
3011         LValue argument = lowJSValue(m_node->child1());
3012         setJSValue(vmCall(Int64, m_out.operation(operationArithCeil), m_callFrame, argument));
3013     }
3014
3015     void compileArithTrunc()
3016     {
3017         if (m_node->child1().useKind() == DoubleRepUse) {
3018             LValue value = lowDouble(m_node->child1());
3019             LValue result = m_out.doubleTrunc(value);
3020             if (producesInteger(m_node->arithRoundingMode()))
3021                 setInt32(convertDoubleToInt32(result, shouldCheckNegativeZero(m_node->arithRoundingMode())));
3022             else
3023                 setDouble(result);
3024             return;
3025         }
3026         DFG_ASSERT(m_graph, m_node, m_node->child1().useKind() == UntypedUse, m_node->child1().useKind());
3027         LValue argument = lowJSValue(m_node->child1());
3028         setJSValue(vmCall(Int64, m_out.operation(operationArithTrunc), m_callFrame, argument));
3029     }
3030
3031     void compileArithSqrt()
3032     {
3033         if (m_node->child1().useKind() == DoubleRepUse) {
3034             setDouble(m_out.doubleSqrt(lowDouble(m_node->child1())));
3035             return;
3036         }
3037         LValue argument = lowJSValue(m_node->child1());
3038         LValue result = vmCall(Double, m_out.operation(operationArithSqrt), m_callFrame, argument);
3039         setDouble(result);
3040     }
3041
3042     void compileArithFRound()
3043     {
3044         if (m_node->child1().useKind() == DoubleRepUse) {
3045             setDouble(m_out.fround(lowDouble(m_node->child1())));
3046             return;
3047         }
3048         LValue argument = lowJSValue(m_node->child1());
3049         LValue result = vmCall(Double, m_out.operation(operationArithFRound), m_callFrame, argument);
3050         setDouble(result);
3051     }
3052
3053     void compileValueNegate()
3054     {
3055         DFG_ASSERT(m_graph, m_node, m_node->child1().useKind() == UntypedUse);
3056         CodeBlock* baselineCodeBlock = m_ftlState.graph.baselineCodeBlockFor(m_node->origin.semantic);
3057         unsigned bytecodeIndex = m_node->origin.semantic.bytecodeIndex();
3058         ArithProfile* arithProfile = baselineCodeBlock->arithProfileForBytecodeOffset(bytecodeIndex);
3059         auto repatchingFunction = operationArithNegateOptimize;
3060         auto nonRepatchingFunction = operationArithNegate;
3061         compileUnaryMathIC<JITNegGenerator>(arithProfile, repatchingFunction, nonRepatchingFunction);
3062     }
3063
3064     void compileArithNegate()
3065     {
3066         switch (m_node->child1().useKind()) {
3067         case Int32Use: {
3068             LValue value = lowInt32(m_node->child1());
3069             
3070             LValue result;
3071             if (!shouldCheckOverflow(m_node->arithMode()))
3072                 result = m_out.neg(value);
3073             else if (!shouldCheckNegativeZero(m_node->arithMode())) {
3074                 CheckValue* check = m_out.speculateSub(m_out.int32Zero, value);
3075                 blessSpeculation(check, Overflow, noValue(), nullptr, m_origin);
3076                 result = check;
3077             } else {
3078                 speculate(Overflow, noValue(), 0, m_out.testIsZero32(value, m_out.constInt32(0x7fffffff)));
3079                 result = m_out.neg(value);
3080             }
3081
3082             setInt32(result);
3083             break;
3084         }
3085             
3086         case Int52RepUse: {
3087             if (!abstractValue(m_node->child1()).couldBeType(SpecNonInt32AsInt52)) {
3088                 Int52Kind kind;
3089                 LValue value = lowWhicheverInt52(m_node->child1(), kind);
3090                 LValue result = m_out.neg(value);
3091                 if (shouldCheckNegativeZero(m_node->arithMode()))
3092                     speculate(NegativeZero, noValue(), 0, m_out.isZero64(result));
3093                 setInt52(result, kind);
3094                 break;
3095             }
3096             
3097             LValue value = lowInt52(m_node->child1());
3098             CheckValue* result = m_out.speculateSub(m_out.int64Zero, value);
3099             blessSpeculation(result, Int52Overflow, noValue(), nullptr, m_origin);
3100             if (shouldCheckNegativeZero(m_node->arithMode()))
3101                 speculate(NegativeZero, noValue(), 0, m_out.isZero64(result));
3102             setInt52(result);
3103             break;
3104         }
3105             
3106         case DoubleRepUse: {
3107             setDouble(m_out.doubleNeg(lowDouble(m_node->child1())));
3108             break;
3109         }
3110             
3111         default:
3112             DFG_CRASH(m_graph, m_node, "Bad use kind");
3113             break;
3114         }
3115     }
3116     
3117     void compileValueBitNot()
3118     {
3119         if (m_node->child1().useKind() == BigIntUse) {
3120             LValue operand = lowBigInt(m_node->child1());
3121             LValue result = vmCall(pointerType(), m_out.operation(operationBitNotBigInt), m_callFrame, operand);
3122             setJSValue(result);
3123             return;
3124         }
3125
3126         LValue operand = lowJSValue(m_node->child1());
3127         LValue result = vmCall(Int64, m_out.operation(operationValueBitNot), m_callFrame, operand);
3128         setJSValue(result);
3129     }
3130
3131     void compileArithBitNot()
3132     {
3133         setInt32(m_out.bitNot(lowInt32(m_node->child1())));
3134     }
3135
3136    &