1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
9 #if V8_TARGET_ARCH_IA32
11 #include "src/hydrogen-osr.h"
12 #include "src/ia32/lithium-codegen-ia32.h"
13 #include "src/lithium-inl.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 void LInstruction::PrintTo(StringStream* stream) {
65 stream->Add("%s ", this->Mnemonic());
67 PrintOutputOperandTo(stream);
71 if (HasEnvironment()) {
73 environment()->PrintTo(stream);
76 if (HasPointerMap()) {
78 pointer_map()->PrintTo(stream);
83 void LInstruction::PrintDataTo(StringStream* stream) {
85 for (int i = 0; i < InputCount(); i++) {
86 if (i > 0) stream->Add(" ");
87 if (InputAt(i) == NULL) {
90 InputAt(i)->PrintTo(stream);
96 void LInstruction::PrintOutputOperandTo(StringStream* stream) {
97 if (HasResult()) result()->PrintTo(stream);
101 void LLabel::PrintDataTo(StringStream* stream) {
102 LGap::PrintDataTo(stream);
103 LLabel* rep = replacement();
105 stream->Add(" Dead block replaced with B%d", rep->block_id());
110 bool LGap::IsRedundant() const {
111 for (int i = 0; i < 4; i++) {
112 if (parallel_moves_[i] != NULL && !parallel_moves_[i]->IsRedundant()) {
121 void LGap::PrintDataTo(StringStream* stream) {
122 for (int i = 0; i < 4; i++) {
124 if (parallel_moves_[i] != NULL) {
125 parallel_moves_[i]->PrintDataTo(stream);
132 const char* LArithmeticD::Mnemonic() const {
134 case Token::ADD: return "add-d";
135 case Token::SUB: return "sub-d";
136 case Token::MUL: return "mul-d";
137 case Token::DIV: return "div-d";
138 case Token::MOD: return "mod-d";
146 const char* LArithmeticT::Mnemonic() const {
148 case Token::ADD: return "add-t";
149 case Token::SUB: return "sub-t";
150 case Token::MUL: return "mul-t";
151 case Token::MOD: return "mod-t";
152 case Token::DIV: return "div-t";
153 case Token::BIT_AND: return "bit-and-t";
154 case Token::BIT_OR: return "bit-or-t";
155 case Token::BIT_XOR: return "bit-xor-t";
156 case Token::ROR: return "ror-t";
157 case Token::SHL: return "sal-t";
158 case Token::SAR: return "sar-t";
159 case Token::SHR: return "shr-t";
167 bool LGoto::HasInterestingComment(LCodeGen* gen) const {
168 return !gen->IsNextEmittedBlock(block_id());
172 void LGoto::PrintDataTo(StringStream* stream) {
173 stream->Add("B%d", block_id());
177 void LBranch::PrintDataTo(StringStream* stream) {
178 stream->Add("B%d | B%d on ", true_block_id(), false_block_id());
179 value()->PrintTo(stream);
183 void LCompareNumericAndBranch::PrintDataTo(StringStream* stream) {
185 left()->PrintTo(stream);
186 stream->Add(" %s ", Token::String(op()));
187 right()->PrintTo(stream);
188 stream->Add(" then B%d else B%d", true_block_id(), false_block_id());
192 void LIsObjectAndBranch::PrintDataTo(StringStream* stream) {
193 stream->Add("if is_object(");
194 value()->PrintTo(stream);
195 stream->Add(") then B%d else B%d", true_block_id(), false_block_id());
199 void LIsStringAndBranch::PrintDataTo(StringStream* stream) {
200 stream->Add("if is_string(");
201 value()->PrintTo(stream);
202 stream->Add(") then B%d else B%d", true_block_id(), false_block_id());
206 void LIsSmiAndBranch::PrintDataTo(StringStream* stream) {
207 stream->Add("if is_smi(");
208 value()->PrintTo(stream);
209 stream->Add(") then B%d else B%d", true_block_id(), false_block_id());
213 void LIsUndetectableAndBranch::PrintDataTo(StringStream* stream) {
214 stream->Add("if is_undetectable(");
215 value()->PrintTo(stream);
216 stream->Add(") then B%d else B%d", true_block_id(), false_block_id());
220 void LStringCompareAndBranch::PrintDataTo(StringStream* stream) {
221 stream->Add("if string_compare(");
222 left()->PrintTo(stream);
223 right()->PrintTo(stream);
224 stream->Add(") then B%d else B%d", true_block_id(), false_block_id());
228 void LHasInstanceTypeAndBranch::PrintDataTo(StringStream* stream) {
229 stream->Add("if has_instance_type(");
230 value()->PrintTo(stream);
231 stream->Add(") then B%d else B%d", true_block_id(), false_block_id());
235 void LHasCachedArrayIndexAndBranch::PrintDataTo(StringStream* stream) {
236 stream->Add("if has_cached_array_index(");
237 value()->PrintTo(stream);
238 stream->Add(") then B%d else B%d", true_block_id(), false_block_id());
242 void LClassOfTestAndBranch::PrintDataTo(StringStream* stream) {
243 stream->Add("if class_of_test(");
244 value()->PrintTo(stream);
245 stream->Add(", \"%o\") then B%d else B%d",
246 *hydrogen()->class_name(),
252 void LTypeofIsAndBranch::PrintDataTo(StringStream* stream) {
253 stream->Add("if typeof ");
254 value()->PrintTo(stream);
255 stream->Add(" == \"%s\" then B%d else B%d",
256 hydrogen()->type_literal()->ToCString().get(),
257 true_block_id(), false_block_id());
261 void LStoreCodeEntry::PrintDataTo(StringStream* stream) {
263 function()->PrintTo(stream);
264 stream->Add(".code_entry = ");
265 code_object()->PrintTo(stream);
269 void LInnerAllocatedObject::PrintDataTo(StringStream* stream) {
271 base_object()->PrintTo(stream);
273 offset()->PrintTo(stream);
277 void LCallFunction::PrintDataTo(StringStream* stream) {
278 context()->PrintTo(stream);
280 function()->PrintTo(stream);
281 if (hydrogen()->HasVectorAndSlot()) {
282 stream->Add(" (type-feedback-vector ");
283 temp_vector()->PrintTo(stream);
285 temp_slot()->PrintTo(stream);
291 void LCallJSFunction::PrintDataTo(StringStream* stream) {
293 function()->PrintTo(stream);
294 stream->Add("#%d / ", arity());
298 void LCallWithDescriptor::PrintDataTo(StringStream* stream) {
299 for (int i = 0; i < InputCount(); i++) {
300 InputAt(i)->PrintTo(stream);
303 stream->Add("#%d / ", arity());
307 void LLoadContextSlot::PrintDataTo(StringStream* stream) {
308 context()->PrintTo(stream);
309 stream->Add("[%d]", slot_index());
313 void LStoreContextSlot::PrintDataTo(StringStream* stream) {
314 context()->PrintTo(stream);
315 stream->Add("[%d] <- ", slot_index());
316 value()->PrintTo(stream);
320 void LInvokeFunction::PrintDataTo(StringStream* stream) {
322 context()->PrintTo(stream);
324 function()->PrintTo(stream);
325 stream->Add(" #%d / ", arity());
329 void LCallNew::PrintDataTo(StringStream* stream) {
331 context()->PrintTo(stream);
333 constructor()->PrintTo(stream);
334 stream->Add(" #%d / ", arity());
338 void LCallNewArray::PrintDataTo(StringStream* stream) {
340 context()->PrintTo(stream);
342 constructor()->PrintTo(stream);
343 stream->Add(" #%d / ", arity());
344 ElementsKind kind = hydrogen()->elements_kind();
345 stream->Add(" (%s) ", ElementsKindToString(kind));
349 void LAccessArgumentsAt::PrintDataTo(StringStream* stream) {
350 arguments()->PrintTo(stream);
352 stream->Add(" length ");
353 length()->PrintTo(stream);
355 stream->Add(" index ");
356 index()->PrintTo(stream);
360 int LPlatformChunk::GetNextSpillIndex(RegisterKind kind) {
361 // Skip a slot if for a double-width slot.
362 if (kind == DOUBLE_REGISTERS) {
364 spill_slot_count_ |= 1;
367 return spill_slot_count_++;
371 LOperand* LPlatformChunk::GetNextSpillSlot(RegisterKind kind) {
372 int index = GetNextSpillIndex(kind);
373 if (kind == DOUBLE_REGISTERS) {
374 return LDoubleStackSlot::Create(index, zone());
376 DCHECK(kind == GENERAL_REGISTERS);
377 return LStackSlot::Create(index, zone());
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 LLoadKeyed::PrintDataTo(StringStream* stream) {
401 elements()->PrintTo(stream);
403 key()->PrintTo(stream);
404 if (hydrogen()->IsDehoisted()) {
405 stream->Add(" + %d]", base_offset());
412 void LStoreKeyed::PrintDataTo(StringStream* stream) {
413 elements()->PrintTo(stream);
415 key()->PrintTo(stream);
416 if (hydrogen()->IsDehoisted()) {
417 stream->Add(" + %d] <-", base_offset());
419 stream->Add("] <- ");
422 if (value() == NULL) {
423 DCHECK(hydrogen()->IsConstantHoleStore() &&
424 hydrogen()->value()->representation().IsDouble());
425 stream->Add("<the hole(nan)>");
427 value()->PrintTo(stream);
432 void LStoreKeyedGeneric::PrintDataTo(StringStream* stream) {
433 object()->PrintTo(stream);
435 key()->PrintTo(stream);
436 stream->Add("] <- ");
437 value()->PrintTo(stream);
441 void LTransitionElementsKind::PrintDataTo(StringStream* stream) {
442 object()->PrintTo(stream);
443 stream->Add(" %p -> %p", *original_map(), *transitioned_map());
447 LPlatformChunk* LChunkBuilder::Build() {
449 chunk_ = new(zone()) LPlatformChunk(info(), graph());
450 LPhase phase("L_Building chunk", chunk_);
453 // Reserve the first spill slot for the state of dynamic alignment.
454 if (info()->IsOptimizing()) {
455 int alignment_state_index = chunk_->GetNextSpillIndex(GENERAL_REGISTERS);
456 DCHECK_EQ(alignment_state_index, 0);
457 USE(alignment_state_index);
460 // If compiling for OSR, reserve space for the unoptimized frame,
461 // which will be subsumed into this frame.
462 if (graph()->has_osr()) {
463 for (int i = graph()->osr()->UnoptimizedFrameSlots(); i > 0; i--) {
464 chunk_->GetNextSpillIndex(GENERAL_REGISTERS);
468 const ZoneList<HBasicBlock*>* blocks = graph()->blocks();
469 for (int i = 0; i < blocks->length(); i++) {
470 HBasicBlock* next = NULL;
471 if (i < blocks->length() - 1) next = blocks->at(i + 1);
472 DoBasicBlock(blocks->at(i), next);
473 if (is_aborted()) return NULL;
480 LUnallocated* LChunkBuilder::ToUnallocated(Register reg) {
481 return new(zone()) LUnallocated(LUnallocated::FIXED_REGISTER,
482 Register::ToAllocationIndex(reg));
486 LUnallocated* LChunkBuilder::ToUnallocated(XMMRegister reg) {
487 return new(zone()) LUnallocated(LUnallocated::FIXED_DOUBLE_REGISTER,
488 XMMRegister::ToAllocationIndex(reg));
492 LOperand* LChunkBuilder::UseFixed(HValue* value, Register fixed_register) {
493 return Use(value, ToUnallocated(fixed_register));
497 LOperand* LChunkBuilder::UseFixedDouble(HValue* value, XMMRegister reg) {
498 return Use(value, ToUnallocated(reg));
502 LOperand* LChunkBuilder::UseRegister(HValue* value) {
503 return Use(value, new(zone()) LUnallocated(LUnallocated::MUST_HAVE_REGISTER));
507 LOperand* LChunkBuilder::UseRegisterAtStart(HValue* value) {
509 new(zone()) LUnallocated(LUnallocated::MUST_HAVE_REGISTER,
510 LUnallocated::USED_AT_START));
514 LOperand* LChunkBuilder::UseTempRegister(HValue* value) {
515 return Use(value, new(zone()) LUnallocated(LUnallocated::WRITABLE_REGISTER));
519 LOperand* LChunkBuilder::Use(HValue* value) {
520 return Use(value, new(zone()) LUnallocated(LUnallocated::NONE));
524 LOperand* LChunkBuilder::UseAtStart(HValue* value) {
525 return Use(value, new(zone()) LUnallocated(LUnallocated::NONE,
526 LUnallocated::USED_AT_START));
530 static inline bool CanBeImmediateConstant(HValue* value) {
531 return value->IsConstant() && HConstant::cast(value)->NotInNewSpace();
535 LOperand* LChunkBuilder::UseOrConstant(HValue* value) {
536 return CanBeImmediateConstant(value)
537 ? chunk_->DefineConstantOperand(HConstant::cast(value))
542 LOperand* LChunkBuilder::UseOrConstantAtStart(HValue* value) {
543 return CanBeImmediateConstant(value)
544 ? chunk_->DefineConstantOperand(HConstant::cast(value))
549 LOperand* LChunkBuilder::UseFixedOrConstant(HValue* value,
550 Register fixed_register) {
551 return CanBeImmediateConstant(value)
552 ? chunk_->DefineConstantOperand(HConstant::cast(value))
553 : UseFixed(value, fixed_register);
557 LOperand* LChunkBuilder::UseRegisterOrConstant(HValue* value) {
558 return CanBeImmediateConstant(value)
559 ? chunk_->DefineConstantOperand(HConstant::cast(value))
560 : UseRegister(value);
564 LOperand* LChunkBuilder::UseRegisterOrConstantAtStart(HValue* value) {
565 return CanBeImmediateConstant(value)
566 ? chunk_->DefineConstantOperand(HConstant::cast(value))
567 : UseRegisterAtStart(value);
571 LOperand* LChunkBuilder::UseConstant(HValue* value) {
572 return chunk_->DefineConstantOperand(HConstant::cast(value));
576 LOperand* LChunkBuilder::UseAny(HValue* value) {
577 return value->IsConstant()
578 ? chunk_->DefineConstantOperand(HConstant::cast(value))
579 : Use(value, new(zone()) LUnallocated(LUnallocated::ANY));
583 LOperand* LChunkBuilder::Use(HValue* value, LUnallocated* operand) {
584 if (value->EmitAtUses()) {
585 HInstruction* instr = HInstruction::cast(value);
586 VisitInstruction(instr);
588 operand->set_virtual_register(value->id());
593 LInstruction* LChunkBuilder::Define(LTemplateResultInstruction<1>* instr,
594 LUnallocated* result) {
595 result->set_virtual_register(current_instruction_->id());
596 instr->set_result(result);
601 LInstruction* LChunkBuilder::DefineAsRegister(
602 LTemplateResultInstruction<1>* instr) {
604 new(zone()) LUnallocated(LUnallocated::MUST_HAVE_REGISTER));
608 LInstruction* LChunkBuilder::DefineAsSpilled(
609 LTemplateResultInstruction<1>* instr,
612 new(zone()) LUnallocated(LUnallocated::FIXED_SLOT, index));
616 LInstruction* LChunkBuilder::DefineSameAsFirst(
617 LTemplateResultInstruction<1>* instr) {
619 new(zone()) LUnallocated(LUnallocated::SAME_AS_FIRST_INPUT));
623 LInstruction* LChunkBuilder::DefineFixed(LTemplateResultInstruction<1>* instr,
625 return Define(instr, ToUnallocated(reg));
629 LInstruction* LChunkBuilder::DefineFixedDouble(
630 LTemplateResultInstruction<1>* instr,
632 return Define(instr, ToUnallocated(reg));
636 LInstruction* LChunkBuilder::AssignEnvironment(LInstruction* instr) {
637 HEnvironment* hydrogen_env = current_block_->last_environment();
638 int argument_index_accumulator = 0;
639 ZoneList<HValue*> objects_to_materialize(0, zone());
640 instr->set_environment(CreateEnvironment(
641 hydrogen_env, &argument_index_accumulator, &objects_to_materialize));
646 LInstruction* LChunkBuilder::MarkAsCall(LInstruction* instr,
647 HInstruction* hinstr,
648 CanDeoptimize can_deoptimize) {
649 info()->MarkAsNonDeferredCalling();
655 instr = AssignPointerMap(instr);
657 // If instruction does not have side-effects lazy deoptimization
658 // after the call will try to deoptimize to the point before the call.
659 // Thus we still need to attach environment to this call even if
660 // call sequence can not deoptimize eagerly.
661 bool needs_environment =
662 (can_deoptimize == CAN_DEOPTIMIZE_EAGERLY) ||
663 !hinstr->HasObservableSideEffects();
664 if (needs_environment && !instr->HasEnvironment()) {
665 instr = AssignEnvironment(instr);
666 // We can't really figure out if the environment is needed or not.
667 instr->environment()->set_has_been_used();
674 LInstruction* LChunkBuilder::AssignPointerMap(LInstruction* instr) {
675 DCHECK(!instr->HasPointerMap());
676 instr->set_pointer_map(new(zone()) LPointerMap(zone()));
681 LUnallocated* LChunkBuilder::TempRegister() {
682 LUnallocated* operand =
683 new(zone()) LUnallocated(LUnallocated::MUST_HAVE_REGISTER);
684 int vreg = allocator_->GetVirtualRegister();
685 if (!allocator_->AllocationOk()) {
686 Abort(kOutOfVirtualRegistersWhileTryingToAllocateTempRegister);
689 operand->set_virtual_register(vreg);
694 LOperand* LChunkBuilder::FixedTemp(Register reg) {
695 LUnallocated* operand = ToUnallocated(reg);
696 DCHECK(operand->HasFixedPolicy());
701 LOperand* LChunkBuilder::FixedTemp(XMMRegister reg) {
702 LUnallocated* operand = ToUnallocated(reg);
703 DCHECK(operand->HasFixedPolicy());
708 LInstruction* LChunkBuilder::DoBlockEntry(HBlockEntry* instr) {
709 return new(zone()) LLabel(instr->block());
713 LInstruction* LChunkBuilder::DoDummyUse(HDummyUse* instr) {
714 return DefineAsRegister(new(zone()) LDummyUse(UseAny(instr->value())));
718 LInstruction* LChunkBuilder::DoEnvironmentMarker(HEnvironmentMarker* instr) {
724 LInstruction* LChunkBuilder::DoDeoptimize(HDeoptimize* instr) {
725 return AssignEnvironment(new(zone()) LDeoptimize);
729 LInstruction* LChunkBuilder::DoShift(Token::Value op,
730 HBitwiseBinaryOperation* instr) {
731 if (instr->representation().IsSmiOrInteger32()) {
732 DCHECK(instr->left()->representation().Equals(instr->representation()));
733 DCHECK(instr->right()->representation().Equals(instr->representation()));
734 LOperand* left = UseRegisterAtStart(instr->left());
736 HValue* right_value = instr->right();
737 LOperand* right = NULL;
738 int constant_value = 0;
739 bool does_deopt = false;
740 if (right_value->IsConstant()) {
741 HConstant* constant = HConstant::cast(right_value);
742 right = chunk_->DefineConstantOperand(constant);
743 constant_value = constant->Integer32Value() & 0x1f;
744 // Left shifts can deoptimize if we shift by > 0 and the result cannot be
746 if (instr->representation().IsSmi() && constant_value > 0) {
747 does_deopt = !instr->CheckUsesForFlag(HValue::kTruncatingToSmi);
750 right = UseFixed(right_value, ecx);
753 // Shift operations can only deoptimize if we do a logical shift by 0 and
754 // the result cannot be truncated to int32.
755 if (op == Token::SHR && constant_value == 0) {
756 does_deopt = !instr->CheckFlag(HInstruction::kUint32);
759 LInstruction* result =
760 DefineSameAsFirst(new(zone()) LShiftI(op, left, right, does_deopt));
761 return does_deopt ? AssignEnvironment(result) : result;
763 return DoArithmeticT(op, instr);
768 LInstruction* LChunkBuilder::DoArithmeticD(Token::Value op,
769 HArithmeticBinaryOperation* instr) {
770 DCHECK(instr->representation().IsDouble());
771 DCHECK(instr->left()->representation().IsDouble());
772 DCHECK(instr->right()->representation().IsDouble());
773 if (op == Token::MOD) {
774 LOperand* left = UseRegisterAtStart(instr->BetterLeftOperand());
775 LOperand* right = UseRegisterAtStart(instr->BetterRightOperand());
776 LArithmeticD* result = new(zone()) LArithmeticD(op, left, right);
777 return MarkAsCall(DefineSameAsFirst(result), instr);
779 LOperand* left = UseRegisterAtStart(instr->BetterLeftOperand());
780 LOperand* right = UseRegisterAtStart(instr->BetterRightOperand());
781 LArithmeticD* result = new(zone()) LArithmeticD(op, left, right);
782 return CpuFeatures::IsSupported(AVX) ? DefineAsRegister(result)
783 : DefineSameAsFirst(result);
788 LInstruction* LChunkBuilder::DoArithmeticT(Token::Value op,
789 HBinaryOperation* instr) {
790 HValue* left = instr->left();
791 HValue* right = instr->right();
792 DCHECK(left->representation().IsTagged());
793 DCHECK(right->representation().IsTagged());
794 LOperand* context = UseFixed(instr->context(), esi);
795 LOperand* left_operand = UseFixed(left, edx);
796 LOperand* right_operand = UseFixed(right, eax);
797 LArithmeticT* result =
798 new(zone()) LArithmeticT(op, context, left_operand, right_operand);
799 return MarkAsCall(DefineFixed(result, eax), instr);
803 void LChunkBuilder::DoBasicBlock(HBasicBlock* block, HBasicBlock* next_block) {
804 DCHECK(is_building());
805 current_block_ = block;
806 next_block_ = next_block;
807 if (block->IsStartBlock()) {
808 block->UpdateEnvironment(graph_->start_environment());
810 } else if (block->predecessors()->length() == 1) {
811 // We have a single predecessor => copy environment and outgoing
812 // argument count from the predecessor.
813 DCHECK(block->phis()->length() == 0);
814 HBasicBlock* pred = block->predecessors()->at(0);
815 HEnvironment* last_environment = pred->last_environment();
816 DCHECK(last_environment != NULL);
817 // Only copy the environment, if it is later used again.
818 if (pred->end()->SecondSuccessor() == NULL) {
819 DCHECK(pred->end()->FirstSuccessor() == block);
821 if (pred->end()->FirstSuccessor()->block_id() > block->block_id() ||
822 pred->end()->SecondSuccessor()->block_id() > block->block_id()) {
823 last_environment = last_environment->Copy();
826 block->UpdateEnvironment(last_environment);
827 DCHECK(pred->argument_count() >= 0);
828 argument_count_ = pred->argument_count();
830 // We are at a state join => process phis.
831 HBasicBlock* pred = block->predecessors()->at(0);
832 // No need to copy the environment, it cannot be used later.
833 HEnvironment* last_environment = pred->last_environment();
834 for (int i = 0; i < block->phis()->length(); ++i) {
835 HPhi* phi = block->phis()->at(i);
836 if (phi->HasMergedIndex()) {
837 last_environment->SetValueAt(phi->merged_index(), phi);
840 for (int i = 0; i < block->deleted_phis()->length(); ++i) {
841 if (block->deleted_phis()->at(i) < last_environment->length()) {
842 last_environment->SetValueAt(block->deleted_phis()->at(i),
843 graph_->GetConstantUndefined());
846 block->UpdateEnvironment(last_environment);
847 // Pick up the outgoing argument count of one of the predecessors.
848 argument_count_ = pred->argument_count();
850 HInstruction* current = block->first();
851 int start = chunk_->instructions()->length();
852 while (current != NULL && !is_aborted()) {
853 // Code for constants in registers is generated lazily.
854 if (!current->EmitAtUses()) {
855 VisitInstruction(current);
857 current = current->next();
859 int end = chunk_->instructions()->length() - 1;
861 block->set_first_instruction_index(start);
862 block->set_last_instruction_index(end);
864 block->set_argument_count(argument_count_);
866 current_block_ = NULL;
870 void LChunkBuilder::VisitInstruction(HInstruction* current) {
871 HInstruction* old_current = current_instruction_;
872 current_instruction_ = current;
874 LInstruction* instr = NULL;
875 if (current->CanReplaceWithDummyUses()) {
876 if (current->OperandCount() == 0) {
877 instr = DefineAsRegister(new(zone()) LDummy());
879 DCHECK(!current->OperandAt(0)->IsControlInstruction());
880 instr = DefineAsRegister(new(zone())
881 LDummyUse(UseAny(current->OperandAt(0))));
883 for (int i = 1; i < current->OperandCount(); ++i) {
884 if (current->OperandAt(i)->IsControlInstruction()) continue;
885 LInstruction* dummy =
886 new(zone()) LDummyUse(UseAny(current->OperandAt(i)));
887 dummy->set_hydrogen_value(current);
888 chunk_->AddInstruction(dummy, current_block_);
891 HBasicBlock* successor;
892 if (current->IsControlInstruction() &&
893 HControlInstruction::cast(current)->KnownSuccessorBlock(&successor) &&
895 instr = new(zone()) LGoto(successor);
897 instr = current->CompileToLithium(this);
901 argument_count_ += current->argument_delta();
902 DCHECK(argument_count_ >= 0);
905 AddInstruction(instr, current);
908 current_instruction_ = old_current;
912 void LChunkBuilder::AddInstruction(LInstruction* instr,
913 HInstruction* hydrogen_val) {
914 // Associate the hydrogen instruction first, since we may need it for
915 // the ClobbersRegisters() or ClobbersDoubleRegisters() calls below.
916 instr->set_hydrogen_value(hydrogen_val);
919 // Make sure that the lithium instruction has either no fixed register
920 // constraints in temps or the result OR no uses that are only used at
921 // start. If this invariant doesn't hold, the register allocator can decide
922 // to insert a split of a range immediately before the instruction due to an
923 // already allocated register needing to be used for the instruction's fixed
924 // register constraint. In this case, The register allocator won't see an
925 // interference between the split child and the use-at-start (it would if
926 // the it was just a plain use), so it is free to move the split child into
927 // the same register that is used for the use-at-start.
928 // See https://code.google.com/p/chromium/issues/detail?id=201590
929 if (!(instr->ClobbersRegisters() &&
930 instr->ClobbersDoubleRegisters(isolate()))) {
932 int used_at_start = 0;
933 for (UseIterator it(instr); !it.Done(); it.Advance()) {
934 LUnallocated* operand = LUnallocated::cast(it.Current());
935 if (operand->IsUsedAtStart()) ++used_at_start;
937 if (instr->Output() != NULL) {
938 if (LUnallocated::cast(instr->Output())->HasFixedPolicy()) ++fixed;
940 for (TempIterator it(instr); !it.Done(); it.Advance()) {
941 LUnallocated* operand = LUnallocated::cast(it.Current());
942 if (operand->HasFixedPolicy()) ++fixed;
944 DCHECK(fixed == 0 || used_at_start == 0);
948 if (FLAG_stress_pointer_maps && !instr->HasPointerMap()) {
949 instr = AssignPointerMap(instr);
951 if (FLAG_stress_environments && !instr->HasEnvironment()) {
952 instr = AssignEnvironment(instr);
954 chunk_->AddInstruction(instr, current_block_);
956 if (instr->IsCall()) {
957 HValue* hydrogen_value_for_lazy_bailout = hydrogen_val;
958 LInstruction* instruction_needing_environment = NULL;
959 if (hydrogen_val->HasObservableSideEffects()) {
960 HSimulate* sim = HSimulate::cast(hydrogen_val->next());
961 instruction_needing_environment = instr;
962 sim->ReplayEnvironment(current_block_->last_environment());
963 hydrogen_value_for_lazy_bailout = sim;
965 LInstruction* bailout = AssignEnvironment(new(zone()) LLazyBailout());
966 bailout->set_hydrogen_value(hydrogen_value_for_lazy_bailout);
967 chunk_->AddInstruction(bailout, current_block_);
968 if (instruction_needing_environment != NULL) {
969 // Store the lazy deopt environment with the instruction if needed.
970 // Right now it is only used for LInstanceOfKnownGlobal.
971 instruction_needing_environment->
972 SetDeferredLazyDeoptimizationEnvironment(bailout->environment());
978 LInstruction* LChunkBuilder::DoGoto(HGoto* instr) {
979 return new(zone()) LGoto(instr->FirstSuccessor());
983 LInstruction* LChunkBuilder::DoBranch(HBranch* instr) {
984 HValue* value = instr->value();
985 Representation r = value->representation();
986 HType type = value->type();
987 ToBooleanStub::Types expected = instr->expected_input_types();
988 if (expected.IsEmpty()) expected = ToBooleanStub::Types::Generic();
990 bool easy_case = !r.IsTagged() || type.IsBoolean() || type.IsSmi() ||
991 type.IsJSArray() || type.IsHeapNumber() || type.IsString();
992 LOperand* temp = !easy_case && expected.NeedsMap() ? TempRegister() : NULL;
993 LInstruction* branch = new(zone()) LBranch(UseRegister(value), temp);
995 ((!expected.Contains(ToBooleanStub::SMI) && expected.NeedsMap()) ||
996 !expected.IsGeneric())) {
997 branch = AssignEnvironment(branch);
1003 LInstruction* LChunkBuilder::DoDebugBreak(HDebugBreak* instr) {
1004 return new(zone()) LDebugBreak();
1008 LInstruction* LChunkBuilder::DoCompareMap(HCompareMap* instr) {
1009 DCHECK(instr->value()->representation().IsTagged());
1010 LOperand* value = UseRegisterAtStart(instr->value());
1011 return new(zone()) LCmpMapAndBranch(value);
1015 LInstruction* LChunkBuilder::DoArgumentsLength(HArgumentsLength* length) {
1016 info()->MarkAsRequiresFrame();
1017 return DefineAsRegister(new(zone()) LArgumentsLength(Use(length->value())));
1021 LInstruction* LChunkBuilder::DoArgumentsElements(HArgumentsElements* elems) {
1022 info()->MarkAsRequiresFrame();
1023 return DefineAsRegister(new(zone()) LArgumentsElements);
1027 LInstruction* LChunkBuilder::DoInstanceOf(HInstanceOf* instr) {
1028 LOperand* left = UseFixed(instr->left(), InstanceofStub::left());
1029 LOperand* right = UseFixed(instr->right(), InstanceofStub::right());
1030 LOperand* context = UseFixed(instr->context(), esi);
1031 LInstanceOf* result = new(zone()) LInstanceOf(context, left, right);
1032 return MarkAsCall(DefineFixed(result, eax), instr);
1036 LInstruction* LChunkBuilder::DoInstanceOfKnownGlobal(
1037 HInstanceOfKnownGlobal* instr) {
1038 LInstanceOfKnownGlobal* result =
1039 new(zone()) LInstanceOfKnownGlobal(
1040 UseFixed(instr->context(), esi),
1041 UseFixed(instr->left(), InstanceofStub::left()),
1043 return MarkAsCall(DefineFixed(result, eax), instr);
1047 LInstruction* LChunkBuilder::DoWrapReceiver(HWrapReceiver* instr) {
1048 LOperand* receiver = UseRegister(instr->receiver());
1049 LOperand* function = UseRegister(instr->function());
1050 LOperand* temp = TempRegister();
1051 LWrapReceiver* result =
1052 new(zone()) LWrapReceiver(receiver, function, temp);
1053 return AssignEnvironment(DefineSameAsFirst(result));
1057 LInstruction* LChunkBuilder::DoApplyArguments(HApplyArguments* instr) {
1058 LOperand* function = UseFixed(instr->function(), edi);
1059 LOperand* receiver = UseFixed(instr->receiver(), eax);
1060 LOperand* length = UseFixed(instr->length(), ebx);
1061 LOperand* elements = UseFixed(instr->elements(), ecx);
1062 LApplyArguments* result = new(zone()) LApplyArguments(function,
1066 return MarkAsCall(DefineFixed(result, eax), instr, CAN_DEOPTIMIZE_EAGERLY);
1070 LInstruction* LChunkBuilder::DoPushArguments(HPushArguments* instr) {
1071 int argc = instr->OperandCount();
1072 for (int i = 0; i < argc; ++i) {
1073 LOperand* argument = UseAny(instr->argument(i));
1074 AddInstruction(new(zone()) LPushArgument(argument), instr);
1080 LInstruction* LChunkBuilder::DoStoreCodeEntry(
1081 HStoreCodeEntry* store_code_entry) {
1082 LOperand* function = UseRegister(store_code_entry->function());
1083 LOperand* code_object = UseTempRegister(store_code_entry->code_object());
1084 return new(zone()) LStoreCodeEntry(function, code_object);
1088 LInstruction* LChunkBuilder::DoInnerAllocatedObject(
1089 HInnerAllocatedObject* instr) {
1090 LOperand* base_object = UseRegisterAtStart(instr->base_object());
1091 LOperand* offset = UseRegisterOrConstantAtStart(instr->offset());
1092 return DefineAsRegister(
1093 new(zone()) LInnerAllocatedObject(base_object, offset));
1097 LInstruction* LChunkBuilder::DoThisFunction(HThisFunction* instr) {
1098 return instr->HasNoUses()
1100 : DefineAsRegister(new(zone()) LThisFunction);
1104 LInstruction* LChunkBuilder::DoContext(HContext* instr) {
1105 if (instr->HasNoUses()) return NULL;
1107 if (info()->IsStub()) {
1108 return DefineFixed(new(zone()) LContext, esi);
1111 return DefineAsRegister(new(zone()) LContext);
1115 LInstruction* LChunkBuilder::DoDeclareGlobals(HDeclareGlobals* instr) {
1116 LOperand* context = UseFixed(instr->context(), esi);
1117 return MarkAsCall(new(zone()) LDeclareGlobals(context), instr);
1121 LInstruction* LChunkBuilder::DoCallJSFunction(
1122 HCallJSFunction* instr) {
1123 LOperand* function = UseFixed(instr->function(), edi);
1125 LCallJSFunction* result = new(zone()) LCallJSFunction(function);
1127 return MarkAsCall(DefineFixed(result, eax), instr, CANNOT_DEOPTIMIZE_EAGERLY);
1131 LInstruction* LChunkBuilder::DoCallWithDescriptor(
1132 HCallWithDescriptor* instr) {
1133 CallInterfaceDescriptor descriptor = instr->descriptor();
1134 LOperand* target = UseRegisterOrConstantAtStart(instr->target());
1135 ZoneList<LOperand*> ops(instr->OperandCount(), zone());
1136 ops.Add(target, zone());
1137 for (int i = 1; i < instr->OperandCount(); i++) {
1139 UseFixed(instr->OperandAt(i), descriptor.GetParameterRegister(i - 1));
1140 ops.Add(op, zone());
1143 LCallWithDescriptor* result = new(zone()) LCallWithDescriptor(
1144 descriptor, ops, zone());
1145 return MarkAsCall(DefineFixed(result, eax), instr, CANNOT_DEOPTIMIZE_EAGERLY);
1149 LInstruction* LChunkBuilder::DoTailCallThroughMegamorphicCache(
1150 HTailCallThroughMegamorphicCache* instr) {
1151 LOperand* context = UseFixed(instr->context(), esi);
1152 LOperand* receiver_register =
1153 UseFixed(instr->receiver(), LoadDescriptor::ReceiverRegister());
1154 LOperand* name_register =
1155 UseFixed(instr->name(), LoadDescriptor::NameRegister());
1156 LOperand* slot = NULL;
1157 LOperand* vector = NULL;
1158 if (FLAG_vector_ics) {
1159 slot = UseFixed(instr->slot(), VectorLoadICDescriptor::SlotRegister());
1161 UseFixed(instr->vector(), VectorLoadICDescriptor::VectorRegister());
1164 // Not marked as call. It can't deoptimize, and it never returns.
1165 return new (zone()) LTailCallThroughMegamorphicCache(
1166 context, receiver_register, name_register, slot, vector);
1170 LInstruction* LChunkBuilder::DoInvokeFunction(HInvokeFunction* instr) {
1171 LOperand* context = UseFixed(instr->context(), esi);
1172 LOperand* function = UseFixed(instr->function(), edi);
1173 LInvokeFunction* result = new(zone()) LInvokeFunction(context, function);
1174 return MarkAsCall(DefineFixed(result, eax), instr, CANNOT_DEOPTIMIZE_EAGERLY);
1178 LInstruction* LChunkBuilder::DoUnaryMathOperation(HUnaryMathOperation* instr) {
1179 switch (instr->op()) {
1181 return DoMathFloor(instr);
1183 return DoMathRound(instr);
1185 return DoMathFround(instr);
1187 return DoMathAbs(instr);
1189 return DoMathLog(instr);
1191 return DoMathExp(instr);
1193 return DoMathSqrt(instr);
1195 return DoMathPowHalf(instr);
1197 return DoMathClz32(instr);
1205 LInstruction* LChunkBuilder::DoMathFloor(HUnaryMathOperation* instr) {
1206 LOperand* input = UseRegisterAtStart(instr->value());
1207 LMathFloor* result = new(zone()) LMathFloor(input);
1208 return AssignEnvironment(DefineAsRegister(result));
1212 LInstruction* LChunkBuilder::DoMathRound(HUnaryMathOperation* instr) {
1213 LOperand* input = UseRegister(instr->value());
1214 LOperand* temp = FixedTemp(xmm4);
1215 LMathRound* result = new(zone()) LMathRound(input, temp);
1216 return AssignEnvironment(DefineAsRegister(result));
1220 LInstruction* LChunkBuilder::DoMathFround(HUnaryMathOperation* instr) {
1221 LOperand* input = UseRegister(instr->value());
1222 LMathFround* result = new (zone()) LMathFround(input);
1223 return DefineAsRegister(result);
1227 LInstruction* LChunkBuilder::DoMathAbs(HUnaryMathOperation* instr) {
1228 LOperand* context = UseAny(instr->context()); // Deferred use.
1229 LOperand* input = UseRegisterAtStart(instr->value());
1230 LInstruction* result =
1231 DefineSameAsFirst(new(zone()) LMathAbs(context, input));
1232 Representation r = instr->value()->representation();
1233 if (!r.IsDouble() && !r.IsSmiOrInteger32()) result = AssignPointerMap(result);
1234 if (!r.IsDouble()) result = AssignEnvironment(result);
1239 LInstruction* LChunkBuilder::DoMathLog(HUnaryMathOperation* instr) {
1240 DCHECK(instr->representation().IsDouble());
1241 DCHECK(instr->value()->representation().IsDouble());
1242 LOperand* input = UseRegisterAtStart(instr->value());
1243 return MarkAsCall(DefineSameAsFirst(new(zone()) LMathLog(input)), instr);
1247 LInstruction* LChunkBuilder::DoMathClz32(HUnaryMathOperation* instr) {
1248 LOperand* input = UseRegisterAtStart(instr->value());
1249 LMathClz32* result = new(zone()) LMathClz32(input);
1250 return DefineAsRegister(result);
1254 LInstruction* LChunkBuilder::DoMathExp(HUnaryMathOperation* instr) {
1255 DCHECK(instr->representation().IsDouble());
1256 DCHECK(instr->value()->representation().IsDouble());
1257 LOperand* value = UseTempRegister(instr->value());
1258 LOperand* temp1 = TempRegister();
1259 LOperand* temp2 = TempRegister();
1260 LMathExp* result = new(zone()) LMathExp(value, temp1, temp2);
1261 return DefineAsRegister(result);
1265 LInstruction* LChunkBuilder::DoMathSqrt(HUnaryMathOperation* instr) {
1266 LOperand* input = UseAtStart(instr->value());
1267 return DefineAsRegister(new(zone()) LMathSqrt(input));
1271 LInstruction* LChunkBuilder::DoMathPowHalf(HUnaryMathOperation* instr) {
1272 LOperand* input = UseRegisterAtStart(instr->value());
1273 LOperand* temp = TempRegister();
1274 LMathPowHalf* result = new(zone()) LMathPowHalf(input, temp);
1275 return DefineSameAsFirst(result);
1279 LInstruction* LChunkBuilder::DoCallNew(HCallNew* instr) {
1280 LOperand* context = UseFixed(instr->context(), esi);
1281 LOperand* constructor = UseFixed(instr->constructor(), edi);
1282 LCallNew* result = new(zone()) LCallNew(context, constructor);
1283 return MarkAsCall(DefineFixed(result, eax), instr);
1287 LInstruction* LChunkBuilder::DoCallNewArray(HCallNewArray* instr) {
1288 LOperand* context = UseFixed(instr->context(), esi);
1289 LOperand* constructor = UseFixed(instr->constructor(), edi);
1290 LCallNewArray* result = new(zone()) LCallNewArray(context, constructor);
1291 return MarkAsCall(DefineFixed(result, eax), instr);
1295 LInstruction* LChunkBuilder::DoCallFunction(HCallFunction* instr) {
1296 LOperand* context = UseFixed(instr->context(), esi);
1297 LOperand* function = UseFixed(instr->function(), edi);
1298 LOperand* slot = NULL;
1299 LOperand* vector = NULL;
1300 if (instr->HasVectorAndSlot()) {
1301 slot = FixedTemp(edx);
1302 vector = FixedTemp(ebx);
1305 LCallFunction* call =
1306 new (zone()) LCallFunction(context, function, slot, vector);
1307 return MarkAsCall(DefineFixed(call, eax), instr);
1311 LInstruction* LChunkBuilder::DoCallRuntime(HCallRuntime* instr) {
1312 LOperand* context = UseFixed(instr->context(), esi);
1313 return MarkAsCall(DefineFixed(new(zone()) LCallRuntime(context), eax), instr);
1317 LInstruction* LChunkBuilder::DoRor(HRor* instr) {
1318 return DoShift(Token::ROR, instr);
1322 LInstruction* LChunkBuilder::DoShr(HShr* instr) {
1323 return DoShift(Token::SHR, instr);
1327 LInstruction* LChunkBuilder::DoSar(HSar* instr) {
1328 return DoShift(Token::SAR, instr);
1332 LInstruction* LChunkBuilder::DoShl(HShl* instr) {
1333 return DoShift(Token::SHL, instr);
1337 LInstruction* LChunkBuilder::DoBitwise(HBitwise* instr) {
1338 if (instr->representation().IsSmiOrInteger32()) {
1339 DCHECK(instr->left()->representation().Equals(instr->representation()));
1340 DCHECK(instr->right()->representation().Equals(instr->representation()));
1341 DCHECK(instr->CheckFlag(HValue::kTruncatingToInt32));
1343 LOperand* left = UseRegisterAtStart(instr->BetterLeftOperand());
1344 LOperand* right = UseOrConstantAtStart(instr->BetterRightOperand());
1345 return DefineSameAsFirst(new(zone()) LBitI(left, right));
1347 return DoArithmeticT(instr->op(), instr);
1352 LInstruction* LChunkBuilder::DoDivByPowerOf2I(HDiv* instr) {
1353 DCHECK(instr->representation().IsSmiOrInteger32());
1354 DCHECK(instr->left()->representation().Equals(instr->representation()));
1355 DCHECK(instr->right()->representation().Equals(instr->representation()));
1356 LOperand* dividend = UseRegister(instr->left());
1357 int32_t divisor = instr->right()->GetInteger32Constant();
1358 LInstruction* result = DefineAsRegister(new(zone()) LDivByPowerOf2I(
1359 dividend, divisor));
1360 if ((instr->CheckFlag(HValue::kBailoutOnMinusZero) && divisor < 0) ||
1361 (instr->CheckFlag(HValue::kCanOverflow) && divisor == -1) ||
1362 (!instr->CheckFlag(HInstruction::kAllUsesTruncatingToInt32) &&
1363 divisor != 1 && divisor != -1)) {
1364 result = AssignEnvironment(result);
1370 LInstruction* LChunkBuilder::DoDivByConstI(HDiv* instr) {
1371 DCHECK(instr->representation().IsInteger32());
1372 DCHECK(instr->left()->representation().Equals(instr->representation()));
1373 DCHECK(instr->right()->representation().Equals(instr->representation()));
1374 LOperand* dividend = UseRegister(instr->left());
1375 int32_t divisor = instr->right()->GetInteger32Constant();
1376 LOperand* temp1 = FixedTemp(eax);
1377 LOperand* temp2 = FixedTemp(edx);
1378 LInstruction* result = DefineFixed(new(zone()) LDivByConstI(
1379 dividend, divisor, temp1, temp2), edx);
1381 (instr->CheckFlag(HValue::kBailoutOnMinusZero) && divisor < 0) ||
1382 !instr->CheckFlag(HInstruction::kAllUsesTruncatingToInt32)) {
1383 result = AssignEnvironment(result);
1389 LInstruction* LChunkBuilder::DoDivI(HDiv* instr) {
1390 DCHECK(instr->representation().IsSmiOrInteger32());
1391 DCHECK(instr->left()->representation().Equals(instr->representation()));
1392 DCHECK(instr->right()->representation().Equals(instr->representation()));
1393 LOperand* dividend = UseFixed(instr->left(), eax);
1394 LOperand* divisor = UseRegister(instr->right());
1395 LOperand* temp = FixedTemp(edx);
1396 LInstruction* result = DefineFixed(new(zone()) LDivI(
1397 dividend, divisor, temp), eax);
1398 if (instr->CheckFlag(HValue::kCanBeDivByZero) ||
1399 instr->CheckFlag(HValue::kBailoutOnMinusZero) ||
1400 instr->CheckFlag(HValue::kCanOverflow) ||
1401 !instr->CheckFlag(HValue::kAllUsesTruncatingToInt32)) {
1402 result = AssignEnvironment(result);
1408 LInstruction* LChunkBuilder::DoDiv(HDiv* instr) {
1409 if (instr->representation().IsSmiOrInteger32()) {
1410 if (instr->RightIsPowerOf2()) {
1411 return DoDivByPowerOf2I(instr);
1412 } else if (instr->right()->IsConstant()) {
1413 return DoDivByConstI(instr);
1415 return DoDivI(instr);
1417 } else if (instr->representation().IsDouble()) {
1418 return DoArithmeticD(Token::DIV, instr);
1420 return DoArithmeticT(Token::DIV, instr);
1425 LInstruction* LChunkBuilder::DoFlooringDivByPowerOf2I(HMathFloorOfDiv* instr) {
1426 LOperand* dividend = UseRegisterAtStart(instr->left());
1427 int32_t divisor = instr->right()->GetInteger32Constant();
1428 LInstruction* result = DefineSameAsFirst(new(zone()) LFlooringDivByPowerOf2I(
1429 dividend, divisor));
1430 if ((instr->CheckFlag(HValue::kBailoutOnMinusZero) && divisor < 0) ||
1431 (instr->CheckFlag(HValue::kLeftCanBeMinInt) && divisor == -1)) {
1432 result = AssignEnvironment(result);
1438 LInstruction* LChunkBuilder::DoFlooringDivByConstI(HMathFloorOfDiv* instr) {
1439 DCHECK(instr->representation().IsInteger32());
1440 DCHECK(instr->left()->representation().Equals(instr->representation()));
1441 DCHECK(instr->right()->representation().Equals(instr->representation()));
1442 LOperand* dividend = UseRegister(instr->left());
1443 int32_t divisor = instr->right()->GetInteger32Constant();
1444 LOperand* temp1 = FixedTemp(eax);
1445 LOperand* temp2 = FixedTemp(edx);
1447 ((divisor > 0 && !instr->CheckFlag(HValue::kLeftCanBeNegative)) ||
1448 (divisor < 0 && !instr->CheckFlag(HValue::kLeftCanBePositive))) ?
1449 NULL : TempRegister();
1450 LInstruction* result =
1451 DefineFixed(new(zone()) LFlooringDivByConstI(dividend,
1458 (instr->CheckFlag(HValue::kBailoutOnMinusZero) && divisor < 0)) {
1459 result = AssignEnvironment(result);
1465 LInstruction* LChunkBuilder::DoFlooringDivI(HMathFloorOfDiv* instr) {
1466 DCHECK(instr->representation().IsSmiOrInteger32());
1467 DCHECK(instr->left()->representation().Equals(instr->representation()));
1468 DCHECK(instr->right()->representation().Equals(instr->representation()));
1469 LOperand* dividend = UseFixed(instr->left(), eax);
1470 LOperand* divisor = UseRegister(instr->right());
1471 LOperand* temp = FixedTemp(edx);
1472 LInstruction* result = DefineFixed(new(zone()) LFlooringDivI(
1473 dividend, divisor, temp), eax);
1474 if (instr->CheckFlag(HValue::kCanBeDivByZero) ||
1475 instr->CheckFlag(HValue::kBailoutOnMinusZero) ||
1476 instr->CheckFlag(HValue::kCanOverflow)) {
1477 result = AssignEnvironment(result);
1483 LInstruction* LChunkBuilder::DoMathFloorOfDiv(HMathFloorOfDiv* instr) {
1484 if (instr->RightIsPowerOf2()) {
1485 return DoFlooringDivByPowerOf2I(instr);
1486 } else if (instr->right()->IsConstant()) {
1487 return DoFlooringDivByConstI(instr);
1489 return DoFlooringDivI(instr);
1494 LInstruction* LChunkBuilder::DoModByPowerOf2I(HMod* instr) {
1495 DCHECK(instr->representation().IsSmiOrInteger32());
1496 DCHECK(instr->left()->representation().Equals(instr->representation()));
1497 DCHECK(instr->right()->representation().Equals(instr->representation()));
1498 LOperand* dividend = UseRegisterAtStart(instr->left());
1499 int32_t divisor = instr->right()->GetInteger32Constant();
1500 LInstruction* result = DefineSameAsFirst(new(zone()) LModByPowerOf2I(
1501 dividend, divisor));
1502 if (instr->CheckFlag(HValue::kLeftCanBeNegative) &&
1503 instr->CheckFlag(HValue::kBailoutOnMinusZero)) {
1504 result = AssignEnvironment(result);
1510 LInstruction* LChunkBuilder::DoModByConstI(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 = UseRegister(instr->left());
1515 int32_t divisor = instr->right()->GetInteger32Constant();
1516 LOperand* temp1 = FixedTemp(eax);
1517 LOperand* temp2 = FixedTemp(edx);
1518 LInstruction* result = DefineFixed(new(zone()) LModByConstI(
1519 dividend, divisor, temp1, temp2), eax);
1520 if (divisor == 0 || instr->CheckFlag(HValue::kBailoutOnMinusZero)) {
1521 result = AssignEnvironment(result);
1527 LInstruction* LChunkBuilder::DoModI(HMod* instr) {
1528 DCHECK(instr->representation().IsSmiOrInteger32());
1529 DCHECK(instr->left()->representation().Equals(instr->representation()));
1530 DCHECK(instr->right()->representation().Equals(instr->representation()));
1531 LOperand* dividend = UseFixed(instr->left(), eax);
1532 LOperand* divisor = UseRegister(instr->right());
1533 LOperand* temp = FixedTemp(edx);
1534 LInstruction* result = DefineFixed(new(zone()) LModI(
1535 dividend, divisor, temp), edx);
1536 if (instr->CheckFlag(HValue::kCanBeDivByZero) ||
1537 instr->CheckFlag(HValue::kBailoutOnMinusZero)) {
1538 result = AssignEnvironment(result);
1544 LInstruction* LChunkBuilder::DoMod(HMod* instr) {
1545 if (instr->representation().IsSmiOrInteger32()) {
1546 if (instr->RightIsPowerOf2()) {
1547 return DoModByPowerOf2I(instr);
1548 } else if (instr->right()->IsConstant()) {
1549 return DoModByConstI(instr);
1551 return DoModI(instr);
1553 } else if (instr->representation().IsDouble()) {
1554 return DoArithmeticD(Token::MOD, instr);
1556 return DoArithmeticT(Token::MOD, instr);
1561 LInstruction* LChunkBuilder::DoMul(HMul* instr) {
1562 if (instr->representation().IsSmiOrInteger32()) {
1563 DCHECK(instr->left()->representation().Equals(instr->representation()));
1564 DCHECK(instr->right()->representation().Equals(instr->representation()));
1565 LOperand* left = UseRegisterAtStart(instr->BetterLeftOperand());
1566 LOperand* right = UseOrConstant(instr->BetterRightOperand());
1567 LOperand* temp = NULL;
1568 if (instr->CheckFlag(HValue::kBailoutOnMinusZero)) {
1569 temp = TempRegister();
1571 LMulI* mul = new(zone()) LMulI(left, right, temp);
1572 if (instr->CheckFlag(HValue::kCanOverflow) ||
1573 instr->CheckFlag(HValue::kBailoutOnMinusZero)) {
1574 AssignEnvironment(mul);
1576 return DefineSameAsFirst(mul);
1577 } else if (instr->representation().IsDouble()) {
1578 return DoArithmeticD(Token::MUL, instr);
1580 return DoArithmeticT(Token::MUL, instr);
1585 LInstruction* LChunkBuilder::DoSub(HSub* instr) {
1586 if (instr->representation().IsSmiOrInteger32()) {
1587 DCHECK(instr->left()->representation().Equals(instr->representation()));
1588 DCHECK(instr->right()->representation().Equals(instr->representation()));
1589 LOperand* left = UseRegisterAtStart(instr->left());
1590 LOperand* right = UseOrConstantAtStart(instr->right());
1591 LSubI* sub = new(zone()) LSubI(left, right);
1592 LInstruction* result = DefineSameAsFirst(sub);
1593 if (instr->CheckFlag(HValue::kCanOverflow)) {
1594 result = AssignEnvironment(result);
1597 } else if (instr->representation().IsDouble()) {
1598 return DoArithmeticD(Token::SUB, instr);
1600 return DoArithmeticT(Token::SUB, instr);
1605 LInstruction* LChunkBuilder::DoAdd(HAdd* instr) {
1606 if (instr->representation().IsSmiOrInteger32()) {
1607 DCHECK(instr->left()->representation().Equals(instr->representation()));
1608 DCHECK(instr->right()->representation().Equals(instr->representation()));
1609 // Check to see if it would be advantageous to use an lea instruction rather
1610 // than an add. This is the case when no overflow check is needed and there
1611 // are multiple uses of the add's inputs, so using a 3-register add will
1612 // preserve all input values for later uses.
1613 bool use_lea = LAddI::UseLea(instr);
1614 LOperand* left = UseRegisterAtStart(instr->BetterLeftOperand());
1615 HValue* right_candidate = instr->BetterRightOperand();
1616 LOperand* right = use_lea
1617 ? UseRegisterOrConstantAtStart(right_candidate)
1618 : UseOrConstantAtStart(right_candidate);
1619 LAddI* add = new(zone()) LAddI(left, right);
1620 bool can_overflow = instr->CheckFlag(HValue::kCanOverflow);
1621 LInstruction* result = use_lea
1622 ? DefineAsRegister(add)
1623 : DefineSameAsFirst(add);
1625 result = AssignEnvironment(result);
1628 } else if (instr->representation().IsDouble()) {
1629 return DoArithmeticD(Token::ADD, instr);
1630 } else if (instr->representation().IsExternal()) {
1631 DCHECK(instr->left()->representation().IsExternal());
1632 DCHECK(instr->right()->representation().IsInteger32());
1633 DCHECK(!instr->CheckFlag(HValue::kCanOverflow));
1634 bool use_lea = LAddI::UseLea(instr);
1635 LOperand* left = UseRegisterAtStart(instr->left());
1636 HValue* right_candidate = instr->right();
1637 LOperand* right = use_lea
1638 ? UseRegisterOrConstantAtStart(right_candidate)
1639 : UseOrConstantAtStart(right_candidate);
1640 LAddI* add = new(zone()) LAddI(left, right);
1641 LInstruction* result = use_lea
1642 ? DefineAsRegister(add)
1643 : DefineSameAsFirst(add);
1646 return DoArithmeticT(Token::ADD, instr);
1651 LInstruction* LChunkBuilder::DoMathMinMax(HMathMinMax* instr) {
1652 LOperand* left = NULL;
1653 LOperand* right = NULL;
1654 if (instr->representation().IsSmiOrInteger32()) {
1655 DCHECK(instr->left()->representation().Equals(instr->representation()));
1656 DCHECK(instr->right()->representation().Equals(instr->representation()));
1657 left = UseRegisterAtStart(instr->BetterLeftOperand());
1658 right = UseOrConstantAtStart(instr->BetterRightOperand());
1660 DCHECK(instr->representation().IsDouble());
1661 DCHECK(instr->left()->representation().IsDouble());
1662 DCHECK(instr->right()->representation().IsDouble());
1663 left = UseRegisterAtStart(instr->left());
1664 right = UseRegisterAtStart(instr->right());
1666 LMathMinMax* minmax = new(zone()) LMathMinMax(left, right);
1667 return DefineSameAsFirst(minmax);
1671 LInstruction* LChunkBuilder::DoPower(HPower* instr) {
1672 DCHECK(instr->representation().IsDouble());
1673 // We call a C function for double power. It can't trigger a GC.
1674 // We need to use fixed result register for the call.
1675 Representation exponent_type = instr->right()->representation();
1676 DCHECK(instr->left()->representation().IsDouble());
1677 LOperand* left = UseFixedDouble(instr->left(), xmm2);
1679 exponent_type.IsDouble()
1680 ? UseFixedDouble(instr->right(), xmm1)
1681 : UseFixed(instr->right(), MathPowTaggedDescriptor::exponent());
1682 LPower* result = new(zone()) LPower(left, right);
1683 return MarkAsCall(DefineFixedDouble(result, xmm3), instr,
1684 CAN_DEOPTIMIZE_EAGERLY);
1688 LInstruction* LChunkBuilder::DoCompareGeneric(HCompareGeneric* instr) {
1689 DCHECK(instr->left()->representation().IsSmiOrTagged());
1690 DCHECK(instr->right()->representation().IsSmiOrTagged());
1691 LOperand* context = UseFixed(instr->context(), esi);
1692 LOperand* left = UseFixed(instr->left(), edx);
1693 LOperand* right = UseFixed(instr->right(), eax);
1694 LCmpT* result = new(zone()) LCmpT(context, left, right);
1695 return MarkAsCall(DefineFixed(result, eax), instr);
1699 LInstruction* LChunkBuilder::DoCompareNumericAndBranch(
1700 HCompareNumericAndBranch* instr) {
1701 Representation r = instr->representation();
1702 if (r.IsSmiOrInteger32()) {
1703 DCHECK(instr->left()->representation().Equals(r));
1704 DCHECK(instr->right()->representation().Equals(r));
1705 LOperand* left = UseRegisterOrConstantAtStart(instr->left());
1706 LOperand* right = UseOrConstantAtStart(instr->right());
1707 return new(zone()) LCompareNumericAndBranch(left, right);
1709 DCHECK(r.IsDouble());
1710 DCHECK(instr->left()->representation().IsDouble());
1711 DCHECK(instr->right()->representation().IsDouble());
1714 if (CanBeImmediateConstant(instr->left()) &&
1715 CanBeImmediateConstant(instr->right())) {
1716 // The code generator requires either both inputs to be constant
1717 // operands, or neither.
1718 left = UseConstant(instr->left());
1719 right = UseConstant(instr->right());
1721 left = UseRegisterAtStart(instr->left());
1722 right = UseRegisterAtStart(instr->right());
1724 return new(zone()) LCompareNumericAndBranch(left, right);
1729 LInstruction* LChunkBuilder::DoCompareObjectEqAndBranch(
1730 HCompareObjectEqAndBranch* instr) {
1731 LOperand* left = UseRegisterAtStart(instr->left());
1732 LOperand* right = UseOrConstantAtStart(instr->right());
1733 return new(zone()) LCmpObjectEqAndBranch(left, right);
1737 LInstruction* LChunkBuilder::DoCompareHoleAndBranch(
1738 HCompareHoleAndBranch* instr) {
1739 LOperand* value = UseRegisterAtStart(instr->value());
1740 return new(zone()) LCmpHoleAndBranch(value);
1744 LInstruction* LChunkBuilder::DoCompareMinusZeroAndBranch(
1745 HCompareMinusZeroAndBranch* instr) {
1746 LOperand* value = UseRegister(instr->value());
1747 LOperand* scratch = TempRegister();
1748 return new(zone()) LCompareMinusZeroAndBranch(value, scratch);
1752 LInstruction* LChunkBuilder::DoIsObjectAndBranch(HIsObjectAndBranch* instr) {
1753 DCHECK(instr->value()->representation().IsSmiOrTagged());
1754 LOperand* temp = TempRegister();
1755 return new(zone()) LIsObjectAndBranch(UseRegister(instr->value()), temp);
1759 LInstruction* LChunkBuilder::DoIsStringAndBranch(HIsStringAndBranch* instr) {
1760 DCHECK(instr->value()->representation().IsTagged());
1761 LOperand* temp = TempRegister();
1762 return new(zone()) LIsStringAndBranch(UseRegister(instr->value()), temp);
1766 LInstruction* LChunkBuilder::DoIsSmiAndBranch(HIsSmiAndBranch* instr) {
1767 DCHECK(instr->value()->representation().IsTagged());
1768 return new(zone()) LIsSmiAndBranch(Use(instr->value()));
1772 LInstruction* LChunkBuilder::DoIsUndetectableAndBranch(
1773 HIsUndetectableAndBranch* instr) {
1774 DCHECK(instr->value()->representation().IsTagged());
1775 return new(zone()) LIsUndetectableAndBranch(
1776 UseRegisterAtStart(instr->value()), TempRegister());
1780 LInstruction* LChunkBuilder::DoStringCompareAndBranch(
1781 HStringCompareAndBranch* instr) {
1782 DCHECK(instr->left()->representation().IsTagged());
1783 DCHECK(instr->right()->representation().IsTagged());
1784 LOperand* context = UseFixed(instr->context(), esi);
1785 LOperand* left = UseFixed(instr->left(), edx);
1786 LOperand* right = UseFixed(instr->right(), eax);
1788 LStringCompareAndBranch* result = new(zone())
1789 LStringCompareAndBranch(context, left, right);
1791 return MarkAsCall(result, instr);
1795 LInstruction* LChunkBuilder::DoHasInstanceTypeAndBranch(
1796 HHasInstanceTypeAndBranch* instr) {
1797 DCHECK(instr->value()->representation().IsTagged());
1798 return new(zone()) LHasInstanceTypeAndBranch(
1799 UseRegisterAtStart(instr->value()),
1804 LInstruction* LChunkBuilder::DoGetCachedArrayIndex(
1805 HGetCachedArrayIndex* instr) {
1806 DCHECK(instr->value()->representation().IsTagged());
1807 LOperand* value = UseRegisterAtStart(instr->value());
1809 return DefineAsRegister(new(zone()) LGetCachedArrayIndex(value));
1813 LInstruction* LChunkBuilder::DoHasCachedArrayIndexAndBranch(
1814 HHasCachedArrayIndexAndBranch* instr) {
1815 DCHECK(instr->value()->representation().IsTagged());
1816 return new(zone()) LHasCachedArrayIndexAndBranch(
1817 UseRegisterAtStart(instr->value()));
1821 LInstruction* LChunkBuilder::DoClassOfTestAndBranch(
1822 HClassOfTestAndBranch* instr) {
1823 DCHECK(instr->value()->representation().IsTagged());
1824 return new(zone()) LClassOfTestAndBranch(UseRegister(instr->value()),
1830 LInstruction* LChunkBuilder::DoMapEnumLength(HMapEnumLength* instr) {
1831 LOperand* map = UseRegisterAtStart(instr->value());
1832 return DefineAsRegister(new(zone()) LMapEnumLength(map));
1836 LInstruction* LChunkBuilder::DoDateField(HDateField* instr) {
1837 LOperand* date = UseFixed(instr->value(), eax);
1838 LDateField* result =
1839 new(zone()) LDateField(date, FixedTemp(ecx), instr->index());
1840 return MarkAsCall(DefineFixed(result, eax), instr, CAN_DEOPTIMIZE_EAGERLY);
1844 LInstruction* LChunkBuilder::DoSeqStringGetChar(HSeqStringGetChar* instr) {
1845 LOperand* string = UseRegisterAtStart(instr->string());
1846 LOperand* index = UseRegisterOrConstantAtStart(instr->index());
1847 return DefineAsRegister(new(zone()) LSeqStringGetChar(string, index));
1851 LOperand* LChunkBuilder::GetSeqStringSetCharOperand(HSeqStringSetChar* instr) {
1852 if (instr->encoding() == String::ONE_BYTE_ENCODING) {
1853 if (FLAG_debug_code) {
1854 return UseFixed(instr->value(), eax);
1856 return UseFixedOrConstant(instr->value(), eax);
1859 if (FLAG_debug_code) {
1860 return UseRegisterAtStart(instr->value());
1862 return UseRegisterOrConstantAtStart(instr->value());
1868 LInstruction* LChunkBuilder::DoSeqStringSetChar(HSeqStringSetChar* instr) {
1869 LOperand* string = UseRegisterAtStart(instr->string());
1870 LOperand* index = FLAG_debug_code
1871 ? UseRegisterAtStart(instr->index())
1872 : UseRegisterOrConstantAtStart(instr->index());
1873 LOperand* value = GetSeqStringSetCharOperand(instr);
1874 LOperand* context = FLAG_debug_code ? UseFixed(instr->context(), esi) : NULL;
1875 LInstruction* result = new(zone()) LSeqStringSetChar(context, string,
1877 if (FLAG_debug_code) {
1878 result = MarkAsCall(result, instr);
1884 LInstruction* LChunkBuilder::DoBoundsCheck(HBoundsCheck* instr) {
1885 if (!FLAG_debug_code && instr->skip_check()) return NULL;
1886 LOperand* index = UseRegisterOrConstantAtStart(instr->index());
1887 LOperand* length = !index->IsConstantOperand()
1888 ? UseOrConstantAtStart(instr->length())
1889 : UseAtStart(instr->length());
1890 LInstruction* result = new(zone()) LBoundsCheck(index, length);
1891 if (!FLAG_debug_code || !instr->skip_check()) {
1892 result = AssignEnvironment(result);
1898 LInstruction* LChunkBuilder::DoBoundsCheckBaseIndexInformation(
1899 HBoundsCheckBaseIndexInformation* instr) {
1905 LInstruction* LChunkBuilder::DoAbnormalExit(HAbnormalExit* instr) {
1906 // The control instruction marking the end of a block that completed
1907 // abruptly (e.g., threw an exception). There is nothing specific to do.
1912 LInstruction* LChunkBuilder::DoUseConst(HUseConst* instr) {
1917 LInstruction* LChunkBuilder::DoForceRepresentation(HForceRepresentation* bad) {
1918 // All HForceRepresentation instructions should be eliminated in the
1919 // representation change phase of Hydrogen.
1925 LInstruction* LChunkBuilder::DoChange(HChange* instr) {
1926 Representation from = instr->from();
1927 Representation to = instr->to();
1928 HValue* val = instr->value();
1930 if (to.IsTagged()) {
1931 LOperand* value = UseRegister(val);
1932 return DefineSameAsFirst(new(zone()) LDummyUse(value));
1934 from = Representation::Tagged();
1936 if (from.IsTagged()) {
1937 if (to.IsDouble()) {
1938 LOperand* value = UseRegister(val);
1939 LOperand* temp = TempRegister();
1940 LInstruction* result =
1941 DefineAsRegister(new(zone()) LNumberUntagD(value, temp));
1942 if (!val->representation().IsSmi()) result = AssignEnvironment(result);
1944 } else if (to.IsSmi()) {
1945 LOperand* value = UseRegister(val);
1946 if (val->type().IsSmi()) {
1947 return DefineSameAsFirst(new(zone()) LDummyUse(value));
1949 return AssignEnvironment(DefineSameAsFirst(new(zone()) LCheckSmi(value)));
1951 DCHECK(to.IsInteger32());
1952 if (val->type().IsSmi() || val->representation().IsSmi()) {
1953 LOperand* value = UseRegister(val);
1954 return DefineSameAsFirst(new(zone()) LSmiUntag(value, false));
1956 LOperand* value = UseRegister(val);
1957 bool truncating = instr->CanTruncateToInt32();
1958 LOperand* xmm_temp = !truncating ? FixedTemp(xmm1) : NULL;
1959 LInstruction* result =
1960 DefineSameAsFirst(new(zone()) LTaggedToI(value, xmm_temp));
1961 if (!val->representation().IsSmi()) result = AssignEnvironment(result);
1965 } else if (from.IsDouble()) {
1966 if (to.IsTagged()) {
1967 info()->MarkAsDeferredCalling();
1968 LOperand* value = UseRegisterAtStart(val);
1969 LOperand* temp = FLAG_inline_new ? TempRegister() : NULL;
1970 LUnallocated* result_temp = TempRegister();
1971 LNumberTagD* result = new(zone()) LNumberTagD(value, temp);
1972 return AssignPointerMap(Define(result, result_temp));
1973 } else if (to.IsSmi()) {
1974 LOperand* value = UseRegister(val);
1975 return AssignEnvironment(
1976 DefineAsRegister(new(zone()) LDoubleToSmi(value)));
1978 DCHECK(to.IsInteger32());
1979 bool truncating = instr->CanTruncateToInt32();
1980 bool needs_temp = !truncating;
1981 LOperand* value = needs_temp ? UseTempRegister(val) : UseRegister(val);
1982 LOperand* temp = needs_temp ? TempRegister() : NULL;
1983 LInstruction* result =
1984 DefineAsRegister(new(zone()) LDoubleToI(value, temp));
1985 if (!truncating) result = AssignEnvironment(result);
1988 } else if (from.IsInteger32()) {
1989 info()->MarkAsDeferredCalling();
1990 if (to.IsTagged()) {
1991 LOperand* value = UseRegister(val);
1992 if (!instr->CheckFlag(HValue::kCanOverflow)) {
1993 return DefineSameAsFirst(new(zone()) LSmiTag(value));
1994 } else if (val->CheckFlag(HInstruction::kUint32)) {
1995 LOperand* temp = TempRegister();
1996 LNumberTagU* result = new(zone()) LNumberTagU(value, temp);
1997 return AssignPointerMap(DefineSameAsFirst(result));
1999 LOperand* temp = TempRegister();
2000 LNumberTagI* result = new(zone()) LNumberTagI(value, temp);
2001 return AssignPointerMap(DefineSameAsFirst(result));
2003 } else if (to.IsSmi()) {
2004 LOperand* value = UseRegister(val);
2005 LInstruction* result = DefineSameAsFirst(new(zone()) LSmiTag(value));
2006 if (instr->CheckFlag(HValue::kCanOverflow)) {
2007 result = AssignEnvironment(result);
2011 DCHECK(to.IsDouble());
2012 if (val->CheckFlag(HInstruction::kUint32)) {
2013 return DefineAsRegister(new(zone()) LUint32ToDouble(UseRegister(val)));
2015 return DefineAsRegister(new(zone()) LInteger32ToDouble(Use(val)));
2024 LInstruction* LChunkBuilder::DoCheckHeapObject(HCheckHeapObject* instr) {
2025 LOperand* value = UseAtStart(instr->value());
2026 LInstruction* result = new(zone()) LCheckNonSmi(value);
2027 if (!instr->value()->type().IsHeapObject()) {
2028 result = AssignEnvironment(result);
2034 LInstruction* LChunkBuilder::DoCheckSmi(HCheckSmi* instr) {
2035 LOperand* value = UseRegisterAtStart(instr->value());
2036 return AssignEnvironment(new(zone()) LCheckSmi(value));
2040 LInstruction* LChunkBuilder::DoCheckInstanceType(HCheckInstanceType* instr) {
2041 LOperand* value = UseRegisterAtStart(instr->value());
2042 LOperand* temp = TempRegister();
2043 LCheckInstanceType* result = new(zone()) LCheckInstanceType(value, temp);
2044 return AssignEnvironment(result);
2048 LInstruction* LChunkBuilder::DoCheckValue(HCheckValue* instr) {
2049 // If the object is in new space, we'll emit a global cell compare and so
2050 // want the value in a register. If the object gets promoted before we
2051 // emit code, we will still get the register but will do an immediate
2052 // compare instead of the cell compare. This is safe.
2053 LOperand* value = instr->object_in_new_space()
2054 ? UseRegisterAtStart(instr->value()) : UseAtStart(instr->value());
2055 return AssignEnvironment(new(zone()) LCheckValue(value));
2059 LInstruction* LChunkBuilder::DoCheckMaps(HCheckMaps* instr) {
2060 if (instr->IsStabilityCheck()) return new(zone()) LCheckMaps;
2061 LOperand* value = UseRegisterAtStart(instr->value());
2062 LInstruction* result = AssignEnvironment(new(zone()) LCheckMaps(value));
2063 if (instr->HasMigrationTarget()) {
2064 info()->MarkAsDeferredCalling();
2065 result = AssignPointerMap(result);
2071 LInstruction* LChunkBuilder::DoClampToUint8(HClampToUint8* instr) {
2072 HValue* value = instr->value();
2073 Representation input_rep = value->representation();
2074 if (input_rep.IsDouble()) {
2075 LOperand* reg = UseRegister(value);
2076 return DefineFixed(new(zone()) LClampDToUint8(reg), eax);
2077 } else if (input_rep.IsInteger32()) {
2078 LOperand* reg = UseFixed(value, eax);
2079 return DefineFixed(new(zone()) LClampIToUint8(reg), eax);
2081 DCHECK(input_rep.IsSmiOrTagged());
2082 LOperand* reg = UseFixed(value, eax);
2083 // Register allocator doesn't (yet) support allocation of double
2084 // temps. Reserve xmm1 explicitly.
2085 LOperand* temp = FixedTemp(xmm1);
2086 LClampTToUint8* result = new(zone()) LClampTToUint8(reg, temp);
2087 return AssignEnvironment(DefineFixed(result, eax));
2092 LInstruction* LChunkBuilder::DoDoubleBits(HDoubleBits* instr) {
2093 HValue* value = instr->value();
2094 DCHECK(value->representation().IsDouble());
2095 return DefineAsRegister(new(zone()) LDoubleBits(UseRegister(value)));
2099 LInstruction* LChunkBuilder::DoConstructDouble(HConstructDouble* instr) {
2100 LOperand* lo = UseRegister(instr->lo());
2101 LOperand* hi = UseRegister(instr->hi());
2102 return DefineAsRegister(new(zone()) LConstructDouble(hi, lo));
2106 LInstruction* LChunkBuilder::DoReturn(HReturn* instr) {
2107 LOperand* context = info()->IsStub() ? UseFixed(instr->context(), esi) : NULL;
2108 LOperand* parameter_count = UseRegisterOrConstant(instr->parameter_count());
2109 return new(zone()) LReturn(
2110 UseFixed(instr->value(), eax), context, parameter_count);
2114 LInstruction* LChunkBuilder::DoConstant(HConstant* instr) {
2115 Representation r = instr->representation();
2117 return DefineAsRegister(new(zone()) LConstantS);
2118 } else if (r.IsInteger32()) {
2119 return DefineAsRegister(new(zone()) LConstantI);
2120 } else if (r.IsDouble()) {
2121 uint64_t const bits = instr->DoubleValueAsBits();
2122 LOperand* temp = bits ? TempRegister() : nullptr;
2123 return DefineAsRegister(new(zone()) LConstantD(temp));
2124 } else if (r.IsExternal()) {
2125 return DefineAsRegister(new(zone()) LConstantE);
2126 } else if (r.IsTagged()) {
2127 return DefineAsRegister(new(zone()) LConstantT);
2135 LInstruction* LChunkBuilder::DoLoadGlobalGeneric(HLoadGlobalGeneric* instr) {
2136 LOperand* context = UseFixed(instr->context(), esi);
2137 LOperand* global_object =
2138 UseFixed(instr->global_object(), LoadDescriptor::ReceiverRegister());
2139 LOperand* vector = NULL;
2140 if (instr->HasVectorAndSlot()) {
2141 vector = FixedTemp(VectorLoadICDescriptor::VectorRegister());
2144 LLoadGlobalGeneric* result =
2145 new(zone()) LLoadGlobalGeneric(context, global_object, vector);
2146 return MarkAsCall(DefineFixed(result, eax), instr);
2150 LInstruction* LChunkBuilder::DoLoadContextSlot(HLoadContextSlot* instr) {
2151 LOperand* context = UseRegisterAtStart(instr->value());
2152 LInstruction* result =
2153 DefineAsRegister(new(zone()) LLoadContextSlot(context));
2154 if (instr->RequiresHoleCheck() && instr->DeoptimizesOnHole()) {
2155 result = AssignEnvironment(result);
2161 LInstruction* LChunkBuilder::DoStoreContextSlot(HStoreContextSlot* instr) {
2164 LOperand* context = UseRegister(instr->context());
2165 if (instr->NeedsWriteBarrier()) {
2166 value = UseTempRegister(instr->value());
2167 temp = TempRegister();
2169 value = UseRegister(instr->value());
2172 LInstruction* result = new(zone()) LStoreContextSlot(context, value, temp);
2173 if (instr->RequiresHoleCheck() && instr->DeoptimizesOnHole()) {
2174 result = AssignEnvironment(result);
2180 LInstruction* LChunkBuilder::DoLoadNamedField(HLoadNamedField* instr) {
2181 LOperand* obj = (instr->access().IsExternalMemory() &&
2182 instr->access().offset() == 0)
2183 ? UseRegisterOrConstantAtStart(instr->object())
2184 : UseRegisterAtStart(instr->object());
2185 return DefineAsRegister(new(zone()) LLoadNamedField(obj));
2189 LInstruction* LChunkBuilder::DoLoadNamedGeneric(HLoadNamedGeneric* instr) {
2190 LOperand* context = UseFixed(instr->context(), esi);
2192 UseFixed(instr->object(), LoadDescriptor::ReceiverRegister());
2193 LOperand* vector = NULL;
2194 if (instr->HasVectorAndSlot()) {
2195 vector = FixedTemp(VectorLoadICDescriptor::VectorRegister());
2197 LLoadNamedGeneric* result = new(zone()) LLoadNamedGeneric(
2198 context, object, vector);
2199 return MarkAsCall(DefineFixed(result, eax), instr);
2203 LInstruction* LChunkBuilder::DoLoadFunctionPrototype(
2204 HLoadFunctionPrototype* instr) {
2205 return AssignEnvironment(DefineAsRegister(
2206 new(zone()) LLoadFunctionPrototype(UseRegister(instr->function()),
2211 LInstruction* LChunkBuilder::DoLoadRoot(HLoadRoot* instr) {
2212 return DefineAsRegister(new(zone()) LLoadRoot);
2216 LInstruction* LChunkBuilder::DoLoadKeyed(HLoadKeyed* instr) {
2217 DCHECK(instr->key()->representation().IsSmiOrInteger32());
2218 ElementsKind elements_kind = instr->elements_kind();
2219 bool clobbers_key = ExternalArrayOpRequiresTemp(
2220 instr->key()->representation(), elements_kind);
2221 LOperand* key = clobbers_key
2222 ? UseTempRegister(instr->key())
2223 : UseRegisterOrConstantAtStart(instr->key());
2224 LInstruction* result = NULL;
2226 if (!instr->is_typed_elements()) {
2227 LOperand* obj = UseRegisterAtStart(instr->elements());
2228 result = DefineAsRegister(new(zone()) LLoadKeyed(obj, key));
2231 (instr->representation().IsInteger32() &&
2232 !(IsDoubleOrFloatElementsKind(instr->elements_kind()))) ||
2233 (instr->representation().IsDouble() &&
2234 (IsDoubleOrFloatElementsKind(instr->elements_kind()))));
2235 LOperand* backing_store = UseRegister(instr->elements());
2236 result = DefineAsRegister(new(zone()) LLoadKeyed(backing_store, key));
2239 if ((instr->is_external() || instr->is_fixed_typed_array()) ?
2240 // see LCodeGen::DoLoadKeyedExternalArray
2241 ((instr->elements_kind() == EXTERNAL_UINT32_ELEMENTS ||
2242 instr->elements_kind() == UINT32_ELEMENTS) &&
2243 !instr->CheckFlag(HInstruction::kUint32)) :
2244 // see LCodeGen::DoLoadKeyedFixedDoubleArray and
2245 // LCodeGen::DoLoadKeyedFixedArray
2246 instr->RequiresHoleCheck()) {
2247 result = AssignEnvironment(result);
2253 LInstruction* LChunkBuilder::DoLoadKeyedGeneric(HLoadKeyedGeneric* instr) {
2254 LOperand* context = UseFixed(instr->context(), esi);
2256 UseFixed(instr->object(), LoadDescriptor::ReceiverRegister());
2257 LOperand* key = UseFixed(instr->key(), LoadDescriptor::NameRegister());
2258 LOperand* vector = NULL;
2259 if (instr->HasVectorAndSlot()) {
2260 vector = FixedTemp(VectorLoadICDescriptor::VectorRegister());
2262 LLoadKeyedGeneric* result =
2263 new(zone()) LLoadKeyedGeneric(context, object, key, vector);
2264 return MarkAsCall(DefineFixed(result, eax), instr);
2268 LOperand* LChunkBuilder::GetStoreKeyedValueOperand(HStoreKeyed* instr) {
2269 ElementsKind elements_kind = instr->elements_kind();
2271 // Determine if we need a byte register in this case for the value.
2272 bool val_is_fixed_register =
2273 elements_kind == EXTERNAL_INT8_ELEMENTS ||
2274 elements_kind == EXTERNAL_UINT8_ELEMENTS ||
2275 elements_kind == EXTERNAL_UINT8_CLAMPED_ELEMENTS ||
2276 elements_kind == UINT8_ELEMENTS ||
2277 elements_kind == INT8_ELEMENTS ||
2278 elements_kind == UINT8_CLAMPED_ELEMENTS;
2279 if (val_is_fixed_register) {
2280 return UseFixed(instr->value(), eax);
2283 return UseRegister(instr->value());
2287 LInstruction* LChunkBuilder::DoStoreKeyed(HStoreKeyed* instr) {
2288 if (!instr->is_typed_elements()) {
2289 DCHECK(instr->elements()->representation().IsTagged());
2290 DCHECK(instr->key()->representation().IsInteger32() ||
2291 instr->key()->representation().IsSmi());
2293 if (instr->value()->representation().IsDouble()) {
2294 LOperand* object = UseRegisterAtStart(instr->elements());
2295 LOperand* val = NULL;
2296 val = UseRegisterAtStart(instr->value());
2297 LOperand* key = UseRegisterOrConstantAtStart(instr->key());
2298 return new(zone()) LStoreKeyed(object, key, val);
2300 DCHECK(instr->value()->representation().IsSmiOrTagged());
2301 bool needs_write_barrier = instr->NeedsWriteBarrier();
2303 LOperand* obj = UseRegister(instr->elements());
2306 if (needs_write_barrier) {
2307 val = UseTempRegister(instr->value());
2308 key = UseTempRegister(instr->key());
2310 val = UseRegisterOrConstantAtStart(instr->value());
2311 key = UseRegisterOrConstantAtStart(instr->key());
2313 return new(zone()) LStoreKeyed(obj, key, val);
2317 ElementsKind elements_kind = instr->elements_kind();
2319 (instr->value()->representation().IsInteger32() &&
2320 !IsDoubleOrFloatElementsKind(elements_kind)) ||
2321 (instr->value()->representation().IsDouble() &&
2322 IsDoubleOrFloatElementsKind(elements_kind)));
2323 DCHECK((instr->is_fixed_typed_array() &&
2324 instr->elements()->representation().IsTagged()) ||
2325 (instr->is_external() &&
2326 instr->elements()->representation().IsExternal()));
2328 LOperand* backing_store = UseRegister(instr->elements());
2329 LOperand* val = GetStoreKeyedValueOperand(instr);
2330 bool clobbers_key = ExternalArrayOpRequiresTemp(
2331 instr->key()->representation(), elements_kind);
2332 LOperand* key = clobbers_key
2333 ? UseTempRegister(instr->key())
2334 : UseRegisterOrConstantAtStart(instr->key());
2335 return new(zone()) LStoreKeyed(backing_store, key, val);
2339 LInstruction* LChunkBuilder::DoStoreKeyedGeneric(HStoreKeyedGeneric* instr) {
2340 LOperand* context = UseFixed(instr->context(), esi);
2342 UseFixed(instr->object(), StoreDescriptor::ReceiverRegister());
2343 LOperand* key = UseFixed(instr->key(), StoreDescriptor::NameRegister());
2344 LOperand* value = UseFixed(instr->value(), StoreDescriptor::ValueRegister());
2346 DCHECK(instr->object()->representation().IsTagged());
2347 DCHECK(instr->key()->representation().IsTagged());
2348 DCHECK(instr->value()->representation().IsTagged());
2350 LStoreKeyedGeneric* result =
2351 new(zone()) LStoreKeyedGeneric(context, object, key, value);
2352 return MarkAsCall(result, instr);
2356 LInstruction* LChunkBuilder::DoTransitionElementsKind(
2357 HTransitionElementsKind* instr) {
2358 if (IsSimpleMapChangeTransition(instr->from_kind(), instr->to_kind())) {
2359 LOperand* object = UseRegister(instr->object());
2360 LOperand* new_map_reg = TempRegister();
2361 LOperand* temp_reg = TempRegister();
2362 LTransitionElementsKind* result =
2363 new(zone()) LTransitionElementsKind(object, NULL,
2364 new_map_reg, temp_reg);
2367 LOperand* object = UseFixed(instr->object(), eax);
2368 LOperand* context = UseFixed(instr->context(), esi);
2369 LTransitionElementsKind* result =
2370 new(zone()) LTransitionElementsKind(object, context, NULL, NULL);
2371 return MarkAsCall(result, instr);
2376 LInstruction* LChunkBuilder::DoTrapAllocationMemento(
2377 HTrapAllocationMemento* instr) {
2378 LOperand* object = UseRegister(instr->object());
2379 LOperand* temp = TempRegister();
2380 LTrapAllocationMemento* result =
2381 new(zone()) LTrapAllocationMemento(object, temp);
2382 return AssignEnvironment(result);
2386 LInstruction* LChunkBuilder::DoStoreNamedField(HStoreNamedField* instr) {
2387 bool is_in_object = instr->access().IsInobject();
2388 bool is_external_location = instr->access().IsExternalMemory() &&
2389 instr->access().offset() == 0;
2390 bool needs_write_barrier = instr->NeedsWriteBarrier();
2391 bool needs_write_barrier_for_map = instr->has_transition() &&
2392 instr->NeedsWriteBarrierForMap();
2395 if (needs_write_barrier) {
2397 ? UseRegister(instr->object())
2398 : UseTempRegister(instr->object());
2399 } else if (is_external_location) {
2400 DCHECK(!is_in_object);
2401 DCHECK(!needs_write_barrier);
2402 DCHECK(!needs_write_barrier_for_map);
2403 obj = UseRegisterOrConstant(instr->object());
2405 obj = needs_write_barrier_for_map
2406 ? UseRegister(instr->object())
2407 : UseRegisterAtStart(instr->object());
2410 bool can_be_constant = instr->value()->IsConstant() &&
2411 HConstant::cast(instr->value())->NotInNewSpace() &&
2412 !instr->field_representation().IsDouble();
2415 if (instr->field_representation().IsInteger8() ||
2416 instr->field_representation().IsUInteger8()) {
2417 // mov_b requires a byte register (i.e. any of eax, ebx, ecx, edx).
2418 // Just force the value to be in eax and we're safe here.
2419 val = UseFixed(instr->value(), eax);
2420 } else if (needs_write_barrier) {
2421 val = UseTempRegister(instr->value());
2422 } else if (can_be_constant) {
2423 val = UseRegisterOrConstant(instr->value());
2424 } else if (instr->field_representation().IsDouble()) {
2425 val = UseRegisterAtStart(instr->value());
2427 val = UseRegister(instr->value());
2430 // We only need a scratch register if we have a write barrier or we
2431 // have a store into the properties array (not in-object-property).
2432 LOperand* temp = (!is_in_object || needs_write_barrier ||
2433 needs_write_barrier_for_map) ? TempRegister() : NULL;
2435 // We need a temporary register for write barrier of the map field.
2436 LOperand* temp_map = needs_write_barrier_for_map ? TempRegister() : NULL;
2438 return new(zone()) LStoreNamedField(obj, val, temp, temp_map);
2442 LInstruction* LChunkBuilder::DoStoreNamedGeneric(HStoreNamedGeneric* instr) {
2443 LOperand* context = UseFixed(instr->context(), esi);
2445 UseFixed(instr->object(), StoreDescriptor::ReceiverRegister());
2446 LOperand* value = UseFixed(instr->value(), StoreDescriptor::ValueRegister());
2448 LStoreNamedGeneric* result =
2449 new(zone()) LStoreNamedGeneric(context, object, value);
2450 return MarkAsCall(result, instr);
2454 LInstruction* LChunkBuilder::DoStringAdd(HStringAdd* instr) {
2455 LOperand* context = UseFixed(instr->context(), esi);
2456 LOperand* left = UseFixed(instr->left(), edx);
2457 LOperand* right = UseFixed(instr->right(), eax);
2458 LStringAdd* string_add = new(zone()) LStringAdd(context, left, right);
2459 return MarkAsCall(DefineFixed(string_add, eax), instr);
2463 LInstruction* LChunkBuilder::DoStringCharCodeAt(HStringCharCodeAt* instr) {
2464 LOperand* string = UseTempRegister(instr->string());
2465 LOperand* index = UseTempRegister(instr->index());
2466 LOperand* context = UseAny(instr->context());
2467 LStringCharCodeAt* result =
2468 new(zone()) LStringCharCodeAt(context, string, index);
2469 return AssignPointerMap(DefineAsRegister(result));
2473 LInstruction* LChunkBuilder::DoStringCharFromCode(HStringCharFromCode* instr) {
2474 LOperand* char_code = UseRegister(instr->value());
2475 LOperand* context = UseAny(instr->context());
2476 LStringCharFromCode* result =
2477 new(zone()) LStringCharFromCode(context, char_code);
2478 return AssignPointerMap(DefineAsRegister(result));
2482 LInstruction* LChunkBuilder::DoAllocate(HAllocate* instr) {
2483 info()->MarkAsDeferredCalling();
2484 LOperand* context = UseAny(instr->context());
2485 LOperand* size = instr->size()->IsConstant()
2486 ? UseConstant(instr->size())
2487 : UseTempRegister(instr->size());
2488 LOperand* temp = TempRegister();
2489 LAllocate* result = new(zone()) LAllocate(context, size, temp);
2490 return AssignPointerMap(DefineAsRegister(result));
2494 LInstruction* LChunkBuilder::DoRegExpLiteral(HRegExpLiteral* instr) {
2495 LOperand* context = UseFixed(instr->context(), esi);
2497 DefineFixed(new(zone()) LRegExpLiteral(context), eax), instr);
2501 LInstruction* LChunkBuilder::DoFunctionLiteral(HFunctionLiteral* instr) {
2502 LOperand* context = UseFixed(instr->context(), esi);
2504 DefineFixed(new(zone()) LFunctionLiteral(context), eax), instr);
2508 LInstruction* LChunkBuilder::DoOsrEntry(HOsrEntry* instr) {
2509 DCHECK(argument_count_ == 0);
2510 allocator_->MarkAsOsrEntry();
2511 current_block_->last_environment()->set_ast_id(instr->ast_id());
2512 return AssignEnvironment(new(zone()) LOsrEntry);
2516 LInstruction* LChunkBuilder::DoParameter(HParameter* instr) {
2517 LParameter* result = new(zone()) LParameter;
2518 if (instr->kind() == HParameter::STACK_PARAMETER) {
2519 int spill_index = chunk()->GetParameterStackSlot(instr->index());
2520 return DefineAsSpilled(result, spill_index);
2522 DCHECK(info()->IsStub());
2523 CallInterfaceDescriptor descriptor =
2524 info()->code_stub()->GetCallInterfaceDescriptor();
2525 int index = static_cast<int>(instr->index());
2526 Register reg = descriptor.GetEnvironmentParameterRegister(index);
2527 return DefineFixed(result, reg);
2532 LInstruction* LChunkBuilder::DoUnknownOSRValue(HUnknownOSRValue* instr) {
2533 // Use an index that corresponds to the location in the unoptimized frame,
2534 // which the optimized frame will subsume.
2535 int env_index = instr->index();
2536 int spill_index = 0;
2537 if (instr->environment()->is_parameter_index(env_index)) {
2538 spill_index = chunk()->GetParameterStackSlot(env_index);
2540 spill_index = env_index - instr->environment()->first_local_index();
2541 if (spill_index > LUnallocated::kMaxFixedSlotIndex) {
2542 Retry(kNotEnoughSpillSlotsForOsr);
2545 if (spill_index == 0) {
2546 // The dynamic frame alignment state overwrites the first local.
2547 // The first local is saved at the end of the unoptimized frame.
2548 spill_index = graph()->osr()->UnoptimizedFrameSlots();
2551 return DefineAsSpilled(new(zone()) LUnknownOSRValue, spill_index);
2555 LInstruction* LChunkBuilder::DoCallStub(HCallStub* instr) {
2556 LOperand* context = UseFixed(instr->context(), esi);
2557 LCallStub* result = new(zone()) LCallStub(context);
2558 return MarkAsCall(DefineFixed(result, eax), instr);
2562 LInstruction* LChunkBuilder::DoArgumentsObject(HArgumentsObject* instr) {
2563 // There are no real uses of the arguments object.
2564 // arguments.length and element access are supported directly on
2565 // stack arguments, and any real arguments object use causes a bailout.
2566 // So this value is never used.
2571 LInstruction* LChunkBuilder::DoCapturedObject(HCapturedObject* instr) {
2572 instr->ReplayEnvironment(current_block_->last_environment());
2574 // There are no real uses of a captured object.
2579 LInstruction* LChunkBuilder::DoAccessArgumentsAt(HAccessArgumentsAt* instr) {
2580 info()->MarkAsRequiresFrame();
2581 LOperand* args = UseRegister(instr->arguments());
2584 if (instr->length()->IsConstant() && instr->index()->IsConstant()) {
2585 length = UseRegisterOrConstant(instr->length());
2586 index = UseOrConstant(instr->index());
2588 length = UseTempRegister(instr->length());
2589 index = Use(instr->index());
2591 return DefineAsRegister(new(zone()) LAccessArgumentsAt(args, length, index));
2595 LInstruction* LChunkBuilder::DoToFastProperties(HToFastProperties* instr) {
2596 LOperand* object = UseFixed(instr->value(), eax);
2597 LToFastProperties* result = new(zone()) LToFastProperties(object);
2598 return MarkAsCall(DefineFixed(result, eax), instr);
2602 LInstruction* LChunkBuilder::DoTypeof(HTypeof* instr) {
2603 LOperand* context = UseFixed(instr->context(), esi);
2604 LOperand* value = UseAtStart(instr->value());
2605 LTypeof* result = new(zone()) LTypeof(context, value);
2606 return MarkAsCall(DefineFixed(result, eax), instr);
2610 LInstruction* LChunkBuilder::DoTypeofIsAndBranch(HTypeofIsAndBranch* instr) {
2611 return new(zone()) LTypeofIsAndBranch(UseTempRegister(instr->value()));
2615 LInstruction* LChunkBuilder::DoIsConstructCallAndBranch(
2616 HIsConstructCallAndBranch* instr) {
2617 return new(zone()) LIsConstructCallAndBranch(TempRegister());
2621 LInstruction* LChunkBuilder::DoSimulate(HSimulate* instr) {
2622 instr->ReplayEnvironment(current_block_->last_environment());
2627 LInstruction* LChunkBuilder::DoStackCheck(HStackCheck* instr) {
2628 info()->MarkAsDeferredCalling();
2629 if (instr->is_function_entry()) {
2630 LOperand* context = UseFixed(instr->context(), esi);
2631 return MarkAsCall(new(zone()) LStackCheck(context), instr);
2633 DCHECK(instr->is_backwards_branch());
2634 LOperand* context = UseAny(instr->context());
2635 return AssignEnvironment(
2636 AssignPointerMap(new(zone()) LStackCheck(context)));
2641 LInstruction* LChunkBuilder::DoEnterInlined(HEnterInlined* instr) {
2642 HEnvironment* outer = current_block_->last_environment();
2643 outer->set_ast_id(instr->ReturnId());
2644 HConstant* undefined = graph()->GetConstantUndefined();
2645 HEnvironment* inner = outer->CopyForInlining(instr->closure(),
2646 instr->arguments_count(),
2649 instr->inlining_kind());
2650 // Only replay binding of arguments object if it wasn't removed from graph.
2651 if (instr->arguments_var() != NULL && instr->arguments_object()->IsLinked()) {
2652 inner->Bind(instr->arguments_var(), instr->arguments_object());
2654 inner->BindContext(instr->closure_context());
2655 inner->set_entry(instr);
2656 current_block_->UpdateEnvironment(inner);
2657 chunk_->AddInlinedClosure(instr->closure());
2662 LInstruction* LChunkBuilder::DoLeaveInlined(HLeaveInlined* instr) {
2663 LInstruction* pop = NULL;
2665 HEnvironment* env = current_block_->last_environment();
2667 if (env->entry()->arguments_pushed()) {
2668 int argument_count = env->arguments_environment()->parameter_count();
2669 pop = new(zone()) LDrop(argument_count);
2670 DCHECK(instr->argument_delta() == -argument_count);
2673 HEnvironment* outer = current_block_->last_environment()->
2674 DiscardInlined(false);
2675 current_block_->UpdateEnvironment(outer);
2680 LInstruction* LChunkBuilder::DoForInPrepareMap(HForInPrepareMap* instr) {
2681 LOperand* context = UseFixed(instr->context(), esi);
2682 LOperand* object = UseFixed(instr->enumerable(), eax);
2683 LForInPrepareMap* result = new(zone()) LForInPrepareMap(context, object);
2684 return MarkAsCall(DefineFixed(result, eax), instr, CAN_DEOPTIMIZE_EAGERLY);
2688 LInstruction* LChunkBuilder::DoForInCacheArray(HForInCacheArray* instr) {
2689 LOperand* map = UseRegister(instr->map());
2690 return AssignEnvironment(DefineAsRegister(
2691 new(zone()) LForInCacheArray(map)));
2695 LInstruction* LChunkBuilder::DoCheckMapValue(HCheckMapValue* instr) {
2696 LOperand* value = UseRegisterAtStart(instr->value());
2697 LOperand* map = UseRegisterAtStart(instr->map());
2698 return AssignEnvironment(new(zone()) LCheckMapValue(value, map));
2702 LInstruction* LChunkBuilder::DoLoadFieldByIndex(HLoadFieldByIndex* instr) {
2703 LOperand* object = UseRegister(instr->object());
2704 LOperand* index = UseTempRegister(instr->index());
2705 LLoadFieldByIndex* load = new(zone()) LLoadFieldByIndex(object, index);
2706 LInstruction* result = DefineSameAsFirst(load);
2707 return AssignPointerMap(result);
2711 LInstruction* LChunkBuilder::DoStoreFrameContext(HStoreFrameContext* instr) {
2712 LOperand* context = UseRegisterAtStart(instr->context());
2713 return new(zone()) LStoreFrameContext(context);
2717 LInstruction* LChunkBuilder::DoAllocateBlockContext(
2718 HAllocateBlockContext* instr) {
2719 LOperand* context = UseFixed(instr->context(), esi);
2720 LOperand* function = UseRegisterAtStart(instr->function());
2721 LAllocateBlockContext* result =
2722 new(zone()) LAllocateBlockContext(context, function);
2723 return MarkAsCall(DefineFixed(result, esi), instr);
2727 } } // namespace v8::internal
2729 #endif // V8_TARGET_ARCH_IA32