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.
7 #if V8_TARGET_ARCH_ARM64
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"
20 #include "src/arm64/code-stubs-arm64.h"
21 #include "src/arm64/macro-assembler-arm64.h"
26 #define __ ACCESS_MASM(masm_)
28 class JumpPatchSite BASE_EMBEDDED {
30 explicit JumpPatchSite(MacroAssembler* masm) : masm_(masm), reg_(NoReg) {
32 info_emitted_ = false;
37 if (patch_site_.is_bound()) {
38 DCHECK(info_emitted_);
40 DCHECK(reg_.IsNone());
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());
51 __ bind(&patch_site_);
52 __ tbz(xzr, 0, target); // Always taken before patched.
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());
62 __ bind(&patch_site_);
63 __ tbnz(xzr, 0, target); // Never taken before patched.
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);
73 void EmitPatchInfo() {
74 Assembler::BlockPoolsScope scope(masm_);
75 InlineSmiCheckInfo::Emit(masm_, reg_, &patch_site_);
82 MacroAssembler* masm_;
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
96 // The live registers are:
97 // - x1: the JS function object being called (i.e. ourselves).
99 // - fp: our caller's frame pointer.
100 // - jssp: stack pointer.
101 // - lr: return address.
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_;
108 Handle<HandlerTable>::cast(isolate()->factory()->NewFixedArray(
109 HandlerTable::LengthForRange(function()->handler_count()), TENURED));
111 profiling_counter_ = isolate()->factory()->NewCell(
112 Handle<Smi>(Smi::FromInt(FLAG_interrupt_budget), isolate()));
113 SetFunctionPosition(function());
114 Comment cmnt(masm_, "[ Function compiled by full code generator");
116 ProfileEntryHookStub::MaybeCallEntryHook(masm_);
119 if (strlen(FLAG_stop_at) > 0 &&
120 info->function()->name()->IsUtf8EqualTo(CStrVector(FLAG_stop_at))) {
121 __ Debug("stop-at", __LINE__, BREAK);
125 // Sloppy mode functions and builtins need to replace the receiver with the
126 // global proxy when called as functions (without an explicit receiver
128 if (is_sloppy(info->language_mode()) && !info->is_native()) {
130 int receiver_offset = info->scope()->num_parameters() * kXRegSize;
131 __ Peek(x10, receiver_offset);
132 __ JumpIfNotRoot(x10, Heap::kUndefinedValueRootIndex, &ok);
134 __ Ldr(x10, GlobalObjectMemOperand());
135 __ Ldr(x10, FieldMemOperand(x10, GlobalObject::kGlobalProxyOffset));
136 __ Poke(x10, receiver_offset);
142 // Open a frame scope to indicate that there is a frame on the stack.
143 // The MANUAL indicates that the scope shouldn't actually generate code
144 // to set up the frame because we do it manually below.
145 FrameScope frame_scope(masm_, StackFrame::MANUAL);
147 // This call emits the following sequence in a way that can be patched for
148 // code ageing support:
149 // Push(lr, fp, cp, x1);
150 // Add(fp, jssp, 2 * kPointerSize);
151 info->set_prologue_offset(masm_->pc_offset());
152 __ Prologue(info->IsCodePreAgingActive());
153 info->AddNoFrameRange(0, masm_->pc_offset());
155 // Reserve space on the stack for locals.
156 { Comment cmnt(masm_, "[ Allocate locals");
157 int locals_count = info->scope()->num_stack_slots();
158 // Generators allocate locals, if any, in context slots.
159 DCHECK(!IsGeneratorFunction(info->function()->kind()) || locals_count == 0);
161 if (locals_count > 0) {
162 if (locals_count >= 128) {
164 DCHECK(jssp.Is(__ StackPointer()));
165 __ Sub(x10, jssp, locals_count * kPointerSize);
166 __ CompareRoot(x10, Heap::kRealStackLimitRootIndex);
168 __ InvokeBuiltin(Builtins::STACK_OVERFLOW, CALL_FUNCTION);
171 __ LoadRoot(x10, Heap::kUndefinedValueRootIndex);
172 if (FLAG_optimize_for_size) {
173 __ PushMultipleTimes(x10 , locals_count);
175 const int kMaxPushes = 32;
176 if (locals_count >= kMaxPushes) {
177 int loop_iterations = locals_count / kMaxPushes;
178 __ Mov(x3, loop_iterations);
180 __ Bind(&loop_header);
182 __ PushMultipleTimes(x10 , kMaxPushes);
184 __ B(ne, &loop_header);
186 int remaining = locals_count % kMaxPushes;
187 // Emit the remaining pushes.
188 __ PushMultipleTimes(x10 , remaining);
193 bool function_in_register_x1 = true;
195 int heap_slots = info->scope()->num_heap_slots() - Context::MIN_CONTEXT_SLOTS;
196 if (heap_slots > 0) {
197 // Argument to NewContext is the function, which is still in x1.
198 Comment cmnt(masm_, "[ Allocate context");
199 bool need_write_barrier = true;
200 if (info->scope()->is_script_scope()) {
201 __ Mov(x10, Operand(info->scope()->GetScopeInfo(info->isolate())));
203 __ CallRuntime(Runtime::kNewScriptContext, 2);
204 } else if (heap_slots <= FastNewContextStub::kMaximumSlots) {
205 FastNewContextStub stub(isolate(), heap_slots);
207 // Result of FastNewContextStub is always in new space.
208 need_write_barrier = false;
211 __ CallRuntime(Runtime::kNewFunctionContext, 1);
213 function_in_register_x1 = false;
214 // Context is returned in x0. It replaces the context passed to us.
215 // It's saved in the stack and kept live in cp.
217 __ Str(x0, MemOperand(fp, StandardFrameConstants::kContextOffset));
218 // Copy any necessary parameters into the context.
219 int num_parameters = info->scope()->num_parameters();
220 for (int i = 0; i < num_parameters; i++) {
221 Variable* var = scope()->parameter(i);
222 if (var->IsContextSlot()) {
223 int parameter_offset = StandardFrameConstants::kCallerSPOffset +
224 (num_parameters - 1 - i) * kPointerSize;
225 // Load parameter from stack.
226 __ Ldr(x10, MemOperand(fp, parameter_offset));
227 // Store it in the context.
228 MemOperand target = ContextMemOperand(cp, var->index());
231 // Update the write barrier.
232 if (need_write_barrier) {
233 __ RecordWriteContextSlot(
234 cp, target.offset(), x10, x11, kLRHasBeenSaved, kDontSaveFPRegs);
235 } else if (FLAG_debug_code) {
237 __ JumpIfInNewSpace(cp, &done);
238 __ Abort(kExpectedNewSpaceObject);
245 ArgumentsAccessStub::HasNewTarget has_new_target =
246 IsSubclassConstructor(info->function()->kind())
247 ? ArgumentsAccessStub::HAS_NEW_TARGET
248 : ArgumentsAccessStub::NO_NEW_TARGET;
250 // Possibly allocate RestParameters
252 Variable* rest_param = scope()->rest_parameter(&rest_index);
254 Comment cmnt(masm_, "[ Allocate rest parameter array");
256 int num_parameters = info->scope()->num_parameters();
257 int offset = num_parameters * kPointerSize;
258 if (has_new_target == ArgumentsAccessStub::HAS_NEW_TARGET) {
263 __ Add(x3, fp, StandardFrameConstants::kCallerSPOffset + offset);
264 __ Mov(x2, Smi::FromInt(num_parameters));
265 __ Mov(x1, Smi::FromInt(rest_index));
268 RestParamAccessStub stub(isolate());
271 SetVar(rest_param, x0, x1, x2);
274 Variable* arguments = scope()->arguments();
275 if (arguments != NULL) {
276 // Function uses arguments object.
277 Comment cmnt(masm_, "[ Allocate arguments object");
278 if (!function_in_register_x1) {
279 // Load this again, if it's used by the local context below.
280 __ Ldr(x3, MemOperand(fp, JavaScriptFrameConstants::kFunctionOffset));
284 // Receiver is just before the parameters on the caller's stack.
285 int num_parameters = info->scope()->num_parameters();
286 int offset = num_parameters * kPointerSize;
287 __ Add(x2, fp, StandardFrameConstants::kCallerSPOffset + offset);
288 __ Mov(x1, Smi::FromInt(num_parameters));
291 // Arguments to ArgumentsAccessStub:
292 // function, receiver address, parameter count.
293 // The stub will rewrite receiver and parameter count if the previous
294 // stack frame was an arguments adapter frame.
295 ArgumentsAccessStub::Type type;
296 if (is_strict(language_mode()) || !is_simple_parameter_list()) {
297 type = ArgumentsAccessStub::NEW_STRICT;
298 } else if (function()->has_duplicate_parameters()) {
299 type = ArgumentsAccessStub::NEW_SLOPPY_SLOW;
301 type = ArgumentsAccessStub::NEW_SLOPPY_FAST;
303 ArgumentsAccessStub stub(isolate(), type, has_new_target);
306 SetVar(arguments, x0, x1, x2);
310 __ CallRuntime(Runtime::kTraceEnter, 0);
314 // Visit the declarations and body unless there is an illegal
316 if (scope()->HasIllegalRedeclaration()) {
317 Comment cmnt(masm_, "[ Declarations");
318 scope()->VisitIllegalRedeclaration(this);
321 PrepareForBailoutForId(BailoutId::FunctionEntry(), NO_REGISTERS);
322 { Comment cmnt(masm_, "[ Declarations");
323 if (scope()->is_function_scope() && scope()->function() != NULL) {
324 VariableDeclaration* function = scope()->function();
325 DCHECK(function->proxy()->var()->mode() == CONST ||
326 function->proxy()->var()->mode() == CONST_LEGACY);
327 DCHECK(function->proxy()->var()->location() != Variable::UNALLOCATED);
328 VisitVariableDeclaration(function);
330 VisitDeclarations(scope()->declarations());
334 Comment cmnt(masm_, "[ Stack check");
335 PrepareForBailoutForId(BailoutId::Declarations(), NO_REGISTERS);
337 DCHECK(jssp.Is(__ StackPointer()));
338 __ CompareRoot(jssp, Heap::kStackLimitRootIndex);
340 PredictableCodeSizeScope predictable(masm_,
341 Assembler::kCallSizeWithRelocation);
342 __ Call(isolate()->builtins()->StackCheck(), RelocInfo::CODE_TARGET);
347 Comment cmnt(masm_, "[ Body");
348 DCHECK(loop_depth() == 0);
349 VisitStatements(function()->body());
350 DCHECK(loop_depth() == 0);
354 // Always emit a 'return undefined' in case control fell off the end of
356 { Comment cmnt(masm_, "[ return <undefined>;");
357 __ LoadRoot(x0, Heap::kUndefinedValueRootIndex);
359 EmitReturnSequence();
361 // Force emission of the pools, so they don't get emitted in the middle
362 // of the back edge table.
363 masm()->CheckVeneerPool(true, false);
364 masm()->CheckConstPool(true, false);
368 void FullCodeGenerator::ClearAccumulator() {
369 __ Mov(x0, Smi::FromInt(0));
373 void FullCodeGenerator::EmitProfilingCounterDecrement(int delta) {
374 __ Mov(x2, Operand(profiling_counter_));
375 __ Ldr(x3, FieldMemOperand(x2, Cell::kValueOffset));
376 __ Subs(x3, x3, Smi::FromInt(delta));
377 __ Str(x3, FieldMemOperand(x2, Cell::kValueOffset));
381 void FullCodeGenerator::EmitProfilingCounterReset() {
382 int reset_value = FLAG_interrupt_budget;
383 if (info_->is_debug()) {
384 // Detect debug break requests as soon as possible.
385 reset_value = FLAG_interrupt_budget >> 4;
387 __ Mov(x2, Operand(profiling_counter_));
388 __ Mov(x3, Smi::FromInt(reset_value));
389 __ Str(x3, FieldMemOperand(x2, Cell::kValueOffset));
393 void FullCodeGenerator::EmitBackEdgeBookkeeping(IterationStatement* stmt,
394 Label* back_edge_target) {
395 DCHECK(jssp.Is(__ StackPointer()));
396 Comment cmnt(masm_, "[ Back edge bookkeeping");
397 // Block literal pools whilst emitting back edge code.
398 Assembler::BlockPoolsScope block_const_pool(masm_);
401 DCHECK(back_edge_target->is_bound());
402 // We want to do a round rather than a floor of distance/kCodeSizeMultiplier
403 // to reduce the absolute error due to the integer division. To do that,
404 // we add kCodeSizeMultiplier/2 to the distance (equivalent to adding 0.5 to
407 masm_->SizeOfCodeGeneratedSince(back_edge_target) + kCodeSizeMultiplier / 2;
408 int weight = Min(kMaxBackEdgeWeight,
409 Max(1, distance / kCodeSizeMultiplier));
410 EmitProfilingCounterDecrement(weight);
412 __ Call(isolate()->builtins()->InterruptCheck(), RelocInfo::CODE_TARGET);
414 // Record a mapping of this PC offset to the OSR id. This is used to find
415 // the AST id from the unoptimized code in order to use it as a key into
416 // the deoptimization input data found in the optimized code.
417 RecordBackEdge(stmt->OsrEntryId());
419 EmitProfilingCounterReset();
422 PrepareForBailoutForId(stmt->EntryId(), NO_REGISTERS);
423 // Record a mapping of the OSR id to this PC. This is used if the OSR
424 // entry becomes the target of a bailout. We don't expect it to be, but
425 // we want it to work if it is.
426 PrepareForBailoutForId(stmt->OsrEntryId(), NO_REGISTERS);
430 void FullCodeGenerator::EmitReturnSequence() {
431 Comment cmnt(masm_, "[ Return sequence");
433 if (return_label_.is_bound()) {
434 __ B(&return_label_);
437 __ Bind(&return_label_);
439 // Push the return value on the stack as the parameter.
440 // Runtime::TraceExit returns its parameter in x0.
441 __ Push(result_register());
442 __ CallRuntime(Runtime::kTraceExit, 1);
443 DCHECK(x0.Is(result_register()));
445 // Pretend that the exit is a backwards jump to the entry.
447 if (info_->ShouldSelfOptimize()) {
448 weight = FLAG_interrupt_budget / FLAG_self_opt_count;
450 int distance = masm_->pc_offset() + kCodeSizeMultiplier / 2;
451 weight = Min(kMaxBackEdgeWeight,
452 Max(1, distance / kCodeSizeMultiplier));
454 EmitProfilingCounterDecrement(weight);
458 __ Call(isolate()->builtins()->InterruptCheck(),
459 RelocInfo::CODE_TARGET);
461 EmitProfilingCounterReset();
464 // Make sure that the constant pool is not emitted inside of the return
465 // sequence. This sequence can get patched when the debugger is used. See
466 // debug-arm64.cc:BreakLocation::SetDebugBreakAtReturn().
468 InstructionAccurateScope scope(masm_,
469 Assembler::kJSReturnSequenceInstructions);
470 CodeGenerator::RecordPositions(masm_, function()->end_position() - 1);
472 // This code is generated using Assembler methods rather than Macro
473 // Assembler methods because it will be patched later on, and so the size
474 // of the generated code must be consistent.
475 const Register& current_sp = __ StackPointer();
476 // Nothing ensures 16 bytes alignment here.
477 DCHECK(!current_sp.Is(csp));
478 __ mov(current_sp, fp);
479 int no_frame_start = masm_->pc_offset();
480 __ ldp(fp, lr, MemOperand(current_sp, 2 * kXRegSize, PostIndex));
481 // Drop the arguments and receiver and return.
482 // TODO(all): This implementation is overkill as it supports 2**31+1
483 // arguments, consider how to improve it without creating a security
485 __ ldr_pcrel(ip0, (3 * kInstructionSize) >> kLoadLiteralScaleLog2);
486 __ add(current_sp, current_sp, ip0);
488 int32_t arg_count = info_->scope()->num_parameters() + 1;
489 if (IsSubclassConstructor(info_->function()->kind())) {
492 __ dc64(kXRegSize * arg_count);
493 info_->AddNoFrameRange(no_frame_start, masm_->pc_offset());
499 void FullCodeGenerator::EffectContext::Plug(Variable* var) const {
500 DCHECK(var->IsStackAllocated() || var->IsContextSlot());
504 void FullCodeGenerator::AccumulatorValueContext::Plug(Variable* var) const {
505 DCHECK(var->IsStackAllocated() || var->IsContextSlot());
506 codegen()->GetVar(result_register(), var);
510 void FullCodeGenerator::StackValueContext::Plug(Variable* var) const {
511 DCHECK(var->IsStackAllocated() || var->IsContextSlot());
512 codegen()->GetVar(result_register(), var);
513 __ Push(result_register());
517 void FullCodeGenerator::TestContext::Plug(Variable* var) const {
518 DCHECK(var->IsStackAllocated() || var->IsContextSlot());
519 // For simplicity we always test the accumulator register.
520 codegen()->GetVar(result_register(), var);
521 codegen()->PrepareForBailoutBeforeSplit(condition(), false, NULL, NULL);
522 codegen()->DoTest(this);
526 void FullCodeGenerator::EffectContext::Plug(Heap::RootListIndex index) const {
527 // Root values have no side effects.
531 void FullCodeGenerator::AccumulatorValueContext::Plug(
532 Heap::RootListIndex index) const {
533 __ LoadRoot(result_register(), index);
537 void FullCodeGenerator::StackValueContext::Plug(
538 Heap::RootListIndex index) const {
539 __ LoadRoot(result_register(), index);
540 __ Push(result_register());
544 void FullCodeGenerator::TestContext::Plug(Heap::RootListIndex index) const {
545 codegen()->PrepareForBailoutBeforeSplit(condition(), true, true_label_,
547 if (index == Heap::kUndefinedValueRootIndex ||
548 index == Heap::kNullValueRootIndex ||
549 index == Heap::kFalseValueRootIndex) {
550 if (false_label_ != fall_through_) __ B(false_label_);
551 } else if (index == Heap::kTrueValueRootIndex) {
552 if (true_label_ != fall_through_) __ B(true_label_);
554 __ LoadRoot(result_register(), index);
555 codegen()->DoTest(this);
560 void FullCodeGenerator::EffectContext::Plug(Handle<Object> lit) const {
564 void FullCodeGenerator::AccumulatorValueContext::Plug(
565 Handle<Object> lit) const {
566 __ Mov(result_register(), Operand(lit));
570 void FullCodeGenerator::StackValueContext::Plug(Handle<Object> lit) const {
571 // Immediates cannot be pushed directly.
572 __ Mov(result_register(), Operand(lit));
573 __ Push(result_register());
577 void FullCodeGenerator::TestContext::Plug(Handle<Object> lit) const {
578 codegen()->PrepareForBailoutBeforeSplit(condition(),
582 DCHECK(!lit->IsUndetectableObject()); // There are no undetectable literals.
583 if (lit->IsUndefined() || lit->IsNull() || lit->IsFalse()) {
584 if (false_label_ != fall_through_) __ B(false_label_);
585 } else if (lit->IsTrue() || lit->IsJSObject()) {
586 if (true_label_ != fall_through_) __ B(true_label_);
587 } else if (lit->IsString()) {
588 if (String::cast(*lit)->length() == 0) {
589 if (false_label_ != fall_through_) __ B(false_label_);
591 if (true_label_ != fall_through_) __ B(true_label_);
593 } else if (lit->IsSmi()) {
594 if (Smi::cast(*lit)->value() == 0) {
595 if (false_label_ != fall_through_) __ B(false_label_);
597 if (true_label_ != fall_through_) __ B(true_label_);
600 // For simplicity we always test the accumulator register.
601 __ Mov(result_register(), Operand(lit));
602 codegen()->DoTest(this);
607 void FullCodeGenerator::EffectContext::DropAndPlug(int count,
608 Register reg) const {
614 void FullCodeGenerator::AccumulatorValueContext::DropAndPlug(
616 Register reg) const {
619 __ Move(result_register(), reg);
623 void FullCodeGenerator::StackValueContext::DropAndPlug(int count,
624 Register reg) const {
626 if (count > 1) __ Drop(count - 1);
631 void FullCodeGenerator::TestContext::DropAndPlug(int count,
632 Register reg) const {
634 // For simplicity we always test the accumulator register.
636 __ Mov(result_register(), reg);
637 codegen()->PrepareForBailoutBeforeSplit(condition(), false, NULL, NULL);
638 codegen()->DoTest(this);
642 void FullCodeGenerator::EffectContext::Plug(Label* materialize_true,
643 Label* materialize_false) const {
644 DCHECK(materialize_true == materialize_false);
645 __ Bind(materialize_true);
649 void FullCodeGenerator::AccumulatorValueContext::Plug(
650 Label* materialize_true,
651 Label* materialize_false) const {
653 __ Bind(materialize_true);
654 __ LoadRoot(result_register(), Heap::kTrueValueRootIndex);
656 __ Bind(materialize_false);
657 __ LoadRoot(result_register(), Heap::kFalseValueRootIndex);
662 void FullCodeGenerator::StackValueContext::Plug(
663 Label* materialize_true,
664 Label* materialize_false) const {
666 __ Bind(materialize_true);
667 __ LoadRoot(x10, Heap::kTrueValueRootIndex);
669 __ Bind(materialize_false);
670 __ LoadRoot(x10, Heap::kFalseValueRootIndex);
676 void FullCodeGenerator::TestContext::Plug(Label* materialize_true,
677 Label* materialize_false) const {
678 DCHECK(materialize_true == true_label_);
679 DCHECK(materialize_false == false_label_);
683 void FullCodeGenerator::EffectContext::Plug(bool flag) const {
687 void FullCodeGenerator::AccumulatorValueContext::Plug(bool flag) const {
688 Heap::RootListIndex value_root_index =
689 flag ? Heap::kTrueValueRootIndex : Heap::kFalseValueRootIndex;
690 __ LoadRoot(result_register(), value_root_index);
694 void FullCodeGenerator::StackValueContext::Plug(bool flag) const {
695 Heap::RootListIndex value_root_index =
696 flag ? Heap::kTrueValueRootIndex : Heap::kFalseValueRootIndex;
697 __ LoadRoot(x10, value_root_index);
702 void FullCodeGenerator::TestContext::Plug(bool flag) const {
703 codegen()->PrepareForBailoutBeforeSplit(condition(),
708 if (true_label_ != fall_through_) {
712 if (false_label_ != fall_through_) {
719 void FullCodeGenerator::DoTest(Expression* condition,
722 Label* fall_through) {
723 Handle<Code> ic = ToBooleanStub::GetUninitialized(isolate());
724 CallIC(ic, condition->test_id());
725 __ CompareAndSplit(result_register(), 0, ne, if_true, if_false, fall_through);
729 // If (cond), branch to if_true.
730 // If (!cond), branch to if_false.
731 // fall_through is used as an optimization in cases where only one branch
732 // instruction is necessary.
733 void FullCodeGenerator::Split(Condition cond,
736 Label* fall_through) {
737 if (if_false == fall_through) {
739 } else if (if_true == fall_through) {
740 DCHECK(if_false != fall_through);
741 __ B(NegateCondition(cond), if_false);
749 MemOperand FullCodeGenerator::StackOperand(Variable* var) {
750 // Offset is negative because higher indexes are at lower addresses.
751 int offset = -var->index() * kXRegSize;
752 // Adjust by a (parameter or local) base offset.
753 if (var->IsParameter()) {
754 offset += (info_->scope()->num_parameters() + 1) * kPointerSize;
756 offset += JavaScriptFrameConstants::kLocal0Offset;
758 return MemOperand(fp, offset);
762 MemOperand FullCodeGenerator::VarOperand(Variable* var, Register scratch) {
763 DCHECK(var->IsContextSlot() || var->IsStackAllocated());
764 if (var->IsContextSlot()) {
765 int context_chain_length = scope()->ContextChainLength(var->scope());
766 __ LoadContext(scratch, context_chain_length);
767 return ContextMemOperand(scratch, var->index());
769 return StackOperand(var);
774 void FullCodeGenerator::GetVar(Register dest, Variable* var) {
775 // Use destination as scratch.
776 MemOperand location = VarOperand(var, dest);
777 __ Ldr(dest, location);
781 void FullCodeGenerator::SetVar(Variable* var,
785 DCHECK(var->IsContextSlot() || var->IsStackAllocated());
786 DCHECK(!AreAliased(src, scratch0, scratch1));
787 MemOperand location = VarOperand(var, scratch0);
788 __ Str(src, location);
790 // Emit the write barrier code if the location is in the heap.
791 if (var->IsContextSlot()) {
792 // scratch0 contains the correct context.
793 __ RecordWriteContextSlot(scratch0,
803 void FullCodeGenerator::PrepareForBailoutBeforeSplit(Expression* expr,
804 bool should_normalize,
807 // Only prepare for bailouts before splits if we're in a test
808 // context. Otherwise, we let the Visit function deal with the
809 // preparation to avoid preparing with the same AST id twice.
810 if (!context()->IsTest() || !info_->IsOptimizable()) return;
812 // TODO(all): Investigate to see if there is something to work on here.
814 if (should_normalize) {
817 PrepareForBailout(expr, TOS_REG);
818 if (should_normalize) {
819 __ CompareRoot(x0, Heap::kTrueValueRootIndex);
820 Split(eq, if_true, if_false, NULL);
826 void FullCodeGenerator::EmitDebugCheckDeclarationContext(Variable* variable) {
827 // The variable in the declaration always resides in the current function
829 DCHECK_EQ(0, scope()->ContextChainLength(variable->scope()));
830 if (generate_debug_code_) {
831 // Check that we're not inside a with or catch context.
832 __ Ldr(x1, FieldMemOperand(cp, HeapObject::kMapOffset));
833 __ CompareRoot(x1, Heap::kWithContextMapRootIndex);
834 __ Check(ne, kDeclarationInWithContext);
835 __ CompareRoot(x1, Heap::kCatchContextMapRootIndex);
836 __ Check(ne, kDeclarationInCatchContext);
841 void FullCodeGenerator::VisitVariableDeclaration(
842 VariableDeclaration* declaration) {
843 // If it was not possible to allocate the variable at compile time, we
844 // need to "declare" it at runtime to make sure it actually exists in the
846 VariableProxy* proxy = declaration->proxy();
847 VariableMode mode = declaration->mode();
848 Variable* variable = proxy->var();
849 bool hole_init = mode == LET || mode == CONST || mode == CONST_LEGACY;
851 switch (variable->location()) {
852 case Variable::UNALLOCATED:
853 globals_->Add(variable->name(), zone());
854 globals_->Add(variable->binding_needs_init()
855 ? isolate()->factory()->the_hole_value()
856 : isolate()->factory()->undefined_value(),
860 case Variable::PARAMETER:
861 case Variable::LOCAL:
863 Comment cmnt(masm_, "[ VariableDeclaration");
864 __ LoadRoot(x10, Heap::kTheHoleValueRootIndex);
865 __ Str(x10, StackOperand(variable));
869 case Variable::CONTEXT:
871 Comment cmnt(masm_, "[ VariableDeclaration");
872 EmitDebugCheckDeclarationContext(variable);
873 __ LoadRoot(x10, Heap::kTheHoleValueRootIndex);
874 __ Str(x10, ContextMemOperand(cp, variable->index()));
875 // No write barrier since the_hole_value is in old space.
876 PrepareForBailoutForId(proxy->id(), NO_REGISTERS);
880 case Variable::LOOKUP: {
881 Comment cmnt(masm_, "[ VariableDeclaration");
882 __ Mov(x2, Operand(variable->name()));
883 // Declaration nodes are always introduced in one of four modes.
884 DCHECK(IsDeclaredVariableMode(mode));
885 PropertyAttributes attr = IsImmutableVariableMode(mode) ? READ_ONLY
887 __ Mov(x1, Smi::FromInt(attr));
888 // Push initial value, if any.
889 // Note: For variables we must not push an initial value (such as
890 // 'undefined') because we may have a (legal) redeclaration and we
891 // must not destroy the current value.
893 __ LoadRoot(x0, Heap::kTheHoleValueRootIndex);
894 __ Push(cp, x2, x1, x0);
896 // Pushing 0 (xzr) indicates no initial value.
897 __ Push(cp, x2, x1, xzr);
899 __ CallRuntime(Runtime::kDeclareLookupSlot, 4);
906 void FullCodeGenerator::VisitFunctionDeclaration(
907 FunctionDeclaration* declaration) {
908 VariableProxy* proxy = declaration->proxy();
909 Variable* variable = proxy->var();
910 switch (variable->location()) {
911 case Variable::UNALLOCATED: {
912 globals_->Add(variable->name(), zone());
913 Handle<SharedFunctionInfo> function =
914 Compiler::BuildFunctionInfo(declaration->fun(), script(), info_);
915 // Check for stack overflow exception.
916 if (function.is_null()) return SetStackOverflow();
917 globals_->Add(function, zone());
921 case Variable::PARAMETER:
922 case Variable::LOCAL: {
923 Comment cmnt(masm_, "[ Function Declaration");
924 VisitForAccumulatorValue(declaration->fun());
925 __ Str(result_register(), StackOperand(variable));
929 case Variable::CONTEXT: {
930 Comment cmnt(masm_, "[ Function Declaration");
931 EmitDebugCheckDeclarationContext(variable);
932 VisitForAccumulatorValue(declaration->fun());
933 __ Str(result_register(), ContextMemOperand(cp, variable->index()));
934 int offset = Context::SlotOffset(variable->index());
935 // We know that we have written a function, which is not a smi.
936 __ RecordWriteContextSlot(cp,
944 PrepareForBailoutForId(proxy->id(), NO_REGISTERS);
948 case Variable::LOOKUP: {
949 Comment cmnt(masm_, "[ Function Declaration");
950 __ Mov(x2, Operand(variable->name()));
951 __ Mov(x1, Smi::FromInt(NONE));
953 // Push initial value for function declaration.
954 VisitForStackValue(declaration->fun());
955 __ CallRuntime(Runtime::kDeclareLookupSlot, 4);
962 void FullCodeGenerator::VisitModuleDeclaration(ModuleDeclaration* declaration) {
963 Variable* variable = declaration->proxy()->var();
964 ModuleDescriptor* descriptor = declaration->module()->descriptor();
965 DCHECK(variable->location() == Variable::CONTEXT);
966 DCHECK(descriptor->IsFrozen());
968 Comment cmnt(masm_, "[ ModuleDeclaration");
969 EmitDebugCheckDeclarationContext(variable);
971 // Load instance object.
972 __ LoadContext(x1, scope_->ContextChainLength(scope_->ScriptScope()));
973 __ Ldr(x1, ContextMemOperand(x1, descriptor->Index()));
974 __ Ldr(x1, ContextMemOperand(x1, Context::EXTENSION_INDEX));
977 __ Str(x1, ContextMemOperand(cp, variable->index()));
978 // We know that we have written a module, which is not a smi.
979 __ RecordWriteContextSlot(cp,
980 Context::SlotOffset(variable->index()),
987 PrepareForBailoutForId(declaration->proxy()->id(), NO_REGISTERS);
989 // Traverse info body.
990 Visit(declaration->module());
994 void FullCodeGenerator::VisitImportDeclaration(ImportDeclaration* declaration) {
995 VariableProxy* proxy = declaration->proxy();
996 Variable* variable = proxy->var();
997 switch (variable->location()) {
998 case Variable::UNALLOCATED:
1002 case Variable::CONTEXT: {
1003 Comment cmnt(masm_, "[ ImportDeclaration");
1004 EmitDebugCheckDeclarationContext(variable);
1009 case Variable::PARAMETER:
1010 case Variable::LOCAL:
1011 case Variable::LOOKUP:
1017 void FullCodeGenerator::VisitExportDeclaration(ExportDeclaration* declaration) {
1022 void FullCodeGenerator::DeclareGlobals(Handle<FixedArray> pairs) {
1023 // Call the runtime to declare the globals.
1024 __ Mov(x11, Operand(pairs));
1025 Register flags = xzr;
1026 if (Smi::FromInt(DeclareGlobalsFlags())) {
1028 __ Mov(flags, Smi::FromInt(DeclareGlobalsFlags()));
1030 __ Push(cp, x11, flags);
1031 __ CallRuntime(Runtime::kDeclareGlobals, 3);
1032 // Return value is ignored.
1036 void FullCodeGenerator::DeclareModules(Handle<FixedArray> descriptions) {
1037 // Call the runtime to declare the modules.
1038 __ Push(descriptions);
1039 __ CallRuntime(Runtime::kDeclareModules, 1);
1040 // Return value is ignored.
1044 void FullCodeGenerator::VisitSwitchStatement(SwitchStatement* stmt) {
1045 ASM_LOCATION("FullCodeGenerator::VisitSwitchStatement");
1046 Comment cmnt(masm_, "[ SwitchStatement");
1047 Breakable nested_statement(this, stmt);
1048 SetStatementPosition(stmt);
1050 // Keep the switch value on the stack until a case matches.
1051 VisitForStackValue(stmt->tag());
1052 PrepareForBailoutForId(stmt->EntryId(), NO_REGISTERS);
1054 ZoneList<CaseClause*>* clauses = stmt->cases();
1055 CaseClause* default_clause = NULL; // Can occur anywhere in the list.
1057 Label next_test; // Recycled for each test.
1058 // Compile all the tests with branches to their bodies.
1059 for (int i = 0; i < clauses->length(); i++) {
1060 CaseClause* clause = clauses->at(i);
1061 clause->body_target()->Unuse();
1063 // The default is not a test, but remember it as final fall through.
1064 if (clause->is_default()) {
1065 default_clause = clause;
1069 Comment cmnt(masm_, "[ Case comparison");
1070 __ Bind(&next_test);
1073 // Compile the label expression.
1074 VisitForAccumulatorValue(clause->label());
1076 // Perform the comparison as if via '==='.
1077 __ Peek(x1, 0); // Switch value.
1079 JumpPatchSite patch_site(masm_);
1080 if (ShouldInlineSmiCase(Token::EQ_STRICT)) {
1082 patch_site.EmitJumpIfEitherNotSmi(x0, x1, &slow_case);
1084 __ B(ne, &next_test);
1085 __ Drop(1); // Switch value is no longer needed.
1086 __ B(clause->body_target());
1087 __ Bind(&slow_case);
1090 // Record position before stub call for type feedback.
1091 SetSourcePosition(clause->position());
1093 CodeFactory::CompareIC(isolate(), Token::EQ_STRICT).code();
1094 CallIC(ic, clause->CompareId());
1095 patch_site.EmitPatchInfo();
1099 PrepareForBailout(clause, TOS_REG);
1100 __ JumpIfNotRoot(x0, Heap::kTrueValueRootIndex, &next_test);
1102 __ B(clause->body_target());
1105 __ Cbnz(x0, &next_test);
1106 __ Drop(1); // Switch value is no longer needed.
1107 __ B(clause->body_target());
1110 // Discard the test value and jump to the default if present, otherwise to
1111 // the end of the statement.
1112 __ Bind(&next_test);
1113 __ Drop(1); // Switch value is no longer needed.
1114 if (default_clause == NULL) {
1115 __ B(nested_statement.break_label());
1117 __ B(default_clause->body_target());
1120 // Compile all the case bodies.
1121 for (int i = 0; i < clauses->length(); i++) {
1122 Comment cmnt(masm_, "[ Case body");
1123 CaseClause* clause = clauses->at(i);
1124 __ Bind(clause->body_target());
1125 PrepareForBailoutForId(clause->EntryId(), NO_REGISTERS);
1126 VisitStatements(clause->statements());
1129 __ Bind(nested_statement.break_label());
1130 PrepareForBailoutForId(stmt->ExitId(), NO_REGISTERS);
1134 void FullCodeGenerator::VisitForInStatement(ForInStatement* stmt) {
1135 ASM_LOCATION("FullCodeGenerator::VisitForInStatement");
1136 Comment cmnt(masm_, "[ ForInStatement");
1137 FeedbackVectorSlot slot = stmt->ForInFeedbackSlot();
1138 // TODO(all): This visitor probably needs better comments and a revisit.
1139 SetStatementPosition(stmt);
1142 ForIn loop_statement(this, stmt);
1143 increment_loop_depth();
1145 // Get the object to enumerate over. If the object is null or undefined, skip
1146 // over the loop. See ECMA-262 version 5, section 12.6.4.
1147 SetExpressionPosition(stmt->enumerable());
1148 VisitForAccumulatorValue(stmt->enumerable());
1149 __ JumpIfRoot(x0, Heap::kUndefinedValueRootIndex, &exit);
1150 Register null_value = x15;
1151 __ LoadRoot(null_value, Heap::kNullValueRootIndex);
1152 __ Cmp(x0, null_value);
1155 PrepareForBailoutForId(stmt->PrepareId(), TOS_REG);
1157 // Convert the object to a JS object.
1158 Label convert, done_convert;
1159 __ JumpIfSmi(x0, &convert);
1160 __ JumpIfObjectType(x0, x10, x11, FIRST_SPEC_OBJECT_TYPE, &done_convert, ge);
1163 __ InvokeBuiltin(Builtins::TO_OBJECT, CALL_FUNCTION);
1164 __ Bind(&done_convert);
1165 PrepareForBailoutForId(stmt->ToObjectId(), TOS_REG);
1168 // Check for proxies.
1170 STATIC_ASSERT(FIRST_JS_PROXY_TYPE == FIRST_SPEC_OBJECT_TYPE);
1171 __ JumpIfObjectType(x0, x10, x11, LAST_JS_PROXY_TYPE, &call_runtime, le);
1173 // Check cache validity in generated code. This is a fast case for
1174 // the JSObject::IsSimpleEnum cache validity checks. If we cannot
1175 // guarantee cache validity, call the runtime system to check cache
1176 // validity or get the property names in a fixed array.
1177 __ CheckEnumCache(x0, null_value, x10, x11, x12, x13, &call_runtime);
1179 // The enum cache is valid. Load the map of the object being
1180 // iterated over and use the cache for the iteration.
1182 __ Ldr(x0, FieldMemOperand(x0, HeapObject::kMapOffset));
1185 // Get the set of properties to enumerate.
1186 __ Bind(&call_runtime);
1187 __ Push(x0); // Duplicate the enumerable object on the stack.
1188 __ CallRuntime(Runtime::kGetPropertyNamesFast, 1);
1189 PrepareForBailoutForId(stmt->EnumId(), TOS_REG);
1191 // If we got a map from the runtime call, we can do a fast
1192 // modification check. Otherwise, we got a fixed array, and we have
1193 // to do a slow check.
1194 Label fixed_array, no_descriptors;
1195 __ Ldr(x2, FieldMemOperand(x0, HeapObject::kMapOffset));
1196 __ JumpIfNotRoot(x2, Heap::kMetaMapRootIndex, &fixed_array);
1198 // We got a map in register x0. Get the enumeration cache from it.
1199 __ Bind(&use_cache);
1201 __ EnumLengthUntagged(x1, x0);
1202 __ Cbz(x1, &no_descriptors);
1204 __ LoadInstanceDescriptors(x0, x2);
1205 __ Ldr(x2, FieldMemOperand(x2, DescriptorArray::kEnumCacheOffset));
1207 FieldMemOperand(x2, DescriptorArray::kEnumCacheBridgeCacheOffset));
1209 // Set up the four remaining stack slots.
1211 // Map, enumeration cache, enum cache length, zero (both last as smis).
1212 __ Push(x0, x2, x1, xzr);
1215 __ Bind(&no_descriptors);
1219 // We got a fixed array in register x0. Iterate through that.
1220 __ Bind(&fixed_array);
1222 __ LoadObject(x1, FeedbackVector());
1223 __ Mov(x10, Operand(TypeFeedbackVector::MegamorphicSentinel(isolate())));
1224 int vector_index = FeedbackVector()->GetIndex(slot);
1225 __ Str(x10, FieldMemOperand(x1, FixedArray::OffsetOfElementAt(vector_index)));
1227 __ Mov(x1, Smi::FromInt(1)); // Smi indicates slow check.
1228 __ Peek(x10, 0); // Get enumerated object.
1229 STATIC_ASSERT(FIRST_JS_PROXY_TYPE == FIRST_SPEC_OBJECT_TYPE);
1230 // TODO(all): similar check was done already. Can we avoid it here?
1231 __ CompareObjectType(x10, x11, x12, LAST_JS_PROXY_TYPE);
1232 DCHECK(Smi::FromInt(0) == 0);
1233 __ CzeroX(x1, le); // Zero indicates proxy.
1234 __ Ldr(x2, FieldMemOperand(x0, FixedArray::kLengthOffset));
1235 // Smi and array, fixed array length (as smi) and initial index.
1236 __ Push(x1, x0, x2, xzr);
1238 // Generate code for doing the condition check.
1239 PrepareForBailoutForId(stmt->BodyId(), NO_REGISTERS);
1241 SetExpressionPosition(stmt->each());
1243 // Load the current count to x0, load the length to x1.
1244 __ PeekPair(x0, x1, 0);
1245 __ Cmp(x0, x1); // Compare to the array length.
1246 __ B(hs, loop_statement.break_label());
1248 // Get the current entry of the array into register r3.
1249 __ Peek(x10, 2 * kXRegSize);
1250 __ Add(x10, x10, Operand::UntagSmiAndScale(x0, kPointerSizeLog2));
1251 __ Ldr(x3, MemOperand(x10, FixedArray::kHeaderSize - kHeapObjectTag));
1253 // Get the expected map from the stack or a smi in the
1254 // permanent slow case into register x10.
1255 __ Peek(x2, 3 * kXRegSize);
1257 // Check if the expected map still matches that of the enumerable.
1258 // If not, we may have to filter the key.
1260 __ Peek(x1, 4 * kXRegSize);
1261 __ Ldr(x11, FieldMemOperand(x1, HeapObject::kMapOffset));
1263 __ B(eq, &update_each);
1265 // For proxies, no filtering is done.
1266 // TODO(rossberg): What if only a prototype is a proxy? Not specified yet.
1267 STATIC_ASSERT(kSmiTag == 0);
1268 __ Cbz(x2, &update_each);
1270 // Convert the entry to a string or (smi) 0 if it isn't a property
1271 // any more. If the property has been removed while iterating, we
1274 __ InvokeBuiltin(Builtins::FILTER_KEY, CALL_FUNCTION);
1276 __ Cbz(x0, loop_statement.continue_label());
1278 // Update the 'each' property or variable from the possibly filtered
1279 // entry in register x3.
1280 __ Bind(&update_each);
1281 __ Mov(result_register(), x3);
1282 // Perform the assignment as if via '='.
1283 { EffectContext context(this);
1284 EmitAssignment(stmt->each());
1285 PrepareForBailoutForId(stmt->AssignmentId(), NO_REGISTERS);
1288 // Generate code for the body of the loop.
1289 Visit(stmt->body());
1291 // Generate code for going to the next element by incrementing
1292 // the index (smi) stored on top of the stack.
1293 __ Bind(loop_statement.continue_label());
1294 // TODO(all): We could use a callee saved register to avoid popping.
1296 __ Add(x0, x0, Smi::FromInt(1));
1299 EmitBackEdgeBookkeeping(stmt, &loop);
1302 // Remove the pointers stored on the stack.
1303 __ Bind(loop_statement.break_label());
1306 // Exit and decrement the loop depth.
1307 PrepareForBailoutForId(stmt->ExitId(), NO_REGISTERS);
1309 decrement_loop_depth();
1313 void FullCodeGenerator::EmitNewClosure(Handle<SharedFunctionInfo> info,
1315 // Use the fast case closure allocation code that allocates in new space for
1316 // nested functions that don't need literals cloning. If we're running with
1317 // the --always-opt or the --prepare-always-opt flag, we need to use the
1318 // runtime function so that the new function we are creating here gets a
1319 // chance to have its code optimized and doesn't just get a copy of the
1320 // existing unoptimized code.
1321 if (!FLAG_always_opt &&
1322 !FLAG_prepare_always_opt &&
1324 scope()->is_function_scope() &&
1325 info->num_literals() == 0) {
1326 FastNewClosureStub stub(isolate(), info->language_mode(), info->kind());
1327 __ Mov(x2, Operand(info));
1330 __ Mov(x11, Operand(info));
1331 __ LoadRoot(x10, pretenure ? Heap::kTrueValueRootIndex
1332 : Heap::kFalseValueRootIndex);
1333 __ Push(cp, x11, x10);
1334 __ CallRuntime(Runtime::kNewClosure, 3);
1336 context()->Plug(x0);
1340 void FullCodeGenerator::VisitVariableProxy(VariableProxy* expr) {
1341 Comment cmnt(masm_, "[ VariableProxy");
1342 EmitVariableLoad(expr);
1346 void FullCodeGenerator::EmitLoadHomeObject(SuperReference* expr) {
1347 Comment cnmt(masm_, "[ SuperReference ");
1349 __ ldr(LoadDescriptor::ReceiverRegister(),
1350 MemOperand(fp, JavaScriptFrameConstants::kFunctionOffset));
1352 Handle<Symbol> home_object_symbol(isolate()->heap()->home_object_symbol());
1353 __ Mov(LoadDescriptor::NameRegister(), Operand(home_object_symbol));
1355 if (FLAG_vector_ics) {
1356 __ Mov(VectorLoadICDescriptor::SlotRegister(),
1357 SmiFromSlot(expr->HomeObjectFeedbackSlot()));
1358 CallLoadIC(NOT_CONTEXTUAL);
1360 CallLoadIC(NOT_CONTEXTUAL, expr->HomeObjectFeedbackId());
1363 __ Mov(x10, Operand(isolate()->factory()->undefined_value()));
1367 __ CallRuntime(Runtime::kThrowNonMethodError, 0);
1372 void FullCodeGenerator::EmitSetHomeObjectIfNeeded(Expression* initializer,
1374 if (NeedsHomeObject(initializer)) {
1375 __ Peek(StoreDescriptor::ReceiverRegister(), 0);
1376 __ Mov(StoreDescriptor::NameRegister(),
1377 Operand(isolate()->factory()->home_object_symbol()));
1378 __ Peek(StoreDescriptor::ValueRegister(), offset * kPointerSize);
1384 void FullCodeGenerator::EmitLoadGlobalCheckExtensions(VariableProxy* proxy,
1385 TypeofState typeof_state,
1387 Register current = cp;
1388 Register next = x10;
1389 Register temp = x11;
1393 if (s->num_heap_slots() > 0) {
1394 if (s->calls_sloppy_eval()) {
1395 // Check that extension is NULL.
1396 __ Ldr(temp, ContextMemOperand(current, Context::EXTENSION_INDEX));
1397 __ Cbnz(temp, slow);
1399 // Load next context in chain.
1400 __ Ldr(next, ContextMemOperand(current, Context::PREVIOUS_INDEX));
1401 // Walk the rest of the chain without clobbering cp.
1404 // If no outer scope calls eval, we do not need to check more
1405 // context extensions.
1406 if (!s->outer_scope_calls_sloppy_eval() || s->is_eval_scope()) break;
1407 s = s->outer_scope();
1410 if (s->is_eval_scope()) {
1412 __ Mov(next, current);
1415 // Terminate at native context.
1416 __ Ldr(temp, FieldMemOperand(next, HeapObject::kMapOffset));
1417 __ JumpIfRoot(temp, Heap::kNativeContextMapRootIndex, &fast);
1418 // Check that extension is NULL.
1419 __ Ldr(temp, ContextMemOperand(next, Context::EXTENSION_INDEX));
1420 __ Cbnz(temp, slow);
1421 // Load next context in chain.
1422 __ Ldr(next, ContextMemOperand(next, Context::PREVIOUS_INDEX));
1427 __ Ldr(LoadDescriptor::ReceiverRegister(), GlobalObjectMemOperand());
1428 __ Mov(LoadDescriptor::NameRegister(), Operand(proxy->var()->name()));
1429 if (FLAG_vector_ics) {
1430 __ Mov(VectorLoadICDescriptor::SlotRegister(),
1431 SmiFromSlot(proxy->VariableFeedbackSlot()));
1434 ContextualMode mode = (typeof_state == INSIDE_TYPEOF) ? NOT_CONTEXTUAL
1440 MemOperand FullCodeGenerator::ContextSlotOperandCheckExtensions(Variable* var,
1442 DCHECK(var->IsContextSlot());
1443 Register context = cp;
1444 Register next = x10;
1445 Register temp = x11;
1447 for (Scope* s = scope(); s != var->scope(); s = s->outer_scope()) {
1448 if (s->num_heap_slots() > 0) {
1449 if (s->calls_sloppy_eval()) {
1450 // Check that extension is NULL.
1451 __ Ldr(temp, ContextMemOperand(context, Context::EXTENSION_INDEX));
1452 __ Cbnz(temp, slow);
1454 __ Ldr(next, ContextMemOperand(context, Context::PREVIOUS_INDEX));
1455 // Walk the rest of the chain without clobbering cp.
1459 // Check that last extension is NULL.
1460 __ Ldr(temp, ContextMemOperand(context, Context::EXTENSION_INDEX));
1461 __ Cbnz(temp, slow);
1463 // This function is used only for loads, not stores, so it's safe to
1464 // return an cp-based operand (the write barrier cannot be allowed to
1465 // destroy the cp register).
1466 return ContextMemOperand(context, var->index());
1470 void FullCodeGenerator::EmitDynamicLookupFastCase(VariableProxy* proxy,
1471 TypeofState typeof_state,
1474 // Generate fast-case code for variables that might be shadowed by
1475 // eval-introduced variables. Eval is used a lot without
1476 // introducing variables. In those cases, we do not want to
1477 // perform a runtime call for all variables in the scope
1478 // containing the eval.
1479 Variable* var = proxy->var();
1480 if (var->mode() == DYNAMIC_GLOBAL) {
1481 EmitLoadGlobalCheckExtensions(proxy, typeof_state, slow);
1483 } else if (var->mode() == DYNAMIC_LOCAL) {
1484 Variable* local = var->local_if_not_shadowed();
1485 __ Ldr(x0, ContextSlotOperandCheckExtensions(local, slow));
1486 if (local->mode() == LET || local->mode() == CONST ||
1487 local->mode() == CONST_LEGACY) {
1488 __ JumpIfNotRoot(x0, Heap::kTheHoleValueRootIndex, done);
1489 if (local->mode() == CONST_LEGACY) {
1490 __ LoadRoot(x0, Heap::kUndefinedValueRootIndex);
1491 } else { // LET || CONST
1492 __ Mov(x0, Operand(var->name()));
1494 __ CallRuntime(Runtime::kThrowReferenceError, 1);
1502 void FullCodeGenerator::EmitVariableLoad(VariableProxy* proxy) {
1503 // Record position before possible IC call.
1504 SetSourcePosition(proxy->position());
1505 Variable* var = proxy->var();
1507 // Three cases: global variables, lookup variables, and all other types of
1509 switch (var->location()) {
1510 case Variable::UNALLOCATED: {
1511 Comment cmnt(masm_, "Global variable");
1512 __ Ldr(LoadDescriptor::ReceiverRegister(), GlobalObjectMemOperand());
1513 __ Mov(LoadDescriptor::NameRegister(), Operand(var->name()));
1514 if (FLAG_vector_ics) {
1515 __ Mov(VectorLoadICDescriptor::SlotRegister(),
1516 SmiFromSlot(proxy->VariableFeedbackSlot()));
1518 CallGlobalLoadIC(var->name());
1519 context()->Plug(x0);
1523 case Variable::PARAMETER:
1524 case Variable::LOCAL:
1525 case Variable::CONTEXT: {
1526 Comment cmnt(masm_, var->IsContextSlot()
1527 ? "Context variable"
1528 : "Stack variable");
1529 if (var->binding_needs_init()) {
1530 // var->scope() may be NULL when the proxy is located in eval code and
1531 // refers to a potential outside binding. Currently those bindings are
1532 // always looked up dynamically, i.e. in that case
1533 // var->location() == LOOKUP.
1535 DCHECK(var->scope() != NULL);
1537 // Check if the binding really needs an initialization check. The check
1538 // can be skipped in the following situation: we have a LET or CONST
1539 // binding in harmony mode, both the Variable and the VariableProxy have
1540 // the same declaration scope (i.e. they are both in global code, in the
1541 // same function or in the same eval code) and the VariableProxy is in
1542 // the source physically located after the initializer of the variable.
1544 // We cannot skip any initialization checks for CONST in non-harmony
1545 // mode because const variables may be declared but never initialized:
1546 // if (false) { const x; }; var y = x;
1548 // The condition on the declaration scopes is a conservative check for
1549 // nested functions that access a binding and are called before the
1550 // binding is initialized:
1551 // function() { f(); let x = 1; function f() { x = 2; } }
1553 bool skip_init_check;
1554 if (var->scope()->DeclarationScope() != scope()->DeclarationScope()) {
1555 skip_init_check = false;
1556 } else if (var->is_this()) {
1557 CHECK(info_->function() != nullptr &&
1558 (info_->function()->kind() & kSubclassConstructor) != 0);
1559 // TODO(dslomov): implement 'this' hole check elimination.
1560 skip_init_check = false;
1562 // Check that we always have valid source position.
1563 DCHECK(var->initializer_position() != RelocInfo::kNoPosition);
1564 DCHECK(proxy->position() != RelocInfo::kNoPosition);
1565 skip_init_check = var->mode() != CONST_LEGACY &&
1566 var->initializer_position() < proxy->position();
1569 if (!skip_init_check) {
1570 // Let and const need a read barrier.
1573 __ JumpIfNotRoot(x0, Heap::kTheHoleValueRootIndex, &done);
1574 if (var->mode() == LET || var->mode() == CONST) {
1575 // Throw a reference error when using an uninitialized let/const
1576 // binding in harmony mode.
1577 __ Mov(x0, Operand(var->name()));
1579 __ CallRuntime(Runtime::kThrowReferenceError, 1);
1582 // Uninitalized const bindings outside of harmony mode are unholed.
1583 DCHECK(var->mode() == CONST_LEGACY);
1584 __ LoadRoot(x0, Heap::kUndefinedValueRootIndex);
1587 context()->Plug(x0);
1591 context()->Plug(var);
1595 case Variable::LOOKUP: {
1597 // Generate code for loading from variables potentially shadowed by
1598 // eval-introduced variables.
1599 EmitDynamicLookupFastCase(proxy, NOT_INSIDE_TYPEOF, &slow, &done);
1601 Comment cmnt(masm_, "Lookup variable");
1602 __ Mov(x1, Operand(var->name()));
1603 __ Push(cp, x1); // Context and name.
1604 __ CallRuntime(Runtime::kLoadLookupSlot, 2);
1606 context()->Plug(x0);
1613 void FullCodeGenerator::VisitRegExpLiteral(RegExpLiteral* expr) {
1614 Comment cmnt(masm_, "[ RegExpLiteral");
1616 // Registers will be used as follows:
1617 // x5 = materialized value (RegExp literal)
1618 // x4 = JS function, literals array
1619 // x3 = literal index
1620 // x2 = RegExp pattern
1621 // x1 = RegExp flags
1622 // x0 = RegExp literal clone
1623 __ Ldr(x10, MemOperand(fp, JavaScriptFrameConstants::kFunctionOffset));
1624 __ Ldr(x4, FieldMemOperand(x10, JSFunction::kLiteralsOffset));
1625 int literal_offset =
1626 FixedArray::kHeaderSize + expr->literal_index() * kPointerSize;
1627 __ Ldr(x5, FieldMemOperand(x4, literal_offset));
1628 __ JumpIfNotRoot(x5, Heap::kUndefinedValueRootIndex, &materialized);
1630 // Create regexp literal using runtime function.
1631 // Result will be in x0.
1632 __ Mov(x3, Smi::FromInt(expr->literal_index()));
1633 __ Mov(x2, Operand(expr->pattern()));
1634 __ Mov(x1, Operand(expr->flags()));
1635 __ Push(x4, x3, x2, x1);
1636 __ CallRuntime(Runtime::kMaterializeRegExpLiteral, 4);
1639 __ Bind(&materialized);
1640 int size = JSRegExp::kSize + JSRegExp::kInObjectFieldCount * kPointerSize;
1641 Label allocated, runtime_allocate;
1642 __ Allocate(size, x0, x2, x3, &runtime_allocate, TAG_OBJECT);
1645 __ Bind(&runtime_allocate);
1646 __ Mov(x10, Smi::FromInt(size));
1648 __ CallRuntime(Runtime::kAllocateInNewSpace, 1);
1651 __ Bind(&allocated);
1652 // After this, registers are used as follows:
1653 // x0: Newly allocated regexp.
1654 // x5: Materialized regexp.
1655 // x10, x11, x12: temps.
1656 __ CopyFields(x0, x5, CPURegList(x10, x11, x12), size / kPointerSize);
1657 context()->Plug(x0);
1661 void FullCodeGenerator::EmitAccessor(Expression* expression) {
1662 if (expression == NULL) {
1663 __ LoadRoot(x10, Heap::kNullValueRootIndex);
1666 VisitForStackValue(expression);
1671 void FullCodeGenerator::VisitObjectLiteral(ObjectLiteral* expr) {
1672 Comment cmnt(masm_, "[ ObjectLiteral");
1674 expr->BuildConstantProperties(isolate());
1675 Handle<FixedArray> constant_properties = expr->constant_properties();
1676 __ Ldr(x3, MemOperand(fp, JavaScriptFrameConstants::kFunctionOffset));
1677 __ Ldr(x3, FieldMemOperand(x3, JSFunction::kLiteralsOffset));
1678 __ Mov(x2, Smi::FromInt(expr->literal_index()));
1679 __ Mov(x1, Operand(constant_properties));
1680 int flags = expr->ComputeFlags();
1681 __ Mov(x0, Smi::FromInt(flags));
1682 if (MustCreateObjectLiteralWithRuntime(expr)) {
1683 __ Push(x3, x2, x1, x0);
1684 __ CallRuntime(Runtime::kCreateObjectLiteral, 4);
1686 FastCloneShallowObjectStub stub(isolate(), expr->properties_count());
1689 PrepareForBailoutForId(expr->CreateLiteralId(), TOS_REG);
1691 // If result_saved is true the result is on top of the stack. If
1692 // result_saved is false the result is in x0.
1693 bool result_saved = false;
1695 // Mark all computed expressions that are bound to a key that
1696 // is shadowed by a later occurrence of the same key. For the
1697 // marked expressions, no store code is emitted.
1698 expr->CalculateEmitStore(zone());
1700 AccessorTable accessor_table(zone());
1701 int property_index = 0;
1702 for (; property_index < expr->properties()->length(); property_index++) {
1703 ObjectLiteral::Property* property = expr->properties()->at(property_index);
1704 if (property->is_computed_name()) break;
1705 if (property->IsCompileTimeValue()) continue;
1707 Literal* key = property->key()->AsLiteral();
1708 Expression* value = property->value();
1709 if (!result_saved) {
1710 __ Push(x0); // Save result on stack
1711 result_saved = true;
1713 switch (property->kind()) {
1714 case ObjectLiteral::Property::CONSTANT:
1716 case ObjectLiteral::Property::MATERIALIZED_LITERAL:
1717 DCHECK(!CompileTimeValue::IsCompileTimeValue(property->value()));
1719 case ObjectLiteral::Property::COMPUTED:
1720 // It is safe to use [[Put]] here because the boilerplate already
1721 // contains computed properties with an uninitialized value.
1722 if (key->value()->IsInternalizedString()) {
1723 if (property->emit_store()) {
1724 VisitForAccumulatorValue(value);
1725 DCHECK(StoreDescriptor::ValueRegister().is(x0));
1726 __ Mov(StoreDescriptor::NameRegister(), Operand(key->value()));
1727 __ Peek(StoreDescriptor::ReceiverRegister(), 0);
1728 CallStoreIC(key->LiteralFeedbackId());
1729 PrepareForBailoutForId(key->id(), NO_REGISTERS);
1731 if (NeedsHomeObject(value)) {
1732 __ Mov(StoreDescriptor::ReceiverRegister(), x0);
1733 __ Mov(StoreDescriptor::NameRegister(),
1734 Operand(isolate()->factory()->home_object_symbol()));
1735 __ Peek(StoreDescriptor::ValueRegister(), 0);
1739 VisitForEffect(value);
1743 if (property->emit_store()) {
1744 // Duplicate receiver on stack.
1747 VisitForStackValue(key);
1748 VisitForStackValue(value);
1749 EmitSetHomeObjectIfNeeded(value, 2);
1750 __ Mov(x0, Smi::FromInt(SLOPPY)); // Language mode
1752 __ CallRuntime(Runtime::kSetProperty, 4);
1754 VisitForEffect(key);
1755 VisitForEffect(value);
1758 case ObjectLiteral::Property::PROTOTYPE:
1759 DCHECK(property->emit_store());
1760 // Duplicate receiver on stack.
1763 VisitForStackValue(value);
1764 __ CallRuntime(Runtime::kInternalSetPrototype, 2);
1766 case ObjectLiteral::Property::GETTER:
1767 if (property->emit_store()) {
1768 accessor_table.lookup(key)->second->getter = value;
1771 case ObjectLiteral::Property::SETTER:
1772 if (property->emit_store()) {
1773 accessor_table.lookup(key)->second->setter = value;
1779 // Emit code to define accessors, using only a single call to the runtime for
1780 // each pair of corresponding getters and setters.
1781 for (AccessorTable::Iterator it = accessor_table.begin();
1782 it != accessor_table.end();
1784 __ Peek(x10, 0); // Duplicate receiver.
1786 VisitForStackValue(it->first);
1787 EmitAccessor(it->second->getter);
1788 EmitSetHomeObjectIfNeeded(it->second->getter, 2);
1789 EmitAccessor(it->second->setter);
1790 EmitSetHomeObjectIfNeeded(it->second->setter, 3);
1791 __ Mov(x10, Smi::FromInt(NONE));
1793 __ CallRuntime(Runtime::kDefineAccessorPropertyUnchecked, 5);
1796 // Object literals have two parts. The "static" part on the left contains no
1797 // computed property names, and so we can compute its map ahead of time; see
1798 // runtime.cc::CreateObjectLiteralBoilerplate. The second "dynamic" part
1799 // starts with the first computed property name, and continues with all
1800 // properties to its right. All the code from above initializes the static
1801 // component of the object literal, and arranges for the map of the result to
1802 // reflect the static order in which the keys appear. For the dynamic
1803 // properties, we compile them into a series of "SetOwnProperty" runtime
1804 // calls. This will preserve insertion order.
1805 for (; property_index < expr->properties()->length(); property_index++) {
1806 ObjectLiteral::Property* property = expr->properties()->at(property_index);
1808 Expression* value = property->value();
1809 if (!result_saved) {
1810 __ Push(x0); // Save result on stack
1811 result_saved = true;
1814 __ Peek(x10, 0); // Duplicate receiver.
1817 if (property->kind() == ObjectLiteral::Property::PROTOTYPE) {
1818 DCHECK(!property->is_computed_name());
1819 VisitForStackValue(value);
1820 DCHECK(property->emit_store());
1821 __ CallRuntime(Runtime::kInternalSetPrototype, 2);
1823 EmitPropertyKey(property, expr->GetIdForProperty(property_index));
1824 VisitForStackValue(value);
1825 EmitSetHomeObjectIfNeeded(value, 2);
1827 switch (property->kind()) {
1828 case ObjectLiteral::Property::CONSTANT:
1829 case ObjectLiteral::Property::MATERIALIZED_LITERAL:
1830 case ObjectLiteral::Property::COMPUTED:
1831 if (property->emit_store()) {
1832 __ Mov(x0, Smi::FromInt(NONE));
1834 __ CallRuntime(Runtime::kDefineDataPropertyUnchecked, 4);
1840 case ObjectLiteral::Property::PROTOTYPE:
1844 case ObjectLiteral::Property::GETTER:
1845 __ Mov(x0, Smi::FromInt(NONE));
1847 __ CallRuntime(Runtime::kDefineGetterPropertyUnchecked, 4);
1850 case ObjectLiteral::Property::SETTER:
1851 __ Mov(x0, Smi::FromInt(NONE));
1853 __ CallRuntime(Runtime::kDefineSetterPropertyUnchecked, 4);
1859 if (expr->has_function()) {
1860 DCHECK(result_saved);
1863 __ CallRuntime(Runtime::kToFastProperties, 1);
1867 context()->PlugTOS();
1869 context()->Plug(x0);
1874 void FullCodeGenerator::VisitArrayLiteral(ArrayLiteral* expr) {
1875 Comment cmnt(masm_, "[ ArrayLiteral");
1877 expr->BuildConstantElements(isolate());
1878 Handle<FixedArray> constant_elements = expr->constant_elements();
1879 bool has_fast_elements =
1880 IsFastObjectElementsKind(expr->constant_elements_kind());
1882 AllocationSiteMode allocation_site_mode = TRACK_ALLOCATION_SITE;
1883 if (has_fast_elements && !FLAG_allocation_site_pretenuring) {
1884 // If the only customer of allocation sites is transitioning, then
1885 // we can turn it off if we don't have anywhere else to transition to.
1886 allocation_site_mode = DONT_TRACK_ALLOCATION_SITE;
1889 __ Ldr(x3, MemOperand(fp, JavaScriptFrameConstants::kFunctionOffset));
1890 __ Ldr(x3, FieldMemOperand(x3, JSFunction::kLiteralsOffset));
1891 __ Mov(x2, Smi::FromInt(expr->literal_index()));
1892 __ Mov(x1, Operand(constant_elements));
1893 if (MustCreateArrayLiteralWithRuntime(expr)) {
1894 __ Mov(x0, Smi::FromInt(expr->ComputeFlags()));
1895 __ Push(x3, x2, x1, x0);
1896 __ CallRuntime(Runtime::kCreateArrayLiteral, 4);
1898 FastCloneShallowArrayStub stub(isolate(), allocation_site_mode);
1901 PrepareForBailoutForId(expr->CreateLiteralId(), TOS_REG);
1903 bool result_saved = false; // Is the result saved to the stack?
1904 ZoneList<Expression*>* subexprs = expr->values();
1905 int length = subexprs->length();
1907 // Emit code to evaluate all the non-constant subexpressions and to store
1908 // them into the newly cloned array.
1909 for (int i = 0; i < length; i++) {
1910 Expression* subexpr = subexprs->at(i);
1911 // If the subexpression is a literal or a simple materialized literal it
1912 // is already set in the cloned array.
1913 if (CompileTimeValue::IsCompileTimeValue(subexpr)) continue;
1915 if (!result_saved) {
1916 __ Mov(x1, Smi::FromInt(expr->literal_index()));
1918 result_saved = true;
1920 VisitForAccumulatorValue(subexpr);
1922 if (has_fast_elements) {
1923 int offset = FixedArray::kHeaderSize + (i * kPointerSize);
1924 __ Peek(x6, kPointerSize); // Copy of array literal.
1925 __ Ldr(x1, FieldMemOperand(x6, JSObject::kElementsOffset));
1926 __ Str(result_register(), FieldMemOperand(x1, offset));
1927 // Update the write barrier for the array store.
1928 __ RecordWriteField(x1, offset, result_register(), x10,
1929 kLRHasBeenSaved, kDontSaveFPRegs,
1930 EMIT_REMEMBERED_SET, INLINE_SMI_CHECK);
1932 __ Mov(x3, Smi::FromInt(i));
1933 StoreArrayLiteralElementStub stub(isolate());
1937 PrepareForBailoutForId(expr->GetIdForElement(i), NO_REGISTERS);
1941 __ Drop(1); // literal index
1942 context()->PlugTOS();
1944 context()->Plug(x0);
1949 void FullCodeGenerator::VisitAssignment(Assignment* expr) {
1950 DCHECK(expr->target()->IsValidReferenceExpression());
1952 Comment cmnt(masm_, "[ Assignment");
1954 Property* property = expr->target()->AsProperty();
1955 LhsKind assign_type = GetAssignType(property);
1957 // Evaluate LHS expression.
1958 switch (assign_type) {
1960 // Nothing to do here.
1962 case NAMED_PROPERTY:
1963 if (expr->is_compound()) {
1964 // We need the receiver both on the stack and in the register.
1965 VisitForStackValue(property->obj());
1966 __ Peek(LoadDescriptor::ReceiverRegister(), 0);
1968 VisitForStackValue(property->obj());
1971 case NAMED_SUPER_PROPERTY:
1972 VisitForStackValue(property->obj()->AsSuperReference()->this_var());
1973 EmitLoadHomeObject(property->obj()->AsSuperReference());
1974 __ Push(result_register());
1975 if (expr->is_compound()) {
1976 const Register scratch = x10;
1977 __ Peek(scratch, kPointerSize);
1978 __ Push(scratch, result_register());
1981 case KEYED_SUPER_PROPERTY:
1982 VisitForStackValue(property->obj()->AsSuperReference()->this_var());
1983 EmitLoadHomeObject(property->obj()->AsSuperReference());
1984 __ Push(result_register());
1985 VisitForAccumulatorValue(property->key());
1986 __ Push(result_register());
1987 if (expr->is_compound()) {
1988 const Register scratch1 = x10;
1989 const Register scratch2 = x11;
1990 __ Peek(scratch1, 2 * kPointerSize);
1991 __ Peek(scratch2, kPointerSize);
1992 __ Push(scratch1, scratch2, result_register());
1995 case KEYED_PROPERTY:
1996 if (expr->is_compound()) {
1997 VisitForStackValue(property->obj());
1998 VisitForStackValue(property->key());
1999 __ Peek(LoadDescriptor::ReceiverRegister(), 1 * kPointerSize);
2000 __ Peek(LoadDescriptor::NameRegister(), 0);
2002 VisitForStackValue(property->obj());
2003 VisitForStackValue(property->key());
2008 // For compound assignments we need another deoptimization point after the
2009 // variable/property load.
2010 if (expr->is_compound()) {
2011 { AccumulatorValueContext context(this);
2012 switch (assign_type) {
2014 EmitVariableLoad(expr->target()->AsVariableProxy());
2015 PrepareForBailout(expr->target(), TOS_REG);
2017 case NAMED_PROPERTY:
2018 EmitNamedPropertyLoad(property);
2019 PrepareForBailoutForId(property->LoadId(), TOS_REG);
2021 case NAMED_SUPER_PROPERTY:
2022 EmitNamedSuperPropertyLoad(property);
2023 PrepareForBailoutForId(property->LoadId(), TOS_REG);
2025 case KEYED_SUPER_PROPERTY:
2026 EmitKeyedSuperPropertyLoad(property);
2027 PrepareForBailoutForId(property->LoadId(), TOS_REG);
2029 case KEYED_PROPERTY:
2030 EmitKeyedPropertyLoad(property);
2031 PrepareForBailoutForId(property->LoadId(), TOS_REG);
2036 Token::Value op = expr->binary_op();
2037 __ Push(x0); // Left operand goes on the stack.
2038 VisitForAccumulatorValue(expr->value());
2040 SetSourcePosition(expr->position() + 1);
2041 AccumulatorValueContext context(this);
2042 if (ShouldInlineSmiCase(op)) {
2043 EmitInlineSmiBinaryOp(expr->binary_operation(),
2048 EmitBinaryOp(expr->binary_operation(), op);
2051 // Deoptimization point in case the binary operation may have side effects.
2052 PrepareForBailout(expr->binary_operation(), TOS_REG);
2054 VisitForAccumulatorValue(expr->value());
2057 // Record source position before possible IC call.
2058 SetSourcePosition(expr->position());
2061 switch (assign_type) {
2063 EmitVariableAssignment(expr->target()->AsVariableProxy()->var(),
2065 PrepareForBailoutForId(expr->AssignmentId(), TOS_REG);
2066 context()->Plug(x0);
2068 case NAMED_PROPERTY:
2069 EmitNamedPropertyAssignment(expr);
2071 case NAMED_SUPER_PROPERTY:
2072 EmitNamedSuperPropertyStore(property);
2073 context()->Plug(x0);
2075 case KEYED_SUPER_PROPERTY:
2076 EmitKeyedSuperPropertyStore(property);
2077 context()->Plug(x0);
2079 case KEYED_PROPERTY:
2080 EmitKeyedPropertyAssignment(expr);
2086 void FullCodeGenerator::EmitNamedPropertyLoad(Property* prop) {
2087 SetSourcePosition(prop->position());
2088 Literal* key = prop->key()->AsLiteral();
2089 DCHECK(!prop->IsSuperAccess());
2091 __ Mov(LoadDescriptor::NameRegister(), Operand(key->value()));
2092 if (FLAG_vector_ics) {
2093 __ Mov(VectorLoadICDescriptor::SlotRegister(),
2094 SmiFromSlot(prop->PropertyFeedbackSlot()));
2095 CallLoadIC(NOT_CONTEXTUAL);
2097 CallLoadIC(NOT_CONTEXTUAL, prop->PropertyFeedbackId());
2102 void FullCodeGenerator::EmitNamedSuperPropertyLoad(Property* prop) {
2103 // Stack: receiver, home_object.
2104 SetSourcePosition(prop->position());
2105 Literal* key = prop->key()->AsLiteral();
2106 DCHECK(!key->value()->IsSmi());
2107 DCHECK(prop->IsSuperAccess());
2109 __ Push(key->value());
2110 __ CallRuntime(Runtime::kLoadFromSuper, 3);
2114 void FullCodeGenerator::EmitKeyedPropertyLoad(Property* prop) {
2115 SetSourcePosition(prop->position());
2116 // Call keyed load IC. It has arguments key and receiver in x0 and x1.
2117 Handle<Code> ic = CodeFactory::KeyedLoadIC(isolate()).code();
2118 if (FLAG_vector_ics) {
2119 __ Mov(VectorLoadICDescriptor::SlotRegister(),
2120 SmiFromSlot(prop->PropertyFeedbackSlot()));
2123 CallIC(ic, prop->PropertyFeedbackId());
2128 void FullCodeGenerator::EmitKeyedSuperPropertyLoad(Property* prop) {
2129 // Stack: receiver, home_object, key.
2130 SetSourcePosition(prop->position());
2132 __ CallRuntime(Runtime::kLoadKeyedFromSuper, 3);
2136 void FullCodeGenerator::EmitInlineSmiBinaryOp(BinaryOperation* expr,
2138 Expression* left_expr,
2139 Expression* right_expr) {
2140 Label done, both_smis, stub_call;
2142 // Get the arguments.
2144 Register right = x0;
2145 Register result = x0;
2148 // Perform combined smi check on both operands.
2149 __ Orr(x10, left, right);
2150 JumpPatchSite patch_site(masm_);
2151 patch_site.EmitJumpIfSmi(x10, &both_smis);
2153 __ Bind(&stub_call);
2155 Handle<Code> code = CodeFactory::BinaryOpIC(isolate(), op).code();
2157 Assembler::BlockPoolsScope scope(masm_);
2158 CallIC(code, expr->BinaryOperationFeedbackId());
2159 patch_site.EmitPatchInfo();
2163 __ Bind(&both_smis);
2164 // Smi case. This code works in the same way as the smi-smi case in the type
2165 // recording binary operation stub, see
2166 // BinaryOpStub::GenerateSmiSmiOperation for comments.
2167 // TODO(all): That doesn't exist any more. Where are the comments?
2169 // The set of operations that needs to be supported here is controlled by
2170 // FullCodeGenerator::ShouldInlineSmiCase().
2173 __ Ubfx(right, right, kSmiShift, 5);
2174 __ Asr(result, left, right);
2175 __ Bic(result, result, kSmiShiftMask);
2178 __ Ubfx(right, right, kSmiShift, 5);
2179 __ Lsl(result, left, right);
2182 // If `left >>> right` >= 0x80000000, the result is not representable in a
2183 // signed 32-bit smi.
2184 __ Ubfx(right, right, kSmiShift, 5);
2185 __ Lsr(x10, left, right);
2186 __ Tbnz(x10, kXSignBit, &stub_call);
2187 __ Bic(result, x10, kSmiShiftMask);
2190 __ Adds(x10, left, right);
2191 __ B(vs, &stub_call);
2192 __ Mov(result, x10);
2195 __ Subs(x10, left, right);
2196 __ B(vs, &stub_call);
2197 __ Mov(result, x10);
2200 Label not_minus_zero, done;
2201 STATIC_ASSERT(static_cast<unsigned>(kSmiShift) == (kXRegSizeInBits / 2));
2202 STATIC_ASSERT(kSmiTag == 0);
2203 __ Smulh(x10, left, right);
2204 __ Cbnz(x10, ¬_minus_zero);
2205 __ Eor(x11, left, right);
2206 __ Tbnz(x11, kXSignBit, &stub_call);
2207 __ Mov(result, x10);
2209 __ Bind(¬_minus_zero);
2211 __ Cmp(x11, kXRegSizeInBits - kSmiShift);
2212 __ B(lt, &stub_call);
2213 __ SmiTag(result, x10);
2218 __ Orr(result, left, right);
2220 case Token::BIT_AND:
2221 __ And(result, left, right);
2223 case Token::BIT_XOR:
2224 __ Eor(result, left, right);
2231 context()->Plug(x0);
2235 void FullCodeGenerator::EmitBinaryOp(BinaryOperation* expr, Token::Value op) {
2237 Handle<Code> code = CodeFactory::BinaryOpIC(isolate(), op).code();
2238 JumpPatchSite patch_site(masm_); // Unbound, signals no inlined smi code.
2240 Assembler::BlockPoolsScope scope(masm_);
2241 CallIC(code, expr->BinaryOperationFeedbackId());
2242 patch_site.EmitPatchInfo();
2244 context()->Plug(x0);
2248 void FullCodeGenerator::EmitClassDefineProperties(ClassLiteral* lit) {
2249 // Constructor is in x0.
2250 DCHECK(lit != NULL);
2253 // No access check is needed here since the constructor is created by the
2255 Register scratch = x1;
2257 FieldMemOperand(x0, JSFunction::kPrototypeOrInitialMapOffset));
2260 for (int i = 0; i < lit->properties()->length(); i++) {
2261 ObjectLiteral::Property* property = lit->properties()->at(i);
2262 Expression* value = property->value();
2264 if (property->is_static()) {
2265 __ Peek(scratch, kPointerSize); // constructor
2267 __ Peek(scratch, 0); // prototype
2270 EmitPropertyKey(property, lit->GetIdForProperty(i));
2272 // The static prototype property is read only. We handle the non computed
2273 // property name case in the parser. Since this is the only case where we
2274 // need to check for an own read only property we special case this so we do
2275 // not need to do this for every property.
2276 if (property->is_static() && property->is_computed_name()) {
2277 __ CallRuntime(Runtime::kThrowIfStaticPrototype, 1);
2281 VisitForStackValue(value);
2282 EmitSetHomeObjectIfNeeded(value, 2);
2284 switch (property->kind()) {
2285 case ObjectLiteral::Property::CONSTANT:
2286 case ObjectLiteral::Property::MATERIALIZED_LITERAL:
2287 case ObjectLiteral::Property::PROTOTYPE:
2289 case ObjectLiteral::Property::COMPUTED:
2290 __ CallRuntime(Runtime::kDefineClassMethod, 3);
2293 case ObjectLiteral::Property::GETTER:
2294 __ Mov(x0, Smi::FromInt(DONT_ENUM));
2296 __ CallRuntime(Runtime::kDefineGetterPropertyUnchecked, 4);
2299 case ObjectLiteral::Property::SETTER:
2300 __ Mov(x0, Smi::FromInt(DONT_ENUM));
2302 __ CallRuntime(Runtime::kDefineSetterPropertyUnchecked, 4);
2311 __ CallRuntime(Runtime::kToFastProperties, 1);
2314 __ CallRuntime(Runtime::kToFastProperties, 1);
2318 void FullCodeGenerator::EmitAssignment(Expression* expr) {
2319 DCHECK(expr->IsValidReferenceExpression());
2321 Property* prop = expr->AsProperty();
2322 LhsKind assign_type = GetAssignType(prop);
2324 switch (assign_type) {
2326 Variable* var = expr->AsVariableProxy()->var();
2327 EffectContext context(this);
2328 EmitVariableAssignment(var, Token::ASSIGN);
2331 case NAMED_PROPERTY: {
2332 __ Push(x0); // Preserve value.
2333 VisitForAccumulatorValue(prop->obj());
2334 // TODO(all): We could introduce a VisitForRegValue(reg, expr) to avoid
2336 __ Mov(StoreDescriptor::ReceiverRegister(), x0);
2337 __ Pop(StoreDescriptor::ValueRegister()); // Restore value.
2338 __ Mov(StoreDescriptor::NameRegister(),
2339 Operand(prop->key()->AsLiteral()->value()));
2343 case NAMED_SUPER_PROPERTY: {
2345 VisitForStackValue(prop->obj()->AsSuperReference()->this_var());
2346 EmitLoadHomeObject(prop->obj()->AsSuperReference());
2347 // stack: value, this; x0: home_object
2348 Register scratch = x10;
2349 Register scratch2 = x11;
2350 __ mov(scratch, result_register()); // home_object
2351 __ Peek(x0, kPointerSize); // value
2352 __ Peek(scratch2, 0); // this
2353 __ Poke(scratch2, kPointerSize); // this
2354 __ Poke(scratch, 0); // home_object
2355 // stack: this, home_object; x0: value
2356 EmitNamedSuperPropertyStore(prop);
2359 case KEYED_SUPER_PROPERTY: {
2361 VisitForStackValue(prop->obj()->AsSuperReference()->this_var());
2362 EmitLoadHomeObject(prop->obj()->AsSuperReference());
2363 __ Push(result_register());
2364 VisitForAccumulatorValue(prop->key());
2365 Register scratch = x10;
2366 Register scratch2 = x11;
2367 __ Peek(scratch2, 2 * kPointerSize); // value
2368 // stack: value, this, home_object; x0: key, x11: value
2369 __ Peek(scratch, kPointerSize); // this
2370 __ Poke(scratch, 2 * kPointerSize);
2371 __ Peek(scratch, 0); // home_object
2372 __ Poke(scratch, kPointerSize);
2374 __ Move(x0, scratch2);
2375 // stack: this, home_object, key; x0: value.
2376 EmitKeyedSuperPropertyStore(prop);
2379 case KEYED_PROPERTY: {
2380 __ Push(x0); // Preserve value.
2381 VisitForStackValue(prop->obj());
2382 VisitForAccumulatorValue(prop->key());
2383 __ Mov(StoreDescriptor::NameRegister(), x0);
2384 __ Pop(StoreDescriptor::ReceiverRegister(),
2385 StoreDescriptor::ValueRegister());
2387 CodeFactory::KeyedStoreIC(isolate(), language_mode()).code();
2392 context()->Plug(x0);
2396 void FullCodeGenerator::EmitStoreToStackLocalOrContextSlot(
2397 Variable* var, MemOperand location) {
2398 __ Str(result_register(), location);
2399 if (var->IsContextSlot()) {
2400 // RecordWrite may destroy all its register arguments.
2401 __ Mov(x10, result_register());
2402 int offset = Context::SlotOffset(var->index());
2403 __ RecordWriteContextSlot(
2404 x1, offset, x10, x11, kLRHasBeenSaved, kDontSaveFPRegs);
2409 void FullCodeGenerator::EmitVariableAssignment(Variable* var,
2411 ASM_LOCATION("FullCodeGenerator::EmitVariableAssignment");
2412 if (var->IsUnallocated()) {
2413 // Global var, const, or let.
2414 __ Mov(StoreDescriptor::NameRegister(), Operand(var->name()));
2415 __ Ldr(StoreDescriptor::ReceiverRegister(), GlobalObjectMemOperand());
2418 } else if (var->mode() == LET && op != Token::INIT_LET) {
2419 // Non-initializing assignment to let variable needs a write barrier.
2420 DCHECK(!var->IsLookupSlot());
2421 DCHECK(var->IsStackAllocated() || var->IsContextSlot());
2423 MemOperand location = VarOperand(var, x1);
2424 __ Ldr(x10, location);
2425 __ JumpIfNotRoot(x10, Heap::kTheHoleValueRootIndex, &assign);
2426 __ Mov(x10, Operand(var->name()));
2428 __ CallRuntime(Runtime::kThrowReferenceError, 1);
2429 // Perform the assignment.
2431 EmitStoreToStackLocalOrContextSlot(var, location);
2433 } else if (var->mode() == CONST && op != Token::INIT_CONST) {
2434 // Assignment to const variable needs a write barrier.
2435 DCHECK(!var->IsLookupSlot());
2436 DCHECK(var->IsStackAllocated() || var->IsContextSlot());
2438 MemOperand location = VarOperand(var, x1);
2439 __ Ldr(x10, location);
2440 __ JumpIfNotRoot(x10, Heap::kTheHoleValueRootIndex, &const_error);
2441 __ Mov(x10, Operand(var->name()));
2443 __ CallRuntime(Runtime::kThrowReferenceError, 1);
2444 __ Bind(&const_error);
2445 __ CallRuntime(Runtime::kThrowConstAssignError, 0);
2447 } else if (!var->is_const_mode() || op == Token::INIT_CONST) {
2448 if (var->IsLookupSlot()) {
2449 // Assignment to var.
2450 __ Mov(x11, Operand(var->name()));
2451 __ Mov(x10, Smi::FromInt(language_mode()));
2454 // jssp[16] : context.
2455 // jssp[24] : value.
2456 __ Push(x0, cp, x11, x10);
2457 __ CallRuntime(Runtime::kStoreLookupSlot, 4);
2459 // Assignment to var or initializing assignment to let/const in harmony
2461 DCHECK(var->IsStackAllocated() || var->IsContextSlot());
2462 MemOperand location = VarOperand(var, x1);
2463 if (FLAG_debug_code && op == Token::INIT_LET) {
2464 __ Ldr(x10, location);
2465 __ CompareRoot(x10, Heap::kTheHoleValueRootIndex);
2466 __ Check(eq, kLetBindingReInitialization);
2468 EmitStoreToStackLocalOrContextSlot(var, location);
2471 } else if (op == Token::INIT_CONST_LEGACY) {
2472 // Const initializers need a write barrier.
2473 DCHECK(var->mode() == CONST_LEGACY);
2474 DCHECK(!var->IsParameter()); // No const parameters.
2475 if (var->IsLookupSlot()) {
2476 __ Mov(x1, Operand(var->name()));
2477 __ Push(x0, cp, x1);
2478 __ CallRuntime(Runtime::kInitializeLegacyConstLookupSlot, 3);
2480 DCHECK(var->IsStackLocal() || var->IsContextSlot());
2482 MemOperand location = VarOperand(var, x1);
2483 __ Ldr(x10, location);
2484 __ JumpIfNotRoot(x10, Heap::kTheHoleValueRootIndex, &skip);
2485 EmitStoreToStackLocalOrContextSlot(var, location);
2490 DCHECK(var->mode() == CONST_LEGACY && op != Token::INIT_CONST_LEGACY);
2491 if (is_strict(language_mode())) {
2492 __ CallRuntime(Runtime::kThrowConstAssignError, 0);
2494 // Silently ignore store in sloppy mode.
2499 void FullCodeGenerator::EmitNamedPropertyAssignment(Assignment* expr) {
2500 ASM_LOCATION("FullCodeGenerator::EmitNamedPropertyAssignment");
2501 // Assignment to a property, using a named store IC.
2502 Property* prop = expr->target()->AsProperty();
2503 DCHECK(prop != NULL);
2504 DCHECK(prop->key()->IsLiteral());
2506 // Record source code position before IC call.
2507 SetSourcePosition(expr->position());
2508 __ Mov(StoreDescriptor::NameRegister(),
2509 Operand(prop->key()->AsLiteral()->value()));
2510 __ Pop(StoreDescriptor::ReceiverRegister());
2511 CallStoreIC(expr->AssignmentFeedbackId());
2513 PrepareForBailoutForId(expr->AssignmentId(), TOS_REG);
2514 context()->Plug(x0);
2518 void FullCodeGenerator::EmitNamedSuperPropertyStore(Property* prop) {
2519 // Assignment to named property of super.
2521 // stack : receiver ('this'), home_object
2522 DCHECK(prop != NULL);
2523 Literal* key = prop->key()->AsLiteral();
2524 DCHECK(key != NULL);
2526 __ Push(key->value());
2528 __ CallRuntime((is_strict(language_mode()) ? Runtime::kStoreToSuper_Strict
2529 : Runtime::kStoreToSuper_Sloppy),
2534 void FullCodeGenerator::EmitKeyedSuperPropertyStore(Property* prop) {
2535 // Assignment to named property of super.
2537 // stack : receiver ('this'), home_object, key
2538 DCHECK(prop != NULL);
2542 (is_strict(language_mode()) ? Runtime::kStoreKeyedToSuper_Strict
2543 : Runtime::kStoreKeyedToSuper_Sloppy),
2548 void FullCodeGenerator::EmitKeyedPropertyAssignment(Assignment* expr) {
2549 ASM_LOCATION("FullCodeGenerator::EmitKeyedPropertyAssignment");
2550 // Assignment to a property, using a keyed store IC.
2552 // Record source code position before IC call.
2553 SetSourcePosition(expr->position());
2554 // TODO(all): Could we pass this in registers rather than on the stack?
2555 __ Pop(StoreDescriptor::NameRegister(), StoreDescriptor::ReceiverRegister());
2556 DCHECK(StoreDescriptor::ValueRegister().is(x0));
2559 CodeFactory::KeyedStoreIC(isolate(), language_mode()).code();
2560 CallIC(ic, expr->AssignmentFeedbackId());
2562 PrepareForBailoutForId(expr->AssignmentId(), TOS_REG);
2563 context()->Plug(x0);
2567 void FullCodeGenerator::VisitProperty(Property* expr) {
2568 Comment cmnt(masm_, "[ Property");
2569 Expression* key = expr->key();
2571 if (key->IsPropertyName()) {
2572 if (!expr->IsSuperAccess()) {
2573 VisitForAccumulatorValue(expr->obj());
2574 __ Move(LoadDescriptor::ReceiverRegister(), x0);
2575 EmitNamedPropertyLoad(expr);
2577 VisitForStackValue(expr->obj()->AsSuperReference()->this_var());
2578 EmitLoadHomeObject(expr->obj()->AsSuperReference());
2579 __ Push(result_register());
2580 EmitNamedSuperPropertyLoad(expr);
2583 if (!expr->IsSuperAccess()) {
2584 VisitForStackValue(expr->obj());
2585 VisitForAccumulatorValue(expr->key());
2586 __ Move(LoadDescriptor::NameRegister(), x0);
2587 __ Pop(LoadDescriptor::ReceiverRegister());
2588 EmitKeyedPropertyLoad(expr);
2590 VisitForStackValue(expr->obj()->AsSuperReference()->this_var());
2591 EmitLoadHomeObject(expr->obj()->AsSuperReference());
2592 __ Push(result_register());
2593 VisitForStackValue(expr->key());
2594 EmitKeyedSuperPropertyLoad(expr);
2597 PrepareForBailoutForId(expr->LoadId(), TOS_REG);
2598 context()->Plug(x0);
2602 void FullCodeGenerator::CallIC(Handle<Code> code,
2603 TypeFeedbackId ast_id) {
2605 // All calls must have a predictable size in full-codegen code to ensure that
2606 // the debugger can patch them correctly.
2607 __ Call(code, RelocInfo::CODE_TARGET, ast_id);
2611 // Code common for calls using the IC.
2612 void FullCodeGenerator::EmitCallWithLoadIC(Call* expr) {
2613 Expression* callee = expr->expression();
2615 CallICState::CallType call_type =
2616 callee->IsVariableProxy() ? CallICState::FUNCTION : CallICState::METHOD;
2618 // Get the target function.
2619 if (call_type == CallICState::FUNCTION) {
2620 { StackValueContext context(this);
2621 EmitVariableLoad(callee->AsVariableProxy());
2622 PrepareForBailout(callee, NO_REGISTERS);
2624 // Push undefined as receiver. This is patched in the method prologue if it
2625 // is a sloppy mode method.
2627 UseScratchRegisterScope temps(masm_);
2628 Register temp = temps.AcquireX();
2629 __ LoadRoot(temp, Heap::kUndefinedValueRootIndex);
2633 // Load the function from the receiver.
2634 DCHECK(callee->IsProperty());
2635 DCHECK(!callee->AsProperty()->IsSuperAccess());
2636 __ Peek(LoadDescriptor::ReceiverRegister(), 0);
2637 EmitNamedPropertyLoad(callee->AsProperty());
2638 PrepareForBailoutForId(callee->AsProperty()->LoadId(), TOS_REG);
2639 // Push the target function under the receiver.
2644 EmitCall(expr, call_type);
2648 void FullCodeGenerator::EmitSuperCallWithLoadIC(Call* expr) {
2649 Expression* callee = expr->expression();
2650 DCHECK(callee->IsProperty());
2651 Property* prop = callee->AsProperty();
2652 DCHECK(prop->IsSuperAccess());
2654 SetSourcePosition(prop->position());
2655 Literal* key = prop->key()->AsLiteral();
2656 DCHECK(!key->value()->IsSmi());
2658 // Load the function from the receiver.
2659 const Register scratch = x10;
2660 SuperReference* super_ref = callee->AsProperty()->obj()->AsSuperReference();
2661 EmitLoadHomeObject(super_ref);
2663 VisitForAccumulatorValue(super_ref->this_var());
2665 __ Peek(scratch, kPointerSize);
2666 __ Push(x0, scratch);
2667 __ Push(key->value());
2671 // - this (receiver)
2672 // - this (receiver) <-- LoadFromSuper will pop here and below.
2675 __ CallRuntime(Runtime::kLoadFromSuper, 3);
2677 // Replace home_object with target function.
2678 __ Poke(x0, kPointerSize);
2681 // - target function
2682 // - this (receiver)
2683 EmitCall(expr, CallICState::METHOD);
2687 // Code common for calls using the IC.
2688 void FullCodeGenerator::EmitKeyedCallWithLoadIC(Call* expr,
2691 VisitForAccumulatorValue(key);
2693 Expression* callee = expr->expression();
2695 // Load the function from the receiver.
2696 DCHECK(callee->IsProperty());
2697 __ Peek(LoadDescriptor::ReceiverRegister(), 0);
2698 __ Move(LoadDescriptor::NameRegister(), x0);
2699 EmitKeyedPropertyLoad(callee->AsProperty());
2700 PrepareForBailoutForId(callee->AsProperty()->LoadId(), TOS_REG);
2702 // Push the target function under the receiver.
2706 EmitCall(expr, CallICState::METHOD);
2710 void FullCodeGenerator::EmitKeyedSuperCallWithLoadIC(Call* expr) {
2711 Expression* callee = expr->expression();
2712 DCHECK(callee->IsProperty());
2713 Property* prop = callee->AsProperty();
2714 DCHECK(prop->IsSuperAccess());
2716 SetSourcePosition(prop->position());
2718 // Load the function from the receiver.
2719 const Register scratch = x10;
2720 SuperReference* super_ref = callee->AsProperty()->obj()->AsSuperReference();
2721 EmitLoadHomeObject(super_ref);
2723 VisitForAccumulatorValue(super_ref->this_var());
2725 __ Peek(scratch, kPointerSize);
2726 __ Push(x0, scratch);
2727 VisitForStackValue(prop->key());
2731 // - this (receiver)
2732 // - this (receiver) <-- LoadKeyedFromSuper will pop here and below.
2735 __ CallRuntime(Runtime::kLoadKeyedFromSuper, 3);
2737 // Replace home_object with target function.
2738 __ Poke(x0, kPointerSize);
2741 // - target function
2742 // - this (receiver)
2743 EmitCall(expr, CallICState::METHOD);
2747 void FullCodeGenerator::EmitCall(Call* expr, CallICState::CallType call_type) {
2748 // Load the arguments.
2749 ZoneList<Expression*>* args = expr->arguments();
2750 int arg_count = args->length();
2751 { PreservePositionScope scope(masm()->positions_recorder());
2752 for (int i = 0; i < arg_count; i++) {
2753 VisitForStackValue(args->at(i));
2756 // Record source position of the IC call.
2757 SetSourcePosition(expr->position());
2759 Handle<Code> ic = CodeFactory::CallIC(isolate(), arg_count, call_type).code();
2760 __ Mov(x3, SmiFromSlot(expr->CallFeedbackICSlot()));
2761 __ Peek(x1, (arg_count + 1) * kXRegSize);
2762 // Don't assign a type feedback id to the IC, since type feedback is provided
2763 // by the vector above.
2766 RecordJSReturnSite(expr);
2767 // Restore context register.
2768 __ Ldr(cp, MemOperand(fp, StandardFrameConstants::kContextOffset));
2769 context()->DropAndPlug(1, x0);
2773 void FullCodeGenerator::EmitResolvePossiblyDirectEval(int arg_count) {
2774 ASM_LOCATION("FullCodeGenerator::EmitResolvePossiblyDirectEval");
2775 // Prepare to push a copy of the first argument or undefined if it doesn't
2777 if (arg_count > 0) {
2778 __ Peek(x9, arg_count * kXRegSize);
2780 __ LoadRoot(x9, Heap::kUndefinedValueRootIndex);
2783 __ Ldr(x10, MemOperand(fp, JavaScriptFrameConstants::kFunctionOffset));
2784 // Prepare to push the receiver of the enclosing function.
2785 int receiver_offset = 2 + info_->scope()->num_parameters();
2786 __ Ldr(x11, MemOperand(fp, receiver_offset * kPointerSize));
2788 // Prepare to push the language mode.
2789 __ Mov(x12, Smi::FromInt(language_mode()));
2790 // Prepare to push the start position of the scope the calls resides in.
2791 __ Mov(x13, Smi::FromInt(scope()->start_position()));
2794 __ Push(x9, x10, x11, x12, x13);
2796 // Do the runtime call.
2797 __ CallRuntime(Runtime::kResolvePossiblyDirectEval, 6);
2801 void FullCodeGenerator::EmitLoadSuperConstructor() {
2802 __ ldr(x0, MemOperand(fp, JavaScriptFrameConstants::kFunctionOffset));
2804 __ CallRuntime(Runtime::kGetPrototype, 1);
2808 void FullCodeGenerator::VisitCall(Call* expr) {
2810 // We want to verify that RecordJSReturnSite gets called on all paths
2811 // through this function. Avoid early returns.
2812 expr->return_is_recorded_ = false;
2815 Comment cmnt(masm_, "[ Call");
2816 Expression* callee = expr->expression();
2817 Call::CallType call_type = expr->GetCallType(isolate());
2819 if (call_type == Call::POSSIBLY_EVAL_CALL) {
2820 // In a call to eval, we first call RuntimeHidden_ResolvePossiblyDirectEval
2821 // to resolve the function we need to call and the receiver of the
2822 // call. Then we call the resolved function using the given
2824 ZoneList<Expression*>* args = expr->arguments();
2825 int arg_count = args->length();
2828 PreservePositionScope pos_scope(masm()->positions_recorder());
2829 VisitForStackValue(callee);
2830 __ LoadRoot(x10, Heap::kUndefinedValueRootIndex);
2831 __ Push(x10); // Reserved receiver slot.
2833 // Push the arguments.
2834 for (int i = 0; i < arg_count; i++) {
2835 VisitForStackValue(args->at(i));
2838 // Push a copy of the function (found below the arguments) and
2840 __ Peek(x10, (arg_count + 1) * kPointerSize);
2842 EmitResolvePossiblyDirectEval(arg_count);
2844 // The runtime call returns a pair of values in x0 (function) and
2845 // x1 (receiver). Touch up the stack with the right values.
2846 __ PokePair(x1, x0, arg_count * kPointerSize);
2848 PrepareForBailoutForId(expr->EvalOrLookupId(), NO_REGISTERS);
2851 // Record source position for debugger.
2852 SetSourcePosition(expr->position());
2854 // Call the evaluated function.
2855 CallFunctionStub stub(isolate(), arg_count, NO_CALL_FUNCTION_FLAGS);
2856 __ Peek(x1, (arg_count + 1) * kXRegSize);
2858 RecordJSReturnSite(expr);
2859 // Restore context register.
2860 __ Ldr(cp, MemOperand(fp, StandardFrameConstants::kContextOffset));
2861 context()->DropAndPlug(1, x0);
2863 } else if (call_type == Call::GLOBAL_CALL) {
2864 EmitCallWithLoadIC(expr);
2866 } else if (call_type == Call::LOOKUP_SLOT_CALL) {
2867 // Call to a lookup slot (dynamically introduced variable).
2868 VariableProxy* proxy = callee->AsVariableProxy();
2871 { PreservePositionScope scope(masm()->positions_recorder());
2872 // Generate code for loading from variables potentially shadowed
2873 // by eval-introduced variables.
2874 EmitDynamicLookupFastCase(proxy, NOT_INSIDE_TYPEOF, &slow, &done);
2878 // Call the runtime to find the function to call (returned in x0)
2879 // and the object holding it (returned in x1).
2880 __ Mov(x10, Operand(proxy->name()));
2881 __ Push(context_register(), x10);
2882 __ CallRuntime(Runtime::kLoadLookupSlot, 2);
2883 __ Push(x0, x1); // Receiver, function.
2884 PrepareForBailoutForId(expr->EvalOrLookupId(), NO_REGISTERS);
2886 // If fast case code has been generated, emit code to push the
2887 // function and receiver and have the slow path jump around this
2889 if (done.is_linked()) {
2894 // The receiver is implicitly the global receiver. Indicate this
2895 // by passing the undefined to the call function stub.
2896 __ LoadRoot(x1, Heap::kUndefinedValueRootIndex);
2901 // The receiver is either the global receiver or an object found
2902 // by LoadContextSlot.
2904 } else if (call_type == Call::PROPERTY_CALL) {
2905 Property* property = callee->AsProperty();
2906 bool is_named_call = property->key()->IsPropertyName();
2907 if (property->IsSuperAccess()) {
2908 if (is_named_call) {
2909 EmitSuperCallWithLoadIC(expr);
2911 EmitKeyedSuperCallWithLoadIC(expr);
2915 PreservePositionScope scope(masm()->positions_recorder());
2916 VisitForStackValue(property->obj());
2918 if (is_named_call) {
2919 EmitCallWithLoadIC(expr);
2921 EmitKeyedCallWithLoadIC(expr, property->key());
2924 } else if (call_type == Call::SUPER_CALL) {
2925 EmitSuperConstructorCall(expr);
2927 DCHECK(call_type == Call::OTHER_CALL);
2928 // Call to an arbitrary expression not handled specially above.
2929 { PreservePositionScope scope(masm()->positions_recorder());
2930 VisitForStackValue(callee);
2932 __ LoadRoot(x1, Heap::kUndefinedValueRootIndex);
2934 // Emit function call.
2939 // RecordJSReturnSite should have been called.
2940 DCHECK(expr->return_is_recorded_);
2945 void FullCodeGenerator::VisitCallNew(CallNew* expr) {
2946 Comment cmnt(masm_, "[ CallNew");
2947 // According to ECMA-262, section 11.2.2, page 44, the function
2948 // expression in new calls must be evaluated before the
2951 // Push constructor on the stack. If it's not a function it's used as
2952 // receiver for CALL_NON_FUNCTION, otherwise the value on the stack is
2954 DCHECK(!expr->expression()->IsSuperReference());
2955 VisitForStackValue(expr->expression());
2957 // Push the arguments ("left-to-right") on the stack.
2958 ZoneList<Expression*>* args = expr->arguments();
2959 int arg_count = args->length();
2960 for (int i = 0; i < arg_count; i++) {
2961 VisitForStackValue(args->at(i));
2964 // Call the construct call builtin that handles allocation and
2965 // constructor invocation.
2966 SetSourcePosition(expr->position());
2968 // Load function and argument count into x1 and x0.
2969 __ Mov(x0, arg_count);
2970 __ Peek(x1, arg_count * kXRegSize);
2972 // Record call targets in unoptimized code.
2973 if (FLAG_pretenuring_call_new) {
2974 EnsureSlotContainsAllocationSite(expr->AllocationSiteFeedbackSlot());
2975 DCHECK(expr->AllocationSiteFeedbackSlot().ToInt() ==
2976 expr->CallNewFeedbackSlot().ToInt() + 1);
2979 __ LoadObject(x2, FeedbackVector());
2980 __ Mov(x3, SmiFromSlot(expr->CallNewFeedbackSlot()));
2982 CallConstructStub stub(isolate(), RECORD_CONSTRUCTOR_TARGET);
2983 __ Call(stub.GetCode(), RelocInfo::CONSTRUCT_CALL);
2984 PrepareForBailoutForId(expr->ReturnId(), TOS_REG);
2985 context()->Plug(x0);
2989 void FullCodeGenerator::EmitSuperConstructorCall(Call* expr) {
2990 Variable* new_target_var = scope()->DeclarationScope()->new_target_var();
2991 GetVar(result_register(), new_target_var);
2992 __ Push(result_register());
2994 EmitLoadSuperConstructor();
2995 __ push(result_register());
2997 // Push the arguments ("left-to-right") on the stack.
2998 ZoneList<Expression*>* args = expr->arguments();
2999 int arg_count = args->length();
3000 for (int i = 0; i < arg_count; i++) {
3001 VisitForStackValue(args->at(i));
3004 // Call the construct call builtin that handles allocation and
3005 // constructor invocation.
3006 SetSourcePosition(expr->position());
3008 // Load function and argument count into x1 and x0.
3009 __ Mov(x0, arg_count);
3010 __ Peek(x1, arg_count * kXRegSize);
3012 // Record call targets in unoptimized code.
3013 if (FLAG_pretenuring_call_new) {
3015 /* TODO(dslomov): support pretenuring.
3016 EnsureSlotContainsAllocationSite(expr->AllocationSiteFeedbackSlot());
3017 DCHECK(expr->AllocationSiteFeedbackSlot().ToInt() ==
3018 expr->CallNewFeedbackSlot().ToInt() + 1);
3022 __ LoadObject(x2, FeedbackVector());
3023 __ Mov(x3, SmiFromSlot(expr->CallFeedbackSlot()));
3025 CallConstructStub stub(isolate(), SUPER_CALL_RECORD_TARGET);
3026 __ Call(stub.GetCode(), RelocInfo::CONSTRUCT_CALL);
3030 RecordJSReturnSite(expr);
3032 SuperReference* super_ref = expr->expression()->AsSuperReference();
3033 Variable* this_var = super_ref->this_var()->var();
3034 GetVar(x1, this_var);
3035 Label uninitialized_this;
3036 __ JumpIfRoot(x1, Heap::kTheHoleValueRootIndex, &uninitialized_this);
3037 __ Mov(x0, Operand(this_var->name()));
3039 __ CallRuntime(Runtime::kThrowReferenceError, 1);
3040 __ bind(&uninitialized_this);
3042 EmitVariableAssignment(this_var, Token::INIT_CONST);
3043 context()->Plug(x0);
3047 void FullCodeGenerator::EmitIsSmi(CallRuntime* expr) {
3048 ZoneList<Expression*>* args = expr->arguments();
3049 DCHECK(args->length() == 1);
3051 VisitForAccumulatorValue(args->at(0));
3053 Label materialize_true, materialize_false;
3054 Label* if_true = NULL;
3055 Label* if_false = NULL;
3056 Label* fall_through = NULL;
3057 context()->PrepareTest(&materialize_true, &materialize_false,
3058 &if_true, &if_false, &fall_through);
3060 PrepareForBailoutBeforeSplit(expr, true, if_true, if_false);
3061 __ TestAndSplit(x0, kSmiTagMask, if_true, if_false, fall_through);
3063 context()->Plug(if_true, if_false);
3067 void FullCodeGenerator::EmitIsNonNegativeSmi(CallRuntime* expr) {
3068 ZoneList<Expression*>* args = expr->arguments();
3069 DCHECK(args->length() == 1);
3071 VisitForAccumulatorValue(args->at(0));
3073 Label materialize_true, materialize_false;
3074 Label* if_true = NULL;
3075 Label* if_false = NULL;
3076 Label* fall_through = NULL;
3077 context()->PrepareTest(&materialize_true, &materialize_false,
3078 &if_true, &if_false, &fall_through);
3080 uint64_t sign_mask = V8_UINT64_C(1) << (kSmiShift + kSmiValueSize - 1);
3082 PrepareForBailoutBeforeSplit(expr, true, if_true, if_false);
3083 __ TestAndSplit(x0, kSmiTagMask | sign_mask, if_true, if_false, fall_through);
3085 context()->Plug(if_true, if_false);
3089 void FullCodeGenerator::EmitIsObject(CallRuntime* expr) {
3090 ZoneList<Expression*>* args = expr->arguments();
3091 DCHECK(args->length() == 1);
3093 VisitForAccumulatorValue(args->at(0));
3095 Label materialize_true, materialize_false;
3096 Label* if_true = NULL;
3097 Label* if_false = NULL;
3098 Label* fall_through = NULL;
3099 context()->PrepareTest(&materialize_true, &materialize_false,
3100 &if_true, &if_false, &fall_through);
3102 __ JumpIfSmi(x0, if_false);
3103 __ JumpIfRoot(x0, Heap::kNullValueRootIndex, if_true);
3104 __ Ldr(x10, FieldMemOperand(x0, HeapObject::kMapOffset));
3105 // Undetectable objects behave like undefined when tested with typeof.
3106 __ Ldrb(x11, FieldMemOperand(x10, Map::kBitFieldOffset));
3107 __ Tbnz(x11, Map::kIsUndetectable, if_false);
3108 __ Ldrb(x12, FieldMemOperand(x10, Map::kInstanceTypeOffset));
3109 __ Cmp(x12, FIRST_NONCALLABLE_SPEC_OBJECT_TYPE);
3111 __ Cmp(x12, LAST_NONCALLABLE_SPEC_OBJECT_TYPE);
3112 PrepareForBailoutBeforeSplit(expr, true, if_true, if_false);
3113 Split(le, if_true, if_false, fall_through);
3115 context()->Plug(if_true, if_false);
3119 void FullCodeGenerator::EmitIsSpecObject(CallRuntime* expr) {
3120 ZoneList<Expression*>* args = expr->arguments();
3121 DCHECK(args->length() == 1);
3123 VisitForAccumulatorValue(args->at(0));
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);
3132 __ JumpIfSmi(x0, if_false);
3133 __ CompareObjectType(x0, x10, x11, FIRST_SPEC_OBJECT_TYPE);
3134 PrepareForBailoutBeforeSplit(expr, true, if_true, if_false);
3135 Split(ge, if_true, if_false, fall_through);
3137 context()->Plug(if_true, if_false);
3141 void FullCodeGenerator::EmitIsUndetectableObject(CallRuntime* expr) {
3142 ASM_LOCATION("FullCodeGenerator::EmitIsUndetectableObject");
3143 ZoneList<Expression*>* args = expr->arguments();
3144 DCHECK(args->length() == 1);
3146 VisitForAccumulatorValue(args->at(0));
3148 Label materialize_true, materialize_false;
3149 Label* if_true = NULL;
3150 Label* if_false = NULL;
3151 Label* fall_through = NULL;
3152 context()->PrepareTest(&materialize_true, &materialize_false,
3153 &if_true, &if_false, &fall_through);
3155 __ JumpIfSmi(x0, if_false);
3156 __ Ldr(x10, FieldMemOperand(x0, HeapObject::kMapOffset));
3157 __ Ldrb(x11, FieldMemOperand(x10, Map::kBitFieldOffset));
3158 __ Tst(x11, 1 << Map::kIsUndetectable);
3159 PrepareForBailoutBeforeSplit(expr, true, if_true, if_false);
3160 Split(ne, if_true, if_false, fall_through);
3162 context()->Plug(if_true, if_false);
3166 void FullCodeGenerator::EmitIsStringWrapperSafeForDefaultValueOf(
3167 CallRuntime* expr) {
3168 ZoneList<Expression*>* args = expr->arguments();
3169 DCHECK(args->length() == 1);
3170 VisitForAccumulatorValue(args->at(0));
3172 Label materialize_true, materialize_false, skip_lookup;
3173 Label* if_true = NULL;
3174 Label* if_false = NULL;
3175 Label* fall_through = NULL;
3176 context()->PrepareTest(&materialize_true, &materialize_false,
3177 &if_true, &if_false, &fall_through);
3179 Register object = x0;
3180 __ AssertNotSmi(object);
3183 Register bitfield2 = x11;
3184 __ Ldr(map, FieldMemOperand(object, HeapObject::kMapOffset));
3185 __ Ldrb(bitfield2, FieldMemOperand(map, Map::kBitField2Offset));
3186 __ Tbnz(bitfield2, Map::kStringWrapperSafeForDefaultValueOf, &skip_lookup);
3188 // Check for fast case object. Generate false result for slow case object.
3189 Register props = x12;
3190 Register props_map = x12;
3191 Register hash_table_map = x13;
3192 __ Ldr(props, FieldMemOperand(object, JSObject::kPropertiesOffset));
3193 __ Ldr(props_map, FieldMemOperand(props, HeapObject::kMapOffset));
3194 __ LoadRoot(hash_table_map, Heap::kHashTableMapRootIndex);
3195 __ Cmp(props_map, hash_table_map);
3198 // Look for valueOf name in the descriptor array, and indicate false if found.
3199 // Since we omit an enumeration index check, if it is added via a transition
3200 // that shares its descriptor array, this is a false positive.
3203 // Skip loop if no descriptors are valid.
3204 Register descriptors = x12;
3205 Register descriptors_length = x13;
3206 __ NumberOfOwnDescriptors(descriptors_length, map);
3207 __ Cbz(descriptors_length, &done);
3209 __ LoadInstanceDescriptors(map, descriptors);
3211 // Calculate the end of the descriptor array.
3212 Register descriptors_end = x14;
3213 __ Mov(x15, DescriptorArray::kDescriptorSize);
3214 __ Mul(descriptors_length, descriptors_length, x15);
3215 // Calculate location of the first key name.
3216 __ Add(descriptors, descriptors,
3217 DescriptorArray::kFirstOffset - kHeapObjectTag);
3218 // Calculate the end of the descriptor array.
3219 __ Add(descriptors_end, descriptors,
3220 Operand(descriptors_length, LSL, kPointerSizeLog2));
3222 // Loop through all the keys in the descriptor array. If one of these is the
3223 // string "valueOf" the result is false.
3224 Register valueof_string = x1;
3225 int descriptor_size = DescriptorArray::kDescriptorSize * kPointerSize;
3226 __ Mov(valueof_string, Operand(isolate()->factory()->value_of_string()));
3228 __ Ldr(x15, MemOperand(descriptors, descriptor_size, PostIndex));
3229 __ Cmp(x15, valueof_string);
3231 __ Cmp(descriptors, descriptors_end);
3236 // Set the bit in the map to indicate that there is no local valueOf field.
3237 __ Ldrb(x2, FieldMemOperand(map, Map::kBitField2Offset));
3238 __ Orr(x2, x2, 1 << Map::kStringWrapperSafeForDefaultValueOf);
3239 __ Strb(x2, FieldMemOperand(map, Map::kBitField2Offset));
3241 __ Bind(&skip_lookup);
3243 // If a valueOf property is not found on the object check that its prototype
3244 // is the unmodified String prototype. If not result is false.
3245 Register prototype = x1;
3246 Register global_idx = x2;
3247 Register native_context = x2;
3248 Register string_proto = x3;
3249 Register proto_map = x4;
3250 __ Ldr(prototype, FieldMemOperand(map, Map::kPrototypeOffset));
3251 __ JumpIfSmi(prototype, if_false);
3252 __ Ldr(proto_map, FieldMemOperand(prototype, HeapObject::kMapOffset));
3253 __ Ldr(global_idx, GlobalObjectMemOperand());
3254 __ Ldr(native_context,
3255 FieldMemOperand(global_idx, GlobalObject::kNativeContextOffset));
3256 __ Ldr(string_proto,
3257 ContextMemOperand(native_context,
3258 Context::STRING_FUNCTION_PROTOTYPE_MAP_INDEX));
3259 __ Cmp(proto_map, string_proto);
3261 PrepareForBailoutBeforeSplit(expr, true, if_true, if_false);
3262 Split(eq, if_true, if_false, fall_through);
3264 context()->Plug(if_true, if_false);
3268 void FullCodeGenerator::EmitIsFunction(CallRuntime* expr) {
3269 ZoneList<Expression*>* args = expr->arguments();
3270 DCHECK(args->length() == 1);
3272 VisitForAccumulatorValue(args->at(0));
3274 Label materialize_true, materialize_false;
3275 Label* if_true = NULL;
3276 Label* if_false = NULL;
3277 Label* fall_through = NULL;
3278 context()->PrepareTest(&materialize_true, &materialize_false,
3279 &if_true, &if_false, &fall_through);
3281 __ JumpIfSmi(x0, if_false);
3282 __ CompareObjectType(x0, x10, x11, JS_FUNCTION_TYPE);
3283 PrepareForBailoutBeforeSplit(expr, true, if_true, if_false);
3284 Split(eq, if_true, if_false, fall_through);
3286 context()->Plug(if_true, if_false);
3290 void FullCodeGenerator::EmitIsMinusZero(CallRuntime* expr) {
3291 ZoneList<Expression*>* args = expr->arguments();
3292 DCHECK(args->length() == 1);
3294 VisitForAccumulatorValue(args->at(0));
3296 Label materialize_true, materialize_false;
3297 Label* if_true = NULL;
3298 Label* if_false = NULL;
3299 Label* fall_through = NULL;
3300 context()->PrepareTest(&materialize_true, &materialize_false,
3301 &if_true, &if_false, &fall_through);
3303 // Only a HeapNumber can be -0.0, so return false if we have something else.
3304 __ JumpIfNotHeapNumber(x0, if_false, DO_SMI_CHECK);
3306 // Test the bit pattern.
3307 __ Ldr(x10, FieldMemOperand(x0, HeapNumber::kValueOffset));
3308 __ Cmp(x10, 1); // Set V on 0x8000000000000000.
3310 PrepareForBailoutBeforeSplit(expr, true, if_true, if_false);
3311 Split(vs, if_true, if_false, fall_through);
3313 context()->Plug(if_true, if_false);
3317 void FullCodeGenerator::EmitIsArray(CallRuntime* expr) {
3318 ZoneList<Expression*>* args = expr->arguments();
3319 DCHECK(args->length() == 1);
3321 VisitForAccumulatorValue(args->at(0));
3323 Label materialize_true, materialize_false;
3324 Label* if_true = NULL;
3325 Label* if_false = NULL;
3326 Label* fall_through = NULL;
3327 context()->PrepareTest(&materialize_true, &materialize_false,
3328 &if_true, &if_false, &fall_through);
3330 __ JumpIfSmi(x0, if_false);
3331 __ CompareObjectType(x0, x10, x11, JS_ARRAY_TYPE);
3332 PrepareForBailoutBeforeSplit(expr, true, if_true, if_false);
3333 Split(eq, if_true, if_false, fall_through);
3335 context()->Plug(if_true, if_false);
3339 void FullCodeGenerator::EmitIsRegExp(CallRuntime* expr) {
3340 ZoneList<Expression*>* args = expr->arguments();
3341 DCHECK(args->length() == 1);
3343 VisitForAccumulatorValue(args->at(0));
3345 Label materialize_true, materialize_false;
3346 Label* if_true = NULL;
3347 Label* if_false = NULL;
3348 Label* fall_through = NULL;
3349 context()->PrepareTest(&materialize_true, &materialize_false,
3350 &if_true, &if_false, &fall_through);
3352 __ JumpIfSmi(x0, if_false);
3353 __ CompareObjectType(x0, x10, x11, JS_REGEXP_TYPE);
3354 PrepareForBailoutBeforeSplit(expr, true, if_true, if_false);
3355 Split(eq, if_true, if_false, fall_through);
3357 context()->Plug(if_true, if_false);
3361 void FullCodeGenerator::EmitIsJSProxy(CallRuntime* expr) {
3362 ZoneList<Expression*>* args = expr->arguments();
3363 DCHECK(args->length() == 1);
3365 VisitForAccumulatorValue(args->at(0));
3367 Label materialize_true, materialize_false;
3368 Label* if_true = NULL;
3369 Label* if_false = NULL;
3370 Label* fall_through = NULL;
3371 context()->PrepareTest(&materialize_true, &materialize_false, &if_true,
3372 &if_false, &fall_through);
3374 __ JumpIfSmi(x0, if_false);
3376 Register type_reg = x11;
3377 __ Ldr(map, FieldMemOperand(x0, HeapObject::kMapOffset));
3378 __ Ldrb(type_reg, FieldMemOperand(map, Map::kInstanceTypeOffset));
3379 __ Sub(type_reg, type_reg, Operand(FIRST_JS_PROXY_TYPE));
3380 __ Cmp(type_reg, Operand(LAST_JS_PROXY_TYPE - FIRST_JS_PROXY_TYPE));
3381 PrepareForBailoutBeforeSplit(expr, true, if_true, if_false);
3382 Split(ls, if_true, if_false, fall_through);
3384 context()->Plug(if_true, if_false);
3388 void FullCodeGenerator::EmitIsConstructCall(CallRuntime* expr) {
3389 DCHECK(expr->arguments()->length() == 0);
3391 Label materialize_true, materialize_false;
3392 Label* if_true = NULL;
3393 Label* if_false = NULL;
3394 Label* fall_through = NULL;
3395 context()->PrepareTest(&materialize_true, &materialize_false,
3396 &if_true, &if_false, &fall_through);
3398 // Get the frame pointer for the calling frame.
3399 __ Ldr(x2, MemOperand(fp, StandardFrameConstants::kCallerFPOffset));
3401 // Skip the arguments adaptor frame if it exists.
3402 Label check_frame_marker;
3403 __ Ldr(x1, MemOperand(x2, StandardFrameConstants::kContextOffset));
3404 __ Cmp(x1, Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR));
3405 __ B(ne, &check_frame_marker);
3406 __ Ldr(x2, MemOperand(x2, StandardFrameConstants::kCallerFPOffset));
3408 // Check the marker in the calling frame.
3409 __ Bind(&check_frame_marker);
3410 __ Ldr(x1, MemOperand(x2, StandardFrameConstants::kMarkerOffset));
3411 __ Cmp(x1, Smi::FromInt(StackFrame::CONSTRUCT));
3412 PrepareForBailoutBeforeSplit(expr, true, if_true, if_false);
3413 Split(eq, if_true, if_false, fall_through);
3415 context()->Plug(if_true, if_false);
3419 void FullCodeGenerator::EmitObjectEquals(CallRuntime* expr) {
3420 ZoneList<Expression*>* args = expr->arguments();
3421 DCHECK(args->length() == 2);
3423 // Load the two objects into registers and perform the comparison.
3424 VisitForStackValue(args->at(0));
3425 VisitForAccumulatorValue(args->at(1));
3427 Label materialize_true, materialize_false;
3428 Label* if_true = NULL;
3429 Label* if_false = NULL;
3430 Label* fall_through = NULL;
3431 context()->PrepareTest(&materialize_true, &materialize_false,
3432 &if_true, &if_false, &fall_through);
3436 PrepareForBailoutBeforeSplit(expr, true, if_true, if_false);
3437 Split(eq, if_true, if_false, fall_through);
3439 context()->Plug(if_true, if_false);
3443 void FullCodeGenerator::EmitArguments(CallRuntime* expr) {
3444 ZoneList<Expression*>* args = expr->arguments();
3445 DCHECK(args->length() == 1);
3447 // ArgumentsAccessStub expects the key in x1.
3448 VisitForAccumulatorValue(args->at(0));
3450 __ Mov(x0, Smi::FromInt(info_->scope()->num_parameters()));
3451 ArgumentsAccessStub stub(isolate(), ArgumentsAccessStub::READ_ELEMENT);
3453 context()->Plug(x0);
3457 void FullCodeGenerator::EmitArgumentsLength(CallRuntime* expr) {
3458 DCHECK(expr->arguments()->length() == 0);
3460 // Get the number of formal parameters.
3461 __ Mov(x0, Smi::FromInt(info_->scope()->num_parameters()));
3463 // Check if the calling frame is an arguments adaptor frame.
3464 __ Ldr(x12, MemOperand(fp, StandardFrameConstants::kCallerFPOffset));
3465 __ Ldr(x13, MemOperand(x12, StandardFrameConstants::kContextOffset));
3466 __ Cmp(x13, Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR));
3469 // Arguments adaptor case: Read the arguments length from the
3471 __ Ldr(x0, MemOperand(x12, ArgumentsAdaptorFrameConstants::kLengthOffset));
3474 context()->Plug(x0);
3478 void FullCodeGenerator::EmitClassOf(CallRuntime* expr) {
3479 ASM_LOCATION("FullCodeGenerator::EmitClassOf");
3480 ZoneList<Expression*>* args = expr->arguments();
3481 DCHECK(args->length() == 1);
3482 Label done, null, function, non_function_constructor;
3484 VisitForAccumulatorValue(args->at(0));
3486 // If the object is a smi, we return null.
3487 __ JumpIfSmi(x0, &null);
3489 // Check that the object is a JS object but take special care of JS
3490 // functions to make sure they have 'Function' as their class.
3491 // Assume that there are only two callable types, and one of them is at
3492 // either end of the type range for JS object types. Saves extra comparisons.
3493 STATIC_ASSERT(NUM_OF_CALLABLE_SPEC_OBJECT_TYPES == 2);
3494 __ CompareObjectType(x0, x10, x11, FIRST_SPEC_OBJECT_TYPE);
3495 // x10: object's map.
3496 // x11: object's type.
3498 STATIC_ASSERT(FIRST_NONCALLABLE_SPEC_OBJECT_TYPE ==
3499 FIRST_SPEC_OBJECT_TYPE + 1);
3500 __ B(eq, &function);
3502 __ Cmp(x11, LAST_SPEC_OBJECT_TYPE);
3503 STATIC_ASSERT(LAST_NONCALLABLE_SPEC_OBJECT_TYPE ==
3504 LAST_SPEC_OBJECT_TYPE - 1);
3505 __ B(eq, &function);
3506 // Assume that there is no larger type.
3507 STATIC_ASSERT(LAST_NONCALLABLE_SPEC_OBJECT_TYPE == LAST_TYPE - 1);
3509 // Check if the constructor in the map is a JS function.
3510 Register instance_type = x14;
3511 __ GetMapConstructor(x12, x10, x13, instance_type);
3512 __ Cmp(instance_type, JS_FUNCTION_TYPE);
3513 __ B(ne, &non_function_constructor);
3515 // x12 now contains the constructor function. Grab the
3516 // instance class name from there.
3517 __ Ldr(x13, FieldMemOperand(x12, JSFunction::kSharedFunctionInfoOffset));
3519 FieldMemOperand(x13, SharedFunctionInfo::kInstanceClassNameOffset));
3522 // Functions have class 'Function'.
3524 __ LoadRoot(x0, Heap::kFunction_stringRootIndex);
3527 // Objects with a non-function constructor have class 'Object'.
3528 __ Bind(&non_function_constructor);
3529 __ LoadRoot(x0, Heap::kObject_stringRootIndex);
3532 // Non-JS objects have class null.
3534 __ LoadRoot(x0, Heap::kNullValueRootIndex);
3539 context()->Plug(x0);
3543 void FullCodeGenerator::EmitSubString(CallRuntime* expr) {
3544 // Load the arguments on the stack and call the stub.
3545 SubStringStub stub(isolate());
3546 ZoneList<Expression*>* args = expr->arguments();
3547 DCHECK(args->length() == 3);
3548 VisitForStackValue(args->at(0));
3549 VisitForStackValue(args->at(1));
3550 VisitForStackValue(args->at(2));
3552 context()->Plug(x0);
3556 void FullCodeGenerator::EmitRegExpExec(CallRuntime* expr) {
3557 // Load the arguments on the stack and call the stub.
3558 RegExpExecStub stub(isolate());
3559 ZoneList<Expression*>* args = expr->arguments();
3560 DCHECK(args->length() == 4);
3561 VisitForStackValue(args->at(0));
3562 VisitForStackValue(args->at(1));
3563 VisitForStackValue(args->at(2));
3564 VisitForStackValue(args->at(3));
3566 context()->Plug(x0);
3570 void FullCodeGenerator::EmitValueOf(CallRuntime* expr) {
3571 ASM_LOCATION("FullCodeGenerator::EmitValueOf");
3572 ZoneList<Expression*>* args = expr->arguments();
3573 DCHECK(args->length() == 1);
3574 VisitForAccumulatorValue(args->at(0)); // Load the object.
3577 // If the object is a smi return the object.
3578 __ JumpIfSmi(x0, &done);
3579 // If the object is not a value type, return the object.
3580 __ JumpIfNotObjectType(x0, x10, x11, JS_VALUE_TYPE, &done);
3581 __ Ldr(x0, FieldMemOperand(x0, JSValue::kValueOffset));
3584 context()->Plug(x0);
3588 void FullCodeGenerator::EmitDateField(CallRuntime* expr) {
3589 ZoneList<Expression*>* args = expr->arguments();
3590 DCHECK(args->length() == 2);
3591 DCHECK_NOT_NULL(args->at(1)->AsLiteral());
3592 Smi* index = Smi::cast(*(args->at(1)->AsLiteral()->value()));
3594 VisitForAccumulatorValue(args->at(0)); // Load the object.
3596 Label runtime, done, not_date_object;
3597 Register object = x0;
3598 Register result = x0;
3599 Register stamp_addr = x10;
3600 Register stamp_cache = x11;
3602 __ JumpIfSmi(object, ¬_date_object);
3603 __ JumpIfNotObjectType(object, x10, x10, JS_DATE_TYPE, ¬_date_object);
3605 if (index->value() == 0) {
3606 __ Ldr(result, FieldMemOperand(object, JSDate::kValueOffset));
3609 if (index->value() < JSDate::kFirstUncachedField) {
3610 ExternalReference stamp = ExternalReference::date_cache_stamp(isolate());
3612 __ Ldr(stamp_addr, MemOperand(x10));
3613 __ Ldr(stamp_cache, FieldMemOperand(object, JSDate::kCacheStampOffset));
3614 __ Cmp(stamp_addr, stamp_cache);
3616 __ Ldr(result, FieldMemOperand(object, JSDate::kValueOffset +
3617 kPointerSize * index->value()));
3623 __ CallCFunction(ExternalReference::get_date_field_function(isolate()), 2);
3627 __ Bind(¬_date_object);
3628 __ CallRuntime(Runtime::kThrowNotDateError, 0);
3630 context()->Plug(x0);
3634 void FullCodeGenerator::EmitOneByteSeqStringSetChar(CallRuntime* expr) {
3635 ZoneList<Expression*>* args = expr->arguments();
3636 DCHECK_EQ(3, args->length());
3638 Register string = x0;
3639 Register index = x1;
3640 Register value = x2;
3641 Register scratch = x10;
3643 VisitForStackValue(args->at(0)); // index
3644 VisitForStackValue(args->at(1)); // value
3645 VisitForAccumulatorValue(args->at(2)); // string
3646 __ Pop(value, index);
3648 if (FLAG_debug_code) {
3649 __ AssertSmi(value, kNonSmiValue);
3650 __ AssertSmi(index, kNonSmiIndex);
3651 static const uint32_t one_byte_seq_type = kSeqStringTag | kOneByteStringTag;
3652 __ EmitSeqStringSetCharCheck(string, index, kIndexIsSmi, scratch,
3656 __ Add(scratch, string, SeqOneByteString::kHeaderSize - kHeapObjectTag);
3659 __ Strb(value, MemOperand(scratch, index));
3660 context()->Plug(string);
3664 void FullCodeGenerator::EmitTwoByteSeqStringSetChar(CallRuntime* expr) {
3665 ZoneList<Expression*>* args = expr->arguments();
3666 DCHECK_EQ(3, args->length());
3668 Register string = x0;
3669 Register index = x1;
3670 Register value = x2;
3671 Register scratch = x10;
3673 VisitForStackValue(args->at(0)); // index
3674 VisitForStackValue(args->at(1)); // value
3675 VisitForAccumulatorValue(args->at(2)); // string
3676 __ Pop(value, index);
3678 if (FLAG_debug_code) {
3679 __ AssertSmi(value, kNonSmiValue);
3680 __ AssertSmi(index, kNonSmiIndex);
3681 static const uint32_t two_byte_seq_type = kSeqStringTag | kTwoByteStringTag;
3682 __ EmitSeqStringSetCharCheck(string, index, kIndexIsSmi, scratch,
3686 __ Add(scratch, string, SeqTwoByteString::kHeaderSize - kHeapObjectTag);
3689 __ Strh(value, MemOperand(scratch, index, LSL, 1));
3690 context()->Plug(string);
3694 void FullCodeGenerator::EmitMathPow(CallRuntime* expr) {
3695 // Load the arguments on the stack and call the MathPow stub.
3696 ZoneList<Expression*>* args = expr->arguments();
3697 DCHECK(args->length() == 2);
3698 VisitForStackValue(args->at(0));
3699 VisitForStackValue(args->at(1));
3700 MathPowStub stub(isolate(), MathPowStub::ON_STACK);
3702 context()->Plug(x0);
3706 void FullCodeGenerator::EmitSetValueOf(CallRuntime* expr) {
3707 ZoneList<Expression*>* args = expr->arguments();
3708 DCHECK(args->length() == 2);
3709 VisitForStackValue(args->at(0)); // Load the object.
3710 VisitForAccumulatorValue(args->at(1)); // Load the value.
3716 // If the object is a smi, return the value.
3717 __ JumpIfSmi(x1, &done);
3719 // If the object is not a value type, return the value.
3720 __ JumpIfNotObjectType(x1, x10, x11, JS_VALUE_TYPE, &done);
3723 __ Str(x0, FieldMemOperand(x1, JSValue::kValueOffset));
3724 // Update the write barrier. Save the value as it will be
3725 // overwritten by the write barrier code and is needed afterward.
3727 __ RecordWriteField(
3728 x1, JSValue::kValueOffset, x10, x11, kLRHasBeenSaved, kDontSaveFPRegs);
3731 context()->Plug(x0);
3735 void FullCodeGenerator::EmitNumberToString(CallRuntime* expr) {
3736 ZoneList<Expression*>* args = expr->arguments();
3737 DCHECK_EQ(args->length(), 1);
3739 // Load the argument into x0 and call the stub.
3740 VisitForAccumulatorValue(args->at(0));
3742 NumberToStringStub stub(isolate());
3744 context()->Plug(x0);
3748 void FullCodeGenerator::EmitStringCharFromCode(CallRuntime* expr) {
3749 ZoneList<Expression*>* args = expr->arguments();
3750 DCHECK(args->length() == 1);
3752 VisitForAccumulatorValue(args->at(0));
3756 Register result = x1;
3758 StringCharFromCodeGenerator generator(code, result);
3759 generator.GenerateFast(masm_);
3762 NopRuntimeCallHelper call_helper;
3763 generator.GenerateSlow(masm_, call_helper);
3766 context()->Plug(result);
3770 void FullCodeGenerator::EmitStringCharCodeAt(CallRuntime* expr) {
3771 ZoneList<Expression*>* args = expr->arguments();
3772 DCHECK(args->length() == 2);
3774 VisitForStackValue(args->at(0));
3775 VisitForAccumulatorValue(args->at(1));
3777 Register object = x1;
3778 Register index = x0;
3779 Register result = x3;
3783 Label need_conversion;
3784 Label index_out_of_range;
3786 StringCharCodeAtGenerator generator(object,
3791 &index_out_of_range,
3792 STRING_INDEX_IS_NUMBER);
3793 generator.GenerateFast(masm_);
3796 __ Bind(&index_out_of_range);
3797 // When the index is out of range, the spec requires us to return NaN.
3798 __ LoadRoot(result, Heap::kNanValueRootIndex);
3801 __ Bind(&need_conversion);
3802 // Load the undefined value into the result register, which will
3803 // trigger conversion.
3804 __ LoadRoot(result, Heap::kUndefinedValueRootIndex);
3807 NopRuntimeCallHelper call_helper;
3808 generator.GenerateSlow(masm_, NOT_PART_OF_IC_HANDLER, call_helper);
3811 context()->Plug(result);
3815 void FullCodeGenerator::EmitStringCharAt(CallRuntime* expr) {
3816 ZoneList<Expression*>* args = expr->arguments();
3817 DCHECK(args->length() == 2);
3819 VisitForStackValue(args->at(0));
3820 VisitForAccumulatorValue(args->at(1));
3822 Register object = x1;
3823 Register index = x0;
3824 Register result = x0;
3828 Label need_conversion;
3829 Label index_out_of_range;
3831 StringCharAtGenerator generator(object,
3837 &index_out_of_range,
3838 STRING_INDEX_IS_NUMBER);
3839 generator.GenerateFast(masm_);
3842 __ Bind(&index_out_of_range);
3843 // When the index is out of range, the spec requires us to return
3844 // the empty string.
3845 __ LoadRoot(result, Heap::kempty_stringRootIndex);
3848 __ Bind(&need_conversion);
3849 // Move smi zero into the result register, which will trigger conversion.
3850 __ Mov(result, Smi::FromInt(0));
3853 NopRuntimeCallHelper call_helper;
3854 generator.GenerateSlow(masm_, NOT_PART_OF_IC_HANDLER, call_helper);
3857 context()->Plug(result);
3861 void FullCodeGenerator::EmitStringAdd(CallRuntime* expr) {
3862 ASM_LOCATION("FullCodeGenerator::EmitStringAdd");
3863 ZoneList<Expression*>* args = expr->arguments();
3864 DCHECK_EQ(2, args->length());
3866 VisitForStackValue(args->at(0));
3867 VisitForAccumulatorValue(args->at(1));
3870 StringAddStub stub(isolate(), STRING_ADD_CHECK_BOTH, NOT_TENURED);
3873 context()->Plug(x0);
3877 void FullCodeGenerator::EmitStringCompare(CallRuntime* expr) {
3878 ZoneList<Expression*>* args = expr->arguments();
3879 DCHECK_EQ(2, args->length());
3880 VisitForStackValue(args->at(0));
3881 VisitForStackValue(args->at(1));
3883 StringCompareStub stub(isolate());
3885 context()->Plug(x0);
3889 void FullCodeGenerator::EmitCallFunction(CallRuntime* expr) {
3890 ASM_LOCATION("FullCodeGenerator::EmitCallFunction");
3891 ZoneList<Expression*>* args = expr->arguments();
3892 DCHECK(args->length() >= 2);
3894 int arg_count = args->length() - 2; // 2 ~ receiver and function.
3895 for (int i = 0; i < arg_count + 1; i++) {
3896 VisitForStackValue(args->at(i));
3898 VisitForAccumulatorValue(args->last()); // Function.
3900 Label runtime, done;
3901 // Check for non-function argument (including proxy).
3902 __ JumpIfSmi(x0, &runtime);
3903 __ JumpIfNotObjectType(x0, x1, x1, JS_FUNCTION_TYPE, &runtime);
3905 // InvokeFunction requires the function in x1. Move it in there.
3907 ParameterCount count(arg_count);
3908 __ InvokeFunction(x1, count, CALL_FUNCTION, NullCallWrapper());
3909 __ Ldr(cp, MemOperand(fp, StandardFrameConstants::kContextOffset));
3914 __ CallRuntime(Runtime::kCall, args->length());
3917 context()->Plug(x0);
3921 void FullCodeGenerator::EmitDefaultConstructorCallSuper(CallRuntime* expr) {
3922 Variable* new_target_var = scope()->DeclarationScope()->new_target_var();
3923 GetVar(result_register(), new_target_var);
3924 __ Push(result_register());
3926 EmitLoadSuperConstructor();
3927 __ Push(result_register());
3929 // Check if the calling frame is an arguments adaptor frame.
3930 Label adaptor_frame, args_set_up, runtime;
3931 __ Ldr(x11, MemOperand(fp, StandardFrameConstants::kCallerFPOffset));
3932 __ Ldr(x12, MemOperand(x11, StandardFrameConstants::kContextOffset));
3933 __ Cmp(x12, Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR));
3934 __ B(eq, &adaptor_frame);
3935 // default constructor has no arguments, so no adaptor frame means no args.
3936 __ Mov(x0, Operand(0));
3939 // Copy arguments from adaptor frame.
3941 __ bind(&adaptor_frame);
3942 __ Ldr(x1, MemOperand(x11, ArgumentsAdaptorFrameConstants::kLengthOffset));
3943 __ SmiUntag(x1, x1);
3945 // Subtract 1 from arguments count, for new.target.
3946 __ Sub(x1, x1, Operand(1));
3949 // Get arguments pointer in x11.
3950 __ Add(x11, x11, Operand(x1, LSL, kPointerSizeLog2));
3951 __ Add(x11, x11, StandardFrameConstants::kCallerSPOffset);
3954 // Pre-decrement x11 with kPointerSize on each iteration.
3955 // Pre-decrement in order to skip receiver.
3956 __ Ldr(x10, MemOperand(x11, -kPointerSize, PreIndex));
3958 __ Sub(x1, x1, Operand(1));
3962 __ bind(&args_set_up);
3963 __ Peek(x1, Operand(x0, LSL, kPointerSizeLog2));
3964 __ LoadRoot(x2, Heap::kUndefinedValueRootIndex);
3966 CallConstructStub stub(isolate(), SUPER_CONSTRUCTOR_CALL);
3967 __ Call(stub.GetCode(), RelocInfo::CONSTRUCT_CALL);
3971 context()->Plug(result_register());
3975 void FullCodeGenerator::EmitRegExpConstructResult(CallRuntime* expr) {
3976 RegExpConstructResultStub stub(isolate());
3977 ZoneList<Expression*>* args = expr->arguments();
3978 DCHECK(args->length() == 3);
3979 VisitForStackValue(args->at(0));
3980 VisitForStackValue(args->at(1));
3981 VisitForAccumulatorValue(args->at(2));
3984 context()->Plug(x0);
3988 void FullCodeGenerator::EmitGetFromCache(CallRuntime* expr) {
3989 ZoneList<Expression*>* args = expr->arguments();
3990 DCHECK_EQ(2, args->length());
3991 DCHECK_NOT_NULL(args->at(0)->AsLiteral());
3992 int cache_id = Smi::cast(*(args->at(0)->AsLiteral()->value()))->value();
3994 Handle<FixedArray> jsfunction_result_caches(
3995 isolate()->native_context()->jsfunction_result_caches());
3996 if (jsfunction_result_caches->length() <= cache_id) {
3997 __ Abort(kAttemptToUseUndefinedCache);
3998 __ LoadRoot(x0, Heap::kUndefinedValueRootIndex);
3999 context()->Plug(x0);
4003 VisitForAccumulatorValue(args->at(1));
4006 Register cache = x1;
4007 __ Ldr(cache, GlobalObjectMemOperand());
4008 __ Ldr(cache, FieldMemOperand(cache, GlobalObject::kNativeContextOffset));
4009 __ Ldr(cache, ContextMemOperand(cache,
4010 Context::JSFUNCTION_RESULT_CACHES_INDEX));
4012 FieldMemOperand(cache, FixedArray::OffsetOfElementAt(cache_id)));
4015 __ Ldrsw(x2, UntagSmiFieldMemOperand(cache,
4016 JSFunctionResultCache::kFingerOffset));
4017 __ Add(x3, cache, FixedArray::kHeaderSize - kHeapObjectTag);
4018 __ Add(x3, x3, Operand(x2, LSL, kPointerSizeLog2));
4020 // Load the key and data from the cache.
4021 __ Ldp(x2, x3, MemOperand(x3));
4024 __ CmovX(x0, x3, eq);
4027 // Call runtime to perform the lookup.
4028 __ Push(cache, key);
4029 __ CallRuntime(Runtime::kGetFromCacheRT, 2);
4032 context()->Plug(x0);
4036 void FullCodeGenerator::EmitHasCachedArrayIndex(CallRuntime* expr) {
4037 ZoneList<Expression*>* args = expr->arguments();
4038 VisitForAccumulatorValue(args->at(0));
4040 Label materialize_true, materialize_false;
4041 Label* if_true = NULL;
4042 Label* if_false = NULL;
4043 Label* fall_through = NULL;
4044 context()->PrepareTest(&materialize_true, &materialize_false,
4045 &if_true, &if_false, &fall_through);
4047 __ Ldr(x10, FieldMemOperand(x0, String::kHashFieldOffset));
4048 __ Tst(x10, String::kContainsCachedArrayIndexMask);
4049 PrepareForBailoutBeforeSplit(expr, true, if_true, if_false);
4050 Split(eq, if_true, if_false, fall_through);
4052 context()->Plug(if_true, if_false);
4056 void FullCodeGenerator::EmitGetCachedArrayIndex(CallRuntime* expr) {
4057 ZoneList<Expression*>* args = expr->arguments();
4058 DCHECK(args->length() == 1);
4059 VisitForAccumulatorValue(args->at(0));
4061 __ AssertString(x0);
4063 __ Ldr(x10, FieldMemOperand(x0, String::kHashFieldOffset));
4064 __ IndexFromHash(x10, x0);
4066 context()->Plug(x0);
4070 void FullCodeGenerator::EmitFastOneByteArrayJoin(CallRuntime* expr) {
4071 ASM_LOCATION("FullCodeGenerator::EmitFastOneByteArrayJoin");
4073 ZoneList<Expression*>* args = expr->arguments();
4074 DCHECK(args->length() == 2);
4075 VisitForStackValue(args->at(1));
4076 VisitForAccumulatorValue(args->at(0));
4078 Register array = x0;
4079 Register result = x0;
4080 Register elements = x1;
4081 Register element = x2;
4082 Register separator = x3;
4083 Register array_length = x4;
4084 Register result_pos = x5;
4086 Register string_length = x10;
4087 Register elements_end = x11;
4088 Register string = x12;
4089 Register scratch1 = x13;
4090 Register scratch2 = x14;
4091 Register scratch3 = x7;
4092 Register separator_length = x15;
4094 Label bailout, done, one_char_separator, long_separator,
4095 non_trivial_array, not_size_one_array, loop,
4096 empty_separator_loop, one_char_separator_loop,
4097 one_char_separator_loop_entry, long_separator_loop;
4099 // The separator operand is on the stack.
4102 // Check that the array is a JSArray.
4103 __ JumpIfSmi(array, &bailout);
4104 __ JumpIfNotObjectType(array, map, scratch1, JS_ARRAY_TYPE, &bailout);
4106 // Check that the array has fast elements.
4107 __ CheckFastElements(map, scratch1, &bailout);
4109 // If the array has length zero, return the empty string.
4110 // Load and untag the length of the array.
4111 // It is an unsigned value, so we can skip sign extension.
4112 // We assume little endianness.
4113 __ Ldrsw(array_length,
4114 UntagSmiFieldMemOperand(array, JSArray::kLengthOffset));
4115 __ Cbnz(array_length, &non_trivial_array);
4116 __ LoadRoot(result, Heap::kempty_stringRootIndex);
4119 __ Bind(&non_trivial_array);
4120 // Get the FixedArray containing array's elements.
4121 __ Ldr(elements, FieldMemOperand(array, JSArray::kElementsOffset));
4123 // Check that all array elements are sequential one-byte strings, and
4124 // accumulate the sum of their lengths.
4125 __ Mov(string_length, 0);
4126 __ Add(element, elements, FixedArray::kHeaderSize - kHeapObjectTag);
4127 __ Add(elements_end, element, Operand(array_length, LSL, kPointerSizeLog2));
4128 // Loop condition: while (element < elements_end).
4129 // Live values in registers:
4130 // elements: Fixed array of strings.
4131 // array_length: Length of the fixed array of strings (not smi)
4132 // separator: Separator string
4133 // string_length: Accumulated sum of string lengths (not smi).
4134 // element: Current array element.
4135 // elements_end: Array end.
4136 if (FLAG_debug_code) {
4137 __ Cmp(array_length, 0);
4138 __ Assert(gt, kNoEmptyArraysHereInEmitFastOneByteArrayJoin);
4141 __ Ldr(string, MemOperand(element, kPointerSize, PostIndex));
4142 __ JumpIfSmi(string, &bailout);
4143 __ Ldr(scratch1, FieldMemOperand(string, HeapObject::kMapOffset));
4144 __ Ldrb(scratch1, FieldMemOperand(scratch1, Map::kInstanceTypeOffset));
4145 __ JumpIfInstanceTypeIsNotSequentialOneByte(scratch1, scratch2, &bailout);
4147 UntagSmiFieldMemOperand(string, SeqOneByteString::kLengthOffset));
4148 __ Adds(string_length, string_length, scratch1);
4150 __ Cmp(element, elements_end);
4153 // If array_length is 1, return elements[0], a string.
4154 __ Cmp(array_length, 1);
4155 __ B(ne, ¬_size_one_array);
4156 __ Ldr(result, FieldMemOperand(elements, FixedArray::kHeaderSize));
4159 __ Bind(¬_size_one_array);
4161 // Live values in registers:
4162 // separator: Separator string
4163 // array_length: Length of the array (not smi).
4164 // string_length: Sum of string lengths (not smi).
4165 // elements: FixedArray of strings.
4167 // Check that the separator is a flat one-byte string.
4168 __ JumpIfSmi(separator, &bailout);
4169 __ Ldr(scratch1, FieldMemOperand(separator, HeapObject::kMapOffset));
4170 __ Ldrb(scratch1, FieldMemOperand(scratch1, Map::kInstanceTypeOffset));
4171 __ JumpIfInstanceTypeIsNotSequentialOneByte(scratch1, scratch2, &bailout);
4173 // Add (separator length times array_length) - separator length to the
4174 // string_length to get the length of the result string.
4175 // Load the separator length as untagged.
4176 // We assume little endianness, and that the length is positive.
4177 __ Ldrsw(separator_length,
4178 UntagSmiFieldMemOperand(separator,
4179 SeqOneByteString::kLengthOffset));
4180 __ Sub(string_length, string_length, separator_length);
4181 __ Umaddl(string_length, array_length.W(), separator_length.W(),
4184 // Get first element in the array.
4185 __ Add(element, elements, FixedArray::kHeaderSize - kHeapObjectTag);
4186 // Live values in registers:
4187 // element: First array element
4188 // separator: Separator string
4189 // string_length: Length of result string (not smi)
4190 // array_length: Length of the array (not smi).
4191 __ AllocateOneByteString(result, string_length, scratch1, scratch2, scratch3,
4194 // Prepare for looping. Set up elements_end to end of the array. Set
4195 // result_pos to the position of the result where to write the first
4197 // TODO(all): useless unless AllocateOneByteString trashes the register.
4198 __ Add(elements_end, element, Operand(array_length, LSL, kPointerSizeLog2));
4199 __ Add(result_pos, result, SeqOneByteString::kHeaderSize - kHeapObjectTag);
4201 // Check the length of the separator.
4202 __ Cmp(separator_length, 1);
4203 __ B(eq, &one_char_separator);
4204 __ B(gt, &long_separator);
4206 // Empty separator case
4207 __ Bind(&empty_separator_loop);
4208 // Live values in registers:
4209 // result_pos: the position to which we are currently copying characters.
4210 // element: Current array element.
4211 // elements_end: Array end.
4213 // Copy next array element to the result.
4214 __ Ldr(string, MemOperand(element, kPointerSize, PostIndex));
4215 __ Ldrsw(string_length,
4216 UntagSmiFieldMemOperand(string, String::kLengthOffset));
4217 __ Add(string, string, SeqOneByteString::kHeaderSize - kHeapObjectTag);
4218 __ CopyBytes(result_pos, string, string_length, scratch1);
4219 __ Cmp(element, elements_end);
4220 __ B(lt, &empty_separator_loop); // End while (element < elements_end).
4223 // One-character separator case
4224 __ Bind(&one_char_separator);
4225 // Replace separator with its one-byte character value.
4226 __ Ldrb(separator, FieldMemOperand(separator, SeqOneByteString::kHeaderSize));
4227 // Jump into the loop after the code that copies the separator, so the first
4228 // element is not preceded by a separator
4229 __ B(&one_char_separator_loop_entry);
4231 __ Bind(&one_char_separator_loop);
4232 // Live values in registers:
4233 // result_pos: the position to which we are currently copying characters.
4234 // element: Current array element.
4235 // elements_end: Array end.
4236 // separator: Single separator one-byte char (in lower byte).
4238 // Copy the separator character to the result.
4239 __ Strb(separator, MemOperand(result_pos, 1, PostIndex));
4241 // Copy next array element to the result.
4242 __ Bind(&one_char_separator_loop_entry);
4243 __ Ldr(string, MemOperand(element, kPointerSize, PostIndex));
4244 __ Ldrsw(string_length,
4245 UntagSmiFieldMemOperand(string, String::kLengthOffset));
4246 __ Add(string, string, SeqOneByteString::kHeaderSize - kHeapObjectTag);
4247 __ CopyBytes(result_pos, string, string_length, scratch1);
4248 __ Cmp(element, elements_end);
4249 __ B(lt, &one_char_separator_loop); // End while (element < elements_end).
4252 // Long separator case (separator is more than one character). Entry is at the
4253 // label long_separator below.
4254 __ Bind(&long_separator_loop);
4255 // Live values in registers:
4256 // result_pos: the position to which we are currently copying characters.
4257 // element: Current array element.
4258 // elements_end: Array end.
4259 // separator: Separator string.
4261 // Copy the separator to the result.
4262 // TODO(all): hoist next two instructions.
4263 __ Ldrsw(string_length,
4264 UntagSmiFieldMemOperand(separator, String::kLengthOffset));
4265 __ Add(string, separator, SeqOneByteString::kHeaderSize - kHeapObjectTag);
4266 __ CopyBytes(result_pos, string, string_length, scratch1);
4268 __ Bind(&long_separator);
4269 __ Ldr(string, MemOperand(element, kPointerSize, PostIndex));
4270 __ Ldrsw(string_length,
4271 UntagSmiFieldMemOperand(string, String::kLengthOffset));
4272 __ Add(string, string, SeqOneByteString::kHeaderSize - kHeapObjectTag);
4273 __ CopyBytes(result_pos, string, string_length, scratch1);
4274 __ Cmp(element, elements_end);
4275 __ B(lt, &long_separator_loop); // End while (element < elements_end).
4279 // Returning undefined will force slower code to handle it.
4280 __ LoadRoot(result, Heap::kUndefinedValueRootIndex);
4282 context()->Plug(result);
4286 void FullCodeGenerator::EmitDebugIsActive(CallRuntime* expr) {
4287 DCHECK(expr->arguments()->length() == 0);
4288 ExternalReference debug_is_active =
4289 ExternalReference::debug_is_active_address(isolate());
4290 __ Mov(x10, debug_is_active);
4291 __ Ldrb(x0, MemOperand(x10));
4293 context()->Plug(x0);
4297 void FullCodeGenerator::VisitCallRuntime(CallRuntime* expr) {
4298 ZoneList<Expression*>* args = expr->arguments();
4299 int arg_count = args->length();
4301 if (expr->is_jsruntime()) {
4302 Comment cmnt(masm_, "[ CallRunTime");
4303 // Push the builtins object as the receiver.
4304 __ Ldr(x10, GlobalObjectMemOperand());
4305 __ Ldr(LoadDescriptor::ReceiverRegister(),
4306 FieldMemOperand(x10, GlobalObject::kBuiltinsOffset));
4307 __ Push(LoadDescriptor::ReceiverRegister());
4309 // Load the function from the receiver.
4310 Handle<String> name = expr->name();
4311 __ Mov(LoadDescriptor::NameRegister(), Operand(name));
4312 if (FLAG_vector_ics) {
4313 __ Mov(VectorLoadICDescriptor::SlotRegister(),
4314 SmiFromSlot(expr->CallRuntimeFeedbackSlot()));
4315 CallLoadIC(NOT_CONTEXTUAL);
4317 CallLoadIC(NOT_CONTEXTUAL, expr->CallRuntimeFeedbackId());
4320 // Push the target function under the receiver.
4324 for (int i = 0; i < arg_count; i++) {
4325 VisitForStackValue(args->at(i));
4328 // Record source position of the IC call.
4329 SetSourcePosition(expr->position());
4330 CallFunctionStub stub(isolate(), arg_count, NO_CALL_FUNCTION_FLAGS);
4331 __ Peek(x1, (arg_count + 1) * kPointerSize);
4334 // Restore context register.
4335 __ Ldr(cp, MemOperand(fp, StandardFrameConstants::kContextOffset));
4337 context()->DropAndPlug(1, x0);
4340 const Runtime::Function* function = expr->function();
4341 switch (function->function_id) {
4342 #define CALL_INTRINSIC_GENERATOR(Name) \
4343 case Runtime::kInline##Name: { \
4344 Comment cmnt(masm_, "[ Inline" #Name); \
4345 return Emit##Name(expr); \
4347 FOR_EACH_FULL_CODE_INTRINSIC(CALL_INTRINSIC_GENERATOR)
4348 #undef CALL_INTRINSIC_GENERATOR
4350 Comment cmnt(masm_, "[ CallRuntime for unhandled intrinsic");
4351 // Push the arguments ("left-to-right").
4352 for (int i = 0; i < arg_count; i++) {
4353 VisitForStackValue(args->at(i));
4356 // Call the C runtime function.
4357 __ CallRuntime(expr->function(), arg_count);
4358 context()->Plug(x0);
4365 void FullCodeGenerator::VisitUnaryOperation(UnaryOperation* expr) {
4366 switch (expr->op()) {
4367 case Token::DELETE: {
4368 Comment cmnt(masm_, "[ UnaryOperation (DELETE)");
4369 Property* property = expr->expression()->AsProperty();
4370 VariableProxy* proxy = expr->expression()->AsVariableProxy();
4372 if (property != NULL) {
4373 VisitForStackValue(property->obj());
4374 VisitForStackValue(property->key());
4375 __ Mov(x10, Smi::FromInt(language_mode()));
4377 __ InvokeBuiltin(Builtins::DELETE, CALL_FUNCTION);
4378 context()->Plug(x0);
4379 } else if (proxy != NULL) {
4380 Variable* var = proxy->var();
4381 // Delete of an unqualified identifier is disallowed in strict mode
4382 // but "delete this" is allowed.
4383 DCHECK(is_sloppy(language_mode()) || var->is_this());
4384 if (var->IsUnallocated()) {
4385 __ Ldr(x12, GlobalObjectMemOperand());
4386 __ Mov(x11, Operand(var->name()));
4387 __ Mov(x10, Smi::FromInt(SLOPPY));
4388 __ Push(x12, x11, x10);
4389 __ InvokeBuiltin(Builtins::DELETE, CALL_FUNCTION);
4390 context()->Plug(x0);
4391 } else if (var->IsStackAllocated() || var->IsContextSlot()) {
4392 // Result of deleting non-global, non-dynamic variables is false.
4393 // The subexpression does not have side effects.
4394 context()->Plug(var->is_this());
4396 // Non-global variable. Call the runtime to try to delete from the
4397 // context where the variable was introduced.
4398 __ Mov(x2, Operand(var->name()));
4399 __ Push(context_register(), x2);
4400 __ CallRuntime(Runtime::kDeleteLookupSlot, 2);
4401 context()->Plug(x0);
4404 // Result of deleting non-property, non-variable reference is true.
4405 // The subexpression may have side effects.
4406 VisitForEffect(expr->expression());
4407 context()->Plug(true);
4413 Comment cmnt(masm_, "[ UnaryOperation (VOID)");
4414 VisitForEffect(expr->expression());
4415 context()->Plug(Heap::kUndefinedValueRootIndex);
4419 Comment cmnt(masm_, "[ UnaryOperation (NOT)");
4420 if (context()->IsEffect()) {
4421 // Unary NOT has no side effects so it's only necessary to visit the
4422 // subexpression. Match the optimizing compiler by not branching.
4423 VisitForEffect(expr->expression());
4424 } else if (context()->IsTest()) {
4425 const TestContext* test = TestContext::cast(context());
4426 // The labels are swapped for the recursive call.
4427 VisitForControl(expr->expression(),
4428 test->false_label(),
4430 test->fall_through());
4431 context()->Plug(test->true_label(), test->false_label());
4433 DCHECK(context()->IsAccumulatorValue() || context()->IsStackValue());
4434 // TODO(jbramley): This could be much more efficient using (for
4435 // example) the CSEL instruction.
4436 Label materialize_true, materialize_false, done;
4437 VisitForControl(expr->expression(),
4442 __ Bind(&materialize_true);
4443 PrepareForBailoutForId(expr->MaterializeTrueId(), NO_REGISTERS);
4444 __ LoadRoot(result_register(), Heap::kTrueValueRootIndex);
4447 __ Bind(&materialize_false);
4448 PrepareForBailoutForId(expr->MaterializeFalseId(), NO_REGISTERS);
4449 __ LoadRoot(result_register(), Heap::kFalseValueRootIndex);
4453 if (context()->IsStackValue()) {
4454 __ Push(result_register());
4459 case Token::TYPEOF: {
4460 Comment cmnt(masm_, "[ UnaryOperation (TYPEOF)");
4462 StackValueContext context(this);
4463 VisitForTypeofValue(expr->expression());
4465 __ CallRuntime(Runtime::kTypeof, 1);
4466 context()->Plug(x0);
4475 void FullCodeGenerator::VisitCountOperation(CountOperation* expr) {
4476 DCHECK(expr->expression()->IsValidReferenceExpression());
4478 Comment cmnt(masm_, "[ CountOperation");
4479 SetSourcePosition(expr->position());
4481 Property* prop = expr->expression()->AsProperty();
4482 LhsKind assign_type = GetAssignType(prop);
4484 // Evaluate expression and get value.
4485 if (assign_type == VARIABLE) {
4486 DCHECK(expr->expression()->AsVariableProxy()->var() != NULL);
4487 AccumulatorValueContext context(this);
4488 EmitVariableLoad(expr->expression()->AsVariableProxy());
4490 // Reserve space for result of postfix operation.
4491 if (expr->is_postfix() && !context()->IsEffect()) {
4494 switch (assign_type) {
4495 case NAMED_PROPERTY: {
4496 // Put the object both on the stack and in the register.
4497 VisitForStackValue(prop->obj());
4498 __ Peek(LoadDescriptor::ReceiverRegister(), 0);
4499 EmitNamedPropertyLoad(prop);
4503 case NAMED_SUPER_PROPERTY: {
4504 VisitForStackValue(prop->obj()->AsSuperReference()->this_var());
4505 EmitLoadHomeObject(prop->obj()->AsSuperReference());
4506 __ Push(result_register());
4507 const Register scratch = x10;
4508 __ Peek(scratch, kPointerSize);
4509 __ Push(scratch, result_register());
4510 EmitNamedSuperPropertyLoad(prop);
4514 case KEYED_SUPER_PROPERTY: {
4515 VisitForStackValue(prop->obj()->AsSuperReference()->this_var());
4516 EmitLoadHomeObject(prop->obj()->AsSuperReference());
4517 __ Push(result_register());
4518 VisitForAccumulatorValue(prop->key());
4519 __ Push(result_register());
4520 const Register scratch1 = x10;
4521 const Register scratch2 = x11;
4522 __ Peek(scratch1, 2 * kPointerSize);
4523 __ Peek(scratch2, kPointerSize);
4524 __ Push(scratch1, scratch2, result_register());
4525 EmitKeyedSuperPropertyLoad(prop);
4529 case KEYED_PROPERTY: {
4530 VisitForStackValue(prop->obj());
4531 VisitForStackValue(prop->key());
4532 __ Peek(LoadDescriptor::ReceiverRegister(), 1 * kPointerSize);
4533 __ Peek(LoadDescriptor::NameRegister(), 0);
4534 EmitKeyedPropertyLoad(prop);
4543 // We need a second deoptimization point after loading the value
4544 // in case evaluating the property load my have a side effect.
4545 if (assign_type == VARIABLE) {
4546 PrepareForBailout(expr->expression(), TOS_REG);
4548 PrepareForBailoutForId(prop->LoadId(), TOS_REG);
4551 // Inline smi case if we are in a loop.
4552 Label stub_call, done;
4553 JumpPatchSite patch_site(masm_);
4555 int count_value = expr->op() == Token::INC ? 1 : -1;
4556 if (ShouldInlineSmiCase(expr->op())) {
4558 patch_site.EmitJumpIfNotSmi(x0, &slow);
4560 // Save result for postfix expressions.
4561 if (expr->is_postfix()) {
4562 if (!context()->IsEffect()) {
4563 // Save the result on the stack. If we have a named or keyed property we
4564 // store the result under the receiver that is currently on top of the
4566 switch (assign_type) {
4570 case NAMED_PROPERTY:
4571 __ Poke(x0, kPointerSize);
4573 case NAMED_SUPER_PROPERTY:
4574 __ Poke(x0, kPointerSize * 2);
4576 case KEYED_PROPERTY:
4577 __ Poke(x0, kPointerSize * 2);
4579 case KEYED_SUPER_PROPERTY:
4580 __ Poke(x0, kPointerSize * 3);
4586 __ Adds(x0, x0, Smi::FromInt(count_value));
4588 // Call stub. Undo operation first.
4589 __ Sub(x0, x0, Smi::FromInt(count_value));
4593 ToNumberStub convert_stub(isolate());
4594 __ CallStub(&convert_stub);
4595 PrepareForBailoutForId(expr->ToNumberId(), TOS_REG);
4597 // Save result for postfix expressions.
4598 if (expr->is_postfix()) {
4599 if (!context()->IsEffect()) {
4600 // Save the result on the stack. If we have a named or keyed property
4601 // we store the result under the receiver that is currently on top
4603 switch (assign_type) {
4607 case NAMED_PROPERTY:
4608 __ Poke(x0, kXRegSize);
4610 case NAMED_SUPER_PROPERTY:
4611 __ Poke(x0, 2 * kXRegSize);
4613 case KEYED_PROPERTY:
4614 __ Poke(x0, 2 * kXRegSize);
4616 case KEYED_SUPER_PROPERTY:
4617 __ Poke(x0, 3 * kXRegSize);
4623 __ Bind(&stub_call);
4625 __ Mov(x0, Smi::FromInt(count_value));
4627 // Record position before stub call.
4628 SetSourcePosition(expr->position());
4631 Assembler::BlockPoolsScope scope(masm_);
4632 Handle<Code> code = CodeFactory::BinaryOpIC(isolate(), Token::ADD).code();
4633 CallIC(code, expr->CountBinOpFeedbackId());
4634 patch_site.EmitPatchInfo();
4638 // Store the value returned in x0.
4639 switch (assign_type) {
4641 if (expr->is_postfix()) {
4642 { EffectContext context(this);
4643 EmitVariableAssignment(expr->expression()->AsVariableProxy()->var(),
4645 PrepareForBailoutForId(expr->AssignmentId(), TOS_REG);
4648 // For all contexts except EffectConstant We have the result on
4649 // top of the stack.
4650 if (!context()->IsEffect()) {
4651 context()->PlugTOS();
4654 EmitVariableAssignment(expr->expression()->AsVariableProxy()->var(),
4656 PrepareForBailoutForId(expr->AssignmentId(), TOS_REG);
4657 context()->Plug(x0);
4660 case NAMED_PROPERTY: {
4661 __ Mov(StoreDescriptor::NameRegister(),
4662 Operand(prop->key()->AsLiteral()->value()));
4663 __ Pop(StoreDescriptor::ReceiverRegister());
4664 CallStoreIC(expr->CountStoreFeedbackId());
4665 PrepareForBailoutForId(expr->AssignmentId(), TOS_REG);
4666 if (expr->is_postfix()) {
4667 if (!context()->IsEffect()) {
4668 context()->PlugTOS();
4671 context()->Plug(x0);
4675 case NAMED_SUPER_PROPERTY: {
4676 EmitNamedSuperPropertyStore(prop);
4677 if (expr->is_postfix()) {
4678 if (!context()->IsEffect()) {
4679 context()->PlugTOS();
4682 context()->Plug(x0);
4686 case KEYED_SUPER_PROPERTY: {
4687 EmitKeyedSuperPropertyStore(prop);
4688 if (expr->is_postfix()) {
4689 if (!context()->IsEffect()) {
4690 context()->PlugTOS();
4693 context()->Plug(x0);
4697 case KEYED_PROPERTY: {
4698 __ Pop(StoreDescriptor::NameRegister());
4699 __ Pop(StoreDescriptor::ReceiverRegister());
4701 CodeFactory::KeyedStoreIC(isolate(), language_mode()).code();
4702 CallIC(ic, expr->CountStoreFeedbackId());
4703 PrepareForBailoutForId(expr->AssignmentId(), TOS_REG);
4704 if (expr->is_postfix()) {
4705 if (!context()->IsEffect()) {
4706 context()->PlugTOS();
4709 context()->Plug(x0);
4717 void FullCodeGenerator::VisitForTypeofValue(Expression* expr) {
4718 DCHECK(!context()->IsEffect());
4719 DCHECK(!context()->IsTest());
4720 VariableProxy* proxy = expr->AsVariableProxy();
4721 if (proxy != NULL && proxy->var()->IsUnallocated()) {
4722 Comment cmnt(masm_, "Global variable");
4723 __ Ldr(LoadDescriptor::ReceiverRegister(), GlobalObjectMemOperand());
4724 __ Mov(LoadDescriptor::NameRegister(), Operand(proxy->name()));
4725 if (FLAG_vector_ics) {
4726 __ Mov(VectorLoadICDescriptor::SlotRegister(),
4727 SmiFromSlot(proxy->VariableFeedbackSlot()));
4729 // Use a regular load, not a contextual load, to avoid a reference
4731 CallLoadIC(NOT_CONTEXTUAL);
4732 PrepareForBailout(expr, TOS_REG);
4733 context()->Plug(x0);
4734 } else if (proxy != NULL && proxy->var()->IsLookupSlot()) {
4737 // Generate code for loading from variables potentially shadowed
4738 // by eval-introduced variables.
4739 EmitDynamicLookupFastCase(proxy, INSIDE_TYPEOF, &slow, &done);
4742 __ Mov(x0, Operand(proxy->name()));
4744 __ CallRuntime(Runtime::kLoadLookupSlotNoReferenceError, 2);
4745 PrepareForBailout(expr, TOS_REG);
4748 context()->Plug(x0);
4750 // This expression cannot throw a reference error at the top level.
4751 VisitInDuplicateContext(expr);
4756 void FullCodeGenerator::EmitLiteralCompareTypeof(Expression* expr,
4757 Expression* sub_expr,
4758 Handle<String> check) {
4759 ASM_LOCATION("FullCodeGenerator::EmitLiteralCompareTypeof");
4760 Comment cmnt(masm_, "[ EmitLiteralCompareTypeof");
4761 Label materialize_true, materialize_false;
4762 Label* if_true = NULL;
4763 Label* if_false = NULL;
4764 Label* fall_through = NULL;
4765 context()->PrepareTest(&materialize_true, &materialize_false,
4766 &if_true, &if_false, &fall_through);
4768 { AccumulatorValueContext context(this);
4769 VisitForTypeofValue(sub_expr);
4771 PrepareForBailoutBeforeSplit(expr, true, if_true, if_false);
4773 Factory* factory = isolate()->factory();
4774 if (String::Equals(check, factory->number_string())) {
4775 ASM_LOCATION("FullCodeGenerator::EmitLiteralCompareTypeof number_string");
4776 __ JumpIfSmi(x0, if_true);
4777 __ Ldr(x0, FieldMemOperand(x0, HeapObject::kMapOffset));
4778 __ CompareRoot(x0, Heap::kHeapNumberMapRootIndex);
4779 Split(eq, if_true, if_false, fall_through);
4780 } else if (String::Equals(check, factory->string_string())) {
4781 ASM_LOCATION("FullCodeGenerator::EmitLiteralCompareTypeof string_string");
4782 __ JumpIfSmi(x0, if_false);
4783 // Check for undetectable objects => false.
4784 __ JumpIfObjectType(x0, x0, x1, FIRST_NONSTRING_TYPE, if_false, ge);
4785 __ Ldrb(x1, FieldMemOperand(x0, Map::kBitFieldOffset));
4786 __ TestAndSplit(x1, 1 << Map::kIsUndetectable, if_true, if_false,
4788 } else if (String::Equals(check, factory->symbol_string())) {
4789 ASM_LOCATION("FullCodeGenerator::EmitLiteralCompareTypeof symbol_string");
4790 __ JumpIfSmi(x0, if_false);
4791 __ CompareObjectType(x0, x0, x1, SYMBOL_TYPE);
4792 Split(eq, if_true, if_false, fall_through);
4793 } else if (String::Equals(check, factory->boolean_string())) {
4794 ASM_LOCATION("FullCodeGenerator::EmitLiteralCompareTypeof boolean_string");
4795 __ JumpIfRoot(x0, Heap::kTrueValueRootIndex, if_true);
4796 __ CompareRoot(x0, Heap::kFalseValueRootIndex);
4797 Split(eq, if_true, if_false, fall_through);
4798 } else if (String::Equals(check, factory->undefined_string())) {
4800 "FullCodeGenerator::EmitLiteralCompareTypeof undefined_string");
4801 __ JumpIfRoot(x0, Heap::kUndefinedValueRootIndex, if_true);
4802 __ JumpIfSmi(x0, if_false);
4803 // Check for undetectable objects => true.
4804 __ Ldr(x0, FieldMemOperand(x0, HeapObject::kMapOffset));
4805 __ Ldrb(x1, FieldMemOperand(x0, Map::kBitFieldOffset));
4806 __ TestAndSplit(x1, 1 << Map::kIsUndetectable, if_false, if_true,
4808 } else if (String::Equals(check, factory->function_string())) {
4809 ASM_LOCATION("FullCodeGenerator::EmitLiteralCompareTypeof function_string");
4810 __ JumpIfSmi(x0, if_false);
4811 STATIC_ASSERT(NUM_OF_CALLABLE_SPEC_OBJECT_TYPES == 2);
4812 __ JumpIfObjectType(x0, x10, x11, JS_FUNCTION_TYPE, if_true);
4813 __ CompareAndSplit(x11, JS_FUNCTION_PROXY_TYPE, eq, if_true, if_false,
4816 } else if (String::Equals(check, factory->object_string())) {
4817 ASM_LOCATION("FullCodeGenerator::EmitLiteralCompareTypeof object_string");
4818 __ JumpIfSmi(x0, if_false);
4819 __ JumpIfRoot(x0, Heap::kNullValueRootIndex, if_true);
4820 // Check for JS objects => true.
4822 __ JumpIfObjectType(x0, map, x11, FIRST_NONCALLABLE_SPEC_OBJECT_TYPE,
4824 __ CompareInstanceType(map, x11, LAST_NONCALLABLE_SPEC_OBJECT_TYPE);
4826 // Check for undetectable objects => false.
4827 __ Ldrb(x10, FieldMemOperand(map, Map::kBitFieldOffset));
4829 __ TestAndSplit(x10, 1 << Map::kIsUndetectable, if_true, if_false,
4833 ASM_LOCATION("FullCodeGenerator::EmitLiteralCompareTypeof other");
4834 if (if_false != fall_through) __ B(if_false);
4836 context()->Plug(if_true, if_false);
4840 void FullCodeGenerator::VisitCompareOperation(CompareOperation* expr) {
4841 Comment cmnt(masm_, "[ CompareOperation");
4842 SetSourcePosition(expr->position());
4844 // Try to generate an optimized comparison with a literal value.
4845 // TODO(jbramley): This only checks common values like NaN or undefined.
4846 // Should it also handle ARM64 immediate operands?
4847 if (TryLiteralCompare(expr)) {
4851 // Assign labels according to context()->PrepareTest.
4852 Label materialize_true;
4853 Label materialize_false;
4854 Label* if_true = NULL;
4855 Label* if_false = NULL;
4856 Label* fall_through = NULL;
4857 context()->PrepareTest(&materialize_true, &materialize_false,
4858 &if_true, &if_false, &fall_through);
4860 Token::Value op = expr->op();
4861 VisitForStackValue(expr->left());
4864 VisitForStackValue(expr->right());
4865 __ InvokeBuiltin(Builtins::IN, CALL_FUNCTION);
4866 PrepareForBailoutBeforeSplit(expr, false, NULL, NULL);
4867 __ CompareRoot(x0, Heap::kTrueValueRootIndex);
4868 Split(eq, if_true, if_false, fall_through);
4871 case Token::INSTANCEOF: {
4872 VisitForStackValue(expr->right());
4873 InstanceofStub stub(isolate(), InstanceofStub::kNoFlags);
4875 PrepareForBailoutBeforeSplit(expr, true, if_true, if_false);
4876 // The stub returns 0 for true.
4877 __ CompareAndSplit(x0, 0, eq, if_true, if_false, fall_through);
4882 VisitForAccumulatorValue(expr->right());
4883 Condition cond = CompareIC::ComputeCondition(op);
4885 // Pop the stack value.
4888 JumpPatchSite patch_site(masm_);
4889 if (ShouldInlineSmiCase(op)) {
4891 patch_site.EmitJumpIfEitherNotSmi(x0, x1, &slow_case);
4893 Split(cond, if_true, if_false, NULL);
4894 __ Bind(&slow_case);
4897 // Record position and call the compare IC.
4898 SetSourcePosition(expr->position());
4899 Handle<Code> ic = CodeFactory::CompareIC(isolate(), op).code();
4900 CallIC(ic, expr->CompareOperationFeedbackId());
4901 patch_site.EmitPatchInfo();
4902 PrepareForBailoutBeforeSplit(expr, true, if_true, if_false);
4903 __ CompareAndSplit(x0, 0, cond, if_true, if_false, fall_through);
4907 // Convert the result of the comparison into one expected for this
4908 // expression's context.
4909 context()->Plug(if_true, if_false);
4913 void FullCodeGenerator::EmitLiteralCompareNil(CompareOperation* expr,
4914 Expression* sub_expr,
4916 ASM_LOCATION("FullCodeGenerator::EmitLiteralCompareNil");
4917 Label materialize_true, materialize_false;
4918 Label* if_true = NULL;
4919 Label* if_false = NULL;
4920 Label* fall_through = NULL;
4921 context()->PrepareTest(&materialize_true, &materialize_false,
4922 &if_true, &if_false, &fall_through);
4924 VisitForAccumulatorValue(sub_expr);
4925 PrepareForBailoutBeforeSplit(expr, true, if_true, if_false);
4927 if (expr->op() == Token::EQ_STRICT) {
4928 Heap::RootListIndex nil_value = nil == kNullValue ?
4929 Heap::kNullValueRootIndex :
4930 Heap::kUndefinedValueRootIndex;
4931 __ CompareRoot(x0, nil_value);
4932 Split(eq, if_true, if_false, fall_through);
4934 Handle<Code> ic = CompareNilICStub::GetUninitialized(isolate(), nil);
4935 CallIC(ic, expr->CompareOperationFeedbackId());
4936 __ CompareAndSplit(x0, 0, ne, if_true, if_false, fall_through);
4939 context()->Plug(if_true, if_false);
4943 void FullCodeGenerator::VisitThisFunction(ThisFunction* expr) {
4944 __ Ldr(x0, MemOperand(fp, JavaScriptFrameConstants::kFunctionOffset));
4945 context()->Plug(x0);
4949 void FullCodeGenerator::VisitYield(Yield* expr) {
4950 Comment cmnt(masm_, "[ Yield");
4951 // Evaluate yielded value first; the initial iterator definition depends on
4952 // this. It stays on the stack while we update the iterator.
4953 VisitForStackValue(expr->expression());
4955 // TODO(jbramley): Tidy this up once the merge is done, using named registers
4956 // and suchlike. The implementation changes a little by bleeding_edge so I
4957 // don't want to spend too much time on it now.
4959 switch (expr->yield_kind()) {
4960 case Yield::kSuspend:
4961 // Pop value from top-of-stack slot; box result into result register.
4962 EmitCreateIteratorResult(false);
4963 __ Push(result_register());
4965 case Yield::kInitial: {
4966 Label suspend, continuation, post_runtime, resume;
4970 // TODO(jbramley): This label is bound here because the following code
4971 // looks at its pos(). Is it possible to do something more efficient here,
4972 // perhaps using Adr?
4973 __ Bind(&continuation);
4977 VisitForAccumulatorValue(expr->generator_object());
4978 DCHECK((continuation.pos() > 0) && Smi::IsValid(continuation.pos()));
4979 __ Mov(x1, Smi::FromInt(continuation.pos()));
4980 __ Str(x1, FieldMemOperand(x0, JSGeneratorObject::kContinuationOffset));
4981 __ Str(cp, FieldMemOperand(x0, JSGeneratorObject::kContextOffset));
4983 __ RecordWriteField(x0, JSGeneratorObject::kContextOffset, x1, x2,
4984 kLRHasBeenSaved, kDontSaveFPRegs);
4985 __ Add(x1, fp, StandardFrameConstants::kExpressionsOffset);
4986 __ Cmp(__ StackPointer(), x1);
4987 __ B(eq, &post_runtime);
4988 __ Push(x0); // generator object
4989 __ CallRuntime(Runtime::kSuspendJSGeneratorObject, 1);
4990 __ Ldr(cp, MemOperand(fp, StandardFrameConstants::kContextOffset));
4991 __ Bind(&post_runtime);
4992 __ Pop(result_register());
4993 EmitReturnSequence();
4996 context()->Plug(result_register());
5000 case Yield::kFinal: {
5001 VisitForAccumulatorValue(expr->generator_object());
5002 __ Mov(x1, Smi::FromInt(JSGeneratorObject::kGeneratorClosed));
5003 __ Str(x1, FieldMemOperand(result_register(),
5004 JSGeneratorObject::kContinuationOffset));
5005 // Pop value from top-of-stack slot, box result into result register.
5006 EmitCreateIteratorResult(true);
5007 EmitUnwindBeforeReturn();
5008 EmitReturnSequence();
5012 case Yield::kDelegating: {
5013 VisitForStackValue(expr->generator_object());
5015 // Initial stack layout is as follows:
5016 // [sp + 1 * kPointerSize] iter
5017 // [sp + 0 * kPointerSize] g
5019 Label l_catch, l_try, l_suspend, l_continuation, l_resume;
5020 Label l_next, l_call, l_loop;
5021 Register load_receiver = LoadDescriptor::ReceiverRegister();
5022 Register load_name = LoadDescriptor::NameRegister();
5024 // Initial send value is undefined.
5025 __ LoadRoot(x0, Heap::kUndefinedValueRootIndex);
5028 // catch (e) { receiver = iter; f = 'throw'; arg = e; goto l_call; }
5030 __ LoadRoot(load_name, Heap::kthrow_stringRootIndex); // "throw"
5031 __ Peek(x3, 1 * kPointerSize); // iter
5032 __ Push(load_name, x3, x0); // "throw", iter, except
5035 // try { received = %yield result }
5036 // Shuffle the received result above a try handler and yield it without
5039 __ Pop(x0); // result
5040 EnterTryBlock(expr->index(), &l_catch);
5041 const int try_block_size = TryCatch::kElementCount * kPointerSize;
5042 __ Push(x0); // result
5045 // TODO(jbramley): This label is bound here because the following code
5046 // looks at its pos(). Is it possible to do something more efficient here,
5047 // perhaps using Adr?
5048 __ Bind(&l_continuation);
5051 __ Bind(&l_suspend);
5052 const int generator_object_depth = kPointerSize + try_block_size;
5053 __ Peek(x0, generator_object_depth);
5055 __ Push(Smi::FromInt(expr->index())); // handler-index
5056 DCHECK((l_continuation.pos() > 0) && Smi::IsValid(l_continuation.pos()));
5057 __ Mov(x1, Smi::FromInt(l_continuation.pos()));
5058 __ Str(x1, FieldMemOperand(x0, JSGeneratorObject::kContinuationOffset));
5059 __ Str(cp, FieldMemOperand(x0, JSGeneratorObject::kContextOffset));
5061 __ RecordWriteField(x0, JSGeneratorObject::kContextOffset, x1, x2,
5062 kLRHasBeenSaved, kDontSaveFPRegs);
5063 __ CallRuntime(Runtime::kSuspendJSGeneratorObject, 2);
5064 __ Ldr(cp, MemOperand(fp, StandardFrameConstants::kContextOffset));
5065 __ Pop(x0); // result
5066 EmitReturnSequence();
5067 __ Bind(&l_resume); // received in x0
5068 ExitTryBlock(expr->index());
5070 // receiver = iter; f = 'next'; arg = received;
5073 __ LoadRoot(load_name, Heap::knext_stringRootIndex); // "next"
5074 __ Peek(x3, 1 * kPointerSize); // iter
5075 __ Push(load_name, x3, x0); // "next", iter, received
5077 // result = receiver[f](arg);
5079 __ Peek(load_receiver, 1 * kPointerSize);
5080 __ Peek(load_name, 2 * kPointerSize);
5081 if (FLAG_vector_ics) {
5082 __ Mov(VectorLoadICDescriptor::SlotRegister(),
5083 SmiFromSlot(expr->KeyedLoadFeedbackSlot()));
5085 Handle<Code> ic = CodeFactory::KeyedLoadIC(isolate()).code();
5086 CallIC(ic, TypeFeedbackId::None());
5088 __ Poke(x1, 2 * kPointerSize);
5089 CallFunctionStub stub(isolate(), 1, CALL_AS_METHOD);
5092 __ Ldr(cp, MemOperand(fp, StandardFrameConstants::kContextOffset));
5093 __ Drop(1); // The function is still on the stack; drop it.
5095 // if (!result.done) goto l_try;
5097 __ Move(load_receiver, x0);
5099 __ Push(load_receiver); // save result
5100 __ LoadRoot(load_name, Heap::kdone_stringRootIndex); // "done"
5101 if (FLAG_vector_ics) {
5102 __ Mov(VectorLoadICDescriptor::SlotRegister(),
5103 SmiFromSlot(expr->DoneFeedbackSlot()));
5105 CallLoadIC(NOT_CONTEXTUAL); // x0=result.done
5106 // The ToBooleanStub argument (result.done) is in x0.
5107 Handle<Code> bool_ic = ToBooleanStub::GetUninitialized(isolate());
5112 __ Pop(load_receiver); // result
5113 __ LoadRoot(load_name, Heap::kvalue_stringRootIndex); // "value"
5114 if (FLAG_vector_ics) {
5115 __ Mov(VectorLoadICDescriptor::SlotRegister(),
5116 SmiFromSlot(expr->ValueFeedbackSlot()));
5118 CallLoadIC(NOT_CONTEXTUAL); // x0=result.value
5119 context()->DropAndPlug(2, x0); // drop iter and g
5126 void FullCodeGenerator::EmitGeneratorResume(Expression *generator,
5128 JSGeneratorObject::ResumeMode resume_mode) {
5129 ASM_LOCATION("FullCodeGenerator::EmitGeneratorResume");
5130 Register generator_object = x1;
5131 Register the_hole = x2;
5132 Register operand_stack_size = w3;
5133 Register function = x4;
5135 // The value stays in x0, and is ultimately read by the resumed generator, as
5136 // if CallRuntime(Runtime::kSuspendJSGeneratorObject) returned it. Or it
5137 // is read to throw the value when the resumed generator is already closed. x1
5138 // will hold the generator object until the activation has been resumed.
5139 VisitForStackValue(generator);
5140 VisitForAccumulatorValue(value);
5141 __ Pop(generator_object);
5143 // Load suspended function and context.
5144 __ Ldr(cp, FieldMemOperand(generator_object,
5145 JSGeneratorObject::kContextOffset));
5146 __ Ldr(function, FieldMemOperand(generator_object,
5147 JSGeneratorObject::kFunctionOffset));
5149 // Load receiver and store as the first argument.
5150 __ Ldr(x10, FieldMemOperand(generator_object,
5151 JSGeneratorObject::kReceiverOffset));
5154 // Push holes for the rest of the arguments to the generator function.
5155 __ Ldr(x10, FieldMemOperand(function, JSFunction::kSharedFunctionInfoOffset));
5157 // The number of arguments is stored as an int32_t, and -1 is a marker
5158 // (SharedFunctionInfo::kDontAdaptArgumentsSentinel), so we need sign
5159 // extension to correctly handle it. However, in this case, we operate on
5160 // 32-bit W registers, so extension isn't required.
5161 __ Ldr(w10, FieldMemOperand(x10,
5162 SharedFunctionInfo::kFormalParameterCountOffset));
5163 __ LoadRoot(the_hole, Heap::kTheHoleValueRootIndex);
5164 __ PushMultipleTimes(the_hole, w10);
5166 // Enter a new JavaScript frame, and initialize its slots as they were when
5167 // the generator was suspended.
5168 Label resume_frame, done;
5169 __ Bl(&resume_frame);
5172 __ Bind(&resume_frame);
5173 __ Push(lr, // Return address.
5174 fp, // Caller's frame pointer.
5175 cp, // Callee's context.
5176 function); // Callee's JS Function.
5177 __ Add(fp, __ StackPointer(), kPointerSize * 2);
5179 // Load and untag the operand stack size.
5180 __ Ldr(x10, FieldMemOperand(generator_object,
5181 JSGeneratorObject::kOperandStackOffset));
5182 __ Ldr(operand_stack_size,
5183 UntagSmiFieldMemOperand(x10, FixedArray::kLengthOffset));
5185 // If we are sending a value and there is no operand stack, we can jump back
5187 if (resume_mode == JSGeneratorObject::NEXT) {
5189 __ Cbnz(operand_stack_size, &slow_resume);
5190 __ Ldr(x10, FieldMemOperand(function, JSFunction::kCodeEntryOffset));
5192 UntagSmiFieldMemOperand(generator_object,
5193 JSGeneratorObject::kContinuationOffset));
5194 __ Add(x10, x10, x11);
5195 __ Mov(x12, Smi::FromInt(JSGeneratorObject::kGeneratorExecuting));
5196 __ Str(x12, FieldMemOperand(generator_object,
5197 JSGeneratorObject::kContinuationOffset));
5200 __ Bind(&slow_resume);
5203 // Otherwise, we push holes for the operand stack and call the runtime to fix
5204 // up the stack and the handlers.
5205 __ PushMultipleTimes(the_hole, operand_stack_size);
5207 __ Mov(x10, Smi::FromInt(resume_mode));
5208 __ Push(generator_object, result_register(), x10);
5209 __ CallRuntime(Runtime::kResumeJSGeneratorObject, 3);
5210 // Not reached: the runtime call returns elsewhere.
5214 context()->Plug(result_register());
5218 void FullCodeGenerator::EmitCreateIteratorResult(bool done) {
5222 const int instance_size = 5 * kPointerSize;
5223 DCHECK_EQ(isolate()->native_context()->iterator_result_map()->instance_size(),
5226 // Allocate and populate an object with this form: { value: VAL, done: DONE }
5228 Register result = x0;
5229 __ Allocate(instance_size, result, x10, x11, &gc_required, TAG_OBJECT);
5232 __ Bind(&gc_required);
5233 __ Push(Smi::FromInt(instance_size));
5234 __ CallRuntime(Runtime::kAllocateInNewSpace, 1);
5235 __ Ldr(context_register(),
5236 MemOperand(fp, StandardFrameConstants::kContextOffset));
5238 __ Bind(&allocated);
5239 Register map_reg = x1;
5240 Register result_value = x2;
5241 Register boolean_done = x3;
5242 Register empty_fixed_array = x4;
5243 Register untagged_result = x5;
5244 __ Ldr(map_reg, GlobalObjectMemOperand());
5245 __ Ldr(map_reg, FieldMemOperand(map_reg, GlobalObject::kNativeContextOffset));
5247 ContextMemOperand(map_reg, Context::ITERATOR_RESULT_MAP_INDEX));
5248 __ Pop(result_value);
5249 __ Mov(boolean_done, Operand(isolate()->factory()->ToBoolean(done)));
5250 __ Mov(empty_fixed_array, Operand(isolate()->factory()->empty_fixed_array()));
5251 STATIC_ASSERT(JSObject::kPropertiesOffset + kPointerSize ==
5252 JSObject::kElementsOffset);
5253 STATIC_ASSERT(JSGeneratorObject::kResultValuePropertyOffset + kPointerSize ==
5254 JSGeneratorObject::kResultDonePropertyOffset);
5255 __ ObjectUntag(untagged_result, result);
5256 __ Str(map_reg, MemOperand(untagged_result, HeapObject::kMapOffset));
5257 __ Stp(empty_fixed_array, empty_fixed_array,
5258 MemOperand(untagged_result, JSObject::kPropertiesOffset));
5259 __ Stp(result_value, boolean_done,
5260 MemOperand(untagged_result,
5261 JSGeneratorObject::kResultValuePropertyOffset));
5263 // Only the value field needs a write barrier, as the other values are in the
5265 __ RecordWriteField(result, JSGeneratorObject::kResultValuePropertyOffset,
5266 x10, x11, kLRHasBeenSaved, kDontSaveFPRegs);
5270 // TODO(all): I don't like this method.
5271 // It seems to me that in too many places x0 is used in place of this.
5272 // Also, this function is not suitable for all places where x0 should be
5273 // abstracted (eg. when used as an argument). But some places assume that the
5274 // first argument register is x0, and use this function instead.
5275 // Considering that most of the register allocation is hard-coded in the
5276 // FullCodeGen, that it is unlikely we will need to change it extensively, and
5277 // that abstracting the allocation through functions would not yield any
5278 // performance benefit, I think the existence of this function is debatable.
5279 Register FullCodeGenerator::result_register() {
5284 Register FullCodeGenerator::context_register() {
5289 void FullCodeGenerator::StoreToFrameField(int frame_offset, Register value) {
5290 DCHECK(POINTER_SIZE_ALIGN(frame_offset) == frame_offset);
5291 __ Str(value, MemOperand(fp, frame_offset));
5295 void FullCodeGenerator::LoadContextField(Register dst, int context_index) {
5296 __ Ldr(dst, ContextMemOperand(cp, context_index));
5300 void FullCodeGenerator::PushFunctionArgumentForContextAllocation() {
5301 Scope* declaration_scope = scope()->DeclarationScope();
5302 if (declaration_scope->is_script_scope() ||
5303 declaration_scope->is_module_scope()) {
5304 // Contexts nested in the native context have a canonical empty function
5305 // as their closure, not the anonymous closure containing the global
5306 // code. Pass a smi sentinel and let the runtime look up the empty
5308 DCHECK(kSmiTag == 0);
5310 } else if (declaration_scope->is_eval_scope()) {
5311 // Contexts created by a call to eval have the same closure as the
5312 // context calling eval, not the anonymous closure containing the eval
5313 // code. Fetch it from the context.
5314 __ Ldr(x10, ContextMemOperand(cp, Context::CLOSURE_INDEX));
5317 DCHECK(declaration_scope->is_function_scope());
5318 __ Ldr(x10, MemOperand(fp, JavaScriptFrameConstants::kFunctionOffset));
5324 void FullCodeGenerator::EnterFinallyBlock() {
5325 ASM_LOCATION("FullCodeGenerator::EnterFinallyBlock");
5326 DCHECK(!result_register().is(x10));
5327 // Preserve the result register while executing finally block.
5328 // Also cook the return address in lr to the stack (smi encoded Code* delta).
5329 __ Sub(x10, lr, Operand(masm_->CodeObject()));
5331 __ Push(result_register(), x10);
5333 // Store pending message while executing finally block.
5334 ExternalReference pending_message_obj =
5335 ExternalReference::address_of_pending_message_obj(isolate());
5336 __ Mov(x10, pending_message_obj);
5337 __ Ldr(x10, MemOperand(x10));
5342 void FullCodeGenerator::ExitFinallyBlock() {
5343 ASM_LOCATION("FullCodeGenerator::ExitFinallyBlock");
5344 DCHECK(!result_register().is(x10));
5346 // Restore pending message from stack.
5348 ExternalReference pending_message_obj =
5349 ExternalReference::address_of_pending_message_obj(isolate());
5350 __ Mov(x13, pending_message_obj);
5351 __ Str(x10, MemOperand(x13));
5353 // Restore result register and cooked return address from the stack.
5354 __ Pop(x10, result_register());
5356 // Uncook the return address (see EnterFinallyBlock).
5358 __ Add(x11, x10, Operand(masm_->CodeObject()));
5366 void BackEdgeTable::PatchAt(Code* unoptimized_code,
5368 BackEdgeState target_state,
5369 Code* replacement_code) {
5370 // Turn the jump into a nop.
5371 Address branch_address = pc - 3 * kInstructionSize;
5372 PatchingAssembler patcher(branch_address, 1);
5374 DCHECK(Instruction::Cast(branch_address)
5375 ->IsNop(Assembler::INTERRUPT_CODE_NOP) ||
5376 (Instruction::Cast(branch_address)->IsCondBranchImm() &&
5377 Instruction::Cast(branch_address)->ImmPCOffset() ==
5378 6 * kInstructionSize));
5380 switch (target_state) {
5382 // <decrement profiling counter>
5383 // .. .. .. .. b.pl ok
5384 // .. .. .. .. ldr x16, pc+<interrupt stub address>
5385 // .. .. .. .. blr x16
5386 // ... more instructions.
5388 // Jump offset is 6 instructions.
5391 case ON_STACK_REPLACEMENT:
5392 case OSR_AFTER_STACK_CHECK:
5393 // <decrement profiling counter>
5394 // .. .. .. .. mov x0, x0 (NOP)
5395 // .. .. .. .. ldr x16, pc+<on-stack replacement address>
5396 // .. .. .. .. blr x16
5397 patcher.nop(Assembler::INTERRUPT_CODE_NOP);
5401 // Replace the call address.
5402 Instruction* load = Instruction::Cast(pc)->preceding(2);
5403 Address interrupt_address_pointer =
5404 reinterpret_cast<Address>(load) + load->ImmPCOffset();
5405 DCHECK((Memory::uint64_at(interrupt_address_pointer) ==
5406 reinterpret_cast<uint64_t>(unoptimized_code->GetIsolate()
5408 ->OnStackReplacement()
5410 (Memory::uint64_at(interrupt_address_pointer) ==
5411 reinterpret_cast<uint64_t>(unoptimized_code->GetIsolate()
5415 (Memory::uint64_at(interrupt_address_pointer) ==
5416 reinterpret_cast<uint64_t>(unoptimized_code->GetIsolate()
5418 ->OsrAfterStackCheck()
5420 (Memory::uint64_at(interrupt_address_pointer) ==
5421 reinterpret_cast<uint64_t>(unoptimized_code->GetIsolate()
5423 ->OnStackReplacement()
5425 Memory::uint64_at(interrupt_address_pointer) =
5426 reinterpret_cast<uint64_t>(replacement_code->entry());
5428 unoptimized_code->GetHeap()->incremental_marking()->RecordCodeTargetPatch(
5429 unoptimized_code, reinterpret_cast<Address>(load), replacement_code);
5433 BackEdgeTable::BackEdgeState BackEdgeTable::GetBackEdgeState(
5435 Code* unoptimized_code,
5437 // TODO(jbramley): There should be some extra assertions here (as in the ARM
5438 // back-end), but this function is gone in bleeding_edge so it might not
5440 Instruction* jump_or_nop = Instruction::Cast(pc)->preceding(3);
5442 if (jump_or_nop->IsNop(Assembler::INTERRUPT_CODE_NOP)) {
5443 Instruction* load = Instruction::Cast(pc)->preceding(2);
5444 uint64_t entry = Memory::uint64_at(reinterpret_cast<Address>(load) +
5445 load->ImmPCOffset());
5446 if (entry == reinterpret_cast<uint64_t>(
5447 isolate->builtins()->OnStackReplacement()->entry())) {
5448 return ON_STACK_REPLACEMENT;
5449 } else if (entry == reinterpret_cast<uint64_t>(
5450 isolate->builtins()->OsrAfterStackCheck()->entry())) {
5451 return OSR_AFTER_STACK_CHECK;
5461 } } // namespace v8::internal
5463 #endif // V8_TARGET_ARCH_ARM64