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 (is_sloppy(info_->language_mode()) && info()->MayUseThis() &&
122 !info_->is_native() && info_->scope()->has_this_declaration()) {
124 int receiver_offset = info_->scope()->num_parameters() * kPointerSize;
125 __ ldr(r2, MemOperand(sp, receiver_offset));
126 __ CompareRoot(r2, Heap::kUndefinedValueRootIndex);
129 __ ldr(r2, GlobalObjectOperand());
130 __ ldr(r2, FieldMemOperand(r2, GlobalObject::kGlobalProxyOffset));
132 __ str(r2, MemOperand(sp, receiver_offset));
138 info()->set_prologue_offset(masm_->pc_offset());
139 if (NeedsEagerFrame()) {
140 if (info()->IsStub()) {
143 __ Prologue(info()->IsCodePreAgingActive());
145 frame_is_built_ = true;
146 info_->AddNoFrameRange(0, masm_->pc_offset());
149 // Reserve space for the stack slots needed by the code.
150 int slots = GetStackSlotCount();
152 if (FLAG_debug_code) {
153 __ sub(sp, sp, Operand(slots * kPointerSize));
156 __ add(r0, sp, Operand(slots * kPointerSize));
157 __ mov(r1, Operand(kSlotsZapValue));
160 __ sub(r0, r0, Operand(kPointerSize));
161 __ str(r1, MemOperand(r0, 2 * kPointerSize));
167 __ sub(sp, sp, Operand(slots * kPointerSize));
171 if (info()->saves_caller_doubles()) {
175 // Possibly allocate a local context.
176 int heap_slots = info()->num_heap_slots() - Context::MIN_CONTEXT_SLOTS;
177 if (heap_slots > 0) {
178 Comment(";;; Allocate local context");
179 bool need_write_barrier = true;
180 // Argument to NewContext is the function, which is in r1.
181 DCHECK(!info()->scope()->is_script_scope());
182 if (heap_slots <= FastNewContextStub::kMaximumSlots) {
183 FastNewContextStub stub(isolate(), heap_slots);
185 // Result of FastNewContextStub is always in new space.
186 need_write_barrier = false;
189 __ CallRuntime(Runtime::kNewFunctionContext, 1);
191 RecordSafepoint(Safepoint::kNoLazyDeopt);
192 // Context is returned in both r0 and cp. It replaces the context
193 // passed to us. It's saved in the stack and kept live in cp.
195 __ str(r0, MemOperand(fp, StandardFrameConstants::kContextOffset));
196 // Copy any necessary parameters into the context.
197 int num_parameters = scope()->num_parameters();
198 int first_parameter = scope()->has_this_declaration() ? -1 : 0;
199 for (int i = first_parameter; i < num_parameters; i++) {
200 Variable* var = (i == -1) ? scope()->receiver() : scope()->parameter(i);
201 if (var->IsContextSlot()) {
202 int parameter_offset = StandardFrameConstants::kCallerSPOffset +
203 (num_parameters - 1 - i) * kPointerSize;
204 // Load parameter from stack.
205 __ ldr(r0, MemOperand(fp, parameter_offset));
206 // Store it in the context.
207 MemOperand target = ContextOperand(cp, var->index());
209 // Update the write barrier. This clobbers r3 and r0.
210 if (need_write_barrier) {
211 __ RecordWriteContextSlot(
216 GetLinkRegisterState(),
218 } else if (FLAG_debug_code) {
220 __ JumpIfInNewSpace(cp, r0, &done);
221 __ Abort(kExpectedNewSpaceObject);
226 Comment(";;; End allocate local context");
230 if (FLAG_trace && info()->IsOptimizing()) {
231 // We have not executed any compiled code yet, so cp still holds the
233 __ CallRuntime(Runtime::kTraceEnter, 0);
235 return !is_aborted();
239 void LCodeGen::GenerateOsrPrologue() {
240 // Generate the OSR entry prologue at the first unknown OSR value, or if there
241 // are none, at the OSR entrypoint instruction.
242 if (osr_pc_offset_ >= 0) return;
244 osr_pc_offset_ = masm()->pc_offset();
246 // Adjust the frame size, subsuming the unoptimized frame into the
248 int slots = GetStackSlotCount() - graph()->osr()->UnoptimizedFrameSlots();
250 __ sub(sp, sp, Operand(slots * kPointerSize));
254 void LCodeGen::GenerateBodyInstructionPre(LInstruction* instr) {
255 if (instr->IsCall()) {
256 EnsureSpaceForLazyDeopt(Deoptimizer::patch_size());
258 if (!instr->IsLazyBailout() && !instr->IsGap()) {
259 safepoints_.BumpLastLazySafepointIndex();
264 bool LCodeGen::GenerateDeferredCode() {
265 DCHECK(is_generating());
266 if (deferred_.length() > 0) {
267 for (int i = 0; !is_aborted() && i < deferred_.length(); i++) {
268 LDeferredCode* code = deferred_[i];
271 instructions_->at(code->instruction_index())->hydrogen_value();
272 RecordAndWritePosition(
273 chunk()->graph()->SourcePositionToScriptPosition(value->position()));
275 Comment(";;; <@%d,#%d> "
276 "-------------------- Deferred %s --------------------",
277 code->instruction_index(),
278 code->instr()->hydrogen_value()->id(),
279 code->instr()->Mnemonic());
280 __ bind(code->entry());
281 if (NeedsDeferredFrame()) {
282 Comment(";;; Build frame");
283 DCHECK(!frame_is_built_);
284 DCHECK(info()->IsStub());
285 frame_is_built_ = true;
287 __ mov(scratch0(), Operand(Smi::FromInt(StackFrame::STUB)));
289 __ add(fp, sp, Operand(StandardFrameConstants::kFixedFrameSizeFromFp));
290 Comment(";;; Deferred code");
293 if (NeedsDeferredFrame()) {
294 Comment(";;; Destroy frame");
295 DCHECK(frame_is_built_);
298 frame_is_built_ = false;
300 __ jmp(code->exit());
304 // Force constant pool emission at the end of the deferred code to make
305 // sure that no constant pools are emitted after.
306 masm()->CheckConstPool(true, false);
308 return !is_aborted();
312 bool LCodeGen::GenerateJumpTable() {
313 // Check that the jump table is accessible from everywhere in the function
314 // code, i.e. that offsets to the table can be encoded in the 24bit signed
315 // immediate of a branch instruction.
316 // To simplify we consider the code size from the first instruction to the
317 // end of the jump table. We also don't consider the pc load delta.
318 // Each entry in the jump table generates one instruction and inlines one
319 // 32bit data after it.
320 if (!is_int24((masm()->pc_offset() / Assembler::kInstrSize) +
321 jump_table_.length() * 7)) {
322 Abort(kGeneratedCodeIsTooLarge);
325 if (jump_table_.length() > 0) {
326 Label needs_frame, call_deopt_entry;
328 Comment(";;; -------------------- Jump table --------------------");
329 Address base = jump_table_[0].address;
331 Register entry_offset = scratch0();
333 int length = jump_table_.length();
334 for (int i = 0; i < length; i++) {
335 Deoptimizer::JumpTableEntry* table_entry = &jump_table_[i];
336 __ bind(&table_entry->label);
338 DCHECK_EQ(jump_table_[0].bailout_type, table_entry->bailout_type);
339 Address entry = table_entry->address;
340 DeoptComment(table_entry->deopt_info);
342 // Second-level deopt table entries are contiguous and small, so instead
343 // of loading the full, absolute address of each one, load an immediate
344 // offset which will be added to the base address later.
345 __ mov(entry_offset, Operand(entry - base));
347 if (table_entry->needs_frame) {
348 DCHECK(!info()->saves_caller_doubles());
349 Comment(";;; call deopt with frame");
353 __ bl(&call_deopt_entry);
355 info()->LogDeoptCallPosition(masm()->pc_offset(),
356 table_entry->deopt_info.inlining_id);
357 masm()->CheckConstPool(false, false);
360 if (needs_frame.is_linked()) {
361 __ bind(&needs_frame);
362 // This variant of deopt can only be used with stubs. Since we don't
363 // have a function pointer to install in the stack frame that we're
364 // building, install a special marker there instead.
365 DCHECK(info()->IsStub());
366 __ mov(ip, Operand(Smi::FromInt(StackFrame::STUB)));
368 __ add(fp, sp, Operand(StandardFrameConstants::kFixedFrameSizeFromFp));
371 Comment(";;; call deopt");
372 __ bind(&call_deopt_entry);
374 if (info()->saves_caller_doubles()) {
375 DCHECK(info()->IsStub());
376 RestoreCallerDoubles();
379 // Add the base address to the offset previously loaded in entry_offset.
380 __ add(entry_offset, entry_offset,
381 Operand(ExternalReference::ForDeoptEntry(base)));
385 // Force constant pool emission at the end of the deopt jump table to make
386 // sure that no constant pools are emitted after.
387 masm()->CheckConstPool(true, false);
389 // The deoptimization jump table is the last part of the instruction
390 // sequence. Mark the generated code as done unless we bailed out.
391 if (!is_aborted()) status_ = DONE;
392 return !is_aborted();
396 bool LCodeGen::GenerateSafepointTable() {
398 safepoints_.Emit(masm(), GetStackSlotCount());
399 return !is_aborted();
403 Register LCodeGen::ToRegister(int index) const {
404 return Register::FromAllocationIndex(index);
408 DwVfpRegister LCodeGen::ToDoubleRegister(int index) const {
409 return DwVfpRegister::FromAllocationIndex(index);
413 Register LCodeGen::ToRegister(LOperand* op) const {
414 DCHECK(op->IsRegister());
415 return ToRegister(op->index());
419 Register LCodeGen::EmitLoadRegister(LOperand* op, Register scratch) {
420 if (op->IsRegister()) {
421 return ToRegister(op->index());
422 } else if (op->IsConstantOperand()) {
423 LConstantOperand* const_op = LConstantOperand::cast(op);
424 HConstant* constant = chunk_->LookupConstant(const_op);
425 Handle<Object> literal = constant->handle(isolate());
426 Representation r = chunk_->LookupLiteralRepresentation(const_op);
427 if (r.IsInteger32()) {
428 AllowDeferredHandleDereference get_number;
429 DCHECK(literal->IsNumber());
430 __ mov(scratch, Operand(static_cast<int32_t>(literal->Number())));
431 } else if (r.IsDouble()) {
432 Abort(kEmitLoadRegisterUnsupportedDoubleImmediate);
434 DCHECK(r.IsSmiOrTagged());
435 __ Move(scratch, literal);
438 } else if (op->IsStackSlot()) {
439 __ ldr(scratch, ToMemOperand(op));
447 DwVfpRegister LCodeGen::ToDoubleRegister(LOperand* op) const {
448 DCHECK(op->IsDoubleRegister());
449 return ToDoubleRegister(op->index());
453 DwVfpRegister LCodeGen::EmitLoadDoubleRegister(LOperand* op,
454 SwVfpRegister flt_scratch,
455 DwVfpRegister dbl_scratch) {
456 if (op->IsDoubleRegister()) {
457 return ToDoubleRegister(op->index());
458 } else if (op->IsConstantOperand()) {
459 LConstantOperand* const_op = LConstantOperand::cast(op);
460 HConstant* constant = chunk_->LookupConstant(const_op);
461 Handle<Object> literal = constant->handle(isolate());
462 Representation r = chunk_->LookupLiteralRepresentation(const_op);
463 if (r.IsInteger32()) {
464 DCHECK(literal->IsNumber());
465 __ mov(ip, Operand(static_cast<int32_t>(literal->Number())));
466 __ vmov(flt_scratch, ip);
467 __ vcvt_f64_s32(dbl_scratch, flt_scratch);
469 } else if (r.IsDouble()) {
470 Abort(kUnsupportedDoubleImmediate);
471 } else if (r.IsTagged()) {
472 Abort(kUnsupportedTaggedImmediate);
474 } else if (op->IsStackSlot()) {
475 // TODO(regis): Why is vldr not taking a MemOperand?
476 // __ vldr(dbl_scratch, ToMemOperand(op));
477 MemOperand mem_op = ToMemOperand(op);
478 __ vldr(dbl_scratch, mem_op.rn(), mem_op.offset());
486 Handle<Object> LCodeGen::ToHandle(LConstantOperand* op) const {
487 HConstant* constant = chunk_->LookupConstant(op);
488 DCHECK(chunk_->LookupLiteralRepresentation(op).IsSmiOrTagged());
489 return constant->handle(isolate());
493 bool LCodeGen::IsInteger32(LConstantOperand* op) const {
494 return chunk_->LookupLiteralRepresentation(op).IsSmiOrInteger32();
498 bool LCodeGen::IsSmi(LConstantOperand* op) const {
499 return chunk_->LookupLiteralRepresentation(op).IsSmi();
503 int32_t LCodeGen::ToInteger32(LConstantOperand* op) const {
504 return ToRepresentation(op, Representation::Integer32());
508 int32_t LCodeGen::ToRepresentation(LConstantOperand* op,
509 const Representation& r) const {
510 HConstant* constant = chunk_->LookupConstant(op);
511 int32_t value = constant->Integer32Value();
512 if (r.IsInteger32()) return value;
513 DCHECK(r.IsSmiOrTagged());
514 return reinterpret_cast<int32_t>(Smi::FromInt(value));
518 Smi* LCodeGen::ToSmi(LConstantOperand* op) const {
519 HConstant* constant = chunk_->LookupConstant(op);
520 return Smi::FromInt(constant->Integer32Value());
524 double LCodeGen::ToDouble(LConstantOperand* op) const {
525 HConstant* constant = chunk_->LookupConstant(op);
526 DCHECK(constant->HasDoubleValue());
527 return constant->DoubleValue();
531 Operand LCodeGen::ToOperand(LOperand* op) {
532 if (op->IsConstantOperand()) {
533 LConstantOperand* const_op = LConstantOperand::cast(op);
534 HConstant* constant = chunk()->LookupConstant(const_op);
535 Representation r = chunk_->LookupLiteralRepresentation(const_op);
537 DCHECK(constant->HasSmiValue());
538 return Operand(Smi::FromInt(constant->Integer32Value()));
539 } else if (r.IsInteger32()) {
540 DCHECK(constant->HasInteger32Value());
541 return Operand(constant->Integer32Value());
542 } else if (r.IsDouble()) {
543 Abort(kToOperandUnsupportedDoubleImmediate);
545 DCHECK(r.IsTagged());
546 return Operand(constant->handle(isolate()));
547 } else if (op->IsRegister()) {
548 return Operand(ToRegister(op));
549 } else if (op->IsDoubleRegister()) {
550 Abort(kToOperandIsDoubleRegisterUnimplemented);
551 return Operand::Zero();
553 // Stack slots not implemented, use ToMemOperand instead.
555 return Operand::Zero();
559 static int ArgumentsOffsetWithoutFrame(int index) {
561 return -(index + 1) * kPointerSize;
565 MemOperand LCodeGen::ToMemOperand(LOperand* op) const {
566 DCHECK(!op->IsRegister());
567 DCHECK(!op->IsDoubleRegister());
568 DCHECK(op->IsStackSlot() || op->IsDoubleStackSlot());
569 if (NeedsEagerFrame()) {
570 return MemOperand(fp, StackSlotOffset(op->index()));
572 // Retrieve parameter without eager stack-frame relative to the
574 return MemOperand(sp, ArgumentsOffsetWithoutFrame(op->index()));
579 MemOperand LCodeGen::ToHighMemOperand(LOperand* op) const {
580 DCHECK(op->IsDoubleStackSlot());
581 if (NeedsEagerFrame()) {
582 return MemOperand(fp, StackSlotOffset(op->index()) + kPointerSize);
584 // Retrieve parameter without eager stack-frame relative to the
587 sp, ArgumentsOffsetWithoutFrame(op->index()) + kPointerSize);
592 void LCodeGen::WriteTranslation(LEnvironment* environment,
593 Translation* translation) {
594 if (environment == NULL) return;
596 // The translation includes one command per value in the environment.
597 int translation_size = environment->translation_size();
599 WriteTranslation(environment->outer(), translation);
600 WriteTranslationFrame(environment, translation);
602 int object_index = 0;
603 int dematerialized_index = 0;
604 for (int i = 0; i < translation_size; ++i) {
605 LOperand* value = environment->values()->at(i);
607 environment, translation, value, environment->HasTaggedValueAt(i),
608 environment->HasUint32ValueAt(i), &object_index, &dematerialized_index);
613 void LCodeGen::AddToTranslation(LEnvironment* environment,
614 Translation* translation,
618 int* object_index_pointer,
619 int* dematerialized_index_pointer) {
620 if (op == LEnvironment::materialization_marker()) {
621 int object_index = (*object_index_pointer)++;
622 if (environment->ObjectIsDuplicateAt(object_index)) {
623 int dupe_of = environment->ObjectDuplicateOfAt(object_index);
624 translation->DuplicateObject(dupe_of);
627 int object_length = environment->ObjectLengthAt(object_index);
628 if (environment->ObjectIsArgumentsAt(object_index)) {
629 translation->BeginArgumentsObject(object_length);
631 translation->BeginCapturedObject(object_length);
633 int dematerialized_index = *dematerialized_index_pointer;
634 int env_offset = environment->translation_size() + dematerialized_index;
635 *dematerialized_index_pointer += object_length;
636 for (int i = 0; i < object_length; ++i) {
637 LOperand* value = environment->values()->at(env_offset + i);
638 AddToTranslation(environment,
641 environment->HasTaggedValueAt(env_offset + i),
642 environment->HasUint32ValueAt(env_offset + i),
643 object_index_pointer,
644 dematerialized_index_pointer);
649 if (op->IsStackSlot()) {
650 int index = op->index();
652 index += StandardFrameConstants::kFixedFrameSize / kPointerSize;
655 translation->StoreStackSlot(index);
656 } else if (is_uint32) {
657 translation->StoreUint32StackSlot(index);
659 translation->StoreInt32StackSlot(index);
661 } else if (op->IsDoubleStackSlot()) {
662 int index = op->index();
664 index += StandardFrameConstants::kFixedFrameSize / kPointerSize;
666 translation->StoreDoubleStackSlot(index);
667 } else if (op->IsRegister()) {
668 Register reg = ToRegister(op);
670 translation->StoreRegister(reg);
671 } else if (is_uint32) {
672 translation->StoreUint32Register(reg);
674 translation->StoreInt32Register(reg);
676 } else if (op->IsDoubleRegister()) {
677 DoubleRegister reg = ToDoubleRegister(op);
678 translation->StoreDoubleRegister(reg);
679 } else if (op->IsConstantOperand()) {
680 HConstant* constant = chunk()->LookupConstant(LConstantOperand::cast(op));
681 int src_index = DefineDeoptimizationLiteral(constant->handle(isolate()));
682 translation->StoreLiteral(src_index);
689 int LCodeGen::CallCodeSize(Handle<Code> code, RelocInfo::Mode mode) {
690 int size = masm()->CallSize(code, mode);
691 if (code->kind() == Code::BINARY_OP_IC ||
692 code->kind() == Code::COMPARE_IC) {
693 size += Assembler::kInstrSize; // extra nop() added in CallCodeGeneric.
699 void LCodeGen::CallCode(Handle<Code> code,
700 RelocInfo::Mode mode,
702 TargetAddressStorageMode storage_mode) {
703 CallCodeGeneric(code, mode, instr, RECORD_SIMPLE_SAFEPOINT, storage_mode);
707 void LCodeGen::CallCodeGeneric(Handle<Code> code,
708 RelocInfo::Mode mode,
710 SafepointMode safepoint_mode,
711 TargetAddressStorageMode storage_mode) {
712 DCHECK(instr != NULL);
713 // Block literal pool emission to ensure nop indicating no inlined smi code
714 // is in the correct position.
715 Assembler::BlockConstPoolScope block_const_pool(masm());
716 __ Call(code, mode, TypeFeedbackId::None(), al, storage_mode);
717 RecordSafepointWithLazyDeopt(instr, safepoint_mode);
719 // Signal that we don't inline smi code before these stubs in the
720 // optimizing code generator.
721 if (code->kind() == Code::BINARY_OP_IC ||
722 code->kind() == Code::COMPARE_IC) {
728 void LCodeGen::CallRuntime(const Runtime::Function* function,
731 SaveFPRegsMode save_doubles) {
732 DCHECK(instr != NULL);
734 __ CallRuntime(function, num_arguments, save_doubles);
736 RecordSafepointWithLazyDeopt(instr, RECORD_SIMPLE_SAFEPOINT);
740 void LCodeGen::LoadContextFromDeferred(LOperand* context) {
741 if (context->IsRegister()) {
742 __ Move(cp, ToRegister(context));
743 } else if (context->IsStackSlot()) {
744 __ ldr(cp, ToMemOperand(context));
745 } else if (context->IsConstantOperand()) {
746 HConstant* constant =
747 chunk_->LookupConstant(LConstantOperand::cast(context));
748 __ Move(cp, Handle<Object>::cast(constant->handle(isolate())));
755 void LCodeGen::CallRuntimeFromDeferred(Runtime::FunctionId id,
759 LoadContextFromDeferred(context);
760 __ CallRuntimeSaveDoubles(id);
761 RecordSafepointWithRegisters(
762 instr->pointer_map(), argc, Safepoint::kNoLazyDeopt);
766 void LCodeGen::RegisterEnvironmentForDeoptimization(LEnvironment* environment,
767 Safepoint::DeoptMode mode) {
768 environment->set_has_been_used();
769 if (!environment->HasBeenRegistered()) {
770 // Physical stack frame layout:
771 // -x ............. -4 0 ..................................... y
772 // [incoming arguments] [spill slots] [pushed outgoing arguments]
774 // Layout of the environment:
775 // 0 ..................................................... size-1
776 // [parameters] [locals] [expression stack including arguments]
778 // Layout of the translation:
779 // 0 ........................................................ size - 1 + 4
780 // [expression stack including arguments] [locals] [4 words] [parameters]
781 // |>------------ translation_size ------------<|
784 int jsframe_count = 0;
785 for (LEnvironment* e = environment; e != NULL; e = e->outer()) {
787 if (e->frame_type() == JS_FUNCTION) {
791 Translation translation(&translations_, frame_count, jsframe_count, zone());
792 WriteTranslation(environment, &translation);
793 int deoptimization_index = deoptimizations_.length();
794 int pc_offset = masm()->pc_offset();
795 environment->Register(deoptimization_index,
797 (mode == Safepoint::kLazyDeopt) ? pc_offset : -1);
798 deoptimizations_.Add(environment, zone());
803 void LCodeGen::DeoptimizeIf(Condition condition, LInstruction* instr,
804 Deoptimizer::DeoptReason deopt_reason,
805 Deoptimizer::BailoutType bailout_type) {
806 LEnvironment* environment = instr->environment();
807 RegisterEnvironmentForDeoptimization(environment, Safepoint::kNoLazyDeopt);
808 DCHECK(environment->HasBeenRegistered());
809 int id = environment->deoptimization_index();
810 DCHECK(info()->IsOptimizing() || info()->IsStub());
812 Deoptimizer::GetDeoptimizationEntry(isolate(), id, bailout_type);
814 Abort(kBailoutWasNotPrepared);
818 if (FLAG_deopt_every_n_times != 0 && !info()->IsStub()) {
819 Register scratch = scratch0();
820 ExternalReference count = ExternalReference::stress_deopt_count(isolate());
822 // Store the condition on the stack if necessary
823 if (condition != al) {
824 __ mov(scratch, Operand::Zero(), LeaveCC, NegateCondition(condition));
825 __ mov(scratch, Operand(1), LeaveCC, condition);
830 __ mov(scratch, Operand(count));
831 __ ldr(r1, MemOperand(scratch));
832 __ sub(r1, r1, Operand(1), SetCC);
833 __ mov(r1, Operand(FLAG_deopt_every_n_times), LeaveCC, eq);
834 __ str(r1, MemOperand(scratch));
837 if (condition != al) {
838 // Clean up the stack before the deoptimizer call
842 __ Call(entry, RelocInfo::RUNTIME_ENTRY, eq);
844 // 'Restore' the condition in a slightly hacky way. (It would be better
845 // to use 'msr' and 'mrs' instructions here, but they are not supported by
846 // our ARM simulator).
847 if (condition != al) {
849 __ cmp(scratch, Operand::Zero());
853 if (info()->ShouldTrapOnDeopt()) {
854 __ stop("trap_on_deopt", condition);
857 Deoptimizer::DeoptInfo deopt_info = MakeDeoptInfo(instr, deopt_reason);
859 DCHECK(info()->IsStub() || frame_is_built_);
860 // Go through jump table if we need to handle condition, build frame, or
861 // restore caller doubles.
862 if (condition == al && frame_is_built_ &&
863 !info()->saves_caller_doubles()) {
864 DeoptComment(deopt_info);
865 __ Call(entry, RelocInfo::RUNTIME_ENTRY);
866 info()->LogDeoptCallPosition(masm()->pc_offset(), deopt_info.inlining_id);
868 Deoptimizer::JumpTableEntry table_entry(entry, deopt_info, bailout_type,
870 // We often have several deopts to the same entry, reuse the last
871 // jump entry if this is the case.
872 if (FLAG_trace_deopt || isolate()->cpu_profiler()->is_profiling() ||
873 jump_table_.is_empty() ||
874 !table_entry.IsEquivalentTo(jump_table_.last())) {
875 jump_table_.Add(table_entry, zone());
877 __ b(condition, &jump_table_.last().label);
882 void LCodeGen::DeoptimizeIf(Condition condition, LInstruction* instr,
883 Deoptimizer::DeoptReason deopt_reason) {
884 Deoptimizer::BailoutType bailout_type = info()->IsStub()
886 : Deoptimizer::EAGER;
887 DeoptimizeIf(condition, instr, deopt_reason, bailout_type);
891 void LCodeGen::PopulateDeoptimizationData(Handle<Code> code) {
892 int length = deoptimizations_.length();
893 if (length == 0) return;
894 Handle<DeoptimizationInputData> data =
895 DeoptimizationInputData::New(isolate(), length, TENURED);
897 Handle<ByteArray> translations =
898 translations_.CreateByteArray(isolate()->factory());
899 data->SetTranslationByteArray(*translations);
900 data->SetInlinedFunctionCount(Smi::FromInt(inlined_function_count_));
901 data->SetOptimizationId(Smi::FromInt(info_->optimization_id()));
902 if (info_->IsOptimizing()) {
903 // Reference to shared function info does not change between phases.
904 AllowDeferredHandleDereference allow_handle_dereference;
905 data->SetSharedFunctionInfo(*info_->shared_info());
907 data->SetSharedFunctionInfo(Smi::FromInt(0));
909 data->SetWeakCellCache(Smi::FromInt(0));
911 Handle<FixedArray> literals =
912 factory()->NewFixedArray(deoptimization_literals_.length(), TENURED);
913 { AllowDeferredHandleDereference copy_handles;
914 for (int i = 0; i < deoptimization_literals_.length(); i++) {
915 literals->set(i, *deoptimization_literals_[i]);
917 data->SetLiteralArray(*literals);
920 data->SetOsrAstId(Smi::FromInt(info_->osr_ast_id().ToInt()));
921 data->SetOsrPcOffset(Smi::FromInt(osr_pc_offset_));
923 // Populate the deoptimization entries.
924 for (int i = 0; i < length; i++) {
925 LEnvironment* env = deoptimizations_[i];
926 data->SetAstId(i, env->ast_id());
927 data->SetTranslationIndex(i, Smi::FromInt(env->translation_index()));
928 data->SetArgumentsStackHeight(i,
929 Smi::FromInt(env->arguments_stack_height()));
930 data->SetPc(i, Smi::FromInt(env->pc_offset()));
932 code->set_deoptimization_data(*data);
936 void LCodeGen::PopulateDeoptimizationLiteralsWithInlinedFunctions() {
937 DCHECK_EQ(0, deoptimization_literals_.length());
938 for (auto function : chunk()->inlined_functions()) {
939 DefineDeoptimizationLiteral(function);
941 inlined_function_count_ = deoptimization_literals_.length();
945 void LCodeGen::RecordSafepointWithLazyDeopt(
946 LInstruction* instr, SafepointMode safepoint_mode) {
947 if (safepoint_mode == RECORD_SIMPLE_SAFEPOINT) {
948 RecordSafepoint(instr->pointer_map(), Safepoint::kLazyDeopt);
950 DCHECK(safepoint_mode == RECORD_SAFEPOINT_WITH_REGISTERS_AND_NO_ARGUMENTS);
951 RecordSafepointWithRegisters(
952 instr->pointer_map(), 0, Safepoint::kLazyDeopt);
957 void LCodeGen::RecordSafepoint(
958 LPointerMap* pointers,
959 Safepoint::Kind kind,
961 Safepoint::DeoptMode deopt_mode) {
962 DCHECK(expected_safepoint_kind_ == kind);
964 const ZoneList<LOperand*>* operands = pointers->GetNormalizedOperands();
965 Safepoint safepoint = safepoints_.DefineSafepoint(masm(),
966 kind, arguments, deopt_mode);
967 for (int i = 0; i < operands->length(); i++) {
968 LOperand* pointer = operands->at(i);
969 if (pointer->IsStackSlot()) {
970 safepoint.DefinePointerSlot(pointer->index(), zone());
971 } else if (pointer->IsRegister() && (kind & Safepoint::kWithRegisters)) {
972 safepoint.DefinePointerRegister(ToRegister(pointer), zone());
978 void LCodeGen::RecordSafepoint(LPointerMap* pointers,
979 Safepoint::DeoptMode deopt_mode) {
980 RecordSafepoint(pointers, Safepoint::kSimple, 0, deopt_mode);
984 void LCodeGen::RecordSafepoint(Safepoint::DeoptMode deopt_mode) {
985 LPointerMap empty_pointers(zone());
986 RecordSafepoint(&empty_pointers, deopt_mode);
990 void LCodeGen::RecordSafepointWithRegisters(LPointerMap* pointers,
992 Safepoint::DeoptMode deopt_mode) {
994 pointers, Safepoint::kWithRegisters, arguments, deopt_mode);
998 void LCodeGen::RecordAndWritePosition(int position) {
999 if (position == RelocInfo::kNoPosition) return;
1000 masm()->positions_recorder()->RecordPosition(position);
1001 masm()->positions_recorder()->WriteRecordedPositions();
1005 static const char* LabelType(LLabel* label) {
1006 if (label->is_loop_header()) return " (loop header)";
1007 if (label->is_osr_entry()) return " (OSR entry)";
1012 void LCodeGen::DoLabel(LLabel* label) {
1013 Comment(";;; <@%d,#%d> -------------------- B%d%s --------------------",
1014 current_instruction_,
1015 label->hydrogen_value()->id(),
1018 __ bind(label->label());
1019 current_block_ = label->block_id();
1024 void LCodeGen::DoParallelMove(LParallelMove* move) {
1025 resolver_.Resolve(move);
1029 void LCodeGen::DoGap(LGap* gap) {
1030 for (int i = LGap::FIRST_INNER_POSITION;
1031 i <= LGap::LAST_INNER_POSITION;
1033 LGap::InnerPosition inner_pos = static_cast<LGap::InnerPosition>(i);
1034 LParallelMove* move = gap->GetParallelMove(inner_pos);
1035 if (move != NULL) DoParallelMove(move);
1040 void LCodeGen::DoInstructionGap(LInstructionGap* instr) {
1045 void LCodeGen::DoParameter(LParameter* instr) {
1050 void LCodeGen::DoCallStub(LCallStub* instr) {
1051 DCHECK(ToRegister(instr->context()).is(cp));
1052 DCHECK(ToRegister(instr->result()).is(r0));
1053 switch (instr->hydrogen()->major_key()) {
1054 case CodeStub::RegExpExec: {
1055 RegExpExecStub stub(isolate());
1056 CallCode(stub.GetCode(), RelocInfo::CODE_TARGET, instr);
1059 case CodeStub::SubString: {
1060 SubStringStub stub(isolate());
1061 CallCode(stub.GetCode(), RelocInfo::CODE_TARGET, instr);
1064 case CodeStub::StringCompare: {
1065 StringCompareStub stub(isolate());
1066 CallCode(stub.GetCode(), RelocInfo::CODE_TARGET, instr);
1075 void LCodeGen::DoUnknownOSRValue(LUnknownOSRValue* instr) {
1076 GenerateOsrPrologue();
1080 void LCodeGen::DoModByPowerOf2I(LModByPowerOf2I* instr) {
1081 Register dividend = ToRegister(instr->dividend());
1082 int32_t divisor = instr->divisor();
1083 DCHECK(dividend.is(ToRegister(instr->result())));
1085 // Theoretically, a variation of the branch-free code for integer division by
1086 // a power of 2 (calculating the remainder via an additional multiplication
1087 // (which gets simplified to an 'and') and subtraction) should be faster, and
1088 // this is exactly what GCC and clang emit. Nevertheless, benchmarks seem to
1089 // indicate that positive dividends are heavily favored, so the branching
1090 // version performs better.
1091 HMod* hmod = instr->hydrogen();
1092 int32_t mask = divisor < 0 ? -(divisor + 1) : (divisor - 1);
1093 Label dividend_is_not_negative, done;
1094 if (hmod->CheckFlag(HValue::kLeftCanBeNegative)) {
1095 __ cmp(dividend, Operand::Zero());
1096 __ b(pl, ÷nd_is_not_negative);
1097 // Note that this is correct even for kMinInt operands.
1098 __ rsb(dividend, dividend, Operand::Zero());
1099 __ and_(dividend, dividend, Operand(mask));
1100 __ rsb(dividend, dividend, Operand::Zero(), SetCC);
1101 if (hmod->CheckFlag(HValue::kBailoutOnMinusZero)) {
1102 DeoptimizeIf(eq, instr, Deoptimizer::kMinusZero);
1107 __ bind(÷nd_is_not_negative);
1108 __ and_(dividend, dividend, Operand(mask));
1113 void LCodeGen::DoModByConstI(LModByConstI* instr) {
1114 Register dividend = ToRegister(instr->dividend());
1115 int32_t divisor = instr->divisor();
1116 Register result = ToRegister(instr->result());
1117 DCHECK(!dividend.is(result));
1120 DeoptimizeIf(al, instr, Deoptimizer::kDivisionByZero);
1124 __ TruncatingDiv(result, dividend, Abs(divisor));
1125 __ mov(ip, Operand(Abs(divisor)));
1126 __ smull(result, ip, result, ip);
1127 __ sub(result, dividend, result, SetCC);
1129 // Check for negative zero.
1130 HMod* hmod = instr->hydrogen();
1131 if (hmod->CheckFlag(HValue::kBailoutOnMinusZero)) {
1132 Label remainder_not_zero;
1133 __ b(ne, &remainder_not_zero);
1134 __ cmp(dividend, Operand::Zero());
1135 DeoptimizeIf(lt, instr, Deoptimizer::kMinusZero);
1136 __ bind(&remainder_not_zero);
1141 void LCodeGen::DoModI(LModI* instr) {
1142 HMod* hmod = instr->hydrogen();
1143 if (CpuFeatures::IsSupported(SUDIV)) {
1144 CpuFeatureScope scope(masm(), SUDIV);
1146 Register left_reg = ToRegister(instr->left());
1147 Register right_reg = ToRegister(instr->right());
1148 Register result_reg = ToRegister(instr->result());
1151 // Check for x % 0, sdiv might signal an exception. We have to deopt in this
1152 // case because we can't return a NaN.
1153 if (hmod->CheckFlag(HValue::kCanBeDivByZero)) {
1154 __ cmp(right_reg, Operand::Zero());
1155 DeoptimizeIf(eq, instr, Deoptimizer::kDivisionByZero);
1158 // Check for kMinInt % -1, sdiv will return kMinInt, which is not what we
1159 // want. We have to deopt if we care about -0, because we can't return that.
1160 if (hmod->CheckFlag(HValue::kCanOverflow)) {
1161 Label no_overflow_possible;
1162 __ cmp(left_reg, Operand(kMinInt));
1163 __ b(ne, &no_overflow_possible);
1164 __ cmp(right_reg, Operand(-1));
1165 if (hmod->CheckFlag(HValue::kBailoutOnMinusZero)) {
1166 DeoptimizeIf(eq, instr, Deoptimizer::kMinusZero);
1168 __ b(ne, &no_overflow_possible);
1169 __ mov(result_reg, Operand::Zero());
1172 __ bind(&no_overflow_possible);
1175 // For 'r3 = r1 % r2' we can have the following ARM code:
1177 // mls r3, r3, r2, r1
1179 __ sdiv(result_reg, left_reg, right_reg);
1180 __ Mls(result_reg, result_reg, right_reg, left_reg);
1182 // If we care about -0, test if the dividend is <0 and the result is 0.
1183 if (hmod->CheckFlag(HValue::kBailoutOnMinusZero)) {
1184 __ cmp(result_reg, Operand::Zero());
1186 __ cmp(left_reg, Operand::Zero());
1187 DeoptimizeIf(lt, instr, Deoptimizer::kMinusZero);
1192 // General case, without any SDIV support.
1193 Register left_reg = ToRegister(instr->left());
1194 Register right_reg = ToRegister(instr->right());
1195 Register result_reg = ToRegister(instr->result());
1196 Register scratch = scratch0();
1197 DCHECK(!scratch.is(left_reg));
1198 DCHECK(!scratch.is(right_reg));
1199 DCHECK(!scratch.is(result_reg));
1200 DwVfpRegister dividend = ToDoubleRegister(instr->temp());
1201 DwVfpRegister divisor = ToDoubleRegister(instr->temp2());
1202 DCHECK(!divisor.is(dividend));
1203 LowDwVfpRegister quotient = double_scratch0();
1204 DCHECK(!quotient.is(dividend));
1205 DCHECK(!quotient.is(divisor));
1208 // Check for x % 0, we have to deopt in this case because we can't return a
1210 if (hmod->CheckFlag(HValue::kCanBeDivByZero)) {
1211 __ cmp(right_reg, Operand::Zero());
1212 DeoptimizeIf(eq, instr, Deoptimizer::kDivisionByZero);
1215 __ Move(result_reg, left_reg);
1216 // Load the arguments in VFP registers. The divisor value is preloaded
1217 // before. Be careful that 'right_reg' is only live on entry.
1218 // TODO(svenpanne) The last comments seems to be wrong nowadays.
1219 __ vmov(double_scratch0().low(), left_reg);
1220 __ vcvt_f64_s32(dividend, double_scratch0().low());
1221 __ vmov(double_scratch0().low(), right_reg);
1222 __ vcvt_f64_s32(divisor, double_scratch0().low());
1224 // We do not care about the sign of the divisor. Note that we still handle
1225 // the kMinInt % -1 case correctly, though.
1226 __ vabs(divisor, divisor);
1227 // Compute the quotient and round it to a 32bit integer.
1228 __ vdiv(quotient, dividend, divisor);
1229 __ vcvt_s32_f64(quotient.low(), quotient);
1230 __ vcvt_f64_s32(quotient, quotient.low());
1232 // Compute the remainder in result.
1233 __ vmul(double_scratch0(), divisor, quotient);
1234 __ vcvt_s32_f64(double_scratch0().low(), double_scratch0());
1235 __ vmov(scratch, double_scratch0().low());
1236 __ sub(result_reg, left_reg, scratch, SetCC);
1238 // If we care about -0, test if the dividend is <0 and the result is 0.
1239 if (hmod->CheckFlag(HValue::kBailoutOnMinusZero)) {
1241 __ cmp(left_reg, Operand::Zero());
1242 DeoptimizeIf(mi, instr, Deoptimizer::kMinusZero);
1249 void LCodeGen::DoDivByPowerOf2I(LDivByPowerOf2I* instr) {
1250 Register dividend = ToRegister(instr->dividend());
1251 int32_t divisor = instr->divisor();
1252 Register result = ToRegister(instr->result());
1253 DCHECK(divisor == kMinInt || base::bits::IsPowerOfTwo32(Abs(divisor)));
1254 DCHECK(!result.is(dividend));
1256 // Check for (0 / -x) that will produce negative zero.
1257 HDiv* hdiv = instr->hydrogen();
1258 if (hdiv->CheckFlag(HValue::kBailoutOnMinusZero) && divisor < 0) {
1259 __ cmp(dividend, Operand::Zero());
1260 DeoptimizeIf(eq, instr, Deoptimizer::kMinusZero);
1262 // Check for (kMinInt / -1).
1263 if (hdiv->CheckFlag(HValue::kCanOverflow) && divisor == -1) {
1264 __ cmp(dividend, Operand(kMinInt));
1265 DeoptimizeIf(eq, instr, Deoptimizer::kOverflow);
1267 // Deoptimize if remainder will not be 0.
1268 if (!hdiv->CheckFlag(HInstruction::kAllUsesTruncatingToInt32) &&
1269 divisor != 1 && divisor != -1) {
1270 int32_t mask = divisor < 0 ? -(divisor + 1) : (divisor - 1);
1271 __ tst(dividend, Operand(mask));
1272 DeoptimizeIf(ne, instr, Deoptimizer::kLostPrecision);
1275 if (divisor == -1) { // Nice shortcut, not needed for correctness.
1276 __ rsb(result, dividend, Operand(0));
1279 int32_t shift = WhichPowerOf2Abs(divisor);
1281 __ mov(result, dividend);
1282 } else if (shift == 1) {
1283 __ add(result, dividend, Operand(dividend, LSR, 31));
1285 __ mov(result, Operand(dividend, ASR, 31));
1286 __ add(result, dividend, Operand(result, LSR, 32 - shift));
1288 if (shift > 0) __ mov(result, Operand(result, ASR, shift));
1289 if (divisor < 0) __ rsb(result, result, Operand(0));
1293 void LCodeGen::DoDivByConstI(LDivByConstI* instr) {
1294 Register dividend = ToRegister(instr->dividend());
1295 int32_t divisor = instr->divisor();
1296 Register result = ToRegister(instr->result());
1297 DCHECK(!dividend.is(result));
1300 DeoptimizeIf(al, instr, Deoptimizer::kDivisionByZero);
1304 // Check for (0 / -x) that will produce negative zero.
1305 HDiv* hdiv = instr->hydrogen();
1306 if (hdiv->CheckFlag(HValue::kBailoutOnMinusZero) && divisor < 0) {
1307 __ cmp(dividend, Operand::Zero());
1308 DeoptimizeIf(eq, instr, Deoptimizer::kMinusZero);
1311 __ TruncatingDiv(result, dividend, Abs(divisor));
1312 if (divisor < 0) __ rsb(result, result, Operand::Zero());
1314 if (!hdiv->CheckFlag(HInstruction::kAllUsesTruncatingToInt32)) {
1315 __ mov(ip, Operand(divisor));
1316 __ smull(scratch0(), ip, result, ip);
1317 __ sub(scratch0(), scratch0(), dividend, SetCC);
1318 DeoptimizeIf(ne, instr, Deoptimizer::kLostPrecision);
1323 // TODO(svenpanne) Refactor this to avoid code duplication with DoFlooringDivI.
1324 void LCodeGen::DoDivI(LDivI* instr) {
1325 HBinaryOperation* hdiv = instr->hydrogen();
1326 Register dividend = ToRegister(instr->dividend());
1327 Register divisor = ToRegister(instr->divisor());
1328 Register result = ToRegister(instr->result());
1331 if (hdiv->CheckFlag(HValue::kCanBeDivByZero)) {
1332 __ cmp(divisor, Operand::Zero());
1333 DeoptimizeIf(eq, instr, Deoptimizer::kDivisionByZero);
1336 // Check for (0 / -x) that will produce negative zero.
1337 if (hdiv->CheckFlag(HValue::kBailoutOnMinusZero)) {
1339 if (!instr->hydrogen_value()->CheckFlag(HValue::kCanBeDivByZero)) {
1340 // Do the test only if it hadn't be done above.
1341 __ cmp(divisor, Operand::Zero());
1343 __ b(pl, &positive);
1344 __ cmp(dividend, Operand::Zero());
1345 DeoptimizeIf(eq, instr, Deoptimizer::kMinusZero);
1349 // Check for (kMinInt / -1).
1350 if (hdiv->CheckFlag(HValue::kCanOverflow) &&
1351 (!CpuFeatures::IsSupported(SUDIV) ||
1352 !hdiv->CheckFlag(HValue::kAllUsesTruncatingToInt32))) {
1353 // We don't need to check for overflow when truncating with sdiv
1354 // support because, on ARM, sdiv kMinInt, -1 -> kMinInt.
1355 __ cmp(dividend, Operand(kMinInt));
1356 __ cmp(divisor, Operand(-1), eq);
1357 DeoptimizeIf(eq, instr, Deoptimizer::kOverflow);
1360 if (CpuFeatures::IsSupported(SUDIV)) {
1361 CpuFeatureScope scope(masm(), SUDIV);
1362 __ sdiv(result, dividend, divisor);
1364 DoubleRegister vleft = ToDoubleRegister(instr->temp());
1365 DoubleRegister vright = double_scratch0();
1366 __ vmov(double_scratch0().low(), dividend);
1367 __ vcvt_f64_s32(vleft, double_scratch0().low());
1368 __ vmov(double_scratch0().low(), divisor);
1369 __ vcvt_f64_s32(vright, double_scratch0().low());
1370 __ vdiv(vleft, vleft, vright); // vleft now contains the result.
1371 __ vcvt_s32_f64(double_scratch0().low(), vleft);
1372 __ vmov(result, double_scratch0().low());
1375 if (!hdiv->CheckFlag(HValue::kAllUsesTruncatingToInt32)) {
1376 // Compute remainder and deopt if it's not zero.
1377 Register remainder = scratch0();
1378 __ Mls(remainder, result, divisor, dividend);
1379 __ cmp(remainder, Operand::Zero());
1380 DeoptimizeIf(ne, instr, Deoptimizer::kLostPrecision);
1385 void LCodeGen::DoMultiplyAddD(LMultiplyAddD* instr) {
1386 DwVfpRegister addend = ToDoubleRegister(instr->addend());
1387 DwVfpRegister multiplier = ToDoubleRegister(instr->multiplier());
1388 DwVfpRegister multiplicand = ToDoubleRegister(instr->multiplicand());
1390 // This is computed in-place.
1391 DCHECK(addend.is(ToDoubleRegister(instr->result())));
1393 __ vmla(addend, multiplier, multiplicand);
1397 void LCodeGen::DoMultiplySubD(LMultiplySubD* instr) {
1398 DwVfpRegister minuend = ToDoubleRegister(instr->minuend());
1399 DwVfpRegister multiplier = ToDoubleRegister(instr->multiplier());
1400 DwVfpRegister multiplicand = ToDoubleRegister(instr->multiplicand());
1402 // This is computed in-place.
1403 DCHECK(minuend.is(ToDoubleRegister(instr->result())));
1405 __ vmls(minuend, multiplier, multiplicand);
1409 void LCodeGen::DoFlooringDivByPowerOf2I(LFlooringDivByPowerOf2I* instr) {
1410 Register dividend = ToRegister(instr->dividend());
1411 Register result = ToRegister(instr->result());
1412 int32_t divisor = instr->divisor();
1414 // If the divisor is 1, return the dividend.
1416 __ Move(result, dividend);
1420 // If the divisor is positive, things are easy: There can be no deopts and we
1421 // can simply do an arithmetic right shift.
1422 int32_t shift = WhichPowerOf2Abs(divisor);
1424 __ mov(result, Operand(dividend, ASR, shift));
1428 // If the divisor is negative, we have to negate and handle edge cases.
1429 __ rsb(result, dividend, Operand::Zero(), SetCC);
1430 if (instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero)) {
1431 DeoptimizeIf(eq, instr, Deoptimizer::kMinusZero);
1434 // Dividing by -1 is basically negation, unless we overflow.
1435 if (divisor == -1) {
1436 if (instr->hydrogen()->CheckFlag(HValue::kLeftCanBeMinInt)) {
1437 DeoptimizeIf(vs, instr, Deoptimizer::kOverflow);
1442 // If the negation could not overflow, simply shifting is OK.
1443 if (!instr->hydrogen()->CheckFlag(HValue::kLeftCanBeMinInt)) {
1444 __ mov(result, Operand(result, ASR, shift));
1448 __ mov(result, Operand(kMinInt / divisor), LeaveCC, vs);
1449 __ mov(result, Operand(result, ASR, shift), LeaveCC, vc);
1453 void LCodeGen::DoFlooringDivByConstI(LFlooringDivByConstI* instr) {
1454 Register dividend = ToRegister(instr->dividend());
1455 int32_t divisor = instr->divisor();
1456 Register result = ToRegister(instr->result());
1457 DCHECK(!dividend.is(result));
1460 DeoptimizeIf(al, instr, Deoptimizer::kDivisionByZero);
1464 // Check for (0 / -x) that will produce negative zero.
1465 HMathFloorOfDiv* hdiv = instr->hydrogen();
1466 if (hdiv->CheckFlag(HValue::kBailoutOnMinusZero) && divisor < 0) {
1467 __ cmp(dividend, Operand::Zero());
1468 DeoptimizeIf(eq, instr, Deoptimizer::kMinusZero);
1471 // Easy case: We need no dynamic check for the dividend and the flooring
1472 // division is the same as the truncating division.
1473 if ((divisor > 0 && !hdiv->CheckFlag(HValue::kLeftCanBeNegative)) ||
1474 (divisor < 0 && !hdiv->CheckFlag(HValue::kLeftCanBePositive))) {
1475 __ TruncatingDiv(result, dividend, Abs(divisor));
1476 if (divisor < 0) __ rsb(result, result, Operand::Zero());
1480 // In the general case we may need to adjust before and after the truncating
1481 // division to get a flooring division.
1482 Register temp = ToRegister(instr->temp());
1483 DCHECK(!temp.is(dividend) && !temp.is(result));
1484 Label needs_adjustment, done;
1485 __ cmp(dividend, Operand::Zero());
1486 __ b(divisor > 0 ? lt : gt, &needs_adjustment);
1487 __ TruncatingDiv(result, dividend, Abs(divisor));
1488 if (divisor < 0) __ rsb(result, result, Operand::Zero());
1490 __ bind(&needs_adjustment);
1491 __ add(temp, dividend, Operand(divisor > 0 ? 1 : -1));
1492 __ TruncatingDiv(result, temp, Abs(divisor));
1493 if (divisor < 0) __ rsb(result, result, Operand::Zero());
1494 __ sub(result, result, Operand(1));
1499 // TODO(svenpanne) Refactor this to avoid code duplication with DoDivI.
1500 void LCodeGen::DoFlooringDivI(LFlooringDivI* instr) {
1501 HBinaryOperation* hdiv = instr->hydrogen();
1502 Register left = ToRegister(instr->dividend());
1503 Register right = ToRegister(instr->divisor());
1504 Register result = ToRegister(instr->result());
1507 if (hdiv->CheckFlag(HValue::kCanBeDivByZero)) {
1508 __ cmp(right, Operand::Zero());
1509 DeoptimizeIf(eq, instr, Deoptimizer::kDivisionByZero);
1512 // Check for (0 / -x) that will produce negative zero.
1513 if (hdiv->CheckFlag(HValue::kBailoutOnMinusZero)) {
1515 if (!instr->hydrogen_value()->CheckFlag(HValue::kCanBeDivByZero)) {
1516 // Do the test only if it hadn't be done above.
1517 __ cmp(right, Operand::Zero());
1519 __ b(pl, &positive);
1520 __ cmp(left, Operand::Zero());
1521 DeoptimizeIf(eq, instr, Deoptimizer::kMinusZero);
1525 // Check for (kMinInt / -1).
1526 if (hdiv->CheckFlag(HValue::kCanOverflow) &&
1527 (!CpuFeatures::IsSupported(SUDIV) ||
1528 !hdiv->CheckFlag(HValue::kAllUsesTruncatingToInt32))) {
1529 // We don't need to check for overflow when truncating with sdiv
1530 // support because, on ARM, sdiv kMinInt, -1 -> kMinInt.
1531 __ cmp(left, Operand(kMinInt));
1532 __ cmp(right, Operand(-1), eq);
1533 DeoptimizeIf(eq, instr, Deoptimizer::kOverflow);
1536 if (CpuFeatures::IsSupported(SUDIV)) {
1537 CpuFeatureScope scope(masm(), SUDIV);
1538 __ sdiv(result, left, right);
1540 DoubleRegister vleft = ToDoubleRegister(instr->temp());
1541 DoubleRegister vright = double_scratch0();
1542 __ vmov(double_scratch0().low(), left);
1543 __ vcvt_f64_s32(vleft, double_scratch0().low());
1544 __ vmov(double_scratch0().low(), right);
1545 __ vcvt_f64_s32(vright, double_scratch0().low());
1546 __ vdiv(vleft, vleft, vright); // vleft now contains the result.
1547 __ vcvt_s32_f64(double_scratch0().low(), vleft);
1548 __ vmov(result, double_scratch0().low());
1552 Register remainder = scratch0();
1553 __ Mls(remainder, result, right, left);
1554 __ cmp(remainder, Operand::Zero());
1556 __ eor(remainder, remainder, Operand(right));
1557 __ add(result, result, Operand(remainder, ASR, 31));
1562 void LCodeGen::DoMulI(LMulI* instr) {
1563 Register result = ToRegister(instr->result());
1564 // Note that result may alias left.
1565 Register left = ToRegister(instr->left());
1566 LOperand* right_op = instr->right();
1568 bool bailout_on_minus_zero =
1569 instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero);
1570 bool overflow = instr->hydrogen()->CheckFlag(HValue::kCanOverflow);
1572 if (right_op->IsConstantOperand()) {
1573 int32_t constant = ToInteger32(LConstantOperand::cast(right_op));
1575 if (bailout_on_minus_zero && (constant < 0)) {
1576 // The case of a null constant will be handled separately.
1577 // If constant is negative and left is null, the result should be -0.
1578 __ cmp(left, Operand::Zero());
1579 DeoptimizeIf(eq, instr, Deoptimizer::kMinusZero);
1585 __ rsb(result, left, Operand::Zero(), SetCC);
1586 DeoptimizeIf(vs, instr, Deoptimizer::kOverflow);
1588 __ rsb(result, left, Operand::Zero());
1592 if (bailout_on_minus_zero) {
1593 // If left is strictly negative and the constant is null, the
1594 // result is -0. Deoptimize if required, otherwise return 0.
1595 __ cmp(left, Operand::Zero());
1596 DeoptimizeIf(mi, instr, Deoptimizer::kMinusZero);
1598 __ mov(result, Operand::Zero());
1601 __ Move(result, left);
1604 // Multiplying by powers of two and powers of two plus or minus
1605 // one can be done faster with shifted operands.
1606 // For other constants we emit standard code.
1607 int32_t mask = constant >> 31;
1608 uint32_t constant_abs = (constant + mask) ^ mask;
1610 if (base::bits::IsPowerOfTwo32(constant_abs)) {
1611 int32_t shift = WhichPowerOf2(constant_abs);
1612 __ mov(result, Operand(left, LSL, shift));
1613 // Correct the sign of the result is the constant is negative.
1614 if (constant < 0) __ rsb(result, result, Operand::Zero());
1615 } else if (base::bits::IsPowerOfTwo32(constant_abs - 1)) {
1616 int32_t shift = WhichPowerOf2(constant_abs - 1);
1617 __ add(result, left, Operand(left, LSL, shift));
1618 // Correct the sign of the result is the constant is negative.
1619 if (constant < 0) __ rsb(result, result, Operand::Zero());
1620 } else if (base::bits::IsPowerOfTwo32(constant_abs + 1)) {
1621 int32_t shift = WhichPowerOf2(constant_abs + 1);
1622 __ rsb(result, left, Operand(left, LSL, shift));
1623 // Correct the sign of the result is the constant is negative.
1624 if (constant < 0) __ rsb(result, result, Operand::Zero());
1626 // Generate standard code.
1627 __ mov(ip, Operand(constant));
1628 __ mul(result, left, ip);
1633 DCHECK(right_op->IsRegister());
1634 Register right = ToRegister(right_op);
1637 Register scratch = scratch0();
1638 // scratch:result = left * right.
1639 if (instr->hydrogen()->representation().IsSmi()) {
1640 __ SmiUntag(result, left);
1641 __ smull(result, scratch, result, right);
1643 __ smull(result, scratch, left, right);
1645 __ cmp(scratch, Operand(result, ASR, 31));
1646 DeoptimizeIf(ne, instr, Deoptimizer::kOverflow);
1648 if (instr->hydrogen()->representation().IsSmi()) {
1649 __ SmiUntag(result, left);
1650 __ mul(result, result, right);
1652 __ mul(result, left, right);
1656 if (bailout_on_minus_zero) {
1658 __ teq(left, Operand(right));
1660 // Bail out if the result is minus zero.
1661 __ cmp(result, Operand::Zero());
1662 DeoptimizeIf(eq, instr, Deoptimizer::kMinusZero);
1669 void LCodeGen::DoBitI(LBitI* instr) {
1670 LOperand* left_op = instr->left();
1671 LOperand* right_op = instr->right();
1672 DCHECK(left_op->IsRegister());
1673 Register left = ToRegister(left_op);
1674 Register result = ToRegister(instr->result());
1675 Operand right(no_reg);
1677 if (right_op->IsStackSlot()) {
1678 right = Operand(EmitLoadRegister(right_op, ip));
1680 DCHECK(right_op->IsRegister() || right_op->IsConstantOperand());
1681 right = ToOperand(right_op);
1684 switch (instr->op()) {
1685 case Token::BIT_AND:
1686 __ and_(result, left, right);
1689 __ orr(result, left, right);
1691 case Token::BIT_XOR:
1692 if (right_op->IsConstantOperand() && right.immediate() == int32_t(~0)) {
1693 __ mvn(result, Operand(left));
1695 __ eor(result, left, right);
1705 void LCodeGen::DoShiftI(LShiftI* instr) {
1706 // Both 'left' and 'right' are "used at start" (see LCodeGen::DoShift), so
1707 // result may alias either of them.
1708 LOperand* right_op = instr->right();
1709 Register left = ToRegister(instr->left());
1710 Register result = ToRegister(instr->result());
1711 Register scratch = scratch0();
1712 if (right_op->IsRegister()) {
1713 // Mask the right_op operand.
1714 __ and_(scratch, ToRegister(right_op), Operand(0x1F));
1715 switch (instr->op()) {
1717 __ mov(result, Operand(left, ROR, scratch));
1720 __ mov(result, Operand(left, ASR, scratch));
1723 if (instr->can_deopt()) {
1724 __ mov(result, Operand(left, LSR, scratch), SetCC);
1725 DeoptimizeIf(mi, instr, Deoptimizer::kNegativeValue);
1727 __ mov(result, Operand(left, LSR, scratch));
1731 __ mov(result, Operand(left, LSL, scratch));
1738 // Mask the right_op operand.
1739 int value = ToInteger32(LConstantOperand::cast(right_op));
1740 uint8_t shift_count = static_cast<uint8_t>(value & 0x1F);
1741 switch (instr->op()) {
1743 if (shift_count != 0) {
1744 __ mov(result, Operand(left, ROR, shift_count));
1746 __ Move(result, left);
1750 if (shift_count != 0) {
1751 __ mov(result, Operand(left, ASR, shift_count));
1753 __ Move(result, left);
1757 if (shift_count != 0) {
1758 __ mov(result, Operand(left, LSR, shift_count));
1760 if (instr->can_deopt()) {
1761 __ tst(left, Operand(0x80000000));
1762 DeoptimizeIf(ne, instr, Deoptimizer::kNegativeValue);
1764 __ Move(result, left);
1768 if (shift_count != 0) {
1769 if (instr->hydrogen_value()->representation().IsSmi() &&
1770 instr->can_deopt()) {
1771 if (shift_count != 1) {
1772 __ mov(result, Operand(left, LSL, shift_count - 1));
1773 __ SmiTag(result, result, SetCC);
1775 __ SmiTag(result, left, SetCC);
1777 DeoptimizeIf(vs, instr, Deoptimizer::kOverflow);
1779 __ mov(result, Operand(left, LSL, shift_count));
1782 __ Move(result, left);
1793 void LCodeGen::DoSubI(LSubI* instr) {
1794 LOperand* left = instr->left();
1795 LOperand* right = instr->right();
1796 LOperand* result = instr->result();
1797 bool can_overflow = instr->hydrogen()->CheckFlag(HValue::kCanOverflow);
1798 SBit set_cond = can_overflow ? SetCC : LeaveCC;
1800 if (right->IsStackSlot()) {
1801 Register right_reg = EmitLoadRegister(right, ip);
1802 __ sub(ToRegister(result), ToRegister(left), Operand(right_reg), set_cond);
1804 DCHECK(right->IsRegister() || right->IsConstantOperand());
1805 __ sub(ToRegister(result), ToRegister(left), ToOperand(right), set_cond);
1809 DeoptimizeIf(vs, instr, Deoptimizer::kOverflow);
1814 void LCodeGen::DoRSubI(LRSubI* instr) {
1815 LOperand* left = instr->left();
1816 LOperand* right = instr->right();
1817 LOperand* result = instr->result();
1818 bool can_overflow = instr->hydrogen()->CheckFlag(HValue::kCanOverflow);
1819 SBit set_cond = can_overflow ? SetCC : LeaveCC;
1821 if (right->IsStackSlot()) {
1822 Register right_reg = EmitLoadRegister(right, ip);
1823 __ rsb(ToRegister(result), ToRegister(left), Operand(right_reg), set_cond);
1825 DCHECK(right->IsRegister() || right->IsConstantOperand());
1826 __ rsb(ToRegister(result), ToRegister(left), ToOperand(right), set_cond);
1830 DeoptimizeIf(vs, instr, Deoptimizer::kOverflow);
1835 void LCodeGen::DoConstantI(LConstantI* instr) {
1836 __ mov(ToRegister(instr->result()), Operand(instr->value()));
1840 void LCodeGen::DoConstantS(LConstantS* instr) {
1841 __ mov(ToRegister(instr->result()), Operand(instr->value()));
1845 void LCodeGen::DoConstantD(LConstantD* instr) {
1846 DCHECK(instr->result()->IsDoubleRegister());
1847 DwVfpRegister result = ToDoubleRegister(instr->result());
1848 #if V8_HOST_ARCH_IA32
1849 // Need some crappy work-around for x87 sNaN -> qNaN breakage in simulator
1851 uint64_t bits = instr->bits();
1852 if ((bits & V8_UINT64_C(0x7FF8000000000000)) ==
1853 V8_UINT64_C(0x7FF0000000000000)) {
1854 uint32_t lo = static_cast<uint32_t>(bits);
1855 uint32_t hi = static_cast<uint32_t>(bits >> 32);
1856 __ mov(ip, Operand(lo));
1857 __ mov(scratch0(), Operand(hi));
1858 __ vmov(result, ip, scratch0());
1862 double v = instr->value();
1863 __ Vmov(result, v, scratch0());
1867 void LCodeGen::DoConstantE(LConstantE* instr) {
1868 __ mov(ToRegister(instr->result()), Operand(instr->value()));
1872 void LCodeGen::DoConstantT(LConstantT* instr) {
1873 Handle<Object> object = instr->value(isolate());
1874 AllowDeferredHandleDereference smi_check;
1875 __ Move(ToRegister(instr->result()), object);
1879 void LCodeGen::DoMapEnumLength(LMapEnumLength* instr) {
1880 Register result = ToRegister(instr->result());
1881 Register map = ToRegister(instr->value());
1882 __ EnumLength(result, map);
1886 void LCodeGen::DoDateField(LDateField* instr) {
1887 Register object = ToRegister(instr->date());
1888 Register result = ToRegister(instr->result());
1889 Register scratch = ToRegister(instr->temp());
1890 Smi* index = instr->index();
1891 DCHECK(object.is(result));
1892 DCHECK(object.is(r0));
1893 DCHECK(!scratch.is(scratch0()));
1894 DCHECK(!scratch.is(object));
1896 if (index->value() == 0) {
1897 __ ldr(result, FieldMemOperand(object, JSDate::kValueOffset));
1899 Label runtime, done;
1900 if (index->value() < JSDate::kFirstUncachedField) {
1901 ExternalReference stamp = ExternalReference::date_cache_stamp(isolate());
1902 __ mov(scratch, Operand(stamp));
1903 __ ldr(scratch, MemOperand(scratch));
1904 __ ldr(scratch0(), FieldMemOperand(object, JSDate::kCacheStampOffset));
1905 __ cmp(scratch, scratch0());
1907 __ ldr(result, FieldMemOperand(object, JSDate::kValueOffset +
1908 kPointerSize * index->value()));
1912 __ PrepareCallCFunction(2, scratch);
1913 __ mov(r1, Operand(index));
1914 __ CallCFunction(ExternalReference::get_date_field_function(isolate()), 2);
1920 MemOperand LCodeGen::BuildSeqStringOperand(Register string,
1922 String::Encoding encoding) {
1923 if (index->IsConstantOperand()) {
1924 int offset = ToInteger32(LConstantOperand::cast(index));
1925 if (encoding == String::TWO_BYTE_ENCODING) {
1926 offset *= kUC16Size;
1928 STATIC_ASSERT(kCharSize == 1);
1929 return FieldMemOperand(string, SeqString::kHeaderSize + offset);
1931 Register scratch = scratch0();
1932 DCHECK(!scratch.is(string));
1933 DCHECK(!scratch.is(ToRegister(index)));
1934 if (encoding == String::ONE_BYTE_ENCODING) {
1935 __ add(scratch, string, Operand(ToRegister(index)));
1937 STATIC_ASSERT(kUC16Size == 2);
1938 __ add(scratch, string, Operand(ToRegister(index), LSL, 1));
1940 return FieldMemOperand(scratch, SeqString::kHeaderSize);
1944 void LCodeGen::DoSeqStringGetChar(LSeqStringGetChar* instr) {
1945 String::Encoding encoding = instr->hydrogen()->encoding();
1946 Register string = ToRegister(instr->string());
1947 Register result = ToRegister(instr->result());
1949 if (FLAG_debug_code) {
1950 Register scratch = scratch0();
1951 __ ldr(scratch, FieldMemOperand(string, HeapObject::kMapOffset));
1952 __ ldrb(scratch, FieldMemOperand(scratch, Map::kInstanceTypeOffset));
1954 __ and_(scratch, scratch,
1955 Operand(kStringRepresentationMask | kStringEncodingMask));
1956 static const uint32_t one_byte_seq_type = kSeqStringTag | kOneByteStringTag;
1957 static const uint32_t two_byte_seq_type = kSeqStringTag | kTwoByteStringTag;
1958 __ cmp(scratch, Operand(encoding == String::ONE_BYTE_ENCODING
1959 ? one_byte_seq_type : two_byte_seq_type));
1960 __ Check(eq, kUnexpectedStringType);
1963 MemOperand operand = BuildSeqStringOperand(string, instr->index(), encoding);
1964 if (encoding == String::ONE_BYTE_ENCODING) {
1965 __ ldrb(result, operand);
1967 __ ldrh(result, operand);
1972 void LCodeGen::DoSeqStringSetChar(LSeqStringSetChar* instr) {
1973 String::Encoding encoding = instr->hydrogen()->encoding();
1974 Register string = ToRegister(instr->string());
1975 Register value = ToRegister(instr->value());
1977 if (FLAG_debug_code) {
1978 Register index = ToRegister(instr->index());
1979 static const uint32_t one_byte_seq_type = kSeqStringTag | kOneByteStringTag;
1980 static const uint32_t two_byte_seq_type = kSeqStringTag | kTwoByteStringTag;
1982 instr->hydrogen()->encoding() == String::ONE_BYTE_ENCODING
1983 ? one_byte_seq_type : two_byte_seq_type;
1984 __ EmitSeqStringSetCharCheck(string, index, value, encoding_mask);
1987 MemOperand operand = BuildSeqStringOperand(string, instr->index(), encoding);
1988 if (encoding == String::ONE_BYTE_ENCODING) {
1989 __ strb(value, operand);
1991 __ strh(value, operand);
1996 void LCodeGen::DoAddI(LAddI* instr) {
1997 LOperand* left = instr->left();
1998 LOperand* right = instr->right();
1999 LOperand* result = instr->result();
2000 bool can_overflow = instr->hydrogen()->CheckFlag(HValue::kCanOverflow);
2001 SBit set_cond = can_overflow ? SetCC : LeaveCC;
2003 if (right->IsStackSlot()) {
2004 Register right_reg = EmitLoadRegister(right, ip);
2005 __ add(ToRegister(result), ToRegister(left), Operand(right_reg), set_cond);
2007 DCHECK(right->IsRegister() || right->IsConstantOperand());
2008 __ add(ToRegister(result), ToRegister(left), ToOperand(right), set_cond);
2012 DeoptimizeIf(vs, instr, Deoptimizer::kOverflow);
2017 void LCodeGen::DoMathMinMax(LMathMinMax* instr) {
2018 LOperand* left = instr->left();
2019 LOperand* right = instr->right();
2020 HMathMinMax::Operation operation = instr->hydrogen()->operation();
2021 if (instr->hydrogen()->representation().IsSmiOrInteger32()) {
2022 Condition condition = (operation == HMathMinMax::kMathMin) ? le : ge;
2023 Register left_reg = ToRegister(left);
2024 Operand right_op = (right->IsRegister() || right->IsConstantOperand())
2026 : Operand(EmitLoadRegister(right, ip));
2027 Register result_reg = ToRegister(instr->result());
2028 __ cmp(left_reg, right_op);
2029 __ Move(result_reg, left_reg, condition);
2030 __ mov(result_reg, right_op, LeaveCC, NegateCondition(condition));
2032 DCHECK(instr->hydrogen()->representation().IsDouble());
2033 DwVfpRegister left_reg = ToDoubleRegister(left);
2034 DwVfpRegister right_reg = ToDoubleRegister(right);
2035 DwVfpRegister result_reg = ToDoubleRegister(instr->result());
2036 Label result_is_nan, return_left, return_right, check_zero, done;
2037 __ VFPCompareAndSetFlags(left_reg, right_reg);
2038 if (operation == HMathMinMax::kMathMin) {
2039 __ b(mi, &return_left);
2040 __ b(gt, &return_right);
2042 __ b(mi, &return_right);
2043 __ b(gt, &return_left);
2045 __ b(vs, &result_is_nan);
2046 // Left equals right => check for -0.
2047 __ VFPCompareAndSetFlags(left_reg, 0.0);
2048 if (left_reg.is(result_reg) || right_reg.is(result_reg)) {
2049 __ b(ne, &done); // left == right != 0.
2051 __ b(ne, &return_left); // left == right != 0.
2053 // At this point, both left and right are either 0 or -0.
2054 if (operation == HMathMinMax::kMathMin) {
2055 // We could use a single 'vorr' instruction here if we had NEON support.
2056 __ vneg(left_reg, left_reg);
2057 __ vsub(result_reg, left_reg, right_reg);
2058 __ vneg(result_reg, result_reg);
2060 // Since we operate on +0 and/or -0, vadd and vand have the same effect;
2061 // the decision for vadd is easy because vand is a NEON instruction.
2062 __ vadd(result_reg, left_reg, right_reg);
2066 __ bind(&result_is_nan);
2067 __ vadd(result_reg, left_reg, right_reg);
2070 __ bind(&return_right);
2071 __ Move(result_reg, right_reg);
2072 if (!left_reg.is(result_reg)) {
2076 __ bind(&return_left);
2077 __ Move(result_reg, left_reg);
2084 void LCodeGen::DoArithmeticD(LArithmeticD* instr) {
2085 DwVfpRegister left = ToDoubleRegister(instr->left());
2086 DwVfpRegister right = ToDoubleRegister(instr->right());
2087 DwVfpRegister result = ToDoubleRegister(instr->result());
2088 switch (instr->op()) {
2090 __ vadd(result, left, right);
2093 __ vsub(result, left, right);
2096 __ vmul(result, left, right);
2099 __ vdiv(result, left, right);
2102 __ PrepareCallCFunction(0, 2, scratch0());
2103 __ MovToFloatParameters(left, right);
2105 ExternalReference::mod_two_doubles_operation(isolate()),
2107 // Move the result in the double result register.
2108 __ MovFromFloatResult(result);
2118 void LCodeGen::DoArithmeticT(LArithmeticT* instr) {
2119 DCHECK(ToRegister(instr->context()).is(cp));
2120 DCHECK(ToRegister(instr->left()).is(r1));
2121 DCHECK(ToRegister(instr->right()).is(r0));
2122 DCHECK(ToRegister(instr->result()).is(r0));
2125 CodeFactory::BinaryOpIC(isolate(), instr->op(), instr->strength()).code();
2126 // Block literal pool emission to ensure nop indicating no inlined smi code
2127 // is in the correct position.
2128 Assembler::BlockConstPoolScope block_const_pool(masm());
2129 CallCode(code, RelocInfo::CODE_TARGET, instr);
2133 template<class InstrType>
2134 void LCodeGen::EmitBranch(InstrType instr, Condition condition) {
2135 int left_block = instr->TrueDestination(chunk_);
2136 int right_block = instr->FalseDestination(chunk_);
2138 int next_block = GetNextEmittedBlock();
2140 if (right_block == left_block || condition == al) {
2141 EmitGoto(left_block);
2142 } else if (left_block == next_block) {
2143 __ b(NegateCondition(condition), chunk_->GetAssemblyLabel(right_block));
2144 } else if (right_block == next_block) {
2145 __ b(condition, chunk_->GetAssemblyLabel(left_block));
2147 __ b(condition, chunk_->GetAssemblyLabel(left_block));
2148 __ b(chunk_->GetAssemblyLabel(right_block));
2153 template <class InstrType>
2154 void LCodeGen::EmitTrueBranch(InstrType instr, Condition condition) {
2155 int true_block = instr->TrueDestination(chunk_);
2156 __ b(condition, chunk_->GetAssemblyLabel(true_block));
2160 template <class InstrType>
2161 void LCodeGen::EmitFalseBranch(InstrType instr, Condition condition) {
2162 int false_block = instr->FalseDestination(chunk_);
2163 __ b(condition, chunk_->GetAssemblyLabel(false_block));
2167 void LCodeGen::DoDebugBreak(LDebugBreak* instr) {
2172 void LCodeGen::DoBranch(LBranch* instr) {
2173 Representation r = instr->hydrogen()->value()->representation();
2174 if (r.IsInteger32() || r.IsSmi()) {
2175 DCHECK(!info()->IsStub());
2176 Register reg = ToRegister(instr->value());
2177 __ cmp(reg, Operand::Zero());
2178 EmitBranch(instr, ne);
2179 } else if (r.IsDouble()) {
2180 DCHECK(!info()->IsStub());
2181 DwVfpRegister reg = ToDoubleRegister(instr->value());
2182 // Test the double value. Zero and NaN are false.
2183 __ VFPCompareAndSetFlags(reg, 0.0);
2184 __ cmp(r0, r0, vs); // If NaN, set the Z flag. (NaN -> false)
2185 EmitBranch(instr, ne);
2187 DCHECK(r.IsTagged());
2188 Register reg = ToRegister(instr->value());
2189 HType type = instr->hydrogen()->value()->type();
2190 if (type.IsBoolean()) {
2191 DCHECK(!info()->IsStub());
2192 __ CompareRoot(reg, Heap::kTrueValueRootIndex);
2193 EmitBranch(instr, eq);
2194 } else if (type.IsSmi()) {
2195 DCHECK(!info()->IsStub());
2196 __ cmp(reg, Operand::Zero());
2197 EmitBranch(instr, ne);
2198 } else if (type.IsJSArray()) {
2199 DCHECK(!info()->IsStub());
2200 EmitBranch(instr, al);
2201 } else if (type.IsHeapNumber()) {
2202 DCHECK(!info()->IsStub());
2203 DwVfpRegister dbl_scratch = double_scratch0();
2204 __ vldr(dbl_scratch, FieldMemOperand(reg, HeapNumber::kValueOffset));
2205 // Test the double value. Zero and NaN are false.
2206 __ VFPCompareAndSetFlags(dbl_scratch, 0.0);
2207 __ cmp(r0, r0, vs); // If NaN, set the Z flag. (NaN)
2208 EmitBranch(instr, ne);
2209 } else if (type.IsString()) {
2210 DCHECK(!info()->IsStub());
2211 __ ldr(ip, FieldMemOperand(reg, String::kLengthOffset));
2212 __ cmp(ip, Operand::Zero());
2213 EmitBranch(instr, ne);
2215 ToBooleanStub::Types expected = instr->hydrogen()->expected_input_types();
2216 // Avoid deopts in the case where we've never executed this path before.
2217 if (expected.IsEmpty()) expected = ToBooleanStub::Types::Generic();
2219 if (expected.Contains(ToBooleanStub::UNDEFINED)) {
2220 // undefined -> false.
2221 __ CompareRoot(reg, Heap::kUndefinedValueRootIndex);
2222 __ b(eq, instr->FalseLabel(chunk_));
2224 if (expected.Contains(ToBooleanStub::BOOLEAN)) {
2225 // Boolean -> its value.
2226 __ CompareRoot(reg, Heap::kTrueValueRootIndex);
2227 __ b(eq, instr->TrueLabel(chunk_));
2228 __ CompareRoot(reg, Heap::kFalseValueRootIndex);
2229 __ b(eq, instr->FalseLabel(chunk_));
2231 if (expected.Contains(ToBooleanStub::NULL_TYPE)) {
2233 __ CompareRoot(reg, Heap::kNullValueRootIndex);
2234 __ b(eq, instr->FalseLabel(chunk_));
2237 if (expected.Contains(ToBooleanStub::SMI)) {
2238 // Smis: 0 -> false, all other -> true.
2239 __ cmp(reg, Operand::Zero());
2240 __ b(eq, instr->FalseLabel(chunk_));
2241 __ JumpIfSmi(reg, instr->TrueLabel(chunk_));
2242 } else if (expected.NeedsMap()) {
2243 // If we need a map later and have a Smi -> deopt.
2245 DeoptimizeIf(eq, instr, Deoptimizer::kSmi);
2248 const Register map = scratch0();
2249 if (expected.NeedsMap()) {
2250 __ ldr(map, FieldMemOperand(reg, HeapObject::kMapOffset));
2252 if (expected.CanBeUndetectable()) {
2253 // Undetectable -> false.
2254 __ ldrb(ip, FieldMemOperand(map, Map::kBitFieldOffset));
2255 __ tst(ip, Operand(1 << Map::kIsUndetectable));
2256 __ b(ne, instr->FalseLabel(chunk_));
2260 if (expected.Contains(ToBooleanStub::SPEC_OBJECT)) {
2261 // spec object -> true.
2262 __ CompareInstanceType(map, ip, FIRST_SPEC_OBJECT_TYPE);
2263 __ b(ge, instr->TrueLabel(chunk_));
2266 if (expected.Contains(ToBooleanStub::STRING)) {
2267 // String value -> false iff empty.
2269 __ CompareInstanceType(map, ip, FIRST_NONSTRING_TYPE);
2270 __ b(ge, ¬_string);
2271 __ ldr(ip, FieldMemOperand(reg, String::kLengthOffset));
2272 __ cmp(ip, Operand::Zero());
2273 __ b(ne, instr->TrueLabel(chunk_));
2274 __ b(instr->FalseLabel(chunk_));
2275 __ bind(¬_string);
2278 if (expected.Contains(ToBooleanStub::SYMBOL)) {
2279 // Symbol value -> true.
2280 __ CompareInstanceType(map, ip, SYMBOL_TYPE);
2281 __ b(eq, instr->TrueLabel(chunk_));
2284 if (expected.Contains(ToBooleanStub::SIMD_VALUE)) {
2285 // SIMD value -> true.
2286 __ CompareInstanceType(map, ip, SIMD128_VALUE_TYPE);
2287 __ b(eq, instr->TrueLabel(chunk_));
2290 if (expected.Contains(ToBooleanStub::HEAP_NUMBER)) {
2291 // heap number -> false iff +0, -0, or NaN.
2292 DwVfpRegister dbl_scratch = double_scratch0();
2293 Label not_heap_number;
2294 __ CompareRoot(map, Heap::kHeapNumberMapRootIndex);
2295 __ b(ne, ¬_heap_number);
2296 __ vldr(dbl_scratch, FieldMemOperand(reg, HeapNumber::kValueOffset));
2297 __ VFPCompareAndSetFlags(dbl_scratch, 0.0);
2298 __ cmp(r0, r0, vs); // NaN -> false.
2299 __ b(eq, instr->FalseLabel(chunk_)); // +0, -0 -> false.
2300 __ b(instr->TrueLabel(chunk_));
2301 __ bind(¬_heap_number);
2304 if (!expected.IsGeneric()) {
2305 // We've seen something for the first time -> deopt.
2306 // This can only happen if we are not generic already.
2307 DeoptimizeIf(al, instr, Deoptimizer::kUnexpectedObject);
2314 void LCodeGen::EmitGoto(int block) {
2315 if (!IsNextEmittedBlock(block)) {
2316 __ jmp(chunk_->GetAssemblyLabel(LookupDestination(block)));
2321 void LCodeGen::DoGoto(LGoto* instr) {
2322 EmitGoto(instr->block_id());
2326 Condition LCodeGen::TokenToCondition(Token::Value op, bool is_unsigned) {
2327 Condition cond = kNoCondition;
2330 case Token::EQ_STRICT:
2334 case Token::NE_STRICT:
2338 cond = is_unsigned ? lo : lt;
2341 cond = is_unsigned ? hi : gt;
2344 cond = is_unsigned ? ls : le;
2347 cond = is_unsigned ? hs : ge;
2350 case Token::INSTANCEOF:
2358 void LCodeGen::DoCompareNumericAndBranch(LCompareNumericAndBranch* instr) {
2359 LOperand* left = instr->left();
2360 LOperand* right = instr->right();
2362 instr->hydrogen()->left()->CheckFlag(HInstruction::kUint32) ||
2363 instr->hydrogen()->right()->CheckFlag(HInstruction::kUint32);
2364 Condition cond = TokenToCondition(instr->op(), is_unsigned);
2366 if (left->IsConstantOperand() && right->IsConstantOperand()) {
2367 // We can statically evaluate the comparison.
2368 double left_val = ToDouble(LConstantOperand::cast(left));
2369 double right_val = ToDouble(LConstantOperand::cast(right));
2370 int next_block = EvalComparison(instr->op(), left_val, right_val) ?
2371 instr->TrueDestination(chunk_) : instr->FalseDestination(chunk_);
2372 EmitGoto(next_block);
2374 if (instr->is_double()) {
2375 // Compare left and right operands as doubles and load the
2376 // resulting flags into the normal status register.
2377 __ VFPCompareAndSetFlags(ToDoubleRegister(left), ToDoubleRegister(right));
2378 // If a NaN is involved, i.e. the result is unordered (V set),
2379 // jump to false block label.
2380 __ b(vs, instr->FalseLabel(chunk_));
2382 if (right->IsConstantOperand()) {
2383 int32_t value = ToInteger32(LConstantOperand::cast(right));
2384 if (instr->hydrogen_value()->representation().IsSmi()) {
2385 __ cmp(ToRegister(left), Operand(Smi::FromInt(value)));
2387 __ cmp(ToRegister(left), Operand(value));
2389 } else if (left->IsConstantOperand()) {
2390 int32_t value = ToInteger32(LConstantOperand::cast(left));
2391 if (instr->hydrogen_value()->representation().IsSmi()) {
2392 __ cmp(ToRegister(right), Operand(Smi::FromInt(value)));
2394 __ cmp(ToRegister(right), Operand(value));
2396 // We commuted the operands, so commute the condition.
2397 cond = CommuteCondition(cond);
2399 __ cmp(ToRegister(left), ToRegister(right));
2402 EmitBranch(instr, cond);
2407 void LCodeGen::DoCmpObjectEqAndBranch(LCmpObjectEqAndBranch* instr) {
2408 Register left = ToRegister(instr->left());
2409 Register right = ToRegister(instr->right());
2411 __ cmp(left, Operand(right));
2412 EmitBranch(instr, eq);
2416 void LCodeGen::DoCmpHoleAndBranch(LCmpHoleAndBranch* instr) {
2417 if (instr->hydrogen()->representation().IsTagged()) {
2418 Register input_reg = ToRegister(instr->object());
2419 __ mov(ip, Operand(factory()->the_hole_value()));
2420 __ cmp(input_reg, ip);
2421 EmitBranch(instr, eq);
2425 DwVfpRegister input_reg = ToDoubleRegister(instr->object());
2426 __ VFPCompareAndSetFlags(input_reg, input_reg);
2427 EmitFalseBranch(instr, vc);
2429 Register scratch = scratch0();
2430 __ VmovHigh(scratch, input_reg);
2431 __ cmp(scratch, Operand(kHoleNanUpper32));
2432 EmitBranch(instr, eq);
2436 void LCodeGen::DoCompareMinusZeroAndBranch(LCompareMinusZeroAndBranch* instr) {
2437 Representation rep = instr->hydrogen()->value()->representation();
2438 DCHECK(!rep.IsInteger32());
2439 Register scratch = ToRegister(instr->temp());
2441 if (rep.IsDouble()) {
2442 DwVfpRegister value = ToDoubleRegister(instr->value());
2443 __ VFPCompareAndSetFlags(value, 0.0);
2444 EmitFalseBranch(instr, ne);
2445 __ VmovHigh(scratch, value);
2446 __ cmp(scratch, Operand(0x80000000));
2448 Register value = ToRegister(instr->value());
2451 Heap::kHeapNumberMapRootIndex,
2452 instr->FalseLabel(chunk()),
2454 __ ldr(scratch, FieldMemOperand(value, HeapNumber::kExponentOffset));
2455 __ ldr(ip, FieldMemOperand(value, HeapNumber::kMantissaOffset));
2456 __ cmp(scratch, Operand(0x80000000));
2457 __ cmp(ip, Operand(0x00000000), eq);
2459 EmitBranch(instr, eq);
2463 Condition LCodeGen::EmitIsObject(Register input,
2465 Label* is_not_object,
2467 Register temp2 = scratch0();
2468 __ JumpIfSmi(input, is_not_object);
2470 __ LoadRoot(temp2, Heap::kNullValueRootIndex);
2471 __ cmp(input, temp2);
2472 __ b(eq, is_object);
2475 __ ldr(temp1, FieldMemOperand(input, HeapObject::kMapOffset));
2476 // Undetectable objects behave like undefined.
2477 __ ldrb(temp2, FieldMemOperand(temp1, Map::kBitFieldOffset));
2478 __ tst(temp2, Operand(1 << Map::kIsUndetectable));
2479 __ b(ne, is_not_object);
2481 // Load instance type and check that it is in object type range.
2482 __ ldrb(temp2, FieldMemOperand(temp1, Map::kInstanceTypeOffset));
2483 __ cmp(temp2, Operand(FIRST_NONCALLABLE_SPEC_OBJECT_TYPE));
2484 __ b(lt, is_not_object);
2485 __ cmp(temp2, Operand(LAST_NONCALLABLE_SPEC_OBJECT_TYPE));
2490 void LCodeGen::DoIsObjectAndBranch(LIsObjectAndBranch* instr) {
2491 Register reg = ToRegister(instr->value());
2492 Register temp1 = ToRegister(instr->temp());
2494 Condition true_cond =
2495 EmitIsObject(reg, temp1,
2496 instr->FalseLabel(chunk_), instr->TrueLabel(chunk_));
2498 EmitBranch(instr, true_cond);
2502 Condition LCodeGen::EmitIsString(Register input,
2504 Label* is_not_string,
2505 SmiCheck check_needed = INLINE_SMI_CHECK) {
2506 if (check_needed == INLINE_SMI_CHECK) {
2507 __ JumpIfSmi(input, is_not_string);
2509 __ CompareObjectType(input, temp1, temp1, FIRST_NONSTRING_TYPE);
2515 void LCodeGen::DoIsStringAndBranch(LIsStringAndBranch* instr) {
2516 Register reg = ToRegister(instr->value());
2517 Register temp1 = ToRegister(instr->temp());
2519 SmiCheck check_needed =
2520 instr->hydrogen()->value()->type().IsHeapObject()
2521 ? OMIT_SMI_CHECK : INLINE_SMI_CHECK;
2522 Condition true_cond =
2523 EmitIsString(reg, temp1, instr->FalseLabel(chunk_), check_needed);
2525 EmitBranch(instr, true_cond);
2529 void LCodeGen::DoIsSmiAndBranch(LIsSmiAndBranch* instr) {
2530 Register input_reg = EmitLoadRegister(instr->value(), ip);
2531 __ SmiTst(input_reg);
2532 EmitBranch(instr, eq);
2536 void LCodeGen::DoIsUndetectableAndBranch(LIsUndetectableAndBranch* instr) {
2537 Register input = ToRegister(instr->value());
2538 Register temp = ToRegister(instr->temp());
2540 if (!instr->hydrogen()->value()->type().IsHeapObject()) {
2541 __ JumpIfSmi(input, instr->FalseLabel(chunk_));
2543 __ ldr(temp, FieldMemOperand(input, HeapObject::kMapOffset));
2544 __ ldrb(temp, FieldMemOperand(temp, Map::kBitFieldOffset));
2545 __ tst(temp, Operand(1 << Map::kIsUndetectable));
2546 EmitBranch(instr, ne);
2550 static Condition ComputeCompareCondition(Token::Value op) {
2552 case Token::EQ_STRICT:
2565 return kNoCondition;
2570 void LCodeGen::DoStringCompareAndBranch(LStringCompareAndBranch* instr) {
2571 DCHECK(ToRegister(instr->context()).is(cp));
2572 Token::Value op = instr->op();
2575 CodeFactory::CompareIC(isolate(), op, Strength::WEAK).code();
2576 CallCode(ic, RelocInfo::CODE_TARGET, instr);
2577 // This instruction also signals no smi code inlined.
2578 __ cmp(r0, Operand::Zero());
2580 Condition condition = ComputeCompareCondition(op);
2582 EmitBranch(instr, condition);
2586 static InstanceType TestType(HHasInstanceTypeAndBranch* instr) {
2587 InstanceType from = instr->from();
2588 InstanceType to = instr->to();
2589 if (from == FIRST_TYPE) return to;
2590 DCHECK(from == to || to == LAST_TYPE);
2595 static Condition BranchCondition(HHasInstanceTypeAndBranch* instr) {
2596 InstanceType from = instr->from();
2597 InstanceType to = instr->to();
2598 if (from == to) return eq;
2599 if (to == LAST_TYPE) return hs;
2600 if (from == FIRST_TYPE) return ls;
2606 void LCodeGen::DoHasInstanceTypeAndBranch(LHasInstanceTypeAndBranch* instr) {
2607 Register scratch = scratch0();
2608 Register input = ToRegister(instr->value());
2610 if (!instr->hydrogen()->value()->type().IsHeapObject()) {
2611 __ JumpIfSmi(input, instr->FalseLabel(chunk_));
2614 __ CompareObjectType(input, scratch, scratch, TestType(instr->hydrogen()));
2615 EmitBranch(instr, BranchCondition(instr->hydrogen()));
2619 void LCodeGen::DoGetCachedArrayIndex(LGetCachedArrayIndex* instr) {
2620 Register input = ToRegister(instr->value());
2621 Register result = ToRegister(instr->result());
2623 __ AssertString(input);
2625 __ ldr(result, FieldMemOperand(input, String::kHashFieldOffset));
2626 __ IndexFromHash(result, result);
2630 void LCodeGen::DoHasCachedArrayIndexAndBranch(
2631 LHasCachedArrayIndexAndBranch* instr) {
2632 Register input = ToRegister(instr->value());
2633 Register scratch = scratch0();
2636 FieldMemOperand(input, String::kHashFieldOffset));
2637 __ tst(scratch, Operand(String::kContainsCachedArrayIndexMask));
2638 EmitBranch(instr, eq);
2642 // Branches to a label or falls through with the answer in flags. Trashes
2643 // the temp registers, but not the input.
2644 void LCodeGen::EmitClassOfTest(Label* is_true,
2646 Handle<String>class_name,
2650 DCHECK(!input.is(temp));
2651 DCHECK(!input.is(temp2));
2652 DCHECK(!temp.is(temp2));
2654 __ JumpIfSmi(input, is_false);
2656 if (String::Equals(isolate()->factory()->Function_string(), class_name)) {
2657 // Assuming the following assertions, we can use the same compares to test
2658 // for both being a function type and being in the object type range.
2659 STATIC_ASSERT(NUM_OF_CALLABLE_SPEC_OBJECT_TYPES == 2);
2660 STATIC_ASSERT(FIRST_NONCALLABLE_SPEC_OBJECT_TYPE ==
2661 FIRST_SPEC_OBJECT_TYPE + 1);
2662 STATIC_ASSERT(LAST_NONCALLABLE_SPEC_OBJECT_TYPE ==
2663 LAST_SPEC_OBJECT_TYPE - 1);
2664 STATIC_ASSERT(LAST_SPEC_OBJECT_TYPE == LAST_TYPE);
2665 __ CompareObjectType(input, temp, temp2, FIRST_SPEC_OBJECT_TYPE);
2668 __ cmp(temp2, Operand(LAST_SPEC_OBJECT_TYPE));
2671 // Faster code path to avoid two compares: subtract lower bound from the
2672 // actual type and do a signed compare with the width of the type range.
2673 __ ldr(temp, FieldMemOperand(input, HeapObject::kMapOffset));
2674 __ ldrb(temp2, FieldMemOperand(temp, Map::kInstanceTypeOffset));
2675 __ sub(temp2, temp2, Operand(FIRST_NONCALLABLE_SPEC_OBJECT_TYPE));
2676 __ cmp(temp2, Operand(LAST_NONCALLABLE_SPEC_OBJECT_TYPE -
2677 FIRST_NONCALLABLE_SPEC_OBJECT_TYPE));
2681 // Now we are in the FIRST-LAST_NONCALLABLE_SPEC_OBJECT_TYPE range.
2682 // Check if the constructor in the map is a function.
2683 Register instance_type = ip;
2684 __ GetMapConstructor(temp, temp, temp2, instance_type);
2686 // Objects with a non-function constructor have class 'Object'.
2687 __ cmp(instance_type, Operand(JS_FUNCTION_TYPE));
2688 if (class_name->IsOneByteEqualTo(STATIC_CHAR_VECTOR("Object"))) {
2694 // temp now contains the constructor function. Grab the
2695 // instance class name from there.
2696 __ ldr(temp, FieldMemOperand(temp, JSFunction::kSharedFunctionInfoOffset));
2697 __ ldr(temp, FieldMemOperand(temp,
2698 SharedFunctionInfo::kInstanceClassNameOffset));
2699 // The class name we are testing against is internalized since it's a literal.
2700 // The name in the constructor is internalized because of the way the context
2701 // is booted. This routine isn't expected to work for random API-created
2702 // classes and it doesn't have to because you can't access it with natives
2703 // syntax. Since both sides are internalized it is sufficient to use an
2704 // identity comparison.
2705 __ cmp(temp, Operand(class_name));
2706 // End with the answer in flags.
2710 void LCodeGen::DoClassOfTestAndBranch(LClassOfTestAndBranch* instr) {
2711 Register input = ToRegister(instr->value());
2712 Register temp = scratch0();
2713 Register temp2 = ToRegister(instr->temp());
2714 Handle<String> class_name = instr->hydrogen()->class_name();
2716 EmitClassOfTest(instr->TrueLabel(chunk_), instr->FalseLabel(chunk_),
2717 class_name, input, temp, temp2);
2719 EmitBranch(instr, eq);
2723 void LCodeGen::DoCmpMapAndBranch(LCmpMapAndBranch* instr) {
2724 Register reg = ToRegister(instr->value());
2725 Register temp = ToRegister(instr->temp());
2727 __ ldr(temp, FieldMemOperand(reg, HeapObject::kMapOffset));
2728 __ cmp(temp, Operand(instr->map()));
2729 EmitBranch(instr, eq);
2733 void LCodeGen::DoInstanceOf(LInstanceOf* instr) {
2734 DCHECK(ToRegister(instr->context()).is(cp));
2735 DCHECK(ToRegister(instr->left()).is(InstanceOfDescriptor::LeftRegister()));
2736 DCHECK(ToRegister(instr->right()).is(InstanceOfDescriptor::RightRegister()));
2737 DCHECK(ToRegister(instr->result()).is(r0));
2738 InstanceOfStub stub(isolate());
2739 CallCode(stub.GetCode(), RelocInfo::CODE_TARGET, instr);
2743 void LCodeGen::DoHasInPrototypeChainAndBranch(
2744 LHasInPrototypeChainAndBranch* instr) {
2745 Register const object = ToRegister(instr->object());
2746 Register const object_map = scratch0();
2747 Register const object_prototype = object_map;
2748 Register const prototype = ToRegister(instr->prototype());
2750 // The {object} must be a spec object. It's sufficient to know that {object}
2751 // is not a smi, since all other non-spec objects have {null} prototypes and
2752 // will be ruled out below.
2753 if (instr->hydrogen()->ObjectNeedsSmiCheck()) {
2755 EmitFalseBranch(instr, eq);
2758 // Loop through the {object}s prototype chain looking for the {prototype}.
2759 __ ldr(object_map, FieldMemOperand(object, HeapObject::kMapOffset));
2762 __ ldr(object_prototype, FieldMemOperand(object_map, Map::kPrototypeOffset));
2763 __ cmp(object_prototype, prototype);
2764 EmitTrueBranch(instr, eq);
2765 __ CompareRoot(object_prototype, Heap::kNullValueRootIndex);
2766 EmitFalseBranch(instr, eq);
2767 __ ldr(object_map, FieldMemOperand(object_prototype, HeapObject::kMapOffset));
2772 void LCodeGen::DoCmpT(LCmpT* instr) {
2773 DCHECK(ToRegister(instr->context()).is(cp));
2774 Token::Value op = instr->op();
2777 CodeFactory::CompareIC(isolate(), op, instr->strength()).code();
2778 CallCode(ic, RelocInfo::CODE_TARGET, instr);
2779 // This instruction also signals no smi code inlined.
2780 __ cmp(r0, Operand::Zero());
2782 Condition condition = ComputeCompareCondition(op);
2783 __ LoadRoot(ToRegister(instr->result()),
2784 Heap::kTrueValueRootIndex,
2786 __ LoadRoot(ToRegister(instr->result()),
2787 Heap::kFalseValueRootIndex,
2788 NegateCondition(condition));
2792 void LCodeGen::DoReturn(LReturn* instr) {
2793 if (FLAG_trace && info()->IsOptimizing()) {
2794 // Push the return value on the stack as the parameter.
2795 // Runtime::TraceExit returns its parameter in r0. We're leaving the code
2796 // managed by the register allocator and tearing down the frame, it's
2797 // safe to write to the context register.
2799 __ ldr(cp, MemOperand(fp, StandardFrameConstants::kContextOffset));
2800 __ CallRuntime(Runtime::kTraceExit, 1);
2802 if (info()->saves_caller_doubles()) {
2803 RestoreCallerDoubles();
2805 int no_frame_start = -1;
2806 if (NeedsEagerFrame()) {
2807 no_frame_start = masm_->LeaveFrame(StackFrame::JAVA_SCRIPT);
2809 { ConstantPoolUnavailableScope constant_pool_unavailable(masm());
2810 if (instr->has_constant_parameter_count()) {
2811 int parameter_count = ToInteger32(instr->constant_parameter_count());
2812 int32_t sp_delta = (parameter_count + 1) * kPointerSize;
2813 if (sp_delta != 0) {
2814 __ add(sp, sp, Operand(sp_delta));
2817 DCHECK(info()->IsStub()); // Functions would need to drop one more value.
2818 Register reg = ToRegister(instr->parameter_count());
2819 // The argument count parameter is a smi
2821 __ add(sp, sp, Operand(reg, LSL, kPointerSizeLog2));
2826 if (no_frame_start != -1) {
2827 info_->AddNoFrameRange(no_frame_start, masm_->pc_offset());
2834 void LCodeGen::EmitVectorLoadICRegisters(T* instr) {
2835 Register vector_register = ToRegister(instr->temp_vector());
2836 Register slot_register = LoadDescriptor::SlotRegister();
2837 DCHECK(vector_register.is(LoadWithVectorDescriptor::VectorRegister()));
2838 DCHECK(slot_register.is(r0));
2840 AllowDeferredHandleDereference vector_structure_check;
2841 Handle<TypeFeedbackVector> vector = instr->hydrogen()->feedback_vector();
2842 __ Move(vector_register, vector);
2843 // No need to allocate this register.
2844 FeedbackVectorICSlot slot = instr->hydrogen()->slot();
2845 int index = vector->GetIndex(slot);
2846 __ mov(slot_register, Operand(Smi::FromInt(index)));
2851 void LCodeGen::EmitVectorStoreICRegisters(T* instr) {
2852 Register vector_register = ToRegister(instr->temp_vector());
2853 Register slot_register = ToRegister(instr->temp_slot());
2855 AllowDeferredHandleDereference vector_structure_check;
2856 Handle<TypeFeedbackVector> vector = instr->hydrogen()->feedback_vector();
2857 __ Move(vector_register, vector);
2858 FeedbackVectorICSlot slot = instr->hydrogen()->slot();
2859 int index = vector->GetIndex(slot);
2860 __ mov(slot_register, Operand(Smi::FromInt(index)));
2864 void LCodeGen::DoLoadGlobalGeneric(LLoadGlobalGeneric* instr) {
2865 DCHECK(ToRegister(instr->context()).is(cp));
2866 DCHECK(ToRegister(instr->global_object())
2867 .is(LoadDescriptor::ReceiverRegister()));
2868 DCHECK(ToRegister(instr->result()).is(r0));
2870 __ mov(LoadDescriptor::NameRegister(), Operand(instr->name()));
2871 EmitVectorLoadICRegisters<LLoadGlobalGeneric>(instr);
2873 CodeFactory::LoadICInOptimizedCode(isolate(), instr->typeof_mode(),
2874 SLOPPY, PREMONOMORPHIC).code();
2875 CallCode(ic, RelocInfo::CODE_TARGET, instr);
2879 void LCodeGen::DoLoadGlobalViaContext(LLoadGlobalViaContext* instr) {
2880 DCHECK(ToRegister(instr->context()).is(cp));
2881 DCHECK(ToRegister(instr->result()).is(r0));
2883 int const slot = instr->slot_index();
2884 int const depth = instr->depth();
2885 if (depth <= LoadGlobalViaContextStub::kMaximumDepth) {
2886 __ mov(LoadGlobalViaContextDescriptor::SlotRegister(), Operand(slot));
2888 CodeFactory::LoadGlobalViaContext(isolate(), depth).code();
2889 CallCode(stub, RelocInfo::CODE_TARGET, instr);
2891 __ Push(Smi::FromInt(slot));
2892 __ CallRuntime(Runtime::kLoadGlobalViaContext, 1);
2897 void LCodeGen::DoLoadContextSlot(LLoadContextSlot* instr) {
2898 Register context = ToRegister(instr->context());
2899 Register result = ToRegister(instr->result());
2900 __ ldr(result, ContextOperand(context, instr->slot_index()));
2901 if (instr->hydrogen()->RequiresHoleCheck()) {
2902 __ LoadRoot(ip, Heap::kTheHoleValueRootIndex);
2904 if (instr->hydrogen()->DeoptimizesOnHole()) {
2905 DeoptimizeIf(eq, instr, Deoptimizer::kHole);
2907 __ mov(result, Operand(factory()->undefined_value()), LeaveCC, eq);
2913 void LCodeGen::DoStoreContextSlot(LStoreContextSlot* instr) {
2914 Register context = ToRegister(instr->context());
2915 Register value = ToRegister(instr->value());
2916 Register scratch = scratch0();
2917 MemOperand target = ContextOperand(context, instr->slot_index());
2919 Label skip_assignment;
2921 if (instr->hydrogen()->RequiresHoleCheck()) {
2922 __ ldr(scratch, target);
2923 __ LoadRoot(ip, Heap::kTheHoleValueRootIndex);
2924 __ cmp(scratch, ip);
2925 if (instr->hydrogen()->DeoptimizesOnHole()) {
2926 DeoptimizeIf(eq, instr, Deoptimizer::kHole);
2928 __ b(ne, &skip_assignment);
2932 __ str(value, target);
2933 if (instr->hydrogen()->NeedsWriteBarrier()) {
2934 SmiCheck check_needed =
2935 instr->hydrogen()->value()->type().IsHeapObject()
2936 ? OMIT_SMI_CHECK : INLINE_SMI_CHECK;
2937 __ RecordWriteContextSlot(context,
2941 GetLinkRegisterState(),
2943 EMIT_REMEMBERED_SET,
2947 __ bind(&skip_assignment);
2951 void LCodeGen::DoLoadNamedField(LLoadNamedField* instr) {
2952 HObjectAccess access = instr->hydrogen()->access();
2953 int offset = access.offset();
2954 Register object = ToRegister(instr->object());
2956 if (access.IsExternalMemory()) {
2957 Register result = ToRegister(instr->result());
2958 MemOperand operand = MemOperand(object, offset);
2959 __ Load(result, operand, access.representation());
2963 if (instr->hydrogen()->representation().IsDouble()) {
2964 DwVfpRegister result = ToDoubleRegister(instr->result());
2965 __ vldr(result, FieldMemOperand(object, offset));
2969 Register result = ToRegister(instr->result());
2970 if (!access.IsInobject()) {
2971 __ ldr(result, FieldMemOperand(object, JSObject::kPropertiesOffset));
2974 MemOperand operand = FieldMemOperand(object, offset);
2975 __ Load(result, operand, access.representation());
2979 void LCodeGen::DoLoadNamedGeneric(LLoadNamedGeneric* instr) {
2980 DCHECK(ToRegister(instr->context()).is(cp));
2981 DCHECK(ToRegister(instr->object()).is(LoadDescriptor::ReceiverRegister()));
2982 DCHECK(ToRegister(instr->result()).is(r0));
2984 // Name is always in r2.
2985 __ mov(LoadDescriptor::NameRegister(), Operand(instr->name()));
2986 EmitVectorLoadICRegisters<LLoadNamedGeneric>(instr);
2988 CodeFactory::LoadICInOptimizedCode(
2989 isolate(), NOT_INSIDE_TYPEOF, instr->hydrogen()->language_mode(),
2990 instr->hydrogen()->initialization_state()).code();
2991 CallCode(ic, RelocInfo::CODE_TARGET, instr, NEVER_INLINE_TARGET_ADDRESS);
2995 void LCodeGen::DoLoadFunctionPrototype(LLoadFunctionPrototype* instr) {
2996 Register scratch = scratch0();
2997 Register function = ToRegister(instr->function());
2998 Register result = ToRegister(instr->result());
3000 // Get the prototype or initial map from the function.
3002 FieldMemOperand(function, JSFunction::kPrototypeOrInitialMapOffset));
3004 // Check that the function has a prototype or an initial map.
3005 __ LoadRoot(ip, Heap::kTheHoleValueRootIndex);
3007 DeoptimizeIf(eq, instr, Deoptimizer::kHole);
3009 // If the function does not have an initial map, we're done.
3011 __ CompareObjectType(result, scratch, scratch, MAP_TYPE);
3014 // Get the prototype from the initial map.
3015 __ ldr(result, FieldMemOperand(result, Map::kPrototypeOffset));
3022 void LCodeGen::DoLoadRoot(LLoadRoot* instr) {
3023 Register result = ToRegister(instr->result());
3024 __ LoadRoot(result, instr->index());
3028 void LCodeGen::DoAccessArgumentsAt(LAccessArgumentsAt* instr) {
3029 Register arguments = ToRegister(instr->arguments());
3030 Register result = ToRegister(instr->result());
3031 // There are two words between the frame pointer and the last argument.
3032 // Subtracting from length accounts for one of them add one more.
3033 if (instr->length()->IsConstantOperand()) {
3034 int const_length = ToInteger32(LConstantOperand::cast(instr->length()));
3035 if (instr->index()->IsConstantOperand()) {
3036 int const_index = ToInteger32(LConstantOperand::cast(instr->index()));
3037 int index = (const_length - const_index) + 1;
3038 __ ldr(result, MemOperand(arguments, index * kPointerSize));
3040 Register index = ToRegister(instr->index());
3041 __ rsb(result, index, Operand(const_length + 1));
3042 __ ldr(result, MemOperand(arguments, result, LSL, kPointerSizeLog2));
3044 } else if (instr->index()->IsConstantOperand()) {
3045 Register length = ToRegister(instr->length());
3046 int const_index = ToInteger32(LConstantOperand::cast(instr->index()));
3047 int loc = const_index - 1;
3049 __ sub(result, length, Operand(loc));
3050 __ ldr(result, MemOperand(arguments, result, LSL, kPointerSizeLog2));
3052 __ ldr(result, MemOperand(arguments, length, LSL, kPointerSizeLog2));
3055 Register length = ToRegister(instr->length());
3056 Register index = ToRegister(instr->index());
3057 __ sub(result, length, index);
3058 __ add(result, result, Operand(1));
3059 __ ldr(result, MemOperand(arguments, result, LSL, kPointerSizeLog2));
3064 void LCodeGen::DoLoadKeyedExternalArray(LLoadKeyed* instr) {
3065 Register external_pointer = ToRegister(instr->elements());
3066 Register key = no_reg;
3067 ElementsKind elements_kind = instr->elements_kind();
3068 bool key_is_constant = instr->key()->IsConstantOperand();
3069 int constant_key = 0;
3070 if (key_is_constant) {
3071 constant_key = ToInteger32(LConstantOperand::cast(instr->key()));
3072 if (constant_key & 0xF0000000) {
3073 Abort(kArrayIndexConstantValueTooBig);
3076 key = ToRegister(instr->key());
3078 int element_size_shift = ElementsKindToShiftSize(elements_kind);
3079 int shift_size = (instr->hydrogen()->key()->representation().IsSmi())
3080 ? (element_size_shift - kSmiTagSize) : element_size_shift;
3081 int base_offset = instr->base_offset();
3083 if (elements_kind == FLOAT32_ELEMENTS || elements_kind == FLOAT64_ELEMENTS) {
3084 DwVfpRegister result = ToDoubleRegister(instr->result());
3085 Operand operand = key_is_constant
3086 ? Operand(constant_key << element_size_shift)
3087 : Operand(key, LSL, shift_size);
3088 __ add(scratch0(), external_pointer, operand);
3089 if (elements_kind == FLOAT32_ELEMENTS) {
3090 __ vldr(double_scratch0().low(), scratch0(), base_offset);
3091 __ vcvt_f64_f32(result, double_scratch0().low());
3092 } else { // i.e. elements_kind == EXTERNAL_DOUBLE_ELEMENTS
3093 __ vldr(result, scratch0(), base_offset);
3096 Register result = ToRegister(instr->result());
3097 MemOperand mem_operand = PrepareKeyedOperand(
3098 key, external_pointer, key_is_constant, constant_key,
3099 element_size_shift, shift_size, base_offset);
3100 switch (elements_kind) {
3102 __ ldrsb(result, mem_operand);
3104 case UINT8_ELEMENTS:
3105 case UINT8_CLAMPED_ELEMENTS:
3106 __ ldrb(result, mem_operand);
3108 case INT16_ELEMENTS:
3109 __ ldrsh(result, mem_operand);
3111 case UINT16_ELEMENTS:
3112 __ ldrh(result, mem_operand);
3114 case INT32_ELEMENTS:
3115 __ ldr(result, mem_operand);
3117 case UINT32_ELEMENTS:
3118 __ ldr(result, mem_operand);
3119 if (!instr->hydrogen()->CheckFlag(HInstruction::kUint32)) {
3120 __ cmp(result, Operand(0x80000000));
3121 DeoptimizeIf(cs, instr, Deoptimizer::kNegativeValue);
3124 case FLOAT32_ELEMENTS:
3125 case FLOAT64_ELEMENTS:
3126 case FAST_HOLEY_DOUBLE_ELEMENTS:
3127 case FAST_HOLEY_ELEMENTS:
3128 case FAST_HOLEY_SMI_ELEMENTS:
3129 case FAST_DOUBLE_ELEMENTS:
3131 case FAST_SMI_ELEMENTS:
3132 case DICTIONARY_ELEMENTS:
3133 case FAST_SLOPPY_ARGUMENTS_ELEMENTS:
3134 case SLOW_SLOPPY_ARGUMENTS_ELEMENTS:
3142 void LCodeGen::DoLoadKeyedFixedDoubleArray(LLoadKeyed* instr) {
3143 Register elements = ToRegister(instr->elements());
3144 bool key_is_constant = instr->key()->IsConstantOperand();
3145 Register key = no_reg;
3146 DwVfpRegister result = ToDoubleRegister(instr->result());
3147 Register scratch = scratch0();
3149 int element_size_shift = ElementsKindToShiftSize(FAST_DOUBLE_ELEMENTS);
3151 int base_offset = instr->base_offset();
3152 if (key_is_constant) {
3153 int constant_key = ToInteger32(LConstantOperand::cast(instr->key()));
3154 if (constant_key & 0xF0000000) {
3155 Abort(kArrayIndexConstantValueTooBig);
3157 base_offset += constant_key * kDoubleSize;
3159 __ add(scratch, elements, Operand(base_offset));
3161 if (!key_is_constant) {
3162 key = ToRegister(instr->key());
3163 int shift_size = (instr->hydrogen()->key()->representation().IsSmi())
3164 ? (element_size_shift - kSmiTagSize) : element_size_shift;
3165 __ add(scratch, scratch, Operand(key, LSL, shift_size));
3168 __ vldr(result, scratch, 0);
3170 if (instr->hydrogen()->RequiresHoleCheck()) {
3171 __ ldr(scratch, MemOperand(scratch, sizeof(kHoleNanLower32)));
3172 __ cmp(scratch, Operand(kHoleNanUpper32));
3173 DeoptimizeIf(eq, instr, Deoptimizer::kHole);
3178 void LCodeGen::DoLoadKeyedFixedArray(LLoadKeyed* instr) {
3179 Register elements = ToRegister(instr->elements());
3180 Register result = ToRegister(instr->result());
3181 Register scratch = scratch0();
3182 Register store_base = scratch;
3183 int offset = instr->base_offset();
3185 if (instr->key()->IsConstantOperand()) {
3186 LConstantOperand* const_operand = LConstantOperand::cast(instr->key());
3187 offset += ToInteger32(const_operand) * kPointerSize;
3188 store_base = elements;
3190 Register key = ToRegister(instr->key());
3191 // Even though the HLoadKeyed instruction forces the input
3192 // representation for the key to be an integer, the input gets replaced
3193 // during bound check elimination with the index argument to the bounds
3194 // check, which can be tagged, so that case must be handled here, too.
3195 if (instr->hydrogen()->key()->representation().IsSmi()) {
3196 __ add(scratch, elements, Operand::PointerOffsetFromSmiKey(key));
3198 __ add(scratch, elements, Operand(key, LSL, kPointerSizeLog2));
3201 __ ldr(result, MemOperand(store_base, offset));
3203 // Check for the hole value.
3204 if (instr->hydrogen()->RequiresHoleCheck()) {
3205 if (IsFastSmiElementsKind(instr->hydrogen()->elements_kind())) {
3207 DeoptimizeIf(ne, instr, Deoptimizer::kNotASmi);
3209 __ LoadRoot(scratch, Heap::kTheHoleValueRootIndex);
3210 __ cmp(result, scratch);
3211 DeoptimizeIf(eq, instr, Deoptimizer::kHole);
3213 } else if (instr->hydrogen()->hole_mode() == CONVERT_HOLE_TO_UNDEFINED) {
3214 DCHECK(instr->hydrogen()->elements_kind() == FAST_HOLEY_ELEMENTS);
3216 __ LoadRoot(scratch, Heap::kTheHoleValueRootIndex);
3217 __ cmp(result, scratch);
3219 if (info()->IsStub()) {
3220 // A stub can safely convert the hole to undefined only if the array
3221 // protector cell contains (Smi) Isolate::kArrayProtectorValid. Otherwise
3222 // it needs to bail out.
3223 __ LoadRoot(result, Heap::kArrayProtectorRootIndex);
3224 __ ldr(result, FieldMemOperand(result, Cell::kValueOffset));
3225 __ cmp(result, Operand(Smi::FromInt(Isolate::kArrayProtectorValid)));
3226 DeoptimizeIf(ne, instr, Deoptimizer::kHole);
3228 __ LoadRoot(result, Heap::kUndefinedValueRootIndex);
3234 void LCodeGen::DoLoadKeyed(LLoadKeyed* instr) {
3235 if (instr->is_fixed_typed_array()) {
3236 DoLoadKeyedExternalArray(instr);
3237 } else if (instr->hydrogen()->representation().IsDouble()) {
3238 DoLoadKeyedFixedDoubleArray(instr);
3240 DoLoadKeyedFixedArray(instr);
3245 MemOperand LCodeGen::PrepareKeyedOperand(Register key,
3247 bool key_is_constant,
3252 if (key_is_constant) {
3253 return MemOperand(base, (constant_key << element_size) + base_offset);
3256 if (base_offset == 0) {
3257 if (shift_size >= 0) {
3258 return MemOperand(base, key, LSL, shift_size);
3260 DCHECK_EQ(-1, shift_size);
3261 return MemOperand(base, key, LSR, 1);
3265 if (shift_size >= 0) {
3266 __ add(scratch0(), base, Operand(key, LSL, shift_size));
3267 return MemOperand(scratch0(), base_offset);
3269 DCHECK_EQ(-1, shift_size);
3270 __ add(scratch0(), base, Operand(key, ASR, 1));
3271 return MemOperand(scratch0(), base_offset);
3276 void LCodeGen::DoLoadKeyedGeneric(LLoadKeyedGeneric* instr) {
3277 DCHECK(ToRegister(instr->context()).is(cp));
3278 DCHECK(ToRegister(instr->object()).is(LoadDescriptor::ReceiverRegister()));
3279 DCHECK(ToRegister(instr->key()).is(LoadDescriptor::NameRegister()));
3281 if (instr->hydrogen()->HasVectorAndSlot()) {
3282 EmitVectorLoadICRegisters<LLoadKeyedGeneric>(instr);
3285 Handle<Code> ic = CodeFactory::KeyedLoadICInOptimizedCode(
3286 isolate(), instr->hydrogen()->language_mode(),
3287 instr->hydrogen()->initialization_state()).code();
3288 CallCode(ic, RelocInfo::CODE_TARGET, instr, NEVER_INLINE_TARGET_ADDRESS);
3292 void LCodeGen::DoArgumentsElements(LArgumentsElements* instr) {
3293 Register scratch = scratch0();
3294 Register result = ToRegister(instr->result());
3296 if (instr->hydrogen()->from_inlined()) {
3297 __ sub(result, sp, Operand(2 * kPointerSize));
3299 // Check if the calling frame is an arguments adaptor frame.
3300 Label done, adapted;
3301 __ ldr(scratch, MemOperand(fp, StandardFrameConstants::kCallerFPOffset));
3302 __ ldr(result, MemOperand(scratch, StandardFrameConstants::kContextOffset));
3303 __ cmp(result, Operand(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR)));
3305 // Result is the frame pointer for the frame if not adapted and for the real
3306 // frame below the adaptor frame if adapted.
3307 __ mov(result, fp, LeaveCC, ne);
3308 __ mov(result, scratch, LeaveCC, eq);
3313 void LCodeGen::DoArgumentsLength(LArgumentsLength* instr) {
3314 Register elem = ToRegister(instr->elements());
3315 Register result = ToRegister(instr->result());
3319 // If no arguments adaptor frame the number of arguments is fixed.
3321 __ mov(result, Operand(scope()->num_parameters()));
3324 // Arguments adaptor frame present. Get argument length from there.
3325 __ ldr(result, MemOperand(fp, StandardFrameConstants::kCallerFPOffset));
3327 MemOperand(result, ArgumentsAdaptorFrameConstants::kLengthOffset));
3328 __ SmiUntag(result);
3330 // Argument length is in result register.
3335 void LCodeGen::DoWrapReceiver(LWrapReceiver* instr) {
3336 Register receiver = ToRegister(instr->receiver());
3337 Register function = ToRegister(instr->function());
3338 Register result = ToRegister(instr->result());
3339 Register scratch = scratch0();
3341 // If the receiver is null or undefined, we have to pass the global
3342 // object as a receiver to normal functions. Values have to be
3343 // passed unchanged to builtins and strict-mode functions.
3344 Label global_object, result_in_receiver;
3346 if (!instr->hydrogen()->known_function()) {
3347 // Do not transform the receiver to object for strict mode
3350 FieldMemOperand(function, JSFunction::kSharedFunctionInfoOffset));
3352 FieldMemOperand(scratch, SharedFunctionInfo::kCompilerHintsOffset));
3353 int mask = 1 << (SharedFunctionInfo::kStrictModeFunction + kSmiTagSize);
3354 __ tst(scratch, Operand(mask));
3355 __ b(ne, &result_in_receiver);
3357 // Do not transform the receiver to object for builtins.
3358 __ tst(scratch, Operand(1 << (SharedFunctionInfo::kNative + kSmiTagSize)));
3359 __ b(ne, &result_in_receiver);
3362 // Normal function. Replace undefined or null with global receiver.
3363 __ LoadRoot(scratch, Heap::kNullValueRootIndex);
3364 __ cmp(receiver, scratch);
3365 __ b(eq, &global_object);
3366 __ LoadRoot(scratch, Heap::kUndefinedValueRootIndex);
3367 __ cmp(receiver, scratch);
3368 __ b(eq, &global_object);
3370 // Deoptimize if the receiver is not a JS object.
3371 __ SmiTst(receiver);
3372 DeoptimizeIf(eq, instr, Deoptimizer::kSmi);
3373 __ CompareObjectType(receiver, scratch, scratch, FIRST_SPEC_OBJECT_TYPE);
3374 DeoptimizeIf(lt, instr, Deoptimizer::kNotAJavaScriptObject);
3376 __ b(&result_in_receiver);
3377 __ bind(&global_object);
3378 __ ldr(result, FieldMemOperand(function, JSFunction::kContextOffset));
3380 ContextOperand(result, Context::GLOBAL_OBJECT_INDEX));
3381 __ ldr(result, FieldMemOperand(result, GlobalObject::kGlobalProxyOffset));
3383 if (result.is(receiver)) {
3384 __ bind(&result_in_receiver);
3388 __ bind(&result_in_receiver);
3389 __ mov(result, receiver);
3390 __ bind(&result_ok);
3395 void LCodeGen::DoApplyArguments(LApplyArguments* instr) {
3396 Register receiver = ToRegister(instr->receiver());
3397 Register function = ToRegister(instr->function());
3398 Register length = ToRegister(instr->length());
3399 Register elements = ToRegister(instr->elements());
3400 Register scratch = scratch0();
3401 DCHECK(receiver.is(r0)); // Used for parameter count.
3402 DCHECK(function.is(r1)); // Required by InvokeFunction.
3403 DCHECK(ToRegister(instr->result()).is(r0));
3405 // Copy the arguments to this function possibly from the
3406 // adaptor frame below it.
3407 const uint32_t kArgumentsLimit = 1 * KB;
3408 __ cmp(length, Operand(kArgumentsLimit));
3409 DeoptimizeIf(hi, instr, Deoptimizer::kTooManyArguments);
3411 // Push the receiver and use the register to keep the original
3412 // number of arguments.
3414 __ mov(receiver, length);
3415 // The arguments are at a one pointer size offset from elements.
3416 __ add(elements, elements, Operand(1 * kPointerSize));
3418 // Loop through the arguments pushing them onto the execution
3421 // length is a small non-negative integer, due to the test above.
3422 __ cmp(length, Operand::Zero());
3425 __ ldr(scratch, MemOperand(elements, length, LSL, 2));
3427 __ sub(length, length, Operand(1), SetCC);
3431 DCHECK(instr->HasPointerMap());
3432 LPointerMap* pointers = instr->pointer_map();
3433 SafepointGenerator safepoint_generator(
3434 this, pointers, Safepoint::kLazyDeopt);
3435 // The number of arguments is stored in receiver which is r0, as expected
3436 // by InvokeFunction.
3437 ParameterCount actual(receiver);
3438 __ InvokeFunction(function, actual, CALL_FUNCTION, safepoint_generator);
3442 void LCodeGen::DoPushArgument(LPushArgument* instr) {
3443 LOperand* argument = instr->value();
3444 if (argument->IsDoubleRegister() || argument->IsDoubleStackSlot()) {
3445 Abort(kDoPushArgumentNotImplementedForDoubleType);
3447 Register argument_reg = EmitLoadRegister(argument, ip);
3448 __ push(argument_reg);
3453 void LCodeGen::DoDrop(LDrop* instr) {
3454 __ Drop(instr->count());
3458 void LCodeGen::DoThisFunction(LThisFunction* instr) {
3459 Register result = ToRegister(instr->result());
3460 __ ldr(result, MemOperand(fp, JavaScriptFrameConstants::kFunctionOffset));
3464 void LCodeGen::DoContext(LContext* instr) {
3465 // If there is a non-return use, the context must be moved to a register.
3466 Register result = ToRegister(instr->result());
3467 if (info()->IsOptimizing()) {
3468 __ ldr(result, MemOperand(fp, StandardFrameConstants::kContextOffset));
3470 // If there is no frame, the context must be in cp.
3471 DCHECK(result.is(cp));
3476 void LCodeGen::DoDeclareGlobals(LDeclareGlobals* instr) {
3477 DCHECK(ToRegister(instr->context()).is(cp));
3478 __ Move(scratch0(), instr->hydrogen()->pairs());
3479 __ push(scratch0());
3480 __ mov(scratch0(), Operand(Smi::FromInt(instr->hydrogen()->flags())));
3481 __ push(scratch0());
3482 CallRuntime(Runtime::kDeclareGlobals, 2, instr);
3486 void LCodeGen::CallKnownFunction(Handle<JSFunction> function,
3487 int formal_parameter_count, int arity,
3488 LInstruction* instr) {
3489 bool dont_adapt_arguments =
3490 formal_parameter_count == SharedFunctionInfo::kDontAdaptArgumentsSentinel;
3491 bool can_invoke_directly =
3492 dont_adapt_arguments || formal_parameter_count == arity;
3494 Register function_reg = r1;
3496 LPointerMap* pointers = instr->pointer_map();
3498 if (can_invoke_directly) {
3500 __ ldr(cp, FieldMemOperand(function_reg, JSFunction::kContextOffset));
3502 // Set r0 to arguments count if adaption is not needed. Assumes that r0
3503 // is available to write to at this point.
3504 if (dont_adapt_arguments) {
3505 __ mov(r0, Operand(arity));
3509 __ ldr(ip, FieldMemOperand(function_reg, JSFunction::kCodeEntryOffset));
3512 // Set up deoptimization.
3513 RecordSafepointWithLazyDeopt(instr, RECORD_SIMPLE_SAFEPOINT);
3515 SafepointGenerator generator(this, pointers, Safepoint::kLazyDeopt);
3516 ParameterCount count(arity);
3517 ParameterCount expected(formal_parameter_count);
3518 __ InvokeFunction(function_reg, expected, count, CALL_FUNCTION, generator);
3523 void LCodeGen::DoDeferredMathAbsTaggedHeapNumber(LMathAbs* instr) {
3524 DCHECK(instr->context() != NULL);
3525 DCHECK(ToRegister(instr->context()).is(cp));
3526 Register input = ToRegister(instr->value());
3527 Register result = ToRegister(instr->result());
3528 Register scratch = scratch0();
3530 // Deoptimize if not a heap number.
3531 __ ldr(scratch, FieldMemOperand(input, HeapObject::kMapOffset));
3532 __ LoadRoot(ip, Heap::kHeapNumberMapRootIndex);
3533 __ cmp(scratch, Operand(ip));
3534 DeoptimizeIf(ne, instr, Deoptimizer::kNotAHeapNumber);
3537 Register exponent = scratch0();
3539 __ ldr(exponent, FieldMemOperand(input, HeapNumber::kExponentOffset));
3540 // Check the sign of the argument. If the argument is positive, just
3542 __ tst(exponent, Operand(HeapNumber::kSignMask));
3543 // Move the input to the result if necessary.
3544 __ Move(result, input);
3547 // Input is negative. Reverse its sign.
3548 // Preserve the value of all registers.
3550 PushSafepointRegistersScope scope(this);
3552 // Registers were saved at the safepoint, so we can use
3553 // many scratch registers.
3554 Register tmp1 = input.is(r1) ? r0 : r1;
3555 Register tmp2 = input.is(r2) ? r0 : r2;
3556 Register tmp3 = input.is(r3) ? r0 : r3;
3557 Register tmp4 = input.is(r4) ? r0 : r4;
3559 // exponent: floating point exponent value.
3561 Label allocated, slow;
3562 __ LoadRoot(tmp4, Heap::kHeapNumberMapRootIndex);
3563 __ AllocateHeapNumber(tmp1, tmp2, tmp3, tmp4, &slow);
3566 // Slow case: Call the runtime system to do the number allocation.
3569 CallRuntimeFromDeferred(Runtime::kAllocateHeapNumber, 0, instr,
3571 // Set the pointer to the new heap number in tmp.
3572 if (!tmp1.is(r0)) __ mov(tmp1, Operand(r0));
3573 // Restore input_reg after call to runtime.
3574 __ LoadFromSafepointRegisterSlot(input, input);
3575 __ ldr(exponent, FieldMemOperand(input, HeapNumber::kExponentOffset));
3577 __ bind(&allocated);
3578 // exponent: floating point exponent value.
3579 // tmp1: allocated heap number.
3580 __ bic(exponent, exponent, Operand(HeapNumber::kSignMask));
3581 __ str(exponent, FieldMemOperand(tmp1, HeapNumber::kExponentOffset));
3582 __ ldr(tmp2, FieldMemOperand(input, HeapNumber::kMantissaOffset));
3583 __ str(tmp2, FieldMemOperand(tmp1, HeapNumber::kMantissaOffset));
3585 __ StoreToSafepointRegisterSlot(tmp1, result);
3592 void LCodeGen::EmitIntegerMathAbs(LMathAbs* instr) {
3593 Register input = ToRegister(instr->value());
3594 Register result = ToRegister(instr->result());
3595 __ cmp(input, Operand::Zero());
3596 __ Move(result, input, pl);
3597 // We can make rsb conditional because the previous cmp instruction
3598 // will clear the V (overflow) flag and rsb won't set this flag
3599 // if input is positive.
3600 __ rsb(result, input, Operand::Zero(), SetCC, mi);
3601 // Deoptimize on overflow.
3602 DeoptimizeIf(vs, instr, Deoptimizer::kOverflow);
3606 void LCodeGen::DoMathAbs(LMathAbs* instr) {
3607 // Class for deferred case.
3608 class DeferredMathAbsTaggedHeapNumber final : public LDeferredCode {
3610 DeferredMathAbsTaggedHeapNumber(LCodeGen* codegen, LMathAbs* instr)
3611 : LDeferredCode(codegen), instr_(instr) { }
3612 void Generate() override {
3613 codegen()->DoDeferredMathAbsTaggedHeapNumber(instr_);
3615 LInstruction* instr() override { return instr_; }
3621 Representation r = instr->hydrogen()->value()->representation();
3623 DwVfpRegister input = ToDoubleRegister(instr->value());
3624 DwVfpRegister result = ToDoubleRegister(instr->result());
3625 __ vabs(result, input);
3626 } else if (r.IsSmiOrInteger32()) {
3627 EmitIntegerMathAbs(instr);
3629 // Representation is tagged.
3630 DeferredMathAbsTaggedHeapNumber* deferred =
3631 new(zone()) DeferredMathAbsTaggedHeapNumber(this, instr);
3632 Register input = ToRegister(instr->value());
3634 __ JumpIfNotSmi(input, deferred->entry());
3635 // If smi, handle it directly.
3636 EmitIntegerMathAbs(instr);
3637 __ bind(deferred->exit());
3642 void LCodeGen::DoMathFloor(LMathFloor* instr) {
3643 DwVfpRegister input = ToDoubleRegister(instr->value());
3644 Register result = ToRegister(instr->result());
3645 Register input_high = scratch0();
3648 __ TryInt32Floor(result, input, input_high, double_scratch0(), &done, &exact);
3649 DeoptimizeIf(al, instr, Deoptimizer::kLostPrecisionOrNaN);
3652 if (instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero)) {
3654 __ cmp(result, Operand::Zero());
3656 __ cmp(input_high, Operand::Zero());
3657 DeoptimizeIf(mi, instr, Deoptimizer::kMinusZero);
3663 void LCodeGen::DoMathRound(LMathRound* instr) {
3664 DwVfpRegister input = ToDoubleRegister(instr->value());
3665 Register result = ToRegister(instr->result());
3666 DwVfpRegister double_scratch1 = ToDoubleRegister(instr->temp());
3667 DwVfpRegister input_plus_dot_five = double_scratch1;
3668 Register input_high = scratch0();
3669 DwVfpRegister dot_five = double_scratch0();
3670 Label convert, done;
3672 __ Vmov(dot_five, 0.5, scratch0());
3673 __ vabs(double_scratch1, input);
3674 __ VFPCompareAndSetFlags(double_scratch1, dot_five);
3675 // If input is in [-0.5, -0], the result is -0.
3676 // If input is in [+0, +0.5[, the result is +0.
3677 // If the input is +0.5, the result is 1.
3678 __ b(hi, &convert); // Out of [-0.5, +0.5].
3679 if (instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero)) {
3680 __ VmovHigh(input_high, input);
3681 __ cmp(input_high, Operand::Zero());
3683 DeoptimizeIf(mi, instr, Deoptimizer::kMinusZero);
3685 __ VFPCompareAndSetFlags(input, dot_five);
3686 __ mov(result, Operand(1), LeaveCC, eq); // +0.5.
3687 // Remaining cases: [+0, +0.5[ or [-0.5, +0.5[, depending on
3688 // flag kBailoutOnMinusZero.
3689 __ mov(result, Operand::Zero(), LeaveCC, ne);
3693 __ vadd(input_plus_dot_five, input, dot_five);
3694 // Reuse dot_five (double_scratch0) as we no longer need this value.
3695 __ TryInt32Floor(result, input_plus_dot_five, input_high, double_scratch0(),
3697 DeoptimizeIf(al, instr, Deoptimizer::kLostPrecisionOrNaN);
3702 void LCodeGen::DoMathFround(LMathFround* instr) {
3703 DwVfpRegister input_reg = ToDoubleRegister(instr->value());
3704 DwVfpRegister output_reg = ToDoubleRegister(instr->result());
3705 LowDwVfpRegister scratch = double_scratch0();
3706 __ vcvt_f32_f64(scratch.low(), input_reg);
3707 __ vcvt_f64_f32(output_reg, scratch.low());
3711 void LCodeGen::DoMathSqrt(LMathSqrt* instr) {
3712 DwVfpRegister input = ToDoubleRegister(instr->value());
3713 DwVfpRegister result = ToDoubleRegister(instr->result());
3714 __ vsqrt(result, input);
3718 void LCodeGen::DoMathPowHalf(LMathPowHalf* instr) {
3719 DwVfpRegister input = ToDoubleRegister(instr->value());
3720 DwVfpRegister result = ToDoubleRegister(instr->result());
3721 DwVfpRegister temp = double_scratch0();
3723 // Note that according to ECMA-262 15.8.2.13:
3724 // Math.pow(-Infinity, 0.5) == Infinity
3725 // Math.sqrt(-Infinity) == NaN
3727 __ vmov(temp, -V8_INFINITY, scratch0());
3728 __ VFPCompareAndSetFlags(input, temp);
3729 __ vneg(result, temp, eq);
3732 // Add +0 to convert -0 to +0.
3733 __ vadd(result, input, kDoubleRegZero);
3734 __ vsqrt(result, result);
3739 void LCodeGen::DoPower(LPower* instr) {
3740 Representation exponent_type = instr->hydrogen()->right()->representation();
3741 // Having marked this as a call, we can use any registers.
3742 // Just make sure that the input/output registers are the expected ones.
3743 Register tagged_exponent = MathPowTaggedDescriptor::exponent();
3744 DCHECK(!instr->right()->IsDoubleRegister() ||
3745 ToDoubleRegister(instr->right()).is(d1));
3746 DCHECK(!instr->right()->IsRegister() ||
3747 ToRegister(instr->right()).is(tagged_exponent));
3748 DCHECK(ToDoubleRegister(instr->left()).is(d0));
3749 DCHECK(ToDoubleRegister(instr->result()).is(d2));
3751 if (exponent_type.IsSmi()) {
3752 MathPowStub stub(isolate(), MathPowStub::TAGGED);
3754 } else if (exponent_type.IsTagged()) {
3756 __ JumpIfSmi(tagged_exponent, &no_deopt);
3757 DCHECK(!r6.is(tagged_exponent));
3758 __ ldr(r6, FieldMemOperand(tagged_exponent, HeapObject::kMapOffset));
3759 __ LoadRoot(ip, Heap::kHeapNumberMapRootIndex);
3760 __ cmp(r6, Operand(ip));
3761 DeoptimizeIf(ne, instr, Deoptimizer::kNotAHeapNumber);
3763 MathPowStub stub(isolate(), MathPowStub::TAGGED);
3765 } else if (exponent_type.IsInteger32()) {
3766 MathPowStub stub(isolate(), MathPowStub::INTEGER);
3769 DCHECK(exponent_type.IsDouble());
3770 MathPowStub stub(isolate(), MathPowStub::DOUBLE);
3776 void LCodeGen::DoMathExp(LMathExp* instr) {
3777 DwVfpRegister input = ToDoubleRegister(instr->value());
3778 DwVfpRegister result = ToDoubleRegister(instr->result());
3779 DwVfpRegister double_scratch1 = ToDoubleRegister(instr->double_temp());
3780 DwVfpRegister double_scratch2 = double_scratch0();
3781 Register temp1 = ToRegister(instr->temp1());
3782 Register temp2 = ToRegister(instr->temp2());
3784 MathExpGenerator::EmitMathExp(
3785 masm(), input, result, double_scratch1, double_scratch2,
3786 temp1, temp2, scratch0());
3790 void LCodeGen::DoMathLog(LMathLog* instr) {
3791 __ PrepareCallCFunction(0, 1, scratch0());
3792 __ MovToFloatParameter(ToDoubleRegister(instr->value()));
3793 __ CallCFunction(ExternalReference::math_log_double_function(isolate()),
3795 __ MovFromFloatResult(ToDoubleRegister(instr->result()));
3799 void LCodeGen::DoMathClz32(LMathClz32* instr) {
3800 Register input = ToRegister(instr->value());
3801 Register result = ToRegister(instr->result());
3802 __ clz(result, input);
3806 void LCodeGen::DoInvokeFunction(LInvokeFunction* instr) {
3807 DCHECK(ToRegister(instr->context()).is(cp));
3808 DCHECK(ToRegister(instr->function()).is(r1));
3809 DCHECK(instr->HasPointerMap());
3811 Handle<JSFunction> known_function = instr->hydrogen()->known_function();
3812 if (known_function.is_null()) {
3813 LPointerMap* pointers = instr->pointer_map();
3814 SafepointGenerator generator(this, pointers, Safepoint::kLazyDeopt);
3815 ParameterCount count(instr->arity());
3816 __ InvokeFunction(r1, count, CALL_FUNCTION, generator);
3818 CallKnownFunction(known_function,
3819 instr->hydrogen()->formal_parameter_count(),
3820 instr->arity(), instr);
3825 void LCodeGen::DoCallWithDescriptor(LCallWithDescriptor* instr) {
3826 DCHECK(ToRegister(instr->result()).is(r0));
3828 if (instr->hydrogen()->IsTailCall()) {
3829 if (NeedsEagerFrame()) __ LeaveFrame(StackFrame::INTERNAL);
3831 if (instr->target()->IsConstantOperand()) {
3832 LConstantOperand* target = LConstantOperand::cast(instr->target());
3833 Handle<Code> code = Handle<Code>::cast(ToHandle(target));
3834 __ Jump(code, RelocInfo::CODE_TARGET);
3836 DCHECK(instr->target()->IsRegister());
3837 Register target = ToRegister(instr->target());
3838 // Make sure we don't emit any additional entries in the constant pool
3839 // before the call to ensure that the CallCodeSize() calculated the
3841 // number of instructions for the constant pool load.
3843 ConstantPoolUnavailableScope constant_pool_unavailable(masm_);
3844 __ add(target, target, Operand(Code::kHeaderSize - kHeapObjectTag));
3849 LPointerMap* pointers = instr->pointer_map();
3850 SafepointGenerator generator(this, pointers, Safepoint::kLazyDeopt);
3852 if (instr->target()->IsConstantOperand()) {
3853 LConstantOperand* target = LConstantOperand::cast(instr->target());
3854 Handle<Code> code = Handle<Code>::cast(ToHandle(target));
3855 generator.BeforeCall(__ CallSize(code, RelocInfo::CODE_TARGET));
3856 PlatformInterfaceDescriptor* call_descriptor =
3857 instr->descriptor().platform_specific_descriptor();
3858 if (call_descriptor != NULL) {
3859 __ Call(code, RelocInfo::CODE_TARGET, TypeFeedbackId::None(), al,
3860 call_descriptor->storage_mode());
3862 __ Call(code, RelocInfo::CODE_TARGET, TypeFeedbackId::None(), al);
3865 DCHECK(instr->target()->IsRegister());
3866 Register target = ToRegister(instr->target());
3867 generator.BeforeCall(__ CallSize(target));
3868 // Make sure we don't emit any additional entries in the constant pool
3869 // before the call to ensure that the CallCodeSize() calculated the
3871 // number of instructions for the constant pool load.
3873 ConstantPoolUnavailableScope constant_pool_unavailable(masm_);
3874 __ add(target, target, Operand(Code::kHeaderSize - kHeapObjectTag));
3878 generator.AfterCall();
3883 void LCodeGen::DoCallJSFunction(LCallJSFunction* instr) {
3884 DCHECK(ToRegister(instr->function()).is(r1));
3885 DCHECK(ToRegister(instr->result()).is(r0));
3887 if (instr->hydrogen()->pass_argument_count()) {
3888 __ mov(r0, Operand(instr->arity()));
3892 __ ldr(cp, FieldMemOperand(r1, JSFunction::kContextOffset));
3894 // Load the code entry address
3895 __ ldr(ip, FieldMemOperand(r1, JSFunction::kCodeEntryOffset));
3898 RecordSafepointWithLazyDeopt(instr, RECORD_SIMPLE_SAFEPOINT);
3902 void LCodeGen::DoCallFunction(LCallFunction* instr) {
3903 DCHECK(ToRegister(instr->context()).is(cp));
3904 DCHECK(ToRegister(instr->function()).is(r1));
3905 DCHECK(ToRegister(instr->result()).is(r0));
3907 int arity = instr->arity();
3908 CallFunctionFlags flags = instr->hydrogen()->function_flags();
3909 if (instr->hydrogen()->HasVectorAndSlot()) {
3910 Register slot_register = ToRegister(instr->temp_slot());
3911 Register vector_register = ToRegister(instr->temp_vector());
3912 DCHECK(slot_register.is(r3));
3913 DCHECK(vector_register.is(r2));
3915 AllowDeferredHandleDereference vector_structure_check;
3916 Handle<TypeFeedbackVector> vector = instr->hydrogen()->feedback_vector();
3917 int index = vector->GetIndex(instr->hydrogen()->slot());
3919 __ Move(vector_register, vector);
3920 __ mov(slot_register, Operand(Smi::FromInt(index)));
3922 CallICState::CallType call_type =
3923 (flags & CALL_AS_METHOD) ? CallICState::METHOD : CallICState::FUNCTION;
3926 CodeFactory::CallICInOptimizedCode(isolate(), arity, call_type).code();
3927 CallCode(ic, RelocInfo::CODE_TARGET, instr);
3929 CallFunctionStub stub(isolate(), arity, flags);
3930 CallCode(stub.GetCode(), RelocInfo::CODE_TARGET, instr);
3935 void LCodeGen::DoCallNew(LCallNew* instr) {
3936 DCHECK(ToRegister(instr->context()).is(cp));
3937 DCHECK(ToRegister(instr->constructor()).is(r1));
3938 DCHECK(ToRegister(instr->result()).is(r0));
3940 __ mov(r0, Operand(instr->arity()));
3941 // No cell in r2 for construct type feedback in optimized code
3942 __ LoadRoot(r2, Heap::kUndefinedValueRootIndex);
3943 CallConstructStub stub(isolate(), NO_CALL_CONSTRUCTOR_FLAGS);
3944 CallCode(stub.GetCode(), RelocInfo::CONSTRUCT_CALL, instr);
3948 void LCodeGen::DoCallNewArray(LCallNewArray* instr) {
3949 DCHECK(ToRegister(instr->context()).is(cp));
3950 DCHECK(ToRegister(instr->constructor()).is(r1));
3951 DCHECK(ToRegister(instr->result()).is(r0));
3953 __ mov(r0, Operand(instr->arity()));
3954 if (instr->arity() == 1) {
3955 // We only need the allocation site for the case we have a length argument.
3956 // The case may bail out to the runtime, which will determine the correct
3957 // elements kind with the site.
3958 __ Move(r2, instr->hydrogen()->site());
3960 __ LoadRoot(r2, Heap::kUndefinedValueRootIndex);
3962 ElementsKind kind = instr->hydrogen()->elements_kind();
3963 AllocationSiteOverrideMode override_mode =
3964 (AllocationSite::GetMode(kind) == TRACK_ALLOCATION_SITE)
3965 ? DISABLE_ALLOCATION_SITES
3968 if (instr->arity() == 0) {
3969 ArrayNoArgumentConstructorStub stub(isolate(), kind, override_mode);
3970 CallCode(stub.GetCode(), RelocInfo::CONSTRUCT_CALL, instr);
3971 } else if (instr->arity() == 1) {
3973 if (IsFastPackedElementsKind(kind)) {
3975 // We might need a change here
3976 // look at the first argument
3977 __ ldr(r5, MemOperand(sp, 0));
3978 __ cmp(r5, Operand::Zero());
3979 __ b(eq, &packed_case);
3981 ElementsKind holey_kind = GetHoleyElementsKind(kind);
3982 ArraySingleArgumentConstructorStub stub(isolate(),
3985 CallCode(stub.GetCode(), RelocInfo::CONSTRUCT_CALL, instr);
3987 __ bind(&packed_case);
3990 ArraySingleArgumentConstructorStub stub(isolate(), kind, override_mode);
3991 CallCode(stub.GetCode(), RelocInfo::CONSTRUCT_CALL, instr);
3994 ArrayNArgumentsConstructorStub stub(isolate(), kind, override_mode);
3995 CallCode(stub.GetCode(), RelocInfo::CONSTRUCT_CALL, instr);
4000 void LCodeGen::DoCallRuntime(LCallRuntime* instr) {
4001 CallRuntime(instr->function(), instr->arity(), instr);
4005 void LCodeGen::DoStoreCodeEntry(LStoreCodeEntry* instr) {
4006 Register function = ToRegister(instr->function());
4007 Register code_object = ToRegister(instr->code_object());
4008 __ add(code_object, code_object, Operand(Code::kHeaderSize - kHeapObjectTag));
4010 FieldMemOperand(function, JSFunction::kCodeEntryOffset));
4014 void LCodeGen::DoInnerAllocatedObject(LInnerAllocatedObject* instr) {
4015 Register result = ToRegister(instr->result());
4016 Register base = ToRegister(instr->base_object());
4017 if (instr->offset()->IsConstantOperand()) {
4018 LConstantOperand* offset = LConstantOperand::cast(instr->offset());
4019 __ add(result, base, Operand(ToInteger32(offset)));
4021 Register offset = ToRegister(instr->offset());
4022 __ add(result, base, offset);
4027 void LCodeGen::DoStoreNamedField(LStoreNamedField* instr) {
4028 Representation representation = instr->representation();
4030 Register object = ToRegister(instr->object());
4031 Register scratch = scratch0();
4032 HObjectAccess access = instr->hydrogen()->access();
4033 int offset = access.offset();
4035 if (access.IsExternalMemory()) {
4036 Register value = ToRegister(instr->value());
4037 MemOperand operand = MemOperand(object, offset);
4038 __ Store(value, operand, representation);
4042 __ AssertNotSmi(object);
4044 DCHECK(!representation.IsSmi() ||
4045 !instr->value()->IsConstantOperand() ||
4046 IsSmi(LConstantOperand::cast(instr->value())));
4047 if (representation.IsDouble()) {
4048 DCHECK(access.IsInobject());
4049 DCHECK(!instr->hydrogen()->has_transition());
4050 DCHECK(!instr->hydrogen()->NeedsWriteBarrier());
4051 DwVfpRegister value = ToDoubleRegister(instr->value());
4052 __ vstr(value, FieldMemOperand(object, offset));
4056 if (instr->hydrogen()->has_transition()) {
4057 Handle<Map> transition = instr->hydrogen()->transition_map();
4058 AddDeprecationDependency(transition);
4059 __ mov(scratch, Operand(transition));
4060 __ str(scratch, FieldMemOperand(object, HeapObject::kMapOffset));
4061 if (instr->hydrogen()->NeedsWriteBarrierForMap()) {
4062 Register temp = ToRegister(instr->temp());
4063 // Update the write barrier for the map field.
4064 __ RecordWriteForMap(object,
4067 GetLinkRegisterState(),
4073 Register value = ToRegister(instr->value());
4074 if (access.IsInobject()) {
4075 MemOperand operand = FieldMemOperand(object, offset);
4076 __ Store(value, operand, representation);
4077 if (instr->hydrogen()->NeedsWriteBarrier()) {
4078 // Update the write barrier for the object for in-object properties.
4079 __ RecordWriteField(object,
4083 GetLinkRegisterState(),
4085 EMIT_REMEMBERED_SET,
4086 instr->hydrogen()->SmiCheckForWriteBarrier(),
4087 instr->hydrogen()->PointersToHereCheckForValue());
4090 __ ldr(scratch, FieldMemOperand(object, JSObject::kPropertiesOffset));
4091 MemOperand operand = FieldMemOperand(scratch, offset);
4092 __ Store(value, operand, representation);
4093 if (instr->hydrogen()->NeedsWriteBarrier()) {
4094 // Update the write barrier for the properties array.
4095 // object is used as a scratch register.
4096 __ RecordWriteField(scratch,
4100 GetLinkRegisterState(),
4102 EMIT_REMEMBERED_SET,
4103 instr->hydrogen()->SmiCheckForWriteBarrier(),
4104 instr->hydrogen()->PointersToHereCheckForValue());
4110 void LCodeGen::DoStoreNamedGeneric(LStoreNamedGeneric* instr) {
4111 DCHECK(ToRegister(instr->context()).is(cp));
4112 DCHECK(ToRegister(instr->object()).is(StoreDescriptor::ReceiverRegister()));
4113 DCHECK(ToRegister(instr->value()).is(StoreDescriptor::ValueRegister()));
4115 if (instr->hydrogen()->HasVectorAndSlot()) {
4116 EmitVectorStoreICRegisters<LStoreNamedGeneric>(instr);
4119 __ mov(StoreDescriptor::NameRegister(), Operand(instr->name()));
4120 Handle<Code> ic = CodeFactory::StoreICInOptimizedCode(
4121 isolate(), instr->language_mode(),
4122 instr->hydrogen()->initialization_state()).code();
4123 CallCode(ic, RelocInfo::CODE_TARGET, instr, NEVER_INLINE_TARGET_ADDRESS);
4127 void LCodeGen::DoStoreGlobalViaContext(LStoreGlobalViaContext* instr) {
4128 DCHECK(ToRegister(instr->context()).is(cp));
4129 DCHECK(ToRegister(instr->value())
4130 .is(StoreGlobalViaContextDescriptor::ValueRegister()));
4132 int const slot = instr->slot_index();
4133 int const depth = instr->depth();
4134 if (depth <= StoreGlobalViaContextStub::kMaximumDepth) {
4135 __ mov(StoreGlobalViaContextDescriptor::SlotRegister(), Operand(slot));
4136 Handle<Code> stub = CodeFactory::StoreGlobalViaContext(
4137 isolate(), depth, instr->language_mode())
4139 CallCode(stub, RelocInfo::CODE_TARGET, instr);
4141 __ Push(Smi::FromInt(slot));
4142 __ push(StoreGlobalViaContextDescriptor::ValueRegister());
4143 __ CallRuntime(is_strict(instr->language_mode())
4144 ? Runtime::kStoreGlobalViaContext_Strict
4145 : Runtime::kStoreGlobalViaContext_Sloppy,
4151 void LCodeGen::DoBoundsCheck(LBoundsCheck* instr) {
4152 Condition cc = instr->hydrogen()->allow_equality() ? hi : hs;
4153 if (instr->index()->IsConstantOperand()) {
4154 Operand index = ToOperand(instr->index());
4155 Register length = ToRegister(instr->length());
4156 __ cmp(length, index);
4157 cc = CommuteCondition(cc);
4159 Register index = ToRegister(instr->index());
4160 Operand length = ToOperand(instr->length());
4161 __ cmp(index, length);
4163 if (FLAG_debug_code && instr->hydrogen()->skip_check()) {
4165 __ b(NegateCondition(cc), &done);
4166 __ stop("eliminated bounds check failed");
4169 DeoptimizeIf(cc, instr, Deoptimizer::kOutOfBounds);
4174 void LCodeGen::DoStoreKeyedExternalArray(LStoreKeyed* instr) {
4175 Register external_pointer = ToRegister(instr->elements());
4176 Register key = no_reg;
4177 ElementsKind elements_kind = instr->elements_kind();
4178 bool key_is_constant = instr->key()->IsConstantOperand();
4179 int constant_key = 0;
4180 if (key_is_constant) {
4181 constant_key = ToInteger32(LConstantOperand::cast(instr->key()));
4182 if (constant_key & 0xF0000000) {
4183 Abort(kArrayIndexConstantValueTooBig);
4186 key = ToRegister(instr->key());
4188 int element_size_shift = ElementsKindToShiftSize(elements_kind);
4189 int shift_size = (instr->hydrogen()->key()->representation().IsSmi())
4190 ? (element_size_shift - kSmiTagSize) : element_size_shift;
4191 int base_offset = instr->base_offset();
4193 if (elements_kind == FLOAT32_ELEMENTS || elements_kind == FLOAT64_ELEMENTS) {
4194 Register address = scratch0();
4195 DwVfpRegister value(ToDoubleRegister(instr->value()));
4196 if (key_is_constant) {
4197 if (constant_key != 0) {
4198 __ add(address, external_pointer,
4199 Operand(constant_key << element_size_shift));
4201 address = external_pointer;
4204 __ add(address, external_pointer, Operand(key, LSL, shift_size));
4206 if (elements_kind == FLOAT32_ELEMENTS) {
4207 __ vcvt_f32_f64(double_scratch0().low(), value);
4208 __ vstr(double_scratch0().low(), address, base_offset);
4209 } else { // Storing doubles, not floats.
4210 __ vstr(value, address, base_offset);
4213 Register value(ToRegister(instr->value()));
4214 MemOperand mem_operand = PrepareKeyedOperand(
4215 key, external_pointer, key_is_constant, constant_key,
4216 element_size_shift, shift_size,
4218 switch (elements_kind) {
4219 case UINT8_ELEMENTS:
4220 case UINT8_CLAMPED_ELEMENTS:
4222 __ strb(value, mem_operand);
4224 case INT16_ELEMENTS:
4225 case UINT16_ELEMENTS:
4226 __ strh(value, mem_operand);
4228 case INT32_ELEMENTS:
4229 case UINT32_ELEMENTS:
4230 __ str(value, mem_operand);
4232 case FLOAT32_ELEMENTS:
4233 case FLOAT64_ELEMENTS:
4234 case FAST_DOUBLE_ELEMENTS:
4236 case FAST_SMI_ELEMENTS:
4237 case FAST_HOLEY_DOUBLE_ELEMENTS:
4238 case FAST_HOLEY_ELEMENTS:
4239 case FAST_HOLEY_SMI_ELEMENTS:
4240 case DICTIONARY_ELEMENTS:
4241 case FAST_SLOPPY_ARGUMENTS_ELEMENTS:
4242 case SLOW_SLOPPY_ARGUMENTS_ELEMENTS:
4250 void LCodeGen::DoStoreKeyedFixedDoubleArray(LStoreKeyed* instr) {
4251 DwVfpRegister value = ToDoubleRegister(instr->value());
4252 Register elements = ToRegister(instr->elements());
4253 Register scratch = scratch0();
4254 DwVfpRegister double_scratch = double_scratch0();
4255 bool key_is_constant = instr->key()->IsConstantOperand();
4256 int base_offset = instr->base_offset();
4258 // Calculate the effective address of the slot in the array to store the
4260 int element_size_shift = ElementsKindToShiftSize(FAST_DOUBLE_ELEMENTS);
4261 if (key_is_constant) {
4262 int constant_key = ToInteger32(LConstantOperand::cast(instr->key()));
4263 if (constant_key & 0xF0000000) {
4264 Abort(kArrayIndexConstantValueTooBig);
4266 __ add(scratch, elements,
4267 Operand((constant_key << element_size_shift) + base_offset));
4269 int shift_size = (instr->hydrogen()->key()->representation().IsSmi())
4270 ? (element_size_shift - kSmiTagSize) : element_size_shift;
4271 __ add(scratch, elements, Operand(base_offset));
4272 __ add(scratch, scratch,
4273 Operand(ToRegister(instr->key()), LSL, shift_size));
4276 if (instr->NeedsCanonicalization()) {
4277 // Force a canonical NaN.
4278 if (masm()->emit_debug_code()) {
4280 __ tst(ip, Operand(kVFPDefaultNaNModeControlBit));
4281 __ Assert(ne, kDefaultNaNModeNotSet);
4283 __ VFPCanonicalizeNaN(double_scratch, value);
4284 __ vstr(double_scratch, scratch, 0);
4286 __ vstr(value, scratch, 0);
4291 void LCodeGen::DoStoreKeyedFixedArray(LStoreKeyed* instr) {
4292 Register value = ToRegister(instr->value());
4293 Register elements = ToRegister(instr->elements());
4294 Register key = instr->key()->IsRegister() ? ToRegister(instr->key())
4296 Register scratch = scratch0();
4297 Register store_base = scratch;
4298 int offset = instr->base_offset();
4301 if (instr->key()->IsConstantOperand()) {
4302 DCHECK(!instr->hydrogen()->NeedsWriteBarrier());
4303 LConstantOperand* const_operand = LConstantOperand::cast(instr->key());
4304 offset += ToInteger32(const_operand) * kPointerSize;
4305 store_base = elements;
4307 // Even though the HLoadKeyed instruction forces the input
4308 // representation for the key to be an integer, the input gets replaced
4309 // during bound check elimination with the index argument to the bounds
4310 // check, which can be tagged, so that case must be handled here, too.
4311 if (instr->hydrogen()->key()->representation().IsSmi()) {
4312 __ add(scratch, elements, Operand::PointerOffsetFromSmiKey(key));
4314 __ add(scratch, elements, Operand(key, LSL, kPointerSizeLog2));
4317 __ str(value, MemOperand(store_base, offset));
4319 if (instr->hydrogen()->NeedsWriteBarrier()) {
4320 SmiCheck check_needed =
4321 instr->hydrogen()->value()->type().IsHeapObject()
4322 ? OMIT_SMI_CHECK : INLINE_SMI_CHECK;
4323 // Compute address of modified element and store it into key register.
4324 __ add(key, store_base, Operand(offset));
4325 __ RecordWrite(elements,
4328 GetLinkRegisterState(),
4330 EMIT_REMEMBERED_SET,
4332 instr->hydrogen()->PointersToHereCheckForValue());
4337 void LCodeGen::DoStoreKeyed(LStoreKeyed* instr) {
4338 // By cases: external, fast double
4339 if (instr->is_fixed_typed_array()) {
4340 DoStoreKeyedExternalArray(instr);
4341 } else if (instr->hydrogen()->value()->representation().IsDouble()) {
4342 DoStoreKeyedFixedDoubleArray(instr);
4344 DoStoreKeyedFixedArray(instr);
4349 void LCodeGen::DoStoreKeyedGeneric(LStoreKeyedGeneric* instr) {
4350 DCHECK(ToRegister(instr->context()).is(cp));
4351 DCHECK(ToRegister(instr->object()).is(StoreDescriptor::ReceiverRegister()));
4352 DCHECK(ToRegister(instr->key()).is(StoreDescriptor::NameRegister()));
4353 DCHECK(ToRegister(instr->value()).is(StoreDescriptor::ValueRegister()));
4355 if (instr->hydrogen()->HasVectorAndSlot()) {
4356 EmitVectorStoreICRegisters<LStoreKeyedGeneric>(instr);
4359 Handle<Code> ic = CodeFactory::KeyedStoreICInOptimizedCode(
4360 isolate(), instr->language_mode(),
4361 instr->hydrogen()->initialization_state()).code();
4362 CallCode(ic, RelocInfo::CODE_TARGET, instr, NEVER_INLINE_TARGET_ADDRESS);
4366 void LCodeGen::DoMaybeGrowElements(LMaybeGrowElements* instr) {
4367 class DeferredMaybeGrowElements final : public LDeferredCode {
4369 DeferredMaybeGrowElements(LCodeGen* codegen, LMaybeGrowElements* instr)
4370 : LDeferredCode(codegen), instr_(instr) {}
4371 void Generate() override { codegen()->DoDeferredMaybeGrowElements(instr_); }
4372 LInstruction* instr() override { return instr_; }
4375 LMaybeGrowElements* instr_;
4378 Register result = r0;
4379 DeferredMaybeGrowElements* deferred =
4380 new (zone()) DeferredMaybeGrowElements(this, instr);
4381 LOperand* key = instr->key();
4382 LOperand* current_capacity = instr->current_capacity();
4384 DCHECK(instr->hydrogen()->key()->representation().IsInteger32());
4385 DCHECK(instr->hydrogen()->current_capacity()->representation().IsInteger32());
4386 DCHECK(key->IsConstantOperand() || key->IsRegister());
4387 DCHECK(current_capacity->IsConstantOperand() ||
4388 current_capacity->IsRegister());
4390 if (key->IsConstantOperand() && current_capacity->IsConstantOperand()) {
4391 int32_t constant_key = ToInteger32(LConstantOperand::cast(key));
4392 int32_t constant_capacity =
4393 ToInteger32(LConstantOperand::cast(current_capacity));
4394 if (constant_key >= constant_capacity) {
4396 __ jmp(deferred->entry());
4398 } else if (key->IsConstantOperand()) {
4399 int32_t constant_key = ToInteger32(LConstantOperand::cast(key));
4400 __ cmp(ToRegister(current_capacity), Operand(constant_key));
4401 __ b(le, deferred->entry());
4402 } else if (current_capacity->IsConstantOperand()) {
4403 int32_t constant_capacity =
4404 ToInteger32(LConstantOperand::cast(current_capacity));
4405 __ cmp(ToRegister(key), Operand(constant_capacity));
4406 __ b(ge, deferred->entry());
4408 __ cmp(ToRegister(key), ToRegister(current_capacity));
4409 __ b(ge, deferred->entry());
4412 if (instr->elements()->IsRegister()) {
4413 __ Move(result, ToRegister(instr->elements()));
4415 __ ldr(result, ToMemOperand(instr->elements()));
4418 __ bind(deferred->exit());
4422 void LCodeGen::DoDeferredMaybeGrowElements(LMaybeGrowElements* instr) {
4423 // TODO(3095996): Get rid of this. For now, we need to make the
4424 // result register contain a valid pointer because it is already
4425 // contained in the register pointer map.
4426 Register result = r0;
4427 __ mov(result, Operand::Zero());
4429 // We have to call a stub.
4431 PushSafepointRegistersScope scope(this);
4432 if (instr->object()->IsRegister()) {
4433 __ Move(result, ToRegister(instr->object()));
4435 __ ldr(result, ToMemOperand(instr->object()));
4438 LOperand* key = instr->key();
4439 if (key->IsConstantOperand()) {
4440 __ Move(r3, Operand(ToSmi(LConstantOperand::cast(key))));
4442 __ Move(r3, ToRegister(key));
4446 GrowArrayElementsStub stub(isolate(), instr->hydrogen()->is_js_array(),
4447 instr->hydrogen()->kind());
4449 RecordSafepointWithLazyDeopt(
4450 instr, RECORD_SAFEPOINT_WITH_REGISTERS_AND_NO_ARGUMENTS);
4451 __ StoreToSafepointRegisterSlot(result, result);
4454 // Deopt on smi, which means the elements array changed to dictionary mode.
4456 DeoptimizeIf(eq, instr, Deoptimizer::kSmi);
4460 void LCodeGen::DoTransitionElementsKind(LTransitionElementsKind* instr) {
4461 Register object_reg = ToRegister(instr->object());
4462 Register scratch = scratch0();
4464 Handle<Map> from_map = instr->original_map();
4465 Handle<Map> to_map = instr->transitioned_map();
4466 ElementsKind from_kind = instr->from_kind();
4467 ElementsKind to_kind = instr->to_kind();
4469 Label not_applicable;
4470 __ ldr(scratch, FieldMemOperand(object_reg, HeapObject::kMapOffset));
4471 __ cmp(scratch, Operand(from_map));
4472 __ b(ne, ¬_applicable);
4474 if (IsSimpleMapChangeTransition(from_kind, to_kind)) {
4475 Register new_map_reg = ToRegister(instr->new_map_temp());
4476 __ mov(new_map_reg, Operand(to_map));
4477 __ str(new_map_reg, FieldMemOperand(object_reg, HeapObject::kMapOffset));
4479 __ RecordWriteForMap(object_reg,
4482 GetLinkRegisterState(),
4485 DCHECK(ToRegister(instr->context()).is(cp));
4486 DCHECK(object_reg.is(r0));
4487 PushSafepointRegistersScope scope(this);
4488 __ Move(r1, to_map);
4489 bool is_js_array = from_map->instance_type() == JS_ARRAY_TYPE;
4490 TransitionElementsKindStub stub(isolate(), from_kind, to_kind, is_js_array);
4492 RecordSafepointWithRegisters(
4493 instr->pointer_map(), 0, Safepoint::kLazyDeopt);
4495 __ bind(¬_applicable);
4499 void LCodeGen::DoTrapAllocationMemento(LTrapAllocationMemento* instr) {
4500 Register object = ToRegister(instr->object());
4501 Register temp = ToRegister(instr->temp());
4502 Label no_memento_found;
4503 __ TestJSArrayForAllocationMemento(object, temp, &no_memento_found);
4504 DeoptimizeIf(eq, instr, Deoptimizer::kMementoFound);
4505 __ bind(&no_memento_found);
4509 void LCodeGen::DoStringAdd(LStringAdd* instr) {
4510 DCHECK(ToRegister(instr->context()).is(cp));
4511 DCHECK(ToRegister(instr->left()).is(r1));
4512 DCHECK(ToRegister(instr->right()).is(r0));
4513 StringAddStub stub(isolate(),
4514 instr->hydrogen()->flags(),
4515 instr->hydrogen()->pretenure_flag());
4516 CallCode(stub.GetCode(), RelocInfo::CODE_TARGET, instr);
4520 void LCodeGen::DoStringCharCodeAt(LStringCharCodeAt* instr) {
4521 class DeferredStringCharCodeAt final : public LDeferredCode {
4523 DeferredStringCharCodeAt(LCodeGen* codegen, LStringCharCodeAt* instr)
4524 : LDeferredCode(codegen), instr_(instr) { }
4525 void Generate() override { codegen()->DoDeferredStringCharCodeAt(instr_); }
4526 LInstruction* instr() override { return instr_; }
4529 LStringCharCodeAt* instr_;
4532 DeferredStringCharCodeAt* deferred =
4533 new(zone()) DeferredStringCharCodeAt(this, instr);
4535 StringCharLoadGenerator::Generate(masm(),
4536 ToRegister(instr->string()),
4537 ToRegister(instr->index()),
4538 ToRegister(instr->result()),
4540 __ bind(deferred->exit());
4544 void LCodeGen::DoDeferredStringCharCodeAt(LStringCharCodeAt* instr) {
4545 Register string = ToRegister(instr->string());
4546 Register result = ToRegister(instr->result());
4547 Register scratch = scratch0();
4549 // TODO(3095996): Get rid of this. For now, we need to make the
4550 // result register contain a valid pointer because it is already
4551 // contained in the register pointer map.
4552 __ mov(result, Operand::Zero());
4554 PushSafepointRegistersScope scope(this);
4556 // Push the index as a smi. This is safe because of the checks in
4557 // DoStringCharCodeAt above.
4558 if (instr->index()->IsConstantOperand()) {
4559 int const_index = ToInteger32(LConstantOperand::cast(instr->index()));
4560 __ mov(scratch, Operand(Smi::FromInt(const_index)));
4563 Register index = ToRegister(instr->index());
4567 CallRuntimeFromDeferred(Runtime::kStringCharCodeAtRT, 2, instr,
4571 __ StoreToSafepointRegisterSlot(r0, result);
4575 void LCodeGen::DoStringCharFromCode(LStringCharFromCode* instr) {
4576 class DeferredStringCharFromCode final : public LDeferredCode {
4578 DeferredStringCharFromCode(LCodeGen* codegen, LStringCharFromCode* instr)
4579 : LDeferredCode(codegen), instr_(instr) { }
4580 void Generate() override {
4581 codegen()->DoDeferredStringCharFromCode(instr_);
4583 LInstruction* instr() override { return instr_; }
4586 LStringCharFromCode* instr_;
4589 DeferredStringCharFromCode* deferred =
4590 new(zone()) DeferredStringCharFromCode(this, instr);
4592 DCHECK(instr->hydrogen()->value()->representation().IsInteger32());
4593 Register char_code = ToRegister(instr->char_code());
4594 Register result = ToRegister(instr->result());
4595 DCHECK(!char_code.is(result));
4597 __ cmp(char_code, Operand(String::kMaxOneByteCharCode));
4598 __ b(hi, deferred->entry());
4599 __ LoadRoot(result, Heap::kSingleCharacterStringCacheRootIndex);
4600 __ add(result, result, Operand(char_code, LSL, kPointerSizeLog2));
4601 __ ldr(result, FieldMemOperand(result, FixedArray::kHeaderSize));
4602 __ LoadRoot(ip, Heap::kUndefinedValueRootIndex);
4604 __ b(eq, deferred->entry());
4605 __ bind(deferred->exit());
4609 void LCodeGen::DoDeferredStringCharFromCode(LStringCharFromCode* instr) {
4610 Register char_code = ToRegister(instr->char_code());
4611 Register result = ToRegister(instr->result());
4613 // TODO(3095996): Get rid of this. For now, we need to make the
4614 // result register contain a valid pointer because it is already
4615 // contained in the register pointer map.
4616 __ mov(result, Operand::Zero());
4618 PushSafepointRegistersScope scope(this);
4619 __ SmiTag(char_code);
4621 CallRuntimeFromDeferred(Runtime::kCharFromCode, 1, instr, instr->context());
4622 __ StoreToSafepointRegisterSlot(r0, result);
4626 void LCodeGen::DoInteger32ToDouble(LInteger32ToDouble* instr) {
4627 LOperand* input = instr->value();
4628 DCHECK(input->IsRegister() || input->IsStackSlot());
4629 LOperand* output = instr->result();
4630 DCHECK(output->IsDoubleRegister());
4631 SwVfpRegister single_scratch = double_scratch0().low();
4632 if (input->IsStackSlot()) {
4633 Register scratch = scratch0();
4634 __ ldr(scratch, ToMemOperand(input));
4635 __ vmov(single_scratch, scratch);
4637 __ vmov(single_scratch, ToRegister(input));
4639 __ vcvt_f64_s32(ToDoubleRegister(output), single_scratch);
4643 void LCodeGen::DoUint32ToDouble(LUint32ToDouble* instr) {
4644 LOperand* input = instr->value();
4645 LOperand* output = instr->result();
4647 SwVfpRegister flt_scratch = double_scratch0().low();
4648 __ vmov(flt_scratch, ToRegister(input));
4649 __ vcvt_f64_u32(ToDoubleRegister(output), flt_scratch);
4653 void LCodeGen::DoNumberTagI(LNumberTagI* instr) {
4654 class DeferredNumberTagI final : public LDeferredCode {
4656 DeferredNumberTagI(LCodeGen* codegen, LNumberTagI* instr)
4657 : LDeferredCode(codegen), instr_(instr) { }
4658 void Generate() override {
4659 codegen()->DoDeferredNumberTagIU(instr_,
4665 LInstruction* instr() override { return instr_; }
4668 LNumberTagI* instr_;
4671 Register src = ToRegister(instr->value());
4672 Register dst = ToRegister(instr->result());
4674 DeferredNumberTagI* deferred = new(zone()) DeferredNumberTagI(this, instr);
4675 __ SmiTag(dst, src, SetCC);
4676 __ b(vs, deferred->entry());
4677 __ bind(deferred->exit());
4681 void LCodeGen::DoNumberTagU(LNumberTagU* instr) {
4682 class DeferredNumberTagU final : public LDeferredCode {
4684 DeferredNumberTagU(LCodeGen* codegen, LNumberTagU* instr)
4685 : LDeferredCode(codegen), instr_(instr) { }
4686 void Generate() override {
4687 codegen()->DoDeferredNumberTagIU(instr_,
4693 LInstruction* instr() override { return instr_; }
4696 LNumberTagU* instr_;
4699 Register input = ToRegister(instr->value());
4700 Register result = ToRegister(instr->result());
4702 DeferredNumberTagU* deferred = new(zone()) DeferredNumberTagU(this, instr);
4703 __ cmp(input, Operand(Smi::kMaxValue));
4704 __ b(hi, deferred->entry());
4705 __ SmiTag(result, input);
4706 __ bind(deferred->exit());
4710 void LCodeGen::DoDeferredNumberTagIU(LInstruction* instr,
4714 IntegerSignedness signedness) {
4716 Register src = ToRegister(value);
4717 Register dst = ToRegister(instr->result());
4718 Register tmp1 = scratch0();
4719 Register tmp2 = ToRegister(temp1);
4720 Register tmp3 = ToRegister(temp2);
4721 LowDwVfpRegister dbl_scratch = double_scratch0();
4723 if (signedness == SIGNED_INT32) {
4724 // There was overflow, so bits 30 and 31 of the original integer
4725 // disagree. Try to allocate a heap number in new space and store
4726 // the value in there. If that fails, call the runtime system.
4728 __ SmiUntag(src, dst);
4729 __ eor(src, src, Operand(0x80000000));
4731 __ vmov(dbl_scratch.low(), src);
4732 __ vcvt_f64_s32(dbl_scratch, dbl_scratch.low());
4734 __ vmov(dbl_scratch.low(), src);
4735 __ vcvt_f64_u32(dbl_scratch, dbl_scratch.low());
4738 if (FLAG_inline_new) {
4739 __ LoadRoot(tmp3, Heap::kHeapNumberMapRootIndex);
4740 __ AllocateHeapNumber(dst, tmp1, tmp2, tmp3, &slow, DONT_TAG_RESULT);
4744 // Slow case: Call the runtime system to do the number allocation.
4747 // TODO(3095996): Put a valid pointer value in the stack slot where the
4748 // result register is stored, as this register is in the pointer map, but
4749 // contains an integer value.
4750 __ mov(dst, Operand::Zero());
4752 // Preserve the value of all registers.
4753 PushSafepointRegistersScope scope(this);
4755 // NumberTagI and NumberTagD use the context from the frame, rather than
4756 // the environment's HContext or HInlinedContext value.
4757 // They only call Runtime::kAllocateHeapNumber.
4758 // The corresponding HChange instructions are added in a phase that does
4759 // not have easy access to the local context.
4760 __ ldr(cp, MemOperand(fp, StandardFrameConstants::kContextOffset));
4761 __ CallRuntimeSaveDoubles(Runtime::kAllocateHeapNumber);
4762 RecordSafepointWithRegisters(
4763 instr->pointer_map(), 0, Safepoint::kNoLazyDeopt);
4764 __ sub(r0, r0, Operand(kHeapObjectTag));
4765 __ StoreToSafepointRegisterSlot(r0, dst);
4768 // Done. Put the value in dbl_scratch into the value of the allocated heap
4771 __ vstr(dbl_scratch, dst, HeapNumber::kValueOffset);
4772 __ add(dst, dst, Operand(kHeapObjectTag));
4776 void LCodeGen::DoNumberTagD(LNumberTagD* instr) {
4777 class DeferredNumberTagD final : public LDeferredCode {
4779 DeferredNumberTagD(LCodeGen* codegen, LNumberTagD* instr)
4780 : LDeferredCode(codegen), instr_(instr) { }
4781 void Generate() override { codegen()->DoDeferredNumberTagD(instr_); }
4782 LInstruction* instr() override { return instr_; }
4785 LNumberTagD* instr_;
4788 DwVfpRegister input_reg = ToDoubleRegister(instr->value());
4789 Register scratch = scratch0();
4790 Register reg = ToRegister(instr->result());
4791 Register temp1 = ToRegister(instr->temp());
4792 Register temp2 = ToRegister(instr->temp2());
4794 DeferredNumberTagD* deferred = new(zone()) DeferredNumberTagD(this, instr);
4795 if (FLAG_inline_new) {
4796 __ LoadRoot(scratch, Heap::kHeapNumberMapRootIndex);
4797 // We want the untagged address first for performance
4798 __ AllocateHeapNumber(reg, temp1, temp2, scratch, deferred->entry(),
4801 __ jmp(deferred->entry());
4803 __ bind(deferred->exit());
4804 __ vstr(input_reg, reg, HeapNumber::kValueOffset);
4805 // Now that we have finished with the object's real address tag it
4806 __ add(reg, reg, Operand(kHeapObjectTag));
4810 void LCodeGen::DoDeferredNumberTagD(LNumberTagD* instr) {
4811 // TODO(3095996): Get rid of this. For now, we need to make the
4812 // result register contain a valid pointer because it is already
4813 // contained in the register pointer map.
4814 Register reg = ToRegister(instr->result());
4815 __ mov(reg, Operand::Zero());
4817 PushSafepointRegistersScope scope(this);
4818 // NumberTagI and NumberTagD use the context from the frame, rather than
4819 // the environment's HContext or HInlinedContext value.
4820 // They only call Runtime::kAllocateHeapNumber.
4821 // The corresponding HChange instructions are added in a phase that does
4822 // not have easy access to the local context.
4823 __ ldr(cp, MemOperand(fp, StandardFrameConstants::kContextOffset));
4824 __ CallRuntimeSaveDoubles(Runtime::kAllocateHeapNumber);
4825 RecordSafepointWithRegisters(
4826 instr->pointer_map(), 0, Safepoint::kNoLazyDeopt);
4827 __ sub(r0, r0, Operand(kHeapObjectTag));
4828 __ StoreToSafepointRegisterSlot(r0, reg);
4832 void LCodeGen::DoSmiTag(LSmiTag* instr) {
4833 HChange* hchange = instr->hydrogen();
4834 Register input = ToRegister(instr->value());
4835 Register output = ToRegister(instr->result());
4836 if (hchange->CheckFlag(HValue::kCanOverflow) &&
4837 hchange->value()->CheckFlag(HValue::kUint32)) {
4838 __ tst(input, Operand(0xc0000000));
4839 DeoptimizeIf(ne, instr, Deoptimizer::kOverflow);
4841 if (hchange->CheckFlag(HValue::kCanOverflow) &&
4842 !hchange->value()->CheckFlag(HValue::kUint32)) {
4843 __ SmiTag(output, input, SetCC);
4844 DeoptimizeIf(vs, instr, Deoptimizer::kOverflow);
4846 __ SmiTag(output, input);
4851 void LCodeGen::DoSmiUntag(LSmiUntag* instr) {
4852 Register input = ToRegister(instr->value());
4853 Register result = ToRegister(instr->result());
4854 if (instr->needs_check()) {
4855 STATIC_ASSERT(kHeapObjectTag == 1);
4856 // If the input is a HeapObject, SmiUntag will set the carry flag.
4857 __ SmiUntag(result, input, SetCC);
4858 DeoptimizeIf(cs, instr, Deoptimizer::kNotASmi);
4860 __ SmiUntag(result, input);
4865 void LCodeGen::EmitNumberUntagD(LNumberUntagD* instr, Register input_reg,
4866 DwVfpRegister result_reg,
4867 NumberUntagDMode mode) {
4868 bool can_convert_undefined_to_nan =
4869 instr->hydrogen()->can_convert_undefined_to_nan();
4870 bool deoptimize_on_minus_zero = instr->hydrogen()->deoptimize_on_minus_zero();
4872 Register scratch = scratch0();
4873 SwVfpRegister flt_scratch = double_scratch0().low();
4874 DCHECK(!result_reg.is(double_scratch0()));
4875 Label convert, load_smi, done;
4876 if (mode == NUMBER_CANDIDATE_IS_ANY_TAGGED) {
4878 __ UntagAndJumpIfSmi(scratch, input_reg, &load_smi);
4879 // Heap number map check.
4880 __ ldr(scratch, FieldMemOperand(input_reg, HeapObject::kMapOffset));
4881 __ LoadRoot(ip, Heap::kHeapNumberMapRootIndex);
4882 __ cmp(scratch, Operand(ip));
4883 if (can_convert_undefined_to_nan) {
4886 DeoptimizeIf(ne, instr, Deoptimizer::kNotAHeapNumber);
4889 __ vldr(result_reg, input_reg, HeapNumber::kValueOffset - kHeapObjectTag);
4890 if (deoptimize_on_minus_zero) {
4891 __ VmovLow(scratch, result_reg);
4892 __ cmp(scratch, Operand::Zero());
4894 __ VmovHigh(scratch, result_reg);
4895 __ cmp(scratch, Operand(HeapNumber::kSignMask));
4896 DeoptimizeIf(eq, instr, Deoptimizer::kMinusZero);
4899 if (can_convert_undefined_to_nan) {
4901 // Convert undefined (and hole) to NaN.
4902 __ LoadRoot(ip, Heap::kUndefinedValueRootIndex);
4903 __ cmp(input_reg, Operand(ip));
4904 DeoptimizeIf(ne, instr, Deoptimizer::kNotAHeapNumberUndefined);
4905 __ LoadRoot(scratch, Heap::kNanValueRootIndex);
4906 __ vldr(result_reg, scratch, HeapNumber::kValueOffset - kHeapObjectTag);
4910 __ SmiUntag(scratch, input_reg);
4911 DCHECK(mode == NUMBER_CANDIDATE_IS_SMI);
4913 // Smi to double register conversion
4915 // scratch: untagged value of input_reg
4916 __ vmov(flt_scratch, scratch);
4917 __ vcvt_f64_s32(result_reg, flt_scratch);
4922 void LCodeGen::DoDeferredTaggedToI(LTaggedToI* instr) {
4923 Register input_reg = ToRegister(instr->value());
4924 Register scratch1 = scratch0();
4925 Register scratch2 = ToRegister(instr->temp());
4926 LowDwVfpRegister double_scratch = double_scratch0();
4927 DwVfpRegister double_scratch2 = ToDoubleRegister(instr->temp2());
4929 DCHECK(!scratch1.is(input_reg) && !scratch1.is(scratch2));
4930 DCHECK(!scratch2.is(input_reg) && !scratch2.is(scratch1));
4934 // The input was optimistically untagged; revert it.
4935 // The carry flag is set when we reach this deferred code as we just executed
4936 // SmiUntag(heap_object, SetCC)
4937 STATIC_ASSERT(kHeapObjectTag == 1);
4938 __ adc(scratch2, input_reg, Operand(input_reg));
4940 // Heap number map check.
4941 __ ldr(scratch1, FieldMemOperand(scratch2, HeapObject::kMapOffset));
4942 __ LoadRoot(ip, Heap::kHeapNumberMapRootIndex);
4943 __ cmp(scratch1, Operand(ip));
4945 if (instr->truncating()) {
4946 // Performs a truncating conversion of a floating point number as used by
4947 // the JS bitwise operations.
4948 Label no_heap_number, check_bools, check_false;
4949 __ b(ne, &no_heap_number);
4950 __ TruncateHeapNumberToI(input_reg, scratch2);
4953 // Check for Oddballs. Undefined/False is converted to zero and True to one
4954 // for truncating conversions.
4955 __ bind(&no_heap_number);
4956 __ LoadRoot(ip, Heap::kUndefinedValueRootIndex);
4957 __ cmp(scratch2, Operand(ip));
4958 __ b(ne, &check_bools);
4959 __ mov(input_reg, Operand::Zero());
4962 __ bind(&check_bools);
4963 __ LoadRoot(ip, Heap::kTrueValueRootIndex);
4964 __ cmp(scratch2, Operand(ip));
4965 __ b(ne, &check_false);
4966 __ mov(input_reg, Operand(1));
4969 __ bind(&check_false);
4970 __ LoadRoot(ip, Heap::kFalseValueRootIndex);
4971 __ cmp(scratch2, Operand(ip));
4972 DeoptimizeIf(ne, instr, Deoptimizer::kNotAHeapNumberUndefinedBoolean);
4973 __ mov(input_reg, Operand::Zero());
4975 DeoptimizeIf(ne, instr, Deoptimizer::kNotAHeapNumber);
4977 __ sub(ip, scratch2, Operand(kHeapObjectTag));
4978 __ vldr(double_scratch2, ip, HeapNumber::kValueOffset);
4979 __ TryDoubleToInt32Exact(input_reg, double_scratch2, double_scratch);
4980 DeoptimizeIf(ne, instr, Deoptimizer::kLostPrecisionOrNaN);
4982 if (instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero)) {
4983 __ cmp(input_reg, Operand::Zero());
4985 __ VmovHigh(scratch1, double_scratch2);
4986 __ tst(scratch1, Operand(HeapNumber::kSignMask));
4987 DeoptimizeIf(ne, instr, Deoptimizer::kMinusZero);
4994 void LCodeGen::DoTaggedToI(LTaggedToI* instr) {
4995 class DeferredTaggedToI final : public LDeferredCode {
4997 DeferredTaggedToI(LCodeGen* codegen, LTaggedToI* instr)
4998 : LDeferredCode(codegen), instr_(instr) { }
4999 void Generate() override { codegen()->DoDeferredTaggedToI(instr_); }
5000 LInstruction* instr() override { return instr_; }
5006 LOperand* input = instr->value();
5007 DCHECK(input->IsRegister());
5008 DCHECK(input->Equals(instr->result()));
5010 Register input_reg = ToRegister(input);
5012 if (instr->hydrogen()->value()->representation().IsSmi()) {
5013 __ SmiUntag(input_reg);
5015 DeferredTaggedToI* deferred = new(zone()) DeferredTaggedToI(this, instr);
5017 // Optimistically untag the input.
5018 // If the input is a HeapObject, SmiUntag will set the carry flag.
5019 __ SmiUntag(input_reg, SetCC);
5020 // Branch to deferred code if the input was tagged.
5021 // The deferred code will take care of restoring the tag.
5022 __ b(cs, deferred->entry());
5023 __ bind(deferred->exit());
5028 void LCodeGen::DoNumberUntagD(LNumberUntagD* instr) {
5029 LOperand* input = instr->value();
5030 DCHECK(input->IsRegister());
5031 LOperand* result = instr->result();
5032 DCHECK(result->IsDoubleRegister());
5034 Register input_reg = ToRegister(input);
5035 DwVfpRegister result_reg = ToDoubleRegister(result);
5037 HValue* value = instr->hydrogen()->value();
5038 NumberUntagDMode mode = value->representation().IsSmi()
5039 ? NUMBER_CANDIDATE_IS_SMI : NUMBER_CANDIDATE_IS_ANY_TAGGED;
5041 EmitNumberUntagD(instr, input_reg, result_reg, mode);
5045 void LCodeGen::DoDoubleToI(LDoubleToI* instr) {
5046 Register result_reg = ToRegister(instr->result());
5047 Register scratch1 = scratch0();
5048 DwVfpRegister double_input = ToDoubleRegister(instr->value());
5049 LowDwVfpRegister double_scratch = double_scratch0();
5051 if (instr->truncating()) {
5052 __ TruncateDoubleToI(result_reg, double_input);
5054 __ TryDoubleToInt32Exact(result_reg, double_input, double_scratch);
5055 // Deoptimize if the input wasn't a int32 (inside a double).
5056 DeoptimizeIf(ne, instr, Deoptimizer::kLostPrecisionOrNaN);
5057 if (instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero)) {
5059 __ cmp(result_reg, Operand::Zero());
5061 __ VmovHigh(scratch1, double_input);
5062 __ tst(scratch1, Operand(HeapNumber::kSignMask));
5063 DeoptimizeIf(ne, instr, Deoptimizer::kMinusZero);
5070 void LCodeGen::DoDoubleToSmi(LDoubleToSmi* instr) {
5071 Register result_reg = ToRegister(instr->result());
5072 Register scratch1 = scratch0();
5073 DwVfpRegister double_input = ToDoubleRegister(instr->value());
5074 LowDwVfpRegister double_scratch = double_scratch0();
5076 if (instr->truncating()) {
5077 __ TruncateDoubleToI(result_reg, double_input);
5079 __ TryDoubleToInt32Exact(result_reg, double_input, double_scratch);
5080 // Deoptimize if the input wasn't a int32 (inside a double).
5081 DeoptimizeIf(ne, instr, Deoptimizer::kLostPrecisionOrNaN);
5082 if (instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero)) {
5084 __ cmp(result_reg, Operand::Zero());
5086 __ VmovHigh(scratch1, double_input);
5087 __ tst(scratch1, Operand(HeapNumber::kSignMask));
5088 DeoptimizeIf(ne, instr, Deoptimizer::kMinusZero);
5092 __ SmiTag(result_reg, SetCC);
5093 DeoptimizeIf(vs, instr, Deoptimizer::kOverflow);
5097 void LCodeGen::DoCheckSmi(LCheckSmi* instr) {
5098 LOperand* input = instr->value();
5099 __ SmiTst(ToRegister(input));
5100 DeoptimizeIf(ne, instr, Deoptimizer::kNotASmi);
5104 void LCodeGen::DoCheckNonSmi(LCheckNonSmi* instr) {
5105 if (!instr->hydrogen()->value()->type().IsHeapObject()) {
5106 LOperand* input = instr->value();
5107 __ SmiTst(ToRegister(input));
5108 DeoptimizeIf(eq, instr, Deoptimizer::kSmi);
5113 void LCodeGen::DoCheckArrayBufferNotNeutered(
5114 LCheckArrayBufferNotNeutered* instr) {
5115 Register view = ToRegister(instr->view());
5116 Register scratch = scratch0();
5118 __ ldr(scratch, FieldMemOperand(view, JSArrayBufferView::kBufferOffset));
5119 __ ldr(scratch, FieldMemOperand(scratch, JSArrayBuffer::kBitFieldOffset));
5120 __ tst(scratch, Operand(1 << JSArrayBuffer::WasNeutered::kShift));
5121 DeoptimizeIf(ne, instr, Deoptimizer::kOutOfBounds);
5125 void LCodeGen::DoCheckInstanceType(LCheckInstanceType* instr) {
5126 Register input = ToRegister(instr->value());
5127 Register scratch = scratch0();
5129 __ ldr(scratch, FieldMemOperand(input, HeapObject::kMapOffset));
5130 __ ldrb(scratch, FieldMemOperand(scratch, Map::kInstanceTypeOffset));
5132 if (instr->hydrogen()->is_interval_check()) {
5135 instr->hydrogen()->GetCheckInterval(&first, &last);
5137 __ cmp(scratch, Operand(first));
5139 // If there is only one type in the interval check for equality.
5140 if (first == last) {
5141 DeoptimizeIf(ne, instr, Deoptimizer::kWrongInstanceType);
5143 DeoptimizeIf(lo, instr, Deoptimizer::kWrongInstanceType);
5144 // Omit check for the last type.
5145 if (last != LAST_TYPE) {
5146 __ cmp(scratch, Operand(last));
5147 DeoptimizeIf(hi, instr, Deoptimizer::kWrongInstanceType);
5153 instr->hydrogen()->GetCheckMaskAndTag(&mask, &tag);
5155 if (base::bits::IsPowerOfTwo32(mask)) {
5156 DCHECK(tag == 0 || base::bits::IsPowerOfTwo32(tag));
5157 __ tst(scratch, Operand(mask));
5158 DeoptimizeIf(tag == 0 ? ne : eq, instr, Deoptimizer::kWrongInstanceType);
5160 __ and_(scratch, scratch, Operand(mask));
5161 __ cmp(scratch, Operand(tag));
5162 DeoptimizeIf(ne, instr, Deoptimizer::kWrongInstanceType);
5168 void LCodeGen::DoCheckValue(LCheckValue* instr) {
5169 Register reg = ToRegister(instr->value());
5170 Handle<HeapObject> object = instr->hydrogen()->object().handle();
5171 AllowDeferredHandleDereference smi_check;
5172 if (isolate()->heap()->InNewSpace(*object)) {
5173 Register reg = ToRegister(instr->value());
5174 Handle<Cell> cell = isolate()->factory()->NewCell(object);
5175 __ mov(ip, Operand(cell));
5176 __ ldr(ip, FieldMemOperand(ip, Cell::kValueOffset));
5179 __ cmp(reg, Operand(object));
5181 DeoptimizeIf(ne, instr, Deoptimizer::kValueMismatch);
5185 void LCodeGen::DoDeferredInstanceMigration(LCheckMaps* instr, Register object) {
5187 PushSafepointRegistersScope scope(this);
5189 __ mov(cp, Operand::Zero());
5190 __ CallRuntimeSaveDoubles(Runtime::kTryMigrateInstance);
5191 RecordSafepointWithRegisters(
5192 instr->pointer_map(), 1, Safepoint::kNoLazyDeopt);
5193 __ StoreToSafepointRegisterSlot(r0, scratch0());
5195 __ tst(scratch0(), Operand(kSmiTagMask));
5196 DeoptimizeIf(eq, instr, Deoptimizer::kInstanceMigrationFailed);
5200 void LCodeGen::DoCheckMaps(LCheckMaps* instr) {
5201 class DeferredCheckMaps final : public LDeferredCode {
5203 DeferredCheckMaps(LCodeGen* codegen, LCheckMaps* instr, Register object)
5204 : LDeferredCode(codegen), instr_(instr), object_(object) {
5205 SetExit(check_maps());
5207 void Generate() override {
5208 codegen()->DoDeferredInstanceMigration(instr_, object_);
5210 Label* check_maps() { return &check_maps_; }
5211 LInstruction* instr() override { return instr_; }
5219 if (instr->hydrogen()->IsStabilityCheck()) {
5220 const UniqueSet<Map>* maps = instr->hydrogen()->maps();
5221 for (int i = 0; i < maps->size(); ++i) {
5222 AddStabilityDependency(maps->at(i).handle());
5227 Register map_reg = scratch0();
5229 LOperand* input = instr->value();
5230 DCHECK(input->IsRegister());
5231 Register reg = ToRegister(input);
5233 __ ldr(map_reg, FieldMemOperand(reg, HeapObject::kMapOffset));
5235 DeferredCheckMaps* deferred = NULL;
5236 if (instr->hydrogen()->HasMigrationTarget()) {
5237 deferred = new(zone()) DeferredCheckMaps(this, instr, reg);
5238 __ bind(deferred->check_maps());
5241 const UniqueSet<Map>* maps = instr->hydrogen()->maps();
5243 for (int i = 0; i < maps->size() - 1; i++) {
5244 Handle<Map> map = maps->at(i).handle();
5245 __ CompareMap(map_reg, map, &success);
5249 Handle<Map> map = maps->at(maps->size() - 1).handle();
5250 __ CompareMap(map_reg, map, &success);
5251 if (instr->hydrogen()->HasMigrationTarget()) {
5252 __ b(ne, deferred->entry());
5254 DeoptimizeIf(ne, instr, Deoptimizer::kWrongMap);
5261 void LCodeGen::DoClampDToUint8(LClampDToUint8* instr) {
5262 DwVfpRegister value_reg = ToDoubleRegister(instr->unclamped());
5263 Register result_reg = ToRegister(instr->result());
5264 __ ClampDoubleToUint8(result_reg, value_reg, double_scratch0());
5268 void LCodeGen::DoClampIToUint8(LClampIToUint8* instr) {
5269 Register unclamped_reg = ToRegister(instr->unclamped());
5270 Register result_reg = ToRegister(instr->result());
5271 __ ClampUint8(result_reg, unclamped_reg);
5275 void LCodeGen::DoClampTToUint8(LClampTToUint8* instr) {
5276 Register scratch = scratch0();
5277 Register input_reg = ToRegister(instr->unclamped());
5278 Register result_reg = ToRegister(instr->result());
5279 DwVfpRegister temp_reg = ToDoubleRegister(instr->temp());
5280 Label is_smi, done, heap_number;
5282 // Both smi and heap number cases are handled.
5283 __ UntagAndJumpIfSmi(result_reg, input_reg, &is_smi);
5285 // Check for heap number
5286 __ ldr(scratch, FieldMemOperand(input_reg, HeapObject::kMapOffset));
5287 __ cmp(scratch, Operand(factory()->heap_number_map()));
5288 __ b(eq, &heap_number);
5290 // Check for undefined. Undefined is converted to zero for clamping
5292 __ cmp(input_reg, Operand(factory()->undefined_value()));
5293 DeoptimizeIf(ne, instr, Deoptimizer::kNotAHeapNumberUndefined);
5294 __ mov(result_reg, Operand::Zero());
5298 __ bind(&heap_number);
5299 __ vldr(temp_reg, FieldMemOperand(input_reg, HeapNumber::kValueOffset));
5300 __ ClampDoubleToUint8(result_reg, temp_reg, double_scratch0());
5305 __ ClampUint8(result_reg, result_reg);
5311 void LCodeGen::DoDoubleBits(LDoubleBits* instr) {
5312 DwVfpRegister value_reg = ToDoubleRegister(instr->value());
5313 Register result_reg = ToRegister(instr->result());
5314 if (instr->hydrogen()->bits() == HDoubleBits::HIGH) {
5315 __ VmovHigh(result_reg, value_reg);
5317 __ VmovLow(result_reg, value_reg);
5322 void LCodeGen::DoConstructDouble(LConstructDouble* instr) {
5323 Register hi_reg = ToRegister(instr->hi());
5324 Register lo_reg = ToRegister(instr->lo());
5325 DwVfpRegister result_reg = ToDoubleRegister(instr->result());
5326 __ VmovHigh(result_reg, hi_reg);
5327 __ VmovLow(result_reg, lo_reg);
5331 void LCodeGen::DoAllocate(LAllocate* instr) {
5332 class DeferredAllocate final : public LDeferredCode {
5334 DeferredAllocate(LCodeGen* codegen, LAllocate* instr)
5335 : LDeferredCode(codegen), instr_(instr) { }
5336 void Generate() override { codegen()->DoDeferredAllocate(instr_); }
5337 LInstruction* instr() override { return instr_; }
5343 DeferredAllocate* deferred =
5344 new(zone()) DeferredAllocate(this, instr);
5346 Register result = ToRegister(instr->result());
5347 Register scratch = ToRegister(instr->temp1());
5348 Register scratch2 = ToRegister(instr->temp2());
5350 // Allocate memory for the object.
5351 AllocationFlags flags = TAG_OBJECT;
5352 if (instr->hydrogen()->MustAllocateDoubleAligned()) {
5353 flags = static_cast<AllocationFlags>(flags | DOUBLE_ALIGNMENT);
5355 if (instr->hydrogen()->IsOldSpaceAllocation()) {
5356 DCHECK(!instr->hydrogen()->IsNewSpaceAllocation());
5357 flags = static_cast<AllocationFlags>(flags | PRETENURE);
5360 if (instr->size()->IsConstantOperand()) {
5361 int32_t size = ToInteger32(LConstantOperand::cast(instr->size()));
5362 if (size <= Page::kMaxRegularHeapObjectSize) {
5363 __ Allocate(size, result, scratch, scratch2, deferred->entry(), flags);
5365 __ jmp(deferred->entry());
5368 Register size = ToRegister(instr->size());
5369 __ Allocate(size, result, scratch, scratch2, deferred->entry(), flags);
5372 __ bind(deferred->exit());
5374 if (instr->hydrogen()->MustPrefillWithFiller()) {
5375 STATIC_ASSERT(kHeapObjectTag == 1);
5376 if (instr->size()->IsConstantOperand()) {
5377 int32_t size = ToInteger32(LConstantOperand::cast(instr->size()));
5378 __ mov(scratch, Operand(size - kHeapObjectTag));
5380 __ sub(scratch, ToRegister(instr->size()), Operand(kHeapObjectTag));
5382 __ mov(scratch2, Operand(isolate()->factory()->one_pointer_filler_map()));
5385 __ sub(scratch, scratch, Operand(kPointerSize), SetCC);
5386 __ str(scratch2, MemOperand(result, scratch));
5392 void LCodeGen::DoDeferredAllocate(LAllocate* instr) {
5393 Register result = ToRegister(instr->result());
5395 // TODO(3095996): Get rid of this. For now, we need to make the
5396 // result register contain a valid pointer because it is already
5397 // contained in the register pointer map.
5398 __ mov(result, Operand(Smi::FromInt(0)));
5400 PushSafepointRegistersScope scope(this);
5401 if (instr->size()->IsRegister()) {
5402 Register size = ToRegister(instr->size());
5403 DCHECK(!size.is(result));
5407 int32_t size = ToInteger32(LConstantOperand::cast(instr->size()));
5408 if (size >= 0 && size <= Smi::kMaxValue) {
5409 __ Push(Smi::FromInt(size));
5411 // We should never get here at runtime => abort
5412 __ stop("invalid allocation size");
5417 int flags = AllocateDoubleAlignFlag::encode(
5418 instr->hydrogen()->MustAllocateDoubleAligned());
5419 if (instr->hydrogen()->IsOldSpaceAllocation()) {
5420 DCHECK(!instr->hydrogen()->IsNewSpaceAllocation());
5421 flags = AllocateTargetSpace::update(flags, OLD_SPACE);
5423 flags = AllocateTargetSpace::update(flags, NEW_SPACE);
5425 __ Push(Smi::FromInt(flags));
5427 CallRuntimeFromDeferred(
5428 Runtime::kAllocateInTargetSpace, 2, instr, instr->context());
5429 __ StoreToSafepointRegisterSlot(r0, result);
5433 void LCodeGen::DoToFastProperties(LToFastProperties* instr) {
5434 DCHECK(ToRegister(instr->value()).is(r0));
5436 CallRuntime(Runtime::kToFastProperties, 1, instr);
5440 void LCodeGen::DoRegExpLiteral(LRegExpLiteral* instr) {
5441 DCHECK(ToRegister(instr->context()).is(cp));
5443 // Registers will be used as follows:
5444 // r6 = literals array.
5445 // r1 = regexp literal.
5446 // r0 = regexp literal clone.
5447 // r2-5 are used as temporaries.
5448 int literal_offset =
5449 FixedArray::OffsetOfElementAt(instr->hydrogen()->literal_index());
5450 __ Move(r6, instr->hydrogen()->literals());
5451 __ ldr(r1, FieldMemOperand(r6, literal_offset));
5452 __ LoadRoot(ip, Heap::kUndefinedValueRootIndex);
5454 __ b(ne, &materialized);
5456 // Create regexp literal using runtime function
5457 // Result will be in r0.
5458 __ mov(r5, Operand(Smi::FromInt(instr->hydrogen()->literal_index())));
5459 __ mov(r4, Operand(instr->hydrogen()->pattern()));
5460 __ mov(r3, Operand(instr->hydrogen()->flags()));
5461 __ Push(r6, r5, r4, r3);
5462 CallRuntime(Runtime::kMaterializeRegExpLiteral, 4, instr);
5465 __ bind(&materialized);
5466 int size = JSRegExp::kSize + JSRegExp::kInObjectFieldCount * kPointerSize;
5467 Label allocated, runtime_allocate;
5469 __ Allocate(size, r0, r2, r3, &runtime_allocate, TAG_OBJECT);
5472 __ bind(&runtime_allocate);
5473 __ mov(r0, Operand(Smi::FromInt(size)));
5475 CallRuntime(Runtime::kAllocateInNewSpace, 1, instr);
5478 __ bind(&allocated);
5479 // Copy the content into the newly allocated memory.
5480 __ CopyFields(r0, r1, double_scratch0(), size / kPointerSize);
5484 void LCodeGen::DoFunctionLiteral(LFunctionLiteral* instr) {
5485 DCHECK(ToRegister(instr->context()).is(cp));
5486 // Use the fast case closure allocation code that allocates in new
5487 // space for nested functions that don't need literals cloning.
5488 bool pretenure = instr->hydrogen()->pretenure();
5489 if (!pretenure && instr->hydrogen()->has_no_literals()) {
5490 FastNewClosureStub stub(isolate(), instr->hydrogen()->language_mode(),
5491 instr->hydrogen()->kind());
5492 __ mov(r2, Operand(instr->hydrogen()->shared_info()));
5493 CallCode(stub.GetCode(), RelocInfo::CODE_TARGET, instr);
5495 __ mov(r2, Operand(instr->hydrogen()->shared_info()));
5496 __ mov(r1, Operand(pretenure ? factory()->true_value()
5497 : factory()->false_value()));
5498 __ Push(cp, r2, r1);
5499 CallRuntime(Runtime::kNewClosure, 3, instr);
5504 void LCodeGen::DoTypeof(LTypeof* instr) {
5505 DCHECK(ToRegister(instr->value()).is(r3));
5506 DCHECK(ToRegister(instr->result()).is(r0));
5508 Register value_register = ToRegister(instr->value());
5509 __ JumpIfNotSmi(value_register, &do_call);
5510 __ mov(r0, Operand(isolate()->factory()->number_string()));
5513 TypeofStub stub(isolate());
5514 CallCode(stub.GetCode(), RelocInfo::CODE_TARGET, instr);
5519 void LCodeGen::DoTypeofIsAndBranch(LTypeofIsAndBranch* instr) {
5520 Register input = ToRegister(instr->value());
5522 Condition final_branch_condition = EmitTypeofIs(instr->TrueLabel(chunk_),
5523 instr->FalseLabel(chunk_),
5525 instr->type_literal());
5526 if (final_branch_condition != kNoCondition) {
5527 EmitBranch(instr, final_branch_condition);
5532 Condition LCodeGen::EmitTypeofIs(Label* true_label,
5535 Handle<String> type_name) {
5536 Condition final_branch_condition = kNoCondition;
5537 Register scratch = scratch0();
5538 Factory* factory = isolate()->factory();
5539 if (String::Equals(type_name, factory->number_string())) {
5540 __ JumpIfSmi(input, true_label);
5541 __ ldr(scratch, FieldMemOperand(input, HeapObject::kMapOffset));
5542 __ CompareRoot(scratch, Heap::kHeapNumberMapRootIndex);
5543 final_branch_condition = eq;
5545 } else if (String::Equals(type_name, factory->string_string())) {
5546 __ JumpIfSmi(input, false_label);
5547 __ CompareObjectType(input, scratch, no_reg, FIRST_NONSTRING_TYPE);
5548 final_branch_condition = lt;
5550 } else if (String::Equals(type_name, factory->symbol_string())) {
5551 __ JumpIfSmi(input, false_label);
5552 __ CompareObjectType(input, scratch, no_reg, SYMBOL_TYPE);
5553 final_branch_condition = eq;
5555 } else if (String::Equals(type_name, factory->boolean_string())) {
5556 __ CompareRoot(input, Heap::kTrueValueRootIndex);
5557 __ b(eq, true_label);
5558 __ CompareRoot(input, Heap::kFalseValueRootIndex);
5559 final_branch_condition = eq;
5561 } else if (String::Equals(type_name, factory->undefined_string())) {
5562 __ CompareRoot(input, Heap::kUndefinedValueRootIndex);
5563 __ b(eq, true_label);
5564 __ JumpIfSmi(input, false_label);
5565 // Check for undetectable objects => true.
5566 __ ldr(scratch, FieldMemOperand(input, HeapObject::kMapOffset));
5567 __ ldrb(scratch, FieldMemOperand(scratch, Map::kBitFieldOffset));
5568 __ tst(scratch, Operand(1 << Map::kIsUndetectable));
5569 final_branch_condition = ne;
5571 } else if (String::Equals(type_name, factory->function_string())) {
5572 STATIC_ASSERT(NUM_OF_CALLABLE_SPEC_OBJECT_TYPES == 2);
5573 Register type_reg = scratch;
5574 __ JumpIfSmi(input, false_label);
5575 __ CompareObjectType(input, scratch, type_reg, JS_FUNCTION_TYPE);
5576 __ b(eq, true_label);
5577 __ cmp(type_reg, Operand(JS_FUNCTION_PROXY_TYPE));
5578 final_branch_condition = eq;
5580 } else if (String::Equals(type_name, factory->object_string())) {
5581 Register map = scratch;
5582 __ JumpIfSmi(input, false_label);
5583 __ CompareRoot(input, Heap::kNullValueRootIndex);
5584 __ b(eq, true_label);
5585 __ CheckObjectTypeRange(input,
5587 FIRST_NONCALLABLE_SPEC_OBJECT_TYPE,
5588 LAST_NONCALLABLE_SPEC_OBJECT_TYPE,
5590 // Check for undetectable objects => false.
5591 __ ldrb(scratch, FieldMemOperand(map, Map::kBitFieldOffset));
5592 __ tst(scratch, Operand(1 << Map::kIsUndetectable));
5593 final_branch_condition = eq;
5596 #define SIMD128_TYPE(TYPE, Type, type, lane_count, lane_type) \
5597 } else if (String::Equals(type_name, factory->type##_string())) { \
5598 __ JumpIfSmi(input, false_label); \
5599 __ ldr(scratch, FieldMemOperand(input, HeapObject::kMapOffset)); \
5600 __ CompareRoot(scratch, Heap::k##Type##MapRootIndex); \
5601 final_branch_condition = eq;
5602 SIMD128_TYPES(SIMD128_TYPE)
5610 return final_branch_condition;
5614 void LCodeGen::DoIsConstructCallAndBranch(LIsConstructCallAndBranch* instr) {
5615 Register temp1 = ToRegister(instr->temp());
5617 EmitIsConstructCall(temp1, scratch0());
5618 EmitBranch(instr, eq);
5622 void LCodeGen::EmitIsConstructCall(Register temp1, Register temp2) {
5623 DCHECK(!temp1.is(temp2));
5624 // Get the frame pointer for the calling frame.
5625 __ ldr(temp1, MemOperand(fp, StandardFrameConstants::kCallerFPOffset));
5627 // Skip the arguments adaptor frame if it exists.
5628 __ ldr(temp2, MemOperand(temp1, StandardFrameConstants::kContextOffset));
5629 __ cmp(temp2, Operand(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR)));
5630 __ ldr(temp1, MemOperand(temp1, StandardFrameConstants::kCallerFPOffset), eq);
5632 // Check the marker in the calling frame.
5633 __ ldr(temp1, MemOperand(temp1, StandardFrameConstants::kMarkerOffset));
5634 __ cmp(temp1, Operand(Smi::FromInt(StackFrame::CONSTRUCT)));
5638 void LCodeGen::EnsureSpaceForLazyDeopt(int space_needed) {
5639 if (!info()->IsStub()) {
5640 // Ensure that we have enough space after the previous lazy-bailout
5641 // instruction for patching the code here.
5642 int current_pc = masm()->pc_offset();
5643 if (current_pc < last_lazy_deopt_pc_ + space_needed) {
5644 // Block literal pool emission for duration of padding.
5645 Assembler::BlockConstPoolScope block_const_pool(masm());
5646 int padding_size = last_lazy_deopt_pc_ + space_needed - current_pc;
5647 DCHECK_EQ(0, padding_size % Assembler::kInstrSize);
5648 while (padding_size > 0) {
5650 padding_size -= Assembler::kInstrSize;
5654 last_lazy_deopt_pc_ = masm()->pc_offset();
5658 void LCodeGen::DoLazyBailout(LLazyBailout* instr) {
5659 last_lazy_deopt_pc_ = masm()->pc_offset();
5660 DCHECK(instr->HasEnvironment());
5661 LEnvironment* env = instr->environment();
5662 RegisterEnvironmentForDeoptimization(env, Safepoint::kLazyDeopt);
5663 safepoints_.RecordLazyDeoptimizationIndex(env->deoptimization_index());
5667 void LCodeGen::DoDeoptimize(LDeoptimize* instr) {
5668 Deoptimizer::BailoutType type = instr->hydrogen()->type();
5669 // TODO(danno): Stubs expect all deopts to be lazy for historical reasons (the
5670 // needed return address), even though the implementation of LAZY and EAGER is
5671 // now identical. When LAZY is eventually completely folded into EAGER, remove
5672 // the special case below.
5673 if (info()->IsStub() && type == Deoptimizer::EAGER) {
5674 type = Deoptimizer::LAZY;
5677 DeoptimizeIf(al, instr, instr->hydrogen()->reason(), type);
5681 void LCodeGen::DoDummy(LDummy* instr) {
5682 // Nothing to see here, move on!
5686 void LCodeGen::DoDummyUse(LDummyUse* instr) {
5687 // Nothing to see here, move on!
5691 void LCodeGen::DoDeferredStackCheck(LStackCheck* instr) {
5692 PushSafepointRegistersScope scope(this);
5693 LoadContextFromDeferred(instr->context());
5694 __ CallRuntimeSaveDoubles(Runtime::kStackGuard);
5695 RecordSafepointWithLazyDeopt(
5696 instr, RECORD_SAFEPOINT_WITH_REGISTERS_AND_NO_ARGUMENTS);
5697 DCHECK(instr->HasEnvironment());
5698 LEnvironment* env = instr->environment();
5699 safepoints_.RecordLazyDeoptimizationIndex(env->deoptimization_index());
5703 void LCodeGen::DoStackCheck(LStackCheck* instr) {
5704 class DeferredStackCheck final : public LDeferredCode {
5706 DeferredStackCheck(LCodeGen* codegen, LStackCheck* instr)
5707 : LDeferredCode(codegen), instr_(instr) { }
5708 void Generate() override { codegen()->DoDeferredStackCheck(instr_); }
5709 LInstruction* instr() override { return instr_; }
5712 LStackCheck* instr_;
5715 DCHECK(instr->HasEnvironment());
5716 LEnvironment* env = instr->environment();
5717 // There is no LLazyBailout instruction for stack-checks. We have to
5718 // prepare for lazy deoptimization explicitly here.
5719 if (instr->hydrogen()->is_function_entry()) {
5720 // Perform stack overflow check.
5722 __ LoadRoot(ip, Heap::kStackLimitRootIndex);
5723 __ cmp(sp, Operand(ip));
5725 Handle<Code> stack_check = isolate()->builtins()->StackCheck();
5726 PredictableCodeSizeScope predictable(masm());
5727 predictable.ExpectSize(CallCodeSize(stack_check, RelocInfo::CODE_TARGET));
5728 DCHECK(instr->context()->IsRegister());
5729 DCHECK(ToRegister(instr->context()).is(cp));
5730 CallCode(stack_check, RelocInfo::CODE_TARGET, instr);
5733 DCHECK(instr->hydrogen()->is_backwards_branch());
5734 // Perform stack overflow check if this goto needs it before jumping.
5735 DeferredStackCheck* deferred_stack_check =
5736 new(zone()) DeferredStackCheck(this, instr);
5737 __ LoadRoot(ip, Heap::kStackLimitRootIndex);
5738 __ cmp(sp, Operand(ip));
5739 __ b(lo, deferred_stack_check->entry());
5740 EnsureSpaceForLazyDeopt(Deoptimizer::patch_size());
5741 __ bind(instr->done_label());
5742 deferred_stack_check->SetExit(instr->done_label());
5743 RegisterEnvironmentForDeoptimization(env, Safepoint::kLazyDeopt);
5744 // Don't record a deoptimization index for the safepoint here.
5745 // This will be done explicitly when emitting call and the safepoint in
5746 // the deferred code.
5751 void LCodeGen::DoOsrEntry(LOsrEntry* instr) {
5752 // This is a pseudo-instruction that ensures that the environment here is
5753 // properly registered for deoptimization and records the assembler's PC
5755 LEnvironment* environment = instr->environment();
5757 // If the environment were already registered, we would have no way of
5758 // backpatching it with the spill slot operands.
5759 DCHECK(!environment->HasBeenRegistered());
5760 RegisterEnvironmentForDeoptimization(environment, Safepoint::kNoLazyDeopt);
5762 GenerateOsrPrologue();
5766 void LCodeGen::DoForInPrepareMap(LForInPrepareMap* instr) {
5768 DeoptimizeIf(eq, instr, Deoptimizer::kSmi);
5770 STATIC_ASSERT(FIRST_JS_PROXY_TYPE == FIRST_SPEC_OBJECT_TYPE);
5771 __ CompareObjectType(r0, r1, r1, LAST_JS_PROXY_TYPE);
5772 DeoptimizeIf(le, instr, Deoptimizer::kWrongInstanceType);
5774 Label use_cache, call_runtime;
5775 Register null_value = r5;
5776 __ LoadRoot(null_value, Heap::kNullValueRootIndex);
5777 __ CheckEnumCache(null_value, &call_runtime);
5779 __ ldr(r0, FieldMemOperand(r0, HeapObject::kMapOffset));
5782 // Get the set of properties to enumerate.
5783 __ bind(&call_runtime);
5785 CallRuntime(Runtime::kGetPropertyNamesFast, 1, instr);
5787 __ ldr(r1, FieldMemOperand(r0, HeapObject::kMapOffset));
5788 __ LoadRoot(ip, Heap::kMetaMapRootIndex);
5790 DeoptimizeIf(ne, instr, Deoptimizer::kWrongMap);
5791 __ bind(&use_cache);
5795 void LCodeGen::DoForInCacheArray(LForInCacheArray* instr) {
5796 Register map = ToRegister(instr->map());
5797 Register result = ToRegister(instr->result());
5798 Label load_cache, done;
5799 __ EnumLength(result, map);
5800 __ cmp(result, Operand(Smi::FromInt(0)));
5801 __ b(ne, &load_cache);
5802 __ mov(result, Operand(isolate()->factory()->empty_fixed_array()));
5805 __ bind(&load_cache);
5806 __ LoadInstanceDescriptors(map, result);
5808 FieldMemOperand(result, DescriptorArray::kEnumCacheOffset));
5810 FieldMemOperand(result, FixedArray::SizeFor(instr->idx())));
5811 __ cmp(result, Operand::Zero());
5812 DeoptimizeIf(eq, instr, Deoptimizer::kNoCache);
5818 void LCodeGen::DoCheckMapValue(LCheckMapValue* instr) {
5819 Register object = ToRegister(instr->value());
5820 Register map = ToRegister(instr->map());
5821 __ ldr(scratch0(), FieldMemOperand(object, HeapObject::kMapOffset));
5822 __ cmp(map, scratch0());
5823 DeoptimizeIf(ne, instr, Deoptimizer::kWrongMap);
5827 void LCodeGen::DoDeferredLoadMutableDouble(LLoadFieldByIndex* instr,
5831 PushSafepointRegistersScope scope(this);
5834 __ mov(cp, Operand::Zero());
5835 __ CallRuntimeSaveDoubles(Runtime::kLoadMutableDouble);
5836 RecordSafepointWithRegisters(
5837 instr->pointer_map(), 2, Safepoint::kNoLazyDeopt);
5838 __ StoreToSafepointRegisterSlot(r0, result);
5842 void LCodeGen::DoLoadFieldByIndex(LLoadFieldByIndex* instr) {
5843 class DeferredLoadMutableDouble final : public LDeferredCode {
5845 DeferredLoadMutableDouble(LCodeGen* codegen,
5846 LLoadFieldByIndex* instr,
5850 : LDeferredCode(codegen),
5856 void Generate() override {
5857 codegen()->DoDeferredLoadMutableDouble(instr_, result_, object_, index_);
5859 LInstruction* instr() override { return instr_; }
5862 LLoadFieldByIndex* instr_;
5868 Register object = ToRegister(instr->object());
5869 Register index = ToRegister(instr->index());
5870 Register result = ToRegister(instr->result());
5871 Register scratch = scratch0();
5873 DeferredLoadMutableDouble* deferred;
5874 deferred = new(zone()) DeferredLoadMutableDouble(
5875 this, instr, result, object, index);
5877 Label out_of_object, done;
5879 __ tst(index, Operand(Smi::FromInt(1)));
5880 __ b(ne, deferred->entry());
5881 __ mov(index, Operand(index, ASR, 1));
5883 __ cmp(index, Operand::Zero());
5884 __ b(lt, &out_of_object);
5886 __ add(scratch, object, Operand::PointerOffsetFromSmiKey(index));
5887 __ ldr(result, FieldMemOperand(scratch, JSObject::kHeaderSize));
5891 __ bind(&out_of_object);
5892 __ ldr(result, FieldMemOperand(object, JSObject::kPropertiesOffset));
5893 // Index is equal to negated out of object property index plus 1.
5894 STATIC_ASSERT(kSmiTag == 0 && kSmiTagSize < kPointerSizeLog2);
5895 __ sub(scratch, result, Operand::PointerOffsetFromSmiKey(index));
5896 __ ldr(result, FieldMemOperand(scratch,
5897 FixedArray::kHeaderSize - kPointerSize));
5898 __ bind(deferred->exit());
5903 void LCodeGen::DoStoreFrameContext(LStoreFrameContext* instr) {
5904 Register context = ToRegister(instr->context());
5905 __ str(context, MemOperand(fp, StandardFrameConstants::kContextOffset));
5909 void LCodeGen::DoAllocateBlockContext(LAllocateBlockContext* instr) {
5910 Handle<ScopeInfo> scope_info = instr->scope_info();
5911 __ Push(scope_info);
5912 __ push(ToRegister(instr->function()));
5913 CallRuntime(Runtime::kPushBlockContext, 2, instr);
5914 RecordSafepoint(Safepoint::kNoLazyDeopt);
5920 } // namespace internal