1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/js/src/jit/arm/BaselineHelpers-arm.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,334 @@ 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 +#ifndef jit_arm_BaselineHelpers_arm_h 1.11 +#define jit_arm_BaselineHelpers_arm_h 1.12 + 1.13 +#ifdef JS_ION 1.14 +#include "jit/BaselineFrame.h" 1.15 +#include "jit/BaselineIC.h" 1.16 +#include "jit/BaselineRegisters.h" 1.17 +#include "jit/IonMacroAssembler.h" 1.18 + 1.19 +namespace js { 1.20 +namespace jit { 1.21 + 1.22 +// Distance from sp to the top Value inside an IC stub (no return address on the stack on ARM). 1.23 +static const size_t ICStackValueOffset = 0; 1.24 + 1.25 +inline void 1.26 +EmitRestoreTailCallReg(MacroAssembler &masm) 1.27 +{ 1.28 + // No-op on ARM because link register is always holding the return address. 1.29 +} 1.30 + 1.31 +inline void 1.32 +EmitRepushTailCallReg(MacroAssembler &masm) 1.33 +{ 1.34 + // No-op on ARM because link register is always holding the return address. 1.35 +} 1.36 + 1.37 +inline void 1.38 +EmitCallIC(CodeOffsetLabel *patchOffset, MacroAssembler &masm) 1.39 +{ 1.40 + // Move ICEntry offset into BaselineStubReg 1.41 + CodeOffsetLabel offset = masm.movWithPatch(ImmWord(-1), BaselineStubReg); 1.42 + *patchOffset = offset; 1.43 + 1.44 + // Load stub pointer into BaselineStubReg 1.45 + masm.loadPtr(Address(BaselineStubReg, ICEntry::offsetOfFirstStub()), BaselineStubReg); 1.46 + 1.47 + // Load stubcode pointer from BaselineStubEntry. 1.48 + // R2 won't be active when we call ICs, so we can use r0. 1.49 + JS_ASSERT(R2 == ValueOperand(r1, r0)); 1.50 + masm.loadPtr(Address(BaselineStubReg, ICStub::offsetOfStubCode()), r0); 1.51 + 1.52 + // Call the stubcode via a direct branch-and-link 1.53 + masm.ma_blx(r0); 1.54 +} 1.55 + 1.56 +inline void 1.57 +EmitEnterTypeMonitorIC(MacroAssembler &masm, 1.58 + size_t monitorStubOffset = ICMonitoredStub::offsetOfFirstMonitorStub()) 1.59 +{ 1.60 + // This is expected to be called from within an IC, when BaselineStubReg 1.61 + // is properly initialized to point to the stub. 1.62 + masm.loadPtr(Address(BaselineStubReg, (uint32_t) monitorStubOffset), BaselineStubReg); 1.63 + 1.64 + // Load stubcode pointer from BaselineStubEntry. 1.65 + // R2 won't be active when we call ICs, so we can use r0. 1.66 + JS_ASSERT(R2 == ValueOperand(r1, r0)); 1.67 + masm.loadPtr(Address(BaselineStubReg, ICStub::offsetOfStubCode()), r0); 1.68 + 1.69 + // Jump to the stubcode. 1.70 + masm.branch(r0); 1.71 +} 1.72 + 1.73 +inline void 1.74 +EmitReturnFromIC(MacroAssembler &masm) 1.75 +{ 1.76 + masm.ma_mov(lr, pc); 1.77 +} 1.78 + 1.79 +inline void 1.80 +EmitChangeICReturnAddress(MacroAssembler &masm, Register reg) 1.81 +{ 1.82 + masm.ma_mov(reg, lr); 1.83 +} 1.84 + 1.85 +inline void 1.86 +EmitTailCallVM(JitCode *target, MacroAssembler &masm, uint32_t argSize) 1.87 +{ 1.88 + // We assume during this that R0 and R1 have been pushed, and that R2 is 1.89 + // unused. 1.90 + JS_ASSERT(R2 == ValueOperand(r1, r0)); 1.91 + 1.92 + // Compute frame size. 1.93 + masm.movePtr(BaselineFrameReg, r0); 1.94 + masm.ma_add(Imm32(BaselineFrame::FramePointerOffset), r0); 1.95 + masm.ma_sub(BaselineStackReg, r0); 1.96 + 1.97 + // Store frame size without VMFunction arguments for GC marking. 1.98 + masm.ma_sub(r0, Imm32(argSize), r1); 1.99 + masm.store32(r1, Address(BaselineFrameReg, BaselineFrame::reverseOffsetOfFrameSize())); 1.100 + 1.101 + // Push frame descriptor and perform the tail call. 1.102 + // BaselineTailCallReg (lr) already contains the return address (as we keep it there through 1.103 + // the stub calls), but the VMWrapper code being called expects the return address to also 1.104 + // be pushed on the stack. 1.105 + JS_ASSERT(BaselineTailCallReg == lr); 1.106 + masm.makeFrameDescriptor(r0, JitFrame_BaselineJS); 1.107 + masm.push(r0); 1.108 + masm.push(lr); 1.109 + masm.branch(target); 1.110 +} 1.111 + 1.112 +inline void 1.113 +EmitCreateStubFrameDescriptor(MacroAssembler &masm, Register reg) 1.114 +{ 1.115 + // Compute stub frame size. We have to add two pointers: the stub reg and previous 1.116 + // frame pointer pushed by EmitEnterStubFrame. 1.117 + masm.mov(BaselineFrameReg, reg); 1.118 + masm.ma_add(Imm32(sizeof(void *) * 2), reg); 1.119 + masm.ma_sub(BaselineStackReg, reg); 1.120 + 1.121 + masm.makeFrameDescriptor(reg, JitFrame_BaselineStub); 1.122 +} 1.123 + 1.124 +inline void 1.125 +EmitCallVM(JitCode *target, MacroAssembler &masm) 1.126 +{ 1.127 + EmitCreateStubFrameDescriptor(masm, r0); 1.128 + masm.push(r0); 1.129 + masm.call(target); 1.130 +} 1.131 + 1.132 +// Size of vales pushed by EmitEnterStubFrame. 1.133 +static const uint32_t STUB_FRAME_SIZE = 4 * sizeof(void *); 1.134 +static const uint32_t STUB_FRAME_SAVED_STUB_OFFSET = sizeof(void *); 1.135 + 1.136 +inline void 1.137 +EmitEnterStubFrame(MacroAssembler &masm, Register scratch) 1.138 +{ 1.139 + JS_ASSERT(scratch != BaselineTailCallReg); 1.140 + 1.141 + // Compute frame size. 1.142 + masm.mov(BaselineFrameReg, scratch); 1.143 + masm.ma_add(Imm32(BaselineFrame::FramePointerOffset), scratch); 1.144 + masm.ma_sub(BaselineStackReg, scratch); 1.145 + 1.146 + masm.store32(scratch, Address(BaselineFrameReg, BaselineFrame::reverseOffsetOfFrameSize())); 1.147 + 1.148 + // Note: when making changes here, don't forget to update STUB_FRAME_SIZE 1.149 + // if needed. 1.150 + 1.151 + // Push frame descriptor and return address. 1.152 + masm.makeFrameDescriptor(scratch, JitFrame_BaselineJS); 1.153 + masm.push(scratch); 1.154 + masm.push(BaselineTailCallReg); 1.155 + 1.156 + // Save old frame pointer, stack pointer and stub reg. 1.157 + masm.push(BaselineStubReg); 1.158 + masm.push(BaselineFrameReg); 1.159 + masm.mov(BaselineStackReg, BaselineFrameReg); 1.160 + 1.161 + // We pushed 4 words, so the stack is still aligned to 8 bytes. 1.162 + masm.checkStackAlignment(); 1.163 +} 1.164 + 1.165 +inline void 1.166 +EmitLeaveStubFrameHead(MacroAssembler &masm, bool calledIntoIon = false) 1.167 +{ 1.168 + // Ion frames do not save and restore the frame pointer. If we called 1.169 + // into Ion, we have to restore the stack pointer from the frame descriptor. 1.170 + // If we performed a VM call, the descriptor has been popped already so 1.171 + // in that case we use the frame pointer. 1.172 + if (calledIntoIon) { 1.173 + masm.pop(ScratchRegister); 1.174 + masm.ma_lsr(Imm32(FRAMESIZE_SHIFT), ScratchRegister, ScratchRegister); 1.175 + masm.ma_add(ScratchRegister, BaselineStackReg); 1.176 + } else { 1.177 + masm.mov(BaselineFrameReg, BaselineStackReg); 1.178 + } 1.179 +} 1.180 + 1.181 +inline void 1.182 +EmitLeaveStubFrameCommonTail(MacroAssembler &masm) 1.183 +{ 1.184 + masm.pop(BaselineFrameReg); 1.185 + masm.pop(BaselineStubReg); 1.186 + 1.187 + // Load the return address. 1.188 + masm.pop(BaselineTailCallReg); 1.189 + 1.190 + // Discard the frame descriptor. 1.191 + masm.pop(ScratchRegister); 1.192 +} 1.193 + 1.194 +inline void 1.195 +EmitLeaveStubFrame(MacroAssembler &masm, bool calledIntoIon = false) 1.196 +{ 1.197 + EmitLeaveStubFrameHead(masm, calledIntoIon); 1.198 + EmitLeaveStubFrameCommonTail(masm); 1.199 +} 1.200 + 1.201 +inline void 1.202 +EmitStowICValues(MacroAssembler &masm, int values) 1.203 +{ 1.204 + JS_ASSERT(values >= 0 && values <= 2); 1.205 + switch(values) { 1.206 + case 1: 1.207 + // Stow R0 1.208 + masm.pushValue(R0); 1.209 + break; 1.210 + case 2: 1.211 + // Stow R0 and R1 1.212 + masm.pushValue(R0); 1.213 + masm.pushValue(R1); 1.214 + break; 1.215 + } 1.216 +} 1.217 + 1.218 +inline void 1.219 +EmitUnstowICValues(MacroAssembler &masm, int values, bool discard = false) 1.220 +{ 1.221 + JS_ASSERT(values >= 0 && values <= 2); 1.222 + switch(values) { 1.223 + case 1: 1.224 + // Unstow R0 1.225 + if (discard) 1.226 + masm.addPtr(Imm32(sizeof(Value)), BaselineStackReg); 1.227 + else 1.228 + masm.popValue(R0); 1.229 + break; 1.230 + case 2: 1.231 + // Unstow R0 and R1 1.232 + if (discard) { 1.233 + masm.addPtr(Imm32(sizeof(Value) * 2), BaselineStackReg); 1.234 + } else { 1.235 + masm.popValue(R1); 1.236 + masm.popValue(R0); 1.237 + } 1.238 + break; 1.239 + } 1.240 +} 1.241 + 1.242 +inline void 1.243 +EmitCallTypeUpdateIC(MacroAssembler &masm, JitCode *code, uint32_t objectOffset) 1.244 +{ 1.245 + JS_ASSERT(R2 == ValueOperand(r1, r0)); 1.246 + 1.247 + // R0 contains the value that needs to be typechecked. 1.248 + // The object we're updating is a boxed Value on the stack, at offset 1.249 + // objectOffset from esp, excluding the return address. 1.250 + 1.251 + // Save the current BaselineStubReg to stack, as well as the TailCallReg, 1.252 + // since on ARM, the LR is live. 1.253 + masm.push(BaselineStubReg); 1.254 + masm.push(BaselineTailCallReg); 1.255 + 1.256 + // This is expected to be called from within an IC, when BaselineStubReg 1.257 + // is properly initialized to point to the stub. 1.258 + masm.loadPtr(Address(BaselineStubReg, ICUpdatedStub::offsetOfFirstUpdateStub()), 1.259 + BaselineStubReg); 1.260 + 1.261 + // TODO: Change r0 uses below to use masm's configurable scratch register instead. 1.262 + 1.263 + // Load stubcode pointer from BaselineStubReg into BaselineTailCallReg. 1.264 + masm.loadPtr(Address(BaselineStubReg, ICStub::offsetOfStubCode()), r0); 1.265 + 1.266 + // Call the stubcode. 1.267 + masm.ma_blx(r0); 1.268 + 1.269 + // Restore the old stub reg and tailcall reg. 1.270 + masm.pop(BaselineTailCallReg); 1.271 + masm.pop(BaselineStubReg); 1.272 + 1.273 + // The update IC will store 0 or 1 in R1.scratchReg() reflecting if the 1.274 + // value in R0 type-checked properly or not. 1.275 + Label success; 1.276 + masm.cmp32(R1.scratchReg(), Imm32(1)); 1.277 + masm.j(Assembler::Equal, &success); 1.278 + 1.279 + // If the IC failed, then call the update fallback function. 1.280 + EmitEnterStubFrame(masm, R1.scratchReg()); 1.281 + 1.282 + masm.loadValue(Address(BaselineStackReg, STUB_FRAME_SIZE + objectOffset), R1); 1.283 + 1.284 + masm.pushValue(R0); 1.285 + masm.pushValue(R1); 1.286 + masm.push(BaselineStubReg); 1.287 + 1.288 + // Load previous frame pointer, push BaselineFrame *. 1.289 + masm.loadPtr(Address(BaselineFrameReg, 0), R0.scratchReg()); 1.290 + masm.pushBaselineFramePtr(R0.scratchReg(), R0.scratchReg()); 1.291 + 1.292 + EmitCallVM(code, masm); 1.293 + EmitLeaveStubFrame(masm); 1.294 + 1.295 + // Success at end. 1.296 + masm.bind(&success); 1.297 +} 1.298 + 1.299 +template <typename AddrType> 1.300 +inline void 1.301 +EmitPreBarrier(MacroAssembler &masm, const AddrType &addr, MIRType type) 1.302 +{ 1.303 + // on ARM, lr is clobbered by patchableCallPreBarrier. Save it first. 1.304 + masm.push(lr); 1.305 + masm.patchableCallPreBarrier(addr, type); 1.306 + masm.pop(lr); 1.307 +} 1.308 + 1.309 +inline void 1.310 +EmitStubGuardFailure(MacroAssembler &masm) 1.311 +{ 1.312 + JS_ASSERT(R2 == ValueOperand(r1, r0)); 1.313 + 1.314 + // NOTE: This routine assumes that the stub guard code left the stack in the 1.315 + // same state it was in when it was entered. 1.316 + 1.317 + // BaselineStubEntry points to the current stub. 1.318 + 1.319 + // Load next stub into BaselineStubReg 1.320 + masm.loadPtr(Address(BaselineStubReg, ICStub::offsetOfNext()), BaselineStubReg); 1.321 + 1.322 + // Load stubcode pointer from BaselineStubEntry into scratch register. 1.323 + masm.loadPtr(Address(BaselineStubReg, ICStub::offsetOfStubCode()), r0); 1.324 + 1.325 + // Return address is already loaded, just jump to the next stubcode. 1.326 + JS_ASSERT(BaselineTailCallReg == lr); 1.327 + masm.branch(r0); 1.328 +} 1.329 + 1.330 + 1.331 +} // namespace jit 1.332 +} // namespace js 1.333 + 1.334 +#endif // JS_ION 1.335 + 1.336 +#endif /* jit_arm_BaselineHelpers_arm_h */ 1.337 +