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