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