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 LCallJSFunction::PrintDataTo(StringStream* stream) {
279 function()->PrintTo(stream);
280 stream->Add("#%d / ", arity());
284 void LCallWithDescriptor::PrintDataTo(StringStream* stream) {
285 for (int i = 0; i < InputCount(); i++) {
286 InputAt(i)->PrintTo(stream);
289 stream->Add("#%d / ", arity());
293 void LLoadContextSlot::PrintDataTo(StringStream* stream) {
294 context()->PrintTo(stream);
295 stream->Add("[%d]", slot_index());
299 void LStoreContextSlot::PrintDataTo(StringStream* stream) {
300 context()->PrintTo(stream);
301 stream->Add("[%d] <- ", slot_index());
302 value()->PrintTo(stream);
306 void LInvokeFunction::PrintDataTo(StringStream* stream) {
308 context()->PrintTo(stream);
310 function()->PrintTo(stream);
311 stream->Add(" #%d / ", arity());
315 void LCallNew::PrintDataTo(StringStream* stream) {
317 context()->PrintTo(stream);
319 constructor()->PrintTo(stream);
320 stream->Add(" #%d / ", arity());
324 void LCallNewArray::PrintDataTo(StringStream* stream) {
326 context()->PrintTo(stream);
328 constructor()->PrintTo(stream);
329 stream->Add(" #%d / ", arity());
330 ElementsKind kind = hydrogen()->elements_kind();
331 stream->Add(" (%s) ", ElementsKindToString(kind));
335 void LAccessArgumentsAt::PrintDataTo(StringStream* stream) {
336 arguments()->PrintTo(stream);
338 stream->Add(" length ");
339 length()->PrintTo(stream);
341 stream->Add(" index ");
342 index()->PrintTo(stream);
346 int LPlatformChunk::GetNextSpillIndex(RegisterKind kind) {
347 // Skip a slot if for a double-width slot.
348 if (kind == DOUBLE_REGISTERS) {
350 spill_slot_count_ |= 1;
353 return spill_slot_count_++;
357 LOperand* LPlatformChunk::GetNextSpillSlot(RegisterKind kind) {
358 int index = GetNextSpillIndex(kind);
359 if (kind == DOUBLE_REGISTERS) {
360 return LDoubleStackSlot::Create(index, zone());
362 DCHECK(kind == GENERAL_REGISTERS);
363 return LStackSlot::Create(index, zone());
368 void LStoreNamedField::PrintDataTo(StringStream* stream) {
369 object()->PrintTo(stream);
370 std::ostringstream os;
371 os << hydrogen()->access() << " <- ";
372 stream->Add(os.str().c_str());
373 value()->PrintTo(stream);
377 void LStoreNamedGeneric::PrintDataTo(StringStream* stream) {
378 object()->PrintTo(stream);
380 stream->Add(String::cast(*name())->ToCString().get());
382 value()->PrintTo(stream);
386 void LLoadKeyed::PrintDataTo(StringStream* stream) {
387 elements()->PrintTo(stream);
389 key()->PrintTo(stream);
390 if (hydrogen()->IsDehoisted()) {
391 stream->Add(" + %d]", base_offset());
398 void LStoreKeyed::PrintDataTo(StringStream* stream) {
399 elements()->PrintTo(stream);
401 key()->PrintTo(stream);
402 if (hydrogen()->IsDehoisted()) {
403 stream->Add(" + %d] <-", base_offset());
405 stream->Add("] <- ");
408 if (value() == NULL) {
409 DCHECK(hydrogen()->IsConstantHoleStore() &&
410 hydrogen()->value()->representation().IsDouble());
411 stream->Add("<the hole(nan)>");
413 value()->PrintTo(stream);
418 void LStoreKeyedGeneric::PrintDataTo(StringStream* stream) {
419 object()->PrintTo(stream);
421 key()->PrintTo(stream);
422 stream->Add("] <- ");
423 value()->PrintTo(stream);
427 void LTransitionElementsKind::PrintDataTo(StringStream* stream) {
428 object()->PrintTo(stream);
429 stream->Add(" %p -> %p", *original_map(), *transitioned_map());
433 LPlatformChunk* LChunkBuilder::Build() {
435 chunk_ = new(zone()) LPlatformChunk(info(), graph());
436 LPhase phase("L_Building chunk", chunk_);
439 // Reserve the first spill slot for the state of dynamic alignment.
440 if (info()->IsOptimizing()) {
441 int alignment_state_index = chunk_->GetNextSpillIndex(GENERAL_REGISTERS);
442 DCHECK_EQ(alignment_state_index, 0);
443 USE(alignment_state_index);
446 // If compiling for OSR, reserve space for the unoptimized frame,
447 // which will be subsumed into this frame.
448 if (graph()->has_osr()) {
449 for (int i = graph()->osr()->UnoptimizedFrameSlots(); i > 0; i--) {
450 chunk_->GetNextSpillIndex(GENERAL_REGISTERS);
454 const ZoneList<HBasicBlock*>* blocks = graph()->blocks();
455 for (int i = 0; i < blocks->length(); i++) {
456 HBasicBlock* next = NULL;
457 if (i < blocks->length() - 1) next = blocks->at(i + 1);
458 DoBasicBlock(blocks->at(i), next);
459 if (is_aborted()) return NULL;
466 LUnallocated* LChunkBuilder::ToUnallocated(Register reg) {
467 return new(zone()) LUnallocated(LUnallocated::FIXED_REGISTER,
468 Register::ToAllocationIndex(reg));
472 LUnallocated* LChunkBuilder::ToUnallocated(XMMRegister reg) {
473 return new(zone()) LUnallocated(LUnallocated::FIXED_DOUBLE_REGISTER,
474 XMMRegister::ToAllocationIndex(reg));
478 LOperand* LChunkBuilder::UseFixed(HValue* value, Register fixed_register) {
479 return Use(value, ToUnallocated(fixed_register));
483 LOperand* LChunkBuilder::UseFixedDouble(HValue* value, XMMRegister reg) {
484 return Use(value, ToUnallocated(reg));
488 LOperand* LChunkBuilder::UseRegister(HValue* value) {
489 return Use(value, new(zone()) LUnallocated(LUnallocated::MUST_HAVE_REGISTER));
493 LOperand* LChunkBuilder::UseRegisterAtStart(HValue* value) {
495 new(zone()) LUnallocated(LUnallocated::MUST_HAVE_REGISTER,
496 LUnallocated::USED_AT_START));
500 LOperand* LChunkBuilder::UseTempRegister(HValue* value) {
501 return Use(value, new(zone()) LUnallocated(LUnallocated::WRITABLE_REGISTER));
505 LOperand* LChunkBuilder::Use(HValue* value) {
506 return Use(value, new(zone()) LUnallocated(LUnallocated::NONE));
510 LOperand* LChunkBuilder::UseAtStart(HValue* value) {
511 return Use(value, new(zone()) LUnallocated(LUnallocated::NONE,
512 LUnallocated::USED_AT_START));
516 static inline bool CanBeImmediateConstant(HValue* value) {
517 return value->IsConstant() && HConstant::cast(value)->NotInNewSpace();
521 LOperand* LChunkBuilder::UseOrConstant(HValue* value) {
522 return CanBeImmediateConstant(value)
523 ? chunk_->DefineConstantOperand(HConstant::cast(value))
528 LOperand* LChunkBuilder::UseOrConstantAtStart(HValue* value) {
529 return CanBeImmediateConstant(value)
530 ? chunk_->DefineConstantOperand(HConstant::cast(value))
535 LOperand* LChunkBuilder::UseFixedOrConstant(HValue* value,
536 Register fixed_register) {
537 return CanBeImmediateConstant(value)
538 ? chunk_->DefineConstantOperand(HConstant::cast(value))
539 : UseFixed(value, fixed_register);
543 LOperand* LChunkBuilder::UseRegisterOrConstant(HValue* value) {
544 return CanBeImmediateConstant(value)
545 ? chunk_->DefineConstantOperand(HConstant::cast(value))
546 : UseRegister(value);
550 LOperand* LChunkBuilder::UseRegisterOrConstantAtStart(HValue* value) {
551 return CanBeImmediateConstant(value)
552 ? chunk_->DefineConstantOperand(HConstant::cast(value))
553 : UseRegisterAtStart(value);
557 LOperand* LChunkBuilder::UseConstant(HValue* value) {
558 return chunk_->DefineConstantOperand(HConstant::cast(value));
562 LOperand* LChunkBuilder::UseAny(HValue* value) {
563 return value->IsConstant()
564 ? chunk_->DefineConstantOperand(HConstant::cast(value))
565 : Use(value, new(zone()) LUnallocated(LUnallocated::ANY));
569 LOperand* LChunkBuilder::Use(HValue* value, LUnallocated* operand) {
570 if (value->EmitAtUses()) {
571 HInstruction* instr = HInstruction::cast(value);
572 VisitInstruction(instr);
574 operand->set_virtual_register(value->id());
579 LInstruction* LChunkBuilder::Define(LTemplateResultInstruction<1>* instr,
580 LUnallocated* result) {
581 result->set_virtual_register(current_instruction_->id());
582 instr->set_result(result);
587 LInstruction* LChunkBuilder::DefineAsRegister(
588 LTemplateResultInstruction<1>* instr) {
590 new(zone()) LUnallocated(LUnallocated::MUST_HAVE_REGISTER));
594 LInstruction* LChunkBuilder::DefineAsSpilled(
595 LTemplateResultInstruction<1>* instr,
598 new(zone()) LUnallocated(LUnallocated::FIXED_SLOT, index));
602 LInstruction* LChunkBuilder::DefineSameAsFirst(
603 LTemplateResultInstruction<1>* instr) {
605 new(zone()) LUnallocated(LUnallocated::SAME_AS_FIRST_INPUT));
609 LInstruction* LChunkBuilder::DefineFixed(LTemplateResultInstruction<1>* instr,
611 return Define(instr, ToUnallocated(reg));
615 LInstruction* LChunkBuilder::DefineFixedDouble(
616 LTemplateResultInstruction<1>* instr,
618 return Define(instr, ToUnallocated(reg));
622 LInstruction* LChunkBuilder::AssignEnvironment(LInstruction* instr) {
623 HEnvironment* hydrogen_env = current_block_->last_environment();
624 int argument_index_accumulator = 0;
625 ZoneList<HValue*> objects_to_materialize(0, zone());
626 instr->set_environment(CreateEnvironment(
627 hydrogen_env, &argument_index_accumulator, &objects_to_materialize));
632 LInstruction* LChunkBuilder::MarkAsCall(LInstruction* instr,
633 HInstruction* hinstr,
634 CanDeoptimize can_deoptimize) {
635 info()->MarkAsNonDeferredCalling();
641 instr = AssignPointerMap(instr);
643 // If instruction does not have side-effects lazy deoptimization
644 // after the call will try to deoptimize to the point before the call.
645 // Thus we still need to attach environment to this call even if
646 // call sequence can not deoptimize eagerly.
647 bool needs_environment =
648 (can_deoptimize == CAN_DEOPTIMIZE_EAGERLY) ||
649 !hinstr->HasObservableSideEffects();
650 if (needs_environment && !instr->HasEnvironment()) {
651 instr = AssignEnvironment(instr);
652 // We can't really figure out if the environment is needed or not.
653 instr->environment()->set_has_been_used();
660 LInstruction* LChunkBuilder::AssignPointerMap(LInstruction* instr) {
661 DCHECK(!instr->HasPointerMap());
662 instr->set_pointer_map(new(zone()) LPointerMap(zone()));
667 LUnallocated* LChunkBuilder::TempRegister() {
668 LUnallocated* operand =
669 new(zone()) LUnallocated(LUnallocated::MUST_HAVE_REGISTER);
670 int vreg = allocator_->GetVirtualRegister();
671 if (!allocator_->AllocationOk()) {
672 Abort(kOutOfVirtualRegistersWhileTryingToAllocateTempRegister);
675 operand->set_virtual_register(vreg);
680 LOperand* LChunkBuilder::FixedTemp(Register reg) {
681 LUnallocated* operand = ToUnallocated(reg);
682 DCHECK(operand->HasFixedPolicy());
687 LOperand* LChunkBuilder::FixedTemp(XMMRegister reg) {
688 LUnallocated* operand = ToUnallocated(reg);
689 DCHECK(operand->HasFixedPolicy());
694 LInstruction* LChunkBuilder::DoBlockEntry(HBlockEntry* instr) {
695 return new(zone()) LLabel(instr->block());
699 LInstruction* LChunkBuilder::DoDummyUse(HDummyUse* instr) {
700 return DefineAsRegister(new(zone()) LDummyUse(UseAny(instr->value())));
704 LInstruction* LChunkBuilder::DoEnvironmentMarker(HEnvironmentMarker* instr) {
710 LInstruction* LChunkBuilder::DoDeoptimize(HDeoptimize* instr) {
711 return AssignEnvironment(new(zone()) LDeoptimize);
715 LInstruction* LChunkBuilder::DoShift(Token::Value op,
716 HBitwiseBinaryOperation* instr) {
717 if (instr->representation().IsSmiOrInteger32()) {
718 DCHECK(instr->left()->representation().Equals(instr->representation()));
719 DCHECK(instr->right()->representation().Equals(instr->representation()));
720 LOperand* left = UseRegisterAtStart(instr->left());
722 HValue* right_value = instr->right();
723 LOperand* right = NULL;
724 int constant_value = 0;
725 bool does_deopt = false;
726 if (right_value->IsConstant()) {
727 HConstant* constant = HConstant::cast(right_value);
728 right = chunk_->DefineConstantOperand(constant);
729 constant_value = constant->Integer32Value() & 0x1f;
730 // Left shifts can deoptimize if we shift by > 0 and the result cannot be
732 if (instr->representation().IsSmi() && constant_value > 0) {
733 does_deopt = !instr->CheckUsesForFlag(HValue::kTruncatingToSmi);
736 right = UseFixed(right_value, ecx);
739 // Shift operations can only deoptimize if we do a logical shift by 0 and
740 // the result cannot be truncated to int32.
741 if (op == Token::SHR && constant_value == 0) {
742 does_deopt = !instr->CheckFlag(HInstruction::kUint32);
745 LInstruction* result =
746 DefineSameAsFirst(new(zone()) LShiftI(op, left, right, does_deopt));
747 return does_deopt ? AssignEnvironment(result) : result;
749 return DoArithmeticT(op, instr);
754 LInstruction* LChunkBuilder::DoArithmeticD(Token::Value op,
755 HArithmeticBinaryOperation* instr) {
756 DCHECK(instr->representation().IsDouble());
757 DCHECK(instr->left()->representation().IsDouble());
758 DCHECK(instr->right()->representation().IsDouble());
759 if (op == Token::MOD) {
760 LOperand* left = UseRegisterAtStart(instr->BetterLeftOperand());
761 LOperand* right = UseRegisterAtStart(instr->BetterRightOperand());
762 LArithmeticD* result = new(zone()) LArithmeticD(op, left, right);
763 return MarkAsCall(DefineSameAsFirst(result), instr);
765 LOperand* left = UseRegisterAtStart(instr->BetterLeftOperand());
766 LOperand* right = UseRegisterAtStart(instr->BetterRightOperand());
767 LArithmeticD* result = new(zone()) LArithmeticD(op, left, right);
768 return DefineSameAsFirst(result);
773 LInstruction* LChunkBuilder::DoArithmeticT(Token::Value op,
774 HBinaryOperation* instr) {
775 HValue* left = instr->left();
776 HValue* right = instr->right();
777 DCHECK(left->representation().IsTagged());
778 DCHECK(right->representation().IsTagged());
779 LOperand* context = UseFixed(instr->context(), esi);
780 LOperand* left_operand = UseFixed(left, edx);
781 LOperand* right_operand = UseFixed(right, eax);
782 LArithmeticT* result =
783 new(zone()) LArithmeticT(op, context, left_operand, right_operand);
784 return MarkAsCall(DefineFixed(result, eax), instr);
788 void LChunkBuilder::DoBasicBlock(HBasicBlock* block, HBasicBlock* next_block) {
789 DCHECK(is_building());
790 current_block_ = block;
791 next_block_ = next_block;
792 if (block->IsStartBlock()) {
793 block->UpdateEnvironment(graph_->start_environment());
795 } else if (block->predecessors()->length() == 1) {
796 // We have a single predecessor => copy environment and outgoing
797 // argument count from the predecessor.
798 DCHECK(block->phis()->length() == 0);
799 HBasicBlock* pred = block->predecessors()->at(0);
800 HEnvironment* last_environment = pred->last_environment();
801 DCHECK(last_environment != NULL);
802 // Only copy the environment, if it is later used again.
803 if (pred->end()->SecondSuccessor() == NULL) {
804 DCHECK(pred->end()->FirstSuccessor() == block);
806 if (pred->end()->FirstSuccessor()->block_id() > block->block_id() ||
807 pred->end()->SecondSuccessor()->block_id() > block->block_id()) {
808 last_environment = last_environment->Copy();
811 block->UpdateEnvironment(last_environment);
812 DCHECK(pred->argument_count() >= 0);
813 argument_count_ = pred->argument_count();
815 // We are at a state join => process phis.
816 HBasicBlock* pred = block->predecessors()->at(0);
817 // No need to copy the environment, it cannot be used later.
818 HEnvironment* last_environment = pred->last_environment();
819 for (int i = 0; i < block->phis()->length(); ++i) {
820 HPhi* phi = block->phis()->at(i);
821 if (phi->HasMergedIndex()) {
822 last_environment->SetValueAt(phi->merged_index(), phi);
825 for (int i = 0; i < block->deleted_phis()->length(); ++i) {
826 if (block->deleted_phis()->at(i) < last_environment->length()) {
827 last_environment->SetValueAt(block->deleted_phis()->at(i),
828 graph_->GetConstantUndefined());
831 block->UpdateEnvironment(last_environment);
832 // Pick up the outgoing argument count of one of the predecessors.
833 argument_count_ = pred->argument_count();
835 HInstruction* current = block->first();
836 int start = chunk_->instructions()->length();
837 while (current != NULL && !is_aborted()) {
838 // Code for constants in registers is generated lazily.
839 if (!current->EmitAtUses()) {
840 VisitInstruction(current);
842 current = current->next();
844 int end = chunk_->instructions()->length() - 1;
846 block->set_first_instruction_index(start);
847 block->set_last_instruction_index(end);
849 block->set_argument_count(argument_count_);
851 current_block_ = NULL;
855 void LChunkBuilder::VisitInstruction(HInstruction* current) {
856 HInstruction* old_current = current_instruction_;
857 current_instruction_ = current;
859 LInstruction* instr = NULL;
860 if (current->CanReplaceWithDummyUses()) {
861 if (current->OperandCount() == 0) {
862 instr = DefineAsRegister(new(zone()) LDummy());
864 DCHECK(!current->OperandAt(0)->IsControlInstruction());
865 instr = DefineAsRegister(new(zone())
866 LDummyUse(UseAny(current->OperandAt(0))));
868 for (int i = 1; i < current->OperandCount(); ++i) {
869 if (current->OperandAt(i)->IsControlInstruction()) continue;
870 LInstruction* dummy =
871 new(zone()) LDummyUse(UseAny(current->OperandAt(i)));
872 dummy->set_hydrogen_value(current);
873 chunk_->AddInstruction(dummy, current_block_);
876 HBasicBlock* successor;
877 if (current->IsControlInstruction() &&
878 HControlInstruction::cast(current)->KnownSuccessorBlock(&successor) &&
880 instr = new(zone()) LGoto(successor);
882 instr = current->CompileToLithium(this);
886 argument_count_ += current->argument_delta();
887 DCHECK(argument_count_ >= 0);
890 AddInstruction(instr, current);
893 current_instruction_ = old_current;
897 void LChunkBuilder::AddInstruction(LInstruction* instr,
898 HInstruction* hydrogen_val) {
899 // Associate the hydrogen instruction first, since we may need it for
900 // the ClobbersRegisters() or ClobbersDoubleRegisters() calls below.
901 instr->set_hydrogen_value(hydrogen_val);
904 // Make sure that the lithium instruction has either no fixed register
905 // constraints in temps or the result OR no uses that are only used at
906 // start. If this invariant doesn't hold, the register allocator can decide
907 // to insert a split of a range immediately before the instruction due to an
908 // already allocated register needing to be used for the instruction's fixed
909 // register constraint. In this case, The register allocator won't see an
910 // interference between the split child and the use-at-start (it would if
911 // the it was just a plain use), so it is free to move the split child into
912 // the same register that is used for the use-at-start.
913 // See https://code.google.com/p/chromium/issues/detail?id=201590
914 if (!(instr->ClobbersRegisters() &&
915 instr->ClobbersDoubleRegisters(isolate()))) {
917 int used_at_start = 0;
918 for (UseIterator it(instr); !it.Done(); it.Advance()) {
919 LUnallocated* operand = LUnallocated::cast(it.Current());
920 if (operand->IsUsedAtStart()) ++used_at_start;
922 if (instr->Output() != NULL) {
923 if (LUnallocated::cast(instr->Output())->HasFixedPolicy()) ++fixed;
925 for (TempIterator it(instr); !it.Done(); it.Advance()) {
926 LUnallocated* operand = LUnallocated::cast(it.Current());
927 if (operand->HasFixedPolicy()) ++fixed;
929 DCHECK(fixed == 0 || used_at_start == 0);
933 if (FLAG_stress_pointer_maps && !instr->HasPointerMap()) {
934 instr = AssignPointerMap(instr);
936 if (FLAG_stress_environments && !instr->HasEnvironment()) {
937 instr = AssignEnvironment(instr);
939 chunk_->AddInstruction(instr, current_block_);
941 if (instr->IsCall()) {
942 HValue* hydrogen_value_for_lazy_bailout = hydrogen_val;
943 LInstruction* instruction_needing_environment = NULL;
944 if (hydrogen_val->HasObservableSideEffects()) {
945 HSimulate* sim = HSimulate::cast(hydrogen_val->next());
946 instruction_needing_environment = instr;
947 sim->ReplayEnvironment(current_block_->last_environment());
948 hydrogen_value_for_lazy_bailout = sim;
950 LInstruction* bailout = AssignEnvironment(new(zone()) LLazyBailout());
951 bailout->set_hydrogen_value(hydrogen_value_for_lazy_bailout);
952 chunk_->AddInstruction(bailout, current_block_);
953 if (instruction_needing_environment != NULL) {
954 // Store the lazy deopt environment with the instruction if needed.
955 // Right now it is only used for LInstanceOfKnownGlobal.
956 instruction_needing_environment->
957 SetDeferredLazyDeoptimizationEnvironment(bailout->environment());
963 LInstruction* LChunkBuilder::DoGoto(HGoto* instr) {
964 return new(zone()) LGoto(instr->FirstSuccessor());
968 LInstruction* LChunkBuilder::DoBranch(HBranch* instr) {
969 HValue* value = instr->value();
970 Representation r = value->representation();
971 HType type = value->type();
972 ToBooleanStub::Types expected = instr->expected_input_types();
973 if (expected.IsEmpty()) expected = ToBooleanStub::Types::Generic();
975 bool easy_case = !r.IsTagged() || type.IsBoolean() || type.IsSmi() ||
976 type.IsJSArray() || type.IsHeapNumber() || type.IsString();
977 LOperand* temp = !easy_case && expected.NeedsMap() ? TempRegister() : NULL;
978 LInstruction* branch = new(zone()) LBranch(UseRegister(value), temp);
980 ((!expected.Contains(ToBooleanStub::SMI) && expected.NeedsMap()) ||
981 !expected.IsGeneric())) {
982 branch = AssignEnvironment(branch);
988 LInstruction* LChunkBuilder::DoDebugBreak(HDebugBreak* instr) {
989 return new(zone()) LDebugBreak();
993 LInstruction* LChunkBuilder::DoCompareMap(HCompareMap* instr) {
994 DCHECK(instr->value()->representation().IsTagged());
995 LOperand* value = UseRegisterAtStart(instr->value());
996 return new(zone()) LCmpMapAndBranch(value);
1000 LInstruction* LChunkBuilder::DoArgumentsLength(HArgumentsLength* length) {
1001 info()->MarkAsRequiresFrame();
1002 return DefineAsRegister(new(zone()) LArgumentsLength(Use(length->value())));
1006 LInstruction* LChunkBuilder::DoArgumentsElements(HArgumentsElements* elems) {
1007 info()->MarkAsRequiresFrame();
1008 return DefineAsRegister(new(zone()) LArgumentsElements);
1012 LInstruction* LChunkBuilder::DoInstanceOf(HInstanceOf* instr) {
1013 LOperand* left = UseFixed(instr->left(), InstanceofStub::left());
1014 LOperand* right = UseFixed(instr->right(), InstanceofStub::right());
1015 LOperand* context = UseFixed(instr->context(), esi);
1016 LInstanceOf* result = new(zone()) LInstanceOf(context, left, right);
1017 return MarkAsCall(DefineFixed(result, eax), instr);
1021 LInstruction* LChunkBuilder::DoInstanceOfKnownGlobal(
1022 HInstanceOfKnownGlobal* instr) {
1023 LInstanceOfKnownGlobal* result =
1024 new(zone()) LInstanceOfKnownGlobal(
1025 UseFixed(instr->context(), esi),
1026 UseFixed(instr->left(), InstanceofStub::left()),
1028 return MarkAsCall(DefineFixed(result, eax), instr);
1032 LInstruction* LChunkBuilder::DoWrapReceiver(HWrapReceiver* instr) {
1033 LOperand* receiver = UseRegister(instr->receiver());
1034 LOperand* function = UseRegister(instr->function());
1035 LOperand* temp = TempRegister();
1036 LWrapReceiver* result =
1037 new(zone()) LWrapReceiver(receiver, function, temp);
1038 return AssignEnvironment(DefineSameAsFirst(result));
1042 LInstruction* LChunkBuilder::DoApplyArguments(HApplyArguments* instr) {
1043 LOperand* function = UseFixed(instr->function(), edi);
1044 LOperand* receiver = UseFixed(instr->receiver(), eax);
1045 LOperand* length = UseFixed(instr->length(), ebx);
1046 LOperand* elements = UseFixed(instr->elements(), ecx);
1047 LApplyArguments* result = new(zone()) LApplyArguments(function,
1051 return MarkAsCall(DefineFixed(result, eax), instr, CAN_DEOPTIMIZE_EAGERLY);
1055 LInstruction* LChunkBuilder::DoPushArguments(HPushArguments* instr) {
1056 int argc = instr->OperandCount();
1057 for (int i = 0; i < argc; ++i) {
1058 LOperand* argument = UseAny(instr->argument(i));
1059 AddInstruction(new(zone()) LPushArgument(argument), instr);
1065 LInstruction* LChunkBuilder::DoStoreCodeEntry(
1066 HStoreCodeEntry* store_code_entry) {
1067 LOperand* function = UseRegister(store_code_entry->function());
1068 LOperand* code_object = UseTempRegister(store_code_entry->code_object());
1069 return new(zone()) LStoreCodeEntry(function, code_object);
1073 LInstruction* LChunkBuilder::DoInnerAllocatedObject(
1074 HInnerAllocatedObject* instr) {
1075 LOperand* base_object = UseRegisterAtStart(instr->base_object());
1076 LOperand* offset = UseRegisterOrConstantAtStart(instr->offset());
1077 return DefineAsRegister(
1078 new(zone()) LInnerAllocatedObject(base_object, offset));
1082 LInstruction* LChunkBuilder::DoThisFunction(HThisFunction* instr) {
1083 return instr->HasNoUses()
1085 : DefineAsRegister(new(zone()) LThisFunction);
1089 LInstruction* LChunkBuilder::DoContext(HContext* instr) {
1090 if (instr->HasNoUses()) return NULL;
1092 if (info()->IsStub()) {
1093 return DefineFixed(new(zone()) LContext, esi);
1096 return DefineAsRegister(new(zone()) LContext);
1100 LInstruction* LChunkBuilder::DoDeclareGlobals(HDeclareGlobals* instr) {
1101 LOperand* context = UseFixed(instr->context(), esi);
1102 return MarkAsCall(new(zone()) LDeclareGlobals(context), instr);
1106 LInstruction* LChunkBuilder::DoCallJSFunction(
1107 HCallJSFunction* instr) {
1108 LOperand* function = UseFixed(instr->function(), edi);
1110 LCallJSFunction* result = new(zone()) LCallJSFunction(function);
1112 return MarkAsCall(DefineFixed(result, eax), instr, CANNOT_DEOPTIMIZE_EAGERLY);
1116 LInstruction* LChunkBuilder::DoCallWithDescriptor(
1117 HCallWithDescriptor* instr) {
1118 CallInterfaceDescriptor descriptor = instr->descriptor();
1119 LOperand* target = UseRegisterOrConstantAtStart(instr->target());
1120 ZoneList<LOperand*> ops(instr->OperandCount(), zone());
1121 ops.Add(target, zone());
1122 for (int i = 1; i < instr->OperandCount(); i++) {
1124 UseFixed(instr->OperandAt(i), descriptor.GetParameterRegister(i - 1));
1125 ops.Add(op, zone());
1128 LCallWithDescriptor* result = new(zone()) LCallWithDescriptor(
1129 descriptor, ops, zone());
1130 return MarkAsCall(DefineFixed(result, eax), instr, CANNOT_DEOPTIMIZE_EAGERLY);
1134 LInstruction* LChunkBuilder::DoTailCallThroughMegamorphicCache(
1135 HTailCallThroughMegamorphicCache* instr) {
1136 LOperand* context = UseFixed(instr->context(), esi);
1137 LOperand* receiver_register =
1138 UseFixed(instr->receiver(), LoadDescriptor::ReceiverRegister());
1139 LOperand* name_register =
1140 UseFixed(instr->name(), LoadDescriptor::NameRegister());
1141 // Not marked as call. It can't deoptimize, and it never returns.
1142 return new (zone()) LTailCallThroughMegamorphicCache(
1143 context, receiver_register, name_register);
1147 LInstruction* LChunkBuilder::DoInvokeFunction(HInvokeFunction* instr) {
1148 LOperand* context = UseFixed(instr->context(), esi);
1149 LOperand* function = UseFixed(instr->function(), edi);
1150 LInvokeFunction* result = new(zone()) LInvokeFunction(context, function);
1151 return MarkAsCall(DefineFixed(result, eax), instr, CANNOT_DEOPTIMIZE_EAGERLY);
1155 LInstruction* LChunkBuilder::DoUnaryMathOperation(HUnaryMathOperation* instr) {
1156 switch (instr->op()) {
1158 return DoMathFloor(instr);
1160 return DoMathRound(instr);
1162 return DoMathFround(instr);
1164 return DoMathAbs(instr);
1166 return DoMathLog(instr);
1168 return DoMathExp(instr);
1170 return DoMathSqrt(instr);
1172 return DoMathPowHalf(instr);
1174 return DoMathClz32(instr);
1182 LInstruction* LChunkBuilder::DoMathFloor(HUnaryMathOperation* instr) {
1183 LOperand* input = UseRegisterAtStart(instr->value());
1184 LMathFloor* result = new(zone()) LMathFloor(input);
1185 return AssignEnvironment(DefineAsRegister(result));
1189 LInstruction* LChunkBuilder::DoMathRound(HUnaryMathOperation* instr) {
1190 LOperand* input = UseRegister(instr->value());
1191 LOperand* temp = FixedTemp(xmm4);
1192 LMathRound* result = new(zone()) LMathRound(input, temp);
1193 return AssignEnvironment(DefineAsRegister(result));
1197 LInstruction* LChunkBuilder::DoMathFround(HUnaryMathOperation* instr) {
1198 LOperand* input = UseRegister(instr->value());
1199 LMathFround* result = new (zone()) LMathFround(input);
1200 return DefineAsRegister(result);
1204 LInstruction* LChunkBuilder::DoMathAbs(HUnaryMathOperation* instr) {
1205 LOperand* context = UseAny(instr->context()); // Deferred use.
1206 LOperand* input = UseRegisterAtStart(instr->value());
1207 LInstruction* result =
1208 DefineSameAsFirst(new(zone()) LMathAbs(context, input));
1209 Representation r = instr->value()->representation();
1210 if (!r.IsDouble() && !r.IsSmiOrInteger32()) result = AssignPointerMap(result);
1211 if (!r.IsDouble()) result = AssignEnvironment(result);
1216 LInstruction* LChunkBuilder::DoMathLog(HUnaryMathOperation* instr) {
1217 DCHECK(instr->representation().IsDouble());
1218 DCHECK(instr->value()->representation().IsDouble());
1219 LOperand* input = UseRegisterAtStart(instr->value());
1220 return MarkAsCall(DefineSameAsFirst(new(zone()) LMathLog(input)), instr);
1224 LInstruction* LChunkBuilder::DoMathClz32(HUnaryMathOperation* instr) {
1225 LOperand* input = UseRegisterAtStart(instr->value());
1226 LMathClz32* result = new(zone()) LMathClz32(input);
1227 return DefineAsRegister(result);
1231 LInstruction* LChunkBuilder::DoMathExp(HUnaryMathOperation* instr) {
1232 DCHECK(instr->representation().IsDouble());
1233 DCHECK(instr->value()->representation().IsDouble());
1234 LOperand* value = UseTempRegister(instr->value());
1235 LOperand* temp1 = TempRegister();
1236 LOperand* temp2 = TempRegister();
1237 LMathExp* result = new(zone()) LMathExp(value, temp1, temp2);
1238 return DefineAsRegister(result);
1242 LInstruction* LChunkBuilder::DoMathSqrt(HUnaryMathOperation* instr) {
1243 LOperand* input = UseAtStart(instr->value());
1244 return DefineAsRegister(new(zone()) LMathSqrt(input));
1248 LInstruction* LChunkBuilder::DoMathPowHalf(HUnaryMathOperation* instr) {
1249 LOperand* input = UseRegisterAtStart(instr->value());
1250 LOperand* temp = TempRegister();
1251 LMathPowHalf* result = new(zone()) LMathPowHalf(input, temp);
1252 return DefineSameAsFirst(result);
1256 LInstruction* LChunkBuilder::DoCallNew(HCallNew* instr) {
1257 LOperand* context = UseFixed(instr->context(), esi);
1258 LOperand* constructor = UseFixed(instr->constructor(), edi);
1259 LCallNew* result = new(zone()) LCallNew(context, constructor);
1260 return MarkAsCall(DefineFixed(result, eax), instr);
1264 LInstruction* LChunkBuilder::DoCallNewArray(HCallNewArray* instr) {
1265 LOperand* context = UseFixed(instr->context(), esi);
1266 LOperand* constructor = UseFixed(instr->constructor(), edi);
1267 LCallNewArray* result = new(zone()) LCallNewArray(context, constructor);
1268 return MarkAsCall(DefineFixed(result, eax), instr);
1272 LInstruction* LChunkBuilder::DoCallFunction(HCallFunction* instr) {
1273 LOperand* context = UseFixed(instr->context(), esi);
1274 LOperand* function = UseFixed(instr->function(), edi);
1275 LCallFunction* call = new(zone()) LCallFunction(context, function);
1276 return MarkAsCall(DefineFixed(call, eax), instr);
1280 LInstruction* LChunkBuilder::DoCallRuntime(HCallRuntime* instr) {
1281 LOperand* context = UseFixed(instr->context(), esi);
1282 return MarkAsCall(DefineFixed(new(zone()) LCallRuntime(context), eax), instr);
1286 LInstruction* LChunkBuilder::DoRor(HRor* instr) {
1287 return DoShift(Token::ROR, instr);
1291 LInstruction* LChunkBuilder::DoShr(HShr* instr) {
1292 return DoShift(Token::SHR, instr);
1296 LInstruction* LChunkBuilder::DoSar(HSar* instr) {
1297 return DoShift(Token::SAR, instr);
1301 LInstruction* LChunkBuilder::DoShl(HShl* instr) {
1302 return DoShift(Token::SHL, instr);
1306 LInstruction* LChunkBuilder::DoBitwise(HBitwise* instr) {
1307 if (instr->representation().IsSmiOrInteger32()) {
1308 DCHECK(instr->left()->representation().Equals(instr->representation()));
1309 DCHECK(instr->right()->representation().Equals(instr->representation()));
1310 DCHECK(instr->CheckFlag(HValue::kTruncatingToInt32));
1312 LOperand* left = UseRegisterAtStart(instr->BetterLeftOperand());
1313 LOperand* right = UseOrConstantAtStart(instr->BetterRightOperand());
1314 return DefineSameAsFirst(new(zone()) LBitI(left, right));
1316 return DoArithmeticT(instr->op(), instr);
1321 LInstruction* LChunkBuilder::DoDivByPowerOf2I(HDiv* instr) {
1322 DCHECK(instr->representation().IsSmiOrInteger32());
1323 DCHECK(instr->left()->representation().Equals(instr->representation()));
1324 DCHECK(instr->right()->representation().Equals(instr->representation()));
1325 LOperand* dividend = UseRegister(instr->left());
1326 int32_t divisor = instr->right()->GetInteger32Constant();
1327 LInstruction* result = DefineAsRegister(new(zone()) LDivByPowerOf2I(
1328 dividend, divisor));
1329 if ((instr->CheckFlag(HValue::kBailoutOnMinusZero) && divisor < 0) ||
1330 (instr->CheckFlag(HValue::kCanOverflow) && divisor == -1) ||
1331 (!instr->CheckFlag(HInstruction::kAllUsesTruncatingToInt32) &&
1332 divisor != 1 && divisor != -1)) {
1333 result = AssignEnvironment(result);
1339 LInstruction* LChunkBuilder::DoDivByConstI(HDiv* instr) {
1340 DCHECK(instr->representation().IsInteger32());
1341 DCHECK(instr->left()->representation().Equals(instr->representation()));
1342 DCHECK(instr->right()->representation().Equals(instr->representation()));
1343 LOperand* dividend = UseRegister(instr->left());
1344 int32_t divisor = instr->right()->GetInteger32Constant();
1345 LOperand* temp1 = FixedTemp(eax);
1346 LOperand* temp2 = FixedTemp(edx);
1347 LInstruction* result = DefineFixed(new(zone()) LDivByConstI(
1348 dividend, divisor, temp1, temp2), edx);
1350 (instr->CheckFlag(HValue::kBailoutOnMinusZero) && divisor < 0) ||
1351 !instr->CheckFlag(HInstruction::kAllUsesTruncatingToInt32)) {
1352 result = AssignEnvironment(result);
1358 LInstruction* LChunkBuilder::DoDivI(HDiv* instr) {
1359 DCHECK(instr->representation().IsSmiOrInteger32());
1360 DCHECK(instr->left()->representation().Equals(instr->representation()));
1361 DCHECK(instr->right()->representation().Equals(instr->representation()));
1362 LOperand* dividend = UseFixed(instr->left(), eax);
1363 LOperand* divisor = UseRegister(instr->right());
1364 LOperand* temp = FixedTemp(edx);
1365 LInstruction* result = DefineFixed(new(zone()) LDivI(
1366 dividend, divisor, temp), eax);
1367 if (instr->CheckFlag(HValue::kCanBeDivByZero) ||
1368 instr->CheckFlag(HValue::kBailoutOnMinusZero) ||
1369 instr->CheckFlag(HValue::kCanOverflow) ||
1370 !instr->CheckFlag(HValue::kAllUsesTruncatingToInt32)) {
1371 result = AssignEnvironment(result);
1377 LInstruction* LChunkBuilder::DoDiv(HDiv* instr) {
1378 if (instr->representation().IsSmiOrInteger32()) {
1379 if (instr->RightIsPowerOf2()) {
1380 return DoDivByPowerOf2I(instr);
1381 } else if (instr->right()->IsConstant()) {
1382 return DoDivByConstI(instr);
1384 return DoDivI(instr);
1386 } else if (instr->representation().IsDouble()) {
1387 return DoArithmeticD(Token::DIV, instr);
1389 return DoArithmeticT(Token::DIV, instr);
1394 LInstruction* LChunkBuilder::DoFlooringDivByPowerOf2I(HMathFloorOfDiv* instr) {
1395 LOperand* dividend = UseRegisterAtStart(instr->left());
1396 int32_t divisor = instr->right()->GetInteger32Constant();
1397 LInstruction* result = DefineSameAsFirst(new(zone()) LFlooringDivByPowerOf2I(
1398 dividend, divisor));
1399 if ((instr->CheckFlag(HValue::kBailoutOnMinusZero) && divisor < 0) ||
1400 (instr->CheckFlag(HValue::kLeftCanBeMinInt) && divisor == -1)) {
1401 result = AssignEnvironment(result);
1407 LInstruction* LChunkBuilder::DoFlooringDivByConstI(HMathFloorOfDiv* instr) {
1408 DCHECK(instr->representation().IsInteger32());
1409 DCHECK(instr->left()->representation().Equals(instr->representation()));
1410 DCHECK(instr->right()->representation().Equals(instr->representation()));
1411 LOperand* dividend = UseRegister(instr->left());
1412 int32_t divisor = instr->right()->GetInteger32Constant();
1413 LOperand* temp1 = FixedTemp(eax);
1414 LOperand* temp2 = FixedTemp(edx);
1416 ((divisor > 0 && !instr->CheckFlag(HValue::kLeftCanBeNegative)) ||
1417 (divisor < 0 && !instr->CheckFlag(HValue::kLeftCanBePositive))) ?
1418 NULL : TempRegister();
1419 LInstruction* result =
1420 DefineFixed(new(zone()) LFlooringDivByConstI(dividend,
1427 (instr->CheckFlag(HValue::kBailoutOnMinusZero) && divisor < 0)) {
1428 result = AssignEnvironment(result);
1434 LInstruction* LChunkBuilder::DoFlooringDivI(HMathFloorOfDiv* instr) {
1435 DCHECK(instr->representation().IsSmiOrInteger32());
1436 DCHECK(instr->left()->representation().Equals(instr->representation()));
1437 DCHECK(instr->right()->representation().Equals(instr->representation()));
1438 LOperand* dividend = UseFixed(instr->left(), eax);
1439 LOperand* divisor = UseRegister(instr->right());
1440 LOperand* temp = FixedTemp(edx);
1441 LInstruction* result = DefineFixed(new(zone()) LFlooringDivI(
1442 dividend, divisor, temp), eax);
1443 if (instr->CheckFlag(HValue::kCanBeDivByZero) ||
1444 instr->CheckFlag(HValue::kBailoutOnMinusZero) ||
1445 instr->CheckFlag(HValue::kCanOverflow)) {
1446 result = AssignEnvironment(result);
1452 LInstruction* LChunkBuilder::DoMathFloorOfDiv(HMathFloorOfDiv* instr) {
1453 if (instr->RightIsPowerOf2()) {
1454 return DoFlooringDivByPowerOf2I(instr);
1455 } else if (instr->right()->IsConstant()) {
1456 return DoFlooringDivByConstI(instr);
1458 return DoFlooringDivI(instr);
1463 LInstruction* LChunkBuilder::DoModByPowerOf2I(HMod* instr) {
1464 DCHECK(instr->representation().IsSmiOrInteger32());
1465 DCHECK(instr->left()->representation().Equals(instr->representation()));
1466 DCHECK(instr->right()->representation().Equals(instr->representation()));
1467 LOperand* dividend = UseRegisterAtStart(instr->left());
1468 int32_t divisor = instr->right()->GetInteger32Constant();
1469 LInstruction* result = DefineSameAsFirst(new(zone()) LModByPowerOf2I(
1470 dividend, divisor));
1471 if (instr->CheckFlag(HValue::kLeftCanBeNegative) &&
1472 instr->CheckFlag(HValue::kBailoutOnMinusZero)) {
1473 result = AssignEnvironment(result);
1479 LInstruction* LChunkBuilder::DoModByConstI(HMod* instr) {
1480 DCHECK(instr->representation().IsSmiOrInteger32());
1481 DCHECK(instr->left()->representation().Equals(instr->representation()));
1482 DCHECK(instr->right()->representation().Equals(instr->representation()));
1483 LOperand* dividend = UseRegister(instr->left());
1484 int32_t divisor = instr->right()->GetInteger32Constant();
1485 LOperand* temp1 = FixedTemp(eax);
1486 LOperand* temp2 = FixedTemp(edx);
1487 LInstruction* result = DefineFixed(new(zone()) LModByConstI(
1488 dividend, divisor, temp1, temp2), eax);
1489 if (divisor == 0 || instr->CheckFlag(HValue::kBailoutOnMinusZero)) {
1490 result = AssignEnvironment(result);
1496 LInstruction* LChunkBuilder::DoModI(HMod* instr) {
1497 DCHECK(instr->representation().IsSmiOrInteger32());
1498 DCHECK(instr->left()->representation().Equals(instr->representation()));
1499 DCHECK(instr->right()->representation().Equals(instr->representation()));
1500 LOperand* dividend = UseFixed(instr->left(), eax);
1501 LOperand* divisor = UseRegister(instr->right());
1502 LOperand* temp = FixedTemp(edx);
1503 LInstruction* result = DefineFixed(new(zone()) LModI(
1504 dividend, divisor, temp), edx);
1505 if (instr->CheckFlag(HValue::kCanBeDivByZero) ||
1506 instr->CheckFlag(HValue::kBailoutOnMinusZero)) {
1507 result = AssignEnvironment(result);
1513 LInstruction* LChunkBuilder::DoMod(HMod* instr) {
1514 if (instr->representation().IsSmiOrInteger32()) {
1515 if (instr->RightIsPowerOf2()) {
1516 return DoModByPowerOf2I(instr);
1517 } else if (instr->right()->IsConstant()) {
1518 return DoModByConstI(instr);
1520 return DoModI(instr);
1522 } else if (instr->representation().IsDouble()) {
1523 return DoArithmeticD(Token::MOD, instr);
1525 return DoArithmeticT(Token::MOD, instr);
1530 LInstruction* LChunkBuilder::DoMul(HMul* instr) {
1531 if (instr->representation().IsSmiOrInteger32()) {
1532 DCHECK(instr->left()->representation().Equals(instr->representation()));
1533 DCHECK(instr->right()->representation().Equals(instr->representation()));
1534 LOperand* left = UseRegisterAtStart(instr->BetterLeftOperand());
1535 LOperand* right = UseOrConstant(instr->BetterRightOperand());
1536 LOperand* temp = NULL;
1537 if (instr->CheckFlag(HValue::kBailoutOnMinusZero)) {
1538 temp = TempRegister();
1540 LMulI* mul = new(zone()) LMulI(left, right, temp);
1541 if (instr->CheckFlag(HValue::kCanOverflow) ||
1542 instr->CheckFlag(HValue::kBailoutOnMinusZero)) {
1543 AssignEnvironment(mul);
1545 return DefineSameAsFirst(mul);
1546 } else if (instr->representation().IsDouble()) {
1547 return DoArithmeticD(Token::MUL, instr);
1549 return DoArithmeticT(Token::MUL, instr);
1554 LInstruction* LChunkBuilder::DoSub(HSub* instr) {
1555 if (instr->representation().IsSmiOrInteger32()) {
1556 DCHECK(instr->left()->representation().Equals(instr->representation()));
1557 DCHECK(instr->right()->representation().Equals(instr->representation()));
1558 LOperand* left = UseRegisterAtStart(instr->left());
1559 LOperand* right = UseOrConstantAtStart(instr->right());
1560 LSubI* sub = new(zone()) LSubI(left, right);
1561 LInstruction* result = DefineSameAsFirst(sub);
1562 if (instr->CheckFlag(HValue::kCanOverflow)) {
1563 result = AssignEnvironment(result);
1566 } else if (instr->representation().IsDouble()) {
1567 return DoArithmeticD(Token::SUB, instr);
1569 return DoArithmeticT(Token::SUB, instr);
1574 LInstruction* LChunkBuilder::DoAdd(HAdd* instr) {
1575 if (instr->representation().IsSmiOrInteger32()) {
1576 DCHECK(instr->left()->representation().Equals(instr->representation()));
1577 DCHECK(instr->right()->representation().Equals(instr->representation()));
1578 // Check to see if it would be advantageous to use an lea instruction rather
1579 // than an add. This is the case when no overflow check is needed and there
1580 // are multiple uses of the add's inputs, so using a 3-register add will
1581 // preserve all input values for later uses.
1582 bool use_lea = LAddI::UseLea(instr);
1583 LOperand* left = UseRegisterAtStart(instr->BetterLeftOperand());
1584 HValue* right_candidate = instr->BetterRightOperand();
1585 LOperand* right = use_lea
1586 ? UseRegisterOrConstantAtStart(right_candidate)
1587 : UseOrConstantAtStart(right_candidate);
1588 LAddI* add = new(zone()) LAddI(left, right);
1589 bool can_overflow = instr->CheckFlag(HValue::kCanOverflow);
1590 LInstruction* result = use_lea
1591 ? DefineAsRegister(add)
1592 : DefineSameAsFirst(add);
1594 result = AssignEnvironment(result);
1597 } else if (instr->representation().IsDouble()) {
1598 return DoArithmeticD(Token::ADD, instr);
1599 } else if (instr->representation().IsExternal()) {
1600 DCHECK(instr->left()->representation().IsExternal());
1601 DCHECK(instr->right()->representation().IsInteger32());
1602 DCHECK(!instr->CheckFlag(HValue::kCanOverflow));
1603 bool use_lea = LAddI::UseLea(instr);
1604 LOperand* left = UseRegisterAtStart(instr->left());
1605 HValue* right_candidate = instr->right();
1606 LOperand* right = use_lea
1607 ? UseRegisterOrConstantAtStart(right_candidate)
1608 : UseOrConstantAtStart(right_candidate);
1609 LAddI* add = new(zone()) LAddI(left, right);
1610 LInstruction* result = use_lea
1611 ? DefineAsRegister(add)
1612 : DefineSameAsFirst(add);
1615 return DoArithmeticT(Token::ADD, instr);
1620 LInstruction* LChunkBuilder::DoMathMinMax(HMathMinMax* instr) {
1621 LOperand* left = NULL;
1622 LOperand* right = NULL;
1623 if (instr->representation().IsSmiOrInteger32()) {
1624 DCHECK(instr->left()->representation().Equals(instr->representation()));
1625 DCHECK(instr->right()->representation().Equals(instr->representation()));
1626 left = UseRegisterAtStart(instr->BetterLeftOperand());
1627 right = UseOrConstantAtStart(instr->BetterRightOperand());
1629 DCHECK(instr->representation().IsDouble());
1630 DCHECK(instr->left()->representation().IsDouble());
1631 DCHECK(instr->right()->representation().IsDouble());
1632 left = UseRegisterAtStart(instr->left());
1633 right = UseRegisterAtStart(instr->right());
1635 LMathMinMax* minmax = new(zone()) LMathMinMax(left, right);
1636 return DefineSameAsFirst(minmax);
1640 LInstruction* LChunkBuilder::DoPower(HPower* instr) {
1641 DCHECK(instr->representation().IsDouble());
1642 // We call a C function for double power. It can't trigger a GC.
1643 // We need to use fixed result register for the call.
1644 Representation exponent_type = instr->right()->representation();
1645 DCHECK(instr->left()->representation().IsDouble());
1646 LOperand* left = UseFixedDouble(instr->left(), xmm2);
1648 exponent_type.IsDouble()
1649 ? UseFixedDouble(instr->right(), xmm1)
1650 : UseFixed(instr->right(), MathPowTaggedDescriptor::exponent());
1651 LPower* result = new(zone()) LPower(left, right);
1652 return MarkAsCall(DefineFixedDouble(result, xmm3), instr,
1653 CAN_DEOPTIMIZE_EAGERLY);
1657 LInstruction* LChunkBuilder::DoCompareGeneric(HCompareGeneric* instr) {
1658 DCHECK(instr->left()->representation().IsSmiOrTagged());
1659 DCHECK(instr->right()->representation().IsSmiOrTagged());
1660 LOperand* context = UseFixed(instr->context(), esi);
1661 LOperand* left = UseFixed(instr->left(), edx);
1662 LOperand* right = UseFixed(instr->right(), eax);
1663 LCmpT* result = new(zone()) LCmpT(context, left, right);
1664 return MarkAsCall(DefineFixed(result, eax), instr);
1668 LInstruction* LChunkBuilder::DoCompareNumericAndBranch(
1669 HCompareNumericAndBranch* instr) {
1670 Representation r = instr->representation();
1671 if (r.IsSmiOrInteger32()) {
1672 DCHECK(instr->left()->representation().Equals(r));
1673 DCHECK(instr->right()->representation().Equals(r));
1674 LOperand* left = UseRegisterOrConstantAtStart(instr->left());
1675 LOperand* right = UseOrConstantAtStart(instr->right());
1676 return new(zone()) LCompareNumericAndBranch(left, right);
1678 DCHECK(r.IsDouble());
1679 DCHECK(instr->left()->representation().IsDouble());
1680 DCHECK(instr->right()->representation().IsDouble());
1683 if (CanBeImmediateConstant(instr->left()) &&
1684 CanBeImmediateConstant(instr->right())) {
1685 // The code generator requires either both inputs to be constant
1686 // operands, or neither.
1687 left = UseConstant(instr->left());
1688 right = UseConstant(instr->right());
1690 left = UseRegisterAtStart(instr->left());
1691 right = UseRegisterAtStart(instr->right());
1693 return new(zone()) LCompareNumericAndBranch(left, right);
1698 LInstruction* LChunkBuilder::DoCompareObjectEqAndBranch(
1699 HCompareObjectEqAndBranch* instr) {
1700 LOperand* left = UseRegisterAtStart(instr->left());
1701 LOperand* right = UseOrConstantAtStart(instr->right());
1702 return new(zone()) LCmpObjectEqAndBranch(left, right);
1706 LInstruction* LChunkBuilder::DoCompareHoleAndBranch(
1707 HCompareHoleAndBranch* instr) {
1708 LOperand* value = UseRegisterAtStart(instr->value());
1709 return new(zone()) LCmpHoleAndBranch(value);
1713 LInstruction* LChunkBuilder::DoCompareMinusZeroAndBranch(
1714 HCompareMinusZeroAndBranch* instr) {
1715 LOperand* value = UseRegister(instr->value());
1716 LOperand* scratch = TempRegister();
1717 return new(zone()) LCompareMinusZeroAndBranch(value, scratch);
1721 LInstruction* LChunkBuilder::DoIsObjectAndBranch(HIsObjectAndBranch* instr) {
1722 DCHECK(instr->value()->representation().IsSmiOrTagged());
1723 LOperand* temp = TempRegister();
1724 return new(zone()) LIsObjectAndBranch(UseRegister(instr->value()), temp);
1728 LInstruction* LChunkBuilder::DoIsStringAndBranch(HIsStringAndBranch* instr) {
1729 DCHECK(instr->value()->representation().IsTagged());
1730 LOperand* temp = TempRegister();
1731 return new(zone()) LIsStringAndBranch(UseRegister(instr->value()), temp);
1735 LInstruction* LChunkBuilder::DoIsSmiAndBranch(HIsSmiAndBranch* instr) {
1736 DCHECK(instr->value()->representation().IsTagged());
1737 return new(zone()) LIsSmiAndBranch(Use(instr->value()));
1741 LInstruction* LChunkBuilder::DoIsUndetectableAndBranch(
1742 HIsUndetectableAndBranch* instr) {
1743 DCHECK(instr->value()->representation().IsTagged());
1744 return new(zone()) LIsUndetectableAndBranch(
1745 UseRegisterAtStart(instr->value()), TempRegister());
1749 LInstruction* LChunkBuilder::DoStringCompareAndBranch(
1750 HStringCompareAndBranch* instr) {
1751 DCHECK(instr->left()->representation().IsTagged());
1752 DCHECK(instr->right()->representation().IsTagged());
1753 LOperand* context = UseFixed(instr->context(), esi);
1754 LOperand* left = UseFixed(instr->left(), edx);
1755 LOperand* right = UseFixed(instr->right(), eax);
1757 LStringCompareAndBranch* result = new(zone())
1758 LStringCompareAndBranch(context, left, right);
1760 return MarkAsCall(result, instr);
1764 LInstruction* LChunkBuilder::DoHasInstanceTypeAndBranch(
1765 HHasInstanceTypeAndBranch* instr) {
1766 DCHECK(instr->value()->representation().IsTagged());
1767 return new(zone()) LHasInstanceTypeAndBranch(
1768 UseRegisterAtStart(instr->value()),
1773 LInstruction* LChunkBuilder::DoGetCachedArrayIndex(
1774 HGetCachedArrayIndex* instr) {
1775 DCHECK(instr->value()->representation().IsTagged());
1776 LOperand* value = UseRegisterAtStart(instr->value());
1778 return DefineAsRegister(new(zone()) LGetCachedArrayIndex(value));
1782 LInstruction* LChunkBuilder::DoHasCachedArrayIndexAndBranch(
1783 HHasCachedArrayIndexAndBranch* instr) {
1784 DCHECK(instr->value()->representation().IsTagged());
1785 return new(zone()) LHasCachedArrayIndexAndBranch(
1786 UseRegisterAtStart(instr->value()));
1790 LInstruction* LChunkBuilder::DoClassOfTestAndBranch(
1791 HClassOfTestAndBranch* instr) {
1792 DCHECK(instr->value()->representation().IsTagged());
1793 return new(zone()) LClassOfTestAndBranch(UseRegister(instr->value()),
1799 LInstruction* LChunkBuilder::DoMapEnumLength(HMapEnumLength* instr) {
1800 LOperand* map = UseRegisterAtStart(instr->value());
1801 return DefineAsRegister(new(zone()) LMapEnumLength(map));
1805 LInstruction* LChunkBuilder::DoDateField(HDateField* instr) {
1806 LOperand* date = UseFixed(instr->value(), eax);
1807 LDateField* result =
1808 new(zone()) LDateField(date, FixedTemp(ecx), instr->index());
1809 return MarkAsCall(DefineFixed(result, eax), instr, CAN_DEOPTIMIZE_EAGERLY);
1813 LInstruction* LChunkBuilder::DoSeqStringGetChar(HSeqStringGetChar* instr) {
1814 LOperand* string = UseRegisterAtStart(instr->string());
1815 LOperand* index = UseRegisterOrConstantAtStart(instr->index());
1816 return DefineAsRegister(new(zone()) LSeqStringGetChar(string, index));
1820 LOperand* LChunkBuilder::GetSeqStringSetCharOperand(HSeqStringSetChar* instr) {
1821 if (instr->encoding() == String::ONE_BYTE_ENCODING) {
1822 if (FLAG_debug_code) {
1823 return UseFixed(instr->value(), eax);
1825 return UseFixedOrConstant(instr->value(), eax);
1828 if (FLAG_debug_code) {
1829 return UseRegisterAtStart(instr->value());
1831 return UseRegisterOrConstantAtStart(instr->value());
1837 LInstruction* LChunkBuilder::DoSeqStringSetChar(HSeqStringSetChar* instr) {
1838 LOperand* string = UseRegisterAtStart(instr->string());
1839 LOperand* index = FLAG_debug_code
1840 ? UseRegisterAtStart(instr->index())
1841 : UseRegisterOrConstantAtStart(instr->index());
1842 LOperand* value = GetSeqStringSetCharOperand(instr);
1843 LOperand* context = FLAG_debug_code ? UseFixed(instr->context(), esi) : NULL;
1844 LInstruction* result = new(zone()) LSeqStringSetChar(context, string,
1846 if (FLAG_debug_code) {
1847 result = MarkAsCall(result, instr);
1853 LInstruction* LChunkBuilder::DoBoundsCheck(HBoundsCheck* instr) {
1854 if (!FLAG_debug_code && instr->skip_check()) return NULL;
1855 LOperand* index = UseRegisterOrConstantAtStart(instr->index());
1856 LOperand* length = !index->IsConstantOperand()
1857 ? UseOrConstantAtStart(instr->length())
1858 : UseAtStart(instr->length());
1859 LInstruction* result = new(zone()) LBoundsCheck(index, length);
1860 if (!FLAG_debug_code || !instr->skip_check()) {
1861 result = AssignEnvironment(result);
1867 LInstruction* LChunkBuilder::DoBoundsCheckBaseIndexInformation(
1868 HBoundsCheckBaseIndexInformation* instr) {
1874 LInstruction* LChunkBuilder::DoAbnormalExit(HAbnormalExit* instr) {
1875 // The control instruction marking the end of a block that completed
1876 // abruptly (e.g., threw an exception). There is nothing specific to do.
1881 LInstruction* LChunkBuilder::DoUseConst(HUseConst* instr) {
1886 LInstruction* LChunkBuilder::DoForceRepresentation(HForceRepresentation* bad) {
1887 // All HForceRepresentation instructions should be eliminated in the
1888 // representation change phase of Hydrogen.
1894 LInstruction* LChunkBuilder::DoChange(HChange* instr) {
1895 Representation from = instr->from();
1896 Representation to = instr->to();
1897 HValue* val = instr->value();
1899 if (to.IsTagged()) {
1900 LOperand* value = UseRegister(val);
1901 return DefineSameAsFirst(new(zone()) LDummyUse(value));
1903 from = Representation::Tagged();
1905 if (from.IsTagged()) {
1906 if (to.IsDouble()) {
1907 LOperand* value = UseRegister(val);
1908 LOperand* temp = TempRegister();
1909 LInstruction* result =
1910 DefineAsRegister(new(zone()) LNumberUntagD(value, temp));
1911 if (!val->representation().IsSmi()) result = AssignEnvironment(result);
1913 } else if (to.IsSmi()) {
1914 LOperand* value = UseRegister(val);
1915 if (val->type().IsSmi()) {
1916 return DefineSameAsFirst(new(zone()) LDummyUse(value));
1918 return AssignEnvironment(DefineSameAsFirst(new(zone()) LCheckSmi(value)));
1920 DCHECK(to.IsInteger32());
1921 if (val->type().IsSmi() || val->representation().IsSmi()) {
1922 LOperand* value = UseRegister(val);
1923 return DefineSameAsFirst(new(zone()) LSmiUntag(value, false));
1925 LOperand* value = UseRegister(val);
1926 bool truncating = instr->CanTruncateToInt32();
1927 LOperand* xmm_temp = !truncating ? FixedTemp(xmm1) : NULL;
1928 LInstruction* result =
1929 DefineSameAsFirst(new(zone()) LTaggedToI(value, xmm_temp));
1930 if (!val->representation().IsSmi()) result = AssignEnvironment(result);
1934 } else if (from.IsDouble()) {
1935 if (to.IsTagged()) {
1936 info()->MarkAsDeferredCalling();
1937 LOperand* value = UseRegisterAtStart(val);
1938 LOperand* temp = FLAG_inline_new ? TempRegister() : NULL;
1939 LUnallocated* result_temp = TempRegister();
1940 LNumberTagD* result = new(zone()) LNumberTagD(value, temp);
1941 return AssignPointerMap(Define(result, result_temp));
1942 } else if (to.IsSmi()) {
1943 LOperand* value = UseRegister(val);
1944 return AssignEnvironment(
1945 DefineAsRegister(new(zone()) LDoubleToSmi(value)));
1947 DCHECK(to.IsInteger32());
1948 bool truncating = instr->CanTruncateToInt32();
1949 bool needs_temp = !truncating;
1950 LOperand* value = needs_temp ? UseTempRegister(val) : UseRegister(val);
1951 LOperand* temp = needs_temp ? TempRegister() : NULL;
1952 LInstruction* result =
1953 DefineAsRegister(new(zone()) LDoubleToI(value, temp));
1954 if (!truncating) result = AssignEnvironment(result);
1957 } else if (from.IsInteger32()) {
1958 info()->MarkAsDeferredCalling();
1959 if (to.IsTagged()) {
1960 LOperand* value = UseRegister(val);
1961 if (!instr->CheckFlag(HValue::kCanOverflow)) {
1962 return DefineSameAsFirst(new(zone()) LSmiTag(value));
1963 } else if (val->CheckFlag(HInstruction::kUint32)) {
1964 LOperand* temp = TempRegister();
1965 LNumberTagU* result = new(zone()) LNumberTagU(value, temp);
1966 return AssignPointerMap(DefineSameAsFirst(result));
1968 LOperand* temp = TempRegister();
1969 LNumberTagI* result = new(zone()) LNumberTagI(value, temp);
1970 return AssignPointerMap(DefineSameAsFirst(result));
1972 } else if (to.IsSmi()) {
1973 LOperand* value = UseRegister(val);
1974 LInstruction* result = DefineSameAsFirst(new(zone()) LSmiTag(value));
1975 if (instr->CheckFlag(HValue::kCanOverflow)) {
1976 result = AssignEnvironment(result);
1980 DCHECK(to.IsDouble());
1981 if (val->CheckFlag(HInstruction::kUint32)) {
1982 return DefineAsRegister(new(zone()) LUint32ToDouble(UseRegister(val)));
1984 return DefineAsRegister(new(zone()) LInteger32ToDouble(Use(val)));
1993 LInstruction* LChunkBuilder::DoCheckHeapObject(HCheckHeapObject* instr) {
1994 LOperand* value = UseAtStart(instr->value());
1995 LInstruction* result = new(zone()) LCheckNonSmi(value);
1996 if (!instr->value()->type().IsHeapObject()) {
1997 result = AssignEnvironment(result);
2003 LInstruction* LChunkBuilder::DoCheckSmi(HCheckSmi* instr) {
2004 LOperand* value = UseRegisterAtStart(instr->value());
2005 return AssignEnvironment(new(zone()) LCheckSmi(value));
2009 LInstruction* LChunkBuilder::DoCheckInstanceType(HCheckInstanceType* instr) {
2010 LOperand* value = UseRegisterAtStart(instr->value());
2011 LOperand* temp = TempRegister();
2012 LCheckInstanceType* result = new(zone()) LCheckInstanceType(value, temp);
2013 return AssignEnvironment(result);
2017 LInstruction* LChunkBuilder::DoCheckValue(HCheckValue* instr) {
2018 // If the object is in new space, we'll emit a global cell compare and so
2019 // want the value in a register. If the object gets promoted before we
2020 // emit code, we will still get the register but will do an immediate
2021 // compare instead of the cell compare. This is safe.
2022 LOperand* value = instr->object_in_new_space()
2023 ? UseRegisterAtStart(instr->value()) : UseAtStart(instr->value());
2024 return AssignEnvironment(new(zone()) LCheckValue(value));
2028 LInstruction* LChunkBuilder::DoCheckMaps(HCheckMaps* instr) {
2029 if (instr->IsStabilityCheck()) return new(zone()) LCheckMaps;
2030 LOperand* value = UseRegisterAtStart(instr->value());
2031 LInstruction* result = AssignEnvironment(new(zone()) LCheckMaps(value));
2032 if (instr->HasMigrationTarget()) {
2033 info()->MarkAsDeferredCalling();
2034 result = AssignPointerMap(result);
2040 LInstruction* LChunkBuilder::DoClampToUint8(HClampToUint8* instr) {
2041 HValue* value = instr->value();
2042 Representation input_rep = value->representation();
2043 if (input_rep.IsDouble()) {
2044 LOperand* reg = UseRegister(value);
2045 return DefineFixed(new(zone()) LClampDToUint8(reg), eax);
2046 } else if (input_rep.IsInteger32()) {
2047 LOperand* reg = UseFixed(value, eax);
2048 return DefineFixed(new(zone()) LClampIToUint8(reg), eax);
2050 DCHECK(input_rep.IsSmiOrTagged());
2051 LOperand* reg = UseFixed(value, eax);
2052 // Register allocator doesn't (yet) support allocation of double
2053 // temps. Reserve xmm1 explicitly.
2054 LOperand* temp = FixedTemp(xmm1);
2055 LClampTToUint8* result = new(zone()) LClampTToUint8(reg, temp);
2056 return AssignEnvironment(DefineFixed(result, eax));
2061 LInstruction* LChunkBuilder::DoDoubleBits(HDoubleBits* instr) {
2062 HValue* value = instr->value();
2063 DCHECK(value->representation().IsDouble());
2064 return DefineAsRegister(new(zone()) LDoubleBits(UseRegister(value)));
2068 LInstruction* LChunkBuilder::DoConstructDouble(HConstructDouble* instr) {
2069 LOperand* lo = UseRegister(instr->lo());
2070 LOperand* hi = UseRegister(instr->hi());
2071 return DefineAsRegister(new(zone()) LConstructDouble(hi, lo));
2075 LInstruction* LChunkBuilder::DoReturn(HReturn* instr) {
2076 LOperand* context = info()->IsStub() ? UseFixed(instr->context(), esi) : NULL;
2077 LOperand* parameter_count = UseRegisterOrConstant(instr->parameter_count());
2078 return new(zone()) LReturn(
2079 UseFixed(instr->value(), eax), context, parameter_count);
2083 LInstruction* LChunkBuilder::DoConstant(HConstant* instr) {
2084 Representation r = instr->representation();
2086 return DefineAsRegister(new(zone()) LConstantS);
2087 } else if (r.IsInteger32()) {
2088 return DefineAsRegister(new(zone()) LConstantI);
2089 } else if (r.IsDouble()) {
2090 double value = instr->DoubleValue();
2091 bool value_is_zero = bit_cast<uint64_t, double>(value) == 0;
2092 LOperand* temp = value_is_zero ? NULL : TempRegister();
2093 return DefineAsRegister(new(zone()) LConstantD(temp));
2094 } else if (r.IsExternal()) {
2095 return DefineAsRegister(new(zone()) LConstantE);
2096 } else if (r.IsTagged()) {
2097 return DefineAsRegister(new(zone()) LConstantT);
2105 LInstruction* LChunkBuilder::DoLoadGlobalCell(HLoadGlobalCell* instr) {
2106 LLoadGlobalCell* result = new(zone()) LLoadGlobalCell;
2107 return instr->RequiresHoleCheck()
2108 ? AssignEnvironment(DefineAsRegister(result))
2109 : DefineAsRegister(result);
2113 LInstruction* LChunkBuilder::DoLoadGlobalGeneric(HLoadGlobalGeneric* instr) {
2114 LOperand* context = UseFixed(instr->context(), esi);
2115 LOperand* global_object =
2116 UseFixed(instr->global_object(), LoadDescriptor::ReceiverRegister());
2117 LOperand* vector = NULL;
2118 if (FLAG_vector_ics) {
2119 vector = FixedTemp(VectorLoadICDescriptor::VectorRegister());
2122 LLoadGlobalGeneric* result =
2123 new(zone()) LLoadGlobalGeneric(context, global_object, vector);
2124 return MarkAsCall(DefineFixed(result, eax), instr);
2128 LInstruction* LChunkBuilder::DoStoreGlobalCell(HStoreGlobalCell* instr) {
2129 LStoreGlobalCell* result =
2130 new(zone()) LStoreGlobalCell(UseRegister(instr->value()));
2131 return instr->RequiresHoleCheck() ? AssignEnvironment(result) : result;
2135 LInstruction* LChunkBuilder::DoLoadContextSlot(HLoadContextSlot* instr) {
2136 LOperand* context = UseRegisterAtStart(instr->value());
2137 LInstruction* result =
2138 DefineAsRegister(new(zone()) LLoadContextSlot(context));
2139 if (instr->RequiresHoleCheck() && instr->DeoptimizesOnHole()) {
2140 result = AssignEnvironment(result);
2146 LInstruction* LChunkBuilder::DoStoreContextSlot(HStoreContextSlot* instr) {
2149 LOperand* context = UseRegister(instr->context());
2150 if (instr->NeedsWriteBarrier()) {
2151 value = UseTempRegister(instr->value());
2152 temp = TempRegister();
2154 value = UseRegister(instr->value());
2157 LInstruction* result = new(zone()) LStoreContextSlot(context, value, temp);
2158 if (instr->RequiresHoleCheck() && instr->DeoptimizesOnHole()) {
2159 result = AssignEnvironment(result);
2165 LInstruction* LChunkBuilder::DoLoadNamedField(HLoadNamedField* instr) {
2166 LOperand* obj = (instr->access().IsExternalMemory() &&
2167 instr->access().offset() == 0)
2168 ? UseRegisterOrConstantAtStart(instr->object())
2169 : UseRegisterAtStart(instr->object());
2170 return DefineAsRegister(new(zone()) LLoadNamedField(obj));
2174 LInstruction* LChunkBuilder::DoLoadNamedGeneric(HLoadNamedGeneric* instr) {
2175 LOperand* context = UseFixed(instr->context(), esi);
2177 UseFixed(instr->object(), LoadDescriptor::ReceiverRegister());
2178 LOperand* vector = NULL;
2179 if (FLAG_vector_ics) {
2180 vector = FixedTemp(VectorLoadICDescriptor::VectorRegister());
2182 LLoadNamedGeneric* result = new(zone()) LLoadNamedGeneric(
2183 context, object, vector);
2184 return MarkAsCall(DefineFixed(result, eax), instr);
2188 LInstruction* LChunkBuilder::DoLoadFunctionPrototype(
2189 HLoadFunctionPrototype* instr) {
2190 return AssignEnvironment(DefineAsRegister(
2191 new(zone()) LLoadFunctionPrototype(UseRegister(instr->function()),
2196 LInstruction* LChunkBuilder::DoLoadRoot(HLoadRoot* instr) {
2197 return DefineAsRegister(new(zone()) LLoadRoot);
2201 LInstruction* LChunkBuilder::DoLoadKeyed(HLoadKeyed* instr) {
2202 DCHECK(instr->key()->representation().IsSmiOrInteger32());
2203 ElementsKind elements_kind = instr->elements_kind();
2204 bool clobbers_key = ExternalArrayOpRequiresTemp(
2205 instr->key()->representation(), elements_kind);
2206 LOperand* key = clobbers_key
2207 ? UseTempRegister(instr->key())
2208 : UseRegisterOrConstantAtStart(instr->key());
2209 LInstruction* result = NULL;
2211 if (!instr->is_typed_elements()) {
2212 LOperand* obj = UseRegisterAtStart(instr->elements());
2213 result = DefineAsRegister(new(zone()) LLoadKeyed(obj, key));
2216 (instr->representation().IsInteger32() &&
2217 !(IsDoubleOrFloatElementsKind(instr->elements_kind()))) ||
2218 (instr->representation().IsDouble() &&
2219 (IsDoubleOrFloatElementsKind(instr->elements_kind()))));
2220 LOperand* backing_store = UseRegister(instr->elements());
2221 result = DefineAsRegister(new(zone()) LLoadKeyed(backing_store, key));
2224 if ((instr->is_external() || instr->is_fixed_typed_array()) ?
2225 // see LCodeGen::DoLoadKeyedExternalArray
2226 ((instr->elements_kind() == EXTERNAL_UINT32_ELEMENTS ||
2227 instr->elements_kind() == UINT32_ELEMENTS) &&
2228 !instr->CheckFlag(HInstruction::kUint32)) :
2229 // see LCodeGen::DoLoadKeyedFixedDoubleArray and
2230 // LCodeGen::DoLoadKeyedFixedArray
2231 instr->RequiresHoleCheck()) {
2232 result = AssignEnvironment(result);
2238 LInstruction* LChunkBuilder::DoLoadKeyedGeneric(HLoadKeyedGeneric* instr) {
2239 LOperand* context = UseFixed(instr->context(), esi);
2241 UseFixed(instr->object(), LoadDescriptor::ReceiverRegister());
2242 LOperand* key = UseFixed(instr->key(), LoadDescriptor::NameRegister());
2243 LOperand* vector = NULL;
2244 if (FLAG_vector_ics) {
2245 vector = FixedTemp(VectorLoadICDescriptor::VectorRegister());
2247 LLoadKeyedGeneric* result =
2248 new(zone()) LLoadKeyedGeneric(context, object, key, vector);
2249 return MarkAsCall(DefineFixed(result, eax), instr);
2253 LOperand* LChunkBuilder::GetStoreKeyedValueOperand(HStoreKeyed* instr) {
2254 ElementsKind elements_kind = instr->elements_kind();
2256 // Determine if we need a byte register in this case for the value.
2257 bool val_is_fixed_register =
2258 elements_kind == EXTERNAL_INT8_ELEMENTS ||
2259 elements_kind == EXTERNAL_UINT8_ELEMENTS ||
2260 elements_kind == EXTERNAL_UINT8_CLAMPED_ELEMENTS ||
2261 elements_kind == UINT8_ELEMENTS ||
2262 elements_kind == INT8_ELEMENTS ||
2263 elements_kind == UINT8_CLAMPED_ELEMENTS;
2264 if (val_is_fixed_register) {
2265 return UseFixed(instr->value(), eax);
2268 return UseRegister(instr->value());
2272 LInstruction* LChunkBuilder::DoStoreKeyed(HStoreKeyed* instr) {
2273 if (!instr->is_typed_elements()) {
2274 DCHECK(instr->elements()->representation().IsTagged());
2275 DCHECK(instr->key()->representation().IsInteger32() ||
2276 instr->key()->representation().IsSmi());
2278 if (instr->value()->representation().IsDouble()) {
2279 LOperand* object = UseRegisterAtStart(instr->elements());
2280 LOperand* val = NULL;
2281 val = UseRegisterAtStart(instr->value());
2282 LOperand* key = UseRegisterOrConstantAtStart(instr->key());
2283 return new(zone()) LStoreKeyed(object, key, val);
2285 DCHECK(instr->value()->representation().IsSmiOrTagged());
2286 bool needs_write_barrier = instr->NeedsWriteBarrier();
2288 LOperand* obj = UseRegister(instr->elements());
2291 if (needs_write_barrier) {
2292 val = UseTempRegister(instr->value());
2293 key = UseTempRegister(instr->key());
2295 val = UseRegisterOrConstantAtStart(instr->value());
2296 key = UseRegisterOrConstantAtStart(instr->key());
2298 return new(zone()) LStoreKeyed(obj, key, val);
2302 ElementsKind elements_kind = instr->elements_kind();
2304 (instr->value()->representation().IsInteger32() &&
2305 !IsDoubleOrFloatElementsKind(elements_kind)) ||
2306 (instr->value()->representation().IsDouble() &&
2307 IsDoubleOrFloatElementsKind(elements_kind)));
2308 DCHECK((instr->is_fixed_typed_array() &&
2309 instr->elements()->representation().IsTagged()) ||
2310 (instr->is_external() &&
2311 instr->elements()->representation().IsExternal()));
2313 LOperand* backing_store = UseRegister(instr->elements());
2314 LOperand* val = GetStoreKeyedValueOperand(instr);
2315 bool clobbers_key = ExternalArrayOpRequiresTemp(
2316 instr->key()->representation(), elements_kind);
2317 LOperand* key = clobbers_key
2318 ? UseTempRegister(instr->key())
2319 : UseRegisterOrConstantAtStart(instr->key());
2320 return new(zone()) LStoreKeyed(backing_store, key, val);
2324 LInstruction* LChunkBuilder::DoStoreKeyedGeneric(HStoreKeyedGeneric* instr) {
2325 LOperand* context = UseFixed(instr->context(), esi);
2327 UseFixed(instr->object(), StoreDescriptor::ReceiverRegister());
2328 LOperand* key = UseFixed(instr->key(), StoreDescriptor::NameRegister());
2329 LOperand* value = UseFixed(instr->value(), StoreDescriptor::ValueRegister());
2331 DCHECK(instr->object()->representation().IsTagged());
2332 DCHECK(instr->key()->representation().IsTagged());
2333 DCHECK(instr->value()->representation().IsTagged());
2335 LStoreKeyedGeneric* result =
2336 new(zone()) LStoreKeyedGeneric(context, object, key, value);
2337 return MarkAsCall(result, instr);
2341 LInstruction* LChunkBuilder::DoTransitionElementsKind(
2342 HTransitionElementsKind* instr) {
2343 if (IsSimpleMapChangeTransition(instr->from_kind(), instr->to_kind())) {
2344 LOperand* object = UseRegister(instr->object());
2345 LOperand* new_map_reg = TempRegister();
2346 LOperand* temp_reg = TempRegister();
2347 LTransitionElementsKind* result =
2348 new(zone()) LTransitionElementsKind(object, NULL,
2349 new_map_reg, temp_reg);
2352 LOperand* object = UseFixed(instr->object(), eax);
2353 LOperand* context = UseFixed(instr->context(), esi);
2354 LTransitionElementsKind* result =
2355 new(zone()) LTransitionElementsKind(object, context, NULL, NULL);
2356 return MarkAsCall(result, instr);
2361 LInstruction* LChunkBuilder::DoTrapAllocationMemento(
2362 HTrapAllocationMemento* instr) {
2363 LOperand* object = UseRegister(instr->object());
2364 LOperand* temp = TempRegister();
2365 LTrapAllocationMemento* result =
2366 new(zone()) LTrapAllocationMemento(object, temp);
2367 return AssignEnvironment(result);
2371 LInstruction* LChunkBuilder::DoStoreNamedField(HStoreNamedField* instr) {
2372 bool is_in_object = instr->access().IsInobject();
2373 bool is_external_location = instr->access().IsExternalMemory() &&
2374 instr->access().offset() == 0;
2375 bool needs_write_barrier = instr->NeedsWriteBarrier();
2376 bool needs_write_barrier_for_map = instr->has_transition() &&
2377 instr->NeedsWriteBarrierForMap();
2380 if (needs_write_barrier) {
2382 ? UseRegister(instr->object())
2383 : UseTempRegister(instr->object());
2384 } else if (is_external_location) {
2385 DCHECK(!is_in_object);
2386 DCHECK(!needs_write_barrier);
2387 DCHECK(!needs_write_barrier_for_map);
2388 obj = UseRegisterOrConstant(instr->object());
2390 obj = needs_write_barrier_for_map
2391 ? UseRegister(instr->object())
2392 : UseRegisterAtStart(instr->object());
2395 bool can_be_constant = instr->value()->IsConstant() &&
2396 HConstant::cast(instr->value())->NotInNewSpace() &&
2397 !instr->field_representation().IsDouble();
2400 if (instr->field_representation().IsInteger8() ||
2401 instr->field_representation().IsUInteger8()) {
2402 // mov_b requires a byte register (i.e. any of eax, ebx, ecx, edx).
2403 // Just force the value to be in eax and we're safe here.
2404 val = UseFixed(instr->value(), eax);
2405 } else if (needs_write_barrier) {
2406 val = UseTempRegister(instr->value());
2407 } else if (can_be_constant) {
2408 val = UseRegisterOrConstant(instr->value());
2409 } else if (instr->field_representation().IsDouble()) {
2410 val = UseRegisterAtStart(instr->value());
2412 val = UseRegister(instr->value());
2415 // We only need a scratch register if we have a write barrier or we
2416 // have a store into the properties array (not in-object-property).
2417 LOperand* temp = (!is_in_object || needs_write_barrier ||
2418 needs_write_barrier_for_map) ? TempRegister() : NULL;
2420 // We need a temporary register for write barrier of the map field.
2421 LOperand* temp_map = needs_write_barrier_for_map ? TempRegister() : NULL;
2423 return new(zone()) LStoreNamedField(obj, val, temp, temp_map);
2427 LInstruction* LChunkBuilder::DoStoreNamedGeneric(HStoreNamedGeneric* instr) {
2428 LOperand* context = UseFixed(instr->context(), esi);
2430 UseFixed(instr->object(), StoreDescriptor::ReceiverRegister());
2431 LOperand* value = UseFixed(instr->value(), StoreDescriptor::ValueRegister());
2433 LStoreNamedGeneric* result =
2434 new(zone()) LStoreNamedGeneric(context, object, value);
2435 return MarkAsCall(result, instr);
2439 LInstruction* LChunkBuilder::DoStringAdd(HStringAdd* instr) {
2440 LOperand* context = UseFixed(instr->context(), esi);
2441 LOperand* left = UseFixed(instr->left(), edx);
2442 LOperand* right = UseFixed(instr->right(), eax);
2443 LStringAdd* string_add = new(zone()) LStringAdd(context, left, right);
2444 return MarkAsCall(DefineFixed(string_add, eax), instr);
2448 LInstruction* LChunkBuilder::DoStringCharCodeAt(HStringCharCodeAt* instr) {
2449 LOperand* string = UseTempRegister(instr->string());
2450 LOperand* index = UseTempRegister(instr->index());
2451 LOperand* context = UseAny(instr->context());
2452 LStringCharCodeAt* result =
2453 new(zone()) LStringCharCodeAt(context, string, index);
2454 return AssignPointerMap(DefineAsRegister(result));
2458 LInstruction* LChunkBuilder::DoStringCharFromCode(HStringCharFromCode* instr) {
2459 LOperand* char_code = UseRegister(instr->value());
2460 LOperand* context = UseAny(instr->context());
2461 LStringCharFromCode* result =
2462 new(zone()) LStringCharFromCode(context, char_code);
2463 return AssignPointerMap(DefineAsRegister(result));
2467 LInstruction* LChunkBuilder::DoAllocate(HAllocate* instr) {
2468 info()->MarkAsDeferredCalling();
2469 LOperand* context = UseAny(instr->context());
2470 LOperand* size = instr->size()->IsConstant()
2471 ? UseConstant(instr->size())
2472 : UseTempRegister(instr->size());
2473 LOperand* temp = TempRegister();
2474 LAllocate* result = new(zone()) LAllocate(context, size, temp);
2475 return AssignPointerMap(DefineAsRegister(result));
2479 LInstruction* LChunkBuilder::DoRegExpLiteral(HRegExpLiteral* instr) {
2480 LOperand* context = UseFixed(instr->context(), esi);
2482 DefineFixed(new(zone()) LRegExpLiteral(context), eax), instr);
2486 LInstruction* LChunkBuilder::DoFunctionLiteral(HFunctionLiteral* instr) {
2487 LOperand* context = UseFixed(instr->context(), esi);
2489 DefineFixed(new(zone()) LFunctionLiteral(context), eax), instr);
2493 LInstruction* LChunkBuilder::DoOsrEntry(HOsrEntry* instr) {
2494 DCHECK(argument_count_ == 0);
2495 allocator_->MarkAsOsrEntry();
2496 current_block_->last_environment()->set_ast_id(instr->ast_id());
2497 return AssignEnvironment(new(zone()) LOsrEntry);
2501 LInstruction* LChunkBuilder::DoParameter(HParameter* instr) {
2502 LParameter* result = new(zone()) LParameter;
2503 if (instr->kind() == HParameter::STACK_PARAMETER) {
2504 int spill_index = chunk()->GetParameterStackSlot(instr->index());
2505 return DefineAsSpilled(result, spill_index);
2507 DCHECK(info()->IsStub());
2508 CallInterfaceDescriptor descriptor =
2509 info()->code_stub()->GetCallInterfaceDescriptor();
2510 int index = static_cast<int>(instr->index());
2511 Register reg = descriptor.GetEnvironmentParameterRegister(index);
2512 return DefineFixed(result, reg);
2517 LInstruction* LChunkBuilder::DoUnknownOSRValue(HUnknownOSRValue* instr) {
2518 // Use an index that corresponds to the location in the unoptimized frame,
2519 // which the optimized frame will subsume.
2520 int env_index = instr->index();
2521 int spill_index = 0;
2522 if (instr->environment()->is_parameter_index(env_index)) {
2523 spill_index = chunk()->GetParameterStackSlot(env_index);
2525 spill_index = env_index - instr->environment()->first_local_index();
2526 if (spill_index > LUnallocated::kMaxFixedSlotIndex) {
2527 Retry(kNotEnoughSpillSlotsForOsr);
2530 if (spill_index == 0) {
2531 // The dynamic frame alignment state overwrites the first local.
2532 // The first local is saved at the end of the unoptimized frame.
2533 spill_index = graph()->osr()->UnoptimizedFrameSlots();
2536 return DefineAsSpilled(new(zone()) LUnknownOSRValue, spill_index);
2540 LInstruction* LChunkBuilder::DoCallStub(HCallStub* instr) {
2541 LOperand* context = UseFixed(instr->context(), esi);
2542 LCallStub* result = new(zone()) LCallStub(context);
2543 return MarkAsCall(DefineFixed(result, eax), instr);
2547 LInstruction* LChunkBuilder::DoArgumentsObject(HArgumentsObject* instr) {
2548 // There are no real uses of the arguments object.
2549 // arguments.length and element access are supported directly on
2550 // stack arguments, and any real arguments object use causes a bailout.
2551 // So this value is never used.
2556 LInstruction* LChunkBuilder::DoCapturedObject(HCapturedObject* instr) {
2557 instr->ReplayEnvironment(current_block_->last_environment());
2559 // There are no real uses of a captured object.
2564 LInstruction* LChunkBuilder::DoAccessArgumentsAt(HAccessArgumentsAt* instr) {
2565 info()->MarkAsRequiresFrame();
2566 LOperand* args = UseRegister(instr->arguments());
2569 if (instr->length()->IsConstant() && instr->index()->IsConstant()) {
2570 length = UseRegisterOrConstant(instr->length());
2571 index = UseOrConstant(instr->index());
2573 length = UseTempRegister(instr->length());
2574 index = Use(instr->index());
2576 return DefineAsRegister(new(zone()) LAccessArgumentsAt(args, length, index));
2580 LInstruction* LChunkBuilder::DoToFastProperties(HToFastProperties* instr) {
2581 LOperand* object = UseFixed(instr->value(), eax);
2582 LToFastProperties* result = new(zone()) LToFastProperties(object);
2583 return MarkAsCall(DefineFixed(result, eax), instr);
2587 LInstruction* LChunkBuilder::DoTypeof(HTypeof* instr) {
2588 LOperand* context = UseFixed(instr->context(), esi);
2589 LOperand* value = UseAtStart(instr->value());
2590 LTypeof* result = new(zone()) LTypeof(context, value);
2591 return MarkAsCall(DefineFixed(result, eax), instr);
2595 LInstruction* LChunkBuilder::DoTypeofIsAndBranch(HTypeofIsAndBranch* instr) {
2596 return new(zone()) LTypeofIsAndBranch(UseTempRegister(instr->value()));
2600 LInstruction* LChunkBuilder::DoIsConstructCallAndBranch(
2601 HIsConstructCallAndBranch* instr) {
2602 return new(zone()) LIsConstructCallAndBranch(TempRegister());
2606 LInstruction* LChunkBuilder::DoSimulate(HSimulate* instr) {
2607 instr->ReplayEnvironment(current_block_->last_environment());
2612 LInstruction* LChunkBuilder::DoStackCheck(HStackCheck* instr) {
2613 info()->MarkAsDeferredCalling();
2614 if (instr->is_function_entry()) {
2615 LOperand* context = UseFixed(instr->context(), esi);
2616 return MarkAsCall(new(zone()) LStackCheck(context), instr);
2618 DCHECK(instr->is_backwards_branch());
2619 LOperand* context = UseAny(instr->context());
2620 return AssignEnvironment(
2621 AssignPointerMap(new(zone()) LStackCheck(context)));
2626 LInstruction* LChunkBuilder::DoEnterInlined(HEnterInlined* instr) {
2627 HEnvironment* outer = current_block_->last_environment();
2628 outer->set_ast_id(instr->ReturnId());
2629 HConstant* undefined = graph()->GetConstantUndefined();
2630 HEnvironment* inner = outer->CopyForInlining(instr->closure(),
2631 instr->arguments_count(),
2634 instr->inlining_kind());
2635 // Only replay binding of arguments object if it wasn't removed from graph.
2636 if (instr->arguments_var() != NULL && instr->arguments_object()->IsLinked()) {
2637 inner->Bind(instr->arguments_var(), instr->arguments_object());
2639 inner->BindContext(instr->closure_context());
2640 inner->set_entry(instr);
2641 current_block_->UpdateEnvironment(inner);
2642 chunk_->AddInlinedClosure(instr->closure());
2647 LInstruction* LChunkBuilder::DoLeaveInlined(HLeaveInlined* instr) {
2648 LInstruction* pop = NULL;
2650 HEnvironment* env = current_block_->last_environment();
2652 if (env->entry()->arguments_pushed()) {
2653 int argument_count = env->arguments_environment()->parameter_count();
2654 pop = new(zone()) LDrop(argument_count);
2655 DCHECK(instr->argument_delta() == -argument_count);
2658 HEnvironment* outer = current_block_->last_environment()->
2659 DiscardInlined(false);
2660 current_block_->UpdateEnvironment(outer);
2665 LInstruction* LChunkBuilder::DoForInPrepareMap(HForInPrepareMap* instr) {
2666 LOperand* context = UseFixed(instr->context(), esi);
2667 LOperand* object = UseFixed(instr->enumerable(), eax);
2668 LForInPrepareMap* result = new(zone()) LForInPrepareMap(context, object);
2669 return MarkAsCall(DefineFixed(result, eax), instr, CAN_DEOPTIMIZE_EAGERLY);
2673 LInstruction* LChunkBuilder::DoForInCacheArray(HForInCacheArray* instr) {
2674 LOperand* map = UseRegister(instr->map());
2675 return AssignEnvironment(DefineAsRegister(
2676 new(zone()) LForInCacheArray(map)));
2680 LInstruction* LChunkBuilder::DoCheckMapValue(HCheckMapValue* instr) {
2681 LOperand* value = UseRegisterAtStart(instr->value());
2682 LOperand* map = UseRegisterAtStart(instr->map());
2683 return AssignEnvironment(new(zone()) LCheckMapValue(value, map));
2687 LInstruction* LChunkBuilder::DoLoadFieldByIndex(HLoadFieldByIndex* instr) {
2688 LOperand* object = UseRegister(instr->object());
2689 LOperand* index = UseTempRegister(instr->index());
2690 LLoadFieldByIndex* load = new(zone()) LLoadFieldByIndex(object, index);
2691 LInstruction* result = DefineSameAsFirst(load);
2692 return AssignPointerMap(result);
2696 LInstruction* LChunkBuilder::DoStoreFrameContext(HStoreFrameContext* instr) {
2697 LOperand* context = UseRegisterAtStart(instr->context());
2698 return new(zone()) LStoreFrameContext(context);
2702 LInstruction* LChunkBuilder::DoAllocateBlockContext(
2703 HAllocateBlockContext* instr) {
2704 LOperand* context = UseFixed(instr->context(), esi);
2705 LOperand* function = UseRegisterAtStart(instr->function());
2706 LAllocateBlockContext* result =
2707 new(zone()) LAllocateBlockContext(context, function);
2708 return MarkAsCall(DefineFixed(result, esi), instr);
2712 } } // namespace v8::internal
2714 #endif // V8_TARGET_ARCH_IA32