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