1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/js/src/jit/shared/BaselineCompiler-shared.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,103 @@ 1.4 +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- 1.5 + * vim: set ts=8 sts=4 et sw=4 tw=99: 1.6 + * This Source Code Form is subject to the terms of the Mozilla Public 1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.9 + 1.10 +#include "jit/shared/BaselineCompiler-shared.h" 1.11 + 1.12 +#include "jit/BaselineIC.h" 1.13 +#include "jit/VMFunctions.h" 1.14 + 1.15 +using namespace js; 1.16 +using namespace js::jit; 1.17 + 1.18 +BaselineCompilerShared::BaselineCompilerShared(JSContext *cx, TempAllocator &alloc, JSScript *script) 1.19 + : cx(cx), 1.20 + script(script), 1.21 + pc(script->code()), 1.22 + ionCompileable_(jit::IsIonEnabled(cx) && CanIonCompileScript(cx, script, false)), 1.23 + ionOSRCompileable_(jit::IsIonEnabled(cx) && CanIonCompileScript(cx, script, true)), 1.24 + debugMode_(cx->compartment()->debugMode()), 1.25 + alloc_(alloc), 1.26 + analysis_(alloc, script), 1.27 + frame(script, masm), 1.28 + stubSpace_(), 1.29 + icEntries_(), 1.30 + pcMappingEntries_(), 1.31 + icLoadLabels_(), 1.32 + pushedBeforeCall_(0), 1.33 + inCall_(false), 1.34 + spsPushToggleOffset_() 1.35 +{ } 1.36 + 1.37 +bool 1.38 +BaselineCompilerShared::callVM(const VMFunction &fun, CallVMPhase phase) 1.39 +{ 1.40 + JitCode *code = cx->runtime()->jitRuntime()->getVMWrapper(fun); 1.41 + if (!code) 1.42 + return false; 1.43 + 1.44 +#ifdef DEBUG 1.45 + // Assert prepareVMCall() has been called. 1.46 + JS_ASSERT(inCall_); 1.47 + inCall_ = false; 1.48 +#endif 1.49 + 1.50 + // Compute argument size. Note that this include the size of the frame pointer 1.51 + // pushed by prepareVMCall. 1.52 + uint32_t argSize = fun.explicitStackSlots() * sizeof(void *) + sizeof(void *); 1.53 + 1.54 + // Assert all arguments were pushed. 1.55 + JS_ASSERT(masm.framePushed() - pushedBeforeCall_ == argSize); 1.56 + 1.57 + Address frameSizeAddress(BaselineFrameReg, BaselineFrame::reverseOffsetOfFrameSize()); 1.58 + uint32_t frameVals = frame.nlocals() + frame.stackDepth(); 1.59 + uint32_t frameBaseSize = BaselineFrame::FramePointerOffset + BaselineFrame::Size(); 1.60 + uint32_t frameFullSize = frameBaseSize + (frameVals * sizeof(Value)); 1.61 + if (phase == POST_INITIALIZE) { 1.62 + masm.store32(Imm32(frameFullSize), frameSizeAddress); 1.63 + uint32_t descriptor = MakeFrameDescriptor(frameFullSize + argSize, JitFrame_BaselineJS); 1.64 + masm.push(Imm32(descriptor)); 1.65 + 1.66 + } else if (phase == PRE_INITIALIZE) { 1.67 + masm.store32(Imm32(frameBaseSize), frameSizeAddress); 1.68 + uint32_t descriptor = MakeFrameDescriptor(frameBaseSize + argSize, JitFrame_BaselineJS); 1.69 + masm.push(Imm32(descriptor)); 1.70 + 1.71 + } else { 1.72 + JS_ASSERT(phase == CHECK_OVER_RECURSED); 1.73 + Label afterWrite; 1.74 + Label writePostInitialize; 1.75 + 1.76 + // If OVER_RECURSED is set, then frame locals haven't been pushed yet. 1.77 + masm.branchTest32(Assembler::Zero, 1.78 + frame.addressOfFlags(), 1.79 + Imm32(BaselineFrame::OVER_RECURSED), 1.80 + &writePostInitialize); 1.81 + 1.82 + masm.move32(Imm32(frameBaseSize), BaselineTailCallReg); 1.83 + masm.jump(&afterWrite); 1.84 + 1.85 + masm.bind(&writePostInitialize); 1.86 + masm.move32(Imm32(frameFullSize), BaselineTailCallReg); 1.87 + 1.88 + masm.bind(&afterWrite); 1.89 + masm.store32(BaselineTailCallReg, frameSizeAddress); 1.90 + masm.add32(Imm32(argSize), BaselineTailCallReg); 1.91 + masm.makeFrameDescriptor(BaselineTailCallReg, JitFrame_BaselineJS); 1.92 + masm.push(BaselineTailCallReg); 1.93 + } 1.94 + 1.95 + // Perform the call. 1.96 + masm.call(code); 1.97 + uint32_t callOffset = masm.currentOffset(); 1.98 + masm.pop(BaselineFrameReg); 1.99 + 1.100 + // Add a fake ICEntry (without stubs), so that the return offset to 1.101 + // pc mapping works. 1.102 + ICEntry entry(script->pcToOffset(pc), ICEntry::Kind_CallVM); 1.103 + entry.setReturnOffset(callOffset); 1.104 + 1.105 + return icEntries_.append(entry); 1.106 +}