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/x87/lithium-codegen-x87.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 bool LInstruction::HasDoubleRegisterResult() {
49 return HasResult() && result()->IsDoubleRegister();
53 bool LInstruction::HasDoubleRegisterInput() {
54 for (int i = 0; i < InputCount(); i++) {
55 LOperand* op = InputAt(i);
56 if (op != NULL && op->IsDoubleRegister()) {
64 bool LInstruction::IsDoubleInput(X87Register reg, LCodeGen* cgen) {
65 for (int i = 0; i < InputCount(); i++) {
66 LOperand* op = InputAt(i);
67 if (op != NULL && op->IsDoubleRegister()) {
68 if (cgen->ToX87Register(op).is(reg)) return true;
75 void LInstruction::PrintTo(StringStream* stream) {
76 stream->Add("%s ", this->Mnemonic());
78 PrintOutputOperandTo(stream);
82 if (HasEnvironment()) {
84 environment()->PrintTo(stream);
87 if (HasPointerMap()) {
89 pointer_map()->PrintTo(stream);
94 void LInstruction::PrintDataTo(StringStream* stream) {
96 for (int i = 0; i < InputCount(); i++) {
97 if (i > 0) stream->Add(" ");
98 if (InputAt(i) == NULL) {
101 InputAt(i)->PrintTo(stream);
107 void LInstruction::PrintOutputOperandTo(StringStream* stream) {
108 if (HasResult()) result()->PrintTo(stream);
112 void LLabel::PrintDataTo(StringStream* stream) {
113 LGap::PrintDataTo(stream);
114 LLabel* rep = replacement();
116 stream->Add(" Dead block replaced with B%d", rep->block_id());
121 bool LGap::IsRedundant() const {
122 for (int i = 0; i < 4; i++) {
123 if (parallel_moves_[i] != NULL && !parallel_moves_[i]->IsRedundant()) {
132 void LGap::PrintDataTo(StringStream* stream) {
133 for (int i = 0; i < 4; i++) {
135 if (parallel_moves_[i] != NULL) {
136 parallel_moves_[i]->PrintDataTo(stream);
143 const char* LArithmeticD::Mnemonic() const {
145 case Token::ADD: return "add-d";
146 case Token::SUB: return "sub-d";
147 case Token::MUL: return "mul-d";
148 case Token::DIV: return "div-d";
149 case Token::MOD: return "mod-d";
157 const char* LArithmeticT::Mnemonic() const {
159 case Token::ADD: return "add-t";
160 case Token::SUB: return "sub-t";
161 case Token::MUL: return "mul-t";
162 case Token::MOD: return "mod-t";
163 case Token::DIV: return "div-t";
164 case Token::BIT_AND: return "bit-and-t";
165 case Token::BIT_OR: return "bit-or-t";
166 case Token::BIT_XOR: return "bit-xor-t";
167 case Token::ROR: return "ror-t";
168 case Token::SHL: return "sal-t";
169 case Token::SAR: return "sar-t";
170 case Token::SHR: return "shr-t";
178 bool LGoto::HasInterestingComment(LCodeGen* gen) const {
179 return !gen->IsNextEmittedBlock(block_id());
183 void LGoto::PrintDataTo(StringStream* stream) {
184 stream->Add("B%d", block_id());
188 void LBranch::PrintDataTo(StringStream* stream) {
189 stream->Add("B%d | B%d on ", true_block_id(), false_block_id());
190 value()->PrintTo(stream);
194 void LCompareNumericAndBranch::PrintDataTo(StringStream* stream) {
196 left()->PrintTo(stream);
197 stream->Add(" %s ", Token::String(op()));
198 right()->PrintTo(stream);
199 stream->Add(" then B%d else B%d", true_block_id(), false_block_id());
203 void LIsObjectAndBranch::PrintDataTo(StringStream* stream) {
204 stream->Add("if is_object(");
205 value()->PrintTo(stream);
206 stream->Add(") then B%d else B%d", true_block_id(), false_block_id());
210 void LIsStringAndBranch::PrintDataTo(StringStream* stream) {
211 stream->Add("if is_string(");
212 value()->PrintTo(stream);
213 stream->Add(") then B%d else B%d", true_block_id(), false_block_id());
217 void LIsSmiAndBranch::PrintDataTo(StringStream* stream) {
218 stream->Add("if is_smi(");
219 value()->PrintTo(stream);
220 stream->Add(") then B%d else B%d", true_block_id(), false_block_id());
224 void LIsUndetectableAndBranch::PrintDataTo(StringStream* stream) {
225 stream->Add("if is_undetectable(");
226 value()->PrintTo(stream);
227 stream->Add(") then B%d else B%d", true_block_id(), false_block_id());
231 void LStringCompareAndBranch::PrintDataTo(StringStream* stream) {
232 stream->Add("if string_compare(");
233 left()->PrintTo(stream);
234 right()->PrintTo(stream);
235 stream->Add(") then B%d else B%d", true_block_id(), false_block_id());
239 void LHasInstanceTypeAndBranch::PrintDataTo(StringStream* stream) {
240 stream->Add("if has_instance_type(");
241 value()->PrintTo(stream);
242 stream->Add(") then B%d else B%d", true_block_id(), false_block_id());
246 void LHasCachedArrayIndexAndBranch::PrintDataTo(StringStream* stream) {
247 stream->Add("if has_cached_array_index(");
248 value()->PrintTo(stream);
249 stream->Add(") then B%d else B%d", true_block_id(), false_block_id());
253 void LClassOfTestAndBranch::PrintDataTo(StringStream* stream) {
254 stream->Add("if class_of_test(");
255 value()->PrintTo(stream);
256 stream->Add(", \"%o\") then B%d else B%d",
257 *hydrogen()->class_name(),
263 void LTypeofIsAndBranch::PrintDataTo(StringStream* stream) {
264 stream->Add("if typeof ");
265 value()->PrintTo(stream);
266 stream->Add(" == \"%s\" then B%d else B%d",
267 hydrogen()->type_literal()->ToCString().get(),
268 true_block_id(), false_block_id());
272 void LStoreCodeEntry::PrintDataTo(StringStream* stream) {
274 function()->PrintTo(stream);
275 stream->Add(".code_entry = ");
276 code_object()->PrintTo(stream);
280 void LInnerAllocatedObject::PrintDataTo(StringStream* stream) {
282 base_object()->PrintTo(stream);
284 offset()->PrintTo(stream);
288 void LCallJSFunction::PrintDataTo(StringStream* stream) {
290 function()->PrintTo(stream);
291 stream->Add("#%d / ", arity());
295 void LCallWithDescriptor::PrintDataTo(StringStream* stream) {
296 for (int i = 0; i < InputCount(); i++) {
297 InputAt(i)->PrintTo(stream);
300 stream->Add("#%d / ", arity());
304 void LLoadContextSlot::PrintDataTo(StringStream* stream) {
305 context()->PrintTo(stream);
306 stream->Add("[%d]", slot_index());
310 void LStoreContextSlot::PrintDataTo(StringStream* stream) {
311 context()->PrintTo(stream);
312 stream->Add("[%d] <- ", slot_index());
313 value()->PrintTo(stream);
317 void LInvokeFunction::PrintDataTo(StringStream* stream) {
319 context()->PrintTo(stream);
321 function()->PrintTo(stream);
322 stream->Add(" #%d / ", arity());
326 void LCallNew::PrintDataTo(StringStream* stream) {
328 context()->PrintTo(stream);
330 constructor()->PrintTo(stream);
331 stream->Add(" #%d / ", arity());
335 void LCallNewArray::PrintDataTo(StringStream* stream) {
337 context()->PrintTo(stream);
339 constructor()->PrintTo(stream);
340 stream->Add(" #%d / ", arity());
341 ElementsKind kind = hydrogen()->elements_kind();
342 stream->Add(" (%s) ", ElementsKindToString(kind));
346 void LAccessArgumentsAt::PrintDataTo(StringStream* stream) {
347 arguments()->PrintTo(stream);
349 stream->Add(" length ");
350 length()->PrintTo(stream);
352 stream->Add(" index ");
353 index()->PrintTo(stream);
357 int LPlatformChunk::GetNextSpillIndex(RegisterKind kind) {
358 // Skip a slot if for a double-width slot.
359 if (kind == DOUBLE_REGISTERS) {
361 spill_slot_count_ |= 1;
364 return spill_slot_count_++;
368 LOperand* LPlatformChunk::GetNextSpillSlot(RegisterKind kind) {
369 int index = GetNextSpillIndex(kind);
370 if (kind == DOUBLE_REGISTERS) {
371 return LDoubleStackSlot::Create(index, zone());
373 DCHECK(kind == GENERAL_REGISTERS);
374 return LStackSlot::Create(index, zone());
379 void LStoreNamedField::PrintDataTo(StringStream* stream) {
380 object()->PrintTo(stream);
381 std::ostringstream os;
382 os << hydrogen()->access() << " <- ";
383 stream->Add(os.str().c_str());
384 value()->PrintTo(stream);
388 void LStoreNamedGeneric::PrintDataTo(StringStream* stream) {
389 object()->PrintTo(stream);
391 stream->Add(String::cast(*name())->ToCString().get());
393 value()->PrintTo(stream);
397 void LLoadKeyed::PrintDataTo(StringStream* stream) {
398 elements()->PrintTo(stream);
400 key()->PrintTo(stream);
401 if (hydrogen()->IsDehoisted()) {
402 stream->Add(" + %d]", base_offset());
409 void LStoreKeyed::PrintDataTo(StringStream* stream) {
410 elements()->PrintTo(stream);
412 key()->PrintTo(stream);
413 if (hydrogen()->IsDehoisted()) {
414 stream->Add(" + %d] <-", base_offset());
416 stream->Add("] <- ");
419 if (value() == NULL) {
420 DCHECK(hydrogen()->IsConstantHoleStore() &&
421 hydrogen()->value()->representation().IsDouble());
422 stream->Add("<the hole(nan)>");
424 value()->PrintTo(stream);
429 void LStoreKeyedGeneric::PrintDataTo(StringStream* stream) {
430 object()->PrintTo(stream);
432 key()->PrintTo(stream);
433 stream->Add("] <- ");
434 value()->PrintTo(stream);
438 void LTransitionElementsKind::PrintDataTo(StringStream* stream) {
439 object()->PrintTo(stream);
440 stream->Add(" %p -> %p", *original_map(), *transitioned_map());
444 LPlatformChunk* LChunkBuilder::Build() {
446 chunk_ = new(zone()) LPlatformChunk(info(), graph());
447 LPhase phase("L_Building chunk", chunk_);
450 // Reserve the first spill slot for the state of dynamic alignment.
451 if (info()->IsOptimizing()) {
452 int alignment_state_index = chunk_->GetNextSpillIndex(GENERAL_REGISTERS);
453 DCHECK_EQ(alignment_state_index, 0);
454 USE(alignment_state_index);
457 // If compiling for OSR, reserve space for the unoptimized frame,
458 // which will be subsumed into this frame.
459 if (graph()->has_osr()) {
460 for (int i = graph()->osr()->UnoptimizedFrameSlots(); i > 0; i--) {
461 chunk_->GetNextSpillIndex(GENERAL_REGISTERS);
465 const ZoneList<HBasicBlock*>* blocks = graph()->blocks();
466 for (int i = 0; i < blocks->length(); i++) {
467 HBasicBlock* next = NULL;
468 if (i < blocks->length() - 1) next = blocks->at(i + 1);
469 DoBasicBlock(blocks->at(i), next);
470 if (is_aborted()) return NULL;
477 LUnallocated* LChunkBuilder::ToUnallocated(Register reg) {
478 return new(zone()) LUnallocated(LUnallocated::FIXED_REGISTER,
479 Register::ToAllocationIndex(reg));
483 LUnallocated* LChunkBuilder::ToUnallocated(X87Register reg) {
484 return new (zone()) LUnallocated(LUnallocated::FIXED_DOUBLE_REGISTER,
485 X87Register::ToAllocationIndex(reg));
489 LOperand* LChunkBuilder::UseFixed(HValue* value, Register fixed_register) {
490 return Use(value, ToUnallocated(fixed_register));
494 LOperand* LChunkBuilder::UseRegister(HValue* value) {
495 return Use(value, new(zone()) LUnallocated(LUnallocated::MUST_HAVE_REGISTER));
499 LOperand* LChunkBuilder::UseRegisterAtStart(HValue* value) {
501 new(zone()) LUnallocated(LUnallocated::MUST_HAVE_REGISTER,
502 LUnallocated::USED_AT_START));
506 LOperand* LChunkBuilder::UseTempRegister(HValue* value) {
507 return Use(value, new(zone()) LUnallocated(LUnallocated::WRITABLE_REGISTER));
511 LOperand* LChunkBuilder::Use(HValue* value) {
512 return Use(value, new(zone()) LUnallocated(LUnallocated::NONE));
516 LOperand* LChunkBuilder::UseAtStart(HValue* value) {
517 return Use(value, new(zone()) LUnallocated(LUnallocated::NONE,
518 LUnallocated::USED_AT_START));
522 static inline bool CanBeImmediateConstant(HValue* value) {
523 return value->IsConstant() && HConstant::cast(value)->NotInNewSpace();
527 LOperand* LChunkBuilder::UseOrConstant(HValue* value) {
528 return CanBeImmediateConstant(value)
529 ? chunk_->DefineConstantOperand(HConstant::cast(value))
534 LOperand* LChunkBuilder::UseOrConstantAtStart(HValue* value) {
535 return CanBeImmediateConstant(value)
536 ? chunk_->DefineConstantOperand(HConstant::cast(value))
541 LOperand* LChunkBuilder::UseFixedOrConstant(HValue* value,
542 Register fixed_register) {
543 return CanBeImmediateConstant(value)
544 ? chunk_->DefineConstantOperand(HConstant::cast(value))
545 : UseFixed(value, fixed_register);
549 LOperand* LChunkBuilder::UseRegisterOrConstant(HValue* value) {
550 return CanBeImmediateConstant(value)
551 ? chunk_->DefineConstantOperand(HConstant::cast(value))
552 : UseRegister(value);
556 LOperand* LChunkBuilder::UseRegisterOrConstantAtStart(HValue* value) {
557 return CanBeImmediateConstant(value)
558 ? chunk_->DefineConstantOperand(HConstant::cast(value))
559 : UseRegisterAtStart(value);
563 LOperand* LChunkBuilder::UseConstant(HValue* value) {
564 return chunk_->DefineConstantOperand(HConstant::cast(value));
568 LOperand* LChunkBuilder::UseAny(HValue* value) {
569 return value->IsConstant()
570 ? chunk_->DefineConstantOperand(HConstant::cast(value))
571 : Use(value, new(zone()) LUnallocated(LUnallocated::ANY));
575 LOperand* LChunkBuilder::Use(HValue* value, LUnallocated* operand) {
576 if (value->EmitAtUses()) {
577 HInstruction* instr = HInstruction::cast(value);
578 VisitInstruction(instr);
580 operand->set_virtual_register(value->id());
585 LInstruction* LChunkBuilder::Define(LTemplateResultInstruction<1>* instr,
586 LUnallocated* result) {
587 result->set_virtual_register(current_instruction_->id());
588 instr->set_result(result);
593 LInstruction* LChunkBuilder::DefineAsRegister(
594 LTemplateResultInstruction<1>* instr) {
596 new(zone()) LUnallocated(LUnallocated::MUST_HAVE_REGISTER));
600 LInstruction* LChunkBuilder::DefineAsSpilled(
601 LTemplateResultInstruction<1>* instr,
604 new(zone()) LUnallocated(LUnallocated::FIXED_SLOT, index));
608 LInstruction* LChunkBuilder::DefineSameAsFirst(
609 LTemplateResultInstruction<1>* instr) {
611 new(zone()) LUnallocated(LUnallocated::SAME_AS_FIRST_INPUT));
615 LInstruction* LChunkBuilder::DefineFixed(LTemplateResultInstruction<1>* instr,
617 return Define(instr, ToUnallocated(reg));
621 LInstruction* LChunkBuilder::DefineFixed(LTemplateResultInstruction<1>* instr,
623 return Define(instr, ToUnallocated(reg));
627 LInstruction* LChunkBuilder::AssignEnvironment(LInstruction* instr) {
628 HEnvironment* hydrogen_env = current_block_->last_environment();
629 int argument_index_accumulator = 0;
630 ZoneList<HValue*> objects_to_materialize(0, zone());
631 instr->set_environment(CreateEnvironment(hydrogen_env,
632 &argument_index_accumulator,
633 &objects_to_materialize));
638 LInstruction* LChunkBuilder::MarkAsCall(LInstruction* instr,
639 HInstruction* hinstr,
640 CanDeoptimize can_deoptimize) {
641 info()->MarkAsNonDeferredCalling();
647 instr = AssignPointerMap(instr);
649 // If instruction does not have side-effects lazy deoptimization
650 // after the call will try to deoptimize to the point before the call.
651 // Thus we still need to attach environment to this call even if
652 // call sequence can not deoptimize eagerly.
653 bool needs_environment =
654 (can_deoptimize == CAN_DEOPTIMIZE_EAGERLY) ||
655 !hinstr->HasObservableSideEffects();
656 if (needs_environment && !instr->HasEnvironment()) {
657 instr = AssignEnvironment(instr);
658 // We can't really figure out if the environment is needed or not.
659 instr->environment()->set_has_been_used();
666 LInstruction* LChunkBuilder::AssignPointerMap(LInstruction* instr) {
667 DCHECK(!instr->HasPointerMap());
668 instr->set_pointer_map(new(zone()) LPointerMap(zone()));
673 LUnallocated* LChunkBuilder::TempRegister() {
674 LUnallocated* operand =
675 new(zone()) LUnallocated(LUnallocated::MUST_HAVE_REGISTER);
676 int vreg = allocator_->GetVirtualRegister();
677 if (!allocator_->AllocationOk()) {
678 Abort(kOutOfVirtualRegistersWhileTryingToAllocateTempRegister);
681 operand->set_virtual_register(vreg);
686 LOperand* LChunkBuilder::FixedTemp(Register 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 // Left shifts can deoptimize if we shift by > 0 and the result cannot be
731 if (instr->representation().IsSmi() && constant_value > 0) {
732 does_deopt = !instr->CheckUsesForFlag(HValue::kTruncatingToSmi);
735 right = UseFixed(right_value, ecx);
738 // Shift operations can only deoptimize if we do a logical shift by 0 and
739 // the result cannot be truncated to int32.
740 if (op == Token::SHR && constant_value == 0) {
741 does_deopt = !instr->CheckFlag(HInstruction::kUint32);
744 LInstruction* result =
745 DefineSameAsFirst(new(zone()) LShiftI(op, left, right, does_deopt));
746 return does_deopt ? AssignEnvironment(result) : result;
748 return DoArithmeticT(op, instr);
753 LInstruction* LChunkBuilder::DoArithmeticD(Token::Value op,
754 HArithmeticBinaryOperation* instr) {
755 DCHECK(instr->representation().IsDouble());
756 DCHECK(instr->left()->representation().IsDouble());
757 DCHECK(instr->right()->representation().IsDouble());
758 if (op == Token::MOD) {
759 LOperand* left = UseRegisterAtStart(instr->BetterLeftOperand());
760 LOperand* right = UseRegisterAtStart(instr->BetterRightOperand());
761 LArithmeticD* result = new(zone()) LArithmeticD(op, left, right);
762 return MarkAsCall(DefineSameAsFirst(result), instr);
764 LOperand* left = UseRegisterAtStart(instr->BetterLeftOperand());
765 LOperand* right = UseRegisterAtStart(instr->BetterRightOperand());
766 LArithmeticD* result = new(zone()) LArithmeticD(op, left, right);
767 return DefineSameAsFirst(result);
772 LInstruction* LChunkBuilder::DoArithmeticT(Token::Value op,
773 HBinaryOperation* instr) {
774 HValue* left = instr->left();
775 HValue* right = instr->right();
776 DCHECK(left->representation().IsTagged());
777 DCHECK(right->representation().IsTagged());
778 LOperand* context = UseFixed(instr->context(), esi);
779 LOperand* left_operand = UseFixed(left, edx);
780 LOperand* right_operand = UseFixed(right, eax);
781 LArithmeticT* result =
782 new(zone()) LArithmeticT(op, context, left_operand, right_operand);
783 return MarkAsCall(DefineFixed(result, eax), instr);
787 void LChunkBuilder::DoBasicBlock(HBasicBlock* block, HBasicBlock* next_block) {
788 DCHECK(is_building());
789 current_block_ = block;
790 next_block_ = next_block;
791 if (block->IsStartBlock()) {
792 block->UpdateEnvironment(graph_->start_environment());
794 } else if (block->predecessors()->length() == 1) {
795 // We have a single predecessor => copy environment and outgoing
796 // argument count from the predecessor.
797 DCHECK(block->phis()->length() == 0);
798 HBasicBlock* pred = block->predecessors()->at(0);
799 HEnvironment* last_environment = pred->last_environment();
800 DCHECK(last_environment != NULL);
801 // Only copy the environment, if it is later used again.
802 if (pred->end()->SecondSuccessor() == NULL) {
803 DCHECK(pred->end()->FirstSuccessor() == block);
805 if (pred->end()->FirstSuccessor()->block_id() > block->block_id() ||
806 pred->end()->SecondSuccessor()->block_id() > block->block_id()) {
807 last_environment = last_environment->Copy();
810 block->UpdateEnvironment(last_environment);
811 DCHECK(pred->argument_count() >= 0);
812 argument_count_ = pred->argument_count();
814 // We are at a state join => process phis.
815 HBasicBlock* pred = block->predecessors()->at(0);
816 // No need to copy the environment, it cannot be used later.
817 HEnvironment* last_environment = pred->last_environment();
818 for (int i = 0; i < block->phis()->length(); ++i) {
819 HPhi* phi = block->phis()->at(i);
820 if (phi->HasMergedIndex()) {
821 last_environment->SetValueAt(phi->merged_index(), phi);
824 for (int i = 0; i < block->deleted_phis()->length(); ++i) {
825 if (block->deleted_phis()->at(i) < last_environment->length()) {
826 last_environment->SetValueAt(block->deleted_phis()->at(i),
827 graph_->GetConstantUndefined());
830 block->UpdateEnvironment(last_environment);
831 // Pick up the outgoing argument count of one of the predecessors.
832 argument_count_ = pred->argument_count();
834 HInstruction* current = block->first();
835 int start = chunk_->instructions()->length();
836 while (current != NULL && !is_aborted()) {
837 // Code for constants in registers is generated lazily.
838 if (!current->EmitAtUses()) {
839 VisitInstruction(current);
841 current = current->next();
843 int end = chunk_->instructions()->length() - 1;
845 block->set_first_instruction_index(start);
846 block->set_last_instruction_index(end);
848 block->set_argument_count(argument_count_);
850 current_block_ = NULL;
854 void LChunkBuilder::VisitInstruction(HInstruction* current) {
855 HInstruction* old_current = current_instruction_;
856 current_instruction_ = current;
858 LInstruction* instr = NULL;
859 if (current->CanReplaceWithDummyUses()) {
860 if (current->OperandCount() == 0) {
861 instr = DefineAsRegister(new(zone()) LDummy());
863 DCHECK(!current->OperandAt(0)->IsControlInstruction());
864 instr = DefineAsRegister(new(zone())
865 LDummyUse(UseAny(current->OperandAt(0))));
867 for (int i = 1; i < current->OperandCount(); ++i) {
868 if (current->OperandAt(i)->IsControlInstruction()) continue;
869 LInstruction* dummy =
870 new(zone()) LDummyUse(UseAny(current->OperandAt(i)));
871 dummy->set_hydrogen_value(current);
872 chunk_->AddInstruction(dummy, current_block_);
875 HBasicBlock* successor;
876 if (current->IsControlInstruction() &&
877 HControlInstruction::cast(current)->KnownSuccessorBlock(&successor) &&
879 // Always insert a fpu register barrier here when branch is optimized to
881 // TODO(weiliang): require a better solution.
882 if (!current->IsGoto()) {
883 LClobberDoubles* clobber = new (zone()) LClobberDoubles(isolate());
884 clobber->set_hydrogen_value(current);
885 chunk_->AddInstruction(clobber, current_block_);
887 instr = new(zone()) LGoto(successor);
889 instr = current->CompileToLithium(this);
893 argument_count_ += current->argument_delta();
894 DCHECK(argument_count_ >= 0);
897 AddInstruction(instr, current);
900 current_instruction_ = old_current;
904 void LChunkBuilder::AddInstruction(LInstruction* instr,
905 HInstruction* hydrogen_val) {
906 // Associate the hydrogen instruction first, since we may need it for
907 // the ClobbersRegisters() or ClobbersDoubleRegisters() calls below.
908 instr->set_hydrogen_value(hydrogen_val);
911 // Make sure that the lithium instruction has either no fixed register
912 // constraints in temps or the result OR no uses that are only used at
913 // start. If this invariant doesn't hold, the register allocator can decide
914 // to insert a split of a range immediately before the instruction due to an
915 // already allocated register needing to be used for the instruction's fixed
916 // register constraint. In this case, The register allocator won't see an
917 // interference between the split child and the use-at-start (it would if
918 // the it was just a plain use), so it is free to move the split child into
919 // the same register that is used for the use-at-start.
920 // See https://code.google.com/p/chromium/issues/detail?id=201590
921 if (!(instr->ClobbersRegisters() &&
922 instr->ClobbersDoubleRegisters(isolate()))) {
924 int used_at_start = 0;
925 for (UseIterator it(instr); !it.Done(); it.Advance()) {
926 LUnallocated* operand = LUnallocated::cast(it.Current());
927 if (operand->IsUsedAtStart()) ++used_at_start;
929 if (instr->Output() != NULL) {
930 if (LUnallocated::cast(instr->Output())->HasFixedPolicy()) ++fixed;
932 for (TempIterator it(instr); !it.Done(); it.Advance()) {
933 LUnallocated* operand = LUnallocated::cast(it.Current());
934 if (operand->HasFixedPolicy()) ++fixed;
936 DCHECK(fixed == 0 || used_at_start == 0);
940 if (FLAG_stress_pointer_maps && !instr->HasPointerMap()) {
941 instr = AssignPointerMap(instr);
943 if (FLAG_stress_environments && !instr->HasEnvironment()) {
944 instr = AssignEnvironment(instr);
946 if (instr->IsGoto() &&
947 (LGoto::cast(instr)->jumps_to_join() || next_block_->is_osr_entry())) {
948 // TODO(olivf) Since phis of spilled values are joined as registers
949 // (not in the stack slot), we need to allow the goto gaps to keep one
950 // x87 register alive. To ensure all other values are still spilled, we
951 // insert a fpu register barrier right before.
952 LClobberDoubles* clobber = new(zone()) LClobberDoubles(isolate());
953 clobber->set_hydrogen_value(hydrogen_val);
954 chunk_->AddInstruction(clobber, current_block_);
956 chunk_->AddInstruction(instr, current_block_);
958 if (instr->IsCall()) {
959 HValue* hydrogen_value_for_lazy_bailout = hydrogen_val;
960 LInstruction* instruction_needing_environment = NULL;
961 if (hydrogen_val->HasObservableSideEffects()) {
962 HSimulate* sim = HSimulate::cast(hydrogen_val->next());
963 instruction_needing_environment = instr;
964 sim->ReplayEnvironment(current_block_->last_environment());
965 hydrogen_value_for_lazy_bailout = sim;
967 LInstruction* bailout = AssignEnvironment(new(zone()) LLazyBailout());
968 bailout->set_hydrogen_value(hydrogen_value_for_lazy_bailout);
969 chunk_->AddInstruction(bailout, current_block_);
970 if (instruction_needing_environment != NULL) {
971 // Store the lazy deopt environment with the instruction if needed.
972 // Right now it is only used for LInstanceOfKnownGlobal.
973 instruction_needing_environment->
974 SetDeferredLazyDeoptimizationEnvironment(bailout->environment());
980 LInstruction* LChunkBuilder::DoGoto(HGoto* instr) {
981 return new(zone()) LGoto(instr->FirstSuccessor());
985 LInstruction* LChunkBuilder::DoBranch(HBranch* instr) {
986 HValue* value = instr->value();
987 Representation r = value->representation();
988 HType type = value->type();
989 ToBooleanStub::Types expected = instr->expected_input_types();
990 if (expected.IsEmpty()) expected = ToBooleanStub::Types::Generic();
992 bool easy_case = !r.IsTagged() || type.IsBoolean() || type.IsSmi() ||
993 type.IsJSArray() || type.IsHeapNumber() || type.IsString();
994 LOperand* temp = !easy_case && expected.NeedsMap() ? TempRegister() : NULL;
995 LInstruction* branch =
996 temp != NULL ? new (zone()) LBranch(UseRegister(value), temp)
997 : new (zone()) LBranch(UseRegisterAtStart(value), temp);
999 ((!expected.Contains(ToBooleanStub::SMI) && expected.NeedsMap()) ||
1000 !expected.IsGeneric())) {
1001 branch = AssignEnvironment(branch);
1007 LInstruction* LChunkBuilder::DoDebugBreak(HDebugBreak* instr) {
1008 return new(zone()) LDebugBreak();
1012 LInstruction* LChunkBuilder::DoCompareMap(HCompareMap* instr) {
1013 DCHECK(instr->value()->representation().IsTagged());
1014 LOperand* value = UseRegisterAtStart(instr->value());
1015 return new(zone()) LCmpMapAndBranch(value);
1019 LInstruction* LChunkBuilder::DoArgumentsLength(HArgumentsLength* length) {
1020 info()->MarkAsRequiresFrame();
1021 return DefineAsRegister(new(zone()) LArgumentsLength(Use(length->value())));
1025 LInstruction* LChunkBuilder::DoArgumentsElements(HArgumentsElements* elems) {
1026 info()->MarkAsRequiresFrame();
1027 return DefineAsRegister(new(zone()) LArgumentsElements);
1031 LInstruction* LChunkBuilder::DoInstanceOf(HInstanceOf* instr) {
1032 LOperand* left = UseFixed(instr->left(), InstanceofStub::left());
1033 LOperand* right = UseFixed(instr->right(), InstanceofStub::right());
1034 LOperand* context = UseFixed(instr->context(), esi);
1035 LInstanceOf* result = new(zone()) LInstanceOf(context, left, right);
1036 return MarkAsCall(DefineFixed(result, eax), instr);
1040 LInstruction* LChunkBuilder::DoInstanceOfKnownGlobal(
1041 HInstanceOfKnownGlobal* instr) {
1042 LInstanceOfKnownGlobal* result =
1043 new(zone()) LInstanceOfKnownGlobal(
1044 UseFixed(instr->context(), esi),
1045 UseFixed(instr->left(), InstanceofStub::left()),
1047 return MarkAsCall(DefineFixed(result, eax), instr);
1051 LInstruction* LChunkBuilder::DoWrapReceiver(HWrapReceiver* instr) {
1052 LOperand* receiver = UseRegister(instr->receiver());
1053 LOperand* function = UseRegister(instr->function());
1054 LOperand* temp = TempRegister();
1055 LWrapReceiver* result =
1056 new(zone()) LWrapReceiver(receiver, function, temp);
1057 return AssignEnvironment(DefineSameAsFirst(result));
1061 LInstruction* LChunkBuilder::DoApplyArguments(HApplyArguments* instr) {
1062 LOperand* function = UseFixed(instr->function(), edi);
1063 LOperand* receiver = UseFixed(instr->receiver(), eax);
1064 LOperand* length = UseFixed(instr->length(), ebx);
1065 LOperand* elements = UseFixed(instr->elements(), ecx);
1066 LApplyArguments* result = new(zone()) LApplyArguments(function,
1070 return MarkAsCall(DefineFixed(result, eax), instr, CAN_DEOPTIMIZE_EAGERLY);
1074 LInstruction* LChunkBuilder::DoPushArguments(HPushArguments* instr) {
1075 int argc = instr->OperandCount();
1076 for (int i = 0; i < argc; ++i) {
1077 LOperand* argument = UseAny(instr->argument(i));
1078 AddInstruction(new(zone()) LPushArgument(argument), instr);
1084 LInstruction* LChunkBuilder::DoStoreCodeEntry(
1085 HStoreCodeEntry* store_code_entry) {
1086 LOperand* function = UseRegister(store_code_entry->function());
1087 LOperand* code_object = UseTempRegister(store_code_entry->code_object());
1088 return new(zone()) LStoreCodeEntry(function, code_object);
1092 LInstruction* LChunkBuilder::DoInnerAllocatedObject(
1093 HInnerAllocatedObject* instr) {
1094 LOperand* base_object = UseRegisterAtStart(instr->base_object());
1095 LOperand* offset = UseRegisterOrConstantAtStart(instr->offset());
1096 return DefineAsRegister(
1097 new(zone()) LInnerAllocatedObject(base_object, offset));
1101 LInstruction* LChunkBuilder::DoThisFunction(HThisFunction* instr) {
1102 return instr->HasNoUses()
1104 : DefineAsRegister(new(zone()) LThisFunction);
1108 LInstruction* LChunkBuilder::DoContext(HContext* instr) {
1109 if (instr->HasNoUses()) return NULL;
1111 if (info()->IsStub()) {
1112 return DefineFixed(new(zone()) LContext, esi);
1115 return DefineAsRegister(new(zone()) LContext);
1119 LInstruction* LChunkBuilder::DoDeclareGlobals(HDeclareGlobals* instr) {
1120 LOperand* context = UseFixed(instr->context(), esi);
1121 return MarkAsCall(new(zone()) LDeclareGlobals(context), instr);
1125 LInstruction* LChunkBuilder::DoCallJSFunction(
1126 HCallJSFunction* instr) {
1127 LOperand* function = UseFixed(instr->function(), edi);
1129 LCallJSFunction* result = new(zone()) LCallJSFunction(function);
1131 return MarkAsCall(DefineFixed(result, eax), instr, CANNOT_DEOPTIMIZE_EAGERLY);
1135 LInstruction* LChunkBuilder::DoCallWithDescriptor(
1136 HCallWithDescriptor* instr) {
1137 CallInterfaceDescriptor descriptor = instr->descriptor();
1138 LOperand* target = UseRegisterOrConstantAtStart(instr->target());
1139 ZoneList<LOperand*> ops(instr->OperandCount(), zone());
1140 ops.Add(target, zone());
1141 for (int i = 1; i < instr->OperandCount(); i++) {
1143 UseFixed(instr->OperandAt(i), descriptor.GetParameterRegister(i - 1));
1144 ops.Add(op, zone());
1147 LCallWithDescriptor* result = new(zone()) LCallWithDescriptor(
1148 descriptor, ops, zone());
1149 return MarkAsCall(DefineFixed(result, eax), instr, CANNOT_DEOPTIMIZE_EAGERLY);
1153 LInstruction* LChunkBuilder::DoTailCallThroughMegamorphicCache(
1154 HTailCallThroughMegamorphicCache* instr) {
1155 LOperand* context = UseFixed(instr->context(), esi);
1156 LOperand* receiver_register =
1157 UseFixed(instr->receiver(), LoadDescriptor::ReceiverRegister());
1158 LOperand* name_register =
1159 UseFixed(instr->name(), LoadDescriptor::NameRegister());
1160 // Not marked as call. It can't deoptimize, and it never returns.
1161 return new (zone()) LTailCallThroughMegamorphicCache(
1162 context, receiver_register, name_register);
1166 LInstruction* LChunkBuilder::DoInvokeFunction(HInvokeFunction* instr) {
1167 LOperand* context = UseFixed(instr->context(), esi);
1168 LOperand* function = UseFixed(instr->function(), edi);
1169 LInvokeFunction* result = new(zone()) LInvokeFunction(context, function);
1170 return MarkAsCall(DefineFixed(result, eax), instr, CANNOT_DEOPTIMIZE_EAGERLY);
1174 LInstruction* LChunkBuilder::DoUnaryMathOperation(HUnaryMathOperation* instr) {
1175 switch (instr->op()) {
1176 case kMathFloor: return DoMathFloor(instr);
1177 case kMathRound: return DoMathRound(instr);
1178 case kMathFround: return DoMathFround(instr);
1179 case kMathAbs: return DoMathAbs(instr);
1180 case kMathLog: return DoMathLog(instr);
1181 case kMathExp: return DoMathExp(instr);
1182 case kMathSqrt: return DoMathSqrt(instr);
1183 case kMathPowHalf: return DoMathPowHalf(instr);
1184 case kMathClz32: return DoMathClz32(instr);
1192 LInstruction* LChunkBuilder::DoMathFloor(HUnaryMathOperation* instr) {
1193 LOperand* input = UseRegisterAtStart(instr->value());
1194 LMathFloor* result = new(zone()) LMathFloor(input);
1195 return AssignEnvironment(DefineAsRegister(result));
1199 LInstruction* LChunkBuilder::DoMathRound(HUnaryMathOperation* instr) {
1200 LOperand* input = UseRegisterAtStart(instr->value());
1201 LInstruction* result = DefineAsRegister(new (zone()) LMathRound(input));
1202 return AssignEnvironment(result);
1206 LInstruction* LChunkBuilder::DoMathFround(HUnaryMathOperation* instr) {
1207 LOperand* input = UseRegister(instr->value());
1208 LMathFround* result = new (zone()) LMathFround(input);
1209 return DefineSameAsFirst(result);
1213 LInstruction* LChunkBuilder::DoMathAbs(HUnaryMathOperation* instr) {
1214 LOperand* context = UseAny(instr->context()); // Deferred use.
1215 LOperand* input = UseRegisterAtStart(instr->value());
1216 LInstruction* result =
1217 DefineSameAsFirst(new(zone()) LMathAbs(context, input));
1218 Representation r = instr->value()->representation();
1219 if (!r.IsDouble() && !r.IsSmiOrInteger32()) result = AssignPointerMap(result);
1220 if (!r.IsDouble()) result = AssignEnvironment(result);
1225 LInstruction* LChunkBuilder::DoMathLog(HUnaryMathOperation* instr) {
1226 DCHECK(instr->representation().IsDouble());
1227 DCHECK(instr->value()->representation().IsDouble());
1228 LOperand* input = UseRegisterAtStart(instr->value());
1229 return MarkAsCall(DefineSameAsFirst(new(zone()) LMathLog(input)), instr);
1233 LInstruction* LChunkBuilder::DoMathClz32(HUnaryMathOperation* instr) {
1234 LOperand* input = UseRegisterAtStart(instr->value());
1235 LMathClz32* result = new(zone()) LMathClz32(input);
1236 return DefineAsRegister(result);
1240 LInstruction* LChunkBuilder::DoMathExp(HUnaryMathOperation* instr) {
1241 DCHECK(instr->representation().IsDouble());
1242 DCHECK(instr->value()->representation().IsDouble());
1243 LOperand* value = UseRegisterAtStart(instr->value());
1244 LOperand* temp1 = FixedTemp(ecx);
1245 LOperand* temp2 = FixedTemp(edx);
1246 LMathExp* result = new(zone()) LMathExp(value, temp1, temp2);
1247 return MarkAsCall(DefineSameAsFirst(result), instr);
1251 LInstruction* LChunkBuilder::DoMathSqrt(HUnaryMathOperation* instr) {
1252 LOperand* input = UseRegisterAtStart(instr->value());
1253 LOperand* temp1 = FixedTemp(ecx);
1254 LOperand* temp2 = FixedTemp(edx);
1255 LMathSqrt* result = new(zone()) LMathSqrt(input, temp1, temp2);
1256 return MarkAsCall(DefineSameAsFirst(result), instr);
1260 LInstruction* LChunkBuilder::DoMathPowHalf(HUnaryMathOperation* instr) {
1261 LOperand* input = UseRegisterAtStart(instr->value());
1262 LMathPowHalf* result = new (zone()) LMathPowHalf(input);
1263 return DefineSameAsFirst(result);
1267 LInstruction* LChunkBuilder::DoCallNew(HCallNew* instr) {
1268 LOperand* context = UseFixed(instr->context(), esi);
1269 LOperand* constructor = UseFixed(instr->constructor(), edi);
1270 LCallNew* result = new(zone()) LCallNew(context, constructor);
1271 return MarkAsCall(DefineFixed(result, eax), instr);
1275 LInstruction* LChunkBuilder::DoCallNewArray(HCallNewArray* instr) {
1276 LOperand* context = UseFixed(instr->context(), esi);
1277 LOperand* constructor = UseFixed(instr->constructor(), edi);
1278 LCallNewArray* result = new(zone()) LCallNewArray(context, constructor);
1279 return MarkAsCall(DefineFixed(result, eax), instr);
1283 LInstruction* LChunkBuilder::DoCallFunction(HCallFunction* instr) {
1284 LOperand* context = UseFixed(instr->context(), esi);
1285 LOperand* function = UseFixed(instr->function(), edi);
1286 LCallFunction* call = new(zone()) LCallFunction(context, function);
1287 return MarkAsCall(DefineFixed(call, eax), instr);
1291 LInstruction* LChunkBuilder::DoCallRuntime(HCallRuntime* instr) {
1292 LOperand* context = UseFixed(instr->context(), esi);
1293 return MarkAsCall(DefineFixed(new(zone()) LCallRuntime(context), eax), instr);
1297 LInstruction* LChunkBuilder::DoRor(HRor* instr) {
1298 return DoShift(Token::ROR, instr);
1302 LInstruction* LChunkBuilder::DoShr(HShr* instr) {
1303 return DoShift(Token::SHR, instr);
1307 LInstruction* LChunkBuilder::DoSar(HSar* instr) {
1308 return DoShift(Token::SAR, instr);
1312 LInstruction* LChunkBuilder::DoShl(HShl* instr) {
1313 return DoShift(Token::SHL, instr);
1317 LInstruction* LChunkBuilder::DoBitwise(HBitwise* instr) {
1318 if (instr->representation().IsSmiOrInteger32()) {
1319 DCHECK(instr->left()->representation().Equals(instr->representation()));
1320 DCHECK(instr->right()->representation().Equals(instr->representation()));
1321 DCHECK(instr->CheckFlag(HValue::kTruncatingToInt32));
1323 LOperand* left = UseRegisterAtStart(instr->BetterLeftOperand());
1324 LOperand* right = UseOrConstantAtStart(instr->BetterRightOperand());
1325 return DefineSameAsFirst(new(zone()) LBitI(left, right));
1327 return DoArithmeticT(instr->op(), instr);
1332 LInstruction* LChunkBuilder::DoDivByPowerOf2I(HDiv* instr) {
1333 DCHECK(instr->representation().IsSmiOrInteger32());
1334 DCHECK(instr->left()->representation().Equals(instr->representation()));
1335 DCHECK(instr->right()->representation().Equals(instr->representation()));
1336 LOperand* dividend = UseRegister(instr->left());
1337 int32_t divisor = instr->right()->GetInteger32Constant();
1338 LInstruction* result = DefineAsRegister(new(zone()) LDivByPowerOf2I(
1339 dividend, divisor));
1340 if ((instr->CheckFlag(HValue::kBailoutOnMinusZero) && divisor < 0) ||
1341 (instr->CheckFlag(HValue::kCanOverflow) && divisor == -1) ||
1342 (!instr->CheckFlag(HInstruction::kAllUsesTruncatingToInt32) &&
1343 divisor != 1 && divisor != -1)) {
1344 result = AssignEnvironment(result);
1350 LInstruction* LChunkBuilder::DoDivByConstI(HDiv* instr) {
1351 DCHECK(instr->representation().IsInteger32());
1352 DCHECK(instr->left()->representation().Equals(instr->representation()));
1353 DCHECK(instr->right()->representation().Equals(instr->representation()));
1354 LOperand* dividend = UseRegister(instr->left());
1355 int32_t divisor = instr->right()->GetInteger32Constant();
1356 LOperand* temp1 = FixedTemp(eax);
1357 LOperand* temp2 = FixedTemp(edx);
1358 LInstruction* result = DefineFixed(new(zone()) LDivByConstI(
1359 dividend, divisor, temp1, temp2), edx);
1361 (instr->CheckFlag(HValue::kBailoutOnMinusZero) && divisor < 0) ||
1362 !instr->CheckFlag(HInstruction::kAllUsesTruncatingToInt32)) {
1363 result = AssignEnvironment(result);
1369 LInstruction* LChunkBuilder::DoDivI(HDiv* instr) {
1370 DCHECK(instr->representation().IsSmiOrInteger32());
1371 DCHECK(instr->left()->representation().Equals(instr->representation()));
1372 DCHECK(instr->right()->representation().Equals(instr->representation()));
1373 LOperand* dividend = UseFixed(instr->left(), eax);
1374 LOperand* divisor = UseRegister(instr->right());
1375 LOperand* temp = FixedTemp(edx);
1376 LInstruction* result = DefineFixed(new(zone()) LDivI(
1377 dividend, divisor, temp), eax);
1378 if (instr->CheckFlag(HValue::kCanBeDivByZero) ||
1379 instr->CheckFlag(HValue::kBailoutOnMinusZero) ||
1380 instr->CheckFlag(HValue::kCanOverflow) ||
1381 !instr->CheckFlag(HValue::kAllUsesTruncatingToInt32)) {
1382 result = AssignEnvironment(result);
1388 LInstruction* LChunkBuilder::DoDiv(HDiv* instr) {
1389 if (instr->representation().IsSmiOrInteger32()) {
1390 if (instr->RightIsPowerOf2()) {
1391 return DoDivByPowerOf2I(instr);
1392 } else if (instr->right()->IsConstant()) {
1393 return DoDivByConstI(instr);
1395 return DoDivI(instr);
1397 } else if (instr->representation().IsDouble()) {
1398 return DoArithmeticD(Token::DIV, instr);
1400 return DoArithmeticT(Token::DIV, instr);
1405 LInstruction* LChunkBuilder::DoFlooringDivByPowerOf2I(HMathFloorOfDiv* instr) {
1406 LOperand* dividend = UseRegisterAtStart(instr->left());
1407 int32_t divisor = instr->right()->GetInteger32Constant();
1408 LInstruction* result = DefineSameAsFirst(new(zone()) LFlooringDivByPowerOf2I(
1409 dividend, divisor));
1410 if ((instr->CheckFlag(HValue::kBailoutOnMinusZero) && divisor < 0) ||
1411 (instr->CheckFlag(HValue::kLeftCanBeMinInt) && divisor == -1)) {
1412 result = AssignEnvironment(result);
1418 LInstruction* LChunkBuilder::DoFlooringDivByConstI(HMathFloorOfDiv* instr) {
1419 DCHECK(instr->representation().IsInteger32());
1420 DCHECK(instr->left()->representation().Equals(instr->representation()));
1421 DCHECK(instr->right()->representation().Equals(instr->representation()));
1422 LOperand* dividend = UseRegister(instr->left());
1423 int32_t divisor = instr->right()->GetInteger32Constant();
1424 LOperand* temp1 = FixedTemp(eax);
1425 LOperand* temp2 = FixedTemp(edx);
1427 ((divisor > 0 && !instr->CheckFlag(HValue::kLeftCanBeNegative)) ||
1428 (divisor < 0 && !instr->CheckFlag(HValue::kLeftCanBePositive))) ?
1429 NULL : TempRegister();
1430 LInstruction* result =
1431 DefineFixed(new(zone()) LFlooringDivByConstI(dividend,
1438 (instr->CheckFlag(HValue::kBailoutOnMinusZero) && divisor < 0)) {
1439 result = AssignEnvironment(result);
1445 LInstruction* LChunkBuilder::DoFlooringDivI(HMathFloorOfDiv* instr) {
1446 DCHECK(instr->representation().IsSmiOrInteger32());
1447 DCHECK(instr->left()->representation().Equals(instr->representation()));
1448 DCHECK(instr->right()->representation().Equals(instr->representation()));
1449 LOperand* dividend = UseFixed(instr->left(), eax);
1450 LOperand* divisor = UseRegister(instr->right());
1451 LOperand* temp = FixedTemp(edx);
1452 LInstruction* result = DefineFixed(new(zone()) LFlooringDivI(
1453 dividend, divisor, temp), eax);
1454 if (instr->CheckFlag(HValue::kCanBeDivByZero) ||
1455 instr->CheckFlag(HValue::kBailoutOnMinusZero) ||
1456 instr->CheckFlag(HValue::kCanOverflow)) {
1457 result = AssignEnvironment(result);
1463 LInstruction* LChunkBuilder::DoMathFloorOfDiv(HMathFloorOfDiv* instr) {
1464 if (instr->RightIsPowerOf2()) {
1465 return DoFlooringDivByPowerOf2I(instr);
1466 } else if (instr->right()->IsConstant()) {
1467 return DoFlooringDivByConstI(instr);
1469 return DoFlooringDivI(instr);
1474 LInstruction* LChunkBuilder::DoModByPowerOf2I(HMod* instr) {
1475 DCHECK(instr->representation().IsSmiOrInteger32());
1476 DCHECK(instr->left()->representation().Equals(instr->representation()));
1477 DCHECK(instr->right()->representation().Equals(instr->representation()));
1478 LOperand* dividend = UseRegisterAtStart(instr->left());
1479 int32_t divisor = instr->right()->GetInteger32Constant();
1480 LInstruction* result = DefineSameAsFirst(new(zone()) LModByPowerOf2I(
1481 dividend, divisor));
1482 if (instr->CheckFlag(HValue::kLeftCanBeNegative) &&
1483 instr->CheckFlag(HValue::kBailoutOnMinusZero)) {
1484 result = AssignEnvironment(result);
1490 LInstruction* LChunkBuilder::DoModByConstI(HMod* instr) {
1491 DCHECK(instr->representation().IsSmiOrInteger32());
1492 DCHECK(instr->left()->representation().Equals(instr->representation()));
1493 DCHECK(instr->right()->representation().Equals(instr->representation()));
1494 LOperand* dividend = UseRegister(instr->left());
1495 int32_t divisor = instr->right()->GetInteger32Constant();
1496 LOperand* temp1 = FixedTemp(eax);
1497 LOperand* temp2 = FixedTemp(edx);
1498 LInstruction* result = DefineFixed(new(zone()) LModByConstI(
1499 dividend, divisor, temp1, temp2), eax);
1500 if (divisor == 0 || instr->CheckFlag(HValue::kBailoutOnMinusZero)) {
1501 result = AssignEnvironment(result);
1507 LInstruction* LChunkBuilder::DoModI(HMod* instr) {
1508 DCHECK(instr->representation().IsSmiOrInteger32());
1509 DCHECK(instr->left()->representation().Equals(instr->representation()));
1510 DCHECK(instr->right()->representation().Equals(instr->representation()));
1511 LOperand* dividend = UseFixed(instr->left(), eax);
1512 LOperand* divisor = UseRegister(instr->right());
1513 LOperand* temp = FixedTemp(edx);
1514 LInstruction* result = DefineFixed(new(zone()) LModI(
1515 dividend, divisor, temp), edx);
1516 if (instr->CheckFlag(HValue::kCanBeDivByZero) ||
1517 instr->CheckFlag(HValue::kBailoutOnMinusZero)) {
1518 result = AssignEnvironment(result);
1524 LInstruction* LChunkBuilder::DoMod(HMod* instr) {
1525 if (instr->representation().IsSmiOrInteger32()) {
1526 if (instr->RightIsPowerOf2()) {
1527 return DoModByPowerOf2I(instr);
1528 } else if (instr->right()->IsConstant()) {
1529 return DoModByConstI(instr);
1531 return DoModI(instr);
1533 } else if (instr->representation().IsDouble()) {
1534 return DoArithmeticD(Token::MOD, instr);
1536 return DoArithmeticT(Token::MOD, instr);
1541 LInstruction* LChunkBuilder::DoMul(HMul* instr) {
1542 if (instr->representation().IsSmiOrInteger32()) {
1543 DCHECK(instr->left()->representation().Equals(instr->representation()));
1544 DCHECK(instr->right()->representation().Equals(instr->representation()));
1545 LOperand* left = UseRegisterAtStart(instr->BetterLeftOperand());
1546 LOperand* right = UseOrConstant(instr->BetterRightOperand());
1547 LOperand* temp = NULL;
1548 if (instr->CheckFlag(HValue::kBailoutOnMinusZero)) {
1549 temp = TempRegister();
1551 LMulI* mul = new(zone()) LMulI(left, right, temp);
1552 if (instr->CheckFlag(HValue::kCanOverflow) ||
1553 instr->CheckFlag(HValue::kBailoutOnMinusZero)) {
1554 AssignEnvironment(mul);
1556 return DefineSameAsFirst(mul);
1557 } else if (instr->representation().IsDouble()) {
1558 return DoArithmeticD(Token::MUL, instr);
1560 return DoArithmeticT(Token::MUL, instr);
1565 LInstruction* LChunkBuilder::DoSub(HSub* instr) {
1566 if (instr->representation().IsSmiOrInteger32()) {
1567 DCHECK(instr->left()->representation().Equals(instr->representation()));
1568 DCHECK(instr->right()->representation().Equals(instr->representation()));
1569 LOperand* left = UseRegisterAtStart(instr->left());
1570 LOperand* right = UseOrConstantAtStart(instr->right());
1571 LSubI* sub = new(zone()) LSubI(left, right);
1572 LInstruction* result = DefineSameAsFirst(sub);
1573 if (instr->CheckFlag(HValue::kCanOverflow)) {
1574 result = AssignEnvironment(result);
1577 } else if (instr->representation().IsDouble()) {
1578 return DoArithmeticD(Token::SUB, instr);
1580 return DoArithmeticT(Token::SUB, instr);
1585 LInstruction* LChunkBuilder::DoAdd(HAdd* instr) {
1586 if (instr->representation().IsSmiOrInteger32()) {
1587 DCHECK(instr->left()->representation().Equals(instr->representation()));
1588 DCHECK(instr->right()->representation().Equals(instr->representation()));
1589 // Check to see if it would be advantageous to use an lea instruction rather
1590 // than an add. This is the case when no overflow check is needed and there
1591 // are multiple uses of the add's inputs, so using a 3-register add will
1592 // preserve all input values for later uses.
1593 bool use_lea = LAddI::UseLea(instr);
1594 LOperand* left = UseRegisterAtStart(instr->BetterLeftOperand());
1595 HValue* right_candidate = instr->BetterRightOperand();
1596 LOperand* right = use_lea
1597 ? UseRegisterOrConstantAtStart(right_candidate)
1598 : UseOrConstantAtStart(right_candidate);
1599 LAddI* add = new(zone()) LAddI(left, right);
1600 bool can_overflow = instr->CheckFlag(HValue::kCanOverflow);
1601 LInstruction* result = use_lea
1602 ? DefineAsRegister(add)
1603 : DefineSameAsFirst(add);
1605 result = AssignEnvironment(result);
1608 } else if (instr->representation().IsDouble()) {
1609 return DoArithmeticD(Token::ADD, instr);
1610 } else if (instr->representation().IsExternal()) {
1611 DCHECK(instr->left()->representation().IsExternal());
1612 DCHECK(instr->right()->representation().IsInteger32());
1613 DCHECK(!instr->CheckFlag(HValue::kCanOverflow));
1614 bool use_lea = LAddI::UseLea(instr);
1615 LOperand* left = UseRegisterAtStart(instr->left());
1616 HValue* right_candidate = instr->right();
1617 LOperand* right = use_lea
1618 ? UseRegisterOrConstantAtStart(right_candidate)
1619 : UseOrConstantAtStart(right_candidate);
1620 LAddI* add = new(zone()) LAddI(left, right);
1621 LInstruction* result = use_lea
1622 ? DefineAsRegister(add)
1623 : DefineSameAsFirst(add);
1626 return DoArithmeticT(Token::ADD, instr);
1631 LInstruction* LChunkBuilder::DoMathMinMax(HMathMinMax* instr) {
1632 LOperand* left = NULL;
1633 LOperand* right = NULL;
1634 LOperand* scratch = TempRegister();
1636 if (instr->representation().IsSmiOrInteger32()) {
1637 DCHECK(instr->left()->representation().Equals(instr->representation()));
1638 DCHECK(instr->right()->representation().Equals(instr->representation()));
1639 left = UseRegisterAtStart(instr->BetterLeftOperand());
1640 right = UseOrConstantAtStart(instr->BetterRightOperand());
1642 DCHECK(instr->representation().IsDouble());
1643 DCHECK(instr->left()->representation().IsDouble());
1644 DCHECK(instr->right()->representation().IsDouble());
1645 left = UseRegisterAtStart(instr->left());
1646 right = UseRegisterAtStart(instr->right());
1648 LMathMinMax* minmax = new (zone()) LMathMinMax(left, right, scratch);
1649 return DefineSameAsFirst(minmax);
1653 LInstruction* LChunkBuilder::DoPower(HPower* instr) {
1654 // Unlike ia32, we don't have a MathPowStub and directly call c function.
1655 DCHECK(instr->representation().IsDouble());
1656 DCHECK(instr->left()->representation().IsDouble());
1657 LOperand* left = UseRegisterAtStart(instr->left());
1658 LOperand* right = UseRegisterAtStart(instr->right());
1659 LPower* result = new (zone()) LPower(left, right);
1660 return MarkAsCall(DefineSameAsFirst(result), instr);
1664 LInstruction* LChunkBuilder::DoCompareGeneric(HCompareGeneric* instr) {
1665 DCHECK(instr->left()->representation().IsSmiOrTagged());
1666 DCHECK(instr->right()->representation().IsSmiOrTagged());
1667 LOperand* context = UseFixed(instr->context(), esi);
1668 LOperand* left = UseFixed(instr->left(), edx);
1669 LOperand* right = UseFixed(instr->right(), eax);
1670 LCmpT* result = new(zone()) LCmpT(context, left, right);
1671 return MarkAsCall(DefineFixed(result, eax), instr);
1675 LInstruction* LChunkBuilder::DoCompareNumericAndBranch(
1676 HCompareNumericAndBranch* instr) {
1677 Representation r = instr->representation();
1678 if (r.IsSmiOrInteger32()) {
1679 DCHECK(instr->left()->representation().Equals(r));
1680 DCHECK(instr->right()->representation().Equals(r));
1681 LOperand* left = UseRegisterOrConstantAtStart(instr->left());
1682 LOperand* right = UseOrConstantAtStart(instr->right());
1683 return new(zone()) LCompareNumericAndBranch(left, right);
1685 DCHECK(r.IsDouble());
1686 DCHECK(instr->left()->representation().IsDouble());
1687 DCHECK(instr->right()->representation().IsDouble());
1690 if (CanBeImmediateConstant(instr->left()) &&
1691 CanBeImmediateConstant(instr->right())) {
1692 // The code generator requires either both inputs to be constant
1693 // operands, or neither.
1694 left = UseConstant(instr->left());
1695 right = UseConstant(instr->right());
1697 left = UseRegisterAtStart(instr->left());
1698 right = UseRegisterAtStart(instr->right());
1700 return new(zone()) LCompareNumericAndBranch(left, right);
1705 LInstruction* LChunkBuilder::DoCompareObjectEqAndBranch(
1706 HCompareObjectEqAndBranch* instr) {
1707 LOperand* left = UseRegisterAtStart(instr->left());
1708 LOperand* right = UseOrConstantAtStart(instr->right());
1709 return new(zone()) LCmpObjectEqAndBranch(left, right);
1713 LInstruction* LChunkBuilder::DoCompareHoleAndBranch(
1714 HCompareHoleAndBranch* instr) {
1715 LOperand* value = UseRegisterAtStart(instr->value());
1716 return new(zone()) LCmpHoleAndBranch(value);
1720 LInstruction* LChunkBuilder::DoCompareMinusZeroAndBranch(
1721 HCompareMinusZeroAndBranch* instr) {
1722 LOperand* value = UseRegisterAtStart(instr->value());
1723 return new (zone()) LCompareMinusZeroAndBranch(value);
1727 LInstruction* LChunkBuilder::DoIsObjectAndBranch(HIsObjectAndBranch* instr) {
1728 DCHECK(instr->value()->representation().IsSmiOrTagged());
1729 LOperand* temp = TempRegister();
1730 return new(zone()) LIsObjectAndBranch(UseRegister(instr->value()), temp);
1734 LInstruction* LChunkBuilder::DoIsStringAndBranch(HIsStringAndBranch* instr) {
1735 DCHECK(instr->value()->representation().IsTagged());
1736 LOperand* temp = TempRegister();
1737 return new(zone()) LIsStringAndBranch(UseRegister(instr->value()), temp);
1741 LInstruction* LChunkBuilder::DoIsSmiAndBranch(HIsSmiAndBranch* instr) {
1742 DCHECK(instr->value()->representation().IsTagged());
1743 return new(zone()) LIsSmiAndBranch(Use(instr->value()));
1747 LInstruction* LChunkBuilder::DoIsUndetectableAndBranch(
1748 HIsUndetectableAndBranch* instr) {
1749 DCHECK(instr->value()->representation().IsTagged());
1750 return new(zone()) LIsUndetectableAndBranch(
1751 UseRegisterAtStart(instr->value()), TempRegister());
1755 LInstruction* LChunkBuilder::DoStringCompareAndBranch(
1756 HStringCompareAndBranch* instr) {
1757 DCHECK(instr->left()->representation().IsTagged());
1758 DCHECK(instr->right()->representation().IsTagged());
1759 LOperand* context = UseFixed(instr->context(), esi);
1760 LOperand* left = UseFixed(instr->left(), edx);
1761 LOperand* right = UseFixed(instr->right(), eax);
1763 LStringCompareAndBranch* result = new(zone())
1764 LStringCompareAndBranch(context, left, right);
1766 return MarkAsCall(result, instr);
1770 LInstruction* LChunkBuilder::DoHasInstanceTypeAndBranch(
1771 HHasInstanceTypeAndBranch* instr) {
1772 DCHECK(instr->value()->representation().IsTagged());
1773 return new(zone()) LHasInstanceTypeAndBranch(
1774 UseRegisterAtStart(instr->value()),
1779 LInstruction* LChunkBuilder::DoGetCachedArrayIndex(
1780 HGetCachedArrayIndex* instr) {
1781 DCHECK(instr->value()->representation().IsTagged());
1782 LOperand* value = UseRegisterAtStart(instr->value());
1784 return DefineAsRegister(new(zone()) LGetCachedArrayIndex(value));
1788 LInstruction* LChunkBuilder::DoHasCachedArrayIndexAndBranch(
1789 HHasCachedArrayIndexAndBranch* instr) {
1790 DCHECK(instr->value()->representation().IsTagged());
1791 return new(zone()) LHasCachedArrayIndexAndBranch(
1792 UseRegisterAtStart(instr->value()));
1796 LInstruction* LChunkBuilder::DoClassOfTestAndBranch(
1797 HClassOfTestAndBranch* instr) {
1798 DCHECK(instr->value()->representation().IsTagged());
1799 return new(zone()) LClassOfTestAndBranch(UseRegister(instr->value()),
1805 LInstruction* LChunkBuilder::DoMapEnumLength(HMapEnumLength* instr) {
1806 LOperand* map = UseRegisterAtStart(instr->value());
1807 return DefineAsRegister(new(zone()) LMapEnumLength(map));
1811 LInstruction* LChunkBuilder::DoDateField(HDateField* instr) {
1812 LOperand* date = UseFixed(instr->value(), eax);
1813 LDateField* result =
1814 new(zone()) LDateField(date, FixedTemp(ecx), instr->index());
1815 return MarkAsCall(DefineFixed(result, eax), instr, CAN_DEOPTIMIZE_EAGERLY);
1819 LInstruction* LChunkBuilder::DoSeqStringGetChar(HSeqStringGetChar* instr) {
1820 LOperand* string = UseRegisterAtStart(instr->string());
1821 LOperand* index = UseRegisterOrConstantAtStart(instr->index());
1822 return DefineAsRegister(new(zone()) LSeqStringGetChar(string, index));
1826 LOperand* LChunkBuilder::GetSeqStringSetCharOperand(HSeqStringSetChar* instr) {
1827 if (instr->encoding() == String::ONE_BYTE_ENCODING) {
1828 if (FLAG_debug_code) {
1829 return UseFixed(instr->value(), eax);
1831 return UseFixedOrConstant(instr->value(), eax);
1834 if (FLAG_debug_code) {
1835 return UseRegisterAtStart(instr->value());
1837 return UseRegisterOrConstantAtStart(instr->value());
1843 LInstruction* LChunkBuilder::DoSeqStringSetChar(HSeqStringSetChar* instr) {
1844 LOperand* string = UseRegisterAtStart(instr->string());
1845 LOperand* index = FLAG_debug_code
1846 ? UseRegisterAtStart(instr->index())
1847 : UseRegisterOrConstantAtStart(instr->index());
1848 LOperand* value = GetSeqStringSetCharOperand(instr);
1849 LOperand* context = FLAG_debug_code ? UseFixed(instr->context(), esi) : NULL;
1850 LInstruction* result = new(zone()) LSeqStringSetChar(context, string,
1852 if (FLAG_debug_code) {
1853 result = MarkAsCall(result, instr);
1859 LInstruction* LChunkBuilder::DoBoundsCheck(HBoundsCheck* instr) {
1860 if (!FLAG_debug_code && instr->skip_check()) return NULL;
1861 LOperand* index = UseRegisterOrConstantAtStart(instr->index());
1862 LOperand* length = !index->IsConstantOperand()
1863 ? UseOrConstantAtStart(instr->length())
1864 : UseAtStart(instr->length());
1865 LInstruction* result = new(zone()) LBoundsCheck(index, length);
1866 if (!FLAG_debug_code || !instr->skip_check()) {
1867 result = AssignEnvironment(result);
1873 LInstruction* LChunkBuilder::DoBoundsCheckBaseIndexInformation(
1874 HBoundsCheckBaseIndexInformation* instr) {
1880 LInstruction* LChunkBuilder::DoAbnormalExit(HAbnormalExit* instr) {
1881 // The control instruction marking the end of a block that completed
1882 // abruptly (e.g., threw an exception). There is nothing specific to do.
1887 LInstruction* LChunkBuilder::DoUseConst(HUseConst* instr) {
1892 LInstruction* LChunkBuilder::DoForceRepresentation(HForceRepresentation* bad) {
1893 // All HForceRepresentation instructions should be eliminated in the
1894 // representation change phase of Hydrogen.
1900 LInstruction* LChunkBuilder::DoChange(HChange* instr) {
1901 Representation from = instr->from();
1902 Representation to = instr->to();
1903 HValue* val = instr->value();
1905 if (to.IsTagged()) {
1906 LOperand* value = UseRegister(val);
1907 return DefineSameAsFirst(new(zone()) LDummyUse(value));
1909 from = Representation::Tagged();
1911 if (from.IsTagged()) {
1912 if (to.IsDouble()) {
1913 LOperand* value = UseRegister(val);
1914 LOperand* temp = TempRegister();
1915 LInstruction* result =
1916 DefineAsRegister(new(zone()) LNumberUntagD(value, temp));
1917 if (!val->representation().IsSmi()) result = AssignEnvironment(result);
1919 } else if (to.IsSmi()) {
1920 LOperand* value = UseRegister(val);
1921 if (val->type().IsSmi()) {
1922 return DefineSameAsFirst(new(zone()) LDummyUse(value));
1924 return AssignEnvironment(DefineSameAsFirst(new(zone()) LCheckSmi(value)));
1926 DCHECK(to.IsInteger32());
1927 if (val->type().IsSmi() || val->representation().IsSmi()) {
1928 LOperand* value = UseRegister(val);
1929 return DefineSameAsFirst(new(zone()) LSmiUntag(value, false));
1931 LOperand* value = UseRegister(val);
1932 LInstruction* result = DefineSameAsFirst(new(zone()) LTaggedToI(value));
1933 if (!val->representation().IsSmi()) result = AssignEnvironment(result);
1937 } else if (from.IsDouble()) {
1938 if (to.IsTagged()) {
1939 info()->MarkAsDeferredCalling();
1940 LOperand* value = UseRegisterAtStart(val);
1941 LOperand* temp = FLAG_inline_new ? TempRegister() : NULL;
1942 LUnallocated* result_temp = TempRegister();
1943 LNumberTagD* result = new(zone()) LNumberTagD(value, temp);
1944 return AssignPointerMap(Define(result, result_temp));
1945 } else if (to.IsSmi()) {
1946 LOperand* value = UseRegister(val);
1947 return AssignEnvironment(
1948 DefineAsRegister(new(zone()) LDoubleToSmi(value)));
1950 DCHECK(to.IsInteger32());
1951 bool truncating = instr->CanTruncateToInt32();
1952 LOperand* value = UseRegister(val);
1953 LInstruction* result = DefineAsRegister(new(zone()) LDoubleToI(value));
1954 if (!truncating) result = AssignEnvironment(result);
1957 } else if (from.IsInteger32()) {
1958 info()->MarkAsDeferredCalling();
1959 if (to.IsTagged()) {
1960 if (!instr->CheckFlag(HValue::kCanOverflow)) {
1961 LOperand* value = UseRegister(val);
1962 return DefineSameAsFirst(new(zone()) LSmiTag(value));
1963 } else if (val->CheckFlag(HInstruction::kUint32)) {
1964 LOperand* value = UseRegister(val);
1965 LOperand* temp = TempRegister();
1966 LNumberTagU* result = new(zone()) LNumberTagU(value, temp);
1967 return AssignPointerMap(DefineSameAsFirst(result));
1969 LOperand* value = UseRegister(val);
1970 LOperand* temp = TempRegister();
1971 LNumberTagI* result = new(zone()) LNumberTagI(value, temp);
1972 return AssignPointerMap(DefineSameAsFirst(result));
1974 } else if (to.IsSmi()) {
1975 LOperand* value = UseRegister(val);
1976 LInstruction* result = DefineSameAsFirst(new(zone()) LSmiTag(value));
1977 if (instr->CheckFlag(HValue::kCanOverflow)) {
1978 result = AssignEnvironment(result);
1982 DCHECK(to.IsDouble());
1983 if (val->CheckFlag(HInstruction::kUint32)) {
1984 return DefineAsRegister(new(zone()) LUint32ToDouble(UseRegister(val)));
1986 return DefineAsRegister(new(zone()) LInteger32ToDouble(Use(val)));
1995 LInstruction* LChunkBuilder::DoCheckHeapObject(HCheckHeapObject* instr) {
1996 LOperand* value = UseAtStart(instr->value());
1997 LInstruction* result = new(zone()) LCheckNonSmi(value);
1998 if (!instr->value()->type().IsHeapObject()) {
1999 result = AssignEnvironment(result);
2005 LInstruction* LChunkBuilder::DoCheckSmi(HCheckSmi* instr) {
2006 LOperand* value = UseRegisterAtStart(instr->value());
2007 return AssignEnvironment(new(zone()) LCheckSmi(value));
2011 LInstruction* LChunkBuilder::DoCheckInstanceType(HCheckInstanceType* instr) {
2012 LOperand* value = UseRegisterAtStart(instr->value());
2013 LOperand* temp = TempRegister();
2014 LCheckInstanceType* result = new(zone()) LCheckInstanceType(value, temp);
2015 return AssignEnvironment(result);
2019 LInstruction* LChunkBuilder::DoCheckValue(HCheckValue* instr) {
2020 // If the object is in new space, we'll emit a global cell compare and so
2021 // want the value in a register. If the object gets promoted before we
2022 // emit code, we will still get the register but will do an immediate
2023 // compare instead of the cell compare. This is safe.
2024 LOperand* value = instr->object_in_new_space()
2025 ? UseRegisterAtStart(instr->value()) : UseAtStart(instr->value());
2026 return AssignEnvironment(new(zone()) LCheckValue(value));
2030 LInstruction* LChunkBuilder::DoCheckMaps(HCheckMaps* instr) {
2031 if (instr->IsStabilityCheck()) return new(zone()) LCheckMaps;
2032 LOperand* value = UseRegisterAtStart(instr->value());
2033 LInstruction* result = AssignEnvironment(new(zone()) LCheckMaps(value));
2034 if (instr->HasMigrationTarget()) {
2035 info()->MarkAsDeferredCalling();
2036 result = AssignPointerMap(result);
2042 LInstruction* LChunkBuilder::DoClampToUint8(HClampToUint8* instr) {
2043 HValue* value = instr->value();
2044 Representation input_rep = value->representation();
2045 if (input_rep.IsDouble()) {
2046 LOperand* reg = UseRegister(value);
2047 return DefineFixed(new (zone()) LClampDToUint8(reg), eax);
2048 } else if (input_rep.IsInteger32()) {
2049 LOperand* reg = UseFixed(value, eax);
2050 return DefineFixed(new(zone()) LClampIToUint8(reg), eax);
2052 DCHECK(input_rep.IsSmiOrTagged());
2053 LOperand* value = UseRegister(instr->value());
2054 LClampTToUint8NoSSE2* res =
2055 new(zone()) LClampTToUint8NoSSE2(value, TempRegister(),
2056 TempRegister(), TempRegister());
2057 return AssignEnvironment(DefineFixed(res, ecx));
2062 LInstruction* LChunkBuilder::DoDoubleBits(HDoubleBits* instr) {
2063 HValue* value = instr->value();
2064 DCHECK(value->representation().IsDouble());
2065 return DefineAsRegister(new(zone()) LDoubleBits(UseRegister(value)));
2069 LInstruction* LChunkBuilder::DoConstructDouble(HConstructDouble* instr) {
2070 LOperand* lo = UseRegister(instr->lo());
2071 LOperand* hi = UseRegister(instr->hi());
2072 return DefineAsRegister(new(zone()) LConstructDouble(hi, lo));
2076 LInstruction* LChunkBuilder::DoReturn(HReturn* instr) {
2077 LOperand* context = info()->IsStub() ? UseFixed(instr->context(), esi) : NULL;
2078 LOperand* parameter_count = UseRegisterOrConstant(instr->parameter_count());
2079 return new(zone()) LReturn(
2080 UseFixed(instr->value(), eax), context, parameter_count);
2084 LInstruction* LChunkBuilder::DoConstant(HConstant* instr) {
2085 Representation r = instr->representation();
2087 return DefineAsRegister(new(zone()) LConstantS);
2088 } else if (r.IsInteger32()) {
2089 return DefineAsRegister(new(zone()) LConstantI);
2090 } else if (r.IsDouble()) {
2091 return DefineAsRegister(new (zone()) LConstantD);
2092 } else if (r.IsExternal()) {
2093 return DefineAsRegister(new(zone()) LConstantE);
2094 } else if (r.IsTagged()) {
2095 return DefineAsRegister(new(zone()) LConstantT);
2103 LInstruction* LChunkBuilder::DoLoadGlobalCell(HLoadGlobalCell* instr) {
2104 LLoadGlobalCell* result = new(zone()) LLoadGlobalCell;
2105 return instr->RequiresHoleCheck()
2106 ? AssignEnvironment(DefineAsRegister(result))
2107 : DefineAsRegister(result);
2111 LInstruction* LChunkBuilder::DoLoadGlobalGeneric(HLoadGlobalGeneric* instr) {
2112 LOperand* context = UseFixed(instr->context(), esi);
2113 LOperand* global_object =
2114 UseFixed(instr->global_object(), LoadDescriptor::ReceiverRegister());
2115 LOperand* vector = NULL;
2116 if (FLAG_vector_ics) {
2117 vector = FixedTemp(VectorLoadICDescriptor::VectorRegister());
2120 LLoadGlobalGeneric* result =
2121 new(zone()) LLoadGlobalGeneric(context, global_object, vector);
2122 return MarkAsCall(DefineFixed(result, eax), instr);
2126 LInstruction* LChunkBuilder::DoStoreGlobalCell(HStoreGlobalCell* instr) {
2127 LStoreGlobalCell* result =
2128 new(zone()) LStoreGlobalCell(UseRegister(instr->value()));
2129 return instr->RequiresHoleCheck() ? AssignEnvironment(result) : result;
2133 LInstruction* LChunkBuilder::DoLoadContextSlot(HLoadContextSlot* instr) {
2134 LOperand* context = UseRegisterAtStart(instr->value());
2135 LInstruction* result =
2136 DefineAsRegister(new(zone()) LLoadContextSlot(context));
2137 if (instr->RequiresHoleCheck() && instr->DeoptimizesOnHole()) {
2138 result = AssignEnvironment(result);
2144 LInstruction* LChunkBuilder::DoStoreContextSlot(HStoreContextSlot* instr) {
2147 LOperand* context = UseRegister(instr->context());
2148 if (instr->NeedsWriteBarrier()) {
2149 value = UseTempRegister(instr->value());
2150 temp = TempRegister();
2152 value = UseRegister(instr->value());
2155 LInstruction* result = new(zone()) LStoreContextSlot(context, value, temp);
2156 if (instr->RequiresHoleCheck() && instr->DeoptimizesOnHole()) {
2157 result = AssignEnvironment(result);
2163 LInstruction* LChunkBuilder::DoLoadNamedField(HLoadNamedField* instr) {
2164 LOperand* obj = (instr->access().IsExternalMemory() &&
2165 instr->access().offset() == 0)
2166 ? UseRegisterOrConstantAtStart(instr->object())
2167 : UseRegisterAtStart(instr->object());
2168 return DefineAsRegister(new(zone()) LLoadNamedField(obj));
2172 LInstruction* LChunkBuilder::DoLoadNamedGeneric(HLoadNamedGeneric* instr) {
2173 LOperand* context = UseFixed(instr->context(), esi);
2175 UseFixed(instr->object(), LoadDescriptor::ReceiverRegister());
2176 LOperand* vector = NULL;
2177 if (FLAG_vector_ics) {
2178 vector = FixedTemp(VectorLoadICDescriptor::VectorRegister());
2180 LLoadNamedGeneric* result = new(zone()) LLoadNamedGeneric(
2181 context, object, vector);
2182 return MarkAsCall(DefineFixed(result, eax), instr);
2186 LInstruction* LChunkBuilder::DoLoadFunctionPrototype(
2187 HLoadFunctionPrototype* instr) {
2188 return AssignEnvironment(DefineAsRegister(
2189 new(zone()) LLoadFunctionPrototype(UseRegister(instr->function()),
2194 LInstruction* LChunkBuilder::DoLoadRoot(HLoadRoot* instr) {
2195 return DefineAsRegister(new(zone()) LLoadRoot);
2199 LInstruction* LChunkBuilder::DoLoadKeyed(HLoadKeyed* instr) {
2200 DCHECK(instr->key()->representation().IsSmiOrInteger32());
2201 ElementsKind elements_kind = instr->elements_kind();
2202 bool clobbers_key = ExternalArrayOpRequiresTemp(
2203 instr->key()->representation(), elements_kind);
2204 LOperand* key = clobbers_key
2205 ? UseTempRegister(instr->key())
2206 : UseRegisterOrConstantAtStart(instr->key());
2207 LInstruction* result = NULL;
2209 if (!instr->is_typed_elements()) {
2210 LOperand* obj = UseRegisterAtStart(instr->elements());
2211 result = DefineAsRegister(new(zone()) LLoadKeyed(obj, key));
2214 (instr->representation().IsInteger32() &&
2215 !(IsDoubleOrFloatElementsKind(instr->elements_kind()))) ||
2216 (instr->representation().IsDouble() &&
2217 (IsDoubleOrFloatElementsKind(instr->elements_kind()))));
2218 LOperand* backing_store = UseRegister(instr->elements());
2219 result = DefineAsRegister(new(zone()) LLoadKeyed(backing_store, key));
2222 if ((instr->is_external() || instr->is_fixed_typed_array()) ?
2223 // see LCodeGen::DoLoadKeyedExternalArray
2224 ((instr->elements_kind() == EXTERNAL_UINT32_ELEMENTS ||
2225 instr->elements_kind() == UINT32_ELEMENTS) &&
2226 !instr->CheckFlag(HInstruction::kUint32)) :
2227 // see LCodeGen::DoLoadKeyedFixedDoubleArray and
2228 // LCodeGen::DoLoadKeyedFixedArray
2229 instr->RequiresHoleCheck()) {
2230 result = AssignEnvironment(result);
2236 LInstruction* LChunkBuilder::DoLoadKeyedGeneric(HLoadKeyedGeneric* instr) {
2237 LOperand* context = UseFixed(instr->context(), esi);
2239 UseFixed(instr->object(), LoadDescriptor::ReceiverRegister());
2240 LOperand* key = UseFixed(instr->key(), LoadDescriptor::NameRegister());
2241 LOperand* vector = NULL;
2242 if (FLAG_vector_ics) {
2243 vector = FixedTemp(VectorLoadICDescriptor::VectorRegister());
2245 LLoadKeyedGeneric* result =
2246 new(zone()) LLoadKeyedGeneric(context, object, key, vector);
2247 return MarkAsCall(DefineFixed(result, eax), instr);
2251 LOperand* LChunkBuilder::GetStoreKeyedValueOperand(HStoreKeyed* instr) {
2252 ElementsKind elements_kind = instr->elements_kind();
2254 // Determine if we need a byte register in this case for the value.
2255 bool val_is_fixed_register =
2256 elements_kind == EXTERNAL_INT8_ELEMENTS ||
2257 elements_kind == EXTERNAL_UINT8_ELEMENTS ||
2258 elements_kind == EXTERNAL_UINT8_CLAMPED_ELEMENTS ||
2259 elements_kind == UINT8_ELEMENTS ||
2260 elements_kind == INT8_ELEMENTS ||
2261 elements_kind == UINT8_CLAMPED_ELEMENTS;
2262 if (val_is_fixed_register) {
2263 return UseFixed(instr->value(), eax);
2266 if (IsDoubleOrFloatElementsKind(elements_kind)) {
2267 return UseRegisterAtStart(instr->value());
2270 return UseRegister(instr->value());
2274 LInstruction* LChunkBuilder::DoStoreKeyed(HStoreKeyed* instr) {
2275 if (!instr->is_typed_elements()) {
2276 DCHECK(instr->elements()->representation().IsTagged());
2277 DCHECK(instr->key()->representation().IsInteger32() ||
2278 instr->key()->representation().IsSmi());
2280 if (instr->value()->representation().IsDouble()) {
2281 LOperand* object = UseRegisterAtStart(instr->elements());
2282 // For storing double hole, no fp register required.
2283 LOperand* val = instr->IsConstantHoleStore()
2285 : UseRegisterAtStart(instr->value());
2286 LOperand* key = UseRegisterOrConstantAtStart(instr->key());
2287 return new(zone()) LStoreKeyed(object, key, val);
2289 DCHECK(instr->value()->representation().IsSmiOrTagged());
2290 bool needs_write_barrier = instr->NeedsWriteBarrier();
2292 LOperand* obj = UseRegister(instr->elements());
2295 if (needs_write_barrier) {
2296 val = UseTempRegister(instr->value());
2297 key = UseTempRegister(instr->key());
2299 val = UseRegisterOrConstantAtStart(instr->value());
2300 key = UseRegisterOrConstantAtStart(instr->key());
2302 return new(zone()) LStoreKeyed(obj, key, val);
2306 ElementsKind elements_kind = instr->elements_kind();
2308 (instr->value()->representation().IsInteger32() &&
2309 !IsDoubleOrFloatElementsKind(elements_kind)) ||
2310 (instr->value()->representation().IsDouble() &&
2311 IsDoubleOrFloatElementsKind(elements_kind)));
2312 DCHECK((instr->is_fixed_typed_array() &&
2313 instr->elements()->representation().IsTagged()) ||
2314 (instr->is_external() &&
2315 instr->elements()->representation().IsExternal()));
2317 LOperand* backing_store = UseRegister(instr->elements());
2318 LOperand* val = GetStoreKeyedValueOperand(instr);
2319 bool clobbers_key = ExternalArrayOpRequiresTemp(
2320 instr->key()->representation(), elements_kind);
2321 LOperand* key = clobbers_key
2322 ? UseTempRegister(instr->key())
2323 : UseRegisterOrConstantAtStart(instr->key());
2324 return new(zone()) LStoreKeyed(backing_store, key, val);
2328 LInstruction* LChunkBuilder::DoStoreKeyedGeneric(HStoreKeyedGeneric* instr) {
2329 LOperand* context = UseFixed(instr->context(), esi);
2331 UseFixed(instr->object(), StoreDescriptor::ReceiverRegister());
2332 LOperand* key = UseFixed(instr->key(), StoreDescriptor::NameRegister());
2333 LOperand* value = UseFixed(instr->value(), StoreDescriptor::ValueRegister());
2335 DCHECK(instr->object()->representation().IsTagged());
2336 DCHECK(instr->key()->representation().IsTagged());
2337 DCHECK(instr->value()->representation().IsTagged());
2339 LStoreKeyedGeneric* result =
2340 new(zone()) LStoreKeyedGeneric(context, object, key, value);
2341 return MarkAsCall(result, instr);
2345 LInstruction* LChunkBuilder::DoTransitionElementsKind(
2346 HTransitionElementsKind* instr) {
2347 if (IsSimpleMapChangeTransition(instr->from_kind(), instr->to_kind())) {
2348 LOperand* object = UseRegister(instr->object());
2349 LOperand* new_map_reg = TempRegister();
2350 LOperand* temp_reg = TempRegister();
2351 LTransitionElementsKind* result =
2352 new(zone()) LTransitionElementsKind(object, NULL,
2353 new_map_reg, temp_reg);
2356 LOperand* object = UseFixed(instr->object(), eax);
2357 LOperand* context = UseFixed(instr->context(), esi);
2358 LTransitionElementsKind* result =
2359 new(zone()) LTransitionElementsKind(object, context, NULL, NULL);
2360 return MarkAsCall(result, instr);
2365 LInstruction* LChunkBuilder::DoTrapAllocationMemento(
2366 HTrapAllocationMemento* instr) {
2367 LOperand* object = UseRegister(instr->object());
2368 LOperand* temp = TempRegister();
2369 LTrapAllocationMemento* result =
2370 new(zone()) LTrapAllocationMemento(object, temp);
2371 return AssignEnvironment(result);
2375 LInstruction* LChunkBuilder::DoStoreNamedField(HStoreNamedField* instr) {
2376 bool is_in_object = instr->access().IsInobject();
2377 bool is_external_location = instr->access().IsExternalMemory() &&
2378 instr->access().offset() == 0;
2379 bool needs_write_barrier = instr->NeedsWriteBarrier();
2380 bool needs_write_barrier_for_map = instr->has_transition() &&
2381 instr->NeedsWriteBarrierForMap();
2384 if (needs_write_barrier) {
2386 ? UseRegister(instr->object())
2387 : UseTempRegister(instr->object());
2388 } else if (is_external_location) {
2389 DCHECK(!is_in_object);
2390 DCHECK(!needs_write_barrier);
2391 DCHECK(!needs_write_barrier_for_map);
2392 obj = UseRegisterOrConstant(instr->object());
2394 obj = needs_write_barrier_for_map
2395 ? UseRegister(instr->object())
2396 : UseRegisterAtStart(instr->object());
2399 bool can_be_constant = instr->value()->IsConstant() &&
2400 HConstant::cast(instr->value())->NotInNewSpace() &&
2401 !instr->field_representation().IsDouble();
2404 if (instr->field_representation().IsInteger8() ||
2405 instr->field_representation().IsUInteger8()) {
2406 // mov_b requires a byte register (i.e. any of eax, ebx, ecx, edx).
2407 // Just force the value to be in eax and we're safe here.
2408 val = UseFixed(instr->value(), eax);
2409 } else if (needs_write_barrier) {
2410 val = UseTempRegister(instr->value());
2411 } else if (can_be_constant) {
2412 val = UseRegisterOrConstant(instr->value());
2413 } else if (instr->field_representation().IsDouble()) {
2414 val = UseRegisterAtStart(instr->value());
2416 val = UseRegister(instr->value());
2419 // We only need a scratch register if we have a write barrier or we
2420 // have a store into the properties array (not in-object-property).
2421 LOperand* temp = (!is_in_object || needs_write_barrier ||
2422 needs_write_barrier_for_map) ? TempRegister() : NULL;
2424 // We need a temporary register for write barrier of the map field.
2425 LOperand* temp_map = needs_write_barrier_for_map ? TempRegister() : NULL;
2427 return new(zone()) LStoreNamedField(obj, val, temp, temp_map);
2431 LInstruction* LChunkBuilder::DoStoreNamedGeneric(HStoreNamedGeneric* instr) {
2432 LOperand* context = UseFixed(instr->context(), esi);
2434 UseFixed(instr->object(), StoreDescriptor::ReceiverRegister());
2435 LOperand* value = UseFixed(instr->value(), StoreDescriptor::ValueRegister());
2437 LStoreNamedGeneric* result =
2438 new(zone()) LStoreNamedGeneric(context, object, value);
2439 return MarkAsCall(result, instr);
2443 LInstruction* LChunkBuilder::DoStringAdd(HStringAdd* instr) {
2444 LOperand* context = UseFixed(instr->context(), esi);
2445 LOperand* left = UseFixed(instr->left(), edx);
2446 LOperand* right = UseFixed(instr->right(), eax);
2447 LStringAdd* string_add = new(zone()) LStringAdd(context, left, right);
2448 return MarkAsCall(DefineFixed(string_add, eax), instr);
2452 LInstruction* LChunkBuilder::DoStringCharCodeAt(HStringCharCodeAt* instr) {
2453 LOperand* string = UseTempRegister(instr->string());
2454 LOperand* index = UseTempRegister(instr->index());
2455 LOperand* context = UseAny(instr->context());
2456 LStringCharCodeAt* result =
2457 new(zone()) LStringCharCodeAt(context, string, index);
2458 return AssignPointerMap(DefineAsRegister(result));
2462 LInstruction* LChunkBuilder::DoStringCharFromCode(HStringCharFromCode* instr) {
2463 LOperand* char_code = UseRegister(instr->value());
2464 LOperand* context = UseAny(instr->context());
2465 LStringCharFromCode* result =
2466 new(zone()) LStringCharFromCode(context, char_code);
2467 return AssignPointerMap(DefineAsRegister(result));
2471 LInstruction* LChunkBuilder::DoAllocate(HAllocate* instr) {
2472 info()->MarkAsDeferredCalling();
2473 LOperand* context = UseAny(instr->context());
2474 LOperand* size = instr->size()->IsConstant()
2475 ? UseConstant(instr->size())
2476 : UseTempRegister(instr->size());
2477 LOperand* temp = TempRegister();
2478 LAllocate* result = new(zone()) LAllocate(context, size, temp);
2479 return AssignPointerMap(DefineAsRegister(result));
2483 LInstruction* LChunkBuilder::DoRegExpLiteral(HRegExpLiteral* instr) {
2484 LOperand* context = UseFixed(instr->context(), esi);
2486 DefineFixed(new(zone()) LRegExpLiteral(context), eax), instr);
2490 LInstruction* LChunkBuilder::DoFunctionLiteral(HFunctionLiteral* instr) {
2491 LOperand* context = UseFixed(instr->context(), esi);
2493 DefineFixed(new(zone()) LFunctionLiteral(context), eax), instr);
2497 LInstruction* LChunkBuilder::DoOsrEntry(HOsrEntry* instr) {
2498 DCHECK(argument_count_ == 0);
2499 allocator_->MarkAsOsrEntry();
2500 current_block_->last_environment()->set_ast_id(instr->ast_id());
2501 return AssignEnvironment(new(zone()) LOsrEntry);
2505 LInstruction* LChunkBuilder::DoParameter(HParameter* instr) {
2506 LParameter* result = new(zone()) LParameter;
2507 if (instr->kind() == HParameter::STACK_PARAMETER) {
2508 int spill_index = chunk()->GetParameterStackSlot(instr->index());
2509 return DefineAsSpilled(result, spill_index);
2511 DCHECK(info()->IsStub());
2512 CallInterfaceDescriptor descriptor =
2513 info()->code_stub()->GetCallInterfaceDescriptor();
2514 int index = static_cast<int>(instr->index());
2515 Register reg = descriptor.GetEnvironmentParameterRegister(index);
2516 return DefineFixed(result, reg);
2521 LInstruction* LChunkBuilder::DoUnknownOSRValue(HUnknownOSRValue* instr) {
2522 // Use an index that corresponds to the location in the unoptimized frame,
2523 // which the optimized frame will subsume.
2524 int env_index = instr->index();
2525 int spill_index = 0;
2526 if (instr->environment()->is_parameter_index(env_index)) {
2527 spill_index = chunk()->GetParameterStackSlot(env_index);
2529 spill_index = env_index - instr->environment()->first_local_index();
2530 if (spill_index > LUnallocated::kMaxFixedSlotIndex) {
2531 Retry(kNotEnoughSpillSlotsForOsr);
2534 if (spill_index == 0) {
2535 // The dynamic frame alignment state overwrites the first local.
2536 // The first local is saved at the end of the unoptimized frame.
2537 spill_index = graph()->osr()->UnoptimizedFrameSlots();
2540 return DefineAsSpilled(new(zone()) LUnknownOSRValue, spill_index);
2544 LInstruction* LChunkBuilder::DoCallStub(HCallStub* instr) {
2545 LOperand* context = UseFixed(instr->context(), esi);
2546 LCallStub* result = new(zone()) LCallStub(context);
2547 return MarkAsCall(DefineFixed(result, eax), instr);
2551 LInstruction* LChunkBuilder::DoArgumentsObject(HArgumentsObject* instr) {
2552 // There are no real uses of the arguments object.
2553 // arguments.length and element access are supported directly on
2554 // stack arguments, and any real arguments object use causes a bailout.
2555 // So this value is never used.
2560 LInstruction* LChunkBuilder::DoCapturedObject(HCapturedObject* instr) {
2561 instr->ReplayEnvironment(current_block_->last_environment());
2563 // There are no real uses of a captured object.
2568 LInstruction* LChunkBuilder::DoAccessArgumentsAt(HAccessArgumentsAt* instr) {
2569 info()->MarkAsRequiresFrame();
2570 LOperand* args = UseRegister(instr->arguments());
2573 if (instr->length()->IsConstant() && instr->index()->IsConstant()) {
2574 length = UseRegisterOrConstant(instr->length());
2575 index = UseOrConstant(instr->index());
2577 length = UseTempRegister(instr->length());
2578 index = Use(instr->index());
2580 return DefineAsRegister(new(zone()) LAccessArgumentsAt(args, length, index));
2584 LInstruction* LChunkBuilder::DoToFastProperties(HToFastProperties* instr) {
2585 LOperand* object = UseFixed(instr->value(), eax);
2586 LToFastProperties* result = new(zone()) LToFastProperties(object);
2587 return MarkAsCall(DefineFixed(result, eax), instr);
2591 LInstruction* LChunkBuilder::DoTypeof(HTypeof* instr) {
2592 LOperand* context = UseFixed(instr->context(), esi);
2593 LOperand* value = UseAtStart(instr->value());
2594 LTypeof* result = new(zone()) LTypeof(context, value);
2595 return MarkAsCall(DefineFixed(result, eax), instr);
2599 LInstruction* LChunkBuilder::DoTypeofIsAndBranch(HTypeofIsAndBranch* instr) {
2600 return new(zone()) LTypeofIsAndBranch(UseTempRegister(instr->value()));
2604 LInstruction* LChunkBuilder::DoIsConstructCallAndBranch(
2605 HIsConstructCallAndBranch* instr) {
2606 return new(zone()) LIsConstructCallAndBranch(TempRegister());
2610 LInstruction* LChunkBuilder::DoSimulate(HSimulate* instr) {
2611 instr->ReplayEnvironment(current_block_->last_environment());
2616 LInstruction* LChunkBuilder::DoStackCheck(HStackCheck* instr) {
2617 info()->MarkAsDeferredCalling();
2618 if (instr->is_function_entry()) {
2619 LOperand* context = UseFixed(instr->context(), esi);
2620 return MarkAsCall(new(zone()) LStackCheck(context), instr);
2622 DCHECK(instr->is_backwards_branch());
2623 LOperand* context = UseAny(instr->context());
2624 return AssignEnvironment(
2625 AssignPointerMap(new(zone()) LStackCheck(context)));
2630 LInstruction* LChunkBuilder::DoEnterInlined(HEnterInlined* instr) {
2631 HEnvironment* outer = current_block_->last_environment();
2632 outer->set_ast_id(instr->ReturnId());
2633 HConstant* undefined = graph()->GetConstantUndefined();
2634 HEnvironment* inner = outer->CopyForInlining(instr->closure(),
2635 instr->arguments_count(),
2638 instr->inlining_kind());
2639 // Only replay binding of arguments object if it wasn't removed from graph.
2640 if (instr->arguments_var() != NULL && instr->arguments_object()->IsLinked()) {
2641 inner->Bind(instr->arguments_var(), instr->arguments_object());
2643 inner->BindContext(instr->closure_context());
2644 inner->set_entry(instr);
2645 current_block_->UpdateEnvironment(inner);
2646 chunk_->AddInlinedClosure(instr->closure());
2651 LInstruction* LChunkBuilder::DoLeaveInlined(HLeaveInlined* instr) {
2652 LInstruction* pop = NULL;
2654 HEnvironment* env = current_block_->last_environment();
2656 if (env->entry()->arguments_pushed()) {
2657 int argument_count = env->arguments_environment()->parameter_count();
2658 pop = new(zone()) LDrop(argument_count);
2659 DCHECK(instr->argument_delta() == -argument_count);
2662 HEnvironment* outer = current_block_->last_environment()->
2663 DiscardInlined(false);
2664 current_block_->UpdateEnvironment(outer);
2669 LInstruction* LChunkBuilder::DoForInPrepareMap(HForInPrepareMap* instr) {
2670 LOperand* context = UseFixed(instr->context(), esi);
2671 LOperand* object = UseFixed(instr->enumerable(), eax);
2672 LForInPrepareMap* result = new(zone()) LForInPrepareMap(context, object);
2673 return MarkAsCall(DefineFixed(result, eax), instr, CAN_DEOPTIMIZE_EAGERLY);
2677 LInstruction* LChunkBuilder::DoForInCacheArray(HForInCacheArray* instr) {
2678 LOperand* map = UseRegister(instr->map());
2679 return AssignEnvironment(DefineAsRegister(
2680 new(zone()) LForInCacheArray(map)));
2684 LInstruction* LChunkBuilder::DoCheckMapValue(HCheckMapValue* instr) {
2685 LOperand* value = UseRegisterAtStart(instr->value());
2686 LOperand* map = UseRegisterAtStart(instr->map());
2687 return AssignEnvironment(new(zone()) LCheckMapValue(value, map));
2691 LInstruction* LChunkBuilder::DoLoadFieldByIndex(HLoadFieldByIndex* instr) {
2692 LOperand* object = UseRegister(instr->object());
2693 LOperand* index = UseTempRegister(instr->index());
2694 LLoadFieldByIndex* load = new(zone()) LLoadFieldByIndex(object, index);
2695 LInstruction* result = DefineSameAsFirst(load);
2696 return AssignPointerMap(result);
2700 LInstruction* LChunkBuilder::DoStoreFrameContext(HStoreFrameContext* instr) {
2701 LOperand* context = UseRegisterAtStart(instr->context());
2702 return new(zone()) LStoreFrameContext(context);
2706 LInstruction* LChunkBuilder::DoAllocateBlockContext(
2707 HAllocateBlockContext* instr) {
2708 LOperand* context = UseFixed(instr->context(), esi);
2709 LOperand* function = UseRegisterAtStart(instr->function());
2710 LAllocateBlockContext* result =
2711 new(zone()) LAllocateBlockContext(context, function);
2712 return MarkAsCall(DefineFixed(result, esi), instr);
2716 } } // namespace v8::internal
2718 #endif // V8_TARGET_ARCH_X87