1 // Copyright 2014 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
9 #include "src/hydrogen-osr.h"
10 #include "src/lithium-inl.h"
11 #include "src/ppc/lithium-codegen-ppc.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)
24 void LInstruction::VerifyCall() {
25 // Call instructions can use only fixed registers as temporaries and
26 // outputs because all registers are blocked by the calling convention.
27 // Inputs operands must use a fixed register or use-at-start policy or
28 // a non-register policy.
29 DCHECK(Output() == NULL || LUnallocated::cast(Output())->HasFixedPolicy() ||
30 !LUnallocated::cast(Output())->HasRegisterPolicy());
31 for (UseIterator it(this); !it.Done(); it.Advance()) {
32 LUnallocated* operand = LUnallocated::cast(it.Current());
33 DCHECK(operand->HasFixedPolicy() || 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 {
130 const char* LArithmeticT::Mnemonic() const {
163 bool LGoto::HasInterestingComment(LCodeGen* gen) const {
164 return !gen->IsNextEmittedBlock(block_id());
168 void LGoto::PrintDataTo(StringStream* stream) {
169 stream->Add("B%d", block_id());
173 void LBranch::PrintDataTo(StringStream* stream) {
174 stream->Add("B%d | B%d on ", true_block_id(), false_block_id());
175 value()->PrintTo(stream);
179 void LCompareNumericAndBranch::PrintDataTo(StringStream* stream) {
181 left()->PrintTo(stream);
182 stream->Add(" %s ", Token::String(op()));
183 right()->PrintTo(stream);
184 stream->Add(" then B%d else B%d", true_block_id(), false_block_id());
188 void LIsObjectAndBranch::PrintDataTo(StringStream* stream) {
189 stream->Add("if is_object(");
190 value()->PrintTo(stream);
191 stream->Add(") then B%d else B%d", true_block_id(), false_block_id());
195 void LIsStringAndBranch::PrintDataTo(StringStream* stream) {
196 stream->Add("if is_string(");
197 value()->PrintTo(stream);
198 stream->Add(") then B%d else B%d", true_block_id(), false_block_id());
202 void LIsSmiAndBranch::PrintDataTo(StringStream* stream) {
203 stream->Add("if is_smi(");
204 value()->PrintTo(stream);
205 stream->Add(") then B%d else B%d", true_block_id(), false_block_id());
209 void LIsUndetectableAndBranch::PrintDataTo(StringStream* stream) {
210 stream->Add("if is_undetectable(");
211 value()->PrintTo(stream);
212 stream->Add(") then B%d else B%d", true_block_id(), false_block_id());
216 void LStringCompareAndBranch::PrintDataTo(StringStream* stream) {
217 stream->Add("if string_compare(");
218 left()->PrintTo(stream);
219 right()->PrintTo(stream);
220 stream->Add(") then B%d else B%d", true_block_id(), false_block_id());
224 void LHasInstanceTypeAndBranch::PrintDataTo(StringStream* stream) {
225 stream->Add("if has_instance_type(");
226 value()->PrintTo(stream);
227 stream->Add(") then B%d else B%d", true_block_id(), false_block_id());
231 void LHasCachedArrayIndexAndBranch::PrintDataTo(StringStream* stream) {
232 stream->Add("if has_cached_array_index(");
233 value()->PrintTo(stream);
234 stream->Add(") then B%d else B%d", true_block_id(), false_block_id());
238 void LClassOfTestAndBranch::PrintDataTo(StringStream* stream) {
239 stream->Add("if class_of_test(");
240 value()->PrintTo(stream);
241 stream->Add(", \"%o\") then B%d else B%d", *hydrogen()->class_name(),
242 true_block_id(), false_block_id());
246 void LTypeofIsAndBranch::PrintDataTo(StringStream* stream) {
247 stream->Add("if typeof ");
248 value()->PrintTo(stream);
249 stream->Add(" == \"%s\" then B%d else B%d",
250 hydrogen()->type_literal()->ToCString().get(), true_block_id(),
255 void LStoreCodeEntry::PrintDataTo(StringStream* stream) {
257 function()->PrintTo(stream);
258 stream->Add(".code_entry = ");
259 code_object()->PrintTo(stream);
263 void LInnerAllocatedObject::PrintDataTo(StringStream* stream) {
265 base_object()->PrintTo(stream);
267 offset()->PrintTo(stream);
271 void LCallFunction::PrintDataTo(StringStream* stream) {
272 context()->PrintTo(stream);
274 function()->PrintTo(stream);
275 if (hydrogen()->HasVectorAndSlot()) {
276 stream->Add(" (type-feedback-vector ");
277 temp_vector()->PrintTo(stream);
279 temp_slot()->PrintTo(stream);
285 void LCallJSFunction::PrintDataTo(StringStream* stream) {
287 function()->PrintTo(stream);
288 stream->Add("#%d / ", arity());
292 void LCallWithDescriptor::PrintDataTo(StringStream* stream) {
293 for (int i = 0; i < InputCount(); i++) {
294 InputAt(i)->PrintTo(stream);
297 stream->Add("#%d / ", arity());
301 void LLoadContextSlot::PrintDataTo(StringStream* stream) {
302 context()->PrintTo(stream);
303 stream->Add("[%d]", slot_index());
307 void LStoreContextSlot::PrintDataTo(StringStream* stream) {
308 context()->PrintTo(stream);
309 stream->Add("[%d] <- ", slot_index());
310 value()->PrintTo(stream);
314 void LInvokeFunction::PrintDataTo(StringStream* stream) {
316 function()->PrintTo(stream);
317 stream->Add(" #%d / ", arity());
321 void LCallNew::PrintDataTo(StringStream* stream) {
323 constructor()->PrintTo(stream);
324 stream->Add(" #%d / ", arity());
328 void LCallNewArray::PrintDataTo(StringStream* stream) {
330 constructor()->PrintTo(stream);
331 stream->Add(" #%d / ", arity());
332 ElementsKind kind = hydrogen()->elements_kind();
333 stream->Add(" (%s) ", ElementsKindToString(kind));
337 void LAccessArgumentsAt::PrintDataTo(StringStream* stream) {
338 arguments()->PrintTo(stream);
339 stream->Add(" length ");
340 length()->PrintTo(stream);
341 stream->Add(" index ");
342 index()->PrintTo(stream);
346 void LLoadGlobalViaContext::PrintDataTo(StringStream* stream) {
347 stream->Add(String::cast(*name())->ToCString().get());
348 stream->Add(" depth:%d slot:%d", depth(), slot_index());
352 void LStoreNamedField::PrintDataTo(StringStream* stream) {
353 object()->PrintTo(stream);
354 std::ostringstream os;
355 os << hydrogen()->access() << " <- ";
356 stream->Add(os.str().c_str());
357 value()->PrintTo(stream);
361 void LStoreNamedGeneric::PrintDataTo(StringStream* stream) {
362 object()->PrintTo(stream);
364 stream->Add(String::cast(*name())->ToCString().get());
366 value()->PrintTo(stream);
370 void LStoreGlobalViaContext::PrintDataTo(StringStream* stream) {
371 stream->Add(String::cast(*name())->ToCString().get());
373 value()->PrintTo(stream);
374 stream->Add(" depth:%d slot:%d", depth(), slot_index());
378 void LLoadKeyed::PrintDataTo(StringStream* stream) {
379 elements()->PrintTo(stream);
381 key()->PrintTo(stream);
382 if (hydrogen()->IsDehoisted()) {
383 stream->Add(" + %d]", base_offset());
390 void LStoreKeyed::PrintDataTo(StringStream* stream) {
391 elements()->PrintTo(stream);
393 key()->PrintTo(stream);
394 if (hydrogen()->IsDehoisted()) {
395 stream->Add(" + %d] <-", base_offset());
397 stream->Add("] <- ");
400 if (value() == NULL) {
401 DCHECK(hydrogen()->IsConstantHoleStore() &&
402 hydrogen()->value()->representation().IsDouble());
403 stream->Add("<the hole(nan)>");
405 value()->PrintTo(stream);
410 void LStoreKeyedGeneric::PrintDataTo(StringStream* stream) {
411 object()->PrintTo(stream);
413 key()->PrintTo(stream);
414 stream->Add("] <- ");
415 value()->PrintTo(stream);
419 void LTransitionElementsKind::PrintDataTo(StringStream* stream) {
420 object()->PrintTo(stream);
421 stream->Add(" %p -> %p", *original_map(), *transitioned_map());
425 int LPlatformChunk::GetNextSpillIndex(RegisterKind kind) {
426 // Skip a slot if for a double-width slot.
427 if (kind == DOUBLE_REGISTERS) spill_slot_count_++;
428 return spill_slot_count_++;
432 LOperand* LPlatformChunk::GetNextSpillSlot(RegisterKind kind) {
433 int index = GetNextSpillIndex(kind);
434 if (kind == DOUBLE_REGISTERS) {
435 return LDoubleStackSlot::Create(index, zone());
437 DCHECK(kind == GENERAL_REGISTERS);
438 return LStackSlot::Create(index, zone());
443 LPlatformChunk* LChunkBuilder::Build() {
445 chunk_ = new (zone()) LPlatformChunk(info(), graph());
446 LPhase phase("L_Building chunk", chunk_);
449 // If compiling for OSR, reserve space for the unoptimized frame,
450 // which will be subsumed into this frame.
451 if (graph()->has_osr()) {
452 for (int i = graph()->osr()->UnoptimizedFrameSlots(); i > 0; i--) {
453 chunk_->GetNextSpillIndex(GENERAL_REGISTERS);
457 const ZoneList<HBasicBlock*>* blocks = graph()->blocks();
458 for (int i = 0; i < blocks->length(); i++) {
459 HBasicBlock* next = NULL;
460 if (i < blocks->length() - 1) next = blocks->at(i + 1);
461 DoBasicBlock(blocks->at(i), next);
462 if (is_aborted()) return NULL;
469 LUnallocated* LChunkBuilder::ToUnallocated(Register reg) {
470 return new (zone()) LUnallocated(LUnallocated::FIXED_REGISTER,
471 Register::ToAllocationIndex(reg));
475 LUnallocated* LChunkBuilder::ToUnallocated(DoubleRegister reg) {
476 return new (zone()) LUnallocated(LUnallocated::FIXED_DOUBLE_REGISTER,
477 DoubleRegister::ToAllocationIndex(reg));
481 LOperand* LChunkBuilder::UseFixed(HValue* value, Register fixed_register) {
482 return Use(value, ToUnallocated(fixed_register));
486 LOperand* LChunkBuilder::UseFixedDouble(HValue* value, DoubleRegister reg) {
487 return Use(value, ToUnallocated(reg));
491 LOperand* LChunkBuilder::UseRegister(HValue* value) {
493 new (zone()) LUnallocated(LUnallocated::MUST_HAVE_REGISTER));
497 LOperand* LChunkBuilder::UseRegisterAtStart(HValue* value) {
498 return Use(value, new (zone()) LUnallocated(LUnallocated::MUST_HAVE_REGISTER,
499 LUnallocated::USED_AT_START));
503 LOperand* LChunkBuilder::UseTempRegister(HValue* value) {
504 return Use(value, new (zone()) LUnallocated(LUnallocated::WRITABLE_REGISTER));
508 LOperand* LChunkBuilder::Use(HValue* value) {
509 return Use(value, new (zone()) LUnallocated(LUnallocated::NONE));
513 LOperand* LChunkBuilder::UseAtStart(HValue* value) {
514 return Use(value, new (zone())
515 LUnallocated(LUnallocated::NONE, LUnallocated::USED_AT_START));
519 LOperand* LChunkBuilder::UseOrConstant(HValue* value) {
520 return value->IsConstant()
521 ? chunk_->DefineConstantOperand(HConstant::cast(value))
526 LOperand* LChunkBuilder::UseOrConstantAtStart(HValue* value) {
527 return value->IsConstant()
528 ? chunk_->DefineConstantOperand(HConstant::cast(value))
533 LOperand* LChunkBuilder::UseRegisterOrConstant(HValue* value) {
534 return value->IsConstant()
535 ? chunk_->DefineConstantOperand(HConstant::cast(value))
536 : UseRegister(value);
540 LOperand* LChunkBuilder::UseRegisterOrConstantAtStart(HValue* value) {
541 return value->IsConstant()
542 ? chunk_->DefineConstantOperand(HConstant::cast(value))
543 : UseRegisterAtStart(value);
547 LOperand* LChunkBuilder::UseConstant(HValue* value) {
548 return chunk_->DefineConstantOperand(HConstant::cast(value));
552 LOperand* LChunkBuilder::UseAny(HValue* value) {
553 return value->IsConstant()
554 ? chunk_->DefineConstantOperand(HConstant::cast(value))
555 : Use(value, new (zone()) LUnallocated(LUnallocated::ANY));
559 LOperand* LChunkBuilder::Use(HValue* value, LUnallocated* operand) {
560 if (value->EmitAtUses()) {
561 HInstruction* instr = HInstruction::cast(value);
562 VisitInstruction(instr);
564 operand->set_virtual_register(value->id());
569 LInstruction* LChunkBuilder::Define(LTemplateResultInstruction<1>* instr,
570 LUnallocated* result) {
571 result->set_virtual_register(current_instruction_->id());
572 instr->set_result(result);
577 LInstruction* LChunkBuilder::DefineAsRegister(
578 LTemplateResultInstruction<1>* instr) {
580 new (zone()) LUnallocated(LUnallocated::MUST_HAVE_REGISTER));
584 LInstruction* LChunkBuilder::DefineAsSpilled(
585 LTemplateResultInstruction<1>* instr, int index) {
587 new (zone()) LUnallocated(LUnallocated::FIXED_SLOT, index));
591 LInstruction* LChunkBuilder::DefineSameAsFirst(
592 LTemplateResultInstruction<1>* instr) {
594 new (zone()) LUnallocated(LUnallocated::SAME_AS_FIRST_INPUT));
598 LInstruction* LChunkBuilder::DefineFixed(LTemplateResultInstruction<1>* instr,
600 return Define(instr, ToUnallocated(reg));
604 LInstruction* LChunkBuilder::DefineFixedDouble(
605 LTemplateResultInstruction<1>* instr, DoubleRegister reg) {
606 return Define(instr, ToUnallocated(reg));
610 LInstruction* LChunkBuilder::AssignEnvironment(LInstruction* instr) {
611 HEnvironment* hydrogen_env = current_block_->last_environment();
612 int argument_index_accumulator = 0;
613 ZoneList<HValue*> objects_to_materialize(0, zone());
614 instr->set_environment(CreateEnvironment(
615 hydrogen_env, &argument_index_accumulator, &objects_to_materialize));
620 LInstruction* LChunkBuilder::MarkAsCall(LInstruction* instr,
621 HInstruction* hinstr,
622 CanDeoptimize can_deoptimize) {
623 info()->MarkAsNonDeferredCalling();
628 instr = AssignPointerMap(instr);
630 // If instruction does not have side-effects lazy deoptimization
631 // after the call will try to deoptimize to the point before the call.
632 // Thus we still need to attach environment to this call even if
633 // call sequence can not deoptimize eagerly.
634 bool needs_environment = (can_deoptimize == CAN_DEOPTIMIZE_EAGERLY) ||
635 !hinstr->HasObservableSideEffects();
636 if (needs_environment && !instr->HasEnvironment()) {
637 instr = AssignEnvironment(instr);
638 // We can't really figure out if the environment is needed or not.
639 instr->environment()->set_has_been_used();
646 LInstruction* LChunkBuilder::AssignPointerMap(LInstruction* instr) {
647 DCHECK(!instr->HasPointerMap());
648 instr->set_pointer_map(new (zone()) LPointerMap(zone()));
653 LUnallocated* LChunkBuilder::TempRegister() {
654 LUnallocated* operand =
655 new (zone()) LUnallocated(LUnallocated::MUST_HAVE_REGISTER);
656 int vreg = allocator_->GetVirtualRegister();
657 if (!allocator_->AllocationOk()) {
658 Abort(kOutOfVirtualRegistersWhileTryingToAllocateTempRegister);
661 operand->set_virtual_register(vreg);
666 LUnallocated* LChunkBuilder::TempDoubleRegister() {
667 LUnallocated* operand =
668 new (zone()) LUnallocated(LUnallocated::MUST_HAVE_DOUBLE_REGISTER);
669 int vreg = allocator_->GetVirtualRegister();
670 if (!allocator_->AllocationOk()) {
671 Abort(kOutOfVirtualRegistersWhileTryingToAllocateTempRegister);
674 operand->set_virtual_register(vreg);
679 LOperand* LChunkBuilder::FixedTemp(Register reg) {
680 LUnallocated* operand = ToUnallocated(reg);
681 DCHECK(operand->HasFixedPolicy());
686 LOperand* LChunkBuilder::FixedTemp(DoubleRegister reg) {
687 LUnallocated* operand = ToUnallocated(reg);
688 DCHECK(operand->HasFixedPolicy());
693 LInstruction* LChunkBuilder::DoBlockEntry(HBlockEntry* instr) {
694 return new (zone()) LLabel(instr->block());
698 LInstruction* LChunkBuilder::DoDummyUse(HDummyUse* instr) {
699 return DefineAsRegister(new (zone()) LDummyUse(UseAny(instr->value())));
703 LInstruction* LChunkBuilder::DoEnvironmentMarker(HEnvironmentMarker* instr) {
709 LInstruction* LChunkBuilder::DoDeoptimize(HDeoptimize* instr) {
710 return AssignEnvironment(new (zone()) LDeoptimize);
714 LInstruction* LChunkBuilder::DoShift(Token::Value op,
715 HBitwiseBinaryOperation* instr) {
716 if (instr->representation().IsSmiOrInteger32()) {
717 DCHECK(instr->left()->representation().Equals(instr->representation()));
718 DCHECK(instr->right()->representation().Equals(instr->representation()));
719 LOperand* left = UseRegisterAtStart(instr->left());
721 HValue* right_value = instr->right();
722 LOperand* right = NULL;
723 int constant_value = 0;
724 bool does_deopt = false;
725 if (right_value->IsConstant()) {
726 HConstant* constant = HConstant::cast(right_value);
727 right = chunk_->DefineConstantOperand(constant);
728 constant_value = constant->Integer32Value() & 0x1f;
729 // Left shifts can deoptimize if we shift by > 0 and the result cannot be
731 if (instr->representation().IsSmi() && constant_value > 0) {
732 does_deopt = !instr->CheckUsesForFlag(HValue::kTruncatingToSmi);
735 right = UseRegisterAtStart(right_value);
738 // Shift operations can only deoptimize if we do a logical shift
739 // by 0 and the result cannot be truncated to int32.
740 if (op == Token::SHR && constant_value == 0) {
741 does_deopt = !instr->CheckFlag(HInstruction::kUint32);
744 LInstruction* result =
745 DefineAsRegister(new (zone()) LShiftI(op, left, right, does_deopt));
746 return does_deopt ? AssignEnvironment(result) : result;
748 return DoArithmeticT(op, instr);
753 LInstruction* LChunkBuilder::DoArithmeticD(Token::Value op,
754 HArithmeticBinaryOperation* instr) {
755 DCHECK(instr->representation().IsDouble());
756 DCHECK(instr->left()->representation().IsDouble());
757 DCHECK(instr->right()->representation().IsDouble());
758 if (op == Token::MOD) {
759 LOperand* left = UseFixedDouble(instr->left(), d1);
760 LOperand* right = UseFixedDouble(instr->right(), d2);
761 LArithmeticD* result = new (zone()) LArithmeticD(op, left, right);
762 // We call a C function for double modulo. It can't trigger a GC. We need
763 // to use fixed result register for the call.
764 // TODO(fschneider): Allow any register as input registers.
765 return MarkAsCall(DefineFixedDouble(result, d1), instr);
767 LOperand* left = UseRegisterAtStart(instr->left());
768 LOperand* right = UseRegisterAtStart(instr->right());
769 LArithmeticD* result = new (zone()) LArithmeticD(op, left, right);
770 return DefineAsRegister(result);
775 LInstruction* LChunkBuilder::DoArithmeticT(Token::Value op,
776 HBinaryOperation* instr) {
777 HValue* left = instr->left();
778 HValue* right = instr->right();
779 DCHECK(left->representation().IsTagged());
780 DCHECK(right->representation().IsTagged());
781 LOperand* context = UseFixed(instr->context(), cp);
782 LOperand* left_operand = UseFixed(left, r4);
783 LOperand* right_operand = UseFixed(right, r3);
784 LArithmeticT* result =
785 new (zone()) LArithmeticT(op, context, left_operand, right_operand);
786 return MarkAsCall(DefineFixed(result, r3), instr);
790 void LChunkBuilder::DoBasicBlock(HBasicBlock* block, HBasicBlock* next_block) {
791 DCHECK(is_building());
792 current_block_ = block;
793 next_block_ = next_block;
794 if (block->IsStartBlock()) {
795 block->UpdateEnvironment(graph_->start_environment());
797 } else if (block->predecessors()->length() == 1) {
798 // We have a single predecessor => copy environment and outgoing
799 // argument count from the predecessor.
800 DCHECK(block->phis()->length() == 0);
801 HBasicBlock* pred = block->predecessors()->at(0);
802 HEnvironment* last_environment = pred->last_environment();
803 DCHECK(last_environment != NULL);
804 // Only copy the environment, if it is later used again.
805 if (pred->end()->SecondSuccessor() == NULL) {
806 DCHECK(pred->end()->FirstSuccessor() == block);
808 if (pred->end()->FirstSuccessor()->block_id() > block->block_id() ||
809 pred->end()->SecondSuccessor()->block_id() > block->block_id()) {
810 last_environment = last_environment->Copy();
813 block->UpdateEnvironment(last_environment);
814 DCHECK(pred->argument_count() >= 0);
815 argument_count_ = pred->argument_count();
817 // We are at a state join => process phis.
818 HBasicBlock* pred = block->predecessors()->at(0);
819 // No need to copy the environment, it cannot be used later.
820 HEnvironment* last_environment = pred->last_environment();
821 for (int i = 0; i < block->phis()->length(); ++i) {
822 HPhi* phi = block->phis()->at(i);
823 if (phi->HasMergedIndex()) {
824 last_environment->SetValueAt(phi->merged_index(), phi);
827 for (int i = 0; i < block->deleted_phis()->length(); ++i) {
828 if (block->deleted_phis()->at(i) < last_environment->length()) {
829 last_environment->SetValueAt(block->deleted_phis()->at(i),
830 graph_->GetConstantUndefined());
833 block->UpdateEnvironment(last_environment);
834 // Pick up the outgoing argument count of one of the predecessors.
835 argument_count_ = pred->argument_count();
837 HInstruction* current = block->first();
838 int start = chunk_->instructions()->length();
839 while (current != NULL && !is_aborted()) {
840 // Code for constants in registers is generated lazily.
841 if (!current->EmitAtUses()) {
842 VisitInstruction(current);
844 current = current->next();
846 int end = chunk_->instructions()->length() - 1;
848 block->set_first_instruction_index(start);
849 block->set_last_instruction_index(end);
851 block->set_argument_count(argument_count_);
853 current_block_ = NULL;
857 void LChunkBuilder::VisitInstruction(HInstruction* current) {
858 HInstruction* old_current = current_instruction_;
859 current_instruction_ = current;
861 LInstruction* instr = NULL;
862 if (current->CanReplaceWithDummyUses()) {
863 if (current->OperandCount() == 0) {
864 instr = DefineAsRegister(new (zone()) LDummy());
866 DCHECK(!current->OperandAt(0)->IsControlInstruction());
867 instr = DefineAsRegister(new (zone())
868 LDummyUse(UseAny(current->OperandAt(0))));
870 for (int i = 1; i < current->OperandCount(); ++i) {
871 if (current->OperandAt(i)->IsControlInstruction()) continue;
872 LInstruction* dummy =
873 new (zone()) LDummyUse(UseAny(current->OperandAt(i)));
874 dummy->set_hydrogen_value(current);
875 chunk_->AddInstruction(dummy, current_block_);
878 HBasicBlock* successor;
879 if (current->IsControlInstruction() &&
880 HControlInstruction::cast(current)->KnownSuccessorBlock(&successor) &&
882 instr = new (zone()) LGoto(successor);
884 instr = current->CompileToLithium(this);
888 argument_count_ += current->argument_delta();
889 DCHECK(argument_count_ >= 0);
892 AddInstruction(instr, current);
895 current_instruction_ = old_current;
899 void LChunkBuilder::AddInstruction(LInstruction* instr,
900 HInstruction* hydrogen_val) {
901 // Associate the hydrogen instruction first, since we may need it for
902 // the ClobbersRegisters() or ClobbersDoubleRegisters() calls below.
903 instr->set_hydrogen_value(hydrogen_val);
906 // Make sure that the lithium instruction has either no fixed register
907 // constraints in temps or the result OR no uses that are only used at
908 // start. If this invariant doesn't hold, the register allocator can decide
909 // to insert a split of a range immediately before the instruction due to an
910 // already allocated register needing to be used for the instruction's fixed
911 // register constraint. In this case, The register allocator won't see an
912 // interference between the split child and the use-at-start (it would if
913 // the it was just a plain use), so it is free to move the split child into
914 // the same register that is used for the use-at-start.
915 // See https://code.google.com/p/chromium/issues/detail?id=201590
916 if (!(instr->ClobbersRegisters() &&
917 instr->ClobbersDoubleRegisters(isolate()))) {
919 int used_at_start = 0;
920 for (UseIterator it(instr); !it.Done(); it.Advance()) {
921 LUnallocated* operand = LUnallocated::cast(it.Current());
922 if (operand->IsUsedAtStart()) ++used_at_start;
924 if (instr->Output() != NULL) {
925 if (LUnallocated::cast(instr->Output())->HasFixedPolicy()) ++fixed;
927 for (TempIterator it(instr); !it.Done(); it.Advance()) {
928 LUnallocated* operand = LUnallocated::cast(it.Current());
929 if (operand->HasFixedPolicy()) ++fixed;
931 DCHECK(fixed == 0 || used_at_start == 0);
935 if (FLAG_stress_pointer_maps && !instr->HasPointerMap()) {
936 instr = AssignPointerMap(instr);
938 if (FLAG_stress_environments && !instr->HasEnvironment()) {
939 instr = AssignEnvironment(instr);
941 chunk_->AddInstruction(instr, current_block_);
943 if (instr->IsCall()) {
944 HValue* hydrogen_value_for_lazy_bailout = hydrogen_val;
945 LInstruction* instruction_needing_environment = NULL;
946 if (hydrogen_val->HasObservableSideEffects()) {
947 HSimulate* sim = HSimulate::cast(hydrogen_val->next());
948 instruction_needing_environment = instr;
949 sim->ReplayEnvironment(current_block_->last_environment());
950 hydrogen_value_for_lazy_bailout = sim;
952 LInstruction* bailout = AssignEnvironment(new (zone()) LLazyBailout());
953 bailout->set_hydrogen_value(hydrogen_value_for_lazy_bailout);
954 chunk_->AddInstruction(bailout, current_block_);
955 if (instruction_needing_environment != NULL) {
956 // Store the lazy deopt environment with the instruction if needed.
957 // Right now it is only used for LInstanceOfKnownGlobal.
958 instruction_needing_environment->SetDeferredLazyDeoptimizationEnvironment(
959 bailout->environment());
965 LInstruction* LChunkBuilder::DoGoto(HGoto* instr) {
966 return new (zone()) LGoto(instr->FirstSuccessor());
970 LInstruction* LChunkBuilder::DoBranch(HBranch* instr) {
971 HValue* value = instr->value();
972 Representation r = value->representation();
973 HType type = value->type();
974 ToBooleanStub::Types expected = instr->expected_input_types();
975 if (expected.IsEmpty()) expected = ToBooleanStub::Types::Generic();
977 bool easy_case = !r.IsTagged() || type.IsBoolean() || type.IsSmi() ||
978 type.IsJSArray() || type.IsHeapNumber() || type.IsString();
979 LInstruction* branch = new (zone()) LBranch(UseRegister(value));
981 ((!expected.Contains(ToBooleanStub::SMI) && expected.NeedsMap()) ||
982 !expected.IsGeneric())) {
983 branch = AssignEnvironment(branch);
989 LInstruction* LChunkBuilder::DoDebugBreak(HDebugBreak* instr) {
990 return new (zone()) LDebugBreak();
994 LInstruction* LChunkBuilder::DoCompareMap(HCompareMap* instr) {
995 DCHECK(instr->value()->representation().IsTagged());
996 LOperand* value = UseRegisterAtStart(instr->value());
997 LOperand* temp = TempRegister();
998 return new (zone()) LCmpMapAndBranch(value, temp);
1002 LInstruction* LChunkBuilder::DoArgumentsLength(HArgumentsLength* instr) {
1003 info()->MarkAsRequiresFrame();
1004 LOperand* value = UseRegister(instr->value());
1005 return DefineAsRegister(new (zone()) LArgumentsLength(value));
1009 LInstruction* LChunkBuilder::DoArgumentsElements(HArgumentsElements* elems) {
1010 info()->MarkAsRequiresFrame();
1011 return DefineAsRegister(new (zone()) LArgumentsElements);
1015 LInstruction* LChunkBuilder::DoInstanceOf(HInstanceOf* instr) {
1016 LOperand* context = UseFixed(instr->context(), cp);
1017 LInstanceOf* result = new (zone()) LInstanceOf(
1018 context, UseFixed(instr->left(), r3), UseFixed(instr->right(), r4));
1019 return MarkAsCall(DefineFixed(result, r3), instr);
1023 LInstruction* LChunkBuilder::DoInstanceOfKnownGlobal(
1024 HInstanceOfKnownGlobal* instr) {
1025 LInstanceOfKnownGlobal* result = new (zone())
1026 LInstanceOfKnownGlobal(UseFixed(instr->context(), cp),
1027 UseFixed(instr->left(), r3), FixedTemp(r7));
1028 return MarkAsCall(DefineFixed(result, r3), instr);
1032 LInstruction* LChunkBuilder::DoWrapReceiver(HWrapReceiver* instr) {
1033 LOperand* receiver = UseRegisterAtStart(instr->receiver());
1034 LOperand* function = UseRegisterAtStart(instr->function());
1035 LWrapReceiver* result = new (zone()) LWrapReceiver(receiver, function);
1036 return AssignEnvironment(DefineAsRegister(result));
1040 LInstruction* LChunkBuilder::DoApplyArguments(HApplyArguments* instr) {
1041 LOperand* function = UseFixed(instr->function(), r4);
1042 LOperand* receiver = UseFixed(instr->receiver(), r3);
1043 LOperand* length = UseFixed(instr->length(), r5);
1044 LOperand* elements = UseFixed(instr->elements(), r6);
1045 LApplyArguments* result =
1046 new (zone()) LApplyArguments(function, receiver, length, elements);
1047 return MarkAsCall(DefineFixed(result, r3), instr, CAN_DEOPTIMIZE_EAGERLY);
1051 LInstruction* LChunkBuilder::DoPushArguments(HPushArguments* instr) {
1052 int argc = instr->OperandCount();
1053 for (int i = 0; i < argc; ++i) {
1054 LOperand* argument = Use(instr->argument(i));
1055 AddInstruction(new (zone()) LPushArgument(argument), instr);
1061 LInstruction* LChunkBuilder::DoStoreCodeEntry(
1062 HStoreCodeEntry* store_code_entry) {
1063 LOperand* function = UseRegister(store_code_entry->function());
1064 LOperand* code_object = UseTempRegister(store_code_entry->code_object());
1065 return new (zone()) LStoreCodeEntry(function, code_object);
1069 LInstruction* LChunkBuilder::DoInnerAllocatedObject(
1070 HInnerAllocatedObject* instr) {
1071 LOperand* base_object = UseRegisterAtStart(instr->base_object());
1072 LOperand* offset = UseRegisterOrConstantAtStart(instr->offset());
1073 return DefineAsRegister(new (zone())
1074 LInnerAllocatedObject(base_object, offset));
1078 LInstruction* LChunkBuilder::DoThisFunction(HThisFunction* instr) {
1079 return instr->HasNoUses() ? NULL
1080 : DefineAsRegister(new (zone()) LThisFunction);
1084 LInstruction* LChunkBuilder::DoContext(HContext* instr) {
1085 if (instr->HasNoUses()) return NULL;
1087 if (info()->IsStub()) {
1088 return DefineFixed(new (zone()) LContext, cp);
1091 return DefineAsRegister(new (zone()) LContext);
1095 LInstruction* LChunkBuilder::DoDeclareGlobals(HDeclareGlobals* instr) {
1096 LOperand* context = UseFixed(instr->context(), cp);
1097 return MarkAsCall(new (zone()) LDeclareGlobals(context), instr);
1101 LInstruction* LChunkBuilder::DoCallJSFunction(HCallJSFunction* instr) {
1102 LOperand* function = UseFixed(instr->function(), r4);
1104 LCallJSFunction* result = new (zone()) LCallJSFunction(function);
1106 return MarkAsCall(DefineFixed(result, r3), instr);
1110 LInstruction* LChunkBuilder::DoCallWithDescriptor(HCallWithDescriptor* instr) {
1111 CallInterfaceDescriptor descriptor = instr->descriptor();
1113 LOperand* target = UseRegisterOrConstantAtStart(instr->target());
1114 ZoneList<LOperand*> ops(instr->OperandCount(), zone());
1116 ops.Add(target, zone());
1118 LOperand* op = UseFixed(instr->OperandAt(1), cp);
1119 ops.Add(op, zone());
1120 // Other register parameters
1121 for (int i = LCallWithDescriptor::kImplicitRegisterParameterCount;
1122 i < instr->OperandCount(); i++) {
1124 UseFixed(instr->OperandAt(i),
1125 descriptor.GetRegisterParameter(
1126 i - LCallWithDescriptor::kImplicitRegisterParameterCount));
1127 ops.Add(op, zone());
1130 LCallWithDescriptor* result =
1131 new (zone()) LCallWithDescriptor(descriptor, ops, zone());
1132 return MarkAsCall(DefineFixed(result, r3), instr);
1136 LInstruction* LChunkBuilder::DoInvokeFunction(HInvokeFunction* instr) {
1137 LOperand* context = UseFixed(instr->context(), cp);
1138 LOperand* function = UseFixed(instr->function(), r4);
1139 LInvokeFunction* result = new (zone()) LInvokeFunction(context, function);
1140 return MarkAsCall(DefineFixed(result, r3), instr, CANNOT_DEOPTIMIZE_EAGERLY);
1144 LInstruction* LChunkBuilder::DoUnaryMathOperation(HUnaryMathOperation* instr) {
1145 switch (instr->op()) {
1147 return DoMathFloor(instr);
1149 return DoMathRound(instr);
1151 return DoMathFround(instr);
1153 return DoMathAbs(instr);
1155 return DoMathLog(instr);
1157 return DoMathExp(instr);
1159 return DoMathSqrt(instr);
1161 return DoMathPowHalf(instr);
1163 return DoMathClz32(instr);
1171 LInstruction* LChunkBuilder::DoMathFloor(HUnaryMathOperation* instr) {
1172 LOperand* input = UseRegister(instr->value());
1173 LMathFloor* result = new (zone()) LMathFloor(input);
1174 return AssignEnvironment(AssignPointerMap(DefineAsRegister(result)));
1178 LInstruction* LChunkBuilder::DoMathRound(HUnaryMathOperation* instr) {
1179 LOperand* input = UseRegister(instr->value());
1180 LOperand* temp = TempDoubleRegister();
1181 LMathRound* result = new (zone()) LMathRound(input, temp);
1182 return AssignEnvironment(DefineAsRegister(result));
1186 LInstruction* LChunkBuilder::DoMathFround(HUnaryMathOperation* instr) {
1187 LOperand* input = UseRegister(instr->value());
1188 LMathFround* result = new (zone()) LMathFround(input);
1189 return DefineAsRegister(result);
1193 LInstruction* LChunkBuilder::DoMathAbs(HUnaryMathOperation* instr) {
1194 Representation r = instr->value()->representation();
1195 LOperand* context = (r.IsDouble() || r.IsSmiOrInteger32())
1197 : UseFixed(instr->context(), cp);
1198 LOperand* input = UseRegister(instr->value());
1199 LInstruction* result =
1200 DefineAsRegister(new (zone()) LMathAbs(context, input));
1201 if (!r.IsDouble() && !r.IsSmiOrInteger32()) result = AssignPointerMap(result);
1202 if (!r.IsDouble()) result = AssignEnvironment(result);
1207 LInstruction* LChunkBuilder::DoMathLog(HUnaryMathOperation* instr) {
1208 DCHECK(instr->representation().IsDouble());
1209 DCHECK(instr->value()->representation().IsDouble());
1210 LOperand* input = UseFixedDouble(instr->value(), d1);
1211 return MarkAsCall(DefineFixedDouble(new (zone()) LMathLog(input), d1), instr);
1215 LInstruction* LChunkBuilder::DoMathClz32(HUnaryMathOperation* instr) {
1216 LOperand* input = UseRegisterAtStart(instr->value());
1217 LMathClz32* result = new (zone()) LMathClz32(input);
1218 return DefineAsRegister(result);
1222 LInstruction* LChunkBuilder::DoMathExp(HUnaryMathOperation* instr) {
1223 DCHECK(instr->representation().IsDouble());
1224 DCHECK(instr->value()->representation().IsDouble());
1225 LOperand* input = UseRegister(instr->value());
1226 LOperand* temp1 = TempRegister();
1227 LOperand* temp2 = TempRegister();
1228 LOperand* double_temp = TempDoubleRegister();
1229 LMathExp* result = new (zone()) LMathExp(input, double_temp, temp1, temp2);
1230 return DefineAsRegister(result);
1234 LInstruction* LChunkBuilder::DoMathSqrt(HUnaryMathOperation* instr) {
1235 LOperand* input = UseRegisterAtStart(instr->value());
1236 LMathSqrt* result = new (zone()) LMathSqrt(input);
1237 return DefineAsRegister(result);
1241 LInstruction* LChunkBuilder::DoMathPowHalf(HUnaryMathOperation* instr) {
1242 LOperand* input = UseRegisterAtStart(instr->value());
1243 LMathPowHalf* result = new (zone()) LMathPowHalf(input);
1244 return DefineAsRegister(result);
1248 LInstruction* LChunkBuilder::DoCallNew(HCallNew* instr) {
1249 LOperand* context = UseFixed(instr->context(), cp);
1250 LOperand* constructor = UseFixed(instr->constructor(), r4);
1251 LCallNew* result = new (zone()) LCallNew(context, constructor);
1252 return MarkAsCall(DefineFixed(result, r3), instr);
1256 LInstruction* LChunkBuilder::DoCallNewArray(HCallNewArray* instr) {
1257 LOperand* context = UseFixed(instr->context(), cp);
1258 LOperand* constructor = UseFixed(instr->constructor(), r4);
1259 LCallNewArray* result = new (zone()) LCallNewArray(context, constructor);
1260 return MarkAsCall(DefineFixed(result, r3), instr);
1264 LInstruction* LChunkBuilder::DoCallFunction(HCallFunction* instr) {
1265 LOperand* context = UseFixed(instr->context(), cp);
1266 LOperand* function = UseFixed(instr->function(), r4);
1267 LOperand* slot = NULL;
1268 LOperand* vector = NULL;
1269 if (instr->HasVectorAndSlot()) {
1270 slot = FixedTemp(r6);
1271 vector = FixedTemp(r5);
1274 LCallFunction* call =
1275 new (zone()) LCallFunction(context, function, slot, vector);
1276 return MarkAsCall(DefineFixed(call, r3), instr);
1280 LInstruction* LChunkBuilder::DoCallRuntime(HCallRuntime* instr) {
1281 LOperand* context = UseFixed(instr->context(), cp);
1282 return MarkAsCall(DefineFixed(new (zone()) LCallRuntime(context), r3), instr);
1286 LInstruction* LChunkBuilder::DoRor(HRor* instr) {
1287 return DoShift(Token::ROR, instr);
1291 LInstruction* LChunkBuilder::DoShr(HShr* instr) {
1292 return DoShift(Token::SHR, instr);
1296 LInstruction* LChunkBuilder::DoSar(HSar* instr) {
1297 return DoShift(Token::SAR, instr);
1301 LInstruction* LChunkBuilder::DoShl(HShl* instr) {
1302 return DoShift(Token::SHL, instr);
1306 LInstruction* LChunkBuilder::DoBitwise(HBitwise* instr) {
1307 if (instr->representation().IsSmiOrInteger32()) {
1308 DCHECK(instr->left()->representation().Equals(instr->representation()));
1309 DCHECK(instr->right()->representation().Equals(instr->representation()));
1310 DCHECK(instr->CheckFlag(HValue::kTruncatingToInt32));
1312 LOperand* left = UseRegisterAtStart(instr->BetterLeftOperand());
1313 LOperand* right = UseOrConstantAtStart(instr->BetterRightOperand());
1314 return DefineAsRegister(new (zone()) LBitI(left, right));
1316 return DoArithmeticT(instr->op(), instr);
1321 LInstruction* LChunkBuilder::DoDivByPowerOf2I(HDiv* instr) {
1322 DCHECK(instr->representation().IsSmiOrInteger32());
1323 DCHECK(instr->left()->representation().Equals(instr->representation()));
1324 DCHECK(instr->right()->representation().Equals(instr->representation()));
1325 LOperand* dividend = UseRegister(instr->left());
1326 int32_t divisor = instr->right()->GetInteger32Constant();
1327 LInstruction* result =
1328 DefineAsRegister(new (zone()) LDivByPowerOf2I(dividend, divisor));
1329 if ((instr->CheckFlag(HValue::kBailoutOnMinusZero) && divisor < 0) ||
1330 (instr->CheckFlag(HValue::kCanOverflow) && divisor == -1) ||
1331 (!instr->CheckFlag(HInstruction::kAllUsesTruncatingToInt32) &&
1332 divisor != 1 && divisor != -1)) {
1333 result = AssignEnvironment(result);
1339 LInstruction* LChunkBuilder::DoDivByConstI(HDiv* instr) {
1340 DCHECK(instr->representation().IsInteger32());
1341 DCHECK(instr->left()->representation().Equals(instr->representation()));
1342 DCHECK(instr->right()->representation().Equals(instr->representation()));
1343 LOperand* dividend = UseRegister(instr->left());
1344 int32_t divisor = instr->right()->GetInteger32Constant();
1345 LInstruction* result =
1346 DefineAsRegister(new (zone()) LDivByConstI(dividend, divisor));
1348 (instr->CheckFlag(HValue::kBailoutOnMinusZero) && divisor < 0) ||
1349 !instr->CheckFlag(HInstruction::kAllUsesTruncatingToInt32)) {
1350 result = AssignEnvironment(result);
1356 LInstruction* LChunkBuilder::DoDivI(HDiv* instr) {
1357 DCHECK(instr->representation().IsSmiOrInteger32());
1358 DCHECK(instr->left()->representation().Equals(instr->representation()));
1359 DCHECK(instr->right()->representation().Equals(instr->representation()));
1360 LOperand* dividend = UseRegister(instr->left());
1361 LOperand* divisor = UseRegister(instr->right());
1362 LInstruction* result =
1363 DefineAsRegister(new (zone()) LDivI(dividend, divisor));
1364 if (instr->CheckFlag(HValue::kCanBeDivByZero) ||
1365 instr->CheckFlag(HValue::kBailoutOnMinusZero) ||
1366 (instr->CheckFlag(HValue::kCanOverflow) &&
1367 !instr->CheckFlag(HValue::kAllUsesTruncatingToInt32)) ||
1368 (!instr->IsMathFloorOfDiv() &&
1369 !instr->CheckFlag(HValue::kAllUsesTruncatingToInt32))) {
1370 result = AssignEnvironment(result);
1376 LInstruction* LChunkBuilder::DoDiv(HDiv* instr) {
1377 if (instr->representation().IsSmiOrInteger32()) {
1378 if (instr->RightIsPowerOf2()) {
1379 return DoDivByPowerOf2I(instr);
1380 } else if (instr->right()->IsConstant()) {
1381 return DoDivByConstI(instr);
1383 return DoDivI(instr);
1385 } else if (instr->representation().IsDouble()) {
1386 return DoArithmeticD(Token::DIV, instr);
1388 return DoArithmeticT(Token::DIV, instr);
1393 LInstruction* LChunkBuilder::DoFlooringDivByPowerOf2I(HMathFloorOfDiv* instr) {
1394 LOperand* dividend = UseRegisterAtStart(instr->left());
1395 int32_t divisor = instr->right()->GetInteger32Constant();
1396 LInstruction* result =
1397 DefineAsRegister(new (zone()) LFlooringDivByPowerOf2I(dividend, divisor));
1398 if ((instr->CheckFlag(HValue::kBailoutOnMinusZero) && divisor < 0) ||
1399 (instr->CheckFlag(HValue::kLeftCanBeMinInt) && divisor == -1)) {
1400 result = AssignEnvironment(result);
1406 LInstruction* LChunkBuilder::DoFlooringDivByConstI(HMathFloorOfDiv* instr) {
1407 DCHECK(instr->representation().IsInteger32());
1408 DCHECK(instr->left()->representation().Equals(instr->representation()));
1409 DCHECK(instr->right()->representation().Equals(instr->representation()));
1410 LOperand* dividend = UseRegister(instr->left());
1411 int32_t divisor = instr->right()->GetInteger32Constant();
1413 ((divisor > 0 && !instr->CheckFlag(HValue::kLeftCanBeNegative)) ||
1414 (divisor < 0 && !instr->CheckFlag(HValue::kLeftCanBePositive)))
1417 LInstruction* result = DefineAsRegister(
1418 new (zone()) LFlooringDivByConstI(dividend, divisor, temp));
1420 (instr->CheckFlag(HValue::kBailoutOnMinusZero) && divisor < 0)) {
1421 result = AssignEnvironment(result);
1427 LInstruction* LChunkBuilder::DoFlooringDivI(HMathFloorOfDiv* instr) {
1428 DCHECK(instr->representation().IsSmiOrInteger32());
1429 DCHECK(instr->left()->representation().Equals(instr->representation()));
1430 DCHECK(instr->right()->representation().Equals(instr->representation()));
1431 LOperand* dividend = UseRegister(instr->left());
1432 LOperand* divisor = UseRegister(instr->right());
1433 LInstruction* result =
1434 DefineAsRegister(new (zone()) LFlooringDivI(dividend, divisor));
1435 if (instr->CheckFlag(HValue::kCanBeDivByZero) ||
1436 instr->CheckFlag(HValue::kBailoutOnMinusZero) ||
1437 (instr->CheckFlag(HValue::kCanOverflow) &&
1438 !instr->CheckFlag(HValue::kAllUsesTruncatingToInt32))) {
1439 result = AssignEnvironment(result);
1445 LInstruction* LChunkBuilder::DoMathFloorOfDiv(HMathFloorOfDiv* instr) {
1446 if (instr->RightIsPowerOf2()) {
1447 return DoFlooringDivByPowerOf2I(instr);
1448 } else if (instr->right()->IsConstant()) {
1449 return DoFlooringDivByConstI(instr);
1451 return DoFlooringDivI(instr);
1456 LInstruction* LChunkBuilder::DoModByPowerOf2I(HMod* instr) {
1457 DCHECK(instr->representation().IsSmiOrInteger32());
1458 DCHECK(instr->left()->representation().Equals(instr->representation()));
1459 DCHECK(instr->right()->representation().Equals(instr->representation()));
1460 LOperand* dividend = UseRegisterAtStart(instr->left());
1461 int32_t divisor = instr->right()->GetInteger32Constant();
1462 LInstruction* result =
1463 DefineSameAsFirst(new (zone()) LModByPowerOf2I(dividend, divisor));
1464 if (instr->CheckFlag(HValue::kLeftCanBeNegative) &&
1465 instr->CheckFlag(HValue::kBailoutOnMinusZero)) {
1466 result = AssignEnvironment(result);
1472 LInstruction* LChunkBuilder::DoModByConstI(HMod* instr) {
1473 DCHECK(instr->representation().IsSmiOrInteger32());
1474 DCHECK(instr->left()->representation().Equals(instr->representation()));
1475 DCHECK(instr->right()->representation().Equals(instr->representation()));
1476 LOperand* dividend = UseRegister(instr->left());
1477 int32_t divisor = instr->right()->GetInteger32Constant();
1478 LInstruction* result =
1479 DefineAsRegister(new (zone()) LModByConstI(dividend, divisor));
1480 if (divisor == 0 || instr->CheckFlag(HValue::kBailoutOnMinusZero)) {
1481 result = AssignEnvironment(result);
1487 LInstruction* LChunkBuilder::DoModI(HMod* instr) {
1488 DCHECK(instr->representation().IsSmiOrInteger32());
1489 DCHECK(instr->left()->representation().Equals(instr->representation()));
1490 DCHECK(instr->right()->representation().Equals(instr->representation()));
1491 LOperand* dividend = UseRegister(instr->left());
1492 LOperand* divisor = UseRegister(instr->right());
1493 LInstruction* result =
1494 DefineAsRegister(new (zone()) LModI(dividend, divisor));
1495 if (instr->CheckFlag(HValue::kCanBeDivByZero) ||
1496 instr->CheckFlag(HValue::kBailoutOnMinusZero)) {
1497 result = AssignEnvironment(result);
1503 LInstruction* LChunkBuilder::DoMod(HMod* instr) {
1504 if (instr->representation().IsSmiOrInteger32()) {
1505 if (instr->RightIsPowerOf2()) {
1506 return DoModByPowerOf2I(instr);
1507 } else if (instr->right()->IsConstant()) {
1508 return DoModByConstI(instr);
1510 return DoModI(instr);
1512 } else if (instr->representation().IsDouble()) {
1513 return DoArithmeticD(Token::MOD, instr);
1515 return DoArithmeticT(Token::MOD, instr);
1520 LInstruction* LChunkBuilder::DoMul(HMul* instr) {
1521 if (instr->representation().IsSmiOrInteger32()) {
1522 DCHECK(instr->left()->representation().Equals(instr->representation()));
1523 DCHECK(instr->right()->representation().Equals(instr->representation()));
1524 HValue* left = instr->BetterLeftOperand();
1525 HValue* right = instr->BetterRightOperand();
1528 bool can_overflow = instr->CheckFlag(HValue::kCanOverflow);
1529 bool bailout_on_minus_zero = instr->CheckFlag(HValue::kBailoutOnMinusZero);
1531 int32_t constant_value = 0;
1532 if (right->IsConstant()) {
1533 HConstant* constant = HConstant::cast(right);
1534 constant_value = constant->Integer32Value();
1535 // Constants -1, 0 and 1 can be optimized if the result can overflow.
1536 // For other constants, it can be optimized only without overflow.
1537 if (!can_overflow || ((constant_value >= -1) && (constant_value <= 1))) {
1538 left_op = UseRegisterAtStart(left);
1539 right_op = UseConstant(right);
1541 if (bailout_on_minus_zero) {
1542 left_op = UseRegister(left);
1544 left_op = UseRegisterAtStart(left);
1546 right_op = UseRegister(right);
1549 if (bailout_on_minus_zero) {
1550 left_op = UseRegister(left);
1552 left_op = UseRegisterAtStart(left);
1554 right_op = UseRegister(right);
1556 LMulI* mul = new (zone()) LMulI(left_op, right_op);
1557 if (right_op->IsConstantOperand()
1558 ? ((can_overflow && constant_value == -1) ||
1559 (bailout_on_minus_zero && constant_value <= 0))
1560 : (can_overflow || bailout_on_minus_zero)) {
1561 AssignEnvironment(mul);
1563 return DefineAsRegister(mul);
1565 } else if (instr->representation().IsDouble()) {
1566 return DoArithmeticD(Token::MUL, instr);
1568 return DoArithmeticT(Token::MUL, instr);
1573 LInstruction* LChunkBuilder::DoSub(HSub* instr) {
1574 if (instr->representation().IsSmiOrInteger32()) {
1575 DCHECK(instr->left()->representation().Equals(instr->representation()));
1576 DCHECK(instr->right()->representation().Equals(instr->representation()));
1578 if (instr->left()->IsConstant() &&
1579 !instr->CheckFlag(HValue::kCanOverflow)) {
1580 // If lhs is constant, do reverse subtraction instead.
1581 return DoRSub(instr);
1584 LOperand* left = UseRegisterAtStart(instr->left());
1585 LOperand* right = UseOrConstantAtStart(instr->right());
1586 LSubI* sub = new (zone()) LSubI(left, right);
1587 LInstruction* result = DefineAsRegister(sub);
1588 if (instr->CheckFlag(HValue::kCanOverflow)) {
1589 result = AssignEnvironment(result);
1592 } else if (instr->representation().IsDouble()) {
1593 return DoArithmeticD(Token::SUB, instr);
1595 return DoArithmeticT(Token::SUB, instr);
1600 LInstruction* LChunkBuilder::DoRSub(HSub* instr) {
1601 DCHECK(instr->representation().IsSmiOrInteger32());
1602 DCHECK(instr->left()->representation().Equals(instr->representation()));
1603 DCHECK(instr->right()->representation().Equals(instr->representation()));
1604 DCHECK(!instr->CheckFlag(HValue::kCanOverflow));
1606 // Note: The lhs of the subtraction becomes the rhs of the
1607 // reverse-subtraction.
1608 LOperand* left = UseRegisterAtStart(instr->right());
1609 LOperand* right = UseOrConstantAtStart(instr->left());
1610 LRSubI* rsb = new (zone()) LRSubI(left, right);
1611 LInstruction* result = DefineAsRegister(rsb);
1616 LInstruction* LChunkBuilder::DoMultiplyAdd(HMul* mul, HValue* addend) {
1617 LOperand* multiplier_op = UseRegisterAtStart(mul->left());
1618 LOperand* multiplicand_op = UseRegisterAtStart(mul->right());
1619 LOperand* addend_op = UseRegisterAtStart(addend);
1620 return DefineSameAsFirst(
1621 new (zone()) LMultiplyAddD(addend_op, multiplier_op, multiplicand_op));
1625 LInstruction* LChunkBuilder::DoMultiplySub(HValue* minuend, HMul* mul) {
1626 LOperand* minuend_op = UseRegisterAtStart(minuend);
1627 LOperand* multiplier_op = UseRegisterAtStart(mul->left());
1628 LOperand* multiplicand_op = UseRegisterAtStart(mul->right());
1630 return DefineSameAsFirst(
1631 new (zone()) LMultiplySubD(minuend_op, multiplier_op, multiplicand_op));
1635 LInstruction* LChunkBuilder::DoAdd(HAdd* instr) {
1636 if (instr->representation().IsSmiOrInteger32()) {
1637 DCHECK(instr->left()->representation().Equals(instr->representation()));
1638 DCHECK(instr->right()->representation().Equals(instr->representation()));
1639 LOperand* left = UseRegisterAtStart(instr->BetterLeftOperand());
1640 LOperand* right = UseOrConstantAtStart(instr->BetterRightOperand());
1641 LAddI* add = new (zone()) LAddI(left, right);
1642 LInstruction* result = DefineAsRegister(add);
1643 if (instr->CheckFlag(HValue::kCanOverflow)) {
1644 result = AssignEnvironment(result);
1647 } else if (instr->representation().IsExternal()) {
1648 DCHECK(instr->IsConsistentExternalRepresentation());
1649 DCHECK(!instr->CheckFlag(HValue::kCanOverflow));
1650 LOperand* left = UseRegisterAtStart(instr->left());
1651 LOperand* right = UseOrConstantAtStart(instr->right());
1652 LAddI* add = new (zone()) LAddI(left, right);
1653 LInstruction* result = DefineAsRegister(add);
1655 } else if (instr->representation().IsDouble()) {
1656 return DoArithmeticD(Token::ADD, instr);
1658 return DoArithmeticT(Token::ADD, instr);
1663 LInstruction* LChunkBuilder::DoMathMinMax(HMathMinMax* instr) {
1664 LOperand* left = NULL;
1665 LOperand* right = NULL;
1666 if (instr->representation().IsSmiOrInteger32()) {
1667 DCHECK(instr->left()->representation().Equals(instr->representation()));
1668 DCHECK(instr->right()->representation().Equals(instr->representation()));
1669 left = UseRegisterAtStart(instr->BetterLeftOperand());
1670 right = UseOrConstantAtStart(instr->BetterRightOperand());
1672 DCHECK(instr->representation().IsDouble());
1673 DCHECK(instr->left()->representation().IsDouble());
1674 DCHECK(instr->right()->representation().IsDouble());
1675 left = UseRegisterAtStart(instr->left());
1676 right = UseRegisterAtStart(instr->right());
1678 return DefineAsRegister(new (zone()) LMathMinMax(left, right));
1682 LInstruction* LChunkBuilder::DoPower(HPower* instr) {
1683 DCHECK(instr->representation().IsDouble());
1684 // We call a C function for double power. It can't trigger a GC.
1685 // We need to use fixed result register for the call.
1686 Representation exponent_type = instr->right()->representation();
1687 DCHECK(instr->left()->representation().IsDouble());
1688 LOperand* left = UseFixedDouble(instr->left(), d1);
1690 exponent_type.IsDouble()
1691 ? UseFixedDouble(instr->right(), d2)
1692 : UseFixed(instr->right(), MathPowTaggedDescriptor::exponent());
1693 LPower* result = new (zone()) LPower(left, right);
1694 return MarkAsCall(DefineFixedDouble(result, d3), instr,
1695 CAN_DEOPTIMIZE_EAGERLY);
1699 LInstruction* LChunkBuilder::DoCompareGeneric(HCompareGeneric* instr) {
1700 DCHECK(instr->left()->representation().IsTagged());
1701 DCHECK(instr->right()->representation().IsTagged());
1702 LOperand* context = UseFixed(instr->context(), cp);
1703 LOperand* left = UseFixed(instr->left(), r4);
1704 LOperand* right = UseFixed(instr->right(), r3);
1705 LCmpT* result = new (zone()) LCmpT(context, left, right);
1706 return MarkAsCall(DefineFixed(result, r3), instr);
1710 LInstruction* LChunkBuilder::DoCompareNumericAndBranch(
1711 HCompareNumericAndBranch* instr) {
1712 Representation r = instr->representation();
1713 if (r.IsSmiOrInteger32()) {
1714 DCHECK(instr->left()->representation().Equals(r));
1715 DCHECK(instr->right()->representation().Equals(r));
1716 LOperand* left = UseRegisterOrConstantAtStart(instr->left());
1717 LOperand* right = UseRegisterOrConstantAtStart(instr->right());
1718 return new (zone()) LCompareNumericAndBranch(left, right);
1720 DCHECK(r.IsDouble());
1721 DCHECK(instr->left()->representation().IsDouble());
1722 DCHECK(instr->right()->representation().IsDouble());
1723 LOperand* left = UseRegisterAtStart(instr->left());
1724 LOperand* right = UseRegisterAtStart(instr->right());
1725 return new (zone()) LCompareNumericAndBranch(left, right);
1730 LInstruction* LChunkBuilder::DoCompareObjectEqAndBranch(
1731 HCompareObjectEqAndBranch* instr) {
1732 LOperand* left = UseRegisterAtStart(instr->left());
1733 LOperand* right = UseRegisterAtStart(instr->right());
1734 return new (zone()) LCmpObjectEqAndBranch(left, right);
1738 LInstruction* LChunkBuilder::DoCompareHoleAndBranch(
1739 HCompareHoleAndBranch* instr) {
1740 LOperand* value = UseRegisterAtStart(instr->value());
1741 return new (zone()) LCmpHoleAndBranch(value);
1745 LInstruction* LChunkBuilder::DoCompareMinusZeroAndBranch(
1746 HCompareMinusZeroAndBranch* instr) {
1747 LOperand* value = UseRegister(instr->value());
1748 LOperand* scratch = TempRegister();
1749 return new (zone()) LCompareMinusZeroAndBranch(value, scratch);
1753 LInstruction* LChunkBuilder::DoIsObjectAndBranch(HIsObjectAndBranch* instr) {
1754 DCHECK(instr->value()->representation().IsTagged());
1755 LOperand* value = UseRegisterAtStart(instr->value());
1756 LOperand* temp = TempRegister();
1757 return new (zone()) LIsObjectAndBranch(value, temp);
1761 LInstruction* LChunkBuilder::DoIsStringAndBranch(HIsStringAndBranch* instr) {
1762 DCHECK(instr->value()->representation().IsTagged());
1763 LOperand* value = UseRegisterAtStart(instr->value());
1764 LOperand* temp = TempRegister();
1765 return new (zone()) LIsStringAndBranch(value, temp);
1769 LInstruction* LChunkBuilder::DoIsSmiAndBranch(HIsSmiAndBranch* instr) {
1770 DCHECK(instr->value()->representation().IsTagged());
1771 return new (zone()) LIsSmiAndBranch(Use(instr->value()));
1775 LInstruction* LChunkBuilder::DoIsUndetectableAndBranch(
1776 HIsUndetectableAndBranch* instr) {
1777 DCHECK(instr->value()->representation().IsTagged());
1778 LOperand* value = UseRegisterAtStart(instr->value());
1779 return new (zone()) LIsUndetectableAndBranch(value, TempRegister());
1783 LInstruction* LChunkBuilder::DoStringCompareAndBranch(
1784 HStringCompareAndBranch* instr) {
1785 DCHECK(instr->left()->representation().IsTagged());
1786 DCHECK(instr->right()->representation().IsTagged());
1787 LOperand* context = UseFixed(instr->context(), cp);
1788 LOperand* left = UseFixed(instr->left(), r4);
1789 LOperand* right = UseFixed(instr->right(), r3);
1790 LStringCompareAndBranch* result =
1791 new (zone()) LStringCompareAndBranch(context, left, right);
1792 return MarkAsCall(result, instr);
1796 LInstruction* LChunkBuilder::DoHasInstanceTypeAndBranch(
1797 HHasInstanceTypeAndBranch* instr) {
1798 DCHECK(instr->value()->representation().IsTagged());
1799 LOperand* value = UseRegisterAtStart(instr->value());
1800 return new (zone()) LHasInstanceTypeAndBranch(value);
1804 LInstruction* LChunkBuilder::DoGetCachedArrayIndex(
1805 HGetCachedArrayIndex* instr) {
1806 DCHECK(instr->value()->representation().IsTagged());
1807 LOperand* value = UseRegisterAtStart(instr->value());
1809 return DefineAsRegister(new (zone()) LGetCachedArrayIndex(value));
1813 LInstruction* LChunkBuilder::DoHasCachedArrayIndexAndBranch(
1814 HHasCachedArrayIndexAndBranch* instr) {
1815 DCHECK(instr->value()->representation().IsTagged());
1817 LHasCachedArrayIndexAndBranch(UseRegisterAtStart(instr->value()));
1821 LInstruction* LChunkBuilder::DoClassOfTestAndBranch(
1822 HClassOfTestAndBranch* instr) {
1823 DCHECK(instr->value()->representation().IsTagged());
1824 LOperand* value = UseRegister(instr->value());
1825 return new (zone()) LClassOfTestAndBranch(value, TempRegister());
1829 LInstruction* LChunkBuilder::DoMapEnumLength(HMapEnumLength* instr) {
1830 LOperand* map = UseRegisterAtStart(instr->value());
1831 return DefineAsRegister(new (zone()) LMapEnumLength(map));
1835 LInstruction* LChunkBuilder::DoDateField(HDateField* instr) {
1836 LOperand* object = UseFixed(instr->value(), r3);
1837 LDateField* result =
1838 new (zone()) LDateField(object, FixedTemp(r4), instr->index());
1839 return MarkAsCall(DefineFixed(result, r3), instr, CANNOT_DEOPTIMIZE_EAGERLY);
1843 LInstruction* LChunkBuilder::DoSeqStringGetChar(HSeqStringGetChar* instr) {
1844 LOperand* string = UseRegisterAtStart(instr->string());
1845 LOperand* index = UseRegisterOrConstantAtStart(instr->index());
1846 return DefineAsRegister(new (zone()) LSeqStringGetChar(string, index));
1850 LInstruction* LChunkBuilder::DoSeqStringSetChar(HSeqStringSetChar* instr) {
1851 LOperand* string = UseRegisterAtStart(instr->string());
1852 LOperand* index = FLAG_debug_code
1853 ? UseRegisterAtStart(instr->index())
1854 : UseRegisterOrConstantAtStart(instr->index());
1855 LOperand* value = UseRegisterAtStart(instr->value());
1856 LOperand* context = FLAG_debug_code ? UseFixed(instr->context(), cp) : NULL;
1857 return new (zone()) LSeqStringSetChar(context, string, index, value);
1861 LInstruction* LChunkBuilder::DoBoundsCheck(HBoundsCheck* instr) {
1862 if (!FLAG_debug_code && instr->skip_check()) return NULL;
1863 LOperand* index = UseRegisterOrConstantAtStart(instr->index());
1864 LOperand* length = !index->IsConstantOperand()
1865 ? UseRegisterOrConstantAtStart(instr->length())
1866 : UseRegisterAtStart(instr->length());
1867 LInstruction* result = new (zone()) LBoundsCheck(index, length);
1868 if (!FLAG_debug_code || !instr->skip_check()) {
1869 result = AssignEnvironment(result);
1875 LInstruction* LChunkBuilder::DoBoundsCheckBaseIndexInformation(
1876 HBoundsCheckBaseIndexInformation* instr) {
1882 LInstruction* LChunkBuilder::DoAbnormalExit(HAbnormalExit* instr) {
1883 // The control instruction marking the end of a block that completed
1884 // abruptly (e.g., threw an exception). There is nothing specific to do.
1889 LInstruction* LChunkBuilder::DoUseConst(HUseConst* instr) { return NULL; }
1892 LInstruction* LChunkBuilder::DoForceRepresentation(HForceRepresentation* bad) {
1893 // All HForceRepresentation instructions should be eliminated in the
1894 // representation change phase of Hydrogen.
1900 LInstruction* LChunkBuilder::DoChange(HChange* instr) {
1901 Representation from = instr->from();
1902 Representation to = instr->to();
1903 HValue* val = instr->value();
1905 if (to.IsTagged()) {
1906 LOperand* value = UseRegister(val);
1907 return DefineSameAsFirst(new (zone()) LDummyUse(value));
1909 from = Representation::Tagged();
1911 if (from.IsTagged()) {
1912 if (to.IsDouble()) {
1913 LOperand* value = UseRegister(val);
1914 LInstruction* result =
1915 DefineAsRegister(new (zone()) LNumberUntagD(value));
1916 if (!val->representation().IsSmi()) result = AssignEnvironment(result);
1918 } else if (to.IsSmi()) {
1919 LOperand* value = UseRegister(val);
1920 if (val->type().IsSmi()) {
1921 return DefineSameAsFirst(new (zone()) LDummyUse(value));
1923 return AssignEnvironment(
1924 DefineSameAsFirst(new (zone()) LCheckSmi(value)));
1926 DCHECK(to.IsInteger32());
1927 if (val->type().IsSmi() || val->representation().IsSmi()) {
1928 LOperand* value = UseRegisterAtStart(val);
1929 return DefineAsRegister(new (zone()) LSmiUntag(value, false));
1931 LOperand* value = UseRegister(val);
1932 LOperand* temp1 = TempRegister();
1933 LOperand* temp2 = TempDoubleRegister();
1934 LInstruction* result =
1935 DefineSameAsFirst(new (zone()) LTaggedToI(value, temp1, temp2));
1936 if (!val->representation().IsSmi()) result = AssignEnvironment(result);
1940 } else if (from.IsDouble()) {
1941 if (to.IsTagged()) {
1942 info()->MarkAsDeferredCalling();
1943 LOperand* value = UseRegister(val);
1944 LOperand* temp1 = TempRegister();
1945 LOperand* temp2 = TempRegister();
1946 LUnallocated* result_temp = TempRegister();
1947 LNumberTagD* result = new (zone()) LNumberTagD(value, temp1, temp2);
1948 return AssignPointerMap(Define(result, result_temp));
1949 } else if (to.IsSmi()) {
1950 LOperand* value = UseRegister(val);
1951 return AssignEnvironment(
1952 DefineAsRegister(new (zone()) LDoubleToSmi(value)));
1954 DCHECK(to.IsInteger32());
1955 LOperand* value = UseRegister(val);
1956 LInstruction* result = DefineAsRegister(new (zone()) LDoubleToI(value));
1957 if (!instr->CanTruncateToInt32()) result = AssignEnvironment(result);
1960 } else if (from.IsInteger32()) {
1961 info()->MarkAsDeferredCalling();
1962 if (to.IsTagged()) {
1963 if (!instr->CheckFlag(HValue::kCanOverflow)) {
1964 LOperand* value = UseRegisterAtStart(val);
1965 return DefineAsRegister(new (zone()) LSmiTag(value));
1966 } else if (val->CheckFlag(HInstruction::kUint32)) {
1967 LOperand* value = UseRegisterAtStart(val);
1968 LOperand* temp1 = TempRegister();
1969 LOperand* temp2 = TempRegister();
1970 LNumberTagU* result = new (zone()) LNumberTagU(value, temp1, temp2);
1971 return AssignPointerMap(DefineAsRegister(result));
1973 LOperand* value = UseRegisterAtStart(val);
1974 LOperand* temp1 = TempRegister();
1975 LOperand* temp2 = TempRegister();
1976 LNumberTagI* result = new (zone()) LNumberTagI(value, temp1, temp2);
1977 return AssignPointerMap(DefineAsRegister(result));
1979 } else if (to.IsSmi()) {
1980 LOperand* value = UseRegister(val);
1981 LInstruction* result = DefineAsRegister(new (zone()) LSmiTag(value));
1982 if (instr->CheckFlag(HValue::kCanOverflow)) {
1983 result = AssignEnvironment(result);
1987 DCHECK(to.IsDouble());
1988 if (val->CheckFlag(HInstruction::kUint32)) {
1989 return DefineAsRegister(new (zone()) LUint32ToDouble(UseRegister(val)));
1991 return DefineAsRegister(new (zone()) LInteger32ToDouble(Use(val)));
2000 LInstruction* LChunkBuilder::DoCheckHeapObject(HCheckHeapObject* instr) {
2001 LOperand* value = UseRegisterAtStart(instr->value());
2002 LInstruction* result = new (zone()) LCheckNonSmi(value);
2003 if (!instr->value()->type().IsHeapObject()) {
2004 result = AssignEnvironment(result);
2010 LInstruction* LChunkBuilder::DoCheckSmi(HCheckSmi* instr) {
2011 LOperand* value = UseRegisterAtStart(instr->value());
2012 return AssignEnvironment(new (zone()) LCheckSmi(value));
2016 LInstruction* LChunkBuilder::DoCheckArrayBufferNotNeutered(
2017 HCheckArrayBufferNotNeutered* instr) {
2018 LOperand* view = UseRegisterAtStart(instr->value());
2019 LCheckArrayBufferNotNeutered* result =
2020 new (zone()) LCheckArrayBufferNotNeutered(view);
2021 return AssignEnvironment(result);
2025 LInstruction* LChunkBuilder::DoCheckInstanceType(HCheckInstanceType* instr) {
2026 LOperand* value = UseRegisterAtStart(instr->value());
2027 LInstruction* result = new (zone()) LCheckInstanceType(value);
2028 return AssignEnvironment(result);
2032 LInstruction* LChunkBuilder::DoCheckValue(HCheckValue* instr) {
2033 LOperand* value = UseRegisterAtStart(instr->value());
2034 return AssignEnvironment(new (zone()) LCheckValue(value));
2038 LInstruction* LChunkBuilder::DoCheckMaps(HCheckMaps* instr) {
2039 if (instr->IsStabilityCheck()) return new (zone()) LCheckMaps;
2040 LOperand* value = UseRegisterAtStart(instr->value());
2041 LOperand* temp = TempRegister();
2042 LInstruction* result =
2043 AssignEnvironment(new (zone()) LCheckMaps(value, temp));
2044 if (instr->HasMigrationTarget()) {
2045 info()->MarkAsDeferredCalling();
2046 result = AssignPointerMap(result);
2052 LInstruction* LChunkBuilder::DoClampToUint8(HClampToUint8* instr) {
2053 HValue* value = instr->value();
2054 Representation input_rep = value->representation();
2055 LOperand* reg = UseRegister(value);
2056 if (input_rep.IsDouble()) {
2057 return DefineAsRegister(new (zone()) LClampDToUint8(reg));
2058 } else if (input_rep.IsInteger32()) {
2059 return DefineAsRegister(new (zone()) LClampIToUint8(reg));
2061 DCHECK(input_rep.IsSmiOrTagged());
2062 LClampTToUint8* result =
2063 new (zone()) LClampTToUint8(reg, TempDoubleRegister());
2064 return AssignEnvironment(DefineAsRegister(result));
2069 LInstruction* LChunkBuilder::DoDoubleBits(HDoubleBits* instr) {
2070 HValue* value = instr->value();
2071 DCHECK(value->representation().IsDouble());
2072 return DefineAsRegister(new (zone()) LDoubleBits(UseRegister(value)));
2076 LInstruction* LChunkBuilder::DoConstructDouble(HConstructDouble* instr) {
2077 LOperand* lo = UseRegister(instr->lo());
2078 LOperand* hi = UseRegister(instr->hi());
2079 return DefineAsRegister(new (zone()) LConstructDouble(hi, lo));
2083 LInstruction* LChunkBuilder::DoReturn(HReturn* instr) {
2084 LOperand* context = info()->IsStub() ? UseFixed(instr->context(), cp) : NULL;
2085 LOperand* parameter_count = UseRegisterOrConstant(instr->parameter_count());
2087 LReturn(UseFixed(instr->value(), r3), context, parameter_count);
2091 LInstruction* LChunkBuilder::DoConstant(HConstant* instr) {
2092 Representation r = instr->representation();
2094 return DefineAsRegister(new (zone()) LConstantS);
2095 } else if (r.IsInteger32()) {
2096 return DefineAsRegister(new (zone()) LConstantI);
2097 } else if (r.IsDouble()) {
2098 return DefineAsRegister(new (zone()) LConstantD);
2099 } else if (r.IsExternal()) {
2100 return DefineAsRegister(new (zone()) LConstantE);
2101 } else if (r.IsTagged()) {
2102 return DefineAsRegister(new (zone()) LConstantT);
2110 LInstruction* LChunkBuilder::DoLoadGlobalGeneric(HLoadGlobalGeneric* instr) {
2111 LOperand* context = UseFixed(instr->context(), cp);
2112 LOperand* global_object =
2113 UseFixed(instr->global_object(), LoadDescriptor::ReceiverRegister());
2114 LOperand* vector = NULL;
2115 if (instr->HasVectorAndSlot()) {
2116 vector = FixedTemp(LoadWithVectorDescriptor::VectorRegister());
2118 LLoadGlobalGeneric* result =
2119 new (zone()) LLoadGlobalGeneric(context, global_object, vector);
2120 return MarkAsCall(DefineFixed(result, r3), instr);
2124 LInstruction* LChunkBuilder::DoLoadGlobalViaContext(
2125 HLoadGlobalViaContext* instr) {
2126 LOperand* context = UseFixed(instr->context(), cp);
2127 DCHECK(instr->slot_index() > 0);
2128 LLoadGlobalViaContext* result = new (zone()) LLoadGlobalViaContext(context);
2129 return MarkAsCall(DefineFixed(result, r3), instr);
2133 LInstruction* LChunkBuilder::DoLoadContextSlot(HLoadContextSlot* instr) {
2134 LOperand* context = UseRegisterAtStart(instr->value());
2135 LInstruction* result =
2136 DefineAsRegister(new (zone()) LLoadContextSlot(context));
2137 if (instr->RequiresHoleCheck() && instr->DeoptimizesOnHole()) {
2138 result = AssignEnvironment(result);
2144 LInstruction* LChunkBuilder::DoStoreContextSlot(HStoreContextSlot* instr) {
2147 if (instr->NeedsWriteBarrier()) {
2148 context = UseTempRegister(instr->context());
2149 value = UseTempRegister(instr->value());
2151 context = UseRegister(instr->context());
2152 value = UseRegister(instr->value());
2154 LInstruction* result = new (zone()) LStoreContextSlot(context, value);
2155 if (instr->RequiresHoleCheck() && instr->DeoptimizesOnHole()) {
2156 result = AssignEnvironment(result);
2162 LInstruction* LChunkBuilder::DoLoadNamedField(HLoadNamedField* instr) {
2163 LOperand* obj = UseRegisterAtStart(instr->object());
2164 return DefineAsRegister(new (zone()) LLoadNamedField(obj));
2168 LInstruction* LChunkBuilder::DoLoadNamedGeneric(HLoadNamedGeneric* instr) {
2169 LOperand* context = UseFixed(instr->context(), cp);
2171 UseFixed(instr->object(), LoadDescriptor::ReceiverRegister());
2172 LOperand* vector = NULL;
2173 if (instr->HasVectorAndSlot()) {
2174 vector = FixedTemp(LoadWithVectorDescriptor::VectorRegister());
2177 LInstruction* result =
2178 DefineFixed(new (zone()) LLoadNamedGeneric(context, object, vector), r3);
2179 return MarkAsCall(result, instr);
2183 LInstruction* LChunkBuilder::DoLoadFunctionPrototype(
2184 HLoadFunctionPrototype* instr) {
2185 return AssignEnvironment(DefineAsRegister(
2186 new (zone()) LLoadFunctionPrototype(UseRegister(instr->function()))));
2190 LInstruction* LChunkBuilder::DoLoadRoot(HLoadRoot* instr) {
2191 return DefineAsRegister(new (zone()) LLoadRoot);
2195 LInstruction* LChunkBuilder::DoLoadKeyed(HLoadKeyed* instr) {
2196 DCHECK(instr->key()->representation().IsSmiOrInteger32());
2197 ElementsKind elements_kind = instr->elements_kind();
2198 LOperand* key = UseRegisterOrConstantAtStart(instr->key());
2199 LInstruction* result = NULL;
2201 if (!instr->is_typed_elements()) {
2202 LOperand* obj = NULL;
2203 if (instr->representation().IsDouble()) {
2204 obj = UseRegister(instr->elements());
2206 obj = UseRegisterAtStart(instr->elements());
2208 result = DefineAsRegister(new (zone()) LLoadKeyed(obj, key));
2210 DCHECK((instr->representation().IsInteger32() &&
2211 !IsDoubleOrFloatElementsKind(elements_kind)) ||
2212 (instr->representation().IsDouble() &&
2213 IsDoubleOrFloatElementsKind(elements_kind)));
2214 LOperand* backing_store = UseRegister(instr->elements());
2215 result = DefineAsRegister(new (zone()) LLoadKeyed(backing_store, key));
2218 bool needs_environment;
2219 if (instr->is_external() || instr->is_fixed_typed_array()) {
2220 // see LCodeGen::DoLoadKeyedExternalArray
2221 needs_environment = (elements_kind == EXTERNAL_UINT32_ELEMENTS ||
2222 elements_kind == UINT32_ELEMENTS) &&
2223 !instr->CheckFlag(HInstruction::kUint32);
2225 // see LCodeGen::DoLoadKeyedFixedDoubleArray and
2226 // LCodeGen::DoLoadKeyedFixedArray
2228 instr->RequiresHoleCheck() ||
2229 (instr->hole_mode() == CONVERT_HOLE_TO_UNDEFINED && info()->IsStub());
2232 if (needs_environment) {
2233 result = AssignEnvironment(result);
2239 LInstruction* LChunkBuilder::DoLoadKeyedGeneric(HLoadKeyedGeneric* instr) {
2240 LOperand* context = UseFixed(instr->context(), cp);
2242 UseFixed(instr->object(), LoadDescriptor::ReceiverRegister());
2243 LOperand* key = UseFixed(instr->key(), LoadDescriptor::NameRegister());
2244 LOperand* vector = NULL;
2245 if (instr->HasVectorAndSlot()) {
2246 vector = FixedTemp(LoadWithVectorDescriptor::VectorRegister());
2249 LInstruction* result = DefineFixed(
2250 new (zone()) LLoadKeyedGeneric(context, object, key, vector), r3);
2251 return MarkAsCall(result, instr);
2255 LInstruction* LChunkBuilder::DoStoreKeyed(HStoreKeyed* instr) {
2256 if (!instr->is_typed_elements()) {
2257 DCHECK(instr->elements()->representation().IsTagged());
2258 bool needs_write_barrier = instr->NeedsWriteBarrier();
2259 LOperand* object = NULL;
2260 LOperand* key = NULL;
2261 LOperand* val = NULL;
2263 if (instr->value()->representation().IsDouble()) {
2264 object = UseRegisterAtStart(instr->elements());
2265 val = UseRegister(instr->value());
2266 key = UseRegisterOrConstantAtStart(instr->key());
2268 if (needs_write_barrier) {
2269 object = UseTempRegister(instr->elements());
2270 val = UseTempRegister(instr->value());
2271 key = UseTempRegister(instr->key());
2273 object = UseRegisterAtStart(instr->elements());
2274 val = UseRegisterAtStart(instr->value());
2275 key = UseRegisterOrConstantAtStart(instr->key());
2279 return new (zone()) LStoreKeyed(object, key, val);
2282 DCHECK((instr->value()->representation().IsInteger32() &&
2283 !IsDoubleOrFloatElementsKind(instr->elements_kind())) ||
2284 (instr->value()->representation().IsDouble() &&
2285 IsDoubleOrFloatElementsKind(instr->elements_kind())));
2286 DCHECK(instr->elements()->representation().IsExternal());
2287 LOperand* val = UseRegister(instr->value());
2288 LOperand* key = UseRegisterOrConstantAtStart(instr->key());
2289 LOperand* backing_store = UseRegister(instr->elements());
2290 return new (zone()) LStoreKeyed(backing_store, key, val);
2294 LInstruction* LChunkBuilder::DoStoreKeyedGeneric(HStoreKeyedGeneric* instr) {
2295 LOperand* context = UseFixed(instr->context(), cp);
2297 UseFixed(instr->object(), StoreDescriptor::ReceiverRegister());
2298 LOperand* key = UseFixed(instr->key(), StoreDescriptor::NameRegister());
2299 LOperand* val = UseFixed(instr->value(), StoreDescriptor::ValueRegister());
2301 DCHECK(instr->object()->representation().IsTagged());
2302 DCHECK(instr->key()->representation().IsTagged());
2303 DCHECK(instr->value()->representation().IsTagged());
2305 LOperand* slot = NULL;
2306 LOperand* vector = NULL;
2307 if (instr->HasVectorAndSlot()) {
2308 slot = FixedTemp(VectorStoreICDescriptor::SlotRegister());
2309 vector = FixedTemp(VectorStoreICDescriptor::VectorRegister());
2312 LStoreKeyedGeneric* result =
2313 new (zone()) LStoreKeyedGeneric(context, obj, key, val, slot, vector);
2314 return MarkAsCall(result, instr);
2318 LInstruction* LChunkBuilder::DoTransitionElementsKind(
2319 HTransitionElementsKind* instr) {
2320 if (IsSimpleMapChangeTransition(instr->from_kind(), instr->to_kind())) {
2321 LOperand* object = UseRegister(instr->object());
2322 LOperand* new_map_reg = TempRegister();
2323 LTransitionElementsKind* result =
2324 new (zone()) LTransitionElementsKind(object, NULL, new_map_reg);
2327 LOperand* object = UseFixed(instr->object(), r3);
2328 LOperand* context = UseFixed(instr->context(), cp);
2329 LTransitionElementsKind* result =
2330 new (zone()) LTransitionElementsKind(object, context, NULL);
2331 return MarkAsCall(result, instr);
2336 LInstruction* LChunkBuilder::DoTrapAllocationMemento(
2337 HTrapAllocationMemento* instr) {
2338 LOperand* object = UseRegister(instr->object());
2339 LOperand* temp = TempRegister();
2340 LTrapAllocationMemento* result =
2341 new (zone()) LTrapAllocationMemento(object, temp);
2342 return AssignEnvironment(result);
2346 LInstruction* LChunkBuilder::DoMaybeGrowElements(HMaybeGrowElements* instr) {
2347 info()->MarkAsDeferredCalling();
2348 LOperand* context = UseFixed(instr->context(), cp);
2349 LOperand* object = Use(instr->object());
2350 LOperand* elements = Use(instr->elements());
2351 LOperand* key = UseRegisterOrConstant(instr->key());
2352 LOperand* current_capacity = UseRegisterOrConstant(instr->current_capacity());
2354 LMaybeGrowElements* result = new (zone())
2355 LMaybeGrowElements(context, object, elements, key, current_capacity);
2356 DefineFixed(result, r3);
2357 return AssignPointerMap(AssignEnvironment(result));
2361 LInstruction* LChunkBuilder::DoStoreNamedField(HStoreNamedField* instr) {
2362 bool is_in_object = instr->access().IsInobject();
2363 bool needs_write_barrier = instr->NeedsWriteBarrier();
2364 bool needs_write_barrier_for_map =
2365 instr->has_transition() && instr->NeedsWriteBarrierForMap();
2368 if (needs_write_barrier) {
2369 obj = is_in_object ? UseRegister(instr->object())
2370 : UseTempRegister(instr->object());
2372 obj = needs_write_barrier_for_map ? UseRegister(instr->object())
2373 : UseRegisterAtStart(instr->object());
2377 if (needs_write_barrier) {
2378 val = UseTempRegister(instr->value());
2379 } else if (instr->field_representation().IsDouble()) {
2380 val = UseRegisterAtStart(instr->value());
2382 val = UseRegister(instr->value());
2385 // We need a temporary register for write barrier of the map field.
2386 LOperand* temp = needs_write_barrier_for_map ? TempRegister() : NULL;
2388 return new (zone()) LStoreNamedField(obj, val, temp);
2392 LInstruction* LChunkBuilder::DoStoreNamedGeneric(HStoreNamedGeneric* instr) {
2393 LOperand* context = UseFixed(instr->context(), cp);
2395 UseFixed(instr->object(), StoreDescriptor::ReceiverRegister());
2396 LOperand* val = UseFixed(instr->value(), StoreDescriptor::ValueRegister());
2397 LOperand* slot = NULL;
2398 LOperand* vector = NULL;
2399 if (instr->HasVectorAndSlot()) {
2400 slot = FixedTemp(VectorStoreICDescriptor::SlotRegister());
2401 vector = FixedTemp(VectorStoreICDescriptor::VectorRegister());
2404 LStoreNamedGeneric* result =
2405 new (zone()) LStoreNamedGeneric(context, obj, val, slot, vector);
2406 return MarkAsCall(result, instr);
2410 LInstruction* LChunkBuilder::DoStoreGlobalViaContext(
2411 HStoreGlobalViaContext* instr) {
2412 LOperand* context = UseFixed(instr->context(), cp);
2413 LOperand* value = UseFixed(instr->value(),
2414 StoreGlobalViaContextDescriptor::ValueRegister());
2415 DCHECK(instr->slot_index() > 0);
2417 LStoreGlobalViaContext* result =
2418 new (zone()) LStoreGlobalViaContext(context, value);
2419 return MarkAsCall(result, instr);
2423 LInstruction* LChunkBuilder::DoStringAdd(HStringAdd* instr) {
2424 LOperand* context = UseFixed(instr->context(), cp);
2425 LOperand* left = UseFixed(instr->left(), r4);
2426 LOperand* right = UseFixed(instr->right(), r3);
2428 DefineFixed(new (zone()) LStringAdd(context, left, right), r3), instr);
2432 LInstruction* LChunkBuilder::DoStringCharCodeAt(HStringCharCodeAt* instr) {
2433 LOperand* string = UseTempRegister(instr->string());
2434 LOperand* index = UseTempRegister(instr->index());
2435 LOperand* context = UseAny(instr->context());
2436 LStringCharCodeAt* result =
2437 new (zone()) LStringCharCodeAt(context, string, index);
2438 return AssignPointerMap(DefineAsRegister(result));
2442 LInstruction* LChunkBuilder::DoStringCharFromCode(HStringCharFromCode* instr) {
2443 LOperand* char_code = UseRegister(instr->value());
2444 LOperand* context = UseAny(instr->context());
2445 LStringCharFromCode* result =
2446 new (zone()) LStringCharFromCode(context, char_code);
2447 return AssignPointerMap(DefineAsRegister(result));
2451 LInstruction* LChunkBuilder::DoAllocate(HAllocate* instr) {
2452 info()->MarkAsDeferredCalling();
2453 LOperand* context = UseAny(instr->context());
2454 LOperand* size = UseRegisterOrConstant(instr->size());
2455 LOperand* temp1 = TempRegister();
2456 LOperand* temp2 = TempRegister();
2457 LAllocate* result = new (zone()) LAllocate(context, size, temp1, temp2);
2458 return AssignPointerMap(DefineAsRegister(result));
2462 LInstruction* LChunkBuilder::DoRegExpLiteral(HRegExpLiteral* instr) {
2463 LOperand* context = UseFixed(instr->context(), cp);
2464 return MarkAsCall(DefineFixed(new (zone()) LRegExpLiteral(context), r3),
2469 LInstruction* LChunkBuilder::DoFunctionLiteral(HFunctionLiteral* instr) {
2470 LOperand* context = UseFixed(instr->context(), cp);
2471 return MarkAsCall(DefineFixed(new (zone()) LFunctionLiteral(context), r3),
2476 LInstruction* LChunkBuilder::DoOsrEntry(HOsrEntry* instr) {
2477 DCHECK(argument_count_ == 0);
2478 allocator_->MarkAsOsrEntry();
2479 current_block_->last_environment()->set_ast_id(instr->ast_id());
2480 return AssignEnvironment(new (zone()) LOsrEntry);
2484 LInstruction* LChunkBuilder::DoParameter(HParameter* instr) {
2485 LParameter* result = new (zone()) LParameter;
2486 if (instr->kind() == HParameter::STACK_PARAMETER) {
2487 int spill_index = chunk()->GetParameterStackSlot(instr->index());
2488 return DefineAsSpilled(result, spill_index);
2490 DCHECK(info()->IsStub());
2491 CallInterfaceDescriptor descriptor =
2492 info()->code_stub()->GetCallInterfaceDescriptor();
2493 int index = static_cast<int>(instr->index());
2494 Register reg = descriptor.GetRegisterParameter(index);
2495 return DefineFixed(result, reg);
2500 LInstruction* LChunkBuilder::DoUnknownOSRValue(HUnknownOSRValue* instr) {
2501 // Use an index that corresponds to the location in the unoptimized frame,
2502 // which the optimized frame will subsume.
2503 int env_index = instr->index();
2504 int spill_index = 0;
2505 if (instr->environment()->is_parameter_index(env_index)) {
2506 spill_index = chunk()->GetParameterStackSlot(env_index);
2508 spill_index = env_index - instr->environment()->first_local_index();
2509 if (spill_index > LUnallocated::kMaxFixedSlotIndex) {
2510 Retry(kTooManySpillSlotsNeededForOSR);
2514 return DefineAsSpilled(new (zone()) LUnknownOSRValue, spill_index);
2518 LInstruction* LChunkBuilder::DoCallStub(HCallStub* instr) {
2519 LOperand* context = UseFixed(instr->context(), cp);
2520 return MarkAsCall(DefineFixed(new (zone()) LCallStub(context), r3), instr);
2524 LInstruction* LChunkBuilder::DoArgumentsObject(HArgumentsObject* instr) {
2525 // There are no real uses of the arguments object.
2526 // arguments.length and element access are supported directly on
2527 // stack arguments, and any real arguments object use causes a bailout.
2528 // So this value is never used.
2533 LInstruction* LChunkBuilder::DoCapturedObject(HCapturedObject* instr) {
2534 instr->ReplayEnvironment(current_block_->last_environment());
2536 // There are no real uses of a captured object.
2541 LInstruction* LChunkBuilder::DoAccessArgumentsAt(HAccessArgumentsAt* instr) {
2542 info()->MarkAsRequiresFrame();
2543 LOperand* args = UseRegister(instr->arguments());
2544 LOperand* length = UseRegisterOrConstantAtStart(instr->length());
2545 LOperand* index = UseRegisterOrConstantAtStart(instr->index());
2546 return DefineAsRegister(new (zone()) LAccessArgumentsAt(args, length, index));
2550 LInstruction* LChunkBuilder::DoToFastProperties(HToFastProperties* instr) {
2551 LOperand* object = UseFixed(instr->value(), r3);
2552 LToFastProperties* result = new (zone()) LToFastProperties(object);
2553 return MarkAsCall(DefineFixed(result, r3), instr);
2557 LInstruction* LChunkBuilder::DoTypeof(HTypeof* instr) {
2558 LOperand* context = UseFixed(instr->context(), cp);
2559 LOperand* value = UseFixed(instr->value(), r6);
2560 LTypeof* result = new (zone()) LTypeof(context, value);
2561 return MarkAsCall(DefineFixed(result, r3), instr);
2565 LInstruction* LChunkBuilder::DoTypeofIsAndBranch(HTypeofIsAndBranch* instr) {
2566 return new (zone()) LTypeofIsAndBranch(UseRegister(instr->value()));
2570 LInstruction* LChunkBuilder::DoIsConstructCallAndBranch(
2571 HIsConstructCallAndBranch* instr) {
2572 return new (zone()) LIsConstructCallAndBranch(TempRegister());
2576 LInstruction* LChunkBuilder::DoSimulate(HSimulate* instr) {
2577 instr->ReplayEnvironment(current_block_->last_environment());
2582 LInstruction* LChunkBuilder::DoStackCheck(HStackCheck* instr) {
2583 if (instr->is_function_entry()) {
2584 LOperand* context = UseFixed(instr->context(), cp);
2585 return MarkAsCall(new (zone()) LStackCheck(context), instr);
2587 DCHECK(instr->is_backwards_branch());
2588 LOperand* context = UseAny(instr->context());
2589 return AssignEnvironment(
2590 AssignPointerMap(new (zone()) LStackCheck(context)));
2595 LInstruction* LChunkBuilder::DoEnterInlined(HEnterInlined* instr) {
2596 HEnvironment* outer = current_block_->last_environment();
2597 outer->set_ast_id(instr->ReturnId());
2598 HConstant* undefined = graph()->GetConstantUndefined();
2599 HEnvironment* inner = outer->CopyForInlining(
2600 instr->closure(), instr->arguments_count(), instr->function(), undefined,
2601 instr->inlining_kind());
2602 // Only replay binding of arguments object if it wasn't removed from graph.
2603 if (instr->arguments_var() != NULL && instr->arguments_object()->IsLinked()) {
2604 inner->Bind(instr->arguments_var(), instr->arguments_object());
2606 inner->BindContext(instr->closure_context());
2607 inner->set_entry(instr);
2608 current_block_->UpdateEnvironment(inner);
2609 chunk_->AddInlinedFunction(instr->shared());
2614 LInstruction* LChunkBuilder::DoLeaveInlined(HLeaveInlined* instr) {
2615 LInstruction* pop = NULL;
2617 HEnvironment* env = current_block_->last_environment();
2619 if (env->entry()->arguments_pushed()) {
2620 int argument_count = env->arguments_environment()->parameter_count();
2621 pop = new (zone()) LDrop(argument_count);
2622 DCHECK(instr->argument_delta() == -argument_count);
2625 HEnvironment* outer =
2626 current_block_->last_environment()->DiscardInlined(false);
2627 current_block_->UpdateEnvironment(outer);
2633 LInstruction* LChunkBuilder::DoForInPrepareMap(HForInPrepareMap* instr) {
2634 LOperand* context = UseFixed(instr->context(), cp);
2635 LOperand* object = UseFixed(instr->enumerable(), r3);
2636 LForInPrepareMap* result = new (zone()) LForInPrepareMap(context, object);
2637 return MarkAsCall(DefineFixed(result, r3), instr, CAN_DEOPTIMIZE_EAGERLY);
2641 LInstruction* LChunkBuilder::DoForInCacheArray(HForInCacheArray* instr) {
2642 LOperand* map = UseRegister(instr->map());
2643 return AssignEnvironment(
2644 DefineAsRegister(new (zone()) LForInCacheArray(map)));
2648 LInstruction* LChunkBuilder::DoCheckMapValue(HCheckMapValue* instr) {
2649 LOperand* value = UseRegisterAtStart(instr->value());
2650 LOperand* map = UseRegisterAtStart(instr->map());
2651 return AssignEnvironment(new (zone()) LCheckMapValue(value, map));
2655 LInstruction* LChunkBuilder::DoLoadFieldByIndex(HLoadFieldByIndex* instr) {
2656 LOperand* object = UseRegister(instr->object());
2657 LOperand* index = UseTempRegister(instr->index());
2658 LLoadFieldByIndex* load = new (zone()) LLoadFieldByIndex(object, index);
2659 LInstruction* result = DefineSameAsFirst(load);
2660 return AssignPointerMap(result);
2664 LInstruction* LChunkBuilder::DoStoreFrameContext(HStoreFrameContext* instr) {
2665 LOperand* context = UseRegisterAtStart(instr->context());
2666 return new (zone()) LStoreFrameContext(context);
2670 LInstruction* LChunkBuilder::DoAllocateBlockContext(
2671 HAllocateBlockContext* instr) {
2672 LOperand* context = UseFixed(instr->context(), cp);
2673 LOperand* function = UseRegisterAtStart(instr->function());
2674 LAllocateBlockContext* result =
2675 new (zone()) LAllocateBlockContext(context, function);
2676 return MarkAsCall(DefineFixed(result, cp), instr);
2678 } // namespace internal