blob: 71c34df516c4149b24c8995565c7f01a676f0871 [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();
890 if (info_->num_heap_slots() > 0) {
891 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
942LInstruction* LChunkBuilder::DoInstanceOf(HInstanceOf* instr) {
943 LOperand* left =
944 UseFixed(instr->left(), InstanceOfDescriptor::LeftRegister());
945 LOperand* right =
946 UseFixed(instr->right(), InstanceOfDescriptor::RightRegister());
947 LOperand* context = UseFixed(instr->context(), cp);
948 LInstanceOf* result = new (zone()) LInstanceOf(context, left, right);
949 return MarkAsCall(DefineFixed(result, v0), instr);
950}
951
952
953LInstruction* LChunkBuilder::DoHasInPrototypeChainAndBranch(
954 HHasInPrototypeChainAndBranch* instr) {
955 LOperand* object = UseRegister(instr->object());
956 LOperand* prototype = UseRegister(instr->prototype());
957 LHasInPrototypeChainAndBranch* result =
958 new (zone()) LHasInPrototypeChainAndBranch(object, prototype);
959 return AssignEnvironment(result);
960}
961
962
963LInstruction* LChunkBuilder::DoWrapReceiver(HWrapReceiver* instr) {
964 LOperand* receiver = UseRegisterAtStart(instr->receiver());
965 LOperand* function = UseRegisterAtStart(instr->function());
966 LWrapReceiver* result = new(zone()) LWrapReceiver(receiver, function);
967 return AssignEnvironment(DefineAsRegister(result));
968}
969
970
971LInstruction* LChunkBuilder::DoApplyArguments(HApplyArguments* instr) {
972 LOperand* function = UseFixed(instr->function(), a1);
973 LOperand* receiver = UseFixed(instr->receiver(), a0);
974 LOperand* length = UseFixed(instr->length(), a2);
975 LOperand* elements = UseFixed(instr->elements(), a3);
976 LApplyArguments* result = new(zone()) LApplyArguments(function,
977 receiver,
978 length,
979 elements);
980 return MarkAsCall(DefineFixed(result, v0), instr, CAN_DEOPTIMIZE_EAGERLY);
981}
982
983
984LInstruction* LChunkBuilder::DoPushArguments(HPushArguments* instr) {
985 int argc = instr->OperandCount();
986 for (int i = 0; i < argc; ++i) {
987 LOperand* argument = Use(instr->argument(i));
988 AddInstruction(new(zone()) LPushArgument(argument), instr);
989 }
990 return NULL;
991}
992
993
994LInstruction* LChunkBuilder::DoStoreCodeEntry(
995 HStoreCodeEntry* store_code_entry) {
996 LOperand* function = UseRegister(store_code_entry->function());
997 LOperand* code_object = UseTempRegister(store_code_entry->code_object());
998 return new(zone()) LStoreCodeEntry(function, code_object);
999}
1000
1001
1002LInstruction* LChunkBuilder::DoInnerAllocatedObject(
1003 HInnerAllocatedObject* instr) {
1004 LOperand* base_object = UseRegisterAtStart(instr->base_object());
1005 LOperand* offset = UseRegisterOrConstantAtStart(instr->offset());
1006 return DefineAsRegister(
1007 new(zone()) LInnerAllocatedObject(base_object, offset));
1008}
1009
1010
1011LInstruction* LChunkBuilder::DoThisFunction(HThisFunction* instr) {
1012 return instr->HasNoUses()
1013 ? NULL
1014 : DefineAsRegister(new(zone()) LThisFunction);
1015}
1016
1017
1018LInstruction* LChunkBuilder::DoContext(HContext* instr) {
1019 if (instr->HasNoUses()) return NULL;
1020
1021 if (info()->IsStub()) {
1022 return DefineFixed(new(zone()) LContext, cp);
1023 }
1024
1025 return DefineAsRegister(new(zone()) LContext);
1026}
1027
1028
1029LInstruction* LChunkBuilder::DoDeclareGlobals(HDeclareGlobals* instr) {
1030 LOperand* context = UseFixed(instr->context(), cp);
1031 return MarkAsCall(new(zone()) LDeclareGlobals(context), instr);
1032}
1033
1034
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001035LInstruction* LChunkBuilder::DoCallWithDescriptor(
1036 HCallWithDescriptor* instr) {
1037 CallInterfaceDescriptor descriptor = instr->descriptor();
1038
1039 LOperand* target = UseRegisterOrConstantAtStart(instr->target());
1040 ZoneList<LOperand*> ops(instr->OperandCount(), zone());
1041 // Target
1042 ops.Add(target, zone());
1043 // Context
1044 LOperand* op = UseFixed(instr->OperandAt(1), cp);
1045 ops.Add(op, zone());
1046 // Other register parameters
1047 for (int i = LCallWithDescriptor::kImplicitRegisterParameterCount;
1048 i < instr->OperandCount(); i++) {
1049 op =
1050 UseFixed(instr->OperandAt(i),
1051 descriptor.GetRegisterParameter(
1052 i - LCallWithDescriptor::kImplicitRegisterParameterCount));
1053 ops.Add(op, zone());
1054 }
1055
1056 LCallWithDescriptor* result = new(zone()) LCallWithDescriptor(
1057 descriptor, ops, zone());
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);
1062}
1063
1064
1065LInstruction* LChunkBuilder::DoInvokeFunction(HInvokeFunction* instr) {
1066 LOperand* context = UseFixed(instr->context(), cp);
1067 LOperand* function = UseFixed(instr->function(), a1);
1068 LInvokeFunction* result = new(zone()) LInvokeFunction(context, function);
Ben Murdochda12d292016-06-02 14:46:10 +01001069 if (instr->syntactic_tail_call_mode() == TailCallMode::kAllow) {
1070 result->MarkAsSyntacticTailCall();
1071 }
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001072 return MarkAsCall(DefineFixed(result, v0), instr, CANNOT_DEOPTIMIZE_EAGERLY);
1073}
1074
1075
1076LInstruction* LChunkBuilder::DoUnaryMathOperation(HUnaryMathOperation* instr) {
1077 switch (instr->op()) {
1078 case kMathFloor:
1079 return DoMathFloor(instr);
1080 case kMathRound:
1081 return DoMathRound(instr);
1082 case kMathFround:
1083 return DoMathFround(instr);
1084 case kMathAbs:
1085 return DoMathAbs(instr);
1086 case kMathLog:
1087 return DoMathLog(instr);
1088 case kMathExp:
1089 return DoMathExp(instr);
1090 case kMathSqrt:
1091 return DoMathSqrt(instr);
1092 case kMathPowHalf:
1093 return DoMathPowHalf(instr);
1094 case kMathClz32:
1095 return DoMathClz32(instr);
1096 default:
1097 UNREACHABLE();
1098 return NULL;
1099 }
1100}
1101
1102
1103LInstruction* LChunkBuilder::DoMathLog(HUnaryMathOperation* instr) {
1104 DCHECK(instr->representation().IsDouble());
1105 DCHECK(instr->value()->representation().IsDouble());
1106 LOperand* input = UseFixedDouble(instr->value(), f4);
1107 return MarkAsCall(DefineFixedDouble(new(zone()) LMathLog(input), f4), instr);
1108}
1109
1110
1111LInstruction* LChunkBuilder::DoMathClz32(HUnaryMathOperation* instr) {
1112 LOperand* input = UseRegisterAtStart(instr->value());
1113 LMathClz32* result = new(zone()) LMathClz32(input);
1114 return DefineAsRegister(result);
1115}
1116
1117
1118LInstruction* LChunkBuilder::DoMathExp(HUnaryMathOperation* instr) {
1119 DCHECK(instr->representation().IsDouble());
1120 DCHECK(instr->value()->representation().IsDouble());
1121 LOperand* input = UseRegister(instr->value());
1122 LOperand* temp1 = TempRegister();
1123 LOperand* temp2 = TempRegister();
1124 LOperand* double_temp = TempDoubleRegister();
1125 LMathExp* result = new(zone()) LMathExp(input, double_temp, temp1, temp2);
1126 return DefineAsRegister(result);
1127}
1128
1129
1130LInstruction* LChunkBuilder::DoMathPowHalf(HUnaryMathOperation* instr) {
1131 // Input cannot be the same as the result, see LCodeGen::DoMathPowHalf.
1132 LOperand* input = UseFixedDouble(instr->value(), f8);
1133 LOperand* temp = TempDoubleRegister();
1134 LMathPowHalf* result = new(zone()) LMathPowHalf(input, temp);
1135 return DefineFixedDouble(result, f4);
1136}
1137
1138
1139LInstruction* LChunkBuilder::DoMathFround(HUnaryMathOperation* instr) {
1140 LOperand* input = UseRegister(instr->value());
1141 LMathFround* result = new (zone()) LMathFround(input);
1142 return DefineAsRegister(result);
1143}
1144
1145
1146LInstruction* LChunkBuilder::DoMathAbs(HUnaryMathOperation* instr) {
1147 Representation r = instr->value()->representation();
1148 LOperand* context = (r.IsDouble() || r.IsSmiOrInteger32())
1149 ? NULL
1150 : UseFixed(instr->context(), cp);
1151 LOperand* input = UseRegister(instr->value());
1152 LInstruction* result =
1153 DefineAsRegister(new(zone()) LMathAbs(context, input));
1154 if (!r.IsDouble() && !r.IsSmiOrInteger32()) result = AssignPointerMap(result);
1155 if (!r.IsDouble()) result = AssignEnvironment(result);
1156 return result;
1157}
1158
1159
1160LInstruction* LChunkBuilder::DoMathFloor(HUnaryMathOperation* instr) {
1161 LOperand* input = UseRegister(instr->value());
1162 LOperand* temp = TempRegister();
1163 LMathFloor* result = new(zone()) LMathFloor(input, temp);
1164 return AssignEnvironment(AssignPointerMap(DefineAsRegister(result)));
1165}
1166
1167
1168LInstruction* LChunkBuilder::DoMathSqrt(HUnaryMathOperation* instr) {
1169 LOperand* input = UseRegister(instr->value());
1170 LMathSqrt* result = new(zone()) LMathSqrt(input);
1171 return DefineAsRegister(result);
1172}
1173
1174
1175LInstruction* LChunkBuilder::DoMathRound(HUnaryMathOperation* instr) {
1176 LOperand* input = UseRegister(instr->value());
1177 LOperand* temp = TempDoubleRegister();
1178 LMathRound* result = new(zone()) LMathRound(input, temp);
1179 return AssignEnvironment(DefineAsRegister(result));
1180}
1181
1182
1183LInstruction* LChunkBuilder::DoCallNewArray(HCallNewArray* instr) {
1184 LOperand* context = UseFixed(instr->context(), cp);
1185 LOperand* constructor = UseFixed(instr->constructor(), a1);
1186 LCallNewArray* result = new(zone()) LCallNewArray(context, constructor);
1187 return MarkAsCall(DefineFixed(result, v0), instr);
1188}
1189
1190
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001191LInstruction* LChunkBuilder::DoCallRuntime(HCallRuntime* instr) {
1192 LOperand* context = UseFixed(instr->context(), cp);
1193 return MarkAsCall(DefineFixed(new(zone()) LCallRuntime(context), v0), instr);
1194}
1195
1196
1197LInstruction* LChunkBuilder::DoRor(HRor* instr) {
1198 return DoShift(Token::ROR, instr);
1199}
1200
1201
1202LInstruction* LChunkBuilder::DoShr(HShr* instr) {
1203 return DoShift(Token::SHR, instr);
1204}
1205
1206
1207LInstruction* LChunkBuilder::DoSar(HSar* instr) {
1208 return DoShift(Token::SAR, instr);
1209}
1210
1211
1212LInstruction* LChunkBuilder::DoShl(HShl* instr) {
1213 return DoShift(Token::SHL, instr);
1214}
1215
1216
1217LInstruction* LChunkBuilder::DoBitwise(HBitwise* instr) {
1218 if (instr->representation().IsSmiOrInteger32()) {
1219 DCHECK(instr->left()->representation().Equals(instr->representation()));
1220 DCHECK(instr->right()->representation().Equals(instr->representation()));
1221 DCHECK(instr->CheckFlag(HValue::kTruncatingToInt32));
1222
1223 LOperand* left = UseRegisterAtStart(instr->BetterLeftOperand());
1224 LOperand* right = UseOrConstantAtStart(instr->BetterRightOperand());
1225 return DefineAsRegister(new(zone()) LBitI(left, right));
1226 } else {
1227 return DoArithmeticT(instr->op(), instr);
1228 }
1229}
1230
1231
1232LInstruction* LChunkBuilder::DoDivByPowerOf2I(HDiv* instr) {
1233 DCHECK(instr->representation().IsSmiOrInteger32());
1234 DCHECK(instr->left()->representation().Equals(instr->representation()));
1235 DCHECK(instr->right()->representation().Equals(instr->representation()));
1236 LOperand* dividend = UseRegister(instr->left());
1237 int32_t divisor = instr->right()->GetInteger32Constant();
1238 LInstruction* result = DefineAsRegister(new(zone()) LDivByPowerOf2I(
1239 dividend, divisor));
1240 if ((instr->CheckFlag(HValue::kBailoutOnMinusZero) && divisor < 0) ||
1241 (instr->CheckFlag(HValue::kCanOverflow) && divisor == -1) ||
1242 (!instr->CheckFlag(HInstruction::kAllUsesTruncatingToInt32) &&
1243 divisor != 1 && divisor != -1)) {
1244 result = AssignEnvironment(result);
1245 }
1246 return result;
1247}
1248
1249
1250LInstruction* LChunkBuilder::DoDivByConstI(HDiv* instr) {
1251 DCHECK(instr->representation().IsInteger32());
1252 DCHECK(instr->left()->representation().Equals(instr->representation()));
1253 DCHECK(instr->right()->representation().Equals(instr->representation()));
1254 LOperand* dividend = UseRegister(instr->left());
1255 int32_t divisor = instr->right()->GetInteger32Constant();
1256 LInstruction* result = DefineAsRegister(new(zone()) LDivByConstI(
1257 dividend, divisor));
1258 if (divisor == 0 ||
1259 (instr->CheckFlag(HValue::kBailoutOnMinusZero) && divisor < 0) ||
1260 !instr->CheckFlag(HInstruction::kAllUsesTruncatingToInt32)) {
1261 result = AssignEnvironment(result);
1262 }
1263 return result;
1264}
1265
1266
1267LInstruction* LChunkBuilder::DoDivI(HDiv* instr) {
1268 DCHECK(instr->representation().IsSmiOrInteger32());
1269 DCHECK(instr->left()->representation().Equals(instr->representation()));
1270 DCHECK(instr->right()->representation().Equals(instr->representation()));
1271 LOperand* dividend = UseRegister(instr->left());
1272 LOperand* divisor = UseRegister(instr->right());
1273 LOperand* temp = TempRegister();
1274 LInstruction* result =
1275 DefineAsRegister(new(zone()) LDivI(dividend, divisor, temp));
1276 if (instr->CheckFlag(HValue::kCanBeDivByZero) ||
1277 instr->CheckFlag(HValue::kBailoutOnMinusZero) ||
1278 (instr->CheckFlag(HValue::kCanOverflow) &&
1279 !instr->CheckFlag(HValue::kAllUsesTruncatingToInt32)) ||
1280 (!instr->IsMathFloorOfDiv() &&
1281 !instr->CheckFlag(HValue::kAllUsesTruncatingToInt32))) {
1282 result = AssignEnvironment(result);
1283 }
1284 return result;
1285}
1286
1287
1288LInstruction* LChunkBuilder::DoDiv(HDiv* instr) {
1289 if (instr->representation().IsSmiOrInteger32()) {
1290 if (instr->RightIsPowerOf2()) {
1291 return DoDivByPowerOf2I(instr);
1292 } else if (instr->right()->IsConstant()) {
1293 return DoDivByConstI(instr);
1294 } else {
1295 return DoDivI(instr);
1296 }
1297 } else if (instr->representation().IsDouble()) {
1298 return DoArithmeticD(Token::DIV, instr);
1299 } else {
1300 return DoArithmeticT(Token::DIV, instr);
1301 }
1302}
1303
1304
1305LInstruction* LChunkBuilder::DoFlooringDivByPowerOf2I(HMathFloorOfDiv* instr) {
1306 LOperand* dividend = UseRegisterAtStart(instr->left());
1307 int32_t divisor = instr->right()->GetInteger32Constant();
1308 LInstruction* result = DefineAsRegister(new(zone()) LFlooringDivByPowerOf2I(
1309 dividend, divisor));
1310 if ((instr->CheckFlag(HValue::kBailoutOnMinusZero) && divisor < 0) ||
1311 (instr->CheckFlag(HValue::kLeftCanBeMinInt) && divisor == -1)) {
1312 result = AssignEnvironment(result);
1313 }
1314 return result;
1315}
1316
1317
1318LInstruction* LChunkBuilder::DoFlooringDivByConstI(HMathFloorOfDiv* instr) {
1319 DCHECK(instr->representation().IsInteger32());
1320 DCHECK(instr->left()->representation().Equals(instr->representation()));
1321 DCHECK(instr->right()->representation().Equals(instr->representation()));
1322 LOperand* dividend = UseRegister(instr->left());
1323 int32_t divisor = instr->right()->GetInteger32Constant();
1324 LOperand* temp =
1325 ((divisor > 0 && !instr->CheckFlag(HValue::kLeftCanBeNegative)) ||
1326 (divisor < 0 && !instr->CheckFlag(HValue::kLeftCanBePositive))) ?
1327 NULL : TempRegister();
1328 LInstruction* result = DefineAsRegister(
1329 new(zone()) LFlooringDivByConstI(dividend, divisor, temp));
1330 if (divisor == 0 ||
1331 (instr->CheckFlag(HValue::kBailoutOnMinusZero) && divisor < 0)) {
1332 result = AssignEnvironment(result);
1333 }
1334 return result;
1335}
1336
1337
1338LInstruction* LChunkBuilder::DoFlooringDivI(HMathFloorOfDiv* instr) {
1339 DCHECK(instr->representation().IsSmiOrInteger32());
1340 DCHECK(instr->left()->representation().Equals(instr->representation()));
1341 DCHECK(instr->right()->representation().Equals(instr->representation()));
1342 LOperand* dividend = UseRegister(instr->left());
1343 LOperand* divisor = UseRegister(instr->right());
1344 LInstruction* result =
1345 DefineAsRegister(new (zone()) LFlooringDivI(dividend, divisor));
1346 if (instr->CheckFlag(HValue::kCanBeDivByZero) ||
1347 instr->CheckFlag(HValue::kBailoutOnMinusZero) ||
1348 (instr->CheckFlag(HValue::kCanOverflow))) {
1349 result = AssignEnvironment(result);
1350 }
1351 return result;
1352}
1353
1354
1355LInstruction* LChunkBuilder::DoMathFloorOfDiv(HMathFloorOfDiv* instr) {
1356 if (instr->RightIsPowerOf2()) {
1357 return DoFlooringDivByPowerOf2I(instr);
1358 } else if (instr->right()->IsConstant()) {
1359 return DoFlooringDivByConstI(instr);
1360 } else {
1361 return DoFlooringDivI(instr);
1362 }
1363}
1364
1365
1366LInstruction* LChunkBuilder::DoModByPowerOf2I(HMod* instr) {
1367 DCHECK(instr->representation().IsSmiOrInteger32());
1368 DCHECK(instr->left()->representation().Equals(instr->representation()));
1369 DCHECK(instr->right()->representation().Equals(instr->representation()));
1370 LOperand* dividend = UseRegisterAtStart(instr->left());
1371 int32_t divisor = instr->right()->GetInteger32Constant();
1372 LInstruction* result = DefineSameAsFirst(new(zone()) LModByPowerOf2I(
1373 dividend, divisor));
1374 if (instr->CheckFlag(HValue::kLeftCanBeNegative) &&
1375 instr->CheckFlag(HValue::kBailoutOnMinusZero)) {
1376 result = AssignEnvironment(result);
1377 }
1378 return result;
1379}
1380
1381
1382LInstruction* LChunkBuilder::DoModByConstI(HMod* instr) {
1383 DCHECK(instr->representation().IsSmiOrInteger32());
1384 DCHECK(instr->left()->representation().Equals(instr->representation()));
1385 DCHECK(instr->right()->representation().Equals(instr->representation()));
1386 LOperand* dividend = UseRegister(instr->left());
1387 int32_t divisor = instr->right()->GetInteger32Constant();
1388 LInstruction* result = DefineAsRegister(new(zone()) LModByConstI(
1389 dividend, divisor));
1390 if (divisor == 0 || instr->CheckFlag(HValue::kBailoutOnMinusZero)) {
1391 result = AssignEnvironment(result);
1392 }
1393 return result;
1394}
1395
1396
1397LInstruction* LChunkBuilder::DoModI(HMod* instr) {
1398 DCHECK(instr->representation().IsSmiOrInteger32());
1399 DCHECK(instr->left()->representation().Equals(instr->representation()));
1400 DCHECK(instr->right()->representation().Equals(instr->representation()));
1401 LOperand* dividend = UseRegister(instr->left());
1402 LOperand* divisor = UseRegister(instr->right());
1403 LInstruction* result = DefineAsRegister(new(zone()) LModI(
1404 dividend, divisor));
1405 if (instr->CheckFlag(HValue::kCanBeDivByZero) ||
1406 instr->CheckFlag(HValue::kBailoutOnMinusZero)) {
1407 result = AssignEnvironment(result);
1408 }
1409 return result;
1410}
1411
1412
1413LInstruction* LChunkBuilder::DoMod(HMod* instr) {
1414 if (instr->representation().IsSmiOrInteger32()) {
1415 return instr->RightIsPowerOf2() ? DoModByPowerOf2I(instr) : DoModI(instr);
1416 } else if (instr->representation().IsDouble()) {
1417 return DoArithmeticD(Token::MOD, instr);
1418 } else {
1419 return DoArithmeticT(Token::MOD, instr);
1420 }
1421}
1422
1423
1424LInstruction* LChunkBuilder::DoMul(HMul* instr) {
1425 if (instr->representation().IsSmiOrInteger32()) {
1426 DCHECK(instr->left()->representation().Equals(instr->representation()));
1427 DCHECK(instr->right()->representation().Equals(instr->representation()));
1428 HValue* left = instr->BetterLeftOperand();
1429 HValue* right = instr->BetterRightOperand();
1430 LOperand* left_op;
1431 LOperand* right_op;
1432 bool can_overflow = instr->CheckFlag(HValue::kCanOverflow);
1433 bool bailout_on_minus_zero = instr->CheckFlag(HValue::kBailoutOnMinusZero);
1434
1435 int32_t constant_value = 0;
1436 if (right->IsConstant()) {
1437 HConstant* constant = HConstant::cast(right);
1438 constant_value = constant->Integer32Value();
1439 // Constants -1, 0 and 1 can be optimized if the result can overflow.
1440 // For other constants, it can be optimized only without overflow.
1441 if (!can_overflow || ((constant_value >= -1) && (constant_value <= 1))) {
1442 left_op = UseRegisterAtStart(left);
1443 right_op = UseConstant(right);
1444 } else {
1445 if (bailout_on_minus_zero) {
1446 left_op = UseRegister(left);
1447 } else {
1448 left_op = UseRegisterAtStart(left);
1449 }
1450 right_op = UseRegister(right);
1451 }
1452 } else {
1453 if (bailout_on_minus_zero) {
1454 left_op = UseRegister(left);
1455 } else {
1456 left_op = UseRegisterAtStart(left);
1457 }
1458 right_op = UseRegister(right);
1459 }
1460 LMulI* mul = new(zone()) LMulI(left_op, right_op);
1461 if (right_op->IsConstantOperand()
1462 ? ((can_overflow && constant_value == -1) ||
1463 (bailout_on_minus_zero && constant_value <= 0))
1464 : (can_overflow || bailout_on_minus_zero)) {
1465 AssignEnvironment(mul);
1466 }
1467 return DefineAsRegister(mul);
1468
1469 } else if (instr->representation().IsDouble()) {
1470 if (IsMipsArchVariant(kMips32r2)) {
1471 if (instr->HasOneUse() && instr->uses().value()->IsAdd()) {
1472 HAdd* add = HAdd::cast(instr->uses().value());
1473 if (instr == add->left()) {
1474 // This mul is the lhs of an add. The add and mul will be folded
1475 // into a multiply-add.
1476 return NULL;
1477 }
1478 if (instr == add->right() && !add->left()->IsMul()) {
1479 // This mul is the rhs of an add, where the lhs is not another mul.
1480 // The add and mul will be folded into a multiply-add.
1481 return NULL;
1482 }
1483 }
1484 }
1485 return DoArithmeticD(Token::MUL, instr);
1486 } else {
1487 return DoArithmeticT(Token::MUL, instr);
1488 }
1489}
1490
1491
1492LInstruction* LChunkBuilder::DoSub(HSub* instr) {
1493 if (instr->representation().IsSmiOrInteger32()) {
1494 DCHECK(instr->left()->representation().Equals(instr->representation()));
1495 DCHECK(instr->right()->representation().Equals(instr->representation()));
1496 LOperand* left = UseRegisterAtStart(instr->left());
1497 LOperand* right = UseOrConstantAtStart(instr->right());
1498 LSubI* sub = new(zone()) LSubI(left, right);
1499 LInstruction* result = DefineAsRegister(sub);
1500 if (instr->CheckFlag(HValue::kCanOverflow)) {
1501 result = AssignEnvironment(result);
1502 }
1503 return result;
1504 } else if (instr->representation().IsDouble()) {
1505 return DoArithmeticD(Token::SUB, instr);
1506 } else {
1507 return DoArithmeticT(Token::SUB, instr);
1508 }
1509}
1510
1511
1512LInstruction* LChunkBuilder::DoMultiplyAdd(HMul* mul, HValue* addend) {
1513 LOperand* multiplier_op = UseRegisterAtStart(mul->left());
1514 LOperand* multiplicand_op = UseRegisterAtStart(mul->right());
1515 LOperand* addend_op = UseRegisterAtStart(addend);
1516 return DefineSameAsFirst(new(zone()) LMultiplyAddD(addend_op, multiplier_op,
1517 multiplicand_op));
1518}
1519
1520
1521LInstruction* LChunkBuilder::DoAdd(HAdd* instr) {
1522 if (instr->representation().IsSmiOrInteger32()) {
1523 DCHECK(instr->left()->representation().Equals(instr->representation()));
1524 DCHECK(instr->right()->representation().Equals(instr->representation()));
1525 LOperand* left = UseRegisterAtStart(instr->BetterLeftOperand());
1526 LOperand* right = UseOrConstantAtStart(instr->BetterRightOperand());
1527 LAddI* add = new(zone()) LAddI(left, right);
1528 LInstruction* result = DefineAsRegister(add);
1529 if (instr->CheckFlag(HValue::kCanOverflow)) {
1530 result = AssignEnvironment(result);
1531 }
1532 return result;
1533 } else if (instr->representation().IsExternal()) {
1534 DCHECK(instr->IsConsistentExternalRepresentation());
1535 DCHECK(!instr->CheckFlag(HValue::kCanOverflow));
1536 LOperand* left = UseRegisterAtStart(instr->left());
1537 LOperand* right = UseOrConstantAtStart(instr->right());
1538 LAddI* add = new(zone()) LAddI(left, right);
1539 LInstruction* result = DefineAsRegister(add);
1540 return result;
1541 } else if (instr->representation().IsDouble()) {
1542 if (IsMipsArchVariant(kMips32r2)) {
1543 if (instr->left()->IsMul())
1544 return DoMultiplyAdd(HMul::cast(instr->left()), instr->right());
1545
1546 if (instr->right()->IsMul()) {
1547 DCHECK(!instr->left()->IsMul());
1548 return DoMultiplyAdd(HMul::cast(instr->right()), instr->left());
1549 }
1550 }
1551 return DoArithmeticD(Token::ADD, instr);
1552 } else {
1553 return DoArithmeticT(Token::ADD, instr);
1554 }
1555}
1556
1557
1558LInstruction* LChunkBuilder::DoMathMinMax(HMathMinMax* instr) {
1559 LOperand* left = NULL;
1560 LOperand* right = NULL;
1561 if (instr->representation().IsSmiOrInteger32()) {
1562 DCHECK(instr->left()->representation().Equals(instr->representation()));
1563 DCHECK(instr->right()->representation().Equals(instr->representation()));
1564 left = UseRegisterAtStart(instr->BetterLeftOperand());
1565 right = UseOrConstantAtStart(instr->BetterRightOperand());
1566 } else {
1567 DCHECK(instr->representation().IsDouble());
1568 DCHECK(instr->left()->representation().IsDouble());
1569 DCHECK(instr->right()->representation().IsDouble());
1570 left = UseRegisterAtStart(instr->left());
1571 right = UseRegisterAtStart(instr->right());
1572 }
1573 return DefineAsRegister(new(zone()) LMathMinMax(left, right));
1574}
1575
1576
1577LInstruction* LChunkBuilder::DoPower(HPower* instr) {
1578 DCHECK(instr->representation().IsDouble());
1579 // We call a C function for double power. It can't trigger a GC.
1580 // We need to use fixed result register for the call.
1581 Representation exponent_type = instr->right()->representation();
1582 DCHECK(instr->left()->representation().IsDouble());
1583 LOperand* left = UseFixedDouble(instr->left(), f2);
1584 LOperand* right =
1585 exponent_type.IsDouble()
1586 ? UseFixedDouble(instr->right(), f4)
1587 : UseFixed(instr->right(), MathPowTaggedDescriptor::exponent());
1588 LPower* result = new(zone()) LPower(left, right);
1589 return MarkAsCall(DefineFixedDouble(result, f0),
1590 instr,
1591 CAN_DEOPTIMIZE_EAGERLY);
1592}
1593
1594
1595LInstruction* LChunkBuilder::DoCompareGeneric(HCompareGeneric* instr) {
1596 DCHECK(instr->left()->representation().IsTagged());
1597 DCHECK(instr->right()->representation().IsTagged());
1598 LOperand* context = UseFixed(instr->context(), cp);
1599 LOperand* left = UseFixed(instr->left(), a1);
1600 LOperand* right = UseFixed(instr->right(), a0);
1601 LCmpT* result = new(zone()) LCmpT(context, left, right);
1602 return MarkAsCall(DefineFixed(result, v0), instr);
1603}
1604
1605
1606LInstruction* LChunkBuilder::DoCompareNumericAndBranch(
1607 HCompareNumericAndBranch* instr) {
1608 Representation r = instr->representation();
1609 if (r.IsSmiOrInteger32()) {
1610 DCHECK(instr->left()->representation().Equals(r));
1611 DCHECK(instr->right()->representation().Equals(r));
1612 LOperand* left = UseRegisterOrConstantAtStart(instr->left());
1613 LOperand* right = UseRegisterOrConstantAtStart(instr->right());
1614 return new(zone()) LCompareNumericAndBranch(left, right);
1615 } else {
1616 DCHECK(r.IsDouble());
1617 DCHECK(instr->left()->representation().IsDouble());
1618 DCHECK(instr->right()->representation().IsDouble());
1619 LOperand* left = UseRegisterAtStart(instr->left());
1620 LOperand* right = UseRegisterAtStart(instr->right());
1621 return new(zone()) LCompareNumericAndBranch(left, right);
1622 }
1623}
1624
1625
1626LInstruction* LChunkBuilder::DoCompareObjectEqAndBranch(
1627 HCompareObjectEqAndBranch* instr) {
1628 LOperand* left = UseRegisterAtStart(instr->left());
1629 LOperand* right = UseRegisterAtStart(instr->right());
1630 return new(zone()) LCmpObjectEqAndBranch(left, right);
1631}
1632
1633
1634LInstruction* LChunkBuilder::DoCompareHoleAndBranch(
1635 HCompareHoleAndBranch* instr) {
1636 LOperand* value = UseRegisterAtStart(instr->value());
1637 return new(zone()) LCmpHoleAndBranch(value);
1638}
1639
1640
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001641LInstruction* LChunkBuilder::DoIsStringAndBranch(HIsStringAndBranch* instr) {
1642 DCHECK(instr->value()->representation().IsTagged());
1643 LOperand* temp = TempRegister();
1644 return new(zone()) LIsStringAndBranch(UseRegisterAtStart(instr->value()),
1645 temp);
1646}
1647
1648
1649LInstruction* LChunkBuilder::DoIsSmiAndBranch(HIsSmiAndBranch* instr) {
1650 DCHECK(instr->value()->representation().IsTagged());
1651 return new(zone()) LIsSmiAndBranch(Use(instr->value()));
1652}
1653
1654
1655LInstruction* LChunkBuilder::DoIsUndetectableAndBranch(
1656 HIsUndetectableAndBranch* instr) {
1657 DCHECK(instr->value()->representation().IsTagged());
1658 return new(zone()) LIsUndetectableAndBranch(
1659 UseRegisterAtStart(instr->value()), TempRegister());
1660}
1661
1662
1663LInstruction* LChunkBuilder::DoStringCompareAndBranch(
1664 HStringCompareAndBranch* instr) {
1665 DCHECK(instr->left()->representation().IsTagged());
1666 DCHECK(instr->right()->representation().IsTagged());
1667 LOperand* context = UseFixed(instr->context(), cp);
1668 LOperand* left = UseFixed(instr->left(), a1);
1669 LOperand* right = UseFixed(instr->right(), a0);
1670 LStringCompareAndBranch* result =
1671 new(zone()) LStringCompareAndBranch(context, left, right);
1672 return MarkAsCall(result, instr);
1673}
1674
1675
1676LInstruction* LChunkBuilder::DoHasInstanceTypeAndBranch(
1677 HHasInstanceTypeAndBranch* instr) {
1678 DCHECK(instr->value()->representation().IsTagged());
1679 LOperand* value = UseRegisterAtStart(instr->value());
1680 return new(zone()) LHasInstanceTypeAndBranch(value);
1681}
1682
1683
1684LInstruction* LChunkBuilder::DoGetCachedArrayIndex(
1685 HGetCachedArrayIndex* instr) {
1686 DCHECK(instr->value()->representation().IsTagged());
1687 LOperand* value = UseRegisterAtStart(instr->value());
1688
1689 return DefineAsRegister(new(zone()) LGetCachedArrayIndex(value));
1690}
1691
1692
1693LInstruction* LChunkBuilder::DoHasCachedArrayIndexAndBranch(
1694 HHasCachedArrayIndexAndBranch* instr) {
1695 DCHECK(instr->value()->representation().IsTagged());
1696 return new(zone()) LHasCachedArrayIndexAndBranch(
1697 UseRegisterAtStart(instr->value()));
1698}
1699
1700
1701LInstruction* LChunkBuilder::DoClassOfTestAndBranch(
1702 HClassOfTestAndBranch* instr) {
1703 DCHECK(instr->value()->representation().IsTagged());
1704 return new(zone()) LClassOfTestAndBranch(UseRegister(instr->value()),
1705 TempRegister());
1706}
1707
1708
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001709LInstruction* LChunkBuilder::DoSeqStringGetChar(HSeqStringGetChar* instr) {
1710 LOperand* string = UseRegisterAtStart(instr->string());
1711 LOperand* index = UseRegisterOrConstantAtStart(instr->index());
1712 return DefineAsRegister(new(zone()) LSeqStringGetChar(string, index));
1713}
1714
1715
1716LInstruction* LChunkBuilder::DoSeqStringSetChar(HSeqStringSetChar* instr) {
1717 LOperand* string = UseRegisterAtStart(instr->string());
1718 LOperand* index = FLAG_debug_code
1719 ? UseRegisterAtStart(instr->index())
1720 : UseRegisterOrConstantAtStart(instr->index());
1721 LOperand* value = UseRegisterAtStart(instr->value());
1722 LOperand* context = FLAG_debug_code ? UseFixed(instr->context(), cp) : NULL;
1723 return new(zone()) LSeqStringSetChar(context, string, index, value);
1724}
1725
1726
1727LInstruction* LChunkBuilder::DoBoundsCheck(HBoundsCheck* instr) {
1728 if (!FLAG_debug_code && instr->skip_check()) return NULL;
1729 LOperand* index = UseRegisterOrConstantAtStart(instr->index());
1730 LOperand* length = !index->IsConstantOperand()
1731 ? UseRegisterOrConstantAtStart(instr->length())
1732 : UseRegisterAtStart(instr->length());
1733 LInstruction* result = new(zone()) LBoundsCheck(index, length);
1734 if (!FLAG_debug_code || !instr->skip_check()) {
1735 result = AssignEnvironment(result);
1736 }
1737 return result;
1738}
1739
1740
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001741LInstruction* LChunkBuilder::DoAbnormalExit(HAbnormalExit* instr) {
1742 // The control instruction marking the end of a block that completed
1743 // abruptly (e.g., threw an exception). There is nothing specific to do.
1744 return NULL;
1745}
1746
1747
1748LInstruction* LChunkBuilder::DoUseConst(HUseConst* instr) {
1749 return NULL;
1750}
1751
1752
1753LInstruction* LChunkBuilder::DoForceRepresentation(HForceRepresentation* bad) {
1754 // All HForceRepresentation instructions should be eliminated in the
1755 // representation change phase of Hydrogen.
1756 UNREACHABLE();
1757 return NULL;
1758}
1759
1760
1761LInstruction* LChunkBuilder::DoChange(HChange* instr) {
1762 Representation from = instr->from();
1763 Representation to = instr->to();
1764 HValue* val = instr->value();
1765 if (from.IsSmi()) {
1766 if (to.IsTagged()) {
1767 LOperand* value = UseRegister(val);
1768 return DefineSameAsFirst(new(zone()) LDummyUse(value));
1769 }
1770 from = Representation::Tagged();
1771 }
1772 if (from.IsTagged()) {
1773 if (to.IsDouble()) {
1774 LOperand* value = UseRegister(val);
1775 LInstruction* result = DefineAsRegister(new(zone()) LNumberUntagD(value));
1776 if (!val->representation().IsSmi()) result = AssignEnvironment(result);
1777 return result;
1778 } else if (to.IsSmi()) {
1779 LOperand* value = UseRegister(val);
1780 if (val->type().IsSmi()) {
1781 return DefineSameAsFirst(new(zone()) LDummyUse(value));
1782 }
1783 return AssignEnvironment(DefineSameAsFirst(new(zone()) LCheckSmi(value)));
1784 } else {
1785 DCHECK(to.IsInteger32());
1786 if (val->type().IsSmi() || val->representation().IsSmi()) {
1787 LOperand* value = UseRegisterAtStart(val);
1788 return DefineAsRegister(new(zone()) LSmiUntag(value, false));
1789 } else {
1790 LOperand* value = UseRegister(val);
1791 LOperand* temp1 = TempRegister();
1792 LOperand* temp2 = TempDoubleRegister();
1793 LInstruction* result =
1794 DefineSameAsFirst(new(zone()) LTaggedToI(value, temp1, temp2));
1795 if (!val->representation().IsSmi()) result = AssignEnvironment(result);
1796 return result;
1797 }
1798 }
1799 } else if (from.IsDouble()) {
1800 if (to.IsTagged()) {
1801 info()->MarkAsDeferredCalling();
1802 LOperand* value = UseRegister(val);
1803 LOperand* temp1 = TempRegister();
1804 LOperand* temp2 = TempRegister();
1805 LUnallocated* result_temp = TempRegister();
1806 LNumberTagD* result = new(zone()) LNumberTagD(value, temp1, temp2);
1807 return AssignPointerMap(Define(result, result_temp));
1808 } else if (to.IsSmi()) {
1809 LOperand* value = UseRegister(val);
1810 return AssignEnvironment(
1811 DefineAsRegister(new(zone()) LDoubleToSmi(value)));
1812 } else {
1813 DCHECK(to.IsInteger32());
1814 LOperand* value = UseRegister(val);
1815 LInstruction* result = DefineAsRegister(new(zone()) LDoubleToI(value));
1816 if (!instr->CanTruncateToInt32()) result = AssignEnvironment(result);
1817 return result;
1818 }
1819 } else if (from.IsInteger32()) {
1820 info()->MarkAsDeferredCalling();
1821 if (to.IsTagged()) {
1822 if (!instr->CheckFlag(HValue::kCanOverflow)) {
1823 LOperand* value = UseRegisterAtStart(val);
1824 return DefineAsRegister(new(zone()) LSmiTag(value));
1825 } else if (val->CheckFlag(HInstruction::kUint32)) {
1826 LOperand* value = UseRegisterAtStart(val);
1827 LOperand* temp1 = TempRegister();
1828 LOperand* temp2 = TempRegister();
1829 LNumberTagU* result = new(zone()) LNumberTagU(value, temp1, temp2);
1830 return AssignPointerMap(DefineAsRegister(result));
1831 } else {
1832 LOperand* value = UseRegisterAtStart(val);
1833 LOperand* temp1 = TempRegister();
1834 LOperand* temp2 = TempRegister();
1835 LNumberTagI* result = new(zone()) LNumberTagI(value, temp1, temp2);
1836 return AssignPointerMap(DefineAsRegister(result));
1837 }
1838 } else if (to.IsSmi()) {
1839 LOperand* value = UseRegister(val);
1840 LInstruction* result = DefineAsRegister(new(zone()) LSmiTag(value));
1841 if (instr->CheckFlag(HValue::kCanOverflow)) {
1842 result = AssignEnvironment(result);
1843 }
1844 return result;
1845 } else {
1846 DCHECK(to.IsDouble());
1847 if (val->CheckFlag(HInstruction::kUint32)) {
1848 return DefineAsRegister(new(zone()) LUint32ToDouble(UseRegister(val)));
1849 } else {
1850 return DefineAsRegister(new(zone()) LInteger32ToDouble(Use(val)));
1851 }
1852 }
1853 }
1854 UNREACHABLE();
1855 return NULL;
1856}
1857
1858
1859LInstruction* LChunkBuilder::DoCheckHeapObject(HCheckHeapObject* instr) {
1860 LOperand* value = UseRegisterAtStart(instr->value());
1861 LInstruction* result = new(zone()) LCheckNonSmi(value);
1862 if (!instr->value()->type().IsHeapObject()) {
1863 result = AssignEnvironment(result);
1864 }
1865 return result;
1866}
1867
1868
1869LInstruction* LChunkBuilder::DoCheckSmi(HCheckSmi* instr) {
1870 LOperand* value = UseRegisterAtStart(instr->value());
1871 return AssignEnvironment(new(zone()) LCheckSmi(value));
1872}
1873
1874
1875LInstruction* LChunkBuilder::DoCheckArrayBufferNotNeutered(
1876 HCheckArrayBufferNotNeutered* instr) {
1877 LOperand* view = UseRegisterAtStart(instr->value());
1878 LCheckArrayBufferNotNeutered* result =
1879 new (zone()) LCheckArrayBufferNotNeutered(view);
1880 return AssignEnvironment(result);
1881}
1882
1883
1884LInstruction* LChunkBuilder::DoCheckInstanceType(HCheckInstanceType* instr) {
1885 LOperand* value = UseRegisterAtStart(instr->value());
1886 LInstruction* result = new(zone()) LCheckInstanceType(value);
1887 return AssignEnvironment(result);
1888}
1889
1890
1891LInstruction* LChunkBuilder::DoCheckValue(HCheckValue* instr) {
1892 LOperand* value = UseRegisterAtStart(instr->value());
1893 return AssignEnvironment(new(zone()) LCheckValue(value));
1894}
1895
1896
1897LInstruction* LChunkBuilder::DoCheckMaps(HCheckMaps* instr) {
1898 if (instr->IsStabilityCheck()) return new(zone()) LCheckMaps;
1899 LOperand* value = UseRegisterAtStart(instr->value());
1900 LInstruction* result = AssignEnvironment(new(zone()) LCheckMaps(value));
1901 if (instr->HasMigrationTarget()) {
1902 info()->MarkAsDeferredCalling();
1903 result = AssignPointerMap(result);
1904 }
1905 return result;
1906}
1907
1908
1909LInstruction* LChunkBuilder::DoClampToUint8(HClampToUint8* instr) {
1910 HValue* value = instr->value();
1911 Representation input_rep = value->representation();
1912 LOperand* reg = UseRegister(value);
1913 if (input_rep.IsDouble()) {
1914 // Revisit this decision, here and 8 lines below.
1915 return DefineAsRegister(new(zone()) LClampDToUint8(reg,
1916 TempDoubleRegister()));
1917 } else if (input_rep.IsInteger32()) {
1918 return DefineAsRegister(new(zone()) LClampIToUint8(reg));
1919 } else {
1920 DCHECK(input_rep.IsSmiOrTagged());
1921 LClampTToUint8* result =
1922 new(zone()) LClampTToUint8(reg, TempDoubleRegister());
1923 return AssignEnvironment(DefineAsRegister(result));
1924 }
1925}
1926
1927
1928LInstruction* LChunkBuilder::DoDoubleBits(HDoubleBits* instr) {
1929 HValue* value = instr->value();
1930 DCHECK(value->representation().IsDouble());
1931 return DefineAsRegister(new(zone()) LDoubleBits(UseRegister(value)));
1932}
1933
1934
1935LInstruction* LChunkBuilder::DoConstructDouble(HConstructDouble* instr) {
1936 LOperand* lo = UseRegister(instr->lo());
1937 LOperand* hi = UseRegister(instr->hi());
1938 return DefineAsRegister(new(zone()) LConstructDouble(hi, lo));
1939}
1940
1941
1942LInstruction* LChunkBuilder::DoReturn(HReturn* instr) {
1943 LOperand* context = info()->IsStub()
1944 ? UseFixed(instr->context(), cp)
1945 : NULL;
1946 LOperand* parameter_count = UseRegisterOrConstant(instr->parameter_count());
1947 return new(zone()) LReturn(UseFixed(instr->value(), v0), context,
1948 parameter_count);
1949}
1950
1951
1952LInstruction* LChunkBuilder::DoConstant(HConstant* instr) {
1953 Representation r = instr->representation();
1954 if (r.IsSmi()) {
1955 return DefineAsRegister(new(zone()) LConstantS);
1956 } else if (r.IsInteger32()) {
1957 return DefineAsRegister(new(zone()) LConstantI);
1958 } else if (r.IsDouble()) {
1959 return DefineAsRegister(new(zone()) LConstantD);
1960 } else if (r.IsExternal()) {
1961 return DefineAsRegister(new(zone()) LConstantE);
1962 } else if (r.IsTagged()) {
1963 return DefineAsRegister(new(zone()) LConstantT);
1964 } else {
1965 UNREACHABLE();
1966 return NULL;
1967 }
1968}
1969
1970
1971LInstruction* LChunkBuilder::DoLoadGlobalGeneric(HLoadGlobalGeneric* instr) {
1972 LOperand* context = UseFixed(instr->context(), cp);
1973 LOperand* global_object =
1974 UseFixed(instr->global_object(), LoadDescriptor::ReceiverRegister());
1975 LOperand* vector = NULL;
1976 if (instr->HasVectorAndSlot()) {
1977 vector = FixedTemp(LoadWithVectorDescriptor::VectorRegister());
1978 }
1979 LLoadGlobalGeneric* result =
1980 new(zone()) LLoadGlobalGeneric(context, global_object, vector);
1981 return MarkAsCall(DefineFixed(result, v0), instr);
1982}
1983
1984
1985LInstruction* LChunkBuilder::DoLoadContextSlot(HLoadContextSlot* instr) {
1986 LOperand* context = UseRegisterAtStart(instr->value());
1987 LInstruction* result =
1988 DefineAsRegister(new(zone()) LLoadContextSlot(context));
1989 if (instr->RequiresHoleCheck() && instr->DeoptimizesOnHole()) {
1990 result = AssignEnvironment(result);
1991 }
1992 return result;
1993}
1994
1995
1996LInstruction* LChunkBuilder::DoStoreContextSlot(HStoreContextSlot* instr) {
1997 LOperand* context;
1998 LOperand* value;
1999 if (instr->NeedsWriteBarrier()) {
2000 context = UseTempRegister(instr->context());
2001 value = UseTempRegister(instr->value());
2002 } else {
2003 context = UseRegister(instr->context());
2004 value = UseRegister(instr->value());
2005 }
2006 LInstruction* result = new(zone()) LStoreContextSlot(context, value);
2007 if (instr->RequiresHoleCheck() && instr->DeoptimizesOnHole()) {
2008 result = AssignEnvironment(result);
2009 }
2010 return result;
2011}
2012
2013
2014LInstruction* LChunkBuilder::DoLoadNamedField(HLoadNamedField* instr) {
2015 LOperand* obj = UseRegisterAtStart(instr->object());
2016 return DefineAsRegister(new(zone()) LLoadNamedField(obj));
2017}
2018
2019
2020LInstruction* LChunkBuilder::DoLoadNamedGeneric(HLoadNamedGeneric* instr) {
2021 LOperand* context = UseFixed(instr->context(), cp);
2022 LOperand* object =
2023 UseFixed(instr->object(), LoadDescriptor::ReceiverRegister());
2024 LOperand* vector = NULL;
2025 if (instr->HasVectorAndSlot()) {
2026 vector = FixedTemp(LoadWithVectorDescriptor::VectorRegister());
2027 }
2028
2029 LInstruction* result =
2030 DefineFixed(new(zone()) LLoadNamedGeneric(context, object, vector), v0);
2031 return MarkAsCall(result, instr);
2032}
2033
2034
2035LInstruction* LChunkBuilder::DoLoadFunctionPrototype(
2036 HLoadFunctionPrototype* instr) {
2037 return AssignEnvironment(DefineAsRegister(
2038 new(zone()) LLoadFunctionPrototype(UseRegister(instr->function()))));
2039}
2040
2041
2042LInstruction* LChunkBuilder::DoLoadRoot(HLoadRoot* instr) {
2043 return DefineAsRegister(new(zone()) LLoadRoot);
2044}
2045
2046
2047LInstruction* LChunkBuilder::DoLoadKeyed(HLoadKeyed* instr) {
2048 DCHECK(instr->key()->representation().IsSmiOrInteger32());
2049 ElementsKind elements_kind = instr->elements_kind();
2050 LOperand* key = UseRegisterOrConstantAtStart(instr->key());
2051 LInstruction* result = NULL;
2052
2053 if (!instr->is_fixed_typed_array()) {
2054 LOperand* obj = NULL;
2055 if (instr->representation().IsDouble()) {
2056 obj = UseRegister(instr->elements());
2057 } else {
2058 DCHECK(instr->representation().IsSmiOrTagged());
2059 obj = UseRegisterAtStart(instr->elements());
2060 }
2061 result = DefineAsRegister(new (zone()) LLoadKeyed(obj, key, nullptr));
2062 } else {
2063 DCHECK(
2064 (instr->representation().IsInteger32() &&
2065 !IsDoubleOrFloatElementsKind(elements_kind)) ||
2066 (instr->representation().IsDouble() &&
2067 IsDoubleOrFloatElementsKind(elements_kind)));
2068 LOperand* backing_store = UseRegister(instr->elements());
2069 LOperand* backing_store_owner = UseAny(instr->backing_store_owner());
2070 result = DefineAsRegister(
2071 new (zone()) LLoadKeyed(backing_store, key, backing_store_owner));
2072 }
2073
2074 bool needs_environment;
2075 if (instr->is_fixed_typed_array()) {
2076 // see LCodeGen::DoLoadKeyedExternalArray
2077 needs_environment = elements_kind == UINT32_ELEMENTS &&
2078 !instr->CheckFlag(HInstruction::kUint32);
2079 } else {
2080 // see LCodeGen::DoLoadKeyedFixedDoubleArray and
2081 // LCodeGen::DoLoadKeyedFixedArray
2082 needs_environment =
2083 instr->RequiresHoleCheck() ||
2084 (instr->hole_mode() == CONVERT_HOLE_TO_UNDEFINED && info()->IsStub());
2085 }
2086
2087 if (needs_environment) {
2088 result = AssignEnvironment(result);
2089 }
2090 return result;
2091}
2092
2093
2094LInstruction* LChunkBuilder::DoLoadKeyedGeneric(HLoadKeyedGeneric* instr) {
2095 LOperand* context = UseFixed(instr->context(), cp);
2096 LOperand* object =
2097 UseFixed(instr->object(), LoadDescriptor::ReceiverRegister());
2098 LOperand* key = UseFixed(instr->key(), LoadDescriptor::NameRegister());
2099 LOperand* vector = NULL;
2100 if (instr->HasVectorAndSlot()) {
2101 vector = FixedTemp(LoadWithVectorDescriptor::VectorRegister());
2102 }
2103
2104 LInstruction* result =
2105 DefineFixed(new(zone()) LLoadKeyedGeneric(context, object, key, vector),
2106 v0);
2107 return MarkAsCall(result, instr);
2108}
2109
2110
2111LInstruction* LChunkBuilder::DoStoreKeyed(HStoreKeyed* instr) {
2112 if (!instr->is_fixed_typed_array()) {
2113 DCHECK(instr->elements()->representation().IsTagged());
2114 bool needs_write_barrier = instr->NeedsWriteBarrier();
2115 LOperand* object = NULL;
2116 LOperand* val = NULL;
2117 LOperand* key = NULL;
2118
2119 if (instr->value()->representation().IsDouble()) {
2120 object = UseRegisterAtStart(instr->elements());
2121 key = UseRegisterOrConstantAtStart(instr->key());
2122 val = UseRegister(instr->value());
2123 } else {
2124 DCHECK(instr->value()->representation().IsSmiOrTagged());
2125 if (needs_write_barrier) {
2126 object = UseTempRegister(instr->elements());
2127 val = UseTempRegister(instr->value());
2128 key = UseTempRegister(instr->key());
2129 } else {
2130 object = UseRegisterAtStart(instr->elements());
2131 val = UseRegisterAtStart(instr->value());
2132 key = UseRegisterOrConstantAtStart(instr->key());
2133 }
2134 }
2135
2136 return new (zone()) LStoreKeyed(object, key, val, nullptr);
2137 }
2138
2139 DCHECK(
2140 (instr->value()->representation().IsInteger32() &&
2141 !IsDoubleOrFloatElementsKind(instr->elements_kind())) ||
2142 (instr->value()->representation().IsDouble() &&
2143 IsDoubleOrFloatElementsKind(instr->elements_kind())));
2144 DCHECK(instr->elements()->representation().IsExternal());
2145 LOperand* val = UseRegister(instr->value());
2146 LOperand* key = UseRegisterOrConstantAtStart(instr->key());
2147 LOperand* backing_store = UseRegister(instr->elements());
2148 LOperand* backing_store_owner = UseAny(instr->backing_store_owner());
2149 return new (zone()) LStoreKeyed(backing_store, key, val, backing_store_owner);
2150}
2151
2152
2153LInstruction* LChunkBuilder::DoStoreKeyedGeneric(HStoreKeyedGeneric* instr) {
2154 LOperand* context = UseFixed(instr->context(), cp);
2155 LOperand* obj =
2156 UseFixed(instr->object(), StoreDescriptor::ReceiverRegister());
2157 LOperand* key = UseFixed(instr->key(), StoreDescriptor::NameRegister());
2158 LOperand* val = UseFixed(instr->value(), StoreDescriptor::ValueRegister());
2159
2160 DCHECK(instr->object()->representation().IsTagged());
2161 DCHECK(instr->key()->representation().IsTagged());
2162 DCHECK(instr->value()->representation().IsTagged());
2163
2164 LOperand* slot = NULL;
2165 LOperand* vector = NULL;
2166 if (instr->HasVectorAndSlot()) {
2167 slot = FixedTemp(VectorStoreICDescriptor::SlotRegister());
2168 vector = FixedTemp(VectorStoreICDescriptor::VectorRegister());
2169 }
2170
2171 LStoreKeyedGeneric* result =
2172 new (zone()) LStoreKeyedGeneric(context, obj, key, val, slot, vector);
2173 return MarkAsCall(result, instr);
2174}
2175
2176
2177LInstruction* LChunkBuilder::DoTransitionElementsKind(
2178 HTransitionElementsKind* instr) {
2179 if (IsSimpleMapChangeTransition(instr->from_kind(), instr->to_kind())) {
2180 LOperand* object = UseRegister(instr->object());
2181 LOperand* new_map_reg = TempRegister();
2182 LTransitionElementsKind* result =
2183 new(zone()) LTransitionElementsKind(object, NULL, new_map_reg);
2184 return result;
2185 } else {
2186 LOperand* object = UseFixed(instr->object(), a0);
2187 LOperand* context = UseFixed(instr->context(), cp);
2188 LTransitionElementsKind* result =
2189 new(zone()) LTransitionElementsKind(object, context, NULL);
2190 return MarkAsCall(result, instr);
2191 }
2192}
2193
2194
2195LInstruction* LChunkBuilder::DoTrapAllocationMemento(
2196 HTrapAllocationMemento* instr) {
2197 LOperand* object = UseRegister(instr->object());
2198 LOperand* temp = TempRegister();
2199 LTrapAllocationMemento* result =
2200 new(zone()) LTrapAllocationMemento(object, temp);
2201 return AssignEnvironment(result);
2202}
2203
2204
2205LInstruction* LChunkBuilder::DoMaybeGrowElements(HMaybeGrowElements* instr) {
2206 info()->MarkAsDeferredCalling();
2207 LOperand* context = UseFixed(instr->context(), cp);
2208 LOperand* object = Use(instr->object());
2209 LOperand* elements = Use(instr->elements());
2210 LOperand* key = UseRegisterOrConstant(instr->key());
2211 LOperand* current_capacity = UseRegisterOrConstant(instr->current_capacity());
2212
2213 LMaybeGrowElements* result = new (zone())
2214 LMaybeGrowElements(context, object, elements, key, current_capacity);
2215 DefineFixed(result, v0);
2216 return AssignPointerMap(AssignEnvironment(result));
2217}
2218
2219
2220LInstruction* LChunkBuilder::DoStoreNamedField(HStoreNamedField* instr) {
2221 bool is_in_object = instr->access().IsInobject();
2222 bool needs_write_barrier = instr->NeedsWriteBarrier();
2223 bool needs_write_barrier_for_map = instr->has_transition() &&
2224 instr->NeedsWriteBarrierForMap();
2225
2226 LOperand* obj;
2227 if (needs_write_barrier) {
2228 obj = is_in_object
2229 ? UseRegister(instr->object())
2230 : UseTempRegister(instr->object());
2231 } else {
2232 obj = needs_write_barrier_for_map
2233 ? UseRegister(instr->object())
2234 : UseRegisterAtStart(instr->object());
2235 }
2236
2237 LOperand* val;
2238 if (needs_write_barrier) {
2239 val = UseTempRegister(instr->value());
2240 } else if (instr->field_representation().IsDouble()) {
2241 val = UseRegisterAtStart(instr->value());
2242 } else {
2243 val = UseRegister(instr->value());
2244 }
2245
2246 // We need a temporary register for write barrier of the map field.
2247 LOperand* temp = needs_write_barrier_for_map ? TempRegister() : NULL;
2248
2249 return new(zone()) LStoreNamedField(obj, val, temp);
2250}
2251
2252
2253LInstruction* LChunkBuilder::DoStoreNamedGeneric(HStoreNamedGeneric* instr) {
2254 LOperand* context = UseFixed(instr->context(), cp);
2255 LOperand* obj =
2256 UseFixed(instr->object(), StoreDescriptor::ReceiverRegister());
2257 LOperand* val = UseFixed(instr->value(), StoreDescriptor::ValueRegister());
2258 LOperand* slot = NULL;
2259 LOperand* vector = NULL;
2260 if (instr->HasVectorAndSlot()) {
2261 slot = FixedTemp(VectorStoreICDescriptor::SlotRegister());
2262 vector = FixedTemp(VectorStoreICDescriptor::VectorRegister());
2263 }
2264
2265 LStoreNamedGeneric* result =
2266 new (zone()) LStoreNamedGeneric(context, obj, val, slot, vector);
2267 return MarkAsCall(result, instr);
2268}
2269
2270
2271LInstruction* LChunkBuilder::DoStringAdd(HStringAdd* instr) {
2272 LOperand* context = UseFixed(instr->context(), cp);
2273 LOperand* left = UseFixed(instr->left(), a1);
2274 LOperand* right = UseFixed(instr->right(), a0);
2275 return MarkAsCall(
2276 DefineFixed(new(zone()) LStringAdd(context, left, right), v0),
2277 instr);
2278}
2279
2280
2281LInstruction* LChunkBuilder::DoStringCharCodeAt(HStringCharCodeAt* instr) {
2282 LOperand* string = UseTempRegister(instr->string());
2283 LOperand* index = UseTempRegister(instr->index());
2284 LOperand* context = UseAny(instr->context());
2285 LStringCharCodeAt* result =
2286 new(zone()) LStringCharCodeAt(context, string, index);
2287 return AssignPointerMap(DefineAsRegister(result));
2288}
2289
2290
2291LInstruction* LChunkBuilder::DoStringCharFromCode(HStringCharFromCode* instr) {
2292 LOperand* char_code = UseRegister(instr->value());
2293 LOperand* context = UseAny(instr->context());
2294 LStringCharFromCode* result =
2295 new(zone()) LStringCharFromCode(context, char_code);
2296 return AssignPointerMap(DefineAsRegister(result));
2297}
2298
2299
2300LInstruction* LChunkBuilder::DoAllocate(HAllocate* instr) {
2301 info()->MarkAsDeferredCalling();
2302 LOperand* context = UseAny(instr->context());
2303 LOperand* size = UseRegisterOrConstant(instr->size());
2304 LOperand* temp1 = TempRegister();
2305 LOperand* temp2 = TempRegister();
2306 LAllocate* result = new(zone()) LAllocate(context, size, temp1, temp2);
2307 return AssignPointerMap(DefineAsRegister(result));
2308}
2309
2310
2311LInstruction* LChunkBuilder::DoOsrEntry(HOsrEntry* instr) {
2312 DCHECK(argument_count_ == 0);
2313 allocator_->MarkAsOsrEntry();
2314 current_block_->last_environment()->set_ast_id(instr->ast_id());
2315 return AssignEnvironment(new(zone()) LOsrEntry);
2316}
2317
2318
2319LInstruction* LChunkBuilder::DoParameter(HParameter* instr) {
2320 LParameter* result = new(zone()) LParameter;
2321 if (instr->kind() == HParameter::STACK_PARAMETER) {
2322 int spill_index = chunk()->GetParameterStackSlot(instr->index());
2323 return DefineAsSpilled(result, spill_index);
2324 } else {
2325 DCHECK(info()->IsStub());
Ben Murdoch097c5b22016-05-18 11:27:45 +01002326 CallInterfaceDescriptor descriptor = graph()->descriptor();
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002327 int index = static_cast<int>(instr->index());
2328 Register reg = descriptor.GetRegisterParameter(index);
2329 return DefineFixed(result, reg);
2330 }
2331}
2332
2333
2334LInstruction* LChunkBuilder::DoUnknownOSRValue(HUnknownOSRValue* instr) {
2335 // Use an index that corresponds to the location in the unoptimized frame,
2336 // which the optimized frame will subsume.
2337 int env_index = instr->index();
2338 int spill_index = 0;
2339 if (instr->environment()->is_parameter_index(env_index)) {
2340 spill_index = chunk()->GetParameterStackSlot(env_index);
2341 } else {
2342 spill_index = env_index - instr->environment()->first_local_index();
2343 if (spill_index > LUnallocated::kMaxFixedSlotIndex) {
2344 Retry(kTooManySpillSlotsNeededForOSR);
2345 spill_index = 0;
2346 }
Ben Murdoch097c5b22016-05-18 11:27:45 +01002347 spill_index += StandardFrameConstants::kFixedSlotCount;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002348 }
2349 return DefineAsSpilled(new(zone()) LUnknownOSRValue, spill_index);
2350}
2351
2352
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002353LInstruction* LChunkBuilder::DoArgumentsObject(HArgumentsObject* instr) {
2354 // There are no real uses of the arguments object.
2355 // arguments.length and element access are supported directly on
2356 // stack arguments, and any real arguments object use causes a bailout.
2357 // So this value is never used.
2358 return NULL;
2359}
2360
2361
2362LInstruction* LChunkBuilder::DoCapturedObject(HCapturedObject* instr) {
2363 instr->ReplayEnvironment(current_block_->last_environment());
2364
2365 // There are no real uses of a captured object.
2366 return NULL;
2367}
2368
2369
2370LInstruction* LChunkBuilder::DoAccessArgumentsAt(HAccessArgumentsAt* instr) {
2371 info()->MarkAsRequiresFrame();
2372 LOperand* args = UseRegister(instr->arguments());
2373 LOperand* length = UseRegisterOrConstantAtStart(instr->length());
2374 LOperand* index = UseRegisterOrConstantAtStart(instr->index());
2375 return DefineAsRegister(new(zone()) LAccessArgumentsAt(args, length, index));
2376}
2377
2378
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002379LInstruction* LChunkBuilder::DoTypeof(HTypeof* instr) {
2380 LOperand* context = UseFixed(instr->context(), cp);
2381 LOperand* value = UseFixed(instr->value(), a3);
2382 LTypeof* result = new (zone()) LTypeof(context, value);
2383 return MarkAsCall(DefineFixed(result, v0), instr);
2384}
2385
2386
2387LInstruction* LChunkBuilder::DoTypeofIsAndBranch(HTypeofIsAndBranch* instr) {
2388 return new(zone()) LTypeofIsAndBranch(UseTempRegister(instr->value()));
2389}
2390
2391
2392LInstruction* LChunkBuilder::DoSimulate(HSimulate* instr) {
2393 instr->ReplayEnvironment(current_block_->last_environment());
2394 return NULL;
2395}
2396
2397
2398LInstruction* LChunkBuilder::DoStackCheck(HStackCheck* instr) {
2399 if (instr->is_function_entry()) {
2400 LOperand* context = UseFixed(instr->context(), cp);
2401 return MarkAsCall(new(zone()) LStackCheck(context), instr);
2402 } else {
2403 DCHECK(instr->is_backwards_branch());
2404 LOperand* context = UseAny(instr->context());
2405 return AssignEnvironment(
2406 AssignPointerMap(new(zone()) LStackCheck(context)));
2407 }
2408}
2409
2410
2411LInstruction* LChunkBuilder::DoEnterInlined(HEnterInlined* instr) {
2412 HEnvironment* outer = current_block_->last_environment();
2413 outer->set_ast_id(instr->ReturnId());
2414 HConstant* undefined = graph()->GetConstantUndefined();
Ben Murdochda12d292016-06-02 14:46:10 +01002415 HEnvironment* inner = outer->CopyForInlining(
2416 instr->closure(), instr->arguments_count(), instr->function(), undefined,
2417 instr->inlining_kind(), instr->syntactic_tail_call_mode());
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002418 // Only replay binding of arguments object if it wasn't removed from graph.
2419 if (instr->arguments_var() != NULL && instr->arguments_object()->IsLinked()) {
2420 inner->Bind(instr->arguments_var(), instr->arguments_object());
2421 }
2422 inner->BindContext(instr->closure_context());
2423 inner->set_entry(instr);
2424 current_block_->UpdateEnvironment(inner);
2425 chunk_->AddInlinedFunction(instr->shared());
2426 return NULL;
2427}
2428
2429
2430LInstruction* LChunkBuilder::DoLeaveInlined(HLeaveInlined* instr) {
2431 LInstruction* pop = NULL;
2432
2433 HEnvironment* env = current_block_->last_environment();
2434
2435 if (env->entry()->arguments_pushed()) {
2436 int argument_count = env->arguments_environment()->parameter_count();
2437 pop = new(zone()) LDrop(argument_count);
2438 DCHECK(instr->argument_delta() == -argument_count);
2439 }
2440
2441 HEnvironment* outer = current_block_->last_environment()->
2442 DiscardInlined(false);
2443 current_block_->UpdateEnvironment(outer);
2444
2445 return pop;
2446}
2447
2448
2449LInstruction* LChunkBuilder::DoForInPrepareMap(HForInPrepareMap* instr) {
2450 LOperand* context = UseFixed(instr->context(), cp);
2451 LOperand* object = UseFixed(instr->enumerable(), a0);
2452 LForInPrepareMap* result = new(zone()) LForInPrepareMap(context, object);
2453 return MarkAsCall(DefineFixed(result, v0), instr, CAN_DEOPTIMIZE_EAGERLY);
2454}
2455
2456
2457LInstruction* LChunkBuilder::DoForInCacheArray(HForInCacheArray* instr) {
2458 LOperand* map = UseRegister(instr->map());
2459 return AssignEnvironment(DefineAsRegister(new(zone()) LForInCacheArray(map)));
2460}
2461
2462
2463LInstruction* LChunkBuilder::DoCheckMapValue(HCheckMapValue* instr) {
2464 LOperand* value = UseRegisterAtStart(instr->value());
2465 LOperand* map = UseRegisterAtStart(instr->map());
2466 return AssignEnvironment(new(zone()) LCheckMapValue(value, map));
2467}
2468
2469
2470LInstruction* LChunkBuilder::DoLoadFieldByIndex(HLoadFieldByIndex* instr) {
2471 LOperand* object = UseRegister(instr->object());
2472 LOperand* index = UseTempRegister(instr->index());
2473 LLoadFieldByIndex* load = new(zone()) LLoadFieldByIndex(object, index);
2474 LInstruction* result = DefineSameAsFirst(load);
2475 return AssignPointerMap(result);
2476}
2477
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002478} // namespace internal
2479} // namespace v8
2480
2481#endif // V8_TARGET_ARCH_MIPS