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