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.
9 #include "src/hydrogen-osr.h"
10 #include "src/lithium-inl.h"
11 #include "src/x64/lithium-codegen-x64.h"
16 #define DEFINE_COMPILE(type) \
17 void L##type::CompileToNative(LCodeGen* generator) { \
18 generator->Do##type(this); \
20 LITHIUM_CONCRETE_INSTRUCTION_LIST(DEFINE_COMPILE)
25 void LInstruction::VerifyCall() {
26 // Call instructions can use only fixed registers as temporaries and
27 // outputs because all registers are blocked by the calling convention.
28 // Inputs operands must use a fixed register or use-at-start policy or
29 // a non-register policy.
30 DCHECK(Output() == NULL ||
31 LUnallocated::cast(Output())->HasFixedPolicy() ||
32 !LUnallocated::cast(Output())->HasRegisterPolicy());
33 for (UseIterator it(this); !it.Done(); it.Advance()) {
34 LUnallocated* operand = LUnallocated::cast(it.Current());
35 DCHECK(operand->HasFixedPolicy() ||
36 operand->IsUsedAtStart());
38 for (TempIterator it(this); !it.Done(); it.Advance()) {
39 LUnallocated* operand = LUnallocated::cast(it.Current());
40 DCHECK(operand->HasFixedPolicy() ||!operand->HasRegisterPolicy());
46 void LInstruction::PrintTo(StringStream* stream) {
47 stream->Add("%s ", this->Mnemonic());
49 PrintOutputOperandTo(stream);
53 if (HasEnvironment()) {
55 environment()->PrintTo(stream);
58 if (HasPointerMap()) {
60 pointer_map()->PrintTo(stream);
65 void LInstruction::PrintDataTo(StringStream* stream) {
67 for (int i = 0; i < InputCount(); i++) {
68 if (i > 0) stream->Add(" ");
69 if (InputAt(i) == NULL) {
72 InputAt(i)->PrintTo(stream);
78 void LInstruction::PrintOutputOperandTo(StringStream* stream) {
79 if (HasResult()) result()->PrintTo(stream);
83 void LLabel::PrintDataTo(StringStream* stream) {
84 LGap::PrintDataTo(stream);
85 LLabel* rep = replacement();
87 stream->Add(" Dead block replaced with B%d", rep->block_id());
92 bool LGap::IsRedundant() const {
93 for (int i = 0; i < 4; i++) {
94 if (parallel_moves_[i] != NULL && !parallel_moves_[i]->IsRedundant()) {
103 void LGap::PrintDataTo(StringStream* stream) {
104 for (int i = 0; i < 4; i++) {
106 if (parallel_moves_[i] != NULL) {
107 parallel_moves_[i]->PrintDataTo(stream);
114 const char* LArithmeticD::Mnemonic() const {
116 case Token::ADD: return "add-d";
117 case Token::SUB: return "sub-d";
118 case Token::MUL: return "mul-d";
119 case Token::DIV: return "div-d";
120 case Token::MOD: return "mod-d";
128 const char* LArithmeticT::Mnemonic() const {
130 case Token::ADD: return "add-t";
131 case Token::SUB: return "sub-t";
132 case Token::MUL: return "mul-t";
133 case Token::MOD: return "mod-t";
134 case Token::DIV: return "div-t";
135 case Token::BIT_AND: return "bit-and-t";
136 case Token::BIT_OR: return "bit-or-t";
137 case Token::BIT_XOR: return "bit-xor-t";
138 case Token::ROR: return "ror-t";
139 case Token::SHL: return "sal-t";
140 case Token::SAR: return "sar-t";
141 case Token::SHR: return "shr-t";
149 bool LGoto::HasInterestingComment(LCodeGen* gen) const {
150 return !gen->IsNextEmittedBlock(block_id());
155 bool LTemplateResultInstruction<R>::MustSignExtendResult(
156 LPlatformChunk* chunk) const {
157 HValue* hvalue = this->hydrogen_value();
158 return hvalue != NULL &&
159 hvalue->representation().IsInteger32() &&
160 chunk->GetDehoistedKeyIds()->Contains(hvalue->id());
164 void LGoto::PrintDataTo(StringStream* stream) {
165 stream->Add("B%d", block_id());
169 void LBranch::PrintDataTo(StringStream* stream) {
170 stream->Add("B%d | B%d on ", true_block_id(), false_block_id());
171 value()->PrintTo(stream);
175 void LCompareNumericAndBranch::PrintDataTo(StringStream* stream) {
177 left()->PrintTo(stream);
178 stream->Add(" %s ", Token::String(op()));
179 right()->PrintTo(stream);
180 stream->Add(" then B%d else B%d", true_block_id(), false_block_id());
184 void LIsObjectAndBranch::PrintDataTo(StringStream* stream) {
185 stream->Add("if is_object(");
186 value()->PrintTo(stream);
187 stream->Add(") then B%d else B%d", true_block_id(), false_block_id());
191 void LIsStringAndBranch::PrintDataTo(StringStream* stream) {
192 stream->Add("if is_string(");
193 value()->PrintTo(stream);
194 stream->Add(") then B%d else B%d", true_block_id(), false_block_id());
198 void LIsSmiAndBranch::PrintDataTo(StringStream* stream) {
199 stream->Add("if is_smi(");
200 value()->PrintTo(stream);
201 stream->Add(") then B%d else B%d", true_block_id(), false_block_id());
205 void LIsUndetectableAndBranch::PrintDataTo(StringStream* stream) {
206 stream->Add("if is_undetectable(");
207 value()->PrintTo(stream);
208 stream->Add(") then B%d else B%d", true_block_id(), false_block_id());
212 void LStringCompareAndBranch::PrintDataTo(StringStream* stream) {
213 stream->Add("if string_compare(");
214 left()->PrintTo(stream);
215 right()->PrintTo(stream);
216 stream->Add(") then B%d else B%d", true_block_id(), false_block_id());
220 void LHasInstanceTypeAndBranch::PrintDataTo(StringStream* stream) {
221 stream->Add("if has_instance_type(");
222 value()->PrintTo(stream);
223 stream->Add(") then B%d else B%d", true_block_id(), false_block_id());
227 void LHasCachedArrayIndexAndBranch::PrintDataTo(StringStream* stream) {
228 stream->Add("if has_cached_array_index(");
229 value()->PrintTo(stream);
230 stream->Add(") then B%d else B%d", true_block_id(), false_block_id());
234 void LClassOfTestAndBranch::PrintDataTo(StringStream* stream) {
235 stream->Add("if class_of_test(");
236 value()->PrintTo(stream);
237 stream->Add(", \"%o\") then B%d else B%d",
238 *hydrogen()->class_name(),
244 void LTypeofIsAndBranch::PrintDataTo(StringStream* stream) {
245 stream->Add("if typeof ");
246 value()->PrintTo(stream);
247 stream->Add(" == \"%s\" then B%d else B%d",
248 hydrogen()->type_literal()->ToCString().get(),
249 true_block_id(), false_block_id());
253 void LStoreCodeEntry::PrintDataTo(StringStream* stream) {
255 function()->PrintTo(stream);
256 stream->Add(".code_entry = ");
257 code_object()->PrintTo(stream);
261 void LInnerAllocatedObject::PrintDataTo(StringStream* stream) {
263 base_object()->PrintTo(stream);
265 offset()->PrintTo(stream);
269 void LCallJSFunction::PrintDataTo(StringStream* stream) {
271 function()->PrintTo(stream);
272 stream->Add("#%d / ", arity());
276 void LCallWithDescriptor::PrintDataTo(StringStream* stream) {
277 for (int i = 0; i < InputCount(); i++) {
278 InputAt(i)->PrintTo(stream);
281 stream->Add("#%d / ", arity());
285 void LLoadContextSlot::PrintDataTo(StringStream* stream) {
286 context()->PrintTo(stream);
287 stream->Add("[%d]", slot_index());
291 void LStoreContextSlot::PrintDataTo(StringStream* stream) {
292 context()->PrintTo(stream);
293 stream->Add("[%d] <- ", slot_index());
294 value()->PrintTo(stream);
298 void LInvokeFunction::PrintDataTo(StringStream* stream) {
300 function()->PrintTo(stream);
301 stream->Add(" #%d / ", arity());
305 void LCallNew::PrintDataTo(StringStream* stream) {
307 constructor()->PrintTo(stream);
308 stream->Add(" #%d / ", arity());
312 void LCallNewArray::PrintDataTo(StringStream* stream) {
314 constructor()->PrintTo(stream);
315 stream->Add(" #%d / ", arity());
316 ElementsKind kind = hydrogen()->elements_kind();
317 stream->Add(" (%s) ", ElementsKindToString(kind));
321 void LAccessArgumentsAt::PrintDataTo(StringStream* stream) {
322 arguments()->PrintTo(stream);
324 stream->Add(" length ");
325 length()->PrintTo(stream);
327 stream->Add(" index ");
328 index()->PrintTo(stream);
332 int LPlatformChunk::GetNextSpillIndex(RegisterKind kind) {
333 if (kind == DOUBLE_REGISTERS && kDoubleSize == 2 * kPointerSize) {
334 // Skip a slot if for a double-width slot for x32 port.
336 // The spill slot's address is at rbp - (index + 1) * kPointerSize -
337 // StandardFrameConstants::kFixedFrameSizeFromFp. kFixedFrameSizeFromFp is
338 // 2 * kPointerSize, if rbp is aligned at 8-byte boundary, the below "|= 1"
339 // will make sure the spilled doubles are aligned at 8-byte boundary.
340 // TODO(haitao): make sure rbp is aligned at 8-byte boundary for x32 port.
341 spill_slot_count_ |= 1;
345 case GENERAL_REGISTERS: return spill_slot_count_++;
346 case DOUBLE_REGISTERS: return spill_slot_count_++;
347 case FLOAT32x4_REGISTERS:
348 case FLOAT64x2_REGISTERS:
349 case INT32x4_REGISTERS: {
351 return spill_slot_count_++;
358 return spill_slot_count_++;
362 LOperand* LPlatformChunk::GetNextSpillSlot(RegisterKind kind) {
363 // All stack slots are Double stack slots on x64.
364 // Alternatively, at some point, start using half-size
365 // stack slots for int32 values.
366 int index = GetNextSpillIndex(kind);
368 case GENERAL_REGISTERS: return LStackSlot::Create(index, zone());
369 case DOUBLE_REGISTERS: return LDoubleStackSlot::Create(index, zone());
370 case FLOAT32x4_REGISTERS: return LFloat32x4StackSlot::Create(index, zone());
371 case FLOAT64x2_REGISTERS: return LFloat64x2StackSlot::Create(index, zone());
372 case INT32x4_REGISTERS: return LInt32x4StackSlot::Create(index, zone());
380 void LStoreNamedField::PrintDataTo(StringStream* stream) {
381 object()->PrintTo(stream);
383 os << hydrogen()->access() << " <- ";
384 stream->Add(os.c_str());
385 value()->PrintTo(stream);
389 void LStoreNamedGeneric::PrintDataTo(StringStream* stream) {
390 object()->PrintTo(stream);
392 stream->Add(String::cast(*name())->ToCString().get());
394 value()->PrintTo(stream);
398 void LLoadKeyed::PrintDataTo(StringStream* stream) {
399 elements()->PrintTo(stream);
401 key()->PrintTo(stream);
402 if (hydrogen()->IsDehoisted()) {
403 stream->Add(" + %d]", base_offset());
410 void LStoreKeyed::PrintDataTo(StringStream* stream) {
411 elements()->PrintTo(stream);
413 key()->PrintTo(stream);
414 if (hydrogen()->IsDehoisted()) {
415 stream->Add(" + %d] <-", base_offset());
417 stream->Add("] <- ");
420 if (value() == NULL) {
421 DCHECK(hydrogen()->IsConstantHoleStore() &&
422 hydrogen()->value()->representation().IsDouble());
423 stream->Add("<the hole(nan)>");
425 value()->PrintTo(stream);
430 void LStoreKeyedGeneric::PrintDataTo(StringStream* stream) {
431 object()->PrintTo(stream);
433 key()->PrintTo(stream);
434 stream->Add("] <- ");
435 value()->PrintTo(stream);
439 void LTransitionElementsKind::PrintDataTo(StringStream* stream) {
440 object()->PrintTo(stream);
441 stream->Add(" %p -> %p", *original_map(), *transitioned_map());
445 LPlatformChunk* LChunkBuilder::Build() {
447 chunk_ = new(zone()) LPlatformChunk(info(), graph());
448 LPhase phase("L_Building chunk", chunk_);
451 // If compiling for OSR, reserve space for the unoptimized frame,
452 // which will be subsumed into this frame.
453 if (graph()->has_osr()) {
454 for (int i = graph()->osr()->UnoptimizedFrameSlots(); i > 0; i--) {
455 chunk_->GetNextSpillIndex(GENERAL_REGISTERS);
459 const ZoneList<HBasicBlock*>* blocks = graph()->blocks();
460 for (int i = 0; i < blocks->length(); i++) {
461 HBasicBlock* next = NULL;
462 if (i < blocks->length() - 1) next = blocks->at(i + 1);
463 DoBasicBlock(blocks->at(i), next);
464 if (is_aborted()) return NULL;
471 LUnallocated* LChunkBuilder::ToUnallocated(Register reg) {
472 return new(zone()) LUnallocated(LUnallocated::FIXED_REGISTER,
473 Register::ToAllocationIndex(reg));
477 LUnallocated* LChunkBuilder::ToUnallocated(XMMRegister reg) {
478 return new(zone()) LUnallocated(LUnallocated::FIXED_DOUBLE_REGISTER,
479 XMMRegister::ToAllocationIndex(reg));
483 LOperand* LChunkBuilder::UseFixed(HValue* value, Register fixed_register) {
484 return Use(value, ToUnallocated(fixed_register));
488 LOperand* LChunkBuilder::UseFixedDouble(HValue* value, XMMRegister reg) {
489 return Use(value, ToUnallocated(reg));
493 LOperand* LChunkBuilder::UseRegister(HValue* value) {
494 return Use(value, new(zone()) LUnallocated(LUnallocated::MUST_HAVE_REGISTER));
498 LOperand* LChunkBuilder::UseRegisterAtStart(HValue* value) {
500 new(zone()) LUnallocated(LUnallocated::MUST_HAVE_REGISTER,
501 LUnallocated::USED_AT_START));
505 LOperand* LChunkBuilder::UseTempRegister(HValue* value) {
506 return Use(value, new(zone()) LUnallocated(LUnallocated::WRITABLE_REGISTER));
510 LOperand* LChunkBuilder::UseTempRegisterOrConstant(HValue* value) {
511 return value->IsConstant()
512 ? chunk_->DefineConstantOperand(HConstant::cast(value))
513 : UseTempRegister(value);
517 LOperand* LChunkBuilder::Use(HValue* value) {
518 return Use(value, new(zone()) LUnallocated(LUnallocated::NONE));
522 LOperand* LChunkBuilder::UseAtStart(HValue* value) {
523 return Use(value, new(zone()) LUnallocated(LUnallocated::NONE,
524 LUnallocated::USED_AT_START));
528 LOperand* LChunkBuilder::UseOrConstant(HValue* value) {
529 return value->IsConstant()
530 ? chunk_->DefineConstantOperand(HConstant::cast(value))
535 LOperand* LChunkBuilder::UseOrConstantAtStart(HValue* value) {
536 return value->IsConstant()
537 ? chunk_->DefineConstantOperand(HConstant::cast(value))
542 LOperand* LChunkBuilder::UseRegisterOrConstant(HValue* value) {
543 return value->IsConstant()
544 ? chunk_->DefineConstantOperand(HConstant::cast(value))
545 : UseRegister(value);
549 LOperand* LChunkBuilder::UseRegisterOrConstantAtStart(HValue* value) {
550 return value->IsConstant()
551 ? chunk_->DefineConstantOperand(HConstant::cast(value))
552 : UseRegisterAtStart(value);
556 LOperand* LChunkBuilder::UseConstant(HValue* value) {
557 return chunk_->DefineConstantOperand(HConstant::cast(value));
561 LOperand* LChunkBuilder::UseAny(HValue* value) {
562 return value->IsConstant()
563 ? chunk_->DefineConstantOperand(HConstant::cast(value))
564 : Use(value, new(zone()) LUnallocated(LUnallocated::ANY));
568 LOperand* LChunkBuilder::Use(HValue* value, LUnallocated* operand) {
569 if (value->EmitAtUses()) {
570 HInstruction* instr = HInstruction::cast(value);
571 VisitInstruction(instr);
573 operand->set_virtual_register(value->id());
578 LInstruction* LChunkBuilder::Define(LTemplateResultInstruction<1>* instr,
579 LUnallocated* result) {
580 result->set_virtual_register(current_instruction_->id());
581 instr->set_result(result);
586 LInstruction* LChunkBuilder::DefineAsRegister(
587 LTemplateResultInstruction<1>* instr) {
589 new(zone()) LUnallocated(LUnallocated::MUST_HAVE_REGISTER));
593 LInstruction* LChunkBuilder::DefineAsSpilled(
594 LTemplateResultInstruction<1>* instr,
597 new(zone()) LUnallocated(LUnallocated::FIXED_SLOT, index));
601 LInstruction* LChunkBuilder::DefineSameAsFirst(
602 LTemplateResultInstruction<1>* instr) {
604 new(zone()) LUnallocated(LUnallocated::SAME_AS_FIRST_INPUT));
608 LInstruction* LChunkBuilder::DefineFixed(LTemplateResultInstruction<1>* instr,
610 return Define(instr, ToUnallocated(reg));
614 LInstruction* LChunkBuilder::DefineFixedDouble(
615 LTemplateResultInstruction<1>* instr,
617 return Define(instr, ToUnallocated(reg));
621 LInstruction* LChunkBuilder::AssignEnvironment(LInstruction* instr) {
622 HEnvironment* hydrogen_env = current_block_->last_environment();
623 int argument_index_accumulator = 0;
624 ZoneList<HValue*> objects_to_materialize(0, zone());
625 instr->set_environment(CreateEnvironment(
626 hydrogen_env, &argument_index_accumulator, &objects_to_materialize));
631 LInstruction* LChunkBuilder::MarkAsCall(LInstruction* instr,
632 HInstruction* hinstr,
633 CanDeoptimize can_deoptimize) {
634 info()->MarkAsNonDeferredCalling();
640 instr = AssignPointerMap(instr);
642 // If instruction does not have side-effects lazy deoptimization
643 // after the call will try to deoptimize to the point before the call.
644 // Thus we still need to attach environment to this call even if
645 // call sequence can not deoptimize eagerly.
646 bool needs_environment =
647 (can_deoptimize == CAN_DEOPTIMIZE_EAGERLY) ||
648 !hinstr->HasObservableSideEffects();
649 if (needs_environment && !instr->HasEnvironment()) {
650 instr = AssignEnvironment(instr);
651 // We can't really figure out if the environment is needed or not.
652 instr->environment()->set_has_been_used();
659 LInstruction* LChunkBuilder::AssignPointerMap(LInstruction* instr) {
660 DCHECK(!instr->HasPointerMap());
661 instr->set_pointer_map(new(zone()) LPointerMap(zone()));
666 LUnallocated* LChunkBuilder::TempRegister() {
667 LUnallocated* operand =
668 new(zone()) LUnallocated(LUnallocated::MUST_HAVE_REGISTER);
669 int vreg = allocator_->GetVirtualRegister();
670 if (!allocator_->AllocationOk()) {
671 Abort(kOutOfVirtualRegistersWhileTryingToAllocateTempRegister);
674 operand->set_virtual_register(vreg);
679 LOperand* LChunkBuilder::FixedTemp(Register reg) {
680 LUnallocated* operand = ToUnallocated(reg);
681 DCHECK(operand->HasFixedPolicy());
686 LOperand* LChunkBuilder::FixedTemp(XMMRegister reg) {
687 LUnallocated* operand = ToUnallocated(reg);
688 DCHECK(operand->HasFixedPolicy());
693 LInstruction* LChunkBuilder::DoBlockEntry(HBlockEntry* instr) {
694 return new(zone()) LLabel(instr->block());
698 LInstruction* LChunkBuilder::DoDummyUse(HDummyUse* instr) {
699 return DefineAsRegister(new(zone()) LDummyUse(UseAny(instr->value())));
703 LInstruction* LChunkBuilder::DoEnvironmentMarker(HEnvironmentMarker* instr) {
709 LInstruction* LChunkBuilder::DoDeoptimize(HDeoptimize* instr) {
710 return AssignEnvironment(new(zone()) LDeoptimize);
714 LInstruction* LChunkBuilder::DoShift(Token::Value op,
715 HBitwiseBinaryOperation* instr) {
716 if (instr->representation().IsSmiOrInteger32()) {
717 DCHECK(instr->left()->representation().Equals(instr->representation()));
718 DCHECK(instr->right()->representation().Equals(instr->representation()));
719 LOperand* left = UseRegisterAtStart(instr->left());
721 HValue* right_value = instr->right();
722 LOperand* right = NULL;
723 int constant_value = 0;
724 bool does_deopt = false;
725 if (right_value->IsConstant()) {
726 HConstant* constant = HConstant::cast(right_value);
727 right = chunk_->DefineConstantOperand(constant);
728 constant_value = constant->Integer32Value() & 0x1f;
729 if (SmiValuesAre31Bits() && instr->representation().IsSmi() &&
730 constant_value > 0) {
731 // Left shift can deoptimize if we shift by > 0 and the result
732 // cannot be truncated to smi.
733 does_deopt = !instr->CheckUsesForFlag(HValue::kTruncatingToSmi);
736 right = UseFixed(right_value, rcx);
739 // Shift operations can only deoptimize if we do a logical shift by 0 and
740 // the result cannot be truncated to int32.
741 if (op == Token::SHR && constant_value == 0) {
742 if (FLAG_opt_safe_uint32_operations) {
743 does_deopt = !instr->CheckFlag(HInstruction::kUint32);
745 does_deopt = !instr->CheckUsesForFlag(HValue::kTruncatingToInt32);
749 LInstruction* result =
750 DefineSameAsFirst(new(zone()) LShiftI(op, left, right, does_deopt));
751 return does_deopt ? AssignEnvironment(result) : result;
753 return DoArithmeticT(op, instr);
758 LInstruction* LChunkBuilder::DoArithmeticD(Token::Value op,
759 HArithmeticBinaryOperation* instr) {
760 DCHECK(instr->representation().IsDouble());
761 DCHECK(instr->left()->representation().IsDouble());
762 DCHECK(instr->right()->representation().IsDouble());
763 if (op == Token::MOD) {
764 LOperand* left = UseRegisterAtStart(instr->BetterLeftOperand());
765 LOperand* right = UseFixedDouble(instr->BetterRightOperand(), xmm1);
766 LArithmeticD* result = new(zone()) LArithmeticD(op, left, right);
767 return MarkAsCall(DefineSameAsFirst(result), instr);
769 LOperand* left = UseRegisterAtStart(instr->BetterLeftOperand());
770 LOperand* right = UseRegisterAtStart(instr->BetterRightOperand());
771 LArithmeticD* result = new(zone()) LArithmeticD(op, left, right);
772 return DefineSameAsFirst(result);
777 LInstruction* LChunkBuilder::DoArithmeticT(Token::Value op,
778 HBinaryOperation* instr) {
779 HValue* left = instr->left();
780 HValue* right = instr->right();
781 DCHECK(left->representation().IsTagged());
782 DCHECK(right->representation().IsTagged());
783 LOperand* context = UseFixed(instr->context(), rsi);
784 LOperand* left_operand = UseFixed(left, rdx);
785 LOperand* right_operand = UseFixed(right, rax);
786 LArithmeticT* result =
787 new(zone()) LArithmeticT(op, context, left_operand, right_operand);
788 return MarkAsCall(DefineFixed(result, rax), instr);
792 void LChunkBuilder::DoBasicBlock(HBasicBlock* block, HBasicBlock* next_block) {
793 DCHECK(is_building());
794 current_block_ = block;
795 next_block_ = next_block;
796 if (block->IsStartBlock()) {
797 block->UpdateEnvironment(graph_->start_environment());
799 } else if (block->predecessors()->length() == 1) {
800 // We have a single predecessor => copy environment and outgoing
801 // argument count from the predecessor.
802 DCHECK(block->phis()->length() == 0);
803 HBasicBlock* pred = block->predecessors()->at(0);
804 HEnvironment* last_environment = pred->last_environment();
805 DCHECK(last_environment != NULL);
806 // Only copy the environment, if it is later used again.
807 if (pred->end()->SecondSuccessor() == NULL) {
808 DCHECK(pred->end()->FirstSuccessor() == block);
810 if (pred->end()->FirstSuccessor()->block_id() > block->block_id() ||
811 pred->end()->SecondSuccessor()->block_id() > block->block_id()) {
812 last_environment = last_environment->Copy();
815 block->UpdateEnvironment(last_environment);
816 DCHECK(pred->argument_count() >= 0);
817 argument_count_ = pred->argument_count();
819 // We are at a state join => process phis.
820 HBasicBlock* pred = block->predecessors()->at(0);
821 // No need to copy the environment, it cannot be used later.
822 HEnvironment* last_environment = pred->last_environment();
823 for (int i = 0; i < block->phis()->length(); ++i) {
824 HPhi* phi = block->phis()->at(i);
825 if (phi->HasMergedIndex()) {
826 last_environment->SetValueAt(phi->merged_index(), phi);
829 for (int i = 0; i < block->deleted_phis()->length(); ++i) {
830 if (block->deleted_phis()->at(i) < last_environment->length()) {
831 last_environment->SetValueAt(block->deleted_phis()->at(i),
832 graph_->GetConstantUndefined());
835 block->UpdateEnvironment(last_environment);
836 // Pick up the outgoing argument count of one of the predecessors.
837 argument_count_ = pred->argument_count();
839 HInstruction* current = block->first();
840 int start = chunk_->instructions()->length();
841 while (current != NULL && !is_aborted()) {
842 // Code for constants in registers is generated lazily.
843 if (!current->EmitAtUses()) {
844 VisitInstruction(current);
846 current = current->next();
848 int end = chunk_->instructions()->length() - 1;
850 block->set_first_instruction_index(start);
851 block->set_last_instruction_index(end);
853 block->set_argument_count(argument_count_);
855 current_block_ = NULL;
859 void LChunkBuilder::VisitInstruction(HInstruction* current) {
860 HInstruction* old_current = current_instruction_;
861 current_instruction_ = current;
863 LInstruction* instr = NULL;
864 if (current->CanReplaceWithDummyUses()) {
865 if (current->OperandCount() == 0) {
866 instr = DefineAsRegister(new(zone()) LDummy());
868 DCHECK(!current->OperandAt(0)->IsControlInstruction());
869 instr = DefineAsRegister(new(zone())
870 LDummyUse(UseAny(current->OperandAt(0))));
872 for (int i = 1; i < current->OperandCount(); ++i) {
873 if (current->OperandAt(i)->IsControlInstruction()) continue;
874 LInstruction* dummy =
875 new(zone()) LDummyUse(UseAny(current->OperandAt(i)));
876 dummy->set_hydrogen_value(current);
877 chunk_->AddInstruction(dummy, current_block_);
880 HBasicBlock* successor;
881 if (current->IsControlInstruction() &&
882 HControlInstruction::cast(current)->KnownSuccessorBlock(&successor) &&
884 instr = new(zone()) LGoto(successor);
886 instr = current->CompileToLithium(this);
890 argument_count_ += current->argument_delta();
891 DCHECK(argument_count_ >= 0);
894 AddInstruction(instr, current);
897 current_instruction_ = old_current;
901 void LChunkBuilder::AddInstruction(LInstruction* instr,
902 HInstruction* hydrogen_val) {
903 // Associate the hydrogen instruction first, since we may need it for
904 // the ClobbersRegisters() or ClobbersDoubleRegisters() calls below.
905 instr->set_hydrogen_value(hydrogen_val);
908 // Make sure that the lithium instruction has either no fixed register
909 // constraints in temps or the result OR no uses that are only used at
910 // start. If this invariant doesn't hold, the register allocator can decide
911 // to insert a split of a range immediately before the instruction due to an
912 // already allocated register needing to be used for the instruction's fixed
913 // register constraint. In this case, The register allocator won't see an
914 // interference between the split child and the use-at-start (it would if
915 // the it was just a plain use), so it is free to move the split child into
916 // the same register that is used for the use-at-start.
917 // See https://code.google.com/p/chromium/issues/detail?id=201590
918 if (!(instr->ClobbersRegisters() &&
919 instr->ClobbersDoubleRegisters(isolate()))) {
921 int used_at_start = 0;
922 for (UseIterator it(instr); !it.Done(); it.Advance()) {
923 LUnallocated* operand = LUnallocated::cast(it.Current());
924 if (operand->IsUsedAtStart()) ++used_at_start;
926 if (instr->Output() != NULL) {
927 if (LUnallocated::cast(instr->Output())->HasFixedPolicy()) ++fixed;
929 for (TempIterator it(instr); !it.Done(); it.Advance()) {
930 LUnallocated* operand = LUnallocated::cast(it.Current());
931 if (operand->HasFixedPolicy()) ++fixed;
933 DCHECK(fixed == 0 || used_at_start == 0);
937 if (FLAG_stress_pointer_maps && !instr->HasPointerMap()) {
938 instr = AssignPointerMap(instr);
940 if (FLAG_stress_environments && !instr->HasEnvironment()) {
941 instr = AssignEnvironment(instr);
943 chunk_->AddInstruction(instr, current_block_);
945 if (instr->IsCall()) {
946 HValue* hydrogen_value_for_lazy_bailout = hydrogen_val;
947 LInstruction* instruction_needing_environment = NULL;
948 if (hydrogen_val->HasObservableSideEffects()) {
949 HSimulate* sim = HSimulate::cast(hydrogen_val->next());
950 instruction_needing_environment = instr;
951 sim->ReplayEnvironment(current_block_->last_environment());
952 hydrogen_value_for_lazy_bailout = sim;
954 LInstruction* bailout = AssignEnvironment(new(zone()) LLazyBailout());
955 bailout->set_hydrogen_value(hydrogen_value_for_lazy_bailout);
956 chunk_->AddInstruction(bailout, current_block_);
957 if (instruction_needing_environment != NULL) {
958 // Store the lazy deopt environment with the instruction if needed.
959 // Right now it is only used for LInstanceOfKnownGlobal.
960 instruction_needing_environment->
961 SetDeferredLazyDeoptimizationEnvironment(bailout->environment());
967 LInstruction* LChunkBuilder::DoGoto(HGoto* instr) {
968 return new(zone()) LGoto(instr->FirstSuccessor());
972 LInstruction* LChunkBuilder::DoDebugBreak(HDebugBreak* instr) {
973 return new(zone()) LDebugBreak();
977 LInstruction* LChunkBuilder::DoBranch(HBranch* instr) {
978 HValue* value = instr->value();
979 Representation r = value->representation();
980 HType type = value->type();
981 ToBooleanStub::Types expected = instr->expected_input_types();
982 if (expected.IsEmpty()) expected = ToBooleanStub::Types::Generic();
984 bool easy_case = !r.IsTagged() || type.IsBoolean() || type.IsSmi() ||
985 type.IsJSArray() || type.IsHeapNumber() || type.IsString();
986 LInstruction* branch = new(zone()) LBranch(UseRegister(value));
988 ((!expected.Contains(ToBooleanStub::SMI) && expected.NeedsMap()) ||
989 !expected.IsGeneric())) {
990 branch = AssignEnvironment(branch);
996 LInstruction* LChunkBuilder::DoCompareMap(HCompareMap* instr) {
997 DCHECK(instr->value()->representation().IsTagged());
998 LOperand* value = UseRegisterAtStart(instr->value());
999 return new(zone()) LCmpMapAndBranch(value);
1003 LInstruction* LChunkBuilder::DoArgumentsLength(HArgumentsLength* length) {
1004 info()->MarkAsRequiresFrame();
1005 return DefineAsRegister(new(zone()) LArgumentsLength(Use(length->value())));
1009 LInstruction* LChunkBuilder::DoArgumentsElements(HArgumentsElements* elems) {
1010 info()->MarkAsRequiresFrame();
1011 return DefineAsRegister(new(zone()) LArgumentsElements);
1015 LInstruction* LChunkBuilder::DoInstanceOf(HInstanceOf* instr) {
1016 LOperand* left = UseFixed(instr->left(), rax);
1017 LOperand* right = UseFixed(instr->right(), rdx);
1018 LOperand* context = UseFixed(instr->context(), rsi);
1019 LInstanceOf* result = new(zone()) LInstanceOf(context, left, right);
1020 return MarkAsCall(DefineFixed(result, rax), instr);
1024 LInstruction* LChunkBuilder::DoInstanceOfKnownGlobal(
1025 HInstanceOfKnownGlobal* instr) {
1026 LInstanceOfKnownGlobal* result =
1027 new(zone()) LInstanceOfKnownGlobal(UseFixed(instr->context(), rsi),
1028 UseFixed(instr->left(), rax),
1030 return MarkAsCall(DefineFixed(result, rax), instr);
1034 LInstruction* LChunkBuilder::DoWrapReceiver(HWrapReceiver* instr) {
1035 LOperand* receiver = UseRegister(instr->receiver());
1036 LOperand* function = UseRegisterAtStart(instr->function());
1037 LWrapReceiver* result = new(zone()) LWrapReceiver(receiver, function);
1038 return AssignEnvironment(DefineSameAsFirst(result));
1042 LInstruction* LChunkBuilder::DoApplyArguments(HApplyArguments* instr) {
1043 LOperand* function = UseFixed(instr->function(), rdi);
1044 LOperand* receiver = UseFixed(instr->receiver(), rax);
1045 LOperand* length = UseFixed(instr->length(), rbx);
1046 LOperand* elements = UseFixed(instr->elements(), rcx);
1047 LApplyArguments* result = new(zone()) LApplyArguments(function,
1051 return MarkAsCall(DefineFixed(result, rax), instr, CAN_DEOPTIMIZE_EAGERLY);
1055 LInstruction* LChunkBuilder::DoPushArguments(HPushArguments* instr) {
1056 int argc = instr->OperandCount();
1057 for (int i = 0; i < argc; ++i) {
1058 LOperand* argument = UseOrConstant(instr->argument(i));
1059 AddInstruction(new(zone()) LPushArgument(argument), instr);
1065 LInstruction* LChunkBuilder::DoStoreCodeEntry(
1066 HStoreCodeEntry* store_code_entry) {
1067 LOperand* function = UseRegister(store_code_entry->function());
1068 LOperand* code_object = UseTempRegister(store_code_entry->code_object());
1069 return new(zone()) LStoreCodeEntry(function, code_object);
1073 LInstruction* LChunkBuilder::DoInnerAllocatedObject(
1074 HInnerAllocatedObject* instr) {
1075 LOperand* base_object = UseRegisterAtStart(instr->base_object());
1076 LOperand* offset = UseRegisterOrConstantAtStart(instr->offset());
1077 return DefineAsRegister(
1078 new(zone()) LInnerAllocatedObject(base_object, offset));
1082 LInstruction* LChunkBuilder::DoThisFunction(HThisFunction* instr) {
1083 return instr->HasNoUses()
1085 : DefineAsRegister(new(zone()) LThisFunction);
1089 LInstruction* LChunkBuilder::DoContext(HContext* instr) {
1090 if (instr->HasNoUses()) return NULL;
1092 if (info()->IsStub()) {
1093 return DefineFixed(new(zone()) LContext, rsi);
1096 return DefineAsRegister(new(zone()) LContext);
1100 LInstruction* LChunkBuilder::DoDeclareGlobals(HDeclareGlobals* instr) {
1101 LOperand* context = UseFixed(instr->context(), rsi);
1102 return MarkAsCall(new(zone()) LDeclareGlobals(context), instr);
1106 LInstruction* LChunkBuilder::DoCallJSFunction(
1107 HCallJSFunction* instr) {
1108 LOperand* function = UseFixed(instr->function(), rdi);
1110 LCallJSFunction* result = new(zone()) LCallJSFunction(function);
1112 return MarkAsCall(DefineFixed(result, rax), instr);
1116 LInstruction* LChunkBuilder::DoCallWithDescriptor(
1117 HCallWithDescriptor* instr) {
1118 CallInterfaceDescriptor descriptor = instr->descriptor();
1120 LOperand* target = UseRegisterOrConstantAtStart(instr->target());
1121 ZoneList<LOperand*> ops(instr->OperandCount(), zone());
1122 ops.Add(target, zone());
1123 for (int i = 1; i < instr->OperandCount(); i++) {
1125 UseFixed(instr->OperandAt(i), descriptor.GetParameterRegister(i - 1));
1126 ops.Add(op, zone());
1129 LCallWithDescriptor* result = new(zone()) LCallWithDescriptor(
1130 descriptor, ops, zone());
1131 return MarkAsCall(DefineFixed(result, rax), instr);
1135 LInstruction* LChunkBuilder::DoTailCallThroughMegamorphicCache(
1136 HTailCallThroughMegamorphicCache* instr) {
1137 LOperand* context = UseFixed(instr->context(), rsi);
1138 LOperand* receiver_register =
1139 UseFixed(instr->receiver(), LoadDescriptor::ReceiverRegister());
1140 LOperand* name_register =
1141 UseFixed(instr->name(), LoadDescriptor::NameRegister());
1142 // Not marked as call. It can't deoptimize, and it never returns.
1143 return new (zone()) LTailCallThroughMegamorphicCache(
1144 context, receiver_register, name_register);
1148 LInstruction* LChunkBuilder::DoInvokeFunction(HInvokeFunction* instr) {
1149 LOperand* context = UseFixed(instr->context(), rsi);
1150 LOperand* function = UseFixed(instr->function(), rdi);
1151 LInvokeFunction* result = new(zone()) LInvokeFunction(context, function);
1152 return MarkAsCall(DefineFixed(result, rax), instr, CANNOT_DEOPTIMIZE_EAGERLY);
1156 LInstruction* LChunkBuilder::DoUnaryMathOperation(HUnaryMathOperation* instr) {
1157 switch (instr->op()) {
1159 return DoMathFloor(instr);
1161 return DoMathRound(instr);
1163 return DoMathFround(instr);
1165 return DoMathAbs(instr);
1167 return DoMathLog(instr);
1169 return DoMathExp(instr);
1171 return DoMathSqrt(instr);
1173 return DoMathPowHalf(instr);
1175 return DoMathClz32(instr);
1183 LInstruction* LChunkBuilder::DoMathFloor(HUnaryMathOperation* instr) {
1184 LOperand* input = UseRegisterAtStart(instr->value());
1185 LMathFloor* result = new(zone()) LMathFloor(input);
1186 return AssignEnvironment(DefineAsRegister(result));
1190 LInstruction* LChunkBuilder::DoMathRound(HUnaryMathOperation* instr) {
1191 LOperand* input = UseRegister(instr->value());
1192 LOperand* temp = FixedTemp(xmm4);
1193 LMathRound* result = new(zone()) LMathRound(input, temp);
1194 return AssignEnvironment(DefineAsRegister(result));
1198 LInstruction* LChunkBuilder::DoMathFround(HUnaryMathOperation* instr) {
1199 LOperand* input = UseRegister(instr->value());
1200 LMathFround* result = new (zone()) LMathFround(input);
1201 return DefineAsRegister(result);
1205 LInstruction* LChunkBuilder::DoMathAbs(HUnaryMathOperation* instr) {
1206 LOperand* context = UseAny(instr->context());
1207 LOperand* input = UseRegisterAtStart(instr->value());
1208 LInstruction* result =
1209 DefineSameAsFirst(new(zone()) LMathAbs(context, input));
1210 Representation r = instr->value()->representation();
1211 if (!r.IsDouble() && !r.IsSmiOrInteger32()) result = AssignPointerMap(result);
1212 if (!r.IsDouble()) result = AssignEnvironment(result);
1217 LInstruction* LChunkBuilder::DoMathLog(HUnaryMathOperation* instr) {
1218 DCHECK(instr->representation().IsDouble());
1219 DCHECK(instr->value()->representation().IsDouble());
1220 LOperand* input = UseRegisterAtStart(instr->value());
1221 return MarkAsCall(DefineSameAsFirst(new(zone()) LMathLog(input)), instr);
1225 LInstruction* LChunkBuilder::DoMathClz32(HUnaryMathOperation* instr) {
1226 LOperand* input = UseRegisterAtStart(instr->value());
1227 LMathClz32* result = new(zone()) LMathClz32(input);
1228 return DefineAsRegister(result);
1232 LInstruction* LChunkBuilder::DoMathExp(HUnaryMathOperation* instr) {
1233 DCHECK(instr->representation().IsDouble());
1234 DCHECK(instr->value()->representation().IsDouble());
1235 LOperand* value = UseTempRegister(instr->value());
1236 LOperand* temp1 = TempRegister();
1237 LOperand* temp2 = TempRegister();
1238 LMathExp* result = new(zone()) LMathExp(value, temp1, temp2);
1239 return DefineAsRegister(result);
1243 LInstruction* LChunkBuilder::DoMathSqrt(HUnaryMathOperation* instr) {
1244 LOperand* input = UseAtStart(instr->value());
1245 return DefineAsRegister(new(zone()) LMathSqrt(input));
1249 LInstruction* LChunkBuilder::DoMathPowHalf(HUnaryMathOperation* instr) {
1250 LOperand* input = UseRegisterAtStart(instr->value());
1251 LMathPowHalf* result = new(zone()) LMathPowHalf(input);
1252 return DefineSameAsFirst(result);
1256 const char* LNullarySIMDOperation::Mnemonic() const {
1258 #define SIMD_NULLARY_OPERATION_CASE_ITEM(module, function, name, p4) \
1260 return #module "-" #function;
1261 SIMD_NULLARY_OPERATIONS(SIMD_NULLARY_OPERATION_CASE_ITEM)
1262 #undef SIMD_NULLARY_OPERATION_CASE_ITEM
1270 LInstruction* LChunkBuilder::DoNullarySIMDOperation(
1271 HNullarySIMDOperation* instr) {
1272 LNullarySIMDOperation* result =
1273 new(zone()) LNullarySIMDOperation(instr->op());
1274 switch (instr->op()) {
1275 #define SIMD_NULLARY_OPERATION_CASE_ITEM(module, function, name, p4) \
1277 SIMD_NULLARY_OPERATIONS(SIMD_NULLARY_OPERATION_CASE_ITEM)
1278 #undef SIMD_NULLARY_OPERATION_CASE_ITEM
1279 return DefineAsRegister(result);
1287 const char* LUnarySIMDOperation::Mnemonic() const {
1289 case kSIMD128Change: return "SIMD128-change";
1290 #define SIMD_UNARY_OPERATION_CASE_ITEM(module, function, name, p4, p5) \
1292 return #module "-" #function;
1293 SIMD_UNARY_OPERATIONS(SIMD_UNARY_OPERATION_CASE_ITEM)
1294 SIMD_UNARY_OPERATIONS_FOR_PROPERTY_ACCESS(SIMD_UNARY_OPERATION_CASE_ITEM)
1295 #undef SIMD_UNARY_OPERATION_CASE_ITEM
1303 LInstruction* LChunkBuilder::DoUnarySIMDOperation(HUnarySIMDOperation* instr) {
1304 LOperand* input = UseRegisterAtStart(instr->value());
1305 LUnarySIMDOperation* result =
1306 new(zone()) LUnarySIMDOperation(input, instr->op());
1307 switch (instr->op()) {
1308 case kSIMD128Change:
1309 return AssignEnvironment(DefineAsRegister(result));
1312 case kFloat32x4Reciprocal:
1313 case kFloat32x4ReciprocalSqrt:
1314 case kFloat32x4Sqrt:
1317 case kFloat64x2Sqrt:
1320 return DefineSameAsFirst(result);
1321 case kFloat32x4Coercion:
1322 case kFloat64x2Coercion:
1323 case kInt32x4Coercion:
1324 case kFloat32x4BitsToInt32x4:
1325 case kFloat32x4ToInt32x4:
1326 case kInt32x4BitsToFloat32x4:
1327 case kInt32x4ToFloat32x4:
1328 case kFloat32x4Splat:
1330 case kFloat32x4GetSignMask:
1331 case kFloat32x4GetX:
1332 case kFloat32x4GetY:
1333 case kFloat32x4GetZ:
1334 case kFloat32x4GetW:
1335 case kFloat64x2GetSignMask:
1336 case kFloat64x2GetX:
1337 case kFloat64x2GetY:
1338 case kInt32x4GetSignMask:
1343 case kInt32x4GetFlagX:
1344 case kInt32x4GetFlagY:
1345 case kInt32x4GetFlagZ:
1346 case kInt32x4GetFlagW:
1347 return DefineAsRegister(result);
1355 const char* LBinarySIMDOperation::Mnemonic() const {
1357 #define SIMD_BINARY_OPERATION_CASE_ITEM(module, function, name, p4, p5, p6) \
1359 return #module "-" #function;
1360 SIMD_BINARY_OPERATIONS(SIMD_BINARY_OPERATION_CASE_ITEM)
1361 #undef SIMD_BINARY_OPERATION_CASE_ITEM
1369 LInstruction* LChunkBuilder::DoBinarySIMDOperation(
1370 HBinarySIMDOperation* instr) {
1371 switch (instr->op()) {
1378 case kFloat32x4Scale:
1379 case kFloat32x4WithX:
1380 case kFloat32x4WithY:
1381 case kFloat32x4WithZ:
1382 case kFloat32x4WithW:
1389 case kFloat64x2Scale:
1390 case kFloat64x2WithX:
1391 case kFloat64x2WithY:
1402 case kInt32x4WithFlagX:
1403 case kInt32x4WithFlagY:
1404 case kInt32x4WithFlagZ:
1405 case kInt32x4WithFlagW:
1406 case kInt32x4GreaterThan:
1408 case kInt32x4LessThan: {
1409 LOperand* left = UseRegisterAtStart(instr->left());
1410 LOperand* right = UseRegisterAtStart(instr->right());
1411 LBinarySIMDOperation* result =
1412 new(zone()) LBinarySIMDOperation(left, right, instr->op());
1413 if (instr->op() == kInt32x4WithFlagX ||
1414 instr->op() == kInt32x4WithFlagY ||
1415 instr->op() == kInt32x4WithFlagZ ||
1416 instr->op() == kInt32x4WithFlagW) {
1417 return AssignEnvironment(DefineSameAsFirst(result));
1419 return DefineSameAsFirst(result);
1422 case kFloat64x2Constructor: {
1423 LOperand* left = UseRegisterAtStart(instr->left());
1424 LOperand* right = UseRegisterAtStart(instr->right());
1425 LBinarySIMDOperation* result =
1426 new(zone()) LBinarySIMDOperation(left, right, instr->op());
1427 return DefineAsRegister(result);
1429 case kFloat32x4Shuffle:
1430 case kInt32x4Shuffle:
1431 case kInt32x4ShiftLeft:
1432 case kInt32x4ShiftRight:
1433 case kInt32x4ShiftRightArithmetic: {
1434 LOperand* left = UseRegisterAtStart(instr->left());
1435 LOperand* right = UseOrConstant(instr->right());
1436 LBinarySIMDOperation* result =
1437 new(zone()) LBinarySIMDOperation(left, right, instr->op());
1438 return AssignEnvironment(DefineSameAsFirst(result));
1440 case kFloat32x4LessThan:
1441 case kFloat32x4LessThanOrEqual:
1442 case kFloat32x4Equal:
1443 case kFloat32x4NotEqual:
1444 case kFloat32x4GreaterThanOrEqual:
1445 case kFloat32x4GreaterThan: {
1446 LOperand* left = UseRegisterAtStart(instr->left());
1447 LOperand* right = UseRegisterAtStart(instr->right());
1448 LBinarySIMDOperation* result =
1449 new(zone()) LBinarySIMDOperation(left, right, instr->op());
1450 return DefineAsRegister(result);
1459 const char* LTernarySIMDOperation::Mnemonic() const {
1461 #define SIMD_TERNARY_OPERATION_CASE_ITEM(module, function, name, p4, p5, p6, \
1464 return #module "-" #function;
1465 SIMD_TERNARY_OPERATIONS(SIMD_TERNARY_OPERATION_CASE_ITEM)
1466 #undef SIMD_TERNARY_OPERATION_CASE_ITEM
1474 LInstruction* LChunkBuilder::DoTernarySIMDOperation(
1475 HTernarySIMDOperation* instr) {
1476 LOperand* first = UseRegisterAtStart(instr->first());
1477 LOperand* second = UseRegisterAtStart(instr->second());
1478 LOperand* third = instr->op() == kFloat32x4ShuffleMix
1479 ? UseOrConstant(instr->third())
1480 : UseRegisterAtStart(instr->third());
1481 LTernarySIMDOperation* result =
1482 new(zone()) LTernarySIMDOperation(first, second, third, instr->op());
1483 switch (instr->op()) {
1484 case kFloat32x4Clamp:
1485 case kFloat64x2Clamp: {
1486 return DefineSameAsFirst(result);
1488 case kFloat32x4ShuffleMix: {
1489 return AssignEnvironment(DefineSameAsFirst(result));
1491 case kFloat32x4Select:
1492 case kInt32x4Select: {
1493 return DefineAsRegister(result);
1502 const char* LQuarternarySIMDOperation::Mnemonic() const {
1504 #define SIMD_QUARTERNARY_OPERATION_CASE_ITEM(module, function, name, p4, p5, \
1507 return #module "-" #function;
1508 SIMD_QUARTERNARY_OPERATIONS(SIMD_QUARTERNARY_OPERATION_CASE_ITEM)
1509 #undef SIMD_QUARTERNARY_OPERATION_CASE_ITEM
1517 LInstruction* LChunkBuilder::DoQuarternarySIMDOperation(
1518 HQuarternarySIMDOperation* instr) {
1519 LOperand* x = UseRegisterAtStart(instr->x());
1520 LOperand* y = UseRegisterAtStart(instr->y());
1521 LOperand* z = UseRegisterAtStart(instr->z());
1522 LOperand* w = UseRegisterAtStart(instr->w());
1523 LQuarternarySIMDOperation* result =
1524 new(zone()) LQuarternarySIMDOperation(x, y, z, w, instr->op());
1525 if (instr->op() == kInt32x4Bool) {
1526 return AssignEnvironment(DefineAsRegister(result));
1528 return DefineAsRegister(result);
1533 LInstruction* LChunkBuilder::DoCallNew(HCallNew* instr) {
1534 LOperand* context = UseFixed(instr->context(), rsi);
1535 LOperand* constructor = UseFixed(instr->constructor(), rdi);
1536 LCallNew* result = new(zone()) LCallNew(context, constructor);
1537 return MarkAsCall(DefineFixed(result, rax), instr);
1541 LInstruction* LChunkBuilder::DoCallNewArray(HCallNewArray* instr) {
1542 LOperand* context = UseFixed(instr->context(), rsi);
1543 LOperand* constructor = UseFixed(instr->constructor(), rdi);
1544 LCallNewArray* result = new(zone()) LCallNewArray(context, constructor);
1545 return MarkAsCall(DefineFixed(result, rax), instr);
1549 LInstruction* LChunkBuilder::DoCallFunction(HCallFunction* instr) {
1550 LOperand* context = UseFixed(instr->context(), rsi);
1551 LOperand* function = UseFixed(instr->function(), rdi);
1552 LCallFunction* call = new(zone()) LCallFunction(context, function);
1553 return MarkAsCall(DefineFixed(call, rax), instr);
1557 LInstruction* LChunkBuilder::DoCallRuntime(HCallRuntime* instr) {
1558 LOperand* context = UseFixed(instr->context(), rsi);
1559 LCallRuntime* result = new(zone()) LCallRuntime(context);
1560 return MarkAsCall(DefineFixed(result, rax), instr);
1564 LInstruction* LChunkBuilder::DoRor(HRor* instr) {
1565 return DoShift(Token::ROR, instr);
1569 LInstruction* LChunkBuilder::DoShr(HShr* instr) {
1570 return DoShift(Token::SHR, instr);
1574 LInstruction* LChunkBuilder::DoSar(HSar* instr) {
1575 return DoShift(Token::SAR, instr);
1579 LInstruction* LChunkBuilder::DoShl(HShl* instr) {
1580 return DoShift(Token::SHL, instr);
1584 LInstruction* LChunkBuilder::DoBitwise(HBitwise* instr) {
1585 if (instr->representation().IsSmiOrInteger32()) {
1586 DCHECK(instr->left()->representation().Equals(instr->representation()));
1587 DCHECK(instr->right()->representation().Equals(instr->representation()));
1588 DCHECK(instr->CheckFlag(HValue::kTruncatingToInt32));
1590 LOperand* left = UseRegisterAtStart(instr->BetterLeftOperand());
1591 LOperand* right = UseOrConstantAtStart(instr->BetterRightOperand());
1592 return DefineSameAsFirst(new(zone()) LBitI(left, right));
1594 return DoArithmeticT(instr->op(), instr);
1599 LInstruction* LChunkBuilder::DoDivByPowerOf2I(HDiv* instr) {
1600 DCHECK(instr->representation().IsSmiOrInteger32());
1601 DCHECK(instr->left()->representation().Equals(instr->representation()));
1602 DCHECK(instr->right()->representation().Equals(instr->representation()));
1603 LOperand* dividend = UseRegister(instr->left());
1604 int32_t divisor = instr->right()->GetInteger32Constant();
1605 LInstruction* result = DefineAsRegister(new(zone()) LDivByPowerOf2I(
1606 dividend, divisor));
1607 if ((instr->CheckFlag(HValue::kBailoutOnMinusZero) && divisor < 0) ||
1608 (instr->CheckFlag(HValue::kCanOverflow) && divisor == -1) ||
1609 (!instr->CheckFlag(HInstruction::kAllUsesTruncatingToInt32) &&
1610 divisor != 1 && divisor != -1)) {
1611 result = AssignEnvironment(result);
1617 LInstruction* LChunkBuilder::DoDivByConstI(HDiv* instr) {
1618 DCHECK(instr->representation().IsInteger32());
1619 DCHECK(instr->left()->representation().Equals(instr->representation()));
1620 DCHECK(instr->right()->representation().Equals(instr->representation()));
1621 LOperand* dividend = UseRegister(instr->left());
1622 int32_t divisor = instr->right()->GetInteger32Constant();
1623 LOperand* temp1 = FixedTemp(rax);
1624 LOperand* temp2 = FixedTemp(rdx);
1625 LInstruction* result = DefineFixed(new(zone()) LDivByConstI(
1626 dividend, divisor, temp1, temp2), rdx);
1628 (instr->CheckFlag(HValue::kBailoutOnMinusZero) && divisor < 0) ||
1629 !instr->CheckFlag(HInstruction::kAllUsesTruncatingToInt32)) {
1630 result = AssignEnvironment(result);
1636 LInstruction* LChunkBuilder::DoDivI(HDiv* instr) {
1637 DCHECK(instr->representation().IsSmiOrInteger32());
1638 DCHECK(instr->left()->representation().Equals(instr->representation()));
1639 DCHECK(instr->right()->representation().Equals(instr->representation()));
1640 LOperand* dividend = UseFixed(instr->left(), rax);
1641 LOperand* divisor = UseRegister(instr->right());
1642 LOperand* temp = FixedTemp(rdx);
1643 LInstruction* result = DefineFixed(new(zone()) LDivI(
1644 dividend, divisor, temp), rax);
1645 if (instr->CheckFlag(HValue::kCanBeDivByZero) ||
1646 instr->CheckFlag(HValue::kBailoutOnMinusZero) ||
1647 instr->CheckFlag(HValue::kCanOverflow) ||
1648 !instr->CheckFlag(HValue::kAllUsesTruncatingToInt32)) {
1649 result = AssignEnvironment(result);
1655 LInstruction* LChunkBuilder::DoDiv(HDiv* instr) {
1656 if (instr->representation().IsSmiOrInteger32()) {
1657 if (instr->RightIsPowerOf2()) {
1658 return DoDivByPowerOf2I(instr);
1659 } else if (instr->right()->IsConstant()) {
1660 return DoDivByConstI(instr);
1662 return DoDivI(instr);
1664 } else if (instr->representation().IsDouble()) {
1665 return DoArithmeticD(Token::DIV, instr);
1667 return DoArithmeticT(Token::DIV, instr);
1672 LInstruction* LChunkBuilder::DoFlooringDivByPowerOf2I(HMathFloorOfDiv* instr) {
1673 LOperand* dividend = UseRegisterAtStart(instr->left());
1674 int32_t divisor = instr->right()->GetInteger32Constant();
1675 LInstruction* result = DefineSameAsFirst(new(zone()) LFlooringDivByPowerOf2I(
1676 dividend, divisor));
1677 if ((instr->CheckFlag(HValue::kBailoutOnMinusZero) && divisor < 0) ||
1678 (instr->CheckFlag(HValue::kLeftCanBeMinInt) && divisor == -1)) {
1679 result = AssignEnvironment(result);
1685 LInstruction* LChunkBuilder::DoFlooringDivByConstI(HMathFloorOfDiv* instr) {
1686 DCHECK(instr->representation().IsInteger32());
1687 DCHECK(instr->left()->representation().Equals(instr->representation()));
1688 DCHECK(instr->right()->representation().Equals(instr->representation()));
1689 LOperand* dividend = UseRegister(instr->left());
1690 int32_t divisor = instr->right()->GetInteger32Constant();
1691 LOperand* temp1 = FixedTemp(rax);
1692 LOperand* temp2 = FixedTemp(rdx);
1694 ((divisor > 0 && !instr->CheckFlag(HValue::kLeftCanBeNegative)) ||
1695 (divisor < 0 && !instr->CheckFlag(HValue::kLeftCanBePositive))) ?
1696 NULL : TempRegister();
1697 LInstruction* result =
1698 DefineFixed(new(zone()) LFlooringDivByConstI(dividend,
1705 (instr->CheckFlag(HValue::kBailoutOnMinusZero) && divisor < 0)) {
1706 result = AssignEnvironment(result);
1712 LInstruction* LChunkBuilder::DoFlooringDivI(HMathFloorOfDiv* instr) {
1713 DCHECK(instr->representation().IsSmiOrInteger32());
1714 DCHECK(instr->left()->representation().Equals(instr->representation()));
1715 DCHECK(instr->right()->representation().Equals(instr->representation()));
1716 LOperand* dividend = UseFixed(instr->left(), rax);
1717 LOperand* divisor = UseRegister(instr->right());
1718 LOperand* temp = FixedTemp(rdx);
1719 LInstruction* result = DefineFixed(new(zone()) LFlooringDivI(
1720 dividend, divisor, temp), rax);
1721 if (instr->CheckFlag(HValue::kCanBeDivByZero) ||
1722 instr->CheckFlag(HValue::kBailoutOnMinusZero) ||
1723 instr->CheckFlag(HValue::kCanOverflow)) {
1724 result = AssignEnvironment(result);
1730 LInstruction* LChunkBuilder::DoMathFloorOfDiv(HMathFloorOfDiv* instr) {
1731 if (instr->RightIsPowerOf2()) {
1732 return DoFlooringDivByPowerOf2I(instr);
1733 } else if (instr->right()->IsConstant()) {
1734 return DoFlooringDivByConstI(instr);
1736 return DoFlooringDivI(instr);
1741 LInstruction* LChunkBuilder::DoModByPowerOf2I(HMod* instr) {
1742 DCHECK(instr->representation().IsSmiOrInteger32());
1743 DCHECK(instr->left()->representation().Equals(instr->representation()));
1744 DCHECK(instr->right()->representation().Equals(instr->representation()));
1745 LOperand* dividend = UseRegisterAtStart(instr->left());
1746 int32_t divisor = instr->right()->GetInteger32Constant();
1747 LInstruction* result = DefineSameAsFirst(new(zone()) LModByPowerOf2I(
1748 dividend, divisor));
1749 if (instr->CheckFlag(HValue::kLeftCanBeNegative) &&
1750 instr->CheckFlag(HValue::kBailoutOnMinusZero)) {
1751 result = AssignEnvironment(result);
1757 LInstruction* LChunkBuilder::DoModByConstI(HMod* instr) {
1758 DCHECK(instr->representation().IsSmiOrInteger32());
1759 DCHECK(instr->left()->representation().Equals(instr->representation()));
1760 DCHECK(instr->right()->representation().Equals(instr->representation()));
1761 LOperand* dividend = UseRegister(instr->left());
1762 int32_t divisor = instr->right()->GetInteger32Constant();
1763 LOperand* temp1 = FixedTemp(rax);
1764 LOperand* temp2 = FixedTemp(rdx);
1765 LInstruction* result = DefineFixed(new(zone()) LModByConstI(
1766 dividend, divisor, temp1, temp2), rax);
1767 if (divisor == 0 || instr->CheckFlag(HValue::kBailoutOnMinusZero)) {
1768 result = AssignEnvironment(result);
1774 LInstruction* LChunkBuilder::DoModI(HMod* instr) {
1775 DCHECK(instr->representation().IsSmiOrInteger32());
1776 DCHECK(instr->left()->representation().Equals(instr->representation()));
1777 DCHECK(instr->right()->representation().Equals(instr->representation()));
1778 LOperand* dividend = UseFixed(instr->left(), rax);
1779 LOperand* divisor = UseRegister(instr->right());
1780 LOperand* temp = FixedTemp(rdx);
1781 LInstruction* result = DefineFixed(new(zone()) LModI(
1782 dividend, divisor, temp), rdx);
1783 if (instr->CheckFlag(HValue::kCanBeDivByZero) ||
1784 instr->CheckFlag(HValue::kBailoutOnMinusZero)) {
1785 result = AssignEnvironment(result);
1791 LInstruction* LChunkBuilder::DoMod(HMod* instr) {
1792 if (instr->representation().IsSmiOrInteger32()) {
1793 if (instr->RightIsPowerOf2()) {
1794 return DoModByPowerOf2I(instr);
1795 } else if (instr->right()->IsConstant()) {
1796 return DoModByConstI(instr);
1798 return DoModI(instr);
1800 } else if (instr->representation().IsDouble()) {
1801 return DoArithmeticD(Token::MOD, instr);
1803 return DoArithmeticT(Token::MOD, instr);
1808 LInstruction* LChunkBuilder::DoMul(HMul* instr) {
1809 if (instr->representation().IsSmiOrInteger32()) {
1810 DCHECK(instr->left()->representation().Equals(instr->representation()));
1811 DCHECK(instr->right()->representation().Equals(instr->representation()));
1812 LOperand* left = UseRegisterAtStart(instr->BetterLeftOperand());
1813 LOperand* right = UseOrConstant(instr->BetterRightOperand());
1814 LMulI* mul = new(zone()) LMulI(left, right);
1815 if (instr->CheckFlag(HValue::kCanOverflow) ||
1816 instr->CheckFlag(HValue::kBailoutOnMinusZero)) {
1817 AssignEnvironment(mul);
1819 return DefineSameAsFirst(mul);
1820 } else if (instr->representation().IsDouble()) {
1821 return DoArithmeticD(Token::MUL, instr);
1823 return DoArithmeticT(Token::MUL, instr);
1828 LInstruction* LChunkBuilder::DoSub(HSub* instr) {
1829 if (instr->representation().IsSmiOrInteger32()) {
1830 DCHECK(instr->left()->representation().Equals(instr->representation()));
1831 DCHECK(instr->right()->representation().Equals(instr->representation()));
1832 LOperand* left = UseRegisterAtStart(instr->left());
1833 LOperand* right = UseOrConstantAtStart(instr->right());
1834 LSubI* sub = new(zone()) LSubI(left, right);
1835 LInstruction* result = DefineSameAsFirst(sub);
1836 if (instr->CheckFlag(HValue::kCanOverflow)) {
1837 result = AssignEnvironment(result);
1840 } else if (instr->representation().IsDouble()) {
1841 return DoArithmeticD(Token::SUB, instr);
1843 return DoArithmeticT(Token::SUB, instr);
1848 LInstruction* LChunkBuilder::DoAdd(HAdd* instr) {
1849 if (instr->representation().IsSmiOrInteger32()) {
1850 // Check to see if it would be advantageous to use an lea instruction rather
1851 // than an add. This is the case when no overflow check is needed and there
1852 // are multiple uses of the add's inputs, so using a 3-register add will
1853 // preserve all input values for later uses.
1854 bool use_lea = LAddI::UseLea(instr);
1855 DCHECK(instr->left()->representation().Equals(instr->representation()));
1856 DCHECK(instr->right()->representation().Equals(instr->representation()));
1857 LOperand* left = UseRegisterAtStart(instr->BetterLeftOperand());
1858 HValue* right_candidate = instr->BetterRightOperand();
1860 if (SmiValuesAre32Bits() && instr->representation().IsSmi()) {
1861 // We cannot add a tagged immediate to a tagged value,
1862 // so we request it in a register.
1863 right = UseRegisterAtStart(right_candidate);
1865 right = use_lea ? UseRegisterOrConstantAtStart(right_candidate)
1866 : UseOrConstantAtStart(right_candidate);
1868 LAddI* add = new(zone()) LAddI(left, right);
1869 bool can_overflow = instr->CheckFlag(HValue::kCanOverflow);
1870 LInstruction* result = use_lea ? DefineAsRegister(add)
1871 : DefineSameAsFirst(add);
1873 result = AssignEnvironment(result);
1876 } else if (instr->representation().IsExternal()) {
1877 DCHECK(instr->left()->representation().IsExternal());
1878 DCHECK(instr->right()->representation().IsInteger32());
1879 DCHECK(!instr->CheckFlag(HValue::kCanOverflow));
1880 bool use_lea = LAddI::UseLea(instr);
1881 LOperand* left = UseRegisterAtStart(instr->left());
1882 HValue* right_candidate = instr->right();
1883 LOperand* right = use_lea
1884 ? UseRegisterOrConstantAtStart(right_candidate)
1885 : UseOrConstantAtStart(right_candidate);
1886 LAddI* add = new(zone()) LAddI(left, right);
1887 LInstruction* result = use_lea
1888 ? DefineAsRegister(add)
1889 : DefineSameAsFirst(add);
1891 } else if (instr->representation().IsDouble()) {
1892 return DoArithmeticD(Token::ADD, instr);
1894 return DoArithmeticT(Token::ADD, instr);
1900 LInstruction* LChunkBuilder::DoMathMinMax(HMathMinMax* instr) {
1901 LOperand* left = NULL;
1902 LOperand* right = NULL;
1903 DCHECK(instr->left()->representation().Equals(instr->representation()));
1904 DCHECK(instr->right()->representation().Equals(instr->representation()));
1905 if (instr->representation().IsSmi()) {
1906 left = UseRegisterAtStart(instr->BetterLeftOperand());
1907 right = UseAtStart(instr->BetterRightOperand());
1908 } else if (instr->representation().IsInteger32()) {
1909 left = UseRegisterAtStart(instr->BetterLeftOperand());
1910 right = UseOrConstantAtStart(instr->BetterRightOperand());
1912 DCHECK(instr->representation().IsDouble());
1913 left = UseRegisterAtStart(instr->left());
1914 right = UseRegisterAtStart(instr->right());
1916 LMathMinMax* minmax = new(zone()) LMathMinMax(left, right);
1917 return DefineSameAsFirst(minmax);
1921 LInstruction* LChunkBuilder::DoPower(HPower* instr) {
1922 DCHECK(instr->representation().IsDouble());
1923 // We call a C function for double power. It can't trigger a GC.
1924 // We need to use fixed result register for the call.
1925 Representation exponent_type = instr->right()->representation();
1926 DCHECK(instr->left()->representation().IsDouble());
1927 LOperand* left = UseFixedDouble(instr->left(), xmm2);
1929 exponent_type.IsDouble()
1930 ? UseFixedDouble(instr->right(), xmm1)
1931 : UseFixed(instr->right(), MathPowTaggedDescriptor::exponent());
1932 LPower* result = new(zone()) LPower(left, right);
1933 return MarkAsCall(DefineFixedDouble(result, xmm3), instr,
1934 CAN_DEOPTIMIZE_EAGERLY);
1938 LInstruction* LChunkBuilder::DoCompareGeneric(HCompareGeneric* instr) {
1939 DCHECK(instr->left()->representation().IsTagged());
1940 DCHECK(instr->right()->representation().IsTagged());
1941 LOperand* context = UseFixed(instr->context(), rsi);
1942 LOperand* left = UseFixed(instr->left(), rdx);
1943 LOperand* right = UseFixed(instr->right(), rax);
1944 LCmpT* result = new(zone()) LCmpT(context, left, right);
1945 return MarkAsCall(DefineFixed(result, rax), instr);
1949 LInstruction* LChunkBuilder::DoCompareNumericAndBranch(
1950 HCompareNumericAndBranch* instr) {
1951 Representation r = instr->representation();
1952 if (r.IsSmiOrInteger32()) {
1953 DCHECK(instr->left()->representation().Equals(r));
1954 DCHECK(instr->right()->representation().Equals(r));
1955 LOperand* left = UseRegisterOrConstantAtStart(instr->left());
1956 LOperand* right = UseOrConstantAtStart(instr->right());
1957 return new(zone()) LCompareNumericAndBranch(left, right);
1959 DCHECK(r.IsDouble());
1960 DCHECK(instr->left()->representation().IsDouble());
1961 DCHECK(instr->right()->representation().IsDouble());
1964 if (instr->left()->IsConstant() && instr->right()->IsConstant()) {
1965 left = UseRegisterOrConstantAtStart(instr->left());
1966 right = UseRegisterOrConstantAtStart(instr->right());
1968 left = UseRegisterAtStart(instr->left());
1969 right = UseRegisterAtStart(instr->right());
1971 return new(zone()) LCompareNumericAndBranch(left, right);
1976 LInstruction* LChunkBuilder::DoCompareObjectEqAndBranch(
1977 HCompareObjectEqAndBranch* instr) {
1978 LOperand* left = UseRegisterAtStart(instr->left());
1979 LOperand* right = UseRegisterOrConstantAtStart(instr->right());
1980 return new(zone()) LCmpObjectEqAndBranch(left, right);
1984 LInstruction* LChunkBuilder::DoCompareHoleAndBranch(
1985 HCompareHoleAndBranch* instr) {
1986 LOperand* value = UseRegisterAtStart(instr->value());
1987 return new(zone()) LCmpHoleAndBranch(value);
1991 LInstruction* LChunkBuilder::DoCompareMinusZeroAndBranch(
1992 HCompareMinusZeroAndBranch* instr) {
1993 LOperand* value = UseRegister(instr->value());
1994 return new(zone()) LCompareMinusZeroAndBranch(value);
1998 LInstruction* LChunkBuilder::DoIsObjectAndBranch(HIsObjectAndBranch* instr) {
1999 DCHECK(instr->value()->representation().IsTagged());
2000 return new(zone()) LIsObjectAndBranch(UseRegisterAtStart(instr->value()));
2004 LInstruction* LChunkBuilder::DoIsStringAndBranch(HIsStringAndBranch* instr) {
2005 DCHECK(instr->value()->representation().IsTagged());
2006 LOperand* value = UseRegisterAtStart(instr->value());
2007 LOperand* temp = TempRegister();
2008 return new(zone()) LIsStringAndBranch(value, temp);
2012 LInstruction* LChunkBuilder::DoIsSmiAndBranch(HIsSmiAndBranch* instr) {
2013 DCHECK(instr->value()->representation().IsTagged());
2014 return new(zone()) LIsSmiAndBranch(Use(instr->value()));
2018 LInstruction* LChunkBuilder::DoIsUndetectableAndBranch(
2019 HIsUndetectableAndBranch* instr) {
2020 DCHECK(instr->value()->representation().IsTagged());
2021 LOperand* value = UseRegisterAtStart(instr->value());
2022 LOperand* temp = TempRegister();
2023 return new(zone()) LIsUndetectableAndBranch(value, temp);
2027 LInstruction* LChunkBuilder::DoStringCompareAndBranch(
2028 HStringCompareAndBranch* instr) {
2030 DCHECK(instr->left()->representation().IsTagged());
2031 DCHECK(instr->right()->representation().IsTagged());
2032 LOperand* context = UseFixed(instr->context(), rsi);
2033 LOperand* left = UseFixed(instr->left(), rdx);
2034 LOperand* right = UseFixed(instr->right(), rax);
2035 LStringCompareAndBranch* result =
2036 new(zone()) LStringCompareAndBranch(context, left, right);
2038 return MarkAsCall(result, instr);
2042 LInstruction* LChunkBuilder::DoHasInstanceTypeAndBranch(
2043 HHasInstanceTypeAndBranch* instr) {
2044 DCHECK(instr->value()->representation().IsTagged());
2045 LOperand* value = UseRegisterAtStart(instr->value());
2046 return new(zone()) LHasInstanceTypeAndBranch(value);
2050 LInstruction* LChunkBuilder::DoGetCachedArrayIndex(
2051 HGetCachedArrayIndex* instr) {
2052 DCHECK(instr->value()->representation().IsTagged());
2053 LOperand* value = UseRegisterAtStart(instr->value());
2055 return DefineAsRegister(new(zone()) LGetCachedArrayIndex(value));
2059 LInstruction* LChunkBuilder::DoHasCachedArrayIndexAndBranch(
2060 HHasCachedArrayIndexAndBranch* instr) {
2061 DCHECK(instr->value()->representation().IsTagged());
2062 LOperand* value = UseRegisterAtStart(instr->value());
2063 return new(zone()) LHasCachedArrayIndexAndBranch(value);
2067 LInstruction* LChunkBuilder::DoClassOfTestAndBranch(
2068 HClassOfTestAndBranch* instr) {
2069 LOperand* value = UseRegister(instr->value());
2070 return new(zone()) LClassOfTestAndBranch(value,
2076 LInstruction* LChunkBuilder::DoMapEnumLength(HMapEnumLength* instr) {
2077 LOperand* map = UseRegisterAtStart(instr->value());
2078 return DefineAsRegister(new(zone()) LMapEnumLength(map));
2082 LInstruction* LChunkBuilder::DoDateField(HDateField* instr) {
2083 LOperand* object = UseFixed(instr->value(), rax);
2084 LDateField* result = new(zone()) LDateField(object, instr->index());
2085 return MarkAsCall(DefineFixed(result, rax), instr, CAN_DEOPTIMIZE_EAGERLY);
2089 LInstruction* LChunkBuilder::DoSeqStringGetChar(HSeqStringGetChar* instr) {
2090 LOperand* string = UseRegisterAtStart(instr->string());
2091 LOperand* index = UseRegisterOrConstantAtStart(instr->index());
2092 return DefineAsRegister(new(zone()) LSeqStringGetChar(string, index));
2096 LInstruction* LChunkBuilder::DoSeqStringSetChar(HSeqStringSetChar* instr) {
2097 LOperand* string = UseRegisterAtStart(instr->string());
2098 LOperand* index = FLAG_debug_code
2099 ? UseRegisterAtStart(instr->index())
2100 : UseRegisterOrConstantAtStart(instr->index());
2101 LOperand* value = FLAG_debug_code
2102 ? UseRegisterAtStart(instr->value())
2103 : UseRegisterOrConstantAtStart(instr->value());
2104 LOperand* context = FLAG_debug_code ? UseFixed(instr->context(), rsi) : NULL;
2105 LInstruction* result = new(zone()) LSeqStringSetChar(context, string,
2107 if (FLAG_debug_code) {
2108 result = MarkAsCall(result, instr);
2114 LInstruction* LChunkBuilder::DoBoundsCheck(HBoundsCheck* instr) {
2115 if (!FLAG_debug_code && instr->skip_check()) return NULL;
2116 LOperand* index = UseRegisterOrConstantAtStart(instr->index());
2117 LOperand* length = !index->IsConstantOperand()
2118 ? UseOrConstantAtStart(instr->length())
2119 : UseAtStart(instr->length());
2120 LInstruction* result = new(zone()) LBoundsCheck(index, length);
2121 if (!FLAG_debug_code || !instr->skip_check()) {
2122 result = AssignEnvironment(result);
2128 LInstruction* LChunkBuilder::DoBoundsCheckBaseIndexInformation(
2129 HBoundsCheckBaseIndexInformation* instr) {
2135 LInstruction* LChunkBuilder::DoAbnormalExit(HAbnormalExit* instr) {
2136 // The control instruction marking the end of a block that completed
2137 // abruptly (e.g., threw an exception). There is nothing specific to do.
2142 LInstruction* LChunkBuilder::DoUseConst(HUseConst* instr) {
2147 LInstruction* LChunkBuilder::DoForceRepresentation(HForceRepresentation* bad) {
2148 // All HForceRepresentation instructions should be eliminated in the
2149 // representation change phase of Hydrogen.
2155 LInstruction* LChunkBuilder::DoChange(HChange* instr) {
2156 Representation from = instr->from();
2157 Representation to = instr->to();
2158 HValue* val = instr->value();
2160 if (to.IsTagged()) {
2161 LOperand* value = UseRegister(val);
2162 return DefineSameAsFirst(new(zone()) LDummyUse(value));
2164 from = Representation::Tagged();
2166 if (from.IsTagged()) {
2167 if (to.IsDouble()) {
2168 LOperand* value = UseRegister(val);
2169 LInstruction* result = DefineAsRegister(new(zone()) LNumberUntagD(value));
2170 if (!val->representation().IsSmi()) result = AssignEnvironment(result);
2172 } else if (to.IsSIMD128()) {
2173 LOperand* value = UseRegister(instr->value());
2174 LOperand* temp = TempRegister();
2175 LTaggedToSIMD128* res = new(zone()) LTaggedToSIMD128(value, temp, to);
2176 return AssignEnvironment(DefineAsRegister(res));
2177 } else if (to.IsSmi()) {
2178 LOperand* value = UseRegister(val);
2179 if (val->type().IsSmi()) {
2180 return DefineSameAsFirst(new(zone()) LDummyUse(value));
2182 return AssignEnvironment(DefineSameAsFirst(new(zone()) LCheckSmi(value)));
2184 DCHECK(to.IsInteger32());
2185 if (val->type().IsSmi() || val->representation().IsSmi()) {
2186 LOperand* value = UseRegister(val);
2187 return DefineSameAsFirst(new(zone()) LSmiUntag(value, false));
2189 LOperand* value = UseRegister(val);
2190 bool truncating = instr->CanTruncateToInt32();
2191 LOperand* xmm_temp = truncating ? NULL : FixedTemp(xmm1);
2192 LInstruction* result =
2193 DefineSameAsFirst(new(zone()) LTaggedToI(value, xmm_temp));
2194 if (!val->representation().IsSmi()) result = AssignEnvironment(result);
2198 } else if (from.IsDouble()) {
2199 if (to.IsTagged()) {
2200 info()->MarkAsDeferredCalling();
2201 LOperand* value = UseRegister(val);
2202 LOperand* temp = TempRegister();
2203 LUnallocated* result_temp = TempRegister();
2204 LNumberTagD* result = new(zone()) LNumberTagD(value, temp);
2205 return AssignPointerMap(Define(result, result_temp));
2206 } else if (to.IsSmi()) {
2207 LOperand* value = UseRegister(val);
2208 return AssignEnvironment(
2209 DefineAsRegister(new(zone()) LDoubleToSmi(value)));
2211 DCHECK(to.IsInteger32());
2212 LOperand* value = UseRegister(val);
2213 LInstruction* result = DefineAsRegister(new(zone()) LDoubleToI(value));
2214 if (!instr->CanTruncateToInt32()) result = AssignEnvironment(result);
2217 } else if (from.IsInteger32()) {
2218 info()->MarkAsDeferredCalling();
2219 if (to.IsTagged()) {
2220 if (!instr->CheckFlag(HValue::kCanOverflow)) {
2221 LOperand* value = UseRegister(val);
2222 return DefineAsRegister(new(zone()) LSmiTag(value));
2223 } else if (val->CheckFlag(HInstruction::kUint32)) {
2224 LOperand* value = UseRegister(val);
2225 LOperand* temp1 = TempRegister();
2226 LOperand* temp2 = FixedTemp(xmm1);
2227 LNumberTagU* result = new(zone()) LNumberTagU(value, temp1, temp2);
2228 return AssignPointerMap(DefineSameAsFirst(result));
2230 LOperand* value = UseRegister(val);
2231 LOperand* temp1 = SmiValuesAre32Bits() ? NULL : TempRegister();
2232 LOperand* temp2 = SmiValuesAre32Bits() ? NULL : FixedTemp(xmm1);
2233 LNumberTagI* result = new(zone()) LNumberTagI(value, temp1, temp2);
2234 return AssignPointerMap(DefineSameAsFirst(result));
2236 } else if (to.IsSmi()) {
2237 LOperand* value = UseRegister(val);
2238 LInstruction* result = DefineAsRegister(new(zone()) LSmiTag(value));
2239 if (instr->CheckFlag(HValue::kCanOverflow)) {
2240 result = AssignEnvironment(result);
2244 DCHECK(to.IsDouble());
2245 if (val->CheckFlag(HInstruction::kUint32)) {
2246 return DefineAsRegister(new(zone()) LUint32ToDouble(UseRegister(val)));
2248 LOperand* value = Use(val);
2249 return DefineAsRegister(new(zone()) LInteger32ToDouble(value));
2252 } else if (from.IsSIMD128()) {
2253 DCHECK(to.IsTagged());
2254 info()->MarkAsDeferredCalling();
2255 LOperand* value = UseRegister(instr->value());
2256 LOperand* temp = TempRegister();
2257 LOperand* temp2 = TempRegister();
2258 LOperand* temp3 = TempRegister();
2260 // Make sure that temp and result_temp are different registers.
2261 LUnallocated* result_temp = TempRegister();
2262 LSIMD128ToTagged* result =
2263 new(zone()) LSIMD128ToTagged(value, temp, temp2, temp3);
2264 return AssignPointerMap(Define(result, result_temp));
2271 LInstruction* LChunkBuilder::DoCheckHeapObject(HCheckHeapObject* instr) {
2272 LOperand* value = UseRegisterAtStart(instr->value());
2273 LInstruction* result = new(zone()) LCheckNonSmi(value);
2274 if (!instr->value()->type().IsHeapObject()) {
2275 result = AssignEnvironment(result);
2281 LInstruction* LChunkBuilder::DoCheckSmi(HCheckSmi* instr) {
2282 LOperand* value = UseRegisterAtStart(instr->value());
2283 return AssignEnvironment(new(zone()) LCheckSmi(value));
2287 LInstruction* LChunkBuilder::DoCheckInstanceType(HCheckInstanceType* instr) {
2288 LOperand* value = UseRegisterAtStart(instr->value());
2289 LCheckInstanceType* result = new(zone()) LCheckInstanceType(value);
2290 return AssignEnvironment(result);
2294 LInstruction* LChunkBuilder::DoCheckValue(HCheckValue* instr) {
2295 LOperand* value = UseRegisterAtStart(instr->value());
2296 return AssignEnvironment(new(zone()) LCheckValue(value));
2300 LInstruction* LChunkBuilder::DoCheckMaps(HCheckMaps* instr) {
2301 if (instr->IsStabilityCheck()) return new(zone()) LCheckMaps;
2302 LOperand* value = UseRegisterAtStart(instr->value());
2303 LInstruction* result = AssignEnvironment(new(zone()) LCheckMaps(value));
2304 if (instr->HasMigrationTarget()) {
2305 info()->MarkAsDeferredCalling();
2306 result = AssignPointerMap(result);
2312 LInstruction* LChunkBuilder::DoClampToUint8(HClampToUint8* instr) {
2313 HValue* value = instr->value();
2314 Representation input_rep = value->representation();
2315 LOperand* reg = UseRegister(value);
2316 if (input_rep.IsDouble()) {
2317 return DefineAsRegister(new(zone()) LClampDToUint8(reg));
2318 } else if (input_rep.IsInteger32()) {
2319 return DefineSameAsFirst(new(zone()) LClampIToUint8(reg));
2321 DCHECK(input_rep.IsSmiOrTagged());
2322 // Register allocator doesn't (yet) support allocation of double
2323 // temps. Reserve xmm1 explicitly.
2324 LClampTToUint8* result = new(zone()) LClampTToUint8(reg,
2326 return AssignEnvironment(DefineSameAsFirst(result));
2331 LInstruction* LChunkBuilder::DoDoubleBits(HDoubleBits* instr) {
2332 HValue* value = instr->value();
2333 DCHECK(value->representation().IsDouble());
2334 return DefineAsRegister(new(zone()) LDoubleBits(UseRegister(value)));
2338 LInstruction* LChunkBuilder::DoConstructDouble(HConstructDouble* instr) {
2339 LOperand* lo = UseRegister(instr->lo());
2340 LOperand* hi = UseRegister(instr->hi());
2341 return DefineAsRegister(new(zone()) LConstructDouble(hi, lo));
2345 LInstruction* LChunkBuilder::DoReturn(HReturn* instr) {
2346 LOperand* context = info()->IsStub() ? UseFixed(instr->context(), rsi) : NULL;
2347 LOperand* parameter_count = UseRegisterOrConstant(instr->parameter_count());
2348 return new(zone()) LReturn(
2349 UseFixed(instr->value(), rax), context, parameter_count);
2353 LInstruction* LChunkBuilder::DoConstant(HConstant* instr) {
2354 Representation r = instr->representation();
2356 return DefineAsRegister(new(zone()) LConstantS);
2357 } else if (r.IsInteger32()) {
2358 return DefineAsRegister(new(zone()) LConstantI);
2359 } else if (r.IsDouble()) {
2360 LOperand* temp = TempRegister();
2361 return DefineAsRegister(new(zone()) LConstantD(temp));
2362 } else if (r.IsExternal()) {
2363 return DefineAsRegister(new(zone()) LConstantE);
2364 } else if (r.IsTagged()) {
2365 return DefineAsRegister(new(zone()) LConstantT);
2373 LInstruction* LChunkBuilder::DoLoadGlobalCell(HLoadGlobalCell* instr) {
2374 LLoadGlobalCell* result = new(zone()) LLoadGlobalCell;
2375 return instr->RequiresHoleCheck()
2376 ? AssignEnvironment(DefineAsRegister(result))
2377 : DefineAsRegister(result);
2381 LInstruction* LChunkBuilder::DoLoadGlobalGeneric(HLoadGlobalGeneric* instr) {
2382 LOperand* context = UseFixed(instr->context(), rsi);
2383 LOperand* global_object =
2384 UseFixed(instr->global_object(), LoadDescriptor::ReceiverRegister());
2385 LOperand* vector = NULL;
2386 if (FLAG_vector_ics) {
2387 vector = FixedTemp(VectorLoadICDescriptor::VectorRegister());
2390 LLoadGlobalGeneric* result =
2391 new(zone()) LLoadGlobalGeneric(context, global_object, vector);
2392 return MarkAsCall(DefineFixed(result, rax), instr);
2396 LInstruction* LChunkBuilder::DoStoreGlobalCell(HStoreGlobalCell* instr) {
2397 LOperand* value = UseRegister(instr->value());
2398 // Use a temp to avoid reloading the cell value address in the case where
2399 // we perform a hole check.
2400 return instr->RequiresHoleCheck()
2401 ? AssignEnvironment(new(zone()) LStoreGlobalCell(value, TempRegister()))
2402 : new(zone()) LStoreGlobalCell(value, NULL);
2406 LInstruction* LChunkBuilder::DoLoadContextSlot(HLoadContextSlot* instr) {
2407 LOperand* context = UseRegisterAtStart(instr->value());
2408 LInstruction* result =
2409 DefineAsRegister(new(zone()) LLoadContextSlot(context));
2410 if (instr->RequiresHoleCheck() && instr->DeoptimizesOnHole()) {
2411 result = AssignEnvironment(result);
2417 LInstruction* LChunkBuilder::DoStoreContextSlot(HStoreContextSlot* instr) {
2421 context = UseRegister(instr->context());
2422 if (instr->NeedsWriteBarrier()) {
2423 value = UseTempRegister(instr->value());
2424 temp = TempRegister();
2426 value = UseRegister(instr->value());
2429 LInstruction* result = new(zone()) LStoreContextSlot(context, value, temp);
2430 if (instr->RequiresHoleCheck() && instr->DeoptimizesOnHole()) {
2431 result = AssignEnvironment(result);
2437 LInstruction* LChunkBuilder::DoLoadNamedField(HLoadNamedField* instr) {
2438 // Use the special mov rax, moffs64 encoding for external
2439 // memory accesses with 64-bit word-sized values.
2440 if (instr->access().IsExternalMemory() &&
2441 instr->access().offset() == 0 &&
2442 (instr->access().representation().IsSmi() ||
2443 instr->access().representation().IsTagged() ||
2444 instr->access().representation().IsHeapObject() ||
2445 instr->access().representation().IsExternal())) {
2446 LOperand* obj = UseRegisterOrConstantAtStart(instr->object());
2447 return DefineFixed(new(zone()) LLoadNamedField(obj), rax);
2449 LOperand* obj = UseRegisterAtStart(instr->object());
2450 return DefineAsRegister(new(zone()) LLoadNamedField(obj));
2454 LInstruction* LChunkBuilder::DoLoadNamedGeneric(HLoadNamedGeneric* instr) {
2455 LOperand* context = UseFixed(instr->context(), rsi);
2457 UseFixed(instr->object(), LoadDescriptor::ReceiverRegister());
2458 LOperand* vector = NULL;
2459 if (FLAG_vector_ics) {
2460 vector = FixedTemp(VectorLoadICDescriptor::VectorRegister());
2462 LLoadNamedGeneric* result = new(zone()) LLoadNamedGeneric(
2463 context, object, vector);
2464 return MarkAsCall(DefineFixed(result, rax), instr);
2468 LInstruction* LChunkBuilder::DoLoadFunctionPrototype(
2469 HLoadFunctionPrototype* instr) {
2470 return AssignEnvironment(DefineAsRegister(
2471 new(zone()) LLoadFunctionPrototype(UseRegister(instr->function()))));
2475 LInstruction* LChunkBuilder::DoLoadRoot(HLoadRoot* instr) {
2476 return DefineAsRegister(new(zone()) LLoadRoot);
2480 void LChunkBuilder::FindDehoistedKeyDefinitions(HValue* candidate) {
2481 // We sign extend the dehoisted key at the definition point when the pointer
2482 // size is 64-bit. For x32 port, we sign extend the dehoisted key at the use
2483 // points and should not invoke this function. We can't use STATIC_ASSERT
2484 // here as the pointer size is 32-bit for x32.
2485 DCHECK(kPointerSize == kInt64Size);
2486 BitVector* dehoisted_key_ids = chunk_->GetDehoistedKeyIds();
2487 if (dehoisted_key_ids->Contains(candidate->id())) return;
2488 dehoisted_key_ids->Add(candidate->id());
2489 if (!candidate->IsPhi()) return;
2490 for (int i = 0; i < candidate->OperandCount(); ++i) {
2491 FindDehoistedKeyDefinitions(candidate->OperandAt(i));
2496 LInstruction* LChunkBuilder::DoLoadKeyed(HLoadKeyed* instr) {
2497 DCHECK((kPointerSize == kInt64Size &&
2498 instr->key()->representation().IsInteger32()) ||
2499 (kPointerSize == kInt32Size &&
2500 instr->key()->representation().IsSmiOrInteger32()));
2501 ElementsKind elements_kind = instr->elements_kind();
2502 LOperand* key = NULL;
2503 LInstruction* result = NULL;
2505 if (kPointerSize == kInt64Size) {
2506 bool clobbers_key = ExternalArrayOpRequiresPreScale(
2507 instr->key()->representation(), elements_kind);
2509 ? UseTempRegisterOrConstant(instr->key())
2510 : UseRegisterOrConstantAtStart(instr->key());
2512 bool clobbers_key = ExternalArrayOpRequiresTemp(
2513 instr->key()->representation(), elements_kind);
2515 ? UseTempRegister(instr->key())
2516 : UseRegisterOrConstantAtStart(instr->key());
2519 if ((kPointerSize == kInt64Size) && instr->IsDehoisted()) {
2520 FindDehoistedKeyDefinitions(instr->key());
2524 if (!instr->is_typed_elements()) {
2525 LOperand* obj = UseRegisterAtStart(instr->elements());
2526 result = DefineAsRegister(new(zone()) LLoadKeyed(obj, key));
2529 (instr->representation().IsInteger32() &&
2530 !(IsDoubleOrFloatElementsKind(elements_kind))) ||
2531 (instr->representation().IsDouble() &&
2532 (IsDoubleOrFloatElementsKind(elements_kind))) ||
2533 (instr->representation().IsFloat32x4() &&
2534 IsFloat32x4ElementsKind(elements_kind)) ||
2535 (instr->representation().IsFloat64x2() &&
2536 IsFloat64x2ElementsKind(elements_kind)) ||
2537 (instr->representation().IsInt32x4() &&
2538 IsInt32x4ElementsKind(elements_kind)));
2539 LOperand* backing_store = UseRegister(instr->elements());
2540 result = DefineAsRegister(new(zone()) LLoadKeyed(backing_store, key));
2543 if ((instr->is_external() || instr->is_fixed_typed_array()) ?
2544 // see LCodeGen::DoLoadKeyedExternalArray
2545 ((elements_kind == EXTERNAL_UINT32_ELEMENTS ||
2546 elements_kind == UINT32_ELEMENTS) &&
2547 !instr->CheckFlag(HInstruction::kUint32)) :
2548 // see LCodeGen::DoLoadKeyedFixedDoubleArray and
2549 // LCodeGen::DoLoadKeyedFixedArray
2550 instr->RequiresHoleCheck()) {
2551 result = AssignEnvironment(result);
2557 LInstruction* LChunkBuilder::DoLoadKeyedGeneric(HLoadKeyedGeneric* instr) {
2558 LOperand* context = UseFixed(instr->context(), rsi);
2560 UseFixed(instr->object(), LoadDescriptor::ReceiverRegister());
2561 LOperand* key = UseFixed(instr->key(), LoadDescriptor::NameRegister());
2562 LOperand* vector = NULL;
2563 if (FLAG_vector_ics) {
2564 vector = FixedTemp(VectorLoadICDescriptor::VectorRegister());
2567 LLoadKeyedGeneric* result =
2568 new(zone()) LLoadKeyedGeneric(context, object, key, vector);
2569 return MarkAsCall(DefineFixed(result, rax), instr);
2573 LInstruction* LChunkBuilder::DoStoreKeyed(HStoreKeyed* instr) {
2574 ElementsKind elements_kind = instr->elements_kind();
2576 if ((kPointerSize == kInt64Size) && instr->IsDehoisted()) {
2577 FindDehoistedKeyDefinitions(instr->key());
2580 if (!instr->is_typed_elements()) {
2581 DCHECK(instr->elements()->representation().IsTagged());
2582 bool needs_write_barrier = instr->NeedsWriteBarrier();
2583 LOperand* object = NULL;
2584 LOperand* key = NULL;
2585 LOperand* val = NULL;
2587 Representation value_representation = instr->value()->representation();
2588 if (value_representation.IsDouble()) {
2589 object = UseRegisterAtStart(instr->elements());
2590 val = UseRegisterAtStart(instr->value());
2591 key = UseRegisterOrConstantAtStart(instr->key());
2593 DCHECK(value_representation.IsSmiOrTagged() ||
2594 value_representation.IsInteger32());
2595 if (needs_write_barrier) {
2596 object = UseTempRegister(instr->elements());
2597 val = UseTempRegister(instr->value());
2598 key = UseTempRegister(instr->key());
2600 object = UseRegisterAtStart(instr->elements());
2601 val = UseRegisterOrConstantAtStart(instr->value());
2602 key = UseRegisterOrConstantAtStart(instr->key());
2606 return new(zone()) LStoreKeyed(object, key, val);
2610 (instr->value()->representation().IsInteger32() &&
2611 !IsDoubleOrFloatElementsKind(elements_kind)) ||
2612 (instr->value()->representation().IsDouble() &&
2613 IsDoubleOrFloatElementsKind(elements_kind)) ||
2614 (instr->value()->representation().IsFloat32x4() &&
2615 IsFloat32x4ElementsKind(elements_kind)) ||
2616 (instr->value()->representation().IsFloat64x2() &&
2617 IsFloat64x2ElementsKind(elements_kind)) ||
2618 (instr->value()->representation().IsInt32x4() &&
2619 IsInt32x4ElementsKind(elements_kind)));
2620 DCHECK((instr->is_fixed_typed_array() &&
2621 instr->elements()->representation().IsTagged()) ||
2622 (instr->is_external() &&
2623 instr->elements()->representation().IsExternal()));
2624 bool val_is_temp_register =
2625 elements_kind == EXTERNAL_UINT8_CLAMPED_ELEMENTS ||
2626 elements_kind == EXTERNAL_FLOAT32_ELEMENTS ||
2627 elements_kind == FLOAT32_ELEMENTS;
2628 LOperand* val = val_is_temp_register ? UseTempRegister(instr->value())
2629 : UseRegister(instr->value());
2630 LOperand* key = NULL;
2631 if (kPointerSize == kInt64Size) {
2632 bool clobbers_key = ExternalArrayOpRequiresPreScale(
2633 instr->key()->representation(), elements_kind);
2635 ? UseTempRegisterOrConstant(instr->key())
2636 : UseRegisterOrConstantAtStart(instr->key());
2638 bool clobbers_key = ExternalArrayOpRequiresTemp(
2639 instr->key()->representation(), elements_kind);
2641 ? UseTempRegister(instr->key())
2642 : UseRegisterOrConstantAtStart(instr->key());
2644 LOperand* backing_store = UseRegister(instr->elements());
2645 return new(zone()) LStoreKeyed(backing_store, key, val);
2649 LInstruction* LChunkBuilder::DoStoreKeyedGeneric(HStoreKeyedGeneric* instr) {
2650 LOperand* context = UseFixed(instr->context(), rsi);
2652 UseFixed(instr->object(), StoreDescriptor::ReceiverRegister());
2653 LOperand* key = UseFixed(instr->key(), StoreDescriptor::NameRegister());
2654 LOperand* value = UseFixed(instr->value(), StoreDescriptor::ValueRegister());
2656 DCHECK(instr->object()->representation().IsTagged());
2657 DCHECK(instr->key()->representation().IsTagged());
2658 DCHECK(instr->value()->representation().IsTagged());
2660 LStoreKeyedGeneric* result =
2661 new(zone()) LStoreKeyedGeneric(context, object, key, value);
2662 return MarkAsCall(result, instr);
2666 LInstruction* LChunkBuilder::DoTransitionElementsKind(
2667 HTransitionElementsKind* instr) {
2668 if (IsSimpleMapChangeTransition(instr->from_kind(), instr->to_kind())) {
2669 LOperand* object = UseRegister(instr->object());
2670 LOperand* new_map_reg = TempRegister();
2671 LOperand* temp_reg = TempRegister();
2672 LTransitionElementsKind* result = new(zone()) LTransitionElementsKind(
2673 object, NULL, new_map_reg, temp_reg);
2676 LOperand* object = UseFixed(instr->object(), rax);
2677 LOperand* context = UseFixed(instr->context(), rsi);
2678 LTransitionElementsKind* result =
2679 new(zone()) LTransitionElementsKind(object, context, NULL, NULL);
2680 return MarkAsCall(result, instr);
2685 LInstruction* LChunkBuilder::DoTrapAllocationMemento(
2686 HTrapAllocationMemento* instr) {
2687 LOperand* object = UseRegister(instr->object());
2688 LOperand* temp = TempRegister();
2689 LTrapAllocationMemento* result =
2690 new(zone()) LTrapAllocationMemento(object, temp);
2691 return AssignEnvironment(result);
2695 LInstruction* LChunkBuilder::DoStoreNamedField(HStoreNamedField* instr) {
2696 bool is_in_object = instr->access().IsInobject();
2697 bool is_external_location = instr->access().IsExternalMemory() &&
2698 instr->access().offset() == 0;
2699 bool needs_write_barrier = instr->NeedsWriteBarrier();
2700 bool needs_write_barrier_for_map = instr->has_transition() &&
2701 instr->NeedsWriteBarrierForMap();
2704 if (needs_write_barrier) {
2706 ? UseRegister(instr->object())
2707 : UseTempRegister(instr->object());
2708 } else if (is_external_location) {
2709 DCHECK(!is_in_object);
2710 DCHECK(!needs_write_barrier);
2711 DCHECK(!needs_write_barrier_for_map);
2712 obj = UseRegisterOrConstant(instr->object());
2714 obj = needs_write_barrier_for_map
2715 ? UseRegister(instr->object())
2716 : UseRegisterAtStart(instr->object());
2719 bool can_be_constant = instr->value()->IsConstant() &&
2720 HConstant::cast(instr->value())->NotInNewSpace() &&
2721 !instr->field_representation().IsDouble();
2724 if (needs_write_barrier) {
2725 val = UseTempRegister(instr->value());
2726 } else if (is_external_location) {
2727 val = UseFixed(instr->value(), rax);
2728 } else if (can_be_constant) {
2729 val = UseRegisterOrConstant(instr->value());
2730 } else if (instr->field_representation().IsDouble()) {
2731 val = UseRegisterAtStart(instr->value());
2733 val = UseRegister(instr->value());
2736 // We only need a scratch register if we have a write barrier or we
2737 // have a store into the properties array (not in-object-property).
2738 LOperand* temp = (!is_in_object || needs_write_barrier ||
2739 needs_write_barrier_for_map) ? TempRegister() : NULL;
2741 return new(zone()) LStoreNamedField(obj, val, temp);
2745 LInstruction* LChunkBuilder::DoStoreNamedGeneric(HStoreNamedGeneric* instr) {
2746 LOperand* context = UseFixed(instr->context(), rsi);
2748 UseFixed(instr->object(), StoreDescriptor::ReceiverRegister());
2749 LOperand* value = UseFixed(instr->value(), StoreDescriptor::ValueRegister());
2751 LStoreNamedGeneric* result =
2752 new(zone()) LStoreNamedGeneric(context, object, value);
2753 return MarkAsCall(result, instr);
2757 LInstruction* LChunkBuilder::DoStringAdd(HStringAdd* instr) {
2758 LOperand* context = UseFixed(instr->context(), rsi);
2759 LOperand* left = UseFixed(instr->left(), rdx);
2760 LOperand* right = UseFixed(instr->right(), rax);
2762 DefineFixed(new(zone()) LStringAdd(context, left, right), rax), instr);
2766 LInstruction* LChunkBuilder::DoStringCharCodeAt(HStringCharCodeAt* instr) {
2767 LOperand* string = UseTempRegister(instr->string());
2768 LOperand* index = UseTempRegister(instr->index());
2769 LOperand* context = UseAny(instr->context());
2770 LStringCharCodeAt* result =
2771 new(zone()) LStringCharCodeAt(context, string, index);
2772 return AssignPointerMap(DefineAsRegister(result));
2776 LInstruction* LChunkBuilder::DoStringCharFromCode(HStringCharFromCode* instr) {
2777 LOperand* char_code = UseRegister(instr->value());
2778 LOperand* context = UseAny(instr->context());
2779 LStringCharFromCode* result =
2780 new(zone()) LStringCharFromCode(context, char_code);
2781 return AssignPointerMap(DefineAsRegister(result));
2785 LInstruction* LChunkBuilder::DoAllocate(HAllocate* instr) {
2786 info()->MarkAsDeferredCalling();
2787 LOperand* context = UseAny(instr->context());
2788 LOperand* size = instr->size()->IsConstant()
2789 ? UseConstant(instr->size())
2790 : UseTempRegister(instr->size());
2791 LOperand* temp = TempRegister();
2792 LAllocate* result = new(zone()) LAllocate(context, size, temp);
2793 return AssignPointerMap(DefineAsRegister(result));
2797 LInstruction* LChunkBuilder::DoRegExpLiteral(HRegExpLiteral* instr) {
2798 LOperand* context = UseFixed(instr->context(), rsi);
2799 LRegExpLiteral* result = new(zone()) LRegExpLiteral(context);
2800 return MarkAsCall(DefineFixed(result, rax), instr);
2804 LInstruction* LChunkBuilder::DoFunctionLiteral(HFunctionLiteral* instr) {
2805 LOperand* context = UseFixed(instr->context(), rsi);
2806 LFunctionLiteral* result = new(zone()) LFunctionLiteral(context);
2807 return MarkAsCall(DefineFixed(result, rax), instr);
2811 LInstruction* LChunkBuilder::DoOsrEntry(HOsrEntry* instr) {
2812 DCHECK(argument_count_ == 0);
2813 allocator_->MarkAsOsrEntry();
2814 current_block_->last_environment()->set_ast_id(instr->ast_id());
2815 return AssignEnvironment(new(zone()) LOsrEntry);
2819 LInstruction* LChunkBuilder::DoParameter(HParameter* instr) {
2820 LParameter* result = new(zone()) LParameter;
2821 if (instr->kind() == HParameter::STACK_PARAMETER) {
2822 int spill_index = chunk()->GetParameterStackSlot(instr->index());
2823 return DefineAsSpilled(result, spill_index);
2825 DCHECK(info()->IsStub());
2826 CallInterfaceDescriptor descriptor =
2827 info()->code_stub()->GetCallInterfaceDescriptor();
2828 int index = static_cast<int>(instr->index());
2829 Register reg = descriptor.GetEnvironmentParameterRegister(index);
2830 return DefineFixed(result, reg);
2835 LInstruction* LChunkBuilder::DoUnknownOSRValue(HUnknownOSRValue* instr) {
2836 // Use an index that corresponds to the location in the unoptimized frame,
2837 // which the optimized frame will subsume.
2838 int env_index = instr->index();
2839 int spill_index = 0;
2840 if (instr->environment()->is_parameter_index(env_index)) {
2841 spill_index = chunk()->GetParameterStackSlot(env_index);
2843 spill_index = env_index - instr->environment()->first_local_index();
2844 if (spill_index > LUnallocated::kMaxFixedSlotIndex) {
2845 Retry(kTooManySpillSlotsNeededForOSR);
2849 return DefineAsSpilled(new(zone()) LUnknownOSRValue, spill_index);
2853 LInstruction* LChunkBuilder::DoCallStub(HCallStub* instr) {
2854 LOperand* context = UseFixed(instr->context(), rsi);
2855 LCallStub* result = new(zone()) LCallStub(context);
2856 return MarkAsCall(DefineFixed(result, rax), instr);
2860 LInstruction* LChunkBuilder::DoArgumentsObject(HArgumentsObject* instr) {
2861 // There are no real uses of the arguments object.
2862 // arguments.length and element access are supported directly on
2863 // stack arguments, and any real arguments object use causes a bailout.
2864 // So this value is never used.
2869 LInstruction* LChunkBuilder::DoCapturedObject(HCapturedObject* instr) {
2870 instr->ReplayEnvironment(current_block_->last_environment());
2872 // There are no real uses of a captured object.
2877 LInstruction* LChunkBuilder::DoAccessArgumentsAt(HAccessArgumentsAt* instr) {
2878 info()->MarkAsRequiresFrame();
2879 LOperand* args = UseRegister(instr->arguments());
2882 if (instr->length()->IsConstant() && instr->index()->IsConstant()) {
2883 length = UseRegisterOrConstant(instr->length());
2884 index = UseOrConstant(instr->index());
2886 length = UseTempRegister(instr->length());
2887 index = Use(instr->index());
2889 return DefineAsRegister(new(zone()) LAccessArgumentsAt(args, length, index));
2893 LInstruction* LChunkBuilder::DoToFastProperties(HToFastProperties* instr) {
2894 LOperand* object = UseFixed(instr->value(), rax);
2895 LToFastProperties* result = new(zone()) LToFastProperties(object);
2896 return MarkAsCall(DefineFixed(result, rax), instr);
2900 LInstruction* LChunkBuilder::DoTypeof(HTypeof* instr) {
2901 LOperand* context = UseFixed(instr->context(), rsi);
2902 LOperand* value = UseAtStart(instr->value());
2903 LTypeof* result = new(zone()) LTypeof(context, value);
2904 return MarkAsCall(DefineFixed(result, rax), instr);
2908 LInstruction* LChunkBuilder::DoTypeofIsAndBranch(HTypeofIsAndBranch* instr) {
2909 return new(zone()) LTypeofIsAndBranch(UseTempRegister(instr->value()));
2913 LInstruction* LChunkBuilder::DoIsConstructCallAndBranch(
2914 HIsConstructCallAndBranch* instr) {
2915 return new(zone()) LIsConstructCallAndBranch(TempRegister());
2919 LInstruction* LChunkBuilder::DoSimulate(HSimulate* instr) {
2920 instr->ReplayEnvironment(current_block_->last_environment());
2925 LInstruction* LChunkBuilder::DoStackCheck(HStackCheck* instr) {
2926 info()->MarkAsDeferredCalling();
2927 if (instr->is_function_entry()) {
2928 LOperand* context = UseFixed(instr->context(), rsi);
2929 return MarkAsCall(new(zone()) LStackCheck(context), instr);
2931 DCHECK(instr->is_backwards_branch());
2932 LOperand* context = UseAny(instr->context());
2933 return AssignEnvironment(
2934 AssignPointerMap(new(zone()) LStackCheck(context)));
2939 LInstruction* LChunkBuilder::DoEnterInlined(HEnterInlined* instr) {
2940 HEnvironment* outer = current_block_->last_environment();
2941 outer->set_ast_id(instr->ReturnId());
2942 HConstant* undefined = graph()->GetConstantUndefined();
2943 HEnvironment* inner = outer->CopyForInlining(instr->closure(),
2944 instr->arguments_count(),
2947 instr->inlining_kind());
2948 // Only replay binding of arguments object if it wasn't removed from graph.
2949 if (instr->arguments_var() != NULL && instr->arguments_object()->IsLinked()) {
2950 inner->Bind(instr->arguments_var(), instr->arguments_object());
2952 inner->BindContext(instr->closure_context());
2953 inner->set_entry(instr);
2954 current_block_->UpdateEnvironment(inner);
2955 chunk_->AddInlinedClosure(instr->closure());
2960 LInstruction* LChunkBuilder::DoLeaveInlined(HLeaveInlined* instr) {
2961 LInstruction* pop = NULL;
2963 HEnvironment* env = current_block_->last_environment();
2965 if (env->entry()->arguments_pushed()) {
2966 int argument_count = env->arguments_environment()->parameter_count();
2967 pop = new(zone()) LDrop(argument_count);
2968 DCHECK(instr->argument_delta() == -argument_count);
2971 HEnvironment* outer = current_block_->last_environment()->
2972 DiscardInlined(false);
2973 current_block_->UpdateEnvironment(outer);
2979 LInstruction* LChunkBuilder::DoForInPrepareMap(HForInPrepareMap* instr) {
2980 LOperand* context = UseFixed(instr->context(), rsi);
2981 LOperand* object = UseFixed(instr->enumerable(), rax);
2982 LForInPrepareMap* result = new(zone()) LForInPrepareMap(context, object);
2983 return MarkAsCall(DefineFixed(result, rax), instr, CAN_DEOPTIMIZE_EAGERLY);
2987 LInstruction* LChunkBuilder::DoForInCacheArray(HForInCacheArray* instr) {
2988 LOperand* map = UseRegister(instr->map());
2989 return AssignEnvironment(DefineAsRegister(
2990 new(zone()) LForInCacheArray(map)));
2994 LInstruction* LChunkBuilder::DoCheckMapValue(HCheckMapValue* instr) {
2995 LOperand* value = UseRegisterAtStart(instr->value());
2996 LOperand* map = UseRegisterAtStart(instr->map());
2997 return AssignEnvironment(new(zone()) LCheckMapValue(value, map));
3001 LInstruction* LChunkBuilder::DoLoadFieldByIndex(HLoadFieldByIndex* instr) {
3002 LOperand* object = UseRegister(instr->object());
3003 LOperand* index = UseTempRegister(instr->index());
3004 LLoadFieldByIndex* load = new(zone()) LLoadFieldByIndex(object, index);
3005 LInstruction* result = DefineSameAsFirst(load);
3006 return AssignPointerMap(result);
3010 LInstruction* LChunkBuilder::DoStoreFrameContext(HStoreFrameContext* instr) {
3011 LOperand* context = UseRegisterAtStart(instr->context());
3012 return new(zone()) LStoreFrameContext(context);
3016 LInstruction* LChunkBuilder::DoAllocateBlockContext(
3017 HAllocateBlockContext* instr) {
3018 LOperand* context = UseFixed(instr->context(), rsi);
3019 LOperand* function = UseRegisterAtStart(instr->function());
3020 LAllocateBlockContext* result =
3021 new(zone()) LAllocateBlockContext(context, function);
3022 return MarkAsCall(DefineFixed(result, rsi), instr);
3026 } } // namespace v8::internal
3028 #endif // V8_TARGET_ARCH_X64