Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(727)

Side by Side Diff: src/mips/lithium-mips.cc

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

Powered by Google App Engine
This is Rietveld 408576698