blob: a18f8771875730b9da6ffaef145236732d0e9e04 [file] [log] [blame]
Ben Murdochda12d292016-06-02 14:46:10 +01001// 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.
4
5#include "src/crankshaft/s390/lithium-s390.h"
6
7#include <sstream>
8
9#include "src/crankshaft/hydrogen-osr.h"
10#include "src/crankshaft/lithium-inl.h"
11#include "src/crankshaft/s390/lithium-codegen-s390.h"
12
13namespace v8 {
14namespace internal {
15
16#define DEFINE_COMPILE(type) \
17 void L##type::CompileToNative(LCodeGen* generator) { \
18 generator->Do##type(this); \
19 }
20LITHIUM_CONCRETE_INSTRUCTION_LIST(DEFINE_COMPILE)
21#undef DEFINE_COMPILE
22
23#ifdef DEBUG
24void 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());
34 }
35 for (TempIterator it(this); !it.Done(); it.Advance()) {
36 LUnallocated* operand = LUnallocated::cast(it.Current());
37 DCHECK(operand->HasFixedPolicy() || !operand->HasRegisterPolicy());
38 }
39}
40#endif
41
42void LInstruction::PrintTo(StringStream* stream) {
43 stream->Add("%s ", this->Mnemonic());
44
45 PrintOutputOperandTo(stream);
46
47 PrintDataTo(stream);
48
49 if (HasEnvironment()) {
50 stream->Add(" ");
51 environment()->PrintTo(stream);
52 }
53
54 if (HasPointerMap()) {
55 stream->Add(" ");
56 pointer_map()->PrintTo(stream);
57 }
58}
59
60void LInstruction::PrintDataTo(StringStream* stream) {
61 stream->Add("= ");
62 for (int i = 0; i < InputCount(); i++) {
63 if (i > 0) stream->Add(" ");
64 if (InputAt(i) == NULL) {
65 stream->Add("NULL");
66 } else {
67 InputAt(i)->PrintTo(stream);
68 }
69 }
70}
71
72void LInstruction::PrintOutputOperandTo(StringStream* stream) {
73 if (HasResult()) result()->PrintTo(stream);
74}
75
76void LLabel::PrintDataTo(StringStream* stream) {
77 LGap::PrintDataTo(stream);
78 LLabel* rep = replacement();
79 if (rep != NULL) {
80 stream->Add(" Dead block replaced with B%d", rep->block_id());
81 }
82}
83
84bool LGap::IsRedundant() const {
85 for (int i = 0; i < 4; i++) {
86 if (parallel_moves_[i] != NULL && !parallel_moves_[i]->IsRedundant()) {
87 return false;
88 }
89 }
90
91 return true;
92}
93
94void LGap::PrintDataTo(StringStream* stream) {
95 for (int i = 0; i < 4; i++) {
96 stream->Add("(");
97 if (parallel_moves_[i] != NULL) {
98 parallel_moves_[i]->PrintDataTo(stream);
99 }
100 stream->Add(") ");
101 }
102}
103
104const char* LArithmeticD::Mnemonic() const {
105 switch (op()) {
106 case Token::ADD:
107 return "add-d";
108 case Token::SUB:
109 return "sub-d";
110 case Token::MUL:
111 return "mul-d";
112 case Token::DIV:
113 return "div-d";
114 case Token::MOD:
115 return "mod-d";
116 default:
117 UNREACHABLE();
118 return NULL;
119 }
120}
121
122const char* LArithmeticT::Mnemonic() const {
123 switch (op()) {
124 case Token::ADD:
125 return "add-t";
126 case Token::SUB:
127 return "sub-t";
128 case Token::MUL:
129 return "mul-t";
130 case Token::MOD:
131 return "mod-t";
132 case Token::DIV:
133 return "div-t";
134 case Token::BIT_AND:
135 return "bit-and-t";
136 case Token::BIT_OR:
137 return "bit-or-t";
138 case Token::BIT_XOR:
139 return "bit-xor-t";
140 case Token::ROR:
141 return "ror-t";
142 case Token::SHL:
143 return "shl-t";
144 case Token::SAR:
145 return "sar-t";
146 case Token::SHR:
147 return "shr-t";
148 default:
149 UNREACHABLE();
150 return NULL;
151 }
152}
153
154bool LGoto::HasInterestingComment(LCodeGen* gen) const {
155 return !gen->IsNextEmittedBlock(block_id());
156}
157
158void LGoto::PrintDataTo(StringStream* stream) {
159 stream->Add("B%d", block_id());
160}
161
162void LBranch::PrintDataTo(StringStream* stream) {
163 stream->Add("B%d | B%d on ", true_block_id(), false_block_id());
164 value()->PrintTo(stream);
165}
166
167void LCompareNumericAndBranch::PrintDataTo(StringStream* stream) {
168 stream->Add("if ");
169 left()->PrintTo(stream);
170 stream->Add(" %s ", Token::String(op()));
171 right()->PrintTo(stream);
172 stream->Add(" then B%d else B%d", true_block_id(), false_block_id());
173}
174
175void LIsStringAndBranch::PrintDataTo(StringStream* stream) {
176 stream->Add("if is_string(");
177 value()->PrintTo(stream);
178 stream->Add(") then B%d else B%d", true_block_id(), false_block_id());
179}
180
181void LIsSmiAndBranch::PrintDataTo(StringStream* stream) {
182 stream->Add("if is_smi(");
183 value()->PrintTo(stream);
184 stream->Add(") then B%d else B%d", true_block_id(), false_block_id());
185}
186
187void LIsUndetectableAndBranch::PrintDataTo(StringStream* stream) {
188 stream->Add("if is_undetectable(");
189 value()->PrintTo(stream);
190 stream->Add(") then B%d else B%d", true_block_id(), false_block_id());
191}
192
193void LStringCompareAndBranch::PrintDataTo(StringStream* stream) {
194 stream->Add("if string_compare(");
195 left()->PrintTo(stream);
196 right()->PrintTo(stream);
197 stream->Add(") then B%d else B%d", true_block_id(), false_block_id());
198}
199
200void LHasInstanceTypeAndBranch::PrintDataTo(StringStream* stream) {
201 stream->Add("if has_instance_type(");
202 value()->PrintTo(stream);
203 stream->Add(") then B%d else B%d", true_block_id(), false_block_id());
204}
205
206void LHasCachedArrayIndexAndBranch::PrintDataTo(StringStream* stream) {
207 stream->Add("if has_cached_array_index(");
208 value()->PrintTo(stream);
209 stream->Add(") then B%d else B%d", true_block_id(), false_block_id());
210}
211
212void LClassOfTestAndBranch::PrintDataTo(StringStream* stream) {
213 stream->Add("if class_of_test(");
214 value()->PrintTo(stream);
215 stream->Add(", \"%o\") then B%d else B%d", *hydrogen()->class_name(),
216 true_block_id(), false_block_id());
217}
218
219void LTypeofIsAndBranch::PrintDataTo(StringStream* stream) {
220 stream->Add("if typeof ");
221 value()->PrintTo(stream);
222 stream->Add(" == \"%s\" then B%d else B%d",
223 hydrogen()->type_literal()->ToCString().get(), true_block_id(),
224 false_block_id());
225}
226
227void LStoreCodeEntry::PrintDataTo(StringStream* stream) {
228 stream->Add(" = ");
229 function()->PrintTo(stream);
230 stream->Add(".code_entry = ");
231 code_object()->PrintTo(stream);
232}
233
234void LInnerAllocatedObject::PrintDataTo(StringStream* stream) {
235 stream->Add(" = ");
236 base_object()->PrintTo(stream);
237 stream->Add(" + ");
238 offset()->PrintTo(stream);
239}
240
241void LCallWithDescriptor::PrintDataTo(StringStream* stream) {
242 for (int i = 0; i < InputCount(); i++) {
243 InputAt(i)->PrintTo(stream);
244 stream->Add(" ");
245 }
246 stream->Add("#%d / ", arity());
247}
248
249void LLoadContextSlot::PrintDataTo(StringStream* stream) {
250 context()->PrintTo(stream);
251 stream->Add("[%d]", slot_index());
252}
253
254void LStoreContextSlot::PrintDataTo(StringStream* stream) {
255 context()->PrintTo(stream);
256 stream->Add("[%d] <- ", slot_index());
257 value()->PrintTo(stream);
258}
259
260void LInvokeFunction::PrintDataTo(StringStream* stream) {
261 stream->Add("= ");
262 function()->PrintTo(stream);
263 stream->Add(" #%d / ", arity());
264}
265
266void LCallNewArray::PrintDataTo(StringStream* stream) {
267 stream->Add("= ");
268 constructor()->PrintTo(stream);
269 stream->Add(" #%d / ", arity());
270 ElementsKind kind = hydrogen()->elements_kind();
271 stream->Add(" (%s) ", ElementsKindToString(kind));
272}
273
274void LAccessArgumentsAt::PrintDataTo(StringStream* stream) {
275 arguments()->PrintTo(stream);
276 stream->Add(" length ");
277 length()->PrintTo(stream);
278 stream->Add(" index ");
279 index()->PrintTo(stream);
280}
281
282void LStoreNamedField::PrintDataTo(StringStream* stream) {
283 object()->PrintTo(stream);
284 std::ostringstream os;
285 os << hydrogen()->access() << " <- ";
286 stream->Add(os.str().c_str());
287 value()->PrintTo(stream);
288}
289
290void LStoreNamedGeneric::PrintDataTo(StringStream* stream) {
291 object()->PrintTo(stream);
292 stream->Add(".");
293 stream->Add(String::cast(*name())->ToCString().get());
294 stream->Add(" <- ");
295 value()->PrintTo(stream);
296}
297
298void LLoadKeyed::PrintDataTo(StringStream* stream) {
299 elements()->PrintTo(stream);
300 stream->Add("[");
301 key()->PrintTo(stream);
302 if (hydrogen()->IsDehoisted()) {
303 stream->Add(" + %d]", base_offset());
304 } else {
305 stream->Add("]");
306 }
307}
308
309void LStoreKeyed::PrintDataTo(StringStream* stream) {
310 elements()->PrintTo(stream);
311 stream->Add("[");
312 key()->PrintTo(stream);
313 if (hydrogen()->IsDehoisted()) {
314 stream->Add(" + %d] <-", base_offset());
315 } else {
316 stream->Add("] <- ");
317 }
318
319 if (value() == NULL) {
320 DCHECK(hydrogen()->IsConstantHoleStore() &&
321 hydrogen()->value()->representation().IsDouble());
322 stream->Add("<the hole(nan)>");
323 } else {
324 value()->PrintTo(stream);
325 }
326}
327
328void LStoreKeyedGeneric::PrintDataTo(StringStream* stream) {
329 object()->PrintTo(stream);
330 stream->Add("[");
331 key()->PrintTo(stream);
332 stream->Add("] <- ");
333 value()->PrintTo(stream);
334}
335
336void LTransitionElementsKind::PrintDataTo(StringStream* stream) {
337 object()->PrintTo(stream);
338 stream->Add(" %p -> %p", *original_map(), *transitioned_map());
339}
340
341int LPlatformChunk::GetNextSpillIndex(RegisterKind kind) {
342 // Skip a slot if for a double-width slot.
343 if (kind == DOUBLE_REGISTERS) current_frame_slots_++;
344 return current_frame_slots_++;
345}
346
347LOperand* LPlatformChunk::GetNextSpillSlot(RegisterKind kind) {
348 int index = GetNextSpillIndex(kind);
349 if (kind == DOUBLE_REGISTERS) {
350 return LDoubleStackSlot::Create(index, zone());
351 } else {
352 DCHECK(kind == GENERAL_REGISTERS);
353 return LStackSlot::Create(index, zone());
354 }
355}
356
357LPlatformChunk* LChunkBuilder::Build() {
358 DCHECK(is_unused());
359 chunk_ = new (zone()) LPlatformChunk(info(), graph());
360 LPhase phase("L_Building chunk", chunk_);
361 status_ = BUILDING;
362
363 // If compiling for OSR, reserve space for the unoptimized frame,
364 // which will be subsumed into this frame.
365 if (graph()->has_osr()) {
366 for (int i = graph()->osr()->UnoptimizedFrameSlots(); i > 0; i--) {
367 chunk_->GetNextSpillIndex(GENERAL_REGISTERS);
368 }
369 }
370
371 const ZoneList<HBasicBlock*>* blocks = graph()->blocks();
372 for (int i = 0; i < blocks->length(); i++) {
373 HBasicBlock* next = NULL;
374 if (i < blocks->length() - 1) next = blocks->at(i + 1);
375 DoBasicBlock(blocks->at(i), next);
376 if (is_aborted()) return NULL;
377 }
378 status_ = DONE;
379 return chunk_;
380}
381
382LUnallocated* LChunkBuilder::ToUnallocated(Register reg) {
383 return new (zone()) LUnallocated(LUnallocated::FIXED_REGISTER, reg.code());
384}
385
386LUnallocated* LChunkBuilder::ToUnallocated(DoubleRegister reg) {
387 return new (zone())
388 LUnallocated(LUnallocated::FIXED_DOUBLE_REGISTER, reg.code());
389}
390
391LOperand* LChunkBuilder::UseFixed(HValue* value, Register fixed_register) {
392 return Use(value, ToUnallocated(fixed_register));
393}
394
395LOperand* LChunkBuilder::UseFixedDouble(HValue* value, DoubleRegister reg) {
396 return Use(value, ToUnallocated(reg));
397}
398
399LOperand* LChunkBuilder::UseRegister(HValue* value) {
400 return Use(value,
401 new (zone()) LUnallocated(LUnallocated::MUST_HAVE_REGISTER));
402}
403
404LOperand* LChunkBuilder::UseRegisterAtStart(HValue* value) {
405 return Use(value, new (zone()) LUnallocated(LUnallocated::MUST_HAVE_REGISTER,
406 LUnallocated::USED_AT_START));
407}
408
409LOperand* LChunkBuilder::UseTempRegister(HValue* value) {
410 return Use(value, new (zone()) LUnallocated(LUnallocated::WRITABLE_REGISTER));
411}
412
413LOperand* LChunkBuilder::Use(HValue* value) {
414 return Use(value, new (zone()) LUnallocated(LUnallocated::NONE));
415}
416
417LOperand* LChunkBuilder::UseAtStart(HValue* value) {
418 return Use(value, new (zone()) LUnallocated(LUnallocated::NONE,
419 LUnallocated::USED_AT_START));
420}
421
422LOperand* LChunkBuilder::UseOrConstant(HValue* value) {
423 return value->IsConstant()
424 ? chunk_->DefineConstantOperand(HConstant::cast(value))
425 : Use(value);
426}
427
428LOperand* LChunkBuilder::UseOrConstantAtStart(HValue* value) {
429 return value->IsConstant()
430 ? chunk_->DefineConstantOperand(HConstant::cast(value))
431 : UseAtStart(value);
432}
433
434LOperand* LChunkBuilder::UseRegisterOrConstant(HValue* value) {
435 return value->IsConstant()
436 ? chunk_->DefineConstantOperand(HConstant::cast(value))
437 : UseRegister(value);
438}
439
440LOperand* LChunkBuilder::UseRegisterOrConstantAtStart(HValue* value) {
441 return value->IsConstant()
442 ? chunk_->DefineConstantOperand(HConstant::cast(value))
443 : UseRegisterAtStart(value);
444}
445
446LOperand* LChunkBuilder::UseConstant(HValue* value) {
447 return chunk_->DefineConstantOperand(HConstant::cast(value));
448}
449
450LOperand* LChunkBuilder::UseAny(HValue* value) {
451 return value->IsConstant()
452 ? chunk_->DefineConstantOperand(HConstant::cast(value))
453 : Use(value, new (zone()) LUnallocated(LUnallocated::ANY));
454}
455
456LOperand* LChunkBuilder::Use(HValue* value, LUnallocated* operand) {
457 if (value->EmitAtUses()) {
458 HInstruction* instr = HInstruction::cast(value);
459 VisitInstruction(instr);
460 }
461 operand->set_virtual_register(value->id());
462 return operand;
463}
464
465LInstruction* LChunkBuilder::Define(LTemplateResultInstruction<1>* instr,
466 LUnallocated* result) {
467 result->set_virtual_register(current_instruction_->id());
468 instr->set_result(result);
469 return instr;
470}
471
472LInstruction* LChunkBuilder::DefineAsRegister(
473 LTemplateResultInstruction<1>* instr) {
474 return Define(instr,
475 new (zone()) LUnallocated(LUnallocated::MUST_HAVE_REGISTER));
476}
477
478LInstruction* LChunkBuilder::DefineAsSpilled(
479 LTemplateResultInstruction<1>* instr, int index) {
480 return Define(instr,
481 new (zone()) LUnallocated(LUnallocated::FIXED_SLOT, index));
482}
483
484LInstruction* LChunkBuilder::DefineSameAsFirst(
485 LTemplateResultInstruction<1>* instr) {
486 return Define(instr,
487 new (zone()) LUnallocated(LUnallocated::SAME_AS_FIRST_INPUT));
488}
489
490LInstruction* LChunkBuilder::DefineFixed(LTemplateResultInstruction<1>* instr,
491 Register reg) {
492 return Define(instr, ToUnallocated(reg));
493}
494
495LInstruction* LChunkBuilder::DefineFixedDouble(
496 LTemplateResultInstruction<1>* instr, DoubleRegister reg) {
497 return Define(instr, ToUnallocated(reg));
498}
499
500LInstruction* LChunkBuilder::AssignEnvironment(LInstruction* instr) {
501 HEnvironment* hydrogen_env = current_block_->last_environment();
502 return LChunkBuilderBase::AssignEnvironment(instr, hydrogen_env);
503}
504
505LInstruction* LChunkBuilder::MarkAsCall(LInstruction* instr,
506 HInstruction* hinstr,
507 CanDeoptimize can_deoptimize) {
508 info()->MarkAsNonDeferredCalling();
509#ifdef DEBUG
510 instr->VerifyCall();
511#endif
512 instr->MarkAsCall();
513 instr = AssignPointerMap(instr);
514
515 // If instruction does not have side-effects lazy deoptimization
516 // after the call will try to deoptimize to the point before the call.
517 // Thus we still need to attach environment to this call even if
518 // call sequence can not deoptimize eagerly.
519 bool needs_environment = (can_deoptimize == CAN_DEOPTIMIZE_EAGERLY) ||
520 !hinstr->HasObservableSideEffects();
521 if (needs_environment && !instr->HasEnvironment()) {
522 instr = AssignEnvironment(instr);
523 // We can't really figure out if the environment is needed or not.
524 instr->environment()->set_has_been_used();
525 }
526
527 return instr;
528}
529
530LInstruction* LChunkBuilder::AssignPointerMap(LInstruction* instr) {
531 DCHECK(!instr->HasPointerMap());
532 instr->set_pointer_map(new (zone()) LPointerMap(zone()));
533 return instr;
534}
535
536LUnallocated* LChunkBuilder::TempRegister() {
537 LUnallocated* operand =
538 new (zone()) LUnallocated(LUnallocated::MUST_HAVE_REGISTER);
539 int vreg = allocator_->GetVirtualRegister();
540 if (!allocator_->AllocationOk()) {
541 Abort(kOutOfVirtualRegistersWhileTryingToAllocateTempRegister);
542 vreg = 0;
543 }
544 operand->set_virtual_register(vreg);
545 return operand;
546}
547
548LUnallocated* LChunkBuilder::TempDoubleRegister() {
549 LUnallocated* operand =
550 new (zone()) LUnallocated(LUnallocated::MUST_HAVE_DOUBLE_REGISTER);
551 int vreg = allocator_->GetVirtualRegister();
552 if (!allocator_->AllocationOk()) {
553 Abort(kOutOfVirtualRegistersWhileTryingToAllocateTempRegister);
554 vreg = 0;
555 }
556 operand->set_virtual_register(vreg);
557 return operand;
558}
559
560LOperand* LChunkBuilder::FixedTemp(Register reg) {
561 LUnallocated* operand = ToUnallocated(reg);
562 DCHECK(operand->HasFixedPolicy());
563 return operand;
564}
565
566LOperand* LChunkBuilder::FixedTemp(DoubleRegister reg) {
567 LUnallocated* operand = ToUnallocated(reg);
568 DCHECK(operand->HasFixedPolicy());
569 return operand;
570}
571
572LInstruction* LChunkBuilder::DoBlockEntry(HBlockEntry* instr) {
573 return new (zone()) LLabel(instr->block());
574}
575
576LInstruction* LChunkBuilder::DoDummyUse(HDummyUse* instr) {
577 return DefineAsRegister(new (zone()) LDummyUse(UseAny(instr->value())));
578}
579
580LInstruction* LChunkBuilder::DoEnvironmentMarker(HEnvironmentMarker* instr) {
581 UNREACHABLE();
582 return NULL;
583}
584
585LInstruction* LChunkBuilder::DoDeoptimize(HDeoptimize* instr) {
586 return AssignEnvironment(new (zone()) LDeoptimize);
587}
588
589LInstruction* LChunkBuilder::DoShift(Token::Value op,
590 HBitwiseBinaryOperation* instr) {
591 if (instr->representation().IsSmiOrInteger32()) {
592 DCHECK(instr->left()->representation().Equals(instr->representation()));
593 DCHECK(instr->right()->representation().Equals(instr->representation()));
594 LOperand* left = UseRegisterAtStart(instr->left());
595
596 HValue* right_value = instr->right();
597 LOperand* right = NULL;
598 int constant_value = 0;
599 bool does_deopt = false;
600 if (right_value->IsConstant()) {
601 HConstant* constant = HConstant::cast(right_value);
602 right = chunk_->DefineConstantOperand(constant);
603 constant_value = constant->Integer32Value() & 0x1f;
604 // Left shifts can deoptimize if we shift by > 0 and the result cannot be
605 // truncated to smi.
606 if (instr->representation().IsSmi() && constant_value > 0) {
607 does_deopt = !instr->CheckUsesForFlag(HValue::kTruncatingToSmi);
608 }
609 } else {
610 right = UseRegisterAtStart(right_value);
611 }
612
613 // Shift operations can only deoptimize if we do a logical shift
614 // by 0 and the result cannot be truncated to int32.
615 if (op == Token::SHR && constant_value == 0) {
616 does_deopt = !instr->CheckFlag(HInstruction::kUint32);
617 }
618
619 LInstruction* result =
620 DefineAsRegister(new (zone()) LShiftI(op, left, right, does_deopt));
621 return does_deopt ? AssignEnvironment(result) : result;
622 } else {
623 return DoArithmeticT(op, instr);
624 }
625}
626
627LInstruction* LChunkBuilder::DoArithmeticD(Token::Value op,
628 HArithmeticBinaryOperation* instr) {
629 DCHECK(instr->representation().IsDouble());
630 DCHECK(instr->left()->representation().IsDouble());
631 DCHECK(instr->right()->representation().IsDouble());
632 if (op == Token::MOD) {
633 LOperand* left = UseFixedDouble(instr->left(), d1);
634 LOperand* right = UseFixedDouble(instr->right(), d2);
635 LArithmeticD* result = new (zone()) LArithmeticD(op, left, right);
636 // We call a C function for double modulo. It can't trigger a GC. We need
637 // to use fixed result register for the call.
638 // TODO(fschneider): Allow any register as input registers.
639 return MarkAsCall(DefineFixedDouble(result, d1), instr);
640 } else {
641 LOperand* left = UseRegisterAtStart(instr->BetterLeftOperand());
642 LOperand* right = UseRegisterAtStart(instr->BetterRightOperand());
643 LArithmeticD* result = new (zone()) LArithmeticD(op, left, right);
644 return DefineSameAsFirst(result);
645 }
646}
647
648LInstruction* LChunkBuilder::DoArithmeticT(Token::Value op,
649 HBinaryOperation* instr) {
650 HValue* left = instr->left();
651 HValue* right = instr->right();
652 DCHECK(left->representation().IsTagged());
653 DCHECK(right->representation().IsTagged());
654 LOperand* context = UseFixed(instr->context(), cp);
655 LOperand* left_operand = UseFixed(left, r3);
656 LOperand* right_operand = UseFixed(right, r2);
657 LArithmeticT* result =
658 new (zone()) LArithmeticT(op, context, left_operand, right_operand);
659 return MarkAsCall(DefineFixed(result, r2), instr);
660}
661
662void LChunkBuilder::DoBasicBlock(HBasicBlock* block, HBasicBlock* next_block) {
663 DCHECK(is_building());
664 current_block_ = block;
665 next_block_ = next_block;
666 if (block->IsStartBlock()) {
667 block->UpdateEnvironment(graph_->start_environment());
668 argument_count_ = 0;
669 } else if (block->predecessors()->length() == 1) {
670 // We have a single predecessor => copy environment and outgoing
671 // argument count from the predecessor.
672 DCHECK(block->phis()->length() == 0);
673 HBasicBlock* pred = block->predecessors()->at(0);
674 HEnvironment* last_environment = pred->last_environment();
675 DCHECK(last_environment != NULL);
676 // Only copy the environment, if it is later used again.
677 if (pred->end()->SecondSuccessor() == NULL) {
678 DCHECK(pred->end()->FirstSuccessor() == block);
679 } else {
680 if (pred->end()->FirstSuccessor()->block_id() > block->block_id() ||
681 pred->end()->SecondSuccessor()->block_id() > block->block_id()) {
682 last_environment = last_environment->Copy();
683 }
684 }
685 block->UpdateEnvironment(last_environment);
686 DCHECK(pred->argument_count() >= 0);
687 argument_count_ = pred->argument_count();
688 } else {
689 // We are at a state join => process phis.
690 HBasicBlock* pred = block->predecessors()->at(0);
691 // No need to copy the environment, it cannot be used later.
692 HEnvironment* last_environment = pred->last_environment();
693 for (int i = 0; i < block->phis()->length(); ++i) {
694 HPhi* phi = block->phis()->at(i);
695 if (phi->HasMergedIndex()) {
696 last_environment->SetValueAt(phi->merged_index(), phi);
697 }
698 }
699 for (int i = 0; i < block->deleted_phis()->length(); ++i) {
700 if (block->deleted_phis()->at(i) < last_environment->length()) {
701 last_environment->SetValueAt(block->deleted_phis()->at(i),
702 graph_->GetConstantUndefined());
703 }
704 }
705 block->UpdateEnvironment(last_environment);
706 // Pick up the outgoing argument count of one of the predecessors.
707 argument_count_ = pred->argument_count();
708 }
709 HInstruction* current = block->first();
710 int start = chunk_->instructions()->length();
711 while (current != NULL && !is_aborted()) {
712 // Code for constants in registers is generated lazily.
713 if (!current->EmitAtUses()) {
714 VisitInstruction(current);
715 }
716 current = current->next();
717 }
718 int end = chunk_->instructions()->length() - 1;
719 if (end >= start) {
720 block->set_first_instruction_index(start);
721 block->set_last_instruction_index(end);
722 }
723 block->set_argument_count(argument_count_);
724 next_block_ = NULL;
725 current_block_ = NULL;
726}
727
728void LChunkBuilder::VisitInstruction(HInstruction* current) {
729 HInstruction* old_current = current_instruction_;
730 current_instruction_ = current;
731
732 LInstruction* instr = NULL;
733 if (current->CanReplaceWithDummyUses()) {
734 if (current->OperandCount() == 0) {
735 instr = DefineAsRegister(new (zone()) LDummy());
736 } else {
737 DCHECK(!current->OperandAt(0)->IsControlInstruction());
738 instr = DefineAsRegister(new (zone())
739 LDummyUse(UseAny(current->OperandAt(0))));
740 }
741 for (int i = 1; i < current->OperandCount(); ++i) {
742 if (current->OperandAt(i)->IsControlInstruction()) continue;
743 LInstruction* dummy =
744 new (zone()) LDummyUse(UseAny(current->OperandAt(i)));
745 dummy->set_hydrogen_value(current);
746 chunk_->AddInstruction(dummy, current_block_);
747 }
748 } else {
749 HBasicBlock* successor;
750 if (current->IsControlInstruction() &&
751 HControlInstruction::cast(current)->KnownSuccessorBlock(&successor) &&
752 successor != NULL) {
753 instr = new (zone()) LGoto(successor);
754 } else {
755 instr = current->CompileToLithium(this);
756 }
757 }
758
759 argument_count_ += current->argument_delta();
760 DCHECK(argument_count_ >= 0);
761
762 if (instr != NULL) {
763 AddInstruction(instr, current);
764 }
765
766 current_instruction_ = old_current;
767}
768
769void LChunkBuilder::AddInstruction(LInstruction* instr,
770 HInstruction* hydrogen_val) {
771 // Associate the hydrogen instruction first, since we may need it for
772 // the ClobbersRegisters() or ClobbersDoubleRegisters() calls below.
773 instr->set_hydrogen_value(hydrogen_val);
774
775#if DEBUG
776 // Make sure that the lithium instruction has either no fixed register
777 // constraints in temps or the result OR no uses that are only used at
778 // start. If this invariant doesn't hold, the register allocator can decide
779 // to insert a split of a range immediately before the instruction due to an
780 // already allocated register needing to be used for the instruction's fixed
781 // register constraint. In this case, The register allocator won't see an
782 // interference between the split child and the use-at-start (it would if
783 // the it was just a plain use), so it is free to move the split child into
784 // the same register that is used for the use-at-start.
785 // See https://code.google.com/p/chromium/issues/detail?id=201590
786 if (!(instr->ClobbersRegisters() &&
787 instr->ClobbersDoubleRegisters(isolate()))) {
788 int fixed = 0;
789 int used_at_start = 0;
790 for (UseIterator it(instr); !it.Done(); it.Advance()) {
791 LUnallocated* operand = LUnallocated::cast(it.Current());
792 if (operand->IsUsedAtStart()) ++used_at_start;
793 }
794 if (instr->Output() != NULL) {
795 if (LUnallocated::cast(instr->Output())->HasFixedPolicy()) ++fixed;
796 }
797 for (TempIterator it(instr); !it.Done(); it.Advance()) {
798 LUnallocated* operand = LUnallocated::cast(it.Current());
799 if (operand->HasFixedPolicy()) ++fixed;
800 }
801 DCHECK(fixed == 0 || used_at_start == 0);
802 }
803#endif
804
805 if (FLAG_stress_pointer_maps && !instr->HasPointerMap()) {
806 instr = AssignPointerMap(instr);
807 }
808 if (FLAG_stress_environments && !instr->HasEnvironment()) {
809 instr = AssignEnvironment(instr);
810 }
811 chunk_->AddInstruction(instr, current_block_);
812
813 CreateLazyBailoutForCall(current_block_, instr, hydrogen_val);
814}
815
816LInstruction* LChunkBuilder::DoPrologue(HPrologue* instr) {
817 LInstruction* result = new (zone()) LPrologue();
818 if (info_->num_heap_slots() > 0) {
819 result = MarkAsCall(result, instr);
820 }
821 return result;
822}
823
824LInstruction* LChunkBuilder::DoGoto(HGoto* instr) {
825 return new (zone()) LGoto(instr->FirstSuccessor());
826}
827
828LInstruction* LChunkBuilder::DoBranch(HBranch* instr) {
829 HValue* value = instr->value();
830 Representation r = value->representation();
831 HType type = value->type();
832 ToBooleanICStub::Types expected = instr->expected_input_types();
833 if (expected.IsEmpty()) expected = ToBooleanICStub::Types::Generic();
834
835 bool easy_case = !r.IsTagged() || type.IsBoolean() || type.IsSmi() ||
836 type.IsJSArray() || type.IsHeapNumber() || type.IsString();
837 LInstruction* branch = new (zone()) LBranch(UseRegister(value));
838 if (!easy_case &&
839 ((!expected.Contains(ToBooleanICStub::SMI) && expected.NeedsMap()) ||
840 !expected.IsGeneric())) {
841 branch = AssignEnvironment(branch);
842 }
843 return branch;
844}
845
846LInstruction* LChunkBuilder::DoDebugBreak(HDebugBreak* instr) {
847 return new (zone()) LDebugBreak();
848}
849
850LInstruction* LChunkBuilder::DoCompareMap(HCompareMap* instr) {
851 DCHECK(instr->value()->representation().IsTagged());
852 LOperand* value = UseRegister(instr->value());
853 LOperand* temp = TempRegister();
854 return new (zone()) LCmpMapAndBranch(value, temp);
855}
856
857LInstruction* LChunkBuilder::DoArgumentsLength(HArgumentsLength* instr) {
858 info()->MarkAsRequiresFrame();
859 LOperand* value = UseRegister(instr->value());
860 return DefineAsRegister(new (zone()) LArgumentsLength(value));
861}
862
863LInstruction* LChunkBuilder::DoArgumentsElements(HArgumentsElements* elems) {
864 info()->MarkAsRequiresFrame();
865 return DefineAsRegister(new (zone()) LArgumentsElements);
866}
867
868LInstruction* LChunkBuilder::DoInstanceOf(HInstanceOf* instr) {
869 LOperand* left =
870 UseFixed(instr->left(), InstanceOfDescriptor::LeftRegister());
871 LOperand* right =
872 UseFixed(instr->right(), InstanceOfDescriptor::RightRegister());
873 LOperand* context = UseFixed(instr->context(), cp);
874 LInstanceOf* result = new (zone()) LInstanceOf(context, left, right);
875 return MarkAsCall(DefineFixed(result, r2), instr);
876}
877
878LInstruction* LChunkBuilder::DoHasInPrototypeChainAndBranch(
879 HHasInPrototypeChainAndBranch* instr) {
880 LOperand* object = UseRegister(instr->object());
881 LOperand* prototype = UseRegister(instr->prototype());
882 LHasInPrototypeChainAndBranch* result =
883 new (zone()) LHasInPrototypeChainAndBranch(object, prototype);
884 return AssignEnvironment(result);
885}
886
887LInstruction* LChunkBuilder::DoWrapReceiver(HWrapReceiver* instr) {
888 LOperand* receiver = UseRegisterAtStart(instr->receiver());
889 LOperand* function = UseRegisterAtStart(instr->function());
890 LWrapReceiver* result = new (zone()) LWrapReceiver(receiver, function);
891 return AssignEnvironment(DefineAsRegister(result));
892}
893
894LInstruction* LChunkBuilder::DoApplyArguments(HApplyArguments* instr) {
895 LOperand* function = UseFixed(instr->function(), r3);
896 LOperand* receiver = UseFixed(instr->receiver(), r2);
897 LOperand* length = UseFixed(instr->length(), r4);
898 LOperand* elements = UseFixed(instr->elements(), r5);
899 LApplyArguments* result =
900 new (zone()) LApplyArguments(function, receiver, length, elements);
901 return MarkAsCall(DefineFixed(result, r2), instr, CAN_DEOPTIMIZE_EAGERLY);
902}
903
904LInstruction* LChunkBuilder::DoPushArguments(HPushArguments* instr) {
905 int argc = instr->OperandCount();
906 for (int i = 0; i < argc; ++i) {
907 LOperand* argument = Use(instr->argument(i));
908 AddInstruction(new (zone()) LPushArgument(argument), instr);
909 }
910 return NULL;
911}
912
913LInstruction* LChunkBuilder::DoStoreCodeEntry(
914 HStoreCodeEntry* store_code_entry) {
915 LOperand* function = UseRegister(store_code_entry->function());
916 LOperand* code_object = UseTempRegister(store_code_entry->code_object());
917 return new (zone()) LStoreCodeEntry(function, code_object);
918}
919
920LInstruction* LChunkBuilder::DoInnerAllocatedObject(
921 HInnerAllocatedObject* instr) {
922 LOperand* base_object = UseRegisterAtStart(instr->base_object());
923 LOperand* offset = UseRegisterOrConstantAtStart(instr->offset());
924 return DefineAsRegister(new (zone())
925 LInnerAllocatedObject(base_object, offset));
926}
927
928LInstruction* LChunkBuilder::DoThisFunction(HThisFunction* instr) {
929 return instr->HasNoUses() ? NULL
930 : DefineAsRegister(new (zone()) LThisFunction);
931}
932
933LInstruction* LChunkBuilder::DoContext(HContext* instr) {
934 if (instr->HasNoUses()) return NULL;
935
936 if (info()->IsStub()) {
937 return DefineFixed(new (zone()) LContext, cp);
938 }
939
940 return DefineAsRegister(new (zone()) LContext);
941}
942
943LInstruction* LChunkBuilder::DoDeclareGlobals(HDeclareGlobals* instr) {
944 LOperand* context = UseFixed(instr->context(), cp);
945 return MarkAsCall(new (zone()) LDeclareGlobals(context), instr);
946}
947
948LInstruction* LChunkBuilder::DoCallWithDescriptor(HCallWithDescriptor* instr) {
949 CallInterfaceDescriptor descriptor = instr->descriptor();
950
951 LOperand* target = UseRegisterOrConstantAtStart(instr->target());
952 ZoneList<LOperand*> ops(instr->OperandCount(), zone());
953 // Target
954 ops.Add(target, zone());
955 // Context
956 LOperand* op = UseFixed(instr->OperandAt(1), cp);
957 ops.Add(op, zone());
958 // Other register parameters
959 for (int i = LCallWithDescriptor::kImplicitRegisterParameterCount;
960 i < instr->OperandCount(); i++) {
961 op =
962 UseFixed(instr->OperandAt(i),
963 descriptor.GetRegisterParameter(
964 i - LCallWithDescriptor::kImplicitRegisterParameterCount));
965 ops.Add(op, zone());
966 }
967
968 LCallWithDescriptor* result =
969 new (zone()) LCallWithDescriptor(descriptor, ops, zone());
970 if (instr->syntactic_tail_call_mode() == TailCallMode::kAllow) {
971 result->MarkAsSyntacticTailCall();
972 }
973 return MarkAsCall(DefineFixed(result, r2), instr);
974}
975
976LInstruction* LChunkBuilder::DoInvokeFunction(HInvokeFunction* instr) {
977 LOperand* context = UseFixed(instr->context(), cp);
978 LOperand* function = UseFixed(instr->function(), r3);
979 LInvokeFunction* result = new (zone()) LInvokeFunction(context, function);
980 if (instr->syntactic_tail_call_mode() == TailCallMode::kAllow) {
981 result->MarkAsSyntacticTailCall();
982 }
983 return MarkAsCall(DefineFixed(result, r2), instr, CANNOT_DEOPTIMIZE_EAGERLY);
984}
985
986LInstruction* LChunkBuilder::DoUnaryMathOperation(HUnaryMathOperation* instr) {
987 switch (instr->op()) {
988 case kMathFloor:
989 return DoMathFloor(instr);
990 case kMathRound:
991 return DoMathRound(instr);
992 case kMathFround:
993 return DoMathFround(instr);
994 case kMathAbs:
995 return DoMathAbs(instr);
996 case kMathLog:
997 return DoMathLog(instr);
998 case kMathExp:
999 return DoMathExp(instr);
1000 case kMathSqrt:
1001 return DoMathSqrt(instr);
1002 case kMathPowHalf:
1003 return DoMathPowHalf(instr);
1004 case kMathClz32:
1005 return DoMathClz32(instr);
1006 default:
1007 UNREACHABLE();
1008 return NULL;
1009 }
1010}
1011
1012LInstruction* LChunkBuilder::DoMathFloor(HUnaryMathOperation* instr) {
1013 LOperand* input = UseRegister(instr->value());
1014 LMathFloor* result = new (zone()) LMathFloor(input);
1015 return AssignEnvironment(AssignPointerMap(DefineAsRegister(result)));
1016}
1017
1018LInstruction* LChunkBuilder::DoMathRound(HUnaryMathOperation* instr) {
1019 LOperand* input = UseRegister(instr->value());
1020 LOperand* temp = TempDoubleRegister();
1021 LMathRound* result = new (zone()) LMathRound(input, temp);
1022 return AssignEnvironment(DefineAsRegister(result));
1023}
1024
1025LInstruction* LChunkBuilder::DoMathFround(HUnaryMathOperation* instr) {
1026 LOperand* input = UseRegister(instr->value());
1027 LMathFround* result = new (zone()) LMathFround(input);
1028 return DefineAsRegister(result);
1029}
1030
1031LInstruction* LChunkBuilder::DoMathAbs(HUnaryMathOperation* instr) {
1032 Representation r = instr->value()->representation();
1033 LOperand* context = (r.IsDouble() || r.IsSmiOrInteger32())
1034 ? NULL
1035 : UseFixed(instr->context(), cp);
1036 LOperand* input = UseRegister(instr->value());
1037 LInstruction* result =
1038 DefineAsRegister(new (zone()) LMathAbs(context, input));
1039 if (!r.IsDouble() && !r.IsSmiOrInteger32()) result = AssignPointerMap(result);
1040 if (!r.IsDouble()) result = AssignEnvironment(result);
1041 return result;
1042}
1043
1044LInstruction* LChunkBuilder::DoMathLog(HUnaryMathOperation* instr) {
1045 DCHECK(instr->representation().IsDouble());
1046 DCHECK(instr->value()->representation().IsDouble());
1047 LOperand* input = UseFixedDouble(instr->value(), d1);
1048 return MarkAsCall(DefineFixedDouble(new (zone()) LMathLog(input), d1), instr);
1049}
1050
1051LInstruction* LChunkBuilder::DoMathClz32(HUnaryMathOperation* instr) {
1052 LOperand* input = UseRegisterAtStart(instr->value());
1053 LMathClz32* result = new (zone()) LMathClz32(input);
1054 return DefineAsRegister(result);
1055}
1056
1057LInstruction* LChunkBuilder::DoMathExp(HUnaryMathOperation* instr) {
1058 DCHECK(instr->representation().IsDouble());
1059 DCHECK(instr->value()->representation().IsDouble());
1060 LOperand* input = UseRegister(instr->value());
1061 LOperand* temp1 = TempRegister();
1062 LOperand* temp2 = TempRegister();
1063 LOperand* double_temp = TempDoubleRegister();
1064 LMathExp* result = new (zone()) LMathExp(input, double_temp, temp1, temp2);
1065 return DefineAsRegister(result);
1066}
1067
1068LInstruction* LChunkBuilder::DoMathSqrt(HUnaryMathOperation* instr) {
1069 LOperand* input = UseRegisterAtStart(instr->value());
1070 LMathSqrt* result = new (zone()) LMathSqrt(input);
1071 return DefineAsRegister(result);
1072}
1073
1074LInstruction* LChunkBuilder::DoMathPowHalf(HUnaryMathOperation* instr) {
1075 LOperand* input = UseRegisterAtStart(instr->value());
1076 LMathPowHalf* result = new (zone()) LMathPowHalf(input);
1077 return DefineAsRegister(result);
1078}
1079
1080LInstruction* LChunkBuilder::DoCallNewArray(HCallNewArray* instr) {
1081 LOperand* context = UseFixed(instr->context(), cp);
1082 LOperand* constructor = UseFixed(instr->constructor(), r3);
1083 LCallNewArray* result = new (zone()) LCallNewArray(context, constructor);
1084 return MarkAsCall(DefineFixed(result, r2), instr);
1085}
1086
1087LInstruction* LChunkBuilder::DoCallRuntime(HCallRuntime* instr) {
1088 LOperand* context = UseFixed(instr->context(), cp);
1089 return MarkAsCall(DefineFixed(new (zone()) LCallRuntime(context), r2), instr);
1090}
1091
1092LInstruction* LChunkBuilder::DoRor(HRor* instr) {
1093 return DoShift(Token::ROR, instr);
1094}
1095
1096LInstruction* LChunkBuilder::DoShr(HShr* instr) {
1097 return DoShift(Token::SHR, instr);
1098}
1099
1100LInstruction* LChunkBuilder::DoSar(HSar* instr) {
1101 return DoShift(Token::SAR, instr);
1102}
1103
1104LInstruction* LChunkBuilder::DoShl(HShl* instr) {
1105 return DoShift(Token::SHL, instr);
1106}
1107
1108LInstruction* LChunkBuilder::DoBitwise(HBitwise* instr) {
1109 if (instr->representation().IsSmiOrInteger32()) {
1110 DCHECK(instr->left()->representation().Equals(instr->representation()));
1111 DCHECK(instr->right()->representation().Equals(instr->representation()));
1112 DCHECK(instr->CheckFlag(HValue::kTruncatingToInt32));
1113
1114 LOperand* left = UseRegisterAtStart(instr->BetterLeftOperand());
1115 LOperand* right = UseOrConstantAtStart(instr->BetterRightOperand());
1116 return DefineAsRegister(new (zone()) LBitI(left, right));
1117 } else {
1118 return DoArithmeticT(instr->op(), instr);
1119 }
1120}
1121
1122LInstruction* LChunkBuilder::DoDivByPowerOf2I(HDiv* instr) {
1123 DCHECK(instr->representation().IsSmiOrInteger32());
1124 DCHECK(instr->left()->representation().Equals(instr->representation()));
1125 DCHECK(instr->right()->representation().Equals(instr->representation()));
1126 LOperand* dividend = UseRegister(instr->left());
1127 int32_t divisor = instr->right()->GetInteger32Constant();
1128 LInstruction* result =
1129 DefineAsRegister(new (zone()) LDivByPowerOf2I(dividend, divisor));
1130 if ((instr->CheckFlag(HValue::kBailoutOnMinusZero) && divisor < 0) ||
1131 (instr->CheckFlag(HValue::kCanOverflow) && divisor == -1) ||
1132 (!instr->CheckFlag(HInstruction::kAllUsesTruncatingToInt32) &&
1133 divisor != 1 && divisor != -1)) {
1134 result = AssignEnvironment(result);
1135 }
1136 return result;
1137}
1138
1139LInstruction* LChunkBuilder::DoDivByConstI(HDiv* instr) {
1140 DCHECK(instr->representation().IsInteger32());
1141 DCHECK(instr->left()->representation().Equals(instr->representation()));
1142 DCHECK(instr->right()->representation().Equals(instr->representation()));
1143 LOperand* dividend = UseRegister(instr->left());
1144 int32_t divisor = instr->right()->GetInteger32Constant();
1145 LInstruction* result =
1146 DefineAsRegister(new (zone()) LDivByConstI(dividend, divisor));
1147 if (divisor == 0 ||
1148 (instr->CheckFlag(HValue::kBailoutOnMinusZero) && divisor < 0) ||
1149 !instr->CheckFlag(HInstruction::kAllUsesTruncatingToInt32)) {
1150 result = AssignEnvironment(result);
1151 }
1152 return result;
1153}
1154
1155LInstruction* LChunkBuilder::DoDivI(HDiv* instr) {
1156 DCHECK(instr->representation().IsSmiOrInteger32());
1157 DCHECK(instr->left()->representation().Equals(instr->representation()));
1158 DCHECK(instr->right()->representation().Equals(instr->representation()));
1159 LOperand* dividend = UseRegister(instr->left());
1160 LOperand* divisor = UseRegister(instr->right());
1161 LInstruction* result =
1162 DefineAsRegister(new (zone()) LDivI(dividend, divisor));
1163 if (instr->CheckFlag(HValue::kCanBeDivByZero) ||
1164 instr->CheckFlag(HValue::kBailoutOnMinusZero) ||
1165 (instr->CheckFlag(HValue::kCanOverflow) &&
1166 !instr->CheckFlag(HValue::kAllUsesTruncatingToInt32)) ||
1167 (!instr->IsMathFloorOfDiv() &&
1168 !instr->CheckFlag(HValue::kAllUsesTruncatingToInt32))) {
1169 result = AssignEnvironment(result);
1170 }
1171 return result;
1172}
1173
1174LInstruction* LChunkBuilder::DoDiv(HDiv* instr) {
1175 if (instr->representation().IsSmiOrInteger32()) {
1176 if (instr->RightIsPowerOf2()) {
1177 return DoDivByPowerOf2I(instr);
1178 } else if (instr->right()->IsConstant()) {
1179 return DoDivByConstI(instr);
1180 } else {
1181 return DoDivI(instr);
1182 }
1183 } else if (instr->representation().IsDouble()) {
1184 return DoArithmeticD(Token::DIV, instr);
1185 } else {
1186 return DoArithmeticT(Token::DIV, instr);
1187 }
1188}
1189
1190LInstruction* LChunkBuilder::DoFlooringDivByPowerOf2I(HMathFloorOfDiv* instr) {
1191 LOperand* dividend = UseRegisterAtStart(instr->left());
1192 int32_t divisor = instr->right()->GetInteger32Constant();
1193 LInstruction* result =
1194 DefineAsRegister(new (zone()) LFlooringDivByPowerOf2I(dividend, divisor));
1195 if ((instr->CheckFlag(HValue::kBailoutOnMinusZero) && divisor < 0) ||
1196 (instr->CheckFlag(HValue::kLeftCanBeMinInt) && divisor == -1)) {
1197 result = AssignEnvironment(result);
1198 }
1199 return result;
1200}
1201
1202LInstruction* LChunkBuilder::DoFlooringDivByConstI(HMathFloorOfDiv* instr) {
1203 DCHECK(instr->representation().IsInteger32());
1204 DCHECK(instr->left()->representation().Equals(instr->representation()));
1205 DCHECK(instr->right()->representation().Equals(instr->representation()));
1206 LOperand* dividend = UseRegister(instr->left());
1207 int32_t divisor = instr->right()->GetInteger32Constant();
1208 LOperand* temp =
1209 ((divisor > 0 && !instr->CheckFlag(HValue::kLeftCanBeNegative)) ||
1210 (divisor < 0 && !instr->CheckFlag(HValue::kLeftCanBePositive)))
1211 ? NULL
1212 : TempRegister();
1213 LInstruction* result = DefineAsRegister(
1214 new (zone()) LFlooringDivByConstI(dividend, divisor, temp));
1215 if (divisor == 0 ||
1216 (instr->CheckFlag(HValue::kBailoutOnMinusZero) && divisor < 0)) {
1217 result = AssignEnvironment(result);
1218 }
1219 return result;
1220}
1221
1222LInstruction* LChunkBuilder::DoFlooringDivI(HMathFloorOfDiv* instr) {
1223 DCHECK(instr->representation().IsSmiOrInteger32());
1224 DCHECK(instr->left()->representation().Equals(instr->representation()));
1225 DCHECK(instr->right()->representation().Equals(instr->representation()));
1226 LOperand* dividend = UseRegister(instr->left());
1227 LOperand* divisor = UseRegister(instr->right());
1228 LInstruction* result =
1229 DefineAsRegister(new (zone()) LFlooringDivI(dividend, divisor));
1230 if (instr->CheckFlag(HValue::kCanBeDivByZero) ||
1231 instr->CheckFlag(HValue::kBailoutOnMinusZero) ||
1232 (instr->CheckFlag(HValue::kCanOverflow) &&
1233 !instr->CheckFlag(HValue::kAllUsesTruncatingToInt32))) {
1234 result = AssignEnvironment(result);
1235 }
1236 return result;
1237}
1238
1239LInstruction* LChunkBuilder::DoMathFloorOfDiv(HMathFloorOfDiv* instr) {
1240 if (instr->RightIsPowerOf2()) {
1241 return DoFlooringDivByPowerOf2I(instr);
1242 } else if (instr->right()->IsConstant()) {
1243 return DoFlooringDivByConstI(instr);
1244 } else {
1245 return DoFlooringDivI(instr);
1246 }
1247}
1248
1249LInstruction* LChunkBuilder::DoModByPowerOf2I(HMod* instr) {
1250 DCHECK(instr->representation().IsSmiOrInteger32());
1251 DCHECK(instr->left()->representation().Equals(instr->representation()));
1252 DCHECK(instr->right()->representation().Equals(instr->representation()));
1253 LOperand* dividend = UseRegisterAtStart(instr->left());
1254 int32_t divisor = instr->right()->GetInteger32Constant();
1255 LInstruction* result =
1256 DefineSameAsFirst(new (zone()) LModByPowerOf2I(dividend, divisor));
1257 if (instr->CheckFlag(HValue::kLeftCanBeNegative) &&
1258 instr->CheckFlag(HValue::kBailoutOnMinusZero)) {
1259 result = AssignEnvironment(result);
1260 }
1261 return result;
1262}
1263
1264LInstruction* LChunkBuilder::DoModByConstI(HMod* instr) {
1265 DCHECK(instr->representation().IsSmiOrInteger32());
1266 DCHECK(instr->left()->representation().Equals(instr->representation()));
1267 DCHECK(instr->right()->representation().Equals(instr->representation()));
1268 LOperand* dividend = UseRegister(instr->left());
1269 int32_t divisor = instr->right()->GetInteger32Constant();
1270 LInstruction* result =
1271 DefineAsRegister(new (zone()) LModByConstI(dividend, divisor));
1272 if (divisor == 0 || instr->CheckFlag(HValue::kBailoutOnMinusZero)) {
1273 result = AssignEnvironment(result);
1274 }
1275 return result;
1276}
1277
1278LInstruction* LChunkBuilder::DoModI(HMod* instr) {
1279 DCHECK(instr->representation().IsSmiOrInteger32());
1280 DCHECK(instr->left()->representation().Equals(instr->representation()));
1281 DCHECK(instr->right()->representation().Equals(instr->representation()));
1282 LOperand* dividend = UseRegister(instr->left());
1283 LOperand* divisor = UseRegister(instr->right());
1284 LInstruction* result =
1285 DefineAsRegister(new (zone()) LModI(dividend, divisor));
1286 if (instr->CheckFlag(HValue::kCanBeDivByZero) ||
1287 instr->CheckFlag(HValue::kBailoutOnMinusZero)) {
1288 result = AssignEnvironment(result);
1289 }
1290 return result;
1291}
1292
1293LInstruction* LChunkBuilder::DoMod(HMod* instr) {
1294 if (instr->representation().IsSmiOrInteger32()) {
1295 if (instr->RightIsPowerOf2()) {
1296 return DoModByPowerOf2I(instr);
1297 } else if (instr->right()->IsConstant()) {
1298 return DoModByConstI(instr);
1299 } else {
1300 return DoModI(instr);
1301 }
1302 } else if (instr->representation().IsDouble()) {
1303 return DoArithmeticD(Token::MOD, instr);
1304 } else {
1305 return DoArithmeticT(Token::MOD, instr);
1306 }
1307}
1308
1309LInstruction* LChunkBuilder::DoMul(HMul* instr) {
1310 if (instr->representation().IsSmiOrInteger32()) {
1311 DCHECK(instr->left()->representation().Equals(instr->representation()));
1312 DCHECK(instr->right()->representation().Equals(instr->representation()));
1313 HValue* left = instr->BetterLeftOperand();
1314 HValue* right = instr->BetterRightOperand();
1315 LOperand* left_op;
1316 LOperand* right_op;
1317 bool can_overflow = instr->CheckFlag(HValue::kCanOverflow);
1318 bool bailout_on_minus_zero = instr->CheckFlag(HValue::kBailoutOnMinusZero);
1319
1320 int32_t constant_value = 0;
1321 if (right->IsConstant()) {
1322 HConstant* constant = HConstant::cast(right);
1323 constant_value = constant->Integer32Value();
1324 // Constants -1, 0 and 1 can be optimized if the result can overflow.
1325 // For other constants, it can be optimized only without overflow.
1326 if (!can_overflow || ((constant_value >= -1) && (constant_value <= 1))) {
1327 left_op = UseRegisterAtStart(left);
1328 right_op = UseConstant(right);
1329 } else {
1330 if (bailout_on_minus_zero) {
1331 left_op = UseRegister(left);
1332 } else {
1333 left_op = UseRegisterAtStart(left);
1334 }
1335 right_op = UseRegister(right);
1336 }
1337 } else {
1338 if (bailout_on_minus_zero) {
1339 left_op = UseRegister(left);
1340 } else {
1341 left_op = UseRegisterAtStart(left);
1342 }
1343 right_op = UseRegister(right);
1344 }
1345 LMulI* mul = new (zone()) LMulI(left_op, right_op);
1346 if (right_op->IsConstantOperand()
1347 ? ((can_overflow && constant_value == -1) ||
1348 (bailout_on_minus_zero && constant_value <= 0))
1349 : (can_overflow || bailout_on_minus_zero)) {
1350 AssignEnvironment(mul);
1351 }
1352 return DefineAsRegister(mul);
1353
1354 } else if (instr->representation().IsDouble()) {
1355 return DoArithmeticD(Token::MUL, instr);
1356 } else {
1357 return DoArithmeticT(Token::MUL, instr);
1358 }
1359}
1360
1361LInstruction* LChunkBuilder::DoSub(HSub* instr) {
1362 if (instr->representation().IsSmiOrInteger32()) {
1363 DCHECK(instr->left()->representation().Equals(instr->representation()));
1364 DCHECK(instr->right()->representation().Equals(instr->representation()));
1365
1366 if (instr->left()->IsConstant() &&
1367 !instr->CheckFlag(HValue::kCanOverflow)) {
1368 // If lhs is constant, do reverse subtraction instead.
1369 return DoRSub(instr);
1370 }
1371
1372 LOperand* left = UseRegisterAtStart(instr->left());
1373 LOperand* right = UseOrConstantAtStart(instr->right());
1374 LSubI* sub = new (zone()) LSubI(left, right);
1375 LInstruction* result = DefineAsRegister(sub);
1376 if (instr->CheckFlag(HValue::kCanOverflow)) {
1377 result = AssignEnvironment(result);
1378 }
1379 return result;
1380 } else if (instr->representation().IsDouble()) {
1381 return DoArithmeticD(Token::SUB, instr);
1382 } else {
1383 return DoArithmeticT(Token::SUB, instr);
1384 }
1385}
1386
1387LInstruction* LChunkBuilder::DoRSub(HSub* instr) {
1388 DCHECK(instr->representation().IsSmiOrInteger32());
1389 DCHECK(instr->left()->representation().Equals(instr->representation()));
1390 DCHECK(instr->right()->representation().Equals(instr->representation()));
1391 DCHECK(!instr->CheckFlag(HValue::kCanOverflow));
1392
1393 // Note: The lhs of the subtraction becomes the rhs of the
1394 // reverse-subtraction.
1395 LOperand* left = UseRegisterAtStart(instr->right());
1396 LOperand* right = UseOrConstantAtStart(instr->left());
1397 LRSubI* rsb = new (zone()) LRSubI(left, right);
1398 LInstruction* result = DefineAsRegister(rsb);
1399 return result;
1400}
1401
1402LInstruction* LChunkBuilder::DoMultiplyAdd(HMul* mul, HValue* addend) {
1403 LOperand* multiplier_op = UseRegister(mul->left());
1404 LOperand* multiplicand_op = UseRegister(mul->right());
1405 LOperand* addend_op = UseRegister(addend);
1406 return DefineAsRegister(
1407 new (zone()) LMultiplyAddD(addend_op, multiplier_op, multiplicand_op));
1408}
1409
1410LInstruction* LChunkBuilder::DoMultiplySub(HValue* minuend, HMul* mul) {
1411 LOperand* minuend_op = UseRegister(minuend);
1412 LOperand* multiplier_op = UseRegister(mul->left());
1413 LOperand* multiplicand_op = UseRegister(mul->right());
1414
1415 return DefineAsRegister(
1416 new (zone()) LMultiplySubD(minuend_op, multiplier_op, multiplicand_op));
1417}
1418
1419LInstruction* LChunkBuilder::DoAdd(HAdd* instr) {
1420 if (instr->representation().IsSmiOrInteger32()) {
1421 DCHECK(instr->left()->representation().Equals(instr->representation()));
1422 DCHECK(instr->right()->representation().Equals(instr->representation()));
1423 LOperand* left = UseRegisterAtStart(instr->BetterLeftOperand());
1424 LOperand* right = UseOrConstantAtStart(instr->BetterRightOperand());
1425 LAddI* add = new (zone()) LAddI(left, right);
1426 LInstruction* result = DefineAsRegister(add);
1427 if (instr->CheckFlag(HValue::kCanOverflow)) {
1428 result = AssignEnvironment(result);
1429 }
1430 return result;
1431 } else if (instr->representation().IsExternal()) {
1432 DCHECK(instr->IsConsistentExternalRepresentation());
1433 DCHECK(!instr->CheckFlag(HValue::kCanOverflow));
1434 LOperand* left = UseRegisterAtStart(instr->left());
1435 LOperand* right = UseOrConstantAtStart(instr->right());
1436 LAddI* add = new (zone()) LAddI(left, right);
1437 LInstruction* result = DefineAsRegister(add);
1438 return result;
1439 } else if (instr->representation().IsDouble()) {
1440 return DoArithmeticD(Token::ADD, instr);
1441 } else {
1442 return DoArithmeticT(Token::ADD, instr);
1443 }
1444}
1445
1446LInstruction* LChunkBuilder::DoMathMinMax(HMathMinMax* instr) {
1447 LOperand* left = NULL;
1448 LOperand* right = NULL;
1449 if (instr->representation().IsSmiOrInteger32()) {
1450 DCHECK(instr->left()->representation().Equals(instr->representation()));
1451 DCHECK(instr->right()->representation().Equals(instr->representation()));
1452 left = UseRegisterAtStart(instr->BetterLeftOperand());
1453 right = UseOrConstantAtStart(instr->BetterRightOperand());
1454 } else {
1455 DCHECK(instr->representation().IsDouble());
1456 DCHECK(instr->left()->representation().IsDouble());
1457 DCHECK(instr->right()->representation().IsDouble());
1458 left = UseRegister(instr->left());
1459 right = UseRegister(instr->right());
1460 }
1461 return DefineAsRegister(new (zone()) LMathMinMax(left, right));
1462}
1463
1464LInstruction* LChunkBuilder::DoPower(HPower* instr) {
1465 DCHECK(instr->representation().IsDouble());
1466 // We call a C function for double power. It can't trigger a GC.
1467 // We need to use fixed result register for the call.
1468 Representation exponent_type = instr->right()->representation();
1469 DCHECK(instr->left()->representation().IsDouble());
1470 LOperand* left = UseFixedDouble(instr->left(), d1);
1471 LOperand* right = exponent_type.IsDouble()
1472 ? UseFixedDouble(instr->right(), d2)
1473 : UseFixed(instr->right(), r4);
1474 LPower* result = new (zone()) LPower(left, right);
1475 return MarkAsCall(DefineFixedDouble(result, d3), instr,
1476 CAN_DEOPTIMIZE_EAGERLY);
1477}
1478
1479LInstruction* LChunkBuilder::DoCompareGeneric(HCompareGeneric* instr) {
1480 DCHECK(instr->left()->representation().IsTagged());
1481 DCHECK(instr->right()->representation().IsTagged());
1482 LOperand* context = UseFixed(instr->context(), cp);
1483 LOperand* left = UseFixed(instr->left(), r3);
1484 LOperand* right = UseFixed(instr->right(), r2);
1485 LCmpT* result = new (zone()) LCmpT(context, left, right);
1486 return MarkAsCall(DefineFixed(result, r2), instr);
1487}
1488
1489LInstruction* LChunkBuilder::DoCompareNumericAndBranch(
1490 HCompareNumericAndBranch* instr) {
1491 Representation r = instr->representation();
1492 if (r.IsSmiOrInteger32()) {
1493 DCHECK(instr->left()->representation().Equals(r));
1494 DCHECK(instr->right()->representation().Equals(r));
1495 LOperand* left = UseRegisterOrConstantAtStart(instr->left());
1496 LOperand* right = UseRegisterOrConstantAtStart(instr->right());
1497 return new (zone()) LCompareNumericAndBranch(left, right);
1498 } else {
1499 DCHECK(r.IsDouble());
1500 DCHECK(instr->left()->representation().IsDouble());
1501 DCHECK(instr->right()->representation().IsDouble());
1502 LOperand* left = UseRegisterAtStart(instr->left());
1503 LOperand* right = UseRegisterAtStart(instr->right());
1504 return new (zone()) LCompareNumericAndBranch(left, right);
1505 }
1506}
1507
1508LInstruction* LChunkBuilder::DoCompareObjectEqAndBranch(
1509 HCompareObjectEqAndBranch* instr) {
1510 LOperand* left = UseRegisterAtStart(instr->left());
1511 LOperand* right = UseRegisterAtStart(instr->right());
1512 return new (zone()) LCmpObjectEqAndBranch(left, right);
1513}
1514
1515LInstruction* LChunkBuilder::DoCompareHoleAndBranch(
1516 HCompareHoleAndBranch* instr) {
1517 LOperand* value = UseRegisterAtStart(instr->value());
1518 return new (zone()) LCmpHoleAndBranch(value);
1519}
1520
1521LInstruction* LChunkBuilder::DoIsStringAndBranch(HIsStringAndBranch* instr) {
1522 DCHECK(instr->value()->representation().IsTagged());
1523 LOperand* value = UseRegisterAtStart(instr->value());
1524 LOperand* temp = TempRegister();
1525 return new (zone()) LIsStringAndBranch(value, temp);
1526}
1527
1528LInstruction* LChunkBuilder::DoIsSmiAndBranch(HIsSmiAndBranch* instr) {
1529 DCHECK(instr->value()->representation().IsTagged());
1530 return new (zone()) LIsSmiAndBranch(Use(instr->value()));
1531}
1532
1533LInstruction* LChunkBuilder::DoIsUndetectableAndBranch(
1534 HIsUndetectableAndBranch* instr) {
1535 DCHECK(instr->value()->representation().IsTagged());
1536 LOperand* value = UseRegisterAtStart(instr->value());
1537 return new (zone()) LIsUndetectableAndBranch(value, TempRegister());
1538}
1539
1540LInstruction* LChunkBuilder::DoStringCompareAndBranch(
1541 HStringCompareAndBranch* instr) {
1542 DCHECK(instr->left()->representation().IsTagged());
1543 DCHECK(instr->right()->representation().IsTagged());
1544 LOperand* context = UseFixed(instr->context(), cp);
1545 LOperand* left = UseFixed(instr->left(), r3);
1546 LOperand* right = UseFixed(instr->right(), r2);
1547 LStringCompareAndBranch* result =
1548 new (zone()) LStringCompareAndBranch(context, left, right);
1549 return MarkAsCall(result, instr);
1550}
1551
1552LInstruction* LChunkBuilder::DoHasInstanceTypeAndBranch(
1553 HHasInstanceTypeAndBranch* instr) {
1554 DCHECK(instr->value()->representation().IsTagged());
1555 LOperand* value = UseRegisterAtStart(instr->value());
1556 return new (zone()) LHasInstanceTypeAndBranch(value);
1557}
1558
1559LInstruction* LChunkBuilder::DoGetCachedArrayIndex(
1560 HGetCachedArrayIndex* instr) {
1561 DCHECK(instr->value()->representation().IsTagged());
1562 LOperand* value = UseRegisterAtStart(instr->value());
1563
1564 return DefineAsRegister(new (zone()) LGetCachedArrayIndex(value));
1565}
1566
1567LInstruction* LChunkBuilder::DoHasCachedArrayIndexAndBranch(
1568 HHasCachedArrayIndexAndBranch* instr) {
1569 DCHECK(instr->value()->representation().IsTagged());
1570 return new (zone())
1571 LHasCachedArrayIndexAndBranch(UseRegisterAtStart(instr->value()));
1572}
1573
1574LInstruction* LChunkBuilder::DoClassOfTestAndBranch(
1575 HClassOfTestAndBranch* instr) {
1576 DCHECK(instr->value()->representation().IsTagged());
1577 LOperand* value = UseRegister(instr->value());
1578 return new (zone()) LClassOfTestAndBranch(value, TempRegister());
1579}
1580
1581LInstruction* LChunkBuilder::DoSeqStringGetChar(HSeqStringGetChar* instr) {
1582 LOperand* string = UseRegisterAtStart(instr->string());
1583 LOperand* index = UseRegisterOrConstantAtStart(instr->index());
1584 return DefineAsRegister(new (zone()) LSeqStringGetChar(string, index));
1585}
1586
1587LInstruction* LChunkBuilder::DoSeqStringSetChar(HSeqStringSetChar* instr) {
1588 LOperand* string = UseRegisterAtStart(instr->string());
1589 LOperand* index = FLAG_debug_code
1590 ? UseRegisterAtStart(instr->index())
1591 : UseRegisterOrConstantAtStart(instr->index());
1592 LOperand* value = UseRegisterAtStart(instr->value());
1593 LOperand* context = FLAG_debug_code ? UseFixed(instr->context(), cp) : NULL;
1594 return new (zone()) LSeqStringSetChar(context, string, index, value);
1595}
1596
1597LInstruction* LChunkBuilder::DoBoundsCheck(HBoundsCheck* instr) {
1598 if (!FLAG_debug_code && instr->skip_check()) return NULL;
1599 LOperand* index = UseRegisterOrConstantAtStart(instr->index());
1600 LOperand* length = !index->IsConstantOperand()
1601 ? UseRegisterOrConstantAtStart(instr->length())
1602 : UseRegisterAtStart(instr->length());
1603 LInstruction* result = new (zone()) LBoundsCheck(index, length);
1604 if (!FLAG_debug_code || !instr->skip_check()) {
1605 result = AssignEnvironment(result);
1606 }
1607 return result;
1608}
1609
1610LInstruction* LChunkBuilder::DoAbnormalExit(HAbnormalExit* instr) {
1611 // The control instruction marking the end of a block that completed
1612 // abruptly (e.g., threw an exception). There is nothing specific to do.
1613 return NULL;
1614}
1615
1616LInstruction* LChunkBuilder::DoUseConst(HUseConst* instr) { return NULL; }
1617
1618LInstruction* LChunkBuilder::DoForceRepresentation(HForceRepresentation* bad) {
1619 // All HForceRepresentation instructions should be eliminated in the
1620 // representation change phase of Hydrogen.
1621 UNREACHABLE();
1622 return NULL;
1623}
1624
1625LInstruction* LChunkBuilder::DoChange(HChange* instr) {
1626 Representation from = instr->from();
1627 Representation to = instr->to();
1628 HValue* val = instr->value();
1629 if (from.IsSmi()) {
1630 if (to.IsTagged()) {
1631 LOperand* value = UseRegister(val);
1632 return DefineSameAsFirst(new (zone()) LDummyUse(value));
1633 }
1634 from = Representation::Tagged();
1635 }
1636 if (from.IsTagged()) {
1637 if (to.IsDouble()) {
1638 LOperand* value = UseRegister(val);
1639 LInstruction* result =
1640 DefineAsRegister(new (zone()) LNumberUntagD(value));
1641 if (!val->representation().IsSmi()) result = AssignEnvironment(result);
1642 return result;
1643 } else if (to.IsSmi()) {
1644 LOperand* value = UseRegister(val);
1645 if (val->type().IsSmi()) {
1646 return DefineSameAsFirst(new (zone()) LDummyUse(value));
1647 }
1648 return AssignEnvironment(
1649 DefineSameAsFirst(new (zone()) LCheckSmi(value)));
1650 } else {
1651 DCHECK(to.IsInteger32());
1652 if (val->type().IsSmi() || val->representation().IsSmi()) {
1653 LOperand* value = UseRegisterAtStart(val);
1654 return DefineAsRegister(new (zone()) LSmiUntag(value, false));
1655 } else {
1656 LOperand* value = UseRegister(val);
1657 LOperand* temp1 = TempRegister();
1658 LOperand* temp2 = TempDoubleRegister();
1659 LInstruction* result =
1660 DefineSameAsFirst(new (zone()) LTaggedToI(value, temp1, temp2));
1661 if (!val->representation().IsSmi()) result = AssignEnvironment(result);
1662 return result;
1663 }
1664 }
1665 } else if (from.IsDouble()) {
1666 if (to.IsTagged()) {
1667 info()->MarkAsDeferredCalling();
1668 LOperand* value = UseRegister(val);
1669 LOperand* temp1 = TempRegister();
1670 LOperand* temp2 = TempRegister();
1671 LUnallocated* result_temp = TempRegister();
1672 LNumberTagD* result = new (zone()) LNumberTagD(value, temp1, temp2);
1673 return AssignPointerMap(Define(result, result_temp));
1674 } else if (to.IsSmi()) {
1675 LOperand* value = UseRegister(val);
1676 return AssignEnvironment(
1677 DefineAsRegister(new (zone()) LDoubleToSmi(value)));
1678 } else {
1679 DCHECK(to.IsInteger32());
1680 LOperand* value = UseRegister(val);
1681 LInstruction* result = DefineAsRegister(new (zone()) LDoubleToI(value));
1682 if (!instr->CanTruncateToInt32()) result = AssignEnvironment(result);
1683 return result;
1684 }
1685 } else if (from.IsInteger32()) {
1686 info()->MarkAsDeferredCalling();
1687 if (to.IsTagged()) {
1688 if (!instr->CheckFlag(HValue::kCanOverflow)) {
1689 LOperand* value = UseRegisterAtStart(val);
1690 return DefineAsRegister(new (zone()) LSmiTag(value));
1691 } else if (val->CheckFlag(HInstruction::kUint32)) {
1692 LOperand* value = UseRegisterAtStart(val);
1693 LOperand* temp1 = TempRegister();
1694 LOperand* temp2 = TempRegister();
1695 LNumberTagU* result = new (zone()) LNumberTagU(value, temp1, temp2);
1696 return AssignPointerMap(DefineAsRegister(result));
1697 } else {
1698 LOperand* value = UseRegisterAtStart(val);
1699 LOperand* temp1 = TempRegister();
1700 LOperand* temp2 = TempRegister();
1701 LNumberTagI* result = new (zone()) LNumberTagI(value, temp1, temp2);
1702 return AssignPointerMap(DefineAsRegister(result));
1703 }
1704 } else if (to.IsSmi()) {
1705 LOperand* value = UseRegister(val);
1706 LInstruction* result = DefineAsRegister(new (zone()) LSmiTag(value));
1707 if (instr->CheckFlag(HValue::kCanOverflow)) {
1708 result = AssignEnvironment(result);
1709 }
1710 return result;
1711 } else {
1712 DCHECK(to.IsDouble());
1713 if (val->CheckFlag(HInstruction::kUint32)) {
1714 return DefineAsRegister(new (zone()) LUint32ToDouble(UseRegister(val)));
1715 } else {
1716 return DefineAsRegister(new (zone()) LInteger32ToDouble(Use(val)));
1717 }
1718 }
1719 }
1720 UNREACHABLE();
1721 return NULL;
1722}
1723
1724LInstruction* LChunkBuilder::DoCheckHeapObject(HCheckHeapObject* instr) {
1725 LOperand* value = UseRegisterAtStart(instr->value());
1726 LInstruction* result = new (zone()) LCheckNonSmi(value);
1727 if (!instr->value()->type().IsHeapObject()) {
1728 result = AssignEnvironment(result);
1729 }
1730 return result;
1731}
1732
1733LInstruction* LChunkBuilder::DoCheckSmi(HCheckSmi* instr) {
1734 LOperand* value = UseRegisterAtStart(instr->value());
1735 return AssignEnvironment(new (zone()) LCheckSmi(value));
1736}
1737
1738LInstruction* LChunkBuilder::DoCheckArrayBufferNotNeutered(
1739 HCheckArrayBufferNotNeutered* instr) {
1740 LOperand* view = UseRegisterAtStart(instr->value());
1741 LCheckArrayBufferNotNeutered* result =
1742 new (zone()) LCheckArrayBufferNotNeutered(view);
1743 return AssignEnvironment(result);
1744}
1745
1746LInstruction* LChunkBuilder::DoCheckInstanceType(HCheckInstanceType* instr) {
1747 LOperand* value = UseRegisterAtStart(instr->value());
1748 LInstruction* result = new (zone()) LCheckInstanceType(value);
1749 return AssignEnvironment(result);
1750}
1751
1752LInstruction* LChunkBuilder::DoCheckValue(HCheckValue* instr) {
1753 LOperand* value = UseRegisterAtStart(instr->value());
1754 return AssignEnvironment(new (zone()) LCheckValue(value));
1755}
1756
1757LInstruction* LChunkBuilder::DoCheckMaps(HCheckMaps* instr) {
1758 if (instr->IsStabilityCheck()) return new (zone()) LCheckMaps;
1759 LOperand* value = UseRegisterAtStart(instr->value());
1760 LOperand* temp = TempRegister();
1761 LInstruction* result =
1762 AssignEnvironment(new (zone()) LCheckMaps(value, temp));
1763 if (instr->HasMigrationTarget()) {
1764 info()->MarkAsDeferredCalling();
1765 result = AssignPointerMap(result);
1766 }
1767 return result;
1768}
1769
1770LInstruction* LChunkBuilder::DoClampToUint8(HClampToUint8* instr) {
1771 HValue* value = instr->value();
1772 Representation input_rep = value->representation();
1773 LOperand* reg = UseRegister(value);
1774 if (input_rep.IsDouble()) {
1775 return DefineAsRegister(new (zone()) LClampDToUint8(reg));
1776 } else if (input_rep.IsInteger32()) {
1777 return DefineAsRegister(new (zone()) LClampIToUint8(reg));
1778 } else {
1779 DCHECK(input_rep.IsSmiOrTagged());
1780 LClampTToUint8* result =
1781 new (zone()) LClampTToUint8(reg, TempDoubleRegister());
1782 return AssignEnvironment(DefineAsRegister(result));
1783 }
1784}
1785
1786LInstruction* LChunkBuilder::DoDoubleBits(HDoubleBits* instr) {
1787 HValue* value = instr->value();
1788 DCHECK(value->representation().IsDouble());
1789 return DefineAsRegister(new (zone()) LDoubleBits(UseRegister(value)));
1790}
1791
1792LInstruction* LChunkBuilder::DoConstructDouble(HConstructDouble* instr) {
1793 LOperand* lo = UseRegister(instr->lo());
1794 LOperand* hi = UseRegister(instr->hi());
1795 return DefineAsRegister(new (zone()) LConstructDouble(hi, lo));
1796}
1797
1798LInstruction* LChunkBuilder::DoReturn(HReturn* instr) {
1799 LOperand* context = info()->IsStub() ? UseFixed(instr->context(), cp) : NULL;
1800 LOperand* parameter_count = UseRegisterOrConstant(instr->parameter_count());
1801 return new (zone())
1802 LReturn(UseFixed(instr->value(), r2), context, parameter_count);
1803}
1804
1805LInstruction* LChunkBuilder::DoConstant(HConstant* instr) {
1806 Representation r = instr->representation();
1807 if (r.IsSmi()) {
1808 return DefineAsRegister(new (zone()) LConstantS);
1809 } else if (r.IsInteger32()) {
1810 return DefineAsRegister(new (zone()) LConstantI);
1811 } else if (r.IsDouble()) {
1812 return DefineAsRegister(new (zone()) LConstantD);
1813 } else if (r.IsExternal()) {
1814 return DefineAsRegister(new (zone()) LConstantE);
1815 } else if (r.IsTagged()) {
1816 return DefineAsRegister(new (zone()) LConstantT);
1817 } else {
1818 UNREACHABLE();
1819 return NULL;
1820 }
1821}
1822
1823LInstruction* LChunkBuilder::DoLoadGlobalGeneric(HLoadGlobalGeneric* instr) {
1824 LOperand* context = UseFixed(instr->context(), cp);
1825 LOperand* global_object =
1826 UseFixed(instr->global_object(), LoadDescriptor::ReceiverRegister());
1827 LOperand* vector = NULL;
1828 if (instr->HasVectorAndSlot()) {
1829 vector = FixedTemp(LoadWithVectorDescriptor::VectorRegister());
1830 }
1831 LLoadGlobalGeneric* result =
1832 new (zone()) LLoadGlobalGeneric(context, global_object, vector);
1833 return MarkAsCall(DefineFixed(result, r2), instr);
1834}
1835
1836LInstruction* LChunkBuilder::DoLoadContextSlot(HLoadContextSlot* instr) {
1837 LOperand* context = UseRegisterAtStart(instr->value());
1838 LInstruction* result =
1839 DefineAsRegister(new (zone()) LLoadContextSlot(context));
1840 if (instr->RequiresHoleCheck() && instr->DeoptimizesOnHole()) {
1841 result = AssignEnvironment(result);
1842 }
1843 return result;
1844}
1845
1846LInstruction* LChunkBuilder::DoStoreContextSlot(HStoreContextSlot* instr) {
1847 LOperand* context;
1848 LOperand* value;
1849 if (instr->NeedsWriteBarrier()) {
1850 context = UseTempRegister(instr->context());
1851 value = UseTempRegister(instr->value());
1852 } else {
1853 context = UseRegister(instr->context());
1854 value = UseRegister(instr->value());
1855 }
1856 LInstruction* result = new (zone()) LStoreContextSlot(context, value);
1857 if (instr->RequiresHoleCheck() && instr->DeoptimizesOnHole()) {
1858 result = AssignEnvironment(result);
1859 }
1860 return result;
1861}
1862
1863LInstruction* LChunkBuilder::DoLoadNamedField(HLoadNamedField* instr) {
1864 LOperand* obj = UseRegisterAtStart(instr->object());
1865 return DefineAsRegister(new (zone()) LLoadNamedField(obj));
1866}
1867
1868LInstruction* LChunkBuilder::DoLoadNamedGeneric(HLoadNamedGeneric* instr) {
1869 LOperand* context = UseFixed(instr->context(), cp);
1870 LOperand* object =
1871 UseFixed(instr->object(), LoadDescriptor::ReceiverRegister());
1872 LOperand* vector = NULL;
1873 if (instr->HasVectorAndSlot()) {
1874 vector = FixedTemp(LoadWithVectorDescriptor::VectorRegister());
1875 }
1876
1877 LInstruction* result =
1878 DefineFixed(new (zone()) LLoadNamedGeneric(context, object, vector), r2);
1879 return MarkAsCall(result, instr);
1880}
1881
1882LInstruction* LChunkBuilder::DoLoadFunctionPrototype(
1883 HLoadFunctionPrototype* instr) {
1884 return AssignEnvironment(DefineAsRegister(
1885 new (zone()) LLoadFunctionPrototype(UseRegister(instr->function()))));
1886}
1887
1888LInstruction* LChunkBuilder::DoLoadRoot(HLoadRoot* instr) {
1889 return DefineAsRegister(new (zone()) LLoadRoot);
1890}
1891
1892LInstruction* LChunkBuilder::DoLoadKeyed(HLoadKeyed* instr) {
1893 DCHECK(instr->key()->representation().IsSmiOrInteger32());
1894 ElementsKind elements_kind = instr->elements_kind();
1895 LOperand* key = UseRegisterOrConstantAtStart(instr->key());
1896 LInstruction* result = NULL;
1897
1898 if (!instr->is_fixed_typed_array()) {
1899 LOperand* obj = NULL;
1900 if (instr->representation().IsDouble()) {
1901 obj = UseRegister(instr->elements());
1902 } else {
1903 obj = UseRegisterAtStart(instr->elements());
1904 }
1905 result = DefineAsRegister(new (zone()) LLoadKeyed(obj, key, nullptr));
1906 } else {
1907 DCHECK((instr->representation().IsInteger32() &&
1908 !IsDoubleOrFloatElementsKind(elements_kind)) ||
1909 (instr->representation().IsDouble() &&
1910 IsDoubleOrFloatElementsKind(elements_kind)));
1911 LOperand* backing_store = UseRegister(instr->elements());
1912 LOperand* backing_store_owner = UseAny(instr->backing_store_owner());
1913 result = DefineAsRegister(
1914 new (zone()) LLoadKeyed(backing_store, key, backing_store_owner));
1915 }
1916
1917 bool needs_environment;
1918 if (instr->is_fixed_typed_array()) {
1919 // see LCodeGen::DoLoadKeyedExternalArray
1920 needs_environment = elements_kind == UINT32_ELEMENTS &&
1921 !instr->CheckFlag(HInstruction::kUint32);
1922 } else {
1923 // see LCodeGen::DoLoadKeyedFixedDoubleArray and
1924 // LCodeGen::DoLoadKeyedFixedArray
1925 needs_environment =
1926 instr->RequiresHoleCheck() ||
1927 (instr->hole_mode() == CONVERT_HOLE_TO_UNDEFINED && info()->IsStub());
1928 }
1929
1930 if (needs_environment) {
1931 result = AssignEnvironment(result);
1932 }
1933 return result;
1934}
1935
1936LInstruction* LChunkBuilder::DoLoadKeyedGeneric(HLoadKeyedGeneric* instr) {
1937 LOperand* context = UseFixed(instr->context(), cp);
1938 LOperand* object =
1939 UseFixed(instr->object(), LoadDescriptor::ReceiverRegister());
1940 LOperand* key = UseFixed(instr->key(), LoadDescriptor::NameRegister());
1941 LOperand* vector = NULL;
1942 if (instr->HasVectorAndSlot()) {
1943 vector = FixedTemp(LoadWithVectorDescriptor::VectorRegister());
1944 }
1945
1946 LInstruction* result = DefineFixed(
1947 new (zone()) LLoadKeyedGeneric(context, object, key, vector), r2);
1948 return MarkAsCall(result, instr);
1949}
1950
1951LInstruction* LChunkBuilder::DoStoreKeyed(HStoreKeyed* instr) {
1952 if (!instr->is_fixed_typed_array()) {
1953 DCHECK(instr->elements()->representation().IsTagged());
1954 bool needs_write_barrier = instr->NeedsWriteBarrier();
1955 LOperand* object = NULL;
1956 LOperand* key = NULL;
1957 LOperand* val = NULL;
1958
1959 if (instr->value()->representation().IsDouble()) {
1960 object = UseRegisterAtStart(instr->elements());
1961 val = UseRegister(instr->value());
1962 key = UseRegisterOrConstantAtStart(instr->key());
1963 } else {
1964 if (needs_write_barrier) {
1965 object = UseTempRegister(instr->elements());
1966 val = UseTempRegister(instr->value());
1967 key = UseTempRegister(instr->key());
1968 } else {
1969 object = UseRegisterAtStart(instr->elements());
1970 val = UseRegisterAtStart(instr->value());
1971 key = UseRegisterOrConstantAtStart(instr->key());
1972 }
1973 }
1974
1975 return new (zone()) LStoreKeyed(object, key, val, nullptr);
1976 }
1977
1978 DCHECK((instr->value()->representation().IsInteger32() &&
1979 !IsDoubleOrFloatElementsKind(instr->elements_kind())) ||
1980 (instr->value()->representation().IsDouble() &&
1981 IsDoubleOrFloatElementsKind(instr->elements_kind())));
1982 DCHECK(instr->elements()->representation().IsExternal());
1983 LOperand* val = UseRegister(instr->value());
1984 LOperand* key = UseRegisterOrConstantAtStart(instr->key());
1985 LOperand* backing_store = UseRegister(instr->elements());
1986 LOperand* backing_store_owner = UseAny(instr->backing_store_owner());
1987 return new (zone()) LStoreKeyed(backing_store, key, val, backing_store_owner);
1988}
1989
1990LInstruction* LChunkBuilder::DoStoreKeyedGeneric(HStoreKeyedGeneric* instr) {
1991 LOperand* context = UseFixed(instr->context(), cp);
1992 LOperand* obj =
1993 UseFixed(instr->object(), StoreDescriptor::ReceiverRegister());
1994 LOperand* key = UseFixed(instr->key(), StoreDescriptor::NameRegister());
1995 LOperand* val = UseFixed(instr->value(), StoreDescriptor::ValueRegister());
1996
1997 DCHECK(instr->object()->representation().IsTagged());
1998 DCHECK(instr->key()->representation().IsTagged());
1999 DCHECK(instr->value()->representation().IsTagged());
2000
2001 LOperand* slot = NULL;
2002 LOperand* vector = NULL;
2003 if (instr->HasVectorAndSlot()) {
2004 slot = FixedTemp(VectorStoreICDescriptor::SlotRegister());
2005 vector = FixedTemp(VectorStoreICDescriptor::VectorRegister());
2006 }
2007
2008 LStoreKeyedGeneric* result =
2009 new (zone()) LStoreKeyedGeneric(context, obj, key, val, slot, vector);
2010 return MarkAsCall(result, instr);
2011}
2012
2013LInstruction* LChunkBuilder::DoTransitionElementsKind(
2014 HTransitionElementsKind* instr) {
2015 if (IsSimpleMapChangeTransition(instr->from_kind(), instr->to_kind())) {
2016 LOperand* object = UseRegister(instr->object());
2017 LOperand* new_map_reg = TempRegister();
2018 LTransitionElementsKind* result =
2019 new (zone()) LTransitionElementsKind(object, NULL, new_map_reg);
2020 return result;
2021 } else {
2022 LOperand* object = UseFixed(instr->object(), r2);
2023 LOperand* context = UseFixed(instr->context(), cp);
2024 LTransitionElementsKind* result =
2025 new (zone()) LTransitionElementsKind(object, context, NULL);
2026 return MarkAsCall(result, instr);
2027 }
2028}
2029
2030LInstruction* LChunkBuilder::DoTrapAllocationMemento(
2031 HTrapAllocationMemento* instr) {
2032 LOperand* object = UseRegister(instr->object());
2033 LOperand* temp1 = TempRegister();
2034 LOperand* temp2 = TempRegister();
2035 LTrapAllocationMemento* result =
2036 new (zone()) LTrapAllocationMemento(object, temp1, temp2);
2037 return AssignEnvironment(result);
2038}
2039
2040LInstruction* LChunkBuilder::DoMaybeGrowElements(HMaybeGrowElements* instr) {
2041 info()->MarkAsDeferredCalling();
2042 LOperand* context = UseFixed(instr->context(), cp);
2043 LOperand* object = Use(instr->object());
2044 LOperand* elements = Use(instr->elements());
2045 LOperand* key = UseRegisterOrConstant(instr->key());
2046 LOperand* current_capacity = UseRegisterOrConstant(instr->current_capacity());
2047
2048 LMaybeGrowElements* result = new (zone())
2049 LMaybeGrowElements(context, object, elements, key, current_capacity);
2050 DefineFixed(result, r2);
2051 return AssignPointerMap(AssignEnvironment(result));
2052}
2053
2054LInstruction* LChunkBuilder::DoStoreNamedField(HStoreNamedField* instr) {
2055 bool is_in_object = instr->access().IsInobject();
2056 bool needs_write_barrier = instr->NeedsWriteBarrier();
2057 bool needs_write_barrier_for_map =
2058 instr->has_transition() && instr->NeedsWriteBarrierForMap();
2059
2060 LOperand* obj;
2061 if (needs_write_barrier) {
2062 obj = is_in_object ? UseRegister(instr->object())
2063 : UseTempRegister(instr->object());
2064 } else {
2065 obj = needs_write_barrier_for_map ? UseRegister(instr->object())
2066 : UseRegisterAtStart(instr->object());
2067 }
2068
2069 LOperand* val;
2070 if (needs_write_barrier) {
2071 val = UseTempRegister(instr->value());
2072 } else if (instr->field_representation().IsDouble()) {
2073 val = UseRegisterAtStart(instr->value());
2074 } else {
2075 val = UseRegister(instr->value());
2076 }
2077
2078 // We need a temporary register for write barrier of the map field.
2079 LOperand* temp = needs_write_barrier_for_map ? TempRegister() : NULL;
2080
2081 return new (zone()) LStoreNamedField(obj, val, temp);
2082}
2083
2084LInstruction* LChunkBuilder::DoStoreNamedGeneric(HStoreNamedGeneric* instr) {
2085 LOperand* context = UseFixed(instr->context(), cp);
2086 LOperand* obj =
2087 UseFixed(instr->object(), StoreDescriptor::ReceiverRegister());
2088 LOperand* val = UseFixed(instr->value(), StoreDescriptor::ValueRegister());
2089 LOperand* slot = NULL;
2090 LOperand* vector = NULL;
2091 if (instr->HasVectorAndSlot()) {
2092 slot = FixedTemp(VectorStoreICDescriptor::SlotRegister());
2093 vector = FixedTemp(VectorStoreICDescriptor::VectorRegister());
2094 }
2095
2096 LStoreNamedGeneric* result =
2097 new (zone()) LStoreNamedGeneric(context, obj, val, slot, vector);
2098 return MarkAsCall(result, instr);
2099}
2100
2101LInstruction* LChunkBuilder::DoStringAdd(HStringAdd* instr) {
2102 LOperand* context = UseFixed(instr->context(), cp);
2103 LOperand* left = UseFixed(instr->left(), r3);
2104 LOperand* right = UseFixed(instr->right(), r2);
2105 return MarkAsCall(
2106 DefineFixed(new (zone()) LStringAdd(context, left, right), r2), instr);
2107}
2108
2109LInstruction* LChunkBuilder::DoStringCharCodeAt(HStringCharCodeAt* instr) {
2110 LOperand* string = UseTempRegister(instr->string());
2111 LOperand* index = UseTempRegister(instr->index());
2112 LOperand* context = UseAny(instr->context());
2113 LStringCharCodeAt* result =
2114 new (zone()) LStringCharCodeAt(context, string, index);
2115 return AssignPointerMap(DefineAsRegister(result));
2116}
2117
2118LInstruction* LChunkBuilder::DoStringCharFromCode(HStringCharFromCode* instr) {
2119 LOperand* char_code = UseRegister(instr->value());
2120 LOperand* context = UseAny(instr->context());
2121 LStringCharFromCode* result =
2122 new (zone()) LStringCharFromCode(context, char_code);
2123 return AssignPointerMap(DefineAsRegister(result));
2124}
2125
2126LInstruction* LChunkBuilder::DoAllocate(HAllocate* instr) {
2127 info()->MarkAsDeferredCalling();
2128 LOperand* context = UseAny(instr->context());
2129 LOperand* size = UseRegisterOrConstant(instr->size());
2130 LOperand* temp1 = TempRegister();
2131 LOperand* temp2 = TempRegister();
2132 LAllocate* result = new (zone()) LAllocate(context, size, temp1, temp2);
2133 return AssignPointerMap(DefineAsRegister(result));
2134}
2135
2136LInstruction* LChunkBuilder::DoOsrEntry(HOsrEntry* instr) {
2137 DCHECK(argument_count_ == 0);
2138 allocator_->MarkAsOsrEntry();
2139 current_block_->last_environment()->set_ast_id(instr->ast_id());
2140 return AssignEnvironment(new (zone()) LOsrEntry);
2141}
2142
2143LInstruction* LChunkBuilder::DoParameter(HParameter* instr) {
2144 LParameter* result = new (zone()) LParameter;
2145 if (instr->kind() == HParameter::STACK_PARAMETER) {
2146 int spill_index = chunk()->GetParameterStackSlot(instr->index());
2147 return DefineAsSpilled(result, spill_index);
2148 } else {
2149 DCHECK(info()->IsStub());
2150 CallInterfaceDescriptor descriptor = graph()->descriptor();
2151 int index = static_cast<int>(instr->index());
2152 Register reg = descriptor.GetRegisterParameter(index);
2153 return DefineFixed(result, reg);
2154 }
2155}
2156
2157LInstruction* LChunkBuilder::DoUnknownOSRValue(HUnknownOSRValue* instr) {
2158 // Use an index that corresponds to the location in the unoptimized frame,
2159 // which the optimized frame will subsume.
2160 int env_index = instr->index();
2161 int spill_index = 0;
2162 if (instr->environment()->is_parameter_index(env_index)) {
2163 spill_index = chunk()->GetParameterStackSlot(env_index);
2164 } else {
2165 spill_index = env_index - instr->environment()->first_local_index();
2166 if (spill_index > LUnallocated::kMaxFixedSlotIndex) {
2167 Retry(kTooManySpillSlotsNeededForOSR);
2168 spill_index = 0;
2169 }
2170 spill_index += StandardFrameConstants::kFixedSlotCount;
2171 }
2172 return DefineAsSpilled(new (zone()) LUnknownOSRValue, spill_index);
2173}
2174
2175LInstruction* LChunkBuilder::DoArgumentsObject(HArgumentsObject* instr) {
2176 // There are no real uses of the arguments object.
2177 // arguments.length and element access are supported directly on
2178 // stack arguments, and any real arguments object use causes a bailout.
2179 // So this value is never used.
2180 return NULL;
2181}
2182
2183LInstruction* LChunkBuilder::DoCapturedObject(HCapturedObject* instr) {
2184 instr->ReplayEnvironment(current_block_->last_environment());
2185
2186 // There are no real uses of a captured object.
2187 return NULL;
2188}
2189
2190LInstruction* LChunkBuilder::DoAccessArgumentsAt(HAccessArgumentsAt* instr) {
2191 info()->MarkAsRequiresFrame();
2192 LOperand* args = UseRegister(instr->arguments());
2193 LOperand* length = UseRegisterOrConstantAtStart(instr->length());
2194 LOperand* index = UseRegisterOrConstantAtStart(instr->index());
2195 return DefineAsRegister(new (zone()) LAccessArgumentsAt(args, length, index));
2196}
2197
2198LInstruction* LChunkBuilder::DoTypeof(HTypeof* instr) {
2199 LOperand* context = UseFixed(instr->context(), cp);
2200 LOperand* value = UseFixed(instr->value(), r5);
2201 LTypeof* result = new (zone()) LTypeof(context, value);
2202 return MarkAsCall(DefineFixed(result, r2), instr);
2203}
2204
2205LInstruction* LChunkBuilder::DoTypeofIsAndBranch(HTypeofIsAndBranch* instr) {
2206 return new (zone()) LTypeofIsAndBranch(UseRegister(instr->value()));
2207}
2208
2209LInstruction* LChunkBuilder::DoSimulate(HSimulate* instr) {
2210 instr->ReplayEnvironment(current_block_->last_environment());
2211 return NULL;
2212}
2213
2214LInstruction* LChunkBuilder::DoStackCheck(HStackCheck* instr) {
2215 if (instr->is_function_entry()) {
2216 LOperand* context = UseFixed(instr->context(), cp);
2217 return MarkAsCall(new (zone()) LStackCheck(context), instr);
2218 } else {
2219 DCHECK(instr->is_backwards_branch());
2220 LOperand* context = UseAny(instr->context());
2221 return AssignEnvironment(
2222 AssignPointerMap(new (zone()) LStackCheck(context)));
2223 }
2224}
2225
2226LInstruction* LChunkBuilder::DoEnterInlined(HEnterInlined* instr) {
2227 HEnvironment* outer = current_block_->last_environment();
2228 outer->set_ast_id(instr->ReturnId());
2229 HConstant* undefined = graph()->GetConstantUndefined();
2230 HEnvironment* inner = outer->CopyForInlining(
2231 instr->closure(), instr->arguments_count(), instr->function(), undefined,
2232 instr->inlining_kind(), instr->syntactic_tail_call_mode());
2233 // Only replay binding of arguments object if it wasn't removed from graph.
2234 if (instr->arguments_var() != NULL && instr->arguments_object()->IsLinked()) {
2235 inner->Bind(instr->arguments_var(), instr->arguments_object());
2236 }
2237 inner->BindContext(instr->closure_context());
2238 inner->set_entry(instr);
2239 current_block_->UpdateEnvironment(inner);
2240 chunk_->AddInlinedFunction(instr->shared());
2241 return NULL;
2242}
2243
2244LInstruction* LChunkBuilder::DoLeaveInlined(HLeaveInlined* instr) {
2245 LInstruction* pop = NULL;
2246
2247 HEnvironment* env = current_block_->last_environment();
2248
2249 if (env->entry()->arguments_pushed()) {
2250 int argument_count = env->arguments_environment()->parameter_count();
2251 pop = new (zone()) LDrop(argument_count);
2252 DCHECK(instr->argument_delta() == -argument_count);
2253 }
2254
2255 HEnvironment* outer =
2256 current_block_->last_environment()->DiscardInlined(false);
2257 current_block_->UpdateEnvironment(outer);
2258
2259 return pop;
2260}
2261
2262LInstruction* LChunkBuilder::DoForInPrepareMap(HForInPrepareMap* instr) {
2263 LOperand* context = UseFixed(instr->context(), cp);
2264 LOperand* object = UseFixed(instr->enumerable(), r2);
2265 LForInPrepareMap* result = new (zone()) LForInPrepareMap(context, object);
2266 return MarkAsCall(DefineFixed(result, r2), instr, CAN_DEOPTIMIZE_EAGERLY);
2267}
2268
2269LInstruction* LChunkBuilder::DoForInCacheArray(HForInCacheArray* instr) {
2270 LOperand* map = UseRegister(instr->map());
2271 return AssignEnvironment(
2272 DefineAsRegister(new (zone()) LForInCacheArray(map)));
2273}
2274
2275LInstruction* LChunkBuilder::DoCheckMapValue(HCheckMapValue* instr) {
2276 LOperand* value = UseRegisterAtStart(instr->value());
2277 LOperand* map = UseRegisterAtStart(instr->map());
2278 return AssignEnvironment(new (zone()) LCheckMapValue(value, map));
2279}
2280
2281LInstruction* LChunkBuilder::DoLoadFieldByIndex(HLoadFieldByIndex* instr) {
2282 LOperand* object = UseRegister(instr->object());
2283 LOperand* index = UseTempRegister(instr->index());
2284 LLoadFieldByIndex* load = new (zone()) LLoadFieldByIndex(object, index);
2285 LInstruction* result = DefineSameAsFirst(load);
2286 return AssignPointerMap(result);
2287}
2288
2289} // namespace internal
2290} // namespace v8