Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 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 |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "src/v8.h" |
| 6 | |
| 7 | #if V8_TARGET_ARCH_ARM64 |
| 8 | |
| 9 | #include "src/code-factory.h" |
| 10 | #include "src/code-stubs.h" |
| 11 | #include "src/codegen.h" |
| 12 | #include "src/compiler.h" |
| 13 | #include "src/debug.h" |
| 14 | #include "src/full-codegen.h" |
| 15 | #include "src/ic/ic.h" |
| 16 | #include "src/isolate-inl.h" |
| 17 | #include "src/parser.h" |
| 18 | #include "src/scopes.h" |
| 19 | |
| 20 | #include "src/arm64/code-stubs-arm64.h" |
| 21 | #include "src/arm64/macro-assembler-arm64.h" |
| 22 | |
| 23 | namespace v8 { |
| 24 | namespace internal { |
| 25 | |
| 26 | #define __ ACCESS_MASM(masm_) |
| 27 | |
| 28 | class JumpPatchSite BASE_EMBEDDED { |
| 29 | public: |
| 30 | explicit JumpPatchSite(MacroAssembler* masm) : masm_(masm), reg_(NoReg) { |
| 31 | #ifdef DEBUG |
| 32 | info_emitted_ = false; |
| 33 | #endif |
| 34 | } |
| 35 | |
| 36 | ~JumpPatchSite() { |
| 37 | if (patch_site_.is_bound()) { |
| 38 | DCHECK(info_emitted_); |
| 39 | } else { |
| 40 | DCHECK(reg_.IsNone()); |
| 41 | } |
| 42 | } |
| 43 | |
| 44 | void EmitJumpIfNotSmi(Register reg, Label* target) { |
| 45 | // This code will be patched by PatchInlinedSmiCode, in ic-arm64.cc. |
| 46 | InstructionAccurateScope scope(masm_, 1); |
| 47 | DCHECK(!info_emitted_); |
| 48 | DCHECK(reg.Is64Bits()); |
| 49 | DCHECK(!reg.Is(csp)); |
| 50 | reg_ = reg; |
| 51 | __ bind(&patch_site_); |
| 52 | __ tbz(xzr, 0, target); // Always taken before patched. |
| 53 | } |
| 54 | |
| 55 | void EmitJumpIfSmi(Register reg, Label* target) { |
| 56 | // This code will be patched by PatchInlinedSmiCode, in ic-arm64.cc. |
| 57 | InstructionAccurateScope scope(masm_, 1); |
| 58 | DCHECK(!info_emitted_); |
| 59 | DCHECK(reg.Is64Bits()); |
| 60 | DCHECK(!reg.Is(csp)); |
| 61 | reg_ = reg; |
| 62 | __ bind(&patch_site_); |
| 63 | __ tbnz(xzr, 0, target); // Never taken before patched. |
| 64 | } |
| 65 | |
| 66 | void EmitJumpIfEitherNotSmi(Register reg1, Register reg2, Label* target) { |
| 67 | UseScratchRegisterScope temps(masm_); |
| 68 | Register temp = temps.AcquireX(); |
| 69 | __ Orr(temp, reg1, reg2); |
| 70 | EmitJumpIfNotSmi(temp, target); |
| 71 | } |
| 72 | |
| 73 | void EmitPatchInfo() { |
| 74 | Assembler::BlockPoolsScope scope(masm_); |
| 75 | InlineSmiCheckInfo::Emit(masm_, reg_, &patch_site_); |
| 76 | #ifdef DEBUG |
| 77 | info_emitted_ = true; |
| 78 | #endif |
| 79 | } |
| 80 | |
| 81 | private: |
| 82 | MacroAssembler* masm_; |
| 83 | Label patch_site_; |
| 84 | Register reg_; |
| 85 | #ifdef DEBUG |
| 86 | bool info_emitted_; |
| 87 | #endif |
| 88 | }; |
| 89 | |
| 90 | |
| 91 | // Generate code for a JS function. On entry to the function the receiver |
| 92 | // and arguments have been pushed on the stack left to right. The actual |
| 93 | // argument count matches the formal parameter count expected by the |
| 94 | // function. |
| 95 | // |
| 96 | // The live registers are: |
| 97 | // - x1: the JS function object being called (i.e. ourselves). |
| 98 | // - cp: our context. |
| 99 | // - fp: our caller's frame pointer. |
| 100 | // - jssp: stack pointer. |
| 101 | // - lr: return address. |
| 102 | // |
| 103 | // The function builds a JS frame. See JavaScriptFrameConstants in |
| 104 | // frames-arm.h for its layout. |
| 105 | void FullCodeGenerator::Generate() { |
| 106 | CompilationInfo* info = info_; |
| 107 | handler_table_ = |
| 108 | isolate()->factory()->NewFixedArray(function()->handler_count(), TENURED); |
| 109 | |
| 110 | profiling_counter_ = isolate()->factory()->NewCell( |
| 111 | Handle<Smi>(Smi::FromInt(FLAG_interrupt_budget), isolate())); |
| 112 | SetFunctionPosition(function()); |
| 113 | Comment cmnt(masm_, "[ Function compiled by full code generator"); |
| 114 | |
| 115 | ProfileEntryHookStub::MaybeCallEntryHook(masm_); |
| 116 | |
| 117 | #ifdef DEBUG |
| 118 | if (strlen(FLAG_stop_at) > 0 && |
| 119 | info->function()->name()->IsUtf8EqualTo(CStrVector(FLAG_stop_at))) { |
| 120 | __ Debug("stop-at", __LINE__, BREAK); |
| 121 | } |
| 122 | #endif |
| 123 | |
| 124 | // Sloppy mode functions and builtins need to replace the receiver with the |
| 125 | // global proxy when called as functions (without an explicit receiver |
| 126 | // object). |
| 127 | if (info->strict_mode() == SLOPPY && !info->is_native()) { |
| 128 | Label ok; |
| 129 | int receiver_offset = info->scope()->num_parameters() * kXRegSize; |
| 130 | __ Peek(x10, receiver_offset); |
| 131 | __ JumpIfNotRoot(x10, Heap::kUndefinedValueRootIndex, &ok); |
| 132 | |
| 133 | __ Ldr(x10, GlobalObjectMemOperand()); |
| 134 | __ Ldr(x10, FieldMemOperand(x10, GlobalObject::kGlobalProxyOffset)); |
| 135 | __ Poke(x10, receiver_offset); |
| 136 | |
| 137 | __ Bind(&ok); |
| 138 | } |
| 139 | |
| 140 | |
| 141 | // Open a frame scope to indicate that there is a frame on the stack. |
| 142 | // The MANUAL indicates that the scope shouldn't actually generate code |
| 143 | // to set up the frame because we do it manually below. |
| 144 | FrameScope frame_scope(masm_, StackFrame::MANUAL); |
| 145 | |
| 146 | // This call emits the following sequence in a way that can be patched for |
| 147 | // code ageing support: |
| 148 | // Push(lr, fp, cp, x1); |
| 149 | // Add(fp, jssp, 2 * kPointerSize); |
| 150 | info->set_prologue_offset(masm_->pc_offset()); |
| 151 | __ Prologue(info->IsCodePreAgingActive()); |
| 152 | info->AddNoFrameRange(0, masm_->pc_offset()); |
| 153 | |
| 154 | // Reserve space on the stack for locals. |
| 155 | { Comment cmnt(masm_, "[ Allocate locals"); |
| 156 | int locals_count = info->scope()->num_stack_slots(); |
| 157 | // Generators allocate locals, if any, in context slots. |
| 158 | DCHECK(!info->function()->is_generator() || locals_count == 0); |
| 159 | |
| 160 | if (locals_count > 0) { |
| 161 | if (locals_count >= 128) { |
| 162 | Label ok; |
| 163 | DCHECK(jssp.Is(__ StackPointer())); |
| 164 | __ Sub(x10, jssp, locals_count * kPointerSize); |
| 165 | __ CompareRoot(x10, Heap::kRealStackLimitRootIndex); |
| 166 | __ B(hs, &ok); |
| 167 | __ InvokeBuiltin(Builtins::STACK_OVERFLOW, CALL_FUNCTION); |
| 168 | __ Bind(&ok); |
| 169 | } |
| 170 | __ LoadRoot(x10, Heap::kUndefinedValueRootIndex); |
| 171 | if (FLAG_optimize_for_size) { |
| 172 | __ PushMultipleTimes(x10 , locals_count); |
| 173 | } else { |
| 174 | const int kMaxPushes = 32; |
| 175 | if (locals_count >= kMaxPushes) { |
| 176 | int loop_iterations = locals_count / kMaxPushes; |
| 177 | __ Mov(x3, loop_iterations); |
| 178 | Label loop_header; |
| 179 | __ Bind(&loop_header); |
| 180 | // Do pushes. |
| 181 | __ PushMultipleTimes(x10 , kMaxPushes); |
| 182 | __ Subs(x3, x3, 1); |
| 183 | __ B(ne, &loop_header); |
| 184 | } |
| 185 | int remaining = locals_count % kMaxPushes; |
| 186 | // Emit the remaining pushes. |
| 187 | __ PushMultipleTimes(x10 , remaining); |
| 188 | } |
| 189 | } |
| 190 | } |
| 191 | |
| 192 | bool function_in_register_x1 = true; |
| 193 | |
| 194 | int heap_slots = info->scope()->num_heap_slots() - Context::MIN_CONTEXT_SLOTS; |
| 195 | if (heap_slots > 0) { |
| 196 | // Argument to NewContext is the function, which is still in x1. |
| 197 | Comment cmnt(masm_, "[ Allocate context"); |
| 198 | bool need_write_barrier = true; |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 199 | if (FLAG_harmony_scoping && info->scope()->is_script_scope()) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 200 | __ Mov(x10, Operand(info->scope()->GetScopeInfo())); |
| 201 | __ Push(x1, x10); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 202 | __ CallRuntime(Runtime::kNewScriptContext, 2); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 203 | } else if (heap_slots <= FastNewContextStub::kMaximumSlots) { |
| 204 | FastNewContextStub stub(isolate(), heap_slots); |
| 205 | __ CallStub(&stub); |
| 206 | // Result of FastNewContextStub is always in new space. |
| 207 | need_write_barrier = false; |
| 208 | } else { |
| 209 | __ Push(x1); |
| 210 | __ CallRuntime(Runtime::kNewFunctionContext, 1); |
| 211 | } |
| 212 | function_in_register_x1 = false; |
| 213 | // Context is returned in x0. It replaces the context passed to us. |
| 214 | // It's saved in the stack and kept live in cp. |
| 215 | __ Mov(cp, x0); |
| 216 | __ Str(x0, MemOperand(fp, StandardFrameConstants::kContextOffset)); |
| 217 | // Copy any necessary parameters into the context. |
| 218 | int num_parameters = info->scope()->num_parameters(); |
| 219 | for (int i = 0; i < num_parameters; i++) { |
| 220 | Variable* var = scope()->parameter(i); |
| 221 | if (var->IsContextSlot()) { |
| 222 | int parameter_offset = StandardFrameConstants::kCallerSPOffset + |
| 223 | (num_parameters - 1 - i) * kPointerSize; |
| 224 | // Load parameter from stack. |
| 225 | __ Ldr(x10, MemOperand(fp, parameter_offset)); |
| 226 | // Store it in the context. |
| 227 | MemOperand target = ContextMemOperand(cp, var->index()); |
| 228 | __ Str(x10, target); |
| 229 | |
| 230 | // Update the write barrier. |
| 231 | if (need_write_barrier) { |
| 232 | __ RecordWriteContextSlot( |
| 233 | cp, target.offset(), x10, x11, kLRHasBeenSaved, kDontSaveFPRegs); |
| 234 | } else if (FLAG_debug_code) { |
| 235 | Label done; |
| 236 | __ JumpIfInNewSpace(cp, &done); |
| 237 | __ Abort(kExpectedNewSpaceObject); |
| 238 | __ bind(&done); |
| 239 | } |
| 240 | } |
| 241 | } |
| 242 | } |
| 243 | |
| 244 | Variable* arguments = scope()->arguments(); |
| 245 | if (arguments != NULL) { |
| 246 | // Function uses arguments object. |
| 247 | Comment cmnt(masm_, "[ Allocate arguments object"); |
| 248 | if (!function_in_register_x1) { |
| 249 | // Load this again, if it's used by the local context below. |
| 250 | __ Ldr(x3, MemOperand(fp, JavaScriptFrameConstants::kFunctionOffset)); |
| 251 | } else { |
| 252 | __ Mov(x3, x1); |
| 253 | } |
| 254 | // Receiver is just before the parameters on the caller's stack. |
| 255 | int num_parameters = info->scope()->num_parameters(); |
| 256 | int offset = num_parameters * kPointerSize; |
| 257 | __ Add(x2, fp, StandardFrameConstants::kCallerSPOffset + offset); |
| 258 | __ Mov(x1, Smi::FromInt(num_parameters)); |
| 259 | __ Push(x3, x2, x1); |
| 260 | |
| 261 | // Arguments to ArgumentsAccessStub: |
| 262 | // function, receiver address, parameter count. |
| 263 | // The stub will rewrite receiver and parameter count if the previous |
| 264 | // stack frame was an arguments adapter frame. |
| 265 | ArgumentsAccessStub::Type type; |
| 266 | if (strict_mode() == STRICT) { |
| 267 | type = ArgumentsAccessStub::NEW_STRICT; |
| 268 | } else if (function()->has_duplicate_parameters()) { |
| 269 | type = ArgumentsAccessStub::NEW_SLOPPY_SLOW; |
| 270 | } else { |
| 271 | type = ArgumentsAccessStub::NEW_SLOPPY_FAST; |
| 272 | } |
| 273 | ArgumentsAccessStub stub(isolate(), type); |
| 274 | __ CallStub(&stub); |
| 275 | |
| 276 | SetVar(arguments, x0, x1, x2); |
| 277 | } |
| 278 | |
| 279 | if (FLAG_trace) { |
| 280 | __ CallRuntime(Runtime::kTraceEnter, 0); |
| 281 | } |
| 282 | |
| 283 | |
| 284 | // Visit the declarations and body unless there is an illegal |
| 285 | // redeclaration. |
| 286 | if (scope()->HasIllegalRedeclaration()) { |
| 287 | Comment cmnt(masm_, "[ Declarations"); |
| 288 | scope()->VisitIllegalRedeclaration(this); |
| 289 | |
| 290 | } else { |
| 291 | PrepareForBailoutForId(BailoutId::FunctionEntry(), NO_REGISTERS); |
| 292 | { Comment cmnt(masm_, "[ Declarations"); |
| 293 | if (scope()->is_function_scope() && scope()->function() != NULL) { |
| 294 | VariableDeclaration* function = scope()->function(); |
| 295 | DCHECK(function->proxy()->var()->mode() == CONST || |
| 296 | function->proxy()->var()->mode() == CONST_LEGACY); |
| 297 | DCHECK(function->proxy()->var()->location() != Variable::UNALLOCATED); |
| 298 | VisitVariableDeclaration(function); |
| 299 | } |
| 300 | VisitDeclarations(scope()->declarations()); |
| 301 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 302 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 303 | { |
| 304 | Comment cmnt(masm_, "[ Stack check"); |
| 305 | PrepareForBailoutForId(BailoutId::Declarations(), NO_REGISTERS); |
| 306 | Label ok; |
| 307 | DCHECK(jssp.Is(__ StackPointer())); |
| 308 | __ CompareRoot(jssp, Heap::kStackLimitRootIndex); |
| 309 | __ B(hs, &ok); |
| 310 | PredictableCodeSizeScope predictable(masm_, |
| 311 | Assembler::kCallSizeWithRelocation); |
| 312 | __ Call(isolate()->builtins()->StackCheck(), RelocInfo::CODE_TARGET); |
| 313 | __ Bind(&ok); |
| 314 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 315 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 316 | { |
| 317 | Comment cmnt(masm_, "[ Body"); |
| 318 | DCHECK(loop_depth() == 0); |
| 319 | VisitStatements(function()->body()); |
| 320 | DCHECK(loop_depth() == 0); |
| 321 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 322 | } |
| 323 | |
| 324 | // Always emit a 'return undefined' in case control fell off the end of |
| 325 | // the body. |
| 326 | { Comment cmnt(masm_, "[ return <undefined>;"); |
| 327 | __ LoadRoot(x0, Heap::kUndefinedValueRootIndex); |
| 328 | } |
| 329 | EmitReturnSequence(); |
| 330 | |
| 331 | // Force emission of the pools, so they don't get emitted in the middle |
| 332 | // of the back edge table. |
| 333 | masm()->CheckVeneerPool(true, false); |
| 334 | masm()->CheckConstPool(true, false); |
| 335 | } |
| 336 | |
| 337 | |
| 338 | void FullCodeGenerator::ClearAccumulator() { |
| 339 | __ Mov(x0, Smi::FromInt(0)); |
| 340 | } |
| 341 | |
| 342 | |
| 343 | void FullCodeGenerator::EmitProfilingCounterDecrement(int delta) { |
| 344 | __ Mov(x2, Operand(profiling_counter_)); |
| 345 | __ Ldr(x3, FieldMemOperand(x2, Cell::kValueOffset)); |
| 346 | __ Subs(x3, x3, Smi::FromInt(delta)); |
| 347 | __ Str(x3, FieldMemOperand(x2, Cell::kValueOffset)); |
| 348 | } |
| 349 | |
| 350 | |
| 351 | void FullCodeGenerator::EmitProfilingCounterReset() { |
| 352 | int reset_value = FLAG_interrupt_budget; |
| 353 | if (info_->is_debug()) { |
| 354 | // Detect debug break requests as soon as possible. |
| 355 | reset_value = FLAG_interrupt_budget >> 4; |
| 356 | } |
| 357 | __ Mov(x2, Operand(profiling_counter_)); |
| 358 | __ Mov(x3, Smi::FromInt(reset_value)); |
| 359 | __ Str(x3, FieldMemOperand(x2, Cell::kValueOffset)); |
| 360 | } |
| 361 | |
| 362 | |
| 363 | void FullCodeGenerator::EmitBackEdgeBookkeeping(IterationStatement* stmt, |
| 364 | Label* back_edge_target) { |
| 365 | DCHECK(jssp.Is(__ StackPointer())); |
| 366 | Comment cmnt(masm_, "[ Back edge bookkeeping"); |
| 367 | // Block literal pools whilst emitting back edge code. |
| 368 | Assembler::BlockPoolsScope block_const_pool(masm_); |
| 369 | Label ok; |
| 370 | |
| 371 | DCHECK(back_edge_target->is_bound()); |
| 372 | // We want to do a round rather than a floor of distance/kCodeSizeMultiplier |
| 373 | // to reduce the absolute error due to the integer division. To do that, |
| 374 | // we add kCodeSizeMultiplier/2 to the distance (equivalent to adding 0.5 to |
| 375 | // the result). |
| 376 | int distance = |
| 377 | masm_->SizeOfCodeGeneratedSince(back_edge_target) + kCodeSizeMultiplier / 2; |
| 378 | int weight = Min(kMaxBackEdgeWeight, |
| 379 | Max(1, distance / kCodeSizeMultiplier)); |
| 380 | EmitProfilingCounterDecrement(weight); |
| 381 | __ B(pl, &ok); |
| 382 | __ Call(isolate()->builtins()->InterruptCheck(), RelocInfo::CODE_TARGET); |
| 383 | |
| 384 | // Record a mapping of this PC offset to the OSR id. This is used to find |
| 385 | // the AST id from the unoptimized code in order to use it as a key into |
| 386 | // the deoptimization input data found in the optimized code. |
| 387 | RecordBackEdge(stmt->OsrEntryId()); |
| 388 | |
| 389 | EmitProfilingCounterReset(); |
| 390 | |
| 391 | __ Bind(&ok); |
| 392 | PrepareForBailoutForId(stmt->EntryId(), NO_REGISTERS); |
| 393 | // Record a mapping of the OSR id to this PC. This is used if the OSR |
| 394 | // entry becomes the target of a bailout. We don't expect it to be, but |
| 395 | // we want it to work if it is. |
| 396 | PrepareForBailoutForId(stmt->OsrEntryId(), NO_REGISTERS); |
| 397 | } |
| 398 | |
| 399 | |
| 400 | void FullCodeGenerator::EmitReturnSequence() { |
| 401 | Comment cmnt(masm_, "[ Return sequence"); |
| 402 | |
| 403 | if (return_label_.is_bound()) { |
| 404 | __ B(&return_label_); |
| 405 | |
| 406 | } else { |
| 407 | __ Bind(&return_label_); |
| 408 | if (FLAG_trace) { |
| 409 | // Push the return value on the stack as the parameter. |
| 410 | // Runtime::TraceExit returns its parameter in x0. |
| 411 | __ Push(result_register()); |
| 412 | __ CallRuntime(Runtime::kTraceExit, 1); |
| 413 | DCHECK(x0.Is(result_register())); |
| 414 | } |
| 415 | // Pretend that the exit is a backwards jump to the entry. |
| 416 | int weight = 1; |
| 417 | if (info_->ShouldSelfOptimize()) { |
| 418 | weight = FLAG_interrupt_budget / FLAG_self_opt_count; |
| 419 | } else { |
| 420 | int distance = masm_->pc_offset() + kCodeSizeMultiplier / 2; |
| 421 | weight = Min(kMaxBackEdgeWeight, |
| 422 | Max(1, distance / kCodeSizeMultiplier)); |
| 423 | } |
| 424 | EmitProfilingCounterDecrement(weight); |
| 425 | Label ok; |
| 426 | __ B(pl, &ok); |
| 427 | __ Push(x0); |
| 428 | __ Call(isolate()->builtins()->InterruptCheck(), |
| 429 | RelocInfo::CODE_TARGET); |
| 430 | __ Pop(x0); |
| 431 | EmitProfilingCounterReset(); |
| 432 | __ Bind(&ok); |
| 433 | |
| 434 | // Make sure that the constant pool is not emitted inside of the return |
| 435 | // sequence. This sequence can get patched when the debugger is used. See |
| 436 | // debug-arm64.cc:BreakLocationIterator::SetDebugBreakAtReturn(). |
| 437 | { |
| 438 | InstructionAccurateScope scope(masm_, |
| 439 | Assembler::kJSRetSequenceInstructions); |
| 440 | CodeGenerator::RecordPositions(masm_, function()->end_position() - 1); |
| 441 | __ RecordJSReturn(); |
| 442 | // This code is generated using Assembler methods rather than Macro |
| 443 | // Assembler methods because it will be patched later on, and so the size |
| 444 | // of the generated code must be consistent. |
| 445 | const Register& current_sp = __ StackPointer(); |
| 446 | // Nothing ensures 16 bytes alignment here. |
| 447 | DCHECK(!current_sp.Is(csp)); |
| 448 | __ mov(current_sp, fp); |
| 449 | int no_frame_start = masm_->pc_offset(); |
| 450 | __ ldp(fp, lr, MemOperand(current_sp, 2 * kXRegSize, PostIndex)); |
| 451 | // Drop the arguments and receiver and return. |
| 452 | // TODO(all): This implementation is overkill as it supports 2**31+1 |
| 453 | // arguments, consider how to improve it without creating a security |
| 454 | // hole. |
| 455 | __ ldr_pcrel(ip0, (3 * kInstructionSize) >> kLoadLiteralScaleLog2); |
| 456 | __ add(current_sp, current_sp, ip0); |
| 457 | __ ret(); |
| 458 | __ dc64(kXRegSize * (info_->scope()->num_parameters() + 1)); |
| 459 | info_->AddNoFrameRange(no_frame_start, masm_->pc_offset()); |
| 460 | } |
| 461 | } |
| 462 | } |
| 463 | |
| 464 | |
| 465 | void FullCodeGenerator::EffectContext::Plug(Variable* var) const { |
| 466 | DCHECK(var->IsStackAllocated() || var->IsContextSlot()); |
| 467 | } |
| 468 | |
| 469 | |
| 470 | void FullCodeGenerator::AccumulatorValueContext::Plug(Variable* var) const { |
| 471 | DCHECK(var->IsStackAllocated() || var->IsContextSlot()); |
| 472 | codegen()->GetVar(result_register(), var); |
| 473 | } |
| 474 | |
| 475 | |
| 476 | void FullCodeGenerator::StackValueContext::Plug(Variable* var) const { |
| 477 | DCHECK(var->IsStackAllocated() || var->IsContextSlot()); |
| 478 | codegen()->GetVar(result_register(), var); |
| 479 | __ Push(result_register()); |
| 480 | } |
| 481 | |
| 482 | |
| 483 | void FullCodeGenerator::TestContext::Plug(Variable* var) const { |
| 484 | DCHECK(var->IsStackAllocated() || var->IsContextSlot()); |
| 485 | // For simplicity we always test the accumulator register. |
| 486 | codegen()->GetVar(result_register(), var); |
| 487 | codegen()->PrepareForBailoutBeforeSplit(condition(), false, NULL, NULL); |
| 488 | codegen()->DoTest(this); |
| 489 | } |
| 490 | |
| 491 | |
| 492 | void FullCodeGenerator::EffectContext::Plug(Heap::RootListIndex index) const { |
| 493 | // Root values have no side effects. |
| 494 | } |
| 495 | |
| 496 | |
| 497 | void FullCodeGenerator::AccumulatorValueContext::Plug( |
| 498 | Heap::RootListIndex index) const { |
| 499 | __ LoadRoot(result_register(), index); |
| 500 | } |
| 501 | |
| 502 | |
| 503 | void FullCodeGenerator::StackValueContext::Plug( |
| 504 | Heap::RootListIndex index) const { |
| 505 | __ LoadRoot(result_register(), index); |
| 506 | __ Push(result_register()); |
| 507 | } |
| 508 | |
| 509 | |
| 510 | void FullCodeGenerator::TestContext::Plug(Heap::RootListIndex index) const { |
| 511 | codegen()->PrepareForBailoutBeforeSplit(condition(), true, true_label_, |
| 512 | false_label_); |
| 513 | if (index == Heap::kUndefinedValueRootIndex || |
| 514 | index == Heap::kNullValueRootIndex || |
| 515 | index == Heap::kFalseValueRootIndex) { |
| 516 | if (false_label_ != fall_through_) __ B(false_label_); |
| 517 | } else if (index == Heap::kTrueValueRootIndex) { |
| 518 | if (true_label_ != fall_through_) __ B(true_label_); |
| 519 | } else { |
| 520 | __ LoadRoot(result_register(), index); |
| 521 | codegen()->DoTest(this); |
| 522 | } |
| 523 | } |
| 524 | |
| 525 | |
| 526 | void FullCodeGenerator::EffectContext::Plug(Handle<Object> lit) const { |
| 527 | } |
| 528 | |
| 529 | |
| 530 | void FullCodeGenerator::AccumulatorValueContext::Plug( |
| 531 | Handle<Object> lit) const { |
| 532 | __ Mov(result_register(), Operand(lit)); |
| 533 | } |
| 534 | |
| 535 | |
| 536 | void FullCodeGenerator::StackValueContext::Plug(Handle<Object> lit) const { |
| 537 | // Immediates cannot be pushed directly. |
| 538 | __ Mov(result_register(), Operand(lit)); |
| 539 | __ Push(result_register()); |
| 540 | } |
| 541 | |
| 542 | |
| 543 | void FullCodeGenerator::TestContext::Plug(Handle<Object> lit) const { |
| 544 | codegen()->PrepareForBailoutBeforeSplit(condition(), |
| 545 | true, |
| 546 | true_label_, |
| 547 | false_label_); |
| 548 | DCHECK(!lit->IsUndetectableObject()); // There are no undetectable literals. |
| 549 | if (lit->IsUndefined() || lit->IsNull() || lit->IsFalse()) { |
| 550 | if (false_label_ != fall_through_) __ B(false_label_); |
| 551 | } else if (lit->IsTrue() || lit->IsJSObject()) { |
| 552 | if (true_label_ != fall_through_) __ B(true_label_); |
| 553 | } else if (lit->IsString()) { |
| 554 | if (String::cast(*lit)->length() == 0) { |
| 555 | if (false_label_ != fall_through_) __ B(false_label_); |
| 556 | } else { |
| 557 | if (true_label_ != fall_through_) __ B(true_label_); |
| 558 | } |
| 559 | } else if (lit->IsSmi()) { |
| 560 | if (Smi::cast(*lit)->value() == 0) { |
| 561 | if (false_label_ != fall_through_) __ B(false_label_); |
| 562 | } else { |
| 563 | if (true_label_ != fall_through_) __ B(true_label_); |
| 564 | } |
| 565 | } else { |
| 566 | // For simplicity we always test the accumulator register. |
| 567 | __ Mov(result_register(), Operand(lit)); |
| 568 | codegen()->DoTest(this); |
| 569 | } |
| 570 | } |
| 571 | |
| 572 | |
| 573 | void FullCodeGenerator::EffectContext::DropAndPlug(int count, |
| 574 | Register reg) const { |
| 575 | DCHECK(count > 0); |
| 576 | __ Drop(count); |
| 577 | } |
| 578 | |
| 579 | |
| 580 | void FullCodeGenerator::AccumulatorValueContext::DropAndPlug( |
| 581 | int count, |
| 582 | Register reg) const { |
| 583 | DCHECK(count > 0); |
| 584 | __ Drop(count); |
| 585 | __ Move(result_register(), reg); |
| 586 | } |
| 587 | |
| 588 | |
| 589 | void FullCodeGenerator::StackValueContext::DropAndPlug(int count, |
| 590 | Register reg) const { |
| 591 | DCHECK(count > 0); |
| 592 | if (count > 1) __ Drop(count - 1); |
| 593 | __ Poke(reg, 0); |
| 594 | } |
| 595 | |
| 596 | |
| 597 | void FullCodeGenerator::TestContext::DropAndPlug(int count, |
| 598 | Register reg) const { |
| 599 | DCHECK(count > 0); |
| 600 | // For simplicity we always test the accumulator register. |
| 601 | __ Drop(count); |
| 602 | __ Mov(result_register(), reg); |
| 603 | codegen()->PrepareForBailoutBeforeSplit(condition(), false, NULL, NULL); |
| 604 | codegen()->DoTest(this); |
| 605 | } |
| 606 | |
| 607 | |
| 608 | void FullCodeGenerator::EffectContext::Plug(Label* materialize_true, |
| 609 | Label* materialize_false) const { |
| 610 | DCHECK(materialize_true == materialize_false); |
| 611 | __ Bind(materialize_true); |
| 612 | } |
| 613 | |
| 614 | |
| 615 | void FullCodeGenerator::AccumulatorValueContext::Plug( |
| 616 | Label* materialize_true, |
| 617 | Label* materialize_false) const { |
| 618 | Label done; |
| 619 | __ Bind(materialize_true); |
| 620 | __ LoadRoot(result_register(), Heap::kTrueValueRootIndex); |
| 621 | __ B(&done); |
| 622 | __ Bind(materialize_false); |
| 623 | __ LoadRoot(result_register(), Heap::kFalseValueRootIndex); |
| 624 | __ Bind(&done); |
| 625 | } |
| 626 | |
| 627 | |
| 628 | void FullCodeGenerator::StackValueContext::Plug( |
| 629 | Label* materialize_true, |
| 630 | Label* materialize_false) const { |
| 631 | Label done; |
| 632 | __ Bind(materialize_true); |
| 633 | __ LoadRoot(x10, Heap::kTrueValueRootIndex); |
| 634 | __ B(&done); |
| 635 | __ Bind(materialize_false); |
| 636 | __ LoadRoot(x10, Heap::kFalseValueRootIndex); |
| 637 | __ Bind(&done); |
| 638 | __ Push(x10); |
| 639 | } |
| 640 | |
| 641 | |
| 642 | void FullCodeGenerator::TestContext::Plug(Label* materialize_true, |
| 643 | Label* materialize_false) const { |
| 644 | DCHECK(materialize_true == true_label_); |
| 645 | DCHECK(materialize_false == false_label_); |
| 646 | } |
| 647 | |
| 648 | |
| 649 | void FullCodeGenerator::EffectContext::Plug(bool flag) const { |
| 650 | } |
| 651 | |
| 652 | |
| 653 | void FullCodeGenerator::AccumulatorValueContext::Plug(bool flag) const { |
| 654 | Heap::RootListIndex value_root_index = |
| 655 | flag ? Heap::kTrueValueRootIndex : Heap::kFalseValueRootIndex; |
| 656 | __ LoadRoot(result_register(), value_root_index); |
| 657 | } |
| 658 | |
| 659 | |
| 660 | void FullCodeGenerator::StackValueContext::Plug(bool flag) const { |
| 661 | Heap::RootListIndex value_root_index = |
| 662 | flag ? Heap::kTrueValueRootIndex : Heap::kFalseValueRootIndex; |
| 663 | __ LoadRoot(x10, value_root_index); |
| 664 | __ Push(x10); |
| 665 | } |
| 666 | |
| 667 | |
| 668 | void FullCodeGenerator::TestContext::Plug(bool flag) const { |
| 669 | codegen()->PrepareForBailoutBeforeSplit(condition(), |
| 670 | true, |
| 671 | true_label_, |
| 672 | false_label_); |
| 673 | if (flag) { |
| 674 | if (true_label_ != fall_through_) { |
| 675 | __ B(true_label_); |
| 676 | } |
| 677 | } else { |
| 678 | if (false_label_ != fall_through_) { |
| 679 | __ B(false_label_); |
| 680 | } |
| 681 | } |
| 682 | } |
| 683 | |
| 684 | |
| 685 | void FullCodeGenerator::DoTest(Expression* condition, |
| 686 | Label* if_true, |
| 687 | Label* if_false, |
| 688 | Label* fall_through) { |
| 689 | Handle<Code> ic = ToBooleanStub::GetUninitialized(isolate()); |
| 690 | CallIC(ic, condition->test_id()); |
| 691 | __ CompareAndSplit(result_register(), 0, ne, if_true, if_false, fall_through); |
| 692 | } |
| 693 | |
| 694 | |
| 695 | // If (cond), branch to if_true. |
| 696 | // If (!cond), branch to if_false. |
| 697 | // fall_through is used as an optimization in cases where only one branch |
| 698 | // instruction is necessary. |
| 699 | void FullCodeGenerator::Split(Condition cond, |
| 700 | Label* if_true, |
| 701 | Label* if_false, |
| 702 | Label* fall_through) { |
| 703 | if (if_false == fall_through) { |
| 704 | __ B(cond, if_true); |
| 705 | } else if (if_true == fall_through) { |
| 706 | DCHECK(if_false != fall_through); |
| 707 | __ B(NegateCondition(cond), if_false); |
| 708 | } else { |
| 709 | __ B(cond, if_true); |
| 710 | __ B(if_false); |
| 711 | } |
| 712 | } |
| 713 | |
| 714 | |
| 715 | MemOperand FullCodeGenerator::StackOperand(Variable* var) { |
| 716 | // Offset is negative because higher indexes are at lower addresses. |
| 717 | int offset = -var->index() * kXRegSize; |
| 718 | // Adjust by a (parameter or local) base offset. |
| 719 | if (var->IsParameter()) { |
| 720 | offset += (info_->scope()->num_parameters() + 1) * kPointerSize; |
| 721 | } else { |
| 722 | offset += JavaScriptFrameConstants::kLocal0Offset; |
| 723 | } |
| 724 | return MemOperand(fp, offset); |
| 725 | } |
| 726 | |
| 727 | |
| 728 | MemOperand FullCodeGenerator::VarOperand(Variable* var, Register scratch) { |
| 729 | DCHECK(var->IsContextSlot() || var->IsStackAllocated()); |
| 730 | if (var->IsContextSlot()) { |
| 731 | int context_chain_length = scope()->ContextChainLength(var->scope()); |
| 732 | __ LoadContext(scratch, context_chain_length); |
| 733 | return ContextMemOperand(scratch, var->index()); |
| 734 | } else { |
| 735 | return StackOperand(var); |
| 736 | } |
| 737 | } |
| 738 | |
| 739 | |
| 740 | void FullCodeGenerator::GetVar(Register dest, Variable* var) { |
| 741 | // Use destination as scratch. |
| 742 | MemOperand location = VarOperand(var, dest); |
| 743 | __ Ldr(dest, location); |
| 744 | } |
| 745 | |
| 746 | |
| 747 | void FullCodeGenerator::SetVar(Variable* var, |
| 748 | Register src, |
| 749 | Register scratch0, |
| 750 | Register scratch1) { |
| 751 | DCHECK(var->IsContextSlot() || var->IsStackAllocated()); |
| 752 | DCHECK(!AreAliased(src, scratch0, scratch1)); |
| 753 | MemOperand location = VarOperand(var, scratch0); |
| 754 | __ Str(src, location); |
| 755 | |
| 756 | // Emit the write barrier code if the location is in the heap. |
| 757 | if (var->IsContextSlot()) { |
| 758 | // scratch0 contains the correct context. |
| 759 | __ RecordWriteContextSlot(scratch0, |
| 760 | location.offset(), |
| 761 | src, |
| 762 | scratch1, |
| 763 | kLRHasBeenSaved, |
| 764 | kDontSaveFPRegs); |
| 765 | } |
| 766 | } |
| 767 | |
| 768 | |
| 769 | void FullCodeGenerator::PrepareForBailoutBeforeSplit(Expression* expr, |
| 770 | bool should_normalize, |
| 771 | Label* if_true, |
| 772 | Label* if_false) { |
| 773 | // Only prepare for bailouts before splits if we're in a test |
| 774 | // context. Otherwise, we let the Visit function deal with the |
| 775 | // preparation to avoid preparing with the same AST id twice. |
| 776 | if (!context()->IsTest() || !info_->IsOptimizable()) return; |
| 777 | |
| 778 | // TODO(all): Investigate to see if there is something to work on here. |
| 779 | Label skip; |
| 780 | if (should_normalize) { |
| 781 | __ B(&skip); |
| 782 | } |
| 783 | PrepareForBailout(expr, TOS_REG); |
| 784 | if (should_normalize) { |
| 785 | __ CompareRoot(x0, Heap::kTrueValueRootIndex); |
| 786 | Split(eq, if_true, if_false, NULL); |
| 787 | __ Bind(&skip); |
| 788 | } |
| 789 | } |
| 790 | |
| 791 | |
| 792 | void FullCodeGenerator::EmitDebugCheckDeclarationContext(Variable* variable) { |
| 793 | // The variable in the declaration always resides in the current function |
| 794 | // context. |
| 795 | DCHECK_EQ(0, scope()->ContextChainLength(variable->scope())); |
| 796 | if (generate_debug_code_) { |
| 797 | // Check that we're not inside a with or catch context. |
| 798 | __ Ldr(x1, FieldMemOperand(cp, HeapObject::kMapOffset)); |
| 799 | __ CompareRoot(x1, Heap::kWithContextMapRootIndex); |
| 800 | __ Check(ne, kDeclarationInWithContext); |
| 801 | __ CompareRoot(x1, Heap::kCatchContextMapRootIndex); |
| 802 | __ Check(ne, kDeclarationInCatchContext); |
| 803 | } |
| 804 | } |
| 805 | |
| 806 | |
| 807 | void FullCodeGenerator::VisitVariableDeclaration( |
| 808 | VariableDeclaration* declaration) { |
| 809 | // If it was not possible to allocate the variable at compile time, we |
| 810 | // need to "declare" it at runtime to make sure it actually exists in the |
| 811 | // local context. |
| 812 | VariableProxy* proxy = declaration->proxy(); |
| 813 | VariableMode mode = declaration->mode(); |
| 814 | Variable* variable = proxy->var(); |
| 815 | bool hole_init = mode == LET || mode == CONST || mode == CONST_LEGACY; |
| 816 | |
| 817 | switch (variable->location()) { |
| 818 | case Variable::UNALLOCATED: |
| 819 | globals_->Add(variable->name(), zone()); |
| 820 | globals_->Add(variable->binding_needs_init() |
| 821 | ? isolate()->factory()->the_hole_value() |
| 822 | : isolate()->factory()->undefined_value(), |
| 823 | zone()); |
| 824 | break; |
| 825 | |
| 826 | case Variable::PARAMETER: |
| 827 | case Variable::LOCAL: |
| 828 | if (hole_init) { |
| 829 | Comment cmnt(masm_, "[ VariableDeclaration"); |
| 830 | __ LoadRoot(x10, Heap::kTheHoleValueRootIndex); |
| 831 | __ Str(x10, StackOperand(variable)); |
| 832 | } |
| 833 | break; |
| 834 | |
| 835 | case Variable::CONTEXT: |
| 836 | if (hole_init) { |
| 837 | Comment cmnt(masm_, "[ VariableDeclaration"); |
| 838 | EmitDebugCheckDeclarationContext(variable); |
| 839 | __ LoadRoot(x10, Heap::kTheHoleValueRootIndex); |
| 840 | __ Str(x10, ContextMemOperand(cp, variable->index())); |
| 841 | // No write barrier since the_hole_value is in old space. |
| 842 | PrepareForBailoutForId(proxy->id(), NO_REGISTERS); |
| 843 | } |
| 844 | break; |
| 845 | |
| 846 | case Variable::LOOKUP: { |
| 847 | Comment cmnt(masm_, "[ VariableDeclaration"); |
| 848 | __ Mov(x2, Operand(variable->name())); |
| 849 | // Declaration nodes are always introduced in one of four modes. |
| 850 | DCHECK(IsDeclaredVariableMode(mode)); |
| 851 | PropertyAttributes attr = IsImmutableVariableMode(mode) ? READ_ONLY |
| 852 | : NONE; |
| 853 | __ Mov(x1, Smi::FromInt(attr)); |
| 854 | // Push initial value, if any. |
| 855 | // Note: For variables we must not push an initial value (such as |
| 856 | // 'undefined') because we may have a (legal) redeclaration and we |
| 857 | // must not destroy the current value. |
| 858 | if (hole_init) { |
| 859 | __ LoadRoot(x0, Heap::kTheHoleValueRootIndex); |
| 860 | __ Push(cp, x2, x1, x0); |
| 861 | } else { |
| 862 | // Pushing 0 (xzr) indicates no initial value. |
| 863 | __ Push(cp, x2, x1, xzr); |
| 864 | } |
| 865 | __ CallRuntime(Runtime::kDeclareLookupSlot, 4); |
| 866 | break; |
| 867 | } |
| 868 | } |
| 869 | } |
| 870 | |
| 871 | |
| 872 | void FullCodeGenerator::VisitFunctionDeclaration( |
| 873 | FunctionDeclaration* declaration) { |
| 874 | VariableProxy* proxy = declaration->proxy(); |
| 875 | Variable* variable = proxy->var(); |
| 876 | switch (variable->location()) { |
| 877 | case Variable::UNALLOCATED: { |
| 878 | globals_->Add(variable->name(), zone()); |
| 879 | Handle<SharedFunctionInfo> function = |
| 880 | Compiler::BuildFunctionInfo(declaration->fun(), script(), info_); |
| 881 | // Check for stack overflow exception. |
| 882 | if (function.is_null()) return SetStackOverflow(); |
| 883 | globals_->Add(function, zone()); |
| 884 | break; |
| 885 | } |
| 886 | |
| 887 | case Variable::PARAMETER: |
| 888 | case Variable::LOCAL: { |
| 889 | Comment cmnt(masm_, "[ Function Declaration"); |
| 890 | VisitForAccumulatorValue(declaration->fun()); |
| 891 | __ Str(result_register(), StackOperand(variable)); |
| 892 | break; |
| 893 | } |
| 894 | |
| 895 | case Variable::CONTEXT: { |
| 896 | Comment cmnt(masm_, "[ Function Declaration"); |
| 897 | EmitDebugCheckDeclarationContext(variable); |
| 898 | VisitForAccumulatorValue(declaration->fun()); |
| 899 | __ Str(result_register(), ContextMemOperand(cp, variable->index())); |
| 900 | int offset = Context::SlotOffset(variable->index()); |
| 901 | // We know that we have written a function, which is not a smi. |
| 902 | __ RecordWriteContextSlot(cp, |
| 903 | offset, |
| 904 | result_register(), |
| 905 | x2, |
| 906 | kLRHasBeenSaved, |
| 907 | kDontSaveFPRegs, |
| 908 | EMIT_REMEMBERED_SET, |
| 909 | OMIT_SMI_CHECK); |
| 910 | PrepareForBailoutForId(proxy->id(), NO_REGISTERS); |
| 911 | break; |
| 912 | } |
| 913 | |
| 914 | case Variable::LOOKUP: { |
| 915 | Comment cmnt(masm_, "[ Function Declaration"); |
| 916 | __ Mov(x2, Operand(variable->name())); |
| 917 | __ Mov(x1, Smi::FromInt(NONE)); |
| 918 | __ Push(cp, x2, x1); |
| 919 | // Push initial value for function declaration. |
| 920 | VisitForStackValue(declaration->fun()); |
| 921 | __ CallRuntime(Runtime::kDeclareLookupSlot, 4); |
| 922 | break; |
| 923 | } |
| 924 | } |
| 925 | } |
| 926 | |
| 927 | |
| 928 | void FullCodeGenerator::VisitModuleDeclaration(ModuleDeclaration* declaration) { |
| 929 | Variable* variable = declaration->proxy()->var(); |
| 930 | DCHECK(variable->location() == Variable::CONTEXT); |
| 931 | DCHECK(variable->interface()->IsFrozen()); |
| 932 | |
| 933 | Comment cmnt(masm_, "[ ModuleDeclaration"); |
| 934 | EmitDebugCheckDeclarationContext(variable); |
| 935 | |
| 936 | // Load instance object. |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 937 | __ LoadContext(x1, scope_->ContextChainLength(scope_->ScriptScope())); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 938 | __ Ldr(x1, ContextMemOperand(x1, variable->interface()->Index())); |
| 939 | __ Ldr(x1, ContextMemOperand(x1, Context::EXTENSION_INDEX)); |
| 940 | |
| 941 | // Assign it. |
| 942 | __ Str(x1, ContextMemOperand(cp, variable->index())); |
| 943 | // We know that we have written a module, which is not a smi. |
| 944 | __ RecordWriteContextSlot(cp, |
| 945 | Context::SlotOffset(variable->index()), |
| 946 | x1, |
| 947 | x3, |
| 948 | kLRHasBeenSaved, |
| 949 | kDontSaveFPRegs, |
| 950 | EMIT_REMEMBERED_SET, |
| 951 | OMIT_SMI_CHECK); |
| 952 | PrepareForBailoutForId(declaration->proxy()->id(), NO_REGISTERS); |
| 953 | |
| 954 | // Traverse info body. |
| 955 | Visit(declaration->module()); |
| 956 | } |
| 957 | |
| 958 | |
| 959 | void FullCodeGenerator::VisitImportDeclaration(ImportDeclaration* declaration) { |
| 960 | VariableProxy* proxy = declaration->proxy(); |
| 961 | Variable* variable = proxy->var(); |
| 962 | switch (variable->location()) { |
| 963 | case Variable::UNALLOCATED: |
| 964 | // TODO(rossberg) |
| 965 | break; |
| 966 | |
| 967 | case Variable::CONTEXT: { |
| 968 | Comment cmnt(masm_, "[ ImportDeclaration"); |
| 969 | EmitDebugCheckDeclarationContext(variable); |
| 970 | // TODO(rossberg) |
| 971 | break; |
| 972 | } |
| 973 | |
| 974 | case Variable::PARAMETER: |
| 975 | case Variable::LOCAL: |
| 976 | case Variable::LOOKUP: |
| 977 | UNREACHABLE(); |
| 978 | } |
| 979 | } |
| 980 | |
| 981 | |
| 982 | void FullCodeGenerator::VisitExportDeclaration(ExportDeclaration* declaration) { |
| 983 | // TODO(rossberg) |
| 984 | } |
| 985 | |
| 986 | |
| 987 | void FullCodeGenerator::DeclareGlobals(Handle<FixedArray> pairs) { |
| 988 | // Call the runtime to declare the globals. |
| 989 | __ Mov(x11, Operand(pairs)); |
| 990 | Register flags = xzr; |
| 991 | if (Smi::FromInt(DeclareGlobalsFlags())) { |
| 992 | flags = x10; |
| 993 | __ Mov(flags, Smi::FromInt(DeclareGlobalsFlags())); |
| 994 | } |
| 995 | __ Push(cp, x11, flags); |
| 996 | __ CallRuntime(Runtime::kDeclareGlobals, 3); |
| 997 | // Return value is ignored. |
| 998 | } |
| 999 | |
| 1000 | |
| 1001 | void FullCodeGenerator::DeclareModules(Handle<FixedArray> descriptions) { |
| 1002 | // Call the runtime to declare the modules. |
| 1003 | __ Push(descriptions); |
| 1004 | __ CallRuntime(Runtime::kDeclareModules, 1); |
| 1005 | // Return value is ignored. |
| 1006 | } |
| 1007 | |
| 1008 | |
| 1009 | void FullCodeGenerator::VisitSwitchStatement(SwitchStatement* stmt) { |
| 1010 | ASM_LOCATION("FullCodeGenerator::VisitSwitchStatement"); |
| 1011 | Comment cmnt(masm_, "[ SwitchStatement"); |
| 1012 | Breakable nested_statement(this, stmt); |
| 1013 | SetStatementPosition(stmt); |
| 1014 | |
| 1015 | // Keep the switch value on the stack until a case matches. |
| 1016 | VisitForStackValue(stmt->tag()); |
| 1017 | PrepareForBailoutForId(stmt->EntryId(), NO_REGISTERS); |
| 1018 | |
| 1019 | ZoneList<CaseClause*>* clauses = stmt->cases(); |
| 1020 | CaseClause* default_clause = NULL; // Can occur anywhere in the list. |
| 1021 | |
| 1022 | Label next_test; // Recycled for each test. |
| 1023 | // Compile all the tests with branches to their bodies. |
| 1024 | for (int i = 0; i < clauses->length(); i++) { |
| 1025 | CaseClause* clause = clauses->at(i); |
| 1026 | clause->body_target()->Unuse(); |
| 1027 | |
| 1028 | // The default is not a test, but remember it as final fall through. |
| 1029 | if (clause->is_default()) { |
| 1030 | default_clause = clause; |
| 1031 | continue; |
| 1032 | } |
| 1033 | |
| 1034 | Comment cmnt(masm_, "[ Case comparison"); |
| 1035 | __ Bind(&next_test); |
| 1036 | next_test.Unuse(); |
| 1037 | |
| 1038 | // Compile the label expression. |
| 1039 | VisitForAccumulatorValue(clause->label()); |
| 1040 | |
| 1041 | // Perform the comparison as if via '==='. |
| 1042 | __ Peek(x1, 0); // Switch value. |
| 1043 | |
| 1044 | JumpPatchSite patch_site(masm_); |
| 1045 | if (ShouldInlineSmiCase(Token::EQ_STRICT)) { |
| 1046 | Label slow_case; |
| 1047 | patch_site.EmitJumpIfEitherNotSmi(x0, x1, &slow_case); |
| 1048 | __ Cmp(x1, x0); |
| 1049 | __ B(ne, &next_test); |
| 1050 | __ Drop(1); // Switch value is no longer needed. |
| 1051 | __ B(clause->body_target()); |
| 1052 | __ Bind(&slow_case); |
| 1053 | } |
| 1054 | |
| 1055 | // Record position before stub call for type feedback. |
| 1056 | SetSourcePosition(clause->position()); |
| 1057 | Handle<Code> ic = |
| 1058 | CodeFactory::CompareIC(isolate(), Token::EQ_STRICT).code(); |
| 1059 | CallIC(ic, clause->CompareId()); |
| 1060 | patch_site.EmitPatchInfo(); |
| 1061 | |
| 1062 | Label skip; |
| 1063 | __ B(&skip); |
| 1064 | PrepareForBailout(clause, TOS_REG); |
| 1065 | __ JumpIfNotRoot(x0, Heap::kTrueValueRootIndex, &next_test); |
| 1066 | __ Drop(1); |
| 1067 | __ B(clause->body_target()); |
| 1068 | __ Bind(&skip); |
| 1069 | |
| 1070 | __ Cbnz(x0, &next_test); |
| 1071 | __ Drop(1); // Switch value is no longer needed. |
| 1072 | __ B(clause->body_target()); |
| 1073 | } |
| 1074 | |
| 1075 | // Discard the test value and jump to the default if present, otherwise to |
| 1076 | // the end of the statement. |
| 1077 | __ Bind(&next_test); |
| 1078 | __ Drop(1); // Switch value is no longer needed. |
| 1079 | if (default_clause == NULL) { |
| 1080 | __ B(nested_statement.break_label()); |
| 1081 | } else { |
| 1082 | __ B(default_clause->body_target()); |
| 1083 | } |
| 1084 | |
| 1085 | // Compile all the case bodies. |
| 1086 | for (int i = 0; i < clauses->length(); i++) { |
| 1087 | Comment cmnt(masm_, "[ Case body"); |
| 1088 | CaseClause* clause = clauses->at(i); |
| 1089 | __ Bind(clause->body_target()); |
| 1090 | PrepareForBailoutForId(clause->EntryId(), NO_REGISTERS); |
| 1091 | VisitStatements(clause->statements()); |
| 1092 | } |
| 1093 | |
| 1094 | __ Bind(nested_statement.break_label()); |
| 1095 | PrepareForBailoutForId(stmt->ExitId(), NO_REGISTERS); |
| 1096 | } |
| 1097 | |
| 1098 | |
| 1099 | void FullCodeGenerator::VisitForInStatement(ForInStatement* stmt) { |
| 1100 | ASM_LOCATION("FullCodeGenerator::VisitForInStatement"); |
| 1101 | Comment cmnt(masm_, "[ ForInStatement"); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 1102 | FeedbackVectorSlot slot = stmt->ForInFeedbackSlot(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1103 | // TODO(all): This visitor probably needs better comments and a revisit. |
| 1104 | SetStatementPosition(stmt); |
| 1105 | |
| 1106 | Label loop, exit; |
| 1107 | ForIn loop_statement(this, stmt); |
| 1108 | increment_loop_depth(); |
| 1109 | |
| 1110 | // Get the object to enumerate over. If the object is null or undefined, skip |
| 1111 | // over the loop. See ECMA-262 version 5, section 12.6.4. |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 1112 | SetExpressionPosition(stmt->enumerable()); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1113 | VisitForAccumulatorValue(stmt->enumerable()); |
| 1114 | __ JumpIfRoot(x0, Heap::kUndefinedValueRootIndex, &exit); |
| 1115 | Register null_value = x15; |
| 1116 | __ LoadRoot(null_value, Heap::kNullValueRootIndex); |
| 1117 | __ Cmp(x0, null_value); |
| 1118 | __ B(eq, &exit); |
| 1119 | |
| 1120 | PrepareForBailoutForId(stmt->PrepareId(), TOS_REG); |
| 1121 | |
| 1122 | // Convert the object to a JS object. |
| 1123 | Label convert, done_convert; |
| 1124 | __ JumpIfSmi(x0, &convert); |
| 1125 | __ JumpIfObjectType(x0, x10, x11, FIRST_SPEC_OBJECT_TYPE, &done_convert, ge); |
| 1126 | __ Bind(&convert); |
| 1127 | __ Push(x0); |
| 1128 | __ InvokeBuiltin(Builtins::TO_OBJECT, CALL_FUNCTION); |
| 1129 | __ Bind(&done_convert); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 1130 | PrepareForBailoutForId(stmt->ToObjectId(), TOS_REG); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1131 | __ Push(x0); |
| 1132 | |
| 1133 | // Check for proxies. |
| 1134 | Label call_runtime; |
| 1135 | STATIC_ASSERT(FIRST_JS_PROXY_TYPE == FIRST_SPEC_OBJECT_TYPE); |
| 1136 | __ JumpIfObjectType(x0, x10, x11, LAST_JS_PROXY_TYPE, &call_runtime, le); |
| 1137 | |
| 1138 | // Check cache validity in generated code. This is a fast case for |
| 1139 | // the JSObject::IsSimpleEnum cache validity checks. If we cannot |
| 1140 | // guarantee cache validity, call the runtime system to check cache |
| 1141 | // validity or get the property names in a fixed array. |
| 1142 | __ CheckEnumCache(x0, null_value, x10, x11, x12, x13, &call_runtime); |
| 1143 | |
| 1144 | // The enum cache is valid. Load the map of the object being |
| 1145 | // iterated over and use the cache for the iteration. |
| 1146 | Label use_cache; |
| 1147 | __ Ldr(x0, FieldMemOperand(x0, HeapObject::kMapOffset)); |
| 1148 | __ B(&use_cache); |
| 1149 | |
| 1150 | // Get the set of properties to enumerate. |
| 1151 | __ Bind(&call_runtime); |
| 1152 | __ Push(x0); // Duplicate the enumerable object on the stack. |
| 1153 | __ CallRuntime(Runtime::kGetPropertyNamesFast, 1); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 1154 | PrepareForBailoutForId(stmt->EnumId(), TOS_REG); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1155 | |
| 1156 | // If we got a map from the runtime call, we can do a fast |
| 1157 | // modification check. Otherwise, we got a fixed array, and we have |
| 1158 | // to do a slow check. |
| 1159 | Label fixed_array, no_descriptors; |
| 1160 | __ Ldr(x2, FieldMemOperand(x0, HeapObject::kMapOffset)); |
| 1161 | __ JumpIfNotRoot(x2, Heap::kMetaMapRootIndex, &fixed_array); |
| 1162 | |
| 1163 | // We got a map in register x0. Get the enumeration cache from it. |
| 1164 | __ Bind(&use_cache); |
| 1165 | |
| 1166 | __ EnumLengthUntagged(x1, x0); |
| 1167 | __ Cbz(x1, &no_descriptors); |
| 1168 | |
| 1169 | __ LoadInstanceDescriptors(x0, x2); |
| 1170 | __ Ldr(x2, FieldMemOperand(x2, DescriptorArray::kEnumCacheOffset)); |
| 1171 | __ Ldr(x2, |
| 1172 | FieldMemOperand(x2, DescriptorArray::kEnumCacheBridgeCacheOffset)); |
| 1173 | |
| 1174 | // Set up the four remaining stack slots. |
| 1175 | __ SmiTag(x1); |
| 1176 | // Map, enumeration cache, enum cache length, zero (both last as smis). |
| 1177 | __ Push(x0, x2, x1, xzr); |
| 1178 | __ B(&loop); |
| 1179 | |
| 1180 | __ Bind(&no_descriptors); |
| 1181 | __ Drop(1); |
| 1182 | __ B(&exit); |
| 1183 | |
| 1184 | // We got a fixed array in register x0. Iterate through that. |
| 1185 | __ Bind(&fixed_array); |
| 1186 | |
| 1187 | __ LoadObject(x1, FeedbackVector()); |
| 1188 | __ Mov(x10, Operand(TypeFeedbackVector::MegamorphicSentinel(isolate()))); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 1189 | int vector_index = FeedbackVector()->GetIndex(slot); |
| 1190 | __ Str(x10, FieldMemOperand(x1, FixedArray::OffsetOfElementAt(vector_index))); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1191 | |
| 1192 | __ Mov(x1, Smi::FromInt(1)); // Smi indicates slow check. |
| 1193 | __ Peek(x10, 0); // Get enumerated object. |
| 1194 | STATIC_ASSERT(FIRST_JS_PROXY_TYPE == FIRST_SPEC_OBJECT_TYPE); |
| 1195 | // TODO(all): similar check was done already. Can we avoid it here? |
| 1196 | __ CompareObjectType(x10, x11, x12, LAST_JS_PROXY_TYPE); |
| 1197 | DCHECK(Smi::FromInt(0) == 0); |
| 1198 | __ CzeroX(x1, le); // Zero indicates proxy. |
| 1199 | __ Ldr(x2, FieldMemOperand(x0, FixedArray::kLengthOffset)); |
| 1200 | // Smi and array, fixed array length (as smi) and initial index. |
| 1201 | __ Push(x1, x0, x2, xzr); |
| 1202 | |
| 1203 | // Generate code for doing the condition check. |
| 1204 | PrepareForBailoutForId(stmt->BodyId(), NO_REGISTERS); |
| 1205 | __ Bind(&loop); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 1206 | SetExpressionPosition(stmt->each()); |
| 1207 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1208 | // Load the current count to x0, load the length to x1. |
| 1209 | __ PeekPair(x0, x1, 0); |
| 1210 | __ Cmp(x0, x1); // Compare to the array length. |
| 1211 | __ B(hs, loop_statement.break_label()); |
| 1212 | |
| 1213 | // Get the current entry of the array into register r3. |
| 1214 | __ Peek(x10, 2 * kXRegSize); |
| 1215 | __ Add(x10, x10, Operand::UntagSmiAndScale(x0, kPointerSizeLog2)); |
| 1216 | __ Ldr(x3, MemOperand(x10, FixedArray::kHeaderSize - kHeapObjectTag)); |
| 1217 | |
| 1218 | // Get the expected map from the stack or a smi in the |
| 1219 | // permanent slow case into register x10. |
| 1220 | __ Peek(x2, 3 * kXRegSize); |
| 1221 | |
| 1222 | // Check if the expected map still matches that of the enumerable. |
| 1223 | // If not, we may have to filter the key. |
| 1224 | Label update_each; |
| 1225 | __ Peek(x1, 4 * kXRegSize); |
| 1226 | __ Ldr(x11, FieldMemOperand(x1, HeapObject::kMapOffset)); |
| 1227 | __ Cmp(x11, x2); |
| 1228 | __ B(eq, &update_each); |
| 1229 | |
| 1230 | // For proxies, no filtering is done. |
| 1231 | // TODO(rossberg): What if only a prototype is a proxy? Not specified yet. |
| 1232 | STATIC_ASSERT(kSmiTag == 0); |
| 1233 | __ Cbz(x2, &update_each); |
| 1234 | |
| 1235 | // Convert the entry to a string or (smi) 0 if it isn't a property |
| 1236 | // any more. If the property has been removed while iterating, we |
| 1237 | // just skip it. |
| 1238 | __ Push(x1, x3); |
| 1239 | __ InvokeBuiltin(Builtins::FILTER_KEY, CALL_FUNCTION); |
| 1240 | __ Mov(x3, x0); |
| 1241 | __ Cbz(x0, loop_statement.continue_label()); |
| 1242 | |
| 1243 | // Update the 'each' property or variable from the possibly filtered |
| 1244 | // entry in register x3. |
| 1245 | __ Bind(&update_each); |
| 1246 | __ Mov(result_register(), x3); |
| 1247 | // Perform the assignment as if via '='. |
| 1248 | { EffectContext context(this); |
| 1249 | EmitAssignment(stmt->each()); |
| 1250 | } |
| 1251 | |
| 1252 | // Generate code for the body of the loop. |
| 1253 | Visit(stmt->body()); |
| 1254 | |
| 1255 | // Generate code for going to the next element by incrementing |
| 1256 | // the index (smi) stored on top of the stack. |
| 1257 | __ Bind(loop_statement.continue_label()); |
| 1258 | // TODO(all): We could use a callee saved register to avoid popping. |
| 1259 | __ Pop(x0); |
| 1260 | __ Add(x0, x0, Smi::FromInt(1)); |
| 1261 | __ Push(x0); |
| 1262 | |
| 1263 | EmitBackEdgeBookkeeping(stmt, &loop); |
| 1264 | __ B(&loop); |
| 1265 | |
| 1266 | // Remove the pointers stored on the stack. |
| 1267 | __ Bind(loop_statement.break_label()); |
| 1268 | __ Drop(5); |
| 1269 | |
| 1270 | // Exit and decrement the loop depth. |
| 1271 | PrepareForBailoutForId(stmt->ExitId(), NO_REGISTERS); |
| 1272 | __ Bind(&exit); |
| 1273 | decrement_loop_depth(); |
| 1274 | } |
| 1275 | |
| 1276 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1277 | void FullCodeGenerator::EmitNewClosure(Handle<SharedFunctionInfo> info, |
| 1278 | bool pretenure) { |
| 1279 | // Use the fast case closure allocation code that allocates in new space for |
| 1280 | // nested functions that don't need literals cloning. If we're running with |
| 1281 | // the --always-opt or the --prepare-always-opt flag, we need to use the |
| 1282 | // runtime function so that the new function we are creating here gets a |
| 1283 | // chance to have its code optimized and doesn't just get a copy of the |
| 1284 | // existing unoptimized code. |
| 1285 | if (!FLAG_always_opt && |
| 1286 | !FLAG_prepare_always_opt && |
| 1287 | !pretenure && |
| 1288 | scope()->is_function_scope() && |
| 1289 | info->num_literals() == 0) { |
| 1290 | FastNewClosureStub stub(isolate(), info->strict_mode(), info->kind()); |
| 1291 | __ Mov(x2, Operand(info)); |
| 1292 | __ CallStub(&stub); |
| 1293 | } else { |
| 1294 | __ Mov(x11, Operand(info)); |
| 1295 | __ LoadRoot(x10, pretenure ? Heap::kTrueValueRootIndex |
| 1296 | : Heap::kFalseValueRootIndex); |
| 1297 | __ Push(cp, x11, x10); |
| 1298 | __ CallRuntime(Runtime::kNewClosure, 3); |
| 1299 | } |
| 1300 | context()->Plug(x0); |
| 1301 | } |
| 1302 | |
| 1303 | |
| 1304 | void FullCodeGenerator::VisitVariableProxy(VariableProxy* expr) { |
| 1305 | Comment cmnt(masm_, "[ VariableProxy"); |
| 1306 | EmitVariableLoad(expr); |
| 1307 | } |
| 1308 | |
| 1309 | |
| 1310 | void FullCodeGenerator::EmitLoadHomeObject(SuperReference* expr) { |
| 1311 | Comment cnmt(masm_, "[ SuperReference "); |
| 1312 | |
| 1313 | __ ldr(LoadDescriptor::ReceiverRegister(), |
| 1314 | MemOperand(fp, JavaScriptFrameConstants::kFunctionOffset)); |
| 1315 | |
| 1316 | Handle<Symbol> home_object_symbol(isolate()->heap()->home_object_symbol()); |
| 1317 | __ Mov(LoadDescriptor::NameRegister(), Operand(home_object_symbol)); |
| 1318 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 1319 | if (FLAG_vector_ics) { |
| 1320 | __ Mov(VectorLoadICDescriptor::SlotRegister(), |
| 1321 | SmiFromSlot(expr->HomeObjectFeedbackSlot())); |
| 1322 | CallLoadIC(NOT_CONTEXTUAL); |
| 1323 | } else { |
| 1324 | CallLoadIC(NOT_CONTEXTUAL, expr->HomeObjectFeedbackId()); |
| 1325 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1326 | |
| 1327 | __ Mov(x10, Operand(isolate()->factory()->undefined_value())); |
| 1328 | __ cmp(x0, x10); |
| 1329 | Label done; |
| 1330 | __ b(&done, ne); |
| 1331 | __ CallRuntime(Runtime::kThrowNonMethodError, 0); |
| 1332 | __ bind(&done); |
| 1333 | } |
| 1334 | |
| 1335 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 1336 | void FullCodeGenerator::EmitSetHomeObjectIfNeeded(Expression* initializer, |
| 1337 | int offset) { |
| 1338 | if (NeedsHomeObject(initializer)) { |
| 1339 | __ Peek(StoreDescriptor::ReceiverRegister(), 0); |
| 1340 | __ Mov(StoreDescriptor::NameRegister(), |
| 1341 | Operand(isolate()->factory()->home_object_symbol())); |
| 1342 | __ Peek(StoreDescriptor::ValueRegister(), offset * kPointerSize); |
| 1343 | CallStoreIC(); |
| 1344 | } |
| 1345 | } |
| 1346 | |
| 1347 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1348 | void FullCodeGenerator::EmitLoadGlobalCheckExtensions(VariableProxy* proxy, |
| 1349 | TypeofState typeof_state, |
| 1350 | Label* slow) { |
| 1351 | Register current = cp; |
| 1352 | Register next = x10; |
| 1353 | Register temp = x11; |
| 1354 | |
| 1355 | Scope* s = scope(); |
| 1356 | while (s != NULL) { |
| 1357 | if (s->num_heap_slots() > 0) { |
| 1358 | if (s->calls_sloppy_eval()) { |
| 1359 | // Check that extension is NULL. |
| 1360 | __ Ldr(temp, ContextMemOperand(current, Context::EXTENSION_INDEX)); |
| 1361 | __ Cbnz(temp, slow); |
| 1362 | } |
| 1363 | // Load next context in chain. |
| 1364 | __ Ldr(next, ContextMemOperand(current, Context::PREVIOUS_INDEX)); |
| 1365 | // Walk the rest of the chain without clobbering cp. |
| 1366 | current = next; |
| 1367 | } |
| 1368 | // If no outer scope calls eval, we do not need to check more |
| 1369 | // context extensions. |
| 1370 | if (!s->outer_scope_calls_sloppy_eval() || s->is_eval_scope()) break; |
| 1371 | s = s->outer_scope(); |
| 1372 | } |
| 1373 | |
| 1374 | if (s->is_eval_scope()) { |
| 1375 | Label loop, fast; |
| 1376 | __ Mov(next, current); |
| 1377 | |
| 1378 | __ Bind(&loop); |
| 1379 | // Terminate at native context. |
| 1380 | __ Ldr(temp, FieldMemOperand(next, HeapObject::kMapOffset)); |
| 1381 | __ JumpIfRoot(temp, Heap::kNativeContextMapRootIndex, &fast); |
| 1382 | // Check that extension is NULL. |
| 1383 | __ Ldr(temp, ContextMemOperand(next, Context::EXTENSION_INDEX)); |
| 1384 | __ Cbnz(temp, slow); |
| 1385 | // Load next context in chain. |
| 1386 | __ Ldr(next, ContextMemOperand(next, Context::PREVIOUS_INDEX)); |
| 1387 | __ B(&loop); |
| 1388 | __ Bind(&fast); |
| 1389 | } |
| 1390 | |
| 1391 | __ Ldr(LoadDescriptor::ReceiverRegister(), GlobalObjectMemOperand()); |
| 1392 | __ Mov(LoadDescriptor::NameRegister(), Operand(proxy->var()->name())); |
| 1393 | if (FLAG_vector_ics) { |
| 1394 | __ Mov(VectorLoadICDescriptor::SlotRegister(), |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 1395 | SmiFromSlot(proxy->VariableFeedbackSlot())); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1396 | } |
| 1397 | |
| 1398 | ContextualMode mode = (typeof_state == INSIDE_TYPEOF) ? NOT_CONTEXTUAL |
| 1399 | : CONTEXTUAL; |
| 1400 | CallLoadIC(mode); |
| 1401 | } |
| 1402 | |
| 1403 | |
| 1404 | MemOperand FullCodeGenerator::ContextSlotOperandCheckExtensions(Variable* var, |
| 1405 | Label* slow) { |
| 1406 | DCHECK(var->IsContextSlot()); |
| 1407 | Register context = cp; |
| 1408 | Register next = x10; |
| 1409 | Register temp = x11; |
| 1410 | |
| 1411 | for (Scope* s = scope(); s != var->scope(); s = s->outer_scope()) { |
| 1412 | if (s->num_heap_slots() > 0) { |
| 1413 | if (s->calls_sloppy_eval()) { |
| 1414 | // Check that extension is NULL. |
| 1415 | __ Ldr(temp, ContextMemOperand(context, Context::EXTENSION_INDEX)); |
| 1416 | __ Cbnz(temp, slow); |
| 1417 | } |
| 1418 | __ Ldr(next, ContextMemOperand(context, Context::PREVIOUS_INDEX)); |
| 1419 | // Walk the rest of the chain without clobbering cp. |
| 1420 | context = next; |
| 1421 | } |
| 1422 | } |
| 1423 | // Check that last extension is NULL. |
| 1424 | __ Ldr(temp, ContextMemOperand(context, Context::EXTENSION_INDEX)); |
| 1425 | __ Cbnz(temp, slow); |
| 1426 | |
| 1427 | // This function is used only for loads, not stores, so it's safe to |
| 1428 | // return an cp-based operand (the write barrier cannot be allowed to |
| 1429 | // destroy the cp register). |
| 1430 | return ContextMemOperand(context, var->index()); |
| 1431 | } |
| 1432 | |
| 1433 | |
| 1434 | void FullCodeGenerator::EmitDynamicLookupFastCase(VariableProxy* proxy, |
| 1435 | TypeofState typeof_state, |
| 1436 | Label* slow, |
| 1437 | Label* done) { |
| 1438 | // Generate fast-case code for variables that might be shadowed by |
| 1439 | // eval-introduced variables. Eval is used a lot without |
| 1440 | // introducing variables. In those cases, we do not want to |
| 1441 | // perform a runtime call for all variables in the scope |
| 1442 | // containing the eval. |
| 1443 | Variable* var = proxy->var(); |
| 1444 | if (var->mode() == DYNAMIC_GLOBAL) { |
| 1445 | EmitLoadGlobalCheckExtensions(proxy, typeof_state, slow); |
| 1446 | __ B(done); |
| 1447 | } else if (var->mode() == DYNAMIC_LOCAL) { |
| 1448 | Variable* local = var->local_if_not_shadowed(); |
| 1449 | __ Ldr(x0, ContextSlotOperandCheckExtensions(local, slow)); |
| 1450 | if (local->mode() == LET || local->mode() == CONST || |
| 1451 | local->mode() == CONST_LEGACY) { |
| 1452 | __ JumpIfNotRoot(x0, Heap::kTheHoleValueRootIndex, done); |
| 1453 | if (local->mode() == CONST_LEGACY) { |
| 1454 | __ LoadRoot(x0, Heap::kUndefinedValueRootIndex); |
| 1455 | } else { // LET || CONST |
| 1456 | __ Mov(x0, Operand(var->name())); |
| 1457 | __ Push(x0); |
| 1458 | __ CallRuntime(Runtime::kThrowReferenceError, 1); |
| 1459 | } |
| 1460 | } |
| 1461 | __ B(done); |
| 1462 | } |
| 1463 | } |
| 1464 | |
| 1465 | |
| 1466 | void FullCodeGenerator::EmitVariableLoad(VariableProxy* proxy) { |
| 1467 | // Record position before possible IC call. |
| 1468 | SetSourcePosition(proxy->position()); |
| 1469 | Variable* var = proxy->var(); |
| 1470 | |
| 1471 | // Three cases: global variables, lookup variables, and all other types of |
| 1472 | // variables. |
| 1473 | switch (var->location()) { |
| 1474 | case Variable::UNALLOCATED: { |
| 1475 | Comment cmnt(masm_, "Global variable"); |
| 1476 | __ Ldr(LoadDescriptor::ReceiverRegister(), GlobalObjectMemOperand()); |
| 1477 | __ Mov(LoadDescriptor::NameRegister(), Operand(var->name())); |
| 1478 | if (FLAG_vector_ics) { |
| 1479 | __ Mov(VectorLoadICDescriptor::SlotRegister(), |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 1480 | SmiFromSlot(proxy->VariableFeedbackSlot())); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1481 | } |
| 1482 | CallLoadIC(CONTEXTUAL); |
| 1483 | context()->Plug(x0); |
| 1484 | break; |
| 1485 | } |
| 1486 | |
| 1487 | case Variable::PARAMETER: |
| 1488 | case Variable::LOCAL: |
| 1489 | case Variable::CONTEXT: { |
| 1490 | Comment cmnt(masm_, var->IsContextSlot() |
| 1491 | ? "Context variable" |
| 1492 | : "Stack variable"); |
| 1493 | if (var->binding_needs_init()) { |
| 1494 | // var->scope() may be NULL when the proxy is located in eval code and |
| 1495 | // refers to a potential outside binding. Currently those bindings are |
| 1496 | // always looked up dynamically, i.e. in that case |
| 1497 | // var->location() == LOOKUP. |
| 1498 | // always holds. |
| 1499 | DCHECK(var->scope() != NULL); |
| 1500 | |
| 1501 | // Check if the binding really needs an initialization check. The check |
| 1502 | // can be skipped in the following situation: we have a LET or CONST |
| 1503 | // binding in harmony mode, both the Variable and the VariableProxy have |
| 1504 | // the same declaration scope (i.e. they are both in global code, in the |
| 1505 | // same function or in the same eval code) and the VariableProxy is in |
| 1506 | // the source physically located after the initializer of the variable. |
| 1507 | // |
| 1508 | // We cannot skip any initialization checks for CONST in non-harmony |
| 1509 | // mode because const variables may be declared but never initialized: |
| 1510 | // if (false) { const x; }; var y = x; |
| 1511 | // |
| 1512 | // The condition on the declaration scopes is a conservative check for |
| 1513 | // nested functions that access a binding and are called before the |
| 1514 | // binding is initialized: |
| 1515 | // function() { f(); let x = 1; function f() { x = 2; } } |
| 1516 | // |
| 1517 | bool skip_init_check; |
| 1518 | if (var->scope()->DeclarationScope() != scope()->DeclarationScope()) { |
| 1519 | skip_init_check = false; |
| 1520 | } else { |
| 1521 | // Check that we always have valid source position. |
| 1522 | DCHECK(var->initializer_position() != RelocInfo::kNoPosition); |
| 1523 | DCHECK(proxy->position() != RelocInfo::kNoPosition); |
| 1524 | skip_init_check = var->mode() != CONST_LEGACY && |
| 1525 | var->initializer_position() < proxy->position(); |
| 1526 | } |
| 1527 | |
| 1528 | if (!skip_init_check) { |
| 1529 | // Let and const need a read barrier. |
| 1530 | GetVar(x0, var); |
| 1531 | Label done; |
| 1532 | __ JumpIfNotRoot(x0, Heap::kTheHoleValueRootIndex, &done); |
| 1533 | if (var->mode() == LET || var->mode() == CONST) { |
| 1534 | // Throw a reference error when using an uninitialized let/const |
| 1535 | // binding in harmony mode. |
| 1536 | __ Mov(x0, Operand(var->name())); |
| 1537 | __ Push(x0); |
| 1538 | __ CallRuntime(Runtime::kThrowReferenceError, 1); |
| 1539 | __ Bind(&done); |
| 1540 | } else { |
| 1541 | // Uninitalized const bindings outside of harmony mode are unholed. |
| 1542 | DCHECK(var->mode() == CONST_LEGACY); |
| 1543 | __ LoadRoot(x0, Heap::kUndefinedValueRootIndex); |
| 1544 | __ Bind(&done); |
| 1545 | } |
| 1546 | context()->Plug(x0); |
| 1547 | break; |
| 1548 | } |
| 1549 | } |
| 1550 | context()->Plug(var); |
| 1551 | break; |
| 1552 | } |
| 1553 | |
| 1554 | case Variable::LOOKUP: { |
| 1555 | Label done, slow; |
| 1556 | // Generate code for loading from variables potentially shadowed by |
| 1557 | // eval-introduced variables. |
| 1558 | EmitDynamicLookupFastCase(proxy, NOT_INSIDE_TYPEOF, &slow, &done); |
| 1559 | __ Bind(&slow); |
| 1560 | Comment cmnt(masm_, "Lookup variable"); |
| 1561 | __ Mov(x1, Operand(var->name())); |
| 1562 | __ Push(cp, x1); // Context and name. |
| 1563 | __ CallRuntime(Runtime::kLoadLookupSlot, 2); |
| 1564 | __ Bind(&done); |
| 1565 | context()->Plug(x0); |
| 1566 | break; |
| 1567 | } |
| 1568 | } |
| 1569 | } |
| 1570 | |
| 1571 | |
| 1572 | void FullCodeGenerator::VisitRegExpLiteral(RegExpLiteral* expr) { |
| 1573 | Comment cmnt(masm_, "[ RegExpLiteral"); |
| 1574 | Label materialized; |
| 1575 | // Registers will be used as follows: |
| 1576 | // x5 = materialized value (RegExp literal) |
| 1577 | // x4 = JS function, literals array |
| 1578 | // x3 = literal index |
| 1579 | // x2 = RegExp pattern |
| 1580 | // x1 = RegExp flags |
| 1581 | // x0 = RegExp literal clone |
| 1582 | __ Ldr(x10, MemOperand(fp, JavaScriptFrameConstants::kFunctionOffset)); |
| 1583 | __ Ldr(x4, FieldMemOperand(x10, JSFunction::kLiteralsOffset)); |
| 1584 | int literal_offset = |
| 1585 | FixedArray::kHeaderSize + expr->literal_index() * kPointerSize; |
| 1586 | __ Ldr(x5, FieldMemOperand(x4, literal_offset)); |
| 1587 | __ JumpIfNotRoot(x5, Heap::kUndefinedValueRootIndex, &materialized); |
| 1588 | |
| 1589 | // Create regexp literal using runtime function. |
| 1590 | // Result will be in x0. |
| 1591 | __ Mov(x3, Smi::FromInt(expr->literal_index())); |
| 1592 | __ Mov(x2, Operand(expr->pattern())); |
| 1593 | __ Mov(x1, Operand(expr->flags())); |
| 1594 | __ Push(x4, x3, x2, x1); |
| 1595 | __ CallRuntime(Runtime::kMaterializeRegExpLiteral, 4); |
| 1596 | __ Mov(x5, x0); |
| 1597 | |
| 1598 | __ Bind(&materialized); |
| 1599 | int size = JSRegExp::kSize + JSRegExp::kInObjectFieldCount * kPointerSize; |
| 1600 | Label allocated, runtime_allocate; |
| 1601 | __ Allocate(size, x0, x2, x3, &runtime_allocate, TAG_OBJECT); |
| 1602 | __ B(&allocated); |
| 1603 | |
| 1604 | __ Bind(&runtime_allocate); |
| 1605 | __ Mov(x10, Smi::FromInt(size)); |
| 1606 | __ Push(x5, x10); |
| 1607 | __ CallRuntime(Runtime::kAllocateInNewSpace, 1); |
| 1608 | __ Pop(x5); |
| 1609 | |
| 1610 | __ Bind(&allocated); |
| 1611 | // After this, registers are used as follows: |
| 1612 | // x0: Newly allocated regexp. |
| 1613 | // x5: Materialized regexp. |
| 1614 | // x10, x11, x12: temps. |
| 1615 | __ CopyFields(x0, x5, CPURegList(x10, x11, x12), size / kPointerSize); |
| 1616 | context()->Plug(x0); |
| 1617 | } |
| 1618 | |
| 1619 | |
| 1620 | void FullCodeGenerator::EmitAccessor(Expression* expression) { |
| 1621 | if (expression == NULL) { |
| 1622 | __ LoadRoot(x10, Heap::kNullValueRootIndex); |
| 1623 | __ Push(x10); |
| 1624 | } else { |
| 1625 | VisitForStackValue(expression); |
| 1626 | } |
| 1627 | } |
| 1628 | |
| 1629 | |
| 1630 | void FullCodeGenerator::VisitObjectLiteral(ObjectLiteral* expr) { |
| 1631 | Comment cmnt(masm_, "[ ObjectLiteral"); |
| 1632 | |
| 1633 | expr->BuildConstantProperties(isolate()); |
| 1634 | Handle<FixedArray> constant_properties = expr->constant_properties(); |
| 1635 | __ Ldr(x3, MemOperand(fp, JavaScriptFrameConstants::kFunctionOffset)); |
| 1636 | __ Ldr(x3, FieldMemOperand(x3, JSFunction::kLiteralsOffset)); |
| 1637 | __ Mov(x2, Smi::FromInt(expr->literal_index())); |
| 1638 | __ Mov(x1, Operand(constant_properties)); |
| 1639 | int flags = expr->fast_elements() |
| 1640 | ? ObjectLiteral::kFastElements |
| 1641 | : ObjectLiteral::kNoFlags; |
| 1642 | flags |= expr->has_function() |
| 1643 | ? ObjectLiteral::kHasFunction |
| 1644 | : ObjectLiteral::kNoFlags; |
| 1645 | __ Mov(x0, Smi::FromInt(flags)); |
| 1646 | int properties_count = constant_properties->length() / 2; |
| 1647 | const int max_cloned_properties = |
| 1648 | FastCloneShallowObjectStub::kMaximumClonedProperties; |
| 1649 | if (expr->may_store_doubles() || expr->depth() > 1 || |
| 1650 | masm()->serializer_enabled() || flags != ObjectLiteral::kFastElements || |
| 1651 | properties_count > max_cloned_properties) { |
| 1652 | __ Push(x3, x2, x1, x0); |
| 1653 | __ CallRuntime(Runtime::kCreateObjectLiteral, 4); |
| 1654 | } else { |
| 1655 | FastCloneShallowObjectStub stub(isolate(), properties_count); |
| 1656 | __ CallStub(&stub); |
| 1657 | } |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 1658 | PrepareForBailoutForId(expr->CreateLiteralId(), TOS_REG); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1659 | |
| 1660 | // If result_saved is true the result is on top of the stack. If |
| 1661 | // result_saved is false the result is in x0. |
| 1662 | bool result_saved = false; |
| 1663 | |
| 1664 | // Mark all computed expressions that are bound to a key that |
| 1665 | // is shadowed by a later occurrence of the same key. For the |
| 1666 | // marked expressions, no store code is emitted. |
| 1667 | expr->CalculateEmitStore(zone()); |
| 1668 | |
| 1669 | AccessorTable accessor_table(zone()); |
| 1670 | for (int i = 0; i < expr->properties()->length(); i++) { |
| 1671 | ObjectLiteral::Property* property = expr->properties()->at(i); |
| 1672 | if (property->IsCompileTimeValue()) continue; |
| 1673 | |
| 1674 | Literal* key = property->key(); |
| 1675 | Expression* value = property->value(); |
| 1676 | if (!result_saved) { |
| 1677 | __ Push(x0); // Save result on stack |
| 1678 | result_saved = true; |
| 1679 | } |
| 1680 | switch (property->kind()) { |
| 1681 | case ObjectLiteral::Property::CONSTANT: |
| 1682 | UNREACHABLE(); |
| 1683 | case ObjectLiteral::Property::MATERIALIZED_LITERAL: |
| 1684 | DCHECK(!CompileTimeValue::IsCompileTimeValue(property->value())); |
| 1685 | // Fall through. |
| 1686 | case ObjectLiteral::Property::COMPUTED: |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 1687 | // It is safe to use [[Put]] here because the boilerplate already |
| 1688 | // contains computed properties with an uninitialized value. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1689 | if (key->value()->IsInternalizedString()) { |
| 1690 | if (property->emit_store()) { |
| 1691 | VisitForAccumulatorValue(value); |
| 1692 | DCHECK(StoreDescriptor::ValueRegister().is(x0)); |
| 1693 | __ Mov(StoreDescriptor::NameRegister(), Operand(key->value())); |
| 1694 | __ Peek(StoreDescriptor::ReceiverRegister(), 0); |
| 1695 | CallStoreIC(key->LiteralFeedbackId()); |
| 1696 | PrepareForBailoutForId(key->id(), NO_REGISTERS); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 1697 | |
| 1698 | if (NeedsHomeObject(value)) { |
| 1699 | __ Mov(StoreDescriptor::ReceiverRegister(), x0); |
| 1700 | __ Mov(StoreDescriptor::NameRegister(), |
| 1701 | Operand(isolate()->factory()->home_object_symbol())); |
| 1702 | __ Peek(StoreDescriptor::ValueRegister(), 0); |
| 1703 | CallStoreIC(); |
| 1704 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1705 | } else { |
| 1706 | VisitForEffect(value); |
| 1707 | } |
| 1708 | break; |
| 1709 | } |
| 1710 | if (property->emit_store()) { |
| 1711 | // Duplicate receiver on stack. |
| 1712 | __ Peek(x0, 0); |
| 1713 | __ Push(x0); |
| 1714 | VisitForStackValue(key); |
| 1715 | VisitForStackValue(value); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 1716 | EmitSetHomeObjectIfNeeded(value, 2); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1717 | __ Mov(x0, Smi::FromInt(SLOPPY)); // Strict mode |
| 1718 | __ Push(x0); |
| 1719 | __ CallRuntime(Runtime::kSetProperty, 4); |
| 1720 | } else { |
| 1721 | VisitForEffect(key); |
| 1722 | VisitForEffect(value); |
| 1723 | } |
| 1724 | break; |
| 1725 | case ObjectLiteral::Property::PROTOTYPE: |
| 1726 | if (property->emit_store()) { |
| 1727 | // Duplicate receiver on stack. |
| 1728 | __ Peek(x0, 0); |
| 1729 | __ Push(x0); |
| 1730 | VisitForStackValue(value); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 1731 | __ CallRuntime(Runtime::kInternalSetPrototype, 2); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1732 | } else { |
| 1733 | VisitForEffect(value); |
| 1734 | } |
| 1735 | break; |
| 1736 | case ObjectLiteral::Property::GETTER: |
| 1737 | accessor_table.lookup(key)->second->getter = value; |
| 1738 | break; |
| 1739 | case ObjectLiteral::Property::SETTER: |
| 1740 | accessor_table.lookup(key)->second->setter = value; |
| 1741 | break; |
| 1742 | } |
| 1743 | } |
| 1744 | |
| 1745 | // Emit code to define accessors, using only a single call to the runtime for |
| 1746 | // each pair of corresponding getters and setters. |
| 1747 | for (AccessorTable::Iterator it = accessor_table.begin(); |
| 1748 | it != accessor_table.end(); |
| 1749 | ++it) { |
| 1750 | __ Peek(x10, 0); // Duplicate receiver. |
| 1751 | __ Push(x10); |
| 1752 | VisitForStackValue(it->first); |
| 1753 | EmitAccessor(it->second->getter); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 1754 | EmitSetHomeObjectIfNeeded(it->second->getter, 2); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1755 | EmitAccessor(it->second->setter); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 1756 | EmitSetHomeObjectIfNeeded(it->second->setter, 3); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1757 | __ Mov(x10, Smi::FromInt(NONE)); |
| 1758 | __ Push(x10); |
| 1759 | __ CallRuntime(Runtime::kDefineAccessorPropertyUnchecked, 5); |
| 1760 | } |
| 1761 | |
| 1762 | if (expr->has_function()) { |
| 1763 | DCHECK(result_saved); |
| 1764 | __ Peek(x0, 0); |
| 1765 | __ Push(x0); |
| 1766 | __ CallRuntime(Runtime::kToFastProperties, 1); |
| 1767 | } |
| 1768 | |
| 1769 | if (result_saved) { |
| 1770 | context()->PlugTOS(); |
| 1771 | } else { |
| 1772 | context()->Plug(x0); |
| 1773 | } |
| 1774 | } |
| 1775 | |
| 1776 | |
| 1777 | void FullCodeGenerator::VisitArrayLiteral(ArrayLiteral* expr) { |
| 1778 | Comment cmnt(masm_, "[ ArrayLiteral"); |
| 1779 | |
| 1780 | expr->BuildConstantElements(isolate()); |
| 1781 | int flags = (expr->depth() == 1) ? ArrayLiteral::kShallowElements |
| 1782 | : ArrayLiteral::kNoFlags; |
| 1783 | |
| 1784 | ZoneList<Expression*>* subexprs = expr->values(); |
| 1785 | int length = subexprs->length(); |
| 1786 | Handle<FixedArray> constant_elements = expr->constant_elements(); |
| 1787 | DCHECK_EQ(2, constant_elements->length()); |
| 1788 | ElementsKind constant_elements_kind = |
| 1789 | static_cast<ElementsKind>(Smi::cast(constant_elements->get(0))->value()); |
| 1790 | bool has_fast_elements = IsFastObjectElementsKind(constant_elements_kind); |
| 1791 | Handle<FixedArrayBase> constant_elements_values( |
| 1792 | FixedArrayBase::cast(constant_elements->get(1))); |
| 1793 | |
| 1794 | AllocationSiteMode allocation_site_mode = TRACK_ALLOCATION_SITE; |
| 1795 | if (has_fast_elements && !FLAG_allocation_site_pretenuring) { |
| 1796 | // If the only customer of allocation sites is transitioning, then |
| 1797 | // we can turn it off if we don't have anywhere else to transition to. |
| 1798 | allocation_site_mode = DONT_TRACK_ALLOCATION_SITE; |
| 1799 | } |
| 1800 | |
| 1801 | __ Ldr(x3, MemOperand(fp, JavaScriptFrameConstants::kFunctionOffset)); |
| 1802 | __ Ldr(x3, FieldMemOperand(x3, JSFunction::kLiteralsOffset)); |
| 1803 | __ Mov(x2, Smi::FromInt(expr->literal_index())); |
| 1804 | __ Mov(x1, Operand(constant_elements)); |
| 1805 | if (expr->depth() > 1 || length > JSObject::kInitialMaxFastElementArray) { |
| 1806 | __ Mov(x0, Smi::FromInt(flags)); |
| 1807 | __ Push(x3, x2, x1, x0); |
| 1808 | __ CallRuntime(Runtime::kCreateArrayLiteral, 4); |
| 1809 | } else { |
| 1810 | FastCloneShallowArrayStub stub(isolate(), allocation_site_mode); |
| 1811 | __ CallStub(&stub); |
| 1812 | } |
| 1813 | |
| 1814 | bool result_saved = false; // Is the result saved to the stack? |
| 1815 | |
| 1816 | // Emit code to evaluate all the non-constant subexpressions and to store |
| 1817 | // them into the newly cloned array. |
| 1818 | for (int i = 0; i < length; i++) { |
| 1819 | Expression* subexpr = subexprs->at(i); |
| 1820 | // If the subexpression is a literal or a simple materialized literal it |
| 1821 | // is already set in the cloned array. |
| 1822 | if (CompileTimeValue::IsCompileTimeValue(subexpr)) continue; |
| 1823 | |
| 1824 | if (!result_saved) { |
| 1825 | __ Mov(x1, Smi::FromInt(expr->literal_index())); |
| 1826 | __ Push(x0, x1); |
| 1827 | result_saved = true; |
| 1828 | } |
| 1829 | VisitForAccumulatorValue(subexpr); |
| 1830 | |
| 1831 | if (IsFastObjectElementsKind(constant_elements_kind)) { |
| 1832 | int offset = FixedArray::kHeaderSize + (i * kPointerSize); |
| 1833 | __ Peek(x6, kPointerSize); // Copy of array literal. |
| 1834 | __ Ldr(x1, FieldMemOperand(x6, JSObject::kElementsOffset)); |
| 1835 | __ Str(result_register(), FieldMemOperand(x1, offset)); |
| 1836 | // Update the write barrier for the array store. |
| 1837 | __ RecordWriteField(x1, offset, result_register(), x10, |
| 1838 | kLRHasBeenSaved, kDontSaveFPRegs, |
| 1839 | EMIT_REMEMBERED_SET, INLINE_SMI_CHECK); |
| 1840 | } else { |
| 1841 | __ Mov(x3, Smi::FromInt(i)); |
| 1842 | StoreArrayLiteralElementStub stub(isolate()); |
| 1843 | __ CallStub(&stub); |
| 1844 | } |
| 1845 | |
| 1846 | PrepareForBailoutForId(expr->GetIdForElement(i), NO_REGISTERS); |
| 1847 | } |
| 1848 | |
| 1849 | if (result_saved) { |
| 1850 | __ Drop(1); // literal index |
| 1851 | context()->PlugTOS(); |
| 1852 | } else { |
| 1853 | context()->Plug(x0); |
| 1854 | } |
| 1855 | } |
| 1856 | |
| 1857 | |
| 1858 | void FullCodeGenerator::VisitAssignment(Assignment* expr) { |
| 1859 | DCHECK(expr->target()->IsValidReferenceExpression()); |
| 1860 | |
| 1861 | Comment cmnt(masm_, "[ Assignment"); |
| 1862 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1863 | Property* property = expr->target()->AsProperty(); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 1864 | LhsKind assign_type = GetAssignType(property); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1865 | |
| 1866 | // Evaluate LHS expression. |
| 1867 | switch (assign_type) { |
| 1868 | case VARIABLE: |
| 1869 | // Nothing to do here. |
| 1870 | break; |
| 1871 | case NAMED_PROPERTY: |
| 1872 | if (expr->is_compound()) { |
| 1873 | // We need the receiver both on the stack and in the register. |
| 1874 | VisitForStackValue(property->obj()); |
| 1875 | __ Peek(LoadDescriptor::ReceiverRegister(), 0); |
| 1876 | } else { |
| 1877 | VisitForStackValue(property->obj()); |
| 1878 | } |
| 1879 | break; |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 1880 | case NAMED_SUPER_PROPERTY: |
| 1881 | VisitForStackValue(property->obj()->AsSuperReference()->this_var()); |
| 1882 | EmitLoadHomeObject(property->obj()->AsSuperReference()); |
| 1883 | __ Push(result_register()); |
| 1884 | if (expr->is_compound()) { |
| 1885 | const Register scratch = x10; |
| 1886 | __ Peek(scratch, kPointerSize); |
| 1887 | __ Push(scratch, result_register()); |
| 1888 | } |
| 1889 | break; |
| 1890 | case KEYED_SUPER_PROPERTY: |
| 1891 | VisitForStackValue(property->obj()->AsSuperReference()->this_var()); |
| 1892 | EmitLoadHomeObject(property->obj()->AsSuperReference()); |
| 1893 | __ Push(result_register()); |
| 1894 | VisitForAccumulatorValue(property->key()); |
| 1895 | __ Push(result_register()); |
| 1896 | if (expr->is_compound()) { |
| 1897 | const Register scratch1 = x10; |
| 1898 | const Register scratch2 = x11; |
| 1899 | __ Peek(scratch1, 2 * kPointerSize); |
| 1900 | __ Peek(scratch2, kPointerSize); |
| 1901 | __ Push(scratch1, scratch2, result_register()); |
| 1902 | } |
| 1903 | break; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1904 | case KEYED_PROPERTY: |
| 1905 | if (expr->is_compound()) { |
| 1906 | VisitForStackValue(property->obj()); |
| 1907 | VisitForStackValue(property->key()); |
| 1908 | __ Peek(LoadDescriptor::ReceiverRegister(), 1 * kPointerSize); |
| 1909 | __ Peek(LoadDescriptor::NameRegister(), 0); |
| 1910 | } else { |
| 1911 | VisitForStackValue(property->obj()); |
| 1912 | VisitForStackValue(property->key()); |
| 1913 | } |
| 1914 | break; |
| 1915 | } |
| 1916 | |
| 1917 | // For compound assignments we need another deoptimization point after the |
| 1918 | // variable/property load. |
| 1919 | if (expr->is_compound()) { |
| 1920 | { AccumulatorValueContext context(this); |
| 1921 | switch (assign_type) { |
| 1922 | case VARIABLE: |
| 1923 | EmitVariableLoad(expr->target()->AsVariableProxy()); |
| 1924 | PrepareForBailout(expr->target(), TOS_REG); |
| 1925 | break; |
| 1926 | case NAMED_PROPERTY: |
| 1927 | EmitNamedPropertyLoad(property); |
| 1928 | PrepareForBailoutForId(property->LoadId(), TOS_REG); |
| 1929 | break; |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 1930 | case NAMED_SUPER_PROPERTY: |
| 1931 | EmitNamedSuperPropertyLoad(property); |
| 1932 | PrepareForBailoutForId(property->LoadId(), TOS_REG); |
| 1933 | break; |
| 1934 | case KEYED_SUPER_PROPERTY: |
| 1935 | EmitKeyedSuperPropertyLoad(property); |
| 1936 | PrepareForBailoutForId(property->LoadId(), TOS_REG); |
| 1937 | break; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1938 | case KEYED_PROPERTY: |
| 1939 | EmitKeyedPropertyLoad(property); |
| 1940 | PrepareForBailoutForId(property->LoadId(), TOS_REG); |
| 1941 | break; |
| 1942 | } |
| 1943 | } |
| 1944 | |
| 1945 | Token::Value op = expr->binary_op(); |
| 1946 | __ Push(x0); // Left operand goes on the stack. |
| 1947 | VisitForAccumulatorValue(expr->value()); |
| 1948 | |
| 1949 | OverwriteMode mode = expr->value()->ResultOverwriteAllowed() |
| 1950 | ? OVERWRITE_RIGHT |
| 1951 | : NO_OVERWRITE; |
| 1952 | SetSourcePosition(expr->position() + 1); |
| 1953 | AccumulatorValueContext context(this); |
| 1954 | if (ShouldInlineSmiCase(op)) { |
| 1955 | EmitInlineSmiBinaryOp(expr->binary_operation(), |
| 1956 | op, |
| 1957 | mode, |
| 1958 | expr->target(), |
| 1959 | expr->value()); |
| 1960 | } else { |
| 1961 | EmitBinaryOp(expr->binary_operation(), op, mode); |
| 1962 | } |
| 1963 | |
| 1964 | // Deoptimization point in case the binary operation may have side effects. |
| 1965 | PrepareForBailout(expr->binary_operation(), TOS_REG); |
| 1966 | } else { |
| 1967 | VisitForAccumulatorValue(expr->value()); |
| 1968 | } |
| 1969 | |
| 1970 | // Record source position before possible IC call. |
| 1971 | SetSourcePosition(expr->position()); |
| 1972 | |
| 1973 | // Store the value. |
| 1974 | switch (assign_type) { |
| 1975 | case VARIABLE: |
| 1976 | EmitVariableAssignment(expr->target()->AsVariableProxy()->var(), |
| 1977 | expr->op()); |
| 1978 | PrepareForBailoutForId(expr->AssignmentId(), TOS_REG); |
| 1979 | context()->Plug(x0); |
| 1980 | break; |
| 1981 | case NAMED_PROPERTY: |
| 1982 | EmitNamedPropertyAssignment(expr); |
| 1983 | break; |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 1984 | case NAMED_SUPER_PROPERTY: |
| 1985 | EmitNamedSuperPropertyStore(property); |
| 1986 | context()->Plug(x0); |
| 1987 | break; |
| 1988 | case KEYED_SUPER_PROPERTY: |
| 1989 | EmitKeyedSuperPropertyStore(property); |
| 1990 | context()->Plug(x0); |
| 1991 | break; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1992 | case KEYED_PROPERTY: |
| 1993 | EmitKeyedPropertyAssignment(expr); |
| 1994 | break; |
| 1995 | } |
| 1996 | } |
| 1997 | |
| 1998 | |
| 1999 | void FullCodeGenerator::EmitNamedPropertyLoad(Property* prop) { |
| 2000 | SetSourcePosition(prop->position()); |
| 2001 | Literal* key = prop->key()->AsLiteral(); |
| 2002 | DCHECK(!prop->IsSuperAccess()); |
| 2003 | |
| 2004 | __ Mov(LoadDescriptor::NameRegister(), Operand(key->value())); |
| 2005 | if (FLAG_vector_ics) { |
| 2006 | __ Mov(VectorLoadICDescriptor::SlotRegister(), |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 2007 | SmiFromSlot(prop->PropertyFeedbackSlot())); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2008 | CallLoadIC(NOT_CONTEXTUAL); |
| 2009 | } else { |
| 2010 | CallLoadIC(NOT_CONTEXTUAL, prop->PropertyFeedbackId()); |
| 2011 | } |
| 2012 | } |
| 2013 | |
| 2014 | |
| 2015 | void FullCodeGenerator::EmitNamedSuperPropertyLoad(Property* prop) { |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 2016 | // Stack: receiver, home_object. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2017 | SetSourcePosition(prop->position()); |
| 2018 | Literal* key = prop->key()->AsLiteral(); |
| 2019 | DCHECK(!key->value()->IsSmi()); |
| 2020 | DCHECK(prop->IsSuperAccess()); |
| 2021 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2022 | __ Push(key->value()); |
| 2023 | __ CallRuntime(Runtime::kLoadFromSuper, 3); |
| 2024 | } |
| 2025 | |
| 2026 | |
| 2027 | void FullCodeGenerator::EmitKeyedPropertyLoad(Property* prop) { |
| 2028 | SetSourcePosition(prop->position()); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 2029 | // Call keyed load IC. It has arguments key and receiver in x0 and x1. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2030 | Handle<Code> ic = CodeFactory::KeyedLoadIC(isolate()).code(); |
| 2031 | if (FLAG_vector_ics) { |
| 2032 | __ Mov(VectorLoadICDescriptor::SlotRegister(), |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 2033 | SmiFromSlot(prop->PropertyFeedbackSlot())); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2034 | CallIC(ic); |
| 2035 | } else { |
| 2036 | CallIC(ic, prop->PropertyFeedbackId()); |
| 2037 | } |
| 2038 | } |
| 2039 | |
| 2040 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 2041 | void FullCodeGenerator::EmitKeyedSuperPropertyLoad(Property* prop) { |
| 2042 | // Stack: receiver, home_object, key. |
| 2043 | SetSourcePosition(prop->position()); |
| 2044 | |
| 2045 | __ CallRuntime(Runtime::kLoadKeyedFromSuper, 3); |
| 2046 | } |
| 2047 | |
| 2048 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2049 | void FullCodeGenerator::EmitInlineSmiBinaryOp(BinaryOperation* expr, |
| 2050 | Token::Value op, |
| 2051 | OverwriteMode mode, |
| 2052 | Expression* left_expr, |
| 2053 | Expression* right_expr) { |
| 2054 | Label done, both_smis, stub_call; |
| 2055 | |
| 2056 | // Get the arguments. |
| 2057 | Register left = x1; |
| 2058 | Register right = x0; |
| 2059 | Register result = x0; |
| 2060 | __ Pop(left); |
| 2061 | |
| 2062 | // Perform combined smi check on both operands. |
| 2063 | __ Orr(x10, left, right); |
| 2064 | JumpPatchSite patch_site(masm_); |
| 2065 | patch_site.EmitJumpIfSmi(x10, &both_smis); |
| 2066 | |
| 2067 | __ Bind(&stub_call); |
| 2068 | |
| 2069 | Handle<Code> code = CodeFactory::BinaryOpIC(isolate(), op, mode).code(); |
| 2070 | { |
| 2071 | Assembler::BlockPoolsScope scope(masm_); |
| 2072 | CallIC(code, expr->BinaryOperationFeedbackId()); |
| 2073 | patch_site.EmitPatchInfo(); |
| 2074 | } |
| 2075 | __ B(&done); |
| 2076 | |
| 2077 | __ Bind(&both_smis); |
| 2078 | // Smi case. This code works in the same way as the smi-smi case in the type |
| 2079 | // recording binary operation stub, see |
| 2080 | // BinaryOpStub::GenerateSmiSmiOperation for comments. |
| 2081 | // TODO(all): That doesn't exist any more. Where are the comments? |
| 2082 | // |
| 2083 | // The set of operations that needs to be supported here is controlled by |
| 2084 | // FullCodeGenerator::ShouldInlineSmiCase(). |
| 2085 | switch (op) { |
| 2086 | case Token::SAR: |
| 2087 | __ Ubfx(right, right, kSmiShift, 5); |
| 2088 | __ Asr(result, left, right); |
| 2089 | __ Bic(result, result, kSmiShiftMask); |
| 2090 | break; |
| 2091 | case Token::SHL: |
| 2092 | __ Ubfx(right, right, kSmiShift, 5); |
| 2093 | __ Lsl(result, left, right); |
| 2094 | break; |
| 2095 | case Token::SHR: |
| 2096 | // If `left >>> right` >= 0x80000000, the result is not representable in a |
| 2097 | // signed 32-bit smi. |
| 2098 | __ Ubfx(right, right, kSmiShift, 5); |
| 2099 | __ Lsr(x10, left, right); |
| 2100 | __ Tbnz(x10, kXSignBit, &stub_call); |
| 2101 | __ Bic(result, x10, kSmiShiftMask); |
| 2102 | break; |
| 2103 | case Token::ADD: |
| 2104 | __ Adds(x10, left, right); |
| 2105 | __ B(vs, &stub_call); |
| 2106 | __ Mov(result, x10); |
| 2107 | break; |
| 2108 | case Token::SUB: |
| 2109 | __ Subs(x10, left, right); |
| 2110 | __ B(vs, &stub_call); |
| 2111 | __ Mov(result, x10); |
| 2112 | break; |
| 2113 | case Token::MUL: { |
| 2114 | Label not_minus_zero, done; |
| 2115 | STATIC_ASSERT(static_cast<unsigned>(kSmiShift) == (kXRegSizeInBits / 2)); |
| 2116 | STATIC_ASSERT(kSmiTag == 0); |
| 2117 | __ Smulh(x10, left, right); |
| 2118 | __ Cbnz(x10, ¬_minus_zero); |
| 2119 | __ Eor(x11, left, right); |
| 2120 | __ Tbnz(x11, kXSignBit, &stub_call); |
| 2121 | __ Mov(result, x10); |
| 2122 | __ B(&done); |
| 2123 | __ Bind(¬_minus_zero); |
| 2124 | __ Cls(x11, x10); |
| 2125 | __ Cmp(x11, kXRegSizeInBits - kSmiShift); |
| 2126 | __ B(lt, &stub_call); |
| 2127 | __ SmiTag(result, x10); |
| 2128 | __ Bind(&done); |
| 2129 | break; |
| 2130 | } |
| 2131 | case Token::BIT_OR: |
| 2132 | __ Orr(result, left, right); |
| 2133 | break; |
| 2134 | case Token::BIT_AND: |
| 2135 | __ And(result, left, right); |
| 2136 | break; |
| 2137 | case Token::BIT_XOR: |
| 2138 | __ Eor(result, left, right); |
| 2139 | break; |
| 2140 | default: |
| 2141 | UNREACHABLE(); |
| 2142 | } |
| 2143 | |
| 2144 | __ Bind(&done); |
| 2145 | context()->Plug(x0); |
| 2146 | } |
| 2147 | |
| 2148 | |
| 2149 | void FullCodeGenerator::EmitBinaryOp(BinaryOperation* expr, |
| 2150 | Token::Value op, |
| 2151 | OverwriteMode mode) { |
| 2152 | __ Pop(x1); |
| 2153 | Handle<Code> code = CodeFactory::BinaryOpIC(isolate(), op, mode).code(); |
| 2154 | JumpPatchSite patch_site(masm_); // Unbound, signals no inlined smi code. |
| 2155 | { |
| 2156 | Assembler::BlockPoolsScope scope(masm_); |
| 2157 | CallIC(code, expr->BinaryOperationFeedbackId()); |
| 2158 | patch_site.EmitPatchInfo(); |
| 2159 | } |
| 2160 | context()->Plug(x0); |
| 2161 | } |
| 2162 | |
| 2163 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 2164 | void FullCodeGenerator::EmitClassDefineProperties(ClassLiteral* lit) { |
| 2165 | // Constructor is in x0. |
| 2166 | DCHECK(lit != NULL); |
| 2167 | __ push(x0); |
| 2168 | |
| 2169 | // No access check is needed here since the constructor is created by the |
| 2170 | // class literal. |
| 2171 | Register scratch = x1; |
| 2172 | __ Ldr(scratch, |
| 2173 | FieldMemOperand(x0, JSFunction::kPrototypeOrInitialMapOffset)); |
| 2174 | __ Push(scratch); |
| 2175 | |
| 2176 | for (int i = 0; i < lit->properties()->length(); i++) { |
| 2177 | ObjectLiteral::Property* property = lit->properties()->at(i); |
| 2178 | Literal* key = property->key()->AsLiteral(); |
| 2179 | Expression* value = property->value(); |
| 2180 | DCHECK(key != NULL); |
| 2181 | |
| 2182 | if (property->is_static()) { |
| 2183 | __ Peek(scratch, kPointerSize); // constructor |
| 2184 | } else { |
| 2185 | __ Peek(scratch, 0); // prototype |
| 2186 | } |
| 2187 | __ Push(scratch); |
| 2188 | VisitForStackValue(key); |
| 2189 | VisitForStackValue(value); |
| 2190 | EmitSetHomeObjectIfNeeded(value, 2); |
| 2191 | |
| 2192 | switch (property->kind()) { |
| 2193 | case ObjectLiteral::Property::CONSTANT: |
| 2194 | case ObjectLiteral::Property::MATERIALIZED_LITERAL: |
| 2195 | case ObjectLiteral::Property::COMPUTED: |
| 2196 | case ObjectLiteral::Property::PROTOTYPE: |
| 2197 | __ CallRuntime(Runtime::kDefineClassMethod, 3); |
| 2198 | break; |
| 2199 | |
| 2200 | case ObjectLiteral::Property::GETTER: |
| 2201 | __ CallRuntime(Runtime::kDefineClassGetter, 3); |
| 2202 | break; |
| 2203 | |
| 2204 | case ObjectLiteral::Property::SETTER: |
| 2205 | __ CallRuntime(Runtime::kDefineClassSetter, 3); |
| 2206 | break; |
| 2207 | |
| 2208 | default: |
| 2209 | UNREACHABLE(); |
| 2210 | } |
| 2211 | } |
| 2212 | |
| 2213 | // prototype |
| 2214 | __ CallRuntime(Runtime::kToFastProperties, 1); |
| 2215 | |
| 2216 | // constructor |
| 2217 | __ CallRuntime(Runtime::kToFastProperties, 1); |
| 2218 | } |
| 2219 | |
| 2220 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2221 | void FullCodeGenerator::EmitAssignment(Expression* expr) { |
| 2222 | DCHECK(expr->IsValidReferenceExpression()); |
| 2223 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2224 | Property* prop = expr->AsProperty(); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 2225 | LhsKind assign_type = GetAssignType(prop); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2226 | |
| 2227 | switch (assign_type) { |
| 2228 | case VARIABLE: { |
| 2229 | Variable* var = expr->AsVariableProxy()->var(); |
| 2230 | EffectContext context(this); |
| 2231 | EmitVariableAssignment(var, Token::ASSIGN); |
| 2232 | break; |
| 2233 | } |
| 2234 | case NAMED_PROPERTY: { |
| 2235 | __ Push(x0); // Preserve value. |
| 2236 | VisitForAccumulatorValue(prop->obj()); |
| 2237 | // TODO(all): We could introduce a VisitForRegValue(reg, expr) to avoid |
| 2238 | // this copy. |
| 2239 | __ Mov(StoreDescriptor::ReceiverRegister(), x0); |
| 2240 | __ Pop(StoreDescriptor::ValueRegister()); // Restore value. |
| 2241 | __ Mov(StoreDescriptor::NameRegister(), |
| 2242 | Operand(prop->key()->AsLiteral()->value())); |
| 2243 | CallStoreIC(); |
| 2244 | break; |
| 2245 | } |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 2246 | case NAMED_SUPER_PROPERTY: { |
| 2247 | __ Push(x0); |
| 2248 | VisitForStackValue(prop->obj()->AsSuperReference()->this_var()); |
| 2249 | EmitLoadHomeObject(prop->obj()->AsSuperReference()); |
| 2250 | // stack: value, this; x0: home_object |
| 2251 | Register scratch = x10; |
| 2252 | Register scratch2 = x11; |
| 2253 | __ mov(scratch, result_register()); // home_object |
| 2254 | __ Peek(x0, kPointerSize); // value |
| 2255 | __ Peek(scratch2, 0); // this |
| 2256 | __ Poke(scratch2, kPointerSize); // this |
| 2257 | __ Poke(scratch, 0); // home_object |
| 2258 | // stack: this, home_object; x0: value |
| 2259 | EmitNamedSuperPropertyStore(prop); |
| 2260 | break; |
| 2261 | } |
| 2262 | case KEYED_SUPER_PROPERTY: { |
| 2263 | __ Push(x0); |
| 2264 | VisitForStackValue(prop->obj()->AsSuperReference()->this_var()); |
| 2265 | EmitLoadHomeObject(prop->obj()->AsSuperReference()); |
| 2266 | __ Push(result_register()); |
| 2267 | VisitForAccumulatorValue(prop->key()); |
| 2268 | Register scratch = x10; |
| 2269 | Register scratch2 = x11; |
| 2270 | __ Peek(scratch2, 2 * kPointerSize); // value |
| 2271 | // stack: value, this, home_object; x0: key, x11: value |
| 2272 | __ Peek(scratch, kPointerSize); // this |
| 2273 | __ Poke(scratch, 2 * kPointerSize); |
| 2274 | __ Peek(scratch, 0); // home_object |
| 2275 | __ Poke(scratch, kPointerSize); |
| 2276 | __ Poke(x0, 0); |
| 2277 | __ Move(x0, scratch2); |
| 2278 | // stack: this, home_object, key; x0: value. |
| 2279 | EmitKeyedSuperPropertyStore(prop); |
| 2280 | break; |
| 2281 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2282 | case KEYED_PROPERTY: { |
| 2283 | __ Push(x0); // Preserve value. |
| 2284 | VisitForStackValue(prop->obj()); |
| 2285 | VisitForAccumulatorValue(prop->key()); |
| 2286 | __ Mov(StoreDescriptor::NameRegister(), x0); |
| 2287 | __ Pop(StoreDescriptor::ReceiverRegister(), |
| 2288 | StoreDescriptor::ValueRegister()); |
| 2289 | Handle<Code> ic = |
| 2290 | CodeFactory::KeyedStoreIC(isolate(), strict_mode()).code(); |
| 2291 | CallIC(ic); |
| 2292 | break; |
| 2293 | } |
| 2294 | } |
| 2295 | context()->Plug(x0); |
| 2296 | } |
| 2297 | |
| 2298 | |
| 2299 | void FullCodeGenerator::EmitStoreToStackLocalOrContextSlot( |
| 2300 | Variable* var, MemOperand location) { |
| 2301 | __ Str(result_register(), location); |
| 2302 | if (var->IsContextSlot()) { |
| 2303 | // RecordWrite may destroy all its register arguments. |
| 2304 | __ Mov(x10, result_register()); |
| 2305 | int offset = Context::SlotOffset(var->index()); |
| 2306 | __ RecordWriteContextSlot( |
| 2307 | x1, offset, x10, x11, kLRHasBeenSaved, kDontSaveFPRegs); |
| 2308 | } |
| 2309 | } |
| 2310 | |
| 2311 | |
| 2312 | void FullCodeGenerator::EmitVariableAssignment(Variable* var, |
| 2313 | Token::Value op) { |
| 2314 | ASM_LOCATION("FullCodeGenerator::EmitVariableAssignment"); |
| 2315 | if (var->IsUnallocated()) { |
| 2316 | // Global var, const, or let. |
| 2317 | __ Mov(StoreDescriptor::NameRegister(), Operand(var->name())); |
| 2318 | __ Ldr(StoreDescriptor::ReceiverRegister(), GlobalObjectMemOperand()); |
| 2319 | CallStoreIC(); |
| 2320 | |
| 2321 | } else if (op == Token::INIT_CONST_LEGACY) { |
| 2322 | // Const initializers need a write barrier. |
| 2323 | DCHECK(!var->IsParameter()); // No const parameters. |
| 2324 | if (var->IsLookupSlot()) { |
| 2325 | __ Mov(x1, Operand(var->name())); |
| 2326 | __ Push(x0, cp, x1); |
| 2327 | __ CallRuntime(Runtime::kInitializeLegacyConstLookupSlot, 3); |
| 2328 | } else { |
| 2329 | DCHECK(var->IsStackLocal() || var->IsContextSlot()); |
| 2330 | Label skip; |
| 2331 | MemOperand location = VarOperand(var, x1); |
| 2332 | __ Ldr(x10, location); |
| 2333 | __ JumpIfNotRoot(x10, Heap::kTheHoleValueRootIndex, &skip); |
| 2334 | EmitStoreToStackLocalOrContextSlot(var, location); |
| 2335 | __ Bind(&skip); |
| 2336 | } |
| 2337 | |
| 2338 | } else if (var->mode() == LET && op != Token::INIT_LET) { |
| 2339 | // Non-initializing assignment to let variable needs a write barrier. |
| 2340 | DCHECK(!var->IsLookupSlot()); |
| 2341 | DCHECK(var->IsStackAllocated() || var->IsContextSlot()); |
| 2342 | Label assign; |
| 2343 | MemOperand location = VarOperand(var, x1); |
| 2344 | __ Ldr(x10, location); |
| 2345 | __ JumpIfNotRoot(x10, Heap::kTheHoleValueRootIndex, &assign); |
| 2346 | __ Mov(x10, Operand(var->name())); |
| 2347 | __ Push(x10); |
| 2348 | __ CallRuntime(Runtime::kThrowReferenceError, 1); |
| 2349 | // Perform the assignment. |
| 2350 | __ Bind(&assign); |
| 2351 | EmitStoreToStackLocalOrContextSlot(var, location); |
| 2352 | |
| 2353 | } else if (!var->is_const_mode() || op == Token::INIT_CONST) { |
| 2354 | if (var->IsLookupSlot()) { |
| 2355 | // Assignment to var. |
| 2356 | __ Mov(x11, Operand(var->name())); |
| 2357 | __ Mov(x10, Smi::FromInt(strict_mode())); |
| 2358 | // jssp[0] : mode. |
| 2359 | // jssp[8] : name. |
| 2360 | // jssp[16] : context. |
| 2361 | // jssp[24] : value. |
| 2362 | __ Push(x0, cp, x11, x10); |
| 2363 | __ CallRuntime(Runtime::kStoreLookupSlot, 4); |
| 2364 | } else { |
| 2365 | // Assignment to var or initializing assignment to let/const in harmony |
| 2366 | // mode. |
| 2367 | DCHECK(var->IsStackAllocated() || var->IsContextSlot()); |
| 2368 | MemOperand location = VarOperand(var, x1); |
| 2369 | if (FLAG_debug_code && op == Token::INIT_LET) { |
| 2370 | __ Ldr(x10, location); |
| 2371 | __ CompareRoot(x10, Heap::kTheHoleValueRootIndex); |
| 2372 | __ Check(eq, kLetBindingReInitialization); |
| 2373 | } |
| 2374 | EmitStoreToStackLocalOrContextSlot(var, location); |
| 2375 | } |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 2376 | } else if (IsSignallingAssignmentToConst(var, op, strict_mode())) { |
| 2377 | __ CallRuntime(Runtime::kThrowConstAssignError, 0); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2378 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2379 | } |
| 2380 | |
| 2381 | |
| 2382 | void FullCodeGenerator::EmitNamedPropertyAssignment(Assignment* expr) { |
| 2383 | ASM_LOCATION("FullCodeGenerator::EmitNamedPropertyAssignment"); |
| 2384 | // Assignment to a property, using a named store IC. |
| 2385 | Property* prop = expr->target()->AsProperty(); |
| 2386 | DCHECK(prop != NULL); |
| 2387 | DCHECK(prop->key()->IsLiteral()); |
| 2388 | |
| 2389 | // Record source code position before IC call. |
| 2390 | SetSourcePosition(expr->position()); |
| 2391 | __ Mov(StoreDescriptor::NameRegister(), |
| 2392 | Operand(prop->key()->AsLiteral()->value())); |
| 2393 | __ Pop(StoreDescriptor::ReceiverRegister()); |
| 2394 | CallStoreIC(expr->AssignmentFeedbackId()); |
| 2395 | |
| 2396 | PrepareForBailoutForId(expr->AssignmentId(), TOS_REG); |
| 2397 | context()->Plug(x0); |
| 2398 | } |
| 2399 | |
| 2400 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 2401 | void FullCodeGenerator::EmitNamedSuperPropertyStore(Property* prop) { |
| 2402 | // Assignment to named property of super. |
| 2403 | // x0 : value |
| 2404 | // stack : receiver ('this'), home_object |
| 2405 | DCHECK(prop != NULL); |
| 2406 | Literal* key = prop->key()->AsLiteral(); |
| 2407 | DCHECK(key != NULL); |
| 2408 | |
| 2409 | __ Push(key->value()); |
| 2410 | __ Push(x0); |
| 2411 | __ CallRuntime((strict_mode() == STRICT ? Runtime::kStoreToSuper_Strict |
| 2412 | : Runtime::kStoreToSuper_Sloppy), |
| 2413 | 4); |
| 2414 | } |
| 2415 | |
| 2416 | |
| 2417 | void FullCodeGenerator::EmitKeyedSuperPropertyStore(Property* prop) { |
| 2418 | // Assignment to named property of super. |
| 2419 | // x0 : value |
| 2420 | // stack : receiver ('this'), home_object, key |
| 2421 | DCHECK(prop != NULL); |
| 2422 | |
| 2423 | __ Push(x0); |
| 2424 | __ CallRuntime((strict_mode() == STRICT ? Runtime::kStoreKeyedToSuper_Strict |
| 2425 | : Runtime::kStoreKeyedToSuper_Sloppy), |
| 2426 | 4); |
| 2427 | } |
| 2428 | |
| 2429 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2430 | void FullCodeGenerator::EmitKeyedPropertyAssignment(Assignment* expr) { |
| 2431 | ASM_LOCATION("FullCodeGenerator::EmitKeyedPropertyAssignment"); |
| 2432 | // Assignment to a property, using a keyed store IC. |
| 2433 | |
| 2434 | // Record source code position before IC call. |
| 2435 | SetSourcePosition(expr->position()); |
| 2436 | // TODO(all): Could we pass this in registers rather than on the stack? |
| 2437 | __ Pop(StoreDescriptor::NameRegister(), StoreDescriptor::ReceiverRegister()); |
| 2438 | DCHECK(StoreDescriptor::ValueRegister().is(x0)); |
| 2439 | |
| 2440 | Handle<Code> ic = CodeFactory::KeyedStoreIC(isolate(), strict_mode()).code(); |
| 2441 | CallIC(ic, expr->AssignmentFeedbackId()); |
| 2442 | |
| 2443 | PrepareForBailoutForId(expr->AssignmentId(), TOS_REG); |
| 2444 | context()->Plug(x0); |
| 2445 | } |
| 2446 | |
| 2447 | |
| 2448 | void FullCodeGenerator::VisitProperty(Property* expr) { |
| 2449 | Comment cmnt(masm_, "[ Property"); |
| 2450 | Expression* key = expr->key(); |
| 2451 | |
| 2452 | if (key->IsPropertyName()) { |
| 2453 | if (!expr->IsSuperAccess()) { |
| 2454 | VisitForAccumulatorValue(expr->obj()); |
| 2455 | __ Move(LoadDescriptor::ReceiverRegister(), x0); |
| 2456 | EmitNamedPropertyLoad(expr); |
| 2457 | } else { |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 2458 | VisitForStackValue(expr->obj()->AsSuperReference()->this_var()); |
| 2459 | EmitLoadHomeObject(expr->obj()->AsSuperReference()); |
| 2460 | __ Push(result_register()); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2461 | EmitNamedSuperPropertyLoad(expr); |
| 2462 | } |
| 2463 | PrepareForBailoutForId(expr->LoadId(), TOS_REG); |
| 2464 | context()->Plug(x0); |
| 2465 | } else { |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 2466 | if (!expr->IsSuperAccess()) { |
| 2467 | VisitForStackValue(expr->obj()); |
| 2468 | VisitForAccumulatorValue(expr->key()); |
| 2469 | __ Move(LoadDescriptor::NameRegister(), x0); |
| 2470 | __ Pop(LoadDescriptor::ReceiverRegister()); |
| 2471 | EmitKeyedPropertyLoad(expr); |
| 2472 | } else { |
| 2473 | VisitForStackValue(expr->obj()->AsSuperReference()->this_var()); |
| 2474 | EmitLoadHomeObject(expr->obj()->AsSuperReference()); |
| 2475 | __ Push(result_register()); |
| 2476 | VisitForStackValue(expr->key()); |
| 2477 | EmitKeyedSuperPropertyLoad(expr); |
| 2478 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2479 | context()->Plug(x0); |
| 2480 | } |
| 2481 | } |
| 2482 | |
| 2483 | |
| 2484 | void FullCodeGenerator::CallIC(Handle<Code> code, |
| 2485 | TypeFeedbackId ast_id) { |
| 2486 | ic_total_count_++; |
| 2487 | // All calls must have a predictable size in full-codegen code to ensure that |
| 2488 | // the debugger can patch them correctly. |
| 2489 | __ Call(code, RelocInfo::CODE_TARGET, ast_id); |
| 2490 | } |
| 2491 | |
| 2492 | |
| 2493 | // Code common for calls using the IC. |
| 2494 | void FullCodeGenerator::EmitCallWithLoadIC(Call* expr) { |
| 2495 | Expression* callee = expr->expression(); |
| 2496 | |
| 2497 | CallICState::CallType call_type = |
| 2498 | callee->IsVariableProxy() ? CallICState::FUNCTION : CallICState::METHOD; |
| 2499 | |
| 2500 | // Get the target function. |
| 2501 | if (call_type == CallICState::FUNCTION) { |
| 2502 | { StackValueContext context(this); |
| 2503 | EmitVariableLoad(callee->AsVariableProxy()); |
| 2504 | PrepareForBailout(callee, NO_REGISTERS); |
| 2505 | } |
| 2506 | // Push undefined as receiver. This is patched in the method prologue if it |
| 2507 | // is a sloppy mode method. |
| 2508 | __ Push(isolate()->factory()->undefined_value()); |
| 2509 | } else { |
| 2510 | // Load the function from the receiver. |
| 2511 | DCHECK(callee->IsProperty()); |
| 2512 | DCHECK(!callee->AsProperty()->IsSuperAccess()); |
| 2513 | __ Peek(LoadDescriptor::ReceiverRegister(), 0); |
| 2514 | EmitNamedPropertyLoad(callee->AsProperty()); |
| 2515 | PrepareForBailoutForId(callee->AsProperty()->LoadId(), TOS_REG); |
| 2516 | // Push the target function under the receiver. |
| 2517 | __ Pop(x10); |
| 2518 | __ Push(x0, x10); |
| 2519 | } |
| 2520 | |
| 2521 | EmitCall(expr, call_type); |
| 2522 | } |
| 2523 | |
| 2524 | |
| 2525 | void FullCodeGenerator::EmitSuperCallWithLoadIC(Call* expr) { |
| 2526 | Expression* callee = expr->expression(); |
| 2527 | DCHECK(callee->IsProperty()); |
| 2528 | Property* prop = callee->AsProperty(); |
| 2529 | DCHECK(prop->IsSuperAccess()); |
| 2530 | |
| 2531 | SetSourcePosition(prop->position()); |
| 2532 | Literal* key = prop->key()->AsLiteral(); |
| 2533 | DCHECK(!key->value()->IsSmi()); |
| 2534 | |
| 2535 | // Load the function from the receiver. |
| 2536 | const Register scratch = x10; |
| 2537 | SuperReference* super_ref = callee->AsProperty()->obj()->AsSuperReference(); |
| 2538 | EmitLoadHomeObject(super_ref); |
| 2539 | __ Push(x0); |
| 2540 | VisitForAccumulatorValue(super_ref->this_var()); |
| 2541 | __ Push(x0); |
| 2542 | __ Peek(scratch, kPointerSize); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 2543 | __ Push(x0, scratch); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2544 | __ Push(key->value()); |
| 2545 | |
| 2546 | // Stack here: |
| 2547 | // - home_object |
| 2548 | // - this (receiver) |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 2549 | // - this (receiver) <-- LoadFromSuper will pop here and below. |
| 2550 | // - home_object |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2551 | // - key |
| 2552 | __ CallRuntime(Runtime::kLoadFromSuper, 3); |
| 2553 | |
| 2554 | // Replace home_object with target function. |
| 2555 | __ Poke(x0, kPointerSize); |
| 2556 | |
| 2557 | // Stack here: |
| 2558 | // - target function |
| 2559 | // - this (receiver) |
| 2560 | EmitCall(expr, CallICState::METHOD); |
| 2561 | } |
| 2562 | |
| 2563 | |
| 2564 | // Code common for calls using the IC. |
| 2565 | void FullCodeGenerator::EmitKeyedCallWithLoadIC(Call* expr, |
| 2566 | Expression* key) { |
| 2567 | // Load the key. |
| 2568 | VisitForAccumulatorValue(key); |
| 2569 | |
| 2570 | Expression* callee = expr->expression(); |
| 2571 | |
| 2572 | // Load the function from the receiver. |
| 2573 | DCHECK(callee->IsProperty()); |
| 2574 | __ Peek(LoadDescriptor::ReceiverRegister(), 0); |
| 2575 | __ Move(LoadDescriptor::NameRegister(), x0); |
| 2576 | EmitKeyedPropertyLoad(callee->AsProperty()); |
| 2577 | PrepareForBailoutForId(callee->AsProperty()->LoadId(), TOS_REG); |
| 2578 | |
| 2579 | // Push the target function under the receiver. |
| 2580 | __ Pop(x10); |
| 2581 | __ Push(x0, x10); |
| 2582 | |
| 2583 | EmitCall(expr, CallICState::METHOD); |
| 2584 | } |
| 2585 | |
| 2586 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 2587 | void FullCodeGenerator::EmitKeyedSuperCallWithLoadIC(Call* expr) { |
| 2588 | Expression* callee = expr->expression(); |
| 2589 | DCHECK(callee->IsProperty()); |
| 2590 | Property* prop = callee->AsProperty(); |
| 2591 | DCHECK(prop->IsSuperAccess()); |
| 2592 | |
| 2593 | SetSourcePosition(prop->position()); |
| 2594 | |
| 2595 | // Load the function from the receiver. |
| 2596 | const Register scratch = x10; |
| 2597 | SuperReference* super_ref = callee->AsProperty()->obj()->AsSuperReference(); |
| 2598 | EmitLoadHomeObject(super_ref); |
| 2599 | __ Push(x0); |
| 2600 | VisitForAccumulatorValue(super_ref->this_var()); |
| 2601 | __ Push(x0); |
| 2602 | __ Peek(scratch, kPointerSize); |
| 2603 | __ Push(x0, scratch); |
| 2604 | VisitForStackValue(prop->key()); |
| 2605 | |
| 2606 | // Stack here: |
| 2607 | // - home_object |
| 2608 | // - this (receiver) |
| 2609 | // - this (receiver) <-- LoadKeyedFromSuper will pop here and below. |
| 2610 | // - home_object |
| 2611 | // - key |
| 2612 | __ CallRuntime(Runtime::kLoadKeyedFromSuper, 3); |
| 2613 | |
| 2614 | // Replace home_object with target function. |
| 2615 | __ Poke(x0, kPointerSize); |
| 2616 | |
| 2617 | // Stack here: |
| 2618 | // - target function |
| 2619 | // - this (receiver) |
| 2620 | EmitCall(expr, CallICState::METHOD); |
| 2621 | } |
| 2622 | |
| 2623 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2624 | void FullCodeGenerator::EmitCall(Call* expr, CallICState::CallType call_type) { |
| 2625 | // Load the arguments. |
| 2626 | ZoneList<Expression*>* args = expr->arguments(); |
| 2627 | int arg_count = args->length(); |
| 2628 | { PreservePositionScope scope(masm()->positions_recorder()); |
| 2629 | for (int i = 0; i < arg_count; i++) { |
| 2630 | VisitForStackValue(args->at(i)); |
| 2631 | } |
| 2632 | } |
| 2633 | // Record source position of the IC call. |
| 2634 | SetSourcePosition(expr->position()); |
| 2635 | |
| 2636 | Handle<Code> ic = CallIC::initialize_stub( |
| 2637 | isolate(), arg_count, call_type); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 2638 | __ Mov(x3, SmiFromSlot(expr->CallFeedbackSlot())); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2639 | __ Peek(x1, (arg_count + 1) * kXRegSize); |
| 2640 | // Don't assign a type feedback id to the IC, since type feedback is provided |
| 2641 | // by the vector above. |
| 2642 | CallIC(ic); |
| 2643 | |
| 2644 | RecordJSReturnSite(expr); |
| 2645 | // Restore context register. |
| 2646 | __ Ldr(cp, MemOperand(fp, StandardFrameConstants::kContextOffset)); |
| 2647 | context()->DropAndPlug(1, x0); |
| 2648 | } |
| 2649 | |
| 2650 | |
| 2651 | void FullCodeGenerator::EmitResolvePossiblyDirectEval(int arg_count) { |
| 2652 | ASM_LOCATION("FullCodeGenerator::EmitResolvePossiblyDirectEval"); |
| 2653 | // Prepare to push a copy of the first argument or undefined if it doesn't |
| 2654 | // exist. |
| 2655 | if (arg_count > 0) { |
| 2656 | __ Peek(x9, arg_count * kXRegSize); |
| 2657 | } else { |
| 2658 | __ LoadRoot(x9, Heap::kUndefinedValueRootIndex); |
| 2659 | } |
| 2660 | |
| 2661 | __ Ldr(x10, MemOperand(fp, JavaScriptFrameConstants::kFunctionOffset)); |
| 2662 | // Prepare to push the receiver of the enclosing function. |
| 2663 | int receiver_offset = 2 + info_->scope()->num_parameters(); |
| 2664 | __ Ldr(x11, MemOperand(fp, receiver_offset * kPointerSize)); |
| 2665 | |
| 2666 | // Prepare to push the language mode. |
| 2667 | __ Mov(x12, Smi::FromInt(strict_mode())); |
| 2668 | // Prepare to push the start position of the scope the calls resides in. |
| 2669 | __ Mov(x13, Smi::FromInt(scope()->start_position())); |
| 2670 | |
| 2671 | // Push. |
| 2672 | __ Push(x9, x10, x11, x12, x13); |
| 2673 | |
| 2674 | // Do the runtime call. |
| 2675 | __ CallRuntime(Runtime::kResolvePossiblyDirectEval, 6); |
| 2676 | } |
| 2677 | |
| 2678 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 2679 | void FullCodeGenerator::EmitLoadSuperConstructor(SuperReference* super_ref) { |
| 2680 | DCHECK(super_ref != NULL); |
| 2681 | __ ldr(x0, MemOperand(fp, JavaScriptFrameConstants::kFunctionOffset)); |
| 2682 | __ Push(x0); |
| 2683 | __ CallRuntime(Runtime::kGetPrototype, 1); |
| 2684 | } |
| 2685 | |
| 2686 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2687 | void FullCodeGenerator::VisitCall(Call* expr) { |
| 2688 | #ifdef DEBUG |
| 2689 | // We want to verify that RecordJSReturnSite gets called on all paths |
| 2690 | // through this function. Avoid early returns. |
| 2691 | expr->return_is_recorded_ = false; |
| 2692 | #endif |
| 2693 | |
| 2694 | Comment cmnt(masm_, "[ Call"); |
| 2695 | Expression* callee = expr->expression(); |
| 2696 | Call::CallType call_type = expr->GetCallType(isolate()); |
| 2697 | |
| 2698 | if (call_type == Call::POSSIBLY_EVAL_CALL) { |
| 2699 | // In a call to eval, we first call RuntimeHidden_ResolvePossiblyDirectEval |
| 2700 | // to resolve the function we need to call and the receiver of the |
| 2701 | // call. Then we call the resolved function using the given |
| 2702 | // arguments. |
| 2703 | ZoneList<Expression*>* args = expr->arguments(); |
| 2704 | int arg_count = args->length(); |
| 2705 | |
| 2706 | { |
| 2707 | PreservePositionScope pos_scope(masm()->positions_recorder()); |
| 2708 | VisitForStackValue(callee); |
| 2709 | __ LoadRoot(x10, Heap::kUndefinedValueRootIndex); |
| 2710 | __ Push(x10); // Reserved receiver slot. |
| 2711 | |
| 2712 | // Push the arguments. |
| 2713 | for (int i = 0; i < arg_count; i++) { |
| 2714 | VisitForStackValue(args->at(i)); |
| 2715 | } |
| 2716 | |
| 2717 | // Push a copy of the function (found below the arguments) and |
| 2718 | // resolve eval. |
| 2719 | __ Peek(x10, (arg_count + 1) * kPointerSize); |
| 2720 | __ Push(x10); |
| 2721 | EmitResolvePossiblyDirectEval(arg_count); |
| 2722 | |
| 2723 | // The runtime call returns a pair of values in x0 (function) and |
| 2724 | // x1 (receiver). Touch up the stack with the right values. |
| 2725 | __ PokePair(x1, x0, arg_count * kPointerSize); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 2726 | |
| 2727 | PrepareForBailoutForId(expr->EvalOrLookupId(), NO_REGISTERS); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2728 | } |
| 2729 | |
| 2730 | // Record source position for debugger. |
| 2731 | SetSourcePosition(expr->position()); |
| 2732 | |
| 2733 | // Call the evaluated function. |
| 2734 | CallFunctionStub stub(isolate(), arg_count, NO_CALL_FUNCTION_FLAGS); |
| 2735 | __ Peek(x1, (arg_count + 1) * kXRegSize); |
| 2736 | __ CallStub(&stub); |
| 2737 | RecordJSReturnSite(expr); |
| 2738 | // Restore context register. |
| 2739 | __ Ldr(cp, MemOperand(fp, StandardFrameConstants::kContextOffset)); |
| 2740 | context()->DropAndPlug(1, x0); |
| 2741 | |
| 2742 | } else if (call_type == Call::GLOBAL_CALL) { |
| 2743 | EmitCallWithLoadIC(expr); |
| 2744 | |
| 2745 | } else if (call_type == Call::LOOKUP_SLOT_CALL) { |
| 2746 | // Call to a lookup slot (dynamically introduced variable). |
| 2747 | VariableProxy* proxy = callee->AsVariableProxy(); |
| 2748 | Label slow, done; |
| 2749 | |
| 2750 | { PreservePositionScope scope(masm()->positions_recorder()); |
| 2751 | // Generate code for loading from variables potentially shadowed |
| 2752 | // by eval-introduced variables. |
| 2753 | EmitDynamicLookupFastCase(proxy, NOT_INSIDE_TYPEOF, &slow, &done); |
| 2754 | } |
| 2755 | |
| 2756 | __ Bind(&slow); |
| 2757 | // Call the runtime to find the function to call (returned in x0) |
| 2758 | // and the object holding it (returned in x1). |
| 2759 | __ Mov(x10, Operand(proxy->name())); |
| 2760 | __ Push(context_register(), x10); |
| 2761 | __ CallRuntime(Runtime::kLoadLookupSlot, 2); |
| 2762 | __ Push(x0, x1); // Receiver, function. |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 2763 | PrepareForBailoutForId(expr->EvalOrLookupId(), NO_REGISTERS); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2764 | |
| 2765 | // If fast case code has been generated, emit code to push the |
| 2766 | // function and receiver and have the slow path jump around this |
| 2767 | // code. |
| 2768 | if (done.is_linked()) { |
| 2769 | Label call; |
| 2770 | __ B(&call); |
| 2771 | __ Bind(&done); |
| 2772 | // Push function. |
| 2773 | // The receiver is implicitly the global receiver. Indicate this |
| 2774 | // by passing the undefined to the call function stub. |
| 2775 | __ LoadRoot(x1, Heap::kUndefinedValueRootIndex); |
| 2776 | __ Push(x0, x1); |
| 2777 | __ Bind(&call); |
| 2778 | } |
| 2779 | |
| 2780 | // The receiver is either the global receiver or an object found |
| 2781 | // by LoadContextSlot. |
| 2782 | EmitCall(expr); |
| 2783 | } else if (call_type == Call::PROPERTY_CALL) { |
| 2784 | Property* property = callee->AsProperty(); |
| 2785 | bool is_named_call = property->key()->IsPropertyName(); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 2786 | if (property->IsSuperAccess()) { |
| 2787 | if (is_named_call) { |
| 2788 | EmitSuperCallWithLoadIC(expr); |
| 2789 | } else { |
| 2790 | EmitKeyedSuperCallWithLoadIC(expr); |
| 2791 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2792 | } else { |
| 2793 | { |
| 2794 | PreservePositionScope scope(masm()->positions_recorder()); |
| 2795 | VisitForStackValue(property->obj()); |
| 2796 | } |
| 2797 | if (is_named_call) { |
| 2798 | EmitCallWithLoadIC(expr); |
| 2799 | } else { |
| 2800 | EmitKeyedCallWithLoadIC(expr, property->key()); |
| 2801 | } |
| 2802 | } |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 2803 | } else if (call_type == Call::SUPER_CALL) { |
| 2804 | SuperReference* super_ref = callee->AsSuperReference(); |
| 2805 | EmitLoadSuperConstructor(super_ref); |
| 2806 | __ Push(result_register()); |
| 2807 | VisitForStackValue(super_ref->this_var()); |
| 2808 | EmitCall(expr, CallICState::METHOD); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2809 | } else { |
| 2810 | DCHECK(call_type == Call::OTHER_CALL); |
| 2811 | // Call to an arbitrary expression not handled specially above. |
| 2812 | { PreservePositionScope scope(masm()->positions_recorder()); |
| 2813 | VisitForStackValue(callee); |
| 2814 | } |
| 2815 | __ LoadRoot(x1, Heap::kUndefinedValueRootIndex); |
| 2816 | __ Push(x1); |
| 2817 | // Emit function call. |
| 2818 | EmitCall(expr); |
| 2819 | } |
| 2820 | |
| 2821 | #ifdef DEBUG |
| 2822 | // RecordJSReturnSite should have been called. |
| 2823 | DCHECK(expr->return_is_recorded_); |
| 2824 | #endif |
| 2825 | } |
| 2826 | |
| 2827 | |
| 2828 | void FullCodeGenerator::VisitCallNew(CallNew* expr) { |
| 2829 | Comment cmnt(masm_, "[ CallNew"); |
| 2830 | // According to ECMA-262, section 11.2.2, page 44, the function |
| 2831 | // expression in new calls must be evaluated before the |
| 2832 | // arguments. |
| 2833 | |
| 2834 | // Push constructor on the stack. If it's not a function it's used as |
| 2835 | // receiver for CALL_NON_FUNCTION, otherwise the value on the stack is |
| 2836 | // ignored. |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 2837 | if (expr->expression()->IsSuperReference()) { |
| 2838 | EmitLoadSuperConstructor(expr->expression()->AsSuperReference()); |
| 2839 | __ Push(result_register()); |
| 2840 | } else { |
| 2841 | VisitForStackValue(expr->expression()); |
| 2842 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2843 | |
| 2844 | // Push the arguments ("left-to-right") on the stack. |
| 2845 | ZoneList<Expression*>* args = expr->arguments(); |
| 2846 | int arg_count = args->length(); |
| 2847 | for (int i = 0; i < arg_count; i++) { |
| 2848 | VisitForStackValue(args->at(i)); |
| 2849 | } |
| 2850 | |
| 2851 | // Call the construct call builtin that handles allocation and |
| 2852 | // constructor invocation. |
| 2853 | SetSourcePosition(expr->position()); |
| 2854 | |
| 2855 | // Load function and argument count into x1 and x0. |
| 2856 | __ Mov(x0, arg_count); |
| 2857 | __ Peek(x1, arg_count * kXRegSize); |
| 2858 | |
| 2859 | // Record call targets in unoptimized code. |
| 2860 | if (FLAG_pretenuring_call_new) { |
| 2861 | EnsureSlotContainsAllocationSite(expr->AllocationSiteFeedbackSlot()); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 2862 | DCHECK(expr->AllocationSiteFeedbackSlot().ToInt() == |
| 2863 | expr->CallNewFeedbackSlot().ToInt() + 1); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2864 | } |
| 2865 | |
| 2866 | __ LoadObject(x2, FeedbackVector()); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 2867 | __ Mov(x3, SmiFromSlot(expr->CallNewFeedbackSlot())); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2868 | |
| 2869 | CallConstructStub stub(isolate(), RECORD_CONSTRUCTOR_TARGET); |
| 2870 | __ Call(stub.GetCode(), RelocInfo::CONSTRUCT_CALL); |
| 2871 | PrepareForBailoutForId(expr->ReturnId(), TOS_REG); |
| 2872 | context()->Plug(x0); |
| 2873 | } |
| 2874 | |
| 2875 | |
| 2876 | void FullCodeGenerator::EmitIsSmi(CallRuntime* expr) { |
| 2877 | ZoneList<Expression*>* args = expr->arguments(); |
| 2878 | DCHECK(args->length() == 1); |
| 2879 | |
| 2880 | VisitForAccumulatorValue(args->at(0)); |
| 2881 | |
| 2882 | Label materialize_true, materialize_false; |
| 2883 | Label* if_true = NULL; |
| 2884 | Label* if_false = NULL; |
| 2885 | Label* fall_through = NULL; |
| 2886 | context()->PrepareTest(&materialize_true, &materialize_false, |
| 2887 | &if_true, &if_false, &fall_through); |
| 2888 | |
| 2889 | PrepareForBailoutBeforeSplit(expr, true, if_true, if_false); |
| 2890 | __ TestAndSplit(x0, kSmiTagMask, if_true, if_false, fall_through); |
| 2891 | |
| 2892 | context()->Plug(if_true, if_false); |
| 2893 | } |
| 2894 | |
| 2895 | |
| 2896 | void FullCodeGenerator::EmitIsNonNegativeSmi(CallRuntime* expr) { |
| 2897 | ZoneList<Expression*>* args = expr->arguments(); |
| 2898 | DCHECK(args->length() == 1); |
| 2899 | |
| 2900 | VisitForAccumulatorValue(args->at(0)); |
| 2901 | |
| 2902 | Label materialize_true, materialize_false; |
| 2903 | Label* if_true = NULL; |
| 2904 | Label* if_false = NULL; |
| 2905 | Label* fall_through = NULL; |
| 2906 | context()->PrepareTest(&materialize_true, &materialize_false, |
| 2907 | &if_true, &if_false, &fall_through); |
| 2908 | |
| 2909 | uint64_t sign_mask = V8_UINT64_C(1) << (kSmiShift + kSmiValueSize - 1); |
| 2910 | |
| 2911 | PrepareForBailoutBeforeSplit(expr, true, if_true, if_false); |
| 2912 | __ TestAndSplit(x0, kSmiTagMask | sign_mask, if_true, if_false, fall_through); |
| 2913 | |
| 2914 | context()->Plug(if_true, if_false); |
| 2915 | } |
| 2916 | |
| 2917 | |
| 2918 | void FullCodeGenerator::EmitIsObject(CallRuntime* expr) { |
| 2919 | ZoneList<Expression*>* args = expr->arguments(); |
| 2920 | DCHECK(args->length() == 1); |
| 2921 | |
| 2922 | VisitForAccumulatorValue(args->at(0)); |
| 2923 | |
| 2924 | Label materialize_true, materialize_false; |
| 2925 | Label* if_true = NULL; |
| 2926 | Label* if_false = NULL; |
| 2927 | Label* fall_through = NULL; |
| 2928 | context()->PrepareTest(&materialize_true, &materialize_false, |
| 2929 | &if_true, &if_false, &fall_through); |
| 2930 | |
| 2931 | __ JumpIfSmi(x0, if_false); |
| 2932 | __ JumpIfRoot(x0, Heap::kNullValueRootIndex, if_true); |
| 2933 | __ Ldr(x10, FieldMemOperand(x0, HeapObject::kMapOffset)); |
| 2934 | // Undetectable objects behave like undefined when tested with typeof. |
| 2935 | __ Ldrb(x11, FieldMemOperand(x10, Map::kBitFieldOffset)); |
| 2936 | __ Tbnz(x11, Map::kIsUndetectable, if_false); |
| 2937 | __ Ldrb(x12, FieldMemOperand(x10, Map::kInstanceTypeOffset)); |
| 2938 | __ Cmp(x12, FIRST_NONCALLABLE_SPEC_OBJECT_TYPE); |
| 2939 | __ B(lt, if_false); |
| 2940 | __ Cmp(x12, LAST_NONCALLABLE_SPEC_OBJECT_TYPE); |
| 2941 | PrepareForBailoutBeforeSplit(expr, true, if_true, if_false); |
| 2942 | Split(le, if_true, if_false, fall_through); |
| 2943 | |
| 2944 | context()->Plug(if_true, if_false); |
| 2945 | } |
| 2946 | |
| 2947 | |
| 2948 | void FullCodeGenerator::EmitIsSpecObject(CallRuntime* expr) { |
| 2949 | ZoneList<Expression*>* args = expr->arguments(); |
| 2950 | DCHECK(args->length() == 1); |
| 2951 | |
| 2952 | VisitForAccumulatorValue(args->at(0)); |
| 2953 | |
| 2954 | Label materialize_true, materialize_false; |
| 2955 | Label* if_true = NULL; |
| 2956 | Label* if_false = NULL; |
| 2957 | Label* fall_through = NULL; |
| 2958 | context()->PrepareTest(&materialize_true, &materialize_false, |
| 2959 | &if_true, &if_false, &fall_through); |
| 2960 | |
| 2961 | __ JumpIfSmi(x0, if_false); |
| 2962 | __ CompareObjectType(x0, x10, x11, FIRST_SPEC_OBJECT_TYPE); |
| 2963 | PrepareForBailoutBeforeSplit(expr, true, if_true, if_false); |
| 2964 | Split(ge, if_true, if_false, fall_through); |
| 2965 | |
| 2966 | context()->Plug(if_true, if_false); |
| 2967 | } |
| 2968 | |
| 2969 | |
| 2970 | void FullCodeGenerator::EmitIsUndetectableObject(CallRuntime* expr) { |
| 2971 | ASM_LOCATION("FullCodeGenerator::EmitIsUndetectableObject"); |
| 2972 | ZoneList<Expression*>* args = expr->arguments(); |
| 2973 | DCHECK(args->length() == 1); |
| 2974 | |
| 2975 | VisitForAccumulatorValue(args->at(0)); |
| 2976 | |
| 2977 | Label materialize_true, materialize_false; |
| 2978 | Label* if_true = NULL; |
| 2979 | Label* if_false = NULL; |
| 2980 | Label* fall_through = NULL; |
| 2981 | context()->PrepareTest(&materialize_true, &materialize_false, |
| 2982 | &if_true, &if_false, &fall_through); |
| 2983 | |
| 2984 | __ JumpIfSmi(x0, if_false); |
| 2985 | __ Ldr(x10, FieldMemOperand(x0, HeapObject::kMapOffset)); |
| 2986 | __ Ldrb(x11, FieldMemOperand(x10, Map::kBitFieldOffset)); |
| 2987 | __ Tst(x11, 1 << Map::kIsUndetectable); |
| 2988 | PrepareForBailoutBeforeSplit(expr, true, if_true, if_false); |
| 2989 | Split(ne, if_true, if_false, fall_through); |
| 2990 | |
| 2991 | context()->Plug(if_true, if_false); |
| 2992 | } |
| 2993 | |
| 2994 | |
| 2995 | void FullCodeGenerator::EmitIsStringWrapperSafeForDefaultValueOf( |
| 2996 | CallRuntime* expr) { |
| 2997 | ZoneList<Expression*>* args = expr->arguments(); |
| 2998 | DCHECK(args->length() == 1); |
| 2999 | VisitForAccumulatorValue(args->at(0)); |
| 3000 | |
| 3001 | Label materialize_true, materialize_false, skip_lookup; |
| 3002 | Label* if_true = NULL; |
| 3003 | Label* if_false = NULL; |
| 3004 | Label* fall_through = NULL; |
| 3005 | context()->PrepareTest(&materialize_true, &materialize_false, |
| 3006 | &if_true, &if_false, &fall_through); |
| 3007 | |
| 3008 | Register object = x0; |
| 3009 | __ AssertNotSmi(object); |
| 3010 | |
| 3011 | Register map = x10; |
| 3012 | Register bitfield2 = x11; |
| 3013 | __ Ldr(map, FieldMemOperand(object, HeapObject::kMapOffset)); |
| 3014 | __ Ldrb(bitfield2, FieldMemOperand(map, Map::kBitField2Offset)); |
| 3015 | __ Tbnz(bitfield2, Map::kStringWrapperSafeForDefaultValueOf, &skip_lookup); |
| 3016 | |
| 3017 | // Check for fast case object. Generate false result for slow case object. |
| 3018 | Register props = x12; |
| 3019 | Register props_map = x12; |
| 3020 | Register hash_table_map = x13; |
| 3021 | __ Ldr(props, FieldMemOperand(object, JSObject::kPropertiesOffset)); |
| 3022 | __ Ldr(props_map, FieldMemOperand(props, HeapObject::kMapOffset)); |
| 3023 | __ LoadRoot(hash_table_map, Heap::kHashTableMapRootIndex); |
| 3024 | __ Cmp(props_map, hash_table_map); |
| 3025 | __ B(eq, if_false); |
| 3026 | |
| 3027 | // Look for valueOf name in the descriptor array, and indicate false if found. |
| 3028 | // Since we omit an enumeration index check, if it is added via a transition |
| 3029 | // that shares its descriptor array, this is a false positive. |
| 3030 | Label loop, done; |
| 3031 | |
| 3032 | // Skip loop if no descriptors are valid. |
| 3033 | Register descriptors = x12; |
| 3034 | Register descriptors_length = x13; |
| 3035 | __ NumberOfOwnDescriptors(descriptors_length, map); |
| 3036 | __ Cbz(descriptors_length, &done); |
| 3037 | |
| 3038 | __ LoadInstanceDescriptors(map, descriptors); |
| 3039 | |
| 3040 | // Calculate the end of the descriptor array. |
| 3041 | Register descriptors_end = x14; |
| 3042 | __ Mov(x15, DescriptorArray::kDescriptorSize); |
| 3043 | __ Mul(descriptors_length, descriptors_length, x15); |
| 3044 | // Calculate location of the first key name. |
| 3045 | __ Add(descriptors, descriptors, |
| 3046 | DescriptorArray::kFirstOffset - kHeapObjectTag); |
| 3047 | // Calculate the end of the descriptor array. |
| 3048 | __ Add(descriptors_end, descriptors, |
| 3049 | Operand(descriptors_length, LSL, kPointerSizeLog2)); |
| 3050 | |
| 3051 | // Loop through all the keys in the descriptor array. If one of these is the |
| 3052 | // string "valueOf" the result is false. |
| 3053 | Register valueof_string = x1; |
| 3054 | int descriptor_size = DescriptorArray::kDescriptorSize * kPointerSize; |
| 3055 | __ Mov(valueof_string, Operand(isolate()->factory()->value_of_string())); |
| 3056 | __ Bind(&loop); |
| 3057 | __ Ldr(x15, MemOperand(descriptors, descriptor_size, PostIndex)); |
| 3058 | __ Cmp(x15, valueof_string); |
| 3059 | __ B(eq, if_false); |
| 3060 | __ Cmp(descriptors, descriptors_end); |
| 3061 | __ B(ne, &loop); |
| 3062 | |
| 3063 | __ Bind(&done); |
| 3064 | |
| 3065 | // Set the bit in the map to indicate that there is no local valueOf field. |
| 3066 | __ Ldrb(x2, FieldMemOperand(map, Map::kBitField2Offset)); |
| 3067 | __ Orr(x2, x2, 1 << Map::kStringWrapperSafeForDefaultValueOf); |
| 3068 | __ Strb(x2, FieldMemOperand(map, Map::kBitField2Offset)); |
| 3069 | |
| 3070 | __ Bind(&skip_lookup); |
| 3071 | |
| 3072 | // If a valueOf property is not found on the object check that its prototype |
| 3073 | // is the unmodified String prototype. If not result is false. |
| 3074 | Register prototype = x1; |
| 3075 | Register global_idx = x2; |
| 3076 | Register native_context = x2; |
| 3077 | Register string_proto = x3; |
| 3078 | Register proto_map = x4; |
| 3079 | __ Ldr(prototype, FieldMemOperand(map, Map::kPrototypeOffset)); |
| 3080 | __ JumpIfSmi(prototype, if_false); |
| 3081 | __ Ldr(proto_map, FieldMemOperand(prototype, HeapObject::kMapOffset)); |
| 3082 | __ Ldr(global_idx, GlobalObjectMemOperand()); |
| 3083 | __ Ldr(native_context, |
| 3084 | FieldMemOperand(global_idx, GlobalObject::kNativeContextOffset)); |
| 3085 | __ Ldr(string_proto, |
| 3086 | ContextMemOperand(native_context, |
| 3087 | Context::STRING_FUNCTION_PROTOTYPE_MAP_INDEX)); |
| 3088 | __ Cmp(proto_map, string_proto); |
| 3089 | |
| 3090 | PrepareForBailoutBeforeSplit(expr, true, if_true, if_false); |
| 3091 | Split(eq, if_true, if_false, fall_through); |
| 3092 | |
| 3093 | context()->Plug(if_true, if_false); |
| 3094 | } |
| 3095 | |
| 3096 | |
| 3097 | void FullCodeGenerator::EmitIsFunction(CallRuntime* expr) { |
| 3098 | ZoneList<Expression*>* args = expr->arguments(); |
| 3099 | DCHECK(args->length() == 1); |
| 3100 | |
| 3101 | VisitForAccumulatorValue(args->at(0)); |
| 3102 | |
| 3103 | Label materialize_true, materialize_false; |
| 3104 | Label* if_true = NULL; |
| 3105 | Label* if_false = NULL; |
| 3106 | Label* fall_through = NULL; |
| 3107 | context()->PrepareTest(&materialize_true, &materialize_false, |
| 3108 | &if_true, &if_false, &fall_through); |
| 3109 | |
| 3110 | __ JumpIfSmi(x0, if_false); |
| 3111 | __ CompareObjectType(x0, x10, x11, JS_FUNCTION_TYPE); |
| 3112 | PrepareForBailoutBeforeSplit(expr, true, if_true, if_false); |
| 3113 | Split(eq, if_true, if_false, fall_through); |
| 3114 | |
| 3115 | context()->Plug(if_true, if_false); |
| 3116 | } |
| 3117 | |
| 3118 | |
| 3119 | void FullCodeGenerator::EmitIsMinusZero(CallRuntime* expr) { |
| 3120 | ZoneList<Expression*>* args = expr->arguments(); |
| 3121 | DCHECK(args->length() == 1); |
| 3122 | |
| 3123 | VisitForAccumulatorValue(args->at(0)); |
| 3124 | |
| 3125 | Label materialize_true, materialize_false; |
| 3126 | Label* if_true = NULL; |
| 3127 | Label* if_false = NULL; |
| 3128 | Label* fall_through = NULL; |
| 3129 | context()->PrepareTest(&materialize_true, &materialize_false, |
| 3130 | &if_true, &if_false, &fall_through); |
| 3131 | |
| 3132 | // Only a HeapNumber can be -0.0, so return false if we have something else. |
| 3133 | __ JumpIfNotHeapNumber(x0, if_false, DO_SMI_CHECK); |
| 3134 | |
| 3135 | // Test the bit pattern. |
| 3136 | __ Ldr(x10, FieldMemOperand(x0, HeapNumber::kValueOffset)); |
| 3137 | __ Cmp(x10, 1); // Set V on 0x8000000000000000. |
| 3138 | |
| 3139 | PrepareForBailoutBeforeSplit(expr, true, if_true, if_false); |
| 3140 | Split(vs, if_true, if_false, fall_through); |
| 3141 | |
| 3142 | context()->Plug(if_true, if_false); |
| 3143 | } |
| 3144 | |
| 3145 | |
| 3146 | void FullCodeGenerator::EmitIsArray(CallRuntime* expr) { |
| 3147 | ZoneList<Expression*>* args = expr->arguments(); |
| 3148 | DCHECK(args->length() == 1); |
| 3149 | |
| 3150 | VisitForAccumulatorValue(args->at(0)); |
| 3151 | |
| 3152 | Label materialize_true, materialize_false; |
| 3153 | Label* if_true = NULL; |
| 3154 | Label* if_false = NULL; |
| 3155 | Label* fall_through = NULL; |
| 3156 | context()->PrepareTest(&materialize_true, &materialize_false, |
| 3157 | &if_true, &if_false, &fall_through); |
| 3158 | |
| 3159 | __ JumpIfSmi(x0, if_false); |
| 3160 | __ CompareObjectType(x0, x10, x11, JS_ARRAY_TYPE); |
| 3161 | PrepareForBailoutBeforeSplit(expr, true, if_true, if_false); |
| 3162 | Split(eq, if_true, if_false, fall_through); |
| 3163 | |
| 3164 | context()->Plug(if_true, if_false); |
| 3165 | } |
| 3166 | |
| 3167 | |
| 3168 | void FullCodeGenerator::EmitIsRegExp(CallRuntime* expr) { |
| 3169 | ZoneList<Expression*>* args = expr->arguments(); |
| 3170 | DCHECK(args->length() == 1); |
| 3171 | |
| 3172 | VisitForAccumulatorValue(args->at(0)); |
| 3173 | |
| 3174 | Label materialize_true, materialize_false; |
| 3175 | Label* if_true = NULL; |
| 3176 | Label* if_false = NULL; |
| 3177 | Label* fall_through = NULL; |
| 3178 | context()->PrepareTest(&materialize_true, &materialize_false, |
| 3179 | &if_true, &if_false, &fall_through); |
| 3180 | |
| 3181 | __ JumpIfSmi(x0, if_false); |
| 3182 | __ CompareObjectType(x0, x10, x11, JS_REGEXP_TYPE); |
| 3183 | PrepareForBailoutBeforeSplit(expr, true, if_true, if_false); |
| 3184 | Split(eq, if_true, if_false, fall_through); |
| 3185 | |
| 3186 | context()->Plug(if_true, if_false); |
| 3187 | } |
| 3188 | |
| 3189 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 3190 | void FullCodeGenerator::EmitIsJSProxy(CallRuntime* expr) { |
| 3191 | ZoneList<Expression*>* args = expr->arguments(); |
| 3192 | DCHECK(args->length() == 1); |
| 3193 | |
| 3194 | VisitForAccumulatorValue(args->at(0)); |
| 3195 | |
| 3196 | Label materialize_true, materialize_false; |
| 3197 | Label* if_true = NULL; |
| 3198 | Label* if_false = NULL; |
| 3199 | Label* fall_through = NULL; |
| 3200 | context()->PrepareTest(&materialize_true, &materialize_false, &if_true, |
| 3201 | &if_false, &fall_through); |
| 3202 | |
| 3203 | __ JumpIfSmi(x0, if_false); |
| 3204 | Register map = x10; |
| 3205 | Register type_reg = x11; |
| 3206 | __ Ldr(map, FieldMemOperand(x0, HeapObject::kMapOffset)); |
| 3207 | __ Ldrb(type_reg, FieldMemOperand(map, Map::kInstanceTypeOffset)); |
| 3208 | __ Sub(type_reg, type_reg, Operand(FIRST_JS_PROXY_TYPE)); |
| 3209 | __ Cmp(type_reg, Operand(LAST_JS_PROXY_TYPE - FIRST_JS_PROXY_TYPE)); |
| 3210 | PrepareForBailoutBeforeSplit(expr, true, if_true, if_false); |
| 3211 | Split(ls, if_true, if_false, fall_through); |
| 3212 | |
| 3213 | context()->Plug(if_true, if_false); |
| 3214 | } |
| 3215 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3216 | |
| 3217 | void FullCodeGenerator::EmitIsConstructCall(CallRuntime* expr) { |
| 3218 | DCHECK(expr->arguments()->length() == 0); |
| 3219 | |
| 3220 | Label materialize_true, materialize_false; |
| 3221 | Label* if_true = NULL; |
| 3222 | Label* if_false = NULL; |
| 3223 | Label* fall_through = NULL; |
| 3224 | context()->PrepareTest(&materialize_true, &materialize_false, |
| 3225 | &if_true, &if_false, &fall_through); |
| 3226 | |
| 3227 | // Get the frame pointer for the calling frame. |
| 3228 | __ Ldr(x2, MemOperand(fp, StandardFrameConstants::kCallerFPOffset)); |
| 3229 | |
| 3230 | // Skip the arguments adaptor frame if it exists. |
| 3231 | Label check_frame_marker; |
| 3232 | __ Ldr(x1, MemOperand(x2, StandardFrameConstants::kContextOffset)); |
| 3233 | __ Cmp(x1, Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR)); |
| 3234 | __ B(ne, &check_frame_marker); |
| 3235 | __ Ldr(x2, MemOperand(x2, StandardFrameConstants::kCallerFPOffset)); |
| 3236 | |
| 3237 | // Check the marker in the calling frame. |
| 3238 | __ Bind(&check_frame_marker); |
| 3239 | __ Ldr(x1, MemOperand(x2, StandardFrameConstants::kMarkerOffset)); |
| 3240 | __ Cmp(x1, Smi::FromInt(StackFrame::CONSTRUCT)); |
| 3241 | PrepareForBailoutBeforeSplit(expr, true, if_true, if_false); |
| 3242 | Split(eq, if_true, if_false, fall_through); |
| 3243 | |
| 3244 | context()->Plug(if_true, if_false); |
| 3245 | } |
| 3246 | |
| 3247 | |
| 3248 | void FullCodeGenerator::EmitObjectEquals(CallRuntime* expr) { |
| 3249 | ZoneList<Expression*>* args = expr->arguments(); |
| 3250 | DCHECK(args->length() == 2); |
| 3251 | |
| 3252 | // Load the two objects into registers and perform the comparison. |
| 3253 | VisitForStackValue(args->at(0)); |
| 3254 | VisitForAccumulatorValue(args->at(1)); |
| 3255 | |
| 3256 | Label materialize_true, materialize_false; |
| 3257 | Label* if_true = NULL; |
| 3258 | Label* if_false = NULL; |
| 3259 | Label* fall_through = NULL; |
| 3260 | context()->PrepareTest(&materialize_true, &materialize_false, |
| 3261 | &if_true, &if_false, &fall_through); |
| 3262 | |
| 3263 | __ Pop(x1); |
| 3264 | __ Cmp(x0, x1); |
| 3265 | PrepareForBailoutBeforeSplit(expr, true, if_true, if_false); |
| 3266 | Split(eq, if_true, if_false, fall_through); |
| 3267 | |
| 3268 | context()->Plug(if_true, if_false); |
| 3269 | } |
| 3270 | |
| 3271 | |
| 3272 | void FullCodeGenerator::EmitArguments(CallRuntime* expr) { |
| 3273 | ZoneList<Expression*>* args = expr->arguments(); |
| 3274 | DCHECK(args->length() == 1); |
| 3275 | |
| 3276 | // ArgumentsAccessStub expects the key in x1. |
| 3277 | VisitForAccumulatorValue(args->at(0)); |
| 3278 | __ Mov(x1, x0); |
| 3279 | __ Mov(x0, Smi::FromInt(info_->scope()->num_parameters())); |
| 3280 | ArgumentsAccessStub stub(isolate(), ArgumentsAccessStub::READ_ELEMENT); |
| 3281 | __ CallStub(&stub); |
| 3282 | context()->Plug(x0); |
| 3283 | } |
| 3284 | |
| 3285 | |
| 3286 | void FullCodeGenerator::EmitArgumentsLength(CallRuntime* expr) { |
| 3287 | DCHECK(expr->arguments()->length() == 0); |
| 3288 | Label exit; |
| 3289 | // Get the number of formal parameters. |
| 3290 | __ Mov(x0, Smi::FromInt(info_->scope()->num_parameters())); |
| 3291 | |
| 3292 | // Check if the calling frame is an arguments adaptor frame. |
| 3293 | __ Ldr(x12, MemOperand(fp, StandardFrameConstants::kCallerFPOffset)); |
| 3294 | __ Ldr(x13, MemOperand(x12, StandardFrameConstants::kContextOffset)); |
| 3295 | __ Cmp(x13, Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR)); |
| 3296 | __ B(ne, &exit); |
| 3297 | |
| 3298 | // Arguments adaptor case: Read the arguments length from the |
| 3299 | // adaptor frame. |
| 3300 | __ Ldr(x0, MemOperand(x12, ArgumentsAdaptorFrameConstants::kLengthOffset)); |
| 3301 | |
| 3302 | __ Bind(&exit); |
| 3303 | context()->Plug(x0); |
| 3304 | } |
| 3305 | |
| 3306 | |
| 3307 | void FullCodeGenerator::EmitClassOf(CallRuntime* expr) { |
| 3308 | ASM_LOCATION("FullCodeGenerator::EmitClassOf"); |
| 3309 | ZoneList<Expression*>* args = expr->arguments(); |
| 3310 | DCHECK(args->length() == 1); |
| 3311 | Label done, null, function, non_function_constructor; |
| 3312 | |
| 3313 | VisitForAccumulatorValue(args->at(0)); |
| 3314 | |
| 3315 | // If the object is a smi, we return null. |
| 3316 | __ JumpIfSmi(x0, &null); |
| 3317 | |
| 3318 | // Check that the object is a JS object but take special care of JS |
| 3319 | // functions to make sure they have 'Function' as their class. |
| 3320 | // Assume that there are only two callable types, and one of them is at |
| 3321 | // either end of the type range for JS object types. Saves extra comparisons. |
| 3322 | STATIC_ASSERT(NUM_OF_CALLABLE_SPEC_OBJECT_TYPES == 2); |
| 3323 | __ CompareObjectType(x0, x10, x11, FIRST_SPEC_OBJECT_TYPE); |
| 3324 | // x10: object's map. |
| 3325 | // x11: object's type. |
| 3326 | __ B(lt, &null); |
| 3327 | STATIC_ASSERT(FIRST_NONCALLABLE_SPEC_OBJECT_TYPE == |
| 3328 | FIRST_SPEC_OBJECT_TYPE + 1); |
| 3329 | __ B(eq, &function); |
| 3330 | |
| 3331 | __ Cmp(x11, LAST_SPEC_OBJECT_TYPE); |
| 3332 | STATIC_ASSERT(LAST_NONCALLABLE_SPEC_OBJECT_TYPE == |
| 3333 | LAST_SPEC_OBJECT_TYPE - 1); |
| 3334 | __ B(eq, &function); |
| 3335 | // Assume that there is no larger type. |
| 3336 | STATIC_ASSERT(LAST_NONCALLABLE_SPEC_OBJECT_TYPE == LAST_TYPE - 1); |
| 3337 | |
| 3338 | // Check if the constructor in the map is a JS function. |
| 3339 | __ Ldr(x12, FieldMemOperand(x10, Map::kConstructorOffset)); |
| 3340 | __ JumpIfNotObjectType(x12, x13, x14, JS_FUNCTION_TYPE, |
| 3341 | &non_function_constructor); |
| 3342 | |
| 3343 | // x12 now contains the constructor function. Grab the |
| 3344 | // instance class name from there. |
| 3345 | __ Ldr(x13, FieldMemOperand(x12, JSFunction::kSharedFunctionInfoOffset)); |
| 3346 | __ Ldr(x0, |
| 3347 | FieldMemOperand(x13, SharedFunctionInfo::kInstanceClassNameOffset)); |
| 3348 | __ B(&done); |
| 3349 | |
| 3350 | // Functions have class 'Function'. |
| 3351 | __ Bind(&function); |
| 3352 | __ LoadRoot(x0, Heap::kFunction_stringRootIndex); |
| 3353 | __ B(&done); |
| 3354 | |
| 3355 | // Objects with a non-function constructor have class 'Object'. |
| 3356 | __ Bind(&non_function_constructor); |
| 3357 | __ LoadRoot(x0, Heap::kObject_stringRootIndex); |
| 3358 | __ B(&done); |
| 3359 | |
| 3360 | // Non-JS objects have class null. |
| 3361 | __ Bind(&null); |
| 3362 | __ LoadRoot(x0, Heap::kNullValueRootIndex); |
| 3363 | |
| 3364 | // All done. |
| 3365 | __ Bind(&done); |
| 3366 | |
| 3367 | context()->Plug(x0); |
| 3368 | } |
| 3369 | |
| 3370 | |
| 3371 | void FullCodeGenerator::EmitSubString(CallRuntime* expr) { |
| 3372 | // Load the arguments on the stack and call the stub. |
| 3373 | SubStringStub stub(isolate()); |
| 3374 | ZoneList<Expression*>* args = expr->arguments(); |
| 3375 | DCHECK(args->length() == 3); |
| 3376 | VisitForStackValue(args->at(0)); |
| 3377 | VisitForStackValue(args->at(1)); |
| 3378 | VisitForStackValue(args->at(2)); |
| 3379 | __ CallStub(&stub); |
| 3380 | context()->Plug(x0); |
| 3381 | } |
| 3382 | |
| 3383 | |
| 3384 | void FullCodeGenerator::EmitRegExpExec(CallRuntime* expr) { |
| 3385 | // Load the arguments on the stack and call the stub. |
| 3386 | RegExpExecStub stub(isolate()); |
| 3387 | ZoneList<Expression*>* args = expr->arguments(); |
| 3388 | DCHECK(args->length() == 4); |
| 3389 | VisitForStackValue(args->at(0)); |
| 3390 | VisitForStackValue(args->at(1)); |
| 3391 | VisitForStackValue(args->at(2)); |
| 3392 | VisitForStackValue(args->at(3)); |
| 3393 | __ CallStub(&stub); |
| 3394 | context()->Plug(x0); |
| 3395 | } |
| 3396 | |
| 3397 | |
| 3398 | void FullCodeGenerator::EmitValueOf(CallRuntime* expr) { |
| 3399 | ASM_LOCATION("FullCodeGenerator::EmitValueOf"); |
| 3400 | ZoneList<Expression*>* args = expr->arguments(); |
| 3401 | DCHECK(args->length() == 1); |
| 3402 | VisitForAccumulatorValue(args->at(0)); // Load the object. |
| 3403 | |
| 3404 | Label done; |
| 3405 | // If the object is a smi return the object. |
| 3406 | __ JumpIfSmi(x0, &done); |
| 3407 | // If the object is not a value type, return the object. |
| 3408 | __ JumpIfNotObjectType(x0, x10, x11, JS_VALUE_TYPE, &done); |
| 3409 | __ Ldr(x0, FieldMemOperand(x0, JSValue::kValueOffset)); |
| 3410 | |
| 3411 | __ Bind(&done); |
| 3412 | context()->Plug(x0); |
| 3413 | } |
| 3414 | |
| 3415 | |
| 3416 | void FullCodeGenerator::EmitDateField(CallRuntime* expr) { |
| 3417 | ZoneList<Expression*>* args = expr->arguments(); |
| 3418 | DCHECK(args->length() == 2); |
| 3419 | DCHECK_NE(NULL, args->at(1)->AsLiteral()); |
| 3420 | Smi* index = Smi::cast(*(args->at(1)->AsLiteral()->value())); |
| 3421 | |
| 3422 | VisitForAccumulatorValue(args->at(0)); // Load the object. |
| 3423 | |
| 3424 | Label runtime, done, not_date_object; |
| 3425 | Register object = x0; |
| 3426 | Register result = x0; |
| 3427 | Register stamp_addr = x10; |
| 3428 | Register stamp_cache = x11; |
| 3429 | |
| 3430 | __ JumpIfSmi(object, ¬_date_object); |
| 3431 | __ JumpIfNotObjectType(object, x10, x10, JS_DATE_TYPE, ¬_date_object); |
| 3432 | |
| 3433 | if (index->value() == 0) { |
| 3434 | __ Ldr(result, FieldMemOperand(object, JSDate::kValueOffset)); |
| 3435 | __ B(&done); |
| 3436 | } else { |
| 3437 | if (index->value() < JSDate::kFirstUncachedField) { |
| 3438 | ExternalReference stamp = ExternalReference::date_cache_stamp(isolate()); |
| 3439 | __ Mov(x10, stamp); |
| 3440 | __ Ldr(stamp_addr, MemOperand(x10)); |
| 3441 | __ Ldr(stamp_cache, FieldMemOperand(object, JSDate::kCacheStampOffset)); |
| 3442 | __ Cmp(stamp_addr, stamp_cache); |
| 3443 | __ B(ne, &runtime); |
| 3444 | __ Ldr(result, FieldMemOperand(object, JSDate::kValueOffset + |
| 3445 | kPointerSize * index->value())); |
| 3446 | __ B(&done); |
| 3447 | } |
| 3448 | |
| 3449 | __ Bind(&runtime); |
| 3450 | __ Mov(x1, index); |
| 3451 | __ CallCFunction(ExternalReference::get_date_field_function(isolate()), 2); |
| 3452 | __ B(&done); |
| 3453 | } |
| 3454 | |
| 3455 | __ Bind(¬_date_object); |
| 3456 | __ CallRuntime(Runtime::kThrowNotDateError, 0); |
| 3457 | __ Bind(&done); |
| 3458 | context()->Plug(x0); |
| 3459 | } |
| 3460 | |
| 3461 | |
| 3462 | void FullCodeGenerator::EmitOneByteSeqStringSetChar(CallRuntime* expr) { |
| 3463 | ZoneList<Expression*>* args = expr->arguments(); |
| 3464 | DCHECK_EQ(3, args->length()); |
| 3465 | |
| 3466 | Register string = x0; |
| 3467 | Register index = x1; |
| 3468 | Register value = x2; |
| 3469 | Register scratch = x10; |
| 3470 | |
| 3471 | VisitForStackValue(args->at(0)); // index |
| 3472 | VisitForStackValue(args->at(1)); // value |
| 3473 | VisitForAccumulatorValue(args->at(2)); // string |
| 3474 | __ Pop(value, index); |
| 3475 | |
| 3476 | if (FLAG_debug_code) { |
| 3477 | __ AssertSmi(value, kNonSmiValue); |
| 3478 | __ AssertSmi(index, kNonSmiIndex); |
| 3479 | static const uint32_t one_byte_seq_type = kSeqStringTag | kOneByteStringTag; |
| 3480 | __ EmitSeqStringSetCharCheck(string, index, kIndexIsSmi, scratch, |
| 3481 | one_byte_seq_type); |
| 3482 | } |
| 3483 | |
| 3484 | __ Add(scratch, string, SeqOneByteString::kHeaderSize - kHeapObjectTag); |
| 3485 | __ SmiUntag(value); |
| 3486 | __ SmiUntag(index); |
| 3487 | __ Strb(value, MemOperand(scratch, index)); |
| 3488 | context()->Plug(string); |
| 3489 | } |
| 3490 | |
| 3491 | |
| 3492 | void FullCodeGenerator::EmitTwoByteSeqStringSetChar(CallRuntime* expr) { |
| 3493 | ZoneList<Expression*>* args = expr->arguments(); |
| 3494 | DCHECK_EQ(3, args->length()); |
| 3495 | |
| 3496 | Register string = x0; |
| 3497 | Register index = x1; |
| 3498 | Register value = x2; |
| 3499 | Register scratch = x10; |
| 3500 | |
| 3501 | VisitForStackValue(args->at(0)); // index |
| 3502 | VisitForStackValue(args->at(1)); // value |
| 3503 | VisitForAccumulatorValue(args->at(2)); // string |
| 3504 | __ Pop(value, index); |
| 3505 | |
| 3506 | if (FLAG_debug_code) { |
| 3507 | __ AssertSmi(value, kNonSmiValue); |
| 3508 | __ AssertSmi(index, kNonSmiIndex); |
| 3509 | static const uint32_t two_byte_seq_type = kSeqStringTag | kTwoByteStringTag; |
| 3510 | __ EmitSeqStringSetCharCheck(string, index, kIndexIsSmi, scratch, |
| 3511 | two_byte_seq_type); |
| 3512 | } |
| 3513 | |
| 3514 | __ Add(scratch, string, SeqTwoByteString::kHeaderSize - kHeapObjectTag); |
| 3515 | __ SmiUntag(value); |
| 3516 | __ SmiUntag(index); |
| 3517 | __ Strh(value, MemOperand(scratch, index, LSL, 1)); |
| 3518 | context()->Plug(string); |
| 3519 | } |
| 3520 | |
| 3521 | |
| 3522 | void FullCodeGenerator::EmitMathPow(CallRuntime* expr) { |
| 3523 | // Load the arguments on the stack and call the MathPow stub. |
| 3524 | ZoneList<Expression*>* args = expr->arguments(); |
| 3525 | DCHECK(args->length() == 2); |
| 3526 | VisitForStackValue(args->at(0)); |
| 3527 | VisitForStackValue(args->at(1)); |
| 3528 | MathPowStub stub(isolate(), MathPowStub::ON_STACK); |
| 3529 | __ CallStub(&stub); |
| 3530 | context()->Plug(x0); |
| 3531 | } |
| 3532 | |
| 3533 | |
| 3534 | void FullCodeGenerator::EmitSetValueOf(CallRuntime* expr) { |
| 3535 | ZoneList<Expression*>* args = expr->arguments(); |
| 3536 | DCHECK(args->length() == 2); |
| 3537 | VisitForStackValue(args->at(0)); // Load the object. |
| 3538 | VisitForAccumulatorValue(args->at(1)); // Load the value. |
| 3539 | __ Pop(x1); |
| 3540 | // x0 = value. |
| 3541 | // x1 = object. |
| 3542 | |
| 3543 | Label done; |
| 3544 | // If the object is a smi, return the value. |
| 3545 | __ JumpIfSmi(x1, &done); |
| 3546 | |
| 3547 | // If the object is not a value type, return the value. |
| 3548 | __ JumpIfNotObjectType(x1, x10, x11, JS_VALUE_TYPE, &done); |
| 3549 | |
| 3550 | // Store the value. |
| 3551 | __ Str(x0, FieldMemOperand(x1, JSValue::kValueOffset)); |
| 3552 | // Update the write barrier. Save the value as it will be |
| 3553 | // overwritten by the write barrier code and is needed afterward. |
| 3554 | __ Mov(x10, x0); |
| 3555 | __ RecordWriteField( |
| 3556 | x1, JSValue::kValueOffset, x10, x11, kLRHasBeenSaved, kDontSaveFPRegs); |
| 3557 | |
| 3558 | __ Bind(&done); |
| 3559 | context()->Plug(x0); |
| 3560 | } |
| 3561 | |
| 3562 | |
| 3563 | void FullCodeGenerator::EmitNumberToString(CallRuntime* expr) { |
| 3564 | ZoneList<Expression*>* args = expr->arguments(); |
| 3565 | DCHECK_EQ(args->length(), 1); |
| 3566 | |
| 3567 | // Load the argument into x0 and call the stub. |
| 3568 | VisitForAccumulatorValue(args->at(0)); |
| 3569 | |
| 3570 | NumberToStringStub stub(isolate()); |
| 3571 | __ CallStub(&stub); |
| 3572 | context()->Plug(x0); |
| 3573 | } |
| 3574 | |
| 3575 | |
| 3576 | void FullCodeGenerator::EmitStringCharFromCode(CallRuntime* expr) { |
| 3577 | ZoneList<Expression*>* args = expr->arguments(); |
| 3578 | DCHECK(args->length() == 1); |
| 3579 | |
| 3580 | VisitForAccumulatorValue(args->at(0)); |
| 3581 | |
| 3582 | Label done; |
| 3583 | Register code = x0; |
| 3584 | Register result = x1; |
| 3585 | |
| 3586 | StringCharFromCodeGenerator generator(code, result); |
| 3587 | generator.GenerateFast(masm_); |
| 3588 | __ B(&done); |
| 3589 | |
| 3590 | NopRuntimeCallHelper call_helper; |
| 3591 | generator.GenerateSlow(masm_, call_helper); |
| 3592 | |
| 3593 | __ Bind(&done); |
| 3594 | context()->Plug(result); |
| 3595 | } |
| 3596 | |
| 3597 | |
| 3598 | void FullCodeGenerator::EmitStringCharCodeAt(CallRuntime* expr) { |
| 3599 | ZoneList<Expression*>* args = expr->arguments(); |
| 3600 | DCHECK(args->length() == 2); |
| 3601 | |
| 3602 | VisitForStackValue(args->at(0)); |
| 3603 | VisitForAccumulatorValue(args->at(1)); |
| 3604 | |
| 3605 | Register object = x1; |
| 3606 | Register index = x0; |
| 3607 | Register result = x3; |
| 3608 | |
| 3609 | __ Pop(object); |
| 3610 | |
| 3611 | Label need_conversion; |
| 3612 | Label index_out_of_range; |
| 3613 | Label done; |
| 3614 | StringCharCodeAtGenerator generator(object, |
| 3615 | index, |
| 3616 | result, |
| 3617 | &need_conversion, |
| 3618 | &need_conversion, |
| 3619 | &index_out_of_range, |
| 3620 | STRING_INDEX_IS_NUMBER); |
| 3621 | generator.GenerateFast(masm_); |
| 3622 | __ B(&done); |
| 3623 | |
| 3624 | __ Bind(&index_out_of_range); |
| 3625 | // When the index is out of range, the spec requires us to return NaN. |
| 3626 | __ LoadRoot(result, Heap::kNanValueRootIndex); |
| 3627 | __ B(&done); |
| 3628 | |
| 3629 | __ Bind(&need_conversion); |
| 3630 | // Load the undefined value into the result register, which will |
| 3631 | // trigger conversion. |
| 3632 | __ LoadRoot(result, Heap::kUndefinedValueRootIndex); |
| 3633 | __ B(&done); |
| 3634 | |
| 3635 | NopRuntimeCallHelper call_helper; |
| 3636 | generator.GenerateSlow(masm_, call_helper); |
| 3637 | |
| 3638 | __ Bind(&done); |
| 3639 | context()->Plug(result); |
| 3640 | } |
| 3641 | |
| 3642 | |
| 3643 | void FullCodeGenerator::EmitStringCharAt(CallRuntime* expr) { |
| 3644 | ZoneList<Expression*>* args = expr->arguments(); |
| 3645 | DCHECK(args->length() == 2); |
| 3646 | |
| 3647 | VisitForStackValue(args->at(0)); |
| 3648 | VisitForAccumulatorValue(args->at(1)); |
| 3649 | |
| 3650 | Register object = x1; |
| 3651 | Register index = x0; |
| 3652 | Register result = x0; |
| 3653 | |
| 3654 | __ Pop(object); |
| 3655 | |
| 3656 | Label need_conversion; |
| 3657 | Label index_out_of_range; |
| 3658 | Label done; |
| 3659 | StringCharAtGenerator generator(object, |
| 3660 | index, |
| 3661 | x3, |
| 3662 | result, |
| 3663 | &need_conversion, |
| 3664 | &need_conversion, |
| 3665 | &index_out_of_range, |
| 3666 | STRING_INDEX_IS_NUMBER); |
| 3667 | generator.GenerateFast(masm_); |
| 3668 | __ B(&done); |
| 3669 | |
| 3670 | __ Bind(&index_out_of_range); |
| 3671 | // When the index is out of range, the spec requires us to return |
| 3672 | // the empty string. |
| 3673 | __ LoadRoot(result, Heap::kempty_stringRootIndex); |
| 3674 | __ B(&done); |
| 3675 | |
| 3676 | __ Bind(&need_conversion); |
| 3677 | // Move smi zero into the result register, which will trigger conversion. |
| 3678 | __ Mov(result, Smi::FromInt(0)); |
| 3679 | __ B(&done); |
| 3680 | |
| 3681 | NopRuntimeCallHelper call_helper; |
| 3682 | generator.GenerateSlow(masm_, call_helper); |
| 3683 | |
| 3684 | __ Bind(&done); |
| 3685 | context()->Plug(result); |
| 3686 | } |
| 3687 | |
| 3688 | |
| 3689 | void FullCodeGenerator::EmitStringAdd(CallRuntime* expr) { |
| 3690 | ASM_LOCATION("FullCodeGenerator::EmitStringAdd"); |
| 3691 | ZoneList<Expression*>* args = expr->arguments(); |
| 3692 | DCHECK_EQ(2, args->length()); |
| 3693 | |
| 3694 | VisitForStackValue(args->at(0)); |
| 3695 | VisitForAccumulatorValue(args->at(1)); |
| 3696 | |
| 3697 | __ Pop(x1); |
| 3698 | StringAddStub stub(isolate(), STRING_ADD_CHECK_BOTH, NOT_TENURED); |
| 3699 | __ CallStub(&stub); |
| 3700 | |
| 3701 | context()->Plug(x0); |
| 3702 | } |
| 3703 | |
| 3704 | |
| 3705 | void FullCodeGenerator::EmitStringCompare(CallRuntime* expr) { |
| 3706 | ZoneList<Expression*>* args = expr->arguments(); |
| 3707 | DCHECK_EQ(2, args->length()); |
| 3708 | VisitForStackValue(args->at(0)); |
| 3709 | VisitForStackValue(args->at(1)); |
| 3710 | |
| 3711 | StringCompareStub stub(isolate()); |
| 3712 | __ CallStub(&stub); |
| 3713 | context()->Plug(x0); |
| 3714 | } |
| 3715 | |
| 3716 | |
| 3717 | void FullCodeGenerator::EmitCallFunction(CallRuntime* expr) { |
| 3718 | ASM_LOCATION("FullCodeGenerator::EmitCallFunction"); |
| 3719 | ZoneList<Expression*>* args = expr->arguments(); |
| 3720 | DCHECK(args->length() >= 2); |
| 3721 | |
| 3722 | int arg_count = args->length() - 2; // 2 ~ receiver and function. |
| 3723 | for (int i = 0; i < arg_count + 1; i++) { |
| 3724 | VisitForStackValue(args->at(i)); |
| 3725 | } |
| 3726 | VisitForAccumulatorValue(args->last()); // Function. |
| 3727 | |
| 3728 | Label runtime, done; |
| 3729 | // Check for non-function argument (including proxy). |
| 3730 | __ JumpIfSmi(x0, &runtime); |
| 3731 | __ JumpIfNotObjectType(x0, x1, x1, JS_FUNCTION_TYPE, &runtime); |
| 3732 | |
| 3733 | // InvokeFunction requires the function in x1. Move it in there. |
| 3734 | __ Mov(x1, x0); |
| 3735 | ParameterCount count(arg_count); |
| 3736 | __ InvokeFunction(x1, count, CALL_FUNCTION, NullCallWrapper()); |
| 3737 | __ Ldr(cp, MemOperand(fp, StandardFrameConstants::kContextOffset)); |
| 3738 | __ B(&done); |
| 3739 | |
| 3740 | __ Bind(&runtime); |
| 3741 | __ Push(x0); |
| 3742 | __ CallRuntime(Runtime::kCall, args->length()); |
| 3743 | __ Bind(&done); |
| 3744 | |
| 3745 | context()->Plug(x0); |
| 3746 | } |
| 3747 | |
| 3748 | |
| 3749 | void FullCodeGenerator::EmitRegExpConstructResult(CallRuntime* expr) { |
| 3750 | RegExpConstructResultStub stub(isolate()); |
| 3751 | ZoneList<Expression*>* args = expr->arguments(); |
| 3752 | DCHECK(args->length() == 3); |
| 3753 | VisitForStackValue(args->at(0)); |
| 3754 | VisitForStackValue(args->at(1)); |
| 3755 | VisitForAccumulatorValue(args->at(2)); |
| 3756 | __ Pop(x1, x2); |
| 3757 | __ CallStub(&stub); |
| 3758 | context()->Plug(x0); |
| 3759 | } |
| 3760 | |
| 3761 | |
| 3762 | void FullCodeGenerator::EmitGetFromCache(CallRuntime* expr) { |
| 3763 | ZoneList<Expression*>* args = expr->arguments(); |
| 3764 | DCHECK_EQ(2, args->length()); |
| 3765 | DCHECK_NE(NULL, args->at(0)->AsLiteral()); |
| 3766 | int cache_id = Smi::cast(*(args->at(0)->AsLiteral()->value()))->value(); |
| 3767 | |
| 3768 | Handle<FixedArray> jsfunction_result_caches( |
| 3769 | isolate()->native_context()->jsfunction_result_caches()); |
| 3770 | if (jsfunction_result_caches->length() <= cache_id) { |
| 3771 | __ Abort(kAttemptToUseUndefinedCache); |
| 3772 | __ LoadRoot(x0, Heap::kUndefinedValueRootIndex); |
| 3773 | context()->Plug(x0); |
| 3774 | return; |
| 3775 | } |
| 3776 | |
| 3777 | VisitForAccumulatorValue(args->at(1)); |
| 3778 | |
| 3779 | Register key = x0; |
| 3780 | Register cache = x1; |
| 3781 | __ Ldr(cache, GlobalObjectMemOperand()); |
| 3782 | __ Ldr(cache, FieldMemOperand(cache, GlobalObject::kNativeContextOffset)); |
| 3783 | __ Ldr(cache, ContextMemOperand(cache, |
| 3784 | Context::JSFUNCTION_RESULT_CACHES_INDEX)); |
| 3785 | __ Ldr(cache, |
| 3786 | FieldMemOperand(cache, FixedArray::OffsetOfElementAt(cache_id))); |
| 3787 | |
| 3788 | Label done; |
| 3789 | __ Ldrsw(x2, UntagSmiFieldMemOperand(cache, |
| 3790 | JSFunctionResultCache::kFingerOffset)); |
| 3791 | __ Add(x3, cache, FixedArray::kHeaderSize - kHeapObjectTag); |
| 3792 | __ Add(x3, x3, Operand(x2, LSL, kPointerSizeLog2)); |
| 3793 | |
| 3794 | // Load the key and data from the cache. |
| 3795 | __ Ldp(x2, x3, MemOperand(x3)); |
| 3796 | |
| 3797 | __ Cmp(key, x2); |
| 3798 | __ CmovX(x0, x3, eq); |
| 3799 | __ B(eq, &done); |
| 3800 | |
| 3801 | // Call runtime to perform the lookup. |
| 3802 | __ Push(cache, key); |
| 3803 | __ CallRuntime(Runtime::kGetFromCache, 2); |
| 3804 | |
| 3805 | __ Bind(&done); |
| 3806 | context()->Plug(x0); |
| 3807 | } |
| 3808 | |
| 3809 | |
| 3810 | void FullCodeGenerator::EmitHasCachedArrayIndex(CallRuntime* expr) { |
| 3811 | ZoneList<Expression*>* args = expr->arguments(); |
| 3812 | VisitForAccumulatorValue(args->at(0)); |
| 3813 | |
| 3814 | Label materialize_true, materialize_false; |
| 3815 | Label* if_true = NULL; |
| 3816 | Label* if_false = NULL; |
| 3817 | Label* fall_through = NULL; |
| 3818 | context()->PrepareTest(&materialize_true, &materialize_false, |
| 3819 | &if_true, &if_false, &fall_through); |
| 3820 | |
| 3821 | __ Ldr(x10, FieldMemOperand(x0, String::kHashFieldOffset)); |
| 3822 | __ Tst(x10, String::kContainsCachedArrayIndexMask); |
| 3823 | PrepareForBailoutBeforeSplit(expr, true, if_true, if_false); |
| 3824 | Split(eq, if_true, if_false, fall_through); |
| 3825 | |
| 3826 | context()->Plug(if_true, if_false); |
| 3827 | } |
| 3828 | |
| 3829 | |
| 3830 | void FullCodeGenerator::EmitGetCachedArrayIndex(CallRuntime* expr) { |
| 3831 | ZoneList<Expression*>* args = expr->arguments(); |
| 3832 | DCHECK(args->length() == 1); |
| 3833 | VisitForAccumulatorValue(args->at(0)); |
| 3834 | |
| 3835 | __ AssertString(x0); |
| 3836 | |
| 3837 | __ Ldr(x10, FieldMemOperand(x0, String::kHashFieldOffset)); |
| 3838 | __ IndexFromHash(x10, x0); |
| 3839 | |
| 3840 | context()->Plug(x0); |
| 3841 | } |
| 3842 | |
| 3843 | |
| 3844 | void FullCodeGenerator::EmitFastOneByteArrayJoin(CallRuntime* expr) { |
| 3845 | ASM_LOCATION("FullCodeGenerator::EmitFastOneByteArrayJoin"); |
| 3846 | |
| 3847 | ZoneList<Expression*>* args = expr->arguments(); |
| 3848 | DCHECK(args->length() == 2); |
| 3849 | VisitForStackValue(args->at(1)); |
| 3850 | VisitForAccumulatorValue(args->at(0)); |
| 3851 | |
| 3852 | Register array = x0; |
| 3853 | Register result = x0; |
| 3854 | Register elements = x1; |
| 3855 | Register element = x2; |
| 3856 | Register separator = x3; |
| 3857 | Register array_length = x4; |
| 3858 | Register result_pos = x5; |
| 3859 | Register map = x6; |
| 3860 | Register string_length = x10; |
| 3861 | Register elements_end = x11; |
| 3862 | Register string = x12; |
| 3863 | Register scratch1 = x13; |
| 3864 | Register scratch2 = x14; |
| 3865 | Register scratch3 = x7; |
| 3866 | Register separator_length = x15; |
| 3867 | |
| 3868 | Label bailout, done, one_char_separator, long_separator, |
| 3869 | non_trivial_array, not_size_one_array, loop, |
| 3870 | empty_separator_loop, one_char_separator_loop, |
| 3871 | one_char_separator_loop_entry, long_separator_loop; |
| 3872 | |
| 3873 | // The separator operand is on the stack. |
| 3874 | __ Pop(separator); |
| 3875 | |
| 3876 | // Check that the array is a JSArray. |
| 3877 | __ JumpIfSmi(array, &bailout); |
| 3878 | __ JumpIfNotObjectType(array, map, scratch1, JS_ARRAY_TYPE, &bailout); |
| 3879 | |
| 3880 | // Check that the array has fast elements. |
| 3881 | __ CheckFastElements(map, scratch1, &bailout); |
| 3882 | |
| 3883 | // If the array has length zero, return the empty string. |
| 3884 | // Load and untag the length of the array. |
| 3885 | // It is an unsigned value, so we can skip sign extension. |
| 3886 | // We assume little endianness. |
| 3887 | __ Ldrsw(array_length, |
| 3888 | UntagSmiFieldMemOperand(array, JSArray::kLengthOffset)); |
| 3889 | __ Cbnz(array_length, &non_trivial_array); |
| 3890 | __ LoadRoot(result, Heap::kempty_stringRootIndex); |
| 3891 | __ B(&done); |
| 3892 | |
| 3893 | __ Bind(&non_trivial_array); |
| 3894 | // Get the FixedArray containing array's elements. |
| 3895 | __ Ldr(elements, FieldMemOperand(array, JSArray::kElementsOffset)); |
| 3896 | |
| 3897 | // Check that all array elements are sequential one-byte strings, and |
| 3898 | // accumulate the sum of their lengths. |
| 3899 | __ Mov(string_length, 0); |
| 3900 | __ Add(element, elements, FixedArray::kHeaderSize - kHeapObjectTag); |
| 3901 | __ Add(elements_end, element, Operand(array_length, LSL, kPointerSizeLog2)); |
| 3902 | // Loop condition: while (element < elements_end). |
| 3903 | // Live values in registers: |
| 3904 | // elements: Fixed array of strings. |
| 3905 | // array_length: Length of the fixed array of strings (not smi) |
| 3906 | // separator: Separator string |
| 3907 | // string_length: Accumulated sum of string lengths (not smi). |
| 3908 | // element: Current array element. |
| 3909 | // elements_end: Array end. |
| 3910 | if (FLAG_debug_code) { |
| 3911 | __ Cmp(array_length, 0); |
| 3912 | __ Assert(gt, kNoEmptyArraysHereInEmitFastOneByteArrayJoin); |
| 3913 | } |
| 3914 | __ Bind(&loop); |
| 3915 | __ Ldr(string, MemOperand(element, kPointerSize, PostIndex)); |
| 3916 | __ JumpIfSmi(string, &bailout); |
| 3917 | __ Ldr(scratch1, FieldMemOperand(string, HeapObject::kMapOffset)); |
| 3918 | __ Ldrb(scratch1, FieldMemOperand(scratch1, Map::kInstanceTypeOffset)); |
| 3919 | __ JumpIfInstanceTypeIsNotSequentialOneByte(scratch1, scratch2, &bailout); |
| 3920 | __ Ldrsw(scratch1, |
| 3921 | UntagSmiFieldMemOperand(string, SeqOneByteString::kLengthOffset)); |
| 3922 | __ Adds(string_length, string_length, scratch1); |
| 3923 | __ B(vs, &bailout); |
| 3924 | __ Cmp(element, elements_end); |
| 3925 | __ B(lt, &loop); |
| 3926 | |
| 3927 | // If array_length is 1, return elements[0], a string. |
| 3928 | __ Cmp(array_length, 1); |
| 3929 | __ B(ne, ¬_size_one_array); |
| 3930 | __ Ldr(result, FieldMemOperand(elements, FixedArray::kHeaderSize)); |
| 3931 | __ B(&done); |
| 3932 | |
| 3933 | __ Bind(¬_size_one_array); |
| 3934 | |
| 3935 | // Live values in registers: |
| 3936 | // separator: Separator string |
| 3937 | // array_length: Length of the array (not smi). |
| 3938 | // string_length: Sum of string lengths (not smi). |
| 3939 | // elements: FixedArray of strings. |
| 3940 | |
| 3941 | // Check that the separator is a flat one-byte string. |
| 3942 | __ JumpIfSmi(separator, &bailout); |
| 3943 | __ Ldr(scratch1, FieldMemOperand(separator, HeapObject::kMapOffset)); |
| 3944 | __ Ldrb(scratch1, FieldMemOperand(scratch1, Map::kInstanceTypeOffset)); |
| 3945 | __ JumpIfInstanceTypeIsNotSequentialOneByte(scratch1, scratch2, &bailout); |
| 3946 | |
| 3947 | // Add (separator length times array_length) - separator length to the |
| 3948 | // string_length to get the length of the result string. |
| 3949 | // Load the separator length as untagged. |
| 3950 | // We assume little endianness, and that the length is positive. |
| 3951 | __ Ldrsw(separator_length, |
| 3952 | UntagSmiFieldMemOperand(separator, |
| 3953 | SeqOneByteString::kLengthOffset)); |
| 3954 | __ Sub(string_length, string_length, separator_length); |
| 3955 | __ Umaddl(string_length, array_length.W(), separator_length.W(), |
| 3956 | string_length); |
| 3957 | |
| 3958 | // Get first element in the array. |
| 3959 | __ Add(element, elements, FixedArray::kHeaderSize - kHeapObjectTag); |
| 3960 | // Live values in registers: |
| 3961 | // element: First array element |
| 3962 | // separator: Separator string |
| 3963 | // string_length: Length of result string (not smi) |
| 3964 | // array_length: Length of the array (not smi). |
| 3965 | __ AllocateOneByteString(result, string_length, scratch1, scratch2, scratch3, |
| 3966 | &bailout); |
| 3967 | |
| 3968 | // Prepare for looping. Set up elements_end to end of the array. Set |
| 3969 | // result_pos to the position of the result where to write the first |
| 3970 | // character. |
| 3971 | // TODO(all): useless unless AllocateOneByteString trashes the register. |
| 3972 | __ Add(elements_end, element, Operand(array_length, LSL, kPointerSizeLog2)); |
| 3973 | __ Add(result_pos, result, SeqOneByteString::kHeaderSize - kHeapObjectTag); |
| 3974 | |
| 3975 | // Check the length of the separator. |
| 3976 | __ Cmp(separator_length, 1); |
| 3977 | __ B(eq, &one_char_separator); |
| 3978 | __ B(gt, &long_separator); |
| 3979 | |
| 3980 | // Empty separator case |
| 3981 | __ Bind(&empty_separator_loop); |
| 3982 | // Live values in registers: |
| 3983 | // result_pos: the position to which we are currently copying characters. |
| 3984 | // element: Current array element. |
| 3985 | // elements_end: Array end. |
| 3986 | |
| 3987 | // Copy next array element to the result. |
| 3988 | __ Ldr(string, MemOperand(element, kPointerSize, PostIndex)); |
| 3989 | __ Ldrsw(string_length, |
| 3990 | UntagSmiFieldMemOperand(string, String::kLengthOffset)); |
| 3991 | __ Add(string, string, SeqOneByteString::kHeaderSize - kHeapObjectTag); |
| 3992 | __ CopyBytes(result_pos, string, string_length, scratch1); |
| 3993 | __ Cmp(element, elements_end); |
| 3994 | __ B(lt, &empty_separator_loop); // End while (element < elements_end). |
| 3995 | __ B(&done); |
| 3996 | |
| 3997 | // One-character separator case |
| 3998 | __ Bind(&one_char_separator); |
| 3999 | // Replace separator with its one-byte character value. |
| 4000 | __ Ldrb(separator, FieldMemOperand(separator, SeqOneByteString::kHeaderSize)); |
| 4001 | // Jump into the loop after the code that copies the separator, so the first |
| 4002 | // element is not preceded by a separator |
| 4003 | __ B(&one_char_separator_loop_entry); |
| 4004 | |
| 4005 | __ Bind(&one_char_separator_loop); |
| 4006 | // Live values in registers: |
| 4007 | // result_pos: the position to which we are currently copying characters. |
| 4008 | // element: Current array element. |
| 4009 | // elements_end: Array end. |
| 4010 | // separator: Single separator one-byte char (in lower byte). |
| 4011 | |
| 4012 | // Copy the separator character to the result. |
| 4013 | __ Strb(separator, MemOperand(result_pos, 1, PostIndex)); |
| 4014 | |
| 4015 | // Copy next array element to the result. |
| 4016 | __ Bind(&one_char_separator_loop_entry); |
| 4017 | __ Ldr(string, MemOperand(element, kPointerSize, PostIndex)); |
| 4018 | __ Ldrsw(string_length, |
| 4019 | UntagSmiFieldMemOperand(string, String::kLengthOffset)); |
| 4020 | __ Add(string, string, SeqOneByteString::kHeaderSize - kHeapObjectTag); |
| 4021 | __ CopyBytes(result_pos, string, string_length, scratch1); |
| 4022 | __ Cmp(element, elements_end); |
| 4023 | __ B(lt, &one_char_separator_loop); // End while (element < elements_end). |
| 4024 | __ B(&done); |
| 4025 | |
| 4026 | // Long separator case (separator is more than one character). Entry is at the |
| 4027 | // label long_separator below. |
| 4028 | __ Bind(&long_separator_loop); |
| 4029 | // Live values in registers: |
| 4030 | // result_pos: the position to which we are currently copying characters. |
| 4031 | // element: Current array element. |
| 4032 | // elements_end: Array end. |
| 4033 | // separator: Separator string. |
| 4034 | |
| 4035 | // Copy the separator to the result. |
| 4036 | // TODO(all): hoist next two instructions. |
| 4037 | __ Ldrsw(string_length, |
| 4038 | UntagSmiFieldMemOperand(separator, String::kLengthOffset)); |
| 4039 | __ Add(string, separator, SeqOneByteString::kHeaderSize - kHeapObjectTag); |
| 4040 | __ CopyBytes(result_pos, string, string_length, scratch1); |
| 4041 | |
| 4042 | __ Bind(&long_separator); |
| 4043 | __ Ldr(string, MemOperand(element, kPointerSize, PostIndex)); |
| 4044 | __ Ldrsw(string_length, |
| 4045 | UntagSmiFieldMemOperand(string, String::kLengthOffset)); |
| 4046 | __ Add(string, string, SeqOneByteString::kHeaderSize - kHeapObjectTag); |
| 4047 | __ CopyBytes(result_pos, string, string_length, scratch1); |
| 4048 | __ Cmp(element, elements_end); |
| 4049 | __ B(lt, &long_separator_loop); // End while (element < elements_end). |
| 4050 | __ B(&done); |
| 4051 | |
| 4052 | __ Bind(&bailout); |
| 4053 | // Returning undefined will force slower code to handle it. |
| 4054 | __ LoadRoot(result, Heap::kUndefinedValueRootIndex); |
| 4055 | __ Bind(&done); |
| 4056 | context()->Plug(result); |
| 4057 | } |
| 4058 | |
| 4059 | |
| 4060 | void FullCodeGenerator::EmitDebugIsActive(CallRuntime* expr) { |
| 4061 | DCHECK(expr->arguments()->length() == 0); |
| 4062 | ExternalReference debug_is_active = |
| 4063 | ExternalReference::debug_is_active_address(isolate()); |
| 4064 | __ Mov(x10, debug_is_active); |
| 4065 | __ Ldrb(x0, MemOperand(x10)); |
| 4066 | __ SmiTag(x0); |
| 4067 | context()->Plug(x0); |
| 4068 | } |
| 4069 | |
| 4070 | |
| 4071 | void FullCodeGenerator::VisitCallRuntime(CallRuntime* expr) { |
| 4072 | if (expr->function() != NULL && |
| 4073 | expr->function()->intrinsic_type == Runtime::INLINE) { |
| 4074 | Comment cmnt(masm_, "[ InlineRuntimeCall"); |
| 4075 | EmitInlineRuntimeCall(expr); |
| 4076 | return; |
| 4077 | } |
| 4078 | |
| 4079 | Comment cmnt(masm_, "[ CallRunTime"); |
| 4080 | ZoneList<Expression*>* args = expr->arguments(); |
| 4081 | int arg_count = args->length(); |
| 4082 | |
| 4083 | if (expr->is_jsruntime()) { |
| 4084 | // Push the builtins object as the receiver. |
| 4085 | __ Ldr(x10, GlobalObjectMemOperand()); |
| 4086 | __ Ldr(LoadDescriptor::ReceiverRegister(), |
| 4087 | FieldMemOperand(x10, GlobalObject::kBuiltinsOffset)); |
| 4088 | __ Push(LoadDescriptor::ReceiverRegister()); |
| 4089 | |
| 4090 | // Load the function from the receiver. |
| 4091 | Handle<String> name = expr->name(); |
| 4092 | __ Mov(LoadDescriptor::NameRegister(), Operand(name)); |
| 4093 | if (FLAG_vector_ics) { |
| 4094 | __ Mov(VectorLoadICDescriptor::SlotRegister(), |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 4095 | SmiFromSlot(expr->CallRuntimeFeedbackSlot())); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4096 | CallLoadIC(NOT_CONTEXTUAL); |
| 4097 | } else { |
| 4098 | CallLoadIC(NOT_CONTEXTUAL, expr->CallRuntimeFeedbackId()); |
| 4099 | } |
| 4100 | |
| 4101 | // Push the target function under the receiver. |
| 4102 | __ Pop(x10); |
| 4103 | __ Push(x0, x10); |
| 4104 | |
| 4105 | int arg_count = args->length(); |
| 4106 | for (int i = 0; i < arg_count; i++) { |
| 4107 | VisitForStackValue(args->at(i)); |
| 4108 | } |
| 4109 | |
| 4110 | // Record source position of the IC call. |
| 4111 | SetSourcePosition(expr->position()); |
| 4112 | CallFunctionStub stub(isolate(), arg_count, NO_CALL_FUNCTION_FLAGS); |
| 4113 | __ Peek(x1, (arg_count + 1) * kPointerSize); |
| 4114 | __ CallStub(&stub); |
| 4115 | |
| 4116 | // Restore context register. |
| 4117 | __ Ldr(cp, MemOperand(fp, StandardFrameConstants::kContextOffset)); |
| 4118 | |
| 4119 | context()->DropAndPlug(1, x0); |
| 4120 | } else { |
| 4121 | // Push the arguments ("left-to-right"). |
| 4122 | for (int i = 0; i < arg_count; i++) { |
| 4123 | VisitForStackValue(args->at(i)); |
| 4124 | } |
| 4125 | |
| 4126 | // Call the C runtime function. |
| 4127 | __ CallRuntime(expr->function(), arg_count); |
| 4128 | context()->Plug(x0); |
| 4129 | } |
| 4130 | } |
| 4131 | |
| 4132 | |
| 4133 | void FullCodeGenerator::VisitUnaryOperation(UnaryOperation* expr) { |
| 4134 | switch (expr->op()) { |
| 4135 | case Token::DELETE: { |
| 4136 | Comment cmnt(masm_, "[ UnaryOperation (DELETE)"); |
| 4137 | Property* property = expr->expression()->AsProperty(); |
| 4138 | VariableProxy* proxy = expr->expression()->AsVariableProxy(); |
| 4139 | |
| 4140 | if (property != NULL) { |
| 4141 | VisitForStackValue(property->obj()); |
| 4142 | VisitForStackValue(property->key()); |
| 4143 | __ Mov(x10, Smi::FromInt(strict_mode())); |
| 4144 | __ Push(x10); |
| 4145 | __ InvokeBuiltin(Builtins::DELETE, CALL_FUNCTION); |
| 4146 | context()->Plug(x0); |
| 4147 | } else if (proxy != NULL) { |
| 4148 | Variable* var = proxy->var(); |
| 4149 | // Delete of an unqualified identifier is disallowed in strict mode |
| 4150 | // but "delete this" is allowed. |
| 4151 | DCHECK(strict_mode() == SLOPPY || var->is_this()); |
| 4152 | if (var->IsUnallocated()) { |
| 4153 | __ Ldr(x12, GlobalObjectMemOperand()); |
| 4154 | __ Mov(x11, Operand(var->name())); |
| 4155 | __ Mov(x10, Smi::FromInt(SLOPPY)); |
| 4156 | __ Push(x12, x11, x10); |
| 4157 | __ InvokeBuiltin(Builtins::DELETE, CALL_FUNCTION); |
| 4158 | context()->Plug(x0); |
| 4159 | } else if (var->IsStackAllocated() || var->IsContextSlot()) { |
| 4160 | // Result of deleting non-global, non-dynamic variables is false. |
| 4161 | // The subexpression does not have side effects. |
| 4162 | context()->Plug(var->is_this()); |
| 4163 | } else { |
| 4164 | // Non-global variable. Call the runtime to try to delete from the |
| 4165 | // context where the variable was introduced. |
| 4166 | __ Mov(x2, Operand(var->name())); |
| 4167 | __ Push(context_register(), x2); |
| 4168 | __ CallRuntime(Runtime::kDeleteLookupSlot, 2); |
| 4169 | context()->Plug(x0); |
| 4170 | } |
| 4171 | } else { |
| 4172 | // Result of deleting non-property, non-variable reference is true. |
| 4173 | // The subexpression may have side effects. |
| 4174 | VisitForEffect(expr->expression()); |
| 4175 | context()->Plug(true); |
| 4176 | } |
| 4177 | break; |
| 4178 | break; |
| 4179 | } |
| 4180 | case Token::VOID: { |
| 4181 | Comment cmnt(masm_, "[ UnaryOperation (VOID)"); |
| 4182 | VisitForEffect(expr->expression()); |
| 4183 | context()->Plug(Heap::kUndefinedValueRootIndex); |
| 4184 | break; |
| 4185 | } |
| 4186 | case Token::NOT: { |
| 4187 | Comment cmnt(masm_, "[ UnaryOperation (NOT)"); |
| 4188 | if (context()->IsEffect()) { |
| 4189 | // Unary NOT has no side effects so it's only necessary to visit the |
| 4190 | // subexpression. Match the optimizing compiler by not branching. |
| 4191 | VisitForEffect(expr->expression()); |
| 4192 | } else if (context()->IsTest()) { |
| 4193 | const TestContext* test = TestContext::cast(context()); |
| 4194 | // The labels are swapped for the recursive call. |
| 4195 | VisitForControl(expr->expression(), |
| 4196 | test->false_label(), |
| 4197 | test->true_label(), |
| 4198 | test->fall_through()); |
| 4199 | context()->Plug(test->true_label(), test->false_label()); |
| 4200 | } else { |
| 4201 | DCHECK(context()->IsAccumulatorValue() || context()->IsStackValue()); |
| 4202 | // TODO(jbramley): This could be much more efficient using (for |
| 4203 | // example) the CSEL instruction. |
| 4204 | Label materialize_true, materialize_false, done; |
| 4205 | VisitForControl(expr->expression(), |
| 4206 | &materialize_false, |
| 4207 | &materialize_true, |
| 4208 | &materialize_true); |
| 4209 | |
| 4210 | __ Bind(&materialize_true); |
| 4211 | PrepareForBailoutForId(expr->MaterializeTrueId(), NO_REGISTERS); |
| 4212 | __ LoadRoot(result_register(), Heap::kTrueValueRootIndex); |
| 4213 | __ B(&done); |
| 4214 | |
| 4215 | __ Bind(&materialize_false); |
| 4216 | PrepareForBailoutForId(expr->MaterializeFalseId(), NO_REGISTERS); |
| 4217 | __ LoadRoot(result_register(), Heap::kFalseValueRootIndex); |
| 4218 | __ B(&done); |
| 4219 | |
| 4220 | __ Bind(&done); |
| 4221 | if (context()->IsStackValue()) { |
| 4222 | __ Push(result_register()); |
| 4223 | } |
| 4224 | } |
| 4225 | break; |
| 4226 | } |
| 4227 | case Token::TYPEOF: { |
| 4228 | Comment cmnt(masm_, "[ UnaryOperation (TYPEOF)"); |
| 4229 | { |
| 4230 | StackValueContext context(this); |
| 4231 | VisitForTypeofValue(expr->expression()); |
| 4232 | } |
| 4233 | __ CallRuntime(Runtime::kTypeof, 1); |
| 4234 | context()->Plug(x0); |
| 4235 | break; |
| 4236 | } |
| 4237 | default: |
| 4238 | UNREACHABLE(); |
| 4239 | } |
| 4240 | } |
| 4241 | |
| 4242 | |
| 4243 | void FullCodeGenerator::VisitCountOperation(CountOperation* expr) { |
| 4244 | DCHECK(expr->expression()->IsValidReferenceExpression()); |
| 4245 | |
| 4246 | Comment cmnt(masm_, "[ CountOperation"); |
| 4247 | SetSourcePosition(expr->position()); |
| 4248 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4249 | Property* prop = expr->expression()->AsProperty(); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 4250 | LhsKind assign_type = GetAssignType(prop); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4251 | |
| 4252 | // Evaluate expression and get value. |
| 4253 | if (assign_type == VARIABLE) { |
| 4254 | DCHECK(expr->expression()->AsVariableProxy()->var() != NULL); |
| 4255 | AccumulatorValueContext context(this); |
| 4256 | EmitVariableLoad(expr->expression()->AsVariableProxy()); |
| 4257 | } else { |
| 4258 | // Reserve space for result of postfix operation. |
| 4259 | if (expr->is_postfix() && !context()->IsEffect()) { |
| 4260 | __ Push(xzr); |
| 4261 | } |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 4262 | switch (assign_type) { |
| 4263 | case NAMED_PROPERTY: { |
| 4264 | // Put the object both on the stack and in the register. |
| 4265 | VisitForStackValue(prop->obj()); |
| 4266 | __ Peek(LoadDescriptor::ReceiverRegister(), 0); |
| 4267 | EmitNamedPropertyLoad(prop); |
| 4268 | break; |
| 4269 | } |
| 4270 | |
| 4271 | case NAMED_SUPER_PROPERTY: { |
| 4272 | VisitForStackValue(prop->obj()->AsSuperReference()->this_var()); |
| 4273 | EmitLoadHomeObject(prop->obj()->AsSuperReference()); |
| 4274 | __ Push(result_register()); |
| 4275 | const Register scratch = x10; |
| 4276 | __ Peek(scratch, kPointerSize); |
| 4277 | __ Push(scratch, result_register()); |
| 4278 | EmitNamedSuperPropertyLoad(prop); |
| 4279 | break; |
| 4280 | } |
| 4281 | |
| 4282 | case KEYED_SUPER_PROPERTY: { |
| 4283 | VisitForStackValue(prop->obj()->AsSuperReference()->this_var()); |
| 4284 | EmitLoadHomeObject(prop->obj()->AsSuperReference()); |
| 4285 | __ Push(result_register()); |
| 4286 | VisitForAccumulatorValue(prop->key()); |
| 4287 | __ Push(result_register()); |
| 4288 | const Register scratch1 = x10; |
| 4289 | const Register scratch2 = x11; |
| 4290 | __ Peek(scratch1, 2 * kPointerSize); |
| 4291 | __ Peek(scratch2, kPointerSize); |
| 4292 | __ Push(scratch1, scratch2, result_register()); |
| 4293 | EmitKeyedSuperPropertyLoad(prop); |
| 4294 | break; |
| 4295 | } |
| 4296 | |
| 4297 | case KEYED_PROPERTY: { |
| 4298 | VisitForStackValue(prop->obj()); |
| 4299 | VisitForStackValue(prop->key()); |
| 4300 | __ Peek(LoadDescriptor::ReceiverRegister(), 1 * kPointerSize); |
| 4301 | __ Peek(LoadDescriptor::NameRegister(), 0); |
| 4302 | EmitKeyedPropertyLoad(prop); |
| 4303 | break; |
| 4304 | } |
| 4305 | |
| 4306 | case VARIABLE: |
| 4307 | UNREACHABLE(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4308 | } |
| 4309 | } |
| 4310 | |
| 4311 | // We need a second deoptimization point after loading the value |
| 4312 | // in case evaluating the property load my have a side effect. |
| 4313 | if (assign_type == VARIABLE) { |
| 4314 | PrepareForBailout(expr->expression(), TOS_REG); |
| 4315 | } else { |
| 4316 | PrepareForBailoutForId(prop->LoadId(), TOS_REG); |
| 4317 | } |
| 4318 | |
| 4319 | // Inline smi case if we are in a loop. |
| 4320 | Label stub_call, done; |
| 4321 | JumpPatchSite patch_site(masm_); |
| 4322 | |
| 4323 | int count_value = expr->op() == Token::INC ? 1 : -1; |
| 4324 | if (ShouldInlineSmiCase(expr->op())) { |
| 4325 | Label slow; |
| 4326 | patch_site.EmitJumpIfNotSmi(x0, &slow); |
| 4327 | |
| 4328 | // Save result for postfix expressions. |
| 4329 | if (expr->is_postfix()) { |
| 4330 | if (!context()->IsEffect()) { |
| 4331 | // Save the result on the stack. If we have a named or keyed property we |
| 4332 | // store the result under the receiver that is currently on top of the |
| 4333 | // stack. |
| 4334 | switch (assign_type) { |
| 4335 | case VARIABLE: |
| 4336 | __ Push(x0); |
| 4337 | break; |
| 4338 | case NAMED_PROPERTY: |
| 4339 | __ Poke(x0, kPointerSize); |
| 4340 | break; |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 4341 | case NAMED_SUPER_PROPERTY: |
| 4342 | __ Poke(x0, kPointerSize * 2); |
| 4343 | break; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4344 | case KEYED_PROPERTY: |
| 4345 | __ Poke(x0, kPointerSize * 2); |
| 4346 | break; |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 4347 | case KEYED_SUPER_PROPERTY: |
| 4348 | __ Poke(x0, kPointerSize * 3); |
| 4349 | break; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4350 | } |
| 4351 | } |
| 4352 | } |
| 4353 | |
| 4354 | __ Adds(x0, x0, Smi::FromInt(count_value)); |
| 4355 | __ B(vc, &done); |
| 4356 | // Call stub. Undo operation first. |
| 4357 | __ Sub(x0, x0, Smi::FromInt(count_value)); |
| 4358 | __ B(&stub_call); |
| 4359 | __ Bind(&slow); |
| 4360 | } |
| 4361 | ToNumberStub convert_stub(isolate()); |
| 4362 | __ CallStub(&convert_stub); |
| 4363 | |
| 4364 | // Save result for postfix expressions. |
| 4365 | if (expr->is_postfix()) { |
| 4366 | if (!context()->IsEffect()) { |
| 4367 | // Save the result on the stack. If we have a named or keyed property |
| 4368 | // we store the result under the receiver that is currently on top |
| 4369 | // of the stack. |
| 4370 | switch (assign_type) { |
| 4371 | case VARIABLE: |
| 4372 | __ Push(x0); |
| 4373 | break; |
| 4374 | case NAMED_PROPERTY: |
| 4375 | __ Poke(x0, kXRegSize); |
| 4376 | break; |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 4377 | case NAMED_SUPER_PROPERTY: |
| 4378 | __ Poke(x0, 2 * kXRegSize); |
| 4379 | break; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4380 | case KEYED_PROPERTY: |
| 4381 | __ Poke(x0, 2 * kXRegSize); |
| 4382 | break; |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 4383 | case KEYED_SUPER_PROPERTY: |
| 4384 | __ Poke(x0, 3 * kXRegSize); |
| 4385 | break; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4386 | } |
| 4387 | } |
| 4388 | } |
| 4389 | |
| 4390 | __ Bind(&stub_call); |
| 4391 | __ Mov(x1, x0); |
| 4392 | __ Mov(x0, Smi::FromInt(count_value)); |
| 4393 | |
| 4394 | // Record position before stub call. |
| 4395 | SetSourcePosition(expr->position()); |
| 4396 | |
| 4397 | { |
| 4398 | Assembler::BlockPoolsScope scope(masm_); |
| 4399 | Handle<Code> code = |
| 4400 | CodeFactory::BinaryOpIC(isolate(), Token::ADD, NO_OVERWRITE).code(); |
| 4401 | CallIC(code, expr->CountBinOpFeedbackId()); |
| 4402 | patch_site.EmitPatchInfo(); |
| 4403 | } |
| 4404 | __ Bind(&done); |
| 4405 | |
| 4406 | // Store the value returned in x0. |
| 4407 | switch (assign_type) { |
| 4408 | case VARIABLE: |
| 4409 | if (expr->is_postfix()) { |
| 4410 | { EffectContext context(this); |
| 4411 | EmitVariableAssignment(expr->expression()->AsVariableProxy()->var(), |
| 4412 | Token::ASSIGN); |
| 4413 | PrepareForBailoutForId(expr->AssignmentId(), TOS_REG); |
| 4414 | context.Plug(x0); |
| 4415 | } |
| 4416 | // For all contexts except EffectConstant We have the result on |
| 4417 | // top of the stack. |
| 4418 | if (!context()->IsEffect()) { |
| 4419 | context()->PlugTOS(); |
| 4420 | } |
| 4421 | } else { |
| 4422 | EmitVariableAssignment(expr->expression()->AsVariableProxy()->var(), |
| 4423 | Token::ASSIGN); |
| 4424 | PrepareForBailoutForId(expr->AssignmentId(), TOS_REG); |
| 4425 | context()->Plug(x0); |
| 4426 | } |
| 4427 | break; |
| 4428 | case NAMED_PROPERTY: { |
| 4429 | __ Mov(StoreDescriptor::NameRegister(), |
| 4430 | Operand(prop->key()->AsLiteral()->value())); |
| 4431 | __ Pop(StoreDescriptor::ReceiverRegister()); |
| 4432 | CallStoreIC(expr->CountStoreFeedbackId()); |
| 4433 | PrepareForBailoutForId(expr->AssignmentId(), TOS_REG); |
| 4434 | if (expr->is_postfix()) { |
| 4435 | if (!context()->IsEffect()) { |
| 4436 | context()->PlugTOS(); |
| 4437 | } |
| 4438 | } else { |
| 4439 | context()->Plug(x0); |
| 4440 | } |
| 4441 | break; |
| 4442 | } |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 4443 | case NAMED_SUPER_PROPERTY: { |
| 4444 | EmitNamedSuperPropertyStore(prop); |
| 4445 | if (expr->is_postfix()) { |
| 4446 | if (!context()->IsEffect()) { |
| 4447 | context()->PlugTOS(); |
| 4448 | } |
| 4449 | } else { |
| 4450 | context()->Plug(x0); |
| 4451 | } |
| 4452 | break; |
| 4453 | } |
| 4454 | case KEYED_SUPER_PROPERTY: { |
| 4455 | EmitKeyedSuperPropertyStore(prop); |
| 4456 | if (expr->is_postfix()) { |
| 4457 | if (!context()->IsEffect()) { |
| 4458 | context()->PlugTOS(); |
| 4459 | } |
| 4460 | } else { |
| 4461 | context()->Plug(x0); |
| 4462 | } |
| 4463 | break; |
| 4464 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4465 | case KEYED_PROPERTY: { |
| 4466 | __ Pop(StoreDescriptor::NameRegister()); |
| 4467 | __ Pop(StoreDescriptor::ReceiverRegister()); |
| 4468 | Handle<Code> ic = |
| 4469 | CodeFactory::KeyedStoreIC(isolate(), strict_mode()).code(); |
| 4470 | CallIC(ic, expr->CountStoreFeedbackId()); |
| 4471 | PrepareForBailoutForId(expr->AssignmentId(), TOS_REG); |
| 4472 | if (expr->is_postfix()) { |
| 4473 | if (!context()->IsEffect()) { |
| 4474 | context()->PlugTOS(); |
| 4475 | } |
| 4476 | } else { |
| 4477 | context()->Plug(x0); |
| 4478 | } |
| 4479 | break; |
| 4480 | } |
| 4481 | } |
| 4482 | } |
| 4483 | |
| 4484 | |
| 4485 | void FullCodeGenerator::VisitForTypeofValue(Expression* expr) { |
| 4486 | DCHECK(!context()->IsEffect()); |
| 4487 | DCHECK(!context()->IsTest()); |
| 4488 | VariableProxy* proxy = expr->AsVariableProxy(); |
| 4489 | if (proxy != NULL && proxy->var()->IsUnallocated()) { |
| 4490 | Comment cmnt(masm_, "Global variable"); |
| 4491 | __ Ldr(LoadDescriptor::ReceiverRegister(), GlobalObjectMemOperand()); |
| 4492 | __ Mov(LoadDescriptor::NameRegister(), Operand(proxy->name())); |
| 4493 | if (FLAG_vector_ics) { |
| 4494 | __ Mov(VectorLoadICDescriptor::SlotRegister(), |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 4495 | SmiFromSlot(proxy->VariableFeedbackSlot())); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4496 | } |
| 4497 | // Use a regular load, not a contextual load, to avoid a reference |
| 4498 | // error. |
| 4499 | CallLoadIC(NOT_CONTEXTUAL); |
| 4500 | PrepareForBailout(expr, TOS_REG); |
| 4501 | context()->Plug(x0); |
| 4502 | } else if (proxy != NULL && proxy->var()->IsLookupSlot()) { |
| 4503 | Label done, slow; |
| 4504 | |
| 4505 | // Generate code for loading from variables potentially shadowed |
| 4506 | // by eval-introduced variables. |
| 4507 | EmitDynamicLookupFastCase(proxy, INSIDE_TYPEOF, &slow, &done); |
| 4508 | |
| 4509 | __ Bind(&slow); |
| 4510 | __ Mov(x0, Operand(proxy->name())); |
| 4511 | __ Push(cp, x0); |
| 4512 | __ CallRuntime(Runtime::kLoadLookupSlotNoReferenceError, 2); |
| 4513 | PrepareForBailout(expr, TOS_REG); |
| 4514 | __ Bind(&done); |
| 4515 | |
| 4516 | context()->Plug(x0); |
| 4517 | } else { |
| 4518 | // This expression cannot throw a reference error at the top level. |
| 4519 | VisitInDuplicateContext(expr); |
| 4520 | } |
| 4521 | } |
| 4522 | |
| 4523 | |
| 4524 | void FullCodeGenerator::EmitLiteralCompareTypeof(Expression* expr, |
| 4525 | Expression* sub_expr, |
| 4526 | Handle<String> check) { |
| 4527 | ASM_LOCATION("FullCodeGenerator::EmitLiteralCompareTypeof"); |
| 4528 | Comment cmnt(masm_, "[ EmitLiteralCompareTypeof"); |
| 4529 | Label materialize_true, materialize_false; |
| 4530 | Label* if_true = NULL; |
| 4531 | Label* if_false = NULL; |
| 4532 | Label* fall_through = NULL; |
| 4533 | context()->PrepareTest(&materialize_true, &materialize_false, |
| 4534 | &if_true, &if_false, &fall_through); |
| 4535 | |
| 4536 | { AccumulatorValueContext context(this); |
| 4537 | VisitForTypeofValue(sub_expr); |
| 4538 | } |
| 4539 | PrepareForBailoutBeforeSplit(expr, true, if_true, if_false); |
| 4540 | |
| 4541 | Factory* factory = isolate()->factory(); |
| 4542 | if (String::Equals(check, factory->number_string())) { |
| 4543 | ASM_LOCATION("FullCodeGenerator::EmitLiteralCompareTypeof number_string"); |
| 4544 | __ JumpIfSmi(x0, if_true); |
| 4545 | __ Ldr(x0, FieldMemOperand(x0, HeapObject::kMapOffset)); |
| 4546 | __ CompareRoot(x0, Heap::kHeapNumberMapRootIndex); |
| 4547 | Split(eq, if_true, if_false, fall_through); |
| 4548 | } else if (String::Equals(check, factory->string_string())) { |
| 4549 | ASM_LOCATION("FullCodeGenerator::EmitLiteralCompareTypeof string_string"); |
| 4550 | __ JumpIfSmi(x0, if_false); |
| 4551 | // Check for undetectable objects => false. |
| 4552 | __ JumpIfObjectType(x0, x0, x1, FIRST_NONSTRING_TYPE, if_false, ge); |
| 4553 | __ Ldrb(x1, FieldMemOperand(x0, Map::kBitFieldOffset)); |
| 4554 | __ TestAndSplit(x1, 1 << Map::kIsUndetectable, if_true, if_false, |
| 4555 | fall_through); |
| 4556 | } else if (String::Equals(check, factory->symbol_string())) { |
| 4557 | ASM_LOCATION("FullCodeGenerator::EmitLiteralCompareTypeof symbol_string"); |
| 4558 | __ JumpIfSmi(x0, if_false); |
| 4559 | __ CompareObjectType(x0, x0, x1, SYMBOL_TYPE); |
| 4560 | Split(eq, if_true, if_false, fall_through); |
| 4561 | } else if (String::Equals(check, factory->boolean_string())) { |
| 4562 | ASM_LOCATION("FullCodeGenerator::EmitLiteralCompareTypeof boolean_string"); |
| 4563 | __ JumpIfRoot(x0, Heap::kTrueValueRootIndex, if_true); |
| 4564 | __ CompareRoot(x0, Heap::kFalseValueRootIndex); |
| 4565 | Split(eq, if_true, if_false, fall_through); |
| 4566 | } else if (String::Equals(check, factory->undefined_string())) { |
| 4567 | ASM_LOCATION( |
| 4568 | "FullCodeGenerator::EmitLiteralCompareTypeof undefined_string"); |
| 4569 | __ JumpIfRoot(x0, Heap::kUndefinedValueRootIndex, if_true); |
| 4570 | __ JumpIfSmi(x0, if_false); |
| 4571 | // Check for undetectable objects => true. |
| 4572 | __ Ldr(x0, FieldMemOperand(x0, HeapObject::kMapOffset)); |
| 4573 | __ Ldrb(x1, FieldMemOperand(x0, Map::kBitFieldOffset)); |
| 4574 | __ TestAndSplit(x1, 1 << Map::kIsUndetectable, if_false, if_true, |
| 4575 | fall_through); |
| 4576 | } else if (String::Equals(check, factory->function_string())) { |
| 4577 | ASM_LOCATION("FullCodeGenerator::EmitLiteralCompareTypeof function_string"); |
| 4578 | __ JumpIfSmi(x0, if_false); |
| 4579 | STATIC_ASSERT(NUM_OF_CALLABLE_SPEC_OBJECT_TYPES == 2); |
| 4580 | __ JumpIfObjectType(x0, x10, x11, JS_FUNCTION_TYPE, if_true); |
| 4581 | __ CompareAndSplit(x11, JS_FUNCTION_PROXY_TYPE, eq, if_true, if_false, |
| 4582 | fall_through); |
| 4583 | |
| 4584 | } else if (String::Equals(check, factory->object_string())) { |
| 4585 | ASM_LOCATION("FullCodeGenerator::EmitLiteralCompareTypeof object_string"); |
| 4586 | __ JumpIfSmi(x0, if_false); |
| 4587 | __ JumpIfRoot(x0, Heap::kNullValueRootIndex, if_true); |
| 4588 | // Check for JS objects => true. |
| 4589 | Register map = x10; |
| 4590 | __ JumpIfObjectType(x0, map, x11, FIRST_NONCALLABLE_SPEC_OBJECT_TYPE, |
| 4591 | if_false, lt); |
| 4592 | __ CompareInstanceType(map, x11, LAST_NONCALLABLE_SPEC_OBJECT_TYPE); |
| 4593 | __ B(gt, if_false); |
| 4594 | // Check for undetectable objects => false. |
| 4595 | __ Ldrb(x10, FieldMemOperand(map, Map::kBitFieldOffset)); |
| 4596 | |
| 4597 | __ TestAndSplit(x10, 1 << Map::kIsUndetectable, if_true, if_false, |
| 4598 | fall_through); |
| 4599 | |
| 4600 | } else { |
| 4601 | ASM_LOCATION("FullCodeGenerator::EmitLiteralCompareTypeof other"); |
| 4602 | if (if_false != fall_through) __ B(if_false); |
| 4603 | } |
| 4604 | context()->Plug(if_true, if_false); |
| 4605 | } |
| 4606 | |
| 4607 | |
| 4608 | void FullCodeGenerator::VisitCompareOperation(CompareOperation* expr) { |
| 4609 | Comment cmnt(masm_, "[ CompareOperation"); |
| 4610 | SetSourcePosition(expr->position()); |
| 4611 | |
| 4612 | // Try to generate an optimized comparison with a literal value. |
| 4613 | // TODO(jbramley): This only checks common values like NaN or undefined. |
| 4614 | // Should it also handle ARM64 immediate operands? |
| 4615 | if (TryLiteralCompare(expr)) { |
| 4616 | return; |
| 4617 | } |
| 4618 | |
| 4619 | // Assign labels according to context()->PrepareTest. |
| 4620 | Label materialize_true; |
| 4621 | Label materialize_false; |
| 4622 | Label* if_true = NULL; |
| 4623 | Label* if_false = NULL; |
| 4624 | Label* fall_through = NULL; |
| 4625 | context()->PrepareTest(&materialize_true, &materialize_false, |
| 4626 | &if_true, &if_false, &fall_through); |
| 4627 | |
| 4628 | Token::Value op = expr->op(); |
| 4629 | VisitForStackValue(expr->left()); |
| 4630 | switch (op) { |
| 4631 | case Token::IN: |
| 4632 | VisitForStackValue(expr->right()); |
| 4633 | __ InvokeBuiltin(Builtins::IN, CALL_FUNCTION); |
| 4634 | PrepareForBailoutBeforeSplit(expr, false, NULL, NULL); |
| 4635 | __ CompareRoot(x0, Heap::kTrueValueRootIndex); |
| 4636 | Split(eq, if_true, if_false, fall_through); |
| 4637 | break; |
| 4638 | |
| 4639 | case Token::INSTANCEOF: { |
| 4640 | VisitForStackValue(expr->right()); |
| 4641 | InstanceofStub stub(isolate(), InstanceofStub::kNoFlags); |
| 4642 | __ CallStub(&stub); |
| 4643 | PrepareForBailoutBeforeSplit(expr, true, if_true, if_false); |
| 4644 | // The stub returns 0 for true. |
| 4645 | __ CompareAndSplit(x0, 0, eq, if_true, if_false, fall_through); |
| 4646 | break; |
| 4647 | } |
| 4648 | |
| 4649 | default: { |
| 4650 | VisitForAccumulatorValue(expr->right()); |
| 4651 | Condition cond = CompareIC::ComputeCondition(op); |
| 4652 | |
| 4653 | // Pop the stack value. |
| 4654 | __ Pop(x1); |
| 4655 | |
| 4656 | JumpPatchSite patch_site(masm_); |
| 4657 | if (ShouldInlineSmiCase(op)) { |
| 4658 | Label slow_case; |
| 4659 | patch_site.EmitJumpIfEitherNotSmi(x0, x1, &slow_case); |
| 4660 | __ Cmp(x1, x0); |
| 4661 | Split(cond, if_true, if_false, NULL); |
| 4662 | __ Bind(&slow_case); |
| 4663 | } |
| 4664 | |
| 4665 | // Record position and call the compare IC. |
| 4666 | SetSourcePosition(expr->position()); |
| 4667 | Handle<Code> ic = CodeFactory::CompareIC(isolate(), op).code(); |
| 4668 | CallIC(ic, expr->CompareOperationFeedbackId()); |
| 4669 | patch_site.EmitPatchInfo(); |
| 4670 | PrepareForBailoutBeforeSplit(expr, true, if_true, if_false); |
| 4671 | __ CompareAndSplit(x0, 0, cond, if_true, if_false, fall_through); |
| 4672 | } |
| 4673 | } |
| 4674 | |
| 4675 | // Convert the result of the comparison into one expected for this |
| 4676 | // expression's context. |
| 4677 | context()->Plug(if_true, if_false); |
| 4678 | } |
| 4679 | |
| 4680 | |
| 4681 | void FullCodeGenerator::EmitLiteralCompareNil(CompareOperation* expr, |
| 4682 | Expression* sub_expr, |
| 4683 | NilValue nil) { |
| 4684 | ASM_LOCATION("FullCodeGenerator::EmitLiteralCompareNil"); |
| 4685 | Label materialize_true, materialize_false; |
| 4686 | Label* if_true = NULL; |
| 4687 | Label* if_false = NULL; |
| 4688 | Label* fall_through = NULL; |
| 4689 | context()->PrepareTest(&materialize_true, &materialize_false, |
| 4690 | &if_true, &if_false, &fall_through); |
| 4691 | |
| 4692 | VisitForAccumulatorValue(sub_expr); |
| 4693 | PrepareForBailoutBeforeSplit(expr, true, if_true, if_false); |
| 4694 | |
| 4695 | if (expr->op() == Token::EQ_STRICT) { |
| 4696 | Heap::RootListIndex nil_value = nil == kNullValue ? |
| 4697 | Heap::kNullValueRootIndex : |
| 4698 | Heap::kUndefinedValueRootIndex; |
| 4699 | __ CompareRoot(x0, nil_value); |
| 4700 | Split(eq, if_true, if_false, fall_through); |
| 4701 | } else { |
| 4702 | Handle<Code> ic = CompareNilICStub::GetUninitialized(isolate(), nil); |
| 4703 | CallIC(ic, expr->CompareOperationFeedbackId()); |
| 4704 | __ CompareAndSplit(x0, 0, ne, if_true, if_false, fall_through); |
| 4705 | } |
| 4706 | |
| 4707 | context()->Plug(if_true, if_false); |
| 4708 | } |
| 4709 | |
| 4710 | |
| 4711 | void FullCodeGenerator::VisitThisFunction(ThisFunction* expr) { |
| 4712 | __ Ldr(x0, MemOperand(fp, JavaScriptFrameConstants::kFunctionOffset)); |
| 4713 | context()->Plug(x0); |
| 4714 | } |
| 4715 | |
| 4716 | |
| 4717 | void FullCodeGenerator::VisitYield(Yield* expr) { |
| 4718 | Comment cmnt(masm_, "[ Yield"); |
| 4719 | // Evaluate yielded value first; the initial iterator definition depends on |
| 4720 | // this. It stays on the stack while we update the iterator. |
| 4721 | VisitForStackValue(expr->expression()); |
| 4722 | |
| 4723 | // TODO(jbramley): Tidy this up once the merge is done, using named registers |
| 4724 | // and suchlike. The implementation changes a little by bleeding_edge so I |
| 4725 | // don't want to spend too much time on it now. |
| 4726 | |
| 4727 | switch (expr->yield_kind()) { |
| 4728 | case Yield::kSuspend: |
| 4729 | // Pop value from top-of-stack slot; box result into result register. |
| 4730 | EmitCreateIteratorResult(false); |
| 4731 | __ Push(result_register()); |
| 4732 | // Fall through. |
| 4733 | case Yield::kInitial: { |
| 4734 | Label suspend, continuation, post_runtime, resume; |
| 4735 | |
| 4736 | __ B(&suspend); |
| 4737 | |
| 4738 | // TODO(jbramley): This label is bound here because the following code |
| 4739 | // looks at its pos(). Is it possible to do something more efficient here, |
| 4740 | // perhaps using Adr? |
| 4741 | __ Bind(&continuation); |
| 4742 | __ B(&resume); |
| 4743 | |
| 4744 | __ Bind(&suspend); |
| 4745 | VisitForAccumulatorValue(expr->generator_object()); |
| 4746 | DCHECK((continuation.pos() > 0) && Smi::IsValid(continuation.pos())); |
| 4747 | __ Mov(x1, Smi::FromInt(continuation.pos())); |
| 4748 | __ Str(x1, FieldMemOperand(x0, JSGeneratorObject::kContinuationOffset)); |
| 4749 | __ Str(cp, FieldMemOperand(x0, JSGeneratorObject::kContextOffset)); |
| 4750 | __ Mov(x1, cp); |
| 4751 | __ RecordWriteField(x0, JSGeneratorObject::kContextOffset, x1, x2, |
| 4752 | kLRHasBeenSaved, kDontSaveFPRegs); |
| 4753 | __ Add(x1, fp, StandardFrameConstants::kExpressionsOffset); |
| 4754 | __ Cmp(__ StackPointer(), x1); |
| 4755 | __ B(eq, &post_runtime); |
| 4756 | __ Push(x0); // generator object |
| 4757 | __ CallRuntime(Runtime::kSuspendJSGeneratorObject, 1); |
| 4758 | __ Ldr(cp, MemOperand(fp, StandardFrameConstants::kContextOffset)); |
| 4759 | __ Bind(&post_runtime); |
| 4760 | __ Pop(result_register()); |
| 4761 | EmitReturnSequence(); |
| 4762 | |
| 4763 | __ Bind(&resume); |
| 4764 | context()->Plug(result_register()); |
| 4765 | break; |
| 4766 | } |
| 4767 | |
| 4768 | case Yield::kFinal: { |
| 4769 | VisitForAccumulatorValue(expr->generator_object()); |
| 4770 | __ Mov(x1, Smi::FromInt(JSGeneratorObject::kGeneratorClosed)); |
| 4771 | __ Str(x1, FieldMemOperand(result_register(), |
| 4772 | JSGeneratorObject::kContinuationOffset)); |
| 4773 | // Pop value from top-of-stack slot, box result into result register. |
| 4774 | EmitCreateIteratorResult(true); |
| 4775 | EmitUnwindBeforeReturn(); |
| 4776 | EmitReturnSequence(); |
| 4777 | break; |
| 4778 | } |
| 4779 | |
| 4780 | case Yield::kDelegating: { |
| 4781 | VisitForStackValue(expr->generator_object()); |
| 4782 | |
| 4783 | // Initial stack layout is as follows: |
| 4784 | // [sp + 1 * kPointerSize] iter |
| 4785 | // [sp + 0 * kPointerSize] g |
| 4786 | |
| 4787 | Label l_catch, l_try, l_suspend, l_continuation, l_resume; |
| 4788 | Label l_next, l_call, l_loop; |
| 4789 | Register load_receiver = LoadDescriptor::ReceiverRegister(); |
| 4790 | Register load_name = LoadDescriptor::NameRegister(); |
| 4791 | |
| 4792 | // Initial send value is undefined. |
| 4793 | __ LoadRoot(x0, Heap::kUndefinedValueRootIndex); |
| 4794 | __ B(&l_next); |
| 4795 | |
| 4796 | // catch (e) { receiver = iter; f = 'throw'; arg = e; goto l_call; } |
| 4797 | __ Bind(&l_catch); |
| 4798 | handler_table()->set(expr->index(), Smi::FromInt(l_catch.pos())); |
| 4799 | __ LoadRoot(load_name, Heap::kthrow_stringRootIndex); // "throw" |
| 4800 | __ Peek(x3, 1 * kPointerSize); // iter |
| 4801 | __ Push(load_name, x3, x0); // "throw", iter, except |
| 4802 | __ B(&l_call); |
| 4803 | |
| 4804 | // try { received = %yield result } |
| 4805 | // Shuffle the received result above a try handler and yield it without |
| 4806 | // re-boxing. |
| 4807 | __ Bind(&l_try); |
| 4808 | __ Pop(x0); // result |
| 4809 | __ PushTryHandler(StackHandler::CATCH, expr->index()); |
| 4810 | const int handler_size = StackHandlerConstants::kSize; |
| 4811 | __ Push(x0); // result |
| 4812 | __ B(&l_suspend); |
| 4813 | |
| 4814 | // TODO(jbramley): This label is bound here because the following code |
| 4815 | // looks at its pos(). Is it possible to do something more efficient here, |
| 4816 | // perhaps using Adr? |
| 4817 | __ Bind(&l_continuation); |
| 4818 | __ B(&l_resume); |
| 4819 | |
| 4820 | __ Bind(&l_suspend); |
| 4821 | const int generator_object_depth = kPointerSize + handler_size; |
| 4822 | __ Peek(x0, generator_object_depth); |
| 4823 | __ Push(x0); // g |
| 4824 | DCHECK((l_continuation.pos() > 0) && Smi::IsValid(l_continuation.pos())); |
| 4825 | __ Mov(x1, Smi::FromInt(l_continuation.pos())); |
| 4826 | __ Str(x1, FieldMemOperand(x0, JSGeneratorObject::kContinuationOffset)); |
| 4827 | __ Str(cp, FieldMemOperand(x0, JSGeneratorObject::kContextOffset)); |
| 4828 | __ Mov(x1, cp); |
| 4829 | __ RecordWriteField(x0, JSGeneratorObject::kContextOffset, x1, x2, |
| 4830 | kLRHasBeenSaved, kDontSaveFPRegs); |
| 4831 | __ CallRuntime(Runtime::kSuspendJSGeneratorObject, 1); |
| 4832 | __ Ldr(cp, MemOperand(fp, StandardFrameConstants::kContextOffset)); |
| 4833 | __ Pop(x0); // result |
| 4834 | EmitReturnSequence(); |
| 4835 | __ Bind(&l_resume); // received in x0 |
| 4836 | __ PopTryHandler(); |
| 4837 | |
| 4838 | // receiver = iter; f = 'next'; arg = received; |
| 4839 | __ Bind(&l_next); |
| 4840 | |
| 4841 | __ LoadRoot(load_name, Heap::knext_stringRootIndex); // "next" |
| 4842 | __ Peek(x3, 1 * kPointerSize); // iter |
| 4843 | __ Push(load_name, x3, x0); // "next", iter, received |
| 4844 | |
| 4845 | // result = receiver[f](arg); |
| 4846 | __ Bind(&l_call); |
| 4847 | __ Peek(load_receiver, 1 * kPointerSize); |
| 4848 | __ Peek(load_name, 2 * kPointerSize); |
| 4849 | if (FLAG_vector_ics) { |
| 4850 | __ Mov(VectorLoadICDescriptor::SlotRegister(), |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 4851 | SmiFromSlot(expr->KeyedLoadFeedbackSlot())); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4852 | } |
| 4853 | Handle<Code> ic = CodeFactory::KeyedLoadIC(isolate()).code(); |
| 4854 | CallIC(ic, TypeFeedbackId::None()); |
| 4855 | __ Mov(x1, x0); |
| 4856 | __ Poke(x1, 2 * kPointerSize); |
| 4857 | CallFunctionStub stub(isolate(), 1, CALL_AS_METHOD); |
| 4858 | __ CallStub(&stub); |
| 4859 | |
| 4860 | __ Ldr(cp, MemOperand(fp, StandardFrameConstants::kContextOffset)); |
| 4861 | __ Drop(1); // The function is still on the stack; drop it. |
| 4862 | |
| 4863 | // if (!result.done) goto l_try; |
| 4864 | __ Bind(&l_loop); |
| 4865 | __ Move(load_receiver, x0); |
| 4866 | |
| 4867 | __ Push(load_receiver); // save result |
| 4868 | __ LoadRoot(load_name, Heap::kdone_stringRootIndex); // "done" |
| 4869 | if (FLAG_vector_ics) { |
| 4870 | __ Mov(VectorLoadICDescriptor::SlotRegister(), |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 4871 | SmiFromSlot(expr->DoneFeedbackSlot())); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4872 | } |
| 4873 | CallLoadIC(NOT_CONTEXTUAL); // x0=result.done |
| 4874 | // The ToBooleanStub argument (result.done) is in x0. |
| 4875 | Handle<Code> bool_ic = ToBooleanStub::GetUninitialized(isolate()); |
| 4876 | CallIC(bool_ic); |
| 4877 | __ Cbz(x0, &l_try); |
| 4878 | |
| 4879 | // result.value |
| 4880 | __ Pop(load_receiver); // result |
| 4881 | __ LoadRoot(load_name, Heap::kvalue_stringRootIndex); // "value" |
| 4882 | if (FLAG_vector_ics) { |
| 4883 | __ Mov(VectorLoadICDescriptor::SlotRegister(), |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 4884 | SmiFromSlot(expr->ValueFeedbackSlot())); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4885 | } |
| 4886 | CallLoadIC(NOT_CONTEXTUAL); // x0=result.value |
| 4887 | context()->DropAndPlug(2, x0); // drop iter and g |
| 4888 | break; |
| 4889 | } |
| 4890 | } |
| 4891 | } |
| 4892 | |
| 4893 | |
| 4894 | void FullCodeGenerator::EmitGeneratorResume(Expression *generator, |
| 4895 | Expression *value, |
| 4896 | JSGeneratorObject::ResumeMode resume_mode) { |
| 4897 | ASM_LOCATION("FullCodeGenerator::EmitGeneratorResume"); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4898 | Register generator_object = x1; |
| 4899 | Register the_hole = x2; |
| 4900 | Register operand_stack_size = w3; |
| 4901 | Register function = x4; |
| 4902 | |
| 4903 | // The value stays in x0, and is ultimately read by the resumed generator, as |
| 4904 | // if CallRuntime(Runtime::kSuspendJSGeneratorObject) returned it. Or it |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 4905 | // is read to throw the value when the resumed generator is already closed. x1 |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4906 | // will hold the generator object until the activation has been resumed. |
| 4907 | VisitForStackValue(generator); |
| 4908 | VisitForAccumulatorValue(value); |
| 4909 | __ Pop(generator_object); |
| 4910 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4911 | // Load suspended function and context. |
| 4912 | __ Ldr(cp, FieldMemOperand(generator_object, |
| 4913 | JSGeneratorObject::kContextOffset)); |
| 4914 | __ Ldr(function, FieldMemOperand(generator_object, |
| 4915 | JSGeneratorObject::kFunctionOffset)); |
| 4916 | |
| 4917 | // Load receiver and store as the first argument. |
| 4918 | __ Ldr(x10, FieldMemOperand(generator_object, |
| 4919 | JSGeneratorObject::kReceiverOffset)); |
| 4920 | __ Push(x10); |
| 4921 | |
| 4922 | // Push holes for the rest of the arguments to the generator function. |
| 4923 | __ Ldr(x10, FieldMemOperand(function, JSFunction::kSharedFunctionInfoOffset)); |
| 4924 | |
| 4925 | // The number of arguments is stored as an int32_t, and -1 is a marker |
| 4926 | // (SharedFunctionInfo::kDontAdaptArgumentsSentinel), so we need sign |
| 4927 | // extension to correctly handle it. However, in this case, we operate on |
| 4928 | // 32-bit W registers, so extension isn't required. |
| 4929 | __ Ldr(w10, FieldMemOperand(x10, |
| 4930 | SharedFunctionInfo::kFormalParameterCountOffset)); |
| 4931 | __ LoadRoot(the_hole, Heap::kTheHoleValueRootIndex); |
| 4932 | __ PushMultipleTimes(the_hole, w10); |
| 4933 | |
| 4934 | // Enter a new JavaScript frame, and initialize its slots as they were when |
| 4935 | // the generator was suspended. |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 4936 | Label resume_frame, done; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4937 | __ Bl(&resume_frame); |
| 4938 | __ B(&done); |
| 4939 | |
| 4940 | __ Bind(&resume_frame); |
| 4941 | __ Push(lr, // Return address. |
| 4942 | fp, // Caller's frame pointer. |
| 4943 | cp, // Callee's context. |
| 4944 | function); // Callee's JS Function. |
| 4945 | __ Add(fp, __ StackPointer(), kPointerSize * 2); |
| 4946 | |
| 4947 | // Load and untag the operand stack size. |
| 4948 | __ Ldr(x10, FieldMemOperand(generator_object, |
| 4949 | JSGeneratorObject::kOperandStackOffset)); |
| 4950 | __ Ldr(operand_stack_size, |
| 4951 | UntagSmiFieldMemOperand(x10, FixedArray::kLengthOffset)); |
| 4952 | |
| 4953 | // If we are sending a value and there is no operand stack, we can jump back |
| 4954 | // in directly. |
| 4955 | if (resume_mode == JSGeneratorObject::NEXT) { |
| 4956 | Label slow_resume; |
| 4957 | __ Cbnz(operand_stack_size, &slow_resume); |
| 4958 | __ Ldr(x10, FieldMemOperand(function, JSFunction::kCodeEntryOffset)); |
| 4959 | __ Ldrsw(x11, |
| 4960 | UntagSmiFieldMemOperand(generator_object, |
| 4961 | JSGeneratorObject::kContinuationOffset)); |
| 4962 | __ Add(x10, x10, x11); |
| 4963 | __ Mov(x12, Smi::FromInt(JSGeneratorObject::kGeneratorExecuting)); |
| 4964 | __ Str(x12, FieldMemOperand(generator_object, |
| 4965 | JSGeneratorObject::kContinuationOffset)); |
| 4966 | __ Br(x10); |
| 4967 | |
| 4968 | __ Bind(&slow_resume); |
| 4969 | } |
| 4970 | |
| 4971 | // Otherwise, we push holes for the operand stack and call the runtime to fix |
| 4972 | // up the stack and the handlers. |
| 4973 | __ PushMultipleTimes(the_hole, operand_stack_size); |
| 4974 | |
| 4975 | __ Mov(x10, Smi::FromInt(resume_mode)); |
| 4976 | __ Push(generator_object, result_register(), x10); |
| 4977 | __ CallRuntime(Runtime::kResumeJSGeneratorObject, 3); |
| 4978 | // Not reached: the runtime call returns elsewhere. |
| 4979 | __ Unreachable(); |
| 4980 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4981 | __ Bind(&done); |
| 4982 | context()->Plug(result_register()); |
| 4983 | } |
| 4984 | |
| 4985 | |
| 4986 | void FullCodeGenerator::EmitCreateIteratorResult(bool done) { |
| 4987 | Label gc_required; |
| 4988 | Label allocated; |
| 4989 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 4990 | const int instance_size = 5 * kPointerSize; |
| 4991 | DCHECK_EQ(isolate()->native_context()->iterator_result_map()->instance_size(), |
| 4992 | instance_size); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4993 | |
| 4994 | // Allocate and populate an object with this form: { value: VAL, done: DONE } |
| 4995 | |
| 4996 | Register result = x0; |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 4997 | __ Allocate(instance_size, result, x10, x11, &gc_required, TAG_OBJECT); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4998 | __ B(&allocated); |
| 4999 | |
| 5000 | __ Bind(&gc_required); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 5001 | __ Push(Smi::FromInt(instance_size)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5002 | __ CallRuntime(Runtime::kAllocateInNewSpace, 1); |
| 5003 | __ Ldr(context_register(), |
| 5004 | MemOperand(fp, StandardFrameConstants::kContextOffset)); |
| 5005 | |
| 5006 | __ Bind(&allocated); |
| 5007 | Register map_reg = x1; |
| 5008 | Register result_value = x2; |
| 5009 | Register boolean_done = x3; |
| 5010 | Register empty_fixed_array = x4; |
| 5011 | Register untagged_result = x5; |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 5012 | __ Ldr(map_reg, GlobalObjectMemOperand()); |
| 5013 | __ Ldr(map_reg, FieldMemOperand(map_reg, GlobalObject::kNativeContextOffset)); |
| 5014 | __ Ldr(map_reg, |
| 5015 | ContextMemOperand(map_reg, Context::ITERATOR_RESULT_MAP_INDEX)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5016 | __ Pop(result_value); |
| 5017 | __ Mov(boolean_done, Operand(isolate()->factory()->ToBoolean(done))); |
| 5018 | __ Mov(empty_fixed_array, Operand(isolate()->factory()->empty_fixed_array())); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5019 | STATIC_ASSERT(JSObject::kPropertiesOffset + kPointerSize == |
| 5020 | JSObject::kElementsOffset); |
| 5021 | STATIC_ASSERT(JSGeneratorObject::kResultValuePropertyOffset + kPointerSize == |
| 5022 | JSGeneratorObject::kResultDonePropertyOffset); |
| 5023 | __ ObjectUntag(untagged_result, result); |
| 5024 | __ Str(map_reg, MemOperand(untagged_result, HeapObject::kMapOffset)); |
| 5025 | __ Stp(empty_fixed_array, empty_fixed_array, |
| 5026 | MemOperand(untagged_result, JSObject::kPropertiesOffset)); |
| 5027 | __ Stp(result_value, boolean_done, |
| 5028 | MemOperand(untagged_result, |
| 5029 | JSGeneratorObject::kResultValuePropertyOffset)); |
| 5030 | |
| 5031 | // Only the value field needs a write barrier, as the other values are in the |
| 5032 | // root set. |
| 5033 | __ RecordWriteField(result, JSGeneratorObject::kResultValuePropertyOffset, |
| 5034 | x10, x11, kLRHasBeenSaved, kDontSaveFPRegs); |
| 5035 | } |
| 5036 | |
| 5037 | |
| 5038 | // TODO(all): I don't like this method. |
| 5039 | // It seems to me that in too many places x0 is used in place of this. |
| 5040 | // Also, this function is not suitable for all places where x0 should be |
| 5041 | // abstracted (eg. when used as an argument). But some places assume that the |
| 5042 | // first argument register is x0, and use this function instead. |
| 5043 | // Considering that most of the register allocation is hard-coded in the |
| 5044 | // FullCodeGen, that it is unlikely we will need to change it extensively, and |
| 5045 | // that abstracting the allocation through functions would not yield any |
| 5046 | // performance benefit, I think the existence of this function is debatable. |
| 5047 | Register FullCodeGenerator::result_register() { |
| 5048 | return x0; |
| 5049 | } |
| 5050 | |
| 5051 | |
| 5052 | Register FullCodeGenerator::context_register() { |
| 5053 | return cp; |
| 5054 | } |
| 5055 | |
| 5056 | |
| 5057 | void FullCodeGenerator::StoreToFrameField(int frame_offset, Register value) { |
| 5058 | DCHECK(POINTER_SIZE_ALIGN(frame_offset) == frame_offset); |
| 5059 | __ Str(value, MemOperand(fp, frame_offset)); |
| 5060 | } |
| 5061 | |
| 5062 | |
| 5063 | void FullCodeGenerator::LoadContextField(Register dst, int context_index) { |
| 5064 | __ Ldr(dst, ContextMemOperand(cp, context_index)); |
| 5065 | } |
| 5066 | |
| 5067 | |
| 5068 | void FullCodeGenerator::PushFunctionArgumentForContextAllocation() { |
| 5069 | Scope* declaration_scope = scope()->DeclarationScope(); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 5070 | if (declaration_scope->is_script_scope() || |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5071 | declaration_scope->is_module_scope()) { |
| 5072 | // Contexts nested in the native context have a canonical empty function |
| 5073 | // as their closure, not the anonymous closure containing the global |
| 5074 | // code. Pass a smi sentinel and let the runtime look up the empty |
| 5075 | // function. |
| 5076 | DCHECK(kSmiTag == 0); |
| 5077 | __ Push(xzr); |
| 5078 | } else if (declaration_scope->is_eval_scope()) { |
| 5079 | // Contexts created by a call to eval have the same closure as the |
| 5080 | // context calling eval, not the anonymous closure containing the eval |
| 5081 | // code. Fetch it from the context. |
| 5082 | __ Ldr(x10, ContextMemOperand(cp, Context::CLOSURE_INDEX)); |
| 5083 | __ Push(x10); |
| 5084 | } else { |
| 5085 | DCHECK(declaration_scope->is_function_scope()); |
| 5086 | __ Ldr(x10, MemOperand(fp, JavaScriptFrameConstants::kFunctionOffset)); |
| 5087 | __ Push(x10); |
| 5088 | } |
| 5089 | } |
| 5090 | |
| 5091 | |
| 5092 | void FullCodeGenerator::EnterFinallyBlock() { |
| 5093 | ASM_LOCATION("FullCodeGenerator::EnterFinallyBlock"); |
| 5094 | DCHECK(!result_register().is(x10)); |
| 5095 | // Preserve the result register while executing finally block. |
| 5096 | // Also cook the return address in lr to the stack (smi encoded Code* delta). |
| 5097 | __ Sub(x10, lr, Operand(masm_->CodeObject())); |
| 5098 | __ SmiTag(x10); |
| 5099 | __ Push(result_register(), x10); |
| 5100 | |
| 5101 | // Store pending message while executing finally block. |
| 5102 | ExternalReference pending_message_obj = |
| 5103 | ExternalReference::address_of_pending_message_obj(isolate()); |
| 5104 | __ Mov(x10, pending_message_obj); |
| 5105 | __ Ldr(x10, MemOperand(x10)); |
| 5106 | |
| 5107 | ExternalReference has_pending_message = |
| 5108 | ExternalReference::address_of_has_pending_message(isolate()); |
| 5109 | STATIC_ASSERT(sizeof(bool) == 1); // NOLINT(runtime/sizeof) |
| 5110 | __ Mov(x11, has_pending_message); |
| 5111 | __ Ldrb(x11, MemOperand(x11)); |
| 5112 | __ SmiTag(x11); |
| 5113 | |
| 5114 | __ Push(x10, x11); |
| 5115 | |
| 5116 | ExternalReference pending_message_script = |
| 5117 | ExternalReference::address_of_pending_message_script(isolate()); |
| 5118 | __ Mov(x10, pending_message_script); |
| 5119 | __ Ldr(x10, MemOperand(x10)); |
| 5120 | __ Push(x10); |
| 5121 | } |
| 5122 | |
| 5123 | |
| 5124 | void FullCodeGenerator::ExitFinallyBlock() { |
| 5125 | ASM_LOCATION("FullCodeGenerator::ExitFinallyBlock"); |
| 5126 | DCHECK(!result_register().is(x10)); |
| 5127 | |
| 5128 | // Restore pending message from stack. |
| 5129 | __ Pop(x10, x11, x12); |
| 5130 | ExternalReference pending_message_script = |
| 5131 | ExternalReference::address_of_pending_message_script(isolate()); |
| 5132 | __ Mov(x13, pending_message_script); |
| 5133 | __ Str(x10, MemOperand(x13)); |
| 5134 | |
| 5135 | __ SmiUntag(x11); |
| 5136 | ExternalReference has_pending_message = |
| 5137 | ExternalReference::address_of_has_pending_message(isolate()); |
| 5138 | __ Mov(x13, has_pending_message); |
| 5139 | STATIC_ASSERT(sizeof(bool) == 1); // NOLINT(runtime/sizeof) |
| 5140 | __ Strb(x11, MemOperand(x13)); |
| 5141 | |
| 5142 | ExternalReference pending_message_obj = |
| 5143 | ExternalReference::address_of_pending_message_obj(isolate()); |
| 5144 | __ Mov(x13, pending_message_obj); |
| 5145 | __ Str(x12, MemOperand(x13)); |
| 5146 | |
| 5147 | // Restore result register and cooked return address from the stack. |
| 5148 | __ Pop(x10, result_register()); |
| 5149 | |
| 5150 | // Uncook the return address (see EnterFinallyBlock). |
| 5151 | __ SmiUntag(x10); |
| 5152 | __ Add(x11, x10, Operand(masm_->CodeObject())); |
| 5153 | __ Br(x11); |
| 5154 | } |
| 5155 | |
| 5156 | |
| 5157 | #undef __ |
| 5158 | |
| 5159 | |
| 5160 | void BackEdgeTable::PatchAt(Code* unoptimized_code, |
| 5161 | Address pc, |
| 5162 | BackEdgeState target_state, |
| 5163 | Code* replacement_code) { |
| 5164 | // Turn the jump into a nop. |
| 5165 | Address branch_address = pc - 3 * kInstructionSize; |
| 5166 | PatchingAssembler patcher(branch_address, 1); |
| 5167 | |
| 5168 | DCHECK(Instruction::Cast(branch_address) |
| 5169 | ->IsNop(Assembler::INTERRUPT_CODE_NOP) || |
| 5170 | (Instruction::Cast(branch_address)->IsCondBranchImm() && |
| 5171 | Instruction::Cast(branch_address)->ImmPCOffset() == |
| 5172 | 6 * kInstructionSize)); |
| 5173 | |
| 5174 | switch (target_state) { |
| 5175 | case INTERRUPT: |
| 5176 | // <decrement profiling counter> |
| 5177 | // .. .. .. .. b.pl ok |
| 5178 | // .. .. .. .. ldr x16, pc+<interrupt stub address> |
| 5179 | // .. .. .. .. blr x16 |
| 5180 | // ... more instructions. |
| 5181 | // ok-label |
| 5182 | // Jump offset is 6 instructions. |
| 5183 | patcher.b(6, pl); |
| 5184 | break; |
| 5185 | case ON_STACK_REPLACEMENT: |
| 5186 | case OSR_AFTER_STACK_CHECK: |
| 5187 | // <decrement profiling counter> |
| 5188 | // .. .. .. .. mov x0, x0 (NOP) |
| 5189 | // .. .. .. .. ldr x16, pc+<on-stack replacement address> |
| 5190 | // .. .. .. .. blr x16 |
| 5191 | patcher.nop(Assembler::INTERRUPT_CODE_NOP); |
| 5192 | break; |
| 5193 | } |
| 5194 | |
| 5195 | // Replace the call address. |
| 5196 | Instruction* load = Instruction::Cast(pc)->preceding(2); |
| 5197 | Address interrupt_address_pointer = |
| 5198 | reinterpret_cast<Address>(load) + load->ImmPCOffset(); |
| 5199 | DCHECK((Memory::uint64_at(interrupt_address_pointer) == |
| 5200 | reinterpret_cast<uint64_t>(unoptimized_code->GetIsolate() |
| 5201 | ->builtins() |
| 5202 | ->OnStackReplacement() |
| 5203 | ->entry())) || |
| 5204 | (Memory::uint64_at(interrupt_address_pointer) == |
| 5205 | reinterpret_cast<uint64_t>(unoptimized_code->GetIsolate() |
| 5206 | ->builtins() |
| 5207 | ->InterruptCheck() |
| 5208 | ->entry())) || |
| 5209 | (Memory::uint64_at(interrupt_address_pointer) == |
| 5210 | reinterpret_cast<uint64_t>(unoptimized_code->GetIsolate() |
| 5211 | ->builtins() |
| 5212 | ->OsrAfterStackCheck() |
| 5213 | ->entry())) || |
| 5214 | (Memory::uint64_at(interrupt_address_pointer) == |
| 5215 | reinterpret_cast<uint64_t>(unoptimized_code->GetIsolate() |
| 5216 | ->builtins() |
| 5217 | ->OnStackReplacement() |
| 5218 | ->entry()))); |
| 5219 | Memory::uint64_at(interrupt_address_pointer) = |
| 5220 | reinterpret_cast<uint64_t>(replacement_code->entry()); |
| 5221 | |
| 5222 | unoptimized_code->GetHeap()->incremental_marking()->RecordCodeTargetPatch( |
| 5223 | unoptimized_code, reinterpret_cast<Address>(load), replacement_code); |
| 5224 | } |
| 5225 | |
| 5226 | |
| 5227 | BackEdgeTable::BackEdgeState BackEdgeTable::GetBackEdgeState( |
| 5228 | Isolate* isolate, |
| 5229 | Code* unoptimized_code, |
| 5230 | Address pc) { |
| 5231 | // TODO(jbramley): There should be some extra assertions here (as in the ARM |
| 5232 | // back-end), but this function is gone in bleeding_edge so it might not |
| 5233 | // matter anyway. |
| 5234 | Instruction* jump_or_nop = Instruction::Cast(pc)->preceding(3); |
| 5235 | |
| 5236 | if (jump_or_nop->IsNop(Assembler::INTERRUPT_CODE_NOP)) { |
| 5237 | Instruction* load = Instruction::Cast(pc)->preceding(2); |
| 5238 | uint64_t entry = Memory::uint64_at(reinterpret_cast<Address>(load) + |
| 5239 | load->ImmPCOffset()); |
| 5240 | if (entry == reinterpret_cast<uint64_t>( |
| 5241 | isolate->builtins()->OnStackReplacement()->entry())) { |
| 5242 | return ON_STACK_REPLACEMENT; |
| 5243 | } else if (entry == reinterpret_cast<uint64_t>( |
| 5244 | isolate->builtins()->OsrAfterStackCheck()->entry())) { |
| 5245 | return OSR_AFTER_STACK_CHECK; |
| 5246 | } else { |
| 5247 | UNREACHABLE(); |
| 5248 | } |
| 5249 | } |
| 5250 | |
| 5251 | return INTERRUPT; |
| 5252 | } |
| 5253 | |
| 5254 | |
| 5255 | #define __ ACCESS_MASM(masm()) |
| 5256 | |
| 5257 | |
| 5258 | FullCodeGenerator::NestedStatement* FullCodeGenerator::TryFinally::Exit( |
| 5259 | int* stack_depth, |
| 5260 | int* context_length) { |
| 5261 | ASM_LOCATION("FullCodeGenerator::TryFinally::Exit"); |
| 5262 | // The macros used here must preserve the result register. |
| 5263 | |
| 5264 | // Because the handler block contains the context of the finally |
| 5265 | // code, we can restore it directly from there for the finally code |
| 5266 | // rather than iteratively unwinding contexts via their previous |
| 5267 | // links. |
| 5268 | __ Drop(*stack_depth); // Down to the handler block. |
| 5269 | if (*context_length > 0) { |
| 5270 | // Restore the context to its dedicated register and the stack. |
| 5271 | __ Peek(cp, StackHandlerConstants::kContextOffset); |
| 5272 | __ Str(cp, MemOperand(fp, StandardFrameConstants::kContextOffset)); |
| 5273 | } |
| 5274 | __ PopTryHandler(); |
| 5275 | __ Bl(finally_entry_); |
| 5276 | |
| 5277 | *stack_depth = 0; |
| 5278 | *context_length = 0; |
| 5279 | return previous_; |
| 5280 | } |
| 5281 | |
| 5282 | |
| 5283 | #undef __ |
| 5284 | |
| 5285 | |
| 5286 | } } // namespace v8::internal |
| 5287 | |
| 5288 | #endif // V8_TARGET_ARCH_ARM64 |