blob: 3ee9ab6a3ea96725897a539861e7b13e68a3741e [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/mips64/lithium-mips64.h"
6
7#include <sstream>
8
9#if V8_TARGET_ARCH_MIPS64
10
11#include "src/crankshaft/hydrogen-osr.h"
12#include "src/crankshaft/lithium-inl.h"
13#include "src/crankshaft/mips64/lithium-codegen-mips64.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 = instr->CheckFlag(HInstruction::kAllUsesTruncatingToInt32)
1263 ? NULL : TempRegister();
1264 LInstruction* result =
1265 DefineAsRegister(new(zone()) LDivI(dividend, divisor, temp));
1266 if (instr->CheckFlag(HValue::kCanBeDivByZero) ||
1267 instr->CheckFlag(HValue::kBailoutOnMinusZero) ||
1268 (instr->CheckFlag(HValue::kCanOverflow) &&
1269 !instr->CheckFlag(HValue::kAllUsesTruncatingToInt32)) ||
1270 (!instr->IsMathFloorOfDiv() &&
1271 !instr->CheckFlag(HValue::kAllUsesTruncatingToInt32))) {
1272 result = AssignEnvironment(result);
1273 }
1274 return result;
1275}
1276
1277
1278LInstruction* LChunkBuilder::DoDiv(HDiv* instr) {
1279 if (instr->representation().IsSmiOrInteger32()) {
1280 if (instr->RightIsPowerOf2()) {
1281 return DoDivByPowerOf2I(instr);
1282 } else if (instr->right()->IsConstant()) {
1283 return DoDivByConstI(instr);
1284 } else {
1285 return DoDivI(instr);
1286 }
1287 } else if (instr->representation().IsDouble()) {
1288 return DoArithmeticD(Token::DIV, instr);
1289 } else {
1290 return DoArithmeticT(Token::DIV, instr);
1291 }
1292}
1293
1294
1295LInstruction* LChunkBuilder::DoFlooringDivByPowerOf2I(HMathFloorOfDiv* instr) {
1296 LOperand* dividend = UseRegisterAtStart(instr->left());
1297 int32_t divisor = instr->right()->GetInteger32Constant();
1298 LInstruction* result = DefineAsRegister(new(zone()) LFlooringDivByPowerOf2I(
1299 dividend, divisor));
1300 if ((instr->CheckFlag(HValue::kBailoutOnMinusZero) && divisor < 0) ||
1301 (instr->CheckFlag(HValue::kLeftCanBeMinInt) && divisor == -1)) {
1302 result = AssignEnvironment(result);
1303 }
1304 return result;
1305}
1306
1307
1308LInstruction* LChunkBuilder::DoFlooringDivByConstI(HMathFloorOfDiv* instr) {
1309 DCHECK(instr->representation().IsInteger32());
1310 DCHECK(instr->left()->representation().Equals(instr->representation()));
1311 DCHECK(instr->right()->representation().Equals(instr->representation()));
1312 LOperand* dividend = UseRegister(instr->left());
1313 int32_t divisor = instr->right()->GetInteger32Constant();
1314 LOperand* temp =
1315 ((divisor > 0 && !instr->CheckFlag(HValue::kLeftCanBeNegative)) ||
1316 (divisor < 0 && !instr->CheckFlag(HValue::kLeftCanBePositive))) ?
1317 NULL : TempRegister();
1318 LInstruction* result = DefineAsRegister(
1319 new(zone()) LFlooringDivByConstI(dividend, divisor, temp));
1320 if (divisor == 0 ||
1321 (instr->CheckFlag(HValue::kBailoutOnMinusZero) && divisor < 0)) {
1322 result = AssignEnvironment(result);
1323 }
1324 return result;
1325}
1326
1327
1328LInstruction* LChunkBuilder::DoFlooringDivI(HMathFloorOfDiv* instr) {
1329 DCHECK(instr->representation().IsSmiOrInteger32());
1330 DCHECK(instr->left()->representation().Equals(instr->representation()));
1331 DCHECK(instr->right()->representation().Equals(instr->representation()));
1332 LOperand* dividend = UseRegister(instr->left());
1333 LOperand* divisor = UseRegister(instr->right());
1334 LInstruction* result =
1335 DefineAsRegister(new (zone()) LFlooringDivI(dividend, divisor));
1336 if (instr->CheckFlag(HValue::kCanBeDivByZero) ||
1337 instr->CheckFlag(HValue::kBailoutOnMinusZero) ||
1338 (instr->CheckFlag(HValue::kCanOverflow))) {
1339 result = AssignEnvironment(result);
1340 }
1341 return result;
1342}
1343
1344
1345LInstruction* LChunkBuilder::DoMathFloorOfDiv(HMathFloorOfDiv* instr) {
1346 if (instr->RightIsPowerOf2()) {
1347 return DoFlooringDivByPowerOf2I(instr);
1348 } else if (instr->right()->IsConstant()) {
1349 return DoFlooringDivByConstI(instr);
1350 } else {
1351 return DoFlooringDivI(instr);
1352 }
1353}
1354
1355
1356LInstruction* LChunkBuilder::DoModByPowerOf2I(HMod* instr) {
1357 DCHECK(instr->representation().IsSmiOrInteger32());
1358 DCHECK(instr->left()->representation().Equals(instr->representation()));
1359 DCHECK(instr->right()->representation().Equals(instr->representation()));
1360 LOperand* dividend = UseRegisterAtStart(instr->left());
1361 int32_t divisor = instr->right()->GetInteger32Constant();
1362 LInstruction* result = DefineSameAsFirst(new(zone()) LModByPowerOf2I(
1363 dividend, divisor));
1364 if (instr->CheckFlag(HValue::kLeftCanBeNegative) &&
1365 instr->CheckFlag(HValue::kBailoutOnMinusZero)) {
1366 result = AssignEnvironment(result);
1367 }
1368 return result;
1369}
1370
1371
1372LInstruction* LChunkBuilder::DoModByConstI(HMod* instr) {
1373 DCHECK(instr->representation().IsSmiOrInteger32());
1374 DCHECK(instr->left()->representation().Equals(instr->representation()));
1375 DCHECK(instr->right()->representation().Equals(instr->representation()));
1376 LOperand* dividend = UseRegister(instr->left());
1377 int32_t divisor = instr->right()->GetInteger32Constant();
1378 LInstruction* result = DefineAsRegister(new(zone()) LModByConstI(
1379 dividend, divisor));
1380 if (divisor == 0 || instr->CheckFlag(HValue::kBailoutOnMinusZero)) {
1381 result = AssignEnvironment(result);
1382 }
1383 return result;
1384}
1385
1386
1387LInstruction* LChunkBuilder::DoModI(HMod* instr) {
1388 DCHECK(instr->representation().IsSmiOrInteger32());
1389 DCHECK(instr->left()->representation().Equals(instr->representation()));
1390 DCHECK(instr->right()->representation().Equals(instr->representation()));
1391 LOperand* dividend = UseRegister(instr->left());
1392 LOperand* divisor = UseRegister(instr->right());
1393 LInstruction* result = DefineAsRegister(new(zone()) LModI(
1394 dividend, divisor));
1395 if (instr->CheckFlag(HValue::kCanBeDivByZero) ||
1396 instr->CheckFlag(HValue::kBailoutOnMinusZero)) {
1397 result = AssignEnvironment(result);
1398 }
1399 return result;
1400}
1401
1402
1403LInstruction* LChunkBuilder::DoMod(HMod* instr) {
1404 if (instr->representation().IsSmiOrInteger32()) {
1405 return instr->RightIsPowerOf2() ? DoModByPowerOf2I(instr) : DoModI(instr);
1406 } else if (instr->representation().IsDouble()) {
1407 return DoArithmeticD(Token::MOD, instr);
1408 } else {
1409 return DoArithmeticT(Token::MOD, instr);
1410 }
1411}
1412
1413
1414LInstruction* LChunkBuilder::DoMul(HMul* instr) {
1415 if (instr->representation().IsSmiOrInteger32()) {
1416 DCHECK(instr->left()->representation().Equals(instr->representation()));
1417 DCHECK(instr->right()->representation().Equals(instr->representation()));
1418 HValue* left = instr->BetterLeftOperand();
1419 HValue* right = instr->BetterRightOperand();
1420 LOperand* left_op;
1421 LOperand* right_op;
1422 bool can_overflow = instr->CheckFlag(HValue::kCanOverflow);
1423 bool bailout_on_minus_zero = instr->CheckFlag(HValue::kBailoutOnMinusZero);
1424
1425 int32_t constant_value = 0;
1426 if (right->IsConstant()) {
1427 HConstant* constant = HConstant::cast(right);
1428 constant_value = constant->Integer32Value();
1429 // Constants -1, 0 and 1 can be optimized if the result can overflow.
1430 // For other constants, it can be optimized only without overflow.
1431 if (!can_overflow || ((constant_value >= -1) && (constant_value <= 1))) {
1432 left_op = UseRegisterAtStart(left);
1433 right_op = UseConstant(right);
1434 } else {
1435 if (bailout_on_minus_zero) {
1436 left_op = UseRegister(left);
1437 } else {
1438 left_op = UseRegisterAtStart(left);
1439 }
1440 right_op = UseRegister(right);
1441 }
1442 } else {
1443 if (bailout_on_minus_zero) {
1444 left_op = UseRegister(left);
1445 } else {
1446 left_op = UseRegisterAtStart(left);
1447 }
1448 right_op = UseRegister(right);
1449 }
1450 LInstruction* result =
1451 instr->representation().IsSmi()
1452 ? DefineAsRegister(new (zone()) LMulS(left_op, right_op))
1453 : DefineAsRegister(new (zone()) LMulI(left_op, right_op));
1454 if (right_op->IsConstantOperand()
1455 ? ((can_overflow && constant_value == -1) ||
1456 (bailout_on_minus_zero && constant_value <= 0))
1457 : (can_overflow || bailout_on_minus_zero)) {
1458 AssignEnvironment(result);
1459 }
1460 return result;
1461
1462 } else if (instr->representation().IsDouble()) {
1463 if (kArchVariant == kMips64r2) {
1464 if (instr->HasOneUse() && instr->uses().value()->IsAdd()) {
1465 HAdd* add = HAdd::cast(instr->uses().value());
1466 if (instr == add->left()) {
1467 // This mul is the lhs of an add. The add and mul will be folded
1468 // into a multiply-add.
1469 return NULL;
1470 }
1471 if (instr == add->right() && !add->left()->IsMul()) {
1472 // This mul is the rhs of an add, where the lhs is not another mul.
1473 // The add and mul will be folded into a multiply-add.
1474 return NULL;
1475 }
1476 }
1477 }
1478 return DoArithmeticD(Token::MUL, instr);
1479 } else {
1480 return DoArithmeticT(Token::MUL, instr);
1481 }
1482}
1483
1484
1485LInstruction* LChunkBuilder::DoSub(HSub* instr) {
1486 if (instr->representation().IsSmiOrInteger32()) {
1487 DCHECK(instr->left()->representation().Equals(instr->representation()));
1488 DCHECK(instr->right()->representation().Equals(instr->representation()));
1489 LOperand* left = UseRegisterAtStart(instr->left());
1490 LOperand* right = UseRegisterOrConstantAtStart(instr->right());
1491 LInstruction* result =
1492 instr->representation().IsSmi()
1493 ? DefineAsRegister(new (zone()) LSubS(left, right))
1494 : DefineAsRegister(new (zone()) LSubI(left, right));
1495 if (instr->CheckFlag(HValue::kCanOverflow)) {
1496 result = AssignEnvironment(result);
1497 }
1498 return result;
1499 } else if (instr->representation().IsDouble()) {
1500 return DoArithmeticD(Token::SUB, instr);
1501 } else {
1502 return DoArithmeticT(Token::SUB, instr);
1503 }
1504}
1505
1506
1507LInstruction* LChunkBuilder::DoMultiplyAdd(HMul* mul, HValue* addend) {
1508 LOperand* multiplier_op = UseRegisterAtStart(mul->left());
1509 LOperand* multiplicand_op = UseRegisterAtStart(mul->right());
1510 LOperand* addend_op = UseRegisterAtStart(addend);
1511 return DefineSameAsFirst(new(zone()) LMultiplyAddD(addend_op, multiplier_op,
1512 multiplicand_op));
1513}
1514
1515
1516LInstruction* LChunkBuilder::DoAdd(HAdd* instr) {
1517 if (instr->representation().IsSmiOrInteger32()) {
1518 DCHECK(instr->left()->representation().Equals(instr->representation()));
1519 DCHECK(instr->right()->representation().Equals(instr->representation()));
1520 LOperand* left = UseRegisterAtStart(instr->BetterLeftOperand());
1521 LOperand* right = UseRegisterOrConstantAtStart(instr->BetterRightOperand());
1522 LInstruction* result =
1523 instr->representation().IsSmi()
1524 ? DefineAsRegister(new (zone()) LAddS(left, right))
1525 : DefineAsRegister(new (zone()) LAddI(left, right));
1526 if (instr->CheckFlag(HValue::kCanOverflow)) {
1527 result = AssignEnvironment(result);
1528 }
1529 return result;
1530 } else if (instr->representation().IsExternal()) {
1531 DCHECK(instr->IsConsistentExternalRepresentation());
1532 DCHECK(!instr->CheckFlag(HValue::kCanOverflow));
1533 LOperand* left = UseRegisterAtStart(instr->left());
1534 LOperand* right = UseRegisterOrConstantAtStart(instr->right());
1535 return DefineAsRegister(new (zone()) LAddE(left, right));
1536 } else if (instr->representation().IsDouble()) {
1537 if (kArchVariant == kMips64r2) {
1538 if (instr->left()->IsMul())
1539 return DoMultiplyAdd(HMul::cast(instr->left()), instr->right());
1540
1541 if (instr->right()->IsMul()) {
1542 DCHECK(!instr->left()->IsMul());
1543 return DoMultiplyAdd(HMul::cast(instr->right()), instr->left());
1544 }
1545 }
1546 return DoArithmeticD(Token::ADD, instr);
1547 } else {
1548 return DoArithmeticT(Token::ADD, instr);
1549 }
1550}
1551
1552
1553LInstruction* LChunkBuilder::DoMathMinMax(HMathMinMax* instr) {
1554 LOperand* left = NULL;
1555 LOperand* right = NULL;
1556 if (instr->representation().IsSmiOrInteger32()) {
1557 DCHECK(instr->left()->representation().Equals(instr->representation()));
1558 DCHECK(instr->right()->representation().Equals(instr->representation()));
1559 left = UseRegisterAtStart(instr->BetterLeftOperand());
1560 right = UseOrConstantAtStart(instr->BetterRightOperand());
1561 } else {
1562 DCHECK(instr->representation().IsDouble());
1563 DCHECK(instr->left()->representation().IsDouble());
1564 DCHECK(instr->right()->representation().IsDouble());
1565 left = UseRegisterAtStart(instr->left());
1566 right = UseRegisterAtStart(instr->right());
1567 }
1568 return DefineAsRegister(new(zone()) LMathMinMax(left, right));
1569}
1570
1571
1572LInstruction* LChunkBuilder::DoPower(HPower* instr) {
1573 DCHECK(instr->representation().IsDouble());
1574 // We call a C function for double power. It can't trigger a GC.
1575 // We need to use fixed result register for the call.
1576 Representation exponent_type = instr->right()->representation();
1577 DCHECK(instr->left()->representation().IsDouble());
1578 LOperand* left = UseFixedDouble(instr->left(), f2);
1579 LOperand* right =
1580 exponent_type.IsDouble()
1581 ? UseFixedDouble(instr->right(), f4)
1582 : UseFixed(instr->right(), MathPowTaggedDescriptor::exponent());
1583 LPower* result = new(zone()) LPower(left, right);
1584 return MarkAsCall(DefineFixedDouble(result, f0),
1585 instr,
1586 CAN_DEOPTIMIZE_EAGERLY);
1587}
1588
1589
1590LInstruction* LChunkBuilder::DoCompareGeneric(HCompareGeneric* instr) {
1591 DCHECK(instr->left()->representation().IsTagged());
1592 DCHECK(instr->right()->representation().IsTagged());
1593 LOperand* context = UseFixed(instr->context(), cp);
1594 LOperand* left = UseFixed(instr->left(), a1);
1595 LOperand* right = UseFixed(instr->right(), a0);
1596 LCmpT* result = new(zone()) LCmpT(context, left, right);
1597 return MarkAsCall(DefineFixed(result, v0), instr);
1598}
1599
1600
1601LInstruction* LChunkBuilder::DoCompareNumericAndBranch(
1602 HCompareNumericAndBranch* instr) {
1603 Representation r = instr->representation();
1604 if (r.IsSmiOrInteger32()) {
1605 DCHECK(instr->left()->representation().Equals(r));
1606 DCHECK(instr->right()->representation().Equals(r));
1607 LOperand* left = UseRegisterOrConstantAtStart(instr->left());
1608 LOperand* right = UseRegisterOrConstantAtStart(instr->right());
1609 return new(zone()) LCompareNumericAndBranch(left, right);
1610 } else {
1611 DCHECK(r.IsDouble());
1612 DCHECK(instr->left()->representation().IsDouble());
1613 DCHECK(instr->right()->representation().IsDouble());
1614 LOperand* left = UseRegisterAtStart(instr->left());
1615 LOperand* right = UseRegisterAtStart(instr->right());
1616 return new(zone()) LCompareNumericAndBranch(left, right);
1617 }
1618}
1619
1620
1621LInstruction* LChunkBuilder::DoCompareObjectEqAndBranch(
1622 HCompareObjectEqAndBranch* instr) {
1623 LOperand* left = UseRegisterAtStart(instr->left());
1624 LOperand* right = UseRegisterAtStart(instr->right());
1625 return new(zone()) LCmpObjectEqAndBranch(left, right);
1626}
1627
1628
1629LInstruction* LChunkBuilder::DoCompareHoleAndBranch(
1630 HCompareHoleAndBranch* instr) {
1631 LOperand* value = UseRegisterAtStart(instr->value());
1632 return new(zone()) LCmpHoleAndBranch(value);
1633}
1634
1635
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001636LInstruction* LChunkBuilder::DoIsStringAndBranch(HIsStringAndBranch* instr) {
1637 DCHECK(instr->value()->representation().IsTagged());
1638 LOperand* temp = TempRegister();
1639 return new(zone()) LIsStringAndBranch(UseRegisterAtStart(instr->value()),
1640 temp);
1641}
1642
1643
1644LInstruction* LChunkBuilder::DoIsSmiAndBranch(HIsSmiAndBranch* instr) {
1645 DCHECK(instr->value()->representation().IsTagged());
1646 return new(zone()) LIsSmiAndBranch(Use(instr->value()));
1647}
1648
1649
1650LInstruction* LChunkBuilder::DoIsUndetectableAndBranch(
1651 HIsUndetectableAndBranch* instr) {
1652 DCHECK(instr->value()->representation().IsTagged());
1653 return new(zone()) LIsUndetectableAndBranch(
1654 UseRegisterAtStart(instr->value()), TempRegister());
1655}
1656
1657
1658LInstruction* LChunkBuilder::DoStringCompareAndBranch(
1659 HStringCompareAndBranch* instr) {
1660 DCHECK(instr->left()->representation().IsTagged());
1661 DCHECK(instr->right()->representation().IsTagged());
1662 LOperand* context = UseFixed(instr->context(), cp);
1663 LOperand* left = UseFixed(instr->left(), a1);
1664 LOperand* right = UseFixed(instr->right(), a0);
1665 LStringCompareAndBranch* result =
1666 new(zone()) LStringCompareAndBranch(context, left, right);
1667 return MarkAsCall(result, instr);
1668}
1669
1670
1671LInstruction* LChunkBuilder::DoHasInstanceTypeAndBranch(
1672 HHasInstanceTypeAndBranch* instr) {
1673 DCHECK(instr->value()->representation().IsTagged());
1674 LOperand* value = UseRegisterAtStart(instr->value());
1675 return new(zone()) LHasInstanceTypeAndBranch(value);
1676}
1677
1678
1679LInstruction* LChunkBuilder::DoGetCachedArrayIndex(
1680 HGetCachedArrayIndex* instr) {
1681 DCHECK(instr->value()->representation().IsTagged());
1682 LOperand* value = UseRegisterAtStart(instr->value());
1683
1684 return DefineAsRegister(new(zone()) LGetCachedArrayIndex(value));
1685}
1686
1687
1688LInstruction* LChunkBuilder::DoHasCachedArrayIndexAndBranch(
1689 HHasCachedArrayIndexAndBranch* instr) {
1690 DCHECK(instr->value()->representation().IsTagged());
1691 return new(zone()) LHasCachedArrayIndexAndBranch(
1692 UseRegisterAtStart(instr->value()));
1693}
1694
1695
1696LInstruction* LChunkBuilder::DoClassOfTestAndBranch(
1697 HClassOfTestAndBranch* instr) {
1698 DCHECK(instr->value()->representation().IsTagged());
1699 return new(zone()) LClassOfTestAndBranch(UseRegister(instr->value()),
1700 TempRegister());
1701}
1702
1703
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001704LInstruction* LChunkBuilder::DoSeqStringGetChar(HSeqStringGetChar* instr) {
1705 LOperand* string = UseRegisterAtStart(instr->string());
1706 LOperand* index = UseRegisterOrConstantAtStart(instr->index());
1707 return DefineAsRegister(new(zone()) LSeqStringGetChar(string, index));
1708}
1709
1710
1711LInstruction* LChunkBuilder::DoSeqStringSetChar(HSeqStringSetChar* instr) {
1712 LOperand* string = UseRegisterAtStart(instr->string());
1713 LOperand* index = FLAG_debug_code
1714 ? UseRegisterAtStart(instr->index())
1715 : UseRegisterOrConstantAtStart(instr->index());
1716 LOperand* value = UseRegisterAtStart(instr->value());
1717 LOperand* context = FLAG_debug_code ? UseFixed(instr->context(), cp) : NULL;
1718 return new(zone()) LSeqStringSetChar(context, string, index, value);
1719}
1720
1721
1722LInstruction* LChunkBuilder::DoBoundsCheck(HBoundsCheck* instr) {
1723 if (!FLAG_debug_code && instr->skip_check()) return NULL;
1724 LOperand* index = UseRegisterOrConstantAtStart(instr->index());
1725 LOperand* length = !index->IsConstantOperand()
1726 ? UseRegisterOrConstantAtStart(instr->length())
1727 : UseRegisterAtStart(instr->length());
1728 LInstruction* result = new(zone()) LBoundsCheck(index, length);
1729 if (!FLAG_debug_code || !instr->skip_check()) {
1730 result = AssignEnvironment(result);
1731 }
1732return result;
1733}
1734
1735
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001736LInstruction* LChunkBuilder::DoAbnormalExit(HAbnormalExit* instr) {
1737 // The control instruction marking the end of a block that completed
1738 // abruptly (e.g., threw an exception). There is nothing specific to do.
1739 return NULL;
1740}
1741
1742
1743LInstruction* LChunkBuilder::DoUseConst(HUseConst* instr) {
1744 return NULL;
1745}
1746
1747
1748LInstruction* LChunkBuilder::DoForceRepresentation(HForceRepresentation* bad) {
1749 // All HForceRepresentation instructions should be eliminated in the
1750 // representation change phase of Hydrogen.
1751 UNREACHABLE();
1752 return NULL;
1753}
1754
1755
1756LInstruction* LChunkBuilder::DoChange(HChange* instr) {
1757 Representation from = instr->from();
1758 Representation to = instr->to();
1759 HValue* val = instr->value();
1760 if (from.IsSmi()) {
1761 if (to.IsTagged()) {
1762 LOperand* value = UseRegister(val);
1763 return DefineSameAsFirst(new(zone()) LDummyUse(value));
1764 }
1765 from = Representation::Tagged();
1766 }
1767 if (from.IsTagged()) {
1768 if (to.IsDouble()) {
1769 LOperand* value = UseRegister(val);
1770 LInstruction* result = DefineAsRegister(new(zone()) LNumberUntagD(value));
1771 if (!val->representation().IsSmi()) result = AssignEnvironment(result);
1772 return result;
1773 } else if (to.IsSmi()) {
1774 LOperand* value = UseRegister(val);
1775 if (val->type().IsSmi()) {
1776 return DefineSameAsFirst(new(zone()) LDummyUse(value));
1777 }
1778 return AssignEnvironment(DefineSameAsFirst(new(zone()) LCheckSmi(value)));
1779 } else {
1780 DCHECK(to.IsInteger32());
1781 if (val->type().IsSmi() || val->representation().IsSmi()) {
1782 LOperand* value = UseRegisterAtStart(val);
1783 return DefineAsRegister(new(zone()) LSmiUntag(value, false));
1784 } else {
1785 LOperand* value = UseRegister(val);
1786 LOperand* temp1 = TempRegister();
1787 LOperand* temp2 = TempDoubleRegister();
1788 LInstruction* result =
1789 DefineSameAsFirst(new(zone()) LTaggedToI(value, temp1, temp2));
1790 if (!val->representation().IsSmi()) result = AssignEnvironment(result);
1791 return result;
1792 }
1793 }
1794 } else if (from.IsDouble()) {
1795 if (to.IsTagged()) {
1796 info()->MarkAsDeferredCalling();
1797 LOperand* value = UseRegister(val);
1798 LOperand* temp1 = TempRegister();
1799 LOperand* temp2 = TempRegister();
1800
1801 LUnallocated* result_temp = TempRegister();
1802 LNumberTagD* result = new(zone()) LNumberTagD(value, temp1, temp2);
1803 return AssignPointerMap(Define(result, result_temp));
1804 } else if (to.IsSmi()) {
1805 LOperand* value = UseRegister(val);
1806 return AssignEnvironment(
1807 DefineAsRegister(new(zone()) LDoubleToSmi(value)));
1808 } else {
1809 DCHECK(to.IsInteger32());
1810 LOperand* value = UseRegister(val);
1811 LInstruction* result = DefineAsRegister(new(zone()) LDoubleToI(value));
1812 if (!instr->CanTruncateToInt32()) result = AssignEnvironment(result);
1813 return result;
1814 }
1815 } else if (from.IsInteger32()) {
1816 info()->MarkAsDeferredCalling();
1817 if (to.IsTagged()) {
1818 if (val->CheckFlag(HInstruction::kUint32)) {
1819 LOperand* value = UseRegisterAtStart(val);
1820 LOperand* temp1 = TempRegister();
1821 LOperand* temp2 = TempRegister();
1822 LNumberTagU* result = new(zone()) LNumberTagU(value, temp1, temp2);
1823 return AssignPointerMap(DefineAsRegister(result));
1824 } else {
1825 STATIC_ASSERT((kMinInt == Smi::kMinValue) &&
1826 (kMaxInt == Smi::kMaxValue));
1827 LOperand* value = UseRegisterAtStart(val);
1828 return DefineAsRegister(new(zone()) LSmiTag(value));
1829 }
1830 } else if (to.IsSmi()) {
1831 LOperand* value = UseRegister(val);
1832 LInstruction* result = DefineAsRegister(new(zone()) LSmiTag(value));
1833 if (instr->CheckFlag(HValue::kCanOverflow)) {
1834 result = AssignEnvironment(result);
1835 }
1836 return result;
1837 } else {
1838 DCHECK(to.IsDouble());
1839 if (val->CheckFlag(HInstruction::kUint32)) {
1840 return DefineAsRegister(new(zone()) LUint32ToDouble(UseRegister(val)));
1841 } else {
1842 return DefineAsRegister(new(zone()) LInteger32ToDouble(Use(val)));
1843 }
1844 }
1845 }
1846 UNREACHABLE();
1847 return NULL;
1848}
1849
1850
1851LInstruction* LChunkBuilder::DoCheckHeapObject(HCheckHeapObject* instr) {
1852 LOperand* value = UseRegisterAtStart(instr->value());
1853 LInstruction* result = new(zone()) LCheckNonSmi(value);
1854 if (!instr->value()->type().IsHeapObject()) {
1855 result = AssignEnvironment(result);
1856 }
1857 return result;
1858}
1859
1860
1861LInstruction* LChunkBuilder::DoCheckSmi(HCheckSmi* instr) {
1862 LOperand* value = UseRegisterAtStart(instr->value());
1863 return AssignEnvironment(new(zone()) LCheckSmi(value));
1864}
1865
1866
1867LInstruction* LChunkBuilder::DoCheckArrayBufferNotNeutered(
1868 HCheckArrayBufferNotNeutered* instr) {
1869 LOperand* view = UseRegisterAtStart(instr->value());
1870 LCheckArrayBufferNotNeutered* result =
1871 new (zone()) LCheckArrayBufferNotNeutered(view);
1872 return AssignEnvironment(result);
1873}
1874
1875
1876LInstruction* LChunkBuilder::DoCheckInstanceType(HCheckInstanceType* instr) {
1877 LOperand* value = UseRegisterAtStart(instr->value());
1878 LInstruction* result = new(zone()) LCheckInstanceType(value);
1879 return AssignEnvironment(result);
1880}
1881
1882
1883LInstruction* LChunkBuilder::DoCheckValue(HCheckValue* instr) {
1884 LOperand* value = UseRegisterAtStart(instr->value());
1885 return AssignEnvironment(new(zone()) LCheckValue(value));
1886}
1887
1888
1889LInstruction* LChunkBuilder::DoCheckMaps(HCheckMaps* instr) {
1890 if (instr->IsStabilityCheck()) return new(zone()) LCheckMaps;
1891 LOperand* value = UseRegisterAtStart(instr->value());
1892 LInstruction* result = AssignEnvironment(new(zone()) LCheckMaps(value));
1893 if (instr->HasMigrationTarget()) {
1894 info()->MarkAsDeferredCalling();
1895 result = AssignPointerMap(result);
1896 }
1897 return result;
1898}
1899
1900
1901LInstruction* LChunkBuilder::DoClampToUint8(HClampToUint8* instr) {
1902 HValue* value = instr->value();
1903 Representation input_rep = value->representation();
1904 LOperand* reg = UseRegister(value);
1905 if (input_rep.IsDouble()) {
1906 // Revisit this decision, here and 8 lines below.
1907 return DefineAsRegister(new(zone()) LClampDToUint8(reg,
1908 TempDoubleRegister()));
1909 } else if (input_rep.IsInteger32()) {
1910 return DefineAsRegister(new(zone()) LClampIToUint8(reg));
1911 } else {
1912 DCHECK(input_rep.IsSmiOrTagged());
1913 LClampTToUint8* result =
1914 new(zone()) LClampTToUint8(reg, TempDoubleRegister());
1915 return AssignEnvironment(DefineAsRegister(result));
1916 }
1917}
1918
1919
1920LInstruction* LChunkBuilder::DoDoubleBits(HDoubleBits* instr) {
1921 HValue* value = instr->value();
1922 DCHECK(value->representation().IsDouble());
1923 return DefineAsRegister(new(zone()) LDoubleBits(UseRegister(value)));
1924}
1925
1926
1927LInstruction* LChunkBuilder::DoConstructDouble(HConstructDouble* instr) {
1928 LOperand* lo = UseRegister(instr->lo());
1929 LOperand* hi = UseRegister(instr->hi());
1930 return DefineAsRegister(new(zone()) LConstructDouble(hi, lo));
1931}
1932
1933
1934LInstruction* LChunkBuilder::DoReturn(HReturn* instr) {
1935 LOperand* context = info()->IsStub()
1936 ? UseFixed(instr->context(), cp)
1937 : NULL;
1938 LOperand* parameter_count = UseRegisterOrConstant(instr->parameter_count());
1939 return new(zone()) LReturn(UseFixed(instr->value(), v0), context,
1940 parameter_count);
1941}
1942
1943
1944LInstruction* LChunkBuilder::DoConstant(HConstant* instr) {
1945 Representation r = instr->representation();
1946 if (r.IsSmi()) {
1947 return DefineAsRegister(new(zone()) LConstantS);
1948 } else if (r.IsInteger32()) {
1949 return DefineAsRegister(new(zone()) LConstantI);
1950 } else if (r.IsDouble()) {
1951 return DefineAsRegister(new(zone()) LConstantD);
1952 } else if (r.IsExternal()) {
1953 return DefineAsRegister(new(zone()) LConstantE);
1954 } else if (r.IsTagged()) {
1955 return DefineAsRegister(new(zone()) LConstantT);
1956 } else {
1957 UNREACHABLE();
1958 return NULL;
1959 }
1960}
1961
1962
1963LInstruction* LChunkBuilder::DoLoadGlobalGeneric(HLoadGlobalGeneric* instr) {
1964 LOperand* context = UseFixed(instr->context(), cp);
1965 LOperand* global_object =
1966 UseFixed(instr->global_object(), LoadDescriptor::ReceiverRegister());
1967 LOperand* vector = NULL;
1968 if (instr->HasVectorAndSlot()) {
1969 vector = FixedTemp(LoadWithVectorDescriptor::VectorRegister());
1970 }
1971 LLoadGlobalGeneric* result =
1972 new(zone()) LLoadGlobalGeneric(context, global_object, vector);
1973 return MarkAsCall(DefineFixed(result, v0), instr);
1974}
1975
1976
1977LInstruction* LChunkBuilder::DoLoadContextSlot(HLoadContextSlot* instr) {
1978 LOperand* context = UseRegisterAtStart(instr->value());
1979 LInstruction* result =
1980 DefineAsRegister(new(zone()) LLoadContextSlot(context));
1981 if (instr->RequiresHoleCheck() && instr->DeoptimizesOnHole()) {
1982 result = AssignEnvironment(result);
1983 }
1984 return result;
1985}
1986
1987
1988LInstruction* LChunkBuilder::DoStoreContextSlot(HStoreContextSlot* instr) {
1989 LOperand* context;
1990 LOperand* value;
1991 if (instr->NeedsWriteBarrier()) {
1992 context = UseTempRegister(instr->context());
1993 value = UseTempRegister(instr->value());
1994 } else {
1995 context = UseRegister(instr->context());
1996 value = UseRegister(instr->value());
1997 }
1998 LInstruction* result = new(zone()) LStoreContextSlot(context, value);
1999 if (instr->RequiresHoleCheck() && instr->DeoptimizesOnHole()) {
2000 result = AssignEnvironment(result);
2001 }
2002 return result;
2003}
2004
2005
2006LInstruction* LChunkBuilder::DoLoadNamedField(HLoadNamedField* instr) {
2007 LOperand* obj = UseRegisterAtStart(instr->object());
2008 return DefineAsRegister(new(zone()) LLoadNamedField(obj));
2009}
2010
2011
2012LInstruction* LChunkBuilder::DoLoadNamedGeneric(HLoadNamedGeneric* instr) {
2013 LOperand* context = UseFixed(instr->context(), cp);
2014 LOperand* object =
2015 UseFixed(instr->object(), LoadDescriptor::ReceiverRegister());
2016 LOperand* vector = NULL;
2017 if (instr->HasVectorAndSlot()) {
2018 vector = FixedTemp(LoadWithVectorDescriptor::VectorRegister());
2019 }
2020
2021 LInstruction* result =
2022 DefineFixed(new(zone()) LLoadNamedGeneric(context, object, vector), v0);
2023 return MarkAsCall(result, instr);
2024}
2025
2026
2027LInstruction* LChunkBuilder::DoLoadFunctionPrototype(
2028 HLoadFunctionPrototype* instr) {
2029 return AssignEnvironment(DefineAsRegister(
2030 new(zone()) LLoadFunctionPrototype(UseRegister(instr->function()))));
2031}
2032
2033
2034LInstruction* LChunkBuilder::DoLoadRoot(HLoadRoot* instr) {
2035 return DefineAsRegister(new(zone()) LLoadRoot);
2036}
2037
2038
2039LInstruction* LChunkBuilder::DoLoadKeyed(HLoadKeyed* instr) {
2040 DCHECK(instr->key()->representation().IsSmiOrInteger32());
2041 ElementsKind elements_kind = instr->elements_kind();
2042 LOperand* key = UseRegisterOrConstantAtStart(instr->key());
2043 LInstruction* result = NULL;
2044
2045 if (!instr->is_fixed_typed_array()) {
2046 LOperand* obj = NULL;
2047 if (instr->representation().IsDouble()) {
2048 obj = UseRegister(instr->elements());
2049 } else {
2050 DCHECK(instr->representation().IsSmiOrTagged() ||
2051 instr->representation().IsInteger32());
2052 obj = UseRegisterAtStart(instr->elements());
2053 }
2054 result = DefineAsRegister(new (zone()) LLoadKeyed(obj, key, nullptr));
2055 } else {
2056 DCHECK(
2057 (instr->representation().IsInteger32() &&
2058 !IsDoubleOrFloatElementsKind(elements_kind)) ||
2059 (instr->representation().IsDouble() &&
2060 IsDoubleOrFloatElementsKind(elements_kind)));
2061 LOperand* backing_store = UseRegister(instr->elements());
2062 LOperand* backing_store_owner = UseAny(instr->backing_store_owner());
2063 result = DefineAsRegister(
2064 new (zone()) LLoadKeyed(backing_store, key, backing_store_owner));
2065 }
2066
2067 bool needs_environment;
2068 if (instr->is_fixed_typed_array()) {
2069 // see LCodeGen::DoLoadKeyedExternalArray
2070 needs_environment = elements_kind == UINT32_ELEMENTS &&
2071 !instr->CheckFlag(HInstruction::kUint32);
2072 } else {
2073 // see LCodeGen::DoLoadKeyedFixedDoubleArray and
2074 // LCodeGen::DoLoadKeyedFixedArray
2075 needs_environment =
2076 instr->RequiresHoleCheck() ||
2077 (instr->hole_mode() == CONVERT_HOLE_TO_UNDEFINED && info()->IsStub());
2078 }
2079
2080 if (needs_environment) {
2081 result = AssignEnvironment(result);
2082 }
2083 return result;
2084}
2085
2086
2087LInstruction* LChunkBuilder::DoLoadKeyedGeneric(HLoadKeyedGeneric* instr) {
2088 LOperand* context = UseFixed(instr->context(), cp);
2089 LOperand* object =
2090 UseFixed(instr->object(), LoadDescriptor::ReceiverRegister());
2091 LOperand* key = UseFixed(instr->key(), LoadDescriptor::NameRegister());
2092 LOperand* vector = NULL;
2093 if (instr->HasVectorAndSlot()) {
2094 vector = FixedTemp(LoadWithVectorDescriptor::VectorRegister());
2095 }
2096
2097 LInstruction* result =
2098 DefineFixed(new(zone()) LLoadKeyedGeneric(context, object, key, vector),
2099 v0);
2100 return MarkAsCall(result, instr);
2101}
2102
2103
2104LInstruction* LChunkBuilder::DoStoreKeyed(HStoreKeyed* instr) {
2105 if (!instr->is_fixed_typed_array()) {
2106 DCHECK(instr->elements()->representation().IsTagged());
2107 bool needs_write_barrier = instr->NeedsWriteBarrier();
2108 LOperand* object = NULL;
2109 LOperand* val = NULL;
2110 LOperand* key = NULL;
2111
2112 if (instr->value()->representation().IsDouble()) {
2113 object = UseRegisterAtStart(instr->elements());
2114 key = UseRegisterOrConstantAtStart(instr->key());
2115 val = UseRegister(instr->value());
2116 } else {
2117 DCHECK(instr->value()->representation().IsSmiOrTagged() ||
2118 instr->value()->representation().IsInteger32());
2119 if (needs_write_barrier) {
2120 object = UseTempRegister(instr->elements());
2121 val = UseTempRegister(instr->value());
2122 key = UseTempRegister(instr->key());
2123 } else {
2124 object = UseRegisterAtStart(instr->elements());
2125 val = UseRegisterAtStart(instr->value());
2126 key = UseRegisterOrConstantAtStart(instr->key());
2127 }
2128 }
2129
2130 return new (zone()) LStoreKeyed(object, key, val, nullptr);
2131 }
2132
2133 DCHECK(
2134 (instr->value()->representation().IsInteger32() &&
2135 !IsDoubleOrFloatElementsKind(instr->elements_kind())) ||
2136 (instr->value()->representation().IsDouble() &&
2137 IsDoubleOrFloatElementsKind(instr->elements_kind())));
2138 DCHECK(instr->elements()->representation().IsExternal());
2139 LOperand* val = UseRegister(instr->value());
2140 LOperand* key = UseRegisterOrConstantAtStart(instr->key());
2141 LOperand* backing_store = UseRegister(instr->elements());
2142 LOperand* backing_store_owner = UseAny(instr->backing_store_owner());
2143 return new (zone()) LStoreKeyed(backing_store, key, val, backing_store_owner);
2144}
2145
2146
2147LInstruction* LChunkBuilder::DoStoreKeyedGeneric(HStoreKeyedGeneric* instr) {
2148 LOperand* context = UseFixed(instr->context(), cp);
2149 LOperand* obj =
2150 UseFixed(instr->object(), StoreDescriptor::ReceiverRegister());
2151 LOperand* key = UseFixed(instr->key(), StoreDescriptor::NameRegister());
2152 LOperand* val = UseFixed(instr->value(), StoreDescriptor::ValueRegister());
2153
2154 DCHECK(instr->object()->representation().IsTagged());
2155 DCHECK(instr->key()->representation().IsTagged());
2156 DCHECK(instr->value()->representation().IsTagged());
2157
2158 LOperand* slot = NULL;
2159 LOperand* vector = NULL;
2160 if (instr->HasVectorAndSlot()) {
2161 slot = FixedTemp(VectorStoreICDescriptor::SlotRegister());
2162 vector = FixedTemp(VectorStoreICDescriptor::VectorRegister());
2163 }
2164
2165 LStoreKeyedGeneric* result =
2166 new (zone()) LStoreKeyedGeneric(context, obj, key, val, slot, vector);
2167 return MarkAsCall(result, instr);
2168}
2169
2170
2171LInstruction* LChunkBuilder::DoTransitionElementsKind(
2172 HTransitionElementsKind* instr) {
2173 if (IsSimpleMapChangeTransition(instr->from_kind(), instr->to_kind())) {
2174 LOperand* object = UseRegister(instr->object());
2175 LOperand* new_map_reg = TempRegister();
2176 LTransitionElementsKind* result =
2177 new(zone()) LTransitionElementsKind(object, NULL, new_map_reg);
2178 return result;
2179 } else {
2180 LOperand* object = UseFixed(instr->object(), a0);
2181 LOperand* context = UseFixed(instr->context(), cp);
2182 LTransitionElementsKind* result =
2183 new(zone()) LTransitionElementsKind(object, context, NULL);
2184 return MarkAsCall(result, instr);
2185 }
2186}
2187
2188
2189LInstruction* LChunkBuilder::DoTrapAllocationMemento(
2190 HTrapAllocationMemento* instr) {
2191 LOperand* object = UseRegister(instr->object());
2192 LOperand* temp = TempRegister();
2193 LTrapAllocationMemento* result =
2194 new(zone()) LTrapAllocationMemento(object, temp);
2195 return AssignEnvironment(result);
2196}
2197
2198
2199LInstruction* LChunkBuilder::DoMaybeGrowElements(HMaybeGrowElements* instr) {
2200 info()->MarkAsDeferredCalling();
2201 LOperand* context = UseFixed(instr->context(), cp);
2202 LOperand* object = Use(instr->object());
2203 LOperand* elements = Use(instr->elements());
2204 LOperand* key = UseRegisterOrConstant(instr->key());
2205 LOperand* current_capacity = UseRegisterOrConstant(instr->current_capacity());
2206
2207 LMaybeGrowElements* result = new (zone())
2208 LMaybeGrowElements(context, object, elements, key, current_capacity);
2209 DefineFixed(result, v0);
2210 return AssignPointerMap(AssignEnvironment(result));
2211}
2212
2213
2214LInstruction* LChunkBuilder::DoStoreNamedField(HStoreNamedField* instr) {
2215 bool is_in_object = instr->access().IsInobject();
2216 bool needs_write_barrier = instr->NeedsWriteBarrier();
2217 bool needs_write_barrier_for_map = instr->has_transition() &&
2218 instr->NeedsWriteBarrierForMap();
2219
2220 LOperand* obj;
2221 if (needs_write_barrier) {
2222 obj = is_in_object
2223 ? UseRegister(instr->object())
2224 : UseTempRegister(instr->object());
2225 } else {
2226 obj = needs_write_barrier_for_map
2227 ? UseRegister(instr->object())
2228 : UseRegisterAtStart(instr->object());
2229 }
2230
2231 LOperand* val;
2232 if (needs_write_barrier) {
2233 val = UseTempRegister(instr->value());
2234 } else if (instr->field_representation().IsDouble()) {
2235 val = UseRegisterAtStart(instr->value());
2236 } else {
2237 val = UseRegister(instr->value());
2238 }
2239
2240 // We need a temporary register for write barrier of the map field.
2241 LOperand* temp = needs_write_barrier_for_map ? TempRegister() : NULL;
2242
2243 return new(zone()) LStoreNamedField(obj, val, temp);
2244}
2245
2246
2247LInstruction* LChunkBuilder::DoStoreNamedGeneric(HStoreNamedGeneric* instr) {
2248 LOperand* context = UseFixed(instr->context(), cp);
2249 LOperand* obj =
2250 UseFixed(instr->object(), StoreDescriptor::ReceiverRegister());
2251 LOperand* val = UseFixed(instr->value(), StoreDescriptor::ValueRegister());
2252 LOperand* slot = NULL;
2253 LOperand* vector = NULL;
2254 if (instr->HasVectorAndSlot()) {
2255 slot = FixedTemp(VectorStoreICDescriptor::SlotRegister());
2256 vector = FixedTemp(VectorStoreICDescriptor::VectorRegister());
2257 }
2258
2259 LStoreNamedGeneric* result =
2260 new (zone()) LStoreNamedGeneric(context, obj, val, slot, vector);
2261 return MarkAsCall(result, instr);
2262}
2263
2264
2265LInstruction* LChunkBuilder::DoStringAdd(HStringAdd* instr) {
2266 LOperand* context = UseFixed(instr->context(), cp);
2267 LOperand* left = UseFixed(instr->left(), a1);
2268 LOperand* right = UseFixed(instr->right(), a0);
2269 return MarkAsCall(
2270 DefineFixed(new(zone()) LStringAdd(context, left, right), v0),
2271 instr);
2272}
2273
2274
2275LInstruction* LChunkBuilder::DoStringCharCodeAt(HStringCharCodeAt* instr) {
2276 LOperand* string = UseTempRegister(instr->string());
2277 LOperand* index = UseTempRegister(instr->index());
2278 LOperand* context = UseAny(instr->context());
2279 LStringCharCodeAt* result =
2280 new(zone()) LStringCharCodeAt(context, string, index);
2281 return AssignPointerMap(DefineAsRegister(result));
2282}
2283
2284
2285LInstruction* LChunkBuilder::DoStringCharFromCode(HStringCharFromCode* instr) {
2286 LOperand* char_code = UseRegister(instr->value());
2287 LOperand* context = UseAny(instr->context());
2288 LStringCharFromCode* result =
2289 new(zone()) LStringCharFromCode(context, char_code);
2290 return AssignPointerMap(DefineAsRegister(result));
2291}
2292
2293
2294LInstruction* LChunkBuilder::DoAllocate(HAllocate* instr) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002295 LOperand* size = UseRegisterOrConstant(instr->size());
2296 LOperand* temp1 = TempRegister();
2297 LOperand* temp2 = TempRegister();
Ben Murdochc5610432016-08-08 18:44:38 +01002298 if (instr->IsAllocationFolded()) {
2299 LFastAllocate* result = new (zone()) LFastAllocate(size, temp1, temp2);
2300 return DefineAsRegister(result);
2301 } else {
2302 info()->MarkAsDeferredCalling();
2303 LOperand* context = UseAny(instr->context());
2304 LAllocate* result = new (zone()) LAllocate(context, size, temp1, temp2);
2305 return AssignPointerMap(DefineAsRegister(result));
2306 }
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002307}
2308
2309
2310LInstruction* LChunkBuilder::DoOsrEntry(HOsrEntry* instr) {
2311 DCHECK(argument_count_ == 0);
2312 allocator_->MarkAsOsrEntry();
2313 current_block_->last_environment()->set_ast_id(instr->ast_id());
2314 return AssignEnvironment(new(zone()) LOsrEntry);
2315}
2316
2317
2318LInstruction* LChunkBuilder::DoParameter(HParameter* instr) {
2319 LParameter* result = new(zone()) LParameter;
2320 if (instr->kind() == HParameter::STACK_PARAMETER) {
2321 int spill_index = chunk()->GetParameterStackSlot(instr->index());
2322 return DefineAsSpilled(result, spill_index);
2323 } else {
2324 DCHECK(info()->IsStub());
Ben Murdoch097c5b22016-05-18 11:27:45 +01002325 CallInterfaceDescriptor descriptor = graph()->descriptor();
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002326 int index = static_cast<int>(instr->index());
2327 Register reg = descriptor.GetRegisterParameter(index);
2328 return DefineFixed(result, reg);
2329 }
2330}
2331
2332
2333LInstruction* LChunkBuilder::DoUnknownOSRValue(HUnknownOSRValue* instr) {
2334 // Use an index that corresponds to the location in the unoptimized frame,
2335 // which the optimized frame will subsume.
2336 int env_index = instr->index();
2337 int spill_index = 0;
2338 if (instr->environment()->is_parameter_index(env_index)) {
2339 spill_index = chunk()->GetParameterStackSlot(env_index);
2340 } else {
2341 spill_index = env_index - instr->environment()->first_local_index();
2342 if (spill_index > LUnallocated::kMaxFixedSlotIndex) {
2343 Retry(kTooManySpillSlotsNeededForOSR);
2344 spill_index = 0;
2345 }
Ben Murdoch097c5b22016-05-18 11:27:45 +01002346 spill_index += StandardFrameConstants::kFixedSlotCount;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002347 }
2348 return DefineAsSpilled(new(zone()) LUnknownOSRValue, spill_index);
2349}
2350
2351
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002352LInstruction* LChunkBuilder::DoArgumentsObject(HArgumentsObject* instr) {
2353 // There are no real uses of the arguments object.
2354 // arguments.length and element access are supported directly on
2355 // stack arguments, and any real arguments object use causes a bailout.
2356 // So this value is never used.
2357 return NULL;
2358}
2359
2360
2361LInstruction* LChunkBuilder::DoCapturedObject(HCapturedObject* instr) {
2362 instr->ReplayEnvironment(current_block_->last_environment());
2363
2364 // There are no real uses of a captured object.
2365 return NULL;
2366}
2367
2368
2369LInstruction* LChunkBuilder::DoAccessArgumentsAt(HAccessArgumentsAt* instr) {
2370 info()->MarkAsRequiresFrame();
2371 LOperand* args = UseRegister(instr->arguments());
2372 LOperand* length = UseRegisterOrConstantAtStart(instr->length());
2373 LOperand* index = UseRegisterOrConstantAtStart(instr->index());
2374 return DefineAsRegister(new(zone()) LAccessArgumentsAt(args, length, index));
2375}
2376
2377
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002378LInstruction* LChunkBuilder::DoTypeof(HTypeof* instr) {
2379 LOperand* context = UseFixed(instr->context(), cp);
2380 LOperand* value = UseFixed(instr->value(), a3);
2381 LTypeof* result = new (zone()) LTypeof(context, value);
2382 return MarkAsCall(DefineFixed(result, v0), instr);
2383}
2384
2385
2386LInstruction* LChunkBuilder::DoTypeofIsAndBranch(HTypeofIsAndBranch* instr) {
2387 return new(zone()) LTypeofIsAndBranch(UseTempRegister(instr->value()));
2388}
2389
2390
2391LInstruction* LChunkBuilder::DoSimulate(HSimulate* instr) {
2392 instr->ReplayEnvironment(current_block_->last_environment());
2393 return NULL;
2394}
2395
2396
2397LInstruction* LChunkBuilder::DoStackCheck(HStackCheck* instr) {
2398 if (instr->is_function_entry()) {
2399 LOperand* context = UseFixed(instr->context(), cp);
2400 return MarkAsCall(new(zone()) LStackCheck(context), instr);
2401 } else {
2402 DCHECK(instr->is_backwards_branch());
2403 LOperand* context = UseAny(instr->context());
2404 return AssignEnvironment(
2405 AssignPointerMap(new(zone()) LStackCheck(context)));
2406 }
2407}
2408
2409
2410LInstruction* LChunkBuilder::DoEnterInlined(HEnterInlined* instr) {
2411 HEnvironment* outer = current_block_->last_environment();
2412 outer->set_ast_id(instr->ReturnId());
2413 HConstant* undefined = graph()->GetConstantUndefined();
Ben Murdochda12d292016-06-02 14:46:10 +01002414 HEnvironment* inner = outer->CopyForInlining(
2415 instr->closure(), instr->arguments_count(), instr->function(), undefined,
2416 instr->inlining_kind(), instr->syntactic_tail_call_mode());
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002417 // Only replay binding of arguments object if it wasn't removed from graph.
2418 if (instr->arguments_var() != NULL && instr->arguments_object()->IsLinked()) {
2419 inner->Bind(instr->arguments_var(), instr->arguments_object());
2420 }
2421 inner->BindContext(instr->closure_context());
2422 inner->set_entry(instr);
2423 current_block_->UpdateEnvironment(inner);
2424 chunk_->AddInlinedFunction(instr->shared());
2425 return NULL;
2426}
2427
2428
2429LInstruction* LChunkBuilder::DoLeaveInlined(HLeaveInlined* instr) {
2430 LInstruction* pop = NULL;
2431
2432 HEnvironment* env = current_block_->last_environment();
2433
2434 if (env->entry()->arguments_pushed()) {
2435 int argument_count = env->arguments_environment()->parameter_count();
2436 pop = new(zone()) LDrop(argument_count);
2437 DCHECK(instr->argument_delta() == -argument_count);
2438 }
2439
2440 HEnvironment* outer = current_block_->last_environment()->
2441 DiscardInlined(false);
2442 current_block_->UpdateEnvironment(outer);
2443
2444 return pop;
2445}
2446
2447
2448LInstruction* LChunkBuilder::DoForInPrepareMap(HForInPrepareMap* instr) {
2449 LOperand* context = UseFixed(instr->context(), cp);
2450 LOperand* object = UseFixed(instr->enumerable(), a0);
2451 LForInPrepareMap* result = new(zone()) LForInPrepareMap(context, object);
2452 return MarkAsCall(DefineFixed(result, v0), instr, CAN_DEOPTIMIZE_EAGERLY);
2453}
2454
2455
2456LInstruction* LChunkBuilder::DoForInCacheArray(HForInCacheArray* instr) {
2457 LOperand* map = UseRegister(instr->map());
2458 return AssignEnvironment(DefineAsRegister(new(zone()) LForInCacheArray(map)));
2459}
2460
2461
2462LInstruction* LChunkBuilder::DoCheckMapValue(HCheckMapValue* instr) {
2463 LOperand* value = UseRegisterAtStart(instr->value());
2464 LOperand* map = UseRegisterAtStart(instr->map());
2465 return AssignEnvironment(new(zone()) LCheckMapValue(value, map));
2466}
2467
2468
2469LInstruction* LChunkBuilder::DoLoadFieldByIndex(HLoadFieldByIndex* instr) {
2470 LOperand* object = UseRegister(instr->object());
2471 LOperand* index = UseTempRegister(instr->index());
2472 LLoadFieldByIndex* load = new(zone()) LLoadFieldByIndex(object, index);
2473 LInstruction* result = DefineSameAsFirst(load);
2474 return AssignPointerMap(result);
2475}
2476
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002477} // namespace internal
2478} // namespace v8
2479
2480#endif // V8_TARGET_ARCH_MIPS64