1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "src/arm/lithium-codegen-arm.h"
6 #include "src/arm/lithium-gap-resolver-arm.h"
7 #include "src/base/bits.h"
8 #include "src/code-factory.h"
9 #include "src/code-stubs.h"
10 #include "src/cpu-profiler.h"
11 #include "src/hydrogen-osr.h"
12 #include "src/ic/ic.h"
13 #include "src/ic/stub-cache.h"
19 class SafepointGenerator final : public CallWrapper {
21 SafepointGenerator(LCodeGen* codegen,
22 LPointerMap* pointers,
23 Safepoint::DeoptMode mode)
27 virtual ~SafepointGenerator() {}
29 void BeforeCall(int call_size) const override {}
31 void AfterCall() const override {
32 codegen_->RecordSafepoint(pointers_, deopt_mode_);
37 LPointerMap* pointers_;
38 Safepoint::DeoptMode deopt_mode_;
44 bool LCodeGen::GenerateCode() {
45 LPhase phase("Z_Code generation", chunk());
49 // Open a frame scope to indicate that there is a frame on the stack. The
50 // NONE indicates that the scope shouldn't actually generate code to set up
51 // the frame (that is done in GeneratePrologue).
52 FrameScope frame_scope(masm_, StackFrame::NONE);
54 return GeneratePrologue() && GenerateBody() && GenerateDeferredCode() &&
55 GenerateJumpTable() && GenerateSafepointTable();
59 void LCodeGen::FinishCode(Handle<Code> code) {
61 code->set_stack_slots(GetStackSlotCount());
62 code->set_safepoint_table_offset(safepoints_.GetCodeOffset());
63 PopulateDeoptimizationData(code);
67 void LCodeGen::SaveCallerDoubles() {
68 DCHECK(info()->saves_caller_doubles());
69 DCHECK(NeedsEagerFrame());
70 Comment(";;; Save clobbered callee double registers");
72 BitVector* doubles = chunk()->allocated_double_registers();
73 BitVector::Iterator save_iterator(doubles);
74 while (!save_iterator.Done()) {
75 __ vstr(DwVfpRegister::FromAllocationIndex(save_iterator.Current()),
76 MemOperand(sp, count * kDoubleSize));
77 save_iterator.Advance();
83 void LCodeGen::RestoreCallerDoubles() {
84 DCHECK(info()->saves_caller_doubles());
85 DCHECK(NeedsEagerFrame());
86 Comment(";;; Restore clobbered callee double registers");
87 BitVector* doubles = chunk()->allocated_double_registers();
88 BitVector::Iterator save_iterator(doubles);
90 while (!save_iterator.Done()) {
91 __ vldr(DwVfpRegister::FromAllocationIndex(save_iterator.Current()),
92 MemOperand(sp, count * kDoubleSize));
93 save_iterator.Advance();
99 bool LCodeGen::GeneratePrologue() {
100 DCHECK(is_generating());
102 if (info()->IsOptimizing()) {
103 ProfileEntryHookStub::MaybeCallEntryHook(masm_);
106 if (strlen(FLAG_stop_at) > 0 &&
107 info_->literal()->name()->IsUtf8EqualTo(CStrVector(FLAG_stop_at))) {
112 // r1: Callee's JS function.
113 // cp: Callee's context.
114 // pp: Callee's constant pool pointer (if enabled)
115 // fp: Caller's frame pointer.
118 // Sloppy mode functions and builtins need to replace the receiver with the
119 // global proxy when called as functions (without an explicit receiver
121 if (info()->MustReplaceUndefinedReceiverWithGlobalProxy()) {
123 int receiver_offset = info_->scope()->num_parameters() * kPointerSize;
124 __ ldr(r2, MemOperand(sp, receiver_offset));
125 __ CompareRoot(r2, Heap::kUndefinedValueRootIndex);
128 __ ldr(r2, GlobalObjectOperand());
129 __ ldr(r2, FieldMemOperand(r2, GlobalObject::kGlobalProxyOffset));
131 __ str(r2, MemOperand(sp, receiver_offset));
137 info()->set_prologue_offset(masm_->pc_offset());
138 if (NeedsEagerFrame()) {
139 if (info()->IsStub()) {
142 __ Prologue(info()->IsCodePreAgingActive());
144 frame_is_built_ = true;
145 info_->AddNoFrameRange(0, masm_->pc_offset());
148 // Reserve space for the stack slots needed by the code.
149 int slots = GetStackSlotCount();
151 if (FLAG_debug_code) {
152 __ sub(sp, sp, Operand(slots * kPointerSize));
155 __ add(r0, sp, Operand(slots * kPointerSize));
156 __ mov(r1, Operand(kSlotsZapValue));
159 __ sub(r0, r0, Operand(kPointerSize));
160 __ str(r1, MemOperand(r0, 2 * kPointerSize));
166 __ sub(sp, sp, Operand(slots * kPointerSize));
170 if (info()->saves_caller_doubles()) {
173 return !is_aborted();
177 void LCodeGen::DoPrologue(LPrologue* instr) {
178 Comment(";;; Prologue begin");
180 // Possibly allocate a local context.
181 if (info()->scope()->num_heap_slots() > 0) {
182 Comment(";;; Allocate local context");
183 bool need_write_barrier = true;
184 // Argument to NewContext is the function, which is in r1.
185 int slots = info()->scope()->num_heap_slots() - Context::MIN_CONTEXT_SLOTS;
186 Safepoint::DeoptMode deopt_mode = Safepoint::kNoLazyDeopt;
187 if (info()->scope()->is_script_scope()) {
189 __ Push(info()->scope()->GetScopeInfo(info()->isolate()));
190 __ CallRuntime(Runtime::kNewScriptContext, 2);
191 deopt_mode = Safepoint::kLazyDeopt;
192 } else if (slots <= FastNewContextStub::kMaximumSlots) {
193 FastNewContextStub stub(isolate(), slots);
195 // Result of FastNewContextStub is always in new space.
196 need_write_barrier = false;
199 __ CallRuntime(Runtime::kNewFunctionContext, 1);
201 RecordSafepoint(deopt_mode);
203 // Context is returned in both r0 and cp. It replaces the context
204 // passed to us. It's saved in the stack and kept live in cp.
206 __ str(r0, MemOperand(fp, StandardFrameConstants::kContextOffset));
207 // Copy any necessary parameters into the context.
208 int num_parameters = scope()->num_parameters();
209 int first_parameter = scope()->has_this_declaration() ? -1 : 0;
210 for (int i = first_parameter; i < num_parameters; i++) {
211 Variable* var = (i == -1) ? scope()->receiver() : scope()->parameter(i);
212 if (var->IsContextSlot()) {
213 int parameter_offset = StandardFrameConstants::kCallerSPOffset +
214 (num_parameters - 1 - i) * kPointerSize;
215 // Load parameter from stack.
216 __ ldr(r0, MemOperand(fp, parameter_offset));
217 // Store it in the context.
218 MemOperand target = ContextOperand(cp, var->index());
220 // Update the write barrier. This clobbers r3 and r0.
221 if (need_write_barrier) {
222 __ RecordWriteContextSlot(
227 GetLinkRegisterState(),
229 } else if (FLAG_debug_code) {
231 __ JumpIfInNewSpace(cp, r0, &done);
232 __ Abort(kExpectedNewSpaceObject);
237 Comment(";;; End allocate local context");
240 Comment(";;; Prologue end");
244 void LCodeGen::GenerateOsrPrologue() {
245 // Generate the OSR entry prologue at the first unknown OSR value, or if there
246 // are none, at the OSR entrypoint instruction.
247 if (osr_pc_offset_ >= 0) return;
249 osr_pc_offset_ = masm()->pc_offset();
251 // Adjust the frame size, subsuming the unoptimized frame into the
253 int slots = GetStackSlotCount() - graph()->osr()->UnoptimizedFrameSlots();
255 __ sub(sp, sp, Operand(slots * kPointerSize));
259 void LCodeGen::GenerateBodyInstructionPre(LInstruction* instr) {
260 if (instr->IsCall()) {
261 EnsureSpaceForLazyDeopt(Deoptimizer::patch_size());
263 if (!instr->IsLazyBailout() && !instr->IsGap()) {
264 safepoints_.BumpLastLazySafepointIndex();
269 bool LCodeGen::GenerateDeferredCode() {
270 DCHECK(is_generating());
271 if (deferred_.length() > 0) {
272 for (int i = 0; !is_aborted() && i < deferred_.length(); i++) {
273 LDeferredCode* code = deferred_[i];
276 instructions_->at(code->instruction_index())->hydrogen_value();
277 RecordAndWritePosition(
278 chunk()->graph()->SourcePositionToScriptPosition(value->position()));
280 Comment(";;; <@%d,#%d> "
281 "-------------------- Deferred %s --------------------",
282 code->instruction_index(),
283 code->instr()->hydrogen_value()->id(),
284 code->instr()->Mnemonic());
285 __ bind(code->entry());
286 if (NeedsDeferredFrame()) {
287 Comment(";;; Build frame");
288 DCHECK(!frame_is_built_);
289 DCHECK(info()->IsStub());
290 frame_is_built_ = true;
292 __ mov(scratch0(), Operand(Smi::FromInt(StackFrame::STUB)));
294 __ add(fp, sp, Operand(StandardFrameConstants::kFixedFrameSizeFromFp));
295 Comment(";;; Deferred code");
298 if (NeedsDeferredFrame()) {
299 Comment(";;; Destroy frame");
300 DCHECK(frame_is_built_);
303 frame_is_built_ = false;
305 __ jmp(code->exit());
309 // Force constant pool emission at the end of the deferred code to make
310 // sure that no constant pools are emitted after.
311 masm()->CheckConstPool(true, false);
313 return !is_aborted();
317 bool LCodeGen::GenerateJumpTable() {
318 // Check that the jump table is accessible from everywhere in the function
319 // code, i.e. that offsets to the table can be encoded in the 24bit signed
320 // immediate of a branch instruction.
321 // To simplify we consider the code size from the first instruction to the
322 // end of the jump table. We also don't consider the pc load delta.
323 // Each entry in the jump table generates one instruction and inlines one
324 // 32bit data after it.
325 if (!is_int24((masm()->pc_offset() / Assembler::kInstrSize) +
326 jump_table_.length() * 7)) {
327 Abort(kGeneratedCodeIsTooLarge);
330 if (jump_table_.length() > 0) {
331 Label needs_frame, call_deopt_entry;
333 Comment(";;; -------------------- Jump table --------------------");
334 Address base = jump_table_[0].address;
336 Register entry_offset = scratch0();
338 int length = jump_table_.length();
339 for (int i = 0; i < length; i++) {
340 Deoptimizer::JumpTableEntry* table_entry = &jump_table_[i];
341 __ bind(&table_entry->label);
343 DCHECK_EQ(jump_table_[0].bailout_type, table_entry->bailout_type);
344 Address entry = table_entry->address;
345 DeoptComment(table_entry->deopt_info);
347 // Second-level deopt table entries are contiguous and small, so instead
348 // of loading the full, absolute address of each one, load an immediate
349 // offset which will be added to the base address later.
350 __ mov(entry_offset, Operand(entry - base));
352 if (table_entry->needs_frame) {
353 DCHECK(!info()->saves_caller_doubles());
354 Comment(";;; call deopt with frame");
358 __ bl(&call_deopt_entry);
360 info()->LogDeoptCallPosition(masm()->pc_offset(),
361 table_entry->deopt_info.inlining_id);
362 masm()->CheckConstPool(false, false);
365 if (needs_frame.is_linked()) {
366 __ bind(&needs_frame);
367 // This variant of deopt can only be used with stubs. Since we don't
368 // have a function pointer to install in the stack frame that we're
369 // building, install a special marker there instead.
370 DCHECK(info()->IsStub());
371 __ mov(ip, Operand(Smi::FromInt(StackFrame::STUB)));
373 __ add(fp, sp, Operand(StandardFrameConstants::kFixedFrameSizeFromFp));
376 Comment(";;; call deopt");
377 __ bind(&call_deopt_entry);
379 if (info()->saves_caller_doubles()) {
380 DCHECK(info()->IsStub());
381 RestoreCallerDoubles();
384 // Add the base address to the offset previously loaded in entry_offset.
385 __ add(entry_offset, entry_offset,
386 Operand(ExternalReference::ForDeoptEntry(base)));
390 // Force constant pool emission at the end of the deopt jump table to make
391 // sure that no constant pools are emitted after.
392 masm()->CheckConstPool(true, false);
394 // The deoptimization jump table is the last part of the instruction
395 // sequence. Mark the generated code as done unless we bailed out.
396 if (!is_aborted()) status_ = DONE;
397 return !is_aborted();
401 bool LCodeGen::GenerateSafepointTable() {
403 safepoints_.Emit(masm(), GetStackSlotCount());
404 return !is_aborted();
408 Register LCodeGen::ToRegister(int index) const {
409 return Register::FromAllocationIndex(index);
413 DwVfpRegister LCodeGen::ToDoubleRegister(int index) const {
414 return DwVfpRegister::FromAllocationIndex(index);
418 Register LCodeGen::ToRegister(LOperand* op) const {
419 DCHECK(op->IsRegister());
420 return ToRegister(op->index());
424 Register LCodeGen::EmitLoadRegister(LOperand* op, Register scratch) {
425 if (op->IsRegister()) {
426 return ToRegister(op->index());
427 } else if (op->IsConstantOperand()) {
428 LConstantOperand* const_op = LConstantOperand::cast(op);
429 HConstant* constant = chunk_->LookupConstant(const_op);
430 Handle<Object> literal = constant->handle(isolate());
431 Representation r = chunk_->LookupLiteralRepresentation(const_op);
432 if (r.IsInteger32()) {
433 AllowDeferredHandleDereference get_number;
434 DCHECK(literal->IsNumber());
435 __ mov(scratch, Operand(static_cast<int32_t>(literal->Number())));
436 } else if (r.IsDouble()) {
437 Abort(kEmitLoadRegisterUnsupportedDoubleImmediate);
439 DCHECK(r.IsSmiOrTagged());
440 __ Move(scratch, literal);
443 } else if (op->IsStackSlot()) {
444 __ ldr(scratch, ToMemOperand(op));
452 DwVfpRegister LCodeGen::ToDoubleRegister(LOperand* op) const {
453 DCHECK(op->IsDoubleRegister());
454 return ToDoubleRegister(op->index());
458 DwVfpRegister LCodeGen::EmitLoadDoubleRegister(LOperand* op,
459 SwVfpRegister flt_scratch,
460 DwVfpRegister dbl_scratch) {
461 if (op->IsDoubleRegister()) {
462 return ToDoubleRegister(op->index());
463 } else if (op->IsConstantOperand()) {
464 LConstantOperand* const_op = LConstantOperand::cast(op);
465 HConstant* constant = chunk_->LookupConstant(const_op);
466 Handle<Object> literal = constant->handle(isolate());
467 Representation r = chunk_->LookupLiteralRepresentation(const_op);
468 if (r.IsInteger32()) {
469 DCHECK(literal->IsNumber());
470 __ mov(ip, Operand(static_cast<int32_t>(literal->Number())));
471 __ vmov(flt_scratch, ip);
472 __ vcvt_f64_s32(dbl_scratch, flt_scratch);
474 } else if (r.IsDouble()) {
475 Abort(kUnsupportedDoubleImmediate);
476 } else if (r.IsTagged()) {
477 Abort(kUnsupportedTaggedImmediate);
479 } else if (op->IsStackSlot()) {
480 // TODO(regis): Why is vldr not taking a MemOperand?
481 // __ vldr(dbl_scratch, ToMemOperand(op));
482 MemOperand mem_op = ToMemOperand(op);
483 __ vldr(dbl_scratch, mem_op.rn(), mem_op.offset());
491 Handle<Object> LCodeGen::ToHandle(LConstantOperand* op) const {
492 HConstant* constant = chunk_->LookupConstant(op);
493 DCHECK(chunk_->LookupLiteralRepresentation(op).IsSmiOrTagged());
494 return constant->handle(isolate());
498 bool LCodeGen::IsInteger32(LConstantOperand* op) const {
499 return chunk_->LookupLiteralRepresentation(op).IsSmiOrInteger32();
503 bool LCodeGen::IsSmi(LConstantOperand* op) const {
504 return chunk_->LookupLiteralRepresentation(op).IsSmi();
508 int32_t LCodeGen::ToInteger32(LConstantOperand* op) const {
509 return ToRepresentation(op, Representation::Integer32());
513 int32_t LCodeGen::ToRepresentation(LConstantOperand* op,
514 const Representation& r) const {
515 HConstant* constant = chunk_->LookupConstant(op);
516 int32_t value = constant->Integer32Value();
517 if (r.IsInteger32()) return value;
518 DCHECK(r.IsSmiOrTagged());
519 return reinterpret_cast<int32_t>(Smi::FromInt(value));
523 Smi* LCodeGen::ToSmi(LConstantOperand* op) const {
524 HConstant* constant = chunk_->LookupConstant(op);
525 return Smi::FromInt(constant->Integer32Value());
529 double LCodeGen::ToDouble(LConstantOperand* op) const {
530 HConstant* constant = chunk_->LookupConstant(op);
531 DCHECK(constant->HasDoubleValue());
532 return constant->DoubleValue();
536 Operand LCodeGen::ToOperand(LOperand* op) {
537 if (op->IsConstantOperand()) {
538 LConstantOperand* const_op = LConstantOperand::cast(op);
539 HConstant* constant = chunk()->LookupConstant(const_op);
540 Representation r = chunk_->LookupLiteralRepresentation(const_op);
542 DCHECK(constant->HasSmiValue());
543 return Operand(Smi::FromInt(constant->Integer32Value()));
544 } else if (r.IsInteger32()) {
545 DCHECK(constant->HasInteger32Value());
546 return Operand(constant->Integer32Value());
547 } else if (r.IsDouble()) {
548 Abort(kToOperandUnsupportedDoubleImmediate);
550 DCHECK(r.IsTagged());
551 return Operand(constant->handle(isolate()));
552 } else if (op->IsRegister()) {
553 return Operand(ToRegister(op));
554 } else if (op->IsDoubleRegister()) {
555 Abort(kToOperandIsDoubleRegisterUnimplemented);
556 return Operand::Zero();
558 // Stack slots not implemented, use ToMemOperand instead.
560 return Operand::Zero();
564 static int ArgumentsOffsetWithoutFrame(int index) {
566 return -(index + 1) * kPointerSize;
570 MemOperand LCodeGen::ToMemOperand(LOperand* op) const {
571 DCHECK(!op->IsRegister());
572 DCHECK(!op->IsDoubleRegister());
573 DCHECK(op->IsStackSlot() || op->IsDoubleStackSlot());
574 if (NeedsEagerFrame()) {
575 return MemOperand(fp, StackSlotOffset(op->index()));
577 // Retrieve parameter without eager stack-frame relative to the
579 return MemOperand(sp, ArgumentsOffsetWithoutFrame(op->index()));
584 MemOperand LCodeGen::ToHighMemOperand(LOperand* op) const {
585 DCHECK(op->IsDoubleStackSlot());
586 if (NeedsEagerFrame()) {
587 return MemOperand(fp, StackSlotOffset(op->index()) + kPointerSize);
589 // Retrieve parameter without eager stack-frame relative to the
592 sp, ArgumentsOffsetWithoutFrame(op->index()) + kPointerSize);
597 void LCodeGen::WriteTranslation(LEnvironment* environment,
598 Translation* translation) {
599 if (environment == NULL) return;
601 // The translation includes one command per value in the environment.
602 int translation_size = environment->translation_size();
604 WriteTranslation(environment->outer(), translation);
605 WriteTranslationFrame(environment, translation);
607 int object_index = 0;
608 int dematerialized_index = 0;
609 for (int i = 0; i < translation_size; ++i) {
610 LOperand* value = environment->values()->at(i);
612 environment, translation, value, environment->HasTaggedValueAt(i),
613 environment->HasUint32ValueAt(i), &object_index, &dematerialized_index);
618 void LCodeGen::AddToTranslation(LEnvironment* environment,
619 Translation* translation,
623 int* object_index_pointer,
624 int* dematerialized_index_pointer) {
625 if (op == LEnvironment::materialization_marker()) {
626 int object_index = (*object_index_pointer)++;
627 if (environment->ObjectIsDuplicateAt(object_index)) {
628 int dupe_of = environment->ObjectDuplicateOfAt(object_index);
629 translation->DuplicateObject(dupe_of);
632 int object_length = environment->ObjectLengthAt(object_index);
633 if (environment->ObjectIsArgumentsAt(object_index)) {
634 translation->BeginArgumentsObject(object_length);
636 translation->BeginCapturedObject(object_length);
638 int dematerialized_index = *dematerialized_index_pointer;
639 int env_offset = environment->translation_size() + dematerialized_index;
640 *dematerialized_index_pointer += object_length;
641 for (int i = 0; i < object_length; ++i) {
642 LOperand* value = environment->values()->at(env_offset + i);
643 AddToTranslation(environment,
646 environment->HasTaggedValueAt(env_offset + i),
647 environment->HasUint32ValueAt(env_offset + i),
648 object_index_pointer,
649 dematerialized_index_pointer);
654 if (op->IsStackSlot()) {
655 int index = op->index();
657 index += StandardFrameConstants::kFixedFrameSize / kPointerSize;
660 translation->StoreStackSlot(index);
661 } else if (is_uint32) {
662 translation->StoreUint32StackSlot(index);
664 translation->StoreInt32StackSlot(index);
666 } else if (op->IsDoubleStackSlot()) {
667 int index = op->index();
669 index += StandardFrameConstants::kFixedFrameSize / kPointerSize;
671 translation->StoreDoubleStackSlot(index);
672 } else if (op->IsRegister()) {
673 Register reg = ToRegister(op);
675 translation->StoreRegister(reg);
676 } else if (is_uint32) {
677 translation->StoreUint32Register(reg);
679 translation->StoreInt32Register(reg);
681 } else if (op->IsDoubleRegister()) {
682 DoubleRegister reg = ToDoubleRegister(op);
683 translation->StoreDoubleRegister(reg);
684 } else if (op->IsConstantOperand()) {
685 HConstant* constant = chunk()->LookupConstant(LConstantOperand::cast(op));
686 int src_index = DefineDeoptimizationLiteral(constant->handle(isolate()));
687 translation->StoreLiteral(src_index);
694 int LCodeGen::CallCodeSize(Handle<Code> code, RelocInfo::Mode mode) {
695 int size = masm()->CallSize(code, mode);
696 if (code->kind() == Code::BINARY_OP_IC ||
697 code->kind() == Code::COMPARE_IC) {
698 size += Assembler::kInstrSize; // extra nop() added in CallCodeGeneric.
704 void LCodeGen::CallCode(Handle<Code> code,
705 RelocInfo::Mode mode,
707 TargetAddressStorageMode storage_mode) {
708 CallCodeGeneric(code, mode, instr, RECORD_SIMPLE_SAFEPOINT, storage_mode);
712 void LCodeGen::CallCodeGeneric(Handle<Code> code,
713 RelocInfo::Mode mode,
715 SafepointMode safepoint_mode,
716 TargetAddressStorageMode storage_mode) {
717 DCHECK(instr != NULL);
718 // Block literal pool emission to ensure nop indicating no inlined smi code
719 // is in the correct position.
720 Assembler::BlockConstPoolScope block_const_pool(masm());
721 __ Call(code, mode, TypeFeedbackId::None(), al, storage_mode);
722 RecordSafepointWithLazyDeopt(instr, safepoint_mode);
724 // Signal that we don't inline smi code before these stubs in the
725 // optimizing code generator.
726 if (code->kind() == Code::BINARY_OP_IC ||
727 code->kind() == Code::COMPARE_IC) {
733 void LCodeGen::CallRuntime(const Runtime::Function* function,
736 SaveFPRegsMode save_doubles) {
737 DCHECK(instr != NULL);
739 __ CallRuntime(function, num_arguments, save_doubles);
741 RecordSafepointWithLazyDeopt(instr, RECORD_SIMPLE_SAFEPOINT);
745 void LCodeGen::LoadContextFromDeferred(LOperand* context) {
746 if (context->IsRegister()) {
747 __ Move(cp, ToRegister(context));
748 } else if (context->IsStackSlot()) {
749 __ ldr(cp, ToMemOperand(context));
750 } else if (context->IsConstantOperand()) {
751 HConstant* constant =
752 chunk_->LookupConstant(LConstantOperand::cast(context));
753 __ Move(cp, Handle<Object>::cast(constant->handle(isolate())));
760 void LCodeGen::CallRuntimeFromDeferred(Runtime::FunctionId id,
764 LoadContextFromDeferred(context);
765 __ CallRuntimeSaveDoubles(id);
766 RecordSafepointWithRegisters(
767 instr->pointer_map(), argc, Safepoint::kNoLazyDeopt);
771 void LCodeGen::RegisterEnvironmentForDeoptimization(LEnvironment* environment,
772 Safepoint::DeoptMode mode) {
773 environment->set_has_been_used();
774 if (!environment->HasBeenRegistered()) {
775 // Physical stack frame layout:
776 // -x ............. -4 0 ..................................... y
777 // [incoming arguments] [spill slots] [pushed outgoing arguments]
779 // Layout of the environment:
780 // 0 ..................................................... size-1
781 // [parameters] [locals] [expression stack including arguments]
783 // Layout of the translation:
784 // 0 ........................................................ size - 1 + 4
785 // [expression stack including arguments] [locals] [4 words] [parameters]
786 // |>------------ translation_size ------------<|
789 int jsframe_count = 0;
790 for (LEnvironment* e = environment; e != NULL; e = e->outer()) {
792 if (e->frame_type() == JS_FUNCTION) {
796 Translation translation(&translations_, frame_count, jsframe_count, zone());
797 WriteTranslation(environment, &translation);
798 int deoptimization_index = deoptimizations_.length();
799 int pc_offset = masm()->pc_offset();
800 environment->Register(deoptimization_index,
802 (mode == Safepoint::kLazyDeopt) ? pc_offset : -1);
803 deoptimizations_.Add(environment, zone());
808 void LCodeGen::DeoptimizeIf(Condition condition, LInstruction* instr,
809 Deoptimizer::DeoptReason deopt_reason,
810 Deoptimizer::BailoutType bailout_type) {
811 LEnvironment* environment = instr->environment();
812 RegisterEnvironmentForDeoptimization(environment, Safepoint::kNoLazyDeopt);
813 DCHECK(environment->HasBeenRegistered());
814 int id = environment->deoptimization_index();
816 Deoptimizer::GetDeoptimizationEntry(isolate(), id, bailout_type);
818 Abort(kBailoutWasNotPrepared);
822 if (FLAG_deopt_every_n_times != 0 && !info()->IsStub()) {
823 Register scratch = scratch0();
824 ExternalReference count = ExternalReference::stress_deopt_count(isolate());
826 // Store the condition on the stack if necessary
827 if (condition != al) {
828 __ mov(scratch, Operand::Zero(), LeaveCC, NegateCondition(condition));
829 __ mov(scratch, Operand(1), LeaveCC, condition);
834 __ mov(scratch, Operand(count));
835 __ ldr(r1, MemOperand(scratch));
836 __ sub(r1, r1, Operand(1), SetCC);
837 __ mov(r1, Operand(FLAG_deopt_every_n_times), LeaveCC, eq);
838 __ str(r1, MemOperand(scratch));
841 if (condition != al) {
842 // Clean up the stack before the deoptimizer call
846 __ Call(entry, RelocInfo::RUNTIME_ENTRY, eq);
848 // 'Restore' the condition in a slightly hacky way. (It would be better
849 // to use 'msr' and 'mrs' instructions here, but they are not supported by
850 // our ARM simulator).
851 if (condition != al) {
853 __ cmp(scratch, Operand::Zero());
857 if (info()->ShouldTrapOnDeopt()) {
858 __ stop("trap_on_deopt", condition);
861 Deoptimizer::DeoptInfo deopt_info = MakeDeoptInfo(instr, deopt_reason);
863 DCHECK(info()->IsStub() || frame_is_built_);
864 // Go through jump table if we need to handle condition, build frame, or
865 // restore caller doubles.
866 if (condition == al && frame_is_built_ &&
867 !info()->saves_caller_doubles()) {
868 DeoptComment(deopt_info);
869 __ Call(entry, RelocInfo::RUNTIME_ENTRY);
870 info()->LogDeoptCallPosition(masm()->pc_offset(), deopt_info.inlining_id);
872 Deoptimizer::JumpTableEntry table_entry(entry, deopt_info, bailout_type,
874 // We often have several deopts to the same entry, reuse the last
875 // jump entry if this is the case.
876 if (FLAG_trace_deopt || isolate()->cpu_profiler()->is_profiling() ||
877 jump_table_.is_empty() ||
878 !table_entry.IsEquivalentTo(jump_table_.last())) {
879 jump_table_.Add(table_entry, zone());
881 __ b(condition, &jump_table_.last().label);
886 void LCodeGen::DeoptimizeIf(Condition condition, LInstruction* instr,
887 Deoptimizer::DeoptReason deopt_reason) {
888 Deoptimizer::BailoutType bailout_type = info()->IsStub()
890 : Deoptimizer::EAGER;
891 DeoptimizeIf(condition, instr, deopt_reason, bailout_type);
895 void LCodeGen::PopulateDeoptimizationData(Handle<Code> code) {
896 int length = deoptimizations_.length();
897 if (length == 0) return;
898 Handle<DeoptimizationInputData> data =
899 DeoptimizationInputData::New(isolate(), length, TENURED);
901 Handle<ByteArray> translations =
902 translations_.CreateByteArray(isolate()->factory());
903 data->SetTranslationByteArray(*translations);
904 data->SetInlinedFunctionCount(Smi::FromInt(inlined_function_count_));
905 data->SetOptimizationId(Smi::FromInt(info_->optimization_id()));
906 if (info_->IsOptimizing()) {
907 // Reference to shared function info does not change between phases.
908 AllowDeferredHandleDereference allow_handle_dereference;
909 data->SetSharedFunctionInfo(*info_->shared_info());
911 data->SetSharedFunctionInfo(Smi::FromInt(0));
913 data->SetWeakCellCache(Smi::FromInt(0));
915 Handle<FixedArray> literals =
916 factory()->NewFixedArray(deoptimization_literals_.length(), TENURED);
917 { AllowDeferredHandleDereference copy_handles;
918 for (int i = 0; i < deoptimization_literals_.length(); i++) {
919 literals->set(i, *deoptimization_literals_[i]);
921 data->SetLiteralArray(*literals);
924 data->SetOsrAstId(Smi::FromInt(info_->osr_ast_id().ToInt()));
925 data->SetOsrPcOffset(Smi::FromInt(osr_pc_offset_));
927 // Populate the deoptimization entries.
928 for (int i = 0; i < length; i++) {
929 LEnvironment* env = deoptimizations_[i];
930 data->SetAstId(i, env->ast_id());
931 data->SetTranslationIndex(i, Smi::FromInt(env->translation_index()));
932 data->SetArgumentsStackHeight(i,
933 Smi::FromInt(env->arguments_stack_height()));
934 data->SetPc(i, Smi::FromInt(env->pc_offset()));
936 code->set_deoptimization_data(*data);
940 void LCodeGen::PopulateDeoptimizationLiteralsWithInlinedFunctions() {
941 DCHECK_EQ(0, deoptimization_literals_.length());
942 for (auto function : chunk()->inlined_functions()) {
943 DefineDeoptimizationLiteral(function);
945 inlined_function_count_ = deoptimization_literals_.length();
949 void LCodeGen::RecordSafepointWithLazyDeopt(
950 LInstruction* instr, SafepointMode safepoint_mode) {
951 if (safepoint_mode == RECORD_SIMPLE_SAFEPOINT) {
952 RecordSafepoint(instr->pointer_map(), Safepoint::kLazyDeopt);
954 DCHECK(safepoint_mode == RECORD_SAFEPOINT_WITH_REGISTERS_AND_NO_ARGUMENTS);
955 RecordSafepointWithRegisters(
956 instr->pointer_map(), 0, Safepoint::kLazyDeopt);
961 void LCodeGen::RecordSafepoint(
962 LPointerMap* pointers,
963 Safepoint::Kind kind,
965 Safepoint::DeoptMode deopt_mode) {
966 DCHECK(expected_safepoint_kind_ == kind);
968 const ZoneList<LOperand*>* operands = pointers->GetNormalizedOperands();
969 Safepoint safepoint = safepoints_.DefineSafepoint(masm(),
970 kind, arguments, deopt_mode);
971 for (int i = 0; i < operands->length(); i++) {
972 LOperand* pointer = operands->at(i);
973 if (pointer->IsStackSlot()) {
974 safepoint.DefinePointerSlot(pointer->index(), zone());
975 } else if (pointer->IsRegister() && (kind & Safepoint::kWithRegisters)) {
976 safepoint.DefinePointerRegister(ToRegister(pointer), zone());
982 void LCodeGen::RecordSafepoint(LPointerMap* pointers,
983 Safepoint::DeoptMode deopt_mode) {
984 RecordSafepoint(pointers, Safepoint::kSimple, 0, deopt_mode);
988 void LCodeGen::RecordSafepoint(Safepoint::DeoptMode deopt_mode) {
989 LPointerMap empty_pointers(zone());
990 RecordSafepoint(&empty_pointers, deopt_mode);
994 void LCodeGen::RecordSafepointWithRegisters(LPointerMap* pointers,
996 Safepoint::DeoptMode deopt_mode) {
998 pointers, Safepoint::kWithRegisters, arguments, deopt_mode);
1002 void LCodeGen::RecordAndWritePosition(int position) {
1003 if (position == RelocInfo::kNoPosition) return;
1004 masm()->positions_recorder()->RecordPosition(position);
1005 masm()->positions_recorder()->WriteRecordedPositions();
1009 static const char* LabelType(LLabel* label) {
1010 if (label->is_loop_header()) return " (loop header)";
1011 if (label->is_osr_entry()) return " (OSR entry)";
1016 void LCodeGen::DoLabel(LLabel* label) {
1017 Comment(";;; <@%d,#%d> -------------------- B%d%s --------------------",
1018 current_instruction_,
1019 label->hydrogen_value()->id(),
1022 __ bind(label->label());
1023 current_block_ = label->block_id();
1028 void LCodeGen::DoParallelMove(LParallelMove* move) {
1029 resolver_.Resolve(move);
1033 void LCodeGen::DoGap(LGap* gap) {
1034 for (int i = LGap::FIRST_INNER_POSITION;
1035 i <= LGap::LAST_INNER_POSITION;
1037 LGap::InnerPosition inner_pos = static_cast<LGap::InnerPosition>(i);
1038 LParallelMove* move = gap->GetParallelMove(inner_pos);
1039 if (move != NULL) DoParallelMove(move);
1044 void LCodeGen::DoInstructionGap(LInstructionGap* instr) {
1049 void LCodeGen::DoParameter(LParameter* instr) {
1054 void LCodeGen::DoCallStub(LCallStub* instr) {
1055 DCHECK(ToRegister(instr->context()).is(cp));
1056 DCHECK(ToRegister(instr->result()).is(r0));
1057 switch (instr->hydrogen()->major_key()) {
1058 case CodeStub::RegExpExec: {
1059 RegExpExecStub stub(isolate());
1060 CallCode(stub.GetCode(), RelocInfo::CODE_TARGET, instr);
1063 case CodeStub::SubString: {
1064 SubStringStub stub(isolate());
1065 CallCode(stub.GetCode(), RelocInfo::CODE_TARGET, instr);
1068 case CodeStub::StringCompare: {
1069 StringCompareStub stub(isolate());
1070 CallCode(stub.GetCode(), RelocInfo::CODE_TARGET, instr);
1079 void LCodeGen::DoUnknownOSRValue(LUnknownOSRValue* instr) {
1080 GenerateOsrPrologue();
1084 void LCodeGen::DoModByPowerOf2I(LModByPowerOf2I* instr) {
1085 Register dividend = ToRegister(instr->dividend());
1086 int32_t divisor = instr->divisor();
1087 DCHECK(dividend.is(ToRegister(instr->result())));
1089 // Theoretically, a variation of the branch-free code for integer division by
1090 // a power of 2 (calculating the remainder via an additional multiplication
1091 // (which gets simplified to an 'and') and subtraction) should be faster, and
1092 // this is exactly what GCC and clang emit. Nevertheless, benchmarks seem to
1093 // indicate that positive dividends are heavily favored, so the branching
1094 // version performs better.
1095 HMod* hmod = instr->hydrogen();
1096 int32_t mask = divisor < 0 ? -(divisor + 1) : (divisor - 1);
1097 Label dividend_is_not_negative, done;
1098 if (hmod->CheckFlag(HValue::kLeftCanBeNegative)) {
1099 __ cmp(dividend, Operand::Zero());
1100 __ b(pl, ÷nd_is_not_negative);
1101 // Note that this is correct even for kMinInt operands.
1102 __ rsb(dividend, dividend, Operand::Zero());
1103 __ and_(dividend, dividend, Operand(mask));
1104 __ rsb(dividend, dividend, Operand::Zero(), SetCC);
1105 if (hmod->CheckFlag(HValue::kBailoutOnMinusZero)) {
1106 DeoptimizeIf(eq, instr, Deoptimizer::kMinusZero);
1111 __ bind(÷nd_is_not_negative);
1112 __ and_(dividend, dividend, Operand(mask));
1117 void LCodeGen::DoModByConstI(LModByConstI* instr) {
1118 Register dividend = ToRegister(instr->dividend());
1119 int32_t divisor = instr->divisor();
1120 Register result = ToRegister(instr->result());
1121 DCHECK(!dividend.is(result));
1124 DeoptimizeIf(al, instr, Deoptimizer::kDivisionByZero);
1128 __ TruncatingDiv(result, dividend, Abs(divisor));
1129 __ mov(ip, Operand(Abs(divisor)));
1130 __ smull(result, ip, result, ip);
1131 __ sub(result, dividend, result, SetCC);
1133 // Check for negative zero.
1134 HMod* hmod = instr->hydrogen();
1135 if (hmod->CheckFlag(HValue::kBailoutOnMinusZero)) {
1136 Label remainder_not_zero;
1137 __ b(ne, &remainder_not_zero);
1138 __ cmp(dividend, Operand::Zero());
1139 DeoptimizeIf(lt, instr, Deoptimizer::kMinusZero);
1140 __ bind(&remainder_not_zero);
1145 void LCodeGen::DoModI(LModI* instr) {
1146 HMod* hmod = instr->hydrogen();
1147 if (CpuFeatures::IsSupported(SUDIV)) {
1148 CpuFeatureScope scope(masm(), SUDIV);
1150 Register left_reg = ToRegister(instr->left());
1151 Register right_reg = ToRegister(instr->right());
1152 Register result_reg = ToRegister(instr->result());
1155 // Check for x % 0, sdiv might signal an exception. We have to deopt in this
1156 // case because we can't return a NaN.
1157 if (hmod->CheckFlag(HValue::kCanBeDivByZero)) {
1158 __ cmp(right_reg, Operand::Zero());
1159 DeoptimizeIf(eq, instr, Deoptimizer::kDivisionByZero);
1162 // Check for kMinInt % -1, sdiv will return kMinInt, which is not what we
1163 // want. We have to deopt if we care about -0, because we can't return that.
1164 if (hmod->CheckFlag(HValue::kCanOverflow)) {
1165 Label no_overflow_possible;
1166 __ cmp(left_reg, Operand(kMinInt));
1167 __ b(ne, &no_overflow_possible);
1168 __ cmp(right_reg, Operand(-1));
1169 if (hmod->CheckFlag(HValue::kBailoutOnMinusZero)) {
1170 DeoptimizeIf(eq, instr, Deoptimizer::kMinusZero);
1172 __ b(ne, &no_overflow_possible);
1173 __ mov(result_reg, Operand::Zero());
1176 __ bind(&no_overflow_possible);
1179 // For 'r3 = r1 % r2' we can have the following ARM code:
1181 // mls r3, r3, r2, r1
1183 __ sdiv(result_reg, left_reg, right_reg);
1184 __ Mls(result_reg, result_reg, right_reg, left_reg);
1186 // If we care about -0, test if the dividend is <0 and the result is 0.
1187 if (hmod->CheckFlag(HValue::kBailoutOnMinusZero)) {
1188 __ cmp(result_reg, Operand::Zero());
1190 __ cmp(left_reg, Operand::Zero());
1191 DeoptimizeIf(lt, instr, Deoptimizer::kMinusZero);
1196 // General case, without any SDIV support.
1197 Register left_reg = ToRegister(instr->left());
1198 Register right_reg = ToRegister(instr->right());
1199 Register result_reg = ToRegister(instr->result());
1200 Register scratch = scratch0();
1201 DCHECK(!scratch.is(left_reg));
1202 DCHECK(!scratch.is(right_reg));
1203 DCHECK(!scratch.is(result_reg));
1204 DwVfpRegister dividend = ToDoubleRegister(instr->temp());
1205 DwVfpRegister divisor = ToDoubleRegister(instr->temp2());
1206 DCHECK(!divisor.is(dividend));
1207 LowDwVfpRegister quotient = double_scratch0();
1208 DCHECK(!quotient.is(dividend));
1209 DCHECK(!quotient.is(divisor));
1212 // Check for x % 0, we have to deopt in this case because we can't return a
1214 if (hmod->CheckFlag(HValue::kCanBeDivByZero)) {
1215 __ cmp(right_reg, Operand::Zero());
1216 DeoptimizeIf(eq, instr, Deoptimizer::kDivisionByZero);
1219 __ Move(result_reg, left_reg);
1220 // Load the arguments in VFP registers. The divisor value is preloaded
1221 // before. Be careful that 'right_reg' is only live on entry.
1222 // TODO(svenpanne) The last comments seems to be wrong nowadays.
1223 __ vmov(double_scratch0().low(), left_reg);
1224 __ vcvt_f64_s32(dividend, double_scratch0().low());
1225 __ vmov(double_scratch0().low(), right_reg);
1226 __ vcvt_f64_s32(divisor, double_scratch0().low());
1228 // We do not care about the sign of the divisor. Note that we still handle
1229 // the kMinInt % -1 case correctly, though.
1230 __ vabs(divisor, divisor);
1231 // Compute the quotient and round it to a 32bit integer.
1232 __ vdiv(quotient, dividend, divisor);
1233 __ vcvt_s32_f64(quotient.low(), quotient);
1234 __ vcvt_f64_s32(quotient, quotient.low());
1236 // Compute the remainder in result.
1237 __ vmul(double_scratch0(), divisor, quotient);
1238 __ vcvt_s32_f64(double_scratch0().low(), double_scratch0());
1239 __ vmov(scratch, double_scratch0().low());
1240 __ sub(result_reg, left_reg, scratch, SetCC);
1242 // If we care about -0, test if the dividend is <0 and the result is 0.
1243 if (hmod->CheckFlag(HValue::kBailoutOnMinusZero)) {
1245 __ cmp(left_reg, Operand::Zero());
1246 DeoptimizeIf(mi, instr, Deoptimizer::kMinusZero);
1253 void LCodeGen::DoDivByPowerOf2I(LDivByPowerOf2I* instr) {
1254 Register dividend = ToRegister(instr->dividend());
1255 int32_t divisor = instr->divisor();
1256 Register result = ToRegister(instr->result());
1257 DCHECK(divisor == kMinInt || base::bits::IsPowerOfTwo32(Abs(divisor)));
1258 DCHECK(!result.is(dividend));
1260 // Check for (0 / -x) that will produce negative zero.
1261 HDiv* hdiv = instr->hydrogen();
1262 if (hdiv->CheckFlag(HValue::kBailoutOnMinusZero) && divisor < 0) {
1263 __ cmp(dividend, Operand::Zero());
1264 DeoptimizeIf(eq, instr, Deoptimizer::kMinusZero);
1266 // Check for (kMinInt / -1).
1267 if (hdiv->CheckFlag(HValue::kCanOverflow) && divisor == -1) {
1268 __ cmp(dividend, Operand(kMinInt));
1269 DeoptimizeIf(eq, instr, Deoptimizer::kOverflow);
1271 // Deoptimize if remainder will not be 0.
1272 if (!hdiv->CheckFlag(HInstruction::kAllUsesTruncatingToInt32) &&
1273 divisor != 1 && divisor != -1) {
1274 int32_t mask = divisor < 0 ? -(divisor + 1) : (divisor - 1);
1275 __ tst(dividend, Operand(mask));
1276 DeoptimizeIf(ne, instr, Deoptimizer::kLostPrecision);
1279 if (divisor == -1) { // Nice shortcut, not needed for correctness.
1280 __ rsb(result, dividend, Operand(0));
1283 int32_t shift = WhichPowerOf2Abs(divisor);
1285 __ mov(result, dividend);
1286 } else if (shift == 1) {
1287 __ add(result, dividend, Operand(dividend, LSR, 31));
1289 __ mov(result, Operand(dividend, ASR, 31));
1290 __ add(result, dividend, Operand(result, LSR, 32 - shift));
1292 if (shift > 0) __ mov(result, Operand(result, ASR, shift));
1293 if (divisor < 0) __ rsb(result, result, Operand(0));
1297 void LCodeGen::DoDivByConstI(LDivByConstI* instr) {
1298 Register dividend = ToRegister(instr->dividend());
1299 int32_t divisor = instr->divisor();
1300 Register result = ToRegister(instr->result());
1301 DCHECK(!dividend.is(result));
1304 DeoptimizeIf(al, instr, Deoptimizer::kDivisionByZero);
1308 // Check for (0 / -x) that will produce negative zero.
1309 HDiv* hdiv = instr->hydrogen();
1310 if (hdiv->CheckFlag(HValue::kBailoutOnMinusZero) && divisor < 0) {
1311 __ cmp(dividend, Operand::Zero());
1312 DeoptimizeIf(eq, instr, Deoptimizer::kMinusZero);
1315 __ TruncatingDiv(result, dividend, Abs(divisor));
1316 if (divisor < 0) __ rsb(result, result, Operand::Zero());
1318 if (!hdiv->CheckFlag(HInstruction::kAllUsesTruncatingToInt32)) {
1319 __ mov(ip, Operand(divisor));
1320 __ smull(scratch0(), ip, result, ip);
1321 __ sub(scratch0(), scratch0(), dividend, SetCC);
1322 DeoptimizeIf(ne, instr, Deoptimizer::kLostPrecision);
1327 // TODO(svenpanne) Refactor this to avoid code duplication with DoFlooringDivI.
1328 void LCodeGen::DoDivI(LDivI* instr) {
1329 HBinaryOperation* hdiv = instr->hydrogen();
1330 Register dividend = ToRegister(instr->dividend());
1331 Register divisor = ToRegister(instr->divisor());
1332 Register result = ToRegister(instr->result());
1335 if (hdiv->CheckFlag(HValue::kCanBeDivByZero)) {
1336 __ cmp(divisor, Operand::Zero());
1337 DeoptimizeIf(eq, instr, Deoptimizer::kDivisionByZero);
1340 // Check for (0 / -x) that will produce negative zero.
1341 if (hdiv->CheckFlag(HValue::kBailoutOnMinusZero)) {
1343 if (!instr->hydrogen_value()->CheckFlag(HValue::kCanBeDivByZero)) {
1344 // Do the test only if it hadn't be done above.
1345 __ cmp(divisor, Operand::Zero());
1347 __ b(pl, &positive);
1348 __ cmp(dividend, Operand::Zero());
1349 DeoptimizeIf(eq, instr, Deoptimizer::kMinusZero);
1353 // Check for (kMinInt / -1).
1354 if (hdiv->CheckFlag(HValue::kCanOverflow) &&
1355 (!CpuFeatures::IsSupported(SUDIV) ||
1356 !hdiv->CheckFlag(HValue::kAllUsesTruncatingToInt32))) {
1357 // We don't need to check for overflow when truncating with sdiv
1358 // support because, on ARM, sdiv kMinInt, -1 -> kMinInt.
1359 __ cmp(dividend, Operand(kMinInt));
1360 __ cmp(divisor, Operand(-1), eq);
1361 DeoptimizeIf(eq, instr, Deoptimizer::kOverflow);
1364 if (CpuFeatures::IsSupported(SUDIV)) {
1365 CpuFeatureScope scope(masm(), SUDIV);
1366 __ sdiv(result, dividend, divisor);
1368 DoubleRegister vleft = ToDoubleRegister(instr->temp());
1369 DoubleRegister vright = double_scratch0();
1370 __ vmov(double_scratch0().low(), dividend);
1371 __ vcvt_f64_s32(vleft, double_scratch0().low());
1372 __ vmov(double_scratch0().low(), divisor);
1373 __ vcvt_f64_s32(vright, double_scratch0().low());
1374 __ vdiv(vleft, vleft, vright); // vleft now contains the result.
1375 __ vcvt_s32_f64(double_scratch0().low(), vleft);
1376 __ vmov(result, double_scratch0().low());
1379 if (!hdiv->CheckFlag(HValue::kAllUsesTruncatingToInt32)) {
1380 // Compute remainder and deopt if it's not zero.
1381 Register remainder = scratch0();
1382 __ Mls(remainder, result, divisor, dividend);
1383 __ cmp(remainder, Operand::Zero());
1384 DeoptimizeIf(ne, instr, Deoptimizer::kLostPrecision);
1389 void LCodeGen::DoMultiplyAddD(LMultiplyAddD* instr) {
1390 DwVfpRegister addend = ToDoubleRegister(instr->addend());
1391 DwVfpRegister multiplier = ToDoubleRegister(instr->multiplier());
1392 DwVfpRegister multiplicand = ToDoubleRegister(instr->multiplicand());
1394 // This is computed in-place.
1395 DCHECK(addend.is(ToDoubleRegister(instr->result())));
1397 __ vmla(addend, multiplier, multiplicand);
1401 void LCodeGen::DoMultiplySubD(LMultiplySubD* instr) {
1402 DwVfpRegister minuend = ToDoubleRegister(instr->minuend());
1403 DwVfpRegister multiplier = ToDoubleRegister(instr->multiplier());
1404 DwVfpRegister multiplicand = ToDoubleRegister(instr->multiplicand());
1406 // This is computed in-place.
1407 DCHECK(minuend.is(ToDoubleRegister(instr->result())));
1409 __ vmls(minuend, multiplier, multiplicand);
1413 void LCodeGen::DoFlooringDivByPowerOf2I(LFlooringDivByPowerOf2I* instr) {
1414 Register dividend = ToRegister(instr->dividend());
1415 Register result = ToRegister(instr->result());
1416 int32_t divisor = instr->divisor();
1418 // If the divisor is 1, return the dividend.
1420 __ Move(result, dividend);
1424 // If the divisor is positive, things are easy: There can be no deopts and we
1425 // can simply do an arithmetic right shift.
1426 int32_t shift = WhichPowerOf2Abs(divisor);
1428 __ mov(result, Operand(dividend, ASR, shift));
1432 // If the divisor is negative, we have to negate and handle edge cases.
1433 __ rsb(result, dividend, Operand::Zero(), SetCC);
1434 if (instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero)) {
1435 DeoptimizeIf(eq, instr, Deoptimizer::kMinusZero);
1438 // Dividing by -1 is basically negation, unless we overflow.
1439 if (divisor == -1) {
1440 if (instr->hydrogen()->CheckFlag(HValue::kLeftCanBeMinInt)) {
1441 DeoptimizeIf(vs, instr, Deoptimizer::kOverflow);
1446 // If the negation could not overflow, simply shifting is OK.
1447 if (!instr->hydrogen()->CheckFlag(HValue::kLeftCanBeMinInt)) {
1448 __ mov(result, Operand(result, ASR, shift));
1452 __ mov(result, Operand(kMinInt / divisor), LeaveCC, vs);
1453 __ mov(result, Operand(result, ASR, shift), LeaveCC, vc);
1457 void LCodeGen::DoFlooringDivByConstI(LFlooringDivByConstI* instr) {
1458 Register dividend = ToRegister(instr->dividend());
1459 int32_t divisor = instr->divisor();
1460 Register result = ToRegister(instr->result());
1461 DCHECK(!dividend.is(result));
1464 DeoptimizeIf(al, instr, Deoptimizer::kDivisionByZero);
1468 // Check for (0 / -x) that will produce negative zero.
1469 HMathFloorOfDiv* hdiv = instr->hydrogen();
1470 if (hdiv->CheckFlag(HValue::kBailoutOnMinusZero) && divisor < 0) {
1471 __ cmp(dividend, Operand::Zero());
1472 DeoptimizeIf(eq, instr, Deoptimizer::kMinusZero);
1475 // Easy case: We need no dynamic check for the dividend and the flooring
1476 // division is the same as the truncating division.
1477 if ((divisor > 0 && !hdiv->CheckFlag(HValue::kLeftCanBeNegative)) ||
1478 (divisor < 0 && !hdiv->CheckFlag(HValue::kLeftCanBePositive))) {
1479 __ TruncatingDiv(result, dividend, Abs(divisor));
1480 if (divisor < 0) __ rsb(result, result, Operand::Zero());
1484 // In the general case we may need to adjust before and after the truncating
1485 // division to get a flooring division.
1486 Register temp = ToRegister(instr->temp());
1487 DCHECK(!temp.is(dividend) && !temp.is(result));
1488 Label needs_adjustment, done;
1489 __ cmp(dividend, Operand::Zero());
1490 __ b(divisor > 0 ? lt : gt, &needs_adjustment);
1491 __ TruncatingDiv(result, dividend, Abs(divisor));
1492 if (divisor < 0) __ rsb(result, result, Operand::Zero());
1494 __ bind(&needs_adjustment);
1495 __ add(temp, dividend, Operand(divisor > 0 ? 1 : -1));
1496 __ TruncatingDiv(result, temp, Abs(divisor));
1497 if (divisor < 0) __ rsb(result, result, Operand::Zero());
1498 __ sub(result, result, Operand(1));
1503 // TODO(svenpanne) Refactor this to avoid code duplication with DoDivI.
1504 void LCodeGen::DoFlooringDivI(LFlooringDivI* instr) {
1505 HBinaryOperation* hdiv = instr->hydrogen();
1506 Register left = ToRegister(instr->dividend());
1507 Register right = ToRegister(instr->divisor());
1508 Register result = ToRegister(instr->result());
1511 if (hdiv->CheckFlag(HValue::kCanBeDivByZero)) {
1512 __ cmp(right, Operand::Zero());
1513 DeoptimizeIf(eq, instr, Deoptimizer::kDivisionByZero);
1516 // Check for (0 / -x) that will produce negative zero.
1517 if (hdiv->CheckFlag(HValue::kBailoutOnMinusZero)) {
1519 if (!instr->hydrogen_value()->CheckFlag(HValue::kCanBeDivByZero)) {
1520 // Do the test only if it hadn't be done above.
1521 __ cmp(right, Operand::Zero());
1523 __ b(pl, &positive);
1524 __ cmp(left, Operand::Zero());
1525 DeoptimizeIf(eq, instr, Deoptimizer::kMinusZero);
1529 // Check for (kMinInt / -1).
1530 if (hdiv->CheckFlag(HValue::kCanOverflow) &&
1531 (!CpuFeatures::IsSupported(SUDIV) ||
1532 !hdiv->CheckFlag(HValue::kAllUsesTruncatingToInt32))) {
1533 // We don't need to check for overflow when truncating with sdiv
1534 // support because, on ARM, sdiv kMinInt, -1 -> kMinInt.
1535 __ cmp(left, Operand(kMinInt));
1536 __ cmp(right, Operand(-1), eq);
1537 DeoptimizeIf(eq, instr, Deoptimizer::kOverflow);
1540 if (CpuFeatures::IsSupported(SUDIV)) {
1541 CpuFeatureScope scope(masm(), SUDIV);
1542 __ sdiv(result, left, right);
1544 DoubleRegister vleft = ToDoubleRegister(instr->temp());
1545 DoubleRegister vright = double_scratch0();
1546 __ vmov(double_scratch0().low(), left);
1547 __ vcvt_f64_s32(vleft, double_scratch0().low());
1548 __ vmov(double_scratch0().low(), right);
1549 __ vcvt_f64_s32(vright, double_scratch0().low());
1550 __ vdiv(vleft, vleft, vright); // vleft now contains the result.
1551 __ vcvt_s32_f64(double_scratch0().low(), vleft);
1552 __ vmov(result, double_scratch0().low());
1556 Register remainder = scratch0();
1557 __ Mls(remainder, result, right, left);
1558 __ cmp(remainder, Operand::Zero());
1560 __ eor(remainder, remainder, Operand(right));
1561 __ add(result, result, Operand(remainder, ASR, 31));
1566 void LCodeGen::DoMulI(LMulI* instr) {
1567 Register result = ToRegister(instr->result());
1568 // Note that result may alias left.
1569 Register left = ToRegister(instr->left());
1570 LOperand* right_op = instr->right();
1572 bool bailout_on_minus_zero =
1573 instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero);
1574 bool overflow = instr->hydrogen()->CheckFlag(HValue::kCanOverflow);
1576 if (right_op->IsConstantOperand()) {
1577 int32_t constant = ToInteger32(LConstantOperand::cast(right_op));
1579 if (bailout_on_minus_zero && (constant < 0)) {
1580 // The case of a null constant will be handled separately.
1581 // If constant is negative and left is null, the result should be -0.
1582 __ cmp(left, Operand::Zero());
1583 DeoptimizeIf(eq, instr, Deoptimizer::kMinusZero);
1589 __ rsb(result, left, Operand::Zero(), SetCC);
1590 DeoptimizeIf(vs, instr, Deoptimizer::kOverflow);
1592 __ rsb(result, left, Operand::Zero());
1596 if (bailout_on_minus_zero) {
1597 // If left is strictly negative and the constant is null, the
1598 // result is -0. Deoptimize if required, otherwise return 0.
1599 __ cmp(left, Operand::Zero());
1600 DeoptimizeIf(mi, instr, Deoptimizer::kMinusZero);
1602 __ mov(result, Operand::Zero());
1605 __ Move(result, left);
1608 // Multiplying by powers of two and powers of two plus or minus
1609 // one can be done faster with shifted operands.
1610 // For other constants we emit standard code.
1611 int32_t mask = constant >> 31;
1612 uint32_t constant_abs = (constant + mask) ^ mask;
1614 if (base::bits::IsPowerOfTwo32(constant_abs)) {
1615 int32_t shift = WhichPowerOf2(constant_abs);
1616 __ mov(result, Operand(left, LSL, shift));
1617 // Correct the sign of the result is the constant is negative.
1618 if (constant < 0) __ rsb(result, result, Operand::Zero());
1619 } else if (base::bits::IsPowerOfTwo32(constant_abs - 1)) {
1620 int32_t shift = WhichPowerOf2(constant_abs - 1);
1621 __ add(result, left, Operand(left, LSL, shift));
1622 // Correct the sign of the result is the constant is negative.
1623 if (constant < 0) __ rsb(result, result, Operand::Zero());
1624 } else if (base::bits::IsPowerOfTwo32(constant_abs + 1)) {
1625 int32_t shift = WhichPowerOf2(constant_abs + 1);
1626 __ rsb(result, left, Operand(left, LSL, shift));
1627 // Correct the sign of the result is the constant is negative.
1628 if (constant < 0) __ rsb(result, result, Operand::Zero());
1630 // Generate standard code.
1631 __ mov(ip, Operand(constant));
1632 __ mul(result, left, ip);
1637 DCHECK(right_op->IsRegister());
1638 Register right = ToRegister(right_op);
1641 Register scratch = scratch0();
1642 // scratch:result = left * right.
1643 if (instr->hydrogen()->representation().IsSmi()) {
1644 __ SmiUntag(result, left);
1645 __ smull(result, scratch, result, right);
1647 __ smull(result, scratch, left, right);
1649 __ cmp(scratch, Operand(result, ASR, 31));
1650 DeoptimizeIf(ne, instr, Deoptimizer::kOverflow);
1652 if (instr->hydrogen()->representation().IsSmi()) {
1653 __ SmiUntag(result, left);
1654 __ mul(result, result, right);
1656 __ mul(result, left, right);
1660 if (bailout_on_minus_zero) {
1662 __ teq(left, Operand(right));
1664 // Bail out if the result is minus zero.
1665 __ cmp(result, Operand::Zero());
1666 DeoptimizeIf(eq, instr, Deoptimizer::kMinusZero);
1673 void LCodeGen::DoBitI(LBitI* instr) {
1674 LOperand* left_op = instr->left();
1675 LOperand* right_op = instr->right();
1676 DCHECK(left_op->IsRegister());
1677 Register left = ToRegister(left_op);
1678 Register result = ToRegister(instr->result());
1679 Operand right(no_reg);
1681 if (right_op->IsStackSlot()) {
1682 right = Operand(EmitLoadRegister(right_op, ip));
1684 DCHECK(right_op->IsRegister() || right_op->IsConstantOperand());
1685 right = ToOperand(right_op);
1688 switch (instr->op()) {
1689 case Token::BIT_AND:
1690 __ and_(result, left, right);
1693 __ orr(result, left, right);
1695 case Token::BIT_XOR:
1696 if (right_op->IsConstantOperand() && right.immediate() == int32_t(~0)) {
1697 __ mvn(result, Operand(left));
1699 __ eor(result, left, right);
1709 void LCodeGen::DoShiftI(LShiftI* instr) {
1710 // Both 'left' and 'right' are "used at start" (see LCodeGen::DoShift), so
1711 // result may alias either of them.
1712 LOperand* right_op = instr->right();
1713 Register left = ToRegister(instr->left());
1714 Register result = ToRegister(instr->result());
1715 Register scratch = scratch0();
1716 if (right_op->IsRegister()) {
1717 // Mask the right_op operand.
1718 __ and_(scratch, ToRegister(right_op), Operand(0x1F));
1719 switch (instr->op()) {
1721 __ mov(result, Operand(left, ROR, scratch));
1724 __ mov(result, Operand(left, ASR, scratch));
1727 if (instr->can_deopt()) {
1728 __ mov(result, Operand(left, LSR, scratch), SetCC);
1729 DeoptimizeIf(mi, instr, Deoptimizer::kNegativeValue);
1731 __ mov(result, Operand(left, LSR, scratch));
1735 __ mov(result, Operand(left, LSL, scratch));
1742 // Mask the right_op operand.
1743 int value = ToInteger32(LConstantOperand::cast(right_op));
1744 uint8_t shift_count = static_cast<uint8_t>(value & 0x1F);
1745 switch (instr->op()) {
1747 if (shift_count != 0) {
1748 __ mov(result, Operand(left, ROR, shift_count));
1750 __ Move(result, left);
1754 if (shift_count != 0) {
1755 __ mov(result, Operand(left, ASR, shift_count));
1757 __ Move(result, left);
1761 if (shift_count != 0) {
1762 __ mov(result, Operand(left, LSR, shift_count));
1764 if (instr->can_deopt()) {
1765 __ tst(left, Operand(0x80000000));
1766 DeoptimizeIf(ne, instr, Deoptimizer::kNegativeValue);
1768 __ Move(result, left);
1772 if (shift_count != 0) {
1773 if (instr->hydrogen_value()->representation().IsSmi() &&
1774 instr->can_deopt()) {
1775 if (shift_count != 1) {
1776 __ mov(result, Operand(left, LSL, shift_count - 1));
1777 __ SmiTag(result, result, SetCC);
1779 __ SmiTag(result, left, SetCC);
1781 DeoptimizeIf(vs, instr, Deoptimizer::kOverflow);
1783 __ mov(result, Operand(left, LSL, shift_count));
1786 __ Move(result, left);
1797 void LCodeGen::DoSubI(LSubI* instr) {
1798 LOperand* left = instr->left();
1799 LOperand* right = instr->right();
1800 LOperand* result = instr->result();
1801 bool can_overflow = instr->hydrogen()->CheckFlag(HValue::kCanOverflow);
1802 SBit set_cond = can_overflow ? SetCC : LeaveCC;
1804 if (right->IsStackSlot()) {
1805 Register right_reg = EmitLoadRegister(right, ip);
1806 __ sub(ToRegister(result), ToRegister(left), Operand(right_reg), set_cond);
1808 DCHECK(right->IsRegister() || right->IsConstantOperand());
1809 __ sub(ToRegister(result), ToRegister(left), ToOperand(right), set_cond);
1813 DeoptimizeIf(vs, instr, Deoptimizer::kOverflow);
1818 void LCodeGen::DoRSubI(LRSubI* instr) {
1819 LOperand* left = instr->left();
1820 LOperand* right = instr->right();
1821 LOperand* result = instr->result();
1822 bool can_overflow = instr->hydrogen()->CheckFlag(HValue::kCanOverflow);
1823 SBit set_cond = can_overflow ? SetCC : LeaveCC;
1825 if (right->IsStackSlot()) {
1826 Register right_reg = EmitLoadRegister(right, ip);
1827 __ rsb(ToRegister(result), ToRegister(left), Operand(right_reg), set_cond);
1829 DCHECK(right->IsRegister() || right->IsConstantOperand());
1830 __ rsb(ToRegister(result), ToRegister(left), ToOperand(right), set_cond);
1834 DeoptimizeIf(vs, instr, Deoptimizer::kOverflow);
1839 void LCodeGen::DoConstantI(LConstantI* instr) {
1840 __ mov(ToRegister(instr->result()), Operand(instr->value()));
1844 void LCodeGen::DoConstantS(LConstantS* instr) {
1845 __ mov(ToRegister(instr->result()), Operand(instr->value()));
1849 void LCodeGen::DoConstantD(LConstantD* instr) {
1850 DCHECK(instr->result()->IsDoubleRegister());
1851 DwVfpRegister result = ToDoubleRegister(instr->result());
1852 #if V8_HOST_ARCH_IA32
1853 // Need some crappy work-around for x87 sNaN -> qNaN breakage in simulator
1855 uint64_t bits = instr->bits();
1856 if ((bits & V8_UINT64_C(0x7FF8000000000000)) ==
1857 V8_UINT64_C(0x7FF0000000000000)) {
1858 uint32_t lo = static_cast<uint32_t>(bits);
1859 uint32_t hi = static_cast<uint32_t>(bits >> 32);
1860 __ mov(ip, Operand(lo));
1861 __ mov(scratch0(), Operand(hi));
1862 __ vmov(result, ip, scratch0());
1866 double v = instr->value();
1867 __ Vmov(result, v, scratch0());
1871 void LCodeGen::DoConstantE(LConstantE* instr) {
1872 __ mov(ToRegister(instr->result()), Operand(instr->value()));
1876 void LCodeGen::DoConstantT(LConstantT* instr) {
1877 Handle<Object> object = instr->value(isolate());
1878 AllowDeferredHandleDereference smi_check;
1879 __ Move(ToRegister(instr->result()), object);
1883 void LCodeGen::DoMapEnumLength(LMapEnumLength* instr) {
1884 Register result = ToRegister(instr->result());
1885 Register map = ToRegister(instr->value());
1886 __ EnumLength(result, map);
1890 void LCodeGen::DoDateField(LDateField* instr) {
1891 Register object = ToRegister(instr->date());
1892 Register result = ToRegister(instr->result());
1893 Register scratch = ToRegister(instr->temp());
1894 Smi* index = instr->index();
1895 DCHECK(object.is(result));
1896 DCHECK(object.is(r0));
1897 DCHECK(!scratch.is(scratch0()));
1898 DCHECK(!scratch.is(object));
1900 if (index->value() == 0) {
1901 __ ldr(result, FieldMemOperand(object, JSDate::kValueOffset));
1903 Label runtime, done;
1904 if (index->value() < JSDate::kFirstUncachedField) {
1905 ExternalReference stamp = ExternalReference::date_cache_stamp(isolate());
1906 __ mov(scratch, Operand(stamp));
1907 __ ldr(scratch, MemOperand(scratch));
1908 __ ldr(scratch0(), FieldMemOperand(object, JSDate::kCacheStampOffset));
1909 __ cmp(scratch, scratch0());
1911 __ ldr(result, FieldMemOperand(object, JSDate::kValueOffset +
1912 kPointerSize * index->value()));
1916 __ PrepareCallCFunction(2, scratch);
1917 __ mov(r1, Operand(index));
1918 __ CallCFunction(ExternalReference::get_date_field_function(isolate()), 2);
1924 MemOperand LCodeGen::BuildSeqStringOperand(Register string,
1926 String::Encoding encoding) {
1927 if (index->IsConstantOperand()) {
1928 int offset = ToInteger32(LConstantOperand::cast(index));
1929 if (encoding == String::TWO_BYTE_ENCODING) {
1930 offset *= kUC16Size;
1932 STATIC_ASSERT(kCharSize == 1);
1933 return FieldMemOperand(string, SeqString::kHeaderSize + offset);
1935 Register scratch = scratch0();
1936 DCHECK(!scratch.is(string));
1937 DCHECK(!scratch.is(ToRegister(index)));
1938 if (encoding == String::ONE_BYTE_ENCODING) {
1939 __ add(scratch, string, Operand(ToRegister(index)));
1941 STATIC_ASSERT(kUC16Size == 2);
1942 __ add(scratch, string, Operand(ToRegister(index), LSL, 1));
1944 return FieldMemOperand(scratch, SeqString::kHeaderSize);
1948 void LCodeGen::DoSeqStringGetChar(LSeqStringGetChar* instr) {
1949 String::Encoding encoding = instr->hydrogen()->encoding();
1950 Register string = ToRegister(instr->string());
1951 Register result = ToRegister(instr->result());
1953 if (FLAG_debug_code) {
1954 Register scratch = scratch0();
1955 __ ldr(scratch, FieldMemOperand(string, HeapObject::kMapOffset));
1956 __ ldrb(scratch, FieldMemOperand(scratch, Map::kInstanceTypeOffset));
1958 __ and_(scratch, scratch,
1959 Operand(kStringRepresentationMask | kStringEncodingMask));
1960 static const uint32_t one_byte_seq_type = kSeqStringTag | kOneByteStringTag;
1961 static const uint32_t two_byte_seq_type = kSeqStringTag | kTwoByteStringTag;
1962 __ cmp(scratch, Operand(encoding == String::ONE_BYTE_ENCODING
1963 ? one_byte_seq_type : two_byte_seq_type));
1964 __ Check(eq, kUnexpectedStringType);
1967 MemOperand operand = BuildSeqStringOperand(string, instr->index(), encoding);
1968 if (encoding == String::ONE_BYTE_ENCODING) {
1969 __ ldrb(result, operand);
1971 __ ldrh(result, operand);
1976 void LCodeGen::DoSeqStringSetChar(LSeqStringSetChar* instr) {
1977 String::Encoding encoding = instr->hydrogen()->encoding();
1978 Register string = ToRegister(instr->string());
1979 Register value = ToRegister(instr->value());
1981 if (FLAG_debug_code) {
1982 Register index = ToRegister(instr->index());
1983 static const uint32_t one_byte_seq_type = kSeqStringTag | kOneByteStringTag;
1984 static const uint32_t two_byte_seq_type = kSeqStringTag | kTwoByteStringTag;
1986 instr->hydrogen()->encoding() == String::ONE_BYTE_ENCODING
1987 ? one_byte_seq_type : two_byte_seq_type;
1988 __ EmitSeqStringSetCharCheck(string, index, value, encoding_mask);
1991 MemOperand operand = BuildSeqStringOperand(string, instr->index(), encoding);
1992 if (encoding == String::ONE_BYTE_ENCODING) {
1993 __ strb(value, operand);
1995 __ strh(value, operand);
2000 void LCodeGen::DoAddI(LAddI* instr) {
2001 LOperand* left = instr->left();
2002 LOperand* right = instr->right();
2003 LOperand* result = instr->result();
2004 bool can_overflow = instr->hydrogen()->CheckFlag(HValue::kCanOverflow);
2005 SBit set_cond = can_overflow ? SetCC : LeaveCC;
2007 if (right->IsStackSlot()) {
2008 Register right_reg = EmitLoadRegister(right, ip);
2009 __ add(ToRegister(result), ToRegister(left), Operand(right_reg), set_cond);
2011 DCHECK(right->IsRegister() || right->IsConstantOperand());
2012 __ add(ToRegister(result), ToRegister(left), ToOperand(right), set_cond);
2016 DeoptimizeIf(vs, instr, Deoptimizer::kOverflow);
2021 void LCodeGen::DoMathMinMax(LMathMinMax* instr) {
2022 LOperand* left = instr->left();
2023 LOperand* right = instr->right();
2024 HMathMinMax::Operation operation = instr->hydrogen()->operation();
2025 if (instr->hydrogen()->representation().IsSmiOrInteger32()) {
2026 Condition condition = (operation == HMathMinMax::kMathMin) ? le : ge;
2027 Register left_reg = ToRegister(left);
2028 Operand right_op = (right->IsRegister() || right->IsConstantOperand())
2030 : Operand(EmitLoadRegister(right, ip));
2031 Register result_reg = ToRegister(instr->result());
2032 __ cmp(left_reg, right_op);
2033 __ Move(result_reg, left_reg, condition);
2034 __ mov(result_reg, right_op, LeaveCC, NegateCondition(condition));
2036 DCHECK(instr->hydrogen()->representation().IsDouble());
2037 DwVfpRegister left_reg = ToDoubleRegister(left);
2038 DwVfpRegister right_reg = ToDoubleRegister(right);
2039 DwVfpRegister result_reg = ToDoubleRegister(instr->result());
2040 Label result_is_nan, return_left, return_right, check_zero, done;
2041 __ VFPCompareAndSetFlags(left_reg, right_reg);
2042 if (operation == HMathMinMax::kMathMin) {
2043 __ b(mi, &return_left);
2044 __ b(gt, &return_right);
2046 __ b(mi, &return_right);
2047 __ b(gt, &return_left);
2049 __ b(vs, &result_is_nan);
2050 // Left equals right => check for -0.
2051 __ VFPCompareAndSetFlags(left_reg, 0.0);
2052 if (left_reg.is(result_reg) || right_reg.is(result_reg)) {
2053 __ b(ne, &done); // left == right != 0.
2055 __ b(ne, &return_left); // left == right != 0.
2057 // At this point, both left and right are either 0 or -0.
2058 if (operation == HMathMinMax::kMathMin) {
2059 // We could use a single 'vorr' instruction here if we had NEON support.
2060 __ vneg(left_reg, left_reg);
2061 __ vsub(result_reg, left_reg, right_reg);
2062 __ vneg(result_reg, result_reg);
2064 // Since we operate on +0 and/or -0, vadd and vand have the same effect;
2065 // the decision for vadd is easy because vand is a NEON instruction.
2066 __ vadd(result_reg, left_reg, right_reg);
2070 __ bind(&result_is_nan);
2071 __ vadd(result_reg, left_reg, right_reg);
2074 __ bind(&return_right);
2075 __ Move(result_reg, right_reg);
2076 if (!left_reg.is(result_reg)) {
2080 __ bind(&return_left);
2081 __ Move(result_reg, left_reg);
2088 void LCodeGen::DoArithmeticD(LArithmeticD* instr) {
2089 DwVfpRegister left = ToDoubleRegister(instr->left());
2090 DwVfpRegister right = ToDoubleRegister(instr->right());
2091 DwVfpRegister result = ToDoubleRegister(instr->result());
2092 switch (instr->op()) {
2094 __ vadd(result, left, right);
2097 __ vsub(result, left, right);
2100 __ vmul(result, left, right);
2103 __ vdiv(result, left, right);
2106 __ PrepareCallCFunction(0, 2, scratch0());
2107 __ MovToFloatParameters(left, right);
2109 ExternalReference::mod_two_doubles_operation(isolate()),
2111 // Move the result in the double result register.
2112 __ MovFromFloatResult(result);
2122 void LCodeGen::DoArithmeticT(LArithmeticT* instr) {
2123 DCHECK(ToRegister(instr->context()).is(cp));
2124 DCHECK(ToRegister(instr->left()).is(r1));
2125 DCHECK(ToRegister(instr->right()).is(r0));
2126 DCHECK(ToRegister(instr->result()).is(r0));
2129 CodeFactory::BinaryOpIC(isolate(), instr->op(), instr->strength()).code();
2130 // Block literal pool emission to ensure nop indicating no inlined smi code
2131 // is in the correct position.
2132 Assembler::BlockConstPoolScope block_const_pool(masm());
2133 CallCode(code, RelocInfo::CODE_TARGET, instr);
2137 template<class InstrType>
2138 void LCodeGen::EmitBranch(InstrType instr, Condition condition) {
2139 int left_block = instr->TrueDestination(chunk_);
2140 int right_block = instr->FalseDestination(chunk_);
2142 int next_block = GetNextEmittedBlock();
2144 if (right_block == left_block || condition == al) {
2145 EmitGoto(left_block);
2146 } else if (left_block == next_block) {
2147 __ b(NegateCondition(condition), chunk_->GetAssemblyLabel(right_block));
2148 } else if (right_block == next_block) {
2149 __ b(condition, chunk_->GetAssemblyLabel(left_block));
2151 __ b(condition, chunk_->GetAssemblyLabel(left_block));
2152 __ b(chunk_->GetAssemblyLabel(right_block));
2157 template <class InstrType>
2158 void LCodeGen::EmitTrueBranch(InstrType instr, Condition condition) {
2159 int true_block = instr->TrueDestination(chunk_);
2160 __ b(condition, chunk_->GetAssemblyLabel(true_block));
2164 template <class InstrType>
2165 void LCodeGen::EmitFalseBranch(InstrType instr, Condition condition) {
2166 int false_block = instr->FalseDestination(chunk_);
2167 __ b(condition, chunk_->GetAssemblyLabel(false_block));
2171 void LCodeGen::DoDebugBreak(LDebugBreak* instr) {
2176 void LCodeGen::DoBranch(LBranch* instr) {
2177 Representation r = instr->hydrogen()->value()->representation();
2178 if (r.IsInteger32() || r.IsSmi()) {
2179 DCHECK(!info()->IsStub());
2180 Register reg = ToRegister(instr->value());
2181 __ cmp(reg, Operand::Zero());
2182 EmitBranch(instr, ne);
2183 } else if (r.IsDouble()) {
2184 DCHECK(!info()->IsStub());
2185 DwVfpRegister reg = ToDoubleRegister(instr->value());
2186 // Test the double value. Zero and NaN are false.
2187 __ VFPCompareAndSetFlags(reg, 0.0);
2188 __ cmp(r0, r0, vs); // If NaN, set the Z flag. (NaN -> false)
2189 EmitBranch(instr, ne);
2191 DCHECK(r.IsTagged());
2192 Register reg = ToRegister(instr->value());
2193 HType type = instr->hydrogen()->value()->type();
2194 if (type.IsBoolean()) {
2195 DCHECK(!info()->IsStub());
2196 __ CompareRoot(reg, Heap::kTrueValueRootIndex);
2197 EmitBranch(instr, eq);
2198 } else if (type.IsSmi()) {
2199 DCHECK(!info()->IsStub());
2200 __ cmp(reg, Operand::Zero());
2201 EmitBranch(instr, ne);
2202 } else if (type.IsJSArray()) {
2203 DCHECK(!info()->IsStub());
2204 EmitBranch(instr, al);
2205 } else if (type.IsHeapNumber()) {
2206 DCHECK(!info()->IsStub());
2207 DwVfpRegister dbl_scratch = double_scratch0();
2208 __ vldr(dbl_scratch, FieldMemOperand(reg, HeapNumber::kValueOffset));
2209 // Test the double value. Zero and NaN are false.
2210 __ VFPCompareAndSetFlags(dbl_scratch, 0.0);
2211 __ cmp(r0, r0, vs); // If NaN, set the Z flag. (NaN)
2212 EmitBranch(instr, ne);
2213 } else if (type.IsString()) {
2214 DCHECK(!info()->IsStub());
2215 __ ldr(ip, FieldMemOperand(reg, String::kLengthOffset));
2216 __ cmp(ip, Operand::Zero());
2217 EmitBranch(instr, ne);
2219 ToBooleanStub::Types expected = instr->hydrogen()->expected_input_types();
2220 // Avoid deopts in the case where we've never executed this path before.
2221 if (expected.IsEmpty()) expected = ToBooleanStub::Types::Generic();
2223 if (expected.Contains(ToBooleanStub::UNDEFINED)) {
2224 // undefined -> false.
2225 __ CompareRoot(reg, Heap::kUndefinedValueRootIndex);
2226 __ b(eq, instr->FalseLabel(chunk_));
2228 if (expected.Contains(ToBooleanStub::BOOLEAN)) {
2229 // Boolean -> its value.
2230 __ CompareRoot(reg, Heap::kTrueValueRootIndex);
2231 __ b(eq, instr->TrueLabel(chunk_));
2232 __ CompareRoot(reg, Heap::kFalseValueRootIndex);
2233 __ b(eq, instr->FalseLabel(chunk_));
2235 if (expected.Contains(ToBooleanStub::NULL_TYPE)) {
2237 __ CompareRoot(reg, Heap::kNullValueRootIndex);
2238 __ b(eq, instr->FalseLabel(chunk_));
2241 if (expected.Contains(ToBooleanStub::SMI)) {
2242 // Smis: 0 -> false, all other -> true.
2243 __ cmp(reg, Operand::Zero());
2244 __ b(eq, instr->FalseLabel(chunk_));
2245 __ JumpIfSmi(reg, instr->TrueLabel(chunk_));
2246 } else if (expected.NeedsMap()) {
2247 // If we need a map later and have a Smi -> deopt.
2249 DeoptimizeIf(eq, instr, Deoptimizer::kSmi);
2252 const Register map = scratch0();
2253 if (expected.NeedsMap()) {
2254 __ ldr(map, FieldMemOperand(reg, HeapObject::kMapOffset));
2256 if (expected.CanBeUndetectable()) {
2257 // Undetectable -> false.
2258 __ ldrb(ip, FieldMemOperand(map, Map::kBitFieldOffset));
2259 __ tst(ip, Operand(1 << Map::kIsUndetectable));
2260 __ b(ne, instr->FalseLabel(chunk_));
2264 if (expected.Contains(ToBooleanStub::SPEC_OBJECT)) {
2265 // spec object -> true.
2266 __ CompareInstanceType(map, ip, FIRST_SPEC_OBJECT_TYPE);
2267 __ b(ge, instr->TrueLabel(chunk_));
2270 if (expected.Contains(ToBooleanStub::STRING)) {
2271 // String value -> false iff empty.
2273 __ CompareInstanceType(map, ip, FIRST_NONSTRING_TYPE);
2274 __ b(ge, ¬_string);
2275 __ ldr(ip, FieldMemOperand(reg, String::kLengthOffset));
2276 __ cmp(ip, Operand::Zero());
2277 __ b(ne, instr->TrueLabel(chunk_));
2278 __ b(instr->FalseLabel(chunk_));
2279 __ bind(¬_string);
2282 if (expected.Contains(ToBooleanStub::SYMBOL)) {
2283 // Symbol value -> true.
2284 __ CompareInstanceType(map, ip, SYMBOL_TYPE);
2285 __ b(eq, instr->TrueLabel(chunk_));
2288 if (expected.Contains(ToBooleanStub::SIMD_VALUE)) {
2289 // SIMD value -> true.
2290 __ CompareInstanceType(map, ip, SIMD128_VALUE_TYPE);
2291 __ b(eq, instr->TrueLabel(chunk_));
2294 if (expected.Contains(ToBooleanStub::HEAP_NUMBER)) {
2295 // heap number -> false iff +0, -0, or NaN.
2296 DwVfpRegister dbl_scratch = double_scratch0();
2297 Label not_heap_number;
2298 __ CompareRoot(map, Heap::kHeapNumberMapRootIndex);
2299 __ b(ne, ¬_heap_number);
2300 __ vldr(dbl_scratch, FieldMemOperand(reg, HeapNumber::kValueOffset));
2301 __ VFPCompareAndSetFlags(dbl_scratch, 0.0);
2302 __ cmp(r0, r0, vs); // NaN -> false.
2303 __ b(eq, instr->FalseLabel(chunk_)); // +0, -0 -> false.
2304 __ b(instr->TrueLabel(chunk_));
2305 __ bind(¬_heap_number);
2308 if (!expected.IsGeneric()) {
2309 // We've seen something for the first time -> deopt.
2310 // This can only happen if we are not generic already.
2311 DeoptimizeIf(al, instr, Deoptimizer::kUnexpectedObject);
2318 void LCodeGen::EmitGoto(int block) {
2319 if (!IsNextEmittedBlock(block)) {
2320 __ jmp(chunk_->GetAssemblyLabel(LookupDestination(block)));
2325 void LCodeGen::DoGoto(LGoto* instr) {
2326 EmitGoto(instr->block_id());
2330 Condition LCodeGen::TokenToCondition(Token::Value op, bool is_unsigned) {
2331 Condition cond = kNoCondition;
2334 case Token::EQ_STRICT:
2338 case Token::NE_STRICT:
2342 cond = is_unsigned ? lo : lt;
2345 cond = is_unsigned ? hi : gt;
2348 cond = is_unsigned ? ls : le;
2351 cond = is_unsigned ? hs : ge;
2354 case Token::INSTANCEOF:
2362 void LCodeGen::DoCompareNumericAndBranch(LCompareNumericAndBranch* instr) {
2363 LOperand* left = instr->left();
2364 LOperand* right = instr->right();
2366 instr->hydrogen()->left()->CheckFlag(HInstruction::kUint32) ||
2367 instr->hydrogen()->right()->CheckFlag(HInstruction::kUint32);
2368 Condition cond = TokenToCondition(instr->op(), is_unsigned);
2370 if (left->IsConstantOperand() && right->IsConstantOperand()) {
2371 // We can statically evaluate the comparison.
2372 double left_val = ToDouble(LConstantOperand::cast(left));
2373 double right_val = ToDouble(LConstantOperand::cast(right));
2374 int next_block = EvalComparison(instr->op(), left_val, right_val) ?
2375 instr->TrueDestination(chunk_) : instr->FalseDestination(chunk_);
2376 EmitGoto(next_block);
2378 if (instr->is_double()) {
2379 // Compare left and right operands as doubles and load the
2380 // resulting flags into the normal status register.
2381 __ VFPCompareAndSetFlags(ToDoubleRegister(left), ToDoubleRegister(right));
2382 // If a NaN is involved, i.e. the result is unordered (V set),
2383 // jump to false block label.
2384 __ b(vs, instr->FalseLabel(chunk_));
2386 if (right->IsConstantOperand()) {
2387 int32_t value = ToInteger32(LConstantOperand::cast(right));
2388 if (instr->hydrogen_value()->representation().IsSmi()) {
2389 __ cmp(ToRegister(left), Operand(Smi::FromInt(value)));
2391 __ cmp(ToRegister(left), Operand(value));
2393 } else if (left->IsConstantOperand()) {
2394 int32_t value = ToInteger32(LConstantOperand::cast(left));
2395 if (instr->hydrogen_value()->representation().IsSmi()) {
2396 __ cmp(ToRegister(right), Operand(Smi::FromInt(value)));
2398 __ cmp(ToRegister(right), Operand(value));
2400 // We commuted the operands, so commute the condition.
2401 cond = CommuteCondition(cond);
2403 __ cmp(ToRegister(left), ToRegister(right));
2406 EmitBranch(instr, cond);
2411 void LCodeGen::DoCmpObjectEqAndBranch(LCmpObjectEqAndBranch* instr) {
2412 Register left = ToRegister(instr->left());
2413 Register right = ToRegister(instr->right());
2415 __ cmp(left, Operand(right));
2416 EmitBranch(instr, eq);
2420 void LCodeGen::DoCmpHoleAndBranch(LCmpHoleAndBranch* instr) {
2421 if (instr->hydrogen()->representation().IsTagged()) {
2422 Register input_reg = ToRegister(instr->object());
2423 __ mov(ip, Operand(factory()->the_hole_value()));
2424 __ cmp(input_reg, ip);
2425 EmitBranch(instr, eq);
2429 DwVfpRegister input_reg = ToDoubleRegister(instr->object());
2430 __ VFPCompareAndSetFlags(input_reg, input_reg);
2431 EmitFalseBranch(instr, vc);
2433 Register scratch = scratch0();
2434 __ VmovHigh(scratch, input_reg);
2435 __ cmp(scratch, Operand(kHoleNanUpper32));
2436 EmitBranch(instr, eq);
2440 void LCodeGen::DoCompareMinusZeroAndBranch(LCompareMinusZeroAndBranch* instr) {
2441 Representation rep = instr->hydrogen()->value()->representation();
2442 DCHECK(!rep.IsInteger32());
2443 Register scratch = ToRegister(instr->temp());
2445 if (rep.IsDouble()) {
2446 DwVfpRegister value = ToDoubleRegister(instr->value());
2447 __ VFPCompareAndSetFlags(value, 0.0);
2448 EmitFalseBranch(instr, ne);
2449 __ VmovHigh(scratch, value);
2450 __ cmp(scratch, Operand(0x80000000));
2452 Register value = ToRegister(instr->value());
2455 Heap::kHeapNumberMapRootIndex,
2456 instr->FalseLabel(chunk()),
2458 __ ldr(scratch, FieldMemOperand(value, HeapNumber::kExponentOffset));
2459 __ ldr(ip, FieldMemOperand(value, HeapNumber::kMantissaOffset));
2460 __ cmp(scratch, Operand(0x80000000));
2461 __ cmp(ip, Operand(0x00000000), eq);
2463 EmitBranch(instr, eq);
2467 Condition LCodeGen::EmitIsString(Register input,
2469 Label* is_not_string,
2470 SmiCheck check_needed = INLINE_SMI_CHECK) {
2471 if (check_needed == INLINE_SMI_CHECK) {
2472 __ JumpIfSmi(input, is_not_string);
2474 __ CompareObjectType(input, temp1, temp1, FIRST_NONSTRING_TYPE);
2480 void LCodeGen::DoIsStringAndBranch(LIsStringAndBranch* instr) {
2481 Register reg = ToRegister(instr->value());
2482 Register temp1 = ToRegister(instr->temp());
2484 SmiCheck check_needed =
2485 instr->hydrogen()->value()->type().IsHeapObject()
2486 ? OMIT_SMI_CHECK : INLINE_SMI_CHECK;
2487 Condition true_cond =
2488 EmitIsString(reg, temp1, instr->FalseLabel(chunk_), check_needed);
2490 EmitBranch(instr, true_cond);
2494 void LCodeGen::DoIsSmiAndBranch(LIsSmiAndBranch* instr) {
2495 Register input_reg = EmitLoadRegister(instr->value(), ip);
2496 __ SmiTst(input_reg);
2497 EmitBranch(instr, eq);
2501 void LCodeGen::DoIsUndetectableAndBranch(LIsUndetectableAndBranch* instr) {
2502 Register input = ToRegister(instr->value());
2503 Register temp = ToRegister(instr->temp());
2505 if (!instr->hydrogen()->value()->type().IsHeapObject()) {
2506 __ JumpIfSmi(input, instr->FalseLabel(chunk_));
2508 __ ldr(temp, FieldMemOperand(input, HeapObject::kMapOffset));
2509 __ ldrb(temp, FieldMemOperand(temp, Map::kBitFieldOffset));
2510 __ tst(temp, Operand(1 << Map::kIsUndetectable));
2511 EmitBranch(instr, ne);
2515 static Condition ComputeCompareCondition(Token::Value op) {
2517 case Token::EQ_STRICT:
2530 return kNoCondition;
2535 void LCodeGen::DoStringCompareAndBranch(LStringCompareAndBranch* instr) {
2536 DCHECK(ToRegister(instr->context()).is(cp));
2537 Token::Value op = instr->op();
2540 CodeFactory::CompareIC(isolate(), op, Strength::WEAK).code();
2541 CallCode(ic, RelocInfo::CODE_TARGET, instr);
2542 // This instruction also signals no smi code inlined.
2543 __ cmp(r0, Operand::Zero());
2545 Condition condition = ComputeCompareCondition(op);
2547 EmitBranch(instr, condition);
2551 static InstanceType TestType(HHasInstanceTypeAndBranch* instr) {
2552 InstanceType from = instr->from();
2553 InstanceType to = instr->to();
2554 if (from == FIRST_TYPE) return to;
2555 DCHECK(from == to || to == LAST_TYPE);
2560 static Condition BranchCondition(HHasInstanceTypeAndBranch* instr) {
2561 InstanceType from = instr->from();
2562 InstanceType to = instr->to();
2563 if (from == to) return eq;
2564 if (to == LAST_TYPE) return hs;
2565 if (from == FIRST_TYPE) return ls;
2571 void LCodeGen::DoHasInstanceTypeAndBranch(LHasInstanceTypeAndBranch* instr) {
2572 Register scratch = scratch0();
2573 Register input = ToRegister(instr->value());
2575 if (!instr->hydrogen()->value()->type().IsHeapObject()) {
2576 __ JumpIfSmi(input, instr->FalseLabel(chunk_));
2579 __ CompareObjectType(input, scratch, scratch, TestType(instr->hydrogen()));
2580 EmitBranch(instr, BranchCondition(instr->hydrogen()));
2584 void LCodeGen::DoGetCachedArrayIndex(LGetCachedArrayIndex* instr) {
2585 Register input = ToRegister(instr->value());
2586 Register result = ToRegister(instr->result());
2588 __ AssertString(input);
2590 __ ldr(result, FieldMemOperand(input, String::kHashFieldOffset));
2591 __ IndexFromHash(result, result);
2595 void LCodeGen::DoHasCachedArrayIndexAndBranch(
2596 LHasCachedArrayIndexAndBranch* instr) {
2597 Register input = ToRegister(instr->value());
2598 Register scratch = scratch0();
2601 FieldMemOperand(input, String::kHashFieldOffset));
2602 __ tst(scratch, Operand(String::kContainsCachedArrayIndexMask));
2603 EmitBranch(instr, eq);
2607 // Branches to a label or falls through with the answer in flags. Trashes
2608 // the temp registers, but not the input.
2609 void LCodeGen::EmitClassOfTest(Label* is_true,
2611 Handle<String>class_name,
2615 DCHECK(!input.is(temp));
2616 DCHECK(!input.is(temp2));
2617 DCHECK(!temp.is(temp2));
2619 __ JumpIfSmi(input, is_false);
2621 if (String::Equals(isolate()->factory()->Function_string(), class_name)) {
2622 // Assuming the following assertions, we can use the same compares to test
2623 // for both being a function type and being in the object type range.
2624 STATIC_ASSERT(NUM_OF_CALLABLE_SPEC_OBJECT_TYPES == 2);
2625 STATIC_ASSERT(FIRST_NONCALLABLE_SPEC_OBJECT_TYPE ==
2626 FIRST_SPEC_OBJECT_TYPE + 1);
2627 STATIC_ASSERT(LAST_NONCALLABLE_SPEC_OBJECT_TYPE ==
2628 LAST_SPEC_OBJECT_TYPE - 1);
2629 STATIC_ASSERT(LAST_SPEC_OBJECT_TYPE == LAST_TYPE);
2630 __ CompareObjectType(input, temp, temp2, FIRST_SPEC_OBJECT_TYPE);
2633 __ cmp(temp2, Operand(LAST_SPEC_OBJECT_TYPE));
2636 // Faster code path to avoid two compares: subtract lower bound from the
2637 // actual type and do a signed compare with the width of the type range.
2638 __ ldr(temp, FieldMemOperand(input, HeapObject::kMapOffset));
2639 __ ldrb(temp2, FieldMemOperand(temp, Map::kInstanceTypeOffset));
2640 __ sub(temp2, temp2, Operand(FIRST_NONCALLABLE_SPEC_OBJECT_TYPE));
2641 __ cmp(temp2, Operand(LAST_NONCALLABLE_SPEC_OBJECT_TYPE -
2642 FIRST_NONCALLABLE_SPEC_OBJECT_TYPE));
2646 // Now we are in the FIRST-LAST_NONCALLABLE_SPEC_OBJECT_TYPE range.
2647 // Check if the constructor in the map is a function.
2648 Register instance_type = ip;
2649 __ GetMapConstructor(temp, temp, temp2, instance_type);
2651 // Objects with a non-function constructor have class 'Object'.
2652 __ cmp(instance_type, Operand(JS_FUNCTION_TYPE));
2653 if (class_name->IsOneByteEqualTo(STATIC_CHAR_VECTOR("Object"))) {
2659 // temp now contains the constructor function. Grab the
2660 // instance class name from there.
2661 __ ldr(temp, FieldMemOperand(temp, JSFunction::kSharedFunctionInfoOffset));
2662 __ ldr(temp, FieldMemOperand(temp,
2663 SharedFunctionInfo::kInstanceClassNameOffset));
2664 // The class name we are testing against is internalized since it's a literal.
2665 // The name in the constructor is internalized because of the way the context
2666 // is booted. This routine isn't expected to work for random API-created
2667 // classes and it doesn't have to because you can't access it with natives
2668 // syntax. Since both sides are internalized it is sufficient to use an
2669 // identity comparison.
2670 __ cmp(temp, Operand(class_name));
2671 // End with the answer in flags.
2675 void LCodeGen::DoClassOfTestAndBranch(LClassOfTestAndBranch* instr) {
2676 Register input = ToRegister(instr->value());
2677 Register temp = scratch0();
2678 Register temp2 = ToRegister(instr->temp());
2679 Handle<String> class_name = instr->hydrogen()->class_name();
2681 EmitClassOfTest(instr->TrueLabel(chunk_), instr->FalseLabel(chunk_),
2682 class_name, input, temp, temp2);
2684 EmitBranch(instr, eq);
2688 void LCodeGen::DoCmpMapAndBranch(LCmpMapAndBranch* instr) {
2689 Register reg = ToRegister(instr->value());
2690 Register temp = ToRegister(instr->temp());
2692 __ ldr(temp, FieldMemOperand(reg, HeapObject::kMapOffset));
2693 __ cmp(temp, Operand(instr->map()));
2694 EmitBranch(instr, eq);
2698 void LCodeGen::DoInstanceOf(LInstanceOf* instr) {
2699 DCHECK(ToRegister(instr->context()).is(cp));
2700 DCHECK(ToRegister(instr->left()).is(InstanceOfDescriptor::LeftRegister()));
2701 DCHECK(ToRegister(instr->right()).is(InstanceOfDescriptor::RightRegister()));
2702 DCHECK(ToRegister(instr->result()).is(r0));
2703 InstanceOfStub stub(isolate());
2704 CallCode(stub.GetCode(), RelocInfo::CODE_TARGET, instr);
2708 void LCodeGen::DoHasInPrototypeChainAndBranch(
2709 LHasInPrototypeChainAndBranch* instr) {
2710 Register const object = ToRegister(instr->object());
2711 Register const object_map = scratch0();
2712 Register const object_prototype = object_map;
2713 Register const prototype = ToRegister(instr->prototype());
2715 // The {object} must be a spec object. It's sufficient to know that {object}
2716 // is not a smi, since all other non-spec objects have {null} prototypes and
2717 // will be ruled out below.
2718 if (instr->hydrogen()->ObjectNeedsSmiCheck()) {
2720 EmitFalseBranch(instr, eq);
2723 // Loop through the {object}s prototype chain looking for the {prototype}.
2724 __ ldr(object_map, FieldMemOperand(object, HeapObject::kMapOffset));
2727 __ ldr(object_prototype, FieldMemOperand(object_map, Map::kPrototypeOffset));
2728 __ cmp(object_prototype, prototype);
2729 EmitTrueBranch(instr, eq);
2730 __ CompareRoot(object_prototype, Heap::kNullValueRootIndex);
2731 EmitFalseBranch(instr, eq);
2732 __ ldr(object_map, FieldMemOperand(object_prototype, HeapObject::kMapOffset));
2737 void LCodeGen::DoCmpT(LCmpT* instr) {
2738 DCHECK(ToRegister(instr->context()).is(cp));
2739 Token::Value op = instr->op();
2742 CodeFactory::CompareIC(isolate(), op, instr->strength()).code();
2743 CallCode(ic, RelocInfo::CODE_TARGET, instr);
2744 // This instruction also signals no smi code inlined.
2745 __ cmp(r0, Operand::Zero());
2747 Condition condition = ComputeCompareCondition(op);
2748 __ LoadRoot(ToRegister(instr->result()),
2749 Heap::kTrueValueRootIndex,
2751 __ LoadRoot(ToRegister(instr->result()),
2752 Heap::kFalseValueRootIndex,
2753 NegateCondition(condition));
2757 void LCodeGen::DoReturn(LReturn* instr) {
2758 if (FLAG_trace && info()->IsOptimizing()) {
2759 // Push the return value on the stack as the parameter.
2760 // Runtime::TraceExit returns its parameter in r0. We're leaving the code
2761 // managed by the register allocator and tearing down the frame, it's
2762 // safe to write to the context register.
2764 __ ldr(cp, MemOperand(fp, StandardFrameConstants::kContextOffset));
2765 __ CallRuntime(Runtime::kTraceExit, 1);
2767 if (info()->saves_caller_doubles()) {
2768 RestoreCallerDoubles();
2770 int no_frame_start = -1;
2771 if (NeedsEagerFrame()) {
2772 no_frame_start = masm_->LeaveFrame(StackFrame::JAVA_SCRIPT);
2774 { ConstantPoolUnavailableScope constant_pool_unavailable(masm());
2775 if (instr->has_constant_parameter_count()) {
2776 int parameter_count = ToInteger32(instr->constant_parameter_count());
2777 int32_t sp_delta = (parameter_count + 1) * kPointerSize;
2778 if (sp_delta != 0) {
2779 __ add(sp, sp, Operand(sp_delta));
2782 DCHECK(info()->IsStub()); // Functions would need to drop one more value.
2783 Register reg = ToRegister(instr->parameter_count());
2784 // The argument count parameter is a smi
2786 __ add(sp, sp, Operand(reg, LSL, kPointerSizeLog2));
2791 if (no_frame_start != -1) {
2792 info_->AddNoFrameRange(no_frame_start, masm_->pc_offset());
2799 void LCodeGen::EmitVectorLoadICRegisters(T* instr) {
2800 Register vector_register = ToRegister(instr->temp_vector());
2801 Register slot_register = LoadDescriptor::SlotRegister();
2802 DCHECK(vector_register.is(LoadWithVectorDescriptor::VectorRegister()));
2803 DCHECK(slot_register.is(r0));
2805 AllowDeferredHandleDereference vector_structure_check;
2806 Handle<TypeFeedbackVector> vector = instr->hydrogen()->feedback_vector();
2807 __ Move(vector_register, vector);
2808 // No need to allocate this register.
2809 FeedbackVectorICSlot slot = instr->hydrogen()->slot();
2810 int index = vector->GetIndex(slot);
2811 __ mov(slot_register, Operand(Smi::FromInt(index)));
2816 void LCodeGen::EmitVectorStoreICRegisters(T* instr) {
2817 Register vector_register = ToRegister(instr->temp_vector());
2818 Register slot_register = ToRegister(instr->temp_slot());
2820 AllowDeferredHandleDereference vector_structure_check;
2821 Handle<TypeFeedbackVector> vector = instr->hydrogen()->feedback_vector();
2822 __ Move(vector_register, vector);
2823 FeedbackVectorICSlot slot = instr->hydrogen()->slot();
2824 int index = vector->GetIndex(slot);
2825 __ mov(slot_register, Operand(Smi::FromInt(index)));
2829 void LCodeGen::DoLoadGlobalGeneric(LLoadGlobalGeneric* instr) {
2830 DCHECK(ToRegister(instr->context()).is(cp));
2831 DCHECK(ToRegister(instr->global_object())
2832 .is(LoadDescriptor::ReceiverRegister()));
2833 DCHECK(ToRegister(instr->result()).is(r0));
2835 __ mov(LoadDescriptor::NameRegister(), Operand(instr->name()));
2836 EmitVectorLoadICRegisters<LLoadGlobalGeneric>(instr);
2838 CodeFactory::LoadICInOptimizedCode(isolate(), instr->typeof_mode(),
2839 SLOPPY, PREMONOMORPHIC).code();
2840 CallCode(ic, RelocInfo::CODE_TARGET, instr);
2844 void LCodeGen::DoLoadGlobalViaContext(LLoadGlobalViaContext* instr) {
2845 DCHECK(ToRegister(instr->context()).is(cp));
2846 DCHECK(ToRegister(instr->result()).is(r0));
2848 int const slot = instr->slot_index();
2849 int const depth = instr->depth();
2850 if (depth <= LoadGlobalViaContextStub::kMaximumDepth) {
2851 __ mov(LoadGlobalViaContextDescriptor::SlotRegister(), Operand(slot));
2853 CodeFactory::LoadGlobalViaContext(isolate(), depth).code();
2854 CallCode(stub, RelocInfo::CODE_TARGET, instr);
2856 __ Push(Smi::FromInt(slot));
2857 __ CallRuntime(Runtime::kLoadGlobalViaContext, 1);
2862 void LCodeGen::DoLoadContextSlot(LLoadContextSlot* instr) {
2863 Register context = ToRegister(instr->context());
2864 Register result = ToRegister(instr->result());
2865 __ ldr(result, ContextOperand(context, instr->slot_index()));
2866 if (instr->hydrogen()->RequiresHoleCheck()) {
2867 __ LoadRoot(ip, Heap::kTheHoleValueRootIndex);
2869 if (instr->hydrogen()->DeoptimizesOnHole()) {
2870 DeoptimizeIf(eq, instr, Deoptimizer::kHole);
2872 __ mov(result, Operand(factory()->undefined_value()), LeaveCC, eq);
2878 void LCodeGen::DoStoreContextSlot(LStoreContextSlot* instr) {
2879 Register context = ToRegister(instr->context());
2880 Register value = ToRegister(instr->value());
2881 Register scratch = scratch0();
2882 MemOperand target = ContextOperand(context, instr->slot_index());
2884 Label skip_assignment;
2886 if (instr->hydrogen()->RequiresHoleCheck()) {
2887 __ ldr(scratch, target);
2888 __ LoadRoot(ip, Heap::kTheHoleValueRootIndex);
2889 __ cmp(scratch, ip);
2890 if (instr->hydrogen()->DeoptimizesOnHole()) {
2891 DeoptimizeIf(eq, instr, Deoptimizer::kHole);
2893 __ b(ne, &skip_assignment);
2897 __ str(value, target);
2898 if (instr->hydrogen()->NeedsWriteBarrier()) {
2899 SmiCheck check_needed =
2900 instr->hydrogen()->value()->type().IsHeapObject()
2901 ? OMIT_SMI_CHECK : INLINE_SMI_CHECK;
2902 __ RecordWriteContextSlot(context,
2906 GetLinkRegisterState(),
2908 EMIT_REMEMBERED_SET,
2912 __ bind(&skip_assignment);
2916 void LCodeGen::DoLoadNamedField(LLoadNamedField* instr) {
2917 HObjectAccess access = instr->hydrogen()->access();
2918 int offset = access.offset();
2919 Register object = ToRegister(instr->object());
2921 if (access.IsExternalMemory()) {
2922 Register result = ToRegister(instr->result());
2923 MemOperand operand = MemOperand(object, offset);
2924 __ Load(result, operand, access.representation());
2928 if (instr->hydrogen()->representation().IsDouble()) {
2929 DwVfpRegister result = ToDoubleRegister(instr->result());
2930 __ vldr(result, FieldMemOperand(object, offset));
2934 Register result = ToRegister(instr->result());
2935 if (!access.IsInobject()) {
2936 __ ldr(result, FieldMemOperand(object, JSObject::kPropertiesOffset));
2939 MemOperand operand = FieldMemOperand(object, offset);
2940 __ Load(result, operand, access.representation());
2944 void LCodeGen::DoLoadNamedGeneric(LLoadNamedGeneric* instr) {
2945 DCHECK(ToRegister(instr->context()).is(cp));
2946 DCHECK(ToRegister(instr->object()).is(LoadDescriptor::ReceiverRegister()));
2947 DCHECK(ToRegister(instr->result()).is(r0));
2949 // Name is always in r2.
2950 __ mov(LoadDescriptor::NameRegister(), Operand(instr->name()));
2951 EmitVectorLoadICRegisters<LLoadNamedGeneric>(instr);
2953 CodeFactory::LoadICInOptimizedCode(
2954 isolate(), NOT_INSIDE_TYPEOF, instr->hydrogen()->language_mode(),
2955 instr->hydrogen()->initialization_state()).code();
2956 CallCode(ic, RelocInfo::CODE_TARGET, instr, NEVER_INLINE_TARGET_ADDRESS);
2960 void LCodeGen::DoLoadFunctionPrototype(LLoadFunctionPrototype* instr) {
2961 Register scratch = scratch0();
2962 Register function = ToRegister(instr->function());
2963 Register result = ToRegister(instr->result());
2965 // Get the prototype or initial map from the function.
2967 FieldMemOperand(function, JSFunction::kPrototypeOrInitialMapOffset));
2969 // Check that the function has a prototype or an initial map.
2970 __ LoadRoot(ip, Heap::kTheHoleValueRootIndex);
2972 DeoptimizeIf(eq, instr, Deoptimizer::kHole);
2974 // If the function does not have an initial map, we're done.
2976 __ CompareObjectType(result, scratch, scratch, MAP_TYPE);
2979 // Get the prototype from the initial map.
2980 __ ldr(result, FieldMemOperand(result, Map::kPrototypeOffset));
2987 void LCodeGen::DoLoadRoot(LLoadRoot* instr) {
2988 Register result = ToRegister(instr->result());
2989 __ LoadRoot(result, instr->index());
2993 void LCodeGen::DoAccessArgumentsAt(LAccessArgumentsAt* instr) {
2994 Register arguments = ToRegister(instr->arguments());
2995 Register result = ToRegister(instr->result());
2996 // There are two words between the frame pointer and the last argument.
2997 // Subtracting from length accounts for one of them add one more.
2998 if (instr->length()->IsConstantOperand()) {
2999 int const_length = ToInteger32(LConstantOperand::cast(instr->length()));
3000 if (instr->index()->IsConstantOperand()) {
3001 int const_index = ToInteger32(LConstantOperand::cast(instr->index()));
3002 int index = (const_length - const_index) + 1;
3003 __ ldr(result, MemOperand(arguments, index * kPointerSize));
3005 Register index = ToRegister(instr->index());
3006 __ rsb(result, index, Operand(const_length + 1));
3007 __ ldr(result, MemOperand(arguments, result, LSL, kPointerSizeLog2));
3009 } else if (instr->index()->IsConstantOperand()) {
3010 Register length = ToRegister(instr->length());
3011 int const_index = ToInteger32(LConstantOperand::cast(instr->index()));
3012 int loc = const_index - 1;
3014 __ sub(result, length, Operand(loc));
3015 __ ldr(result, MemOperand(arguments, result, LSL, kPointerSizeLog2));
3017 __ ldr(result, MemOperand(arguments, length, LSL, kPointerSizeLog2));
3020 Register length = ToRegister(instr->length());
3021 Register index = ToRegister(instr->index());
3022 __ sub(result, length, index);
3023 __ add(result, result, Operand(1));
3024 __ ldr(result, MemOperand(arguments, result, LSL, kPointerSizeLog2));
3029 void LCodeGen::DoLoadKeyedExternalArray(LLoadKeyed* instr) {
3030 Register external_pointer = ToRegister(instr->elements());
3031 Register key = no_reg;
3032 ElementsKind elements_kind = instr->elements_kind();
3033 bool key_is_constant = instr->key()->IsConstantOperand();
3034 int constant_key = 0;
3035 if (key_is_constant) {
3036 constant_key = ToInteger32(LConstantOperand::cast(instr->key()));
3037 if (constant_key & 0xF0000000) {
3038 Abort(kArrayIndexConstantValueTooBig);
3041 key = ToRegister(instr->key());
3043 int element_size_shift = ElementsKindToShiftSize(elements_kind);
3044 int shift_size = (instr->hydrogen()->key()->representation().IsSmi())
3045 ? (element_size_shift - kSmiTagSize) : element_size_shift;
3046 int base_offset = instr->base_offset();
3048 if (elements_kind == FLOAT32_ELEMENTS || elements_kind == FLOAT64_ELEMENTS) {
3049 DwVfpRegister result = ToDoubleRegister(instr->result());
3050 Operand operand = key_is_constant
3051 ? Operand(constant_key << element_size_shift)
3052 : Operand(key, LSL, shift_size);
3053 __ add(scratch0(), external_pointer, operand);
3054 if (elements_kind == FLOAT32_ELEMENTS) {
3055 __ vldr(double_scratch0().low(), scratch0(), base_offset);
3056 __ vcvt_f64_f32(result, double_scratch0().low());
3057 } else { // i.e. elements_kind == EXTERNAL_DOUBLE_ELEMENTS
3058 __ vldr(result, scratch0(), base_offset);
3061 Register result = ToRegister(instr->result());
3062 MemOperand mem_operand = PrepareKeyedOperand(
3063 key, external_pointer, key_is_constant, constant_key,
3064 element_size_shift, shift_size, base_offset);
3065 switch (elements_kind) {
3067 __ ldrsb(result, mem_operand);
3069 case UINT8_ELEMENTS:
3070 case UINT8_CLAMPED_ELEMENTS:
3071 __ ldrb(result, mem_operand);
3073 case INT16_ELEMENTS:
3074 __ ldrsh(result, mem_operand);
3076 case UINT16_ELEMENTS:
3077 __ ldrh(result, mem_operand);
3079 case INT32_ELEMENTS:
3080 __ ldr(result, mem_operand);
3082 case UINT32_ELEMENTS:
3083 __ ldr(result, mem_operand);
3084 if (!instr->hydrogen()->CheckFlag(HInstruction::kUint32)) {
3085 __ cmp(result, Operand(0x80000000));
3086 DeoptimizeIf(cs, instr, Deoptimizer::kNegativeValue);
3089 case FLOAT32_ELEMENTS:
3090 case FLOAT64_ELEMENTS:
3091 case FAST_HOLEY_DOUBLE_ELEMENTS:
3092 case FAST_HOLEY_ELEMENTS:
3093 case FAST_HOLEY_SMI_ELEMENTS:
3094 case FAST_DOUBLE_ELEMENTS:
3096 case FAST_SMI_ELEMENTS:
3097 case DICTIONARY_ELEMENTS:
3098 case FAST_SLOPPY_ARGUMENTS_ELEMENTS:
3099 case SLOW_SLOPPY_ARGUMENTS_ELEMENTS:
3107 void LCodeGen::DoLoadKeyedFixedDoubleArray(LLoadKeyed* instr) {
3108 Register elements = ToRegister(instr->elements());
3109 bool key_is_constant = instr->key()->IsConstantOperand();
3110 Register key = no_reg;
3111 DwVfpRegister result = ToDoubleRegister(instr->result());
3112 Register scratch = scratch0();
3114 int element_size_shift = ElementsKindToShiftSize(FAST_DOUBLE_ELEMENTS);
3116 int base_offset = instr->base_offset();
3117 if (key_is_constant) {
3118 int constant_key = ToInteger32(LConstantOperand::cast(instr->key()));
3119 if (constant_key & 0xF0000000) {
3120 Abort(kArrayIndexConstantValueTooBig);
3122 base_offset += constant_key * kDoubleSize;
3124 __ add(scratch, elements, Operand(base_offset));
3126 if (!key_is_constant) {
3127 key = ToRegister(instr->key());
3128 int shift_size = (instr->hydrogen()->key()->representation().IsSmi())
3129 ? (element_size_shift - kSmiTagSize) : element_size_shift;
3130 __ add(scratch, scratch, Operand(key, LSL, shift_size));
3133 __ vldr(result, scratch, 0);
3135 if (instr->hydrogen()->RequiresHoleCheck()) {
3136 __ ldr(scratch, MemOperand(scratch, sizeof(kHoleNanLower32)));
3137 __ cmp(scratch, Operand(kHoleNanUpper32));
3138 DeoptimizeIf(eq, instr, Deoptimizer::kHole);
3143 void LCodeGen::DoLoadKeyedFixedArray(LLoadKeyed* instr) {
3144 Register elements = ToRegister(instr->elements());
3145 Register result = ToRegister(instr->result());
3146 Register scratch = scratch0();
3147 Register store_base = scratch;
3148 int offset = instr->base_offset();
3150 if (instr->key()->IsConstantOperand()) {
3151 LConstantOperand* const_operand = LConstantOperand::cast(instr->key());
3152 offset += ToInteger32(const_operand) * kPointerSize;
3153 store_base = elements;
3155 Register key = ToRegister(instr->key());
3156 // Even though the HLoadKeyed instruction forces the input
3157 // representation for the key to be an integer, the input gets replaced
3158 // during bound check elimination with the index argument to the bounds
3159 // check, which can be tagged, so that case must be handled here, too.
3160 if (instr->hydrogen()->key()->representation().IsSmi()) {
3161 __ add(scratch, elements, Operand::PointerOffsetFromSmiKey(key));
3163 __ add(scratch, elements, Operand(key, LSL, kPointerSizeLog2));
3166 __ ldr(result, MemOperand(store_base, offset));
3168 // Check for the hole value.
3169 if (instr->hydrogen()->RequiresHoleCheck()) {
3170 if (IsFastSmiElementsKind(instr->hydrogen()->elements_kind())) {
3172 DeoptimizeIf(ne, instr, Deoptimizer::kNotASmi);
3174 __ LoadRoot(scratch, Heap::kTheHoleValueRootIndex);
3175 __ cmp(result, scratch);
3176 DeoptimizeIf(eq, instr, Deoptimizer::kHole);
3178 } else if (instr->hydrogen()->hole_mode() == CONVERT_HOLE_TO_UNDEFINED) {
3179 DCHECK(instr->hydrogen()->elements_kind() == FAST_HOLEY_ELEMENTS);
3181 __ LoadRoot(scratch, Heap::kTheHoleValueRootIndex);
3182 __ cmp(result, scratch);
3184 if (info()->IsStub()) {
3185 // A stub can safely convert the hole to undefined only if the array
3186 // protector cell contains (Smi) Isolate::kArrayProtectorValid. Otherwise
3187 // it needs to bail out.
3188 __ LoadRoot(result, Heap::kArrayProtectorRootIndex);
3189 __ ldr(result, FieldMemOperand(result, Cell::kValueOffset));
3190 __ cmp(result, Operand(Smi::FromInt(Isolate::kArrayProtectorValid)));
3191 DeoptimizeIf(ne, instr, Deoptimizer::kHole);
3193 __ LoadRoot(result, Heap::kUndefinedValueRootIndex);
3199 void LCodeGen::DoLoadKeyed(LLoadKeyed* instr) {
3200 if (instr->is_fixed_typed_array()) {
3201 DoLoadKeyedExternalArray(instr);
3202 } else if (instr->hydrogen()->representation().IsDouble()) {
3203 DoLoadKeyedFixedDoubleArray(instr);
3205 DoLoadKeyedFixedArray(instr);
3210 MemOperand LCodeGen::PrepareKeyedOperand(Register key,
3212 bool key_is_constant,
3217 if (key_is_constant) {
3218 return MemOperand(base, (constant_key << element_size) + base_offset);
3221 if (base_offset == 0) {
3222 if (shift_size >= 0) {
3223 return MemOperand(base, key, LSL, shift_size);
3225 DCHECK_EQ(-1, shift_size);
3226 return MemOperand(base, key, LSR, 1);
3230 if (shift_size >= 0) {
3231 __ add(scratch0(), base, Operand(key, LSL, shift_size));
3232 return MemOperand(scratch0(), base_offset);
3234 DCHECK_EQ(-1, shift_size);
3235 __ add(scratch0(), base, Operand(key, ASR, 1));
3236 return MemOperand(scratch0(), base_offset);
3241 void LCodeGen::DoLoadKeyedGeneric(LLoadKeyedGeneric* instr) {
3242 DCHECK(ToRegister(instr->context()).is(cp));
3243 DCHECK(ToRegister(instr->object()).is(LoadDescriptor::ReceiverRegister()));
3244 DCHECK(ToRegister(instr->key()).is(LoadDescriptor::NameRegister()));
3246 if (instr->hydrogen()->HasVectorAndSlot()) {
3247 EmitVectorLoadICRegisters<LLoadKeyedGeneric>(instr);
3250 Handle<Code> ic = CodeFactory::KeyedLoadICInOptimizedCode(
3251 isolate(), instr->hydrogen()->language_mode(),
3252 instr->hydrogen()->initialization_state()).code();
3253 CallCode(ic, RelocInfo::CODE_TARGET, instr, NEVER_INLINE_TARGET_ADDRESS);
3257 void LCodeGen::DoArgumentsElements(LArgumentsElements* instr) {
3258 Register scratch = scratch0();
3259 Register result = ToRegister(instr->result());
3261 if (instr->hydrogen()->from_inlined()) {
3262 __ sub(result, sp, Operand(2 * kPointerSize));
3264 // Check if the calling frame is an arguments adaptor frame.
3265 Label done, adapted;
3266 __ ldr(scratch, MemOperand(fp, StandardFrameConstants::kCallerFPOffset));
3267 __ ldr(result, MemOperand(scratch, StandardFrameConstants::kContextOffset));
3268 __ cmp(result, Operand(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR)));
3270 // Result is the frame pointer for the frame if not adapted and for the real
3271 // frame below the adaptor frame if adapted.
3272 __ mov(result, fp, LeaveCC, ne);
3273 __ mov(result, scratch, LeaveCC, eq);
3278 void LCodeGen::DoArgumentsLength(LArgumentsLength* instr) {
3279 Register elem = ToRegister(instr->elements());
3280 Register result = ToRegister(instr->result());
3284 // If no arguments adaptor frame the number of arguments is fixed.
3286 __ mov(result, Operand(scope()->num_parameters()));
3289 // Arguments adaptor frame present. Get argument length from there.
3290 __ ldr(result, MemOperand(fp, StandardFrameConstants::kCallerFPOffset));
3292 MemOperand(result, ArgumentsAdaptorFrameConstants::kLengthOffset));
3293 __ SmiUntag(result);
3295 // Argument length is in result register.
3300 void LCodeGen::DoWrapReceiver(LWrapReceiver* instr) {
3301 Register receiver = ToRegister(instr->receiver());
3302 Register function = ToRegister(instr->function());
3303 Register result = ToRegister(instr->result());
3304 Register scratch = scratch0();
3306 // If the receiver is null or undefined, we have to pass the global
3307 // object as a receiver to normal functions. Values have to be
3308 // passed unchanged to builtins and strict-mode functions.
3309 Label global_object, result_in_receiver;
3311 if (!instr->hydrogen()->known_function()) {
3312 // Do not transform the receiver to object for strict mode
3315 FieldMemOperand(function, JSFunction::kSharedFunctionInfoOffset));
3317 FieldMemOperand(scratch, SharedFunctionInfo::kCompilerHintsOffset));
3318 int mask = 1 << (SharedFunctionInfo::kStrictModeFunction + kSmiTagSize);
3319 __ tst(scratch, Operand(mask));
3320 __ b(ne, &result_in_receiver);
3322 // Do not transform the receiver to object for builtins.
3323 __ tst(scratch, Operand(1 << (SharedFunctionInfo::kNative + kSmiTagSize)));
3324 __ b(ne, &result_in_receiver);
3327 // Normal function. Replace undefined or null with global receiver.
3328 __ LoadRoot(scratch, Heap::kNullValueRootIndex);
3329 __ cmp(receiver, scratch);
3330 __ b(eq, &global_object);
3331 __ LoadRoot(scratch, Heap::kUndefinedValueRootIndex);
3332 __ cmp(receiver, scratch);
3333 __ b(eq, &global_object);
3335 // Deoptimize if the receiver is not a JS object.
3336 __ SmiTst(receiver);
3337 DeoptimizeIf(eq, instr, Deoptimizer::kSmi);
3338 __ CompareObjectType(receiver, scratch, scratch, FIRST_SPEC_OBJECT_TYPE);
3339 DeoptimizeIf(lt, instr, Deoptimizer::kNotAJavaScriptObject);
3341 __ b(&result_in_receiver);
3342 __ bind(&global_object);
3343 __ ldr(result, FieldMemOperand(function, JSFunction::kContextOffset));
3345 ContextOperand(result, Context::GLOBAL_OBJECT_INDEX));
3346 __ ldr(result, FieldMemOperand(result, GlobalObject::kGlobalProxyOffset));
3348 if (result.is(receiver)) {
3349 __ bind(&result_in_receiver);
3353 __ bind(&result_in_receiver);
3354 __ mov(result, receiver);
3355 __ bind(&result_ok);
3360 void LCodeGen::DoApplyArguments(LApplyArguments* instr) {
3361 Register receiver = ToRegister(instr->receiver());
3362 Register function = ToRegister(instr->function());
3363 Register length = ToRegister(instr->length());
3364 Register elements = ToRegister(instr->elements());
3365 Register scratch = scratch0();
3366 DCHECK(receiver.is(r0)); // Used for parameter count.
3367 DCHECK(function.is(r1)); // Required by InvokeFunction.
3368 DCHECK(ToRegister(instr->result()).is(r0));
3370 // Copy the arguments to this function possibly from the
3371 // adaptor frame below it.
3372 const uint32_t kArgumentsLimit = 1 * KB;
3373 __ cmp(length, Operand(kArgumentsLimit));
3374 DeoptimizeIf(hi, instr, Deoptimizer::kTooManyArguments);
3376 // Push the receiver and use the register to keep the original
3377 // number of arguments.
3379 __ mov(receiver, length);
3380 // The arguments are at a one pointer size offset from elements.
3381 __ add(elements, elements, Operand(1 * kPointerSize));
3383 // Loop through the arguments pushing them onto the execution
3386 // length is a small non-negative integer, due to the test above.
3387 __ cmp(length, Operand::Zero());
3390 __ ldr(scratch, MemOperand(elements, length, LSL, 2));
3392 __ sub(length, length, Operand(1), SetCC);
3396 DCHECK(instr->HasPointerMap());
3397 LPointerMap* pointers = instr->pointer_map();
3398 SafepointGenerator safepoint_generator(
3399 this, pointers, Safepoint::kLazyDeopt);
3400 // The number of arguments is stored in receiver which is r0, as expected
3401 // by InvokeFunction.
3402 ParameterCount actual(receiver);
3403 __ InvokeFunction(function, actual, CALL_FUNCTION, safepoint_generator);
3407 void LCodeGen::DoPushArgument(LPushArgument* instr) {
3408 LOperand* argument = instr->value();
3409 if (argument->IsDoubleRegister() || argument->IsDoubleStackSlot()) {
3410 Abort(kDoPushArgumentNotImplementedForDoubleType);
3412 Register argument_reg = EmitLoadRegister(argument, ip);
3413 __ push(argument_reg);
3418 void LCodeGen::DoDrop(LDrop* instr) {
3419 __ Drop(instr->count());
3423 void LCodeGen::DoThisFunction(LThisFunction* instr) {
3424 Register result = ToRegister(instr->result());
3425 __ ldr(result, MemOperand(fp, JavaScriptFrameConstants::kFunctionOffset));
3429 void LCodeGen::DoContext(LContext* instr) {
3430 // If there is a non-return use, the context must be moved to a register.
3431 Register result = ToRegister(instr->result());
3432 if (info()->IsOptimizing()) {
3433 __ ldr(result, MemOperand(fp, StandardFrameConstants::kContextOffset));
3435 // If there is no frame, the context must be in cp.
3436 DCHECK(result.is(cp));
3441 void LCodeGen::DoDeclareGlobals(LDeclareGlobals* instr) {
3442 DCHECK(ToRegister(instr->context()).is(cp));
3443 __ Move(scratch0(), instr->hydrogen()->pairs());
3444 __ push(scratch0());
3445 __ mov(scratch0(), Operand(Smi::FromInt(instr->hydrogen()->flags())));
3446 __ push(scratch0());
3447 CallRuntime(Runtime::kDeclareGlobals, 2, instr);
3451 void LCodeGen::CallKnownFunction(Handle<JSFunction> function,
3452 int formal_parameter_count, int arity,
3453 LInstruction* instr) {
3454 bool dont_adapt_arguments =
3455 formal_parameter_count == SharedFunctionInfo::kDontAdaptArgumentsSentinel;
3456 bool can_invoke_directly =
3457 dont_adapt_arguments || formal_parameter_count == arity;
3459 Register function_reg = r1;
3461 LPointerMap* pointers = instr->pointer_map();
3463 if (can_invoke_directly) {
3465 __ ldr(cp, FieldMemOperand(function_reg, JSFunction::kContextOffset));
3467 // Always initialize r0 to the number of actual arguments.
3468 __ mov(r0, Operand(arity));
3471 __ ldr(ip, FieldMemOperand(function_reg, JSFunction::kCodeEntryOffset));
3474 // Set up deoptimization.
3475 RecordSafepointWithLazyDeopt(instr, RECORD_SIMPLE_SAFEPOINT);
3477 SafepointGenerator generator(this, pointers, Safepoint::kLazyDeopt);
3478 ParameterCount count(arity);
3479 ParameterCount expected(formal_parameter_count);
3480 __ InvokeFunction(function_reg, expected, count, CALL_FUNCTION, generator);
3485 void LCodeGen::DoDeferredMathAbsTaggedHeapNumber(LMathAbs* instr) {
3486 DCHECK(instr->context() != NULL);
3487 DCHECK(ToRegister(instr->context()).is(cp));
3488 Register input = ToRegister(instr->value());
3489 Register result = ToRegister(instr->result());
3490 Register scratch = scratch0();
3492 // Deoptimize if not a heap number.
3493 __ ldr(scratch, FieldMemOperand(input, HeapObject::kMapOffset));
3494 __ LoadRoot(ip, Heap::kHeapNumberMapRootIndex);
3495 __ cmp(scratch, Operand(ip));
3496 DeoptimizeIf(ne, instr, Deoptimizer::kNotAHeapNumber);
3499 Register exponent = scratch0();
3501 __ ldr(exponent, FieldMemOperand(input, HeapNumber::kExponentOffset));
3502 // Check the sign of the argument. If the argument is positive, just
3504 __ tst(exponent, Operand(HeapNumber::kSignMask));
3505 // Move the input to the result if necessary.
3506 __ Move(result, input);
3509 // Input is negative. Reverse its sign.
3510 // Preserve the value of all registers.
3512 PushSafepointRegistersScope scope(this);
3514 // Registers were saved at the safepoint, so we can use
3515 // many scratch registers.
3516 Register tmp1 = input.is(r1) ? r0 : r1;
3517 Register tmp2 = input.is(r2) ? r0 : r2;
3518 Register tmp3 = input.is(r3) ? r0 : r3;
3519 Register tmp4 = input.is(r4) ? r0 : r4;
3521 // exponent: floating point exponent value.
3523 Label allocated, slow;
3524 __ LoadRoot(tmp4, Heap::kHeapNumberMapRootIndex);
3525 __ AllocateHeapNumber(tmp1, tmp2, tmp3, tmp4, &slow);
3528 // Slow case: Call the runtime system to do the number allocation.
3531 CallRuntimeFromDeferred(Runtime::kAllocateHeapNumber, 0, instr,
3533 // Set the pointer to the new heap number in tmp.
3534 if (!tmp1.is(r0)) __ mov(tmp1, Operand(r0));
3535 // Restore input_reg after call to runtime.
3536 __ LoadFromSafepointRegisterSlot(input, input);
3537 __ ldr(exponent, FieldMemOperand(input, HeapNumber::kExponentOffset));
3539 __ bind(&allocated);
3540 // exponent: floating point exponent value.
3541 // tmp1: allocated heap number.
3542 __ bic(exponent, exponent, Operand(HeapNumber::kSignMask));
3543 __ str(exponent, FieldMemOperand(tmp1, HeapNumber::kExponentOffset));
3544 __ ldr(tmp2, FieldMemOperand(input, HeapNumber::kMantissaOffset));
3545 __ str(tmp2, FieldMemOperand(tmp1, HeapNumber::kMantissaOffset));
3547 __ StoreToSafepointRegisterSlot(tmp1, result);
3554 void LCodeGen::EmitIntegerMathAbs(LMathAbs* instr) {
3555 Register input = ToRegister(instr->value());
3556 Register result = ToRegister(instr->result());
3557 __ cmp(input, Operand::Zero());
3558 __ Move(result, input, pl);
3559 // We can make rsb conditional because the previous cmp instruction
3560 // will clear the V (overflow) flag and rsb won't set this flag
3561 // if input is positive.
3562 __ rsb(result, input, Operand::Zero(), SetCC, mi);
3563 // Deoptimize on overflow.
3564 DeoptimizeIf(vs, instr, Deoptimizer::kOverflow);
3568 void LCodeGen::DoMathAbs(LMathAbs* instr) {
3569 // Class for deferred case.
3570 class DeferredMathAbsTaggedHeapNumber final : public LDeferredCode {
3572 DeferredMathAbsTaggedHeapNumber(LCodeGen* codegen, LMathAbs* instr)
3573 : LDeferredCode(codegen), instr_(instr) { }
3574 void Generate() override {
3575 codegen()->DoDeferredMathAbsTaggedHeapNumber(instr_);
3577 LInstruction* instr() override { return instr_; }
3583 Representation r = instr->hydrogen()->value()->representation();
3585 DwVfpRegister input = ToDoubleRegister(instr->value());
3586 DwVfpRegister result = ToDoubleRegister(instr->result());
3587 __ vabs(result, input);
3588 } else if (r.IsSmiOrInteger32()) {
3589 EmitIntegerMathAbs(instr);
3591 // Representation is tagged.
3592 DeferredMathAbsTaggedHeapNumber* deferred =
3593 new(zone()) DeferredMathAbsTaggedHeapNumber(this, instr);
3594 Register input = ToRegister(instr->value());
3596 __ JumpIfNotSmi(input, deferred->entry());
3597 // If smi, handle it directly.
3598 EmitIntegerMathAbs(instr);
3599 __ bind(deferred->exit());
3604 void LCodeGen::DoMathFloor(LMathFloor* instr) {
3605 DwVfpRegister input = ToDoubleRegister(instr->value());
3606 Register result = ToRegister(instr->result());
3607 Register input_high = scratch0();
3610 __ TryInt32Floor(result, input, input_high, double_scratch0(), &done, &exact);
3611 DeoptimizeIf(al, instr, Deoptimizer::kLostPrecisionOrNaN);
3614 if (instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero)) {
3616 __ cmp(result, Operand::Zero());
3618 __ cmp(input_high, Operand::Zero());
3619 DeoptimizeIf(mi, instr, Deoptimizer::kMinusZero);
3625 void LCodeGen::DoMathRound(LMathRound* instr) {
3626 DwVfpRegister input = ToDoubleRegister(instr->value());
3627 Register result = ToRegister(instr->result());
3628 DwVfpRegister double_scratch1 = ToDoubleRegister(instr->temp());
3629 DwVfpRegister input_plus_dot_five = double_scratch1;
3630 Register input_high = scratch0();
3631 DwVfpRegister dot_five = double_scratch0();
3632 Label convert, done;
3634 __ Vmov(dot_five, 0.5, scratch0());
3635 __ vabs(double_scratch1, input);
3636 __ VFPCompareAndSetFlags(double_scratch1, dot_five);
3637 // If input is in [-0.5, -0], the result is -0.
3638 // If input is in [+0, +0.5[, the result is +0.
3639 // If the input is +0.5, the result is 1.
3640 __ b(hi, &convert); // Out of [-0.5, +0.5].
3641 if (instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero)) {
3642 __ VmovHigh(input_high, input);
3643 __ cmp(input_high, Operand::Zero());
3645 DeoptimizeIf(mi, instr, Deoptimizer::kMinusZero);
3647 __ VFPCompareAndSetFlags(input, dot_five);
3648 __ mov(result, Operand(1), LeaveCC, eq); // +0.5.
3649 // Remaining cases: [+0, +0.5[ or [-0.5, +0.5[, depending on
3650 // flag kBailoutOnMinusZero.
3651 __ mov(result, Operand::Zero(), LeaveCC, ne);
3655 __ vadd(input_plus_dot_five, input, dot_five);
3656 // Reuse dot_five (double_scratch0) as we no longer need this value.
3657 __ TryInt32Floor(result, input_plus_dot_five, input_high, double_scratch0(),
3659 DeoptimizeIf(al, instr, Deoptimizer::kLostPrecisionOrNaN);
3664 void LCodeGen::DoMathFround(LMathFround* instr) {
3665 DwVfpRegister input_reg = ToDoubleRegister(instr->value());
3666 DwVfpRegister output_reg = ToDoubleRegister(instr->result());
3667 LowDwVfpRegister scratch = double_scratch0();
3668 __ vcvt_f32_f64(scratch.low(), input_reg);
3669 __ vcvt_f64_f32(output_reg, scratch.low());
3673 void LCodeGen::DoMathSqrt(LMathSqrt* instr) {
3674 DwVfpRegister input = ToDoubleRegister(instr->value());
3675 DwVfpRegister result = ToDoubleRegister(instr->result());
3676 __ vsqrt(result, input);
3680 void LCodeGen::DoMathPowHalf(LMathPowHalf* instr) {
3681 DwVfpRegister input = ToDoubleRegister(instr->value());
3682 DwVfpRegister result = ToDoubleRegister(instr->result());
3683 DwVfpRegister temp = double_scratch0();
3685 // Note that according to ECMA-262 15.8.2.13:
3686 // Math.pow(-Infinity, 0.5) == Infinity
3687 // Math.sqrt(-Infinity) == NaN
3689 __ vmov(temp, -V8_INFINITY, scratch0());
3690 __ VFPCompareAndSetFlags(input, temp);
3691 __ vneg(result, temp, eq);
3694 // Add +0 to convert -0 to +0.
3695 __ vadd(result, input, kDoubleRegZero);
3696 __ vsqrt(result, result);
3701 void LCodeGen::DoPower(LPower* instr) {
3702 Representation exponent_type = instr->hydrogen()->right()->representation();
3703 // Having marked this as a call, we can use any registers.
3704 // Just make sure that the input/output registers are the expected ones.
3705 Register tagged_exponent = MathPowTaggedDescriptor::exponent();
3706 DCHECK(!instr->right()->IsDoubleRegister() ||
3707 ToDoubleRegister(instr->right()).is(d1));
3708 DCHECK(!instr->right()->IsRegister() ||
3709 ToRegister(instr->right()).is(tagged_exponent));
3710 DCHECK(ToDoubleRegister(instr->left()).is(d0));
3711 DCHECK(ToDoubleRegister(instr->result()).is(d2));
3713 if (exponent_type.IsSmi()) {
3714 MathPowStub stub(isolate(), MathPowStub::TAGGED);
3716 } else if (exponent_type.IsTagged()) {
3718 __ JumpIfSmi(tagged_exponent, &no_deopt);
3719 DCHECK(!r6.is(tagged_exponent));
3720 __ ldr(r6, FieldMemOperand(tagged_exponent, HeapObject::kMapOffset));
3721 __ LoadRoot(ip, Heap::kHeapNumberMapRootIndex);
3722 __ cmp(r6, Operand(ip));
3723 DeoptimizeIf(ne, instr, Deoptimizer::kNotAHeapNumber);
3725 MathPowStub stub(isolate(), MathPowStub::TAGGED);
3727 } else if (exponent_type.IsInteger32()) {
3728 MathPowStub stub(isolate(), MathPowStub::INTEGER);
3731 DCHECK(exponent_type.IsDouble());
3732 MathPowStub stub(isolate(), MathPowStub::DOUBLE);
3738 void LCodeGen::DoMathExp(LMathExp* instr) {
3739 DwVfpRegister input = ToDoubleRegister(instr->value());
3740 DwVfpRegister result = ToDoubleRegister(instr->result());
3741 DwVfpRegister double_scratch1 = ToDoubleRegister(instr->double_temp());
3742 DwVfpRegister double_scratch2 = double_scratch0();
3743 Register temp1 = ToRegister(instr->temp1());
3744 Register temp2 = ToRegister(instr->temp2());
3746 MathExpGenerator::EmitMathExp(
3747 masm(), input, result, double_scratch1, double_scratch2,
3748 temp1, temp2, scratch0());
3752 void LCodeGen::DoMathLog(LMathLog* instr) {
3753 __ PrepareCallCFunction(0, 1, scratch0());
3754 __ MovToFloatParameter(ToDoubleRegister(instr->value()));
3755 __ CallCFunction(ExternalReference::math_log_double_function(isolate()),
3757 __ MovFromFloatResult(ToDoubleRegister(instr->result()));
3761 void LCodeGen::DoMathClz32(LMathClz32* instr) {
3762 Register input = ToRegister(instr->value());
3763 Register result = ToRegister(instr->result());
3764 __ clz(result, input);
3768 void LCodeGen::DoInvokeFunction(LInvokeFunction* instr) {
3769 DCHECK(ToRegister(instr->context()).is(cp));
3770 DCHECK(ToRegister(instr->function()).is(r1));
3771 DCHECK(instr->HasPointerMap());
3773 Handle<JSFunction> known_function = instr->hydrogen()->known_function();
3774 if (known_function.is_null()) {
3775 LPointerMap* pointers = instr->pointer_map();
3776 SafepointGenerator generator(this, pointers, Safepoint::kLazyDeopt);
3777 ParameterCount count(instr->arity());
3778 __ InvokeFunction(r1, count, CALL_FUNCTION, generator);
3780 CallKnownFunction(known_function,
3781 instr->hydrogen()->formal_parameter_count(),
3782 instr->arity(), instr);
3787 void LCodeGen::DoCallWithDescriptor(LCallWithDescriptor* instr) {
3788 DCHECK(ToRegister(instr->result()).is(r0));
3790 if (instr->hydrogen()->IsTailCall()) {
3791 if (NeedsEagerFrame()) __ LeaveFrame(StackFrame::INTERNAL);
3793 if (instr->target()->IsConstantOperand()) {
3794 LConstantOperand* target = LConstantOperand::cast(instr->target());
3795 Handle<Code> code = Handle<Code>::cast(ToHandle(target));
3796 __ Jump(code, RelocInfo::CODE_TARGET);
3798 DCHECK(instr->target()->IsRegister());
3799 Register target = ToRegister(instr->target());
3800 // Make sure we don't emit any additional entries in the constant pool
3801 // before the call to ensure that the CallCodeSize() calculated the
3803 // number of instructions for the constant pool load.
3805 ConstantPoolUnavailableScope constant_pool_unavailable(masm_);
3806 __ add(target, target, Operand(Code::kHeaderSize - kHeapObjectTag));
3811 LPointerMap* pointers = instr->pointer_map();
3812 SafepointGenerator generator(this, pointers, Safepoint::kLazyDeopt);
3814 if (instr->target()->IsConstantOperand()) {
3815 LConstantOperand* target = LConstantOperand::cast(instr->target());
3816 Handle<Code> code = Handle<Code>::cast(ToHandle(target));
3817 generator.BeforeCall(__ CallSize(code, RelocInfo::CODE_TARGET));
3818 PlatformInterfaceDescriptor* call_descriptor =
3819 instr->descriptor().platform_specific_descriptor();
3820 if (call_descriptor != NULL) {
3821 __ Call(code, RelocInfo::CODE_TARGET, TypeFeedbackId::None(), al,
3822 call_descriptor->storage_mode());
3824 __ Call(code, RelocInfo::CODE_TARGET, TypeFeedbackId::None(), al);
3827 DCHECK(instr->target()->IsRegister());
3828 Register target = ToRegister(instr->target());
3829 generator.BeforeCall(__ CallSize(target));
3830 // Make sure we don't emit any additional entries in the constant pool
3831 // before the call to ensure that the CallCodeSize() calculated the
3833 // number of instructions for the constant pool load.
3835 ConstantPoolUnavailableScope constant_pool_unavailable(masm_);
3836 __ add(target, target, Operand(Code::kHeaderSize - kHeapObjectTag));
3840 generator.AfterCall();
3845 void LCodeGen::DoCallJSFunction(LCallJSFunction* instr) {
3846 DCHECK(ToRegister(instr->function()).is(r1));
3847 DCHECK(ToRegister(instr->result()).is(r0));
3849 __ mov(r0, Operand(instr->arity()));
3852 __ ldr(cp, FieldMemOperand(r1, JSFunction::kContextOffset));
3854 // Load the code entry address
3855 __ ldr(ip, FieldMemOperand(r1, JSFunction::kCodeEntryOffset));
3858 RecordSafepointWithLazyDeopt(instr, RECORD_SIMPLE_SAFEPOINT);
3862 void LCodeGen::DoCallFunction(LCallFunction* instr) {
3863 DCHECK(ToRegister(instr->context()).is(cp));
3864 DCHECK(ToRegister(instr->function()).is(r1));
3865 DCHECK(ToRegister(instr->result()).is(r0));
3867 int arity = instr->arity();
3868 CallFunctionFlags flags = instr->hydrogen()->function_flags();
3869 if (instr->hydrogen()->HasVectorAndSlot()) {
3870 Register slot_register = ToRegister(instr->temp_slot());
3871 Register vector_register = ToRegister(instr->temp_vector());
3872 DCHECK(slot_register.is(r3));
3873 DCHECK(vector_register.is(r2));
3875 AllowDeferredHandleDereference vector_structure_check;
3876 Handle<TypeFeedbackVector> vector = instr->hydrogen()->feedback_vector();
3877 int index = vector->GetIndex(instr->hydrogen()->slot());
3879 __ Move(vector_register, vector);
3880 __ mov(slot_register, Operand(Smi::FromInt(index)));
3882 CallICState::CallType call_type =
3883 (flags & CALL_AS_METHOD) ? CallICState::METHOD : CallICState::FUNCTION;
3886 CodeFactory::CallICInOptimizedCode(isolate(), arity, call_type).code();
3887 CallCode(ic, RelocInfo::CODE_TARGET, instr);
3889 CallFunctionStub stub(isolate(), arity, flags);
3890 CallCode(stub.GetCode(), RelocInfo::CODE_TARGET, instr);
3895 void LCodeGen::DoCallNew(LCallNew* instr) {
3896 DCHECK(ToRegister(instr->context()).is(cp));
3897 DCHECK(ToRegister(instr->constructor()).is(r1));
3898 DCHECK(ToRegister(instr->result()).is(r0));
3900 __ mov(r0, Operand(instr->arity()));
3901 // No cell in r2 for construct type feedback in optimized code
3902 __ LoadRoot(r2, Heap::kUndefinedValueRootIndex);
3903 CallConstructStub stub(isolate(), NO_CALL_CONSTRUCTOR_FLAGS);
3904 CallCode(stub.GetCode(), RelocInfo::CONSTRUCT_CALL, instr);
3908 void LCodeGen::DoCallNewArray(LCallNewArray* instr) {
3909 DCHECK(ToRegister(instr->context()).is(cp));
3910 DCHECK(ToRegister(instr->constructor()).is(r1));
3911 DCHECK(ToRegister(instr->result()).is(r0));
3913 __ mov(r0, Operand(instr->arity()));
3914 if (instr->arity() == 1) {
3915 // We only need the allocation site for the case we have a length argument.
3916 // The case may bail out to the runtime, which will determine the correct
3917 // elements kind with the site.
3918 __ Move(r2, instr->hydrogen()->site());
3920 __ LoadRoot(r2, Heap::kUndefinedValueRootIndex);
3922 ElementsKind kind = instr->hydrogen()->elements_kind();
3923 AllocationSiteOverrideMode override_mode =
3924 (AllocationSite::GetMode(kind) == TRACK_ALLOCATION_SITE)
3925 ? DISABLE_ALLOCATION_SITES
3928 if (instr->arity() == 0) {
3929 ArrayNoArgumentConstructorStub stub(isolate(), kind, override_mode);
3930 CallCode(stub.GetCode(), RelocInfo::CONSTRUCT_CALL, instr);
3931 } else if (instr->arity() == 1) {
3933 if (IsFastPackedElementsKind(kind)) {
3935 // We might need a change here
3936 // look at the first argument
3937 __ ldr(r5, MemOperand(sp, 0));
3938 __ cmp(r5, Operand::Zero());
3939 __ b(eq, &packed_case);
3941 ElementsKind holey_kind = GetHoleyElementsKind(kind);
3942 ArraySingleArgumentConstructorStub stub(isolate(),
3945 CallCode(stub.GetCode(), RelocInfo::CONSTRUCT_CALL, instr);
3947 __ bind(&packed_case);
3950 ArraySingleArgumentConstructorStub stub(isolate(), kind, override_mode);
3951 CallCode(stub.GetCode(), RelocInfo::CONSTRUCT_CALL, instr);
3954 ArrayNArgumentsConstructorStub stub(isolate(), kind, override_mode);
3955 CallCode(stub.GetCode(), RelocInfo::CONSTRUCT_CALL, instr);
3960 void LCodeGen::DoCallRuntime(LCallRuntime* instr) {
3961 CallRuntime(instr->function(), instr->arity(), instr);
3965 void LCodeGen::DoStoreCodeEntry(LStoreCodeEntry* instr) {
3966 Register function = ToRegister(instr->function());
3967 Register code_object = ToRegister(instr->code_object());
3968 __ add(code_object, code_object, Operand(Code::kHeaderSize - kHeapObjectTag));
3970 FieldMemOperand(function, JSFunction::kCodeEntryOffset));
3974 void LCodeGen::DoInnerAllocatedObject(LInnerAllocatedObject* instr) {
3975 Register result = ToRegister(instr->result());
3976 Register base = ToRegister(instr->base_object());
3977 if (instr->offset()->IsConstantOperand()) {
3978 LConstantOperand* offset = LConstantOperand::cast(instr->offset());
3979 __ add(result, base, Operand(ToInteger32(offset)));
3981 Register offset = ToRegister(instr->offset());
3982 __ add(result, base, offset);
3987 void LCodeGen::DoStoreNamedField(LStoreNamedField* instr) {
3988 Representation representation = instr->representation();
3990 Register object = ToRegister(instr->object());
3991 Register scratch = scratch0();
3992 HObjectAccess access = instr->hydrogen()->access();
3993 int offset = access.offset();
3995 if (access.IsExternalMemory()) {
3996 Register value = ToRegister(instr->value());
3997 MemOperand operand = MemOperand(object, offset);
3998 __ Store(value, operand, representation);
4002 __ AssertNotSmi(object);
4004 DCHECK(!representation.IsSmi() ||
4005 !instr->value()->IsConstantOperand() ||
4006 IsSmi(LConstantOperand::cast(instr->value())));
4007 if (representation.IsDouble()) {
4008 DCHECK(access.IsInobject());
4009 DCHECK(!instr->hydrogen()->has_transition());
4010 DCHECK(!instr->hydrogen()->NeedsWriteBarrier());
4011 DwVfpRegister value = ToDoubleRegister(instr->value());
4012 __ vstr(value, FieldMemOperand(object, offset));
4016 if (instr->hydrogen()->has_transition()) {
4017 Handle<Map> transition = instr->hydrogen()->transition_map();
4018 AddDeprecationDependency(transition);
4019 __ mov(scratch, Operand(transition));
4020 __ str(scratch, FieldMemOperand(object, HeapObject::kMapOffset));
4021 if (instr->hydrogen()->NeedsWriteBarrierForMap()) {
4022 Register temp = ToRegister(instr->temp());
4023 // Update the write barrier for the map field.
4024 __ RecordWriteForMap(object,
4027 GetLinkRegisterState(),
4033 Register value = ToRegister(instr->value());
4034 if (access.IsInobject()) {
4035 MemOperand operand = FieldMemOperand(object, offset);
4036 __ Store(value, operand, representation);
4037 if (instr->hydrogen()->NeedsWriteBarrier()) {
4038 // Update the write barrier for the object for in-object properties.
4039 __ RecordWriteField(object,
4043 GetLinkRegisterState(),
4045 EMIT_REMEMBERED_SET,
4046 instr->hydrogen()->SmiCheckForWriteBarrier(),
4047 instr->hydrogen()->PointersToHereCheckForValue());
4050 __ ldr(scratch, FieldMemOperand(object, JSObject::kPropertiesOffset));
4051 MemOperand operand = FieldMemOperand(scratch, offset);
4052 __ Store(value, operand, representation);
4053 if (instr->hydrogen()->NeedsWriteBarrier()) {
4054 // Update the write barrier for the properties array.
4055 // object is used as a scratch register.
4056 __ RecordWriteField(scratch,
4060 GetLinkRegisterState(),
4062 EMIT_REMEMBERED_SET,
4063 instr->hydrogen()->SmiCheckForWriteBarrier(),
4064 instr->hydrogen()->PointersToHereCheckForValue());
4070 void LCodeGen::DoStoreNamedGeneric(LStoreNamedGeneric* instr) {
4071 DCHECK(ToRegister(instr->context()).is(cp));
4072 DCHECK(ToRegister(instr->object()).is(StoreDescriptor::ReceiverRegister()));
4073 DCHECK(ToRegister(instr->value()).is(StoreDescriptor::ValueRegister()));
4075 if (instr->hydrogen()->HasVectorAndSlot()) {
4076 EmitVectorStoreICRegisters<LStoreNamedGeneric>(instr);
4079 __ mov(StoreDescriptor::NameRegister(), Operand(instr->name()));
4080 Handle<Code> ic = CodeFactory::StoreICInOptimizedCode(
4081 isolate(), instr->language_mode(),
4082 instr->hydrogen()->initialization_state()).code();
4083 CallCode(ic, RelocInfo::CODE_TARGET, instr, NEVER_INLINE_TARGET_ADDRESS);
4087 void LCodeGen::DoStoreGlobalViaContext(LStoreGlobalViaContext* instr) {
4088 DCHECK(ToRegister(instr->context()).is(cp));
4089 DCHECK(ToRegister(instr->value())
4090 .is(StoreGlobalViaContextDescriptor::ValueRegister()));
4092 int const slot = instr->slot_index();
4093 int const depth = instr->depth();
4094 if (depth <= StoreGlobalViaContextStub::kMaximumDepth) {
4095 __ mov(StoreGlobalViaContextDescriptor::SlotRegister(), Operand(slot));
4096 Handle<Code> stub = CodeFactory::StoreGlobalViaContext(
4097 isolate(), depth, instr->language_mode())
4099 CallCode(stub, RelocInfo::CODE_TARGET, instr);
4101 __ Push(Smi::FromInt(slot));
4102 __ push(StoreGlobalViaContextDescriptor::ValueRegister());
4103 __ CallRuntime(is_strict(instr->language_mode())
4104 ? Runtime::kStoreGlobalViaContext_Strict
4105 : Runtime::kStoreGlobalViaContext_Sloppy,
4111 void LCodeGen::DoBoundsCheck(LBoundsCheck* instr) {
4112 Condition cc = instr->hydrogen()->allow_equality() ? hi : hs;
4113 if (instr->index()->IsConstantOperand()) {
4114 Operand index = ToOperand(instr->index());
4115 Register length = ToRegister(instr->length());
4116 __ cmp(length, index);
4117 cc = CommuteCondition(cc);
4119 Register index = ToRegister(instr->index());
4120 Operand length = ToOperand(instr->length());
4121 __ cmp(index, length);
4123 if (FLAG_debug_code && instr->hydrogen()->skip_check()) {
4125 __ b(NegateCondition(cc), &done);
4126 __ stop("eliminated bounds check failed");
4129 DeoptimizeIf(cc, instr, Deoptimizer::kOutOfBounds);
4134 void LCodeGen::DoStoreKeyedExternalArray(LStoreKeyed* instr) {
4135 Register external_pointer = ToRegister(instr->elements());
4136 Register key = no_reg;
4137 ElementsKind elements_kind = instr->elements_kind();
4138 bool key_is_constant = instr->key()->IsConstantOperand();
4139 int constant_key = 0;
4140 if (key_is_constant) {
4141 constant_key = ToInteger32(LConstantOperand::cast(instr->key()));
4142 if (constant_key & 0xF0000000) {
4143 Abort(kArrayIndexConstantValueTooBig);
4146 key = ToRegister(instr->key());
4148 int element_size_shift = ElementsKindToShiftSize(elements_kind);
4149 int shift_size = (instr->hydrogen()->key()->representation().IsSmi())
4150 ? (element_size_shift - kSmiTagSize) : element_size_shift;
4151 int base_offset = instr->base_offset();
4153 if (elements_kind == FLOAT32_ELEMENTS || elements_kind == FLOAT64_ELEMENTS) {
4154 Register address = scratch0();
4155 DwVfpRegister value(ToDoubleRegister(instr->value()));
4156 if (key_is_constant) {
4157 if (constant_key != 0) {
4158 __ add(address, external_pointer,
4159 Operand(constant_key << element_size_shift));
4161 address = external_pointer;
4164 __ add(address, external_pointer, Operand(key, LSL, shift_size));
4166 if (elements_kind == FLOAT32_ELEMENTS) {
4167 __ vcvt_f32_f64(double_scratch0().low(), value);
4168 __ vstr(double_scratch0().low(), address, base_offset);
4169 } else { // Storing doubles, not floats.
4170 __ vstr(value, address, base_offset);
4173 Register value(ToRegister(instr->value()));
4174 MemOperand mem_operand = PrepareKeyedOperand(
4175 key, external_pointer, key_is_constant, constant_key,
4176 element_size_shift, shift_size,
4178 switch (elements_kind) {
4179 case UINT8_ELEMENTS:
4180 case UINT8_CLAMPED_ELEMENTS:
4182 __ strb(value, mem_operand);
4184 case INT16_ELEMENTS:
4185 case UINT16_ELEMENTS:
4186 __ strh(value, mem_operand);
4188 case INT32_ELEMENTS:
4189 case UINT32_ELEMENTS:
4190 __ str(value, mem_operand);
4192 case FLOAT32_ELEMENTS:
4193 case FLOAT64_ELEMENTS:
4194 case FAST_DOUBLE_ELEMENTS:
4196 case FAST_SMI_ELEMENTS:
4197 case FAST_HOLEY_DOUBLE_ELEMENTS:
4198 case FAST_HOLEY_ELEMENTS:
4199 case FAST_HOLEY_SMI_ELEMENTS:
4200 case DICTIONARY_ELEMENTS:
4201 case FAST_SLOPPY_ARGUMENTS_ELEMENTS:
4202 case SLOW_SLOPPY_ARGUMENTS_ELEMENTS:
4210 void LCodeGen::DoStoreKeyedFixedDoubleArray(LStoreKeyed* instr) {
4211 DwVfpRegister value = ToDoubleRegister(instr->value());
4212 Register elements = ToRegister(instr->elements());
4213 Register scratch = scratch0();
4214 DwVfpRegister double_scratch = double_scratch0();
4215 bool key_is_constant = instr->key()->IsConstantOperand();
4216 int base_offset = instr->base_offset();
4218 // Calculate the effective address of the slot in the array to store the
4220 int element_size_shift = ElementsKindToShiftSize(FAST_DOUBLE_ELEMENTS);
4221 if (key_is_constant) {
4222 int constant_key = ToInteger32(LConstantOperand::cast(instr->key()));
4223 if (constant_key & 0xF0000000) {
4224 Abort(kArrayIndexConstantValueTooBig);
4226 __ add(scratch, elements,
4227 Operand((constant_key << element_size_shift) + base_offset));
4229 int shift_size = (instr->hydrogen()->key()->representation().IsSmi())
4230 ? (element_size_shift - kSmiTagSize) : element_size_shift;
4231 __ add(scratch, elements, Operand(base_offset));
4232 __ add(scratch, scratch,
4233 Operand(ToRegister(instr->key()), LSL, shift_size));
4236 if (instr->NeedsCanonicalization()) {
4237 // Force a canonical NaN.
4238 if (masm()->emit_debug_code()) {
4240 __ tst(ip, Operand(kVFPDefaultNaNModeControlBit));
4241 __ Assert(ne, kDefaultNaNModeNotSet);
4243 __ VFPCanonicalizeNaN(double_scratch, value);
4244 __ vstr(double_scratch, scratch, 0);
4246 __ vstr(value, scratch, 0);
4251 void LCodeGen::DoStoreKeyedFixedArray(LStoreKeyed* instr) {
4252 Register value = ToRegister(instr->value());
4253 Register elements = ToRegister(instr->elements());
4254 Register key = instr->key()->IsRegister() ? ToRegister(instr->key())
4256 Register scratch = scratch0();
4257 Register store_base = scratch;
4258 int offset = instr->base_offset();
4261 if (instr->key()->IsConstantOperand()) {
4262 DCHECK(!instr->hydrogen()->NeedsWriteBarrier());
4263 LConstantOperand* const_operand = LConstantOperand::cast(instr->key());
4264 offset += ToInteger32(const_operand) * kPointerSize;
4265 store_base = elements;
4267 // Even though the HLoadKeyed instruction forces the input
4268 // representation for the key to be an integer, the input gets replaced
4269 // during bound check elimination with the index argument to the bounds
4270 // check, which can be tagged, so that case must be handled here, too.
4271 if (instr->hydrogen()->key()->representation().IsSmi()) {
4272 __ add(scratch, elements, Operand::PointerOffsetFromSmiKey(key));
4274 __ add(scratch, elements, Operand(key, LSL, kPointerSizeLog2));
4277 __ str(value, MemOperand(store_base, offset));
4279 if (instr->hydrogen()->NeedsWriteBarrier()) {
4280 SmiCheck check_needed =
4281 instr->hydrogen()->value()->type().IsHeapObject()
4282 ? OMIT_SMI_CHECK : INLINE_SMI_CHECK;
4283 // Compute address of modified element and store it into key register.
4284 __ add(key, store_base, Operand(offset));
4285 __ RecordWrite(elements,
4288 GetLinkRegisterState(),
4290 EMIT_REMEMBERED_SET,
4292 instr->hydrogen()->PointersToHereCheckForValue());
4297 void LCodeGen::DoStoreKeyed(LStoreKeyed* instr) {
4298 // By cases: external, fast double
4299 if (instr->is_fixed_typed_array()) {
4300 DoStoreKeyedExternalArray(instr);
4301 } else if (instr->hydrogen()->value()->representation().IsDouble()) {
4302 DoStoreKeyedFixedDoubleArray(instr);
4304 DoStoreKeyedFixedArray(instr);
4309 void LCodeGen::DoStoreKeyedGeneric(LStoreKeyedGeneric* instr) {
4310 DCHECK(ToRegister(instr->context()).is(cp));
4311 DCHECK(ToRegister(instr->object()).is(StoreDescriptor::ReceiverRegister()));
4312 DCHECK(ToRegister(instr->key()).is(StoreDescriptor::NameRegister()));
4313 DCHECK(ToRegister(instr->value()).is(StoreDescriptor::ValueRegister()));
4315 if (instr->hydrogen()->HasVectorAndSlot()) {
4316 EmitVectorStoreICRegisters<LStoreKeyedGeneric>(instr);
4319 Handle<Code> ic = CodeFactory::KeyedStoreICInOptimizedCode(
4320 isolate(), instr->language_mode(),
4321 instr->hydrogen()->initialization_state()).code();
4322 CallCode(ic, RelocInfo::CODE_TARGET, instr, NEVER_INLINE_TARGET_ADDRESS);
4326 void LCodeGen::DoMaybeGrowElements(LMaybeGrowElements* instr) {
4327 class DeferredMaybeGrowElements final : public LDeferredCode {
4329 DeferredMaybeGrowElements(LCodeGen* codegen, LMaybeGrowElements* instr)
4330 : LDeferredCode(codegen), instr_(instr) {}
4331 void Generate() override { codegen()->DoDeferredMaybeGrowElements(instr_); }
4332 LInstruction* instr() override { return instr_; }
4335 LMaybeGrowElements* instr_;
4338 Register result = r0;
4339 DeferredMaybeGrowElements* deferred =
4340 new (zone()) DeferredMaybeGrowElements(this, instr);
4341 LOperand* key = instr->key();
4342 LOperand* current_capacity = instr->current_capacity();
4344 DCHECK(instr->hydrogen()->key()->representation().IsInteger32());
4345 DCHECK(instr->hydrogen()->current_capacity()->representation().IsInteger32());
4346 DCHECK(key->IsConstantOperand() || key->IsRegister());
4347 DCHECK(current_capacity->IsConstantOperand() ||
4348 current_capacity->IsRegister());
4350 if (key->IsConstantOperand() && current_capacity->IsConstantOperand()) {
4351 int32_t constant_key = ToInteger32(LConstantOperand::cast(key));
4352 int32_t constant_capacity =
4353 ToInteger32(LConstantOperand::cast(current_capacity));
4354 if (constant_key >= constant_capacity) {
4356 __ jmp(deferred->entry());
4358 } else if (key->IsConstantOperand()) {
4359 int32_t constant_key = ToInteger32(LConstantOperand::cast(key));
4360 __ cmp(ToRegister(current_capacity), Operand(constant_key));
4361 __ b(le, deferred->entry());
4362 } else if (current_capacity->IsConstantOperand()) {
4363 int32_t constant_capacity =
4364 ToInteger32(LConstantOperand::cast(current_capacity));
4365 __ cmp(ToRegister(key), Operand(constant_capacity));
4366 __ b(ge, deferred->entry());
4368 __ cmp(ToRegister(key), ToRegister(current_capacity));
4369 __ b(ge, deferred->entry());
4372 if (instr->elements()->IsRegister()) {
4373 __ Move(result, ToRegister(instr->elements()));
4375 __ ldr(result, ToMemOperand(instr->elements()));
4378 __ bind(deferred->exit());
4382 void LCodeGen::DoDeferredMaybeGrowElements(LMaybeGrowElements* instr) {
4383 // TODO(3095996): Get rid of this. For now, we need to make the
4384 // result register contain a valid pointer because it is already
4385 // contained in the register pointer map.
4386 Register result = r0;
4387 __ mov(result, Operand::Zero());
4389 // We have to call a stub.
4391 PushSafepointRegistersScope scope(this);
4392 if (instr->object()->IsRegister()) {
4393 __ Move(result, ToRegister(instr->object()));
4395 __ ldr(result, ToMemOperand(instr->object()));
4398 LOperand* key = instr->key();
4399 if (key->IsConstantOperand()) {
4400 __ Move(r3, Operand(ToSmi(LConstantOperand::cast(key))));
4402 __ Move(r3, ToRegister(key));
4406 GrowArrayElementsStub stub(isolate(), instr->hydrogen()->is_js_array(),
4407 instr->hydrogen()->kind());
4409 RecordSafepointWithLazyDeopt(
4410 instr, RECORD_SAFEPOINT_WITH_REGISTERS_AND_NO_ARGUMENTS);
4411 __ StoreToSafepointRegisterSlot(result, result);
4414 // Deopt on smi, which means the elements array changed to dictionary mode.
4416 DeoptimizeIf(eq, instr, Deoptimizer::kSmi);
4420 void LCodeGen::DoTransitionElementsKind(LTransitionElementsKind* instr) {
4421 Register object_reg = ToRegister(instr->object());
4422 Register scratch = scratch0();
4424 Handle<Map> from_map = instr->original_map();
4425 Handle<Map> to_map = instr->transitioned_map();
4426 ElementsKind from_kind = instr->from_kind();
4427 ElementsKind to_kind = instr->to_kind();
4429 Label not_applicable;
4430 __ ldr(scratch, FieldMemOperand(object_reg, HeapObject::kMapOffset));
4431 __ cmp(scratch, Operand(from_map));
4432 __ b(ne, ¬_applicable);
4434 if (IsSimpleMapChangeTransition(from_kind, to_kind)) {
4435 Register new_map_reg = ToRegister(instr->new_map_temp());
4436 __ mov(new_map_reg, Operand(to_map));
4437 __ str(new_map_reg, FieldMemOperand(object_reg, HeapObject::kMapOffset));
4439 __ RecordWriteForMap(object_reg,
4442 GetLinkRegisterState(),
4445 DCHECK(ToRegister(instr->context()).is(cp));
4446 DCHECK(object_reg.is(r0));
4447 PushSafepointRegistersScope scope(this);
4448 __ Move(r1, to_map);
4449 bool is_js_array = from_map->instance_type() == JS_ARRAY_TYPE;
4450 TransitionElementsKindStub stub(isolate(), from_kind, to_kind, is_js_array);
4452 RecordSafepointWithRegisters(
4453 instr->pointer_map(), 0, Safepoint::kLazyDeopt);
4455 __ bind(¬_applicable);
4459 void LCodeGen::DoTrapAllocationMemento(LTrapAllocationMemento* instr) {
4460 Register object = ToRegister(instr->object());
4461 Register temp = ToRegister(instr->temp());
4462 Label no_memento_found;
4463 __ TestJSArrayForAllocationMemento(object, temp, &no_memento_found);
4464 DeoptimizeIf(eq, instr, Deoptimizer::kMementoFound);
4465 __ bind(&no_memento_found);
4469 void LCodeGen::DoStringAdd(LStringAdd* instr) {
4470 DCHECK(ToRegister(instr->context()).is(cp));
4471 DCHECK(ToRegister(instr->left()).is(r1));
4472 DCHECK(ToRegister(instr->right()).is(r0));
4473 StringAddStub stub(isolate(),
4474 instr->hydrogen()->flags(),
4475 instr->hydrogen()->pretenure_flag());
4476 CallCode(stub.GetCode(), RelocInfo::CODE_TARGET, instr);
4480 void LCodeGen::DoStringCharCodeAt(LStringCharCodeAt* instr) {
4481 class DeferredStringCharCodeAt final : public LDeferredCode {
4483 DeferredStringCharCodeAt(LCodeGen* codegen, LStringCharCodeAt* instr)
4484 : LDeferredCode(codegen), instr_(instr) { }
4485 void Generate() override { codegen()->DoDeferredStringCharCodeAt(instr_); }
4486 LInstruction* instr() override { return instr_; }
4489 LStringCharCodeAt* instr_;
4492 DeferredStringCharCodeAt* deferred =
4493 new(zone()) DeferredStringCharCodeAt(this, instr);
4495 StringCharLoadGenerator::Generate(masm(),
4496 ToRegister(instr->string()),
4497 ToRegister(instr->index()),
4498 ToRegister(instr->result()),
4500 __ bind(deferred->exit());
4504 void LCodeGen::DoDeferredStringCharCodeAt(LStringCharCodeAt* instr) {
4505 Register string = ToRegister(instr->string());
4506 Register result = ToRegister(instr->result());
4507 Register scratch = scratch0();
4509 // TODO(3095996): Get rid of this. For now, we need to make the
4510 // result register contain a valid pointer because it is already
4511 // contained in the register pointer map.
4512 __ mov(result, Operand::Zero());
4514 PushSafepointRegistersScope scope(this);
4516 // Push the index as a smi. This is safe because of the checks in
4517 // DoStringCharCodeAt above.
4518 if (instr->index()->IsConstantOperand()) {
4519 int const_index = ToInteger32(LConstantOperand::cast(instr->index()));
4520 __ mov(scratch, Operand(Smi::FromInt(const_index)));
4523 Register index = ToRegister(instr->index());
4527 CallRuntimeFromDeferred(Runtime::kStringCharCodeAtRT, 2, instr,
4531 __ StoreToSafepointRegisterSlot(r0, result);
4535 void LCodeGen::DoStringCharFromCode(LStringCharFromCode* instr) {
4536 class DeferredStringCharFromCode final : public LDeferredCode {
4538 DeferredStringCharFromCode(LCodeGen* codegen, LStringCharFromCode* instr)
4539 : LDeferredCode(codegen), instr_(instr) { }
4540 void Generate() override {
4541 codegen()->DoDeferredStringCharFromCode(instr_);
4543 LInstruction* instr() override { return instr_; }
4546 LStringCharFromCode* instr_;
4549 DeferredStringCharFromCode* deferred =
4550 new(zone()) DeferredStringCharFromCode(this, instr);
4552 DCHECK(instr->hydrogen()->value()->representation().IsInteger32());
4553 Register char_code = ToRegister(instr->char_code());
4554 Register result = ToRegister(instr->result());
4555 DCHECK(!char_code.is(result));
4557 __ cmp(char_code, Operand(String::kMaxOneByteCharCode));
4558 __ b(hi, deferred->entry());
4559 __ LoadRoot(result, Heap::kSingleCharacterStringCacheRootIndex);
4560 __ add(result, result, Operand(char_code, LSL, kPointerSizeLog2));
4561 __ ldr(result, FieldMemOperand(result, FixedArray::kHeaderSize));
4562 __ LoadRoot(ip, Heap::kUndefinedValueRootIndex);
4564 __ b(eq, deferred->entry());
4565 __ bind(deferred->exit());
4569 void LCodeGen::DoDeferredStringCharFromCode(LStringCharFromCode* instr) {
4570 Register char_code = ToRegister(instr->char_code());
4571 Register result = ToRegister(instr->result());
4573 // TODO(3095996): Get rid of this. For now, we need to make the
4574 // result register contain a valid pointer because it is already
4575 // contained in the register pointer map.
4576 __ mov(result, Operand::Zero());
4578 PushSafepointRegistersScope scope(this);
4579 __ SmiTag(char_code);
4581 CallRuntimeFromDeferred(Runtime::kCharFromCode, 1, instr, instr->context());
4582 __ StoreToSafepointRegisterSlot(r0, result);
4586 void LCodeGen::DoInteger32ToDouble(LInteger32ToDouble* instr) {
4587 LOperand* input = instr->value();
4588 DCHECK(input->IsRegister() || input->IsStackSlot());
4589 LOperand* output = instr->result();
4590 DCHECK(output->IsDoubleRegister());
4591 SwVfpRegister single_scratch = double_scratch0().low();
4592 if (input->IsStackSlot()) {
4593 Register scratch = scratch0();
4594 __ ldr(scratch, ToMemOperand(input));
4595 __ vmov(single_scratch, scratch);
4597 __ vmov(single_scratch, ToRegister(input));
4599 __ vcvt_f64_s32(ToDoubleRegister(output), single_scratch);
4603 void LCodeGen::DoUint32ToDouble(LUint32ToDouble* instr) {
4604 LOperand* input = instr->value();
4605 LOperand* output = instr->result();
4607 SwVfpRegister flt_scratch = double_scratch0().low();
4608 __ vmov(flt_scratch, ToRegister(input));
4609 __ vcvt_f64_u32(ToDoubleRegister(output), flt_scratch);
4613 void LCodeGen::DoNumberTagI(LNumberTagI* instr) {
4614 class DeferredNumberTagI final : public LDeferredCode {
4616 DeferredNumberTagI(LCodeGen* codegen, LNumberTagI* instr)
4617 : LDeferredCode(codegen), instr_(instr) { }
4618 void Generate() override {
4619 codegen()->DoDeferredNumberTagIU(instr_,
4625 LInstruction* instr() override { return instr_; }
4628 LNumberTagI* instr_;
4631 Register src = ToRegister(instr->value());
4632 Register dst = ToRegister(instr->result());
4634 DeferredNumberTagI* deferred = new(zone()) DeferredNumberTagI(this, instr);
4635 __ SmiTag(dst, src, SetCC);
4636 __ b(vs, deferred->entry());
4637 __ bind(deferred->exit());
4641 void LCodeGen::DoNumberTagU(LNumberTagU* instr) {
4642 class DeferredNumberTagU final : public LDeferredCode {
4644 DeferredNumberTagU(LCodeGen* codegen, LNumberTagU* instr)
4645 : LDeferredCode(codegen), instr_(instr) { }
4646 void Generate() override {
4647 codegen()->DoDeferredNumberTagIU(instr_,
4653 LInstruction* instr() override { return instr_; }
4656 LNumberTagU* instr_;
4659 Register input = ToRegister(instr->value());
4660 Register result = ToRegister(instr->result());
4662 DeferredNumberTagU* deferred = new(zone()) DeferredNumberTagU(this, instr);
4663 __ cmp(input, Operand(Smi::kMaxValue));
4664 __ b(hi, deferred->entry());
4665 __ SmiTag(result, input);
4666 __ bind(deferred->exit());
4670 void LCodeGen::DoDeferredNumberTagIU(LInstruction* instr,
4674 IntegerSignedness signedness) {
4676 Register src = ToRegister(value);
4677 Register dst = ToRegister(instr->result());
4678 Register tmp1 = scratch0();
4679 Register tmp2 = ToRegister(temp1);
4680 Register tmp3 = ToRegister(temp2);
4681 LowDwVfpRegister dbl_scratch = double_scratch0();
4683 if (signedness == SIGNED_INT32) {
4684 // There was overflow, so bits 30 and 31 of the original integer
4685 // disagree. Try to allocate a heap number in new space and store
4686 // the value in there. If that fails, call the runtime system.
4688 __ SmiUntag(src, dst);
4689 __ eor(src, src, Operand(0x80000000));
4691 __ vmov(dbl_scratch.low(), src);
4692 __ vcvt_f64_s32(dbl_scratch, dbl_scratch.low());
4694 __ vmov(dbl_scratch.low(), src);
4695 __ vcvt_f64_u32(dbl_scratch, dbl_scratch.low());
4698 if (FLAG_inline_new) {
4699 __ LoadRoot(tmp3, Heap::kHeapNumberMapRootIndex);
4700 __ AllocateHeapNumber(dst, tmp1, tmp2, tmp3, &slow, DONT_TAG_RESULT);
4704 // Slow case: Call the runtime system to do the number allocation.
4707 // TODO(3095996): Put a valid pointer value in the stack slot where the
4708 // result register is stored, as this register is in the pointer map, but
4709 // contains an integer value.
4710 __ mov(dst, Operand::Zero());
4712 // Preserve the value of all registers.
4713 PushSafepointRegistersScope scope(this);
4715 // NumberTagI and NumberTagD use the context from the frame, rather than
4716 // the environment's HContext or HInlinedContext value.
4717 // They only call Runtime::kAllocateHeapNumber.
4718 // The corresponding HChange instructions are added in a phase that does
4719 // not have easy access to the local context.
4720 __ ldr(cp, MemOperand(fp, StandardFrameConstants::kContextOffset));
4721 __ CallRuntimeSaveDoubles(Runtime::kAllocateHeapNumber);
4722 RecordSafepointWithRegisters(
4723 instr->pointer_map(), 0, Safepoint::kNoLazyDeopt);
4724 __ sub(r0, r0, Operand(kHeapObjectTag));
4725 __ StoreToSafepointRegisterSlot(r0, dst);
4728 // Done. Put the value in dbl_scratch into the value of the allocated heap
4731 __ vstr(dbl_scratch, dst, HeapNumber::kValueOffset);
4732 __ add(dst, dst, Operand(kHeapObjectTag));
4736 void LCodeGen::DoNumberTagD(LNumberTagD* instr) {
4737 class DeferredNumberTagD final : public LDeferredCode {
4739 DeferredNumberTagD(LCodeGen* codegen, LNumberTagD* instr)
4740 : LDeferredCode(codegen), instr_(instr) { }
4741 void Generate() override { codegen()->DoDeferredNumberTagD(instr_); }
4742 LInstruction* instr() override { return instr_; }
4745 LNumberTagD* instr_;
4748 DwVfpRegister input_reg = ToDoubleRegister(instr->value());
4749 Register scratch = scratch0();
4750 Register reg = ToRegister(instr->result());
4751 Register temp1 = ToRegister(instr->temp());
4752 Register temp2 = ToRegister(instr->temp2());
4754 DeferredNumberTagD* deferred = new(zone()) DeferredNumberTagD(this, instr);
4755 if (FLAG_inline_new) {
4756 __ LoadRoot(scratch, Heap::kHeapNumberMapRootIndex);
4757 // We want the untagged address first for performance
4758 __ AllocateHeapNumber(reg, temp1, temp2, scratch, deferred->entry(),
4761 __ jmp(deferred->entry());
4763 __ bind(deferred->exit());
4764 __ vstr(input_reg, reg, HeapNumber::kValueOffset);
4765 // Now that we have finished with the object's real address tag it
4766 __ add(reg, reg, Operand(kHeapObjectTag));
4770 void LCodeGen::DoDeferredNumberTagD(LNumberTagD* instr) {
4771 // TODO(3095996): Get rid of this. For now, we need to make the
4772 // result register contain a valid pointer because it is already
4773 // contained in the register pointer map.
4774 Register reg = ToRegister(instr->result());
4775 __ mov(reg, Operand::Zero());
4777 PushSafepointRegistersScope scope(this);
4778 // NumberTagI and NumberTagD use the context from the frame, rather than
4779 // the environment's HContext or HInlinedContext value.
4780 // They only call Runtime::kAllocateHeapNumber.
4781 // The corresponding HChange instructions are added in a phase that does
4782 // not have easy access to the local context.
4783 __ ldr(cp, MemOperand(fp, StandardFrameConstants::kContextOffset));
4784 __ CallRuntimeSaveDoubles(Runtime::kAllocateHeapNumber);
4785 RecordSafepointWithRegisters(
4786 instr->pointer_map(), 0, Safepoint::kNoLazyDeopt);
4787 __ sub(r0, r0, Operand(kHeapObjectTag));
4788 __ StoreToSafepointRegisterSlot(r0, reg);
4792 void LCodeGen::DoSmiTag(LSmiTag* instr) {
4793 HChange* hchange = instr->hydrogen();
4794 Register input = ToRegister(instr->value());
4795 Register output = ToRegister(instr->result());
4796 if (hchange->CheckFlag(HValue::kCanOverflow) &&
4797 hchange->value()->CheckFlag(HValue::kUint32)) {
4798 __ tst(input, Operand(0xc0000000));
4799 DeoptimizeIf(ne, instr, Deoptimizer::kOverflow);
4801 if (hchange->CheckFlag(HValue::kCanOverflow) &&
4802 !hchange->value()->CheckFlag(HValue::kUint32)) {
4803 __ SmiTag(output, input, SetCC);
4804 DeoptimizeIf(vs, instr, Deoptimizer::kOverflow);
4806 __ SmiTag(output, input);
4811 void LCodeGen::DoSmiUntag(LSmiUntag* instr) {
4812 Register input = ToRegister(instr->value());
4813 Register result = ToRegister(instr->result());
4814 if (instr->needs_check()) {
4815 STATIC_ASSERT(kHeapObjectTag == 1);
4816 // If the input is a HeapObject, SmiUntag will set the carry flag.
4817 __ SmiUntag(result, input, SetCC);
4818 DeoptimizeIf(cs, instr, Deoptimizer::kNotASmi);
4820 __ SmiUntag(result, input);
4825 void LCodeGen::EmitNumberUntagD(LNumberUntagD* instr, Register input_reg,
4826 DwVfpRegister result_reg,
4827 NumberUntagDMode mode) {
4828 bool can_convert_undefined_to_nan =
4829 instr->hydrogen()->can_convert_undefined_to_nan();
4830 bool deoptimize_on_minus_zero = instr->hydrogen()->deoptimize_on_minus_zero();
4832 Register scratch = scratch0();
4833 SwVfpRegister flt_scratch = double_scratch0().low();
4834 DCHECK(!result_reg.is(double_scratch0()));
4835 Label convert, load_smi, done;
4836 if (mode == NUMBER_CANDIDATE_IS_ANY_TAGGED) {
4838 __ UntagAndJumpIfSmi(scratch, input_reg, &load_smi);
4839 // Heap number map check.
4840 __ ldr(scratch, FieldMemOperand(input_reg, HeapObject::kMapOffset));
4841 __ LoadRoot(ip, Heap::kHeapNumberMapRootIndex);
4842 __ cmp(scratch, Operand(ip));
4843 if (can_convert_undefined_to_nan) {
4846 DeoptimizeIf(ne, instr, Deoptimizer::kNotAHeapNumber);
4849 __ vldr(result_reg, input_reg, HeapNumber::kValueOffset - kHeapObjectTag);
4850 if (deoptimize_on_minus_zero) {
4851 __ VmovLow(scratch, result_reg);
4852 __ cmp(scratch, Operand::Zero());
4854 __ VmovHigh(scratch, result_reg);
4855 __ cmp(scratch, Operand(HeapNumber::kSignMask));
4856 DeoptimizeIf(eq, instr, Deoptimizer::kMinusZero);
4859 if (can_convert_undefined_to_nan) {
4861 // Convert undefined (and hole) to NaN.
4862 __ LoadRoot(ip, Heap::kUndefinedValueRootIndex);
4863 __ cmp(input_reg, Operand(ip));
4864 DeoptimizeIf(ne, instr, Deoptimizer::kNotAHeapNumberUndefined);
4865 __ LoadRoot(scratch, Heap::kNanValueRootIndex);
4866 __ vldr(result_reg, scratch, HeapNumber::kValueOffset - kHeapObjectTag);
4870 __ SmiUntag(scratch, input_reg);
4871 DCHECK(mode == NUMBER_CANDIDATE_IS_SMI);
4873 // Smi to double register conversion
4875 // scratch: untagged value of input_reg
4876 __ vmov(flt_scratch, scratch);
4877 __ vcvt_f64_s32(result_reg, flt_scratch);
4882 void LCodeGen::DoDeferredTaggedToI(LTaggedToI* instr) {
4883 Register input_reg = ToRegister(instr->value());
4884 Register scratch1 = scratch0();
4885 Register scratch2 = ToRegister(instr->temp());
4886 LowDwVfpRegister double_scratch = double_scratch0();
4887 DwVfpRegister double_scratch2 = ToDoubleRegister(instr->temp2());
4889 DCHECK(!scratch1.is(input_reg) && !scratch1.is(scratch2));
4890 DCHECK(!scratch2.is(input_reg) && !scratch2.is(scratch1));
4894 // The input was optimistically untagged; revert it.
4895 // The carry flag is set when we reach this deferred code as we just executed
4896 // SmiUntag(heap_object, SetCC)
4897 STATIC_ASSERT(kHeapObjectTag == 1);
4898 __ adc(scratch2, input_reg, Operand(input_reg));
4900 // Heap number map check.
4901 __ ldr(scratch1, FieldMemOperand(scratch2, HeapObject::kMapOffset));
4902 __ LoadRoot(ip, Heap::kHeapNumberMapRootIndex);
4903 __ cmp(scratch1, Operand(ip));
4905 if (instr->truncating()) {
4906 // Performs a truncating conversion of a floating point number as used by
4907 // the JS bitwise operations.
4908 Label no_heap_number, check_bools, check_false;
4909 __ b(ne, &no_heap_number);
4910 __ TruncateHeapNumberToI(input_reg, scratch2);
4913 // Check for Oddballs. Undefined/False is converted to zero and True to one
4914 // for truncating conversions.
4915 __ bind(&no_heap_number);
4916 __ LoadRoot(ip, Heap::kUndefinedValueRootIndex);
4917 __ cmp(scratch2, Operand(ip));
4918 __ b(ne, &check_bools);
4919 __ mov(input_reg, Operand::Zero());
4922 __ bind(&check_bools);
4923 __ LoadRoot(ip, Heap::kTrueValueRootIndex);
4924 __ cmp(scratch2, Operand(ip));
4925 __ b(ne, &check_false);
4926 __ mov(input_reg, Operand(1));
4929 __ bind(&check_false);
4930 __ LoadRoot(ip, Heap::kFalseValueRootIndex);
4931 __ cmp(scratch2, Operand(ip));
4932 DeoptimizeIf(ne, instr, Deoptimizer::kNotAHeapNumberUndefinedBoolean);
4933 __ mov(input_reg, Operand::Zero());
4935 DeoptimizeIf(ne, instr, Deoptimizer::kNotAHeapNumber);
4937 __ sub(ip, scratch2, Operand(kHeapObjectTag));
4938 __ vldr(double_scratch2, ip, HeapNumber::kValueOffset);
4939 __ TryDoubleToInt32Exact(input_reg, double_scratch2, double_scratch);
4940 DeoptimizeIf(ne, instr, Deoptimizer::kLostPrecisionOrNaN);
4942 if (instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero)) {
4943 __ cmp(input_reg, Operand::Zero());
4945 __ VmovHigh(scratch1, double_scratch2);
4946 __ tst(scratch1, Operand(HeapNumber::kSignMask));
4947 DeoptimizeIf(ne, instr, Deoptimizer::kMinusZero);
4954 void LCodeGen::DoTaggedToI(LTaggedToI* instr) {
4955 class DeferredTaggedToI final : public LDeferredCode {
4957 DeferredTaggedToI(LCodeGen* codegen, LTaggedToI* instr)
4958 : LDeferredCode(codegen), instr_(instr) { }
4959 void Generate() override { codegen()->DoDeferredTaggedToI(instr_); }
4960 LInstruction* instr() override { return instr_; }
4966 LOperand* input = instr->value();
4967 DCHECK(input->IsRegister());
4968 DCHECK(input->Equals(instr->result()));
4970 Register input_reg = ToRegister(input);
4972 if (instr->hydrogen()->value()->representation().IsSmi()) {
4973 __ SmiUntag(input_reg);
4975 DeferredTaggedToI* deferred = new(zone()) DeferredTaggedToI(this, instr);
4977 // Optimistically untag the input.
4978 // If the input is a HeapObject, SmiUntag will set the carry flag.
4979 __ SmiUntag(input_reg, SetCC);
4980 // Branch to deferred code if the input was tagged.
4981 // The deferred code will take care of restoring the tag.
4982 __ b(cs, deferred->entry());
4983 __ bind(deferred->exit());
4988 void LCodeGen::DoNumberUntagD(LNumberUntagD* instr) {
4989 LOperand* input = instr->value();
4990 DCHECK(input->IsRegister());
4991 LOperand* result = instr->result();
4992 DCHECK(result->IsDoubleRegister());
4994 Register input_reg = ToRegister(input);
4995 DwVfpRegister result_reg = ToDoubleRegister(result);
4997 HValue* value = instr->hydrogen()->value();
4998 NumberUntagDMode mode = value->representation().IsSmi()
4999 ? NUMBER_CANDIDATE_IS_SMI : NUMBER_CANDIDATE_IS_ANY_TAGGED;
5001 EmitNumberUntagD(instr, input_reg, result_reg, mode);
5005 void LCodeGen::DoDoubleToI(LDoubleToI* instr) {
5006 Register result_reg = ToRegister(instr->result());
5007 Register scratch1 = scratch0();
5008 DwVfpRegister double_input = ToDoubleRegister(instr->value());
5009 LowDwVfpRegister double_scratch = double_scratch0();
5011 if (instr->truncating()) {
5012 __ TruncateDoubleToI(result_reg, double_input);
5014 __ TryDoubleToInt32Exact(result_reg, double_input, double_scratch);
5015 // Deoptimize if the input wasn't a int32 (inside a double).
5016 DeoptimizeIf(ne, instr, Deoptimizer::kLostPrecisionOrNaN);
5017 if (instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero)) {
5019 __ cmp(result_reg, Operand::Zero());
5021 __ VmovHigh(scratch1, double_input);
5022 __ tst(scratch1, Operand(HeapNumber::kSignMask));
5023 DeoptimizeIf(ne, instr, Deoptimizer::kMinusZero);
5030 void LCodeGen::DoDoubleToSmi(LDoubleToSmi* instr) {
5031 Register result_reg = ToRegister(instr->result());
5032 Register scratch1 = scratch0();
5033 DwVfpRegister double_input = ToDoubleRegister(instr->value());
5034 LowDwVfpRegister double_scratch = double_scratch0();
5036 if (instr->truncating()) {
5037 __ TruncateDoubleToI(result_reg, double_input);
5039 __ TryDoubleToInt32Exact(result_reg, double_input, double_scratch);
5040 // Deoptimize if the input wasn't a int32 (inside a double).
5041 DeoptimizeIf(ne, instr, Deoptimizer::kLostPrecisionOrNaN);
5042 if (instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero)) {
5044 __ cmp(result_reg, Operand::Zero());
5046 __ VmovHigh(scratch1, double_input);
5047 __ tst(scratch1, Operand(HeapNumber::kSignMask));
5048 DeoptimizeIf(ne, instr, Deoptimizer::kMinusZero);
5052 __ SmiTag(result_reg, SetCC);
5053 DeoptimizeIf(vs, instr, Deoptimizer::kOverflow);
5057 void LCodeGen::DoCheckSmi(LCheckSmi* instr) {
5058 LOperand* input = instr->value();
5059 __ SmiTst(ToRegister(input));
5060 DeoptimizeIf(ne, instr, Deoptimizer::kNotASmi);
5064 void LCodeGen::DoCheckNonSmi(LCheckNonSmi* instr) {
5065 if (!instr->hydrogen()->value()->type().IsHeapObject()) {
5066 LOperand* input = instr->value();
5067 __ SmiTst(ToRegister(input));
5068 DeoptimizeIf(eq, instr, Deoptimizer::kSmi);
5073 void LCodeGen::DoCheckArrayBufferNotNeutered(
5074 LCheckArrayBufferNotNeutered* instr) {
5075 Register view = ToRegister(instr->view());
5076 Register scratch = scratch0();
5078 __ ldr(scratch, FieldMemOperand(view, JSArrayBufferView::kBufferOffset));
5079 __ ldr(scratch, FieldMemOperand(scratch, JSArrayBuffer::kBitFieldOffset));
5080 __ tst(scratch, Operand(1 << JSArrayBuffer::WasNeutered::kShift));
5081 DeoptimizeIf(ne, instr, Deoptimizer::kOutOfBounds);
5085 void LCodeGen::DoCheckInstanceType(LCheckInstanceType* instr) {
5086 Register input = ToRegister(instr->value());
5087 Register scratch = scratch0();
5089 __ ldr(scratch, FieldMemOperand(input, HeapObject::kMapOffset));
5090 __ ldrb(scratch, FieldMemOperand(scratch, Map::kInstanceTypeOffset));
5092 if (instr->hydrogen()->is_interval_check()) {
5095 instr->hydrogen()->GetCheckInterval(&first, &last);
5097 __ cmp(scratch, Operand(first));
5099 // If there is only one type in the interval check for equality.
5100 if (first == last) {
5101 DeoptimizeIf(ne, instr, Deoptimizer::kWrongInstanceType);
5103 DeoptimizeIf(lo, instr, Deoptimizer::kWrongInstanceType);
5104 // Omit check for the last type.
5105 if (last != LAST_TYPE) {
5106 __ cmp(scratch, Operand(last));
5107 DeoptimizeIf(hi, instr, Deoptimizer::kWrongInstanceType);
5113 instr->hydrogen()->GetCheckMaskAndTag(&mask, &tag);
5115 if (base::bits::IsPowerOfTwo32(mask)) {
5116 DCHECK(tag == 0 || base::bits::IsPowerOfTwo32(tag));
5117 __ tst(scratch, Operand(mask));
5118 DeoptimizeIf(tag == 0 ? ne : eq, instr, Deoptimizer::kWrongInstanceType);
5120 __ and_(scratch, scratch, Operand(mask));
5121 __ cmp(scratch, Operand(tag));
5122 DeoptimizeIf(ne, instr, Deoptimizer::kWrongInstanceType);
5128 void LCodeGen::DoCheckValue(LCheckValue* instr) {
5129 Register reg = ToRegister(instr->value());
5130 Handle<HeapObject> object = instr->hydrogen()->object().handle();
5131 AllowDeferredHandleDereference smi_check;
5132 if (isolate()->heap()->InNewSpace(*object)) {
5133 Register reg = ToRegister(instr->value());
5134 Handle<Cell> cell = isolate()->factory()->NewCell(object);
5135 __ mov(ip, Operand(cell));
5136 __ ldr(ip, FieldMemOperand(ip, Cell::kValueOffset));
5139 __ cmp(reg, Operand(object));
5141 DeoptimizeIf(ne, instr, Deoptimizer::kValueMismatch);
5145 void LCodeGen::DoDeferredInstanceMigration(LCheckMaps* instr, Register object) {
5147 PushSafepointRegistersScope scope(this);
5149 __ mov(cp, Operand::Zero());
5150 __ CallRuntimeSaveDoubles(Runtime::kTryMigrateInstance);
5151 RecordSafepointWithRegisters(
5152 instr->pointer_map(), 1, Safepoint::kNoLazyDeopt);
5153 __ StoreToSafepointRegisterSlot(r0, scratch0());
5155 __ tst(scratch0(), Operand(kSmiTagMask));
5156 DeoptimizeIf(eq, instr, Deoptimizer::kInstanceMigrationFailed);
5160 void LCodeGen::DoCheckMaps(LCheckMaps* instr) {
5161 class DeferredCheckMaps final : public LDeferredCode {
5163 DeferredCheckMaps(LCodeGen* codegen, LCheckMaps* instr, Register object)
5164 : LDeferredCode(codegen), instr_(instr), object_(object) {
5165 SetExit(check_maps());
5167 void Generate() override {
5168 codegen()->DoDeferredInstanceMigration(instr_, object_);
5170 Label* check_maps() { return &check_maps_; }
5171 LInstruction* instr() override { return instr_; }
5179 if (instr->hydrogen()->IsStabilityCheck()) {
5180 const UniqueSet<Map>* maps = instr->hydrogen()->maps();
5181 for (int i = 0; i < maps->size(); ++i) {
5182 AddStabilityDependency(maps->at(i).handle());
5187 Register map_reg = scratch0();
5189 LOperand* input = instr->value();
5190 DCHECK(input->IsRegister());
5191 Register reg = ToRegister(input);
5193 __ ldr(map_reg, FieldMemOperand(reg, HeapObject::kMapOffset));
5195 DeferredCheckMaps* deferred = NULL;
5196 if (instr->hydrogen()->HasMigrationTarget()) {
5197 deferred = new(zone()) DeferredCheckMaps(this, instr, reg);
5198 __ bind(deferred->check_maps());
5201 const UniqueSet<Map>* maps = instr->hydrogen()->maps();
5203 for (int i = 0; i < maps->size() - 1; i++) {
5204 Handle<Map> map = maps->at(i).handle();
5205 __ CompareMap(map_reg, map, &success);
5209 Handle<Map> map = maps->at(maps->size() - 1).handle();
5210 __ CompareMap(map_reg, map, &success);
5211 if (instr->hydrogen()->HasMigrationTarget()) {
5212 __ b(ne, deferred->entry());
5214 DeoptimizeIf(ne, instr, Deoptimizer::kWrongMap);
5221 void LCodeGen::DoClampDToUint8(LClampDToUint8* instr) {
5222 DwVfpRegister value_reg = ToDoubleRegister(instr->unclamped());
5223 Register result_reg = ToRegister(instr->result());
5224 __ ClampDoubleToUint8(result_reg, value_reg, double_scratch0());
5228 void LCodeGen::DoClampIToUint8(LClampIToUint8* instr) {
5229 Register unclamped_reg = ToRegister(instr->unclamped());
5230 Register result_reg = ToRegister(instr->result());
5231 __ ClampUint8(result_reg, unclamped_reg);
5235 void LCodeGen::DoClampTToUint8(LClampTToUint8* instr) {
5236 Register scratch = scratch0();
5237 Register input_reg = ToRegister(instr->unclamped());
5238 Register result_reg = ToRegister(instr->result());
5239 DwVfpRegister temp_reg = ToDoubleRegister(instr->temp());
5240 Label is_smi, done, heap_number;
5242 // Both smi and heap number cases are handled.
5243 __ UntagAndJumpIfSmi(result_reg, input_reg, &is_smi);
5245 // Check for heap number
5246 __ ldr(scratch, FieldMemOperand(input_reg, HeapObject::kMapOffset));
5247 __ cmp(scratch, Operand(factory()->heap_number_map()));
5248 __ b(eq, &heap_number);
5250 // Check for undefined. Undefined is converted to zero for clamping
5252 __ cmp(input_reg, Operand(factory()->undefined_value()));
5253 DeoptimizeIf(ne, instr, Deoptimizer::kNotAHeapNumberUndefined);
5254 __ mov(result_reg, Operand::Zero());
5258 __ bind(&heap_number);
5259 __ vldr(temp_reg, FieldMemOperand(input_reg, HeapNumber::kValueOffset));
5260 __ ClampDoubleToUint8(result_reg, temp_reg, double_scratch0());
5265 __ ClampUint8(result_reg, result_reg);
5271 void LCodeGen::DoDoubleBits(LDoubleBits* instr) {
5272 DwVfpRegister value_reg = ToDoubleRegister(instr->value());
5273 Register result_reg = ToRegister(instr->result());
5274 if (instr->hydrogen()->bits() == HDoubleBits::HIGH) {
5275 __ VmovHigh(result_reg, value_reg);
5277 __ VmovLow(result_reg, value_reg);
5282 void LCodeGen::DoConstructDouble(LConstructDouble* instr) {
5283 Register hi_reg = ToRegister(instr->hi());
5284 Register lo_reg = ToRegister(instr->lo());
5285 DwVfpRegister result_reg = ToDoubleRegister(instr->result());
5286 __ VmovHigh(result_reg, hi_reg);
5287 __ VmovLow(result_reg, lo_reg);
5291 void LCodeGen::DoAllocate(LAllocate* instr) {
5292 class DeferredAllocate final : public LDeferredCode {
5294 DeferredAllocate(LCodeGen* codegen, LAllocate* instr)
5295 : LDeferredCode(codegen), instr_(instr) { }
5296 void Generate() override { codegen()->DoDeferredAllocate(instr_); }
5297 LInstruction* instr() override { return instr_; }
5303 DeferredAllocate* deferred =
5304 new(zone()) DeferredAllocate(this, instr);
5306 Register result = ToRegister(instr->result());
5307 Register scratch = ToRegister(instr->temp1());
5308 Register scratch2 = ToRegister(instr->temp2());
5310 // Allocate memory for the object.
5311 AllocationFlags flags = TAG_OBJECT;
5312 if (instr->hydrogen()->MustAllocateDoubleAligned()) {
5313 flags = static_cast<AllocationFlags>(flags | DOUBLE_ALIGNMENT);
5315 if (instr->hydrogen()->IsOldSpaceAllocation()) {
5316 DCHECK(!instr->hydrogen()->IsNewSpaceAllocation());
5317 flags = static_cast<AllocationFlags>(flags | PRETENURE);
5320 if (instr->size()->IsConstantOperand()) {
5321 int32_t size = ToInteger32(LConstantOperand::cast(instr->size()));
5322 if (size <= Page::kMaxRegularHeapObjectSize) {
5323 __ Allocate(size, result, scratch, scratch2, deferred->entry(), flags);
5325 __ jmp(deferred->entry());
5328 Register size = ToRegister(instr->size());
5329 __ Allocate(size, result, scratch, scratch2, deferred->entry(), flags);
5332 __ bind(deferred->exit());
5334 if (instr->hydrogen()->MustPrefillWithFiller()) {
5335 STATIC_ASSERT(kHeapObjectTag == 1);
5336 if (instr->size()->IsConstantOperand()) {
5337 int32_t size = ToInteger32(LConstantOperand::cast(instr->size()));
5338 __ mov(scratch, Operand(size - kHeapObjectTag));
5340 __ sub(scratch, ToRegister(instr->size()), Operand(kHeapObjectTag));
5342 __ mov(scratch2, Operand(isolate()->factory()->one_pointer_filler_map()));
5345 __ sub(scratch, scratch, Operand(kPointerSize), SetCC);
5346 __ str(scratch2, MemOperand(result, scratch));
5352 void LCodeGen::DoDeferredAllocate(LAllocate* instr) {
5353 Register result = ToRegister(instr->result());
5355 // TODO(3095996): Get rid of this. For now, we need to make the
5356 // result register contain a valid pointer because it is already
5357 // contained in the register pointer map.
5358 __ mov(result, Operand(Smi::FromInt(0)));
5360 PushSafepointRegistersScope scope(this);
5361 if (instr->size()->IsRegister()) {
5362 Register size = ToRegister(instr->size());
5363 DCHECK(!size.is(result));
5367 int32_t size = ToInteger32(LConstantOperand::cast(instr->size()));
5368 if (size >= 0 && size <= Smi::kMaxValue) {
5369 __ Push(Smi::FromInt(size));
5371 // We should never get here at runtime => abort
5372 __ stop("invalid allocation size");
5377 int flags = AllocateDoubleAlignFlag::encode(
5378 instr->hydrogen()->MustAllocateDoubleAligned());
5379 if (instr->hydrogen()->IsOldSpaceAllocation()) {
5380 DCHECK(!instr->hydrogen()->IsNewSpaceAllocation());
5381 flags = AllocateTargetSpace::update(flags, OLD_SPACE);
5383 flags = AllocateTargetSpace::update(flags, NEW_SPACE);
5385 __ Push(Smi::FromInt(flags));
5387 CallRuntimeFromDeferred(
5388 Runtime::kAllocateInTargetSpace, 2, instr, instr->context());
5389 __ StoreToSafepointRegisterSlot(r0, result);
5393 void LCodeGen::DoToFastProperties(LToFastProperties* instr) {
5394 DCHECK(ToRegister(instr->value()).is(r0));
5396 CallRuntime(Runtime::kToFastProperties, 1, instr);
5400 void LCodeGen::DoRegExpLiteral(LRegExpLiteral* instr) {
5401 DCHECK(ToRegister(instr->context()).is(cp));
5403 // Registers will be used as follows:
5404 // r6 = literals array.
5405 // r1 = regexp literal.
5406 // r0 = regexp literal clone.
5407 // r2-5 are used as temporaries.
5408 int literal_offset =
5409 FixedArray::OffsetOfElementAt(instr->hydrogen()->literal_index());
5410 __ Move(r6, instr->hydrogen()->literals());
5411 __ ldr(r1, FieldMemOperand(r6, literal_offset));
5412 __ LoadRoot(ip, Heap::kUndefinedValueRootIndex);
5414 __ b(ne, &materialized);
5416 // Create regexp literal using runtime function
5417 // Result will be in r0.
5418 __ mov(r5, Operand(Smi::FromInt(instr->hydrogen()->literal_index())));
5419 __ mov(r4, Operand(instr->hydrogen()->pattern()));
5420 __ mov(r3, Operand(instr->hydrogen()->flags()));
5421 __ Push(r6, r5, r4, r3);
5422 CallRuntime(Runtime::kMaterializeRegExpLiteral, 4, instr);
5425 __ bind(&materialized);
5426 int size = JSRegExp::kSize + JSRegExp::kInObjectFieldCount * kPointerSize;
5427 Label allocated, runtime_allocate;
5429 __ Allocate(size, r0, r2, r3, &runtime_allocate, TAG_OBJECT);
5432 __ bind(&runtime_allocate);
5433 __ mov(r0, Operand(Smi::FromInt(size)));
5435 CallRuntime(Runtime::kAllocateInNewSpace, 1, instr);
5438 __ bind(&allocated);
5439 // Copy the content into the newly allocated memory.
5440 __ CopyFields(r0, r1, double_scratch0(), size / kPointerSize);
5444 void LCodeGen::DoTypeof(LTypeof* instr) {
5445 DCHECK(ToRegister(instr->value()).is(r3));
5446 DCHECK(ToRegister(instr->result()).is(r0));
5448 Register value_register = ToRegister(instr->value());
5449 __ JumpIfNotSmi(value_register, &do_call);
5450 __ mov(r0, Operand(isolate()->factory()->number_string()));
5453 TypeofStub stub(isolate());
5454 CallCode(stub.GetCode(), RelocInfo::CODE_TARGET, instr);
5459 void LCodeGen::DoTypeofIsAndBranch(LTypeofIsAndBranch* instr) {
5460 Register input = ToRegister(instr->value());
5462 Condition final_branch_condition = EmitTypeofIs(instr->TrueLabel(chunk_),
5463 instr->FalseLabel(chunk_),
5465 instr->type_literal());
5466 if (final_branch_condition != kNoCondition) {
5467 EmitBranch(instr, final_branch_condition);
5472 Condition LCodeGen::EmitTypeofIs(Label* true_label,
5475 Handle<String> type_name) {
5476 Condition final_branch_condition = kNoCondition;
5477 Register scratch = scratch0();
5478 Factory* factory = isolate()->factory();
5479 if (String::Equals(type_name, factory->number_string())) {
5480 __ JumpIfSmi(input, true_label);
5481 __ ldr(scratch, FieldMemOperand(input, HeapObject::kMapOffset));
5482 __ CompareRoot(scratch, Heap::kHeapNumberMapRootIndex);
5483 final_branch_condition = eq;
5485 } else if (String::Equals(type_name, factory->string_string())) {
5486 __ JumpIfSmi(input, false_label);
5487 __ CompareObjectType(input, scratch, no_reg, FIRST_NONSTRING_TYPE);
5488 final_branch_condition = lt;
5490 } else if (String::Equals(type_name, factory->symbol_string())) {
5491 __ JumpIfSmi(input, false_label);
5492 __ CompareObjectType(input, scratch, no_reg, SYMBOL_TYPE);
5493 final_branch_condition = eq;
5495 } else if (String::Equals(type_name, factory->boolean_string())) {
5496 __ CompareRoot(input, Heap::kTrueValueRootIndex);
5497 __ b(eq, true_label);
5498 __ CompareRoot(input, Heap::kFalseValueRootIndex);
5499 final_branch_condition = eq;
5501 } else if (String::Equals(type_name, factory->undefined_string())) {
5502 __ CompareRoot(input, Heap::kUndefinedValueRootIndex);
5503 __ b(eq, true_label);
5504 __ JumpIfSmi(input, false_label);
5505 // Check for undetectable objects => true.
5506 __ ldr(scratch, FieldMemOperand(input, HeapObject::kMapOffset));
5507 __ ldrb(scratch, FieldMemOperand(scratch, Map::kBitFieldOffset));
5508 __ tst(scratch, Operand(1 << Map::kIsUndetectable));
5509 final_branch_condition = ne;
5511 } else if (String::Equals(type_name, factory->function_string())) {
5512 __ JumpIfSmi(input, false_label);
5513 __ ldr(scratch, FieldMemOperand(input, HeapObject::kMapOffset));
5514 __ ldrb(scratch, FieldMemOperand(scratch, Map::kBitFieldOffset));
5515 __ and_(scratch, scratch,
5516 Operand((1 << Map::kIsCallable) | (1 << Map::kIsUndetectable)));
5517 __ cmp(scratch, Operand(1 << Map::kIsCallable));
5518 final_branch_condition = eq;
5520 } else if (String::Equals(type_name, factory->object_string())) {
5521 __ JumpIfSmi(input, false_label);
5522 __ CompareRoot(input, Heap::kNullValueRootIndex);
5523 __ b(eq, true_label);
5524 STATIC_ASSERT(LAST_SPEC_OBJECT_TYPE == LAST_TYPE);
5525 __ CompareObjectType(input, scratch, ip, FIRST_SPEC_OBJECT_TYPE);
5526 __ b(lt, false_label);
5527 // Check for callable or undetectable objects => false.
5528 __ ldrb(scratch, FieldMemOperand(scratch, Map::kBitFieldOffset));
5530 Operand((1 << Map::kIsCallable) | (1 << Map::kIsUndetectable)));
5531 final_branch_condition = eq;
5534 #define SIMD128_TYPE(TYPE, Type, type, lane_count, lane_type) \
5535 } else if (String::Equals(type_name, factory->type##_string())) { \
5536 __ JumpIfSmi(input, false_label); \
5537 __ ldr(scratch, FieldMemOperand(input, HeapObject::kMapOffset)); \
5538 __ CompareRoot(scratch, Heap::k##Type##MapRootIndex); \
5539 final_branch_condition = eq;
5540 SIMD128_TYPES(SIMD128_TYPE)
5548 return final_branch_condition;
5552 void LCodeGen::DoIsConstructCallAndBranch(LIsConstructCallAndBranch* instr) {
5553 Register temp1 = ToRegister(instr->temp());
5555 EmitIsConstructCall(temp1, scratch0());
5556 EmitBranch(instr, eq);
5560 void LCodeGen::EmitIsConstructCall(Register temp1, Register temp2) {
5561 DCHECK(!temp1.is(temp2));
5562 // Get the frame pointer for the calling frame.
5563 __ ldr(temp1, MemOperand(fp, StandardFrameConstants::kCallerFPOffset));
5565 // Skip the arguments adaptor frame if it exists.
5566 __ ldr(temp2, MemOperand(temp1, StandardFrameConstants::kContextOffset));
5567 __ cmp(temp2, Operand(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR)));
5568 __ ldr(temp1, MemOperand(temp1, StandardFrameConstants::kCallerFPOffset), eq);
5570 // Check the marker in the calling frame.
5571 __ ldr(temp1, MemOperand(temp1, StandardFrameConstants::kMarkerOffset));
5572 __ cmp(temp1, Operand(Smi::FromInt(StackFrame::CONSTRUCT)));
5576 void LCodeGen::EnsureSpaceForLazyDeopt(int space_needed) {
5577 if (info()->ShouldEnsureSpaceForLazyDeopt()) {
5578 // Ensure that we have enough space after the previous lazy-bailout
5579 // instruction for patching the code here.
5580 int current_pc = masm()->pc_offset();
5581 if (current_pc < last_lazy_deopt_pc_ + space_needed) {
5582 // Block literal pool emission for duration of padding.
5583 Assembler::BlockConstPoolScope block_const_pool(masm());
5584 int padding_size = last_lazy_deopt_pc_ + space_needed - current_pc;
5585 DCHECK_EQ(0, padding_size % Assembler::kInstrSize);
5586 while (padding_size > 0) {
5588 padding_size -= Assembler::kInstrSize;
5592 last_lazy_deopt_pc_ = masm()->pc_offset();
5596 void LCodeGen::DoLazyBailout(LLazyBailout* instr) {
5597 last_lazy_deopt_pc_ = masm()->pc_offset();
5598 DCHECK(instr->HasEnvironment());
5599 LEnvironment* env = instr->environment();
5600 RegisterEnvironmentForDeoptimization(env, Safepoint::kLazyDeopt);
5601 safepoints_.RecordLazyDeoptimizationIndex(env->deoptimization_index());
5605 void LCodeGen::DoDeoptimize(LDeoptimize* instr) {
5606 Deoptimizer::BailoutType type = instr->hydrogen()->type();
5607 // TODO(danno): Stubs expect all deopts to be lazy for historical reasons (the
5608 // needed return address), even though the implementation of LAZY and EAGER is
5609 // now identical. When LAZY is eventually completely folded into EAGER, remove
5610 // the special case below.
5611 if (info()->IsStub() && type == Deoptimizer::EAGER) {
5612 type = Deoptimizer::LAZY;
5615 DeoptimizeIf(al, instr, instr->hydrogen()->reason(), type);
5619 void LCodeGen::DoDummy(LDummy* instr) {
5620 // Nothing to see here, move on!
5624 void LCodeGen::DoDummyUse(LDummyUse* instr) {
5625 // Nothing to see here, move on!
5629 void LCodeGen::DoDeferredStackCheck(LStackCheck* instr) {
5630 PushSafepointRegistersScope scope(this);
5631 LoadContextFromDeferred(instr->context());
5632 __ CallRuntimeSaveDoubles(Runtime::kStackGuard);
5633 RecordSafepointWithLazyDeopt(
5634 instr, RECORD_SAFEPOINT_WITH_REGISTERS_AND_NO_ARGUMENTS);
5635 DCHECK(instr->HasEnvironment());
5636 LEnvironment* env = instr->environment();
5637 safepoints_.RecordLazyDeoptimizationIndex(env->deoptimization_index());
5641 void LCodeGen::DoStackCheck(LStackCheck* instr) {
5642 class DeferredStackCheck final : public LDeferredCode {
5644 DeferredStackCheck(LCodeGen* codegen, LStackCheck* instr)
5645 : LDeferredCode(codegen), instr_(instr) { }
5646 void Generate() override { codegen()->DoDeferredStackCheck(instr_); }
5647 LInstruction* instr() override { return instr_; }
5650 LStackCheck* instr_;
5653 DCHECK(instr->HasEnvironment());
5654 LEnvironment* env = instr->environment();
5655 // There is no LLazyBailout instruction for stack-checks. We have to
5656 // prepare for lazy deoptimization explicitly here.
5657 if (instr->hydrogen()->is_function_entry()) {
5658 // Perform stack overflow check.
5660 __ LoadRoot(ip, Heap::kStackLimitRootIndex);
5661 __ cmp(sp, Operand(ip));
5663 Handle<Code> stack_check = isolate()->builtins()->StackCheck();
5664 PredictableCodeSizeScope predictable(masm());
5665 predictable.ExpectSize(CallCodeSize(stack_check, RelocInfo::CODE_TARGET));
5666 DCHECK(instr->context()->IsRegister());
5667 DCHECK(ToRegister(instr->context()).is(cp));
5668 CallCode(stack_check, RelocInfo::CODE_TARGET, instr);
5671 DCHECK(instr->hydrogen()->is_backwards_branch());
5672 // Perform stack overflow check if this goto needs it before jumping.
5673 DeferredStackCheck* deferred_stack_check =
5674 new(zone()) DeferredStackCheck(this, instr);
5675 __ LoadRoot(ip, Heap::kStackLimitRootIndex);
5676 __ cmp(sp, Operand(ip));
5677 __ b(lo, deferred_stack_check->entry());
5678 EnsureSpaceForLazyDeopt(Deoptimizer::patch_size());
5679 __ bind(instr->done_label());
5680 deferred_stack_check->SetExit(instr->done_label());
5681 RegisterEnvironmentForDeoptimization(env, Safepoint::kLazyDeopt);
5682 // Don't record a deoptimization index for the safepoint here.
5683 // This will be done explicitly when emitting call and the safepoint in
5684 // the deferred code.
5689 void LCodeGen::DoOsrEntry(LOsrEntry* instr) {
5690 // This is a pseudo-instruction that ensures that the environment here is
5691 // properly registered for deoptimization and records the assembler's PC
5693 LEnvironment* environment = instr->environment();
5695 // If the environment were already registered, we would have no way of
5696 // backpatching it with the spill slot operands.
5697 DCHECK(!environment->HasBeenRegistered());
5698 RegisterEnvironmentForDeoptimization(environment, Safepoint::kNoLazyDeopt);
5700 GenerateOsrPrologue();
5704 void LCodeGen::DoForInPrepareMap(LForInPrepareMap* instr) {
5706 DeoptimizeIf(eq, instr, Deoptimizer::kSmi);
5708 STATIC_ASSERT(FIRST_JS_PROXY_TYPE == FIRST_SPEC_OBJECT_TYPE);
5709 __ CompareObjectType(r0, r1, r1, LAST_JS_PROXY_TYPE);
5710 DeoptimizeIf(le, instr, Deoptimizer::kWrongInstanceType);
5712 Label use_cache, call_runtime;
5713 Register null_value = r5;
5714 __ LoadRoot(null_value, Heap::kNullValueRootIndex);
5715 __ CheckEnumCache(null_value, &call_runtime);
5717 __ ldr(r0, FieldMemOperand(r0, HeapObject::kMapOffset));
5720 // Get the set of properties to enumerate.
5721 __ bind(&call_runtime);
5723 CallRuntime(Runtime::kGetPropertyNamesFast, 1, instr);
5725 __ ldr(r1, FieldMemOperand(r0, HeapObject::kMapOffset));
5726 __ LoadRoot(ip, Heap::kMetaMapRootIndex);
5728 DeoptimizeIf(ne, instr, Deoptimizer::kWrongMap);
5729 __ bind(&use_cache);
5733 void LCodeGen::DoForInCacheArray(LForInCacheArray* instr) {
5734 Register map = ToRegister(instr->map());
5735 Register result = ToRegister(instr->result());
5736 Label load_cache, done;
5737 __ EnumLength(result, map);
5738 __ cmp(result, Operand(Smi::FromInt(0)));
5739 __ b(ne, &load_cache);
5740 __ mov(result, Operand(isolate()->factory()->empty_fixed_array()));
5743 __ bind(&load_cache);
5744 __ LoadInstanceDescriptors(map, result);
5746 FieldMemOperand(result, DescriptorArray::kEnumCacheOffset));
5748 FieldMemOperand(result, FixedArray::SizeFor(instr->idx())));
5749 __ cmp(result, Operand::Zero());
5750 DeoptimizeIf(eq, instr, Deoptimizer::kNoCache);
5756 void LCodeGen::DoCheckMapValue(LCheckMapValue* instr) {
5757 Register object = ToRegister(instr->value());
5758 Register map = ToRegister(instr->map());
5759 __ ldr(scratch0(), FieldMemOperand(object, HeapObject::kMapOffset));
5760 __ cmp(map, scratch0());
5761 DeoptimizeIf(ne, instr, Deoptimizer::kWrongMap);
5765 void LCodeGen::DoDeferredLoadMutableDouble(LLoadFieldByIndex* instr,
5769 PushSafepointRegistersScope scope(this);
5772 __ mov(cp, Operand::Zero());
5773 __ CallRuntimeSaveDoubles(Runtime::kLoadMutableDouble);
5774 RecordSafepointWithRegisters(
5775 instr->pointer_map(), 2, Safepoint::kNoLazyDeopt);
5776 __ StoreToSafepointRegisterSlot(r0, result);
5780 void LCodeGen::DoLoadFieldByIndex(LLoadFieldByIndex* instr) {
5781 class DeferredLoadMutableDouble final : public LDeferredCode {
5783 DeferredLoadMutableDouble(LCodeGen* codegen,
5784 LLoadFieldByIndex* instr,
5788 : LDeferredCode(codegen),
5794 void Generate() override {
5795 codegen()->DoDeferredLoadMutableDouble(instr_, result_, object_, index_);
5797 LInstruction* instr() override { return instr_; }
5800 LLoadFieldByIndex* instr_;
5806 Register object = ToRegister(instr->object());
5807 Register index = ToRegister(instr->index());
5808 Register result = ToRegister(instr->result());
5809 Register scratch = scratch0();
5811 DeferredLoadMutableDouble* deferred;
5812 deferred = new(zone()) DeferredLoadMutableDouble(
5813 this, instr, result, object, index);
5815 Label out_of_object, done;
5817 __ tst(index, Operand(Smi::FromInt(1)));
5818 __ b(ne, deferred->entry());
5819 __ mov(index, Operand(index, ASR, 1));
5821 __ cmp(index, Operand::Zero());
5822 __ b(lt, &out_of_object);
5824 __ add(scratch, object, Operand::PointerOffsetFromSmiKey(index));
5825 __ ldr(result, FieldMemOperand(scratch, JSObject::kHeaderSize));
5829 __ bind(&out_of_object);
5830 __ ldr(result, FieldMemOperand(object, JSObject::kPropertiesOffset));
5831 // Index is equal to negated out of object property index plus 1.
5832 STATIC_ASSERT(kSmiTag == 0 && kSmiTagSize < kPointerSizeLog2);
5833 __ sub(scratch, result, Operand::PointerOffsetFromSmiKey(index));
5834 __ ldr(result, FieldMemOperand(scratch,
5835 FixedArray::kHeaderSize - kPointerSize));
5836 __ bind(deferred->exit());
5841 void LCodeGen::DoStoreFrameContext(LStoreFrameContext* instr) {
5842 Register context = ToRegister(instr->context());
5843 __ str(context, MemOperand(fp, StandardFrameConstants::kContextOffset));
5847 void LCodeGen::DoAllocateBlockContext(LAllocateBlockContext* instr) {
5848 Handle<ScopeInfo> scope_info = instr->scope_info();
5849 __ Push(scope_info);
5850 __ push(ToRegister(instr->function()));
5851 CallRuntime(Runtime::kPushBlockContext, 2, instr);
5852 RecordSafepoint(Safepoint::kNoLazyDeopt);
5858 } // namespace internal