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.
7 #if V8_TARGET_ARCH_IA32
9 #include "src/hydrogen-osr.h"
10 #include "src/ia32/lithium-codegen-ia32.h"
11 #include "src/lithium-inl.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 bool LInstruction::HasDoubleRegisterResult() {
47 return HasResult() && result()->IsDoubleRegister();
51 bool LInstruction::HasDoubleRegisterInput() {
52 for (int i = 0; i < InputCount(); i++) {
53 LOperand* op = InputAt(i);
54 if (op != NULL && op->IsDoubleRegister()) {
62 void LInstruction::PrintTo(StringStream* stream) {
63 stream->Add("%s ", this->Mnemonic());
65 PrintOutputOperandTo(stream);
69 if (HasEnvironment()) {
71 environment()->PrintTo(stream);
74 if (HasPointerMap()) {
76 pointer_map()->PrintTo(stream);
81 void LInstruction::PrintDataTo(StringStream* stream) {
83 for (int i = 0; i < InputCount(); i++) {
84 if (i > 0) stream->Add(" ");
85 if (InputAt(i) == NULL) {
88 InputAt(i)->PrintTo(stream);
94 void LInstruction::PrintOutputOperandTo(StringStream* stream) {
95 if (HasResult()) result()->PrintTo(stream);
99 void LLabel::PrintDataTo(StringStream* stream) {
100 LGap::PrintDataTo(stream);
101 LLabel* rep = replacement();
103 stream->Add(" Dead block replaced with B%d", rep->block_id());
108 bool LGap::IsRedundant() const {
109 for (int i = 0; i < 4; i++) {
110 if (parallel_moves_[i] != NULL && !parallel_moves_[i]->IsRedundant()) {
119 void LGap::PrintDataTo(StringStream* stream) {
120 for (int i = 0; i < 4; i++) {
122 if (parallel_moves_[i] != NULL) {
123 parallel_moves_[i]->PrintDataTo(stream);
130 const char* LArithmeticD::Mnemonic() const {
132 case Token::ADD: return "add-d";
133 case Token::SUB: return "sub-d";
134 case Token::MUL: return "mul-d";
135 case Token::DIV: return "div-d";
136 case Token::MOD: return "mod-d";
144 const char* LArithmeticT::Mnemonic() const {
146 case Token::ADD: return "add-t";
147 case Token::SUB: return "sub-t";
148 case Token::MUL: return "mul-t";
149 case Token::MOD: return "mod-t";
150 case Token::DIV: return "div-t";
151 case Token::BIT_AND: return "bit-and-t";
152 case Token::BIT_OR: return "bit-or-t";
153 case Token::BIT_XOR: return "bit-xor-t";
154 case Token::ROR: return "ror-t";
155 case Token::SHL: return "sal-t";
156 case Token::SAR: return "sar-t";
157 case Token::SHR: return "shr-t";
165 bool LGoto::HasInterestingComment(LCodeGen* gen) const {
166 return !gen->IsNextEmittedBlock(block_id());
170 void LGoto::PrintDataTo(StringStream* stream) {
171 stream->Add("B%d", block_id());
175 void LBranch::PrintDataTo(StringStream* stream) {
176 stream->Add("B%d | B%d on ", true_block_id(), false_block_id());
177 value()->PrintTo(stream);
181 void LCompareNumericAndBranch::PrintDataTo(StringStream* stream) {
183 left()->PrintTo(stream);
184 stream->Add(" %s ", Token::String(op()));
185 right()->PrintTo(stream);
186 stream->Add(" then B%d else B%d", true_block_id(), false_block_id());
190 void LIsObjectAndBranch::PrintDataTo(StringStream* stream) {
191 stream->Add("if is_object(");
192 value()->PrintTo(stream);
193 stream->Add(") then B%d else B%d", true_block_id(), false_block_id());
197 void LIsStringAndBranch::PrintDataTo(StringStream* stream) {
198 stream->Add("if is_string(");
199 value()->PrintTo(stream);
200 stream->Add(") then B%d else B%d", true_block_id(), false_block_id());
204 void LIsSmiAndBranch::PrintDataTo(StringStream* stream) {
205 stream->Add("if is_smi(");
206 value()->PrintTo(stream);
207 stream->Add(") then B%d else B%d", true_block_id(), false_block_id());
211 void LIsUndetectableAndBranch::PrintDataTo(StringStream* stream) {
212 stream->Add("if is_undetectable(");
213 value()->PrintTo(stream);
214 stream->Add(") then B%d else B%d", true_block_id(), false_block_id());
218 void LStringCompareAndBranch::PrintDataTo(StringStream* stream) {
219 stream->Add("if string_compare(");
220 left()->PrintTo(stream);
221 right()->PrintTo(stream);
222 stream->Add(") then B%d else B%d", true_block_id(), false_block_id());
226 void LHasInstanceTypeAndBranch::PrintDataTo(StringStream* stream) {
227 stream->Add("if has_instance_type(");
228 value()->PrintTo(stream);
229 stream->Add(") then B%d else B%d", true_block_id(), false_block_id());
233 void LHasCachedArrayIndexAndBranch::PrintDataTo(StringStream* stream) {
234 stream->Add("if has_cached_array_index(");
235 value()->PrintTo(stream);
236 stream->Add(") then B%d else B%d", true_block_id(), false_block_id());
240 void LClassOfTestAndBranch::PrintDataTo(StringStream* stream) {
241 stream->Add("if class_of_test(");
242 value()->PrintTo(stream);
243 stream->Add(", \"%o\") then B%d else B%d",
244 *hydrogen()->class_name(),
250 void LTypeofIsAndBranch::PrintDataTo(StringStream* stream) {
251 stream->Add("if typeof ");
252 value()->PrintTo(stream);
253 stream->Add(" == \"%s\" then B%d else B%d",
254 hydrogen()->type_literal()->ToCString().get(),
255 true_block_id(), false_block_id());
259 void LStoreCodeEntry::PrintDataTo(StringStream* stream) {
261 function()->PrintTo(stream);
262 stream->Add(".code_entry = ");
263 code_object()->PrintTo(stream);
267 void LInnerAllocatedObject::PrintDataTo(StringStream* stream) {
269 base_object()->PrintTo(stream);
271 offset()->PrintTo(stream);
275 void LCallJSFunction::PrintDataTo(StringStream* stream) {
277 function()->PrintTo(stream);
278 stream->Add("#%d / ", arity());
282 void LCallWithDescriptor::PrintDataTo(StringStream* stream) {
283 for (int i = 0; i < InputCount(); i++) {
284 InputAt(i)->PrintTo(stream);
287 stream->Add("#%d / ", arity());
291 void LLoadContextSlot::PrintDataTo(StringStream* stream) {
292 context()->PrintTo(stream);
293 stream->Add("[%d]", slot_index());
297 void LStoreContextSlot::PrintDataTo(StringStream* stream) {
298 context()->PrintTo(stream);
299 stream->Add("[%d] <- ", slot_index());
300 value()->PrintTo(stream);
304 void LInvokeFunction::PrintDataTo(StringStream* stream) {
306 context()->PrintTo(stream);
308 function()->PrintTo(stream);
309 stream->Add(" #%d / ", arity());
313 void LCallNew::PrintDataTo(StringStream* stream) {
315 context()->PrintTo(stream);
317 constructor()->PrintTo(stream);
318 stream->Add(" #%d / ", arity());
322 void LCallNewArray::PrintDataTo(StringStream* stream) {
324 context()->PrintTo(stream);
326 constructor()->PrintTo(stream);
327 stream->Add(" #%d / ", arity());
328 ElementsKind kind = hydrogen()->elements_kind();
329 stream->Add(" (%s) ", ElementsKindToString(kind));
333 void LAccessArgumentsAt::PrintDataTo(StringStream* stream) {
334 arguments()->PrintTo(stream);
336 stream->Add(" length ");
337 length()->PrintTo(stream);
339 stream->Add(" index ");
340 index()->PrintTo(stream);
344 int LPlatformChunk::GetNextSpillIndex(RegisterKind kind) {
346 case GENERAL_REGISTERS: return spill_slot_count_++;
347 case DOUBLE_REGISTERS: {
348 // Skip a slot if for a double-width slot.
350 spill_slot_count_ |= 1;
352 return spill_slot_count_++;
354 case FLOAT32x4_REGISTERS:
355 case FLOAT64x2_REGISTERS:
356 case INT32x4_REGISTERS: {
357 // Skip three slots if for a quad-width slot.
358 spill_slot_count_ += 3;
359 num_double_slots_ += 2; // for dynamic frame alignment
360 return spill_slot_count_++;
369 LOperand* LPlatformChunk::GetNextSpillSlot(RegisterKind kind) {
370 int index = GetNextSpillIndex(kind);
372 case GENERAL_REGISTERS: return LStackSlot::Create(index, zone());
373 case DOUBLE_REGISTERS: return LDoubleStackSlot::Create(index, zone());
374 case FLOAT32x4_REGISTERS: return LFloat32x4StackSlot::Create(index, zone());
375 case FLOAT64x2_REGISTERS: return LFloat64x2StackSlot::Create(index, zone());
376 case INT32x4_REGISTERS: return LInt32x4StackSlot::Create(index, zone());
384 void LStoreNamedField::PrintDataTo(StringStream* stream) {
385 object()->PrintTo(stream);
387 os << hydrogen()->access() << " <- ";
388 stream->Add(os.c_str());
389 value()->PrintTo(stream);
393 void LStoreNamedGeneric::PrintDataTo(StringStream* stream) {
394 object()->PrintTo(stream);
396 stream->Add(String::cast(*name())->ToCString().get());
398 value()->PrintTo(stream);
402 void LLoadKeyed::PrintDataTo(StringStream* stream) {
403 elements()->PrintTo(stream);
405 key()->PrintTo(stream);
406 if (hydrogen()->IsDehoisted()) {
407 stream->Add(" + %d]", base_offset());
414 void LStoreKeyed::PrintDataTo(StringStream* stream) {
415 elements()->PrintTo(stream);
417 key()->PrintTo(stream);
418 if (hydrogen()->IsDehoisted()) {
419 stream->Add(" + %d] <-", base_offset());
421 stream->Add("] <- ");
424 if (value() == NULL) {
425 DCHECK(hydrogen()->IsConstantHoleStore() &&
426 hydrogen()->value()->representation().IsDouble());
427 stream->Add("<the hole(nan)>");
429 value()->PrintTo(stream);
434 void LStoreKeyedGeneric::PrintDataTo(StringStream* stream) {
435 object()->PrintTo(stream);
437 key()->PrintTo(stream);
438 stream->Add("] <- ");
439 value()->PrintTo(stream);
443 void LTransitionElementsKind::PrintDataTo(StringStream* stream) {
444 object()->PrintTo(stream);
445 stream->Add(" %p -> %p", *original_map(), *transitioned_map());
449 LPlatformChunk* LChunkBuilder::Build() {
451 chunk_ = new(zone()) LPlatformChunk(info(), graph());
452 LPhase phase("L_Building chunk", chunk_);
455 // Reserve the first spill slot for the state of dynamic alignment.
456 if (info()->IsOptimizing()) {
457 int alignment_state_index = chunk_->GetNextSpillIndex(GENERAL_REGISTERS);
458 DCHECK_EQ(alignment_state_index, 0);
459 USE(alignment_state_index);
462 // If compiling for OSR, reserve space for the unoptimized frame,
463 // which will be subsumed into this frame.
464 if (graph()->has_osr()) {
465 for (int i = graph()->osr()->UnoptimizedFrameSlots(); i > 0; i--) {
466 chunk_->GetNextSpillIndex(GENERAL_REGISTERS);
470 const ZoneList<HBasicBlock*>* blocks = graph()->blocks();
471 for (int i = 0; i < blocks->length(); i++) {
472 HBasicBlock* next = NULL;
473 if (i < blocks->length() - 1) next = blocks->at(i + 1);
474 DoBasicBlock(blocks->at(i), next);
475 if (is_aborted()) return NULL;
482 LUnallocated* LChunkBuilder::ToUnallocated(Register reg) {
483 return new(zone()) LUnallocated(LUnallocated::FIXED_REGISTER,
484 Register::ToAllocationIndex(reg));
488 LUnallocated* LChunkBuilder::ToUnallocated(XMMRegister reg) {
489 return new(zone()) LUnallocated(LUnallocated::FIXED_DOUBLE_REGISTER,
490 XMMRegister::ToAllocationIndex(reg));
494 LOperand* LChunkBuilder::UseFixed(HValue* value, Register fixed_register) {
495 return Use(value, ToUnallocated(fixed_register));
499 LOperand* LChunkBuilder::UseFixedDouble(HValue* value, XMMRegister reg) {
500 return Use(value, ToUnallocated(reg));
504 LOperand* LChunkBuilder::UseRegister(HValue* value) {
505 return Use(value, new(zone()) LUnallocated(LUnallocated::MUST_HAVE_REGISTER));
509 LOperand* LChunkBuilder::UseRegisterAtStart(HValue* value) {
511 new(zone()) LUnallocated(LUnallocated::MUST_HAVE_REGISTER,
512 LUnallocated::USED_AT_START));
516 LOperand* LChunkBuilder::UseTempRegister(HValue* value) {
517 return Use(value, new(zone()) LUnallocated(LUnallocated::WRITABLE_REGISTER));
521 LOperand* LChunkBuilder::Use(HValue* value) {
522 return Use(value, new(zone()) LUnallocated(LUnallocated::NONE));
526 LOperand* LChunkBuilder::UseAtStart(HValue* value) {
527 return Use(value, new(zone()) LUnallocated(LUnallocated::NONE,
528 LUnallocated::USED_AT_START));
532 static inline bool CanBeImmediateConstant(HValue* value) {
533 return value->IsConstant() && HConstant::cast(value)->NotInNewSpace();
537 LOperand* LChunkBuilder::UseOrConstant(HValue* value) {
538 return CanBeImmediateConstant(value)
539 ? chunk_->DefineConstantOperand(HConstant::cast(value))
544 LOperand* LChunkBuilder::UseOrConstantAtStart(HValue* value) {
545 return CanBeImmediateConstant(value)
546 ? chunk_->DefineConstantOperand(HConstant::cast(value))
551 LOperand* LChunkBuilder::UseFixedOrConstant(HValue* value,
552 Register fixed_register) {
553 return CanBeImmediateConstant(value)
554 ? chunk_->DefineConstantOperand(HConstant::cast(value))
555 : UseFixed(value, fixed_register);
559 LOperand* LChunkBuilder::UseRegisterOrConstant(HValue* value) {
560 return CanBeImmediateConstant(value)
561 ? chunk_->DefineConstantOperand(HConstant::cast(value))
562 : UseRegister(value);
566 LOperand* LChunkBuilder::UseRegisterOrConstantAtStart(HValue* value) {
567 return CanBeImmediateConstant(value)
568 ? chunk_->DefineConstantOperand(HConstant::cast(value))
569 : UseRegisterAtStart(value);
573 LOperand* LChunkBuilder::UseConstant(HValue* value) {
574 return chunk_->DefineConstantOperand(HConstant::cast(value));
578 LOperand* LChunkBuilder::UseAny(HValue* value) {
579 return value->IsConstant()
580 ? chunk_->DefineConstantOperand(HConstant::cast(value))
581 : Use(value, new(zone()) LUnallocated(LUnallocated::ANY));
585 LOperand* LChunkBuilder::Use(HValue* value, LUnallocated* operand) {
586 if (value->EmitAtUses()) {
587 HInstruction* instr = HInstruction::cast(value);
588 VisitInstruction(instr);
590 operand->set_virtual_register(value->id());
595 LInstruction* LChunkBuilder::Define(LTemplateResultInstruction<1>* instr,
596 LUnallocated* result) {
597 result->set_virtual_register(current_instruction_->id());
598 instr->set_result(result);
603 LInstruction* LChunkBuilder::DefineAsRegister(
604 LTemplateResultInstruction<1>* instr) {
606 new(zone()) LUnallocated(LUnallocated::MUST_HAVE_REGISTER));
610 LInstruction* LChunkBuilder::DefineAsSpilled(
611 LTemplateResultInstruction<1>* instr,
614 new(zone()) LUnallocated(LUnallocated::FIXED_SLOT, index));
618 LInstruction* LChunkBuilder::DefineSameAsFirst(
619 LTemplateResultInstruction<1>* instr) {
621 new(zone()) LUnallocated(LUnallocated::SAME_AS_FIRST_INPUT));
625 LInstruction* LChunkBuilder::DefineFixed(LTemplateResultInstruction<1>* instr,
627 return Define(instr, ToUnallocated(reg));
631 LInstruction* LChunkBuilder::DefineFixedDouble(
632 LTemplateResultInstruction<1>* instr,
634 return Define(instr, ToUnallocated(reg));
638 LInstruction* LChunkBuilder::AssignEnvironment(LInstruction* instr) {
639 HEnvironment* hydrogen_env = current_block_->last_environment();
640 int argument_index_accumulator = 0;
641 ZoneList<HValue*> objects_to_materialize(0, zone());
642 instr->set_environment(CreateEnvironment(
643 hydrogen_env, &argument_index_accumulator, &objects_to_materialize));
648 LInstruction* LChunkBuilder::MarkAsCall(LInstruction* instr,
649 HInstruction* hinstr,
650 CanDeoptimize can_deoptimize) {
651 info()->MarkAsNonDeferredCalling();
657 instr = AssignPointerMap(instr);
659 // If instruction does not have side-effects lazy deoptimization
660 // after the call will try to deoptimize to the point before the call.
661 // Thus we still need to attach environment to this call even if
662 // call sequence can not deoptimize eagerly.
663 bool needs_environment =
664 (can_deoptimize == CAN_DEOPTIMIZE_EAGERLY) ||
665 !hinstr->HasObservableSideEffects();
666 if (needs_environment && !instr->HasEnvironment()) {
667 instr = AssignEnvironment(instr);
668 // We can't really figure out if the environment is needed or not.
669 instr->environment()->set_has_been_used();
676 LInstruction* LChunkBuilder::AssignPointerMap(LInstruction* instr) {
677 DCHECK(!instr->HasPointerMap());
678 instr->set_pointer_map(new(zone()) LPointerMap(zone()));
683 LUnallocated* LChunkBuilder::TempRegister() {
684 LUnallocated* operand =
685 new(zone()) LUnallocated(LUnallocated::MUST_HAVE_REGISTER);
686 int vreg = allocator_->GetVirtualRegister();
687 if (!allocator_->AllocationOk()) {
688 Abort(kOutOfVirtualRegistersWhileTryingToAllocateTempRegister);
691 operand->set_virtual_register(vreg);
696 LOperand* LChunkBuilder::FixedTemp(Register reg) {
697 LUnallocated* operand = ToUnallocated(reg);
698 DCHECK(operand->HasFixedPolicy());
703 LOperand* LChunkBuilder::FixedTemp(XMMRegister reg) {
704 LUnallocated* operand = ToUnallocated(reg);
705 DCHECK(operand->HasFixedPolicy());
710 LInstruction* LChunkBuilder::DoBlockEntry(HBlockEntry* instr) {
711 return new(zone()) LLabel(instr->block());
715 LInstruction* LChunkBuilder::DoDummyUse(HDummyUse* instr) {
716 return DefineAsRegister(new(zone()) LDummyUse(UseAny(instr->value())));
720 LInstruction* LChunkBuilder::DoEnvironmentMarker(HEnvironmentMarker* instr) {
726 LInstruction* LChunkBuilder::DoDeoptimize(HDeoptimize* instr) {
727 return AssignEnvironment(new(zone()) LDeoptimize);
731 LInstruction* LChunkBuilder::DoShift(Token::Value op,
732 HBitwiseBinaryOperation* instr) {
733 if (instr->representation().IsSmiOrInteger32()) {
734 DCHECK(instr->left()->representation().Equals(instr->representation()));
735 DCHECK(instr->right()->representation().Equals(instr->representation()));
736 LOperand* left = UseRegisterAtStart(instr->left());
738 HValue* right_value = instr->right();
739 LOperand* right = NULL;
740 int constant_value = 0;
741 bool does_deopt = false;
742 if (right_value->IsConstant()) {
743 HConstant* constant = HConstant::cast(right_value);
744 right = chunk_->DefineConstantOperand(constant);
745 constant_value = constant->Integer32Value() & 0x1f;
746 // Left shifts can deoptimize if we shift by > 0 and the result cannot be
748 if (instr->representation().IsSmi() && constant_value > 0) {
749 does_deopt = !instr->CheckUsesForFlag(HValue::kTruncatingToSmi);
752 right = UseFixed(right_value, ecx);
755 // Shift operations can only deoptimize if we do a logical shift by 0 and
756 // the result cannot be truncated to int32.
757 if (op == Token::SHR && constant_value == 0) {
758 if (FLAG_opt_safe_uint32_operations) {
759 does_deopt = !instr->CheckFlag(HInstruction::kUint32);
761 does_deopt = !instr->CheckUsesForFlag(HValue::kTruncatingToInt32);
765 LInstruction* result =
766 DefineSameAsFirst(new(zone()) LShiftI(op, left, right, does_deopt));
767 return does_deopt ? AssignEnvironment(result) : result;
769 return DoArithmeticT(op, instr);
774 LInstruction* LChunkBuilder::DoArithmeticD(Token::Value op,
775 HArithmeticBinaryOperation* instr) {
776 DCHECK(instr->representation().IsDouble());
777 DCHECK(instr->left()->representation().IsDouble());
778 DCHECK(instr->right()->representation().IsDouble());
779 if (op == Token::MOD) {
780 LOperand* left = UseRegisterAtStart(instr->BetterLeftOperand());
781 LOperand* right = UseRegisterAtStart(instr->BetterRightOperand());
782 LArithmeticD* result = new(zone()) LArithmeticD(op, left, right);
783 return MarkAsCall(DefineSameAsFirst(result), instr);
785 LOperand* left = UseRegisterAtStart(instr->BetterLeftOperand());
786 LOperand* right = UseRegisterAtStart(instr->BetterRightOperand());
787 LArithmeticD* result = new(zone()) LArithmeticD(op, left, right);
788 return DefineSameAsFirst(result);
793 LInstruction* LChunkBuilder::DoArithmeticT(Token::Value op,
794 HBinaryOperation* instr) {
795 HValue* left = instr->left();
796 HValue* right = instr->right();
797 DCHECK(left->representation().IsTagged());
798 DCHECK(right->representation().IsTagged());
799 LOperand* context = UseFixed(instr->context(), esi);
800 LOperand* left_operand = UseFixed(left, edx);
801 LOperand* right_operand = UseFixed(right, eax);
802 LArithmeticT* result =
803 new(zone()) LArithmeticT(op, context, left_operand, right_operand);
804 return MarkAsCall(DefineFixed(result, eax), instr);
808 void LChunkBuilder::DoBasicBlock(HBasicBlock* block, HBasicBlock* next_block) {
809 DCHECK(is_building());
810 current_block_ = block;
811 next_block_ = next_block;
812 if (block->IsStartBlock()) {
813 block->UpdateEnvironment(graph_->start_environment());
815 } else if (block->predecessors()->length() == 1) {
816 // We have a single predecessor => copy environment and outgoing
817 // argument count from the predecessor.
818 DCHECK(block->phis()->length() == 0);
819 HBasicBlock* pred = block->predecessors()->at(0);
820 HEnvironment* last_environment = pred->last_environment();
821 DCHECK(last_environment != NULL);
822 // Only copy the environment, if it is later used again.
823 if (pred->end()->SecondSuccessor() == NULL) {
824 DCHECK(pred->end()->FirstSuccessor() == block);
826 if (pred->end()->FirstSuccessor()->block_id() > block->block_id() ||
827 pred->end()->SecondSuccessor()->block_id() > block->block_id()) {
828 last_environment = last_environment->Copy();
831 block->UpdateEnvironment(last_environment);
832 DCHECK(pred->argument_count() >= 0);
833 argument_count_ = pred->argument_count();
835 // We are at a state join => process phis.
836 HBasicBlock* pred = block->predecessors()->at(0);
837 // No need to copy the environment, it cannot be used later.
838 HEnvironment* last_environment = pred->last_environment();
839 for (int i = 0; i < block->phis()->length(); ++i) {
840 HPhi* phi = block->phis()->at(i);
841 if (phi->HasMergedIndex()) {
842 last_environment->SetValueAt(phi->merged_index(), phi);
845 for (int i = 0; i < block->deleted_phis()->length(); ++i) {
846 if (block->deleted_phis()->at(i) < last_environment->length()) {
847 last_environment->SetValueAt(block->deleted_phis()->at(i),
848 graph_->GetConstantUndefined());
851 block->UpdateEnvironment(last_environment);
852 // Pick up the outgoing argument count of one of the predecessors.
853 argument_count_ = pred->argument_count();
855 HInstruction* current = block->first();
856 int start = chunk_->instructions()->length();
857 while (current != NULL && !is_aborted()) {
858 // Code for constants in registers is generated lazily.
859 if (!current->EmitAtUses()) {
860 VisitInstruction(current);
862 current = current->next();
864 int end = chunk_->instructions()->length() - 1;
866 block->set_first_instruction_index(start);
867 block->set_last_instruction_index(end);
869 block->set_argument_count(argument_count_);
871 current_block_ = NULL;
875 void LChunkBuilder::VisitInstruction(HInstruction* current) {
876 HInstruction* old_current = current_instruction_;
877 current_instruction_ = current;
879 LInstruction* instr = NULL;
880 if (current->CanReplaceWithDummyUses()) {
881 if (current->OperandCount() == 0) {
882 instr = DefineAsRegister(new(zone()) LDummy());
884 DCHECK(!current->OperandAt(0)->IsControlInstruction());
885 instr = DefineAsRegister(new(zone())
886 LDummyUse(UseAny(current->OperandAt(0))));
888 for (int i = 1; i < current->OperandCount(); ++i) {
889 if (current->OperandAt(i)->IsControlInstruction()) continue;
890 LInstruction* dummy =
891 new(zone()) LDummyUse(UseAny(current->OperandAt(i)));
892 dummy->set_hydrogen_value(current);
893 chunk_->AddInstruction(dummy, current_block_);
896 HBasicBlock* successor;
897 if (current->IsControlInstruction() &&
898 HControlInstruction::cast(current)->KnownSuccessorBlock(&successor) &&
900 instr = new(zone()) LGoto(successor);
902 instr = current->CompileToLithium(this);
906 argument_count_ += current->argument_delta();
907 DCHECK(argument_count_ >= 0);
910 AddInstruction(instr, current);
913 current_instruction_ = old_current;
917 void LChunkBuilder::AddInstruction(LInstruction* instr,
918 HInstruction* hydrogen_val) {
919 // Associate the hydrogen instruction first, since we may need it for
920 // the ClobbersRegisters() or ClobbersDoubleRegisters() calls below.
921 instr->set_hydrogen_value(hydrogen_val);
924 // Make sure that the lithium instruction has either no fixed register
925 // constraints in temps or the result OR no uses that are only used at
926 // start. If this invariant doesn't hold, the register allocator can decide
927 // to insert a split of a range immediately before the instruction due to an
928 // already allocated register needing to be used for the instruction's fixed
929 // register constraint. In this case, The register allocator won't see an
930 // interference between the split child and the use-at-start (it would if
931 // the it was just a plain use), so it is free to move the split child into
932 // the same register that is used for the use-at-start.
933 // See https://code.google.com/p/chromium/issues/detail?id=201590
934 if (!(instr->ClobbersRegisters() &&
935 instr->ClobbersDoubleRegisters(isolate()))) {
937 int used_at_start = 0;
938 for (UseIterator it(instr); !it.Done(); it.Advance()) {
939 LUnallocated* operand = LUnallocated::cast(it.Current());
940 if (operand->IsUsedAtStart()) ++used_at_start;
942 if (instr->Output() != NULL) {
943 if (LUnallocated::cast(instr->Output())->HasFixedPolicy()) ++fixed;
945 for (TempIterator it(instr); !it.Done(); it.Advance()) {
946 LUnallocated* operand = LUnallocated::cast(it.Current());
947 if (operand->HasFixedPolicy()) ++fixed;
949 DCHECK(fixed == 0 || used_at_start == 0);
953 if (FLAG_stress_pointer_maps && !instr->HasPointerMap()) {
954 instr = AssignPointerMap(instr);
956 if (FLAG_stress_environments && !instr->HasEnvironment()) {
957 instr = AssignEnvironment(instr);
959 chunk_->AddInstruction(instr, current_block_);
961 if (instr->IsCall()) {
962 HValue* hydrogen_value_for_lazy_bailout = hydrogen_val;
963 LInstruction* instruction_needing_environment = NULL;
964 if (hydrogen_val->HasObservableSideEffects()) {
965 HSimulate* sim = HSimulate::cast(hydrogen_val->next());
966 instruction_needing_environment = instr;
967 sim->ReplayEnvironment(current_block_->last_environment());
968 hydrogen_value_for_lazy_bailout = sim;
970 LInstruction* bailout = AssignEnvironment(new(zone()) LLazyBailout());
971 bailout->set_hydrogen_value(hydrogen_value_for_lazy_bailout);
972 chunk_->AddInstruction(bailout, current_block_);
973 if (instruction_needing_environment != NULL) {
974 // Store the lazy deopt environment with the instruction if needed.
975 // Right now it is only used for LInstanceOfKnownGlobal.
976 instruction_needing_environment->
977 SetDeferredLazyDeoptimizationEnvironment(bailout->environment());
983 LInstruction* LChunkBuilder::DoGoto(HGoto* instr) {
984 return new(zone()) LGoto(instr->FirstSuccessor());
988 LInstruction* LChunkBuilder::DoBranch(HBranch* instr) {
989 HValue* value = instr->value();
990 Representation r = value->representation();
991 HType type = value->type();
992 ToBooleanStub::Types expected = instr->expected_input_types();
993 if (expected.IsEmpty()) expected = ToBooleanStub::Types::Generic();
995 bool easy_case = !r.IsTagged() || type.IsBoolean() || type.IsSmi() ||
996 type.IsJSArray() || type.IsHeapNumber() || type.IsString();
998 LOperand* temp = !easy_case && expected.NeedsMap() ? TempRegister() : NULL;
999 LInstruction* branch = new(zone()) LBranch(UseRegister(value), temp);
1001 ((!expected.Contains(ToBooleanStub::SMI) && expected.NeedsMap()) ||
1002 !expected.IsGeneric())) {
1003 branch = AssignEnvironment(branch);
1009 LInstruction* LChunkBuilder::DoDebugBreak(HDebugBreak* instr) {
1010 return new(zone()) LDebugBreak();
1014 LInstruction* LChunkBuilder::DoCompareMap(HCompareMap* instr) {
1015 DCHECK(instr->value()->representation().IsTagged());
1016 LOperand* value = UseRegisterAtStart(instr->value());
1017 return new(zone()) LCmpMapAndBranch(value);
1021 LInstruction* LChunkBuilder::DoArgumentsLength(HArgumentsLength* length) {
1022 info()->MarkAsRequiresFrame();
1023 return DefineAsRegister(new(zone()) LArgumentsLength(Use(length->value())));
1027 LInstruction* LChunkBuilder::DoArgumentsElements(HArgumentsElements* elems) {
1028 info()->MarkAsRequiresFrame();
1029 return DefineAsRegister(new(zone()) LArgumentsElements);
1033 LInstruction* LChunkBuilder::DoInstanceOf(HInstanceOf* instr) {
1034 LOperand* left = UseFixed(instr->left(), InstanceofStub::left());
1035 LOperand* right = UseFixed(instr->right(), InstanceofStub::right());
1036 LOperand* context = UseFixed(instr->context(), esi);
1037 LInstanceOf* result = new(zone()) LInstanceOf(context, left, right);
1038 return MarkAsCall(DefineFixed(result, eax), instr);
1042 LInstruction* LChunkBuilder::DoInstanceOfKnownGlobal(
1043 HInstanceOfKnownGlobal* instr) {
1044 LInstanceOfKnownGlobal* result =
1045 new(zone()) LInstanceOfKnownGlobal(
1046 UseFixed(instr->context(), esi),
1047 UseFixed(instr->left(), InstanceofStub::left()),
1049 return MarkAsCall(DefineFixed(result, eax), instr);
1053 LInstruction* LChunkBuilder::DoWrapReceiver(HWrapReceiver* instr) {
1054 LOperand* receiver = UseRegister(instr->receiver());
1055 LOperand* function = UseRegister(instr->function());
1056 LOperand* temp = TempRegister();
1057 LWrapReceiver* result =
1058 new(zone()) LWrapReceiver(receiver, function, temp);
1059 return AssignEnvironment(DefineSameAsFirst(result));
1063 LInstruction* LChunkBuilder::DoApplyArguments(HApplyArguments* instr) {
1064 LOperand* function = UseFixed(instr->function(), edi);
1065 LOperand* receiver = UseFixed(instr->receiver(), eax);
1066 LOperand* length = UseFixed(instr->length(), ebx);
1067 LOperand* elements = UseFixed(instr->elements(), ecx);
1068 LApplyArguments* result = new(zone()) LApplyArguments(function,
1072 return MarkAsCall(DefineFixed(result, eax), instr, CAN_DEOPTIMIZE_EAGERLY);
1076 LInstruction* LChunkBuilder::DoPushArguments(HPushArguments* instr) {
1077 int argc = instr->OperandCount();
1078 for (int i = 0; i < argc; ++i) {
1079 LOperand* argument = UseAny(instr->argument(i));
1080 AddInstruction(new(zone()) LPushArgument(argument), instr);
1086 LInstruction* LChunkBuilder::DoStoreCodeEntry(
1087 HStoreCodeEntry* store_code_entry) {
1088 LOperand* function = UseRegister(store_code_entry->function());
1089 LOperand* code_object = UseTempRegister(store_code_entry->code_object());
1090 return new(zone()) LStoreCodeEntry(function, code_object);
1094 LInstruction* LChunkBuilder::DoInnerAllocatedObject(
1095 HInnerAllocatedObject* instr) {
1096 LOperand* base_object = UseRegisterAtStart(instr->base_object());
1097 LOperand* offset = UseRegisterOrConstantAtStart(instr->offset());
1098 return DefineAsRegister(
1099 new(zone()) LInnerAllocatedObject(base_object, offset));
1103 LInstruction* LChunkBuilder::DoThisFunction(HThisFunction* instr) {
1104 return instr->HasNoUses()
1106 : DefineAsRegister(new(zone()) LThisFunction);
1110 LInstruction* LChunkBuilder::DoContext(HContext* instr) {
1111 if (instr->HasNoUses()) return NULL;
1113 if (info()->IsStub()) {
1114 return DefineFixed(new(zone()) LContext, esi);
1117 return DefineAsRegister(new(zone()) LContext);
1121 LInstruction* LChunkBuilder::DoDeclareGlobals(HDeclareGlobals* instr) {
1122 LOperand* context = UseFixed(instr->context(), esi);
1123 return MarkAsCall(new(zone()) LDeclareGlobals(context), instr);
1127 LInstruction* LChunkBuilder::DoCallJSFunction(
1128 HCallJSFunction* instr) {
1129 LOperand* function = UseFixed(instr->function(), edi);
1131 LCallJSFunction* result = new(zone()) LCallJSFunction(function);
1133 return MarkAsCall(DefineFixed(result, eax), instr, CANNOT_DEOPTIMIZE_EAGERLY);
1137 LInstruction* LChunkBuilder::DoCallWithDescriptor(
1138 HCallWithDescriptor* instr) {
1139 CallInterfaceDescriptor descriptor = instr->descriptor();
1140 LOperand* target = UseRegisterOrConstantAtStart(instr->target());
1141 ZoneList<LOperand*> ops(instr->OperandCount(), zone());
1142 ops.Add(target, zone());
1143 for (int i = 1; i < instr->OperandCount(); i++) {
1145 UseFixed(instr->OperandAt(i), descriptor.GetParameterRegister(i - 1));
1146 ops.Add(op, zone());
1149 LCallWithDescriptor* result = new(zone()) LCallWithDescriptor(
1150 descriptor, ops, zone());
1151 return MarkAsCall(DefineFixed(result, eax), instr, CANNOT_DEOPTIMIZE_EAGERLY);
1155 LInstruction* LChunkBuilder::DoTailCallThroughMegamorphicCache(
1156 HTailCallThroughMegamorphicCache* instr) {
1157 LOperand* context = UseFixed(instr->context(), esi);
1158 LOperand* receiver_register =
1159 UseFixed(instr->receiver(), LoadDescriptor::ReceiverRegister());
1160 LOperand* name_register =
1161 UseFixed(instr->name(), LoadDescriptor::NameRegister());
1162 // Not marked as call. It can't deoptimize, and it never returns.
1163 return new (zone()) LTailCallThroughMegamorphicCache(
1164 context, receiver_register, name_register);
1168 LInstruction* LChunkBuilder::DoInvokeFunction(HInvokeFunction* instr) {
1169 LOperand* context = UseFixed(instr->context(), esi);
1170 LOperand* function = UseFixed(instr->function(), edi);
1171 LInvokeFunction* result = new(zone()) LInvokeFunction(context, function);
1172 return MarkAsCall(DefineFixed(result, eax), instr, CANNOT_DEOPTIMIZE_EAGERLY);
1176 LInstruction* LChunkBuilder::DoUnaryMathOperation(HUnaryMathOperation* instr) {
1177 switch (instr->op()) {
1179 return DoMathFloor(instr);
1181 return DoMathRound(instr);
1183 return DoMathFround(instr);
1185 return DoMathAbs(instr);
1187 return DoMathLog(instr);
1189 return DoMathExp(instr);
1191 return DoMathSqrt(instr);
1193 return DoMathPowHalf(instr);
1195 return DoMathClz32(instr);
1203 LInstruction* LChunkBuilder::DoMathFloor(HUnaryMathOperation* instr) {
1204 LOperand* input = UseRegisterAtStart(instr->value());
1205 LMathFloor* result = new(zone()) LMathFloor(input);
1206 return AssignEnvironment(DefineAsRegister(result));
1210 LInstruction* LChunkBuilder::DoMathRound(HUnaryMathOperation* instr) {
1211 LOperand* input = UseRegister(instr->value());
1212 LOperand* temp = FixedTemp(xmm4);
1213 LMathRound* result = new(zone()) LMathRound(input, temp);
1214 return AssignEnvironment(DefineAsRegister(result));
1218 LInstruction* LChunkBuilder::DoMathFround(HUnaryMathOperation* instr) {
1219 LOperand* input = UseRegister(instr->value());
1220 LMathFround* result = new (zone()) LMathFround(input);
1221 return DefineAsRegister(result);
1225 LInstruction* LChunkBuilder::DoMathAbs(HUnaryMathOperation* instr) {
1226 LOperand* context = UseAny(instr->context()); // Deferred use.
1227 LOperand* input = UseRegisterAtStart(instr->value());
1228 LInstruction* result =
1229 DefineSameAsFirst(new(zone()) LMathAbs(context, input));
1230 Representation r = instr->value()->representation();
1231 if (!r.IsDouble() && !r.IsSmiOrInteger32()) result = AssignPointerMap(result);
1232 if (!r.IsDouble()) result = AssignEnvironment(result);
1237 LInstruction* LChunkBuilder::DoMathLog(HUnaryMathOperation* instr) {
1238 DCHECK(instr->representation().IsDouble());
1239 DCHECK(instr->value()->representation().IsDouble());
1240 LOperand* input = UseRegisterAtStart(instr->value());
1241 return MarkAsCall(DefineSameAsFirst(new(zone()) LMathLog(input)), instr);
1245 LInstruction* LChunkBuilder::DoMathClz32(HUnaryMathOperation* instr) {
1246 LOperand* input = UseRegisterAtStart(instr->value());
1247 LMathClz32* result = new(zone()) LMathClz32(input);
1248 return DefineAsRegister(result);
1252 LInstruction* LChunkBuilder::DoMathExp(HUnaryMathOperation* instr) {
1253 DCHECK(instr->representation().IsDouble());
1254 DCHECK(instr->value()->representation().IsDouble());
1255 LOperand* value = UseTempRegister(instr->value());
1256 LOperand* temp1 = TempRegister();
1257 LOperand* temp2 = TempRegister();
1258 LMathExp* result = new(zone()) LMathExp(value, temp1, temp2);
1259 return DefineAsRegister(result);
1263 LInstruction* LChunkBuilder::DoMathSqrt(HUnaryMathOperation* instr) {
1264 LOperand* input = UseAtStart(instr->value());
1265 return DefineAsRegister(new(zone()) LMathSqrt(input));
1269 LInstruction* LChunkBuilder::DoMathPowHalf(HUnaryMathOperation* instr) {
1270 LOperand* input = UseRegisterAtStart(instr->value());
1271 LOperand* temp = TempRegister();
1272 LMathPowHalf* result = new(zone()) LMathPowHalf(input, temp);
1273 return DefineSameAsFirst(result);
1277 LInstruction* LChunkBuilder::DoCallNew(HCallNew* instr) {
1278 LOperand* context = UseFixed(instr->context(), esi);
1279 LOperand* constructor = UseFixed(instr->constructor(), edi);
1280 LCallNew* result = new(zone()) LCallNew(context, constructor);
1281 return MarkAsCall(DefineFixed(result, eax), instr);
1285 LInstruction* LChunkBuilder::DoCallNewArray(HCallNewArray* instr) {
1286 LOperand* context = UseFixed(instr->context(), esi);
1287 LOperand* constructor = UseFixed(instr->constructor(), edi);
1288 LCallNewArray* result = new(zone()) LCallNewArray(context, constructor);
1289 return MarkAsCall(DefineFixed(result, eax), instr);
1293 LInstruction* LChunkBuilder::DoCallFunction(HCallFunction* instr) {
1294 LOperand* context = UseFixed(instr->context(), esi);
1295 LOperand* function = UseFixed(instr->function(), edi);
1296 LCallFunction* call = new(zone()) LCallFunction(context, function);
1297 return MarkAsCall(DefineFixed(call, eax), instr);
1301 LInstruction* LChunkBuilder::DoCallRuntime(HCallRuntime* instr) {
1302 LOperand* context = UseFixed(instr->context(), esi);
1303 return MarkAsCall(DefineFixed(new(zone()) LCallRuntime(context), eax), instr);
1307 LInstruction* LChunkBuilder::DoRor(HRor* instr) {
1308 return DoShift(Token::ROR, instr);
1312 LInstruction* LChunkBuilder::DoShr(HShr* instr) {
1313 return DoShift(Token::SHR, instr);
1317 LInstruction* LChunkBuilder::DoSar(HSar* instr) {
1318 return DoShift(Token::SAR, instr);
1322 LInstruction* LChunkBuilder::DoShl(HShl* instr) {
1323 return DoShift(Token::SHL, instr);
1327 LInstruction* LChunkBuilder::DoBitwise(HBitwise* instr) {
1328 if (instr->representation().IsSmiOrInteger32()) {
1329 DCHECK(instr->left()->representation().Equals(instr->representation()));
1330 DCHECK(instr->right()->representation().Equals(instr->representation()));
1331 DCHECK(instr->CheckFlag(HValue::kTruncatingToInt32));
1333 LOperand* left = UseRegisterAtStart(instr->BetterLeftOperand());
1334 LOperand* right = UseOrConstantAtStart(instr->BetterRightOperand());
1335 return DefineSameAsFirst(new(zone()) LBitI(left, right));
1337 return DoArithmeticT(instr->op(), instr);
1342 LInstruction* LChunkBuilder::DoDivByPowerOf2I(HDiv* instr) {
1343 DCHECK(instr->representation().IsSmiOrInteger32());
1344 DCHECK(instr->left()->representation().Equals(instr->representation()));
1345 DCHECK(instr->right()->representation().Equals(instr->representation()));
1346 LOperand* dividend = UseRegister(instr->left());
1347 int32_t divisor = instr->right()->GetInteger32Constant();
1348 LInstruction* result = DefineAsRegister(new(zone()) LDivByPowerOf2I(
1349 dividend, divisor));
1350 if ((instr->CheckFlag(HValue::kBailoutOnMinusZero) && divisor < 0) ||
1351 (instr->CheckFlag(HValue::kCanOverflow) && divisor == -1) ||
1352 (!instr->CheckFlag(HInstruction::kAllUsesTruncatingToInt32) &&
1353 divisor != 1 && divisor != -1)) {
1354 result = AssignEnvironment(result);
1360 LInstruction* LChunkBuilder::DoDivByConstI(HDiv* instr) {
1361 DCHECK(instr->representation().IsInteger32());
1362 DCHECK(instr->left()->representation().Equals(instr->representation()));
1363 DCHECK(instr->right()->representation().Equals(instr->representation()));
1364 LOperand* dividend = UseRegister(instr->left());
1365 int32_t divisor = instr->right()->GetInteger32Constant();
1366 LOperand* temp1 = FixedTemp(eax);
1367 LOperand* temp2 = FixedTemp(edx);
1368 LInstruction* result = DefineFixed(new(zone()) LDivByConstI(
1369 dividend, divisor, temp1, temp2), edx);
1371 (instr->CheckFlag(HValue::kBailoutOnMinusZero) && divisor < 0) ||
1372 !instr->CheckFlag(HInstruction::kAllUsesTruncatingToInt32)) {
1373 result = AssignEnvironment(result);
1379 LInstruction* LChunkBuilder::DoDivI(HDiv* instr) {
1380 DCHECK(instr->representation().IsSmiOrInteger32());
1381 DCHECK(instr->left()->representation().Equals(instr->representation()));
1382 DCHECK(instr->right()->representation().Equals(instr->representation()));
1383 LOperand* dividend = UseFixed(instr->left(), eax);
1384 LOperand* divisor = UseRegister(instr->right());
1385 LOperand* temp = FixedTemp(edx);
1386 LInstruction* result = DefineFixed(new(zone()) LDivI(
1387 dividend, divisor, temp), eax);
1388 if (instr->CheckFlag(HValue::kCanBeDivByZero) ||
1389 instr->CheckFlag(HValue::kBailoutOnMinusZero) ||
1390 instr->CheckFlag(HValue::kCanOverflow) ||
1391 !instr->CheckFlag(HValue::kAllUsesTruncatingToInt32)) {
1392 result = AssignEnvironment(result);
1398 LInstruction* LChunkBuilder::DoDiv(HDiv* instr) {
1399 if (instr->representation().IsSmiOrInteger32()) {
1400 if (instr->RightIsPowerOf2()) {
1401 return DoDivByPowerOf2I(instr);
1402 } else if (instr->right()->IsConstant()) {
1403 return DoDivByConstI(instr);
1405 return DoDivI(instr);
1407 } else if (instr->representation().IsDouble()) {
1408 return DoArithmeticD(Token::DIV, instr);
1410 return DoArithmeticT(Token::DIV, instr);
1415 LInstruction* LChunkBuilder::DoFlooringDivByPowerOf2I(HMathFloorOfDiv* instr) {
1416 LOperand* dividend = UseRegisterAtStart(instr->left());
1417 int32_t divisor = instr->right()->GetInteger32Constant();
1418 LInstruction* result = DefineSameAsFirst(new(zone()) LFlooringDivByPowerOf2I(
1419 dividend, divisor));
1420 if ((instr->CheckFlag(HValue::kBailoutOnMinusZero) && divisor < 0) ||
1421 (instr->CheckFlag(HValue::kLeftCanBeMinInt) && divisor == -1)) {
1422 result = AssignEnvironment(result);
1428 LInstruction* LChunkBuilder::DoFlooringDivByConstI(HMathFloorOfDiv* instr) {
1429 DCHECK(instr->representation().IsInteger32());
1430 DCHECK(instr->left()->representation().Equals(instr->representation()));
1431 DCHECK(instr->right()->representation().Equals(instr->representation()));
1432 LOperand* dividend = UseRegister(instr->left());
1433 int32_t divisor = instr->right()->GetInteger32Constant();
1434 LOperand* temp1 = FixedTemp(eax);
1435 LOperand* temp2 = FixedTemp(edx);
1437 ((divisor > 0 && !instr->CheckFlag(HValue::kLeftCanBeNegative)) ||
1438 (divisor < 0 && !instr->CheckFlag(HValue::kLeftCanBePositive))) ?
1439 NULL : TempRegister();
1440 LInstruction* result =
1441 DefineFixed(new(zone()) LFlooringDivByConstI(dividend,
1448 (instr->CheckFlag(HValue::kBailoutOnMinusZero) && divisor < 0)) {
1449 result = AssignEnvironment(result);
1455 LInstruction* LChunkBuilder::DoFlooringDivI(HMathFloorOfDiv* instr) {
1456 DCHECK(instr->representation().IsSmiOrInteger32());
1457 DCHECK(instr->left()->representation().Equals(instr->representation()));
1458 DCHECK(instr->right()->representation().Equals(instr->representation()));
1459 LOperand* dividend = UseFixed(instr->left(), eax);
1460 LOperand* divisor = UseRegister(instr->right());
1461 LOperand* temp = FixedTemp(edx);
1462 LInstruction* result = DefineFixed(new(zone()) LFlooringDivI(
1463 dividend, divisor, temp), eax);
1464 if (instr->CheckFlag(HValue::kCanBeDivByZero) ||
1465 instr->CheckFlag(HValue::kBailoutOnMinusZero) ||
1466 instr->CheckFlag(HValue::kCanOverflow)) {
1467 result = AssignEnvironment(result);
1473 LInstruction* LChunkBuilder::DoMathFloorOfDiv(HMathFloorOfDiv* instr) {
1474 if (instr->RightIsPowerOf2()) {
1475 return DoFlooringDivByPowerOf2I(instr);
1476 } else if (instr->right()->IsConstant()) {
1477 return DoFlooringDivByConstI(instr);
1479 return DoFlooringDivI(instr);
1484 LInstruction* LChunkBuilder::DoModByPowerOf2I(HMod* instr) {
1485 DCHECK(instr->representation().IsSmiOrInteger32());
1486 DCHECK(instr->left()->representation().Equals(instr->representation()));
1487 DCHECK(instr->right()->representation().Equals(instr->representation()));
1488 LOperand* dividend = UseRegisterAtStart(instr->left());
1489 int32_t divisor = instr->right()->GetInteger32Constant();
1490 LInstruction* result = DefineSameAsFirst(new(zone()) LModByPowerOf2I(
1491 dividend, divisor));
1492 if (instr->CheckFlag(HValue::kLeftCanBeNegative) &&
1493 instr->CheckFlag(HValue::kBailoutOnMinusZero)) {
1494 result = AssignEnvironment(result);
1500 LInstruction* LChunkBuilder::DoModByConstI(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 = UseRegister(instr->left());
1505 int32_t divisor = instr->right()->GetInteger32Constant();
1506 LOperand* temp1 = FixedTemp(eax);
1507 LOperand* temp2 = FixedTemp(edx);
1508 LInstruction* result = DefineFixed(new(zone()) LModByConstI(
1509 dividend, divisor, temp1, temp2), eax);
1510 if (divisor == 0 || instr->CheckFlag(HValue::kBailoutOnMinusZero)) {
1511 result = AssignEnvironment(result);
1517 LInstruction* LChunkBuilder::DoModI(HMod* instr) {
1518 DCHECK(instr->representation().IsSmiOrInteger32());
1519 DCHECK(instr->left()->representation().Equals(instr->representation()));
1520 DCHECK(instr->right()->representation().Equals(instr->representation()));
1521 LOperand* dividend = UseFixed(instr->left(), eax);
1522 LOperand* divisor = UseRegister(instr->right());
1523 LOperand* temp = FixedTemp(edx);
1524 LInstruction* result = DefineFixed(new(zone()) LModI(
1525 dividend, divisor, temp), edx);
1526 if (instr->CheckFlag(HValue::kCanBeDivByZero) ||
1527 instr->CheckFlag(HValue::kBailoutOnMinusZero)) {
1528 result = AssignEnvironment(result);
1534 LInstruction* LChunkBuilder::DoMod(HMod* instr) {
1535 if (instr->representation().IsSmiOrInteger32()) {
1536 if (instr->RightIsPowerOf2()) {
1537 return DoModByPowerOf2I(instr);
1538 } else if (instr->right()->IsConstant()) {
1539 return DoModByConstI(instr);
1541 return DoModI(instr);
1543 } else if (instr->representation().IsDouble()) {
1544 return DoArithmeticD(Token::MOD, instr);
1546 return DoArithmeticT(Token::MOD, instr);
1551 LInstruction* LChunkBuilder::DoMul(HMul* instr) {
1552 if (instr->representation().IsSmiOrInteger32()) {
1553 DCHECK(instr->left()->representation().Equals(instr->representation()));
1554 DCHECK(instr->right()->representation().Equals(instr->representation()));
1555 LOperand* left = UseRegisterAtStart(instr->BetterLeftOperand());
1556 LOperand* right = UseOrConstant(instr->BetterRightOperand());
1557 LOperand* temp = NULL;
1558 if (instr->CheckFlag(HValue::kBailoutOnMinusZero)) {
1559 temp = TempRegister();
1561 LMulI* mul = new(zone()) LMulI(left, right, temp);
1562 if (instr->CheckFlag(HValue::kCanOverflow) ||
1563 instr->CheckFlag(HValue::kBailoutOnMinusZero)) {
1564 AssignEnvironment(mul);
1566 return DefineSameAsFirst(mul);
1567 } else if (instr->representation().IsDouble()) {
1568 return DoArithmeticD(Token::MUL, instr);
1570 return DoArithmeticT(Token::MUL, instr);
1575 LInstruction* LChunkBuilder::DoSub(HSub* instr) {
1576 if (instr->representation().IsSmiOrInteger32()) {
1577 DCHECK(instr->left()->representation().Equals(instr->representation()));
1578 DCHECK(instr->right()->representation().Equals(instr->representation()));
1579 LOperand* left = UseRegisterAtStart(instr->left());
1580 LOperand* right = UseOrConstantAtStart(instr->right());
1581 LSubI* sub = new(zone()) LSubI(left, right);
1582 LInstruction* result = DefineSameAsFirst(sub);
1583 if (instr->CheckFlag(HValue::kCanOverflow)) {
1584 result = AssignEnvironment(result);
1587 } else if (instr->representation().IsDouble()) {
1588 return DoArithmeticD(Token::SUB, instr);
1590 return DoArithmeticT(Token::SUB, instr);
1595 LInstruction* LChunkBuilder::DoAdd(HAdd* instr) {
1596 if (instr->representation().IsSmiOrInteger32()) {
1597 DCHECK(instr->left()->representation().Equals(instr->representation()));
1598 DCHECK(instr->right()->representation().Equals(instr->representation()));
1599 // Check to see if it would be advantageous to use an lea instruction rather
1600 // than an add. This is the case when no overflow check is needed and there
1601 // are multiple uses of the add's inputs, so using a 3-register add will
1602 // preserve all input values for later uses.
1603 bool use_lea = LAddI::UseLea(instr);
1604 LOperand* left = UseRegisterAtStart(instr->BetterLeftOperand());
1605 HValue* right_candidate = instr->BetterRightOperand();
1606 LOperand* right = use_lea
1607 ? UseRegisterOrConstantAtStart(right_candidate)
1608 : UseOrConstantAtStart(right_candidate);
1609 LAddI* add = new(zone()) LAddI(left, right);
1610 bool can_overflow = instr->CheckFlag(HValue::kCanOverflow);
1611 LInstruction* result = use_lea
1612 ? DefineAsRegister(add)
1613 : DefineSameAsFirst(add);
1615 result = AssignEnvironment(result);
1618 } else if (instr->representation().IsDouble()) {
1619 return DoArithmeticD(Token::ADD, instr);
1620 } else if (instr->representation().IsExternal()) {
1621 DCHECK(instr->left()->representation().IsExternal());
1622 DCHECK(instr->right()->representation().IsInteger32());
1623 DCHECK(!instr->CheckFlag(HValue::kCanOverflow));
1624 bool use_lea = LAddI::UseLea(instr);
1625 LOperand* left = UseRegisterAtStart(instr->left());
1626 HValue* right_candidate = instr->right();
1627 LOperand* right = use_lea
1628 ? UseRegisterOrConstantAtStart(right_candidate)
1629 : UseOrConstantAtStart(right_candidate);
1630 LAddI* add = new(zone()) LAddI(left, right);
1631 LInstruction* result = use_lea
1632 ? DefineAsRegister(add)
1633 : DefineSameAsFirst(add);
1636 return DoArithmeticT(Token::ADD, instr);
1641 LInstruction* LChunkBuilder::DoMathMinMax(HMathMinMax* instr) {
1642 LOperand* left = NULL;
1643 LOperand* right = NULL;
1644 if (instr->representation().IsSmiOrInteger32()) {
1645 DCHECK(instr->left()->representation().Equals(instr->representation()));
1646 DCHECK(instr->right()->representation().Equals(instr->representation()));
1647 left = UseRegisterAtStart(instr->BetterLeftOperand());
1648 right = UseOrConstantAtStart(instr->BetterRightOperand());
1650 DCHECK(instr->representation().IsDouble());
1651 DCHECK(instr->left()->representation().IsDouble());
1652 DCHECK(instr->right()->representation().IsDouble());
1653 left = UseRegisterAtStart(instr->left());
1654 right = UseRegisterAtStart(instr->right());
1656 LMathMinMax* minmax = new(zone()) LMathMinMax(left, right);
1657 return DefineSameAsFirst(minmax);
1661 LInstruction* LChunkBuilder::DoPower(HPower* instr) {
1662 DCHECK(instr->representation().IsDouble());
1663 // We call a C function for double power. It can't trigger a GC.
1664 // We need to use fixed result register for the call.
1665 Representation exponent_type = instr->right()->representation();
1666 DCHECK(instr->left()->representation().IsDouble());
1667 LOperand* left = UseFixedDouble(instr->left(), xmm2);
1669 exponent_type.IsDouble()
1670 ? UseFixedDouble(instr->right(), xmm1)
1671 : UseFixed(instr->right(), MathPowTaggedDescriptor::exponent());
1672 LPower* result = new(zone()) LPower(left, right);
1673 return MarkAsCall(DefineFixedDouble(result, xmm3), instr,
1674 CAN_DEOPTIMIZE_EAGERLY);
1678 LInstruction* LChunkBuilder::DoCompareGeneric(HCompareGeneric* instr) {
1679 DCHECK(instr->left()->representation().IsSmiOrTagged());
1680 DCHECK(instr->right()->representation().IsSmiOrTagged());
1681 LOperand* context = UseFixed(instr->context(), esi);
1682 LOperand* left = UseFixed(instr->left(), edx);
1683 LOperand* right = UseFixed(instr->right(), eax);
1684 LCmpT* result = new(zone()) LCmpT(context, left, right);
1685 return MarkAsCall(DefineFixed(result, eax), instr);
1689 LInstruction* LChunkBuilder::DoCompareNumericAndBranch(
1690 HCompareNumericAndBranch* instr) {
1691 Representation r = instr->representation();
1692 if (r.IsSmiOrInteger32()) {
1693 DCHECK(instr->left()->representation().Equals(r));
1694 DCHECK(instr->right()->representation().Equals(r));
1695 LOperand* left = UseRegisterOrConstantAtStart(instr->left());
1696 LOperand* right = UseOrConstantAtStart(instr->right());
1697 return new(zone()) LCompareNumericAndBranch(left, right);
1699 DCHECK(r.IsDouble());
1700 DCHECK(instr->left()->representation().IsDouble());
1701 DCHECK(instr->right()->representation().IsDouble());
1704 if (CanBeImmediateConstant(instr->left()) &&
1705 CanBeImmediateConstant(instr->right())) {
1706 // The code generator requires either both inputs to be constant
1707 // operands, or neither.
1708 left = UseConstant(instr->left());
1709 right = UseConstant(instr->right());
1711 left = UseRegisterAtStart(instr->left());
1712 right = UseRegisterAtStart(instr->right());
1714 return new(zone()) LCompareNumericAndBranch(left, right);
1719 LInstruction* LChunkBuilder::DoCompareObjectEqAndBranch(
1720 HCompareObjectEqAndBranch* instr) {
1721 LOperand* left = UseRegisterAtStart(instr->left());
1722 LOperand* right = UseOrConstantAtStart(instr->right());
1723 return new(zone()) LCmpObjectEqAndBranch(left, right);
1727 LInstruction* LChunkBuilder::DoCompareHoleAndBranch(
1728 HCompareHoleAndBranch* instr) {
1729 LOperand* value = UseRegisterAtStart(instr->value());
1730 return new(zone()) LCmpHoleAndBranch(value);
1734 LInstruction* LChunkBuilder::DoCompareMinusZeroAndBranch(
1735 HCompareMinusZeroAndBranch* instr) {
1736 LOperand* value = UseRegister(instr->value());
1737 LOperand* scratch = TempRegister();
1738 return new(zone()) LCompareMinusZeroAndBranch(value, scratch);
1742 LInstruction* LChunkBuilder::DoIsObjectAndBranch(HIsObjectAndBranch* instr) {
1743 DCHECK(instr->value()->representation().IsSmiOrTagged());
1744 LOperand* temp = TempRegister();
1745 return new(zone()) LIsObjectAndBranch(UseRegister(instr->value()), temp);
1749 LInstruction* LChunkBuilder::DoIsStringAndBranch(HIsStringAndBranch* instr) {
1750 DCHECK(instr->value()->representation().IsTagged());
1751 LOperand* temp = TempRegister();
1752 return new(zone()) LIsStringAndBranch(UseRegister(instr->value()), temp);
1756 LInstruction* LChunkBuilder::DoIsSmiAndBranch(HIsSmiAndBranch* instr) {
1757 DCHECK(instr->value()->representation().IsTagged());
1758 return new(zone()) LIsSmiAndBranch(Use(instr->value()));
1762 LInstruction* LChunkBuilder::DoIsUndetectableAndBranch(
1763 HIsUndetectableAndBranch* instr) {
1764 DCHECK(instr->value()->representation().IsTagged());
1765 return new(zone()) LIsUndetectableAndBranch(
1766 UseRegisterAtStart(instr->value()), TempRegister());
1770 LInstruction* LChunkBuilder::DoStringCompareAndBranch(
1771 HStringCompareAndBranch* instr) {
1772 DCHECK(instr->left()->representation().IsTagged());
1773 DCHECK(instr->right()->representation().IsTagged());
1774 LOperand* context = UseFixed(instr->context(), esi);
1775 LOperand* left = UseFixed(instr->left(), edx);
1776 LOperand* right = UseFixed(instr->right(), eax);
1778 LStringCompareAndBranch* result = new(zone())
1779 LStringCompareAndBranch(context, left, right);
1781 return MarkAsCall(result, instr);
1785 LInstruction* LChunkBuilder::DoHasInstanceTypeAndBranch(
1786 HHasInstanceTypeAndBranch* instr) {
1787 DCHECK(instr->value()->representation().IsTagged());
1788 return new(zone()) LHasInstanceTypeAndBranch(
1789 UseRegisterAtStart(instr->value()),
1794 LInstruction* LChunkBuilder::DoGetCachedArrayIndex(
1795 HGetCachedArrayIndex* instr) {
1796 DCHECK(instr->value()->representation().IsTagged());
1797 LOperand* value = UseRegisterAtStart(instr->value());
1799 return DefineAsRegister(new(zone()) LGetCachedArrayIndex(value));
1803 LInstruction* LChunkBuilder::DoHasCachedArrayIndexAndBranch(
1804 HHasCachedArrayIndexAndBranch* instr) {
1805 DCHECK(instr->value()->representation().IsTagged());
1806 return new(zone()) LHasCachedArrayIndexAndBranch(
1807 UseRegisterAtStart(instr->value()));
1811 LInstruction* LChunkBuilder::DoClassOfTestAndBranch(
1812 HClassOfTestAndBranch* instr) {
1813 DCHECK(instr->value()->representation().IsTagged());
1814 return new(zone()) LClassOfTestAndBranch(UseRegister(instr->value()),
1820 LInstruction* LChunkBuilder::DoMapEnumLength(HMapEnumLength* instr) {
1821 LOperand* map = UseRegisterAtStart(instr->value());
1822 return DefineAsRegister(new(zone()) LMapEnumLength(map));
1826 LInstruction* LChunkBuilder::DoDateField(HDateField* instr) {
1827 LOperand* date = UseFixed(instr->value(), eax);
1828 LDateField* result =
1829 new(zone()) LDateField(date, FixedTemp(ecx), instr->index());
1830 return MarkAsCall(DefineFixed(result, eax), instr, CAN_DEOPTIMIZE_EAGERLY);
1834 LInstruction* LChunkBuilder::DoSeqStringGetChar(HSeqStringGetChar* instr) {
1835 LOperand* string = UseRegisterAtStart(instr->string());
1836 LOperand* index = UseRegisterOrConstantAtStart(instr->index());
1837 return DefineAsRegister(new(zone()) LSeqStringGetChar(string, index));
1841 LOperand* LChunkBuilder::GetSeqStringSetCharOperand(HSeqStringSetChar* instr) {
1842 if (instr->encoding() == String::ONE_BYTE_ENCODING) {
1843 if (FLAG_debug_code) {
1844 return UseFixed(instr->value(), eax);
1846 return UseFixedOrConstant(instr->value(), eax);
1849 if (FLAG_debug_code) {
1850 return UseRegisterAtStart(instr->value());
1852 return UseRegisterOrConstantAtStart(instr->value());
1858 LInstruction* LChunkBuilder::DoSeqStringSetChar(HSeqStringSetChar* instr) {
1859 LOperand* string = UseRegisterAtStart(instr->string());
1860 LOperand* index = FLAG_debug_code
1861 ? UseRegisterAtStart(instr->index())
1862 : UseRegisterOrConstantAtStart(instr->index());
1863 LOperand* value = GetSeqStringSetCharOperand(instr);
1864 LOperand* context = FLAG_debug_code ? UseFixed(instr->context(), esi) : NULL;
1865 LInstruction* result = new(zone()) LSeqStringSetChar(context, string,
1867 if (FLAG_debug_code) {
1868 result = MarkAsCall(result, instr);
1874 LInstruction* LChunkBuilder::DoBoundsCheck(HBoundsCheck* instr) {
1875 if (!FLAG_debug_code && instr->skip_check()) return NULL;
1876 LOperand* index = UseRegisterOrConstantAtStart(instr->index());
1877 LOperand* length = !index->IsConstantOperand()
1878 ? UseOrConstantAtStart(instr->length())
1879 : UseAtStart(instr->length());
1880 LOperand* temp0 = TempRegister();
1881 LOperand* temp1 = TempRegister();
1882 LInstruction* result = new(zone()) LBoundsCheck(index, length, temp0, temp1);
1883 if (!FLAG_debug_code || !instr->skip_check()) {
1884 result = AssignEnvironment(result);
1890 LInstruction* LChunkBuilder::DoBoundsCheckBaseIndexInformation(
1891 HBoundsCheckBaseIndexInformation* instr) {
1897 LInstruction* LChunkBuilder::DoAbnormalExit(HAbnormalExit* instr) {
1898 // The control instruction marking the end of a block that completed
1899 // abruptly (e.g., threw an exception). There is nothing specific to do.
1904 LInstruction* LChunkBuilder::DoUseConst(HUseConst* instr) {
1909 LInstruction* LChunkBuilder::DoForceRepresentation(HForceRepresentation* bad) {
1910 // All HForceRepresentation instructions should be eliminated in the
1911 // representation change phase of Hydrogen.
1917 LInstruction* LChunkBuilder::DoChange(HChange* instr) {
1918 Representation from = instr->from();
1919 Representation to = instr->to();
1920 HValue* val = instr->value();
1922 if (to.IsTagged()) {
1923 LOperand* value = UseRegister(val);
1924 return DefineSameAsFirst(new(zone()) LDummyUse(value));
1926 from = Representation::Tagged();
1928 if (from.IsTagged()) {
1929 if (to.IsDouble()) {
1930 LOperand* value = UseRegister(val);
1931 LOperand* temp = TempRegister();
1932 LInstruction* result =
1933 DefineAsRegister(new(zone()) LNumberUntagD(value, temp));
1934 if (!val->representation().IsSmi()) result = AssignEnvironment(result);
1936 } else if (to.IsSIMD128()) {
1937 LOperand* value = UseRegister(instr->value());
1938 LOperand* temp = TempRegister();
1939 LTaggedToSIMD128* res = new(zone()) LTaggedToSIMD128(value, temp, to);
1940 return AssignEnvironment(DefineAsRegister(res));
1941 } else if (to.IsSmi()) {
1942 LOperand* value = UseRegister(val);
1943 if (val->type().IsSmi()) {
1944 return DefineSameAsFirst(new(zone()) LDummyUse(value));
1946 return AssignEnvironment(DefineSameAsFirst(new(zone()) LCheckSmi(value)));
1948 DCHECK(to.IsInteger32());
1949 if (val->type().IsSmi() || val->representation().IsSmi()) {
1950 LOperand* value = UseRegister(val);
1951 return DefineSameAsFirst(new(zone()) LSmiUntag(value, false));
1953 LOperand* value = UseRegister(val);
1954 bool truncating = instr->CanTruncateToInt32();
1955 LOperand* xmm_temp = !truncating ? FixedTemp(xmm1) : NULL;
1956 LInstruction* result =
1957 DefineSameAsFirst(new(zone()) LTaggedToI(value, xmm_temp));
1958 if (!val->representation().IsSmi()) result = AssignEnvironment(result);
1962 } else if (from.IsDouble()) {
1963 if (to.IsTagged()) {
1964 info()->MarkAsDeferredCalling();
1965 LOperand* value = UseRegisterAtStart(val);
1966 LOperand* temp = FLAG_inline_new ? TempRegister() : NULL;
1967 LUnallocated* result_temp = TempRegister();
1968 LNumberTagD* result = new(zone()) LNumberTagD(value, temp);
1969 return AssignPointerMap(Define(result, result_temp));
1970 } else if (to.IsSmi()) {
1971 LOperand* value = UseRegister(val);
1972 return AssignEnvironment(
1973 DefineAsRegister(new(zone()) LDoubleToSmi(value)));
1975 DCHECK(to.IsInteger32());
1976 bool truncating = instr->CanTruncateToInt32();
1977 bool needs_temp = !truncating;
1978 LOperand* value = needs_temp ? UseTempRegister(val) : UseRegister(val);
1979 LOperand* temp = needs_temp ? TempRegister() : NULL;
1980 LInstruction* result =
1981 DefineAsRegister(new(zone()) LDoubleToI(value, temp));
1982 if (!truncating) result = AssignEnvironment(result);
1985 } else if (from.IsInteger32()) {
1986 info()->MarkAsDeferredCalling();
1987 if (to.IsTagged()) {
1988 LOperand* value = UseRegister(val);
1989 if (!instr->CheckFlag(HValue::kCanOverflow)) {
1990 return DefineSameAsFirst(new(zone()) LSmiTag(value));
1991 } else if (val->CheckFlag(HInstruction::kUint32)) {
1992 LOperand* temp = TempRegister();
1993 LNumberTagU* result = new(zone()) LNumberTagU(value, temp);
1994 return AssignPointerMap(DefineSameAsFirst(result));
1996 LOperand* temp = TempRegister();
1997 LNumberTagI* result = new(zone()) LNumberTagI(value, temp);
1998 return AssignPointerMap(DefineSameAsFirst(result));
2000 } else if (to.IsSmi()) {
2001 LOperand* value = UseRegister(val);
2002 LInstruction* result = DefineSameAsFirst(new(zone()) LSmiTag(value));
2003 if (instr->CheckFlag(HValue::kCanOverflow)) {
2004 result = AssignEnvironment(result);
2008 DCHECK(to.IsDouble());
2009 if (val->CheckFlag(HInstruction::kUint32)) {
2010 return DefineAsRegister(new(zone()) LUint32ToDouble(UseRegister(val)));
2012 return DefineAsRegister(new(zone()) LInteger32ToDouble(Use(val)));
2015 } else if (from.IsSIMD128()) {
2016 DCHECK(to.IsTagged());
2017 info()->MarkAsDeferredCalling();
2018 LOperand* value = UseRegister(instr->value());
2019 LOperand* temp = TempRegister();
2020 LOperand* temp2 = TempRegister();
2022 // Make sure that temp and result_temp are different registers.
2023 LUnallocated* result_temp = TempRegister();
2024 LSIMD128ToTagged* result = new(zone()) LSIMD128ToTagged(value, temp, temp2);
2025 return AssignPointerMap(Define(result, result_temp));
2032 LInstruction* LChunkBuilder::DoCheckHeapObject(HCheckHeapObject* instr) {
2033 LOperand* value = UseAtStart(instr->value());
2034 LInstruction* result = new(zone()) LCheckNonSmi(value);
2035 if (!instr->value()->type().IsHeapObject()) {
2036 result = AssignEnvironment(result);
2042 LInstruction* LChunkBuilder::DoCheckSmi(HCheckSmi* instr) {
2043 LOperand* value = UseRegisterAtStart(instr->value());
2044 return AssignEnvironment(new(zone()) LCheckSmi(value));
2048 LInstruction* LChunkBuilder::DoCheckInstanceType(HCheckInstanceType* instr) {
2049 LOperand* value = UseRegisterAtStart(instr->value());
2050 LOperand* temp = TempRegister();
2051 LCheckInstanceType* result = new(zone()) LCheckInstanceType(value, temp);
2052 return AssignEnvironment(result);
2056 LInstruction* LChunkBuilder::DoCheckValue(HCheckValue* instr) {
2057 // If the object is in new space, we'll emit a global cell compare and so
2058 // want the value in a register. If the object gets promoted before we
2059 // emit code, we will still get the register but will do an immediate
2060 // compare instead of the cell compare. This is safe.
2061 LOperand* value = instr->object_in_new_space()
2062 ? UseRegisterAtStart(instr->value()) : UseAtStart(instr->value());
2063 return AssignEnvironment(new(zone()) LCheckValue(value));
2067 LInstruction* LChunkBuilder::DoCheckMaps(HCheckMaps* instr) {
2068 if (instr->IsStabilityCheck()) return new(zone()) LCheckMaps;
2069 LOperand* value = UseRegisterAtStart(instr->value());
2070 LInstruction* result = AssignEnvironment(new(zone()) LCheckMaps(value));
2071 if (instr->HasMigrationTarget()) {
2072 info()->MarkAsDeferredCalling();
2073 result = AssignPointerMap(result);
2079 LInstruction* LChunkBuilder::DoClampToUint8(HClampToUint8* instr) {
2080 HValue* value = instr->value();
2081 Representation input_rep = value->representation();
2082 if (input_rep.IsDouble()) {
2083 LOperand* reg = UseRegister(value);
2084 return DefineFixed(new(zone()) LClampDToUint8(reg), eax);
2085 } else if (input_rep.IsInteger32()) {
2086 LOperand* reg = UseFixed(value, eax);
2087 return DefineFixed(new(zone()) LClampIToUint8(reg), eax);
2089 DCHECK(input_rep.IsSmiOrTagged());
2090 LOperand* reg = UseFixed(value, eax);
2091 // Register allocator doesn't (yet) support allocation of double
2092 // temps. Reserve xmm1 explicitly.
2093 LOperand* temp = FixedTemp(xmm1);
2094 LClampTToUint8* result = new(zone()) LClampTToUint8(reg, temp);
2095 return AssignEnvironment(DefineFixed(result, eax));
2100 LInstruction* LChunkBuilder::DoDoubleBits(HDoubleBits* instr) {
2101 HValue* value = instr->value();
2102 DCHECK(value->representation().IsDouble());
2103 return DefineAsRegister(new(zone()) LDoubleBits(UseRegister(value)));
2107 LInstruction* LChunkBuilder::DoConstructDouble(HConstructDouble* instr) {
2108 LOperand* lo = UseRegister(instr->lo());
2109 LOperand* hi = UseRegister(instr->hi());
2110 return DefineAsRegister(new(zone()) LConstructDouble(hi, lo));
2114 LInstruction* LChunkBuilder::DoReturn(HReturn* instr) {
2115 LOperand* context = info()->IsStub() ? UseFixed(instr->context(), esi) : NULL;
2116 LOperand* parameter_count = UseRegisterOrConstant(instr->parameter_count());
2117 return new(zone()) LReturn(
2118 UseFixed(instr->value(), eax), context, parameter_count);
2122 LInstruction* LChunkBuilder::DoConstant(HConstant* instr) {
2123 Representation r = instr->representation();
2125 return DefineAsRegister(new(zone()) LConstantS);
2126 } else if (r.IsInteger32()) {
2127 return DefineAsRegister(new(zone()) LConstantI);
2128 } else if (r.IsDouble()) {
2129 double value = instr->DoubleValue();
2130 bool value_is_zero = bit_cast<uint64_t, double>(value) == 0;
2131 LOperand* temp = value_is_zero ? NULL : TempRegister();
2132 return DefineAsRegister(new(zone()) LConstantD(temp));
2133 } else if (r.IsExternal()) {
2134 return DefineAsRegister(new(zone()) LConstantE);
2135 } else if (r.IsTagged()) {
2136 return DefineAsRegister(new(zone()) LConstantT);
2144 LInstruction* LChunkBuilder::DoLoadGlobalCell(HLoadGlobalCell* instr) {
2145 LLoadGlobalCell* result = new(zone()) LLoadGlobalCell;
2146 return instr->RequiresHoleCheck()
2147 ? AssignEnvironment(DefineAsRegister(result))
2148 : DefineAsRegister(result);
2152 LInstruction* LChunkBuilder::DoLoadGlobalGeneric(HLoadGlobalGeneric* instr) {
2153 LOperand* context = UseFixed(instr->context(), esi);
2154 LOperand* global_object =
2155 UseFixed(instr->global_object(), LoadDescriptor::ReceiverRegister());
2156 LOperand* vector = NULL;
2157 if (FLAG_vector_ics) {
2158 vector = FixedTemp(VectorLoadICDescriptor::VectorRegister());
2161 LLoadGlobalGeneric* result =
2162 new(zone()) LLoadGlobalGeneric(context, global_object, vector);
2163 return MarkAsCall(DefineFixed(result, eax), instr);
2167 LInstruction* LChunkBuilder::DoStoreGlobalCell(HStoreGlobalCell* instr) {
2168 LStoreGlobalCell* result =
2169 new(zone()) LStoreGlobalCell(UseRegister(instr->value()));
2170 return instr->RequiresHoleCheck() ? AssignEnvironment(result) : result;
2174 LInstruction* LChunkBuilder::DoLoadContextSlot(HLoadContextSlot* instr) {
2175 LOperand* context = UseRegisterAtStart(instr->value());
2176 LInstruction* result =
2177 DefineAsRegister(new(zone()) LLoadContextSlot(context));
2178 if (instr->RequiresHoleCheck() && instr->DeoptimizesOnHole()) {
2179 result = AssignEnvironment(result);
2185 LInstruction* LChunkBuilder::DoStoreContextSlot(HStoreContextSlot* instr) {
2188 LOperand* context = UseRegister(instr->context());
2189 if (instr->NeedsWriteBarrier()) {
2190 value = UseTempRegister(instr->value());
2191 temp = TempRegister();
2193 value = UseRegister(instr->value());
2196 LInstruction* result = new(zone()) LStoreContextSlot(context, value, temp);
2197 if (instr->RequiresHoleCheck() && instr->DeoptimizesOnHole()) {
2198 result = AssignEnvironment(result);
2204 LInstruction* LChunkBuilder::DoLoadNamedField(HLoadNamedField* instr) {
2205 LOperand* obj = (instr->access().IsExternalMemory() &&
2206 instr->access().offset() == 0)
2207 ? UseRegisterOrConstantAtStart(instr->object())
2208 : UseRegisterAtStart(instr->object());
2209 return DefineAsRegister(new(zone()) LLoadNamedField(obj));
2213 LInstruction* LChunkBuilder::DoLoadNamedGeneric(HLoadNamedGeneric* instr) {
2214 LOperand* context = UseFixed(instr->context(), esi);
2216 UseFixed(instr->object(), LoadDescriptor::ReceiverRegister());
2217 LOperand* vector = NULL;
2218 if (FLAG_vector_ics) {
2219 vector = FixedTemp(VectorLoadICDescriptor::VectorRegister());
2221 LLoadNamedGeneric* result = new(zone()) LLoadNamedGeneric(
2222 context, object, vector);
2223 return MarkAsCall(DefineFixed(result, eax), instr);
2227 LInstruction* LChunkBuilder::DoLoadFunctionPrototype(
2228 HLoadFunctionPrototype* instr) {
2229 return AssignEnvironment(DefineAsRegister(
2230 new(zone()) LLoadFunctionPrototype(UseRegister(instr->function()),
2235 LInstruction* LChunkBuilder::DoLoadRoot(HLoadRoot* instr) {
2236 return DefineAsRegister(new(zone()) LLoadRoot);
2240 LInstruction* LChunkBuilder::DoLoadKeyed(HLoadKeyed* instr) {
2241 DCHECK(instr->key()->representation().IsSmiOrInteger32());
2242 ElementsKind elements_kind = instr->elements_kind();
2243 bool clobbers_key = ExternalArrayOpRequiresTemp(
2244 instr->key()->representation(), elements_kind);
2245 LOperand* key = clobbers_key
2246 ? UseTempRegister(instr->key())
2247 : UseRegisterOrConstantAtStart(instr->key());
2248 LInstruction* result = NULL;
2250 if (!instr->is_typed_elements()) {
2251 LOperand* obj = UseRegisterAtStart(instr->elements());
2252 result = DefineAsRegister(new(zone()) LLoadKeyed(obj, key));
2255 (instr->representation().IsInteger32() &&
2256 !(IsDoubleOrFloatElementsKind(instr->elements_kind()))) ||
2257 (instr->representation().IsDouble() &&
2258 (IsDoubleOrFloatElementsKind(instr->elements_kind()))) ||
2259 (CpuFeatures::SupportsSIMD128InCrankshaft()
2260 ? instr->representation().IsFloat32x4()
2261 : instr->representation().IsTagged() &&
2262 (IsFloat32x4ElementsKind(instr->elements_kind()))) ||
2263 (CpuFeatures::SupportsSIMD128InCrankshaft()
2264 ? instr->representation().IsFloat64x2()
2265 : instr->representation().IsTagged() &&
2266 (IsFloat64x2ElementsKind(instr->elements_kind()))) ||
2267 (CpuFeatures::SupportsSIMD128InCrankshaft()
2268 ? instr->representation().IsInt32x4()
2269 : instr->representation().IsTagged() &&
2270 (IsInt32x4ElementsKind(instr->elements_kind()))));
2271 LOperand* backing_store = UseRegister(instr->elements());
2272 result = DefineAsRegister(new(zone()) LLoadKeyed(backing_store, key));
2275 if ((instr->is_external() || instr->is_fixed_typed_array()) ?
2276 // see LCodeGen::DoLoadKeyedExternalArray
2277 ((instr->elements_kind() == EXTERNAL_UINT32_ELEMENTS ||
2278 instr->elements_kind() == UINT32_ELEMENTS) &&
2279 !instr->CheckFlag(HInstruction::kUint32)) :
2280 // see LCodeGen::DoLoadKeyedFixedDoubleArray and
2281 // LCodeGen::DoLoadKeyedFixedArray
2282 instr->RequiresHoleCheck()) {
2283 result = AssignEnvironment(result);
2289 LInstruction* LChunkBuilder::DoLoadKeyedGeneric(HLoadKeyedGeneric* instr) {
2290 LOperand* context = UseFixed(instr->context(), esi);
2292 UseFixed(instr->object(), LoadDescriptor::ReceiverRegister());
2293 LOperand* key = UseFixed(instr->key(), LoadDescriptor::NameRegister());
2294 LOperand* vector = NULL;
2295 if (FLAG_vector_ics) {
2296 vector = FixedTemp(VectorLoadICDescriptor::VectorRegister());
2298 LLoadKeyedGeneric* result =
2299 new(zone()) LLoadKeyedGeneric(context, object, key, vector);
2300 return MarkAsCall(DefineFixed(result, eax), instr);
2304 LOperand* LChunkBuilder::GetStoreKeyedValueOperand(HStoreKeyed* instr) {
2305 ElementsKind elements_kind = instr->elements_kind();
2306 BuiltinFunctionId op = instr->op();
2308 // Determine if we need a byte register in this case for the value.
2309 bool val_is_fixed_register =
2310 (elements_kind == EXTERNAL_INT8_ELEMENTS ||
2311 elements_kind == EXTERNAL_UINT8_ELEMENTS ||
2312 elements_kind == EXTERNAL_UINT8_CLAMPED_ELEMENTS ||
2313 elements_kind == UINT8_ELEMENTS ||
2314 elements_kind == INT8_ELEMENTS ||
2315 elements_kind == UINT8_CLAMPED_ELEMENTS) &&
2316 (op != kInt8ArraySetFloat32x4XYZW &&
2317 op != kInt8ArraySetFloat32x4X &&
2318 op != kInt8ArraySetFloat32x4XY &&
2319 op != kInt8ArraySetFloat32x4XYZ &&
2320 op != kInt8ArraySetInt32x4XYZW &&
2321 op != kInt8ArraySetInt32x4X &&
2322 op != kInt8ArraySetInt32x4XY &&
2323 op != kInt8ArraySetInt32x4XYZ &&
2324 op != kInt8ArraySetFloat64x2XY &&
2325 op != kInt8ArraySetFloat64x2X);
2326 if (val_is_fixed_register) {
2327 return UseFixed(instr->value(), eax);
2330 return UseRegister(instr->value());
2334 LInstruction* LChunkBuilder::DoStoreKeyed(HStoreKeyed* instr) {
2335 if (!instr->is_typed_elements()) {
2336 DCHECK(instr->elements()->representation().IsTagged());
2337 DCHECK(instr->key()->representation().IsInteger32() ||
2338 instr->key()->representation().IsSmi());
2340 if (instr->value()->representation().IsDouble()) {
2341 LOperand* object = UseRegisterAtStart(instr->elements());
2342 LOperand* val = NULL;
2343 val = UseRegisterAtStart(instr->value());
2344 LOperand* key = UseRegisterOrConstantAtStart(instr->key());
2345 return new(zone()) LStoreKeyed(object, key, val);
2347 DCHECK(instr->value()->representation().IsSmiOrTagged());
2348 bool needs_write_barrier = instr->NeedsWriteBarrier();
2350 LOperand* obj = UseRegister(instr->elements());
2353 if (needs_write_barrier) {
2354 val = UseTempRegister(instr->value());
2355 key = UseTempRegister(instr->key());
2357 val = UseRegisterOrConstantAtStart(instr->value());
2358 key = UseRegisterOrConstantAtStart(instr->key());
2360 return new(zone()) LStoreKeyed(obj, key, val);
2364 ElementsKind elements_kind = instr->elements_kind();
2366 (instr->value()->representation().IsInteger32() &&
2367 !IsDoubleOrFloatElementsKind(elements_kind)) ||
2368 (instr->value()->representation().IsDouble() &&
2369 IsDoubleOrFloatElementsKind(elements_kind)) ||
2370 (CpuFeatures::SupportsSIMD128InCrankshaft()
2371 ? instr->value()->representation().IsFloat32x4()
2372 : instr->value()->representation().IsTagged() &&
2373 IsFloat32x4ElementsKind(elements_kind)) ||
2374 (CpuFeatures::SupportsSIMD128InCrankshaft()
2375 ? instr->value()->representation().IsFloat64x2()
2376 : instr->value()->representation().IsTagged() &&
2377 IsFloat64x2ElementsKind(elements_kind)) ||
2378 (CpuFeatures::SupportsSIMD128InCrankshaft()
2379 ? instr->value()->representation().IsInt32x4()
2380 : instr->value()->representation().IsTagged() &&
2381 IsInt32x4ElementsKind(elements_kind)));
2382 DCHECK((instr->is_fixed_typed_array() &&
2383 instr->elements()->representation().IsTagged()) ||
2384 (instr->is_external() &&
2385 instr->elements()->representation().IsExternal()));
2387 LOperand* backing_store = UseRegister(instr->elements());
2388 LOperand* val = GetStoreKeyedValueOperand(instr);
2389 bool clobbers_key = ExternalArrayOpRequiresTemp(
2390 instr->key()->representation(), elements_kind);
2391 LOperand* key = clobbers_key
2392 ? UseTempRegister(instr->key())
2393 : UseRegisterOrConstantAtStart(instr->key());
2394 return new(zone()) LStoreKeyed(backing_store, key, val);
2398 LInstruction* LChunkBuilder::DoStoreKeyedGeneric(HStoreKeyedGeneric* instr) {
2399 LOperand* context = UseFixed(instr->context(), esi);
2401 UseFixed(instr->object(), StoreDescriptor::ReceiverRegister());
2402 LOperand* key = UseFixed(instr->key(), StoreDescriptor::NameRegister());
2403 LOperand* value = UseFixed(instr->value(), StoreDescriptor::ValueRegister());
2405 DCHECK(instr->object()->representation().IsTagged());
2406 DCHECK(instr->key()->representation().IsTagged());
2407 DCHECK(instr->value()->representation().IsTagged());
2409 LStoreKeyedGeneric* result =
2410 new(zone()) LStoreKeyedGeneric(context, object, key, value);
2411 return MarkAsCall(result, instr);
2415 LInstruction* LChunkBuilder::DoTransitionElementsKind(
2416 HTransitionElementsKind* instr) {
2417 if (IsSimpleMapChangeTransition(instr->from_kind(), instr->to_kind())) {
2418 LOperand* object = UseRegister(instr->object());
2419 LOperand* new_map_reg = TempRegister();
2420 LOperand* temp_reg = TempRegister();
2421 LTransitionElementsKind* result =
2422 new(zone()) LTransitionElementsKind(object, NULL,
2423 new_map_reg, temp_reg);
2426 LOperand* object = UseFixed(instr->object(), eax);
2427 LOperand* context = UseFixed(instr->context(), esi);
2428 LTransitionElementsKind* result =
2429 new(zone()) LTransitionElementsKind(object, context, NULL, NULL);
2430 return MarkAsCall(result, instr);
2435 LInstruction* LChunkBuilder::DoTrapAllocationMemento(
2436 HTrapAllocationMemento* instr) {
2437 LOperand* object = UseRegister(instr->object());
2438 LOperand* temp = TempRegister();
2439 LTrapAllocationMemento* result =
2440 new(zone()) LTrapAllocationMemento(object, temp);
2441 return AssignEnvironment(result);
2445 LInstruction* LChunkBuilder::DoStoreNamedField(HStoreNamedField* instr) {
2446 bool is_in_object = instr->access().IsInobject();
2447 bool is_external_location = instr->access().IsExternalMemory() &&
2448 instr->access().offset() == 0;
2449 bool needs_write_barrier = instr->NeedsWriteBarrier();
2450 bool needs_write_barrier_for_map = instr->has_transition() &&
2451 instr->NeedsWriteBarrierForMap();
2454 if (needs_write_barrier) {
2456 ? UseRegister(instr->object())
2457 : UseTempRegister(instr->object());
2458 } else if (is_external_location) {
2459 DCHECK(!is_in_object);
2460 DCHECK(!needs_write_barrier);
2461 DCHECK(!needs_write_barrier_for_map);
2462 obj = UseRegisterOrConstant(instr->object());
2464 obj = needs_write_barrier_for_map
2465 ? UseRegister(instr->object())
2466 : UseRegisterAtStart(instr->object());
2469 bool can_be_constant = instr->value()->IsConstant() &&
2470 HConstant::cast(instr->value())->NotInNewSpace() &&
2471 !instr->field_representation().IsDouble();
2474 if (instr->field_representation().IsInteger8() ||
2475 instr->field_representation().IsUInteger8()) {
2476 // mov_b requires a byte register (i.e. any of eax, ebx, ecx, edx).
2477 // Just force the value to be in eax and we're safe here.
2478 val = UseFixed(instr->value(), eax);
2479 } else if (needs_write_barrier) {
2480 val = UseTempRegister(instr->value());
2481 } else if (can_be_constant) {
2482 val = UseRegisterOrConstant(instr->value());
2483 } else if (instr->field_representation().IsDouble()) {
2484 val = UseRegisterAtStart(instr->value());
2486 val = UseRegister(instr->value());
2489 // We only need a scratch register if we have a write barrier or we
2490 // have a store into the properties array (not in-object-property).
2491 LOperand* temp = (!is_in_object || needs_write_barrier ||
2492 needs_write_barrier_for_map) ? TempRegister() : NULL;
2494 // We need a temporary register for write barrier of the map field.
2495 LOperand* temp_map = needs_write_barrier_for_map ? TempRegister() : NULL;
2497 return new(zone()) LStoreNamedField(obj, val, temp, temp_map);
2501 LInstruction* LChunkBuilder::DoStoreNamedGeneric(HStoreNamedGeneric* instr) {
2502 LOperand* context = UseFixed(instr->context(), esi);
2504 UseFixed(instr->object(), StoreDescriptor::ReceiverRegister());
2505 LOperand* value = UseFixed(instr->value(), StoreDescriptor::ValueRegister());
2507 LStoreNamedGeneric* result =
2508 new(zone()) LStoreNamedGeneric(context, object, value);
2509 return MarkAsCall(result, instr);
2513 LInstruction* LChunkBuilder::DoStringAdd(HStringAdd* instr) {
2514 LOperand* context = UseFixed(instr->context(), esi);
2515 LOperand* left = UseFixed(instr->left(), edx);
2516 LOperand* right = UseFixed(instr->right(), eax);
2517 LStringAdd* string_add = new(zone()) LStringAdd(context, left, right);
2518 return MarkAsCall(DefineFixed(string_add, eax), instr);
2522 LInstruction* LChunkBuilder::DoStringCharCodeAt(HStringCharCodeAt* instr) {
2523 LOperand* string = UseTempRegister(instr->string());
2524 LOperand* index = UseTempRegister(instr->index());
2525 LOperand* context = UseAny(instr->context());
2526 LStringCharCodeAt* result =
2527 new(zone()) LStringCharCodeAt(context, string, index);
2528 return AssignPointerMap(DefineAsRegister(result));
2532 LInstruction* LChunkBuilder::DoStringCharFromCode(HStringCharFromCode* instr) {
2533 LOperand* char_code = UseRegister(instr->value());
2534 LOperand* context = UseAny(instr->context());
2535 LStringCharFromCode* result =
2536 new(zone()) LStringCharFromCode(context, char_code);
2537 return AssignPointerMap(DefineAsRegister(result));
2541 LInstruction* LChunkBuilder::DoAllocate(HAllocate* instr) {
2542 info()->MarkAsDeferredCalling();
2543 LOperand* context = UseAny(instr->context());
2544 LOperand* size = instr->size()->IsConstant()
2545 ? UseConstant(instr->size())
2546 : UseTempRegister(instr->size());
2547 LOperand* temp = TempRegister();
2548 LAllocate* result = new(zone()) LAllocate(context, size, temp);
2549 return AssignPointerMap(DefineAsRegister(result));
2553 LInstruction* LChunkBuilder::DoRegExpLiteral(HRegExpLiteral* instr) {
2554 LOperand* context = UseFixed(instr->context(), esi);
2556 DefineFixed(new(zone()) LRegExpLiteral(context), eax), instr);
2560 LInstruction* LChunkBuilder::DoFunctionLiteral(HFunctionLiteral* instr) {
2561 LOperand* context = UseFixed(instr->context(), esi);
2563 DefineFixed(new(zone()) LFunctionLiteral(context), eax), instr);
2567 LInstruction* LChunkBuilder::DoOsrEntry(HOsrEntry* instr) {
2568 DCHECK(argument_count_ == 0);
2569 allocator_->MarkAsOsrEntry();
2570 current_block_->last_environment()->set_ast_id(instr->ast_id());
2571 return AssignEnvironment(new(zone()) LOsrEntry);
2575 LInstruction* LChunkBuilder::DoParameter(HParameter* instr) {
2576 LParameter* result = new(zone()) LParameter;
2577 if (instr->kind() == HParameter::STACK_PARAMETER) {
2578 int spill_index = chunk()->GetParameterStackSlot(instr->index());
2579 return DefineAsSpilled(result, spill_index);
2581 DCHECK(info()->IsStub());
2582 CallInterfaceDescriptor descriptor =
2583 info()->code_stub()->GetCallInterfaceDescriptor();
2584 int index = static_cast<int>(instr->index());
2585 Register reg = descriptor.GetEnvironmentParameterRegister(index);
2586 return DefineFixed(result, reg);
2591 LInstruction* LChunkBuilder::DoUnknownOSRValue(HUnknownOSRValue* instr) {
2592 // Use an index that corresponds to the location in the unoptimized frame,
2593 // which the optimized frame will subsume.
2594 int env_index = instr->index();
2595 int spill_index = 0;
2596 if (instr->environment()->is_parameter_index(env_index)) {
2597 spill_index = chunk()->GetParameterStackSlot(env_index);
2599 spill_index = env_index - instr->environment()->first_local_index();
2600 if (spill_index > LUnallocated::kMaxFixedSlotIndex) {
2601 Retry(kNotEnoughSpillSlotsForOsr);
2604 if (spill_index == 0) {
2605 // The dynamic frame alignment state overwrites the first local.
2606 // The first local is saved at the end of the unoptimized frame.
2607 spill_index = graph()->osr()->UnoptimizedFrameSlots();
2610 return DefineAsSpilled(new(zone()) LUnknownOSRValue, spill_index);
2614 LInstruction* LChunkBuilder::DoCallStub(HCallStub* instr) {
2615 LOperand* context = UseFixed(instr->context(), esi);
2616 LCallStub* result = new(zone()) LCallStub(context);
2617 return MarkAsCall(DefineFixed(result, eax), instr);
2621 LInstruction* LChunkBuilder::DoArgumentsObject(HArgumentsObject* instr) {
2622 // There are no real uses of the arguments object.
2623 // arguments.length and element access are supported directly on
2624 // stack arguments, and any real arguments object use causes a bailout.
2625 // So this value is never used.
2630 LInstruction* LChunkBuilder::DoCapturedObject(HCapturedObject* instr) {
2631 instr->ReplayEnvironment(current_block_->last_environment());
2633 // There are no real uses of a captured object.
2638 LInstruction* LChunkBuilder::DoAccessArgumentsAt(HAccessArgumentsAt* instr) {
2639 info()->MarkAsRequiresFrame();
2640 LOperand* args = UseRegister(instr->arguments());
2643 if (instr->length()->IsConstant() && instr->index()->IsConstant()) {
2644 length = UseRegisterOrConstant(instr->length());
2645 index = UseOrConstant(instr->index());
2647 length = UseTempRegister(instr->length());
2648 index = Use(instr->index());
2650 return DefineAsRegister(new(zone()) LAccessArgumentsAt(args, length, index));
2654 LInstruction* LChunkBuilder::DoToFastProperties(HToFastProperties* instr) {
2655 LOperand* object = UseFixed(instr->value(), eax);
2656 LToFastProperties* result = new(zone()) LToFastProperties(object);
2657 return MarkAsCall(DefineFixed(result, eax), instr);
2661 LInstruction* LChunkBuilder::DoTypeof(HTypeof* instr) {
2662 LOperand* context = UseFixed(instr->context(), esi);
2663 LOperand* value = UseAtStart(instr->value());
2664 LTypeof* result = new(zone()) LTypeof(context, value);
2665 return MarkAsCall(DefineFixed(result, eax), instr);
2669 LInstruction* LChunkBuilder::DoTypeofIsAndBranch(HTypeofIsAndBranch* instr) {
2670 return new(zone()) LTypeofIsAndBranch(UseTempRegister(instr->value()));
2674 LInstruction* LChunkBuilder::DoIsConstructCallAndBranch(
2675 HIsConstructCallAndBranch* instr) {
2676 return new(zone()) LIsConstructCallAndBranch(TempRegister());
2680 LInstruction* LChunkBuilder::DoSimulate(HSimulate* instr) {
2681 instr->ReplayEnvironment(current_block_->last_environment());
2686 LInstruction* LChunkBuilder::DoStackCheck(HStackCheck* instr) {
2687 info()->MarkAsDeferredCalling();
2688 if (instr->is_function_entry()) {
2689 LOperand* context = UseFixed(instr->context(), esi);
2690 return MarkAsCall(new(zone()) LStackCheck(context), instr);
2692 DCHECK(instr->is_backwards_branch());
2693 LOperand* context = UseAny(instr->context());
2694 return AssignEnvironment(
2695 AssignPointerMap(new(zone()) LStackCheck(context)));
2700 LInstruction* LChunkBuilder::DoEnterInlined(HEnterInlined* instr) {
2701 HEnvironment* outer = current_block_->last_environment();
2702 outer->set_ast_id(instr->ReturnId());
2703 HConstant* undefined = graph()->GetConstantUndefined();
2704 HEnvironment* inner = outer->CopyForInlining(instr->closure(),
2705 instr->arguments_count(),
2708 instr->inlining_kind());
2709 // Only replay binding of arguments object if it wasn't removed from graph.
2710 if (instr->arguments_var() != NULL && instr->arguments_object()->IsLinked()) {
2711 inner->Bind(instr->arguments_var(), instr->arguments_object());
2713 inner->BindContext(instr->closure_context());
2714 inner->set_entry(instr);
2715 current_block_->UpdateEnvironment(inner);
2716 chunk_->AddInlinedClosure(instr->closure());
2721 LInstruction* LChunkBuilder::DoLeaveInlined(HLeaveInlined* instr) {
2722 LInstruction* pop = NULL;
2724 HEnvironment* env = current_block_->last_environment();
2726 if (env->entry()->arguments_pushed()) {
2727 int argument_count = env->arguments_environment()->parameter_count();
2728 pop = new(zone()) LDrop(argument_count);
2729 DCHECK(instr->argument_delta() == -argument_count);
2732 HEnvironment* outer = current_block_->last_environment()->
2733 DiscardInlined(false);
2734 current_block_->UpdateEnvironment(outer);
2739 LInstruction* LChunkBuilder::DoForInPrepareMap(HForInPrepareMap* instr) {
2740 LOperand* context = UseFixed(instr->context(), esi);
2741 LOperand* object = UseFixed(instr->enumerable(), eax);
2742 LForInPrepareMap* result = new(zone()) LForInPrepareMap(context, object);
2743 return MarkAsCall(DefineFixed(result, eax), instr, CAN_DEOPTIMIZE_EAGERLY);
2747 LInstruction* LChunkBuilder::DoForInCacheArray(HForInCacheArray* instr) {
2748 LOperand* map = UseRegister(instr->map());
2749 return AssignEnvironment(DefineAsRegister(
2750 new(zone()) LForInCacheArray(map)));
2754 LInstruction* LChunkBuilder::DoCheckMapValue(HCheckMapValue* instr) {
2755 LOperand* value = UseRegisterAtStart(instr->value());
2756 LOperand* map = UseRegisterAtStart(instr->map());
2757 return AssignEnvironment(new(zone()) LCheckMapValue(value, map));
2761 LInstruction* LChunkBuilder::DoLoadFieldByIndex(HLoadFieldByIndex* instr) {
2762 LOperand* object = UseRegister(instr->object());
2763 LOperand* index = UseTempRegister(instr->index());
2764 LLoadFieldByIndex* load = new(zone()) LLoadFieldByIndex(object, index);
2765 LInstruction* result = DefineSameAsFirst(load);
2766 return AssignPointerMap(result);
2770 LInstruction* LChunkBuilder::DoStoreFrameContext(HStoreFrameContext* instr) {
2771 LOperand* context = UseRegisterAtStart(instr->context());
2772 return new(zone()) LStoreFrameContext(context);
2776 LInstruction* LChunkBuilder::DoAllocateBlockContext(
2777 HAllocateBlockContext* instr) {
2778 LOperand* context = UseFixed(instr->context(), esi);
2779 LOperand* function = UseRegisterAtStart(instr->function());
2780 LAllocateBlockContext* result =
2781 new(zone()) LAllocateBlockContext(context, function);
2782 return MarkAsCall(DefineFixed(result, esi), instr);
2786 const char* LNullarySIMDOperation::Mnemonic() const {
2788 #define SIMD_NULLARY_OPERATION_CASE_ITEM(module, function, name, p4) \
2790 return #module "-" #function;
2791 SIMD_NULLARY_OPERATIONS(SIMD_NULLARY_OPERATION_CASE_ITEM)
2792 #undef SIMD_NULLARY_OPERATION_CASE_ITEM
2800 LInstruction* LChunkBuilder::DoNullarySIMDOperation(
2801 HNullarySIMDOperation* instr) {
2802 LNullarySIMDOperation* result =
2803 new(zone()) LNullarySIMDOperation(instr->op());
2804 switch (instr->op()) {
2805 #define SIMD_NULLARY_OPERATION_CASE_ITEM(module, function, name, p4) \
2807 SIMD_NULLARY_OPERATIONS(SIMD_NULLARY_OPERATION_CASE_ITEM)
2808 #undef SIMD_NULLARY_OPERATION_CASE_ITEM
2809 return DefineAsRegister(result);
2817 const char* LUnarySIMDOperation::Mnemonic() const {
2819 case kSIMD128Change: return "SIMD128-change";
2820 #define SIMD_UNARY_OPERATION_CASE_ITEM(module, function, name, p4, p5) \
2822 return #module "-" #function;
2823 SIMD_UNARY_OPERATIONS(SIMD_UNARY_OPERATION_CASE_ITEM)
2824 SIMD_UNARY_OPERATIONS_FOR_PROPERTY_ACCESS(SIMD_UNARY_OPERATION_CASE_ITEM)
2825 #undef SIMD_UNARY_OPERATION_CASE_ITEM
2833 LInstruction* LChunkBuilder::DoUnarySIMDOperation(HUnarySIMDOperation* instr) {
2834 LOperand* input = UseRegisterAtStart(instr->value());
2835 LUnarySIMDOperation* result =
2836 new(zone()) LUnarySIMDOperation(input, instr->op());
2837 switch (instr->op()) {
2838 case kSIMD128Change:
2839 return AssignEnvironment(DefineAsRegister(result));
2842 case kFloat32x4Reciprocal:
2843 case kFloat32x4ReciprocalSqrt:
2844 case kFloat32x4Sqrt:
2847 case kFloat64x2Sqrt:
2850 return DefineSameAsFirst(result);
2851 case kFloat32x4Coercion:
2852 case kFloat64x2Coercion:
2853 case kInt32x4Coercion:
2854 case kFloat32x4BitsToInt32x4:
2855 case kFloat32x4ToInt32x4:
2856 case kInt32x4BitsToFloat32x4:
2857 case kInt32x4ToFloat32x4:
2858 case kFloat32x4Splat:
2860 case kFloat32x4GetSignMask:
2861 case kFloat32x4GetX:
2862 case kFloat32x4GetY:
2863 case kFloat32x4GetZ:
2864 case kFloat32x4GetW:
2865 case kFloat64x2GetSignMask:
2866 case kFloat64x2GetX:
2867 case kFloat64x2GetY:
2868 case kInt32x4GetSignMask:
2873 case kInt32x4GetFlagX:
2874 case kInt32x4GetFlagY:
2875 case kInt32x4GetFlagZ:
2876 case kInt32x4GetFlagW:
2877 return DefineAsRegister(result);
2885 const char* LBinarySIMDOperation::Mnemonic() const {
2887 #define SIMD_BINARY_OPERATION_CASE_ITEM(module, function, name, p4, p5, p6) \
2889 return #module "-" #function;
2890 SIMD_BINARY_OPERATIONS(SIMD_BINARY_OPERATION_CASE_ITEM)
2891 #undef SIMD_BINARY_OPERATION_CASE_ITEM
2899 LInstruction* LChunkBuilder::DoBinarySIMDOperation(
2900 HBinarySIMDOperation* instr) {
2901 switch (instr->op()) {
2908 case kFloat32x4Scale:
2909 case kFloat32x4WithX:
2910 case kFloat32x4WithY:
2911 case kFloat32x4WithZ:
2912 case kFloat32x4WithW:
2919 case kFloat64x2Scale:
2920 case kFloat64x2WithX:
2921 case kFloat64x2WithY:
2932 case kInt32x4WithFlagX:
2933 case kInt32x4WithFlagY:
2934 case kInt32x4WithFlagZ:
2935 case kInt32x4WithFlagW:
2936 case kInt32x4GreaterThan:
2938 case kInt32x4LessThan: {
2939 LOperand* left = UseRegisterAtStart(instr->left());
2940 LOperand* right = UseRegisterAtStart(instr->right());
2941 LBinarySIMDOperation* result =
2942 new(zone()) LBinarySIMDOperation(left, right, instr->op());
2943 if (instr->op() == kInt32x4WithFlagX ||
2944 instr->op() == kInt32x4WithFlagY ||
2945 instr->op() == kInt32x4WithFlagZ ||
2946 instr->op() == kInt32x4WithFlagW) {
2947 return AssignEnvironment(DefineSameAsFirst(result));
2949 return DefineSameAsFirst(result);
2952 case kFloat64x2Constructor: {
2953 LOperand* left = UseRegisterAtStart(instr->left());
2954 LOperand* right = UseRegisterAtStart(instr->right());
2955 LBinarySIMDOperation* result =
2956 new(zone()) LBinarySIMDOperation(left, right, instr->op());
2957 return DefineAsRegister(result);
2959 case kFloat32x4Shuffle:
2960 case kInt32x4Shuffle:
2961 case kInt32x4ShiftLeft:
2962 case kInt32x4ShiftRight:
2963 case kInt32x4ShiftRightArithmetic: {
2964 LOperand* left = UseRegisterAtStart(instr->left());
2965 LOperand* right = UseOrConstant(instr->right());
2966 LBinarySIMDOperation* result =
2967 new(zone()) LBinarySIMDOperation(left, right, instr->op());
2968 return AssignEnvironment(DefineSameAsFirst(result));
2970 case kFloat32x4LessThan:
2971 case kFloat32x4LessThanOrEqual:
2972 case kFloat32x4Equal:
2973 case kFloat32x4NotEqual:
2974 case kFloat32x4GreaterThanOrEqual:
2975 case kFloat32x4GreaterThan: {
2976 LOperand* left = UseRegisterAtStart(instr->left());
2977 LOperand* right = UseRegisterAtStart(instr->right());
2978 LBinarySIMDOperation* result =
2979 new(zone()) LBinarySIMDOperation(left, right, instr->op());
2980 return DefineAsRegister(result);
2989 const char* LTernarySIMDOperation::Mnemonic() const {
2991 #define SIMD_TERNARY_OPERATION_CASE_ITEM(module, function, name, p4, p5, p6, \
2994 return #module "-" #function;
2995 SIMD_TERNARY_OPERATIONS(SIMD_TERNARY_OPERATION_CASE_ITEM)
2996 #undef SIMD_TERNARY_OPERATION_CASE_ITEM
3004 LInstruction* LChunkBuilder::DoTernarySIMDOperation(
3005 HTernarySIMDOperation* instr) {
3006 LOperand* first = UseRegisterAtStart(instr->first());
3007 LOperand* second = UseRegisterAtStart(instr->second());
3008 LOperand* third = instr->op() == kFloat32x4ShuffleMix
3009 ? UseOrConstant(instr->third())
3010 : UseRegisterAtStart(instr->third());
3011 LTernarySIMDOperation* result =
3012 new(zone()) LTernarySIMDOperation(first, second, third, instr->op());
3013 switch (instr->op()) {
3014 case kInt32x4Select:
3015 case kFloat32x4Select: {
3016 return DefineAsRegister(result);
3018 case kFloat32x4ShuffleMix: {
3019 return AssignEnvironment(DefineSameAsFirst(result));
3021 case kFloat32x4Clamp:
3022 case kFloat64x2Clamp: {
3023 return DefineSameAsFirst(result);
3032 const char* LQuarternarySIMDOperation::Mnemonic() const {
3034 #define SIMD_QUARTERNARY_OPERATION_CASE_ITEM(module, function, name, p4, p5, \
3037 return #module "-" #function;
3038 SIMD_QUARTERNARY_OPERATIONS(SIMD_QUARTERNARY_OPERATION_CASE_ITEM)
3039 #undef SIMD_QUARTERNARY_OPERATION_CASE_ITEM
3047 LInstruction* LChunkBuilder::DoQuarternarySIMDOperation(
3048 HQuarternarySIMDOperation* instr) {
3049 LOperand* x = UseRegisterAtStart(instr->x());
3050 LOperand* y = UseRegisterAtStart(instr->y());
3051 LOperand* z = UseRegisterAtStart(instr->z());
3052 LOperand* w = UseRegisterAtStart(instr->w());
3053 LQuarternarySIMDOperation* result =
3054 new(zone()) LQuarternarySIMDOperation(x, y, z, w, instr->op());
3055 if (instr->op() == kInt32x4Bool) {
3056 return AssignEnvironment(DefineAsRegister(result));
3058 return DefineAsRegister(result);
3063 } } // namespace v8::internal
3065 #endif // V8_TARGET_ARCH_IA32