1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
11 #include "src/hydrogen-osr.h"
12 #include "src/lithium-inl.h"
13 #include "src/x87/lithium-codegen-x87.h"
18 #define DEFINE_COMPILE(type) \
19 void L##type::CompileToNative(LCodeGen* generator) { \
20 generator->Do##type(this); \
22 LITHIUM_CONCRETE_INSTRUCTION_LIST(DEFINE_COMPILE)
27 void LInstruction::VerifyCall() {
28 // Call instructions can use only fixed registers as temporaries and
29 // outputs because all registers are blocked by the calling convention.
30 // Inputs operands must use a fixed register or use-at-start policy or
31 // a non-register policy.
32 DCHECK(Output() == NULL ||
33 LUnallocated::cast(Output())->HasFixedPolicy() ||
34 !LUnallocated::cast(Output())->HasRegisterPolicy());
35 for (UseIterator it(this); !it.Done(); it.Advance()) {
36 LUnallocated* operand = LUnallocated::cast(it.Current());
37 DCHECK(operand->HasFixedPolicy() ||
38 operand->IsUsedAtStart());
40 for (TempIterator it(this); !it.Done(); it.Advance()) {
41 LUnallocated* operand = LUnallocated::cast(it.Current());
42 DCHECK(operand->HasFixedPolicy() ||!operand->HasRegisterPolicy());
48 bool LInstruction::HasDoubleRegisterResult() {
49 return HasResult() && result()->IsDoubleRegister();
53 bool LInstruction::HasDoubleRegisterInput() {
54 for (int i = 0; i < InputCount(); i++) {
55 LOperand* op = InputAt(i);
56 if (op != NULL && op->IsDoubleRegister()) {
64 bool LInstruction::IsDoubleInput(X87Register reg, LCodeGen* cgen) {
65 for (int i = 0; i < InputCount(); i++) {
66 LOperand* op = InputAt(i);
67 if (op != NULL && op->IsDoubleRegister()) {
68 if (cgen->ToX87Register(op).is(reg)) return true;
75 void LInstruction::PrintTo(StringStream* stream) {
76 stream->Add("%s ", this->Mnemonic());
78 PrintOutputOperandTo(stream);
82 if (HasEnvironment()) {
84 environment()->PrintTo(stream);
87 if (HasPointerMap()) {
89 pointer_map()->PrintTo(stream);
94 void LInstruction::PrintDataTo(StringStream* stream) {
96 for (int i = 0; i < InputCount(); i++) {
97 if (i > 0) stream->Add(" ");
98 if (InputAt(i) == NULL) {
101 InputAt(i)->PrintTo(stream);
107 void LInstruction::PrintOutputOperandTo(StringStream* stream) {
108 if (HasResult()) result()->PrintTo(stream);
112 void LLabel::PrintDataTo(StringStream* stream) {
113 LGap::PrintDataTo(stream);
114 LLabel* rep = replacement();
116 stream->Add(" Dead block replaced with B%d", rep->block_id());
121 bool LGap::IsRedundant() const {
122 for (int i = 0; i < 4; i++) {
123 if (parallel_moves_[i] != NULL && !parallel_moves_[i]->IsRedundant()) {
132 void LGap::PrintDataTo(StringStream* stream) {
133 for (int i = 0; i < 4; i++) {
135 if (parallel_moves_[i] != NULL) {
136 parallel_moves_[i]->PrintDataTo(stream);
143 const char* LArithmeticD::Mnemonic() const {
145 case Token::ADD: return "add-d";
146 case Token::SUB: return "sub-d";
147 case Token::MUL: return "mul-d";
148 case Token::DIV: return "div-d";
149 case Token::MOD: return "mod-d";
157 const char* LArithmeticT::Mnemonic() const {
159 case Token::ADD: return "add-t";
160 case Token::SUB: return "sub-t";
161 case Token::MUL: return "mul-t";
162 case Token::MOD: return "mod-t";
163 case Token::DIV: return "div-t";
164 case Token::BIT_AND: return "bit-and-t";
165 case Token::BIT_OR: return "bit-or-t";
166 case Token::BIT_XOR: return "bit-xor-t";
167 case Token::ROR: return "ror-t";
168 case Token::SHL: return "sal-t";
169 case Token::SAR: return "sar-t";
170 case Token::SHR: return "shr-t";
178 bool LGoto::HasInterestingComment(LCodeGen* gen) const {
179 return !gen->IsNextEmittedBlock(block_id());
183 void LGoto::PrintDataTo(StringStream* stream) {
184 stream->Add("B%d", block_id());
188 void LBranch::PrintDataTo(StringStream* stream) {
189 stream->Add("B%d | B%d on ", true_block_id(), false_block_id());
190 value()->PrintTo(stream);
194 void LCompareNumericAndBranch::PrintDataTo(StringStream* stream) {
196 left()->PrintTo(stream);
197 stream->Add(" %s ", Token::String(op()));
198 right()->PrintTo(stream);
199 stream->Add(" then B%d else B%d", true_block_id(), false_block_id());
203 void LIsObjectAndBranch::PrintDataTo(StringStream* stream) {
204 stream->Add("if is_object(");
205 value()->PrintTo(stream);
206 stream->Add(") then B%d else B%d", true_block_id(), false_block_id());
210 void LIsStringAndBranch::PrintDataTo(StringStream* stream) {
211 stream->Add("if is_string(");
212 value()->PrintTo(stream);
213 stream->Add(") then B%d else B%d", true_block_id(), false_block_id());
217 void LIsSmiAndBranch::PrintDataTo(StringStream* stream) {
218 stream->Add("if is_smi(");
219 value()->PrintTo(stream);
220 stream->Add(") then B%d else B%d", true_block_id(), false_block_id());
224 void LIsUndetectableAndBranch::PrintDataTo(StringStream* stream) {
225 stream->Add("if is_undetectable(");
226 value()->PrintTo(stream);
227 stream->Add(") then B%d else B%d", true_block_id(), false_block_id());
231 void LStringCompareAndBranch::PrintDataTo(StringStream* stream) {
232 stream->Add("if string_compare(");
233 left()->PrintTo(stream);
234 right()->PrintTo(stream);
235 stream->Add(") then B%d else B%d", true_block_id(), false_block_id());
239 void LHasInstanceTypeAndBranch::PrintDataTo(StringStream* stream) {
240 stream->Add("if has_instance_type(");
241 value()->PrintTo(stream);
242 stream->Add(") then B%d else B%d", true_block_id(), false_block_id());
246 void LHasCachedArrayIndexAndBranch::PrintDataTo(StringStream* stream) {
247 stream->Add("if has_cached_array_index(");
248 value()->PrintTo(stream);
249 stream->Add(") then B%d else B%d", true_block_id(), false_block_id());
253 void LClassOfTestAndBranch::PrintDataTo(StringStream* stream) {
254 stream->Add("if class_of_test(");
255 value()->PrintTo(stream);
256 stream->Add(", \"%o\") then B%d else B%d",
257 *hydrogen()->class_name(),
263 void LTypeofIsAndBranch::PrintDataTo(StringStream* stream) {
264 stream->Add("if typeof ");
265 value()->PrintTo(stream);
266 stream->Add(" == \"%s\" then B%d else B%d",
267 hydrogen()->type_literal()->ToCString().get(),
268 true_block_id(), false_block_id());
272 void LStoreCodeEntry::PrintDataTo(StringStream* stream) {
274 function()->PrintTo(stream);
275 stream->Add(".code_entry = ");
276 code_object()->PrintTo(stream);
280 void LInnerAllocatedObject::PrintDataTo(StringStream* stream) {
282 base_object()->PrintTo(stream);
284 offset()->PrintTo(stream);
288 void LCallFunction::PrintDataTo(StringStream* stream) {
289 context()->PrintTo(stream);
291 function()->PrintTo(stream);
292 if (hydrogen()->HasVectorAndSlot()) {
293 stream->Add(" (type-feedback-vector ");
294 temp_vector()->PrintTo(stream);
296 temp_slot()->PrintTo(stream);
302 void LCallJSFunction::PrintDataTo(StringStream* stream) {
304 function()->PrintTo(stream);
305 stream->Add("#%d / ", arity());
309 void LCallWithDescriptor::PrintDataTo(StringStream* stream) {
310 for (int i = 0; i < InputCount(); i++) {
311 InputAt(i)->PrintTo(stream);
314 stream->Add("#%d / ", arity());
318 void LLoadContextSlot::PrintDataTo(StringStream* stream) {
319 context()->PrintTo(stream);
320 stream->Add("[%d]", slot_index());
324 void LStoreContextSlot::PrintDataTo(StringStream* stream) {
325 context()->PrintTo(stream);
326 stream->Add("[%d] <- ", slot_index());
327 value()->PrintTo(stream);
331 void LInvokeFunction::PrintDataTo(StringStream* stream) {
333 context()->PrintTo(stream);
335 function()->PrintTo(stream);
336 stream->Add(" #%d / ", arity());
340 void LCallNew::PrintDataTo(StringStream* stream) {
342 context()->PrintTo(stream);
344 constructor()->PrintTo(stream);
345 stream->Add(" #%d / ", arity());
349 void LCallNewArray::PrintDataTo(StringStream* stream) {
351 context()->PrintTo(stream);
353 constructor()->PrintTo(stream);
354 stream->Add(" #%d / ", arity());
355 ElementsKind kind = hydrogen()->elements_kind();
356 stream->Add(" (%s) ", ElementsKindToString(kind));
360 void LAccessArgumentsAt::PrintDataTo(StringStream* stream) {
361 arguments()->PrintTo(stream);
363 stream->Add(" length ");
364 length()->PrintTo(stream);
366 stream->Add(" index ");
367 index()->PrintTo(stream);
371 int LPlatformChunk::GetNextSpillIndex(RegisterKind kind) {
372 // Skip a slot if for a double-width slot.
373 if (kind == DOUBLE_REGISTERS) {
375 spill_slot_count_ |= 1;
378 return spill_slot_count_++;
382 LOperand* LPlatformChunk::GetNextSpillSlot(RegisterKind kind) {
383 int index = GetNextSpillIndex(kind);
384 if (kind == DOUBLE_REGISTERS) {
385 return LDoubleStackSlot::Create(index, zone());
387 DCHECK(kind == GENERAL_REGISTERS);
388 return LStackSlot::Create(index, zone());
393 void LLoadGlobalViaContext::PrintDataTo(StringStream* stream) {
394 stream->Add("depth:%d slot:%d", depth(), slot_index());
398 void LStoreNamedField::PrintDataTo(StringStream* stream) {
399 object()->PrintTo(stream);
400 std::ostringstream os;
401 os << hydrogen()->access() << " <- ";
402 stream->Add(os.str().c_str());
403 value()->PrintTo(stream);
407 void LStoreNamedGeneric::PrintDataTo(StringStream* stream) {
408 object()->PrintTo(stream);
410 stream->Add(String::cast(*name())->ToCString().get());
412 value()->PrintTo(stream);
416 void LStoreGlobalViaContext::PrintDataTo(StringStream* stream) {
417 stream->Add("depth:%d slot:%d <- ", depth(), slot_index());
418 value()->PrintTo(stream);
422 void LLoadKeyed::PrintDataTo(StringStream* stream) {
423 elements()->PrintTo(stream);
425 key()->PrintTo(stream);
426 if (hydrogen()->IsDehoisted()) {
427 stream->Add(" + %d]", base_offset());
434 void LStoreKeyed::PrintDataTo(StringStream* stream) {
435 elements()->PrintTo(stream);
437 key()->PrintTo(stream);
438 if (hydrogen()->IsDehoisted()) {
439 stream->Add(" + %d] <-", base_offset());
441 stream->Add("] <- ");
444 if (value() == NULL) {
445 DCHECK(hydrogen()->IsConstantHoleStore() &&
446 hydrogen()->value()->representation().IsDouble());
447 stream->Add("<the hole(nan)>");
449 value()->PrintTo(stream);
454 void LStoreKeyedGeneric::PrintDataTo(StringStream* stream) {
455 object()->PrintTo(stream);
457 key()->PrintTo(stream);
458 stream->Add("] <- ");
459 value()->PrintTo(stream);
463 void LTransitionElementsKind::PrintDataTo(StringStream* stream) {
464 object()->PrintTo(stream);
465 stream->Add(" %p -> %p", *original_map(), *transitioned_map());
469 LPlatformChunk* LChunkBuilder::Build() {
471 chunk_ = new(zone()) LPlatformChunk(info(), graph());
472 LPhase phase("L_Building chunk", chunk_);
475 // Reserve the first spill slot for the state of dynamic alignment.
476 if (info()->IsOptimizing()) {
477 int alignment_state_index = chunk_->GetNextSpillIndex(GENERAL_REGISTERS);
478 DCHECK_EQ(alignment_state_index, 0);
479 USE(alignment_state_index);
482 // If compiling for OSR, reserve space for the unoptimized frame,
483 // which will be subsumed into this frame.
484 if (graph()->has_osr()) {
485 for (int i = graph()->osr()->UnoptimizedFrameSlots(); i > 0; i--) {
486 chunk_->GetNextSpillIndex(GENERAL_REGISTERS);
490 const ZoneList<HBasicBlock*>* blocks = graph()->blocks();
491 for (int i = 0; i < blocks->length(); i++) {
492 HBasicBlock* next = NULL;
493 if (i < blocks->length() - 1) next = blocks->at(i + 1);
494 DoBasicBlock(blocks->at(i), next);
495 if (is_aborted()) return NULL;
502 LUnallocated* LChunkBuilder::ToUnallocated(Register reg) {
503 return new(zone()) LUnallocated(LUnallocated::FIXED_REGISTER,
504 Register::ToAllocationIndex(reg));
508 LUnallocated* LChunkBuilder::ToUnallocated(X87Register reg) {
509 return new (zone()) LUnallocated(LUnallocated::FIXED_DOUBLE_REGISTER,
510 X87Register::ToAllocationIndex(reg));
514 LOperand* LChunkBuilder::UseFixed(HValue* value, Register fixed_register) {
515 return Use(value, ToUnallocated(fixed_register));
519 LOperand* LChunkBuilder::UseRegister(HValue* value) {
520 return Use(value, new(zone()) LUnallocated(LUnallocated::MUST_HAVE_REGISTER));
524 LOperand* LChunkBuilder::UseRegisterAtStart(HValue* value) {
526 new(zone()) LUnallocated(LUnallocated::MUST_HAVE_REGISTER,
527 LUnallocated::USED_AT_START));
531 LOperand* LChunkBuilder::UseTempRegister(HValue* value) {
532 return Use(value, new(zone()) LUnallocated(LUnallocated::WRITABLE_REGISTER));
536 LOperand* LChunkBuilder::Use(HValue* value) {
537 return Use(value, new(zone()) LUnallocated(LUnallocated::NONE));
541 LOperand* LChunkBuilder::UseAtStart(HValue* value) {
542 return Use(value, new(zone()) LUnallocated(LUnallocated::NONE,
543 LUnallocated::USED_AT_START));
547 static inline bool CanBeImmediateConstant(HValue* value) {
548 return value->IsConstant() && HConstant::cast(value)->NotInNewSpace();
552 LOperand* LChunkBuilder::UseOrConstant(HValue* value) {
553 return CanBeImmediateConstant(value)
554 ? chunk_->DefineConstantOperand(HConstant::cast(value))
559 LOperand* LChunkBuilder::UseOrConstantAtStart(HValue* value) {
560 return CanBeImmediateConstant(value)
561 ? chunk_->DefineConstantOperand(HConstant::cast(value))
566 LOperand* LChunkBuilder::UseFixedOrConstant(HValue* value,
567 Register fixed_register) {
568 return CanBeImmediateConstant(value)
569 ? chunk_->DefineConstantOperand(HConstant::cast(value))
570 : UseFixed(value, fixed_register);
574 LOperand* LChunkBuilder::UseRegisterOrConstant(HValue* value) {
575 return CanBeImmediateConstant(value)
576 ? chunk_->DefineConstantOperand(HConstant::cast(value))
577 : UseRegister(value);
581 LOperand* LChunkBuilder::UseRegisterOrConstantAtStart(HValue* value) {
582 return CanBeImmediateConstant(value)
583 ? chunk_->DefineConstantOperand(HConstant::cast(value))
584 : UseRegisterAtStart(value);
588 LOperand* LChunkBuilder::UseConstant(HValue* value) {
589 return chunk_->DefineConstantOperand(HConstant::cast(value));
593 LOperand* LChunkBuilder::UseAny(HValue* value) {
594 return value->IsConstant()
595 ? chunk_->DefineConstantOperand(HConstant::cast(value))
596 : Use(value, new(zone()) LUnallocated(LUnallocated::ANY));
600 LOperand* LChunkBuilder::Use(HValue* value, LUnallocated* operand) {
601 if (value->EmitAtUses()) {
602 HInstruction* instr = HInstruction::cast(value);
603 VisitInstruction(instr);
605 operand->set_virtual_register(value->id());
610 LInstruction* LChunkBuilder::Define(LTemplateResultInstruction<1>* instr,
611 LUnallocated* result) {
612 result->set_virtual_register(current_instruction_->id());
613 instr->set_result(result);
618 LInstruction* LChunkBuilder::DefineAsRegister(
619 LTemplateResultInstruction<1>* instr) {
621 new(zone()) LUnallocated(LUnallocated::MUST_HAVE_REGISTER));
625 LInstruction* LChunkBuilder::DefineAsSpilled(
626 LTemplateResultInstruction<1>* instr,
629 new(zone()) LUnallocated(LUnallocated::FIXED_SLOT, index));
633 LInstruction* LChunkBuilder::DefineSameAsFirst(
634 LTemplateResultInstruction<1>* instr) {
636 new(zone()) LUnallocated(LUnallocated::SAME_AS_FIRST_INPUT));
640 LInstruction* LChunkBuilder::DefineFixed(LTemplateResultInstruction<1>* instr,
642 return Define(instr, ToUnallocated(reg));
646 LInstruction* LChunkBuilder::DefineFixed(LTemplateResultInstruction<1>* instr,
648 return Define(instr, ToUnallocated(reg));
652 LInstruction* LChunkBuilder::AssignEnvironment(LInstruction* instr) {
653 HEnvironment* hydrogen_env = current_block_->last_environment();
654 int argument_index_accumulator = 0;
655 ZoneList<HValue*> objects_to_materialize(0, zone());
656 instr->set_environment(CreateEnvironment(hydrogen_env,
657 &argument_index_accumulator,
658 &objects_to_materialize));
663 LInstruction* LChunkBuilder::MarkAsCall(LInstruction* instr,
664 HInstruction* hinstr,
665 CanDeoptimize can_deoptimize) {
666 info()->MarkAsNonDeferredCalling();
672 instr = AssignPointerMap(instr);
674 // If instruction does not have side-effects lazy deoptimization
675 // after the call will try to deoptimize to the point before the call.
676 // Thus we still need to attach environment to this call even if
677 // call sequence can not deoptimize eagerly.
678 bool needs_environment =
679 (can_deoptimize == CAN_DEOPTIMIZE_EAGERLY) ||
680 !hinstr->HasObservableSideEffects();
681 if (needs_environment && !instr->HasEnvironment()) {
682 instr = AssignEnvironment(instr);
683 // We can't really figure out if the environment is needed or not.
684 instr->environment()->set_has_been_used();
691 LInstruction* LChunkBuilder::AssignPointerMap(LInstruction* instr) {
692 DCHECK(!instr->HasPointerMap());
693 instr->set_pointer_map(new(zone()) LPointerMap(zone()));
698 LUnallocated* LChunkBuilder::TempRegister() {
699 LUnallocated* operand =
700 new(zone()) LUnallocated(LUnallocated::MUST_HAVE_REGISTER);
701 int vreg = allocator_->GetVirtualRegister();
702 if (!allocator_->AllocationOk()) {
703 Abort(kOutOfVirtualRegistersWhileTryingToAllocateTempRegister);
706 operand->set_virtual_register(vreg);
711 LOperand* LChunkBuilder::FixedTemp(Register reg) {
712 LUnallocated* operand = ToUnallocated(reg);
713 DCHECK(operand->HasFixedPolicy());
718 LInstruction* LChunkBuilder::DoBlockEntry(HBlockEntry* instr) {
719 return new(zone()) LLabel(instr->block());
723 LInstruction* LChunkBuilder::DoDummyUse(HDummyUse* instr) {
724 return DefineAsRegister(new(zone()) LDummyUse(UseAny(instr->value())));
728 LInstruction* LChunkBuilder::DoEnvironmentMarker(HEnvironmentMarker* instr) {
734 LInstruction* LChunkBuilder::DoDeoptimize(HDeoptimize* instr) {
735 return AssignEnvironment(new(zone()) LDeoptimize);
739 LInstruction* LChunkBuilder::DoShift(Token::Value op,
740 HBitwiseBinaryOperation* instr) {
741 if (instr->representation().IsSmiOrInteger32()) {
742 DCHECK(instr->left()->representation().Equals(instr->representation()));
743 DCHECK(instr->right()->representation().Equals(instr->representation()));
744 LOperand* left = UseRegisterAtStart(instr->left());
746 HValue* right_value = instr->right();
747 LOperand* right = NULL;
748 int constant_value = 0;
749 bool does_deopt = false;
750 if (right_value->IsConstant()) {
751 HConstant* constant = HConstant::cast(right_value);
752 right = chunk_->DefineConstantOperand(constant);
753 constant_value = constant->Integer32Value() & 0x1f;
754 // Left shifts can deoptimize if we shift by > 0 and the result cannot be
756 if (instr->representation().IsSmi() && constant_value > 0) {
757 does_deopt = !instr->CheckUsesForFlag(HValue::kTruncatingToSmi);
760 right = UseFixed(right_value, ecx);
763 // Shift operations can only deoptimize if we do a logical shift by 0 and
764 // the result cannot be truncated to int32.
765 if (op == Token::SHR && constant_value == 0) {
766 does_deopt = !instr->CheckFlag(HInstruction::kUint32);
769 LInstruction* result =
770 DefineSameAsFirst(new(zone()) LShiftI(op, left, right, does_deopt));
771 return does_deopt ? AssignEnvironment(result) : result;
773 return DoArithmeticT(op, instr);
778 LInstruction* LChunkBuilder::DoArithmeticD(Token::Value op,
779 HArithmeticBinaryOperation* instr) {
780 DCHECK(instr->representation().IsDouble());
781 DCHECK(instr->left()->representation().IsDouble());
782 DCHECK(instr->right()->representation().IsDouble());
783 if (op == Token::MOD) {
784 LOperand* left = UseRegisterAtStart(instr->BetterLeftOperand());
785 LOperand* right = UseRegisterAtStart(instr->BetterRightOperand());
786 LArithmeticD* result = new(zone()) LArithmeticD(op, left, right);
787 return MarkAsCall(DefineSameAsFirst(result), instr);
789 LOperand* left = UseRegisterAtStart(instr->BetterLeftOperand());
790 LOperand* right = UseRegisterAtStart(instr->BetterRightOperand());
791 LArithmeticD* result = new(zone()) LArithmeticD(op, left, right);
792 return DefineSameAsFirst(result);
797 LInstruction* LChunkBuilder::DoArithmeticT(Token::Value op,
798 HBinaryOperation* instr) {
799 HValue* left = instr->left();
800 HValue* right = instr->right();
801 DCHECK(left->representation().IsTagged());
802 DCHECK(right->representation().IsTagged());
803 LOperand* context = UseFixed(instr->context(), esi);
804 LOperand* left_operand = UseFixed(left, edx);
805 LOperand* right_operand = UseFixed(right, eax);
806 LArithmeticT* result =
807 new(zone()) LArithmeticT(op, context, left_operand, right_operand);
808 return MarkAsCall(DefineFixed(result, eax), instr);
812 void LChunkBuilder::DoBasicBlock(HBasicBlock* block, HBasicBlock* next_block) {
813 DCHECK(is_building());
814 current_block_ = block;
815 next_block_ = next_block;
816 if (block->IsStartBlock()) {
817 block->UpdateEnvironment(graph_->start_environment());
819 } else if (block->predecessors()->length() == 1) {
820 // We have a single predecessor => copy environment and outgoing
821 // argument count from the predecessor.
822 DCHECK(block->phis()->length() == 0);
823 HBasicBlock* pred = block->predecessors()->at(0);
824 HEnvironment* last_environment = pred->last_environment();
825 DCHECK(last_environment != NULL);
826 // Only copy the environment, if it is later used again.
827 if (pred->end()->SecondSuccessor() == NULL) {
828 DCHECK(pred->end()->FirstSuccessor() == block);
830 if (pred->end()->FirstSuccessor()->block_id() > block->block_id() ||
831 pred->end()->SecondSuccessor()->block_id() > block->block_id()) {
832 last_environment = last_environment->Copy();
835 block->UpdateEnvironment(last_environment);
836 DCHECK(pred->argument_count() >= 0);
837 argument_count_ = pred->argument_count();
839 // We are at a state join => process phis.
840 HBasicBlock* pred = block->predecessors()->at(0);
841 // No need to copy the environment, it cannot be used later.
842 HEnvironment* last_environment = pred->last_environment();
843 for (int i = 0; i < block->phis()->length(); ++i) {
844 HPhi* phi = block->phis()->at(i);
845 if (phi->HasMergedIndex()) {
846 last_environment->SetValueAt(phi->merged_index(), phi);
849 for (int i = 0; i < block->deleted_phis()->length(); ++i) {
850 if (block->deleted_phis()->at(i) < last_environment->length()) {
851 last_environment->SetValueAt(block->deleted_phis()->at(i),
852 graph_->GetConstantUndefined());
855 block->UpdateEnvironment(last_environment);
856 // Pick up the outgoing argument count of one of the predecessors.
857 argument_count_ = pred->argument_count();
859 HInstruction* current = block->first();
860 int start = chunk_->instructions()->length();
861 while (current != NULL && !is_aborted()) {
862 // Code for constants in registers is generated lazily.
863 if (!current->EmitAtUses()) {
864 VisitInstruction(current);
866 current = current->next();
868 int end = chunk_->instructions()->length() - 1;
870 block->set_first_instruction_index(start);
871 block->set_last_instruction_index(end);
873 block->set_argument_count(argument_count_);
875 current_block_ = NULL;
879 void LChunkBuilder::VisitInstruction(HInstruction* current) {
880 HInstruction* old_current = current_instruction_;
881 current_instruction_ = current;
883 LInstruction* instr = NULL;
884 if (current->CanReplaceWithDummyUses()) {
885 if (current->OperandCount() == 0) {
886 instr = DefineAsRegister(new(zone()) LDummy());
888 DCHECK(!current->OperandAt(0)->IsControlInstruction());
889 instr = DefineAsRegister(new(zone())
890 LDummyUse(UseAny(current->OperandAt(0))));
892 for (int i = 1; i < current->OperandCount(); ++i) {
893 if (current->OperandAt(i)->IsControlInstruction()) continue;
894 LInstruction* dummy =
895 new(zone()) LDummyUse(UseAny(current->OperandAt(i)));
896 dummy->set_hydrogen_value(current);
897 chunk_->AddInstruction(dummy, current_block_);
900 HBasicBlock* successor;
901 if (current->IsControlInstruction() &&
902 HControlInstruction::cast(current)->KnownSuccessorBlock(&successor) &&
904 // Always insert a fpu register barrier here when branch is optimized to
906 // TODO(weiliang): require a better solution.
907 if (!current->IsGoto()) {
908 LClobberDoubles* clobber = new (zone()) LClobberDoubles(isolate());
909 clobber->set_hydrogen_value(current);
910 chunk_->AddInstruction(clobber, current_block_);
912 instr = new(zone()) LGoto(successor);
914 instr = current->CompileToLithium(this);
918 argument_count_ += current->argument_delta();
919 DCHECK(argument_count_ >= 0);
922 AddInstruction(instr, current);
925 current_instruction_ = old_current;
929 void LChunkBuilder::AddInstruction(LInstruction* instr,
930 HInstruction* hydrogen_val) {
931 // Associate the hydrogen instruction first, since we may need it for
932 // the ClobbersRegisters() or ClobbersDoubleRegisters() calls below.
933 instr->set_hydrogen_value(hydrogen_val);
936 // Make sure that the lithium instruction has either no fixed register
937 // constraints in temps or the result OR no uses that are only used at
938 // start. If this invariant doesn't hold, the register allocator can decide
939 // to insert a split of a range immediately before the instruction due to an
940 // already allocated register needing to be used for the instruction's fixed
941 // register constraint. In this case, The register allocator won't see an
942 // interference between the split child and the use-at-start (it would if
943 // the it was just a plain use), so it is free to move the split child into
944 // the same register that is used for the use-at-start.
945 // See https://code.google.com/p/chromium/issues/detail?id=201590
946 if (!(instr->ClobbersRegisters() &&
947 instr->ClobbersDoubleRegisters(isolate()))) {
949 int used_at_start = 0;
950 for (UseIterator it(instr); !it.Done(); it.Advance()) {
951 LUnallocated* operand = LUnallocated::cast(it.Current());
952 if (operand->IsUsedAtStart()) ++used_at_start;
954 if (instr->Output() != NULL) {
955 if (LUnallocated::cast(instr->Output())->HasFixedPolicy()) ++fixed;
957 for (TempIterator it(instr); !it.Done(); it.Advance()) {
958 LUnallocated* operand = LUnallocated::cast(it.Current());
959 if (operand->HasFixedPolicy()) ++fixed;
961 DCHECK(fixed == 0 || used_at_start == 0);
965 if (FLAG_stress_pointer_maps && !instr->HasPointerMap()) {
966 instr = AssignPointerMap(instr);
968 if (FLAG_stress_environments && !instr->HasEnvironment()) {
969 instr = AssignEnvironment(instr);
971 if (instr->IsGoto() &&
972 (LGoto::cast(instr)->jumps_to_join() || next_block_->is_osr_entry())) {
973 // TODO(olivf) Since phis of spilled values are joined as registers
974 // (not in the stack slot), we need to allow the goto gaps to keep one
975 // x87 register alive. To ensure all other values are still spilled, we
976 // insert a fpu register barrier right before.
977 LClobberDoubles* clobber = new(zone()) LClobberDoubles(isolate());
978 clobber->set_hydrogen_value(hydrogen_val);
979 chunk_->AddInstruction(clobber, current_block_);
981 chunk_->AddInstruction(instr, current_block_);
983 if (instr->IsCall()) {
984 HValue* hydrogen_value_for_lazy_bailout = hydrogen_val;
985 LInstruction* instruction_needing_environment = NULL;
986 if (hydrogen_val->HasObservableSideEffects()) {
987 HSimulate* sim = HSimulate::cast(hydrogen_val->next());
988 instruction_needing_environment = instr;
989 sim->ReplayEnvironment(current_block_->last_environment());
990 hydrogen_value_for_lazy_bailout = sim;
992 LInstruction* bailout = AssignEnvironment(new(zone()) LLazyBailout());
993 bailout->set_hydrogen_value(hydrogen_value_for_lazy_bailout);
994 chunk_->AddInstruction(bailout, current_block_);
995 if (instruction_needing_environment != NULL) {
996 // Store the lazy deopt environment with the instruction if needed.
997 // Right now it is only used for LInstanceOfKnownGlobal.
998 instruction_needing_environment->
999 SetDeferredLazyDeoptimizationEnvironment(bailout->environment());
1005 LInstruction* LChunkBuilder::DoGoto(HGoto* instr) {
1006 return new(zone()) LGoto(instr->FirstSuccessor());
1010 LInstruction* LChunkBuilder::DoBranch(HBranch* instr) {
1011 HValue* value = instr->value();
1012 Representation r = value->representation();
1013 HType type = value->type();
1014 ToBooleanStub::Types expected = instr->expected_input_types();
1015 if (expected.IsEmpty()) expected = ToBooleanStub::Types::Generic();
1017 bool easy_case = !r.IsTagged() || type.IsBoolean() || type.IsSmi() ||
1018 type.IsJSArray() || type.IsHeapNumber() || type.IsString();
1019 LOperand* temp = !easy_case && expected.NeedsMap() ? TempRegister() : NULL;
1020 LInstruction* branch =
1021 temp != NULL ? new (zone()) LBranch(UseRegister(value), temp)
1022 : new (zone()) LBranch(UseRegisterAtStart(value), temp);
1024 ((!expected.Contains(ToBooleanStub::SMI) && expected.NeedsMap()) ||
1025 !expected.IsGeneric())) {
1026 branch = AssignEnvironment(branch);
1032 LInstruction* LChunkBuilder::DoDebugBreak(HDebugBreak* instr) {
1033 return new(zone()) LDebugBreak();
1037 LInstruction* LChunkBuilder::DoCompareMap(HCompareMap* instr) {
1038 DCHECK(instr->value()->representation().IsTagged());
1039 LOperand* value = UseRegisterAtStart(instr->value());
1040 return new(zone()) LCmpMapAndBranch(value);
1044 LInstruction* LChunkBuilder::DoArgumentsLength(HArgumentsLength* length) {
1045 info()->MarkAsRequiresFrame();
1046 return DefineAsRegister(new(zone()) LArgumentsLength(Use(length->value())));
1050 LInstruction* LChunkBuilder::DoArgumentsElements(HArgumentsElements* elems) {
1051 info()->MarkAsRequiresFrame();
1052 return DefineAsRegister(new(zone()) LArgumentsElements);
1056 LInstruction* LChunkBuilder::DoInstanceOf(HInstanceOf* instr) {
1057 LOperand* left = UseFixed(instr->left(), InstanceofStub::left());
1058 LOperand* right = UseFixed(instr->right(), InstanceofStub::right());
1059 LOperand* context = UseFixed(instr->context(), esi);
1060 LInstanceOf* result = new(zone()) LInstanceOf(context, left, right);
1061 return MarkAsCall(DefineFixed(result, eax), instr);
1065 LInstruction* LChunkBuilder::DoInstanceOfKnownGlobal(
1066 HInstanceOfKnownGlobal* instr) {
1067 LInstanceOfKnownGlobal* result =
1068 new(zone()) LInstanceOfKnownGlobal(
1069 UseFixed(instr->context(), esi),
1070 UseFixed(instr->left(), InstanceofStub::left()),
1072 return MarkAsCall(DefineFixed(result, eax), instr);
1076 LInstruction* LChunkBuilder::DoWrapReceiver(HWrapReceiver* instr) {
1077 LOperand* receiver = UseRegister(instr->receiver());
1078 LOperand* function = UseRegister(instr->function());
1079 LOperand* temp = TempRegister();
1080 LWrapReceiver* result =
1081 new(zone()) LWrapReceiver(receiver, function, temp);
1082 return AssignEnvironment(DefineSameAsFirst(result));
1086 LInstruction* LChunkBuilder::DoApplyArguments(HApplyArguments* instr) {
1087 LOperand* function = UseFixed(instr->function(), edi);
1088 LOperand* receiver = UseFixed(instr->receiver(), eax);
1089 LOperand* length = UseFixed(instr->length(), ebx);
1090 LOperand* elements = UseFixed(instr->elements(), ecx);
1091 LApplyArguments* result = new(zone()) LApplyArguments(function,
1095 return MarkAsCall(DefineFixed(result, eax), instr, CAN_DEOPTIMIZE_EAGERLY);
1099 LInstruction* LChunkBuilder::DoPushArguments(HPushArguments* instr) {
1100 int argc = instr->OperandCount();
1101 for (int i = 0; i < argc; ++i) {
1102 LOperand* argument = UseAny(instr->argument(i));
1103 AddInstruction(new(zone()) LPushArgument(argument), instr);
1109 LInstruction* LChunkBuilder::DoStoreCodeEntry(
1110 HStoreCodeEntry* store_code_entry) {
1111 LOperand* function = UseRegister(store_code_entry->function());
1112 LOperand* code_object = UseTempRegister(store_code_entry->code_object());
1113 return new(zone()) LStoreCodeEntry(function, code_object);
1117 LInstruction* LChunkBuilder::DoInnerAllocatedObject(
1118 HInnerAllocatedObject* instr) {
1119 LOperand* base_object = UseRegisterAtStart(instr->base_object());
1120 LOperand* offset = UseRegisterOrConstantAtStart(instr->offset());
1121 return DefineAsRegister(
1122 new(zone()) LInnerAllocatedObject(base_object, offset));
1126 LInstruction* LChunkBuilder::DoThisFunction(HThisFunction* instr) {
1127 return instr->HasNoUses()
1129 : DefineAsRegister(new(zone()) LThisFunction);
1133 LInstruction* LChunkBuilder::DoContext(HContext* instr) {
1134 if (instr->HasNoUses()) return NULL;
1136 if (info()->IsStub()) {
1137 return DefineFixed(new(zone()) LContext, esi);
1140 return DefineAsRegister(new(zone()) LContext);
1144 LInstruction* LChunkBuilder::DoDeclareGlobals(HDeclareGlobals* instr) {
1145 LOperand* context = UseFixed(instr->context(), esi);
1146 return MarkAsCall(new(zone()) LDeclareGlobals(context), instr);
1150 LInstruction* LChunkBuilder::DoCallJSFunction(
1151 HCallJSFunction* instr) {
1152 LOperand* function = UseFixed(instr->function(), edi);
1154 LCallJSFunction* result = new(zone()) LCallJSFunction(function);
1156 return MarkAsCall(DefineFixed(result, eax), instr, CANNOT_DEOPTIMIZE_EAGERLY);
1160 LInstruction* LChunkBuilder::DoCallWithDescriptor(
1161 HCallWithDescriptor* instr) {
1162 CallInterfaceDescriptor descriptor = instr->descriptor();
1163 LOperand* target = UseRegisterOrConstantAtStart(instr->target());
1164 ZoneList<LOperand*> ops(instr->OperandCount(), zone());
1166 ops.Add(target, zone());
1168 LOperand* op = UseFixed(instr->OperandAt(1), esi);
1169 ops.Add(op, zone());
1170 // Other register parameters
1171 for (int i = LCallWithDescriptor::kImplicitRegisterParameterCount;
1172 i < instr->OperandCount(); i++) {
1174 UseFixed(instr->OperandAt(i),
1175 descriptor.GetRegisterParameter(
1176 i - LCallWithDescriptor::kImplicitRegisterParameterCount));
1177 ops.Add(op, zone());
1180 LCallWithDescriptor* result = new(zone()) LCallWithDescriptor(
1181 descriptor, ops, zone());
1182 return MarkAsCall(DefineFixed(result, eax), instr, CANNOT_DEOPTIMIZE_EAGERLY);
1186 LInstruction* LChunkBuilder::DoInvokeFunction(HInvokeFunction* instr) {
1187 LOperand* context = UseFixed(instr->context(), esi);
1188 LOperand* function = UseFixed(instr->function(), edi);
1189 LInvokeFunction* result = new(zone()) LInvokeFunction(context, function);
1190 return MarkAsCall(DefineFixed(result, eax), instr, CANNOT_DEOPTIMIZE_EAGERLY);
1194 LInstruction* LChunkBuilder::DoUnaryMathOperation(HUnaryMathOperation* instr) {
1195 switch (instr->op()) {
1196 case kMathFloor: return DoMathFloor(instr);
1197 case kMathRound: return DoMathRound(instr);
1198 case kMathFround: return DoMathFround(instr);
1199 case kMathAbs: return DoMathAbs(instr);
1200 case kMathLog: return DoMathLog(instr);
1201 case kMathExp: return DoMathExp(instr);
1202 case kMathSqrt: return DoMathSqrt(instr);
1203 case kMathPowHalf: return DoMathPowHalf(instr);
1204 case kMathClz32: return DoMathClz32(instr);
1212 LInstruction* LChunkBuilder::DoMathFloor(HUnaryMathOperation* instr) {
1213 LOperand* input = UseRegisterAtStart(instr->value());
1214 LMathFloor* result = new(zone()) LMathFloor(input);
1215 return AssignEnvironment(DefineAsRegister(result));
1219 LInstruction* LChunkBuilder::DoMathRound(HUnaryMathOperation* instr) {
1220 LOperand* input = UseRegisterAtStart(instr->value());
1221 LInstruction* result = DefineAsRegister(new (zone()) LMathRound(input));
1222 return AssignEnvironment(result);
1226 LInstruction* LChunkBuilder::DoMathFround(HUnaryMathOperation* instr) {
1227 LOperand* input = UseRegister(instr->value());
1228 LMathFround* result = new (zone()) LMathFround(input);
1229 return DefineSameAsFirst(result);
1233 LInstruction* LChunkBuilder::DoMathAbs(HUnaryMathOperation* instr) {
1234 LOperand* context = UseAny(instr->context()); // Deferred use.
1235 LOperand* input = UseRegisterAtStart(instr->value());
1236 LInstruction* result =
1237 DefineSameAsFirst(new(zone()) LMathAbs(context, input));
1238 Representation r = instr->value()->representation();
1239 if (!r.IsDouble() && !r.IsSmiOrInteger32()) result = AssignPointerMap(result);
1240 if (!r.IsDouble()) result = AssignEnvironment(result);
1245 LInstruction* LChunkBuilder::DoMathLog(HUnaryMathOperation* instr) {
1246 DCHECK(instr->representation().IsDouble());
1247 DCHECK(instr->value()->representation().IsDouble());
1248 LOperand* input = UseRegisterAtStart(instr->value());
1249 return MarkAsCall(DefineSameAsFirst(new(zone()) LMathLog(input)), instr);
1253 LInstruction* LChunkBuilder::DoMathClz32(HUnaryMathOperation* instr) {
1254 LOperand* input = UseRegisterAtStart(instr->value());
1255 LMathClz32* result = new(zone()) LMathClz32(input);
1256 return DefineAsRegister(result);
1260 LInstruction* LChunkBuilder::DoMathExp(HUnaryMathOperation* instr) {
1261 DCHECK(instr->representation().IsDouble());
1262 DCHECK(instr->value()->representation().IsDouble());
1263 LOperand* value = UseRegisterAtStart(instr->value());
1264 LOperand* temp1 = FixedTemp(ecx);
1265 LOperand* temp2 = FixedTemp(edx);
1266 LMathExp* result = new(zone()) LMathExp(value, temp1, temp2);
1267 return MarkAsCall(DefineSameAsFirst(result), instr);
1271 LInstruction* LChunkBuilder::DoMathSqrt(HUnaryMathOperation* instr) {
1272 LOperand* input = UseRegisterAtStart(instr->value());
1273 LOperand* temp1 = FixedTemp(ecx);
1274 LOperand* temp2 = FixedTemp(edx);
1275 LMathSqrt* result = new(zone()) LMathSqrt(input, temp1, temp2);
1276 return MarkAsCall(DefineSameAsFirst(result), instr);
1280 LInstruction* LChunkBuilder::DoMathPowHalf(HUnaryMathOperation* instr) {
1281 LOperand* input = UseRegisterAtStart(instr->value());
1282 LMathPowHalf* result = new (zone()) LMathPowHalf(input);
1283 return DefineSameAsFirst(result);
1287 LInstruction* LChunkBuilder::DoCallNew(HCallNew* instr) {
1288 LOperand* context = UseFixed(instr->context(), esi);
1289 LOperand* constructor = UseFixed(instr->constructor(), edi);
1290 LCallNew* result = new(zone()) LCallNew(context, constructor);
1291 return MarkAsCall(DefineFixed(result, eax), instr);
1295 LInstruction* LChunkBuilder::DoCallNewArray(HCallNewArray* instr) {
1296 LOperand* context = UseFixed(instr->context(), esi);
1297 LOperand* constructor = UseFixed(instr->constructor(), edi);
1298 LCallNewArray* result = new(zone()) LCallNewArray(context, constructor);
1299 return MarkAsCall(DefineFixed(result, eax), instr);
1303 LInstruction* LChunkBuilder::DoCallFunction(HCallFunction* instr) {
1304 LOperand* context = UseFixed(instr->context(), esi);
1305 LOperand* function = UseFixed(instr->function(), edi);
1306 LOperand* slot = NULL;
1307 LOperand* vector = NULL;
1308 if (instr->HasVectorAndSlot()) {
1309 slot = FixedTemp(edx);
1310 vector = FixedTemp(ebx);
1313 LCallFunction* call =
1314 new (zone()) LCallFunction(context, function, slot, vector);
1315 return MarkAsCall(DefineFixed(call, eax), instr);
1319 LInstruction* LChunkBuilder::DoCallRuntime(HCallRuntime* instr) {
1320 LOperand* context = UseFixed(instr->context(), esi);
1321 return MarkAsCall(DefineFixed(new(zone()) LCallRuntime(context), eax), instr);
1325 LInstruction* LChunkBuilder::DoRor(HRor* instr) {
1326 return DoShift(Token::ROR, instr);
1330 LInstruction* LChunkBuilder::DoShr(HShr* instr) {
1331 return DoShift(Token::SHR, instr);
1335 LInstruction* LChunkBuilder::DoSar(HSar* instr) {
1336 return DoShift(Token::SAR, instr);
1340 LInstruction* LChunkBuilder::DoShl(HShl* instr) {
1341 return DoShift(Token::SHL, instr);
1345 LInstruction* LChunkBuilder::DoBitwise(HBitwise* instr) {
1346 if (instr->representation().IsSmiOrInteger32()) {
1347 DCHECK(instr->left()->representation().Equals(instr->representation()));
1348 DCHECK(instr->right()->representation().Equals(instr->representation()));
1349 DCHECK(instr->CheckFlag(HValue::kTruncatingToInt32));
1351 LOperand* left = UseRegisterAtStart(instr->BetterLeftOperand());
1352 LOperand* right = UseOrConstantAtStart(instr->BetterRightOperand());
1353 return DefineSameAsFirst(new(zone()) LBitI(left, right));
1355 return DoArithmeticT(instr->op(), instr);
1360 LInstruction* LChunkBuilder::DoDivByPowerOf2I(HDiv* instr) {
1361 DCHECK(instr->representation().IsSmiOrInteger32());
1362 DCHECK(instr->left()->representation().Equals(instr->representation()));
1363 DCHECK(instr->right()->representation().Equals(instr->representation()));
1364 LOperand* dividend = UseRegister(instr->left());
1365 int32_t divisor = instr->right()->GetInteger32Constant();
1366 LInstruction* result = DefineAsRegister(new(zone()) LDivByPowerOf2I(
1367 dividend, divisor));
1368 if ((instr->CheckFlag(HValue::kBailoutOnMinusZero) && divisor < 0) ||
1369 (instr->CheckFlag(HValue::kCanOverflow) && divisor == -1) ||
1370 (!instr->CheckFlag(HInstruction::kAllUsesTruncatingToInt32) &&
1371 divisor != 1 && divisor != -1)) {
1372 result = AssignEnvironment(result);
1378 LInstruction* LChunkBuilder::DoDivByConstI(HDiv* instr) {
1379 DCHECK(instr->representation().IsInteger32());
1380 DCHECK(instr->left()->representation().Equals(instr->representation()));
1381 DCHECK(instr->right()->representation().Equals(instr->representation()));
1382 LOperand* dividend = UseRegister(instr->left());
1383 int32_t divisor = instr->right()->GetInteger32Constant();
1384 LOperand* temp1 = FixedTemp(eax);
1385 LOperand* temp2 = FixedTemp(edx);
1386 LInstruction* result = DefineFixed(new(zone()) LDivByConstI(
1387 dividend, divisor, temp1, temp2), edx);
1389 (instr->CheckFlag(HValue::kBailoutOnMinusZero) && divisor < 0) ||
1390 !instr->CheckFlag(HInstruction::kAllUsesTruncatingToInt32)) {
1391 result = AssignEnvironment(result);
1397 LInstruction* LChunkBuilder::DoDivI(HDiv* instr) {
1398 DCHECK(instr->representation().IsSmiOrInteger32());
1399 DCHECK(instr->left()->representation().Equals(instr->representation()));
1400 DCHECK(instr->right()->representation().Equals(instr->representation()));
1401 LOperand* dividend = UseFixed(instr->left(), eax);
1402 LOperand* divisor = UseRegister(instr->right());
1403 LOperand* temp = FixedTemp(edx);
1404 LInstruction* result = DefineFixed(new(zone()) LDivI(
1405 dividend, divisor, temp), eax);
1406 if (instr->CheckFlag(HValue::kCanBeDivByZero) ||
1407 instr->CheckFlag(HValue::kBailoutOnMinusZero) ||
1408 instr->CheckFlag(HValue::kCanOverflow) ||
1409 !instr->CheckFlag(HValue::kAllUsesTruncatingToInt32)) {
1410 result = AssignEnvironment(result);
1416 LInstruction* LChunkBuilder::DoDiv(HDiv* instr) {
1417 if (instr->representation().IsSmiOrInteger32()) {
1418 if (instr->RightIsPowerOf2()) {
1419 return DoDivByPowerOf2I(instr);
1420 } else if (instr->right()->IsConstant()) {
1421 return DoDivByConstI(instr);
1423 return DoDivI(instr);
1425 } else if (instr->representation().IsDouble()) {
1426 return DoArithmeticD(Token::DIV, instr);
1428 return DoArithmeticT(Token::DIV, instr);
1433 LInstruction* LChunkBuilder::DoFlooringDivByPowerOf2I(HMathFloorOfDiv* instr) {
1434 LOperand* dividend = UseRegisterAtStart(instr->left());
1435 int32_t divisor = instr->right()->GetInteger32Constant();
1436 LInstruction* result = DefineSameAsFirst(new(zone()) LFlooringDivByPowerOf2I(
1437 dividend, divisor));
1438 if ((instr->CheckFlag(HValue::kBailoutOnMinusZero) && divisor < 0) ||
1439 (instr->CheckFlag(HValue::kLeftCanBeMinInt) && divisor == -1)) {
1440 result = AssignEnvironment(result);
1446 LInstruction* LChunkBuilder::DoFlooringDivByConstI(HMathFloorOfDiv* instr) {
1447 DCHECK(instr->representation().IsInteger32());
1448 DCHECK(instr->left()->representation().Equals(instr->representation()));
1449 DCHECK(instr->right()->representation().Equals(instr->representation()));
1450 LOperand* dividend = UseRegister(instr->left());
1451 int32_t divisor = instr->right()->GetInteger32Constant();
1452 LOperand* temp1 = FixedTemp(eax);
1453 LOperand* temp2 = FixedTemp(edx);
1455 ((divisor > 0 && !instr->CheckFlag(HValue::kLeftCanBeNegative)) ||
1456 (divisor < 0 && !instr->CheckFlag(HValue::kLeftCanBePositive))) ?
1457 NULL : TempRegister();
1458 LInstruction* result =
1459 DefineFixed(new(zone()) LFlooringDivByConstI(dividend,
1466 (instr->CheckFlag(HValue::kBailoutOnMinusZero) && divisor < 0)) {
1467 result = AssignEnvironment(result);
1473 LInstruction* LChunkBuilder::DoFlooringDivI(HMathFloorOfDiv* instr) {
1474 DCHECK(instr->representation().IsSmiOrInteger32());
1475 DCHECK(instr->left()->representation().Equals(instr->representation()));
1476 DCHECK(instr->right()->representation().Equals(instr->representation()));
1477 LOperand* dividend = UseFixed(instr->left(), eax);
1478 LOperand* divisor = UseRegister(instr->right());
1479 LOperand* temp = FixedTemp(edx);
1480 LInstruction* result = DefineFixed(new(zone()) LFlooringDivI(
1481 dividend, divisor, temp), eax);
1482 if (instr->CheckFlag(HValue::kCanBeDivByZero) ||
1483 instr->CheckFlag(HValue::kBailoutOnMinusZero) ||
1484 instr->CheckFlag(HValue::kCanOverflow)) {
1485 result = AssignEnvironment(result);
1491 LInstruction* LChunkBuilder::DoMathFloorOfDiv(HMathFloorOfDiv* instr) {
1492 if (instr->RightIsPowerOf2()) {
1493 return DoFlooringDivByPowerOf2I(instr);
1494 } else if (instr->right()->IsConstant()) {
1495 return DoFlooringDivByConstI(instr);
1497 return DoFlooringDivI(instr);
1502 LInstruction* LChunkBuilder::DoModByPowerOf2I(HMod* instr) {
1503 DCHECK(instr->representation().IsSmiOrInteger32());
1504 DCHECK(instr->left()->representation().Equals(instr->representation()));
1505 DCHECK(instr->right()->representation().Equals(instr->representation()));
1506 LOperand* dividend = UseRegisterAtStart(instr->left());
1507 int32_t divisor = instr->right()->GetInteger32Constant();
1508 LInstruction* result = DefineSameAsFirst(new(zone()) LModByPowerOf2I(
1509 dividend, divisor));
1510 if (instr->CheckFlag(HValue::kLeftCanBeNegative) &&
1511 instr->CheckFlag(HValue::kBailoutOnMinusZero)) {
1512 result = AssignEnvironment(result);
1518 LInstruction* LChunkBuilder::DoModByConstI(HMod* instr) {
1519 DCHECK(instr->representation().IsSmiOrInteger32());
1520 DCHECK(instr->left()->representation().Equals(instr->representation()));
1521 DCHECK(instr->right()->representation().Equals(instr->representation()));
1522 LOperand* dividend = UseRegister(instr->left());
1523 int32_t divisor = instr->right()->GetInteger32Constant();
1524 LOperand* temp1 = FixedTemp(eax);
1525 LOperand* temp2 = FixedTemp(edx);
1526 LInstruction* result = DefineFixed(new(zone()) LModByConstI(
1527 dividend, divisor, temp1, temp2), eax);
1528 if (divisor == 0 || instr->CheckFlag(HValue::kBailoutOnMinusZero)) {
1529 result = AssignEnvironment(result);
1535 LInstruction* LChunkBuilder::DoModI(HMod* instr) {
1536 DCHECK(instr->representation().IsSmiOrInteger32());
1537 DCHECK(instr->left()->representation().Equals(instr->representation()));
1538 DCHECK(instr->right()->representation().Equals(instr->representation()));
1539 LOperand* dividend = UseFixed(instr->left(), eax);
1540 LOperand* divisor = UseRegister(instr->right());
1541 LOperand* temp = FixedTemp(edx);
1542 LInstruction* result = DefineFixed(new(zone()) LModI(
1543 dividend, divisor, temp), edx);
1544 if (instr->CheckFlag(HValue::kCanBeDivByZero) ||
1545 instr->CheckFlag(HValue::kBailoutOnMinusZero)) {
1546 result = AssignEnvironment(result);
1552 LInstruction* LChunkBuilder::DoMod(HMod* instr) {
1553 if (instr->representation().IsSmiOrInteger32()) {
1554 if (instr->RightIsPowerOf2()) {
1555 return DoModByPowerOf2I(instr);
1556 } else if (instr->right()->IsConstant()) {
1557 return DoModByConstI(instr);
1559 return DoModI(instr);
1561 } else if (instr->representation().IsDouble()) {
1562 return DoArithmeticD(Token::MOD, instr);
1564 return DoArithmeticT(Token::MOD, instr);
1569 LInstruction* LChunkBuilder::DoMul(HMul* instr) {
1570 if (instr->representation().IsSmiOrInteger32()) {
1571 DCHECK(instr->left()->representation().Equals(instr->representation()));
1572 DCHECK(instr->right()->representation().Equals(instr->representation()));
1573 LOperand* left = UseRegisterAtStart(instr->BetterLeftOperand());
1574 LOperand* right = UseOrConstant(instr->BetterRightOperand());
1575 LOperand* temp = NULL;
1576 if (instr->CheckFlag(HValue::kBailoutOnMinusZero)) {
1577 temp = TempRegister();
1579 LMulI* mul = new(zone()) LMulI(left, right, temp);
1580 if (instr->CheckFlag(HValue::kCanOverflow) ||
1581 instr->CheckFlag(HValue::kBailoutOnMinusZero)) {
1582 AssignEnvironment(mul);
1584 return DefineSameAsFirst(mul);
1585 } else if (instr->representation().IsDouble()) {
1586 return DoArithmeticD(Token::MUL, instr);
1588 return DoArithmeticT(Token::MUL, instr);
1593 LInstruction* LChunkBuilder::DoSub(HSub* instr) {
1594 if (instr->representation().IsSmiOrInteger32()) {
1595 DCHECK(instr->left()->representation().Equals(instr->representation()));
1596 DCHECK(instr->right()->representation().Equals(instr->representation()));
1597 LOperand* left = UseRegisterAtStart(instr->left());
1598 LOperand* right = UseOrConstantAtStart(instr->right());
1599 LSubI* sub = new(zone()) LSubI(left, right);
1600 LInstruction* result = DefineSameAsFirst(sub);
1601 if (instr->CheckFlag(HValue::kCanOverflow)) {
1602 result = AssignEnvironment(result);
1605 } else if (instr->representation().IsDouble()) {
1606 return DoArithmeticD(Token::SUB, instr);
1608 return DoArithmeticT(Token::SUB, instr);
1613 LInstruction* LChunkBuilder::DoAdd(HAdd* instr) {
1614 if (instr->representation().IsSmiOrInteger32()) {
1615 DCHECK(instr->left()->representation().Equals(instr->representation()));
1616 DCHECK(instr->right()->representation().Equals(instr->representation()));
1617 // Check to see if it would be advantageous to use an lea instruction rather
1618 // than an add. This is the case when no overflow check is needed and there
1619 // are multiple uses of the add's inputs, so using a 3-register add will
1620 // preserve all input values for later uses.
1621 bool use_lea = LAddI::UseLea(instr);
1622 LOperand* left = UseRegisterAtStart(instr->BetterLeftOperand());
1623 HValue* right_candidate = instr->BetterRightOperand();
1624 LOperand* right = use_lea
1625 ? UseRegisterOrConstantAtStart(right_candidate)
1626 : UseOrConstantAtStart(right_candidate);
1627 LAddI* add = new(zone()) LAddI(left, right);
1628 bool can_overflow = instr->CheckFlag(HValue::kCanOverflow);
1629 LInstruction* result = use_lea
1630 ? DefineAsRegister(add)
1631 : DefineSameAsFirst(add);
1633 result = AssignEnvironment(result);
1636 } else if (instr->representation().IsDouble()) {
1637 return DoArithmeticD(Token::ADD, instr);
1638 } else if (instr->representation().IsExternal()) {
1639 DCHECK(instr->IsConsistentExternalRepresentation());
1640 DCHECK(!instr->CheckFlag(HValue::kCanOverflow));
1641 bool use_lea = LAddI::UseLea(instr);
1642 LOperand* left = UseRegisterAtStart(instr->left());
1643 HValue* right_candidate = instr->right();
1644 LOperand* right = use_lea
1645 ? UseRegisterOrConstantAtStart(right_candidate)
1646 : UseOrConstantAtStart(right_candidate);
1647 LAddI* add = new(zone()) LAddI(left, right);
1648 LInstruction* result = use_lea
1649 ? DefineAsRegister(add)
1650 : DefineSameAsFirst(add);
1653 return DoArithmeticT(Token::ADD, instr);
1658 LInstruction* LChunkBuilder::DoMathMinMax(HMathMinMax* instr) {
1659 LOperand* left = NULL;
1660 LOperand* right = NULL;
1661 LOperand* scratch = TempRegister();
1663 if (instr->representation().IsSmiOrInteger32()) {
1664 DCHECK(instr->left()->representation().Equals(instr->representation()));
1665 DCHECK(instr->right()->representation().Equals(instr->representation()));
1666 left = UseRegisterAtStart(instr->BetterLeftOperand());
1667 right = UseOrConstantAtStart(instr->BetterRightOperand());
1669 DCHECK(instr->representation().IsDouble());
1670 DCHECK(instr->left()->representation().IsDouble());
1671 DCHECK(instr->right()->representation().IsDouble());
1672 left = UseRegisterAtStart(instr->left());
1673 right = UseRegisterAtStart(instr->right());
1675 LMathMinMax* minmax = new (zone()) LMathMinMax(left, right, scratch);
1676 return DefineSameAsFirst(minmax);
1680 LInstruction* LChunkBuilder::DoPower(HPower* instr) {
1681 // Unlike ia32, we don't have a MathPowStub and directly call c function.
1682 DCHECK(instr->representation().IsDouble());
1683 DCHECK(instr->left()->representation().IsDouble());
1684 LOperand* left = UseRegisterAtStart(instr->left());
1685 LOperand* right = UseRegisterAtStart(instr->right());
1686 LPower* result = new (zone()) LPower(left, right);
1687 return MarkAsCall(DefineSameAsFirst(result), instr);
1691 LInstruction* LChunkBuilder::DoCompareGeneric(HCompareGeneric* instr) {
1692 DCHECK(instr->left()->representation().IsSmiOrTagged());
1693 DCHECK(instr->right()->representation().IsSmiOrTagged());
1694 LOperand* context = UseFixed(instr->context(), esi);
1695 LOperand* left = UseFixed(instr->left(), edx);
1696 LOperand* right = UseFixed(instr->right(), eax);
1697 LCmpT* result = new(zone()) LCmpT(context, left, right);
1698 return MarkAsCall(DefineFixed(result, eax), instr);
1702 LInstruction* LChunkBuilder::DoCompareNumericAndBranch(
1703 HCompareNumericAndBranch* instr) {
1704 Representation r = instr->representation();
1705 if (r.IsSmiOrInteger32()) {
1706 DCHECK(instr->left()->representation().Equals(r));
1707 DCHECK(instr->right()->representation().Equals(r));
1708 LOperand* left = UseRegisterOrConstantAtStart(instr->left());
1709 LOperand* right = UseOrConstantAtStart(instr->right());
1710 return new(zone()) LCompareNumericAndBranch(left, right);
1712 DCHECK(r.IsDouble());
1713 DCHECK(instr->left()->representation().IsDouble());
1714 DCHECK(instr->right()->representation().IsDouble());
1717 if (CanBeImmediateConstant(instr->left()) &&
1718 CanBeImmediateConstant(instr->right())) {
1719 // The code generator requires either both inputs to be constant
1720 // operands, or neither.
1721 left = UseConstant(instr->left());
1722 right = UseConstant(instr->right());
1724 left = UseRegisterAtStart(instr->left());
1725 right = UseRegisterAtStart(instr->right());
1727 return new(zone()) LCompareNumericAndBranch(left, right);
1732 LInstruction* LChunkBuilder::DoCompareObjectEqAndBranch(
1733 HCompareObjectEqAndBranch* instr) {
1734 LOperand* left = UseRegisterAtStart(instr->left());
1735 LOperand* right = UseOrConstantAtStart(instr->right());
1736 return new(zone()) LCmpObjectEqAndBranch(left, right);
1740 LInstruction* LChunkBuilder::DoCompareHoleAndBranch(
1741 HCompareHoleAndBranch* instr) {
1742 LOperand* value = UseRegisterAtStart(instr->value());
1743 return new (zone()) LCmpHoleAndBranch(value);
1747 LInstruction* LChunkBuilder::DoCompareMinusZeroAndBranch(
1748 HCompareMinusZeroAndBranch* instr) {
1749 LOperand* value = UseRegisterAtStart(instr->value());
1750 return new (zone()) LCompareMinusZeroAndBranch(value);
1754 LInstruction* LChunkBuilder::DoIsObjectAndBranch(HIsObjectAndBranch* instr) {
1755 DCHECK(instr->value()->representation().IsSmiOrTagged());
1756 LOperand* temp = TempRegister();
1757 return new(zone()) LIsObjectAndBranch(UseRegister(instr->value()), temp);
1761 LInstruction* LChunkBuilder::DoIsStringAndBranch(HIsStringAndBranch* instr) {
1762 DCHECK(instr->value()->representation().IsTagged());
1763 LOperand* temp = TempRegister();
1764 return new(zone()) LIsStringAndBranch(UseRegister(instr->value()), temp);
1768 LInstruction* LChunkBuilder::DoIsSmiAndBranch(HIsSmiAndBranch* instr) {
1769 DCHECK(instr->value()->representation().IsTagged());
1770 return new(zone()) LIsSmiAndBranch(Use(instr->value()));
1774 LInstruction* LChunkBuilder::DoIsUndetectableAndBranch(
1775 HIsUndetectableAndBranch* instr) {
1776 DCHECK(instr->value()->representation().IsTagged());
1777 return new(zone()) LIsUndetectableAndBranch(
1778 UseRegisterAtStart(instr->value()), TempRegister());
1782 LInstruction* LChunkBuilder::DoStringCompareAndBranch(
1783 HStringCompareAndBranch* instr) {
1784 DCHECK(instr->left()->representation().IsTagged());
1785 DCHECK(instr->right()->representation().IsTagged());
1786 LOperand* context = UseFixed(instr->context(), esi);
1787 LOperand* left = UseFixed(instr->left(), edx);
1788 LOperand* right = UseFixed(instr->right(), eax);
1790 LStringCompareAndBranch* result = new(zone())
1791 LStringCompareAndBranch(context, left, right);
1793 return MarkAsCall(result, instr);
1797 LInstruction* LChunkBuilder::DoHasInstanceTypeAndBranch(
1798 HHasInstanceTypeAndBranch* instr) {
1799 DCHECK(instr->value()->representation().IsTagged());
1800 return new(zone()) LHasInstanceTypeAndBranch(
1801 UseRegisterAtStart(instr->value()),
1806 LInstruction* LChunkBuilder::DoGetCachedArrayIndex(
1807 HGetCachedArrayIndex* instr) {
1808 DCHECK(instr->value()->representation().IsTagged());
1809 LOperand* value = UseRegisterAtStart(instr->value());
1811 return DefineAsRegister(new(zone()) LGetCachedArrayIndex(value));
1815 LInstruction* LChunkBuilder::DoHasCachedArrayIndexAndBranch(
1816 HHasCachedArrayIndexAndBranch* instr) {
1817 DCHECK(instr->value()->representation().IsTagged());
1818 return new(zone()) LHasCachedArrayIndexAndBranch(
1819 UseRegisterAtStart(instr->value()));
1823 LInstruction* LChunkBuilder::DoClassOfTestAndBranch(
1824 HClassOfTestAndBranch* instr) {
1825 DCHECK(instr->value()->representation().IsTagged());
1826 return new(zone()) LClassOfTestAndBranch(UseRegister(instr->value()),
1832 LInstruction* LChunkBuilder::DoMapEnumLength(HMapEnumLength* instr) {
1833 LOperand* map = UseRegisterAtStart(instr->value());
1834 return DefineAsRegister(new(zone()) LMapEnumLength(map));
1838 LInstruction* LChunkBuilder::DoDateField(HDateField* instr) {
1839 LOperand* date = UseFixed(instr->value(), eax);
1840 LDateField* result =
1841 new(zone()) LDateField(date, FixedTemp(ecx), instr->index());
1842 return MarkAsCall(DefineFixed(result, eax), instr, CANNOT_DEOPTIMIZE_EAGERLY);
1846 LInstruction* LChunkBuilder::DoSeqStringGetChar(HSeqStringGetChar* instr) {
1847 LOperand* string = UseRegisterAtStart(instr->string());
1848 LOperand* index = UseRegisterOrConstantAtStart(instr->index());
1849 return DefineAsRegister(new(zone()) LSeqStringGetChar(string, index));
1853 LOperand* LChunkBuilder::GetSeqStringSetCharOperand(HSeqStringSetChar* instr) {
1854 if (instr->encoding() == String::ONE_BYTE_ENCODING) {
1855 if (FLAG_debug_code) {
1856 return UseFixed(instr->value(), eax);
1858 return UseFixedOrConstant(instr->value(), eax);
1861 if (FLAG_debug_code) {
1862 return UseRegisterAtStart(instr->value());
1864 return UseRegisterOrConstantAtStart(instr->value());
1870 LInstruction* LChunkBuilder::DoSeqStringSetChar(HSeqStringSetChar* instr) {
1871 LOperand* string = UseRegisterAtStart(instr->string());
1872 LOperand* index = FLAG_debug_code
1873 ? UseRegisterAtStart(instr->index())
1874 : UseRegisterOrConstantAtStart(instr->index());
1875 LOperand* value = GetSeqStringSetCharOperand(instr);
1876 LOperand* context = FLAG_debug_code ? UseFixed(instr->context(), esi) : NULL;
1877 LInstruction* result = new(zone()) LSeqStringSetChar(context, string,
1879 if (FLAG_debug_code) {
1880 result = MarkAsCall(result, instr);
1886 LInstruction* LChunkBuilder::DoBoundsCheck(HBoundsCheck* instr) {
1887 if (!FLAG_debug_code && instr->skip_check()) return NULL;
1888 LOperand* index = UseRegisterOrConstantAtStart(instr->index());
1889 LOperand* length = !index->IsConstantOperand()
1890 ? UseOrConstantAtStart(instr->length())
1891 : UseAtStart(instr->length());
1892 LInstruction* result = new(zone()) LBoundsCheck(index, length);
1893 if (!FLAG_debug_code || !instr->skip_check()) {
1894 result = AssignEnvironment(result);
1900 LInstruction* LChunkBuilder::DoBoundsCheckBaseIndexInformation(
1901 HBoundsCheckBaseIndexInformation* instr) {
1907 LInstruction* LChunkBuilder::DoAbnormalExit(HAbnormalExit* instr) {
1908 // The control instruction marking the end of a block that completed
1909 // abruptly (e.g., threw an exception). There is nothing specific to do.
1914 LInstruction* LChunkBuilder::DoUseConst(HUseConst* instr) {
1919 LInstruction* LChunkBuilder::DoForceRepresentation(HForceRepresentation* bad) {
1920 // All HForceRepresentation instructions should be eliminated in the
1921 // representation change phase of Hydrogen.
1927 LInstruction* LChunkBuilder::DoChange(HChange* instr) {
1928 Representation from = instr->from();
1929 Representation to = instr->to();
1930 HValue* val = instr->value();
1932 if (to.IsTagged()) {
1933 LOperand* value = UseRegister(val);
1934 return DefineSameAsFirst(new(zone()) LDummyUse(value));
1936 from = Representation::Tagged();
1938 if (from.IsTagged()) {
1939 if (to.IsDouble()) {
1940 LOperand* value = UseRegister(val);
1941 LOperand* temp = TempRegister();
1942 LInstruction* result =
1943 DefineAsRegister(new(zone()) LNumberUntagD(value, temp));
1944 if (!val->representation().IsSmi()) result = AssignEnvironment(result);
1946 } else if (to.IsSmi()) {
1947 LOperand* value = UseRegister(val);
1948 if (val->type().IsSmi()) {
1949 return DefineSameAsFirst(new(zone()) LDummyUse(value));
1951 return AssignEnvironment(DefineSameAsFirst(new(zone()) LCheckSmi(value)));
1953 DCHECK(to.IsInteger32());
1954 if (val->type().IsSmi() || val->representation().IsSmi()) {
1955 LOperand* value = UseRegister(val);
1956 return DefineSameAsFirst(new(zone()) LSmiUntag(value, false));
1958 LOperand* value = UseRegister(val);
1959 LInstruction* result = DefineSameAsFirst(new(zone()) LTaggedToI(value));
1960 if (!val->representation().IsSmi()) result = AssignEnvironment(result);
1964 } else if (from.IsDouble()) {
1965 if (to.IsTagged()) {
1966 info()->MarkAsDeferredCalling();
1967 LOperand* value = UseRegisterAtStart(val);
1968 LOperand* temp = FLAG_inline_new ? TempRegister() : NULL;
1969 LUnallocated* result_temp = TempRegister();
1970 LNumberTagD* result = new(zone()) LNumberTagD(value, temp);
1971 return AssignPointerMap(Define(result, result_temp));
1972 } else if (to.IsSmi()) {
1973 LOperand* value = UseRegister(val);
1974 return AssignEnvironment(
1975 DefineAsRegister(new(zone()) LDoubleToSmi(value)));
1977 DCHECK(to.IsInteger32());
1978 bool truncating = instr->CanTruncateToInt32();
1979 LOperand* value = UseRegister(val);
1980 LInstruction* result = DefineAsRegister(new(zone()) LDoubleToI(value));
1981 if (!truncating) result = AssignEnvironment(result);
1984 } else if (from.IsInteger32()) {
1985 info()->MarkAsDeferredCalling();
1986 if (to.IsTagged()) {
1987 if (!instr->CheckFlag(HValue::kCanOverflow)) {
1988 LOperand* value = UseRegister(val);
1989 return DefineSameAsFirst(new(zone()) LSmiTag(value));
1990 } else if (val->CheckFlag(HInstruction::kUint32)) {
1991 LOperand* value = UseRegister(val);
1992 LOperand* temp = TempRegister();
1993 LNumberTagU* result = new(zone()) LNumberTagU(value, temp);
1994 return AssignPointerMap(DefineSameAsFirst(result));
1996 LOperand* value = UseRegister(val);
1997 LOperand* temp = TempRegister();
1998 LNumberTagI* result = new(zone()) LNumberTagI(value, temp);
1999 return AssignPointerMap(DefineSameAsFirst(result));
2001 } else if (to.IsSmi()) {
2002 LOperand* value = UseRegister(val);
2003 LInstruction* result = DefineSameAsFirst(new(zone()) LSmiTag(value));
2004 if (instr->CheckFlag(HValue::kCanOverflow)) {
2005 result = AssignEnvironment(result);
2009 DCHECK(to.IsDouble());
2010 if (val->CheckFlag(HInstruction::kUint32)) {
2011 return DefineAsRegister(new(zone()) LUint32ToDouble(UseRegister(val)));
2013 return DefineAsRegister(new(zone()) LInteger32ToDouble(Use(val)));
2022 LInstruction* LChunkBuilder::DoCheckHeapObject(HCheckHeapObject* instr) {
2023 LOperand* value = UseAtStart(instr->value());
2024 LInstruction* result = new(zone()) LCheckNonSmi(value);
2025 if (!instr->value()->type().IsHeapObject()) {
2026 result = AssignEnvironment(result);
2032 LInstruction* LChunkBuilder::DoCheckSmi(HCheckSmi* instr) {
2033 LOperand* value = UseRegisterAtStart(instr->value());
2034 return AssignEnvironment(new(zone()) LCheckSmi(value));
2038 LInstruction* LChunkBuilder::DoCheckArrayBufferNotNeutered(
2039 HCheckArrayBufferNotNeutered* instr) {
2040 LOperand* view = UseRegisterAtStart(instr->value());
2041 LOperand* scratch = TempRegister();
2042 LCheckArrayBufferNotNeutered* result =
2043 new (zone()) LCheckArrayBufferNotNeutered(view, scratch);
2044 return AssignEnvironment(result);
2048 LInstruction* LChunkBuilder::DoCheckInstanceType(HCheckInstanceType* instr) {
2049 LOperand* value = UseRegisterAtStart(instr->value());
2050 LOperand* temp = TempRegister();
2051 LCheckInstanceType* result = new(zone()) LCheckInstanceType(value, temp);
2052 return AssignEnvironment(result);
2056 LInstruction* LChunkBuilder::DoCheckValue(HCheckValue* instr) {
2057 // If the object is in new space, we'll emit a global cell compare and so
2058 // want the value in a register. If the object gets promoted before we
2059 // emit code, we will still get the register but will do an immediate
2060 // compare instead of the cell compare. This is safe.
2061 LOperand* value = instr->object_in_new_space()
2062 ? UseRegisterAtStart(instr->value()) : UseAtStart(instr->value());
2063 return AssignEnvironment(new(zone()) LCheckValue(value));
2067 LInstruction* LChunkBuilder::DoCheckMaps(HCheckMaps* instr) {
2068 if (instr->IsStabilityCheck()) return new(zone()) LCheckMaps;
2069 LOperand* value = UseRegisterAtStart(instr->value());
2070 LInstruction* result = AssignEnvironment(new(zone()) LCheckMaps(value));
2071 if (instr->HasMigrationTarget()) {
2072 info()->MarkAsDeferredCalling();
2073 result = AssignPointerMap(result);
2079 LInstruction* LChunkBuilder::DoClampToUint8(HClampToUint8* instr) {
2080 HValue* value = instr->value();
2081 Representation input_rep = value->representation();
2082 if (input_rep.IsDouble()) {
2083 LOperand* reg = UseRegister(value);
2084 return DefineFixed(new (zone()) LClampDToUint8(reg), eax);
2085 } else if (input_rep.IsInteger32()) {
2086 LOperand* reg = UseFixed(value, eax);
2087 return DefineFixed(new(zone()) LClampIToUint8(reg), eax);
2089 DCHECK(input_rep.IsSmiOrTagged());
2090 LOperand* value = UseRegister(instr->value());
2091 LClampTToUint8NoSSE2* res =
2092 new(zone()) LClampTToUint8NoSSE2(value, TempRegister(),
2093 TempRegister(), TempRegister());
2094 return AssignEnvironment(DefineFixed(res, ecx));
2099 LInstruction* LChunkBuilder::DoDoubleBits(HDoubleBits* instr) {
2100 HValue* value = instr->value();
2101 DCHECK(value->representation().IsDouble());
2102 return DefineAsRegister(new(zone()) LDoubleBits(UseRegister(value)));
2106 LInstruction* LChunkBuilder::DoConstructDouble(HConstructDouble* instr) {
2107 LOperand* lo = UseRegister(instr->lo());
2108 LOperand* hi = UseRegister(instr->hi());
2109 return DefineAsRegister(new(zone()) LConstructDouble(hi, lo));
2113 LInstruction* LChunkBuilder::DoReturn(HReturn* instr) {
2114 LOperand* context = info()->IsStub() ? UseFixed(instr->context(), esi) : NULL;
2115 LOperand* parameter_count = UseRegisterOrConstant(instr->parameter_count());
2116 return new(zone()) LReturn(
2117 UseFixed(instr->value(), eax), context, parameter_count);
2121 LInstruction* LChunkBuilder::DoConstant(HConstant* instr) {
2122 Representation r = instr->representation();
2124 return DefineAsRegister(new(zone()) LConstantS);
2125 } else if (r.IsInteger32()) {
2126 return DefineAsRegister(new(zone()) LConstantI);
2127 } else if (r.IsDouble()) {
2128 return DefineAsRegister(new (zone()) LConstantD);
2129 } else if (r.IsExternal()) {
2130 return DefineAsRegister(new(zone()) LConstantE);
2131 } else if (r.IsTagged()) {
2132 return DefineAsRegister(new(zone()) LConstantT);
2140 LInstruction* LChunkBuilder::DoLoadGlobalGeneric(HLoadGlobalGeneric* instr) {
2141 LOperand* context = UseFixed(instr->context(), esi);
2142 LOperand* global_object =
2143 UseFixed(instr->global_object(), LoadDescriptor::ReceiverRegister());
2144 LOperand* vector = NULL;
2145 if (instr->HasVectorAndSlot()) {
2146 vector = FixedTemp(LoadWithVectorDescriptor::VectorRegister());
2149 LLoadGlobalGeneric* result =
2150 new(zone()) LLoadGlobalGeneric(context, global_object, vector);
2151 return MarkAsCall(DefineFixed(result, eax), instr);
2155 LInstruction* LChunkBuilder::DoLoadGlobalViaContext(
2156 HLoadGlobalViaContext* instr) {
2157 LOperand* context = UseFixed(instr->context(), esi);
2158 DCHECK(instr->slot_index() > 0);
2159 LLoadGlobalViaContext* result = new (zone()) LLoadGlobalViaContext(context);
2160 return MarkAsCall(DefineFixed(result, eax), instr);
2164 LInstruction* LChunkBuilder::DoLoadContextSlot(HLoadContextSlot* instr) {
2165 LOperand* context = UseRegisterAtStart(instr->value());
2166 LInstruction* result =
2167 DefineAsRegister(new(zone()) LLoadContextSlot(context));
2168 if (instr->RequiresHoleCheck() && instr->DeoptimizesOnHole()) {
2169 result = AssignEnvironment(result);
2175 LInstruction* LChunkBuilder::DoStoreContextSlot(HStoreContextSlot* instr) {
2178 LOperand* context = UseRegister(instr->context());
2179 if (instr->NeedsWriteBarrier()) {
2180 value = UseTempRegister(instr->value());
2181 temp = TempRegister();
2183 value = UseRegister(instr->value());
2186 LInstruction* result = new(zone()) LStoreContextSlot(context, value, temp);
2187 if (instr->RequiresHoleCheck() && instr->DeoptimizesOnHole()) {
2188 result = AssignEnvironment(result);
2194 LInstruction* LChunkBuilder::DoLoadNamedField(HLoadNamedField* instr) {
2195 LOperand* obj = (instr->access().IsExternalMemory() &&
2196 instr->access().offset() == 0)
2197 ? UseRegisterOrConstantAtStart(instr->object())
2198 : UseRegisterAtStart(instr->object());
2199 return DefineAsRegister(new(zone()) LLoadNamedField(obj));
2203 LInstruction* LChunkBuilder::DoLoadNamedGeneric(HLoadNamedGeneric* instr) {
2204 LOperand* context = UseFixed(instr->context(), esi);
2206 UseFixed(instr->object(), LoadDescriptor::ReceiverRegister());
2207 LOperand* vector = NULL;
2208 if (instr->HasVectorAndSlot()) {
2209 vector = FixedTemp(LoadWithVectorDescriptor::VectorRegister());
2211 LLoadNamedGeneric* result = new(zone()) LLoadNamedGeneric(
2212 context, object, vector);
2213 return MarkAsCall(DefineFixed(result, eax), instr);
2217 LInstruction* LChunkBuilder::DoLoadFunctionPrototype(
2218 HLoadFunctionPrototype* instr) {
2219 return AssignEnvironment(DefineAsRegister(
2220 new(zone()) LLoadFunctionPrototype(UseRegister(instr->function()),
2225 LInstruction* LChunkBuilder::DoLoadRoot(HLoadRoot* instr) {
2226 return DefineAsRegister(new(zone()) LLoadRoot);
2230 LInstruction* LChunkBuilder::DoLoadKeyed(HLoadKeyed* instr) {
2231 DCHECK(instr->key()->representation().IsSmiOrInteger32());
2232 ElementsKind elements_kind = instr->elements_kind();
2233 bool clobbers_key = ExternalArrayOpRequiresTemp(
2234 instr->key()->representation(), elements_kind);
2235 LOperand* key = clobbers_key
2236 ? UseTempRegister(instr->key())
2237 : UseRegisterOrConstantAtStart(instr->key());
2238 LInstruction* result = NULL;
2240 if (!instr->is_typed_elements()) {
2241 LOperand* obj = UseRegisterAtStart(instr->elements());
2242 result = DefineAsRegister(new(zone()) LLoadKeyed(obj, key));
2245 (instr->representation().IsInteger32() &&
2246 !(IsDoubleOrFloatElementsKind(instr->elements_kind()))) ||
2247 (instr->representation().IsDouble() &&
2248 (IsDoubleOrFloatElementsKind(instr->elements_kind()))));
2249 LOperand* backing_store = UseRegister(instr->elements());
2250 result = DefineAsRegister(new(zone()) LLoadKeyed(backing_store, key));
2253 bool needs_environment;
2254 if (instr->is_external() || instr->is_fixed_typed_array()) {
2255 // see LCodeGen::DoLoadKeyedExternalArray
2256 needs_environment = (elements_kind == EXTERNAL_UINT32_ELEMENTS ||
2257 elements_kind == UINT32_ELEMENTS) &&
2258 !instr->CheckFlag(HInstruction::kUint32);
2260 // see LCodeGen::DoLoadKeyedFixedDoubleArray and
2261 // LCodeGen::DoLoadKeyedFixedArray
2263 instr->RequiresHoleCheck() ||
2264 (instr->hole_mode() == CONVERT_HOLE_TO_UNDEFINED && info()->IsStub());
2267 if (needs_environment) {
2268 result = AssignEnvironment(result);
2274 LInstruction* LChunkBuilder::DoLoadKeyedGeneric(HLoadKeyedGeneric* instr) {
2275 LOperand* context = UseFixed(instr->context(), esi);
2277 UseFixed(instr->object(), LoadDescriptor::ReceiverRegister());
2278 LOperand* key = UseFixed(instr->key(), LoadDescriptor::NameRegister());
2279 LOperand* vector = NULL;
2280 if (instr->HasVectorAndSlot()) {
2281 vector = FixedTemp(LoadWithVectorDescriptor::VectorRegister());
2283 LLoadKeyedGeneric* result =
2284 new(zone()) LLoadKeyedGeneric(context, object, key, vector);
2285 return MarkAsCall(DefineFixed(result, eax), instr);
2289 LOperand* LChunkBuilder::GetStoreKeyedValueOperand(HStoreKeyed* instr) {
2290 ElementsKind elements_kind = instr->elements_kind();
2292 // Determine if we need a byte register in this case for the value.
2293 bool val_is_fixed_register =
2294 elements_kind == EXTERNAL_INT8_ELEMENTS ||
2295 elements_kind == EXTERNAL_UINT8_ELEMENTS ||
2296 elements_kind == EXTERNAL_UINT8_CLAMPED_ELEMENTS ||
2297 elements_kind == UINT8_ELEMENTS ||
2298 elements_kind == INT8_ELEMENTS ||
2299 elements_kind == UINT8_CLAMPED_ELEMENTS;
2300 if (val_is_fixed_register) {
2301 return UseFixed(instr->value(), eax);
2304 if (IsDoubleOrFloatElementsKind(elements_kind)) {
2305 return UseRegisterAtStart(instr->value());
2308 return UseRegister(instr->value());
2312 LInstruction* LChunkBuilder::DoStoreKeyed(HStoreKeyed* instr) {
2313 if (!instr->is_typed_elements()) {
2314 DCHECK(instr->elements()->representation().IsTagged());
2315 DCHECK(instr->key()->representation().IsInteger32() ||
2316 instr->key()->representation().IsSmi());
2318 if (instr->value()->representation().IsDouble()) {
2319 LOperand* object = UseRegisterAtStart(instr->elements());
2320 // For storing double hole, no fp register required.
2321 LOperand* val = instr->IsConstantHoleStore()
2323 : UseRegisterAtStart(instr->value());
2324 LOperand* key = UseRegisterOrConstantAtStart(instr->key());
2325 return new(zone()) LStoreKeyed(object, key, val);
2327 DCHECK(instr->value()->representation().IsSmiOrTagged());
2328 bool needs_write_barrier = instr->NeedsWriteBarrier();
2330 LOperand* obj = UseRegister(instr->elements());
2333 if (needs_write_barrier) {
2334 val = UseTempRegister(instr->value());
2335 key = UseTempRegister(instr->key());
2337 val = UseRegisterOrConstantAtStart(instr->value());
2338 key = UseRegisterOrConstantAtStart(instr->key());
2340 return new(zone()) LStoreKeyed(obj, key, val);
2344 ElementsKind elements_kind = instr->elements_kind();
2346 (instr->value()->representation().IsInteger32() &&
2347 !IsDoubleOrFloatElementsKind(elements_kind)) ||
2348 (instr->value()->representation().IsDouble() &&
2349 IsDoubleOrFloatElementsKind(elements_kind)));
2350 DCHECK(instr->elements()->representation().IsExternal());
2352 LOperand* backing_store = UseRegister(instr->elements());
2353 LOperand* val = GetStoreKeyedValueOperand(instr);
2354 bool clobbers_key = ExternalArrayOpRequiresTemp(
2355 instr->key()->representation(), elements_kind);
2356 LOperand* key = clobbers_key
2357 ? UseTempRegister(instr->key())
2358 : UseRegisterOrConstantAtStart(instr->key());
2359 return new(zone()) LStoreKeyed(backing_store, key, val);
2363 LInstruction* LChunkBuilder::DoStoreKeyedGeneric(HStoreKeyedGeneric* instr) {
2364 LOperand* context = UseFixed(instr->context(), esi);
2366 UseFixed(instr->object(), StoreDescriptor::ReceiverRegister());
2367 LOperand* key = UseFixed(instr->key(), StoreDescriptor::NameRegister());
2368 LOperand* value = UseFixed(instr->value(), StoreDescriptor::ValueRegister());
2370 DCHECK(instr->object()->representation().IsTagged());
2371 DCHECK(instr->key()->representation().IsTagged());
2372 DCHECK(instr->value()->representation().IsTagged());
2374 LOperand* slot = NULL;
2375 LOperand* vector = NULL;
2376 if (instr->HasVectorAndSlot()) {
2377 slot = FixedTemp(VectorStoreICDescriptor::SlotRegister());
2378 vector = FixedTemp(VectorStoreICDescriptor::VectorRegister());
2381 LStoreKeyedGeneric* result = new (zone())
2382 LStoreKeyedGeneric(context, object, key, value, slot, vector);
2383 return MarkAsCall(result, instr);
2387 LInstruction* LChunkBuilder::DoTransitionElementsKind(
2388 HTransitionElementsKind* instr) {
2389 if (IsSimpleMapChangeTransition(instr->from_kind(), instr->to_kind())) {
2390 LOperand* object = UseRegister(instr->object());
2391 LOperand* new_map_reg = TempRegister();
2392 LOperand* temp_reg = TempRegister();
2393 LTransitionElementsKind* result =
2394 new(zone()) LTransitionElementsKind(object, NULL,
2395 new_map_reg, temp_reg);
2398 LOperand* object = UseFixed(instr->object(), eax);
2399 LOperand* context = UseFixed(instr->context(), esi);
2400 LTransitionElementsKind* result =
2401 new(zone()) LTransitionElementsKind(object, context, NULL, NULL);
2402 return MarkAsCall(result, instr);
2407 LInstruction* LChunkBuilder::DoTrapAllocationMemento(
2408 HTrapAllocationMemento* instr) {
2409 LOperand* object = UseRegister(instr->object());
2410 LOperand* temp = TempRegister();
2411 LTrapAllocationMemento* result =
2412 new(zone()) LTrapAllocationMemento(object, temp);
2413 return AssignEnvironment(result);
2417 LInstruction* LChunkBuilder::DoMaybeGrowElements(HMaybeGrowElements* instr) {
2418 info()->MarkAsDeferredCalling();
2419 LOperand* context = UseFixed(instr->context(), esi);
2420 LOperand* object = Use(instr->object());
2421 LOperand* elements = Use(instr->elements());
2422 LOperand* key = UseRegisterOrConstant(instr->key());
2423 LOperand* current_capacity = UseRegisterOrConstant(instr->current_capacity());
2425 LMaybeGrowElements* result = new (zone())
2426 LMaybeGrowElements(context, object, elements, key, current_capacity);
2427 DefineFixed(result, eax);
2428 return AssignPointerMap(AssignEnvironment(result));
2432 LInstruction* LChunkBuilder::DoStoreNamedField(HStoreNamedField* instr) {
2433 bool is_in_object = instr->access().IsInobject();
2434 bool is_external_location = instr->access().IsExternalMemory() &&
2435 instr->access().offset() == 0;
2436 bool needs_write_barrier = instr->NeedsWriteBarrier();
2437 bool needs_write_barrier_for_map = instr->has_transition() &&
2438 instr->NeedsWriteBarrierForMap();
2441 if (needs_write_barrier) {
2443 ? UseRegister(instr->object())
2444 : UseTempRegister(instr->object());
2445 } else if (is_external_location) {
2446 DCHECK(!is_in_object);
2447 DCHECK(!needs_write_barrier);
2448 DCHECK(!needs_write_barrier_for_map);
2449 obj = UseRegisterOrConstant(instr->object());
2451 obj = needs_write_barrier_for_map
2452 ? UseRegister(instr->object())
2453 : UseRegisterAtStart(instr->object());
2456 bool can_be_constant = instr->value()->IsConstant() &&
2457 HConstant::cast(instr->value())->NotInNewSpace() &&
2458 !instr->field_representation().IsDouble();
2461 if (instr->field_representation().IsInteger8() ||
2462 instr->field_representation().IsUInteger8()) {
2463 // mov_b requires a byte register (i.e. any of eax, ebx, ecx, edx).
2464 // Just force the value to be in eax and we're safe here.
2465 val = UseFixed(instr->value(), eax);
2466 } else if (needs_write_barrier) {
2467 val = UseTempRegister(instr->value());
2468 } else if (can_be_constant) {
2469 val = UseRegisterOrConstant(instr->value());
2470 } else if (instr->field_representation().IsDouble()) {
2471 val = UseRegisterAtStart(instr->value());
2473 val = UseRegister(instr->value());
2476 // We only need a scratch register if we have a write barrier or we
2477 // have a store into the properties array (not in-object-property).
2478 LOperand* temp = (!is_in_object || needs_write_barrier ||
2479 needs_write_barrier_for_map) ? TempRegister() : NULL;
2481 // We need a temporary register for write barrier of the map field.
2482 LOperand* temp_map = needs_write_barrier_for_map ? TempRegister() : NULL;
2484 return new(zone()) LStoreNamedField(obj, val, temp, temp_map);
2488 LInstruction* LChunkBuilder::DoStoreNamedGeneric(HStoreNamedGeneric* instr) {
2489 LOperand* context = UseFixed(instr->context(), esi);
2491 UseFixed(instr->object(), StoreDescriptor::ReceiverRegister());
2492 LOperand* value = UseFixed(instr->value(), StoreDescriptor::ValueRegister());
2493 LOperand* slot = NULL;
2494 LOperand* vector = NULL;
2495 if (instr->HasVectorAndSlot()) {
2496 slot = FixedTemp(VectorStoreICDescriptor::SlotRegister());
2497 vector = FixedTemp(VectorStoreICDescriptor::VectorRegister());
2500 LStoreNamedGeneric* result =
2501 new (zone()) LStoreNamedGeneric(context, object, value, slot, vector);
2502 return MarkAsCall(result, instr);
2506 LInstruction* LChunkBuilder::DoStoreGlobalViaContext(
2507 HStoreGlobalViaContext* instr) {
2508 LOperand* context = UseFixed(instr->context(), esi);
2509 LOperand* value = UseFixed(instr->value(),
2510 StoreGlobalViaContextDescriptor::ValueRegister());
2511 DCHECK(instr->slot_index() > 0);
2513 LStoreGlobalViaContext* result =
2514 new (zone()) LStoreGlobalViaContext(context, value);
2515 return MarkAsCall(result, instr);
2519 LInstruction* LChunkBuilder::DoStringAdd(HStringAdd* instr) {
2520 LOperand* context = UseFixed(instr->context(), esi);
2521 LOperand* left = UseFixed(instr->left(), edx);
2522 LOperand* right = UseFixed(instr->right(), eax);
2523 LStringAdd* string_add = new(zone()) LStringAdd(context, left, right);
2524 return MarkAsCall(DefineFixed(string_add, eax), instr);
2528 LInstruction* LChunkBuilder::DoStringCharCodeAt(HStringCharCodeAt* instr) {
2529 LOperand* string = UseTempRegister(instr->string());
2530 LOperand* index = UseTempRegister(instr->index());
2531 LOperand* context = UseAny(instr->context());
2532 LStringCharCodeAt* result =
2533 new(zone()) LStringCharCodeAt(context, string, index);
2534 return AssignPointerMap(DefineAsRegister(result));
2538 LInstruction* LChunkBuilder::DoStringCharFromCode(HStringCharFromCode* instr) {
2539 LOperand* char_code = UseRegister(instr->value());
2540 LOperand* context = UseAny(instr->context());
2541 LStringCharFromCode* result =
2542 new(zone()) LStringCharFromCode(context, char_code);
2543 return AssignPointerMap(DefineAsRegister(result));
2547 LInstruction* LChunkBuilder::DoAllocate(HAllocate* instr) {
2548 info()->MarkAsDeferredCalling();
2549 LOperand* context = UseAny(instr->context());
2550 LOperand* size = instr->size()->IsConstant()
2551 ? UseConstant(instr->size())
2552 : UseTempRegister(instr->size());
2553 LOperand* temp = TempRegister();
2554 LAllocate* result = new(zone()) LAllocate(context, size, temp);
2555 return AssignPointerMap(DefineAsRegister(result));
2559 LInstruction* LChunkBuilder::DoRegExpLiteral(HRegExpLiteral* instr) {
2560 LOperand* context = UseFixed(instr->context(), esi);
2562 DefineFixed(new(zone()) LRegExpLiteral(context), eax), instr);
2566 LInstruction* LChunkBuilder::DoFunctionLiteral(HFunctionLiteral* instr) {
2567 LOperand* context = UseFixed(instr->context(), esi);
2569 DefineFixed(new(zone()) LFunctionLiteral(context), eax), instr);
2573 LInstruction* LChunkBuilder::DoOsrEntry(HOsrEntry* instr) {
2574 DCHECK(argument_count_ == 0);
2575 allocator_->MarkAsOsrEntry();
2576 current_block_->last_environment()->set_ast_id(instr->ast_id());
2577 return AssignEnvironment(new(zone()) LOsrEntry);
2581 LInstruction* LChunkBuilder::DoParameter(HParameter* instr) {
2582 LParameter* result = new(zone()) LParameter;
2583 if (instr->kind() == HParameter::STACK_PARAMETER) {
2584 int spill_index = chunk()->GetParameterStackSlot(instr->index());
2585 return DefineAsSpilled(result, spill_index);
2587 DCHECK(info()->IsStub());
2588 CallInterfaceDescriptor descriptor =
2589 info()->code_stub()->GetCallInterfaceDescriptor();
2590 int index = static_cast<int>(instr->index());
2591 Register reg = descriptor.GetRegisterParameter(index);
2592 return DefineFixed(result, reg);
2597 LInstruction* LChunkBuilder::DoUnknownOSRValue(HUnknownOSRValue* instr) {
2598 // Use an index that corresponds to the location in the unoptimized frame,
2599 // which the optimized frame will subsume.
2600 int env_index = instr->index();
2601 int spill_index = 0;
2602 if (instr->environment()->is_parameter_index(env_index)) {
2603 spill_index = chunk()->GetParameterStackSlot(env_index);
2605 spill_index = env_index - instr->environment()->first_local_index();
2606 if (spill_index > LUnallocated::kMaxFixedSlotIndex) {
2607 Retry(kNotEnoughSpillSlotsForOsr);
2610 if (spill_index == 0) {
2611 // The dynamic frame alignment state overwrites the first local.
2612 // The first local is saved at the end of the unoptimized frame.
2613 spill_index = graph()->osr()->UnoptimizedFrameSlots();
2616 return DefineAsSpilled(new(zone()) LUnknownOSRValue, spill_index);
2620 LInstruction* LChunkBuilder::DoCallStub(HCallStub* instr) {
2621 LOperand* context = UseFixed(instr->context(), esi);
2622 LCallStub* result = new(zone()) LCallStub(context);
2623 return MarkAsCall(DefineFixed(result, eax), instr);
2627 LInstruction* LChunkBuilder::DoArgumentsObject(HArgumentsObject* instr) {
2628 // There are no real uses of the arguments object.
2629 // arguments.length and element access are supported directly on
2630 // stack arguments, and any real arguments object use causes a bailout.
2631 // So this value is never used.
2636 LInstruction* LChunkBuilder::DoCapturedObject(HCapturedObject* instr) {
2637 instr->ReplayEnvironment(current_block_->last_environment());
2639 // There are no real uses of a captured object.
2644 LInstruction* LChunkBuilder::DoAccessArgumentsAt(HAccessArgumentsAt* instr) {
2645 info()->MarkAsRequiresFrame();
2646 LOperand* args = UseRegister(instr->arguments());
2649 if (instr->length()->IsConstant() && instr->index()->IsConstant()) {
2650 length = UseRegisterOrConstant(instr->length());
2651 index = UseOrConstant(instr->index());
2653 length = UseTempRegister(instr->length());
2654 index = Use(instr->index());
2656 return DefineAsRegister(new(zone()) LAccessArgumentsAt(args, length, index));
2660 LInstruction* LChunkBuilder::DoToFastProperties(HToFastProperties* instr) {
2661 LOperand* object = UseFixed(instr->value(), eax);
2662 LToFastProperties* result = new(zone()) LToFastProperties(object);
2663 return MarkAsCall(DefineFixed(result, eax), instr);
2667 LInstruction* LChunkBuilder::DoTypeof(HTypeof* instr) {
2668 LOperand* context = UseFixed(instr->context(), esi);
2669 LOperand* value = UseFixed(instr->value(), ebx);
2670 LTypeof* result = new(zone()) LTypeof(context, value);
2671 return MarkAsCall(DefineFixed(result, eax), instr);
2675 LInstruction* LChunkBuilder::DoTypeofIsAndBranch(HTypeofIsAndBranch* instr) {
2676 return new(zone()) LTypeofIsAndBranch(UseTempRegister(instr->value()));
2680 LInstruction* LChunkBuilder::DoIsConstructCallAndBranch(
2681 HIsConstructCallAndBranch* instr) {
2682 return new(zone()) LIsConstructCallAndBranch(TempRegister());
2686 LInstruction* LChunkBuilder::DoSimulate(HSimulate* instr) {
2687 instr->ReplayEnvironment(current_block_->last_environment());
2692 LInstruction* LChunkBuilder::DoStackCheck(HStackCheck* instr) {
2693 info()->MarkAsDeferredCalling();
2694 if (instr->is_function_entry()) {
2695 LOperand* context = UseFixed(instr->context(), esi);
2696 return MarkAsCall(new(zone()) LStackCheck(context), instr);
2698 DCHECK(instr->is_backwards_branch());
2699 LOperand* context = UseAny(instr->context());
2700 return AssignEnvironment(
2701 AssignPointerMap(new(zone()) LStackCheck(context)));
2706 LInstruction* LChunkBuilder::DoEnterInlined(HEnterInlined* instr) {
2707 HEnvironment* outer = current_block_->last_environment();
2708 outer->set_ast_id(instr->ReturnId());
2709 HConstant* undefined = graph()->GetConstantUndefined();
2710 HEnvironment* inner = outer->CopyForInlining(instr->closure(),
2711 instr->arguments_count(),
2714 instr->inlining_kind());
2715 // Only replay binding of arguments object if it wasn't removed from graph.
2716 if (instr->arguments_var() != NULL && instr->arguments_object()->IsLinked()) {
2717 inner->Bind(instr->arguments_var(), instr->arguments_object());
2719 inner->BindContext(instr->closure_context());
2720 inner->set_entry(instr);
2721 current_block_->UpdateEnvironment(inner);
2722 chunk_->AddInlinedFunction(instr->shared());
2727 LInstruction* LChunkBuilder::DoLeaveInlined(HLeaveInlined* instr) {
2728 LInstruction* pop = NULL;
2730 HEnvironment* env = current_block_->last_environment();
2732 if (env->entry()->arguments_pushed()) {
2733 int argument_count = env->arguments_environment()->parameter_count();
2734 pop = new(zone()) LDrop(argument_count);
2735 DCHECK(instr->argument_delta() == -argument_count);
2738 HEnvironment* outer = current_block_->last_environment()->
2739 DiscardInlined(false);
2740 current_block_->UpdateEnvironment(outer);
2745 LInstruction* LChunkBuilder::DoForInPrepareMap(HForInPrepareMap* instr) {
2746 LOperand* context = UseFixed(instr->context(), esi);
2747 LOperand* object = UseFixed(instr->enumerable(), eax);
2748 LForInPrepareMap* result = new(zone()) LForInPrepareMap(context, object);
2749 return MarkAsCall(DefineFixed(result, eax), instr, CAN_DEOPTIMIZE_EAGERLY);
2753 LInstruction* LChunkBuilder::DoForInCacheArray(HForInCacheArray* instr) {
2754 LOperand* map = UseRegister(instr->map());
2755 return AssignEnvironment(DefineAsRegister(
2756 new(zone()) LForInCacheArray(map)));
2760 LInstruction* LChunkBuilder::DoCheckMapValue(HCheckMapValue* instr) {
2761 LOperand* value = UseRegisterAtStart(instr->value());
2762 LOperand* map = UseRegisterAtStart(instr->map());
2763 return AssignEnvironment(new(zone()) LCheckMapValue(value, map));
2767 LInstruction* LChunkBuilder::DoLoadFieldByIndex(HLoadFieldByIndex* instr) {
2768 LOperand* object = UseRegister(instr->object());
2769 LOperand* index = UseTempRegister(instr->index());
2770 LLoadFieldByIndex* load = new(zone()) LLoadFieldByIndex(object, index);
2771 LInstruction* result = DefineSameAsFirst(load);
2772 return AssignPointerMap(result);
2776 LInstruction* LChunkBuilder::DoStoreFrameContext(HStoreFrameContext* instr) {
2777 LOperand* context = UseRegisterAtStart(instr->context());
2778 return new(zone()) LStoreFrameContext(context);
2782 LInstruction* LChunkBuilder::DoAllocateBlockContext(
2783 HAllocateBlockContext* instr) {
2784 LOperand* context = UseFixed(instr->context(), esi);
2785 LOperand* function = UseRegisterAtStart(instr->function());
2786 LAllocateBlockContext* result =
2787 new(zone()) LAllocateBlockContext(context, function);
2788 return MarkAsCall(DefineFixed(result, esi), instr);
2792 } // namespace internal
2795 #endif // V8_TARGET_ARCH_X87