Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 2 | // Copyright 2011 the V8 project authors. All rights reserved. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3 | // Use of this source code is governed by a BSD-style license that can be |
| 4 | // found in the LICENSE file. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 5 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6 | #include "src/v8.h" |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 7 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8 | #include "src/codegen.h" |
| 9 | #include "src/deoptimizer.h" |
| 10 | #include "src/full-codegen.h" |
| 11 | #include "src/safepoint-table.h" |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 12 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 13 | namespace v8 { |
| 14 | namespace internal { |
| 15 | |
| 16 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 17 | int Deoptimizer::patch_size() { |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 18 | const int kCallInstructionSizeInWords = 4; |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 19 | return kCallInstructionSizeInWords * Assembler::kInstrSize; |
| 20 | } |
| 21 | |
| 22 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 23 | void Deoptimizer::EnsureRelocSpaceForLazyDeoptimization(Handle<Code> code) { |
| 24 | // Empty because there is no need for relocation information for the code |
| 25 | // patching in Deoptimizer::PatchCodeForDeoptimization below. |
| 26 | } |
| 27 | |
| 28 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 29 | void Deoptimizer::PatchCodeForDeoptimization(Isolate* isolate, Code* code) { |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 30 | Address code_start_address = code->instruction_start(); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 31 | // Invalidate the relocation information, as it will become invalid by the |
| 32 | // code patching below, and is not needed any more. |
| 33 | code->InvalidateRelocation(); |
| 34 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 35 | if (FLAG_zap_code_space) { |
| 36 | // Fail hard and early if we enter this code object again. |
| 37 | byte* pointer = code->FindCodeAgeSequence(); |
| 38 | if (pointer != NULL) { |
| 39 | pointer += kNoCodeAgeSequenceLength; |
| 40 | } else { |
| 41 | pointer = code->instruction_start(); |
| 42 | } |
| 43 | CodePatcher patcher(pointer, 1); |
| 44 | patcher.masm()->break_(0xCC); |
| 45 | |
| 46 | DeoptimizationInputData* data = |
| 47 | DeoptimizationInputData::cast(code->deoptimization_data()); |
| 48 | int osr_offset = data->OsrPcOffset()->value(); |
| 49 | if (osr_offset > 0) { |
| 50 | CodePatcher osr_patcher(code->instruction_start() + osr_offset, 1); |
| 51 | osr_patcher.masm()->break_(0xCC); |
| 52 | } |
| 53 | } |
| 54 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 55 | DeoptimizationInputData* deopt_data = |
| 56 | DeoptimizationInputData::cast(code->deoptimization_data()); |
| 57 | #ifdef DEBUG |
| 58 | Address prev_call_address = NULL; |
| 59 | #endif |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 60 | // For each LLazyBailout instruction insert a call to the corresponding |
| 61 | // deoptimization entry. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 62 | for (int i = 0; i < deopt_data->DeoptCount(); i++) { |
| 63 | if (deopt_data->Pc(i)->value() == -1) continue; |
| 64 | Address call_address = code_start_address + deopt_data->Pc(i)->value(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 65 | Address deopt_entry = GetDeoptimizationEntry(isolate, i, LAZY); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 66 | int call_size_in_bytes = MacroAssembler::CallSize(deopt_entry, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 67 | RelocInfo::NONE32); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 68 | int call_size_in_words = call_size_in_bytes / Assembler::kInstrSize; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 69 | DCHECK(call_size_in_bytes % Assembler::kInstrSize == 0); |
| 70 | DCHECK(call_size_in_bytes <= patch_size()); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 71 | CodePatcher patcher(call_address, call_size_in_words); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 72 | patcher.masm()->Call(deopt_entry, RelocInfo::NONE32); |
| 73 | DCHECK(prev_call_address == NULL || |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 74 | call_address >= prev_call_address + patch_size()); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 75 | DCHECK(call_address + patch_size() <= code->instruction_end()); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 76 | |
| 77 | #ifdef DEBUG |
| 78 | prev_call_address = call_address; |
| 79 | #endif |
| 80 | } |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 81 | } |
| 82 | |
| 83 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 84 | void Deoptimizer::FillInputFrame(Address tos, JavaScriptFrame* frame) { |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 85 | // Set the register values. The values are not important as there are no |
| 86 | // callee saved registers in JavaScript frames, so all registers are |
| 87 | // spilled. Registers fp and sp are set to the correct values though. |
| 88 | |
| 89 | for (int i = 0; i < Register::kNumRegisters; i++) { |
| 90 | input_->SetRegister(i, i * 4); |
| 91 | } |
| 92 | input_->SetRegister(sp.code(), reinterpret_cast<intptr_t>(frame->sp())); |
| 93 | input_->SetRegister(fp.code(), reinterpret_cast<intptr_t>(frame->fp())); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 94 | for (int i = 0; i < DoubleRegister::NumAllocatableRegisters(); i++) { |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 95 | input_->SetDoubleRegister(i, 0.0); |
| 96 | } |
| 97 | |
| 98 | // Fill the frame content from the actual data on the frame. |
| 99 | for (unsigned i = 0; i < input_->GetFrameSize(); i += kPointerSize) { |
| 100 | input_->SetFrameSlot(i, Memory::uint32_at(tos + i)); |
| 101 | } |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 102 | } |
| 103 | |
| 104 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 105 | void Deoptimizer::SetPlatformCompiledStubRegisters( |
| 106 | FrameDescription* output_frame, CodeStubDescriptor* descriptor) { |
| 107 | ApiFunction function(descriptor->deoptimization_handler()); |
| 108 | ExternalReference xref(&function, ExternalReference::BUILTIN_CALL, isolate_); |
| 109 | intptr_t handler = reinterpret_cast<intptr_t>(xref.address()); |
| 110 | int params = descriptor->GetHandlerParameterCount(); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 111 | output_frame->SetRegister(a0.code(), params); |
| 112 | output_frame->SetRegister(a1.code(), handler); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 113 | } |
| 114 | |
| 115 | |
| 116 | void Deoptimizer::CopyDoubleRegisters(FrameDescription* output_frame) { |
| 117 | for (int i = 0; i < DoubleRegister::kMaxNumRegisters; ++i) { |
| 118 | double double_value = input_->GetDoubleRegister(i); |
| 119 | output_frame->SetDoubleRegister(i, double_value); |
| 120 | } |
| 121 | } |
| 122 | |
| 123 | |
| 124 | bool Deoptimizer::HasAlignmentPadding(JSFunction* function) { |
| 125 | // There is no dynamic alignment padding on MIPS in the input frame. |
| 126 | return false; |
| 127 | } |
| 128 | |
| 129 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 130 | #define __ masm()-> |
| 131 | |
| 132 | |
| 133 | // This code tries to be close to ia32 code so that any changes can be |
| 134 | // easily ported. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 135 | void Deoptimizer::EntryGenerator::Generate() { |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 136 | GeneratePrologue(); |
| 137 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 138 | // Unlike on ARM we don't save all the registers, just the useful ones. |
| 139 | // For the rest, there are gaps on the stack, so the offsets remain the same. |
| 140 | const int kNumberOfRegisters = Register::kNumRegisters; |
| 141 | |
| 142 | RegList restored_regs = kJSCallerSaved | kCalleeSaved; |
| 143 | RegList saved_regs = restored_regs | sp.bit() | ra.bit(); |
| 144 | |
| 145 | const int kDoubleRegsSize = |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 146 | kDoubleSize * FPURegister::kMaxNumAllocatableRegisters; |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 147 | |
| 148 | // Save all FPU registers before messing with them. |
| 149 | __ Subu(sp, sp, Operand(kDoubleRegsSize)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 150 | for (int i = 0; i < FPURegister::kMaxNumAllocatableRegisters; ++i) { |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 151 | FPURegister fpu_reg = FPURegister::FromAllocationIndex(i); |
| 152 | int offset = i * kDoubleSize; |
| 153 | __ sdc1(fpu_reg, MemOperand(sp, offset)); |
| 154 | } |
| 155 | |
| 156 | // Push saved_regs (needed to populate FrameDescription::registers_). |
| 157 | // Leave gaps for other registers. |
| 158 | __ Subu(sp, sp, kNumberOfRegisters * kPointerSize); |
| 159 | for (int16_t i = kNumberOfRegisters - 1; i >= 0; i--) { |
| 160 | if ((saved_regs & (1 << i)) != 0) { |
| 161 | __ sw(ToRegister(i), MemOperand(sp, kPointerSize * i)); |
| 162 | } |
| 163 | } |
| 164 | |
| 165 | const int kSavedRegistersAreaSize = |
| 166 | (kNumberOfRegisters * kPointerSize) + kDoubleRegsSize; |
| 167 | |
| 168 | // Get the bailout id from the stack. |
| 169 | __ lw(a2, MemOperand(sp, kSavedRegistersAreaSize)); |
| 170 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 171 | // Get the address of the location in the code object (a3) (return |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 172 | // address for lazy deoptimization) and compute the fp-to-sp delta in |
| 173 | // register t0. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 174 | __ mov(a3, ra); |
| 175 | // Correct one word for bailout id. |
| 176 | __ Addu(t0, sp, Operand(kSavedRegistersAreaSize + (1 * kPointerSize))); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 177 | |
| 178 | __ Subu(t0, fp, t0); |
| 179 | |
| 180 | // Allocate a new deoptimizer object. |
| 181 | // Pass four arguments in a0 to a3 and fifth & sixth arguments on stack. |
| 182 | __ PrepareCallCFunction(6, t1); |
| 183 | __ lw(a0, MemOperand(fp, JavaScriptFrameConstants::kFunctionOffset)); |
| 184 | __ li(a1, Operand(type())); // bailout type, |
| 185 | // a2: bailout id already loaded. |
| 186 | // a3: code address or 0 already loaded. |
| 187 | __ sw(t0, CFunctionArgumentOperand(5)); // Fp-to-sp delta. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 188 | __ li(t1, Operand(ExternalReference::isolate_address(isolate()))); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 189 | __ sw(t1, CFunctionArgumentOperand(6)); // Isolate. |
| 190 | // Call Deoptimizer::New(). |
| 191 | { |
| 192 | AllowExternalCallThatCantCauseGC scope(masm()); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 193 | __ CallCFunction(ExternalReference::new_deoptimizer_function(isolate()), 6); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 194 | } |
| 195 | |
| 196 | // Preserve "deoptimizer" object in register v0 and get the input |
| 197 | // frame descriptor pointer to a1 (deoptimizer->input_); |
| 198 | // Move deopt-obj to a0 for call to Deoptimizer::ComputeOutputFrames() below. |
| 199 | __ mov(a0, v0); |
| 200 | __ lw(a1, MemOperand(v0, Deoptimizer::input_offset())); |
| 201 | |
| 202 | // Copy core registers into FrameDescription::registers_[kNumRegisters]. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 203 | DCHECK(Register::kNumRegisters == kNumberOfRegisters); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 204 | for (int i = 0; i < kNumberOfRegisters; i++) { |
| 205 | int offset = (i * kPointerSize) + FrameDescription::registers_offset(); |
| 206 | if ((saved_regs & (1 << i)) != 0) { |
| 207 | __ lw(a2, MemOperand(sp, i * kPointerSize)); |
| 208 | __ sw(a2, MemOperand(a1, offset)); |
| 209 | } else if (FLAG_debug_code) { |
| 210 | __ li(a2, kDebugZapValue); |
| 211 | __ sw(a2, MemOperand(a1, offset)); |
| 212 | } |
| 213 | } |
| 214 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 215 | int double_regs_offset = FrameDescription::double_registers_offset(); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 216 | // Copy FPU registers to |
| 217 | // double_registers_[DoubleRegister::kNumAllocatableRegisters] |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 218 | for (int i = 0; i < FPURegister::NumAllocatableRegisters(); ++i) { |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 219 | int dst_offset = i * kDoubleSize + double_regs_offset; |
| 220 | int src_offset = i * kDoubleSize + kNumberOfRegisters * kPointerSize; |
| 221 | __ ldc1(f0, MemOperand(sp, src_offset)); |
| 222 | __ sdc1(f0, MemOperand(a1, dst_offset)); |
| 223 | } |
| 224 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 225 | // Remove the bailout id and the saved registers from the stack. |
| 226 | __ Addu(sp, sp, Operand(kSavedRegistersAreaSize + (1 * kPointerSize))); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 227 | |
| 228 | // Compute a pointer to the unwinding limit in register a2; that is |
| 229 | // the first stack slot not part of the input frame. |
| 230 | __ lw(a2, MemOperand(a1, FrameDescription::frame_size_offset())); |
| 231 | __ Addu(a2, a2, sp); |
| 232 | |
| 233 | // Unwind the stack down to - but not including - the unwinding |
| 234 | // limit and copy the contents of the activation frame to the input |
| 235 | // frame description. |
| 236 | __ Addu(a3, a1, Operand(FrameDescription::frame_content_offset())); |
| 237 | Label pop_loop; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 238 | Label pop_loop_header; |
| 239 | __ BranchShort(&pop_loop_header); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 240 | __ bind(&pop_loop); |
| 241 | __ pop(t0); |
| 242 | __ sw(t0, MemOperand(a3, 0)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 243 | __ addiu(a3, a3, sizeof(uint32_t)); |
| 244 | __ bind(&pop_loop_header); |
| 245 | __ BranchShort(&pop_loop, ne, a2, Operand(sp)); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 246 | |
| 247 | // Compute the output frame in the deoptimizer. |
| 248 | __ push(a0); // Preserve deoptimizer object across call. |
| 249 | // a0: deoptimizer object; a1: scratch. |
| 250 | __ PrepareCallCFunction(1, a1); |
| 251 | // Call Deoptimizer::ComputeOutputFrames(). |
| 252 | { |
| 253 | AllowExternalCallThatCantCauseGC scope(masm()); |
| 254 | __ CallCFunction( |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 255 | ExternalReference::compute_output_frames_function(isolate()), 1); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 256 | } |
| 257 | __ pop(a0); // Restore deoptimizer object (class Deoptimizer). |
| 258 | |
| 259 | // Replace the current (input) frame with the output frames. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 260 | Label outer_push_loop, inner_push_loop, |
| 261 | outer_loop_header, inner_loop_header; |
| 262 | // Outer loop state: t0 = current "FrameDescription** output_", |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 263 | // a1 = one past the last FrameDescription**. |
| 264 | __ lw(a1, MemOperand(a0, Deoptimizer::output_count_offset())); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 265 | __ lw(t0, MemOperand(a0, Deoptimizer::output_offset())); // t0 is output_. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 266 | __ sll(a1, a1, kPointerSizeLog2); // Count to offset. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 267 | __ addu(a1, t0, a1); // a1 = one past the last FrameDescription**. |
| 268 | __ jmp(&outer_loop_header); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 269 | __ bind(&outer_push_loop); |
| 270 | // Inner loop state: a2 = current FrameDescription*, a3 = loop index. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 271 | __ lw(a2, MemOperand(t0, 0)); // output_[ix] |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 272 | __ lw(a3, MemOperand(a2, FrameDescription::frame_size_offset())); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 273 | __ jmp(&inner_loop_header); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 274 | __ bind(&inner_push_loop); |
| 275 | __ Subu(a3, a3, Operand(sizeof(uint32_t))); |
| 276 | __ Addu(t2, a2, Operand(a3)); |
| 277 | __ lw(t3, MemOperand(t2, FrameDescription::frame_content_offset())); |
| 278 | __ push(t3); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 279 | __ bind(&inner_loop_header); |
| 280 | __ BranchShort(&inner_push_loop, ne, a3, Operand(zero_reg)); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 281 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 282 | __ Addu(t0, t0, Operand(kPointerSize)); |
| 283 | __ bind(&outer_loop_header); |
| 284 | __ BranchShort(&outer_push_loop, lt, t0, Operand(a1)); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 285 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 286 | __ lw(a1, MemOperand(a0, Deoptimizer::input_offset())); |
| 287 | for (int i = 0; i < FPURegister::kMaxNumAllocatableRegisters; ++i) { |
| 288 | const FPURegister fpu_reg = FPURegister::FromAllocationIndex(i); |
| 289 | int src_offset = i * kDoubleSize + double_regs_offset; |
| 290 | __ ldc1(fpu_reg, MemOperand(a1, src_offset)); |
| 291 | } |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 292 | |
| 293 | // Push state, pc, and continuation from the last output frame. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 294 | __ lw(t2, MemOperand(a2, FrameDescription::state_offset())); |
| 295 | __ push(t2); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 296 | |
| 297 | __ lw(t2, MemOperand(a2, FrameDescription::pc_offset())); |
| 298 | __ push(t2); |
| 299 | __ lw(t2, MemOperand(a2, FrameDescription::continuation_offset())); |
| 300 | __ push(t2); |
| 301 | |
| 302 | |
| 303 | // Technically restoring 'at' should work unless zero_reg is also restored |
| 304 | // but it's safer to check for this. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 305 | DCHECK(!(at.bit() & restored_regs)); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 306 | // Restore the registers from the last output frame. |
| 307 | __ mov(at, a2); |
| 308 | for (int i = kNumberOfRegisters - 1; i >= 0; i--) { |
| 309 | int offset = (i * kPointerSize) + FrameDescription::registers_offset(); |
| 310 | if ((restored_regs & (1 << i)) != 0) { |
| 311 | __ lw(ToRegister(i), MemOperand(at, offset)); |
| 312 | } |
| 313 | } |
| 314 | |
| 315 | __ InitializeRootRegister(); |
| 316 | |
| 317 | __ pop(at); // Get continuation, leave pc on stack. |
| 318 | __ pop(ra); |
| 319 | __ Jump(at); |
| 320 | __ stop("Unreachable."); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 321 | } |
| 322 | |
| 323 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 324 | // Maximum size of a table entry generated below. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 325 | const int Deoptimizer::table_entry_size_ = 2 * Assembler::kInstrSize; |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 326 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 327 | void Deoptimizer::TableEntryGenerator::GeneratePrologue() { |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 328 | Assembler::BlockTrampolinePoolScope block_trampoline_pool(masm()); |
| 329 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 330 | // Create a sequence of deoptimization entries. |
| 331 | // Note that registers are still live when jumping to an entry. |
| 332 | Label table_start, done, done_special, trampoline_jump; |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 333 | __ bind(&table_start); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 334 | int kMaxEntriesBranchReach = (1 << (kImm16Bits - 2))/ |
| 335 | (table_entry_size_ / Assembler::kInstrSize); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 336 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 337 | if (count() <= kMaxEntriesBranchReach) { |
| 338 | // Common case. |
| 339 | for (int i = 0; i < count(); i++) { |
| 340 | Label start; |
| 341 | __ bind(&start); |
| 342 | DCHECK(is_int16(i)); |
| 343 | __ Branch(USE_DELAY_SLOT, &done); // Expose delay slot. |
| 344 | __ li(at, i); // In the delay slot. |
| 345 | |
| 346 | DCHECK_EQ(table_entry_size_, masm()->SizeOfCodeGeneratedSince(&start)); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 347 | } |
| 348 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 349 | DCHECK_EQ(masm()->SizeOfCodeGeneratedSince(&table_start), |
| 350 | count() * table_entry_size_); |
| 351 | __ bind(&done); |
| 352 | __ Push(at); |
| 353 | } else { |
| 354 | // Uncommon case, the branch cannot reach. |
| 355 | // Create mini trampoline and adjust id constants to get proper value at |
| 356 | // the end of table. |
| 357 | for (int i = kMaxEntriesBranchReach; i > 1; i--) { |
| 358 | Label start; |
| 359 | __ bind(&start); |
| 360 | DCHECK(is_int16(i)); |
| 361 | __ Branch(USE_DELAY_SLOT, &trampoline_jump); // Expose delay slot. |
| 362 | __ li(at, - i); // In the delay slot. |
| 363 | DCHECK_EQ(table_entry_size_, masm()->SizeOfCodeGeneratedSince(&start)); |
| 364 | } |
| 365 | // Entry with id == kMaxEntriesBranchReach - 1. |
| 366 | __ bind(&trampoline_jump); |
| 367 | __ Branch(USE_DELAY_SLOT, &done_special); |
| 368 | __ li(at, -1); |
| 369 | |
| 370 | for (int i = kMaxEntriesBranchReach ; i < count(); i++) { |
| 371 | Label start; |
| 372 | __ bind(&start); |
| 373 | DCHECK(is_int16(i)); |
| 374 | __ Branch(USE_DELAY_SLOT, &done); // Expose delay slot. |
| 375 | __ li(at, i); // In the delay slot. |
| 376 | } |
| 377 | |
| 378 | DCHECK_EQ(masm()->SizeOfCodeGeneratedSince(&table_start), |
| 379 | count() * table_entry_size_); |
| 380 | __ bind(&done_special); |
| 381 | __ addiu(at, at, kMaxEntriesBranchReach); |
| 382 | __ bind(&done); |
| 383 | __ Push(at); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 384 | } |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 385 | } |
| 386 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 387 | |
| 388 | void FrameDescription::SetCallerPc(unsigned offset, intptr_t value) { |
| 389 | SetFrameSlot(offset, value); |
| 390 | } |
| 391 | |
| 392 | |
| 393 | void FrameDescription::SetCallerFp(unsigned offset, intptr_t value) { |
| 394 | SetFrameSlot(offset, value); |
| 395 | } |
| 396 | |
| 397 | |
| 398 | void FrameDescription::SetCallerConstantPool(unsigned offset, intptr_t value) { |
| 399 | // No out-of-line constant pool support. |
| 400 | UNREACHABLE(); |
| 401 | } |
| 402 | |
| 403 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 404 | #undef __ |
| 405 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 406 | |
| 407 | } } // namespace v8::internal |