1 // Copyright 2014 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
7 #include "src/code-factory.h"
8 #include "src/code-stubs.h"
9 #include "src/codegen.h"
10 #include "src/compiler.h"
11 #include "src/debug/debug.h"
12 #include "src/full-codegen/full-codegen.h"
13 #include "src/ic/ic.h"
14 #include "src/parser.h"
15 #include "src/scopes.h"
17 #include "src/ppc/code-stubs-ppc.h"
18 #include "src/ppc/macro-assembler-ppc.h"
23 #define __ ACCESS_MASM(masm_)
25 // A patch site is a location in the code which it is possible to patch. This
26 // class has a number of methods to emit the code which is patchable and the
27 // method EmitPatchInfo to record a marker back to the patchable code. This
28 // marker is a cmpi rx, #yyy instruction, and x * 0x0000ffff + yyy (raw 16 bit
29 // immediate value is used) is the delta from the pc to the first instruction of
30 // the patchable code.
31 // See PatchInlinedSmiCode in ic-ppc.cc for the code that patches it
32 class JumpPatchSite BASE_EMBEDDED {
34 explicit JumpPatchSite(MacroAssembler* masm) : masm_(masm) {
36 info_emitted_ = false;
40 ~JumpPatchSite() { DCHECK(patch_site_.is_bound() == info_emitted_); }
42 // When initially emitting this ensure that a jump is always generated to skip
43 // the inlined smi code.
44 void EmitJumpIfNotSmi(Register reg, Label* target) {
45 DCHECK(!patch_site_.is_bound() && !info_emitted_);
46 Assembler::BlockTrampolinePoolScope block_trampoline_pool(masm_);
47 __ bind(&patch_site_);
48 __ cmp(reg, reg, cr0);
49 __ beq(target, cr0); // Always taken before patched.
52 // When initially emitting this ensure that a jump is never generated to skip
53 // the inlined smi code.
54 void EmitJumpIfSmi(Register reg, Label* target) {
55 Assembler::BlockTrampolinePoolScope block_trampoline_pool(masm_);
56 DCHECK(!patch_site_.is_bound() && !info_emitted_);
57 __ bind(&patch_site_);
58 __ cmp(reg, reg, cr0);
59 __ bne(target, cr0); // Never taken before patched.
62 void EmitPatchInfo() {
63 if (patch_site_.is_bound()) {
64 int delta_to_patch_site = masm_->InstructionsGeneratedSince(&patch_site_);
66 // I believe this is using reg as the high bits of of the offset
67 reg.set_code(delta_to_patch_site / kOff16Mask);
68 __ cmpi(reg, Operand(delta_to_patch_site % kOff16Mask));
73 __ nop(); // Signals no inlined code.
78 MacroAssembler* masm_;
86 // Generate code for a JS function. On entry to the function the receiver
87 // and arguments have been pushed on the stack left to right. The actual
88 // argument count matches the formal parameter count expected by the
91 // The live registers are:
92 // o r4: the JS function object being called (i.e., ourselves)
94 // o fp: our caller's frame pointer (aka r31)
95 // o sp: stack pointer
96 // o lr: return address
97 // o ip: our own function entry (required by the prologue)
99 // The function builds a JS frame. Please see JavaScriptFrameConstants in
100 // frames-ppc.h for its layout.
101 void FullCodeGenerator::Generate() {
102 CompilationInfo* info = info_;
103 profiling_counter_ = isolate()->factory()->NewCell(
104 Handle<Smi>(Smi::FromInt(FLAG_interrupt_budget), isolate()));
105 SetFunctionPosition(literal());
106 Comment cmnt(masm_, "[ function compiled by full code generator");
108 ProfileEntryHookStub::MaybeCallEntryHook(masm_);
111 if (strlen(FLAG_stop_at) > 0 &&
112 info->literal()->name()->IsUtf8EqualTo(CStrVector(FLAG_stop_at))) {
117 // Sloppy mode functions and builtins need to replace the receiver with the
118 // global proxy when called as functions (without an explicit receiver
120 if (info->MustReplaceUndefinedReceiverWithGlobalProxy()) {
122 int receiver_offset = info->scope()->num_parameters() * kPointerSize;
123 __ LoadP(r5, MemOperand(sp, receiver_offset), r0);
124 __ CompareRoot(r5, Heap::kUndefinedValueRootIndex);
127 __ LoadP(r5, GlobalObjectOperand());
128 __ LoadP(r5, FieldMemOperand(r5, GlobalObject::kGlobalProxyOffset));
130 __ StoreP(r5, MemOperand(sp, receiver_offset), r0);
135 // Open a frame scope to indicate that there is a frame on the stack. The
136 // MANUAL indicates that the scope shouldn't actually generate code to set up
137 // the frame (that is done below).
138 FrameScope frame_scope(masm_, StackFrame::MANUAL);
139 int prologue_offset = masm_->pc_offset();
141 if (prologue_offset) {
142 // Prologue logic requires it's starting address in ip and the
143 // corresponding offset from the function entry.
144 prologue_offset += Instruction::kInstrSize;
145 __ addi(ip, ip, Operand(prologue_offset));
147 info->set_prologue_offset(prologue_offset);
148 __ Prologue(info->IsCodePreAgingActive(), prologue_offset);
149 info->AddNoFrameRange(0, masm_->pc_offset());
152 Comment cmnt(masm_, "[ Allocate locals");
153 int locals_count = info->scope()->num_stack_slots();
154 // Generators allocate locals, if any, in context slots.
155 DCHECK(!IsGeneratorFunction(info->literal()->kind()) || locals_count == 0);
156 if (locals_count > 0) {
157 if (locals_count >= 128) {
159 __ Add(ip, sp, -(locals_count * kPointerSize), r0);
160 __ LoadRoot(r5, Heap::kRealStackLimitRootIndex);
162 __ bc_short(ge, &ok);
163 __ InvokeBuiltin(Context::STACK_OVERFLOW_BUILTIN_INDEX, CALL_FUNCTION);
166 __ LoadRoot(ip, Heap::kUndefinedValueRootIndex);
167 int kMaxPushes = FLAG_optimize_for_size ? 4 : 32;
168 if (locals_count >= kMaxPushes) {
169 int loop_iterations = locals_count / kMaxPushes;
170 __ mov(r5, Operand(loop_iterations));
173 __ bind(&loop_header);
175 for (int i = 0; i < kMaxPushes; i++) {
178 // Continue loop if not done.
179 __ bdnz(&loop_header);
181 int remaining = locals_count % kMaxPushes;
182 // Emit the remaining pushes.
183 for (int i = 0; i < remaining; i++) {
189 bool function_in_register = true;
191 // Possibly allocate a local context.
192 if (info->scope()->num_heap_slots() > 0) {
193 // Argument to NewContext is the function, which is still in r4.
194 Comment cmnt(masm_, "[ Allocate context");
195 bool need_write_barrier = true;
196 int slots = info->scope()->num_heap_slots() - Context::MIN_CONTEXT_SLOTS;
197 if (info->scope()->is_script_scope()) {
199 __ Push(info->scope()->GetScopeInfo(info->isolate()));
200 __ CallRuntime(Runtime::kNewScriptContext, 2);
201 } else if (slots <= FastNewContextStub::kMaximumSlots) {
202 FastNewContextStub stub(isolate(), slots);
204 // Result of FastNewContextStub is always in new space.
205 need_write_barrier = false;
208 __ CallRuntime(Runtime::kNewFunctionContext, 1);
210 function_in_register = false;
211 // Context is returned in r3. It replaces the context passed to us.
212 // It's saved in the stack and kept live in cp.
214 __ StoreP(r3, MemOperand(fp, StandardFrameConstants::kContextOffset));
215 // Copy any necessary parameters into the context.
216 int num_parameters = info->scope()->num_parameters();
217 int first_parameter = info->scope()->has_this_declaration() ? -1 : 0;
218 for (int i = first_parameter; i < num_parameters; i++) {
219 Variable* var = (i == -1) ? scope()->receiver() : 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 __ LoadP(r3, MemOperand(fp, parameter_offset), r0);
225 // Store it in the context.
226 MemOperand target = ContextOperand(cp, var->index());
227 __ StoreP(r3, target, r0);
229 // Update the write barrier.
230 if (need_write_barrier) {
231 __ RecordWriteContextSlot(cp, target.offset(), r3, r6,
232 kLRHasBeenSaved, kDontSaveFPRegs);
233 } else if (FLAG_debug_code) {
235 __ JumpIfInNewSpace(cp, r3, &done);
236 __ Abort(kExpectedNewSpaceObject);
243 // Possibly set up a local binding to the this function which is used in
244 // derived constructors with super calls.
245 Variable* this_function_var = scope()->this_function_var();
246 if (this_function_var != nullptr) {
247 Comment cmnt(masm_, "[ This function");
248 if (!function_in_register) {
249 __ LoadP(r4, MemOperand(fp, JavaScriptFrameConstants::kFunctionOffset));
250 // The write barrier clobbers register again, keep is marked as such.
252 SetVar(this_function_var, r4, r3, r5);
255 Variable* new_target_var = scope()->new_target_var();
256 if (new_target_var != nullptr) {
257 Comment cmnt(masm_, "[ new.target");
259 // Get the frame pointer for the calling frame.
260 __ LoadP(r5, MemOperand(fp, StandardFrameConstants::kCallerFPOffset));
262 // Skip the arguments adaptor frame if it exists.
263 __ LoadP(r4, MemOperand(r5, StandardFrameConstants::kContextOffset));
264 __ CmpSmiLiteral(r4, Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR), r0);
267 __ LoadP(r5, MemOperand(r5, StandardFrameConstants::kCallerFPOffset));
270 // Check the marker in the calling frame.
271 __ LoadP(r4, MemOperand(r5, StandardFrameConstants::kMarkerOffset));
272 __ CmpSmiLiteral(r4, Smi::FromInt(StackFrame::CONSTRUCT), r0);
273 Label non_construct_frame, done;
275 __ bne(&non_construct_frame);
276 __ LoadP(r3, MemOperand(
277 r5, ConstructFrameConstants::kOriginalConstructorOffset));
280 __ bind(&non_construct_frame);
281 __ LoadRoot(r3, Heap::kUndefinedValueRootIndex);
284 SetVar(new_target_var, r3, r5, r6);
287 // Possibly allocate RestParameters
289 Variable* rest_param = scope()->rest_parameter(&rest_index);
291 Comment cmnt(masm_, "[ Allocate rest parameter array");
293 int num_parameters = info->scope()->num_parameters();
294 int offset = num_parameters * kPointerSize;
296 __ addi(r6, fp, Operand(StandardFrameConstants::kCallerSPOffset + offset));
297 __ LoadSmiLiteral(r5, Smi::FromInt(num_parameters));
298 __ LoadSmiLiteral(r4, Smi::FromInt(rest_index));
299 __ LoadSmiLiteral(r3, Smi::FromInt(language_mode()));
300 __ Push(r6, r5, r4, r3);
302 RestParamAccessStub stub(isolate());
305 SetVar(rest_param, r3, r4, r5);
308 Variable* arguments = scope()->arguments();
309 if (arguments != NULL) {
310 // Function uses arguments object.
311 Comment cmnt(masm_, "[ Allocate arguments object");
312 if (!function_in_register) {
313 // Load this again, if it's used by the local context below.
314 __ LoadP(r6, MemOperand(fp, JavaScriptFrameConstants::kFunctionOffset));
318 // Receiver is just before the parameters on the caller's stack.
319 int num_parameters = info->scope()->num_parameters();
320 int offset = num_parameters * kPointerSize;
321 __ addi(r5, fp, Operand(StandardFrameConstants::kCallerSPOffset + offset));
322 __ LoadSmiLiteral(r4, Smi::FromInt(num_parameters));
325 // Arguments to ArgumentsAccessStub:
326 // function, receiver address, parameter count.
327 // The stub will rewrite receiver and parameter count if the previous
328 // stack frame was an arguments adapter frame.
329 ArgumentsAccessStub::Type type;
330 if (is_strict(language_mode()) || !has_simple_parameters()) {
331 type = ArgumentsAccessStub::NEW_STRICT;
332 } else if (literal()->has_duplicate_parameters()) {
333 type = ArgumentsAccessStub::NEW_SLOPPY_SLOW;
335 type = ArgumentsAccessStub::NEW_SLOPPY_FAST;
337 ArgumentsAccessStub stub(isolate(), type);
340 SetVar(arguments, r3, r4, r5);
344 __ CallRuntime(Runtime::kTraceEnter, 0);
347 // Visit the declarations and body unless there is an illegal
349 if (scope()->HasIllegalRedeclaration()) {
350 Comment cmnt(masm_, "[ Declarations");
351 scope()->VisitIllegalRedeclaration(this);
354 PrepareForBailoutForId(BailoutId::FunctionEntry(), NO_REGISTERS);
356 Comment cmnt(masm_, "[ Declarations");
357 VisitDeclarations(scope()->declarations());
360 // Assert that the declarations do not use ICs. Otherwise the debugger
361 // won't be able to redirect a PC at an IC to the correct IC in newly
363 DCHECK_EQ(0, ic_total_count_);
366 Comment cmnt(masm_, "[ Stack check");
367 PrepareForBailoutForId(BailoutId::Declarations(), NO_REGISTERS);
369 __ LoadRoot(ip, Heap::kStackLimitRootIndex);
371 __ bc_short(ge, &ok);
372 __ Call(isolate()->builtins()->StackCheck(), RelocInfo::CODE_TARGET);
377 Comment cmnt(masm_, "[ Body");
378 DCHECK(loop_depth() == 0);
379 VisitStatements(literal()->body());
380 DCHECK(loop_depth() == 0);
384 // Always emit a 'return undefined' in case control fell off the end of
387 Comment cmnt(masm_, "[ return <undefined>;");
388 __ LoadRoot(r3, Heap::kUndefinedValueRootIndex);
390 EmitReturnSequence();
392 if (HasStackOverflow()) {
393 masm_->AbortConstantPoolBuilding();
398 void FullCodeGenerator::ClearAccumulator() {
399 __ LoadSmiLiteral(r3, Smi::FromInt(0));
403 void FullCodeGenerator::EmitProfilingCounterDecrement(int delta) {
404 __ mov(r5, Operand(profiling_counter_));
405 __ LoadP(r6, FieldMemOperand(r5, Cell::kValueOffset));
406 __ SubSmiLiteral(r6, r6, Smi::FromInt(delta), r0);
407 __ StoreP(r6, FieldMemOperand(r5, Cell::kValueOffset), r0);
411 void FullCodeGenerator::EmitProfilingCounterReset() {
412 int reset_value = FLAG_interrupt_budget;
413 __ mov(r5, Operand(profiling_counter_));
414 __ LoadSmiLiteral(r6, Smi::FromInt(reset_value));
415 __ StoreP(r6, FieldMemOperand(r5, Cell::kValueOffset), r0);
419 void FullCodeGenerator::EmitBackEdgeBookkeeping(IterationStatement* stmt,
420 Label* back_edge_target) {
421 Comment cmnt(masm_, "[ Back edge bookkeeping");
424 DCHECK(back_edge_target->is_bound());
425 int distance = masm_->SizeOfCodeGeneratedSince(back_edge_target) +
426 kCodeSizeMultiplier / 2;
427 int weight = Min(kMaxBackEdgeWeight, Max(1, distance / kCodeSizeMultiplier));
428 EmitProfilingCounterDecrement(weight);
430 Assembler::BlockTrampolinePoolScope block_trampoline_pool(masm_);
431 Assembler::BlockConstantPoolEntrySharingScope prevent_entry_sharing(masm_);
432 // BackEdgeTable::PatchAt manipulates this sequence.
433 __ cmpi(r6, Operand::Zero());
434 __ bc_short(ge, &ok);
435 __ Call(isolate()->builtins()->InterruptCheck(), RelocInfo::CODE_TARGET);
437 // Record a mapping of this PC offset to the OSR id. This is used to find
438 // the AST id from the unoptimized code in order to use it as a key into
439 // the deoptimization input data found in the optimized code.
440 RecordBackEdge(stmt->OsrEntryId());
442 EmitProfilingCounterReset();
445 PrepareForBailoutForId(stmt->EntryId(), NO_REGISTERS);
446 // Record a mapping of the OSR id to this PC. This is used if the OSR
447 // entry becomes the target of a bailout. We don't expect it to be, but
448 // we want it to work if it is.
449 PrepareForBailoutForId(stmt->OsrEntryId(), NO_REGISTERS);
453 void FullCodeGenerator::EmitReturnSequence() {
454 Comment cmnt(masm_, "[ Return sequence");
455 if (return_label_.is_bound()) {
456 __ b(&return_label_);
458 __ bind(&return_label_);
460 // Push the return value on the stack as the parameter.
461 // Runtime::TraceExit returns its parameter in r3
463 __ CallRuntime(Runtime::kTraceExit, 1);
465 // Pretend that the exit is a backwards jump to the entry.
467 if (info_->ShouldSelfOptimize()) {
468 weight = FLAG_interrupt_budget / FLAG_self_opt_count;
470 int distance = masm_->pc_offset() + kCodeSizeMultiplier / 2;
471 weight = Min(kMaxBackEdgeWeight, Max(1, distance / kCodeSizeMultiplier));
473 EmitProfilingCounterDecrement(weight);
475 __ cmpi(r6, Operand::Zero());
478 __ Call(isolate()->builtins()->InterruptCheck(), RelocInfo::CODE_TARGET);
480 EmitProfilingCounterReset();
483 // Make sure that the constant pool is not emitted inside of the return
486 Assembler::BlockTrampolinePoolScope block_trampoline_pool(masm_);
487 int32_t arg_count = info_->scope()->num_parameters() + 1;
488 int32_t sp_delta = arg_count * kPointerSize;
489 SetReturnPosition(literal());
490 int no_frame_start = __ LeaveFrame(StackFrame::JAVA_SCRIPT, sp_delta);
492 info_->AddNoFrameRange(no_frame_start, masm_->pc_offset());
498 void FullCodeGenerator::StackValueContext::Plug(Variable* var) const {
499 DCHECK(var->IsStackAllocated() || var->IsContextSlot());
500 codegen()->GetVar(result_register(), var);
501 __ push(result_register());
505 void FullCodeGenerator::EffectContext::Plug(Heap::RootListIndex index) const {}
508 void FullCodeGenerator::AccumulatorValueContext::Plug(
509 Heap::RootListIndex index) const {
510 __ LoadRoot(result_register(), index);
514 void FullCodeGenerator::StackValueContext::Plug(
515 Heap::RootListIndex index) const {
516 __ LoadRoot(result_register(), index);
517 __ push(result_register());
521 void FullCodeGenerator::TestContext::Plug(Heap::RootListIndex index) const {
522 codegen()->PrepareForBailoutBeforeSplit(condition(), true, true_label_,
524 if (index == Heap::kUndefinedValueRootIndex ||
525 index == Heap::kNullValueRootIndex ||
526 index == Heap::kFalseValueRootIndex) {
527 if (false_label_ != fall_through_) __ b(false_label_);
528 } else if (index == Heap::kTrueValueRootIndex) {
529 if (true_label_ != fall_through_) __ b(true_label_);
531 __ LoadRoot(result_register(), index);
532 codegen()->DoTest(this);
537 void FullCodeGenerator::EffectContext::Plug(Handle<Object> lit) const {}
540 void FullCodeGenerator::AccumulatorValueContext::Plug(
541 Handle<Object> lit) const {
542 __ mov(result_register(), Operand(lit));
546 void FullCodeGenerator::StackValueContext::Plug(Handle<Object> lit) const {
547 // Immediates cannot be pushed directly.
548 __ mov(result_register(), Operand(lit));
549 __ push(result_register());
553 void FullCodeGenerator::TestContext::Plug(Handle<Object> lit) const {
554 codegen()->PrepareForBailoutBeforeSplit(condition(), true, true_label_,
556 DCHECK(!lit->IsUndetectableObject()); // There are no undetectable literals.
557 if (lit->IsUndefined() || lit->IsNull() || lit->IsFalse()) {
558 if (false_label_ != fall_through_) __ b(false_label_);
559 } else if (lit->IsTrue() || lit->IsJSObject()) {
560 if (true_label_ != fall_through_) __ b(true_label_);
561 } else if (lit->IsString()) {
562 if (String::cast(*lit)->length() == 0) {
563 if (false_label_ != fall_through_) __ b(false_label_);
565 if (true_label_ != fall_through_) __ b(true_label_);
567 } else if (lit->IsSmi()) {
568 if (Smi::cast(*lit)->value() == 0) {
569 if (false_label_ != fall_through_) __ b(false_label_);
571 if (true_label_ != fall_through_) __ b(true_label_);
574 // For simplicity we always test the accumulator register.
575 __ mov(result_register(), Operand(lit));
576 codegen()->DoTest(this);
581 void FullCodeGenerator::EffectContext::DropAndPlug(int count,
582 Register reg) const {
588 void FullCodeGenerator::AccumulatorValueContext::DropAndPlug(
589 int count, Register reg) const {
592 __ Move(result_register(), reg);
596 void FullCodeGenerator::StackValueContext::DropAndPlug(int count,
597 Register reg) const {
599 if (count > 1) __ Drop(count - 1);
600 __ StoreP(reg, MemOperand(sp, 0));
604 void FullCodeGenerator::TestContext::DropAndPlug(int count,
605 Register reg) const {
607 // For simplicity we always test the accumulator register.
609 __ Move(result_register(), reg);
610 codegen()->PrepareForBailoutBeforeSplit(condition(), false, NULL, NULL);
611 codegen()->DoTest(this);
615 void FullCodeGenerator::EffectContext::Plug(Label* materialize_true,
616 Label* materialize_false) const {
617 DCHECK(materialize_true == materialize_false);
618 __ bind(materialize_true);
622 void FullCodeGenerator::AccumulatorValueContext::Plug(
623 Label* materialize_true, Label* materialize_false) const {
625 __ bind(materialize_true);
626 __ LoadRoot(result_register(), Heap::kTrueValueRootIndex);
628 __ bind(materialize_false);
629 __ LoadRoot(result_register(), Heap::kFalseValueRootIndex);
634 void FullCodeGenerator::StackValueContext::Plug(
635 Label* materialize_true, Label* materialize_false) const {
637 __ bind(materialize_true);
638 __ LoadRoot(ip, Heap::kTrueValueRootIndex);
640 __ bind(materialize_false);
641 __ LoadRoot(ip, Heap::kFalseValueRootIndex);
647 void FullCodeGenerator::TestContext::Plug(Label* materialize_true,
648 Label* materialize_false) const {
649 DCHECK(materialize_true == true_label_);
650 DCHECK(materialize_false == false_label_);
654 void FullCodeGenerator::AccumulatorValueContext::Plug(bool flag) const {
655 Heap::RootListIndex value_root_index =
656 flag ? Heap::kTrueValueRootIndex : Heap::kFalseValueRootIndex;
657 __ LoadRoot(result_register(), value_root_index);
661 void FullCodeGenerator::StackValueContext::Plug(bool flag) const {
662 Heap::RootListIndex value_root_index =
663 flag ? Heap::kTrueValueRootIndex : Heap::kFalseValueRootIndex;
664 __ LoadRoot(ip, value_root_index);
669 void FullCodeGenerator::TestContext::Plug(bool flag) const {
670 codegen()->PrepareForBailoutBeforeSplit(condition(), true, true_label_,
673 if (true_label_ != fall_through_) __ b(true_label_);
675 if (false_label_ != fall_through_) __ b(false_label_);
680 void FullCodeGenerator::DoTest(Expression* condition, Label* if_true,
681 Label* if_false, Label* fall_through) {
682 Handle<Code> ic = ToBooleanStub::GetUninitialized(isolate());
683 CallIC(ic, condition->test_id());
684 __ cmpi(result_register(), Operand::Zero());
685 Split(ne, if_true, if_false, fall_through);
689 void FullCodeGenerator::Split(Condition cond, Label* if_true, Label* if_false,
690 Label* fall_through, CRegister cr) {
691 if (if_false == fall_through) {
692 __ b(cond, if_true, cr);
693 } else if (if_true == fall_through) {
694 __ b(NegateCondition(cond), if_false, cr);
696 __ b(cond, if_true, cr);
702 MemOperand FullCodeGenerator::StackOperand(Variable* var) {
703 DCHECK(var->IsStackAllocated());
704 // Offset is negative because higher indexes are at lower addresses.
705 int offset = -var->index() * kPointerSize;
706 // Adjust by a (parameter or local) base offset.
707 if (var->IsParameter()) {
708 offset += (info_->scope()->num_parameters() + 1) * kPointerSize;
710 offset += JavaScriptFrameConstants::kLocal0Offset;
712 return MemOperand(fp, offset);
716 MemOperand FullCodeGenerator::VarOperand(Variable* var, Register scratch) {
717 DCHECK(var->IsContextSlot() || var->IsStackAllocated());
718 if (var->IsContextSlot()) {
719 int context_chain_length = scope()->ContextChainLength(var->scope());
720 __ LoadContext(scratch, context_chain_length);
721 return ContextOperand(scratch, var->index());
723 return StackOperand(var);
728 void FullCodeGenerator::GetVar(Register dest, Variable* var) {
729 // Use destination as scratch.
730 MemOperand location = VarOperand(var, dest);
731 __ LoadP(dest, location, r0);
735 void FullCodeGenerator::SetVar(Variable* var, Register src, Register scratch0,
737 DCHECK(var->IsContextSlot() || var->IsStackAllocated());
738 DCHECK(!scratch0.is(src));
739 DCHECK(!scratch0.is(scratch1));
740 DCHECK(!scratch1.is(src));
741 MemOperand location = VarOperand(var, scratch0);
742 __ StoreP(src, location, r0);
744 // Emit the write barrier code if the location is in the heap.
745 if (var->IsContextSlot()) {
746 __ RecordWriteContextSlot(scratch0, location.offset(), src, scratch1,
747 kLRHasBeenSaved, kDontSaveFPRegs);
752 void FullCodeGenerator::PrepareForBailoutBeforeSplit(Expression* expr,
753 bool should_normalize,
756 // Only prepare for bailouts before splits if we're in a test
757 // context. Otherwise, we let the Visit function deal with the
758 // preparation to avoid preparing with the same AST id twice.
759 if (!context()->IsTest()) return;
762 if (should_normalize) __ b(&skip);
763 PrepareForBailout(expr, TOS_REG);
764 if (should_normalize) {
765 __ LoadRoot(ip, Heap::kTrueValueRootIndex);
767 Split(eq, if_true, if_false, NULL);
773 void FullCodeGenerator::EmitDebugCheckDeclarationContext(Variable* variable) {
774 // The variable in the declaration always resides in the current function
776 DCHECK_EQ(0, scope()->ContextChainLength(variable->scope()));
777 if (generate_debug_code_) {
778 // Check that we're not inside a with or catch context.
779 __ LoadP(r4, FieldMemOperand(cp, HeapObject::kMapOffset));
780 __ CompareRoot(r4, Heap::kWithContextMapRootIndex);
781 __ Check(ne, kDeclarationInWithContext);
782 __ CompareRoot(r4, Heap::kCatchContextMapRootIndex);
783 __ Check(ne, kDeclarationInCatchContext);
788 void FullCodeGenerator::VisitVariableDeclaration(
789 VariableDeclaration* declaration) {
790 // If it was not possible to allocate the variable at compile time, we
791 // need to "declare" it at runtime to make sure it actually exists in the
793 VariableProxy* proxy = declaration->proxy();
794 VariableMode mode = declaration->mode();
795 Variable* variable = proxy->var();
796 bool hole_init = mode == LET || mode == CONST || mode == CONST_LEGACY;
797 switch (variable->location()) {
798 case VariableLocation::GLOBAL:
799 case VariableLocation::UNALLOCATED:
800 globals_->Add(variable->name(), zone());
801 globals_->Add(variable->binding_needs_init()
802 ? isolate()->factory()->the_hole_value()
803 : isolate()->factory()->undefined_value(),
807 case VariableLocation::PARAMETER:
808 case VariableLocation::LOCAL:
810 Comment cmnt(masm_, "[ VariableDeclaration");
811 __ LoadRoot(ip, Heap::kTheHoleValueRootIndex);
812 __ StoreP(ip, StackOperand(variable));
816 case VariableLocation::CONTEXT:
818 Comment cmnt(masm_, "[ VariableDeclaration");
819 EmitDebugCheckDeclarationContext(variable);
820 __ LoadRoot(ip, Heap::kTheHoleValueRootIndex);
821 __ StoreP(ip, ContextOperand(cp, variable->index()), r0);
822 // No write barrier since the_hole_value is in old space.
823 PrepareForBailoutForId(proxy->id(), NO_REGISTERS);
827 case VariableLocation::LOOKUP: {
828 Comment cmnt(masm_, "[ VariableDeclaration");
829 __ mov(r5, Operand(variable->name()));
830 // Declaration nodes are always introduced in one of four modes.
831 DCHECK(IsDeclaredVariableMode(mode));
832 // Push initial value, if any.
833 // Note: For variables we must not push an initial value (such as
834 // 'undefined') because we may have a (legal) redeclaration and we
835 // must not destroy the current value.
837 __ LoadRoot(r3, Heap::kTheHoleValueRootIndex);
840 __ LoadSmiLiteral(r3, Smi::FromInt(0)); // Indicates no initial value.
843 __ CallRuntime(IsImmutableVariableMode(mode)
844 ? Runtime::kDeclareReadOnlyLookupSlot
845 : Runtime::kDeclareLookupSlot,
853 void FullCodeGenerator::VisitFunctionDeclaration(
854 FunctionDeclaration* declaration) {
855 VariableProxy* proxy = declaration->proxy();
856 Variable* variable = proxy->var();
857 switch (variable->location()) {
858 case VariableLocation::GLOBAL:
859 case VariableLocation::UNALLOCATED: {
860 globals_->Add(variable->name(), zone());
861 Handle<SharedFunctionInfo> function =
862 Compiler::GetSharedFunctionInfo(declaration->fun(), script(), info_);
863 // Check for stack-overflow exception.
864 if (function.is_null()) return SetStackOverflow();
865 globals_->Add(function, zone());
869 case VariableLocation::PARAMETER:
870 case VariableLocation::LOCAL: {
871 Comment cmnt(masm_, "[ FunctionDeclaration");
872 VisitForAccumulatorValue(declaration->fun());
873 __ StoreP(result_register(), StackOperand(variable));
877 case VariableLocation::CONTEXT: {
878 Comment cmnt(masm_, "[ FunctionDeclaration");
879 EmitDebugCheckDeclarationContext(variable);
880 VisitForAccumulatorValue(declaration->fun());
881 __ StoreP(result_register(), ContextOperand(cp, variable->index()), r0);
882 int offset = Context::SlotOffset(variable->index());
883 // We know that we have written a function, which is not a smi.
884 __ RecordWriteContextSlot(cp, offset, result_register(), r5,
885 kLRHasBeenSaved, kDontSaveFPRegs,
886 EMIT_REMEMBERED_SET, OMIT_SMI_CHECK);
887 PrepareForBailoutForId(proxy->id(), NO_REGISTERS);
891 case VariableLocation::LOOKUP: {
892 Comment cmnt(masm_, "[ FunctionDeclaration");
893 __ mov(r5, Operand(variable->name()));
895 // Push initial value for function declaration.
896 VisitForStackValue(declaration->fun());
897 __ CallRuntime(Runtime::kDeclareLookupSlot, 2);
904 void FullCodeGenerator::DeclareGlobals(Handle<FixedArray> pairs) {
905 // Call the runtime to declare the globals.
906 __ mov(r4, Operand(pairs));
907 __ LoadSmiLiteral(r3, Smi::FromInt(DeclareGlobalsFlags()));
909 __ CallRuntime(Runtime::kDeclareGlobals, 2);
910 // Return value is ignored.
914 void FullCodeGenerator::DeclareModules(Handle<FixedArray> descriptions) {
915 // Call the runtime to declare the modules.
916 __ Push(descriptions);
917 __ CallRuntime(Runtime::kDeclareModules, 1);
918 // Return value is ignored.
922 void FullCodeGenerator::VisitSwitchStatement(SwitchStatement* stmt) {
923 Comment cmnt(masm_, "[ SwitchStatement");
924 Breakable nested_statement(this, stmt);
925 SetStatementPosition(stmt);
927 // Keep the switch value on the stack until a case matches.
928 VisitForStackValue(stmt->tag());
929 PrepareForBailoutForId(stmt->EntryId(), NO_REGISTERS);
931 ZoneList<CaseClause*>* clauses = stmt->cases();
932 CaseClause* default_clause = NULL; // Can occur anywhere in the list.
934 Label next_test; // Recycled for each test.
935 // Compile all the tests with branches to their bodies.
936 for (int i = 0; i < clauses->length(); i++) {
937 CaseClause* clause = clauses->at(i);
938 clause->body_target()->Unuse();
940 // The default is not a test, but remember it as final fall through.
941 if (clause->is_default()) {
942 default_clause = clause;
946 Comment cmnt(masm_, "[ Case comparison");
950 // Compile the label expression.
951 VisitForAccumulatorValue(clause->label());
953 // Perform the comparison as if via '==='.
954 __ LoadP(r4, MemOperand(sp, 0)); // Switch value.
955 bool inline_smi_code = ShouldInlineSmiCase(Token::EQ_STRICT);
956 JumpPatchSite patch_site(masm_);
957 if (inline_smi_code) {
960 patch_site.EmitJumpIfNotSmi(r5, &slow_case);
964 __ Drop(1); // Switch value is no longer needed.
965 __ b(clause->body_target());
969 // Record position before stub call for type feedback.
970 SetExpressionPosition(clause);
971 Handle<Code> ic = CodeFactory::CompareIC(isolate(), Token::EQ_STRICT,
972 strength(language_mode())).code();
973 CallIC(ic, clause->CompareId());
974 patch_site.EmitPatchInfo();
978 PrepareForBailout(clause, TOS_REG);
979 __ LoadRoot(ip, Heap::kTrueValueRootIndex);
983 __ b(clause->body_target());
986 __ cmpi(r3, Operand::Zero());
988 __ Drop(1); // Switch value is no longer needed.
989 __ b(clause->body_target());
992 // Discard the test value and jump to the default if present, otherwise to
993 // the end of the statement.
995 __ Drop(1); // Switch value is no longer needed.
996 if (default_clause == NULL) {
997 __ b(nested_statement.break_label());
999 __ b(default_clause->body_target());
1002 // Compile all the case bodies.
1003 for (int i = 0; i < clauses->length(); i++) {
1004 Comment cmnt(masm_, "[ Case body");
1005 CaseClause* clause = clauses->at(i);
1006 __ bind(clause->body_target());
1007 PrepareForBailoutForId(clause->EntryId(), NO_REGISTERS);
1008 VisitStatements(clause->statements());
1011 __ bind(nested_statement.break_label());
1012 PrepareForBailoutForId(stmt->ExitId(), NO_REGISTERS);
1016 void FullCodeGenerator::VisitForInStatement(ForInStatement* stmt) {
1017 Comment cmnt(masm_, "[ ForInStatement");
1018 SetStatementPosition(stmt, SKIP_BREAK);
1020 FeedbackVectorSlot slot = stmt->ForInFeedbackSlot();
1023 ForIn loop_statement(this, stmt);
1024 increment_loop_depth();
1026 // Get the object to enumerate over. If the object is null or undefined, skip
1027 // over the loop. See ECMA-262 version 5, section 12.6.4.
1028 SetExpressionAsStatementPosition(stmt->enumerable());
1029 VisitForAccumulatorValue(stmt->enumerable());
1030 __ LoadRoot(ip, Heap::kUndefinedValueRootIndex);
1033 Register null_value = r7;
1034 __ LoadRoot(null_value, Heap::kNullValueRootIndex);
1035 __ cmp(r3, null_value);
1038 PrepareForBailoutForId(stmt->PrepareId(), TOS_REG);
1040 // Convert the object to a JS object.
1041 Label convert, done_convert;
1042 __ JumpIfSmi(r3, &convert);
1043 __ CompareObjectType(r3, r4, r4, FIRST_SPEC_OBJECT_TYPE);
1044 __ bge(&done_convert);
1046 ToObjectStub stub(isolate());
1048 __ bind(&done_convert);
1049 PrepareForBailoutForId(stmt->ToObjectId(), TOS_REG);
1052 // Check for proxies.
1054 STATIC_ASSERT(FIRST_JS_PROXY_TYPE == FIRST_SPEC_OBJECT_TYPE);
1055 __ CompareObjectType(r3, r4, r4, LAST_JS_PROXY_TYPE);
1056 __ ble(&call_runtime);
1058 // Check cache validity in generated code. This is a fast case for
1059 // the JSObject::IsSimpleEnum cache validity checks. If we cannot
1060 // guarantee cache validity, call the runtime system to check cache
1061 // validity or get the property names in a fixed array.
1062 __ CheckEnumCache(null_value, &call_runtime);
1064 // The enum cache is valid. Load the map of the object being
1065 // iterated over and use the cache for the iteration.
1067 __ LoadP(r3, FieldMemOperand(r3, HeapObject::kMapOffset));
1070 // Get the set of properties to enumerate.
1071 __ bind(&call_runtime);
1072 __ push(r3); // Duplicate the enumerable object on the stack.
1073 __ CallRuntime(Runtime::kGetPropertyNamesFast, 1);
1074 PrepareForBailoutForId(stmt->EnumId(), TOS_REG);
1076 // If we got a map from the runtime call, we can do a fast
1077 // modification check. Otherwise, we got a fixed array, and we have
1078 // to do a slow check.
1080 __ LoadP(r5, FieldMemOperand(r3, HeapObject::kMapOffset));
1081 __ LoadRoot(ip, Heap::kMetaMapRootIndex);
1083 __ bne(&fixed_array);
1085 // We got a map in register r3. Get the enumeration cache from it.
1086 Label no_descriptors;
1087 __ bind(&use_cache);
1089 __ EnumLength(r4, r3);
1090 __ CmpSmiLiteral(r4, Smi::FromInt(0), r0);
1091 __ beq(&no_descriptors);
1093 __ LoadInstanceDescriptors(r3, r5);
1094 __ LoadP(r5, FieldMemOperand(r5, DescriptorArray::kEnumCacheOffset));
1096 FieldMemOperand(r5, DescriptorArray::kEnumCacheBridgeCacheOffset));
1098 // Set up the four remaining stack slots.
1099 __ push(r3); // Map.
1100 __ LoadSmiLiteral(r3, Smi::FromInt(0));
1101 // Push enumeration cache, enumeration cache length (as smi) and zero.
1102 __ Push(r5, r4, r3);
1105 __ bind(&no_descriptors);
1109 // We got a fixed array in register r3. Iterate through that.
1111 __ bind(&fixed_array);
1113 __ Move(r4, FeedbackVector());
1114 __ mov(r5, Operand(TypeFeedbackVector::MegamorphicSentinel(isolate())));
1115 int vector_index = FeedbackVector()->GetIndex(slot);
1117 r5, FieldMemOperand(r4, FixedArray::OffsetOfElementAt(vector_index)), r0);
1119 __ LoadSmiLiteral(r4, Smi::FromInt(1)); // Smi indicates slow check
1120 __ LoadP(r5, MemOperand(sp, 0 * kPointerSize)); // Get enumerated object
1121 STATIC_ASSERT(FIRST_JS_PROXY_TYPE == FIRST_SPEC_OBJECT_TYPE);
1122 __ CompareObjectType(r5, r6, r6, LAST_JS_PROXY_TYPE);
1124 __ LoadSmiLiteral(r4, Smi::FromInt(0)); // Zero indicates proxy
1125 __ bind(&non_proxy);
1126 __ Push(r4, r3); // Smi and array
1127 __ LoadP(r4, FieldMemOperand(r3, FixedArray::kLengthOffset));
1128 __ LoadSmiLiteral(r3, Smi::FromInt(0));
1129 __ Push(r4, r3); // Fixed array length (as smi) and initial index.
1131 // Generate code for doing the condition check.
1132 PrepareForBailoutForId(stmt->BodyId(), NO_REGISTERS);
1134 SetExpressionAsStatementPosition(stmt->each());
1136 // Load the current count to r3, load the length to r4.
1137 __ LoadP(r3, MemOperand(sp, 0 * kPointerSize));
1138 __ LoadP(r4, MemOperand(sp, 1 * kPointerSize));
1139 __ cmpl(r3, r4); // Compare to the array length.
1140 __ bge(loop_statement.break_label());
1142 // Get the current entry of the array into register r6.
1143 __ LoadP(r5, MemOperand(sp, 2 * kPointerSize));
1144 __ addi(r5, r5, Operand(FixedArray::kHeaderSize - kHeapObjectTag));
1145 __ SmiToPtrArrayOffset(r6, r3);
1146 __ LoadPX(r6, MemOperand(r6, r5));
1148 // Get the expected map from the stack or a smi in the
1149 // permanent slow case into register r5.
1150 __ LoadP(r5, MemOperand(sp, 3 * kPointerSize));
1152 // Check if the expected map still matches that of the enumerable.
1153 // If not, we may have to filter the key.
1155 __ LoadP(r4, MemOperand(sp, 4 * kPointerSize));
1156 __ LoadP(r7, FieldMemOperand(r4, HeapObject::kMapOffset));
1158 __ beq(&update_each);
1160 // For proxies, no filtering is done.
1161 // TODO(rossberg): What if only a prototype is a proxy? Not specified yet.
1162 __ CmpSmiLiteral(r5, Smi::FromInt(0), r0);
1163 __ beq(&update_each);
1165 // Convert the entry to a string or (smi) 0 if it isn't a property
1166 // any more. If the property has been removed while iterating, we
1168 __ Push(r4, r6); // Enumerable and current entry.
1169 __ CallRuntime(Runtime::kForInFilter, 2);
1170 PrepareForBailoutForId(stmt->FilterId(), TOS_REG);
1172 __ LoadRoot(r0, Heap::kUndefinedValueRootIndex);
1174 __ beq(loop_statement.continue_label());
1176 // Update the 'each' property or variable from the possibly filtered
1177 // entry in register r6.
1178 __ bind(&update_each);
1179 __ mr(result_register(), r6);
1180 // Perform the assignment as if via '='.
1182 EffectContext context(this);
1183 EmitAssignment(stmt->each(), stmt->EachFeedbackSlot());
1184 PrepareForBailoutForId(stmt->AssignmentId(), NO_REGISTERS);
1187 // Generate code for the body of the loop.
1188 Visit(stmt->body());
1190 // Generate code for the going to the next element by incrementing
1191 // the index (smi) stored on top of the stack.
1192 __ bind(loop_statement.continue_label());
1194 __ AddSmiLiteral(r3, r3, Smi::FromInt(1), r0);
1197 EmitBackEdgeBookkeeping(stmt, &loop);
1200 // Remove the pointers stored on the stack.
1201 __ bind(loop_statement.break_label());
1204 // Exit and decrement the loop depth.
1205 PrepareForBailoutForId(stmt->ExitId(), NO_REGISTERS);
1207 decrement_loop_depth();
1211 void FullCodeGenerator::EmitNewClosure(Handle<SharedFunctionInfo> info,
1213 // Use the fast case closure allocation code that allocates in new
1214 // space for nested functions that don't need literals cloning. If
1215 // we're running with the --always-opt or the --prepare-always-opt
1216 // flag, we need to use the runtime function so that the new function
1217 // we are creating here gets a chance to have its code optimized and
1218 // doesn't just get a copy of the existing unoptimized code.
1219 if (!FLAG_always_opt && !FLAG_prepare_always_opt && !pretenure &&
1220 scope()->is_function_scope() && info->num_literals() == 0) {
1221 FastNewClosureStub stub(isolate(), info->language_mode(), info->kind());
1222 __ mov(r5, Operand(info));
1225 __ mov(r3, Operand(info));
1227 r4, pretenure ? Heap::kTrueValueRootIndex : Heap::kFalseValueRootIndex);
1228 __ Push(cp, r3, r4);
1229 __ CallRuntime(Runtime::kNewClosure, 3);
1231 context()->Plug(r3);
1235 void FullCodeGenerator::EmitSetHomeObjectIfNeeded(Expression* initializer,
1237 FeedbackVectorICSlot slot) {
1238 if (NeedsHomeObject(initializer)) {
1239 __ LoadP(StoreDescriptor::ReceiverRegister(), MemOperand(sp));
1240 __ mov(StoreDescriptor::NameRegister(),
1241 Operand(isolate()->factory()->home_object_symbol()));
1242 __ LoadP(StoreDescriptor::ValueRegister(),
1243 MemOperand(sp, offset * kPointerSize));
1244 if (FLAG_vector_stores) EmitLoadStoreICSlot(slot);
1250 void FullCodeGenerator::EmitLoadGlobalCheckExtensions(VariableProxy* proxy,
1251 TypeofMode typeof_mode,
1253 Register current = cp;
1259 if (s->num_heap_slots() > 0) {
1260 if (s->calls_sloppy_eval()) {
1261 // Check that extension is NULL.
1262 __ LoadP(temp, ContextOperand(current, Context::EXTENSION_INDEX));
1263 __ cmpi(temp, Operand::Zero());
1266 // Load next context in chain.
1267 __ LoadP(next, ContextOperand(current, Context::PREVIOUS_INDEX));
1268 // Walk the rest of the chain without clobbering cp.
1271 // If no outer scope calls eval, we do not need to check more
1272 // context extensions.
1273 if (!s->outer_scope_calls_sloppy_eval() || s->is_eval_scope()) break;
1274 s = s->outer_scope();
1277 if (s->is_eval_scope()) {
1279 if (!current.is(next)) {
1280 __ Move(next, current);
1283 // Terminate at native context.
1284 __ LoadP(temp, FieldMemOperand(next, HeapObject::kMapOffset));
1285 __ LoadRoot(ip, Heap::kNativeContextMapRootIndex);
1288 // Check that extension is NULL.
1289 __ LoadP(temp, ContextOperand(next, Context::EXTENSION_INDEX));
1290 __ cmpi(temp, Operand::Zero());
1292 // Load next context in chain.
1293 __ LoadP(next, ContextOperand(next, Context::PREVIOUS_INDEX));
1298 // All extension objects were empty and it is safe to use a normal global
1300 EmitGlobalVariableLoad(proxy, typeof_mode);
1304 MemOperand FullCodeGenerator::ContextSlotOperandCheckExtensions(Variable* var,
1306 DCHECK(var->IsContextSlot());
1307 Register context = cp;
1311 for (Scope* s = scope(); s != var->scope(); s = s->outer_scope()) {
1312 if (s->num_heap_slots() > 0) {
1313 if (s->calls_sloppy_eval()) {
1314 // Check that extension is NULL.
1315 __ LoadP(temp, ContextOperand(context, Context::EXTENSION_INDEX));
1316 __ cmpi(temp, Operand::Zero());
1319 __ LoadP(next, ContextOperand(context, Context::PREVIOUS_INDEX));
1320 // Walk the rest of the chain without clobbering cp.
1324 // Check that last extension is NULL.
1325 __ LoadP(temp, ContextOperand(context, Context::EXTENSION_INDEX));
1326 __ cmpi(temp, Operand::Zero());
1329 // This function is used only for loads, not stores, so it's safe to
1330 // return an cp-based operand (the write barrier cannot be allowed to
1331 // destroy the cp register).
1332 return ContextOperand(context, var->index());
1336 void FullCodeGenerator::EmitDynamicLookupFastCase(VariableProxy* proxy,
1337 TypeofMode typeof_mode,
1338 Label* slow, Label* done) {
1339 // Generate fast-case code for variables that might be shadowed by
1340 // eval-introduced variables. Eval is used a lot without
1341 // introducing variables. In those cases, we do not want to
1342 // perform a runtime call for all variables in the scope
1343 // containing the eval.
1344 Variable* var = proxy->var();
1345 if (var->mode() == DYNAMIC_GLOBAL) {
1346 EmitLoadGlobalCheckExtensions(proxy, typeof_mode, slow);
1348 } else if (var->mode() == DYNAMIC_LOCAL) {
1349 Variable* local = var->local_if_not_shadowed();
1350 __ LoadP(r3, ContextSlotOperandCheckExtensions(local, slow));
1351 if (local->mode() == LET || local->mode() == CONST ||
1352 local->mode() == CONST_LEGACY) {
1353 __ CompareRoot(r3, Heap::kTheHoleValueRootIndex);
1355 if (local->mode() == CONST_LEGACY) {
1356 __ LoadRoot(r3, Heap::kUndefinedValueRootIndex);
1357 } else { // LET || CONST
1358 __ mov(r3, Operand(var->name()));
1360 __ CallRuntime(Runtime::kThrowReferenceError, 1);
1368 void FullCodeGenerator::EmitGlobalVariableLoad(VariableProxy* proxy,
1369 TypeofMode typeof_mode) {
1370 Variable* var = proxy->var();
1371 DCHECK(var->IsUnallocatedOrGlobalSlot() ||
1372 (var->IsLookupSlot() && var->mode() == DYNAMIC_GLOBAL));
1373 if (var->IsGlobalSlot()) {
1374 DCHECK(var->index() > 0);
1375 DCHECK(var->IsStaticGlobalObjectProperty());
1376 const int slot = var->index();
1377 const int depth = scope()->ContextChainLength(var->scope());
1378 if (depth <= LoadGlobalViaContextStub::kMaximumDepth) {
1379 __ mov(LoadGlobalViaContextDescriptor::SlotRegister(), Operand(slot));
1380 LoadGlobalViaContextStub stub(isolate(), depth);
1383 __ Push(Smi::FromInt(slot));
1384 __ CallRuntime(Runtime::kLoadGlobalViaContext, 1);
1387 __ LoadP(LoadDescriptor::ReceiverRegister(), GlobalObjectOperand());
1388 __ mov(LoadDescriptor::NameRegister(), Operand(var->name()));
1389 __ mov(LoadDescriptor::SlotRegister(),
1390 Operand(SmiFromSlot(proxy->VariableFeedbackSlot())));
1391 CallLoadIC(typeof_mode);
1396 void FullCodeGenerator::EmitVariableLoad(VariableProxy* proxy,
1397 TypeofMode typeof_mode) {
1398 // Record position before possible IC call.
1399 SetExpressionPosition(proxy);
1400 PrepareForBailoutForId(proxy->BeforeId(), NO_REGISTERS);
1401 Variable* var = proxy->var();
1403 // Three cases: global variables, lookup variables, and all other types of
1405 switch (var->location()) {
1406 case VariableLocation::GLOBAL:
1407 case VariableLocation::UNALLOCATED: {
1408 Comment cmnt(masm_, "[ Global variable");
1409 EmitGlobalVariableLoad(proxy, typeof_mode);
1410 context()->Plug(r3);
1414 case VariableLocation::PARAMETER:
1415 case VariableLocation::LOCAL:
1416 case VariableLocation::CONTEXT: {
1417 DCHECK_EQ(NOT_INSIDE_TYPEOF, typeof_mode);
1418 Comment cmnt(masm_, var->IsContextSlot() ? "[ Context variable"
1419 : "[ Stack variable");
1420 if (var->binding_needs_init()) {
1421 // var->scope() may be NULL when the proxy is located in eval code and
1422 // refers to a potential outside binding. Currently those bindings are
1423 // always looked up dynamically, i.e. in that case
1424 // var->location() == LOOKUP.
1426 DCHECK(var->scope() != NULL);
1428 // Check if the binding really needs an initialization check. The check
1429 // can be skipped in the following situation: we have a LET or CONST
1430 // binding in harmony mode, both the Variable and the VariableProxy have
1431 // the same declaration scope (i.e. they are both in global code, in the
1432 // same function or in the same eval code) and the VariableProxy is in
1433 // the source physically located after the initializer of the variable.
1435 // We cannot skip any initialization checks for CONST in non-harmony
1436 // mode because const variables may be declared but never initialized:
1437 // if (false) { const x; }; var y = x;
1439 // The condition on the declaration scopes is a conservative check for
1440 // nested functions that access a binding and are called before the
1441 // binding is initialized:
1442 // function() { f(); let x = 1; function f() { x = 2; } }
1444 bool skip_init_check;
1445 if (var->scope()->DeclarationScope() != scope()->DeclarationScope()) {
1446 skip_init_check = false;
1447 } else if (var->is_this()) {
1448 CHECK(info_->has_literal() &&
1449 (info_->literal()->kind() & kSubclassConstructor) != 0);
1450 // TODO(dslomov): implement 'this' hole check elimination.
1451 skip_init_check = false;
1453 // Check that we always have valid source position.
1454 DCHECK(var->initializer_position() != RelocInfo::kNoPosition);
1455 DCHECK(proxy->position() != RelocInfo::kNoPosition);
1456 skip_init_check = var->mode() != CONST_LEGACY &&
1457 var->initializer_position() < proxy->position();
1460 if (!skip_init_check) {
1462 // Let and const need a read barrier.
1464 __ CompareRoot(r3, Heap::kTheHoleValueRootIndex);
1466 if (var->mode() == LET || var->mode() == CONST) {
1467 // Throw a reference error when using an uninitialized let/const
1468 // binding in harmony mode.
1469 __ mov(r3, Operand(var->name()));
1471 __ CallRuntime(Runtime::kThrowReferenceError, 1);
1473 // Uninitalized const bindings outside of harmony mode are unholed.
1474 DCHECK(var->mode() == CONST_LEGACY);
1475 __ LoadRoot(r3, Heap::kUndefinedValueRootIndex);
1478 context()->Plug(r3);
1482 context()->Plug(var);
1486 case VariableLocation::LOOKUP: {
1487 Comment cmnt(masm_, "[ Lookup variable");
1489 // Generate code for loading from variables potentially shadowed
1490 // by eval-introduced variables.
1491 EmitDynamicLookupFastCase(proxy, typeof_mode, &slow, &done);
1493 __ mov(r4, Operand(var->name()));
1494 __ Push(cp, r4); // Context and name.
1495 Runtime::FunctionId function_id =
1496 typeof_mode == NOT_INSIDE_TYPEOF
1497 ? Runtime::kLoadLookupSlot
1498 : Runtime::kLoadLookupSlotNoReferenceError;
1499 __ CallRuntime(function_id, 2);
1501 context()->Plug(r3);
1507 void FullCodeGenerator::VisitRegExpLiteral(RegExpLiteral* expr) {
1508 Comment cmnt(masm_, "[ RegExpLiteral");
1510 // Registers will be used as follows:
1511 // r8 = materialized value (RegExp literal)
1512 // r7 = JS function, literals array
1513 // r6 = literal index
1514 // r5 = RegExp pattern
1515 // r4 = RegExp flags
1516 // r3 = RegExp literal clone
1517 __ LoadP(r3, MemOperand(fp, JavaScriptFrameConstants::kFunctionOffset));
1518 __ LoadP(r7, FieldMemOperand(r3, JSFunction::kLiteralsOffset));
1519 int literal_offset =
1520 FixedArray::kHeaderSize + expr->literal_index() * kPointerSize;
1521 __ LoadP(r8, FieldMemOperand(r7, literal_offset), r0);
1522 __ LoadRoot(ip, Heap::kUndefinedValueRootIndex);
1524 __ bne(&materialized);
1526 // Create regexp literal using runtime function.
1527 // Result will be in r3.
1528 __ LoadSmiLiteral(r6, Smi::FromInt(expr->literal_index()));
1529 __ mov(r5, Operand(expr->pattern()));
1530 __ mov(r4, Operand(expr->flags()));
1531 __ Push(r7, r6, r5, r4);
1532 __ CallRuntime(Runtime::kMaterializeRegExpLiteral, 4);
1535 __ bind(&materialized);
1536 int size = JSRegExp::kSize + JSRegExp::kInObjectFieldCount * kPointerSize;
1537 Label allocated, runtime_allocate;
1538 __ Allocate(size, r3, r5, r6, &runtime_allocate, TAG_OBJECT);
1541 __ bind(&runtime_allocate);
1542 __ LoadSmiLiteral(r3, Smi::FromInt(size));
1544 __ CallRuntime(Runtime::kAllocateInNewSpace, 1);
1547 __ bind(&allocated);
1548 // After this, registers are used as follows:
1549 // r3: Newly allocated regexp.
1550 // r8: Materialized regexp.
1552 __ CopyFields(r3, r8, r5.bit(), size / kPointerSize);
1553 context()->Plug(r3);
1557 void FullCodeGenerator::EmitAccessor(Expression* expression) {
1558 if (expression == NULL) {
1559 __ LoadRoot(r4, Heap::kNullValueRootIndex);
1562 VisitForStackValue(expression);
1567 void FullCodeGenerator::VisitObjectLiteral(ObjectLiteral* expr) {
1568 Comment cmnt(masm_, "[ ObjectLiteral");
1570 Handle<FixedArray> constant_properties = expr->constant_properties();
1571 __ LoadP(r6, MemOperand(fp, JavaScriptFrameConstants::kFunctionOffset));
1572 __ LoadP(r6, FieldMemOperand(r6, JSFunction::kLiteralsOffset));
1573 __ LoadSmiLiteral(r5, Smi::FromInt(expr->literal_index()));
1574 __ mov(r4, Operand(constant_properties));
1575 int flags = expr->ComputeFlags();
1576 __ LoadSmiLiteral(r3, Smi::FromInt(flags));
1577 if (MustCreateObjectLiteralWithRuntime(expr)) {
1578 __ Push(r6, r5, r4, r3);
1579 __ CallRuntime(Runtime::kCreateObjectLiteral, 4);
1581 FastCloneShallowObjectStub stub(isolate(), expr->properties_count());
1584 PrepareForBailoutForId(expr->CreateLiteralId(), TOS_REG);
1586 // If result_saved is true the result is on top of the stack. If
1587 // result_saved is false the result is in r3.
1588 bool result_saved = false;
1590 AccessorTable accessor_table(zone());
1591 int property_index = 0;
1592 // store_slot_index points to the vector IC slot for the next store IC used.
1593 // ObjectLiteral::ComputeFeedbackRequirements controls the allocation of slots
1594 // and must be updated if the number of store ICs emitted here changes.
1595 int store_slot_index = 0;
1596 for (; property_index < expr->properties()->length(); property_index++) {
1597 ObjectLiteral::Property* property = expr->properties()->at(property_index);
1598 if (property->is_computed_name()) break;
1599 if (property->IsCompileTimeValue()) continue;
1601 Literal* key = property->key()->AsLiteral();
1602 Expression* value = property->value();
1603 if (!result_saved) {
1604 __ push(r3); // Save result on stack
1605 result_saved = true;
1607 switch (property->kind()) {
1608 case ObjectLiteral::Property::CONSTANT:
1610 case ObjectLiteral::Property::MATERIALIZED_LITERAL:
1611 DCHECK(!CompileTimeValue::IsCompileTimeValue(property->value()));
1613 case ObjectLiteral::Property::COMPUTED:
1614 // It is safe to use [[Put]] here because the boilerplate already
1615 // contains computed properties with an uninitialized value.
1616 if (key->value()->IsInternalizedString()) {
1617 if (property->emit_store()) {
1618 VisitForAccumulatorValue(value);
1619 DCHECK(StoreDescriptor::ValueRegister().is(r3));
1620 __ mov(StoreDescriptor::NameRegister(), Operand(key->value()));
1621 __ LoadP(StoreDescriptor::ReceiverRegister(), MemOperand(sp));
1622 if (FLAG_vector_stores) {
1623 EmitLoadStoreICSlot(expr->GetNthSlot(store_slot_index++));
1626 CallStoreIC(key->LiteralFeedbackId());
1628 PrepareForBailoutForId(key->id(), NO_REGISTERS);
1630 if (NeedsHomeObject(value)) {
1631 __ Move(StoreDescriptor::ReceiverRegister(), r3);
1632 __ mov(StoreDescriptor::NameRegister(),
1633 Operand(isolate()->factory()->home_object_symbol()));
1634 __ LoadP(StoreDescriptor::ValueRegister(), MemOperand(sp));
1635 if (FLAG_vector_stores) {
1636 EmitLoadStoreICSlot(expr->GetNthSlot(store_slot_index++));
1641 VisitForEffect(value);
1645 // Duplicate receiver on stack.
1646 __ LoadP(r3, MemOperand(sp));
1648 VisitForStackValue(key);
1649 VisitForStackValue(value);
1650 if (property->emit_store()) {
1651 EmitSetHomeObjectIfNeeded(
1652 value, 2, expr->SlotForHomeObject(value, &store_slot_index));
1653 __ LoadSmiLiteral(r3, Smi::FromInt(SLOPPY)); // PropertyAttributes
1655 __ CallRuntime(Runtime::kSetProperty, 4);
1660 case ObjectLiteral::Property::PROTOTYPE:
1661 // Duplicate receiver on stack.
1662 __ LoadP(r3, MemOperand(sp));
1664 VisitForStackValue(value);
1665 DCHECK(property->emit_store());
1666 __ CallRuntime(Runtime::kInternalSetPrototype, 2);
1668 case ObjectLiteral::Property::GETTER:
1669 if (property->emit_store()) {
1670 accessor_table.lookup(key)->second->getter = value;
1673 case ObjectLiteral::Property::SETTER:
1674 if (property->emit_store()) {
1675 accessor_table.lookup(key)->second->setter = value;
1681 // Emit code to define accessors, using only a single call to the runtime for
1682 // each pair of corresponding getters and setters.
1683 for (AccessorTable::Iterator it = accessor_table.begin();
1684 it != accessor_table.end(); ++it) {
1685 __ LoadP(r3, MemOperand(sp)); // Duplicate receiver.
1687 VisitForStackValue(it->first);
1688 EmitAccessor(it->second->getter);
1689 EmitSetHomeObjectIfNeeded(
1690 it->second->getter, 2,
1691 expr->SlotForHomeObject(it->second->getter, &store_slot_index));
1692 EmitAccessor(it->second->setter);
1693 EmitSetHomeObjectIfNeeded(
1694 it->second->setter, 3,
1695 expr->SlotForHomeObject(it->second->setter, &store_slot_index));
1696 __ LoadSmiLiteral(r3, Smi::FromInt(NONE));
1698 __ CallRuntime(Runtime::kDefineAccessorPropertyUnchecked, 5);
1701 // Object literals have two parts. The "static" part on the left contains no
1702 // computed property names, and so we can compute its map ahead of time; see
1703 // runtime.cc::CreateObjectLiteralBoilerplate. The second "dynamic" part
1704 // starts with the first computed property name, and continues with all
1705 // properties to its right. All the code from above initializes the static
1706 // component of the object literal, and arranges for the map of the result to
1707 // reflect the static order in which the keys appear. For the dynamic
1708 // properties, we compile them into a series of "SetOwnProperty" runtime
1709 // calls. This will preserve insertion order.
1710 for (; property_index < expr->properties()->length(); property_index++) {
1711 ObjectLiteral::Property* property = expr->properties()->at(property_index);
1713 Expression* value = property->value();
1714 if (!result_saved) {
1715 __ push(r3); // Save result on the stack
1716 result_saved = true;
1719 __ LoadP(r3, MemOperand(sp)); // Duplicate receiver.
1722 if (property->kind() == ObjectLiteral::Property::PROTOTYPE) {
1723 DCHECK(!property->is_computed_name());
1724 VisitForStackValue(value);
1725 DCHECK(property->emit_store());
1726 __ CallRuntime(Runtime::kInternalSetPrototype, 2);
1728 EmitPropertyKey(property, expr->GetIdForProperty(property_index));
1729 VisitForStackValue(value);
1730 EmitSetHomeObjectIfNeeded(
1731 value, 2, expr->SlotForHomeObject(value, &store_slot_index));
1733 switch (property->kind()) {
1734 case ObjectLiteral::Property::CONSTANT:
1735 case ObjectLiteral::Property::MATERIALIZED_LITERAL:
1736 case ObjectLiteral::Property::COMPUTED:
1737 if (property->emit_store()) {
1738 __ LoadSmiLiteral(r3, Smi::FromInt(NONE));
1740 __ CallRuntime(Runtime::kDefineDataPropertyUnchecked, 4);
1746 case ObjectLiteral::Property::PROTOTYPE:
1750 case ObjectLiteral::Property::GETTER:
1751 __ mov(r3, Operand(Smi::FromInt(NONE)));
1753 __ CallRuntime(Runtime::kDefineGetterPropertyUnchecked, 4);
1756 case ObjectLiteral::Property::SETTER:
1757 __ mov(r3, Operand(Smi::FromInt(NONE)));
1759 __ CallRuntime(Runtime::kDefineSetterPropertyUnchecked, 4);
1765 if (expr->has_function()) {
1766 DCHECK(result_saved);
1767 __ LoadP(r3, MemOperand(sp));
1769 __ CallRuntime(Runtime::kToFastProperties, 1);
1773 context()->PlugTOS();
1775 context()->Plug(r3);
1778 // Verify that compilation exactly consumed the number of store ic slots that
1779 // the ObjectLiteral node had to offer.
1780 DCHECK(!FLAG_vector_stores || store_slot_index == expr->slot_count());
1784 void FullCodeGenerator::VisitArrayLiteral(ArrayLiteral* expr) {
1785 Comment cmnt(masm_, "[ ArrayLiteral");
1787 expr->BuildConstantElements(isolate());
1788 Handle<FixedArray> constant_elements = expr->constant_elements();
1789 bool has_fast_elements =
1790 IsFastObjectElementsKind(expr->constant_elements_kind());
1791 Handle<FixedArrayBase> constant_elements_values(
1792 FixedArrayBase::cast(constant_elements->get(1)));
1794 AllocationSiteMode allocation_site_mode = TRACK_ALLOCATION_SITE;
1795 if (has_fast_elements && !FLAG_allocation_site_pretenuring) {
1796 // If the only customer of allocation sites is transitioning, then
1797 // we can turn it off if we don't have anywhere else to transition to.
1798 allocation_site_mode = DONT_TRACK_ALLOCATION_SITE;
1801 __ LoadP(r6, MemOperand(fp, JavaScriptFrameConstants::kFunctionOffset));
1802 __ LoadP(r6, FieldMemOperand(r6, JSFunction::kLiteralsOffset));
1803 __ LoadSmiLiteral(r5, Smi::FromInt(expr->literal_index()));
1804 __ mov(r4, Operand(constant_elements));
1805 if (MustCreateArrayLiteralWithRuntime(expr)) {
1806 __ LoadSmiLiteral(r3, Smi::FromInt(expr->ComputeFlags()));
1807 __ Push(r6, r5, r4, r3);
1808 __ CallRuntime(Runtime::kCreateArrayLiteral, 4);
1810 FastCloneShallowArrayStub stub(isolate(), allocation_site_mode);
1813 PrepareForBailoutForId(expr->CreateLiteralId(), TOS_REG);
1815 bool result_saved = false; // Is the result saved to the stack?
1816 ZoneList<Expression*>* subexprs = expr->values();
1817 int length = subexprs->length();
1819 // Emit code to evaluate all the non-constant subexpressions and to store
1820 // them into the newly cloned array.
1821 int array_index = 0;
1822 for (; array_index < length; array_index++) {
1823 Expression* subexpr = subexprs->at(array_index);
1824 if (subexpr->IsSpread()) break;
1825 // If the subexpression is a literal or a simple materialized literal it
1826 // is already set in the cloned array.
1827 if (CompileTimeValue::IsCompileTimeValue(subexpr)) continue;
1829 if (!result_saved) {
1831 __ Push(Smi::FromInt(expr->literal_index()));
1832 result_saved = true;
1834 VisitForAccumulatorValue(subexpr);
1836 if (has_fast_elements) {
1837 int offset = FixedArray::kHeaderSize + (array_index * kPointerSize);
1838 __ LoadP(r8, MemOperand(sp, kPointerSize)); // Copy of array literal.
1839 __ LoadP(r4, FieldMemOperand(r8, JSObject::kElementsOffset));
1840 __ StoreP(result_register(), FieldMemOperand(r4, offset), r0);
1841 // Update the write barrier for the array store.
1842 __ RecordWriteField(r4, offset, result_register(), r5, kLRHasBeenSaved,
1843 kDontSaveFPRegs, EMIT_REMEMBERED_SET,
1846 __ LoadSmiLiteral(r6, Smi::FromInt(array_index));
1847 StoreArrayLiteralElementStub stub(isolate());
1851 PrepareForBailoutForId(expr->GetIdForElement(array_index), NO_REGISTERS);
1854 // In case the array literal contains spread expressions it has two parts. The
1855 // first part is the "static" array which has a literal index is handled
1856 // above. The second part is the part after the first spread expression
1857 // (inclusive) and these elements gets appended to the array. Note that the
1858 // number elements an iterable produces is unknown ahead of time.
1859 if (array_index < length && result_saved) {
1860 __ Drop(1); // literal index
1862 result_saved = false;
1864 for (; array_index < length; array_index++) {
1865 Expression* subexpr = subexprs->at(array_index);
1868 if (subexpr->IsSpread()) {
1869 VisitForStackValue(subexpr->AsSpread()->expression());
1870 __ InvokeBuiltin(Context::CONCAT_ITERABLE_TO_ARRAY_BUILTIN_INDEX,
1873 VisitForStackValue(subexpr);
1874 __ CallRuntime(Runtime::kAppendElement, 2);
1877 PrepareForBailoutForId(expr->GetIdForElement(array_index), NO_REGISTERS);
1881 __ Drop(1); // literal index
1882 context()->PlugTOS();
1884 context()->Plug(r3);
1889 void FullCodeGenerator::VisitAssignment(Assignment* expr) {
1890 DCHECK(expr->target()->IsValidReferenceExpressionOrThis());
1892 Comment cmnt(masm_, "[ Assignment");
1893 SetExpressionPosition(expr, INSERT_BREAK);
1895 Property* property = expr->target()->AsProperty();
1896 LhsKind assign_type = Property::GetAssignType(property);
1898 // Evaluate LHS expression.
1899 switch (assign_type) {
1901 // Nothing to do here.
1903 case NAMED_PROPERTY:
1904 if (expr->is_compound()) {
1905 // We need the receiver both on the stack and in the register.
1906 VisitForStackValue(property->obj());
1907 __ LoadP(LoadDescriptor::ReceiverRegister(), MemOperand(sp, 0));
1909 VisitForStackValue(property->obj());
1912 case NAMED_SUPER_PROPERTY:
1914 property->obj()->AsSuperPropertyReference()->this_var());
1915 VisitForAccumulatorValue(
1916 property->obj()->AsSuperPropertyReference()->home_object());
1917 __ Push(result_register());
1918 if (expr->is_compound()) {
1919 const Register scratch = r4;
1920 __ LoadP(scratch, MemOperand(sp, kPointerSize));
1921 __ Push(scratch, result_register());
1924 case KEYED_SUPER_PROPERTY: {
1925 const Register scratch = r4;
1927 property->obj()->AsSuperPropertyReference()->this_var());
1928 VisitForAccumulatorValue(
1929 property->obj()->AsSuperPropertyReference()->home_object());
1930 __ mr(scratch, result_register());
1931 VisitForAccumulatorValue(property->key());
1932 __ Push(scratch, result_register());
1933 if (expr->is_compound()) {
1934 const Register scratch1 = r5;
1935 __ LoadP(scratch1, MemOperand(sp, 2 * kPointerSize));
1936 __ Push(scratch1, scratch, result_register());
1940 case KEYED_PROPERTY:
1941 if (expr->is_compound()) {
1942 VisitForStackValue(property->obj());
1943 VisitForStackValue(property->key());
1944 __ LoadP(LoadDescriptor::ReceiverRegister(),
1945 MemOperand(sp, 1 * kPointerSize));
1946 __ LoadP(LoadDescriptor::NameRegister(), MemOperand(sp, 0));
1948 VisitForStackValue(property->obj());
1949 VisitForStackValue(property->key());
1954 // For compound assignments we need another deoptimization point after the
1955 // variable/property load.
1956 if (expr->is_compound()) {
1958 AccumulatorValueContext context(this);
1959 switch (assign_type) {
1961 EmitVariableLoad(expr->target()->AsVariableProxy());
1962 PrepareForBailout(expr->target(), TOS_REG);
1964 case NAMED_PROPERTY:
1965 EmitNamedPropertyLoad(property);
1966 PrepareForBailoutForId(property->LoadId(), TOS_REG);
1968 case NAMED_SUPER_PROPERTY:
1969 EmitNamedSuperPropertyLoad(property);
1970 PrepareForBailoutForId(property->LoadId(), TOS_REG);
1972 case KEYED_SUPER_PROPERTY:
1973 EmitKeyedSuperPropertyLoad(property);
1974 PrepareForBailoutForId(property->LoadId(), TOS_REG);
1976 case KEYED_PROPERTY:
1977 EmitKeyedPropertyLoad(property);
1978 PrepareForBailoutForId(property->LoadId(), TOS_REG);
1983 Token::Value op = expr->binary_op();
1984 __ push(r3); // Left operand goes on the stack.
1985 VisitForAccumulatorValue(expr->value());
1987 AccumulatorValueContext context(this);
1988 if (ShouldInlineSmiCase(op)) {
1989 EmitInlineSmiBinaryOp(expr->binary_operation(), op, expr->target(),
1992 EmitBinaryOp(expr->binary_operation(), op);
1995 // Deoptimization point in case the binary operation may have side effects.
1996 PrepareForBailout(expr->binary_operation(), TOS_REG);
1998 VisitForAccumulatorValue(expr->value());
2001 SetExpressionPosition(expr);
2004 switch (assign_type) {
2006 EmitVariableAssignment(expr->target()->AsVariableProxy()->var(),
2007 expr->op(), expr->AssignmentSlot());
2008 PrepareForBailoutForId(expr->AssignmentId(), TOS_REG);
2009 context()->Plug(r3);
2011 case NAMED_PROPERTY:
2012 EmitNamedPropertyAssignment(expr);
2014 case NAMED_SUPER_PROPERTY:
2015 EmitNamedSuperPropertyStore(property);
2016 context()->Plug(r3);
2018 case KEYED_SUPER_PROPERTY:
2019 EmitKeyedSuperPropertyStore(property);
2020 context()->Plug(r3);
2022 case KEYED_PROPERTY:
2023 EmitKeyedPropertyAssignment(expr);
2029 void FullCodeGenerator::VisitYield(Yield* expr) {
2030 Comment cmnt(masm_, "[ Yield");
2031 SetExpressionPosition(expr);
2033 // Evaluate yielded value first; the initial iterator definition depends on
2034 // this. It stays on the stack while we update the iterator.
2035 VisitForStackValue(expr->expression());
2037 switch (expr->yield_kind()) {
2038 case Yield::kSuspend:
2039 // Pop value from top-of-stack slot; box result into result register.
2040 EmitCreateIteratorResult(false);
2041 __ push(result_register());
2043 case Yield::kInitial: {
2044 Label suspend, continuation, post_runtime, resume;
2047 __ bind(&continuation);
2048 __ RecordGeneratorContinuation();
2052 VisitForAccumulatorValue(expr->generator_object());
2053 DCHECK(continuation.pos() > 0 && Smi::IsValid(continuation.pos()));
2054 __ LoadSmiLiteral(r4, Smi::FromInt(continuation.pos()));
2055 __ StoreP(r4, FieldMemOperand(r3, JSGeneratorObject::kContinuationOffset),
2057 __ StoreP(cp, FieldMemOperand(r3, JSGeneratorObject::kContextOffset), r0);
2059 __ RecordWriteField(r3, JSGeneratorObject::kContextOffset, r4, r5,
2060 kLRHasBeenSaved, kDontSaveFPRegs);
2061 __ addi(r4, fp, Operand(StandardFrameConstants::kExpressionsOffset));
2063 __ beq(&post_runtime);
2064 __ push(r3); // generator object
2065 __ CallRuntime(Runtime::kSuspendJSGeneratorObject, 1);
2066 __ LoadP(cp, MemOperand(fp, StandardFrameConstants::kContextOffset));
2067 __ bind(&post_runtime);
2068 __ pop(result_register());
2069 EmitReturnSequence();
2072 context()->Plug(result_register());
2076 case Yield::kFinal: {
2077 VisitForAccumulatorValue(expr->generator_object());
2078 __ LoadSmiLiteral(r4, Smi::FromInt(JSGeneratorObject::kGeneratorClosed));
2079 __ StoreP(r4, FieldMemOperand(result_register(),
2080 JSGeneratorObject::kContinuationOffset),
2082 // Pop value from top-of-stack slot, box result into result register.
2083 EmitCreateIteratorResult(true);
2084 EmitUnwindBeforeReturn();
2085 EmitReturnSequence();
2089 case Yield::kDelegating: {
2090 VisitForStackValue(expr->generator_object());
2092 // Initial stack layout is as follows:
2093 // [sp + 1 * kPointerSize] iter
2094 // [sp + 0 * kPointerSize] g
2096 Label l_catch, l_try, l_suspend, l_continuation, l_resume;
2097 Label l_next, l_call;
2098 Register load_receiver = LoadDescriptor::ReceiverRegister();
2099 Register load_name = LoadDescriptor::NameRegister();
2101 // Initial send value is undefined.
2102 __ LoadRoot(r3, Heap::kUndefinedValueRootIndex);
2105 // catch (e) { receiver = iter; f = 'throw'; arg = e; goto l_call; }
2107 __ LoadRoot(load_name, Heap::kthrow_stringRootIndex); // "throw"
2108 __ LoadP(r6, MemOperand(sp, 1 * kPointerSize)); // iter
2109 __ Push(load_name, r6, r3); // "throw", iter, except
2112 // try { received = %yield result }
2113 // Shuffle the received result above a try handler and yield it without
2116 __ pop(r3); // result
2117 int handler_index = NewHandlerTableEntry();
2118 EnterTryBlock(handler_index, &l_catch);
2119 const int try_block_size = TryCatch::kElementCount * kPointerSize;
2120 __ push(r3); // result
2123 __ bind(&l_continuation);
2124 __ RecordGeneratorContinuation();
2127 __ bind(&l_suspend);
2128 const int generator_object_depth = kPointerSize + try_block_size;
2129 __ LoadP(r3, MemOperand(sp, generator_object_depth));
2131 __ Push(Smi::FromInt(handler_index)); // handler-index
2132 DCHECK(l_continuation.pos() > 0 && Smi::IsValid(l_continuation.pos()));
2133 __ LoadSmiLiteral(r4, Smi::FromInt(l_continuation.pos()));
2134 __ StoreP(r4, FieldMemOperand(r3, JSGeneratorObject::kContinuationOffset),
2136 __ StoreP(cp, FieldMemOperand(r3, JSGeneratorObject::kContextOffset), r0);
2138 __ RecordWriteField(r3, JSGeneratorObject::kContextOffset, r4, r5,
2139 kLRHasBeenSaved, kDontSaveFPRegs);
2140 __ CallRuntime(Runtime::kSuspendJSGeneratorObject, 2);
2141 __ LoadP(cp, MemOperand(fp, StandardFrameConstants::kContextOffset));
2142 __ pop(r3); // result
2143 EmitReturnSequence();
2144 __ bind(&l_resume); // received in r3
2145 ExitTryBlock(handler_index);
2147 // receiver = iter; f = 'next'; arg = received;
2150 __ LoadRoot(load_name, Heap::knext_stringRootIndex); // "next"
2151 __ LoadP(r6, MemOperand(sp, 1 * kPointerSize)); // iter
2152 __ Push(load_name, r6, r3); // "next", iter, received
2154 // result = receiver[f](arg);
2156 __ LoadP(load_receiver, MemOperand(sp, kPointerSize));
2157 __ LoadP(load_name, MemOperand(sp, 2 * kPointerSize));
2158 __ mov(LoadDescriptor::SlotRegister(),
2159 Operand(SmiFromSlot(expr->KeyedLoadFeedbackSlot())));
2160 Handle<Code> ic = CodeFactory::KeyedLoadIC(isolate(), SLOPPY).code();
2161 CallIC(ic, TypeFeedbackId::None());
2163 __ StoreP(r4, MemOperand(sp, 2 * kPointerSize));
2164 SetCallPosition(expr, 1);
2165 CallFunctionStub stub(isolate(), 1, CALL_AS_METHOD);
2168 __ LoadP(cp, MemOperand(fp, StandardFrameConstants::kContextOffset));
2169 __ Drop(1); // The function is still on the stack; drop it.
2171 // if (!result.done) goto l_try;
2172 __ Move(load_receiver, r3);
2174 __ push(load_receiver); // save result
2175 __ LoadRoot(load_name, Heap::kdone_stringRootIndex); // "done"
2176 __ mov(LoadDescriptor::SlotRegister(),
2177 Operand(SmiFromSlot(expr->DoneFeedbackSlot())));
2178 CallLoadIC(NOT_INSIDE_TYPEOF); // r0=result.done
2179 Handle<Code> bool_ic = ToBooleanStub::GetUninitialized(isolate());
2181 __ cmpi(r3, Operand::Zero());
2185 __ pop(load_receiver); // result
2186 __ LoadRoot(load_name, Heap::kvalue_stringRootIndex); // "value"
2187 __ mov(LoadDescriptor::SlotRegister(),
2188 Operand(SmiFromSlot(expr->ValueFeedbackSlot())));
2189 CallLoadIC(NOT_INSIDE_TYPEOF); // r3=result.value
2190 context()->DropAndPlug(2, r3); // drop iter and g
2197 void FullCodeGenerator::EmitGeneratorResume(
2198 Expression* generator, Expression* value,
2199 JSGeneratorObject::ResumeMode resume_mode) {
2200 // The value stays in r3, and is ultimately read by the resumed generator, as
2201 // if CallRuntime(Runtime::kSuspendJSGeneratorObject) returned it. Or it
2202 // is read to throw the value when the resumed generator is already closed.
2203 // r4 will hold the generator object until the activation has been resumed.
2204 VisitForStackValue(generator);
2205 VisitForAccumulatorValue(value);
2208 // Load suspended function and context.
2209 __ LoadP(cp, FieldMemOperand(r4, JSGeneratorObject::kContextOffset));
2210 __ LoadP(r7, FieldMemOperand(r4, JSGeneratorObject::kFunctionOffset));
2212 // Load receiver and store as the first argument.
2213 __ LoadP(r5, FieldMemOperand(r4, JSGeneratorObject::kReceiverOffset));
2216 // Push holes for the rest of the arguments to the generator function.
2217 __ LoadP(r6, FieldMemOperand(r7, JSFunction::kSharedFunctionInfoOffset));
2219 r6, FieldMemOperand(r6, SharedFunctionInfo::kFormalParameterCountOffset));
2220 __ LoadRoot(r5, Heap::kTheHoleValueRootIndex);
2221 Label argument_loop, push_frame;
2222 #if V8_TARGET_ARCH_PPC64
2223 __ cmpi(r6, Operand::Zero());
2224 __ beq(&push_frame);
2226 __ SmiUntag(r6, SetRC);
2227 __ beq(&push_frame, cr0);
2230 __ bind(&argument_loop);
2232 __ bdnz(&argument_loop);
2234 // Enter a new JavaScript frame, and initialize its slots as they were when
2235 // the generator was suspended.
2236 Label resume_frame, done;
2237 __ bind(&push_frame);
2238 __ b(&resume_frame, SetLK);
2240 __ bind(&resume_frame);
2241 // lr = return address.
2242 // fp = caller's frame pointer.
2243 // cp = callee's context,
2244 // r7 = callee's JS function.
2245 __ PushFixedFrame(r7);
2246 // Adjust FP to point to saved FP.
2247 __ addi(fp, sp, Operand(StandardFrameConstants::kFixedFrameSizeFromFp));
2249 // Load the operand stack size.
2250 __ LoadP(r6, FieldMemOperand(r4, JSGeneratorObject::kOperandStackOffset));
2251 __ LoadP(r6, FieldMemOperand(r6, FixedArray::kLengthOffset));
2252 __ SmiUntag(r6, SetRC);
2254 // If we are sending a value and there is no operand stack, we can jump back
2257 if (resume_mode == JSGeneratorObject::NEXT) {
2259 __ bne(&slow_resume, cr0);
2260 __ LoadP(ip, FieldMemOperand(r7, JSFunction::kCodeEntryOffset));
2262 ConstantPoolUnavailableScope constant_pool_unavailable(masm_);
2263 if (FLAG_enable_embedded_constant_pool) {
2264 __ LoadConstantPoolPointerRegisterFromCodeTargetAddress(ip);
2266 __ LoadP(r5, FieldMemOperand(r4, JSGeneratorObject::kContinuationOffset));
2269 __ LoadSmiLiteral(r5,
2270 Smi::FromInt(JSGeneratorObject::kGeneratorExecuting));
2271 __ StoreP(r5, FieldMemOperand(r4, JSGeneratorObject::kContinuationOffset),
2274 __ bind(&slow_resume);
2277 __ beq(&call_resume, cr0);
2280 // Otherwise, we push holes for the operand stack and call the runtime to fix
2281 // up the stack and the handlers.
2284 __ bind(&operand_loop);
2286 __ bdnz(&operand_loop);
2288 __ bind(&call_resume);
2289 DCHECK(!result_register().is(r4));
2290 __ Push(r4, result_register());
2291 __ Push(Smi::FromInt(resume_mode));
2292 __ CallRuntime(Runtime::kResumeJSGeneratorObject, 3);
2293 // Not reached: the runtime call returns elsewhere.
2294 __ stop("not-reached");
2297 context()->Plug(result_register());
2301 void FullCodeGenerator::EmitCreateIteratorResult(bool done) {
2305 const int instance_size = 5 * kPointerSize;
2306 DCHECK_EQ(isolate()->native_context()->iterator_result_map()->instance_size(),
2309 __ Allocate(instance_size, r3, r5, r6, &gc_required, TAG_OBJECT);
2312 __ bind(&gc_required);
2313 __ Push(Smi::FromInt(instance_size));
2314 __ CallRuntime(Runtime::kAllocateInNewSpace, 1);
2315 __ LoadP(context_register(),
2316 MemOperand(fp, StandardFrameConstants::kContextOffset));
2318 __ bind(&allocated);
2319 __ LoadP(r4, ContextOperand(cp, Context::GLOBAL_OBJECT_INDEX));
2320 __ LoadP(r4, FieldMemOperand(r4, GlobalObject::kNativeContextOffset));
2321 __ LoadP(r4, ContextOperand(r4, Context::ITERATOR_RESULT_MAP_INDEX));
2323 __ mov(r6, Operand(isolate()->factory()->ToBoolean(done)));
2324 __ mov(r7, Operand(isolate()->factory()->empty_fixed_array()));
2325 __ StoreP(r4, FieldMemOperand(r3, HeapObject::kMapOffset), r0);
2326 __ StoreP(r7, FieldMemOperand(r3, JSObject::kPropertiesOffset), r0);
2327 __ StoreP(r7, FieldMemOperand(r3, JSObject::kElementsOffset), r0);
2329 FieldMemOperand(r3, JSGeneratorObject::kResultValuePropertyOffset),
2332 FieldMemOperand(r3, JSGeneratorObject::kResultDonePropertyOffset),
2335 // Only the value field needs a write barrier, as the other values are in the
2337 __ RecordWriteField(r3, JSGeneratorObject::kResultValuePropertyOffset, r5, r6,
2338 kLRHasBeenSaved, kDontSaveFPRegs);
2342 void FullCodeGenerator::EmitNamedPropertyLoad(Property* prop) {
2343 SetExpressionPosition(prop);
2344 Literal* key = prop->key()->AsLiteral();
2345 DCHECK(!prop->IsSuperAccess());
2347 __ mov(LoadDescriptor::NameRegister(), Operand(key->value()));
2348 __ mov(LoadDescriptor::SlotRegister(),
2349 Operand(SmiFromSlot(prop->PropertyFeedbackSlot())));
2350 CallLoadIC(NOT_INSIDE_TYPEOF, language_mode());
2354 void FullCodeGenerator::EmitNamedSuperPropertyLoad(Property* prop) {
2355 // Stack: receiver, home_object.
2356 SetExpressionPosition(prop);
2357 Literal* key = prop->key()->AsLiteral();
2358 DCHECK(!key->value()->IsSmi());
2359 DCHECK(prop->IsSuperAccess());
2361 __ Push(key->value());
2362 __ Push(Smi::FromInt(language_mode()));
2363 __ CallRuntime(Runtime::kLoadFromSuper, 4);
2367 void FullCodeGenerator::EmitKeyedPropertyLoad(Property* prop) {
2368 SetExpressionPosition(prop);
2369 Handle<Code> ic = CodeFactory::KeyedLoadIC(isolate(), language_mode()).code();
2370 __ mov(LoadDescriptor::SlotRegister(),
2371 Operand(SmiFromSlot(prop->PropertyFeedbackSlot())));
2376 void FullCodeGenerator::EmitKeyedSuperPropertyLoad(Property* prop) {
2377 // Stack: receiver, home_object, key.
2378 SetExpressionPosition(prop);
2379 __ Push(Smi::FromInt(language_mode()));
2380 __ CallRuntime(Runtime::kLoadKeyedFromSuper, 4);
2384 void FullCodeGenerator::EmitInlineSmiBinaryOp(BinaryOperation* expr,
2386 Expression* left_expr,
2387 Expression* right_expr) {
2388 Label done, smi_case, stub_call;
2390 Register scratch1 = r5;
2391 Register scratch2 = r6;
2393 // Get the arguments.
2395 Register right = r3;
2398 // Perform combined smi check on both operands.
2399 __ orx(scratch1, left, right);
2400 STATIC_ASSERT(kSmiTag == 0);
2401 JumpPatchSite patch_site(masm_);
2402 patch_site.EmitJumpIfSmi(scratch1, &smi_case);
2404 __ bind(&stub_call);
2406 CodeFactory::BinaryOpIC(isolate(), op, strength(language_mode())).code();
2407 CallIC(code, expr->BinaryOperationFeedbackId());
2408 patch_site.EmitPatchInfo();
2412 // Smi case. This code works the same way as the smi-smi case in the type
2413 // recording binary operation stub.
2416 __ GetLeastBitsFromSmi(scratch1, right, 5);
2417 __ ShiftRightArith(right, left, scratch1);
2418 __ ClearRightImm(right, right, Operand(kSmiTagSize + kSmiShiftSize));
2421 __ GetLeastBitsFromSmi(scratch2, right, 5);
2422 #if V8_TARGET_ARCH_PPC64
2423 __ ShiftLeft_(right, left, scratch2);
2425 __ SmiUntag(scratch1, left);
2426 __ ShiftLeft_(scratch1, scratch1, scratch2);
2427 // Check that the *signed* result fits in a smi
2428 __ JumpIfNotSmiCandidate(scratch1, scratch2, &stub_call);
2429 __ SmiTag(right, scratch1);
2434 __ SmiUntag(scratch1, left);
2435 __ GetLeastBitsFromSmi(scratch2, right, 5);
2436 __ srw(scratch1, scratch1, scratch2);
2437 // Unsigned shift is not allowed to produce a negative number.
2438 __ JumpIfNotUnsignedSmiCandidate(scratch1, r0, &stub_call);
2439 __ SmiTag(right, scratch1);
2443 __ AddAndCheckForOverflow(scratch1, left, right, scratch2, r0);
2444 __ BranchOnOverflow(&stub_call);
2445 __ mr(right, scratch1);
2449 __ SubAndCheckForOverflow(scratch1, left, right, scratch2, r0);
2450 __ BranchOnOverflow(&stub_call);
2451 __ mr(right, scratch1);
2456 #if V8_TARGET_ARCH_PPC64
2457 // Remove tag from both operands.
2458 __ SmiUntag(ip, right);
2459 __ SmiUntag(r0, left);
2460 __ Mul(scratch1, r0, ip);
2461 // Check for overflowing the smi range - no overflow if higher 33 bits of
2462 // the result are identical.
2463 __ TestIfInt32(scratch1, r0);
2466 __ SmiUntag(ip, right);
2467 __ mullw(scratch1, left, ip);
2468 __ mulhw(scratch2, left, ip);
2469 // Check for overflowing the smi range - no overflow if higher 33 bits of
2470 // the result are identical.
2471 __ TestIfInt32(scratch2, scratch1, ip);
2474 // Go slow on zero result to handle -0.
2475 __ cmpi(scratch1, Operand::Zero());
2477 #if V8_TARGET_ARCH_PPC64
2478 __ SmiTag(right, scratch1);
2480 __ mr(right, scratch1);
2483 // We need -0 if we were multiplying a negative number with 0 to get 0.
2484 // We know one of them was zero.
2486 __ add(scratch2, right, left);
2487 __ cmpi(scratch2, Operand::Zero());
2489 __ LoadSmiLiteral(right, Smi::FromInt(0));
2493 __ orx(right, left, right);
2495 case Token::BIT_AND:
2496 __ and_(right, left, right);
2498 case Token::BIT_XOR:
2499 __ xor_(right, left, right);
2506 context()->Plug(r3);
2510 void FullCodeGenerator::EmitClassDefineProperties(ClassLiteral* lit,
2511 int* used_store_slots) {
2512 // Constructor is in r3.
2513 DCHECK(lit != NULL);
2516 // No access check is needed here since the constructor is created by the
2518 Register scratch = r4;
2520 FieldMemOperand(r3, JSFunction::kPrototypeOrInitialMapOffset));
2523 for (int i = 0; i < lit->properties()->length(); i++) {
2524 ObjectLiteral::Property* property = lit->properties()->at(i);
2525 Expression* value = property->value();
2527 if (property->is_static()) {
2528 __ LoadP(scratch, MemOperand(sp, kPointerSize)); // constructor
2530 __ LoadP(scratch, MemOperand(sp, 0)); // prototype
2533 EmitPropertyKey(property, lit->GetIdForProperty(i));
2535 // The static prototype property is read only. We handle the non computed
2536 // property name case in the parser. Since this is the only case where we
2537 // need to check for an own read only property we special case this so we do
2538 // not need to do this for every property.
2539 if (property->is_static() && property->is_computed_name()) {
2540 __ CallRuntime(Runtime::kThrowIfStaticPrototype, 1);
2544 VisitForStackValue(value);
2545 EmitSetHomeObjectIfNeeded(value, 2,
2546 lit->SlotForHomeObject(value, used_store_slots));
2548 switch (property->kind()) {
2549 case ObjectLiteral::Property::CONSTANT:
2550 case ObjectLiteral::Property::MATERIALIZED_LITERAL:
2551 case ObjectLiteral::Property::PROTOTYPE:
2553 case ObjectLiteral::Property::COMPUTED:
2554 __ CallRuntime(Runtime::kDefineClassMethod, 3);
2557 case ObjectLiteral::Property::GETTER:
2558 __ mov(r3, Operand(Smi::FromInt(DONT_ENUM)));
2560 __ CallRuntime(Runtime::kDefineGetterPropertyUnchecked, 4);
2563 case ObjectLiteral::Property::SETTER:
2564 __ mov(r3, Operand(Smi::FromInt(DONT_ENUM)));
2566 __ CallRuntime(Runtime::kDefineSetterPropertyUnchecked, 4);
2574 // Set both the prototype and constructor to have fast properties, and also
2575 // freeze them in strong mode.
2576 __ CallRuntime(Runtime::kFinalizeClassDefinition, 2);
2580 void FullCodeGenerator::EmitBinaryOp(BinaryOperation* expr, Token::Value op) {
2583 CodeFactory::BinaryOpIC(isolate(), op, strength(language_mode())).code();
2584 JumpPatchSite patch_site(masm_); // unbound, signals no inlined smi code.
2585 CallIC(code, expr->BinaryOperationFeedbackId());
2586 patch_site.EmitPatchInfo();
2587 context()->Plug(r3);
2591 void FullCodeGenerator::EmitAssignment(Expression* expr,
2592 FeedbackVectorICSlot slot) {
2593 DCHECK(expr->IsValidReferenceExpressionOrThis());
2595 Property* prop = expr->AsProperty();
2596 LhsKind assign_type = Property::GetAssignType(prop);
2598 switch (assign_type) {
2600 Variable* var = expr->AsVariableProxy()->var();
2601 EffectContext context(this);
2602 EmitVariableAssignment(var, Token::ASSIGN, slot);
2605 case NAMED_PROPERTY: {
2606 __ push(r3); // Preserve value.
2607 VisitForAccumulatorValue(prop->obj());
2608 __ Move(StoreDescriptor::ReceiverRegister(), r3);
2609 __ pop(StoreDescriptor::ValueRegister()); // Restore value.
2610 __ mov(StoreDescriptor::NameRegister(),
2611 Operand(prop->key()->AsLiteral()->value()));
2612 if (FLAG_vector_stores) EmitLoadStoreICSlot(slot);
2616 case NAMED_SUPER_PROPERTY: {
2618 VisitForStackValue(prop->obj()->AsSuperPropertyReference()->this_var());
2619 VisitForAccumulatorValue(
2620 prop->obj()->AsSuperPropertyReference()->home_object());
2621 // stack: value, this; r3: home_object
2622 Register scratch = r5;
2623 Register scratch2 = r6;
2624 __ mr(scratch, result_register()); // home_object
2625 __ LoadP(r3, MemOperand(sp, kPointerSize)); // value
2626 __ LoadP(scratch2, MemOperand(sp, 0)); // this
2627 __ StoreP(scratch2, MemOperand(sp, kPointerSize)); // this
2628 __ StoreP(scratch, MemOperand(sp, 0)); // home_object
2629 // stack: this, home_object; r3: value
2630 EmitNamedSuperPropertyStore(prop);
2633 case KEYED_SUPER_PROPERTY: {
2635 VisitForStackValue(prop->obj()->AsSuperPropertyReference()->this_var());
2637 prop->obj()->AsSuperPropertyReference()->home_object());
2638 VisitForAccumulatorValue(prop->key());
2639 Register scratch = r5;
2640 Register scratch2 = r6;
2641 __ LoadP(scratch2, MemOperand(sp, 2 * kPointerSize)); // value
2642 // stack: value, this, home_object; r3: key, r6: value
2643 __ LoadP(scratch, MemOperand(sp, kPointerSize)); // this
2644 __ StoreP(scratch, MemOperand(sp, 2 * kPointerSize));
2645 __ LoadP(scratch, MemOperand(sp, 0)); // home_object
2646 __ StoreP(scratch, MemOperand(sp, kPointerSize));
2647 __ StoreP(r3, MemOperand(sp, 0));
2648 __ Move(r3, scratch2);
2649 // stack: this, home_object, key; r3: value.
2650 EmitKeyedSuperPropertyStore(prop);
2653 case KEYED_PROPERTY: {
2654 __ push(r3); // Preserve value.
2655 VisitForStackValue(prop->obj());
2656 VisitForAccumulatorValue(prop->key());
2657 __ Move(StoreDescriptor::NameRegister(), r3);
2658 __ Pop(StoreDescriptor::ValueRegister(),
2659 StoreDescriptor::ReceiverRegister());
2660 if (FLAG_vector_stores) EmitLoadStoreICSlot(slot);
2662 CodeFactory::KeyedStoreIC(isolate(), language_mode()).code();
2667 context()->Plug(r3);
2671 void FullCodeGenerator::EmitStoreToStackLocalOrContextSlot(
2672 Variable* var, MemOperand location) {
2673 __ StoreP(result_register(), location, r0);
2674 if (var->IsContextSlot()) {
2675 // RecordWrite may destroy all its register arguments.
2676 __ mr(r6, result_register());
2677 int offset = Context::SlotOffset(var->index());
2678 __ RecordWriteContextSlot(r4, offset, r6, r5, kLRHasBeenSaved,
2684 void FullCodeGenerator::EmitVariableAssignment(Variable* var, Token::Value op,
2685 FeedbackVectorICSlot slot) {
2686 if (var->IsUnallocated()) {
2687 // Global var, const, or let.
2688 __ mov(StoreDescriptor::NameRegister(), Operand(var->name()));
2689 __ LoadP(StoreDescriptor::ReceiverRegister(), GlobalObjectOperand());
2690 if (FLAG_vector_stores) EmitLoadStoreICSlot(slot);
2693 } else if (var->IsGlobalSlot()) {
2694 // Global var, const, or let.
2695 DCHECK(var->index() > 0);
2696 DCHECK(var->IsStaticGlobalObjectProperty());
2697 const int slot = var->index();
2698 const int depth = scope()->ContextChainLength(var->scope());
2699 if (depth <= StoreGlobalViaContextStub::kMaximumDepth) {
2700 __ mov(StoreGlobalViaContextDescriptor::SlotRegister(), Operand(slot));
2701 DCHECK(StoreGlobalViaContextDescriptor::ValueRegister().is(r3));
2702 StoreGlobalViaContextStub stub(isolate(), depth, language_mode());
2705 __ Push(Smi::FromInt(slot));
2707 __ CallRuntime(is_strict(language_mode())
2708 ? Runtime::kStoreGlobalViaContext_Strict
2709 : Runtime::kStoreGlobalViaContext_Sloppy,
2712 } else if (var->mode() == LET && op != Token::INIT_LET) {
2713 // Non-initializing assignment to let variable needs a write barrier.
2714 DCHECK(!var->IsLookupSlot());
2715 DCHECK(var->IsStackAllocated() || var->IsContextSlot());
2717 MemOperand location = VarOperand(var, r4);
2718 __ LoadP(r6, location);
2719 __ CompareRoot(r6, Heap::kTheHoleValueRootIndex);
2721 __ mov(r6, Operand(var->name()));
2723 __ CallRuntime(Runtime::kThrowReferenceError, 1);
2724 // Perform the assignment.
2726 EmitStoreToStackLocalOrContextSlot(var, location);
2728 } else if (var->mode() == CONST && op != Token::INIT_CONST) {
2729 // Assignment to const variable needs a write barrier.
2730 DCHECK(!var->IsLookupSlot());
2731 DCHECK(var->IsStackAllocated() || var->IsContextSlot());
2733 MemOperand location = VarOperand(var, r4);
2734 __ LoadP(r6, location);
2735 __ CompareRoot(r6, Heap::kTheHoleValueRootIndex);
2736 __ bne(&const_error);
2737 __ mov(r6, Operand(var->name()));
2739 __ CallRuntime(Runtime::kThrowReferenceError, 1);
2740 __ bind(&const_error);
2741 __ CallRuntime(Runtime::kThrowConstAssignError, 0);
2743 } else if (var->is_this() && op == Token::INIT_CONST) {
2744 // Initializing assignment to const {this} needs a write barrier.
2745 DCHECK(var->IsStackAllocated() || var->IsContextSlot());
2746 Label uninitialized_this;
2747 MemOperand location = VarOperand(var, r4);
2748 __ LoadP(r6, location);
2749 __ CompareRoot(r6, Heap::kTheHoleValueRootIndex);
2750 __ beq(&uninitialized_this);
2751 __ mov(r4, Operand(var->name()));
2753 __ CallRuntime(Runtime::kThrowReferenceError, 1);
2754 __ bind(&uninitialized_this);
2755 EmitStoreToStackLocalOrContextSlot(var, location);
2757 } else if (!var->is_const_mode() || op == Token::INIT_CONST) {
2758 if (var->IsLookupSlot()) {
2759 // Assignment to var.
2760 __ push(r3); // Value.
2761 __ mov(r4, Operand(var->name()));
2762 __ mov(r3, Operand(Smi::FromInt(language_mode())));
2763 __ Push(cp, r4, r3); // Context, name, language mode.
2764 __ CallRuntime(Runtime::kStoreLookupSlot, 4);
2766 // Assignment to var or initializing assignment to let/const in harmony
2768 DCHECK((var->IsStackAllocated() || var->IsContextSlot()));
2769 MemOperand location = VarOperand(var, r4);
2770 if (generate_debug_code_ && op == Token::INIT_LET) {
2771 // Check for an uninitialized let binding.
2772 __ LoadP(r5, location);
2773 __ CompareRoot(r5, Heap::kTheHoleValueRootIndex);
2774 __ Check(eq, kLetBindingReInitialization);
2776 EmitStoreToStackLocalOrContextSlot(var, location);
2778 } else if (op == Token::INIT_CONST_LEGACY) {
2779 // Const initializers need a write barrier.
2780 DCHECK(var->mode() == CONST_LEGACY);
2781 DCHECK(!var->IsParameter()); // No const parameters.
2782 if (var->IsLookupSlot()) {
2784 __ mov(r3, Operand(var->name()));
2785 __ Push(cp, r3); // Context and name.
2786 __ CallRuntime(Runtime::kInitializeLegacyConstLookupSlot, 3);
2788 DCHECK(var->IsStackAllocated() || var->IsContextSlot());
2790 MemOperand location = VarOperand(var, r4);
2791 __ LoadP(r5, location);
2792 __ CompareRoot(r5, Heap::kTheHoleValueRootIndex);
2794 EmitStoreToStackLocalOrContextSlot(var, location);
2799 DCHECK(var->mode() == CONST_LEGACY && op != Token::INIT_CONST_LEGACY);
2800 if (is_strict(language_mode())) {
2801 __ CallRuntime(Runtime::kThrowConstAssignError, 0);
2803 // Silently ignore store in sloppy mode.
2808 void FullCodeGenerator::EmitNamedPropertyAssignment(Assignment* expr) {
2809 // Assignment to a property, using a named store IC.
2810 Property* prop = expr->target()->AsProperty();
2811 DCHECK(prop != NULL);
2812 DCHECK(prop->key()->IsLiteral());
2814 __ mov(StoreDescriptor::NameRegister(),
2815 Operand(prop->key()->AsLiteral()->value()));
2816 __ pop(StoreDescriptor::ReceiverRegister());
2817 if (FLAG_vector_stores) {
2818 EmitLoadStoreICSlot(expr->AssignmentSlot());
2821 CallStoreIC(expr->AssignmentFeedbackId());
2824 PrepareForBailoutForId(expr->AssignmentId(), TOS_REG);
2825 context()->Plug(r3);
2829 void FullCodeGenerator::EmitNamedSuperPropertyStore(Property* prop) {
2830 // Assignment to named property of super.
2832 // stack : receiver ('this'), home_object
2833 DCHECK(prop != NULL);
2834 Literal* key = prop->key()->AsLiteral();
2835 DCHECK(key != NULL);
2837 __ Push(key->value());
2839 __ CallRuntime((is_strict(language_mode()) ? Runtime::kStoreToSuper_Strict
2840 : Runtime::kStoreToSuper_Sloppy),
2845 void FullCodeGenerator::EmitKeyedSuperPropertyStore(Property* prop) {
2846 // Assignment to named property of super.
2848 // stack : receiver ('this'), home_object, key
2849 DCHECK(prop != NULL);
2853 (is_strict(language_mode()) ? Runtime::kStoreKeyedToSuper_Strict
2854 : Runtime::kStoreKeyedToSuper_Sloppy),
2859 void FullCodeGenerator::EmitKeyedPropertyAssignment(Assignment* expr) {
2860 // Assignment to a property, using a keyed store IC.
2861 __ Pop(StoreDescriptor::ReceiverRegister(), StoreDescriptor::NameRegister());
2862 DCHECK(StoreDescriptor::ValueRegister().is(r3));
2865 CodeFactory::KeyedStoreIC(isolate(), language_mode()).code();
2866 if (FLAG_vector_stores) {
2867 EmitLoadStoreICSlot(expr->AssignmentSlot());
2870 CallIC(ic, expr->AssignmentFeedbackId());
2873 PrepareForBailoutForId(expr->AssignmentId(), TOS_REG);
2874 context()->Plug(r3);
2878 void FullCodeGenerator::VisitProperty(Property* expr) {
2879 Comment cmnt(masm_, "[ Property");
2880 SetExpressionPosition(expr);
2882 Expression* key = expr->key();
2884 if (key->IsPropertyName()) {
2885 if (!expr->IsSuperAccess()) {
2886 VisitForAccumulatorValue(expr->obj());
2887 __ Move(LoadDescriptor::ReceiverRegister(), r3);
2888 EmitNamedPropertyLoad(expr);
2890 VisitForStackValue(expr->obj()->AsSuperPropertyReference()->this_var());
2892 expr->obj()->AsSuperPropertyReference()->home_object());
2893 EmitNamedSuperPropertyLoad(expr);
2896 if (!expr->IsSuperAccess()) {
2897 VisitForStackValue(expr->obj());
2898 VisitForAccumulatorValue(expr->key());
2899 __ Move(LoadDescriptor::NameRegister(), r3);
2900 __ pop(LoadDescriptor::ReceiverRegister());
2901 EmitKeyedPropertyLoad(expr);
2903 VisitForStackValue(expr->obj()->AsSuperPropertyReference()->this_var());
2905 expr->obj()->AsSuperPropertyReference()->home_object());
2906 VisitForStackValue(expr->key());
2907 EmitKeyedSuperPropertyLoad(expr);
2910 PrepareForBailoutForId(expr->LoadId(), TOS_REG);
2911 context()->Plug(r3);
2915 void FullCodeGenerator::CallIC(Handle<Code> code, TypeFeedbackId ast_id) {
2917 __ Call(code, RelocInfo::CODE_TARGET, ast_id);
2921 // Code common for calls using the IC.
2922 void FullCodeGenerator::EmitCallWithLoadIC(Call* expr) {
2923 Expression* callee = expr->expression();
2925 CallICState::CallType call_type =
2926 callee->IsVariableProxy() ? CallICState::FUNCTION : CallICState::METHOD;
2928 // Get the target function.
2929 if (call_type == CallICState::FUNCTION) {
2931 StackValueContext context(this);
2932 EmitVariableLoad(callee->AsVariableProxy());
2933 PrepareForBailout(callee, NO_REGISTERS);
2935 // Push undefined as receiver. This is patched in the method prologue if it
2936 // is a sloppy mode method.
2937 __ LoadRoot(r0, Heap::kUndefinedValueRootIndex);
2940 // Load the function from the receiver.
2941 DCHECK(callee->IsProperty());
2942 DCHECK(!callee->AsProperty()->IsSuperAccess());
2943 __ LoadP(LoadDescriptor::ReceiverRegister(), MemOperand(sp, 0));
2944 EmitNamedPropertyLoad(callee->AsProperty());
2945 PrepareForBailoutForId(callee->AsProperty()->LoadId(), TOS_REG);
2946 // Push the target function under the receiver.
2947 __ LoadP(r0, MemOperand(sp, 0));
2949 __ StoreP(r3, MemOperand(sp, kPointerSize));
2952 EmitCall(expr, call_type);
2956 void FullCodeGenerator::EmitSuperCallWithLoadIC(Call* expr) {
2957 Expression* callee = expr->expression();
2958 DCHECK(callee->IsProperty());
2959 Property* prop = callee->AsProperty();
2960 DCHECK(prop->IsSuperAccess());
2961 SetExpressionPosition(prop);
2963 Literal* key = prop->key()->AsLiteral();
2964 DCHECK(!key->value()->IsSmi());
2965 // Load the function from the receiver.
2966 const Register scratch = r4;
2967 SuperPropertyReference* super_ref = prop->obj()->AsSuperPropertyReference();
2968 VisitForAccumulatorValue(super_ref->home_object());
2970 VisitForAccumulatorValue(super_ref->this_var());
2971 __ Push(scratch, r3, r3, scratch);
2972 __ Push(key->value());
2973 __ Push(Smi::FromInt(language_mode()));
2977 // - this (receiver)
2978 // - this (receiver) <-- LoadFromSuper will pop here and below.
2982 __ CallRuntime(Runtime::kLoadFromSuper, 4);
2984 // Replace home_object with target function.
2985 __ StoreP(r3, MemOperand(sp, kPointerSize));
2988 // - target function
2989 // - this (receiver)
2990 EmitCall(expr, CallICState::METHOD);
2994 // Code common for calls using the IC.
2995 void FullCodeGenerator::EmitKeyedCallWithLoadIC(Call* expr, Expression* key) {
2997 VisitForAccumulatorValue(key);
2999 Expression* callee = expr->expression();
3001 // Load the function from the receiver.
3002 DCHECK(callee->IsProperty());
3003 __ LoadP(LoadDescriptor::ReceiverRegister(), MemOperand(sp, 0));
3004 __ Move(LoadDescriptor::NameRegister(), r3);
3005 EmitKeyedPropertyLoad(callee->AsProperty());
3006 PrepareForBailoutForId(callee->AsProperty()->LoadId(), TOS_REG);
3008 // Push the target function under the receiver.
3009 __ LoadP(ip, MemOperand(sp, 0));
3011 __ StoreP(r3, MemOperand(sp, kPointerSize));
3013 EmitCall(expr, CallICState::METHOD);
3017 void FullCodeGenerator::EmitKeyedSuperCallWithLoadIC(Call* expr) {
3018 Expression* callee = expr->expression();
3019 DCHECK(callee->IsProperty());
3020 Property* prop = callee->AsProperty();
3021 DCHECK(prop->IsSuperAccess());
3023 SetExpressionPosition(prop);
3024 // Load the function from the receiver.
3025 const Register scratch = r4;
3026 SuperPropertyReference* super_ref = prop->obj()->AsSuperPropertyReference();
3027 VisitForAccumulatorValue(super_ref->home_object());
3029 VisitForAccumulatorValue(super_ref->this_var());
3030 __ Push(scratch, r3, r3, scratch);
3031 VisitForStackValue(prop->key());
3032 __ Push(Smi::FromInt(language_mode()));
3036 // - this (receiver)
3037 // - this (receiver) <-- LoadKeyedFromSuper will pop here and below.
3041 __ CallRuntime(Runtime::kLoadKeyedFromSuper, 4);
3043 // Replace home_object with target function.
3044 __ StoreP(r3, MemOperand(sp, kPointerSize));
3047 // - target function
3048 // - this (receiver)
3049 EmitCall(expr, CallICState::METHOD);
3053 void FullCodeGenerator::EmitCall(Call* expr, CallICState::CallType call_type) {
3054 // Load the arguments.
3055 ZoneList<Expression*>* args = expr->arguments();
3056 int arg_count = args->length();
3057 for (int i = 0; i < arg_count; i++) {
3058 VisitForStackValue(args->at(i));
3061 SetCallPosition(expr, arg_count);
3062 Handle<Code> ic = CodeFactory::CallIC(isolate(), arg_count, call_type).code();
3063 __ LoadSmiLiteral(r6, SmiFromSlot(expr->CallFeedbackICSlot()));
3064 __ LoadP(r4, MemOperand(sp, (arg_count + 1) * kPointerSize), r0);
3065 // Don't assign a type feedback id to the IC, since type feedback is provided
3066 // by the vector above.
3069 RecordJSReturnSite(expr);
3070 // Restore context register.
3071 __ LoadP(cp, MemOperand(fp, StandardFrameConstants::kContextOffset));
3072 context()->DropAndPlug(1, r3);
3076 void FullCodeGenerator::EmitResolvePossiblyDirectEval(int arg_count) {
3077 // r7: copy of the first argument or undefined if it doesn't exist.
3078 if (arg_count > 0) {
3079 __ LoadP(r7, MemOperand(sp, arg_count * kPointerSize), r0);
3081 __ LoadRoot(r7, Heap::kUndefinedValueRootIndex);
3084 // r6: the receiver of the enclosing function.
3085 __ LoadP(r6, MemOperand(fp, JavaScriptFrameConstants::kFunctionOffset));
3087 // r5: language mode.
3088 __ LoadSmiLiteral(r5, Smi::FromInt(language_mode()));
3090 // r4: the start position of the scope the calls resides in.
3091 __ LoadSmiLiteral(r4, Smi::FromInt(scope()->start_position()));
3093 // Do the runtime call.
3094 __ Push(r7, r6, r5, r4);
3095 __ CallRuntime(Runtime::kResolvePossiblyDirectEval, 5);
3099 // See http://www.ecma-international.org/ecma-262/6.0/#sec-function-calls.
3100 void FullCodeGenerator::PushCalleeAndWithBaseObject(Call* expr) {
3101 VariableProxy* callee = expr->expression()->AsVariableProxy();
3102 if (callee->var()->IsLookupSlot()) {
3104 SetExpressionPosition(callee);
3105 // Generate code for loading from variables potentially shadowed by
3106 // eval-introduced variables.
3107 EmitDynamicLookupFastCase(callee, NOT_INSIDE_TYPEOF, &slow, &done);
3110 // Call the runtime to find the function to call (returned in r3) and
3111 // the object holding it (returned in r4).
3112 DCHECK(!context_register().is(r5));
3113 __ mov(r5, Operand(callee->name()));
3114 __ Push(context_register(), r5);
3115 __ CallRuntime(Runtime::kLoadLookupSlot, 2);
3116 __ Push(r3, r4); // Function, receiver.
3117 PrepareForBailoutForId(expr->LookupId(), NO_REGISTERS);
3119 // If fast case code has been generated, emit code to push the function
3120 // and receiver and have the slow path jump around this code.
3121 if (done.is_linked()) {
3127 // Pass undefined as the receiver, which is the WithBaseObject of a
3128 // non-object environment record. If the callee is sloppy, it will patch
3129 // it up to be the global receiver.
3130 __ LoadRoot(r4, Heap::kUndefinedValueRootIndex);
3135 VisitForStackValue(callee);
3136 // refEnv.WithBaseObject()
3137 __ LoadRoot(r5, Heap::kUndefinedValueRootIndex);
3138 __ push(r5); // Reserved receiver slot.
3143 void FullCodeGenerator::VisitCall(Call* expr) {
3145 // We want to verify that RecordJSReturnSite gets called on all paths
3146 // through this function. Avoid early returns.
3147 expr->return_is_recorded_ = false;
3150 Comment cmnt(masm_, "[ Call");
3151 Expression* callee = expr->expression();
3152 Call::CallType call_type = expr->GetCallType(isolate());
3154 if (call_type == Call::POSSIBLY_EVAL_CALL) {
3155 // In a call to eval, we first call RuntimeHidden_ResolvePossiblyDirectEval
3156 // to resolve the function we need to call. Then we call the resolved
3157 // function using the given arguments.
3158 ZoneList<Expression*>* args = expr->arguments();
3159 int arg_count = args->length();
3161 PushCalleeAndWithBaseObject(expr);
3163 // Push the arguments.
3164 for (int i = 0; i < arg_count; i++) {
3165 VisitForStackValue(args->at(i));
3168 // Push a copy of the function (found below the arguments) and
3170 __ LoadP(r4, MemOperand(sp, (arg_count + 1) * kPointerSize), r0);
3172 EmitResolvePossiblyDirectEval(arg_count);
3174 // Touch up the stack with the resolved function.
3175 __ StoreP(r3, MemOperand(sp, (arg_count + 1) * kPointerSize), r0);
3177 PrepareForBailoutForId(expr->EvalId(), NO_REGISTERS);
3179 // Record source position for debugger.
3180 SetCallPosition(expr, arg_count);
3181 CallFunctionStub stub(isolate(), arg_count, NO_CALL_FUNCTION_FLAGS);
3182 __ LoadP(r4, MemOperand(sp, (arg_count + 1) * kPointerSize), r0);
3184 RecordJSReturnSite(expr);
3185 // Restore context register.
3186 __ LoadP(cp, MemOperand(fp, StandardFrameConstants::kContextOffset));
3187 context()->DropAndPlug(1, r3);
3188 } else if (call_type == Call::GLOBAL_CALL) {
3189 EmitCallWithLoadIC(expr);
3191 } else if (call_type == Call::LOOKUP_SLOT_CALL) {
3192 // Call to a lookup slot (dynamically introduced variable).
3193 PushCalleeAndWithBaseObject(expr);
3195 } else if (call_type == Call::PROPERTY_CALL) {
3196 Property* property = callee->AsProperty();
3197 bool is_named_call = property->key()->IsPropertyName();
3198 if (property->IsSuperAccess()) {
3199 if (is_named_call) {
3200 EmitSuperCallWithLoadIC(expr);
3202 EmitKeyedSuperCallWithLoadIC(expr);
3205 VisitForStackValue(property->obj());
3206 if (is_named_call) {
3207 EmitCallWithLoadIC(expr);
3209 EmitKeyedCallWithLoadIC(expr, property->key());
3212 } else if (call_type == Call::SUPER_CALL) {
3213 EmitSuperConstructorCall(expr);
3215 DCHECK(call_type == Call::OTHER_CALL);
3216 // Call to an arbitrary expression not handled specially above.
3217 VisitForStackValue(callee);
3218 __ LoadRoot(r4, Heap::kUndefinedValueRootIndex);
3220 // Emit function call.
3225 // RecordJSReturnSite should have been called.
3226 DCHECK(expr->return_is_recorded_);
3231 void FullCodeGenerator::VisitCallNew(CallNew* expr) {
3232 Comment cmnt(masm_, "[ CallNew");
3233 // According to ECMA-262, section 11.2.2, page 44, the function
3234 // expression in new calls must be evaluated before the
3237 // Push constructor on the stack. If it's not a function it's used as
3238 // receiver for CALL_NON_FUNCTION, otherwise the value on the stack is
3240 DCHECK(!expr->expression()->IsSuperPropertyReference());
3241 VisitForStackValue(expr->expression());
3243 // Push the arguments ("left-to-right") on the stack.
3244 ZoneList<Expression*>* args = expr->arguments();
3245 int arg_count = args->length();
3246 for (int i = 0; i < arg_count; i++) {
3247 VisitForStackValue(args->at(i));
3250 // Call the construct call builtin that handles allocation and
3251 // constructor invocation.
3252 SetConstructCallPosition(expr);
3254 // Load function and argument count into r4 and r3.
3255 __ mov(r3, Operand(arg_count));
3256 __ LoadP(r4, MemOperand(sp, arg_count * kPointerSize), r0);
3258 // Record call targets in unoptimized code.
3259 if (FLAG_pretenuring_call_new) {
3260 EnsureSlotContainsAllocationSite(expr->AllocationSiteFeedbackSlot());
3261 DCHECK(expr->AllocationSiteFeedbackSlot().ToInt() ==
3262 expr->CallNewFeedbackSlot().ToInt() + 1);
3265 __ Move(r5, FeedbackVector());
3266 __ LoadSmiLiteral(r6, SmiFromSlot(expr->CallNewFeedbackSlot()));
3268 CallConstructStub stub(isolate(), RECORD_CONSTRUCTOR_TARGET);
3269 __ Call(stub.GetCode(), RelocInfo::CONSTRUCT_CALL);
3270 PrepareForBailoutForId(expr->ReturnId(), TOS_REG);
3271 context()->Plug(r3);
3275 void FullCodeGenerator::EmitSuperConstructorCall(Call* expr) {
3276 SuperCallReference* super_call_ref =
3277 expr->expression()->AsSuperCallReference();
3278 DCHECK_NOT_NULL(super_call_ref);
3280 EmitLoadSuperConstructor(super_call_ref);
3281 __ push(result_register());
3283 // Push the arguments ("left-to-right") on the stack.
3284 ZoneList<Expression*>* args = expr->arguments();
3285 int arg_count = args->length();
3286 for (int i = 0; i < arg_count; i++) {
3287 VisitForStackValue(args->at(i));
3290 // Call the construct call builtin that handles allocation and
3291 // constructor invocation.
3292 SetConstructCallPosition(expr);
3294 // Load original constructor into r7.
3295 VisitForAccumulatorValue(super_call_ref->new_target_var());
3296 __ mr(r7, result_register());
3298 // Load function and argument count into r1 and r0.
3299 __ mov(r3, Operand(arg_count));
3300 __ LoadP(r4, MemOperand(sp, arg_count * kPointerSize));
3302 // Record call targets in unoptimized code.
3303 if (FLAG_pretenuring_call_new) {
3305 /* TODO(dslomov): support pretenuring.
3306 EnsureSlotContainsAllocationSite(expr->AllocationSiteFeedbackSlot());
3307 DCHECK(expr->AllocationSiteFeedbackSlot().ToInt() ==
3308 expr->CallNewFeedbackSlot().ToInt() + 1);
3312 __ Move(r5, FeedbackVector());
3313 __ LoadSmiLiteral(r6, SmiFromSlot(expr->CallFeedbackSlot()));
3315 CallConstructStub stub(isolate(), SUPER_CALL_RECORD_TARGET);
3316 __ Call(stub.GetCode(), RelocInfo::CONSTRUCT_CALL);
3318 RecordJSReturnSite(expr);
3320 context()->Plug(r3);
3324 void FullCodeGenerator::EmitIsSmi(CallRuntime* expr) {
3325 ZoneList<Expression*>* args = expr->arguments();
3326 DCHECK(args->length() == 1);
3328 VisitForAccumulatorValue(args->at(0));
3330 Label materialize_true, materialize_false;
3331 Label* if_true = NULL;
3332 Label* if_false = NULL;
3333 Label* fall_through = NULL;
3334 context()->PrepareTest(&materialize_true, &materialize_false, &if_true,
3335 &if_false, &fall_through);
3337 PrepareForBailoutBeforeSplit(expr, true, if_true, if_false);
3338 __ TestIfSmi(r3, r0);
3339 Split(eq, if_true, if_false, fall_through, cr0);
3341 context()->Plug(if_true, if_false);
3345 void FullCodeGenerator::EmitIsNonNegativeSmi(CallRuntime* expr) {
3346 ZoneList<Expression*>* args = expr->arguments();
3347 DCHECK(args->length() == 1);
3349 VisitForAccumulatorValue(args->at(0));
3351 Label materialize_true, materialize_false;
3352 Label* if_true = NULL;
3353 Label* if_false = NULL;
3354 Label* fall_through = NULL;
3355 context()->PrepareTest(&materialize_true, &materialize_false, &if_true,
3356 &if_false, &fall_through);
3358 PrepareForBailoutBeforeSplit(expr, true, if_true, if_false);
3359 __ TestIfPositiveSmi(r3, r0);
3360 Split(eq, if_true, if_false, fall_through, cr0);
3362 context()->Plug(if_true, if_false);
3366 void FullCodeGenerator::EmitIsSpecObject(CallRuntime* expr) {
3367 ZoneList<Expression*>* args = expr->arguments();
3368 DCHECK(args->length() == 1);
3370 VisitForAccumulatorValue(args->at(0));
3372 Label materialize_true, materialize_false;
3373 Label* if_true = NULL;
3374 Label* if_false = NULL;
3375 Label* fall_through = NULL;
3376 context()->PrepareTest(&materialize_true, &materialize_false, &if_true,
3377 &if_false, &fall_through);
3379 __ JumpIfSmi(r3, if_false);
3380 __ CompareObjectType(r3, r4, r4, FIRST_SPEC_OBJECT_TYPE);
3381 PrepareForBailoutBeforeSplit(expr, true, if_true, if_false);
3382 Split(ge, if_true, if_false, fall_through);
3384 context()->Plug(if_true, if_false);
3388 void FullCodeGenerator::EmitIsSimdValue(CallRuntime* expr) {
3389 ZoneList<Expression*>* args = expr->arguments();
3390 DCHECK(args->length() == 1);
3392 VisitForAccumulatorValue(args->at(0));
3394 Label materialize_true, materialize_false;
3395 Label* if_true = NULL;
3396 Label* if_false = NULL;
3397 Label* fall_through = NULL;
3398 context()->PrepareTest(&materialize_true, &materialize_false, &if_true,
3399 &if_false, &fall_through);
3401 __ JumpIfSmi(r3, if_false);
3402 __ CompareObjectType(r3, r4, r4, SIMD128_VALUE_TYPE);
3403 PrepareForBailoutBeforeSplit(expr, true, if_true, if_false);
3404 Split(eq, if_true, if_false, fall_through);
3406 context()->Plug(if_true, if_false);
3410 void FullCodeGenerator::EmitIsStringWrapperSafeForDefaultValueOf(
3411 CallRuntime* expr) {
3412 ZoneList<Expression*>* args = expr->arguments();
3413 DCHECK(args->length() == 1);
3415 VisitForAccumulatorValue(args->at(0));
3417 Label materialize_true, materialize_false, skip_lookup;
3418 Label* if_true = NULL;
3419 Label* if_false = NULL;
3420 Label* fall_through = NULL;
3421 context()->PrepareTest(&materialize_true, &materialize_false, &if_true,
3422 &if_false, &fall_through);
3424 __ AssertNotSmi(r3);
3426 __ LoadP(r4, FieldMemOperand(r3, HeapObject::kMapOffset));
3427 __ lbz(ip, FieldMemOperand(r4, Map::kBitField2Offset));
3428 __ andi(r0, ip, Operand(1 << Map::kStringWrapperSafeForDefaultValueOf));
3429 __ bne(&skip_lookup, cr0);
3431 // Check for fast case object. Generate false result for slow case object.
3432 __ LoadP(r5, FieldMemOperand(r3, JSObject::kPropertiesOffset));
3433 __ LoadP(r5, FieldMemOperand(r5, HeapObject::kMapOffset));
3434 __ LoadRoot(ip, Heap::kHashTableMapRootIndex);
3438 // Look for valueOf name in the descriptor array, and indicate false if
3439 // found. Since we omit an enumeration index check, if it is added via a
3440 // transition that shares its descriptor array, this is a false positive.
3441 Label entry, loop, done;
3443 // Skip loop if no descriptors are valid.
3444 __ NumberOfOwnDescriptors(r6, r4);
3445 __ cmpi(r6, Operand::Zero());
3448 __ LoadInstanceDescriptors(r4, r7);
3449 // r7: descriptor array.
3450 // r6: valid entries in the descriptor array.
3451 __ mov(ip, Operand(DescriptorArray::kDescriptorSize));
3453 // Calculate location of the first key name.
3454 __ addi(r7, r7, Operand(DescriptorArray::kFirstOffset - kHeapObjectTag));
3455 // Calculate the end of the descriptor array.
3457 __ ShiftLeftImm(ip, r6, Operand(kPointerSizeLog2));
3460 // Loop through all the keys in the descriptor array. If one of these is the
3461 // string "valueOf" the result is false.
3462 // The use of ip to store the valueOf string assumes that it is not otherwise
3463 // used in the loop below.
3464 __ LoadRoot(ip, Heap::kvalueOf_stringRootIndex);
3467 __ LoadP(r6, MemOperand(r7, 0));
3470 __ addi(r7, r7, Operand(DescriptorArray::kDescriptorSize * kPointerSize));
3477 // Set the bit in the map to indicate that there is no local valueOf field.
3478 __ lbz(r5, FieldMemOperand(r4, Map::kBitField2Offset));
3479 __ ori(r5, r5, Operand(1 << Map::kStringWrapperSafeForDefaultValueOf));
3480 __ stb(r5, FieldMemOperand(r4, Map::kBitField2Offset));
3482 __ bind(&skip_lookup);
3484 // If a valueOf property is not found on the object check that its
3485 // prototype is the un-modified String prototype. If not result is false.
3486 __ LoadP(r5, FieldMemOperand(r4, Map::kPrototypeOffset));
3487 __ JumpIfSmi(r5, if_false);
3488 __ LoadP(r5, FieldMemOperand(r5, HeapObject::kMapOffset));
3489 __ LoadP(r6, ContextOperand(cp, Context::GLOBAL_OBJECT_INDEX));
3490 __ LoadP(r6, FieldMemOperand(r6, GlobalObject::kNativeContextOffset));
3492 ContextOperand(r6, Context::STRING_FUNCTION_PROTOTYPE_MAP_INDEX));
3494 PrepareForBailoutBeforeSplit(expr, true, if_true, if_false);
3495 Split(eq, if_true, if_false, fall_through);
3497 context()->Plug(if_true, if_false);
3501 void FullCodeGenerator::EmitIsFunction(CallRuntime* expr) {
3502 ZoneList<Expression*>* args = expr->arguments();
3503 DCHECK(args->length() == 1);
3505 VisitForAccumulatorValue(args->at(0));
3507 Label materialize_true, materialize_false;
3508 Label* if_true = NULL;
3509 Label* if_false = NULL;
3510 Label* fall_through = NULL;
3511 context()->PrepareTest(&materialize_true, &materialize_false, &if_true,
3512 &if_false, &fall_through);
3514 __ JumpIfSmi(r3, if_false);
3515 __ CompareObjectType(r3, r4, r5, JS_FUNCTION_TYPE);
3516 PrepareForBailoutBeforeSplit(expr, true, if_true, if_false);
3517 Split(eq, if_true, if_false, fall_through);
3519 context()->Plug(if_true, if_false);
3523 void FullCodeGenerator::EmitIsMinusZero(CallRuntime* expr) {
3524 ZoneList<Expression*>* args = expr->arguments();
3525 DCHECK(args->length() == 1);
3527 VisitForAccumulatorValue(args->at(0));
3529 Label materialize_true, materialize_false;
3530 Label* if_true = NULL;
3531 Label* if_false = NULL;
3532 Label* fall_through = NULL;
3533 context()->PrepareTest(&materialize_true, &materialize_false, &if_true,
3534 &if_false, &fall_through);
3536 __ CheckMap(r3, r4, Heap::kHeapNumberMapRootIndex, if_false, DO_SMI_CHECK);
3537 #if V8_TARGET_ARCH_PPC64
3538 __ LoadP(r4, FieldMemOperand(r3, HeapNumber::kValueOffset));
3539 __ li(r5, Operand(1));
3540 __ rotrdi(r5, r5, 1); // r5 = 0x80000000_00000000
3543 __ lwz(r5, FieldMemOperand(r3, HeapNumber::kExponentOffset));
3544 __ lwz(r4, FieldMemOperand(r3, HeapNumber::kMantissaOffset));
3546 __ lis(r0, Operand(SIGN_EXT_IMM16(0x8000)));
3549 __ cmpi(r4, Operand::Zero());
3553 PrepareForBailoutBeforeSplit(expr, true, if_true, if_false);
3554 Split(eq, if_true, if_false, fall_through);
3556 context()->Plug(if_true, if_false);
3560 void FullCodeGenerator::EmitIsArray(CallRuntime* expr) {
3561 ZoneList<Expression*>* args = expr->arguments();
3562 DCHECK(args->length() == 1);
3564 VisitForAccumulatorValue(args->at(0));
3566 Label materialize_true, materialize_false;
3567 Label* if_true = NULL;
3568 Label* if_false = NULL;
3569 Label* fall_through = NULL;
3570 context()->PrepareTest(&materialize_true, &materialize_false, &if_true,
3571 &if_false, &fall_through);
3573 __ JumpIfSmi(r3, if_false);
3574 __ CompareObjectType(r3, r4, r4, JS_ARRAY_TYPE);
3575 PrepareForBailoutBeforeSplit(expr, true, if_true, if_false);
3576 Split(eq, if_true, if_false, fall_through);
3578 context()->Plug(if_true, if_false);
3582 void FullCodeGenerator::EmitIsTypedArray(CallRuntime* expr) {
3583 ZoneList<Expression*>* args = expr->arguments();
3584 DCHECK(args->length() == 1);
3586 VisitForAccumulatorValue(args->at(0));
3588 Label materialize_true, materialize_false;
3589 Label* if_true = NULL;
3590 Label* if_false = NULL;
3591 Label* fall_through = NULL;
3592 context()->PrepareTest(&materialize_true, &materialize_false, &if_true,
3593 &if_false, &fall_through);
3595 __ JumpIfSmi(r3, if_false);
3596 __ CompareObjectType(r3, r4, r4, JS_TYPED_ARRAY_TYPE);
3597 PrepareForBailoutBeforeSplit(expr, true, if_true, if_false);
3598 Split(eq, if_true, if_false, fall_through);
3600 context()->Plug(if_true, if_false);
3604 void FullCodeGenerator::EmitIsRegExp(CallRuntime* expr) {
3605 ZoneList<Expression*>* args = expr->arguments();
3606 DCHECK(args->length() == 1);
3608 VisitForAccumulatorValue(args->at(0));
3610 Label materialize_true, materialize_false;
3611 Label* if_true = NULL;
3612 Label* if_false = NULL;
3613 Label* fall_through = NULL;
3614 context()->PrepareTest(&materialize_true, &materialize_false, &if_true,
3615 &if_false, &fall_through);
3617 __ JumpIfSmi(r3, if_false);
3618 __ CompareObjectType(r3, r4, r4, JS_REGEXP_TYPE);
3619 PrepareForBailoutBeforeSplit(expr, true, if_true, if_false);
3620 Split(eq, if_true, if_false, fall_through);
3622 context()->Plug(if_true, if_false);
3626 void FullCodeGenerator::EmitIsJSProxy(CallRuntime* expr) {
3627 ZoneList<Expression*>* args = expr->arguments();
3628 DCHECK(args->length() == 1);
3630 VisitForAccumulatorValue(args->at(0));
3632 Label materialize_true, materialize_false;
3633 Label* if_true = NULL;
3634 Label* if_false = NULL;
3635 Label* fall_through = NULL;
3636 context()->PrepareTest(&materialize_true, &materialize_false, &if_true,
3637 &if_false, &fall_through);
3639 __ JumpIfSmi(r3, if_false);
3641 Register type_reg = r5;
3642 __ LoadP(map, FieldMemOperand(r3, HeapObject::kMapOffset));
3643 __ lbz(type_reg, FieldMemOperand(map, Map::kInstanceTypeOffset));
3644 __ subi(type_reg, type_reg, Operand(FIRST_JS_PROXY_TYPE));
3645 __ cmpli(type_reg, Operand(LAST_JS_PROXY_TYPE - FIRST_JS_PROXY_TYPE));
3646 PrepareForBailoutBeforeSplit(expr, true, if_true, if_false);
3647 Split(le, if_true, if_false, fall_through);
3649 context()->Plug(if_true, if_false);
3653 void FullCodeGenerator::EmitIsConstructCall(CallRuntime* expr) {
3654 DCHECK(expr->arguments()->length() == 0);
3656 Label materialize_true, materialize_false;
3657 Label* if_true = NULL;
3658 Label* if_false = NULL;
3659 Label* fall_through = NULL;
3660 context()->PrepareTest(&materialize_true, &materialize_false, &if_true,
3661 &if_false, &fall_through);
3663 // Get the frame pointer for the calling frame.
3664 __ LoadP(r5, MemOperand(fp, StandardFrameConstants::kCallerFPOffset));
3666 // Skip the arguments adaptor frame if it exists.
3667 Label check_frame_marker;
3668 __ LoadP(r4, MemOperand(r5, StandardFrameConstants::kContextOffset));
3669 __ CmpSmiLiteral(r4, Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR), r0);
3670 __ bne(&check_frame_marker);
3671 __ LoadP(r5, MemOperand(r5, StandardFrameConstants::kCallerFPOffset));
3673 // Check the marker in the calling frame.
3674 __ bind(&check_frame_marker);
3675 __ LoadP(r4, MemOperand(r5, StandardFrameConstants::kMarkerOffset));
3676 STATIC_ASSERT(StackFrame::CONSTRUCT < 0x4000);
3677 __ CmpSmiLiteral(r4, Smi::FromInt(StackFrame::CONSTRUCT), r0);
3678 PrepareForBailoutBeforeSplit(expr, true, if_true, if_false);
3679 Split(eq, if_true, if_false, fall_through);
3681 context()->Plug(if_true, if_false);
3685 void FullCodeGenerator::EmitObjectEquals(CallRuntime* expr) {
3686 ZoneList<Expression*>* args = expr->arguments();
3687 DCHECK(args->length() == 2);
3689 // Load the two objects into registers and perform the comparison.
3690 VisitForStackValue(args->at(0));
3691 VisitForAccumulatorValue(args->at(1));
3693 Label materialize_true, materialize_false;
3694 Label* if_true = NULL;
3695 Label* if_false = NULL;
3696 Label* fall_through = NULL;
3697 context()->PrepareTest(&materialize_true, &materialize_false, &if_true,
3698 &if_false, &fall_through);
3702 PrepareForBailoutBeforeSplit(expr, true, if_true, if_false);
3703 Split(eq, if_true, if_false, fall_through);
3705 context()->Plug(if_true, if_false);
3709 void FullCodeGenerator::EmitArguments(CallRuntime* expr) {
3710 ZoneList<Expression*>* args = expr->arguments();
3711 DCHECK(args->length() == 1);
3713 // ArgumentsAccessStub expects the key in r4 and the formal
3714 // parameter count in r3.
3715 VisitForAccumulatorValue(args->at(0));
3717 __ LoadSmiLiteral(r3, Smi::FromInt(info_->scope()->num_parameters()));
3718 ArgumentsAccessStub stub(isolate(), ArgumentsAccessStub::READ_ELEMENT);
3720 context()->Plug(r3);
3724 void FullCodeGenerator::EmitArgumentsLength(CallRuntime* expr) {
3725 DCHECK(expr->arguments()->length() == 0);
3727 // Get the number of formal parameters.
3728 __ LoadSmiLiteral(r3, Smi::FromInt(info_->scope()->num_parameters()));
3730 // Check if the calling frame is an arguments adaptor frame.
3731 __ LoadP(r5, MemOperand(fp, StandardFrameConstants::kCallerFPOffset));
3732 __ LoadP(r6, MemOperand(r5, StandardFrameConstants::kContextOffset));
3733 __ CmpSmiLiteral(r6, Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR), r0);
3736 // Arguments adaptor case: Read the arguments length from the
3738 __ LoadP(r3, MemOperand(r5, ArgumentsAdaptorFrameConstants::kLengthOffset));
3741 context()->Plug(r3);
3745 void FullCodeGenerator::EmitClassOf(CallRuntime* expr) {
3746 ZoneList<Expression*>* args = expr->arguments();
3747 DCHECK(args->length() == 1);
3748 Label done, null, function, non_function_constructor;
3750 VisitForAccumulatorValue(args->at(0));
3752 // If the object is a smi, we return null.
3753 __ JumpIfSmi(r3, &null);
3755 // Check that the object is a JS object but take special care of JS
3756 // functions to make sure they have 'Function' as their class.
3757 // Assume that there are only two callable types, and one of them is at
3758 // either end of the type range for JS object types. Saves extra comparisons.
3759 STATIC_ASSERT(NUM_OF_CALLABLE_SPEC_OBJECT_TYPES == 2);
3760 __ CompareObjectType(r3, r3, r4, FIRST_SPEC_OBJECT_TYPE);
3761 // Map is now in r3.
3763 STATIC_ASSERT(FIRST_NONCALLABLE_SPEC_OBJECT_TYPE ==
3764 FIRST_SPEC_OBJECT_TYPE + 1);
3767 __ cmpi(r4, Operand(LAST_SPEC_OBJECT_TYPE));
3768 STATIC_ASSERT(LAST_NONCALLABLE_SPEC_OBJECT_TYPE == LAST_SPEC_OBJECT_TYPE - 1);
3770 // Assume that there is no larger type.
3771 STATIC_ASSERT(LAST_NONCALLABLE_SPEC_OBJECT_TYPE == LAST_TYPE - 1);
3773 // Check if the constructor in the map is a JS function.
3774 Register instance_type = r5;
3775 __ GetMapConstructor(r3, r3, r4, instance_type);
3776 __ cmpi(instance_type, Operand(JS_FUNCTION_TYPE));
3777 __ bne(&non_function_constructor);
3779 // r3 now contains the constructor function. Grab the
3780 // instance class name from there.
3781 __ LoadP(r3, FieldMemOperand(r3, JSFunction::kSharedFunctionInfoOffset));
3783 FieldMemOperand(r3, SharedFunctionInfo::kInstanceClassNameOffset));
3786 // Functions have class 'Function'.
3788 __ LoadRoot(r3, Heap::kFunction_stringRootIndex);
3791 // Objects with a non-function constructor have class 'Object'.
3792 __ bind(&non_function_constructor);
3793 __ LoadRoot(r3, Heap::kObject_stringRootIndex);
3796 // Non-JS objects have class null.
3798 __ LoadRoot(r3, Heap::kNullValueRootIndex);
3803 context()->Plug(r3);
3807 void FullCodeGenerator::EmitValueOf(CallRuntime* expr) {
3808 ZoneList<Expression*>* args = expr->arguments();
3809 DCHECK(args->length() == 1);
3810 VisitForAccumulatorValue(args->at(0)); // Load the object.
3813 // If the object is a smi return the object.
3814 __ JumpIfSmi(r3, &done);
3815 // If the object is not a value type, return the object.
3816 __ CompareObjectType(r3, r4, r4, JS_VALUE_TYPE);
3818 __ LoadP(r3, FieldMemOperand(r3, JSValue::kValueOffset));
3821 context()->Plug(r3);
3825 void FullCodeGenerator::EmitIsDate(CallRuntime* expr) {
3826 ZoneList<Expression*>* args = expr->arguments();
3827 DCHECK_EQ(1, args->length());
3829 VisitForAccumulatorValue(args->at(0));
3831 Label materialize_true, materialize_false;
3832 Label* if_true = nullptr;
3833 Label* if_false = nullptr;
3834 Label* fall_through = nullptr;
3835 context()->PrepareTest(&materialize_true, &materialize_false, &if_true,
3836 &if_false, &fall_through);
3838 __ JumpIfSmi(r3, if_false);
3839 __ CompareObjectType(r3, r4, r4, JS_DATE_TYPE);
3840 PrepareForBailoutBeforeSplit(expr, true, if_true, if_false);
3841 Split(eq, if_true, if_false, fall_through);
3843 context()->Plug(if_true, if_false);
3847 void FullCodeGenerator::EmitDateField(CallRuntime* expr) {
3848 ZoneList<Expression*>* args = expr->arguments();
3849 DCHECK(args->length() == 2);
3850 DCHECK_NOT_NULL(args->at(1)->AsLiteral());
3851 Smi* index = Smi::cast(*(args->at(1)->AsLiteral()->value()));
3853 VisitForAccumulatorValue(args->at(0)); // Load the object.
3855 Register object = r3;
3856 Register result = r3;
3857 Register scratch0 = r11;
3858 Register scratch1 = r4;
3860 if (index->value() == 0) {
3861 __ LoadP(result, FieldMemOperand(object, JSDate::kValueOffset));
3863 Label runtime, done;
3864 if (index->value() < JSDate::kFirstUncachedField) {
3865 ExternalReference stamp = ExternalReference::date_cache_stamp(isolate());
3866 __ mov(scratch1, Operand(stamp));
3867 __ LoadP(scratch1, MemOperand(scratch1));
3868 __ LoadP(scratch0, FieldMemOperand(object, JSDate::kCacheStampOffset));
3869 __ cmp(scratch1, scratch0);
3872 FieldMemOperand(object, JSDate::kValueOffset +
3873 kPointerSize * index->value()),
3878 __ PrepareCallCFunction(2, scratch1);
3879 __ LoadSmiLiteral(r4, index);
3880 __ CallCFunction(ExternalReference::get_date_field_function(isolate()), 2);
3884 context()->Plug(result);
3888 void FullCodeGenerator::EmitOneByteSeqStringSetChar(CallRuntime* expr) {
3889 ZoneList<Expression*>* args = expr->arguments();
3890 DCHECK_EQ(3, args->length());
3892 Register string = r3;
3893 Register index = r4;
3894 Register value = r5;
3896 VisitForStackValue(args->at(0)); // index
3897 VisitForStackValue(args->at(1)); // value
3898 VisitForAccumulatorValue(args->at(2)); // string
3899 __ Pop(index, value);
3901 if (FLAG_debug_code) {
3902 __ TestIfSmi(value, r0);
3903 __ Check(eq, kNonSmiValue, cr0);
3904 __ TestIfSmi(index, r0);
3905 __ Check(eq, kNonSmiIndex, cr0);
3906 __ SmiUntag(index, index);
3907 static const uint32_t one_byte_seq_type = kSeqStringTag | kOneByteStringTag;
3908 __ EmitSeqStringSetCharCheck(string, index, value, one_byte_seq_type);
3909 __ SmiTag(index, index);
3913 __ addi(ip, string, Operand(SeqOneByteString::kHeaderSize - kHeapObjectTag));
3914 __ SmiToByteArrayOffset(r0, index);
3915 __ stbx(value, MemOperand(ip, r0));
3916 context()->Plug(string);
3920 void FullCodeGenerator::EmitTwoByteSeqStringSetChar(CallRuntime* expr) {
3921 ZoneList<Expression*>* args = expr->arguments();
3922 DCHECK_EQ(3, args->length());
3924 Register string = r3;
3925 Register index = r4;
3926 Register value = r5;
3928 VisitForStackValue(args->at(0)); // index
3929 VisitForStackValue(args->at(1)); // value
3930 VisitForAccumulatorValue(args->at(2)); // string
3931 __ Pop(index, value);
3933 if (FLAG_debug_code) {
3934 __ TestIfSmi(value, r0);
3935 __ Check(eq, kNonSmiValue, cr0);
3936 __ TestIfSmi(index, r0);
3937 __ Check(eq, kNonSmiIndex, cr0);
3938 __ SmiUntag(index, index);
3939 static const uint32_t two_byte_seq_type = kSeqStringTag | kTwoByteStringTag;
3940 __ EmitSeqStringSetCharCheck(string, index, value, two_byte_seq_type);
3941 __ SmiTag(index, index);
3945 __ addi(ip, string, Operand(SeqTwoByteString::kHeaderSize - kHeapObjectTag));
3946 __ SmiToShortArrayOffset(r0, index);
3947 __ sthx(value, MemOperand(ip, r0));
3948 context()->Plug(string);
3952 void FullCodeGenerator::EmitSetValueOf(CallRuntime* expr) {
3953 ZoneList<Expression*>* args = expr->arguments();
3954 DCHECK(args->length() == 2);
3955 VisitForStackValue(args->at(0)); // Load the object.
3956 VisitForAccumulatorValue(args->at(1)); // Load the value.
3957 __ pop(r4); // r3 = value. r4 = object.
3960 // If the object is a smi, return the value.
3961 __ JumpIfSmi(r4, &done);
3963 // If the object is not a value type, return the value.
3964 __ CompareObjectType(r4, r5, r5, JS_VALUE_TYPE);
3968 __ StoreP(r3, FieldMemOperand(r4, JSValue::kValueOffset), r0);
3969 // Update the write barrier. Save the value as it will be
3970 // overwritten by the write barrier code and is needed afterward.
3972 __ RecordWriteField(r4, JSValue::kValueOffset, r5, r6, kLRHasBeenSaved,
3976 context()->Plug(r3);
3980 void FullCodeGenerator::EmitNumberToString(CallRuntime* expr) {
3981 ZoneList<Expression*>* args = expr->arguments();
3982 DCHECK_EQ(args->length(), 1);
3983 // Load the argument into r3 and call the stub.
3984 VisitForAccumulatorValue(args->at(0));
3986 NumberToStringStub stub(isolate());
3988 context()->Plug(r3);
3992 void FullCodeGenerator::EmitToObject(CallRuntime* expr) {
3993 ZoneList<Expression*>* args = expr->arguments();
3994 DCHECK_EQ(1, args->length());
3995 // Load the argument into r3 and convert it.
3996 VisitForAccumulatorValue(args->at(0));
3998 ToObjectStub stub(isolate());
4000 context()->Plug(r3);
4004 void FullCodeGenerator::EmitStringCharFromCode(CallRuntime* expr) {
4005 ZoneList<Expression*>* args = expr->arguments();
4006 DCHECK(args->length() == 1);
4007 VisitForAccumulatorValue(args->at(0));
4010 StringCharFromCodeGenerator generator(r3, r4);
4011 generator.GenerateFast(masm_);
4014 NopRuntimeCallHelper call_helper;
4015 generator.GenerateSlow(masm_, call_helper);
4018 context()->Plug(r4);
4022 void FullCodeGenerator::EmitStringCharCodeAt(CallRuntime* expr) {
4023 ZoneList<Expression*>* args = expr->arguments();
4024 DCHECK(args->length() == 2);
4025 VisitForStackValue(args->at(0));
4026 VisitForAccumulatorValue(args->at(1));
4028 Register object = r4;
4029 Register index = r3;
4030 Register result = r6;
4034 Label need_conversion;
4035 Label index_out_of_range;
4037 StringCharCodeAtGenerator generator(object, index, result, &need_conversion,
4038 &need_conversion, &index_out_of_range,
4039 STRING_INDEX_IS_NUMBER);
4040 generator.GenerateFast(masm_);
4043 __ bind(&index_out_of_range);
4044 // When the index is out of range, the spec requires us to return
4046 __ LoadRoot(result, Heap::kNanValueRootIndex);
4049 __ bind(&need_conversion);
4050 // Load the undefined value into the result register, which will
4051 // trigger conversion.
4052 __ LoadRoot(result, Heap::kUndefinedValueRootIndex);
4055 NopRuntimeCallHelper call_helper;
4056 generator.GenerateSlow(masm_, NOT_PART_OF_IC_HANDLER, call_helper);
4059 context()->Plug(result);
4063 void FullCodeGenerator::EmitStringCharAt(CallRuntime* expr) {
4064 ZoneList<Expression*>* args = expr->arguments();
4065 DCHECK(args->length() == 2);
4066 VisitForStackValue(args->at(0));
4067 VisitForAccumulatorValue(args->at(1));
4069 Register object = r4;
4070 Register index = r3;
4071 Register scratch = r6;
4072 Register result = r3;
4076 Label need_conversion;
4077 Label index_out_of_range;
4079 StringCharAtGenerator generator(object, index, scratch, result,
4080 &need_conversion, &need_conversion,
4081 &index_out_of_range, STRING_INDEX_IS_NUMBER);
4082 generator.GenerateFast(masm_);
4085 __ bind(&index_out_of_range);
4086 // When the index is out of range, the spec requires us to return
4087 // the empty string.
4088 __ LoadRoot(result, Heap::kempty_stringRootIndex);
4091 __ bind(&need_conversion);
4092 // Move smi zero into the result register, which will trigger
4094 __ LoadSmiLiteral(result, Smi::FromInt(0));
4097 NopRuntimeCallHelper call_helper;
4098 generator.GenerateSlow(masm_, NOT_PART_OF_IC_HANDLER, call_helper);
4101 context()->Plug(result);
4105 void FullCodeGenerator::EmitStringAdd(CallRuntime* expr) {
4106 ZoneList<Expression*>* args = expr->arguments();
4107 DCHECK_EQ(2, args->length());
4108 VisitForStackValue(args->at(0));
4109 VisitForAccumulatorValue(args->at(1));
4112 StringAddStub stub(isolate(), STRING_ADD_CHECK_BOTH, NOT_TENURED);
4114 context()->Plug(r3);
4118 void FullCodeGenerator::EmitCallFunction(CallRuntime* expr) {
4119 ZoneList<Expression*>* args = expr->arguments();
4120 DCHECK(args->length() >= 2);
4122 int arg_count = args->length() - 2; // 2 ~ receiver and function.
4123 for (int i = 0; i < arg_count + 1; i++) {
4124 VisitForStackValue(args->at(i));
4126 VisitForAccumulatorValue(args->last()); // Function.
4128 Label runtime, done;
4129 // Check for non-function argument (including proxy).
4130 __ JumpIfSmi(r3, &runtime);
4131 __ CompareObjectType(r3, r4, r4, JS_FUNCTION_TYPE);
4134 // InvokeFunction requires the function in r4. Move it in there.
4135 __ mr(r4, result_register());
4136 ParameterCount count(arg_count);
4137 __ InvokeFunction(r4, count, CALL_FUNCTION, NullCallWrapper());
4138 __ LoadP(cp, MemOperand(fp, StandardFrameConstants::kContextOffset));
4143 __ CallRuntime(Runtime::kCall, args->length());
4146 context()->Plug(r3);
4150 void FullCodeGenerator::EmitDefaultConstructorCallSuper(CallRuntime* expr) {
4151 ZoneList<Expression*>* args = expr->arguments();
4152 DCHECK(args->length() == 2);
4155 VisitForStackValue(args->at(0));
4158 VisitForStackValue(args->at(1));
4159 __ CallRuntime(Runtime::kGetPrototype, 1);
4160 __ mr(r4, result_register());
4163 // Load original constructor into r7.
4164 __ LoadP(r7, MemOperand(sp, 1 * kPointerSize));
4166 // Check if the calling frame is an arguments adaptor frame.
4167 Label adaptor_frame, args_set_up, runtime;
4168 __ LoadP(r5, MemOperand(fp, StandardFrameConstants::kCallerFPOffset));
4169 __ LoadP(r6, MemOperand(r5, StandardFrameConstants::kContextOffset));
4170 __ CmpSmiLiteral(r6, Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR), r0);
4171 __ beq(&adaptor_frame);
4173 // default constructor has no arguments, so no adaptor frame means no args.
4174 __ li(r3, Operand::Zero());
4177 // Copy arguments from adaptor frame.
4179 __ bind(&adaptor_frame);
4180 __ LoadP(r3, MemOperand(r5, ArgumentsAdaptorFrameConstants::kLengthOffset));
4183 // Get arguments pointer in r5.
4184 __ ShiftLeftImm(r0, r3, Operand(kPointerSizeLog2));
4186 __ addi(r5, r5, Operand(StandardFrameConstants::kCallerSPOffset));
4191 // Pre-decrement in order to skip receiver.
4192 __ LoadPU(r6, MemOperand(r5, -kPointerSize));
4197 __ bind(&args_set_up);
4198 __ LoadRoot(r5, Heap::kUndefinedValueRootIndex);
4200 CallConstructStub stub(isolate(), SUPER_CONSTRUCTOR_CALL);
4201 __ Call(stub.GetCode(), RelocInfo::CONSTRUCT_CALL);
4205 context()->Plug(result_register());
4209 void FullCodeGenerator::EmitRegExpConstructResult(CallRuntime* expr) {
4210 RegExpConstructResultStub stub(isolate());
4211 ZoneList<Expression*>* args = expr->arguments();
4212 DCHECK(args->length() == 3);
4213 VisitForStackValue(args->at(0));
4214 VisitForStackValue(args->at(1));
4215 VisitForAccumulatorValue(args->at(2));
4218 context()->Plug(r3);
4222 void FullCodeGenerator::EmitHasCachedArrayIndex(CallRuntime* expr) {
4223 ZoneList<Expression*>* args = expr->arguments();
4224 VisitForAccumulatorValue(args->at(0));
4226 Label materialize_true, materialize_false;
4227 Label* if_true = NULL;
4228 Label* if_false = NULL;
4229 Label* fall_through = NULL;
4230 context()->PrepareTest(&materialize_true, &materialize_false, &if_true,
4231 &if_false, &fall_through);
4233 __ lwz(r3, FieldMemOperand(r3, String::kHashFieldOffset));
4234 // PPC - assume ip is free
4235 __ mov(ip, Operand(String::kContainsCachedArrayIndexMask));
4236 __ and_(r0, r3, ip, SetRC);
4237 PrepareForBailoutBeforeSplit(expr, true, if_true, if_false);
4238 Split(eq, if_true, if_false, fall_through, cr0);
4240 context()->Plug(if_true, if_false);
4244 void FullCodeGenerator::EmitGetCachedArrayIndex(CallRuntime* expr) {
4245 ZoneList<Expression*>* args = expr->arguments();
4246 DCHECK(args->length() == 1);
4247 VisitForAccumulatorValue(args->at(0));
4249 __ AssertString(r3);
4251 __ lwz(r3, FieldMemOperand(r3, String::kHashFieldOffset));
4252 __ IndexFromHash(r3, r3);
4254 context()->Plug(r3);
4258 void FullCodeGenerator::EmitFastOneByteArrayJoin(CallRuntime* expr) {
4259 Label bailout, done, one_char_separator, long_separator, non_trivial_array,
4260 not_size_one_array, loop, empty_separator_loop, one_char_separator_loop,
4261 one_char_separator_loop_entry, long_separator_loop;
4262 ZoneList<Expression*>* args = expr->arguments();
4263 DCHECK(args->length() == 2);
4264 VisitForStackValue(args->at(1));
4265 VisitForAccumulatorValue(args->at(0));
4267 // All aliases of the same register have disjoint lifetimes.
4268 Register array = r3;
4269 Register elements = no_reg; // Will be r3.
4270 Register result = no_reg; // Will be r3.
4271 Register separator = r4;
4272 Register array_length = r5;
4273 Register result_pos = no_reg; // Will be r5
4274 Register string_length = r6;
4275 Register string = r7;
4276 Register element = r8;
4277 Register elements_end = r9;
4278 Register scratch1 = r10;
4279 Register scratch2 = r11;
4281 // Separator operand is on the stack.
4284 // Check that the array is a JSArray.
4285 __ JumpIfSmi(array, &bailout);
4286 __ CompareObjectType(array, scratch1, scratch2, JS_ARRAY_TYPE);
4289 // Check that the array has fast elements.
4290 __ CheckFastElements(scratch1, scratch2, &bailout);
4292 // If the array has length zero, return the empty string.
4293 __ LoadP(array_length, FieldMemOperand(array, JSArray::kLengthOffset));
4294 __ SmiUntag(array_length);
4295 __ cmpi(array_length, Operand::Zero());
4296 __ bne(&non_trivial_array);
4297 __ LoadRoot(r3, Heap::kempty_stringRootIndex);
4300 __ bind(&non_trivial_array);
4302 // Get the FixedArray containing array's elements.
4304 __ LoadP(elements, FieldMemOperand(array, JSArray::kElementsOffset));
4305 array = no_reg; // End of array's live range.
4307 // Check that all array elements are sequential one-byte strings, and
4308 // accumulate the sum of their lengths, as a smi-encoded value.
4309 __ li(string_length, Operand::Zero());
4310 __ addi(element, elements, Operand(FixedArray::kHeaderSize - kHeapObjectTag));
4311 __ ShiftLeftImm(elements_end, array_length, Operand(kPointerSizeLog2));
4312 __ add(elements_end, element, elements_end);
4313 // Loop condition: while (element < elements_end).
4314 // Live values in registers:
4315 // elements: Fixed array of strings.
4316 // array_length: Length of the fixed array of strings (not smi)
4317 // separator: Separator string
4318 // string_length: Accumulated sum of string lengths (smi).
4319 // element: Current array element.
4320 // elements_end: Array end.
4321 if (generate_debug_code_) {
4322 __ cmpi(array_length, Operand::Zero());
4323 __ Assert(gt, kNoEmptyArraysHereInEmitFastOneByteArrayJoin);
4326 __ LoadP(string, MemOperand(element));
4327 __ addi(element, element, Operand(kPointerSize));
4328 __ JumpIfSmi(string, &bailout);
4329 __ LoadP(scratch1, FieldMemOperand(string, HeapObject::kMapOffset));
4330 __ lbz(scratch1, FieldMemOperand(scratch1, Map::kInstanceTypeOffset));
4331 __ JumpIfInstanceTypeIsNotSequentialOneByte(scratch1, scratch2, &bailout);
4332 __ LoadP(scratch1, FieldMemOperand(string, SeqOneByteString::kLengthOffset));
4334 __ AddAndCheckForOverflow(string_length, string_length, scratch1, scratch2,
4336 __ BranchOnOverflow(&bailout);
4338 __ cmp(element, elements_end);
4341 // If array_length is 1, return elements[0], a string.
4342 __ cmpi(array_length, Operand(1));
4343 __ bne(¬_size_one_array);
4344 __ LoadP(r3, FieldMemOperand(elements, FixedArray::kHeaderSize));
4347 __ bind(¬_size_one_array);
4349 // Live values in registers:
4350 // separator: Separator string
4351 // array_length: Length of the array.
4352 // string_length: Sum of string lengths (smi).
4353 // elements: FixedArray of strings.
4355 // Check that the separator is a flat one-byte string.
4356 __ JumpIfSmi(separator, &bailout);
4357 __ LoadP(scratch1, FieldMemOperand(separator, HeapObject::kMapOffset));
4358 __ lbz(scratch1, FieldMemOperand(scratch1, Map::kInstanceTypeOffset));
4359 __ JumpIfInstanceTypeIsNotSequentialOneByte(scratch1, scratch2, &bailout);
4361 // Add (separator length times array_length) - separator length to the
4362 // string_length to get the length of the result string.
4364 FieldMemOperand(separator, SeqOneByteString::kLengthOffset));
4365 __ sub(string_length, string_length, scratch1);
4366 #if V8_TARGET_ARCH_PPC64
4367 __ SmiUntag(scratch1, scratch1);
4368 __ Mul(scratch2, array_length, scratch1);
4369 // Check for smi overflow. No overflow if higher 33 bits of 64-bit result are
4371 __ ShiftRightImm(ip, scratch2, Operand(31), SetRC);
4372 __ bne(&bailout, cr0);
4373 __ SmiTag(scratch2, scratch2);
4375 // array_length is not smi but the other values are, so the result is a smi
4376 __ mullw(scratch2, array_length, scratch1);
4377 __ mulhw(ip, array_length, scratch1);
4378 // Check for smi overflow. No overflow if higher 33 bits of 64-bit result are
4380 __ cmpi(ip, Operand::Zero());
4382 __ cmpwi(scratch2, Operand::Zero());
4386 __ AddAndCheckForOverflow(string_length, string_length, scratch2, scratch1,
4388 __ BranchOnOverflow(&bailout);
4389 __ SmiUntag(string_length);
4391 // Get first element in the array to free up the elements register to be used
4393 __ addi(element, elements, Operand(FixedArray::kHeaderSize - kHeapObjectTag));
4394 result = elements; // End of live range for elements.
4396 // Live values in registers:
4397 // element: First array element
4398 // separator: Separator string
4399 // string_length: Length of result string (not smi)
4400 // array_length: Length of the array.
4401 __ AllocateOneByteString(result, string_length, scratch1, scratch2,
4402 elements_end, &bailout);
4403 // Prepare for looping. Set up elements_end to end of the array. Set
4404 // result_pos to the position of the result where to write the first
4406 __ ShiftLeftImm(elements_end, array_length, Operand(kPointerSizeLog2));
4407 __ add(elements_end, element, elements_end);
4408 result_pos = array_length; // End of live range for array_length.
4409 array_length = no_reg;
4410 __ addi(result_pos, result,
4411 Operand(SeqOneByteString::kHeaderSize - kHeapObjectTag));
4413 // Check the length of the separator.
4415 FieldMemOperand(separator, SeqOneByteString::kLengthOffset));
4416 __ CmpSmiLiteral(scratch1, Smi::FromInt(1), r0);
4417 __ beq(&one_char_separator);
4418 __ bgt(&long_separator);
4420 // Empty separator case
4421 __ bind(&empty_separator_loop);
4422 // Live values in registers:
4423 // result_pos: the position to which we are currently copying characters.
4424 // element: Current array element.
4425 // elements_end: Array end.
4427 // Copy next array element to the result.
4428 __ LoadP(string, MemOperand(element));
4429 __ addi(element, element, Operand(kPointerSize));
4430 __ LoadP(string_length, FieldMemOperand(string, String::kLengthOffset));
4431 __ SmiUntag(string_length);
4432 __ addi(string, string,
4433 Operand(SeqOneByteString::kHeaderSize - kHeapObjectTag));
4434 __ CopyBytes(string, result_pos, string_length, scratch1);
4435 __ cmp(element, elements_end);
4436 __ blt(&empty_separator_loop); // End while (element < elements_end).
4437 DCHECK(result.is(r3));
4440 // One-character separator case
4441 __ bind(&one_char_separator);
4442 // Replace separator with its one-byte character value.
4443 __ lbz(separator, FieldMemOperand(separator, SeqOneByteString::kHeaderSize));
4444 // Jump into the loop after the code that copies the separator, so the first
4445 // element is not preceded by a separator
4446 __ b(&one_char_separator_loop_entry);
4448 __ bind(&one_char_separator_loop);
4449 // Live values in registers:
4450 // result_pos: the position to which we are currently copying characters.
4451 // element: Current array element.
4452 // elements_end: Array end.
4453 // separator: Single separator one-byte char (in lower byte).
4455 // Copy the separator character to the result.
4456 __ stb(separator, MemOperand(result_pos));
4457 __ addi(result_pos, result_pos, Operand(1));
4459 // Copy next array element to the result.
4460 __ bind(&one_char_separator_loop_entry);
4461 __ LoadP(string, MemOperand(element));
4462 __ addi(element, element, Operand(kPointerSize));
4463 __ LoadP(string_length, FieldMemOperand(string, String::kLengthOffset));
4464 __ SmiUntag(string_length);
4465 __ addi(string, string,
4466 Operand(SeqOneByteString::kHeaderSize - kHeapObjectTag));
4467 __ CopyBytes(string, result_pos, string_length, scratch1);
4468 __ cmpl(element, elements_end);
4469 __ blt(&one_char_separator_loop); // End while (element < elements_end).
4470 DCHECK(result.is(r3));
4473 // Long separator case (separator is more than one character). Entry is at the
4474 // label long_separator below.
4475 __ bind(&long_separator_loop);
4476 // Live values in registers:
4477 // result_pos: the position to which we are currently copying characters.
4478 // element: Current array element.
4479 // elements_end: Array end.
4480 // separator: Separator string.
4482 // Copy the separator to the result.
4483 __ LoadP(string_length, FieldMemOperand(separator, String::kLengthOffset));
4484 __ SmiUntag(string_length);
4485 __ addi(string, separator,
4486 Operand(SeqOneByteString::kHeaderSize - kHeapObjectTag));
4487 __ CopyBytes(string, result_pos, string_length, scratch1);
4489 __ bind(&long_separator);
4490 __ LoadP(string, MemOperand(element));
4491 __ addi(element, element, Operand(kPointerSize));
4492 __ LoadP(string_length, FieldMemOperand(string, String::kLengthOffset));
4493 __ SmiUntag(string_length);
4494 __ addi(string, string,
4495 Operand(SeqOneByteString::kHeaderSize - kHeapObjectTag));
4496 __ CopyBytes(string, result_pos, string_length, scratch1);
4497 __ cmpl(element, elements_end);
4498 __ blt(&long_separator_loop); // End while (element < elements_end).
4499 DCHECK(result.is(r3));
4503 __ LoadRoot(r3, Heap::kUndefinedValueRootIndex);
4505 context()->Plug(r3);
4509 void FullCodeGenerator::EmitDebugIsActive(CallRuntime* expr) {
4510 DCHECK(expr->arguments()->length() == 0);
4511 ExternalReference debug_is_active =
4512 ExternalReference::debug_is_active_address(isolate());
4513 __ mov(ip, Operand(debug_is_active));
4514 __ lbz(r3, MemOperand(ip));
4516 context()->Plug(r3);
4520 void FullCodeGenerator::EmitLoadJSRuntimeFunction(CallRuntime* expr) {
4521 // Push undefined as the receiver.
4522 __ LoadRoot(r3, Heap::kUndefinedValueRootIndex);
4525 __ LoadP(r3, GlobalObjectOperand());
4526 __ LoadP(r3, FieldMemOperand(r3, GlobalObject::kNativeContextOffset));
4527 __ LoadP(r3, ContextOperand(r3, expr->context_index()));
4531 void FullCodeGenerator::EmitCallJSRuntimeFunction(CallRuntime* expr) {
4532 ZoneList<Expression*>* args = expr->arguments();
4533 int arg_count = args->length();
4535 SetCallPosition(expr, arg_count);
4536 CallFunctionStub stub(isolate(), arg_count, NO_CALL_FUNCTION_FLAGS);
4537 __ LoadP(r4, MemOperand(sp, (arg_count + 1) * kPointerSize), r0);
4542 void FullCodeGenerator::VisitCallRuntime(CallRuntime* expr) {
4543 ZoneList<Expression*>* args = expr->arguments();
4544 int arg_count = args->length();
4546 if (expr->is_jsruntime()) {
4547 Comment cmnt(masm_, "[ CallRuntime");
4548 EmitLoadJSRuntimeFunction(expr);
4550 // Push the target function under the receiver.
4551 __ LoadP(ip, MemOperand(sp, 0));
4553 __ StoreP(r3, MemOperand(sp, kPointerSize));
4555 // Push the arguments ("left-to-right").
4556 for (int i = 0; i < arg_count; i++) {
4557 VisitForStackValue(args->at(i));
4560 PrepareForBailoutForId(expr->CallId(), NO_REGISTERS);
4561 EmitCallJSRuntimeFunction(expr);
4563 // Restore context register.
4564 __ LoadP(cp, MemOperand(fp, StandardFrameConstants::kContextOffset));
4566 context()->DropAndPlug(1, r3);
4569 const Runtime::Function* function = expr->function();
4570 switch (function->function_id) {
4571 #define CALL_INTRINSIC_GENERATOR(Name) \
4572 case Runtime::kInline##Name: { \
4573 Comment cmnt(masm_, "[ Inline" #Name); \
4574 return Emit##Name(expr); \
4576 FOR_EACH_FULL_CODE_INTRINSIC(CALL_INTRINSIC_GENERATOR)
4577 #undef CALL_INTRINSIC_GENERATOR
4579 Comment cmnt(masm_, "[ CallRuntime for unhandled intrinsic");
4580 // Push the arguments ("left-to-right").
4581 for (int i = 0; i < arg_count; i++) {
4582 VisitForStackValue(args->at(i));
4585 // Call the C runtime function.
4586 PrepareForBailoutForId(expr->CallId(), NO_REGISTERS);
4587 __ CallRuntime(expr->function(), arg_count);
4588 context()->Plug(r3);
4595 void FullCodeGenerator::VisitUnaryOperation(UnaryOperation* expr) {
4596 switch (expr->op()) {
4597 case Token::DELETE: {
4598 Comment cmnt(masm_, "[ UnaryOperation (DELETE)");
4599 Property* property = expr->expression()->AsProperty();
4600 VariableProxy* proxy = expr->expression()->AsVariableProxy();
4602 if (property != NULL) {
4603 VisitForStackValue(property->obj());
4604 VisitForStackValue(property->key());
4605 __ CallRuntime(is_strict(language_mode())
4606 ? Runtime::kDeleteProperty_Strict
4607 : Runtime::kDeleteProperty_Sloppy,
4609 context()->Plug(r3);
4610 } else if (proxy != NULL) {
4611 Variable* var = proxy->var();
4612 // Delete of an unqualified identifier is disallowed in strict mode but
4613 // "delete this" is allowed.
4614 bool is_this = var->HasThisName(isolate());
4615 DCHECK(is_sloppy(language_mode()) || is_this);
4616 if (var->IsUnallocatedOrGlobalSlot()) {
4617 __ LoadP(r5, GlobalObjectOperand());
4618 __ mov(r4, Operand(var->name()));
4620 __ CallRuntime(Runtime::kDeleteProperty_Sloppy, 2);
4621 context()->Plug(r3);
4622 } else if (var->IsStackAllocated() || var->IsContextSlot()) {
4623 // Result of deleting non-global, non-dynamic variables is false.
4624 // The subexpression does not have side effects.
4625 context()->Plug(is_this);
4627 // Non-global variable. Call the runtime to try to delete from the
4628 // context where the variable was introduced.
4629 DCHECK(!context_register().is(r5));
4630 __ mov(r5, Operand(var->name()));
4631 __ Push(context_register(), r5);
4632 __ CallRuntime(Runtime::kDeleteLookupSlot, 2);
4633 context()->Plug(r3);
4636 // Result of deleting non-property, non-variable reference is true.
4637 // The subexpression may have side effects.
4638 VisitForEffect(expr->expression());
4639 context()->Plug(true);
4645 Comment cmnt(masm_, "[ UnaryOperation (VOID)");
4646 VisitForEffect(expr->expression());
4647 context()->Plug(Heap::kUndefinedValueRootIndex);
4652 Comment cmnt(masm_, "[ UnaryOperation (NOT)");
4653 if (context()->IsEffect()) {
4654 // Unary NOT has no side effects so it's only necessary to visit the
4655 // subexpression. Match the optimizing compiler by not branching.
4656 VisitForEffect(expr->expression());
4657 } else if (context()->IsTest()) {
4658 const TestContext* test = TestContext::cast(context());
4659 // The labels are swapped for the recursive call.
4660 VisitForControl(expr->expression(), test->false_label(),
4661 test->true_label(), test->fall_through());
4662 context()->Plug(test->true_label(), test->false_label());
4664 // We handle value contexts explicitly rather than simply visiting
4665 // for control and plugging the control flow into the context,
4666 // because we need to prepare a pair of extra administrative AST ids
4667 // for the optimizing compiler.
4668 DCHECK(context()->IsAccumulatorValue() || context()->IsStackValue());
4669 Label materialize_true, materialize_false, done;
4670 VisitForControl(expr->expression(), &materialize_false,
4671 &materialize_true, &materialize_true);
4672 __ bind(&materialize_true);
4673 PrepareForBailoutForId(expr->MaterializeTrueId(), NO_REGISTERS);
4674 __ LoadRoot(r3, Heap::kTrueValueRootIndex);
4675 if (context()->IsStackValue()) __ push(r3);
4677 __ bind(&materialize_false);
4678 PrepareForBailoutForId(expr->MaterializeFalseId(), NO_REGISTERS);
4679 __ LoadRoot(r3, Heap::kFalseValueRootIndex);
4680 if (context()->IsStackValue()) __ push(r3);
4686 case Token::TYPEOF: {
4687 Comment cmnt(masm_, "[ UnaryOperation (TYPEOF)");
4689 AccumulatorValueContext context(this);
4690 VisitForTypeofValue(expr->expression());
4693 TypeofStub typeof_stub(isolate());
4694 __ CallStub(&typeof_stub);
4695 context()->Plug(r3);
4705 void FullCodeGenerator::VisitCountOperation(CountOperation* expr) {
4706 DCHECK(expr->expression()->IsValidReferenceExpressionOrThis());
4708 Comment cmnt(masm_, "[ CountOperation");
4710 Property* prop = expr->expression()->AsProperty();
4711 LhsKind assign_type = Property::GetAssignType(prop);
4713 // Evaluate expression and get value.
4714 if (assign_type == VARIABLE) {
4715 DCHECK(expr->expression()->AsVariableProxy()->var() != NULL);
4716 AccumulatorValueContext context(this);
4717 EmitVariableLoad(expr->expression()->AsVariableProxy());
4719 // Reserve space for result of postfix operation.
4720 if (expr->is_postfix() && !context()->IsEffect()) {
4721 __ LoadSmiLiteral(ip, Smi::FromInt(0));
4724 switch (assign_type) {
4725 case NAMED_PROPERTY: {
4726 // Put the object both on the stack and in the register.
4727 VisitForStackValue(prop->obj());
4728 __ LoadP(LoadDescriptor::ReceiverRegister(), MemOperand(sp, 0));
4729 EmitNamedPropertyLoad(prop);
4733 case NAMED_SUPER_PROPERTY: {
4734 VisitForStackValue(prop->obj()->AsSuperPropertyReference()->this_var());
4735 VisitForAccumulatorValue(
4736 prop->obj()->AsSuperPropertyReference()->home_object());
4737 __ Push(result_register());
4738 const Register scratch = r4;
4739 __ LoadP(scratch, MemOperand(sp, kPointerSize));
4740 __ Push(scratch, result_register());
4741 EmitNamedSuperPropertyLoad(prop);
4745 case KEYED_SUPER_PROPERTY: {
4746 VisitForStackValue(prop->obj()->AsSuperPropertyReference()->this_var());
4747 VisitForAccumulatorValue(
4748 prop->obj()->AsSuperPropertyReference()->home_object());
4749 const Register scratch = r4;
4750 const Register scratch1 = r5;
4751 __ mr(scratch, result_register());
4752 VisitForAccumulatorValue(prop->key());
4753 __ Push(scratch, result_register());
4754 __ LoadP(scratch1, MemOperand(sp, 2 * kPointerSize));
4755 __ Push(scratch1, scratch, result_register());
4756 EmitKeyedSuperPropertyLoad(prop);
4760 case KEYED_PROPERTY: {
4761 VisitForStackValue(prop->obj());
4762 VisitForStackValue(prop->key());
4763 __ LoadP(LoadDescriptor::ReceiverRegister(),
4764 MemOperand(sp, 1 * kPointerSize));
4765 __ LoadP(LoadDescriptor::NameRegister(), MemOperand(sp, 0));
4766 EmitKeyedPropertyLoad(prop);
4775 // We need a second deoptimization point after loading the value
4776 // in case evaluating the property load my have a side effect.
4777 if (assign_type == VARIABLE) {
4778 PrepareForBailout(expr->expression(), TOS_REG);
4780 PrepareForBailoutForId(prop->LoadId(), TOS_REG);
4783 // Inline smi case if we are in a loop.
4784 Label stub_call, done;
4785 JumpPatchSite patch_site(masm_);
4787 int count_value = expr->op() == Token::INC ? 1 : -1;
4788 if (ShouldInlineSmiCase(expr->op())) {
4790 patch_site.EmitJumpIfNotSmi(r3, &slow);
4792 // Save result for postfix expressions.
4793 if (expr->is_postfix()) {
4794 if (!context()->IsEffect()) {
4795 // Save the result on the stack. If we have a named or keyed property
4796 // we store the result under the receiver that is currently on top
4798 switch (assign_type) {
4802 case NAMED_PROPERTY:
4803 __ StoreP(r3, MemOperand(sp, kPointerSize));
4805 case NAMED_SUPER_PROPERTY:
4806 __ StoreP(r3, MemOperand(sp, 2 * kPointerSize));
4808 case KEYED_PROPERTY:
4809 __ StoreP(r3, MemOperand(sp, 2 * kPointerSize));
4811 case KEYED_SUPER_PROPERTY:
4812 __ StoreP(r3, MemOperand(sp, 3 * kPointerSize));
4818 Register scratch1 = r4;
4819 Register scratch2 = r5;
4820 __ LoadSmiLiteral(scratch1, Smi::FromInt(count_value));
4821 __ AddAndCheckForOverflow(r3, r3, scratch1, scratch2, r0);
4822 __ BranchOnNoOverflow(&done);
4823 // Call stub. Undo operation first.
4824 __ sub(r3, r3, scratch1);
4828 if (!is_strong(language_mode())) {
4829 ToNumberStub convert_stub(isolate());
4830 __ CallStub(&convert_stub);
4831 PrepareForBailoutForId(expr->ToNumberId(), TOS_REG);
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 __ StoreP(r3, MemOperand(sp, kPointerSize));
4847 case NAMED_SUPER_PROPERTY:
4848 __ StoreP(r3, MemOperand(sp, 2 * kPointerSize));
4850 case KEYED_PROPERTY:
4851 __ StoreP(r3, MemOperand(sp, 2 * kPointerSize));
4853 case KEYED_SUPER_PROPERTY:
4854 __ StoreP(r3, MemOperand(sp, 3 * kPointerSize));
4860 __ bind(&stub_call);
4862 __ LoadSmiLiteral(r3, Smi::FromInt(count_value));
4864 SetExpressionPosition(expr);
4866 Handle<Code> code = CodeFactory::BinaryOpIC(isolate(), Token::ADD,
4867 strength(language_mode())).code();
4868 CallIC(code, expr->CountBinOpFeedbackId());
4869 patch_site.EmitPatchInfo();
4872 if (is_strong(language_mode())) {
4873 PrepareForBailoutForId(expr->ToNumberId(), TOS_REG);
4875 // Store the value returned in r3.
4876 switch (assign_type) {
4878 if (expr->is_postfix()) {
4880 EffectContext context(this);
4881 EmitVariableAssignment(expr->expression()->AsVariableProxy()->var(),
4882 Token::ASSIGN, expr->CountSlot());
4883 PrepareForBailoutForId(expr->AssignmentId(), TOS_REG);
4886 // For all contexts except EffectConstant We have the result on
4887 // top of the stack.
4888 if (!context()->IsEffect()) {
4889 context()->PlugTOS();
4892 EmitVariableAssignment(expr->expression()->AsVariableProxy()->var(),
4893 Token::ASSIGN, expr->CountSlot());
4894 PrepareForBailoutForId(expr->AssignmentId(), TOS_REG);
4895 context()->Plug(r3);
4898 case NAMED_PROPERTY: {
4899 __ mov(StoreDescriptor::NameRegister(),
4900 Operand(prop->key()->AsLiteral()->value()));
4901 __ pop(StoreDescriptor::ReceiverRegister());
4902 if (FLAG_vector_stores) {
4903 EmitLoadStoreICSlot(expr->CountSlot());
4906 CallStoreIC(expr->CountStoreFeedbackId());
4908 PrepareForBailoutForId(expr->AssignmentId(), TOS_REG);
4909 if (expr->is_postfix()) {
4910 if (!context()->IsEffect()) {
4911 context()->PlugTOS();
4914 context()->Plug(r3);
4918 case NAMED_SUPER_PROPERTY: {
4919 EmitNamedSuperPropertyStore(prop);
4920 if (expr->is_postfix()) {
4921 if (!context()->IsEffect()) {
4922 context()->PlugTOS();
4925 context()->Plug(r3);
4929 case KEYED_SUPER_PROPERTY: {
4930 EmitKeyedSuperPropertyStore(prop);
4931 if (expr->is_postfix()) {
4932 if (!context()->IsEffect()) {
4933 context()->PlugTOS();
4936 context()->Plug(r3);
4940 case KEYED_PROPERTY: {
4941 __ Pop(StoreDescriptor::ReceiverRegister(),
4942 StoreDescriptor::NameRegister());
4944 CodeFactory::KeyedStoreIC(isolate(), language_mode()).code();
4945 if (FLAG_vector_stores) {
4946 EmitLoadStoreICSlot(expr->CountSlot());
4949 CallIC(ic, expr->CountStoreFeedbackId());
4951 PrepareForBailoutForId(expr->AssignmentId(), TOS_REG);
4952 if (expr->is_postfix()) {
4953 if (!context()->IsEffect()) {
4954 context()->PlugTOS();
4957 context()->Plug(r3);
4965 void FullCodeGenerator::EmitLiteralCompareTypeof(Expression* expr,
4966 Expression* sub_expr,
4967 Handle<String> check) {
4968 Label materialize_true, materialize_false;
4969 Label* if_true = NULL;
4970 Label* if_false = NULL;
4971 Label* fall_through = NULL;
4972 context()->PrepareTest(&materialize_true, &materialize_false, &if_true,
4973 &if_false, &fall_through);
4976 AccumulatorValueContext context(this);
4977 VisitForTypeofValue(sub_expr);
4979 PrepareForBailoutBeforeSplit(expr, true, if_true, if_false);
4981 Factory* factory = isolate()->factory();
4982 if (String::Equals(check, factory->number_string())) {
4983 __ JumpIfSmi(r3, if_true);
4984 __ LoadP(r3, FieldMemOperand(r3, HeapObject::kMapOffset));
4985 __ LoadRoot(ip, Heap::kHeapNumberMapRootIndex);
4987 Split(eq, if_true, if_false, fall_through);
4988 } else if (String::Equals(check, factory->string_string())) {
4989 __ JumpIfSmi(r3, if_false);
4990 __ CompareObjectType(r3, r3, r4, FIRST_NONSTRING_TYPE);
4991 Split(lt, if_true, if_false, fall_through);
4992 } else if (String::Equals(check, factory->symbol_string())) {
4993 __ JumpIfSmi(r3, if_false);
4994 __ CompareObjectType(r3, r3, r4, SYMBOL_TYPE);
4995 Split(eq, if_true, if_false, fall_through);
4996 } else if (String::Equals(check, factory->boolean_string())) {
4997 __ CompareRoot(r3, Heap::kTrueValueRootIndex);
4999 __ CompareRoot(r3, Heap::kFalseValueRootIndex);
5000 Split(eq, if_true, if_false, fall_through);
5001 } else if (String::Equals(check, factory->undefined_string())) {
5002 __ CompareRoot(r3, Heap::kUndefinedValueRootIndex);
5004 __ JumpIfSmi(r3, if_false);
5005 // Check for undetectable objects => true.
5006 __ LoadP(r3, FieldMemOperand(r3, HeapObject::kMapOffset));
5007 __ lbz(r4, FieldMemOperand(r3, Map::kBitFieldOffset));
5008 __ andi(r0, r4, Operand(1 << Map::kIsUndetectable));
5009 Split(ne, if_true, if_false, fall_through, cr0);
5011 } else if (String::Equals(check, factory->function_string())) {
5012 __ JumpIfSmi(r3, if_false);
5013 STATIC_ASSERT(NUM_OF_CALLABLE_SPEC_OBJECT_TYPES == 2);
5014 __ CompareObjectType(r3, r3, r4, JS_FUNCTION_TYPE);
5016 __ cmpi(r4, Operand(JS_FUNCTION_PROXY_TYPE));
5017 Split(eq, if_true, if_false, fall_through);
5018 } else if (String::Equals(check, factory->object_string())) {
5019 __ JumpIfSmi(r3, if_false);
5020 __ CompareRoot(r3, Heap::kNullValueRootIndex);
5022 // Check for JS objects => true.
5023 __ CompareObjectType(r3, r3, r4, FIRST_NONCALLABLE_SPEC_OBJECT_TYPE);
5025 __ CompareInstanceType(r3, r4, LAST_NONCALLABLE_SPEC_OBJECT_TYPE);
5027 // Check for undetectable objects => false.
5028 __ lbz(r4, FieldMemOperand(r3, Map::kBitFieldOffset));
5029 __ andi(r0, r4, Operand(1 << Map::kIsUndetectable));
5030 Split(eq, if_true, if_false, fall_through, cr0);
5032 #define SIMD128_TYPE(TYPE, Type, type, lane_count, lane_type) \
5033 } else if (String::Equals(check, factory->type##_string())) { \
5034 __ JumpIfSmi(r3, if_false); \
5035 __ LoadP(r3, FieldMemOperand(r3, HeapObject::kMapOffset)); \
5036 __ CompareRoot(r3, Heap::k##Type##MapRootIndex); \
5037 Split(eq, if_true, if_false, fall_through);
5038 SIMD128_TYPES(SIMD128_TYPE)
5042 if (if_false != fall_through) __ b(if_false);
5044 context()->Plug(if_true, if_false);
5048 void FullCodeGenerator::VisitCompareOperation(CompareOperation* expr) {
5049 Comment cmnt(masm_, "[ CompareOperation");
5050 SetExpressionPosition(expr);
5052 // First we try a fast inlined version of the compare when one of
5053 // the operands is a literal.
5054 if (TryLiteralCompare(expr)) return;
5056 // Always perform the comparison for its control flow. Pack the result
5057 // into the expression's context after the comparison is performed.
5058 Label materialize_true, materialize_false;
5059 Label* if_true = NULL;
5060 Label* if_false = NULL;
5061 Label* fall_through = NULL;
5062 context()->PrepareTest(&materialize_true, &materialize_false, &if_true,
5063 &if_false, &fall_through);
5065 Token::Value op = expr->op();
5066 VisitForStackValue(expr->left());
5069 VisitForStackValue(expr->right());
5070 __ InvokeBuiltin(Context::IN_BUILTIN_INDEX, CALL_FUNCTION);
5071 PrepareForBailoutBeforeSplit(expr, false, NULL, NULL);
5072 __ CompareRoot(r3, Heap::kTrueValueRootIndex);
5073 Split(eq, if_true, if_false, fall_through);
5076 case Token::INSTANCEOF: {
5077 VisitForAccumulatorValue(expr->right());
5079 InstanceOfStub stub(isolate());
5081 PrepareForBailoutBeforeSplit(expr, false, NULL, NULL);
5082 __ CompareRoot(r3, Heap::kTrueValueRootIndex);
5083 Split(eq, if_true, if_false, fall_through);
5088 VisitForAccumulatorValue(expr->right());
5089 Condition cond = CompareIC::ComputeCondition(op);
5092 bool inline_smi_code = ShouldInlineSmiCase(op);
5093 JumpPatchSite patch_site(masm_);
5094 if (inline_smi_code) {
5097 patch_site.EmitJumpIfNotSmi(r5, &slow_case);
5099 Split(cond, if_true, if_false, NULL);
5100 __ bind(&slow_case);
5103 Handle<Code> ic = CodeFactory::CompareIC(
5104 isolate(), op, strength(language_mode())).code();
5105 CallIC(ic, expr->CompareOperationFeedbackId());
5106 patch_site.EmitPatchInfo();
5107 PrepareForBailoutBeforeSplit(expr, true, if_true, if_false);
5108 __ cmpi(r3, Operand::Zero());
5109 Split(cond, if_true, if_false, fall_through);
5113 // Convert the result of the comparison into one expected for this
5114 // expression's context.
5115 context()->Plug(if_true, if_false);
5119 void FullCodeGenerator::EmitLiteralCompareNil(CompareOperation* expr,
5120 Expression* sub_expr,
5122 Label materialize_true, materialize_false;
5123 Label* if_true = NULL;
5124 Label* if_false = NULL;
5125 Label* fall_through = NULL;
5126 context()->PrepareTest(&materialize_true, &materialize_false, &if_true,
5127 &if_false, &fall_through);
5129 VisitForAccumulatorValue(sub_expr);
5130 PrepareForBailoutBeforeSplit(expr, true, if_true, if_false);
5131 if (expr->op() == Token::EQ_STRICT) {
5132 Heap::RootListIndex nil_value = nil == kNullValue
5133 ? Heap::kNullValueRootIndex
5134 : Heap::kUndefinedValueRootIndex;
5135 __ LoadRoot(r4, nil_value);
5137 Split(eq, if_true, if_false, fall_through);
5139 Handle<Code> ic = CompareNilICStub::GetUninitialized(isolate(), nil);
5140 CallIC(ic, expr->CompareOperationFeedbackId());
5141 __ cmpi(r3, Operand::Zero());
5142 Split(ne, if_true, if_false, fall_through);
5144 context()->Plug(if_true, if_false);
5148 void FullCodeGenerator::VisitThisFunction(ThisFunction* expr) {
5149 __ LoadP(r3, MemOperand(fp, JavaScriptFrameConstants::kFunctionOffset));
5150 context()->Plug(r3);
5154 Register FullCodeGenerator::result_register() { return r3; }
5157 Register FullCodeGenerator::context_register() { return cp; }
5160 void FullCodeGenerator::StoreToFrameField(int frame_offset, Register value) {
5161 DCHECK_EQ(static_cast<int>(POINTER_SIZE_ALIGN(frame_offset)), frame_offset);
5162 __ StoreP(value, MemOperand(fp, frame_offset), r0);
5166 void FullCodeGenerator::LoadContextField(Register dst, int context_index) {
5167 __ LoadP(dst, ContextOperand(cp, context_index), r0);
5171 void FullCodeGenerator::PushFunctionArgumentForContextAllocation() {
5172 Scope* closure_scope = scope()->ClosureScope();
5173 if (closure_scope->is_script_scope() ||
5174 closure_scope->is_module_scope()) {
5175 // Contexts nested in the native context have a canonical empty function
5176 // as their closure, not the anonymous closure containing the global
5177 // code. Pass a smi sentinel and let the runtime look up the empty
5179 __ LoadSmiLiteral(ip, Smi::FromInt(0));
5180 } else if (closure_scope->is_eval_scope()) {
5181 // Contexts created by a call to eval have the same closure as the
5182 // context calling eval, not the anonymous closure containing the eval
5183 // code. Fetch it from the context.
5184 __ LoadP(ip, ContextOperand(cp, Context::CLOSURE_INDEX));
5186 DCHECK(closure_scope->is_function_scope());
5187 __ LoadP(ip, MemOperand(fp, JavaScriptFrameConstants::kFunctionOffset));
5193 // ----------------------------------------------------------------------------
5194 // Non-local control flow support.
5196 void FullCodeGenerator::EnterFinallyBlock() {
5197 DCHECK(!result_register().is(r4));
5198 // Store result register while executing finally block.
5199 __ push(result_register());
5200 // Cook return address in link register to stack (smi encoded Code* delta)
5202 __ mov(ip, Operand(masm_->CodeObject()));
5206 // Store result register while executing finally block.
5209 // Store pending message while executing finally block.
5210 ExternalReference pending_message_obj =
5211 ExternalReference::address_of_pending_message_obj(isolate());
5212 __ mov(ip, Operand(pending_message_obj));
5213 __ LoadP(r4, MemOperand(ip));
5216 ClearPendingMessage();
5220 void FullCodeGenerator::ExitFinallyBlock() {
5221 DCHECK(!result_register().is(r4));
5222 // Restore pending message from stack.
5224 ExternalReference pending_message_obj =
5225 ExternalReference::address_of_pending_message_obj(isolate());
5226 __ mov(ip, Operand(pending_message_obj));
5227 __ StoreP(r4, MemOperand(ip));
5229 // Restore result register from stack.
5232 // Uncook return address and return.
5233 __ pop(result_register());
5235 __ mov(ip, Operand(masm_->CodeObject()));
5242 void FullCodeGenerator::ClearPendingMessage() {
5243 DCHECK(!result_register().is(r4));
5244 ExternalReference pending_message_obj =
5245 ExternalReference::address_of_pending_message_obj(isolate());
5246 __ LoadRoot(r4, Heap::kTheHoleValueRootIndex);
5247 __ mov(ip, Operand(pending_message_obj));
5248 __ StoreP(r4, MemOperand(ip));
5252 void FullCodeGenerator::EmitLoadStoreICSlot(FeedbackVectorICSlot slot) {
5253 DCHECK(FLAG_vector_stores && !slot.IsInvalid());
5254 __ mov(VectorStoreICTrampolineDescriptor::SlotRegister(),
5255 Operand(SmiFromSlot(slot)));
5262 void BackEdgeTable::PatchAt(Code* unoptimized_code, Address pc,
5263 BackEdgeState target_state,
5264 Code* replacement_code) {
5265 Address mov_address = Assembler::target_address_from_return_address(pc);
5266 Address cmp_address = mov_address - 2 * Assembler::kInstrSize;
5267 CodePatcher patcher(cmp_address, 1);
5269 switch (target_state) {
5271 // <decrement profiling counter>
5273 // bge <ok> ;; not changed
5274 // mov r12, <interrupt stub address>
5277 // <reset profiling counter>
5279 patcher.masm()->cmpi(r6, Operand::Zero());
5282 case ON_STACK_REPLACEMENT:
5283 case OSR_AFTER_STACK_CHECK:
5284 // <decrement profiling counter>
5286 // bge <ok> ;; not changed
5287 // mov r12, <on-stack replacement address>
5290 // <reset profiling counter>
5291 // ok-label ----- pc_after points here
5293 // Set the LT bit such that bge is a NOP
5294 patcher.masm()->crset(Assembler::encode_crbit(cr7, CR_LT));
5298 // Replace the stack check address in the mov sequence with the
5299 // entry address of the replacement code.
5300 Assembler::set_target_address_at(mov_address, unoptimized_code,
5301 replacement_code->entry());
5303 unoptimized_code->GetHeap()->incremental_marking()->RecordCodeTargetPatch(
5304 unoptimized_code, mov_address, replacement_code);
5308 BackEdgeTable::BackEdgeState BackEdgeTable::GetBackEdgeState(
5309 Isolate* isolate, Code* unoptimized_code, Address pc) {
5310 Address mov_address = Assembler::target_address_from_return_address(pc);
5311 Address cmp_address = mov_address - 2 * Assembler::kInstrSize;
5312 Address interrupt_address =
5313 Assembler::target_address_at(mov_address, unoptimized_code);
5315 if (Assembler::IsCmpImmediate(Assembler::instr_at(cmp_address))) {
5316 DCHECK(interrupt_address == isolate->builtins()->InterruptCheck()->entry());
5320 DCHECK(Assembler::IsCrSet(Assembler::instr_at(cmp_address)));
5322 if (interrupt_address == isolate->builtins()->OnStackReplacement()->entry()) {
5323 return ON_STACK_REPLACEMENT;
5326 DCHECK(interrupt_address ==
5327 isolate->builtins()->OsrAfterStackCheck()->entry());
5328 return OSR_AFTER_STACK_CHECK;
5330 } // namespace internal
5332 #endif // V8_TARGET_ARCH_PPC