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