OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #if V8_TARGET_ARCH_ARM | 5 #if V8_TARGET_ARCH_ARM |
6 | 6 |
7 #include "src/ast/scopes.h" | 7 #include "src/ast/scopes.h" |
8 #include "src/code-factory.h" | 8 #include "src/code-factory.h" |
9 #include "src/code-stubs.h" | 9 #include "src/code-stubs.h" |
10 #include "src/codegen.h" | 10 #include "src/codegen.h" |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
85 }; | 85 }; |
86 | 86 |
87 | 87 |
88 // Generate code for a JS function. On entry to the function the receiver | 88 // Generate code for a JS function. On entry to the function the receiver |
89 // and arguments have been pushed on the stack left to right. The actual | 89 // and arguments have been pushed on the stack left to right. The actual |
90 // argument count matches the formal parameter count expected by the | 90 // argument count matches the formal parameter count expected by the |
91 // function. | 91 // function. |
92 // | 92 // |
93 // The live registers are: | 93 // The live registers are: |
94 // o r1: the JS function object being called (i.e., ourselves) | 94 // o r1: the JS function object being called (i.e., ourselves) |
| 95 // o r3: the new target value |
95 // o cp: our context | 96 // o cp: our context |
96 // o pp: our caller's constant pool pointer (if enabled) | 97 // o pp: our caller's constant pool pointer (if enabled) |
97 // o fp: our caller's frame pointer | 98 // o fp: our caller's frame pointer |
98 // o sp: stack pointer | 99 // o sp: stack pointer |
99 // o lr: return address | 100 // o lr: return address |
100 // | 101 // |
101 // The function builds a JS frame. Please see JavaScriptFrameConstants in | 102 // The function builds a JS frame. Please see JavaScriptFrameConstants in |
102 // frames-arm.h for its layout. | 103 // frames-arm.h for its layout. |
103 void FullCodeGenerator::Generate() { | 104 void FullCodeGenerator::Generate() { |
104 CompilationInfo* info = info_; | 105 CompilationInfo* info = info_; |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
175 if (info->scope()->num_heap_slots() > 0) { | 176 if (info->scope()->num_heap_slots() > 0) { |
176 // Argument to NewContext is the function, which is still in r1. | 177 // Argument to NewContext is the function, which is still in r1. |
177 Comment cmnt(masm_, "[ Allocate context"); | 178 Comment cmnt(masm_, "[ Allocate context"); |
178 bool need_write_barrier = true; | 179 bool need_write_barrier = true; |
179 int slots = info->scope()->num_heap_slots() - Context::MIN_CONTEXT_SLOTS; | 180 int slots = info->scope()->num_heap_slots() - Context::MIN_CONTEXT_SLOTS; |
180 if (info->scope()->is_script_scope()) { | 181 if (info->scope()->is_script_scope()) { |
181 __ push(r1); | 182 __ push(r1); |
182 __ Push(info->scope()->GetScopeInfo(info->isolate())); | 183 __ Push(info->scope()->GetScopeInfo(info->isolate())); |
183 __ CallRuntime(Runtime::kNewScriptContext, 2); | 184 __ CallRuntime(Runtime::kNewScriptContext, 2); |
184 PrepareForBailoutForId(BailoutId::ScriptContext(), TOS_REG); | 185 PrepareForBailoutForId(BailoutId::ScriptContext(), TOS_REG); |
185 } else if (slots <= FastNewContextStub::kMaximumSlots) { | 186 // The new target value is not used, clobbering is safe. |
186 FastNewContextStub stub(isolate(), slots); | 187 DCHECK_NULL(info->scope()->new_target_var()); |
187 __ CallStub(&stub); | |
188 // Result of FastNewContextStub is always in new space. | |
189 need_write_barrier = false; | |
190 } else { | 188 } else { |
191 __ push(r1); | 189 if (info->scope()->new_target_var() != nullptr) { |
192 __ CallRuntime(Runtime::kNewFunctionContext, 1); | 190 __ push(r3); // Preserve new target. |
| 191 } |
| 192 if (slots <= FastNewContextStub::kMaximumSlots) { |
| 193 FastNewContextStub stub(isolate(), slots); |
| 194 __ CallStub(&stub); |
| 195 // Result of FastNewContextStub is always in new space. |
| 196 need_write_barrier = false; |
| 197 } else { |
| 198 __ push(r1); |
| 199 __ CallRuntime(Runtime::kNewFunctionContext, 1); |
| 200 } |
| 201 if (info->scope()->new_target_var() != nullptr) { |
| 202 __ pop(r3); // Preserve new target. |
| 203 } |
193 } | 204 } |
194 function_in_register_r1 = false; | 205 function_in_register_r1 = false; |
195 // Context is returned in r0. It replaces the context passed to us. | 206 // Context is returned in r0. It replaces the context passed to us. |
196 // It's saved in the stack and kept live in cp. | 207 // It's saved in the stack and kept live in cp. |
197 __ mov(cp, r0); | 208 __ mov(cp, r0); |
198 __ str(r0, MemOperand(fp, StandardFrameConstants::kContextOffset)); | 209 __ str(r0, MemOperand(fp, StandardFrameConstants::kContextOffset)); |
199 // Copy any necessary parameters into the context. | 210 // Copy any necessary parameters into the context. |
200 int num_parameters = info->scope()->num_parameters(); | 211 int num_parameters = info->scope()->num_parameters(); |
201 int first_parameter = info->scope()->has_this_declaration() ? -1 : 0; | 212 int first_parameter = info->scope()->has_this_declaration() ? -1 : 0; |
202 for (int i = first_parameter; i < num_parameters; i++) { | 213 for (int i = first_parameter; i < num_parameters; i++) { |
203 Variable* var = (i == -1) ? scope()->receiver() : scope()->parameter(i); | 214 Variable* var = (i == -1) ? scope()->receiver() : scope()->parameter(i); |
204 if (var->IsContextSlot()) { | 215 if (var->IsContextSlot()) { |
205 int parameter_offset = StandardFrameConstants::kCallerSPOffset + | 216 int parameter_offset = StandardFrameConstants::kCallerSPOffset + |
206 (num_parameters - 1 - i) * kPointerSize; | 217 (num_parameters - 1 - i) * kPointerSize; |
207 // Load parameter from stack. | 218 // Load parameter from stack. |
208 __ ldr(r0, MemOperand(fp, parameter_offset)); | 219 __ ldr(r0, MemOperand(fp, parameter_offset)); |
209 // Store it in the context. | 220 // Store it in the context. |
210 MemOperand target = ContextMemOperand(cp, var->index()); | 221 MemOperand target = ContextMemOperand(cp, var->index()); |
211 __ str(r0, target); | 222 __ str(r0, target); |
212 | 223 |
213 // Update the write barrier. | 224 // Update the write barrier. |
214 if (need_write_barrier) { | 225 if (need_write_barrier) { |
215 __ RecordWriteContextSlot( | 226 __ RecordWriteContextSlot(cp, target.offset(), r0, r2, |
216 cp, target.offset(), r0, r3, kLRHasBeenSaved, kDontSaveFPRegs); | 227 kLRHasBeenSaved, kDontSaveFPRegs); |
217 } else if (FLAG_debug_code) { | 228 } else if (FLAG_debug_code) { |
218 Label done; | 229 Label done; |
219 __ JumpIfInNewSpace(cp, r0, &done); | 230 __ JumpIfInNewSpace(cp, r0, &done); |
220 __ Abort(kExpectedNewSpaceObject); | 231 __ Abort(kExpectedNewSpaceObject); |
221 __ bind(&done); | 232 __ bind(&done); |
222 } | 233 } |
223 } | 234 } |
224 } | 235 } |
225 } | 236 } |
| 237 |
| 238 // Register holding this function and new target are both trashed in case we |
| 239 // bailout here. But since that can happen only when new target is not used |
| 240 // and we allocate a context, the value of |function_in_register| is correct. |
226 PrepareForBailoutForId(BailoutId::FunctionContext(), NO_REGISTERS); | 241 PrepareForBailoutForId(BailoutId::FunctionContext(), NO_REGISTERS); |
227 | 242 |
228 // Function register is trashed in case we bailout here. But since that | |
229 // could happen only when we allocate a context the value of | |
230 // |function_in_register_r1| is correct. | |
231 | |
232 // Possibly set up a local binding to the this function which is used in | 243 // Possibly set up a local binding to the this function which is used in |
233 // derived constructors with super calls. | 244 // derived constructors with super calls. |
234 Variable* this_function_var = scope()->this_function_var(); | 245 Variable* this_function_var = scope()->this_function_var(); |
235 if (this_function_var != nullptr) { | 246 if (this_function_var != nullptr) { |
236 Comment cmnt(masm_, "[ This function"); | 247 Comment cmnt(masm_, "[ This function"); |
237 if (!function_in_register_r1) { | 248 if (!function_in_register_r1) { |
238 __ ldr(r1, MemOperand(fp, JavaScriptFrameConstants::kFunctionOffset)); | 249 __ ldr(r1, MemOperand(fp, JavaScriptFrameConstants::kFunctionOffset)); |
239 // The write barrier clobbers register again, keep it marked as such. | 250 // The write barrier clobbers register again, keep it marked as such. |
240 } | 251 } |
241 SetVar(this_function_var, r1, r0, r2); | 252 SetVar(this_function_var, r1, r0, r2); |
242 } | 253 } |
243 | 254 |
| 255 // Possibly set up a local binding to the new target value. |
244 Variable* new_target_var = scope()->new_target_var(); | 256 Variable* new_target_var = scope()->new_target_var(); |
245 if (new_target_var != nullptr) { | 257 if (new_target_var != nullptr) { |
246 Comment cmnt(masm_, "[ new.target"); | 258 Comment cmnt(masm_, "[ new.target"); |
247 | 259 SetVar(new_target_var, r3, r0, r2); |
248 __ ldr(r2, MemOperand(fp, StandardFrameConstants::kCallerFPOffset)); | |
249 __ ldr(r1, MemOperand(r2, StandardFrameConstants::kContextOffset)); | |
250 __ cmp(r1, Operand(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR))); | |
251 __ ldr(r2, MemOperand(r2, StandardFrameConstants::kCallerFPOffset), eq); | |
252 __ ldr(r1, MemOperand(r2, StandardFrameConstants::kMarkerOffset)); | |
253 __ cmp(r1, Operand(Smi::FromInt(StackFrame::CONSTRUCT))); | |
254 Label non_construct_frame, done; | |
255 function_in_register_r1 = false; | |
256 | |
257 __ b(ne, &non_construct_frame); | |
258 __ ldr(r0, MemOperand(r2, ConstructFrameConstants::kNewTargetOffset)); | |
259 __ b(&done); | |
260 | |
261 __ bind(&non_construct_frame); | |
262 __ LoadRoot(r0, Heap::kUndefinedValueRootIndex); | |
263 __ bind(&done); | |
264 | |
265 SetVar(new_target_var, r0, r2, r3); | |
266 } | 260 } |
267 | 261 |
268 Variable* arguments = scope()->arguments(); | 262 Variable* arguments = scope()->arguments(); |
269 if (arguments != NULL) { | 263 if (arguments != NULL) { |
270 // Function uses arguments object. | 264 // Function uses arguments object. |
271 Comment cmnt(masm_, "[ Allocate arguments object"); | 265 Comment cmnt(masm_, "[ Allocate arguments object"); |
272 DCHECK(r1.is(ArgumentsAccessNewDescriptor::function())); | 266 DCHECK(r1.is(ArgumentsAccessNewDescriptor::function())); |
273 if (!function_in_register_r1) { | 267 if (!function_in_register_r1) { |
274 // Load this again, if it's used by the local context below. | 268 // Load this again, if it's used by the local context below. |
275 __ ldr(r1, MemOperand(fp, JavaScriptFrameConstants::kFunctionOffset)); | 269 __ ldr(r1, MemOperand(fp, JavaScriptFrameConstants::kFunctionOffset)); |
(...skipping 4697 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4973 DCHECK(interrupt_address == | 4967 DCHECK(interrupt_address == |
4974 isolate->builtins()->OsrAfterStackCheck()->entry()); | 4968 isolate->builtins()->OsrAfterStackCheck()->entry()); |
4975 return OSR_AFTER_STACK_CHECK; | 4969 return OSR_AFTER_STACK_CHECK; |
4976 } | 4970 } |
4977 | 4971 |
4978 | 4972 |
4979 } // namespace internal | 4973 } // namespace internal |
4980 } // namespace v8 | 4974 } // namespace v8 |
4981 | 4975 |
4982 #endif // V8_TARGET_ARCH_ARM | 4976 #endif // V8_TARGET_ARCH_ARM |
OLD | NEW |