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