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

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

Powered by Google App Engine
This is Rietveld 408576698