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/x64/lithium-codegen-x64.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 void LInstruction::PrintTo(StringStream* stream) {
49 stream->Add("%s ", this->Mnemonic());
51 PrintOutputOperandTo(stream);
55 if (HasEnvironment()) {
57 environment()->PrintTo(stream);
60 if (HasPointerMap()) {
62 pointer_map()->PrintTo(stream);
67 void LInstruction::PrintDataTo(StringStream* stream) {
69 for (int i = 0; i < InputCount(); i++) {
70 if (i > 0) stream->Add(" ");
71 if (InputAt(i) == NULL) {
74 InputAt(i)->PrintTo(stream);
80 void LInstruction::PrintOutputOperandTo(StringStream* stream) {
81 if (HasResult()) result()->PrintTo(stream);
85 void LLabel::PrintDataTo(StringStream* stream) {
86 LGap::PrintDataTo(stream);
87 LLabel* rep = replacement();
89 stream->Add(" Dead block replaced with B%d", rep->block_id());
94 bool LGap::IsRedundant() const {
95 for (int i = 0; i < 4; i++) {
96 if (parallel_moves_[i] != NULL && !parallel_moves_[i]->IsRedundant()) {
105 void LGap::PrintDataTo(StringStream* stream) {
106 for (int i = 0; i < 4; i++) {
108 if (parallel_moves_[i] != NULL) {
109 parallel_moves_[i]->PrintDataTo(stream);
116 const char* LArithmeticD::Mnemonic() const {
118 case Token::ADD: return "add-d";
119 case Token::SUB: return "sub-d";
120 case Token::MUL: return "mul-d";
121 case Token::DIV: return "div-d";
122 case Token::MOD: return "mod-d";
130 const char* LArithmeticT::Mnemonic() const {
132 case Token::ADD: return "add-t";
133 case Token::SUB: return "sub-t";
134 case Token::MUL: return "mul-t";
135 case Token::MOD: return "mod-t";
136 case Token::DIV: return "div-t";
137 case Token::BIT_AND: return "bit-and-t";
138 case Token::BIT_OR: return "bit-or-t";
139 case Token::BIT_XOR: return "bit-xor-t";
140 case Token::ROR: return "ror-t";
141 case Token::SHL: return "sal-t";
142 case Token::SAR: return "sar-t";
143 case Token::SHR: return "shr-t";
151 bool LGoto::HasInterestingComment(LCodeGen* gen) const {
152 return !gen->IsNextEmittedBlock(block_id());
157 bool LTemplateResultInstruction<R>::MustSignExtendResult(
158 LPlatformChunk* chunk) const {
159 HValue* hvalue = this->hydrogen_value();
160 return hvalue != NULL &&
161 hvalue->representation().IsInteger32() &&
162 chunk->GetDehoistedKeyIds()->Contains(hvalue->id());
166 void LGoto::PrintDataTo(StringStream* stream) {
167 stream->Add("B%d", block_id());
171 void LBranch::PrintDataTo(StringStream* stream) {
172 stream->Add("B%d | B%d on ", true_block_id(), false_block_id());
173 value()->PrintTo(stream);
177 void LCompareNumericAndBranch::PrintDataTo(StringStream* stream) {
179 left()->PrintTo(stream);
180 stream->Add(" %s ", Token::String(op()));
181 right()->PrintTo(stream);
182 stream->Add(" then B%d else B%d", true_block_id(), false_block_id());
186 void LIsObjectAndBranch::PrintDataTo(StringStream* stream) {
187 stream->Add("if is_object(");
188 value()->PrintTo(stream);
189 stream->Add(") then B%d else B%d", true_block_id(), false_block_id());
193 void LIsStringAndBranch::PrintDataTo(StringStream* stream) {
194 stream->Add("if is_string(");
195 value()->PrintTo(stream);
196 stream->Add(") then B%d else B%d", true_block_id(), false_block_id());
200 void LIsSmiAndBranch::PrintDataTo(StringStream* stream) {
201 stream->Add("if is_smi(");
202 value()->PrintTo(stream);
203 stream->Add(") then B%d else B%d", true_block_id(), false_block_id());
207 void LIsUndetectableAndBranch::PrintDataTo(StringStream* stream) {
208 stream->Add("if is_undetectable(");
209 value()->PrintTo(stream);
210 stream->Add(") then B%d else B%d", true_block_id(), false_block_id());
214 void LStringCompareAndBranch::PrintDataTo(StringStream* stream) {
215 stream->Add("if string_compare(");
216 left()->PrintTo(stream);
217 right()->PrintTo(stream);
218 stream->Add(") then B%d else B%d", true_block_id(), false_block_id());
222 void LHasInstanceTypeAndBranch::PrintDataTo(StringStream* stream) {
223 stream->Add("if has_instance_type(");
224 value()->PrintTo(stream);
225 stream->Add(") then B%d else B%d", true_block_id(), false_block_id());
229 void LHasCachedArrayIndexAndBranch::PrintDataTo(StringStream* stream) {
230 stream->Add("if has_cached_array_index(");
231 value()->PrintTo(stream);
232 stream->Add(") then B%d else B%d", true_block_id(), false_block_id());
236 void LClassOfTestAndBranch::PrintDataTo(StringStream* stream) {
237 stream->Add("if class_of_test(");
238 value()->PrintTo(stream);
239 stream->Add(", \"%o\") then B%d else B%d",
240 *hydrogen()->class_name(),
246 void LTypeofIsAndBranch::PrintDataTo(StringStream* stream) {
247 stream->Add("if typeof ");
248 value()->PrintTo(stream);
249 stream->Add(" == \"%s\" then B%d else B%d",
250 hydrogen()->type_literal()->ToCString().get(),
251 true_block_id(), false_block_id());
255 void LStoreCodeEntry::PrintDataTo(StringStream* stream) {
257 function()->PrintTo(stream);
258 stream->Add(".code_entry = ");
259 code_object()->PrintTo(stream);
263 void LInnerAllocatedObject::PrintDataTo(StringStream* stream) {
265 base_object()->PrintTo(stream);
267 offset()->PrintTo(stream);
271 void LCallJSFunction::PrintDataTo(StringStream* stream) {
273 function()->PrintTo(stream);
274 stream->Add("#%d / ", arity());
278 void LCallWithDescriptor::PrintDataTo(StringStream* stream) {
279 for (int i = 0; i < InputCount(); i++) {
280 InputAt(i)->PrintTo(stream);
283 stream->Add("#%d / ", arity());
287 void LLoadContextSlot::PrintDataTo(StringStream* stream) {
288 context()->PrintTo(stream);
289 stream->Add("[%d]", slot_index());
293 void LStoreContextSlot::PrintDataTo(StringStream* stream) {
294 context()->PrintTo(stream);
295 stream->Add("[%d] <- ", slot_index());
296 value()->PrintTo(stream);
300 void LInvokeFunction::PrintDataTo(StringStream* stream) {
302 function()->PrintTo(stream);
303 stream->Add(" #%d / ", arity());
307 void LCallNew::PrintDataTo(StringStream* stream) {
309 constructor()->PrintTo(stream);
310 stream->Add(" #%d / ", arity());
314 void LCallNewArray::PrintDataTo(StringStream* stream) {
316 constructor()->PrintTo(stream);
317 stream->Add(" #%d / ", arity());
318 ElementsKind kind = hydrogen()->elements_kind();
319 stream->Add(" (%s) ", ElementsKindToString(kind));
323 void LAccessArgumentsAt::PrintDataTo(StringStream* stream) {
324 arguments()->PrintTo(stream);
326 stream->Add(" length ");
327 length()->PrintTo(stream);
329 stream->Add(" index ");
330 index()->PrintTo(stream);
334 int LPlatformChunk::GetNextSpillIndex(RegisterKind kind) {
335 if (kind == DOUBLE_REGISTERS && kDoubleSize == 2 * kPointerSize) {
336 // Skip a slot if for a double-width slot for x32 port.
338 // The spill slot's address is at rbp - (index + 1) * kPointerSize -
339 // StandardFrameConstants::kFixedFrameSizeFromFp. kFixedFrameSizeFromFp is
340 // 2 * kPointerSize, if rbp is aligned at 8-byte boundary, the below "|= 1"
341 // will make sure the spilled doubles are aligned at 8-byte boundary.
342 // TODO(haitao): make sure rbp is aligned at 8-byte boundary for x32 port.
343 spill_slot_count_ |= 1;
345 return spill_slot_count_++;
349 LOperand* LPlatformChunk::GetNextSpillSlot(RegisterKind kind) {
350 // All stack slots are Double stack slots on x64.
351 // Alternatively, at some point, start using half-size
352 // stack slots for int32 values.
353 int index = GetNextSpillIndex(kind);
354 if (kind == DOUBLE_REGISTERS) {
355 return LDoubleStackSlot::Create(index, zone());
357 DCHECK(kind == GENERAL_REGISTERS);
358 return LStackSlot::Create(index, zone());
363 void LStoreNamedField::PrintDataTo(StringStream* stream) {
364 object()->PrintTo(stream);
365 std::ostringstream os;
366 os << hydrogen()->access() << " <- ";
367 stream->Add(os.str().c_str());
368 value()->PrintTo(stream);
372 void LStoreNamedGeneric::PrintDataTo(StringStream* stream) {
373 object()->PrintTo(stream);
375 stream->Add(String::cast(*name())->ToCString().get());
377 value()->PrintTo(stream);
381 void LLoadKeyed::PrintDataTo(StringStream* stream) {
382 elements()->PrintTo(stream);
384 key()->PrintTo(stream);
385 if (hydrogen()->IsDehoisted()) {
386 stream->Add(" + %d]", base_offset());
393 void LStoreKeyed::PrintDataTo(StringStream* stream) {
394 elements()->PrintTo(stream);
396 key()->PrintTo(stream);
397 if (hydrogen()->IsDehoisted()) {
398 stream->Add(" + %d] <-", base_offset());
400 stream->Add("] <- ");
403 if (value() == NULL) {
404 DCHECK(hydrogen()->IsConstantHoleStore() &&
405 hydrogen()->value()->representation().IsDouble());
406 stream->Add("<the hole(nan)>");
408 value()->PrintTo(stream);
413 void LStoreKeyedGeneric::PrintDataTo(StringStream* stream) {
414 object()->PrintTo(stream);
416 key()->PrintTo(stream);
417 stream->Add("] <- ");
418 value()->PrintTo(stream);
422 void LTransitionElementsKind::PrintDataTo(StringStream* stream) {
423 object()->PrintTo(stream);
424 stream->Add(" %p -> %p", *original_map(), *transitioned_map());
428 LPlatformChunk* LChunkBuilder::Build() {
430 chunk_ = new(zone()) LPlatformChunk(info(), graph());
431 LPhase phase("L_Building chunk", chunk_);
434 // If compiling for OSR, reserve space for the unoptimized frame,
435 // which will be subsumed into this frame.
436 if (graph()->has_osr()) {
437 for (int i = graph()->osr()->UnoptimizedFrameSlots(); i > 0; i--) {
438 chunk_->GetNextSpillIndex(GENERAL_REGISTERS);
442 const ZoneList<HBasicBlock*>* blocks = graph()->blocks();
443 for (int i = 0; i < blocks->length(); i++) {
444 HBasicBlock* next = NULL;
445 if (i < blocks->length() - 1) next = blocks->at(i + 1);
446 DoBasicBlock(blocks->at(i), next);
447 if (is_aborted()) return NULL;
454 LUnallocated* LChunkBuilder::ToUnallocated(Register reg) {
455 return new(zone()) LUnallocated(LUnallocated::FIXED_REGISTER,
456 Register::ToAllocationIndex(reg));
460 LUnallocated* LChunkBuilder::ToUnallocated(XMMRegister reg) {
461 return new(zone()) LUnallocated(LUnallocated::FIXED_DOUBLE_REGISTER,
462 XMMRegister::ToAllocationIndex(reg));
466 LOperand* LChunkBuilder::UseFixed(HValue* value, Register fixed_register) {
467 return Use(value, ToUnallocated(fixed_register));
471 LOperand* LChunkBuilder::UseFixedDouble(HValue* value, XMMRegister reg) {
472 return Use(value, ToUnallocated(reg));
476 LOperand* LChunkBuilder::UseRegister(HValue* value) {
477 return Use(value, new(zone()) LUnallocated(LUnallocated::MUST_HAVE_REGISTER));
481 LOperand* LChunkBuilder::UseRegisterAtStart(HValue* value) {
483 new(zone()) LUnallocated(LUnallocated::MUST_HAVE_REGISTER,
484 LUnallocated::USED_AT_START));
488 LOperand* LChunkBuilder::UseTempRegister(HValue* value) {
489 return Use(value, new(zone()) LUnallocated(LUnallocated::WRITABLE_REGISTER));
493 LOperand* LChunkBuilder::UseTempRegisterOrConstant(HValue* value) {
494 return value->IsConstant()
495 ? chunk_->DefineConstantOperand(HConstant::cast(value))
496 : UseTempRegister(value);
500 LOperand* LChunkBuilder::Use(HValue* value) {
501 return Use(value, new(zone()) LUnallocated(LUnallocated::NONE));
505 LOperand* LChunkBuilder::UseAtStart(HValue* value) {
506 return Use(value, new(zone()) LUnallocated(LUnallocated::NONE,
507 LUnallocated::USED_AT_START));
511 LOperand* LChunkBuilder::UseOrConstant(HValue* value) {
512 return value->IsConstant()
513 ? chunk_->DefineConstantOperand(HConstant::cast(value))
518 LOperand* LChunkBuilder::UseOrConstantAtStart(HValue* value) {
519 return value->IsConstant()
520 ? chunk_->DefineConstantOperand(HConstant::cast(value))
525 LOperand* LChunkBuilder::UseRegisterOrConstant(HValue* value) {
526 return value->IsConstant()
527 ? chunk_->DefineConstantOperand(HConstant::cast(value))
528 : UseRegister(value);
532 LOperand* LChunkBuilder::UseRegisterOrConstantAtStart(HValue* value) {
533 return value->IsConstant()
534 ? chunk_->DefineConstantOperand(HConstant::cast(value))
535 : UseRegisterAtStart(value);
539 LOperand* LChunkBuilder::UseConstant(HValue* value) {
540 return chunk_->DefineConstantOperand(HConstant::cast(value));
544 LOperand* LChunkBuilder::UseAny(HValue* value) {
545 return value->IsConstant()
546 ? chunk_->DefineConstantOperand(HConstant::cast(value))
547 : Use(value, new(zone()) LUnallocated(LUnallocated::ANY));
551 LOperand* LChunkBuilder::Use(HValue* value, LUnallocated* operand) {
552 if (value->EmitAtUses()) {
553 HInstruction* instr = HInstruction::cast(value);
554 VisitInstruction(instr);
556 operand->set_virtual_register(value->id());
561 LInstruction* LChunkBuilder::Define(LTemplateResultInstruction<1>* instr,
562 LUnallocated* result) {
563 result->set_virtual_register(current_instruction_->id());
564 instr->set_result(result);
569 LInstruction* LChunkBuilder::DefineAsRegister(
570 LTemplateResultInstruction<1>* instr) {
572 new(zone()) LUnallocated(LUnallocated::MUST_HAVE_REGISTER));
576 LInstruction* LChunkBuilder::DefineAsSpilled(
577 LTemplateResultInstruction<1>* instr,
580 new(zone()) LUnallocated(LUnallocated::FIXED_SLOT, index));
584 LInstruction* LChunkBuilder::DefineSameAsFirst(
585 LTemplateResultInstruction<1>* instr) {
587 new(zone()) LUnallocated(LUnallocated::SAME_AS_FIRST_INPUT));
591 LInstruction* LChunkBuilder::DefineFixed(LTemplateResultInstruction<1>* instr,
593 return Define(instr, ToUnallocated(reg));
597 LInstruction* LChunkBuilder::DefineFixedDouble(
598 LTemplateResultInstruction<1>* instr,
600 return Define(instr, ToUnallocated(reg));
604 LInstruction* LChunkBuilder::AssignEnvironment(LInstruction* instr) {
605 HEnvironment* hydrogen_env = current_block_->last_environment();
606 int argument_index_accumulator = 0;
607 ZoneList<HValue*> objects_to_materialize(0, zone());
608 instr->set_environment(CreateEnvironment(
609 hydrogen_env, &argument_index_accumulator, &objects_to_materialize));
614 LInstruction* LChunkBuilder::MarkAsCall(LInstruction* instr,
615 HInstruction* hinstr,
616 CanDeoptimize can_deoptimize) {
617 info()->MarkAsNonDeferredCalling();
623 instr = AssignPointerMap(instr);
625 // If instruction does not have side-effects lazy deoptimization
626 // after the call will try to deoptimize to the point before the call.
627 // Thus we still need to attach environment to this call even if
628 // call sequence can not deoptimize eagerly.
629 bool needs_environment =
630 (can_deoptimize == CAN_DEOPTIMIZE_EAGERLY) ||
631 !hinstr->HasObservableSideEffects();
632 if (needs_environment && !instr->HasEnvironment()) {
633 instr = AssignEnvironment(instr);
634 // We can't really figure out if the environment is needed or not.
635 instr->environment()->set_has_been_used();
642 LInstruction* LChunkBuilder::AssignPointerMap(LInstruction* instr) {
643 DCHECK(!instr->HasPointerMap());
644 instr->set_pointer_map(new(zone()) LPointerMap(zone()));
649 LUnallocated* LChunkBuilder::TempRegister() {
650 LUnallocated* operand =
651 new(zone()) LUnallocated(LUnallocated::MUST_HAVE_REGISTER);
652 int vreg = allocator_->GetVirtualRegister();
653 if (!allocator_->AllocationOk()) {
654 Abort(kOutOfVirtualRegistersWhileTryingToAllocateTempRegister);
657 operand->set_virtual_register(vreg);
662 LOperand* LChunkBuilder::FixedTemp(Register reg) {
663 LUnallocated* operand = ToUnallocated(reg);
664 DCHECK(operand->HasFixedPolicy());
669 LOperand* LChunkBuilder::FixedTemp(XMMRegister reg) {
670 LUnallocated* operand = ToUnallocated(reg);
671 DCHECK(operand->HasFixedPolicy());
676 LInstruction* LChunkBuilder::DoBlockEntry(HBlockEntry* instr) {
677 return new(zone()) LLabel(instr->block());
681 LInstruction* LChunkBuilder::DoDummyUse(HDummyUse* instr) {
682 return DefineAsRegister(new(zone()) LDummyUse(UseAny(instr->value())));
686 LInstruction* LChunkBuilder::DoEnvironmentMarker(HEnvironmentMarker* instr) {
692 LInstruction* LChunkBuilder::DoDeoptimize(HDeoptimize* instr) {
693 return AssignEnvironment(new(zone()) LDeoptimize);
697 LInstruction* LChunkBuilder::DoShift(Token::Value op,
698 HBitwiseBinaryOperation* instr) {
699 if (instr->representation().IsSmiOrInteger32()) {
700 DCHECK(instr->left()->representation().Equals(instr->representation()));
701 DCHECK(instr->right()->representation().Equals(instr->representation()));
702 LOperand* left = UseRegisterAtStart(instr->left());
704 HValue* right_value = instr->right();
705 LOperand* right = NULL;
706 int constant_value = 0;
707 bool does_deopt = false;
708 if (right_value->IsConstant()) {
709 HConstant* constant = HConstant::cast(right_value);
710 right = chunk_->DefineConstantOperand(constant);
711 constant_value = constant->Integer32Value() & 0x1f;
712 if (SmiValuesAre31Bits() && instr->representation().IsSmi() &&
713 constant_value > 0) {
714 // Left shift can deoptimize if we shift by > 0 and the result
715 // cannot be truncated to smi.
716 does_deopt = !instr->CheckUsesForFlag(HValue::kTruncatingToSmi);
719 right = UseFixed(right_value, rcx);
722 // Shift operations can only deoptimize if we do a logical shift by 0 and
723 // the result cannot be truncated to int32.
724 if (op == Token::SHR && constant_value == 0) {
725 does_deopt = !instr->CheckFlag(HInstruction::kUint32);
728 LInstruction* result =
729 DefineSameAsFirst(new(zone()) LShiftI(op, left, right, does_deopt));
730 return does_deopt ? AssignEnvironment(result) : result;
732 return DoArithmeticT(op, instr);
737 LInstruction* LChunkBuilder::DoArithmeticD(Token::Value op,
738 HArithmeticBinaryOperation* instr) {
739 DCHECK(instr->representation().IsDouble());
740 DCHECK(instr->left()->representation().IsDouble());
741 DCHECK(instr->right()->representation().IsDouble());
742 if (op == Token::MOD) {
743 LOperand* left = UseRegisterAtStart(instr->BetterLeftOperand());
744 LOperand* right = UseFixedDouble(instr->BetterRightOperand(), xmm1);
745 LArithmeticD* result = new(zone()) LArithmeticD(op, left, right);
746 return MarkAsCall(DefineSameAsFirst(result), instr);
748 LOperand* left = UseRegisterAtStart(instr->BetterLeftOperand());
749 LOperand* right = UseRegisterAtStart(instr->BetterRightOperand());
750 LArithmeticD* result = new(zone()) LArithmeticD(op, left, right);
751 return DefineSameAsFirst(result);
756 LInstruction* LChunkBuilder::DoArithmeticT(Token::Value op,
757 HBinaryOperation* instr) {
758 HValue* left = instr->left();
759 HValue* right = instr->right();
760 DCHECK(left->representation().IsTagged());
761 DCHECK(right->representation().IsTagged());
762 LOperand* context = UseFixed(instr->context(), rsi);
763 LOperand* left_operand = UseFixed(left, rdx);
764 LOperand* right_operand = UseFixed(right, rax);
765 LArithmeticT* result =
766 new(zone()) LArithmeticT(op, context, left_operand, right_operand);
767 return MarkAsCall(DefineFixed(result, rax), instr);
771 void LChunkBuilder::DoBasicBlock(HBasicBlock* block, HBasicBlock* next_block) {
772 DCHECK(is_building());
773 current_block_ = block;
774 next_block_ = next_block;
775 if (block->IsStartBlock()) {
776 block->UpdateEnvironment(graph_->start_environment());
778 } else if (block->predecessors()->length() == 1) {
779 // We have a single predecessor => copy environment and outgoing
780 // argument count from the predecessor.
781 DCHECK(block->phis()->length() == 0);
782 HBasicBlock* pred = block->predecessors()->at(0);
783 HEnvironment* last_environment = pred->last_environment();
784 DCHECK(last_environment != NULL);
785 // Only copy the environment, if it is later used again.
786 if (pred->end()->SecondSuccessor() == NULL) {
787 DCHECK(pred->end()->FirstSuccessor() == block);
789 if (pred->end()->FirstSuccessor()->block_id() > block->block_id() ||
790 pred->end()->SecondSuccessor()->block_id() > block->block_id()) {
791 last_environment = last_environment->Copy();
794 block->UpdateEnvironment(last_environment);
795 DCHECK(pred->argument_count() >= 0);
796 argument_count_ = pred->argument_count();
798 // We are at a state join => process phis.
799 HBasicBlock* pred = block->predecessors()->at(0);
800 // No need to copy the environment, it cannot be used later.
801 HEnvironment* last_environment = pred->last_environment();
802 for (int i = 0; i < block->phis()->length(); ++i) {
803 HPhi* phi = block->phis()->at(i);
804 if (phi->HasMergedIndex()) {
805 last_environment->SetValueAt(phi->merged_index(), phi);
808 for (int i = 0; i < block->deleted_phis()->length(); ++i) {
809 if (block->deleted_phis()->at(i) < last_environment->length()) {
810 last_environment->SetValueAt(block->deleted_phis()->at(i),
811 graph_->GetConstantUndefined());
814 block->UpdateEnvironment(last_environment);
815 // Pick up the outgoing argument count of one of the predecessors.
816 argument_count_ = pred->argument_count();
818 HInstruction* current = block->first();
819 int start = chunk_->instructions()->length();
820 while (current != NULL && !is_aborted()) {
821 // Code for constants in registers is generated lazily.
822 if (!current->EmitAtUses()) {
823 VisitInstruction(current);
825 current = current->next();
827 int end = chunk_->instructions()->length() - 1;
829 block->set_first_instruction_index(start);
830 block->set_last_instruction_index(end);
832 block->set_argument_count(argument_count_);
834 current_block_ = NULL;
838 void LChunkBuilder::VisitInstruction(HInstruction* current) {
839 HInstruction* old_current = current_instruction_;
840 current_instruction_ = current;
842 LInstruction* instr = NULL;
843 if (current->CanReplaceWithDummyUses()) {
844 if (current->OperandCount() == 0) {
845 instr = DefineAsRegister(new(zone()) LDummy());
847 DCHECK(!current->OperandAt(0)->IsControlInstruction());
848 instr = DefineAsRegister(new(zone())
849 LDummyUse(UseAny(current->OperandAt(0))));
851 for (int i = 1; i < current->OperandCount(); ++i) {
852 if (current->OperandAt(i)->IsControlInstruction()) continue;
853 LInstruction* dummy =
854 new(zone()) LDummyUse(UseAny(current->OperandAt(i)));
855 dummy->set_hydrogen_value(current);
856 chunk_->AddInstruction(dummy, current_block_);
859 HBasicBlock* successor;
860 if (current->IsControlInstruction() &&
861 HControlInstruction::cast(current)->KnownSuccessorBlock(&successor) &&
863 instr = new(zone()) LGoto(successor);
865 instr = current->CompileToLithium(this);
869 argument_count_ += current->argument_delta();
870 DCHECK(argument_count_ >= 0);
873 AddInstruction(instr, current);
876 current_instruction_ = old_current;
880 void LChunkBuilder::AddInstruction(LInstruction* instr,
881 HInstruction* hydrogen_val) {
882 // Associate the hydrogen instruction first, since we may need it for
883 // the ClobbersRegisters() or ClobbersDoubleRegisters() calls below.
884 instr->set_hydrogen_value(hydrogen_val);
887 // Make sure that the lithium instruction has either no fixed register
888 // constraints in temps or the result OR no uses that are only used at
889 // start. If this invariant doesn't hold, the register allocator can decide
890 // to insert a split of a range immediately before the instruction due to an
891 // already allocated register needing to be used for the instruction's fixed
892 // register constraint. In this case, The register allocator won't see an
893 // interference between the split child and the use-at-start (it would if
894 // the it was just a plain use), so it is free to move the split child into
895 // the same register that is used for the use-at-start.
896 // See https://code.google.com/p/chromium/issues/detail?id=201590
897 if (!(instr->ClobbersRegisters() &&
898 instr->ClobbersDoubleRegisters(isolate()))) {
900 int used_at_start = 0;
901 for (UseIterator it(instr); !it.Done(); it.Advance()) {
902 LUnallocated* operand = LUnallocated::cast(it.Current());
903 if (operand->IsUsedAtStart()) ++used_at_start;
905 if (instr->Output() != NULL) {
906 if (LUnallocated::cast(instr->Output())->HasFixedPolicy()) ++fixed;
908 for (TempIterator it(instr); !it.Done(); it.Advance()) {
909 LUnallocated* operand = LUnallocated::cast(it.Current());
910 if (operand->HasFixedPolicy()) ++fixed;
912 DCHECK(fixed == 0 || used_at_start == 0);
916 if (FLAG_stress_pointer_maps && !instr->HasPointerMap()) {
917 instr = AssignPointerMap(instr);
919 if (FLAG_stress_environments && !instr->HasEnvironment()) {
920 instr = AssignEnvironment(instr);
922 chunk_->AddInstruction(instr, current_block_);
924 if (instr->IsCall()) {
925 HValue* hydrogen_value_for_lazy_bailout = hydrogen_val;
926 LInstruction* instruction_needing_environment = NULL;
927 if (hydrogen_val->HasObservableSideEffects()) {
928 HSimulate* sim = HSimulate::cast(hydrogen_val->next());
929 instruction_needing_environment = instr;
930 sim->ReplayEnvironment(current_block_->last_environment());
931 hydrogen_value_for_lazy_bailout = sim;
933 LInstruction* bailout = AssignEnvironment(new(zone()) LLazyBailout());
934 bailout->set_hydrogen_value(hydrogen_value_for_lazy_bailout);
935 chunk_->AddInstruction(bailout, current_block_);
936 if (instruction_needing_environment != NULL) {
937 // Store the lazy deopt environment with the instruction if needed.
938 // Right now it is only used for LInstanceOfKnownGlobal.
939 instruction_needing_environment->
940 SetDeferredLazyDeoptimizationEnvironment(bailout->environment());
946 LInstruction* LChunkBuilder::DoGoto(HGoto* instr) {
947 return new(zone()) LGoto(instr->FirstSuccessor());
951 LInstruction* LChunkBuilder::DoDebugBreak(HDebugBreak* instr) {
952 return new(zone()) LDebugBreak();
956 LInstruction* LChunkBuilder::DoBranch(HBranch* instr) {
957 HValue* value = instr->value();
958 Representation r = value->representation();
959 HType type = value->type();
960 ToBooleanStub::Types expected = instr->expected_input_types();
961 if (expected.IsEmpty()) expected = ToBooleanStub::Types::Generic();
963 bool easy_case = !r.IsTagged() || type.IsBoolean() || type.IsSmi() ||
964 type.IsJSArray() || type.IsHeapNumber() || type.IsString();
965 LInstruction* branch = new(zone()) LBranch(UseRegister(value));
967 ((!expected.Contains(ToBooleanStub::SMI) && expected.NeedsMap()) ||
968 !expected.IsGeneric())) {
969 branch = AssignEnvironment(branch);
975 LInstruction* LChunkBuilder::DoCompareMap(HCompareMap* instr) {
976 DCHECK(instr->value()->representation().IsTagged());
977 LOperand* value = UseRegisterAtStart(instr->value());
978 return new(zone()) LCmpMapAndBranch(value);
982 LInstruction* LChunkBuilder::DoArgumentsLength(HArgumentsLength* length) {
983 info()->MarkAsRequiresFrame();
984 return DefineAsRegister(new(zone()) LArgumentsLength(Use(length->value())));
988 LInstruction* LChunkBuilder::DoArgumentsElements(HArgumentsElements* elems) {
989 info()->MarkAsRequiresFrame();
990 return DefineAsRegister(new(zone()) LArgumentsElements);
994 LInstruction* LChunkBuilder::DoInstanceOf(HInstanceOf* instr) {
995 LOperand* left = UseFixed(instr->left(), rax);
996 LOperand* right = UseFixed(instr->right(), rdx);
997 LOperand* context = UseFixed(instr->context(), rsi);
998 LInstanceOf* result = new(zone()) LInstanceOf(context, left, right);
999 return MarkAsCall(DefineFixed(result, rax), instr);
1003 LInstruction* LChunkBuilder::DoInstanceOfKnownGlobal(
1004 HInstanceOfKnownGlobal* instr) {
1005 LInstanceOfKnownGlobal* result =
1006 new(zone()) LInstanceOfKnownGlobal(UseFixed(instr->context(), rsi),
1007 UseFixed(instr->left(), rax),
1009 return MarkAsCall(DefineFixed(result, rax), instr);
1013 LInstruction* LChunkBuilder::DoWrapReceiver(HWrapReceiver* instr) {
1014 LOperand* receiver = UseRegister(instr->receiver());
1015 LOperand* function = UseRegisterAtStart(instr->function());
1016 LWrapReceiver* result = new(zone()) LWrapReceiver(receiver, function);
1017 return AssignEnvironment(DefineSameAsFirst(result));
1021 LInstruction* LChunkBuilder::DoApplyArguments(HApplyArguments* instr) {
1022 LOperand* function = UseFixed(instr->function(), rdi);
1023 LOperand* receiver = UseFixed(instr->receiver(), rax);
1024 LOperand* length = UseFixed(instr->length(), rbx);
1025 LOperand* elements = UseFixed(instr->elements(), rcx);
1026 LApplyArguments* result = new(zone()) LApplyArguments(function,
1030 return MarkAsCall(DefineFixed(result, rax), instr, CAN_DEOPTIMIZE_EAGERLY);
1034 LInstruction* LChunkBuilder::DoPushArguments(HPushArguments* instr) {
1035 int argc = instr->OperandCount();
1036 for (int i = 0; i < argc; ++i) {
1037 LOperand* argument = UseOrConstant(instr->argument(i));
1038 AddInstruction(new(zone()) LPushArgument(argument), instr);
1044 LInstruction* LChunkBuilder::DoStoreCodeEntry(
1045 HStoreCodeEntry* store_code_entry) {
1046 LOperand* function = UseRegister(store_code_entry->function());
1047 LOperand* code_object = UseTempRegister(store_code_entry->code_object());
1048 return new(zone()) LStoreCodeEntry(function, code_object);
1052 LInstruction* LChunkBuilder::DoInnerAllocatedObject(
1053 HInnerAllocatedObject* instr) {
1054 LOperand* base_object = UseRegisterAtStart(instr->base_object());
1055 LOperand* offset = UseRegisterOrConstantAtStart(instr->offset());
1056 return DefineAsRegister(
1057 new(zone()) LInnerAllocatedObject(base_object, offset));
1061 LInstruction* LChunkBuilder::DoThisFunction(HThisFunction* instr) {
1062 return instr->HasNoUses()
1064 : DefineAsRegister(new(zone()) LThisFunction);
1068 LInstruction* LChunkBuilder::DoContext(HContext* instr) {
1069 if (instr->HasNoUses()) return NULL;
1071 if (info()->IsStub()) {
1072 return DefineFixed(new(zone()) LContext, rsi);
1075 return DefineAsRegister(new(zone()) LContext);
1079 LInstruction* LChunkBuilder::DoDeclareGlobals(HDeclareGlobals* instr) {
1080 LOperand* context = UseFixed(instr->context(), rsi);
1081 return MarkAsCall(new(zone()) LDeclareGlobals(context), instr);
1085 LInstruction* LChunkBuilder::DoCallJSFunction(
1086 HCallJSFunction* instr) {
1087 LOperand* function = UseFixed(instr->function(), rdi);
1089 LCallJSFunction* result = new(zone()) LCallJSFunction(function);
1091 return MarkAsCall(DefineFixed(result, rax), instr);
1095 LInstruction* LChunkBuilder::DoCallWithDescriptor(
1096 HCallWithDescriptor* instr) {
1097 CallInterfaceDescriptor descriptor = instr->descriptor();
1099 LOperand* target = UseRegisterOrConstantAtStart(instr->target());
1100 ZoneList<LOperand*> ops(instr->OperandCount(), zone());
1101 ops.Add(target, zone());
1102 for (int i = 1; i < instr->OperandCount(); i++) {
1104 UseFixed(instr->OperandAt(i), descriptor.GetParameterRegister(i - 1));
1105 ops.Add(op, zone());
1108 LCallWithDescriptor* result = new(zone()) LCallWithDescriptor(
1109 descriptor, ops, zone());
1110 return MarkAsCall(DefineFixed(result, rax), instr);
1114 LInstruction* LChunkBuilder::DoTailCallThroughMegamorphicCache(
1115 HTailCallThroughMegamorphicCache* instr) {
1116 LOperand* context = UseFixed(instr->context(), rsi);
1117 LOperand* receiver_register =
1118 UseFixed(instr->receiver(), LoadDescriptor::ReceiverRegister());
1119 LOperand* name_register =
1120 UseFixed(instr->name(), LoadDescriptor::NameRegister());
1121 // Not marked as call. It can't deoptimize, and it never returns.
1122 return new (zone()) LTailCallThroughMegamorphicCache(
1123 context, receiver_register, name_register);
1127 LInstruction* LChunkBuilder::DoInvokeFunction(HInvokeFunction* instr) {
1128 LOperand* context = UseFixed(instr->context(), rsi);
1129 LOperand* function = UseFixed(instr->function(), rdi);
1130 LInvokeFunction* result = new(zone()) LInvokeFunction(context, function);
1131 return MarkAsCall(DefineFixed(result, rax), instr, CANNOT_DEOPTIMIZE_EAGERLY);
1135 LInstruction* LChunkBuilder::DoUnaryMathOperation(HUnaryMathOperation* instr) {
1136 switch (instr->op()) {
1138 return DoMathFloor(instr);
1140 return DoMathRound(instr);
1142 return DoMathFround(instr);
1144 return DoMathAbs(instr);
1146 return DoMathLog(instr);
1148 return DoMathExp(instr);
1150 return DoMathSqrt(instr);
1152 return DoMathPowHalf(instr);
1154 return DoMathClz32(instr);
1162 LInstruction* LChunkBuilder::DoMathFloor(HUnaryMathOperation* instr) {
1163 LOperand* input = UseRegisterAtStart(instr->value());
1164 LMathFloor* result = new(zone()) LMathFloor(input);
1165 return AssignEnvironment(DefineAsRegister(result));
1169 LInstruction* LChunkBuilder::DoMathRound(HUnaryMathOperation* instr) {
1170 LOperand* input = UseRegister(instr->value());
1171 LOperand* temp = FixedTemp(xmm4);
1172 LMathRound* result = new(zone()) LMathRound(input, temp);
1173 return AssignEnvironment(DefineAsRegister(result));
1177 LInstruction* LChunkBuilder::DoMathFround(HUnaryMathOperation* instr) {
1178 LOperand* input = UseRegister(instr->value());
1179 LMathFround* result = new (zone()) LMathFround(input);
1180 return DefineAsRegister(result);
1184 LInstruction* LChunkBuilder::DoMathAbs(HUnaryMathOperation* instr) {
1185 LOperand* context = UseAny(instr->context());
1186 LOperand* input = UseRegisterAtStart(instr->value());
1187 LInstruction* result =
1188 DefineSameAsFirst(new(zone()) LMathAbs(context, input));
1189 Representation r = instr->value()->representation();
1190 if (!r.IsDouble() && !r.IsSmiOrInteger32()) result = AssignPointerMap(result);
1191 if (!r.IsDouble()) result = AssignEnvironment(result);
1196 LInstruction* LChunkBuilder::DoMathLog(HUnaryMathOperation* instr) {
1197 DCHECK(instr->representation().IsDouble());
1198 DCHECK(instr->value()->representation().IsDouble());
1199 LOperand* input = UseRegisterAtStart(instr->value());
1200 return MarkAsCall(DefineSameAsFirst(new(zone()) LMathLog(input)), instr);
1204 LInstruction* LChunkBuilder::DoMathClz32(HUnaryMathOperation* instr) {
1205 LOperand* input = UseRegisterAtStart(instr->value());
1206 LMathClz32* result = new(zone()) LMathClz32(input);
1207 return DefineAsRegister(result);
1211 LInstruction* LChunkBuilder::DoMathExp(HUnaryMathOperation* instr) {
1212 DCHECK(instr->representation().IsDouble());
1213 DCHECK(instr->value()->representation().IsDouble());
1214 LOperand* value = UseTempRegister(instr->value());
1215 LOperand* temp1 = TempRegister();
1216 LOperand* temp2 = TempRegister();
1217 LMathExp* result = new(zone()) LMathExp(value, temp1, temp2);
1218 return DefineAsRegister(result);
1222 LInstruction* LChunkBuilder::DoMathSqrt(HUnaryMathOperation* instr) {
1223 LOperand* input = UseAtStart(instr->value());
1224 return DefineAsRegister(new(zone()) LMathSqrt(input));
1228 LInstruction* LChunkBuilder::DoMathPowHalf(HUnaryMathOperation* instr) {
1229 LOperand* input = UseRegisterAtStart(instr->value());
1230 LMathPowHalf* result = new(zone()) LMathPowHalf(input);
1231 return DefineSameAsFirst(result);
1235 LInstruction* LChunkBuilder::DoCallNew(HCallNew* instr) {
1236 LOperand* context = UseFixed(instr->context(), rsi);
1237 LOperand* constructor = UseFixed(instr->constructor(), rdi);
1238 LCallNew* result = new(zone()) LCallNew(context, constructor);
1239 return MarkAsCall(DefineFixed(result, rax), instr);
1243 LInstruction* LChunkBuilder::DoCallNewArray(HCallNewArray* instr) {
1244 LOperand* context = UseFixed(instr->context(), rsi);
1245 LOperand* constructor = UseFixed(instr->constructor(), rdi);
1246 LCallNewArray* result = new(zone()) LCallNewArray(context, constructor);
1247 return MarkAsCall(DefineFixed(result, rax), instr);
1251 LInstruction* LChunkBuilder::DoCallFunction(HCallFunction* instr) {
1252 LOperand* context = UseFixed(instr->context(), rsi);
1253 LOperand* function = UseFixed(instr->function(), rdi);
1254 LCallFunction* call = new(zone()) LCallFunction(context, function);
1255 return MarkAsCall(DefineFixed(call, rax), instr);
1259 LInstruction* LChunkBuilder::DoCallRuntime(HCallRuntime* instr) {
1260 LOperand* context = UseFixed(instr->context(), rsi);
1261 LCallRuntime* result = new(zone()) LCallRuntime(context);
1262 return MarkAsCall(DefineFixed(result, rax), instr);
1266 LInstruction* LChunkBuilder::DoRor(HRor* instr) {
1267 return DoShift(Token::ROR, instr);
1271 LInstruction* LChunkBuilder::DoShr(HShr* instr) {
1272 return DoShift(Token::SHR, instr);
1276 LInstruction* LChunkBuilder::DoSar(HSar* instr) {
1277 return DoShift(Token::SAR, instr);
1281 LInstruction* LChunkBuilder::DoShl(HShl* instr) {
1282 return DoShift(Token::SHL, instr);
1286 LInstruction* LChunkBuilder::DoBitwise(HBitwise* instr) {
1287 if (instr->representation().IsSmiOrInteger32()) {
1288 DCHECK(instr->left()->representation().Equals(instr->representation()));
1289 DCHECK(instr->right()->representation().Equals(instr->representation()));
1290 DCHECK(instr->CheckFlag(HValue::kTruncatingToInt32));
1292 LOperand* left = UseRegisterAtStart(instr->BetterLeftOperand());
1293 LOperand* right = UseOrConstantAtStart(instr->BetterRightOperand());
1294 return DefineSameAsFirst(new(zone()) LBitI(left, right));
1296 return DoArithmeticT(instr->op(), instr);
1301 LInstruction* LChunkBuilder::DoDivByPowerOf2I(HDiv* instr) {
1302 DCHECK(instr->representation().IsSmiOrInteger32());
1303 DCHECK(instr->left()->representation().Equals(instr->representation()));
1304 DCHECK(instr->right()->representation().Equals(instr->representation()));
1305 LOperand* dividend = UseRegister(instr->left());
1306 int32_t divisor = instr->right()->GetInteger32Constant();
1307 LInstruction* result = DefineAsRegister(new(zone()) LDivByPowerOf2I(
1308 dividend, divisor));
1309 if ((instr->CheckFlag(HValue::kBailoutOnMinusZero) && divisor < 0) ||
1310 (instr->CheckFlag(HValue::kCanOverflow) && divisor == -1) ||
1311 (!instr->CheckFlag(HInstruction::kAllUsesTruncatingToInt32) &&
1312 divisor != 1 && divisor != -1)) {
1313 result = AssignEnvironment(result);
1319 LInstruction* LChunkBuilder::DoDivByConstI(HDiv* instr) {
1320 DCHECK(instr->representation().IsInteger32());
1321 DCHECK(instr->left()->representation().Equals(instr->representation()));
1322 DCHECK(instr->right()->representation().Equals(instr->representation()));
1323 LOperand* dividend = UseRegister(instr->left());
1324 int32_t divisor = instr->right()->GetInteger32Constant();
1325 LOperand* temp1 = FixedTemp(rax);
1326 LOperand* temp2 = FixedTemp(rdx);
1327 LInstruction* result = DefineFixed(new(zone()) LDivByConstI(
1328 dividend, divisor, temp1, temp2), rdx);
1330 (instr->CheckFlag(HValue::kBailoutOnMinusZero) && divisor < 0) ||
1331 !instr->CheckFlag(HInstruction::kAllUsesTruncatingToInt32)) {
1332 result = AssignEnvironment(result);
1338 LInstruction* LChunkBuilder::DoDivI(HDiv* instr) {
1339 DCHECK(instr->representation().IsSmiOrInteger32());
1340 DCHECK(instr->left()->representation().Equals(instr->representation()));
1341 DCHECK(instr->right()->representation().Equals(instr->representation()));
1342 LOperand* dividend = UseFixed(instr->left(), rax);
1343 LOperand* divisor = UseRegister(instr->right());
1344 LOperand* temp = FixedTemp(rdx);
1345 LInstruction* result = DefineFixed(new(zone()) LDivI(
1346 dividend, divisor, temp), rax);
1347 if (instr->CheckFlag(HValue::kCanBeDivByZero) ||
1348 instr->CheckFlag(HValue::kBailoutOnMinusZero) ||
1349 instr->CheckFlag(HValue::kCanOverflow) ||
1350 !instr->CheckFlag(HValue::kAllUsesTruncatingToInt32)) {
1351 result = AssignEnvironment(result);
1357 LInstruction* LChunkBuilder::DoDiv(HDiv* instr) {
1358 if (instr->representation().IsSmiOrInteger32()) {
1359 if (instr->RightIsPowerOf2()) {
1360 return DoDivByPowerOf2I(instr);
1361 } else if (instr->right()->IsConstant()) {
1362 return DoDivByConstI(instr);
1364 return DoDivI(instr);
1366 } else if (instr->representation().IsDouble()) {
1367 return DoArithmeticD(Token::DIV, instr);
1369 return DoArithmeticT(Token::DIV, instr);
1374 LInstruction* LChunkBuilder::DoFlooringDivByPowerOf2I(HMathFloorOfDiv* instr) {
1375 LOperand* dividend = UseRegisterAtStart(instr->left());
1376 int32_t divisor = instr->right()->GetInteger32Constant();
1377 LInstruction* result = DefineSameAsFirst(new(zone()) LFlooringDivByPowerOf2I(
1378 dividend, divisor));
1379 if ((instr->CheckFlag(HValue::kBailoutOnMinusZero) && divisor < 0) ||
1380 (instr->CheckFlag(HValue::kLeftCanBeMinInt) && divisor == -1)) {
1381 result = AssignEnvironment(result);
1387 LInstruction* LChunkBuilder::DoFlooringDivByConstI(HMathFloorOfDiv* instr) {
1388 DCHECK(instr->representation().IsInteger32());
1389 DCHECK(instr->left()->representation().Equals(instr->representation()));
1390 DCHECK(instr->right()->representation().Equals(instr->representation()));
1391 LOperand* dividend = UseRegister(instr->left());
1392 int32_t divisor = instr->right()->GetInteger32Constant();
1393 LOperand* temp1 = FixedTemp(rax);
1394 LOperand* temp2 = FixedTemp(rdx);
1396 ((divisor > 0 && !instr->CheckFlag(HValue::kLeftCanBeNegative)) ||
1397 (divisor < 0 && !instr->CheckFlag(HValue::kLeftCanBePositive))) ?
1398 NULL : TempRegister();
1399 LInstruction* result =
1400 DefineFixed(new(zone()) LFlooringDivByConstI(dividend,
1407 (instr->CheckFlag(HValue::kBailoutOnMinusZero) && divisor < 0)) {
1408 result = AssignEnvironment(result);
1414 LInstruction* LChunkBuilder::DoFlooringDivI(HMathFloorOfDiv* instr) {
1415 DCHECK(instr->representation().IsSmiOrInteger32());
1416 DCHECK(instr->left()->representation().Equals(instr->representation()));
1417 DCHECK(instr->right()->representation().Equals(instr->representation()));
1418 LOperand* dividend = UseFixed(instr->left(), rax);
1419 LOperand* divisor = UseRegister(instr->right());
1420 LOperand* temp = FixedTemp(rdx);
1421 LInstruction* result = DefineFixed(new(zone()) LFlooringDivI(
1422 dividend, divisor, temp), rax);
1423 if (instr->CheckFlag(HValue::kCanBeDivByZero) ||
1424 instr->CheckFlag(HValue::kBailoutOnMinusZero) ||
1425 instr->CheckFlag(HValue::kCanOverflow)) {
1426 result = AssignEnvironment(result);
1432 LInstruction* LChunkBuilder::DoMathFloorOfDiv(HMathFloorOfDiv* instr) {
1433 if (instr->RightIsPowerOf2()) {
1434 return DoFlooringDivByPowerOf2I(instr);
1435 } else if (instr->right()->IsConstant()) {
1436 return DoFlooringDivByConstI(instr);
1438 return DoFlooringDivI(instr);
1443 LInstruction* LChunkBuilder::DoModByPowerOf2I(HMod* instr) {
1444 DCHECK(instr->representation().IsSmiOrInteger32());
1445 DCHECK(instr->left()->representation().Equals(instr->representation()));
1446 DCHECK(instr->right()->representation().Equals(instr->representation()));
1447 LOperand* dividend = UseRegisterAtStart(instr->left());
1448 int32_t divisor = instr->right()->GetInteger32Constant();
1449 LInstruction* result = DefineSameAsFirst(new(zone()) LModByPowerOf2I(
1450 dividend, divisor));
1451 if (instr->CheckFlag(HValue::kLeftCanBeNegative) &&
1452 instr->CheckFlag(HValue::kBailoutOnMinusZero)) {
1453 result = AssignEnvironment(result);
1459 LInstruction* LChunkBuilder::DoModByConstI(HMod* instr) {
1460 DCHECK(instr->representation().IsSmiOrInteger32());
1461 DCHECK(instr->left()->representation().Equals(instr->representation()));
1462 DCHECK(instr->right()->representation().Equals(instr->representation()));
1463 LOperand* dividend = UseRegister(instr->left());
1464 int32_t divisor = instr->right()->GetInteger32Constant();
1465 LOperand* temp1 = FixedTemp(rax);
1466 LOperand* temp2 = FixedTemp(rdx);
1467 LInstruction* result = DefineFixed(new(zone()) LModByConstI(
1468 dividend, divisor, temp1, temp2), rax);
1469 if (divisor == 0 || instr->CheckFlag(HValue::kBailoutOnMinusZero)) {
1470 result = AssignEnvironment(result);
1476 LInstruction* LChunkBuilder::DoModI(HMod* instr) {
1477 DCHECK(instr->representation().IsSmiOrInteger32());
1478 DCHECK(instr->left()->representation().Equals(instr->representation()));
1479 DCHECK(instr->right()->representation().Equals(instr->representation()));
1480 LOperand* dividend = UseFixed(instr->left(), rax);
1481 LOperand* divisor = UseRegister(instr->right());
1482 LOperand* temp = FixedTemp(rdx);
1483 LInstruction* result = DefineFixed(new(zone()) LModI(
1484 dividend, divisor, temp), rdx);
1485 if (instr->CheckFlag(HValue::kCanBeDivByZero) ||
1486 instr->CheckFlag(HValue::kBailoutOnMinusZero)) {
1487 result = AssignEnvironment(result);
1493 LInstruction* LChunkBuilder::DoMod(HMod* instr) {
1494 if (instr->representation().IsSmiOrInteger32()) {
1495 if (instr->RightIsPowerOf2()) {
1496 return DoModByPowerOf2I(instr);
1497 } else if (instr->right()->IsConstant()) {
1498 return DoModByConstI(instr);
1500 return DoModI(instr);
1502 } else if (instr->representation().IsDouble()) {
1503 return DoArithmeticD(Token::MOD, instr);
1505 return DoArithmeticT(Token::MOD, instr);
1510 LInstruction* LChunkBuilder::DoMul(HMul* instr) {
1511 if (instr->representation().IsSmiOrInteger32()) {
1512 DCHECK(instr->left()->representation().Equals(instr->representation()));
1513 DCHECK(instr->right()->representation().Equals(instr->representation()));
1514 LOperand* left = UseRegisterAtStart(instr->BetterLeftOperand());
1515 LOperand* right = UseOrConstant(instr->BetterRightOperand());
1516 LMulI* mul = new(zone()) LMulI(left, right);
1517 if (instr->CheckFlag(HValue::kCanOverflow) ||
1518 instr->CheckFlag(HValue::kBailoutOnMinusZero)) {
1519 AssignEnvironment(mul);
1521 return DefineSameAsFirst(mul);
1522 } else if (instr->representation().IsDouble()) {
1523 return DoArithmeticD(Token::MUL, instr);
1525 return DoArithmeticT(Token::MUL, instr);
1530 LInstruction* LChunkBuilder::DoSub(HSub* instr) {
1531 if (instr->representation().IsSmiOrInteger32()) {
1532 DCHECK(instr->left()->representation().Equals(instr->representation()));
1533 DCHECK(instr->right()->representation().Equals(instr->representation()));
1534 LOperand* left = UseRegisterAtStart(instr->left());
1535 LOperand* right = UseOrConstantAtStart(instr->right());
1536 LSubI* sub = new(zone()) LSubI(left, right);
1537 LInstruction* result = DefineSameAsFirst(sub);
1538 if (instr->CheckFlag(HValue::kCanOverflow)) {
1539 result = AssignEnvironment(result);
1542 } else if (instr->representation().IsDouble()) {
1543 return DoArithmeticD(Token::SUB, instr);
1545 return DoArithmeticT(Token::SUB, instr);
1550 LInstruction* LChunkBuilder::DoAdd(HAdd* instr) {
1551 if (instr->representation().IsSmiOrInteger32()) {
1552 // Check to see if it would be advantageous to use an lea instruction rather
1553 // than an add. This is the case when no overflow check is needed and there
1554 // are multiple uses of the add's inputs, so using a 3-register add will
1555 // preserve all input values for later uses.
1556 bool use_lea = LAddI::UseLea(instr);
1557 DCHECK(instr->left()->representation().Equals(instr->representation()));
1558 DCHECK(instr->right()->representation().Equals(instr->representation()));
1559 LOperand* left = UseRegisterAtStart(instr->BetterLeftOperand());
1560 HValue* right_candidate = instr->BetterRightOperand();
1562 if (SmiValuesAre32Bits() && instr->representation().IsSmi()) {
1563 // We cannot add a tagged immediate to a tagged value,
1564 // so we request it in a register.
1565 right = UseRegisterAtStart(right_candidate);
1567 right = use_lea ? UseRegisterOrConstantAtStart(right_candidate)
1568 : UseOrConstantAtStart(right_candidate);
1570 LAddI* add = new(zone()) LAddI(left, right);
1571 bool can_overflow = instr->CheckFlag(HValue::kCanOverflow);
1572 LInstruction* result = use_lea ? DefineAsRegister(add)
1573 : DefineSameAsFirst(add);
1575 result = AssignEnvironment(result);
1578 } else if (instr->representation().IsExternal()) {
1579 DCHECK(instr->left()->representation().IsExternal());
1580 DCHECK(instr->right()->representation().IsInteger32());
1581 DCHECK(!instr->CheckFlag(HValue::kCanOverflow));
1582 bool use_lea = LAddI::UseLea(instr);
1583 LOperand* left = UseRegisterAtStart(instr->left());
1584 HValue* right_candidate = instr->right();
1585 LOperand* right = use_lea
1586 ? UseRegisterOrConstantAtStart(right_candidate)
1587 : UseOrConstantAtStart(right_candidate);
1588 LAddI* add = new(zone()) LAddI(left, right);
1589 LInstruction* result = use_lea
1590 ? DefineAsRegister(add)
1591 : DefineSameAsFirst(add);
1593 } else if (instr->representation().IsDouble()) {
1594 return DoArithmeticD(Token::ADD, instr);
1596 return DoArithmeticT(Token::ADD, instr);
1602 LInstruction* LChunkBuilder::DoMathMinMax(HMathMinMax* instr) {
1603 LOperand* left = NULL;
1604 LOperand* right = NULL;
1605 DCHECK(instr->left()->representation().Equals(instr->representation()));
1606 DCHECK(instr->right()->representation().Equals(instr->representation()));
1607 if (instr->representation().IsSmi()) {
1608 left = UseRegisterAtStart(instr->BetterLeftOperand());
1609 right = UseAtStart(instr->BetterRightOperand());
1610 } else if (instr->representation().IsInteger32()) {
1611 left = UseRegisterAtStart(instr->BetterLeftOperand());
1612 right = UseOrConstantAtStart(instr->BetterRightOperand());
1614 DCHECK(instr->representation().IsDouble());
1615 left = UseRegisterAtStart(instr->left());
1616 right = UseRegisterAtStart(instr->right());
1618 LMathMinMax* minmax = new(zone()) LMathMinMax(left, right);
1619 return DefineSameAsFirst(minmax);
1623 LInstruction* LChunkBuilder::DoPower(HPower* instr) {
1624 DCHECK(instr->representation().IsDouble());
1625 // We call a C function for double power. It can't trigger a GC.
1626 // We need to use fixed result register for the call.
1627 Representation exponent_type = instr->right()->representation();
1628 DCHECK(instr->left()->representation().IsDouble());
1629 LOperand* left = UseFixedDouble(instr->left(), xmm2);
1631 exponent_type.IsDouble()
1632 ? UseFixedDouble(instr->right(), xmm1)
1633 : UseFixed(instr->right(), MathPowTaggedDescriptor::exponent());
1634 LPower* result = new(zone()) LPower(left, right);
1635 return MarkAsCall(DefineFixedDouble(result, xmm3), instr,
1636 CAN_DEOPTIMIZE_EAGERLY);
1640 LInstruction* LChunkBuilder::DoCompareGeneric(HCompareGeneric* instr) {
1641 DCHECK(instr->left()->representation().IsTagged());
1642 DCHECK(instr->right()->representation().IsTagged());
1643 LOperand* context = UseFixed(instr->context(), rsi);
1644 LOperand* left = UseFixed(instr->left(), rdx);
1645 LOperand* right = UseFixed(instr->right(), rax);
1646 LCmpT* result = new(zone()) LCmpT(context, left, right);
1647 return MarkAsCall(DefineFixed(result, rax), instr);
1651 LInstruction* LChunkBuilder::DoCompareNumericAndBranch(
1652 HCompareNumericAndBranch* instr) {
1653 Representation r = instr->representation();
1654 if (r.IsSmiOrInteger32()) {
1655 DCHECK(instr->left()->representation().Equals(r));
1656 DCHECK(instr->right()->representation().Equals(r));
1657 LOperand* left = UseRegisterOrConstantAtStart(instr->left());
1658 LOperand* right = UseOrConstantAtStart(instr->right());
1659 return new(zone()) LCompareNumericAndBranch(left, right);
1661 DCHECK(r.IsDouble());
1662 DCHECK(instr->left()->representation().IsDouble());
1663 DCHECK(instr->right()->representation().IsDouble());
1666 if (instr->left()->IsConstant() && instr->right()->IsConstant()) {
1667 left = UseRegisterOrConstantAtStart(instr->left());
1668 right = UseRegisterOrConstantAtStart(instr->right());
1670 left = UseRegisterAtStart(instr->left());
1671 right = UseRegisterAtStart(instr->right());
1673 return new(zone()) LCompareNumericAndBranch(left, right);
1678 LInstruction* LChunkBuilder::DoCompareObjectEqAndBranch(
1679 HCompareObjectEqAndBranch* instr) {
1680 LOperand* left = UseRegisterAtStart(instr->left());
1681 LOperand* right = UseRegisterOrConstantAtStart(instr->right());
1682 return new(zone()) LCmpObjectEqAndBranch(left, right);
1686 LInstruction* LChunkBuilder::DoCompareHoleAndBranch(
1687 HCompareHoleAndBranch* instr) {
1688 LOperand* value = UseRegisterAtStart(instr->value());
1689 return new(zone()) LCmpHoleAndBranch(value);
1693 LInstruction* LChunkBuilder::DoCompareMinusZeroAndBranch(
1694 HCompareMinusZeroAndBranch* instr) {
1695 LOperand* value = UseRegister(instr->value());
1696 return new(zone()) LCompareMinusZeroAndBranch(value);
1700 LInstruction* LChunkBuilder::DoIsObjectAndBranch(HIsObjectAndBranch* instr) {
1701 DCHECK(instr->value()->representation().IsTagged());
1702 return new(zone()) LIsObjectAndBranch(UseRegisterAtStart(instr->value()));
1706 LInstruction* LChunkBuilder::DoIsStringAndBranch(HIsStringAndBranch* instr) {
1707 DCHECK(instr->value()->representation().IsTagged());
1708 LOperand* value = UseRegisterAtStart(instr->value());
1709 LOperand* temp = TempRegister();
1710 return new(zone()) LIsStringAndBranch(value, temp);
1714 LInstruction* LChunkBuilder::DoIsSmiAndBranch(HIsSmiAndBranch* instr) {
1715 DCHECK(instr->value()->representation().IsTagged());
1716 return new(zone()) LIsSmiAndBranch(Use(instr->value()));
1720 LInstruction* LChunkBuilder::DoIsUndetectableAndBranch(
1721 HIsUndetectableAndBranch* instr) {
1722 DCHECK(instr->value()->representation().IsTagged());
1723 LOperand* value = UseRegisterAtStart(instr->value());
1724 LOperand* temp = TempRegister();
1725 return new(zone()) LIsUndetectableAndBranch(value, temp);
1729 LInstruction* LChunkBuilder::DoStringCompareAndBranch(
1730 HStringCompareAndBranch* instr) {
1732 DCHECK(instr->left()->representation().IsTagged());
1733 DCHECK(instr->right()->representation().IsTagged());
1734 LOperand* context = UseFixed(instr->context(), rsi);
1735 LOperand* left = UseFixed(instr->left(), rdx);
1736 LOperand* right = UseFixed(instr->right(), rax);
1737 LStringCompareAndBranch* result =
1738 new(zone()) LStringCompareAndBranch(context, left, right);
1740 return MarkAsCall(result, instr);
1744 LInstruction* LChunkBuilder::DoHasInstanceTypeAndBranch(
1745 HHasInstanceTypeAndBranch* instr) {
1746 DCHECK(instr->value()->representation().IsTagged());
1747 LOperand* value = UseRegisterAtStart(instr->value());
1748 return new(zone()) LHasInstanceTypeAndBranch(value);
1752 LInstruction* LChunkBuilder::DoGetCachedArrayIndex(
1753 HGetCachedArrayIndex* instr) {
1754 DCHECK(instr->value()->representation().IsTagged());
1755 LOperand* value = UseRegisterAtStart(instr->value());
1757 return DefineAsRegister(new(zone()) LGetCachedArrayIndex(value));
1761 LInstruction* LChunkBuilder::DoHasCachedArrayIndexAndBranch(
1762 HHasCachedArrayIndexAndBranch* instr) {
1763 DCHECK(instr->value()->representation().IsTagged());
1764 LOperand* value = UseRegisterAtStart(instr->value());
1765 return new(zone()) LHasCachedArrayIndexAndBranch(value);
1769 LInstruction* LChunkBuilder::DoClassOfTestAndBranch(
1770 HClassOfTestAndBranch* instr) {
1771 LOperand* value = UseRegister(instr->value());
1772 return new(zone()) LClassOfTestAndBranch(value,
1778 LInstruction* LChunkBuilder::DoMapEnumLength(HMapEnumLength* instr) {
1779 LOperand* map = UseRegisterAtStart(instr->value());
1780 return DefineAsRegister(new(zone()) LMapEnumLength(map));
1784 LInstruction* LChunkBuilder::DoDateField(HDateField* instr) {
1785 LOperand* object = UseFixed(instr->value(), rax);
1786 LDateField* result = new(zone()) LDateField(object, instr->index());
1787 return MarkAsCall(DefineFixed(result, rax), instr, CAN_DEOPTIMIZE_EAGERLY);
1791 LInstruction* LChunkBuilder::DoSeqStringGetChar(HSeqStringGetChar* instr) {
1792 LOperand* string = UseRegisterAtStart(instr->string());
1793 LOperand* index = UseRegisterOrConstantAtStart(instr->index());
1794 return DefineAsRegister(new(zone()) LSeqStringGetChar(string, index));
1798 LInstruction* LChunkBuilder::DoSeqStringSetChar(HSeqStringSetChar* instr) {
1799 LOperand* string = UseRegisterAtStart(instr->string());
1800 LOperand* index = FLAG_debug_code
1801 ? UseRegisterAtStart(instr->index())
1802 : UseRegisterOrConstantAtStart(instr->index());
1803 LOperand* value = FLAG_debug_code
1804 ? UseRegisterAtStart(instr->value())
1805 : UseRegisterOrConstantAtStart(instr->value());
1806 LOperand* context = FLAG_debug_code ? UseFixed(instr->context(), rsi) : NULL;
1807 LInstruction* result = new(zone()) LSeqStringSetChar(context, string,
1809 if (FLAG_debug_code) {
1810 result = MarkAsCall(result, instr);
1816 LInstruction* LChunkBuilder::DoBoundsCheck(HBoundsCheck* instr) {
1817 if (!FLAG_debug_code && instr->skip_check()) return NULL;
1818 LOperand* index = UseRegisterOrConstantAtStart(instr->index());
1819 LOperand* length = !index->IsConstantOperand()
1820 ? UseOrConstantAtStart(instr->length())
1821 : UseAtStart(instr->length());
1822 LInstruction* result = new(zone()) LBoundsCheck(index, length);
1823 if (!FLAG_debug_code || !instr->skip_check()) {
1824 result = AssignEnvironment(result);
1830 LInstruction* LChunkBuilder::DoBoundsCheckBaseIndexInformation(
1831 HBoundsCheckBaseIndexInformation* instr) {
1837 LInstruction* LChunkBuilder::DoAbnormalExit(HAbnormalExit* instr) {
1838 // The control instruction marking the end of a block that completed
1839 // abruptly (e.g., threw an exception). There is nothing specific to do.
1844 LInstruction* LChunkBuilder::DoUseConst(HUseConst* instr) {
1849 LInstruction* LChunkBuilder::DoForceRepresentation(HForceRepresentation* bad) {
1850 // All HForceRepresentation instructions should be eliminated in the
1851 // representation change phase of Hydrogen.
1857 LInstruction* LChunkBuilder::DoChange(HChange* instr) {
1858 Representation from = instr->from();
1859 Representation to = instr->to();
1860 HValue* val = instr->value();
1862 if (to.IsTagged()) {
1863 LOperand* value = UseRegister(val);
1864 return DefineSameAsFirst(new(zone()) LDummyUse(value));
1866 from = Representation::Tagged();
1868 if (from.IsTagged()) {
1869 if (to.IsDouble()) {
1870 LOperand* value = UseRegister(val);
1871 LInstruction* result = DefineAsRegister(new(zone()) LNumberUntagD(value));
1872 if (!val->representation().IsSmi()) result = AssignEnvironment(result);
1874 } else if (to.IsSmi()) {
1875 LOperand* value = UseRegister(val);
1876 if (val->type().IsSmi()) {
1877 return DefineSameAsFirst(new(zone()) LDummyUse(value));
1879 return AssignEnvironment(DefineSameAsFirst(new(zone()) LCheckSmi(value)));
1881 DCHECK(to.IsInteger32());
1882 if (val->type().IsSmi() || val->representation().IsSmi()) {
1883 LOperand* value = UseRegister(val);
1884 return DefineSameAsFirst(new(zone()) LSmiUntag(value, false));
1886 LOperand* value = UseRegister(val);
1887 bool truncating = instr->CanTruncateToInt32();
1888 LOperand* xmm_temp = truncating ? NULL : FixedTemp(xmm1);
1889 LInstruction* result =
1890 DefineSameAsFirst(new(zone()) LTaggedToI(value, xmm_temp));
1891 if (!val->representation().IsSmi()) result = AssignEnvironment(result);
1895 } else if (from.IsDouble()) {
1896 if (to.IsTagged()) {
1897 info()->MarkAsDeferredCalling();
1898 LOperand* value = UseRegister(val);
1899 LOperand* temp = TempRegister();
1900 LUnallocated* result_temp = TempRegister();
1901 LNumberTagD* result = new(zone()) LNumberTagD(value, temp);
1902 return AssignPointerMap(Define(result, result_temp));
1903 } else if (to.IsSmi()) {
1904 LOperand* value = UseRegister(val);
1905 return AssignEnvironment(
1906 DefineAsRegister(new(zone()) LDoubleToSmi(value)));
1908 DCHECK(to.IsInteger32());
1909 LOperand* value = UseRegister(val);
1910 LInstruction* result = DefineAsRegister(new(zone()) LDoubleToI(value));
1911 if (!instr->CanTruncateToInt32()) result = AssignEnvironment(result);
1914 } else if (from.IsInteger32()) {
1915 info()->MarkAsDeferredCalling();
1916 if (to.IsTagged()) {
1917 if (!instr->CheckFlag(HValue::kCanOverflow)) {
1918 LOperand* value = UseRegister(val);
1919 return DefineAsRegister(new(zone()) LSmiTag(value));
1920 } else if (val->CheckFlag(HInstruction::kUint32)) {
1921 LOperand* value = UseRegister(val);
1922 LOperand* temp1 = TempRegister();
1923 LOperand* temp2 = FixedTemp(xmm1);
1924 LNumberTagU* result = new(zone()) LNumberTagU(value, temp1, temp2);
1925 return AssignPointerMap(DefineSameAsFirst(result));
1927 LOperand* value = UseRegister(val);
1928 LOperand* temp1 = SmiValuesAre32Bits() ? NULL : TempRegister();
1929 LOperand* temp2 = SmiValuesAre32Bits() ? NULL : FixedTemp(xmm1);
1930 LNumberTagI* result = new(zone()) LNumberTagI(value, temp1, temp2);
1931 return AssignPointerMap(DefineSameAsFirst(result));
1933 } else if (to.IsSmi()) {
1934 LOperand* value = UseRegister(val);
1935 LInstruction* result = DefineAsRegister(new(zone()) LSmiTag(value));
1936 if (instr->CheckFlag(HValue::kCanOverflow)) {
1937 result = AssignEnvironment(result);
1941 DCHECK(to.IsDouble());
1942 if (val->CheckFlag(HInstruction::kUint32)) {
1943 return DefineAsRegister(new(zone()) LUint32ToDouble(UseRegister(val)));
1945 LOperand* value = Use(val);
1946 return DefineAsRegister(new(zone()) LInteger32ToDouble(value));
1955 LInstruction* LChunkBuilder::DoCheckHeapObject(HCheckHeapObject* instr) {
1956 LOperand* value = UseRegisterAtStart(instr->value());
1957 LInstruction* result = new(zone()) LCheckNonSmi(value);
1958 if (!instr->value()->type().IsHeapObject()) {
1959 result = AssignEnvironment(result);
1965 LInstruction* LChunkBuilder::DoCheckSmi(HCheckSmi* instr) {
1966 LOperand* value = UseRegisterAtStart(instr->value());
1967 return AssignEnvironment(new(zone()) LCheckSmi(value));
1971 LInstruction* LChunkBuilder::DoCheckInstanceType(HCheckInstanceType* instr) {
1972 LOperand* value = UseRegisterAtStart(instr->value());
1973 LCheckInstanceType* result = new(zone()) LCheckInstanceType(value);
1974 return AssignEnvironment(result);
1978 LInstruction* LChunkBuilder::DoCheckValue(HCheckValue* instr) {
1979 LOperand* value = UseRegisterAtStart(instr->value());
1980 return AssignEnvironment(new(zone()) LCheckValue(value));
1984 LInstruction* LChunkBuilder::DoCheckMaps(HCheckMaps* instr) {
1985 if (instr->IsStabilityCheck()) return new(zone()) LCheckMaps;
1986 LOperand* value = UseRegisterAtStart(instr->value());
1987 LInstruction* result = AssignEnvironment(new(zone()) LCheckMaps(value));
1988 if (instr->HasMigrationTarget()) {
1989 info()->MarkAsDeferredCalling();
1990 result = AssignPointerMap(result);
1996 LInstruction* LChunkBuilder::DoClampToUint8(HClampToUint8* instr) {
1997 HValue* value = instr->value();
1998 Representation input_rep = value->representation();
1999 LOperand* reg = UseRegister(value);
2000 if (input_rep.IsDouble()) {
2001 return DefineAsRegister(new(zone()) LClampDToUint8(reg));
2002 } else if (input_rep.IsInteger32()) {
2003 return DefineSameAsFirst(new(zone()) LClampIToUint8(reg));
2005 DCHECK(input_rep.IsSmiOrTagged());
2006 // Register allocator doesn't (yet) support allocation of double
2007 // temps. Reserve xmm1 explicitly.
2008 LClampTToUint8* result = new(zone()) LClampTToUint8(reg,
2010 return AssignEnvironment(DefineSameAsFirst(result));
2015 LInstruction* LChunkBuilder::DoDoubleBits(HDoubleBits* instr) {
2016 HValue* value = instr->value();
2017 DCHECK(value->representation().IsDouble());
2018 return DefineAsRegister(new(zone()) LDoubleBits(UseRegister(value)));
2022 LInstruction* LChunkBuilder::DoConstructDouble(HConstructDouble* instr) {
2023 LOperand* lo = UseRegister(instr->lo());
2024 LOperand* hi = UseRegister(instr->hi());
2025 return DefineAsRegister(new(zone()) LConstructDouble(hi, lo));
2029 LInstruction* LChunkBuilder::DoReturn(HReturn* instr) {
2030 LOperand* context = info()->IsStub() ? UseFixed(instr->context(), rsi) : NULL;
2031 LOperand* parameter_count = UseRegisterOrConstant(instr->parameter_count());
2032 return new(zone()) LReturn(
2033 UseFixed(instr->value(), rax), context, parameter_count);
2037 LInstruction* LChunkBuilder::DoConstant(HConstant* instr) {
2038 Representation r = instr->representation();
2040 return DefineAsRegister(new(zone()) LConstantS);
2041 } else if (r.IsInteger32()) {
2042 return DefineAsRegister(new(zone()) LConstantI);
2043 } else if (r.IsDouble()) {
2044 LOperand* temp = TempRegister();
2045 return DefineAsRegister(new(zone()) LConstantD(temp));
2046 } else if (r.IsExternal()) {
2047 return DefineAsRegister(new(zone()) LConstantE);
2048 } else if (r.IsTagged()) {
2049 return DefineAsRegister(new(zone()) LConstantT);
2057 LInstruction* LChunkBuilder::DoLoadGlobalCell(HLoadGlobalCell* instr) {
2058 LLoadGlobalCell* result = new(zone()) LLoadGlobalCell;
2059 return instr->RequiresHoleCheck()
2060 ? AssignEnvironment(DefineAsRegister(result))
2061 : DefineAsRegister(result);
2065 LInstruction* LChunkBuilder::DoLoadGlobalGeneric(HLoadGlobalGeneric* instr) {
2066 LOperand* context = UseFixed(instr->context(), rsi);
2067 LOperand* global_object =
2068 UseFixed(instr->global_object(), LoadDescriptor::ReceiverRegister());
2069 LOperand* vector = NULL;
2070 if (FLAG_vector_ics) {
2071 vector = FixedTemp(VectorLoadICDescriptor::VectorRegister());
2074 LLoadGlobalGeneric* result =
2075 new(zone()) LLoadGlobalGeneric(context, global_object, vector);
2076 return MarkAsCall(DefineFixed(result, rax), instr);
2080 LInstruction* LChunkBuilder::DoStoreGlobalCell(HStoreGlobalCell* instr) {
2081 LOperand* value = UseRegister(instr->value());
2082 // Use a temp to avoid reloading the cell value address in the case where
2083 // we perform a hole check.
2084 return instr->RequiresHoleCheck()
2085 ? AssignEnvironment(new(zone()) LStoreGlobalCell(value, TempRegister()))
2086 : new(zone()) LStoreGlobalCell(value, NULL);
2090 LInstruction* LChunkBuilder::DoLoadContextSlot(HLoadContextSlot* instr) {
2091 LOperand* context = UseRegisterAtStart(instr->value());
2092 LInstruction* result =
2093 DefineAsRegister(new(zone()) LLoadContextSlot(context));
2094 if (instr->RequiresHoleCheck() && instr->DeoptimizesOnHole()) {
2095 result = AssignEnvironment(result);
2101 LInstruction* LChunkBuilder::DoStoreContextSlot(HStoreContextSlot* instr) {
2105 context = UseRegister(instr->context());
2106 if (instr->NeedsWriteBarrier()) {
2107 value = UseTempRegister(instr->value());
2108 temp = TempRegister();
2110 value = UseRegister(instr->value());
2113 LInstruction* result = new(zone()) LStoreContextSlot(context, value, temp);
2114 if (instr->RequiresHoleCheck() && instr->DeoptimizesOnHole()) {
2115 result = AssignEnvironment(result);
2121 LInstruction* LChunkBuilder::DoLoadNamedField(HLoadNamedField* instr) {
2122 // Use the special mov rax, moffs64 encoding for external
2123 // memory accesses with 64-bit word-sized values.
2124 if (instr->access().IsExternalMemory() &&
2125 instr->access().offset() == 0 &&
2126 (instr->access().representation().IsSmi() ||
2127 instr->access().representation().IsTagged() ||
2128 instr->access().representation().IsHeapObject() ||
2129 instr->access().representation().IsExternal())) {
2130 LOperand* obj = UseRegisterOrConstantAtStart(instr->object());
2131 return DefineFixed(new(zone()) LLoadNamedField(obj), rax);
2133 LOperand* obj = UseRegisterAtStart(instr->object());
2134 return DefineAsRegister(new(zone()) LLoadNamedField(obj));
2138 LInstruction* LChunkBuilder::DoLoadNamedGeneric(HLoadNamedGeneric* instr) {
2139 LOperand* context = UseFixed(instr->context(), rsi);
2141 UseFixed(instr->object(), LoadDescriptor::ReceiverRegister());
2142 LOperand* vector = NULL;
2143 if (FLAG_vector_ics) {
2144 vector = FixedTemp(VectorLoadICDescriptor::VectorRegister());
2146 LLoadNamedGeneric* result = new(zone()) LLoadNamedGeneric(
2147 context, object, vector);
2148 return MarkAsCall(DefineFixed(result, rax), instr);
2152 LInstruction* LChunkBuilder::DoLoadFunctionPrototype(
2153 HLoadFunctionPrototype* instr) {
2154 return AssignEnvironment(DefineAsRegister(
2155 new(zone()) LLoadFunctionPrototype(UseRegister(instr->function()))));
2159 LInstruction* LChunkBuilder::DoLoadRoot(HLoadRoot* instr) {
2160 return DefineAsRegister(new(zone()) LLoadRoot);
2164 void LChunkBuilder::FindDehoistedKeyDefinitions(HValue* candidate) {
2165 // We sign extend the dehoisted key at the definition point when the pointer
2166 // size is 64-bit. For x32 port, we sign extend the dehoisted key at the use
2167 // points and should not invoke this function. We can't use STATIC_ASSERT
2168 // here as the pointer size is 32-bit for x32.
2169 DCHECK(kPointerSize == kInt64Size);
2170 BitVector* dehoisted_key_ids = chunk_->GetDehoistedKeyIds();
2171 if (dehoisted_key_ids->Contains(candidate->id())) return;
2172 dehoisted_key_ids->Add(candidate->id());
2173 if (!candidate->IsPhi()) return;
2174 for (int i = 0; i < candidate->OperandCount(); ++i) {
2175 FindDehoistedKeyDefinitions(candidate->OperandAt(i));
2180 LInstruction* LChunkBuilder::DoLoadKeyed(HLoadKeyed* instr) {
2181 DCHECK((kPointerSize == kInt64Size &&
2182 instr->key()->representation().IsInteger32()) ||
2183 (kPointerSize == kInt32Size &&
2184 instr->key()->representation().IsSmiOrInteger32()));
2185 ElementsKind elements_kind = instr->elements_kind();
2186 LOperand* key = NULL;
2187 LInstruction* result = NULL;
2189 if (kPointerSize == kInt64Size) {
2190 key = UseRegisterOrConstantAtStart(instr->key());
2192 bool clobbers_key = ExternalArrayOpRequiresTemp(
2193 instr->key()->representation(), elements_kind);
2195 ? UseTempRegister(instr->key())
2196 : UseRegisterOrConstantAtStart(instr->key());
2199 if ((kPointerSize == kInt64Size) && instr->IsDehoisted()) {
2200 FindDehoistedKeyDefinitions(instr->key());
2203 if (!instr->is_typed_elements()) {
2204 LOperand* obj = UseRegisterAtStart(instr->elements());
2205 result = DefineAsRegister(new(zone()) LLoadKeyed(obj, key));
2208 (instr->representation().IsInteger32() &&
2209 !(IsDoubleOrFloatElementsKind(elements_kind))) ||
2210 (instr->representation().IsDouble() &&
2211 (IsDoubleOrFloatElementsKind(elements_kind))));
2212 LOperand* backing_store = UseRegister(instr->elements());
2213 result = DefineAsRegister(new(zone()) LLoadKeyed(backing_store, key));
2216 if ((instr->is_external() || instr->is_fixed_typed_array()) ?
2217 // see LCodeGen::DoLoadKeyedExternalArray
2218 ((elements_kind == EXTERNAL_UINT32_ELEMENTS ||
2219 elements_kind == UINT32_ELEMENTS) &&
2220 !instr->CheckFlag(HInstruction::kUint32)) :
2221 // see LCodeGen::DoLoadKeyedFixedDoubleArray and
2222 // LCodeGen::DoLoadKeyedFixedArray
2223 instr->RequiresHoleCheck()) {
2224 result = AssignEnvironment(result);
2230 LInstruction* LChunkBuilder::DoLoadKeyedGeneric(HLoadKeyedGeneric* instr) {
2231 LOperand* context = UseFixed(instr->context(), rsi);
2233 UseFixed(instr->object(), LoadDescriptor::ReceiverRegister());
2234 LOperand* key = UseFixed(instr->key(), LoadDescriptor::NameRegister());
2235 LOperand* vector = NULL;
2236 if (FLAG_vector_ics) {
2237 vector = FixedTemp(VectorLoadICDescriptor::VectorRegister());
2240 LLoadKeyedGeneric* result =
2241 new(zone()) LLoadKeyedGeneric(context, object, key, vector);
2242 return MarkAsCall(DefineFixed(result, rax), instr);
2246 LInstruction* LChunkBuilder::DoStoreKeyed(HStoreKeyed* instr) {
2247 ElementsKind elements_kind = instr->elements_kind();
2249 if ((kPointerSize == kInt64Size) && instr->IsDehoisted()) {
2250 FindDehoistedKeyDefinitions(instr->key());
2253 if (!instr->is_typed_elements()) {
2254 DCHECK(instr->elements()->representation().IsTagged());
2255 bool needs_write_barrier = instr->NeedsWriteBarrier();
2256 LOperand* object = NULL;
2257 LOperand* key = NULL;
2258 LOperand* val = NULL;
2260 Representation value_representation = instr->value()->representation();
2261 if (value_representation.IsDouble()) {
2262 object = UseRegisterAtStart(instr->elements());
2263 val = UseRegisterAtStart(instr->value());
2264 key = UseRegisterOrConstantAtStart(instr->key());
2266 DCHECK(value_representation.IsSmiOrTagged() ||
2267 value_representation.IsInteger32());
2268 if (needs_write_barrier) {
2269 object = UseTempRegister(instr->elements());
2270 val = UseTempRegister(instr->value());
2271 key = UseTempRegister(instr->key());
2273 object = UseRegisterAtStart(instr->elements());
2274 val = UseRegisterOrConstantAtStart(instr->value());
2275 key = UseRegisterOrConstantAtStart(instr->key());
2279 return new(zone()) LStoreKeyed(object, key, val);
2283 (instr->value()->representation().IsInteger32() &&
2284 !IsDoubleOrFloatElementsKind(elements_kind)) ||
2285 (instr->value()->representation().IsDouble() &&
2286 IsDoubleOrFloatElementsKind(elements_kind)));
2287 DCHECK((instr->is_fixed_typed_array() &&
2288 instr->elements()->representation().IsTagged()) ||
2289 (instr->is_external() &&
2290 instr->elements()->representation().IsExternal()));
2291 bool val_is_temp_register =
2292 elements_kind == EXTERNAL_UINT8_CLAMPED_ELEMENTS ||
2293 elements_kind == EXTERNAL_FLOAT32_ELEMENTS ||
2294 elements_kind == FLOAT32_ELEMENTS;
2295 LOperand* val = val_is_temp_register ? UseTempRegister(instr->value())
2296 : UseRegister(instr->value());
2297 LOperand* key = NULL;
2298 if (kPointerSize == kInt64Size) {
2299 key = UseRegisterOrConstantAtStart(instr->key());
2301 bool clobbers_key = ExternalArrayOpRequiresTemp(
2302 instr->key()->representation(), elements_kind);
2304 ? UseTempRegister(instr->key())
2305 : UseRegisterOrConstantAtStart(instr->key());
2307 LOperand* backing_store = UseRegister(instr->elements());
2308 return new(zone()) LStoreKeyed(backing_store, key, val);
2312 LInstruction* LChunkBuilder::DoStoreKeyedGeneric(HStoreKeyedGeneric* instr) {
2313 LOperand* context = UseFixed(instr->context(), rsi);
2315 UseFixed(instr->object(), StoreDescriptor::ReceiverRegister());
2316 LOperand* key = UseFixed(instr->key(), StoreDescriptor::NameRegister());
2317 LOperand* value = UseFixed(instr->value(), StoreDescriptor::ValueRegister());
2319 DCHECK(instr->object()->representation().IsTagged());
2320 DCHECK(instr->key()->representation().IsTagged());
2321 DCHECK(instr->value()->representation().IsTagged());
2323 LStoreKeyedGeneric* result =
2324 new(zone()) LStoreKeyedGeneric(context, object, key, value);
2325 return MarkAsCall(result, instr);
2329 LInstruction* LChunkBuilder::DoTransitionElementsKind(
2330 HTransitionElementsKind* instr) {
2331 if (IsSimpleMapChangeTransition(instr->from_kind(), instr->to_kind())) {
2332 LOperand* object = UseRegister(instr->object());
2333 LOperand* new_map_reg = TempRegister();
2334 LOperand* temp_reg = TempRegister();
2335 LTransitionElementsKind* result = new(zone()) LTransitionElementsKind(
2336 object, NULL, new_map_reg, temp_reg);
2339 LOperand* object = UseFixed(instr->object(), rax);
2340 LOperand* context = UseFixed(instr->context(), rsi);
2341 LTransitionElementsKind* result =
2342 new(zone()) LTransitionElementsKind(object, context, NULL, NULL);
2343 return MarkAsCall(result, instr);
2348 LInstruction* LChunkBuilder::DoTrapAllocationMemento(
2349 HTrapAllocationMemento* instr) {
2350 LOperand* object = UseRegister(instr->object());
2351 LOperand* temp = TempRegister();
2352 LTrapAllocationMemento* result =
2353 new(zone()) LTrapAllocationMemento(object, temp);
2354 return AssignEnvironment(result);
2358 LInstruction* LChunkBuilder::DoStoreNamedField(HStoreNamedField* instr) {
2359 bool is_in_object = instr->access().IsInobject();
2360 bool is_external_location = instr->access().IsExternalMemory() &&
2361 instr->access().offset() == 0;
2362 bool needs_write_barrier = instr->NeedsWriteBarrier();
2363 bool needs_write_barrier_for_map = instr->has_transition() &&
2364 instr->NeedsWriteBarrierForMap();
2367 if (needs_write_barrier) {
2369 ? UseRegister(instr->object())
2370 : UseTempRegister(instr->object());
2371 } else if (is_external_location) {
2372 DCHECK(!is_in_object);
2373 DCHECK(!needs_write_barrier);
2374 DCHECK(!needs_write_barrier_for_map);
2375 obj = UseRegisterOrConstant(instr->object());
2377 obj = needs_write_barrier_for_map
2378 ? UseRegister(instr->object())
2379 : UseRegisterAtStart(instr->object());
2382 bool can_be_constant = instr->value()->IsConstant() &&
2383 HConstant::cast(instr->value())->NotInNewSpace() &&
2384 !instr->field_representation().IsDouble();
2387 if (needs_write_barrier) {
2388 val = UseTempRegister(instr->value());
2389 } else if (is_external_location) {
2390 val = UseFixed(instr->value(), rax);
2391 } else if (can_be_constant) {
2392 val = UseRegisterOrConstant(instr->value());
2393 } else if (instr->field_representation().IsDouble()) {
2394 val = UseRegisterAtStart(instr->value());
2396 val = UseRegister(instr->value());
2399 // We only need a scratch register if we have a write barrier or we
2400 // have a store into the properties array (not in-object-property).
2401 LOperand* temp = (!is_in_object || needs_write_barrier ||
2402 needs_write_barrier_for_map) ? TempRegister() : NULL;
2404 return new(zone()) LStoreNamedField(obj, val, temp);
2408 LInstruction* LChunkBuilder::DoStoreNamedGeneric(HStoreNamedGeneric* instr) {
2409 LOperand* context = UseFixed(instr->context(), rsi);
2411 UseFixed(instr->object(), StoreDescriptor::ReceiverRegister());
2412 LOperand* value = UseFixed(instr->value(), StoreDescriptor::ValueRegister());
2414 LStoreNamedGeneric* result =
2415 new(zone()) LStoreNamedGeneric(context, object, value);
2416 return MarkAsCall(result, instr);
2420 LInstruction* LChunkBuilder::DoStringAdd(HStringAdd* instr) {
2421 LOperand* context = UseFixed(instr->context(), rsi);
2422 LOperand* left = UseFixed(instr->left(), rdx);
2423 LOperand* right = UseFixed(instr->right(), rax);
2425 DefineFixed(new(zone()) LStringAdd(context, left, right), rax), instr);
2429 LInstruction* LChunkBuilder::DoStringCharCodeAt(HStringCharCodeAt* instr) {
2430 LOperand* string = UseTempRegister(instr->string());
2431 LOperand* index = UseTempRegister(instr->index());
2432 LOperand* context = UseAny(instr->context());
2433 LStringCharCodeAt* result =
2434 new(zone()) LStringCharCodeAt(context, string, index);
2435 return AssignPointerMap(DefineAsRegister(result));
2439 LInstruction* LChunkBuilder::DoStringCharFromCode(HStringCharFromCode* instr) {
2440 LOperand* char_code = UseRegister(instr->value());
2441 LOperand* context = UseAny(instr->context());
2442 LStringCharFromCode* result =
2443 new(zone()) LStringCharFromCode(context, char_code);
2444 return AssignPointerMap(DefineAsRegister(result));
2448 LInstruction* LChunkBuilder::DoAllocate(HAllocate* instr) {
2449 info()->MarkAsDeferredCalling();
2450 LOperand* context = UseAny(instr->context());
2451 LOperand* size = instr->size()->IsConstant()
2452 ? UseConstant(instr->size())
2453 : UseTempRegister(instr->size());
2454 LOperand* temp = TempRegister();
2455 LAllocate* result = new(zone()) LAllocate(context, size, temp);
2456 return AssignPointerMap(DefineAsRegister(result));
2460 LInstruction* LChunkBuilder::DoRegExpLiteral(HRegExpLiteral* instr) {
2461 LOperand* context = UseFixed(instr->context(), rsi);
2462 LRegExpLiteral* result = new(zone()) LRegExpLiteral(context);
2463 return MarkAsCall(DefineFixed(result, rax), instr);
2467 LInstruction* LChunkBuilder::DoFunctionLiteral(HFunctionLiteral* instr) {
2468 LOperand* context = UseFixed(instr->context(), rsi);
2469 LFunctionLiteral* result = new(zone()) LFunctionLiteral(context);
2470 return MarkAsCall(DefineFixed(result, rax), instr);
2474 LInstruction* LChunkBuilder::DoOsrEntry(HOsrEntry* instr) {
2475 DCHECK(argument_count_ == 0);
2476 allocator_->MarkAsOsrEntry();
2477 current_block_->last_environment()->set_ast_id(instr->ast_id());
2478 return AssignEnvironment(new(zone()) LOsrEntry);
2482 LInstruction* LChunkBuilder::DoParameter(HParameter* instr) {
2483 LParameter* result = new(zone()) LParameter;
2484 if (instr->kind() == HParameter::STACK_PARAMETER) {
2485 int spill_index = chunk()->GetParameterStackSlot(instr->index());
2486 return DefineAsSpilled(result, spill_index);
2488 DCHECK(info()->IsStub());
2489 CallInterfaceDescriptor descriptor =
2490 info()->code_stub()->GetCallInterfaceDescriptor();
2491 int index = static_cast<int>(instr->index());
2492 Register reg = descriptor.GetEnvironmentParameterRegister(index);
2493 return DefineFixed(result, reg);
2498 LInstruction* LChunkBuilder::DoUnknownOSRValue(HUnknownOSRValue* instr) {
2499 // Use an index that corresponds to the location in the unoptimized frame,
2500 // which the optimized frame will subsume.
2501 int env_index = instr->index();
2502 int spill_index = 0;
2503 if (instr->environment()->is_parameter_index(env_index)) {
2504 spill_index = chunk()->GetParameterStackSlot(env_index);
2506 spill_index = env_index - instr->environment()->first_local_index();
2507 if (spill_index > LUnallocated::kMaxFixedSlotIndex) {
2508 Retry(kTooManySpillSlotsNeededForOSR);
2512 return DefineAsSpilled(new(zone()) LUnknownOSRValue, spill_index);
2516 LInstruction* LChunkBuilder::DoCallStub(HCallStub* instr) {
2517 LOperand* context = UseFixed(instr->context(), rsi);
2518 LCallStub* result = new(zone()) LCallStub(context);
2519 return MarkAsCall(DefineFixed(result, rax), instr);
2523 LInstruction* LChunkBuilder::DoArgumentsObject(HArgumentsObject* instr) {
2524 // There are no real uses of the arguments object.
2525 // arguments.length and element access are supported directly on
2526 // stack arguments, and any real arguments object use causes a bailout.
2527 // So this value is never used.
2532 LInstruction* LChunkBuilder::DoCapturedObject(HCapturedObject* instr) {
2533 instr->ReplayEnvironment(current_block_->last_environment());
2535 // There are no real uses of a captured object.
2540 LInstruction* LChunkBuilder::DoAccessArgumentsAt(HAccessArgumentsAt* instr) {
2541 info()->MarkAsRequiresFrame();
2542 LOperand* args = UseRegister(instr->arguments());
2545 if (instr->length()->IsConstant() && instr->index()->IsConstant()) {
2546 length = UseRegisterOrConstant(instr->length());
2547 index = UseOrConstant(instr->index());
2549 length = UseTempRegister(instr->length());
2550 index = Use(instr->index());
2552 return DefineAsRegister(new(zone()) LAccessArgumentsAt(args, length, index));
2556 LInstruction* LChunkBuilder::DoToFastProperties(HToFastProperties* instr) {
2557 LOperand* object = UseFixed(instr->value(), rax);
2558 LToFastProperties* result = new(zone()) LToFastProperties(object);
2559 return MarkAsCall(DefineFixed(result, rax), instr);
2563 LInstruction* LChunkBuilder::DoTypeof(HTypeof* instr) {
2564 LOperand* context = UseFixed(instr->context(), rsi);
2565 LOperand* value = UseAtStart(instr->value());
2566 LTypeof* result = new(zone()) LTypeof(context, value);
2567 return MarkAsCall(DefineFixed(result, rax), instr);
2571 LInstruction* LChunkBuilder::DoTypeofIsAndBranch(HTypeofIsAndBranch* instr) {
2572 return new(zone()) LTypeofIsAndBranch(UseTempRegister(instr->value()));
2576 LInstruction* LChunkBuilder::DoIsConstructCallAndBranch(
2577 HIsConstructCallAndBranch* instr) {
2578 return new(zone()) LIsConstructCallAndBranch(TempRegister());
2582 LInstruction* LChunkBuilder::DoSimulate(HSimulate* instr) {
2583 instr->ReplayEnvironment(current_block_->last_environment());
2588 LInstruction* LChunkBuilder::DoStackCheck(HStackCheck* instr) {
2589 info()->MarkAsDeferredCalling();
2590 if (instr->is_function_entry()) {
2591 LOperand* context = UseFixed(instr->context(), rsi);
2592 return MarkAsCall(new(zone()) LStackCheck(context), instr);
2594 DCHECK(instr->is_backwards_branch());
2595 LOperand* context = UseAny(instr->context());
2596 return AssignEnvironment(
2597 AssignPointerMap(new(zone()) LStackCheck(context)));
2602 LInstruction* LChunkBuilder::DoEnterInlined(HEnterInlined* instr) {
2603 HEnvironment* outer = current_block_->last_environment();
2604 outer->set_ast_id(instr->ReturnId());
2605 HConstant* undefined = graph()->GetConstantUndefined();
2606 HEnvironment* inner = outer->CopyForInlining(instr->closure(),
2607 instr->arguments_count(),
2610 instr->inlining_kind());
2611 // Only replay binding of arguments object if it wasn't removed from graph.
2612 if (instr->arguments_var() != NULL && instr->arguments_object()->IsLinked()) {
2613 inner->Bind(instr->arguments_var(), instr->arguments_object());
2615 inner->BindContext(instr->closure_context());
2616 inner->set_entry(instr);
2617 current_block_->UpdateEnvironment(inner);
2618 chunk_->AddInlinedClosure(instr->closure());
2623 LInstruction* LChunkBuilder::DoLeaveInlined(HLeaveInlined* instr) {
2624 LInstruction* pop = NULL;
2626 HEnvironment* env = current_block_->last_environment();
2628 if (env->entry()->arguments_pushed()) {
2629 int argument_count = env->arguments_environment()->parameter_count();
2630 pop = new(zone()) LDrop(argument_count);
2631 DCHECK(instr->argument_delta() == -argument_count);
2634 HEnvironment* outer = current_block_->last_environment()->
2635 DiscardInlined(false);
2636 current_block_->UpdateEnvironment(outer);
2642 LInstruction* LChunkBuilder::DoForInPrepareMap(HForInPrepareMap* instr) {
2643 LOperand* context = UseFixed(instr->context(), rsi);
2644 LOperand* object = UseFixed(instr->enumerable(), rax);
2645 LForInPrepareMap* result = new(zone()) LForInPrepareMap(context, object);
2646 return MarkAsCall(DefineFixed(result, rax), instr, CAN_DEOPTIMIZE_EAGERLY);
2650 LInstruction* LChunkBuilder::DoForInCacheArray(HForInCacheArray* instr) {
2651 LOperand* map = UseRegister(instr->map());
2652 return AssignEnvironment(DefineAsRegister(
2653 new(zone()) LForInCacheArray(map)));
2657 LInstruction* LChunkBuilder::DoCheckMapValue(HCheckMapValue* instr) {
2658 LOperand* value = UseRegisterAtStart(instr->value());
2659 LOperand* map = UseRegisterAtStart(instr->map());
2660 return AssignEnvironment(new(zone()) LCheckMapValue(value, map));
2664 LInstruction* LChunkBuilder::DoLoadFieldByIndex(HLoadFieldByIndex* instr) {
2665 LOperand* object = UseRegister(instr->object());
2666 LOperand* index = UseTempRegister(instr->index());
2667 LLoadFieldByIndex* load = new(zone()) LLoadFieldByIndex(object, index);
2668 LInstruction* result = DefineSameAsFirst(load);
2669 return AssignPointerMap(result);
2673 LInstruction* LChunkBuilder::DoStoreFrameContext(HStoreFrameContext* instr) {
2674 LOperand* context = UseRegisterAtStart(instr->context());
2675 return new(zone()) LStoreFrameContext(context);
2679 LInstruction* LChunkBuilder::DoAllocateBlockContext(
2680 HAllocateBlockContext* instr) {
2681 LOperand* context = UseFixed(instr->context(), rsi);
2682 LOperand* function = UseRegisterAtStart(instr->function());
2683 LAllocateBlockContext* result =
2684 new(zone()) LAllocateBlockContext(context, function);
2685 return MarkAsCall(DefineFixed(result, rsi), instr);
2689 } } // namespace v8::internal
2691 #endif // V8_TARGET_ARCH_X64