1 // Copyright 2011 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are
6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided
11 // with the distribution.
12 // * Neither the name of Google Inc. nor the names of its
13 // contributors may be used to endorse or promote products derived
14 // from this software without specific prior written permission.
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 #include "lithium-allocator-inl.h"
31 #include "arm/lithium-arm.h"
32 #include "arm/lithium-codegen-arm.h"
37 #define DEFINE_COMPILE(type) \
38 void L##type::CompileToNative(LCodeGen* generator) { \
39 generator->Do##type(this); \
41 LITHIUM_CONCRETE_INSTRUCTION_LIST(DEFINE_COMPILE)
44 LOsrEntry::LOsrEntry() {
45 for (int i = 0; i < Register::kNumAllocatableRegisters; ++i) {
46 register_spills_[i] = NULL;
48 for (int i = 0; i < DoubleRegister::kNumAllocatableRegisters; ++i) {
49 double_register_spills_[i] = NULL;
54 void LOsrEntry::MarkSpilledRegister(int allocation_index,
55 LOperand* spill_operand) {
56 ASSERT(spill_operand->IsStackSlot());
57 ASSERT(register_spills_[allocation_index] == NULL);
58 register_spills_[allocation_index] = spill_operand;
63 void LInstruction::VerifyCall() {
64 // Call instructions can use only fixed registers as temporaries and
65 // outputs because all registers are blocked by the calling convention.
66 // Inputs operands must use a fixed register or use-at-start policy or
67 // a non-register policy.
68 ASSERT(Output() == NULL ||
69 LUnallocated::cast(Output())->HasFixedPolicy() ||
70 !LUnallocated::cast(Output())->HasRegisterPolicy());
71 for (UseIterator it(this); !it.Done(); it.Advance()) {
72 LUnallocated* operand = LUnallocated::cast(it.Current());
73 ASSERT(operand->HasFixedPolicy() ||
74 operand->IsUsedAtStart());
76 for (TempIterator it(this); !it.Done(); it.Advance()) {
77 LUnallocated* operand = LUnallocated::cast(it.Current());
78 ASSERT(operand->HasFixedPolicy() ||!operand->HasRegisterPolicy());
84 void LOsrEntry::MarkSpilledDoubleRegister(int allocation_index,
85 LOperand* spill_operand) {
86 ASSERT(spill_operand->IsDoubleStackSlot());
87 ASSERT(double_register_spills_[allocation_index] == NULL);
88 double_register_spills_[allocation_index] = spill_operand;
92 void LInstruction::PrintTo(StringStream* stream) {
93 stream->Add("%s ", this->Mnemonic());
95 PrintOutputOperandTo(stream);
99 if (HasEnvironment()) {
101 environment()->PrintTo(stream);
104 if (HasPointerMap()) {
106 pointer_map()->PrintTo(stream);
111 template<int R, int I, int T>
112 void LTemplateInstruction<R, I, T>::PrintDataTo(StringStream* stream) {
114 for (int i = 0; i < inputs_.length(); i++) {
115 if (i > 0) stream->Add(" ");
116 inputs_[i]->PrintTo(stream);
121 template<int R, int I, int T>
122 void LTemplateInstruction<R, I, T>::PrintOutputOperandTo(StringStream* stream) {
123 for (int i = 0; i < results_.length(); i++) {
124 if (i > 0) stream->Add(" ");
125 results_[i]->PrintTo(stream);
130 void LLabel::PrintDataTo(StringStream* stream) {
131 LGap::PrintDataTo(stream);
132 LLabel* rep = replacement();
134 stream->Add(" Dead block replaced with B%d", rep->block_id());
139 bool LGap::IsRedundant() const {
140 for (int i = 0; i < 4; i++) {
141 if (parallel_moves_[i] != NULL && !parallel_moves_[i]->IsRedundant()) {
150 void LGap::PrintDataTo(StringStream* stream) {
151 for (int i = 0; i < 4; i++) {
153 if (parallel_moves_[i] != NULL) {
154 parallel_moves_[i]->PrintDataTo(stream);
161 const char* LArithmeticD::Mnemonic() const {
163 case Token::ADD: return "add-d";
164 case Token::SUB: return "sub-d";
165 case Token::MUL: return "mul-d";
166 case Token::DIV: return "div-d";
167 case Token::MOD: return "mod-d";
175 const char* LArithmeticT::Mnemonic() const {
177 case Token::ADD: return "add-t";
178 case Token::SUB: return "sub-t";
179 case Token::MUL: return "mul-t";
180 case Token::MOD: return "mod-t";
181 case Token::DIV: return "div-t";
182 case Token::BIT_AND: return "bit-and-t";
183 case Token::BIT_OR: return "bit-or-t";
184 case Token::BIT_XOR: return "bit-xor-t";
185 case Token::SHL: return "shl-t";
186 case Token::SAR: return "sar-t";
187 case Token::SHR: return "shr-t";
195 void LGoto::PrintDataTo(StringStream* stream) {
196 stream->Add("B%d", block_id());
200 void LBranch::PrintDataTo(StringStream* stream) {
201 stream->Add("B%d | B%d on ", true_block_id(), false_block_id());
202 InputAt(0)->PrintTo(stream);
206 void LCmpIDAndBranch::PrintDataTo(StringStream* stream) {
208 InputAt(0)->PrintTo(stream);
209 stream->Add(" %s ", Token::String(op()));
210 InputAt(1)->PrintTo(stream);
211 stream->Add(" then B%d else B%d", true_block_id(), false_block_id());
215 void LIsNilAndBranch::PrintDataTo(StringStream* stream) {
217 InputAt(0)->PrintTo(stream);
218 stream->Add(kind() == kStrictEquality ? " === " : " == ");
219 stream->Add(nil() == kNullValue ? "null" : "undefined");
220 stream->Add(" then B%d else B%d", true_block_id(), false_block_id());
224 void LIsObjectAndBranch::PrintDataTo(StringStream* stream) {
225 stream->Add("if is_object(");
226 InputAt(0)->PrintTo(stream);
227 stream->Add(") then B%d else B%d", true_block_id(), false_block_id());
231 void LIsSmiAndBranch::PrintDataTo(StringStream* stream) {
232 stream->Add("if is_smi(");
233 InputAt(0)->PrintTo(stream);
234 stream->Add(") then B%d else B%d", true_block_id(), false_block_id());
238 void LIsUndetectableAndBranch::PrintDataTo(StringStream* stream) {
239 stream->Add("if is_undetectable(");
240 InputAt(0)->PrintTo(stream);
241 stream->Add(") then B%d else B%d", true_block_id(), false_block_id());
245 void LHasInstanceTypeAndBranch::PrintDataTo(StringStream* stream) {
246 stream->Add("if has_instance_type(");
247 InputAt(0)->PrintTo(stream);
248 stream->Add(") then B%d else B%d", true_block_id(), false_block_id());
252 void LHasCachedArrayIndexAndBranch::PrintDataTo(StringStream* stream) {
253 stream->Add("if has_cached_array_index(");
254 InputAt(0)->PrintTo(stream);
255 stream->Add(") then B%d else B%d", true_block_id(), false_block_id());
259 void LClassOfTestAndBranch::PrintDataTo(StringStream* stream) {
260 stream->Add("if class_of_test(");
261 InputAt(0)->PrintTo(stream);
262 stream->Add(", \"%o\") then B%d else B%d",
263 *hydrogen()->class_name(),
269 void LTypeofIsAndBranch::PrintDataTo(StringStream* stream) {
270 stream->Add("if typeof ");
271 InputAt(0)->PrintTo(stream);
272 stream->Add(" == \"%s\" then B%d else B%d",
273 *hydrogen()->type_literal()->ToCString(),
274 true_block_id(), false_block_id());
278 void LCallConstantFunction::PrintDataTo(StringStream* stream) {
279 stream->Add("#%d / ", arity());
283 void LUnaryMathOperation::PrintDataTo(StringStream* stream) {
284 stream->Add("/%s ", hydrogen()->OpName());
285 InputAt(0)->PrintTo(stream);
289 void LLoadContextSlot::PrintDataTo(StringStream* stream) {
290 InputAt(0)->PrintTo(stream);
291 stream->Add("[%d]", slot_index());
295 void LStoreContextSlot::PrintDataTo(StringStream* stream) {
296 InputAt(0)->PrintTo(stream);
297 stream->Add("[%d] <- ", slot_index());
298 InputAt(1)->PrintTo(stream);
302 void LInvokeFunction::PrintDataTo(StringStream* stream) {
304 InputAt(0)->PrintTo(stream);
305 stream->Add(" #%d / ", arity());
309 void LCallKeyed::PrintDataTo(StringStream* stream) {
310 stream->Add("[r2] #%d / ", arity());
314 void LCallNamed::PrintDataTo(StringStream* stream) {
315 SmartArrayPointer<char> name_string = name()->ToCString();
316 stream->Add("%s #%d / ", *name_string, arity());
320 void LCallGlobal::PrintDataTo(StringStream* stream) {
321 SmartArrayPointer<char> name_string = name()->ToCString();
322 stream->Add("%s #%d / ", *name_string, arity());
326 void LCallKnownGlobal::PrintDataTo(StringStream* stream) {
327 stream->Add("#%d / ", arity());
331 void LCallNew::PrintDataTo(StringStream* stream) {
333 InputAt(0)->PrintTo(stream);
334 stream->Add(" #%d / ", arity());
338 void LAccessArgumentsAt::PrintDataTo(StringStream* stream) {
339 arguments()->PrintTo(stream);
341 stream->Add(" length ");
342 length()->PrintTo(stream);
344 stream->Add(" index ");
345 index()->PrintTo(stream);
349 void LStoreNamedField::PrintDataTo(StringStream* stream) {
350 object()->PrintTo(stream);
352 stream->Add(*String::cast(*name())->ToCString());
354 value()->PrintTo(stream);
358 void LStoreNamedGeneric::PrintDataTo(StringStream* stream) {
359 object()->PrintTo(stream);
361 stream->Add(*String::cast(*name())->ToCString());
363 value()->PrintTo(stream);
367 void LStoreKeyedFastElement::PrintDataTo(StringStream* stream) {
368 object()->PrintTo(stream);
370 key()->PrintTo(stream);
371 stream->Add("] <- ");
372 value()->PrintTo(stream);
376 void LStoreKeyedFastDoubleElement::PrintDataTo(StringStream* stream) {
377 elements()->PrintTo(stream);
379 key()->PrintTo(stream);
380 stream->Add("] <- ");
381 value()->PrintTo(stream);
385 void LStoreKeyedGeneric::PrintDataTo(StringStream* stream) {
386 object()->PrintTo(stream);
388 key()->PrintTo(stream);
389 stream->Add("] <- ");
390 value()->PrintTo(stream);
394 void LTransitionElementsKind::PrintDataTo(StringStream* stream) {
395 object()->PrintTo(stream);
396 stream->Add(" %p -> %p", *original_map(), *transitioned_map());
400 LChunk::LChunk(CompilationInfo* info, HGraph* graph)
401 : spill_slot_count_(0),
406 inlined_closures_(1) {
410 int LChunk::GetNextSpillIndex(bool is_double) {
411 // Skip a slot if for a double-width slot.
412 if (is_double) spill_slot_count_++;
413 return spill_slot_count_++;
417 LOperand* LChunk::GetNextSpillSlot(bool is_double) {
418 int index = GetNextSpillIndex(is_double);
420 return LDoubleStackSlot::Create(index);
422 return LStackSlot::Create(index);
427 void LChunk::MarkEmptyBlocks() {
428 HPhase phase("Mark empty blocks", this);
429 for (int i = 0; i < graph()->blocks()->length(); ++i) {
430 HBasicBlock* block = graph()->blocks()->at(i);
431 int first = block->first_instruction_index();
432 int last = block->last_instruction_index();
433 LInstruction* first_instr = instructions()->at(first);
434 LInstruction* last_instr = instructions()->at(last);
436 LLabel* label = LLabel::cast(first_instr);
437 if (last_instr->IsGoto()) {
438 LGoto* goto_instr = LGoto::cast(last_instr);
439 if (label->IsRedundant() &&
440 !label->is_loop_header()) {
441 bool can_eliminate = true;
442 for (int i = first + 1; i < last && can_eliminate; ++i) {
443 LInstruction* cur = instructions()->at(i);
445 LGap* gap = LGap::cast(cur);
446 if (!gap->IsRedundant()) {
447 can_eliminate = false;
450 can_eliminate = false;
455 label->set_replacement(GetLabel(goto_instr->block_id()));
463 void LChunk::AddInstruction(LInstruction* instr, HBasicBlock* block) {
464 LInstructionGap* gap = new LInstructionGap(block);
466 if (instr->IsControl()) {
467 instructions_.Add(gap);
468 index = instructions_.length();
469 instructions_.Add(instr);
471 index = instructions_.length();
472 instructions_.Add(instr);
473 instructions_.Add(gap);
475 if (instr->HasPointerMap()) {
476 pointer_maps_.Add(instr->pointer_map());
477 instr->pointer_map()->set_lithium_position(index);
482 LConstantOperand* LChunk::DefineConstantOperand(HConstant* constant) {
483 return LConstantOperand::Create(constant->id());
487 int LChunk::GetParameterStackSlot(int index) const {
488 // The receiver is at index 0, the first parameter at index 1, so we
489 // shift all parameter indexes down by the number of parameters, and
490 // make sure they end up negative so they are distinguishable from
492 int result = index - info()->scope()->num_parameters() - 1;
497 // A parameter relative to ebp in the arguments stub.
498 int LChunk::ParameterAt(int index) {
499 ASSERT(-1 <= index); // -1 is the receiver.
500 return (1 + info()->scope()->num_parameters() - index) *
505 LGap* LChunk::GetGapAt(int index) const {
506 return LGap::cast(instructions_[index]);
510 bool LChunk::IsGapAt(int index) const {
511 return instructions_[index]->IsGap();
515 int LChunk::NearestGapPos(int index) const {
516 while (!IsGapAt(index)) index--;
521 void LChunk::AddGapMove(int index, LOperand* from, LOperand* to) {
522 GetGapAt(index)->GetOrCreateParallelMove(LGap::START)->AddMove(from, to);
526 Handle<Object> LChunk::LookupLiteral(LConstantOperand* operand) const {
527 return HConstant::cast(graph_->LookupValue(operand->index()))->handle();
531 Representation LChunk::LookupLiteralRepresentation(
532 LConstantOperand* operand) const {
533 return graph_->LookupValue(operand->index())->representation();
537 LChunk* LChunkBuilder::Build() {
539 chunk_ = new LChunk(info(), graph());
540 HPhase phase("Building chunk", chunk_);
542 const ZoneList<HBasicBlock*>* blocks = graph()->blocks();
543 for (int i = 0; i < blocks->length(); i++) {
544 HBasicBlock* next = NULL;
545 if (i < blocks->length() - 1) next = blocks->at(i + 1);
546 DoBasicBlock(blocks->at(i), next);
547 if (is_aborted()) return NULL;
554 void LChunkBuilder::Abort(const char* format, ...) {
555 if (FLAG_trace_bailout) {
556 SmartArrayPointer<char> name(
557 info()->shared_info()->DebugName()->ToCString());
558 PrintF("Aborting LChunk building in @\"%s\": ", *name);
560 va_start(arguments, format);
561 OS::VPrint(format, arguments);
569 LRegister* LChunkBuilder::ToOperand(Register reg) {
570 return LRegister::Create(Register::ToAllocationIndex(reg));
574 LUnallocated* LChunkBuilder::ToUnallocated(Register reg) {
575 return new LUnallocated(LUnallocated::FIXED_REGISTER,
576 Register::ToAllocationIndex(reg));
580 LUnallocated* LChunkBuilder::ToUnallocated(DoubleRegister reg) {
581 return new LUnallocated(LUnallocated::FIXED_DOUBLE_REGISTER,
582 DoubleRegister::ToAllocationIndex(reg));
586 LOperand* LChunkBuilder::UseFixed(HValue* value, Register fixed_register) {
587 return Use(value, ToUnallocated(fixed_register));
591 LOperand* LChunkBuilder::UseFixedDouble(HValue* value, DoubleRegister reg) {
592 return Use(value, ToUnallocated(reg));
596 LOperand* LChunkBuilder::UseRegister(HValue* value) {
597 return Use(value, new LUnallocated(LUnallocated::MUST_HAVE_REGISTER));
601 LOperand* LChunkBuilder::UseRegisterAtStart(HValue* value) {
603 new LUnallocated(LUnallocated::MUST_HAVE_REGISTER,
604 LUnallocated::USED_AT_START));
608 LOperand* LChunkBuilder::UseTempRegister(HValue* value) {
609 return Use(value, new LUnallocated(LUnallocated::WRITABLE_REGISTER));
613 LOperand* LChunkBuilder::Use(HValue* value) {
614 return Use(value, new LUnallocated(LUnallocated::NONE));
618 LOperand* LChunkBuilder::UseAtStart(HValue* value) {
619 return Use(value, new LUnallocated(LUnallocated::NONE,
620 LUnallocated::USED_AT_START));
624 LOperand* LChunkBuilder::UseOrConstant(HValue* value) {
625 return value->IsConstant()
626 ? chunk_->DefineConstantOperand(HConstant::cast(value))
631 LOperand* LChunkBuilder::UseOrConstantAtStart(HValue* value) {
632 return value->IsConstant()
633 ? chunk_->DefineConstantOperand(HConstant::cast(value))
638 LOperand* LChunkBuilder::UseRegisterOrConstant(HValue* value) {
639 return value->IsConstant()
640 ? chunk_->DefineConstantOperand(HConstant::cast(value))
641 : UseRegister(value);
645 LOperand* LChunkBuilder::UseRegisterOrConstantAtStart(HValue* value) {
646 return value->IsConstant()
647 ? chunk_->DefineConstantOperand(HConstant::cast(value))
648 : UseRegisterAtStart(value);
652 LOperand* LChunkBuilder::UseAny(HValue* value) {
653 return value->IsConstant()
654 ? chunk_->DefineConstantOperand(HConstant::cast(value))
655 : Use(value, new LUnallocated(LUnallocated::ANY));
659 LOperand* LChunkBuilder::Use(HValue* value, LUnallocated* operand) {
660 if (value->EmitAtUses()) {
661 HInstruction* instr = HInstruction::cast(value);
662 VisitInstruction(instr);
664 allocator_->RecordUse(value, operand);
669 template<int I, int T>
670 LInstruction* LChunkBuilder::Define(LTemplateInstruction<1, I, T>* instr,
671 LUnallocated* result) {
672 allocator_->RecordDefinition(current_instruction_, result);
673 instr->set_result(result);
678 template<int I, int T>
679 LInstruction* LChunkBuilder::Define(LTemplateInstruction<1, I, T>* instr) {
680 return Define(instr, new LUnallocated(LUnallocated::NONE));
684 template<int I, int T>
685 LInstruction* LChunkBuilder::DefineAsRegister(
686 LTemplateInstruction<1, I, T>* instr) {
687 return Define(instr, new LUnallocated(LUnallocated::MUST_HAVE_REGISTER));
691 template<int I, int T>
692 LInstruction* LChunkBuilder::DefineAsSpilled(
693 LTemplateInstruction<1, I, T>* instr, int index) {
694 return Define(instr, new LUnallocated(LUnallocated::FIXED_SLOT, index));
698 template<int I, int T>
699 LInstruction* LChunkBuilder::DefineSameAsFirst(
700 LTemplateInstruction<1, I, T>* instr) {
701 return Define(instr, new LUnallocated(LUnallocated::SAME_AS_FIRST_INPUT));
705 template<int I, int T>
706 LInstruction* LChunkBuilder::DefineFixed(
707 LTemplateInstruction<1, I, T>* instr, Register reg) {
708 return Define(instr, ToUnallocated(reg));
712 template<int I, int T>
713 LInstruction* LChunkBuilder::DefineFixedDouble(
714 LTemplateInstruction<1, I, T>* instr, DoubleRegister reg) {
715 return Define(instr, ToUnallocated(reg));
719 LInstruction* LChunkBuilder::AssignEnvironment(LInstruction* instr) {
720 HEnvironment* hydrogen_env = current_block_->last_environment();
721 int argument_index_accumulator = 0;
722 instr->set_environment(CreateEnvironment(hydrogen_env,
723 &argument_index_accumulator));
728 LInstruction* LChunkBuilder::SetInstructionPendingDeoptimizationEnvironment(
729 LInstruction* instr, int ast_id) {
730 ASSERT(instruction_pending_deoptimization_environment_ == NULL);
731 ASSERT(pending_deoptimization_ast_id_ == AstNode::kNoNumber);
732 instruction_pending_deoptimization_environment_ = instr;
733 pending_deoptimization_ast_id_ = ast_id;
738 void LChunkBuilder::ClearInstructionPendingDeoptimizationEnvironment() {
739 instruction_pending_deoptimization_environment_ = NULL;
740 pending_deoptimization_ast_id_ = AstNode::kNoNumber;
744 LInstruction* LChunkBuilder::MarkAsCall(LInstruction* instr,
745 HInstruction* hinstr,
746 CanDeoptimize can_deoptimize) {
751 instr = AssignPointerMap(instr);
753 if (hinstr->HasObservableSideEffects()) {
754 ASSERT(hinstr->next()->IsSimulate());
755 HSimulate* sim = HSimulate::cast(hinstr->next());
756 instr = SetInstructionPendingDeoptimizationEnvironment(
757 instr, sim->ast_id());
760 // If instruction does not have side-effects lazy deoptimization
761 // after the call will try to deoptimize to the point before the call.
762 // Thus we still need to attach environment to this call even if
763 // call sequence can not deoptimize eagerly.
764 bool needs_environment =
765 (can_deoptimize == CAN_DEOPTIMIZE_EAGERLY) ||
766 !hinstr->HasObservableSideEffects();
767 if (needs_environment && !instr->HasEnvironment()) {
768 instr = AssignEnvironment(instr);
775 LInstruction* LChunkBuilder::MarkAsSaveDoubles(LInstruction* instr) {
776 instr->MarkAsSaveDoubles();
781 LInstruction* LChunkBuilder::AssignPointerMap(LInstruction* instr) {
782 ASSERT(!instr->HasPointerMap());
783 instr->set_pointer_map(new LPointerMap(position_));
788 LUnallocated* LChunkBuilder::TempRegister() {
789 LUnallocated* operand = new LUnallocated(LUnallocated::MUST_HAVE_REGISTER);
790 allocator_->RecordTemporary(operand);
795 LOperand* LChunkBuilder::FixedTemp(Register reg) {
796 LUnallocated* operand = ToUnallocated(reg);
797 allocator_->RecordTemporary(operand);
802 LOperand* LChunkBuilder::FixedTemp(DoubleRegister reg) {
803 LUnallocated* operand = ToUnallocated(reg);
804 allocator_->RecordTemporary(operand);
809 LInstruction* LChunkBuilder::DoBlockEntry(HBlockEntry* instr) {
810 return new LLabel(instr->block());
814 LInstruction* LChunkBuilder::DoSoftDeoptimize(HSoftDeoptimize* instr) {
815 return AssignEnvironment(new LDeoptimize);
819 LInstruction* LChunkBuilder::DoDeoptimize(HDeoptimize* instr) {
820 return AssignEnvironment(new LDeoptimize);
824 LInstruction* LChunkBuilder::DoShift(Token::Value op,
825 HBitwiseBinaryOperation* instr) {
826 if (instr->representation().IsTagged()) {
827 ASSERT(instr->left()->representation().IsTagged());
828 ASSERT(instr->right()->representation().IsTagged());
830 LOperand* left = UseFixed(instr->left(), r1);
831 LOperand* right = UseFixed(instr->right(), r0);
832 LArithmeticT* result = new LArithmeticT(op, left, right);
833 return MarkAsCall(DefineFixed(result, r0), instr);
836 ASSERT(instr->representation().IsInteger32());
837 ASSERT(instr->left()->representation().IsInteger32());
838 ASSERT(instr->right()->representation().IsInteger32());
839 LOperand* left = UseRegisterAtStart(instr->left());
841 HValue* right_value = instr->right();
842 LOperand* right = NULL;
843 int constant_value = 0;
844 if (right_value->IsConstant()) {
845 HConstant* constant = HConstant::cast(right_value);
846 right = chunk_->DefineConstantOperand(constant);
847 constant_value = constant->Integer32Value() & 0x1f;
849 right = UseRegisterAtStart(right_value);
852 // Shift operations can only deoptimize if we do a logical shift
853 // by 0 and the result cannot be truncated to int32.
854 bool may_deopt = (op == Token::SHR && constant_value == 0);
855 bool does_deopt = false;
857 for (HUseIterator it(instr->uses()); !it.Done(); it.Advance()) {
858 if (!it.value()->CheckFlag(HValue::kTruncatingToInt32)) {
865 LInstruction* result =
866 DefineAsRegister(new LShiftI(op, left, right, does_deopt));
867 return does_deopt ? AssignEnvironment(result) : result;
871 LInstruction* LChunkBuilder::DoArithmeticD(Token::Value op,
872 HArithmeticBinaryOperation* instr) {
873 ASSERT(instr->representation().IsDouble());
874 ASSERT(instr->left()->representation().IsDouble());
875 ASSERT(instr->right()->representation().IsDouble());
876 ASSERT(op != Token::MOD);
877 LOperand* left = UseRegisterAtStart(instr->left());
878 LOperand* right = UseRegisterAtStart(instr->right());
879 LArithmeticD* result = new LArithmeticD(op, left, right);
880 return DefineAsRegister(result);
884 LInstruction* LChunkBuilder::DoArithmeticT(Token::Value op,
885 HArithmeticBinaryOperation* instr) {
886 ASSERT(op == Token::ADD ||
891 HValue* left = instr->left();
892 HValue* right = instr->right();
893 ASSERT(left->representation().IsTagged());
894 ASSERT(right->representation().IsTagged());
895 LOperand* left_operand = UseFixed(left, r1);
896 LOperand* right_operand = UseFixed(right, r0);
897 LArithmeticT* result = new LArithmeticT(op, left_operand, right_operand);
898 return MarkAsCall(DefineFixed(result, r0), instr);
902 void LChunkBuilder::DoBasicBlock(HBasicBlock* block, HBasicBlock* next_block) {
903 ASSERT(is_building());
904 current_block_ = block;
905 next_block_ = next_block;
906 if (block->IsStartBlock()) {
907 block->UpdateEnvironment(graph_->start_environment());
909 } else if (block->predecessors()->length() == 1) {
910 // We have a single predecessor => copy environment and outgoing
911 // argument count from the predecessor.
912 ASSERT(block->phis()->length() == 0);
913 HBasicBlock* pred = block->predecessors()->at(0);
914 HEnvironment* last_environment = pred->last_environment();
915 ASSERT(last_environment != NULL);
916 // Only copy the environment, if it is later used again.
917 if (pred->end()->SecondSuccessor() == NULL) {
918 ASSERT(pred->end()->FirstSuccessor() == block);
920 if (pred->end()->FirstSuccessor()->block_id() > block->block_id() ||
921 pred->end()->SecondSuccessor()->block_id() > block->block_id()) {
922 last_environment = last_environment->Copy();
925 block->UpdateEnvironment(last_environment);
926 ASSERT(pred->argument_count() >= 0);
927 argument_count_ = pred->argument_count();
929 // We are at a state join => process phis.
930 HBasicBlock* pred = block->predecessors()->at(0);
931 // No need to copy the environment, it cannot be used later.
932 HEnvironment* last_environment = pred->last_environment();
933 for (int i = 0; i < block->phis()->length(); ++i) {
934 HPhi* phi = block->phis()->at(i);
935 last_environment->SetValueAt(phi->merged_index(), phi);
937 for (int i = 0; i < block->deleted_phis()->length(); ++i) {
938 last_environment->SetValueAt(block->deleted_phis()->at(i),
939 graph_->GetConstantUndefined());
941 block->UpdateEnvironment(last_environment);
942 // Pick up the outgoing argument count of one of the predecessors.
943 argument_count_ = pred->argument_count();
945 HInstruction* current = block->first();
946 int start = chunk_->instructions()->length();
947 while (current != NULL && !is_aborted()) {
948 // Code for constants in registers is generated lazily.
949 if (!current->EmitAtUses()) {
950 VisitInstruction(current);
952 current = current->next();
954 int end = chunk_->instructions()->length() - 1;
956 block->set_first_instruction_index(start);
957 block->set_last_instruction_index(end);
959 block->set_argument_count(argument_count_);
961 current_block_ = NULL;
965 void LChunkBuilder::VisitInstruction(HInstruction* current) {
966 HInstruction* old_current = current_instruction_;
967 current_instruction_ = current;
968 if (current->has_position()) position_ = current->position();
969 LInstruction* instr = current->CompileToLithium(this);
972 if (FLAG_stress_pointer_maps && !instr->HasPointerMap()) {
973 instr = AssignPointerMap(instr);
975 if (FLAG_stress_environments && !instr->HasEnvironment()) {
976 instr = AssignEnvironment(instr);
978 instr->set_hydrogen_value(current);
979 chunk_->AddInstruction(instr, current_block_);
981 current_instruction_ = old_current;
985 LEnvironment* LChunkBuilder::CreateEnvironment(
986 HEnvironment* hydrogen_env,
987 int* argument_index_accumulator) {
988 if (hydrogen_env == NULL) return NULL;
990 LEnvironment* outer =
991 CreateEnvironment(hydrogen_env->outer(), argument_index_accumulator);
992 int ast_id = hydrogen_env->ast_id();
993 ASSERT(ast_id != AstNode::kNoNumber);
994 int value_count = hydrogen_env->length();
995 LEnvironment* result = new LEnvironment(hydrogen_env->closure(),
997 hydrogen_env->parameter_count(),
1001 for (int i = 0; i < value_count; ++i) {
1002 if (hydrogen_env->is_special_index(i)) continue;
1004 HValue* value = hydrogen_env->values()->at(i);
1005 LOperand* op = NULL;
1006 if (value->IsArgumentsObject()) {
1008 } else if (value->IsPushArgument()) {
1009 op = new LArgument((*argument_index_accumulator)++);
1013 result->AddValue(op, value->representation());
1020 LInstruction* LChunkBuilder::DoGoto(HGoto* instr) {
1021 return new LGoto(instr->FirstSuccessor()->block_id());
1025 LInstruction* LChunkBuilder::DoBranch(HBranch* instr) {
1026 HValue* v = instr->value();
1027 if (v->EmitAtUses()) {
1028 HBasicBlock* successor = HConstant::cast(v)->ToBoolean()
1029 ? instr->FirstSuccessor()
1030 : instr->SecondSuccessor();
1031 return new LGoto(successor->block_id());
1033 return AssignEnvironment(new LBranch(UseRegister(v)));
1038 LInstruction* LChunkBuilder::DoCompareMap(HCompareMap* instr) {
1039 ASSERT(instr->value()->representation().IsTagged());
1040 LOperand* value = UseRegisterAtStart(instr->value());
1041 LOperand* temp = TempRegister();
1042 return new LCmpMapAndBranch(value, temp);
1046 LInstruction* LChunkBuilder::DoArgumentsLength(HArgumentsLength* length) {
1047 return DefineAsRegister(new LArgumentsLength(UseRegister(length->value())));
1051 LInstruction* LChunkBuilder::DoArgumentsElements(HArgumentsElements* elems) {
1052 return DefineAsRegister(new LArgumentsElements);
1056 LInstruction* LChunkBuilder::DoInstanceOf(HInstanceOf* instr) {
1057 LInstanceOf* result =
1058 new LInstanceOf(UseFixed(instr->left(), r0),
1059 UseFixed(instr->right(), r1));
1060 return MarkAsCall(DefineFixed(result, r0), instr);
1064 LInstruction* LChunkBuilder::DoInstanceOfKnownGlobal(
1065 HInstanceOfKnownGlobal* instr) {
1066 LInstanceOfKnownGlobal* result =
1067 new LInstanceOfKnownGlobal(UseFixed(instr->left(), r0), FixedTemp(r4));
1068 return MarkAsCall(DefineFixed(result, r0), instr);
1072 LInstruction* LChunkBuilder::DoApplyArguments(HApplyArguments* instr) {
1073 LOperand* function = UseFixed(instr->function(), r1);
1074 LOperand* receiver = UseFixed(instr->receiver(), r0);
1075 LOperand* length = UseFixed(instr->length(), r2);
1076 LOperand* elements = UseFixed(instr->elements(), r3);
1077 LApplyArguments* result = new LApplyArguments(function,
1081 return MarkAsCall(DefineFixed(result, r0), instr, CAN_DEOPTIMIZE_EAGERLY);
1085 LInstruction* LChunkBuilder::DoPushArgument(HPushArgument* instr) {
1087 LOperand* argument = Use(instr->argument());
1088 return new LPushArgument(argument);
1092 LInstruction* LChunkBuilder::DoThisFunction(HThisFunction* instr) {
1093 return instr->HasNoUses() ? NULL : DefineAsRegister(new LThisFunction);
1097 LInstruction* LChunkBuilder::DoContext(HContext* instr) {
1098 return instr->HasNoUses() ? NULL : DefineAsRegister(new LContext);
1102 LInstruction* LChunkBuilder::DoOuterContext(HOuterContext* instr) {
1103 LOperand* context = UseRegisterAtStart(instr->value());
1104 return DefineAsRegister(new LOuterContext(context));
1108 LInstruction* LChunkBuilder::DoGlobalObject(HGlobalObject* instr) {
1109 LOperand* context = UseRegisterAtStart(instr->value());
1110 return DefineAsRegister(new LGlobalObject(context, instr->qml_global()));
1114 LInstruction* LChunkBuilder::DoGlobalReceiver(HGlobalReceiver* instr) {
1115 LOperand* global_object = UseRegisterAtStart(instr->value());
1116 return DefineAsRegister(new LGlobalReceiver(global_object));
1120 LInstruction* LChunkBuilder::DoCallConstantFunction(
1121 HCallConstantFunction* instr) {
1122 argument_count_ -= instr->argument_count();
1123 return MarkAsCall(DefineFixed(new LCallConstantFunction, r0), instr);
1127 LInstruction* LChunkBuilder::DoInvokeFunction(HInvokeFunction* instr) {
1128 LOperand* function = UseFixed(instr->function(), r1);
1129 argument_count_ -= instr->argument_count();
1130 LInvokeFunction* result = new LInvokeFunction(function);
1131 return MarkAsCall(DefineFixed(result, r0), instr, CANNOT_DEOPTIMIZE_EAGERLY);
1135 LInstruction* LChunkBuilder::DoUnaryMathOperation(HUnaryMathOperation* instr) {
1136 BuiltinFunctionId op = instr->op();
1137 if (op == kMathLog || op == kMathSin || op == kMathCos) {
1138 LOperand* input = UseFixedDouble(instr->value(), d2);
1139 LUnaryMathOperation* result = new LUnaryMathOperation(input, NULL);
1140 return MarkAsCall(DefineFixedDouble(result, d2), instr);
1142 LOperand* input = UseRegisterAtStart(instr->value());
1143 LOperand* temp = (op == kMathFloor) ? TempRegister() : NULL;
1144 LUnaryMathOperation* result = new LUnaryMathOperation(input, temp);
1147 return AssignEnvironment(AssignPointerMap(DefineAsRegister(result)));
1149 return AssignEnvironment(AssignPointerMap(DefineAsRegister(result)));
1151 return DefineAsRegister(result);
1153 return AssignEnvironment(DefineAsRegister(result));
1155 return DefineAsRegister(result);
1164 LInstruction* LChunkBuilder::DoCallKeyed(HCallKeyed* instr) {
1165 ASSERT(instr->key()->representation().IsTagged());
1166 argument_count_ -= instr->argument_count();
1167 LOperand* key = UseFixed(instr->key(), r2);
1168 return MarkAsCall(DefineFixed(new LCallKeyed(key), r0), instr);
1172 LInstruction* LChunkBuilder::DoCallNamed(HCallNamed* instr) {
1173 argument_count_ -= instr->argument_count();
1174 return MarkAsCall(DefineFixed(new LCallNamed, r0), instr);
1178 LInstruction* LChunkBuilder::DoCallGlobal(HCallGlobal* instr) {
1179 argument_count_ -= instr->argument_count();
1180 return MarkAsCall(DefineFixed(new LCallGlobal(instr->qml_global()), r0), instr);
1184 LInstruction* LChunkBuilder::DoCallKnownGlobal(HCallKnownGlobal* instr) {
1185 argument_count_ -= instr->argument_count();
1186 return MarkAsCall(DefineFixed(new LCallKnownGlobal, r0), instr);
1190 LInstruction* LChunkBuilder::DoCallNew(HCallNew* instr) {
1191 LOperand* constructor = UseFixed(instr->constructor(), r1);
1192 argument_count_ -= instr->argument_count();
1193 LCallNew* result = new LCallNew(constructor);
1194 return MarkAsCall(DefineFixed(result, r0), instr);
1198 LInstruction* LChunkBuilder::DoCallFunction(HCallFunction* instr) {
1199 argument_count_ -= instr->argument_count();
1200 return MarkAsCall(DefineFixed(new LCallFunction, r0), instr);
1204 LInstruction* LChunkBuilder::DoCallRuntime(HCallRuntime* instr) {
1205 argument_count_ -= instr->argument_count();
1206 return MarkAsCall(DefineFixed(new LCallRuntime, r0), instr);
1210 LInstruction* LChunkBuilder::DoShr(HShr* instr) {
1211 return DoShift(Token::SHR, instr);
1215 LInstruction* LChunkBuilder::DoSar(HSar* instr) {
1216 return DoShift(Token::SAR, instr);
1220 LInstruction* LChunkBuilder::DoShl(HShl* instr) {
1221 return DoShift(Token::SHL, instr);
1225 LInstruction* LChunkBuilder::DoBitwise(HBitwise* instr) {
1226 if (instr->representation().IsInteger32()) {
1227 ASSERT(instr->left()->representation().IsInteger32());
1228 ASSERT(instr->right()->representation().IsInteger32());
1230 LOperand* left = UseRegisterAtStart(instr->LeastConstantOperand());
1231 LOperand* right = UseOrConstantAtStart(instr->MostConstantOperand());
1232 return DefineAsRegister(new LBitI(left, right));
1234 ASSERT(instr->representation().IsTagged());
1235 ASSERT(instr->left()->representation().IsTagged());
1236 ASSERT(instr->right()->representation().IsTagged());
1238 LOperand* left = UseFixed(instr->left(), r1);
1239 LOperand* right = UseFixed(instr->right(), r0);
1240 LArithmeticT* result = new LArithmeticT(instr->op(), left, right);
1241 return MarkAsCall(DefineFixed(result, r0), instr);
1246 LInstruction* LChunkBuilder::DoBitNot(HBitNot* instr) {
1247 ASSERT(instr->value()->representation().IsInteger32());
1248 ASSERT(instr->representation().IsInteger32());
1249 return DefineAsRegister(new LBitNotI(UseRegisterAtStart(instr->value())));
1253 LInstruction* LChunkBuilder::DoDiv(HDiv* instr) {
1254 if (instr->representation().IsDouble()) {
1255 return DoArithmeticD(Token::DIV, instr);
1256 } else if (instr->representation().IsInteger32()) {
1257 // TODO(1042) The fixed register allocation
1258 // is needed because we call TypeRecordingBinaryOpStub from
1259 // the generated code, which requires registers r0
1260 // and r1 to be used. We should remove that
1261 // when we provide a native implementation.
1262 LOperand* dividend = UseFixed(instr->left(), r0);
1263 LOperand* divisor = UseFixed(instr->right(), r1);
1264 return AssignEnvironment(AssignPointerMap(
1265 DefineFixed(new LDivI(dividend, divisor), r0)));
1267 return DoArithmeticT(Token::DIV, instr);
1272 LInstruction* LChunkBuilder::DoMod(HMod* instr) {
1273 if (instr->representation().IsInteger32()) {
1274 ASSERT(instr->left()->representation().IsInteger32());
1275 ASSERT(instr->right()->representation().IsInteger32());
1278 if (instr->HasPowerOf2Divisor()) {
1279 ASSERT(!instr->CheckFlag(HValue::kCanBeDivByZero));
1280 LOperand* value = UseRegisterAtStart(instr->left());
1281 mod = new LModI(value, UseOrConstant(instr->right()));
1283 LOperand* dividend = UseRegister(instr->left());
1284 LOperand* divisor = UseRegister(instr->right());
1285 mod = new LModI(dividend,
1292 if (instr->CheckFlag(HValue::kBailoutOnMinusZero) ||
1293 instr->CheckFlag(HValue::kCanBeDivByZero)) {
1294 return AssignEnvironment(DefineAsRegister(mod));
1296 return DefineAsRegister(mod);
1298 } else if (instr->representation().IsTagged()) {
1299 return DoArithmeticT(Token::MOD, instr);
1301 ASSERT(instr->representation().IsDouble());
1302 // We call a C function for double modulo. It can't trigger a GC.
1303 // We need to use fixed result register for the call.
1304 // TODO(fschneider): Allow any register as input registers.
1305 LOperand* left = UseFixedDouble(instr->left(), d1);
1306 LOperand* right = UseFixedDouble(instr->right(), d2);
1307 LArithmeticD* result = new LArithmeticD(Token::MOD, left, right);
1308 return MarkAsCall(DefineFixedDouble(result, d1), instr);
1313 LInstruction* LChunkBuilder::DoMul(HMul* instr) {
1314 if (instr->representation().IsInteger32()) {
1315 ASSERT(instr->left()->representation().IsInteger32());
1316 ASSERT(instr->right()->representation().IsInteger32());
1318 LOperand* right = UseOrConstant(instr->MostConstantOperand());
1319 LOperand* temp = NULL;
1320 if (instr->CheckFlag(HValue::kBailoutOnMinusZero) &&
1321 (instr->CheckFlag(HValue::kCanOverflow) ||
1322 !right->IsConstantOperand())) {
1323 left = UseRegister(instr->LeastConstantOperand());
1324 temp = TempRegister();
1326 left = UseRegisterAtStart(instr->LeastConstantOperand());
1328 return AssignEnvironment(DefineAsRegister(new LMulI(left, right, temp)));
1330 } else if (instr->representation().IsDouble()) {
1331 return DoArithmeticD(Token::MUL, instr);
1334 return DoArithmeticT(Token::MUL, instr);
1339 LInstruction* LChunkBuilder::DoSub(HSub* instr) {
1340 if (instr->representation().IsInteger32()) {
1341 ASSERT(instr->left()->representation().IsInteger32());
1342 ASSERT(instr->right()->representation().IsInteger32());
1343 LOperand* left = UseRegisterAtStart(instr->left());
1344 LOperand* right = UseOrConstantAtStart(instr->right());
1345 LSubI* sub = new LSubI(left, right);
1346 LInstruction* result = DefineAsRegister(sub);
1347 if (instr->CheckFlag(HValue::kCanOverflow)) {
1348 result = AssignEnvironment(result);
1351 } else if (instr->representation().IsDouble()) {
1352 return DoArithmeticD(Token::SUB, instr);
1354 return DoArithmeticT(Token::SUB, instr);
1359 LInstruction* LChunkBuilder::DoAdd(HAdd* instr) {
1360 if (instr->representation().IsInteger32()) {
1361 ASSERT(instr->left()->representation().IsInteger32());
1362 ASSERT(instr->right()->representation().IsInteger32());
1363 LOperand* left = UseRegisterAtStart(instr->LeastConstantOperand());
1364 LOperand* right = UseOrConstantAtStart(instr->MostConstantOperand());
1365 LAddI* add = new LAddI(left, right);
1366 LInstruction* result = DefineAsRegister(add);
1367 if (instr->CheckFlag(HValue::kCanOverflow)) {
1368 result = AssignEnvironment(result);
1371 } else if (instr->representation().IsDouble()) {
1372 return DoArithmeticD(Token::ADD, instr);
1374 ASSERT(instr->representation().IsTagged());
1375 return DoArithmeticT(Token::ADD, instr);
1380 LInstruction* LChunkBuilder::DoPower(HPower* instr) {
1381 ASSERT(instr->representation().IsDouble());
1382 // We call a C function for double power. It can't trigger a GC.
1383 // We need to use fixed result register for the call.
1384 Representation exponent_type = instr->right()->representation();
1385 ASSERT(instr->left()->representation().IsDouble());
1386 LOperand* left = UseFixedDouble(instr->left(), d1);
1387 LOperand* right = exponent_type.IsDouble() ?
1388 UseFixedDouble(instr->right(), d2) :
1389 UseFixed(instr->right(), r0);
1390 LPower* result = new LPower(left, right);
1391 return MarkAsCall(DefineFixedDouble(result, d3),
1393 CAN_DEOPTIMIZE_EAGERLY);
1397 LInstruction* LChunkBuilder::DoCompareGeneric(HCompareGeneric* instr) {
1398 ASSERT(instr->left()->representation().IsTagged());
1399 ASSERT(instr->right()->representation().IsTagged());
1400 LOperand* left = UseFixed(instr->left(), r1);
1401 LOperand* right = UseFixed(instr->right(), r0);
1402 LCmpT* result = new LCmpT(left, right);
1403 return MarkAsCall(DefineFixed(result, r0), instr);
1407 LInstruction* LChunkBuilder::DoCompareIDAndBranch(
1408 HCompareIDAndBranch* instr) {
1409 Representation r = instr->GetInputRepresentation();
1410 if (r.IsInteger32()) {
1411 ASSERT(instr->left()->representation().IsInteger32());
1412 ASSERT(instr->right()->representation().IsInteger32());
1413 LOperand* left = UseRegisterOrConstantAtStart(instr->left());
1414 LOperand* right = UseRegisterOrConstantAtStart(instr->right());
1415 return new LCmpIDAndBranch(left, right);
1417 ASSERT(r.IsDouble());
1418 ASSERT(instr->left()->representation().IsDouble());
1419 ASSERT(instr->right()->representation().IsDouble());
1420 LOperand* left = UseRegisterAtStart(instr->left());
1421 LOperand* right = UseRegisterAtStart(instr->right());
1422 return new LCmpIDAndBranch(left, right);
1427 LInstruction* LChunkBuilder::DoCompareObjectEqAndBranch(
1428 HCompareObjectEqAndBranch* instr) {
1429 LOperand* left = UseRegisterAtStart(instr->left());
1430 LOperand* right = UseRegisterAtStart(instr->right());
1431 return new LCmpObjectEqAndBranch(left, right);
1435 LInstruction* LChunkBuilder::DoCompareConstantEqAndBranch(
1436 HCompareConstantEqAndBranch* instr) {
1437 return new LCmpConstantEqAndBranch(UseRegisterAtStart(instr->value()));
1441 LInstruction* LChunkBuilder::DoIsNilAndBranch(HIsNilAndBranch* instr) {
1442 ASSERT(instr->value()->representation().IsTagged());
1443 return new LIsNilAndBranch(UseRegisterAtStart(instr->value()));
1447 LInstruction* LChunkBuilder::DoIsObjectAndBranch(HIsObjectAndBranch* instr) {
1448 ASSERT(instr->value()->representation().IsTagged());
1449 LOperand* temp = TempRegister();
1450 return new LIsObjectAndBranch(UseRegisterAtStart(instr->value()), temp);
1454 LInstruction* LChunkBuilder::DoIsSmiAndBranch(HIsSmiAndBranch* instr) {
1455 ASSERT(instr->value()->representation().IsTagged());
1456 return new LIsSmiAndBranch(Use(instr->value()));
1460 LInstruction* LChunkBuilder::DoIsUndetectableAndBranch(
1461 HIsUndetectableAndBranch* instr) {
1462 ASSERT(instr->value()->representation().IsTagged());
1463 return new LIsUndetectableAndBranch(UseRegisterAtStart(instr->value()),
1468 LInstruction* LChunkBuilder::DoHasInstanceTypeAndBranch(
1469 HHasInstanceTypeAndBranch* instr) {
1470 ASSERT(instr->value()->representation().IsTagged());
1471 return new LHasInstanceTypeAndBranch(UseRegisterAtStart(instr->value()));
1475 LInstruction* LChunkBuilder::DoGetCachedArrayIndex(
1476 HGetCachedArrayIndex* instr) {
1477 ASSERT(instr->value()->representation().IsTagged());
1478 LOperand* value = UseRegisterAtStart(instr->value());
1480 return DefineAsRegister(new LGetCachedArrayIndex(value));
1484 LInstruction* LChunkBuilder::DoHasCachedArrayIndexAndBranch(
1485 HHasCachedArrayIndexAndBranch* instr) {
1486 ASSERT(instr->value()->representation().IsTagged());
1487 return new LHasCachedArrayIndexAndBranch(
1488 UseRegisterAtStart(instr->value()));
1492 LInstruction* LChunkBuilder::DoClassOfTestAndBranch(
1493 HClassOfTestAndBranch* instr) {
1494 ASSERT(instr->value()->representation().IsTagged());
1495 return new LClassOfTestAndBranch(UseTempRegister(instr->value()),
1500 LInstruction* LChunkBuilder::DoJSArrayLength(HJSArrayLength* instr) {
1501 LOperand* array = UseRegisterAtStart(instr->value());
1502 return DefineAsRegister(new LJSArrayLength(array));
1506 LInstruction* LChunkBuilder::DoFixedArrayBaseLength(
1507 HFixedArrayBaseLength* instr) {
1508 LOperand* array = UseRegisterAtStart(instr->value());
1509 return DefineAsRegister(new LFixedArrayBaseLength(array));
1513 LInstruction* LChunkBuilder::DoElementsKind(HElementsKind* instr) {
1514 LOperand* object = UseRegisterAtStart(instr->value());
1515 return DefineAsRegister(new LElementsKind(object));
1519 LInstruction* LChunkBuilder::DoValueOf(HValueOf* instr) {
1520 LOperand* object = UseRegister(instr->value());
1521 LValueOf* result = new LValueOf(object, TempRegister());
1522 return AssignEnvironment(DefineAsRegister(result));
1526 LInstruction* LChunkBuilder::DoBoundsCheck(HBoundsCheck* instr) {
1527 return AssignEnvironment(new LBoundsCheck(UseRegisterAtStart(instr->index()),
1528 UseRegister(instr->length())));
1532 LInstruction* LChunkBuilder::DoAbnormalExit(HAbnormalExit* instr) {
1533 // The control instruction marking the end of a block that completed
1534 // abruptly (e.g., threw an exception). There is nothing specific to do.
1539 LInstruction* LChunkBuilder::DoThrow(HThrow* instr) {
1540 LOperand* value = UseFixed(instr->value(), r0);
1541 return MarkAsCall(new LThrow(value), instr);
1545 LInstruction* LChunkBuilder::DoUseConst(HUseConst* instr) {
1550 LInstruction* LChunkBuilder::DoForceRepresentation(HForceRepresentation* bad) {
1551 // All HForceRepresentation instructions should be eliminated in the
1552 // representation change phase of Hydrogen.
1558 LInstruction* LChunkBuilder::DoChange(HChange* instr) {
1559 Representation from = instr->from();
1560 Representation to = instr->to();
1561 if (from.IsTagged()) {
1562 if (to.IsDouble()) {
1563 LOperand* value = UseRegister(instr->value());
1564 LNumberUntagD* res = new LNumberUntagD(value);
1565 return AssignEnvironment(DefineAsRegister(res));
1567 ASSERT(to.IsInteger32());
1568 LOperand* value = UseRegister(instr->value());
1569 bool needs_check = !instr->value()->type().IsSmi();
1570 LInstruction* res = NULL;
1572 res = DefineSameAsFirst(new LSmiUntag(value, needs_check));
1574 LOperand* temp1 = TempRegister();
1575 LOperand* temp2 = instr->CanTruncateToInt32() ? TempRegister()
1577 LOperand* temp3 = instr->CanTruncateToInt32() ? FixedTemp(d11)
1579 res = DefineSameAsFirst(new LTaggedToI(value, temp1, temp2, temp3));
1580 res = AssignEnvironment(res);
1584 } else if (from.IsDouble()) {
1585 if (to.IsTagged()) {
1586 LOperand* value = UseRegister(instr->value());
1587 LOperand* temp1 = TempRegister();
1588 LOperand* temp2 = TempRegister();
1590 // Make sure that the temp and result_temp registers are
1592 LUnallocated* result_temp = TempRegister();
1593 LNumberTagD* result = new LNumberTagD(value, temp1, temp2);
1594 Define(result, result_temp);
1595 return AssignPointerMap(result);
1597 ASSERT(to.IsInteger32());
1598 LOperand* value = UseRegister(instr->value());
1600 new LDoubleToI(value,
1602 instr->CanTruncateToInt32() ? TempRegister() : NULL);
1603 return AssignEnvironment(DefineAsRegister(res));
1605 } else if (from.IsInteger32()) {
1606 if (to.IsTagged()) {
1607 HValue* val = instr->value();
1608 LOperand* value = UseRegister(val);
1609 if (val->HasRange() && val->range()->IsInSmiRange()) {
1610 return DefineSameAsFirst(new LSmiTag(value));
1612 LNumberTagI* result = new LNumberTagI(value);
1613 return AssignEnvironment(AssignPointerMap(DefineSameAsFirst(result)));
1616 ASSERT(to.IsDouble());
1617 LOperand* value = Use(instr->value());
1618 return DefineAsRegister(new LInteger32ToDouble(value));
1626 LInstruction* LChunkBuilder::DoCheckNonSmi(HCheckNonSmi* instr) {
1627 LOperand* value = UseRegisterAtStart(instr->value());
1628 return AssignEnvironment(new LCheckNonSmi(value));
1632 LInstruction* LChunkBuilder::DoCheckInstanceType(HCheckInstanceType* instr) {
1633 LOperand* value = UseRegisterAtStart(instr->value());
1634 LInstruction* result = new LCheckInstanceType(value);
1635 return AssignEnvironment(result);
1639 LInstruction* LChunkBuilder::DoCheckPrototypeMaps(HCheckPrototypeMaps* instr) {
1640 LOperand* temp1 = TempRegister();
1641 LOperand* temp2 = TempRegister();
1642 LInstruction* result = new LCheckPrototypeMaps(temp1, temp2);
1643 return AssignEnvironment(result);
1647 LInstruction* LChunkBuilder::DoCheckSmi(HCheckSmi* instr) {
1648 LOperand* value = UseRegisterAtStart(instr->value());
1649 return AssignEnvironment(new LCheckSmi(value));
1653 LInstruction* LChunkBuilder::DoCheckFunction(HCheckFunction* instr) {
1654 LOperand* value = UseRegisterAtStart(instr->value());
1655 return AssignEnvironment(new LCheckFunction(value));
1659 LInstruction* LChunkBuilder::DoCheckMap(HCheckMap* instr) {
1660 LOperand* value = UseRegisterAtStart(instr->value());
1661 LInstruction* result = new LCheckMap(value);
1662 return AssignEnvironment(result);
1666 LInstruction* LChunkBuilder::DoClampToUint8(HClampToUint8* instr) {
1667 HValue* value = instr->value();
1668 Representation input_rep = value->representation();
1669 LOperand* reg = UseRegister(value);
1670 if (input_rep.IsDouble()) {
1671 return DefineAsRegister(new LClampDToUint8(reg, FixedTemp(d11)));
1672 } else if (input_rep.IsInteger32()) {
1673 return DefineAsRegister(new LClampIToUint8(reg));
1675 ASSERT(input_rep.IsTagged());
1676 // Register allocator doesn't (yet) support allocation of double
1677 // temps. Reserve d1 explicitly.
1678 LClampTToUint8* result = new LClampTToUint8(reg, FixedTemp(d11));
1679 return AssignEnvironment(DefineAsRegister(result));
1684 LInstruction* LChunkBuilder::DoToInt32(HToInt32* instr) {
1685 HValue* value = instr->value();
1686 Representation input_rep = value->representation();
1687 LOperand* reg = UseRegister(value);
1688 if (input_rep.IsDouble()) {
1689 LOperand* temp1 = TempRegister();
1690 LOperand* temp2 = TempRegister();
1691 LDoubleToI* res = new LDoubleToI(reg, temp1, temp2);
1692 return AssignEnvironment(DefineAsRegister(res));
1693 } else if (input_rep.IsInteger32()) {
1694 // Canonicalization should already have removed the hydrogen instruction in
1695 // this case, since it is a noop.
1699 ASSERT(input_rep.IsTagged());
1700 LOperand* temp1 = TempRegister();
1701 LOperand* temp2 = TempRegister();
1702 LOperand* temp3 = FixedTemp(d11);
1703 LTaggedToI* res = new LTaggedToI(reg, temp1, temp2, temp3);
1704 return AssignEnvironment(DefineSameAsFirst(res));
1709 LInstruction* LChunkBuilder::DoReturn(HReturn* instr) {
1710 return new LReturn(UseFixed(instr->value(), r0));
1714 LInstruction* LChunkBuilder::DoConstant(HConstant* instr) {
1715 Representation r = instr->representation();
1716 if (r.IsInteger32()) {
1717 return DefineAsRegister(new LConstantI);
1718 } else if (r.IsDouble()) {
1719 return DefineAsRegister(new LConstantD);
1720 } else if (r.IsTagged()) {
1721 return DefineAsRegister(new LConstantT);
1729 LInstruction* LChunkBuilder::DoLoadGlobalCell(HLoadGlobalCell* instr) {
1730 LLoadGlobalCell* result = new LLoadGlobalCell;
1731 return instr->RequiresHoleCheck()
1732 ? AssignEnvironment(DefineAsRegister(result))
1733 : DefineAsRegister(result);
1737 LInstruction* LChunkBuilder::DoLoadGlobalGeneric(HLoadGlobalGeneric* instr) {
1738 LOperand* global_object = UseFixed(instr->global_object(), r0);
1739 LLoadGlobalGeneric* result = new LLoadGlobalGeneric(global_object);
1740 return MarkAsCall(DefineFixed(result, r0), instr);
1744 LInstruction* LChunkBuilder::DoStoreGlobalCell(HStoreGlobalCell* instr) {
1745 LOperand* temp = TempRegister();
1746 LOperand* value = UseTempRegister(instr->value());
1747 LInstruction* result = new LStoreGlobalCell(value, temp);
1748 if (instr->RequiresHoleCheck()) result = AssignEnvironment(result);
1753 LInstruction* LChunkBuilder::DoStoreGlobalGeneric(HStoreGlobalGeneric* instr) {
1754 LOperand* global_object = UseFixed(instr->global_object(), r1);
1755 LOperand* value = UseFixed(instr->value(), r0);
1756 LStoreGlobalGeneric* result =
1757 new LStoreGlobalGeneric(global_object, value);
1758 return MarkAsCall(result, instr);
1762 LInstruction* LChunkBuilder::DoLoadContextSlot(HLoadContextSlot* instr) {
1763 LOperand* context = UseRegisterAtStart(instr->value());
1764 return DefineAsRegister(new LLoadContextSlot(context));
1768 LInstruction* LChunkBuilder::DoStoreContextSlot(HStoreContextSlot* instr) {
1771 if (instr->NeedsWriteBarrier()) {
1772 context = UseTempRegister(instr->context());
1773 value = UseTempRegister(instr->value());
1775 context = UseRegister(instr->context());
1776 value = UseRegister(instr->value());
1778 return new LStoreContextSlot(context, value);
1782 LInstruction* LChunkBuilder::DoLoadNamedField(HLoadNamedField* instr) {
1783 return DefineAsRegister(
1784 new LLoadNamedField(UseRegisterAtStart(instr->object())));
1788 LInstruction* LChunkBuilder::DoLoadNamedFieldPolymorphic(
1789 HLoadNamedFieldPolymorphic* instr) {
1790 ASSERT(instr->representation().IsTagged());
1791 if (instr->need_generic()) {
1792 LOperand* obj = UseFixed(instr->object(), r0);
1793 LLoadNamedFieldPolymorphic* result = new LLoadNamedFieldPolymorphic(obj);
1794 return MarkAsCall(DefineFixed(result, r0), instr);
1796 LOperand* obj = UseRegisterAtStart(instr->object());
1797 LLoadNamedFieldPolymorphic* result = new LLoadNamedFieldPolymorphic(obj);
1798 return AssignEnvironment(DefineAsRegister(result));
1803 LInstruction* LChunkBuilder::DoLoadNamedGeneric(HLoadNamedGeneric* instr) {
1804 LOperand* object = UseFixed(instr->object(), r0);
1805 LInstruction* result = DefineFixed(new LLoadNamedGeneric(object), r0);
1806 return MarkAsCall(result, instr);
1810 LInstruction* LChunkBuilder::DoLoadFunctionPrototype(
1811 HLoadFunctionPrototype* instr) {
1812 return AssignEnvironment(DefineAsRegister(
1813 new LLoadFunctionPrototype(UseRegister(instr->function()))));
1817 LInstruction* LChunkBuilder::DoLoadElements(HLoadElements* instr) {
1818 LOperand* input = UseRegisterAtStart(instr->value());
1819 return DefineAsRegister(new LLoadElements(input));
1823 LInstruction* LChunkBuilder::DoLoadExternalArrayPointer(
1824 HLoadExternalArrayPointer* instr) {
1825 LOperand* input = UseRegisterAtStart(instr->value());
1826 return DefineAsRegister(new LLoadExternalArrayPointer(input));
1830 LInstruction* LChunkBuilder::DoLoadKeyedFastElement(
1831 HLoadKeyedFastElement* instr) {
1832 ASSERT(instr->representation().IsTagged());
1833 ASSERT(instr->key()->representation().IsInteger32());
1834 LOperand* obj = UseRegisterAtStart(instr->object());
1835 LOperand* key = UseRegisterAtStart(instr->key());
1836 LLoadKeyedFastElement* result = new LLoadKeyedFastElement(obj, key);
1837 return AssignEnvironment(DefineAsRegister(result));
1841 LInstruction* LChunkBuilder::DoLoadKeyedFastDoubleElement(
1842 HLoadKeyedFastDoubleElement* instr) {
1843 ASSERT(instr->representation().IsDouble());
1844 ASSERT(instr->key()->representation().IsInteger32());
1845 LOperand* elements = UseTempRegister(instr->elements());
1846 LOperand* key = UseRegisterOrConstantAtStart(instr->key());
1847 LLoadKeyedFastDoubleElement* result =
1848 new LLoadKeyedFastDoubleElement(elements, key);
1849 return AssignEnvironment(DefineAsRegister(result));
1853 LInstruction* LChunkBuilder::DoLoadKeyedSpecializedArrayElement(
1854 HLoadKeyedSpecializedArrayElement* instr) {
1855 ElementsKind elements_kind = instr->elements_kind();
1856 Representation representation(instr->representation());
1858 (representation.IsInteger32() &&
1859 (elements_kind != EXTERNAL_FLOAT_ELEMENTS) &&
1860 (elements_kind != EXTERNAL_DOUBLE_ELEMENTS)) ||
1861 (representation.IsDouble() &&
1862 ((elements_kind == EXTERNAL_FLOAT_ELEMENTS) ||
1863 (elements_kind == EXTERNAL_DOUBLE_ELEMENTS))));
1864 ASSERT(instr->key()->representation().IsInteger32());
1865 LOperand* external_pointer = UseRegister(instr->external_pointer());
1866 LOperand* key = UseRegisterOrConstant(instr->key());
1867 LLoadKeyedSpecializedArrayElement* result =
1868 new LLoadKeyedSpecializedArrayElement(external_pointer, key);
1869 LInstruction* load_instr = DefineAsRegister(result);
1870 // An unsigned int array load might overflow and cause a deopt, make sure it
1871 // has an environment.
1872 return (elements_kind == EXTERNAL_UNSIGNED_INT_ELEMENTS) ?
1873 AssignEnvironment(load_instr) : load_instr;
1877 LInstruction* LChunkBuilder::DoLoadKeyedGeneric(HLoadKeyedGeneric* instr) {
1878 LOperand* object = UseFixed(instr->object(), r1);
1879 LOperand* key = UseFixed(instr->key(), r0);
1881 LInstruction* result =
1882 DefineFixed(new LLoadKeyedGeneric(object, key), r0);
1883 return MarkAsCall(result, instr);
1887 LInstruction* LChunkBuilder::DoStoreKeyedFastElement(
1888 HStoreKeyedFastElement* instr) {
1889 bool needs_write_barrier = instr->NeedsWriteBarrier();
1890 ASSERT(instr->value()->representation().IsTagged());
1891 ASSERT(instr->object()->representation().IsTagged());
1892 ASSERT(instr->key()->representation().IsInteger32());
1894 LOperand* obj = UseTempRegister(instr->object());
1895 LOperand* val = needs_write_barrier
1896 ? UseTempRegister(instr->value())
1897 : UseRegisterAtStart(instr->value());
1898 LOperand* key = needs_write_barrier
1899 ? UseTempRegister(instr->key())
1900 : UseRegisterOrConstantAtStart(instr->key());
1902 return AssignEnvironment(new LStoreKeyedFastElement(obj, key, val));
1906 LInstruction* LChunkBuilder::DoStoreKeyedFastDoubleElement(
1907 HStoreKeyedFastDoubleElement* instr) {
1908 ASSERT(instr->value()->representation().IsDouble());
1909 ASSERT(instr->elements()->representation().IsTagged());
1910 ASSERT(instr->key()->representation().IsInteger32());
1912 LOperand* elements = UseRegisterAtStart(instr->elements());
1913 LOperand* val = UseTempRegister(instr->value());
1914 LOperand* key = UseRegisterOrConstantAtStart(instr->key());
1916 return new LStoreKeyedFastDoubleElement(elements, key, val);
1920 LInstruction* LChunkBuilder::DoStoreKeyedSpecializedArrayElement(
1921 HStoreKeyedSpecializedArrayElement* instr) {
1922 Representation representation(instr->value()->representation());
1923 ElementsKind elements_kind = instr->elements_kind();
1925 (representation.IsInteger32() &&
1926 (elements_kind != EXTERNAL_FLOAT_ELEMENTS) &&
1927 (elements_kind != EXTERNAL_DOUBLE_ELEMENTS)) ||
1928 (representation.IsDouble() &&
1929 ((elements_kind == EXTERNAL_FLOAT_ELEMENTS) ||
1930 (elements_kind == EXTERNAL_DOUBLE_ELEMENTS))));
1931 ASSERT(instr->external_pointer()->representation().IsExternal());
1932 ASSERT(instr->key()->representation().IsInteger32());
1934 LOperand* external_pointer = UseRegister(instr->external_pointer());
1935 bool val_is_temp_register =
1936 elements_kind == EXTERNAL_PIXEL_ELEMENTS ||
1937 elements_kind == EXTERNAL_FLOAT_ELEMENTS;
1938 LOperand* val = val_is_temp_register
1939 ? UseTempRegister(instr->value())
1940 : UseRegister(instr->value());
1941 LOperand* key = UseRegisterOrConstant(instr->key());
1943 return new LStoreKeyedSpecializedArrayElement(external_pointer,
1949 LInstruction* LChunkBuilder::DoStoreKeyedGeneric(HStoreKeyedGeneric* instr) {
1950 LOperand* obj = UseFixed(instr->object(), r2);
1951 LOperand* key = UseFixed(instr->key(), r1);
1952 LOperand* val = UseFixed(instr->value(), r0);
1954 ASSERT(instr->object()->representation().IsTagged());
1955 ASSERT(instr->key()->representation().IsTagged());
1956 ASSERT(instr->value()->representation().IsTagged());
1958 return MarkAsCall(new LStoreKeyedGeneric(obj, key, val), instr);
1962 LInstruction* LChunkBuilder::DoTransitionElementsKind(
1963 HTransitionElementsKind* instr) {
1964 if (instr->original_map()->elements_kind() == FAST_SMI_ONLY_ELEMENTS &&
1965 instr->transitioned_map()->elements_kind() == FAST_ELEMENTS) {
1966 LOperand* object = UseRegister(instr->object());
1967 LOperand* new_map_reg = TempRegister();
1968 LTransitionElementsKind* result =
1969 new LTransitionElementsKind(object, new_map_reg, NULL);
1970 return DefineSameAsFirst(result);
1972 LOperand* object = UseFixed(instr->object(), r0);
1973 LOperand* fixed_object_reg = FixedTemp(r2);
1974 LOperand* new_map_reg = FixedTemp(r3);
1975 LTransitionElementsKind* result =
1976 new LTransitionElementsKind(object, new_map_reg, fixed_object_reg);
1977 return MarkAsCall(DefineFixed(result, r0), instr);
1982 LInstruction* LChunkBuilder::DoStoreNamedField(HStoreNamedField* instr) {
1983 bool needs_write_barrier = instr->NeedsWriteBarrier();
1985 LOperand* obj = needs_write_barrier
1986 ? UseTempRegister(instr->object())
1987 : UseRegisterAtStart(instr->object());
1989 LOperand* val = needs_write_barrier
1990 ? UseTempRegister(instr->value())
1991 : UseRegister(instr->value());
1993 return new LStoreNamedField(obj, val);
1997 LInstruction* LChunkBuilder::DoStoreNamedGeneric(HStoreNamedGeneric* instr) {
1998 LOperand* obj = UseFixed(instr->object(), r1);
1999 LOperand* val = UseFixed(instr->value(), r0);
2001 LInstruction* result = new LStoreNamedGeneric(obj, val);
2002 return MarkAsCall(result, instr);
2006 LInstruction* LChunkBuilder::DoStringAdd(HStringAdd* instr) {
2007 LOperand* left = UseRegisterAtStart(instr->left());
2008 LOperand* right = UseRegisterAtStart(instr->right());
2009 return MarkAsCall(DefineFixed(new LStringAdd(left, right), r0), instr);
2013 LInstruction* LChunkBuilder::DoStringCharCodeAt(HStringCharCodeAt* instr) {
2014 LOperand* string = UseTempRegister(instr->string());
2015 LOperand* index = UseTempRegister(instr->index());
2016 LStringCharCodeAt* result = new LStringCharCodeAt(string, index);
2017 return AssignEnvironment(AssignPointerMap(DefineAsRegister(result)));
2021 LInstruction* LChunkBuilder::DoStringCharFromCode(HStringCharFromCode* instr) {
2022 LOperand* char_code = UseRegister(instr->value());
2023 LStringCharFromCode* result = new LStringCharFromCode(char_code);
2024 return AssignPointerMap(DefineAsRegister(result));
2028 LInstruction* LChunkBuilder::DoStringLength(HStringLength* instr) {
2029 LOperand* string = UseRegisterAtStart(instr->value());
2030 return DefineAsRegister(new LStringLength(string));
2034 LInstruction* LChunkBuilder::DoArrayLiteral(HArrayLiteral* instr) {
2035 return MarkAsCall(DefineFixed(new LArrayLiteral, r0), instr);
2039 LInstruction* LChunkBuilder::DoObjectLiteral(HObjectLiteral* instr) {
2040 return MarkAsCall(DefineFixed(new LObjectLiteral, r0), instr);
2044 LInstruction* LChunkBuilder::DoRegExpLiteral(HRegExpLiteral* instr) {
2045 return MarkAsCall(DefineFixed(new LRegExpLiteral, r0), instr);
2049 LInstruction* LChunkBuilder::DoFunctionLiteral(HFunctionLiteral* instr) {
2050 return MarkAsCall(DefineFixed(new LFunctionLiteral, r0), instr);
2054 LInstruction* LChunkBuilder::DoDeleteProperty(HDeleteProperty* instr) {
2055 LOperand* object = UseFixed(instr->object(), r0);
2056 LOperand* key = UseFixed(instr->key(), r1);
2057 LDeleteProperty* result = new LDeleteProperty(object, key);
2058 return MarkAsCall(DefineFixed(result, r0), instr);
2062 LInstruction* LChunkBuilder::DoOsrEntry(HOsrEntry* instr) {
2063 allocator_->MarkAsOsrEntry();
2064 current_block_->last_environment()->set_ast_id(instr->ast_id());
2065 return AssignEnvironment(new LOsrEntry);
2069 LInstruction* LChunkBuilder::DoParameter(HParameter* instr) {
2070 int spill_index = chunk()->GetParameterStackSlot(instr->index());
2071 return DefineAsSpilled(new LParameter, spill_index);
2075 LInstruction* LChunkBuilder::DoUnknownOSRValue(HUnknownOSRValue* instr) {
2076 int spill_index = chunk()->GetNextSpillIndex(false); // Not double-width.
2077 if (spill_index > LUnallocated::kMaxFixedIndex) {
2078 Abort("Too many spill slots needed for OSR");
2081 return DefineAsSpilled(new LUnknownOSRValue, spill_index);
2085 LInstruction* LChunkBuilder::DoCallStub(HCallStub* instr) {
2086 argument_count_ -= instr->argument_count();
2087 return MarkAsCall(DefineFixed(new LCallStub, r0), instr);
2091 LInstruction* LChunkBuilder::DoArgumentsObject(HArgumentsObject* instr) {
2092 // There are no real uses of the arguments object.
2093 // arguments.length and element access are supported directly on
2094 // stack arguments, and any real arguments object use causes a bailout.
2095 // So this value is never used.
2100 LInstruction* LChunkBuilder::DoAccessArgumentsAt(HAccessArgumentsAt* instr) {
2101 LOperand* arguments = UseRegister(instr->arguments());
2102 LOperand* length = UseTempRegister(instr->length());
2103 LOperand* index = UseRegister(instr->index());
2104 LAccessArgumentsAt* result = new LAccessArgumentsAt(arguments, length, index);
2105 return AssignEnvironment(DefineAsRegister(result));
2109 LInstruction* LChunkBuilder::DoToFastProperties(HToFastProperties* instr) {
2110 LOperand* object = UseFixed(instr->value(), r0);
2111 LToFastProperties* result = new LToFastProperties(object);
2112 return MarkAsCall(DefineFixed(result, r0), instr);
2116 LInstruction* LChunkBuilder::DoTypeof(HTypeof* instr) {
2117 LTypeof* result = new LTypeof(UseFixed(instr->value(), r0));
2118 return MarkAsCall(DefineFixed(result, r0), instr);
2122 LInstruction* LChunkBuilder::DoTypeofIsAndBranch(HTypeofIsAndBranch* instr) {
2123 return new LTypeofIsAndBranch(UseTempRegister(instr->value()));
2127 LInstruction* LChunkBuilder::DoIsConstructCallAndBranch(
2128 HIsConstructCallAndBranch* instr) {
2129 return new LIsConstructCallAndBranch(TempRegister());
2133 LInstruction* LChunkBuilder::DoSimulate(HSimulate* instr) {
2134 HEnvironment* env = current_block_->last_environment();
2135 ASSERT(env != NULL);
2137 env->set_ast_id(instr->ast_id());
2139 env->Drop(instr->pop_count());
2140 for (int i = 0; i < instr->values()->length(); ++i) {
2141 HValue* value = instr->values()->at(i);
2142 if (instr->HasAssignedIndexAt(i)) {
2143 env->Bind(instr->GetAssignedIndexAt(i), value);
2149 // If there is an instruction pending deoptimization environment create a
2150 // lazy bailout instruction to capture the environment.
2151 if (pending_deoptimization_ast_id_ == instr->ast_id()) {
2152 LInstruction* result = new LLazyBailout;
2153 result = AssignEnvironment(result);
2154 instruction_pending_deoptimization_environment_->
2155 set_deoptimization_environment(result->environment());
2156 ClearInstructionPendingDeoptimizationEnvironment();
2164 LInstruction* LChunkBuilder::DoStackCheck(HStackCheck* instr) {
2165 if (instr->is_function_entry()) {
2166 return MarkAsCall(new LStackCheck, instr);
2168 ASSERT(instr->is_backwards_branch());
2169 return AssignEnvironment(AssignPointerMap(new LStackCheck));
2174 LInstruction* LChunkBuilder::DoEnterInlined(HEnterInlined* instr) {
2175 HEnvironment* outer = current_block_->last_environment();
2176 HConstant* undefined = graph()->GetConstantUndefined();
2177 HEnvironment* inner = outer->CopyForInlining(instr->closure(),
2180 instr->call_kind());
2181 current_block_->UpdateEnvironment(inner);
2182 chunk_->AddInlinedClosure(instr->closure());
2187 LInstruction* LChunkBuilder::DoLeaveInlined(HLeaveInlined* instr) {
2188 HEnvironment* outer = current_block_->last_environment()->outer();
2189 current_block_->UpdateEnvironment(outer);
2194 LInstruction* LChunkBuilder::DoIn(HIn* instr) {
2195 LOperand* key = UseRegisterAtStart(instr->key());
2196 LOperand* object = UseRegisterAtStart(instr->object());
2197 LIn* result = new LIn(key, object);
2198 return MarkAsCall(DefineFixed(result, r0), instr);
2202 } } // namespace v8::internal