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 LInstruction* result = new(zone()) LBoundsCheck(index, length);
1881 if (!FLAG_debug_code || !instr->skip_check()) {
1882 result = AssignEnvironment(result);
1888 LInstruction* LChunkBuilder::DoBoundsCheckBaseIndexInformation(
1889 HBoundsCheckBaseIndexInformation* instr) {
1895 LInstruction* LChunkBuilder::DoAbnormalExit(HAbnormalExit* instr) {
1896 // The control instruction marking the end of a block that completed
1897 // abruptly (e.g., threw an exception). There is nothing specific to do.
1902 LInstruction* LChunkBuilder::DoUseConst(HUseConst* instr) {
1907 LInstruction* LChunkBuilder::DoForceRepresentation(HForceRepresentation* bad) {
1908 // All HForceRepresentation instructions should be eliminated in the
1909 // representation change phase of Hydrogen.
1915 LInstruction* LChunkBuilder::DoChange(HChange* instr) {
1916 Representation from = instr->from();
1917 Representation to = instr->to();
1918 HValue* val = instr->value();
1920 if (to.IsTagged()) {
1921 LOperand* value = UseRegister(val);
1922 return DefineSameAsFirst(new(zone()) LDummyUse(value));
1924 from = Representation::Tagged();
1926 if (from.IsTagged()) {
1927 if (to.IsDouble()) {
1928 LOperand* value = UseRegister(val);
1929 LOperand* temp = TempRegister();
1930 LInstruction* result =
1931 DefineAsRegister(new(zone()) LNumberUntagD(value, temp));
1932 if (!val->representation().IsSmi()) result = AssignEnvironment(result);
1934 } else if (to.IsSIMD128()) {
1935 LOperand* value = UseRegister(instr->value());
1936 LOperand* temp = TempRegister();
1937 LTaggedToSIMD128* res = new(zone()) LTaggedToSIMD128(value, temp, to);
1938 return AssignEnvironment(DefineAsRegister(res));
1939 } else if (to.IsSmi()) {
1940 LOperand* value = UseRegister(val);
1941 if (val->type().IsSmi()) {
1942 return DefineSameAsFirst(new(zone()) LDummyUse(value));
1944 return AssignEnvironment(DefineSameAsFirst(new(zone()) LCheckSmi(value)));
1946 DCHECK(to.IsInteger32());
1947 if (val->type().IsSmi() || val->representation().IsSmi()) {
1948 LOperand* value = UseRegister(val);
1949 return DefineSameAsFirst(new(zone()) LSmiUntag(value, false));
1951 LOperand* value = UseRegister(val);
1952 bool truncating = instr->CanTruncateToInt32();
1953 LOperand* xmm_temp = !truncating ? FixedTemp(xmm1) : NULL;
1954 LInstruction* result =
1955 DefineSameAsFirst(new(zone()) LTaggedToI(value, xmm_temp));
1956 if (!val->representation().IsSmi()) result = AssignEnvironment(result);
1960 } else if (from.IsDouble()) {
1961 if (to.IsTagged()) {
1962 info()->MarkAsDeferredCalling();
1963 LOperand* value = UseRegisterAtStart(val);
1964 LOperand* temp = FLAG_inline_new ? TempRegister() : NULL;
1965 LUnallocated* result_temp = TempRegister();
1966 LNumberTagD* result = new(zone()) LNumberTagD(value, temp);
1967 return AssignPointerMap(Define(result, result_temp));
1968 } else if (to.IsSmi()) {
1969 LOperand* value = UseRegister(val);
1970 return AssignEnvironment(
1971 DefineAsRegister(new(zone()) LDoubleToSmi(value)));
1973 DCHECK(to.IsInteger32());
1974 bool truncating = instr->CanTruncateToInt32();
1975 bool needs_temp = !truncating;
1976 LOperand* value = needs_temp ? UseTempRegister(val) : UseRegister(val);
1977 LOperand* temp = needs_temp ? TempRegister() : NULL;
1978 LInstruction* result =
1979 DefineAsRegister(new(zone()) LDoubleToI(value, temp));
1980 if (!truncating) result = AssignEnvironment(result);
1983 } else if (from.IsInteger32()) {
1984 info()->MarkAsDeferredCalling();
1985 if (to.IsTagged()) {
1986 LOperand* value = UseRegister(val);
1987 if (!instr->CheckFlag(HValue::kCanOverflow)) {
1988 return DefineSameAsFirst(new(zone()) LSmiTag(value));
1989 } else if (val->CheckFlag(HInstruction::kUint32)) {
1990 LOperand* temp = TempRegister();
1991 LNumberTagU* result = new(zone()) LNumberTagU(value, temp);
1992 return AssignPointerMap(DefineSameAsFirst(result));
1994 LOperand* temp = TempRegister();
1995 LNumberTagI* result = new(zone()) LNumberTagI(value, temp);
1996 return AssignPointerMap(DefineSameAsFirst(result));
1998 } else if (to.IsSmi()) {
1999 LOperand* value = UseRegister(val);
2000 LInstruction* result = DefineSameAsFirst(new(zone()) LSmiTag(value));
2001 if (instr->CheckFlag(HValue::kCanOverflow)) {
2002 result = AssignEnvironment(result);
2006 DCHECK(to.IsDouble());
2007 if (val->CheckFlag(HInstruction::kUint32)) {
2008 return DefineAsRegister(new(zone()) LUint32ToDouble(UseRegister(val)));
2010 return DefineAsRegister(new(zone()) LInteger32ToDouble(Use(val)));
2013 } else if (from.IsSIMD128()) {
2014 DCHECK(to.IsTagged());
2015 info()->MarkAsDeferredCalling();
2016 LOperand* value = UseRegister(instr->value());
2017 LOperand* temp = TempRegister();
2018 LOperand* temp2 = TempRegister();
2020 // Make sure that temp and result_temp are different registers.
2021 LUnallocated* result_temp = TempRegister();
2022 LSIMD128ToTagged* result = new(zone()) LSIMD128ToTagged(value, temp, temp2);
2023 return AssignPointerMap(Define(result, result_temp));
2030 LInstruction* LChunkBuilder::DoCheckHeapObject(HCheckHeapObject* instr) {
2031 LOperand* value = UseAtStart(instr->value());
2032 LInstruction* result = new(zone()) LCheckNonSmi(value);
2033 if (!instr->value()->type().IsHeapObject()) {
2034 result = AssignEnvironment(result);
2040 LInstruction* LChunkBuilder::DoCheckSmi(HCheckSmi* instr) {
2041 LOperand* value = UseRegisterAtStart(instr->value());
2042 return AssignEnvironment(new(zone()) LCheckSmi(value));
2046 LInstruction* LChunkBuilder::DoCheckInstanceType(HCheckInstanceType* instr) {
2047 LOperand* value = UseRegisterAtStart(instr->value());
2048 LOperand* temp = TempRegister();
2049 LCheckInstanceType* result = new(zone()) LCheckInstanceType(value, temp);
2050 return AssignEnvironment(result);
2054 LInstruction* LChunkBuilder::DoCheckValue(HCheckValue* instr) {
2055 // If the object is in new space, we'll emit a global cell compare and so
2056 // want the value in a register. If the object gets promoted before we
2057 // emit code, we will still get the register but will do an immediate
2058 // compare instead of the cell compare. This is safe.
2059 LOperand* value = instr->object_in_new_space()
2060 ? UseRegisterAtStart(instr->value()) : UseAtStart(instr->value());
2061 return AssignEnvironment(new(zone()) LCheckValue(value));
2065 LInstruction* LChunkBuilder::DoCheckMaps(HCheckMaps* instr) {
2066 if (instr->IsStabilityCheck()) return new(zone()) LCheckMaps;
2067 LOperand* value = UseRegisterAtStart(instr->value());
2068 LInstruction* result = AssignEnvironment(new(zone()) LCheckMaps(value));
2069 if (instr->HasMigrationTarget()) {
2070 info()->MarkAsDeferredCalling();
2071 result = AssignPointerMap(result);
2077 LInstruction* LChunkBuilder::DoClampToUint8(HClampToUint8* instr) {
2078 HValue* value = instr->value();
2079 Representation input_rep = value->representation();
2080 if (input_rep.IsDouble()) {
2081 LOperand* reg = UseRegister(value);
2082 return DefineFixed(new(zone()) LClampDToUint8(reg), eax);
2083 } else if (input_rep.IsInteger32()) {
2084 LOperand* reg = UseFixed(value, eax);
2085 return DefineFixed(new(zone()) LClampIToUint8(reg), eax);
2087 DCHECK(input_rep.IsSmiOrTagged());
2088 LOperand* reg = UseFixed(value, eax);
2089 // Register allocator doesn't (yet) support allocation of double
2090 // temps. Reserve xmm1 explicitly.
2091 LOperand* temp = FixedTemp(xmm1);
2092 LClampTToUint8* result = new(zone()) LClampTToUint8(reg, temp);
2093 return AssignEnvironment(DefineFixed(result, eax));
2098 LInstruction* LChunkBuilder::DoDoubleBits(HDoubleBits* instr) {
2099 HValue* value = instr->value();
2100 DCHECK(value->representation().IsDouble());
2101 return DefineAsRegister(new(zone()) LDoubleBits(UseRegister(value)));
2105 LInstruction* LChunkBuilder::DoConstructDouble(HConstructDouble* instr) {
2106 LOperand* lo = UseRegister(instr->lo());
2107 LOperand* hi = UseRegister(instr->hi());
2108 return DefineAsRegister(new(zone()) LConstructDouble(hi, lo));
2112 LInstruction* LChunkBuilder::DoReturn(HReturn* instr) {
2113 LOperand* context = info()->IsStub() ? UseFixed(instr->context(), esi) : NULL;
2114 LOperand* parameter_count = UseRegisterOrConstant(instr->parameter_count());
2115 return new(zone()) LReturn(
2116 UseFixed(instr->value(), eax), context, parameter_count);
2120 LInstruction* LChunkBuilder::DoConstant(HConstant* instr) {
2121 Representation r = instr->representation();
2123 return DefineAsRegister(new(zone()) LConstantS);
2124 } else if (r.IsInteger32()) {
2125 return DefineAsRegister(new(zone()) LConstantI);
2126 } else if (r.IsDouble()) {
2127 double value = instr->DoubleValue();
2128 bool value_is_zero = bit_cast<uint64_t, double>(value) == 0;
2129 LOperand* temp = value_is_zero ? NULL : TempRegister();
2130 return DefineAsRegister(new(zone()) LConstantD(temp));
2131 } else if (r.IsExternal()) {
2132 return DefineAsRegister(new(zone()) LConstantE);
2133 } else if (r.IsTagged()) {
2134 return DefineAsRegister(new(zone()) LConstantT);
2142 LInstruction* LChunkBuilder::DoLoadGlobalCell(HLoadGlobalCell* instr) {
2143 LLoadGlobalCell* result = new(zone()) LLoadGlobalCell;
2144 return instr->RequiresHoleCheck()
2145 ? AssignEnvironment(DefineAsRegister(result))
2146 : DefineAsRegister(result);
2150 LInstruction* LChunkBuilder::DoLoadGlobalGeneric(HLoadGlobalGeneric* instr) {
2151 LOperand* context = UseFixed(instr->context(), esi);
2152 LOperand* global_object =
2153 UseFixed(instr->global_object(), LoadDescriptor::ReceiverRegister());
2154 LOperand* vector = NULL;
2155 if (FLAG_vector_ics) {
2156 vector = FixedTemp(VectorLoadICDescriptor::VectorRegister());
2159 LLoadGlobalGeneric* result =
2160 new(zone()) LLoadGlobalGeneric(context, global_object, vector);
2161 return MarkAsCall(DefineFixed(result, eax), instr);
2165 LInstruction* LChunkBuilder::DoStoreGlobalCell(HStoreGlobalCell* instr) {
2166 LStoreGlobalCell* result =
2167 new(zone()) LStoreGlobalCell(UseRegister(instr->value()));
2168 return instr->RequiresHoleCheck() ? AssignEnvironment(result) : result;
2172 LInstruction* LChunkBuilder::DoLoadContextSlot(HLoadContextSlot* instr) {
2173 LOperand* context = UseRegisterAtStart(instr->value());
2174 LInstruction* result =
2175 DefineAsRegister(new(zone()) LLoadContextSlot(context));
2176 if (instr->RequiresHoleCheck() && instr->DeoptimizesOnHole()) {
2177 result = AssignEnvironment(result);
2183 LInstruction* LChunkBuilder::DoStoreContextSlot(HStoreContextSlot* instr) {
2186 LOperand* context = UseRegister(instr->context());
2187 if (instr->NeedsWriteBarrier()) {
2188 value = UseTempRegister(instr->value());
2189 temp = TempRegister();
2191 value = UseRegister(instr->value());
2194 LInstruction* result = new(zone()) LStoreContextSlot(context, value, temp);
2195 if (instr->RequiresHoleCheck() && instr->DeoptimizesOnHole()) {
2196 result = AssignEnvironment(result);
2202 LInstruction* LChunkBuilder::DoLoadNamedField(HLoadNamedField* instr) {
2203 LOperand* obj = (instr->access().IsExternalMemory() &&
2204 instr->access().offset() == 0)
2205 ? UseRegisterOrConstantAtStart(instr->object())
2206 : UseRegisterAtStart(instr->object());
2207 return DefineAsRegister(new(zone()) LLoadNamedField(obj));
2211 LInstruction* LChunkBuilder::DoLoadNamedGeneric(HLoadNamedGeneric* instr) {
2212 LOperand* context = UseFixed(instr->context(), esi);
2214 UseFixed(instr->object(), LoadDescriptor::ReceiverRegister());
2215 LOperand* vector = NULL;
2216 if (FLAG_vector_ics) {
2217 vector = FixedTemp(VectorLoadICDescriptor::VectorRegister());
2219 LLoadNamedGeneric* result = new(zone()) LLoadNamedGeneric(
2220 context, object, vector);
2221 return MarkAsCall(DefineFixed(result, eax), instr);
2225 LInstruction* LChunkBuilder::DoLoadFunctionPrototype(
2226 HLoadFunctionPrototype* instr) {
2227 return AssignEnvironment(DefineAsRegister(
2228 new(zone()) LLoadFunctionPrototype(UseRegister(instr->function()),
2233 LInstruction* LChunkBuilder::DoLoadRoot(HLoadRoot* instr) {
2234 return DefineAsRegister(new(zone()) LLoadRoot);
2238 LInstruction* LChunkBuilder::DoLoadKeyed(HLoadKeyed* instr) {
2239 DCHECK(instr->key()->representation().IsSmiOrInteger32());
2240 ElementsKind elements_kind = instr->elements_kind();
2241 bool clobbers_key = ExternalArrayOpRequiresTemp(
2242 instr->key()->representation(), elements_kind);
2243 LOperand* key = clobbers_key
2244 ? UseTempRegister(instr->key())
2245 : UseRegisterOrConstantAtStart(instr->key());
2246 LInstruction* result = NULL;
2248 if (!instr->is_typed_elements()) {
2249 LOperand* obj = UseRegisterAtStart(instr->elements());
2250 result = DefineAsRegister(new(zone()) LLoadKeyed(obj, key));
2253 (instr->representation().IsInteger32() &&
2254 !(IsDoubleOrFloatElementsKind(instr->elements_kind()))) ||
2255 (instr->representation().IsDouble() &&
2256 (IsDoubleOrFloatElementsKind(instr->elements_kind()))) ||
2257 (CpuFeatures::SupportsSIMD128InCrankshaft()
2258 ? instr->representation().IsFloat32x4()
2259 : instr->representation().IsTagged() &&
2260 (IsFloat32x4ElementsKind(instr->elements_kind()))) ||
2261 (CpuFeatures::SupportsSIMD128InCrankshaft()
2262 ? instr->representation().IsFloat64x2()
2263 : instr->representation().IsTagged() &&
2264 (IsFloat64x2ElementsKind(instr->elements_kind()))) ||
2265 (CpuFeatures::SupportsSIMD128InCrankshaft()
2266 ? instr->representation().IsInt32x4()
2267 : instr->representation().IsTagged() &&
2268 (IsInt32x4ElementsKind(instr->elements_kind()))));
2269 LOperand* backing_store = UseRegister(instr->elements());
2270 result = DefineAsRegister(new(zone()) LLoadKeyed(backing_store, key));
2273 if ((instr->is_external() || instr->is_fixed_typed_array()) ?
2274 // see LCodeGen::DoLoadKeyedExternalArray
2275 ((instr->elements_kind() == EXTERNAL_UINT32_ELEMENTS ||
2276 instr->elements_kind() == UINT32_ELEMENTS) &&
2277 !instr->CheckFlag(HInstruction::kUint32)) :
2278 // see LCodeGen::DoLoadKeyedFixedDoubleArray and
2279 // LCodeGen::DoLoadKeyedFixedArray
2280 instr->RequiresHoleCheck()) {
2281 result = AssignEnvironment(result);
2287 LInstruction* LChunkBuilder::DoLoadKeyedGeneric(HLoadKeyedGeneric* instr) {
2288 LOperand* context = UseFixed(instr->context(), esi);
2290 UseFixed(instr->object(), LoadDescriptor::ReceiverRegister());
2291 LOperand* key = UseFixed(instr->key(), LoadDescriptor::NameRegister());
2292 LOperand* vector = NULL;
2293 if (FLAG_vector_ics) {
2294 vector = FixedTemp(VectorLoadICDescriptor::VectorRegister());
2296 LLoadKeyedGeneric* result =
2297 new(zone()) LLoadKeyedGeneric(context, object, key, vector);
2298 return MarkAsCall(DefineFixed(result, eax), instr);
2302 LOperand* LChunkBuilder::GetStoreKeyedValueOperand(HStoreKeyed* instr) {
2303 ElementsKind elements_kind = instr->elements_kind();
2305 // Determine if we need a byte register in this case for the value.
2306 bool val_is_fixed_register =
2307 elements_kind == EXTERNAL_INT8_ELEMENTS ||
2308 elements_kind == EXTERNAL_UINT8_ELEMENTS ||
2309 elements_kind == EXTERNAL_UINT8_CLAMPED_ELEMENTS ||
2310 elements_kind == UINT8_ELEMENTS ||
2311 elements_kind == INT8_ELEMENTS ||
2312 elements_kind == UINT8_CLAMPED_ELEMENTS;
2313 if (val_is_fixed_register) {
2314 return UseFixed(instr->value(), eax);
2317 return UseRegister(instr->value());
2321 LInstruction* LChunkBuilder::DoStoreKeyed(HStoreKeyed* instr) {
2322 if (!instr->is_typed_elements()) {
2323 DCHECK(instr->elements()->representation().IsTagged());
2324 DCHECK(instr->key()->representation().IsInteger32() ||
2325 instr->key()->representation().IsSmi());
2327 if (instr->value()->representation().IsDouble()) {
2328 LOperand* object = UseRegisterAtStart(instr->elements());
2329 LOperand* val = NULL;
2330 val = UseRegisterAtStart(instr->value());
2331 LOperand* key = UseRegisterOrConstantAtStart(instr->key());
2332 return new(zone()) LStoreKeyed(object, key, val);
2334 DCHECK(instr->value()->representation().IsSmiOrTagged());
2335 bool needs_write_barrier = instr->NeedsWriteBarrier();
2337 LOperand* obj = UseRegister(instr->elements());
2340 if (needs_write_barrier) {
2341 val = UseTempRegister(instr->value());
2342 key = UseTempRegister(instr->key());
2344 val = UseRegisterOrConstantAtStart(instr->value());
2345 key = UseRegisterOrConstantAtStart(instr->key());
2347 return new(zone()) LStoreKeyed(obj, key, val);
2351 ElementsKind elements_kind = instr->elements_kind();
2353 (instr->value()->representation().IsInteger32() &&
2354 !IsDoubleOrFloatElementsKind(elements_kind)) ||
2355 (instr->value()->representation().IsDouble() &&
2356 IsDoubleOrFloatElementsKind(elements_kind)) ||
2357 (CpuFeatures::SupportsSIMD128InCrankshaft()
2358 ? instr->value()->representation().IsFloat32x4()
2359 : instr->value()->representation().IsTagged() &&
2360 IsFloat32x4ElementsKind(elements_kind)) ||
2361 (CpuFeatures::SupportsSIMD128InCrankshaft()
2362 ? instr->value()->representation().IsFloat64x2()
2363 : instr->value()->representation().IsTagged() &&
2364 IsFloat64x2ElementsKind(elements_kind)) ||
2365 (CpuFeatures::SupportsSIMD128InCrankshaft()
2366 ? instr->value()->representation().IsInt32x4()
2367 : instr->value()->representation().IsTagged() &&
2368 IsInt32x4ElementsKind(elements_kind)));
2369 DCHECK((instr->is_fixed_typed_array() &&
2370 instr->elements()->representation().IsTagged()) ||
2371 (instr->is_external() &&
2372 instr->elements()->representation().IsExternal()));
2374 LOperand* backing_store = UseRegister(instr->elements());
2375 LOperand* val = GetStoreKeyedValueOperand(instr);
2376 bool clobbers_key = ExternalArrayOpRequiresTemp(
2377 instr->key()->representation(), elements_kind);
2378 LOperand* key = clobbers_key
2379 ? UseTempRegister(instr->key())
2380 : UseRegisterOrConstantAtStart(instr->key());
2381 return new(zone()) LStoreKeyed(backing_store, key, val);
2385 LInstruction* LChunkBuilder::DoStoreKeyedGeneric(HStoreKeyedGeneric* instr) {
2386 LOperand* context = UseFixed(instr->context(), esi);
2388 UseFixed(instr->object(), StoreDescriptor::ReceiverRegister());
2389 LOperand* key = UseFixed(instr->key(), StoreDescriptor::NameRegister());
2390 LOperand* value = UseFixed(instr->value(), StoreDescriptor::ValueRegister());
2392 DCHECK(instr->object()->representation().IsTagged());
2393 DCHECK(instr->key()->representation().IsTagged());
2394 DCHECK(instr->value()->representation().IsTagged());
2396 LStoreKeyedGeneric* result =
2397 new(zone()) LStoreKeyedGeneric(context, object, key, value);
2398 return MarkAsCall(result, instr);
2402 LInstruction* LChunkBuilder::DoTransitionElementsKind(
2403 HTransitionElementsKind* instr) {
2404 if (IsSimpleMapChangeTransition(instr->from_kind(), instr->to_kind())) {
2405 LOperand* object = UseRegister(instr->object());
2406 LOperand* new_map_reg = TempRegister();
2407 LOperand* temp_reg = TempRegister();
2408 LTransitionElementsKind* result =
2409 new(zone()) LTransitionElementsKind(object, NULL,
2410 new_map_reg, temp_reg);
2413 LOperand* object = UseFixed(instr->object(), eax);
2414 LOperand* context = UseFixed(instr->context(), esi);
2415 LTransitionElementsKind* result =
2416 new(zone()) LTransitionElementsKind(object, context, NULL, NULL);
2417 return MarkAsCall(result, instr);
2422 LInstruction* LChunkBuilder::DoTrapAllocationMemento(
2423 HTrapAllocationMemento* instr) {
2424 LOperand* object = UseRegister(instr->object());
2425 LOperand* temp = TempRegister();
2426 LTrapAllocationMemento* result =
2427 new(zone()) LTrapAllocationMemento(object, temp);
2428 return AssignEnvironment(result);
2432 LInstruction* LChunkBuilder::DoStoreNamedField(HStoreNamedField* instr) {
2433 bool is_in_object = instr->access().IsInobject();
2434 bool is_external_location = instr->access().IsExternalMemory() &&
2435 instr->access().offset() == 0;
2436 bool needs_write_barrier = instr->NeedsWriteBarrier();
2437 bool needs_write_barrier_for_map = instr->has_transition() &&
2438 instr->NeedsWriteBarrierForMap();
2441 if (needs_write_barrier) {
2443 ? UseRegister(instr->object())
2444 : UseTempRegister(instr->object());
2445 } else if (is_external_location) {
2446 DCHECK(!is_in_object);
2447 DCHECK(!needs_write_barrier);
2448 DCHECK(!needs_write_barrier_for_map);
2449 obj = UseRegisterOrConstant(instr->object());
2451 obj = needs_write_barrier_for_map
2452 ? UseRegister(instr->object())
2453 : UseRegisterAtStart(instr->object());
2456 bool can_be_constant = instr->value()->IsConstant() &&
2457 HConstant::cast(instr->value())->NotInNewSpace() &&
2458 !instr->field_representation().IsDouble();
2461 if (instr->field_representation().IsInteger8() ||
2462 instr->field_representation().IsUInteger8()) {
2463 // mov_b requires a byte register (i.e. any of eax, ebx, ecx, edx).
2464 // Just force the value to be in eax and we're safe here.
2465 val = UseFixed(instr->value(), eax);
2466 } else if (needs_write_barrier) {
2467 val = UseTempRegister(instr->value());
2468 } else if (can_be_constant) {
2469 val = UseRegisterOrConstant(instr->value());
2470 } else if (instr->field_representation().IsDouble()) {
2471 val = UseRegisterAtStart(instr->value());
2473 val = UseRegister(instr->value());
2476 // We only need a scratch register if we have a write barrier or we
2477 // have a store into the properties array (not in-object-property).
2478 LOperand* temp = (!is_in_object || needs_write_barrier ||
2479 needs_write_barrier_for_map) ? TempRegister() : NULL;
2481 // We need a temporary register for write barrier of the map field.
2482 LOperand* temp_map = needs_write_barrier_for_map ? TempRegister() : NULL;
2484 return new(zone()) LStoreNamedField(obj, val, temp, temp_map);
2488 LInstruction* LChunkBuilder::DoStoreNamedGeneric(HStoreNamedGeneric* instr) {
2489 LOperand* context = UseFixed(instr->context(), esi);
2491 UseFixed(instr->object(), StoreDescriptor::ReceiverRegister());
2492 LOperand* value = UseFixed(instr->value(), StoreDescriptor::ValueRegister());
2494 LStoreNamedGeneric* result =
2495 new(zone()) LStoreNamedGeneric(context, object, value);
2496 return MarkAsCall(result, instr);
2500 LInstruction* LChunkBuilder::DoStringAdd(HStringAdd* instr) {
2501 LOperand* context = UseFixed(instr->context(), esi);
2502 LOperand* left = UseFixed(instr->left(), edx);
2503 LOperand* right = UseFixed(instr->right(), eax);
2504 LStringAdd* string_add = new(zone()) LStringAdd(context, left, right);
2505 return MarkAsCall(DefineFixed(string_add, eax), instr);
2509 LInstruction* LChunkBuilder::DoStringCharCodeAt(HStringCharCodeAt* instr) {
2510 LOperand* string = UseTempRegister(instr->string());
2511 LOperand* index = UseTempRegister(instr->index());
2512 LOperand* context = UseAny(instr->context());
2513 LStringCharCodeAt* result =
2514 new(zone()) LStringCharCodeAt(context, string, index);
2515 return AssignPointerMap(DefineAsRegister(result));
2519 LInstruction* LChunkBuilder::DoStringCharFromCode(HStringCharFromCode* instr) {
2520 LOperand* char_code = UseRegister(instr->value());
2521 LOperand* context = UseAny(instr->context());
2522 LStringCharFromCode* result =
2523 new(zone()) LStringCharFromCode(context, char_code);
2524 return AssignPointerMap(DefineAsRegister(result));
2528 LInstruction* LChunkBuilder::DoAllocate(HAllocate* instr) {
2529 info()->MarkAsDeferredCalling();
2530 LOperand* context = UseAny(instr->context());
2531 LOperand* size = instr->size()->IsConstant()
2532 ? UseConstant(instr->size())
2533 : UseTempRegister(instr->size());
2534 LOperand* temp = TempRegister();
2535 LAllocate* result = new(zone()) LAllocate(context, size, temp);
2536 return AssignPointerMap(DefineAsRegister(result));
2540 LInstruction* LChunkBuilder::DoRegExpLiteral(HRegExpLiteral* instr) {
2541 LOperand* context = UseFixed(instr->context(), esi);
2543 DefineFixed(new(zone()) LRegExpLiteral(context), eax), instr);
2547 LInstruction* LChunkBuilder::DoFunctionLiteral(HFunctionLiteral* instr) {
2548 LOperand* context = UseFixed(instr->context(), esi);
2550 DefineFixed(new(zone()) LFunctionLiteral(context), eax), instr);
2554 LInstruction* LChunkBuilder::DoOsrEntry(HOsrEntry* instr) {
2555 DCHECK(argument_count_ == 0);
2556 allocator_->MarkAsOsrEntry();
2557 current_block_->last_environment()->set_ast_id(instr->ast_id());
2558 return AssignEnvironment(new(zone()) LOsrEntry);
2562 LInstruction* LChunkBuilder::DoParameter(HParameter* instr) {
2563 LParameter* result = new(zone()) LParameter;
2564 if (instr->kind() == HParameter::STACK_PARAMETER) {
2565 int spill_index = chunk()->GetParameterStackSlot(instr->index());
2566 return DefineAsSpilled(result, spill_index);
2568 DCHECK(info()->IsStub());
2569 CallInterfaceDescriptor descriptor =
2570 info()->code_stub()->GetCallInterfaceDescriptor();
2571 int index = static_cast<int>(instr->index());
2572 Register reg = descriptor.GetEnvironmentParameterRegister(index);
2573 return DefineFixed(result, reg);
2578 LInstruction* LChunkBuilder::DoUnknownOSRValue(HUnknownOSRValue* instr) {
2579 // Use an index that corresponds to the location in the unoptimized frame,
2580 // which the optimized frame will subsume.
2581 int env_index = instr->index();
2582 int spill_index = 0;
2583 if (instr->environment()->is_parameter_index(env_index)) {
2584 spill_index = chunk()->GetParameterStackSlot(env_index);
2586 spill_index = env_index - instr->environment()->first_local_index();
2587 if (spill_index > LUnallocated::kMaxFixedSlotIndex) {
2588 Retry(kNotEnoughSpillSlotsForOsr);
2591 if (spill_index == 0) {
2592 // The dynamic frame alignment state overwrites the first local.
2593 // The first local is saved at the end of the unoptimized frame.
2594 spill_index = graph()->osr()->UnoptimizedFrameSlots();
2597 return DefineAsSpilled(new(zone()) LUnknownOSRValue, spill_index);
2601 LInstruction* LChunkBuilder::DoCallStub(HCallStub* instr) {
2602 LOperand* context = UseFixed(instr->context(), esi);
2603 LCallStub* result = new(zone()) LCallStub(context);
2604 return MarkAsCall(DefineFixed(result, eax), instr);
2608 LInstruction* LChunkBuilder::DoArgumentsObject(HArgumentsObject* instr) {
2609 // There are no real uses of the arguments object.
2610 // arguments.length and element access are supported directly on
2611 // stack arguments, and any real arguments object use causes a bailout.
2612 // So this value is never used.
2617 LInstruction* LChunkBuilder::DoCapturedObject(HCapturedObject* instr) {
2618 instr->ReplayEnvironment(current_block_->last_environment());
2620 // There are no real uses of a captured object.
2625 LInstruction* LChunkBuilder::DoAccessArgumentsAt(HAccessArgumentsAt* instr) {
2626 info()->MarkAsRequiresFrame();
2627 LOperand* args = UseRegister(instr->arguments());
2630 if (instr->length()->IsConstant() && instr->index()->IsConstant()) {
2631 length = UseRegisterOrConstant(instr->length());
2632 index = UseOrConstant(instr->index());
2634 length = UseTempRegister(instr->length());
2635 index = Use(instr->index());
2637 return DefineAsRegister(new(zone()) LAccessArgumentsAt(args, length, index));
2641 LInstruction* LChunkBuilder::DoToFastProperties(HToFastProperties* instr) {
2642 LOperand* object = UseFixed(instr->value(), eax);
2643 LToFastProperties* result = new(zone()) LToFastProperties(object);
2644 return MarkAsCall(DefineFixed(result, eax), instr);
2648 LInstruction* LChunkBuilder::DoTypeof(HTypeof* instr) {
2649 LOperand* context = UseFixed(instr->context(), esi);
2650 LOperand* value = UseAtStart(instr->value());
2651 LTypeof* result = new(zone()) LTypeof(context, value);
2652 return MarkAsCall(DefineFixed(result, eax), instr);
2656 LInstruction* LChunkBuilder::DoTypeofIsAndBranch(HTypeofIsAndBranch* instr) {
2657 return new(zone()) LTypeofIsAndBranch(UseTempRegister(instr->value()));
2661 LInstruction* LChunkBuilder::DoIsConstructCallAndBranch(
2662 HIsConstructCallAndBranch* instr) {
2663 return new(zone()) LIsConstructCallAndBranch(TempRegister());
2667 LInstruction* LChunkBuilder::DoSimulate(HSimulate* instr) {
2668 instr->ReplayEnvironment(current_block_->last_environment());
2673 LInstruction* LChunkBuilder::DoStackCheck(HStackCheck* instr) {
2674 info()->MarkAsDeferredCalling();
2675 if (instr->is_function_entry()) {
2676 LOperand* context = UseFixed(instr->context(), esi);
2677 return MarkAsCall(new(zone()) LStackCheck(context), instr);
2679 DCHECK(instr->is_backwards_branch());
2680 LOperand* context = UseAny(instr->context());
2681 return AssignEnvironment(
2682 AssignPointerMap(new(zone()) LStackCheck(context)));
2687 LInstruction* LChunkBuilder::DoEnterInlined(HEnterInlined* instr) {
2688 HEnvironment* outer = current_block_->last_environment();
2689 outer->set_ast_id(instr->ReturnId());
2690 HConstant* undefined = graph()->GetConstantUndefined();
2691 HEnvironment* inner = outer->CopyForInlining(instr->closure(),
2692 instr->arguments_count(),
2695 instr->inlining_kind());
2696 // Only replay binding of arguments object if it wasn't removed from graph.
2697 if (instr->arguments_var() != NULL && instr->arguments_object()->IsLinked()) {
2698 inner->Bind(instr->arguments_var(), instr->arguments_object());
2700 inner->BindContext(instr->closure_context());
2701 inner->set_entry(instr);
2702 current_block_->UpdateEnvironment(inner);
2703 chunk_->AddInlinedClosure(instr->closure());
2708 LInstruction* LChunkBuilder::DoLeaveInlined(HLeaveInlined* instr) {
2709 LInstruction* pop = NULL;
2711 HEnvironment* env = current_block_->last_environment();
2713 if (env->entry()->arguments_pushed()) {
2714 int argument_count = env->arguments_environment()->parameter_count();
2715 pop = new(zone()) LDrop(argument_count);
2716 DCHECK(instr->argument_delta() == -argument_count);
2719 HEnvironment* outer = current_block_->last_environment()->
2720 DiscardInlined(false);
2721 current_block_->UpdateEnvironment(outer);
2726 LInstruction* LChunkBuilder::DoForInPrepareMap(HForInPrepareMap* instr) {
2727 LOperand* context = UseFixed(instr->context(), esi);
2728 LOperand* object = UseFixed(instr->enumerable(), eax);
2729 LForInPrepareMap* result = new(zone()) LForInPrepareMap(context, object);
2730 return MarkAsCall(DefineFixed(result, eax), instr, CAN_DEOPTIMIZE_EAGERLY);
2734 LInstruction* LChunkBuilder::DoForInCacheArray(HForInCacheArray* instr) {
2735 LOperand* map = UseRegister(instr->map());
2736 return AssignEnvironment(DefineAsRegister(
2737 new(zone()) LForInCacheArray(map)));
2741 LInstruction* LChunkBuilder::DoCheckMapValue(HCheckMapValue* instr) {
2742 LOperand* value = UseRegisterAtStart(instr->value());
2743 LOperand* map = UseRegisterAtStart(instr->map());
2744 return AssignEnvironment(new(zone()) LCheckMapValue(value, map));
2748 LInstruction* LChunkBuilder::DoLoadFieldByIndex(HLoadFieldByIndex* instr) {
2749 LOperand* object = UseRegister(instr->object());
2750 LOperand* index = UseTempRegister(instr->index());
2751 LLoadFieldByIndex* load = new(zone()) LLoadFieldByIndex(object, index);
2752 LInstruction* result = DefineSameAsFirst(load);
2753 return AssignPointerMap(result);
2757 LInstruction* LChunkBuilder::DoStoreFrameContext(HStoreFrameContext* instr) {
2758 LOperand* context = UseRegisterAtStart(instr->context());
2759 return new(zone()) LStoreFrameContext(context);
2763 LInstruction* LChunkBuilder::DoAllocateBlockContext(
2764 HAllocateBlockContext* instr) {
2765 LOperand* context = UseFixed(instr->context(), esi);
2766 LOperand* function = UseRegisterAtStart(instr->function());
2767 LAllocateBlockContext* result =
2768 new(zone()) LAllocateBlockContext(context, function);
2769 return MarkAsCall(DefineFixed(result, esi), instr);
2773 const char* LNullarySIMDOperation::Mnemonic() const {
2775 #define SIMD_NULLARY_OPERATION_CASE_ITEM(module, function, name, p4) \
2777 return #module "-" #function;
2778 SIMD_NULLARY_OPERATIONS(SIMD_NULLARY_OPERATION_CASE_ITEM)
2779 #undef SIMD_NULLARY_OPERATION_CASE_ITEM
2787 LInstruction* LChunkBuilder::DoNullarySIMDOperation(
2788 HNullarySIMDOperation* instr) {
2789 LNullarySIMDOperation* result =
2790 new(zone()) LNullarySIMDOperation(instr->op());
2791 switch (instr->op()) {
2792 #define SIMD_NULLARY_OPERATION_CASE_ITEM(module, function, name, p4) \
2794 SIMD_NULLARY_OPERATIONS(SIMD_NULLARY_OPERATION_CASE_ITEM)
2795 #undef SIMD_NULLARY_OPERATION_CASE_ITEM
2796 return DefineAsRegister(result);
2804 const char* LUnarySIMDOperation::Mnemonic() const {
2806 case kSIMD128Change: return "SIMD128-change";
2807 #define SIMD_UNARY_OPERATION_CASE_ITEM(module, function, name, p4, p5) \
2809 return #module "-" #function;
2810 SIMD_UNARY_OPERATIONS(SIMD_UNARY_OPERATION_CASE_ITEM)
2811 SIMD_UNARY_OPERATIONS_FOR_PROPERTY_ACCESS(SIMD_UNARY_OPERATION_CASE_ITEM)
2812 #undef SIMD_UNARY_OPERATION_CASE_ITEM
2820 LInstruction* LChunkBuilder::DoUnarySIMDOperation(HUnarySIMDOperation* instr) {
2821 LOperand* input = UseRegisterAtStart(instr->value());
2822 LUnarySIMDOperation* result =
2823 new(zone()) LUnarySIMDOperation(input, instr->op());
2824 switch (instr->op()) {
2825 case kSIMD128Change:
2826 return AssignEnvironment(DefineAsRegister(result));
2829 case kFloat32x4Reciprocal:
2830 case kFloat32x4ReciprocalSqrt:
2831 case kFloat32x4Sqrt:
2834 case kFloat64x2Sqrt:
2837 return DefineSameAsFirst(result);
2838 case kFloat32x4Coercion:
2839 case kFloat64x2Coercion:
2840 case kInt32x4Coercion:
2841 case kFloat32x4BitsToInt32x4:
2842 case kFloat32x4ToInt32x4:
2843 case kInt32x4BitsToFloat32x4:
2844 case kInt32x4ToFloat32x4:
2845 case kFloat32x4Splat:
2847 case kFloat32x4GetSignMask:
2848 case kFloat32x4GetX:
2849 case kFloat32x4GetY:
2850 case kFloat32x4GetZ:
2851 case kFloat32x4GetW:
2852 case kFloat64x2GetSignMask:
2853 case kFloat64x2GetX:
2854 case kFloat64x2GetY:
2855 case kInt32x4GetSignMask:
2860 case kInt32x4GetFlagX:
2861 case kInt32x4GetFlagY:
2862 case kInt32x4GetFlagZ:
2863 case kInt32x4GetFlagW:
2864 return DefineAsRegister(result);
2872 const char* LBinarySIMDOperation::Mnemonic() const {
2874 #define SIMD_BINARY_OPERATION_CASE_ITEM(module, function, name, p4, p5, p6) \
2876 return #module "-" #function;
2877 SIMD_BINARY_OPERATIONS(SIMD_BINARY_OPERATION_CASE_ITEM)
2878 #undef SIMD_BINARY_OPERATION_CASE_ITEM
2886 LInstruction* LChunkBuilder::DoBinarySIMDOperation(
2887 HBinarySIMDOperation* instr) {
2888 switch (instr->op()) {
2895 case kFloat32x4Scale:
2896 case kFloat32x4WithX:
2897 case kFloat32x4WithY:
2898 case kFloat32x4WithZ:
2899 case kFloat32x4WithW:
2906 case kFloat64x2Scale:
2907 case kFloat64x2WithX:
2908 case kFloat64x2WithY:
2919 case kInt32x4WithFlagX:
2920 case kInt32x4WithFlagY:
2921 case kInt32x4WithFlagZ:
2922 case kInt32x4WithFlagW:
2923 case kInt32x4GreaterThan:
2925 case kInt32x4LessThan: {
2926 LOperand* left = UseRegisterAtStart(instr->left());
2927 LOperand* right = UseRegisterAtStart(instr->right());
2928 LBinarySIMDOperation* result =
2929 new(zone()) LBinarySIMDOperation(left, right, instr->op());
2930 if (instr->op() == kInt32x4WithFlagX ||
2931 instr->op() == kInt32x4WithFlagY ||
2932 instr->op() == kInt32x4WithFlagZ ||
2933 instr->op() == kInt32x4WithFlagW) {
2934 return AssignEnvironment(DefineSameAsFirst(result));
2936 return DefineSameAsFirst(result);
2939 case kFloat64x2Constructor: {
2940 LOperand* left = UseRegisterAtStart(instr->left());
2941 LOperand* right = UseRegisterAtStart(instr->right());
2942 LBinarySIMDOperation* result =
2943 new(zone()) LBinarySIMDOperation(left, right, instr->op());
2944 return DefineAsRegister(result);
2946 case kFloat32x4Shuffle:
2947 case kInt32x4Shuffle:
2948 case kInt32x4ShiftLeft:
2949 case kInt32x4ShiftRight:
2950 case kInt32x4ShiftRightArithmetic: {
2951 LOperand* left = UseRegisterAtStart(instr->left());
2952 LOperand* right = UseOrConstant(instr->right());
2953 LBinarySIMDOperation* result =
2954 new(zone()) LBinarySIMDOperation(left, right, instr->op());
2955 return AssignEnvironment(DefineSameAsFirst(result));
2957 case kFloat32x4LessThan:
2958 case kFloat32x4LessThanOrEqual:
2959 case kFloat32x4Equal:
2960 case kFloat32x4NotEqual:
2961 case kFloat32x4GreaterThanOrEqual:
2962 case kFloat32x4GreaterThan: {
2963 LOperand* left = UseRegisterAtStart(instr->left());
2964 LOperand* right = UseRegisterAtStart(instr->right());
2965 LBinarySIMDOperation* result =
2966 new(zone()) LBinarySIMDOperation(left, right, instr->op());
2967 return DefineAsRegister(result);
2976 const char* LTernarySIMDOperation::Mnemonic() const {
2978 #define SIMD_TERNARY_OPERATION_CASE_ITEM(module, function, name, p4, p5, p6, \
2981 return #module "-" #function;
2982 SIMD_TERNARY_OPERATIONS(SIMD_TERNARY_OPERATION_CASE_ITEM)
2983 #undef SIMD_TERNARY_OPERATION_CASE_ITEM
2991 LInstruction* LChunkBuilder::DoTernarySIMDOperation(
2992 HTernarySIMDOperation* instr) {
2993 LOperand* first = UseRegisterAtStart(instr->first());
2994 LOperand* second = UseRegisterAtStart(instr->second());
2995 LOperand* third = instr->op() == kFloat32x4ShuffleMix
2996 ? UseOrConstant(instr->third())
2997 : UseRegisterAtStart(instr->third());
2998 LTernarySIMDOperation* result =
2999 new(zone()) LTernarySIMDOperation(first, second, third, instr->op());
3000 switch (instr->op()) {
3001 case kInt32x4Select:
3002 case kFloat32x4Select: {
3003 return DefineAsRegister(result);
3005 case kFloat32x4ShuffleMix: {
3006 return AssignEnvironment(DefineSameAsFirst(result));
3008 case kFloat32x4Clamp:
3009 case kFloat64x2Clamp: {
3010 return DefineSameAsFirst(result);
3019 const char* LQuarternarySIMDOperation::Mnemonic() const {
3021 #define SIMD_QUARTERNARY_OPERATION_CASE_ITEM(module, function, name, p4, p5, \
3024 return #module "-" #function;
3025 SIMD_QUARTERNARY_OPERATIONS(SIMD_QUARTERNARY_OPERATION_CASE_ITEM)
3026 #undef SIMD_QUARTERNARY_OPERATION_CASE_ITEM
3034 LInstruction* LChunkBuilder::DoQuarternarySIMDOperation(
3035 HQuarternarySIMDOperation* instr) {
3036 LOperand* x = UseRegisterAtStart(instr->x());
3037 LOperand* y = UseRegisterAtStart(instr->y());
3038 LOperand* z = UseRegisterAtStart(instr->z());
3039 LOperand* w = UseRegisterAtStart(instr->w());
3040 LQuarternarySIMDOperation* result =
3041 new(zone()) LQuarternarySIMDOperation(x, y, z, w, instr->op());
3042 if (instr->op() == kInt32x4Bool) {
3043 return AssignEnvironment(DefineAsRegister(result));
3045 return DefineAsRegister(result);
3050 } } // namespace v8::internal
3052 #endif // V8_TARGET_ARCH_IA32