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.
5 #include "src/ia32/lithium-ia32.h"
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 LIsStringAndBranch::PrintDataTo(StringStream* stream) {
193 stream->Add("if is_string(");
194 value()->PrintTo(stream);
195 stream->Add(") then B%d else B%d", true_block_id(), false_block_id());
199 void LIsSmiAndBranch::PrintDataTo(StringStream* stream) {
200 stream->Add("if is_smi(");
201 value()->PrintTo(stream);
202 stream->Add(") then B%d else B%d", true_block_id(), false_block_id());
206 void LIsUndetectableAndBranch::PrintDataTo(StringStream* stream) {
207 stream->Add("if is_undetectable(");
208 value()->PrintTo(stream);
209 stream->Add(") then B%d else B%d", true_block_id(), false_block_id());
213 void LStringCompareAndBranch::PrintDataTo(StringStream* stream) {
214 stream->Add("if string_compare(");
215 left()->PrintTo(stream);
216 right()->PrintTo(stream);
217 stream->Add(") then B%d else B%d", true_block_id(), false_block_id());
221 void LHasInstanceTypeAndBranch::PrintDataTo(StringStream* stream) {
222 stream->Add("if has_instance_type(");
223 value()->PrintTo(stream);
224 stream->Add(") then B%d else B%d", true_block_id(), false_block_id());
228 void LHasCachedArrayIndexAndBranch::PrintDataTo(StringStream* stream) {
229 stream->Add("if has_cached_array_index(");
230 value()->PrintTo(stream);
231 stream->Add(") then B%d else B%d", true_block_id(), false_block_id());
235 void LClassOfTestAndBranch::PrintDataTo(StringStream* stream) {
236 stream->Add("if class_of_test(");
237 value()->PrintTo(stream);
238 stream->Add(", \"%o\") then B%d else B%d",
239 *hydrogen()->class_name(),
245 void LTypeofIsAndBranch::PrintDataTo(StringStream* stream) {
246 stream->Add("if typeof ");
247 value()->PrintTo(stream);
248 stream->Add(" == \"%s\" then B%d else B%d",
249 hydrogen()->type_literal()->ToCString().get(),
250 true_block_id(), false_block_id());
254 void LStoreCodeEntry::PrintDataTo(StringStream* stream) {
256 function()->PrintTo(stream);
257 stream->Add(".code_entry = ");
258 code_object()->PrintTo(stream);
262 void LInnerAllocatedObject::PrintDataTo(StringStream* stream) {
264 base_object()->PrintTo(stream);
266 offset()->PrintTo(stream);
270 void LCallFunction::PrintDataTo(StringStream* stream) {
271 context()->PrintTo(stream);
273 function()->PrintTo(stream);
274 if (hydrogen()->HasVectorAndSlot()) {
275 stream->Add(" (type-feedback-vector ");
276 temp_vector()->PrintTo(stream);
278 temp_slot()->PrintTo(stream);
284 void LCallJSFunction::PrintDataTo(StringStream* stream) {
286 function()->PrintTo(stream);
287 stream->Add("#%d / ", arity());
291 void LCallWithDescriptor::PrintDataTo(StringStream* stream) {
292 for (int i = 0; i < InputCount(); i++) {
293 InputAt(i)->PrintTo(stream);
296 stream->Add("#%d / ", arity());
300 void LLoadContextSlot::PrintDataTo(StringStream* stream) {
301 context()->PrintTo(stream);
302 stream->Add("[%d]", slot_index());
306 void LStoreContextSlot::PrintDataTo(StringStream* stream) {
307 context()->PrintTo(stream);
308 stream->Add("[%d] <- ", slot_index());
309 value()->PrintTo(stream);
313 void LInvokeFunction::PrintDataTo(StringStream* stream) {
315 context()->PrintTo(stream);
317 function()->PrintTo(stream);
318 stream->Add(" #%d / ", arity());
322 void LCallNew::PrintDataTo(StringStream* stream) {
324 context()->PrintTo(stream);
326 constructor()->PrintTo(stream);
327 stream->Add(" #%d / ", arity());
331 void LCallNewArray::PrintDataTo(StringStream* stream) {
333 context()->PrintTo(stream);
335 constructor()->PrintTo(stream);
336 stream->Add(" #%d / ", arity());
337 ElementsKind kind = hydrogen()->elements_kind();
338 stream->Add(" (%s) ", ElementsKindToString(kind));
342 void LAccessArgumentsAt::PrintDataTo(StringStream* stream) {
343 arguments()->PrintTo(stream);
345 stream->Add(" length ");
346 length()->PrintTo(stream);
348 stream->Add(" index ");
349 index()->PrintTo(stream);
353 int LPlatformChunk::GetNextSpillIndex(RegisterKind kind) {
354 // Skip a slot if for a double-width slot.
355 if (kind == DOUBLE_REGISTERS) {
357 spill_slot_count_ |= 1;
360 return spill_slot_count_++;
364 LOperand* LPlatformChunk::GetNextSpillSlot(RegisterKind kind) {
365 int index = GetNextSpillIndex(kind);
366 if (kind == DOUBLE_REGISTERS) {
367 return LDoubleStackSlot::Create(index, zone());
369 DCHECK(kind == GENERAL_REGISTERS);
370 return LStackSlot::Create(index, zone());
375 void LLoadGlobalViaContext::PrintDataTo(StringStream* stream) {
376 stream->Add("depth:%d slot:%d", depth(), slot_index());
380 void LStoreNamedField::PrintDataTo(StringStream* stream) {
381 object()->PrintTo(stream);
382 std::ostringstream os;
383 os << hydrogen()->access() << " <- ";
384 stream->Add(os.str().c_str());
385 value()->PrintTo(stream);
389 void LStoreNamedGeneric::PrintDataTo(StringStream* stream) {
390 object()->PrintTo(stream);
392 stream->Add(String::cast(*name())->ToCString().get());
394 value()->PrintTo(stream);
398 void LStoreGlobalViaContext::PrintDataTo(StringStream* stream) {
399 stream->Add("depth:%d slot:%d <- ", depth(), slot_index());
400 value()->PrintTo(stream);
404 void LLoadKeyed::PrintDataTo(StringStream* stream) {
405 elements()->PrintTo(stream);
407 key()->PrintTo(stream);
408 if (hydrogen()->IsDehoisted()) {
409 stream->Add(" + %d]", base_offset());
416 void LStoreKeyed::PrintDataTo(StringStream* stream) {
417 elements()->PrintTo(stream);
419 key()->PrintTo(stream);
420 if (hydrogen()->IsDehoisted()) {
421 stream->Add(" + %d] <-", base_offset());
423 stream->Add("] <- ");
426 if (value() == NULL) {
427 DCHECK(hydrogen()->IsConstantHoleStore() &&
428 hydrogen()->value()->representation().IsDouble());
429 stream->Add("<the hole(nan)>");
431 value()->PrintTo(stream);
436 void LStoreKeyedGeneric::PrintDataTo(StringStream* stream) {
437 object()->PrintTo(stream);
439 key()->PrintTo(stream);
440 stream->Add("] <- ");
441 value()->PrintTo(stream);
445 void LTransitionElementsKind::PrintDataTo(StringStream* stream) {
446 object()->PrintTo(stream);
447 stream->Add(" %p -> %p", *original_map(), *transitioned_map());
451 LPlatformChunk* LChunkBuilder::Build() {
453 chunk_ = new(zone()) LPlatformChunk(info(), graph());
454 LPhase phase("L_Building chunk", chunk_);
457 // Reserve the first spill slot for the state of dynamic alignment.
458 if (info()->IsOptimizing()) {
459 int alignment_state_index = chunk_->GetNextSpillIndex(GENERAL_REGISTERS);
460 DCHECK_EQ(alignment_state_index, 0);
461 USE(alignment_state_index);
464 // If compiling for OSR, reserve space for the unoptimized frame,
465 // which will be subsumed into this frame.
466 if (graph()->has_osr()) {
467 for (int i = graph()->osr()->UnoptimizedFrameSlots(); i > 0; i--) {
468 chunk_->GetNextSpillIndex(GENERAL_REGISTERS);
472 const ZoneList<HBasicBlock*>* blocks = graph()->blocks();
473 for (int i = 0; i < blocks->length(); i++) {
474 HBasicBlock* next = NULL;
475 if (i < blocks->length() - 1) next = blocks->at(i + 1);
476 DoBasicBlock(blocks->at(i), next);
477 if (is_aborted()) return NULL;
484 LUnallocated* LChunkBuilder::ToUnallocated(Register reg) {
485 return new(zone()) LUnallocated(LUnallocated::FIXED_REGISTER,
486 Register::ToAllocationIndex(reg));
490 LUnallocated* LChunkBuilder::ToUnallocated(XMMRegister reg) {
491 return new(zone()) LUnallocated(LUnallocated::FIXED_DOUBLE_REGISTER,
492 XMMRegister::ToAllocationIndex(reg));
496 LOperand* LChunkBuilder::UseFixed(HValue* value, Register fixed_register) {
497 return Use(value, ToUnallocated(fixed_register));
501 LOperand* LChunkBuilder::UseFixedDouble(HValue* value, XMMRegister reg) {
502 return Use(value, ToUnallocated(reg));
506 LOperand* LChunkBuilder::UseRegister(HValue* value) {
507 return Use(value, new(zone()) LUnallocated(LUnallocated::MUST_HAVE_REGISTER));
511 LOperand* LChunkBuilder::UseRegisterAtStart(HValue* value) {
513 new(zone()) LUnallocated(LUnallocated::MUST_HAVE_REGISTER,
514 LUnallocated::USED_AT_START));
518 LOperand* LChunkBuilder::UseTempRegister(HValue* value) {
519 return Use(value, new(zone()) LUnallocated(LUnallocated::WRITABLE_REGISTER));
523 LOperand* LChunkBuilder::Use(HValue* value) {
524 return Use(value, new(zone()) LUnallocated(LUnallocated::NONE));
528 LOperand* LChunkBuilder::UseAtStart(HValue* value) {
529 return Use(value, new(zone()) LUnallocated(LUnallocated::NONE,
530 LUnallocated::USED_AT_START));
534 static inline bool CanBeImmediateConstant(HValue* value) {
535 return value->IsConstant() && HConstant::cast(value)->NotInNewSpace();
539 LOperand* LChunkBuilder::UseOrConstant(HValue* value) {
540 return CanBeImmediateConstant(value)
541 ? chunk_->DefineConstantOperand(HConstant::cast(value))
546 LOperand* LChunkBuilder::UseOrConstantAtStart(HValue* value) {
547 return CanBeImmediateConstant(value)
548 ? chunk_->DefineConstantOperand(HConstant::cast(value))
553 LOperand* LChunkBuilder::UseFixedOrConstant(HValue* value,
554 Register fixed_register) {
555 return CanBeImmediateConstant(value)
556 ? chunk_->DefineConstantOperand(HConstant::cast(value))
557 : UseFixed(value, fixed_register);
561 LOperand* LChunkBuilder::UseRegisterOrConstant(HValue* value) {
562 return CanBeImmediateConstant(value)
563 ? chunk_->DefineConstantOperand(HConstant::cast(value))
564 : UseRegister(value);
568 LOperand* LChunkBuilder::UseRegisterOrConstantAtStart(HValue* value) {
569 return CanBeImmediateConstant(value)
570 ? chunk_->DefineConstantOperand(HConstant::cast(value))
571 : UseRegisterAtStart(value);
575 LOperand* LChunkBuilder::UseConstant(HValue* value) {
576 return chunk_->DefineConstantOperand(HConstant::cast(value));
580 LOperand* LChunkBuilder::UseAny(HValue* value) {
581 return value->IsConstant()
582 ? chunk_->DefineConstantOperand(HConstant::cast(value))
583 : Use(value, new(zone()) LUnallocated(LUnallocated::ANY));
587 LOperand* LChunkBuilder::Use(HValue* value, LUnallocated* operand) {
588 if (value->EmitAtUses()) {
589 HInstruction* instr = HInstruction::cast(value);
590 VisitInstruction(instr);
592 operand->set_virtual_register(value->id());
597 LInstruction* LChunkBuilder::Define(LTemplateResultInstruction<1>* instr,
598 LUnallocated* result) {
599 result->set_virtual_register(current_instruction_->id());
600 instr->set_result(result);
605 LInstruction* LChunkBuilder::DefineAsRegister(
606 LTemplateResultInstruction<1>* instr) {
608 new(zone()) LUnallocated(LUnallocated::MUST_HAVE_REGISTER));
612 LInstruction* LChunkBuilder::DefineAsSpilled(
613 LTemplateResultInstruction<1>* instr,
616 new(zone()) LUnallocated(LUnallocated::FIXED_SLOT, index));
620 LInstruction* LChunkBuilder::DefineSameAsFirst(
621 LTemplateResultInstruction<1>* instr) {
623 new(zone()) LUnallocated(LUnallocated::SAME_AS_FIRST_INPUT));
627 LInstruction* LChunkBuilder::DefineFixed(LTemplateResultInstruction<1>* instr,
629 return Define(instr, ToUnallocated(reg));
633 LInstruction* LChunkBuilder::DefineFixedDouble(
634 LTemplateResultInstruction<1>* instr,
636 return Define(instr, ToUnallocated(reg));
640 LInstruction* LChunkBuilder::AssignEnvironment(LInstruction* instr) {
641 HEnvironment* hydrogen_env = current_block_->last_environment();
642 int argument_index_accumulator = 0;
643 ZoneList<HValue*> objects_to_materialize(0, zone());
644 instr->set_environment(CreateEnvironment(
645 hydrogen_env, &argument_index_accumulator, &objects_to_materialize));
650 LInstruction* LChunkBuilder::MarkAsCall(LInstruction* instr,
651 HInstruction* hinstr,
652 CanDeoptimize can_deoptimize) {
653 info()->MarkAsNonDeferredCalling();
659 instr = AssignPointerMap(instr);
661 // If instruction does not have side-effects lazy deoptimization
662 // after the call will try to deoptimize to the point before the call.
663 // Thus we still need to attach environment to this call even if
664 // call sequence can not deoptimize eagerly.
665 bool needs_environment =
666 (can_deoptimize == CAN_DEOPTIMIZE_EAGERLY) ||
667 !hinstr->HasObservableSideEffects();
668 if (needs_environment && !instr->HasEnvironment()) {
669 instr = AssignEnvironment(instr);
670 // We can't really figure out if the environment is needed or not.
671 instr->environment()->set_has_been_used();
678 LInstruction* LChunkBuilder::AssignPointerMap(LInstruction* instr) {
679 DCHECK(!instr->HasPointerMap());
680 instr->set_pointer_map(new(zone()) LPointerMap(zone()));
685 LUnallocated* LChunkBuilder::TempRegister() {
686 LUnallocated* operand =
687 new(zone()) LUnallocated(LUnallocated::MUST_HAVE_REGISTER);
688 int vreg = allocator_->GetVirtualRegister();
689 if (!allocator_->AllocationOk()) {
690 Abort(kOutOfVirtualRegistersWhileTryingToAllocateTempRegister);
693 operand->set_virtual_register(vreg);
698 LOperand* LChunkBuilder::FixedTemp(Register reg) {
699 LUnallocated* operand = ToUnallocated(reg);
700 DCHECK(operand->HasFixedPolicy());
705 LOperand* LChunkBuilder::FixedTemp(XMMRegister reg) {
706 LUnallocated* operand = ToUnallocated(reg);
707 DCHECK(operand->HasFixedPolicy());
712 LInstruction* LChunkBuilder::DoBlockEntry(HBlockEntry* instr) {
713 return new(zone()) LLabel(instr->block());
717 LInstruction* LChunkBuilder::DoDummyUse(HDummyUse* instr) {
718 return DefineAsRegister(new(zone()) LDummyUse(UseAny(instr->value())));
722 LInstruction* LChunkBuilder::DoEnvironmentMarker(HEnvironmentMarker* instr) {
728 LInstruction* LChunkBuilder::DoDeoptimize(HDeoptimize* instr) {
729 return AssignEnvironment(new(zone()) LDeoptimize);
733 LInstruction* LChunkBuilder::DoShift(Token::Value op,
734 HBitwiseBinaryOperation* instr) {
735 if (instr->representation().IsSmiOrInteger32()) {
736 DCHECK(instr->left()->representation().Equals(instr->representation()));
737 DCHECK(instr->right()->representation().Equals(instr->representation()));
738 LOperand* left = UseRegisterAtStart(instr->left());
740 HValue* right_value = instr->right();
741 LOperand* right = NULL;
742 int constant_value = 0;
743 bool does_deopt = false;
744 if (right_value->IsConstant()) {
745 HConstant* constant = HConstant::cast(right_value);
746 right = chunk_->DefineConstantOperand(constant);
747 constant_value = constant->Integer32Value() & 0x1f;
748 // Left shifts can deoptimize if we shift by > 0 and the result cannot be
750 if (instr->representation().IsSmi() && constant_value > 0) {
751 does_deopt = !instr->CheckUsesForFlag(HValue::kTruncatingToSmi);
754 right = UseFixed(right_value, ecx);
757 // Shift operations can only deoptimize if we do a logical shift by 0 and
758 // the result cannot be truncated to int32.
759 if (op == Token::SHR && constant_value == 0) {
760 does_deopt = !instr->CheckFlag(HInstruction::kUint32);
763 LInstruction* result =
764 DefineSameAsFirst(new(zone()) LShiftI(op, left, right, does_deopt));
765 return does_deopt ? AssignEnvironment(result) : result;
767 return DoArithmeticT(op, instr);
772 LInstruction* LChunkBuilder::DoArithmeticD(Token::Value op,
773 HArithmeticBinaryOperation* instr) {
774 DCHECK(instr->representation().IsDouble());
775 DCHECK(instr->left()->representation().IsDouble());
776 DCHECK(instr->right()->representation().IsDouble());
777 if (op == Token::MOD) {
778 LOperand* left = UseRegisterAtStart(instr->BetterLeftOperand());
779 LOperand* right = UseRegisterAtStart(instr->BetterRightOperand());
780 LArithmeticD* result = new(zone()) LArithmeticD(op, left, right);
781 return MarkAsCall(DefineSameAsFirst(result), instr);
783 LOperand* left = UseRegisterAtStart(instr->BetterLeftOperand());
784 LOperand* right = UseRegisterAtStart(instr->BetterRightOperand());
785 LArithmeticD* result = new(zone()) LArithmeticD(op, left, right);
786 return CpuFeatures::IsSupported(AVX) ? DefineAsRegister(result)
787 : DefineSameAsFirst(result);
792 LInstruction* LChunkBuilder::DoArithmeticT(Token::Value op,
793 HBinaryOperation* instr) {
794 HValue* left = instr->left();
795 HValue* right = instr->right();
796 DCHECK(left->representation().IsTagged());
797 DCHECK(right->representation().IsTagged());
798 LOperand* context = UseFixed(instr->context(), esi);
799 LOperand* left_operand = UseFixed(left, edx);
800 LOperand* right_operand = UseFixed(right, eax);
801 LArithmeticT* result =
802 new(zone()) LArithmeticT(op, context, left_operand, right_operand);
803 return MarkAsCall(DefineFixed(result, eax), instr);
807 void LChunkBuilder::DoBasicBlock(HBasicBlock* block, HBasicBlock* next_block) {
808 DCHECK(is_building());
809 current_block_ = block;
810 next_block_ = next_block;
811 if (block->IsStartBlock()) {
812 block->UpdateEnvironment(graph_->start_environment());
814 } else if (block->predecessors()->length() == 1) {
815 // We have a single predecessor => copy environment and outgoing
816 // argument count from the predecessor.
817 DCHECK(block->phis()->length() == 0);
818 HBasicBlock* pred = block->predecessors()->at(0);
819 HEnvironment* last_environment = pred->last_environment();
820 DCHECK(last_environment != NULL);
821 // Only copy the environment, if it is later used again.
822 if (pred->end()->SecondSuccessor() == NULL) {
823 DCHECK(pred->end()->FirstSuccessor() == block);
825 if (pred->end()->FirstSuccessor()->block_id() > block->block_id() ||
826 pred->end()->SecondSuccessor()->block_id() > block->block_id()) {
827 last_environment = last_environment->Copy();
830 block->UpdateEnvironment(last_environment);
831 DCHECK(pred->argument_count() >= 0);
832 argument_count_ = pred->argument_count();
834 // We are at a state join => process phis.
835 HBasicBlock* pred = block->predecessors()->at(0);
836 // No need to copy the environment, it cannot be used later.
837 HEnvironment* last_environment = pred->last_environment();
838 for (int i = 0; i < block->phis()->length(); ++i) {
839 HPhi* phi = block->phis()->at(i);
840 if (phi->HasMergedIndex()) {
841 last_environment->SetValueAt(phi->merged_index(), phi);
844 for (int i = 0; i < block->deleted_phis()->length(); ++i) {
845 if (block->deleted_phis()->at(i) < last_environment->length()) {
846 last_environment->SetValueAt(block->deleted_phis()->at(i),
847 graph_->GetConstantUndefined());
850 block->UpdateEnvironment(last_environment);
851 // Pick up the outgoing argument count of one of the predecessors.
852 argument_count_ = pred->argument_count();
854 HInstruction* current = block->first();
855 int start = chunk_->instructions()->length();
856 while (current != NULL && !is_aborted()) {
857 // Code for constants in registers is generated lazily.
858 if (!current->EmitAtUses()) {
859 VisitInstruction(current);
861 current = current->next();
863 int end = chunk_->instructions()->length() - 1;
865 block->set_first_instruction_index(start);
866 block->set_last_instruction_index(end);
868 block->set_argument_count(argument_count_);
870 current_block_ = NULL;
874 void LChunkBuilder::VisitInstruction(HInstruction* current) {
875 HInstruction* old_current = current_instruction_;
876 current_instruction_ = current;
878 LInstruction* instr = NULL;
879 if (current->CanReplaceWithDummyUses()) {
880 if (current->OperandCount() == 0) {
881 instr = DefineAsRegister(new(zone()) LDummy());
883 DCHECK(!current->OperandAt(0)->IsControlInstruction());
884 instr = DefineAsRegister(new(zone())
885 LDummyUse(UseAny(current->OperandAt(0))));
887 for (int i = 1; i < current->OperandCount(); ++i) {
888 if (current->OperandAt(i)->IsControlInstruction()) continue;
889 LInstruction* dummy =
890 new(zone()) LDummyUse(UseAny(current->OperandAt(i)));
891 dummy->set_hydrogen_value(current);
892 chunk_->AddInstruction(dummy, current_block_);
895 HBasicBlock* successor;
896 if (current->IsControlInstruction() &&
897 HControlInstruction::cast(current)->KnownSuccessorBlock(&successor) &&
899 instr = new(zone()) LGoto(successor);
901 instr = current->CompileToLithium(this);
905 argument_count_ += current->argument_delta();
906 DCHECK(argument_count_ >= 0);
909 AddInstruction(instr, current);
912 current_instruction_ = old_current;
916 void LChunkBuilder::AddInstruction(LInstruction* instr,
917 HInstruction* hydrogen_val) {
918 // Associate the hydrogen instruction first, since we may need it for
919 // the ClobbersRegisters() or ClobbersDoubleRegisters() calls below.
920 instr->set_hydrogen_value(hydrogen_val);
923 // Make sure that the lithium instruction has either no fixed register
924 // constraints in temps or the result OR no uses that are only used at
925 // start. If this invariant doesn't hold, the register allocator can decide
926 // to insert a split of a range immediately before the instruction due to an
927 // already allocated register needing to be used for the instruction's fixed
928 // register constraint. In this case, The register allocator won't see an
929 // interference between the split child and the use-at-start (it would if
930 // the it was just a plain use), so it is free to move the split child into
931 // the same register that is used for the use-at-start.
932 // See https://code.google.com/p/chromium/issues/detail?id=201590
933 if (!(instr->ClobbersRegisters() &&
934 instr->ClobbersDoubleRegisters(isolate()))) {
936 int used_at_start = 0;
937 for (UseIterator it(instr); !it.Done(); it.Advance()) {
938 LUnallocated* operand = LUnallocated::cast(it.Current());
939 if (operand->IsUsedAtStart()) ++used_at_start;
941 if (instr->Output() != NULL) {
942 if (LUnallocated::cast(instr->Output())->HasFixedPolicy()) ++fixed;
944 for (TempIterator it(instr); !it.Done(); it.Advance()) {
945 LUnallocated* operand = LUnallocated::cast(it.Current());
946 if (operand->HasFixedPolicy()) ++fixed;
948 DCHECK(fixed == 0 || used_at_start == 0);
952 if (FLAG_stress_pointer_maps && !instr->HasPointerMap()) {
953 instr = AssignPointerMap(instr);
955 if (FLAG_stress_environments && !instr->HasEnvironment()) {
956 instr = AssignEnvironment(instr);
958 chunk_->AddInstruction(instr, current_block_);
960 if (instr->IsCall() || instr->IsPrologue()) {
961 HValue* hydrogen_value_for_lazy_bailout = hydrogen_val;
962 if (hydrogen_val->HasObservableSideEffects()) {
963 HSimulate* sim = HSimulate::cast(hydrogen_val->next());
964 sim->ReplayEnvironment(current_block_->last_environment());
965 hydrogen_value_for_lazy_bailout = sim;
967 LInstruction* bailout = AssignEnvironment(new(zone()) LLazyBailout());
968 bailout->set_hydrogen_value(hydrogen_value_for_lazy_bailout);
969 chunk_->AddInstruction(bailout, current_block_);
974 LInstruction* LChunkBuilder::DoPrologue(HPrologue* instr) {
975 return new (zone()) LPrologue();
979 LInstruction* LChunkBuilder::DoGoto(HGoto* instr) {
980 return new(zone()) LGoto(instr->FirstSuccessor());
984 LInstruction* LChunkBuilder::DoBranch(HBranch* instr) {
985 HValue* value = instr->value();
986 Representation r = value->representation();
987 HType type = value->type();
988 ToBooleanStub::Types expected = instr->expected_input_types();
989 if (expected.IsEmpty()) expected = ToBooleanStub::Types::Generic();
991 bool easy_case = !r.IsTagged() || type.IsBoolean() || type.IsSmi() ||
992 type.IsJSArray() || type.IsHeapNumber() || type.IsString();
993 LOperand* temp = !easy_case && expected.NeedsMap() ? TempRegister() : NULL;
994 LInstruction* branch = new(zone()) LBranch(UseRegister(value), temp);
996 ((!expected.Contains(ToBooleanStub::SMI) && expected.NeedsMap()) ||
997 !expected.IsGeneric())) {
998 branch = AssignEnvironment(branch);
1004 LInstruction* LChunkBuilder::DoDebugBreak(HDebugBreak* instr) {
1005 return new(zone()) LDebugBreak();
1009 LInstruction* LChunkBuilder::DoCompareMap(HCompareMap* instr) {
1010 DCHECK(instr->value()->representation().IsTagged());
1011 LOperand* value = UseRegisterAtStart(instr->value());
1012 return new(zone()) LCmpMapAndBranch(value);
1016 LInstruction* LChunkBuilder::DoArgumentsLength(HArgumentsLength* length) {
1017 info()->MarkAsRequiresFrame();
1018 return DefineAsRegister(new(zone()) LArgumentsLength(Use(length->value())));
1022 LInstruction* LChunkBuilder::DoArgumentsElements(HArgumentsElements* elems) {
1023 info()->MarkAsRequiresFrame();
1024 return DefineAsRegister(new(zone()) LArgumentsElements);
1028 LInstruction* LChunkBuilder::DoInstanceOf(HInstanceOf* instr) {
1030 UseFixed(instr->left(), InstanceOfDescriptor::LeftRegister());
1032 UseFixed(instr->right(), InstanceOfDescriptor::RightRegister());
1033 LOperand* context = UseFixed(instr->context(), esi);
1034 LInstanceOf* result = new (zone()) LInstanceOf(context, left, right);
1035 return MarkAsCall(DefineFixed(result, eax), instr);
1039 LInstruction* LChunkBuilder::DoHasInPrototypeChainAndBranch(
1040 HHasInPrototypeChainAndBranch* instr) {
1041 LOperand* object = UseRegister(instr->object());
1042 LOperand* prototype = UseRegister(instr->prototype());
1043 LOperand* temp = TempRegister();
1044 return new (zone()) LHasInPrototypeChainAndBranch(object, prototype, temp);
1048 LInstruction* LChunkBuilder::DoWrapReceiver(HWrapReceiver* instr) {
1049 LOperand* receiver = UseRegister(instr->receiver());
1050 LOperand* function = UseRegister(instr->function());
1051 LOperand* temp = TempRegister();
1052 LWrapReceiver* result =
1053 new(zone()) LWrapReceiver(receiver, function, temp);
1054 return AssignEnvironment(DefineSameAsFirst(result));
1058 LInstruction* LChunkBuilder::DoApplyArguments(HApplyArguments* instr) {
1059 LOperand* function = UseFixed(instr->function(), edi);
1060 LOperand* receiver = UseFixed(instr->receiver(), eax);
1061 LOperand* length = UseFixed(instr->length(), ebx);
1062 LOperand* elements = UseFixed(instr->elements(), ecx);
1063 LApplyArguments* result = new(zone()) LApplyArguments(function,
1067 return MarkAsCall(DefineFixed(result, eax), instr, CAN_DEOPTIMIZE_EAGERLY);
1071 LInstruction* LChunkBuilder::DoPushArguments(HPushArguments* instr) {
1072 int argc = instr->OperandCount();
1073 for (int i = 0; i < argc; ++i) {
1074 LOperand* argument = UseAny(instr->argument(i));
1075 AddInstruction(new(zone()) LPushArgument(argument), instr);
1081 LInstruction* LChunkBuilder::DoStoreCodeEntry(
1082 HStoreCodeEntry* store_code_entry) {
1083 LOperand* function = UseRegister(store_code_entry->function());
1084 LOperand* code_object = UseTempRegister(store_code_entry->code_object());
1085 return new(zone()) LStoreCodeEntry(function, code_object);
1089 LInstruction* LChunkBuilder::DoInnerAllocatedObject(
1090 HInnerAllocatedObject* instr) {
1091 LOperand* base_object = UseRegisterAtStart(instr->base_object());
1092 LOperand* offset = UseRegisterOrConstantAtStart(instr->offset());
1093 return DefineAsRegister(
1094 new(zone()) LInnerAllocatedObject(base_object, offset));
1098 LInstruction* LChunkBuilder::DoThisFunction(HThisFunction* instr) {
1099 return instr->HasNoUses()
1101 : DefineAsRegister(new(zone()) LThisFunction);
1105 LInstruction* LChunkBuilder::DoContext(HContext* instr) {
1106 if (instr->HasNoUses()) return NULL;
1108 if (info()->IsStub()) {
1109 return DefineFixed(new(zone()) LContext, esi);
1112 return DefineAsRegister(new(zone()) LContext);
1116 LInstruction* LChunkBuilder::DoDeclareGlobals(HDeclareGlobals* instr) {
1117 LOperand* context = UseFixed(instr->context(), esi);
1118 return MarkAsCall(new(zone()) LDeclareGlobals(context), instr);
1122 LInstruction* LChunkBuilder::DoCallJSFunction(
1123 HCallJSFunction* instr) {
1124 LOperand* function = UseFixed(instr->function(), edi);
1126 LCallJSFunction* result = new(zone()) LCallJSFunction(function);
1128 return MarkAsCall(DefineFixed(result, eax), instr, CANNOT_DEOPTIMIZE_EAGERLY);
1132 LInstruction* LChunkBuilder::DoCallWithDescriptor(
1133 HCallWithDescriptor* instr) {
1134 CallInterfaceDescriptor descriptor = instr->descriptor();
1135 LOperand* target = UseRegisterOrConstantAtStart(instr->target());
1136 ZoneList<LOperand*> ops(instr->OperandCount(), zone());
1138 ops.Add(target, zone());
1140 LOperand* op = UseFixed(instr->OperandAt(1), esi);
1141 ops.Add(op, zone());
1142 // Other register parameters
1143 for (int i = LCallWithDescriptor::kImplicitRegisterParameterCount;
1144 i < instr->OperandCount(); i++) {
1146 UseFixed(instr->OperandAt(i),
1147 descriptor.GetRegisterParameter(
1148 i - LCallWithDescriptor::kImplicitRegisterParameterCount));
1149 ops.Add(op, zone());
1152 LCallWithDescriptor* result = new(zone()) LCallWithDescriptor(
1153 descriptor, ops, zone());
1154 return MarkAsCall(DefineFixed(result, eax), instr, CANNOT_DEOPTIMIZE_EAGERLY);
1158 LInstruction* LChunkBuilder::DoInvokeFunction(HInvokeFunction* instr) {
1159 LOperand* context = UseFixed(instr->context(), esi);
1160 LOperand* function = UseFixed(instr->function(), edi);
1161 LInvokeFunction* result = new(zone()) LInvokeFunction(context, function);
1162 return MarkAsCall(DefineFixed(result, eax), instr, CANNOT_DEOPTIMIZE_EAGERLY);
1166 LInstruction* LChunkBuilder::DoUnaryMathOperation(HUnaryMathOperation* instr) {
1167 switch (instr->op()) {
1169 return DoMathFloor(instr);
1171 return DoMathRound(instr);
1173 return DoMathFround(instr);
1175 return DoMathAbs(instr);
1177 return DoMathLog(instr);
1179 return DoMathExp(instr);
1181 return DoMathSqrt(instr);
1183 return DoMathPowHalf(instr);
1185 return DoMathClz32(instr);
1193 LInstruction* LChunkBuilder::DoMathFloor(HUnaryMathOperation* instr) {
1194 LOperand* input = UseRegisterAtStart(instr->value());
1195 LMathFloor* result = new(zone()) LMathFloor(input);
1196 return AssignEnvironment(DefineAsRegister(result));
1200 LInstruction* LChunkBuilder::DoMathRound(HUnaryMathOperation* instr) {
1201 LOperand* input = UseRegister(instr->value());
1202 LOperand* temp = FixedTemp(xmm4);
1203 LMathRound* result = new(zone()) LMathRound(input, temp);
1204 return AssignEnvironment(DefineAsRegister(result));
1208 LInstruction* LChunkBuilder::DoMathFround(HUnaryMathOperation* instr) {
1209 LOperand* input = UseRegister(instr->value());
1210 LMathFround* result = new (zone()) LMathFround(input);
1211 return DefineAsRegister(result);
1215 LInstruction* LChunkBuilder::DoMathAbs(HUnaryMathOperation* instr) {
1216 LOperand* context = UseAny(instr->context()); // Deferred use.
1217 LOperand* input = UseRegisterAtStart(instr->value());
1218 LInstruction* result =
1219 DefineSameAsFirst(new(zone()) LMathAbs(context, input));
1220 Representation r = instr->value()->representation();
1221 if (!r.IsDouble() && !r.IsSmiOrInteger32()) result = AssignPointerMap(result);
1222 if (!r.IsDouble()) result = AssignEnvironment(result);
1227 LInstruction* LChunkBuilder::DoMathLog(HUnaryMathOperation* instr) {
1228 DCHECK(instr->representation().IsDouble());
1229 DCHECK(instr->value()->representation().IsDouble());
1230 LOperand* input = UseRegisterAtStart(instr->value());
1231 return MarkAsCall(DefineSameAsFirst(new(zone()) LMathLog(input)), instr);
1235 LInstruction* LChunkBuilder::DoMathClz32(HUnaryMathOperation* instr) {
1236 LOperand* input = UseRegisterAtStart(instr->value());
1237 LMathClz32* result = new(zone()) LMathClz32(input);
1238 return DefineAsRegister(result);
1242 LInstruction* LChunkBuilder::DoMathExp(HUnaryMathOperation* instr) {
1243 DCHECK(instr->representation().IsDouble());
1244 DCHECK(instr->value()->representation().IsDouble());
1245 LOperand* value = UseTempRegister(instr->value());
1246 LOperand* temp1 = TempRegister();
1247 LOperand* temp2 = TempRegister();
1248 LMathExp* result = new(zone()) LMathExp(value, temp1, temp2);
1249 return DefineAsRegister(result);
1253 LInstruction* LChunkBuilder::DoMathSqrt(HUnaryMathOperation* instr) {
1254 LOperand* input = UseAtStart(instr->value());
1255 return DefineAsRegister(new(zone()) LMathSqrt(input));
1259 LInstruction* LChunkBuilder::DoMathPowHalf(HUnaryMathOperation* instr) {
1260 LOperand* input = UseRegisterAtStart(instr->value());
1261 LOperand* temp = TempRegister();
1262 LMathPowHalf* result = new(zone()) LMathPowHalf(input, temp);
1263 return DefineSameAsFirst(result);
1267 LInstruction* LChunkBuilder::DoCallNew(HCallNew* instr) {
1268 LOperand* context = UseFixed(instr->context(), esi);
1269 LOperand* constructor = UseFixed(instr->constructor(), edi);
1270 LCallNew* result = new(zone()) LCallNew(context, constructor);
1271 return MarkAsCall(DefineFixed(result, eax), instr);
1275 LInstruction* LChunkBuilder::DoCallNewArray(HCallNewArray* instr) {
1276 LOperand* context = UseFixed(instr->context(), esi);
1277 LOperand* constructor = UseFixed(instr->constructor(), edi);
1278 LCallNewArray* result = new(zone()) LCallNewArray(context, constructor);
1279 return MarkAsCall(DefineFixed(result, eax), instr);
1283 LInstruction* LChunkBuilder::DoCallFunction(HCallFunction* instr) {
1284 LOperand* context = UseFixed(instr->context(), esi);
1285 LOperand* function = UseFixed(instr->function(), edi);
1286 LOperand* slot = NULL;
1287 LOperand* vector = NULL;
1288 if (instr->HasVectorAndSlot()) {
1289 slot = FixedTemp(edx);
1290 vector = FixedTemp(ebx);
1293 LCallFunction* call =
1294 new (zone()) LCallFunction(context, function, slot, vector);
1295 return MarkAsCall(DefineFixed(call, eax), instr);
1299 LInstruction* LChunkBuilder::DoCallRuntime(HCallRuntime* instr) {
1300 LOperand* context = UseFixed(instr->context(), esi);
1301 return MarkAsCall(DefineFixed(new(zone()) LCallRuntime(context), eax), instr);
1305 LInstruction* LChunkBuilder::DoRor(HRor* instr) {
1306 return DoShift(Token::ROR, instr);
1310 LInstruction* LChunkBuilder::DoShr(HShr* instr) {
1311 return DoShift(Token::SHR, instr);
1315 LInstruction* LChunkBuilder::DoSar(HSar* instr) {
1316 return DoShift(Token::SAR, instr);
1320 LInstruction* LChunkBuilder::DoShl(HShl* instr) {
1321 return DoShift(Token::SHL, instr);
1325 LInstruction* LChunkBuilder::DoBitwise(HBitwise* instr) {
1326 if (instr->representation().IsSmiOrInteger32()) {
1327 DCHECK(instr->left()->representation().Equals(instr->representation()));
1328 DCHECK(instr->right()->representation().Equals(instr->representation()));
1329 DCHECK(instr->CheckFlag(HValue::kTruncatingToInt32));
1331 LOperand* left = UseRegisterAtStart(instr->BetterLeftOperand());
1332 LOperand* right = UseOrConstantAtStart(instr->BetterRightOperand());
1333 return DefineSameAsFirst(new(zone()) LBitI(left, right));
1335 return DoArithmeticT(instr->op(), instr);
1340 LInstruction* LChunkBuilder::DoDivByPowerOf2I(HDiv* instr) {
1341 DCHECK(instr->representation().IsSmiOrInteger32());
1342 DCHECK(instr->left()->representation().Equals(instr->representation()));
1343 DCHECK(instr->right()->representation().Equals(instr->representation()));
1344 LOperand* dividend = UseRegister(instr->left());
1345 int32_t divisor = instr->right()->GetInteger32Constant();
1346 LInstruction* result = DefineAsRegister(new(zone()) LDivByPowerOf2I(
1347 dividend, divisor));
1348 if ((instr->CheckFlag(HValue::kBailoutOnMinusZero) && divisor < 0) ||
1349 (instr->CheckFlag(HValue::kCanOverflow) && divisor == -1) ||
1350 (!instr->CheckFlag(HInstruction::kAllUsesTruncatingToInt32) &&
1351 divisor != 1 && divisor != -1)) {
1352 result = AssignEnvironment(result);
1358 LInstruction* LChunkBuilder::DoDivByConstI(HDiv* instr) {
1359 DCHECK(instr->representation().IsInteger32());
1360 DCHECK(instr->left()->representation().Equals(instr->representation()));
1361 DCHECK(instr->right()->representation().Equals(instr->representation()));
1362 LOperand* dividend = UseRegister(instr->left());
1363 int32_t divisor = instr->right()->GetInteger32Constant();
1364 LOperand* temp1 = FixedTemp(eax);
1365 LOperand* temp2 = FixedTemp(edx);
1366 LInstruction* result = DefineFixed(new(zone()) LDivByConstI(
1367 dividend, divisor, temp1, temp2), edx);
1369 (instr->CheckFlag(HValue::kBailoutOnMinusZero) && divisor < 0) ||
1370 !instr->CheckFlag(HInstruction::kAllUsesTruncatingToInt32)) {
1371 result = AssignEnvironment(result);
1377 LInstruction* LChunkBuilder::DoDivI(HDiv* instr) {
1378 DCHECK(instr->representation().IsSmiOrInteger32());
1379 DCHECK(instr->left()->representation().Equals(instr->representation()));
1380 DCHECK(instr->right()->representation().Equals(instr->representation()));
1381 LOperand* dividend = UseFixed(instr->left(), eax);
1382 LOperand* divisor = UseRegister(instr->right());
1383 LOperand* temp = FixedTemp(edx);
1384 LInstruction* result = DefineFixed(new(zone()) LDivI(
1385 dividend, divisor, temp), eax);
1386 if (instr->CheckFlag(HValue::kCanBeDivByZero) ||
1387 instr->CheckFlag(HValue::kBailoutOnMinusZero) ||
1388 instr->CheckFlag(HValue::kCanOverflow) ||
1389 !instr->CheckFlag(HValue::kAllUsesTruncatingToInt32)) {
1390 result = AssignEnvironment(result);
1396 LInstruction* LChunkBuilder::DoDiv(HDiv* instr) {
1397 if (instr->representation().IsSmiOrInteger32()) {
1398 if (instr->RightIsPowerOf2()) {
1399 return DoDivByPowerOf2I(instr);
1400 } else if (instr->right()->IsConstant()) {
1401 return DoDivByConstI(instr);
1403 return DoDivI(instr);
1405 } else if (instr->representation().IsDouble()) {
1406 return DoArithmeticD(Token::DIV, instr);
1408 return DoArithmeticT(Token::DIV, instr);
1413 LInstruction* LChunkBuilder::DoFlooringDivByPowerOf2I(HMathFloorOfDiv* instr) {
1414 LOperand* dividend = UseRegisterAtStart(instr->left());
1415 int32_t divisor = instr->right()->GetInteger32Constant();
1416 LInstruction* result = DefineSameAsFirst(new(zone()) LFlooringDivByPowerOf2I(
1417 dividend, divisor));
1418 if ((instr->CheckFlag(HValue::kBailoutOnMinusZero) && divisor < 0) ||
1419 (instr->CheckFlag(HValue::kLeftCanBeMinInt) && divisor == -1)) {
1420 result = AssignEnvironment(result);
1426 LInstruction* LChunkBuilder::DoFlooringDivByConstI(HMathFloorOfDiv* instr) {
1427 DCHECK(instr->representation().IsInteger32());
1428 DCHECK(instr->left()->representation().Equals(instr->representation()));
1429 DCHECK(instr->right()->representation().Equals(instr->representation()));
1430 LOperand* dividend = UseRegister(instr->left());
1431 int32_t divisor = instr->right()->GetInteger32Constant();
1432 LOperand* temp1 = FixedTemp(eax);
1433 LOperand* temp2 = FixedTemp(edx);
1435 ((divisor > 0 && !instr->CheckFlag(HValue::kLeftCanBeNegative)) ||
1436 (divisor < 0 && !instr->CheckFlag(HValue::kLeftCanBePositive))) ?
1437 NULL : TempRegister();
1438 LInstruction* result =
1439 DefineFixed(new(zone()) LFlooringDivByConstI(dividend,
1446 (instr->CheckFlag(HValue::kBailoutOnMinusZero) && divisor < 0)) {
1447 result = AssignEnvironment(result);
1453 LInstruction* LChunkBuilder::DoFlooringDivI(HMathFloorOfDiv* instr) {
1454 DCHECK(instr->representation().IsSmiOrInteger32());
1455 DCHECK(instr->left()->representation().Equals(instr->representation()));
1456 DCHECK(instr->right()->representation().Equals(instr->representation()));
1457 LOperand* dividend = UseFixed(instr->left(), eax);
1458 LOperand* divisor = UseRegister(instr->right());
1459 LOperand* temp = FixedTemp(edx);
1460 LInstruction* result = DefineFixed(new(zone()) LFlooringDivI(
1461 dividend, divisor, temp), eax);
1462 if (instr->CheckFlag(HValue::kCanBeDivByZero) ||
1463 instr->CheckFlag(HValue::kBailoutOnMinusZero) ||
1464 instr->CheckFlag(HValue::kCanOverflow)) {
1465 result = AssignEnvironment(result);
1471 LInstruction* LChunkBuilder::DoMathFloorOfDiv(HMathFloorOfDiv* instr) {
1472 if (instr->RightIsPowerOf2()) {
1473 return DoFlooringDivByPowerOf2I(instr);
1474 } else if (instr->right()->IsConstant()) {
1475 return DoFlooringDivByConstI(instr);
1477 return DoFlooringDivI(instr);
1482 LInstruction* LChunkBuilder::DoModByPowerOf2I(HMod* instr) {
1483 DCHECK(instr->representation().IsSmiOrInteger32());
1484 DCHECK(instr->left()->representation().Equals(instr->representation()));
1485 DCHECK(instr->right()->representation().Equals(instr->representation()));
1486 LOperand* dividend = UseRegisterAtStart(instr->left());
1487 int32_t divisor = instr->right()->GetInteger32Constant();
1488 LInstruction* result = DefineSameAsFirst(new(zone()) LModByPowerOf2I(
1489 dividend, divisor));
1490 if (instr->CheckFlag(HValue::kLeftCanBeNegative) &&
1491 instr->CheckFlag(HValue::kBailoutOnMinusZero)) {
1492 result = AssignEnvironment(result);
1498 LInstruction* LChunkBuilder::DoModByConstI(HMod* instr) {
1499 DCHECK(instr->representation().IsSmiOrInteger32());
1500 DCHECK(instr->left()->representation().Equals(instr->representation()));
1501 DCHECK(instr->right()->representation().Equals(instr->representation()));
1502 LOperand* dividend = UseRegister(instr->left());
1503 int32_t divisor = instr->right()->GetInteger32Constant();
1504 LOperand* temp1 = FixedTemp(eax);
1505 LOperand* temp2 = FixedTemp(edx);
1506 LInstruction* result = DefineFixed(new(zone()) LModByConstI(
1507 dividend, divisor, temp1, temp2), eax);
1508 if (divisor == 0 || instr->CheckFlag(HValue::kBailoutOnMinusZero)) {
1509 result = AssignEnvironment(result);
1515 LInstruction* LChunkBuilder::DoModI(HMod* instr) {
1516 DCHECK(instr->representation().IsSmiOrInteger32());
1517 DCHECK(instr->left()->representation().Equals(instr->representation()));
1518 DCHECK(instr->right()->representation().Equals(instr->representation()));
1519 LOperand* dividend = UseFixed(instr->left(), eax);
1520 LOperand* divisor = UseRegister(instr->right());
1521 LOperand* temp = FixedTemp(edx);
1522 LInstruction* result = DefineFixed(new(zone()) LModI(
1523 dividend, divisor, temp), edx);
1524 if (instr->CheckFlag(HValue::kCanBeDivByZero) ||
1525 instr->CheckFlag(HValue::kBailoutOnMinusZero)) {
1526 result = AssignEnvironment(result);
1532 LInstruction* LChunkBuilder::DoMod(HMod* instr) {
1533 if (instr->representation().IsSmiOrInteger32()) {
1534 if (instr->RightIsPowerOf2()) {
1535 return DoModByPowerOf2I(instr);
1536 } else if (instr->right()->IsConstant()) {
1537 return DoModByConstI(instr);
1539 return DoModI(instr);
1541 } else if (instr->representation().IsDouble()) {
1542 return DoArithmeticD(Token::MOD, instr);
1544 return DoArithmeticT(Token::MOD, instr);
1549 LInstruction* LChunkBuilder::DoMul(HMul* instr) {
1550 if (instr->representation().IsSmiOrInteger32()) {
1551 DCHECK(instr->left()->representation().Equals(instr->representation()));
1552 DCHECK(instr->right()->representation().Equals(instr->representation()));
1553 LOperand* left = UseRegisterAtStart(instr->BetterLeftOperand());
1554 LOperand* right = UseOrConstant(instr->BetterRightOperand());
1555 LOperand* temp = NULL;
1556 if (instr->CheckFlag(HValue::kBailoutOnMinusZero)) {
1557 temp = TempRegister();
1559 LMulI* mul = new(zone()) LMulI(left, right, temp);
1560 if (instr->CheckFlag(HValue::kCanOverflow) ||
1561 instr->CheckFlag(HValue::kBailoutOnMinusZero)) {
1562 AssignEnvironment(mul);
1564 return DefineSameAsFirst(mul);
1565 } else if (instr->representation().IsDouble()) {
1566 return DoArithmeticD(Token::MUL, instr);
1568 return DoArithmeticT(Token::MUL, instr);
1573 LInstruction* LChunkBuilder::DoSub(HSub* instr) {
1574 if (instr->representation().IsSmiOrInteger32()) {
1575 DCHECK(instr->left()->representation().Equals(instr->representation()));
1576 DCHECK(instr->right()->representation().Equals(instr->representation()));
1577 LOperand* left = UseRegisterAtStart(instr->left());
1578 LOperand* right = UseOrConstantAtStart(instr->right());
1579 LSubI* sub = new(zone()) LSubI(left, right);
1580 LInstruction* result = DefineSameAsFirst(sub);
1581 if (instr->CheckFlag(HValue::kCanOverflow)) {
1582 result = AssignEnvironment(result);
1585 } else if (instr->representation().IsDouble()) {
1586 return DoArithmeticD(Token::SUB, instr);
1588 return DoArithmeticT(Token::SUB, instr);
1593 LInstruction* LChunkBuilder::DoAdd(HAdd* instr) {
1594 if (instr->representation().IsSmiOrInteger32()) {
1595 DCHECK(instr->left()->representation().Equals(instr->representation()));
1596 DCHECK(instr->right()->representation().Equals(instr->representation()));
1597 // Check to see if it would be advantageous to use an lea instruction rather
1598 // than an add. This is the case when no overflow check is needed and there
1599 // are multiple uses of the add's inputs, so using a 3-register add will
1600 // preserve all input values for later uses.
1601 bool use_lea = LAddI::UseLea(instr);
1602 LOperand* left = UseRegisterAtStart(instr->BetterLeftOperand());
1603 HValue* right_candidate = instr->BetterRightOperand();
1604 LOperand* right = use_lea
1605 ? UseRegisterOrConstantAtStart(right_candidate)
1606 : UseOrConstantAtStart(right_candidate);
1607 LAddI* add = new(zone()) LAddI(left, right);
1608 bool can_overflow = instr->CheckFlag(HValue::kCanOverflow);
1609 LInstruction* result = use_lea
1610 ? DefineAsRegister(add)
1611 : DefineSameAsFirst(add);
1613 result = AssignEnvironment(result);
1616 } else if (instr->representation().IsDouble()) {
1617 return DoArithmeticD(Token::ADD, instr);
1618 } else if (instr->representation().IsExternal()) {
1619 DCHECK(instr->IsConsistentExternalRepresentation());
1620 DCHECK(!instr->CheckFlag(HValue::kCanOverflow));
1621 bool use_lea = LAddI::UseLea(instr);
1622 LOperand* left = UseRegisterAtStart(instr->left());
1623 HValue* right_candidate = instr->right();
1624 LOperand* right = use_lea
1625 ? UseRegisterOrConstantAtStart(right_candidate)
1626 : UseOrConstantAtStart(right_candidate);
1627 LAddI* add = new(zone()) LAddI(left, right);
1628 LInstruction* result = use_lea
1629 ? DefineAsRegister(add)
1630 : DefineSameAsFirst(add);
1633 return DoArithmeticT(Token::ADD, instr);
1638 LInstruction* LChunkBuilder::DoMathMinMax(HMathMinMax* instr) {
1639 LOperand* left = NULL;
1640 LOperand* right = NULL;
1641 if (instr->representation().IsSmiOrInteger32()) {
1642 DCHECK(instr->left()->representation().Equals(instr->representation()));
1643 DCHECK(instr->right()->representation().Equals(instr->representation()));
1644 left = UseRegisterAtStart(instr->BetterLeftOperand());
1645 right = UseOrConstantAtStart(instr->BetterRightOperand());
1647 DCHECK(instr->representation().IsDouble());
1648 DCHECK(instr->left()->representation().IsDouble());
1649 DCHECK(instr->right()->representation().IsDouble());
1650 left = UseRegisterAtStart(instr->left());
1651 right = UseRegisterAtStart(instr->right());
1653 LMathMinMax* minmax = new(zone()) LMathMinMax(left, right);
1654 return DefineSameAsFirst(minmax);
1658 LInstruction* LChunkBuilder::DoPower(HPower* instr) {
1659 DCHECK(instr->representation().IsDouble());
1660 // We call a C function for double power. It can't trigger a GC.
1661 // We need to use fixed result register for the call.
1662 Representation exponent_type = instr->right()->representation();
1663 DCHECK(instr->left()->representation().IsDouble());
1664 LOperand* left = UseFixedDouble(instr->left(), xmm2);
1666 exponent_type.IsDouble()
1667 ? UseFixedDouble(instr->right(), xmm1)
1668 : UseFixed(instr->right(), MathPowTaggedDescriptor::exponent());
1669 LPower* result = new(zone()) LPower(left, right);
1670 return MarkAsCall(DefineFixedDouble(result, xmm3), instr,
1671 CAN_DEOPTIMIZE_EAGERLY);
1675 LInstruction* LChunkBuilder::DoCompareGeneric(HCompareGeneric* instr) {
1676 DCHECK(instr->left()->representation().IsSmiOrTagged());
1677 DCHECK(instr->right()->representation().IsSmiOrTagged());
1678 LOperand* context = UseFixed(instr->context(), esi);
1679 LOperand* left = UseFixed(instr->left(), edx);
1680 LOperand* right = UseFixed(instr->right(), eax);
1681 LCmpT* result = new(zone()) LCmpT(context, left, right);
1682 return MarkAsCall(DefineFixed(result, eax), instr);
1686 LInstruction* LChunkBuilder::DoCompareNumericAndBranch(
1687 HCompareNumericAndBranch* instr) {
1688 Representation r = instr->representation();
1689 if (r.IsSmiOrInteger32()) {
1690 DCHECK(instr->left()->representation().Equals(r));
1691 DCHECK(instr->right()->representation().Equals(r));
1692 LOperand* left = UseRegisterOrConstantAtStart(instr->left());
1693 LOperand* right = UseOrConstantAtStart(instr->right());
1694 return new(zone()) LCompareNumericAndBranch(left, right);
1696 DCHECK(r.IsDouble());
1697 DCHECK(instr->left()->representation().IsDouble());
1698 DCHECK(instr->right()->representation().IsDouble());
1701 if (CanBeImmediateConstant(instr->left()) &&
1702 CanBeImmediateConstant(instr->right())) {
1703 // The code generator requires either both inputs to be constant
1704 // operands, or neither.
1705 left = UseConstant(instr->left());
1706 right = UseConstant(instr->right());
1708 left = UseRegisterAtStart(instr->left());
1709 right = UseRegisterAtStart(instr->right());
1711 return new(zone()) LCompareNumericAndBranch(left, right);
1716 LInstruction* LChunkBuilder::DoCompareObjectEqAndBranch(
1717 HCompareObjectEqAndBranch* instr) {
1718 LOperand* left = UseRegisterAtStart(instr->left());
1719 LOperand* right = UseOrConstantAtStart(instr->right());
1720 return new(zone()) LCmpObjectEqAndBranch(left, right);
1724 LInstruction* LChunkBuilder::DoCompareHoleAndBranch(
1725 HCompareHoleAndBranch* instr) {
1726 LOperand* value = UseRegisterAtStart(instr->value());
1727 return new(zone()) LCmpHoleAndBranch(value);
1731 LInstruction* LChunkBuilder::DoCompareMinusZeroAndBranch(
1732 HCompareMinusZeroAndBranch* instr) {
1733 LOperand* value = UseRegister(instr->value());
1734 LOperand* scratch = TempRegister();
1735 return new(zone()) LCompareMinusZeroAndBranch(value, scratch);
1739 LInstruction* LChunkBuilder::DoIsStringAndBranch(HIsStringAndBranch* instr) {
1740 DCHECK(instr->value()->representation().IsTagged());
1741 LOperand* temp = TempRegister();
1742 return new(zone()) LIsStringAndBranch(UseRegister(instr->value()), temp);
1746 LInstruction* LChunkBuilder::DoIsSmiAndBranch(HIsSmiAndBranch* instr) {
1747 DCHECK(instr->value()->representation().IsTagged());
1748 return new(zone()) LIsSmiAndBranch(Use(instr->value()));
1752 LInstruction* LChunkBuilder::DoIsUndetectableAndBranch(
1753 HIsUndetectableAndBranch* instr) {
1754 DCHECK(instr->value()->representation().IsTagged());
1755 return new(zone()) LIsUndetectableAndBranch(
1756 UseRegisterAtStart(instr->value()), TempRegister());
1760 LInstruction* LChunkBuilder::DoStringCompareAndBranch(
1761 HStringCompareAndBranch* instr) {
1762 DCHECK(instr->left()->representation().IsTagged());
1763 DCHECK(instr->right()->representation().IsTagged());
1764 LOperand* context = UseFixed(instr->context(), esi);
1765 LOperand* left = UseFixed(instr->left(), edx);
1766 LOperand* right = UseFixed(instr->right(), eax);
1768 LStringCompareAndBranch* result = new(zone())
1769 LStringCompareAndBranch(context, left, right);
1771 return MarkAsCall(result, instr);
1775 LInstruction* LChunkBuilder::DoHasInstanceTypeAndBranch(
1776 HHasInstanceTypeAndBranch* instr) {
1777 DCHECK(instr->value()->representation().IsTagged());
1778 return new(zone()) LHasInstanceTypeAndBranch(
1779 UseRegisterAtStart(instr->value()),
1784 LInstruction* LChunkBuilder::DoGetCachedArrayIndex(
1785 HGetCachedArrayIndex* instr) {
1786 DCHECK(instr->value()->representation().IsTagged());
1787 LOperand* value = UseRegisterAtStart(instr->value());
1789 return DefineAsRegister(new(zone()) LGetCachedArrayIndex(value));
1793 LInstruction* LChunkBuilder::DoHasCachedArrayIndexAndBranch(
1794 HHasCachedArrayIndexAndBranch* instr) {
1795 DCHECK(instr->value()->representation().IsTagged());
1796 return new(zone()) LHasCachedArrayIndexAndBranch(
1797 UseRegisterAtStart(instr->value()));
1801 LInstruction* LChunkBuilder::DoClassOfTestAndBranch(
1802 HClassOfTestAndBranch* instr) {
1803 DCHECK(instr->value()->representation().IsTagged());
1804 return new(zone()) LClassOfTestAndBranch(UseRegister(instr->value()),
1810 LInstruction* LChunkBuilder::DoMapEnumLength(HMapEnumLength* instr) {
1811 LOperand* map = UseRegisterAtStart(instr->value());
1812 return DefineAsRegister(new(zone()) LMapEnumLength(map));
1816 LInstruction* LChunkBuilder::DoDateField(HDateField* instr) {
1817 LOperand* date = UseFixed(instr->value(), eax);
1818 LDateField* result =
1819 new(zone()) LDateField(date, FixedTemp(ecx), instr->index());
1820 return MarkAsCall(DefineFixed(result, eax), instr, CANNOT_DEOPTIMIZE_EAGERLY);
1824 LInstruction* LChunkBuilder::DoSeqStringGetChar(HSeqStringGetChar* instr) {
1825 LOperand* string = UseRegisterAtStart(instr->string());
1826 LOperand* index = UseRegisterOrConstantAtStart(instr->index());
1827 return DefineAsRegister(new(zone()) LSeqStringGetChar(string, index));
1831 LOperand* LChunkBuilder::GetSeqStringSetCharOperand(HSeqStringSetChar* instr) {
1832 if (instr->encoding() == String::ONE_BYTE_ENCODING) {
1833 if (FLAG_debug_code) {
1834 return UseFixed(instr->value(), eax);
1836 return UseFixedOrConstant(instr->value(), eax);
1839 if (FLAG_debug_code) {
1840 return UseRegisterAtStart(instr->value());
1842 return UseRegisterOrConstantAtStart(instr->value());
1848 LInstruction* LChunkBuilder::DoSeqStringSetChar(HSeqStringSetChar* instr) {
1849 LOperand* string = UseRegisterAtStart(instr->string());
1850 LOperand* index = FLAG_debug_code
1851 ? UseRegisterAtStart(instr->index())
1852 : UseRegisterOrConstantAtStart(instr->index());
1853 LOperand* value = GetSeqStringSetCharOperand(instr);
1854 LOperand* context = FLAG_debug_code ? UseFixed(instr->context(), esi) : NULL;
1855 LInstruction* result = new(zone()) LSeqStringSetChar(context, string,
1857 if (FLAG_debug_code) {
1858 result = MarkAsCall(result, instr);
1864 LInstruction* LChunkBuilder::DoBoundsCheck(HBoundsCheck* instr) {
1865 if (!FLAG_debug_code && instr->skip_check()) return NULL;
1866 LOperand* index = UseRegisterOrConstantAtStart(instr->index());
1867 LOperand* length = !index->IsConstantOperand()
1868 ? UseOrConstantAtStart(instr->length())
1869 : UseAtStart(instr->length());
1870 LInstruction* result = new(zone()) LBoundsCheck(index, length);
1871 if (!FLAG_debug_code || !instr->skip_check()) {
1872 result = AssignEnvironment(result);
1878 LInstruction* LChunkBuilder::DoBoundsCheckBaseIndexInformation(
1879 HBoundsCheckBaseIndexInformation* instr) {
1885 LInstruction* LChunkBuilder::DoAbnormalExit(HAbnormalExit* instr) {
1886 // The control instruction marking the end of a block that completed
1887 // abruptly (e.g., threw an exception). There is nothing specific to do.
1892 LInstruction* LChunkBuilder::DoUseConst(HUseConst* instr) {
1897 LInstruction* LChunkBuilder::DoForceRepresentation(HForceRepresentation* bad) {
1898 // All HForceRepresentation instructions should be eliminated in the
1899 // representation change phase of Hydrogen.
1905 LInstruction* LChunkBuilder::DoChange(HChange* instr) {
1906 Representation from = instr->from();
1907 Representation to = instr->to();
1908 HValue* val = instr->value();
1910 if (to.IsTagged()) {
1911 LOperand* value = UseRegister(val);
1912 return DefineSameAsFirst(new(zone()) LDummyUse(value));
1914 from = Representation::Tagged();
1916 if (from.IsTagged()) {
1917 if (to.IsDouble()) {
1918 LOperand* value = UseRegister(val);
1919 LOperand* temp = TempRegister();
1920 LInstruction* result =
1921 DefineAsRegister(new(zone()) LNumberUntagD(value, temp));
1922 if (!val->representation().IsSmi()) result = AssignEnvironment(result);
1924 } else if (to.IsSmi()) {
1925 LOperand* value = UseRegister(val);
1926 if (val->type().IsSmi()) {
1927 return DefineSameAsFirst(new(zone()) LDummyUse(value));
1929 return AssignEnvironment(DefineSameAsFirst(new(zone()) LCheckSmi(value)));
1931 DCHECK(to.IsInteger32());
1932 if (val->type().IsSmi() || val->representation().IsSmi()) {
1933 LOperand* value = UseRegister(val);
1934 return DefineSameAsFirst(new(zone()) LSmiUntag(value, false));
1936 LOperand* value = UseRegister(val);
1937 bool truncating = instr->CanTruncateToInt32();
1938 LOperand* xmm_temp = !truncating ? FixedTemp(xmm1) : NULL;
1939 LInstruction* result =
1940 DefineSameAsFirst(new(zone()) LTaggedToI(value, xmm_temp));
1941 if (!val->representation().IsSmi()) result = AssignEnvironment(result);
1945 } else if (from.IsDouble()) {
1946 if (to.IsTagged()) {
1947 info()->MarkAsDeferredCalling();
1948 LOperand* value = UseRegisterAtStart(val);
1949 LOperand* temp = FLAG_inline_new ? TempRegister() : NULL;
1950 LUnallocated* result_temp = TempRegister();
1951 LNumberTagD* result = new(zone()) LNumberTagD(value, temp);
1952 return AssignPointerMap(Define(result, result_temp));
1953 } else if (to.IsSmi()) {
1954 LOperand* value = UseRegister(val);
1955 return AssignEnvironment(
1956 DefineAsRegister(new(zone()) LDoubleToSmi(value)));
1958 DCHECK(to.IsInteger32());
1959 bool truncating = instr->CanTruncateToInt32();
1960 bool needs_temp = !truncating;
1961 LOperand* value = needs_temp ? UseTempRegister(val) : UseRegister(val);
1962 LOperand* temp = needs_temp ? TempRegister() : NULL;
1963 LInstruction* result =
1964 DefineAsRegister(new(zone()) LDoubleToI(value, temp));
1965 if (!truncating) result = AssignEnvironment(result);
1968 } else if (from.IsInteger32()) {
1969 info()->MarkAsDeferredCalling();
1970 if (to.IsTagged()) {
1971 LOperand* value = UseRegister(val);
1972 if (!instr->CheckFlag(HValue::kCanOverflow)) {
1973 return DefineSameAsFirst(new(zone()) LSmiTag(value));
1974 } else if (val->CheckFlag(HInstruction::kUint32)) {
1975 LOperand* temp = TempRegister();
1976 LNumberTagU* result = new(zone()) LNumberTagU(value, temp);
1977 return AssignPointerMap(DefineSameAsFirst(result));
1979 LOperand* temp = TempRegister();
1980 LNumberTagI* result = new(zone()) LNumberTagI(value, temp);
1981 return AssignPointerMap(DefineSameAsFirst(result));
1983 } else if (to.IsSmi()) {
1984 LOperand* value = UseRegister(val);
1985 LInstruction* result = DefineSameAsFirst(new(zone()) LSmiTag(value));
1986 if (instr->CheckFlag(HValue::kCanOverflow)) {
1987 result = AssignEnvironment(result);
1991 DCHECK(to.IsDouble());
1992 if (val->CheckFlag(HInstruction::kUint32)) {
1993 return DefineAsRegister(new(zone()) LUint32ToDouble(UseRegister(val)));
1995 return DefineAsRegister(new(zone()) LInteger32ToDouble(Use(val)));
2004 LInstruction* LChunkBuilder::DoCheckHeapObject(HCheckHeapObject* instr) {
2005 LOperand* value = UseAtStart(instr->value());
2006 LInstruction* result = new(zone()) LCheckNonSmi(value);
2007 if (!instr->value()->type().IsHeapObject()) {
2008 result = AssignEnvironment(result);
2014 LInstruction* LChunkBuilder::DoCheckSmi(HCheckSmi* instr) {
2015 LOperand* value = UseRegisterAtStart(instr->value());
2016 return AssignEnvironment(new(zone()) LCheckSmi(value));
2020 LInstruction* LChunkBuilder::DoCheckArrayBufferNotNeutered(
2021 HCheckArrayBufferNotNeutered* instr) {
2022 LOperand* view = UseRegisterAtStart(instr->value());
2023 LOperand* scratch = TempRegister();
2024 LCheckArrayBufferNotNeutered* result =
2025 new (zone()) LCheckArrayBufferNotNeutered(view, scratch);
2026 return AssignEnvironment(result);
2030 LInstruction* LChunkBuilder::DoCheckInstanceType(HCheckInstanceType* instr) {
2031 LOperand* value = UseRegisterAtStart(instr->value());
2032 LOperand* temp = TempRegister();
2033 LCheckInstanceType* result = new(zone()) LCheckInstanceType(value, temp);
2034 return AssignEnvironment(result);
2038 LInstruction* LChunkBuilder::DoCheckValue(HCheckValue* instr) {
2039 // If the object is in new space, we'll emit a global cell compare and so
2040 // want the value in a register. If the object gets promoted before we
2041 // emit code, we will still get the register but will do an immediate
2042 // compare instead of the cell compare. This is safe.
2043 LOperand* value = instr->object_in_new_space()
2044 ? UseRegisterAtStart(instr->value()) : UseAtStart(instr->value());
2045 return AssignEnvironment(new(zone()) LCheckValue(value));
2049 LInstruction* LChunkBuilder::DoCheckMaps(HCheckMaps* instr) {
2050 if (instr->IsStabilityCheck()) return new(zone()) LCheckMaps;
2051 LOperand* value = UseRegisterAtStart(instr->value());
2052 LInstruction* result = AssignEnvironment(new(zone()) LCheckMaps(value));
2053 if (instr->HasMigrationTarget()) {
2054 info()->MarkAsDeferredCalling();
2055 result = AssignPointerMap(result);
2061 LInstruction* LChunkBuilder::DoClampToUint8(HClampToUint8* instr) {
2062 HValue* value = instr->value();
2063 Representation input_rep = value->representation();
2064 if (input_rep.IsDouble()) {
2065 LOperand* reg = UseRegister(value);
2066 return DefineFixed(new(zone()) LClampDToUint8(reg), eax);
2067 } else if (input_rep.IsInteger32()) {
2068 LOperand* reg = UseFixed(value, eax);
2069 return DefineFixed(new(zone()) LClampIToUint8(reg), eax);
2071 DCHECK(input_rep.IsSmiOrTagged());
2072 LOperand* reg = UseFixed(value, eax);
2073 // Register allocator doesn't (yet) support allocation of double
2074 // temps. Reserve xmm1 explicitly.
2075 LOperand* temp = FixedTemp(xmm1);
2076 LClampTToUint8* result = new(zone()) LClampTToUint8(reg, temp);
2077 return AssignEnvironment(DefineFixed(result, eax));
2082 LInstruction* LChunkBuilder::DoDoubleBits(HDoubleBits* instr) {
2083 HValue* value = instr->value();
2084 DCHECK(value->representation().IsDouble());
2085 return DefineAsRegister(new(zone()) LDoubleBits(UseRegister(value)));
2089 LInstruction* LChunkBuilder::DoConstructDouble(HConstructDouble* instr) {
2090 LOperand* lo = UseRegister(instr->lo());
2091 LOperand* hi = UseRegister(instr->hi());
2092 return DefineAsRegister(new(zone()) LConstructDouble(hi, lo));
2096 LInstruction* LChunkBuilder::DoReturn(HReturn* instr) {
2097 LOperand* context = info()->IsStub() ? UseFixed(instr->context(), esi) : NULL;
2098 LOperand* parameter_count = UseRegisterOrConstant(instr->parameter_count());
2099 return new(zone()) LReturn(
2100 UseFixed(instr->value(), eax), context, parameter_count);
2104 LInstruction* LChunkBuilder::DoConstant(HConstant* instr) {
2105 Representation r = instr->representation();
2107 return DefineAsRegister(new(zone()) LConstantS);
2108 } else if (r.IsInteger32()) {
2109 return DefineAsRegister(new(zone()) LConstantI);
2110 } else if (r.IsDouble()) {
2111 uint64_t const bits = instr->DoubleValueAsBits();
2112 LOperand* temp = bits ? TempRegister() : nullptr;
2113 return DefineAsRegister(new(zone()) LConstantD(temp));
2114 } else if (r.IsExternal()) {
2115 return DefineAsRegister(new(zone()) LConstantE);
2116 } else if (r.IsTagged()) {
2117 return DefineAsRegister(new(zone()) LConstantT);
2125 LInstruction* LChunkBuilder::DoLoadGlobalGeneric(HLoadGlobalGeneric* instr) {
2126 LOperand* context = UseFixed(instr->context(), esi);
2127 LOperand* global_object =
2128 UseFixed(instr->global_object(), LoadDescriptor::ReceiverRegister());
2129 LOperand* vector = NULL;
2130 if (instr->HasVectorAndSlot()) {
2131 vector = FixedTemp(LoadWithVectorDescriptor::VectorRegister());
2134 LLoadGlobalGeneric* result =
2135 new(zone()) LLoadGlobalGeneric(context, global_object, vector);
2136 return MarkAsCall(DefineFixed(result, eax), instr);
2140 LInstruction* LChunkBuilder::DoLoadGlobalViaContext(
2141 HLoadGlobalViaContext* instr) {
2142 LOperand* context = UseFixed(instr->context(), esi);
2143 DCHECK(instr->slot_index() > 0);
2144 LLoadGlobalViaContext* result = new (zone()) LLoadGlobalViaContext(context);
2145 return MarkAsCall(DefineFixed(result, eax), instr);
2149 LInstruction* LChunkBuilder::DoLoadContextSlot(HLoadContextSlot* instr) {
2150 LOperand* context = UseRegisterAtStart(instr->value());
2151 LInstruction* result =
2152 DefineAsRegister(new(zone()) LLoadContextSlot(context));
2153 if (instr->RequiresHoleCheck() && instr->DeoptimizesOnHole()) {
2154 result = AssignEnvironment(result);
2160 LInstruction* LChunkBuilder::DoStoreContextSlot(HStoreContextSlot* instr) {
2163 LOperand* context = UseRegister(instr->context());
2164 if (instr->NeedsWriteBarrier()) {
2165 value = UseTempRegister(instr->value());
2166 temp = TempRegister();
2168 value = UseRegister(instr->value());
2171 LInstruction* result = new(zone()) LStoreContextSlot(context, value, temp);
2172 if (instr->RequiresHoleCheck() && instr->DeoptimizesOnHole()) {
2173 result = AssignEnvironment(result);
2179 LInstruction* LChunkBuilder::DoLoadNamedField(HLoadNamedField* instr) {
2180 LOperand* obj = (instr->access().IsExternalMemory() &&
2181 instr->access().offset() == 0)
2182 ? UseRegisterOrConstantAtStart(instr->object())
2183 : UseRegisterAtStart(instr->object());
2184 return DefineAsRegister(new(zone()) LLoadNamedField(obj));
2188 LInstruction* LChunkBuilder::DoLoadNamedGeneric(HLoadNamedGeneric* instr) {
2189 LOperand* context = UseFixed(instr->context(), esi);
2191 UseFixed(instr->object(), LoadDescriptor::ReceiverRegister());
2192 LOperand* vector = NULL;
2193 if (instr->HasVectorAndSlot()) {
2194 vector = FixedTemp(LoadWithVectorDescriptor::VectorRegister());
2196 LLoadNamedGeneric* result = new(zone()) LLoadNamedGeneric(
2197 context, object, vector);
2198 return MarkAsCall(DefineFixed(result, eax), instr);
2202 LInstruction* LChunkBuilder::DoLoadFunctionPrototype(
2203 HLoadFunctionPrototype* instr) {
2204 return AssignEnvironment(DefineAsRegister(
2205 new(zone()) LLoadFunctionPrototype(UseRegister(instr->function()),
2210 LInstruction* LChunkBuilder::DoLoadRoot(HLoadRoot* instr) {
2211 return DefineAsRegister(new(zone()) LLoadRoot);
2215 LInstruction* LChunkBuilder::DoLoadKeyed(HLoadKeyed* instr) {
2216 DCHECK(instr->key()->representation().IsSmiOrInteger32());
2217 ElementsKind elements_kind = instr->elements_kind();
2218 bool clobbers_key = ExternalArrayOpRequiresTemp(
2219 instr->key()->representation(), elements_kind);
2220 LOperand* key = clobbers_key
2221 ? UseTempRegister(instr->key())
2222 : UseRegisterOrConstantAtStart(instr->key());
2223 LInstruction* result = NULL;
2225 if (!instr->is_fixed_typed_array()) {
2226 LOperand* obj = UseRegisterAtStart(instr->elements());
2227 result = DefineAsRegister(new(zone()) LLoadKeyed(obj, key));
2230 (instr->representation().IsInteger32() &&
2231 !(IsDoubleOrFloatElementsKind(instr->elements_kind()))) ||
2232 (instr->representation().IsDouble() &&
2233 (IsDoubleOrFloatElementsKind(instr->elements_kind()))));
2234 LOperand* backing_store = UseRegister(instr->elements());
2235 result = DefineAsRegister(new(zone()) LLoadKeyed(backing_store, key));
2238 bool needs_environment;
2239 if (instr->is_fixed_typed_array()) {
2240 // see LCodeGen::DoLoadKeyedExternalArray
2241 needs_environment = elements_kind == UINT32_ELEMENTS &&
2242 !instr->CheckFlag(HInstruction::kUint32);
2244 // see LCodeGen::DoLoadKeyedFixedDoubleArray and
2245 // LCodeGen::DoLoadKeyedFixedArray
2247 instr->RequiresHoleCheck() ||
2248 (instr->hole_mode() == CONVERT_HOLE_TO_UNDEFINED && info()->IsStub());
2251 if (needs_environment) {
2252 result = AssignEnvironment(result);
2258 LInstruction* LChunkBuilder::DoLoadKeyedGeneric(HLoadKeyedGeneric* instr) {
2259 LOperand* context = UseFixed(instr->context(), esi);
2261 UseFixed(instr->object(), LoadDescriptor::ReceiverRegister());
2262 LOperand* key = UseFixed(instr->key(), LoadDescriptor::NameRegister());
2263 LOperand* vector = NULL;
2264 if (instr->HasVectorAndSlot()) {
2265 vector = FixedTemp(LoadWithVectorDescriptor::VectorRegister());
2267 LLoadKeyedGeneric* result =
2268 new(zone()) LLoadKeyedGeneric(context, object, key, vector);
2269 return MarkAsCall(DefineFixed(result, eax), instr);
2273 LOperand* LChunkBuilder::GetStoreKeyedValueOperand(HStoreKeyed* instr) {
2274 ElementsKind elements_kind = instr->elements_kind();
2276 // Determine if we need a byte register in this case for the value.
2277 bool val_is_fixed_register =
2278 elements_kind == UINT8_ELEMENTS ||
2279 elements_kind == INT8_ELEMENTS ||
2280 elements_kind == UINT8_CLAMPED_ELEMENTS;
2281 if (val_is_fixed_register) {
2282 return UseFixed(instr->value(), eax);
2285 return UseRegister(instr->value());
2289 LInstruction* LChunkBuilder::DoStoreKeyed(HStoreKeyed* instr) {
2290 if (!instr->is_fixed_typed_array()) {
2291 DCHECK(instr->elements()->representation().IsTagged());
2292 DCHECK(instr->key()->representation().IsInteger32() ||
2293 instr->key()->representation().IsSmi());
2295 if (instr->value()->representation().IsDouble()) {
2296 LOperand* object = UseRegisterAtStart(instr->elements());
2297 LOperand* val = NULL;
2298 val = UseRegisterAtStart(instr->value());
2299 LOperand* key = UseRegisterOrConstantAtStart(instr->key());
2300 return new(zone()) LStoreKeyed(object, key, val);
2302 DCHECK(instr->value()->representation().IsSmiOrTagged());
2303 bool needs_write_barrier = instr->NeedsWriteBarrier();
2305 LOperand* obj = UseRegister(instr->elements());
2308 if (needs_write_barrier) {
2309 val = UseTempRegister(instr->value());
2310 key = UseTempRegister(instr->key());
2312 val = UseRegisterOrConstantAtStart(instr->value());
2313 key = UseRegisterOrConstantAtStart(instr->key());
2315 return new(zone()) LStoreKeyed(obj, key, val);
2319 ElementsKind elements_kind = instr->elements_kind();
2321 (instr->value()->representation().IsInteger32() &&
2322 !IsDoubleOrFloatElementsKind(elements_kind)) ||
2323 (instr->value()->representation().IsDouble() &&
2324 IsDoubleOrFloatElementsKind(elements_kind)));
2325 DCHECK(instr->elements()->representation().IsExternal());
2327 LOperand* backing_store = UseRegister(instr->elements());
2328 LOperand* val = GetStoreKeyedValueOperand(instr);
2329 bool clobbers_key = ExternalArrayOpRequiresTemp(
2330 instr->key()->representation(), elements_kind);
2331 LOperand* key = clobbers_key
2332 ? UseTempRegister(instr->key())
2333 : UseRegisterOrConstantAtStart(instr->key());
2334 return new(zone()) LStoreKeyed(backing_store, key, val);
2338 LInstruction* LChunkBuilder::DoStoreKeyedGeneric(HStoreKeyedGeneric* instr) {
2339 LOperand* context = UseFixed(instr->context(), esi);
2341 UseFixed(instr->object(), StoreDescriptor::ReceiverRegister());
2342 LOperand* key = UseFixed(instr->key(), StoreDescriptor::NameRegister());
2343 LOperand* value = UseFixed(instr->value(), StoreDescriptor::ValueRegister());
2345 DCHECK(instr->object()->representation().IsTagged());
2346 DCHECK(instr->key()->representation().IsTagged());
2347 DCHECK(instr->value()->representation().IsTagged());
2349 LOperand* slot = NULL;
2350 LOperand* vector = NULL;
2351 if (instr->HasVectorAndSlot()) {
2352 slot = FixedTemp(VectorStoreICDescriptor::SlotRegister());
2353 vector = FixedTemp(VectorStoreICDescriptor::VectorRegister());
2356 LStoreKeyedGeneric* result = new (zone())
2357 LStoreKeyedGeneric(context, object, key, value, slot, vector);
2358 return MarkAsCall(result, instr);
2362 LInstruction* LChunkBuilder::DoTransitionElementsKind(
2363 HTransitionElementsKind* instr) {
2364 if (IsSimpleMapChangeTransition(instr->from_kind(), instr->to_kind())) {
2365 LOperand* object = UseRegister(instr->object());
2366 LOperand* new_map_reg = TempRegister();
2367 LOperand* temp_reg = TempRegister();
2368 LTransitionElementsKind* result =
2369 new(zone()) LTransitionElementsKind(object, NULL,
2370 new_map_reg, temp_reg);
2373 LOperand* object = UseFixed(instr->object(), eax);
2374 LOperand* context = UseFixed(instr->context(), esi);
2375 LTransitionElementsKind* result =
2376 new(zone()) LTransitionElementsKind(object, context, NULL, NULL);
2377 return MarkAsCall(result, instr);
2382 LInstruction* LChunkBuilder::DoTrapAllocationMemento(
2383 HTrapAllocationMemento* instr) {
2384 LOperand* object = UseRegister(instr->object());
2385 LOperand* temp = TempRegister();
2386 LTrapAllocationMemento* result =
2387 new(zone()) LTrapAllocationMemento(object, temp);
2388 return AssignEnvironment(result);
2392 LInstruction* LChunkBuilder::DoMaybeGrowElements(HMaybeGrowElements* instr) {
2393 info()->MarkAsDeferredCalling();
2394 LOperand* context = UseFixed(instr->context(), esi);
2395 LOperand* object = Use(instr->object());
2396 LOperand* elements = Use(instr->elements());
2397 LOperand* key = UseRegisterOrConstant(instr->key());
2398 LOperand* current_capacity = UseRegisterOrConstant(instr->current_capacity());
2400 LMaybeGrowElements* result = new (zone())
2401 LMaybeGrowElements(context, object, elements, key, current_capacity);
2402 DefineFixed(result, eax);
2403 return AssignPointerMap(AssignEnvironment(result));
2407 LInstruction* LChunkBuilder::DoStoreNamedField(HStoreNamedField* instr) {
2408 bool is_in_object = instr->access().IsInobject();
2409 bool is_external_location = instr->access().IsExternalMemory() &&
2410 instr->access().offset() == 0;
2411 bool needs_write_barrier = instr->NeedsWriteBarrier();
2412 bool needs_write_barrier_for_map = instr->has_transition() &&
2413 instr->NeedsWriteBarrierForMap();
2416 if (needs_write_barrier) {
2418 ? UseRegister(instr->object())
2419 : UseTempRegister(instr->object());
2420 } else if (is_external_location) {
2421 DCHECK(!is_in_object);
2422 DCHECK(!needs_write_barrier);
2423 DCHECK(!needs_write_barrier_for_map);
2424 obj = UseRegisterOrConstant(instr->object());
2426 obj = needs_write_barrier_for_map
2427 ? UseRegister(instr->object())
2428 : UseRegisterAtStart(instr->object());
2431 bool can_be_constant = instr->value()->IsConstant() &&
2432 HConstant::cast(instr->value())->NotInNewSpace() &&
2433 !instr->field_representation().IsDouble();
2436 if (instr->field_representation().IsInteger8() ||
2437 instr->field_representation().IsUInteger8()) {
2438 // mov_b requires a byte register (i.e. any of eax, ebx, ecx, edx).
2439 // Just force the value to be in eax and we're safe here.
2440 val = UseFixed(instr->value(), eax);
2441 } else if (needs_write_barrier) {
2442 val = UseTempRegister(instr->value());
2443 } else if (can_be_constant) {
2444 val = UseRegisterOrConstant(instr->value());
2445 } else if (instr->field_representation().IsDouble()) {
2446 val = UseRegisterAtStart(instr->value());
2448 val = UseRegister(instr->value());
2451 // We only need a scratch register if we have a write barrier or we
2452 // have a store into the properties array (not in-object-property).
2453 LOperand* temp = (!is_in_object || needs_write_barrier ||
2454 needs_write_barrier_for_map) ? TempRegister() : NULL;
2456 // We need a temporary register for write barrier of the map field.
2457 LOperand* temp_map = needs_write_barrier_for_map ? TempRegister() : NULL;
2459 return new(zone()) LStoreNamedField(obj, val, temp, temp_map);
2463 LInstruction* LChunkBuilder::DoStoreNamedGeneric(HStoreNamedGeneric* instr) {
2464 LOperand* context = UseFixed(instr->context(), esi);
2466 UseFixed(instr->object(), StoreDescriptor::ReceiverRegister());
2467 LOperand* value = UseFixed(instr->value(), StoreDescriptor::ValueRegister());
2468 LOperand* slot = NULL;
2469 LOperand* vector = NULL;
2470 if (instr->HasVectorAndSlot()) {
2471 slot = FixedTemp(VectorStoreICDescriptor::SlotRegister());
2472 vector = FixedTemp(VectorStoreICDescriptor::VectorRegister());
2475 LStoreNamedGeneric* result =
2476 new (zone()) LStoreNamedGeneric(context, object, value, slot, vector);
2477 return MarkAsCall(result, instr);
2481 LInstruction* LChunkBuilder::DoStoreGlobalViaContext(
2482 HStoreGlobalViaContext* instr) {
2483 LOperand* context = UseFixed(instr->context(), esi);
2484 LOperand* value = UseFixed(instr->value(),
2485 StoreGlobalViaContextDescriptor::ValueRegister());
2486 DCHECK(instr->slot_index() > 0);
2488 LStoreGlobalViaContext* result =
2489 new (zone()) LStoreGlobalViaContext(context, value);
2490 return MarkAsCall(result, instr);
2494 LInstruction* LChunkBuilder::DoStringAdd(HStringAdd* instr) {
2495 LOperand* context = UseFixed(instr->context(), esi);
2496 LOperand* left = UseFixed(instr->left(), edx);
2497 LOperand* right = UseFixed(instr->right(), eax);
2498 LStringAdd* string_add = new(zone()) LStringAdd(context, left, right);
2499 return MarkAsCall(DefineFixed(string_add, eax), instr);
2503 LInstruction* LChunkBuilder::DoStringCharCodeAt(HStringCharCodeAt* instr) {
2504 LOperand* string = UseTempRegister(instr->string());
2505 LOperand* index = UseTempRegister(instr->index());
2506 LOperand* context = UseAny(instr->context());
2507 LStringCharCodeAt* result =
2508 new(zone()) LStringCharCodeAt(context, string, index);
2509 return AssignPointerMap(DefineAsRegister(result));
2513 LInstruction* LChunkBuilder::DoStringCharFromCode(HStringCharFromCode* instr) {
2514 LOperand* char_code = UseRegister(instr->value());
2515 LOperand* context = UseAny(instr->context());
2516 LStringCharFromCode* result =
2517 new(zone()) LStringCharFromCode(context, char_code);
2518 return AssignPointerMap(DefineAsRegister(result));
2522 LInstruction* LChunkBuilder::DoAllocate(HAllocate* instr) {
2523 info()->MarkAsDeferredCalling();
2524 LOperand* context = UseAny(instr->context());
2525 LOperand* size = instr->size()->IsConstant()
2526 ? UseConstant(instr->size())
2527 : UseTempRegister(instr->size());
2528 LOperand* temp = TempRegister();
2529 LAllocate* result = new(zone()) LAllocate(context, size, temp);
2530 return AssignPointerMap(DefineAsRegister(result));
2534 LInstruction* LChunkBuilder::DoRegExpLiteral(HRegExpLiteral* instr) {
2535 LOperand* context = UseFixed(instr->context(), esi);
2537 DefineFixed(new(zone()) LRegExpLiteral(context), eax), instr);
2541 LInstruction* LChunkBuilder::DoOsrEntry(HOsrEntry* instr) {
2542 DCHECK(argument_count_ == 0);
2543 allocator_->MarkAsOsrEntry();
2544 current_block_->last_environment()->set_ast_id(instr->ast_id());
2545 return AssignEnvironment(new(zone()) LOsrEntry);
2549 LInstruction* LChunkBuilder::DoParameter(HParameter* instr) {
2550 LParameter* result = new(zone()) LParameter;
2551 if (instr->kind() == HParameter::STACK_PARAMETER) {
2552 int spill_index = chunk()->GetParameterStackSlot(instr->index());
2553 return DefineAsSpilled(result, spill_index);
2555 DCHECK(info()->IsStub());
2556 CallInterfaceDescriptor descriptor =
2557 info()->code_stub()->GetCallInterfaceDescriptor();
2558 int index = static_cast<int>(instr->index());
2559 Register reg = descriptor.GetRegisterParameter(index);
2560 return DefineFixed(result, reg);
2565 LInstruction* LChunkBuilder::DoUnknownOSRValue(HUnknownOSRValue* instr) {
2566 // Use an index that corresponds to the location in the unoptimized frame,
2567 // which the optimized frame will subsume.
2568 int env_index = instr->index();
2569 int spill_index = 0;
2570 if (instr->environment()->is_parameter_index(env_index)) {
2571 spill_index = chunk()->GetParameterStackSlot(env_index);
2573 spill_index = env_index - instr->environment()->first_local_index();
2574 if (spill_index > LUnallocated::kMaxFixedSlotIndex) {
2575 Retry(kNotEnoughSpillSlotsForOsr);
2578 if (spill_index == 0) {
2579 // The dynamic frame alignment state overwrites the first local.
2580 // The first local is saved at the end of the unoptimized frame.
2581 spill_index = graph()->osr()->UnoptimizedFrameSlots();
2584 return DefineAsSpilled(new(zone()) LUnknownOSRValue, spill_index);
2588 LInstruction* LChunkBuilder::DoCallStub(HCallStub* instr) {
2589 LOperand* context = UseFixed(instr->context(), esi);
2590 LCallStub* result = new(zone()) LCallStub(context);
2591 return MarkAsCall(DefineFixed(result, eax), instr);
2595 LInstruction* LChunkBuilder::DoArgumentsObject(HArgumentsObject* instr) {
2596 // There are no real uses of the arguments object.
2597 // arguments.length and element access are supported directly on
2598 // stack arguments, and any real arguments object use causes a bailout.
2599 // So this value is never used.
2604 LInstruction* LChunkBuilder::DoCapturedObject(HCapturedObject* instr) {
2605 instr->ReplayEnvironment(current_block_->last_environment());
2607 // There are no real uses of a captured object.
2612 LInstruction* LChunkBuilder::DoAccessArgumentsAt(HAccessArgumentsAt* instr) {
2613 info()->MarkAsRequiresFrame();
2614 LOperand* args = UseRegister(instr->arguments());
2617 if (instr->length()->IsConstant() && instr->index()->IsConstant()) {
2618 length = UseRegisterOrConstant(instr->length());
2619 index = UseOrConstant(instr->index());
2621 length = UseTempRegister(instr->length());
2622 index = Use(instr->index());
2624 return DefineAsRegister(new(zone()) LAccessArgumentsAt(args, length, index));
2628 LInstruction* LChunkBuilder::DoToFastProperties(HToFastProperties* instr) {
2629 LOperand* object = UseFixed(instr->value(), eax);
2630 LToFastProperties* result = new(zone()) LToFastProperties(object);
2631 return MarkAsCall(DefineFixed(result, eax), instr);
2635 LInstruction* LChunkBuilder::DoTypeof(HTypeof* instr) {
2636 LOperand* context = UseFixed(instr->context(), esi);
2637 LOperand* value = UseFixed(instr->value(), ebx);
2638 LTypeof* result = new(zone()) LTypeof(context, value);
2639 return MarkAsCall(DefineFixed(result, eax), instr);
2643 LInstruction* LChunkBuilder::DoTypeofIsAndBranch(HTypeofIsAndBranch* instr) {
2644 return new(zone()) LTypeofIsAndBranch(UseTempRegister(instr->value()));
2648 LInstruction* LChunkBuilder::DoIsConstructCallAndBranch(
2649 HIsConstructCallAndBranch* instr) {
2650 return new(zone()) LIsConstructCallAndBranch(TempRegister());
2654 LInstruction* LChunkBuilder::DoSimulate(HSimulate* instr) {
2655 instr->ReplayEnvironment(current_block_->last_environment());
2660 LInstruction* LChunkBuilder::DoStackCheck(HStackCheck* instr) {
2661 info()->MarkAsDeferredCalling();
2662 if (instr->is_function_entry()) {
2663 LOperand* context = UseFixed(instr->context(), esi);
2664 return MarkAsCall(new(zone()) LStackCheck(context), instr);
2666 DCHECK(instr->is_backwards_branch());
2667 LOperand* context = UseAny(instr->context());
2668 return AssignEnvironment(
2669 AssignPointerMap(new(zone()) LStackCheck(context)));
2674 LInstruction* LChunkBuilder::DoEnterInlined(HEnterInlined* instr) {
2675 HEnvironment* outer = current_block_->last_environment();
2676 outer->set_ast_id(instr->ReturnId());
2677 HConstant* undefined = graph()->GetConstantUndefined();
2678 HEnvironment* inner = outer->CopyForInlining(instr->closure(),
2679 instr->arguments_count(),
2682 instr->inlining_kind());
2683 // Only replay binding of arguments object if it wasn't removed from graph.
2684 if (instr->arguments_var() != NULL && instr->arguments_object()->IsLinked()) {
2685 inner->Bind(instr->arguments_var(), instr->arguments_object());
2687 inner->BindContext(instr->closure_context());
2688 inner->set_entry(instr);
2689 current_block_->UpdateEnvironment(inner);
2690 chunk_->AddInlinedFunction(instr->shared());
2695 LInstruction* LChunkBuilder::DoLeaveInlined(HLeaveInlined* instr) {
2696 LInstruction* pop = NULL;
2698 HEnvironment* env = current_block_->last_environment();
2700 if (env->entry()->arguments_pushed()) {
2701 int argument_count = env->arguments_environment()->parameter_count();
2702 pop = new(zone()) LDrop(argument_count);
2703 DCHECK(instr->argument_delta() == -argument_count);
2706 HEnvironment* outer = current_block_->last_environment()->
2707 DiscardInlined(false);
2708 current_block_->UpdateEnvironment(outer);
2713 LInstruction* LChunkBuilder::DoForInPrepareMap(HForInPrepareMap* instr) {
2714 LOperand* context = UseFixed(instr->context(), esi);
2715 LOperand* object = UseFixed(instr->enumerable(), eax);
2716 LForInPrepareMap* result = new(zone()) LForInPrepareMap(context, object);
2717 return MarkAsCall(DefineFixed(result, eax), instr, CAN_DEOPTIMIZE_EAGERLY);
2721 LInstruction* LChunkBuilder::DoForInCacheArray(HForInCacheArray* instr) {
2722 LOperand* map = UseRegister(instr->map());
2723 return AssignEnvironment(DefineAsRegister(
2724 new(zone()) LForInCacheArray(map)));
2728 LInstruction* LChunkBuilder::DoCheckMapValue(HCheckMapValue* instr) {
2729 LOperand* value = UseRegisterAtStart(instr->value());
2730 LOperand* map = UseRegisterAtStart(instr->map());
2731 return AssignEnvironment(new(zone()) LCheckMapValue(value, map));
2735 LInstruction* LChunkBuilder::DoLoadFieldByIndex(HLoadFieldByIndex* instr) {
2736 LOperand* object = UseRegister(instr->object());
2737 LOperand* index = UseTempRegister(instr->index());
2738 LLoadFieldByIndex* load = new(zone()) LLoadFieldByIndex(object, index);
2739 LInstruction* result = DefineSameAsFirst(load);
2740 return AssignPointerMap(result);
2744 LInstruction* LChunkBuilder::DoStoreFrameContext(HStoreFrameContext* instr) {
2745 LOperand* context = UseRegisterAtStart(instr->context());
2746 return new(zone()) LStoreFrameContext(context);
2750 LInstruction* LChunkBuilder::DoAllocateBlockContext(
2751 HAllocateBlockContext* instr) {
2752 LOperand* context = UseFixed(instr->context(), esi);
2753 LOperand* function = UseRegisterAtStart(instr->function());
2754 LAllocateBlockContext* result =
2755 new(zone()) LAllocateBlockContext(context, function);
2756 return MarkAsCall(DefineFixed(result, esi), instr);
2760 } // namespace internal
2763 #endif // V8_TARGET_ARCH_IA32