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

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

Powered by Google App Engine
This is Rietveld 408576698