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.
11 #include "src/hydrogen-osr.h"
12 #include "src/lithium-inl.h"
13 #include "src/x64/lithium-codegen-x64.h"
18 #define DEFINE_COMPILE(type) \
19 void L##type::CompileToNative(LCodeGen* generator) { \
20 generator->Do##type(this); \
22 LITHIUM_CONCRETE_INSTRUCTION_LIST(DEFINE_COMPILE)
27 void LInstruction::VerifyCall() {
28 // Call instructions can use only fixed registers as temporaries and
29 // outputs because all registers are blocked by the calling convention.
30 // Inputs operands must use a fixed register or use-at-start policy or
31 // a non-register policy.
32 DCHECK(Output() == NULL ||
33 LUnallocated::cast(Output())->HasFixedPolicy() ||
34 !LUnallocated::cast(Output())->HasRegisterPolicy());
35 for (UseIterator it(this); !it.Done(); it.Advance()) {
36 LUnallocated* operand = LUnallocated::cast(it.Current());
37 DCHECK(operand->HasFixedPolicy() ||
38 operand->IsUsedAtStart());
40 for (TempIterator it(this); !it.Done(); it.Advance()) {
41 LUnallocated* operand = LUnallocated::cast(it.Current());
42 DCHECK(operand->HasFixedPolicy() ||!operand->HasRegisterPolicy());
48 void LInstruction::PrintTo(StringStream* stream) {
49 stream->Add("%s ", this->Mnemonic());
51 PrintOutputOperandTo(stream);
55 if (HasEnvironment()) {
57 environment()->PrintTo(stream);
60 if (HasPointerMap()) {
62 pointer_map()->PrintTo(stream);
67 void LInstruction::PrintDataTo(StringStream* stream) {
69 for (int i = 0; i < InputCount(); i++) {
70 if (i > 0) stream->Add(" ");
71 if (InputAt(i) == NULL) {
74 InputAt(i)->PrintTo(stream);
80 void LInstruction::PrintOutputOperandTo(StringStream* stream) {
81 if (HasResult()) result()->PrintTo(stream);
85 void LLabel::PrintDataTo(StringStream* stream) {
86 LGap::PrintDataTo(stream);
87 LLabel* rep = replacement();
89 stream->Add(" Dead block replaced with B%d", rep->block_id());
94 bool LGap::IsRedundant() const {
95 for (int i = 0; i < 4; i++) {
96 if (parallel_moves_[i] != NULL && !parallel_moves_[i]->IsRedundant()) {
105 void LGap::PrintDataTo(StringStream* stream) {
106 for (int i = 0; i < 4; i++) {
108 if (parallel_moves_[i] != NULL) {
109 parallel_moves_[i]->PrintDataTo(stream);
116 const char* LArithmeticD::Mnemonic() const {
118 case Token::ADD: return "add-d";
119 case Token::SUB: return "sub-d";
120 case Token::MUL: return "mul-d";
121 case Token::DIV: return "div-d";
122 case Token::MOD: return "mod-d";
130 const char* LArithmeticT::Mnemonic() const {
132 case Token::ADD: return "add-t";
133 case Token::SUB: return "sub-t";
134 case Token::MUL: return "mul-t";
135 case Token::MOD: return "mod-t";
136 case Token::DIV: return "div-t";
137 case Token::BIT_AND: return "bit-and-t";
138 case Token::BIT_OR: return "bit-or-t";
139 case Token::BIT_XOR: return "bit-xor-t";
140 case Token::ROR: return "ror-t";
141 case Token::SHL: return "sal-t";
142 case Token::SAR: return "sar-t";
143 case Token::SHR: return "shr-t";
151 bool LGoto::HasInterestingComment(LCodeGen* gen) const {
152 return !gen->IsNextEmittedBlock(block_id());
157 bool LTemplateResultInstruction<R>::MustSignExtendResult(
158 LPlatformChunk* chunk) const {
159 HValue* hvalue = this->hydrogen_value();
160 return hvalue != NULL &&
161 hvalue->representation().IsInteger32() &&
162 chunk->GetDehoistedKeyIds()->Contains(hvalue->id());
166 void LGoto::PrintDataTo(StringStream* stream) {
167 stream->Add("B%d", block_id());
171 void LBranch::PrintDataTo(StringStream* stream) {
172 stream->Add("B%d | B%d on ", true_block_id(), false_block_id());
173 value()->PrintTo(stream);
177 void LCompareNumericAndBranch::PrintDataTo(StringStream* stream) {
179 left()->PrintTo(stream);
180 stream->Add(" %s ", Token::String(op()));
181 right()->PrintTo(stream);
182 stream->Add(" then B%d else B%d", true_block_id(), false_block_id());
186 void LIsObjectAndBranch::PrintDataTo(StringStream* stream) {
187 stream->Add("if is_object(");
188 value()->PrintTo(stream);
189 stream->Add(") then B%d else B%d", true_block_id(), false_block_id());
193 void LIsStringAndBranch::PrintDataTo(StringStream* stream) {
194 stream->Add("if is_string(");
195 value()->PrintTo(stream);
196 stream->Add(") then B%d else B%d", true_block_id(), false_block_id());
200 void LIsSmiAndBranch::PrintDataTo(StringStream* stream) {
201 stream->Add("if is_smi(");
202 value()->PrintTo(stream);
203 stream->Add(") then B%d else B%d", true_block_id(), false_block_id());
207 void LIsUndetectableAndBranch::PrintDataTo(StringStream* stream) {
208 stream->Add("if is_undetectable(");
209 value()->PrintTo(stream);
210 stream->Add(") then B%d else B%d", true_block_id(), false_block_id());
214 void LStringCompareAndBranch::PrintDataTo(StringStream* stream) {
215 stream->Add("if string_compare(");
216 left()->PrintTo(stream);
217 right()->PrintTo(stream);
218 stream->Add(") then B%d else B%d", true_block_id(), false_block_id());
222 void LHasInstanceTypeAndBranch::PrintDataTo(StringStream* stream) {
223 stream->Add("if has_instance_type(");
224 value()->PrintTo(stream);
225 stream->Add(") then B%d else B%d", true_block_id(), false_block_id());
229 void LHasCachedArrayIndexAndBranch::PrintDataTo(StringStream* stream) {
230 stream->Add("if has_cached_array_index(");
231 value()->PrintTo(stream);
232 stream->Add(") then B%d else B%d", true_block_id(), false_block_id());
236 void LClassOfTestAndBranch::PrintDataTo(StringStream* stream) {
237 stream->Add("if class_of_test(");
238 value()->PrintTo(stream);
239 stream->Add(", \"%o\") then B%d else B%d",
240 *hydrogen()->class_name(),
246 void LTypeofIsAndBranch::PrintDataTo(StringStream* stream) {
247 stream->Add("if typeof ");
248 value()->PrintTo(stream);
249 stream->Add(" == \"%s\" then B%d else B%d",
250 hydrogen()->type_literal()->ToCString().get(),
251 true_block_id(), false_block_id());
255 void LStoreCodeEntry::PrintDataTo(StringStream* stream) {
257 function()->PrintTo(stream);
258 stream->Add(".code_entry = ");
259 code_object()->PrintTo(stream);
263 void LInnerAllocatedObject::PrintDataTo(StringStream* stream) {
265 base_object()->PrintTo(stream);
267 offset()->PrintTo(stream);
271 void LCallFunction::PrintDataTo(StringStream* stream) {
272 context()->PrintTo(stream);
274 function()->PrintTo(stream);
275 if (hydrogen()->HasVectorAndSlot()) {
276 stream->Add(" (type-feedback-vector ");
277 temp_vector()->PrintTo(stream);
279 temp_slot()->PrintTo(stream);
285 void LCallJSFunction::PrintDataTo(StringStream* stream) {
287 function()->PrintTo(stream);
288 stream->Add("#%d / ", arity());
292 void LCallWithDescriptor::PrintDataTo(StringStream* stream) {
293 for (int i = 0; i < InputCount(); i++) {
294 InputAt(i)->PrintTo(stream);
297 stream->Add("#%d / ", arity());
301 void LLoadContextSlot::PrintDataTo(StringStream* stream) {
302 context()->PrintTo(stream);
303 stream->Add("[%d]", slot_index());
307 void LStoreContextSlot::PrintDataTo(StringStream* stream) {
308 context()->PrintTo(stream);
309 stream->Add("[%d] <- ", slot_index());
310 value()->PrintTo(stream);
314 void LInvokeFunction::PrintDataTo(StringStream* stream) {
316 function()->PrintTo(stream);
317 stream->Add(" #%d / ", arity());
321 void LCallNew::PrintDataTo(StringStream* stream) {
323 constructor()->PrintTo(stream);
324 stream->Add(" #%d / ", arity());
328 void LCallNewArray::PrintDataTo(StringStream* stream) {
330 constructor()->PrintTo(stream);
331 stream->Add(" #%d / ", arity());
332 ElementsKind kind = hydrogen()->elements_kind();
333 stream->Add(" (%s) ", ElementsKindToString(kind));
337 void LAccessArgumentsAt::PrintDataTo(StringStream* stream) {
338 arguments()->PrintTo(stream);
340 stream->Add(" length ");
341 length()->PrintTo(stream);
343 stream->Add(" index ");
344 index()->PrintTo(stream);
348 int LPlatformChunk::GetNextSpillIndex(RegisterKind kind) {
349 if (kind == DOUBLE_REGISTERS && kDoubleSize == 2 * kPointerSize) {
350 // Skip a slot if for a double-width slot for x32 port.
352 // The spill slot's address is at rbp - (index + 1) * kPointerSize -
353 // StandardFrameConstants::kFixedFrameSizeFromFp. kFixedFrameSizeFromFp is
354 // 2 * kPointerSize, if rbp is aligned at 8-byte boundary, the below "|= 1"
355 // will make sure the spilled doubles are aligned at 8-byte boundary.
356 // TODO(haitao): make sure rbp is aligned at 8-byte boundary for x32 port.
357 spill_slot_count_ |= 1;
359 return spill_slot_count_++;
363 LOperand* LPlatformChunk::GetNextSpillSlot(RegisterKind kind) {
364 // All stack slots are Double stack slots on x64.
365 // Alternatively, at some point, start using half-size
366 // stack slots for int32 values.
367 int index = GetNextSpillIndex(kind);
368 if (kind == DOUBLE_REGISTERS) {
369 return LDoubleStackSlot::Create(index, zone());
371 DCHECK(kind == GENERAL_REGISTERS);
372 return LStackSlot::Create(index, zone());
377 void LLoadGlobalViaContext::PrintDataTo(StringStream* stream) {
378 stream->Add("depth:%d slot:%d", depth(), slot_index());
382 void LStoreNamedField::PrintDataTo(StringStream* stream) {
383 object()->PrintTo(stream);
384 std::ostringstream os;
385 os << hydrogen()->access() << " <- ";
386 stream->Add(os.str().c_str());
387 value()->PrintTo(stream);
391 void LStoreNamedGeneric::PrintDataTo(StringStream* stream) {
392 object()->PrintTo(stream);
394 stream->Add(String::cast(*name())->ToCString().get());
396 value()->PrintTo(stream);
400 void LStoreGlobalViaContext::PrintDataTo(StringStream* stream) {
401 stream->Add("depth:%d slot:%d <- ", depth(), slot_index());
402 value()->PrintTo(stream);
406 void LLoadKeyed::PrintDataTo(StringStream* stream) {
407 elements()->PrintTo(stream);
409 key()->PrintTo(stream);
410 if (hydrogen()->IsDehoisted()) {
411 stream->Add(" + %d]", base_offset());
418 void LStoreKeyed::PrintDataTo(StringStream* stream) {
419 elements()->PrintTo(stream);
421 key()->PrintTo(stream);
422 if (hydrogen()->IsDehoisted()) {
423 stream->Add(" + %d] <-", base_offset());
425 stream->Add("] <- ");
428 if (value() == NULL) {
429 DCHECK(hydrogen()->IsConstantHoleStore() &&
430 hydrogen()->value()->representation().IsDouble());
431 stream->Add("<the hole(nan)>");
433 value()->PrintTo(stream);
438 void LStoreKeyedGeneric::PrintDataTo(StringStream* stream) {
439 object()->PrintTo(stream);
441 key()->PrintTo(stream);
442 stream->Add("] <- ");
443 value()->PrintTo(stream);
447 void LTransitionElementsKind::PrintDataTo(StringStream* stream) {
448 object()->PrintTo(stream);
449 stream->Add(" %p -> %p", *original_map(), *transitioned_map());
453 LPlatformChunk* LChunkBuilder::Build() {
455 chunk_ = new(zone()) LPlatformChunk(info(), graph());
456 LPhase phase("L_Building chunk", chunk_);
459 // If compiling for OSR, reserve space for the unoptimized frame,
460 // which will be subsumed into this frame.
461 if (graph()->has_osr()) {
462 for (int i = graph()->osr()->UnoptimizedFrameSlots(); i > 0; i--) {
463 chunk_->GetNextSpillIndex(GENERAL_REGISTERS);
467 const ZoneList<HBasicBlock*>* blocks = graph()->blocks();
468 for (int i = 0; i < blocks->length(); i++) {
469 HBasicBlock* next = NULL;
470 if (i < blocks->length() - 1) next = blocks->at(i + 1);
471 DoBasicBlock(blocks->at(i), next);
472 if (is_aborted()) return NULL;
479 LUnallocated* LChunkBuilder::ToUnallocated(Register reg) {
480 return new(zone()) LUnallocated(LUnallocated::FIXED_REGISTER,
481 Register::ToAllocationIndex(reg));
485 LUnallocated* LChunkBuilder::ToUnallocated(XMMRegister reg) {
486 return new(zone()) LUnallocated(LUnallocated::FIXED_DOUBLE_REGISTER,
487 XMMRegister::ToAllocationIndex(reg));
491 LOperand* LChunkBuilder::UseFixed(HValue* value, Register fixed_register) {
492 return Use(value, ToUnallocated(fixed_register));
496 LOperand* LChunkBuilder::UseFixedDouble(HValue* value, XMMRegister reg) {
497 return Use(value, ToUnallocated(reg));
501 LOperand* LChunkBuilder::UseRegister(HValue* value) {
502 return Use(value, new(zone()) LUnallocated(LUnallocated::MUST_HAVE_REGISTER));
506 LOperand* LChunkBuilder::UseRegisterAtStart(HValue* value) {
508 new(zone()) LUnallocated(LUnallocated::MUST_HAVE_REGISTER,
509 LUnallocated::USED_AT_START));
513 LOperand* LChunkBuilder::UseTempRegister(HValue* value) {
514 return Use(value, new(zone()) LUnallocated(LUnallocated::WRITABLE_REGISTER));
518 LOperand* LChunkBuilder::UseTempRegisterOrConstant(HValue* value) {
519 return value->IsConstant()
520 ? chunk_->DefineConstantOperand(HConstant::cast(value))
521 : UseTempRegister(value);
525 LOperand* LChunkBuilder::Use(HValue* value) {
526 return Use(value, new(zone()) LUnallocated(LUnallocated::NONE));
530 LOperand* LChunkBuilder::UseAtStart(HValue* value) {
531 return Use(value, new(zone()) LUnallocated(LUnallocated::NONE,
532 LUnallocated::USED_AT_START));
536 LOperand* LChunkBuilder::UseOrConstant(HValue* value) {
537 return value->IsConstant()
538 ? chunk_->DefineConstantOperand(HConstant::cast(value))
543 LOperand* LChunkBuilder::UseOrConstantAtStart(HValue* value) {
544 return value->IsConstant()
545 ? chunk_->DefineConstantOperand(HConstant::cast(value))
550 LOperand* LChunkBuilder::UseRegisterOrConstant(HValue* value) {
551 return value->IsConstant()
552 ? chunk_->DefineConstantOperand(HConstant::cast(value))
553 : UseRegister(value);
557 LOperand* LChunkBuilder::UseRegisterOrConstantAtStart(HValue* value) {
558 return value->IsConstant()
559 ? chunk_->DefineConstantOperand(HConstant::cast(value))
560 : UseRegisterAtStart(value);
564 LOperand* LChunkBuilder::UseConstant(HValue* value) {
565 return chunk_->DefineConstantOperand(HConstant::cast(value));
569 LOperand* LChunkBuilder::UseAny(HValue* value) {
570 return value->IsConstant()
571 ? chunk_->DefineConstantOperand(HConstant::cast(value))
572 : Use(value, new(zone()) LUnallocated(LUnallocated::ANY));
576 LOperand* LChunkBuilder::Use(HValue* value, LUnallocated* operand) {
577 if (value->EmitAtUses()) {
578 HInstruction* instr = HInstruction::cast(value);
579 VisitInstruction(instr);
581 operand->set_virtual_register(value->id());
586 LInstruction* LChunkBuilder::Define(LTemplateResultInstruction<1>* instr,
587 LUnallocated* result) {
588 result->set_virtual_register(current_instruction_->id());
589 instr->set_result(result);
594 LInstruction* LChunkBuilder::DefineAsRegister(
595 LTemplateResultInstruction<1>* instr) {
597 new(zone()) LUnallocated(LUnallocated::MUST_HAVE_REGISTER));
601 LInstruction* LChunkBuilder::DefineAsSpilled(
602 LTemplateResultInstruction<1>* instr,
605 new(zone()) LUnallocated(LUnallocated::FIXED_SLOT, index));
609 LInstruction* LChunkBuilder::DefineSameAsFirst(
610 LTemplateResultInstruction<1>* instr) {
612 new(zone()) LUnallocated(LUnallocated::SAME_AS_FIRST_INPUT));
616 LInstruction* LChunkBuilder::DefineFixed(LTemplateResultInstruction<1>* instr,
618 return Define(instr, ToUnallocated(reg));
622 LInstruction* LChunkBuilder::DefineFixedDouble(
623 LTemplateResultInstruction<1>* instr,
625 return Define(instr, ToUnallocated(reg));
629 LInstruction* LChunkBuilder::AssignEnvironment(LInstruction* instr) {
630 HEnvironment* hydrogen_env = current_block_->last_environment();
631 int argument_index_accumulator = 0;
632 ZoneList<HValue*> objects_to_materialize(0, zone());
633 instr->set_environment(CreateEnvironment(
634 hydrogen_env, &argument_index_accumulator, &objects_to_materialize));
639 LInstruction* LChunkBuilder::MarkAsCall(LInstruction* instr,
640 HInstruction* hinstr,
641 CanDeoptimize can_deoptimize) {
642 info()->MarkAsNonDeferredCalling();
648 instr = AssignPointerMap(instr);
650 // If instruction does not have side-effects lazy deoptimization
651 // after the call will try to deoptimize to the point before the call.
652 // Thus we still need to attach environment to this call even if
653 // call sequence can not deoptimize eagerly.
654 bool needs_environment =
655 (can_deoptimize == CAN_DEOPTIMIZE_EAGERLY) ||
656 !hinstr->HasObservableSideEffects();
657 if (needs_environment && !instr->HasEnvironment()) {
658 instr = AssignEnvironment(instr);
659 // We can't really figure out if the environment is needed or not.
660 instr->environment()->set_has_been_used();
667 LInstruction* LChunkBuilder::AssignPointerMap(LInstruction* instr) {
668 DCHECK(!instr->HasPointerMap());
669 instr->set_pointer_map(new(zone()) LPointerMap(zone()));
674 LUnallocated* LChunkBuilder::TempRegister() {
675 LUnallocated* operand =
676 new(zone()) LUnallocated(LUnallocated::MUST_HAVE_REGISTER);
677 int vreg = allocator_->GetVirtualRegister();
678 if (!allocator_->AllocationOk()) {
679 Abort(kOutOfVirtualRegistersWhileTryingToAllocateTempRegister);
682 operand->set_virtual_register(vreg);
687 LOperand* LChunkBuilder::FixedTemp(Register reg) {
688 LUnallocated* operand = ToUnallocated(reg);
689 DCHECK(operand->HasFixedPolicy());
694 LOperand* LChunkBuilder::FixedTemp(XMMRegister reg) {
695 LUnallocated* operand = ToUnallocated(reg);
696 DCHECK(operand->HasFixedPolicy());
701 LInstruction* LChunkBuilder::DoBlockEntry(HBlockEntry* instr) {
702 return new(zone()) LLabel(instr->block());
706 LInstruction* LChunkBuilder::DoDummyUse(HDummyUse* instr) {
707 return DefineAsRegister(new(zone()) LDummyUse(UseAny(instr->value())));
711 LInstruction* LChunkBuilder::DoEnvironmentMarker(HEnvironmentMarker* instr) {
717 LInstruction* LChunkBuilder::DoDeoptimize(HDeoptimize* instr) {
718 return AssignEnvironment(new(zone()) LDeoptimize);
722 LInstruction* LChunkBuilder::DoShift(Token::Value op,
723 HBitwiseBinaryOperation* instr) {
724 if (instr->representation().IsSmiOrInteger32()) {
725 DCHECK(instr->left()->representation().Equals(instr->representation()));
726 DCHECK(instr->right()->representation().Equals(instr->representation()));
727 LOperand* left = UseRegisterAtStart(instr->left());
729 HValue* right_value = instr->right();
730 LOperand* right = NULL;
731 int constant_value = 0;
732 bool does_deopt = false;
733 if (right_value->IsConstant()) {
734 HConstant* constant = HConstant::cast(right_value);
735 right = chunk_->DefineConstantOperand(constant);
736 constant_value = constant->Integer32Value() & 0x1f;
737 if (SmiValuesAre31Bits() && instr->representation().IsSmi() &&
738 constant_value > 0) {
739 // Left shift can deoptimize if we shift by > 0 and the result
740 // cannot be truncated to smi.
741 does_deopt = !instr->CheckUsesForFlag(HValue::kTruncatingToSmi);
744 right = UseFixed(right_value, rcx);
747 // Shift operations can only deoptimize if we do a logical shift by 0 and
748 // the result cannot be truncated to int32.
749 if (op == Token::SHR && constant_value == 0) {
750 does_deopt = !instr->CheckFlag(HInstruction::kUint32);
753 LInstruction* result =
754 DefineSameAsFirst(new(zone()) LShiftI(op, left, right, does_deopt));
755 return does_deopt ? AssignEnvironment(result) : result;
757 return DoArithmeticT(op, instr);
762 LInstruction* LChunkBuilder::DoArithmeticD(Token::Value op,
763 HArithmeticBinaryOperation* instr) {
764 DCHECK(instr->representation().IsDouble());
765 DCHECK(instr->left()->representation().IsDouble());
766 DCHECK(instr->right()->representation().IsDouble());
767 if (op == Token::MOD) {
768 LOperand* left = UseRegisterAtStart(instr->BetterLeftOperand());
769 LOperand* right = UseFixedDouble(instr->BetterRightOperand(), xmm1);
770 LArithmeticD* result = new(zone()) LArithmeticD(op, left, right);
771 return MarkAsCall(DefineSameAsFirst(result), instr);
773 LOperand* left = UseRegisterAtStart(instr->BetterLeftOperand());
774 LOperand* right = UseRegisterAtStart(instr->BetterRightOperand());
775 LArithmeticD* result = new(zone()) LArithmeticD(op, left, right);
776 return CpuFeatures::IsSupported(AVX) ? DefineAsRegister(result)
777 : DefineSameAsFirst(result);
782 LInstruction* LChunkBuilder::DoArithmeticT(Token::Value op,
783 HBinaryOperation* instr) {
784 HValue* left = instr->left();
785 HValue* right = instr->right();
786 DCHECK(left->representation().IsTagged());
787 DCHECK(right->representation().IsTagged());
788 LOperand* context = UseFixed(instr->context(), rsi);
789 LOperand* left_operand = UseFixed(left, rdx);
790 LOperand* right_operand = UseFixed(right, rax);
791 LArithmeticT* result =
792 new(zone()) LArithmeticT(op, context, left_operand, right_operand);
793 return MarkAsCall(DefineFixed(result, rax), instr);
797 void LChunkBuilder::DoBasicBlock(HBasicBlock* block, HBasicBlock* next_block) {
798 DCHECK(is_building());
799 current_block_ = block;
800 next_block_ = next_block;
801 if (block->IsStartBlock()) {
802 block->UpdateEnvironment(graph_->start_environment());
804 } else if (block->predecessors()->length() == 1) {
805 // We have a single predecessor => copy environment and outgoing
806 // argument count from the predecessor.
807 DCHECK(block->phis()->length() == 0);
808 HBasicBlock* pred = block->predecessors()->at(0);
809 HEnvironment* last_environment = pred->last_environment();
810 DCHECK(last_environment != NULL);
811 // Only copy the environment, if it is later used again.
812 if (pred->end()->SecondSuccessor() == NULL) {
813 DCHECK(pred->end()->FirstSuccessor() == block);
815 if (pred->end()->FirstSuccessor()->block_id() > block->block_id() ||
816 pred->end()->SecondSuccessor()->block_id() > block->block_id()) {
817 last_environment = last_environment->Copy();
820 block->UpdateEnvironment(last_environment);
821 DCHECK(pred->argument_count() >= 0);
822 argument_count_ = pred->argument_count();
824 // We are at a state join => process phis.
825 HBasicBlock* pred = block->predecessors()->at(0);
826 // No need to copy the environment, it cannot be used later.
827 HEnvironment* last_environment = pred->last_environment();
828 for (int i = 0; i < block->phis()->length(); ++i) {
829 HPhi* phi = block->phis()->at(i);
830 if (phi->HasMergedIndex()) {
831 last_environment->SetValueAt(phi->merged_index(), phi);
834 for (int i = 0; i < block->deleted_phis()->length(); ++i) {
835 if (block->deleted_phis()->at(i) < last_environment->length()) {
836 last_environment->SetValueAt(block->deleted_phis()->at(i),
837 graph_->GetConstantUndefined());
840 block->UpdateEnvironment(last_environment);
841 // Pick up the outgoing argument count of one of the predecessors.
842 argument_count_ = pred->argument_count();
844 HInstruction* current = block->first();
845 int start = chunk_->instructions()->length();
846 while (current != NULL && !is_aborted()) {
847 // Code for constants in registers is generated lazily.
848 if (!current->EmitAtUses()) {
849 VisitInstruction(current);
851 current = current->next();
853 int end = chunk_->instructions()->length() - 1;
855 block->set_first_instruction_index(start);
856 block->set_last_instruction_index(end);
858 block->set_argument_count(argument_count_);
860 current_block_ = NULL;
864 void LChunkBuilder::VisitInstruction(HInstruction* current) {
865 HInstruction* old_current = current_instruction_;
866 current_instruction_ = current;
868 LInstruction* instr = NULL;
869 if (current->CanReplaceWithDummyUses()) {
870 if (current->OperandCount() == 0) {
871 instr = DefineAsRegister(new(zone()) LDummy());
873 DCHECK(!current->OperandAt(0)->IsControlInstruction());
874 instr = DefineAsRegister(new(zone())
875 LDummyUse(UseAny(current->OperandAt(0))));
877 for (int i = 1; i < current->OperandCount(); ++i) {
878 if (current->OperandAt(i)->IsControlInstruction()) continue;
879 LInstruction* dummy =
880 new(zone()) LDummyUse(UseAny(current->OperandAt(i)));
881 dummy->set_hydrogen_value(current);
882 chunk_->AddInstruction(dummy, current_block_);
885 HBasicBlock* successor;
886 if (current->IsControlInstruction() &&
887 HControlInstruction::cast(current)->KnownSuccessorBlock(&successor) &&
889 instr = new(zone()) LGoto(successor);
891 instr = current->CompileToLithium(this);
895 argument_count_ += current->argument_delta();
896 DCHECK(argument_count_ >= 0);
899 AddInstruction(instr, current);
902 current_instruction_ = old_current;
906 void LChunkBuilder::AddInstruction(LInstruction* instr,
907 HInstruction* hydrogen_val) {
908 // Associate the hydrogen instruction first, since we may need it for
909 // the ClobbersRegisters() or ClobbersDoubleRegisters() calls below.
910 instr->set_hydrogen_value(hydrogen_val);
913 // Make sure that the lithium instruction has either no fixed register
914 // constraints in temps or the result OR no uses that are only used at
915 // start. If this invariant doesn't hold, the register allocator can decide
916 // to insert a split of a range immediately before the instruction due to an
917 // already allocated register needing to be used for the instruction's fixed
918 // register constraint. In this case, The register allocator won't see an
919 // interference between the split child and the use-at-start (it would if
920 // the it was just a plain use), so it is free to move the split child into
921 // the same register that is used for the use-at-start.
922 // See https://code.google.com/p/chromium/issues/detail?id=201590
923 if (!(instr->ClobbersRegisters() &&
924 instr->ClobbersDoubleRegisters(isolate()))) {
926 int used_at_start = 0;
927 for (UseIterator it(instr); !it.Done(); it.Advance()) {
928 LUnallocated* operand = LUnallocated::cast(it.Current());
929 if (operand->IsUsedAtStart()) ++used_at_start;
931 if (instr->Output() != NULL) {
932 if (LUnallocated::cast(instr->Output())->HasFixedPolicy()) ++fixed;
934 for (TempIterator it(instr); !it.Done(); it.Advance()) {
935 LUnallocated* operand = LUnallocated::cast(it.Current());
936 if (operand->HasFixedPolicy()) ++fixed;
938 DCHECK(fixed == 0 || used_at_start == 0);
942 if (FLAG_stress_pointer_maps && !instr->HasPointerMap()) {
943 instr = AssignPointerMap(instr);
945 if (FLAG_stress_environments && !instr->HasEnvironment()) {
946 instr = AssignEnvironment(instr);
948 chunk_->AddInstruction(instr, current_block_);
950 if (instr->IsCall()) {
951 HValue* hydrogen_value_for_lazy_bailout = hydrogen_val;
952 LInstruction* instruction_needing_environment = NULL;
953 if (hydrogen_val->HasObservableSideEffects()) {
954 HSimulate* sim = HSimulate::cast(hydrogen_val->next());
955 instruction_needing_environment = instr;
956 sim->ReplayEnvironment(current_block_->last_environment());
957 hydrogen_value_for_lazy_bailout = sim;
959 LInstruction* bailout = AssignEnvironment(new(zone()) LLazyBailout());
960 bailout->set_hydrogen_value(hydrogen_value_for_lazy_bailout);
961 chunk_->AddInstruction(bailout, current_block_);
962 if (instruction_needing_environment != NULL) {
963 // Store the lazy deopt environment with the instruction if needed.
964 // Right now it is only used for LInstanceOfKnownGlobal.
965 instruction_needing_environment->
966 SetDeferredLazyDeoptimizationEnvironment(bailout->environment());
972 LInstruction* LChunkBuilder::DoGoto(HGoto* instr) {
973 return new(zone()) LGoto(instr->FirstSuccessor());
977 LInstruction* LChunkBuilder::DoDebugBreak(HDebugBreak* instr) {
978 return new(zone()) LDebugBreak();
982 LInstruction* LChunkBuilder::DoBranch(HBranch* instr) {
983 HValue* value = instr->value();
984 Representation r = value->representation();
985 HType type = value->type();
986 ToBooleanStub::Types expected = instr->expected_input_types();
987 if (expected.IsEmpty()) expected = ToBooleanStub::Types::Generic();
989 bool easy_case = !r.IsTagged() || type.IsBoolean() || type.IsSmi() ||
990 type.IsJSArray() || type.IsHeapNumber() || type.IsString();
991 LInstruction* branch = new(zone()) LBranch(UseRegister(value));
993 ((!expected.Contains(ToBooleanStub::SMI) && expected.NeedsMap()) ||
994 !expected.IsGeneric())) {
995 branch = AssignEnvironment(branch);
1001 LInstruction* LChunkBuilder::DoCompareMap(HCompareMap* instr) {
1002 DCHECK(instr->value()->representation().IsTagged());
1003 LOperand* value = UseRegisterAtStart(instr->value());
1004 return new(zone()) LCmpMapAndBranch(value);
1008 LInstruction* LChunkBuilder::DoArgumentsLength(HArgumentsLength* length) {
1009 info()->MarkAsRequiresFrame();
1010 return DefineAsRegister(new(zone()) LArgumentsLength(Use(length->value())));
1014 LInstruction* LChunkBuilder::DoArgumentsElements(HArgumentsElements* elems) {
1015 info()->MarkAsRequiresFrame();
1016 return DefineAsRegister(new(zone()) LArgumentsElements);
1020 LInstruction* LChunkBuilder::DoInstanceOf(HInstanceOf* instr) {
1021 LOperand* left = UseFixed(instr->left(), rax);
1022 LOperand* right = UseFixed(instr->right(), rdx);
1023 LOperand* context = UseFixed(instr->context(), rsi);
1024 LInstanceOf* result = new(zone()) LInstanceOf(context, left, right);
1025 return MarkAsCall(DefineFixed(result, rax), instr);
1029 LInstruction* LChunkBuilder::DoInstanceOfKnownGlobal(
1030 HInstanceOfKnownGlobal* instr) {
1031 LInstanceOfKnownGlobal* result =
1032 new(zone()) LInstanceOfKnownGlobal(UseFixed(instr->context(), rsi),
1033 UseFixed(instr->left(), rax),
1035 return MarkAsCall(DefineFixed(result, rax), instr);
1039 LInstruction* LChunkBuilder::DoWrapReceiver(HWrapReceiver* instr) {
1040 LOperand* receiver = UseRegister(instr->receiver());
1041 LOperand* function = UseRegisterAtStart(instr->function());
1042 LWrapReceiver* result = new(zone()) LWrapReceiver(receiver, function);
1043 return AssignEnvironment(DefineSameAsFirst(result));
1047 LInstruction* LChunkBuilder::DoApplyArguments(HApplyArguments* instr) {
1048 LOperand* function = UseFixed(instr->function(), rdi);
1049 LOperand* receiver = UseFixed(instr->receiver(), rax);
1050 LOperand* length = UseFixed(instr->length(), rbx);
1051 LOperand* elements = UseFixed(instr->elements(), rcx);
1052 LApplyArguments* result = new(zone()) LApplyArguments(function,
1056 return MarkAsCall(DefineFixed(result, rax), instr, CAN_DEOPTIMIZE_EAGERLY);
1060 LInstruction* LChunkBuilder::DoPushArguments(HPushArguments* instr) {
1061 int argc = instr->OperandCount();
1062 for (int i = 0; i < argc; ++i) {
1063 LOperand* argument = UseOrConstant(instr->argument(i));
1064 AddInstruction(new(zone()) LPushArgument(argument), instr);
1070 LInstruction* LChunkBuilder::DoStoreCodeEntry(
1071 HStoreCodeEntry* store_code_entry) {
1072 LOperand* function = UseRegister(store_code_entry->function());
1073 LOperand* code_object = UseTempRegister(store_code_entry->code_object());
1074 return new(zone()) LStoreCodeEntry(function, code_object);
1078 LInstruction* LChunkBuilder::DoInnerAllocatedObject(
1079 HInnerAllocatedObject* instr) {
1080 LOperand* base_object = UseRegisterAtStart(instr->base_object());
1081 LOperand* offset = UseRegisterOrConstantAtStart(instr->offset());
1082 return DefineAsRegister(
1083 new(zone()) LInnerAllocatedObject(base_object, offset));
1087 LInstruction* LChunkBuilder::DoThisFunction(HThisFunction* instr) {
1088 return instr->HasNoUses()
1090 : DefineAsRegister(new(zone()) LThisFunction);
1094 LInstruction* LChunkBuilder::DoContext(HContext* instr) {
1095 if (instr->HasNoUses()) return NULL;
1097 if (info()->IsStub()) {
1098 return DefineFixed(new(zone()) LContext, rsi);
1101 return DefineAsRegister(new(zone()) LContext);
1105 LInstruction* LChunkBuilder::DoDeclareGlobals(HDeclareGlobals* instr) {
1106 LOperand* context = UseFixed(instr->context(), rsi);
1107 return MarkAsCall(new(zone()) LDeclareGlobals(context), instr);
1111 LInstruction* LChunkBuilder::DoCallJSFunction(
1112 HCallJSFunction* instr) {
1113 LOperand* function = UseFixed(instr->function(), rdi);
1115 LCallJSFunction* result = new(zone()) LCallJSFunction(function);
1117 return MarkAsCall(DefineFixed(result, rax), instr);
1121 LInstruction* LChunkBuilder::DoCallWithDescriptor(
1122 HCallWithDescriptor* instr) {
1123 CallInterfaceDescriptor descriptor = instr->descriptor();
1125 LOperand* target = UseRegisterOrConstantAtStart(instr->target());
1126 ZoneList<LOperand*> ops(instr->OperandCount(), zone());
1128 ops.Add(target, zone());
1130 LOperand* op = UseFixed(instr->OperandAt(1), rsi);
1131 ops.Add(op, zone());
1132 // Other register parameters
1133 for (int i = LCallWithDescriptor::kImplicitRegisterParameterCount;
1134 i < instr->OperandCount(); i++) {
1136 UseFixed(instr->OperandAt(i),
1137 descriptor.GetRegisterParameter(
1138 i - LCallWithDescriptor::kImplicitRegisterParameterCount));
1139 ops.Add(op, zone());
1142 LCallWithDescriptor* result = new(zone()) LCallWithDescriptor(
1143 descriptor, ops, zone());
1144 return MarkAsCall(DefineFixed(result, rax), instr);
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 LInstruction* LChunkBuilder::DoCallNew(HCallNew* instr) {
1257 LOperand* context = UseFixed(instr->context(), rsi);
1258 LOperand* constructor = UseFixed(instr->constructor(), rdi);
1259 LCallNew* result = new(zone()) LCallNew(context, constructor);
1260 return MarkAsCall(DefineFixed(result, rax), instr);
1264 LInstruction* LChunkBuilder::DoCallNewArray(HCallNewArray* instr) {
1265 LOperand* context = UseFixed(instr->context(), rsi);
1266 LOperand* constructor = UseFixed(instr->constructor(), rdi);
1267 LCallNewArray* result = new(zone()) LCallNewArray(context, constructor);
1268 return MarkAsCall(DefineFixed(result, rax), instr);
1272 LInstruction* LChunkBuilder::DoCallFunction(HCallFunction* instr) {
1273 LOperand* context = UseFixed(instr->context(), rsi);
1274 LOperand* function = UseFixed(instr->function(), rdi);
1275 LOperand* slot = NULL;
1276 LOperand* vector = NULL;
1277 if (instr->HasVectorAndSlot()) {
1278 slot = FixedTemp(rdx);
1279 vector = FixedTemp(rbx);
1281 LCallFunction* call =
1282 new (zone()) LCallFunction(context, function, slot, vector);
1283 return MarkAsCall(DefineFixed(call, rax), instr);
1287 LInstruction* LChunkBuilder::DoCallRuntime(HCallRuntime* instr) {
1288 LOperand* context = UseFixed(instr->context(), rsi);
1289 LCallRuntime* result = new(zone()) LCallRuntime(context);
1290 return MarkAsCall(DefineFixed(result, rax), instr);
1294 LInstruction* LChunkBuilder::DoRor(HRor* instr) {
1295 return DoShift(Token::ROR, instr);
1299 LInstruction* LChunkBuilder::DoShr(HShr* instr) {
1300 return DoShift(Token::SHR, instr);
1304 LInstruction* LChunkBuilder::DoSar(HSar* instr) {
1305 return DoShift(Token::SAR, instr);
1309 LInstruction* LChunkBuilder::DoShl(HShl* instr) {
1310 return DoShift(Token::SHL, instr);
1314 LInstruction* LChunkBuilder::DoBitwise(HBitwise* instr) {
1315 if (instr->representation().IsSmiOrInteger32()) {
1316 DCHECK(instr->left()->representation().Equals(instr->representation()));
1317 DCHECK(instr->right()->representation().Equals(instr->representation()));
1318 DCHECK(instr->CheckFlag(HValue::kTruncatingToInt32));
1320 LOperand* left = UseRegisterAtStart(instr->BetterLeftOperand());
1322 if (SmiValuesAre32Bits() && instr->representation().IsSmi()) {
1323 // We don't support tagged immediates, so we request it in a register.
1324 right = UseRegisterAtStart(instr->BetterRightOperand());
1326 right = UseOrConstantAtStart(instr->BetterRightOperand());
1328 return DefineSameAsFirst(new(zone()) LBitI(left, right));
1330 return DoArithmeticT(instr->op(), instr);
1335 LInstruction* LChunkBuilder::DoDivByPowerOf2I(HDiv* instr) {
1336 DCHECK(instr->representation().IsSmiOrInteger32());
1337 DCHECK(instr->left()->representation().Equals(instr->representation()));
1338 DCHECK(instr->right()->representation().Equals(instr->representation()));
1339 LOperand* dividend = UseRegister(instr->left());
1340 int32_t divisor = instr->right()->GetInteger32Constant();
1341 LInstruction* result = DefineAsRegister(new(zone()) LDivByPowerOf2I(
1342 dividend, divisor));
1343 if ((instr->CheckFlag(HValue::kBailoutOnMinusZero) && divisor < 0) ||
1344 (instr->CheckFlag(HValue::kCanOverflow) && divisor == -1) ||
1345 (!instr->CheckFlag(HInstruction::kAllUsesTruncatingToInt32) &&
1346 divisor != 1 && divisor != -1)) {
1347 result = AssignEnvironment(result);
1353 LInstruction* LChunkBuilder::DoDivByConstI(HDiv* instr) {
1354 DCHECK(instr->representation().IsInteger32());
1355 DCHECK(instr->left()->representation().Equals(instr->representation()));
1356 DCHECK(instr->right()->representation().Equals(instr->representation()));
1357 LOperand* dividend = UseRegister(instr->left());
1358 int32_t divisor = instr->right()->GetInteger32Constant();
1359 LOperand* temp1 = FixedTemp(rax);
1360 LOperand* temp2 = FixedTemp(rdx);
1361 LInstruction* result = DefineFixed(new(zone()) LDivByConstI(
1362 dividend, divisor, temp1, temp2), rdx);
1364 (instr->CheckFlag(HValue::kBailoutOnMinusZero) && divisor < 0) ||
1365 !instr->CheckFlag(HInstruction::kAllUsesTruncatingToInt32)) {
1366 result = AssignEnvironment(result);
1372 LInstruction* LChunkBuilder::DoDivI(HDiv* instr) {
1373 DCHECK(instr->representation().IsSmiOrInteger32());
1374 DCHECK(instr->left()->representation().Equals(instr->representation()));
1375 DCHECK(instr->right()->representation().Equals(instr->representation()));
1376 LOperand* dividend = UseFixed(instr->left(), rax);
1377 LOperand* divisor = UseRegister(instr->right());
1378 LOperand* temp = FixedTemp(rdx);
1379 LInstruction* result = DefineFixed(new(zone()) LDivI(
1380 dividend, divisor, temp), rax);
1381 if (instr->CheckFlag(HValue::kCanBeDivByZero) ||
1382 instr->CheckFlag(HValue::kBailoutOnMinusZero) ||
1383 instr->CheckFlag(HValue::kCanOverflow) ||
1384 !instr->CheckFlag(HValue::kAllUsesTruncatingToInt32)) {
1385 result = AssignEnvironment(result);
1391 LInstruction* LChunkBuilder::DoDiv(HDiv* instr) {
1392 if (instr->representation().IsSmiOrInteger32()) {
1393 if (instr->RightIsPowerOf2()) {
1394 return DoDivByPowerOf2I(instr);
1395 } else if (instr->right()->IsConstant()) {
1396 return DoDivByConstI(instr);
1398 return DoDivI(instr);
1400 } else if (instr->representation().IsDouble()) {
1401 return DoArithmeticD(Token::DIV, instr);
1403 return DoArithmeticT(Token::DIV, instr);
1408 LInstruction* LChunkBuilder::DoFlooringDivByPowerOf2I(HMathFloorOfDiv* instr) {
1409 LOperand* dividend = UseRegisterAtStart(instr->left());
1410 int32_t divisor = instr->right()->GetInteger32Constant();
1411 LInstruction* result = DefineSameAsFirst(new(zone()) LFlooringDivByPowerOf2I(
1412 dividend, divisor));
1413 if ((instr->CheckFlag(HValue::kBailoutOnMinusZero) && divisor < 0) ||
1414 (instr->CheckFlag(HValue::kLeftCanBeMinInt) && divisor == -1)) {
1415 result = AssignEnvironment(result);
1421 LInstruction* LChunkBuilder::DoFlooringDivByConstI(HMathFloorOfDiv* instr) {
1422 DCHECK(instr->representation().IsInteger32());
1423 DCHECK(instr->left()->representation().Equals(instr->representation()));
1424 DCHECK(instr->right()->representation().Equals(instr->representation()));
1425 LOperand* dividend = UseRegister(instr->left());
1426 int32_t divisor = instr->right()->GetInteger32Constant();
1427 LOperand* temp1 = FixedTemp(rax);
1428 LOperand* temp2 = FixedTemp(rdx);
1430 ((divisor > 0 && !instr->CheckFlag(HValue::kLeftCanBeNegative)) ||
1431 (divisor < 0 && !instr->CheckFlag(HValue::kLeftCanBePositive))) ?
1432 NULL : TempRegister();
1433 LInstruction* result =
1434 DefineFixed(new(zone()) LFlooringDivByConstI(dividend,
1441 (instr->CheckFlag(HValue::kBailoutOnMinusZero) && divisor < 0)) {
1442 result = AssignEnvironment(result);
1448 LInstruction* LChunkBuilder::DoFlooringDivI(HMathFloorOfDiv* instr) {
1449 DCHECK(instr->representation().IsSmiOrInteger32());
1450 DCHECK(instr->left()->representation().Equals(instr->representation()));
1451 DCHECK(instr->right()->representation().Equals(instr->representation()));
1452 LOperand* dividend = UseFixed(instr->left(), rax);
1453 LOperand* divisor = UseRegister(instr->right());
1454 LOperand* temp = FixedTemp(rdx);
1455 LInstruction* result = DefineFixed(new(zone()) LFlooringDivI(
1456 dividend, divisor, temp), rax);
1457 if (instr->CheckFlag(HValue::kCanBeDivByZero) ||
1458 instr->CheckFlag(HValue::kBailoutOnMinusZero) ||
1459 instr->CheckFlag(HValue::kCanOverflow)) {
1460 result = AssignEnvironment(result);
1466 LInstruction* LChunkBuilder::DoMathFloorOfDiv(HMathFloorOfDiv* instr) {
1467 if (instr->RightIsPowerOf2()) {
1468 return DoFlooringDivByPowerOf2I(instr);
1469 } else if (instr->right()->IsConstant()) {
1470 return DoFlooringDivByConstI(instr);
1472 return DoFlooringDivI(instr);
1477 LInstruction* LChunkBuilder::DoModByPowerOf2I(HMod* instr) {
1478 DCHECK(instr->representation().IsSmiOrInteger32());
1479 DCHECK(instr->left()->representation().Equals(instr->representation()));
1480 DCHECK(instr->right()->representation().Equals(instr->representation()));
1481 LOperand* dividend = UseRegisterAtStart(instr->left());
1482 int32_t divisor = instr->right()->GetInteger32Constant();
1483 LInstruction* result = DefineSameAsFirst(new(zone()) LModByPowerOf2I(
1484 dividend, divisor));
1485 if (instr->CheckFlag(HValue::kLeftCanBeNegative) &&
1486 instr->CheckFlag(HValue::kBailoutOnMinusZero)) {
1487 result = AssignEnvironment(result);
1493 LInstruction* LChunkBuilder::DoModByConstI(HMod* instr) {
1494 DCHECK(instr->representation().IsSmiOrInteger32());
1495 DCHECK(instr->left()->representation().Equals(instr->representation()));
1496 DCHECK(instr->right()->representation().Equals(instr->representation()));
1497 LOperand* dividend = UseRegister(instr->left());
1498 int32_t divisor = instr->right()->GetInteger32Constant();
1499 LOperand* temp1 = FixedTemp(rax);
1500 LOperand* temp2 = FixedTemp(rdx);
1501 LInstruction* result = DefineFixed(new(zone()) LModByConstI(
1502 dividend, divisor, temp1, temp2), rax);
1503 if (divisor == 0 || instr->CheckFlag(HValue::kBailoutOnMinusZero)) {
1504 result = AssignEnvironment(result);
1510 LInstruction* LChunkBuilder::DoModI(HMod* instr) {
1511 DCHECK(instr->representation().IsSmiOrInteger32());
1512 DCHECK(instr->left()->representation().Equals(instr->representation()));
1513 DCHECK(instr->right()->representation().Equals(instr->representation()));
1514 LOperand* dividend = UseFixed(instr->left(), rax);
1515 LOperand* divisor = UseRegister(instr->right());
1516 LOperand* temp = FixedTemp(rdx);
1517 LInstruction* result = DefineFixed(new(zone()) LModI(
1518 dividend, divisor, temp), rdx);
1519 if (instr->CheckFlag(HValue::kCanBeDivByZero) ||
1520 instr->CheckFlag(HValue::kBailoutOnMinusZero)) {
1521 result = AssignEnvironment(result);
1527 LInstruction* LChunkBuilder::DoMod(HMod* instr) {
1528 if (instr->representation().IsSmiOrInteger32()) {
1529 if (instr->RightIsPowerOf2()) {
1530 return DoModByPowerOf2I(instr);
1531 } else if (instr->right()->IsConstant()) {
1532 return DoModByConstI(instr);
1534 return DoModI(instr);
1536 } else if (instr->representation().IsDouble()) {
1537 return DoArithmeticD(Token::MOD, instr);
1539 return DoArithmeticT(Token::MOD, instr);
1544 LInstruction* LChunkBuilder::DoMul(HMul* instr) {
1545 if (instr->representation().IsSmiOrInteger32()) {
1546 DCHECK(instr->left()->representation().Equals(instr->representation()));
1547 DCHECK(instr->right()->representation().Equals(instr->representation()));
1548 LOperand* left = UseRegisterAtStart(instr->BetterLeftOperand());
1549 LOperand* right = UseOrConstant(instr->BetterRightOperand());
1550 LMulI* mul = new(zone()) LMulI(left, right);
1551 if (instr->CheckFlag(HValue::kCanOverflow) ||
1552 instr->CheckFlag(HValue::kBailoutOnMinusZero)) {
1553 AssignEnvironment(mul);
1555 return DefineSameAsFirst(mul);
1556 } else if (instr->representation().IsDouble()) {
1557 return DoArithmeticD(Token::MUL, instr);
1559 return DoArithmeticT(Token::MUL, instr);
1564 LInstruction* LChunkBuilder::DoSub(HSub* instr) {
1565 if (instr->representation().IsSmiOrInteger32()) {
1566 DCHECK(instr->left()->representation().Equals(instr->representation()));
1567 DCHECK(instr->right()->representation().Equals(instr->representation()));
1568 LOperand* left = UseRegisterAtStart(instr->left());
1570 if (SmiValuesAre32Bits() && instr->representation().IsSmi()) {
1571 // We don't support tagged immediates, so we request it in a register.
1572 right = UseRegisterAtStart(instr->right());
1574 right = UseOrConstantAtStart(instr->right());
1576 LSubI* sub = new(zone()) LSubI(left, right);
1577 LInstruction* result = DefineSameAsFirst(sub);
1578 if (instr->CheckFlag(HValue::kCanOverflow)) {
1579 result = AssignEnvironment(result);
1582 } else if (instr->representation().IsDouble()) {
1583 return DoArithmeticD(Token::SUB, instr);
1585 return DoArithmeticT(Token::SUB, instr);
1590 LInstruction* LChunkBuilder::DoAdd(HAdd* instr) {
1591 if (instr->representation().IsSmiOrInteger32()) {
1592 // Check to see if it would be advantageous to use an lea instruction rather
1593 // than an add. This is the case when no overflow check is needed and there
1594 // are multiple uses of the add's inputs, so using a 3-register add will
1595 // preserve all input values for later uses.
1596 bool use_lea = LAddI::UseLea(instr);
1597 DCHECK(instr->left()->representation().Equals(instr->representation()));
1598 DCHECK(instr->right()->representation().Equals(instr->representation()));
1599 LOperand* left = UseRegisterAtStart(instr->BetterLeftOperand());
1600 HValue* right_candidate = instr->BetterRightOperand();
1602 if (SmiValuesAre32Bits() && instr->representation().IsSmi()) {
1603 // We cannot add a tagged immediate to a tagged value,
1604 // so we request it in a register.
1605 right = UseRegisterAtStart(right_candidate);
1607 right = use_lea ? UseRegisterOrConstantAtStart(right_candidate)
1608 : UseOrConstantAtStart(right_candidate);
1610 LAddI* add = new(zone()) LAddI(left, right);
1611 bool can_overflow = instr->CheckFlag(HValue::kCanOverflow);
1612 LInstruction* result = use_lea ? DefineAsRegister(add)
1613 : DefineSameAsFirst(add);
1615 result = AssignEnvironment(result);
1618 } else if (instr->representation().IsExternal()) {
1619 DCHECK(instr->IsConsistentExternalRepresentation());
1620 DCHECK(!instr->CheckFlag(HValue::kCanOverflow));
1621 bool use_lea = LAddI::UseLea(instr);
1622 LOperand* left = UseRegisterAtStart(instr->left());
1623 HValue* right_candidate = instr->right();
1624 LOperand* right = use_lea
1625 ? UseRegisterOrConstantAtStart(right_candidate)
1626 : UseOrConstantAtStart(right_candidate);
1627 LAddI* add = new(zone()) LAddI(left, right);
1628 LInstruction* result = use_lea
1629 ? DefineAsRegister(add)
1630 : DefineSameAsFirst(add);
1632 } else if (instr->representation().IsDouble()) {
1633 return DoArithmeticD(Token::ADD, instr);
1635 return DoArithmeticT(Token::ADD, instr);
1641 LInstruction* LChunkBuilder::DoMathMinMax(HMathMinMax* instr) {
1642 LOperand* left = NULL;
1643 LOperand* right = NULL;
1644 DCHECK(instr->left()->representation().Equals(instr->representation()));
1645 DCHECK(instr->right()->representation().Equals(instr->representation()));
1646 if (instr->representation().IsSmi()) {
1647 left = UseRegisterAtStart(instr->BetterLeftOperand());
1648 right = UseAtStart(instr->BetterRightOperand());
1649 } else if (instr->representation().IsInteger32()) {
1650 left = UseRegisterAtStart(instr->BetterLeftOperand());
1651 right = UseOrConstantAtStart(instr->BetterRightOperand());
1653 DCHECK(instr->representation().IsDouble());
1654 left = UseRegisterAtStart(instr->left());
1655 right = UseRegisterAtStart(instr->right());
1657 LMathMinMax* minmax = new(zone()) LMathMinMax(left, right);
1658 return DefineSameAsFirst(minmax);
1662 LInstruction* LChunkBuilder::DoPower(HPower* instr) {
1663 DCHECK(instr->representation().IsDouble());
1664 // We call a C function for double power. It can't trigger a GC.
1665 // We need to use fixed result register for the call.
1666 Representation exponent_type = instr->right()->representation();
1667 DCHECK(instr->left()->representation().IsDouble());
1668 LOperand* left = UseFixedDouble(instr->left(), xmm2);
1670 exponent_type.IsDouble()
1671 ? UseFixedDouble(instr->right(), xmm1)
1672 : UseFixed(instr->right(), MathPowTaggedDescriptor::exponent());
1673 LPower* result = new(zone()) LPower(left, right);
1674 return MarkAsCall(DefineFixedDouble(result, xmm3), instr,
1675 CAN_DEOPTIMIZE_EAGERLY);
1679 LInstruction* LChunkBuilder::DoCompareGeneric(HCompareGeneric* instr) {
1680 DCHECK(instr->left()->representation().IsTagged());
1681 DCHECK(instr->right()->representation().IsTagged());
1682 LOperand* context = UseFixed(instr->context(), rsi);
1683 LOperand* left = UseFixed(instr->left(), rdx);
1684 LOperand* right = UseFixed(instr->right(), rax);
1685 LCmpT* result = new(zone()) LCmpT(context, left, right);
1686 return MarkAsCall(DefineFixed(result, rax), instr);
1690 LInstruction* LChunkBuilder::DoCompareNumericAndBranch(
1691 HCompareNumericAndBranch* instr) {
1692 Representation r = instr->representation();
1693 if (r.IsSmiOrInteger32()) {
1694 DCHECK(instr->left()->representation().Equals(r));
1695 DCHECK(instr->right()->representation().Equals(r));
1696 LOperand* left = UseRegisterOrConstantAtStart(instr->left());
1697 LOperand* right = UseOrConstantAtStart(instr->right());
1698 return new(zone()) LCompareNumericAndBranch(left, right);
1700 DCHECK(r.IsDouble());
1701 DCHECK(instr->left()->representation().IsDouble());
1702 DCHECK(instr->right()->representation().IsDouble());
1705 if (instr->left()->IsConstant() && instr->right()->IsConstant()) {
1706 left = UseRegisterOrConstantAtStart(instr->left());
1707 right = UseRegisterOrConstantAtStart(instr->right());
1709 left = UseRegisterAtStart(instr->left());
1710 right = UseRegisterAtStart(instr->right());
1712 return new(zone()) LCompareNumericAndBranch(left, right);
1717 LInstruction* LChunkBuilder::DoCompareObjectEqAndBranch(
1718 HCompareObjectEqAndBranch* instr) {
1719 LOperand* left = UseRegisterAtStart(instr->left());
1720 LOperand* right = UseRegisterOrConstantAtStart(instr->right());
1721 return new(zone()) LCmpObjectEqAndBranch(left, right);
1725 LInstruction* LChunkBuilder::DoCompareHoleAndBranch(
1726 HCompareHoleAndBranch* instr) {
1727 LOperand* value = UseRegisterAtStart(instr->value());
1728 return new(zone()) LCmpHoleAndBranch(value);
1732 LInstruction* LChunkBuilder::DoCompareMinusZeroAndBranch(
1733 HCompareMinusZeroAndBranch* instr) {
1734 LOperand* value = UseRegister(instr->value());
1735 return new(zone()) LCompareMinusZeroAndBranch(value);
1739 LInstruction* LChunkBuilder::DoIsObjectAndBranch(HIsObjectAndBranch* instr) {
1740 DCHECK(instr->value()->representation().IsTagged());
1741 return new(zone()) LIsObjectAndBranch(UseRegisterAtStart(instr->value()));
1745 LInstruction* LChunkBuilder::DoIsStringAndBranch(HIsStringAndBranch* instr) {
1746 DCHECK(instr->value()->representation().IsTagged());
1747 LOperand* value = UseRegisterAtStart(instr->value());
1748 LOperand* temp = TempRegister();
1749 return new(zone()) LIsStringAndBranch(value, temp);
1753 LInstruction* LChunkBuilder::DoIsSmiAndBranch(HIsSmiAndBranch* instr) {
1754 DCHECK(instr->value()->representation().IsTagged());
1755 return new(zone()) LIsSmiAndBranch(Use(instr->value()));
1759 LInstruction* LChunkBuilder::DoIsUndetectableAndBranch(
1760 HIsUndetectableAndBranch* instr) {
1761 DCHECK(instr->value()->representation().IsTagged());
1762 LOperand* value = UseRegisterAtStart(instr->value());
1763 LOperand* temp = TempRegister();
1764 return new(zone()) LIsUndetectableAndBranch(value, temp);
1768 LInstruction* LChunkBuilder::DoStringCompareAndBranch(
1769 HStringCompareAndBranch* instr) {
1771 DCHECK(instr->left()->representation().IsTagged());
1772 DCHECK(instr->right()->representation().IsTagged());
1773 LOperand* context = UseFixed(instr->context(), rsi);
1774 LOperand* left = UseFixed(instr->left(), rdx);
1775 LOperand* right = UseFixed(instr->right(), rax);
1776 LStringCompareAndBranch* result =
1777 new(zone()) LStringCompareAndBranch(context, left, right);
1779 return MarkAsCall(result, instr);
1783 LInstruction* LChunkBuilder::DoHasInstanceTypeAndBranch(
1784 HHasInstanceTypeAndBranch* instr) {
1785 DCHECK(instr->value()->representation().IsTagged());
1786 LOperand* value = UseRegisterAtStart(instr->value());
1787 return new(zone()) LHasInstanceTypeAndBranch(value);
1791 LInstruction* LChunkBuilder::DoGetCachedArrayIndex(
1792 HGetCachedArrayIndex* instr) {
1793 DCHECK(instr->value()->representation().IsTagged());
1794 LOperand* value = UseRegisterAtStart(instr->value());
1796 return DefineAsRegister(new(zone()) LGetCachedArrayIndex(value));
1800 LInstruction* LChunkBuilder::DoHasCachedArrayIndexAndBranch(
1801 HHasCachedArrayIndexAndBranch* instr) {
1802 DCHECK(instr->value()->representation().IsTagged());
1803 LOperand* value = UseRegisterAtStart(instr->value());
1804 return new(zone()) LHasCachedArrayIndexAndBranch(value);
1808 LInstruction* LChunkBuilder::DoClassOfTestAndBranch(
1809 HClassOfTestAndBranch* instr) {
1810 LOperand* value = UseRegister(instr->value());
1811 return new(zone()) LClassOfTestAndBranch(value,
1817 LInstruction* LChunkBuilder::DoMapEnumLength(HMapEnumLength* instr) {
1818 LOperand* map = UseRegisterAtStart(instr->value());
1819 return DefineAsRegister(new(zone()) LMapEnumLength(map));
1823 LInstruction* LChunkBuilder::DoDateField(HDateField* instr) {
1824 LOperand* object = UseFixed(instr->value(), rax);
1825 LDateField* result = new(zone()) LDateField(object, instr->index());
1826 return MarkAsCall(DefineFixed(result, rax), instr, CANNOT_DEOPTIMIZE_EAGERLY);
1830 LInstruction* LChunkBuilder::DoSeqStringGetChar(HSeqStringGetChar* instr) {
1831 LOperand* string = UseRegisterAtStart(instr->string());
1832 LOperand* index = UseRegisterOrConstantAtStart(instr->index());
1833 return DefineAsRegister(new(zone()) LSeqStringGetChar(string, index));
1837 LInstruction* LChunkBuilder::DoSeqStringSetChar(HSeqStringSetChar* instr) {
1838 LOperand* string = UseRegisterAtStart(instr->string());
1839 LOperand* index = FLAG_debug_code
1840 ? UseRegisterAtStart(instr->index())
1841 : UseRegisterOrConstantAtStart(instr->index());
1842 LOperand* value = FLAG_debug_code
1843 ? UseRegisterAtStart(instr->value())
1844 : UseRegisterOrConstantAtStart(instr->value());
1845 LOperand* context = FLAG_debug_code ? UseFixed(instr->context(), rsi) : NULL;
1846 LInstruction* result = new(zone()) LSeqStringSetChar(context, string,
1848 if (FLAG_debug_code) {
1849 result = MarkAsCall(result, instr);
1855 LInstruction* LChunkBuilder::DoBoundsCheck(HBoundsCheck* instr) {
1856 if (!FLAG_debug_code && instr->skip_check()) return NULL;
1857 LOperand* index = UseRegisterOrConstantAtStart(instr->index());
1858 LOperand* length = !index->IsConstantOperand()
1859 ? UseOrConstantAtStart(instr->length())
1860 : UseAtStart(instr->length());
1861 LInstruction* result = new(zone()) LBoundsCheck(index, length);
1862 if (!FLAG_debug_code || !instr->skip_check()) {
1863 result = AssignEnvironment(result);
1869 LInstruction* LChunkBuilder::DoBoundsCheckBaseIndexInformation(
1870 HBoundsCheckBaseIndexInformation* instr) {
1876 LInstruction* LChunkBuilder::DoAbnormalExit(HAbnormalExit* instr) {
1877 // The control instruction marking the end of a block that completed
1878 // abruptly (e.g., threw an exception). There is nothing specific to do.
1883 LInstruction* LChunkBuilder::DoUseConst(HUseConst* instr) {
1888 LInstruction* LChunkBuilder::DoForceRepresentation(HForceRepresentation* bad) {
1889 // All HForceRepresentation instructions should be eliminated in the
1890 // representation change phase of Hydrogen.
1896 LInstruction* LChunkBuilder::DoChange(HChange* instr) {
1897 Representation from = instr->from();
1898 Representation to = instr->to();
1899 HValue* val = instr->value();
1901 if (to.IsTagged()) {
1902 LOperand* value = UseRegister(val);
1903 return DefineSameAsFirst(new(zone()) LDummyUse(value));
1905 from = Representation::Tagged();
1907 if (from.IsTagged()) {
1908 if (to.IsDouble()) {
1909 LOperand* value = UseRegister(val);
1910 LInstruction* result = DefineAsRegister(new(zone()) LNumberUntagD(value));
1911 if (!val->representation().IsSmi()) result = AssignEnvironment(result);
1913 } else if (to.IsSmi()) {
1914 LOperand* value = UseRegister(val);
1915 if (val->type().IsSmi()) {
1916 return DefineSameAsFirst(new(zone()) LDummyUse(value));
1918 return AssignEnvironment(DefineSameAsFirst(new(zone()) LCheckSmi(value)));
1920 DCHECK(to.IsInteger32());
1921 if (val->type().IsSmi() || val->representation().IsSmi()) {
1922 LOperand* value = UseRegister(val);
1923 return DefineSameAsFirst(new(zone()) LSmiUntag(value, false));
1925 LOperand* value = UseRegister(val);
1926 bool truncating = instr->CanTruncateToInt32();
1927 LOperand* xmm_temp = truncating ? NULL : FixedTemp(xmm1);
1928 LInstruction* result =
1929 DefineSameAsFirst(new(zone()) LTaggedToI(value, xmm_temp));
1930 if (!val->representation().IsSmi()) result = AssignEnvironment(result);
1934 } else if (from.IsDouble()) {
1935 if (to.IsTagged()) {
1936 info()->MarkAsDeferredCalling();
1937 LOperand* value = UseRegister(val);
1938 LOperand* temp = TempRegister();
1939 LUnallocated* result_temp = TempRegister();
1940 LNumberTagD* result = new(zone()) LNumberTagD(value, temp);
1941 return AssignPointerMap(Define(result, result_temp));
1942 } else if (to.IsSmi()) {
1943 LOperand* value = UseRegister(val);
1944 return AssignEnvironment(
1945 DefineAsRegister(new(zone()) LDoubleToSmi(value)));
1947 DCHECK(to.IsInteger32());
1948 LOperand* value = UseRegister(val);
1949 LInstruction* result = DefineAsRegister(new(zone()) LDoubleToI(value));
1950 if (!instr->CanTruncateToInt32()) result = AssignEnvironment(result);
1953 } else if (from.IsInteger32()) {
1954 info()->MarkAsDeferredCalling();
1955 if (to.IsTagged()) {
1956 if (!instr->CheckFlag(HValue::kCanOverflow)) {
1957 LOperand* value = UseRegister(val);
1958 return DefineAsRegister(new(zone()) LSmiTag(value));
1959 } else if (val->CheckFlag(HInstruction::kUint32)) {
1960 LOperand* value = UseRegister(val);
1961 LOperand* temp1 = TempRegister();
1962 LOperand* temp2 = FixedTemp(xmm1);
1963 LNumberTagU* result = new(zone()) LNumberTagU(value, temp1, temp2);
1964 return AssignPointerMap(DefineSameAsFirst(result));
1966 LOperand* value = UseRegister(val);
1967 LOperand* temp1 = SmiValuesAre32Bits() ? NULL : TempRegister();
1968 LOperand* temp2 = SmiValuesAre32Bits() ? NULL : FixedTemp(xmm1);
1969 LNumberTagI* result = new(zone()) LNumberTagI(value, temp1, temp2);
1970 return AssignPointerMap(DefineSameAsFirst(result));
1972 } else if (to.IsSmi()) {
1973 LOperand* value = UseRegister(val);
1974 LInstruction* result = DefineAsRegister(new(zone()) LSmiTag(value));
1975 if (instr->CheckFlag(HValue::kCanOverflow)) {
1976 result = AssignEnvironment(result);
1980 DCHECK(to.IsDouble());
1981 if (val->CheckFlag(HInstruction::kUint32)) {
1982 return DefineAsRegister(new(zone()) LUint32ToDouble(UseRegister(val)));
1984 LOperand* value = Use(val);
1985 return DefineAsRegister(new(zone()) LInteger32ToDouble(value));
1994 LInstruction* LChunkBuilder::DoCheckHeapObject(HCheckHeapObject* instr) {
1995 LOperand* value = UseRegisterAtStart(instr->value());
1996 LInstruction* result = new(zone()) LCheckNonSmi(value);
1997 if (!instr->value()->type().IsHeapObject()) {
1998 result = AssignEnvironment(result);
2004 LInstruction* LChunkBuilder::DoCheckSmi(HCheckSmi* instr) {
2005 LOperand* value = UseRegisterAtStart(instr->value());
2006 return AssignEnvironment(new(zone()) LCheckSmi(value));
2010 LInstruction* LChunkBuilder::DoCheckArrayBufferNotNeutered(
2011 HCheckArrayBufferNotNeutered* instr) {
2012 LOperand* view = UseRegisterAtStart(instr->value());
2013 LCheckArrayBufferNotNeutered* result =
2014 new (zone()) LCheckArrayBufferNotNeutered(view);
2015 return AssignEnvironment(result);
2019 LInstruction* LChunkBuilder::DoCheckInstanceType(HCheckInstanceType* instr) {
2020 LOperand* value = UseRegisterAtStart(instr->value());
2021 LCheckInstanceType* result = new(zone()) LCheckInstanceType(value);
2022 return AssignEnvironment(result);
2026 LInstruction* LChunkBuilder::DoCheckValue(HCheckValue* instr) {
2027 LOperand* value = UseRegisterAtStart(instr->value());
2028 return AssignEnvironment(new(zone()) LCheckValue(value));
2032 LInstruction* LChunkBuilder::DoCheckMaps(HCheckMaps* instr) {
2033 if (instr->IsStabilityCheck()) return new(zone()) LCheckMaps;
2034 LOperand* value = UseRegisterAtStart(instr->value());
2035 LInstruction* result = AssignEnvironment(new(zone()) LCheckMaps(value));
2036 if (instr->HasMigrationTarget()) {
2037 info()->MarkAsDeferredCalling();
2038 result = AssignPointerMap(result);
2044 LInstruction* LChunkBuilder::DoClampToUint8(HClampToUint8* instr) {
2045 HValue* value = instr->value();
2046 Representation input_rep = value->representation();
2047 LOperand* reg = UseRegister(value);
2048 if (input_rep.IsDouble()) {
2049 return DefineAsRegister(new(zone()) LClampDToUint8(reg));
2050 } else if (input_rep.IsInteger32()) {
2051 return DefineSameAsFirst(new(zone()) LClampIToUint8(reg));
2053 DCHECK(input_rep.IsSmiOrTagged());
2054 // Register allocator doesn't (yet) support allocation of double
2055 // temps. Reserve xmm1 explicitly.
2056 LClampTToUint8* result = new(zone()) LClampTToUint8(reg,
2058 return AssignEnvironment(DefineSameAsFirst(result));
2063 LInstruction* LChunkBuilder::DoDoubleBits(HDoubleBits* instr) {
2064 HValue* value = instr->value();
2065 DCHECK(value->representation().IsDouble());
2066 return DefineAsRegister(new(zone()) LDoubleBits(UseRegister(value)));
2070 LInstruction* LChunkBuilder::DoConstructDouble(HConstructDouble* instr) {
2071 LOperand* lo = UseRegister(instr->lo());
2072 LOperand* hi = UseRegister(instr->hi());
2073 return DefineAsRegister(new(zone()) LConstructDouble(hi, lo));
2077 LInstruction* LChunkBuilder::DoReturn(HReturn* instr) {
2078 LOperand* context = info()->IsStub() ? UseFixed(instr->context(), rsi) : NULL;
2079 LOperand* parameter_count = UseRegisterOrConstant(instr->parameter_count());
2080 return new(zone()) LReturn(
2081 UseFixed(instr->value(), rax), context, parameter_count);
2085 LInstruction* LChunkBuilder::DoConstant(HConstant* instr) {
2086 Representation r = instr->representation();
2088 return DefineAsRegister(new(zone()) LConstantS);
2089 } else if (r.IsInteger32()) {
2090 return DefineAsRegister(new(zone()) LConstantI);
2091 } else if (r.IsDouble()) {
2092 return DefineAsRegister(new (zone()) LConstantD);
2093 } else if (r.IsExternal()) {
2094 return DefineAsRegister(new(zone()) LConstantE);
2095 } else if (r.IsTagged()) {
2096 return DefineAsRegister(new(zone()) LConstantT);
2104 LInstruction* LChunkBuilder::DoLoadGlobalGeneric(HLoadGlobalGeneric* instr) {
2105 LOperand* context = UseFixed(instr->context(), rsi);
2106 LOperand* global_object =
2107 UseFixed(instr->global_object(), LoadDescriptor::ReceiverRegister());
2108 LOperand* vector = NULL;
2109 if (instr->HasVectorAndSlot()) {
2110 vector = FixedTemp(LoadWithVectorDescriptor::VectorRegister());
2113 LLoadGlobalGeneric* result =
2114 new(zone()) LLoadGlobalGeneric(context, global_object, vector);
2115 return MarkAsCall(DefineFixed(result, rax), instr);
2119 LInstruction* LChunkBuilder::DoLoadGlobalViaContext(
2120 HLoadGlobalViaContext* instr) {
2121 LOperand* context = UseFixed(instr->context(), rsi);
2122 DCHECK(instr->slot_index() > 0);
2123 LLoadGlobalViaContext* result = new (zone()) LLoadGlobalViaContext(context);
2124 return MarkAsCall(DefineFixed(result, rax), instr);
2128 LInstruction* LChunkBuilder::DoLoadContextSlot(HLoadContextSlot* instr) {
2129 LOperand* context = UseRegisterAtStart(instr->value());
2130 LInstruction* result =
2131 DefineAsRegister(new(zone()) LLoadContextSlot(context));
2132 if (instr->RequiresHoleCheck() && instr->DeoptimizesOnHole()) {
2133 result = AssignEnvironment(result);
2139 LInstruction* LChunkBuilder::DoStoreContextSlot(HStoreContextSlot* instr) {
2143 context = UseRegister(instr->context());
2144 if (instr->NeedsWriteBarrier()) {
2145 value = UseTempRegister(instr->value());
2146 temp = TempRegister();
2148 value = UseRegister(instr->value());
2151 LInstruction* result = new(zone()) LStoreContextSlot(context, value, temp);
2152 if (instr->RequiresHoleCheck() && instr->DeoptimizesOnHole()) {
2153 result = AssignEnvironment(result);
2159 LInstruction* LChunkBuilder::DoLoadNamedField(HLoadNamedField* instr) {
2160 // Use the special mov rax, moffs64 encoding for external
2161 // memory accesses with 64-bit word-sized values.
2162 if (instr->access().IsExternalMemory() &&
2163 instr->access().offset() == 0 &&
2164 (instr->access().representation().IsSmi() ||
2165 instr->access().representation().IsTagged() ||
2166 instr->access().representation().IsHeapObject() ||
2167 instr->access().representation().IsExternal())) {
2168 LOperand* obj = UseRegisterOrConstantAtStart(instr->object());
2169 return DefineFixed(new(zone()) LLoadNamedField(obj), rax);
2171 LOperand* obj = UseRegisterAtStart(instr->object());
2172 return DefineAsRegister(new(zone()) LLoadNamedField(obj));
2176 LInstruction* LChunkBuilder::DoLoadNamedGeneric(HLoadNamedGeneric* instr) {
2177 LOperand* context = UseFixed(instr->context(), rsi);
2179 UseFixed(instr->object(), LoadDescriptor::ReceiverRegister());
2180 LOperand* vector = NULL;
2181 if (instr->HasVectorAndSlot()) {
2182 vector = FixedTemp(LoadWithVectorDescriptor::VectorRegister());
2184 LLoadNamedGeneric* result = new(zone()) LLoadNamedGeneric(
2185 context, object, vector);
2186 return MarkAsCall(DefineFixed(result, rax), instr);
2190 LInstruction* LChunkBuilder::DoLoadFunctionPrototype(
2191 HLoadFunctionPrototype* instr) {
2192 return AssignEnvironment(DefineAsRegister(
2193 new(zone()) LLoadFunctionPrototype(UseRegister(instr->function()))));
2197 LInstruction* LChunkBuilder::DoLoadRoot(HLoadRoot* instr) {
2198 return DefineAsRegister(new(zone()) LLoadRoot);
2202 void LChunkBuilder::FindDehoistedKeyDefinitions(HValue* candidate) {
2203 // We sign extend the dehoisted key at the definition point when the pointer
2204 // size is 64-bit. For x32 port, we sign extend the dehoisted key at the use
2205 // points and should not invoke this function. We can't use STATIC_ASSERT
2206 // here as the pointer size is 32-bit for x32.
2207 DCHECK(kPointerSize == kInt64Size);
2208 BitVector* dehoisted_key_ids = chunk_->GetDehoistedKeyIds();
2209 if (dehoisted_key_ids->Contains(candidate->id())) return;
2210 dehoisted_key_ids->Add(candidate->id());
2211 if (!candidate->IsPhi()) return;
2212 for (int i = 0; i < candidate->OperandCount(); ++i) {
2213 FindDehoistedKeyDefinitions(candidate->OperandAt(i));
2218 LInstruction* LChunkBuilder::DoLoadKeyed(HLoadKeyed* instr) {
2219 DCHECK((kPointerSize == kInt64Size &&
2220 instr->key()->representation().IsInteger32()) ||
2221 (kPointerSize == kInt32Size &&
2222 instr->key()->representation().IsSmiOrInteger32()));
2223 ElementsKind elements_kind = instr->elements_kind();
2224 LOperand* key = NULL;
2225 LInstruction* result = NULL;
2227 if (kPointerSize == kInt64Size) {
2228 key = UseRegisterOrConstantAtStart(instr->key());
2230 bool clobbers_key = ExternalArrayOpRequiresTemp(
2231 instr->key()->representation(), elements_kind);
2233 ? UseTempRegister(instr->key())
2234 : UseRegisterOrConstantAtStart(instr->key());
2237 if ((kPointerSize == kInt64Size) && instr->IsDehoisted()) {
2238 FindDehoistedKeyDefinitions(instr->key());
2241 if (!instr->is_typed_elements()) {
2242 LOperand* obj = UseRegisterAtStart(instr->elements());
2243 result = DefineAsRegister(new(zone()) LLoadKeyed(obj, key));
2246 (instr->representation().IsInteger32() &&
2247 !(IsDoubleOrFloatElementsKind(elements_kind))) ||
2248 (instr->representation().IsDouble() &&
2249 (IsDoubleOrFloatElementsKind(elements_kind))));
2250 LOperand* backing_store = UseRegister(instr->elements());
2251 result = DefineAsRegister(new(zone()) LLoadKeyed(backing_store, key));
2254 bool needs_environment;
2255 if (instr->is_external() || instr->is_fixed_typed_array()) {
2256 // see LCodeGen::DoLoadKeyedExternalArray
2257 needs_environment = (elements_kind == EXTERNAL_UINT32_ELEMENTS ||
2258 elements_kind == UINT32_ELEMENTS) &&
2259 !instr->CheckFlag(HInstruction::kUint32);
2261 // see LCodeGen::DoLoadKeyedFixedDoubleArray and
2262 // LCodeGen::DoLoadKeyedFixedArray
2264 instr->RequiresHoleCheck() ||
2265 (instr->hole_mode() == CONVERT_HOLE_TO_UNDEFINED && info()->IsStub());
2268 if (needs_environment) {
2269 result = AssignEnvironment(result);
2275 LInstruction* LChunkBuilder::DoLoadKeyedGeneric(HLoadKeyedGeneric* instr) {
2276 LOperand* context = UseFixed(instr->context(), rsi);
2278 UseFixed(instr->object(), LoadDescriptor::ReceiverRegister());
2279 LOperand* key = UseFixed(instr->key(), LoadDescriptor::NameRegister());
2280 LOperand* vector = NULL;
2281 if (instr->HasVectorAndSlot()) {
2282 vector = FixedTemp(LoadWithVectorDescriptor::VectorRegister());
2285 LLoadKeyedGeneric* result =
2286 new(zone()) LLoadKeyedGeneric(context, object, key, vector);
2287 return MarkAsCall(DefineFixed(result, rax), instr);
2291 LInstruction* LChunkBuilder::DoStoreKeyed(HStoreKeyed* instr) {
2292 ElementsKind elements_kind = instr->elements_kind();
2294 if ((kPointerSize == kInt64Size) && instr->IsDehoisted()) {
2295 FindDehoistedKeyDefinitions(instr->key());
2298 if (!instr->is_typed_elements()) {
2299 DCHECK(instr->elements()->representation().IsTagged());
2300 bool needs_write_barrier = instr->NeedsWriteBarrier();
2301 LOperand* object = NULL;
2302 LOperand* key = NULL;
2303 LOperand* val = NULL;
2305 Representation value_representation = instr->value()->representation();
2306 if (value_representation.IsDouble()) {
2307 object = UseRegisterAtStart(instr->elements());
2308 val = UseRegisterAtStart(instr->value());
2309 key = UseRegisterOrConstantAtStart(instr->key());
2311 DCHECK(value_representation.IsSmiOrTagged() ||
2312 value_representation.IsInteger32());
2313 if (needs_write_barrier) {
2314 object = UseTempRegister(instr->elements());
2315 val = UseTempRegister(instr->value());
2316 key = UseTempRegister(instr->key());
2318 object = UseRegisterAtStart(instr->elements());
2319 val = UseRegisterOrConstantAtStart(instr->value());
2320 key = UseRegisterOrConstantAtStart(instr->key());
2324 return new(zone()) LStoreKeyed(object, key, val);
2328 (instr->value()->representation().IsInteger32() &&
2329 !IsDoubleOrFloatElementsKind(elements_kind)) ||
2330 (instr->value()->representation().IsDouble() &&
2331 IsDoubleOrFloatElementsKind(elements_kind)));
2332 DCHECK(instr->elements()->representation().IsExternal());
2333 bool val_is_temp_register =
2334 elements_kind == EXTERNAL_UINT8_CLAMPED_ELEMENTS ||
2335 elements_kind == EXTERNAL_FLOAT32_ELEMENTS ||
2336 elements_kind == FLOAT32_ELEMENTS;
2337 LOperand* val = val_is_temp_register ? UseTempRegister(instr->value())
2338 : UseRegister(instr->value());
2339 LOperand* key = NULL;
2340 if (kPointerSize == kInt64Size) {
2341 key = UseRegisterOrConstantAtStart(instr->key());
2343 bool clobbers_key = ExternalArrayOpRequiresTemp(
2344 instr->key()->representation(), elements_kind);
2346 ? UseTempRegister(instr->key())
2347 : UseRegisterOrConstantAtStart(instr->key());
2349 LOperand* backing_store = UseRegister(instr->elements());
2350 return new(zone()) LStoreKeyed(backing_store, key, val);
2354 LInstruction* LChunkBuilder::DoStoreKeyedGeneric(HStoreKeyedGeneric* instr) {
2355 LOperand* context = UseFixed(instr->context(), rsi);
2357 UseFixed(instr->object(), StoreDescriptor::ReceiverRegister());
2358 LOperand* key = UseFixed(instr->key(), StoreDescriptor::NameRegister());
2359 LOperand* value = UseFixed(instr->value(), StoreDescriptor::ValueRegister());
2361 DCHECK(instr->object()->representation().IsTagged());
2362 DCHECK(instr->key()->representation().IsTagged());
2363 DCHECK(instr->value()->representation().IsTagged());
2365 LOperand* slot = NULL;
2366 LOperand* vector = NULL;
2367 if (instr->HasVectorAndSlot()) {
2368 slot = FixedTemp(VectorStoreICDescriptor::SlotRegister());
2369 vector = FixedTemp(VectorStoreICDescriptor::VectorRegister());
2372 LStoreKeyedGeneric* result = new (zone())
2373 LStoreKeyedGeneric(context, object, key, value, slot, vector);
2374 return MarkAsCall(result, instr);
2378 LInstruction* LChunkBuilder::DoTransitionElementsKind(
2379 HTransitionElementsKind* instr) {
2380 if (IsSimpleMapChangeTransition(instr->from_kind(), instr->to_kind())) {
2381 LOperand* object = UseRegister(instr->object());
2382 LOperand* new_map_reg = TempRegister();
2383 LOperand* temp_reg = TempRegister();
2384 LTransitionElementsKind* result = new(zone()) LTransitionElementsKind(
2385 object, NULL, new_map_reg, temp_reg);
2388 LOperand* object = UseFixed(instr->object(), rax);
2389 LOperand* context = UseFixed(instr->context(), rsi);
2390 LTransitionElementsKind* result =
2391 new(zone()) LTransitionElementsKind(object, context, NULL, NULL);
2392 return MarkAsCall(result, instr);
2397 LInstruction* LChunkBuilder::DoTrapAllocationMemento(
2398 HTrapAllocationMemento* instr) {
2399 LOperand* object = UseRegister(instr->object());
2400 LOperand* temp = TempRegister();
2401 LTrapAllocationMemento* result =
2402 new(zone()) LTrapAllocationMemento(object, temp);
2403 return AssignEnvironment(result);
2407 LInstruction* LChunkBuilder::DoMaybeGrowElements(HMaybeGrowElements* instr) {
2408 info()->MarkAsDeferredCalling();
2409 LOperand* context = UseFixed(instr->context(), rsi);
2410 LOperand* object = Use(instr->object());
2411 LOperand* elements = Use(instr->elements());
2412 LOperand* key = UseRegisterOrConstant(instr->key());
2413 LOperand* current_capacity = UseRegisterOrConstant(instr->current_capacity());
2415 LMaybeGrowElements* result = new (zone())
2416 LMaybeGrowElements(context, object, elements, key, current_capacity);
2417 DefineFixed(result, rax);
2418 return AssignPointerMap(AssignEnvironment(result));
2422 LInstruction* LChunkBuilder::DoStoreNamedField(HStoreNamedField* instr) {
2423 bool is_in_object = instr->access().IsInobject();
2424 bool is_external_location = instr->access().IsExternalMemory() &&
2425 instr->access().offset() == 0;
2426 bool needs_write_barrier = instr->NeedsWriteBarrier();
2427 bool needs_write_barrier_for_map = instr->has_transition() &&
2428 instr->NeedsWriteBarrierForMap();
2431 if (needs_write_barrier) {
2433 ? UseRegister(instr->object())
2434 : UseTempRegister(instr->object());
2435 } else if (is_external_location) {
2436 DCHECK(!is_in_object);
2437 DCHECK(!needs_write_barrier);
2438 DCHECK(!needs_write_barrier_for_map);
2439 obj = UseRegisterOrConstant(instr->object());
2441 obj = needs_write_barrier_for_map
2442 ? UseRegister(instr->object())
2443 : UseRegisterAtStart(instr->object());
2446 bool can_be_constant = instr->value()->IsConstant() &&
2447 HConstant::cast(instr->value())->NotInNewSpace() &&
2448 !instr->field_representation().IsDouble();
2451 if (needs_write_barrier) {
2452 val = UseTempRegister(instr->value());
2453 } else if (is_external_location) {
2454 val = UseFixed(instr->value(), rax);
2455 } else if (can_be_constant) {
2456 val = UseRegisterOrConstant(instr->value());
2457 } else if (instr->field_representation().IsDouble()) {
2458 val = UseRegisterAtStart(instr->value());
2460 val = UseRegister(instr->value());
2463 // We only need a scratch register if we have a write barrier or we
2464 // have a store into the properties array (not in-object-property).
2465 LOperand* temp = (!is_in_object || needs_write_barrier ||
2466 needs_write_barrier_for_map) ? TempRegister() : NULL;
2468 return new(zone()) LStoreNamedField(obj, val, temp);
2472 LInstruction* LChunkBuilder::DoStoreNamedGeneric(HStoreNamedGeneric* instr) {
2473 LOperand* context = UseFixed(instr->context(), rsi);
2475 UseFixed(instr->object(), StoreDescriptor::ReceiverRegister());
2476 LOperand* value = UseFixed(instr->value(), StoreDescriptor::ValueRegister());
2477 LOperand* slot = NULL;
2478 LOperand* vector = NULL;
2479 if (instr->HasVectorAndSlot()) {
2480 slot = FixedTemp(VectorStoreICDescriptor::SlotRegister());
2481 vector = FixedTemp(VectorStoreICDescriptor::VectorRegister());
2484 LStoreNamedGeneric* result =
2485 new (zone()) LStoreNamedGeneric(context, object, value, slot, vector);
2486 return MarkAsCall(result, instr);
2490 LInstruction* LChunkBuilder::DoStoreGlobalViaContext(
2491 HStoreGlobalViaContext* instr) {
2492 LOperand* context = UseFixed(instr->context(), rsi);
2493 LOperand* value = UseFixed(instr->value(),
2494 StoreGlobalViaContextDescriptor::ValueRegister());
2495 DCHECK(instr->slot_index() > 0);
2497 LStoreGlobalViaContext* result =
2498 new (zone()) LStoreGlobalViaContext(context, value);
2499 return MarkAsCall(result, instr);
2503 LInstruction* LChunkBuilder::DoStringAdd(HStringAdd* instr) {
2504 LOperand* context = UseFixed(instr->context(), rsi);
2505 LOperand* left = UseFixed(instr->left(), rdx);
2506 LOperand* right = UseFixed(instr->right(), rax);
2508 DefineFixed(new(zone()) LStringAdd(context, left, right), rax), instr);
2512 LInstruction* LChunkBuilder::DoStringCharCodeAt(HStringCharCodeAt* instr) {
2513 LOperand* string = UseTempRegister(instr->string());
2514 LOperand* index = UseTempRegister(instr->index());
2515 LOperand* context = UseAny(instr->context());
2516 LStringCharCodeAt* result =
2517 new(zone()) LStringCharCodeAt(context, string, index);
2518 return AssignPointerMap(DefineAsRegister(result));
2522 LInstruction* LChunkBuilder::DoStringCharFromCode(HStringCharFromCode* instr) {
2523 LOperand* char_code = UseRegister(instr->value());
2524 LOperand* context = UseAny(instr->context());
2525 LStringCharFromCode* result =
2526 new(zone()) LStringCharFromCode(context, char_code);
2527 return AssignPointerMap(DefineAsRegister(result));
2531 LInstruction* LChunkBuilder::DoAllocate(HAllocate* instr) {
2532 info()->MarkAsDeferredCalling();
2533 LOperand* context = UseAny(instr->context());
2534 LOperand* size = instr->size()->IsConstant()
2535 ? UseConstant(instr->size())
2536 : UseTempRegister(instr->size());
2537 LOperand* temp = TempRegister();
2538 LAllocate* result = new(zone()) LAllocate(context, size, temp);
2539 return AssignPointerMap(DefineAsRegister(result));
2543 LInstruction* LChunkBuilder::DoRegExpLiteral(HRegExpLiteral* instr) {
2544 LOperand* context = UseFixed(instr->context(), rsi);
2545 LRegExpLiteral* result = new(zone()) LRegExpLiteral(context);
2546 return MarkAsCall(DefineFixed(result, rax), instr);
2550 LInstruction* LChunkBuilder::DoFunctionLiteral(HFunctionLiteral* instr) {
2551 LOperand* context = UseFixed(instr->context(), rsi);
2552 LFunctionLiteral* result = new(zone()) LFunctionLiteral(context);
2553 return MarkAsCall(DefineFixed(result, rax), instr);
2557 LInstruction* LChunkBuilder::DoOsrEntry(HOsrEntry* instr) {
2558 DCHECK(argument_count_ == 0);
2559 allocator_->MarkAsOsrEntry();
2560 current_block_->last_environment()->set_ast_id(instr->ast_id());
2561 return AssignEnvironment(new(zone()) LOsrEntry);
2565 LInstruction* LChunkBuilder::DoParameter(HParameter* instr) {
2566 LParameter* result = new(zone()) LParameter;
2567 if (instr->kind() == HParameter::STACK_PARAMETER) {
2568 int spill_index = chunk()->GetParameterStackSlot(instr->index());
2569 return DefineAsSpilled(result, spill_index);
2571 DCHECK(info()->IsStub());
2572 CallInterfaceDescriptor descriptor =
2573 info()->code_stub()->GetCallInterfaceDescriptor();
2574 int index = static_cast<int>(instr->index());
2575 Register reg = descriptor.GetRegisterParameter(index);
2576 return DefineFixed(result, reg);
2581 LInstruction* LChunkBuilder::DoUnknownOSRValue(HUnknownOSRValue* instr) {
2582 // Use an index that corresponds to the location in the unoptimized frame,
2583 // which the optimized frame will subsume.
2584 int env_index = instr->index();
2585 int spill_index = 0;
2586 if (instr->environment()->is_parameter_index(env_index)) {
2587 spill_index = chunk()->GetParameterStackSlot(env_index);
2589 spill_index = env_index - instr->environment()->first_local_index();
2590 if (spill_index > LUnallocated::kMaxFixedSlotIndex) {
2591 Retry(kTooManySpillSlotsNeededForOSR);
2595 return DefineAsSpilled(new(zone()) LUnknownOSRValue, spill_index);
2599 LInstruction* LChunkBuilder::DoCallStub(HCallStub* instr) {
2600 LOperand* context = UseFixed(instr->context(), rsi);
2601 LCallStub* result = new(zone()) LCallStub(context);
2602 return MarkAsCall(DefineFixed(result, rax), instr);
2606 LInstruction* LChunkBuilder::DoArgumentsObject(HArgumentsObject* instr) {
2607 // There are no real uses of the arguments object.
2608 // arguments.length and element access are supported directly on
2609 // stack arguments, and any real arguments object use causes a bailout.
2610 // So this value is never used.
2615 LInstruction* LChunkBuilder::DoCapturedObject(HCapturedObject* instr) {
2616 instr->ReplayEnvironment(current_block_->last_environment());
2618 // There are no real uses of a captured object.
2623 LInstruction* LChunkBuilder::DoAccessArgumentsAt(HAccessArgumentsAt* instr) {
2624 info()->MarkAsRequiresFrame();
2625 LOperand* args = UseRegister(instr->arguments());
2628 if (instr->length()->IsConstant() && instr->index()->IsConstant()) {
2629 length = UseRegisterOrConstant(instr->length());
2630 index = UseOrConstant(instr->index());
2632 length = UseTempRegister(instr->length());
2633 index = Use(instr->index());
2635 return DefineAsRegister(new(zone()) LAccessArgumentsAt(args, length, index));
2639 LInstruction* LChunkBuilder::DoToFastProperties(HToFastProperties* instr) {
2640 LOperand* object = UseFixed(instr->value(), rax);
2641 LToFastProperties* result = new(zone()) LToFastProperties(object);
2642 return MarkAsCall(DefineFixed(result, rax), instr);
2646 LInstruction* LChunkBuilder::DoTypeof(HTypeof* instr) {
2647 LOperand* context = UseFixed(instr->context(), rsi);
2648 LOperand* value = UseFixed(instr->value(), rbx);
2649 LTypeof* result = new(zone()) LTypeof(context, value);
2650 return MarkAsCall(DefineFixed(result, rax), instr);
2654 LInstruction* LChunkBuilder::DoTypeofIsAndBranch(HTypeofIsAndBranch* instr) {
2655 return new(zone()) LTypeofIsAndBranch(UseTempRegister(instr->value()));
2659 LInstruction* LChunkBuilder::DoIsConstructCallAndBranch(
2660 HIsConstructCallAndBranch* instr) {
2661 return new(zone()) LIsConstructCallAndBranch(TempRegister());
2665 LInstruction* LChunkBuilder::DoSimulate(HSimulate* instr) {
2666 instr->ReplayEnvironment(current_block_->last_environment());
2671 LInstruction* LChunkBuilder::DoStackCheck(HStackCheck* instr) {
2672 info()->MarkAsDeferredCalling();
2673 if (instr->is_function_entry()) {
2674 LOperand* context = UseFixed(instr->context(), rsi);
2675 return MarkAsCall(new(zone()) LStackCheck(context), instr);
2677 DCHECK(instr->is_backwards_branch());
2678 LOperand* context = UseAny(instr->context());
2679 return AssignEnvironment(
2680 AssignPointerMap(new(zone()) LStackCheck(context)));
2685 LInstruction* LChunkBuilder::DoEnterInlined(HEnterInlined* instr) {
2686 HEnvironment* outer = current_block_->last_environment();
2687 outer->set_ast_id(instr->ReturnId());
2688 HConstant* undefined = graph()->GetConstantUndefined();
2689 HEnvironment* inner = outer->CopyForInlining(instr->closure(),
2690 instr->arguments_count(),
2693 instr->inlining_kind());
2694 // Only replay binding of arguments object if it wasn't removed from graph.
2695 if (instr->arguments_var() != NULL && instr->arguments_object()->IsLinked()) {
2696 inner->Bind(instr->arguments_var(), instr->arguments_object());
2698 inner->BindContext(instr->closure_context());
2699 inner->set_entry(instr);
2700 current_block_->UpdateEnvironment(inner);
2701 chunk_->AddInlinedFunction(instr->shared());
2706 LInstruction* LChunkBuilder::DoLeaveInlined(HLeaveInlined* instr) {
2707 LInstruction* pop = NULL;
2709 HEnvironment* env = current_block_->last_environment();
2711 if (env->entry()->arguments_pushed()) {
2712 int argument_count = env->arguments_environment()->parameter_count();
2713 pop = new(zone()) LDrop(argument_count);
2714 DCHECK(instr->argument_delta() == -argument_count);
2717 HEnvironment* outer = current_block_->last_environment()->
2718 DiscardInlined(false);
2719 current_block_->UpdateEnvironment(outer);
2725 LInstruction* LChunkBuilder::DoForInPrepareMap(HForInPrepareMap* instr) {
2726 LOperand* context = UseFixed(instr->context(), rsi);
2727 LOperand* object = UseFixed(instr->enumerable(), rax);
2728 LForInPrepareMap* result = new(zone()) LForInPrepareMap(context, object);
2729 return MarkAsCall(DefineFixed(result, rax), instr, CAN_DEOPTIMIZE_EAGERLY);
2733 LInstruction* LChunkBuilder::DoForInCacheArray(HForInCacheArray* instr) {
2734 LOperand* map = UseRegister(instr->map());
2735 return AssignEnvironment(DefineAsRegister(
2736 new(zone()) LForInCacheArray(map)));
2740 LInstruction* LChunkBuilder::DoCheckMapValue(HCheckMapValue* instr) {
2741 LOperand* value = UseRegisterAtStart(instr->value());
2742 LOperand* map = UseRegisterAtStart(instr->map());
2743 return AssignEnvironment(new(zone()) LCheckMapValue(value, map));
2747 LInstruction* LChunkBuilder::DoLoadFieldByIndex(HLoadFieldByIndex* instr) {
2748 LOperand* object = UseRegister(instr->object());
2749 LOperand* index = UseTempRegister(instr->index());
2750 LLoadFieldByIndex* load = new(zone()) LLoadFieldByIndex(object, index);
2751 LInstruction* result = DefineSameAsFirst(load);
2752 return AssignPointerMap(result);
2756 LInstruction* LChunkBuilder::DoStoreFrameContext(HStoreFrameContext* instr) {
2757 LOperand* context = UseRegisterAtStart(instr->context());
2758 return new(zone()) LStoreFrameContext(context);
2762 LInstruction* LChunkBuilder::DoAllocateBlockContext(
2763 HAllocateBlockContext* instr) {
2764 LOperand* context = UseFixed(instr->context(), rsi);
2765 LOperand* function = UseRegisterAtStart(instr->function());
2766 LAllocateBlockContext* result =
2767 new(zone()) LAllocateBlockContext(context, function);
2768 return MarkAsCall(DefineFixed(result, rsi), instr);
2772 } // namespace internal
2775 #endif // V8_TARGET_ARCH_X64