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 LCallFunction::PrintDataTo(StringStream* stream) {
272 context()->PrintTo(stream);
274 function()->PrintTo(stream);
275 if (hydrogen()->HasVectorAndSlot()) {
276 stream->Add(" (type-feedback-vector ");
277 temp_vector()->PrintTo(stream);
279 temp_slot()->PrintTo(stream);
285 void LCallJSFunction::PrintDataTo(StringStream* stream) {
287 function()->PrintTo(stream);
288 stream->Add("#%d / ", arity());
292 void LCallWithDescriptor::PrintDataTo(StringStream* stream) {
293 for (int i = 0; i < InputCount(); i++) {
294 InputAt(i)->PrintTo(stream);
297 stream->Add("#%d / ", arity());
301 void LLoadContextSlot::PrintDataTo(StringStream* stream) {
302 context()->PrintTo(stream);
303 stream->Add("[%d]", slot_index());
307 void LStoreContextSlot::PrintDataTo(StringStream* stream) {
308 context()->PrintTo(stream);
309 stream->Add("[%d] <- ", slot_index());
310 value()->PrintTo(stream);
314 void LInvokeFunction::PrintDataTo(StringStream* stream) {
316 function()->PrintTo(stream);
317 stream->Add(" #%d / ", arity());
321 void LCallNew::PrintDataTo(StringStream* stream) {
323 constructor()->PrintTo(stream);
324 stream->Add(" #%d / ", arity());
328 void LCallNewArray::PrintDataTo(StringStream* stream) {
330 constructor()->PrintTo(stream);
331 stream->Add(" #%d / ", arity());
332 ElementsKind kind = hydrogen()->elements_kind();
333 stream->Add(" (%s) ", ElementsKindToString(kind));
337 void LAccessArgumentsAt::PrintDataTo(StringStream* stream) {
338 arguments()->PrintTo(stream);
340 stream->Add(" length ");
341 length()->PrintTo(stream);
343 stream->Add(" index ");
344 index()->PrintTo(stream);
348 int LPlatformChunk::GetNextSpillIndex(RegisterKind kind) {
349 if (kind == DOUBLE_REGISTERS && kDoubleSize == 2 * kPointerSize) {
350 // Skip a slot if for a double-width slot for x32 port.
352 // The spill slot's address is at rbp - (index + 1) * kPointerSize -
353 // StandardFrameConstants::kFixedFrameSizeFromFp. kFixedFrameSizeFromFp is
354 // 2 * kPointerSize, if rbp is aligned at 8-byte boundary, the below "|= 1"
355 // will make sure the spilled doubles are aligned at 8-byte boundary.
356 // TODO(haitao): make sure rbp is aligned at 8-byte boundary for x32 port.
357 spill_slot_count_ |= 1;
359 return spill_slot_count_++;
363 LOperand* LPlatformChunk::GetNextSpillSlot(RegisterKind kind) {
364 // All stack slots are Double stack slots on x64.
365 // Alternatively, at some point, start using half-size
366 // stack slots for int32 values.
367 int index = GetNextSpillIndex(kind);
368 if (kind == DOUBLE_REGISTERS) {
369 return LDoubleStackSlot::Create(index, zone());
371 DCHECK(kind == GENERAL_REGISTERS);
372 return LStackSlot::Create(index, zone());
377 void LStoreNamedField::PrintDataTo(StringStream* stream) {
378 object()->PrintTo(stream);
379 std::ostringstream os;
380 os << hydrogen()->access() << " <- ";
381 stream->Add(os.str().c_str());
382 value()->PrintTo(stream);
386 void LStoreNamedGeneric::PrintDataTo(StringStream* stream) {
387 object()->PrintTo(stream);
389 stream->Add(String::cast(*name())->ToCString().get());
391 value()->PrintTo(stream);
395 void LLoadKeyed::PrintDataTo(StringStream* stream) {
396 elements()->PrintTo(stream);
398 key()->PrintTo(stream);
399 if (hydrogen()->IsDehoisted()) {
400 stream->Add(" + %d]", base_offset());
407 void LStoreKeyed::PrintDataTo(StringStream* stream) {
408 elements()->PrintTo(stream);
410 key()->PrintTo(stream);
411 if (hydrogen()->IsDehoisted()) {
412 stream->Add(" + %d] <-", base_offset());
414 stream->Add("] <- ");
417 if (value() == NULL) {
418 DCHECK(hydrogen()->IsConstantHoleStore() &&
419 hydrogen()->value()->representation().IsDouble());
420 stream->Add("<the hole(nan)>");
422 value()->PrintTo(stream);
427 void LStoreKeyedGeneric::PrintDataTo(StringStream* stream) {
428 object()->PrintTo(stream);
430 key()->PrintTo(stream);
431 stream->Add("] <- ");
432 value()->PrintTo(stream);
436 void LTransitionElementsKind::PrintDataTo(StringStream* stream) {
437 object()->PrintTo(stream);
438 stream->Add(" %p -> %p", *original_map(), *transitioned_map());
442 LPlatformChunk* LChunkBuilder::Build() {
444 chunk_ = new(zone()) LPlatformChunk(info(), graph());
445 LPhase phase("L_Building chunk", chunk_);
448 // If compiling for OSR, reserve space for the unoptimized frame,
449 // which will be subsumed into this frame.
450 if (graph()->has_osr()) {
451 for (int i = graph()->osr()->UnoptimizedFrameSlots(); i > 0; i--) {
452 chunk_->GetNextSpillIndex(GENERAL_REGISTERS);
456 const ZoneList<HBasicBlock*>* blocks = graph()->blocks();
457 for (int i = 0; i < blocks->length(); i++) {
458 HBasicBlock* next = NULL;
459 if (i < blocks->length() - 1) next = blocks->at(i + 1);
460 DoBasicBlock(blocks->at(i), next);
461 if (is_aborted()) return NULL;
468 LUnallocated* LChunkBuilder::ToUnallocated(Register reg) {
469 return new(zone()) LUnallocated(LUnallocated::FIXED_REGISTER,
470 Register::ToAllocationIndex(reg));
474 LUnallocated* LChunkBuilder::ToUnallocated(XMMRegister reg) {
475 return new(zone()) LUnallocated(LUnallocated::FIXED_DOUBLE_REGISTER,
476 XMMRegister::ToAllocationIndex(reg));
480 LOperand* LChunkBuilder::UseFixed(HValue* value, Register fixed_register) {
481 return Use(value, ToUnallocated(fixed_register));
485 LOperand* LChunkBuilder::UseFixedDouble(HValue* value, XMMRegister reg) {
486 return Use(value, ToUnallocated(reg));
490 LOperand* LChunkBuilder::UseRegister(HValue* value) {
491 return Use(value, new(zone()) LUnallocated(LUnallocated::MUST_HAVE_REGISTER));
495 LOperand* LChunkBuilder::UseRegisterAtStart(HValue* value) {
497 new(zone()) LUnallocated(LUnallocated::MUST_HAVE_REGISTER,
498 LUnallocated::USED_AT_START));
502 LOperand* LChunkBuilder::UseTempRegister(HValue* value) {
503 return Use(value, new(zone()) LUnallocated(LUnallocated::WRITABLE_REGISTER));
507 LOperand* LChunkBuilder::UseTempRegisterOrConstant(HValue* value) {
508 return value->IsConstant()
509 ? chunk_->DefineConstantOperand(HConstant::cast(value))
510 : UseTempRegister(value);
514 LOperand* LChunkBuilder::Use(HValue* value) {
515 return Use(value, new(zone()) LUnallocated(LUnallocated::NONE));
519 LOperand* LChunkBuilder::UseAtStart(HValue* value) {
520 return Use(value, new(zone()) LUnallocated(LUnallocated::NONE,
521 LUnallocated::USED_AT_START));
525 LOperand* LChunkBuilder::UseOrConstant(HValue* value) {
526 return value->IsConstant()
527 ? chunk_->DefineConstantOperand(HConstant::cast(value))
532 LOperand* LChunkBuilder::UseOrConstantAtStart(HValue* value) {
533 return value->IsConstant()
534 ? chunk_->DefineConstantOperand(HConstant::cast(value))
539 LOperand* LChunkBuilder::UseRegisterOrConstant(HValue* value) {
540 return value->IsConstant()
541 ? chunk_->DefineConstantOperand(HConstant::cast(value))
542 : UseRegister(value);
546 LOperand* LChunkBuilder::UseRegisterOrConstantAtStart(HValue* value) {
547 return value->IsConstant()
548 ? chunk_->DefineConstantOperand(HConstant::cast(value))
549 : UseRegisterAtStart(value);
553 LOperand* LChunkBuilder::UseConstant(HValue* value) {
554 return chunk_->DefineConstantOperand(HConstant::cast(value));
558 LOperand* LChunkBuilder::UseAny(HValue* value) {
559 return value->IsConstant()
560 ? chunk_->DefineConstantOperand(HConstant::cast(value))
561 : Use(value, new(zone()) LUnallocated(LUnallocated::ANY));
565 LOperand* LChunkBuilder::Use(HValue* value, LUnallocated* operand) {
566 if (value->EmitAtUses()) {
567 HInstruction* instr = HInstruction::cast(value);
568 VisitInstruction(instr);
570 operand->set_virtual_register(value->id());
575 LInstruction* LChunkBuilder::Define(LTemplateResultInstruction<1>* instr,
576 LUnallocated* result) {
577 result->set_virtual_register(current_instruction_->id());
578 instr->set_result(result);
583 LInstruction* LChunkBuilder::DefineAsRegister(
584 LTemplateResultInstruction<1>* instr) {
586 new(zone()) LUnallocated(LUnallocated::MUST_HAVE_REGISTER));
590 LInstruction* LChunkBuilder::DefineAsSpilled(
591 LTemplateResultInstruction<1>* instr,
594 new(zone()) LUnallocated(LUnallocated::FIXED_SLOT, index));
598 LInstruction* LChunkBuilder::DefineSameAsFirst(
599 LTemplateResultInstruction<1>* instr) {
601 new(zone()) LUnallocated(LUnallocated::SAME_AS_FIRST_INPUT));
605 LInstruction* LChunkBuilder::DefineFixed(LTemplateResultInstruction<1>* instr,
607 return Define(instr, ToUnallocated(reg));
611 LInstruction* LChunkBuilder::DefineFixedDouble(
612 LTemplateResultInstruction<1>* instr,
614 return Define(instr, ToUnallocated(reg));
618 LInstruction* LChunkBuilder::AssignEnvironment(LInstruction* instr) {
619 HEnvironment* hydrogen_env = current_block_->last_environment();
620 int argument_index_accumulator = 0;
621 ZoneList<HValue*> objects_to_materialize(0, zone());
622 instr->set_environment(CreateEnvironment(
623 hydrogen_env, &argument_index_accumulator, &objects_to_materialize));
628 LInstruction* LChunkBuilder::MarkAsCall(LInstruction* instr,
629 HInstruction* hinstr,
630 CanDeoptimize can_deoptimize) {
631 info()->MarkAsNonDeferredCalling();
637 instr = AssignPointerMap(instr);
639 // If instruction does not have side-effects lazy deoptimization
640 // after the call will try to deoptimize to the point before the call.
641 // Thus we still need to attach environment to this call even if
642 // call sequence can not deoptimize eagerly.
643 bool needs_environment =
644 (can_deoptimize == CAN_DEOPTIMIZE_EAGERLY) ||
645 !hinstr->HasObservableSideEffects();
646 if (needs_environment && !instr->HasEnvironment()) {
647 instr = AssignEnvironment(instr);
648 // We can't really figure out if the environment is needed or not.
649 instr->environment()->set_has_been_used();
656 LInstruction* LChunkBuilder::AssignPointerMap(LInstruction* instr) {
657 DCHECK(!instr->HasPointerMap());
658 instr->set_pointer_map(new(zone()) LPointerMap(zone()));
663 LUnallocated* LChunkBuilder::TempRegister() {
664 LUnallocated* operand =
665 new(zone()) LUnallocated(LUnallocated::MUST_HAVE_REGISTER);
666 int vreg = allocator_->GetVirtualRegister();
667 if (!allocator_->AllocationOk()) {
668 Abort(kOutOfVirtualRegistersWhileTryingToAllocateTempRegister);
671 operand->set_virtual_register(vreg);
676 LOperand* LChunkBuilder::FixedTemp(Register reg) {
677 LUnallocated* operand = ToUnallocated(reg);
678 DCHECK(operand->HasFixedPolicy());
683 LOperand* LChunkBuilder::FixedTemp(XMMRegister reg) {
684 LUnallocated* operand = ToUnallocated(reg);
685 DCHECK(operand->HasFixedPolicy());
690 LInstruction* LChunkBuilder::DoBlockEntry(HBlockEntry* instr) {
691 return new(zone()) LLabel(instr->block());
695 LInstruction* LChunkBuilder::DoDummyUse(HDummyUse* instr) {
696 return DefineAsRegister(new(zone()) LDummyUse(UseAny(instr->value())));
700 LInstruction* LChunkBuilder::DoEnvironmentMarker(HEnvironmentMarker* instr) {
706 LInstruction* LChunkBuilder::DoDeoptimize(HDeoptimize* instr) {
707 return AssignEnvironment(new(zone()) LDeoptimize);
711 LInstruction* LChunkBuilder::DoShift(Token::Value op,
712 HBitwiseBinaryOperation* instr) {
713 if (instr->representation().IsSmiOrInteger32()) {
714 DCHECK(instr->left()->representation().Equals(instr->representation()));
715 DCHECK(instr->right()->representation().Equals(instr->representation()));
716 LOperand* left = UseRegisterAtStart(instr->left());
718 HValue* right_value = instr->right();
719 LOperand* right = NULL;
720 int constant_value = 0;
721 bool does_deopt = false;
722 if (right_value->IsConstant()) {
723 HConstant* constant = HConstant::cast(right_value);
724 right = chunk_->DefineConstantOperand(constant);
725 constant_value = constant->Integer32Value() & 0x1f;
726 if (SmiValuesAre31Bits() && instr->representation().IsSmi() &&
727 constant_value > 0) {
728 // Left shift can deoptimize if we shift by > 0 and the result
729 // cannot be truncated to smi.
730 does_deopt = !instr->CheckUsesForFlag(HValue::kTruncatingToSmi);
733 right = UseFixed(right_value, rcx);
736 // Shift operations can only deoptimize if we do a logical shift by 0 and
737 // the result cannot be truncated to int32.
738 if (op == Token::SHR && constant_value == 0) {
739 does_deopt = !instr->CheckFlag(HInstruction::kUint32);
742 LInstruction* result =
743 DefineSameAsFirst(new(zone()) LShiftI(op, left, right, does_deopt));
744 return does_deopt ? AssignEnvironment(result) : result;
746 return DoArithmeticT(op, instr);
751 LInstruction* LChunkBuilder::DoArithmeticD(Token::Value op,
752 HArithmeticBinaryOperation* instr) {
753 DCHECK(instr->representation().IsDouble());
754 DCHECK(instr->left()->representation().IsDouble());
755 DCHECK(instr->right()->representation().IsDouble());
756 if (op == Token::MOD) {
757 LOperand* left = UseRegisterAtStart(instr->BetterLeftOperand());
758 LOperand* right = UseFixedDouble(instr->BetterRightOperand(), xmm1);
759 LArithmeticD* result = new(zone()) LArithmeticD(op, left, right);
760 return MarkAsCall(DefineSameAsFirst(result), instr);
762 LOperand* left = UseRegisterAtStart(instr->BetterLeftOperand());
763 LOperand* right = UseRegisterAtStart(instr->BetterRightOperand());
764 LArithmeticD* result = new(zone()) LArithmeticD(op, left, right);
765 return CpuFeatures::IsSupported(AVX) ? DefineAsRegister(result)
766 : DefineSameAsFirst(result);
771 LInstruction* LChunkBuilder::DoArithmeticT(Token::Value op,
772 HBinaryOperation* instr) {
773 HValue* left = instr->left();
774 HValue* right = instr->right();
775 DCHECK(left->representation().IsTagged());
776 DCHECK(right->representation().IsTagged());
777 LOperand* context = UseFixed(instr->context(), rsi);
778 LOperand* left_operand = UseFixed(left, rdx);
779 LOperand* right_operand = UseFixed(right, rax);
780 LArithmeticT* result =
781 new(zone()) LArithmeticT(op, context, left_operand, right_operand);
782 return MarkAsCall(DefineFixed(result, rax), instr);
786 void LChunkBuilder::DoBasicBlock(HBasicBlock* block, HBasicBlock* next_block) {
787 DCHECK(is_building());
788 current_block_ = block;
789 next_block_ = next_block;
790 if (block->IsStartBlock()) {
791 block->UpdateEnvironment(graph_->start_environment());
793 } else if (block->predecessors()->length() == 1) {
794 // We have a single predecessor => copy environment and outgoing
795 // argument count from the predecessor.
796 DCHECK(block->phis()->length() == 0);
797 HBasicBlock* pred = block->predecessors()->at(0);
798 HEnvironment* last_environment = pred->last_environment();
799 DCHECK(last_environment != NULL);
800 // Only copy the environment, if it is later used again.
801 if (pred->end()->SecondSuccessor() == NULL) {
802 DCHECK(pred->end()->FirstSuccessor() == block);
804 if (pred->end()->FirstSuccessor()->block_id() > block->block_id() ||
805 pred->end()->SecondSuccessor()->block_id() > block->block_id()) {
806 last_environment = last_environment->Copy();
809 block->UpdateEnvironment(last_environment);
810 DCHECK(pred->argument_count() >= 0);
811 argument_count_ = pred->argument_count();
813 // We are at a state join => process phis.
814 HBasicBlock* pred = block->predecessors()->at(0);
815 // No need to copy the environment, it cannot be used later.
816 HEnvironment* last_environment = pred->last_environment();
817 for (int i = 0; i < block->phis()->length(); ++i) {
818 HPhi* phi = block->phis()->at(i);
819 if (phi->HasMergedIndex()) {
820 last_environment->SetValueAt(phi->merged_index(), phi);
823 for (int i = 0; i < block->deleted_phis()->length(); ++i) {
824 if (block->deleted_phis()->at(i) < last_environment->length()) {
825 last_environment->SetValueAt(block->deleted_phis()->at(i),
826 graph_->GetConstantUndefined());
829 block->UpdateEnvironment(last_environment);
830 // Pick up the outgoing argument count of one of the predecessors.
831 argument_count_ = pred->argument_count();
833 HInstruction* current = block->first();
834 int start = chunk_->instructions()->length();
835 while (current != NULL && !is_aborted()) {
836 // Code for constants in registers is generated lazily.
837 if (!current->EmitAtUses()) {
838 VisitInstruction(current);
840 current = current->next();
842 int end = chunk_->instructions()->length() - 1;
844 block->set_first_instruction_index(start);
845 block->set_last_instruction_index(end);
847 block->set_argument_count(argument_count_);
849 current_block_ = NULL;
853 void LChunkBuilder::VisitInstruction(HInstruction* current) {
854 HInstruction* old_current = current_instruction_;
855 current_instruction_ = current;
857 LInstruction* instr = NULL;
858 if (current->CanReplaceWithDummyUses()) {
859 if (current->OperandCount() == 0) {
860 instr = DefineAsRegister(new(zone()) LDummy());
862 DCHECK(!current->OperandAt(0)->IsControlInstruction());
863 instr = DefineAsRegister(new(zone())
864 LDummyUse(UseAny(current->OperandAt(0))));
866 for (int i = 1; i < current->OperandCount(); ++i) {
867 if (current->OperandAt(i)->IsControlInstruction()) continue;
868 LInstruction* dummy =
869 new(zone()) LDummyUse(UseAny(current->OperandAt(i)));
870 dummy->set_hydrogen_value(current);
871 chunk_->AddInstruction(dummy, current_block_);
874 HBasicBlock* successor;
875 if (current->IsControlInstruction() &&
876 HControlInstruction::cast(current)->KnownSuccessorBlock(&successor) &&
878 instr = new(zone()) LGoto(successor);
880 instr = current->CompileToLithium(this);
884 argument_count_ += current->argument_delta();
885 DCHECK(argument_count_ >= 0);
888 AddInstruction(instr, current);
891 current_instruction_ = old_current;
895 void LChunkBuilder::AddInstruction(LInstruction* instr,
896 HInstruction* hydrogen_val) {
897 // Associate the hydrogen instruction first, since we may need it for
898 // the ClobbersRegisters() or ClobbersDoubleRegisters() calls below.
899 instr->set_hydrogen_value(hydrogen_val);
902 // Make sure that the lithium instruction has either no fixed register
903 // constraints in temps or the result OR no uses that are only used at
904 // start. If this invariant doesn't hold, the register allocator can decide
905 // to insert a split of a range immediately before the instruction due to an
906 // already allocated register needing to be used for the instruction's fixed
907 // register constraint. In this case, The register allocator won't see an
908 // interference between the split child and the use-at-start (it would if
909 // the it was just a plain use), so it is free to move the split child into
910 // the same register that is used for the use-at-start.
911 // See https://code.google.com/p/chromium/issues/detail?id=201590
912 if (!(instr->ClobbersRegisters() &&
913 instr->ClobbersDoubleRegisters(isolate()))) {
915 int used_at_start = 0;
916 for (UseIterator it(instr); !it.Done(); it.Advance()) {
917 LUnallocated* operand = LUnallocated::cast(it.Current());
918 if (operand->IsUsedAtStart()) ++used_at_start;
920 if (instr->Output() != NULL) {
921 if (LUnallocated::cast(instr->Output())->HasFixedPolicy()) ++fixed;
923 for (TempIterator it(instr); !it.Done(); it.Advance()) {
924 LUnallocated* operand = LUnallocated::cast(it.Current());
925 if (operand->HasFixedPolicy()) ++fixed;
927 DCHECK(fixed == 0 || used_at_start == 0);
931 if (FLAG_stress_pointer_maps && !instr->HasPointerMap()) {
932 instr = AssignPointerMap(instr);
934 if (FLAG_stress_environments && !instr->HasEnvironment()) {
935 instr = AssignEnvironment(instr);
937 chunk_->AddInstruction(instr, current_block_);
939 if (instr->IsCall()) {
940 HValue* hydrogen_value_for_lazy_bailout = hydrogen_val;
941 LInstruction* instruction_needing_environment = NULL;
942 if (hydrogen_val->HasObservableSideEffects()) {
943 HSimulate* sim = HSimulate::cast(hydrogen_val->next());
944 instruction_needing_environment = instr;
945 sim->ReplayEnvironment(current_block_->last_environment());
946 hydrogen_value_for_lazy_bailout = sim;
948 LInstruction* bailout = AssignEnvironment(new(zone()) LLazyBailout());
949 bailout->set_hydrogen_value(hydrogen_value_for_lazy_bailout);
950 chunk_->AddInstruction(bailout, current_block_);
951 if (instruction_needing_environment != NULL) {
952 // Store the lazy deopt environment with the instruction if needed.
953 // Right now it is only used for LInstanceOfKnownGlobal.
954 instruction_needing_environment->
955 SetDeferredLazyDeoptimizationEnvironment(bailout->environment());
961 LInstruction* LChunkBuilder::DoGoto(HGoto* instr) {
962 return new(zone()) LGoto(instr->FirstSuccessor());
966 LInstruction* LChunkBuilder::DoDebugBreak(HDebugBreak* instr) {
967 return new(zone()) LDebugBreak();
971 LInstruction* LChunkBuilder::DoBranch(HBranch* instr) {
972 HValue* value = instr->value();
973 Representation r = value->representation();
974 HType type = value->type();
975 ToBooleanStub::Types expected = instr->expected_input_types();
976 if (expected.IsEmpty()) expected = ToBooleanStub::Types::Generic();
978 bool easy_case = !r.IsTagged() || type.IsBoolean() || type.IsSmi() ||
979 type.IsJSArray() || type.IsHeapNumber() || type.IsString();
980 LInstruction* branch = new(zone()) LBranch(UseRegister(value));
982 ((!expected.Contains(ToBooleanStub::SMI) && expected.NeedsMap()) ||
983 !expected.IsGeneric())) {
984 branch = AssignEnvironment(branch);
990 LInstruction* LChunkBuilder::DoCompareMap(HCompareMap* instr) {
991 DCHECK(instr->value()->representation().IsTagged());
992 LOperand* value = UseRegisterAtStart(instr->value());
993 return new(zone()) LCmpMapAndBranch(value);
997 LInstruction* LChunkBuilder::DoArgumentsLength(HArgumentsLength* length) {
998 info()->MarkAsRequiresFrame();
999 return DefineAsRegister(new(zone()) LArgumentsLength(Use(length->value())));
1003 LInstruction* LChunkBuilder::DoArgumentsElements(HArgumentsElements* elems) {
1004 info()->MarkAsRequiresFrame();
1005 return DefineAsRegister(new(zone()) LArgumentsElements);
1009 LInstruction* LChunkBuilder::DoInstanceOf(HInstanceOf* instr) {
1010 LOperand* left = UseFixed(instr->left(), rax);
1011 LOperand* right = UseFixed(instr->right(), rdx);
1012 LOperand* context = UseFixed(instr->context(), rsi);
1013 LInstanceOf* result = new(zone()) LInstanceOf(context, left, right);
1014 return MarkAsCall(DefineFixed(result, rax), instr);
1018 LInstruction* LChunkBuilder::DoInstanceOfKnownGlobal(
1019 HInstanceOfKnownGlobal* instr) {
1020 LInstanceOfKnownGlobal* result =
1021 new(zone()) LInstanceOfKnownGlobal(UseFixed(instr->context(), rsi),
1022 UseFixed(instr->left(), rax),
1024 return MarkAsCall(DefineFixed(result, rax), instr);
1028 LInstruction* LChunkBuilder::DoWrapReceiver(HWrapReceiver* instr) {
1029 LOperand* receiver = UseRegister(instr->receiver());
1030 LOperand* function = UseRegisterAtStart(instr->function());
1031 LWrapReceiver* result = new(zone()) LWrapReceiver(receiver, function);
1032 return AssignEnvironment(DefineSameAsFirst(result));
1036 LInstruction* LChunkBuilder::DoApplyArguments(HApplyArguments* instr) {
1037 LOperand* function = UseFixed(instr->function(), rdi);
1038 LOperand* receiver = UseFixed(instr->receiver(), rax);
1039 LOperand* length = UseFixed(instr->length(), rbx);
1040 LOperand* elements = UseFixed(instr->elements(), rcx);
1041 LApplyArguments* result = new(zone()) LApplyArguments(function,
1045 return MarkAsCall(DefineFixed(result, rax), instr, CAN_DEOPTIMIZE_EAGERLY);
1049 LInstruction* LChunkBuilder::DoPushArguments(HPushArguments* instr) {
1050 int argc = instr->OperandCount();
1051 for (int i = 0; i < argc; ++i) {
1052 LOperand* argument = UseOrConstant(instr->argument(i));
1053 AddInstruction(new(zone()) LPushArgument(argument), instr);
1059 LInstruction* LChunkBuilder::DoStoreCodeEntry(
1060 HStoreCodeEntry* store_code_entry) {
1061 LOperand* function = UseRegister(store_code_entry->function());
1062 LOperand* code_object = UseTempRegister(store_code_entry->code_object());
1063 return new(zone()) LStoreCodeEntry(function, code_object);
1067 LInstruction* LChunkBuilder::DoInnerAllocatedObject(
1068 HInnerAllocatedObject* instr) {
1069 LOperand* base_object = UseRegisterAtStart(instr->base_object());
1070 LOperand* offset = UseRegisterOrConstantAtStart(instr->offset());
1071 return DefineAsRegister(
1072 new(zone()) LInnerAllocatedObject(base_object, offset));
1076 LInstruction* LChunkBuilder::DoThisFunction(HThisFunction* instr) {
1077 return instr->HasNoUses()
1079 : DefineAsRegister(new(zone()) LThisFunction);
1083 LInstruction* LChunkBuilder::DoContext(HContext* instr) {
1084 if (instr->HasNoUses()) return NULL;
1086 if (info()->IsStub()) {
1087 return DefineFixed(new(zone()) LContext, rsi);
1090 return DefineAsRegister(new(zone()) LContext);
1094 LInstruction* LChunkBuilder::DoDeclareGlobals(HDeclareGlobals* instr) {
1095 LOperand* context = UseFixed(instr->context(), rsi);
1096 return MarkAsCall(new(zone()) LDeclareGlobals(context), instr);
1100 LInstruction* LChunkBuilder::DoCallJSFunction(
1101 HCallJSFunction* instr) {
1102 LOperand* function = UseFixed(instr->function(), rdi);
1104 LCallJSFunction* result = new(zone()) LCallJSFunction(function);
1106 return MarkAsCall(DefineFixed(result, rax), instr);
1110 LInstruction* LChunkBuilder::DoCallWithDescriptor(
1111 HCallWithDescriptor* instr) {
1112 CallInterfaceDescriptor descriptor = instr->descriptor();
1114 LOperand* target = UseRegisterOrConstantAtStart(instr->target());
1115 ZoneList<LOperand*> ops(instr->OperandCount(), zone());
1116 ops.Add(target, zone());
1117 for (int i = 1; i < instr->OperandCount(); i++) {
1119 UseFixed(instr->OperandAt(i), descriptor.GetParameterRegister(i - 1));
1120 ops.Add(op, zone());
1123 LCallWithDescriptor* result = new(zone()) LCallWithDescriptor(
1124 descriptor, ops, zone());
1125 return MarkAsCall(DefineFixed(result, rax), instr);
1129 LInstruction* LChunkBuilder::DoTailCallThroughMegamorphicCache(
1130 HTailCallThroughMegamorphicCache* instr) {
1131 LOperand* context = UseFixed(instr->context(), rsi);
1132 LOperand* receiver_register =
1133 UseFixed(instr->receiver(), LoadDescriptor::ReceiverRegister());
1134 LOperand* name_register =
1135 UseFixed(instr->name(), LoadDescriptor::NameRegister());
1136 LOperand* slot = NULL;
1137 LOperand* vector = NULL;
1138 if (FLAG_vector_ics) {
1139 slot = UseFixed(instr->slot(), VectorLoadICDescriptor::SlotRegister());
1141 UseFixed(instr->vector(), VectorLoadICDescriptor::VectorRegister());
1144 // Not marked as call. It can't deoptimize, and it never returns.
1145 return new (zone()) LTailCallThroughMegamorphicCache(
1146 context, receiver_register, name_register, slot, vector);
1150 LInstruction* LChunkBuilder::DoInvokeFunction(HInvokeFunction* instr) {
1151 LOperand* context = UseFixed(instr->context(), rsi);
1152 LOperand* function = UseFixed(instr->function(), rdi);
1153 LInvokeFunction* result = new(zone()) LInvokeFunction(context, function);
1154 return MarkAsCall(DefineFixed(result, rax), instr, CANNOT_DEOPTIMIZE_EAGERLY);
1158 LInstruction* LChunkBuilder::DoUnaryMathOperation(HUnaryMathOperation* instr) {
1159 switch (instr->op()) {
1161 return DoMathFloor(instr);
1163 return DoMathRound(instr);
1165 return DoMathFround(instr);
1167 return DoMathAbs(instr);
1169 return DoMathLog(instr);
1171 return DoMathExp(instr);
1173 return DoMathSqrt(instr);
1175 return DoMathPowHalf(instr);
1177 return DoMathClz32(instr);
1185 LInstruction* LChunkBuilder::DoMathFloor(HUnaryMathOperation* instr) {
1186 LOperand* input = UseRegisterAtStart(instr->value());
1187 LMathFloor* result = new(zone()) LMathFloor(input);
1188 return AssignEnvironment(DefineAsRegister(result));
1192 LInstruction* LChunkBuilder::DoMathRound(HUnaryMathOperation* instr) {
1193 LOperand* input = UseRegister(instr->value());
1194 LOperand* temp = FixedTemp(xmm4);
1195 LMathRound* result = new(zone()) LMathRound(input, temp);
1196 return AssignEnvironment(DefineAsRegister(result));
1200 LInstruction* LChunkBuilder::DoMathFround(HUnaryMathOperation* instr) {
1201 LOperand* input = UseRegister(instr->value());
1202 LMathFround* result = new (zone()) LMathFround(input);
1203 return DefineAsRegister(result);
1207 LInstruction* LChunkBuilder::DoMathAbs(HUnaryMathOperation* instr) {
1208 LOperand* context = UseAny(instr->context());
1209 LOperand* input = UseRegisterAtStart(instr->value());
1210 LInstruction* result =
1211 DefineSameAsFirst(new(zone()) LMathAbs(context, input));
1212 Representation r = instr->value()->representation();
1213 if (!r.IsDouble() && !r.IsSmiOrInteger32()) result = AssignPointerMap(result);
1214 if (!r.IsDouble()) result = AssignEnvironment(result);
1219 LInstruction* LChunkBuilder::DoMathLog(HUnaryMathOperation* instr) {
1220 DCHECK(instr->representation().IsDouble());
1221 DCHECK(instr->value()->representation().IsDouble());
1222 LOperand* input = UseRegisterAtStart(instr->value());
1223 return MarkAsCall(DefineSameAsFirst(new(zone()) LMathLog(input)), instr);
1227 LInstruction* LChunkBuilder::DoMathClz32(HUnaryMathOperation* instr) {
1228 LOperand* input = UseRegisterAtStart(instr->value());
1229 LMathClz32* result = new(zone()) LMathClz32(input);
1230 return DefineAsRegister(result);
1234 LInstruction* LChunkBuilder::DoMathExp(HUnaryMathOperation* instr) {
1235 DCHECK(instr->representation().IsDouble());
1236 DCHECK(instr->value()->representation().IsDouble());
1237 LOperand* value = UseTempRegister(instr->value());
1238 LOperand* temp1 = TempRegister();
1239 LOperand* temp2 = TempRegister();
1240 LMathExp* result = new(zone()) LMathExp(value, temp1, temp2);
1241 return DefineAsRegister(result);
1245 LInstruction* LChunkBuilder::DoMathSqrt(HUnaryMathOperation* instr) {
1246 LOperand* input = UseAtStart(instr->value());
1247 return DefineAsRegister(new(zone()) LMathSqrt(input));
1251 LInstruction* LChunkBuilder::DoMathPowHalf(HUnaryMathOperation* instr) {
1252 LOperand* input = UseRegisterAtStart(instr->value());
1253 LMathPowHalf* result = new(zone()) LMathPowHalf(input);
1254 return DefineSameAsFirst(result);
1258 LInstruction* LChunkBuilder::DoCallNew(HCallNew* instr) {
1259 LOperand* context = UseFixed(instr->context(), rsi);
1260 LOperand* constructor = UseFixed(instr->constructor(), rdi);
1261 LCallNew* result = new(zone()) LCallNew(context, constructor);
1262 return MarkAsCall(DefineFixed(result, rax), instr);
1266 LInstruction* LChunkBuilder::DoCallNewArray(HCallNewArray* instr) {
1267 LOperand* context = UseFixed(instr->context(), rsi);
1268 LOperand* constructor = UseFixed(instr->constructor(), rdi);
1269 LCallNewArray* result = new(zone()) LCallNewArray(context, constructor);
1270 return MarkAsCall(DefineFixed(result, rax), instr);
1274 LInstruction* LChunkBuilder::DoCallFunction(HCallFunction* instr) {
1275 LOperand* context = UseFixed(instr->context(), rsi);
1276 LOperand* function = UseFixed(instr->function(), rdi);
1277 LOperand* slot = NULL;
1278 LOperand* vector = NULL;
1279 if (instr->HasVectorAndSlot()) {
1280 slot = FixedTemp(rdx);
1281 vector = FixedTemp(rbx);
1283 LCallFunction* call =
1284 new (zone()) LCallFunction(context, function, slot, vector);
1285 return MarkAsCall(DefineFixed(call, rax), instr);
1289 LInstruction* LChunkBuilder::DoCallRuntime(HCallRuntime* instr) {
1290 LOperand* context = UseFixed(instr->context(), rsi);
1291 LCallRuntime* result = new(zone()) LCallRuntime(context);
1292 return MarkAsCall(DefineFixed(result, rax), instr);
1296 LInstruction* LChunkBuilder::DoRor(HRor* instr) {
1297 return DoShift(Token::ROR, instr);
1301 LInstruction* LChunkBuilder::DoShr(HShr* instr) {
1302 return DoShift(Token::SHR, instr);
1306 LInstruction* LChunkBuilder::DoSar(HSar* instr) {
1307 return DoShift(Token::SAR, instr);
1311 LInstruction* LChunkBuilder::DoShl(HShl* instr) {
1312 return DoShift(Token::SHL, instr);
1316 LInstruction* LChunkBuilder::DoBitwise(HBitwise* instr) {
1317 if (instr->representation().IsSmiOrInteger32()) {
1318 DCHECK(instr->left()->representation().Equals(instr->representation()));
1319 DCHECK(instr->right()->representation().Equals(instr->representation()));
1320 DCHECK(instr->CheckFlag(HValue::kTruncatingToInt32));
1322 LOperand* left = UseRegisterAtStart(instr->BetterLeftOperand());
1323 LOperand* right = UseOrConstantAtStart(instr->BetterRightOperand());
1324 return DefineSameAsFirst(new(zone()) LBitI(left, right));
1326 return DoArithmeticT(instr->op(), instr);
1331 LInstruction* LChunkBuilder::DoDivByPowerOf2I(HDiv* instr) {
1332 DCHECK(instr->representation().IsSmiOrInteger32());
1333 DCHECK(instr->left()->representation().Equals(instr->representation()));
1334 DCHECK(instr->right()->representation().Equals(instr->representation()));
1335 LOperand* dividend = UseRegister(instr->left());
1336 int32_t divisor = instr->right()->GetInteger32Constant();
1337 LInstruction* result = DefineAsRegister(new(zone()) LDivByPowerOf2I(
1338 dividend, divisor));
1339 if ((instr->CheckFlag(HValue::kBailoutOnMinusZero) && divisor < 0) ||
1340 (instr->CheckFlag(HValue::kCanOverflow) && divisor == -1) ||
1341 (!instr->CheckFlag(HInstruction::kAllUsesTruncatingToInt32) &&
1342 divisor != 1 && divisor != -1)) {
1343 result = AssignEnvironment(result);
1349 LInstruction* LChunkBuilder::DoDivByConstI(HDiv* instr) {
1350 DCHECK(instr->representation().IsInteger32());
1351 DCHECK(instr->left()->representation().Equals(instr->representation()));
1352 DCHECK(instr->right()->representation().Equals(instr->representation()));
1353 LOperand* dividend = UseRegister(instr->left());
1354 int32_t divisor = instr->right()->GetInteger32Constant();
1355 LOperand* temp1 = FixedTemp(rax);
1356 LOperand* temp2 = FixedTemp(rdx);
1357 LInstruction* result = DefineFixed(new(zone()) LDivByConstI(
1358 dividend, divisor, temp1, temp2), rdx);
1360 (instr->CheckFlag(HValue::kBailoutOnMinusZero) && divisor < 0) ||
1361 !instr->CheckFlag(HInstruction::kAllUsesTruncatingToInt32)) {
1362 result = AssignEnvironment(result);
1368 LInstruction* LChunkBuilder::DoDivI(HDiv* instr) {
1369 DCHECK(instr->representation().IsSmiOrInteger32());
1370 DCHECK(instr->left()->representation().Equals(instr->representation()));
1371 DCHECK(instr->right()->representation().Equals(instr->representation()));
1372 LOperand* dividend = UseFixed(instr->left(), rax);
1373 LOperand* divisor = UseRegister(instr->right());
1374 LOperand* temp = FixedTemp(rdx);
1375 LInstruction* result = DefineFixed(new(zone()) LDivI(
1376 dividend, divisor, temp), rax);
1377 if (instr->CheckFlag(HValue::kCanBeDivByZero) ||
1378 instr->CheckFlag(HValue::kBailoutOnMinusZero) ||
1379 instr->CheckFlag(HValue::kCanOverflow) ||
1380 !instr->CheckFlag(HValue::kAllUsesTruncatingToInt32)) {
1381 result = AssignEnvironment(result);
1387 LInstruction* LChunkBuilder::DoDiv(HDiv* instr) {
1388 if (instr->representation().IsSmiOrInteger32()) {
1389 if (instr->RightIsPowerOf2()) {
1390 return DoDivByPowerOf2I(instr);
1391 } else if (instr->right()->IsConstant()) {
1392 return DoDivByConstI(instr);
1394 return DoDivI(instr);
1396 } else if (instr->representation().IsDouble()) {
1397 return DoArithmeticD(Token::DIV, instr);
1399 return DoArithmeticT(Token::DIV, instr);
1404 LInstruction* LChunkBuilder::DoFlooringDivByPowerOf2I(HMathFloorOfDiv* instr) {
1405 LOperand* dividend = UseRegisterAtStart(instr->left());
1406 int32_t divisor = instr->right()->GetInteger32Constant();
1407 LInstruction* result = DefineSameAsFirst(new(zone()) LFlooringDivByPowerOf2I(
1408 dividend, divisor));
1409 if ((instr->CheckFlag(HValue::kBailoutOnMinusZero) && divisor < 0) ||
1410 (instr->CheckFlag(HValue::kLeftCanBeMinInt) && divisor == -1)) {
1411 result = AssignEnvironment(result);
1417 LInstruction* LChunkBuilder::DoFlooringDivByConstI(HMathFloorOfDiv* instr) {
1418 DCHECK(instr->representation().IsInteger32());
1419 DCHECK(instr->left()->representation().Equals(instr->representation()));
1420 DCHECK(instr->right()->representation().Equals(instr->representation()));
1421 LOperand* dividend = UseRegister(instr->left());
1422 int32_t divisor = instr->right()->GetInteger32Constant();
1423 LOperand* temp1 = FixedTemp(rax);
1424 LOperand* temp2 = FixedTemp(rdx);
1426 ((divisor > 0 && !instr->CheckFlag(HValue::kLeftCanBeNegative)) ||
1427 (divisor < 0 && !instr->CheckFlag(HValue::kLeftCanBePositive))) ?
1428 NULL : TempRegister();
1429 LInstruction* result =
1430 DefineFixed(new(zone()) LFlooringDivByConstI(dividend,
1437 (instr->CheckFlag(HValue::kBailoutOnMinusZero) && divisor < 0)) {
1438 result = AssignEnvironment(result);
1444 LInstruction* LChunkBuilder::DoFlooringDivI(HMathFloorOfDiv* instr) {
1445 DCHECK(instr->representation().IsSmiOrInteger32());
1446 DCHECK(instr->left()->representation().Equals(instr->representation()));
1447 DCHECK(instr->right()->representation().Equals(instr->representation()));
1448 LOperand* dividend = UseFixed(instr->left(), rax);
1449 LOperand* divisor = UseRegister(instr->right());
1450 LOperand* temp = FixedTemp(rdx);
1451 LInstruction* result = DefineFixed(new(zone()) LFlooringDivI(
1452 dividend, divisor, temp), rax);
1453 if (instr->CheckFlag(HValue::kCanBeDivByZero) ||
1454 instr->CheckFlag(HValue::kBailoutOnMinusZero) ||
1455 instr->CheckFlag(HValue::kCanOverflow)) {
1456 result = AssignEnvironment(result);
1462 LInstruction* LChunkBuilder::DoMathFloorOfDiv(HMathFloorOfDiv* instr) {
1463 if (instr->RightIsPowerOf2()) {
1464 return DoFlooringDivByPowerOf2I(instr);
1465 } else if (instr->right()->IsConstant()) {
1466 return DoFlooringDivByConstI(instr);
1468 return DoFlooringDivI(instr);
1473 LInstruction* LChunkBuilder::DoModByPowerOf2I(HMod* 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 = UseRegisterAtStart(instr->left());
1478 int32_t divisor = instr->right()->GetInteger32Constant();
1479 LInstruction* result = DefineSameAsFirst(new(zone()) LModByPowerOf2I(
1480 dividend, divisor));
1481 if (instr->CheckFlag(HValue::kLeftCanBeNegative) &&
1482 instr->CheckFlag(HValue::kBailoutOnMinusZero)) {
1483 result = AssignEnvironment(result);
1489 LInstruction* LChunkBuilder::DoModByConstI(HMod* instr) {
1490 DCHECK(instr->representation().IsSmiOrInteger32());
1491 DCHECK(instr->left()->representation().Equals(instr->representation()));
1492 DCHECK(instr->right()->representation().Equals(instr->representation()));
1493 LOperand* dividend = UseRegister(instr->left());
1494 int32_t divisor = instr->right()->GetInteger32Constant();
1495 LOperand* temp1 = FixedTemp(rax);
1496 LOperand* temp2 = FixedTemp(rdx);
1497 LInstruction* result = DefineFixed(new(zone()) LModByConstI(
1498 dividend, divisor, temp1, temp2), rax);
1499 if (divisor == 0 || instr->CheckFlag(HValue::kBailoutOnMinusZero)) {
1500 result = AssignEnvironment(result);
1506 LInstruction* LChunkBuilder::DoModI(HMod* instr) {
1507 DCHECK(instr->representation().IsSmiOrInteger32());
1508 DCHECK(instr->left()->representation().Equals(instr->representation()));
1509 DCHECK(instr->right()->representation().Equals(instr->representation()));
1510 LOperand* dividend = UseFixed(instr->left(), rax);
1511 LOperand* divisor = UseRegister(instr->right());
1512 LOperand* temp = FixedTemp(rdx);
1513 LInstruction* result = DefineFixed(new(zone()) LModI(
1514 dividend, divisor, temp), rdx);
1515 if (instr->CheckFlag(HValue::kCanBeDivByZero) ||
1516 instr->CheckFlag(HValue::kBailoutOnMinusZero)) {
1517 result = AssignEnvironment(result);
1523 LInstruction* LChunkBuilder::DoMod(HMod* instr) {
1524 if (instr->representation().IsSmiOrInteger32()) {
1525 if (instr->RightIsPowerOf2()) {
1526 return DoModByPowerOf2I(instr);
1527 } else if (instr->right()->IsConstant()) {
1528 return DoModByConstI(instr);
1530 return DoModI(instr);
1532 } else if (instr->representation().IsDouble()) {
1533 return DoArithmeticD(Token::MOD, instr);
1535 return DoArithmeticT(Token::MOD, instr);
1540 LInstruction* LChunkBuilder::DoMul(HMul* instr) {
1541 if (instr->representation().IsSmiOrInteger32()) {
1542 DCHECK(instr->left()->representation().Equals(instr->representation()));
1543 DCHECK(instr->right()->representation().Equals(instr->representation()));
1544 LOperand* left = UseRegisterAtStart(instr->BetterLeftOperand());
1545 LOperand* right = UseOrConstant(instr->BetterRightOperand());
1546 LMulI* mul = new(zone()) LMulI(left, right);
1547 if (instr->CheckFlag(HValue::kCanOverflow) ||
1548 instr->CheckFlag(HValue::kBailoutOnMinusZero)) {
1549 AssignEnvironment(mul);
1551 return DefineSameAsFirst(mul);
1552 } else if (instr->representation().IsDouble()) {
1553 return DoArithmeticD(Token::MUL, instr);
1555 return DoArithmeticT(Token::MUL, instr);
1560 LInstruction* LChunkBuilder::DoSub(HSub* instr) {
1561 if (instr->representation().IsSmiOrInteger32()) {
1562 DCHECK(instr->left()->representation().Equals(instr->representation()));
1563 DCHECK(instr->right()->representation().Equals(instr->representation()));
1564 LOperand* left = UseRegisterAtStart(instr->left());
1565 LOperand* right = UseOrConstantAtStart(instr->right());
1566 LSubI* sub = new(zone()) LSubI(left, right);
1567 LInstruction* result = DefineSameAsFirst(sub);
1568 if (instr->CheckFlag(HValue::kCanOverflow)) {
1569 result = AssignEnvironment(result);
1572 } else if (instr->representation().IsDouble()) {
1573 return DoArithmeticD(Token::SUB, instr);
1575 return DoArithmeticT(Token::SUB, instr);
1580 LInstruction* LChunkBuilder::DoAdd(HAdd* instr) {
1581 if (instr->representation().IsSmiOrInteger32()) {
1582 // Check to see if it would be advantageous to use an lea instruction rather
1583 // than an add. This is the case when no overflow check is needed and there
1584 // are multiple uses of the add's inputs, so using a 3-register add will
1585 // preserve all input values for later uses.
1586 bool use_lea = LAddI::UseLea(instr);
1587 DCHECK(instr->left()->representation().Equals(instr->representation()));
1588 DCHECK(instr->right()->representation().Equals(instr->representation()));
1589 LOperand* left = UseRegisterAtStart(instr->BetterLeftOperand());
1590 HValue* right_candidate = instr->BetterRightOperand();
1592 if (SmiValuesAre32Bits() && instr->representation().IsSmi()) {
1593 // We cannot add a tagged immediate to a tagged value,
1594 // so we request it in a register.
1595 right = UseRegisterAtStart(right_candidate);
1597 right = use_lea ? UseRegisterOrConstantAtStart(right_candidate)
1598 : UseOrConstantAtStart(right_candidate);
1600 LAddI* add = new(zone()) LAddI(left, right);
1601 bool can_overflow = instr->CheckFlag(HValue::kCanOverflow);
1602 LInstruction* result = use_lea ? DefineAsRegister(add)
1603 : DefineSameAsFirst(add);
1605 result = AssignEnvironment(result);
1608 } else if (instr->representation().IsExternal()) {
1609 DCHECK(instr->left()->representation().IsExternal());
1610 DCHECK(instr->right()->representation().IsInteger32());
1611 DCHECK(!instr->CheckFlag(HValue::kCanOverflow));
1612 bool use_lea = LAddI::UseLea(instr);
1613 LOperand* left = UseRegisterAtStart(instr->left());
1614 HValue* right_candidate = instr->right();
1615 LOperand* right = use_lea
1616 ? UseRegisterOrConstantAtStart(right_candidate)
1617 : UseOrConstantAtStart(right_candidate);
1618 LAddI* add = new(zone()) LAddI(left, right);
1619 LInstruction* result = use_lea
1620 ? DefineAsRegister(add)
1621 : DefineSameAsFirst(add);
1623 } else if (instr->representation().IsDouble()) {
1624 return DoArithmeticD(Token::ADD, instr);
1626 return DoArithmeticT(Token::ADD, instr);
1632 LInstruction* LChunkBuilder::DoMathMinMax(HMathMinMax* instr) {
1633 LOperand* left = NULL;
1634 LOperand* right = NULL;
1635 DCHECK(instr->left()->representation().Equals(instr->representation()));
1636 DCHECK(instr->right()->representation().Equals(instr->representation()));
1637 if (instr->representation().IsSmi()) {
1638 left = UseRegisterAtStart(instr->BetterLeftOperand());
1639 right = UseAtStart(instr->BetterRightOperand());
1640 } else if (instr->representation().IsInteger32()) {
1641 left = UseRegisterAtStart(instr->BetterLeftOperand());
1642 right = UseOrConstantAtStart(instr->BetterRightOperand());
1644 DCHECK(instr->representation().IsDouble());
1645 left = UseRegisterAtStart(instr->left());
1646 right = UseRegisterAtStart(instr->right());
1648 LMathMinMax* minmax = new(zone()) LMathMinMax(left, right);
1649 return DefineSameAsFirst(minmax);
1653 LInstruction* LChunkBuilder::DoPower(HPower* instr) {
1654 DCHECK(instr->representation().IsDouble());
1655 // We call a C function for double power. It can't trigger a GC.
1656 // We need to use fixed result register for the call.
1657 Representation exponent_type = instr->right()->representation();
1658 DCHECK(instr->left()->representation().IsDouble());
1659 LOperand* left = UseFixedDouble(instr->left(), xmm2);
1661 exponent_type.IsDouble()
1662 ? UseFixedDouble(instr->right(), xmm1)
1663 : UseFixed(instr->right(), MathPowTaggedDescriptor::exponent());
1664 LPower* result = new(zone()) LPower(left, right);
1665 return MarkAsCall(DefineFixedDouble(result, xmm3), instr,
1666 CAN_DEOPTIMIZE_EAGERLY);
1670 LInstruction* LChunkBuilder::DoCompareGeneric(HCompareGeneric* instr) {
1671 DCHECK(instr->left()->representation().IsTagged());
1672 DCHECK(instr->right()->representation().IsTagged());
1673 LOperand* context = UseFixed(instr->context(), rsi);
1674 LOperand* left = UseFixed(instr->left(), rdx);
1675 LOperand* right = UseFixed(instr->right(), rax);
1676 LCmpT* result = new(zone()) LCmpT(context, left, right);
1677 return MarkAsCall(DefineFixed(result, rax), instr);
1681 LInstruction* LChunkBuilder::DoCompareNumericAndBranch(
1682 HCompareNumericAndBranch* instr) {
1683 Representation r = instr->representation();
1684 if (r.IsSmiOrInteger32()) {
1685 DCHECK(instr->left()->representation().Equals(r));
1686 DCHECK(instr->right()->representation().Equals(r));
1687 LOperand* left = UseRegisterOrConstantAtStart(instr->left());
1688 LOperand* right = UseOrConstantAtStart(instr->right());
1689 return new(zone()) LCompareNumericAndBranch(left, right);
1691 DCHECK(r.IsDouble());
1692 DCHECK(instr->left()->representation().IsDouble());
1693 DCHECK(instr->right()->representation().IsDouble());
1696 if (instr->left()->IsConstant() && instr->right()->IsConstant()) {
1697 left = UseRegisterOrConstantAtStart(instr->left());
1698 right = UseRegisterOrConstantAtStart(instr->right());
1700 left = UseRegisterAtStart(instr->left());
1701 right = UseRegisterAtStart(instr->right());
1703 return new(zone()) LCompareNumericAndBranch(left, right);
1708 LInstruction* LChunkBuilder::DoCompareObjectEqAndBranch(
1709 HCompareObjectEqAndBranch* instr) {
1710 LOperand* left = UseRegisterAtStart(instr->left());
1711 LOperand* right = UseRegisterOrConstantAtStart(instr->right());
1712 return new(zone()) LCmpObjectEqAndBranch(left, right);
1716 LInstruction* LChunkBuilder::DoCompareHoleAndBranch(
1717 HCompareHoleAndBranch* instr) {
1718 LOperand* value = UseRegisterAtStart(instr->value());
1719 return new(zone()) LCmpHoleAndBranch(value);
1723 LInstruction* LChunkBuilder::DoCompareMinusZeroAndBranch(
1724 HCompareMinusZeroAndBranch* instr) {
1725 LOperand* value = UseRegister(instr->value());
1726 return new(zone()) LCompareMinusZeroAndBranch(value);
1730 LInstruction* LChunkBuilder::DoIsObjectAndBranch(HIsObjectAndBranch* instr) {
1731 DCHECK(instr->value()->representation().IsTagged());
1732 return new(zone()) LIsObjectAndBranch(UseRegisterAtStart(instr->value()));
1736 LInstruction* LChunkBuilder::DoIsStringAndBranch(HIsStringAndBranch* instr) {
1737 DCHECK(instr->value()->representation().IsTagged());
1738 LOperand* value = UseRegisterAtStart(instr->value());
1739 LOperand* temp = TempRegister();
1740 return new(zone()) LIsStringAndBranch(value, temp);
1744 LInstruction* LChunkBuilder::DoIsSmiAndBranch(HIsSmiAndBranch* instr) {
1745 DCHECK(instr->value()->representation().IsTagged());
1746 return new(zone()) LIsSmiAndBranch(Use(instr->value()));
1750 LInstruction* LChunkBuilder::DoIsUndetectableAndBranch(
1751 HIsUndetectableAndBranch* instr) {
1752 DCHECK(instr->value()->representation().IsTagged());
1753 LOperand* value = UseRegisterAtStart(instr->value());
1754 LOperand* temp = TempRegister();
1755 return new(zone()) LIsUndetectableAndBranch(value, temp);
1759 LInstruction* LChunkBuilder::DoStringCompareAndBranch(
1760 HStringCompareAndBranch* instr) {
1762 DCHECK(instr->left()->representation().IsTagged());
1763 DCHECK(instr->right()->representation().IsTagged());
1764 LOperand* context = UseFixed(instr->context(), rsi);
1765 LOperand* left = UseFixed(instr->left(), rdx);
1766 LOperand* right = UseFixed(instr->right(), rax);
1767 LStringCompareAndBranch* result =
1768 new(zone()) LStringCompareAndBranch(context, left, right);
1770 return MarkAsCall(result, instr);
1774 LInstruction* LChunkBuilder::DoHasInstanceTypeAndBranch(
1775 HHasInstanceTypeAndBranch* instr) {
1776 DCHECK(instr->value()->representation().IsTagged());
1777 LOperand* value = UseRegisterAtStart(instr->value());
1778 return new(zone()) LHasInstanceTypeAndBranch(value);
1782 LInstruction* LChunkBuilder::DoGetCachedArrayIndex(
1783 HGetCachedArrayIndex* instr) {
1784 DCHECK(instr->value()->representation().IsTagged());
1785 LOperand* value = UseRegisterAtStart(instr->value());
1787 return DefineAsRegister(new(zone()) LGetCachedArrayIndex(value));
1791 LInstruction* LChunkBuilder::DoHasCachedArrayIndexAndBranch(
1792 HHasCachedArrayIndexAndBranch* instr) {
1793 DCHECK(instr->value()->representation().IsTagged());
1794 LOperand* value = UseRegisterAtStart(instr->value());
1795 return new(zone()) LHasCachedArrayIndexAndBranch(value);
1799 LInstruction* LChunkBuilder::DoClassOfTestAndBranch(
1800 HClassOfTestAndBranch* instr) {
1801 LOperand* value = UseRegister(instr->value());
1802 return new(zone()) LClassOfTestAndBranch(value,
1808 LInstruction* LChunkBuilder::DoMapEnumLength(HMapEnumLength* instr) {
1809 LOperand* map = UseRegisterAtStart(instr->value());
1810 return DefineAsRegister(new(zone()) LMapEnumLength(map));
1814 LInstruction* LChunkBuilder::DoDateField(HDateField* instr) {
1815 LOperand* object = UseFixed(instr->value(), rax);
1816 LDateField* result = new(zone()) LDateField(object, instr->index());
1817 return MarkAsCall(DefineFixed(result, rax), instr, CAN_DEOPTIMIZE_EAGERLY);
1821 LInstruction* LChunkBuilder::DoSeqStringGetChar(HSeqStringGetChar* instr) {
1822 LOperand* string = UseRegisterAtStart(instr->string());
1823 LOperand* index = UseRegisterOrConstantAtStart(instr->index());
1824 return DefineAsRegister(new(zone()) LSeqStringGetChar(string, index));
1828 LInstruction* LChunkBuilder::DoSeqStringSetChar(HSeqStringSetChar* instr) {
1829 LOperand* string = UseRegisterAtStart(instr->string());
1830 LOperand* index = FLAG_debug_code
1831 ? UseRegisterAtStart(instr->index())
1832 : UseRegisterOrConstantAtStart(instr->index());
1833 LOperand* value = FLAG_debug_code
1834 ? UseRegisterAtStart(instr->value())
1835 : UseRegisterOrConstantAtStart(instr->value());
1836 LOperand* context = FLAG_debug_code ? UseFixed(instr->context(), rsi) : NULL;
1837 LInstruction* result = new(zone()) LSeqStringSetChar(context, string,
1839 if (FLAG_debug_code) {
1840 result = MarkAsCall(result, instr);
1846 LInstruction* LChunkBuilder::DoBoundsCheck(HBoundsCheck* instr) {
1847 if (!FLAG_debug_code && instr->skip_check()) return NULL;
1848 LOperand* index = UseRegisterOrConstantAtStart(instr->index());
1849 LOperand* length = !index->IsConstantOperand()
1850 ? UseOrConstantAtStart(instr->length())
1851 : UseAtStart(instr->length());
1852 LInstruction* result = new(zone()) LBoundsCheck(index, length);
1853 if (!FLAG_debug_code || !instr->skip_check()) {
1854 result = AssignEnvironment(result);
1860 LInstruction* LChunkBuilder::DoBoundsCheckBaseIndexInformation(
1861 HBoundsCheckBaseIndexInformation* instr) {
1867 LInstruction* LChunkBuilder::DoAbnormalExit(HAbnormalExit* instr) {
1868 // The control instruction marking the end of a block that completed
1869 // abruptly (e.g., threw an exception). There is nothing specific to do.
1874 LInstruction* LChunkBuilder::DoUseConst(HUseConst* instr) {
1879 LInstruction* LChunkBuilder::DoForceRepresentation(HForceRepresentation* bad) {
1880 // All HForceRepresentation instructions should be eliminated in the
1881 // representation change phase of Hydrogen.
1887 LInstruction* LChunkBuilder::DoChange(HChange* instr) {
1888 Representation from = instr->from();
1889 Representation to = instr->to();
1890 HValue* val = instr->value();
1892 if (to.IsTagged()) {
1893 LOperand* value = UseRegister(val);
1894 return DefineSameAsFirst(new(zone()) LDummyUse(value));
1896 from = Representation::Tagged();
1898 if (from.IsTagged()) {
1899 if (to.IsDouble()) {
1900 LOperand* value = UseRegister(val);
1901 LInstruction* result = DefineAsRegister(new(zone()) LNumberUntagD(value));
1902 if (!val->representation().IsSmi()) result = AssignEnvironment(result);
1904 } else if (to.IsSmi()) {
1905 LOperand* value = UseRegister(val);
1906 if (val->type().IsSmi()) {
1907 return DefineSameAsFirst(new(zone()) LDummyUse(value));
1909 return AssignEnvironment(DefineSameAsFirst(new(zone()) LCheckSmi(value)));
1911 DCHECK(to.IsInteger32());
1912 if (val->type().IsSmi() || val->representation().IsSmi()) {
1913 LOperand* value = UseRegister(val);
1914 return DefineSameAsFirst(new(zone()) LSmiUntag(value, false));
1916 LOperand* value = UseRegister(val);
1917 bool truncating = instr->CanTruncateToInt32();
1918 LOperand* xmm_temp = truncating ? NULL : FixedTemp(xmm1);
1919 LInstruction* result =
1920 DefineSameAsFirst(new(zone()) LTaggedToI(value, xmm_temp));
1921 if (!val->representation().IsSmi()) result = AssignEnvironment(result);
1925 } else if (from.IsDouble()) {
1926 if (to.IsTagged()) {
1927 info()->MarkAsDeferredCalling();
1928 LOperand* value = UseRegister(val);
1929 LOperand* temp = TempRegister();
1930 LUnallocated* result_temp = TempRegister();
1931 LNumberTagD* result = new(zone()) LNumberTagD(value, temp);
1932 return AssignPointerMap(Define(result, result_temp));
1933 } else if (to.IsSmi()) {
1934 LOperand* value = UseRegister(val);
1935 return AssignEnvironment(
1936 DefineAsRegister(new(zone()) LDoubleToSmi(value)));
1938 DCHECK(to.IsInteger32());
1939 LOperand* value = UseRegister(val);
1940 LInstruction* result = DefineAsRegister(new(zone()) LDoubleToI(value));
1941 if (!instr->CanTruncateToInt32()) result = AssignEnvironment(result);
1944 } else if (from.IsInteger32()) {
1945 info()->MarkAsDeferredCalling();
1946 if (to.IsTagged()) {
1947 if (!instr->CheckFlag(HValue::kCanOverflow)) {
1948 LOperand* value = UseRegister(val);
1949 return DefineAsRegister(new(zone()) LSmiTag(value));
1950 } else if (val->CheckFlag(HInstruction::kUint32)) {
1951 LOperand* value = UseRegister(val);
1952 LOperand* temp1 = TempRegister();
1953 LOperand* temp2 = FixedTemp(xmm1);
1954 LNumberTagU* result = new(zone()) LNumberTagU(value, temp1, temp2);
1955 return AssignPointerMap(DefineSameAsFirst(result));
1957 LOperand* value = UseRegister(val);
1958 LOperand* temp1 = SmiValuesAre32Bits() ? NULL : TempRegister();
1959 LOperand* temp2 = SmiValuesAre32Bits() ? NULL : FixedTemp(xmm1);
1960 LNumberTagI* result = new(zone()) LNumberTagI(value, temp1, temp2);
1961 return AssignPointerMap(DefineSameAsFirst(result));
1963 } else if (to.IsSmi()) {
1964 LOperand* value = UseRegister(val);
1965 LInstruction* result = DefineAsRegister(new(zone()) LSmiTag(value));
1966 if (instr->CheckFlag(HValue::kCanOverflow)) {
1967 result = AssignEnvironment(result);
1971 DCHECK(to.IsDouble());
1972 if (val->CheckFlag(HInstruction::kUint32)) {
1973 return DefineAsRegister(new(zone()) LUint32ToDouble(UseRegister(val)));
1975 LOperand* value = Use(val);
1976 return DefineAsRegister(new(zone()) LInteger32ToDouble(value));
1985 LInstruction* LChunkBuilder::DoCheckHeapObject(HCheckHeapObject* instr) {
1986 LOperand* value = UseRegisterAtStart(instr->value());
1987 LInstruction* result = new(zone()) LCheckNonSmi(value);
1988 if (!instr->value()->type().IsHeapObject()) {
1989 result = AssignEnvironment(result);
1995 LInstruction* LChunkBuilder::DoCheckSmi(HCheckSmi* instr) {
1996 LOperand* value = UseRegisterAtStart(instr->value());
1997 return AssignEnvironment(new(zone()) LCheckSmi(value));
2001 LInstruction* LChunkBuilder::DoCheckInstanceType(HCheckInstanceType* instr) {
2002 LOperand* value = UseRegisterAtStart(instr->value());
2003 LCheckInstanceType* result = new(zone()) LCheckInstanceType(value);
2004 return AssignEnvironment(result);
2008 LInstruction* LChunkBuilder::DoCheckValue(HCheckValue* instr) {
2009 LOperand* value = UseRegisterAtStart(instr->value());
2010 return AssignEnvironment(new(zone()) LCheckValue(value));
2014 LInstruction* LChunkBuilder::DoCheckMaps(HCheckMaps* instr) {
2015 if (instr->IsStabilityCheck()) return new(zone()) LCheckMaps;
2016 LOperand* value = UseRegisterAtStart(instr->value());
2017 LInstruction* result = AssignEnvironment(new(zone()) LCheckMaps(value));
2018 if (instr->HasMigrationTarget()) {
2019 info()->MarkAsDeferredCalling();
2020 result = AssignPointerMap(result);
2026 LInstruction* LChunkBuilder::DoClampToUint8(HClampToUint8* instr) {
2027 HValue* value = instr->value();
2028 Representation input_rep = value->representation();
2029 LOperand* reg = UseRegister(value);
2030 if (input_rep.IsDouble()) {
2031 return DefineAsRegister(new(zone()) LClampDToUint8(reg));
2032 } else if (input_rep.IsInteger32()) {
2033 return DefineSameAsFirst(new(zone()) LClampIToUint8(reg));
2035 DCHECK(input_rep.IsSmiOrTagged());
2036 // Register allocator doesn't (yet) support allocation of double
2037 // temps. Reserve xmm1 explicitly.
2038 LClampTToUint8* result = new(zone()) LClampTToUint8(reg,
2040 return AssignEnvironment(DefineSameAsFirst(result));
2045 LInstruction* LChunkBuilder::DoDoubleBits(HDoubleBits* instr) {
2046 HValue* value = instr->value();
2047 DCHECK(value->representation().IsDouble());
2048 return DefineAsRegister(new(zone()) LDoubleBits(UseRegister(value)));
2052 LInstruction* LChunkBuilder::DoConstructDouble(HConstructDouble* instr) {
2053 LOperand* lo = UseRegister(instr->lo());
2054 LOperand* hi = UseRegister(instr->hi());
2055 return DefineAsRegister(new(zone()) LConstructDouble(hi, lo));
2059 LInstruction* LChunkBuilder::DoReturn(HReturn* instr) {
2060 LOperand* context = info()->IsStub() ? UseFixed(instr->context(), rsi) : NULL;
2061 LOperand* parameter_count = UseRegisterOrConstant(instr->parameter_count());
2062 return new(zone()) LReturn(
2063 UseFixed(instr->value(), rax), context, parameter_count);
2067 LInstruction* LChunkBuilder::DoConstant(HConstant* instr) {
2068 Representation r = instr->representation();
2070 return DefineAsRegister(new(zone()) LConstantS);
2071 } else if (r.IsInteger32()) {
2072 return DefineAsRegister(new(zone()) LConstantI);
2073 } else if (r.IsDouble()) {
2074 return DefineAsRegister(new (zone()) LConstantD);
2075 } else if (r.IsExternal()) {
2076 return DefineAsRegister(new(zone()) LConstantE);
2077 } else if (r.IsTagged()) {
2078 return DefineAsRegister(new(zone()) LConstantT);
2086 LInstruction* LChunkBuilder::DoLoadGlobalGeneric(HLoadGlobalGeneric* instr) {
2087 LOperand* context = UseFixed(instr->context(), rsi);
2088 LOperand* global_object =
2089 UseFixed(instr->global_object(), LoadDescriptor::ReceiverRegister());
2090 LOperand* vector = NULL;
2091 if (instr->HasVectorAndSlot()) {
2092 vector = FixedTemp(VectorLoadICDescriptor::VectorRegister());
2095 LLoadGlobalGeneric* result =
2096 new(zone()) LLoadGlobalGeneric(context, global_object, vector);
2097 return MarkAsCall(DefineFixed(result, rax), instr);
2101 LInstruction* LChunkBuilder::DoLoadContextSlot(HLoadContextSlot* instr) {
2102 LOperand* context = UseRegisterAtStart(instr->value());
2103 LInstruction* result =
2104 DefineAsRegister(new(zone()) LLoadContextSlot(context));
2105 if (instr->RequiresHoleCheck() && instr->DeoptimizesOnHole()) {
2106 result = AssignEnvironment(result);
2112 LInstruction* LChunkBuilder::DoStoreContextSlot(HStoreContextSlot* instr) {
2116 context = UseRegister(instr->context());
2117 if (instr->NeedsWriteBarrier()) {
2118 value = UseTempRegister(instr->value());
2119 temp = TempRegister();
2121 value = UseRegister(instr->value());
2124 LInstruction* result = new(zone()) LStoreContextSlot(context, value, temp);
2125 if (instr->RequiresHoleCheck() && instr->DeoptimizesOnHole()) {
2126 result = AssignEnvironment(result);
2132 LInstruction* LChunkBuilder::DoLoadNamedField(HLoadNamedField* instr) {
2133 // Use the special mov rax, moffs64 encoding for external
2134 // memory accesses with 64-bit word-sized values.
2135 if (instr->access().IsExternalMemory() &&
2136 instr->access().offset() == 0 &&
2137 (instr->access().representation().IsSmi() ||
2138 instr->access().representation().IsTagged() ||
2139 instr->access().representation().IsHeapObject() ||
2140 instr->access().representation().IsExternal())) {
2141 LOperand* obj = UseRegisterOrConstantAtStart(instr->object());
2142 return DefineFixed(new(zone()) LLoadNamedField(obj), rax);
2144 LOperand* obj = UseRegisterAtStart(instr->object());
2145 return DefineAsRegister(new(zone()) LLoadNamedField(obj));
2149 LInstruction* LChunkBuilder::DoLoadNamedGeneric(HLoadNamedGeneric* instr) {
2150 LOperand* context = UseFixed(instr->context(), rsi);
2152 UseFixed(instr->object(), LoadDescriptor::ReceiverRegister());
2153 LOperand* vector = NULL;
2154 if (instr->HasVectorAndSlot()) {
2155 vector = FixedTemp(VectorLoadICDescriptor::VectorRegister());
2157 LLoadNamedGeneric* result = new(zone()) LLoadNamedGeneric(
2158 context, object, vector);
2159 return MarkAsCall(DefineFixed(result, rax), instr);
2163 LInstruction* LChunkBuilder::DoLoadFunctionPrototype(
2164 HLoadFunctionPrototype* instr) {
2165 return AssignEnvironment(DefineAsRegister(
2166 new(zone()) LLoadFunctionPrototype(UseRegister(instr->function()))));
2170 LInstruction* LChunkBuilder::DoLoadRoot(HLoadRoot* instr) {
2171 return DefineAsRegister(new(zone()) LLoadRoot);
2175 void LChunkBuilder::FindDehoistedKeyDefinitions(HValue* candidate) {
2176 // We sign extend the dehoisted key at the definition point when the pointer
2177 // size is 64-bit. For x32 port, we sign extend the dehoisted key at the use
2178 // points and should not invoke this function. We can't use STATIC_ASSERT
2179 // here as the pointer size is 32-bit for x32.
2180 DCHECK(kPointerSize == kInt64Size);
2181 BitVector* dehoisted_key_ids = chunk_->GetDehoistedKeyIds();
2182 if (dehoisted_key_ids->Contains(candidate->id())) return;
2183 dehoisted_key_ids->Add(candidate->id());
2184 if (!candidate->IsPhi()) return;
2185 for (int i = 0; i < candidate->OperandCount(); ++i) {
2186 FindDehoistedKeyDefinitions(candidate->OperandAt(i));
2191 LInstruction* LChunkBuilder::DoLoadKeyed(HLoadKeyed* instr) {
2192 DCHECK((kPointerSize == kInt64Size &&
2193 instr->key()->representation().IsInteger32()) ||
2194 (kPointerSize == kInt32Size &&
2195 instr->key()->representation().IsSmiOrInteger32()));
2196 ElementsKind elements_kind = instr->elements_kind();
2197 LOperand* key = NULL;
2198 LInstruction* result = NULL;
2200 if (kPointerSize == kInt64Size) {
2201 key = UseRegisterOrConstantAtStart(instr->key());
2203 bool clobbers_key = ExternalArrayOpRequiresTemp(
2204 instr->key()->representation(), elements_kind);
2206 ? UseTempRegister(instr->key())
2207 : UseRegisterOrConstantAtStart(instr->key());
2210 if ((kPointerSize == kInt64Size) && instr->IsDehoisted()) {
2211 FindDehoistedKeyDefinitions(instr->key());
2214 if (!instr->is_typed_elements()) {
2215 LOperand* obj = UseRegisterAtStart(instr->elements());
2216 result = DefineAsRegister(new(zone()) LLoadKeyed(obj, key));
2219 (instr->representation().IsInteger32() &&
2220 !(IsDoubleOrFloatElementsKind(elements_kind))) ||
2221 (instr->representation().IsDouble() &&
2222 (IsDoubleOrFloatElementsKind(elements_kind))));
2223 LOperand* backing_store = UseRegister(instr->elements());
2224 result = DefineAsRegister(new(zone()) LLoadKeyed(backing_store, key));
2227 if ((instr->is_external() || instr->is_fixed_typed_array()) ?
2228 // see LCodeGen::DoLoadKeyedExternalArray
2229 ((elements_kind == EXTERNAL_UINT32_ELEMENTS ||
2230 elements_kind == UINT32_ELEMENTS) &&
2231 !instr->CheckFlag(HInstruction::kUint32)) :
2232 // see LCodeGen::DoLoadKeyedFixedDoubleArray and
2233 // LCodeGen::DoLoadKeyedFixedArray
2234 instr->RequiresHoleCheck()) {
2235 result = AssignEnvironment(result);
2241 LInstruction* LChunkBuilder::DoLoadKeyedGeneric(HLoadKeyedGeneric* instr) {
2242 LOperand* context = UseFixed(instr->context(), rsi);
2244 UseFixed(instr->object(), LoadDescriptor::ReceiverRegister());
2245 LOperand* key = UseFixed(instr->key(), LoadDescriptor::NameRegister());
2246 LOperand* vector = NULL;
2247 if (instr->HasVectorAndSlot()) {
2248 vector = FixedTemp(VectorLoadICDescriptor::VectorRegister());
2251 LLoadKeyedGeneric* result =
2252 new(zone()) LLoadKeyedGeneric(context, object, key, vector);
2253 return MarkAsCall(DefineFixed(result, rax), instr);
2257 LInstruction* LChunkBuilder::DoStoreKeyed(HStoreKeyed* instr) {
2258 ElementsKind elements_kind = instr->elements_kind();
2260 if ((kPointerSize == kInt64Size) && instr->IsDehoisted()) {
2261 FindDehoistedKeyDefinitions(instr->key());
2264 if (!instr->is_typed_elements()) {
2265 DCHECK(instr->elements()->representation().IsTagged());
2266 bool needs_write_barrier = instr->NeedsWriteBarrier();
2267 LOperand* object = NULL;
2268 LOperand* key = NULL;
2269 LOperand* val = NULL;
2271 Representation value_representation = instr->value()->representation();
2272 if (value_representation.IsDouble()) {
2273 object = UseRegisterAtStart(instr->elements());
2274 val = UseRegisterAtStart(instr->value());
2275 key = UseRegisterOrConstantAtStart(instr->key());
2277 DCHECK(value_representation.IsSmiOrTagged() ||
2278 value_representation.IsInteger32());
2279 if (needs_write_barrier) {
2280 object = UseTempRegister(instr->elements());
2281 val = UseTempRegister(instr->value());
2282 key = UseTempRegister(instr->key());
2284 object = UseRegisterAtStart(instr->elements());
2285 val = UseRegisterOrConstantAtStart(instr->value());
2286 key = UseRegisterOrConstantAtStart(instr->key());
2290 return new(zone()) LStoreKeyed(object, key, val);
2294 (instr->value()->representation().IsInteger32() &&
2295 !IsDoubleOrFloatElementsKind(elements_kind)) ||
2296 (instr->value()->representation().IsDouble() &&
2297 IsDoubleOrFloatElementsKind(elements_kind)));
2298 DCHECK((instr->is_fixed_typed_array() &&
2299 instr->elements()->representation().IsTagged()) ||
2300 (instr->is_external() &&
2301 instr->elements()->representation().IsExternal()));
2302 bool val_is_temp_register =
2303 elements_kind == EXTERNAL_UINT8_CLAMPED_ELEMENTS ||
2304 elements_kind == EXTERNAL_FLOAT32_ELEMENTS ||
2305 elements_kind == FLOAT32_ELEMENTS;
2306 LOperand* val = val_is_temp_register ? UseTempRegister(instr->value())
2307 : UseRegister(instr->value());
2308 LOperand* key = NULL;
2309 if (kPointerSize == kInt64Size) {
2310 key = UseRegisterOrConstantAtStart(instr->key());
2312 bool clobbers_key = ExternalArrayOpRequiresTemp(
2313 instr->key()->representation(), elements_kind);
2315 ? UseTempRegister(instr->key())
2316 : UseRegisterOrConstantAtStart(instr->key());
2318 LOperand* backing_store = UseRegister(instr->elements());
2319 return new(zone()) LStoreKeyed(backing_store, key, val);
2323 LInstruction* LChunkBuilder::DoStoreKeyedGeneric(HStoreKeyedGeneric* instr) {
2324 LOperand* context = UseFixed(instr->context(), rsi);
2326 UseFixed(instr->object(), StoreDescriptor::ReceiverRegister());
2327 LOperand* key = UseFixed(instr->key(), StoreDescriptor::NameRegister());
2328 LOperand* value = UseFixed(instr->value(), StoreDescriptor::ValueRegister());
2330 DCHECK(instr->object()->representation().IsTagged());
2331 DCHECK(instr->key()->representation().IsTagged());
2332 DCHECK(instr->value()->representation().IsTagged());
2334 LStoreKeyedGeneric* result =
2335 new(zone()) LStoreKeyedGeneric(context, object, key, value);
2336 return MarkAsCall(result, instr);
2340 LInstruction* LChunkBuilder::DoTransitionElementsKind(
2341 HTransitionElementsKind* instr) {
2342 if (IsSimpleMapChangeTransition(instr->from_kind(), instr->to_kind())) {
2343 LOperand* object = UseRegister(instr->object());
2344 LOperand* new_map_reg = TempRegister();
2345 LOperand* temp_reg = TempRegister();
2346 LTransitionElementsKind* result = new(zone()) LTransitionElementsKind(
2347 object, NULL, new_map_reg, temp_reg);
2350 LOperand* object = UseFixed(instr->object(), rax);
2351 LOperand* context = UseFixed(instr->context(), rsi);
2352 LTransitionElementsKind* result =
2353 new(zone()) LTransitionElementsKind(object, context, NULL, NULL);
2354 return MarkAsCall(result, instr);
2359 LInstruction* LChunkBuilder::DoTrapAllocationMemento(
2360 HTrapAllocationMemento* instr) {
2361 LOperand* object = UseRegister(instr->object());
2362 LOperand* temp = TempRegister();
2363 LTrapAllocationMemento* result =
2364 new(zone()) LTrapAllocationMemento(object, temp);
2365 return AssignEnvironment(result);
2369 LInstruction* LChunkBuilder::DoStoreNamedField(HStoreNamedField* instr) {
2370 bool is_in_object = instr->access().IsInobject();
2371 bool is_external_location = instr->access().IsExternalMemory() &&
2372 instr->access().offset() == 0;
2373 bool needs_write_barrier = instr->NeedsWriteBarrier();
2374 bool needs_write_barrier_for_map = instr->has_transition() &&
2375 instr->NeedsWriteBarrierForMap();
2378 if (needs_write_barrier) {
2380 ? UseRegister(instr->object())
2381 : UseTempRegister(instr->object());
2382 } else if (is_external_location) {
2383 DCHECK(!is_in_object);
2384 DCHECK(!needs_write_barrier);
2385 DCHECK(!needs_write_barrier_for_map);
2386 obj = UseRegisterOrConstant(instr->object());
2388 obj = needs_write_barrier_for_map
2389 ? UseRegister(instr->object())
2390 : UseRegisterAtStart(instr->object());
2393 bool can_be_constant = instr->value()->IsConstant() &&
2394 HConstant::cast(instr->value())->NotInNewSpace() &&
2395 !instr->field_representation().IsDouble();
2398 if (needs_write_barrier) {
2399 val = UseTempRegister(instr->value());
2400 } else if (is_external_location) {
2401 val = UseFixed(instr->value(), rax);
2402 } else if (can_be_constant) {
2403 val = UseRegisterOrConstant(instr->value());
2404 } else if (instr->field_representation().IsDouble()) {
2405 val = UseRegisterAtStart(instr->value());
2407 val = UseRegister(instr->value());
2410 // We only need a scratch register if we have a write barrier or we
2411 // have a store into the properties array (not in-object-property).
2412 LOperand* temp = (!is_in_object || needs_write_barrier ||
2413 needs_write_barrier_for_map) ? TempRegister() : NULL;
2415 return new(zone()) LStoreNamedField(obj, val, temp);
2419 LInstruction* LChunkBuilder::DoStoreNamedGeneric(HStoreNamedGeneric* instr) {
2420 LOperand* context = UseFixed(instr->context(), rsi);
2422 UseFixed(instr->object(), StoreDescriptor::ReceiverRegister());
2423 LOperand* value = UseFixed(instr->value(), StoreDescriptor::ValueRegister());
2425 LStoreNamedGeneric* result =
2426 new(zone()) LStoreNamedGeneric(context, object, value);
2427 return MarkAsCall(result, instr);
2431 LInstruction* LChunkBuilder::DoStringAdd(HStringAdd* instr) {
2432 LOperand* context = UseFixed(instr->context(), rsi);
2433 LOperand* left = UseFixed(instr->left(), rdx);
2434 LOperand* right = UseFixed(instr->right(), rax);
2436 DefineFixed(new(zone()) LStringAdd(context, left, right), rax), instr);
2440 LInstruction* LChunkBuilder::DoStringCharCodeAt(HStringCharCodeAt* instr) {
2441 LOperand* string = UseTempRegister(instr->string());
2442 LOperand* index = UseTempRegister(instr->index());
2443 LOperand* context = UseAny(instr->context());
2444 LStringCharCodeAt* result =
2445 new(zone()) LStringCharCodeAt(context, string, index);
2446 return AssignPointerMap(DefineAsRegister(result));
2450 LInstruction* LChunkBuilder::DoStringCharFromCode(HStringCharFromCode* instr) {
2451 LOperand* char_code = UseRegister(instr->value());
2452 LOperand* context = UseAny(instr->context());
2453 LStringCharFromCode* result =
2454 new(zone()) LStringCharFromCode(context, char_code);
2455 return AssignPointerMap(DefineAsRegister(result));
2459 LInstruction* LChunkBuilder::DoAllocate(HAllocate* instr) {
2460 info()->MarkAsDeferredCalling();
2461 LOperand* context = UseAny(instr->context());
2462 LOperand* size = instr->size()->IsConstant()
2463 ? UseConstant(instr->size())
2464 : UseTempRegister(instr->size());
2465 LOperand* temp = TempRegister();
2466 LAllocate* result = new(zone()) LAllocate(context, size, temp);
2467 return AssignPointerMap(DefineAsRegister(result));
2471 LInstruction* LChunkBuilder::DoRegExpLiteral(HRegExpLiteral* instr) {
2472 LOperand* context = UseFixed(instr->context(), rsi);
2473 LRegExpLiteral* result = new(zone()) LRegExpLiteral(context);
2474 return MarkAsCall(DefineFixed(result, rax), instr);
2478 LInstruction* LChunkBuilder::DoFunctionLiteral(HFunctionLiteral* instr) {
2479 LOperand* context = UseFixed(instr->context(), rsi);
2480 LFunctionLiteral* result = new(zone()) LFunctionLiteral(context);
2481 return MarkAsCall(DefineFixed(result, rax), instr);
2485 LInstruction* LChunkBuilder::DoOsrEntry(HOsrEntry* instr) {
2486 DCHECK(argument_count_ == 0);
2487 allocator_->MarkAsOsrEntry();
2488 current_block_->last_environment()->set_ast_id(instr->ast_id());
2489 return AssignEnvironment(new(zone()) LOsrEntry);
2493 LInstruction* LChunkBuilder::DoParameter(HParameter* instr) {
2494 LParameter* result = new(zone()) LParameter;
2495 if (instr->kind() == HParameter::STACK_PARAMETER) {
2496 int spill_index = chunk()->GetParameterStackSlot(instr->index());
2497 return DefineAsSpilled(result, spill_index);
2499 DCHECK(info()->IsStub());
2500 CallInterfaceDescriptor descriptor =
2501 info()->code_stub()->GetCallInterfaceDescriptor();
2502 int index = static_cast<int>(instr->index());
2503 Register reg = descriptor.GetEnvironmentParameterRegister(index);
2504 return DefineFixed(result, reg);
2509 LInstruction* LChunkBuilder::DoUnknownOSRValue(HUnknownOSRValue* instr) {
2510 // Use an index that corresponds to the location in the unoptimized frame,
2511 // which the optimized frame will subsume.
2512 int env_index = instr->index();
2513 int spill_index = 0;
2514 if (instr->environment()->is_parameter_index(env_index)) {
2515 spill_index = chunk()->GetParameterStackSlot(env_index);
2517 spill_index = env_index - instr->environment()->first_local_index();
2518 if (spill_index > LUnallocated::kMaxFixedSlotIndex) {
2519 Retry(kTooManySpillSlotsNeededForOSR);
2523 return DefineAsSpilled(new(zone()) LUnknownOSRValue, spill_index);
2527 LInstruction* LChunkBuilder::DoCallStub(HCallStub* instr) {
2528 LOperand* context = UseFixed(instr->context(), rsi);
2529 LCallStub* result = new(zone()) LCallStub(context);
2530 return MarkAsCall(DefineFixed(result, rax), instr);
2534 LInstruction* LChunkBuilder::DoArgumentsObject(HArgumentsObject* instr) {
2535 // There are no real uses of the arguments object.
2536 // arguments.length and element access are supported directly on
2537 // stack arguments, and any real arguments object use causes a bailout.
2538 // So this value is never used.
2543 LInstruction* LChunkBuilder::DoCapturedObject(HCapturedObject* instr) {
2544 instr->ReplayEnvironment(current_block_->last_environment());
2546 // There are no real uses of a captured object.
2551 LInstruction* LChunkBuilder::DoAccessArgumentsAt(HAccessArgumentsAt* instr) {
2552 info()->MarkAsRequiresFrame();
2553 LOperand* args = UseRegister(instr->arguments());
2556 if (instr->length()->IsConstant() && instr->index()->IsConstant()) {
2557 length = UseRegisterOrConstant(instr->length());
2558 index = UseOrConstant(instr->index());
2560 length = UseTempRegister(instr->length());
2561 index = Use(instr->index());
2563 return DefineAsRegister(new(zone()) LAccessArgumentsAt(args, length, index));
2567 LInstruction* LChunkBuilder::DoToFastProperties(HToFastProperties* instr) {
2568 LOperand* object = UseFixed(instr->value(), rax);
2569 LToFastProperties* result = new(zone()) LToFastProperties(object);
2570 return MarkAsCall(DefineFixed(result, rax), instr);
2574 LInstruction* LChunkBuilder::DoTypeof(HTypeof* instr) {
2575 LOperand* context = UseFixed(instr->context(), rsi);
2576 LOperand* value = UseAtStart(instr->value());
2577 LTypeof* result = new(zone()) LTypeof(context, value);
2578 return MarkAsCall(DefineFixed(result, rax), instr);
2582 LInstruction* LChunkBuilder::DoTypeofIsAndBranch(HTypeofIsAndBranch* instr) {
2583 return new(zone()) LTypeofIsAndBranch(UseTempRegister(instr->value()));
2587 LInstruction* LChunkBuilder::DoIsConstructCallAndBranch(
2588 HIsConstructCallAndBranch* instr) {
2589 return new(zone()) LIsConstructCallAndBranch(TempRegister());
2593 LInstruction* LChunkBuilder::DoSimulate(HSimulate* instr) {
2594 instr->ReplayEnvironment(current_block_->last_environment());
2599 LInstruction* LChunkBuilder::DoStackCheck(HStackCheck* instr) {
2600 info()->MarkAsDeferredCalling();
2601 if (instr->is_function_entry()) {
2602 LOperand* context = UseFixed(instr->context(), rsi);
2603 return MarkAsCall(new(zone()) LStackCheck(context), instr);
2605 DCHECK(instr->is_backwards_branch());
2606 LOperand* context = UseAny(instr->context());
2607 return AssignEnvironment(
2608 AssignPointerMap(new(zone()) LStackCheck(context)));
2613 LInstruction* LChunkBuilder::DoEnterInlined(HEnterInlined* instr) {
2614 HEnvironment* outer = current_block_->last_environment();
2615 outer->set_ast_id(instr->ReturnId());
2616 HConstant* undefined = graph()->GetConstantUndefined();
2617 HEnvironment* inner = outer->CopyForInlining(instr->closure(),
2618 instr->arguments_count(),
2621 instr->inlining_kind());
2622 // Only replay binding of arguments object if it wasn't removed from graph.
2623 if (instr->arguments_var() != NULL && instr->arguments_object()->IsLinked()) {
2624 inner->Bind(instr->arguments_var(), instr->arguments_object());
2626 inner->BindContext(instr->closure_context());
2627 inner->set_entry(instr);
2628 current_block_->UpdateEnvironment(inner);
2629 chunk_->AddInlinedClosure(instr->closure());
2634 LInstruction* LChunkBuilder::DoLeaveInlined(HLeaveInlined* instr) {
2635 LInstruction* pop = NULL;
2637 HEnvironment* env = current_block_->last_environment();
2639 if (env->entry()->arguments_pushed()) {
2640 int argument_count = env->arguments_environment()->parameter_count();
2641 pop = new(zone()) LDrop(argument_count);
2642 DCHECK(instr->argument_delta() == -argument_count);
2645 HEnvironment* outer = current_block_->last_environment()->
2646 DiscardInlined(false);
2647 current_block_->UpdateEnvironment(outer);
2653 LInstruction* LChunkBuilder::DoForInPrepareMap(HForInPrepareMap* instr) {
2654 LOperand* context = UseFixed(instr->context(), rsi);
2655 LOperand* object = UseFixed(instr->enumerable(), rax);
2656 LForInPrepareMap* result = new(zone()) LForInPrepareMap(context, object);
2657 return MarkAsCall(DefineFixed(result, rax), instr, CAN_DEOPTIMIZE_EAGERLY);
2661 LInstruction* LChunkBuilder::DoForInCacheArray(HForInCacheArray* instr) {
2662 LOperand* map = UseRegister(instr->map());
2663 return AssignEnvironment(DefineAsRegister(
2664 new(zone()) LForInCacheArray(map)));
2668 LInstruction* LChunkBuilder::DoCheckMapValue(HCheckMapValue* instr) {
2669 LOperand* value = UseRegisterAtStart(instr->value());
2670 LOperand* map = UseRegisterAtStart(instr->map());
2671 return AssignEnvironment(new(zone()) LCheckMapValue(value, map));
2675 LInstruction* LChunkBuilder::DoLoadFieldByIndex(HLoadFieldByIndex* instr) {
2676 LOperand* object = UseRegister(instr->object());
2677 LOperand* index = UseTempRegister(instr->index());
2678 LLoadFieldByIndex* load = new(zone()) LLoadFieldByIndex(object, index);
2679 LInstruction* result = DefineSameAsFirst(load);
2680 return AssignPointerMap(result);
2684 LInstruction* LChunkBuilder::DoStoreFrameContext(HStoreFrameContext* instr) {
2685 LOperand* context = UseRegisterAtStart(instr->context());
2686 return new(zone()) LStoreFrameContext(context);
2690 LInstruction* LChunkBuilder::DoAllocateBlockContext(
2691 HAllocateBlockContext* instr) {
2692 LOperand* context = UseFixed(instr->context(), rsi);
2693 LOperand* function = UseRegisterAtStart(instr->function());
2694 LAllocateBlockContext* result =
2695 new(zone()) LAllocateBlockContext(context, function);
2696 return MarkAsCall(DefineFixed(result, rsi), instr);
2700 } } // namespace v8::internal
2702 #endif // V8_TARGET_ARCH_X64