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