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 #include "src/arm/lithium-codegen-arm.h"
8 #include "src/hydrogen-osr.h"
9 #include "src/lithium-inl.h"
14 #define DEFINE_COMPILE(type) \
15 void L##type::CompileToNative(LCodeGen* generator) { \
16 generator->Do##type(this); \
18 LITHIUM_CONCRETE_INSTRUCTION_LIST(DEFINE_COMPILE)
22 void LInstruction::VerifyCall() {
23 // Call instructions can use only fixed registers as temporaries and
24 // outputs because all registers are blocked by the calling convention.
25 // Inputs operands must use a fixed register or use-at-start policy or
26 // a non-register policy.
27 DCHECK(Output() == NULL ||
28 LUnallocated::cast(Output())->HasFixedPolicy() ||
29 !LUnallocated::cast(Output())->HasRegisterPolicy());
30 for (UseIterator it(this); !it.Done(); it.Advance()) {
31 LUnallocated* operand = LUnallocated::cast(it.Current());
32 DCHECK(operand->HasFixedPolicy() ||
33 operand->IsUsedAtStart());
35 for (TempIterator it(this); !it.Done(); it.Advance()) {
36 LUnallocated* operand = LUnallocated::cast(it.Current());
37 DCHECK(operand->HasFixedPolicy() ||!operand->HasRegisterPolicy());
43 void LInstruction::PrintTo(StringStream* stream) {
44 stream->Add("%s ", this->Mnemonic());
46 PrintOutputOperandTo(stream);
50 if (HasEnvironment()) {
52 environment()->PrintTo(stream);
55 if (HasPointerMap()) {
57 pointer_map()->PrintTo(stream);
62 void LInstruction::PrintDataTo(StringStream* stream) {
64 for (int i = 0; i < InputCount(); i++) {
65 if (i > 0) stream->Add(" ");
66 if (InputAt(i) == NULL) {
69 InputAt(i)->PrintTo(stream);
75 void LInstruction::PrintOutputOperandTo(StringStream* stream) {
76 if (HasResult()) result()->PrintTo(stream);
80 void LLabel::PrintDataTo(StringStream* stream) {
81 LGap::PrintDataTo(stream);
82 LLabel* rep = replacement();
84 stream->Add(" Dead block replaced with B%d", rep->block_id());
89 bool LGap::IsRedundant() const {
90 for (int i = 0; i < 4; i++) {
91 if (parallel_moves_[i] != NULL && !parallel_moves_[i]->IsRedundant()) {
100 void LGap::PrintDataTo(StringStream* stream) {
101 for (int i = 0; i < 4; i++) {
103 if (parallel_moves_[i] != NULL) {
104 parallel_moves_[i]->PrintDataTo(stream);
111 const char* LArithmeticD::Mnemonic() const {
113 case Token::ADD: return "add-d";
114 case Token::SUB: return "sub-d";
115 case Token::MUL: return "mul-d";
116 case Token::DIV: return "div-d";
117 case Token::MOD: return "mod-d";
125 const char* LArithmeticT::Mnemonic() const {
127 case Token::ADD: return "add-t";
128 case Token::SUB: return "sub-t";
129 case Token::MUL: return "mul-t";
130 case Token::MOD: return "mod-t";
131 case Token::DIV: return "div-t";
132 case Token::BIT_AND: return "bit-and-t";
133 case Token::BIT_OR: return "bit-or-t";
134 case Token::BIT_XOR: return "bit-xor-t";
135 case Token::ROR: return "ror-t";
136 case Token::SHL: return "shl-t";
137 case Token::SAR: return "sar-t";
138 case Token::SHR: return "shr-t";
146 bool LGoto::HasInterestingComment(LCodeGen* gen) const {
147 return !gen->IsNextEmittedBlock(block_id());
151 void LGoto::PrintDataTo(StringStream* stream) {
152 stream->Add("B%d", block_id());
156 void LBranch::PrintDataTo(StringStream* stream) {
157 stream->Add("B%d | B%d on ", true_block_id(), false_block_id());
158 value()->PrintTo(stream);
162 void LCompareNumericAndBranch::PrintDataTo(StringStream* stream) {
164 left()->PrintTo(stream);
165 stream->Add(" %s ", Token::String(op()));
166 right()->PrintTo(stream);
167 stream->Add(" then B%d else B%d", true_block_id(), false_block_id());
171 void LIsObjectAndBranch::PrintDataTo(StringStream* stream) {
172 stream->Add("if is_object(");
173 value()->PrintTo(stream);
174 stream->Add(") then B%d else B%d", true_block_id(), false_block_id());
178 void LIsStringAndBranch::PrintDataTo(StringStream* stream) {
179 stream->Add("if is_string(");
180 value()->PrintTo(stream);
181 stream->Add(") then B%d else B%d", true_block_id(), false_block_id());
185 void LIsSmiAndBranch::PrintDataTo(StringStream* stream) {
186 stream->Add("if is_smi(");
187 value()->PrintTo(stream);
188 stream->Add(") then B%d else B%d", true_block_id(), false_block_id());
192 void LIsUndetectableAndBranch::PrintDataTo(StringStream* stream) {
193 stream->Add("if is_undetectable(");
194 value()->PrintTo(stream);
195 stream->Add(") then B%d else B%d", true_block_id(), false_block_id());
199 void LStringCompareAndBranch::PrintDataTo(StringStream* stream) {
200 stream->Add("if string_compare(");
201 left()->PrintTo(stream);
202 right()->PrintTo(stream);
203 stream->Add(") then B%d else B%d", true_block_id(), false_block_id());
207 void LHasInstanceTypeAndBranch::PrintDataTo(StringStream* stream) {
208 stream->Add("if has_instance_type(");
209 value()->PrintTo(stream);
210 stream->Add(") then B%d else B%d", true_block_id(), false_block_id());
214 void LHasCachedArrayIndexAndBranch::PrintDataTo(StringStream* stream) {
215 stream->Add("if has_cached_array_index(");
216 value()->PrintTo(stream);
217 stream->Add(") then B%d else B%d", true_block_id(), false_block_id());
221 void LClassOfTestAndBranch::PrintDataTo(StringStream* stream) {
222 stream->Add("if class_of_test(");
223 value()->PrintTo(stream);
224 stream->Add(", \"%o\") then B%d else B%d",
225 *hydrogen()->class_name(),
231 void LTypeofIsAndBranch::PrintDataTo(StringStream* stream) {
232 stream->Add("if typeof ");
233 value()->PrintTo(stream);
234 stream->Add(" == \"%s\" then B%d else B%d",
235 hydrogen()->type_literal()->ToCString().get(),
236 true_block_id(), false_block_id());
240 void LStoreCodeEntry::PrintDataTo(StringStream* stream) {
242 function()->PrintTo(stream);
243 stream->Add(".code_entry = ");
244 code_object()->PrintTo(stream);
248 void LInnerAllocatedObject::PrintDataTo(StringStream* stream) {
250 base_object()->PrintTo(stream);
252 offset()->PrintTo(stream);
256 void LCallJSFunction::PrintDataTo(StringStream* stream) {
258 function()->PrintTo(stream);
259 stream->Add("#%d / ", arity());
263 void LCallWithDescriptor::PrintDataTo(StringStream* stream) {
264 for (int i = 0; i < InputCount(); i++) {
265 InputAt(i)->PrintTo(stream);
268 stream->Add("#%d / ", arity());
272 void LLoadContextSlot::PrintDataTo(StringStream* stream) {
273 context()->PrintTo(stream);
274 stream->Add("[%d]", slot_index());
278 void LStoreContextSlot::PrintDataTo(StringStream* stream) {
279 context()->PrintTo(stream);
280 stream->Add("[%d] <- ", slot_index());
281 value()->PrintTo(stream);
285 void LInvokeFunction::PrintDataTo(StringStream* stream) {
287 function()->PrintTo(stream);
288 stream->Add(" #%d / ", arity());
292 void LCallNew::PrintDataTo(StringStream* stream) {
294 constructor()->PrintTo(stream);
295 stream->Add(" #%d / ", arity());
299 void LCallNewArray::PrintDataTo(StringStream* stream) {
301 constructor()->PrintTo(stream);
302 stream->Add(" #%d / ", arity());
303 ElementsKind kind = hydrogen()->elements_kind();
304 stream->Add(" (%s) ", ElementsKindToString(kind));
308 void LAccessArgumentsAt::PrintDataTo(StringStream* stream) {
309 arguments()->PrintTo(stream);
310 stream->Add(" length ");
311 length()->PrintTo(stream);
312 stream->Add(" index ");
313 index()->PrintTo(stream);
317 void LStoreNamedField::PrintDataTo(StringStream* stream) {
318 object()->PrintTo(stream);
320 os << hydrogen()->access() << " <- ";
321 stream->Add(os.c_str());
322 value()->PrintTo(stream);
326 void LStoreNamedGeneric::PrintDataTo(StringStream* stream) {
327 object()->PrintTo(stream);
329 stream->Add(String::cast(*name())->ToCString().get());
331 value()->PrintTo(stream);
335 void LLoadKeyed::PrintDataTo(StringStream* stream) {
336 elements()->PrintTo(stream);
338 key()->PrintTo(stream);
339 if (hydrogen()->IsDehoisted()) {
340 stream->Add(" + %d]", base_offset());
347 void LStoreKeyed::PrintDataTo(StringStream* stream) {
348 elements()->PrintTo(stream);
350 key()->PrintTo(stream);
351 if (hydrogen()->IsDehoisted()) {
352 stream->Add(" + %d] <-", base_offset());
354 stream->Add("] <- ");
357 if (value() == NULL) {
358 DCHECK(hydrogen()->IsConstantHoleStore() &&
359 hydrogen()->value()->representation().IsDouble());
360 stream->Add("<the hole(nan)>");
362 value()->PrintTo(stream);
367 void LStoreKeyedGeneric::PrintDataTo(StringStream* stream) {
368 object()->PrintTo(stream);
370 key()->PrintTo(stream);
371 stream->Add("] <- ");
372 value()->PrintTo(stream);
376 void LTransitionElementsKind::PrintDataTo(StringStream* stream) {
377 object()->PrintTo(stream);
378 stream->Add(" %p -> %p", *original_map(), *transitioned_map());
382 int LPlatformChunk::GetNextSpillIndex(RegisterKind kind) {
383 // Skip a slot if for a double-width slot.
384 if (kind == DOUBLE_REGISTERS) spill_slot_count_++;
385 return spill_slot_count_++;
389 LOperand* LPlatformChunk::GetNextSpillSlot(RegisterKind kind) {
390 int index = GetNextSpillIndex(kind);
391 if (kind == DOUBLE_REGISTERS) {
392 return LDoubleStackSlot::Create(index, zone());
394 DCHECK(kind == GENERAL_REGISTERS);
395 return LStackSlot::Create(index, zone());
400 LPlatformChunk* LChunkBuilder::Build() {
402 chunk_ = new(zone()) LPlatformChunk(info(), graph());
403 LPhase phase("L_Building chunk", chunk_);
406 // If compiling for OSR, reserve space for the unoptimized frame,
407 // which will be subsumed into this frame.
408 if (graph()->has_osr()) {
409 for (int i = graph()->osr()->UnoptimizedFrameSlots(); i > 0; i--) {
410 chunk_->GetNextSpillIndex(GENERAL_REGISTERS);
414 const ZoneList<HBasicBlock*>* blocks = graph()->blocks();
415 for (int i = 0; i < blocks->length(); i++) {
416 HBasicBlock* next = NULL;
417 if (i < blocks->length() - 1) next = blocks->at(i + 1);
418 DoBasicBlock(blocks->at(i), next);
419 if (is_aborted()) return NULL;
426 void LChunkBuilder::Abort(BailoutReason reason) {
427 info()->set_bailout_reason(reason);
432 LUnallocated* LChunkBuilder::ToUnallocated(Register reg) {
433 return new(zone()) LUnallocated(LUnallocated::FIXED_REGISTER,
434 Register::ToAllocationIndex(reg));
438 LUnallocated* LChunkBuilder::ToUnallocated(DoubleRegister reg) {
439 return new(zone()) LUnallocated(LUnallocated::FIXED_DOUBLE_REGISTER,
440 DoubleRegister::ToAllocationIndex(reg));
444 LOperand* LChunkBuilder::UseFixed(HValue* value, Register fixed_register) {
445 return Use(value, ToUnallocated(fixed_register));
449 LOperand* LChunkBuilder::UseFixedDouble(HValue* value, DoubleRegister reg) {
450 return Use(value, ToUnallocated(reg));
454 LOperand* LChunkBuilder::UseRegister(HValue* value) {
455 return Use(value, new(zone()) LUnallocated(LUnallocated::MUST_HAVE_REGISTER));
459 LOperand* LChunkBuilder::UseRegisterAtStart(HValue* value) {
461 new(zone()) LUnallocated(LUnallocated::MUST_HAVE_REGISTER,
462 LUnallocated::USED_AT_START));
466 LOperand* LChunkBuilder::UseTempRegister(HValue* value) {
467 return Use(value, new(zone()) LUnallocated(LUnallocated::WRITABLE_REGISTER));
471 LOperand* LChunkBuilder::Use(HValue* value) {
472 return Use(value, new(zone()) LUnallocated(LUnallocated::NONE));
476 LOperand* LChunkBuilder::UseAtStart(HValue* value) {
477 return Use(value, new(zone()) LUnallocated(LUnallocated::NONE,
478 LUnallocated::USED_AT_START));
482 LOperand* LChunkBuilder::UseOrConstant(HValue* value) {
483 return value->IsConstant()
484 ? chunk_->DefineConstantOperand(HConstant::cast(value))
489 LOperand* LChunkBuilder::UseOrConstantAtStart(HValue* value) {
490 return value->IsConstant()
491 ? chunk_->DefineConstantOperand(HConstant::cast(value))
496 LOperand* LChunkBuilder::UseRegisterOrConstant(HValue* value) {
497 return value->IsConstant()
498 ? chunk_->DefineConstantOperand(HConstant::cast(value))
499 : UseRegister(value);
503 LOperand* LChunkBuilder::UseRegisterOrConstantAtStart(HValue* value) {
504 return value->IsConstant()
505 ? chunk_->DefineConstantOperand(HConstant::cast(value))
506 : UseRegisterAtStart(value);
510 LOperand* LChunkBuilder::UseConstant(HValue* value) {
511 return chunk_->DefineConstantOperand(HConstant::cast(value));
515 LOperand* LChunkBuilder::UseAny(HValue* value) {
516 return value->IsConstant()
517 ? chunk_->DefineConstantOperand(HConstant::cast(value))
518 : Use(value, new(zone()) LUnallocated(LUnallocated::ANY));
522 LOperand* LChunkBuilder::Use(HValue* value, LUnallocated* operand) {
523 if (value->EmitAtUses()) {
524 HInstruction* instr = HInstruction::cast(value);
525 VisitInstruction(instr);
527 operand->set_virtual_register(value->id());
532 LInstruction* LChunkBuilder::Define(LTemplateResultInstruction<1>* instr,
533 LUnallocated* result) {
534 result->set_virtual_register(current_instruction_->id());
535 instr->set_result(result);
540 LInstruction* LChunkBuilder::DefineAsRegister(
541 LTemplateResultInstruction<1>* instr) {
543 new(zone()) LUnallocated(LUnallocated::MUST_HAVE_REGISTER));
547 LInstruction* LChunkBuilder::DefineAsSpilled(
548 LTemplateResultInstruction<1>* instr, int index) {
550 new(zone()) LUnallocated(LUnallocated::FIXED_SLOT, index));
554 LInstruction* LChunkBuilder::DefineSameAsFirst(
555 LTemplateResultInstruction<1>* instr) {
557 new(zone()) LUnallocated(LUnallocated::SAME_AS_FIRST_INPUT));
561 LInstruction* LChunkBuilder::DefineFixed(
562 LTemplateResultInstruction<1>* instr, Register reg) {
563 return Define(instr, ToUnallocated(reg));
567 LInstruction* LChunkBuilder::DefineFixedDouble(
568 LTemplateResultInstruction<1>* instr, DoubleRegister reg) {
569 return Define(instr, ToUnallocated(reg));
573 LInstruction* LChunkBuilder::AssignEnvironment(LInstruction* instr) {
574 HEnvironment* hydrogen_env = current_block_->last_environment();
575 int argument_index_accumulator = 0;
576 ZoneList<HValue*> objects_to_materialize(0, zone());
577 instr->set_environment(CreateEnvironment(hydrogen_env,
578 &argument_index_accumulator,
579 &objects_to_materialize));
584 LInstruction* LChunkBuilder::MarkAsCall(LInstruction* instr,
585 HInstruction* hinstr,
586 CanDeoptimize can_deoptimize) {
587 info()->MarkAsNonDeferredCalling();
592 instr = AssignPointerMap(instr);
594 // If instruction does not have side-effects lazy deoptimization
595 // after the call will try to deoptimize to the point before the call.
596 // Thus we still need to attach environment to this call even if
597 // call sequence can not deoptimize eagerly.
598 bool needs_environment =
599 (can_deoptimize == CAN_DEOPTIMIZE_EAGERLY) ||
600 !hinstr->HasObservableSideEffects();
601 if (needs_environment && !instr->HasEnvironment()) {
602 instr = AssignEnvironment(instr);
603 // We can't really figure out if the environment is needed or not.
604 instr->environment()->set_has_been_used();
611 LInstruction* LChunkBuilder::AssignPointerMap(LInstruction* instr) {
612 DCHECK(!instr->HasPointerMap());
613 instr->set_pointer_map(new(zone()) LPointerMap(zone()));
618 LUnallocated* LChunkBuilder::TempRegister() {
619 LUnallocated* operand =
620 new(zone()) LUnallocated(LUnallocated::MUST_HAVE_REGISTER);
621 int vreg = allocator_->GetVirtualRegister();
622 if (!allocator_->AllocationOk()) {
623 Abort(kOutOfVirtualRegistersWhileTryingToAllocateTempRegister);
626 operand->set_virtual_register(vreg);
631 LUnallocated* LChunkBuilder::TempDoubleRegister() {
632 LUnallocated* operand =
633 new(zone()) LUnallocated(LUnallocated::MUST_HAVE_DOUBLE_REGISTER);
634 int vreg = allocator_->GetVirtualRegister();
635 if (!allocator_->AllocationOk()) {
636 Abort(kOutOfVirtualRegistersWhileTryingToAllocateTempRegister);
639 operand->set_virtual_register(vreg);
644 LOperand* LChunkBuilder::FixedTemp(Register reg) {
645 LUnallocated* operand = ToUnallocated(reg);
646 DCHECK(operand->HasFixedPolicy());
651 LOperand* LChunkBuilder::FixedTemp(DoubleRegister reg) {
652 LUnallocated* operand = ToUnallocated(reg);
653 DCHECK(operand->HasFixedPolicy());
658 LInstruction* LChunkBuilder::DoBlockEntry(HBlockEntry* instr) {
659 return new(zone()) LLabel(instr->block());
663 LInstruction* LChunkBuilder::DoDummyUse(HDummyUse* instr) {
664 return DefineAsRegister(new(zone()) LDummyUse(UseAny(instr->value())));
668 LInstruction* LChunkBuilder::DoEnvironmentMarker(HEnvironmentMarker* instr) {
674 LInstruction* LChunkBuilder::DoDeoptimize(HDeoptimize* instr) {
675 return AssignEnvironment(new(zone()) LDeoptimize);
679 LInstruction* LChunkBuilder::DoShift(Token::Value op,
680 HBitwiseBinaryOperation* instr) {
681 if (instr->representation().IsSmiOrInteger32()) {
682 DCHECK(instr->left()->representation().Equals(instr->representation()));
683 DCHECK(instr->right()->representation().Equals(instr->representation()));
684 LOperand* left = UseRegisterAtStart(instr->left());
686 HValue* right_value = instr->right();
687 LOperand* right = NULL;
688 int constant_value = 0;
689 bool does_deopt = false;
690 if (right_value->IsConstant()) {
691 HConstant* constant = HConstant::cast(right_value);
692 right = chunk_->DefineConstantOperand(constant);
693 constant_value = constant->Integer32Value() & 0x1f;
694 // Left shifts can deoptimize if we shift by > 0 and the result cannot be
696 if (instr->representation().IsSmi() && constant_value > 0) {
697 does_deopt = !instr->CheckUsesForFlag(HValue::kTruncatingToSmi);
700 right = UseRegisterAtStart(right_value);
703 // Shift operations can only deoptimize if we do a logical shift
704 // by 0 and the result cannot be truncated to int32.
705 if (op == Token::SHR && constant_value == 0) {
706 if (FLAG_opt_safe_uint32_operations) {
707 does_deopt = !instr->CheckFlag(HInstruction::kUint32);
709 does_deopt = !instr->CheckUsesForFlag(HValue::kTruncatingToInt32);
713 LInstruction* result =
714 DefineAsRegister(new(zone()) LShiftI(op, left, right, does_deopt));
715 return does_deopt ? AssignEnvironment(result) : result;
717 return DoArithmeticT(op, instr);
722 LInstruction* LChunkBuilder::DoArithmeticD(Token::Value op,
723 HArithmeticBinaryOperation* instr) {
724 DCHECK(instr->representation().IsDouble());
725 DCHECK(instr->left()->representation().IsDouble());
726 DCHECK(instr->right()->representation().IsDouble());
727 if (op == Token::MOD) {
728 LOperand* left = UseFixedDouble(instr->left(), d0);
729 LOperand* right = UseFixedDouble(instr->right(), d1);
730 LArithmeticD* result = new(zone()) LArithmeticD(op, left, right);
731 return MarkAsCall(DefineFixedDouble(result, d0), instr);
733 LOperand* left = UseRegisterAtStart(instr->left());
734 LOperand* right = UseRegisterAtStart(instr->right());
735 LArithmeticD* result = new(zone()) LArithmeticD(op, left, right);
736 return DefineAsRegister(result);
741 LInstruction* LChunkBuilder::DoArithmeticT(Token::Value op,
742 HBinaryOperation* instr) {
743 HValue* left = instr->left();
744 HValue* right = instr->right();
745 DCHECK(left->representation().IsTagged());
746 DCHECK(right->representation().IsTagged());
747 LOperand* context = UseFixed(instr->context(), cp);
748 LOperand* left_operand = UseFixed(left, r1);
749 LOperand* right_operand = UseFixed(right, r0);
750 LArithmeticT* result =
751 new(zone()) LArithmeticT(op, context, left_operand, right_operand);
752 return MarkAsCall(DefineFixed(result, r0), instr);
756 void LChunkBuilder::DoBasicBlock(HBasicBlock* block, HBasicBlock* next_block) {
757 DCHECK(is_building());
758 current_block_ = block;
759 next_block_ = next_block;
760 if (block->IsStartBlock()) {
761 block->UpdateEnvironment(graph_->start_environment());
763 } else if (block->predecessors()->length() == 1) {
764 // We have a single predecessor => copy environment and outgoing
765 // argument count from the predecessor.
766 DCHECK(block->phis()->length() == 0);
767 HBasicBlock* pred = block->predecessors()->at(0);
768 HEnvironment* last_environment = pred->last_environment();
769 DCHECK(last_environment != NULL);
770 // Only copy the environment, if it is later used again.
771 if (pred->end()->SecondSuccessor() == NULL) {
772 DCHECK(pred->end()->FirstSuccessor() == block);
774 if (pred->end()->FirstSuccessor()->block_id() > block->block_id() ||
775 pred->end()->SecondSuccessor()->block_id() > block->block_id()) {
776 last_environment = last_environment->Copy();
779 block->UpdateEnvironment(last_environment);
780 DCHECK(pred->argument_count() >= 0);
781 argument_count_ = pred->argument_count();
783 // We are at a state join => process phis.
784 HBasicBlock* pred = block->predecessors()->at(0);
785 // No need to copy the environment, it cannot be used later.
786 HEnvironment* last_environment = pred->last_environment();
787 for (int i = 0; i < block->phis()->length(); ++i) {
788 HPhi* phi = block->phis()->at(i);
789 if (phi->HasMergedIndex()) {
790 last_environment->SetValueAt(phi->merged_index(), phi);
793 for (int i = 0; i < block->deleted_phis()->length(); ++i) {
794 if (block->deleted_phis()->at(i) < last_environment->length()) {
795 last_environment->SetValueAt(block->deleted_phis()->at(i),
796 graph_->GetConstantUndefined());
799 block->UpdateEnvironment(last_environment);
800 // Pick up the outgoing argument count of one of the predecessors.
801 argument_count_ = pred->argument_count();
803 HInstruction* current = block->first();
804 int start = chunk_->instructions()->length();
805 while (current != NULL && !is_aborted()) {
806 // Code for constants in registers is generated lazily.
807 if (!current->EmitAtUses()) {
808 VisitInstruction(current);
810 current = current->next();
812 int end = chunk_->instructions()->length() - 1;
814 block->set_first_instruction_index(start);
815 block->set_last_instruction_index(end);
817 block->set_argument_count(argument_count_);
819 current_block_ = NULL;
823 void LChunkBuilder::VisitInstruction(HInstruction* current) {
824 HInstruction* old_current = current_instruction_;
825 current_instruction_ = current;
827 LInstruction* instr = NULL;
828 if (current->CanReplaceWithDummyUses()) {
829 if (current->OperandCount() == 0) {
830 instr = DefineAsRegister(new(zone()) LDummy());
832 DCHECK(!current->OperandAt(0)->IsControlInstruction());
833 instr = DefineAsRegister(new(zone())
834 LDummyUse(UseAny(current->OperandAt(0))));
836 for (int i = 1; i < current->OperandCount(); ++i) {
837 if (current->OperandAt(i)->IsControlInstruction()) continue;
838 LInstruction* dummy =
839 new(zone()) LDummyUse(UseAny(current->OperandAt(i)));
840 dummy->set_hydrogen_value(current);
841 chunk_->AddInstruction(dummy, current_block_);
844 HBasicBlock* successor;
845 if (current->IsControlInstruction() &&
846 HControlInstruction::cast(current)->KnownSuccessorBlock(&successor) &&
848 instr = new(zone()) LGoto(successor);
850 instr = current->CompileToLithium(this);
854 argument_count_ += current->argument_delta();
855 DCHECK(argument_count_ >= 0);
858 AddInstruction(instr, current);
861 current_instruction_ = old_current;
865 void LChunkBuilder::AddInstruction(LInstruction* instr,
866 HInstruction* hydrogen_val) {
867 // Associate the hydrogen instruction first, since we may need it for
868 // the ClobbersRegisters() or ClobbersDoubleRegisters() calls below.
869 instr->set_hydrogen_value(hydrogen_val);
872 // Make sure that the lithium instruction has either no fixed register
873 // constraints in temps or the result OR no uses that are only used at
874 // start. If this invariant doesn't hold, the register allocator can decide
875 // to insert a split of a range immediately before the instruction due to an
876 // already allocated register needing to be used for the instruction's fixed
877 // register constraint. In this case, The register allocator won't see an
878 // interference between the split child and the use-at-start (it would if
879 // the it was just a plain use), so it is free to move the split child into
880 // the same register that is used for the use-at-start.
881 // See https://code.google.com/p/chromium/issues/detail?id=201590
882 if (!(instr->ClobbersRegisters() &&
883 instr->ClobbersDoubleRegisters(isolate()))) {
885 int used_at_start = 0;
886 for (UseIterator it(instr); !it.Done(); it.Advance()) {
887 LUnallocated* operand = LUnallocated::cast(it.Current());
888 if (operand->IsUsedAtStart()) ++used_at_start;
890 if (instr->Output() != NULL) {
891 if (LUnallocated::cast(instr->Output())->HasFixedPolicy()) ++fixed;
893 for (TempIterator it(instr); !it.Done(); it.Advance()) {
894 LUnallocated* operand = LUnallocated::cast(it.Current());
895 if (operand->HasFixedPolicy()) ++fixed;
897 DCHECK(fixed == 0 || used_at_start == 0);
901 if (FLAG_stress_pointer_maps && !instr->HasPointerMap()) {
902 instr = AssignPointerMap(instr);
904 if (FLAG_stress_environments && !instr->HasEnvironment()) {
905 instr = AssignEnvironment(instr);
907 chunk_->AddInstruction(instr, current_block_);
909 if (instr->IsCall()) {
910 HValue* hydrogen_value_for_lazy_bailout = hydrogen_val;
911 LInstruction* instruction_needing_environment = NULL;
912 if (hydrogen_val->HasObservableSideEffects()) {
913 HSimulate* sim = HSimulate::cast(hydrogen_val->next());
914 instruction_needing_environment = instr;
915 sim->ReplayEnvironment(current_block_->last_environment());
916 hydrogen_value_for_lazy_bailout = sim;
918 LInstruction* bailout = AssignEnvironment(new(zone()) LLazyBailout());
919 bailout->set_hydrogen_value(hydrogen_value_for_lazy_bailout);
920 chunk_->AddInstruction(bailout, current_block_);
921 if (instruction_needing_environment != NULL) {
922 // Store the lazy deopt environment with the instruction if needed.
923 // Right now it is only used for LInstanceOfKnownGlobal.
924 instruction_needing_environment->
925 SetDeferredLazyDeoptimizationEnvironment(bailout->environment());
931 LInstruction* LChunkBuilder::DoGoto(HGoto* instr) {
932 return new(zone()) LGoto(instr->FirstSuccessor());
936 LInstruction* LChunkBuilder::DoBranch(HBranch* instr) {
937 HValue* value = instr->value();
938 Representation r = value->representation();
939 HType type = value->type();
940 ToBooleanStub::Types expected = instr->expected_input_types();
941 if (expected.IsEmpty()) expected = ToBooleanStub::Types::Generic();
943 bool easy_case = !r.IsTagged() || type.IsBoolean() || type.IsSmi() ||
944 type.IsJSArray() || type.IsHeapNumber() || type.IsString();
945 LInstruction* branch = new(zone()) LBranch(UseRegister(value));
947 ((!expected.Contains(ToBooleanStub::SMI) && expected.NeedsMap()) ||
948 !expected.IsGeneric())) {
949 branch = AssignEnvironment(branch);
955 LInstruction* LChunkBuilder::DoDebugBreak(HDebugBreak* instr) {
956 return new(zone()) LDebugBreak();
960 LInstruction* LChunkBuilder::DoCompareMap(HCompareMap* instr) {
961 DCHECK(instr->value()->representation().IsTagged());
962 LOperand* value = UseRegisterAtStart(instr->value());
963 LOperand* temp = TempRegister();
964 return new(zone()) LCmpMapAndBranch(value, temp);
968 LInstruction* LChunkBuilder::DoArgumentsLength(HArgumentsLength* instr) {
969 info()->MarkAsRequiresFrame();
970 LOperand* value = UseRegister(instr->value());
971 return DefineAsRegister(new(zone()) LArgumentsLength(value));
975 LInstruction* LChunkBuilder::DoArgumentsElements(HArgumentsElements* elems) {
976 info()->MarkAsRequiresFrame();
977 return DefineAsRegister(new(zone()) LArgumentsElements);
981 LInstruction* LChunkBuilder::DoInstanceOf(HInstanceOf* instr) {
982 LOperand* context = UseFixed(instr->context(), cp);
983 LInstanceOf* result =
984 new(zone()) LInstanceOf(context, UseFixed(instr->left(), r0),
985 UseFixed(instr->right(), r1));
986 return MarkAsCall(DefineFixed(result, r0), instr);
990 LInstruction* LChunkBuilder::DoInstanceOfKnownGlobal(
991 HInstanceOfKnownGlobal* instr) {
992 LInstanceOfKnownGlobal* result =
993 new(zone()) LInstanceOfKnownGlobal(
994 UseFixed(instr->context(), cp),
995 UseFixed(instr->left(), r0),
997 return MarkAsCall(DefineFixed(result, r0), instr);
1001 LInstruction* LChunkBuilder::DoWrapReceiver(HWrapReceiver* instr) {
1002 LOperand* receiver = UseRegisterAtStart(instr->receiver());
1003 LOperand* function = UseRegisterAtStart(instr->function());
1004 LWrapReceiver* result = new(zone()) LWrapReceiver(receiver, function);
1005 return AssignEnvironment(DefineAsRegister(result));
1009 LInstruction* LChunkBuilder::DoApplyArguments(HApplyArguments* instr) {
1010 LOperand* function = UseFixed(instr->function(), r1);
1011 LOperand* receiver = UseFixed(instr->receiver(), r0);
1012 LOperand* length = UseFixed(instr->length(), r2);
1013 LOperand* elements = UseFixed(instr->elements(), r3);
1014 LApplyArguments* result = new(zone()) LApplyArguments(function,
1018 return MarkAsCall(DefineFixed(result, r0), instr, CAN_DEOPTIMIZE_EAGERLY);
1022 LInstruction* LChunkBuilder::DoPushArguments(HPushArguments* instr) {
1023 int argc = instr->OperandCount();
1024 for (int i = 0; i < argc; ++i) {
1025 LOperand* argument = Use(instr->argument(i));
1026 AddInstruction(new(zone()) LPushArgument(argument), instr);
1032 LInstruction* LChunkBuilder::DoStoreCodeEntry(
1033 HStoreCodeEntry* store_code_entry) {
1034 LOperand* function = UseRegister(store_code_entry->function());
1035 LOperand* code_object = UseTempRegister(store_code_entry->code_object());
1036 return new(zone()) LStoreCodeEntry(function, code_object);
1040 LInstruction* LChunkBuilder::DoInnerAllocatedObject(
1041 HInnerAllocatedObject* instr) {
1042 LOperand* base_object = UseRegisterAtStart(instr->base_object());
1043 LOperand* offset = UseRegisterOrConstantAtStart(instr->offset());
1044 return DefineAsRegister(
1045 new(zone()) LInnerAllocatedObject(base_object, offset));
1049 LInstruction* LChunkBuilder::DoThisFunction(HThisFunction* instr) {
1050 return instr->HasNoUses()
1052 : DefineAsRegister(new(zone()) LThisFunction);
1056 LInstruction* LChunkBuilder::DoContext(HContext* instr) {
1057 if (instr->HasNoUses()) return NULL;
1059 if (info()->IsStub()) {
1060 return DefineFixed(new(zone()) LContext, cp);
1063 return DefineAsRegister(new(zone()) LContext);
1067 LInstruction* LChunkBuilder::DoDeclareGlobals(HDeclareGlobals* instr) {
1068 LOperand* context = UseFixed(instr->context(), cp);
1069 return MarkAsCall(new(zone()) LDeclareGlobals(context), instr);
1073 LInstruction* LChunkBuilder::DoCallJSFunction(
1074 HCallJSFunction* instr) {
1075 LOperand* function = UseFixed(instr->function(), r1);
1077 LCallJSFunction* result = new(zone()) LCallJSFunction(function);
1079 return MarkAsCall(DefineFixed(result, r0), instr);
1083 LInstruction* LChunkBuilder::DoCallWithDescriptor(
1084 HCallWithDescriptor* instr) {
1085 const InterfaceDescriptor* descriptor = instr->descriptor();
1087 LOperand* target = UseRegisterOrConstantAtStart(instr->target());
1088 ZoneList<LOperand*> ops(instr->OperandCount(), zone());
1089 ops.Add(target, zone());
1090 for (int i = 1; i < instr->OperandCount(); i++) {
1091 LOperand* op = UseFixed(instr->OperandAt(i),
1092 descriptor->GetParameterRegister(i - 1));
1093 ops.Add(op, zone());
1096 LCallWithDescriptor* result = new(zone()) LCallWithDescriptor(
1097 descriptor, ops, zone());
1098 return MarkAsCall(DefineFixed(result, r0), instr);
1102 LInstruction* LChunkBuilder::DoInvokeFunction(HInvokeFunction* instr) {
1103 LOperand* context = UseFixed(instr->context(), cp);
1104 LOperand* function = UseFixed(instr->function(), r1);
1105 LInvokeFunction* result = new(zone()) LInvokeFunction(context, function);
1106 return MarkAsCall(DefineFixed(result, r0), instr, CANNOT_DEOPTIMIZE_EAGERLY);
1110 LInstruction* LChunkBuilder::DoUnaryMathOperation(HUnaryMathOperation* instr) {
1111 switch (instr->op()) {
1113 return DoMathFloor(instr);
1115 return DoMathRound(instr);
1117 return DoMathFround(instr);
1119 return DoMathAbs(instr);
1121 return DoMathLog(instr);
1123 return DoMathExp(instr);
1125 return DoMathSqrt(instr);
1127 return DoMathPowHalf(instr);
1129 return DoMathClz32(instr);
1137 LInstruction* LChunkBuilder::DoMathFloor(HUnaryMathOperation* instr) {
1138 LOperand* input = UseRegister(instr->value());
1139 LMathFloor* result = new(zone()) LMathFloor(input);
1140 return AssignEnvironment(AssignPointerMap(DefineAsRegister(result)));
1144 LInstruction* LChunkBuilder::DoMathRound(HUnaryMathOperation* instr) {
1145 LOperand* input = UseRegister(instr->value());
1146 LOperand* temp = TempDoubleRegister();
1147 LMathRound* result = new(zone()) LMathRound(input, temp);
1148 return AssignEnvironment(DefineAsRegister(result));
1152 LInstruction* LChunkBuilder::DoMathFround(HUnaryMathOperation* instr) {
1153 LOperand* input = UseRegister(instr->value());
1154 LMathFround* result = new (zone()) LMathFround(input);
1155 return DefineAsRegister(result);
1159 LInstruction* LChunkBuilder::DoMathAbs(HUnaryMathOperation* instr) {
1160 Representation r = instr->value()->representation();
1161 LOperand* context = (r.IsDouble() || r.IsSmiOrInteger32())
1163 : UseFixed(instr->context(), cp);
1164 LOperand* input = UseRegister(instr->value());
1165 LInstruction* result =
1166 DefineAsRegister(new(zone()) LMathAbs(context, input));
1167 if (!r.IsDouble() && !r.IsSmiOrInteger32()) result = AssignPointerMap(result);
1168 if (!r.IsDouble()) result = AssignEnvironment(result);
1173 LInstruction* LChunkBuilder::DoMathLog(HUnaryMathOperation* instr) {
1174 DCHECK(instr->representation().IsDouble());
1175 DCHECK(instr->value()->representation().IsDouble());
1176 LOperand* input = UseFixedDouble(instr->value(), d0);
1177 return MarkAsCall(DefineFixedDouble(new(zone()) LMathLog(input), d0), instr);
1181 LInstruction* LChunkBuilder::DoMathClz32(HUnaryMathOperation* instr) {
1182 LOperand* input = UseRegisterAtStart(instr->value());
1183 LMathClz32* result = new(zone()) LMathClz32(input);
1184 return DefineAsRegister(result);
1188 LInstruction* LChunkBuilder::DoMathExp(HUnaryMathOperation* instr) {
1189 DCHECK(instr->representation().IsDouble());
1190 DCHECK(instr->value()->representation().IsDouble());
1191 LOperand* input = UseRegister(instr->value());
1192 LOperand* temp1 = TempRegister();
1193 LOperand* temp2 = TempRegister();
1194 LOperand* double_temp = TempDoubleRegister();
1195 LMathExp* result = new(zone()) LMathExp(input, double_temp, temp1, temp2);
1196 return DefineAsRegister(result);
1200 LInstruction* LChunkBuilder::DoMathSqrt(HUnaryMathOperation* instr) {
1201 LOperand* input = UseRegisterAtStart(instr->value());
1202 LMathSqrt* result = new(zone()) LMathSqrt(input);
1203 return DefineAsRegister(result);
1207 LInstruction* LChunkBuilder::DoMathPowHalf(HUnaryMathOperation* instr) {
1208 LOperand* input = UseRegisterAtStart(instr->value());
1209 LMathPowHalf* result = new(zone()) LMathPowHalf(input);
1210 return DefineAsRegister(result);
1214 LInstruction* LChunkBuilder::DoNullarySIMDOperation(
1215 HNullarySIMDOperation* instr) {
1221 LInstruction* LChunkBuilder::DoUnarySIMDOperation(
1222 HUnarySIMDOperation* instr) {
1228 LInstruction* LChunkBuilder::DoBinarySIMDOperation(
1229 HBinarySIMDOperation* instr) {
1235 LInstruction* LChunkBuilder::DoTernarySIMDOperation(
1236 HTernarySIMDOperation* instr) {
1242 LInstruction* LChunkBuilder::DoQuarternarySIMDOperation(
1243 HQuarternarySIMDOperation* instr) {
1249 LInstruction* LChunkBuilder::DoCallNew(HCallNew* instr) {
1250 LOperand* context = UseFixed(instr->context(), cp);
1251 LOperand* constructor = UseFixed(instr->constructor(), r1);
1252 LCallNew* result = new(zone()) LCallNew(context, constructor);
1253 return MarkAsCall(DefineFixed(result, r0), instr);
1257 LInstruction* LChunkBuilder::DoCallNewArray(HCallNewArray* instr) {
1258 LOperand* context = UseFixed(instr->context(), cp);
1259 LOperand* constructor = UseFixed(instr->constructor(), r1);
1260 LCallNewArray* result = new(zone()) LCallNewArray(context, constructor);
1261 return MarkAsCall(DefineFixed(result, r0), instr);
1265 LInstruction* LChunkBuilder::DoCallFunction(HCallFunction* instr) {
1266 LOperand* context = UseFixed(instr->context(), cp);
1267 LOperand* function = UseFixed(instr->function(), r1);
1268 LCallFunction* call = new(zone()) LCallFunction(context, function);
1269 return MarkAsCall(DefineFixed(call, r0), instr);
1273 LInstruction* LChunkBuilder::DoCallRuntime(HCallRuntime* instr) {
1274 LOperand* context = UseFixed(instr->context(), cp);
1275 return MarkAsCall(DefineFixed(new(zone()) LCallRuntime(context), r0), instr);
1279 LInstruction* LChunkBuilder::DoRor(HRor* instr) {
1280 return DoShift(Token::ROR, instr);
1284 LInstruction* LChunkBuilder::DoShr(HShr* instr) {
1285 return DoShift(Token::SHR, instr);
1289 LInstruction* LChunkBuilder::DoSar(HSar* instr) {
1290 return DoShift(Token::SAR, instr);
1294 LInstruction* LChunkBuilder::DoShl(HShl* instr) {
1295 return DoShift(Token::SHL, instr);
1299 LInstruction* LChunkBuilder::DoBitwise(HBitwise* instr) {
1300 if (instr->representation().IsSmiOrInteger32()) {
1301 DCHECK(instr->left()->representation().Equals(instr->representation()));
1302 DCHECK(instr->right()->representation().Equals(instr->representation()));
1303 DCHECK(instr->CheckFlag(HValue::kTruncatingToInt32));
1305 LOperand* left = UseRegisterAtStart(instr->BetterLeftOperand());
1306 LOperand* right = UseOrConstantAtStart(instr->BetterRightOperand());
1307 return DefineAsRegister(new(zone()) LBitI(left, right));
1309 return DoArithmeticT(instr->op(), instr);
1314 LInstruction* LChunkBuilder::DoDivByPowerOf2I(HDiv* instr) {
1315 DCHECK(instr->representation().IsSmiOrInteger32());
1316 DCHECK(instr->left()->representation().Equals(instr->representation()));
1317 DCHECK(instr->right()->representation().Equals(instr->representation()));
1318 LOperand* dividend = UseRegister(instr->left());
1319 int32_t divisor = instr->right()->GetInteger32Constant();
1320 LInstruction* result = DefineAsRegister(new(zone()) LDivByPowerOf2I(
1321 dividend, divisor));
1322 if ((instr->CheckFlag(HValue::kBailoutOnMinusZero) && divisor < 0) ||
1323 (instr->CheckFlag(HValue::kCanOverflow) && divisor == -1) ||
1324 (!instr->CheckFlag(HInstruction::kAllUsesTruncatingToInt32) &&
1325 divisor != 1 && divisor != -1)) {
1326 result = AssignEnvironment(result);
1332 LInstruction* LChunkBuilder::DoDivByConstI(HDiv* instr) {
1333 DCHECK(instr->representation().IsInteger32());
1334 DCHECK(instr->left()->representation().Equals(instr->representation()));
1335 DCHECK(instr->right()->representation().Equals(instr->representation()));
1336 LOperand* dividend = UseRegister(instr->left());
1337 int32_t divisor = instr->right()->GetInteger32Constant();
1338 LInstruction* result = DefineAsRegister(new(zone()) LDivByConstI(
1339 dividend, divisor));
1341 (instr->CheckFlag(HValue::kBailoutOnMinusZero) && divisor < 0) ||
1342 !instr->CheckFlag(HInstruction::kAllUsesTruncatingToInt32)) {
1343 result = AssignEnvironment(result);
1349 LInstruction* LChunkBuilder::DoDivI(HDiv* instr) {
1350 DCHECK(instr->representation().IsSmiOrInteger32());
1351 DCHECK(instr->left()->representation().Equals(instr->representation()));
1352 DCHECK(instr->right()->representation().Equals(instr->representation()));
1353 LOperand* dividend = UseRegister(instr->left());
1354 LOperand* divisor = UseRegister(instr->right());
1356 CpuFeatures::IsSupported(SUDIV) ? NULL : TempDoubleRegister();
1357 LInstruction* result =
1358 DefineAsRegister(new(zone()) LDivI(dividend, divisor, temp));
1359 if (instr->CheckFlag(HValue::kCanBeDivByZero) ||
1360 instr->CheckFlag(HValue::kBailoutOnMinusZero) ||
1361 (instr->CheckFlag(HValue::kCanOverflow) &&
1362 (!CpuFeatures::IsSupported(SUDIV) ||
1363 !instr->CheckFlag(HValue::kAllUsesTruncatingToInt32))) ||
1364 (!instr->IsMathFloorOfDiv() &&
1365 !instr->CheckFlag(HValue::kAllUsesTruncatingToInt32))) {
1366 result = AssignEnvironment(result);
1372 LInstruction* LChunkBuilder::DoDiv(HDiv* instr) {
1373 if (instr->representation().IsSmiOrInteger32()) {
1374 if (instr->RightIsPowerOf2()) {
1375 return DoDivByPowerOf2I(instr);
1376 } else if (instr->right()->IsConstant()) {
1377 return DoDivByConstI(instr);
1379 return DoDivI(instr);
1381 } else if (instr->representation().IsDouble()) {
1382 return DoArithmeticD(Token::DIV, instr);
1384 return DoArithmeticT(Token::DIV, instr);
1389 LInstruction* LChunkBuilder::DoFlooringDivByPowerOf2I(HMathFloorOfDiv* instr) {
1390 LOperand* dividend = UseRegisterAtStart(instr->left());
1391 int32_t divisor = instr->right()->GetInteger32Constant();
1392 LInstruction* result = DefineAsRegister(new(zone()) LFlooringDivByPowerOf2I(
1393 dividend, divisor));
1394 if ((instr->CheckFlag(HValue::kBailoutOnMinusZero) && divisor < 0) ||
1395 (instr->CheckFlag(HValue::kLeftCanBeMinInt) && divisor == -1)) {
1396 result = AssignEnvironment(result);
1402 LInstruction* LChunkBuilder::DoFlooringDivByConstI(HMathFloorOfDiv* instr) {
1403 DCHECK(instr->representation().IsInteger32());
1404 DCHECK(instr->left()->representation().Equals(instr->representation()));
1405 DCHECK(instr->right()->representation().Equals(instr->representation()));
1406 LOperand* dividend = UseRegister(instr->left());
1407 int32_t divisor = instr->right()->GetInteger32Constant();
1409 ((divisor > 0 && !instr->CheckFlag(HValue::kLeftCanBeNegative)) ||
1410 (divisor < 0 && !instr->CheckFlag(HValue::kLeftCanBePositive))) ?
1411 NULL : TempRegister();
1412 LInstruction* result = DefineAsRegister(
1413 new(zone()) LFlooringDivByConstI(dividend, divisor, temp));
1415 (instr->CheckFlag(HValue::kBailoutOnMinusZero) && divisor < 0)) {
1416 result = AssignEnvironment(result);
1422 LInstruction* LChunkBuilder::DoFlooringDivI(HMathFloorOfDiv* instr) {
1423 DCHECK(instr->representation().IsSmiOrInteger32());
1424 DCHECK(instr->left()->representation().Equals(instr->representation()));
1425 DCHECK(instr->right()->representation().Equals(instr->representation()));
1426 LOperand* dividend = UseRegister(instr->left());
1427 LOperand* divisor = UseRegister(instr->right());
1429 CpuFeatures::IsSupported(SUDIV) ? NULL : TempDoubleRegister();
1430 LFlooringDivI* div = new(zone()) LFlooringDivI(dividend, divisor, temp);
1431 return AssignEnvironment(DefineAsRegister(div));
1435 LInstruction* LChunkBuilder::DoMathFloorOfDiv(HMathFloorOfDiv* instr) {
1436 if (instr->RightIsPowerOf2()) {
1437 return DoFlooringDivByPowerOf2I(instr);
1438 } else if (instr->right()->IsConstant()) {
1439 return DoFlooringDivByConstI(instr);
1441 return DoFlooringDivI(instr);
1446 LInstruction* LChunkBuilder::DoModByPowerOf2I(HMod* instr) {
1447 DCHECK(instr->representation().IsSmiOrInteger32());
1448 DCHECK(instr->left()->representation().Equals(instr->representation()));
1449 DCHECK(instr->right()->representation().Equals(instr->representation()));
1450 LOperand* dividend = UseRegisterAtStart(instr->left());
1451 int32_t divisor = instr->right()->GetInteger32Constant();
1452 LInstruction* result = DefineSameAsFirst(new(zone()) LModByPowerOf2I(
1453 dividend, divisor));
1454 if (instr->CheckFlag(HValue::kLeftCanBeNegative) &&
1455 instr->CheckFlag(HValue::kBailoutOnMinusZero)) {
1456 result = AssignEnvironment(result);
1462 LInstruction* LChunkBuilder::DoModByConstI(HMod* instr) {
1463 DCHECK(instr->representation().IsSmiOrInteger32());
1464 DCHECK(instr->left()->representation().Equals(instr->representation()));
1465 DCHECK(instr->right()->representation().Equals(instr->representation()));
1466 LOperand* dividend = UseRegister(instr->left());
1467 int32_t divisor = instr->right()->GetInteger32Constant();
1468 LInstruction* result = DefineAsRegister(new(zone()) LModByConstI(
1469 dividend, divisor));
1470 if (divisor == 0 || instr->CheckFlag(HValue::kBailoutOnMinusZero)) {
1471 result = AssignEnvironment(result);
1477 LInstruction* LChunkBuilder::DoModI(HMod* instr) {
1478 DCHECK(instr->representation().IsSmiOrInteger32());
1479 DCHECK(instr->left()->representation().Equals(instr->representation()));
1480 DCHECK(instr->right()->representation().Equals(instr->representation()));
1481 LOperand* dividend = UseRegister(instr->left());
1482 LOperand* divisor = UseRegister(instr->right());
1484 CpuFeatures::IsSupported(SUDIV) ? NULL : TempDoubleRegister();
1486 CpuFeatures::IsSupported(SUDIV) ? NULL : TempDoubleRegister();
1487 LInstruction* result = DefineAsRegister(new(zone()) LModI(
1488 dividend, divisor, temp, temp2));
1489 if (instr->CheckFlag(HValue::kCanBeDivByZero) ||
1490 instr->CheckFlag(HValue::kBailoutOnMinusZero)) {
1491 result = AssignEnvironment(result);
1497 LInstruction* LChunkBuilder::DoMod(HMod* instr) {
1498 if (instr->representation().IsSmiOrInteger32()) {
1499 if (instr->RightIsPowerOf2()) {
1500 return DoModByPowerOf2I(instr);
1501 } else if (instr->right()->IsConstant()) {
1502 return DoModByConstI(instr);
1504 return DoModI(instr);
1506 } else if (instr->representation().IsDouble()) {
1507 return DoArithmeticD(Token::MOD, instr);
1509 return DoArithmeticT(Token::MOD, instr);
1514 LInstruction* LChunkBuilder::DoMul(HMul* instr) {
1515 if (instr->representation().IsSmiOrInteger32()) {
1516 DCHECK(instr->left()->representation().Equals(instr->representation()));
1517 DCHECK(instr->right()->representation().Equals(instr->representation()));
1518 HValue* left = instr->BetterLeftOperand();
1519 HValue* right = instr->BetterRightOperand();
1522 bool can_overflow = instr->CheckFlag(HValue::kCanOverflow);
1523 bool bailout_on_minus_zero = instr->CheckFlag(HValue::kBailoutOnMinusZero);
1525 if (right->IsConstant()) {
1526 HConstant* constant = HConstant::cast(right);
1527 int32_t constant_value = constant->Integer32Value();
1528 // Constants -1, 0 and 1 can be optimized if the result can overflow.
1529 // For other constants, it can be optimized only without overflow.
1530 if (!can_overflow || ((constant_value >= -1) && (constant_value <= 1))) {
1531 left_op = UseRegisterAtStart(left);
1532 right_op = UseConstant(right);
1534 if (bailout_on_minus_zero) {
1535 left_op = UseRegister(left);
1537 left_op = UseRegisterAtStart(left);
1539 right_op = UseRegister(right);
1542 if (bailout_on_minus_zero) {
1543 left_op = UseRegister(left);
1545 left_op = UseRegisterAtStart(left);
1547 right_op = UseRegister(right);
1549 LMulI* mul = new(zone()) LMulI(left_op, right_op);
1550 if (can_overflow || bailout_on_minus_zero) {
1551 AssignEnvironment(mul);
1553 return DefineAsRegister(mul);
1555 } else if (instr->representation().IsDouble()) {
1556 if (instr->HasOneUse() && (instr->uses().value()->IsAdd() ||
1557 instr->uses().value()->IsSub())) {
1558 HBinaryOperation* use = HBinaryOperation::cast(instr->uses().value());
1560 if (use->IsAdd() && instr == use->left()) {
1561 // This mul is the lhs of an add. The add and mul will be folded into a
1562 // multiply-add in DoAdd.
1565 if (instr == use->right() && use->IsAdd() && !use->left()->IsMul()) {
1566 // This mul is the rhs of an add, where the lhs is not another mul.
1567 // The add and mul will be folded into a multiply-add in DoAdd.
1570 if (instr == use->right() && use->IsSub()) {
1571 // This mul is the rhs of a sub. The sub and mul will be folded into a
1572 // multiply-sub in DoSub.
1577 return DoArithmeticD(Token::MUL, instr);
1579 return DoArithmeticT(Token::MUL, instr);
1584 LInstruction* LChunkBuilder::DoSub(HSub* instr) {
1585 if (instr->representation().IsSmiOrInteger32()) {
1586 DCHECK(instr->left()->representation().Equals(instr->representation()));
1587 DCHECK(instr->right()->representation().Equals(instr->representation()));
1589 if (instr->left()->IsConstant()) {
1590 // If lhs is constant, do reverse subtraction instead.
1591 return DoRSub(instr);
1594 LOperand* left = UseRegisterAtStart(instr->left());
1595 LOperand* right = UseOrConstantAtStart(instr->right());
1596 LSubI* sub = new(zone()) LSubI(left, right);
1597 LInstruction* result = DefineAsRegister(sub);
1598 if (instr->CheckFlag(HValue::kCanOverflow)) {
1599 result = AssignEnvironment(result);
1602 } else if (instr->representation().IsDouble()) {
1603 if (instr->right()->IsMul() && instr->right()->HasOneUse()) {
1604 return DoMultiplySub(instr->left(), HMul::cast(instr->right()));
1607 return DoArithmeticD(Token::SUB, instr);
1609 return DoArithmeticT(Token::SUB, instr);
1614 LInstruction* LChunkBuilder::DoRSub(HSub* instr) {
1615 DCHECK(instr->representation().IsSmiOrInteger32());
1616 DCHECK(instr->left()->representation().Equals(instr->representation()));
1617 DCHECK(instr->right()->representation().Equals(instr->representation()));
1619 // Note: The lhs of the subtraction becomes the rhs of the
1620 // reverse-subtraction.
1621 LOperand* left = UseRegisterAtStart(instr->right());
1622 LOperand* right = UseOrConstantAtStart(instr->left());
1623 LRSubI* rsb = new(zone()) LRSubI(left, right);
1624 LInstruction* result = DefineAsRegister(rsb);
1625 if (instr->CheckFlag(HValue::kCanOverflow)) {
1626 result = AssignEnvironment(result);
1632 LInstruction* LChunkBuilder::DoMultiplyAdd(HMul* mul, HValue* addend) {
1633 LOperand* multiplier_op = UseRegisterAtStart(mul->left());
1634 LOperand* multiplicand_op = UseRegisterAtStart(mul->right());
1635 LOperand* addend_op = UseRegisterAtStart(addend);
1636 return DefineSameAsFirst(new(zone()) LMultiplyAddD(addend_op, multiplier_op,
1641 LInstruction* LChunkBuilder::DoMultiplySub(HValue* minuend, HMul* mul) {
1642 LOperand* minuend_op = UseRegisterAtStart(minuend);
1643 LOperand* multiplier_op = UseRegisterAtStart(mul->left());
1644 LOperand* multiplicand_op = UseRegisterAtStart(mul->right());
1646 return DefineSameAsFirst(new(zone()) LMultiplySubD(minuend_op,
1652 LInstruction* LChunkBuilder::DoAdd(HAdd* instr) {
1653 if (instr->representation().IsSmiOrInteger32()) {
1654 DCHECK(instr->left()->representation().Equals(instr->representation()));
1655 DCHECK(instr->right()->representation().Equals(instr->representation()));
1656 LOperand* left = UseRegisterAtStart(instr->BetterLeftOperand());
1657 LOperand* right = UseOrConstantAtStart(instr->BetterRightOperand());
1658 LAddI* add = new(zone()) LAddI(left, right);
1659 LInstruction* result = DefineAsRegister(add);
1660 if (instr->CheckFlag(HValue::kCanOverflow)) {
1661 result = AssignEnvironment(result);
1664 } else if (instr->representation().IsExternal()) {
1665 DCHECK(instr->left()->representation().IsExternal());
1666 DCHECK(instr->right()->representation().IsInteger32());
1667 DCHECK(!instr->CheckFlag(HValue::kCanOverflow));
1668 LOperand* left = UseRegisterAtStart(instr->left());
1669 LOperand* right = UseOrConstantAtStart(instr->right());
1670 LAddI* add = new(zone()) LAddI(left, right);
1671 LInstruction* result = DefineAsRegister(add);
1673 } else if (instr->representation().IsDouble()) {
1674 if (instr->left()->IsMul() && instr->left()->HasOneUse()) {
1675 return DoMultiplyAdd(HMul::cast(instr->left()), instr->right());
1678 if (instr->right()->IsMul() && instr->right()->HasOneUse()) {
1679 DCHECK(!instr->left()->IsMul() || !instr->left()->HasOneUse());
1680 return DoMultiplyAdd(HMul::cast(instr->right()), instr->left());
1683 return DoArithmeticD(Token::ADD, instr);
1685 return DoArithmeticT(Token::ADD, instr);
1690 LInstruction* LChunkBuilder::DoMathMinMax(HMathMinMax* instr) {
1691 LOperand* left = NULL;
1692 LOperand* right = NULL;
1693 if (instr->representation().IsSmiOrInteger32()) {
1694 DCHECK(instr->left()->representation().Equals(instr->representation()));
1695 DCHECK(instr->right()->representation().Equals(instr->representation()));
1696 left = UseRegisterAtStart(instr->BetterLeftOperand());
1697 right = UseOrConstantAtStart(instr->BetterRightOperand());
1699 DCHECK(instr->representation().IsDouble());
1700 DCHECK(instr->left()->representation().IsDouble());
1701 DCHECK(instr->right()->representation().IsDouble());
1702 left = UseRegisterAtStart(instr->left());
1703 right = UseRegisterAtStart(instr->right());
1705 return DefineAsRegister(new(zone()) LMathMinMax(left, right));
1709 LInstruction* LChunkBuilder::DoPower(HPower* instr) {
1710 DCHECK(instr->representation().IsDouble());
1711 // We call a C function for double power. It can't trigger a GC.
1712 // We need to use fixed result register for the call.
1713 Representation exponent_type = instr->right()->representation();
1714 DCHECK(instr->left()->representation().IsDouble());
1715 LOperand* left = UseFixedDouble(instr->left(), d0);
1716 LOperand* right = exponent_type.IsDouble() ?
1717 UseFixedDouble(instr->right(), d1) :
1718 UseFixed(instr->right(), r2);
1719 LPower* result = new(zone()) LPower(left, right);
1720 return MarkAsCall(DefineFixedDouble(result, d2),
1722 CAN_DEOPTIMIZE_EAGERLY);
1726 LInstruction* LChunkBuilder::DoCompareGeneric(HCompareGeneric* instr) {
1727 DCHECK(instr->left()->representation().IsTagged());
1728 DCHECK(instr->right()->representation().IsTagged());
1729 LOperand* context = UseFixed(instr->context(), cp);
1730 LOperand* left = UseFixed(instr->left(), r1);
1731 LOperand* right = UseFixed(instr->right(), r0);
1732 LCmpT* result = new(zone()) LCmpT(context, left, right);
1733 return MarkAsCall(DefineFixed(result, r0), instr);
1737 LInstruction* LChunkBuilder::DoCompareNumericAndBranch(
1738 HCompareNumericAndBranch* instr) {
1739 Representation r = instr->representation();
1740 if (r.IsSmiOrInteger32()) {
1741 DCHECK(instr->left()->representation().Equals(r));
1742 DCHECK(instr->right()->representation().Equals(r));
1743 LOperand* left = UseRegisterOrConstantAtStart(instr->left());
1744 LOperand* right = UseRegisterOrConstantAtStart(instr->right());
1745 return new(zone()) LCompareNumericAndBranch(left, right);
1747 DCHECK(r.IsDouble());
1748 DCHECK(instr->left()->representation().IsDouble());
1749 DCHECK(instr->right()->representation().IsDouble());
1750 LOperand* left = UseRegisterAtStart(instr->left());
1751 LOperand* right = UseRegisterAtStart(instr->right());
1752 return new(zone()) LCompareNumericAndBranch(left, right);
1757 LInstruction* LChunkBuilder::DoCompareObjectEqAndBranch(
1758 HCompareObjectEqAndBranch* instr) {
1759 LOperand* left = UseRegisterAtStart(instr->left());
1760 LOperand* right = UseRegisterAtStart(instr->right());
1761 return new(zone()) LCmpObjectEqAndBranch(left, right);
1765 LInstruction* LChunkBuilder::DoCompareHoleAndBranch(
1766 HCompareHoleAndBranch* instr) {
1767 LOperand* value = UseRegisterAtStart(instr->value());
1768 return new(zone()) LCmpHoleAndBranch(value);
1772 LInstruction* LChunkBuilder::DoCompareMinusZeroAndBranch(
1773 HCompareMinusZeroAndBranch* instr) {
1774 LOperand* value = UseRegister(instr->value());
1775 LOperand* scratch = TempRegister();
1776 return new(zone()) LCompareMinusZeroAndBranch(value, scratch);
1780 LInstruction* LChunkBuilder::DoIsObjectAndBranch(HIsObjectAndBranch* instr) {
1781 DCHECK(instr->value()->representation().IsTagged());
1782 LOperand* value = UseRegisterAtStart(instr->value());
1783 LOperand* temp = TempRegister();
1784 return new(zone()) LIsObjectAndBranch(value, temp);
1788 LInstruction* LChunkBuilder::DoIsStringAndBranch(HIsStringAndBranch* instr) {
1789 DCHECK(instr->value()->representation().IsTagged());
1790 LOperand* value = UseRegisterAtStart(instr->value());
1791 LOperand* temp = TempRegister();
1792 return new(zone()) LIsStringAndBranch(value, temp);
1796 LInstruction* LChunkBuilder::DoIsSmiAndBranch(HIsSmiAndBranch* instr) {
1797 DCHECK(instr->value()->representation().IsTagged());
1798 return new(zone()) LIsSmiAndBranch(Use(instr->value()));
1802 LInstruction* LChunkBuilder::DoIsUndetectableAndBranch(
1803 HIsUndetectableAndBranch* instr) {
1804 DCHECK(instr->value()->representation().IsTagged());
1805 LOperand* value = UseRegisterAtStart(instr->value());
1806 return new(zone()) LIsUndetectableAndBranch(value, TempRegister());
1810 LInstruction* LChunkBuilder::DoStringCompareAndBranch(
1811 HStringCompareAndBranch* instr) {
1812 DCHECK(instr->left()->representation().IsTagged());
1813 DCHECK(instr->right()->representation().IsTagged());
1814 LOperand* context = UseFixed(instr->context(), cp);
1815 LOperand* left = UseFixed(instr->left(), r1);
1816 LOperand* right = UseFixed(instr->right(), r0);
1817 LStringCompareAndBranch* result =
1818 new(zone()) LStringCompareAndBranch(context, left, right);
1819 return MarkAsCall(result, instr);
1823 LInstruction* LChunkBuilder::DoHasInstanceTypeAndBranch(
1824 HHasInstanceTypeAndBranch* instr) {
1825 DCHECK(instr->value()->representation().IsTagged());
1826 LOperand* value = UseRegisterAtStart(instr->value());
1827 return new(zone()) LHasInstanceTypeAndBranch(value);
1831 LInstruction* LChunkBuilder::DoGetCachedArrayIndex(
1832 HGetCachedArrayIndex* instr) {
1833 DCHECK(instr->value()->representation().IsTagged());
1834 LOperand* value = UseRegisterAtStart(instr->value());
1836 return DefineAsRegister(new(zone()) LGetCachedArrayIndex(value));
1840 LInstruction* LChunkBuilder::DoHasCachedArrayIndexAndBranch(
1841 HHasCachedArrayIndexAndBranch* instr) {
1842 DCHECK(instr->value()->representation().IsTagged());
1843 return new(zone()) LHasCachedArrayIndexAndBranch(
1844 UseRegisterAtStart(instr->value()));
1848 LInstruction* LChunkBuilder::DoClassOfTestAndBranch(
1849 HClassOfTestAndBranch* instr) {
1850 DCHECK(instr->value()->representation().IsTagged());
1851 LOperand* value = UseRegister(instr->value());
1852 return new(zone()) LClassOfTestAndBranch(value, TempRegister());
1856 LInstruction* LChunkBuilder::DoMapEnumLength(HMapEnumLength* instr) {
1857 LOperand* map = UseRegisterAtStart(instr->value());
1858 return DefineAsRegister(new(zone()) LMapEnumLength(map));
1862 LInstruction* LChunkBuilder::DoDateField(HDateField* instr) {
1863 LOperand* object = UseFixed(instr->value(), r0);
1864 LDateField* result =
1865 new(zone()) LDateField(object, FixedTemp(r1), instr->index());
1866 return MarkAsCall(DefineFixed(result, r0), instr, CAN_DEOPTIMIZE_EAGERLY);
1870 LInstruction* LChunkBuilder::DoSeqStringGetChar(HSeqStringGetChar* instr) {
1871 LOperand* string = UseRegisterAtStart(instr->string());
1872 LOperand* index = UseRegisterOrConstantAtStart(instr->index());
1873 return DefineAsRegister(new(zone()) LSeqStringGetChar(string, index));
1877 LInstruction* LChunkBuilder::DoSeqStringSetChar(HSeqStringSetChar* instr) {
1878 LOperand* string = UseRegisterAtStart(instr->string());
1879 LOperand* index = FLAG_debug_code
1880 ? UseRegisterAtStart(instr->index())
1881 : UseRegisterOrConstantAtStart(instr->index());
1882 LOperand* value = UseRegisterAtStart(instr->value());
1883 LOperand* context = FLAG_debug_code ? UseFixed(instr->context(), cp) : NULL;
1884 return new(zone()) LSeqStringSetChar(context, string, index, value);
1888 LInstruction* LChunkBuilder::DoBoundsCheck(HBoundsCheck* instr) {
1889 if (!FLAG_debug_code && instr->skip_check()) return NULL;
1890 LOperand* index = UseRegisterOrConstantAtStart(instr->index());
1891 LOperand* length = !index->IsConstantOperand()
1892 ? UseRegisterOrConstantAtStart(instr->length())
1893 : UseRegisterAtStart(instr->length());
1894 LInstruction* result = new(zone()) LBoundsCheck(index, length);
1895 if (!FLAG_debug_code || !instr->skip_check()) {
1896 result = AssignEnvironment(result);
1902 LInstruction* LChunkBuilder::DoBoundsCheckBaseIndexInformation(
1903 HBoundsCheckBaseIndexInformation* instr) {
1909 LInstruction* LChunkBuilder::DoAbnormalExit(HAbnormalExit* instr) {
1910 // The control instruction marking the end of a block that completed
1911 // abruptly (e.g., threw an exception). There is nothing specific to do.
1916 LInstruction* LChunkBuilder::DoUseConst(HUseConst* instr) {
1921 LInstruction* LChunkBuilder::DoForceRepresentation(HForceRepresentation* bad) {
1922 // All HForceRepresentation instructions should be eliminated in the
1923 // representation change phase of Hydrogen.
1929 LInstruction* LChunkBuilder::DoChange(HChange* instr) {
1930 Representation from = instr->from();
1931 Representation to = instr->to();
1932 HValue* val = instr->value();
1934 if (to.IsTagged()) {
1935 LOperand* value = UseRegister(val);
1936 return DefineSameAsFirst(new(zone()) LDummyUse(value));
1938 from = Representation::Tagged();
1940 if (from.IsTagged()) {
1941 if (to.IsDouble()) {
1942 LOperand* value = UseRegister(val);
1943 LInstruction* result = DefineAsRegister(new(zone()) LNumberUntagD(value));
1944 if (!val->representation().IsSmi()) result = AssignEnvironment(result);
1946 } else if (to.IsSmi()) {
1947 LOperand* value = UseRegister(val);
1948 if (val->type().IsSmi()) {
1949 return DefineSameAsFirst(new(zone()) LDummyUse(value));
1951 return AssignEnvironment(DefineSameAsFirst(new(zone()) LCheckSmi(value)));
1953 DCHECK(to.IsInteger32());
1954 if (val->type().IsSmi() || val->representation().IsSmi()) {
1955 LOperand* value = UseRegisterAtStart(val);
1956 return DefineAsRegister(new(zone()) LSmiUntag(value, false));
1958 LOperand* value = UseRegister(val);
1959 LOperand* temp1 = TempRegister();
1960 LOperand* temp2 = TempDoubleRegister();
1961 LInstruction* result =
1962 DefineSameAsFirst(new(zone()) LTaggedToI(value, temp1, temp2));
1963 if (!val->representation().IsSmi()) result = AssignEnvironment(result);
1967 } else if (from.IsDouble()) {
1968 if (to.IsTagged()) {
1969 info()->MarkAsDeferredCalling();
1970 LOperand* value = UseRegister(val);
1971 LOperand* temp1 = TempRegister();
1972 LOperand* temp2 = TempRegister();
1973 LUnallocated* result_temp = TempRegister();
1974 LNumberTagD* result = new(zone()) LNumberTagD(value, temp1, temp2);
1975 return AssignPointerMap(Define(result, result_temp));
1976 } else if (to.IsSmi()) {
1977 LOperand* value = UseRegister(val);
1978 return AssignEnvironment(
1979 DefineAsRegister(new(zone()) LDoubleToSmi(value)));
1981 DCHECK(to.IsInteger32());
1982 LOperand* value = UseRegister(val);
1983 LInstruction* result = DefineAsRegister(new(zone()) LDoubleToI(value));
1984 if (!instr->CanTruncateToInt32()) result = AssignEnvironment(result);
1987 } else if (from.IsInteger32()) {
1988 info()->MarkAsDeferredCalling();
1989 if (to.IsTagged()) {
1990 if (!instr->CheckFlag(HValue::kCanOverflow)) {
1991 LOperand* value = UseRegisterAtStart(val);
1992 return DefineAsRegister(new(zone()) LSmiTag(value));
1993 } else if (val->CheckFlag(HInstruction::kUint32)) {
1994 LOperand* value = UseRegisterAtStart(val);
1995 LOperand* temp1 = TempRegister();
1996 LOperand* temp2 = TempRegister();
1997 LNumberTagU* result = new(zone()) LNumberTagU(value, temp1, temp2);
1998 return AssignPointerMap(DefineAsRegister(result));
2000 LOperand* value = UseRegisterAtStart(val);
2001 LOperand* temp1 = TempRegister();
2002 LOperand* temp2 = TempRegister();
2003 LNumberTagI* result = new(zone()) LNumberTagI(value, temp1, temp2);
2004 return AssignPointerMap(DefineAsRegister(result));
2006 } else if (to.IsSmi()) {
2007 LOperand* value = UseRegister(val);
2008 LInstruction* result = DefineAsRegister(new(zone()) LSmiTag(value));
2009 if (instr->CheckFlag(HValue::kCanOverflow)) {
2010 result = AssignEnvironment(result);
2014 DCHECK(to.IsDouble());
2015 if (val->CheckFlag(HInstruction::kUint32)) {
2016 return DefineAsRegister(new(zone()) LUint32ToDouble(UseRegister(val)));
2018 return DefineAsRegister(new(zone()) LInteger32ToDouble(Use(val)));
2027 LInstruction* LChunkBuilder::DoCheckHeapObject(HCheckHeapObject* instr) {
2028 LOperand* value = UseRegisterAtStart(instr->value());
2029 LInstruction* result = new(zone()) LCheckNonSmi(value);
2030 if (!instr->value()->type().IsHeapObject()) {
2031 result = AssignEnvironment(result);
2037 LInstruction* LChunkBuilder::DoCheckSmi(HCheckSmi* instr) {
2038 LOperand* value = UseRegisterAtStart(instr->value());
2039 return AssignEnvironment(new(zone()) LCheckSmi(value));
2043 LInstruction* LChunkBuilder::DoCheckInstanceType(HCheckInstanceType* instr) {
2044 LOperand* value = UseRegisterAtStart(instr->value());
2045 LInstruction* result = new(zone()) LCheckInstanceType(value);
2046 return AssignEnvironment(result);
2050 LInstruction* LChunkBuilder::DoCheckValue(HCheckValue* instr) {
2051 LOperand* value = UseRegisterAtStart(instr->value());
2052 return AssignEnvironment(new(zone()) LCheckValue(value));
2056 LInstruction* LChunkBuilder::DoCheckMaps(HCheckMaps* instr) {
2057 if (instr->IsStabilityCheck()) return new(zone()) LCheckMaps;
2058 LOperand* value = UseRegisterAtStart(instr->value());
2059 LInstruction* result = AssignEnvironment(new(zone()) LCheckMaps(value));
2060 if (instr->HasMigrationTarget()) {
2061 info()->MarkAsDeferredCalling();
2062 result = AssignPointerMap(result);
2068 LInstruction* LChunkBuilder::DoClampToUint8(HClampToUint8* instr) {
2069 HValue* value = instr->value();
2070 Representation input_rep = value->representation();
2071 LOperand* reg = UseRegister(value);
2072 if (input_rep.IsDouble()) {
2073 return DefineAsRegister(new(zone()) LClampDToUint8(reg));
2074 } else if (input_rep.IsInteger32()) {
2075 return DefineAsRegister(new(zone()) LClampIToUint8(reg));
2077 DCHECK(input_rep.IsSmiOrTagged());
2078 // Register allocator doesn't (yet) support allocation of double
2079 // temps. Reserve d1 explicitly.
2080 LClampTToUint8* result =
2081 new(zone()) LClampTToUint8(reg, TempDoubleRegister());
2082 return AssignEnvironment(DefineAsRegister(result));
2087 LInstruction* LChunkBuilder::DoDoubleBits(HDoubleBits* instr) {
2088 HValue* value = instr->value();
2089 DCHECK(value->representation().IsDouble());
2090 return DefineAsRegister(new(zone()) LDoubleBits(UseRegister(value)));
2094 LInstruction* LChunkBuilder::DoConstructDouble(HConstructDouble* instr) {
2095 LOperand* lo = UseRegister(instr->lo());
2096 LOperand* hi = UseRegister(instr->hi());
2097 return DefineAsRegister(new(zone()) LConstructDouble(hi, lo));
2101 LInstruction* LChunkBuilder::DoReturn(HReturn* instr) {
2102 LOperand* context = info()->IsStub()
2103 ? UseFixed(instr->context(), cp)
2105 LOperand* parameter_count = UseRegisterOrConstant(instr->parameter_count());
2106 return new(zone()) LReturn(UseFixed(instr->value(), r0), context,
2111 LInstruction* LChunkBuilder::DoConstant(HConstant* instr) {
2112 Representation r = instr->representation();
2114 return DefineAsRegister(new(zone()) LConstantS);
2115 } else if (r.IsInteger32()) {
2116 return DefineAsRegister(new(zone()) LConstantI);
2117 } else if (r.IsDouble()) {
2118 return DefineAsRegister(new(zone()) LConstantD);
2119 } else if (r.IsExternal()) {
2120 return DefineAsRegister(new(zone()) LConstantE);
2121 } else if (r.IsTagged()) {
2122 return DefineAsRegister(new(zone()) LConstantT);
2130 LInstruction* LChunkBuilder::DoLoadGlobalCell(HLoadGlobalCell* instr) {
2131 LLoadGlobalCell* result = new(zone()) LLoadGlobalCell;
2132 return instr->RequiresHoleCheck()
2133 ? AssignEnvironment(DefineAsRegister(result))
2134 : DefineAsRegister(result);
2138 LInstruction* LChunkBuilder::DoLoadGlobalGeneric(HLoadGlobalGeneric* instr) {
2139 LOperand* context = UseFixed(instr->context(), cp);
2140 LOperand* global_object = UseFixed(instr->global_object(),
2141 LoadIC::ReceiverRegister());
2142 LOperand* vector = NULL;
2143 if (FLAG_vector_ics) {
2144 vector = FixedTemp(LoadIC::VectorRegister());
2146 LLoadGlobalGeneric* result =
2147 new(zone()) LLoadGlobalGeneric(context, global_object, vector);
2148 return MarkAsCall(DefineFixed(result, r0), instr);
2152 LInstruction* LChunkBuilder::DoStoreGlobalCell(HStoreGlobalCell* instr) {
2153 LOperand* value = UseRegister(instr->value());
2154 // Use a temp to check the value in the cell in the case where we perform
2156 return instr->RequiresHoleCheck()
2157 ? AssignEnvironment(new(zone()) LStoreGlobalCell(value, TempRegister()))
2158 : new(zone()) LStoreGlobalCell(value, NULL);
2162 LInstruction* LChunkBuilder::DoLoadContextSlot(HLoadContextSlot* instr) {
2163 LOperand* context = UseRegisterAtStart(instr->value());
2164 LInstruction* result =
2165 DefineAsRegister(new(zone()) LLoadContextSlot(context));
2166 if (instr->RequiresHoleCheck() && instr->DeoptimizesOnHole()) {
2167 result = AssignEnvironment(result);
2173 LInstruction* LChunkBuilder::DoStoreContextSlot(HStoreContextSlot* instr) {
2176 if (instr->NeedsWriteBarrier()) {
2177 context = UseTempRegister(instr->context());
2178 value = UseTempRegister(instr->value());
2180 context = UseRegister(instr->context());
2181 value = UseRegister(instr->value());
2183 LInstruction* result = new(zone()) LStoreContextSlot(context, value);
2184 if (instr->RequiresHoleCheck() && instr->DeoptimizesOnHole()) {
2185 result = AssignEnvironment(result);
2191 LInstruction* LChunkBuilder::DoLoadNamedField(HLoadNamedField* instr) {
2192 LOperand* obj = UseRegisterAtStart(instr->object());
2193 return DefineAsRegister(new(zone()) LLoadNamedField(obj));
2197 LInstruction* LChunkBuilder::DoLoadNamedGeneric(HLoadNamedGeneric* instr) {
2198 LOperand* context = UseFixed(instr->context(), cp);
2199 LOperand* object = UseFixed(instr->object(), LoadIC::ReceiverRegister());
2200 LOperand* vector = NULL;
2201 if (FLAG_vector_ics) {
2202 vector = FixedTemp(LoadIC::VectorRegister());
2205 LInstruction* result =
2206 DefineFixed(new(zone()) LLoadNamedGeneric(context, object, vector), r0);
2207 return MarkAsCall(result, instr);
2211 LInstruction* LChunkBuilder::DoLoadFunctionPrototype(
2212 HLoadFunctionPrototype* instr) {
2213 return AssignEnvironment(DefineAsRegister(
2214 new(zone()) LLoadFunctionPrototype(UseRegister(instr->function()))));
2218 LInstruction* LChunkBuilder::DoLoadRoot(HLoadRoot* instr) {
2219 return DefineAsRegister(new(zone()) LLoadRoot);
2223 LInstruction* LChunkBuilder::DoLoadKeyed(HLoadKeyed* instr) {
2224 DCHECK(instr->key()->representation().IsSmiOrInteger32());
2225 ElementsKind elements_kind = instr->elements_kind();
2226 bool load_128bits_without_neon = IsSIMD128ElementsKind(elements_kind);
2227 LOperand* key = load_128bits_without_neon
2228 ? UseRegisterOrConstant(instr->key())
2229 : UseRegisterOrConstantAtStart(instr->key());
2230 LInstruction* result = NULL;
2232 if (!instr->is_typed_elements()) {
2233 LOperand* obj = NULL;
2234 if (instr->representation().IsDouble()) {
2235 obj = UseRegister(instr->elements());
2237 DCHECK(instr->representation().IsSmiOrTagged());
2238 obj = UseRegisterAtStart(instr->elements());
2240 result = DefineAsRegister(new(zone()) LLoadKeyed(obj, key, NULL, NULL));
2243 (instr->representation().IsInteger32() &&
2244 !IsDoubleOrFloatElementsKind(elements_kind)) ||
2245 (instr->representation().IsDouble() &&
2246 IsDoubleOrFloatElementsKind(elements_kind)) ||
2247 (instr->representation().IsTagged() &&
2248 (IsSIMD128ElementsKind(elements_kind))));
2249 LOperand* backing_store = UseRegister(instr->elements());
2250 result = load_128bits_without_neon
2251 ? DefineAsRegister(new(zone()) LLoadKeyed(
2252 backing_store, key, TempRegister(), TempRegister()))
2253 : DefineAsRegister(new(zone()) LLoadKeyed(
2254 backing_store, key, NULL, NULL));
2255 if (load_128bits_without_neon) {
2256 info()->MarkAsDeferredCalling();
2257 AssignPointerMap(result);
2261 if ((instr->is_external() || instr->is_fixed_typed_array()) ?
2262 // see LCodeGen::DoLoadKeyedExternalArray
2263 ((elements_kind == EXTERNAL_UINT32_ELEMENTS ||
2264 elements_kind == UINT32_ELEMENTS) &&
2265 !instr->CheckFlag(HInstruction::kUint32)) :
2266 // see LCodeGen::DoLoadKeyedFixedDoubleArray and
2267 // LCodeGen::DoLoadKeyedFixedArray
2268 instr->RequiresHoleCheck()) {
2269 result = AssignEnvironment(result);
2275 LInstruction* LChunkBuilder::DoLoadKeyedGeneric(HLoadKeyedGeneric* instr) {
2276 LOperand* context = UseFixed(instr->context(), cp);
2277 LOperand* object = UseFixed(instr->object(), LoadIC::ReceiverRegister());
2278 LOperand* key = UseFixed(instr->key(), LoadIC::NameRegister());
2279 LOperand* vector = NULL;
2280 if (FLAG_vector_ics) {
2281 vector = FixedTemp(LoadIC::VectorRegister());
2284 LInstruction* result =
2285 DefineFixed(new(zone()) LLoadKeyedGeneric(context, object, key, vector),
2287 return MarkAsCall(result, instr);
2291 LInstruction* LChunkBuilder::DoStoreKeyed(HStoreKeyed* instr) {
2292 if (!instr->is_typed_elements()) {
2293 DCHECK(instr->elements()->representation().IsTagged());
2294 bool needs_write_barrier = instr->NeedsWriteBarrier();
2295 LOperand* object = NULL;
2296 LOperand* key = NULL;
2297 LOperand* val = NULL;
2299 if (instr->value()->representation().IsDouble()) {
2300 object = UseRegisterAtStart(instr->elements());
2301 val = UseRegister(instr->value());
2302 key = UseRegisterOrConstantAtStart(instr->key());
2304 DCHECK(instr->value()->representation().IsSmiOrTagged());
2305 if (needs_write_barrier) {
2306 object = UseTempRegister(instr->elements());
2307 val = UseTempRegister(instr->value());
2308 key = UseTempRegister(instr->key());
2310 object = UseRegisterAtStart(instr->elements());
2311 val = UseRegisterAtStart(instr->value());
2312 key = UseRegisterOrConstantAtStart(instr->key());
2316 return new(zone()) LStoreKeyed(object, key, val, NULL, NULL);
2320 (instr->value()->representation().IsInteger32() &&
2321 !IsDoubleOrFloatElementsKind(instr->elements_kind())) ||
2322 (instr->value()->representation().IsDouble() &&
2323 IsDoubleOrFloatElementsKind(instr->elements_kind())) ||
2324 (instr->value()->representation().IsTagged() &&
2325 IsSIMD128ElementsKind(instr->elements_kind())));
2326 DCHECK((instr->is_fixed_typed_array() &&
2327 instr->elements()->representation().IsTagged()) ||
2328 (instr->is_external() &&
2329 instr->elements()->representation().IsExternal()));
2330 LOperand* val = UseRegister(instr->value());
2331 LOperand* backing_store = UseRegister(instr->elements());
2332 bool store_128bits_without_neon =
2333 IsSIMD128ElementsKind(instr->elements_kind());
2334 LOperand* key = store_128bits_without_neon
2335 ? UseRegisterOrConstant(instr->key())
2336 : UseRegisterOrConstantAtStart(instr->key());
2337 LStoreKeyed* result =
2338 new(zone()) LStoreKeyed(backing_store, key, val,
2339 store_128bits_without_neon ? TempRegister() : NULL,
2340 store_128bits_without_neon ? TempRegister() : NULL);
2341 return store_128bits_without_neon ? AssignEnvironment(result) : result;
2345 LInstruction* LChunkBuilder::DoStoreKeyedGeneric(HStoreKeyedGeneric* instr) {
2346 LOperand* context = UseFixed(instr->context(), cp);
2347 LOperand* obj = UseFixed(instr->object(), KeyedStoreIC::ReceiverRegister());
2348 LOperand* key = UseFixed(instr->key(), KeyedStoreIC::NameRegister());
2349 LOperand* val = UseFixed(instr->value(), KeyedStoreIC::ValueRegister());
2351 DCHECK(instr->object()->representation().IsTagged());
2352 DCHECK(instr->key()->representation().IsTagged());
2353 DCHECK(instr->value()->representation().IsTagged());
2356 new(zone()) LStoreKeyedGeneric(context, obj, key, val), instr);
2360 LInstruction* LChunkBuilder::DoTransitionElementsKind(
2361 HTransitionElementsKind* instr) {
2362 if (IsSimpleMapChangeTransition(instr->from_kind(), instr->to_kind())) {
2363 LOperand* object = UseRegister(instr->object());
2364 LOperand* new_map_reg = TempRegister();
2365 LTransitionElementsKind* result =
2366 new(zone()) LTransitionElementsKind(object, NULL, new_map_reg);
2369 LOperand* object = UseFixed(instr->object(), r0);
2370 LOperand* context = UseFixed(instr->context(), cp);
2371 LTransitionElementsKind* result =
2372 new(zone()) LTransitionElementsKind(object, context, NULL);
2373 return MarkAsCall(result, instr);
2378 LInstruction* LChunkBuilder::DoTrapAllocationMemento(
2379 HTrapAllocationMemento* instr) {
2380 LOperand* object = UseRegister(instr->object());
2381 LOperand* temp = TempRegister();
2382 LTrapAllocationMemento* result =
2383 new(zone()) LTrapAllocationMemento(object, temp);
2384 return AssignEnvironment(result);
2388 LInstruction* LChunkBuilder::DoStoreNamedField(HStoreNamedField* instr) {
2389 bool is_in_object = instr->access().IsInobject();
2390 bool needs_write_barrier = instr->NeedsWriteBarrier();
2391 bool needs_write_barrier_for_map = instr->has_transition() &&
2392 instr->NeedsWriteBarrierForMap();
2395 if (needs_write_barrier) {
2397 ? UseRegister(instr->object())
2398 : UseTempRegister(instr->object());
2400 obj = needs_write_barrier_for_map
2401 ? UseRegister(instr->object())
2402 : UseRegisterAtStart(instr->object());
2406 if (needs_write_barrier || instr->field_representation().IsSmi()) {
2407 val = UseTempRegister(instr->value());
2408 } else if (instr->field_representation().IsDouble()) {
2409 val = UseRegisterAtStart(instr->value());
2411 val = UseRegister(instr->value());
2414 // We need a temporary register for write barrier of the map field.
2415 LOperand* temp = needs_write_barrier_for_map ? TempRegister() : NULL;
2417 return new(zone()) LStoreNamedField(obj, val, temp);
2421 LInstruction* LChunkBuilder::DoStoreNamedGeneric(HStoreNamedGeneric* instr) {
2422 LOperand* context = UseFixed(instr->context(), cp);
2423 LOperand* obj = UseFixed(instr->object(), StoreIC::ReceiverRegister());
2424 LOperand* val = UseFixed(instr->value(), StoreIC::ValueRegister());
2426 LInstruction* result = new(zone()) LStoreNamedGeneric(context, obj, val);
2427 return MarkAsCall(result, instr);
2431 LInstruction* LChunkBuilder::DoStringAdd(HStringAdd* instr) {
2432 LOperand* context = UseFixed(instr->context(), cp);
2433 LOperand* left = UseFixed(instr->left(), r1);
2434 LOperand* right = UseFixed(instr->right(), r0);
2436 DefineFixed(new(zone()) LStringAdd(context, left, right), r0),
2441 LInstruction* LChunkBuilder::DoStringCharCodeAt(HStringCharCodeAt* instr) {
2442 LOperand* string = UseTempRegister(instr->string());
2443 LOperand* index = UseTempRegister(instr->index());
2444 LOperand* context = UseAny(instr->context());
2445 LStringCharCodeAt* result =
2446 new(zone()) LStringCharCodeAt(context, string, index);
2447 return AssignPointerMap(DefineAsRegister(result));
2451 LInstruction* LChunkBuilder::DoStringCharFromCode(HStringCharFromCode* instr) {
2452 LOperand* char_code = UseRegister(instr->value());
2453 LOperand* context = UseAny(instr->context());
2454 LStringCharFromCode* result =
2455 new(zone()) LStringCharFromCode(context, char_code);
2456 return AssignPointerMap(DefineAsRegister(result));
2460 LInstruction* LChunkBuilder::DoAllocate(HAllocate* instr) {
2461 info()->MarkAsDeferredCalling();
2462 LOperand* context = UseAny(instr->context());
2463 LOperand* size = UseRegisterOrConstant(instr->size());
2464 LOperand* temp1 = TempRegister();
2465 LOperand* temp2 = TempRegister();
2466 LAllocate* result = new(zone()) LAllocate(context, size, temp1, temp2);
2467 return AssignPointerMap(DefineAsRegister(result));
2471 LInstruction* LChunkBuilder::DoRegExpLiteral(HRegExpLiteral* instr) {
2472 LOperand* context = UseFixed(instr->context(), cp);
2474 DefineFixed(new(zone()) LRegExpLiteral(context), r0), instr);
2478 LInstruction* LChunkBuilder::DoFunctionLiteral(HFunctionLiteral* instr) {
2479 LOperand* context = UseFixed(instr->context(), cp);
2481 DefineFixed(new(zone()) LFunctionLiteral(context), r0), instr);
2485 LInstruction* LChunkBuilder::DoOsrEntry(HOsrEntry* instr) {
2486 DCHECK(argument_count_ == 0);
2487 allocator_->MarkAsOsrEntry();
2488 current_block_->last_environment()->set_ast_id(instr->ast_id());
2489 return AssignEnvironment(new(zone()) LOsrEntry);
2493 LInstruction* LChunkBuilder::DoParameter(HParameter* instr) {
2494 LParameter* result = new(zone()) LParameter;
2495 if (instr->kind() == HParameter::STACK_PARAMETER) {
2496 int spill_index = chunk()->GetParameterStackSlot(instr->index());
2497 return DefineAsSpilled(result, spill_index);
2499 DCHECK(info()->IsStub());
2500 CodeStubInterfaceDescriptor* descriptor =
2501 info()->code_stub()->GetInterfaceDescriptor();
2502 int index = static_cast<int>(instr->index());
2503 Register reg = descriptor->GetEnvironmentParameterRegister(index);
2504 return DefineFixed(result, reg);
2509 LInstruction* LChunkBuilder::DoUnknownOSRValue(HUnknownOSRValue* instr) {
2510 // Use an index that corresponds to the location in the unoptimized frame,
2511 // which the optimized frame will subsume.
2512 int env_index = instr->index();
2513 int spill_index = 0;
2514 if (instr->environment()->is_parameter_index(env_index)) {
2515 spill_index = chunk()->GetParameterStackSlot(env_index);
2517 spill_index = env_index - instr->environment()->first_local_index();
2518 if (spill_index > LUnallocated::kMaxFixedSlotIndex) {
2519 Abort(kTooManySpillSlotsNeededForOSR);
2523 return DefineAsSpilled(new(zone()) LUnknownOSRValue, spill_index);
2527 LInstruction* LChunkBuilder::DoCallStub(HCallStub* instr) {
2528 LOperand* context = UseFixed(instr->context(), cp);
2529 return MarkAsCall(DefineFixed(new(zone()) LCallStub(context), r0), instr);
2533 LInstruction* LChunkBuilder::DoArgumentsObject(HArgumentsObject* instr) {
2534 // There are no real uses of the arguments object.
2535 // arguments.length and element access are supported directly on
2536 // stack arguments, and any real arguments object use causes a bailout.
2537 // So this value is never used.
2542 LInstruction* LChunkBuilder::DoCapturedObject(HCapturedObject* instr) {
2543 instr->ReplayEnvironment(current_block_->last_environment());
2545 // There are no real uses of a captured object.
2550 LInstruction* LChunkBuilder::DoAccessArgumentsAt(HAccessArgumentsAt* instr) {
2551 info()->MarkAsRequiresFrame();
2552 LOperand* args = UseRegister(instr->arguments());
2553 LOperand* length = UseRegisterOrConstantAtStart(instr->length());
2554 LOperand* index = UseRegisterOrConstantAtStart(instr->index());
2555 return DefineAsRegister(new(zone()) LAccessArgumentsAt(args, length, index));
2559 LInstruction* LChunkBuilder::DoToFastProperties(HToFastProperties* instr) {
2560 LOperand* object = UseFixed(instr->value(), r0);
2561 LToFastProperties* result = new(zone()) LToFastProperties(object);
2562 return MarkAsCall(DefineFixed(result, r0), instr);
2566 LInstruction* LChunkBuilder::DoTypeof(HTypeof* instr) {
2567 LOperand* context = UseFixed(instr->context(), cp);
2568 LTypeof* result = new(zone()) LTypeof(context, UseFixed(instr->value(), r0));
2569 return MarkAsCall(DefineFixed(result, r0), instr);
2573 LInstruction* LChunkBuilder::DoTypeofIsAndBranch(HTypeofIsAndBranch* instr) {
2574 return new(zone()) LTypeofIsAndBranch(UseRegister(instr->value()));
2578 LInstruction* LChunkBuilder::DoIsConstructCallAndBranch(
2579 HIsConstructCallAndBranch* instr) {
2580 return new(zone()) LIsConstructCallAndBranch(TempRegister());
2584 LInstruction* LChunkBuilder::DoSimulate(HSimulate* instr) {
2585 instr->ReplayEnvironment(current_block_->last_environment());
2590 LInstruction* LChunkBuilder::DoStackCheck(HStackCheck* instr) {
2591 if (instr->is_function_entry()) {
2592 LOperand* context = UseFixed(instr->context(), cp);
2593 return MarkAsCall(new(zone()) LStackCheck(context), instr);
2595 DCHECK(instr->is_backwards_branch());
2596 LOperand* context = UseAny(instr->context());
2597 return AssignEnvironment(
2598 AssignPointerMap(new(zone()) LStackCheck(context)));
2603 LInstruction* LChunkBuilder::DoEnterInlined(HEnterInlined* instr) {
2604 HEnvironment* outer = current_block_->last_environment();
2605 outer->set_ast_id(instr->ReturnId());
2606 HConstant* undefined = graph()->GetConstantUndefined();
2607 HEnvironment* inner = outer->CopyForInlining(instr->closure(),
2608 instr->arguments_count(),
2611 instr->inlining_kind());
2612 // Only replay binding of arguments object if it wasn't removed from graph.
2613 if (instr->arguments_var() != NULL && instr->arguments_object()->IsLinked()) {
2614 inner->Bind(instr->arguments_var(), instr->arguments_object());
2616 inner->set_entry(instr);
2617 current_block_->UpdateEnvironment(inner);
2618 chunk_->AddInlinedClosure(instr->closure());
2623 LInstruction* LChunkBuilder::DoLeaveInlined(HLeaveInlined* instr) {
2624 LInstruction* pop = NULL;
2626 HEnvironment* env = current_block_->last_environment();
2628 if (env->entry()->arguments_pushed()) {
2629 int argument_count = env->arguments_environment()->parameter_count();
2630 pop = new(zone()) LDrop(argument_count);
2631 DCHECK(instr->argument_delta() == -argument_count);
2634 HEnvironment* outer = current_block_->last_environment()->
2635 DiscardInlined(false);
2636 current_block_->UpdateEnvironment(outer);
2642 LInstruction* LChunkBuilder::DoForInPrepareMap(HForInPrepareMap* instr) {
2643 LOperand* context = UseFixed(instr->context(), cp);
2644 LOperand* object = UseFixed(instr->enumerable(), r0);
2645 LForInPrepareMap* result = new(zone()) LForInPrepareMap(context, object);
2646 return MarkAsCall(DefineFixed(result, r0), instr, CAN_DEOPTIMIZE_EAGERLY);
2650 LInstruction* LChunkBuilder::DoForInCacheArray(HForInCacheArray* instr) {
2651 LOperand* map = UseRegister(instr->map());
2652 return AssignEnvironment(DefineAsRegister(new(zone()) LForInCacheArray(map)));
2656 LInstruction* LChunkBuilder::DoCheckMapValue(HCheckMapValue* instr) {
2657 LOperand* value = UseRegisterAtStart(instr->value());
2658 LOperand* map = UseRegisterAtStart(instr->map());
2659 return AssignEnvironment(new(zone()) LCheckMapValue(value, map));
2663 LInstruction* LChunkBuilder::DoLoadFieldByIndex(HLoadFieldByIndex* instr) {
2664 LOperand* object = UseRegister(instr->object());
2665 LOperand* index = UseTempRegister(instr->index());
2666 LLoadFieldByIndex* load = new(zone()) LLoadFieldByIndex(object, index);
2667 LInstruction* result = DefineSameAsFirst(load);
2668 return AssignPointerMap(result);
2672 LInstruction* LChunkBuilder::DoStoreFrameContext(HStoreFrameContext* instr) {
2673 LOperand* context = UseRegisterAtStart(instr->context());
2674 return new(zone()) LStoreFrameContext(context);
2678 LInstruction* LChunkBuilder::DoAllocateBlockContext(
2679 HAllocateBlockContext* instr) {
2680 LOperand* context = UseFixed(instr->context(), cp);
2681 LOperand* function = UseRegisterAtStart(instr->function());
2682 LAllocateBlockContext* result =
2683 new(zone()) LAllocateBlockContext(context, function);
2684 return MarkAsCall(DefineFixed(result, cp), instr);
2687 } } // namespace v8::internal