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