| OLD | NEW |
| 1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 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_ARM64 | 5 #if V8_TARGET_ARCH_ARM64 |
| 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 // - x1: the JS function object being called (i.e. ourselves). | 94 // - x1: the JS function object being called (i.e. ourselves). |
| 95 // - x3: the new target value |
| 95 // - cp: our context. | 96 // - cp: our context. |
| 96 // - fp: our caller's frame pointer. | 97 // - fp: our caller's frame pointer. |
| 97 // - jssp: stack pointer. | 98 // - jssp: stack pointer. |
| 98 // - lr: return address. | 99 // - lr: return address. |
| 99 // | 100 // |
| 100 // The function builds a JS frame. See JavaScriptFrameConstants in | 101 // The function builds a JS frame. See JavaScriptFrameConstants in |
| 101 // frames-arm.h for its layout. | 102 // frames-arm.h for its layout. |
| 102 void FullCodeGenerator::Generate() { | 103 void FullCodeGenerator::Generate() { |
| 103 CompilationInfo* info = info_; | 104 CompilationInfo* info = info_; |
| 104 profiling_counter_ = isolate()->factory()->NewCell( | 105 profiling_counter_ = isolate()->factory()->NewCell( |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 151 __ CallRuntime(Runtime::kThrowStackOverflow, 0); | 152 __ CallRuntime(Runtime::kThrowStackOverflow, 0); |
| 152 __ Bind(&ok); | 153 __ Bind(&ok); |
| 153 } | 154 } |
| 154 __ LoadRoot(x10, Heap::kUndefinedValueRootIndex); | 155 __ LoadRoot(x10, Heap::kUndefinedValueRootIndex); |
| 155 if (FLAG_optimize_for_size) { | 156 if (FLAG_optimize_for_size) { |
| 156 __ PushMultipleTimes(x10 , locals_count); | 157 __ PushMultipleTimes(x10 , locals_count); |
| 157 } else { | 158 } else { |
| 158 const int kMaxPushes = 32; | 159 const int kMaxPushes = 32; |
| 159 if (locals_count >= kMaxPushes) { | 160 if (locals_count >= kMaxPushes) { |
| 160 int loop_iterations = locals_count / kMaxPushes; | 161 int loop_iterations = locals_count / kMaxPushes; |
| 161 __ Mov(x3, loop_iterations); | 162 __ Mov(x2, loop_iterations); |
| 162 Label loop_header; | 163 Label loop_header; |
| 163 __ Bind(&loop_header); | 164 __ Bind(&loop_header); |
| 164 // Do pushes. | 165 // Do pushes. |
| 165 __ PushMultipleTimes(x10 , kMaxPushes); | 166 __ PushMultipleTimes(x10 , kMaxPushes); |
| 166 __ Subs(x3, x3, 1); | 167 __ Subs(x2, x2, 1); |
| 167 __ B(ne, &loop_header); | 168 __ B(ne, &loop_header); |
| 168 } | 169 } |
| 169 int remaining = locals_count % kMaxPushes; | 170 int remaining = locals_count % kMaxPushes; |
| 170 // Emit the remaining pushes. | 171 // Emit the remaining pushes. |
| 171 __ PushMultipleTimes(x10 , remaining); | 172 __ PushMultipleTimes(x10 , remaining); |
| 172 } | 173 } |
| 173 } | 174 } |
| 174 } | 175 } |
| 175 | 176 |
| 176 bool function_in_register_x1 = true; | 177 bool function_in_register_x1 = true; |
| 177 | 178 |
| 178 if (info->scope()->num_heap_slots() > 0) { | 179 if (info->scope()->num_heap_slots() > 0) { |
| 179 // Argument to NewContext is the function, which is still in x1. | 180 // Argument to NewContext is the function, which is still in x1. |
| 180 Comment cmnt(masm_, "[ Allocate context"); | 181 Comment cmnt(masm_, "[ Allocate context"); |
| 181 bool need_write_barrier = true; | 182 bool need_write_barrier = true; |
| 182 int slots = info->scope()->num_heap_slots() - Context::MIN_CONTEXT_SLOTS; | 183 int slots = info->scope()->num_heap_slots() - Context::MIN_CONTEXT_SLOTS; |
| 183 if (info->scope()->is_script_scope()) { | 184 if (info->scope()->is_script_scope()) { |
| 184 __ Mov(x10, Operand(info->scope()->GetScopeInfo(info->isolate()))); | 185 __ Mov(x10, Operand(info->scope()->GetScopeInfo(info->isolate()))); |
| 185 __ Push(x1, x10); | 186 __ Push(x1, x10); |
| 186 __ CallRuntime(Runtime::kNewScriptContext, 2); | 187 __ CallRuntime(Runtime::kNewScriptContext, 2); |
| 187 PrepareForBailoutForId(BailoutId::ScriptContext(), TOS_REG); | 188 PrepareForBailoutForId(BailoutId::ScriptContext(), TOS_REG); |
| 188 } else if (slots <= FastNewContextStub::kMaximumSlots) { | 189 // The new target value is not used, clobbering is safe. |
| 189 FastNewContextStub stub(isolate(), slots); | 190 DCHECK_NULL(info->scope()->new_target_var()); |
| 190 __ CallStub(&stub); | |
| 191 // Result of FastNewContextStub is always in new space. | |
| 192 need_write_barrier = false; | |
| 193 } else { | 191 } else { |
| 194 __ Push(x1); | 192 if (info->scope()->new_target_var() != nullptr) { |
| 195 __ CallRuntime(Runtime::kNewFunctionContext, 1); | 193 __ Push(x3); // Preserve new target. |
| 194 } |
| 195 if (slots <= FastNewContextStub::kMaximumSlots) { |
| 196 FastNewContextStub stub(isolate(), slots); |
| 197 __ CallStub(&stub); |
| 198 // Result of FastNewContextStub is always in new space. |
| 199 need_write_barrier = false; |
| 200 } else { |
| 201 __ Push(x1); |
| 202 __ CallRuntime(Runtime::kNewFunctionContext, 1); |
| 203 } |
| 204 if (info->scope()->new_target_var() != nullptr) { |
| 205 __ Pop(x3); // Restore new target. |
| 206 } |
| 196 } | 207 } |
| 197 function_in_register_x1 = false; | 208 function_in_register_x1 = false; |
| 198 // Context is returned in x0. It replaces the context passed to us. | 209 // Context is returned in x0. It replaces the context passed to us. |
| 199 // It's saved in the stack and kept live in cp. | 210 // It's saved in the stack and kept live in cp. |
| 200 __ Mov(cp, x0); | 211 __ Mov(cp, x0); |
| 201 __ Str(x0, MemOperand(fp, StandardFrameConstants::kContextOffset)); | 212 __ Str(x0, MemOperand(fp, StandardFrameConstants::kContextOffset)); |
| 202 // Copy any necessary parameters into the context. | 213 // Copy any necessary parameters into the context. |
| 203 int num_parameters = info->scope()->num_parameters(); | 214 int num_parameters = info->scope()->num_parameters(); |
| 204 int first_parameter = info->scope()->has_this_declaration() ? -1 : 0; | 215 int first_parameter = info->scope()->has_this_declaration() ? -1 : 0; |
| 205 for (int i = first_parameter; i < num_parameters; i++) { | 216 for (int i = first_parameter; i < num_parameters; i++) { |
| (...skipping 13 matching lines...) Expand all Loading... |
| 219 x11, kLRHasBeenSaved, kDontSaveFPRegs); | 230 x11, kLRHasBeenSaved, kDontSaveFPRegs); |
| 220 } else if (FLAG_debug_code) { | 231 } else if (FLAG_debug_code) { |
| 221 Label done; | 232 Label done; |
| 222 __ JumpIfInNewSpace(cp, &done); | 233 __ JumpIfInNewSpace(cp, &done); |
| 223 __ Abort(kExpectedNewSpaceObject); | 234 __ Abort(kExpectedNewSpaceObject); |
| 224 __ bind(&done); | 235 __ bind(&done); |
| 225 } | 236 } |
| 226 } | 237 } |
| 227 } | 238 } |
| 228 } | 239 } |
| 240 |
| 241 // Register holding this function and new target are both trashed in case we |
| 242 // bailout here. But since that can happen only when new target is not used |
| 243 // and we allocate a context, the value of |function_in_register| is correct. |
| 229 PrepareForBailoutForId(BailoutId::FunctionContext(), NO_REGISTERS); | 244 PrepareForBailoutForId(BailoutId::FunctionContext(), NO_REGISTERS); |
| 230 | 245 |
| 231 // Function register is trashed in case we bailout here. But since that | |
| 232 // could happen only when we allocate a context the value of | |
| 233 // |function_in_register_x1| is correct. | |
| 234 | |
| 235 // Possibly set up a local binding to the this function which is used in | 246 // Possibly set up a local binding to the this function which is used in |
| 236 // derived constructors with super calls. | 247 // derived constructors with super calls. |
| 237 Variable* this_function_var = scope()->this_function_var(); | 248 Variable* this_function_var = scope()->this_function_var(); |
| 238 if (this_function_var != nullptr) { | 249 if (this_function_var != nullptr) { |
| 239 Comment cmnt(masm_, "[ This function"); | 250 Comment cmnt(masm_, "[ This function"); |
| 240 if (!function_in_register_x1) { | 251 if (!function_in_register_x1) { |
| 241 __ Ldr(x1, MemOperand(fp, JavaScriptFrameConstants::kFunctionOffset)); | 252 __ Ldr(x1, MemOperand(fp, JavaScriptFrameConstants::kFunctionOffset)); |
| 242 // The write barrier clobbers register again, keep it marked as such. | 253 // The write barrier clobbers register again, keep it marked as such. |
| 243 } | 254 } |
| 244 SetVar(this_function_var, x1, x0, x2); | 255 SetVar(this_function_var, x1, x0, x2); |
| 245 } | 256 } |
| 246 | 257 |
| 258 // Possibly set up a local binding to the new target value. |
| 247 Variable* new_target_var = scope()->new_target_var(); | 259 Variable* new_target_var = scope()->new_target_var(); |
| 248 if (new_target_var != nullptr) { | 260 if (new_target_var != nullptr) { |
| 249 Comment cmnt(masm_, "[ new.target"); | 261 Comment cmnt(masm_, "[ new.target"); |
| 250 // Get the frame pointer for the calling frame. | 262 SetVar(new_target_var, x3, x0, x2); |
| 251 __ Ldr(x2, MemOperand(fp, StandardFrameConstants::kCallerFPOffset)); | |
| 252 | |
| 253 Label check_frame_marker; | |
| 254 __ Ldr(x1, MemOperand(x2, StandardFrameConstants::kContextOffset)); | |
| 255 __ Cmp(x1, Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR)); | |
| 256 __ B(ne, &check_frame_marker); | |
| 257 __ Ldr(x2, MemOperand(x2, StandardFrameConstants::kCallerFPOffset)); | |
| 258 __ Bind(&check_frame_marker); | |
| 259 __ Ldr(x1, MemOperand(x2, StandardFrameConstants::kMarkerOffset)); | |
| 260 __ Cmp(x1, Smi::FromInt(StackFrame::CONSTRUCT)); | |
| 261 function_in_register_x1 = false; | |
| 262 | |
| 263 Label non_construct_frame, done; | |
| 264 | |
| 265 __ B(ne, &non_construct_frame); | |
| 266 __ Ldr(x0, MemOperand(x2, ConstructFrameConstants::kNewTargetOffset)); | |
| 267 __ B(&done); | |
| 268 | |
| 269 __ Bind(&non_construct_frame); | |
| 270 __ LoadRoot(x0, Heap::kUndefinedValueRootIndex); | |
| 271 | |
| 272 __ Bind(&done); | |
| 273 | |
| 274 SetVar(new_target_var, x0, x2, x3); | |
| 275 } | 263 } |
| 276 | 264 |
| 277 Variable* arguments = scope()->arguments(); | 265 Variable* arguments = scope()->arguments(); |
| 278 if (arguments != NULL) { | 266 if (arguments != NULL) { |
| 279 // Function uses arguments object. | 267 // Function uses arguments object. |
| 280 Comment cmnt(masm_, "[ Allocate arguments object"); | 268 Comment cmnt(masm_, "[ Allocate arguments object"); |
| 281 DCHECK(x1.is(ArgumentsAccessNewDescriptor::function())); | 269 DCHECK(x1.is(ArgumentsAccessNewDescriptor::function())); |
| 282 if (!function_in_register_x1) { | 270 if (!function_in_register_x1) { |
| 283 // Load this again, if it's used by the local context below. | 271 // Load this again, if it's used by the local context below. |
| 284 __ Ldr(x1, MemOperand(fp, JavaScriptFrameConstants::kFunctionOffset)); | 272 __ Ldr(x1, MemOperand(fp, JavaScriptFrameConstants::kFunctionOffset)); |
| (...skipping 4666 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4951 } | 4939 } |
| 4952 | 4940 |
| 4953 return INTERRUPT; | 4941 return INTERRUPT; |
| 4954 } | 4942 } |
| 4955 | 4943 |
| 4956 | 4944 |
| 4957 } // namespace internal | 4945 } // namespace internal |
| 4958 } // namespace v8 | 4946 } // namespace v8 |
| 4959 | 4947 |
| 4960 #endif // V8_TARGET_ARCH_ARM64 | 4948 #endif // V8_TARGET_ARCH_ARM64 |
| OLD | NEW |