1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
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/arm/code-stubs-arm.h"
21 #include "src/arm/macro-assembler-arm.h"
26 #define __ ACCESS_MASM(masm_)
29 // A patch site is a location in the code which it is possible to patch. This
30 // class has a number of methods to emit the code which is patchable and the
31 // method EmitPatchInfo to record a marker back to the patchable code. This
32 // marker is a cmp rx, #yyy instruction, and x * 0x00000fff + yyy (raw 12 bit
33 // immediate value is used) is the delta from the pc to the first instruction of
34 // the patchable code.
35 class JumpPatchSite BASE_EMBEDDED {
37 explicit JumpPatchSite(MacroAssembler* masm) : masm_(masm) {
39 info_emitted_ = false;
44 DCHECK(patch_site_.is_bound() == info_emitted_);
47 // When initially emitting this ensure that a jump is always generated to skip
48 // the inlined smi code.
49 void EmitJumpIfNotSmi(Register reg, Label* target) {
50 DCHECK(!patch_site_.is_bound() && !info_emitted_);
51 Assembler::BlockConstPoolScope block_const_pool(masm_);
52 __ bind(&patch_site_);
53 __ cmp(reg, Operand(reg));
54 __ b(eq, target); // Always taken before patched.
57 // When initially emitting this ensure that a jump is never generated to skip
58 // the inlined smi code.
59 void EmitJumpIfSmi(Register reg, Label* target) {
60 DCHECK(!patch_site_.is_bound() && !info_emitted_);
61 Assembler::BlockConstPoolScope block_const_pool(masm_);
62 __ bind(&patch_site_);
63 __ cmp(reg, Operand(reg));
64 __ b(ne, target); // Never taken before patched.
67 void EmitPatchInfo() {
68 // Block literal pool emission whilst recording patch site information.
69 Assembler::BlockConstPoolScope block_const_pool(masm_);
70 if (patch_site_.is_bound()) {
71 int delta_to_patch_site = masm_->InstructionsGeneratedSince(&patch_site_);
73 reg.set_code(delta_to_patch_site / kOff12Mask);
74 __ cmp_raw_immediate(reg, delta_to_patch_site % kOff12Mask);
79 __ nop(); // Signals no inlined code.
84 MacroAssembler* masm_;
92 // Generate code for a JS function. On entry to the function the receiver
93 // and arguments have been pushed on the stack left to right. The actual
94 // argument count matches the formal parameter count expected by the
97 // The live registers are:
98 // o r1: the JS function object being called (i.e., ourselves)
100 // o pp: our caller's constant pool pointer (if FLAG_enable_ool_constant_pool)
101 // o fp: our caller's frame pointer
102 // o sp: stack pointer
103 // o lr: return address
105 // The function builds a JS frame. Please see JavaScriptFrameConstants in
106 // frames-arm.h for its layout.
107 void FullCodeGenerator::Generate() {
108 CompilationInfo* info = info_;
110 isolate()->factory()->NewFixedArray(function()->handler_count(), TENURED);
112 profiling_counter_ = isolate()->factory()->NewCell(
113 Handle<Smi>(Smi::FromInt(FLAG_interrupt_budget), isolate()));
114 SetFunctionPosition(function());
115 Comment cmnt(masm_, "[ function compiled by full code generator");
117 ProfileEntryHookStub::MaybeCallEntryHook(masm_);
120 if (strlen(FLAG_stop_at) > 0 &&
121 info->function()->name()->IsUtf8EqualTo(CStrVector(FLAG_stop_at))) {
126 // Sloppy mode functions and builtins need to replace the receiver with the
127 // global proxy when called as functions (without an explicit receiver
129 if (is_sloppy(info->language_mode()) && !info->is_native()) {
131 int receiver_offset = info->scope()->num_parameters() * kPointerSize;
132 __ ldr(r2, MemOperand(sp, receiver_offset));
133 __ CompareRoot(r2, Heap::kUndefinedValueRootIndex);
136 __ ldr(r2, GlobalObjectOperand());
137 __ ldr(r2, FieldMemOperand(r2, GlobalObject::kGlobalProxyOffset));
139 __ str(r2, MemOperand(sp, receiver_offset));
144 // Open a frame scope to indicate that there is a frame on the stack. The
145 // MANUAL indicates that the scope shouldn't actually generate code to set up
146 // the frame (that is done below).
147 FrameScope frame_scope(masm_, StackFrame::MANUAL);
149 info->set_prologue_offset(masm_->pc_offset());
150 __ Prologue(info->IsCodePreAgingActive());
151 info->AddNoFrameRange(0, masm_->pc_offset());
153 { Comment cmnt(masm_, "[ Allocate locals");
154 int locals_count = info->scope()->num_stack_slots();
155 // Generators allocate locals, if any, in context slots.
156 DCHECK(!IsGeneratorFunction(info->function()->kind()) || locals_count == 0);
157 if (locals_count > 0) {
158 if (locals_count >= 128) {
160 __ sub(r9, sp, Operand(locals_count * kPointerSize));
161 __ LoadRoot(r2, Heap::kRealStackLimitRootIndex);
162 __ cmp(r9, Operand(r2));
164 __ InvokeBuiltin(Builtins::STACK_OVERFLOW, CALL_FUNCTION);
167 __ LoadRoot(r9, Heap::kUndefinedValueRootIndex);
168 int kMaxPushes = FLAG_optimize_for_size ? 4 : 32;
169 if (locals_count >= kMaxPushes) {
170 int loop_iterations = locals_count / kMaxPushes;
171 __ mov(r2, Operand(loop_iterations));
173 __ bind(&loop_header);
175 for (int i = 0; i < kMaxPushes; i++) {
178 // Continue loop if not done.
179 __ sub(r2, r2, Operand(1), SetCC);
180 __ b(&loop_header, ne);
182 int remaining = locals_count % kMaxPushes;
183 // Emit the remaining pushes.
184 for (int i = 0; i < remaining; i++) {
190 bool function_in_register = true;
192 // Possibly allocate a local context.
193 int heap_slots = info->scope()->num_heap_slots() - Context::MIN_CONTEXT_SLOTS;
194 if (heap_slots > 0) {
195 // Argument to NewContext is the function, which is still in r1.
196 Comment cmnt(masm_, "[ Allocate context");
197 bool need_write_barrier = true;
198 if (FLAG_harmony_scoping && info->scope()->is_script_scope()) {
200 __ Push(info->scope()->GetScopeInfo(info->isolate()));
201 __ CallRuntime(Runtime::kNewScriptContext, 2);
202 } else if (heap_slots <= FastNewContextStub::kMaximumSlots) {
203 FastNewContextStub stub(isolate(), heap_slots);
205 // Result of FastNewContextStub is always in new space.
206 need_write_barrier = false;
209 __ CallRuntime(Runtime::kNewFunctionContext, 1);
211 function_in_register = false;
212 // Context is returned in r0. It replaces the context passed to us.
213 // It's saved in the stack and kept live in cp.
215 __ str(r0, MemOperand(fp, StandardFrameConstants::kContextOffset));
216 // Copy any necessary parameters into the context.
217 int num_parameters = info->scope()->num_parameters();
218 for (int i = 0; i < num_parameters; i++) {
219 Variable* var = scope()->parameter(i);
220 if (var->IsContextSlot()) {
221 int parameter_offset = StandardFrameConstants::kCallerSPOffset +
222 (num_parameters - 1 - i) * kPointerSize;
223 // Load parameter from stack.
224 __ ldr(r0, MemOperand(fp, parameter_offset));
225 // Store it in the context.
226 MemOperand target = ContextOperand(cp, var->index());
229 // Update the write barrier.
230 if (need_write_barrier) {
231 __ RecordWriteContextSlot(
232 cp, target.offset(), r0, r3, kLRHasBeenSaved, kDontSaveFPRegs);
233 } else if (FLAG_debug_code) {
235 __ JumpIfInNewSpace(cp, r0, &done);
236 __ Abort(kExpectedNewSpaceObject);
243 // Possibly allocate RestParameters
245 Variable* rest_param = scope()->rest_parameter(&rest_index);
247 Comment cmnt(masm_, "[ Allocate rest parameter array");
249 int num_parameters = info->scope()->num_parameters();
250 int offset = num_parameters * kPointerSize;
251 __ add(r3, fp, Operand(StandardFrameConstants::kCallerSPOffset + offset));
252 __ mov(r2, Operand(Smi::FromInt(num_parameters)));
253 __ mov(r1, Operand(Smi::FromInt(rest_index)));
256 RestParamAccessStub stub(isolate());
259 SetVar(rest_param, r0, r1, r2);
262 Variable* arguments = scope()->arguments();
263 if (arguments != NULL) {
264 // Function uses arguments object.
265 Comment cmnt(masm_, "[ Allocate arguments object");
266 if (!function_in_register) {
267 // Load this again, if it's used by the local context below.
268 __ ldr(r3, MemOperand(fp, JavaScriptFrameConstants::kFunctionOffset));
272 // Receiver is just before the parameters on the caller's stack.
273 int num_parameters = info->scope()->num_parameters();
274 int offset = num_parameters * kPointerSize;
276 Operand(StandardFrameConstants::kCallerSPOffset + offset));
277 __ mov(r1, Operand(Smi::FromInt(num_parameters)));
280 // Arguments to ArgumentsAccessStub:
281 // function, receiver address, parameter count.
282 // The stub will rewrite receiever and parameter count if the previous
283 // stack frame was an arguments adapter frame.
284 ArgumentsAccessStub::HasNewTarget has_new_target =
285 IsSubclassConstructor(info->function()->kind())
286 ? ArgumentsAccessStub::HAS_NEW_TARGET
287 : ArgumentsAccessStub::NO_NEW_TARGET;
288 ArgumentsAccessStub::Type type;
289 if (is_strict(language_mode()) || !is_simple_parameter_list()) {
290 type = ArgumentsAccessStub::NEW_STRICT;
291 } else if (function()->has_duplicate_parameters()) {
292 type = ArgumentsAccessStub::NEW_SLOPPY_SLOW;
294 type = ArgumentsAccessStub::NEW_SLOPPY_FAST;
296 ArgumentsAccessStub stub(isolate(), type, has_new_target);
299 SetVar(arguments, r0, r1, r2);
303 __ CallRuntime(Runtime::kTraceEnter, 0);
306 // Visit the declarations and body unless there is an illegal
308 if (scope()->HasIllegalRedeclaration()) {
309 Comment cmnt(masm_, "[ Declarations");
310 scope()->VisitIllegalRedeclaration(this);
313 PrepareForBailoutForId(BailoutId::FunctionEntry(), NO_REGISTERS);
314 { Comment cmnt(masm_, "[ Declarations");
315 // For named function expressions, declare the function name as a
317 if (scope()->is_function_scope() && scope()->function() != NULL) {
318 VariableDeclaration* function = scope()->function();
319 DCHECK(function->proxy()->var()->mode() == CONST ||
320 function->proxy()->var()->mode() == CONST_LEGACY);
321 DCHECK(function->proxy()->var()->location() != Variable::UNALLOCATED);
322 VisitVariableDeclaration(function);
324 VisitDeclarations(scope()->declarations());
327 { Comment cmnt(masm_, "[ Stack check");
328 PrepareForBailoutForId(BailoutId::Declarations(), NO_REGISTERS);
330 __ LoadRoot(ip, Heap::kStackLimitRootIndex);
331 __ cmp(sp, Operand(ip));
333 Handle<Code> stack_check = isolate()->builtins()->StackCheck();
334 PredictableCodeSizeScope predictable(masm_,
335 masm_->CallSize(stack_check, RelocInfo::CODE_TARGET));
336 __ Call(stack_check, RelocInfo::CODE_TARGET);
340 { Comment cmnt(masm_, "[ Body");
341 DCHECK(loop_depth() == 0);
342 VisitStatements(function()->body());
343 DCHECK(loop_depth() == 0);
347 // Always emit a 'return undefined' in case control fell off the end of
349 { Comment cmnt(masm_, "[ return <undefined>;");
350 __ LoadRoot(r0, Heap::kUndefinedValueRootIndex);
352 EmitReturnSequence();
354 // Force emit the constant pool, so it doesn't get emitted in the middle
355 // of the back edge table.
356 masm()->CheckConstPool(true, false);
360 void FullCodeGenerator::ClearAccumulator() {
361 __ mov(r0, Operand(Smi::FromInt(0)));
365 void FullCodeGenerator::EmitProfilingCounterDecrement(int delta) {
366 __ mov(r2, Operand(profiling_counter_));
367 __ ldr(r3, FieldMemOperand(r2, Cell::kValueOffset));
368 __ sub(r3, r3, Operand(Smi::FromInt(delta)), SetCC);
369 __ str(r3, FieldMemOperand(r2, Cell::kValueOffset));
373 #ifdef CAN_USE_ARMV7_INSTRUCTIONS
374 static const int kProfileCounterResetSequenceLength = 5 * Assembler::kInstrSize;
376 static const int kProfileCounterResetSequenceLength = 7 * Assembler::kInstrSize;
380 void FullCodeGenerator::EmitProfilingCounterReset() {
381 Assembler::BlockConstPoolScope block_const_pool(masm_);
382 PredictableCodeSizeScope predictable_code_size_scope(
383 masm_, kProfileCounterResetSequenceLength);
386 int reset_value = FLAG_interrupt_budget;
387 if (info_->is_debug()) {
388 // Detect debug break requests as soon as possible.
389 reset_value = FLAG_interrupt_budget >> 4;
391 __ mov(r2, Operand(profiling_counter_));
392 // The mov instruction above can be either 1 to 3 (for ARMv7) or 1 to 5
393 // instructions (for ARMv6) depending upon whether it is an extended constant
394 // pool - insert nop to compensate.
395 int expected_instr_count =
396 (kProfileCounterResetSequenceLength / Assembler::kInstrSize) - 2;
397 DCHECK(masm_->InstructionsGeneratedSince(&start) <= expected_instr_count);
398 while (masm_->InstructionsGeneratedSince(&start) != expected_instr_count) {
401 __ mov(r3, Operand(Smi::FromInt(reset_value)));
402 __ str(r3, FieldMemOperand(r2, Cell::kValueOffset));
406 void FullCodeGenerator::EmitBackEdgeBookkeeping(IterationStatement* stmt,
407 Label* back_edge_target) {
408 Comment cmnt(masm_, "[ Back edge bookkeeping");
409 // Block literal pools whilst emitting back edge code.
410 Assembler::BlockConstPoolScope block_const_pool(masm_);
413 DCHECK(back_edge_target->is_bound());
414 int distance = masm_->SizeOfCodeGeneratedSince(back_edge_target);
415 int weight = Min(kMaxBackEdgeWeight,
416 Max(1, distance / kCodeSizeMultiplier));
417 EmitProfilingCounterDecrement(weight);
419 __ Call(isolate()->builtins()->InterruptCheck(), RelocInfo::CODE_TARGET);
421 // Record a mapping of this PC offset to the OSR id. This is used to find
422 // the AST id from the unoptimized code in order to use it as a key into
423 // the deoptimization input data found in the optimized code.
424 RecordBackEdge(stmt->OsrEntryId());
426 EmitProfilingCounterReset();
429 PrepareForBailoutForId(stmt->EntryId(), NO_REGISTERS);
430 // Record a mapping of the OSR id to this PC. This is used if the OSR
431 // entry becomes the target of a bailout. We don't expect it to be, but
432 // we want it to work if it is.
433 PrepareForBailoutForId(stmt->OsrEntryId(), NO_REGISTERS);
437 void FullCodeGenerator::EmitReturnSequence() {
438 Comment cmnt(masm_, "[ Return sequence");
439 if (return_label_.is_bound()) {
440 __ b(&return_label_);
442 __ bind(&return_label_);
444 // Push the return value on the stack as the parameter.
445 // Runtime::TraceExit returns its parameter in r0.
447 __ CallRuntime(Runtime::kTraceExit, 1);
449 // Pretend that the exit is a backwards jump to the entry.
451 if (info_->ShouldSelfOptimize()) {
452 weight = FLAG_interrupt_budget / FLAG_self_opt_count;
454 int distance = masm_->pc_offset();
455 weight = Min(kMaxBackEdgeWeight,
456 Max(1, distance / kCodeSizeMultiplier));
458 EmitProfilingCounterDecrement(weight);
462 __ Call(isolate()->builtins()->InterruptCheck(),
463 RelocInfo::CODE_TARGET);
465 EmitProfilingCounterReset();
469 // Add a label for checking the size of the code used for returning.
470 Label check_exit_codesize;
471 __ bind(&check_exit_codesize);
473 // Make sure that the constant pool is not emitted inside of the return
475 { Assembler::BlockConstPoolScope block_const_pool(masm_);
476 int32_t arg_count = info_->scope()->num_parameters() + 1;
477 if (IsSubclassConstructor(info_->function()->kind())) {
480 int32_t sp_delta = arg_count * kPointerSize;
481 CodeGenerator::RecordPositions(masm_, function()->end_position() - 1);
482 // TODO(svenpanne) The code below is sometimes 4 words, sometimes 5!
483 PredictableCodeSizeScope predictable(masm_, -1);
485 int no_frame_start = __ LeaveFrame(StackFrame::JAVA_SCRIPT);
486 { ConstantPoolUnavailableScope constant_pool_unavailable(masm_);
487 __ add(sp, sp, Operand(sp_delta));
489 info_->AddNoFrameRange(no_frame_start, masm_->pc_offset());
494 // Check that the size of the code used for returning is large enough
495 // for the debugger's requirements.
496 DCHECK(Assembler::kJSReturnSequenceInstructions <=
497 masm_->InstructionsGeneratedSince(&check_exit_codesize));
503 void FullCodeGenerator::EffectContext::Plug(Variable* var) const {
504 DCHECK(var->IsStackAllocated() || var->IsContextSlot());
508 void FullCodeGenerator::AccumulatorValueContext::Plug(Variable* var) const {
509 DCHECK(var->IsStackAllocated() || var->IsContextSlot());
510 codegen()->GetVar(result_register(), var);
514 void FullCodeGenerator::StackValueContext::Plug(Variable* var) const {
515 DCHECK(var->IsStackAllocated() || var->IsContextSlot());
516 codegen()->GetVar(result_register(), var);
517 __ push(result_register());
521 void FullCodeGenerator::TestContext::Plug(Variable* var) const {
522 DCHECK(var->IsStackAllocated() || var->IsContextSlot());
523 // For simplicity we always test the accumulator register.
524 codegen()->GetVar(result_register(), var);
525 codegen()->PrepareForBailoutBeforeSplit(condition(), false, NULL, NULL);
526 codegen()->DoTest(this);
530 void FullCodeGenerator::EffectContext::Plug(Heap::RootListIndex index) const {
534 void FullCodeGenerator::AccumulatorValueContext::Plug(
535 Heap::RootListIndex index) const {
536 __ LoadRoot(result_register(), index);
540 void FullCodeGenerator::StackValueContext::Plug(
541 Heap::RootListIndex index) const {
542 __ LoadRoot(result_register(), index);
543 __ push(result_register());
547 void FullCodeGenerator::TestContext::Plug(Heap::RootListIndex index) const {
548 codegen()->PrepareForBailoutBeforeSplit(condition(),
552 if (index == Heap::kUndefinedValueRootIndex ||
553 index == Heap::kNullValueRootIndex ||
554 index == Heap::kFalseValueRootIndex) {
555 if (false_label_ != fall_through_) __ b(false_label_);
556 } else if (index == Heap::kTrueValueRootIndex) {
557 if (true_label_ != fall_through_) __ b(true_label_);
559 __ LoadRoot(result_register(), index);
560 codegen()->DoTest(this);
565 void FullCodeGenerator::EffectContext::Plug(Handle<Object> lit) const {
569 void FullCodeGenerator::AccumulatorValueContext::Plug(
570 Handle<Object> lit) const {
571 __ mov(result_register(), Operand(lit));
575 void FullCodeGenerator::StackValueContext::Plug(Handle<Object> lit) const {
576 // Immediates cannot be pushed directly.
577 __ mov(result_register(), Operand(lit));
578 __ push(result_register());
582 void FullCodeGenerator::TestContext::Plug(Handle<Object> lit) const {
583 codegen()->PrepareForBailoutBeforeSplit(condition(),
587 DCHECK(!lit->IsUndetectableObject()); // There are no undetectable literals.
588 if (lit->IsUndefined() || lit->IsNull() || lit->IsFalse()) {
589 if (false_label_ != fall_through_) __ b(false_label_);
590 } else if (lit->IsTrue() || lit->IsJSObject()) {
591 if (true_label_ != fall_through_) __ b(true_label_);
592 } else if (lit->IsString()) {
593 if (String::cast(*lit)->length() == 0) {
594 if (false_label_ != fall_through_) __ b(false_label_);
596 if (true_label_ != fall_through_) __ b(true_label_);
598 } else if (lit->IsSmi()) {
599 if (Smi::cast(*lit)->value() == 0) {
600 if (false_label_ != fall_through_) __ b(false_label_);
602 if (true_label_ != fall_through_) __ b(true_label_);
605 // For simplicity we always test the accumulator register.
606 __ mov(result_register(), Operand(lit));
607 codegen()->DoTest(this);
612 void FullCodeGenerator::EffectContext::DropAndPlug(int count,
613 Register reg) const {
619 void FullCodeGenerator::AccumulatorValueContext::DropAndPlug(
621 Register reg) const {
624 __ Move(result_register(), reg);
628 void FullCodeGenerator::StackValueContext::DropAndPlug(int count,
629 Register reg) const {
631 if (count > 1) __ Drop(count - 1);
632 __ str(reg, MemOperand(sp, 0));
636 void FullCodeGenerator::TestContext::DropAndPlug(int count,
637 Register reg) const {
639 // For simplicity we always test the accumulator register.
641 __ Move(result_register(), reg);
642 codegen()->PrepareForBailoutBeforeSplit(condition(), false, NULL, NULL);
643 codegen()->DoTest(this);
647 void FullCodeGenerator::EffectContext::Plug(Label* materialize_true,
648 Label* materialize_false) const {
649 DCHECK(materialize_true == materialize_false);
650 __ bind(materialize_true);
654 void FullCodeGenerator::AccumulatorValueContext::Plug(
655 Label* materialize_true,
656 Label* materialize_false) const {
658 __ bind(materialize_true);
659 __ LoadRoot(result_register(), Heap::kTrueValueRootIndex);
661 __ bind(materialize_false);
662 __ LoadRoot(result_register(), Heap::kFalseValueRootIndex);
667 void FullCodeGenerator::StackValueContext::Plug(
668 Label* materialize_true,
669 Label* materialize_false) const {
671 __ bind(materialize_true);
672 __ LoadRoot(ip, Heap::kTrueValueRootIndex);
674 __ bind(materialize_false);
675 __ LoadRoot(ip, Heap::kFalseValueRootIndex);
681 void FullCodeGenerator::TestContext::Plug(Label* materialize_true,
682 Label* materialize_false) const {
683 DCHECK(materialize_true == true_label_);
684 DCHECK(materialize_false == false_label_);
688 void FullCodeGenerator::EffectContext::Plug(bool flag) const {
692 void FullCodeGenerator::AccumulatorValueContext::Plug(bool flag) const {
693 Heap::RootListIndex value_root_index =
694 flag ? Heap::kTrueValueRootIndex : Heap::kFalseValueRootIndex;
695 __ LoadRoot(result_register(), value_root_index);
699 void FullCodeGenerator::StackValueContext::Plug(bool flag) const {
700 Heap::RootListIndex value_root_index =
701 flag ? Heap::kTrueValueRootIndex : Heap::kFalseValueRootIndex;
702 __ LoadRoot(ip, value_root_index);
707 void FullCodeGenerator::TestContext::Plug(bool flag) const {
708 codegen()->PrepareForBailoutBeforeSplit(condition(),
713 if (true_label_ != fall_through_) __ b(true_label_);
715 if (false_label_ != fall_through_) __ b(false_label_);
720 void FullCodeGenerator::DoTest(Expression* condition,
723 Label* fall_through) {
724 Handle<Code> ic = ToBooleanStub::GetUninitialized(isolate());
725 CallIC(ic, condition->test_id());
726 __ tst(result_register(), result_register());
727 Split(ne, if_true, if_false, fall_through);
731 void FullCodeGenerator::Split(Condition cond,
734 Label* fall_through) {
735 if (if_false == fall_through) {
737 } else if (if_true == fall_through) {
738 __ b(NegateCondition(cond), if_false);
746 MemOperand FullCodeGenerator::StackOperand(Variable* var) {
747 DCHECK(var->IsStackAllocated());
748 // Offset is negative because higher indexes are at lower addresses.
749 int offset = -var->index() * kPointerSize;
750 // Adjust by a (parameter or local) base offset.
751 if (var->IsParameter()) {
752 offset += (info_->scope()->num_parameters() + 1) * kPointerSize;
754 offset += JavaScriptFrameConstants::kLocal0Offset;
756 return MemOperand(fp, offset);
760 MemOperand FullCodeGenerator::VarOperand(Variable* var, Register scratch) {
761 DCHECK(var->IsContextSlot() || var->IsStackAllocated());
762 if (var->IsContextSlot()) {
763 int context_chain_length = scope()->ContextChainLength(var->scope());
764 __ LoadContext(scratch, context_chain_length);
765 return ContextOperand(scratch, var->index());
767 return StackOperand(var);
772 void FullCodeGenerator::GetVar(Register dest, Variable* var) {
773 // Use destination as scratch.
774 MemOperand location = VarOperand(var, dest);
775 __ ldr(dest, location);
779 void FullCodeGenerator::SetVar(Variable* var,
783 DCHECK(var->IsContextSlot() || var->IsStackAllocated());
784 DCHECK(!scratch0.is(src));
785 DCHECK(!scratch0.is(scratch1));
786 DCHECK(!scratch1.is(src));
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 __ RecordWriteContextSlot(scratch0,
802 void FullCodeGenerator::PrepareForBailoutBeforeSplit(Expression* expr,
803 bool should_normalize,
806 // Only prepare for bailouts before splits if we're in a test
807 // context. Otherwise, we let the Visit function deal with the
808 // preparation to avoid preparing with the same AST id twice.
809 if (!context()->IsTest() || !info_->IsOptimizable()) return;
812 if (should_normalize) __ b(&skip);
813 PrepareForBailout(expr, TOS_REG);
814 if (should_normalize) {
815 __ LoadRoot(ip, Heap::kTrueValueRootIndex);
817 Split(eq, if_true, if_false, NULL);
823 void FullCodeGenerator::EmitDebugCheckDeclarationContext(Variable* variable) {
824 // The variable in the declaration always resides in the current function
826 DCHECK_EQ(0, scope()->ContextChainLength(variable->scope()));
827 if (generate_debug_code_) {
828 // Check that we're not inside a with or catch context.
829 __ ldr(r1, FieldMemOperand(cp, HeapObject::kMapOffset));
830 __ CompareRoot(r1, Heap::kWithContextMapRootIndex);
831 __ Check(ne, kDeclarationInWithContext);
832 __ CompareRoot(r1, Heap::kCatchContextMapRootIndex);
833 __ Check(ne, kDeclarationInCatchContext);
838 void FullCodeGenerator::VisitVariableDeclaration(
839 VariableDeclaration* declaration) {
840 // If it was not possible to allocate the variable at compile time, we
841 // need to "declare" it at runtime to make sure it actually exists in the
843 VariableProxy* proxy = declaration->proxy();
844 VariableMode mode = declaration->mode();
845 Variable* variable = proxy->var();
846 bool hole_init = mode == LET || mode == CONST || mode == CONST_LEGACY;
847 switch (variable->location()) {
848 case Variable::UNALLOCATED:
849 globals_->Add(variable->name(), zone());
850 globals_->Add(variable->binding_needs_init()
851 ? isolate()->factory()->the_hole_value()
852 : isolate()->factory()->undefined_value(),
856 case Variable::PARAMETER:
857 case Variable::LOCAL:
859 Comment cmnt(masm_, "[ VariableDeclaration");
860 __ LoadRoot(ip, Heap::kTheHoleValueRootIndex);
861 __ str(ip, StackOperand(variable));
865 case Variable::CONTEXT:
867 Comment cmnt(masm_, "[ VariableDeclaration");
868 EmitDebugCheckDeclarationContext(variable);
869 __ LoadRoot(ip, Heap::kTheHoleValueRootIndex);
870 __ str(ip, ContextOperand(cp, variable->index()));
871 // No write barrier since the_hole_value is in old space.
872 PrepareForBailoutForId(proxy->id(), NO_REGISTERS);
876 case Variable::LOOKUP: {
877 Comment cmnt(masm_, "[ VariableDeclaration");
878 __ mov(r2, Operand(variable->name()));
879 // Declaration nodes are always introduced in one of four modes.
880 DCHECK(IsDeclaredVariableMode(mode));
881 PropertyAttributes attr =
882 IsImmutableVariableMode(mode) ? READ_ONLY : NONE;
883 __ mov(r1, Operand(Smi::FromInt(attr)));
884 // Push initial value, if any.
885 // Note: For variables we must not push an initial value (such as
886 // 'undefined') because we may have a (legal) redeclaration and we
887 // must not destroy the current value.
889 __ LoadRoot(r0, Heap::kTheHoleValueRootIndex);
890 __ Push(cp, r2, r1, r0);
892 __ mov(r0, Operand(Smi::FromInt(0))); // Indicates no initial value.
893 __ Push(cp, r2, r1, r0);
895 __ CallRuntime(Runtime::kDeclareLookupSlot, 4);
902 void FullCodeGenerator::VisitFunctionDeclaration(
903 FunctionDeclaration* declaration) {
904 VariableProxy* proxy = declaration->proxy();
905 Variable* variable = proxy->var();
906 switch (variable->location()) {
907 case Variable::UNALLOCATED: {
908 globals_->Add(variable->name(), zone());
909 Handle<SharedFunctionInfo> function =
910 Compiler::BuildFunctionInfo(declaration->fun(), script(), info_);
911 // Check for stack-overflow exception.
912 if (function.is_null()) return SetStackOverflow();
913 globals_->Add(function, zone());
917 case Variable::PARAMETER:
918 case Variable::LOCAL: {
919 Comment cmnt(masm_, "[ FunctionDeclaration");
920 VisitForAccumulatorValue(declaration->fun());
921 __ str(result_register(), StackOperand(variable));
925 case Variable::CONTEXT: {
926 Comment cmnt(masm_, "[ FunctionDeclaration");
927 EmitDebugCheckDeclarationContext(variable);
928 VisitForAccumulatorValue(declaration->fun());
929 __ str(result_register(), ContextOperand(cp, variable->index()));
930 int offset = Context::SlotOffset(variable->index());
931 // We know that we have written a function, which is not a smi.
932 __ RecordWriteContextSlot(cp,
940 PrepareForBailoutForId(proxy->id(), NO_REGISTERS);
944 case Variable::LOOKUP: {
945 Comment cmnt(masm_, "[ FunctionDeclaration");
946 __ mov(r2, Operand(variable->name()));
947 __ mov(r1, Operand(Smi::FromInt(NONE)));
949 // Push initial value for function declaration.
950 VisitForStackValue(declaration->fun());
951 __ CallRuntime(Runtime::kDeclareLookupSlot, 4);
958 void FullCodeGenerator::VisitModuleDeclaration(ModuleDeclaration* declaration) {
959 Variable* variable = declaration->proxy()->var();
960 ModuleDescriptor* descriptor = declaration->module()->descriptor();
961 DCHECK(variable->location() == Variable::CONTEXT);
962 DCHECK(descriptor->IsFrozen());
964 Comment cmnt(masm_, "[ ModuleDeclaration");
965 EmitDebugCheckDeclarationContext(variable);
967 // Load instance object.
968 __ LoadContext(r1, scope_->ContextChainLength(scope_->ScriptScope()));
969 __ ldr(r1, ContextOperand(r1, descriptor->Index()));
970 __ ldr(r1, ContextOperand(r1, Context::EXTENSION_INDEX));
973 __ str(r1, ContextOperand(cp, variable->index()));
974 // We know that we have written a module, which is not a smi.
975 __ RecordWriteContextSlot(cp,
976 Context::SlotOffset(variable->index()),
983 PrepareForBailoutForId(declaration->proxy()->id(), NO_REGISTERS);
985 // Traverse into body.
986 Visit(declaration->module());
990 void FullCodeGenerator::VisitImportDeclaration(ImportDeclaration* declaration) {
991 VariableProxy* proxy = declaration->proxy();
992 Variable* variable = proxy->var();
993 switch (variable->location()) {
994 case Variable::UNALLOCATED:
998 case Variable::CONTEXT: {
999 Comment cmnt(masm_, "[ ImportDeclaration");
1000 EmitDebugCheckDeclarationContext(variable);
1005 case Variable::PARAMETER:
1006 case Variable::LOCAL:
1007 case Variable::LOOKUP:
1013 void FullCodeGenerator::VisitExportDeclaration(ExportDeclaration* declaration) {
1018 void FullCodeGenerator::DeclareGlobals(Handle<FixedArray> pairs) {
1019 // Call the runtime to declare the globals.
1020 // The context is the first argument.
1021 __ mov(r1, Operand(pairs));
1022 __ mov(r0, Operand(Smi::FromInt(DeclareGlobalsFlags())));
1023 __ Push(cp, r1, r0);
1024 __ CallRuntime(Runtime::kDeclareGlobals, 3);
1025 // Return value is ignored.
1029 void FullCodeGenerator::DeclareModules(Handle<FixedArray> descriptions) {
1030 // Call the runtime to declare the modules.
1031 __ Push(descriptions);
1032 __ CallRuntime(Runtime::kDeclareModules, 1);
1033 // Return value is ignored.
1037 void FullCodeGenerator::VisitSwitchStatement(SwitchStatement* stmt) {
1038 Comment cmnt(masm_, "[ SwitchStatement");
1039 Breakable nested_statement(this, stmt);
1040 SetStatementPosition(stmt);
1042 // Keep the switch value on the stack until a case matches.
1043 VisitForStackValue(stmt->tag());
1044 PrepareForBailoutForId(stmt->EntryId(), NO_REGISTERS);
1046 ZoneList<CaseClause*>* clauses = stmt->cases();
1047 CaseClause* default_clause = NULL; // Can occur anywhere in the list.
1049 Label next_test; // Recycled for each test.
1050 // Compile all the tests with branches to their bodies.
1051 for (int i = 0; i < clauses->length(); i++) {
1052 CaseClause* clause = clauses->at(i);
1053 clause->body_target()->Unuse();
1055 // The default is not a test, but remember it as final fall through.
1056 if (clause->is_default()) {
1057 default_clause = clause;
1061 Comment cmnt(masm_, "[ Case comparison");
1062 __ bind(&next_test);
1065 // Compile the label expression.
1066 VisitForAccumulatorValue(clause->label());
1068 // Perform the comparison as if via '==='.
1069 __ ldr(r1, MemOperand(sp, 0)); // Switch value.
1070 bool inline_smi_code = ShouldInlineSmiCase(Token::EQ_STRICT);
1071 JumpPatchSite patch_site(masm_);
1072 if (inline_smi_code) {
1075 patch_site.EmitJumpIfNotSmi(r2, &slow_case);
1078 __ b(ne, &next_test);
1079 __ Drop(1); // Switch value is no longer needed.
1080 __ b(clause->body_target());
1081 __ bind(&slow_case);
1084 // Record position before stub call for type feedback.
1085 SetSourcePosition(clause->position());
1087 CodeFactory::CompareIC(isolate(), Token::EQ_STRICT).code();
1088 CallIC(ic, clause->CompareId());
1089 patch_site.EmitPatchInfo();
1093 PrepareForBailout(clause, TOS_REG);
1094 __ LoadRoot(ip, Heap::kTrueValueRootIndex);
1096 __ b(ne, &next_test);
1098 __ jmp(clause->body_target());
1101 __ cmp(r0, Operand::Zero());
1102 __ b(ne, &next_test);
1103 __ Drop(1); // Switch value is no longer needed.
1104 __ b(clause->body_target());
1107 // Discard the test value and jump to the default if present, otherwise to
1108 // the end of the statement.
1109 __ bind(&next_test);
1110 __ Drop(1); // Switch value is no longer needed.
1111 if (default_clause == NULL) {
1112 __ b(nested_statement.break_label());
1114 __ b(default_clause->body_target());
1117 // Compile all the case bodies.
1118 for (int i = 0; i < clauses->length(); i++) {
1119 Comment cmnt(masm_, "[ Case body");
1120 CaseClause* clause = clauses->at(i);
1121 __ bind(clause->body_target());
1122 PrepareForBailoutForId(clause->EntryId(), NO_REGISTERS);
1123 VisitStatements(clause->statements());
1126 __ bind(nested_statement.break_label());
1127 PrepareForBailoutForId(stmt->ExitId(), NO_REGISTERS);
1131 void FullCodeGenerator::VisitForInStatement(ForInStatement* stmt) {
1132 Comment cmnt(masm_, "[ ForInStatement");
1133 FeedbackVectorSlot slot = stmt->ForInFeedbackSlot();
1134 SetStatementPosition(stmt);
1137 ForIn loop_statement(this, stmt);
1138 increment_loop_depth();
1140 // Get the object to enumerate over. If the object is null or undefined, skip
1141 // over the loop. See ECMA-262 version 5, section 12.6.4.
1142 SetExpressionPosition(stmt->enumerable());
1143 VisitForAccumulatorValue(stmt->enumerable());
1144 __ LoadRoot(ip, Heap::kUndefinedValueRootIndex);
1147 Register null_value = r5;
1148 __ LoadRoot(null_value, Heap::kNullValueRootIndex);
1149 __ cmp(r0, null_value);
1152 PrepareForBailoutForId(stmt->PrepareId(), TOS_REG);
1154 // Convert the object to a JS object.
1155 Label convert, done_convert;
1156 __ JumpIfSmi(r0, &convert);
1157 __ CompareObjectType(r0, r1, r1, FIRST_SPEC_OBJECT_TYPE);
1158 __ b(ge, &done_convert);
1161 __ InvokeBuiltin(Builtins::TO_OBJECT, CALL_FUNCTION);
1162 __ bind(&done_convert);
1163 PrepareForBailoutForId(stmt->ToObjectId(), TOS_REG);
1166 // Check for proxies.
1168 STATIC_ASSERT(FIRST_JS_PROXY_TYPE == FIRST_SPEC_OBJECT_TYPE);
1169 __ CompareObjectType(r0, r1, r1, LAST_JS_PROXY_TYPE);
1170 __ b(le, &call_runtime);
1172 // Check cache validity in generated code. This is a fast case for
1173 // the JSObject::IsSimpleEnum cache validity checks. If we cannot
1174 // guarantee cache validity, call the runtime system to check cache
1175 // validity or get the property names in a fixed array.
1176 __ CheckEnumCache(null_value, &call_runtime);
1178 // The enum cache is valid. Load the map of the object being
1179 // iterated over and use the cache for the iteration.
1181 __ ldr(r0, FieldMemOperand(r0, HeapObject::kMapOffset));
1184 // Get the set of properties to enumerate.
1185 __ bind(&call_runtime);
1186 __ push(r0); // Duplicate the enumerable object on the stack.
1187 __ CallRuntime(Runtime::kGetPropertyNamesFast, 1);
1188 PrepareForBailoutForId(stmt->EnumId(), TOS_REG);
1190 // If we got a map from the runtime call, we can do a fast
1191 // modification check. Otherwise, we got a fixed array, and we have
1192 // to do a slow check.
1194 __ ldr(r2, FieldMemOperand(r0, HeapObject::kMapOffset));
1195 __ LoadRoot(ip, Heap::kMetaMapRootIndex);
1197 __ b(ne, &fixed_array);
1199 // We got a map in register r0. Get the enumeration cache from it.
1200 Label no_descriptors;
1201 __ bind(&use_cache);
1203 __ EnumLength(r1, r0);
1204 __ cmp(r1, Operand(Smi::FromInt(0)));
1205 __ b(eq, &no_descriptors);
1207 __ LoadInstanceDescriptors(r0, r2);
1208 __ ldr(r2, FieldMemOperand(r2, DescriptorArray::kEnumCacheOffset));
1209 __ ldr(r2, FieldMemOperand(r2, DescriptorArray::kEnumCacheBridgeCacheOffset));
1211 // Set up the four remaining stack slots.
1212 __ push(r0); // Map.
1213 __ mov(r0, Operand(Smi::FromInt(0)));
1214 // Push enumeration cache, enumeration cache length (as smi) and zero.
1215 __ Push(r2, r1, r0);
1218 __ bind(&no_descriptors);
1222 // We got a fixed array in register r0. Iterate through that.
1224 __ bind(&fixed_array);
1226 __ Move(r1, FeedbackVector());
1227 __ mov(r2, Operand(TypeFeedbackVector::MegamorphicSentinel(isolate())));
1228 int vector_index = FeedbackVector()->GetIndex(slot);
1229 __ str(r2, FieldMemOperand(r1, FixedArray::OffsetOfElementAt(vector_index)));
1231 __ mov(r1, Operand(Smi::FromInt(1))); // Smi indicates slow check
1232 __ ldr(r2, MemOperand(sp, 0 * kPointerSize)); // Get enumerated object
1233 STATIC_ASSERT(FIRST_JS_PROXY_TYPE == FIRST_SPEC_OBJECT_TYPE);
1234 __ CompareObjectType(r2, r3, r3, LAST_JS_PROXY_TYPE);
1235 __ b(gt, &non_proxy);
1236 __ mov(r1, Operand(Smi::FromInt(0))); // Zero indicates proxy
1237 __ bind(&non_proxy);
1238 __ Push(r1, r0); // Smi and array
1239 __ ldr(r1, FieldMemOperand(r0, FixedArray::kLengthOffset));
1240 __ mov(r0, Operand(Smi::FromInt(0)));
1241 __ Push(r1, r0); // Fixed array length (as smi) and initial index.
1243 // Generate code for doing the condition check.
1244 PrepareForBailoutForId(stmt->BodyId(), NO_REGISTERS);
1246 SetExpressionPosition(stmt->each());
1248 // Load the current count to r0, load the length to r1.
1249 __ Ldrd(r0, r1, MemOperand(sp, 0 * kPointerSize));
1250 __ cmp(r0, r1); // Compare to the array length.
1251 __ b(hs, loop_statement.break_label());
1253 // Get the current entry of the array into register r3.
1254 __ ldr(r2, MemOperand(sp, 2 * kPointerSize));
1255 __ add(r2, r2, Operand(FixedArray::kHeaderSize - kHeapObjectTag));
1256 __ ldr(r3, MemOperand::PointerAddressFromSmiKey(r2, r0));
1258 // Get the expected map from the stack or a smi in the
1259 // permanent slow case into register r2.
1260 __ ldr(r2, MemOperand(sp, 3 * kPointerSize));
1262 // Check if the expected map still matches that of the enumerable.
1263 // If not, we may have to filter the key.
1265 __ ldr(r1, MemOperand(sp, 4 * kPointerSize));
1266 __ ldr(r4, FieldMemOperand(r1, HeapObject::kMapOffset));
1267 __ cmp(r4, Operand(r2));
1268 __ b(eq, &update_each);
1270 // For proxies, no filtering is done.
1271 // TODO(rossberg): What if only a prototype is a proxy? Not specified yet.
1272 __ cmp(r2, Operand(Smi::FromInt(0)));
1273 __ b(eq, &update_each);
1275 // Convert the entry to a string or (smi) 0 if it isn't a property
1276 // any more. If the property has been removed while iterating, we
1278 __ push(r1); // Enumerable.
1279 __ push(r3); // Current entry.
1280 __ InvokeBuiltin(Builtins::FILTER_KEY, CALL_FUNCTION);
1281 __ mov(r3, Operand(r0), SetCC);
1282 __ b(eq, loop_statement.continue_label());
1284 // Update the 'each' property or variable from the possibly filtered
1285 // entry in register r3.
1286 __ bind(&update_each);
1287 __ mov(result_register(), r3);
1288 // Perform the assignment as if via '='.
1289 { EffectContext context(this);
1290 EmitAssignment(stmt->each());
1291 PrepareForBailoutForId(stmt->AssignmentId(), NO_REGISTERS);
1294 // Generate code for the body of the loop.
1295 Visit(stmt->body());
1297 // Generate code for the going to the next element by incrementing
1298 // the index (smi) stored on top of the stack.
1299 __ bind(loop_statement.continue_label());
1301 __ add(r0, r0, Operand(Smi::FromInt(1)));
1304 EmitBackEdgeBookkeeping(stmt, &loop);
1307 // Remove the pointers stored on the stack.
1308 __ bind(loop_statement.break_label());
1311 // Exit and decrement the loop depth.
1312 PrepareForBailoutForId(stmt->ExitId(), NO_REGISTERS);
1314 decrement_loop_depth();
1318 void FullCodeGenerator::EmitNewClosure(Handle<SharedFunctionInfo> info,
1320 // Use the fast case closure allocation code that allocates in new
1321 // space for nested functions that don't need literals cloning. If
1322 // we're running with the --always-opt or the --prepare-always-opt
1323 // flag, we need to use the runtime function so that the new function
1324 // we are creating here gets a chance to have its code optimized and
1325 // doesn't just get a copy of the existing unoptimized code.
1326 if (!FLAG_always_opt &&
1327 !FLAG_prepare_always_opt &&
1329 scope()->is_function_scope() &&
1330 info->num_literals() == 0) {
1331 FastNewClosureStub stub(isolate(), info->language_mode(), info->kind());
1332 __ mov(r2, Operand(info));
1335 __ mov(r0, Operand(info));
1336 __ LoadRoot(r1, pretenure ? Heap::kTrueValueRootIndex
1337 : Heap::kFalseValueRootIndex);
1338 __ Push(cp, r0, r1);
1339 __ CallRuntime(Runtime::kNewClosure, 3);
1341 context()->Plug(r0);
1345 void FullCodeGenerator::VisitVariableProxy(VariableProxy* expr) {
1346 Comment cmnt(masm_, "[ VariableProxy");
1347 EmitVariableLoad(expr);
1351 void FullCodeGenerator::EmitLoadHomeObject(SuperReference* expr) {
1352 Comment cnmt(masm_, "[ SuperReference ");
1354 __ ldr(LoadDescriptor::ReceiverRegister(),
1355 MemOperand(fp, JavaScriptFrameConstants::kFunctionOffset));
1357 Handle<Symbol> home_object_symbol(isolate()->heap()->home_object_symbol());
1358 __ Move(LoadDescriptor::NameRegister(), home_object_symbol);
1360 if (FLAG_vector_ics) {
1361 __ mov(VectorLoadICDescriptor::SlotRegister(),
1362 Operand(SmiFromSlot(expr->HomeObjectFeedbackSlot())));
1363 CallLoadIC(NOT_CONTEXTUAL);
1365 CallLoadIC(NOT_CONTEXTUAL, expr->HomeObjectFeedbackId());
1368 __ cmp(r0, Operand(isolate()->factory()->undefined_value()));
1371 __ CallRuntime(Runtime::kThrowNonMethodError, 0);
1376 void FullCodeGenerator::EmitSetHomeObjectIfNeeded(Expression* initializer,
1378 if (NeedsHomeObject(initializer)) {
1379 __ ldr(StoreDescriptor::ReceiverRegister(), MemOperand(sp));
1380 __ mov(StoreDescriptor::NameRegister(),
1381 Operand(isolate()->factory()->home_object_symbol()));
1382 __ ldr(StoreDescriptor::ValueRegister(),
1383 MemOperand(sp, offset * kPointerSize));
1389 void FullCodeGenerator::EmitLoadGlobalCheckExtensions(VariableProxy* proxy,
1390 TypeofState typeof_state,
1392 Register current = cp;
1398 if (s->num_heap_slots() > 0) {
1399 if (s->calls_sloppy_eval()) {
1400 // Check that extension is NULL.
1401 __ ldr(temp, ContextOperand(current, Context::EXTENSION_INDEX));
1405 // Load next context in chain.
1406 __ ldr(next, ContextOperand(current, Context::PREVIOUS_INDEX));
1407 // Walk the rest of the chain without clobbering cp.
1410 // If no outer scope calls eval, we do not need to check more
1411 // context extensions.
1412 if (!s->outer_scope_calls_sloppy_eval() || s->is_eval_scope()) break;
1413 s = s->outer_scope();
1416 if (s->is_eval_scope()) {
1418 if (!current.is(next)) {
1419 __ Move(next, current);
1422 // Terminate at native context.
1423 __ ldr(temp, FieldMemOperand(next, HeapObject::kMapOffset));
1424 __ LoadRoot(ip, Heap::kNativeContextMapRootIndex);
1427 // Check that extension is NULL.
1428 __ ldr(temp, ContextOperand(next, Context::EXTENSION_INDEX));
1431 // Load next context in chain.
1432 __ ldr(next, ContextOperand(next, Context::PREVIOUS_INDEX));
1437 __ ldr(LoadDescriptor::ReceiverRegister(), GlobalObjectOperand());
1438 __ mov(LoadDescriptor::NameRegister(), Operand(proxy->var()->name()));
1439 if (FLAG_vector_ics) {
1440 __ mov(VectorLoadICDescriptor::SlotRegister(),
1441 Operand(SmiFromSlot(proxy->VariableFeedbackSlot())));
1444 ContextualMode mode = (typeof_state == INSIDE_TYPEOF)
1451 MemOperand FullCodeGenerator::ContextSlotOperandCheckExtensions(Variable* var,
1453 DCHECK(var->IsContextSlot());
1454 Register context = cp;
1458 for (Scope* s = scope(); s != var->scope(); s = s->outer_scope()) {
1459 if (s->num_heap_slots() > 0) {
1460 if (s->calls_sloppy_eval()) {
1461 // Check that extension is NULL.
1462 __ ldr(temp, ContextOperand(context, Context::EXTENSION_INDEX));
1466 __ ldr(next, ContextOperand(context, Context::PREVIOUS_INDEX));
1467 // Walk the rest of the chain without clobbering cp.
1471 // Check that last extension is NULL.
1472 __ ldr(temp, ContextOperand(context, Context::EXTENSION_INDEX));
1476 // This function is used only for loads, not stores, so it's safe to
1477 // return an cp-based operand (the write barrier cannot be allowed to
1478 // destroy the cp register).
1479 return ContextOperand(context, var->index());
1483 void FullCodeGenerator::EmitDynamicLookupFastCase(VariableProxy* proxy,
1484 TypeofState typeof_state,
1487 // Generate fast-case code for variables that might be shadowed by
1488 // eval-introduced variables. Eval is used a lot without
1489 // introducing variables. In those cases, we do not want to
1490 // perform a runtime call for all variables in the scope
1491 // containing the eval.
1492 Variable* var = proxy->var();
1493 if (var->mode() == DYNAMIC_GLOBAL) {
1494 EmitLoadGlobalCheckExtensions(proxy, typeof_state, slow);
1496 } else if (var->mode() == DYNAMIC_LOCAL) {
1497 Variable* local = var->local_if_not_shadowed();
1498 __ ldr(r0, ContextSlotOperandCheckExtensions(local, slow));
1499 if (local->mode() == LET || local->mode() == CONST ||
1500 local->mode() == CONST_LEGACY) {
1501 __ CompareRoot(r0, Heap::kTheHoleValueRootIndex);
1502 if (local->mode() == CONST_LEGACY) {
1503 __ LoadRoot(r0, Heap::kUndefinedValueRootIndex, eq);
1504 } else { // LET || CONST
1506 __ mov(r0, Operand(var->name()));
1508 __ CallRuntime(Runtime::kThrowReferenceError, 1);
1516 void FullCodeGenerator::EmitVariableLoad(VariableProxy* proxy) {
1517 // Record position before possible IC call.
1518 SetSourcePosition(proxy->position());
1519 Variable* var = proxy->var();
1521 // Three cases: global variables, lookup variables, and all other types of
1523 switch (var->location()) {
1524 case Variable::UNALLOCATED: {
1525 Comment cmnt(masm_, "[ Global variable");
1526 __ ldr(LoadDescriptor::ReceiverRegister(), GlobalObjectOperand());
1527 __ mov(LoadDescriptor::NameRegister(), Operand(var->name()));
1528 if (FLAG_vector_ics) {
1529 __ mov(VectorLoadICDescriptor::SlotRegister(),
1530 Operand(SmiFromSlot(proxy->VariableFeedbackSlot())));
1532 CallLoadIC(CONTEXTUAL);
1533 context()->Plug(r0);
1537 case Variable::PARAMETER:
1538 case Variable::LOCAL:
1539 case Variable::CONTEXT: {
1540 Comment cmnt(masm_, var->IsContextSlot() ? "[ Context variable"
1541 : "[ Stack variable");
1542 if (var->binding_needs_init()) {
1543 // var->scope() may be NULL when the proxy is located in eval code and
1544 // refers to a potential outside binding. Currently those bindings are
1545 // always looked up dynamically, i.e. in that case
1546 // var->location() == LOOKUP.
1548 DCHECK(var->scope() != NULL);
1550 // Check if the binding really needs an initialization check. The check
1551 // can be skipped in the following situation: we have a LET or CONST
1552 // binding in harmony mode, both the Variable and the VariableProxy have
1553 // the same declaration scope (i.e. they are both in global code, in the
1554 // same function or in the same eval code) and the VariableProxy is in
1555 // the source physically located after the initializer of the variable.
1557 // We cannot skip any initialization checks for CONST in non-harmony
1558 // mode because const variables may be declared but never initialized:
1559 // if (false) { const x; }; var y = x;
1561 // The condition on the declaration scopes is a conservative check for
1562 // nested functions that access a binding and are called before the
1563 // binding is initialized:
1564 // function() { f(); let x = 1; function f() { x = 2; } }
1566 bool skip_init_check;
1567 if (var->scope()->DeclarationScope() != scope()->DeclarationScope()) {
1568 skip_init_check = false;
1569 } else if (var->is_this()) {
1570 CHECK(info_->function() != nullptr &&
1571 (info_->function()->kind() & kSubclassConstructor) != 0);
1572 // TODO(dslomov): implement 'this' hole check elimination.
1573 skip_init_check = false;
1575 // Check that we always have valid source position.
1576 DCHECK(var->initializer_position() != RelocInfo::kNoPosition);
1577 DCHECK(proxy->position() != RelocInfo::kNoPosition);
1578 skip_init_check = var->mode() != CONST_LEGACY &&
1579 var->initializer_position() < proxy->position();
1582 if (!skip_init_check) {
1583 // Let and const need a read barrier.
1585 __ CompareRoot(r0, Heap::kTheHoleValueRootIndex);
1586 if (var->mode() == LET || var->mode() == CONST) {
1587 // Throw a reference error when using an uninitialized let/const
1588 // binding in harmony mode.
1591 __ mov(r0, Operand(var->name()));
1593 __ CallRuntime(Runtime::kThrowReferenceError, 1);
1596 // Uninitalized const bindings outside of harmony mode are unholed.
1597 DCHECK(var->mode() == CONST_LEGACY);
1598 __ LoadRoot(r0, Heap::kUndefinedValueRootIndex, eq);
1600 context()->Plug(r0);
1604 context()->Plug(var);
1608 case Variable::LOOKUP: {
1609 Comment cmnt(masm_, "[ Lookup variable");
1611 // Generate code for loading from variables potentially shadowed
1612 // by eval-introduced variables.
1613 EmitDynamicLookupFastCase(proxy, NOT_INSIDE_TYPEOF, &slow, &done);
1615 __ mov(r1, Operand(var->name()));
1616 __ Push(cp, r1); // Context and name.
1617 __ CallRuntime(Runtime::kLoadLookupSlot, 2);
1619 context()->Plug(r0);
1625 void FullCodeGenerator::VisitRegExpLiteral(RegExpLiteral* expr) {
1626 Comment cmnt(masm_, "[ RegExpLiteral");
1628 // Registers will be used as follows:
1629 // r5 = materialized value (RegExp literal)
1630 // r4 = JS function, literals array
1631 // r3 = literal index
1632 // r2 = RegExp pattern
1633 // r1 = RegExp flags
1634 // r0 = RegExp literal clone
1635 __ ldr(r0, MemOperand(fp, JavaScriptFrameConstants::kFunctionOffset));
1636 __ ldr(r4, FieldMemOperand(r0, JSFunction::kLiteralsOffset));
1637 int literal_offset =
1638 FixedArray::kHeaderSize + expr->literal_index() * kPointerSize;
1639 __ ldr(r5, FieldMemOperand(r4, literal_offset));
1640 __ LoadRoot(ip, Heap::kUndefinedValueRootIndex);
1642 __ b(ne, &materialized);
1644 // Create regexp literal using runtime function.
1645 // Result will be in r0.
1646 __ mov(r3, Operand(Smi::FromInt(expr->literal_index())));
1647 __ mov(r2, Operand(expr->pattern()));
1648 __ mov(r1, Operand(expr->flags()));
1649 __ Push(r4, r3, r2, r1);
1650 __ CallRuntime(Runtime::kMaterializeRegExpLiteral, 4);
1653 __ bind(&materialized);
1654 int size = JSRegExp::kSize + JSRegExp::kInObjectFieldCount * kPointerSize;
1655 Label allocated, runtime_allocate;
1656 __ Allocate(size, r0, r2, r3, &runtime_allocate, TAG_OBJECT);
1659 __ bind(&runtime_allocate);
1660 __ mov(r0, Operand(Smi::FromInt(size)));
1662 __ CallRuntime(Runtime::kAllocateInNewSpace, 1);
1665 __ bind(&allocated);
1666 // After this, registers are used as follows:
1667 // r0: Newly allocated regexp.
1668 // r5: Materialized regexp.
1670 __ CopyFields(r0, r5, d0, size / kPointerSize);
1671 context()->Plug(r0);
1675 void FullCodeGenerator::EmitAccessor(Expression* expression) {
1676 if (expression == NULL) {
1677 __ LoadRoot(r1, Heap::kNullValueRootIndex);
1680 VisitForStackValue(expression);
1685 void FullCodeGenerator::VisitObjectLiteral(ObjectLiteral* expr) {
1686 Comment cmnt(masm_, "[ ObjectLiteral");
1688 expr->BuildConstantProperties(isolate());
1689 Handle<FixedArray> constant_properties = expr->constant_properties();
1690 __ ldr(r3, MemOperand(fp, JavaScriptFrameConstants::kFunctionOffset));
1691 __ ldr(r3, FieldMemOperand(r3, JSFunction::kLiteralsOffset));
1692 __ mov(r2, Operand(Smi::FromInt(expr->literal_index())));
1693 __ mov(r1, Operand(constant_properties));
1694 int flags = expr->ComputeFlags();
1695 __ mov(r0, Operand(Smi::FromInt(flags)));
1696 if (MustCreateObjectLiteralWithRuntime(expr)) {
1697 __ Push(r3, r2, r1, r0);
1698 __ CallRuntime(Runtime::kCreateObjectLiteral, 4);
1700 FastCloneShallowObjectStub stub(isolate(), expr->properties_count());
1703 PrepareForBailoutForId(expr->CreateLiteralId(), TOS_REG);
1705 // If result_saved is true the result is on top of the stack. If
1706 // result_saved is false the result is in r0.
1707 bool result_saved = false;
1709 // Mark all computed expressions that are bound to a key that
1710 // is shadowed by a later occurrence of the same key. For the
1711 // marked expressions, no store code is emitted.
1712 expr->CalculateEmitStore(zone());
1714 AccessorTable accessor_table(zone());
1715 int property_index = 0;
1716 for (; property_index < expr->properties()->length(); property_index++) {
1717 ObjectLiteral::Property* property = expr->properties()->at(property_index);
1718 if (property->is_computed_name()) break;
1719 if (property->IsCompileTimeValue()) continue;
1721 Literal* key = property->key()->AsLiteral();
1722 Expression* value = property->value();
1723 if (!result_saved) {
1724 __ push(r0); // Save result on stack
1725 result_saved = true;
1727 switch (property->kind()) {
1728 case ObjectLiteral::Property::CONSTANT:
1730 case ObjectLiteral::Property::MATERIALIZED_LITERAL:
1731 DCHECK(!CompileTimeValue::IsCompileTimeValue(property->value()));
1733 case ObjectLiteral::Property::COMPUTED:
1734 // It is safe to use [[Put]] here because the boilerplate already
1735 // contains computed properties with an uninitialized value.
1736 if (key->value()->IsInternalizedString()) {
1737 if (property->emit_store()) {
1738 VisitForAccumulatorValue(value);
1739 DCHECK(StoreDescriptor::ValueRegister().is(r0));
1740 __ mov(StoreDescriptor::NameRegister(), Operand(key->value()));
1741 __ ldr(StoreDescriptor::ReceiverRegister(), MemOperand(sp));
1742 CallStoreIC(key->LiteralFeedbackId());
1743 PrepareForBailoutForId(key->id(), NO_REGISTERS);
1745 if (NeedsHomeObject(value)) {
1746 __ Move(StoreDescriptor::ReceiverRegister(), r0);
1747 __ mov(StoreDescriptor::NameRegister(),
1748 Operand(isolate()->factory()->home_object_symbol()));
1749 __ ldr(StoreDescriptor::ValueRegister(), MemOperand(sp));
1753 VisitForEffect(value);
1757 // Duplicate receiver on stack.
1758 __ ldr(r0, MemOperand(sp));
1760 VisitForStackValue(key);
1761 VisitForStackValue(value);
1762 if (property->emit_store()) {
1763 EmitSetHomeObjectIfNeeded(value, 2);
1764 __ mov(r0, Operand(Smi::FromInt(SLOPPY))); // PropertyAttributes
1766 __ CallRuntime(Runtime::kSetProperty, 4);
1771 case ObjectLiteral::Property::PROTOTYPE:
1772 // Duplicate receiver on stack.
1773 __ ldr(r0, MemOperand(sp));
1775 VisitForStackValue(value);
1776 DCHECK(property->emit_store());
1777 __ CallRuntime(Runtime::kInternalSetPrototype, 2);
1780 case ObjectLiteral::Property::GETTER:
1781 if (property->emit_store()) {
1782 accessor_table.lookup(key)->second->getter = value;
1785 case ObjectLiteral::Property::SETTER:
1786 if (property->emit_store()) {
1787 accessor_table.lookup(key)->second->setter = value;
1793 // Emit code to define accessors, using only a single call to the runtime for
1794 // each pair of corresponding getters and setters.
1795 for (AccessorTable::Iterator it = accessor_table.begin();
1796 it != accessor_table.end();
1798 __ ldr(r0, MemOperand(sp)); // Duplicate receiver.
1800 VisitForStackValue(it->first);
1801 EmitAccessor(it->second->getter);
1802 EmitSetHomeObjectIfNeeded(it->second->getter, 2);
1803 EmitAccessor(it->second->setter);
1804 EmitSetHomeObjectIfNeeded(it->second->setter, 3);
1805 __ mov(r0, Operand(Smi::FromInt(NONE)));
1807 __ CallRuntime(Runtime::kDefineAccessorPropertyUnchecked, 5);
1810 // Object literals have two parts. The "static" part on the left contains no
1811 // computed property names, and so we can compute its map ahead of time; see
1812 // runtime.cc::CreateObjectLiteralBoilerplate. The second "dynamic" part
1813 // starts with the first computed property name, and continues with all
1814 // properties to its right. All the code from above initializes the static
1815 // component of the object literal, and arranges for the map of the result to
1816 // reflect the static order in which the keys appear. For the dynamic
1817 // properties, we compile them into a series of "SetOwnProperty" runtime
1818 // calls. This will preserve insertion order.
1819 for (; property_index < expr->properties()->length(); property_index++) {
1820 ObjectLiteral::Property* property = expr->properties()->at(property_index);
1822 Expression* value = property->value();
1823 if (!result_saved) {
1824 __ push(r0); // Save result on the stack
1825 result_saved = true;
1828 __ ldr(r0, MemOperand(sp)); // Duplicate receiver.
1831 if (property->kind() == ObjectLiteral::Property::PROTOTYPE) {
1832 DCHECK(!property->is_computed_name());
1833 VisitForStackValue(value);
1834 DCHECK(property->emit_store());
1835 __ CallRuntime(Runtime::kInternalSetPrototype, 2);
1837 EmitPropertyKey(property, expr->GetIdForProperty(property_index));
1838 VisitForStackValue(value);
1839 EmitSetHomeObjectIfNeeded(value, 2);
1841 switch (property->kind()) {
1842 case ObjectLiteral::Property::CONSTANT:
1843 case ObjectLiteral::Property::MATERIALIZED_LITERAL:
1844 case ObjectLiteral::Property::COMPUTED:
1845 if (property->emit_store()) {
1846 __ mov(r0, Operand(Smi::FromInt(NONE)));
1848 __ CallRuntime(Runtime::kDefineDataPropertyUnchecked, 4);
1854 case ObjectLiteral::Property::PROTOTYPE:
1858 case ObjectLiteral::Property::GETTER:
1859 __ mov(r0, Operand(Smi::FromInt(NONE)));
1861 __ CallRuntime(Runtime::kDefineGetterPropertyUnchecked, 4);
1864 case ObjectLiteral::Property::SETTER:
1865 __ mov(r0, Operand(Smi::FromInt(NONE)));
1867 __ CallRuntime(Runtime::kDefineSetterPropertyUnchecked, 4);
1873 if (expr->has_function()) {
1874 DCHECK(result_saved);
1875 __ ldr(r0, MemOperand(sp));
1877 __ CallRuntime(Runtime::kToFastProperties, 1);
1881 context()->PlugTOS();
1883 context()->Plug(r0);
1888 void FullCodeGenerator::VisitArrayLiteral(ArrayLiteral* expr) {
1889 Comment cmnt(masm_, "[ ArrayLiteral");
1891 expr->BuildConstantElements(isolate());
1893 Handle<FixedArray> constant_elements = expr->constant_elements();
1894 bool has_fast_elements =
1895 IsFastObjectElementsKind(expr->constant_elements_kind());
1896 Handle<FixedArrayBase> constant_elements_values(
1897 FixedArrayBase::cast(constant_elements->get(1)));
1899 AllocationSiteMode allocation_site_mode = TRACK_ALLOCATION_SITE;
1900 if (has_fast_elements && !FLAG_allocation_site_pretenuring) {
1901 // If the only customer of allocation sites is transitioning, then
1902 // we can turn it off if we don't have anywhere else to transition to.
1903 allocation_site_mode = DONT_TRACK_ALLOCATION_SITE;
1906 __ ldr(r3, MemOperand(fp, JavaScriptFrameConstants::kFunctionOffset));
1907 __ ldr(r3, FieldMemOperand(r3, JSFunction::kLiteralsOffset));
1908 __ mov(r2, Operand(Smi::FromInt(expr->literal_index())));
1909 __ mov(r1, Operand(constant_elements));
1910 if (MustCreateArrayLiteralWithRuntime(expr)) {
1911 __ mov(r0, Operand(Smi::FromInt(expr->ComputeFlags())));
1912 __ Push(r3, r2, r1, r0);
1913 __ CallRuntime(Runtime::kCreateArrayLiteral, 4);
1915 FastCloneShallowArrayStub stub(isolate(), allocation_site_mode);
1918 PrepareForBailoutForId(expr->CreateLiteralId(), TOS_REG);
1920 bool result_saved = false; // Is the result saved to the stack?
1921 ZoneList<Expression*>* subexprs = expr->values();
1922 int length = subexprs->length();
1924 // Emit code to evaluate all the non-constant subexpressions and to store
1925 // them into the newly cloned array.
1926 for (int i = 0; i < length; i++) {
1927 Expression* subexpr = subexprs->at(i);
1928 // If the subexpression is a literal or a simple materialized literal it
1929 // is already set in the cloned array.
1930 if (CompileTimeValue::IsCompileTimeValue(subexpr)) continue;
1932 if (!result_saved) {
1934 __ Push(Smi::FromInt(expr->literal_index()));
1935 result_saved = true;
1937 VisitForAccumulatorValue(subexpr);
1939 if (has_fast_elements) {
1940 int offset = FixedArray::kHeaderSize + (i * kPointerSize);
1941 __ ldr(r6, MemOperand(sp, kPointerSize)); // Copy of array literal.
1942 __ ldr(r1, FieldMemOperand(r6, JSObject::kElementsOffset));
1943 __ str(result_register(), FieldMemOperand(r1, offset));
1944 // Update the write barrier for the array store.
1945 __ RecordWriteField(r1, offset, result_register(), r2,
1946 kLRHasBeenSaved, kDontSaveFPRegs,
1947 EMIT_REMEMBERED_SET, INLINE_SMI_CHECK);
1949 __ mov(r3, Operand(Smi::FromInt(i)));
1950 StoreArrayLiteralElementStub stub(isolate());
1954 PrepareForBailoutForId(expr->GetIdForElement(i), NO_REGISTERS);
1958 __ pop(); // literal index
1959 context()->PlugTOS();
1961 context()->Plug(r0);
1966 void FullCodeGenerator::VisitAssignment(Assignment* expr) {
1967 DCHECK(expr->target()->IsValidReferenceExpression());
1969 Comment cmnt(masm_, "[ Assignment");
1971 Property* property = expr->target()->AsProperty();
1972 LhsKind assign_type = GetAssignType(property);
1974 // Evaluate LHS expression.
1975 switch (assign_type) {
1977 // Nothing to do here.
1979 case NAMED_PROPERTY:
1980 if (expr->is_compound()) {
1981 // We need the receiver both on the stack and in the register.
1982 VisitForStackValue(property->obj());
1983 __ ldr(LoadDescriptor::ReceiverRegister(), MemOperand(sp, 0));
1985 VisitForStackValue(property->obj());
1988 case NAMED_SUPER_PROPERTY:
1989 VisitForStackValue(property->obj()->AsSuperReference()->this_var());
1990 EmitLoadHomeObject(property->obj()->AsSuperReference());
1991 __ Push(result_register());
1992 if (expr->is_compound()) {
1993 const Register scratch = r1;
1994 __ ldr(scratch, MemOperand(sp, kPointerSize));
1996 __ Push(result_register());
1999 case KEYED_SUPER_PROPERTY:
2000 VisitForStackValue(property->obj()->AsSuperReference()->this_var());
2001 EmitLoadHomeObject(property->obj()->AsSuperReference());
2002 __ Push(result_register());
2003 VisitForAccumulatorValue(property->key());
2004 __ Push(result_register());
2005 if (expr->is_compound()) {
2006 const Register scratch = r1;
2007 __ ldr(scratch, MemOperand(sp, 2 * kPointerSize));
2009 __ ldr(scratch, MemOperand(sp, 2 * kPointerSize));
2011 __ Push(result_register());
2014 case KEYED_PROPERTY:
2015 if (expr->is_compound()) {
2016 VisitForStackValue(property->obj());
2017 VisitForStackValue(property->key());
2018 __ ldr(LoadDescriptor::ReceiverRegister(),
2019 MemOperand(sp, 1 * kPointerSize));
2020 __ ldr(LoadDescriptor::NameRegister(), MemOperand(sp, 0));
2022 VisitForStackValue(property->obj());
2023 VisitForStackValue(property->key());
2028 // For compound assignments we need another deoptimization point after the
2029 // variable/property load.
2030 if (expr->is_compound()) {
2031 { AccumulatorValueContext context(this);
2032 switch (assign_type) {
2034 EmitVariableLoad(expr->target()->AsVariableProxy());
2035 PrepareForBailout(expr->target(), TOS_REG);
2037 case NAMED_PROPERTY:
2038 EmitNamedPropertyLoad(property);
2039 PrepareForBailoutForId(property->LoadId(), TOS_REG);
2041 case NAMED_SUPER_PROPERTY:
2042 EmitNamedSuperPropertyLoad(property);
2043 PrepareForBailoutForId(property->LoadId(), TOS_REG);
2045 case KEYED_SUPER_PROPERTY:
2046 EmitKeyedSuperPropertyLoad(property);
2047 PrepareForBailoutForId(property->LoadId(), TOS_REG);
2049 case KEYED_PROPERTY:
2050 EmitKeyedPropertyLoad(property);
2051 PrepareForBailoutForId(property->LoadId(), TOS_REG);
2056 Token::Value op = expr->binary_op();
2057 __ push(r0); // Left operand goes on the stack.
2058 VisitForAccumulatorValue(expr->value());
2060 SetSourcePosition(expr->position() + 1);
2061 AccumulatorValueContext context(this);
2062 if (ShouldInlineSmiCase(op)) {
2063 EmitInlineSmiBinaryOp(expr->binary_operation(),
2068 EmitBinaryOp(expr->binary_operation(), op);
2071 // Deoptimization point in case the binary operation may have side effects.
2072 PrepareForBailout(expr->binary_operation(), TOS_REG);
2074 VisitForAccumulatorValue(expr->value());
2077 // Record source position before possible IC call.
2078 SetSourcePosition(expr->position());
2081 switch (assign_type) {
2083 EmitVariableAssignment(expr->target()->AsVariableProxy()->var(),
2085 PrepareForBailoutForId(expr->AssignmentId(), TOS_REG);
2086 context()->Plug(r0);
2088 case NAMED_PROPERTY:
2089 EmitNamedPropertyAssignment(expr);
2091 case NAMED_SUPER_PROPERTY:
2092 EmitNamedSuperPropertyStore(property);
2093 context()->Plug(r0);
2095 case KEYED_SUPER_PROPERTY:
2096 EmitKeyedSuperPropertyStore(property);
2097 context()->Plug(r0);
2099 case KEYED_PROPERTY:
2100 EmitKeyedPropertyAssignment(expr);
2106 void FullCodeGenerator::VisitYield(Yield* expr) {
2107 Comment cmnt(masm_, "[ Yield");
2108 // Evaluate yielded value first; the initial iterator definition depends on
2109 // this. It stays on the stack while we update the iterator.
2110 VisitForStackValue(expr->expression());
2112 switch (expr->yield_kind()) {
2113 case Yield::kSuspend:
2114 // Pop value from top-of-stack slot; box result into result register.
2115 EmitCreateIteratorResult(false);
2116 __ push(result_register());
2118 case Yield::kInitial: {
2119 Label suspend, continuation, post_runtime, resume;
2123 __ bind(&continuation);
2127 VisitForAccumulatorValue(expr->generator_object());
2128 DCHECK(continuation.pos() > 0 && Smi::IsValid(continuation.pos()));
2129 __ mov(r1, Operand(Smi::FromInt(continuation.pos())));
2130 __ str(r1, FieldMemOperand(r0, JSGeneratorObject::kContinuationOffset));
2131 __ str(cp, FieldMemOperand(r0, JSGeneratorObject::kContextOffset));
2133 __ RecordWriteField(r0, JSGeneratorObject::kContextOffset, r1, r2,
2134 kLRHasBeenSaved, kDontSaveFPRegs);
2135 __ add(r1, fp, Operand(StandardFrameConstants::kExpressionsOffset));
2137 __ b(eq, &post_runtime);
2138 __ push(r0); // generator object
2139 __ CallRuntime(Runtime::kSuspendJSGeneratorObject, 1);
2140 __ ldr(cp, MemOperand(fp, StandardFrameConstants::kContextOffset));
2141 __ bind(&post_runtime);
2142 __ pop(result_register());
2143 EmitReturnSequence();
2146 context()->Plug(result_register());
2150 case Yield::kFinal: {
2151 VisitForAccumulatorValue(expr->generator_object());
2152 __ mov(r1, Operand(Smi::FromInt(JSGeneratorObject::kGeneratorClosed)));
2153 __ str(r1, FieldMemOperand(result_register(),
2154 JSGeneratorObject::kContinuationOffset));
2155 // Pop value from top-of-stack slot, box result into result register.
2156 EmitCreateIteratorResult(true);
2157 EmitUnwindBeforeReturn();
2158 EmitReturnSequence();
2162 case Yield::kDelegating: {
2163 VisitForStackValue(expr->generator_object());
2165 // Initial stack layout is as follows:
2166 // [sp + 1 * kPointerSize] iter
2167 // [sp + 0 * kPointerSize] g
2169 Label l_catch, l_try, l_suspend, l_continuation, l_resume;
2170 Label l_next, l_call, l_loop;
2171 Register load_receiver = LoadDescriptor::ReceiverRegister();
2172 Register load_name = LoadDescriptor::NameRegister();
2174 // Initial send value is undefined.
2175 __ LoadRoot(r0, Heap::kUndefinedValueRootIndex);
2178 // catch (e) { receiver = iter; f = 'throw'; arg = e; goto l_call; }
2180 handler_table()->set(expr->index(), Smi::FromInt(l_catch.pos()));
2181 __ LoadRoot(load_name, Heap::kthrow_stringRootIndex); // "throw"
2182 __ ldr(r3, MemOperand(sp, 1 * kPointerSize)); // iter
2183 __ Push(load_name, r3, r0); // "throw", iter, except
2186 // try { received = %yield result }
2187 // Shuffle the received result above a try handler and yield it without
2190 __ pop(r0); // result
2191 __ PushTryHandler(StackHandler::CATCH, expr->index());
2192 const int handler_size = StackHandlerConstants::kSize;
2193 __ push(r0); // result
2195 __ bind(&l_continuation);
2197 __ bind(&l_suspend);
2198 const int generator_object_depth = kPointerSize + handler_size;
2199 __ ldr(r0, MemOperand(sp, generator_object_depth));
2201 DCHECK(l_continuation.pos() > 0 && Smi::IsValid(l_continuation.pos()));
2202 __ mov(r1, Operand(Smi::FromInt(l_continuation.pos())));
2203 __ str(r1, FieldMemOperand(r0, JSGeneratorObject::kContinuationOffset));
2204 __ str(cp, FieldMemOperand(r0, JSGeneratorObject::kContextOffset));
2206 __ RecordWriteField(r0, JSGeneratorObject::kContextOffset, r1, r2,
2207 kLRHasBeenSaved, kDontSaveFPRegs);
2208 __ CallRuntime(Runtime::kSuspendJSGeneratorObject, 1);
2209 __ ldr(cp, MemOperand(fp, StandardFrameConstants::kContextOffset));
2210 __ pop(r0); // result
2211 EmitReturnSequence();
2212 __ bind(&l_resume); // received in r0
2215 // receiver = iter; f = 'next'; arg = received;
2218 __ LoadRoot(load_name, Heap::knext_stringRootIndex); // "next"
2219 __ ldr(r3, MemOperand(sp, 1 * kPointerSize)); // iter
2220 __ Push(load_name, r3, r0); // "next", iter, received
2222 // result = receiver[f](arg);
2224 __ ldr(load_receiver, MemOperand(sp, kPointerSize));
2225 __ ldr(load_name, MemOperand(sp, 2 * kPointerSize));
2226 if (FLAG_vector_ics) {
2227 __ mov(VectorLoadICDescriptor::SlotRegister(),
2228 Operand(SmiFromSlot(expr->KeyedLoadFeedbackSlot())));
2230 Handle<Code> ic = CodeFactory::KeyedLoadIC(isolate()).code();
2231 CallIC(ic, TypeFeedbackId::None());
2233 __ str(r1, MemOperand(sp, 2 * kPointerSize));
2234 CallFunctionStub stub(isolate(), 1, CALL_AS_METHOD);
2237 __ ldr(cp, MemOperand(fp, StandardFrameConstants::kContextOffset));
2238 __ Drop(1); // The function is still on the stack; drop it.
2240 // if (!result.done) goto l_try;
2242 __ Move(load_receiver, r0);
2244 __ push(load_receiver); // save result
2245 __ LoadRoot(load_name, Heap::kdone_stringRootIndex); // "done"
2246 if (FLAG_vector_ics) {
2247 __ mov(VectorLoadICDescriptor::SlotRegister(),
2248 Operand(SmiFromSlot(expr->DoneFeedbackSlot())));
2250 CallLoadIC(NOT_CONTEXTUAL); // r0=result.done
2251 Handle<Code> bool_ic = ToBooleanStub::GetUninitialized(isolate());
2253 __ cmp(r0, Operand(0));
2257 __ pop(load_receiver); // result
2258 __ LoadRoot(load_name, Heap::kvalue_stringRootIndex); // "value"
2259 if (FLAG_vector_ics) {
2260 __ mov(VectorLoadICDescriptor::SlotRegister(),
2261 Operand(SmiFromSlot(expr->ValueFeedbackSlot())));
2263 CallLoadIC(NOT_CONTEXTUAL); // r0=result.value
2264 context()->DropAndPlug(2, r0); // drop iter and g
2271 void FullCodeGenerator::EmitGeneratorResume(Expression *generator,
2273 JSGeneratorObject::ResumeMode resume_mode) {
2274 // The value stays in r0, and is ultimately read by the resumed generator, as
2275 // if CallRuntime(Runtime::kSuspendJSGeneratorObject) returned it. Or it
2276 // is read to throw the value when the resumed generator is already closed.
2277 // r1 will hold the generator object until the activation has been resumed.
2278 VisitForStackValue(generator);
2279 VisitForAccumulatorValue(value);
2282 // Load suspended function and context.
2283 __ ldr(cp, FieldMemOperand(r1, JSGeneratorObject::kContextOffset));
2284 __ ldr(r4, FieldMemOperand(r1, JSGeneratorObject::kFunctionOffset));
2286 // Load receiver and store as the first argument.
2287 __ ldr(r2, FieldMemOperand(r1, JSGeneratorObject::kReceiverOffset));
2290 // Push holes for the rest of the arguments to the generator function.
2291 __ ldr(r3, FieldMemOperand(r4, JSFunction::kSharedFunctionInfoOffset));
2293 FieldMemOperand(r3, SharedFunctionInfo::kFormalParameterCountOffset));
2294 __ LoadRoot(r2, Heap::kTheHoleValueRootIndex);
2295 Label push_argument_holes, push_frame;
2296 __ bind(&push_argument_holes);
2297 __ sub(r3, r3, Operand(Smi::FromInt(1)), SetCC);
2298 __ b(mi, &push_frame);
2300 __ jmp(&push_argument_holes);
2302 // Enter a new JavaScript frame, and initialize its slots as they were when
2303 // the generator was suspended.
2304 Label resume_frame, done;
2305 __ bind(&push_frame);
2306 __ bl(&resume_frame);
2308 __ bind(&resume_frame);
2309 // lr = return address.
2310 // fp = caller's frame pointer.
2311 // pp = caller's constant pool (if FLAG_enable_ool_constant_pool),
2312 // cp = callee's context,
2313 // r4 = callee's JS function.
2314 __ PushFixedFrame(r4);
2315 // Adjust FP to point to saved FP.
2316 __ add(fp, sp, Operand(StandardFrameConstants::kFixedFrameSizeFromFp));
2318 // Load the operand stack size.
2319 __ ldr(r3, FieldMemOperand(r1, JSGeneratorObject::kOperandStackOffset));
2320 __ ldr(r3, FieldMemOperand(r3, FixedArray::kLengthOffset));
2323 // If we are sending a value and there is no operand stack, we can jump back
2325 if (resume_mode == JSGeneratorObject::NEXT) {
2327 __ cmp(r3, Operand(0));
2328 __ b(ne, &slow_resume);
2329 __ ldr(r3, FieldMemOperand(r4, JSFunction::kCodeEntryOffset));
2331 { ConstantPoolUnavailableScope constant_pool_unavailable(masm_);
2332 if (FLAG_enable_ool_constant_pool) {
2333 // Load the new code object's constant pool pointer.
2335 MemOperand(r3, Code::kConstantPoolOffset - Code::kHeaderSize));
2338 __ ldr(r2, FieldMemOperand(r1, JSGeneratorObject::kContinuationOffset));
2341 __ mov(r2, Operand(Smi::FromInt(JSGeneratorObject::kGeneratorExecuting)));
2342 __ str(r2, FieldMemOperand(r1, JSGeneratorObject::kContinuationOffset));
2345 __ bind(&slow_resume);
2348 // Otherwise, we push holes for the operand stack and call the runtime to fix
2349 // up the stack and the handlers.
2350 Label push_operand_holes, call_resume;
2351 __ bind(&push_operand_holes);
2352 __ sub(r3, r3, Operand(1), SetCC);
2353 __ b(mi, &call_resume);
2355 __ b(&push_operand_holes);
2356 __ bind(&call_resume);
2357 DCHECK(!result_register().is(r1));
2358 __ Push(r1, result_register());
2359 __ Push(Smi::FromInt(resume_mode));
2360 __ CallRuntime(Runtime::kResumeJSGeneratorObject, 3);
2361 // Not reached: the runtime call returns elsewhere.
2362 __ stop("not-reached");
2365 context()->Plug(result_register());
2369 void FullCodeGenerator::EmitCreateIteratorResult(bool done) {
2373 const int instance_size = 5 * kPointerSize;
2374 DCHECK_EQ(isolate()->native_context()->iterator_result_map()->instance_size(),
2377 __ Allocate(instance_size, r0, r2, r3, &gc_required, TAG_OBJECT);
2380 __ bind(&gc_required);
2381 __ Push(Smi::FromInt(instance_size));
2382 __ CallRuntime(Runtime::kAllocateInNewSpace, 1);
2383 __ ldr(context_register(),
2384 MemOperand(fp, StandardFrameConstants::kContextOffset));
2386 __ bind(&allocated);
2387 __ ldr(r1, ContextOperand(cp, Context::GLOBAL_OBJECT_INDEX));
2388 __ ldr(r1, FieldMemOperand(r1, GlobalObject::kNativeContextOffset));
2389 __ ldr(r1, ContextOperand(r1, Context::ITERATOR_RESULT_MAP_INDEX));
2391 __ mov(r3, Operand(isolate()->factory()->ToBoolean(done)));
2392 __ mov(r4, Operand(isolate()->factory()->empty_fixed_array()));
2393 __ str(r1, FieldMemOperand(r0, HeapObject::kMapOffset));
2394 __ str(r4, FieldMemOperand(r0, JSObject::kPropertiesOffset));
2395 __ str(r4, FieldMemOperand(r0, JSObject::kElementsOffset));
2397 FieldMemOperand(r0, JSGeneratorObject::kResultValuePropertyOffset));
2399 FieldMemOperand(r0, JSGeneratorObject::kResultDonePropertyOffset));
2401 // Only the value field needs a write barrier, as the other values are in the
2403 __ RecordWriteField(r0, JSGeneratorObject::kResultValuePropertyOffset,
2404 r2, r3, kLRHasBeenSaved, kDontSaveFPRegs);
2408 void FullCodeGenerator::EmitNamedPropertyLoad(Property* prop) {
2409 SetSourcePosition(prop->position());
2410 Literal* key = prop->key()->AsLiteral();
2411 DCHECK(!prop->IsSuperAccess());
2413 __ mov(LoadDescriptor::NameRegister(), Operand(key->value()));
2414 if (FLAG_vector_ics) {
2415 __ mov(VectorLoadICDescriptor::SlotRegister(),
2416 Operand(SmiFromSlot(prop->PropertyFeedbackSlot())));
2417 CallLoadIC(NOT_CONTEXTUAL);
2419 CallLoadIC(NOT_CONTEXTUAL, prop->PropertyFeedbackId());
2424 void FullCodeGenerator::EmitNamedSuperPropertyLoad(Property* prop) {
2425 // Stack: receiver, home_object.
2426 SetSourcePosition(prop->position());
2427 Literal* key = prop->key()->AsLiteral();
2428 DCHECK(!key->value()->IsSmi());
2429 DCHECK(prop->IsSuperAccess());
2431 __ Push(key->value());
2432 __ CallRuntime(Runtime::kLoadFromSuper, 3);
2436 void FullCodeGenerator::EmitKeyedPropertyLoad(Property* prop) {
2437 SetSourcePosition(prop->position());
2438 Handle<Code> ic = CodeFactory::KeyedLoadIC(isolate()).code();
2439 if (FLAG_vector_ics) {
2440 __ mov(VectorLoadICDescriptor::SlotRegister(),
2441 Operand(SmiFromSlot(prop->PropertyFeedbackSlot())));
2444 CallIC(ic, prop->PropertyFeedbackId());
2449 void FullCodeGenerator::EmitKeyedSuperPropertyLoad(Property* prop) {
2450 // Stack: receiver, home_object, key.
2451 SetSourcePosition(prop->position());
2453 __ CallRuntime(Runtime::kLoadKeyedFromSuper, 3);
2457 void FullCodeGenerator::EmitInlineSmiBinaryOp(BinaryOperation* expr,
2459 Expression* left_expr,
2460 Expression* right_expr) {
2461 Label done, smi_case, stub_call;
2463 Register scratch1 = r2;
2464 Register scratch2 = r3;
2466 // Get the arguments.
2468 Register right = r0;
2471 // Perform combined smi check on both operands.
2472 __ orr(scratch1, left, Operand(right));
2473 STATIC_ASSERT(kSmiTag == 0);
2474 JumpPatchSite patch_site(masm_);
2475 patch_site.EmitJumpIfSmi(scratch1, &smi_case);
2477 __ bind(&stub_call);
2478 Handle<Code> code = CodeFactory::BinaryOpIC(isolate(), op).code();
2479 CallIC(code, expr->BinaryOperationFeedbackId());
2480 patch_site.EmitPatchInfo();
2484 // Smi case. This code works the same way as the smi-smi case in the type
2485 // recording binary operation stub, see
2488 __ GetLeastBitsFromSmi(scratch1, right, 5);
2489 __ mov(right, Operand(left, ASR, scratch1));
2490 __ bic(right, right, Operand(kSmiTagMask));
2493 __ SmiUntag(scratch1, left);
2494 __ GetLeastBitsFromSmi(scratch2, right, 5);
2495 __ mov(scratch1, Operand(scratch1, LSL, scratch2));
2496 __ TrySmiTag(right, scratch1, &stub_call);
2500 __ SmiUntag(scratch1, left);
2501 __ GetLeastBitsFromSmi(scratch2, right, 5);
2502 __ mov(scratch1, Operand(scratch1, LSR, scratch2));
2503 __ tst(scratch1, Operand(0xc0000000));
2504 __ b(ne, &stub_call);
2505 __ SmiTag(right, scratch1);
2509 __ add(scratch1, left, Operand(right), SetCC);
2510 __ b(vs, &stub_call);
2511 __ mov(right, scratch1);
2514 __ sub(scratch1, left, Operand(right), SetCC);
2515 __ b(vs, &stub_call);
2516 __ mov(right, scratch1);
2519 __ SmiUntag(ip, right);
2520 __ smull(scratch1, scratch2, left, ip);
2521 __ mov(ip, Operand(scratch1, ASR, 31));
2522 __ cmp(ip, Operand(scratch2));
2523 __ b(ne, &stub_call);
2524 __ cmp(scratch1, Operand::Zero());
2525 __ mov(right, Operand(scratch1), LeaveCC, ne);
2527 __ add(scratch2, right, Operand(left), SetCC);
2528 __ mov(right, Operand(Smi::FromInt(0)), LeaveCC, pl);
2529 __ b(mi, &stub_call);
2533 __ orr(right, left, Operand(right));
2535 case Token::BIT_AND:
2536 __ and_(right, left, Operand(right));
2538 case Token::BIT_XOR:
2539 __ eor(right, left, Operand(right));
2546 context()->Plug(r0);
2550 void FullCodeGenerator::EmitClassDefineProperties(ClassLiteral* lit) {
2551 // Constructor is in r0.
2552 DCHECK(lit != NULL);
2555 // No access check is needed here since the constructor is created by the
2557 Register scratch = r1;
2559 FieldMemOperand(r0, JSFunction::kPrototypeOrInitialMapOffset));
2562 for (int i = 0; i < lit->properties()->length(); i++) {
2563 ObjectLiteral::Property* property = lit->properties()->at(i);
2564 Expression* value = property->value();
2566 if (property->is_static()) {
2567 __ ldr(scratch, MemOperand(sp, kPointerSize)); // constructor
2569 __ ldr(scratch, MemOperand(sp, 0)); // prototype
2572 EmitPropertyKey(property, lit->GetIdForProperty(i));
2573 VisitForStackValue(value);
2574 EmitSetHomeObjectIfNeeded(value, 2);
2576 switch (property->kind()) {
2577 case ObjectLiteral::Property::CONSTANT:
2578 case ObjectLiteral::Property::MATERIALIZED_LITERAL:
2579 case ObjectLiteral::Property::PROTOTYPE:
2581 case ObjectLiteral::Property::COMPUTED:
2582 __ CallRuntime(Runtime::kDefineClassMethod, 3);
2585 case ObjectLiteral::Property::GETTER:
2586 __ mov(r0, Operand(Smi::FromInt(DONT_ENUM)));
2588 __ CallRuntime(Runtime::kDefineGetterPropertyUnchecked, 4);
2591 case ObjectLiteral::Property::SETTER:
2592 __ mov(r0, Operand(Smi::FromInt(DONT_ENUM)));
2594 __ CallRuntime(Runtime::kDefineSetterPropertyUnchecked, 4);
2603 __ CallRuntime(Runtime::kToFastProperties, 1);
2606 __ CallRuntime(Runtime::kToFastProperties, 1);
2610 void FullCodeGenerator::EmitBinaryOp(BinaryOperation* expr, Token::Value op) {
2612 Handle<Code> code = CodeFactory::BinaryOpIC(isolate(), op).code();
2613 JumpPatchSite patch_site(masm_); // unbound, signals no inlined smi code.
2614 CallIC(code, expr->BinaryOperationFeedbackId());
2615 patch_site.EmitPatchInfo();
2616 context()->Plug(r0);
2620 void FullCodeGenerator::EmitAssignment(Expression* expr) {
2621 DCHECK(expr->IsValidReferenceExpression());
2623 Property* prop = expr->AsProperty();
2624 LhsKind assign_type = GetAssignType(prop);
2626 switch (assign_type) {
2628 Variable* var = expr->AsVariableProxy()->var();
2629 EffectContext context(this);
2630 EmitVariableAssignment(var, Token::ASSIGN);
2633 case NAMED_PROPERTY: {
2634 __ push(r0); // Preserve value.
2635 VisitForAccumulatorValue(prop->obj());
2636 __ Move(StoreDescriptor::ReceiverRegister(), r0);
2637 __ pop(StoreDescriptor::ValueRegister()); // Restore value.
2638 __ mov(StoreDescriptor::NameRegister(),
2639 Operand(prop->key()->AsLiteral()->value()));
2643 case NAMED_SUPER_PROPERTY: {
2645 VisitForStackValue(prop->obj()->AsSuperReference()->this_var());
2646 EmitLoadHomeObject(prop->obj()->AsSuperReference());
2647 // stack: value, this; r0: home_object
2648 Register scratch = r2;
2649 Register scratch2 = r3;
2650 __ mov(scratch, result_register()); // home_object
2651 __ ldr(r0, MemOperand(sp, kPointerSize)); // value
2652 __ ldr(scratch2, MemOperand(sp, 0)); // this
2653 __ str(scratch2, MemOperand(sp, kPointerSize)); // this
2654 __ str(scratch, MemOperand(sp, 0)); // home_object
2655 // stack: this, home_object; r0: value
2656 EmitNamedSuperPropertyStore(prop);
2659 case KEYED_SUPER_PROPERTY: {
2661 VisitForStackValue(prop->obj()->AsSuperReference()->this_var());
2662 EmitLoadHomeObject(prop->obj()->AsSuperReference());
2663 __ Push(result_register());
2664 VisitForAccumulatorValue(prop->key());
2665 Register scratch = r2;
2666 Register scratch2 = r3;
2667 __ ldr(scratch2, MemOperand(sp, 2 * kPointerSize)); // value
2668 // stack: value, this, home_object; r0: key, r3: value
2669 __ ldr(scratch, MemOperand(sp, kPointerSize)); // this
2670 __ str(scratch, MemOperand(sp, 2 * kPointerSize));
2671 __ ldr(scratch, MemOperand(sp, 0)); // home_object
2672 __ str(scratch, MemOperand(sp, kPointerSize));
2673 __ str(r0, MemOperand(sp, 0));
2674 __ Move(r0, scratch2);
2675 // stack: this, home_object, key; r0: value.
2676 EmitKeyedSuperPropertyStore(prop);
2679 case KEYED_PROPERTY: {
2680 __ push(r0); // Preserve value.
2681 VisitForStackValue(prop->obj());
2682 VisitForAccumulatorValue(prop->key());
2683 __ Move(StoreDescriptor::NameRegister(), r0);
2684 __ Pop(StoreDescriptor::ValueRegister(),
2685 StoreDescriptor::ReceiverRegister());
2687 CodeFactory::KeyedStoreIC(isolate(), language_mode()).code();
2692 context()->Plug(r0);
2696 void FullCodeGenerator::EmitStoreToStackLocalOrContextSlot(
2697 Variable* var, MemOperand location) {
2698 __ str(result_register(), location);
2699 if (var->IsContextSlot()) {
2700 // RecordWrite may destroy all its register arguments.
2701 __ mov(r3, result_register());
2702 int offset = Context::SlotOffset(var->index());
2703 __ RecordWriteContextSlot(
2704 r1, offset, r3, r2, kLRHasBeenSaved, kDontSaveFPRegs);
2709 void FullCodeGenerator::EmitVariableAssignment(Variable* var, Token::Value op) {
2710 if (var->IsUnallocated()) {
2711 // Global var, const, or let.
2712 __ mov(StoreDescriptor::NameRegister(), Operand(var->name()));
2713 __ ldr(StoreDescriptor::ReceiverRegister(), GlobalObjectOperand());
2716 } else if (op == Token::INIT_CONST_LEGACY) {
2717 // Const initializers need a write barrier.
2718 DCHECK(!var->IsParameter()); // No const parameters.
2719 if (var->IsLookupSlot()) {
2721 __ mov(r0, Operand(var->name()));
2722 __ Push(cp, r0); // Context and name.
2723 __ CallRuntime(Runtime::kInitializeLegacyConstLookupSlot, 3);
2725 DCHECK(var->IsStackAllocated() || var->IsContextSlot());
2727 MemOperand location = VarOperand(var, r1);
2728 __ ldr(r2, location);
2729 __ CompareRoot(r2, Heap::kTheHoleValueRootIndex);
2731 EmitStoreToStackLocalOrContextSlot(var, location);
2735 } else if (var->mode() == LET && op != Token::INIT_LET) {
2736 // Non-initializing assignment to let variable needs a write barrier.
2737 DCHECK(!var->IsLookupSlot());
2738 DCHECK(var->IsStackAllocated() || var->IsContextSlot());
2740 MemOperand location = VarOperand(var, r1);
2741 __ ldr(r3, location);
2742 __ CompareRoot(r3, Heap::kTheHoleValueRootIndex);
2744 __ mov(r3, Operand(var->name()));
2746 __ CallRuntime(Runtime::kThrowReferenceError, 1);
2747 // Perform the assignment.
2749 EmitStoreToStackLocalOrContextSlot(var, location);
2751 } else if (!var->is_const_mode() || op == Token::INIT_CONST) {
2752 if (var->IsLookupSlot()) {
2753 // Assignment to var.
2754 __ push(r0); // Value.
2755 __ mov(r1, Operand(var->name()));
2756 __ mov(r0, Operand(Smi::FromInt(language_mode())));
2757 __ Push(cp, r1, r0); // Context, name, language mode.
2758 __ CallRuntime(Runtime::kStoreLookupSlot, 4);
2760 // Assignment to var or initializing assignment to let/const in harmony
2762 DCHECK((var->IsStackAllocated() || var->IsContextSlot()));
2763 MemOperand location = VarOperand(var, r1);
2764 if (generate_debug_code_ && op == Token::INIT_LET) {
2765 // Check for an uninitialized let binding.
2766 __ ldr(r2, location);
2767 __ CompareRoot(r2, Heap::kTheHoleValueRootIndex);
2768 __ Check(eq, kLetBindingReInitialization);
2770 EmitStoreToStackLocalOrContextSlot(var, location);
2772 } else if (IsSignallingAssignmentToConst(var, op, language_mode())) {
2773 __ CallRuntime(Runtime::kThrowConstAssignError, 0);
2778 void FullCodeGenerator::EmitNamedPropertyAssignment(Assignment* expr) {
2779 // Assignment to a property, using a named store IC.
2780 Property* prop = expr->target()->AsProperty();
2781 DCHECK(prop != NULL);
2782 DCHECK(prop->key()->IsLiteral());
2784 // Record source code position before IC call.
2785 SetSourcePosition(expr->position());
2786 __ mov(StoreDescriptor::NameRegister(),
2787 Operand(prop->key()->AsLiteral()->value()));
2788 __ pop(StoreDescriptor::ReceiverRegister());
2789 CallStoreIC(expr->AssignmentFeedbackId());
2791 PrepareForBailoutForId(expr->AssignmentId(), TOS_REG);
2792 context()->Plug(r0);
2796 void FullCodeGenerator::EmitNamedSuperPropertyStore(Property* prop) {
2797 // Assignment to named property of super.
2799 // stack : receiver ('this'), home_object
2800 DCHECK(prop != NULL);
2801 Literal* key = prop->key()->AsLiteral();
2802 DCHECK(key != NULL);
2804 __ Push(key->value());
2806 __ CallRuntime((is_strict(language_mode()) ? Runtime::kStoreToSuper_Strict
2807 : Runtime::kStoreToSuper_Sloppy),
2812 void FullCodeGenerator::EmitKeyedSuperPropertyStore(Property* prop) {
2813 // Assignment to named property of super.
2815 // stack : receiver ('this'), home_object, key
2816 DCHECK(prop != NULL);
2820 (is_strict(language_mode()) ? Runtime::kStoreKeyedToSuper_Strict
2821 : Runtime::kStoreKeyedToSuper_Sloppy),
2826 void FullCodeGenerator::EmitKeyedPropertyAssignment(Assignment* expr) {
2827 // Assignment to a property, using a keyed store IC.
2829 // Record source code position before IC call.
2830 SetSourcePosition(expr->position());
2831 __ Pop(StoreDescriptor::ReceiverRegister(), StoreDescriptor::NameRegister());
2832 DCHECK(StoreDescriptor::ValueRegister().is(r0));
2835 CodeFactory::KeyedStoreIC(isolate(), language_mode()).code();
2836 CallIC(ic, expr->AssignmentFeedbackId());
2838 PrepareForBailoutForId(expr->AssignmentId(), TOS_REG);
2839 context()->Plug(r0);
2843 void FullCodeGenerator::VisitProperty(Property* expr) {
2844 Comment cmnt(masm_, "[ Property");
2845 Expression* key = expr->key();
2847 if (key->IsPropertyName()) {
2848 if (!expr->IsSuperAccess()) {
2849 VisitForAccumulatorValue(expr->obj());
2850 __ Move(LoadDescriptor::ReceiverRegister(), r0);
2851 EmitNamedPropertyLoad(expr);
2853 VisitForStackValue(expr->obj()->AsSuperReference()->this_var());
2854 EmitLoadHomeObject(expr->obj()->AsSuperReference());
2855 __ Push(result_register());
2856 EmitNamedSuperPropertyLoad(expr);
2859 if (!expr->IsSuperAccess()) {
2860 VisitForStackValue(expr->obj());
2861 VisitForAccumulatorValue(expr->key());
2862 __ Move(LoadDescriptor::NameRegister(), r0);
2863 __ pop(LoadDescriptor::ReceiverRegister());
2864 EmitKeyedPropertyLoad(expr);
2866 VisitForStackValue(expr->obj()->AsSuperReference()->this_var());
2867 EmitLoadHomeObject(expr->obj()->AsSuperReference());
2868 __ Push(result_register());
2869 VisitForStackValue(expr->key());
2870 EmitKeyedSuperPropertyLoad(expr);
2873 PrepareForBailoutForId(expr->LoadId(), TOS_REG);
2874 context()->Plug(r0);
2878 void FullCodeGenerator::CallIC(Handle<Code> code,
2879 TypeFeedbackId ast_id) {
2881 // All calls must have a predictable size in full-codegen code to ensure that
2882 // the debugger can patch them correctly.
2883 __ Call(code, RelocInfo::CODE_TARGET, ast_id, al,
2884 NEVER_INLINE_TARGET_ADDRESS);
2888 // Code common for calls using the IC.
2889 void FullCodeGenerator::EmitCallWithLoadIC(Call* expr) {
2890 Expression* callee = expr->expression();
2892 CallICState::CallType call_type =
2893 callee->IsVariableProxy() ? CallICState::FUNCTION : CallICState::METHOD;
2895 // Get the target function.
2896 if (call_type == CallICState::FUNCTION) {
2897 { StackValueContext context(this);
2898 EmitVariableLoad(callee->AsVariableProxy());
2899 PrepareForBailout(callee, NO_REGISTERS);
2901 // Push undefined as receiver. This is patched in the method prologue if it
2902 // is a sloppy mode method.
2903 __ Push(isolate()->factory()->undefined_value());
2905 // Load the function from the receiver.
2906 DCHECK(callee->IsProperty());
2907 DCHECK(!callee->AsProperty()->IsSuperAccess());
2908 __ ldr(LoadDescriptor::ReceiverRegister(), MemOperand(sp, 0));
2909 EmitNamedPropertyLoad(callee->AsProperty());
2910 PrepareForBailoutForId(callee->AsProperty()->LoadId(), TOS_REG);
2911 // Push the target function under the receiver.
2912 __ ldr(ip, MemOperand(sp, 0));
2914 __ str(r0, MemOperand(sp, kPointerSize));
2917 EmitCall(expr, call_type);
2921 void FullCodeGenerator::EmitSuperCallWithLoadIC(Call* expr) {
2922 Expression* callee = expr->expression();
2923 DCHECK(callee->IsProperty());
2924 Property* prop = callee->AsProperty();
2925 DCHECK(prop->IsSuperAccess());
2927 SetSourcePosition(prop->position());
2928 Literal* key = prop->key()->AsLiteral();
2929 DCHECK(!key->value()->IsSmi());
2930 // Load the function from the receiver.
2931 const Register scratch = r1;
2932 SuperReference* super_ref = prop->obj()->AsSuperReference();
2933 EmitLoadHomeObject(super_ref);
2935 VisitForAccumulatorValue(super_ref->this_var());
2938 __ ldr(scratch, MemOperand(sp, kPointerSize * 2));
2940 __ Push(key->value());
2944 // - this (receiver)
2945 // - this (receiver) <-- LoadFromSuper will pop here and below.
2948 __ CallRuntime(Runtime::kLoadFromSuper, 3);
2950 // Replace home_object with target function.
2951 __ str(r0, MemOperand(sp, kPointerSize));
2954 // - target function
2955 // - this (receiver)
2956 EmitCall(expr, CallICState::METHOD);
2960 // Code common for calls using the IC.
2961 void FullCodeGenerator::EmitKeyedCallWithLoadIC(Call* expr,
2964 VisitForAccumulatorValue(key);
2966 Expression* callee = expr->expression();
2968 // Load the function from the receiver.
2969 DCHECK(callee->IsProperty());
2970 __ ldr(LoadDescriptor::ReceiverRegister(), MemOperand(sp, 0));
2971 __ Move(LoadDescriptor::NameRegister(), r0);
2972 EmitKeyedPropertyLoad(callee->AsProperty());
2973 PrepareForBailoutForId(callee->AsProperty()->LoadId(), TOS_REG);
2975 // Push the target function under the receiver.
2976 __ ldr(ip, MemOperand(sp, 0));
2978 __ str(r0, MemOperand(sp, kPointerSize));
2980 EmitCall(expr, CallICState::METHOD);
2984 void FullCodeGenerator::EmitKeyedSuperCallWithLoadIC(Call* expr) {
2985 Expression* callee = expr->expression();
2986 DCHECK(callee->IsProperty());
2987 Property* prop = callee->AsProperty();
2988 DCHECK(prop->IsSuperAccess());
2990 SetSourcePosition(prop->position());
2991 // Load the function from the receiver.
2992 const Register scratch = r1;
2993 SuperReference* super_ref = prop->obj()->AsSuperReference();
2994 EmitLoadHomeObject(super_ref);
2996 VisitForAccumulatorValue(super_ref->this_var());
2999 __ ldr(scratch, MemOperand(sp, kPointerSize * 2));
3001 VisitForStackValue(prop->key());
3005 // - this (receiver)
3006 // - this (receiver) <-- LoadKeyedFromSuper will pop here and below.
3009 __ CallRuntime(Runtime::kLoadKeyedFromSuper, 3);
3011 // Replace home_object with target function.
3012 __ str(r0, MemOperand(sp, kPointerSize));
3015 // - target function
3016 // - this (receiver)
3017 EmitCall(expr, CallICState::METHOD);
3021 void FullCodeGenerator::EmitCall(Call* expr, CallICState::CallType call_type) {
3022 // Load the arguments.
3023 ZoneList<Expression*>* args = expr->arguments();
3024 int arg_count = args->length();
3025 { PreservePositionScope scope(masm()->positions_recorder());
3026 for (int i = 0; i < arg_count; i++) {
3027 VisitForStackValue(args->at(i));
3031 // Record source position of the IC call.
3032 SetSourcePosition(expr->position());
3033 Handle<Code> ic = CodeFactory::CallIC(isolate(), arg_count, call_type).code();
3034 __ mov(r3, Operand(SmiFromSlot(expr->CallFeedbackICSlot())));
3035 __ ldr(r1, MemOperand(sp, (arg_count + 1) * kPointerSize));
3036 // Don't assign a type feedback id to the IC, since type feedback is provided
3037 // by the vector above.
3040 RecordJSReturnSite(expr);
3041 // Restore context register.
3042 __ ldr(cp, MemOperand(fp, StandardFrameConstants::kContextOffset));
3043 context()->DropAndPlug(1, r0);
3047 void FullCodeGenerator::EmitResolvePossiblyDirectEval(int arg_count) {
3048 // r5: copy of the first argument or undefined if it doesn't exist.
3049 if (arg_count > 0) {
3050 __ ldr(r5, MemOperand(sp, arg_count * kPointerSize));
3052 __ LoadRoot(r5, Heap::kUndefinedValueRootIndex);
3055 // r4: the receiver of the enclosing function.
3056 __ ldr(r4, MemOperand(fp, JavaScriptFrameConstants::kFunctionOffset));
3058 // r3: the receiver of the enclosing function.
3059 int receiver_offset = 2 + info_->scope()->num_parameters();
3060 __ ldr(r3, MemOperand(fp, receiver_offset * kPointerSize));
3062 // r2: language mode.
3063 __ mov(r2, Operand(Smi::FromInt(language_mode())));
3065 // r1: the start position of the scope the calls resides in.
3066 __ mov(r1, Operand(Smi::FromInt(scope()->start_position())));
3068 // Do the runtime call.
3070 __ Push(r4, r3, r2, r1);
3071 __ CallRuntime(Runtime::kResolvePossiblyDirectEval, 6);
3075 void FullCodeGenerator::EmitLoadSuperConstructor() {
3076 __ ldr(r0, MemOperand(fp, JavaScriptFrameConstants::kFunctionOffset));
3078 __ CallRuntime(Runtime::kGetPrototype, 1);
3082 void FullCodeGenerator::VisitCall(Call* expr) {
3084 // We want to verify that RecordJSReturnSite gets called on all paths
3085 // through this function. Avoid early returns.
3086 expr->return_is_recorded_ = false;
3089 Comment cmnt(masm_, "[ Call");
3090 Expression* callee = expr->expression();
3091 Call::CallType call_type = expr->GetCallType(isolate());
3093 if (call_type == Call::POSSIBLY_EVAL_CALL) {
3094 // In a call to eval, we first call RuntimeHidden_ResolvePossiblyDirectEval
3095 // to resolve the function we need to call and the receiver of the
3096 // call. Then we call the resolved function using the given
3098 ZoneList<Expression*>* args = expr->arguments();
3099 int arg_count = args->length();
3101 { PreservePositionScope pos_scope(masm()->positions_recorder());
3102 VisitForStackValue(callee);
3103 __ LoadRoot(r2, Heap::kUndefinedValueRootIndex);
3104 __ push(r2); // Reserved receiver slot.
3106 // Push the arguments.
3107 for (int i = 0; i < arg_count; i++) {
3108 VisitForStackValue(args->at(i));
3111 // Push a copy of the function (found below the arguments) and
3113 __ ldr(r1, MemOperand(sp, (arg_count + 1) * kPointerSize));
3115 EmitResolvePossiblyDirectEval(arg_count);
3117 // The runtime call returns a pair of values in r0 (function) and
3118 // r1 (receiver). Touch up the stack with the right values.
3119 __ str(r0, MemOperand(sp, (arg_count + 1) * kPointerSize));
3120 __ str(r1, MemOperand(sp, arg_count * kPointerSize));
3122 PrepareForBailoutForId(expr->EvalOrLookupId(), NO_REGISTERS);
3125 // Record source position for debugger.
3126 SetSourcePosition(expr->position());
3127 CallFunctionStub stub(isolate(), arg_count, NO_CALL_FUNCTION_FLAGS);
3128 __ ldr(r1, MemOperand(sp, (arg_count + 1) * kPointerSize));
3130 RecordJSReturnSite(expr);
3131 // Restore context register.
3132 __ ldr(cp, MemOperand(fp, StandardFrameConstants::kContextOffset));
3133 context()->DropAndPlug(1, r0);
3134 } else if (call_type == Call::GLOBAL_CALL) {
3135 EmitCallWithLoadIC(expr);
3137 } else if (call_type == Call::LOOKUP_SLOT_CALL) {
3138 // Call to a lookup slot (dynamically introduced variable).
3139 VariableProxy* proxy = callee->AsVariableProxy();
3142 { PreservePositionScope scope(masm()->positions_recorder());
3143 // Generate code for loading from variables potentially shadowed
3144 // by eval-introduced variables.
3145 EmitDynamicLookupFastCase(proxy, NOT_INSIDE_TYPEOF, &slow, &done);
3149 // Call the runtime to find the function to call (returned in r0)
3150 // and the object holding it (returned in edx).
3151 DCHECK(!context_register().is(r2));
3152 __ mov(r2, Operand(proxy->name()));
3153 __ Push(context_register(), r2);
3154 __ CallRuntime(Runtime::kLoadLookupSlot, 2);
3155 __ Push(r0, r1); // Function, receiver.
3156 PrepareForBailoutForId(expr->EvalOrLookupId(), NO_REGISTERS);
3158 // If fast case code has been generated, emit code to push the
3159 // function and receiver and have the slow path jump around this
3161 if (done.is_linked()) {
3167 // The receiver is implicitly the global receiver. Indicate this
3168 // by passing the hole to the call function stub.
3169 __ LoadRoot(r1, Heap::kUndefinedValueRootIndex);
3174 // The receiver is either the global receiver or an object found
3175 // by LoadContextSlot.
3177 } else if (call_type == Call::PROPERTY_CALL) {
3178 Property* property = callee->AsProperty();
3179 bool is_named_call = property->key()->IsPropertyName();
3180 if (property->IsSuperAccess()) {
3181 if (is_named_call) {
3182 EmitSuperCallWithLoadIC(expr);
3184 EmitKeyedSuperCallWithLoadIC(expr);
3188 PreservePositionScope scope(masm()->positions_recorder());
3189 VisitForStackValue(property->obj());
3191 if (is_named_call) {
3192 EmitCallWithLoadIC(expr);
3194 EmitKeyedCallWithLoadIC(expr, property->key());
3197 } else if (call_type == Call::SUPER_CALL) {
3198 EmitSuperConstructorCall(expr);
3200 DCHECK(call_type == Call::OTHER_CALL);
3201 // Call to an arbitrary expression not handled specially above.
3202 { PreservePositionScope scope(masm()->positions_recorder());
3203 VisitForStackValue(callee);
3205 __ LoadRoot(r1, Heap::kUndefinedValueRootIndex);
3207 // Emit function call.
3212 // RecordJSReturnSite should have been called.
3213 DCHECK(expr->return_is_recorded_);
3218 void FullCodeGenerator::VisitCallNew(CallNew* expr) {
3219 Comment cmnt(masm_, "[ CallNew");
3220 // According to ECMA-262, section 11.2.2, page 44, the function
3221 // expression in new calls must be evaluated before the
3224 // Push constructor on the stack. If it's not a function it's used as
3225 // receiver for CALL_NON_FUNCTION, otherwise the value on the stack is
3227 DCHECK(!expr->expression()->IsSuperReference());
3228 VisitForStackValue(expr->expression());
3230 // Push the arguments ("left-to-right") on the stack.
3231 ZoneList<Expression*>* args = expr->arguments();
3232 int arg_count = args->length();
3233 for (int i = 0; i < arg_count; i++) {
3234 VisitForStackValue(args->at(i));
3237 // Call the construct call builtin that handles allocation and
3238 // constructor invocation.
3239 SetSourcePosition(expr->position());
3241 // Load function and argument count into r1 and r0.
3242 __ mov(r0, Operand(arg_count));
3243 __ ldr(r1, MemOperand(sp, arg_count * kPointerSize));
3245 // Record call targets in unoptimized code.
3246 if (FLAG_pretenuring_call_new) {
3247 EnsureSlotContainsAllocationSite(expr->AllocationSiteFeedbackSlot());
3248 DCHECK(expr->AllocationSiteFeedbackSlot().ToInt() ==
3249 expr->CallNewFeedbackSlot().ToInt() + 1);
3252 __ Move(r2, FeedbackVector());
3253 __ mov(r3, Operand(SmiFromSlot(expr->CallNewFeedbackSlot())));
3255 CallConstructStub stub(isolate(), RECORD_CONSTRUCTOR_TARGET);
3256 __ Call(stub.GetCode(), RelocInfo::CONSTRUCT_CALL);
3257 PrepareForBailoutForId(expr->ReturnId(), TOS_REG);
3258 context()->Plug(r0);
3262 void FullCodeGenerator::EmitSuperConstructorCall(Call* expr) {
3263 if (!ValidateSuperCall(expr)) return;
3264 Variable* new_target_var = scope()->DeclarationScope()->new_target_var();
3265 GetVar(result_register(), new_target_var);
3266 __ Push(result_register());
3268 EmitLoadSuperConstructor();
3269 __ push(result_register());
3271 // Push the arguments ("left-to-right") on the stack.
3272 ZoneList<Expression*>* args = expr->arguments();
3273 int arg_count = args->length();
3274 for (int i = 0; i < arg_count; i++) {
3275 VisitForStackValue(args->at(i));
3278 // Call the construct call builtin that handles allocation and
3279 // constructor invocation.
3280 SetSourcePosition(expr->position());
3282 // Load function and argument count into r1 and r0.
3283 __ mov(r0, Operand(arg_count));
3284 __ ldr(r1, MemOperand(sp, arg_count * kPointerSize));
3286 // Record call targets in unoptimized code.
3287 if (FLAG_pretenuring_call_new) {
3289 /* TODO(dslomov): support pretenuring.
3290 EnsureSlotContainsAllocationSite(expr->AllocationSiteFeedbackSlot());
3291 DCHECK(expr->AllocationSiteFeedbackSlot().ToInt() ==
3292 expr->CallNewFeedbackSlot().ToInt() + 1);
3296 __ Move(r2, FeedbackVector());
3297 __ mov(r3, Operand(SmiFromSlot(expr->CallFeedbackSlot())));
3299 CallConstructStub stub(isolate(), SUPER_CALL_RECORD_TARGET);
3300 __ Call(stub.GetCode(), RelocInfo::CONSTRUCT_CALL);
3304 RecordJSReturnSite(expr);
3306 SuperReference* super_ref = expr->expression()->AsSuperReference();
3307 Variable* this_var = super_ref->this_var()->var();
3308 GetVar(r1, this_var);
3309 __ CompareRoot(r1, Heap::kTheHoleValueRootIndex);
3310 Label uninitialized_this;
3311 __ b(eq, &uninitialized_this);
3312 __ mov(r0, Operand(this_var->name()));
3314 __ CallRuntime(Runtime::kThrowReferenceError, 1);
3315 __ bind(&uninitialized_this);
3317 EmitVariableAssignment(this_var, Token::INIT_CONST);
3318 context()->Plug(r0);
3322 void FullCodeGenerator::EmitIsSmi(CallRuntime* expr) {
3323 ZoneList<Expression*>* args = expr->arguments();
3324 DCHECK(args->length() == 1);
3326 VisitForAccumulatorValue(args->at(0));
3328 Label materialize_true, materialize_false;
3329 Label* if_true = NULL;
3330 Label* if_false = NULL;
3331 Label* fall_through = NULL;
3332 context()->PrepareTest(&materialize_true, &materialize_false,
3333 &if_true, &if_false, &fall_through);
3335 PrepareForBailoutBeforeSplit(expr, true, if_true, if_false);
3337 Split(eq, if_true, if_false, fall_through);
3339 context()->Plug(if_true, if_false);
3343 void FullCodeGenerator::EmitIsNonNegativeSmi(CallRuntime* expr) {
3344 ZoneList<Expression*>* args = expr->arguments();
3345 DCHECK(args->length() == 1);
3347 VisitForAccumulatorValue(args->at(0));
3349 Label materialize_true, materialize_false;
3350 Label* if_true = NULL;
3351 Label* if_false = NULL;
3352 Label* fall_through = NULL;
3353 context()->PrepareTest(&materialize_true, &materialize_false,
3354 &if_true, &if_false, &fall_through);
3356 PrepareForBailoutBeforeSplit(expr, true, if_true, if_false);
3357 __ NonNegativeSmiTst(r0);
3358 Split(eq, if_true, if_false, fall_through);
3360 context()->Plug(if_true, if_false);
3364 void FullCodeGenerator::EmitIsObject(CallRuntime* expr) {
3365 ZoneList<Expression*>* args = expr->arguments();
3366 DCHECK(args->length() == 1);
3368 VisitForAccumulatorValue(args->at(0));
3370 Label materialize_true, materialize_false;
3371 Label* if_true = NULL;
3372 Label* if_false = NULL;
3373 Label* fall_through = NULL;
3374 context()->PrepareTest(&materialize_true, &materialize_false,
3375 &if_true, &if_false, &fall_through);
3377 __ JumpIfSmi(r0, if_false);
3378 __ LoadRoot(ip, Heap::kNullValueRootIndex);
3381 __ ldr(r2, FieldMemOperand(r0, HeapObject::kMapOffset));
3382 // Undetectable objects behave like undefined when tested with typeof.
3383 __ ldrb(r1, FieldMemOperand(r2, Map::kBitFieldOffset));
3384 __ tst(r1, Operand(1 << Map::kIsUndetectable));
3386 __ ldrb(r1, FieldMemOperand(r2, Map::kInstanceTypeOffset));
3387 __ cmp(r1, Operand(FIRST_NONCALLABLE_SPEC_OBJECT_TYPE));
3389 __ cmp(r1, Operand(LAST_NONCALLABLE_SPEC_OBJECT_TYPE));
3390 PrepareForBailoutBeforeSplit(expr, true, if_true, if_false);
3391 Split(le, if_true, if_false, fall_through);
3393 context()->Plug(if_true, if_false);
3397 void FullCodeGenerator::EmitIsSpecObject(CallRuntime* expr) {
3398 ZoneList<Expression*>* args = expr->arguments();
3399 DCHECK(args->length() == 1);
3401 VisitForAccumulatorValue(args->at(0));
3403 Label materialize_true, materialize_false;
3404 Label* if_true = NULL;
3405 Label* if_false = NULL;
3406 Label* fall_through = NULL;
3407 context()->PrepareTest(&materialize_true, &materialize_false,
3408 &if_true, &if_false, &fall_through);
3410 __ JumpIfSmi(r0, if_false);
3411 __ CompareObjectType(r0, r1, r1, FIRST_SPEC_OBJECT_TYPE);
3412 PrepareForBailoutBeforeSplit(expr, true, if_true, if_false);
3413 Split(ge, if_true, if_false, fall_through);
3415 context()->Plug(if_true, if_false);
3419 void FullCodeGenerator::EmitIsUndetectableObject(CallRuntime* expr) {
3420 ZoneList<Expression*>* args = expr->arguments();
3421 DCHECK(args->length() == 1);
3423 VisitForAccumulatorValue(args->at(0));
3425 Label materialize_true, materialize_false;
3426 Label* if_true = NULL;
3427 Label* if_false = NULL;
3428 Label* fall_through = NULL;
3429 context()->PrepareTest(&materialize_true, &materialize_false,
3430 &if_true, &if_false, &fall_through);
3432 __ JumpIfSmi(r0, if_false);
3433 __ ldr(r1, FieldMemOperand(r0, HeapObject::kMapOffset));
3434 __ ldrb(r1, FieldMemOperand(r1, Map::kBitFieldOffset));
3435 __ tst(r1, Operand(1 << Map::kIsUndetectable));
3436 PrepareForBailoutBeforeSplit(expr, true, if_true, if_false);
3437 Split(ne, if_true, if_false, fall_through);
3439 context()->Plug(if_true, if_false);
3443 void FullCodeGenerator::EmitIsStringWrapperSafeForDefaultValueOf(
3444 CallRuntime* expr) {
3445 ZoneList<Expression*>* args = expr->arguments();
3446 DCHECK(args->length() == 1);
3448 VisitForAccumulatorValue(args->at(0));
3450 Label materialize_true, materialize_false, skip_lookup;
3451 Label* if_true = NULL;
3452 Label* if_false = NULL;
3453 Label* fall_through = NULL;
3454 context()->PrepareTest(&materialize_true, &materialize_false,
3455 &if_true, &if_false, &fall_through);
3457 __ AssertNotSmi(r0);
3459 __ ldr(r1, FieldMemOperand(r0, HeapObject::kMapOffset));
3460 __ ldrb(ip, FieldMemOperand(r1, Map::kBitField2Offset));
3461 __ tst(ip, Operand(1 << Map::kStringWrapperSafeForDefaultValueOf));
3462 __ b(ne, &skip_lookup);
3464 // Check for fast case object. Generate false result for slow case object.
3465 __ ldr(r2, FieldMemOperand(r0, JSObject::kPropertiesOffset));
3466 __ ldr(r2, FieldMemOperand(r2, HeapObject::kMapOffset));
3467 __ LoadRoot(ip, Heap::kHashTableMapRootIndex);
3471 // Look for valueOf name in the descriptor array, and indicate false if
3472 // found. Since we omit an enumeration index check, if it is added via a
3473 // transition that shares its descriptor array, this is a false positive.
3474 Label entry, loop, done;
3476 // Skip loop if no descriptors are valid.
3477 __ NumberOfOwnDescriptors(r3, r1);
3478 __ cmp(r3, Operand::Zero());
3481 __ LoadInstanceDescriptors(r1, r4);
3482 // r4: descriptor array.
3483 // r3: valid entries in the descriptor array.
3484 __ mov(ip, Operand(DescriptorArray::kDescriptorSize));
3486 // Calculate location of the first key name.
3487 __ add(r4, r4, Operand(DescriptorArray::kFirstOffset - kHeapObjectTag));
3488 // Calculate the end of the descriptor array.
3490 __ add(r2, r2, Operand(r3, LSL, kPointerSizeLog2));
3492 // Loop through all the keys in the descriptor array. If one of these is the
3493 // string "valueOf" the result is false.
3494 // The use of ip to store the valueOf string assumes that it is not otherwise
3495 // used in the loop below.
3496 __ mov(ip, Operand(isolate()->factory()->value_of_string()));
3499 __ ldr(r3, MemOperand(r4, 0));
3502 __ add(r4, r4, Operand(DescriptorArray::kDescriptorSize * kPointerSize));
3504 __ cmp(r4, Operand(r2));
3509 // Set the bit in the map to indicate that there is no local valueOf field.
3510 __ ldrb(r2, FieldMemOperand(r1, Map::kBitField2Offset));
3511 __ orr(r2, r2, Operand(1 << Map::kStringWrapperSafeForDefaultValueOf));
3512 __ strb(r2, FieldMemOperand(r1, Map::kBitField2Offset));
3514 __ bind(&skip_lookup);
3516 // If a valueOf property is not found on the object check that its
3517 // prototype is the un-modified String prototype. If not result is false.
3518 __ ldr(r2, FieldMemOperand(r1, Map::kPrototypeOffset));
3519 __ JumpIfSmi(r2, if_false);
3520 __ ldr(r2, FieldMemOperand(r2, HeapObject::kMapOffset));
3521 __ ldr(r3, ContextOperand(cp, Context::GLOBAL_OBJECT_INDEX));
3522 __ ldr(r3, FieldMemOperand(r3, GlobalObject::kNativeContextOffset));
3523 __ ldr(r3, ContextOperand(r3, Context::STRING_FUNCTION_PROTOTYPE_MAP_INDEX));
3525 PrepareForBailoutBeforeSplit(expr, true, if_true, if_false);
3526 Split(eq, if_true, if_false, fall_through);
3528 context()->Plug(if_true, if_false);
3532 void FullCodeGenerator::EmitIsFunction(CallRuntime* expr) {
3533 ZoneList<Expression*>* args = expr->arguments();
3534 DCHECK(args->length() == 1);
3536 VisitForAccumulatorValue(args->at(0));
3538 Label materialize_true, materialize_false;
3539 Label* if_true = NULL;
3540 Label* if_false = NULL;
3541 Label* fall_through = NULL;
3542 context()->PrepareTest(&materialize_true, &materialize_false,
3543 &if_true, &if_false, &fall_through);
3545 __ JumpIfSmi(r0, if_false);
3546 __ CompareObjectType(r0, r1, r2, JS_FUNCTION_TYPE);
3547 PrepareForBailoutBeforeSplit(expr, true, if_true, if_false);
3548 Split(eq, if_true, if_false, fall_through);
3550 context()->Plug(if_true, if_false);
3554 void FullCodeGenerator::EmitIsMinusZero(CallRuntime* expr) {
3555 ZoneList<Expression*>* args = expr->arguments();
3556 DCHECK(args->length() == 1);
3558 VisitForAccumulatorValue(args->at(0));
3560 Label materialize_true, materialize_false;
3561 Label* if_true = NULL;
3562 Label* if_false = NULL;
3563 Label* fall_through = NULL;
3564 context()->PrepareTest(&materialize_true, &materialize_false,
3565 &if_true, &if_false, &fall_through);
3567 __ CheckMap(r0, r1, Heap::kHeapNumberMapRootIndex, if_false, DO_SMI_CHECK);
3568 __ ldr(r2, FieldMemOperand(r0, HeapNumber::kExponentOffset));
3569 __ ldr(r1, FieldMemOperand(r0, HeapNumber::kMantissaOffset));
3570 __ cmp(r2, Operand(0x80000000));
3571 __ cmp(r1, Operand(0x00000000), eq);
3573 PrepareForBailoutBeforeSplit(expr, true, if_true, if_false);
3574 Split(eq, if_true, if_false, fall_through);
3576 context()->Plug(if_true, if_false);
3580 void FullCodeGenerator::EmitIsArray(CallRuntime* expr) {
3581 ZoneList<Expression*>* args = expr->arguments();
3582 DCHECK(args->length() == 1);
3584 VisitForAccumulatorValue(args->at(0));
3586 Label materialize_true, materialize_false;
3587 Label* if_true = NULL;
3588 Label* if_false = NULL;
3589 Label* fall_through = NULL;
3590 context()->PrepareTest(&materialize_true, &materialize_false,
3591 &if_true, &if_false, &fall_through);
3593 __ JumpIfSmi(r0, if_false);
3594 __ CompareObjectType(r0, r1, r1, JS_ARRAY_TYPE);
3595 PrepareForBailoutBeforeSplit(expr, true, if_true, if_false);
3596 Split(eq, if_true, if_false, fall_through);
3598 context()->Plug(if_true, if_false);
3602 void FullCodeGenerator::EmitIsRegExp(CallRuntime* expr) {
3603 ZoneList<Expression*>* args = expr->arguments();
3604 DCHECK(args->length() == 1);
3606 VisitForAccumulatorValue(args->at(0));
3608 Label materialize_true, materialize_false;
3609 Label* if_true = NULL;
3610 Label* if_false = NULL;
3611 Label* fall_through = NULL;
3612 context()->PrepareTest(&materialize_true, &materialize_false,
3613 &if_true, &if_false, &fall_through);
3615 __ JumpIfSmi(r0, if_false);
3616 __ CompareObjectType(r0, r1, r1, JS_REGEXP_TYPE);
3617 PrepareForBailoutBeforeSplit(expr, true, if_true, if_false);
3618 Split(eq, if_true, if_false, fall_through);
3620 context()->Plug(if_true, if_false);
3624 void FullCodeGenerator::EmitIsJSProxy(CallRuntime* expr) {
3625 ZoneList<Expression*>* args = expr->arguments();
3626 DCHECK(args->length() == 1);
3628 VisitForAccumulatorValue(args->at(0));
3630 Label materialize_true, materialize_false;
3631 Label* if_true = NULL;
3632 Label* if_false = NULL;
3633 Label* fall_through = NULL;
3634 context()->PrepareTest(&materialize_true, &materialize_false, &if_true,
3635 &if_false, &fall_through);
3637 __ JumpIfSmi(r0, if_false);
3639 Register type_reg = r2;
3640 __ ldr(map, FieldMemOperand(r0, HeapObject::kMapOffset));
3641 __ ldrb(type_reg, FieldMemOperand(map, Map::kInstanceTypeOffset));
3642 __ sub(type_reg, type_reg, Operand(FIRST_JS_PROXY_TYPE));
3643 __ cmp(type_reg, Operand(LAST_JS_PROXY_TYPE - FIRST_JS_PROXY_TYPE));
3644 PrepareForBailoutBeforeSplit(expr, true, if_true, if_false);
3645 Split(ls, if_true, if_false, fall_through);
3647 context()->Plug(if_true, if_false);
3651 void FullCodeGenerator::EmitIsConstructCall(CallRuntime* expr) {
3652 DCHECK(expr->arguments()->length() == 0);
3654 Label materialize_true, materialize_false;
3655 Label* if_true = NULL;
3656 Label* if_false = NULL;
3657 Label* fall_through = NULL;
3658 context()->PrepareTest(&materialize_true, &materialize_false,
3659 &if_true, &if_false, &fall_through);
3661 // Get the frame pointer for the calling frame.
3662 __ ldr(r2, MemOperand(fp, StandardFrameConstants::kCallerFPOffset));
3664 // Skip the arguments adaptor frame if it exists.
3665 __ ldr(r1, MemOperand(r2, StandardFrameConstants::kContextOffset));
3666 __ cmp(r1, Operand(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR)));
3667 __ ldr(r2, MemOperand(r2, StandardFrameConstants::kCallerFPOffset), eq);
3669 // Check the marker in the calling frame.
3670 __ ldr(r1, MemOperand(r2, StandardFrameConstants::kMarkerOffset));
3671 __ cmp(r1, Operand(Smi::FromInt(StackFrame::CONSTRUCT)));
3672 PrepareForBailoutBeforeSplit(expr, true, if_true, if_false);
3673 Split(eq, if_true, if_false, fall_through);
3675 context()->Plug(if_true, if_false);
3679 void FullCodeGenerator::EmitObjectEquals(CallRuntime* expr) {
3680 ZoneList<Expression*>* args = expr->arguments();
3681 DCHECK(args->length() == 2);
3683 // Load the two objects into registers and perform the comparison.
3684 VisitForStackValue(args->at(0));
3685 VisitForAccumulatorValue(args->at(1));
3687 Label materialize_true, materialize_false;
3688 Label* if_true = NULL;
3689 Label* if_false = NULL;
3690 Label* fall_through = NULL;
3691 context()->PrepareTest(&materialize_true, &materialize_false,
3692 &if_true, &if_false, &fall_through);
3696 PrepareForBailoutBeforeSplit(expr, true, if_true, if_false);
3697 Split(eq, if_true, if_false, fall_through);
3699 context()->Plug(if_true, if_false);
3703 void FullCodeGenerator::EmitArguments(CallRuntime* expr) {
3704 ZoneList<Expression*>* args = expr->arguments();
3705 DCHECK(args->length() == 1);
3707 // ArgumentsAccessStub expects the key in edx and the formal
3708 // parameter count in r0.
3709 VisitForAccumulatorValue(args->at(0));
3711 __ mov(r0, Operand(Smi::FromInt(info_->scope()->num_parameters())));
3712 ArgumentsAccessStub stub(isolate(), ArgumentsAccessStub::READ_ELEMENT);
3714 context()->Plug(r0);
3718 void FullCodeGenerator::EmitArgumentsLength(CallRuntime* expr) {
3719 DCHECK(expr->arguments()->length() == 0);
3721 // Get the number of formal parameters.
3722 __ mov(r0, Operand(Smi::FromInt(info_->scope()->num_parameters())));
3724 // Check if the calling frame is an arguments adaptor frame.
3725 __ ldr(r2, MemOperand(fp, StandardFrameConstants::kCallerFPOffset));
3726 __ ldr(r3, MemOperand(r2, StandardFrameConstants::kContextOffset));
3727 __ cmp(r3, Operand(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR)));
3729 // Arguments adaptor case: Read the arguments length from the
3731 __ ldr(r0, MemOperand(r2, ArgumentsAdaptorFrameConstants::kLengthOffset), eq);
3733 context()->Plug(r0);
3737 void FullCodeGenerator::EmitClassOf(CallRuntime* expr) {
3738 ZoneList<Expression*>* args = expr->arguments();
3739 DCHECK(args->length() == 1);
3740 Label done, null, function, non_function_constructor;
3742 VisitForAccumulatorValue(args->at(0));
3744 // If the object is a smi, we return null.
3745 __ JumpIfSmi(r0, &null);
3747 // Check that the object is a JS object but take special care of JS
3748 // functions to make sure they have 'Function' as their class.
3749 // Assume that there are only two callable types, and one of them is at
3750 // either end of the type range for JS object types. Saves extra comparisons.
3751 STATIC_ASSERT(NUM_OF_CALLABLE_SPEC_OBJECT_TYPES == 2);
3752 __ CompareObjectType(r0, r0, r1, FIRST_SPEC_OBJECT_TYPE);
3753 // Map is now in r0.
3755 STATIC_ASSERT(FIRST_NONCALLABLE_SPEC_OBJECT_TYPE ==
3756 FIRST_SPEC_OBJECT_TYPE + 1);
3757 __ b(eq, &function);
3759 __ cmp(r1, Operand(LAST_SPEC_OBJECT_TYPE));
3760 STATIC_ASSERT(LAST_NONCALLABLE_SPEC_OBJECT_TYPE ==
3761 LAST_SPEC_OBJECT_TYPE - 1);
3762 __ b(eq, &function);
3763 // Assume that there is no larger type.
3764 STATIC_ASSERT(LAST_NONCALLABLE_SPEC_OBJECT_TYPE == LAST_TYPE - 1);
3766 // Check if the constructor in the map is a JS function.
3767 __ ldr(r0, FieldMemOperand(r0, Map::kConstructorOffset));
3768 __ CompareObjectType(r0, r1, r1, JS_FUNCTION_TYPE);
3769 __ b(ne, &non_function_constructor);
3771 // r0 now contains the constructor function. Grab the
3772 // instance class name from there.
3773 __ ldr(r0, FieldMemOperand(r0, JSFunction::kSharedFunctionInfoOffset));
3774 __ ldr(r0, FieldMemOperand(r0, SharedFunctionInfo::kInstanceClassNameOffset));
3777 // Functions have class 'Function'.
3779 __ LoadRoot(r0, Heap::kFunction_stringRootIndex);
3782 // Objects with a non-function constructor have class 'Object'.
3783 __ bind(&non_function_constructor);
3784 __ LoadRoot(r0, Heap::kObject_stringRootIndex);
3787 // Non-JS objects have class null.
3789 __ LoadRoot(r0, Heap::kNullValueRootIndex);
3794 context()->Plug(r0);
3798 void FullCodeGenerator::EmitSubString(CallRuntime* expr) {
3799 // Load the arguments on the stack and call the stub.
3800 SubStringStub stub(isolate());
3801 ZoneList<Expression*>* args = expr->arguments();
3802 DCHECK(args->length() == 3);
3803 VisitForStackValue(args->at(0));
3804 VisitForStackValue(args->at(1));
3805 VisitForStackValue(args->at(2));
3807 context()->Plug(r0);
3811 void FullCodeGenerator::EmitRegExpExec(CallRuntime* expr) {
3812 // Load the arguments on the stack and call the stub.
3813 RegExpExecStub stub(isolate());
3814 ZoneList<Expression*>* args = expr->arguments();
3815 DCHECK(args->length() == 4);
3816 VisitForStackValue(args->at(0));
3817 VisitForStackValue(args->at(1));
3818 VisitForStackValue(args->at(2));
3819 VisitForStackValue(args->at(3));
3821 context()->Plug(r0);
3825 void FullCodeGenerator::EmitValueOf(CallRuntime* expr) {
3826 ZoneList<Expression*>* args = expr->arguments();
3827 DCHECK(args->length() == 1);
3828 VisitForAccumulatorValue(args->at(0)); // Load the object.
3831 // If the object is a smi return the object.
3832 __ JumpIfSmi(r0, &done);
3833 // If the object is not a value type, return the object.
3834 __ CompareObjectType(r0, r1, r1, JS_VALUE_TYPE);
3835 __ ldr(r0, FieldMemOperand(r0, JSValue::kValueOffset), eq);
3838 context()->Plug(r0);
3842 void FullCodeGenerator::EmitDateField(CallRuntime* expr) {
3843 ZoneList<Expression*>* args = expr->arguments();
3844 DCHECK(args->length() == 2);
3845 DCHECK_NOT_NULL(args->at(1)->AsLiteral());
3846 Smi* index = Smi::cast(*(args->at(1)->AsLiteral()->value()));
3848 VisitForAccumulatorValue(args->at(0)); // Load the object.
3850 Label runtime, done, not_date_object;
3851 Register object = r0;
3852 Register result = r0;
3853 Register scratch0 = r9;
3854 Register scratch1 = r1;
3856 __ JumpIfSmi(object, ¬_date_object);
3857 __ CompareObjectType(object, scratch1, scratch1, JS_DATE_TYPE);
3858 __ b(ne, ¬_date_object);
3860 if (index->value() == 0) {
3861 __ ldr(result, FieldMemOperand(object, JSDate::kValueOffset));
3864 if (index->value() < JSDate::kFirstUncachedField) {
3865 ExternalReference stamp = ExternalReference::date_cache_stamp(isolate());
3866 __ mov(scratch1, Operand(stamp));
3867 __ ldr(scratch1, MemOperand(scratch1));
3868 __ ldr(scratch0, FieldMemOperand(object, JSDate::kCacheStampOffset));
3869 __ cmp(scratch1, scratch0);
3871 __ ldr(result, FieldMemOperand(object, JSDate::kValueOffset +
3872 kPointerSize * index->value()));
3876 __ PrepareCallCFunction(2, scratch1);
3877 __ mov(r1, Operand(index));
3878 __ CallCFunction(ExternalReference::get_date_field_function(isolate()), 2);
3882 __ bind(¬_date_object);
3883 __ CallRuntime(Runtime::kThrowNotDateError, 0);
3885 context()->Plug(r0);
3889 void FullCodeGenerator::EmitOneByteSeqStringSetChar(CallRuntime* expr) {
3890 ZoneList<Expression*>* args = expr->arguments();
3891 DCHECK_EQ(3, args->length());
3893 Register string = r0;
3894 Register index = r1;
3895 Register value = r2;
3897 VisitForStackValue(args->at(0)); // index
3898 VisitForStackValue(args->at(1)); // value
3899 VisitForAccumulatorValue(args->at(2)); // string
3900 __ Pop(index, value);
3902 if (FLAG_debug_code) {
3904 __ Check(eq, kNonSmiValue);
3906 __ Check(eq, kNonSmiIndex);
3907 __ SmiUntag(index, index);
3908 static const uint32_t one_byte_seq_type = kSeqStringTag | kOneByteStringTag;
3909 __ EmitSeqStringSetCharCheck(string, index, value, one_byte_seq_type);
3910 __ SmiTag(index, index);
3913 __ SmiUntag(value, value);
3916 Operand(SeqOneByteString::kHeaderSize - kHeapObjectTag));
3917 __ strb(value, MemOperand(ip, index, LSR, kSmiTagSize));
3918 context()->Plug(string);
3922 void FullCodeGenerator::EmitTwoByteSeqStringSetChar(CallRuntime* expr) {
3923 ZoneList<Expression*>* args = expr->arguments();
3924 DCHECK_EQ(3, args->length());
3926 Register string = r0;
3927 Register index = r1;
3928 Register value = r2;
3930 VisitForStackValue(args->at(0)); // index
3931 VisitForStackValue(args->at(1)); // value
3932 VisitForAccumulatorValue(args->at(2)); // string
3933 __ Pop(index, value);
3935 if (FLAG_debug_code) {
3937 __ Check(eq, kNonSmiValue);
3939 __ Check(eq, kNonSmiIndex);
3940 __ SmiUntag(index, index);
3941 static const uint32_t two_byte_seq_type = kSeqStringTag | kTwoByteStringTag;
3942 __ EmitSeqStringSetCharCheck(string, index, value, two_byte_seq_type);
3943 __ SmiTag(index, index);
3946 __ SmiUntag(value, value);
3949 Operand(SeqTwoByteString::kHeaderSize - kHeapObjectTag));
3950 STATIC_ASSERT(kSmiTagSize == 1 && kSmiTag == 0);
3951 __ strh(value, MemOperand(ip, index));
3952 context()->Plug(string);
3957 void FullCodeGenerator::EmitMathPow(CallRuntime* expr) {
3958 // Load the arguments on the stack and call the runtime function.
3959 ZoneList<Expression*>* args = expr->arguments();
3960 DCHECK(args->length() == 2);
3961 VisitForStackValue(args->at(0));
3962 VisitForStackValue(args->at(1));
3963 MathPowStub stub(isolate(), MathPowStub::ON_STACK);
3965 context()->Plug(r0);
3969 void FullCodeGenerator::EmitSetValueOf(CallRuntime* expr) {
3970 ZoneList<Expression*>* args = expr->arguments();
3971 DCHECK(args->length() == 2);
3972 VisitForStackValue(args->at(0)); // Load the object.
3973 VisitForAccumulatorValue(args->at(1)); // Load the value.
3974 __ pop(r1); // r0 = value. r1 = object.
3977 // If the object is a smi, return the value.
3978 __ JumpIfSmi(r1, &done);
3980 // If the object is not a value type, return the value.
3981 __ CompareObjectType(r1, r2, r2, JS_VALUE_TYPE);
3985 __ str(r0, FieldMemOperand(r1, JSValue::kValueOffset));
3986 // Update the write barrier. Save the value as it will be
3987 // overwritten by the write barrier code and is needed afterward.
3989 __ RecordWriteField(
3990 r1, JSValue::kValueOffset, r2, r3, kLRHasBeenSaved, kDontSaveFPRegs);
3993 context()->Plug(r0);
3997 void FullCodeGenerator::EmitNumberToString(CallRuntime* expr) {
3998 ZoneList<Expression*>* args = expr->arguments();
3999 DCHECK_EQ(args->length(), 1);
4000 // Load the argument into r0 and call the stub.
4001 VisitForAccumulatorValue(args->at(0));
4003 NumberToStringStub stub(isolate());
4005 context()->Plug(r0);
4009 void FullCodeGenerator::EmitStringCharFromCode(CallRuntime* expr) {
4010 ZoneList<Expression*>* args = expr->arguments();
4011 DCHECK(args->length() == 1);
4012 VisitForAccumulatorValue(args->at(0));
4015 StringCharFromCodeGenerator generator(r0, r1);
4016 generator.GenerateFast(masm_);
4019 NopRuntimeCallHelper call_helper;
4020 generator.GenerateSlow(masm_, call_helper);
4023 context()->Plug(r1);
4027 void FullCodeGenerator::EmitStringCharCodeAt(CallRuntime* expr) {
4028 ZoneList<Expression*>* args = expr->arguments();
4029 DCHECK(args->length() == 2);
4030 VisitForStackValue(args->at(0));
4031 VisitForAccumulatorValue(args->at(1));
4033 Register object = r1;
4034 Register index = r0;
4035 Register result = r3;
4039 Label need_conversion;
4040 Label index_out_of_range;
4042 StringCharCodeAtGenerator generator(object,
4047 &index_out_of_range,
4048 STRING_INDEX_IS_NUMBER);
4049 generator.GenerateFast(masm_);
4052 __ bind(&index_out_of_range);
4053 // When the index is out of range, the spec requires us to return
4055 __ LoadRoot(result, Heap::kNanValueRootIndex);
4058 __ bind(&need_conversion);
4059 // Load the undefined value into the result register, which will
4060 // trigger conversion.
4061 __ LoadRoot(result, Heap::kUndefinedValueRootIndex);
4064 NopRuntimeCallHelper call_helper;
4065 generator.GenerateSlow(masm_, call_helper);
4068 context()->Plug(result);
4072 void FullCodeGenerator::EmitStringCharAt(CallRuntime* expr) {
4073 ZoneList<Expression*>* args = expr->arguments();
4074 DCHECK(args->length() == 2);
4075 VisitForStackValue(args->at(0));
4076 VisitForAccumulatorValue(args->at(1));
4078 Register object = r1;
4079 Register index = r0;
4080 Register scratch = r3;
4081 Register result = r0;
4085 Label need_conversion;
4086 Label index_out_of_range;
4088 StringCharAtGenerator generator(object,
4094 &index_out_of_range,
4095 STRING_INDEX_IS_NUMBER);
4096 generator.GenerateFast(masm_);
4099 __ bind(&index_out_of_range);
4100 // When the index is out of range, the spec requires us to return
4101 // the empty string.
4102 __ LoadRoot(result, Heap::kempty_stringRootIndex);
4105 __ bind(&need_conversion);
4106 // Move smi zero into the result register, which will trigger
4108 __ mov(result, Operand(Smi::FromInt(0)));
4111 NopRuntimeCallHelper call_helper;
4112 generator.GenerateSlow(masm_, call_helper);
4115 context()->Plug(result);
4119 void FullCodeGenerator::EmitStringAdd(CallRuntime* expr) {
4120 ZoneList<Expression*>* args = expr->arguments();
4121 DCHECK_EQ(2, args->length());
4122 VisitForStackValue(args->at(0));
4123 VisitForAccumulatorValue(args->at(1));
4126 StringAddStub stub(isolate(), STRING_ADD_CHECK_BOTH, NOT_TENURED);
4128 context()->Plug(r0);
4132 void FullCodeGenerator::EmitStringCompare(CallRuntime* expr) {
4133 ZoneList<Expression*>* args = expr->arguments();
4134 DCHECK_EQ(2, args->length());
4135 VisitForStackValue(args->at(0));
4136 VisitForStackValue(args->at(1));
4138 StringCompareStub stub(isolate());
4140 context()->Plug(r0);
4144 void FullCodeGenerator::EmitCallFunction(CallRuntime* expr) {
4145 ZoneList<Expression*>* args = expr->arguments();
4146 DCHECK(args->length() >= 2);
4148 int arg_count = args->length() - 2; // 2 ~ receiver and function.
4149 for (int i = 0; i < arg_count + 1; i++) {
4150 VisitForStackValue(args->at(i));
4152 VisitForAccumulatorValue(args->last()); // Function.
4154 Label runtime, done;
4155 // Check for non-function argument (including proxy).
4156 __ JumpIfSmi(r0, &runtime);
4157 __ CompareObjectType(r0, r1, r1, JS_FUNCTION_TYPE);
4160 // InvokeFunction requires the function in r1. Move it in there.
4161 __ mov(r1, result_register());
4162 ParameterCount count(arg_count);
4163 __ InvokeFunction(r1, count, CALL_FUNCTION, NullCallWrapper());
4164 __ ldr(cp, MemOperand(fp, StandardFrameConstants::kContextOffset));
4169 __ CallRuntime(Runtime::kCall, args->length());
4172 context()->Plug(r0);
4176 void FullCodeGenerator::EmitDefaultConstructorCallSuper(CallRuntime* expr) {
4177 Variable* new_target_var = scope()->DeclarationScope()->new_target_var();
4178 GetVar(result_register(), new_target_var);
4179 __ Push(result_register());
4181 EmitLoadSuperConstructor();
4182 __ Push(result_register());
4184 // Check if the calling frame is an arguments adaptor frame.
4185 Label adaptor_frame, args_set_up, runtime;
4186 __ ldr(r2, MemOperand(fp, StandardFrameConstants::kCallerFPOffset));
4187 __ ldr(r3, MemOperand(r2, StandardFrameConstants::kContextOffset));
4188 __ cmp(r3, Operand(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR)));
4189 __ b(eq, &adaptor_frame);
4190 // default constructor has no arguments, so no adaptor frame means no args.
4191 __ mov(r0, Operand::Zero());
4194 // Copy arguments from adaptor frame.
4196 __ bind(&adaptor_frame);
4197 __ ldr(r1, MemOperand(r2, ArgumentsAdaptorFrameConstants::kLengthOffset));
4198 __ SmiUntag(r1, r1);
4200 // Subtract 1 from arguments count, for new.target.
4201 __ sub(r1, r1, Operand(1));
4204 // Get arguments pointer in r2.
4205 __ add(r2, r2, Operand(r1, LSL, kPointerSizeLog2));
4206 __ add(r2, r2, Operand(StandardFrameConstants::kCallerSPOffset));
4209 // Pre-decrement r2 with kPointerSize on each iteration.
4210 // Pre-decrement in order to skip receiver.
4211 __ ldr(r3, MemOperand(r2, kPointerSize, NegPreIndex));
4213 __ sub(r1, r1, Operand(1));
4214 __ cmp(r1, Operand::Zero());
4218 __ bind(&args_set_up);
4219 __ ldr(r1, MemOperand(sp, r0, LSL, kPointerSizeLog2));
4220 __ LoadRoot(r2, Heap::kUndefinedValueRootIndex);
4222 CallConstructStub stub(isolate(), SUPER_CONSTRUCTOR_CALL);
4223 __ Call(stub.GetCode(), RelocInfo::CONSTRUCT_CALL);
4227 context()->Plug(result_register());
4231 void FullCodeGenerator::EmitRegExpConstructResult(CallRuntime* expr) {
4232 RegExpConstructResultStub stub(isolate());
4233 ZoneList<Expression*>* args = expr->arguments();
4234 DCHECK(args->length() == 3);
4235 VisitForStackValue(args->at(0));
4236 VisitForStackValue(args->at(1));
4237 VisitForAccumulatorValue(args->at(2));
4241 context()->Plug(r0);
4245 void FullCodeGenerator::EmitGetFromCache(CallRuntime* expr) {
4246 ZoneList<Expression*>* args = expr->arguments();
4247 DCHECK_EQ(2, args->length());
4248 DCHECK_NOT_NULL(args->at(0)->AsLiteral());
4249 int cache_id = Smi::cast(*(args->at(0)->AsLiteral()->value()))->value();
4251 Handle<FixedArray> jsfunction_result_caches(
4252 isolate()->native_context()->jsfunction_result_caches());
4253 if (jsfunction_result_caches->length() <= cache_id) {
4254 __ Abort(kAttemptToUseUndefinedCache);
4255 __ LoadRoot(r0, Heap::kUndefinedValueRootIndex);
4256 context()->Plug(r0);
4260 VisitForAccumulatorValue(args->at(1));
4263 Register cache = r1;
4264 __ ldr(cache, ContextOperand(cp, Context::GLOBAL_OBJECT_INDEX));
4265 __ ldr(cache, FieldMemOperand(cache, GlobalObject::kNativeContextOffset));
4266 __ ldr(cache, ContextOperand(cache, Context::JSFUNCTION_RESULT_CACHES_INDEX));
4268 FieldMemOperand(cache, FixedArray::OffsetOfElementAt(cache_id)));
4271 Label done, not_found;
4272 __ ldr(r2, FieldMemOperand(cache, JSFunctionResultCache::kFingerOffset));
4273 // r2 now holds finger offset as a smi.
4274 __ add(r3, cache, Operand(FixedArray::kHeaderSize - kHeapObjectTag));
4275 // r3 now points to the start of fixed array elements.
4276 __ ldr(r2, MemOperand::PointerAddressFromSmiKey(r3, r2, PreIndex));
4277 // Note side effect of PreIndex: r3 now points to the key of the pair.
4279 __ b(ne, ¬_found);
4281 __ ldr(r0, MemOperand(r3, kPointerSize));
4284 __ bind(¬_found);
4285 // Call runtime to perform the lookup.
4286 __ Push(cache, key);
4287 __ CallRuntime(Runtime::kGetFromCache, 2);
4290 context()->Plug(r0);
4294 void FullCodeGenerator::EmitHasCachedArrayIndex(CallRuntime* expr) {
4295 ZoneList<Expression*>* args = expr->arguments();
4296 VisitForAccumulatorValue(args->at(0));
4298 Label materialize_true, materialize_false;
4299 Label* if_true = NULL;
4300 Label* if_false = NULL;
4301 Label* fall_through = NULL;
4302 context()->PrepareTest(&materialize_true, &materialize_false,
4303 &if_true, &if_false, &fall_through);
4305 __ ldr(r0, FieldMemOperand(r0, String::kHashFieldOffset));
4306 __ tst(r0, Operand(String::kContainsCachedArrayIndexMask));
4307 PrepareForBailoutBeforeSplit(expr, true, if_true, if_false);
4308 Split(eq, if_true, if_false, fall_through);
4310 context()->Plug(if_true, if_false);
4314 void FullCodeGenerator::EmitGetCachedArrayIndex(CallRuntime* expr) {
4315 ZoneList<Expression*>* args = expr->arguments();
4316 DCHECK(args->length() == 1);
4317 VisitForAccumulatorValue(args->at(0));
4319 __ AssertString(r0);
4321 __ ldr(r0, FieldMemOperand(r0, String::kHashFieldOffset));
4322 __ IndexFromHash(r0, r0);
4324 context()->Plug(r0);
4328 void FullCodeGenerator::EmitFastOneByteArrayJoin(CallRuntime* expr) {
4329 Label bailout, done, one_char_separator, long_separator, non_trivial_array,
4330 not_size_one_array, loop, empty_separator_loop, one_char_separator_loop,
4331 one_char_separator_loop_entry, long_separator_loop;
4332 ZoneList<Expression*>* args = expr->arguments();
4333 DCHECK(args->length() == 2);
4334 VisitForStackValue(args->at(1));
4335 VisitForAccumulatorValue(args->at(0));
4337 // All aliases of the same register have disjoint lifetimes.
4338 Register array = r0;
4339 Register elements = no_reg; // Will be r0.
4340 Register result = no_reg; // Will be r0.
4341 Register separator = r1;
4342 Register array_length = r2;
4343 Register result_pos = no_reg; // Will be r2
4344 Register string_length = r3;
4345 Register string = r4;
4346 Register element = r5;
4347 Register elements_end = r6;
4348 Register scratch = r9;
4350 // Separator operand is on the stack.
4353 // Check that the array is a JSArray.
4354 __ JumpIfSmi(array, &bailout);
4355 __ CompareObjectType(array, scratch, array_length, JS_ARRAY_TYPE);
4358 // Check that the array has fast elements.
4359 __ CheckFastElements(scratch, array_length, &bailout);
4361 // If the array has length zero, return the empty string.
4362 __ ldr(array_length, FieldMemOperand(array, JSArray::kLengthOffset));
4363 __ SmiUntag(array_length, SetCC);
4364 __ b(ne, &non_trivial_array);
4365 __ LoadRoot(r0, Heap::kempty_stringRootIndex);
4368 __ bind(&non_trivial_array);
4370 // Get the FixedArray containing array's elements.
4372 __ ldr(elements, FieldMemOperand(array, JSArray::kElementsOffset));
4373 array = no_reg; // End of array's live range.
4375 // Check that all array elements are sequential one-byte strings, and
4376 // accumulate the sum of their lengths, as a smi-encoded value.
4377 __ mov(string_length, Operand::Zero());
4379 elements, Operand(FixedArray::kHeaderSize - kHeapObjectTag));
4380 __ add(elements_end, element, Operand(array_length, LSL, kPointerSizeLog2));
4381 // Loop condition: while (element < elements_end).
4382 // Live values in registers:
4383 // elements: Fixed array of strings.
4384 // array_length: Length of the fixed array of strings (not smi)
4385 // separator: Separator string
4386 // string_length: Accumulated sum of string lengths (smi).
4387 // element: Current array element.
4388 // elements_end: Array end.
4389 if (generate_debug_code_) {
4390 __ cmp(array_length, Operand::Zero());
4391 __ Assert(gt, kNoEmptyArraysHereInEmitFastOneByteArrayJoin);
4394 __ ldr(string, MemOperand(element, kPointerSize, PostIndex));
4395 __ JumpIfSmi(string, &bailout);
4396 __ ldr(scratch, FieldMemOperand(string, HeapObject::kMapOffset));
4397 __ ldrb(scratch, FieldMemOperand(scratch, Map::kInstanceTypeOffset));
4398 __ JumpIfInstanceTypeIsNotSequentialOneByte(scratch, scratch, &bailout);
4399 __ ldr(scratch, FieldMemOperand(string, SeqOneByteString::kLengthOffset));
4400 __ add(string_length, string_length, Operand(scratch), SetCC);
4402 __ cmp(element, elements_end);
4405 // If array_length is 1, return elements[0], a string.
4406 __ cmp(array_length, Operand(1));
4407 __ b(ne, ¬_size_one_array);
4408 __ ldr(r0, FieldMemOperand(elements, FixedArray::kHeaderSize));
4411 __ bind(¬_size_one_array);
4413 // Live values in registers:
4414 // separator: Separator string
4415 // array_length: Length of the array.
4416 // string_length: Sum of string lengths (smi).
4417 // elements: FixedArray of strings.
4419 // Check that the separator is a flat one-byte string.
4420 __ JumpIfSmi(separator, &bailout);
4421 __ ldr(scratch, FieldMemOperand(separator, HeapObject::kMapOffset));
4422 __ ldrb(scratch, FieldMemOperand(scratch, Map::kInstanceTypeOffset));
4423 __ JumpIfInstanceTypeIsNotSequentialOneByte(scratch, scratch, &bailout);
4425 // Add (separator length times array_length) - separator length to the
4426 // string_length to get the length of the result string. array_length is not
4427 // smi but the other values are, so the result is a smi
4428 __ ldr(scratch, FieldMemOperand(separator, SeqOneByteString::kLengthOffset));
4429 __ sub(string_length, string_length, Operand(scratch));
4430 __ smull(scratch, ip, array_length, scratch);
4431 // Check for smi overflow. No overflow if higher 33 bits of 64-bit result are
4433 __ cmp(ip, Operand::Zero());
4435 __ tst(scratch, Operand(0x80000000));
4437 __ add(string_length, string_length, Operand(scratch), SetCC);
4439 __ SmiUntag(string_length);
4441 // Get first element in the array to free up the elements register to be used
4444 elements, Operand(FixedArray::kHeaderSize - kHeapObjectTag));
4445 result = elements; // End of live range for elements.
4447 // Live values in registers:
4448 // element: First array element
4449 // separator: Separator string
4450 // string_length: Length of result string (not smi)
4451 // array_length: Length of the array.
4452 __ AllocateOneByteString(result, string_length, scratch,
4453 string, // used as scratch
4454 elements_end, // used as scratch
4456 // Prepare for looping. Set up elements_end to end of the array. Set
4457 // result_pos to the position of the result where to write the first
4459 __ add(elements_end, element, Operand(array_length, LSL, kPointerSizeLog2));
4460 result_pos = array_length; // End of live range for array_length.
4461 array_length = no_reg;
4464 Operand(SeqOneByteString::kHeaderSize - kHeapObjectTag));
4466 // Check the length of the separator.
4467 __ ldr(scratch, FieldMemOperand(separator, SeqOneByteString::kLengthOffset));
4468 __ cmp(scratch, Operand(Smi::FromInt(1)));
4469 __ b(eq, &one_char_separator);
4470 __ b(gt, &long_separator);
4472 // Empty separator case
4473 __ bind(&empty_separator_loop);
4474 // Live values in registers:
4475 // result_pos: the position to which we are currently copying characters.
4476 // element: Current array element.
4477 // elements_end: Array end.
4479 // Copy next array element to the result.
4480 __ ldr(string, MemOperand(element, kPointerSize, PostIndex));
4481 __ ldr(string_length, FieldMemOperand(string, String::kLengthOffset));
4482 __ SmiUntag(string_length);
4485 Operand(SeqOneByteString::kHeaderSize - kHeapObjectTag));
4486 __ CopyBytes(string, result_pos, string_length, scratch);
4487 __ cmp(element, elements_end);
4488 __ b(lt, &empty_separator_loop); // End while (element < elements_end).
4489 DCHECK(result.is(r0));
4492 // One-character separator case
4493 __ bind(&one_char_separator);
4494 // Replace separator with its one-byte character value.
4495 __ ldrb(separator, FieldMemOperand(separator, SeqOneByteString::kHeaderSize));
4496 // Jump into the loop after the code that copies the separator, so the first
4497 // element is not preceded by a separator
4498 __ jmp(&one_char_separator_loop_entry);
4500 __ bind(&one_char_separator_loop);
4501 // Live values in registers:
4502 // result_pos: the position to which we are currently copying characters.
4503 // element: Current array element.
4504 // elements_end: Array end.
4505 // separator: Single separator one-byte char (in lower byte).
4507 // Copy the separator character to the result.
4508 __ strb(separator, MemOperand(result_pos, 1, PostIndex));
4510 // Copy next array element to the result.
4511 __ bind(&one_char_separator_loop_entry);
4512 __ ldr(string, MemOperand(element, kPointerSize, PostIndex));
4513 __ ldr(string_length, FieldMemOperand(string, String::kLengthOffset));
4514 __ SmiUntag(string_length);
4517 Operand(SeqOneByteString::kHeaderSize - kHeapObjectTag));
4518 __ CopyBytes(string, result_pos, string_length, scratch);
4519 __ cmp(element, elements_end);
4520 __ b(lt, &one_char_separator_loop); // End while (element < elements_end).
4521 DCHECK(result.is(r0));
4524 // Long separator case (separator is more than one character). Entry is at the
4525 // label long_separator below.
4526 __ bind(&long_separator_loop);
4527 // Live values in registers:
4528 // result_pos: the position to which we are currently copying characters.
4529 // element: Current array element.
4530 // elements_end: Array end.
4531 // separator: Separator string.
4533 // Copy the separator to the result.
4534 __ ldr(string_length, FieldMemOperand(separator, String::kLengthOffset));
4535 __ SmiUntag(string_length);
4538 Operand(SeqOneByteString::kHeaderSize - kHeapObjectTag));
4539 __ CopyBytes(string, result_pos, string_length, scratch);
4541 __ bind(&long_separator);
4542 __ ldr(string, MemOperand(element, kPointerSize, PostIndex));
4543 __ ldr(string_length, FieldMemOperand(string, String::kLengthOffset));
4544 __ SmiUntag(string_length);
4547 Operand(SeqOneByteString::kHeaderSize - kHeapObjectTag));
4548 __ CopyBytes(string, result_pos, string_length, scratch);
4549 __ cmp(element, elements_end);
4550 __ b(lt, &long_separator_loop); // End while (element < elements_end).
4551 DCHECK(result.is(r0));
4555 __ LoadRoot(r0, Heap::kUndefinedValueRootIndex);
4557 context()->Plug(r0);
4561 void FullCodeGenerator::EmitDebugIsActive(CallRuntime* expr) {
4562 DCHECK(expr->arguments()->length() == 0);
4563 ExternalReference debug_is_active =
4564 ExternalReference::debug_is_active_address(isolate());
4565 __ mov(ip, Operand(debug_is_active));
4566 __ ldrb(r0, MemOperand(ip));
4568 context()->Plug(r0);
4572 void FullCodeGenerator::VisitCallRuntime(CallRuntime* expr) {
4573 if (expr->function() != NULL &&
4574 expr->function()->intrinsic_type == Runtime::INLINE) {
4575 Comment cmnt(masm_, "[ InlineRuntimeCall");
4576 EmitInlineRuntimeCall(expr);
4580 Comment cmnt(masm_, "[ CallRuntime");
4581 ZoneList<Expression*>* args = expr->arguments();
4582 int arg_count = args->length();
4584 if (expr->is_jsruntime()) {
4585 // Push the builtins object as the receiver.
4586 Register receiver = LoadDescriptor::ReceiverRegister();
4587 __ ldr(receiver, GlobalObjectOperand());
4588 __ ldr(receiver, FieldMemOperand(receiver, GlobalObject::kBuiltinsOffset));
4591 // Load the function from the receiver.
4592 __ mov(LoadDescriptor::NameRegister(), Operand(expr->name()));
4593 if (FLAG_vector_ics) {
4594 __ mov(VectorLoadICDescriptor::SlotRegister(),
4595 Operand(SmiFromSlot(expr->CallRuntimeFeedbackSlot())));
4596 CallLoadIC(NOT_CONTEXTUAL);
4598 CallLoadIC(NOT_CONTEXTUAL, expr->CallRuntimeFeedbackId());
4601 // Push the target function under the receiver.
4602 __ ldr(ip, MemOperand(sp, 0));
4604 __ str(r0, MemOperand(sp, kPointerSize));
4606 // Push the arguments ("left-to-right").
4607 int arg_count = args->length();
4608 for (int i = 0; i < arg_count; i++) {
4609 VisitForStackValue(args->at(i));
4612 // Record source position of the IC call.
4613 SetSourcePosition(expr->position());
4614 CallFunctionStub stub(isolate(), arg_count, NO_CALL_FUNCTION_FLAGS);
4615 __ ldr(r1, MemOperand(sp, (arg_count + 1) * kPointerSize));
4618 // Restore context register.
4619 __ ldr(cp, MemOperand(fp, StandardFrameConstants::kContextOffset));
4621 context()->DropAndPlug(1, r0);
4623 // Push the arguments ("left-to-right").
4624 for (int i = 0; i < arg_count; i++) {
4625 VisitForStackValue(args->at(i));
4628 // Call the C runtime function.
4629 __ CallRuntime(expr->function(), arg_count);
4630 context()->Plug(r0);
4635 void FullCodeGenerator::VisitUnaryOperation(UnaryOperation* expr) {
4636 switch (expr->op()) {
4637 case Token::DELETE: {
4638 Comment cmnt(masm_, "[ UnaryOperation (DELETE)");
4639 Property* property = expr->expression()->AsProperty();
4640 VariableProxy* proxy = expr->expression()->AsVariableProxy();
4642 if (property != NULL) {
4643 VisitForStackValue(property->obj());
4644 VisitForStackValue(property->key());
4645 __ mov(r1, Operand(Smi::FromInt(language_mode())));
4647 __ InvokeBuiltin(Builtins::DELETE, CALL_FUNCTION);
4648 context()->Plug(r0);
4649 } else if (proxy != NULL) {
4650 Variable* var = proxy->var();
4651 // Delete of an unqualified identifier is disallowed in strict mode
4652 // but "delete this" is allowed.
4653 DCHECK(is_sloppy(language_mode()) || var->is_this());
4654 if (var->IsUnallocated()) {
4655 __ ldr(r2, GlobalObjectOperand());
4656 __ mov(r1, Operand(var->name()));
4657 __ mov(r0, Operand(Smi::FromInt(SLOPPY)));
4658 __ Push(r2, r1, r0);
4659 __ InvokeBuiltin(Builtins::DELETE, CALL_FUNCTION);
4660 context()->Plug(r0);
4661 } else if (var->IsStackAllocated() || var->IsContextSlot()) {
4662 // Result of deleting non-global, non-dynamic variables is false.
4663 // The subexpression does not have side effects.
4664 context()->Plug(var->is_this());
4666 // Non-global variable. Call the runtime to try to delete from the
4667 // context where the variable was introduced.
4668 DCHECK(!context_register().is(r2));
4669 __ mov(r2, Operand(var->name()));
4670 __ Push(context_register(), r2);
4671 __ CallRuntime(Runtime::kDeleteLookupSlot, 2);
4672 context()->Plug(r0);
4675 // Result of deleting non-property, non-variable reference is true.
4676 // The subexpression may have side effects.
4677 VisitForEffect(expr->expression());
4678 context()->Plug(true);
4684 Comment cmnt(masm_, "[ UnaryOperation (VOID)");
4685 VisitForEffect(expr->expression());
4686 context()->Plug(Heap::kUndefinedValueRootIndex);
4691 Comment cmnt(masm_, "[ UnaryOperation (NOT)");
4692 if (context()->IsEffect()) {
4693 // Unary NOT has no side effects so it's only necessary to visit the
4694 // subexpression. Match the optimizing compiler by not branching.
4695 VisitForEffect(expr->expression());
4696 } else if (context()->IsTest()) {
4697 const TestContext* test = TestContext::cast(context());
4698 // The labels are swapped for the recursive call.
4699 VisitForControl(expr->expression(),
4700 test->false_label(),
4702 test->fall_through());
4703 context()->Plug(test->true_label(), test->false_label());
4705 // We handle value contexts explicitly rather than simply visiting
4706 // for control and plugging the control flow into the context,
4707 // because we need to prepare a pair of extra administrative AST ids
4708 // for the optimizing compiler.
4709 DCHECK(context()->IsAccumulatorValue() || context()->IsStackValue());
4710 Label materialize_true, materialize_false, done;
4711 VisitForControl(expr->expression(),
4715 __ bind(&materialize_true);
4716 PrepareForBailoutForId(expr->MaterializeTrueId(), NO_REGISTERS);
4717 __ LoadRoot(r0, Heap::kTrueValueRootIndex);
4718 if (context()->IsStackValue()) __ push(r0);
4720 __ bind(&materialize_false);
4721 PrepareForBailoutForId(expr->MaterializeFalseId(), NO_REGISTERS);
4722 __ LoadRoot(r0, Heap::kFalseValueRootIndex);
4723 if (context()->IsStackValue()) __ push(r0);
4729 case Token::TYPEOF: {
4730 Comment cmnt(masm_, "[ UnaryOperation (TYPEOF)");
4731 { StackValueContext context(this);
4732 VisitForTypeofValue(expr->expression());
4734 __ CallRuntime(Runtime::kTypeof, 1);
4735 context()->Plug(r0);
4745 void FullCodeGenerator::VisitCountOperation(CountOperation* expr) {
4746 DCHECK(expr->expression()->IsValidReferenceExpression());
4748 Comment cmnt(masm_, "[ CountOperation");
4749 SetSourcePosition(expr->position());
4751 Property* prop = expr->expression()->AsProperty();
4752 LhsKind assign_type = GetAssignType(prop);
4754 // Evaluate expression and get value.
4755 if (assign_type == VARIABLE) {
4756 DCHECK(expr->expression()->AsVariableProxy()->var() != NULL);
4757 AccumulatorValueContext context(this);
4758 EmitVariableLoad(expr->expression()->AsVariableProxy());
4760 // Reserve space for result of postfix operation.
4761 if (expr->is_postfix() && !context()->IsEffect()) {
4762 __ mov(ip, Operand(Smi::FromInt(0)));
4765 switch (assign_type) {
4766 case NAMED_PROPERTY: {
4767 // Put the object both on the stack and in the register.
4768 VisitForStackValue(prop->obj());
4769 __ ldr(LoadDescriptor::ReceiverRegister(), MemOperand(sp, 0));
4770 EmitNamedPropertyLoad(prop);
4774 case NAMED_SUPER_PROPERTY: {
4775 VisitForStackValue(prop->obj()->AsSuperReference()->this_var());
4776 EmitLoadHomeObject(prop->obj()->AsSuperReference());
4777 __ Push(result_register());
4778 const Register scratch = r1;
4779 __ ldr(scratch, MemOperand(sp, kPointerSize));
4781 __ Push(result_register());
4782 EmitNamedSuperPropertyLoad(prop);
4786 case KEYED_SUPER_PROPERTY: {
4787 VisitForStackValue(prop->obj()->AsSuperReference()->this_var());
4788 EmitLoadHomeObject(prop->obj()->AsSuperReference());
4789 __ Push(result_register());
4790 VisitForAccumulatorValue(prop->key());
4791 __ Push(result_register());
4792 const Register scratch = r1;
4793 __ ldr(scratch, MemOperand(sp, 2 * kPointerSize));
4795 __ ldr(scratch, MemOperand(sp, 2 * kPointerSize));
4797 __ Push(result_register());
4798 EmitKeyedSuperPropertyLoad(prop);
4802 case KEYED_PROPERTY: {
4803 VisitForStackValue(prop->obj());
4804 VisitForStackValue(prop->key());
4805 __ ldr(LoadDescriptor::ReceiverRegister(),
4806 MemOperand(sp, 1 * kPointerSize));
4807 __ ldr(LoadDescriptor::NameRegister(), MemOperand(sp, 0));
4808 EmitKeyedPropertyLoad(prop);
4817 // We need a second deoptimization point after loading the value
4818 // in case evaluating the property load my have a side effect.
4819 if (assign_type == VARIABLE) {
4820 PrepareForBailout(expr->expression(), TOS_REG);
4822 PrepareForBailoutForId(prop->LoadId(), TOS_REG);
4825 // Inline smi case if we are in a loop.
4826 Label stub_call, done;
4827 JumpPatchSite patch_site(masm_);
4829 int count_value = expr->op() == Token::INC ? 1 : -1;
4830 if (ShouldInlineSmiCase(expr->op())) {
4832 patch_site.EmitJumpIfNotSmi(r0, &slow);
4834 // Save result for postfix expressions.
4835 if (expr->is_postfix()) {
4836 if (!context()->IsEffect()) {
4837 // Save the result on the stack. If we have a named or keyed property
4838 // we store the result under the receiver that is currently on top
4840 switch (assign_type) {
4844 case NAMED_PROPERTY:
4845 __ str(r0, MemOperand(sp, kPointerSize));
4847 case NAMED_SUPER_PROPERTY:
4848 __ str(r0, MemOperand(sp, 2 * kPointerSize));
4850 case KEYED_PROPERTY:
4851 __ str(r0, MemOperand(sp, 2 * kPointerSize));
4853 case KEYED_SUPER_PROPERTY:
4854 __ str(r0, MemOperand(sp, 3 * kPointerSize));
4860 __ add(r0, r0, Operand(Smi::FromInt(count_value)), SetCC);
4862 // Call stub. Undo operation first.
4863 __ sub(r0, r0, Operand(Smi::FromInt(count_value)));
4867 ToNumberStub convert_stub(isolate());
4868 __ CallStub(&convert_stub);
4869 PrepareForBailoutForId(expr->ToNumberId(), TOS_REG);
4871 // Save result for postfix expressions.
4872 if (expr->is_postfix()) {
4873 if (!context()->IsEffect()) {
4874 // Save the result on the stack. If we have a named or keyed property
4875 // we store the result under the receiver that is currently on top
4877 switch (assign_type) {
4881 case NAMED_PROPERTY:
4882 __ str(r0, MemOperand(sp, kPointerSize));
4884 case NAMED_SUPER_PROPERTY:
4885 __ str(r0, MemOperand(sp, 2 * kPointerSize));
4887 case KEYED_PROPERTY:
4888 __ str(r0, MemOperand(sp, 2 * kPointerSize));
4890 case KEYED_SUPER_PROPERTY:
4891 __ str(r0, MemOperand(sp, 3 * kPointerSize));
4898 __ bind(&stub_call);
4900 __ mov(r0, Operand(Smi::FromInt(count_value)));
4902 // Record position before stub call.
4903 SetSourcePosition(expr->position());
4905 Handle<Code> code = CodeFactory::BinaryOpIC(isolate(), Token::ADD).code();
4906 CallIC(code, expr->CountBinOpFeedbackId());
4907 patch_site.EmitPatchInfo();
4910 // Store the value returned in r0.
4911 switch (assign_type) {
4913 if (expr->is_postfix()) {
4914 { EffectContext context(this);
4915 EmitVariableAssignment(expr->expression()->AsVariableProxy()->var(),
4917 PrepareForBailoutForId(expr->AssignmentId(), TOS_REG);
4920 // For all contexts except EffectConstant We have the result on
4921 // top of the stack.
4922 if (!context()->IsEffect()) {
4923 context()->PlugTOS();
4926 EmitVariableAssignment(expr->expression()->AsVariableProxy()->var(),
4928 PrepareForBailoutForId(expr->AssignmentId(), TOS_REG);
4929 context()->Plug(r0);
4932 case NAMED_PROPERTY: {
4933 __ mov(StoreDescriptor::NameRegister(),
4934 Operand(prop->key()->AsLiteral()->value()));
4935 __ pop(StoreDescriptor::ReceiverRegister());
4936 CallStoreIC(expr->CountStoreFeedbackId());
4937 PrepareForBailoutForId(expr->AssignmentId(), TOS_REG);
4938 if (expr->is_postfix()) {
4939 if (!context()->IsEffect()) {
4940 context()->PlugTOS();
4943 context()->Plug(r0);
4947 case NAMED_SUPER_PROPERTY: {
4948 EmitNamedSuperPropertyStore(prop);
4949 if (expr->is_postfix()) {
4950 if (!context()->IsEffect()) {
4951 context()->PlugTOS();
4954 context()->Plug(r0);
4958 case KEYED_SUPER_PROPERTY: {
4959 EmitKeyedSuperPropertyStore(prop);
4960 if (expr->is_postfix()) {
4961 if (!context()->IsEffect()) {
4962 context()->PlugTOS();
4965 context()->Plug(r0);
4969 case KEYED_PROPERTY: {
4970 __ Pop(StoreDescriptor::ReceiverRegister(),
4971 StoreDescriptor::NameRegister());
4973 CodeFactory::KeyedStoreIC(isolate(), language_mode()).code();
4974 CallIC(ic, expr->CountStoreFeedbackId());
4975 PrepareForBailoutForId(expr->AssignmentId(), TOS_REG);
4976 if (expr->is_postfix()) {
4977 if (!context()->IsEffect()) {
4978 context()->PlugTOS();
4981 context()->Plug(r0);
4989 void FullCodeGenerator::VisitForTypeofValue(Expression* expr) {
4990 DCHECK(!context()->IsEffect());
4991 DCHECK(!context()->IsTest());
4992 VariableProxy* proxy = expr->AsVariableProxy();
4993 if (proxy != NULL && proxy->var()->IsUnallocated()) {
4994 Comment cmnt(masm_, "[ Global variable");
4995 __ ldr(LoadDescriptor::ReceiverRegister(), GlobalObjectOperand());
4996 __ mov(LoadDescriptor::NameRegister(), Operand(proxy->name()));
4997 if (FLAG_vector_ics) {
4998 __ mov(VectorLoadICDescriptor::SlotRegister(),
4999 Operand(SmiFromSlot(proxy->VariableFeedbackSlot())));
5001 // Use a regular load, not a contextual load, to avoid a reference
5003 CallLoadIC(NOT_CONTEXTUAL);
5004 PrepareForBailout(expr, TOS_REG);
5005 context()->Plug(r0);
5006 } else if (proxy != NULL && proxy->var()->IsLookupSlot()) {
5007 Comment cmnt(masm_, "[ Lookup slot");
5010 // Generate code for loading from variables potentially shadowed
5011 // by eval-introduced variables.
5012 EmitDynamicLookupFastCase(proxy, INSIDE_TYPEOF, &slow, &done);
5015 __ mov(r0, Operand(proxy->name()));
5017 __ CallRuntime(Runtime::kLoadLookupSlotNoReferenceError, 2);
5018 PrepareForBailout(expr, TOS_REG);
5021 context()->Plug(r0);
5023 // This expression cannot throw a reference error at the top level.
5024 VisitInDuplicateContext(expr);
5029 void FullCodeGenerator::EmitLiteralCompareTypeof(Expression* expr,
5030 Expression* sub_expr,
5031 Handle<String> check) {
5032 Label materialize_true, materialize_false;
5033 Label* if_true = NULL;
5034 Label* if_false = NULL;
5035 Label* fall_through = NULL;
5036 context()->PrepareTest(&materialize_true, &materialize_false,
5037 &if_true, &if_false, &fall_through);
5039 { AccumulatorValueContext context(this);
5040 VisitForTypeofValue(sub_expr);
5042 PrepareForBailoutBeforeSplit(expr, true, if_true, if_false);
5044 Factory* factory = isolate()->factory();
5045 if (String::Equals(check, factory->number_string())) {
5046 __ JumpIfSmi(r0, if_true);
5047 __ ldr(r0, FieldMemOperand(r0, HeapObject::kMapOffset));
5048 __ LoadRoot(ip, Heap::kHeapNumberMapRootIndex);
5050 Split(eq, if_true, if_false, fall_through);
5051 } else if (String::Equals(check, factory->string_string())) {
5052 __ JumpIfSmi(r0, if_false);
5053 // Check for undetectable objects => false.
5054 __ CompareObjectType(r0, r0, r1, FIRST_NONSTRING_TYPE);
5056 __ ldrb(r1, FieldMemOperand(r0, Map::kBitFieldOffset));
5057 __ tst(r1, Operand(1 << Map::kIsUndetectable));
5058 Split(eq, if_true, if_false, fall_through);
5059 } else if (String::Equals(check, factory->symbol_string())) {
5060 __ JumpIfSmi(r0, if_false);
5061 __ CompareObjectType(r0, r0, r1, SYMBOL_TYPE);
5062 Split(eq, if_true, if_false, fall_through);
5063 } else if (String::Equals(check, factory->boolean_string())) {
5064 __ CompareRoot(r0, Heap::kTrueValueRootIndex);
5066 __ CompareRoot(r0, Heap::kFalseValueRootIndex);
5067 Split(eq, if_true, if_false, fall_through);
5068 } else if (String::Equals(check, factory->undefined_string())) {
5069 __ CompareRoot(r0, Heap::kUndefinedValueRootIndex);
5071 __ JumpIfSmi(r0, if_false);
5072 // Check for undetectable objects => true.
5073 __ ldr(r0, FieldMemOperand(r0, HeapObject::kMapOffset));
5074 __ ldrb(r1, FieldMemOperand(r0, Map::kBitFieldOffset));
5075 __ tst(r1, Operand(1 << Map::kIsUndetectable));
5076 Split(ne, if_true, if_false, fall_through);
5078 } else if (String::Equals(check, factory->function_string())) {
5079 __ JumpIfSmi(r0, if_false);
5080 STATIC_ASSERT(NUM_OF_CALLABLE_SPEC_OBJECT_TYPES == 2);
5081 __ CompareObjectType(r0, r0, r1, JS_FUNCTION_TYPE);
5083 __ cmp(r1, Operand(JS_FUNCTION_PROXY_TYPE));
5084 Split(eq, if_true, if_false, fall_through);
5085 } else if (String::Equals(check, factory->object_string())) {
5086 __ JumpIfSmi(r0, if_false);
5087 __ CompareRoot(r0, Heap::kNullValueRootIndex);
5089 // Check for JS objects => true.
5090 __ CompareObjectType(r0, r0, r1, FIRST_NONCALLABLE_SPEC_OBJECT_TYPE);
5092 __ CompareInstanceType(r0, r1, LAST_NONCALLABLE_SPEC_OBJECT_TYPE);
5094 // Check for undetectable objects => false.
5095 __ ldrb(r1, FieldMemOperand(r0, Map::kBitFieldOffset));
5096 __ tst(r1, Operand(1 << Map::kIsUndetectable));
5097 Split(eq, if_true, if_false, fall_through);
5099 if (if_false != fall_through) __ jmp(if_false);
5101 context()->Plug(if_true, if_false);
5105 void FullCodeGenerator::VisitCompareOperation(CompareOperation* expr) {
5106 Comment cmnt(masm_, "[ CompareOperation");
5107 SetSourcePosition(expr->position());
5109 // First we try a fast inlined version of the compare when one of
5110 // the operands is a literal.
5111 if (TryLiteralCompare(expr)) return;
5113 // Always perform the comparison for its control flow. Pack the result
5114 // into the expression's context after the comparison is performed.
5115 Label materialize_true, materialize_false;
5116 Label* if_true = NULL;
5117 Label* if_false = NULL;
5118 Label* fall_through = NULL;
5119 context()->PrepareTest(&materialize_true, &materialize_false,
5120 &if_true, &if_false, &fall_through);
5122 Token::Value op = expr->op();
5123 VisitForStackValue(expr->left());
5126 VisitForStackValue(expr->right());
5127 __ InvokeBuiltin(Builtins::IN, CALL_FUNCTION);
5128 PrepareForBailoutBeforeSplit(expr, false, NULL, NULL);
5129 __ LoadRoot(ip, Heap::kTrueValueRootIndex);
5131 Split(eq, if_true, if_false, fall_through);
5134 case Token::INSTANCEOF: {
5135 VisitForStackValue(expr->right());
5136 InstanceofStub stub(isolate(), InstanceofStub::kNoFlags);
5138 PrepareForBailoutBeforeSplit(expr, true, if_true, if_false);
5139 // The stub returns 0 for true.
5141 Split(eq, if_true, if_false, fall_through);
5146 VisitForAccumulatorValue(expr->right());
5147 Condition cond = CompareIC::ComputeCondition(op);
5150 bool inline_smi_code = ShouldInlineSmiCase(op);
5151 JumpPatchSite patch_site(masm_);
5152 if (inline_smi_code) {
5154 __ orr(r2, r0, Operand(r1));
5155 patch_site.EmitJumpIfNotSmi(r2, &slow_case);
5157 Split(cond, if_true, if_false, NULL);
5158 __ bind(&slow_case);
5161 // Record position and call the compare IC.
5162 SetSourcePosition(expr->position());
5163 Handle<Code> ic = CodeFactory::CompareIC(isolate(), op).code();
5164 CallIC(ic, expr->CompareOperationFeedbackId());
5165 patch_site.EmitPatchInfo();
5166 PrepareForBailoutBeforeSplit(expr, true, if_true, if_false);
5167 __ cmp(r0, Operand::Zero());
5168 Split(cond, if_true, if_false, fall_through);
5172 // Convert the result of the comparison into one expected for this
5173 // expression's context.
5174 context()->Plug(if_true, if_false);
5178 void FullCodeGenerator::EmitLiteralCompareNil(CompareOperation* expr,
5179 Expression* sub_expr,
5181 Label materialize_true, materialize_false;
5182 Label* if_true = NULL;
5183 Label* if_false = NULL;
5184 Label* fall_through = NULL;
5185 context()->PrepareTest(&materialize_true, &materialize_false,
5186 &if_true, &if_false, &fall_through);
5188 VisitForAccumulatorValue(sub_expr);
5189 PrepareForBailoutBeforeSplit(expr, true, if_true, if_false);
5190 if (expr->op() == Token::EQ_STRICT) {
5191 Heap::RootListIndex nil_value = nil == kNullValue ?
5192 Heap::kNullValueRootIndex :
5193 Heap::kUndefinedValueRootIndex;
5194 __ LoadRoot(r1, nil_value);
5196 Split(eq, if_true, if_false, fall_through);
5198 Handle<Code> ic = CompareNilICStub::GetUninitialized(isolate(), nil);
5199 CallIC(ic, expr->CompareOperationFeedbackId());
5200 __ cmp(r0, Operand(0));
5201 Split(ne, if_true, if_false, fall_through);
5203 context()->Plug(if_true, if_false);
5207 void FullCodeGenerator::VisitThisFunction(ThisFunction* expr) {
5208 __ ldr(r0, MemOperand(fp, JavaScriptFrameConstants::kFunctionOffset));
5209 context()->Plug(r0);
5213 Register FullCodeGenerator::result_register() {
5218 Register FullCodeGenerator::context_register() {
5223 void FullCodeGenerator::StoreToFrameField(int frame_offset, Register value) {
5224 DCHECK_EQ(POINTER_SIZE_ALIGN(frame_offset), frame_offset);
5225 __ str(value, MemOperand(fp, frame_offset));
5229 void FullCodeGenerator::LoadContextField(Register dst, int context_index) {
5230 __ ldr(dst, ContextOperand(cp, context_index));
5234 void FullCodeGenerator::PushFunctionArgumentForContextAllocation() {
5235 Scope* declaration_scope = scope()->DeclarationScope();
5236 if (declaration_scope->is_script_scope() ||
5237 declaration_scope->is_module_scope()) {
5238 // Contexts nested in the native context have a canonical empty function
5239 // as their closure, not the anonymous closure containing the global
5240 // code. Pass a smi sentinel and let the runtime look up the empty
5242 __ mov(ip, Operand(Smi::FromInt(0)));
5243 } else if (declaration_scope->is_eval_scope()) {
5244 // Contexts created by a call to eval have the same closure as the
5245 // context calling eval, not the anonymous closure containing the eval
5246 // code. Fetch it from the context.
5247 __ ldr(ip, ContextOperand(cp, Context::CLOSURE_INDEX));
5249 DCHECK(declaration_scope->is_function_scope());
5250 __ ldr(ip, MemOperand(fp, JavaScriptFrameConstants::kFunctionOffset));
5256 // ----------------------------------------------------------------------------
5257 // Non-local control flow support.
5259 void FullCodeGenerator::EnterFinallyBlock() {
5260 DCHECK(!result_register().is(r1));
5261 // Store result register while executing finally block.
5262 __ push(result_register());
5263 // Cook return address in link register to stack (smi encoded Code* delta)
5264 __ sub(r1, lr, Operand(masm_->CodeObject()));
5267 // Store result register while executing finally block.
5270 // Store pending message while executing finally block.
5271 ExternalReference pending_message_obj =
5272 ExternalReference::address_of_pending_message_obj(isolate());
5273 __ mov(ip, Operand(pending_message_obj));
5274 __ ldr(r1, MemOperand(ip));
5277 ExternalReference has_pending_message =
5278 ExternalReference::address_of_has_pending_message(isolate());
5279 __ mov(ip, Operand(has_pending_message));
5280 STATIC_ASSERT(sizeof(bool) == 1); // NOLINT(runtime/sizeof)
5281 __ ldrb(r1, MemOperand(ip));
5285 ExternalReference pending_message_script =
5286 ExternalReference::address_of_pending_message_script(isolate());
5287 __ mov(ip, Operand(pending_message_script));
5288 __ ldr(r1, MemOperand(ip));
5293 void FullCodeGenerator::ExitFinallyBlock() {
5294 DCHECK(!result_register().is(r1));
5295 // Restore pending message from stack.
5297 ExternalReference pending_message_script =
5298 ExternalReference::address_of_pending_message_script(isolate());
5299 __ mov(ip, Operand(pending_message_script));
5300 __ str(r1, MemOperand(ip));
5304 ExternalReference has_pending_message =
5305 ExternalReference::address_of_has_pending_message(isolate());
5306 __ mov(ip, Operand(has_pending_message));
5307 STATIC_ASSERT(sizeof(bool) == 1); // NOLINT(runtime/sizeof)
5308 __ strb(r1, MemOperand(ip));
5311 ExternalReference pending_message_obj =
5312 ExternalReference::address_of_pending_message_obj(isolate());
5313 __ mov(ip, Operand(pending_message_obj));
5314 __ str(r1, MemOperand(ip));
5316 // Restore result register from stack.
5319 // Uncook return address and return.
5320 __ pop(result_register());
5322 __ add(pc, r1, Operand(masm_->CodeObject()));
5328 #define __ ACCESS_MASM(masm())
5330 FullCodeGenerator::NestedStatement* FullCodeGenerator::TryFinally::Exit(
5332 int* context_length) {
5333 // The macros used here must preserve the result register.
5335 // Because the handler block contains the context of the finally
5336 // code, we can restore it directly from there for the finally code
5337 // rather than iteratively unwinding contexts via their previous
5339 __ Drop(*stack_depth); // Down to the handler block.
5340 if (*context_length > 0) {
5341 // Restore the context to its dedicated register and the stack.
5342 __ ldr(cp, MemOperand(sp, StackHandlerConstants::kContextOffset));
5343 __ str(cp, MemOperand(fp, StandardFrameConstants::kContextOffset));
5346 __ bl(finally_entry_);
5349 *context_length = 0;
5357 static Address GetInterruptImmediateLoadAddress(Address pc) {
5358 Address load_address = pc - 2 * Assembler::kInstrSize;
5359 if (!FLAG_enable_ool_constant_pool) {
5360 DCHECK(Assembler::IsLdrPcImmediateOffset(Memory::int32_at(load_address)));
5361 } else if (Assembler::IsLdrPpRegOffset(Memory::int32_at(load_address))) {
5362 // This is an extended constant pool lookup.
5363 if (CpuFeatures::IsSupported(ARMv7)) {
5364 load_address -= 2 * Assembler::kInstrSize;
5365 DCHECK(Assembler::IsMovW(Memory::int32_at(load_address)));
5366 DCHECK(Assembler::IsMovT(
5367 Memory::int32_at(load_address + Assembler::kInstrSize)));
5369 load_address -= 4 * Assembler::kInstrSize;
5370 DCHECK(Assembler::IsMovImmed(Memory::int32_at(load_address)));
5371 DCHECK(Assembler::IsOrrImmed(
5372 Memory::int32_at(load_address + Assembler::kInstrSize)));
5373 DCHECK(Assembler::IsOrrImmed(
5374 Memory::int32_at(load_address + 2 * Assembler::kInstrSize)));
5375 DCHECK(Assembler::IsOrrImmed(
5376 Memory::int32_at(load_address + 3 * Assembler::kInstrSize)));
5378 } else if (CpuFeatures::IsSupported(ARMv7) &&
5379 Assembler::IsMovT(Memory::int32_at(load_address))) {
5380 // This is a movw / movt immediate load.
5381 load_address -= Assembler::kInstrSize;
5382 DCHECK(Assembler::IsMovW(Memory::int32_at(load_address)));
5383 } else if (!CpuFeatures::IsSupported(ARMv7) &&
5384 Assembler::IsOrrImmed(Memory::int32_at(load_address))) {
5385 // This is a mov / orr immediate load.
5386 load_address -= 3 * Assembler::kInstrSize;
5387 DCHECK(Assembler::IsMovImmed(Memory::int32_at(load_address)));
5388 DCHECK(Assembler::IsOrrImmed(
5389 Memory::int32_at(load_address + Assembler::kInstrSize)));
5390 DCHECK(Assembler::IsOrrImmed(
5391 Memory::int32_at(load_address + 2 * Assembler::kInstrSize)));
5393 // This is a small constant pool lookup.
5394 DCHECK(Assembler::IsLdrPpImmediateOffset(Memory::int32_at(load_address)));
5396 return load_address;
5400 void BackEdgeTable::PatchAt(Code* unoptimized_code,
5402 BackEdgeState target_state,
5403 Code* replacement_code) {
5404 Address pc_immediate_load_address = GetInterruptImmediateLoadAddress(pc);
5405 Address branch_address = pc_immediate_load_address - Assembler::kInstrSize;
5406 CodePatcher patcher(branch_address, 1);
5407 switch (target_state) {
5410 // <decrement profiling counter>
5412 // ; load interrupt stub address into ip - either of (for ARMv7):
5413 // ; <small cp load> | <extended cp load> | <immediate load>
5414 // ldr ip, [pc/pp, #imm] | movw ip, #imm | movw ip, #imm
5415 // | movt ip, #imm | movw ip, #imm
5416 // | ldr ip, [pp, ip]
5417 // ; or (for ARMv6):
5418 // ; <small cp load> | <extended cp load> | <immediate load>
5419 // ldr ip, [pc/pp, #imm] | mov ip, #imm | mov ip, #imm
5420 // | orr ip, ip, #imm> | orr ip, ip, #imm
5421 // | orr ip, ip, #imm> | orr ip, ip, #imm
5422 // | orr ip, ip, #imm> | orr ip, ip, #imm
5424 // <reset profiling counter>
5427 // Calculate branch offset to the ok-label - this is the difference
5428 // between the branch address and |pc| (which points at <blx ip>) plus
5429 // kProfileCounterResetSequence instructions
5430 int branch_offset = pc - Instruction::kPCReadOffset - branch_address +
5431 kProfileCounterResetSequenceLength;
5432 patcher.masm()->b(branch_offset, pl);
5435 case ON_STACK_REPLACEMENT:
5436 case OSR_AFTER_STACK_CHECK:
5437 // <decrement profiling counter>
5439 // ; load on-stack replacement address into ip - either of (for ARMv7):
5440 // ; <small cp load> | <extended cp load> | <immediate load>
5441 // ldr ip, [pc/pp, #imm] | movw ip, #imm | movw ip, #imm
5442 // | movt ip, #imm> | movw ip, #imm
5443 // | ldr ip, [pp, ip]
5444 // ; or (for ARMv6):
5445 // ; <small cp load> | <extended cp load> | <immediate load>
5446 // ldr ip, [pc/pp, #imm] | mov ip, #imm | mov ip, #imm
5447 // | orr ip, ip, #imm> | orr ip, ip, #imm
5448 // | orr ip, ip, #imm> | orr ip, ip, #imm
5449 // | orr ip, ip, #imm> | orr ip, ip, #imm
5451 // <reset profiling counter>
5453 patcher.masm()->nop();
5457 // Replace the call address.
5458 Assembler::set_target_address_at(pc_immediate_load_address, unoptimized_code,
5459 replacement_code->entry());
5461 unoptimized_code->GetHeap()->incremental_marking()->RecordCodeTargetPatch(
5462 unoptimized_code, pc_immediate_load_address, replacement_code);
5466 BackEdgeTable::BackEdgeState BackEdgeTable::GetBackEdgeState(
5468 Code* unoptimized_code,
5470 DCHECK(Assembler::IsBlxIp(Memory::int32_at(pc - Assembler::kInstrSize)));
5472 Address pc_immediate_load_address = GetInterruptImmediateLoadAddress(pc);
5473 Address branch_address = pc_immediate_load_address - Assembler::kInstrSize;
5474 Address interrupt_address = Assembler::target_address_at(
5475 pc_immediate_load_address, unoptimized_code);
5477 if (Assembler::IsBranch(Assembler::instr_at(branch_address))) {
5478 DCHECK(interrupt_address ==
5479 isolate->builtins()->InterruptCheck()->entry());
5483 DCHECK(Assembler::IsNop(Assembler::instr_at(branch_address)));
5485 if (interrupt_address ==
5486 isolate->builtins()->OnStackReplacement()->entry()) {
5487 return ON_STACK_REPLACEMENT;
5490 DCHECK(interrupt_address ==
5491 isolate->builtins()->OsrAfterStackCheck()->entry());
5492 return OSR_AFTER_STACK_CHECK;
5496 } } // namespace v8::internal
5498 #endif // V8_TARGET_ARCH_ARM