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.
7 #if V8_TARGET_ARCH_IA32
9 #include "src/base/bits.h"
10 #include "src/code-factory.h"
11 #include "src/code-stubs.h"
12 #include "src/codegen.h"
13 #include "src/cpu-profiler.h"
14 #include "src/deoptimizer.h"
15 #include "src/hydrogen-osr.h"
16 #include "src/ia32/lithium-codegen-ia32.h"
17 #include "src/ic/ic.h"
18 #include "src/ic/stub-cache.h"
23 // When invoking builtins, we need to record the safepoint in the middle of
24 // the invoke instruction sequence generated by the macro assembler.
25 class SafepointGenerator final : public CallWrapper {
27 SafepointGenerator(LCodeGen* codegen,
28 LPointerMap* pointers,
29 Safepoint::DeoptMode mode)
33 virtual ~SafepointGenerator() {}
35 void BeforeCall(int call_size) const override {}
37 void AfterCall() const override {
38 codegen_->RecordSafepoint(pointers_, deopt_mode_);
43 LPointerMap* pointers_;
44 Safepoint::DeoptMode deopt_mode_;
50 bool LCodeGen::GenerateCode() {
51 LPhase phase("Z_Code generation", chunk());
55 // Open a frame scope to indicate that there is a frame on the stack. The
56 // MANUAL indicates that the scope shouldn't actually generate code to set up
57 // the frame (that is done in GeneratePrologue).
58 FrameScope frame_scope(masm_, StackFrame::MANUAL);
60 support_aligned_spilled_doubles_ = info()->IsOptimizing();
62 dynamic_frame_alignment_ = info()->IsOptimizing() &&
63 ((chunk()->num_double_slots() > 2 &&
64 !chunk()->graph()->is_recursive()) ||
65 !info()->osr_ast_id().IsNone());
67 return GeneratePrologue() &&
69 GenerateDeferredCode() &&
70 GenerateJumpTable() &&
71 GenerateSafepointTable();
75 void LCodeGen::FinishCode(Handle<Code> code) {
77 code->set_stack_slots(GetStackSlotCount());
78 code->set_safepoint_table_offset(safepoints_.GetCodeOffset());
79 PopulateDeoptimizationData(code);
80 if (!info()->IsStub()) {
81 Deoptimizer::EnsureRelocSpaceForLazyDeoptimization(code);
87 void LCodeGen::MakeSureStackPagesMapped(int offset) {
88 const int kPageSize = 4 * KB;
89 for (offset -= kPageSize; offset > 0; offset -= kPageSize) {
90 __ mov(Operand(esp, offset), eax);
96 void LCodeGen::SaveCallerDoubles() {
97 DCHECK(info()->saves_caller_doubles());
98 DCHECK(NeedsEagerFrame());
99 Comment(";;; Save clobbered callee double registers");
101 BitVector* doubles = chunk()->allocated_double_registers();
102 BitVector::Iterator save_iterator(doubles);
103 while (!save_iterator.Done()) {
104 __ movsd(MemOperand(esp, count * kDoubleSize),
105 XMMRegister::FromAllocationIndex(save_iterator.Current()));
106 save_iterator.Advance();
112 void LCodeGen::RestoreCallerDoubles() {
113 DCHECK(info()->saves_caller_doubles());
114 DCHECK(NeedsEagerFrame());
115 Comment(";;; Restore clobbered callee double registers");
116 BitVector* doubles = chunk()->allocated_double_registers();
117 BitVector::Iterator save_iterator(doubles);
119 while (!save_iterator.Done()) {
120 __ movsd(XMMRegister::FromAllocationIndex(save_iterator.Current()),
121 MemOperand(esp, count * kDoubleSize));
122 save_iterator.Advance();
128 bool LCodeGen::GeneratePrologue() {
129 DCHECK(is_generating());
131 if (info()->IsOptimizing()) {
132 ProfileEntryHookStub::MaybeCallEntryHook(masm_);
135 if (strlen(FLAG_stop_at) > 0 &&
136 info_->function()->name()->IsUtf8EqualTo(CStrVector(FLAG_stop_at))) {
141 // Sloppy mode functions and builtins need to replace the receiver with the
142 // global proxy when called as functions (without an explicit receiver
144 if (is_sloppy(info()->language_mode()) && info()->MayUseThis() &&
145 !info()->is_native() && info()->scope()->has_this_declaration()) {
147 // +1 for return address.
148 int receiver_offset = (scope()->num_parameters() + 1) * kPointerSize;
149 __ mov(ecx, Operand(esp, receiver_offset));
151 __ cmp(ecx, isolate()->factory()->undefined_value());
152 __ j(not_equal, &ok, Label::kNear);
154 __ mov(ecx, GlobalObjectOperand());
155 __ mov(ecx, FieldOperand(ecx, GlobalObject::kGlobalProxyOffset));
157 __ mov(Operand(esp, receiver_offset), ecx);
162 if (support_aligned_spilled_doubles_ && dynamic_frame_alignment_) {
163 // Move state of dynamic frame alignment into edx.
164 __ Move(edx, Immediate(kNoAlignmentPadding));
166 Label do_not_pad, align_loop;
167 STATIC_ASSERT(kDoubleSize == 2 * kPointerSize);
168 // Align esp + 4 to a multiple of 2 * kPointerSize.
169 __ test(esp, Immediate(kPointerSize));
170 __ j(not_zero, &do_not_pad, Label::kNear);
171 __ push(Immediate(0));
173 __ mov(edx, Immediate(kAlignmentPaddingPushed));
174 // Copy arguments, receiver, and return address.
175 __ mov(ecx, Immediate(scope()->num_parameters() + 2));
177 __ bind(&align_loop);
178 __ mov(eax, Operand(ebx, 1 * kPointerSize));
179 __ mov(Operand(ebx, 0), eax);
180 __ add(Operand(ebx), Immediate(kPointerSize));
182 __ j(not_zero, &align_loop, Label::kNear);
183 __ mov(Operand(ebx, 0), Immediate(kAlignmentZapValue));
184 __ bind(&do_not_pad);
188 info()->set_prologue_offset(masm_->pc_offset());
189 if (NeedsEagerFrame()) {
190 DCHECK(!frame_is_built_);
191 frame_is_built_ = true;
192 if (info()->IsStub()) {
195 __ Prologue(info()->IsCodePreAgingActive());
197 info()->AddNoFrameRange(0, masm_->pc_offset());
200 if (info()->IsOptimizing() &&
201 dynamic_frame_alignment_ &&
203 __ test(esp, Immediate(kPointerSize));
204 __ Assert(zero, kFrameIsExpectedToBeAligned);
207 // Reserve space for the stack slots needed by the code.
208 int slots = GetStackSlotCount();
209 DCHECK(slots != 0 || !info()->IsOptimizing());
212 if (dynamic_frame_alignment_) {
215 __ push(Immediate(kNoAlignmentPadding));
218 if (FLAG_debug_code) {
219 __ sub(Operand(esp), Immediate(slots * kPointerSize));
221 MakeSureStackPagesMapped(slots * kPointerSize);
224 __ mov(Operand(eax), Immediate(slots));
227 __ mov(MemOperand(esp, eax, times_4, 0),
228 Immediate(kSlotsZapValue));
230 __ j(not_zero, &loop);
233 __ sub(Operand(esp), Immediate(slots * kPointerSize));
235 MakeSureStackPagesMapped(slots * kPointerSize);
239 if (support_aligned_spilled_doubles_) {
240 Comment(";;; Store dynamic frame alignment tag for spilled doubles");
241 // Store dynamic frame alignment state in the first local.
242 int offset = JavaScriptFrameConstants::kDynamicAlignmentStateOffset;
243 if (dynamic_frame_alignment_) {
244 __ mov(Operand(ebp, offset), edx);
246 __ mov(Operand(ebp, offset), Immediate(kNoAlignmentPadding));
251 if (info()->saves_caller_doubles()) SaveCallerDoubles();
254 // Possibly allocate a local context.
255 int heap_slots = info_->num_heap_slots() - Context::MIN_CONTEXT_SLOTS;
256 if (heap_slots > 0) {
257 Comment(";;; Allocate local context");
258 bool need_write_barrier = true;
259 // Argument to NewContext is the function, which is still in edi.
260 DCHECK(!info()->scope()->is_script_scope());
261 if (heap_slots <= FastNewContextStub::kMaximumSlots) {
262 FastNewContextStub stub(isolate(), heap_slots);
264 // Result of FastNewContextStub is always in new space.
265 need_write_barrier = false;
268 __ CallRuntime(Runtime::kNewFunctionContext, 1);
270 RecordSafepoint(Safepoint::kNoLazyDeopt);
271 // Context is returned in eax. It replaces the context passed to us.
272 // It's saved in the stack and kept live in esi.
274 __ mov(Operand(ebp, StandardFrameConstants::kContextOffset), eax);
276 // Copy parameters into context if necessary.
277 int num_parameters = scope()->num_parameters();
278 int first_parameter = scope()->has_this_declaration() ? -1 : 0;
279 for (int i = first_parameter; i < num_parameters; i++) {
280 Variable* var = (i == -1) ? scope()->receiver() : scope()->parameter(i);
281 if (var->IsContextSlot()) {
282 int parameter_offset = StandardFrameConstants::kCallerSPOffset +
283 (num_parameters - 1 - i) * kPointerSize;
284 // Load parameter from stack.
285 __ mov(eax, Operand(ebp, parameter_offset));
286 // Store it in the context.
287 int context_offset = Context::SlotOffset(var->index());
288 __ mov(Operand(esi, context_offset), eax);
289 // Update the write barrier. This clobbers eax and ebx.
290 if (need_write_barrier) {
291 __ RecordWriteContextSlot(esi,
296 } else if (FLAG_debug_code) {
298 __ JumpIfInNewSpace(esi, eax, &done, Label::kNear);
299 __ Abort(kExpectedNewSpaceObject);
304 Comment(";;; End allocate local context");
308 if (FLAG_trace && info()->IsOptimizing()) {
309 // We have not executed any compiled code yet, so esi still holds the
311 __ CallRuntime(Runtime::kTraceEnter, 0);
313 return !is_aborted();
317 void LCodeGen::GenerateOsrPrologue() {
318 // Generate the OSR entry prologue at the first unknown OSR value, or if there
319 // are none, at the OSR entrypoint instruction.
320 if (osr_pc_offset_ >= 0) return;
322 osr_pc_offset_ = masm()->pc_offset();
324 // Move state of dynamic frame alignment into edx.
325 __ Move(edx, Immediate(kNoAlignmentPadding));
327 if (support_aligned_spilled_doubles_ && dynamic_frame_alignment_) {
328 Label do_not_pad, align_loop;
329 // Align ebp + 4 to a multiple of 2 * kPointerSize.
330 __ test(ebp, Immediate(kPointerSize));
331 __ j(zero, &do_not_pad, Label::kNear);
332 __ push(Immediate(0));
334 __ mov(edx, Immediate(kAlignmentPaddingPushed));
336 // Move all parts of the frame over one word. The frame consists of:
337 // unoptimized frame slots, alignment state, context, frame pointer, return
338 // address, receiver, and the arguments.
339 __ mov(ecx, Immediate(scope()->num_parameters() +
340 5 + graph()->osr()->UnoptimizedFrameSlots()));
342 __ bind(&align_loop);
343 __ mov(eax, Operand(ebx, 1 * kPointerSize));
344 __ mov(Operand(ebx, 0), eax);
345 __ add(Operand(ebx), Immediate(kPointerSize));
347 __ j(not_zero, &align_loop, Label::kNear);
348 __ mov(Operand(ebx, 0), Immediate(kAlignmentZapValue));
349 __ sub(Operand(ebp), Immediate(kPointerSize));
350 __ bind(&do_not_pad);
353 // Save the first local, which is overwritten by the alignment state.
354 Operand alignment_loc = MemOperand(ebp, -3 * kPointerSize);
355 __ push(alignment_loc);
357 // Set the dynamic frame alignment state.
358 __ mov(alignment_loc, edx);
360 // Adjust the frame size, subsuming the unoptimized frame into the
362 int slots = GetStackSlotCount() - graph()->osr()->UnoptimizedFrameSlots();
364 __ sub(esp, Immediate((slots - 1) * kPointerSize));
368 void LCodeGen::GenerateBodyInstructionPre(LInstruction* instr) {
369 if (instr->IsCall()) {
370 EnsureSpaceForLazyDeopt(Deoptimizer::patch_size());
372 if (!instr->IsLazyBailout() && !instr->IsGap()) {
373 safepoints_.BumpLastLazySafepointIndex();
378 void LCodeGen::GenerateBodyInstructionPost(LInstruction* instr) { }
381 bool LCodeGen::GenerateJumpTable() {
382 if (!jump_table_.length()) return !is_aborted();
385 Comment(";;; -------------------- Jump table --------------------");
387 for (int i = 0; i < jump_table_.length(); i++) {
388 Deoptimizer::JumpTableEntry* table_entry = &jump_table_[i];
389 __ bind(&table_entry->label);
390 Address entry = table_entry->address;
391 DeoptComment(table_entry->deopt_info);
392 if (table_entry->needs_frame) {
393 DCHECK(!info()->saves_caller_doubles());
394 __ push(Immediate(ExternalReference::ForDeoptEntry(entry)));
395 __ call(&needs_frame);
397 if (info()->saves_caller_doubles()) RestoreCallerDoubles();
398 __ call(entry, RelocInfo::RUNTIME_ENTRY);
400 info()->LogDeoptCallPosition(masm()->pc_offset(),
401 table_entry->deopt_info.inlining_id);
403 if (needs_frame.is_linked()) {
404 __ bind(&needs_frame);
407 3: return address <-- esp
412 __ sub(esp, Immediate(kPointerSize)); // Reserve space for stub marker.
413 __ push(MemOperand(esp, kPointerSize)); // Copy return address.
414 __ push(MemOperand(esp, 3 * kPointerSize)); // Copy entry address.
421 0: entry address <-- esp
423 __ mov(MemOperand(esp, 4 * kPointerSize), ebp); // Save ebp.
425 __ mov(ebp, MemOperand(ebp, StandardFrameConstants::kContextOffset));
426 __ mov(MemOperand(esp, 3 * kPointerSize), ebp);
427 // Fill ebp with the right stack frame address.
428 __ lea(ebp, MemOperand(esp, 4 * kPointerSize));
429 // This variant of deopt can only be used with stubs. Since we don't
430 // have a function pointer to install in the stack frame that we're
431 // building, install a special marker there instead.
432 DCHECK(info()->IsStub());
433 __ mov(MemOperand(esp, 2 * kPointerSize),
434 Immediate(Smi::FromInt(StackFrame::STUB)));
441 0: entry address <-- esp
443 __ ret(0); // Call the continuation without clobbering registers.
445 return !is_aborted();
449 bool LCodeGen::GenerateDeferredCode() {
450 DCHECK(is_generating());
451 if (deferred_.length() > 0) {
452 for (int i = 0; !is_aborted() && i < deferred_.length(); i++) {
453 LDeferredCode* code = deferred_[i];
456 instructions_->at(code->instruction_index())->hydrogen_value();
457 RecordAndWritePosition(
458 chunk()->graph()->SourcePositionToScriptPosition(value->position()));
460 Comment(";;; <@%d,#%d> "
461 "-------------------- Deferred %s --------------------",
462 code->instruction_index(),
463 code->instr()->hydrogen_value()->id(),
464 code->instr()->Mnemonic());
465 __ bind(code->entry());
466 if (NeedsDeferredFrame()) {
467 Comment(";;; Build frame");
468 DCHECK(!frame_is_built_);
469 DCHECK(info()->IsStub());
470 frame_is_built_ = true;
471 // Build the frame in such a way that esi isn't trashed.
472 __ push(ebp); // Caller's frame pointer.
473 __ push(Operand(ebp, StandardFrameConstants::kContextOffset));
474 __ push(Immediate(Smi::FromInt(StackFrame::STUB)));
475 __ lea(ebp, Operand(esp, 2 * kPointerSize));
476 Comment(";;; Deferred code");
479 if (NeedsDeferredFrame()) {
480 __ bind(code->done());
481 Comment(";;; Destroy frame");
482 DCHECK(frame_is_built_);
483 frame_is_built_ = false;
487 __ jmp(code->exit());
491 // Deferred code is the last part of the instruction sequence. Mark
492 // the generated code as done unless we bailed out.
493 if (!is_aborted()) status_ = DONE;
494 return !is_aborted();
498 bool LCodeGen::GenerateSafepointTable() {
500 if (!info()->IsStub()) {
501 // For lazy deoptimization we need space to patch a call after every call.
502 // Ensure there is always space for such patching, even if the code ends
504 int target_offset = masm()->pc_offset() + Deoptimizer::patch_size();
505 while (masm()->pc_offset() < target_offset) {
509 safepoints_.Emit(masm(), GetStackSlotCount());
510 return !is_aborted();
514 Register LCodeGen::ToRegister(int index) const {
515 return Register::FromAllocationIndex(index);
519 XMMRegister LCodeGen::ToDoubleRegister(int index) const {
520 return XMMRegister::FromAllocationIndex(index);
524 Register LCodeGen::ToRegister(LOperand* op) const {
525 DCHECK(op->IsRegister());
526 return ToRegister(op->index());
530 XMMRegister LCodeGen::ToDoubleRegister(LOperand* op) const {
531 DCHECK(op->IsDoubleRegister());
532 return ToDoubleRegister(op->index());
536 int32_t LCodeGen::ToInteger32(LConstantOperand* op) const {
537 return ToRepresentation(op, Representation::Integer32());
541 int32_t LCodeGen::ToRepresentation(LConstantOperand* op,
542 const Representation& r) const {
543 HConstant* constant = chunk_->LookupConstant(op);
544 if (r.IsExternal()) {
545 return reinterpret_cast<int32_t>(
546 constant->ExternalReferenceValue().address());
548 int32_t value = constant->Integer32Value();
549 if (r.IsInteger32()) return value;
550 DCHECK(r.IsSmiOrTagged());
551 return reinterpret_cast<int32_t>(Smi::FromInt(value));
555 Handle<Object> LCodeGen::ToHandle(LConstantOperand* op) const {
556 HConstant* constant = chunk_->LookupConstant(op);
557 DCHECK(chunk_->LookupLiteralRepresentation(op).IsSmiOrTagged());
558 return constant->handle(isolate());
562 double LCodeGen::ToDouble(LConstantOperand* op) const {
563 HConstant* constant = chunk_->LookupConstant(op);
564 DCHECK(constant->HasDoubleValue());
565 return constant->DoubleValue();
569 ExternalReference LCodeGen::ToExternalReference(LConstantOperand* op) const {
570 HConstant* constant = chunk_->LookupConstant(op);
571 DCHECK(constant->HasExternalReferenceValue());
572 return constant->ExternalReferenceValue();
576 bool LCodeGen::IsInteger32(LConstantOperand* op) const {
577 return chunk_->LookupLiteralRepresentation(op).IsSmiOrInteger32();
581 bool LCodeGen::IsSmi(LConstantOperand* op) const {
582 return chunk_->LookupLiteralRepresentation(op).IsSmi();
586 static int ArgumentsOffsetWithoutFrame(int index) {
588 return -(index + 1) * kPointerSize + kPCOnStackSize;
592 Operand LCodeGen::ToOperand(LOperand* op) const {
593 if (op->IsRegister()) return Operand(ToRegister(op));
594 if (op->IsDoubleRegister()) return Operand(ToDoubleRegister(op));
595 DCHECK(op->IsStackSlot() || op->IsDoubleStackSlot());
596 if (NeedsEagerFrame()) {
597 return Operand(ebp, StackSlotOffset(op->index()));
599 // Retrieve parameter without eager stack-frame relative to the
601 return Operand(esp, ArgumentsOffsetWithoutFrame(op->index()));
606 Operand LCodeGen::HighOperand(LOperand* op) {
607 DCHECK(op->IsDoubleStackSlot());
608 if (NeedsEagerFrame()) {
609 return Operand(ebp, StackSlotOffset(op->index()) + kPointerSize);
611 // Retrieve parameter without eager stack-frame relative to the
614 esp, ArgumentsOffsetWithoutFrame(op->index()) + kPointerSize);
619 void LCodeGen::WriteTranslation(LEnvironment* environment,
620 Translation* translation) {
621 if (environment == NULL) return;
623 // The translation includes one command per value in the environment.
624 int translation_size = environment->translation_size();
626 WriteTranslation(environment->outer(), translation);
627 WriteTranslationFrame(environment, translation);
629 int object_index = 0;
630 int dematerialized_index = 0;
631 for (int i = 0; i < translation_size; ++i) {
632 LOperand* value = environment->values()->at(i);
634 environment, translation, value, environment->HasTaggedValueAt(i),
635 environment->HasUint32ValueAt(i), &object_index, &dematerialized_index);
640 void LCodeGen::AddToTranslation(LEnvironment* environment,
641 Translation* translation,
645 int* object_index_pointer,
646 int* dematerialized_index_pointer) {
647 if (op == LEnvironment::materialization_marker()) {
648 int object_index = (*object_index_pointer)++;
649 if (environment->ObjectIsDuplicateAt(object_index)) {
650 int dupe_of = environment->ObjectDuplicateOfAt(object_index);
651 translation->DuplicateObject(dupe_of);
654 int object_length = environment->ObjectLengthAt(object_index);
655 if (environment->ObjectIsArgumentsAt(object_index)) {
656 translation->BeginArgumentsObject(object_length);
658 translation->BeginCapturedObject(object_length);
660 int dematerialized_index = *dematerialized_index_pointer;
661 int env_offset = environment->translation_size() + dematerialized_index;
662 *dematerialized_index_pointer += object_length;
663 for (int i = 0; i < object_length; ++i) {
664 LOperand* value = environment->values()->at(env_offset + i);
665 AddToTranslation(environment,
668 environment->HasTaggedValueAt(env_offset + i),
669 environment->HasUint32ValueAt(env_offset + i),
670 object_index_pointer,
671 dematerialized_index_pointer);
676 if (op->IsStackSlot()) {
678 translation->StoreStackSlot(op->index());
679 } else if (is_uint32) {
680 translation->StoreUint32StackSlot(op->index());
682 translation->StoreInt32StackSlot(op->index());
684 } else if (op->IsDoubleStackSlot()) {
685 translation->StoreDoubleStackSlot(op->index());
686 } else if (op->IsRegister()) {
687 Register reg = ToRegister(op);
689 translation->StoreRegister(reg);
690 } else if (is_uint32) {
691 translation->StoreUint32Register(reg);
693 translation->StoreInt32Register(reg);
695 } else if (op->IsDoubleRegister()) {
696 XMMRegister reg = ToDoubleRegister(op);
697 translation->StoreDoubleRegister(reg);
698 } else if (op->IsConstantOperand()) {
699 HConstant* constant = chunk()->LookupConstant(LConstantOperand::cast(op));
700 int src_index = DefineDeoptimizationLiteral(constant->handle(isolate()));
701 translation->StoreLiteral(src_index);
708 void LCodeGen::CallCodeGeneric(Handle<Code> code,
709 RelocInfo::Mode mode,
711 SafepointMode safepoint_mode) {
712 DCHECK(instr != NULL);
714 RecordSafepointWithLazyDeopt(instr, safepoint_mode);
716 // Signal that we don't inline smi code before these stubs in the
717 // optimizing code generator.
718 if (code->kind() == Code::BINARY_OP_IC ||
719 code->kind() == Code::COMPARE_IC) {
725 void LCodeGen::CallCode(Handle<Code> code,
726 RelocInfo::Mode mode,
727 LInstruction* instr) {
728 CallCodeGeneric(code, mode, instr, RECORD_SIMPLE_SAFEPOINT);
732 void LCodeGen::CallRuntime(const Runtime::Function* fun,
735 SaveFPRegsMode save_doubles) {
736 DCHECK(instr != NULL);
737 DCHECK(instr->HasPointerMap());
739 __ CallRuntime(fun, argc, save_doubles);
741 RecordSafepointWithLazyDeopt(instr, RECORD_SIMPLE_SAFEPOINT);
743 DCHECK(info()->is_calling());
747 void LCodeGen::LoadContextFromDeferred(LOperand* context) {
748 if (context->IsRegister()) {
749 if (!ToRegister(context).is(esi)) {
750 __ mov(esi, ToRegister(context));
752 } else if (context->IsStackSlot()) {
753 __ mov(esi, ToOperand(context));
754 } else if (context->IsConstantOperand()) {
755 HConstant* constant =
756 chunk_->LookupConstant(LConstantOperand::cast(context));
757 __ LoadObject(esi, Handle<Object>::cast(constant->handle(isolate())));
763 void LCodeGen::CallRuntimeFromDeferred(Runtime::FunctionId id,
767 LoadContextFromDeferred(context);
769 __ CallRuntimeSaveDoubles(id);
770 RecordSafepointWithRegisters(
771 instr->pointer_map(), argc, Safepoint::kNoLazyDeopt);
773 DCHECK(info()->is_calling());
777 void LCodeGen::RegisterEnvironmentForDeoptimization(
778 LEnvironment* environment, Safepoint::DeoptMode mode) {
779 environment->set_has_been_used();
780 if (!environment->HasBeenRegistered()) {
781 // Physical stack frame layout:
782 // -x ............. -4 0 ..................................... y
783 // [incoming arguments] [spill slots] [pushed outgoing arguments]
785 // Layout of the environment:
786 // 0 ..................................................... size-1
787 // [parameters] [locals] [expression stack including arguments]
789 // Layout of the translation:
790 // 0 ........................................................ size - 1 + 4
791 // [expression stack including arguments] [locals] [4 words] [parameters]
792 // |>------------ translation_size ------------<|
795 int jsframe_count = 0;
796 for (LEnvironment* e = environment; e != NULL; e = e->outer()) {
798 if (e->frame_type() == JS_FUNCTION) {
802 Translation translation(&translations_, frame_count, jsframe_count, zone());
803 WriteTranslation(environment, &translation);
804 int deoptimization_index = deoptimizations_.length();
805 int pc_offset = masm()->pc_offset();
806 environment->Register(deoptimization_index,
808 (mode == Safepoint::kLazyDeopt) ? pc_offset : -1);
809 deoptimizations_.Add(environment, zone());
814 void LCodeGen::DeoptimizeIf(Condition cc, LInstruction* instr,
815 Deoptimizer::DeoptReason deopt_reason,
816 Deoptimizer::BailoutType bailout_type) {
817 LEnvironment* environment = instr->environment();
818 RegisterEnvironmentForDeoptimization(environment, Safepoint::kNoLazyDeopt);
819 DCHECK(environment->HasBeenRegistered());
820 int id = environment->deoptimization_index();
821 DCHECK(info()->IsOptimizing() || info()->IsStub());
823 Deoptimizer::GetDeoptimizationEntry(isolate(), id, bailout_type);
825 Abort(kBailoutWasNotPrepared);
829 if (DeoptEveryNTimes()) {
830 ExternalReference count = ExternalReference::stress_deopt_count(isolate());
834 __ mov(eax, Operand::StaticVariable(count));
835 __ sub(eax, Immediate(1));
836 __ j(not_zero, &no_deopt, Label::kNear);
837 if (FLAG_trap_on_deopt) __ int3();
838 __ mov(eax, Immediate(FLAG_deopt_every_n_times));
839 __ mov(Operand::StaticVariable(count), eax);
842 DCHECK(frame_is_built_);
843 __ call(entry, RelocInfo::RUNTIME_ENTRY);
845 __ mov(Operand::StaticVariable(count), eax);
850 if (info()->ShouldTrapOnDeopt()) {
852 if (cc != no_condition) __ j(NegateCondition(cc), &done, Label::kNear);
857 Deoptimizer::DeoptInfo deopt_info = MakeDeoptInfo(instr, deopt_reason);
859 DCHECK(info()->IsStub() || frame_is_built_);
860 if (cc == no_condition && frame_is_built_) {
861 DeoptComment(deopt_info);
862 __ call(entry, RelocInfo::RUNTIME_ENTRY);
863 info()->LogDeoptCallPosition(masm()->pc_offset(), deopt_info.inlining_id);
865 Deoptimizer::JumpTableEntry table_entry(entry, deopt_info, bailout_type,
867 // We often have several deopts to the same entry, reuse the last
868 // jump entry if this is the case.
869 if (FLAG_trace_deopt || isolate()->cpu_profiler()->is_profiling() ||
870 jump_table_.is_empty() ||
871 !table_entry.IsEquivalentTo(jump_table_.last())) {
872 jump_table_.Add(table_entry, zone());
874 if (cc == no_condition) {
875 __ jmp(&jump_table_.last().label);
877 __ j(cc, &jump_table_.last().label);
883 void LCodeGen::DeoptimizeIf(Condition cc, LInstruction* instr,
884 Deoptimizer::DeoptReason deopt_reason) {
885 Deoptimizer::BailoutType bailout_type = info()->IsStub()
887 : Deoptimizer::EAGER;
888 DeoptimizeIf(cc, instr, deopt_reason, bailout_type);
892 void LCodeGen::PopulateDeoptimizationData(Handle<Code> code) {
893 int length = deoptimizations_.length();
894 if (length == 0) return;
895 Handle<DeoptimizationInputData> data =
896 DeoptimizationInputData::New(isolate(), length, TENURED);
898 Handle<ByteArray> translations =
899 translations_.CreateByteArray(isolate()->factory());
900 data->SetTranslationByteArray(*translations);
901 data->SetInlinedFunctionCount(Smi::FromInt(inlined_function_count_));
902 data->SetOptimizationId(Smi::FromInt(info_->optimization_id()));
903 if (info_->IsOptimizing()) {
904 // Reference to shared function info does not change between phases.
905 AllowDeferredHandleDereference allow_handle_dereference;
906 data->SetSharedFunctionInfo(*info_->shared_info());
908 data->SetSharedFunctionInfo(Smi::FromInt(0));
910 data->SetWeakCellCache(Smi::FromInt(0));
912 Handle<FixedArray> literals =
913 factory()->NewFixedArray(deoptimization_literals_.length(), TENURED);
914 { AllowDeferredHandleDereference copy_handles;
915 for (int i = 0; i < deoptimization_literals_.length(); i++) {
916 literals->set(i, *deoptimization_literals_[i]);
918 data->SetLiteralArray(*literals);
921 data->SetOsrAstId(Smi::FromInt(info_->osr_ast_id().ToInt()));
922 data->SetOsrPcOffset(Smi::FromInt(osr_pc_offset_));
924 // Populate the deoptimization entries.
925 for (int i = 0; i < length; i++) {
926 LEnvironment* env = deoptimizations_[i];
927 data->SetAstId(i, env->ast_id());
928 data->SetTranslationIndex(i, Smi::FromInt(env->translation_index()));
929 data->SetArgumentsStackHeight(i,
930 Smi::FromInt(env->arguments_stack_height()));
931 data->SetPc(i, Smi::FromInt(env->pc_offset()));
933 code->set_deoptimization_data(*data);
937 void LCodeGen::PopulateDeoptimizationLiteralsWithInlinedFunctions() {
938 DCHECK_EQ(0, deoptimization_literals_.length());
939 for (auto function : chunk()->inlined_functions()) {
940 DefineDeoptimizationLiteral(function);
942 inlined_function_count_ = deoptimization_literals_.length();
946 void LCodeGen::RecordSafepointWithLazyDeopt(
947 LInstruction* instr, SafepointMode safepoint_mode) {
948 if (safepoint_mode == RECORD_SIMPLE_SAFEPOINT) {
949 RecordSafepoint(instr->pointer_map(), Safepoint::kLazyDeopt);
951 DCHECK(safepoint_mode == RECORD_SAFEPOINT_WITH_REGISTERS_AND_NO_ARGUMENTS);
952 RecordSafepointWithRegisters(
953 instr->pointer_map(), 0, Safepoint::kLazyDeopt);
958 void LCodeGen::RecordSafepoint(
959 LPointerMap* pointers,
960 Safepoint::Kind kind,
962 Safepoint::DeoptMode deopt_mode) {
963 DCHECK(kind == expected_safepoint_kind_);
964 const ZoneList<LOperand*>* operands = pointers->GetNormalizedOperands();
965 Safepoint safepoint =
966 safepoints_.DefineSafepoint(masm(), 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 mode) {
980 RecordSafepoint(pointers, Safepoint::kSimple, 0, mode);
984 void LCodeGen::RecordSafepoint(Safepoint::DeoptMode mode) {
985 LPointerMap empty_pointers(zone());
986 RecordSafepoint(&empty_pointers, mode);
990 void LCodeGen::RecordSafepointWithRegisters(LPointerMap* pointers,
992 Safepoint::DeoptMode mode) {
993 RecordSafepoint(pointers, Safepoint::kWithRegisters, arguments, mode);
997 void LCodeGen::RecordAndWritePosition(int position) {
998 if (position == RelocInfo::kNoPosition) return;
999 masm()->positions_recorder()->RecordPosition(position);
1000 masm()->positions_recorder()->WriteRecordedPositions();
1004 static const char* LabelType(LLabel* label) {
1005 if (label->is_loop_header()) return " (loop header)";
1006 if (label->is_osr_entry()) return " (OSR entry)";
1011 void LCodeGen::DoLabel(LLabel* label) {
1012 Comment(";;; <@%d,#%d> -------------------- B%d%s --------------------",
1013 current_instruction_,
1014 label->hydrogen_value()->id(),
1017 __ bind(label->label());
1018 current_block_ = label->block_id();
1023 void LCodeGen::DoParallelMove(LParallelMove* move) {
1024 resolver_.Resolve(move);
1028 void LCodeGen::DoGap(LGap* gap) {
1029 for (int i = LGap::FIRST_INNER_POSITION;
1030 i <= LGap::LAST_INNER_POSITION;
1032 LGap::InnerPosition inner_pos = static_cast<LGap::InnerPosition>(i);
1033 LParallelMove* move = gap->GetParallelMove(inner_pos);
1034 if (move != NULL) DoParallelMove(move);
1039 void LCodeGen::DoInstructionGap(LInstructionGap* instr) {
1044 void LCodeGen::DoParameter(LParameter* instr) {
1049 void LCodeGen::DoCallStub(LCallStub* instr) {
1050 DCHECK(ToRegister(instr->context()).is(esi));
1051 DCHECK(ToRegister(instr->result()).is(eax));
1052 switch (instr->hydrogen()->major_key()) {
1053 case CodeStub::RegExpExec: {
1054 RegExpExecStub stub(isolate());
1055 CallCode(stub.GetCode(), RelocInfo::CODE_TARGET, instr);
1058 case CodeStub::SubString: {
1059 SubStringStub stub(isolate());
1060 CallCode(stub.GetCode(), RelocInfo::CODE_TARGET, instr);
1063 case CodeStub::StringCompare: {
1064 StringCompareStub stub(isolate());
1065 CallCode(stub.GetCode(), RelocInfo::CODE_TARGET, instr);
1074 void LCodeGen::DoUnknownOSRValue(LUnknownOSRValue* instr) {
1075 GenerateOsrPrologue();
1079 void LCodeGen::DoModByPowerOf2I(LModByPowerOf2I* instr) {
1080 Register dividend = ToRegister(instr->dividend());
1081 int32_t divisor = instr->divisor();
1082 DCHECK(dividend.is(ToRegister(instr->result())));
1084 // Theoretically, a variation of the branch-free code for integer division by
1085 // a power of 2 (calculating the remainder via an additional multiplication
1086 // (which gets simplified to an 'and') and subtraction) should be faster, and
1087 // this is exactly what GCC and clang emit. Nevertheless, benchmarks seem to
1088 // indicate that positive dividends are heavily favored, so the branching
1089 // version performs better.
1090 HMod* hmod = instr->hydrogen();
1091 int32_t mask = divisor < 0 ? -(divisor + 1) : (divisor - 1);
1092 Label dividend_is_not_negative, done;
1093 if (hmod->CheckFlag(HValue::kLeftCanBeNegative)) {
1094 __ test(dividend, dividend);
1095 __ j(not_sign, ÷nd_is_not_negative, Label::kNear);
1096 // Note that this is correct even for kMinInt operands.
1098 __ and_(dividend, mask);
1100 if (hmod->CheckFlag(HValue::kBailoutOnMinusZero)) {
1101 DeoptimizeIf(zero, instr, Deoptimizer::kMinusZero);
1103 __ jmp(&done, Label::kNear);
1106 __ bind(÷nd_is_not_negative);
1107 __ and_(dividend, mask);
1112 void LCodeGen::DoModByConstI(LModByConstI* instr) {
1113 Register dividend = ToRegister(instr->dividend());
1114 int32_t divisor = instr->divisor();
1115 DCHECK(ToRegister(instr->result()).is(eax));
1118 DeoptimizeIf(no_condition, instr, Deoptimizer::kDivisionByZero);
1122 __ TruncatingDiv(dividend, Abs(divisor));
1123 __ imul(edx, edx, Abs(divisor));
1124 __ mov(eax, dividend);
1127 // Check for negative zero.
1128 HMod* hmod = instr->hydrogen();
1129 if (hmod->CheckFlag(HValue::kBailoutOnMinusZero)) {
1130 Label remainder_not_zero;
1131 __ j(not_zero, &remainder_not_zero, Label::kNear);
1132 __ cmp(dividend, Immediate(0));
1133 DeoptimizeIf(less, instr, Deoptimizer::kMinusZero);
1134 __ bind(&remainder_not_zero);
1139 void LCodeGen::DoModI(LModI* instr) {
1140 HMod* hmod = instr->hydrogen();
1142 Register left_reg = ToRegister(instr->left());
1143 DCHECK(left_reg.is(eax));
1144 Register right_reg = ToRegister(instr->right());
1145 DCHECK(!right_reg.is(eax));
1146 DCHECK(!right_reg.is(edx));
1147 Register result_reg = ToRegister(instr->result());
1148 DCHECK(result_reg.is(edx));
1151 // Check for x % 0, idiv would signal a divide error. We have to
1152 // deopt in this case because we can't return a NaN.
1153 if (hmod->CheckFlag(HValue::kCanBeDivByZero)) {
1154 __ test(right_reg, Operand(right_reg));
1155 DeoptimizeIf(zero, instr, Deoptimizer::kDivisionByZero);
1158 // Check for kMinInt % -1, idiv would signal a divide error. We
1159 // 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, kMinInt);
1163 __ j(not_equal, &no_overflow_possible, Label::kNear);
1164 __ cmp(right_reg, -1);
1165 if (hmod->CheckFlag(HValue::kBailoutOnMinusZero)) {
1166 DeoptimizeIf(equal, instr, Deoptimizer::kMinusZero);
1168 __ j(not_equal, &no_overflow_possible, Label::kNear);
1169 __ Move(result_reg, Immediate(0));
1170 __ jmp(&done, Label::kNear);
1172 __ bind(&no_overflow_possible);
1175 // Sign extend dividend in eax into edx:eax.
1178 // If we care about -0, test if the dividend is <0 and the result is 0.
1179 if (hmod->CheckFlag(HValue::kBailoutOnMinusZero)) {
1180 Label positive_left;
1181 __ test(left_reg, Operand(left_reg));
1182 __ j(not_sign, &positive_left, Label::kNear);
1184 __ test(result_reg, Operand(result_reg));
1185 DeoptimizeIf(zero, instr, Deoptimizer::kMinusZero);
1186 __ jmp(&done, Label::kNear);
1187 __ bind(&positive_left);
1194 void LCodeGen::DoDivByPowerOf2I(LDivByPowerOf2I* instr) {
1195 Register dividend = ToRegister(instr->dividend());
1196 int32_t divisor = instr->divisor();
1197 Register result = ToRegister(instr->result());
1198 DCHECK(divisor == kMinInt || base::bits::IsPowerOfTwo32(Abs(divisor)));
1199 DCHECK(!result.is(dividend));
1201 // Check for (0 / -x) that will produce negative zero.
1202 HDiv* hdiv = instr->hydrogen();
1203 if (hdiv->CheckFlag(HValue::kBailoutOnMinusZero) && divisor < 0) {
1204 __ test(dividend, dividend);
1205 DeoptimizeIf(zero, instr, Deoptimizer::kMinusZero);
1207 // Check for (kMinInt / -1).
1208 if (hdiv->CheckFlag(HValue::kCanOverflow) && divisor == -1) {
1209 __ cmp(dividend, kMinInt);
1210 DeoptimizeIf(zero, instr, Deoptimizer::kOverflow);
1212 // Deoptimize if remainder will not be 0.
1213 if (!hdiv->CheckFlag(HInstruction::kAllUsesTruncatingToInt32) &&
1214 divisor != 1 && divisor != -1) {
1215 int32_t mask = divisor < 0 ? -(divisor + 1) : (divisor - 1);
1216 __ test(dividend, Immediate(mask));
1217 DeoptimizeIf(not_zero, instr, Deoptimizer::kLostPrecision);
1219 __ Move(result, dividend);
1220 int32_t shift = WhichPowerOf2Abs(divisor);
1222 // The arithmetic shift is always OK, the 'if' is an optimization only.
1223 if (shift > 1) __ sar(result, 31);
1224 __ shr(result, 32 - shift);
1225 __ add(result, dividend);
1226 __ sar(result, shift);
1228 if (divisor < 0) __ neg(result);
1232 void LCodeGen::DoDivByConstI(LDivByConstI* instr) {
1233 Register dividend = ToRegister(instr->dividend());
1234 int32_t divisor = instr->divisor();
1235 DCHECK(ToRegister(instr->result()).is(edx));
1238 DeoptimizeIf(no_condition, instr, Deoptimizer::kDivisionByZero);
1242 // Check for (0 / -x) that will produce negative zero.
1243 HDiv* hdiv = instr->hydrogen();
1244 if (hdiv->CheckFlag(HValue::kBailoutOnMinusZero) && divisor < 0) {
1245 __ test(dividend, dividend);
1246 DeoptimizeIf(zero, instr, Deoptimizer::kMinusZero);
1249 __ TruncatingDiv(dividend, Abs(divisor));
1250 if (divisor < 0) __ neg(edx);
1252 if (!hdiv->CheckFlag(HInstruction::kAllUsesTruncatingToInt32)) {
1254 __ imul(eax, eax, divisor);
1255 __ sub(eax, dividend);
1256 DeoptimizeIf(not_equal, instr, Deoptimizer::kLostPrecision);
1261 // TODO(svenpanne) Refactor this to avoid code duplication with DoFlooringDivI.
1262 void LCodeGen::DoDivI(LDivI* instr) {
1263 HBinaryOperation* hdiv = instr->hydrogen();
1264 Register dividend = ToRegister(instr->dividend());
1265 Register divisor = ToRegister(instr->divisor());
1266 Register remainder = ToRegister(instr->temp());
1267 DCHECK(dividend.is(eax));
1268 DCHECK(remainder.is(edx));
1269 DCHECK(ToRegister(instr->result()).is(eax));
1270 DCHECK(!divisor.is(eax));
1271 DCHECK(!divisor.is(edx));
1274 if (hdiv->CheckFlag(HValue::kCanBeDivByZero)) {
1275 __ test(divisor, divisor);
1276 DeoptimizeIf(zero, instr, Deoptimizer::kDivisionByZero);
1279 // Check for (0 / -x) that will produce negative zero.
1280 if (hdiv->CheckFlag(HValue::kBailoutOnMinusZero)) {
1281 Label dividend_not_zero;
1282 __ test(dividend, dividend);
1283 __ j(not_zero, ÷nd_not_zero, Label::kNear);
1284 __ test(divisor, divisor);
1285 DeoptimizeIf(sign, instr, Deoptimizer::kMinusZero);
1286 __ bind(÷nd_not_zero);
1289 // Check for (kMinInt / -1).
1290 if (hdiv->CheckFlag(HValue::kCanOverflow)) {
1291 Label dividend_not_min_int;
1292 __ cmp(dividend, kMinInt);
1293 __ j(not_zero, ÷nd_not_min_int, Label::kNear);
1294 __ cmp(divisor, -1);
1295 DeoptimizeIf(zero, instr, Deoptimizer::kOverflow);
1296 __ bind(÷nd_not_min_int);
1299 // Sign extend to edx (= remainder).
1303 if (!hdiv->CheckFlag(HValue::kAllUsesTruncatingToInt32)) {
1304 // Deoptimize if remainder is not 0.
1305 __ test(remainder, remainder);
1306 DeoptimizeIf(not_zero, instr, Deoptimizer::kLostPrecision);
1311 void LCodeGen::DoFlooringDivByPowerOf2I(LFlooringDivByPowerOf2I* instr) {
1312 Register dividend = ToRegister(instr->dividend());
1313 int32_t divisor = instr->divisor();
1314 DCHECK(dividend.is(ToRegister(instr->result())));
1316 // If the divisor is positive, things are easy: There can be no deopts and we
1317 // can simply do an arithmetic right shift.
1318 if (divisor == 1) return;
1319 int32_t shift = WhichPowerOf2Abs(divisor);
1321 __ sar(dividend, shift);
1325 // If the divisor is negative, we have to negate and handle edge cases.
1327 if (instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero)) {
1328 DeoptimizeIf(zero, instr, Deoptimizer::kMinusZero);
1331 // Dividing by -1 is basically negation, unless we overflow.
1332 if (divisor == -1) {
1333 if (instr->hydrogen()->CheckFlag(HValue::kLeftCanBeMinInt)) {
1334 DeoptimizeIf(overflow, instr, Deoptimizer::kOverflow);
1339 // If the negation could not overflow, simply shifting is OK.
1340 if (!instr->hydrogen()->CheckFlag(HValue::kLeftCanBeMinInt)) {
1341 __ sar(dividend, shift);
1345 Label not_kmin_int, done;
1346 __ j(no_overflow, ¬_kmin_int, Label::kNear);
1347 __ mov(dividend, Immediate(kMinInt / divisor));
1348 __ jmp(&done, Label::kNear);
1349 __ bind(¬_kmin_int);
1350 __ sar(dividend, shift);
1355 void LCodeGen::DoFlooringDivByConstI(LFlooringDivByConstI* instr) {
1356 Register dividend = ToRegister(instr->dividend());
1357 int32_t divisor = instr->divisor();
1358 DCHECK(ToRegister(instr->result()).is(edx));
1361 DeoptimizeIf(no_condition, instr, Deoptimizer::kDivisionByZero);
1365 // Check for (0 / -x) that will produce negative zero.
1366 HMathFloorOfDiv* hdiv = instr->hydrogen();
1367 if (hdiv->CheckFlag(HValue::kBailoutOnMinusZero) && divisor < 0) {
1368 __ test(dividend, dividend);
1369 DeoptimizeIf(zero, instr, Deoptimizer::kMinusZero);
1372 // Easy case: We need no dynamic check for the dividend and the flooring
1373 // division is the same as the truncating division.
1374 if ((divisor > 0 && !hdiv->CheckFlag(HValue::kLeftCanBeNegative)) ||
1375 (divisor < 0 && !hdiv->CheckFlag(HValue::kLeftCanBePositive))) {
1376 __ TruncatingDiv(dividend, Abs(divisor));
1377 if (divisor < 0) __ neg(edx);
1381 // In the general case we may need to adjust before and after the truncating
1382 // division to get a flooring division.
1383 Register temp = ToRegister(instr->temp3());
1384 DCHECK(!temp.is(dividend) && !temp.is(eax) && !temp.is(edx));
1385 Label needs_adjustment, done;
1386 __ cmp(dividend, Immediate(0));
1387 __ j(divisor > 0 ? less : greater, &needs_adjustment, Label::kNear);
1388 __ TruncatingDiv(dividend, Abs(divisor));
1389 if (divisor < 0) __ neg(edx);
1390 __ jmp(&done, Label::kNear);
1391 __ bind(&needs_adjustment);
1392 __ lea(temp, Operand(dividend, divisor > 0 ? 1 : -1));
1393 __ TruncatingDiv(temp, Abs(divisor));
1394 if (divisor < 0) __ neg(edx);
1400 // TODO(svenpanne) Refactor this to avoid code duplication with DoDivI.
1401 void LCodeGen::DoFlooringDivI(LFlooringDivI* instr) {
1402 HBinaryOperation* hdiv = instr->hydrogen();
1403 Register dividend = ToRegister(instr->dividend());
1404 Register divisor = ToRegister(instr->divisor());
1405 Register remainder = ToRegister(instr->temp());
1406 Register result = ToRegister(instr->result());
1407 DCHECK(dividend.is(eax));
1408 DCHECK(remainder.is(edx));
1409 DCHECK(result.is(eax));
1410 DCHECK(!divisor.is(eax));
1411 DCHECK(!divisor.is(edx));
1414 if (hdiv->CheckFlag(HValue::kCanBeDivByZero)) {
1415 __ test(divisor, divisor);
1416 DeoptimizeIf(zero, instr, Deoptimizer::kDivisionByZero);
1419 // Check for (0 / -x) that will produce negative zero.
1420 if (hdiv->CheckFlag(HValue::kBailoutOnMinusZero)) {
1421 Label dividend_not_zero;
1422 __ test(dividend, dividend);
1423 __ j(not_zero, ÷nd_not_zero, Label::kNear);
1424 __ test(divisor, divisor);
1425 DeoptimizeIf(sign, instr, Deoptimizer::kMinusZero);
1426 __ bind(÷nd_not_zero);
1429 // Check for (kMinInt / -1).
1430 if (hdiv->CheckFlag(HValue::kCanOverflow)) {
1431 Label dividend_not_min_int;
1432 __ cmp(dividend, kMinInt);
1433 __ j(not_zero, ÷nd_not_min_int, Label::kNear);
1434 __ cmp(divisor, -1);
1435 DeoptimizeIf(zero, instr, Deoptimizer::kOverflow);
1436 __ bind(÷nd_not_min_int);
1439 // Sign extend to edx (= remainder).
1444 __ test(remainder, remainder);
1445 __ j(zero, &done, Label::kNear);
1446 __ xor_(remainder, divisor);
1447 __ sar(remainder, 31);
1448 __ add(result, remainder);
1453 void LCodeGen::DoMulI(LMulI* instr) {
1454 Register left = ToRegister(instr->left());
1455 LOperand* right = instr->right();
1457 if (instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero)) {
1458 __ mov(ToRegister(instr->temp()), left);
1461 if (right->IsConstantOperand()) {
1462 // Try strength reductions on the multiplication.
1463 // All replacement instructions are at most as long as the imul
1464 // and have better latency.
1465 int constant = ToInteger32(LConstantOperand::cast(right));
1466 if (constant == -1) {
1468 } else if (constant == 0) {
1469 __ xor_(left, Operand(left));
1470 } else if (constant == 2) {
1471 __ add(left, Operand(left));
1472 } else if (!instr->hydrogen()->CheckFlag(HValue::kCanOverflow)) {
1473 // If we know that the multiplication can't overflow, it's safe to
1474 // use instructions that don't set the overflow flag for the
1481 __ lea(left, Operand(left, left, times_2, 0));
1487 __ lea(left, Operand(left, left, times_4, 0));
1493 __ lea(left, Operand(left, left, times_8, 0));
1499 __ imul(left, left, constant);
1503 __ imul(left, left, constant);
1506 if (instr->hydrogen()->representation().IsSmi()) {
1509 __ imul(left, ToOperand(right));
1512 if (instr->hydrogen()->CheckFlag(HValue::kCanOverflow)) {
1513 DeoptimizeIf(overflow, instr, Deoptimizer::kOverflow);
1516 if (instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero)) {
1517 // Bail out if the result is supposed to be negative zero.
1519 __ test(left, Operand(left));
1520 __ j(not_zero, &done, Label::kNear);
1521 if (right->IsConstantOperand()) {
1522 if (ToInteger32(LConstantOperand::cast(right)) < 0) {
1523 DeoptimizeIf(no_condition, instr, Deoptimizer::kMinusZero);
1524 } else if (ToInteger32(LConstantOperand::cast(right)) == 0) {
1525 __ cmp(ToRegister(instr->temp()), Immediate(0));
1526 DeoptimizeIf(less, instr, Deoptimizer::kMinusZero);
1529 // Test the non-zero operand for negative sign.
1530 __ or_(ToRegister(instr->temp()), ToOperand(right));
1531 DeoptimizeIf(sign, instr, Deoptimizer::kMinusZero);
1538 void LCodeGen::DoBitI(LBitI* instr) {
1539 LOperand* left = instr->left();
1540 LOperand* right = instr->right();
1541 DCHECK(left->Equals(instr->result()));
1542 DCHECK(left->IsRegister());
1544 if (right->IsConstantOperand()) {
1545 int32_t right_operand =
1546 ToRepresentation(LConstantOperand::cast(right),
1547 instr->hydrogen()->representation());
1548 switch (instr->op()) {
1549 case Token::BIT_AND:
1550 __ and_(ToRegister(left), right_operand);
1553 __ or_(ToRegister(left), right_operand);
1555 case Token::BIT_XOR:
1556 if (right_operand == int32_t(~0)) {
1557 __ not_(ToRegister(left));
1559 __ xor_(ToRegister(left), right_operand);
1567 switch (instr->op()) {
1568 case Token::BIT_AND:
1569 __ and_(ToRegister(left), ToOperand(right));
1572 __ or_(ToRegister(left), ToOperand(right));
1574 case Token::BIT_XOR:
1575 __ xor_(ToRegister(left), ToOperand(right));
1585 void LCodeGen::DoShiftI(LShiftI* instr) {
1586 LOperand* left = instr->left();
1587 LOperand* right = instr->right();
1588 DCHECK(left->Equals(instr->result()));
1589 DCHECK(left->IsRegister());
1590 if (right->IsRegister()) {
1591 DCHECK(ToRegister(right).is(ecx));
1593 switch (instr->op()) {
1595 __ ror_cl(ToRegister(left));
1598 __ sar_cl(ToRegister(left));
1601 __ shr_cl(ToRegister(left));
1602 if (instr->can_deopt()) {
1603 __ test(ToRegister(left), ToRegister(left));
1604 DeoptimizeIf(sign, instr, Deoptimizer::kNegativeValue);
1608 __ shl_cl(ToRegister(left));
1615 int value = ToInteger32(LConstantOperand::cast(right));
1616 uint8_t shift_count = static_cast<uint8_t>(value & 0x1F);
1617 switch (instr->op()) {
1619 if (shift_count == 0 && instr->can_deopt()) {
1620 __ test(ToRegister(left), ToRegister(left));
1621 DeoptimizeIf(sign, instr, Deoptimizer::kNegativeValue);
1623 __ ror(ToRegister(left), shift_count);
1627 if (shift_count != 0) {
1628 __ sar(ToRegister(left), shift_count);
1632 if (shift_count != 0) {
1633 __ shr(ToRegister(left), shift_count);
1634 } else if (instr->can_deopt()) {
1635 __ test(ToRegister(left), ToRegister(left));
1636 DeoptimizeIf(sign, instr, Deoptimizer::kNegativeValue);
1640 if (shift_count != 0) {
1641 if (instr->hydrogen_value()->representation().IsSmi() &&
1642 instr->can_deopt()) {
1643 if (shift_count != 1) {
1644 __ shl(ToRegister(left), shift_count - 1);
1646 __ SmiTag(ToRegister(left));
1647 DeoptimizeIf(overflow, instr, Deoptimizer::kOverflow);
1649 __ shl(ToRegister(left), shift_count);
1661 void LCodeGen::DoSubI(LSubI* instr) {
1662 LOperand* left = instr->left();
1663 LOperand* right = instr->right();
1664 DCHECK(left->Equals(instr->result()));
1666 if (right->IsConstantOperand()) {
1667 __ sub(ToOperand(left),
1668 ToImmediate(right, instr->hydrogen()->representation()));
1670 __ sub(ToRegister(left), ToOperand(right));
1672 if (instr->hydrogen()->CheckFlag(HValue::kCanOverflow)) {
1673 DeoptimizeIf(overflow, instr, Deoptimizer::kOverflow);
1678 void LCodeGen::DoConstantI(LConstantI* instr) {
1679 __ Move(ToRegister(instr->result()), Immediate(instr->value()));
1683 void LCodeGen::DoConstantS(LConstantS* instr) {
1684 __ Move(ToRegister(instr->result()), Immediate(instr->value()));
1688 void LCodeGen::DoConstantD(LConstantD* instr) {
1689 uint64_t const bits = instr->bits();
1690 uint32_t const lower = static_cast<uint32_t>(bits);
1691 uint32_t const upper = static_cast<uint32_t>(bits >> 32);
1692 DCHECK(instr->result()->IsDoubleRegister());
1694 XMMRegister result = ToDoubleRegister(instr->result());
1696 __ xorps(result, result);
1698 Register temp = ToRegister(instr->temp());
1699 if (CpuFeatures::IsSupported(SSE4_1)) {
1700 CpuFeatureScope scope2(masm(), SSE4_1);
1702 __ Move(temp, Immediate(lower));
1703 __ movd(result, Operand(temp));
1704 __ Move(temp, Immediate(upper));
1705 __ pinsrd(result, Operand(temp), 1);
1707 __ xorps(result, result);
1708 __ Move(temp, Immediate(upper));
1709 __ pinsrd(result, Operand(temp), 1);
1712 __ Move(temp, Immediate(upper));
1713 __ movd(result, Operand(temp));
1714 __ psllq(result, 32);
1716 XMMRegister xmm_scratch = double_scratch0();
1717 __ Move(temp, Immediate(lower));
1718 __ movd(xmm_scratch, Operand(temp));
1719 __ orps(result, xmm_scratch);
1726 void LCodeGen::DoConstantE(LConstantE* instr) {
1727 __ lea(ToRegister(instr->result()), Operand::StaticVariable(instr->value()));
1731 void LCodeGen::DoConstantT(LConstantT* instr) {
1732 Register reg = ToRegister(instr->result());
1733 Handle<Object> object = instr->value(isolate());
1734 AllowDeferredHandleDereference smi_check;
1735 __ LoadObject(reg, object);
1739 void LCodeGen::DoMapEnumLength(LMapEnumLength* instr) {
1740 Register result = ToRegister(instr->result());
1741 Register map = ToRegister(instr->value());
1742 __ EnumLength(result, map);
1746 void LCodeGen::DoDateField(LDateField* instr) {
1747 Register object = ToRegister(instr->date());
1748 Register result = ToRegister(instr->result());
1749 Register scratch = ToRegister(instr->temp());
1750 Smi* index = instr->index();
1751 DCHECK(object.is(result));
1752 DCHECK(object.is(eax));
1754 if (index->value() == 0) {
1755 __ mov(result, FieldOperand(object, JSDate::kValueOffset));
1757 Label runtime, done;
1758 if (index->value() < JSDate::kFirstUncachedField) {
1759 ExternalReference stamp = ExternalReference::date_cache_stamp(isolate());
1760 __ mov(scratch, Operand::StaticVariable(stamp));
1761 __ cmp(scratch, FieldOperand(object, JSDate::kCacheStampOffset));
1762 __ j(not_equal, &runtime, Label::kNear);
1763 __ mov(result, FieldOperand(object, JSDate::kValueOffset +
1764 kPointerSize * index->value()));
1765 __ jmp(&done, Label::kNear);
1768 __ PrepareCallCFunction(2, scratch);
1769 __ mov(Operand(esp, 0), object);
1770 __ mov(Operand(esp, 1 * kPointerSize), Immediate(index));
1771 __ CallCFunction(ExternalReference::get_date_field_function(isolate()), 2);
1777 Operand LCodeGen::BuildSeqStringOperand(Register string,
1779 String::Encoding encoding) {
1780 if (index->IsConstantOperand()) {
1781 int offset = ToRepresentation(LConstantOperand::cast(index),
1782 Representation::Integer32());
1783 if (encoding == String::TWO_BYTE_ENCODING) {
1784 offset *= kUC16Size;
1786 STATIC_ASSERT(kCharSize == 1);
1787 return FieldOperand(string, SeqString::kHeaderSize + offset);
1789 return FieldOperand(
1790 string, ToRegister(index),
1791 encoding == String::ONE_BYTE_ENCODING ? times_1 : times_2,
1792 SeqString::kHeaderSize);
1796 void LCodeGen::DoSeqStringGetChar(LSeqStringGetChar* instr) {
1797 String::Encoding encoding = instr->hydrogen()->encoding();
1798 Register result = ToRegister(instr->result());
1799 Register string = ToRegister(instr->string());
1801 if (FLAG_debug_code) {
1803 __ mov(string, FieldOperand(string, HeapObject::kMapOffset));
1804 __ movzx_b(string, FieldOperand(string, Map::kInstanceTypeOffset));
1806 __ and_(string, Immediate(kStringRepresentationMask | kStringEncodingMask));
1807 static const uint32_t one_byte_seq_type = kSeqStringTag | kOneByteStringTag;
1808 static const uint32_t two_byte_seq_type = kSeqStringTag | kTwoByteStringTag;
1809 __ cmp(string, Immediate(encoding == String::ONE_BYTE_ENCODING
1810 ? one_byte_seq_type : two_byte_seq_type));
1811 __ Check(equal, kUnexpectedStringType);
1815 Operand operand = BuildSeqStringOperand(string, instr->index(), encoding);
1816 if (encoding == String::ONE_BYTE_ENCODING) {
1817 __ movzx_b(result, operand);
1819 __ movzx_w(result, operand);
1824 void LCodeGen::DoSeqStringSetChar(LSeqStringSetChar* instr) {
1825 String::Encoding encoding = instr->hydrogen()->encoding();
1826 Register string = ToRegister(instr->string());
1828 if (FLAG_debug_code) {
1829 Register value = ToRegister(instr->value());
1830 Register index = ToRegister(instr->index());
1831 static const uint32_t one_byte_seq_type = kSeqStringTag | kOneByteStringTag;
1832 static const uint32_t two_byte_seq_type = kSeqStringTag | kTwoByteStringTag;
1834 instr->hydrogen()->encoding() == String::ONE_BYTE_ENCODING
1835 ? one_byte_seq_type : two_byte_seq_type;
1836 __ EmitSeqStringSetCharCheck(string, index, value, encoding_mask);
1839 Operand operand = BuildSeqStringOperand(string, instr->index(), encoding);
1840 if (instr->value()->IsConstantOperand()) {
1841 int value = ToRepresentation(LConstantOperand::cast(instr->value()),
1842 Representation::Integer32());
1843 DCHECK_LE(0, value);
1844 if (encoding == String::ONE_BYTE_ENCODING) {
1845 DCHECK_LE(value, String::kMaxOneByteCharCode);
1846 __ mov_b(operand, static_cast<int8_t>(value));
1848 DCHECK_LE(value, String::kMaxUtf16CodeUnit);
1849 __ mov_w(operand, static_cast<int16_t>(value));
1852 Register value = ToRegister(instr->value());
1853 if (encoding == String::ONE_BYTE_ENCODING) {
1854 __ mov_b(operand, value);
1856 __ mov_w(operand, value);
1862 void LCodeGen::DoAddI(LAddI* instr) {
1863 LOperand* left = instr->left();
1864 LOperand* right = instr->right();
1866 if (LAddI::UseLea(instr->hydrogen()) && !left->Equals(instr->result())) {
1867 if (right->IsConstantOperand()) {
1868 int32_t offset = ToRepresentation(LConstantOperand::cast(right),
1869 instr->hydrogen()->representation());
1870 __ lea(ToRegister(instr->result()), MemOperand(ToRegister(left), offset));
1872 Operand address(ToRegister(left), ToRegister(right), times_1, 0);
1873 __ lea(ToRegister(instr->result()), address);
1876 if (right->IsConstantOperand()) {
1877 __ add(ToOperand(left),
1878 ToImmediate(right, instr->hydrogen()->representation()));
1880 __ add(ToRegister(left), ToOperand(right));
1882 if (instr->hydrogen()->CheckFlag(HValue::kCanOverflow)) {
1883 DeoptimizeIf(overflow, instr, Deoptimizer::kOverflow);
1889 void LCodeGen::DoMathMinMax(LMathMinMax* instr) {
1890 LOperand* left = instr->left();
1891 LOperand* right = instr->right();
1892 DCHECK(left->Equals(instr->result()));
1893 HMathMinMax::Operation operation = instr->hydrogen()->operation();
1894 if (instr->hydrogen()->representation().IsSmiOrInteger32()) {
1896 Condition condition = (operation == HMathMinMax::kMathMin)
1899 if (right->IsConstantOperand()) {
1900 Operand left_op = ToOperand(left);
1901 Immediate immediate = ToImmediate(LConstantOperand::cast(instr->right()),
1902 instr->hydrogen()->representation());
1903 __ cmp(left_op, immediate);
1904 __ j(condition, &return_left, Label::kNear);
1905 __ mov(left_op, immediate);
1907 Register left_reg = ToRegister(left);
1908 Operand right_op = ToOperand(right);
1909 __ cmp(left_reg, right_op);
1910 __ j(condition, &return_left, Label::kNear);
1911 __ mov(left_reg, right_op);
1913 __ bind(&return_left);
1915 DCHECK(instr->hydrogen()->representation().IsDouble());
1916 Label check_nan_left, check_zero, return_left, return_right;
1917 Condition condition = (operation == HMathMinMax::kMathMin) ? below : above;
1918 XMMRegister left_reg = ToDoubleRegister(left);
1919 XMMRegister right_reg = ToDoubleRegister(right);
1920 __ ucomisd(left_reg, right_reg);
1921 __ j(parity_even, &check_nan_left, Label::kNear); // At least one NaN.
1922 __ j(equal, &check_zero, Label::kNear); // left == right.
1923 __ j(condition, &return_left, Label::kNear);
1924 __ jmp(&return_right, Label::kNear);
1926 __ bind(&check_zero);
1927 XMMRegister xmm_scratch = double_scratch0();
1928 __ xorps(xmm_scratch, xmm_scratch);
1929 __ ucomisd(left_reg, xmm_scratch);
1930 __ j(not_equal, &return_left, Label::kNear); // left == right != 0.
1931 // At this point, both left and right are either 0 or -0.
1932 if (operation == HMathMinMax::kMathMin) {
1933 __ orpd(left_reg, right_reg);
1935 // Since we operate on +0 and/or -0, addsd and andsd have the same effect.
1936 __ addsd(left_reg, right_reg);
1938 __ jmp(&return_left, Label::kNear);
1940 __ bind(&check_nan_left);
1941 __ ucomisd(left_reg, left_reg); // NaN check.
1942 __ j(parity_even, &return_left, Label::kNear); // left == NaN.
1943 __ bind(&return_right);
1944 __ movaps(left_reg, right_reg);
1946 __ bind(&return_left);
1951 void LCodeGen::DoArithmeticD(LArithmeticD* instr) {
1952 XMMRegister left = ToDoubleRegister(instr->left());
1953 XMMRegister right = ToDoubleRegister(instr->right());
1954 XMMRegister result = ToDoubleRegister(instr->result());
1955 switch (instr->op()) {
1957 if (CpuFeatures::IsSupported(AVX)) {
1958 CpuFeatureScope scope(masm(), AVX);
1959 __ vaddsd(result, left, right);
1961 DCHECK(result.is(left));
1962 __ addsd(left, right);
1966 if (CpuFeatures::IsSupported(AVX)) {
1967 CpuFeatureScope scope(masm(), AVX);
1968 __ vsubsd(result, left, right);
1970 DCHECK(result.is(left));
1971 __ subsd(left, right);
1975 if (CpuFeatures::IsSupported(AVX)) {
1976 CpuFeatureScope scope(masm(), AVX);
1977 __ vmulsd(result, left, right);
1979 DCHECK(result.is(left));
1980 __ mulsd(left, right);
1984 if (CpuFeatures::IsSupported(AVX)) {
1985 CpuFeatureScope scope(masm(), AVX);
1986 __ vdivsd(result, left, right);
1988 DCHECK(result.is(left));
1989 __ divsd(left, right);
1991 // Don't delete this mov. It may improve performance on some CPUs,
1992 // when there is a (v)mulsd depending on the result
1993 __ movaps(result, result);
1996 // Pass two doubles as arguments on the stack.
1997 __ PrepareCallCFunction(4, eax);
1998 __ movsd(Operand(esp, 0 * kDoubleSize), left);
1999 __ movsd(Operand(esp, 1 * kDoubleSize), right);
2001 ExternalReference::mod_two_doubles_operation(isolate()),
2004 // Return value is in st(0) on ia32.
2005 // Store it into the result register.
2006 __ sub(Operand(esp), Immediate(kDoubleSize));
2007 __ fstp_d(Operand(esp, 0));
2008 __ movsd(result, Operand(esp, 0));
2009 __ add(Operand(esp), Immediate(kDoubleSize));
2019 void LCodeGen::DoArithmeticT(LArithmeticT* instr) {
2020 DCHECK(ToRegister(instr->context()).is(esi));
2021 DCHECK(ToRegister(instr->left()).is(edx));
2022 DCHECK(ToRegister(instr->right()).is(eax));
2023 DCHECK(ToRegister(instr->result()).is(eax));
2026 CodeFactory::BinaryOpIC(isolate(), instr->op(), instr->strength()).code();
2027 CallCode(code, RelocInfo::CODE_TARGET, instr);
2031 template<class InstrType>
2032 void LCodeGen::EmitBranch(InstrType instr, Condition cc) {
2033 int left_block = instr->TrueDestination(chunk_);
2034 int right_block = instr->FalseDestination(chunk_);
2036 int next_block = GetNextEmittedBlock();
2038 if (right_block == left_block || cc == no_condition) {
2039 EmitGoto(left_block);
2040 } else if (left_block == next_block) {
2041 __ j(NegateCondition(cc), chunk_->GetAssemblyLabel(right_block));
2042 } else if (right_block == next_block) {
2043 __ j(cc, chunk_->GetAssemblyLabel(left_block));
2045 __ j(cc, chunk_->GetAssemblyLabel(left_block));
2046 __ jmp(chunk_->GetAssemblyLabel(right_block));
2051 template<class InstrType>
2052 void LCodeGen::EmitFalseBranch(InstrType instr, Condition cc) {
2053 int false_block = instr->FalseDestination(chunk_);
2054 if (cc == no_condition) {
2055 __ jmp(chunk_->GetAssemblyLabel(false_block));
2057 __ j(cc, chunk_->GetAssemblyLabel(false_block));
2062 void LCodeGen::DoBranch(LBranch* instr) {
2063 Representation r = instr->hydrogen()->value()->representation();
2064 if (r.IsSmiOrInteger32()) {
2065 Register reg = ToRegister(instr->value());
2066 __ test(reg, Operand(reg));
2067 EmitBranch(instr, not_zero);
2068 } else if (r.IsDouble()) {
2069 DCHECK(!info()->IsStub());
2070 XMMRegister reg = ToDoubleRegister(instr->value());
2071 XMMRegister xmm_scratch = double_scratch0();
2072 __ xorps(xmm_scratch, xmm_scratch);
2073 __ ucomisd(reg, xmm_scratch);
2074 EmitBranch(instr, not_equal);
2076 DCHECK(r.IsTagged());
2077 Register reg = ToRegister(instr->value());
2078 HType type = instr->hydrogen()->value()->type();
2079 if (type.IsBoolean()) {
2080 DCHECK(!info()->IsStub());
2081 __ cmp(reg, factory()->true_value());
2082 EmitBranch(instr, equal);
2083 } else if (type.IsSmi()) {
2084 DCHECK(!info()->IsStub());
2085 __ test(reg, Operand(reg));
2086 EmitBranch(instr, not_equal);
2087 } else if (type.IsJSArray()) {
2088 DCHECK(!info()->IsStub());
2089 EmitBranch(instr, no_condition);
2090 } else if (type.IsHeapNumber()) {
2091 DCHECK(!info()->IsStub());
2092 XMMRegister xmm_scratch = double_scratch0();
2093 __ xorps(xmm_scratch, xmm_scratch);
2094 __ ucomisd(xmm_scratch, FieldOperand(reg, HeapNumber::kValueOffset));
2095 EmitBranch(instr, not_equal);
2096 } else if (type.IsString()) {
2097 DCHECK(!info()->IsStub());
2098 __ cmp(FieldOperand(reg, String::kLengthOffset), Immediate(0));
2099 EmitBranch(instr, not_equal);
2101 ToBooleanStub::Types expected = instr->hydrogen()->expected_input_types();
2102 if (expected.IsEmpty()) expected = ToBooleanStub::Types::Generic();
2104 if (expected.Contains(ToBooleanStub::UNDEFINED)) {
2105 // undefined -> false.
2106 __ cmp(reg, factory()->undefined_value());
2107 __ j(equal, instr->FalseLabel(chunk_));
2109 if (expected.Contains(ToBooleanStub::BOOLEAN)) {
2111 __ cmp(reg, factory()->true_value());
2112 __ j(equal, instr->TrueLabel(chunk_));
2114 __ cmp(reg, factory()->false_value());
2115 __ j(equal, instr->FalseLabel(chunk_));
2117 if (expected.Contains(ToBooleanStub::NULL_TYPE)) {
2119 __ cmp(reg, factory()->null_value());
2120 __ j(equal, instr->FalseLabel(chunk_));
2123 if (expected.Contains(ToBooleanStub::SMI)) {
2124 // Smis: 0 -> false, all other -> true.
2125 __ test(reg, Operand(reg));
2126 __ j(equal, instr->FalseLabel(chunk_));
2127 __ JumpIfSmi(reg, instr->TrueLabel(chunk_));
2128 } else if (expected.NeedsMap()) {
2129 // If we need a map later and have a Smi -> deopt.
2130 __ test(reg, Immediate(kSmiTagMask));
2131 DeoptimizeIf(zero, instr, Deoptimizer::kSmi);
2134 Register map = no_reg; // Keep the compiler happy.
2135 if (expected.NeedsMap()) {
2136 map = ToRegister(instr->temp());
2137 DCHECK(!map.is(reg));
2138 __ mov(map, FieldOperand(reg, HeapObject::kMapOffset));
2140 if (expected.CanBeUndetectable()) {
2141 // Undetectable -> false.
2142 __ test_b(FieldOperand(map, Map::kBitFieldOffset),
2143 1 << Map::kIsUndetectable);
2144 __ j(not_zero, instr->FalseLabel(chunk_));
2148 if (expected.Contains(ToBooleanStub::SPEC_OBJECT)) {
2149 // spec object -> true.
2150 __ CmpInstanceType(map, FIRST_SPEC_OBJECT_TYPE);
2151 __ j(above_equal, instr->TrueLabel(chunk_));
2154 if (expected.Contains(ToBooleanStub::STRING)) {
2155 // String value -> false iff empty.
2157 __ CmpInstanceType(map, FIRST_NONSTRING_TYPE);
2158 __ j(above_equal, ¬_string, Label::kNear);
2159 __ cmp(FieldOperand(reg, String::kLengthOffset), Immediate(0));
2160 __ j(not_zero, instr->TrueLabel(chunk_));
2161 __ jmp(instr->FalseLabel(chunk_));
2162 __ bind(¬_string);
2165 if (expected.Contains(ToBooleanStub::SYMBOL)) {
2166 // Symbol value -> true.
2167 __ CmpInstanceType(map, SYMBOL_TYPE);
2168 __ j(equal, instr->TrueLabel(chunk_));
2171 if (expected.Contains(ToBooleanStub::SIMD_VALUE)) {
2172 // SIMD value -> true.
2173 __ CmpInstanceType(map, FLOAT32X4_TYPE);
2174 __ j(equal, instr->TrueLabel(chunk_));
2177 if (expected.Contains(ToBooleanStub::HEAP_NUMBER)) {
2178 // heap number -> false iff +0, -0, or NaN.
2179 Label not_heap_number;
2180 __ cmp(FieldOperand(reg, HeapObject::kMapOffset),
2181 factory()->heap_number_map());
2182 __ j(not_equal, ¬_heap_number, Label::kNear);
2183 XMMRegister xmm_scratch = double_scratch0();
2184 __ xorps(xmm_scratch, xmm_scratch);
2185 __ ucomisd(xmm_scratch, FieldOperand(reg, HeapNumber::kValueOffset));
2186 __ j(zero, instr->FalseLabel(chunk_));
2187 __ jmp(instr->TrueLabel(chunk_));
2188 __ bind(¬_heap_number);
2191 if (!expected.IsGeneric()) {
2192 // We've seen something for the first time -> deopt.
2193 // This can only happen if we are not generic already.
2194 DeoptimizeIf(no_condition, instr, Deoptimizer::kUnexpectedObject);
2201 void LCodeGen::EmitGoto(int block) {
2202 if (!IsNextEmittedBlock(block)) {
2203 __ jmp(chunk_->GetAssemblyLabel(LookupDestination(block)));
2208 void LCodeGen::DoGoto(LGoto* instr) {
2209 EmitGoto(instr->block_id());
2213 Condition LCodeGen::TokenToCondition(Token::Value op, bool is_unsigned) {
2214 Condition cond = no_condition;
2217 case Token::EQ_STRICT:
2221 case Token::NE_STRICT:
2225 cond = is_unsigned ? below : less;
2228 cond = is_unsigned ? above : greater;
2231 cond = is_unsigned ? below_equal : less_equal;
2234 cond = is_unsigned ? above_equal : greater_equal;
2237 case Token::INSTANCEOF:
2245 void LCodeGen::DoCompareNumericAndBranch(LCompareNumericAndBranch* instr) {
2246 LOperand* left = instr->left();
2247 LOperand* right = instr->right();
2249 instr->is_double() ||
2250 instr->hydrogen()->left()->CheckFlag(HInstruction::kUint32) ||
2251 instr->hydrogen()->right()->CheckFlag(HInstruction::kUint32);
2252 Condition cc = TokenToCondition(instr->op(), is_unsigned);
2254 if (left->IsConstantOperand() && right->IsConstantOperand()) {
2255 // We can statically evaluate the comparison.
2256 double left_val = ToDouble(LConstantOperand::cast(left));
2257 double right_val = ToDouble(LConstantOperand::cast(right));
2258 int next_block = EvalComparison(instr->op(), left_val, right_val) ?
2259 instr->TrueDestination(chunk_) : instr->FalseDestination(chunk_);
2260 EmitGoto(next_block);
2262 if (instr->is_double()) {
2263 __ ucomisd(ToDoubleRegister(left), ToDoubleRegister(right));
2264 // Don't base result on EFLAGS when a NaN is involved. Instead
2265 // jump to the false block.
2266 __ j(parity_even, instr->FalseLabel(chunk_));
2268 if (right->IsConstantOperand()) {
2269 __ cmp(ToOperand(left),
2270 ToImmediate(right, instr->hydrogen()->representation()));
2271 } else if (left->IsConstantOperand()) {
2272 __ cmp(ToOperand(right),
2273 ToImmediate(left, instr->hydrogen()->representation()));
2274 // We commuted the operands, so commute the condition.
2275 cc = CommuteCondition(cc);
2277 __ cmp(ToRegister(left), ToOperand(right));
2280 EmitBranch(instr, cc);
2285 void LCodeGen::DoCmpObjectEqAndBranch(LCmpObjectEqAndBranch* instr) {
2286 Register left = ToRegister(instr->left());
2288 if (instr->right()->IsConstantOperand()) {
2289 Handle<Object> right = ToHandle(LConstantOperand::cast(instr->right()));
2290 __ CmpObject(left, right);
2292 Operand right = ToOperand(instr->right());
2293 __ cmp(left, right);
2295 EmitBranch(instr, equal);
2299 void LCodeGen::DoCmpHoleAndBranch(LCmpHoleAndBranch* instr) {
2300 if (instr->hydrogen()->representation().IsTagged()) {
2301 Register input_reg = ToRegister(instr->object());
2302 __ cmp(input_reg, factory()->the_hole_value());
2303 EmitBranch(instr, equal);
2307 XMMRegister input_reg = ToDoubleRegister(instr->object());
2308 __ ucomisd(input_reg, input_reg);
2309 EmitFalseBranch(instr, parity_odd);
2311 __ sub(esp, Immediate(kDoubleSize));
2312 __ movsd(MemOperand(esp, 0), input_reg);
2314 __ add(esp, Immediate(kDoubleSize));
2315 int offset = sizeof(kHoleNanUpper32);
2316 __ cmp(MemOperand(esp, -offset), Immediate(kHoleNanUpper32));
2317 EmitBranch(instr, equal);
2321 void LCodeGen::DoCompareMinusZeroAndBranch(LCompareMinusZeroAndBranch* instr) {
2322 Representation rep = instr->hydrogen()->value()->representation();
2323 DCHECK(!rep.IsInteger32());
2324 Register scratch = ToRegister(instr->temp());
2326 if (rep.IsDouble()) {
2327 XMMRegister value = ToDoubleRegister(instr->value());
2328 XMMRegister xmm_scratch = double_scratch0();
2329 __ xorps(xmm_scratch, xmm_scratch);
2330 __ ucomisd(xmm_scratch, value);
2331 EmitFalseBranch(instr, not_equal);
2332 __ movmskpd(scratch, value);
2333 __ test(scratch, Immediate(1));
2334 EmitBranch(instr, not_zero);
2336 Register value = ToRegister(instr->value());
2337 Handle<Map> map = masm()->isolate()->factory()->heap_number_map();
2338 __ CheckMap(value, map, instr->FalseLabel(chunk()), DO_SMI_CHECK);
2339 __ cmp(FieldOperand(value, HeapNumber::kExponentOffset),
2341 EmitFalseBranch(instr, no_overflow);
2342 __ cmp(FieldOperand(value, HeapNumber::kMantissaOffset),
2343 Immediate(0x00000000));
2344 EmitBranch(instr, equal);
2349 Condition LCodeGen::EmitIsObject(Register input,
2351 Label* is_not_object,
2353 __ JumpIfSmi(input, is_not_object);
2355 __ cmp(input, isolate()->factory()->null_value());
2356 __ j(equal, is_object);
2358 __ mov(temp1, FieldOperand(input, HeapObject::kMapOffset));
2359 // Undetectable objects behave like undefined.
2360 __ test_b(FieldOperand(temp1, Map::kBitFieldOffset),
2361 1 << Map::kIsUndetectable);
2362 __ j(not_zero, is_not_object);
2364 __ movzx_b(temp1, FieldOperand(temp1, Map::kInstanceTypeOffset));
2365 __ cmp(temp1, FIRST_NONCALLABLE_SPEC_OBJECT_TYPE);
2366 __ j(below, is_not_object);
2367 __ cmp(temp1, LAST_NONCALLABLE_SPEC_OBJECT_TYPE);
2372 void LCodeGen::DoIsObjectAndBranch(LIsObjectAndBranch* instr) {
2373 Register reg = ToRegister(instr->value());
2374 Register temp = ToRegister(instr->temp());
2376 Condition true_cond = EmitIsObject(
2377 reg, temp, instr->FalseLabel(chunk_), instr->TrueLabel(chunk_));
2379 EmitBranch(instr, true_cond);
2383 Condition LCodeGen::EmitIsString(Register input,
2385 Label* is_not_string,
2386 SmiCheck check_needed = INLINE_SMI_CHECK) {
2387 if (check_needed == INLINE_SMI_CHECK) {
2388 __ JumpIfSmi(input, is_not_string);
2391 Condition cond = masm_->IsObjectStringType(input, temp1, temp1);
2397 void LCodeGen::DoIsStringAndBranch(LIsStringAndBranch* instr) {
2398 Register reg = ToRegister(instr->value());
2399 Register temp = ToRegister(instr->temp());
2401 SmiCheck check_needed =
2402 instr->hydrogen()->value()->type().IsHeapObject()
2403 ? OMIT_SMI_CHECK : INLINE_SMI_CHECK;
2405 Condition true_cond = EmitIsString(
2406 reg, temp, instr->FalseLabel(chunk_), check_needed);
2408 EmitBranch(instr, true_cond);
2412 void LCodeGen::DoIsSmiAndBranch(LIsSmiAndBranch* instr) {
2413 Operand input = ToOperand(instr->value());
2415 __ test(input, Immediate(kSmiTagMask));
2416 EmitBranch(instr, zero);
2420 void LCodeGen::DoIsUndetectableAndBranch(LIsUndetectableAndBranch* instr) {
2421 Register input = ToRegister(instr->value());
2422 Register temp = ToRegister(instr->temp());
2424 if (!instr->hydrogen()->value()->type().IsHeapObject()) {
2425 STATIC_ASSERT(kSmiTag == 0);
2426 __ JumpIfSmi(input, instr->FalseLabel(chunk_));
2428 __ mov(temp, FieldOperand(input, HeapObject::kMapOffset));
2429 __ test_b(FieldOperand(temp, Map::kBitFieldOffset),
2430 1 << Map::kIsUndetectable);
2431 EmitBranch(instr, not_zero);
2435 static Condition ComputeCompareCondition(Token::Value op) {
2437 case Token::EQ_STRICT:
2447 return greater_equal;
2450 return no_condition;
2455 void LCodeGen::DoStringCompareAndBranch(LStringCompareAndBranch* instr) {
2456 Token::Value op = instr->op();
2459 CodeFactory::CompareIC(isolate(), op, Strength::WEAK).code();
2460 CallCode(ic, RelocInfo::CODE_TARGET, instr);
2462 Condition condition = ComputeCompareCondition(op);
2463 __ test(eax, Operand(eax));
2465 EmitBranch(instr, condition);
2469 static InstanceType TestType(HHasInstanceTypeAndBranch* instr) {
2470 InstanceType from = instr->from();
2471 InstanceType to = instr->to();
2472 if (from == FIRST_TYPE) return to;
2473 DCHECK(from == to || to == LAST_TYPE);
2478 static Condition BranchCondition(HHasInstanceTypeAndBranch* instr) {
2479 InstanceType from = instr->from();
2480 InstanceType to = instr->to();
2481 if (from == to) return equal;
2482 if (to == LAST_TYPE) return above_equal;
2483 if (from == FIRST_TYPE) return below_equal;
2489 void LCodeGen::DoHasInstanceTypeAndBranch(LHasInstanceTypeAndBranch* instr) {
2490 Register input = ToRegister(instr->value());
2491 Register temp = ToRegister(instr->temp());
2493 if (!instr->hydrogen()->value()->type().IsHeapObject()) {
2494 __ JumpIfSmi(input, instr->FalseLabel(chunk_));
2497 __ CmpObjectType(input, TestType(instr->hydrogen()), temp);
2498 EmitBranch(instr, BranchCondition(instr->hydrogen()));
2502 void LCodeGen::DoGetCachedArrayIndex(LGetCachedArrayIndex* instr) {
2503 Register input = ToRegister(instr->value());
2504 Register result = ToRegister(instr->result());
2506 __ AssertString(input);
2508 __ mov(result, FieldOperand(input, String::kHashFieldOffset));
2509 __ IndexFromHash(result, result);
2513 void LCodeGen::DoHasCachedArrayIndexAndBranch(
2514 LHasCachedArrayIndexAndBranch* instr) {
2515 Register input = ToRegister(instr->value());
2517 __ test(FieldOperand(input, String::kHashFieldOffset),
2518 Immediate(String::kContainsCachedArrayIndexMask));
2519 EmitBranch(instr, equal);
2523 // Branches to a label or falls through with the answer in the z flag. Trashes
2524 // the temp registers, but not the input.
2525 void LCodeGen::EmitClassOfTest(Label* is_true,
2527 Handle<String>class_name,
2531 DCHECK(!input.is(temp));
2532 DCHECK(!input.is(temp2));
2533 DCHECK(!temp.is(temp2));
2534 __ JumpIfSmi(input, is_false);
2536 if (String::Equals(isolate()->factory()->Function_string(), class_name)) {
2537 // Assuming the following assertions, we can use the same compares to test
2538 // for both being a function type and being in the object type range.
2539 STATIC_ASSERT(NUM_OF_CALLABLE_SPEC_OBJECT_TYPES == 2);
2540 STATIC_ASSERT(FIRST_NONCALLABLE_SPEC_OBJECT_TYPE ==
2541 FIRST_SPEC_OBJECT_TYPE + 1);
2542 STATIC_ASSERT(LAST_NONCALLABLE_SPEC_OBJECT_TYPE ==
2543 LAST_SPEC_OBJECT_TYPE - 1);
2544 STATIC_ASSERT(LAST_SPEC_OBJECT_TYPE == LAST_TYPE);
2545 __ CmpObjectType(input, FIRST_SPEC_OBJECT_TYPE, temp);
2546 __ j(below, is_false);
2547 __ j(equal, is_true);
2548 __ CmpInstanceType(temp, LAST_SPEC_OBJECT_TYPE);
2549 __ j(equal, is_true);
2551 // Faster code path to avoid two compares: subtract lower bound from the
2552 // actual type and do a signed compare with the width of the type range.
2553 __ mov(temp, FieldOperand(input, HeapObject::kMapOffset));
2554 __ movzx_b(temp2, FieldOperand(temp, Map::kInstanceTypeOffset));
2555 __ sub(Operand(temp2), Immediate(FIRST_NONCALLABLE_SPEC_OBJECT_TYPE));
2556 __ cmp(Operand(temp2), Immediate(LAST_NONCALLABLE_SPEC_OBJECT_TYPE -
2557 FIRST_NONCALLABLE_SPEC_OBJECT_TYPE));
2558 __ j(above, is_false);
2561 // Now we are in the FIRST-LAST_NONCALLABLE_SPEC_OBJECT_TYPE range.
2562 // Check if the constructor in the map is a function.
2563 __ GetMapConstructor(temp, temp, temp2);
2564 // Objects with a non-function constructor have class 'Object'.
2565 __ CmpInstanceType(temp2, JS_FUNCTION_TYPE);
2566 if (String::Equals(class_name, isolate()->factory()->Object_string())) {
2567 __ j(not_equal, is_true);
2569 __ j(not_equal, is_false);
2572 // temp now contains the constructor function. Grab the
2573 // instance class name from there.
2574 __ mov(temp, FieldOperand(temp, JSFunction::kSharedFunctionInfoOffset));
2575 __ mov(temp, FieldOperand(temp,
2576 SharedFunctionInfo::kInstanceClassNameOffset));
2577 // The class name we are testing against is internalized since it's a literal.
2578 // The name in the constructor is internalized because of the way the context
2579 // is booted. This routine isn't expected to work for random API-created
2580 // classes and it doesn't have to because you can't access it with natives
2581 // syntax. Since both sides are internalized it is sufficient to use an
2582 // identity comparison.
2583 __ cmp(temp, class_name);
2584 // End with the answer in the z flag.
2588 void LCodeGen::DoClassOfTestAndBranch(LClassOfTestAndBranch* instr) {
2589 Register input = ToRegister(instr->value());
2590 Register temp = ToRegister(instr->temp());
2591 Register temp2 = ToRegister(instr->temp2());
2593 Handle<String> class_name = instr->hydrogen()->class_name();
2595 EmitClassOfTest(instr->TrueLabel(chunk_), instr->FalseLabel(chunk_),
2596 class_name, input, temp, temp2);
2598 EmitBranch(instr, equal);
2602 void LCodeGen::DoCmpMapAndBranch(LCmpMapAndBranch* instr) {
2603 Register reg = ToRegister(instr->value());
2604 __ cmp(FieldOperand(reg, HeapObject::kMapOffset), instr->map());
2605 EmitBranch(instr, equal);
2609 void LCodeGen::DoInstanceOf(LInstanceOf* instr) {
2610 // Object and function are in fixed registers defined by the stub.
2611 DCHECK(ToRegister(instr->context()).is(esi));
2612 InstanceofStub stub(isolate(), InstanceofStub::kArgsInRegisters);
2613 CallCode(stub.GetCode(), RelocInfo::CODE_TARGET, instr);
2615 Label true_value, done;
2616 __ test(eax, Operand(eax));
2617 __ j(zero, &true_value, Label::kNear);
2618 __ mov(ToRegister(instr->result()), factory()->false_value());
2619 __ jmp(&done, Label::kNear);
2620 __ bind(&true_value);
2621 __ mov(ToRegister(instr->result()), factory()->true_value());
2626 void LCodeGen::DoInstanceOfKnownGlobal(LInstanceOfKnownGlobal* instr) {
2627 class DeferredInstanceOfKnownGlobal final : public LDeferredCode {
2629 DeferredInstanceOfKnownGlobal(LCodeGen* codegen,
2630 LInstanceOfKnownGlobal* instr)
2631 : LDeferredCode(codegen), instr_(instr) { }
2632 void Generate() override {
2633 codegen()->DoDeferredInstanceOfKnownGlobal(instr_, &map_check_);
2635 LInstruction* instr() override { return instr_; }
2636 Label* map_check() { return &map_check_; }
2638 LInstanceOfKnownGlobal* instr_;
2642 DeferredInstanceOfKnownGlobal* deferred;
2643 deferred = new(zone()) DeferredInstanceOfKnownGlobal(this, instr);
2645 Label done, false_result;
2646 Register object = ToRegister(instr->value());
2647 Register temp = ToRegister(instr->temp());
2649 // A Smi is not an instance of anything.
2650 __ JumpIfSmi(object, &false_result, Label::kNear);
2652 // This is the inlined call site instanceof cache. The two occurences of the
2653 // hole value will be patched to the last map/result pair generated by the
2656 Register map = ToRegister(instr->temp());
2657 __ mov(map, FieldOperand(object, HeapObject::kMapOffset));
2658 __ bind(deferred->map_check()); // Label for calculating code patching.
2659 Handle<Cell> cache_cell = factory()->NewCell(factory()->the_hole_value());
2660 __ cmp(map, Operand::ForCell(cache_cell)); // Patched to cached map.
2661 __ j(not_equal, &cache_miss, Label::kNear);
2662 __ mov(eax, factory()->the_hole_value()); // Patched to either true or false.
2663 __ jmp(&done, Label::kNear);
2665 // The inlined call site cache did not match. Check for null and string
2666 // before calling the deferred code.
2667 __ bind(&cache_miss);
2668 // Null is not an instance of anything.
2669 __ cmp(object, factory()->null_value());
2670 __ j(equal, &false_result, Label::kNear);
2672 // String values are not instances of anything.
2673 Condition is_string = masm_->IsObjectStringType(object, temp, temp);
2674 __ j(is_string, &false_result, Label::kNear);
2676 // Go to the deferred code.
2677 __ jmp(deferred->entry());
2679 __ bind(&false_result);
2680 __ mov(ToRegister(instr->result()), factory()->false_value());
2682 // Here result has either true or false. Deferred code also produces true or
2684 __ bind(deferred->exit());
2689 void LCodeGen::DoDeferredInstanceOfKnownGlobal(LInstanceOfKnownGlobal* instr,
2691 PushSafepointRegistersScope scope(this);
2693 InstanceofStub::Flags flags = InstanceofStub::kNoFlags;
2694 flags = static_cast<InstanceofStub::Flags>(
2695 flags | InstanceofStub::kArgsInRegisters);
2696 flags = static_cast<InstanceofStub::Flags>(
2697 flags | InstanceofStub::kCallSiteInlineCheck);
2698 flags = static_cast<InstanceofStub::Flags>(
2699 flags | InstanceofStub::kReturnTrueFalseObject);
2700 InstanceofStub stub(isolate(), flags);
2702 // Get the temp register reserved by the instruction. This needs to be a
2703 // register which is pushed last by PushSafepointRegisters as top of the
2704 // stack is used to pass the offset to the location of the map check to
2706 Register temp = ToRegister(instr->temp());
2707 DCHECK(MacroAssembler::SafepointRegisterStackIndex(temp) == 0);
2708 __ LoadHeapObject(InstanceofStub::right(), instr->function());
2709 static const int kAdditionalDelta = 13;
2710 int delta = masm_->SizeOfCodeGeneratedSince(map_check) + kAdditionalDelta;
2711 __ mov(temp, Immediate(delta));
2712 __ StoreToSafepointRegisterSlot(temp, temp);
2713 CallCodeGeneric(stub.GetCode(),
2714 RelocInfo::CODE_TARGET,
2716 RECORD_SAFEPOINT_WITH_REGISTERS_AND_NO_ARGUMENTS);
2717 // Get the deoptimization index of the LLazyBailout-environment that
2718 // corresponds to this instruction.
2719 LEnvironment* env = instr->GetDeferredLazyDeoptimizationEnvironment();
2720 safepoints_.RecordLazyDeoptimizationIndex(env->deoptimization_index());
2722 // Put the result value into the eax slot and restore all registers.
2723 __ StoreToSafepointRegisterSlot(eax, eax);
2727 void LCodeGen::DoCmpT(LCmpT* instr) {
2728 Token::Value op = instr->op();
2731 CodeFactory::CompareIC(isolate(), op, instr->strength()).code();
2732 CallCode(ic, RelocInfo::CODE_TARGET, instr);
2734 Condition condition = ComputeCompareCondition(op);
2735 Label true_value, done;
2736 __ test(eax, Operand(eax));
2737 __ j(condition, &true_value, Label::kNear);
2738 __ mov(ToRegister(instr->result()), factory()->false_value());
2739 __ jmp(&done, Label::kNear);
2740 __ bind(&true_value);
2741 __ mov(ToRegister(instr->result()), factory()->true_value());
2746 void LCodeGen::EmitReturn(LReturn* instr, bool dynamic_frame_alignment) {
2747 int extra_value_count = dynamic_frame_alignment ? 2 : 1;
2749 if (instr->has_constant_parameter_count()) {
2750 int parameter_count = ToInteger32(instr->constant_parameter_count());
2751 if (dynamic_frame_alignment && FLAG_debug_code) {
2753 (parameter_count + extra_value_count) * kPointerSize),
2754 Immediate(kAlignmentZapValue));
2755 __ Assert(equal, kExpectedAlignmentMarker);
2757 __ Ret((parameter_count + extra_value_count) * kPointerSize, ecx);
2759 DCHECK(info()->IsStub()); // Functions would need to drop one more value.
2760 Register reg = ToRegister(instr->parameter_count());
2761 // The argument count parameter is a smi
2763 Register return_addr_reg = reg.is(ecx) ? ebx : ecx;
2764 if (dynamic_frame_alignment && FLAG_debug_code) {
2765 DCHECK(extra_value_count == 2);
2766 __ cmp(Operand(esp, reg, times_pointer_size,
2767 extra_value_count * kPointerSize),
2768 Immediate(kAlignmentZapValue));
2769 __ Assert(equal, kExpectedAlignmentMarker);
2772 // emit code to restore stack based on instr->parameter_count()
2773 __ pop(return_addr_reg); // save return address
2774 if (dynamic_frame_alignment) {
2775 __ inc(reg); // 1 more for alignment
2778 __ shl(reg, kPointerSizeLog2);
2780 __ jmp(return_addr_reg);
2785 void LCodeGen::DoReturn(LReturn* instr) {
2786 if (FLAG_trace && info()->IsOptimizing()) {
2787 // Preserve the return value on the stack and rely on the runtime call
2788 // to return the value in the same register. We're leaving the code
2789 // managed by the register allocator and tearing down the frame, it's
2790 // safe to write to the context register.
2792 __ mov(esi, Operand(ebp, StandardFrameConstants::kContextOffset));
2793 __ CallRuntime(Runtime::kTraceExit, 1);
2795 if (info()->saves_caller_doubles()) RestoreCallerDoubles();
2796 if (dynamic_frame_alignment_) {
2797 // Fetch the state of the dynamic frame alignment.
2798 __ mov(edx, Operand(ebp,
2799 JavaScriptFrameConstants::kDynamicAlignmentStateOffset));
2801 int no_frame_start = -1;
2802 if (NeedsEagerFrame()) {
2805 no_frame_start = masm_->pc_offset();
2807 if (dynamic_frame_alignment_) {
2809 __ cmp(edx, Immediate(kNoAlignmentPadding));
2810 __ j(equal, &no_padding, Label::kNear);
2812 EmitReturn(instr, true);
2813 __ bind(&no_padding);
2816 EmitReturn(instr, false);
2817 if (no_frame_start != -1) {
2818 info()->AddNoFrameRange(no_frame_start, masm_->pc_offset());
2824 void LCodeGen::EmitVectorLoadICRegisters(T* instr) {
2825 Register vector_register = ToRegister(instr->temp_vector());
2826 Register slot_register = LoadWithVectorDescriptor::SlotRegister();
2827 DCHECK(vector_register.is(LoadWithVectorDescriptor::VectorRegister()));
2828 DCHECK(slot_register.is(eax));
2830 AllowDeferredHandleDereference vector_structure_check;
2831 Handle<TypeFeedbackVector> vector = instr->hydrogen()->feedback_vector();
2832 __ mov(vector_register, vector);
2833 // No need to allocate this register.
2834 FeedbackVectorICSlot slot = instr->hydrogen()->slot();
2835 int index = vector->GetIndex(slot);
2836 __ mov(slot_register, Immediate(Smi::FromInt(index)));
2841 void LCodeGen::EmitVectorStoreICRegisters(T* instr) {
2842 Register vector_register = ToRegister(instr->temp_vector());
2843 Register slot_register = ToRegister(instr->temp_slot());
2845 AllowDeferredHandleDereference vector_structure_check;
2846 Handle<TypeFeedbackVector> vector = instr->hydrogen()->feedback_vector();
2847 __ mov(vector_register, vector);
2848 FeedbackVectorICSlot slot = instr->hydrogen()->slot();
2849 int index = vector->GetIndex(slot);
2850 __ mov(slot_register, Immediate(Smi::FromInt(index)));
2854 void LCodeGen::DoLoadGlobalGeneric(LLoadGlobalGeneric* instr) {
2855 DCHECK(ToRegister(instr->context()).is(esi));
2856 DCHECK(ToRegister(instr->global_object())
2857 .is(LoadDescriptor::ReceiverRegister()));
2858 DCHECK(ToRegister(instr->result()).is(eax));
2860 __ mov(LoadDescriptor::NameRegister(), instr->name());
2861 EmitVectorLoadICRegisters<LLoadGlobalGeneric>(instr);
2863 CodeFactory::LoadICInOptimizedCode(isolate(), instr->typeof_mode(),
2864 SLOPPY, PREMONOMORPHIC).code();
2865 CallCode(ic, RelocInfo::CODE_TARGET, instr);
2869 void LCodeGen::DoLoadGlobalViaContext(LLoadGlobalViaContext* instr) {
2870 DCHECK(ToRegister(instr->context()).is(esi));
2871 DCHECK(ToRegister(instr->result()).is(eax));
2873 __ mov(LoadGlobalViaContextDescriptor::DepthRegister(),
2874 Immediate(Smi::FromInt(instr->depth())));
2875 __ mov(LoadGlobalViaContextDescriptor::SlotRegister(),
2876 Immediate(Smi::FromInt(instr->slot_index())));
2877 __ mov(LoadGlobalViaContextDescriptor::NameRegister(), instr->name());
2880 CodeFactory::LoadGlobalViaContext(isolate(), instr->depth()).code();
2881 CallCode(stub, RelocInfo::CODE_TARGET, instr);
2885 void LCodeGen::DoLoadContextSlot(LLoadContextSlot* instr) {
2886 Register context = ToRegister(instr->context());
2887 Register result = ToRegister(instr->result());
2888 __ mov(result, ContextOperand(context, instr->slot_index()));
2890 if (instr->hydrogen()->RequiresHoleCheck()) {
2891 __ cmp(result, factory()->the_hole_value());
2892 if (instr->hydrogen()->DeoptimizesOnHole()) {
2893 DeoptimizeIf(equal, instr, Deoptimizer::kHole);
2896 __ j(not_equal, &is_not_hole, Label::kNear);
2897 __ mov(result, factory()->undefined_value());
2898 __ bind(&is_not_hole);
2904 void LCodeGen::DoStoreContextSlot(LStoreContextSlot* instr) {
2905 Register context = ToRegister(instr->context());
2906 Register value = ToRegister(instr->value());
2908 Label skip_assignment;
2910 Operand target = ContextOperand(context, instr->slot_index());
2911 if (instr->hydrogen()->RequiresHoleCheck()) {
2912 __ cmp(target, factory()->the_hole_value());
2913 if (instr->hydrogen()->DeoptimizesOnHole()) {
2914 DeoptimizeIf(equal, instr, Deoptimizer::kHole);
2916 __ j(not_equal, &skip_assignment, Label::kNear);
2920 __ mov(target, value);
2921 if (instr->hydrogen()->NeedsWriteBarrier()) {
2922 SmiCheck check_needed =
2923 instr->hydrogen()->value()->type().IsHeapObject()
2924 ? OMIT_SMI_CHECK : INLINE_SMI_CHECK;
2925 Register temp = ToRegister(instr->temp());
2926 int offset = Context::SlotOffset(instr->slot_index());
2927 __ RecordWriteContextSlot(context,
2932 EMIT_REMEMBERED_SET,
2936 __ bind(&skip_assignment);
2940 void LCodeGen::DoLoadNamedField(LLoadNamedField* instr) {
2941 HObjectAccess access = instr->hydrogen()->access();
2942 int offset = access.offset();
2944 if (access.IsExternalMemory()) {
2945 Register result = ToRegister(instr->result());
2946 MemOperand operand = instr->object()->IsConstantOperand()
2947 ? MemOperand::StaticVariable(ToExternalReference(
2948 LConstantOperand::cast(instr->object())))
2949 : MemOperand(ToRegister(instr->object()), offset);
2950 __ Load(result, operand, access.representation());
2954 Register object = ToRegister(instr->object());
2955 if (instr->hydrogen()->representation().IsDouble()) {
2956 XMMRegister result = ToDoubleRegister(instr->result());
2957 __ movsd(result, FieldOperand(object, offset));
2961 Register result = ToRegister(instr->result());
2962 if (!access.IsInobject()) {
2963 __ mov(result, FieldOperand(object, JSObject::kPropertiesOffset));
2966 __ Load(result, FieldOperand(object, offset), access.representation());
2970 void LCodeGen::EmitPushTaggedOperand(LOperand* operand) {
2971 DCHECK(!operand->IsDoubleRegister());
2972 if (operand->IsConstantOperand()) {
2973 Handle<Object> object = ToHandle(LConstantOperand::cast(operand));
2974 AllowDeferredHandleDereference smi_check;
2975 if (object->IsSmi()) {
2976 __ Push(Handle<Smi>::cast(object));
2978 __ PushHeapObject(Handle<HeapObject>::cast(object));
2980 } else if (operand->IsRegister()) {
2981 __ push(ToRegister(operand));
2983 __ push(ToOperand(operand));
2988 void LCodeGen::DoLoadNamedGeneric(LLoadNamedGeneric* instr) {
2989 DCHECK(ToRegister(instr->context()).is(esi));
2990 DCHECK(ToRegister(instr->object()).is(LoadDescriptor::ReceiverRegister()));
2991 DCHECK(ToRegister(instr->result()).is(eax));
2993 __ mov(LoadDescriptor::NameRegister(), instr->name());
2994 EmitVectorLoadICRegisters<LLoadNamedGeneric>(instr);
2996 CodeFactory::LoadICInOptimizedCode(
2997 isolate(), NOT_INSIDE_TYPEOF, instr->hydrogen()->language_mode(),
2998 instr->hydrogen()->initialization_state()).code();
2999 CallCode(ic, RelocInfo::CODE_TARGET, instr);
3003 void LCodeGen::DoLoadFunctionPrototype(LLoadFunctionPrototype* instr) {
3004 Register function = ToRegister(instr->function());
3005 Register temp = ToRegister(instr->temp());
3006 Register result = ToRegister(instr->result());
3008 // Get the prototype or initial map from the function.
3010 FieldOperand(function, JSFunction::kPrototypeOrInitialMapOffset));
3012 // Check that the function has a prototype or an initial map.
3013 __ cmp(Operand(result), Immediate(factory()->the_hole_value()));
3014 DeoptimizeIf(equal, instr, Deoptimizer::kHole);
3016 // If the function does not have an initial map, we're done.
3018 __ CmpObjectType(result, MAP_TYPE, temp);
3019 __ j(not_equal, &done, Label::kNear);
3021 // Get the prototype from the initial map.
3022 __ mov(result, FieldOperand(result, Map::kPrototypeOffset));
3029 void LCodeGen::DoLoadRoot(LLoadRoot* instr) {
3030 Register result = ToRegister(instr->result());
3031 __ LoadRoot(result, instr->index());
3035 void LCodeGen::DoAccessArgumentsAt(LAccessArgumentsAt* instr) {
3036 Register arguments = ToRegister(instr->arguments());
3037 Register result = ToRegister(instr->result());
3038 if (instr->length()->IsConstantOperand() &&
3039 instr->index()->IsConstantOperand()) {
3040 int const_index = ToInteger32(LConstantOperand::cast(instr->index()));
3041 int const_length = ToInteger32(LConstantOperand::cast(instr->length()));
3042 int index = (const_length - const_index) + 1;
3043 __ mov(result, Operand(arguments, index * kPointerSize));
3045 Register length = ToRegister(instr->length());
3046 Operand index = ToOperand(instr->index());
3047 // There are two words between the frame pointer and the last argument.
3048 // Subtracting from length accounts for one of them add one more.
3049 __ sub(length, index);
3050 __ mov(result, Operand(arguments, length, times_4, kPointerSize));
3055 void LCodeGen::DoLoadKeyedExternalArray(LLoadKeyed* instr) {
3056 ElementsKind elements_kind = instr->elements_kind();
3057 LOperand* key = instr->key();
3058 if (!key->IsConstantOperand() &&
3059 ExternalArrayOpRequiresTemp(instr->hydrogen()->key()->representation(),
3061 __ SmiUntag(ToRegister(key));
3063 Operand operand(BuildFastArrayOperand(
3066 instr->hydrogen()->key()->representation(),
3068 instr->base_offset()));
3069 if (elements_kind == EXTERNAL_FLOAT32_ELEMENTS ||
3070 elements_kind == FLOAT32_ELEMENTS) {
3071 XMMRegister result(ToDoubleRegister(instr->result()));
3072 __ movss(result, operand);
3073 __ cvtss2sd(result, result);
3074 } else if (elements_kind == EXTERNAL_FLOAT64_ELEMENTS ||
3075 elements_kind == FLOAT64_ELEMENTS) {
3076 __ movsd(ToDoubleRegister(instr->result()), operand);
3078 Register result(ToRegister(instr->result()));
3079 switch (elements_kind) {
3080 case EXTERNAL_INT8_ELEMENTS:
3082 __ movsx_b(result, operand);
3084 case EXTERNAL_UINT8_CLAMPED_ELEMENTS:
3085 case EXTERNAL_UINT8_ELEMENTS:
3086 case UINT8_ELEMENTS:
3087 case UINT8_CLAMPED_ELEMENTS:
3088 __ movzx_b(result, operand);
3090 case EXTERNAL_INT16_ELEMENTS:
3091 case INT16_ELEMENTS:
3092 __ movsx_w(result, operand);
3094 case EXTERNAL_UINT16_ELEMENTS:
3095 case UINT16_ELEMENTS:
3096 __ movzx_w(result, operand);
3098 case EXTERNAL_INT32_ELEMENTS:
3099 case INT32_ELEMENTS:
3100 __ mov(result, operand);
3102 case EXTERNAL_UINT32_ELEMENTS:
3103 case UINT32_ELEMENTS:
3104 __ mov(result, operand);
3105 if (!instr->hydrogen()->CheckFlag(HInstruction::kUint32)) {
3106 __ test(result, Operand(result));
3107 DeoptimizeIf(negative, instr, Deoptimizer::kNegativeValue);
3110 case EXTERNAL_FLOAT32_ELEMENTS:
3111 case EXTERNAL_FLOAT64_ELEMENTS:
3112 case FLOAT32_ELEMENTS:
3113 case FLOAT64_ELEMENTS:
3114 case FAST_SMI_ELEMENTS:
3116 case FAST_DOUBLE_ELEMENTS:
3117 case FAST_HOLEY_SMI_ELEMENTS:
3118 case FAST_HOLEY_ELEMENTS:
3119 case FAST_HOLEY_DOUBLE_ELEMENTS:
3120 case DICTIONARY_ELEMENTS:
3121 case FAST_SLOPPY_ARGUMENTS_ELEMENTS:
3122 case SLOW_SLOPPY_ARGUMENTS_ELEMENTS:
3130 void LCodeGen::DoLoadKeyedFixedDoubleArray(LLoadKeyed* instr) {
3131 if (instr->hydrogen()->RequiresHoleCheck()) {
3132 Operand hole_check_operand = BuildFastArrayOperand(
3133 instr->elements(), instr->key(),
3134 instr->hydrogen()->key()->representation(),
3135 FAST_DOUBLE_ELEMENTS,
3136 instr->base_offset() + sizeof(kHoleNanLower32));
3137 __ cmp(hole_check_operand, Immediate(kHoleNanUpper32));
3138 DeoptimizeIf(equal, instr, Deoptimizer::kHole);
3141 Operand double_load_operand = BuildFastArrayOperand(
3144 instr->hydrogen()->key()->representation(),
3145 FAST_DOUBLE_ELEMENTS,
3146 instr->base_offset());
3147 XMMRegister result = ToDoubleRegister(instr->result());
3148 __ movsd(result, double_load_operand);
3152 void LCodeGen::DoLoadKeyedFixedArray(LLoadKeyed* instr) {
3153 Register result = ToRegister(instr->result());
3157 BuildFastArrayOperand(instr->elements(), instr->key(),
3158 instr->hydrogen()->key()->representation(),
3159 FAST_ELEMENTS, instr->base_offset()));
3161 // Check for the hole value.
3162 if (instr->hydrogen()->RequiresHoleCheck()) {
3163 if (IsFastSmiElementsKind(instr->hydrogen()->elements_kind())) {
3164 __ test(result, Immediate(kSmiTagMask));
3165 DeoptimizeIf(not_equal, instr, Deoptimizer::kNotASmi);
3167 __ cmp(result, factory()->the_hole_value());
3168 DeoptimizeIf(equal, instr, Deoptimizer::kHole);
3170 } else if (instr->hydrogen()->hole_mode() == CONVERT_HOLE_TO_UNDEFINED) {
3171 DCHECK(instr->hydrogen()->elements_kind() == FAST_HOLEY_ELEMENTS);
3173 __ cmp(result, factory()->the_hole_value());
3174 __ j(not_equal, &done);
3175 if (info()->IsStub()) {
3176 // A stub can safely convert the hole to undefined only if the array
3177 // protector cell contains (Smi) Isolate::kArrayProtectorValid. Otherwise
3178 // it needs to bail out.
3179 __ mov(result, isolate()->factory()->array_protector());
3180 __ cmp(FieldOperand(result, PropertyCell::kValueOffset),
3181 Immediate(Smi::FromInt(Isolate::kArrayProtectorValid)));
3182 DeoptimizeIf(not_equal, instr, Deoptimizer::kHole);
3184 __ mov(result, isolate()->factory()->undefined_value());
3190 void LCodeGen::DoLoadKeyed(LLoadKeyed* instr) {
3191 if (instr->is_typed_elements()) {
3192 DoLoadKeyedExternalArray(instr);
3193 } else if (instr->hydrogen()->representation().IsDouble()) {
3194 DoLoadKeyedFixedDoubleArray(instr);
3196 DoLoadKeyedFixedArray(instr);
3201 Operand LCodeGen::BuildFastArrayOperand(
3202 LOperand* elements_pointer,
3204 Representation key_representation,
3205 ElementsKind elements_kind,
3206 uint32_t base_offset) {
3207 Register elements_pointer_reg = ToRegister(elements_pointer);
3208 int element_shift_size = ElementsKindToShiftSize(elements_kind);
3209 int shift_size = element_shift_size;
3210 if (key->IsConstantOperand()) {
3211 int constant_value = ToInteger32(LConstantOperand::cast(key));
3212 if (constant_value & 0xF0000000) {
3213 Abort(kArrayIndexConstantValueTooBig);
3215 return Operand(elements_pointer_reg,
3216 ((constant_value) << shift_size)
3219 // Take the tag bit into account while computing the shift size.
3220 if (key_representation.IsSmi() && (shift_size >= 1)) {
3221 shift_size -= kSmiTagSize;
3223 ScaleFactor scale_factor = static_cast<ScaleFactor>(shift_size);
3224 return Operand(elements_pointer_reg,
3232 void LCodeGen::DoLoadKeyedGeneric(LLoadKeyedGeneric* instr) {
3233 DCHECK(ToRegister(instr->context()).is(esi));
3234 DCHECK(ToRegister(instr->object()).is(LoadDescriptor::ReceiverRegister()));
3235 DCHECK(ToRegister(instr->key()).is(LoadDescriptor::NameRegister()));
3237 if (instr->hydrogen()->HasVectorAndSlot()) {
3238 EmitVectorLoadICRegisters<LLoadKeyedGeneric>(instr);
3241 Handle<Code> ic = CodeFactory::KeyedLoadICInOptimizedCode(
3242 isolate(), instr->hydrogen()->language_mode(),
3243 instr->hydrogen()->initialization_state()).code();
3244 CallCode(ic, RelocInfo::CODE_TARGET, instr);
3248 void LCodeGen::DoArgumentsElements(LArgumentsElements* instr) {
3249 Register result = ToRegister(instr->result());
3251 if (instr->hydrogen()->from_inlined()) {
3252 __ lea(result, Operand(esp, -2 * kPointerSize));
3254 // Check for arguments adapter frame.
3255 Label done, adapted;
3256 __ mov(result, Operand(ebp, StandardFrameConstants::kCallerFPOffset));
3257 __ mov(result, Operand(result, StandardFrameConstants::kContextOffset));
3258 __ cmp(Operand(result),
3259 Immediate(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR)));
3260 __ j(equal, &adapted, Label::kNear);
3262 // No arguments adaptor frame.
3263 __ mov(result, Operand(ebp));
3264 __ jmp(&done, Label::kNear);
3266 // Arguments adaptor frame present.
3268 __ mov(result, Operand(ebp, StandardFrameConstants::kCallerFPOffset));
3270 // Result is the frame pointer for the frame if not adapted and for the real
3271 // frame below the adaptor frame if adapted.
3277 void LCodeGen::DoArgumentsLength(LArgumentsLength* instr) {
3278 Operand elem = ToOperand(instr->elements());
3279 Register result = ToRegister(instr->result());
3283 // If no arguments adaptor frame the number of arguments is fixed.
3285 __ mov(result, Immediate(scope()->num_parameters()));
3286 __ j(equal, &done, Label::kNear);
3288 // Arguments adaptor frame present. Get argument length from there.
3289 __ mov(result, Operand(ebp, StandardFrameConstants::kCallerFPOffset));
3290 __ mov(result, Operand(result,
3291 ArgumentsAdaptorFrameConstants::kLengthOffset));
3292 __ SmiUntag(result);
3294 // Argument length is in result register.
3299 void LCodeGen::DoWrapReceiver(LWrapReceiver* instr) {
3300 Register receiver = ToRegister(instr->receiver());
3301 Register function = ToRegister(instr->function());
3303 // If the receiver is null or undefined, we have to pass the global
3304 // object as a receiver to normal functions. Values have to be
3305 // passed unchanged to builtins and strict-mode functions.
3306 Label receiver_ok, global_object;
3307 Label::Distance dist = DeoptEveryNTimes() ? Label::kFar : Label::kNear;
3308 Register scratch = ToRegister(instr->temp());
3310 if (!instr->hydrogen()->known_function()) {
3311 // Do not transform the receiver to object for strict mode
3314 FieldOperand(function, JSFunction::kSharedFunctionInfoOffset));
3315 __ test_b(FieldOperand(scratch, SharedFunctionInfo::kStrictModeByteOffset),
3316 1 << SharedFunctionInfo::kStrictModeBitWithinByte);
3317 __ j(not_equal, &receiver_ok, dist);
3319 // Do not transform the receiver to object for builtins.
3320 __ test_b(FieldOperand(scratch, SharedFunctionInfo::kNativeByteOffset),
3321 1 << SharedFunctionInfo::kNativeBitWithinByte);
3322 __ j(not_equal, &receiver_ok, dist);
3325 // Normal function. Replace undefined or null with global receiver.
3326 __ cmp(receiver, factory()->null_value());
3327 __ j(equal, &global_object, Label::kNear);
3328 __ cmp(receiver, factory()->undefined_value());
3329 __ j(equal, &global_object, Label::kNear);
3331 // The receiver should be a JS object.
3332 __ test(receiver, Immediate(kSmiTagMask));
3333 DeoptimizeIf(equal, instr, Deoptimizer::kSmi);
3334 __ CmpObjectType(receiver, FIRST_SPEC_OBJECT_TYPE, scratch);
3335 DeoptimizeIf(below, instr, Deoptimizer::kNotAJavaScriptObject);
3337 __ jmp(&receiver_ok, Label::kNear);
3338 __ bind(&global_object);
3339 __ mov(receiver, FieldOperand(function, JSFunction::kContextOffset));
3340 const int global_offset = Context::SlotOffset(Context::GLOBAL_OBJECT_INDEX);
3341 __ mov(receiver, Operand(receiver, global_offset));
3342 const int proxy_offset = GlobalObject::kGlobalProxyOffset;
3343 __ mov(receiver, FieldOperand(receiver, proxy_offset));
3344 __ bind(&receiver_ok);
3348 void LCodeGen::DoApplyArguments(LApplyArguments* instr) {
3349 Register receiver = ToRegister(instr->receiver());
3350 Register function = ToRegister(instr->function());
3351 Register length = ToRegister(instr->length());
3352 Register elements = ToRegister(instr->elements());
3353 DCHECK(receiver.is(eax)); // Used for parameter count.
3354 DCHECK(function.is(edi)); // Required by InvokeFunction.
3355 DCHECK(ToRegister(instr->result()).is(eax));
3357 // Copy the arguments to this function possibly from the
3358 // adaptor frame below it.
3359 const uint32_t kArgumentsLimit = 1 * KB;
3360 __ cmp(length, kArgumentsLimit);
3361 DeoptimizeIf(above, instr, Deoptimizer::kTooManyArguments);
3364 __ mov(receiver, length);
3366 // Loop through the arguments pushing them onto the execution
3369 // length is a small non-negative integer, due to the test above.
3370 __ test(length, Operand(length));
3371 __ j(zero, &invoke, Label::kNear);
3373 __ push(Operand(elements, length, times_pointer_size, 1 * kPointerSize));
3375 __ j(not_zero, &loop);
3377 // Invoke the function.
3379 DCHECK(instr->HasPointerMap());
3380 LPointerMap* pointers = instr->pointer_map();
3381 SafepointGenerator safepoint_generator(
3382 this, pointers, Safepoint::kLazyDeopt);
3383 ParameterCount actual(eax);
3384 __ InvokeFunction(function, actual, CALL_FUNCTION, safepoint_generator);
3388 void LCodeGen::DoDebugBreak(LDebugBreak* instr) {
3393 void LCodeGen::DoPushArgument(LPushArgument* instr) {
3394 LOperand* argument = instr->value();
3395 EmitPushTaggedOperand(argument);
3399 void LCodeGen::DoDrop(LDrop* instr) {
3400 __ Drop(instr->count());
3404 void LCodeGen::DoThisFunction(LThisFunction* instr) {
3405 Register result = ToRegister(instr->result());
3406 __ mov(result, Operand(ebp, JavaScriptFrameConstants::kFunctionOffset));
3410 void LCodeGen::DoContext(LContext* instr) {
3411 Register result = ToRegister(instr->result());
3412 if (info()->IsOptimizing()) {
3413 __ mov(result, Operand(ebp, StandardFrameConstants::kContextOffset));
3415 // If there is no frame, the context must be in esi.
3416 DCHECK(result.is(esi));
3421 void LCodeGen::DoDeclareGlobals(LDeclareGlobals* instr) {
3422 DCHECK(ToRegister(instr->context()).is(esi));
3423 __ push(esi); // The context is the first argument.
3424 __ push(Immediate(instr->hydrogen()->pairs()));
3425 __ push(Immediate(Smi::FromInt(instr->hydrogen()->flags())));
3426 CallRuntime(Runtime::kDeclareGlobals, 3, instr);
3430 void LCodeGen::CallKnownFunction(Handle<JSFunction> function,
3431 int formal_parameter_count, int arity,
3432 LInstruction* instr) {
3433 bool dont_adapt_arguments =
3434 formal_parameter_count == SharedFunctionInfo::kDontAdaptArgumentsSentinel;
3435 bool can_invoke_directly =
3436 dont_adapt_arguments || formal_parameter_count == arity;
3438 Register function_reg = edi;
3440 if (can_invoke_directly) {
3442 __ mov(esi, FieldOperand(function_reg, JSFunction::kContextOffset));
3444 // Set eax to arguments count if adaption is not needed. Assumes that eax
3445 // is available to write to at this point.
3446 if (dont_adapt_arguments) {
3450 // Invoke function directly.
3451 if (function.is_identical_to(info()->closure())) {
3454 __ call(FieldOperand(function_reg, JSFunction::kCodeEntryOffset));
3456 RecordSafepointWithLazyDeopt(instr, RECORD_SIMPLE_SAFEPOINT);
3458 // We need to adapt arguments.
3459 LPointerMap* pointers = instr->pointer_map();
3460 SafepointGenerator generator(
3461 this, pointers, Safepoint::kLazyDeopt);
3462 ParameterCount count(arity);
3463 ParameterCount expected(formal_parameter_count);
3464 __ InvokeFunction(function_reg, expected, count, CALL_FUNCTION, generator);
3469 void LCodeGen::DoCallWithDescriptor(LCallWithDescriptor* instr) {
3470 DCHECK(ToRegister(instr->result()).is(eax));
3472 if (instr->hydrogen()->IsTailCall()) {
3473 if (NeedsEagerFrame()) __ leave();
3475 if (instr->target()->IsConstantOperand()) {
3476 LConstantOperand* target = LConstantOperand::cast(instr->target());
3477 Handle<Code> code = Handle<Code>::cast(ToHandle(target));
3478 __ jmp(code, RelocInfo::CODE_TARGET);
3480 DCHECK(instr->target()->IsRegister());
3481 Register target = ToRegister(instr->target());
3482 __ add(target, Immediate(Code::kHeaderSize - kHeapObjectTag));
3486 LPointerMap* pointers = instr->pointer_map();
3487 SafepointGenerator generator(this, pointers, Safepoint::kLazyDeopt);
3489 if (instr->target()->IsConstantOperand()) {
3490 LConstantOperand* target = LConstantOperand::cast(instr->target());
3491 Handle<Code> code = Handle<Code>::cast(ToHandle(target));
3492 generator.BeforeCall(__ CallSize(code, RelocInfo::CODE_TARGET));
3493 __ call(code, RelocInfo::CODE_TARGET);
3495 DCHECK(instr->target()->IsRegister());
3496 Register target = ToRegister(instr->target());
3497 generator.BeforeCall(__ CallSize(Operand(target)));
3498 __ add(target, Immediate(Code::kHeaderSize - kHeapObjectTag));
3501 generator.AfterCall();
3506 void LCodeGen::DoCallJSFunction(LCallJSFunction* instr) {
3507 DCHECK(ToRegister(instr->function()).is(edi));
3508 DCHECK(ToRegister(instr->result()).is(eax));
3510 if (instr->hydrogen()->pass_argument_count()) {
3511 __ mov(eax, instr->arity());
3515 __ mov(esi, FieldOperand(edi, JSFunction::kContextOffset));
3517 bool is_self_call = false;
3518 if (instr->hydrogen()->function()->IsConstant()) {
3519 HConstant* fun_const = HConstant::cast(instr->hydrogen()->function());
3520 Handle<JSFunction> jsfun =
3521 Handle<JSFunction>::cast(fun_const->handle(isolate()));
3522 is_self_call = jsfun.is_identical_to(info()->closure());
3528 __ call(FieldOperand(edi, JSFunction::kCodeEntryOffset));
3531 RecordSafepointWithLazyDeopt(instr, RECORD_SIMPLE_SAFEPOINT);
3535 void LCodeGen::DoDeferredMathAbsTaggedHeapNumber(LMathAbs* instr) {
3536 Register input_reg = ToRegister(instr->value());
3537 __ cmp(FieldOperand(input_reg, HeapObject::kMapOffset),
3538 factory()->heap_number_map());
3539 DeoptimizeIf(not_equal, instr, Deoptimizer::kNotAHeapNumber);
3541 Label slow, allocated, done;
3542 Register tmp = input_reg.is(eax) ? ecx : eax;
3543 Register tmp2 = tmp.is(ecx) ? edx : input_reg.is(ecx) ? edx : ecx;
3545 // Preserve the value of all registers.
3546 PushSafepointRegistersScope scope(this);
3548 __ mov(tmp, FieldOperand(input_reg, HeapNumber::kExponentOffset));
3549 // Check the sign of the argument. If the argument is positive, just
3550 // return it. We do not need to patch the stack since |input| and
3551 // |result| are the same register and |input| will be restored
3552 // unchanged by popping safepoint registers.
3553 __ test(tmp, Immediate(HeapNumber::kSignMask));
3554 __ j(zero, &done, Label::kNear);
3556 __ AllocateHeapNumber(tmp, tmp2, no_reg, &slow);
3557 __ jmp(&allocated, Label::kNear);
3559 // Slow case: Call the runtime system to do the number allocation.
3561 CallRuntimeFromDeferred(Runtime::kAllocateHeapNumber, 0,
3562 instr, instr->context());
3563 // Set the pointer to the new heap number in tmp.
3564 if (!tmp.is(eax)) __ mov(tmp, eax);
3565 // Restore input_reg after call to runtime.
3566 __ LoadFromSafepointRegisterSlot(input_reg, input_reg);
3568 __ bind(&allocated);
3569 __ mov(tmp2, FieldOperand(input_reg, HeapNumber::kExponentOffset));
3570 __ and_(tmp2, ~HeapNumber::kSignMask);
3571 __ mov(FieldOperand(tmp, HeapNumber::kExponentOffset), tmp2);
3572 __ mov(tmp2, FieldOperand(input_reg, HeapNumber::kMantissaOffset));
3573 __ mov(FieldOperand(tmp, HeapNumber::kMantissaOffset), tmp2);
3574 __ StoreToSafepointRegisterSlot(input_reg, tmp);
3580 void LCodeGen::EmitIntegerMathAbs(LMathAbs* instr) {
3581 Register input_reg = ToRegister(instr->value());
3582 __ test(input_reg, Operand(input_reg));
3584 __ j(not_sign, &is_positive, Label::kNear);
3585 __ neg(input_reg); // Sets flags.
3586 DeoptimizeIf(negative, instr, Deoptimizer::kOverflow);
3587 __ bind(&is_positive);
3591 void LCodeGen::DoMathAbs(LMathAbs* instr) {
3592 // Class for deferred case.
3593 class DeferredMathAbsTaggedHeapNumber final : public LDeferredCode {
3595 DeferredMathAbsTaggedHeapNumber(LCodeGen* codegen,
3597 : LDeferredCode(codegen), instr_(instr) { }
3598 void Generate() override {
3599 codegen()->DoDeferredMathAbsTaggedHeapNumber(instr_);
3601 LInstruction* instr() override { return instr_; }
3607 DCHECK(instr->value()->Equals(instr->result()));
3608 Representation r = instr->hydrogen()->value()->representation();
3611 XMMRegister scratch = double_scratch0();
3612 XMMRegister input_reg = ToDoubleRegister(instr->value());
3613 __ xorps(scratch, scratch);
3614 __ subsd(scratch, input_reg);
3615 __ andps(input_reg, scratch);
3616 } else if (r.IsSmiOrInteger32()) {
3617 EmitIntegerMathAbs(instr);
3618 } else { // Tagged case.
3619 DeferredMathAbsTaggedHeapNumber* deferred =
3620 new(zone()) DeferredMathAbsTaggedHeapNumber(this, instr);
3621 Register input_reg = ToRegister(instr->value());
3623 __ JumpIfNotSmi(input_reg, deferred->entry());
3624 EmitIntegerMathAbs(instr);
3625 __ bind(deferred->exit());
3630 void LCodeGen::DoMathFloor(LMathFloor* instr) {
3631 XMMRegister xmm_scratch = double_scratch0();
3632 Register output_reg = ToRegister(instr->result());
3633 XMMRegister input_reg = ToDoubleRegister(instr->value());
3635 if (CpuFeatures::IsSupported(SSE4_1)) {
3636 CpuFeatureScope scope(masm(), SSE4_1);
3637 if (instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero)) {
3638 // Deoptimize on negative zero.
3640 __ xorps(xmm_scratch, xmm_scratch); // Zero the register.
3641 __ ucomisd(input_reg, xmm_scratch);
3642 __ j(not_equal, &non_zero, Label::kNear);
3643 __ movmskpd(output_reg, input_reg);
3644 __ test(output_reg, Immediate(1));
3645 DeoptimizeIf(not_zero, instr, Deoptimizer::kMinusZero);
3648 __ roundsd(xmm_scratch, input_reg, kRoundDown);
3649 __ cvttsd2si(output_reg, Operand(xmm_scratch));
3650 // Overflow is signalled with minint.
3651 __ cmp(output_reg, 0x1);
3652 DeoptimizeIf(overflow, instr, Deoptimizer::kOverflow);
3654 Label negative_sign, done;
3655 // Deoptimize on unordered.
3656 __ xorps(xmm_scratch, xmm_scratch); // Zero the register.
3657 __ ucomisd(input_reg, xmm_scratch);
3658 DeoptimizeIf(parity_even, instr, Deoptimizer::kNaN);
3659 __ j(below, &negative_sign, Label::kNear);
3661 if (instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero)) {
3662 // Check for negative zero.
3663 Label positive_sign;
3664 __ j(above, &positive_sign, Label::kNear);
3665 __ movmskpd(output_reg, input_reg);
3666 __ test(output_reg, Immediate(1));
3667 DeoptimizeIf(not_zero, instr, Deoptimizer::kMinusZero);
3668 __ Move(output_reg, Immediate(0));
3669 __ jmp(&done, Label::kNear);
3670 __ bind(&positive_sign);
3673 // Use truncating instruction (OK because input is positive).
3674 __ cvttsd2si(output_reg, Operand(input_reg));
3675 // Overflow is signalled with minint.
3676 __ cmp(output_reg, 0x1);
3677 DeoptimizeIf(overflow, instr, Deoptimizer::kOverflow);
3678 __ jmp(&done, Label::kNear);
3680 // Non-zero negative reaches here.
3681 __ bind(&negative_sign);
3682 // Truncate, then compare and compensate.
3683 __ cvttsd2si(output_reg, Operand(input_reg));
3684 __ Cvtsi2sd(xmm_scratch, output_reg);
3685 __ ucomisd(input_reg, xmm_scratch);
3686 __ j(equal, &done, Label::kNear);
3687 __ sub(output_reg, Immediate(1));
3688 DeoptimizeIf(overflow, instr, Deoptimizer::kOverflow);
3695 void LCodeGen::DoMathRound(LMathRound* instr) {
3696 Register output_reg = ToRegister(instr->result());
3697 XMMRegister input_reg = ToDoubleRegister(instr->value());
3698 XMMRegister xmm_scratch = double_scratch0();
3699 XMMRegister input_temp = ToDoubleRegister(instr->temp());
3700 ExternalReference one_half = ExternalReference::address_of_one_half();
3701 ExternalReference minus_one_half =
3702 ExternalReference::address_of_minus_one_half();
3704 Label done, round_to_zero, below_one_half, do_not_compensate;
3705 Label::Distance dist = DeoptEveryNTimes() ? Label::kFar : Label::kNear;
3707 __ movsd(xmm_scratch, Operand::StaticVariable(one_half));
3708 __ ucomisd(xmm_scratch, input_reg);
3709 __ j(above, &below_one_half, Label::kNear);
3711 // CVTTSD2SI rounds towards zero, since 0.5 <= x, we use floor(0.5 + x).
3712 __ addsd(xmm_scratch, input_reg);
3713 __ cvttsd2si(output_reg, Operand(xmm_scratch));
3714 // Overflow is signalled with minint.
3715 __ cmp(output_reg, 0x1);
3716 DeoptimizeIf(overflow, instr, Deoptimizer::kOverflow);
3717 __ jmp(&done, dist);
3719 __ bind(&below_one_half);
3720 __ movsd(xmm_scratch, Operand::StaticVariable(minus_one_half));
3721 __ ucomisd(xmm_scratch, input_reg);
3722 __ j(below_equal, &round_to_zero, Label::kNear);
3724 // CVTTSD2SI rounds towards zero, we use ceil(x - (-0.5)) and then
3725 // compare and compensate.
3726 __ movaps(input_temp, input_reg); // Do not alter input_reg.
3727 __ subsd(input_temp, xmm_scratch);
3728 __ cvttsd2si(output_reg, Operand(input_temp));
3729 // Catch minint due to overflow, and to prevent overflow when compensating.
3730 __ cmp(output_reg, 0x1);
3731 DeoptimizeIf(overflow, instr, Deoptimizer::kOverflow);
3733 __ Cvtsi2sd(xmm_scratch, output_reg);
3734 __ ucomisd(xmm_scratch, input_temp);
3735 __ j(equal, &done, dist);
3736 __ sub(output_reg, Immediate(1));
3737 // No overflow because we already ruled out minint.
3738 __ jmp(&done, dist);
3740 __ bind(&round_to_zero);
3741 // We return 0 for the input range [+0, 0.5[, or [-0.5, 0.5[ if
3742 // we can ignore the difference between a result of -0 and +0.
3743 if (instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero)) {
3744 // If the sign is positive, we return +0.
3745 __ movmskpd(output_reg, input_reg);
3746 __ test(output_reg, Immediate(1));
3747 DeoptimizeIf(not_zero, instr, Deoptimizer::kMinusZero);
3749 __ Move(output_reg, Immediate(0));
3754 void LCodeGen::DoMathFround(LMathFround* instr) {
3755 XMMRegister input_reg = ToDoubleRegister(instr->value());
3756 XMMRegister output_reg = ToDoubleRegister(instr->result());
3757 __ cvtsd2ss(output_reg, input_reg);
3758 __ cvtss2sd(output_reg, output_reg);
3762 void LCodeGen::DoMathSqrt(LMathSqrt* instr) {
3763 Operand input = ToOperand(instr->value());
3764 XMMRegister output = ToDoubleRegister(instr->result());
3765 __ sqrtsd(output, input);
3769 void LCodeGen::DoMathPowHalf(LMathPowHalf* instr) {
3770 XMMRegister xmm_scratch = double_scratch0();
3771 XMMRegister input_reg = ToDoubleRegister(instr->value());
3772 Register scratch = ToRegister(instr->temp());
3773 DCHECK(ToDoubleRegister(instr->result()).is(input_reg));
3775 // Note that according to ECMA-262 15.8.2.13:
3776 // Math.pow(-Infinity, 0.5) == Infinity
3777 // Math.sqrt(-Infinity) == NaN
3779 // Check base for -Infinity. According to IEEE-754, single-precision
3780 // -Infinity has the highest 9 bits set and the lowest 23 bits cleared.
3781 __ mov(scratch, 0xFF800000);
3782 __ movd(xmm_scratch, scratch);
3783 __ cvtss2sd(xmm_scratch, xmm_scratch);
3784 __ ucomisd(input_reg, xmm_scratch);
3785 // Comparing -Infinity with NaN results in "unordered", which sets the
3786 // zero flag as if both were equal. However, it also sets the carry flag.
3787 __ j(not_equal, &sqrt, Label::kNear);
3788 __ j(carry, &sqrt, Label::kNear);
3789 // If input is -Infinity, return Infinity.
3790 __ xorps(input_reg, input_reg);
3791 __ subsd(input_reg, xmm_scratch);
3792 __ jmp(&done, Label::kNear);
3796 __ xorps(xmm_scratch, xmm_scratch);
3797 __ addsd(input_reg, xmm_scratch); // Convert -0 to +0.
3798 __ sqrtsd(input_reg, input_reg);
3803 void LCodeGen::DoPower(LPower* instr) {
3804 Representation exponent_type = instr->hydrogen()->right()->representation();
3805 // Having marked this as a call, we can use any registers.
3806 // Just make sure that the input/output registers are the expected ones.
3807 Register tagged_exponent = MathPowTaggedDescriptor::exponent();
3808 DCHECK(!instr->right()->IsDoubleRegister() ||
3809 ToDoubleRegister(instr->right()).is(xmm1));
3810 DCHECK(!instr->right()->IsRegister() ||
3811 ToRegister(instr->right()).is(tagged_exponent));
3812 DCHECK(ToDoubleRegister(instr->left()).is(xmm2));
3813 DCHECK(ToDoubleRegister(instr->result()).is(xmm3));
3815 if (exponent_type.IsSmi()) {
3816 MathPowStub stub(isolate(), MathPowStub::TAGGED);
3818 } else if (exponent_type.IsTagged()) {
3820 __ JumpIfSmi(tagged_exponent, &no_deopt);
3821 DCHECK(!ecx.is(tagged_exponent));
3822 __ CmpObjectType(tagged_exponent, HEAP_NUMBER_TYPE, ecx);
3823 DeoptimizeIf(not_equal, instr, Deoptimizer::kNotAHeapNumber);
3825 MathPowStub stub(isolate(), MathPowStub::TAGGED);
3827 } else if (exponent_type.IsInteger32()) {
3828 MathPowStub stub(isolate(), MathPowStub::INTEGER);
3831 DCHECK(exponent_type.IsDouble());
3832 MathPowStub stub(isolate(), MathPowStub::DOUBLE);
3838 void LCodeGen::DoMathLog(LMathLog* instr) {
3839 DCHECK(instr->value()->Equals(instr->result()));
3840 XMMRegister input_reg = ToDoubleRegister(instr->value());
3841 XMMRegister xmm_scratch = double_scratch0();
3842 Label positive, done, zero;
3843 __ xorps(xmm_scratch, xmm_scratch);
3844 __ ucomisd(input_reg, xmm_scratch);
3845 __ j(above, &positive, Label::kNear);
3846 __ j(not_carry, &zero, Label::kNear);
3847 __ pcmpeqd(input_reg, input_reg);
3848 __ jmp(&done, Label::kNear);
3850 ExternalReference ninf =
3851 ExternalReference::address_of_negative_infinity();
3852 __ movsd(input_reg, Operand::StaticVariable(ninf));
3853 __ jmp(&done, Label::kNear);
3856 __ sub(Operand(esp), Immediate(kDoubleSize));
3857 __ movsd(Operand(esp, 0), input_reg);
3858 __ fld_d(Operand(esp, 0));
3860 __ fstp_d(Operand(esp, 0));
3861 __ movsd(input_reg, Operand(esp, 0));
3862 __ add(Operand(esp), Immediate(kDoubleSize));
3867 void LCodeGen::DoMathClz32(LMathClz32* instr) {
3868 Register input = ToRegister(instr->value());
3869 Register result = ToRegister(instr->result());
3871 __ Lzcnt(result, input);
3875 void LCodeGen::DoMathExp(LMathExp* instr) {
3876 XMMRegister input = ToDoubleRegister(instr->value());
3877 XMMRegister result = ToDoubleRegister(instr->result());
3878 XMMRegister temp0 = double_scratch0();
3879 Register temp1 = ToRegister(instr->temp1());
3880 Register temp2 = ToRegister(instr->temp2());
3882 MathExpGenerator::EmitMathExp(masm(), input, result, temp0, temp1, temp2);
3886 void LCodeGen::DoInvokeFunction(LInvokeFunction* instr) {
3887 DCHECK(ToRegister(instr->context()).is(esi));
3888 DCHECK(ToRegister(instr->function()).is(edi));
3889 DCHECK(instr->HasPointerMap());
3891 Handle<JSFunction> known_function = instr->hydrogen()->known_function();
3892 if (known_function.is_null()) {
3893 LPointerMap* pointers = instr->pointer_map();
3894 SafepointGenerator generator(
3895 this, pointers, Safepoint::kLazyDeopt);
3896 ParameterCount count(instr->arity());
3897 __ InvokeFunction(edi, count, CALL_FUNCTION, generator);
3899 CallKnownFunction(known_function,
3900 instr->hydrogen()->formal_parameter_count(),
3901 instr->arity(), instr);
3906 void LCodeGen::DoCallFunction(LCallFunction* instr) {
3907 DCHECK(ToRegister(instr->context()).is(esi));
3908 DCHECK(ToRegister(instr->function()).is(edi));
3909 DCHECK(ToRegister(instr->result()).is(eax));
3911 int arity = instr->arity();
3912 CallFunctionFlags flags = instr->hydrogen()->function_flags();
3913 if (instr->hydrogen()->HasVectorAndSlot()) {
3914 Register slot_register = ToRegister(instr->temp_slot());
3915 Register vector_register = ToRegister(instr->temp_vector());
3916 DCHECK(slot_register.is(edx));
3917 DCHECK(vector_register.is(ebx));
3919 AllowDeferredHandleDereference vector_structure_check;
3920 Handle<TypeFeedbackVector> vector = instr->hydrogen()->feedback_vector();
3921 int index = vector->GetIndex(instr->hydrogen()->slot());
3923 __ mov(vector_register, vector);
3924 __ mov(slot_register, Immediate(Smi::FromInt(index)));
3926 CallICState::CallType call_type =
3927 (flags & CALL_AS_METHOD) ? CallICState::METHOD : CallICState::FUNCTION;
3930 CodeFactory::CallICInOptimizedCode(isolate(), arity, call_type).code();
3931 CallCode(ic, RelocInfo::CODE_TARGET, instr);
3933 CallFunctionStub stub(isolate(), arity, flags);
3934 CallCode(stub.GetCode(), RelocInfo::CODE_TARGET, instr);
3939 void LCodeGen::DoCallNew(LCallNew* instr) {
3940 DCHECK(ToRegister(instr->context()).is(esi));
3941 DCHECK(ToRegister(instr->constructor()).is(edi));
3942 DCHECK(ToRegister(instr->result()).is(eax));
3944 // No cell in ebx for construct type feedback in optimized code
3945 __ mov(ebx, isolate()->factory()->undefined_value());
3946 CallConstructStub stub(isolate(), NO_CALL_CONSTRUCTOR_FLAGS);
3947 __ Move(eax, Immediate(instr->arity()));
3948 CallCode(stub.GetCode(), RelocInfo::CONSTRUCT_CALL, instr);
3952 void LCodeGen::DoCallNewArray(LCallNewArray* instr) {
3953 DCHECK(ToRegister(instr->context()).is(esi));
3954 DCHECK(ToRegister(instr->constructor()).is(edi));
3955 DCHECK(ToRegister(instr->result()).is(eax));
3957 __ Move(eax, Immediate(instr->arity()));
3958 if (instr->arity() == 1) {
3959 // We only need the allocation site for the case we have a length argument.
3960 // The case may bail out to the runtime, which will determine the correct
3961 // elements kind with the site.
3962 __ mov(ebx, instr->hydrogen()->site());
3964 __ mov(ebx, isolate()->factory()->undefined_value());
3967 ElementsKind kind = instr->hydrogen()->elements_kind();
3968 AllocationSiteOverrideMode override_mode =
3969 (AllocationSite::GetMode(kind) == TRACK_ALLOCATION_SITE)
3970 ? DISABLE_ALLOCATION_SITES
3973 if (instr->arity() == 0) {
3974 ArrayNoArgumentConstructorStub stub(isolate(), kind, override_mode);
3975 CallCode(stub.GetCode(), RelocInfo::CONSTRUCT_CALL, instr);
3976 } else if (instr->arity() == 1) {
3978 if (IsFastPackedElementsKind(kind)) {
3980 // We might need a change here
3981 // look at the first argument
3982 __ mov(ecx, Operand(esp, 0));
3984 __ j(zero, &packed_case, Label::kNear);
3986 ElementsKind holey_kind = GetHoleyElementsKind(kind);
3987 ArraySingleArgumentConstructorStub stub(isolate(),
3990 CallCode(stub.GetCode(), RelocInfo::CONSTRUCT_CALL, instr);
3991 __ jmp(&done, Label::kNear);
3992 __ bind(&packed_case);
3995 ArraySingleArgumentConstructorStub stub(isolate(), kind, override_mode);
3996 CallCode(stub.GetCode(), RelocInfo::CONSTRUCT_CALL, instr);
3999 ArrayNArgumentsConstructorStub stub(isolate(), kind, override_mode);
4000 CallCode(stub.GetCode(), RelocInfo::CONSTRUCT_CALL, instr);
4005 void LCodeGen::DoCallRuntime(LCallRuntime* instr) {
4006 DCHECK(ToRegister(instr->context()).is(esi));
4007 CallRuntime(instr->function(), instr->arity(), instr, instr->save_doubles());
4011 void LCodeGen::DoStoreCodeEntry(LStoreCodeEntry* instr) {
4012 Register function = ToRegister(instr->function());
4013 Register code_object = ToRegister(instr->code_object());
4014 __ lea(code_object, FieldOperand(code_object, Code::kHeaderSize));
4015 __ mov(FieldOperand(function, JSFunction::kCodeEntryOffset), code_object);
4019 void LCodeGen::DoInnerAllocatedObject(LInnerAllocatedObject* instr) {
4020 Register result = ToRegister(instr->result());
4021 Register base = ToRegister(instr->base_object());
4022 if (instr->offset()->IsConstantOperand()) {
4023 LConstantOperand* offset = LConstantOperand::cast(instr->offset());
4024 __ lea(result, Operand(base, ToInteger32(offset)));
4026 Register offset = ToRegister(instr->offset());
4027 __ lea(result, Operand(base, offset, times_1, 0));
4032 void LCodeGen::DoStoreNamedField(LStoreNamedField* instr) {
4033 Representation representation = instr->hydrogen()->field_representation();
4035 HObjectAccess access = instr->hydrogen()->access();
4036 int offset = access.offset();
4038 if (access.IsExternalMemory()) {
4039 DCHECK(!instr->hydrogen()->NeedsWriteBarrier());
4040 MemOperand operand = instr->object()->IsConstantOperand()
4041 ? MemOperand::StaticVariable(
4042 ToExternalReference(LConstantOperand::cast(instr->object())))
4043 : MemOperand(ToRegister(instr->object()), offset);
4044 if (instr->value()->IsConstantOperand()) {
4045 LConstantOperand* operand_value = LConstantOperand::cast(instr->value());
4046 __ mov(operand, Immediate(ToInteger32(operand_value)));
4048 Register value = ToRegister(instr->value());
4049 __ Store(value, operand, representation);
4054 Register object = ToRegister(instr->object());
4055 __ AssertNotSmi(object);
4057 DCHECK(!representation.IsSmi() ||
4058 !instr->value()->IsConstantOperand() ||
4059 IsSmi(LConstantOperand::cast(instr->value())));
4060 if (representation.IsDouble()) {
4061 DCHECK(access.IsInobject());
4062 DCHECK(!instr->hydrogen()->has_transition());
4063 DCHECK(!instr->hydrogen()->NeedsWriteBarrier());
4064 XMMRegister value = ToDoubleRegister(instr->value());
4065 __ movsd(FieldOperand(object, offset), value);
4069 if (instr->hydrogen()->has_transition()) {
4070 Handle<Map> transition = instr->hydrogen()->transition_map();
4071 AddDeprecationDependency(transition);
4072 __ mov(FieldOperand(object, HeapObject::kMapOffset), transition);
4073 if (instr->hydrogen()->NeedsWriteBarrierForMap()) {
4074 Register temp = ToRegister(instr->temp());
4075 Register temp_map = ToRegister(instr->temp_map());
4076 // Update the write barrier for the map field.
4077 __ RecordWriteForMap(object, transition, temp_map, temp, kSaveFPRegs);
4082 Register write_register = object;
4083 if (!access.IsInobject()) {
4084 write_register = ToRegister(instr->temp());
4085 __ mov(write_register, FieldOperand(object, JSObject::kPropertiesOffset));
4088 MemOperand operand = FieldOperand(write_register, offset);
4089 if (instr->value()->IsConstantOperand()) {
4090 LConstantOperand* operand_value = LConstantOperand::cast(instr->value());
4091 if (operand_value->IsRegister()) {
4092 Register value = ToRegister(operand_value);
4093 __ Store(value, operand, representation);
4094 } else if (representation.IsInteger32() || representation.IsExternal()) {
4095 Immediate immediate = ToImmediate(operand_value, representation);
4096 DCHECK(!instr->hydrogen()->NeedsWriteBarrier());
4097 __ mov(operand, immediate);
4099 Handle<Object> handle_value = ToHandle(operand_value);
4100 DCHECK(!instr->hydrogen()->NeedsWriteBarrier());
4101 __ mov(operand, handle_value);
4104 Register value = ToRegister(instr->value());
4105 __ Store(value, operand, representation);
4108 if (instr->hydrogen()->NeedsWriteBarrier()) {
4109 Register value = ToRegister(instr->value());
4110 Register temp = access.IsInobject() ? ToRegister(instr->temp()) : object;
4111 // Update the write barrier for the object for in-object properties.
4112 __ RecordWriteField(write_register,
4117 EMIT_REMEMBERED_SET,
4118 instr->hydrogen()->SmiCheckForWriteBarrier(),
4119 instr->hydrogen()->PointersToHereCheckForValue());
4124 void LCodeGen::DoStoreNamedGeneric(LStoreNamedGeneric* instr) {
4125 DCHECK(ToRegister(instr->context()).is(esi));
4126 DCHECK(ToRegister(instr->object()).is(StoreDescriptor::ReceiverRegister()));
4127 DCHECK(ToRegister(instr->value()).is(StoreDescriptor::ValueRegister()));
4129 if (instr->hydrogen()->HasVectorAndSlot()) {
4130 EmitVectorStoreICRegisters<LStoreNamedGeneric>(instr);
4133 __ mov(StoreDescriptor::NameRegister(), instr->name());
4134 Handle<Code> ic = CodeFactory::StoreICInOptimizedCode(
4135 isolate(), instr->language_mode(),
4136 instr->hydrogen()->initialization_state()).code();
4137 CallCode(ic, RelocInfo::CODE_TARGET, instr);
4141 void LCodeGen::DoStoreGlobalViaContext(LStoreGlobalViaContext* instr) {
4142 DCHECK(ToRegister(instr->context()).is(esi));
4143 DCHECK(ToRegister(instr->value())
4144 .is(StoreGlobalViaContextDescriptor::ValueRegister()));
4146 __ mov(StoreGlobalViaContextDescriptor::DepthRegister(),
4147 Immediate(Smi::FromInt(instr->depth())));
4148 __ mov(StoreGlobalViaContextDescriptor::SlotRegister(),
4149 Immediate(Smi::FromInt(instr->slot_index())));
4150 __ mov(StoreGlobalViaContextDescriptor::NameRegister(), instr->name());
4153 CodeFactory::StoreGlobalViaContext(isolate(), instr->depth(),
4154 instr->language_mode()).code();
4155 CallCode(stub, RelocInfo::CODE_TARGET, instr);
4159 void LCodeGen::DoBoundsCheck(LBoundsCheck* instr) {
4160 Condition cc = instr->hydrogen()->allow_equality() ? above : above_equal;
4161 if (instr->index()->IsConstantOperand()) {
4162 __ cmp(ToOperand(instr->length()),
4163 ToImmediate(LConstantOperand::cast(instr->index()),
4164 instr->hydrogen()->length()->representation()));
4165 cc = CommuteCondition(cc);
4166 } else if (instr->length()->IsConstantOperand()) {
4167 __ cmp(ToOperand(instr->index()),
4168 ToImmediate(LConstantOperand::cast(instr->length()),
4169 instr->hydrogen()->index()->representation()));
4171 __ cmp(ToRegister(instr->index()), ToOperand(instr->length()));
4173 if (FLAG_debug_code && instr->hydrogen()->skip_check()) {
4175 __ j(NegateCondition(cc), &done, Label::kNear);
4179 DeoptimizeIf(cc, instr, Deoptimizer::kOutOfBounds);
4184 void LCodeGen::DoStoreKeyedExternalArray(LStoreKeyed* instr) {
4185 ElementsKind elements_kind = instr->elements_kind();
4186 LOperand* key = instr->key();
4187 if (!key->IsConstantOperand() &&
4188 ExternalArrayOpRequiresTemp(instr->hydrogen()->key()->representation(),
4190 __ SmiUntag(ToRegister(key));
4192 Operand operand(BuildFastArrayOperand(
4195 instr->hydrogen()->key()->representation(),
4197 instr->base_offset()));
4198 if (elements_kind == EXTERNAL_FLOAT32_ELEMENTS ||
4199 elements_kind == FLOAT32_ELEMENTS) {
4200 XMMRegister xmm_scratch = double_scratch0();
4201 __ cvtsd2ss(xmm_scratch, ToDoubleRegister(instr->value()));
4202 __ movss(operand, xmm_scratch);
4203 } else if (elements_kind == EXTERNAL_FLOAT64_ELEMENTS ||
4204 elements_kind == FLOAT64_ELEMENTS) {
4205 __ movsd(operand, ToDoubleRegister(instr->value()));
4207 Register value = ToRegister(instr->value());
4208 switch (elements_kind) {
4209 case EXTERNAL_UINT8_CLAMPED_ELEMENTS:
4210 case EXTERNAL_UINT8_ELEMENTS:
4211 case EXTERNAL_INT8_ELEMENTS:
4212 case UINT8_ELEMENTS:
4214 case UINT8_CLAMPED_ELEMENTS:
4215 __ mov_b(operand, value);
4217 case EXTERNAL_INT16_ELEMENTS:
4218 case EXTERNAL_UINT16_ELEMENTS:
4219 case UINT16_ELEMENTS:
4220 case INT16_ELEMENTS:
4221 __ mov_w(operand, value);
4223 case EXTERNAL_INT32_ELEMENTS:
4224 case EXTERNAL_UINT32_ELEMENTS:
4225 case UINT32_ELEMENTS:
4226 case INT32_ELEMENTS:
4227 __ mov(operand, value);
4229 case EXTERNAL_FLOAT32_ELEMENTS:
4230 case EXTERNAL_FLOAT64_ELEMENTS:
4231 case FLOAT32_ELEMENTS:
4232 case FLOAT64_ELEMENTS:
4233 case FAST_SMI_ELEMENTS:
4235 case FAST_DOUBLE_ELEMENTS:
4236 case FAST_HOLEY_SMI_ELEMENTS:
4237 case FAST_HOLEY_ELEMENTS:
4238 case FAST_HOLEY_DOUBLE_ELEMENTS:
4239 case DICTIONARY_ELEMENTS:
4240 case FAST_SLOPPY_ARGUMENTS_ELEMENTS:
4241 case SLOW_SLOPPY_ARGUMENTS_ELEMENTS:
4249 void LCodeGen::DoStoreKeyedFixedDoubleArray(LStoreKeyed* instr) {
4250 Operand double_store_operand = BuildFastArrayOperand(
4253 instr->hydrogen()->key()->representation(),
4254 FAST_DOUBLE_ELEMENTS,
4255 instr->base_offset());
4257 XMMRegister value = ToDoubleRegister(instr->value());
4259 if (instr->NeedsCanonicalization()) {
4260 XMMRegister xmm_scratch = double_scratch0();
4261 // Turn potential sNaN value into qNaN.
4262 __ xorps(xmm_scratch, xmm_scratch);
4263 __ subsd(value, xmm_scratch);
4266 __ movsd(double_store_operand, value);
4270 void LCodeGen::DoStoreKeyedFixedArray(LStoreKeyed* instr) {
4271 Register elements = ToRegister(instr->elements());
4272 Register key = instr->key()->IsRegister() ? ToRegister(instr->key()) : no_reg;
4274 Operand operand = BuildFastArrayOperand(
4277 instr->hydrogen()->key()->representation(),
4279 instr->base_offset());
4280 if (instr->value()->IsRegister()) {
4281 __ mov(operand, ToRegister(instr->value()));
4283 LConstantOperand* operand_value = LConstantOperand::cast(instr->value());
4284 if (IsSmi(operand_value)) {
4285 Immediate immediate = ToImmediate(operand_value, Representation::Smi());
4286 __ mov(operand, immediate);
4288 DCHECK(!IsInteger32(operand_value));
4289 Handle<Object> handle_value = ToHandle(operand_value);
4290 __ mov(operand, handle_value);
4294 if (instr->hydrogen()->NeedsWriteBarrier()) {
4295 DCHECK(instr->value()->IsRegister());
4296 Register value = ToRegister(instr->value());
4297 DCHECK(!instr->key()->IsConstantOperand());
4298 SmiCheck check_needed =
4299 instr->hydrogen()->value()->type().IsHeapObject()
4300 ? OMIT_SMI_CHECK : INLINE_SMI_CHECK;
4301 // Compute address of modified element and store it into key register.
4302 __ lea(key, operand);
4303 __ RecordWrite(elements,
4307 EMIT_REMEMBERED_SET,
4309 instr->hydrogen()->PointersToHereCheckForValue());
4314 void LCodeGen::DoStoreKeyed(LStoreKeyed* instr) {
4315 // By cases...external, fast-double, fast
4316 if (instr->is_typed_elements()) {
4317 DoStoreKeyedExternalArray(instr);
4318 } else if (instr->hydrogen()->value()->representation().IsDouble()) {
4319 DoStoreKeyedFixedDoubleArray(instr);
4321 DoStoreKeyedFixedArray(instr);
4326 void LCodeGen::DoStoreKeyedGeneric(LStoreKeyedGeneric* instr) {
4327 DCHECK(ToRegister(instr->context()).is(esi));
4328 DCHECK(ToRegister(instr->object()).is(StoreDescriptor::ReceiverRegister()));
4329 DCHECK(ToRegister(instr->key()).is(StoreDescriptor::NameRegister()));
4330 DCHECK(ToRegister(instr->value()).is(StoreDescriptor::ValueRegister()));
4332 if (instr->hydrogen()->HasVectorAndSlot()) {
4333 EmitVectorStoreICRegisters<LStoreKeyedGeneric>(instr);
4336 Handle<Code> ic = CodeFactory::KeyedStoreICInOptimizedCode(
4337 isolate(), instr->language_mode(),
4338 instr->hydrogen()->initialization_state()).code();
4339 CallCode(ic, RelocInfo::CODE_TARGET, instr);
4343 void LCodeGen::DoTrapAllocationMemento(LTrapAllocationMemento* instr) {
4344 Register object = ToRegister(instr->object());
4345 Register temp = ToRegister(instr->temp());
4346 Label no_memento_found;
4347 __ TestJSArrayForAllocationMemento(object, temp, &no_memento_found);
4348 DeoptimizeIf(equal, instr, Deoptimizer::kMementoFound);
4349 __ bind(&no_memento_found);
4353 void LCodeGen::DoMaybeGrowElements(LMaybeGrowElements* instr) {
4354 class DeferredMaybeGrowElements final : public LDeferredCode {
4356 DeferredMaybeGrowElements(LCodeGen* codegen, LMaybeGrowElements* instr)
4357 : LDeferredCode(codegen), instr_(instr) {}
4358 void Generate() override { codegen()->DoDeferredMaybeGrowElements(instr_); }
4359 LInstruction* instr() override { return instr_; }
4362 LMaybeGrowElements* instr_;
4365 Register result = eax;
4366 DeferredMaybeGrowElements* deferred =
4367 new (zone()) DeferredMaybeGrowElements(this, instr);
4368 LOperand* key = instr->key();
4369 LOperand* current_capacity = instr->current_capacity();
4371 DCHECK(instr->hydrogen()->key()->representation().IsInteger32());
4372 DCHECK(instr->hydrogen()->current_capacity()->representation().IsInteger32());
4373 DCHECK(key->IsConstantOperand() || key->IsRegister());
4374 DCHECK(current_capacity->IsConstantOperand() ||
4375 current_capacity->IsRegister());
4377 if (key->IsConstantOperand() && current_capacity->IsConstantOperand()) {
4378 int32_t constant_key = ToInteger32(LConstantOperand::cast(key));
4379 int32_t constant_capacity =
4380 ToInteger32(LConstantOperand::cast(current_capacity));
4381 if (constant_key >= constant_capacity) {
4383 __ jmp(deferred->entry());
4385 } else if (key->IsConstantOperand()) {
4386 int32_t constant_key = ToInteger32(LConstantOperand::cast(key));
4387 __ cmp(ToOperand(current_capacity), Immediate(constant_key));
4388 __ j(less_equal, deferred->entry());
4389 } else if (current_capacity->IsConstantOperand()) {
4390 int32_t constant_capacity =
4391 ToInteger32(LConstantOperand::cast(current_capacity));
4392 __ cmp(ToRegister(key), Immediate(constant_capacity));
4393 __ j(greater_equal, deferred->entry());
4395 __ cmp(ToRegister(key), ToRegister(current_capacity));
4396 __ j(greater_equal, deferred->entry());
4399 __ mov(result, ToOperand(instr->elements()));
4400 __ bind(deferred->exit());
4404 void LCodeGen::DoDeferredMaybeGrowElements(LMaybeGrowElements* instr) {
4405 // TODO(3095996): Get rid of this. For now, we need to make the
4406 // result register contain a valid pointer because it is already
4407 // contained in the register pointer map.
4408 Register result = eax;
4409 __ Move(result, Immediate(0));
4411 // We have to call a stub.
4413 PushSafepointRegistersScope scope(this);
4414 if (instr->object()->IsRegister()) {
4415 __ Move(result, ToRegister(instr->object()));
4417 __ mov(result, ToOperand(instr->object()));
4420 LOperand* key = instr->key();
4421 if (key->IsConstantOperand()) {
4422 __ mov(ebx, ToImmediate(key, Representation::Smi()));
4424 __ Move(ebx, ToRegister(key));
4428 GrowArrayElementsStub stub(isolate(), instr->hydrogen()->is_js_array(),
4429 instr->hydrogen()->kind());
4431 RecordSafepointWithLazyDeopt(
4432 instr, RECORD_SAFEPOINT_WITH_REGISTERS_AND_NO_ARGUMENTS);
4433 __ StoreToSafepointRegisterSlot(result, result);
4436 // Deopt on smi, which means the elements array changed to dictionary mode.
4437 __ test(result, Immediate(kSmiTagMask));
4438 DeoptimizeIf(equal, instr, Deoptimizer::kSmi);
4442 void LCodeGen::DoTransitionElementsKind(LTransitionElementsKind* instr) {
4443 Register object_reg = ToRegister(instr->object());
4445 Handle<Map> from_map = instr->original_map();
4446 Handle<Map> to_map = instr->transitioned_map();
4447 ElementsKind from_kind = instr->from_kind();
4448 ElementsKind to_kind = instr->to_kind();
4450 Label not_applicable;
4451 bool is_simple_map_transition =
4452 IsSimpleMapChangeTransition(from_kind, to_kind);
4453 Label::Distance branch_distance =
4454 is_simple_map_transition ? Label::kNear : Label::kFar;
4455 __ cmp(FieldOperand(object_reg, HeapObject::kMapOffset), from_map);
4456 __ j(not_equal, ¬_applicable, branch_distance);
4457 if (is_simple_map_transition) {
4458 Register new_map_reg = ToRegister(instr->new_map_temp());
4459 __ mov(FieldOperand(object_reg, HeapObject::kMapOffset),
4462 DCHECK_NOT_NULL(instr->temp());
4463 __ RecordWriteForMap(object_reg, to_map, new_map_reg,
4464 ToRegister(instr->temp()),
4467 DCHECK(ToRegister(instr->context()).is(esi));
4468 DCHECK(object_reg.is(eax));
4469 PushSafepointRegistersScope scope(this);
4470 __ mov(ebx, to_map);
4471 bool is_js_array = from_map->instance_type() == JS_ARRAY_TYPE;
4472 TransitionElementsKindStub stub(isolate(), from_kind, to_kind, is_js_array);
4474 RecordSafepointWithLazyDeopt(instr,
4475 RECORD_SAFEPOINT_WITH_REGISTERS_AND_NO_ARGUMENTS);
4477 __ bind(¬_applicable);
4481 void LCodeGen::DoStringCharCodeAt(LStringCharCodeAt* instr) {
4482 class DeferredStringCharCodeAt final : public LDeferredCode {
4484 DeferredStringCharCodeAt(LCodeGen* codegen,
4485 LStringCharCodeAt* instr)
4486 : LDeferredCode(codegen), instr_(instr) { }
4487 void Generate() override { codegen()->DoDeferredStringCharCodeAt(instr_); }
4488 LInstruction* instr() override { return instr_; }
4491 LStringCharCodeAt* instr_;
4494 DeferredStringCharCodeAt* deferred =
4495 new(zone()) DeferredStringCharCodeAt(this, instr);
4497 StringCharLoadGenerator::Generate(masm(),
4499 ToRegister(instr->string()),
4500 ToRegister(instr->index()),
4501 ToRegister(instr->result()),
4503 __ bind(deferred->exit());
4507 void LCodeGen::DoDeferredStringCharCodeAt(LStringCharCodeAt* instr) {
4508 Register string = ToRegister(instr->string());
4509 Register result = ToRegister(instr->result());
4511 // TODO(3095996): Get rid of this. For now, we need to make the
4512 // result register contain a valid pointer because it is already
4513 // contained in the register pointer map.
4514 __ Move(result, Immediate(0));
4516 PushSafepointRegistersScope scope(this);
4518 // Push the index as a smi. This is safe because of the checks in
4519 // DoStringCharCodeAt above.
4520 STATIC_ASSERT(String::kMaxLength <= Smi::kMaxValue);
4521 if (instr->index()->IsConstantOperand()) {
4522 Immediate immediate = ToImmediate(LConstantOperand::cast(instr->index()),
4523 Representation::Smi());
4526 Register index = ToRegister(instr->index());
4530 CallRuntimeFromDeferred(Runtime::kStringCharCodeAtRT, 2,
4531 instr, instr->context());
4534 __ StoreToSafepointRegisterSlot(result, eax);
4538 void LCodeGen::DoStringCharFromCode(LStringCharFromCode* instr) {
4539 class DeferredStringCharFromCode final : public LDeferredCode {
4541 DeferredStringCharFromCode(LCodeGen* codegen,
4542 LStringCharFromCode* instr)
4543 : LDeferredCode(codegen), instr_(instr) { }
4544 void Generate() override {
4545 codegen()->DoDeferredStringCharFromCode(instr_);
4547 LInstruction* instr() override { return instr_; }
4550 LStringCharFromCode* instr_;
4553 DeferredStringCharFromCode* deferred =
4554 new(zone()) DeferredStringCharFromCode(this, instr);
4556 DCHECK(instr->hydrogen()->value()->representation().IsInteger32());
4557 Register char_code = ToRegister(instr->char_code());
4558 Register result = ToRegister(instr->result());
4559 DCHECK(!char_code.is(result));
4561 __ cmp(char_code, String::kMaxOneByteCharCode);
4562 __ j(above, deferred->entry());
4563 __ Move(result, Immediate(factory()->single_character_string_cache()));
4564 __ mov(result, FieldOperand(result,
4565 char_code, times_pointer_size,
4566 FixedArray::kHeaderSize));
4567 __ cmp(result, factory()->undefined_value());
4568 __ j(equal, deferred->entry());
4569 __ bind(deferred->exit());
4573 void LCodeGen::DoDeferredStringCharFromCode(LStringCharFromCode* instr) {
4574 Register char_code = ToRegister(instr->char_code());
4575 Register result = ToRegister(instr->result());
4577 // TODO(3095996): Get rid of this. For now, we need to make the
4578 // result register contain a valid pointer because it is already
4579 // contained in the register pointer map.
4580 __ Move(result, Immediate(0));
4582 PushSafepointRegistersScope scope(this);
4583 __ SmiTag(char_code);
4585 CallRuntimeFromDeferred(Runtime::kCharFromCode, 1, instr, instr->context());
4586 __ StoreToSafepointRegisterSlot(result, eax);
4590 void LCodeGen::DoStringAdd(LStringAdd* instr) {
4591 DCHECK(ToRegister(instr->context()).is(esi));
4592 DCHECK(ToRegister(instr->left()).is(edx));
4593 DCHECK(ToRegister(instr->right()).is(eax));
4594 StringAddStub stub(isolate(),
4595 instr->hydrogen()->flags(),
4596 instr->hydrogen()->pretenure_flag());
4597 CallCode(stub.GetCode(), RelocInfo::CODE_TARGET, instr);
4601 void LCodeGen::DoInteger32ToDouble(LInteger32ToDouble* instr) {
4602 LOperand* input = instr->value();
4603 LOperand* output = instr->result();
4604 DCHECK(input->IsRegister() || input->IsStackSlot());
4605 DCHECK(output->IsDoubleRegister());
4606 __ Cvtsi2sd(ToDoubleRegister(output), ToOperand(input));
4610 void LCodeGen::DoUint32ToDouble(LUint32ToDouble* instr) {
4611 LOperand* input = instr->value();
4612 LOperand* output = instr->result();
4613 __ LoadUint32(ToDoubleRegister(output), ToRegister(input));
4617 void LCodeGen::DoNumberTagI(LNumberTagI* instr) {
4618 class DeferredNumberTagI final : public LDeferredCode {
4620 DeferredNumberTagI(LCodeGen* codegen,
4622 : LDeferredCode(codegen), instr_(instr) { }
4623 void Generate() override {
4624 codegen()->DoDeferredNumberTagIU(
4625 instr_, instr_->value(), instr_->temp(), SIGNED_INT32);
4627 LInstruction* instr() override { return instr_; }
4630 LNumberTagI* instr_;
4633 LOperand* input = instr->value();
4634 DCHECK(input->IsRegister() && input->Equals(instr->result()));
4635 Register reg = ToRegister(input);
4637 DeferredNumberTagI* deferred =
4638 new(zone()) DeferredNumberTagI(this, instr);
4640 __ j(overflow, deferred->entry());
4641 __ bind(deferred->exit());
4645 void LCodeGen::DoNumberTagU(LNumberTagU* instr) {
4646 class DeferredNumberTagU final : public LDeferredCode {
4648 DeferredNumberTagU(LCodeGen* codegen, LNumberTagU* instr)
4649 : LDeferredCode(codegen), instr_(instr) { }
4650 void Generate() override {
4651 codegen()->DoDeferredNumberTagIU(
4652 instr_, instr_->value(), instr_->temp(), UNSIGNED_INT32);
4654 LInstruction* instr() override { return instr_; }
4657 LNumberTagU* instr_;
4660 LOperand* input = instr->value();
4661 DCHECK(input->IsRegister() && input->Equals(instr->result()));
4662 Register reg = ToRegister(input);
4664 DeferredNumberTagU* deferred =
4665 new(zone()) DeferredNumberTagU(this, instr);
4666 __ cmp(reg, Immediate(Smi::kMaxValue));
4667 __ j(above, deferred->entry());
4669 __ bind(deferred->exit());
4673 void LCodeGen::DoDeferredNumberTagIU(LInstruction* instr,
4676 IntegerSignedness signedness) {
4678 Register reg = ToRegister(value);
4679 Register tmp = ToRegister(temp);
4680 XMMRegister xmm_scratch = double_scratch0();
4682 if (signedness == SIGNED_INT32) {
4683 // There was overflow, so bits 30 and 31 of the original integer
4684 // disagree. Try to allocate a heap number in new space and store
4685 // the value in there. If that fails, call the runtime system.
4687 __ xor_(reg, 0x80000000);
4688 __ Cvtsi2sd(xmm_scratch, Operand(reg));
4690 __ LoadUint32(xmm_scratch, reg);
4693 if (FLAG_inline_new) {
4694 __ AllocateHeapNumber(reg, tmp, no_reg, &slow);
4695 __ jmp(&done, Label::kNear);
4698 // Slow case: Call the runtime system to do the number allocation.
4701 // TODO(3095996): Put a valid pointer value in the stack slot where the
4702 // result register is stored, as this register is in the pointer map, but
4703 // contains an integer value.
4704 __ Move(reg, Immediate(0));
4706 // Preserve the value of all registers.
4707 PushSafepointRegistersScope scope(this);
4709 // NumberTagI and NumberTagD use the context from the frame, rather than
4710 // the environment's HContext or HInlinedContext value.
4711 // They only call Runtime::kAllocateHeapNumber.
4712 // The corresponding HChange instructions are added in a phase that does
4713 // not have easy access to the local context.
4714 __ mov(esi, Operand(ebp, StandardFrameConstants::kContextOffset));
4715 __ CallRuntimeSaveDoubles(Runtime::kAllocateHeapNumber);
4716 RecordSafepointWithRegisters(
4717 instr->pointer_map(), 0, Safepoint::kNoLazyDeopt);
4718 __ StoreToSafepointRegisterSlot(reg, eax);
4721 // Done. Put the value in xmm_scratch into the value of the allocated heap
4724 __ movsd(FieldOperand(reg, HeapNumber::kValueOffset), xmm_scratch);
4728 void LCodeGen::DoNumberTagD(LNumberTagD* instr) {
4729 class DeferredNumberTagD final : public LDeferredCode {
4731 DeferredNumberTagD(LCodeGen* codegen, LNumberTagD* instr)
4732 : LDeferredCode(codegen), instr_(instr) { }
4733 void Generate() override { codegen()->DoDeferredNumberTagD(instr_); }
4734 LInstruction* instr() override { return instr_; }
4737 LNumberTagD* instr_;
4740 Register reg = ToRegister(instr->result());
4742 DeferredNumberTagD* deferred =
4743 new(zone()) DeferredNumberTagD(this, instr);
4744 if (FLAG_inline_new) {
4745 Register tmp = ToRegister(instr->temp());
4746 __ AllocateHeapNumber(reg, tmp, no_reg, deferred->entry());
4748 __ jmp(deferred->entry());
4750 __ bind(deferred->exit());
4751 XMMRegister input_reg = ToDoubleRegister(instr->value());
4752 __ movsd(FieldOperand(reg, HeapNumber::kValueOffset), input_reg);
4756 void LCodeGen::DoDeferredNumberTagD(LNumberTagD* instr) {
4757 // TODO(3095996): Get rid of this. For now, we need to make the
4758 // result register contain a valid pointer because it is already
4759 // contained in the register pointer map.
4760 Register reg = ToRegister(instr->result());
4761 __ Move(reg, Immediate(0));
4763 PushSafepointRegistersScope scope(this);
4764 // NumberTagI and NumberTagD use the context from the frame, rather than
4765 // the environment's HContext or HInlinedContext value.
4766 // They only call Runtime::kAllocateHeapNumber.
4767 // The corresponding HChange instructions are added in a phase that does
4768 // not have easy access to the local context.
4769 __ mov(esi, Operand(ebp, StandardFrameConstants::kContextOffset));
4770 __ CallRuntimeSaveDoubles(Runtime::kAllocateHeapNumber);
4771 RecordSafepointWithRegisters(
4772 instr->pointer_map(), 0, Safepoint::kNoLazyDeopt);
4773 __ StoreToSafepointRegisterSlot(reg, eax);
4777 void LCodeGen::DoSmiTag(LSmiTag* instr) {
4778 HChange* hchange = instr->hydrogen();
4779 Register input = ToRegister(instr->value());
4780 if (hchange->CheckFlag(HValue::kCanOverflow) &&
4781 hchange->value()->CheckFlag(HValue::kUint32)) {
4782 __ test(input, Immediate(0xc0000000));
4783 DeoptimizeIf(not_zero, instr, Deoptimizer::kOverflow);
4786 if (hchange->CheckFlag(HValue::kCanOverflow) &&
4787 !hchange->value()->CheckFlag(HValue::kUint32)) {
4788 DeoptimizeIf(overflow, instr, Deoptimizer::kOverflow);
4793 void LCodeGen::DoSmiUntag(LSmiUntag* instr) {
4794 LOperand* input = instr->value();
4795 Register result = ToRegister(input);
4796 DCHECK(input->IsRegister() && input->Equals(instr->result()));
4797 if (instr->needs_check()) {
4798 __ test(result, Immediate(kSmiTagMask));
4799 DeoptimizeIf(not_zero, instr, Deoptimizer::kNotASmi);
4801 __ AssertSmi(result);
4803 __ SmiUntag(result);
4807 void LCodeGen::EmitNumberUntagD(LNumberUntagD* instr, Register input_reg,
4808 Register temp_reg, XMMRegister result_reg,
4809 NumberUntagDMode mode) {
4810 bool can_convert_undefined_to_nan =
4811 instr->hydrogen()->can_convert_undefined_to_nan();
4812 bool deoptimize_on_minus_zero = instr->hydrogen()->deoptimize_on_minus_zero();
4814 Label convert, load_smi, done;
4816 if (mode == NUMBER_CANDIDATE_IS_ANY_TAGGED) {
4818 __ JumpIfSmi(input_reg, &load_smi, Label::kNear);
4820 // Heap number map check.
4821 __ cmp(FieldOperand(input_reg, HeapObject::kMapOffset),
4822 factory()->heap_number_map());
4823 if (can_convert_undefined_to_nan) {
4824 __ j(not_equal, &convert, Label::kNear);
4826 DeoptimizeIf(not_equal, instr, Deoptimizer::kNotAHeapNumber);
4829 // Heap number to XMM conversion.
4830 __ movsd(result_reg, FieldOperand(input_reg, HeapNumber::kValueOffset));
4832 if (deoptimize_on_minus_zero) {
4833 XMMRegister xmm_scratch = double_scratch0();
4834 __ xorps(xmm_scratch, xmm_scratch);
4835 __ ucomisd(result_reg, xmm_scratch);
4836 __ j(not_zero, &done, Label::kNear);
4837 __ movmskpd(temp_reg, result_reg);
4838 __ test_b(temp_reg, 1);
4839 DeoptimizeIf(not_zero, instr, Deoptimizer::kMinusZero);
4841 __ jmp(&done, Label::kNear);
4843 if (can_convert_undefined_to_nan) {
4846 // Convert undefined to NaN.
4847 __ cmp(input_reg, factory()->undefined_value());
4848 DeoptimizeIf(not_equal, instr, Deoptimizer::kNotAHeapNumberUndefined);
4850 __ pcmpeqd(result_reg, result_reg);
4851 __ jmp(&done, Label::kNear);
4854 DCHECK(mode == NUMBER_CANDIDATE_IS_SMI);
4858 // Smi to XMM conversion. Clobbering a temp is faster than re-tagging the
4859 // input register since we avoid dependencies.
4860 __ mov(temp_reg, input_reg);
4861 __ SmiUntag(temp_reg); // Untag smi before converting to float.
4862 __ Cvtsi2sd(result_reg, Operand(temp_reg));
4867 void LCodeGen::DoDeferredTaggedToI(LTaggedToI* instr, Label* done) {
4868 Register input_reg = ToRegister(instr->value());
4870 // The input was optimistically untagged; revert it.
4871 STATIC_ASSERT(kSmiTagSize == 1);
4872 __ lea(input_reg, Operand(input_reg, times_2, kHeapObjectTag));
4874 if (instr->truncating()) {
4875 Label no_heap_number, check_bools, check_false;
4877 // Heap number map check.
4878 __ cmp(FieldOperand(input_reg, HeapObject::kMapOffset),
4879 factory()->heap_number_map());
4880 __ j(not_equal, &no_heap_number, Label::kNear);
4881 __ TruncateHeapNumberToI(input_reg, input_reg);
4884 __ bind(&no_heap_number);
4885 // Check for Oddballs. Undefined/False is converted to zero and True to one
4886 // for truncating conversions.
4887 __ cmp(input_reg, factory()->undefined_value());
4888 __ j(not_equal, &check_bools, Label::kNear);
4889 __ Move(input_reg, Immediate(0));
4892 __ bind(&check_bools);
4893 __ cmp(input_reg, factory()->true_value());
4894 __ j(not_equal, &check_false, Label::kNear);
4895 __ Move(input_reg, Immediate(1));
4898 __ bind(&check_false);
4899 __ cmp(input_reg, factory()->false_value());
4900 DeoptimizeIf(not_equal, instr,
4901 Deoptimizer::kNotAHeapNumberUndefinedBoolean);
4902 __ Move(input_reg, Immediate(0));
4904 XMMRegister scratch = ToDoubleRegister(instr->temp());
4905 DCHECK(!scratch.is(xmm0));
4906 __ cmp(FieldOperand(input_reg, HeapObject::kMapOffset),
4907 isolate()->factory()->heap_number_map());
4908 DeoptimizeIf(not_equal, instr, Deoptimizer::kNotAHeapNumber);
4909 __ movsd(xmm0, FieldOperand(input_reg, HeapNumber::kValueOffset));
4910 __ cvttsd2si(input_reg, Operand(xmm0));
4911 __ Cvtsi2sd(scratch, Operand(input_reg));
4912 __ ucomisd(xmm0, scratch);
4913 DeoptimizeIf(not_equal, instr, Deoptimizer::kLostPrecision);
4914 DeoptimizeIf(parity_even, instr, Deoptimizer::kNaN);
4915 if (instr->hydrogen()->GetMinusZeroMode() == FAIL_ON_MINUS_ZERO) {
4916 __ test(input_reg, Operand(input_reg));
4917 __ j(not_zero, done);
4918 __ movmskpd(input_reg, xmm0);
4919 __ and_(input_reg, 1);
4920 DeoptimizeIf(not_zero, instr, Deoptimizer::kMinusZero);
4926 void LCodeGen::DoTaggedToI(LTaggedToI* instr) {
4927 class DeferredTaggedToI final : public LDeferredCode {
4929 DeferredTaggedToI(LCodeGen* codegen, LTaggedToI* instr)
4930 : LDeferredCode(codegen), instr_(instr) { }
4931 void Generate() override { codegen()->DoDeferredTaggedToI(instr_, done()); }
4932 LInstruction* instr() override { return instr_; }
4938 LOperand* input = instr->value();
4939 DCHECK(input->IsRegister());
4940 Register input_reg = ToRegister(input);
4941 DCHECK(input_reg.is(ToRegister(instr->result())));
4943 if (instr->hydrogen()->value()->representation().IsSmi()) {
4944 __ SmiUntag(input_reg);
4946 DeferredTaggedToI* deferred =
4947 new(zone()) DeferredTaggedToI(this, instr);
4948 // Optimistically untag the input.
4949 // If the input is a HeapObject, SmiUntag will set the carry flag.
4950 STATIC_ASSERT(kSmiTagSize == 1 && kSmiTag == 0);
4951 __ SmiUntag(input_reg);
4952 // Branch to deferred code if the input was tagged.
4953 // The deferred code will take care of restoring the tag.
4954 __ j(carry, deferred->entry());
4955 __ bind(deferred->exit());
4960 void LCodeGen::DoNumberUntagD(LNumberUntagD* instr) {
4961 LOperand* input = instr->value();
4962 DCHECK(input->IsRegister());
4963 LOperand* temp = instr->temp();
4964 DCHECK(temp->IsRegister());
4965 LOperand* result = instr->result();
4966 DCHECK(result->IsDoubleRegister());
4968 Register input_reg = ToRegister(input);
4969 Register temp_reg = ToRegister(temp);
4971 HValue* value = instr->hydrogen()->value();
4972 NumberUntagDMode mode = value->representation().IsSmi()
4973 ? NUMBER_CANDIDATE_IS_SMI : NUMBER_CANDIDATE_IS_ANY_TAGGED;
4975 XMMRegister result_reg = ToDoubleRegister(result);
4976 EmitNumberUntagD(instr, input_reg, temp_reg, result_reg, mode);
4980 void LCodeGen::DoDoubleToI(LDoubleToI* instr) {
4981 LOperand* input = instr->value();
4982 DCHECK(input->IsDoubleRegister());
4983 LOperand* result = instr->result();
4984 DCHECK(result->IsRegister());
4985 Register result_reg = ToRegister(result);
4987 if (instr->truncating()) {
4988 XMMRegister input_reg = ToDoubleRegister(input);
4989 __ TruncateDoubleToI(result_reg, input_reg);
4991 Label lost_precision, is_nan, minus_zero, done;
4992 XMMRegister input_reg = ToDoubleRegister(input);
4993 XMMRegister xmm_scratch = double_scratch0();
4994 Label::Distance dist = DeoptEveryNTimes() ? Label::kFar : Label::kNear;
4995 __ DoubleToI(result_reg, input_reg, xmm_scratch,
4996 instr->hydrogen()->GetMinusZeroMode(), &lost_precision,
4997 &is_nan, &minus_zero, dist);
4998 __ jmp(&done, dist);
4999 __ bind(&lost_precision);
5000 DeoptimizeIf(no_condition, instr, Deoptimizer::kLostPrecision);
5002 DeoptimizeIf(no_condition, instr, Deoptimizer::kNaN);
5003 __ bind(&minus_zero);
5004 DeoptimizeIf(no_condition, instr, Deoptimizer::kMinusZero);
5010 void LCodeGen::DoDoubleToSmi(LDoubleToSmi* instr) {
5011 LOperand* input = instr->value();
5012 DCHECK(input->IsDoubleRegister());
5013 LOperand* result = instr->result();
5014 DCHECK(result->IsRegister());
5015 Register result_reg = ToRegister(result);
5017 Label lost_precision, is_nan, minus_zero, done;
5018 XMMRegister input_reg = ToDoubleRegister(input);
5019 XMMRegister xmm_scratch = double_scratch0();
5020 Label::Distance dist = DeoptEveryNTimes() ? Label::kFar : Label::kNear;
5021 __ DoubleToI(result_reg, input_reg, xmm_scratch,
5022 instr->hydrogen()->GetMinusZeroMode(), &lost_precision, &is_nan,
5024 __ jmp(&done, dist);
5025 __ bind(&lost_precision);
5026 DeoptimizeIf(no_condition, instr, Deoptimizer::kLostPrecision);
5028 DeoptimizeIf(no_condition, instr, Deoptimizer::kNaN);
5029 __ bind(&minus_zero);
5030 DeoptimizeIf(no_condition, instr, Deoptimizer::kMinusZero);
5032 __ SmiTag(result_reg);
5033 DeoptimizeIf(overflow, instr, Deoptimizer::kOverflow);
5037 void LCodeGen::DoCheckSmi(LCheckSmi* instr) {
5038 LOperand* input = instr->value();
5039 __ test(ToOperand(input), Immediate(kSmiTagMask));
5040 DeoptimizeIf(not_zero, instr, Deoptimizer::kNotASmi);
5044 void LCodeGen::DoCheckNonSmi(LCheckNonSmi* instr) {
5045 if (!instr->hydrogen()->value()->type().IsHeapObject()) {
5046 LOperand* input = instr->value();
5047 __ test(ToOperand(input), Immediate(kSmiTagMask));
5048 DeoptimizeIf(zero, instr, Deoptimizer::kSmi);
5053 void LCodeGen::DoCheckArrayBufferNotNeutered(
5054 LCheckArrayBufferNotNeutered* instr) {
5055 Register view = ToRegister(instr->view());
5056 Register scratch = ToRegister(instr->scratch());
5058 __ mov(scratch, FieldOperand(view, JSArrayBufferView::kBufferOffset));
5059 __ test_b(FieldOperand(scratch, JSArrayBuffer::kBitFieldOffset),
5060 1 << JSArrayBuffer::WasNeutered::kShift);
5061 DeoptimizeIf(not_zero, instr, Deoptimizer::kOutOfBounds);
5065 void LCodeGen::DoCheckInstanceType(LCheckInstanceType* instr) {
5066 Register input = ToRegister(instr->value());
5067 Register temp = ToRegister(instr->temp());
5069 __ mov(temp, FieldOperand(input, HeapObject::kMapOffset));
5071 if (instr->hydrogen()->is_interval_check()) {
5074 instr->hydrogen()->GetCheckInterval(&first, &last);
5076 __ cmpb(FieldOperand(temp, Map::kInstanceTypeOffset),
5077 static_cast<int8_t>(first));
5079 // If there is only one type in the interval check for equality.
5080 if (first == last) {
5081 DeoptimizeIf(not_equal, instr, Deoptimizer::kWrongInstanceType);
5083 DeoptimizeIf(below, instr, Deoptimizer::kWrongInstanceType);
5084 // Omit check for the last type.
5085 if (last != LAST_TYPE) {
5086 __ cmpb(FieldOperand(temp, Map::kInstanceTypeOffset),
5087 static_cast<int8_t>(last));
5088 DeoptimizeIf(above, instr, Deoptimizer::kWrongInstanceType);
5094 instr->hydrogen()->GetCheckMaskAndTag(&mask, &tag);
5096 if (base::bits::IsPowerOfTwo32(mask)) {
5097 DCHECK(tag == 0 || base::bits::IsPowerOfTwo32(tag));
5098 __ test_b(FieldOperand(temp, Map::kInstanceTypeOffset), mask);
5099 DeoptimizeIf(tag == 0 ? not_zero : zero, instr,
5100 Deoptimizer::kWrongInstanceType);
5102 __ movzx_b(temp, FieldOperand(temp, Map::kInstanceTypeOffset));
5103 __ and_(temp, mask);
5105 DeoptimizeIf(not_equal, instr, Deoptimizer::kWrongInstanceType);
5111 void LCodeGen::DoCheckValue(LCheckValue* instr) {
5112 Handle<HeapObject> object = instr->hydrogen()->object().handle();
5113 if (instr->hydrogen()->object_in_new_space()) {
5114 Register reg = ToRegister(instr->value());
5115 Handle<Cell> cell = isolate()->factory()->NewCell(object);
5116 __ cmp(reg, Operand::ForCell(cell));
5118 Operand operand = ToOperand(instr->value());
5119 __ cmp(operand, object);
5121 DeoptimizeIf(not_equal, instr, Deoptimizer::kValueMismatch);
5125 void LCodeGen::DoDeferredInstanceMigration(LCheckMaps* instr, Register object) {
5127 PushSafepointRegistersScope scope(this);
5130 __ CallRuntimeSaveDoubles(Runtime::kTryMigrateInstance);
5131 RecordSafepointWithRegisters(
5132 instr->pointer_map(), 1, Safepoint::kNoLazyDeopt);
5134 __ test(eax, Immediate(kSmiTagMask));
5136 DeoptimizeIf(zero, instr, Deoptimizer::kInstanceMigrationFailed);
5140 void LCodeGen::DoCheckMaps(LCheckMaps* instr) {
5141 class DeferredCheckMaps final : public LDeferredCode {
5143 DeferredCheckMaps(LCodeGen* codegen, LCheckMaps* instr, Register object)
5144 : LDeferredCode(codegen), instr_(instr), object_(object) {
5145 SetExit(check_maps());
5147 void Generate() override {
5148 codegen()->DoDeferredInstanceMigration(instr_, object_);
5150 Label* check_maps() { return &check_maps_; }
5151 LInstruction* instr() override { return instr_; }
5159 if (instr->hydrogen()->IsStabilityCheck()) {
5160 const UniqueSet<Map>* maps = instr->hydrogen()->maps();
5161 for (int i = 0; i < maps->size(); ++i) {
5162 AddStabilityDependency(maps->at(i).handle());
5167 LOperand* input = instr->value();
5168 DCHECK(input->IsRegister());
5169 Register reg = ToRegister(input);
5171 DeferredCheckMaps* deferred = NULL;
5172 if (instr->hydrogen()->HasMigrationTarget()) {
5173 deferred = new(zone()) DeferredCheckMaps(this, instr, reg);
5174 __ bind(deferred->check_maps());
5177 const UniqueSet<Map>* maps = instr->hydrogen()->maps();
5179 for (int i = 0; i < maps->size() - 1; i++) {
5180 Handle<Map> map = maps->at(i).handle();
5181 __ CompareMap(reg, map);
5182 __ j(equal, &success, Label::kNear);
5185 Handle<Map> map = maps->at(maps->size() - 1).handle();
5186 __ CompareMap(reg, map);
5187 if (instr->hydrogen()->HasMigrationTarget()) {
5188 __ j(not_equal, deferred->entry());
5190 DeoptimizeIf(not_equal, instr, Deoptimizer::kWrongMap);
5197 void LCodeGen::DoClampDToUint8(LClampDToUint8* instr) {
5198 XMMRegister value_reg = ToDoubleRegister(instr->unclamped());
5199 XMMRegister xmm_scratch = double_scratch0();
5200 Register result_reg = ToRegister(instr->result());
5201 __ ClampDoubleToUint8(value_reg, xmm_scratch, result_reg);
5205 void LCodeGen::DoClampIToUint8(LClampIToUint8* instr) {
5206 DCHECK(instr->unclamped()->Equals(instr->result()));
5207 Register value_reg = ToRegister(instr->result());
5208 __ ClampUint8(value_reg);
5212 void LCodeGen::DoClampTToUint8(LClampTToUint8* instr) {
5213 DCHECK(instr->unclamped()->Equals(instr->result()));
5214 Register input_reg = ToRegister(instr->unclamped());
5215 XMMRegister temp_xmm_reg = ToDoubleRegister(instr->temp_xmm());
5216 XMMRegister xmm_scratch = double_scratch0();
5217 Label is_smi, done, heap_number;
5219 __ JumpIfSmi(input_reg, &is_smi);
5221 // Check for heap number
5222 __ cmp(FieldOperand(input_reg, HeapObject::kMapOffset),
5223 factory()->heap_number_map());
5224 __ j(equal, &heap_number, Label::kNear);
5226 // Check for undefined. Undefined is converted to zero for clamping
5228 __ cmp(input_reg, factory()->undefined_value());
5229 DeoptimizeIf(not_equal, instr, Deoptimizer::kNotAHeapNumberUndefined);
5230 __ mov(input_reg, 0);
5231 __ jmp(&done, Label::kNear);
5234 __ bind(&heap_number);
5235 __ movsd(xmm_scratch, FieldOperand(input_reg, HeapNumber::kValueOffset));
5236 __ ClampDoubleToUint8(xmm_scratch, temp_xmm_reg, input_reg);
5237 __ jmp(&done, Label::kNear);
5241 __ SmiUntag(input_reg);
5242 __ ClampUint8(input_reg);
5247 void LCodeGen::DoDoubleBits(LDoubleBits* instr) {
5248 XMMRegister value_reg = ToDoubleRegister(instr->value());
5249 Register result_reg = ToRegister(instr->result());
5250 if (instr->hydrogen()->bits() == HDoubleBits::HIGH) {
5251 if (CpuFeatures::IsSupported(SSE4_1)) {
5252 CpuFeatureScope scope2(masm(), SSE4_1);
5253 __ pextrd(result_reg, value_reg, 1);
5255 XMMRegister xmm_scratch = double_scratch0();
5256 __ pshufd(xmm_scratch, value_reg, 1);
5257 __ movd(result_reg, xmm_scratch);
5260 __ movd(result_reg, value_reg);
5265 void LCodeGen::DoConstructDouble(LConstructDouble* instr) {
5266 Register hi_reg = ToRegister(instr->hi());
5267 Register lo_reg = ToRegister(instr->lo());
5268 XMMRegister result_reg = ToDoubleRegister(instr->result());
5270 if (CpuFeatures::IsSupported(SSE4_1)) {
5271 CpuFeatureScope scope2(masm(), SSE4_1);
5272 __ movd(result_reg, lo_reg);
5273 __ pinsrd(result_reg, hi_reg, 1);
5275 XMMRegister xmm_scratch = double_scratch0();
5276 __ movd(result_reg, hi_reg);
5277 __ psllq(result_reg, 32);
5278 __ movd(xmm_scratch, lo_reg);
5279 __ orps(result_reg, xmm_scratch);
5284 void LCodeGen::DoAllocate(LAllocate* instr) {
5285 class DeferredAllocate final : public LDeferredCode {
5287 DeferredAllocate(LCodeGen* codegen, LAllocate* instr)
5288 : LDeferredCode(codegen), instr_(instr) { }
5289 void Generate() override { codegen()->DoDeferredAllocate(instr_); }
5290 LInstruction* instr() override { return instr_; }
5296 DeferredAllocate* deferred = new(zone()) DeferredAllocate(this, instr);
5298 Register result = ToRegister(instr->result());
5299 Register temp = ToRegister(instr->temp());
5301 // Allocate memory for the object.
5302 AllocationFlags flags = TAG_OBJECT;
5303 if (instr->hydrogen()->MustAllocateDoubleAligned()) {
5304 flags = static_cast<AllocationFlags>(flags | DOUBLE_ALIGNMENT);
5306 if (instr->hydrogen()->IsOldSpaceAllocation()) {
5307 DCHECK(!instr->hydrogen()->IsNewSpaceAllocation());
5308 flags = static_cast<AllocationFlags>(flags | PRETENURE);
5311 if (instr->size()->IsConstantOperand()) {
5312 int32_t size = ToInteger32(LConstantOperand::cast(instr->size()));
5313 if (size <= Page::kMaxRegularHeapObjectSize) {
5314 __ Allocate(size, result, temp, no_reg, deferred->entry(), flags);
5316 __ jmp(deferred->entry());
5319 Register size = ToRegister(instr->size());
5320 __ Allocate(size, result, temp, no_reg, deferred->entry(), flags);
5323 __ bind(deferred->exit());
5325 if (instr->hydrogen()->MustPrefillWithFiller()) {
5326 if (instr->size()->IsConstantOperand()) {
5327 int32_t size = ToInteger32(LConstantOperand::cast(instr->size()));
5328 __ mov(temp, (size / kPointerSize) - 1);
5330 temp = ToRegister(instr->size());
5331 __ shr(temp, kPointerSizeLog2);
5336 __ mov(FieldOperand(result, temp, times_pointer_size, 0),
5337 isolate()->factory()->one_pointer_filler_map());
5339 __ j(not_zero, &loop);
5344 void LCodeGen::DoDeferredAllocate(LAllocate* instr) {
5345 Register result = ToRegister(instr->result());
5347 // TODO(3095996): Get rid of this. For now, we need to make the
5348 // result register contain a valid pointer because it is already
5349 // contained in the register pointer map.
5350 __ Move(result, Immediate(Smi::FromInt(0)));
5352 PushSafepointRegistersScope scope(this);
5353 if (instr->size()->IsRegister()) {
5354 Register size = ToRegister(instr->size());
5355 DCHECK(!size.is(result));
5356 __ SmiTag(ToRegister(instr->size()));
5359 int32_t size = ToInteger32(LConstantOperand::cast(instr->size()));
5360 if (size >= 0 && size <= Smi::kMaxValue) {
5361 __ push(Immediate(Smi::FromInt(size)));
5363 // We should never get here at runtime => abort
5369 int flags = AllocateDoubleAlignFlag::encode(
5370 instr->hydrogen()->MustAllocateDoubleAligned());
5371 if (instr->hydrogen()->IsOldSpaceAllocation()) {
5372 DCHECK(!instr->hydrogen()->IsNewSpaceAllocation());
5373 flags = AllocateTargetSpace::update(flags, OLD_SPACE);
5375 flags = AllocateTargetSpace::update(flags, NEW_SPACE);
5377 __ push(Immediate(Smi::FromInt(flags)));
5379 CallRuntimeFromDeferred(
5380 Runtime::kAllocateInTargetSpace, 2, instr, instr->context());
5381 __ StoreToSafepointRegisterSlot(result, eax);
5385 void LCodeGen::DoToFastProperties(LToFastProperties* instr) {
5386 DCHECK(ToRegister(instr->value()).is(eax));
5388 CallRuntime(Runtime::kToFastProperties, 1, instr);
5392 void LCodeGen::DoRegExpLiteral(LRegExpLiteral* instr) {
5393 DCHECK(ToRegister(instr->context()).is(esi));
5395 // Registers will be used as follows:
5396 // ecx = literals array.
5397 // ebx = regexp literal.
5398 // eax = regexp literal clone.
5400 int literal_offset =
5401 FixedArray::OffsetOfElementAt(instr->hydrogen()->literal_index());
5402 __ LoadHeapObject(ecx, instr->hydrogen()->literals());
5403 __ mov(ebx, FieldOperand(ecx, literal_offset));
5404 __ cmp(ebx, factory()->undefined_value());
5405 __ j(not_equal, &materialized, Label::kNear);
5407 // Create regexp literal using runtime function
5408 // Result will be in eax.
5410 __ push(Immediate(Smi::FromInt(instr->hydrogen()->literal_index())));
5411 __ push(Immediate(instr->hydrogen()->pattern()));
5412 __ push(Immediate(instr->hydrogen()->flags()));
5413 CallRuntime(Runtime::kMaterializeRegExpLiteral, 4, instr);
5416 __ bind(&materialized);
5417 int size = JSRegExp::kSize + JSRegExp::kInObjectFieldCount * kPointerSize;
5418 Label allocated, runtime_allocate;
5419 __ Allocate(size, eax, ecx, edx, &runtime_allocate, TAG_OBJECT);
5420 __ jmp(&allocated, Label::kNear);
5422 __ bind(&runtime_allocate);
5424 __ push(Immediate(Smi::FromInt(size)));
5425 CallRuntime(Runtime::kAllocateInNewSpace, 1, instr);
5428 __ bind(&allocated);
5429 // Copy the content into the newly allocated memory.
5430 // (Unroll copy loop once for better throughput).
5431 for (int i = 0; i < size - kPointerSize; i += 2 * kPointerSize) {
5432 __ mov(edx, FieldOperand(ebx, i));
5433 __ mov(ecx, FieldOperand(ebx, i + kPointerSize));
5434 __ mov(FieldOperand(eax, i), edx);
5435 __ mov(FieldOperand(eax, i + kPointerSize), ecx);
5437 if ((size % (2 * kPointerSize)) != 0) {
5438 __ mov(edx, FieldOperand(ebx, size - kPointerSize));
5439 __ mov(FieldOperand(eax, size - kPointerSize), edx);
5444 void LCodeGen::DoFunctionLiteral(LFunctionLiteral* instr) {
5445 DCHECK(ToRegister(instr->context()).is(esi));
5446 // Use the fast case closure allocation code that allocates in new
5447 // space for nested functions that don't need literals cloning.
5448 bool pretenure = instr->hydrogen()->pretenure();
5449 if (!pretenure && instr->hydrogen()->has_no_literals()) {
5450 FastNewClosureStub stub(isolate(), instr->hydrogen()->language_mode(),
5451 instr->hydrogen()->kind());
5452 __ mov(ebx, Immediate(instr->hydrogen()->shared_info()));
5453 CallCode(stub.GetCode(), RelocInfo::CODE_TARGET, instr);
5456 __ push(Immediate(instr->hydrogen()->shared_info()));
5457 __ push(Immediate(pretenure ? factory()->true_value()
5458 : factory()->false_value()));
5459 CallRuntime(Runtime::kNewClosure, 3, instr);
5464 void LCodeGen::DoTypeof(LTypeof* instr) {
5465 DCHECK(ToRegister(instr->context()).is(esi));
5466 DCHECK(ToRegister(instr->value()).is(ebx));
5468 Register value_register = ToRegister(instr->value());
5469 __ JumpIfNotSmi(value_register, &do_call);
5470 __ mov(eax, Immediate(isolate()->factory()->number_string()));
5473 TypeofStub stub(isolate());
5474 CallCode(stub.GetCode(), RelocInfo::CODE_TARGET, instr);
5479 void LCodeGen::DoTypeofIsAndBranch(LTypeofIsAndBranch* instr) {
5480 Register input = ToRegister(instr->value());
5481 Condition final_branch_condition = EmitTypeofIs(instr, input);
5482 if (final_branch_condition != no_condition) {
5483 EmitBranch(instr, final_branch_condition);
5488 Condition LCodeGen::EmitTypeofIs(LTypeofIsAndBranch* instr, Register input) {
5489 Label* true_label = instr->TrueLabel(chunk_);
5490 Label* false_label = instr->FalseLabel(chunk_);
5491 Handle<String> type_name = instr->type_literal();
5492 int left_block = instr->TrueDestination(chunk_);
5493 int right_block = instr->FalseDestination(chunk_);
5494 int next_block = GetNextEmittedBlock();
5496 Label::Distance true_distance = left_block == next_block ? Label::kNear
5498 Label::Distance false_distance = right_block == next_block ? Label::kNear
5500 Condition final_branch_condition = no_condition;
5501 if (String::Equals(type_name, factory()->number_string())) {
5502 __ JumpIfSmi(input, true_label, true_distance);
5503 __ cmp(FieldOperand(input, HeapObject::kMapOffset),
5504 factory()->heap_number_map());
5505 final_branch_condition = equal;
5507 } else if (String::Equals(type_name, factory()->string_string())) {
5508 __ JumpIfSmi(input, false_label, false_distance);
5509 __ CmpObjectType(input, FIRST_NONSTRING_TYPE, input);
5510 __ j(above_equal, false_label, false_distance);
5511 __ test_b(FieldOperand(input, Map::kBitFieldOffset),
5512 1 << Map::kIsUndetectable);
5513 final_branch_condition = zero;
5515 } else if (String::Equals(type_name, factory()->symbol_string())) {
5516 __ JumpIfSmi(input, false_label, false_distance);
5517 __ CmpObjectType(input, SYMBOL_TYPE, input);
5518 final_branch_condition = equal;
5520 } else if (String::Equals(type_name, factory()->boolean_string())) {
5521 __ cmp(input, factory()->true_value());
5522 __ j(equal, true_label, true_distance);
5523 __ cmp(input, factory()->false_value());
5524 final_branch_condition = equal;
5526 } else if (String::Equals(type_name, factory()->undefined_string())) {
5527 __ cmp(input, factory()->undefined_value());
5528 __ j(equal, true_label, true_distance);
5529 __ JumpIfSmi(input, false_label, false_distance);
5530 // Check for undetectable objects => true.
5531 __ mov(input, FieldOperand(input, HeapObject::kMapOffset));
5532 __ test_b(FieldOperand(input, Map::kBitFieldOffset),
5533 1 << Map::kIsUndetectable);
5534 final_branch_condition = not_zero;
5536 } else if (String::Equals(type_name, factory()->function_string())) {
5537 STATIC_ASSERT(NUM_OF_CALLABLE_SPEC_OBJECT_TYPES == 2);
5538 __ JumpIfSmi(input, false_label, false_distance);
5539 __ CmpObjectType(input, JS_FUNCTION_TYPE, input);
5540 __ j(equal, true_label, true_distance);
5541 __ CmpInstanceType(input, JS_FUNCTION_PROXY_TYPE);
5542 final_branch_condition = equal;
5544 } else if (String::Equals(type_name, factory()->object_string())) {
5545 __ JumpIfSmi(input, false_label, false_distance);
5546 __ cmp(input, factory()->null_value());
5547 __ j(equal, true_label, true_distance);
5548 __ CmpObjectType(input, FIRST_NONCALLABLE_SPEC_OBJECT_TYPE, input);
5549 __ j(below, false_label, false_distance);
5550 __ CmpInstanceType(input, LAST_NONCALLABLE_SPEC_OBJECT_TYPE);
5551 __ j(above, false_label, false_distance);
5552 // Check for undetectable objects => false.
5553 __ test_b(FieldOperand(input, Map::kBitFieldOffset),
5554 1 << Map::kIsUndetectable);
5555 final_branch_condition = zero;
5557 } else if (String::Equals(type_name, factory()->float32x4_string())) {
5558 __ JumpIfSmi(input, false_label, false_distance);
5559 __ CmpObjectType(input, FLOAT32X4_TYPE, input);
5560 final_branch_condition = equal;
5563 __ jmp(false_label, false_distance);
5565 return final_branch_condition;
5569 void LCodeGen::DoIsConstructCallAndBranch(LIsConstructCallAndBranch* instr) {
5570 Register temp = ToRegister(instr->temp());
5572 EmitIsConstructCall(temp);
5573 EmitBranch(instr, equal);
5577 void LCodeGen::EmitIsConstructCall(Register temp) {
5578 // Get the frame pointer for the calling frame.
5579 __ mov(temp, Operand(ebp, StandardFrameConstants::kCallerFPOffset));
5581 // Skip the arguments adaptor frame if it exists.
5582 Label check_frame_marker;
5583 __ cmp(Operand(temp, StandardFrameConstants::kContextOffset),
5584 Immediate(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR)));
5585 __ j(not_equal, &check_frame_marker, Label::kNear);
5586 __ mov(temp, Operand(temp, StandardFrameConstants::kCallerFPOffset));
5588 // Check the marker in the calling frame.
5589 __ bind(&check_frame_marker);
5590 __ cmp(Operand(temp, StandardFrameConstants::kMarkerOffset),
5591 Immediate(Smi::FromInt(StackFrame::CONSTRUCT)));
5595 void LCodeGen::EnsureSpaceForLazyDeopt(int space_needed) {
5596 if (!info()->IsStub()) {
5597 // Ensure that we have enough space after the previous lazy-bailout
5598 // instruction for patching the code here.
5599 int current_pc = masm()->pc_offset();
5600 if (current_pc < last_lazy_deopt_pc_ + space_needed) {
5601 int padding_size = last_lazy_deopt_pc_ + space_needed - current_pc;
5602 __ Nop(padding_size);
5605 last_lazy_deopt_pc_ = masm()->pc_offset();
5609 void LCodeGen::DoLazyBailout(LLazyBailout* instr) {
5610 last_lazy_deopt_pc_ = masm()->pc_offset();
5611 DCHECK(instr->HasEnvironment());
5612 LEnvironment* env = instr->environment();
5613 RegisterEnvironmentForDeoptimization(env, Safepoint::kLazyDeopt);
5614 safepoints_.RecordLazyDeoptimizationIndex(env->deoptimization_index());
5618 void LCodeGen::DoDeoptimize(LDeoptimize* instr) {
5619 Deoptimizer::BailoutType type = instr->hydrogen()->type();
5620 // TODO(danno): Stubs expect all deopts to be lazy for historical reasons (the
5621 // needed return address), even though the implementation of LAZY and EAGER is
5622 // now identical. When LAZY is eventually completely folded into EAGER, remove
5623 // the special case below.
5624 if (info()->IsStub() && type == Deoptimizer::EAGER) {
5625 type = Deoptimizer::LAZY;
5627 DeoptimizeIf(no_condition, instr, instr->hydrogen()->reason(), type);
5631 void LCodeGen::DoDummy(LDummy* instr) {
5632 // Nothing to see here, move on!
5636 void LCodeGen::DoDummyUse(LDummyUse* instr) {
5637 // Nothing to see here, move on!
5641 void LCodeGen::DoDeferredStackCheck(LStackCheck* instr) {
5642 PushSafepointRegistersScope scope(this);
5643 __ mov(esi, Operand(ebp, StandardFrameConstants::kContextOffset));
5644 __ CallRuntimeSaveDoubles(Runtime::kStackGuard);
5645 RecordSafepointWithLazyDeopt(
5646 instr, RECORD_SAFEPOINT_WITH_REGISTERS_AND_NO_ARGUMENTS);
5647 DCHECK(instr->HasEnvironment());
5648 LEnvironment* env = instr->environment();
5649 safepoints_.RecordLazyDeoptimizationIndex(env->deoptimization_index());
5653 void LCodeGen::DoStackCheck(LStackCheck* instr) {
5654 class DeferredStackCheck final : public LDeferredCode {
5656 DeferredStackCheck(LCodeGen* codegen, LStackCheck* instr)
5657 : LDeferredCode(codegen), instr_(instr) { }
5658 void Generate() override { codegen()->DoDeferredStackCheck(instr_); }
5659 LInstruction* instr() override { return instr_; }
5662 LStackCheck* instr_;
5665 DCHECK(instr->HasEnvironment());
5666 LEnvironment* env = instr->environment();
5667 // There is no LLazyBailout instruction for stack-checks. We have to
5668 // prepare for lazy deoptimization explicitly here.
5669 if (instr->hydrogen()->is_function_entry()) {
5670 // Perform stack overflow check.
5672 ExternalReference stack_limit =
5673 ExternalReference::address_of_stack_limit(isolate());
5674 __ cmp(esp, Operand::StaticVariable(stack_limit));
5675 __ j(above_equal, &done, Label::kNear);
5677 DCHECK(instr->context()->IsRegister());
5678 DCHECK(ToRegister(instr->context()).is(esi));
5679 CallCode(isolate()->builtins()->StackCheck(),
5680 RelocInfo::CODE_TARGET,
5684 DCHECK(instr->hydrogen()->is_backwards_branch());
5685 // Perform stack overflow check if this goto needs it before jumping.
5686 DeferredStackCheck* deferred_stack_check =
5687 new(zone()) DeferredStackCheck(this, instr);
5688 ExternalReference stack_limit =
5689 ExternalReference::address_of_stack_limit(isolate());
5690 __ cmp(esp, Operand::StaticVariable(stack_limit));
5691 __ j(below, deferred_stack_check->entry());
5692 EnsureSpaceForLazyDeopt(Deoptimizer::patch_size());
5693 __ bind(instr->done_label());
5694 deferred_stack_check->SetExit(instr->done_label());
5695 RegisterEnvironmentForDeoptimization(env, Safepoint::kLazyDeopt);
5696 // Don't record a deoptimization index for the safepoint here.
5697 // This will be done explicitly when emitting call and the safepoint in
5698 // the deferred code.
5703 void LCodeGen::DoOsrEntry(LOsrEntry* instr) {
5704 // This is a pseudo-instruction that ensures that the environment here is
5705 // properly registered for deoptimization and records the assembler's PC
5707 LEnvironment* environment = instr->environment();
5709 // If the environment were already registered, we would have no way of
5710 // backpatching it with the spill slot operands.
5711 DCHECK(!environment->HasBeenRegistered());
5712 RegisterEnvironmentForDeoptimization(environment, Safepoint::kNoLazyDeopt);
5714 GenerateOsrPrologue();
5718 void LCodeGen::DoForInPrepareMap(LForInPrepareMap* instr) {
5719 DCHECK(ToRegister(instr->context()).is(esi));
5720 __ test(eax, Immediate(kSmiTagMask));
5721 DeoptimizeIf(zero, instr, Deoptimizer::kSmi);
5723 STATIC_ASSERT(FIRST_JS_PROXY_TYPE == FIRST_SPEC_OBJECT_TYPE);
5724 __ CmpObjectType(eax, LAST_JS_PROXY_TYPE, ecx);
5725 DeoptimizeIf(below_equal, instr, Deoptimizer::kWrongInstanceType);
5727 Label use_cache, call_runtime;
5728 __ CheckEnumCache(&call_runtime);
5730 __ mov(eax, FieldOperand(eax, HeapObject::kMapOffset));
5731 __ jmp(&use_cache, Label::kNear);
5733 // Get the set of properties to enumerate.
5734 __ bind(&call_runtime);
5736 CallRuntime(Runtime::kGetPropertyNamesFast, 1, instr);
5738 __ cmp(FieldOperand(eax, HeapObject::kMapOffset),
5739 isolate()->factory()->meta_map());
5740 DeoptimizeIf(not_equal, instr, Deoptimizer::kWrongMap);
5741 __ bind(&use_cache);
5745 void LCodeGen::DoForInCacheArray(LForInCacheArray* instr) {
5746 Register map = ToRegister(instr->map());
5747 Register result = ToRegister(instr->result());
5748 Label load_cache, done;
5749 __ EnumLength(result, map);
5750 __ cmp(result, Immediate(Smi::FromInt(0)));
5751 __ j(not_equal, &load_cache, Label::kNear);
5752 __ mov(result, isolate()->factory()->empty_fixed_array());
5753 __ jmp(&done, Label::kNear);
5755 __ bind(&load_cache);
5756 __ LoadInstanceDescriptors(map, result);
5758 FieldOperand(result, DescriptorArray::kEnumCacheOffset));
5760 FieldOperand(result, FixedArray::SizeFor(instr->idx())));
5762 __ test(result, result);
5763 DeoptimizeIf(equal, instr, Deoptimizer::kNoCache);
5767 void LCodeGen::DoCheckMapValue(LCheckMapValue* instr) {
5768 Register object = ToRegister(instr->value());
5769 __ cmp(ToRegister(instr->map()),
5770 FieldOperand(object, HeapObject::kMapOffset));
5771 DeoptimizeIf(not_equal, instr, Deoptimizer::kWrongMap);
5775 void LCodeGen::DoDeferredLoadMutableDouble(LLoadFieldByIndex* instr,
5778 PushSafepointRegistersScope scope(this);
5782 __ CallRuntimeSaveDoubles(Runtime::kLoadMutableDouble);
5783 RecordSafepointWithRegisters(
5784 instr->pointer_map(), 2, Safepoint::kNoLazyDeopt);
5785 __ StoreToSafepointRegisterSlot(object, eax);
5789 void LCodeGen::DoLoadFieldByIndex(LLoadFieldByIndex* instr) {
5790 class DeferredLoadMutableDouble final : public LDeferredCode {
5792 DeferredLoadMutableDouble(LCodeGen* codegen,
5793 LLoadFieldByIndex* instr,
5796 : LDeferredCode(codegen),
5801 void Generate() override {
5802 codegen()->DoDeferredLoadMutableDouble(instr_, object_, index_);
5804 LInstruction* instr() override { return instr_; }
5807 LLoadFieldByIndex* instr_;
5812 Register object = ToRegister(instr->object());
5813 Register index = ToRegister(instr->index());
5815 DeferredLoadMutableDouble* deferred;
5816 deferred = new(zone()) DeferredLoadMutableDouble(
5817 this, instr, object, index);
5819 Label out_of_object, done;
5820 __ test(index, Immediate(Smi::FromInt(1)));
5821 __ j(not_zero, deferred->entry());
5825 __ cmp(index, Immediate(0));
5826 __ j(less, &out_of_object, Label::kNear);
5827 __ mov(object, FieldOperand(object,
5829 times_half_pointer_size,
5830 JSObject::kHeaderSize));
5831 __ jmp(&done, Label::kNear);
5833 __ bind(&out_of_object);
5834 __ mov(object, FieldOperand(object, JSObject::kPropertiesOffset));
5836 // Index is now equal to out of object property index plus 1.
5837 __ mov(object, FieldOperand(object,
5839 times_half_pointer_size,
5840 FixedArray::kHeaderSize - kPointerSize));
5841 __ bind(deferred->exit());
5846 void LCodeGen::DoStoreFrameContext(LStoreFrameContext* instr) {
5847 Register context = ToRegister(instr->context());
5848 __ mov(Operand(ebp, StandardFrameConstants::kContextOffset), context);
5852 void LCodeGen::DoAllocateBlockContext(LAllocateBlockContext* instr) {
5853 Handle<ScopeInfo> scope_info = instr->scope_info();
5854 __ Push(scope_info);
5855 __ push(ToRegister(instr->function()));
5856 CallRuntime(Runtime::kPushBlockContext, 2, instr);
5857 RecordSafepoint(Safepoint::kNoLazyDeopt);
5863 } // namespace internal
5866 #endif // V8_TARGET_ARCH_IA32