[WTF] Add makeUnique<T>, which ensures T is fast-allocated, makeUnique / makeUniqueWi...
[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 NewStringObject:
1049             compileNewStringObject();
1050             break;
1051         case NewSymbol:
1052             compileNewSymbol();
1053             break;
1054         case NewArray:
1055             compileNewArray();
1056             break;
1057         case NewArrayWithSpread:
1058             compileNewArrayWithSpread();
1059             break;
1060         case CreateThis:
1061             compileCreateThis();
1062             break;
1063         case Spread:
1064             compileSpread();
1065             break;
1066         case NewArrayBuffer:
1067             compileNewArrayBuffer();
1068             break;
1069         case NewArrayWithSize:
1070             compileNewArrayWithSize();
1071             break;
1072         case NewTypedArray:
1073             compileNewTypedArray();
1074             break;
1075         case GetTypedArrayByteOffset:
1076             compileGetTypedArrayByteOffset();
1077             break;
1078         case GetPrototypeOf:
1079             compileGetPrototypeOf();
1080             break;
1081         case AllocatePropertyStorage:
1082             compileAllocatePropertyStorage();
1083             break;
1084         case ReallocatePropertyStorage:
1085             compileReallocatePropertyStorage();
1086             break;
1087         case NukeStructureAndSetButterfly:
1088             compileNukeStructureAndSetButterfly();
1089             break;
1090         case ToNumber:
1091             compileToNumber();
1092             break;
1093         case ToString:
1094         case CallStringConstructor:
1095         case StringValueOf:
1096             compileToStringOrCallStringConstructorOrStringValueOf();
1097             break;
1098         case ToPrimitive:
1099             compileToPrimitive();
1100             break;
1101         case MakeRope:
1102             compileMakeRope();
1103             break;
1104         case StringCharAt:
1105             compileStringCharAt();
1106             break;
1107         case StringCharCodeAt:
1108             compileStringCharCodeAt();
1109             break;
1110         case StringFromCharCode:
1111             compileStringFromCharCode();
1112             break;
1113         case GetByOffset:
1114         case GetGetterSetterByOffset:
1115             compileGetByOffset();
1116             break;
1117         case GetGetter:
1118             compileGetGetter();
1119             break;
1120         case GetSetter:
1121             compileGetSetter();
1122             break;
1123         case MultiGetByOffset:
1124             compileMultiGetByOffset();
1125             break;
1126         case PutByOffset:
1127             compilePutByOffset();
1128             break;
1129         case MultiPutByOffset:
1130             compileMultiPutByOffset();
1131             break;
1132         case MatchStructure:
1133             compileMatchStructure();
1134             break;
1135         case GetGlobalVar:
1136         case GetGlobalLexicalVariable:
1137             compileGetGlobalVariable();
1138             break;
1139         case PutGlobalVariable:
1140             compilePutGlobalVariable();
1141             break;
1142         case NotifyWrite:
1143             compileNotifyWrite();
1144             break;
1145         case GetCallee:
1146             compileGetCallee();
1147             break;
1148         case SetCallee:
1149             compileSetCallee();
1150             break;
1151         case GetArgumentCountIncludingThis:
1152             compileGetArgumentCountIncludingThis();
1153             break;
1154         case SetArgumentCountIncludingThis:
1155             compileSetArgumentCountIncludingThis();
1156             break;
1157         case GetScope:
1158             compileGetScope();
1159             break;
1160         case SkipScope:
1161             compileSkipScope();
1162             break;
1163         case GetGlobalObject:
1164             compileGetGlobalObject();
1165             break;
1166         case GetGlobalThis:
1167             compileGetGlobalThis();
1168             break;
1169         case GetClosureVar:
1170             compileGetClosureVar();
1171             break;
1172         case PutClosureVar:
1173             compilePutClosureVar();
1174             break;
1175         case GetFromArguments:
1176             compileGetFromArguments();
1177             break;
1178         case PutToArguments:
1179             compilePutToArguments();
1180             break;
1181         case GetArgument:
1182             compileGetArgument();
1183             break;
1184         case CompareEq:
1185             compileCompareEq();
1186             break;
1187         case CompareStrictEq:
1188             compileCompareStrictEq();
1189             break;
1190         case CompareLess:
1191             compileCompareLess();
1192             break;
1193         case CompareLessEq:
1194             compileCompareLessEq();
1195             break;
1196         case CompareGreater:
1197             compileCompareGreater();
1198             break;
1199         case CompareGreaterEq:
1200             compileCompareGreaterEq();
1201             break;
1202         case CompareBelow:
1203             compileCompareBelow();
1204             break;
1205         case CompareBelowEq:
1206             compileCompareBelowEq();
1207             break;
1208         case CompareEqPtr:
1209             compileCompareEqPtr();
1210             break;
1211         case SameValue:
1212             compileSameValue();
1213             break;
1214         case LogicalNot:
1215             compileLogicalNot();
1216             break;
1217         case Call:
1218         case TailCallInlinedCaller:
1219         case Construct:
1220             compileCallOrConstruct();
1221             break;
1222         case DirectCall:
1223         case DirectTailCallInlinedCaller:
1224         case DirectConstruct:
1225         case DirectTailCall:
1226             compileDirectCallOrConstruct();
1227             break;
1228         case TailCall:
1229             compileTailCall();
1230             break;
1231         case CallVarargs:
1232         case CallForwardVarargs:
1233         case TailCallVarargs:
1234         case TailCallVarargsInlinedCaller:
1235         case TailCallForwardVarargs:
1236         case TailCallForwardVarargsInlinedCaller:
1237         case ConstructVarargs:
1238         case ConstructForwardVarargs:
1239             compileCallOrConstructVarargs();
1240             break;
1241         case CallEval:
1242             compileCallEval();
1243             break;
1244         case LoadVarargs:
1245             compileLoadVarargs();
1246             break;
1247         case ForwardVarargs:
1248             compileForwardVarargs();
1249             break;
1250         case DFG::Jump:
1251             compileJump();
1252             break;
1253         case DFG::Branch:
1254             compileBranch();
1255             break;
1256         case DFG::Switch:
1257             compileSwitch();
1258             break;
1259         case DFG::EntrySwitch:
1260             compileEntrySwitch();
1261             break;
1262         case DFG::Return:
1263             compileReturn();
1264             break;
1265         case ForceOSRExit:
1266             compileForceOSRExit();
1267             break;
1268         case CPUIntrinsic:
1269 #if CPU(X86_64)
1270             compileCPUIntrinsic();
1271 #else
1272             RELEASE_ASSERT_NOT_REACHED();
1273 #endif
1274             break;
1275         case Throw:
1276             compileThrow();
1277             break;
1278         case ThrowStaticError:
1279             compileThrowStaticError();
1280             break;
1281         case InvalidationPoint:
1282             compileInvalidationPoint();
1283             break;
1284         case IsEmpty:
1285             compileIsEmpty();
1286             break;
1287         case IsUndefined:
1288             compileIsUndefined();
1289             break;
1290         case IsUndefinedOrNull:
1291             compileIsUndefinedOrNull();
1292             break;
1293         case IsBoolean:
1294             compileIsBoolean();
1295             break;
1296         case IsNumber:
1297             compileIsNumber();
1298             break;
1299         case NumberIsInteger:
1300             compileNumberIsInteger();
1301             break;
1302         case IsCellWithType:
1303             compileIsCellWithType();
1304             break;
1305         case MapHash:
1306             compileMapHash();
1307             break;
1308         case NormalizeMapKey:
1309             compileNormalizeMapKey();
1310             break;
1311         case GetMapBucket:
1312             compileGetMapBucket();
1313             break;
1314         case GetMapBucketHead:
1315             compileGetMapBucketHead();
1316             break;
1317         case GetMapBucketNext:
1318             compileGetMapBucketNext();
1319             break;
1320         case LoadKeyFromMapBucket:
1321             compileLoadKeyFromMapBucket();
1322             break;
1323         case LoadValueFromMapBucket:
1324             compileLoadValueFromMapBucket();
1325             break;
1326         case ExtractValueFromWeakMapGet:
1327             compileExtractValueFromWeakMapGet();
1328             break;
1329         case SetAdd:
1330             compileSetAdd();
1331             break;
1332         case MapSet:
1333             compileMapSet();
1334             break;
1335         case WeakMapGet:
1336             compileWeakMapGet();
1337             break;
1338         case WeakSetAdd:
1339             compileWeakSetAdd();
1340             break;
1341         case WeakMapSet:
1342             compileWeakMapSet();
1343             break;
1344         case IsObject:
1345             compileIsObject();
1346             break;
1347         case IsObjectOrNull:
1348             compileIsObjectOrNull();
1349             break;
1350         case IsFunction:
1351             compileIsFunction();
1352             break;
1353         case IsTypedArrayView:
1354             compileIsTypedArrayView();
1355             break;
1356         case ParseInt:
1357             compileParseInt();
1358             break;
1359         case TypeOf:
1360             compileTypeOf();
1361             break;
1362         case CheckTypeInfoFlags:
1363             compileCheckTypeInfoFlags();
1364             break;
1365         case OverridesHasInstance:
1366             compileOverridesHasInstance();
1367             break;
1368         case InstanceOf:
1369             compileInstanceOf();
1370             break;
1371         case InstanceOfCustom:
1372             compileInstanceOfCustom();
1373             break;
1374         case CountExecution:
1375             compileCountExecution();
1376             break;
1377         case SuperSamplerBegin:
1378             compileSuperSamplerBegin();
1379             break;
1380         case SuperSamplerEnd:
1381             compileSuperSamplerEnd();
1382             break;
1383         case StoreBarrier:
1384         case FencedStoreBarrier:
1385             compileStoreBarrier();
1386             break;
1387         case HasIndexedProperty:
1388             compileHasIndexedProperty();
1389             break;
1390         case HasGenericProperty:
1391             compileHasGenericProperty();
1392             break;
1393         case HasStructureProperty:
1394             compileHasStructureProperty();
1395             break;
1396         case GetDirectPname:
1397             compileGetDirectPname();
1398             break;
1399         case GetEnumerableLength:
1400             compileGetEnumerableLength();
1401             break;
1402         case GetPropertyEnumerator:
1403             compileGetPropertyEnumerator();
1404             break;
1405         case GetEnumeratorStructurePname:
1406             compileGetEnumeratorStructurePname();
1407             break;
1408         case GetEnumeratorGenericPname:
1409             compileGetEnumeratorGenericPname();
1410             break;
1411         case ToIndexString:
1412             compileToIndexString();
1413             break;
1414         case CheckStructureImmediate:
1415             compileCheckStructureImmediate();
1416             break;
1417         case MaterializeNewObject:
1418             compileMaterializeNewObject();
1419             break;
1420         case MaterializeCreateActivation:
1421             compileMaterializeCreateActivation();
1422             break;
1423         case CheckTraps:
1424             compileCheckTraps();
1425             break;
1426         case CreateRest:
1427             compileCreateRest();
1428             break;
1429         case GetRestLength:
1430             compileGetRestLength();
1431             break;
1432         case RegExpExec:
1433             compileRegExpExec();
1434             break;
1435         case RegExpExecNonGlobalOrSticky:
1436             compileRegExpExecNonGlobalOrSticky();
1437             break;
1438         case RegExpTest:
1439             compileRegExpTest();
1440             break;
1441         case RegExpMatchFast:
1442             compileRegExpMatchFast();
1443             break;
1444         case RegExpMatchFastGlobal:
1445             compileRegExpMatchFastGlobal();
1446             break;
1447         case NewRegexp:
1448             compileNewRegexp();
1449             break;
1450         case SetFunctionName:
1451             compileSetFunctionName();
1452             break;
1453         case StringReplace:
1454         case StringReplaceRegExp:
1455             compileStringReplace();
1456             break;
1457         case GetRegExpObjectLastIndex:
1458             compileGetRegExpObjectLastIndex();
1459             break;
1460         case SetRegExpObjectLastIndex:
1461             compileSetRegExpObjectLastIndex();
1462             break;
1463         case LogShadowChickenPrologue:
1464             compileLogShadowChickenPrologue();
1465             break;
1466         case LogShadowChickenTail:
1467             compileLogShadowChickenTail();
1468             break;
1469         case RecordRegExpCachedResult:
1470             compileRecordRegExpCachedResult();
1471             break;
1472         case ResolveScopeForHoistingFuncDeclInEval:
1473             compileResolveScopeForHoistingFuncDeclInEval();
1474             break;
1475         case ResolveScope:
1476             compileResolveScope();
1477             break;
1478         case GetDynamicVar:
1479             compileGetDynamicVar();
1480             break;
1481         case PutDynamicVar:
1482             compilePutDynamicVar();
1483             break;
1484         case Unreachable:
1485             compileUnreachable();
1486             break;
1487         case StringSlice:
1488             compileStringSlice();
1489             break;
1490         case ToLowerCase:
1491             compileToLowerCase();
1492             break;
1493         case NumberToStringWithRadix:
1494             compileNumberToStringWithRadix();
1495             break;
1496         case NumberToStringWithValidRadixConstant:
1497             compileNumberToStringWithValidRadixConstant();
1498             break;
1499         case CheckSubClass:
1500             compileCheckSubClass();
1501             break;
1502         case CallDOM:
1503             compileCallDOM();
1504             break;
1505         case CallDOMGetter:
1506             compileCallDOMGetter();
1507             break;
1508         case FilterCallLinkStatus:
1509         case FilterGetByIdStatus:
1510         case FilterPutByIdStatus:
1511         case FilterInByIdStatus:
1512             compileFilterICStatus();
1513             break;
1514         case DataViewGetInt:
1515         case DataViewGetFloat:
1516             compileDataViewGet();
1517             break;
1518         case DataViewSet:
1519             compileDataViewSet();
1520             break;
1521
1522         case PhantomLocal:
1523         case LoopHint:
1524         case MovHint:
1525         case ZombieHint:
1526         case ExitOK:
1527         case PhantomNewObject:
1528         case PhantomNewFunction:
1529         case PhantomNewGeneratorFunction:
1530         case PhantomNewAsyncGeneratorFunction:
1531         case PhantomNewAsyncFunction:
1532         case PhantomCreateActivation:
1533         case PhantomDirectArguments:
1534         case PhantomCreateRest:
1535         case PhantomSpread:
1536         case PhantomNewArrayWithSpread:
1537         case PhantomNewArrayBuffer:
1538         case PhantomClonedArguments:
1539         case PhantomNewRegexp:
1540         case PutHint:
1541         case BottomValue:
1542         case KillStack:
1543         case InitializeEntrypointArguments:
1544             break;
1545         default:
1546             DFG_CRASH(m_graph, m_node, "Unrecognized node in FTL backend");
1547             break;
1548         }
1549         
1550         if (m_node->isTerminal())
1551             return false;
1552         
1553         if (!m_state.isValid()) {
1554             safelyInvalidateAfterTermination();
1555             return false;
1556         }
1557
1558         m_availabilityCalculator.executeNode(m_node);
1559         m_interpreter.executeEffects(nodeIndex);
1560         
1561         return true;
1562     }
1563
1564     void compileUpsilon()
1565     {
1566         LValue upsilonValue = nullptr;
1567         switch (m_node->child1().useKind()) {
1568         case DoubleRepUse:
1569             upsilonValue = lowDouble(m_node->child1());
1570             break;
1571         case Int32Use:
1572         case KnownInt32Use:
1573             upsilonValue = lowInt32(m_node->child1());
1574             break;
1575         case Int52RepUse:
1576             upsilonValue = lowInt52(m_node->child1());
1577             break;
1578         case BooleanUse:
1579         case KnownBooleanUse:
1580             upsilonValue = lowBoolean(m_node->child1());
1581             break;
1582         case CellUse:
1583         case KnownCellUse:
1584             upsilonValue = lowCell(m_node->child1());
1585             break;
1586         case UntypedUse:
1587             upsilonValue = lowJSValue(m_node->child1());
1588             break;
1589         default:
1590             DFG_CRASH(m_graph, m_node, "Bad use kind");
1591             break;
1592         }
1593         ValueFromBlock upsilon = m_out.anchor(upsilonValue);
1594         LValue phiNode = m_phis.get(m_node->phi());
1595         m_out.addIncomingToPhi(phiNode, upsilon);
1596     }
1597     
1598     void compilePhi()
1599     {
1600         LValue phi = m_phis.get(m_node);
1601         m_out.m_block->append(phi);
1602
1603         switch (m_node->flags() & NodeResultMask) {
1604         case NodeResultDouble:
1605             setDouble(phi);
1606             break;
1607         case NodeResultInt32:
1608             setInt32(phi);
1609             break;
1610         case NodeResultInt52:
1611             setInt52(phi);
1612             break;
1613         case NodeResultBoolean:
1614             setBoolean(phi);
1615             break;
1616         case NodeResultJS:
1617             setJSValue(phi);
1618             break;
1619         default:
1620             DFG_CRASH(m_graph, m_node, "Bad result type");
1621             break;
1622         }
1623     }
1624     
1625     void compileDoubleConstant()
1626     {
1627         setDouble(m_out.constDouble(m_node->asNumber()));
1628     }
1629     
1630     void compileInt52Constant()
1631     {
1632         int64_t value = m_node->asAnyInt();
1633         
1634         setInt52(m_out.constInt64(value << JSValue::int52ShiftAmount));
1635         setStrictInt52(m_out.constInt64(value));
1636     }
1637
1638     void compileLazyJSConstant()
1639     {
1640         PatchpointValue* patchpoint = m_out.patchpoint(Int64);
1641         LazyJSValue value = m_node->lazyJSValue();
1642         patchpoint->setGenerator(
1643             [=] (CCallHelpers& jit, const StackmapGenerationParams& params) {
1644                 value.emit(jit, JSValueRegs(params[0].gpr()));
1645             });
1646         patchpoint->effects = Effects::none();
1647         setJSValue(patchpoint);
1648     }
1649
1650     void compileDoubleRep()
1651     {
1652         switch (m_node->child1().useKind()) {
1653         case RealNumberUse: {
1654             LValue value = lowJSValue(m_node->child1(), ManualOperandSpeculation);
1655             
1656             LValue doubleValue = unboxDouble(value);
1657             
1658             LBasicBlock intCase = m_out.newBlock();
1659             LBasicBlock continuation = m_out.newBlock();
1660             
1661             ValueFromBlock fastResult = m_out.anchor(doubleValue);
1662             m_out.branch(
1663                 m_out.doubleEqual(doubleValue, doubleValue),
1664                 usually(continuation), rarely(intCase));
1665             
1666             LBasicBlock lastNext = m_out.appendTo(intCase, continuation);
1667
1668             FTL_TYPE_CHECK(
1669                 jsValueValue(value), m_node->child1(), SpecBytecodeRealNumber,
1670                 isNotInt32(value, provenType(m_node->child1()) & ~SpecDoubleReal));
1671             ValueFromBlock slowResult = m_out.anchor(m_out.intToDouble(unboxInt32(value)));
1672             m_out.jump(continuation);
1673             
1674             m_out.appendTo(continuation, lastNext);
1675             
1676             setDouble(m_out.phi(Double, fastResult, slowResult));
1677             return;
1678         }
1679             
1680         case NotCellUse:
1681         case NumberUse: {
1682             bool shouldConvertNonNumber = m_node->child1().useKind() == NotCellUse;
1683             
1684             LValue value = lowJSValue(m_node->child1(), ManualOperandSpeculation);
1685
1686             LBasicBlock intCase = m_out.newBlock();
1687             LBasicBlock doubleTesting = m_out.newBlock();
1688             LBasicBlock doubleCase = m_out.newBlock();
1689             LBasicBlock nonDoubleCase = m_out.newBlock();
1690             LBasicBlock continuation = m_out.newBlock();
1691             
1692             m_out.branch(
1693                 isNotInt32(value, provenType(m_node->child1())),
1694                 unsure(doubleTesting), unsure(intCase));
1695             
1696             LBasicBlock lastNext = m_out.appendTo(intCase, doubleTesting);
1697             
1698             ValueFromBlock intToDouble = m_out.anchor(
1699                 m_out.intToDouble(unboxInt32(value)));
1700             m_out.jump(continuation);
1701             
1702             m_out.appendTo(doubleTesting, doubleCase);
1703             LValue valueIsNumber = isNumber(value, provenType(m_node->child1()));
1704             m_out.branch(valueIsNumber, usually(doubleCase), rarely(nonDoubleCase));
1705
1706             m_out.appendTo(doubleCase, nonDoubleCase);
1707             ValueFromBlock unboxedDouble = m_out.anchor(unboxDouble(value));
1708             m_out.jump(continuation);
1709
1710             if (shouldConvertNonNumber) {
1711                 LBasicBlock undefinedCase = m_out.newBlock();
1712                 LBasicBlock testNullCase = m_out.newBlock();
1713                 LBasicBlock nullCase = m_out.newBlock();
1714                 LBasicBlock testBooleanTrueCase = m_out.newBlock();
1715                 LBasicBlock convertBooleanTrueCase = m_out.newBlock();
1716                 LBasicBlock convertBooleanFalseCase = m_out.newBlock();
1717
1718                 m_out.appendTo(nonDoubleCase, undefinedCase);
1719                 LValue valueIsUndefined = m_out.equal(value, m_out.constInt64(ValueUndefined));
1720                 m_out.branch(valueIsUndefined, unsure(undefinedCase), unsure(testNullCase));
1721
1722                 m_out.appendTo(undefinedCase, testNullCase);
1723                 ValueFromBlock convertedUndefined = m_out.anchor(m_out.constDouble(PNaN));
1724                 m_out.jump(continuation);
1725
1726                 m_out.appendTo(testNullCase, nullCase);
1727                 LValue valueIsNull = m_out.equal(value, m_out.constInt64(ValueNull));
1728                 m_out.branch(valueIsNull, unsure(nullCase), unsure(testBooleanTrueCase));
1729
1730                 m_out.appendTo(nullCase, testBooleanTrueCase);
1731                 ValueFromBlock convertedNull = m_out.anchor(m_out.constDouble(0));
1732                 m_out.jump(continuation);
1733
1734                 m_out.appendTo(testBooleanTrueCase, convertBooleanTrueCase);
1735                 LValue valueIsBooleanTrue = m_out.equal(value, m_out.constInt64(ValueTrue));
1736                 m_out.branch(valueIsBooleanTrue, unsure(convertBooleanTrueCase), unsure(convertBooleanFalseCase));
1737
1738                 m_out.appendTo(convertBooleanTrueCase, convertBooleanFalseCase);
1739                 ValueFromBlock convertedTrue = m_out.anchor(m_out.constDouble(1));
1740                 m_out.jump(continuation);
1741
1742                 m_out.appendTo(convertBooleanFalseCase, continuation);
1743
1744                 LValue valueIsNotBooleanFalse = m_out.notEqual(value, m_out.constInt64(ValueFalse));
1745                 FTL_TYPE_CHECK(jsValueValue(value), m_node->child1(), ~SpecCellCheck, valueIsNotBooleanFalse);
1746                 ValueFromBlock convertedFalse = m_out.anchor(m_out.constDouble(0));
1747                 m_out.jump(continuation);
1748
1749                 m_out.appendTo(continuation, lastNext);
1750                 setDouble(m_out.phi(Double, intToDouble, unboxedDouble, convertedUndefined, convertedNull, convertedTrue, convertedFalse));
1751                 return;
1752             }
1753             m_out.appendTo(nonDoubleCase, continuation);
1754             FTL_TYPE_CHECK(jsValueValue(value), m_node->child1(), SpecBytecodeNumber, m_out.booleanTrue);
1755             m_out.unreachable();
1756
1757             m_out.appendTo(continuation, lastNext);
1758
1759             setDouble(m_out.phi(Double, intToDouble, unboxedDouble));
1760             return;
1761         }
1762             
1763         case Int52RepUse: {
1764             setDouble(strictInt52ToDouble(lowStrictInt52(m_node->child1())));
1765             return;
1766         }
1767             
1768         default:
1769             DFG_CRASH(m_graph, m_node, "Bad use kind");
1770         }
1771     }
1772
1773     void compileDoubleAsInt32()
1774     {
1775         LValue integerValue = convertDoubleToInt32(lowDouble(m_node->child1()), shouldCheckNegativeZero(m_node->arithMode()));
1776         setInt32(integerValue);
1777     }
1778
1779     void compileValueRep()
1780     {
1781         switch (m_node->child1().useKind()) {
1782         case DoubleRepUse: {
1783             LValue value = lowDouble(m_node->child1());
1784             
1785             if (m_interpreter.needsTypeCheck(m_node->child1(), ~SpecDoubleImpureNaN)) {
1786                 value = m_out.select(
1787                     m_out.doubleEqual(value, value), value, m_out.constDouble(PNaN));
1788             }
1789             
1790             setJSValue(boxDouble(value));
1791             return;
1792         }
1793             
1794         case Int52RepUse: {
1795             setJSValue(strictInt52ToJSValue(lowStrictInt52(m_node->child1())));
1796             return;
1797         }
1798             
1799         default:
1800             DFG_CRASH(m_graph, m_node, "Bad use kind");
1801         }
1802     }
1803     
1804     void compileInt52Rep()
1805     {
1806         switch (m_node->child1().useKind()) {
1807         case Int32Use:
1808             setStrictInt52(m_out.signExt32To64(lowInt32(m_node->child1())));
1809             return;
1810             
1811         case AnyIntUse:
1812             setStrictInt52(
1813                 jsValueToStrictInt52(
1814                     m_node->child1(), lowJSValue(m_node->child1(), ManualOperandSpeculation)));
1815             return;
1816             
1817         case DoubleRepAnyIntUse:
1818             setStrictInt52(
1819                 doubleToStrictInt52(
1820                     m_node->child1(), lowDouble(m_node->child1())));
1821             return;
1822             
1823         default:
1824             RELEASE_ASSERT_NOT_REACHED();
1825         }
1826     }
1827     
1828     void compileValueToInt32()
1829     {
1830         switch (m_node->child1().useKind()) {
1831         case Int52RepUse:
1832             setInt32(m_out.castToInt32(lowStrictInt52(m_node->child1())));
1833             break;
1834             
1835         case DoubleRepUse:
1836             setInt32(doubleToInt32(lowDouble(m_node->child1())));
1837             break;
1838             
1839         case NumberUse:
1840         case NotCellUse: {
1841             LoweredNodeValue value = m_int32Values.get(m_node->child1().node());
1842             if (isValid(value)) {
1843                 setInt32(value.value());
1844                 break;
1845             }
1846             
1847             value = m_jsValueValues.get(m_node->child1().node());
1848             if (isValid(value)) {
1849                 setInt32(numberOrNotCellToInt32(m_node->child1(), value.value()));
1850                 break;
1851             }
1852             
1853             // We'll basically just get here for constants. But it's good to have this
1854             // catch-all since we often add new representations into the mix.
1855             setInt32(
1856                 numberOrNotCellToInt32(
1857                     m_node->child1(),
1858                     lowJSValue(m_node->child1(), ManualOperandSpeculation)));
1859             break;
1860         }
1861             
1862         default:
1863             DFG_CRASH(m_graph, m_node, "Bad use kind");
1864             break;
1865         }
1866     }
1867     
1868     void compileBooleanToNumber()
1869     {
1870         switch (m_node->child1().useKind()) {
1871         case BooleanUse: {
1872             setInt32(m_out.zeroExt(lowBoolean(m_node->child1()), Int32));
1873             return;
1874         }
1875             
1876         case UntypedUse: {
1877             LValue value = lowJSValue(m_node->child1());
1878             
1879             if (!m_interpreter.needsTypeCheck(m_node->child1(), SpecBoolInt32 | SpecBoolean)) {
1880                 setInt32(m_out.bitAnd(m_out.castToInt32(value), m_out.int32One));
1881                 return;
1882             }
1883             
1884             LBasicBlock booleanCase = m_out.newBlock();
1885             LBasicBlock continuation = m_out.newBlock();
1886             
1887             ValueFromBlock notBooleanResult = m_out.anchor(value);
1888             m_out.branch(
1889                 isBoolean(value, provenType(m_node->child1())),
1890                 unsure(booleanCase), unsure(continuation));
1891             
1892             LBasicBlock lastNext = m_out.appendTo(booleanCase, continuation);
1893             ValueFromBlock booleanResult = m_out.anchor(m_out.bitOr(
1894                 m_out.zeroExt(unboxBoolean(value), Int64), m_tagTypeNumber));
1895             m_out.jump(continuation);
1896             
1897             m_out.appendTo(continuation, lastNext);
1898             setJSValue(m_out.phi(Int64, booleanResult, notBooleanResult));
1899             return;
1900         }
1901             
1902         default:
1903             RELEASE_ASSERT_NOT_REACHED();
1904             return;
1905         }
1906     }
1907
1908     void compileExtractOSREntryLocal()
1909     {
1910         EncodedJSValue* buffer = static_cast<EncodedJSValue*>(
1911             m_ftlState.jitCode->ftlForOSREntry()->entryBuffer()->dataBuffer());
1912         setJSValue(m_out.load64(m_out.absolute(buffer + m_node->unlinkedLocal().toLocal())));
1913     }
1914
1915     void compileExtractCatchLocal()
1916     {
1917         EncodedJSValue* buffer = static_cast<EncodedJSValue*>(m_ftlState.jitCode->common.catchOSREntryBuffer->dataBuffer());
1918         setJSValue(m_out.load64(m_out.absolute(buffer + m_node->catchOSREntryIndex())));
1919     }
1920
1921     void compileClearCatchLocals()
1922     {
1923         ScratchBuffer* scratchBuffer = m_ftlState.jitCode->common.catchOSREntryBuffer;
1924         ASSERT(scratchBuffer);
1925         m_out.storePtr(m_out.constIntPtr(0), m_out.absolute(scratchBuffer->addressOfActiveLength()));
1926     }
1927     
1928     void compileGetStack()
1929     {
1930         StackAccessData* data = m_node->stackAccessData();
1931         AbstractValue& value = m_state.operand(data->local);
1932         
1933         DFG_ASSERT(m_graph, m_node, isConcrete(data->format), data->format);
1934         
1935         switch (data->format) {
1936         case FlushedDouble:
1937             setDouble(m_out.loadDouble(addressFor(data->machineLocal)));
1938             break;
1939         case FlushedInt52:
1940             setInt52(m_out.load64(addressFor(data->machineLocal)));
1941             break;
1942         default:
1943             if (isInt32Speculation(value.m_type))
1944                 setInt32(m_out.load32(payloadFor(data->machineLocal)));
1945             else
1946                 setJSValue(m_out.load64(addressFor(data->machineLocal)));
1947             break;
1948         }
1949     }
1950     
1951     void compilePutStack()
1952     {
1953         StackAccessData* data = m_node->stackAccessData();
1954         switch (data->format) {
1955         case FlushedJSValue: {
1956             LValue value = lowJSValue(m_node->child1());
1957             m_out.store64(value, addressFor(data->machineLocal));
1958             break;
1959         }
1960             
1961         case FlushedDouble: {
1962             LValue value = lowDouble(m_node->child1());
1963             m_out.storeDouble(value, addressFor(data->machineLocal));
1964             break;
1965         }
1966             
1967         case FlushedInt32: {
1968             LValue value = lowInt32(m_node->child1());
1969             m_out.store32(value, payloadFor(data->machineLocal));
1970             break;
1971         }
1972             
1973         case FlushedInt52: {
1974             LValue value = lowInt52(m_node->child1());
1975             m_out.store64(value, addressFor(data->machineLocal));
1976             break;
1977         }
1978             
1979         case FlushedCell: {
1980             LValue value = lowCell(m_node->child1());
1981             m_out.store64(value, addressFor(data->machineLocal));
1982             break;
1983         }
1984             
1985         case FlushedBoolean: {
1986             speculateBoolean(m_node->child1());
1987             m_out.store64(
1988                 lowJSValue(m_node->child1(), ManualOperandSpeculation),
1989                 addressFor(data->machineLocal));
1990             break;
1991         }
1992             
1993         default:
1994             DFG_CRASH(m_graph, m_node, "Bad flush format");
1995             break;
1996         }
1997     }
1998     
1999     void compileNoOp()
2000     {
2001         DFG_NODE_DO_TO_CHILDREN(m_graph, m_node, speculate);
2002     }
2003
2004     void compileToObjectOrCallObjectConstructor()
2005     {
2006         LValue value = lowJSValue(m_node->child1());
2007
2008         LBasicBlock isCellCase = m_out.newBlock();
2009         LBasicBlock slowCase = m_out.newBlock();
2010         LBasicBlock continuation = m_out.newBlock();
2011
2012         m_out.branch(isCell(value, provenType(m_node->child1())), usually(isCellCase), rarely(slowCase));
2013
2014         LBasicBlock lastNext = m_out.appendTo(isCellCase, slowCase);
2015         ValueFromBlock fastResult = m_out.anchor(value);
2016         m_out.branch(isObject(value), usually(continuation), rarely(slowCase));
2017
2018         m_out.appendTo(slowCase, continuation);
2019
2020         ValueFromBlock slowResult;
2021         if (m_node->op() == ToObject) {
2022             auto* globalObject = m_graph.globalObjectFor(m_node->origin.semantic);
2023             slowResult = m_out.anchor(vmCall(Int64, m_out.operation(operationToObject), m_callFrame, weakPointer(globalObject), value, m_out.constIntPtr(m_graph.identifiers()[m_node->identifierNumber()])));
2024         } else
2025             slowResult = m_out.anchor(vmCall(Int64, m_out.operation(operationCallObjectConstructor), m_callFrame, frozenPointer(m_node->cellOperand()), value));
2026         m_out.jump(continuation);
2027
2028         m_out.appendTo(continuation, lastNext);
2029         setJSValue(m_out.phi(Int64, fastResult, slowResult));
2030     }
2031     
2032     void compileToThis()
2033     {
2034         LValue value = lowJSValue(m_node->child1());
2035         
2036         LBasicBlock isCellCase = m_out.newBlock();
2037         LBasicBlock slowCase = m_out.newBlock();
2038         LBasicBlock continuation = m_out.newBlock();
2039         
2040         m_out.branch(
2041             isCell(value, provenType(m_node->child1())), usually(isCellCase), rarely(slowCase));
2042         
2043         LBasicBlock lastNext = m_out.appendTo(isCellCase, slowCase);
2044         ValueFromBlock fastResult = m_out.anchor(value);
2045         m_out.branch(
2046             m_out.testIsZero32(
2047                 m_out.load8ZeroExt32(value, m_heaps.JSCell_typeInfoFlags),
2048                 m_out.constInt32(OverridesToThis)),
2049             usually(continuation), rarely(slowCase));
2050         
2051         m_out.appendTo(slowCase, continuation);
2052         J_JITOperation_EJ function;
2053         if (m_graph.isStrictModeFor(m_node->origin.semantic))
2054             function = operationToThisStrict;
2055         else
2056             function = operationToThis;
2057         ValueFromBlock slowResult = m_out.anchor(
2058             vmCall(Int64, m_out.operation(function), m_callFrame, value));
2059         m_out.jump(continuation);
2060         
2061         m_out.appendTo(continuation, lastNext);
2062         setJSValue(m_out.phi(Int64, fastResult, slowResult));
2063     }
2064
2065     void compileValueAdd()
2066     {
2067         if (m_node->isBinaryUseKind(BigIntUse)) {
2068             LValue left = lowBigInt(m_node->child1());
2069             LValue right = lowBigInt(m_node->child2());
2070
2071             LValue result = vmCall(pointerType(), m_out.operation(operationAddBigInt), m_callFrame, left, right);
2072             setJSValue(result);
2073             return;
2074         }
2075
2076         CodeBlock* baselineCodeBlock = m_ftlState.graph.baselineCodeBlockFor(m_node->origin.semantic);
2077         unsigned bytecodeIndex = m_node->origin.semantic.bytecodeIndex();
2078         ArithProfile* arithProfile = baselineCodeBlock->arithProfileForBytecodeOffset(bytecodeIndex);
2079         auto repatchingFunction = operationValueAddOptimize;
2080         auto nonRepatchingFunction = operationValueAdd;
2081         compileBinaryMathIC<JITAddGenerator>(arithProfile, repatchingFunction, nonRepatchingFunction);
2082     }
2083
2084     void compileValueSub()
2085     {
2086         if (m_node->isBinaryUseKind(BigIntUse)) {
2087             LValue left = lowBigInt(m_node->child1());
2088             LValue right = lowBigInt(m_node->child2());
2089             
2090             LValue result = vmCall(pointerType(), m_out.operation(operationSubBigInt), m_callFrame, left, right);
2091             setJSValue(result);
2092             return;
2093         }
2094
2095         CodeBlock* baselineCodeBlock = m_ftlState.graph.baselineCodeBlockFor(m_node->origin.semantic);
2096         unsigned bytecodeIndex = m_node->origin.semantic.bytecodeIndex();
2097         ArithProfile* arithProfile = baselineCodeBlock->arithProfileForBytecodeOffset(bytecodeIndex);
2098         auto repatchingFunction = operationValueSubOptimize;
2099         auto nonRepatchingFunction = operationValueSub;
2100         compileBinaryMathIC<JITSubGenerator>(arithProfile, repatchingFunction, nonRepatchingFunction);
2101     }
2102
2103     void compileValueMul()
2104     {
2105         if (m_node->isBinaryUseKind(BigIntUse)) {
2106             LValue left = lowBigInt(m_node->child1());
2107             LValue right = lowBigInt(m_node->child2());
2108             
2109             LValue result = vmCall(Int64, m_out.operation(operationMulBigInt), m_callFrame, left, right);
2110             setJSValue(result);
2111             return;
2112         }
2113
2114         CodeBlock* baselineCodeBlock = m_ftlState.graph.baselineCodeBlockFor(m_node->origin.semantic);
2115         unsigned bytecodeIndex = m_node->origin.semantic.bytecodeIndex();
2116         ArithProfile* arithProfile = baselineCodeBlock->arithProfileForBytecodeOffset(bytecodeIndex);
2117         auto repatchingFunction = operationValueMulOptimize;
2118         auto nonRepatchingFunction = operationValueMul;
2119         compileBinaryMathIC<JITMulGenerator>(arithProfile, repatchingFunction, nonRepatchingFunction);
2120     }
2121
2122     template <typename Generator, typename Func1, typename Func2,
2123         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>>
2124     void compileUnaryMathIC(ArithProfile* arithProfile, Func1 repatchingFunction, Func2 nonRepatchingFunction)
2125     {
2126         Node* node = m_node;
2127
2128         LValue operand = lowJSValue(node->child1());
2129
2130         PatchpointValue* patchpoint = m_out.patchpoint(Int64);
2131         patchpoint->appendSomeRegister(operand);
2132         patchpoint->append(m_tagMask, ValueRep::lateReg(GPRInfo::tagMaskRegister));
2133         patchpoint->append(m_tagTypeNumber, ValueRep::lateReg(GPRInfo::tagTypeNumberRegister));
2134         RefPtr<PatchpointExceptionHandle> exceptionHandle = preparePatchpointForExceptions(patchpoint);
2135         patchpoint->numGPScratchRegisters = 1;
2136         patchpoint->clobber(RegisterSet::macroScratchRegisters());
2137         State* state = &m_ftlState;
2138         patchpoint->setGenerator(
2139             [=] (CCallHelpers& jit, const StackmapGenerationParams& params) {
2140                 AllowMacroScratchRegisterUsage allowScratch(jit);
2141
2142                 Box<CCallHelpers::JumpList> exceptions =
2143                     exceptionHandle->scheduleExitCreation(params)->jumps(jit);
2144
2145 #if ENABLE(MATH_IC_STATS)
2146                 auto inlineStart = jit.label();
2147 #endif
2148
2149                 Box<MathICGenerationState> mathICGenerationState = Box<MathICGenerationState>::create();
2150                 JITUnaryMathIC<Generator>* mathIC = jit.codeBlock()->addMathIC<Generator>(arithProfile);
2151                 mathIC->m_generator = Generator(JSValueRegs(params[0].gpr()), JSValueRegs(params[1].gpr()), params.gpScratch(0));
2152
2153                 bool shouldEmitProfiling = false;
2154                 bool generatedInline = mathIC->generateInline(jit, *mathICGenerationState, shouldEmitProfiling);
2155
2156                 if (generatedInline) {
2157                     ASSERT(!mathICGenerationState->slowPathJumps.empty());
2158                     auto done = jit.label();
2159                     params.addLatePath([=] (CCallHelpers& jit) {
2160                         AllowMacroScratchRegisterUsage allowScratch(jit);
2161                         mathICGenerationState->slowPathJumps.link(&jit);
2162                         mathICGenerationState->slowPathStart = jit.label();
2163 #if ENABLE(MATH_IC_STATS)
2164                         auto slowPathStart = jit.label();
2165 #endif
2166
2167                         if (mathICGenerationState->shouldSlowPathRepatch) {
2168                             SlowPathCall call = callOperation(*state, params.unavailableRegisters(), jit, node->origin.semantic, exceptions.get(),
2169                                 repatchingFunction, params[0].gpr(), params[1].gpr(), CCallHelpers::TrustedImmPtr(mathIC));
2170                             mathICGenerationState->slowPathCall = call.call();
2171                         } else {
2172                             SlowPathCall call = callOperation(*state, params.unavailableRegisters(), jit, node->origin.semantic,
2173                                 exceptions.get(), nonRepatchingFunction, params[0].gpr(), params[1].gpr());
2174                             mathICGenerationState->slowPathCall = call.call();
2175                         }
2176                         jit.jump().linkTo(done, &jit);
2177
2178                         jit.addLinkTask([=] (LinkBuffer& linkBuffer) {
2179                             mathIC->finalizeInlineCode(*mathICGenerationState, linkBuffer);
2180                         });
2181
2182 #if ENABLE(MATH_IC_STATS)
2183                         auto slowPathEnd = jit.label();
2184                         jit.addLinkTask([=] (LinkBuffer& linkBuffer) {
2185                             size_t size = linkBuffer.locationOf(slowPathEnd).executableAddress<char*>() - linkBuffer.locationOf(slowPathStart).executableAddress<char*>();
2186                             mathIC->m_generatedCodeSize += size;
2187                         });
2188 #endif
2189                     });
2190                 } else {
2191                     callOperation(
2192                         *state, params.unavailableRegisters(), jit, node->origin.semantic, exceptions.get(),
2193                         nonRepatchingFunction, params[0].gpr(), params[1].gpr());
2194                 }
2195
2196 #if ENABLE(MATH_IC_STATS)
2197                 auto inlineEnd = jit.label();
2198                 jit.addLinkTask([=] (LinkBuffer& linkBuffer) {
2199                     size_t size = linkBuffer.locationOf(inlineEnd).executableAddress<char*>() - linkBuffer.locationOf(inlineStart).executableAddress<char*>();
2200                     mathIC->m_generatedCodeSize += size;
2201                 });
2202 #endif
2203             });
2204
2205         setJSValue(patchpoint);
2206     }
2207
2208     template <typename Generator, typename Func1, typename Func2,
2209         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>>
2210     void compileBinaryMathIC(ArithProfile* arithProfile, Func1 repatchingFunction, Func2 nonRepatchingFunction)
2211     {
2212         Node* node = m_node;
2213         
2214         LValue left = lowJSValue(node->child1());
2215         LValue right = lowJSValue(node->child2());
2216
2217         SnippetOperand leftOperand(m_state.forNode(node->child1()).resultType());
2218         SnippetOperand rightOperand(m_state.forNode(node->child2()).resultType());
2219             
2220         PatchpointValue* patchpoint = m_out.patchpoint(Int64);
2221         patchpoint->appendSomeRegister(left);
2222         patchpoint->appendSomeRegister(right);
2223         patchpoint->append(m_tagMask, ValueRep::lateReg(GPRInfo::tagMaskRegister));
2224         patchpoint->append(m_tagTypeNumber, ValueRep::lateReg(GPRInfo::tagTypeNumberRegister));
2225         RefPtr<PatchpointExceptionHandle> exceptionHandle =
2226             preparePatchpointForExceptions(patchpoint);
2227         patchpoint->numGPScratchRegisters = 1;
2228         patchpoint->numFPScratchRegisters = 2;
2229         patchpoint->clobber(RegisterSet::macroScratchRegisters());
2230         State* state = &m_ftlState;
2231         patchpoint->setGenerator(
2232             [=] (CCallHelpers& jit, const StackmapGenerationParams& params) {
2233                 AllowMacroScratchRegisterUsage allowScratch(jit);
2234
2235
2236                 Box<CCallHelpers::JumpList> exceptions =
2237                     exceptionHandle->scheduleExitCreation(params)->jumps(jit);
2238
2239 #if ENABLE(MATH_IC_STATS)
2240                 auto inlineStart = jit.label();
2241 #endif
2242
2243                 Box<MathICGenerationState> mathICGenerationState = Box<MathICGenerationState>::create();
2244                 JITBinaryMathIC<Generator>* mathIC = jit.codeBlock()->addMathIC<Generator>(arithProfile);
2245                 mathIC->m_generator = Generator(leftOperand, rightOperand, JSValueRegs(params[0].gpr()),
2246                     JSValueRegs(params[1].gpr()), JSValueRegs(params[2].gpr()), params.fpScratch(0),
2247                     params.fpScratch(1), params.gpScratch(0), InvalidFPRReg);
2248
2249                 bool shouldEmitProfiling = false;
2250                 bool generatedInline = mathIC->generateInline(jit, *mathICGenerationState, shouldEmitProfiling);
2251
2252                 if (generatedInline) {
2253                     ASSERT(!mathICGenerationState->slowPathJumps.empty());
2254                     auto done = jit.label();
2255                     params.addLatePath([=] (CCallHelpers& jit) {
2256                         AllowMacroScratchRegisterUsage allowScratch(jit);
2257                         mathICGenerationState->slowPathJumps.link(&jit);
2258                         mathICGenerationState->slowPathStart = jit.label();
2259 #if ENABLE(MATH_IC_STATS)
2260                         auto slowPathStart = jit.label();
2261 #endif
2262
2263                         if (mathICGenerationState->shouldSlowPathRepatch) {
2264                             SlowPathCall call = callOperation(*state, params.unavailableRegisters(), jit, node->origin.semantic, exceptions.get(),
2265                                 repatchingFunction, params[0].gpr(), params[1].gpr(), params[2].gpr(), CCallHelpers::TrustedImmPtr(mathIC));
2266                             mathICGenerationState->slowPathCall = call.call();
2267                         } else {
2268                             SlowPathCall call = callOperation(*state, params.unavailableRegisters(), jit, node->origin.semantic,
2269                                 exceptions.get(), nonRepatchingFunction, params[0].gpr(), params[1].gpr(), params[2].gpr());
2270                             mathICGenerationState->slowPathCall = call.call();
2271                         }
2272                         jit.jump().linkTo(done, &jit);
2273
2274                         jit.addLinkTask([=] (LinkBuffer& linkBuffer) {
2275                             mathIC->finalizeInlineCode(*mathICGenerationState, linkBuffer);
2276                         });
2277
2278 #if ENABLE(MATH_IC_STATS)
2279                         auto slowPathEnd = jit.label();
2280                         jit.addLinkTask([=] (LinkBuffer& linkBuffer) {
2281                             size_t size = linkBuffer.locationOf(slowPathEnd).executableAddress<char*>() - linkBuffer.locationOf(slowPathStart).executableAddress<char*>();
2282                             mathIC->m_generatedCodeSize += size;
2283                         });
2284 #endif
2285                     });
2286                 } else {
2287                     callOperation(
2288                         *state, params.unavailableRegisters(), jit, node->origin.semantic, exceptions.get(),
2289                         nonRepatchingFunction, params[0].gpr(), params[1].gpr(), params[2].gpr());
2290                 }
2291
2292 #if ENABLE(MATH_IC_STATS)
2293                 auto inlineEnd = jit.label();
2294                 jit.addLinkTask([=] (LinkBuffer& linkBuffer) {
2295                     size_t size = linkBuffer.locationOf(inlineEnd).executableAddress<char*>() - linkBuffer.locationOf(inlineStart).executableAddress<char*>();
2296                     mathIC->m_generatedCodeSize += size;
2297                 });
2298 #endif
2299             });
2300
2301         setJSValue(patchpoint);
2302     }
2303     
2304     void compileStrCat()
2305     {
2306         LValue result;
2307         if (m_node->child3()) {
2308             result = vmCall(
2309                 Int64, m_out.operation(operationStrCat3), m_callFrame,
2310                 lowJSValue(m_node->child1(), ManualOperandSpeculation),
2311                 lowJSValue(m_node->child2(), ManualOperandSpeculation),
2312                 lowJSValue(m_node->child3(), ManualOperandSpeculation));
2313         } else {
2314             result = vmCall(
2315                 Int64, m_out.operation(operationStrCat2), m_callFrame,
2316                 lowJSValue(m_node->child1(), ManualOperandSpeculation),
2317                 lowJSValue(m_node->child2(), ManualOperandSpeculation));
2318         }
2319         setJSValue(result);
2320     }
2321     
2322     void compileArithAddOrSub()
2323     {
2324         bool isSub =  m_node->op() == ArithSub;
2325         switch (m_node->binaryUseKind()) {
2326         case Int32Use: {
2327             LValue left = lowInt32(m_node->child1());
2328             LValue right = lowInt32(m_node->child2());
2329
2330             if (!shouldCheckOverflow(m_node->arithMode())) {
2331                 setInt32(isSub ? m_out.sub(left, right) : m_out.add(left, right));
2332                 break;
2333             }
2334
2335             CheckValue* result =
2336                 isSub ? m_out.speculateSub(left, right) : m_out.speculateAdd(left, right);
2337             blessSpeculation(result, Overflow, noValue(), nullptr, m_origin);
2338             setInt32(result);
2339             break;
2340         }
2341             
2342         case Int52RepUse: {
2343             if (!abstractValue(m_node->child1()).couldBeType(SpecNonInt32AsInt52)
2344                 && !abstractValue(m_node->child2()).couldBeType(SpecNonInt32AsInt52)) {
2345                 Int52Kind kind;
2346                 LValue left = lowWhicheverInt52(m_node->child1(), kind);
2347                 LValue right = lowInt52(m_node->child2(), kind);
2348                 setInt52(isSub ? m_out.sub(left, right) : m_out.add(left, right), kind);
2349                 break;
2350             }
2351
2352             LValue left = lowInt52(m_node->child1());
2353             LValue right = lowInt52(m_node->child2());
2354             CheckValue* result =
2355                 isSub ? m_out.speculateSub(left, right) : m_out.speculateAdd(left, right);
2356             blessSpeculation(result, Overflow, noValue(), nullptr, m_origin);
2357             setInt52(result);
2358             break;
2359         }
2360             
2361         case DoubleRepUse: {
2362             LValue C1 = lowDouble(m_node->child1());
2363             LValue C2 = lowDouble(m_node->child2());
2364
2365             setDouble(isSub ? m_out.doubleSub(C1, C2) : m_out.doubleAdd(C1, C2));
2366             break;
2367         }
2368
2369         case UntypedUse: {
2370             if (!isSub) {
2371                 DFG_CRASH(m_graph, m_node, "Bad use kind");
2372                 break;
2373             }
2374
2375             CodeBlock* baselineCodeBlock = m_ftlState.graph.baselineCodeBlockFor(m_node->origin.semantic);
2376             unsigned bytecodeIndex = m_node->origin.semantic.bytecodeIndex();
2377             ArithProfile* arithProfile = baselineCodeBlock->arithProfileForBytecodeOffset(bytecodeIndex);
2378             auto repatchingFunction = operationValueSubOptimize;
2379             auto nonRepatchingFunction = operationValueSub;
2380             compileBinaryMathIC<JITSubGenerator>(arithProfile, repatchingFunction, nonRepatchingFunction);
2381             break;
2382         }
2383
2384         default:
2385             DFG_CRASH(m_graph, m_node, "Bad use kind");
2386             break;
2387         }
2388     }
2389
2390     void compileArithClz32()
2391     {
2392         if (m_node->child1().useKind() == Int32Use || m_node->child1().useKind() == KnownInt32Use) {
2393             LValue operand = lowInt32(m_node->child1());
2394             setInt32(m_out.ctlz32(operand));
2395             return;
2396         }
2397         DFG_ASSERT(m_graph, m_node, m_node->child1().useKind() == UntypedUse, m_node->child1().useKind());
2398         LValue argument = lowJSValue(m_node->child1());
2399         LValue result = vmCall(Int32, m_out.operation(operationArithClz32), m_callFrame, argument);
2400         setInt32(result);
2401     }
2402     
2403     void compileArithMul()
2404     {
2405         switch (m_node->binaryUseKind()) {
2406         case Int32Use: {
2407             LValue left = lowInt32(m_node->child1());
2408             LValue right = lowInt32(m_node->child2());
2409             
2410             LValue result;
2411
2412             if (!shouldCheckOverflow(m_node->arithMode()))
2413                 result = m_out.mul(left, right);
2414             else {
2415                 CheckValue* speculation = m_out.speculateMul(left, right);
2416                 blessSpeculation(speculation, Overflow, noValue(), nullptr, m_origin);
2417                 result = speculation;
2418             }
2419             
2420             if (shouldCheckNegativeZero(m_node->arithMode())) {
2421                 LBasicBlock slowCase = m_out.newBlock();
2422                 LBasicBlock continuation = m_out.newBlock();
2423                 
2424                 m_out.branch(
2425                     m_out.notZero32(result), usually(continuation), rarely(slowCase));
2426                 
2427                 LBasicBlock lastNext = m_out.appendTo(slowCase, continuation);
2428                 speculate(NegativeZero, noValue(), nullptr, m_out.lessThan(left, m_out.int32Zero));
2429                 speculate(NegativeZero, noValue(), nullptr, m_out.lessThan(right, m_out.int32Zero));
2430                 m_out.jump(continuation);
2431                 m_out.appendTo(continuation, lastNext);
2432             }
2433             
2434             setInt32(result);
2435             break;
2436         }
2437             
2438         case Int52RepUse: {
2439             Int52Kind kind;
2440             LValue left = lowWhicheverInt52(m_node->child1(), kind);
2441             LValue right = lowInt52(m_node->child2(), opposite(kind));
2442
2443             CheckValue* result = m_out.speculateMul(left, right);
2444             blessSpeculation(result, Overflow, noValue(), nullptr, m_origin);
2445
2446             if (shouldCheckNegativeZero(m_node->arithMode())) {
2447                 LBasicBlock slowCase = m_out.newBlock();
2448                 LBasicBlock continuation = m_out.newBlock();
2449                 
2450                 m_out.branch(
2451                     m_out.notZero64(result), usually(continuation), rarely(slowCase));
2452                 
2453                 LBasicBlock lastNext = m_out.appendTo(slowCase, continuation);
2454                 speculate(NegativeZero, noValue(), nullptr, m_out.lessThan(left, m_out.int64Zero));
2455                 speculate(NegativeZero, noValue(), nullptr, m_out.lessThan(right, m_out.int64Zero));
2456                 m_out.jump(continuation);
2457                 m_out.appendTo(continuation, lastNext);
2458             }
2459             
2460             setInt52(result);
2461             break;
2462         }
2463             
2464         case DoubleRepUse: {
2465             setDouble(
2466                 m_out.doubleMul(lowDouble(m_node->child1()), lowDouble(m_node->child2())));
2467             break;
2468         }
2469
2470         default:
2471             DFG_CRASH(m_graph, m_node, "Bad use kind");
2472             break;
2473         }
2474     }
2475
2476     void compileValueDiv()
2477     {
2478         if (m_node->isBinaryUseKind(BigIntUse)) {
2479             LValue left = lowBigInt(m_node->child1());
2480             LValue right = lowBigInt(m_node->child2());
2481             
2482             LValue result = vmCall(pointerType(), m_out.operation(operationDivBigInt), m_callFrame, left, right);
2483             setJSValue(result);
2484             return;
2485         }
2486
2487         emitBinarySnippet<JITDivGenerator, NeedScratchFPR>(operationValueDiv);
2488     }
2489
2490     void compileArithDiv()
2491     {
2492         switch (m_node->binaryUseKind()) {
2493         case Int32Use: {
2494             LValue numerator = lowInt32(m_node->child1());
2495             LValue denominator = lowInt32(m_node->child2());
2496
2497             if (shouldCheckNegativeZero(m_node->arithMode())) {
2498                 LBasicBlock zeroNumerator = m_out.newBlock();
2499                 LBasicBlock numeratorContinuation = m_out.newBlock();
2500
2501                 m_out.branch(
2502                     m_out.isZero32(numerator),
2503                     rarely(zeroNumerator), usually(numeratorContinuation));
2504
2505                 LBasicBlock innerLastNext = m_out.appendTo(zeroNumerator, numeratorContinuation);
2506
2507                 speculate(
2508                     NegativeZero, noValue(), 0, m_out.lessThan(denominator, m_out.int32Zero));
2509
2510                 m_out.jump(numeratorContinuation);
2511
2512                 m_out.appendTo(numeratorContinuation, innerLastNext);
2513             }
2514             
2515             if (shouldCheckOverflow(m_node->arithMode())) {
2516                 LBasicBlock unsafeDenominator = m_out.newBlock();
2517                 LBasicBlock continuation = m_out.newBlock();
2518
2519                 LValue adjustedDenominator = m_out.add(denominator, m_out.int32One);
2520                 m_out.branch(
2521                     m_out.above(adjustedDenominator, m_out.int32One),
2522                     usually(continuation), rarely(unsafeDenominator));
2523
2524                 LBasicBlock lastNext = m_out.appendTo(unsafeDenominator, continuation);
2525                 LValue neg2ToThe31 = m_out.constInt32(-2147483647-1);
2526                 speculate(Overflow, noValue(), nullptr, m_out.isZero32(denominator));
2527                 speculate(Overflow, noValue(), nullptr, m_out.equal(numerator, neg2ToThe31));
2528                 m_out.jump(continuation);
2529
2530                 m_out.appendTo(continuation, lastNext);
2531                 LValue result = m_out.div(numerator, denominator);
2532                 speculate(
2533                     Overflow, noValue(), 0,
2534                     m_out.notEqual(m_out.mul(result, denominator), numerator));
2535                 setInt32(result);
2536             } else
2537                 setInt32(m_out.chillDiv(numerator, denominator));
2538
2539             break;
2540         }
2541             
2542         case DoubleRepUse: {
2543             setDouble(m_out.doubleDiv(
2544                 lowDouble(m_node->child1()), lowDouble(m_node->child2())));
2545             break;
2546         }
2547
2548         default:
2549             DFG_CRASH(m_graph, m_node, "Bad use kind");
2550             break;
2551         }
2552     }
2553     
2554     void compileValueMod()
2555     {
2556         if (m_node->binaryUseKind() == BigIntUse) {
2557             LValue left = lowBigInt(m_node->child1());
2558             LValue right = lowBigInt(m_node->child2());
2559
2560             LValue result = vmCall(pointerType(), m_out.operation(operationModBigInt), m_callFrame, left, right);
2561             setJSValue(result);
2562             return;
2563         }
2564
2565         DFG_ASSERT(m_graph, m_node, m_node->binaryUseKind() == UntypedUse, m_node->binaryUseKind());
2566         LValue left = lowJSValue(m_node->child1());
2567         LValue right = lowJSValue(m_node->child2());
2568         LValue result = vmCall(Int64, m_out.operation(operationValueMod), m_callFrame, left, right);
2569         setJSValue(result);
2570     }
2571
2572     void compileArithMod()
2573     {
2574         switch (m_node->binaryUseKind()) {
2575         case Int32Use: {
2576             LValue numerator = lowInt32(m_node->child1());
2577             LValue denominator = lowInt32(m_node->child2());
2578
2579             LValue remainder;
2580             if (shouldCheckOverflow(m_node->arithMode())) {
2581                 LBasicBlock unsafeDenominator = m_out.newBlock();
2582                 LBasicBlock continuation = m_out.newBlock();
2583
2584                 LValue adjustedDenominator = m_out.add(denominator, m_out.int32One);
2585                 m_out.branch(
2586                     m_out.above(adjustedDenominator, m_out.int32One),
2587                     usually(continuation), rarely(unsafeDenominator));
2588
2589                 LBasicBlock lastNext = m_out.appendTo(unsafeDenominator, continuation);
2590                 LValue neg2ToThe31 = m_out.constInt32(-2147483647-1);
2591                 speculate(Overflow, noValue(), nullptr, m_out.isZero32(denominator));
2592                 speculate(Overflow, noValue(), nullptr, m_out.equal(numerator, neg2ToThe31));
2593                 m_out.jump(continuation);
2594
2595                 m_out.appendTo(continuation, lastNext);
2596                 LValue result = m_out.mod(numerator, denominator);
2597                 remainder = result;
2598             } else
2599                 remainder = m_out.chillMod(numerator, denominator);
2600
2601             if (shouldCheckNegativeZero(m_node->arithMode())) {
2602                 LBasicBlock negativeNumerator = m_out.newBlock();
2603                 LBasicBlock numeratorContinuation = m_out.newBlock();
2604
2605                 m_out.branch(
2606                     m_out.lessThan(numerator, m_out.int32Zero),
2607                     unsure(negativeNumerator), unsure(numeratorContinuation));
2608
2609                 LBasicBlock innerLastNext = m_out.appendTo(negativeNumerator, numeratorContinuation);
2610
2611                 speculate(NegativeZero, noValue(), 0, m_out.isZero32(remainder));
2612
2613                 m_out.jump(numeratorContinuation);
2614
2615                 m_out.appendTo(numeratorContinuation, innerLastNext);
2616             }
2617
2618             setInt32(remainder);
2619             break;
2620         }
2621             
2622         case DoubleRepUse: {
2623             setDouble(
2624                 m_out.doubleMod(lowDouble(m_node->child1()), lowDouble(m_node->child2())));
2625             break;
2626         }
2627             
2628         default:
2629             DFG_CRASH(m_graph, m_node, "Bad use kind");
2630             break;
2631         }
2632     }
2633
2634     void compileArithMinOrMax()
2635     {
2636         switch (m_node->binaryUseKind()) {
2637         case Int32Use: {
2638             LValue left = lowInt32(m_node->child1());
2639             LValue right = lowInt32(m_node->child2());
2640             
2641             setInt32(
2642                 m_out.select(
2643                     m_node->op() == ArithMin
2644                         ? m_out.lessThan(left, right)
2645                         : m_out.lessThan(right, left),
2646                     left, right));
2647             break;
2648         }
2649             
2650         case DoubleRepUse: {
2651             LValue left = lowDouble(m_node->child1());
2652             LValue right = lowDouble(m_node->child2());
2653             
2654             LBasicBlock notLessThan = m_out.newBlock();
2655             LBasicBlock continuation = m_out.newBlock();
2656             
2657             Vector<ValueFromBlock, 2> results;
2658             
2659             results.append(m_out.anchor(left));
2660             m_out.branch(
2661                 m_node->op() == ArithMin
2662                     ? m_out.doubleLessThan(left, right)
2663                     : m_out.doubleGreaterThan(left, right),
2664                 unsure(continuation), unsure(notLessThan));
2665             
2666             LBasicBlock lastNext = m_out.appendTo(notLessThan, continuation);
2667             results.append(m_out.anchor(m_out.select(
2668                 m_node->op() == ArithMin
2669                     ? m_out.doubleGreaterThanOrEqual(left, right)
2670                     : m_out.doubleLessThanOrEqual(left, right),
2671                 right, m_out.constDouble(PNaN))));
2672             m_out.jump(continuation);
2673             
2674             m_out.appendTo(continuation, lastNext);
2675             setDouble(m_out.phi(Double, results));
2676             break;
2677         }
2678             
2679         default:
2680             DFG_CRASH(m_graph, m_node, "Bad use kind");
2681             break;
2682         }
2683     }
2684     
2685     void compileArithAbs()
2686     {
2687         switch (m_node->child1().useKind()) {
2688         case Int32Use: {
2689             LValue value = lowInt32(m_node->child1());
2690
2691             LValue mask = m_out.aShr(value, m_out.constInt32(31));
2692             LValue result = m_out.bitXor(mask, m_out.add(mask, value));
2693
2694             if (shouldCheckOverflow(m_node->arithMode()))
2695                 speculate(Overflow, noValue(), 0, m_out.lessThan(result, m_out.int32Zero));
2696
2697             setInt32(result);
2698             break;
2699         }
2700             
2701         case DoubleRepUse: {
2702             setDouble(m_out.doubleAbs(lowDouble(m_node->child1())));
2703             break;
2704         }
2705             
2706         default: {
2707             DFG_ASSERT(m_graph, m_node, m_node->child1().useKind() == UntypedUse, m_node->child1().useKind());
2708             LValue argument = lowJSValue(m_node->child1());
2709             LValue result = vmCall(Double, m_out.operation(operationArithAbs), m_callFrame, argument);
2710             setDouble(result);
2711             break;
2712         }
2713         }
2714     }
2715
2716     void compileArithUnary()
2717     {
2718         if (m_node->child1().useKind() == DoubleRepUse) {
2719             setDouble(m_out.doubleUnary(m_node->arithUnaryType(), lowDouble(m_node->child1())));
2720             return;
2721         }
2722         LValue argument = lowJSValue(m_node->child1());
2723         LValue result = vmCall(Double, m_out.operation(DFG::arithUnaryOperation(m_node->arithUnaryType())), m_callFrame, argument);
2724         setDouble(result);
2725     }
2726
2727     void compileValuePow()
2728     {
2729         if (m_node->isBinaryUseKind(BigIntUse)) {
2730             LValue base = lowBigInt(m_node->child1());
2731             LValue exponent = lowBigInt(m_node->child2());
2732             
2733             LValue result = vmCall(pointerType(), m_out.operation(operationPowBigInt), m_callFrame, base, exponent);
2734             setJSValue(result);
2735             return;
2736         }
2737
2738         LValue base = lowJSValue(m_node->child1());
2739         LValue exponent = lowJSValue(m_node->child2());
2740         LValue result = vmCall(Int64, m_out.operation(operationValuePow), m_callFrame, base, exponent);
2741         setJSValue(result);
2742     }
2743
2744     void compileArithPow()
2745     {
2746         if (m_node->child2().useKind() == Int32Use)
2747             setDouble(m_out.doublePowi(lowDouble(m_node->child1()), lowInt32(m_node->child2())));
2748         else {
2749             LValue base = lowDouble(m_node->child1());
2750             LValue exponent = lowDouble(m_node->child2());
2751
2752             LBasicBlock integerExponentIsSmallBlock = m_out.newBlock();
2753             LBasicBlock integerExponentPowBlock = m_out.newBlock();
2754             LBasicBlock doubleExponentPowBlockEntry = m_out.newBlock();
2755             LBasicBlock nanExceptionBaseIsOne = m_out.newBlock();
2756             LBasicBlock nanExceptionExponentIsInfinity = m_out.newBlock();
2757             LBasicBlock testExponentIsOneHalf = m_out.newBlock();
2758             LBasicBlock handleBaseZeroExponentIsOneHalf = m_out.newBlock();
2759             LBasicBlock handleInfinityForExponentIsOneHalf = m_out.newBlock();
2760             LBasicBlock exponentIsOneHalfNormal = m_out.newBlock();
2761             LBasicBlock exponentIsOneHalfInfinity = m_out.newBlock();
2762             LBasicBlock testExponentIsNegativeOneHalf = m_out.newBlock();
2763             LBasicBlock testBaseZeroExponentIsNegativeOneHalf = m_out.newBlock();
2764             LBasicBlock handleBaseZeroExponentIsNegativeOneHalf = m_out.newBlock();
2765             LBasicBlock handleInfinityForExponentIsNegativeOneHalf = m_out.newBlock();
2766             LBasicBlock exponentIsNegativeOneHalfNormal = m_out.newBlock();
2767             LBasicBlock exponentIsNegativeOneHalfInfinity = m_out.newBlock();
2768             LBasicBlock powBlock = m_out.newBlock();
2769             LBasicBlock nanExceptionResultIsNaN = m_out.newBlock();
2770             LBasicBlock continuation = m_out.newBlock();
2771
2772             LValue integerExponent = m_out.doubleToInt(exponent);
2773             LValue integerExponentConvertedToDouble = m_out.intToDouble(integerExponent);
2774             LValue exponentIsInteger = m_out.doubleEqual(exponent, integerExponentConvertedToDouble);
2775             m_out.branch(exponentIsInteger, unsure(integerExponentIsSmallBlock), unsure(doubleExponentPowBlockEntry));
2776
2777             LBasicBlock lastNext = m_out.appendTo(integerExponentIsSmallBlock, integerExponentPowBlock);
2778             LValue integerExponentBelowMax = m_out.belowOrEqual(integerExponent, m_out.constInt32(maxExponentForIntegerMathPow));
2779             m_out.branch(integerExponentBelowMax, usually(integerExponentPowBlock), rarely(doubleExponentPowBlockEntry));
2780
2781             m_out.appendTo(integerExponentPowBlock, doubleExponentPowBlockEntry);
2782             ValueFromBlock powDoubleIntResult = m_out.anchor(m_out.doublePowi(base, integerExponent));
2783             m_out.jump(continuation);
2784
2785             // If y is NaN, the result is NaN.
2786             m_out.appendTo(doubleExponentPowBlockEntry, nanExceptionBaseIsOne);
2787             LValue exponentIsNaN;
2788             if (provenType(m_node->child2()) & SpecDoubleNaN)
2789                 exponentIsNaN = m_out.doubleNotEqualOrUnordered(exponent, exponent);
2790             else
2791                 exponentIsNaN = m_out.booleanFalse;
2792             m_out.branch(exponentIsNaN, rarely(nanExceptionResultIsNaN), usually(nanExceptionBaseIsOne));
2793
2794             // If abs(x) is 1 and y is +infinity, the result is NaN.
2795             // If abs(x) is 1 and y is -infinity, the result is NaN.
2796
2797             //     Test if base == 1.
2798             m_out.appendTo(nanExceptionBaseIsOne, nanExceptionExponentIsInfinity);
2799             LValue absoluteBase = m_out.doubleAbs(base);
2800             LValue absoluteBaseIsOne = m_out.doubleEqual(absoluteBase, m_out.constDouble(1));
2801             m_out.branch(absoluteBaseIsOne, rarely(nanExceptionExponentIsInfinity), usually(testExponentIsOneHalf));
2802
2803             //     Test if abs(y) == Infinity.
2804             m_out.appendTo(nanExceptionExponentIsInfinity, testExponentIsOneHalf);
2805             LValue absoluteExponent = m_out.doubleAbs(exponent);
2806             LValue absoluteExponentIsInfinity = m_out.doubleEqual(absoluteExponent, m_out.constDouble(std::numeric_limits<double>::infinity()));
2807             m_out.branch(absoluteExponentIsInfinity, rarely(nanExceptionResultIsNaN), usually(testExponentIsOneHalf));
2808
2809             // If y == 0.5 or y == -0.5, handle it through SQRT.
2810             // We have be carefuly with -0 and -Infinity.
2811
2812             //     Test if y == 0.5
2813             m_out.appendTo(testExponentIsOneHalf, handleBaseZeroExponentIsOneHalf);
2814             LValue exponentIsOneHalf = m_out.doubleEqual(exponent, m_out.constDouble(0.5));
2815             m_out.branch(exponentIsOneHalf, rarely(handleBaseZeroExponentIsOneHalf), usually(testExponentIsNegativeOneHalf));
2816
2817             //     Handle x == -0.
2818             m_out.appendTo(handleBaseZeroExponentIsOneHalf, handleInfinityForExponentIsOneHalf);
2819             LValue baseIsZeroExponentIsOneHalf = m_out.doubleEqual(base, m_out.doubleZero);
2820             ValueFromBlock zeroResultExponentIsOneHalf = m_out.anchor(m_out.doubleZero);
2821             m_out.branch(baseIsZeroExponentIsOneHalf, rarely(continuation), usually(handleInfinityForExponentIsOneHalf));
2822
2823             //     Test if abs(x) == Infinity.
2824             m_out.appendTo(handleInfinityForExponentIsOneHalf, exponentIsOneHalfNormal);
2825             LValue absoluteBaseIsInfinityOneHalf = m_out.doubleEqual(absoluteBase, m_out.constDouble(std::numeric_limits<double>::infinity()));
2826             m_out.branch(absoluteBaseIsInfinityOneHalf, rarely(exponentIsOneHalfInfinity), usually(exponentIsOneHalfNormal));
2827
2828             //     The exponent is 0.5, the base is finite or NaN, we can use SQRT.
2829             m_out.appendTo(exponentIsOneHalfNormal, exponentIsOneHalfInfinity);
2830             ValueFromBlock sqrtResult = m_out.anchor(m_out.doubleSqrt(base));
2831             m_out.jump(continuation);
2832
2833             //     The exponent is 0.5, the base is infinite, the result is always infinite.
2834             m_out.appendTo(exponentIsOneHalfInfinity, testExponentIsNegativeOneHalf);
2835             ValueFromBlock sqrtInfinityResult = m_out.anchor(m_out.constDouble(std::numeric_limits<double>::infinity()));
2836             m_out.jump(continuation);
2837
2838             //     Test if y == -0.5
2839             m_out.appendTo(testExponentIsNegativeOneHalf, testBaseZeroExponentIsNegativeOneHalf);
2840             LValue exponentIsNegativeOneHalf = m_out.doubleEqual(exponent, m_out.constDouble(-0.5));
2841             m_out.branch(exponentIsNegativeOneHalf, rarely(testBaseZeroExponentIsNegativeOneHalf), usually(powBlock));
2842
2843             //     Handle x == -0.
2844             m_out.appendTo(testBaseZeroExponentIsNegativeOneHalf, handleBaseZeroExponentIsNegativeOneHalf);
2845             LValue baseIsZeroExponentIsNegativeOneHalf = m_out.doubleEqual(base, m_out.doubleZero);
2846             m_out.branch(baseIsZeroExponentIsNegativeOneHalf, rarely(handleBaseZeroExponentIsNegativeOneHalf), usually(handleInfinityForExponentIsNegativeOneHalf));
2847
2848             m_out.appendTo(handleBaseZeroExponentIsNegativeOneHalf, handleInfinityForExponentIsNegativeOneHalf);
2849             ValueFromBlock oneOverSqrtZeroResult = m_out.anchor(m_out.constDouble(std::numeric_limits<double>::infinity()));
2850             m_out.jump(continuation);
2851
2852             //     Test if abs(x) == Infinity.
2853             m_out.appendTo(handleInfinityForExponentIsNegativeOneHalf, exponentIsNegativeOneHalfNormal);
2854             LValue absoluteBaseIsInfinityNegativeOneHalf = m_out.doubleEqual(absoluteBase, m_out.constDouble(std::numeric_limits<double>::infinity()));
2855             m_out.branch(absoluteBaseIsInfinityNegativeOneHalf, rarely(exponentIsNegativeOneHalfInfinity), usually(exponentIsNegativeOneHalfNormal));
2856
2857             //     The exponent is -0.5, the base is finite or NaN, we can use 1/SQRT.
2858             m_out.appendTo(exponentIsNegativeOneHalfNormal, exponentIsNegativeOneHalfInfinity);
2859             LValue sqrtBase = m_out.doubleSqrt(base);
2860             ValueFromBlock oneOverSqrtResult = m_out.anchor(m_out.div(m_out.constDouble(1.), sqrtBase));
2861             m_out.jump(continuation);
2862
2863             //     The exponent is -0.5, the base is infinite, the result is always zero.
2864             m_out.appendTo(exponentIsNegativeOneHalfInfinity, powBlock);
2865             ValueFromBlock oneOverSqrtInfinityResult = m_out.anchor(m_out.doubleZero);
2866             m_out.jump(continuation);
2867
2868             m_out.appendTo(powBlock, nanExceptionResultIsNaN);
2869             ValueFromBlock powResult = m_out.anchor(m_out.doublePow(base, exponent));
2870             m_out.jump(continuation);
2871
2872             m_out.appendTo(nanExceptionResultIsNaN, continuation);
2873             ValueFromBlock pureNan = m_out.anchor(m_out.constDouble(PNaN));
2874             m_out.jump(continuation);
2875
2876             m_out.appendTo(continuation, lastNext);
2877             setDouble(m_out.phi(Double, powDoubleIntResult, zeroResultExponentIsOneHalf, sqrtResult, sqrtInfinityResult, oneOverSqrtZeroResult, oneOverSqrtResult, oneOverSqrtInfinityResult, powResult, pureNan));
2878         }
2879     }
2880
2881     void compileArithRandom()
2882     {
2883         JSGlobalObject* globalObject = m_graph.globalObjectFor(m_node->origin.semantic);
2884
2885         // Inlined WeakRandom::advance().
2886         // uint64_t x = m_low;
2887         void* lowAddress = reinterpret_cast<uint8_t*>(globalObject) + JSGlobalObject::weakRandomOffset() + WeakRandom::lowOffset();
2888         LValue low = m_out.load64(m_out.absolute(lowAddress));
2889         // uint64_t y = m_high;
2890         void* highAddress = reinterpret_cast<uint8_t*>(globalObject) + JSGlobalObject::weakRandomOffset() + WeakRandom::highOffset();
2891         LValue high = m_out.load64(m_out.absolute(highAddress));
2892         // m_low = y;
2893         m_out.store64(high, m_out.absolute(lowAddress));
2894
2895         // x ^= x << 23;
2896         LValue phase1 = m_out.bitXor(m_out.shl(low, m_out.constInt64(23)), low);
2897
2898         // x ^= x >> 17;
2899         LValue phase2 = m_out.bitXor(m_out.lShr(phase1, m_out.constInt64(17)), phase1);
2900
2901         // x ^= y ^ (y >> 26);
2902         LValue phase3 = m_out.bitXor(m_out.bitXor(high, m_out.lShr(high, m_out.constInt64(26))), phase2);
2903
2904         // m_high = x;
2905         m_out.store64(phase3, m_out.absolute(highAddress));
2906
2907         // return x + y;
2908         LValue random64 = m_out.add(phase3, high);
2909
2910         // Extract random 53bit. [0, 53] bit is safe integer number ranges in double representation.
2911         LValue random53 = m_out.bitAnd(random64, m_out.constInt64((1ULL << 53) - 1));
2912
2913         LValue double53Integer = m_out.intToDouble(random53);
2914
2915         // Convert `(53bit double integer value) / (1 << 53)` to `(53bit double integer value) * (1.0 / (1 << 53))`.
2916         // In latter case, `1.0 / (1 << 53)` will become a double value represented as (mantissa = 0 & exp = 970, it means 1e-(2**54)).
2917         static const double scale = 1.0 / (1ULL << 53);
2918
2919         // Multiplying 1e-(2**54) with the double integer does not change anything of the mantissa part of the double integer.
2920         // It just reduces the exp part of the given 53bit double integer.
2921         // (Except for 0.0. This is specially handled and in this case, exp just becomes 0.)
2922         // Now we get 53bit precision random double value in [0, 1).
2923         LValue result = m_out.doubleMul(double53Integer, m_out.constDouble(scale));
2924
2925         setDouble(result);
2926     }
2927
2928     void compileArithRound()
2929     {
2930         if (m_node->child1().useKind() == DoubleRepUse) {
2931             LValue result = nullptr;
2932             if (producesInteger(m_node->arithRoundingMode()) && !shouldCheckNegativeZero(m_node->arithRoundingMode())) {
2933                 LValue value = lowDouble(m_node->child1());
2934                 result = m_out.doubleFloor(m_out.doubleAdd(value, m_out.constDouble(0.5)));
2935             } else {
2936                 LBasicBlock realPartIsMoreThanHalf = m_out.newBlock();
2937                 LBasicBlock continuation = m_out.newBlock();
2938
2939                 LValue value = lowDouble(m_node->child1());
2940                 LValue integerValue = m_out.doubleCeil(value);
2941                 ValueFromBlock integerValueResult = m_out.anchor(integerValue);
2942
2943                 LValue realPart = m_out.doubleSub(integerValue, value);
2944
2945                 m_out.branch(m_out.doubleGreaterThanOrUnordered(realPart, m_out.constDouble(0.5)), unsure(realPartIsMoreThanHalf), unsure(continuation));
2946
2947                 LBasicBlock lastNext = m_out.appendTo(realPartIsMoreThanHalf, continuation);
2948                 LValue integerValueRoundedDown = m_out.doubleSub(integerValue, m_out.constDouble(1));
2949                 ValueFromBlock integerValueRoundedDownResult = m_out.anchor(integerValueRoundedDown);
2950                 m_out.jump(continuation);
2951                 m_out.appendTo(continuation, lastNext);
2952
2953                 result = m_out.phi(Double, integerValueResult, integerValueRoundedDownResult);
2954             }
2955
2956             if (producesInteger(m_node->arithRoundingMode())) {
2957                 LValue integerValue = convertDoubleToInt32(result, shouldCheckNegativeZero(m_node->arithRoundingMode()));
2958                 setInt32(integerValue);
2959             } else
2960                 setDouble(result);
2961             return;
2962         }
2963
2964         DFG_ASSERT(m_graph, m_node, m_node->child1().useKind() == UntypedUse, m_node->child1().useKind());
2965         LValue argument = lowJSValue(m_node->child1());
2966         setJSValue(vmCall(Int64, m_out.operation(operationArithRound), m_callFrame, argument));
2967     }
2968
2969     void compileArithFloor()
2970     {
2971         if (m_node->child1().useKind() == DoubleRepUse) {
2972             LValue value = lowDouble(m_node->child1());
2973             LValue integerValue = m_out.doubleFloor(value);
2974             if (producesInteger(m_node->arithRoundingMode()))
2975                 setInt32(convertDoubleToInt32(integerValue, shouldCheckNegativeZero(m_node->arithRoundingMode())));
2976             else
2977                 setDouble(integerValue);
2978             return;
2979         }
2980         DFG_ASSERT(m_graph, m_node, m_node->child1().useKind() == UntypedUse, m_node->child1().useKind());
2981         LValue argument = lowJSValue(m_node->child1());
2982         setJSValue(vmCall(Int64, m_out.operation(operationArithFloor), m_callFrame, argument));
2983     }
2984
2985     void compileArithCeil()
2986     {
2987         if (m_node->child1().useKind() == DoubleRepUse) {
2988             LValue value = lowDouble(m_node->child1());
2989             LValue integerValue = m_out.doubleCeil(value);
2990             if (producesInteger(m_node->arithRoundingMode()))
2991                 setInt32(convertDoubleToInt32(integerValue, shouldCheckNegativeZero(m_node->arithRoundingMode())));
2992             else
2993                 setDouble(integerValue);
2994             return;
2995         }
2996         DFG_ASSERT(m_graph, m_node, m_node->child1().useKind() == UntypedUse, m_node->child1().useKind());
2997         LValue argument = lowJSValue(m_node->child1());
2998         setJSValue(vmCall(Int64, m_out.operation(operationArithCeil), m_callFrame, argument));
2999     }
3000
3001     void compileArithTrunc()
3002     {
3003         if (m_node->child1().useKind() == DoubleRepUse) {
3004             LValue value = lowDouble(m_node->child1());
3005             LValue result = m_out.doubleTrunc(value);
3006             if (producesInteger(m_node->arithRoundingMode()))
3007                 setInt32(convertDoubleToInt32(result, shouldCheckNegativeZero(m_node->arithRoundingMode())));
3008             else
3009                 setDouble(result);
3010             return;
3011         }
3012         DFG_ASSERT(m_graph, m_node, m_node->child1().useKind() == UntypedUse, m_node->child1().useKind());
3013         LValue argument = lowJSValue(m_node->child1());
3014         setJSValue(vmCall(Int64, m_out.operation(operationArithTrunc), m_callFrame, argument));
3015     }
3016
3017     void compileArithSqrt()
3018     {
3019         if (m_node->child1().useKind() == DoubleRepUse) {
3020             setDouble(m_out.doubleSqrt(lowDouble(m_node->child1())));
3021             return;
3022         }
3023         LValue argument = lowJSValue(m_node->child1());
3024         LValue result = vmCall(Double, m_out.operation(operationArithSqrt), m_callFrame, argument);
3025         setDouble(result);
3026     }
3027
3028     void compileArithFRound()
3029     {
3030         if (m_node->child1().useKind() == DoubleRepUse) {
3031             setDouble(m_out.fround(lowDouble(m_node->child1())));
3032             return;
3033         }
3034         LValue argument = lowJSValue(m_node->child1());
3035         LValue result = vmCall(Double, m_out.operation(operationArithFRound), m_callFrame, argument);
3036         setDouble(result);
3037     }
3038
3039     void compileValueNegate()
3040     {
3041         DFG_ASSERT(m_graph, m_node, m_node->child1().useKind() == UntypedUse);
3042         CodeBlock* baselineCodeBlock = m_ftlState.graph.baselineCodeBlockFor(m_node->origin.semantic);
3043         unsigned bytecodeIndex = m_node->origin.semantic.bytecodeIndex();
3044         ArithProfile* arithProfile = baselineCodeBlock->arithProfileForBytecodeOffset(bytecodeIndex);
3045         auto repatchingFunction = operationArithNegateOptimize;
3046         auto nonRepatchingFunction = operationArithNegate;
3047         compileUnaryMathIC<JITNegGenerator>(arithProfile, repatchingFunction, nonRepatchingFunction);
3048     }
3049
3050     void compileArithNegate()
3051     {
3052         switch (m_node->child1().useKind()) {
3053         case Int32Use: {
3054             LValue value = lowInt32(m_node->child1());
3055             
3056             LValue result;
3057             if (!shouldCheckOverflow(m_node->arithMode()))
3058                 result = m_out.neg(value);
3059             else if (!shouldCheckNegativeZero(m_node->arithMode())) {
3060                 CheckValue* check = m_out.speculateSub(m_out.int32Zero, value);
3061                 blessSpeculation(check, Overflow, noValue(), nullptr, m_origin);
3062                 result = check;
3063             } else {
3064                 speculate(Overflow, noValue(), 0, m_out.testIsZero32(value, m_out.constInt32(0x7fffffff)));
3065                 result = m_out.neg(value);
3066             }
3067
3068             setInt32(result);
3069             break;
3070         }
3071             
3072         case Int52RepUse: {
3073             if (!abstractValue(m_node->child1()).couldBeType(SpecNonInt32AsInt52)) {
3074                 Int52Kind kind;
3075                 LValue value = lowWhicheverInt52(m_node->child1(), kind);
3076                 LValue result = m_out.neg(value);
3077                 if (shouldCheckNegativeZero(m_node->arithMode()))
3078                     speculate(NegativeZero, noValue(), 0, m_out.isZero64(result));
3079                 setInt52(result, kind);
3080                 break;
3081             }
3082             
3083             LValue value = lowInt52(m_node->child1());
3084             CheckValue* result = m_out.speculateSub(m_out.int64Zero, value);
3085             blessSpeculation(result, Int52Overflow, noValue(), nullptr, m_origin);
3086             if (shouldCheckNegativeZero(m_node->arithMode()))
3087                 speculate(NegativeZero, noValue(), 0, m_out.isZero64(result));
3088             setInt52(result);
3089             break;
3090         }
3091             
3092         case DoubleRepUse: {
3093             setDouble(m_out.doubleNeg(lowDouble(m_node->child1())));
3094             break;
3095         }
3096             
3097         default:
3098             DFG_CRASH(m_graph, m_node, "Bad use kind");
3099             break;
3100         }
3101     }
3102     
3103     void compileValueBitNot()
3104     {
3105         if (m_node->child1().useKind() == BigIntUse) {
3106             LValue operand = lowBigInt(m_node->child1());
3107             LValue result = vmCall(pointerType(), m_out.operation(operationBitNotBigInt), m_callFrame, operand);
3108             setJSValue(result);
3109             return;
3110         }
3111
3112         LValue operand = lowJSValue(m_node->child1());
3113         LValue result = vmCall(Int64, m_out.operation(operationValueBitNot), m_callFrame, operand);
3114         setJSValue(result);
3115     }
3116
3117     void compileArithBitNot()
3118     {
3119         setInt32(m_out.bitNot(lowInt32(m_node->child1())));
3120     }
3121
3122     void compileValueBitAnd()
3123     {
3124         if (m_node->isBinaryUseKind(BigIntUse)) {
3125             LValue left = lowBigInt(m_node->child1());
3126             LValue right = lowBigInt(m_node->child2());
3127             
3128             LValue result = vmCall(pointerType(), m_out.operation(operationBitAndBigInt), m_callFrame, left, right);
3129             setJSValue(result);
3130             return;
3131         }
3132         
3133         emitBinaryBitOpSnippet<JITBitAndGenerator>(operationValueBitAnd);
3134     }
3135     
3136     void compileArithBitAnd()