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(function());
106 Comment cmnt(masm_, "[ function compiled by full code generator");
108 ProfileEntryHookStub::MaybeCallEntryHook(masm_);
111 if (strlen(FLAG_stop_at) > 0 &&
112 info->function()->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 (is_sloppy(info->language_mode()) && !info->is_native() &&
121 info->MayUseThis() && info->scope()->has_this_declaration()) {
123 int receiver_offset = info->scope()->num_parameters() * kPointerSize;
124 __ LoadP(r5, MemOperand(sp, receiver_offset), r0);
125 __ CompareRoot(r5, Heap::kUndefinedValueRootIndex);
128 __ LoadP(r5, GlobalObjectOperand());
129 __ LoadP(r5, FieldMemOperand(r5, GlobalObject::kGlobalProxyOffset));
131 __ StoreP(r5, MemOperand(sp, receiver_offset), r0);
136 // Open a frame scope to indicate that there is a frame on the stack. The
137 // MANUAL indicates that the scope shouldn't actually generate code to set up
138 // the frame (that is done below).
139 FrameScope frame_scope(masm_, StackFrame::MANUAL);
140 int prologue_offset = masm_->pc_offset();
142 if (prologue_offset) {
143 // Prologue logic requires it's starting address in ip and the
144 // corresponding offset from the function entry.
145 prologue_offset += Instruction::kInstrSize;
146 __ addi(ip, ip, Operand(prologue_offset));
148 info->set_prologue_offset(prologue_offset);
149 __ Prologue(info->IsCodePreAgingActive(), prologue_offset);
150 info->AddNoFrameRange(0, masm_->pc_offset());
153 Comment cmnt(masm_, "[ Allocate locals");
154 int locals_count = info->scope()->num_stack_slots();
155 // Generators allocate locals, if any, in context slots.
156 DCHECK(!IsGeneratorFunction(info->function()->kind()) || locals_count == 0);
157 if (locals_count > 0) {
158 if (locals_count >= 128) {
160 __ Add(ip, sp, -(locals_count * kPointerSize), r0);
161 __ LoadRoot(r5, Heap::kRealStackLimitRootIndex);
163 __ bc_short(ge, &ok);
164 __ InvokeBuiltin(Builtins::STACK_OVERFLOW, CALL_FUNCTION);
167 __ LoadRoot(ip, Heap::kUndefinedValueRootIndex);
168 int kMaxPushes = FLAG_optimize_for_size ? 4 : 32;
169 if (locals_count >= kMaxPushes) {
170 int loop_iterations = locals_count / kMaxPushes;
171 __ mov(r5, Operand(loop_iterations));
174 __ bind(&loop_header);
176 for (int i = 0; i < kMaxPushes; i++) {
179 // Continue loop if not done.
180 __ bdnz(&loop_header);
182 int remaining = locals_count % kMaxPushes;
183 // Emit the remaining pushes.
184 for (int i = 0; i < remaining; i++) {
190 bool function_in_register = true;
192 // Possibly allocate a local context.
193 if (info->scope()->num_heap_slots() > 0) {
194 // Argument to NewContext is the function, which is still in r4.
195 Comment cmnt(masm_, "[ Allocate context");
196 bool need_write_barrier = true;
197 int slots = info->scope()->num_heap_slots() - Context::MIN_CONTEXT_SLOTS;
198 if (info->scope()->is_script_scope()) {
200 __ Push(info->scope()->GetScopeInfo(info->isolate()));
201 __ CallRuntime(Runtime::kNewScriptContext, 2);
202 } else if (slots <= FastNewContextStub::kMaximumSlots) {
203 FastNewContextStub stub(isolate(), slots);
205 // Result of FastNewContextStub is always in new space.
206 need_write_barrier = false;
209 __ CallRuntime(Runtime::kNewFunctionContext, 1);
211 function_in_register = false;
212 // Context is returned in r3. It replaces the context passed to us.
213 // It's saved in the stack and kept live in cp.
215 __ StoreP(r3, MemOperand(fp, StandardFrameConstants::kContextOffset));
216 // Copy any necessary parameters into the context.
217 int num_parameters = info->scope()->num_parameters();
218 int first_parameter = info->scope()->has_this_declaration() ? -1 : 0;
219 for (int i = first_parameter; i < num_parameters; i++) {
220 Variable* var = (i == -1) ? scope()->receiver() : scope()->parameter(i);
221 if (var->IsContextSlot()) {
222 int parameter_offset = StandardFrameConstants::kCallerSPOffset +
223 (num_parameters - 1 - i) * kPointerSize;
224 // Load parameter from stack.
225 __ LoadP(r3, MemOperand(fp, parameter_offset), r0);
226 // Store it in the context.
227 MemOperand target = ContextOperand(cp, var->index());
228 __ StoreP(r3, target, r0);
230 // Update the write barrier.
231 if (need_write_barrier) {
232 __ RecordWriteContextSlot(cp, target.offset(), r3, r6,
233 kLRHasBeenSaved, kDontSaveFPRegs);
234 } else if (FLAG_debug_code) {
236 __ JumpIfInNewSpace(cp, r3, &done);
237 __ Abort(kExpectedNewSpaceObject);
244 // Possibly set up a local binding to the this function which is used in
245 // derived constructors with super calls.
246 Variable* this_function_var = scope()->this_function_var();
247 if (this_function_var != nullptr) {
248 Comment cmnt(masm_, "[ This function");
249 if (!function_in_register) {
250 __ LoadP(r4, MemOperand(fp, JavaScriptFrameConstants::kFunctionOffset));
251 // The write barrier clobbers register again, keep is marked as such.
253 SetVar(this_function_var, r4, r3, r5);
256 Variable* new_target_var = scope()->new_target_var();
257 if (new_target_var != nullptr) {
258 Comment cmnt(masm_, "[ new.target");
260 // Get the frame pointer for the calling frame.
261 __ LoadP(r5, MemOperand(fp, StandardFrameConstants::kCallerFPOffset));
263 // Skip the arguments adaptor frame if it exists.
264 __ LoadP(r4, MemOperand(r5, StandardFrameConstants::kContextOffset));
265 __ CmpSmiLiteral(r4, Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR), r0);
268 __ LoadP(r5, MemOperand(r5, StandardFrameConstants::kCallerFPOffset));
271 // Check the marker in the calling frame.
272 __ LoadP(r4, MemOperand(r5, StandardFrameConstants::kMarkerOffset));
273 __ CmpSmiLiteral(r4, Smi::FromInt(StackFrame::CONSTRUCT), r0);
274 Label non_construct_frame, done;
276 __ bne(&non_construct_frame);
277 __ LoadP(r3, MemOperand(
278 r5, ConstructFrameConstants::kOriginalConstructorOffset));
281 __ bind(&non_construct_frame);
282 __ LoadRoot(r3, Heap::kUndefinedValueRootIndex);
285 SetVar(new_target_var, r3, r5, r6);
288 // Possibly allocate RestParameters
290 Variable* rest_param = scope()->rest_parameter(&rest_index);
292 Comment cmnt(masm_, "[ Allocate rest parameter array");
294 int num_parameters = info->scope()->num_parameters();
295 int offset = num_parameters * kPointerSize;
297 __ addi(r6, fp, Operand(StandardFrameConstants::kCallerSPOffset + offset));
298 __ LoadSmiLiteral(r5, Smi::FromInt(num_parameters));
299 __ LoadSmiLiteral(r4, Smi::FromInt(rest_index));
300 __ LoadSmiLiteral(r3, Smi::FromInt(language_mode()));
301 __ Push(r6, r5, r4, r3);
303 RestParamAccessStub stub(isolate());
306 SetVar(rest_param, r3, r4, r5);
309 Variable* arguments = scope()->arguments();
310 if (arguments != NULL) {
311 // Function uses arguments object.
312 Comment cmnt(masm_, "[ Allocate arguments object");
313 if (!function_in_register) {
314 // Load this again, if it's used by the local context below.
315 __ LoadP(r6, MemOperand(fp, JavaScriptFrameConstants::kFunctionOffset));
319 // Receiver is just before the parameters on the caller's stack.
320 int num_parameters = info->scope()->num_parameters();
321 int offset = num_parameters * kPointerSize;
322 __ addi(r5, fp, Operand(StandardFrameConstants::kCallerSPOffset + offset));
323 __ LoadSmiLiteral(r4, Smi::FromInt(num_parameters));
326 // Arguments to ArgumentsAccessStub:
327 // function, receiver address, parameter count.
328 // The stub will rewrite receiver and parameter count if the previous
329 // stack frame was an arguments adapter frame.
330 ArgumentsAccessStub::Type type;
331 if (is_strict(language_mode()) || !has_simple_parameters()) {
332 type = ArgumentsAccessStub::NEW_STRICT;
333 } else if (function()->has_duplicate_parameters()) {
334 type = ArgumentsAccessStub::NEW_SLOPPY_SLOW;
336 type = ArgumentsAccessStub::NEW_SLOPPY_FAST;
338 ArgumentsAccessStub stub(isolate(), type);
341 SetVar(arguments, r3, r4, r5);
345 __ CallRuntime(Runtime::kTraceEnter, 0);
348 // Visit the declarations and body unless there is an illegal
350 if (scope()->HasIllegalRedeclaration()) {
351 Comment cmnt(masm_, "[ Declarations");
352 scope()->VisitIllegalRedeclaration(this);
355 PrepareForBailoutForId(BailoutId::FunctionEntry(), NO_REGISTERS);
357 Comment cmnt(masm_, "[ Declarations");
358 VisitDeclarations(scope()->declarations());
361 // Assert that the declarations do not use ICs. Otherwise the debugger
362 // won't be able to redirect a PC at an IC to the correct IC in newly
364 DCHECK_EQ(0, ic_total_count_);
367 Comment cmnt(masm_, "[ Stack check");
368 PrepareForBailoutForId(BailoutId::Declarations(), NO_REGISTERS);
370 __ LoadRoot(ip, Heap::kStackLimitRootIndex);
372 __ bc_short(ge, &ok);
373 __ Call(isolate()->builtins()->StackCheck(), RelocInfo::CODE_TARGET);
378 Comment cmnt(masm_, "[ Body");
379 DCHECK(loop_depth() == 0);
380 VisitStatements(function()->body());
381 DCHECK(loop_depth() == 0);
385 // Always emit a 'return undefined' in case control fell off the end of
388 Comment cmnt(masm_, "[ return <undefined>;");
389 __ LoadRoot(r3, Heap::kUndefinedValueRootIndex);
391 EmitReturnSequence();
393 if (HasStackOverflow()) {
394 masm_->AbortConstantPoolBuilding();
399 void FullCodeGenerator::ClearAccumulator() {
400 __ LoadSmiLiteral(r3, Smi::FromInt(0));
404 void FullCodeGenerator::EmitProfilingCounterDecrement(int delta) {
405 __ mov(r5, Operand(profiling_counter_));
406 __ LoadP(r6, FieldMemOperand(r5, Cell::kValueOffset));
407 __ SubSmiLiteral(r6, r6, Smi::FromInt(delta), r0);
408 __ StoreP(r6, FieldMemOperand(r5, Cell::kValueOffset), r0);
412 void FullCodeGenerator::EmitProfilingCounterReset() {
413 int reset_value = FLAG_interrupt_budget;
414 __ mov(r5, Operand(profiling_counter_));
415 __ LoadSmiLiteral(r6, Smi::FromInt(reset_value));
416 __ StoreP(r6, FieldMemOperand(r5, Cell::kValueOffset), r0);
420 void FullCodeGenerator::EmitBackEdgeBookkeeping(IterationStatement* stmt,
421 Label* back_edge_target) {
422 Comment cmnt(masm_, "[ Back edge bookkeeping");
425 DCHECK(back_edge_target->is_bound());
426 int distance = masm_->SizeOfCodeGeneratedSince(back_edge_target) +
427 kCodeSizeMultiplier / 2;
428 int weight = Min(kMaxBackEdgeWeight, Max(1, distance / kCodeSizeMultiplier));
429 EmitProfilingCounterDecrement(weight);
431 Assembler::BlockTrampolinePoolScope block_trampoline_pool(masm_);
432 Assembler::BlockConstantPoolEntrySharingScope prevent_entry_sharing(masm_);
433 // BackEdgeTable::PatchAt manipulates this sequence.
434 __ cmpi(r6, Operand::Zero());
435 __ bc_short(ge, &ok);
436 __ Call(isolate()->builtins()->InterruptCheck(), RelocInfo::CODE_TARGET);
438 // Record a mapping of this PC offset to the OSR id. This is used to find
439 // the AST id from the unoptimized code in order to use it as a key into
440 // the deoptimization input data found in the optimized code.
441 RecordBackEdge(stmt->OsrEntryId());
443 EmitProfilingCounterReset();
446 PrepareForBailoutForId(stmt->EntryId(), NO_REGISTERS);
447 // Record a mapping of the OSR id to this PC. This is used if the OSR
448 // entry becomes the target of a bailout. We don't expect it to be, but
449 // we want it to work if it is.
450 PrepareForBailoutForId(stmt->OsrEntryId(), NO_REGISTERS);
454 void FullCodeGenerator::EmitReturnSequence() {
455 Comment cmnt(masm_, "[ Return sequence");
456 if (return_label_.is_bound()) {
457 __ b(&return_label_);
459 __ bind(&return_label_);
461 // Push the return value on the stack as the parameter.
462 // Runtime::TraceExit returns its parameter in r3
464 __ CallRuntime(Runtime::kTraceExit, 1);
466 // Pretend that the exit is a backwards jump to the entry.
468 if (info_->ShouldSelfOptimize()) {
469 weight = FLAG_interrupt_budget / FLAG_self_opt_count;
471 int distance = masm_->pc_offset() + kCodeSizeMultiplier / 2;
472 weight = Min(kMaxBackEdgeWeight, Max(1, distance / kCodeSizeMultiplier));
474 EmitProfilingCounterDecrement(weight);
476 __ cmpi(r6, Operand::Zero());
479 __ Call(isolate()->builtins()->InterruptCheck(), RelocInfo::CODE_TARGET);
481 EmitProfilingCounterReset();
484 // Make sure that the constant pool is not emitted inside of the return
487 Assembler::BlockTrampolinePoolScope block_trampoline_pool(masm_);
488 int32_t arg_count = info_->scope()->num_parameters() + 1;
489 int32_t sp_delta = arg_count * kPointerSize;
490 SetReturnPosition(function());
491 int no_frame_start = __ LeaveFrame(StackFrame::JAVA_SCRIPT, sp_delta);
493 info_->AddNoFrameRange(no_frame_start, masm_->pc_offset());
499 void FullCodeGenerator::StackValueContext::Plug(Variable* var) const {
500 DCHECK(var->IsStackAllocated() || var->IsContextSlot());
501 codegen()->GetVar(result_register(), var);
502 __ push(result_register());
506 void FullCodeGenerator::EffectContext::Plug(Heap::RootListIndex index) const {}
509 void FullCodeGenerator::AccumulatorValueContext::Plug(
510 Heap::RootListIndex index) const {
511 __ LoadRoot(result_register(), index);
515 void FullCodeGenerator::StackValueContext::Plug(
516 Heap::RootListIndex index) const {
517 __ LoadRoot(result_register(), index);
518 __ push(result_register());
522 void FullCodeGenerator::TestContext::Plug(Heap::RootListIndex index) const {
523 codegen()->PrepareForBailoutBeforeSplit(condition(), true, true_label_,
525 if (index == Heap::kUndefinedValueRootIndex ||
526 index == Heap::kNullValueRootIndex ||
527 index == Heap::kFalseValueRootIndex) {
528 if (false_label_ != fall_through_) __ b(false_label_);
529 } else if (index == Heap::kTrueValueRootIndex) {
530 if (true_label_ != fall_through_) __ b(true_label_);
532 __ LoadRoot(result_register(), index);
533 codegen()->DoTest(this);
538 void FullCodeGenerator::EffectContext::Plug(Handle<Object> lit) const {}
541 void FullCodeGenerator::AccumulatorValueContext::Plug(
542 Handle<Object> lit) const {
543 __ mov(result_register(), Operand(lit));
547 void FullCodeGenerator::StackValueContext::Plug(Handle<Object> lit) const {
548 // Immediates cannot be pushed directly.
549 __ mov(result_register(), Operand(lit));
550 __ push(result_register());
554 void FullCodeGenerator::TestContext::Plug(Handle<Object> lit) const {
555 codegen()->PrepareForBailoutBeforeSplit(condition(), true, true_label_,
557 DCHECK(!lit->IsUndetectableObject()); // There are no undetectable literals.
558 if (lit->IsUndefined() || lit->IsNull() || lit->IsFalse()) {
559 if (false_label_ != fall_through_) __ b(false_label_);
560 } else if (lit->IsTrue() || lit->IsJSObject()) {
561 if (true_label_ != fall_through_) __ b(true_label_);
562 } else if (lit->IsString()) {
563 if (String::cast(*lit)->length() == 0) {
564 if (false_label_ != fall_through_) __ b(false_label_);
566 if (true_label_ != fall_through_) __ b(true_label_);
568 } else if (lit->IsSmi()) {
569 if (Smi::cast(*lit)->value() == 0) {
570 if (false_label_ != fall_through_) __ b(false_label_);
572 if (true_label_ != fall_through_) __ b(true_label_);
575 // For simplicity we always test the accumulator register.
576 __ mov(result_register(), Operand(lit));
577 codegen()->DoTest(this);
582 void FullCodeGenerator::EffectContext::DropAndPlug(int count,
583 Register reg) const {
589 void FullCodeGenerator::AccumulatorValueContext::DropAndPlug(
590 int count, Register reg) const {
593 __ Move(result_register(), reg);
597 void FullCodeGenerator::StackValueContext::DropAndPlug(int count,
598 Register reg) const {
600 if (count > 1) __ Drop(count - 1);
601 __ StoreP(reg, MemOperand(sp, 0));
605 void FullCodeGenerator::TestContext::DropAndPlug(int count,
606 Register reg) const {
608 // For simplicity we always test the accumulator register.
610 __ Move(result_register(), reg);
611 codegen()->PrepareForBailoutBeforeSplit(condition(), false, NULL, NULL);
612 codegen()->DoTest(this);
616 void FullCodeGenerator::EffectContext::Plug(Label* materialize_true,
617 Label* materialize_false) const {
618 DCHECK(materialize_true == materialize_false);
619 __ bind(materialize_true);
623 void FullCodeGenerator::AccumulatorValueContext::Plug(
624 Label* materialize_true, Label* materialize_false) const {
626 __ bind(materialize_true);
627 __ LoadRoot(result_register(), Heap::kTrueValueRootIndex);
629 __ bind(materialize_false);
630 __ LoadRoot(result_register(), Heap::kFalseValueRootIndex);
635 void FullCodeGenerator::StackValueContext::Plug(
636 Label* materialize_true, Label* materialize_false) const {
638 __ bind(materialize_true);
639 __ LoadRoot(ip, Heap::kTrueValueRootIndex);
641 __ bind(materialize_false);
642 __ LoadRoot(ip, Heap::kFalseValueRootIndex);
648 void FullCodeGenerator::TestContext::Plug(Label* materialize_true,
649 Label* materialize_false) const {
650 DCHECK(materialize_true == true_label_);
651 DCHECK(materialize_false == false_label_);
655 void FullCodeGenerator::AccumulatorValueContext::Plug(bool flag) const {
656 Heap::RootListIndex value_root_index =
657 flag ? Heap::kTrueValueRootIndex : Heap::kFalseValueRootIndex;
658 __ LoadRoot(result_register(), value_root_index);
662 void FullCodeGenerator::StackValueContext::Plug(bool flag) const {
663 Heap::RootListIndex value_root_index =
664 flag ? Heap::kTrueValueRootIndex : Heap::kFalseValueRootIndex;
665 __ LoadRoot(ip, value_root_index);
670 void FullCodeGenerator::TestContext::Plug(bool flag) const {
671 codegen()->PrepareForBailoutBeforeSplit(condition(), true, true_label_,
674 if (true_label_ != fall_through_) __ b(true_label_);
676 if (false_label_ != fall_through_) __ b(false_label_);
681 void FullCodeGenerator::DoTest(Expression* condition, Label* if_true,
682 Label* if_false, Label* fall_through) {
683 Handle<Code> ic = ToBooleanStub::GetUninitialized(isolate());
684 CallIC(ic, condition->test_id());
685 __ cmpi(result_register(), Operand::Zero());
686 Split(ne, if_true, if_false, fall_through);
690 void FullCodeGenerator::Split(Condition cond, Label* if_true, Label* if_false,
691 Label* fall_through, CRegister cr) {
692 if (if_false == fall_through) {
693 __ b(cond, if_true, cr);
694 } else if (if_true == fall_through) {
695 __ b(NegateCondition(cond), if_false, cr);
697 __ b(cond, if_true, cr);
703 MemOperand FullCodeGenerator::StackOperand(Variable* var) {
704 DCHECK(var->IsStackAllocated());
705 // Offset is negative because higher indexes are at lower addresses.
706 int offset = -var->index() * kPointerSize;
707 // Adjust by a (parameter or local) base offset.
708 if (var->IsParameter()) {
709 offset += (info_->scope()->num_parameters() + 1) * kPointerSize;
711 offset += JavaScriptFrameConstants::kLocal0Offset;
713 return MemOperand(fp, offset);
717 MemOperand FullCodeGenerator::VarOperand(Variable* var, Register scratch) {
718 DCHECK(var->IsContextSlot() || var->IsStackAllocated());
719 if (var->IsContextSlot()) {
720 int context_chain_length = scope()->ContextChainLength(var->scope());
721 __ LoadContext(scratch, context_chain_length);
722 return ContextOperand(scratch, var->index());
724 return StackOperand(var);
729 void FullCodeGenerator::GetVar(Register dest, Variable* var) {
730 // Use destination as scratch.
731 MemOperand location = VarOperand(var, dest);
732 __ LoadP(dest, location, r0);
736 void FullCodeGenerator::SetVar(Variable* var, Register src, Register scratch0,
738 DCHECK(var->IsContextSlot() || var->IsStackAllocated());
739 DCHECK(!scratch0.is(src));
740 DCHECK(!scratch0.is(scratch1));
741 DCHECK(!scratch1.is(src));
742 MemOperand location = VarOperand(var, scratch0);
743 __ StoreP(src, location, r0);
745 // Emit the write barrier code if the location is in the heap.
746 if (var->IsContextSlot()) {
747 __ RecordWriteContextSlot(scratch0, location.offset(), src, scratch1,
748 kLRHasBeenSaved, kDontSaveFPRegs);
753 void FullCodeGenerator::PrepareForBailoutBeforeSplit(Expression* expr,
754 bool should_normalize,
757 // Only prepare for bailouts before splits if we're in a test
758 // context. Otherwise, we let the Visit function deal with the
759 // preparation to avoid preparing with the same AST id twice.
760 if (!context()->IsTest() || !info_->IsOptimizable()) return;
763 if (should_normalize) __ b(&skip);
764 PrepareForBailout(expr, TOS_REG);
765 if (should_normalize) {
766 __ LoadRoot(ip, Heap::kTrueValueRootIndex);
768 Split(eq, if_true, if_false, NULL);
774 void FullCodeGenerator::EmitDebugCheckDeclarationContext(Variable* variable) {
775 // The variable in the declaration always resides in the current function
777 DCHECK_EQ(0, scope()->ContextChainLength(variable->scope()));
778 if (generate_debug_code_) {
779 // Check that we're not inside a with or catch context.
780 __ LoadP(r4, FieldMemOperand(cp, HeapObject::kMapOffset));
781 __ CompareRoot(r4, Heap::kWithContextMapRootIndex);
782 __ Check(ne, kDeclarationInWithContext);
783 __ CompareRoot(r4, Heap::kCatchContextMapRootIndex);
784 __ Check(ne, kDeclarationInCatchContext);
789 void FullCodeGenerator::VisitVariableDeclaration(
790 VariableDeclaration* declaration) {
791 // If it was not possible to allocate the variable at compile time, we
792 // need to "declare" it at runtime to make sure it actually exists in the
794 VariableProxy* proxy = declaration->proxy();
795 VariableMode mode = declaration->mode();
796 Variable* variable = proxy->var();
797 bool hole_init = mode == LET || mode == CONST || mode == CONST_LEGACY;
798 switch (variable->location()) {
799 case VariableLocation::GLOBAL:
800 case VariableLocation::UNALLOCATED:
801 globals_->Add(variable->name(), zone());
802 globals_->Add(variable->binding_needs_init()
803 ? isolate()->factory()->the_hole_value()
804 : isolate()->factory()->undefined_value(),
808 case VariableLocation::PARAMETER:
809 case VariableLocation::LOCAL:
811 Comment cmnt(masm_, "[ VariableDeclaration");
812 __ LoadRoot(ip, Heap::kTheHoleValueRootIndex);
813 __ StoreP(ip, StackOperand(variable));
817 case VariableLocation::CONTEXT:
819 Comment cmnt(masm_, "[ VariableDeclaration");
820 EmitDebugCheckDeclarationContext(variable);
821 __ LoadRoot(ip, Heap::kTheHoleValueRootIndex);
822 __ StoreP(ip, ContextOperand(cp, variable->index()), r0);
823 // No write barrier since the_hole_value is in old space.
824 PrepareForBailoutForId(proxy->id(), NO_REGISTERS);
828 case VariableLocation::LOOKUP: {
829 Comment cmnt(masm_, "[ VariableDeclaration");
830 __ mov(r5, Operand(variable->name()));
831 // Declaration nodes are always introduced in one of four modes.
832 DCHECK(IsDeclaredVariableMode(mode));
833 // Push initial value, if any.
834 // Note: For variables we must not push an initial value (such as
835 // 'undefined') because we may have a (legal) redeclaration and we
836 // must not destroy the current value.
838 __ LoadRoot(r3, Heap::kTheHoleValueRootIndex);
841 __ LoadSmiLiteral(r3, Smi::FromInt(0)); // Indicates no initial value.
844 __ CallRuntime(IsImmutableVariableMode(mode)
845 ? Runtime::kDeclareReadOnlyLookupSlot
846 : Runtime::kDeclareLookupSlot,
854 void FullCodeGenerator::VisitFunctionDeclaration(
855 FunctionDeclaration* declaration) {
856 VariableProxy* proxy = declaration->proxy();
857 Variable* variable = proxy->var();
858 switch (variable->location()) {
859 case VariableLocation::GLOBAL:
860 case VariableLocation::UNALLOCATED: {
861 globals_->Add(variable->name(), zone());
862 Handle<SharedFunctionInfo> function =
863 Compiler::GetSharedFunctionInfo(declaration->fun(), script(), info_);
864 // Check for stack-overflow exception.
865 if (function.is_null()) return SetStackOverflow();
866 globals_->Add(function, zone());
870 case VariableLocation::PARAMETER:
871 case VariableLocation::LOCAL: {
872 Comment cmnt(masm_, "[ FunctionDeclaration");
873 VisitForAccumulatorValue(declaration->fun());
874 __ StoreP(result_register(), StackOperand(variable));
878 case VariableLocation::CONTEXT: {
879 Comment cmnt(masm_, "[ FunctionDeclaration");
880 EmitDebugCheckDeclarationContext(variable);
881 VisitForAccumulatorValue(declaration->fun());
882 __ StoreP(result_register(), ContextOperand(cp, variable->index()), r0);
883 int offset = Context::SlotOffset(variable->index());
884 // We know that we have written a function, which is not a smi.
885 __ RecordWriteContextSlot(cp, offset, result_register(), r5,
886 kLRHasBeenSaved, kDontSaveFPRegs,
887 EMIT_REMEMBERED_SET, OMIT_SMI_CHECK);
888 PrepareForBailoutForId(proxy->id(), NO_REGISTERS);
892 case VariableLocation::LOOKUP: {
893 Comment cmnt(masm_, "[ FunctionDeclaration");
894 __ mov(r5, Operand(variable->name()));
896 // Push initial value for function declaration.
897 VisitForStackValue(declaration->fun());
898 __ CallRuntime(Runtime::kDeclareLookupSlot, 2);
905 void FullCodeGenerator::DeclareGlobals(Handle<FixedArray> pairs) {
906 // Call the runtime to declare the globals.
907 __ mov(r4, Operand(pairs));
908 __ LoadSmiLiteral(r3, Smi::FromInt(DeclareGlobalsFlags()));
910 __ CallRuntime(Runtime::kDeclareGlobals, 2);
911 // Return value is ignored.
915 void FullCodeGenerator::DeclareModules(Handle<FixedArray> descriptions) {
916 // Call the runtime to declare the modules.
917 __ Push(descriptions);
918 __ CallRuntime(Runtime::kDeclareModules, 1);
919 // Return value is ignored.
923 void FullCodeGenerator::VisitSwitchStatement(SwitchStatement* stmt) {
924 Comment cmnt(masm_, "[ SwitchStatement");
925 Breakable nested_statement(this, stmt);
926 SetStatementPosition(stmt);
928 // Keep the switch value on the stack until a case matches.
929 VisitForStackValue(stmt->tag());
930 PrepareForBailoutForId(stmt->EntryId(), NO_REGISTERS);
932 ZoneList<CaseClause*>* clauses = stmt->cases();
933 CaseClause* default_clause = NULL; // Can occur anywhere in the list.
935 Label next_test; // Recycled for each test.
936 // Compile all the tests with branches to their bodies.
937 for (int i = 0; i < clauses->length(); i++) {
938 CaseClause* clause = clauses->at(i);
939 clause->body_target()->Unuse();
941 // The default is not a test, but remember it as final fall through.
942 if (clause->is_default()) {
943 default_clause = clause;
947 Comment cmnt(masm_, "[ Case comparison");
951 // Compile the label expression.
952 VisitForAccumulatorValue(clause->label());
954 // Perform the comparison as if via '==='.
955 __ LoadP(r4, MemOperand(sp, 0)); // Switch value.
956 bool inline_smi_code = ShouldInlineSmiCase(Token::EQ_STRICT);
957 JumpPatchSite patch_site(masm_);
958 if (inline_smi_code) {
961 patch_site.EmitJumpIfNotSmi(r5, &slow_case);
965 __ Drop(1); // Switch value is no longer needed.
966 __ b(clause->body_target());
970 // Record position before stub call for type feedback.
971 SetExpressionPosition(clause);
972 Handle<Code> ic = CodeFactory::CompareIC(isolate(), Token::EQ_STRICT,
973 strength(language_mode())).code();
974 CallIC(ic, clause->CompareId());
975 patch_site.EmitPatchInfo();
979 PrepareForBailout(clause, TOS_REG);
980 __ LoadRoot(ip, Heap::kTrueValueRootIndex);
984 __ b(clause->body_target());
987 __ cmpi(r3, Operand::Zero());
989 __ Drop(1); // Switch value is no longer needed.
990 __ b(clause->body_target());
993 // Discard the test value and jump to the default if present, otherwise to
994 // the end of the statement.
996 __ Drop(1); // Switch value is no longer needed.
997 if (default_clause == NULL) {
998 __ b(nested_statement.break_label());
1000 __ b(default_clause->body_target());
1003 // Compile all the case bodies.
1004 for (int i = 0; i < clauses->length(); i++) {
1005 Comment cmnt(masm_, "[ Case body");
1006 CaseClause* clause = clauses->at(i);
1007 __ bind(clause->body_target());
1008 PrepareForBailoutForId(clause->EntryId(), NO_REGISTERS);
1009 VisitStatements(clause->statements());
1012 __ bind(nested_statement.break_label());
1013 PrepareForBailoutForId(stmt->ExitId(), NO_REGISTERS);
1017 void FullCodeGenerator::VisitForInStatement(ForInStatement* stmt) {
1018 Comment cmnt(masm_, "[ ForInStatement");
1019 SetStatementPosition(stmt, SKIP_BREAK);
1021 FeedbackVectorSlot slot = stmt->ForInFeedbackSlot();
1024 ForIn loop_statement(this, stmt);
1025 increment_loop_depth();
1027 // Get the object to enumerate over. If the object is null or undefined, skip
1028 // over the loop. See ECMA-262 version 5, section 12.6.4.
1029 SetExpressionAsStatementPosition(stmt->enumerable());
1030 VisitForAccumulatorValue(stmt->enumerable());
1031 __ LoadRoot(ip, Heap::kUndefinedValueRootIndex);
1034 Register null_value = r7;
1035 __ LoadRoot(null_value, Heap::kNullValueRootIndex);
1036 __ cmp(r3, null_value);
1039 PrepareForBailoutForId(stmt->PrepareId(), TOS_REG);
1041 // Convert the object to a JS object.
1042 Label convert, done_convert;
1043 __ JumpIfSmi(r3, &convert);
1044 __ CompareObjectType(r3, r4, r4, FIRST_SPEC_OBJECT_TYPE);
1045 __ bge(&done_convert);
1047 ToObjectStub stub(isolate());
1049 __ bind(&done_convert);
1050 PrepareForBailoutForId(stmt->ToObjectId(), TOS_REG);
1053 // Check for proxies.
1055 STATIC_ASSERT(FIRST_JS_PROXY_TYPE == FIRST_SPEC_OBJECT_TYPE);
1056 __ CompareObjectType(r3, r4, r4, LAST_JS_PROXY_TYPE);
1057 __ ble(&call_runtime);
1059 // Check cache validity in generated code. This is a fast case for
1060 // the JSObject::IsSimpleEnum cache validity checks. If we cannot
1061 // guarantee cache validity, call the runtime system to check cache
1062 // validity or get the property names in a fixed array.
1063 __ CheckEnumCache(null_value, &call_runtime);
1065 // The enum cache is valid. Load the map of the object being
1066 // iterated over and use the cache for the iteration.
1068 __ LoadP(r3, FieldMemOperand(r3, HeapObject::kMapOffset));
1071 // Get the set of properties to enumerate.
1072 __ bind(&call_runtime);
1073 __ push(r3); // Duplicate the enumerable object on the stack.
1074 __ CallRuntime(Runtime::kGetPropertyNamesFast, 1);
1075 PrepareForBailoutForId(stmt->EnumId(), TOS_REG);
1077 // If we got a map from the runtime call, we can do a fast
1078 // modification check. Otherwise, we got a fixed array, and we have
1079 // to do a slow check.
1081 __ LoadP(r5, FieldMemOperand(r3, HeapObject::kMapOffset));
1082 __ LoadRoot(ip, Heap::kMetaMapRootIndex);
1084 __ bne(&fixed_array);
1086 // We got a map in register r3. Get the enumeration cache from it.
1087 Label no_descriptors;
1088 __ bind(&use_cache);
1090 __ EnumLength(r4, r3);
1091 __ CmpSmiLiteral(r4, Smi::FromInt(0), r0);
1092 __ beq(&no_descriptors);
1094 __ LoadInstanceDescriptors(r3, r5);
1095 __ LoadP(r5, FieldMemOperand(r5, DescriptorArray::kEnumCacheOffset));
1097 FieldMemOperand(r5, DescriptorArray::kEnumCacheBridgeCacheOffset));
1099 // Set up the four remaining stack slots.
1100 __ push(r3); // Map.
1101 __ LoadSmiLiteral(r3, Smi::FromInt(0));
1102 // Push enumeration cache, enumeration cache length (as smi) and zero.
1103 __ Push(r5, r4, r3);
1106 __ bind(&no_descriptors);
1110 // We got a fixed array in register r3. Iterate through that.
1112 __ bind(&fixed_array);
1114 __ Move(r4, FeedbackVector());
1115 __ mov(r5, Operand(TypeFeedbackVector::MegamorphicSentinel(isolate())));
1116 int vector_index = FeedbackVector()->GetIndex(slot);
1118 r5, FieldMemOperand(r4, FixedArray::OffsetOfElementAt(vector_index)), r0);
1120 __ LoadSmiLiteral(r4, Smi::FromInt(1)); // Smi indicates slow check
1121 __ LoadP(r5, MemOperand(sp, 0 * kPointerSize)); // Get enumerated object
1122 STATIC_ASSERT(FIRST_JS_PROXY_TYPE == FIRST_SPEC_OBJECT_TYPE);
1123 __ CompareObjectType(r5, r6, r6, LAST_JS_PROXY_TYPE);
1125 __ LoadSmiLiteral(r4, Smi::FromInt(0)); // Zero indicates proxy
1126 __ bind(&non_proxy);
1127 __ Push(r4, r3); // Smi and array
1128 __ LoadP(r4, FieldMemOperand(r3, FixedArray::kLengthOffset));
1129 __ LoadSmiLiteral(r3, Smi::FromInt(0));
1130 __ Push(r4, r3); // Fixed array length (as smi) and initial index.
1132 // Generate code for doing the condition check.
1133 PrepareForBailoutForId(stmt->BodyId(), NO_REGISTERS);
1135 SetExpressionAsStatementPosition(stmt->each());
1137 // Load the current count to r3, load the length to r4.
1138 __ LoadP(r3, MemOperand(sp, 0 * kPointerSize));
1139 __ LoadP(r4, MemOperand(sp, 1 * kPointerSize));
1140 __ cmpl(r3, r4); // Compare to the array length.
1141 __ bge(loop_statement.break_label());
1143 // Get the current entry of the array into register r6.
1144 __ LoadP(r5, MemOperand(sp, 2 * kPointerSize));
1145 __ addi(r5, r5, Operand(FixedArray::kHeaderSize - kHeapObjectTag));
1146 __ SmiToPtrArrayOffset(r6, r3);
1147 __ LoadPX(r6, MemOperand(r6, r5));
1149 // Get the expected map from the stack or a smi in the
1150 // permanent slow case into register r5.
1151 __ LoadP(r5, MemOperand(sp, 3 * kPointerSize));
1153 // Check if the expected map still matches that of the enumerable.
1154 // If not, we may have to filter the key.
1156 __ LoadP(r4, MemOperand(sp, 4 * kPointerSize));
1157 __ LoadP(r7, FieldMemOperand(r4, HeapObject::kMapOffset));
1159 __ beq(&update_each);
1161 // For proxies, no filtering is done.
1162 // TODO(rossberg): What if only a prototype is a proxy? Not specified yet.
1163 __ CmpSmiLiteral(r5, Smi::FromInt(0), r0);
1164 __ beq(&update_each);
1166 // Convert the entry to a string or (smi) 0 if it isn't a property
1167 // any more. If the property has been removed while iterating, we
1169 __ Push(r4, r6); // Enumerable and current entry.
1170 __ CallRuntime(Runtime::kForInFilter, 2);
1171 PrepareForBailoutForId(stmt->FilterId(), TOS_REG);
1173 __ LoadRoot(r0, Heap::kUndefinedValueRootIndex);
1175 __ beq(loop_statement.continue_label());
1177 // Update the 'each' property or variable from the possibly filtered
1178 // entry in register r6.
1179 __ bind(&update_each);
1180 __ mr(result_register(), r6);
1181 // Perform the assignment as if via '='.
1183 EffectContext context(this);
1184 EmitAssignment(stmt->each(), stmt->EachFeedbackSlot());
1185 PrepareForBailoutForId(stmt->AssignmentId(), NO_REGISTERS);
1188 // Generate code for the body of the loop.
1189 Visit(stmt->body());
1191 // Generate code for the going to the next element by incrementing
1192 // the index (smi) stored on top of the stack.
1193 __ bind(loop_statement.continue_label());
1195 __ AddSmiLiteral(r3, r3, Smi::FromInt(1), r0);
1198 EmitBackEdgeBookkeeping(stmt, &loop);
1201 // Remove the pointers stored on the stack.
1202 __ bind(loop_statement.break_label());
1205 // Exit and decrement the loop depth.
1206 PrepareForBailoutForId(stmt->ExitId(), NO_REGISTERS);
1208 decrement_loop_depth();
1212 void FullCodeGenerator::EmitNewClosure(Handle<SharedFunctionInfo> info,
1214 // Use the fast case closure allocation code that allocates in new
1215 // space for nested functions that don't need literals cloning. If
1216 // we're running with the --always-opt or the --prepare-always-opt
1217 // flag, we need to use the runtime function so that the new function
1218 // we are creating here gets a chance to have its code optimized and
1219 // doesn't just get a copy of the existing unoptimized code.
1220 if (!FLAG_always_opt && !FLAG_prepare_always_opt && !pretenure &&
1221 scope()->is_function_scope() && info->num_literals() == 0) {
1222 FastNewClosureStub stub(isolate(), info->language_mode(), info->kind());
1223 __ mov(r5, Operand(info));
1226 __ mov(r3, Operand(info));
1228 r4, pretenure ? Heap::kTrueValueRootIndex : Heap::kFalseValueRootIndex);
1229 __ Push(cp, r3, r4);
1230 __ CallRuntime(Runtime::kNewClosure, 3);
1232 context()->Plug(r3);
1236 void FullCodeGenerator::EmitSetHomeObjectIfNeeded(Expression* initializer,
1238 FeedbackVectorICSlot slot) {
1239 if (NeedsHomeObject(initializer)) {
1240 __ LoadP(StoreDescriptor::ReceiverRegister(), MemOperand(sp));
1241 __ mov(StoreDescriptor::NameRegister(),
1242 Operand(isolate()->factory()->home_object_symbol()));
1243 __ LoadP(StoreDescriptor::ValueRegister(),
1244 MemOperand(sp, offset * kPointerSize));
1245 if (FLAG_vector_stores) EmitLoadStoreICSlot(slot);
1251 void FullCodeGenerator::EmitLoadGlobalCheckExtensions(VariableProxy* proxy,
1252 TypeofMode typeof_mode,
1254 Register current = cp;
1260 if (s->num_heap_slots() > 0) {
1261 if (s->calls_sloppy_eval()) {
1262 // Check that extension is NULL.
1263 __ LoadP(temp, ContextOperand(current, Context::EXTENSION_INDEX));
1264 __ cmpi(temp, Operand::Zero());
1267 // Load next context in chain.
1268 __ LoadP(next, ContextOperand(current, Context::PREVIOUS_INDEX));
1269 // Walk the rest of the chain without clobbering cp.
1272 // If no outer scope calls eval, we do not need to check more
1273 // context extensions.
1274 if (!s->outer_scope_calls_sloppy_eval() || s->is_eval_scope()) break;
1275 s = s->outer_scope();
1278 if (s->is_eval_scope()) {
1280 if (!current.is(next)) {
1281 __ Move(next, current);
1284 // Terminate at native context.
1285 __ LoadP(temp, FieldMemOperand(next, HeapObject::kMapOffset));
1286 __ LoadRoot(ip, Heap::kNativeContextMapRootIndex);
1289 // Check that extension is NULL.
1290 __ LoadP(temp, ContextOperand(next, Context::EXTENSION_INDEX));
1291 __ cmpi(temp, Operand::Zero());
1293 // Load next context in chain.
1294 __ LoadP(next, ContextOperand(next, Context::PREVIOUS_INDEX));
1299 // All extension objects were empty and it is safe to use a normal global
1301 EmitGlobalVariableLoad(proxy, typeof_mode);
1305 MemOperand FullCodeGenerator::ContextSlotOperandCheckExtensions(Variable* var,
1307 DCHECK(var->IsContextSlot());
1308 Register context = cp;
1312 for (Scope* s = scope(); s != var->scope(); s = s->outer_scope()) {
1313 if (s->num_heap_slots() > 0) {
1314 if (s->calls_sloppy_eval()) {
1315 // Check that extension is NULL.
1316 __ LoadP(temp, ContextOperand(context, Context::EXTENSION_INDEX));
1317 __ cmpi(temp, Operand::Zero());
1320 __ LoadP(next, ContextOperand(context, Context::PREVIOUS_INDEX));
1321 // Walk the rest of the chain without clobbering cp.
1325 // Check that last extension is NULL.
1326 __ LoadP(temp, ContextOperand(context, Context::EXTENSION_INDEX));
1327 __ cmpi(temp, Operand::Zero());
1330 // This function is used only for loads, not stores, so it's safe to
1331 // return an cp-based operand (the write barrier cannot be allowed to
1332 // destroy the cp register).
1333 return ContextOperand(context, var->index());
1337 void FullCodeGenerator::EmitDynamicLookupFastCase(VariableProxy* proxy,
1338 TypeofMode typeof_mode,
1339 Label* slow, Label* done) {
1340 // Generate fast-case code for variables that might be shadowed by
1341 // eval-introduced variables. Eval is used a lot without
1342 // introducing variables. In those cases, we do not want to
1343 // perform a runtime call for all variables in the scope
1344 // containing the eval.
1345 Variable* var = proxy->var();
1346 if (var->mode() == DYNAMIC_GLOBAL) {
1347 EmitLoadGlobalCheckExtensions(proxy, typeof_mode, slow);
1349 } else if (var->mode() == DYNAMIC_LOCAL) {
1350 Variable* local = var->local_if_not_shadowed();
1351 __ LoadP(r3, ContextSlotOperandCheckExtensions(local, slow));
1352 if (local->mode() == LET || local->mode() == CONST ||
1353 local->mode() == CONST_LEGACY) {
1354 __ CompareRoot(r3, Heap::kTheHoleValueRootIndex);
1356 if (local->mode() == CONST_LEGACY) {
1357 __ LoadRoot(r3, Heap::kUndefinedValueRootIndex);
1358 } else { // LET || CONST
1359 __ mov(r3, Operand(var->name()));
1361 __ CallRuntime(Runtime::kThrowReferenceError, 1);
1369 void FullCodeGenerator::EmitGlobalVariableLoad(VariableProxy* proxy,
1370 TypeofMode typeof_mode) {
1371 Variable* var = proxy->var();
1372 DCHECK(var->IsUnallocatedOrGlobalSlot() ||
1373 (var->IsLookupSlot() && var->mode() == DYNAMIC_GLOBAL));
1374 if (var->IsGlobalSlot()) {
1375 DCHECK(var->index() > 0);
1376 DCHECK(var->IsStaticGlobalObjectProperty());
1377 const int slot = var->index();
1378 const int depth = scope()->ContextChainLength(var->scope());
1379 if (depth <= LoadGlobalViaContextStub::kMaximumDepth) {
1380 __ mov(LoadGlobalViaContextDescriptor::SlotRegister(), Operand(slot));
1381 LoadGlobalViaContextStub stub(isolate(), depth);
1384 __ Push(Smi::FromInt(slot));
1385 __ CallRuntime(Runtime::kLoadGlobalViaContext, 1);
1388 __ LoadP(LoadDescriptor::ReceiverRegister(), GlobalObjectOperand());
1389 __ mov(LoadDescriptor::NameRegister(), Operand(var->name()));
1390 __ mov(LoadDescriptor::SlotRegister(),
1391 Operand(SmiFromSlot(proxy->VariableFeedbackSlot())));
1392 CallLoadIC(typeof_mode);
1397 void FullCodeGenerator::EmitVariableLoad(VariableProxy* proxy,
1398 TypeofMode typeof_mode) {
1399 // Record position before possible IC call.
1400 SetExpressionPosition(proxy);
1401 PrepareForBailoutForId(proxy->BeforeId(), NO_REGISTERS);
1402 Variable* var = proxy->var();
1404 // Three cases: global variables, lookup variables, and all other types of
1406 switch (var->location()) {
1407 case VariableLocation::GLOBAL:
1408 case VariableLocation::UNALLOCATED: {
1409 Comment cmnt(masm_, "[ Global variable");
1410 EmitGlobalVariableLoad(proxy, typeof_mode);
1411 context()->Plug(r3);
1415 case VariableLocation::PARAMETER:
1416 case VariableLocation::LOCAL:
1417 case VariableLocation::CONTEXT: {
1418 DCHECK_EQ(NOT_INSIDE_TYPEOF, typeof_mode);
1419 Comment cmnt(masm_, var->IsContextSlot() ? "[ Context variable"
1420 : "[ Stack variable");
1421 if (var->binding_needs_init()) {
1422 // var->scope() may be NULL when the proxy is located in eval code and
1423 // refers to a potential outside binding. Currently those bindings are
1424 // always looked up dynamically, i.e. in that case
1425 // var->location() == LOOKUP.
1427 DCHECK(var->scope() != NULL);
1429 // Check if the binding really needs an initialization check. The check
1430 // can be skipped in the following situation: we have a LET or CONST
1431 // binding in harmony mode, both the Variable and the VariableProxy have
1432 // the same declaration scope (i.e. they are both in global code, in the
1433 // same function or in the same eval code) and the VariableProxy is in
1434 // the source physically located after the initializer of the variable.
1436 // We cannot skip any initialization checks for CONST in non-harmony
1437 // mode because const variables may be declared but never initialized:
1438 // if (false) { const x; }; var y = x;
1440 // The condition on the declaration scopes is a conservative check for
1441 // nested functions that access a binding and are called before the
1442 // binding is initialized:
1443 // function() { f(); let x = 1; function f() { x = 2; } }
1445 bool skip_init_check;
1446 if (var->scope()->DeclarationScope() != scope()->DeclarationScope()) {
1447 skip_init_check = false;
1448 } else if (var->is_this()) {
1449 CHECK(info_->function() != nullptr &&
1450 (info_->function()->kind() & kSubclassConstructor) != 0);
1451 // TODO(dslomov): implement 'this' hole check elimination.
1452 skip_init_check = false;
1454 // Check that we always have valid source position.
1455 DCHECK(var->initializer_position() != RelocInfo::kNoPosition);
1456 DCHECK(proxy->position() != RelocInfo::kNoPosition);
1457 skip_init_check = var->mode() != CONST_LEGACY &&
1458 var->initializer_position() < proxy->position();
1461 if (!skip_init_check) {
1463 // Let and const need a read barrier.
1465 __ CompareRoot(r3, Heap::kTheHoleValueRootIndex);
1467 if (var->mode() == LET || var->mode() == CONST) {
1468 // Throw a reference error when using an uninitialized let/const
1469 // binding in harmony mode.
1470 __ mov(r3, Operand(var->name()));
1472 __ CallRuntime(Runtime::kThrowReferenceError, 1);
1474 // Uninitalized const bindings outside of harmony mode are unholed.
1475 DCHECK(var->mode() == CONST_LEGACY);
1476 __ LoadRoot(r3, Heap::kUndefinedValueRootIndex);
1479 context()->Plug(r3);
1483 context()->Plug(var);
1487 case VariableLocation::LOOKUP: {
1488 Comment cmnt(masm_, "[ Lookup variable");
1490 // Generate code for loading from variables potentially shadowed
1491 // by eval-introduced variables.
1492 EmitDynamicLookupFastCase(proxy, typeof_mode, &slow, &done);
1494 __ mov(r4, Operand(var->name()));
1495 __ Push(cp, r4); // Context and name.
1496 Runtime::FunctionId function_id =
1497 typeof_mode == NOT_INSIDE_TYPEOF
1498 ? Runtime::kLoadLookupSlot
1499 : Runtime::kLoadLookupSlotNoReferenceError;
1500 __ CallRuntime(function_id, 2);
1502 context()->Plug(r3);
1508 void FullCodeGenerator::VisitRegExpLiteral(RegExpLiteral* expr) {
1509 Comment cmnt(masm_, "[ RegExpLiteral");
1511 // Registers will be used as follows:
1512 // r8 = materialized value (RegExp literal)
1513 // r7 = JS function, literals array
1514 // r6 = literal index
1515 // r5 = RegExp pattern
1516 // r4 = RegExp flags
1517 // r3 = RegExp literal clone
1518 __ LoadP(r3, MemOperand(fp, JavaScriptFrameConstants::kFunctionOffset));
1519 __ LoadP(r7, FieldMemOperand(r3, JSFunction::kLiteralsOffset));
1520 int literal_offset =
1521 FixedArray::kHeaderSize + expr->literal_index() * kPointerSize;
1522 __ LoadP(r8, FieldMemOperand(r7, literal_offset), r0);
1523 __ LoadRoot(ip, Heap::kUndefinedValueRootIndex);
1525 __ bne(&materialized);
1527 // Create regexp literal using runtime function.
1528 // Result will be in r3.
1529 __ LoadSmiLiteral(r6, Smi::FromInt(expr->literal_index()));
1530 __ mov(r5, Operand(expr->pattern()));
1531 __ mov(r4, Operand(expr->flags()));
1532 __ Push(r7, r6, r5, r4);
1533 __ CallRuntime(Runtime::kMaterializeRegExpLiteral, 4);
1536 __ bind(&materialized);
1537 int size = JSRegExp::kSize + JSRegExp::kInObjectFieldCount * kPointerSize;
1538 Label allocated, runtime_allocate;
1539 __ Allocate(size, r3, r5, r6, &runtime_allocate, TAG_OBJECT);
1542 __ bind(&runtime_allocate);
1543 __ LoadSmiLiteral(r3, Smi::FromInt(size));
1545 __ CallRuntime(Runtime::kAllocateInNewSpace, 1);
1548 __ bind(&allocated);
1549 // After this, registers are used as follows:
1550 // r3: Newly allocated regexp.
1551 // r8: Materialized regexp.
1553 __ CopyFields(r3, r8, r5.bit(), size / kPointerSize);
1554 context()->Plug(r3);
1558 void FullCodeGenerator::EmitAccessor(Expression* expression) {
1559 if (expression == NULL) {
1560 __ LoadRoot(r4, Heap::kNullValueRootIndex);
1563 VisitForStackValue(expression);
1568 void FullCodeGenerator::VisitObjectLiteral(ObjectLiteral* expr) {
1569 Comment cmnt(masm_, "[ ObjectLiteral");
1571 Handle<FixedArray> constant_properties = expr->constant_properties();
1572 __ LoadP(r6, MemOperand(fp, JavaScriptFrameConstants::kFunctionOffset));
1573 __ LoadP(r6, FieldMemOperand(r6, JSFunction::kLiteralsOffset));
1574 __ LoadSmiLiteral(r5, Smi::FromInt(expr->literal_index()));
1575 __ mov(r4, Operand(constant_properties));
1576 int flags = expr->ComputeFlags();
1577 __ LoadSmiLiteral(r3, Smi::FromInt(flags));
1578 if (MustCreateObjectLiteralWithRuntime(expr)) {
1579 __ Push(r6, r5, r4, r3);
1580 __ CallRuntime(Runtime::kCreateObjectLiteral, 4);
1582 FastCloneShallowObjectStub stub(isolate(), expr->properties_count());
1585 PrepareForBailoutForId(expr->CreateLiteralId(), TOS_REG);
1587 // If result_saved is true the result is on top of the stack. If
1588 // result_saved is false the result is in r3.
1589 bool result_saved = false;
1591 AccessorTable accessor_table(zone());
1592 int property_index = 0;
1593 // store_slot_index points to the vector IC slot for the next store IC used.
1594 // ObjectLiteral::ComputeFeedbackRequirements controls the allocation of slots
1595 // and must be updated if the number of store ICs emitted here changes.
1596 int store_slot_index = 0;
1597 for (; property_index < expr->properties()->length(); property_index++) {
1598 ObjectLiteral::Property* property = expr->properties()->at(property_index);
1599 if (property->is_computed_name()) break;
1600 if (property->IsCompileTimeValue()) continue;
1602 Literal* key = property->key()->AsLiteral();
1603 Expression* value = property->value();
1604 if (!result_saved) {
1605 __ push(r3); // Save result on stack
1606 result_saved = true;
1608 switch (property->kind()) {
1609 case ObjectLiteral::Property::CONSTANT:
1611 case ObjectLiteral::Property::MATERIALIZED_LITERAL:
1612 DCHECK(!CompileTimeValue::IsCompileTimeValue(property->value()));
1614 case ObjectLiteral::Property::COMPUTED:
1615 // It is safe to use [[Put]] here because the boilerplate already
1616 // contains computed properties with an uninitialized value.
1617 if (key->value()->IsInternalizedString()) {
1618 if (property->emit_store()) {
1619 VisitForAccumulatorValue(value);
1620 DCHECK(StoreDescriptor::ValueRegister().is(r3));
1621 __ mov(StoreDescriptor::NameRegister(), Operand(key->value()));
1622 __ LoadP(StoreDescriptor::ReceiverRegister(), MemOperand(sp));
1623 if (FLAG_vector_stores) {
1624 EmitLoadStoreICSlot(expr->GetNthSlot(store_slot_index++));
1627 CallStoreIC(key->LiteralFeedbackId());
1629 PrepareForBailoutForId(key->id(), NO_REGISTERS);
1631 if (NeedsHomeObject(value)) {
1632 __ Move(StoreDescriptor::ReceiverRegister(), r3);
1633 __ mov(StoreDescriptor::NameRegister(),
1634 Operand(isolate()->factory()->home_object_symbol()));
1635 __ LoadP(StoreDescriptor::ValueRegister(), MemOperand(sp));
1636 if (FLAG_vector_stores) {
1637 EmitLoadStoreICSlot(expr->GetNthSlot(store_slot_index++));
1642 VisitForEffect(value);
1646 // Duplicate receiver on stack.
1647 __ LoadP(r3, MemOperand(sp));
1649 VisitForStackValue(key);
1650 VisitForStackValue(value);
1651 if (property->emit_store()) {
1652 EmitSetHomeObjectIfNeeded(
1653 value, 2, expr->SlotForHomeObject(value, &store_slot_index));
1654 __ LoadSmiLiteral(r3, Smi::FromInt(SLOPPY)); // PropertyAttributes
1656 __ CallRuntime(Runtime::kSetProperty, 4);
1661 case ObjectLiteral::Property::PROTOTYPE:
1662 // Duplicate receiver on stack.
1663 __ LoadP(r3, MemOperand(sp));
1665 VisitForStackValue(value);
1666 DCHECK(property->emit_store());
1667 __ CallRuntime(Runtime::kInternalSetPrototype, 2);
1669 case ObjectLiteral::Property::GETTER:
1670 if (property->emit_store()) {
1671 accessor_table.lookup(key)->second->getter = value;
1674 case ObjectLiteral::Property::SETTER:
1675 if (property->emit_store()) {
1676 accessor_table.lookup(key)->second->setter = value;
1682 // Emit code to define accessors, using only a single call to the runtime for
1683 // each pair of corresponding getters and setters.
1684 for (AccessorTable::Iterator it = accessor_table.begin();
1685 it != accessor_table.end(); ++it) {
1686 __ LoadP(r3, MemOperand(sp)); // Duplicate receiver.
1688 VisitForStackValue(it->first);
1689 EmitAccessor(it->second->getter);
1690 EmitSetHomeObjectIfNeeded(
1691 it->second->getter, 2,
1692 expr->SlotForHomeObject(it->second->getter, &store_slot_index));
1693 EmitAccessor(it->second->setter);
1694 EmitSetHomeObjectIfNeeded(
1695 it->second->setter, 3,
1696 expr->SlotForHomeObject(it->second->setter, &store_slot_index));
1697 __ LoadSmiLiteral(r3, Smi::FromInt(NONE));
1699 __ CallRuntime(Runtime::kDefineAccessorPropertyUnchecked, 5);
1702 // Object literals have two parts. The "static" part on the left contains no
1703 // computed property names, and so we can compute its map ahead of time; see
1704 // runtime.cc::CreateObjectLiteralBoilerplate. The second "dynamic" part
1705 // starts with the first computed property name, and continues with all
1706 // properties to its right. All the code from above initializes the static
1707 // component of the object literal, and arranges for the map of the result to
1708 // reflect the static order in which the keys appear. For the dynamic
1709 // properties, we compile them into a series of "SetOwnProperty" runtime
1710 // calls. This will preserve insertion order.
1711 for (; property_index < expr->properties()->length(); property_index++) {
1712 ObjectLiteral::Property* property = expr->properties()->at(property_index);
1714 Expression* value = property->value();
1715 if (!result_saved) {
1716 __ push(r3); // Save result on the stack
1717 result_saved = true;
1720 __ LoadP(r3, MemOperand(sp)); // Duplicate receiver.
1723 if (property->kind() == ObjectLiteral::Property::PROTOTYPE) {
1724 DCHECK(!property->is_computed_name());
1725 VisitForStackValue(value);
1726 DCHECK(property->emit_store());
1727 __ CallRuntime(Runtime::kInternalSetPrototype, 2);
1729 EmitPropertyKey(property, expr->GetIdForProperty(property_index));
1730 VisitForStackValue(value);
1731 EmitSetHomeObjectIfNeeded(
1732 value, 2, expr->SlotForHomeObject(value, &store_slot_index));
1734 switch (property->kind()) {
1735 case ObjectLiteral::Property::CONSTANT:
1736 case ObjectLiteral::Property::MATERIALIZED_LITERAL:
1737 case ObjectLiteral::Property::COMPUTED:
1738 if (property->emit_store()) {
1739 __ LoadSmiLiteral(r3, Smi::FromInt(NONE));
1741 __ CallRuntime(Runtime::kDefineDataPropertyUnchecked, 4);
1747 case ObjectLiteral::Property::PROTOTYPE:
1751 case ObjectLiteral::Property::GETTER:
1752 __ mov(r3, Operand(Smi::FromInt(NONE)));
1754 __ CallRuntime(Runtime::kDefineGetterPropertyUnchecked, 4);
1757 case ObjectLiteral::Property::SETTER:
1758 __ mov(r3, Operand(Smi::FromInt(NONE)));
1760 __ CallRuntime(Runtime::kDefineSetterPropertyUnchecked, 4);
1766 if (expr->has_function()) {
1767 DCHECK(result_saved);
1768 __ LoadP(r3, MemOperand(sp));
1770 __ CallRuntime(Runtime::kToFastProperties, 1);
1774 context()->PlugTOS();
1776 context()->Plug(r3);
1779 // Verify that compilation exactly consumed the number of store ic slots that
1780 // the ObjectLiteral node had to offer.
1781 DCHECK(!FLAG_vector_stores || store_slot_index == expr->slot_count());
1785 void FullCodeGenerator::VisitArrayLiteral(ArrayLiteral* expr) {
1786 Comment cmnt(masm_, "[ ArrayLiteral");
1788 expr->BuildConstantElements(isolate());
1789 Handle<FixedArray> constant_elements = expr->constant_elements();
1790 bool has_fast_elements =
1791 IsFastObjectElementsKind(expr->constant_elements_kind());
1792 Handle<FixedArrayBase> constant_elements_values(
1793 FixedArrayBase::cast(constant_elements->get(1)));
1795 AllocationSiteMode allocation_site_mode = TRACK_ALLOCATION_SITE;
1796 if (has_fast_elements && !FLAG_allocation_site_pretenuring) {
1797 // If the only customer of allocation sites is transitioning, then
1798 // we can turn it off if we don't have anywhere else to transition to.
1799 allocation_site_mode = DONT_TRACK_ALLOCATION_SITE;
1802 __ LoadP(r6, MemOperand(fp, JavaScriptFrameConstants::kFunctionOffset));
1803 __ LoadP(r6, FieldMemOperand(r6, JSFunction::kLiteralsOffset));
1804 __ LoadSmiLiteral(r5, Smi::FromInt(expr->literal_index()));
1805 __ mov(r4, Operand(constant_elements));
1806 if (MustCreateArrayLiteralWithRuntime(expr)) {
1807 __ LoadSmiLiteral(r3, Smi::FromInt(expr->ComputeFlags()));
1808 __ Push(r6, r5, r4, r3);
1809 __ CallRuntime(Runtime::kCreateArrayLiteral, 4);
1811 FastCloneShallowArrayStub stub(isolate(), allocation_site_mode);
1814 PrepareForBailoutForId(expr->CreateLiteralId(), TOS_REG);
1816 bool result_saved = false; // Is the result saved to the stack?
1817 ZoneList<Expression*>* subexprs = expr->values();
1818 int length = subexprs->length();
1820 // Emit code to evaluate all the non-constant subexpressions and to store
1821 // them into the newly cloned array.
1822 int array_index = 0;
1823 for (; array_index < length; array_index++) {
1824 Expression* subexpr = subexprs->at(array_index);
1825 if (subexpr->IsSpread()) break;
1826 // If the subexpression is a literal or a simple materialized literal it
1827 // is already set in the cloned array.
1828 if (CompileTimeValue::IsCompileTimeValue(subexpr)) continue;
1830 if (!result_saved) {
1832 __ Push(Smi::FromInt(expr->literal_index()));
1833 result_saved = true;
1835 VisitForAccumulatorValue(subexpr);
1837 if (has_fast_elements) {
1838 int offset = FixedArray::kHeaderSize + (array_index * kPointerSize);
1839 __ LoadP(r8, MemOperand(sp, kPointerSize)); // Copy of array literal.
1840 __ LoadP(r4, FieldMemOperand(r8, JSObject::kElementsOffset));
1841 __ StoreP(result_register(), FieldMemOperand(r4, offset), r0);
1842 // Update the write barrier for the array store.
1843 __ RecordWriteField(r4, offset, result_register(), r5, kLRHasBeenSaved,
1844 kDontSaveFPRegs, EMIT_REMEMBERED_SET,
1847 __ LoadSmiLiteral(r6, Smi::FromInt(array_index));
1848 StoreArrayLiteralElementStub stub(isolate());
1852 PrepareForBailoutForId(expr->GetIdForElement(array_index), NO_REGISTERS);
1855 // In case the array literal contains spread expressions it has two parts. The
1856 // first part is the "static" array which has a literal index is handled
1857 // above. The second part is the part after the first spread expression
1858 // (inclusive) and these elements gets appended to the array. Note that the
1859 // number elements an iterable produces is unknown ahead of time.
1860 if (array_index < length && result_saved) {
1861 __ Drop(1); // literal index
1863 result_saved = false;
1865 for (; array_index < length; array_index++) {
1866 Expression* subexpr = subexprs->at(array_index);
1869 if (subexpr->IsSpread()) {
1870 VisitForStackValue(subexpr->AsSpread()->expression());
1871 __ InvokeBuiltin(Builtins::CONCAT_ITERABLE_TO_ARRAY, CALL_FUNCTION);
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::EmitIsObject(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 __ JumpIfSmi(r3, if_false);
3359 __ LoadRoot(ip, Heap::kNullValueRootIndex);
3362 __ LoadP(r5, FieldMemOperand(r3, HeapObject::kMapOffset));
3363 // Undetectable objects behave like undefined when tested with typeof.
3364 __ lbz(r4, FieldMemOperand(r5, Map::kBitFieldOffset));
3365 __ andi(r0, r4, Operand(1 << Map::kIsUndetectable));
3366 __ bne(if_false, cr0);
3367 __ lbz(r4, FieldMemOperand(r5, Map::kInstanceTypeOffset));
3368 __ cmpi(r4, Operand(FIRST_NONCALLABLE_SPEC_OBJECT_TYPE));
3370 __ cmpi(r4, Operand(LAST_NONCALLABLE_SPEC_OBJECT_TYPE));
3371 PrepareForBailoutBeforeSplit(expr, true, if_true, if_false);
3372 Split(le, if_true, if_false, fall_through);
3374 context()->Plug(if_true, if_false);
3378 void FullCodeGenerator::EmitIsSpecObject(CallRuntime* expr) {
3379 ZoneList<Expression*>* args = expr->arguments();
3380 DCHECK(args->length() == 1);
3382 VisitForAccumulatorValue(args->at(0));
3384 Label materialize_true, materialize_false;
3385 Label* if_true = NULL;
3386 Label* if_false = NULL;
3387 Label* fall_through = NULL;
3388 context()->PrepareTest(&materialize_true, &materialize_false, &if_true,
3389 &if_false, &fall_through);
3391 __ JumpIfSmi(r3, if_false);
3392 __ CompareObjectType(r3, r4, r4, FIRST_SPEC_OBJECT_TYPE);
3393 PrepareForBailoutBeforeSplit(expr, true, if_true, if_false);
3394 Split(ge, if_true, if_false, fall_through);
3396 context()->Plug(if_true, if_false);
3400 void FullCodeGenerator::EmitIsSimdValue(CallRuntime* expr) {
3401 ZoneList<Expression*>* args = expr->arguments();
3402 DCHECK(args->length() == 1);
3404 VisitForAccumulatorValue(args->at(0));
3406 Label materialize_true, materialize_false;
3407 Label* if_true = NULL;
3408 Label* if_false = NULL;
3409 Label* fall_through = NULL;
3410 context()->PrepareTest(&materialize_true, &materialize_false, &if_true,
3411 &if_false, &fall_through);
3413 __ JumpIfSmi(r3, if_false);
3415 Register type_reg = r5;
3416 __ LoadP(map, FieldMemOperand(r3, HeapObject::kMapOffset));
3417 __ lbz(type_reg, FieldMemOperand(map, Map::kInstanceTypeOffset));
3418 __ subi(type_reg, type_reg, Operand(FIRST_SIMD_VALUE_TYPE));
3419 __ cmpli(type_reg, Operand(LAST_SIMD_VALUE_TYPE - FIRST_SIMD_VALUE_TYPE));
3420 PrepareForBailoutBeforeSplit(expr, true, if_true, if_false);
3421 Split(le, if_true, if_false, fall_through);
3423 context()->Plug(if_true, if_false);
3427 void FullCodeGenerator::EmitIsStringWrapperSafeForDefaultValueOf(
3428 CallRuntime* expr) {
3429 ZoneList<Expression*>* args = expr->arguments();
3430 DCHECK(args->length() == 1);
3432 VisitForAccumulatorValue(args->at(0));
3434 Label materialize_true, materialize_false, skip_lookup;
3435 Label* if_true = NULL;
3436 Label* if_false = NULL;
3437 Label* fall_through = NULL;
3438 context()->PrepareTest(&materialize_true, &materialize_false, &if_true,
3439 &if_false, &fall_through);
3441 __ AssertNotSmi(r3);
3443 __ LoadP(r4, FieldMemOperand(r3, HeapObject::kMapOffset));
3444 __ lbz(ip, FieldMemOperand(r4, Map::kBitField2Offset));
3445 __ andi(r0, ip, Operand(1 << Map::kStringWrapperSafeForDefaultValueOf));
3446 __ bne(&skip_lookup, cr0);
3448 // Check for fast case object. Generate false result for slow case object.
3449 __ LoadP(r5, FieldMemOperand(r3, JSObject::kPropertiesOffset));
3450 __ LoadP(r5, FieldMemOperand(r5, HeapObject::kMapOffset));
3451 __ LoadRoot(ip, Heap::kHashTableMapRootIndex);
3455 // Look for valueOf name in the descriptor array, and indicate false if
3456 // found. Since we omit an enumeration index check, if it is added via a
3457 // transition that shares its descriptor array, this is a false positive.
3458 Label entry, loop, done;
3460 // Skip loop if no descriptors are valid.
3461 __ NumberOfOwnDescriptors(r6, r4);
3462 __ cmpi(r6, Operand::Zero());
3465 __ LoadInstanceDescriptors(r4, r7);
3466 // r7: descriptor array.
3467 // r6: valid entries in the descriptor array.
3468 __ mov(ip, Operand(DescriptorArray::kDescriptorSize));
3470 // Calculate location of the first key name.
3471 __ addi(r7, r7, Operand(DescriptorArray::kFirstOffset - kHeapObjectTag));
3472 // Calculate the end of the descriptor array.
3474 __ ShiftLeftImm(ip, r6, Operand(kPointerSizeLog2));
3477 // Loop through all the keys in the descriptor array. If one of these is the
3478 // string "valueOf" the result is false.
3479 // The use of ip to store the valueOf string assumes that it is not otherwise
3480 // used in the loop below.
3481 __ mov(ip, Operand(isolate()->factory()->value_of_string()));
3484 __ LoadP(r6, MemOperand(r7, 0));
3487 __ addi(r7, r7, Operand(DescriptorArray::kDescriptorSize * kPointerSize));
3494 // Set the bit in the map to indicate that there is no local valueOf field.
3495 __ lbz(r5, FieldMemOperand(r4, Map::kBitField2Offset));
3496 __ ori(r5, r5, Operand(1 << Map::kStringWrapperSafeForDefaultValueOf));
3497 __ stb(r5, FieldMemOperand(r4, Map::kBitField2Offset));
3499 __ bind(&skip_lookup);
3501 // If a valueOf property is not found on the object check that its
3502 // prototype is the un-modified String prototype. If not result is false.
3503 __ LoadP(r5, FieldMemOperand(r4, Map::kPrototypeOffset));
3504 __ JumpIfSmi(r5, if_false);
3505 __ LoadP(r5, FieldMemOperand(r5, HeapObject::kMapOffset));
3506 __ LoadP(r6, ContextOperand(cp, Context::GLOBAL_OBJECT_INDEX));
3507 __ LoadP(r6, FieldMemOperand(r6, GlobalObject::kNativeContextOffset));
3509 ContextOperand(r6, Context::STRING_FUNCTION_PROTOTYPE_MAP_INDEX));
3511 PrepareForBailoutBeforeSplit(expr, true, if_true, if_false);
3512 Split(eq, if_true, if_false, fall_through);
3514 context()->Plug(if_true, if_false);
3518 void FullCodeGenerator::EmitIsFunction(CallRuntime* expr) {
3519 ZoneList<Expression*>* args = expr->arguments();
3520 DCHECK(args->length() == 1);
3522 VisitForAccumulatorValue(args->at(0));
3524 Label materialize_true, materialize_false;
3525 Label* if_true = NULL;
3526 Label* if_false = NULL;
3527 Label* fall_through = NULL;
3528 context()->PrepareTest(&materialize_true, &materialize_false, &if_true,
3529 &if_false, &fall_through);
3531 __ JumpIfSmi(r3, if_false);
3532 __ CompareObjectType(r3, r4, r5, JS_FUNCTION_TYPE);
3533 PrepareForBailoutBeforeSplit(expr, true, if_true, if_false);
3534 Split(eq, if_true, if_false, fall_through);
3536 context()->Plug(if_true, if_false);
3540 void FullCodeGenerator::EmitIsMinusZero(CallRuntime* expr) {
3541 ZoneList<Expression*>* args = expr->arguments();
3542 DCHECK(args->length() == 1);
3544 VisitForAccumulatorValue(args->at(0));
3546 Label materialize_true, materialize_false;
3547 Label* if_true = NULL;
3548 Label* if_false = NULL;
3549 Label* fall_through = NULL;
3550 context()->PrepareTest(&materialize_true, &materialize_false, &if_true,
3551 &if_false, &fall_through);
3553 __ CheckMap(r3, r4, Heap::kHeapNumberMapRootIndex, if_false, DO_SMI_CHECK);
3554 #if V8_TARGET_ARCH_PPC64
3555 __ LoadP(r4, FieldMemOperand(r3, HeapNumber::kValueOffset));
3556 __ li(r5, Operand(1));
3557 __ rotrdi(r5, r5, 1); // r5 = 0x80000000_00000000
3560 __ lwz(r5, FieldMemOperand(r3, HeapNumber::kExponentOffset));
3561 __ lwz(r4, FieldMemOperand(r3, HeapNumber::kMantissaOffset));
3563 __ lis(r0, Operand(SIGN_EXT_IMM16(0x8000)));
3566 __ cmpi(r4, Operand::Zero());
3570 PrepareForBailoutBeforeSplit(expr, true, if_true, if_false);
3571 Split(eq, if_true, if_false, fall_through);
3573 context()->Plug(if_true, if_false);
3577 void FullCodeGenerator::EmitIsArray(CallRuntime* expr) {
3578 ZoneList<Expression*>* args = expr->arguments();
3579 DCHECK(args->length() == 1);
3581 VisitForAccumulatorValue(args->at(0));
3583 Label materialize_true, materialize_false;
3584 Label* if_true = NULL;
3585 Label* if_false = NULL;
3586 Label* fall_through = NULL;
3587 context()->PrepareTest(&materialize_true, &materialize_false, &if_true,
3588 &if_false, &fall_through);
3590 __ JumpIfSmi(r3, if_false);
3591 __ CompareObjectType(r3, r4, r4, JS_ARRAY_TYPE);
3592 PrepareForBailoutBeforeSplit(expr, true, if_true, if_false);
3593 Split(eq, if_true, if_false, fall_through);
3595 context()->Plug(if_true, if_false);
3599 void FullCodeGenerator::EmitIsTypedArray(CallRuntime* expr) {
3600 ZoneList<Expression*>* args = expr->arguments();
3601 DCHECK(args->length() == 1);
3603 VisitForAccumulatorValue(args->at(0));
3605 Label materialize_true, materialize_false;
3606 Label* if_true = NULL;
3607 Label* if_false = NULL;
3608 Label* fall_through = NULL;
3609 context()->PrepareTest(&materialize_true, &materialize_false, &if_true,
3610 &if_false, &fall_through);
3612 __ JumpIfSmi(r3, if_false);
3613 __ CompareObjectType(r3, r4, r4, JS_TYPED_ARRAY_TYPE);
3614 PrepareForBailoutBeforeSplit(expr, true, if_true, if_false);
3615 Split(eq, if_true, if_false, fall_through);
3617 context()->Plug(if_true, if_false);
3621 void FullCodeGenerator::EmitIsRegExp(CallRuntime* expr) {
3622 ZoneList<Expression*>* args = expr->arguments();
3623 DCHECK(args->length() == 1);
3625 VisitForAccumulatorValue(args->at(0));
3627 Label materialize_true, materialize_false;
3628 Label* if_true = NULL;
3629 Label* if_false = NULL;
3630 Label* fall_through = NULL;
3631 context()->PrepareTest(&materialize_true, &materialize_false, &if_true,
3632 &if_false, &fall_through);
3634 __ JumpIfSmi(r3, if_false);
3635 __ CompareObjectType(r3, r4, r4, JS_REGEXP_TYPE);
3636 PrepareForBailoutBeforeSplit(expr, true, if_true, if_false);
3637 Split(eq, if_true, if_false, fall_through);
3639 context()->Plug(if_true, if_false);
3643 void FullCodeGenerator::EmitIsJSProxy(CallRuntime* expr) {
3644 ZoneList<Expression*>* args = expr->arguments();
3645 DCHECK(args->length() == 1);
3647 VisitForAccumulatorValue(args->at(0));
3649 Label materialize_true, materialize_false;
3650 Label* if_true = NULL;
3651 Label* if_false = NULL;
3652 Label* fall_through = NULL;
3653 context()->PrepareTest(&materialize_true, &materialize_false, &if_true,
3654 &if_false, &fall_through);
3656 __ JumpIfSmi(r3, if_false);
3658 Register type_reg = r5;
3659 __ LoadP(map, FieldMemOperand(r3, HeapObject::kMapOffset));
3660 __ lbz(type_reg, FieldMemOperand(map, Map::kInstanceTypeOffset));
3661 __ subi(type_reg, type_reg, Operand(FIRST_JS_PROXY_TYPE));
3662 __ cmpli(type_reg, Operand(LAST_JS_PROXY_TYPE - FIRST_JS_PROXY_TYPE));
3663 PrepareForBailoutBeforeSplit(expr, true, if_true, if_false);
3664 Split(le, if_true, if_false, fall_through);
3666 context()->Plug(if_true, if_false);
3670 void FullCodeGenerator::EmitIsConstructCall(CallRuntime* expr) {
3671 DCHECK(expr->arguments()->length() == 0);
3673 Label materialize_true, materialize_false;
3674 Label* if_true = NULL;
3675 Label* if_false = NULL;
3676 Label* fall_through = NULL;
3677 context()->PrepareTest(&materialize_true, &materialize_false, &if_true,
3678 &if_false, &fall_through);
3680 // Get the frame pointer for the calling frame.
3681 __ LoadP(r5, MemOperand(fp, StandardFrameConstants::kCallerFPOffset));
3683 // Skip the arguments adaptor frame if it exists.
3684 Label check_frame_marker;
3685 __ LoadP(r4, MemOperand(r5, StandardFrameConstants::kContextOffset));
3686 __ CmpSmiLiteral(r4, Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR), r0);
3687 __ bne(&check_frame_marker);
3688 __ LoadP(r5, MemOperand(r5, StandardFrameConstants::kCallerFPOffset));
3690 // Check the marker in the calling frame.
3691 __ bind(&check_frame_marker);
3692 __ LoadP(r4, MemOperand(r5, StandardFrameConstants::kMarkerOffset));
3693 STATIC_ASSERT(StackFrame::CONSTRUCT < 0x4000);
3694 __ CmpSmiLiteral(r4, Smi::FromInt(StackFrame::CONSTRUCT), r0);
3695 PrepareForBailoutBeforeSplit(expr, true, if_true, if_false);
3696 Split(eq, if_true, if_false, fall_through);
3698 context()->Plug(if_true, if_false);
3702 void FullCodeGenerator::EmitObjectEquals(CallRuntime* expr) {
3703 ZoneList<Expression*>* args = expr->arguments();
3704 DCHECK(args->length() == 2);
3706 // Load the two objects into registers and perform the comparison.
3707 VisitForStackValue(args->at(0));
3708 VisitForAccumulatorValue(args->at(1));
3710 Label materialize_true, materialize_false;
3711 Label* if_true = NULL;
3712 Label* if_false = NULL;
3713 Label* fall_through = NULL;
3714 context()->PrepareTest(&materialize_true, &materialize_false, &if_true,
3715 &if_false, &fall_through);
3719 PrepareForBailoutBeforeSplit(expr, true, if_true, if_false);
3720 Split(eq, if_true, if_false, fall_through);
3722 context()->Plug(if_true, if_false);
3726 void FullCodeGenerator::EmitArguments(CallRuntime* expr) {
3727 ZoneList<Expression*>* args = expr->arguments();
3728 DCHECK(args->length() == 1);
3730 // ArgumentsAccessStub expects the key in r4 and the formal
3731 // parameter count in r3.
3732 VisitForAccumulatorValue(args->at(0));
3734 __ LoadSmiLiteral(r3, Smi::FromInt(info_->scope()->num_parameters()));
3735 ArgumentsAccessStub stub(isolate(), ArgumentsAccessStub::READ_ELEMENT);
3737 context()->Plug(r3);
3741 void FullCodeGenerator::EmitArgumentsLength(CallRuntime* expr) {
3742 DCHECK(expr->arguments()->length() == 0);
3744 // Get the number of formal parameters.
3745 __ LoadSmiLiteral(r3, Smi::FromInt(info_->scope()->num_parameters()));
3747 // Check if the calling frame is an arguments adaptor frame.
3748 __ LoadP(r5, MemOperand(fp, StandardFrameConstants::kCallerFPOffset));
3749 __ LoadP(r6, MemOperand(r5, StandardFrameConstants::kContextOffset));
3750 __ CmpSmiLiteral(r6, Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR), r0);
3753 // Arguments adaptor case: Read the arguments length from the
3755 __ LoadP(r3, MemOperand(r5, ArgumentsAdaptorFrameConstants::kLengthOffset));
3758 context()->Plug(r3);
3762 void FullCodeGenerator::EmitClassOf(CallRuntime* expr) {
3763 ZoneList<Expression*>* args = expr->arguments();
3764 DCHECK(args->length() == 1);
3765 Label done, null, function, non_function_constructor;
3767 VisitForAccumulatorValue(args->at(0));
3769 // If the object is a smi, we return null.
3770 __ JumpIfSmi(r3, &null);
3772 // Check that the object is a JS object but take special care of JS
3773 // functions to make sure they have 'Function' as their class.
3774 // Assume that there are only two callable types, and one of them is at
3775 // either end of the type range for JS object types. Saves extra comparisons.
3776 STATIC_ASSERT(NUM_OF_CALLABLE_SPEC_OBJECT_TYPES == 2);
3777 __ CompareObjectType(r3, r3, r4, FIRST_SPEC_OBJECT_TYPE);
3778 // Map is now in r3.
3780 STATIC_ASSERT(FIRST_NONCALLABLE_SPEC_OBJECT_TYPE ==
3781 FIRST_SPEC_OBJECT_TYPE + 1);
3784 __ cmpi(r4, Operand(LAST_SPEC_OBJECT_TYPE));
3785 STATIC_ASSERT(LAST_NONCALLABLE_SPEC_OBJECT_TYPE == LAST_SPEC_OBJECT_TYPE - 1);
3787 // Assume that there is no larger type.
3788 STATIC_ASSERT(LAST_NONCALLABLE_SPEC_OBJECT_TYPE == LAST_TYPE - 1);
3790 // Check if the constructor in the map is a JS function.
3791 Register instance_type = r5;
3792 __ GetMapConstructor(r3, r3, r4, instance_type);
3793 __ cmpi(instance_type, Operand(JS_FUNCTION_TYPE));
3794 __ bne(&non_function_constructor);
3796 // r3 now contains the constructor function. Grab the
3797 // instance class name from there.
3798 __ LoadP(r3, FieldMemOperand(r3, JSFunction::kSharedFunctionInfoOffset));
3800 FieldMemOperand(r3, SharedFunctionInfo::kInstanceClassNameOffset));
3803 // Functions have class 'Function'.
3805 __ LoadRoot(r3, Heap::kFunction_stringRootIndex);
3808 // Objects with a non-function constructor have class 'Object'.
3809 __ bind(&non_function_constructor);
3810 __ LoadRoot(r3, Heap::kObject_stringRootIndex);
3813 // Non-JS objects have class null.
3815 __ LoadRoot(r3, Heap::kNullValueRootIndex);
3820 context()->Plug(r3);
3824 void FullCodeGenerator::EmitValueOf(CallRuntime* expr) {
3825 ZoneList<Expression*>* args = expr->arguments();
3826 DCHECK(args->length() == 1);
3827 VisitForAccumulatorValue(args->at(0)); // Load the object.
3830 // If the object is a smi return the object.
3831 __ JumpIfSmi(r3, &done);
3832 // If the object is not a value type, return the object.
3833 __ CompareObjectType(r3, r4, r4, JS_VALUE_TYPE);
3835 __ LoadP(r3, FieldMemOperand(r3, JSValue::kValueOffset));
3838 context()->Plug(r3);
3842 void FullCodeGenerator::EmitIsDate(CallRuntime* expr) {
3843 ZoneList<Expression*>* args = expr->arguments();
3844 DCHECK_EQ(1, args->length());
3846 VisitForAccumulatorValue(args->at(0));
3848 Label materialize_true, materialize_false;
3849 Label* if_true = nullptr;
3850 Label* if_false = nullptr;
3851 Label* fall_through = nullptr;
3852 context()->PrepareTest(&materialize_true, &materialize_false, &if_true,
3853 &if_false, &fall_through);
3855 __ JumpIfSmi(r3, if_false);
3856 __ CompareObjectType(r3, r4, r4, JS_DATE_TYPE);
3857 PrepareForBailoutBeforeSplit(expr, true, if_true, if_false);
3858 Split(eq, if_true, if_false, fall_through);
3860 context()->Plug(if_true, if_false);
3864 void FullCodeGenerator::EmitDateField(CallRuntime* expr) {
3865 ZoneList<Expression*>* args = expr->arguments();
3866 DCHECK(args->length() == 2);
3867 DCHECK_NOT_NULL(args->at(1)->AsLiteral());
3868 Smi* index = Smi::cast(*(args->at(1)->AsLiteral()->value()));
3870 VisitForAccumulatorValue(args->at(0)); // Load the object.
3872 Register object = r3;
3873 Register result = r3;
3874 Register scratch0 = r11;
3875 Register scratch1 = r4;
3877 if (index->value() == 0) {
3878 __ LoadP(result, FieldMemOperand(object, JSDate::kValueOffset));
3880 Label runtime, done;
3881 if (index->value() < JSDate::kFirstUncachedField) {
3882 ExternalReference stamp = ExternalReference::date_cache_stamp(isolate());
3883 __ mov(scratch1, Operand(stamp));
3884 __ LoadP(scratch1, MemOperand(scratch1));
3885 __ LoadP(scratch0, FieldMemOperand(object, JSDate::kCacheStampOffset));
3886 __ cmp(scratch1, scratch0);
3889 FieldMemOperand(object, JSDate::kValueOffset +
3890 kPointerSize * index->value()),
3895 __ PrepareCallCFunction(2, scratch1);
3896 __ LoadSmiLiteral(r4, index);
3897 __ CallCFunction(ExternalReference::get_date_field_function(isolate()), 2);
3901 context()->Plug(result);
3905 void FullCodeGenerator::EmitOneByteSeqStringSetChar(CallRuntime* expr) {
3906 ZoneList<Expression*>* args = expr->arguments();
3907 DCHECK_EQ(3, args->length());
3909 Register string = r3;
3910 Register index = r4;
3911 Register value = r5;
3913 VisitForStackValue(args->at(0)); // index
3914 VisitForStackValue(args->at(1)); // value
3915 VisitForAccumulatorValue(args->at(2)); // string
3916 __ Pop(index, value);
3918 if (FLAG_debug_code) {
3919 __ TestIfSmi(value, r0);
3920 __ Check(eq, kNonSmiValue, cr0);
3921 __ TestIfSmi(index, r0);
3922 __ Check(eq, kNonSmiIndex, cr0);
3923 __ SmiUntag(index, index);
3924 static const uint32_t one_byte_seq_type = kSeqStringTag | kOneByteStringTag;
3925 __ EmitSeqStringSetCharCheck(string, index, value, one_byte_seq_type);
3926 __ SmiTag(index, index);
3930 __ addi(ip, string, Operand(SeqOneByteString::kHeaderSize - kHeapObjectTag));
3931 __ SmiToByteArrayOffset(r0, index);
3932 __ stbx(value, MemOperand(ip, r0));
3933 context()->Plug(string);
3937 void FullCodeGenerator::EmitTwoByteSeqStringSetChar(CallRuntime* expr) {
3938 ZoneList<Expression*>* args = expr->arguments();
3939 DCHECK_EQ(3, args->length());
3941 Register string = r3;
3942 Register index = r4;
3943 Register value = r5;
3945 VisitForStackValue(args->at(0)); // index
3946 VisitForStackValue(args->at(1)); // value
3947 VisitForAccumulatorValue(args->at(2)); // string
3948 __ Pop(index, value);
3950 if (FLAG_debug_code) {
3951 __ TestIfSmi(value, r0);
3952 __ Check(eq, kNonSmiValue, cr0);
3953 __ TestIfSmi(index, r0);
3954 __ Check(eq, kNonSmiIndex, cr0);
3955 __ SmiUntag(index, index);
3956 static const uint32_t two_byte_seq_type = kSeqStringTag | kTwoByteStringTag;
3957 __ EmitSeqStringSetCharCheck(string, index, value, two_byte_seq_type);
3958 __ SmiTag(index, index);
3962 __ addi(ip, string, Operand(SeqTwoByteString::kHeaderSize - kHeapObjectTag));
3963 __ SmiToShortArrayOffset(r0, index);
3964 __ sthx(value, MemOperand(ip, r0));
3965 context()->Plug(string);
3969 void FullCodeGenerator::EmitSetValueOf(CallRuntime* expr) {
3970 ZoneList<Expression*>* args = expr->arguments();
3971 DCHECK(args->length() == 2);
3972 VisitForStackValue(args->at(0)); // Load the object.
3973 VisitForAccumulatorValue(args->at(1)); // Load the value.
3974 __ pop(r4); // r3 = value. r4 = object.
3977 // If the object is a smi, return the value.
3978 __ JumpIfSmi(r4, &done);
3980 // If the object is not a value type, return the value.
3981 __ CompareObjectType(r4, r5, r5, JS_VALUE_TYPE);
3985 __ StoreP(r3, FieldMemOperand(r4, JSValue::kValueOffset), r0);
3986 // Update the write barrier. Save the value as it will be
3987 // overwritten by the write barrier code and is needed afterward.
3989 __ RecordWriteField(r4, JSValue::kValueOffset, r5, r6, kLRHasBeenSaved,
3993 context()->Plug(r3);
3997 void FullCodeGenerator::EmitNumberToString(CallRuntime* expr) {
3998 ZoneList<Expression*>* args = expr->arguments();
3999 DCHECK_EQ(args->length(), 1);
4000 // Load the argument into r3 and call the stub.
4001 VisitForAccumulatorValue(args->at(0));
4003 NumberToStringStub stub(isolate());
4005 context()->Plug(r3);
4009 void FullCodeGenerator::EmitToObject(CallRuntime* expr) {
4010 ZoneList<Expression*>* args = expr->arguments();
4011 DCHECK_EQ(1, args->length());
4012 // Load the argument into r3 and convert it.
4013 VisitForAccumulatorValue(args->at(0));
4015 ToObjectStub stub(isolate());
4017 context()->Plug(r3);
4021 void FullCodeGenerator::EmitStringCharFromCode(CallRuntime* expr) {
4022 ZoneList<Expression*>* args = expr->arguments();
4023 DCHECK(args->length() == 1);
4024 VisitForAccumulatorValue(args->at(0));
4027 StringCharFromCodeGenerator generator(r3, r4);
4028 generator.GenerateFast(masm_);
4031 NopRuntimeCallHelper call_helper;
4032 generator.GenerateSlow(masm_, call_helper);
4035 context()->Plug(r4);
4039 void FullCodeGenerator::EmitStringCharCodeAt(CallRuntime* expr) {
4040 ZoneList<Expression*>* args = expr->arguments();
4041 DCHECK(args->length() == 2);
4042 VisitForStackValue(args->at(0));
4043 VisitForAccumulatorValue(args->at(1));
4045 Register object = r4;
4046 Register index = r3;
4047 Register result = r6;
4051 Label need_conversion;
4052 Label index_out_of_range;
4054 StringCharCodeAtGenerator generator(object, index, result, &need_conversion,
4055 &need_conversion, &index_out_of_range,
4056 STRING_INDEX_IS_NUMBER);
4057 generator.GenerateFast(masm_);
4060 __ bind(&index_out_of_range);
4061 // When the index is out of range, the spec requires us to return
4063 __ LoadRoot(result, Heap::kNanValueRootIndex);
4066 __ bind(&need_conversion);
4067 // Load the undefined value into the result register, which will
4068 // trigger conversion.
4069 __ LoadRoot(result, Heap::kUndefinedValueRootIndex);
4072 NopRuntimeCallHelper call_helper;
4073 generator.GenerateSlow(masm_, NOT_PART_OF_IC_HANDLER, call_helper);
4076 context()->Plug(result);
4080 void FullCodeGenerator::EmitStringCharAt(CallRuntime* expr) {
4081 ZoneList<Expression*>* args = expr->arguments();
4082 DCHECK(args->length() == 2);
4083 VisitForStackValue(args->at(0));
4084 VisitForAccumulatorValue(args->at(1));
4086 Register object = r4;
4087 Register index = r3;
4088 Register scratch = r6;
4089 Register result = r3;
4093 Label need_conversion;
4094 Label index_out_of_range;
4096 StringCharAtGenerator generator(object, index, scratch, result,
4097 &need_conversion, &need_conversion,
4098 &index_out_of_range, STRING_INDEX_IS_NUMBER);
4099 generator.GenerateFast(masm_);
4102 __ bind(&index_out_of_range);
4103 // When the index is out of range, the spec requires us to return
4104 // the empty string.
4105 __ LoadRoot(result, Heap::kempty_stringRootIndex);
4108 __ bind(&need_conversion);
4109 // Move smi zero into the result register, which will trigger
4111 __ LoadSmiLiteral(result, Smi::FromInt(0));
4114 NopRuntimeCallHelper call_helper;
4115 generator.GenerateSlow(masm_, NOT_PART_OF_IC_HANDLER, call_helper);
4118 context()->Plug(result);
4122 void FullCodeGenerator::EmitStringAdd(CallRuntime* expr) {
4123 ZoneList<Expression*>* args = expr->arguments();
4124 DCHECK_EQ(2, args->length());
4125 VisitForStackValue(args->at(0));
4126 VisitForAccumulatorValue(args->at(1));
4129 StringAddStub stub(isolate(), STRING_ADD_CHECK_BOTH, NOT_TENURED);
4131 context()->Plug(r3);
4135 void FullCodeGenerator::EmitCallFunction(CallRuntime* expr) {
4136 ZoneList<Expression*>* args = expr->arguments();
4137 DCHECK(args->length() >= 2);
4139 int arg_count = args->length() - 2; // 2 ~ receiver and function.
4140 for (int i = 0; i < arg_count + 1; i++) {
4141 VisitForStackValue(args->at(i));
4143 VisitForAccumulatorValue(args->last()); // Function.
4145 Label runtime, done;
4146 // Check for non-function argument (including proxy).
4147 __ JumpIfSmi(r3, &runtime);
4148 __ CompareObjectType(r3, r4, r4, JS_FUNCTION_TYPE);
4151 // InvokeFunction requires the function in r4. Move it in there.
4152 __ mr(r4, result_register());
4153 ParameterCount count(arg_count);
4154 __ InvokeFunction(r4, count, CALL_FUNCTION, NullCallWrapper());
4155 __ LoadP(cp, MemOperand(fp, StandardFrameConstants::kContextOffset));
4160 __ CallRuntime(Runtime::kCall, args->length());
4163 context()->Plug(r3);
4167 void FullCodeGenerator::EmitDefaultConstructorCallSuper(CallRuntime* expr) {
4168 ZoneList<Expression*>* args = expr->arguments();
4169 DCHECK(args->length() == 2);
4172 VisitForStackValue(args->at(0));
4175 VisitForStackValue(args->at(1));
4176 __ CallRuntime(Runtime::kGetPrototype, 1);
4177 __ mr(r4, result_register());
4180 // Load original constructor into r7.
4181 __ LoadP(r7, MemOperand(sp, 1 * kPointerSize));
4183 // Check if the calling frame is an arguments adaptor frame.
4184 Label adaptor_frame, args_set_up, runtime;
4185 __ LoadP(r5, MemOperand(fp, StandardFrameConstants::kCallerFPOffset));
4186 __ LoadP(r6, MemOperand(r5, StandardFrameConstants::kContextOffset));
4187 __ CmpSmiLiteral(r6, Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR), r0);
4188 __ beq(&adaptor_frame);
4190 // default constructor has no arguments, so no adaptor frame means no args.
4191 __ li(r3, Operand::Zero());
4194 // Copy arguments from adaptor frame.
4196 __ bind(&adaptor_frame);
4197 __ LoadP(r3, MemOperand(r5, ArgumentsAdaptorFrameConstants::kLengthOffset));
4200 // Get arguments pointer in r5.
4201 __ ShiftLeftImm(r0, r3, Operand(kPointerSizeLog2));
4203 __ addi(r5, r5, Operand(StandardFrameConstants::kCallerSPOffset));
4208 // Pre-decrement in order to skip receiver.
4209 __ LoadPU(r6, MemOperand(r5, -kPointerSize));
4214 __ bind(&args_set_up);
4215 __ LoadRoot(r5, Heap::kUndefinedValueRootIndex);
4217 CallConstructStub stub(isolate(), SUPER_CONSTRUCTOR_CALL);
4218 __ Call(stub.GetCode(), RelocInfo::CONSTRUCT_CALL);
4222 context()->Plug(result_register());
4226 void FullCodeGenerator::EmitRegExpConstructResult(CallRuntime* expr) {
4227 RegExpConstructResultStub stub(isolate());
4228 ZoneList<Expression*>* args = expr->arguments();
4229 DCHECK(args->length() == 3);
4230 VisitForStackValue(args->at(0));
4231 VisitForStackValue(args->at(1));
4232 VisitForAccumulatorValue(args->at(2));
4235 context()->Plug(r3);
4239 void FullCodeGenerator::EmitHasCachedArrayIndex(CallRuntime* expr) {
4240 ZoneList<Expression*>* args = expr->arguments();
4241 VisitForAccumulatorValue(args->at(0));
4243 Label materialize_true, materialize_false;
4244 Label* if_true = NULL;
4245 Label* if_false = NULL;
4246 Label* fall_through = NULL;
4247 context()->PrepareTest(&materialize_true, &materialize_false, &if_true,
4248 &if_false, &fall_through);
4250 __ lwz(r3, FieldMemOperand(r3, String::kHashFieldOffset));
4251 // PPC - assume ip is free
4252 __ mov(ip, Operand(String::kContainsCachedArrayIndexMask));
4253 __ and_(r0, r3, ip, SetRC);
4254 PrepareForBailoutBeforeSplit(expr, true, if_true, if_false);
4255 Split(eq, if_true, if_false, fall_through, cr0);
4257 context()->Plug(if_true, if_false);
4261 void FullCodeGenerator::EmitGetCachedArrayIndex(CallRuntime* expr) {
4262 ZoneList<Expression*>* args = expr->arguments();
4263 DCHECK(args->length() == 1);
4264 VisitForAccumulatorValue(args->at(0));
4266 __ AssertString(r3);
4268 __ lwz(r3, FieldMemOperand(r3, String::kHashFieldOffset));
4269 __ IndexFromHash(r3, r3);
4271 context()->Plug(r3);
4275 void FullCodeGenerator::EmitFastOneByteArrayJoin(CallRuntime* expr) {
4276 Label bailout, done, one_char_separator, long_separator, non_trivial_array,
4277 not_size_one_array, loop, empty_separator_loop, one_char_separator_loop,
4278 one_char_separator_loop_entry, long_separator_loop;
4279 ZoneList<Expression*>* args = expr->arguments();
4280 DCHECK(args->length() == 2);
4281 VisitForStackValue(args->at(1));
4282 VisitForAccumulatorValue(args->at(0));
4284 // All aliases of the same register have disjoint lifetimes.
4285 Register array = r3;
4286 Register elements = no_reg; // Will be r3.
4287 Register result = no_reg; // Will be r3.
4288 Register separator = r4;
4289 Register array_length = r5;
4290 Register result_pos = no_reg; // Will be r5
4291 Register string_length = r6;
4292 Register string = r7;
4293 Register element = r8;
4294 Register elements_end = r9;
4295 Register scratch1 = r10;
4296 Register scratch2 = r11;
4298 // Separator operand is on the stack.
4301 // Check that the array is a JSArray.
4302 __ JumpIfSmi(array, &bailout);
4303 __ CompareObjectType(array, scratch1, scratch2, JS_ARRAY_TYPE);
4306 // Check that the array has fast elements.
4307 __ CheckFastElements(scratch1, scratch2, &bailout);
4309 // If the array has length zero, return the empty string.
4310 __ LoadP(array_length, FieldMemOperand(array, JSArray::kLengthOffset));
4311 __ SmiUntag(array_length);
4312 __ cmpi(array_length, Operand::Zero());
4313 __ bne(&non_trivial_array);
4314 __ LoadRoot(r3, Heap::kempty_stringRootIndex);
4317 __ bind(&non_trivial_array);
4319 // Get the FixedArray containing array's elements.
4321 __ LoadP(elements, FieldMemOperand(array, JSArray::kElementsOffset));
4322 array = no_reg; // End of array's live range.
4324 // Check that all array elements are sequential one-byte strings, and
4325 // accumulate the sum of their lengths, as a smi-encoded value.
4326 __ li(string_length, Operand::Zero());
4327 __ addi(element, elements, Operand(FixedArray::kHeaderSize - kHeapObjectTag));
4328 __ ShiftLeftImm(elements_end, array_length, Operand(kPointerSizeLog2));
4329 __ add(elements_end, element, elements_end);
4330 // Loop condition: while (element < elements_end).
4331 // Live values in registers:
4332 // elements: Fixed array of strings.
4333 // array_length: Length of the fixed array of strings (not smi)
4334 // separator: Separator string
4335 // string_length: Accumulated sum of string lengths (smi).
4336 // element: Current array element.
4337 // elements_end: Array end.
4338 if (generate_debug_code_) {
4339 __ cmpi(array_length, Operand::Zero());
4340 __ Assert(gt, kNoEmptyArraysHereInEmitFastOneByteArrayJoin);
4343 __ LoadP(string, MemOperand(element));
4344 __ addi(element, element, Operand(kPointerSize));
4345 __ JumpIfSmi(string, &bailout);
4346 __ LoadP(scratch1, FieldMemOperand(string, HeapObject::kMapOffset));
4347 __ lbz(scratch1, FieldMemOperand(scratch1, Map::kInstanceTypeOffset));
4348 __ JumpIfInstanceTypeIsNotSequentialOneByte(scratch1, scratch2, &bailout);
4349 __ LoadP(scratch1, FieldMemOperand(string, SeqOneByteString::kLengthOffset));
4351 __ AddAndCheckForOverflow(string_length, string_length, scratch1, scratch2,
4353 __ BranchOnOverflow(&bailout);
4355 __ cmp(element, elements_end);
4358 // If array_length is 1, return elements[0], a string.
4359 __ cmpi(array_length, Operand(1));
4360 __ bne(¬_size_one_array);
4361 __ LoadP(r3, FieldMemOperand(elements, FixedArray::kHeaderSize));
4364 __ bind(¬_size_one_array);
4366 // Live values in registers:
4367 // separator: Separator string
4368 // array_length: Length of the array.
4369 // string_length: Sum of string lengths (smi).
4370 // elements: FixedArray of strings.
4372 // Check that the separator is a flat one-byte string.
4373 __ JumpIfSmi(separator, &bailout);
4374 __ LoadP(scratch1, FieldMemOperand(separator, HeapObject::kMapOffset));
4375 __ lbz(scratch1, FieldMemOperand(scratch1, Map::kInstanceTypeOffset));
4376 __ JumpIfInstanceTypeIsNotSequentialOneByte(scratch1, scratch2, &bailout);
4378 // Add (separator length times array_length) - separator length to the
4379 // string_length to get the length of the result string.
4381 FieldMemOperand(separator, SeqOneByteString::kLengthOffset));
4382 __ sub(string_length, string_length, scratch1);
4383 #if V8_TARGET_ARCH_PPC64
4384 __ SmiUntag(scratch1, scratch1);
4385 __ Mul(scratch2, array_length, scratch1);
4386 // Check for smi overflow. No overflow if higher 33 bits of 64-bit result are
4388 __ ShiftRightImm(ip, scratch2, Operand(31), SetRC);
4389 __ bne(&bailout, cr0);
4390 __ SmiTag(scratch2, scratch2);
4392 // array_length is not smi but the other values are, so the result is a smi
4393 __ mullw(scratch2, array_length, scratch1);
4394 __ mulhw(ip, array_length, scratch1);
4395 // Check for smi overflow. No overflow if higher 33 bits of 64-bit result are
4397 __ cmpi(ip, Operand::Zero());
4399 __ cmpwi(scratch2, Operand::Zero());
4403 __ AddAndCheckForOverflow(string_length, string_length, scratch2, scratch1,
4405 __ BranchOnOverflow(&bailout);
4406 __ SmiUntag(string_length);
4408 // Get first element in the array to free up the elements register to be used
4410 __ addi(element, elements, Operand(FixedArray::kHeaderSize - kHeapObjectTag));
4411 result = elements; // End of live range for elements.
4413 // Live values in registers:
4414 // element: First array element
4415 // separator: Separator string
4416 // string_length: Length of result string (not smi)
4417 // array_length: Length of the array.
4418 __ AllocateOneByteString(result, string_length, scratch1, scratch2,
4419 elements_end, &bailout);
4420 // Prepare for looping. Set up elements_end to end of the array. Set
4421 // result_pos to the position of the result where to write the first
4423 __ ShiftLeftImm(elements_end, array_length, Operand(kPointerSizeLog2));
4424 __ add(elements_end, element, elements_end);
4425 result_pos = array_length; // End of live range for array_length.
4426 array_length = no_reg;
4427 __ addi(result_pos, result,
4428 Operand(SeqOneByteString::kHeaderSize - kHeapObjectTag));
4430 // Check the length of the separator.
4432 FieldMemOperand(separator, SeqOneByteString::kLengthOffset));
4433 __ CmpSmiLiteral(scratch1, Smi::FromInt(1), r0);
4434 __ beq(&one_char_separator);
4435 __ bgt(&long_separator);
4437 // Empty separator case
4438 __ bind(&empty_separator_loop);
4439 // Live values in registers:
4440 // result_pos: the position to which we are currently copying characters.
4441 // element: Current array element.
4442 // elements_end: Array end.
4444 // Copy next array element to the result.
4445 __ LoadP(string, MemOperand(element));
4446 __ addi(element, element, Operand(kPointerSize));
4447 __ LoadP(string_length, FieldMemOperand(string, String::kLengthOffset));
4448 __ SmiUntag(string_length);
4449 __ addi(string, string,
4450 Operand(SeqOneByteString::kHeaderSize - kHeapObjectTag));
4451 __ CopyBytes(string, result_pos, string_length, scratch1);
4452 __ cmp(element, elements_end);
4453 __ blt(&empty_separator_loop); // End while (element < elements_end).
4454 DCHECK(result.is(r3));
4457 // One-character separator case
4458 __ bind(&one_char_separator);
4459 // Replace separator with its one-byte character value.
4460 __ lbz(separator, FieldMemOperand(separator, SeqOneByteString::kHeaderSize));
4461 // Jump into the loop after the code that copies the separator, so the first
4462 // element is not preceded by a separator
4463 __ b(&one_char_separator_loop_entry);
4465 __ bind(&one_char_separator_loop);
4466 // Live values in registers:
4467 // result_pos: the position to which we are currently copying characters.
4468 // element: Current array element.
4469 // elements_end: Array end.
4470 // separator: Single separator one-byte char (in lower byte).
4472 // Copy the separator character to the result.
4473 __ stb(separator, MemOperand(result_pos));
4474 __ addi(result_pos, result_pos, Operand(1));
4476 // Copy next array element to the result.
4477 __ bind(&one_char_separator_loop_entry);
4478 __ LoadP(string, MemOperand(element));
4479 __ addi(element, element, Operand(kPointerSize));
4480 __ LoadP(string_length, FieldMemOperand(string, String::kLengthOffset));
4481 __ SmiUntag(string_length);
4482 __ addi(string, string,
4483 Operand(SeqOneByteString::kHeaderSize - kHeapObjectTag));
4484 __ CopyBytes(string, result_pos, string_length, scratch1);
4485 __ cmpl(element, elements_end);
4486 __ blt(&one_char_separator_loop); // End while (element < elements_end).
4487 DCHECK(result.is(r3));
4490 // Long separator case (separator is more than one character). Entry is at the
4491 // label long_separator below.
4492 __ bind(&long_separator_loop);
4493 // Live values in registers:
4494 // result_pos: the position to which we are currently copying characters.
4495 // element: Current array element.
4496 // elements_end: Array end.
4497 // separator: Separator string.
4499 // Copy the separator to the result.
4500 __ LoadP(string_length, FieldMemOperand(separator, String::kLengthOffset));
4501 __ SmiUntag(string_length);
4502 __ addi(string, separator,
4503 Operand(SeqOneByteString::kHeaderSize - kHeapObjectTag));
4504 __ CopyBytes(string, result_pos, string_length, scratch1);
4506 __ bind(&long_separator);
4507 __ LoadP(string, MemOperand(element));
4508 __ addi(element, element, Operand(kPointerSize));
4509 __ LoadP(string_length, FieldMemOperand(string, String::kLengthOffset));
4510 __ SmiUntag(string_length);
4511 __ addi(string, string,
4512 Operand(SeqOneByteString::kHeaderSize - kHeapObjectTag));
4513 __ CopyBytes(string, result_pos, string_length, scratch1);
4514 __ cmpl(element, elements_end);
4515 __ blt(&long_separator_loop); // End while (element < elements_end).
4516 DCHECK(result.is(r3));
4520 __ LoadRoot(r3, Heap::kUndefinedValueRootIndex);
4522 context()->Plug(r3);
4526 void FullCodeGenerator::EmitDebugIsActive(CallRuntime* expr) {
4527 DCHECK(expr->arguments()->length() == 0);
4528 ExternalReference debug_is_active =
4529 ExternalReference::debug_is_active_address(isolate());
4530 __ mov(ip, Operand(debug_is_active));
4531 __ lbz(r3, MemOperand(ip));
4533 context()->Plug(r3);
4537 void FullCodeGenerator::EmitLoadJSRuntimeFunction(CallRuntime* expr) {
4538 // Push the builtins object as the receiver.
4539 Register receiver = LoadDescriptor::ReceiverRegister();
4540 __ LoadP(receiver, GlobalObjectOperand());
4541 __ LoadP(receiver, FieldMemOperand(receiver, GlobalObject::kBuiltinsOffset));
4544 // Load the function from the receiver.
4545 __ mov(LoadDescriptor::NameRegister(), Operand(expr->name()));
4546 __ mov(LoadDescriptor::SlotRegister(),
4547 Operand(SmiFromSlot(expr->CallRuntimeFeedbackSlot())));
4548 CallLoadIC(NOT_INSIDE_TYPEOF);
4552 void FullCodeGenerator::EmitCallJSRuntimeFunction(CallRuntime* expr) {
4553 ZoneList<Expression*>* args = expr->arguments();
4554 int arg_count = args->length();
4556 SetCallPosition(expr, arg_count);
4557 CallFunctionStub stub(isolate(), arg_count, NO_CALL_FUNCTION_FLAGS);
4558 __ LoadP(r4, MemOperand(sp, (arg_count + 1) * kPointerSize), r0);
4563 void FullCodeGenerator::VisitCallRuntime(CallRuntime* expr) {
4564 ZoneList<Expression*>* args = expr->arguments();
4565 int arg_count = args->length();
4567 if (expr->is_jsruntime()) {
4568 Comment cmnt(masm_, "[ CallRuntime");
4569 EmitLoadJSRuntimeFunction(expr);
4571 // Push the target function under the receiver.
4572 __ LoadP(ip, MemOperand(sp, 0));
4574 __ StoreP(r3, MemOperand(sp, kPointerSize));
4576 // Push the arguments ("left-to-right").
4577 for (int i = 0; i < arg_count; i++) {
4578 VisitForStackValue(args->at(i));
4581 PrepareForBailoutForId(expr->CallId(), NO_REGISTERS);
4582 EmitCallJSRuntimeFunction(expr);
4584 // Restore context register.
4585 __ LoadP(cp, MemOperand(fp, StandardFrameConstants::kContextOffset));
4587 context()->DropAndPlug(1, r3);
4590 const Runtime::Function* function = expr->function();
4591 switch (function->function_id) {
4592 #define CALL_INTRINSIC_GENERATOR(Name) \
4593 case Runtime::kInline##Name: { \
4594 Comment cmnt(masm_, "[ Inline" #Name); \
4595 return Emit##Name(expr); \
4597 FOR_EACH_FULL_CODE_INTRINSIC(CALL_INTRINSIC_GENERATOR)
4598 #undef CALL_INTRINSIC_GENERATOR
4600 Comment cmnt(masm_, "[ CallRuntime for unhandled intrinsic");
4601 // Push the arguments ("left-to-right").
4602 for (int i = 0; i < arg_count; i++) {
4603 VisitForStackValue(args->at(i));
4606 // Call the C runtime function.
4607 PrepareForBailoutForId(expr->CallId(), NO_REGISTERS);
4608 __ CallRuntime(expr->function(), arg_count);
4609 context()->Plug(r3);
4616 void FullCodeGenerator::VisitUnaryOperation(UnaryOperation* expr) {
4617 switch (expr->op()) {
4618 case Token::DELETE: {
4619 Comment cmnt(masm_, "[ UnaryOperation (DELETE)");
4620 Property* property = expr->expression()->AsProperty();
4621 VariableProxy* proxy = expr->expression()->AsVariableProxy();
4623 if (property != NULL) {
4624 VisitForStackValue(property->obj());
4625 VisitForStackValue(property->key());
4626 __ CallRuntime(is_strict(language_mode())
4627 ? Runtime::kDeleteProperty_Strict
4628 : Runtime::kDeleteProperty_Sloppy,
4630 context()->Plug(r3);
4631 } else if (proxy != NULL) {
4632 Variable* var = proxy->var();
4633 // Delete of an unqualified identifier is disallowed in strict mode but
4634 // "delete this" is allowed.
4635 bool is_this = var->HasThisName(isolate());
4636 DCHECK(is_sloppy(language_mode()) || is_this);
4637 if (var->IsUnallocatedOrGlobalSlot()) {
4638 __ LoadP(r5, GlobalObjectOperand());
4639 __ mov(r4, Operand(var->name()));
4641 __ CallRuntime(Runtime::kDeleteProperty_Sloppy, 2);
4642 context()->Plug(r3);
4643 } else if (var->IsStackAllocated() || var->IsContextSlot()) {
4644 // Result of deleting non-global, non-dynamic variables is false.
4645 // The subexpression does not have side effects.
4646 context()->Plug(is_this);
4648 // Non-global variable. Call the runtime to try to delete from the
4649 // context where the variable was introduced.
4650 DCHECK(!context_register().is(r5));
4651 __ mov(r5, Operand(var->name()));
4652 __ Push(context_register(), r5);
4653 __ CallRuntime(Runtime::kDeleteLookupSlot, 2);
4654 context()->Plug(r3);
4657 // Result of deleting non-property, non-variable reference is true.
4658 // The subexpression may have side effects.
4659 VisitForEffect(expr->expression());
4660 context()->Plug(true);
4666 Comment cmnt(masm_, "[ UnaryOperation (VOID)");
4667 VisitForEffect(expr->expression());
4668 context()->Plug(Heap::kUndefinedValueRootIndex);
4673 Comment cmnt(masm_, "[ UnaryOperation (NOT)");
4674 if (context()->IsEffect()) {
4675 // Unary NOT has no side effects so it's only necessary to visit the
4676 // subexpression. Match the optimizing compiler by not branching.
4677 VisitForEffect(expr->expression());
4678 } else if (context()->IsTest()) {
4679 const TestContext* test = TestContext::cast(context());
4680 // The labels are swapped for the recursive call.
4681 VisitForControl(expr->expression(), test->false_label(),
4682 test->true_label(), test->fall_through());
4683 context()->Plug(test->true_label(), test->false_label());
4685 // We handle value contexts explicitly rather than simply visiting
4686 // for control and plugging the control flow into the context,
4687 // because we need to prepare a pair of extra administrative AST ids
4688 // for the optimizing compiler.
4689 DCHECK(context()->IsAccumulatorValue() || context()->IsStackValue());
4690 Label materialize_true, materialize_false, done;
4691 VisitForControl(expr->expression(), &materialize_false,
4692 &materialize_true, &materialize_true);
4693 __ bind(&materialize_true);
4694 PrepareForBailoutForId(expr->MaterializeTrueId(), NO_REGISTERS);
4695 __ LoadRoot(r3, Heap::kTrueValueRootIndex);
4696 if (context()->IsStackValue()) __ push(r3);
4698 __ bind(&materialize_false);
4699 PrepareForBailoutForId(expr->MaterializeFalseId(), NO_REGISTERS);
4700 __ LoadRoot(r3, Heap::kFalseValueRootIndex);
4701 if (context()->IsStackValue()) __ push(r3);
4707 case Token::TYPEOF: {
4708 Comment cmnt(masm_, "[ UnaryOperation (TYPEOF)");
4710 AccumulatorValueContext context(this);
4711 VisitForTypeofValue(expr->expression());
4714 TypeofStub typeof_stub(isolate());
4715 __ CallStub(&typeof_stub);
4716 context()->Plug(r3);
4726 void FullCodeGenerator::VisitCountOperation(CountOperation* expr) {
4727 DCHECK(expr->expression()->IsValidReferenceExpressionOrThis());
4729 Comment cmnt(masm_, "[ CountOperation");
4731 Property* prop = expr->expression()->AsProperty();
4732 LhsKind assign_type = Property::GetAssignType(prop);
4734 // Evaluate expression and get value.
4735 if (assign_type == VARIABLE) {
4736 DCHECK(expr->expression()->AsVariableProxy()->var() != NULL);
4737 AccumulatorValueContext context(this);
4738 EmitVariableLoad(expr->expression()->AsVariableProxy());
4740 // Reserve space for result of postfix operation.
4741 if (expr->is_postfix() && !context()->IsEffect()) {
4742 __ LoadSmiLiteral(ip, Smi::FromInt(0));
4745 switch (assign_type) {
4746 case NAMED_PROPERTY: {
4747 // Put the object both on the stack and in the register.
4748 VisitForStackValue(prop->obj());
4749 __ LoadP(LoadDescriptor::ReceiverRegister(), MemOperand(sp, 0));
4750 EmitNamedPropertyLoad(prop);
4754 case NAMED_SUPER_PROPERTY: {
4755 VisitForStackValue(prop->obj()->AsSuperPropertyReference()->this_var());
4756 VisitForAccumulatorValue(
4757 prop->obj()->AsSuperPropertyReference()->home_object());
4758 __ Push(result_register());
4759 const Register scratch = r4;
4760 __ LoadP(scratch, MemOperand(sp, kPointerSize));
4761 __ Push(scratch, result_register());
4762 EmitNamedSuperPropertyLoad(prop);
4766 case KEYED_SUPER_PROPERTY: {
4767 VisitForStackValue(prop->obj()->AsSuperPropertyReference()->this_var());
4768 VisitForAccumulatorValue(
4769 prop->obj()->AsSuperPropertyReference()->home_object());
4770 const Register scratch = r4;
4771 const Register scratch1 = r5;
4772 __ mr(scratch, result_register());
4773 VisitForAccumulatorValue(prop->key());
4774 __ Push(scratch, result_register());
4775 __ LoadP(scratch1, MemOperand(sp, 2 * kPointerSize));
4776 __ Push(scratch1, scratch, result_register());
4777 EmitKeyedSuperPropertyLoad(prop);
4781 case KEYED_PROPERTY: {
4782 VisitForStackValue(prop->obj());
4783 VisitForStackValue(prop->key());
4784 __ LoadP(LoadDescriptor::ReceiverRegister(),
4785 MemOperand(sp, 1 * kPointerSize));
4786 __ LoadP(LoadDescriptor::NameRegister(), MemOperand(sp, 0));
4787 EmitKeyedPropertyLoad(prop);
4796 // We need a second deoptimization point after loading the value
4797 // in case evaluating the property load my have a side effect.
4798 if (assign_type == VARIABLE) {
4799 PrepareForBailout(expr->expression(), TOS_REG);
4801 PrepareForBailoutForId(prop->LoadId(), TOS_REG);
4804 // Inline smi case if we are in a loop.
4805 Label stub_call, done;
4806 JumpPatchSite patch_site(masm_);
4808 int count_value = expr->op() == Token::INC ? 1 : -1;
4809 if (ShouldInlineSmiCase(expr->op())) {
4811 patch_site.EmitJumpIfNotSmi(r3, &slow);
4813 // Save result for postfix expressions.
4814 if (expr->is_postfix()) {
4815 if (!context()->IsEffect()) {
4816 // Save the result on the stack. If we have a named or keyed property
4817 // we store the result under the receiver that is currently on top
4819 switch (assign_type) {
4823 case NAMED_PROPERTY:
4824 __ StoreP(r3, MemOperand(sp, kPointerSize));
4826 case NAMED_SUPER_PROPERTY:
4827 __ StoreP(r3, MemOperand(sp, 2 * kPointerSize));
4829 case KEYED_PROPERTY:
4830 __ StoreP(r3, MemOperand(sp, 2 * kPointerSize));
4832 case KEYED_SUPER_PROPERTY:
4833 __ StoreP(r3, MemOperand(sp, 3 * kPointerSize));
4839 Register scratch1 = r4;
4840 Register scratch2 = r5;
4841 __ LoadSmiLiteral(scratch1, Smi::FromInt(count_value));
4842 __ AddAndCheckForOverflow(r3, r3, scratch1, scratch2, r0);
4843 __ BranchOnNoOverflow(&done);
4844 // Call stub. Undo operation first.
4845 __ sub(r3, r3, scratch1);
4849 if (!is_strong(language_mode())) {
4850 ToNumberStub convert_stub(isolate());
4851 __ CallStub(&convert_stub);
4852 PrepareForBailoutForId(expr->ToNumberId(), TOS_REG);
4855 // Save result for postfix expressions.
4856 if (expr->is_postfix()) {
4857 if (!context()->IsEffect()) {
4858 // Save the result on the stack. If we have a named or keyed property
4859 // we store the result under the receiver that is currently on top
4861 switch (assign_type) {
4865 case NAMED_PROPERTY:
4866 __ StoreP(r3, MemOperand(sp, kPointerSize));
4868 case NAMED_SUPER_PROPERTY:
4869 __ StoreP(r3, MemOperand(sp, 2 * kPointerSize));
4871 case KEYED_PROPERTY:
4872 __ StoreP(r3, MemOperand(sp, 2 * kPointerSize));
4874 case KEYED_SUPER_PROPERTY:
4875 __ StoreP(r3, MemOperand(sp, 3 * kPointerSize));
4881 __ bind(&stub_call);
4883 __ LoadSmiLiteral(r3, Smi::FromInt(count_value));
4885 SetExpressionPosition(expr);
4887 Handle<Code> code = CodeFactory::BinaryOpIC(isolate(), Token::ADD,
4888 strength(language_mode())).code();
4889 CallIC(code, expr->CountBinOpFeedbackId());
4890 patch_site.EmitPatchInfo();
4893 if (is_strong(language_mode())) {
4894 PrepareForBailoutForId(expr->ToNumberId(), TOS_REG);
4896 // Store the value returned in r3.
4897 switch (assign_type) {
4899 if (expr->is_postfix()) {
4901 EffectContext context(this);
4902 EmitVariableAssignment(expr->expression()->AsVariableProxy()->var(),
4903 Token::ASSIGN, expr->CountSlot());
4904 PrepareForBailoutForId(expr->AssignmentId(), TOS_REG);
4907 // For all contexts except EffectConstant We have the result on
4908 // top of the stack.
4909 if (!context()->IsEffect()) {
4910 context()->PlugTOS();
4913 EmitVariableAssignment(expr->expression()->AsVariableProxy()->var(),
4914 Token::ASSIGN, expr->CountSlot());
4915 PrepareForBailoutForId(expr->AssignmentId(), TOS_REG);
4916 context()->Plug(r3);
4919 case NAMED_PROPERTY: {
4920 __ mov(StoreDescriptor::NameRegister(),
4921 Operand(prop->key()->AsLiteral()->value()));
4922 __ pop(StoreDescriptor::ReceiverRegister());
4923 if (FLAG_vector_stores) {
4924 EmitLoadStoreICSlot(expr->CountSlot());
4927 CallStoreIC(expr->CountStoreFeedbackId());
4929 PrepareForBailoutForId(expr->AssignmentId(), TOS_REG);
4930 if (expr->is_postfix()) {
4931 if (!context()->IsEffect()) {
4932 context()->PlugTOS();
4935 context()->Plug(r3);
4939 case NAMED_SUPER_PROPERTY: {
4940 EmitNamedSuperPropertyStore(prop);
4941 if (expr->is_postfix()) {
4942 if (!context()->IsEffect()) {
4943 context()->PlugTOS();
4946 context()->Plug(r3);
4950 case KEYED_SUPER_PROPERTY: {
4951 EmitKeyedSuperPropertyStore(prop);
4952 if (expr->is_postfix()) {
4953 if (!context()->IsEffect()) {
4954 context()->PlugTOS();
4957 context()->Plug(r3);
4961 case KEYED_PROPERTY: {
4962 __ Pop(StoreDescriptor::ReceiverRegister(),
4963 StoreDescriptor::NameRegister());
4965 CodeFactory::KeyedStoreIC(isolate(), language_mode()).code();
4966 if (FLAG_vector_stores) {
4967 EmitLoadStoreICSlot(expr->CountSlot());
4970 CallIC(ic, expr->CountStoreFeedbackId());
4972 PrepareForBailoutForId(expr->AssignmentId(), TOS_REG);
4973 if (expr->is_postfix()) {
4974 if (!context()->IsEffect()) {
4975 context()->PlugTOS();
4978 context()->Plug(r3);
4986 void FullCodeGenerator::EmitLiteralCompareTypeof(Expression* expr,
4987 Expression* sub_expr,
4988 Handle<String> check) {
4989 Label materialize_true, materialize_false;
4990 Label* if_true = NULL;
4991 Label* if_false = NULL;
4992 Label* fall_through = NULL;
4993 context()->PrepareTest(&materialize_true, &materialize_false, &if_true,
4994 &if_false, &fall_through);
4997 AccumulatorValueContext context(this);
4998 VisitForTypeofValue(sub_expr);
5000 PrepareForBailoutBeforeSplit(expr, true, if_true, if_false);
5002 Factory* factory = isolate()->factory();
5003 if (String::Equals(check, factory->number_string())) {
5004 __ JumpIfSmi(r3, if_true);
5005 __ LoadP(r3, FieldMemOperand(r3, HeapObject::kMapOffset));
5006 __ LoadRoot(ip, Heap::kHeapNumberMapRootIndex);
5008 Split(eq, if_true, if_false, fall_through);
5009 } else if (String::Equals(check, factory->string_string())) {
5010 __ JumpIfSmi(r3, if_false);
5011 // Check for undetectable objects => false.
5012 __ CompareObjectType(r3, r3, r4, FIRST_NONSTRING_TYPE);
5014 __ lbz(r4, FieldMemOperand(r3, Map::kBitFieldOffset));
5015 STATIC_ASSERT((1 << Map::kIsUndetectable) < 0x8000);
5016 __ andi(r0, r4, Operand(1 << Map::kIsUndetectable));
5017 Split(eq, if_true, if_false, fall_through, cr0);
5018 } else if (String::Equals(check, factory->symbol_string())) {
5019 __ JumpIfSmi(r3, if_false);
5020 __ CompareObjectType(r3, r3, r4, SYMBOL_TYPE);
5021 Split(eq, if_true, if_false, fall_through);
5022 } else if (String::Equals(check, factory->float32x4_string())) {
5023 __ JumpIfSmi(r3, if_false);
5024 __ CompareObjectType(r3, r3, r4, FLOAT32X4_TYPE);
5025 Split(eq, if_true, if_false, fall_through);
5026 } else if (String::Equals(check, factory->int32x4_string())) {
5027 __ JumpIfSmi(r3, if_false);
5028 __ CompareObjectType(r3, r3, r4, INT32X4_TYPE);
5029 Split(eq, if_true, if_false, fall_through);
5030 } else if (String::Equals(check, factory->bool32x4_string())) {
5031 __ JumpIfSmi(r3, if_false);
5032 __ CompareObjectType(r3, r3, r4, BOOL32X4_TYPE);
5033 Split(eq, if_true, if_false, fall_through);
5034 } else if (String::Equals(check, factory->int16x8_string())) {
5035 __ JumpIfSmi(r3, if_false);
5036 __ CompareObjectType(r3, r3, r4, INT16X8_TYPE);
5037 Split(eq, if_true, if_false, fall_through);
5038 } else if (String::Equals(check, factory->bool16x8_string())) {
5039 __ JumpIfSmi(r3, if_false);
5040 __ CompareObjectType(r3, r3, r4, BOOL16X8_TYPE);
5041 Split(eq, if_true, if_false, fall_through);
5042 } else if (String::Equals(check, factory->int8x16_string())) {
5043 __ JumpIfSmi(r3, if_false);
5044 __ CompareObjectType(r3, r3, r4, INT8X16_TYPE);
5045 Split(eq, if_true, if_false, fall_through);
5046 } else if (String::Equals(check, factory->bool8x16_string())) {
5047 __ JumpIfSmi(r3, if_false);
5048 __ CompareObjectType(r3, r3, r4, BOOL8X16_TYPE);
5049 Split(eq, if_true, if_false, fall_through);
5050 } else if (String::Equals(check, factory->boolean_string())) {
5051 __ CompareRoot(r3, Heap::kTrueValueRootIndex);
5053 __ CompareRoot(r3, Heap::kFalseValueRootIndex);
5054 Split(eq, if_true, if_false, fall_through);
5055 } else if (String::Equals(check, factory->undefined_string())) {
5056 __ CompareRoot(r3, Heap::kUndefinedValueRootIndex);
5058 __ JumpIfSmi(r3, if_false);
5059 // Check for undetectable objects => true.
5060 __ LoadP(r3, FieldMemOperand(r3, HeapObject::kMapOffset));
5061 __ lbz(r4, FieldMemOperand(r3, Map::kBitFieldOffset));
5062 __ andi(r0, r4, Operand(1 << Map::kIsUndetectable));
5063 Split(ne, if_true, if_false, fall_through, cr0);
5065 } else if (String::Equals(check, factory->function_string())) {
5066 __ JumpIfSmi(r3, if_false);
5067 STATIC_ASSERT(NUM_OF_CALLABLE_SPEC_OBJECT_TYPES == 2);
5068 __ CompareObjectType(r3, r3, r4, JS_FUNCTION_TYPE);
5070 __ cmpi(r4, Operand(JS_FUNCTION_PROXY_TYPE));
5071 Split(eq, if_true, if_false, fall_through);
5072 } else if (String::Equals(check, factory->object_string())) {
5073 __ JumpIfSmi(r3, if_false);
5074 __ CompareRoot(r3, Heap::kNullValueRootIndex);
5076 // Check for JS objects => true.
5077 __ CompareObjectType(r3, r3, r4, FIRST_NONCALLABLE_SPEC_OBJECT_TYPE);
5079 __ CompareInstanceType(r3, r4, LAST_NONCALLABLE_SPEC_OBJECT_TYPE);
5081 // Check for undetectable objects => false.
5082 __ lbz(r4, FieldMemOperand(r3, Map::kBitFieldOffset));
5083 __ andi(r0, r4, Operand(1 << Map::kIsUndetectable));
5084 Split(eq, if_true, if_false, fall_through, cr0);
5086 if (if_false != fall_through) __ b(if_false);
5088 context()->Plug(if_true, if_false);
5092 void FullCodeGenerator::VisitCompareOperation(CompareOperation* expr) {
5093 Comment cmnt(masm_, "[ CompareOperation");
5094 SetExpressionPosition(expr);
5096 // First we try a fast inlined version of the compare when one of
5097 // the operands is a literal.
5098 if (TryLiteralCompare(expr)) return;
5100 // Always perform the comparison for its control flow. Pack the result
5101 // into the expression's context after the comparison is performed.
5102 Label materialize_true, materialize_false;
5103 Label* if_true = NULL;
5104 Label* if_false = NULL;
5105 Label* fall_through = NULL;
5106 context()->PrepareTest(&materialize_true, &materialize_false, &if_true,
5107 &if_false, &fall_through);
5109 Token::Value op = expr->op();
5110 VisitForStackValue(expr->left());
5113 VisitForStackValue(expr->right());
5114 __ CallRuntime(Runtime::kHasProperty, 2);
5115 PrepareForBailoutBeforeSplit(expr, false, NULL, NULL);
5116 __ LoadRoot(ip, Heap::kTrueValueRootIndex);
5118 Split(eq, if_true, if_false, fall_through);
5121 case Token::INSTANCEOF: {
5122 VisitForStackValue(expr->right());
5123 InstanceofStub stub(isolate(), InstanceofStub::kNoFlags);
5125 PrepareForBailoutBeforeSplit(expr, true, if_true, if_false);
5126 // The stub returns 0 for true.
5127 __ cmpi(r3, Operand::Zero());
5128 Split(eq, if_true, if_false, fall_through);
5133 VisitForAccumulatorValue(expr->right());
5134 Condition cond = CompareIC::ComputeCondition(op);
5137 bool inline_smi_code = ShouldInlineSmiCase(op);
5138 JumpPatchSite patch_site(masm_);
5139 if (inline_smi_code) {
5142 patch_site.EmitJumpIfNotSmi(r5, &slow_case);
5144 Split(cond, if_true, if_false, NULL);
5145 __ bind(&slow_case);
5148 Handle<Code> ic = CodeFactory::CompareIC(
5149 isolate(), op, strength(language_mode())).code();
5150 CallIC(ic, expr->CompareOperationFeedbackId());
5151 patch_site.EmitPatchInfo();
5152 PrepareForBailoutBeforeSplit(expr, true, if_true, if_false);
5153 __ cmpi(r3, Operand::Zero());
5154 Split(cond, if_true, if_false, fall_through);
5158 // Convert the result of the comparison into one expected for this
5159 // expression's context.
5160 context()->Plug(if_true, if_false);
5164 void FullCodeGenerator::EmitLiteralCompareNil(CompareOperation* expr,
5165 Expression* sub_expr,
5167 Label materialize_true, materialize_false;
5168 Label* if_true = NULL;
5169 Label* if_false = NULL;
5170 Label* fall_through = NULL;
5171 context()->PrepareTest(&materialize_true, &materialize_false, &if_true,
5172 &if_false, &fall_through);
5174 VisitForAccumulatorValue(sub_expr);
5175 PrepareForBailoutBeforeSplit(expr, true, if_true, if_false);
5176 if (expr->op() == Token::EQ_STRICT) {
5177 Heap::RootListIndex nil_value = nil == kNullValue
5178 ? Heap::kNullValueRootIndex
5179 : Heap::kUndefinedValueRootIndex;
5180 __ LoadRoot(r4, nil_value);
5182 Split(eq, if_true, if_false, fall_through);
5184 Handle<Code> ic = CompareNilICStub::GetUninitialized(isolate(), nil);
5185 CallIC(ic, expr->CompareOperationFeedbackId());
5186 __ cmpi(r3, Operand::Zero());
5187 Split(ne, if_true, if_false, fall_through);
5189 context()->Plug(if_true, if_false);
5193 void FullCodeGenerator::VisitThisFunction(ThisFunction* expr) {
5194 __ LoadP(r3, MemOperand(fp, JavaScriptFrameConstants::kFunctionOffset));
5195 context()->Plug(r3);
5199 Register FullCodeGenerator::result_register() { return r3; }
5202 Register FullCodeGenerator::context_register() { return cp; }
5205 void FullCodeGenerator::StoreToFrameField(int frame_offset, Register value) {
5206 DCHECK_EQ(static_cast<int>(POINTER_SIZE_ALIGN(frame_offset)), frame_offset);
5207 __ StoreP(value, MemOperand(fp, frame_offset), r0);
5211 void FullCodeGenerator::LoadContextField(Register dst, int context_index) {
5212 __ LoadP(dst, ContextOperand(cp, context_index), r0);
5216 void FullCodeGenerator::PushFunctionArgumentForContextAllocation() {
5217 Scope* closure_scope = scope()->ClosureScope();
5218 if (closure_scope->is_script_scope() ||
5219 closure_scope->is_module_scope()) {
5220 // Contexts nested in the native context have a canonical empty function
5221 // as their closure, not the anonymous closure containing the global
5222 // code. Pass a smi sentinel and let the runtime look up the empty
5224 __ LoadSmiLiteral(ip, Smi::FromInt(0));
5225 } else if (closure_scope->is_eval_scope()) {
5226 // Contexts created by a call to eval have the same closure as the
5227 // context calling eval, not the anonymous closure containing the eval
5228 // code. Fetch it from the context.
5229 __ LoadP(ip, ContextOperand(cp, Context::CLOSURE_INDEX));
5231 DCHECK(closure_scope->is_function_scope());
5232 __ LoadP(ip, MemOperand(fp, JavaScriptFrameConstants::kFunctionOffset));
5238 // ----------------------------------------------------------------------------
5239 // Non-local control flow support.
5241 void FullCodeGenerator::EnterFinallyBlock() {
5242 DCHECK(!result_register().is(r4));
5243 // Store result register while executing finally block.
5244 __ push(result_register());
5245 // Cook return address in link register to stack (smi encoded Code* delta)
5247 __ mov(ip, Operand(masm_->CodeObject()));
5251 // Store result register while executing finally block.
5254 // Store pending message while executing finally block.
5255 ExternalReference pending_message_obj =
5256 ExternalReference::address_of_pending_message_obj(isolate());
5257 __ mov(ip, Operand(pending_message_obj));
5258 __ LoadP(r4, MemOperand(ip));
5261 ClearPendingMessage();
5265 void FullCodeGenerator::ExitFinallyBlock() {
5266 DCHECK(!result_register().is(r4));
5267 // Restore pending message from stack.
5269 ExternalReference pending_message_obj =
5270 ExternalReference::address_of_pending_message_obj(isolate());
5271 __ mov(ip, Operand(pending_message_obj));
5272 __ StoreP(r4, MemOperand(ip));
5274 // Restore result register from stack.
5277 // Uncook return address and return.
5278 __ pop(result_register());
5280 __ mov(ip, Operand(masm_->CodeObject()));
5287 void FullCodeGenerator::ClearPendingMessage() {
5288 DCHECK(!result_register().is(r4));
5289 ExternalReference pending_message_obj =
5290 ExternalReference::address_of_pending_message_obj(isolate());
5291 __ LoadRoot(r4, Heap::kTheHoleValueRootIndex);
5292 __ mov(ip, Operand(pending_message_obj));
5293 __ StoreP(r4, MemOperand(ip));
5297 void FullCodeGenerator::EmitLoadStoreICSlot(FeedbackVectorICSlot slot) {
5298 DCHECK(FLAG_vector_stores && !slot.IsInvalid());
5299 __ mov(VectorStoreICTrampolineDescriptor::SlotRegister(),
5300 Operand(SmiFromSlot(slot)));
5307 void BackEdgeTable::PatchAt(Code* unoptimized_code, Address pc,
5308 BackEdgeState target_state,
5309 Code* replacement_code) {
5310 Address mov_address = Assembler::target_address_from_return_address(pc);
5311 Address cmp_address = mov_address - 2 * Assembler::kInstrSize;
5312 CodePatcher patcher(cmp_address, 1);
5314 switch (target_state) {
5316 // <decrement profiling counter>
5318 // bge <ok> ;; not changed
5319 // mov r12, <interrupt stub address>
5322 // <reset profiling counter>
5324 patcher.masm()->cmpi(r6, Operand::Zero());
5327 case ON_STACK_REPLACEMENT:
5328 case OSR_AFTER_STACK_CHECK:
5329 // <decrement profiling counter>
5331 // bge <ok> ;; not changed
5332 // mov r12, <on-stack replacement address>
5335 // <reset profiling counter>
5336 // ok-label ----- pc_after points here
5338 // Set the LT bit such that bge is a NOP
5339 patcher.masm()->crset(Assembler::encode_crbit(cr7, CR_LT));
5343 // Replace the stack check address in the mov sequence with the
5344 // entry address of the replacement code.
5345 Assembler::set_target_address_at(mov_address, unoptimized_code,
5346 replacement_code->entry());
5348 unoptimized_code->GetHeap()->incremental_marking()->RecordCodeTargetPatch(
5349 unoptimized_code, mov_address, replacement_code);
5353 BackEdgeTable::BackEdgeState BackEdgeTable::GetBackEdgeState(
5354 Isolate* isolate, Code* unoptimized_code, Address pc) {
5355 Address mov_address = Assembler::target_address_from_return_address(pc);
5356 Address cmp_address = mov_address - 2 * Assembler::kInstrSize;
5357 Address interrupt_address =
5358 Assembler::target_address_at(mov_address, unoptimized_code);
5360 if (Assembler::IsCmpImmediate(Assembler::instr_at(cmp_address))) {
5361 DCHECK(interrupt_address == isolate->builtins()->InterruptCheck()->entry());
5365 DCHECK(Assembler::IsCrSet(Assembler::instr_at(cmp_address)));
5367 if (interrupt_address == isolate->builtins()->OnStackReplacement()->entry()) {
5368 return ON_STACK_REPLACEMENT;
5371 DCHECK(interrupt_address ==
5372 isolate->builtins()->OsrAfterStackCheck()->entry());
5373 return OSR_AFTER_STACK_CHECK;
5375 } // namespace internal
5377 #endif // V8_TARGET_ARCH_PPC