1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
9 #include "src/hydrogen-osr.h"
10 #include "src/lithium-inl.h"
11 #include "src/x64/lithium-codegen-x64.h"
16 #define DEFINE_COMPILE(type) \
17 void L##type::CompileToNative(LCodeGen* generator) { \
18 generator->Do##type(this); \
20 LITHIUM_CONCRETE_INSTRUCTION_LIST(DEFINE_COMPILE)
25 void LInstruction::VerifyCall() {
26 // Call instructions can use only fixed registers as temporaries and
27 // outputs because all registers are blocked by the calling convention.
28 // Inputs operands must use a fixed register or use-at-start policy or
29 // a non-register policy.
30 DCHECK(Output() == NULL ||
31 LUnallocated::cast(Output())->HasFixedPolicy() ||
32 !LUnallocated::cast(Output())->HasRegisterPolicy());
33 for (UseIterator it(this); !it.Done(); it.Advance()) {
34 LUnallocated* operand = LUnallocated::cast(it.Current());
35 DCHECK(operand->HasFixedPolicy() ||
36 operand->IsUsedAtStart());
38 for (TempIterator it(this); !it.Done(); it.Advance()) {
39 LUnallocated* operand = LUnallocated::cast(it.Current());
40 DCHECK(operand->HasFixedPolicy() ||!operand->HasRegisterPolicy());
46 void LInstruction::PrintTo(StringStream* stream) {
47 stream->Add("%s ", this->Mnemonic());
49 PrintOutputOperandTo(stream);
53 if (HasEnvironment()) {
55 environment()->PrintTo(stream);
58 if (HasPointerMap()) {
60 pointer_map()->PrintTo(stream);
65 void LInstruction::PrintDataTo(StringStream* stream) {
67 for (int i = 0; i < InputCount(); i++) {
68 if (i > 0) stream->Add(" ");
69 if (InputAt(i) == NULL) {
72 InputAt(i)->PrintTo(stream);
78 void LInstruction::PrintOutputOperandTo(StringStream* stream) {
79 if (HasResult()) result()->PrintTo(stream);
83 void LLabel::PrintDataTo(StringStream* stream) {
84 LGap::PrintDataTo(stream);
85 LLabel* rep = replacement();
87 stream->Add(" Dead block replaced with B%d", rep->block_id());
92 bool LGap::IsRedundant() const {
93 for (int i = 0; i < 4; i++) {
94 if (parallel_moves_[i] != NULL && !parallel_moves_[i]->IsRedundant()) {
103 void LGap::PrintDataTo(StringStream* stream) {
104 for (int i = 0; i < 4; i++) {
106 if (parallel_moves_[i] != NULL) {
107 parallel_moves_[i]->PrintDataTo(stream);
114 const char* LArithmeticD::Mnemonic() const {
116 case Token::ADD: return "add-d";
117 case Token::SUB: return "sub-d";
118 case Token::MUL: return "mul-d";
119 case Token::DIV: return "div-d";
120 case Token::MOD: return "mod-d";
128 const char* LArithmeticT::Mnemonic() const {
130 case Token::ADD: return "add-t";
131 case Token::SUB: return "sub-t";
132 case Token::MUL: return "mul-t";
133 case Token::MOD: return "mod-t";
134 case Token::DIV: return "div-t";
135 case Token::BIT_AND: return "bit-and-t";
136 case Token::BIT_OR: return "bit-or-t";
137 case Token::BIT_XOR: return "bit-xor-t";
138 case Token::ROR: return "ror-t";
139 case Token::SHL: return "sal-t";
140 case Token::SAR: return "sar-t";
141 case Token::SHR: return "shr-t";
149 bool LGoto::HasInterestingComment(LCodeGen* gen) const {
150 return !gen->IsNextEmittedBlock(block_id());
155 bool LTemplateResultInstruction<R>::MustSignExtendResult(
156 LPlatformChunk* chunk) const {
157 HValue* hvalue = this->hydrogen_value();
158 return hvalue != NULL &&
159 hvalue->representation().IsInteger32() &&
160 chunk->GetDehoistedKeyIds()->Contains(hvalue->id());
164 void LGoto::PrintDataTo(StringStream* stream) {
165 stream->Add("B%d", block_id());
169 void LBranch::PrintDataTo(StringStream* stream) {
170 stream->Add("B%d | B%d on ", true_block_id(), false_block_id());
171 value()->PrintTo(stream);
175 void LCompareNumericAndBranch::PrintDataTo(StringStream* stream) {
177 left()->PrintTo(stream);
178 stream->Add(" %s ", Token::String(op()));
179 right()->PrintTo(stream);
180 stream->Add(" then B%d else B%d", true_block_id(), false_block_id());
184 void LIsObjectAndBranch::PrintDataTo(StringStream* stream) {
185 stream->Add("if is_object(");
186 value()->PrintTo(stream);
187 stream->Add(") then B%d else B%d", true_block_id(), false_block_id());
191 void LIsStringAndBranch::PrintDataTo(StringStream* stream) {
192 stream->Add("if is_string(");
193 value()->PrintTo(stream);
194 stream->Add(") then B%d else B%d", true_block_id(), false_block_id());
198 void LIsSmiAndBranch::PrintDataTo(StringStream* stream) {
199 stream->Add("if is_smi(");
200 value()->PrintTo(stream);
201 stream->Add(") then B%d else B%d", true_block_id(), false_block_id());
205 void LIsUndetectableAndBranch::PrintDataTo(StringStream* stream) {
206 stream->Add("if is_undetectable(");
207 value()->PrintTo(stream);
208 stream->Add(") then B%d else B%d", true_block_id(), false_block_id());
212 void LStringCompareAndBranch::PrintDataTo(StringStream* stream) {
213 stream->Add("if string_compare(");
214 left()->PrintTo(stream);
215 right()->PrintTo(stream);
216 stream->Add(") then B%d else B%d", true_block_id(), false_block_id());
220 void LHasInstanceTypeAndBranch::PrintDataTo(StringStream* stream) {
221 stream->Add("if has_instance_type(");
222 value()->PrintTo(stream);
223 stream->Add(") then B%d else B%d", true_block_id(), false_block_id());
227 void LHasCachedArrayIndexAndBranch::PrintDataTo(StringStream* stream) {
228 stream->Add("if has_cached_array_index(");
229 value()->PrintTo(stream);
230 stream->Add(") then B%d else B%d", true_block_id(), false_block_id());
234 void LClassOfTestAndBranch::PrintDataTo(StringStream* stream) {
235 stream->Add("if class_of_test(");
236 value()->PrintTo(stream);
237 stream->Add(", \"%o\") then B%d else B%d",
238 *hydrogen()->class_name(),
244 void LTypeofIsAndBranch::PrintDataTo(StringStream* stream) {
245 stream->Add("if typeof ");
246 value()->PrintTo(stream);
247 stream->Add(" == \"%s\" then B%d else B%d",
248 hydrogen()->type_literal()->ToCString().get(),
249 true_block_id(), false_block_id());
253 void LStoreCodeEntry::PrintDataTo(StringStream* stream) {
255 function()->PrintTo(stream);
256 stream->Add(".code_entry = ");
257 code_object()->PrintTo(stream);
261 void LInnerAllocatedObject::PrintDataTo(StringStream* stream) {
263 base_object()->PrintTo(stream);
265 offset()->PrintTo(stream);
269 void LCallFunction::PrintDataTo(StringStream* stream) {
270 context()->PrintTo(stream);
272 function()->PrintTo(stream);
273 if (hydrogen()->HasVectorAndSlot()) {
274 stream->Add(" (type-feedback-vector ");
275 temp_vector()->PrintTo(stream);
277 temp_slot()->PrintTo(stream);
283 void LCallJSFunction::PrintDataTo(StringStream* stream) {
285 function()->PrintTo(stream);
286 stream->Add("#%d / ", arity());
290 void LCallWithDescriptor::PrintDataTo(StringStream* stream) {
291 for (int i = 0; i < InputCount(); i++) {
292 InputAt(i)->PrintTo(stream);
295 stream->Add("#%d / ", arity());
299 void LLoadContextSlot::PrintDataTo(StringStream* stream) {
300 context()->PrintTo(stream);
301 stream->Add("[%d]", slot_index());
305 void LStoreContextSlot::PrintDataTo(StringStream* stream) {
306 context()->PrintTo(stream);
307 stream->Add("[%d] <- ", slot_index());
308 value()->PrintTo(stream);
312 void LInvokeFunction::PrintDataTo(StringStream* stream) {
314 function()->PrintTo(stream);
315 stream->Add(" #%d / ", arity());
319 void LCallNew::PrintDataTo(StringStream* stream) {
321 constructor()->PrintTo(stream);
322 stream->Add(" #%d / ", arity());
326 void LCallNewArray::PrintDataTo(StringStream* stream) {
328 constructor()->PrintTo(stream);
329 stream->Add(" #%d / ", arity());
330 ElementsKind kind = hydrogen()->elements_kind();
331 stream->Add(" (%s) ", ElementsKindToString(kind));
335 void LAccessArgumentsAt::PrintDataTo(StringStream* stream) {
336 arguments()->PrintTo(stream);
338 stream->Add(" length ");
339 length()->PrintTo(stream);
341 stream->Add(" index ");
342 index()->PrintTo(stream);
346 int LPlatformChunk::GetNextSpillIndex(RegisterKind kind) {
347 if (kind == DOUBLE_REGISTERS && kDoubleSize == 2 * kPointerSize) {
348 // Skip a slot if for a double-width slot for x32 port.
350 // The spill slot's address is at rbp - (index + 1) * kPointerSize -
351 // StandardFrameConstants::kFixedFrameSizeFromFp. kFixedFrameSizeFromFp is
352 // 2 * kPointerSize, if rbp is aligned at 8-byte boundary, the below "|= 1"
353 // will make sure the spilled doubles are aligned at 8-byte boundary.
354 // TODO(haitao): make sure rbp is aligned at 8-byte boundary for x32 port.
355 spill_slot_count_ |= 1;
357 return spill_slot_count_++;
361 LOperand* LPlatformChunk::GetNextSpillSlot(RegisterKind kind) {
362 // All stack slots are Double stack slots on x64.
363 // Alternatively, at some point, start using half-size
364 // stack slots for int32 values.
365 int index = GetNextSpillIndex(kind);
366 if (kind == DOUBLE_REGISTERS) {
367 return LDoubleStackSlot::Create(index, zone());
369 DCHECK(kind == GENERAL_REGISTERS);
370 return LStackSlot::Create(index, zone());
375 void LLoadGlobalViaContext::PrintDataTo(StringStream* stream) {
376 stream->Add("depth:%d slot:%d", depth(), slot_index());
380 void LStoreNamedField::PrintDataTo(StringStream* stream) {
381 object()->PrintTo(stream);
382 std::ostringstream os;
383 os << hydrogen()->access() << " <- ";
384 stream->Add(os.str().c_str());
385 value()->PrintTo(stream);
389 void LStoreNamedGeneric::PrintDataTo(StringStream* stream) {
390 object()->PrintTo(stream);
392 stream->Add(String::cast(*name())->ToCString().get());
394 value()->PrintTo(stream);
398 void LStoreGlobalViaContext::PrintDataTo(StringStream* stream) {
399 stream->Add("depth:%d slot:%d <- ", depth(), slot_index());
400 value()->PrintTo(stream);
404 void LLoadKeyed::PrintDataTo(StringStream* stream) {
405 elements()->PrintTo(stream);
407 key()->PrintTo(stream);
408 if (hydrogen()->IsDehoisted()) {
409 stream->Add(" + %d]", base_offset());
416 void LStoreKeyed::PrintDataTo(StringStream* stream) {
417 elements()->PrintTo(stream);
419 key()->PrintTo(stream);
420 if (hydrogen()->IsDehoisted()) {
421 stream->Add(" + %d] <-", base_offset());
423 stream->Add("] <- ");
426 if (value() == NULL) {
427 DCHECK(hydrogen()->IsConstantHoleStore() &&
428 hydrogen()->value()->representation().IsDouble());
429 stream->Add("<the hole(nan)>");
431 value()->PrintTo(stream);
436 void LStoreKeyedGeneric::PrintDataTo(StringStream* stream) {
437 object()->PrintTo(stream);
439 key()->PrintTo(stream);
440 stream->Add("] <- ");
441 value()->PrintTo(stream);
445 void LTransitionElementsKind::PrintDataTo(StringStream* stream) {
446 object()->PrintTo(stream);
447 stream->Add(" %p -> %p", *original_map(), *transitioned_map());
451 LPlatformChunk* LChunkBuilder::Build() {
453 chunk_ = new(zone()) LPlatformChunk(info(), graph());
454 LPhase phase("L_Building chunk", chunk_);
457 // If compiling for OSR, reserve space for the unoptimized frame,
458 // which will be subsumed into this frame.
459 if (graph()->has_osr()) {
460 for (int i = graph()->osr()->UnoptimizedFrameSlots(); i > 0; i--) {
461 chunk_->GetNextSpillIndex(GENERAL_REGISTERS);
465 const ZoneList<HBasicBlock*>* blocks = graph()->blocks();
466 for (int i = 0; i < blocks->length(); i++) {
467 HBasicBlock* next = NULL;
468 if (i < blocks->length() - 1) next = blocks->at(i + 1);
469 DoBasicBlock(blocks->at(i), next);
470 if (is_aborted()) return NULL;
477 LUnallocated* LChunkBuilder::ToUnallocated(Register reg) {
478 return new(zone()) LUnallocated(LUnallocated::FIXED_REGISTER,
479 Register::ToAllocationIndex(reg));
483 LUnallocated* LChunkBuilder::ToUnallocated(XMMRegister reg) {
484 return new(zone()) LUnallocated(LUnallocated::FIXED_DOUBLE_REGISTER,
485 XMMRegister::ToAllocationIndex(reg));
489 LOperand* LChunkBuilder::UseFixed(HValue* value, Register fixed_register) {
490 return Use(value, ToUnallocated(fixed_register));
494 LOperand* LChunkBuilder::UseFixedDouble(HValue* value, XMMRegister reg) {
495 return Use(value, ToUnallocated(reg));
499 LOperand* LChunkBuilder::UseRegister(HValue* value) {
500 return Use(value, new(zone()) LUnallocated(LUnallocated::MUST_HAVE_REGISTER));
504 LOperand* LChunkBuilder::UseRegisterAtStart(HValue* value) {
506 new(zone()) LUnallocated(LUnallocated::MUST_HAVE_REGISTER,
507 LUnallocated::USED_AT_START));
511 LOperand* LChunkBuilder::UseTempRegister(HValue* value) {
512 return Use(value, new(zone()) LUnallocated(LUnallocated::WRITABLE_REGISTER));
516 LOperand* LChunkBuilder::UseTempRegisterOrConstant(HValue* value) {
517 return value->IsConstant()
518 ? chunk_->DefineConstantOperand(HConstant::cast(value))
519 : UseTempRegister(value);
523 LOperand* LChunkBuilder::Use(HValue* value) {
524 return Use(value, new(zone()) LUnallocated(LUnallocated::NONE));
528 LOperand* LChunkBuilder::UseAtStart(HValue* value) {
529 return Use(value, new(zone()) LUnallocated(LUnallocated::NONE,
530 LUnallocated::USED_AT_START));
534 LOperand* LChunkBuilder::UseOrConstant(HValue* value) {
535 return value->IsConstant()
536 ? chunk_->DefineConstantOperand(HConstant::cast(value))
541 LOperand* LChunkBuilder::UseOrConstantAtStart(HValue* value) {
542 return value->IsConstant()
543 ? chunk_->DefineConstantOperand(HConstant::cast(value))
548 LOperand* LChunkBuilder::UseRegisterOrConstant(HValue* value) {
549 return value->IsConstant()
550 ? chunk_->DefineConstantOperand(HConstant::cast(value))
551 : UseRegister(value);
555 LOperand* LChunkBuilder::UseRegisterOrConstantAtStart(HValue* value) {
556 return value->IsConstant()
557 ? chunk_->DefineConstantOperand(HConstant::cast(value))
558 : UseRegisterAtStart(value);
562 LOperand* LChunkBuilder::UseConstant(HValue* value) {
563 return chunk_->DefineConstantOperand(HConstant::cast(value));
567 LOperand* LChunkBuilder::UseAny(HValue* value) {
568 return value->IsConstant()
569 ? chunk_->DefineConstantOperand(HConstant::cast(value))
570 : Use(value, new(zone()) LUnallocated(LUnallocated::ANY));
574 LOperand* LChunkBuilder::Use(HValue* value, LUnallocated* operand) {
575 if (value->EmitAtUses()) {
576 HInstruction* instr = HInstruction::cast(value);
577 VisitInstruction(instr);
579 operand->set_virtual_register(value->id());
584 LInstruction* LChunkBuilder::Define(LTemplateResultInstruction<1>* instr,
585 LUnallocated* result) {
586 result->set_virtual_register(current_instruction_->id());
587 instr->set_result(result);
592 LInstruction* LChunkBuilder::DefineAsRegister(
593 LTemplateResultInstruction<1>* instr) {
595 new(zone()) LUnallocated(LUnallocated::MUST_HAVE_REGISTER));
599 LInstruction* LChunkBuilder::DefineAsSpilled(
600 LTemplateResultInstruction<1>* instr,
603 new(zone()) LUnallocated(LUnallocated::FIXED_SLOT, index));
607 LInstruction* LChunkBuilder::DefineSameAsFirst(
608 LTemplateResultInstruction<1>* instr) {
610 new(zone()) LUnallocated(LUnallocated::SAME_AS_FIRST_INPUT));
614 LInstruction* LChunkBuilder::DefineFixed(LTemplateResultInstruction<1>* instr,
616 return Define(instr, ToUnallocated(reg));
620 LInstruction* LChunkBuilder::DefineFixedDouble(
621 LTemplateResultInstruction<1>* instr,
623 return Define(instr, ToUnallocated(reg));
627 LInstruction* LChunkBuilder::AssignEnvironment(LInstruction* instr) {
628 HEnvironment* hydrogen_env = current_block_->last_environment();
629 int argument_index_accumulator = 0;
630 ZoneList<HValue*> objects_to_materialize(0, zone());
631 instr->set_environment(CreateEnvironment(
632 hydrogen_env, &argument_index_accumulator, &objects_to_materialize));
637 LInstruction* LChunkBuilder::MarkAsCall(LInstruction* instr,
638 HInstruction* hinstr,
639 CanDeoptimize can_deoptimize) {
640 info()->MarkAsNonDeferredCalling();
646 instr = AssignPointerMap(instr);
648 // If instruction does not have side-effects lazy deoptimization
649 // after the call will try to deoptimize to the point before the call.
650 // Thus we still need to attach environment to this call even if
651 // call sequence can not deoptimize eagerly.
652 bool needs_environment =
653 (can_deoptimize == CAN_DEOPTIMIZE_EAGERLY) ||
654 !hinstr->HasObservableSideEffects();
655 if (needs_environment && !instr->HasEnvironment()) {
656 instr = AssignEnvironment(instr);
657 // We can't really figure out if the environment is needed or not.
658 instr->environment()->set_has_been_used();
665 LInstruction* LChunkBuilder::AssignPointerMap(LInstruction* instr) {
666 DCHECK(!instr->HasPointerMap());
667 instr->set_pointer_map(new(zone()) LPointerMap(zone()));
672 LUnallocated* LChunkBuilder::TempRegister() {
673 LUnallocated* operand =
674 new(zone()) LUnallocated(LUnallocated::MUST_HAVE_REGISTER);
675 int vreg = allocator_->GetVirtualRegister();
676 if (!allocator_->AllocationOk()) {
677 Abort(kOutOfVirtualRegistersWhileTryingToAllocateTempRegister);
680 operand->set_virtual_register(vreg);
685 LOperand* LChunkBuilder::FixedTemp(Register reg) {
686 LUnallocated* operand = ToUnallocated(reg);
687 DCHECK(operand->HasFixedPolicy());
692 LOperand* LChunkBuilder::FixedTemp(XMMRegister reg) {
693 LUnallocated* operand = ToUnallocated(reg);
694 DCHECK(operand->HasFixedPolicy());
699 LInstruction* LChunkBuilder::DoBlockEntry(HBlockEntry* instr) {
700 return new(zone()) LLabel(instr->block());
704 LInstruction* LChunkBuilder::DoDummyUse(HDummyUse* instr) {
705 return DefineAsRegister(new(zone()) LDummyUse(UseAny(instr->value())));
709 LInstruction* LChunkBuilder::DoEnvironmentMarker(HEnvironmentMarker* instr) {
715 LInstruction* LChunkBuilder::DoDeoptimize(HDeoptimize* instr) {
716 return AssignEnvironment(new(zone()) LDeoptimize);
720 LInstruction* LChunkBuilder::DoShift(Token::Value op,
721 HBitwiseBinaryOperation* instr) {
722 if (instr->representation().IsSmiOrInteger32()) {
723 DCHECK(instr->left()->representation().Equals(instr->representation()));
724 DCHECK(instr->right()->representation().Equals(instr->representation()));
725 LOperand* left = UseRegisterAtStart(instr->left());
727 HValue* right_value = instr->right();
728 LOperand* right = NULL;
729 int constant_value = 0;
730 bool does_deopt = false;
731 if (right_value->IsConstant()) {
732 HConstant* constant = HConstant::cast(right_value);
733 right = chunk_->DefineConstantOperand(constant);
734 constant_value = constant->Integer32Value() & 0x1f;
735 if (SmiValuesAre31Bits() && instr->representation().IsSmi() &&
736 constant_value > 0) {
737 // Left shift can deoptimize if we shift by > 0 and the result
738 // cannot be truncated to smi.
739 does_deopt = !instr->CheckUsesForFlag(HValue::kTruncatingToSmi);
742 right = UseFixed(right_value, rcx);
745 // Shift operations can only deoptimize if we do a logical shift by 0 and
746 // the result cannot be truncated to int32.
747 if (op == Token::SHR && constant_value == 0) {
748 does_deopt = !instr->CheckFlag(HInstruction::kUint32);
751 LInstruction* result =
752 DefineSameAsFirst(new(zone()) LShiftI(op, left, right, does_deopt));
753 return does_deopt ? AssignEnvironment(result) : result;
755 return DoArithmeticT(op, instr);
760 LInstruction* LChunkBuilder::DoArithmeticD(Token::Value op,
761 HArithmeticBinaryOperation* instr) {
762 DCHECK(instr->representation().IsDouble());
763 DCHECK(instr->left()->representation().IsDouble());
764 DCHECK(instr->right()->representation().IsDouble());
765 if (op == Token::MOD) {
766 LOperand* left = UseRegisterAtStart(instr->BetterLeftOperand());
767 LOperand* right = UseFixedDouble(instr->BetterRightOperand(), xmm1);
768 LArithmeticD* result = new(zone()) LArithmeticD(op, left, right);
769 return MarkAsCall(DefineSameAsFirst(result), instr);
771 LOperand* left = UseRegisterAtStart(instr->BetterLeftOperand());
772 LOperand* right = UseRegisterAtStart(instr->BetterRightOperand());
773 LArithmeticD* result = new(zone()) LArithmeticD(op, left, right);
774 return CpuFeatures::IsSupported(AVX) ? DefineAsRegister(result)
775 : DefineSameAsFirst(result);
780 LInstruction* LChunkBuilder::DoArithmeticT(Token::Value op,
781 HBinaryOperation* instr) {
782 HValue* left = instr->left();
783 HValue* right = instr->right();
784 DCHECK(left->representation().IsTagged());
785 DCHECK(right->representation().IsTagged());
786 LOperand* context = UseFixed(instr->context(), rsi);
787 LOperand* left_operand = UseFixed(left, rdx);
788 LOperand* right_operand = UseFixed(right, rax);
789 LArithmeticT* result =
790 new(zone()) LArithmeticT(op, context, left_operand, right_operand);
791 return MarkAsCall(DefineFixed(result, rax), instr);
795 void LChunkBuilder::DoBasicBlock(HBasicBlock* block, HBasicBlock* next_block) {
796 DCHECK(is_building());
797 current_block_ = block;
798 next_block_ = next_block;
799 if (block->IsStartBlock()) {
800 block->UpdateEnvironment(graph_->start_environment());
802 } else if (block->predecessors()->length() == 1) {
803 // We have a single predecessor => copy environment and outgoing
804 // argument count from the predecessor.
805 DCHECK(block->phis()->length() == 0);
806 HBasicBlock* pred = block->predecessors()->at(0);
807 HEnvironment* last_environment = pred->last_environment();
808 DCHECK(last_environment != NULL);
809 // Only copy the environment, if it is later used again.
810 if (pred->end()->SecondSuccessor() == NULL) {
811 DCHECK(pred->end()->FirstSuccessor() == block);
813 if (pred->end()->FirstSuccessor()->block_id() > block->block_id() ||
814 pred->end()->SecondSuccessor()->block_id() > block->block_id()) {
815 last_environment = last_environment->Copy();
818 block->UpdateEnvironment(last_environment);
819 DCHECK(pred->argument_count() >= 0);
820 argument_count_ = pred->argument_count();
822 // We are at a state join => process phis.
823 HBasicBlock* pred = block->predecessors()->at(0);
824 // No need to copy the environment, it cannot be used later.
825 HEnvironment* last_environment = pred->last_environment();
826 for (int i = 0; i < block->phis()->length(); ++i) {
827 HPhi* phi = block->phis()->at(i);
828 if (phi->HasMergedIndex()) {
829 last_environment->SetValueAt(phi->merged_index(), phi);
832 for (int i = 0; i < block->deleted_phis()->length(); ++i) {
833 if (block->deleted_phis()->at(i) < last_environment->length()) {
834 last_environment->SetValueAt(block->deleted_phis()->at(i),
835 graph_->GetConstantUndefined());
838 block->UpdateEnvironment(last_environment);
839 // Pick up the outgoing argument count of one of the predecessors.
840 argument_count_ = pred->argument_count();
842 HInstruction* current = block->first();
843 int start = chunk_->instructions()->length();
844 while (current != NULL && !is_aborted()) {
845 // Code for constants in registers is generated lazily.
846 if (!current->EmitAtUses()) {
847 VisitInstruction(current);
849 current = current->next();
851 int end = chunk_->instructions()->length() - 1;
853 block->set_first_instruction_index(start);
854 block->set_last_instruction_index(end);
856 block->set_argument_count(argument_count_);
858 current_block_ = NULL;
862 void LChunkBuilder::VisitInstruction(HInstruction* current) {
863 HInstruction* old_current = current_instruction_;
864 current_instruction_ = current;
866 LInstruction* instr = NULL;
867 if (current->CanReplaceWithDummyUses()) {
868 if (current->OperandCount() == 0) {
869 instr = DefineAsRegister(new(zone()) LDummy());
871 DCHECK(!current->OperandAt(0)->IsControlInstruction());
872 instr = DefineAsRegister(new(zone())
873 LDummyUse(UseAny(current->OperandAt(0))));
875 for (int i = 1; i < current->OperandCount(); ++i) {
876 if (current->OperandAt(i)->IsControlInstruction()) continue;
877 LInstruction* dummy =
878 new(zone()) LDummyUse(UseAny(current->OperandAt(i)));
879 dummy->set_hydrogen_value(current);
880 chunk_->AddInstruction(dummy, current_block_);
883 HBasicBlock* successor;
884 if (current->IsControlInstruction() &&
885 HControlInstruction::cast(current)->KnownSuccessorBlock(&successor) &&
887 instr = new(zone()) LGoto(successor);
889 instr = current->CompileToLithium(this);
893 argument_count_ += current->argument_delta();
894 DCHECK(argument_count_ >= 0);
897 AddInstruction(instr, current);
900 current_instruction_ = old_current;
904 void LChunkBuilder::AddInstruction(LInstruction* instr,
905 HInstruction* hydrogen_val) {
906 // Associate the hydrogen instruction first, since we may need it for
907 // the ClobbersRegisters() or ClobbersDoubleRegisters() calls below.
908 instr->set_hydrogen_value(hydrogen_val);
911 // Make sure that the lithium instruction has either no fixed register
912 // constraints in temps or the result OR no uses that are only used at
913 // start. If this invariant doesn't hold, the register allocator can decide
914 // to insert a split of a range immediately before the instruction due to an
915 // already allocated register needing to be used for the instruction's fixed
916 // register constraint. In this case, The register allocator won't see an
917 // interference between the split child and the use-at-start (it would if
918 // the it was just a plain use), so it is free to move the split child into
919 // the same register that is used for the use-at-start.
920 // See https://code.google.com/p/chromium/issues/detail?id=201590
921 if (!(instr->ClobbersRegisters() &&
922 instr->ClobbersDoubleRegisters(isolate()))) {
924 int used_at_start = 0;
925 for (UseIterator it(instr); !it.Done(); it.Advance()) {
926 LUnallocated* operand = LUnallocated::cast(it.Current());
927 if (operand->IsUsedAtStart()) ++used_at_start;
929 if (instr->Output() != NULL) {
930 if (LUnallocated::cast(instr->Output())->HasFixedPolicy()) ++fixed;
932 for (TempIterator it(instr); !it.Done(); it.Advance()) {
933 LUnallocated* operand = LUnallocated::cast(it.Current());
934 if (operand->HasFixedPolicy()) ++fixed;
936 DCHECK(fixed == 0 || used_at_start == 0);
940 if (FLAG_stress_pointer_maps && !instr->HasPointerMap()) {
941 instr = AssignPointerMap(instr);
943 if (FLAG_stress_environments && !instr->HasEnvironment()) {
944 instr = AssignEnvironment(instr);
946 chunk_->AddInstruction(instr, current_block_);
948 if (instr->IsCall()) {
949 HValue* hydrogen_value_for_lazy_bailout = hydrogen_val;
950 if (hydrogen_val->HasObservableSideEffects()) {
951 HSimulate* sim = HSimulate::cast(hydrogen_val->next());
952 sim->ReplayEnvironment(current_block_->last_environment());
953 hydrogen_value_for_lazy_bailout = sim;
955 LInstruction* bailout = AssignEnvironment(new(zone()) LLazyBailout());
956 bailout->set_hydrogen_value(hydrogen_value_for_lazy_bailout);
957 chunk_->AddInstruction(bailout, current_block_);
962 LInstruction* LChunkBuilder::DoGoto(HGoto* instr) {
963 return new(zone()) LGoto(instr->FirstSuccessor());
967 LInstruction* LChunkBuilder::DoDebugBreak(HDebugBreak* instr) {
968 return new(zone()) LDebugBreak();
972 LInstruction* LChunkBuilder::DoBranch(HBranch* instr) {
973 HValue* value = instr->value();
974 Representation r = value->representation();
975 HType type = value->type();
976 ToBooleanStub::Types expected = instr->expected_input_types();
977 if (expected.IsEmpty()) expected = ToBooleanStub::Types::Generic();
979 bool easy_case = !r.IsTagged() || type.IsBoolean() || type.IsSmi() ||
980 type.IsJSArray() || type.IsHeapNumber() || type.IsString();
981 LInstruction* branch = new(zone()) LBranch(UseRegister(value));
983 ((!expected.Contains(ToBooleanStub::SMI) && expected.NeedsMap()) ||
984 !expected.IsGeneric())) {
985 branch = AssignEnvironment(branch);
991 LInstruction* LChunkBuilder::DoCompareMap(HCompareMap* instr) {
992 DCHECK(instr->value()->representation().IsTagged());
993 LOperand* value = UseRegisterAtStart(instr->value());
994 return new(zone()) LCmpMapAndBranch(value);
998 LInstruction* LChunkBuilder::DoArgumentsLength(HArgumentsLength* length) {
999 info()->MarkAsRequiresFrame();
1000 return DefineAsRegister(new(zone()) LArgumentsLength(Use(length->value())));
1004 LInstruction* LChunkBuilder::DoArgumentsElements(HArgumentsElements* elems) {
1005 info()->MarkAsRequiresFrame();
1006 return DefineAsRegister(new(zone()) LArgumentsElements);
1010 LInstruction* LChunkBuilder::DoInstanceOf(HInstanceOf* instr) {
1012 UseFixed(instr->left(), InstanceOfDescriptor::LeftRegister());
1014 UseFixed(instr->right(), InstanceOfDescriptor::RightRegister());
1015 LOperand* context = UseFixed(instr->context(), rsi);
1016 LInstanceOf* result = new (zone()) LInstanceOf(context, left, right);
1017 return MarkAsCall(DefineFixed(result, rax), instr);
1021 LInstruction* LChunkBuilder::DoHasInPrototypeChainAndBranch(
1022 HHasInPrototypeChainAndBranch* instr) {
1023 LOperand* object = UseRegister(instr->object());
1024 LOperand* prototype = UseRegister(instr->prototype());
1025 return new (zone()) LHasInPrototypeChainAndBranch(object, prototype);
1029 LInstruction* LChunkBuilder::DoWrapReceiver(HWrapReceiver* instr) {
1030 LOperand* receiver = UseRegister(instr->receiver());
1031 LOperand* function = UseRegisterAtStart(instr->function());
1032 LWrapReceiver* result = new(zone()) LWrapReceiver(receiver, function);
1033 return AssignEnvironment(DefineSameAsFirst(result));
1037 LInstruction* LChunkBuilder::DoApplyArguments(HApplyArguments* instr) {
1038 LOperand* function = UseFixed(instr->function(), rdi);
1039 LOperand* receiver = UseFixed(instr->receiver(), rax);
1040 LOperand* length = UseFixed(instr->length(), rbx);
1041 LOperand* elements = UseFixed(instr->elements(), rcx);
1042 LApplyArguments* result = new(zone()) LApplyArguments(function,
1046 return MarkAsCall(DefineFixed(result, rax), instr, CAN_DEOPTIMIZE_EAGERLY);
1050 LInstruction* LChunkBuilder::DoPushArguments(HPushArguments* instr) {
1051 int argc = instr->OperandCount();
1052 for (int i = 0; i < argc; ++i) {
1053 LOperand* argument = UseOrConstant(instr->argument(i));
1054 AddInstruction(new(zone()) LPushArgument(argument), instr);
1060 LInstruction* LChunkBuilder::DoStoreCodeEntry(
1061 HStoreCodeEntry* store_code_entry) {
1062 LOperand* function = UseRegister(store_code_entry->function());
1063 LOperand* code_object = UseTempRegister(store_code_entry->code_object());
1064 return new(zone()) LStoreCodeEntry(function, code_object);
1068 LInstruction* LChunkBuilder::DoInnerAllocatedObject(
1069 HInnerAllocatedObject* instr) {
1070 LOperand* base_object = UseRegisterAtStart(instr->base_object());
1071 LOperand* offset = UseRegisterOrConstantAtStart(instr->offset());
1072 return DefineAsRegister(
1073 new(zone()) LInnerAllocatedObject(base_object, offset));
1077 LInstruction* LChunkBuilder::DoThisFunction(HThisFunction* instr) {
1078 return instr->HasNoUses()
1080 : DefineAsRegister(new(zone()) LThisFunction);
1084 LInstruction* LChunkBuilder::DoContext(HContext* instr) {
1085 if (instr->HasNoUses()) return NULL;
1087 if (info()->IsStub()) {
1088 return DefineFixed(new(zone()) LContext, rsi);
1091 return DefineAsRegister(new(zone()) LContext);
1095 LInstruction* LChunkBuilder::DoDeclareGlobals(HDeclareGlobals* instr) {
1096 LOperand* context = UseFixed(instr->context(), rsi);
1097 return MarkAsCall(new(zone()) LDeclareGlobals(context), instr);
1101 LInstruction* LChunkBuilder::DoCallJSFunction(
1102 HCallJSFunction* instr) {
1103 LOperand* function = UseFixed(instr->function(), rdi);
1105 LCallJSFunction* result = new(zone()) LCallJSFunction(function);
1107 return MarkAsCall(DefineFixed(result, rax), instr);
1111 LInstruction* LChunkBuilder::DoCallWithDescriptor(
1112 HCallWithDescriptor* instr) {
1113 CallInterfaceDescriptor descriptor = instr->descriptor();
1115 LOperand* target = UseRegisterOrConstantAtStart(instr->target());
1116 ZoneList<LOperand*> ops(instr->OperandCount(), zone());
1118 ops.Add(target, zone());
1120 LOperand* op = UseFixed(instr->OperandAt(1), rsi);
1121 ops.Add(op, zone());
1122 // Other register parameters
1123 for (int i = LCallWithDescriptor::kImplicitRegisterParameterCount;
1124 i < instr->OperandCount(); i++) {
1126 UseFixed(instr->OperandAt(i),
1127 descriptor.GetRegisterParameter(
1128 i - LCallWithDescriptor::kImplicitRegisterParameterCount));
1129 ops.Add(op, zone());
1132 LCallWithDescriptor* result = new(zone()) LCallWithDescriptor(
1133 descriptor, ops, zone());
1134 return MarkAsCall(DefineFixed(result, rax), instr);
1138 LInstruction* LChunkBuilder::DoInvokeFunction(HInvokeFunction* instr) {
1139 LOperand* context = UseFixed(instr->context(), rsi);
1140 LOperand* function = UseFixed(instr->function(), rdi);
1141 LInvokeFunction* result = new(zone()) LInvokeFunction(context, function);
1142 return MarkAsCall(DefineFixed(result, rax), instr, CANNOT_DEOPTIMIZE_EAGERLY);
1146 LInstruction* LChunkBuilder::DoUnaryMathOperation(HUnaryMathOperation* instr) {
1147 switch (instr->op()) {
1149 return DoMathFloor(instr);
1151 return DoMathRound(instr);
1153 return DoMathFround(instr);
1155 return DoMathAbs(instr);
1157 return DoMathLog(instr);
1159 return DoMathExp(instr);
1161 return DoMathSqrt(instr);
1163 return DoMathPowHalf(instr);
1165 return DoMathClz32(instr);
1173 LInstruction* LChunkBuilder::DoMathFloor(HUnaryMathOperation* instr) {
1174 LOperand* input = UseRegisterAtStart(instr->value());
1175 LMathFloor* result = new(zone()) LMathFloor(input);
1176 return AssignEnvironment(DefineAsRegister(result));
1180 LInstruction* LChunkBuilder::DoMathRound(HUnaryMathOperation* instr) {
1181 LOperand* input = UseRegister(instr->value());
1182 LOperand* temp = FixedTemp(xmm4);
1183 LMathRound* result = new(zone()) LMathRound(input, temp);
1184 return AssignEnvironment(DefineAsRegister(result));
1188 LInstruction* LChunkBuilder::DoMathFround(HUnaryMathOperation* instr) {
1189 LOperand* input = UseRegister(instr->value());
1190 LMathFround* result = new (zone()) LMathFround(input);
1191 return DefineAsRegister(result);
1195 LInstruction* LChunkBuilder::DoMathAbs(HUnaryMathOperation* instr) {
1196 LOperand* context = UseAny(instr->context());
1197 LOperand* input = UseRegisterAtStart(instr->value());
1198 LInstruction* result =
1199 DefineSameAsFirst(new(zone()) LMathAbs(context, input));
1200 Representation r = instr->value()->representation();
1201 if (!r.IsDouble() && !r.IsSmiOrInteger32()) result = AssignPointerMap(result);
1202 if (!r.IsDouble()) result = AssignEnvironment(result);
1207 LInstruction* LChunkBuilder::DoMathLog(HUnaryMathOperation* instr) {
1208 DCHECK(instr->representation().IsDouble());
1209 DCHECK(instr->value()->representation().IsDouble());
1210 LOperand* input = UseRegisterAtStart(instr->value());
1211 return MarkAsCall(DefineSameAsFirst(new(zone()) LMathLog(input)), instr);
1215 LInstruction* LChunkBuilder::DoMathClz32(HUnaryMathOperation* instr) {
1216 LOperand* input = UseRegisterAtStart(instr->value());
1217 LMathClz32* result = new(zone()) LMathClz32(input);
1218 return DefineAsRegister(result);
1222 LInstruction* LChunkBuilder::DoMathExp(HUnaryMathOperation* instr) {
1223 DCHECK(instr->representation().IsDouble());
1224 DCHECK(instr->value()->representation().IsDouble());
1225 LOperand* value = UseTempRegister(instr->value());
1226 LOperand* temp1 = TempRegister();
1227 LOperand* temp2 = TempRegister();
1228 LMathExp* result = new(zone()) LMathExp(value, temp1, temp2);
1229 return DefineAsRegister(result);
1233 LInstruction* LChunkBuilder::DoMathSqrt(HUnaryMathOperation* instr) {
1234 LOperand* input = UseAtStart(instr->value());
1235 return DefineAsRegister(new(zone()) LMathSqrt(input));
1239 LInstruction* LChunkBuilder::DoMathPowHalf(HUnaryMathOperation* instr) {
1240 LOperand* input = UseRegisterAtStart(instr->value());
1241 LMathPowHalf* result = new(zone()) LMathPowHalf(input);
1242 return DefineSameAsFirst(result);
1246 LInstruction* LChunkBuilder::DoCallNew(HCallNew* instr) {
1247 LOperand* context = UseFixed(instr->context(), rsi);
1248 LOperand* constructor = UseFixed(instr->constructor(), rdi);
1249 LCallNew* result = new(zone()) LCallNew(context, constructor);
1250 return MarkAsCall(DefineFixed(result, rax), instr);
1254 LInstruction* LChunkBuilder::DoCallNewArray(HCallNewArray* instr) {
1255 LOperand* context = UseFixed(instr->context(), rsi);
1256 LOperand* constructor = UseFixed(instr->constructor(), rdi);
1257 LCallNewArray* result = new(zone()) LCallNewArray(context, constructor);
1258 return MarkAsCall(DefineFixed(result, rax), instr);
1262 LInstruction* LChunkBuilder::DoCallFunction(HCallFunction* instr) {
1263 LOperand* context = UseFixed(instr->context(), rsi);
1264 LOperand* function = UseFixed(instr->function(), rdi);
1265 LOperand* slot = NULL;
1266 LOperand* vector = NULL;
1267 if (instr->HasVectorAndSlot()) {
1268 slot = FixedTemp(rdx);
1269 vector = FixedTemp(rbx);
1271 LCallFunction* call =
1272 new (zone()) LCallFunction(context, function, slot, vector);
1273 return MarkAsCall(DefineFixed(call, rax), instr);
1277 LInstruction* LChunkBuilder::DoCallRuntime(HCallRuntime* instr) {
1278 LOperand* context = UseFixed(instr->context(), rsi);
1279 LCallRuntime* result = new(zone()) LCallRuntime(context);
1280 return MarkAsCall(DefineFixed(result, rax), instr);
1284 LInstruction* LChunkBuilder::DoRor(HRor* instr) {
1285 return DoShift(Token::ROR, instr);
1289 LInstruction* LChunkBuilder::DoShr(HShr* instr) {
1290 return DoShift(Token::SHR, instr);
1294 LInstruction* LChunkBuilder::DoSar(HSar* instr) {
1295 return DoShift(Token::SAR, instr);
1299 LInstruction* LChunkBuilder::DoShl(HShl* instr) {
1300 return DoShift(Token::SHL, instr);
1304 LInstruction* LChunkBuilder::DoBitwise(HBitwise* instr) {
1305 if (instr->representation().IsSmiOrInteger32()) {
1306 DCHECK(instr->left()->representation().Equals(instr->representation()));
1307 DCHECK(instr->right()->representation().Equals(instr->representation()));
1308 DCHECK(instr->CheckFlag(HValue::kTruncatingToInt32));
1310 LOperand* left = UseRegisterAtStart(instr->BetterLeftOperand());
1312 if (SmiValuesAre32Bits() && instr->representation().IsSmi()) {
1313 // We don't support tagged immediates, so we request it in a register.
1314 right = UseRegisterAtStart(instr->BetterRightOperand());
1316 right = UseOrConstantAtStart(instr->BetterRightOperand());
1318 return DefineSameAsFirst(new(zone()) LBitI(left, right));
1320 return DoArithmeticT(instr->op(), instr);
1325 LInstruction* LChunkBuilder::DoDivByPowerOf2I(HDiv* instr) {
1326 DCHECK(instr->representation().IsSmiOrInteger32());
1327 DCHECK(instr->left()->representation().Equals(instr->representation()));
1328 DCHECK(instr->right()->representation().Equals(instr->representation()));
1329 LOperand* dividend = UseRegister(instr->left());
1330 int32_t divisor = instr->right()->GetInteger32Constant();
1331 LInstruction* result = DefineAsRegister(new(zone()) LDivByPowerOf2I(
1332 dividend, divisor));
1333 if ((instr->CheckFlag(HValue::kBailoutOnMinusZero) && divisor < 0) ||
1334 (instr->CheckFlag(HValue::kCanOverflow) && divisor == -1) ||
1335 (!instr->CheckFlag(HInstruction::kAllUsesTruncatingToInt32) &&
1336 divisor != 1 && divisor != -1)) {
1337 result = AssignEnvironment(result);
1343 LInstruction* LChunkBuilder::DoDivByConstI(HDiv* instr) {
1344 DCHECK(instr->representation().IsInteger32());
1345 DCHECK(instr->left()->representation().Equals(instr->representation()));
1346 DCHECK(instr->right()->representation().Equals(instr->representation()));
1347 LOperand* dividend = UseRegister(instr->left());
1348 int32_t divisor = instr->right()->GetInteger32Constant();
1349 LOperand* temp1 = FixedTemp(rax);
1350 LOperand* temp2 = FixedTemp(rdx);
1351 LInstruction* result = DefineFixed(new(zone()) LDivByConstI(
1352 dividend, divisor, temp1, temp2), rdx);
1354 (instr->CheckFlag(HValue::kBailoutOnMinusZero) && divisor < 0) ||
1355 !instr->CheckFlag(HInstruction::kAllUsesTruncatingToInt32)) {
1356 result = AssignEnvironment(result);
1362 LInstruction* LChunkBuilder::DoDivI(HDiv* instr) {
1363 DCHECK(instr->representation().IsSmiOrInteger32());
1364 DCHECK(instr->left()->representation().Equals(instr->representation()));
1365 DCHECK(instr->right()->representation().Equals(instr->representation()));
1366 LOperand* dividend = UseFixed(instr->left(), rax);
1367 LOperand* divisor = UseRegister(instr->right());
1368 LOperand* temp = FixedTemp(rdx);
1369 LInstruction* result = DefineFixed(new(zone()) LDivI(
1370 dividend, divisor, temp), rax);
1371 if (instr->CheckFlag(HValue::kCanBeDivByZero) ||
1372 instr->CheckFlag(HValue::kBailoutOnMinusZero) ||
1373 instr->CheckFlag(HValue::kCanOverflow) ||
1374 !instr->CheckFlag(HValue::kAllUsesTruncatingToInt32)) {
1375 result = AssignEnvironment(result);
1381 LInstruction* LChunkBuilder::DoDiv(HDiv* instr) {
1382 if (instr->representation().IsSmiOrInteger32()) {
1383 if (instr->RightIsPowerOf2()) {
1384 return DoDivByPowerOf2I(instr);
1385 } else if (instr->right()->IsConstant()) {
1386 return DoDivByConstI(instr);
1388 return DoDivI(instr);
1390 } else if (instr->representation().IsDouble()) {
1391 return DoArithmeticD(Token::DIV, instr);
1393 return DoArithmeticT(Token::DIV, instr);
1398 LInstruction* LChunkBuilder::DoFlooringDivByPowerOf2I(HMathFloorOfDiv* instr) {
1399 LOperand* dividend = UseRegisterAtStart(instr->left());
1400 int32_t divisor = instr->right()->GetInteger32Constant();
1401 LInstruction* result = DefineSameAsFirst(new(zone()) LFlooringDivByPowerOf2I(
1402 dividend, divisor));
1403 if ((instr->CheckFlag(HValue::kBailoutOnMinusZero) && divisor < 0) ||
1404 (instr->CheckFlag(HValue::kLeftCanBeMinInt) && divisor == -1)) {
1405 result = AssignEnvironment(result);
1411 LInstruction* LChunkBuilder::DoFlooringDivByConstI(HMathFloorOfDiv* instr) {
1412 DCHECK(instr->representation().IsInteger32());
1413 DCHECK(instr->left()->representation().Equals(instr->representation()));
1414 DCHECK(instr->right()->representation().Equals(instr->representation()));
1415 LOperand* dividend = UseRegister(instr->left());
1416 int32_t divisor = instr->right()->GetInteger32Constant();
1417 LOperand* temp1 = FixedTemp(rax);
1418 LOperand* temp2 = FixedTemp(rdx);
1420 ((divisor > 0 && !instr->CheckFlag(HValue::kLeftCanBeNegative)) ||
1421 (divisor < 0 && !instr->CheckFlag(HValue::kLeftCanBePositive))) ?
1422 NULL : TempRegister();
1423 LInstruction* result =
1424 DefineFixed(new(zone()) LFlooringDivByConstI(dividend,
1431 (instr->CheckFlag(HValue::kBailoutOnMinusZero) && divisor < 0)) {
1432 result = AssignEnvironment(result);
1438 LInstruction* LChunkBuilder::DoFlooringDivI(HMathFloorOfDiv* instr) {
1439 DCHECK(instr->representation().IsSmiOrInteger32());
1440 DCHECK(instr->left()->representation().Equals(instr->representation()));
1441 DCHECK(instr->right()->representation().Equals(instr->representation()));
1442 LOperand* dividend = UseFixed(instr->left(), rax);
1443 LOperand* divisor = UseRegister(instr->right());
1444 LOperand* temp = FixedTemp(rdx);
1445 LInstruction* result = DefineFixed(new(zone()) LFlooringDivI(
1446 dividend, divisor, temp), rax);
1447 if (instr->CheckFlag(HValue::kCanBeDivByZero) ||
1448 instr->CheckFlag(HValue::kBailoutOnMinusZero) ||
1449 instr->CheckFlag(HValue::kCanOverflow)) {
1450 result = AssignEnvironment(result);
1456 LInstruction* LChunkBuilder::DoMathFloorOfDiv(HMathFloorOfDiv* instr) {
1457 if (instr->RightIsPowerOf2()) {
1458 return DoFlooringDivByPowerOf2I(instr);
1459 } else if (instr->right()->IsConstant()) {
1460 return DoFlooringDivByConstI(instr);
1462 return DoFlooringDivI(instr);
1467 LInstruction* LChunkBuilder::DoModByPowerOf2I(HMod* instr) {
1468 DCHECK(instr->representation().IsSmiOrInteger32());
1469 DCHECK(instr->left()->representation().Equals(instr->representation()));
1470 DCHECK(instr->right()->representation().Equals(instr->representation()));
1471 LOperand* dividend = UseRegisterAtStart(instr->left());
1472 int32_t divisor = instr->right()->GetInteger32Constant();
1473 LInstruction* result = DefineSameAsFirst(new(zone()) LModByPowerOf2I(
1474 dividend, divisor));
1475 if (instr->CheckFlag(HValue::kLeftCanBeNegative) &&
1476 instr->CheckFlag(HValue::kBailoutOnMinusZero)) {
1477 result = AssignEnvironment(result);
1483 LInstruction* LChunkBuilder::DoModByConstI(HMod* instr) {
1484 DCHECK(instr->representation().IsSmiOrInteger32());
1485 DCHECK(instr->left()->representation().Equals(instr->representation()));
1486 DCHECK(instr->right()->representation().Equals(instr->representation()));
1487 LOperand* dividend = UseRegister(instr->left());
1488 int32_t divisor = instr->right()->GetInteger32Constant();
1489 LOperand* temp1 = FixedTemp(rax);
1490 LOperand* temp2 = FixedTemp(rdx);
1491 LInstruction* result = DefineFixed(new(zone()) LModByConstI(
1492 dividend, divisor, temp1, temp2), rax);
1493 if (divisor == 0 || instr->CheckFlag(HValue::kBailoutOnMinusZero)) {
1494 result = AssignEnvironment(result);
1500 LInstruction* LChunkBuilder::DoModI(HMod* instr) {
1501 DCHECK(instr->representation().IsSmiOrInteger32());
1502 DCHECK(instr->left()->representation().Equals(instr->representation()));
1503 DCHECK(instr->right()->representation().Equals(instr->representation()));
1504 LOperand* dividend = UseFixed(instr->left(), rax);
1505 LOperand* divisor = UseRegister(instr->right());
1506 LOperand* temp = FixedTemp(rdx);
1507 LInstruction* result = DefineFixed(new(zone()) LModI(
1508 dividend, divisor, temp), rdx);
1509 if (instr->CheckFlag(HValue::kCanBeDivByZero) ||
1510 instr->CheckFlag(HValue::kBailoutOnMinusZero)) {
1511 result = AssignEnvironment(result);
1517 LInstruction* LChunkBuilder::DoMod(HMod* instr) {
1518 if (instr->representation().IsSmiOrInteger32()) {
1519 if (instr->RightIsPowerOf2()) {
1520 return DoModByPowerOf2I(instr);
1521 } else if (instr->right()->IsConstant()) {
1522 return DoModByConstI(instr);
1524 return DoModI(instr);
1526 } else if (instr->representation().IsDouble()) {
1527 return DoArithmeticD(Token::MOD, instr);
1529 return DoArithmeticT(Token::MOD, instr);
1534 LInstruction* LChunkBuilder::DoMul(HMul* instr) {
1535 if (instr->representation().IsSmiOrInteger32()) {
1536 DCHECK(instr->left()->representation().Equals(instr->representation()));
1537 DCHECK(instr->right()->representation().Equals(instr->representation()));
1538 LOperand* left = UseRegisterAtStart(instr->BetterLeftOperand());
1539 LOperand* right = UseOrConstant(instr->BetterRightOperand());
1540 LMulI* mul = new(zone()) LMulI(left, right);
1541 if (instr->CheckFlag(HValue::kCanOverflow) ||
1542 instr->CheckFlag(HValue::kBailoutOnMinusZero)) {
1543 AssignEnvironment(mul);
1545 return DefineSameAsFirst(mul);
1546 } else if (instr->representation().IsDouble()) {
1547 return DoArithmeticD(Token::MUL, instr);
1549 return DoArithmeticT(Token::MUL, instr);
1554 LInstruction* LChunkBuilder::DoSub(HSub* instr) {
1555 if (instr->representation().IsSmiOrInteger32()) {
1556 DCHECK(instr->left()->representation().Equals(instr->representation()));
1557 DCHECK(instr->right()->representation().Equals(instr->representation()));
1558 LOperand* left = UseRegisterAtStart(instr->left());
1560 if (SmiValuesAre32Bits() && instr->representation().IsSmi()) {
1561 // We don't support tagged immediates, so we request it in a register.
1562 right = UseRegisterAtStart(instr->right());
1564 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->IsConsistentExternalRepresentation());
1610 DCHECK(!instr->CheckFlag(HValue::kCanOverflow));
1611 bool use_lea = LAddI::UseLea(instr);
1612 LOperand* left = UseRegisterAtStart(instr->left());
1613 HValue* right_candidate = instr->right();
1614 LOperand* right = use_lea
1615 ? UseRegisterOrConstantAtStart(right_candidate)
1616 : UseOrConstantAtStart(right_candidate);
1617 LAddI* add = new(zone()) LAddI(left, right);
1618 LInstruction* result = use_lea
1619 ? DefineAsRegister(add)
1620 : DefineSameAsFirst(add);
1622 } else if (instr->representation().IsDouble()) {
1623 return DoArithmeticD(Token::ADD, instr);
1625 return DoArithmeticT(Token::ADD, instr);
1631 LInstruction* LChunkBuilder::DoMathMinMax(HMathMinMax* instr) {
1632 LOperand* left = NULL;
1633 LOperand* right = NULL;
1634 DCHECK(instr->left()->representation().Equals(instr->representation()));
1635 DCHECK(instr->right()->representation().Equals(instr->representation()));
1636 if (instr->representation().IsSmi()) {
1637 left = UseRegisterAtStart(instr->BetterLeftOperand());
1638 right = UseAtStart(instr->BetterRightOperand());
1639 } else if (instr->representation().IsInteger32()) {
1640 left = UseRegisterAtStart(instr->BetterLeftOperand());
1641 right = UseOrConstantAtStart(instr->BetterRightOperand());
1643 DCHECK(instr->representation().IsDouble());
1644 left = UseRegisterAtStart(instr->left());
1645 right = UseRegisterAtStart(instr->right());
1647 LMathMinMax* minmax = new(zone()) LMathMinMax(left, right);
1648 return DefineSameAsFirst(minmax);
1652 LInstruction* LChunkBuilder::DoPower(HPower* instr) {
1653 DCHECK(instr->representation().IsDouble());
1654 // We call a C function for double power. It can't trigger a GC.
1655 // We need to use fixed result register for the call.
1656 Representation exponent_type = instr->right()->representation();
1657 DCHECK(instr->left()->representation().IsDouble());
1658 LOperand* left = UseFixedDouble(instr->left(), xmm2);
1660 exponent_type.IsDouble()
1661 ? UseFixedDouble(instr->right(), xmm1)
1662 : UseFixed(instr->right(), MathPowTaggedDescriptor::exponent());
1663 LPower* result = new(zone()) LPower(left, right);
1664 return MarkAsCall(DefineFixedDouble(result, xmm3), instr,
1665 CAN_DEOPTIMIZE_EAGERLY);
1669 LInstruction* LChunkBuilder::DoCompareGeneric(HCompareGeneric* instr) {
1670 DCHECK(instr->left()->representation().IsTagged());
1671 DCHECK(instr->right()->representation().IsTagged());
1672 LOperand* context = UseFixed(instr->context(), rsi);
1673 LOperand* left = UseFixed(instr->left(), rdx);
1674 LOperand* right = UseFixed(instr->right(), rax);
1675 LCmpT* result = new(zone()) LCmpT(context, left, right);
1676 return MarkAsCall(DefineFixed(result, rax), instr);
1680 LInstruction* LChunkBuilder::DoCompareNumericAndBranch(
1681 HCompareNumericAndBranch* instr) {
1682 Representation r = instr->representation();
1683 if (r.IsSmiOrInteger32()) {
1684 DCHECK(instr->left()->representation().Equals(r));
1685 DCHECK(instr->right()->representation().Equals(r));
1686 LOperand* left = UseRegisterOrConstantAtStart(instr->left());
1687 LOperand* right = UseOrConstantAtStart(instr->right());
1688 return new(zone()) LCompareNumericAndBranch(left, right);
1690 DCHECK(r.IsDouble());
1691 DCHECK(instr->left()->representation().IsDouble());
1692 DCHECK(instr->right()->representation().IsDouble());
1695 if (instr->left()->IsConstant() && instr->right()->IsConstant()) {
1696 left = UseRegisterOrConstantAtStart(instr->left());
1697 right = UseRegisterOrConstantAtStart(instr->right());
1699 left = UseRegisterAtStart(instr->left());
1700 right = UseRegisterAtStart(instr->right());
1702 return new(zone()) LCompareNumericAndBranch(left, right);
1707 LInstruction* LChunkBuilder::DoCompareObjectEqAndBranch(
1708 HCompareObjectEqAndBranch* instr) {
1709 LOperand* left = UseRegisterAtStart(instr->left());
1710 LOperand* right = UseRegisterOrConstantAtStart(instr->right());
1711 return new(zone()) LCmpObjectEqAndBranch(left, right);
1715 LInstruction* LChunkBuilder::DoCompareHoleAndBranch(
1716 HCompareHoleAndBranch* instr) {
1717 LOperand* value = UseRegisterAtStart(instr->value());
1718 return new(zone()) LCmpHoleAndBranch(value);
1722 LInstruction* LChunkBuilder::DoCompareMinusZeroAndBranch(
1723 HCompareMinusZeroAndBranch* instr) {
1724 LOperand* value = UseRegister(instr->value());
1725 return new(zone()) LCompareMinusZeroAndBranch(value);
1729 LInstruction* LChunkBuilder::DoIsObjectAndBranch(HIsObjectAndBranch* instr) {
1730 DCHECK(instr->value()->representation().IsTagged());
1731 return new(zone()) LIsObjectAndBranch(UseRegisterAtStart(instr->value()));
1735 LInstruction* LChunkBuilder::DoIsStringAndBranch(HIsStringAndBranch* instr) {
1736 DCHECK(instr->value()->representation().IsTagged());
1737 LOperand* value = UseRegisterAtStart(instr->value());
1738 LOperand* temp = TempRegister();
1739 return new(zone()) LIsStringAndBranch(value, temp);
1743 LInstruction* LChunkBuilder::DoIsSmiAndBranch(HIsSmiAndBranch* instr) {
1744 DCHECK(instr->value()->representation().IsTagged());
1745 return new(zone()) LIsSmiAndBranch(Use(instr->value()));
1749 LInstruction* LChunkBuilder::DoIsUndetectableAndBranch(
1750 HIsUndetectableAndBranch* instr) {
1751 DCHECK(instr->value()->representation().IsTagged());
1752 LOperand* value = UseRegisterAtStart(instr->value());
1753 LOperand* temp = TempRegister();
1754 return new(zone()) LIsUndetectableAndBranch(value, temp);
1758 LInstruction* LChunkBuilder::DoStringCompareAndBranch(
1759 HStringCompareAndBranch* instr) {
1761 DCHECK(instr->left()->representation().IsTagged());
1762 DCHECK(instr->right()->representation().IsTagged());
1763 LOperand* context = UseFixed(instr->context(), rsi);
1764 LOperand* left = UseFixed(instr->left(), rdx);
1765 LOperand* right = UseFixed(instr->right(), rax);
1766 LStringCompareAndBranch* result =
1767 new(zone()) LStringCompareAndBranch(context, left, right);
1769 return MarkAsCall(result, instr);
1773 LInstruction* LChunkBuilder::DoHasInstanceTypeAndBranch(
1774 HHasInstanceTypeAndBranch* instr) {
1775 DCHECK(instr->value()->representation().IsTagged());
1776 LOperand* value = UseRegisterAtStart(instr->value());
1777 return new(zone()) LHasInstanceTypeAndBranch(value);
1781 LInstruction* LChunkBuilder::DoGetCachedArrayIndex(
1782 HGetCachedArrayIndex* instr) {
1783 DCHECK(instr->value()->representation().IsTagged());
1784 LOperand* value = UseRegisterAtStart(instr->value());
1786 return DefineAsRegister(new(zone()) LGetCachedArrayIndex(value));
1790 LInstruction* LChunkBuilder::DoHasCachedArrayIndexAndBranch(
1791 HHasCachedArrayIndexAndBranch* instr) {
1792 DCHECK(instr->value()->representation().IsTagged());
1793 LOperand* value = UseRegisterAtStart(instr->value());
1794 return new(zone()) LHasCachedArrayIndexAndBranch(value);
1798 LInstruction* LChunkBuilder::DoClassOfTestAndBranch(
1799 HClassOfTestAndBranch* instr) {
1800 LOperand* value = UseRegister(instr->value());
1801 return new(zone()) LClassOfTestAndBranch(value,
1807 LInstruction* LChunkBuilder::DoMapEnumLength(HMapEnumLength* instr) {
1808 LOperand* map = UseRegisterAtStart(instr->value());
1809 return DefineAsRegister(new(zone()) LMapEnumLength(map));
1813 LInstruction* LChunkBuilder::DoDateField(HDateField* instr) {
1814 LOperand* object = UseFixed(instr->value(), rax);
1815 LDateField* result = new(zone()) LDateField(object, instr->index());
1816 return MarkAsCall(DefineFixed(result, rax), instr, CANNOT_DEOPTIMIZE_EAGERLY);
1820 LInstruction* LChunkBuilder::DoSeqStringGetChar(HSeqStringGetChar* instr) {
1821 LOperand* string = UseRegisterAtStart(instr->string());
1822 LOperand* index = UseRegisterOrConstantAtStart(instr->index());
1823 return DefineAsRegister(new(zone()) LSeqStringGetChar(string, index));
1827 LInstruction* LChunkBuilder::DoSeqStringSetChar(HSeqStringSetChar* instr) {
1828 LOperand* string = UseRegisterAtStart(instr->string());
1829 LOperand* index = FLAG_debug_code
1830 ? UseRegisterAtStart(instr->index())
1831 : UseRegisterOrConstantAtStart(instr->index());
1832 LOperand* value = FLAG_debug_code
1833 ? UseRegisterAtStart(instr->value())
1834 : UseRegisterOrConstantAtStart(instr->value());
1835 LOperand* context = FLAG_debug_code ? UseFixed(instr->context(), rsi) : NULL;
1836 LInstruction* result = new(zone()) LSeqStringSetChar(context, string,
1838 if (FLAG_debug_code) {
1839 result = MarkAsCall(result, instr);
1845 LInstruction* LChunkBuilder::DoBoundsCheck(HBoundsCheck* instr) {
1846 if (!FLAG_debug_code && instr->skip_check()) return NULL;
1847 LOperand* index = UseRegisterOrConstantAtStart(instr->index());
1848 LOperand* length = !index->IsConstantOperand()
1849 ? UseOrConstantAtStart(instr->length())
1850 : UseAtStart(instr->length());
1851 LInstruction* result = new(zone()) LBoundsCheck(index, length);
1852 if (!FLAG_debug_code || !instr->skip_check()) {
1853 result = AssignEnvironment(result);
1859 LInstruction* LChunkBuilder::DoBoundsCheckBaseIndexInformation(
1860 HBoundsCheckBaseIndexInformation* instr) {
1866 LInstruction* LChunkBuilder::DoAbnormalExit(HAbnormalExit* instr) {
1867 // The control instruction marking the end of a block that completed
1868 // abruptly (e.g., threw an exception). There is nothing specific to do.
1873 LInstruction* LChunkBuilder::DoUseConst(HUseConst* instr) {
1878 LInstruction* LChunkBuilder::DoForceRepresentation(HForceRepresentation* bad) {
1879 // All HForceRepresentation instructions should be eliminated in the
1880 // representation change phase of Hydrogen.
1886 LInstruction* LChunkBuilder::DoChange(HChange* instr) {
1887 Representation from = instr->from();
1888 Representation to = instr->to();
1889 HValue* val = instr->value();
1891 if (to.IsTagged()) {
1892 LOperand* value = UseRegister(val);
1893 return DefineSameAsFirst(new(zone()) LDummyUse(value));
1895 from = Representation::Tagged();
1897 if (from.IsTagged()) {
1898 if (to.IsDouble()) {
1899 LOperand* value = UseRegister(val);
1900 LInstruction* result = DefineAsRegister(new(zone()) LNumberUntagD(value));
1901 if (!val->representation().IsSmi()) result = AssignEnvironment(result);
1903 } else if (to.IsSmi()) {
1904 LOperand* value = UseRegister(val);
1905 if (val->type().IsSmi()) {
1906 return DefineSameAsFirst(new(zone()) LDummyUse(value));
1908 return AssignEnvironment(DefineSameAsFirst(new(zone()) LCheckSmi(value)));
1910 DCHECK(to.IsInteger32());
1911 if (val->type().IsSmi() || val->representation().IsSmi()) {
1912 LOperand* value = UseRegister(val);
1913 return DefineSameAsFirst(new(zone()) LSmiUntag(value, false));
1915 LOperand* value = UseRegister(val);
1916 bool truncating = instr->CanTruncateToInt32();
1917 LOperand* xmm_temp = truncating ? NULL : FixedTemp(xmm1);
1918 LInstruction* result =
1919 DefineSameAsFirst(new(zone()) LTaggedToI(value, xmm_temp));
1920 if (!val->representation().IsSmi()) result = AssignEnvironment(result);
1924 } else if (from.IsDouble()) {
1925 if (to.IsTagged()) {
1926 info()->MarkAsDeferredCalling();
1927 LOperand* value = UseRegister(val);
1928 LOperand* temp = TempRegister();
1929 LUnallocated* result_temp = TempRegister();
1930 LNumberTagD* result = new(zone()) LNumberTagD(value, temp);
1931 return AssignPointerMap(Define(result, result_temp));
1932 } else if (to.IsSmi()) {
1933 LOperand* value = UseRegister(val);
1934 return AssignEnvironment(
1935 DefineAsRegister(new(zone()) LDoubleToSmi(value)));
1937 DCHECK(to.IsInteger32());
1938 LOperand* value = UseRegister(val);
1939 LInstruction* result = DefineAsRegister(new(zone()) LDoubleToI(value));
1940 if (!instr->CanTruncateToInt32()) result = AssignEnvironment(result);
1943 } else if (from.IsInteger32()) {
1944 info()->MarkAsDeferredCalling();
1945 if (to.IsTagged()) {
1946 if (!instr->CheckFlag(HValue::kCanOverflow)) {
1947 LOperand* value = UseRegister(val);
1948 return DefineAsRegister(new(zone()) LSmiTag(value));
1949 } else if (val->CheckFlag(HInstruction::kUint32)) {
1950 LOperand* value = UseRegister(val);
1951 LOperand* temp1 = TempRegister();
1952 LOperand* temp2 = FixedTemp(xmm1);
1953 LNumberTagU* result = new(zone()) LNumberTagU(value, temp1, temp2);
1954 return AssignPointerMap(DefineSameAsFirst(result));
1956 LOperand* value = UseRegister(val);
1957 LOperand* temp1 = SmiValuesAre32Bits() ? NULL : TempRegister();
1958 LOperand* temp2 = SmiValuesAre32Bits() ? NULL : FixedTemp(xmm1);
1959 LNumberTagI* result = new(zone()) LNumberTagI(value, temp1, temp2);
1960 return AssignPointerMap(DefineSameAsFirst(result));
1962 } else if (to.IsSmi()) {
1963 LOperand* value = UseRegister(val);
1964 LInstruction* result = DefineAsRegister(new(zone()) LSmiTag(value));
1965 if (instr->CheckFlag(HValue::kCanOverflow)) {
1966 result = AssignEnvironment(result);
1970 DCHECK(to.IsDouble());
1971 if (val->CheckFlag(HInstruction::kUint32)) {
1972 return DefineAsRegister(new(zone()) LUint32ToDouble(UseRegister(val)));
1974 LOperand* value = Use(val);
1975 return DefineAsRegister(new(zone()) LInteger32ToDouble(value));
1984 LInstruction* LChunkBuilder::DoCheckHeapObject(HCheckHeapObject* instr) {
1985 LOperand* value = UseRegisterAtStart(instr->value());
1986 LInstruction* result = new(zone()) LCheckNonSmi(value);
1987 if (!instr->value()->type().IsHeapObject()) {
1988 result = AssignEnvironment(result);
1994 LInstruction* LChunkBuilder::DoCheckSmi(HCheckSmi* instr) {
1995 LOperand* value = UseRegisterAtStart(instr->value());
1996 return AssignEnvironment(new(zone()) LCheckSmi(value));
2000 LInstruction* LChunkBuilder::DoCheckArrayBufferNotNeutered(
2001 HCheckArrayBufferNotNeutered* instr) {
2002 LOperand* view = UseRegisterAtStart(instr->value());
2003 LCheckArrayBufferNotNeutered* result =
2004 new (zone()) LCheckArrayBufferNotNeutered(view);
2005 return AssignEnvironment(result);
2009 LInstruction* LChunkBuilder::DoCheckInstanceType(HCheckInstanceType* instr) {
2010 LOperand* value = UseRegisterAtStart(instr->value());
2011 LCheckInstanceType* result = new(zone()) LCheckInstanceType(value);
2012 return AssignEnvironment(result);
2016 LInstruction* LChunkBuilder::DoCheckValue(HCheckValue* instr) {
2017 LOperand* value = UseRegisterAtStart(instr->value());
2018 return AssignEnvironment(new(zone()) LCheckValue(value));
2022 LInstruction* LChunkBuilder::DoCheckMaps(HCheckMaps* instr) {
2023 if (instr->IsStabilityCheck()) return new(zone()) LCheckMaps;
2024 LOperand* value = UseRegisterAtStart(instr->value());
2025 LInstruction* result = AssignEnvironment(new(zone()) LCheckMaps(value));
2026 if (instr->HasMigrationTarget()) {
2027 info()->MarkAsDeferredCalling();
2028 result = AssignPointerMap(result);
2034 LInstruction* LChunkBuilder::DoClampToUint8(HClampToUint8* instr) {
2035 HValue* value = instr->value();
2036 Representation input_rep = value->representation();
2037 LOperand* reg = UseRegister(value);
2038 if (input_rep.IsDouble()) {
2039 return DefineAsRegister(new(zone()) LClampDToUint8(reg));
2040 } else if (input_rep.IsInteger32()) {
2041 return DefineSameAsFirst(new(zone()) LClampIToUint8(reg));
2043 DCHECK(input_rep.IsSmiOrTagged());
2044 // Register allocator doesn't (yet) support allocation of double
2045 // temps. Reserve xmm1 explicitly.
2046 LClampTToUint8* result = new(zone()) LClampTToUint8(reg,
2048 return AssignEnvironment(DefineSameAsFirst(result));
2053 LInstruction* LChunkBuilder::DoDoubleBits(HDoubleBits* instr) {
2054 HValue* value = instr->value();
2055 DCHECK(value->representation().IsDouble());
2056 return DefineAsRegister(new(zone()) LDoubleBits(UseRegister(value)));
2060 LInstruction* LChunkBuilder::DoConstructDouble(HConstructDouble* instr) {
2061 LOperand* lo = UseRegister(instr->lo());
2062 LOperand* hi = UseRegister(instr->hi());
2063 return DefineAsRegister(new(zone()) LConstructDouble(hi, lo));
2067 LInstruction* LChunkBuilder::DoReturn(HReturn* instr) {
2068 LOperand* context = info()->IsStub() ? UseFixed(instr->context(), rsi) : NULL;
2069 LOperand* parameter_count = UseRegisterOrConstant(instr->parameter_count());
2070 return new(zone()) LReturn(
2071 UseFixed(instr->value(), rax), context, parameter_count);
2075 LInstruction* LChunkBuilder::DoConstant(HConstant* instr) {
2076 Representation r = instr->representation();
2078 return DefineAsRegister(new(zone()) LConstantS);
2079 } else if (r.IsInteger32()) {
2080 return DefineAsRegister(new(zone()) LConstantI);
2081 } else if (r.IsDouble()) {
2082 return DefineAsRegister(new (zone()) LConstantD);
2083 } else if (r.IsExternal()) {
2084 return DefineAsRegister(new(zone()) LConstantE);
2085 } else if (r.IsTagged()) {
2086 return DefineAsRegister(new(zone()) LConstantT);
2094 LInstruction* LChunkBuilder::DoLoadGlobalGeneric(HLoadGlobalGeneric* instr) {
2095 LOperand* context = UseFixed(instr->context(), rsi);
2096 LOperand* global_object =
2097 UseFixed(instr->global_object(), LoadDescriptor::ReceiverRegister());
2098 LOperand* vector = NULL;
2099 if (instr->HasVectorAndSlot()) {
2100 vector = FixedTemp(LoadWithVectorDescriptor::VectorRegister());
2103 LLoadGlobalGeneric* result =
2104 new(zone()) LLoadGlobalGeneric(context, global_object, vector);
2105 return MarkAsCall(DefineFixed(result, rax), instr);
2109 LInstruction* LChunkBuilder::DoLoadGlobalViaContext(
2110 HLoadGlobalViaContext* instr) {
2111 LOperand* context = UseFixed(instr->context(), rsi);
2112 DCHECK(instr->slot_index() > 0);
2113 LLoadGlobalViaContext* result = new (zone()) LLoadGlobalViaContext(context);
2114 return MarkAsCall(DefineFixed(result, rax), instr);
2118 LInstruction* LChunkBuilder::DoLoadContextSlot(HLoadContextSlot* instr) {
2119 LOperand* context = UseRegisterAtStart(instr->value());
2120 LInstruction* result =
2121 DefineAsRegister(new(zone()) LLoadContextSlot(context));
2122 if (instr->RequiresHoleCheck() && instr->DeoptimizesOnHole()) {
2123 result = AssignEnvironment(result);
2129 LInstruction* LChunkBuilder::DoStoreContextSlot(HStoreContextSlot* instr) {
2133 context = UseRegister(instr->context());
2134 if (instr->NeedsWriteBarrier()) {
2135 value = UseTempRegister(instr->value());
2136 temp = TempRegister();
2138 value = UseRegister(instr->value());
2141 LInstruction* result = new(zone()) LStoreContextSlot(context, value, temp);
2142 if (instr->RequiresHoleCheck() && instr->DeoptimizesOnHole()) {
2143 result = AssignEnvironment(result);
2149 LInstruction* LChunkBuilder::DoLoadNamedField(HLoadNamedField* instr) {
2150 // Use the special mov rax, moffs64 encoding for external
2151 // memory accesses with 64-bit word-sized values.
2152 if (instr->access().IsExternalMemory() &&
2153 instr->access().offset() == 0 &&
2154 (instr->access().representation().IsSmi() ||
2155 instr->access().representation().IsTagged() ||
2156 instr->access().representation().IsHeapObject() ||
2157 instr->access().representation().IsExternal())) {
2158 LOperand* obj = UseRegisterOrConstantAtStart(instr->object());
2159 return DefineFixed(new(zone()) LLoadNamedField(obj), rax);
2161 LOperand* obj = UseRegisterAtStart(instr->object());
2162 return DefineAsRegister(new(zone()) LLoadNamedField(obj));
2166 LInstruction* LChunkBuilder::DoLoadNamedGeneric(HLoadNamedGeneric* instr) {
2167 LOperand* context = UseFixed(instr->context(), rsi);
2169 UseFixed(instr->object(), LoadDescriptor::ReceiverRegister());
2170 LOperand* vector = NULL;
2171 if (instr->HasVectorAndSlot()) {
2172 vector = FixedTemp(LoadWithVectorDescriptor::VectorRegister());
2174 LLoadNamedGeneric* result = new(zone()) LLoadNamedGeneric(
2175 context, object, vector);
2176 return MarkAsCall(DefineFixed(result, rax), instr);
2180 LInstruction* LChunkBuilder::DoLoadFunctionPrototype(
2181 HLoadFunctionPrototype* instr) {
2182 return AssignEnvironment(DefineAsRegister(
2183 new(zone()) LLoadFunctionPrototype(UseRegister(instr->function()))));
2187 LInstruction* LChunkBuilder::DoLoadRoot(HLoadRoot* instr) {
2188 return DefineAsRegister(new(zone()) LLoadRoot);
2192 void LChunkBuilder::FindDehoistedKeyDefinitions(HValue* candidate) {
2193 // We sign extend the dehoisted key at the definition point when the pointer
2194 // size is 64-bit. For x32 port, we sign extend the dehoisted key at the use
2195 // points and should not invoke this function. We can't use STATIC_ASSERT
2196 // here as the pointer size is 32-bit for x32.
2197 DCHECK(kPointerSize == kInt64Size);
2198 BitVector* dehoisted_key_ids = chunk_->GetDehoistedKeyIds();
2199 if (dehoisted_key_ids->Contains(candidate->id())) return;
2200 dehoisted_key_ids->Add(candidate->id());
2201 if (!candidate->IsPhi()) return;
2202 for (int i = 0; i < candidate->OperandCount(); ++i) {
2203 FindDehoistedKeyDefinitions(candidate->OperandAt(i));
2208 LInstruction* LChunkBuilder::DoLoadKeyed(HLoadKeyed* instr) {
2209 DCHECK((kPointerSize == kInt64Size &&
2210 instr->key()->representation().IsInteger32()) ||
2211 (kPointerSize == kInt32Size &&
2212 instr->key()->representation().IsSmiOrInteger32()));
2213 ElementsKind elements_kind = instr->elements_kind();
2214 LOperand* key = NULL;
2215 LInstruction* result = NULL;
2217 if (kPointerSize == kInt64Size) {
2218 key = UseRegisterOrConstantAtStart(instr->key());
2220 bool clobbers_key = ExternalArrayOpRequiresTemp(
2221 instr->key()->representation(), elements_kind);
2223 ? UseTempRegister(instr->key())
2224 : UseRegisterOrConstantAtStart(instr->key());
2227 if ((kPointerSize == kInt64Size) && instr->IsDehoisted()) {
2228 FindDehoistedKeyDefinitions(instr->key());
2231 if (!instr->is_fixed_typed_array()) {
2232 LOperand* obj = UseRegisterAtStart(instr->elements());
2233 result = DefineAsRegister(new(zone()) LLoadKeyed(obj, key));
2236 (instr->representation().IsInteger32() &&
2237 !(IsDoubleOrFloatElementsKind(elements_kind))) ||
2238 (instr->representation().IsDouble() &&
2239 (IsDoubleOrFloatElementsKind(elements_kind))));
2240 LOperand* backing_store = UseRegister(instr->elements());
2241 result = DefineAsRegister(new(zone()) LLoadKeyed(backing_store, key));
2244 bool needs_environment;
2245 if (instr->is_fixed_typed_array()) {
2246 // see LCodeGen::DoLoadKeyedExternalArray
2247 needs_environment = elements_kind == UINT32_ELEMENTS &&
2248 !instr->CheckFlag(HInstruction::kUint32);
2250 // see LCodeGen::DoLoadKeyedFixedDoubleArray and
2251 // LCodeGen::DoLoadKeyedFixedArray
2253 instr->RequiresHoleCheck() ||
2254 (instr->hole_mode() == CONVERT_HOLE_TO_UNDEFINED && info()->IsStub());
2257 if (needs_environment) {
2258 result = AssignEnvironment(result);
2264 LInstruction* LChunkBuilder::DoLoadKeyedGeneric(HLoadKeyedGeneric* instr) {
2265 LOperand* context = UseFixed(instr->context(), rsi);
2267 UseFixed(instr->object(), LoadDescriptor::ReceiverRegister());
2268 LOperand* key = UseFixed(instr->key(), LoadDescriptor::NameRegister());
2269 LOperand* vector = NULL;
2270 if (instr->HasVectorAndSlot()) {
2271 vector = FixedTemp(LoadWithVectorDescriptor::VectorRegister());
2274 LLoadKeyedGeneric* result =
2275 new(zone()) LLoadKeyedGeneric(context, object, key, vector);
2276 return MarkAsCall(DefineFixed(result, rax), instr);
2280 LInstruction* LChunkBuilder::DoStoreKeyed(HStoreKeyed* instr) {
2281 ElementsKind elements_kind = instr->elements_kind();
2283 if ((kPointerSize == kInt64Size) && instr->IsDehoisted()) {
2284 FindDehoistedKeyDefinitions(instr->key());
2287 if (!instr->is_fixed_typed_array()) {
2288 DCHECK(instr->elements()->representation().IsTagged());
2289 bool needs_write_barrier = instr->NeedsWriteBarrier();
2290 LOperand* object = NULL;
2291 LOperand* key = NULL;
2292 LOperand* val = NULL;
2294 Representation value_representation = instr->value()->representation();
2295 if (value_representation.IsDouble()) {
2296 object = UseRegisterAtStart(instr->elements());
2297 val = UseRegisterAtStart(instr->value());
2298 key = UseRegisterOrConstantAtStart(instr->key());
2300 DCHECK(value_representation.IsSmiOrTagged() ||
2301 value_representation.IsInteger32());
2302 if (needs_write_barrier) {
2303 object = UseTempRegister(instr->elements());
2304 val = UseTempRegister(instr->value());
2305 key = UseTempRegister(instr->key());
2307 object = UseRegisterAtStart(instr->elements());
2308 val = UseRegisterOrConstantAtStart(instr->value());
2309 key = UseRegisterOrConstantAtStart(instr->key());
2313 return new(zone()) LStoreKeyed(object, key, val);
2317 (instr->value()->representation().IsInteger32() &&
2318 !IsDoubleOrFloatElementsKind(elements_kind)) ||
2319 (instr->value()->representation().IsDouble() &&
2320 IsDoubleOrFloatElementsKind(elements_kind)));
2321 DCHECK(instr->elements()->representation().IsExternal());
2322 bool val_is_temp_register = elements_kind == UINT8_CLAMPED_ELEMENTS ||
2323 elements_kind == FLOAT32_ELEMENTS;
2324 LOperand* val = val_is_temp_register ? UseTempRegister(instr->value())
2325 : UseRegister(instr->value());
2326 LOperand* key = NULL;
2327 if (kPointerSize == kInt64Size) {
2328 key = UseRegisterOrConstantAtStart(instr->key());
2330 bool clobbers_key = ExternalArrayOpRequiresTemp(
2331 instr->key()->representation(), elements_kind);
2333 ? UseTempRegister(instr->key())
2334 : UseRegisterOrConstantAtStart(instr->key());
2336 LOperand* backing_store = UseRegister(instr->elements());
2337 return new(zone()) LStoreKeyed(backing_store, key, val);
2341 LInstruction* LChunkBuilder::DoStoreKeyedGeneric(HStoreKeyedGeneric* instr) {
2342 LOperand* context = UseFixed(instr->context(), rsi);
2344 UseFixed(instr->object(), StoreDescriptor::ReceiverRegister());
2345 LOperand* key = UseFixed(instr->key(), StoreDescriptor::NameRegister());
2346 LOperand* value = UseFixed(instr->value(), StoreDescriptor::ValueRegister());
2348 DCHECK(instr->object()->representation().IsTagged());
2349 DCHECK(instr->key()->representation().IsTagged());
2350 DCHECK(instr->value()->representation().IsTagged());
2352 LOperand* slot = NULL;
2353 LOperand* vector = NULL;
2354 if (instr->HasVectorAndSlot()) {
2355 slot = FixedTemp(VectorStoreICDescriptor::SlotRegister());
2356 vector = FixedTemp(VectorStoreICDescriptor::VectorRegister());
2359 LStoreKeyedGeneric* result = new (zone())
2360 LStoreKeyedGeneric(context, object, key, value, slot, vector);
2361 return MarkAsCall(result, instr);
2365 LInstruction* LChunkBuilder::DoTransitionElementsKind(
2366 HTransitionElementsKind* instr) {
2367 if (IsSimpleMapChangeTransition(instr->from_kind(), instr->to_kind())) {
2368 LOperand* object = UseRegister(instr->object());
2369 LOperand* new_map_reg = TempRegister();
2370 LOperand* temp_reg = TempRegister();
2371 LTransitionElementsKind* result = new(zone()) LTransitionElementsKind(
2372 object, NULL, new_map_reg, temp_reg);
2375 LOperand* object = UseFixed(instr->object(), rax);
2376 LOperand* context = UseFixed(instr->context(), rsi);
2377 LTransitionElementsKind* result =
2378 new(zone()) LTransitionElementsKind(object, context, NULL, NULL);
2379 return MarkAsCall(result, instr);
2384 LInstruction* LChunkBuilder::DoTrapAllocationMemento(
2385 HTrapAllocationMemento* instr) {
2386 LOperand* object = UseRegister(instr->object());
2387 LOperand* temp = TempRegister();
2388 LTrapAllocationMemento* result =
2389 new(zone()) LTrapAllocationMemento(object, temp);
2390 return AssignEnvironment(result);
2394 LInstruction* LChunkBuilder::DoMaybeGrowElements(HMaybeGrowElements* instr) {
2395 info()->MarkAsDeferredCalling();
2396 LOperand* context = UseFixed(instr->context(), rsi);
2397 LOperand* object = Use(instr->object());
2398 LOperand* elements = Use(instr->elements());
2399 LOperand* key = UseRegisterOrConstant(instr->key());
2400 LOperand* current_capacity = UseRegisterOrConstant(instr->current_capacity());
2402 LMaybeGrowElements* result = new (zone())
2403 LMaybeGrowElements(context, object, elements, key, current_capacity);
2404 DefineFixed(result, rax);
2405 return AssignPointerMap(AssignEnvironment(result));
2409 LInstruction* LChunkBuilder::DoStoreNamedField(HStoreNamedField* instr) {
2410 bool is_in_object = instr->access().IsInobject();
2411 bool is_external_location = instr->access().IsExternalMemory() &&
2412 instr->access().offset() == 0;
2413 bool needs_write_barrier = instr->NeedsWriteBarrier();
2414 bool needs_write_barrier_for_map = instr->has_transition() &&
2415 instr->NeedsWriteBarrierForMap();
2418 if (needs_write_barrier) {
2420 ? UseRegister(instr->object())
2421 : UseTempRegister(instr->object());
2422 } else if (is_external_location) {
2423 DCHECK(!is_in_object);
2424 DCHECK(!needs_write_barrier);
2425 DCHECK(!needs_write_barrier_for_map);
2426 obj = UseRegisterOrConstant(instr->object());
2428 obj = needs_write_barrier_for_map
2429 ? UseRegister(instr->object())
2430 : UseRegisterAtStart(instr->object());
2433 bool can_be_constant = instr->value()->IsConstant() &&
2434 HConstant::cast(instr->value())->NotInNewSpace() &&
2435 !instr->field_representation().IsDouble();
2438 if (needs_write_barrier) {
2439 val = UseTempRegister(instr->value());
2440 } else if (is_external_location) {
2441 val = UseFixed(instr->value(), rax);
2442 } else if (can_be_constant) {
2443 val = UseRegisterOrConstant(instr->value());
2444 } else if (instr->field_representation().IsDouble()) {
2445 val = UseRegisterAtStart(instr->value());
2447 val = UseRegister(instr->value());
2450 // We only need a scratch register if we have a write barrier or we
2451 // have a store into the properties array (not in-object-property).
2452 LOperand* temp = (!is_in_object || needs_write_barrier ||
2453 needs_write_barrier_for_map) ? TempRegister() : NULL;
2455 return new(zone()) LStoreNamedField(obj, val, temp);
2459 LInstruction* LChunkBuilder::DoStoreNamedGeneric(HStoreNamedGeneric* instr) {
2460 LOperand* context = UseFixed(instr->context(), rsi);
2462 UseFixed(instr->object(), StoreDescriptor::ReceiverRegister());
2463 LOperand* value = UseFixed(instr->value(), StoreDescriptor::ValueRegister());
2464 LOperand* slot = NULL;
2465 LOperand* vector = NULL;
2466 if (instr->HasVectorAndSlot()) {
2467 slot = FixedTemp(VectorStoreICDescriptor::SlotRegister());
2468 vector = FixedTemp(VectorStoreICDescriptor::VectorRegister());
2471 LStoreNamedGeneric* result =
2472 new (zone()) LStoreNamedGeneric(context, object, value, slot, vector);
2473 return MarkAsCall(result, instr);
2477 LInstruction* LChunkBuilder::DoStoreGlobalViaContext(
2478 HStoreGlobalViaContext* instr) {
2479 LOperand* context = UseFixed(instr->context(), rsi);
2480 LOperand* value = UseFixed(instr->value(),
2481 StoreGlobalViaContextDescriptor::ValueRegister());
2482 DCHECK(instr->slot_index() > 0);
2484 LStoreGlobalViaContext* result =
2485 new (zone()) LStoreGlobalViaContext(context, value);
2486 return MarkAsCall(result, instr);
2490 LInstruction* LChunkBuilder::DoStringAdd(HStringAdd* instr) {
2491 LOperand* context = UseFixed(instr->context(), rsi);
2492 LOperand* left = UseFixed(instr->left(), rdx);
2493 LOperand* right = UseFixed(instr->right(), rax);
2495 DefineFixed(new(zone()) LStringAdd(context, left, right), rax), instr);
2499 LInstruction* LChunkBuilder::DoStringCharCodeAt(HStringCharCodeAt* instr) {
2500 LOperand* string = UseTempRegister(instr->string());
2501 LOperand* index = UseTempRegister(instr->index());
2502 LOperand* context = UseAny(instr->context());
2503 LStringCharCodeAt* result =
2504 new(zone()) LStringCharCodeAt(context, string, index);
2505 return AssignPointerMap(DefineAsRegister(result));
2509 LInstruction* LChunkBuilder::DoStringCharFromCode(HStringCharFromCode* instr) {
2510 LOperand* char_code = UseRegister(instr->value());
2511 LOperand* context = UseAny(instr->context());
2512 LStringCharFromCode* result =
2513 new(zone()) LStringCharFromCode(context, char_code);
2514 return AssignPointerMap(DefineAsRegister(result));
2518 LInstruction* LChunkBuilder::DoAllocate(HAllocate* instr) {
2519 info()->MarkAsDeferredCalling();
2520 LOperand* context = UseAny(instr->context());
2521 LOperand* size = instr->size()->IsConstant()
2522 ? UseConstant(instr->size())
2523 : UseTempRegister(instr->size());
2524 LOperand* temp = TempRegister();
2525 LAllocate* result = new(zone()) LAllocate(context, size, temp);
2526 return AssignPointerMap(DefineAsRegister(result));
2530 LInstruction* LChunkBuilder::DoRegExpLiteral(HRegExpLiteral* instr) {
2531 LOperand* context = UseFixed(instr->context(), rsi);
2532 LRegExpLiteral* result = new(zone()) LRegExpLiteral(context);
2533 return MarkAsCall(DefineFixed(result, rax), instr);
2537 LInstruction* LChunkBuilder::DoFunctionLiteral(HFunctionLiteral* instr) {
2538 LOperand* context = UseFixed(instr->context(), rsi);
2539 LFunctionLiteral* result = new(zone()) LFunctionLiteral(context);
2540 return MarkAsCall(DefineFixed(result, rax), instr);
2544 LInstruction* LChunkBuilder::DoOsrEntry(HOsrEntry* instr) {
2545 DCHECK(argument_count_ == 0);
2546 allocator_->MarkAsOsrEntry();
2547 current_block_->last_environment()->set_ast_id(instr->ast_id());
2548 return AssignEnvironment(new(zone()) LOsrEntry);
2552 LInstruction* LChunkBuilder::DoParameter(HParameter* instr) {
2553 LParameter* result = new(zone()) LParameter;
2554 if (instr->kind() == HParameter::STACK_PARAMETER) {
2555 int spill_index = chunk()->GetParameterStackSlot(instr->index());
2556 return DefineAsSpilled(result, spill_index);
2558 DCHECK(info()->IsStub());
2559 CallInterfaceDescriptor descriptor =
2560 info()->code_stub()->GetCallInterfaceDescriptor();
2561 int index = static_cast<int>(instr->index());
2562 Register reg = descriptor.GetRegisterParameter(index);
2563 return DefineFixed(result, reg);
2568 LInstruction* LChunkBuilder::DoUnknownOSRValue(HUnknownOSRValue* instr) {
2569 // Use an index that corresponds to the location in the unoptimized frame,
2570 // which the optimized frame will subsume.
2571 int env_index = instr->index();
2572 int spill_index = 0;
2573 if (instr->environment()->is_parameter_index(env_index)) {
2574 spill_index = chunk()->GetParameterStackSlot(env_index);
2576 spill_index = env_index - instr->environment()->first_local_index();
2577 if (spill_index > LUnallocated::kMaxFixedSlotIndex) {
2578 Retry(kTooManySpillSlotsNeededForOSR);
2582 return DefineAsSpilled(new(zone()) LUnknownOSRValue, spill_index);
2586 LInstruction* LChunkBuilder::DoCallStub(HCallStub* instr) {
2587 LOperand* context = UseFixed(instr->context(), rsi);
2588 LCallStub* result = new(zone()) LCallStub(context);
2589 return MarkAsCall(DefineFixed(result, rax), instr);
2593 LInstruction* LChunkBuilder::DoArgumentsObject(HArgumentsObject* instr) {
2594 // There are no real uses of the arguments object.
2595 // arguments.length and element access are supported directly on
2596 // stack arguments, and any real arguments object use causes a bailout.
2597 // So this value is never used.
2602 LInstruction* LChunkBuilder::DoCapturedObject(HCapturedObject* instr) {
2603 instr->ReplayEnvironment(current_block_->last_environment());
2605 // There are no real uses of a captured object.
2610 LInstruction* LChunkBuilder::DoAccessArgumentsAt(HAccessArgumentsAt* instr) {
2611 info()->MarkAsRequiresFrame();
2612 LOperand* args = UseRegister(instr->arguments());
2615 if (instr->length()->IsConstant() && instr->index()->IsConstant()) {
2616 length = UseRegisterOrConstant(instr->length());
2617 index = UseOrConstant(instr->index());
2619 length = UseTempRegister(instr->length());
2620 index = Use(instr->index());
2622 return DefineAsRegister(new(zone()) LAccessArgumentsAt(args, length, index));
2626 LInstruction* LChunkBuilder::DoToFastProperties(HToFastProperties* instr) {
2627 LOperand* object = UseFixed(instr->value(), rax);
2628 LToFastProperties* result = new(zone()) LToFastProperties(object);
2629 return MarkAsCall(DefineFixed(result, rax), instr);
2633 LInstruction* LChunkBuilder::DoTypeof(HTypeof* instr) {
2634 LOperand* context = UseFixed(instr->context(), rsi);
2635 LOperand* value = UseFixed(instr->value(), rbx);
2636 LTypeof* result = new(zone()) LTypeof(context, value);
2637 return MarkAsCall(DefineFixed(result, rax), instr);
2641 LInstruction* LChunkBuilder::DoTypeofIsAndBranch(HTypeofIsAndBranch* instr) {
2642 return new(zone()) LTypeofIsAndBranch(UseTempRegister(instr->value()));
2646 LInstruction* LChunkBuilder::DoIsConstructCallAndBranch(
2647 HIsConstructCallAndBranch* instr) {
2648 return new(zone()) LIsConstructCallAndBranch(TempRegister());
2652 LInstruction* LChunkBuilder::DoSimulate(HSimulate* instr) {
2653 instr->ReplayEnvironment(current_block_->last_environment());
2658 LInstruction* LChunkBuilder::DoStackCheck(HStackCheck* instr) {
2659 info()->MarkAsDeferredCalling();
2660 if (instr->is_function_entry()) {
2661 LOperand* context = UseFixed(instr->context(), rsi);
2662 return MarkAsCall(new(zone()) LStackCheck(context), instr);
2664 DCHECK(instr->is_backwards_branch());
2665 LOperand* context = UseAny(instr->context());
2666 return AssignEnvironment(
2667 AssignPointerMap(new(zone()) LStackCheck(context)));
2672 LInstruction* LChunkBuilder::DoEnterInlined(HEnterInlined* instr) {
2673 HEnvironment* outer = current_block_->last_environment();
2674 outer->set_ast_id(instr->ReturnId());
2675 HConstant* undefined = graph()->GetConstantUndefined();
2676 HEnvironment* inner = outer->CopyForInlining(instr->closure(),
2677 instr->arguments_count(),
2680 instr->inlining_kind());
2681 // Only replay binding of arguments object if it wasn't removed from graph.
2682 if (instr->arguments_var() != NULL && instr->arguments_object()->IsLinked()) {
2683 inner->Bind(instr->arguments_var(), instr->arguments_object());
2685 inner->BindContext(instr->closure_context());
2686 inner->set_entry(instr);
2687 current_block_->UpdateEnvironment(inner);
2688 chunk_->AddInlinedFunction(instr->shared());
2693 LInstruction* LChunkBuilder::DoLeaveInlined(HLeaveInlined* instr) {
2694 LInstruction* pop = NULL;
2696 HEnvironment* env = current_block_->last_environment();
2698 if (env->entry()->arguments_pushed()) {
2699 int argument_count = env->arguments_environment()->parameter_count();
2700 pop = new(zone()) LDrop(argument_count);
2701 DCHECK(instr->argument_delta() == -argument_count);
2704 HEnvironment* outer = current_block_->last_environment()->
2705 DiscardInlined(false);
2706 current_block_->UpdateEnvironment(outer);
2712 LInstruction* LChunkBuilder::DoForInPrepareMap(HForInPrepareMap* instr) {
2713 LOperand* context = UseFixed(instr->context(), rsi);
2714 LOperand* object = UseFixed(instr->enumerable(), rax);
2715 LForInPrepareMap* result = new(zone()) LForInPrepareMap(context, object);
2716 return MarkAsCall(DefineFixed(result, rax), instr, CAN_DEOPTIMIZE_EAGERLY);
2720 LInstruction* LChunkBuilder::DoForInCacheArray(HForInCacheArray* instr) {
2721 LOperand* map = UseRegister(instr->map());
2722 return AssignEnvironment(DefineAsRegister(
2723 new(zone()) LForInCacheArray(map)));
2727 LInstruction* LChunkBuilder::DoCheckMapValue(HCheckMapValue* instr) {
2728 LOperand* value = UseRegisterAtStart(instr->value());
2729 LOperand* map = UseRegisterAtStart(instr->map());
2730 return AssignEnvironment(new(zone()) LCheckMapValue(value, map));
2734 LInstruction* LChunkBuilder::DoLoadFieldByIndex(HLoadFieldByIndex* instr) {
2735 LOperand* object = UseRegister(instr->object());
2736 LOperand* index = UseTempRegister(instr->index());
2737 LLoadFieldByIndex* load = new(zone()) LLoadFieldByIndex(object, index);
2738 LInstruction* result = DefineSameAsFirst(load);
2739 return AssignPointerMap(result);
2743 LInstruction* LChunkBuilder::DoStoreFrameContext(HStoreFrameContext* instr) {
2744 LOperand* context = UseRegisterAtStart(instr->context());
2745 return new(zone()) LStoreFrameContext(context);
2749 LInstruction* LChunkBuilder::DoAllocateBlockContext(
2750 HAllocateBlockContext* instr) {
2751 LOperand* context = UseFixed(instr->context(), rsi);
2752 LOperand* function = UseRegisterAtStart(instr->function());
2753 LAllocateBlockContext* result =
2754 new(zone()) LAllocateBlockContext(context, function);
2755 return MarkAsCall(DefineFixed(result, rsi), instr);
2759 } // namespace internal
2762 #endif // V8_TARGET_ARCH_X64