blob: 1c4e1da3fbca3d189ba7d8f14fa2fab4b361dae6 [file] [log] [blame]
erik.corry@gmail.comf2038fb2012-01-16 11:42:08 +00001// Copyright 2012 the V8 project authors. All rights reserved.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002// Redistribution and use in source and binary forms, with or without
3// modification, are permitted provided that the following conditions are
4// met:
5//
6// * Redistributions of source code must retain the above copyright
7// notice, this list of conditions and the following disclaimer.
8// * Redistributions in binary form must reproduce the above
9// copyright notice, this list of conditions and the following
10// disclaimer in the documentation and/or other materials provided
11// with the distribution.
12// * Neither the name of Google Inc. nor the names of its
13// contributors may be used to endorse or promote products derived
14// from this software without specific prior written permission.
15//
16// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
28#include "v8.h"
29
30#include "lithium-allocator-inl.h"
31#include "mips/lithium-mips.h"
32#include "mips/lithium-codegen-mips.h"
33
34namespace v8 {
35namespace internal {
36
37#define DEFINE_COMPILE(type) \
38 void L##type::CompileToNative(LCodeGen* generator) { \
39 generator->Do##type(this); \
40 }
41LITHIUM_CONCRETE_INSTRUCTION_LIST(DEFINE_COMPILE)
42#undef DEFINE_COMPILE
43
44LOsrEntry::LOsrEntry() {
45 for (int i = 0; i < Register::kNumAllocatableRegisters; ++i) {
46 register_spills_[i] = NULL;
47 }
48 for (int i = 0; i < DoubleRegister::kNumAllocatableRegisters; ++i) {
49 double_register_spills_[i] = NULL;
50 }
51}
52
53
54void LOsrEntry::MarkSpilledRegister(int allocation_index,
55 LOperand* spill_operand) {
56 ASSERT(spill_operand->IsStackSlot());
57 ASSERT(register_spills_[allocation_index] == NULL);
58 register_spills_[allocation_index] = spill_operand;
59}
60
61
62#ifdef DEBUG
63void LInstruction::VerifyCall() {
64 // Call instructions can use only fixed registers as temporaries and
65 // outputs because all registers are blocked by the calling convention.
66 // Inputs operands must use a fixed register or use-at-start policy or
67 // a non-register policy.
68 ASSERT(Output() == NULL ||
69 LUnallocated::cast(Output())->HasFixedPolicy() ||
70 !LUnallocated::cast(Output())->HasRegisterPolicy());
71 for (UseIterator it(this); !it.Done(); it.Advance()) {
72 LUnallocated* operand = LUnallocated::cast(it.Current());
73 ASSERT(operand->HasFixedPolicy() ||
74 operand->IsUsedAtStart());
75 }
76 for (TempIterator it(this); !it.Done(); it.Advance()) {
77 LUnallocated* operand = LUnallocated::cast(it.Current());
78 ASSERT(operand->HasFixedPolicy() ||!operand->HasRegisterPolicy());
79 }
80}
81#endif
82
83
84void LOsrEntry::MarkSpilledDoubleRegister(int allocation_index,
85 LOperand* spill_operand) {
86 ASSERT(spill_operand->IsDoubleStackSlot());
87 ASSERT(double_register_spills_[allocation_index] == NULL);
88 double_register_spills_[allocation_index] = spill_operand;
89}
90
91
92void LInstruction::PrintTo(StringStream* stream) {
93 stream->Add("%s ", this->Mnemonic());
94
95 PrintOutputOperandTo(stream);
96
97 PrintDataTo(stream);
98
99 if (HasEnvironment()) {
100 stream->Add(" ");
101 environment()->PrintTo(stream);
102 }
103
104 if (HasPointerMap()) {
105 stream->Add(" ");
106 pointer_map()->PrintTo(stream);
107 }
108}
109
110
111template<int R, int I, int T>
112void LTemplateInstruction<R, I, T>::PrintDataTo(StringStream* stream) {
113 stream->Add("= ");
114 for (int i = 0; i < inputs_.length(); i++) {
115 if (i > 0) stream->Add(" ");
116 inputs_[i]->PrintTo(stream);
117 }
118}
119
120
121template<int R, int I, int T>
122void LTemplateInstruction<R, I, T>::PrintOutputOperandTo(StringStream* stream) {
123 for (int i = 0; i < results_.length(); i++) {
124 if (i > 0) stream->Add(" ");
125 results_[i]->PrintTo(stream);
126 }
127}
128
129
130void LLabel::PrintDataTo(StringStream* stream) {
131 LGap::PrintDataTo(stream);
132 LLabel* rep = replacement();
133 if (rep != NULL) {
134 stream->Add(" Dead block replaced with B%d", rep->block_id());
135 }
136}
137
138
139bool LGap::IsRedundant() const {
140 for (int i = 0; i < 4; i++) {
141 if (parallel_moves_[i] != NULL && !parallel_moves_[i]->IsRedundant()) {
142 return false;
143 }
144 }
145
146 return true;
147}
148
149
150void LGap::PrintDataTo(StringStream* stream) {
151 for (int i = 0; i < 4; i++) {
152 stream->Add("(");
153 if (parallel_moves_[i] != NULL) {
154 parallel_moves_[i]->PrintDataTo(stream);
155 }
156 stream->Add(") ");
157 }
158}
159
160
161const char* LArithmeticD::Mnemonic() const {
162 switch (op()) {
163 case Token::ADD: return "add-d";
164 case Token::SUB: return "sub-d";
165 case Token::MUL: return "mul-d";
166 case Token::DIV: return "div-d";
167 case Token::MOD: return "mod-d";
168 default:
169 UNREACHABLE();
170 return NULL;
171 }
172}
173
174
175const char* LArithmeticT::Mnemonic() const {
176 switch (op()) {
177 case Token::ADD: return "add-t";
178 case Token::SUB: return "sub-t";
179 case Token::MUL: return "mul-t";
180 case Token::MOD: return "mod-t";
181 case Token::DIV: return "div-t";
182 case Token::BIT_AND: return "bit-and-t";
183 case Token::BIT_OR: return "bit-or-t";
184 case Token::BIT_XOR: return "bit-xor-t";
185 case Token::SHL: return "sll-t";
186 case Token::SAR: return "sra-t";
187 case Token::SHR: return "srl-t";
188 default:
189 UNREACHABLE();
190 return NULL;
191 }
192}
193
194
195void LGoto::PrintDataTo(StringStream* stream) {
196 stream->Add("B%d", block_id());
197}
198
199
200void LBranch::PrintDataTo(StringStream* stream) {
201 stream->Add("B%d | B%d on ", true_block_id(), false_block_id());
202 InputAt(0)->PrintTo(stream);
203}
204
205
206void LCmpIDAndBranch::PrintDataTo(StringStream* stream) {
207 stream->Add("if ");
208 InputAt(0)->PrintTo(stream);
209 stream->Add(" %s ", Token::String(op()));
210 InputAt(1)->PrintTo(stream);
211 stream->Add(" then B%d else B%d", true_block_id(), false_block_id());
212}
213
214
215void LIsNilAndBranch::PrintDataTo(StringStream* stream) {
216 stream->Add("if ");
217 InputAt(0)->PrintTo(stream);
218 stream->Add(kind() == kStrictEquality ? " === " : " == ");
219 stream->Add(nil() == kNullValue ? "null" : "undefined");
220 stream->Add(" then B%d else B%d", true_block_id(), false_block_id());
221}
222
223
224void LIsObjectAndBranch::PrintDataTo(StringStream* stream) {
225 stream->Add("if is_object(");
226 InputAt(0)->PrintTo(stream);
227 stream->Add(") then B%d else B%d", true_block_id(), false_block_id());
228}
229
230
mstarzinger@chromium.orgf8c6bd52011-11-23 12:13:52 +0000231void LIsStringAndBranch::PrintDataTo(StringStream* stream) {
232 stream->Add("if is_string(");
233 InputAt(0)->PrintTo(stream);
234 stream->Add(") then B%d else B%d", true_block_id(), false_block_id());
235}
236
237
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000238void LIsSmiAndBranch::PrintDataTo(StringStream* stream) {
239 stream->Add("if is_smi(");
240 InputAt(0)->PrintTo(stream);
241 stream->Add(") then B%d else B%d", true_block_id(), false_block_id());
242}
243
244
245void LIsUndetectableAndBranch::PrintDataTo(StringStream* stream) {
246 stream->Add("if is_undetectable(");
247 InputAt(0)->PrintTo(stream);
248 stream->Add(") then B%d else B%d", true_block_id(), false_block_id());
249}
250
251
mstarzinger@chromium.orgf8c6bd52011-11-23 12:13:52 +0000252void LStringCompareAndBranch::PrintDataTo(StringStream* stream) {
253 stream->Add("if string_compare(");
254 InputAt(0)->PrintTo(stream);
255 InputAt(1)->PrintTo(stream);
256 stream->Add(") then B%d else B%d", true_block_id(), false_block_id());
257}
258
259
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000260void LHasInstanceTypeAndBranch::PrintDataTo(StringStream* stream) {
261 stream->Add("if has_instance_type(");
262 InputAt(0)->PrintTo(stream);
263 stream->Add(") then B%d else B%d", true_block_id(), false_block_id());
264}
265
266
267void LHasCachedArrayIndexAndBranch::PrintDataTo(StringStream* stream) {
268 stream->Add("if has_cached_array_index(");
269 InputAt(0)->PrintTo(stream);
270 stream->Add(") then B%d else B%d", true_block_id(), false_block_id());
271}
272
273
274void LClassOfTestAndBranch::PrintDataTo(StringStream* stream) {
275 stream->Add("if class_of_test(");
276 InputAt(0)->PrintTo(stream);
277 stream->Add(", \"%o\") then B%d else B%d",
278 *hydrogen()->class_name(),
279 true_block_id(),
280 false_block_id());
281}
282
283
284void LTypeofIsAndBranch::PrintDataTo(StringStream* stream) {
285 stream->Add("if typeof ");
286 InputAt(0)->PrintTo(stream);
287 stream->Add(" == \"%s\" then B%d else B%d",
288 *hydrogen()->type_literal()->ToCString(),
289 true_block_id(), false_block_id());
290}
291
292
293void LCallConstantFunction::PrintDataTo(StringStream* stream) {
294 stream->Add("#%d / ", arity());
295}
296
297
298void LUnaryMathOperation::PrintDataTo(StringStream* stream) {
299 stream->Add("/%s ", hydrogen()->OpName());
300 InputAt(0)->PrintTo(stream);
301}
302
303
304void LLoadContextSlot::PrintDataTo(StringStream* stream) {
305 InputAt(0)->PrintTo(stream);
306 stream->Add("[%d]", slot_index());
307}
308
309
310void LStoreContextSlot::PrintDataTo(StringStream* stream) {
311 InputAt(0)->PrintTo(stream);
312 stream->Add("[%d] <- ", slot_index());
313 InputAt(1)->PrintTo(stream);
314}
315
316
317void LInvokeFunction::PrintDataTo(StringStream* stream) {
318 stream->Add("= ");
319 InputAt(0)->PrintTo(stream);
320 stream->Add(" #%d / ", arity());
321}
322
323
324void LCallKeyed::PrintDataTo(StringStream* stream) {
325 stream->Add("[a2] #%d / ", arity());
326}
327
328
329void LCallNamed::PrintDataTo(StringStream* stream) {
330 SmartArrayPointer<char> name_string = name()->ToCString();
331 stream->Add("%s #%d / ", *name_string, arity());
332}
333
334
335void LCallGlobal::PrintDataTo(StringStream* stream) {
336 SmartArrayPointer<char> name_string = name()->ToCString();
337 stream->Add("%s #%d / ", *name_string, arity());
338}
339
340
341void LCallKnownGlobal::PrintDataTo(StringStream* stream) {
342 stream->Add("#%d / ", arity());
343}
344
345
346void LCallNew::PrintDataTo(StringStream* stream) {
347 stream->Add("= ");
348 InputAt(0)->PrintTo(stream);
349 stream->Add(" #%d / ", arity());
350}
351
352
353void LAccessArgumentsAt::PrintDataTo(StringStream* stream) {
354 arguments()->PrintTo(stream);
355
356 stream->Add(" length ");
357 length()->PrintTo(stream);
358
359 stream->Add(" index ");
360 index()->PrintTo(stream);
361}
362
363
364void LStoreNamedField::PrintDataTo(StringStream* stream) {
365 object()->PrintTo(stream);
366 stream->Add(".");
367 stream->Add(*String::cast(*name())->ToCString());
368 stream->Add(" <- ");
369 value()->PrintTo(stream);
370}
371
372
373void LStoreNamedGeneric::PrintDataTo(StringStream* stream) {
374 object()->PrintTo(stream);
375 stream->Add(".");
376 stream->Add(*String::cast(*name())->ToCString());
377 stream->Add(" <- ");
378 value()->PrintTo(stream);
379}
380
381
382void LStoreKeyedFastElement::PrintDataTo(StringStream* stream) {
383 object()->PrintTo(stream);
384 stream->Add("[");
385 key()->PrintTo(stream);
386 stream->Add("] <- ");
387 value()->PrintTo(stream);
388}
389
390
391void LStoreKeyedFastDoubleElement::PrintDataTo(StringStream* stream) {
392 elements()->PrintTo(stream);
393 stream->Add("[");
394 key()->PrintTo(stream);
395 stream->Add("] <- ");
396 value()->PrintTo(stream);
397}
398
399
400void LStoreKeyedGeneric::PrintDataTo(StringStream* stream) {
401 object()->PrintTo(stream);
402 stream->Add("[");
403 key()->PrintTo(stream);
404 stream->Add("] <- ");
405 value()->PrintTo(stream);
406}
407
408
409void LTransitionElementsKind::PrintDataTo(StringStream* stream) {
410 object()->PrintTo(stream);
411 stream->Add(" %p -> %p", *original_map(), *transitioned_map());
412}
413
414
415LChunk::LChunk(CompilationInfo* info, HGraph* graph)
416 : spill_slot_count_(0),
417 info_(info),
418 graph_(graph),
419 instructions_(32),
420 pointer_maps_(8),
421 inlined_closures_(1) {
422}
423
424
425int LChunk::GetNextSpillIndex(bool is_double) {
426 // Skip a slot if for a double-width slot.
427 if (is_double) spill_slot_count_++;
428 return spill_slot_count_++;
429}
430
431
432LOperand* LChunk::GetNextSpillSlot(bool is_double) {
433 int index = GetNextSpillIndex(is_double);
434 if (is_double) {
435 return LDoubleStackSlot::Create(index);
436 } else {
437 return LStackSlot::Create(index);
438 }
439}
440
441
442void LChunk::MarkEmptyBlocks() {
ulan@chromium.org9a21ec42012-03-06 08:42:24 +0000443 HPhase phase("L_Mark empty blocks", this);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000444 for (int i = 0; i < graph()->blocks()->length(); ++i) {
445 HBasicBlock* block = graph()->blocks()->at(i);
446 int first = block->first_instruction_index();
447 int last = block->last_instruction_index();
448 LInstruction* first_instr = instructions()->at(first);
449 LInstruction* last_instr = instructions()->at(last);
450
451 LLabel* label = LLabel::cast(first_instr);
452 if (last_instr->IsGoto()) {
453 LGoto* goto_instr = LGoto::cast(last_instr);
454 if (label->IsRedundant() &&
455 !label->is_loop_header()) {
456 bool can_eliminate = true;
457 for (int i = first + 1; i < last && can_eliminate; ++i) {
458 LInstruction* cur = instructions()->at(i);
459 if (cur->IsGap()) {
460 LGap* gap = LGap::cast(cur);
461 if (!gap->IsRedundant()) {
462 can_eliminate = false;
463 }
464 } else {
465 can_eliminate = false;
466 }
467 }
468
469 if (can_eliminate) {
470 label->set_replacement(GetLabel(goto_instr->block_id()));
471 }
472 }
473 }
474 }
475}
476
477
478void LChunk::AddInstruction(LInstruction* instr, HBasicBlock* block) {
ulan@chromium.org812308e2012-02-29 15:58:45 +0000479 LInstructionGap* gap = new(graph_->zone()) LInstructionGap(block);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000480 int index = -1;
481 if (instr->IsControl()) {
482 instructions_.Add(gap);
483 index = instructions_.length();
484 instructions_.Add(instr);
485 } else {
486 index = instructions_.length();
487 instructions_.Add(instr);
488 instructions_.Add(gap);
489 }
490 if (instr->HasPointerMap()) {
491 pointer_maps_.Add(instr->pointer_map());
492 instr->pointer_map()->set_lithium_position(index);
493 }
494}
495
496
497LConstantOperand* LChunk::DefineConstantOperand(HConstant* constant) {
498 return LConstantOperand::Create(constant->id());
499}
500
501
502int LChunk::GetParameterStackSlot(int index) const {
503 // The receiver is at index 0, the first parameter at index 1, so we
504 // shift all parameter indexes down by the number of parameters, and
505 // make sure they end up negative so they are distinguishable from
506 // spill slots.
507 int result = index - info()->scope()->num_parameters() - 1;
508 ASSERT(result < 0);
509 return result;
510}
511
512// A parameter relative to ebp in the arguments stub.
513int LChunk::ParameterAt(int index) {
514 ASSERT(-1 <= index); // -1 is the receiver.
515 return (1 + info()->scope()->num_parameters() - index) *
516 kPointerSize;
517}
518
519
520LGap* LChunk::GetGapAt(int index) const {
521 return LGap::cast(instructions_[index]);
522}
523
524
525bool LChunk::IsGapAt(int index) const {
526 return instructions_[index]->IsGap();
527}
528
529
530int LChunk::NearestGapPos(int index) const {
531 while (!IsGapAt(index)) index--;
532 return index;
533}
534
535
536void LChunk::AddGapMove(int index, LOperand* from, LOperand* to) {
537 GetGapAt(index)->GetOrCreateParallelMove(LGap::START)->AddMove(from, to);
538}
539
540
541Handle<Object> LChunk::LookupLiteral(LConstantOperand* operand) const {
542 return HConstant::cast(graph_->LookupValue(operand->index()))->handle();
543}
544
545
546Representation LChunk::LookupLiteralRepresentation(
547 LConstantOperand* operand) const {
548 return graph_->LookupValue(operand->index())->representation();
549}
550
551
552LChunk* LChunkBuilder::Build() {
553 ASSERT(is_unused());
ulan@chromium.org812308e2012-02-29 15:58:45 +0000554 chunk_ = new(zone()) LChunk(info(), graph());
ulan@chromium.org9a21ec42012-03-06 08:42:24 +0000555 HPhase phase("L_Building chunk", chunk_);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000556 status_ = BUILDING;
557 const ZoneList<HBasicBlock*>* blocks = graph()->blocks();
558 for (int i = 0; i < blocks->length(); i++) {
559 HBasicBlock* next = NULL;
560 if (i < blocks->length() - 1) next = blocks->at(i + 1);
561 DoBasicBlock(blocks->at(i), next);
562 if (is_aborted()) return NULL;
563 }
564 status_ = DONE;
565 return chunk_;
566}
567
568
569void LChunkBuilder::Abort(const char* format, ...) {
570 if (FLAG_trace_bailout) {
571 SmartArrayPointer<char> name(
572 info()->shared_info()->DebugName()->ToCString());
573 PrintF("Aborting LChunk building in @\"%s\": ", *name);
574 va_list arguments;
575 va_start(arguments, format);
576 OS::VPrint(format, arguments);
577 va_end(arguments);
578 PrintF("\n");
579 }
580 status_ = ABORTED;
581}
582
583
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000584LUnallocated* LChunkBuilder::ToUnallocated(Register reg) {
ulan@chromium.org812308e2012-02-29 15:58:45 +0000585 return new(zone()) LUnallocated(LUnallocated::FIXED_REGISTER,
586 Register::ToAllocationIndex(reg));
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000587}
588
589
590LUnallocated* LChunkBuilder::ToUnallocated(DoubleRegister reg) {
ulan@chromium.org812308e2012-02-29 15:58:45 +0000591 return new(zone()) LUnallocated(LUnallocated::FIXED_DOUBLE_REGISTER,
592 DoubleRegister::ToAllocationIndex(reg));
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000593}
594
595
596LOperand* LChunkBuilder::UseFixed(HValue* value, Register fixed_register) {
597 return Use(value, ToUnallocated(fixed_register));
598}
599
600
601LOperand* LChunkBuilder::UseFixedDouble(HValue* value, DoubleRegister reg) {
602 return Use(value, ToUnallocated(reg));
603}
604
605
606LOperand* LChunkBuilder::UseRegister(HValue* value) {
ulan@chromium.org812308e2012-02-29 15:58:45 +0000607 return Use(value, new(zone()) LUnallocated(LUnallocated::MUST_HAVE_REGISTER));
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000608}
609
610
611LOperand* LChunkBuilder::UseRegisterAtStart(HValue* value) {
612 return Use(value,
ulan@chromium.org812308e2012-02-29 15:58:45 +0000613 new(zone()) LUnallocated(LUnallocated::MUST_HAVE_REGISTER,
614 LUnallocated::USED_AT_START));
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000615}
616
617
618LOperand* LChunkBuilder::UseTempRegister(HValue* value) {
ulan@chromium.org812308e2012-02-29 15:58:45 +0000619 return Use(value, new(zone()) LUnallocated(LUnallocated::WRITABLE_REGISTER));
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000620}
621
622
623LOperand* LChunkBuilder::Use(HValue* value) {
ulan@chromium.org812308e2012-02-29 15:58:45 +0000624 return Use(value, new(zone()) LUnallocated(LUnallocated::NONE));
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000625}
626
627
628LOperand* LChunkBuilder::UseAtStart(HValue* value) {
ulan@chromium.org812308e2012-02-29 15:58:45 +0000629 return Use(value, new(zone()) LUnallocated(LUnallocated::NONE,
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000630 LUnallocated::USED_AT_START));
631}
632
633
634LOperand* LChunkBuilder::UseOrConstant(HValue* value) {
635 return value->IsConstant()
636 ? chunk_->DefineConstantOperand(HConstant::cast(value))
637 : Use(value);
638}
639
640
641LOperand* LChunkBuilder::UseOrConstantAtStart(HValue* value) {
642 return value->IsConstant()
643 ? chunk_->DefineConstantOperand(HConstant::cast(value))
644 : UseAtStart(value);
645}
646
647
648LOperand* LChunkBuilder::UseRegisterOrConstant(HValue* value) {
649 return value->IsConstant()
650 ? chunk_->DefineConstantOperand(HConstant::cast(value))
651 : UseRegister(value);
652}
653
654
655LOperand* LChunkBuilder::UseRegisterOrConstantAtStart(HValue* value) {
656 return value->IsConstant()
657 ? chunk_->DefineConstantOperand(HConstant::cast(value))
658 : UseRegisterAtStart(value);
659}
660
661
662LOperand* LChunkBuilder::UseAny(HValue* value) {
663 return value->IsConstant()
664 ? chunk_->DefineConstantOperand(HConstant::cast(value))
ulan@chromium.org812308e2012-02-29 15:58:45 +0000665 : Use(value, new(zone()) LUnallocated(LUnallocated::ANY));
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000666}
667
668
669LOperand* LChunkBuilder::Use(HValue* value, LUnallocated* operand) {
670 if (value->EmitAtUses()) {
671 HInstruction* instr = HInstruction::cast(value);
672 VisitInstruction(instr);
673 }
rossberg@chromium.org994edf62012-02-06 10:12:55 +0000674 operand->set_virtual_register(value->id());
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000675 return operand;
676}
677
678
679template<int I, int T>
680LInstruction* LChunkBuilder::Define(LTemplateInstruction<1, I, T>* instr,
681 LUnallocated* result) {
rossberg@chromium.org994edf62012-02-06 10:12:55 +0000682 result->set_virtual_register(current_instruction_->id());
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000683 instr->set_result(result);
684 return instr;
685}
686
687
688template<int I, int T>
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000689LInstruction* LChunkBuilder::DefineAsRegister(
690 LTemplateInstruction<1, I, T>* instr) {
ulan@chromium.org812308e2012-02-29 15:58:45 +0000691 return Define(instr,
692 new(zone()) LUnallocated(LUnallocated::MUST_HAVE_REGISTER));
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000693}
694
695
696template<int I, int T>
697LInstruction* LChunkBuilder::DefineAsSpilled(
698 LTemplateInstruction<1, I, T>* instr, int index) {
ulan@chromium.org812308e2012-02-29 15:58:45 +0000699 return Define(instr,
700 new(zone()) LUnallocated(LUnallocated::FIXED_SLOT, index));
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000701}
702
703
704template<int I, int T>
705LInstruction* LChunkBuilder::DefineSameAsFirst(
706 LTemplateInstruction<1, I, T>* instr) {
ulan@chromium.org812308e2012-02-29 15:58:45 +0000707 return Define(instr,
708 new(zone()) LUnallocated(LUnallocated::SAME_AS_FIRST_INPUT));
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000709}
710
711
712template<int I, int T>
713LInstruction* LChunkBuilder::DefineFixed(
714 LTemplateInstruction<1, I, T>* instr, Register reg) {
715 return Define(instr, ToUnallocated(reg));
716}
717
718
719template<int I, int T>
720LInstruction* LChunkBuilder::DefineFixedDouble(
721 LTemplateInstruction<1, I, T>* instr, DoubleRegister reg) {
722 return Define(instr, ToUnallocated(reg));
723}
724
725
726LInstruction* LChunkBuilder::AssignEnvironment(LInstruction* instr) {
727 HEnvironment* hydrogen_env = current_block_->last_environment();
728 int argument_index_accumulator = 0;
729 instr->set_environment(CreateEnvironment(hydrogen_env,
730 &argument_index_accumulator));
731 return instr;
732}
733
734
735LInstruction* LChunkBuilder::SetInstructionPendingDeoptimizationEnvironment(
736 LInstruction* instr, int ast_id) {
737 ASSERT(instruction_pending_deoptimization_environment_ == NULL);
738 ASSERT(pending_deoptimization_ast_id_ == AstNode::kNoNumber);
739 instruction_pending_deoptimization_environment_ = instr;
740 pending_deoptimization_ast_id_ = ast_id;
741 return instr;
742}
743
744
745void LChunkBuilder::ClearInstructionPendingDeoptimizationEnvironment() {
746 instruction_pending_deoptimization_environment_ = NULL;
747 pending_deoptimization_ast_id_ = AstNode::kNoNumber;
748}
749
750
751LInstruction* LChunkBuilder::MarkAsCall(LInstruction* instr,
752 HInstruction* hinstr,
753 CanDeoptimize can_deoptimize) {
754#ifdef DEBUG
755 instr->VerifyCall();
756#endif
757 instr->MarkAsCall();
758 instr = AssignPointerMap(instr);
759
760 if (hinstr->HasObservableSideEffects()) {
761 ASSERT(hinstr->next()->IsSimulate());
762 HSimulate* sim = HSimulate::cast(hinstr->next());
763 instr = SetInstructionPendingDeoptimizationEnvironment(
764 instr, sim->ast_id());
765 }
766
767 // If instruction does not have side-effects lazy deoptimization
768 // after the call will try to deoptimize to the point before the call.
769 // Thus we still need to attach environment to this call even if
770 // call sequence can not deoptimize eagerly.
771 bool needs_environment =
772 (can_deoptimize == CAN_DEOPTIMIZE_EAGERLY) ||
773 !hinstr->HasObservableSideEffects();
774 if (needs_environment && !instr->HasEnvironment()) {
775 instr = AssignEnvironment(instr);
776 }
777
778 return instr;
779}
780
781
782LInstruction* LChunkBuilder::MarkAsSaveDoubles(LInstruction* instr) {
783 instr->MarkAsSaveDoubles();
784 return instr;
785}
786
787
788LInstruction* LChunkBuilder::AssignPointerMap(LInstruction* instr) {
789 ASSERT(!instr->HasPointerMap());
ulan@chromium.org812308e2012-02-29 15:58:45 +0000790 instr->set_pointer_map(new(zone()) LPointerMap(position_));
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000791 return instr;
792}
793
794
795LUnallocated* LChunkBuilder::TempRegister() {
ulan@chromium.org812308e2012-02-29 15:58:45 +0000796 LUnallocated* operand =
797 new(zone()) LUnallocated(LUnallocated::MUST_HAVE_REGISTER);
rossberg@chromium.org994edf62012-02-06 10:12:55 +0000798 operand->set_virtual_register(allocator_->GetVirtualRegister());
799 if (!allocator_->AllocationOk()) Abort("Not enough virtual registers.");
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000800 return operand;
801}
802
803
804LOperand* LChunkBuilder::FixedTemp(Register reg) {
805 LUnallocated* operand = ToUnallocated(reg);
rossberg@chromium.org994edf62012-02-06 10:12:55 +0000806 ASSERT(operand->HasFixedPolicy());
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000807 return operand;
808}
809
810
811LOperand* LChunkBuilder::FixedTemp(DoubleRegister reg) {
812 LUnallocated* operand = ToUnallocated(reg);
rossberg@chromium.org994edf62012-02-06 10:12:55 +0000813 ASSERT(operand->HasFixedPolicy());
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000814 return operand;
815}
816
817
818LInstruction* LChunkBuilder::DoBlockEntry(HBlockEntry* instr) {
ulan@chromium.org812308e2012-02-29 15:58:45 +0000819 return new(zone()) LLabel(instr->block());
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000820}
821
822
823LInstruction* LChunkBuilder::DoSoftDeoptimize(HSoftDeoptimize* instr) {
ulan@chromium.org812308e2012-02-29 15:58:45 +0000824 return AssignEnvironment(new(zone()) LDeoptimize);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000825}
826
827
828LInstruction* LChunkBuilder::DoDeoptimize(HDeoptimize* instr) {
ulan@chromium.org812308e2012-02-29 15:58:45 +0000829 return AssignEnvironment(new(zone()) LDeoptimize);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000830}
831
832
833LInstruction* LChunkBuilder::DoShift(Token::Value op,
834 HBitwiseBinaryOperation* instr) {
835 if (instr->representation().IsTagged()) {
836 ASSERT(instr->left()->representation().IsTagged());
837 ASSERT(instr->right()->representation().IsTagged());
838
839 LOperand* left = UseFixed(instr->left(), a1);
840 LOperand* right = UseFixed(instr->right(), a0);
ulan@chromium.org812308e2012-02-29 15:58:45 +0000841 LArithmeticT* result = new(zone()) LArithmeticT(op, left, right);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000842 return MarkAsCall(DefineFixed(result, v0), instr);
843 }
844
845 ASSERT(instr->representation().IsInteger32());
846 ASSERT(instr->left()->representation().IsInteger32());
847 ASSERT(instr->right()->representation().IsInteger32());
848 LOperand* left = UseRegisterAtStart(instr->left());
849
850 HValue* right_value = instr->right();
851 LOperand* right = NULL;
852 int constant_value = 0;
853 if (right_value->IsConstant()) {
854 HConstant* constant = HConstant::cast(right_value);
855 right = chunk_->DefineConstantOperand(constant);
856 constant_value = constant->Integer32Value() & 0x1f;
857 } else {
858 right = UseRegisterAtStart(right_value);
859 }
860
861 // Shift operations can only deoptimize if we do a logical shift
862 // by 0 and the result cannot be truncated to int32.
863 bool may_deopt = (op == Token::SHR && constant_value == 0);
864 bool does_deopt = false;
865 if (may_deopt) {
866 for (HUseIterator it(instr->uses()); !it.Done(); it.Advance()) {
867 if (!it.value()->CheckFlag(HValue::kTruncatingToInt32)) {
868 does_deopt = true;
869 break;
870 }
871 }
872 }
873
874 LInstruction* result =
ulan@chromium.org812308e2012-02-29 15:58:45 +0000875 DefineAsRegister(new(zone()) LShiftI(op, left, right, does_deopt));
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000876 return does_deopt ? AssignEnvironment(result) : result;
877}
878
879
880LInstruction* LChunkBuilder::DoArithmeticD(Token::Value op,
881 HArithmeticBinaryOperation* instr) {
882 ASSERT(instr->representation().IsDouble());
883 ASSERT(instr->left()->representation().IsDouble());
884 ASSERT(instr->right()->representation().IsDouble());
885 ASSERT(op != Token::MOD);
886 LOperand* left = UseRegisterAtStart(instr->left());
887 LOperand* right = UseRegisterAtStart(instr->right());
ulan@chromium.org812308e2012-02-29 15:58:45 +0000888 LArithmeticD* result = new(zone()) LArithmeticD(op, left, right);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000889 return DefineAsRegister(result);
890}
891
892
893LInstruction* LChunkBuilder::DoArithmeticT(Token::Value op,
894 HArithmeticBinaryOperation* instr) {
895 ASSERT(op == Token::ADD ||
896 op == Token::DIV ||
897 op == Token::MOD ||
898 op == Token::MUL ||
899 op == Token::SUB);
900 HValue* left = instr->left();
901 HValue* right = instr->right();
902 ASSERT(left->representation().IsTagged());
903 ASSERT(right->representation().IsTagged());
904 LOperand* left_operand = UseFixed(left, a1);
905 LOperand* right_operand = UseFixed(right, a0);
ulan@chromium.org812308e2012-02-29 15:58:45 +0000906 LArithmeticT* result =
907 new(zone()) LArithmeticT(op, left_operand, right_operand);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000908 return MarkAsCall(DefineFixed(result, v0), instr);
909}
910
911
912void LChunkBuilder::DoBasicBlock(HBasicBlock* block, HBasicBlock* next_block) {
913 ASSERT(is_building());
914 current_block_ = block;
915 next_block_ = next_block;
916 if (block->IsStartBlock()) {
917 block->UpdateEnvironment(graph_->start_environment());
918 argument_count_ = 0;
919 } else if (block->predecessors()->length() == 1) {
920 // We have a single predecessor => copy environment and outgoing
921 // argument count from the predecessor.
922 ASSERT(block->phis()->length() == 0);
923 HBasicBlock* pred = block->predecessors()->at(0);
924 HEnvironment* last_environment = pred->last_environment();
925 ASSERT(last_environment != NULL);
926 // Only copy the environment, if it is later used again.
927 if (pred->end()->SecondSuccessor() == NULL) {
928 ASSERT(pred->end()->FirstSuccessor() == block);
929 } else {
930 if (pred->end()->FirstSuccessor()->block_id() > block->block_id() ||
931 pred->end()->SecondSuccessor()->block_id() > block->block_id()) {
932 last_environment = last_environment->Copy();
933 }
934 }
935 block->UpdateEnvironment(last_environment);
936 ASSERT(pred->argument_count() >= 0);
937 argument_count_ = pred->argument_count();
938 } else {
939 // We are at a state join => process phis.
940 HBasicBlock* pred = block->predecessors()->at(0);
941 // No need to copy the environment, it cannot be used later.
942 HEnvironment* last_environment = pred->last_environment();
943 for (int i = 0; i < block->phis()->length(); ++i) {
944 HPhi* phi = block->phis()->at(i);
945 last_environment->SetValueAt(phi->merged_index(), phi);
946 }
947 for (int i = 0; i < block->deleted_phis()->length(); ++i) {
948 last_environment->SetValueAt(block->deleted_phis()->at(i),
949 graph_->GetConstantUndefined());
950 }
951 block->UpdateEnvironment(last_environment);
952 // Pick up the outgoing argument count of one of the predecessors.
953 argument_count_ = pred->argument_count();
954 }
955 HInstruction* current = block->first();
956 int start = chunk_->instructions()->length();
957 while (current != NULL && !is_aborted()) {
958 // Code for constants in registers is generated lazily.
959 if (!current->EmitAtUses()) {
960 VisitInstruction(current);
961 }
962 current = current->next();
963 }
964 int end = chunk_->instructions()->length() - 1;
965 if (end >= start) {
966 block->set_first_instruction_index(start);
967 block->set_last_instruction_index(end);
968 }
969 block->set_argument_count(argument_count_);
970 next_block_ = NULL;
971 current_block_ = NULL;
972}
973
974
975void LChunkBuilder::VisitInstruction(HInstruction* current) {
976 HInstruction* old_current = current_instruction_;
977 current_instruction_ = current;
978 if (current->has_position()) position_ = current->position();
979 LInstruction* instr = current->CompileToLithium(this);
980
981 if (instr != NULL) {
982 if (FLAG_stress_pointer_maps && !instr->HasPointerMap()) {
983 instr = AssignPointerMap(instr);
984 }
985 if (FLAG_stress_environments && !instr->HasEnvironment()) {
986 instr = AssignEnvironment(instr);
987 }
988 instr->set_hydrogen_value(current);
989 chunk_->AddInstruction(instr, current_block_);
990 }
991 current_instruction_ = old_current;
992}
993
994
995LEnvironment* LChunkBuilder::CreateEnvironment(
996 HEnvironment* hydrogen_env,
997 int* argument_index_accumulator) {
998 if (hydrogen_env == NULL) return NULL;
999
1000 LEnvironment* outer =
1001 CreateEnvironment(hydrogen_env->outer(), argument_index_accumulator);
1002 int ast_id = hydrogen_env->ast_id();
ulan@chromium.org812308e2012-02-29 15:58:45 +00001003 ASSERT(ast_id != AstNode::kNoNumber ||
1004 hydrogen_env->frame_type() != JS_FUNCTION);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001005 int value_count = hydrogen_env->length();
ulan@chromium.org812308e2012-02-29 15:58:45 +00001006 LEnvironment* result = new(zone()) LEnvironment(
1007 hydrogen_env->closure(),
1008 hydrogen_env->frame_type(),
1009 ast_id,
1010 hydrogen_env->parameter_count(),
1011 argument_count_,
1012 value_count,
1013 outer);
danno@chromium.orgfa458e42012-02-01 10:48:36 +00001014 int argument_index = *argument_index_accumulator;
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001015 for (int i = 0; i < value_count; ++i) {
1016 if (hydrogen_env->is_special_index(i)) continue;
1017
1018 HValue* value = hydrogen_env->values()->at(i);
1019 LOperand* op = NULL;
1020 if (value->IsArgumentsObject()) {
1021 op = NULL;
1022 } else if (value->IsPushArgument()) {
ulan@chromium.org812308e2012-02-29 15:58:45 +00001023 op = new(zone()) LArgument(argument_index++);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001024 } else {
1025 op = UseAny(value);
1026 }
1027 result->AddValue(op, value->representation());
1028 }
1029
ulan@chromium.org812308e2012-02-29 15:58:45 +00001030 if (hydrogen_env->frame_type() == JS_FUNCTION) {
danno@chromium.orgfa458e42012-02-01 10:48:36 +00001031 *argument_index_accumulator = argument_index;
1032 }
1033
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001034 return result;
1035}
1036
1037
1038LInstruction* LChunkBuilder::DoGoto(HGoto* instr) {
ulan@chromium.org812308e2012-02-29 15:58:45 +00001039 return new(zone()) LGoto(instr->FirstSuccessor()->block_id());
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001040}
1041
1042
1043LInstruction* LChunkBuilder::DoBranch(HBranch* instr) {
erik.corry@gmail.comf2038fb2012-01-16 11:42:08 +00001044 HValue* value = instr->value();
1045 if (value->EmitAtUses()) {
1046 HBasicBlock* successor = HConstant::cast(value)->ToBoolean()
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001047 ? instr->FirstSuccessor()
1048 : instr->SecondSuccessor();
ulan@chromium.org812308e2012-02-29 15:58:45 +00001049 return new(zone()) LGoto(successor->block_id());
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001050 }
erik.corry@gmail.comf2038fb2012-01-16 11:42:08 +00001051
ulan@chromium.org812308e2012-02-29 15:58:45 +00001052 LBranch* result = new(zone()) LBranch(UseRegister(value));
erik.corry@gmail.comf2038fb2012-01-16 11:42:08 +00001053 // Tagged values that are not known smis or booleans require a
1054 // deoptimization environment.
1055 Representation rep = value->representation();
1056 HType type = value->type();
1057 if (rep.IsTagged() && !type.IsSmi() && !type.IsBoolean()) {
1058 return AssignEnvironment(result);
1059 }
1060 return result;
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001061}
1062
1063
1064LInstruction* LChunkBuilder::DoCompareMap(HCompareMap* instr) {
1065 ASSERT(instr->value()->representation().IsTagged());
1066 LOperand* value = UseRegisterAtStart(instr->value());
1067 LOperand* temp = TempRegister();
ulan@chromium.org812308e2012-02-29 15:58:45 +00001068 return new(zone()) LCmpMapAndBranch(value, temp);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001069}
1070
1071
1072LInstruction* LChunkBuilder::DoArgumentsLength(HArgumentsLength* length) {
ulan@chromium.org812308e2012-02-29 15:58:45 +00001073 return DefineAsRegister(
1074 new(zone()) LArgumentsLength(UseRegister(length->value())));
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001075}
1076
1077
1078LInstruction* LChunkBuilder::DoArgumentsElements(HArgumentsElements* elems) {
ulan@chromium.org812308e2012-02-29 15:58:45 +00001079 return DefineAsRegister(new(zone()) LArgumentsElements);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001080}
1081
1082
1083LInstruction* LChunkBuilder::DoInstanceOf(HInstanceOf* instr) {
1084 LInstanceOf* result =
ulan@chromium.org812308e2012-02-29 15:58:45 +00001085 new(zone()) LInstanceOf(UseFixed(instr->left(), a0),
1086 UseFixed(instr->right(), a1));
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001087 return MarkAsCall(DefineFixed(result, v0), instr);
1088}
1089
1090
1091LInstruction* LChunkBuilder::DoInstanceOfKnownGlobal(
1092 HInstanceOfKnownGlobal* instr) {
1093 LInstanceOfKnownGlobal* result =
ulan@chromium.org812308e2012-02-29 15:58:45 +00001094 new(zone()) LInstanceOfKnownGlobal(UseFixed(instr->left(), a0),
1095 FixedTemp(t0));
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001096 return MarkAsCall(DefineFixed(result, v0), instr);
1097}
1098
1099
1100LInstruction* LChunkBuilder::DoApplyArguments(HApplyArguments* instr) {
1101 LOperand* function = UseFixed(instr->function(), a1);
1102 LOperand* receiver = UseFixed(instr->receiver(), a0);
1103 LOperand* length = UseFixed(instr->length(), a2);
1104 LOperand* elements = UseFixed(instr->elements(), a3);
ulan@chromium.org812308e2012-02-29 15:58:45 +00001105 LApplyArguments* result = new(zone()) LApplyArguments(function,
1106 receiver,
1107 length,
1108 elements);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001109 return MarkAsCall(DefineFixed(result, v0), instr, CAN_DEOPTIMIZE_EAGERLY);
1110}
1111
1112
1113LInstruction* LChunkBuilder::DoPushArgument(HPushArgument* instr) {
1114 ++argument_count_;
1115 LOperand* argument = Use(instr->argument());
ulan@chromium.org812308e2012-02-29 15:58:45 +00001116 return new(zone()) LPushArgument(argument);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001117}
1118
1119
1120LInstruction* LChunkBuilder::DoThisFunction(HThisFunction* instr) {
ulan@chromium.org812308e2012-02-29 15:58:45 +00001121 return instr->HasNoUses()
1122 ? NULL
1123 : DefineAsRegister(new(zone()) LThisFunction);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001124}
1125
1126
1127LInstruction* LChunkBuilder::DoContext(HContext* instr) {
ulan@chromium.org812308e2012-02-29 15:58:45 +00001128 return instr->HasNoUses() ? NULL : DefineAsRegister(new(zone()) LContext);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001129}
1130
1131
1132LInstruction* LChunkBuilder::DoOuterContext(HOuterContext* instr) {
1133 LOperand* context = UseRegisterAtStart(instr->value());
ulan@chromium.org812308e2012-02-29 15:58:45 +00001134 return DefineAsRegister(new(zone()) LOuterContext(context));
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001135}
1136
1137
jkummerow@chromium.orgf7a58842012-02-21 10:08:21 +00001138LInstruction* LChunkBuilder::DoDeclareGlobals(HDeclareGlobals* instr) {
ulan@chromium.org812308e2012-02-29 15:58:45 +00001139 return MarkAsCall(new(zone()) LDeclareGlobals, instr);
jkummerow@chromium.orgf7a58842012-02-21 10:08:21 +00001140}
1141
1142
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001143LInstruction* LChunkBuilder::DoGlobalObject(HGlobalObject* instr) {
1144 LOperand* context = UseRegisterAtStart(instr->value());
ulan@chromium.org812308e2012-02-29 15:58:45 +00001145 return DefineAsRegister(new(zone()) LGlobalObject(context));
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001146}
1147
1148
1149LInstruction* LChunkBuilder::DoGlobalReceiver(HGlobalReceiver* instr) {
1150 LOperand* global_object = UseRegisterAtStart(instr->value());
ulan@chromium.org812308e2012-02-29 15:58:45 +00001151 return DefineAsRegister(new(zone()) LGlobalReceiver(global_object));
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001152}
1153
1154
1155LInstruction* LChunkBuilder::DoCallConstantFunction(
1156 HCallConstantFunction* instr) {
1157 argument_count_ -= instr->argument_count();
ulan@chromium.org812308e2012-02-29 15:58:45 +00001158 return MarkAsCall(DefineFixed(new(zone()) LCallConstantFunction, v0), instr);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001159}
1160
1161
1162LInstruction* LChunkBuilder::DoInvokeFunction(HInvokeFunction* instr) {
1163 LOperand* function = UseFixed(instr->function(), a1);
1164 argument_count_ -= instr->argument_count();
ulan@chromium.org812308e2012-02-29 15:58:45 +00001165 LInvokeFunction* result = new(zone()) LInvokeFunction(function);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001166 return MarkAsCall(DefineFixed(result, v0), instr, CANNOT_DEOPTIMIZE_EAGERLY);
1167}
1168
1169
1170LInstruction* LChunkBuilder::DoUnaryMathOperation(HUnaryMathOperation* instr) {
1171 BuiltinFunctionId op = instr->op();
ulan@chromium.org9a21ec42012-03-06 08:42:24 +00001172 if (op == kMathLog || op == kMathSin || op == kMathCos || op == kMathTan) {
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001173 LOperand* input = UseFixedDouble(instr->value(), f4);
ulan@chromium.org812308e2012-02-29 15:58:45 +00001174 LUnaryMathOperation* result = new(zone()) LUnaryMathOperation(input, NULL);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001175 return MarkAsCall(DefineFixedDouble(result, f4), instr);
ricow@chromium.org64e3a4b2011-12-13 08:07:27 +00001176 } else if (op == kMathPowHalf) {
1177 // Input cannot be the same as the result.
1178 // See lithium-codegen-mips.cc::DoMathPowHalf.
1179 LOperand* input = UseFixedDouble(instr->value(), f8);
1180 LOperand* temp = FixedTemp(f6);
ulan@chromium.org812308e2012-02-29 15:58:45 +00001181 LUnaryMathOperation* result = new(zone()) LUnaryMathOperation(input, temp);
ricow@chromium.org64e3a4b2011-12-13 08:07:27 +00001182 return DefineFixedDouble(result, f4);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001183 } else {
1184 LOperand* input = UseRegisterAtStart(instr->value());
1185 LOperand* temp = (op == kMathFloor) ? TempRegister() : NULL;
ulan@chromium.org812308e2012-02-29 15:58:45 +00001186 LUnaryMathOperation* result = new(zone()) LUnaryMathOperation(input, temp);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001187 switch (op) {
1188 case kMathAbs:
1189 return AssignEnvironment(AssignPointerMap(DefineAsRegister(result)));
1190 case kMathFloor:
1191 return AssignEnvironment(AssignPointerMap(DefineAsRegister(result)));
1192 case kMathSqrt:
1193 return DefineAsRegister(result);
1194 case kMathRound:
1195 return AssignEnvironment(DefineAsRegister(result));
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001196 default:
1197 UNREACHABLE();
1198 return NULL;
1199 }
1200 }
1201}
1202
1203
1204LInstruction* LChunkBuilder::DoCallKeyed(HCallKeyed* instr) {
1205 ASSERT(instr->key()->representation().IsTagged());
1206 argument_count_ -= instr->argument_count();
1207 LOperand* key = UseFixed(instr->key(), a2);
ulan@chromium.org812308e2012-02-29 15:58:45 +00001208 return MarkAsCall(DefineFixed(new(zone()) LCallKeyed(key), v0), instr);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001209}
1210
1211
1212LInstruction* LChunkBuilder::DoCallNamed(HCallNamed* instr) {
1213 argument_count_ -= instr->argument_count();
ulan@chromium.org812308e2012-02-29 15:58:45 +00001214 return MarkAsCall(DefineFixed(new(zone()) LCallNamed, v0), instr);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001215}
1216
1217
1218LInstruction* LChunkBuilder::DoCallGlobal(HCallGlobal* instr) {
1219 argument_count_ -= instr->argument_count();
ulan@chromium.org812308e2012-02-29 15:58:45 +00001220 return MarkAsCall(DefineFixed(new(zone()) LCallGlobal, v0), instr);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001221}
1222
1223
1224LInstruction* LChunkBuilder::DoCallKnownGlobal(HCallKnownGlobal* instr) {
1225 argument_count_ -= instr->argument_count();
ulan@chromium.org812308e2012-02-29 15:58:45 +00001226 return MarkAsCall(DefineFixed(new(zone()) LCallKnownGlobal, v0), instr);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001227}
1228
1229
1230LInstruction* LChunkBuilder::DoCallNew(HCallNew* instr) {
1231 LOperand* constructor = UseFixed(instr->constructor(), a1);
1232 argument_count_ -= instr->argument_count();
ulan@chromium.org812308e2012-02-29 15:58:45 +00001233 LCallNew* result = new(zone()) LCallNew(constructor);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001234 return MarkAsCall(DefineFixed(result, v0), instr);
1235}
1236
1237
1238LInstruction* LChunkBuilder::DoCallFunction(HCallFunction* instr) {
danno@chromium.orgc612e022011-11-10 11:38:15 +00001239 LOperand* function = UseFixed(instr->function(), a1);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001240 argument_count_ -= instr->argument_count();
ulan@chromium.org812308e2012-02-29 15:58:45 +00001241 return MarkAsCall(DefineFixed(new(zone()) LCallFunction(function), v0),
1242 instr);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001243}
1244
1245
1246LInstruction* LChunkBuilder::DoCallRuntime(HCallRuntime* instr) {
1247 argument_count_ -= instr->argument_count();
ulan@chromium.org812308e2012-02-29 15:58:45 +00001248 return MarkAsCall(DefineFixed(new(zone()) LCallRuntime, v0), instr);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001249}
1250
1251
1252LInstruction* LChunkBuilder::DoShr(HShr* instr) {
1253 return DoShift(Token::SHR, instr);
1254}
1255
1256
1257LInstruction* LChunkBuilder::DoSar(HSar* instr) {
1258 return DoShift(Token::SAR, instr);
1259}
1260
1261
1262LInstruction* LChunkBuilder::DoShl(HShl* instr) {
1263 return DoShift(Token::SHL, instr);
1264}
1265
1266
1267LInstruction* LChunkBuilder::DoBitwise(HBitwise* instr) {
1268 if (instr->representation().IsInteger32()) {
1269 ASSERT(instr->left()->representation().IsInteger32());
1270 ASSERT(instr->right()->representation().IsInteger32());
1271
1272 LOperand* left = UseRegisterAtStart(instr->LeastConstantOperand());
1273 LOperand* right = UseOrConstantAtStart(instr->MostConstantOperand());
ulan@chromium.org812308e2012-02-29 15:58:45 +00001274 return DefineAsRegister(new(zone()) LBitI(left, right));
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001275 } else {
1276 ASSERT(instr->representation().IsTagged());
1277 ASSERT(instr->left()->representation().IsTagged());
1278 ASSERT(instr->right()->representation().IsTagged());
1279
1280 LOperand* left = UseFixed(instr->left(), a1);
1281 LOperand* right = UseFixed(instr->right(), a0);
ulan@chromium.org812308e2012-02-29 15:58:45 +00001282 LArithmeticT* result = new(zone()) LArithmeticT(instr->op(), left, right);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001283 return MarkAsCall(DefineFixed(result, v0), instr);
1284 }
1285}
1286
1287
1288LInstruction* LChunkBuilder::DoBitNot(HBitNot* instr) {
1289 ASSERT(instr->value()->representation().IsInteger32());
1290 ASSERT(instr->representation().IsInteger32());
ulan@chromium.org812308e2012-02-29 15:58:45 +00001291 LOperand* value = UseRegisterAtStart(instr->value());
1292 return DefineAsRegister(new(zone()) LBitNotI(value));
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001293}
1294
1295
1296LInstruction* LChunkBuilder::DoDiv(HDiv* instr) {
1297 if (instr->representation().IsDouble()) {
1298 return DoArithmeticD(Token::DIV, instr);
1299 } else if (instr->representation().IsInteger32()) {
1300 // TODO(1042) The fixed register allocation
1301 // is needed because we call TypeRecordingBinaryOpStub from
1302 // the generated code, which requires registers a0
1303 // and a1 to be used. We should remove that
1304 // when we provide a native implementation.
1305 LOperand* dividend = UseFixed(instr->left(), a0);
1306 LOperand* divisor = UseFixed(instr->right(), a1);
1307 return AssignEnvironment(AssignPointerMap(
ulan@chromium.org812308e2012-02-29 15:58:45 +00001308 DefineFixed(new(zone()) LDivI(dividend, divisor), v0)));
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001309 } else {
1310 return DoArithmeticT(Token::DIV, instr);
1311 }
1312}
1313
1314
1315LInstruction* LChunkBuilder::DoMod(HMod* instr) {
1316 if (instr->representation().IsInteger32()) {
1317 ASSERT(instr->left()->representation().IsInteger32());
1318 ASSERT(instr->right()->representation().IsInteger32());
1319
1320 LModI* mod;
1321 if (instr->HasPowerOf2Divisor()) {
1322 ASSERT(!instr->CheckFlag(HValue::kCanBeDivByZero));
1323 LOperand* value = UseRegisterAtStart(instr->left());
ulan@chromium.org812308e2012-02-29 15:58:45 +00001324 mod = new(zone()) LModI(value, UseOrConstant(instr->right()));
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001325 } else {
1326 LOperand* dividend = UseRegister(instr->left());
1327 LOperand* divisor = UseRegister(instr->right());
ulan@chromium.org812308e2012-02-29 15:58:45 +00001328 mod = new(zone()) LModI(dividend,
1329 divisor,
1330 TempRegister(),
1331 FixedTemp(f20),
1332 FixedTemp(f22));
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001333 }
1334
1335 if (instr->CheckFlag(HValue::kBailoutOnMinusZero) ||
1336 instr->CheckFlag(HValue::kCanBeDivByZero)) {
1337 return AssignEnvironment(DefineAsRegister(mod));
1338 } else {
1339 return DefineAsRegister(mod);
1340 }
1341 } else if (instr->representation().IsTagged()) {
1342 return DoArithmeticT(Token::MOD, instr);
1343 } else {
1344 ASSERT(instr->representation().IsDouble());
1345 // We call a C function for double modulo. It can't trigger a GC.
1346 // We need to use fixed result register for the call.
1347 // TODO(fschneider): Allow any register as input registers.
1348 LOperand* left = UseFixedDouble(instr->left(), f2);
1349 LOperand* right = UseFixedDouble(instr->right(), f4);
ulan@chromium.org812308e2012-02-29 15:58:45 +00001350 LArithmeticD* result = new(zone()) LArithmeticD(Token::MOD, left, right);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001351 return MarkAsCall(DefineFixedDouble(result, f2), instr);
1352 }
1353}
1354
1355
1356LInstruction* LChunkBuilder::DoMul(HMul* instr) {
1357 if (instr->representation().IsInteger32()) {
1358 ASSERT(instr->left()->representation().IsInteger32());
1359 ASSERT(instr->right()->representation().IsInteger32());
1360 LOperand* left;
1361 LOperand* right = UseOrConstant(instr->MostConstantOperand());
1362 LOperand* temp = NULL;
1363 if (instr->CheckFlag(HValue::kBailoutOnMinusZero) &&
1364 (instr->CheckFlag(HValue::kCanOverflow) ||
1365 !right->IsConstantOperand())) {
1366 left = UseRegister(instr->LeastConstantOperand());
1367 temp = TempRegister();
1368 } else {
1369 left = UseRegisterAtStart(instr->LeastConstantOperand());
1370 }
ulan@chromium.org812308e2012-02-29 15:58:45 +00001371 LMulI* mul = new(zone()) LMulI(left, right, temp);
erik.corry@gmail.comf2038fb2012-01-16 11:42:08 +00001372 if (instr->CheckFlag(HValue::kCanOverflow) ||
1373 instr->CheckFlag(HValue::kBailoutOnMinusZero)) {
1374 AssignEnvironment(mul);
1375 }
1376 return DefineAsRegister(mul);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001377
1378 } else if (instr->representation().IsDouble()) {
1379 return DoArithmeticD(Token::MUL, instr);
1380
1381 } else {
1382 return DoArithmeticT(Token::MUL, instr);
1383 }
1384}
1385
1386
1387LInstruction* LChunkBuilder::DoSub(HSub* instr) {
1388 if (instr->representation().IsInteger32()) {
1389 ASSERT(instr->left()->representation().IsInteger32());
1390 ASSERT(instr->right()->representation().IsInteger32());
1391 LOperand* left = UseRegisterAtStart(instr->left());
1392 LOperand* right = UseOrConstantAtStart(instr->right());
ulan@chromium.org812308e2012-02-29 15:58:45 +00001393 LSubI* sub = new(zone()) LSubI(left, right);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001394 LInstruction* result = DefineAsRegister(sub);
1395 if (instr->CheckFlag(HValue::kCanOverflow)) {
1396 result = AssignEnvironment(result);
1397 }
1398 return result;
1399 } else if (instr->representation().IsDouble()) {
1400 return DoArithmeticD(Token::SUB, instr);
1401 } else {
1402 return DoArithmeticT(Token::SUB, instr);
1403 }
1404}
1405
1406
1407LInstruction* LChunkBuilder::DoAdd(HAdd* instr) {
1408 if (instr->representation().IsInteger32()) {
1409 ASSERT(instr->left()->representation().IsInteger32());
1410 ASSERT(instr->right()->representation().IsInteger32());
1411 LOperand* left = UseRegisterAtStart(instr->LeastConstantOperand());
1412 LOperand* right = UseOrConstantAtStart(instr->MostConstantOperand());
ulan@chromium.org812308e2012-02-29 15:58:45 +00001413 LAddI* add = new(zone()) LAddI(left, right);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001414 LInstruction* result = DefineAsRegister(add);
1415 if (instr->CheckFlag(HValue::kCanOverflow)) {
1416 result = AssignEnvironment(result);
1417 }
1418 return result;
1419 } else if (instr->representation().IsDouble()) {
1420 return DoArithmeticD(Token::ADD, instr);
1421 } else {
1422 ASSERT(instr->representation().IsTagged());
1423 return DoArithmeticT(Token::ADD, instr);
1424 }
1425}
1426
1427
1428LInstruction* LChunkBuilder::DoPower(HPower* instr) {
1429 ASSERT(instr->representation().IsDouble());
1430 // We call a C function for double power. It can't trigger a GC.
1431 // We need to use fixed result register for the call.
1432 Representation exponent_type = instr->right()->representation();
1433 ASSERT(instr->left()->representation().IsDouble());
1434 LOperand* left = UseFixedDouble(instr->left(), f2);
1435 LOperand* right = exponent_type.IsDouble() ?
1436 UseFixedDouble(instr->right(), f4) :
ricow@chromium.org64e3a4b2011-12-13 08:07:27 +00001437 UseFixed(instr->right(), a2);
ulan@chromium.org812308e2012-02-29 15:58:45 +00001438 LPower* result = new(zone()) LPower(left, right);
ricow@chromium.org64e3a4b2011-12-13 08:07:27 +00001439 return MarkAsCall(DefineFixedDouble(result, f0),
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001440 instr,
1441 CAN_DEOPTIMIZE_EAGERLY);
1442}
1443
1444
erik.corry@gmail.comf2038fb2012-01-16 11:42:08 +00001445LInstruction* LChunkBuilder::DoRandom(HRandom* instr) {
1446 ASSERT(instr->representation().IsDouble());
1447 ASSERT(instr->global_object()->representation().IsTagged());
1448 LOperand* global_object = UseFixed(instr->global_object(), a0);
ulan@chromium.org812308e2012-02-29 15:58:45 +00001449 LRandom* result = new(zone()) LRandom(global_object);
erik.corry@gmail.comf2038fb2012-01-16 11:42:08 +00001450 return MarkAsCall(DefineFixedDouble(result, f0), instr);
1451}
1452
1453
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001454LInstruction* LChunkBuilder::DoCompareGeneric(HCompareGeneric* instr) {
1455 Representation r = instr->GetInputRepresentation();
1456 ASSERT(instr->left()->representation().IsTagged());
1457 ASSERT(instr->right()->representation().IsTagged());
1458 LOperand* left = UseFixed(instr->left(), a1);
1459 LOperand* right = UseFixed(instr->right(), a0);
ulan@chromium.org812308e2012-02-29 15:58:45 +00001460 LCmpT* result = new(zone()) LCmpT(left, right);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001461 return MarkAsCall(DefineFixed(result, v0), instr);
1462}
1463
1464
1465LInstruction* LChunkBuilder::DoCompareIDAndBranch(
1466 HCompareIDAndBranch* instr) {
1467 Representation r = instr->GetInputRepresentation();
1468 if (r.IsInteger32()) {
1469 ASSERT(instr->left()->representation().IsInteger32());
1470 ASSERT(instr->right()->representation().IsInteger32());
1471 LOperand* left = UseRegisterOrConstantAtStart(instr->left());
1472 LOperand* right = UseRegisterOrConstantAtStart(instr->right());
ulan@chromium.org812308e2012-02-29 15:58:45 +00001473 return new(zone()) LCmpIDAndBranch(left, right);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001474 } else {
1475 ASSERT(r.IsDouble());
1476 ASSERT(instr->left()->representation().IsDouble());
1477 ASSERT(instr->right()->representation().IsDouble());
1478 LOperand* left = UseRegisterAtStart(instr->left());
1479 LOperand* right = UseRegisterAtStart(instr->right());
ulan@chromium.org812308e2012-02-29 15:58:45 +00001480 return new(zone()) LCmpIDAndBranch(left, right);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001481 }
1482}
1483
1484
1485LInstruction* LChunkBuilder::DoCompareObjectEqAndBranch(
1486 HCompareObjectEqAndBranch* instr) {
1487 LOperand* left = UseRegisterAtStart(instr->left());
1488 LOperand* right = UseRegisterAtStart(instr->right());
ulan@chromium.org812308e2012-02-29 15:58:45 +00001489 return new(zone()) LCmpObjectEqAndBranch(left, right);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001490}
1491
1492
1493LInstruction* LChunkBuilder::DoCompareConstantEqAndBranch(
1494 HCompareConstantEqAndBranch* instr) {
ulan@chromium.org812308e2012-02-29 15:58:45 +00001495 return new(zone()) LCmpConstantEqAndBranch(
1496 UseRegisterAtStart(instr->value()));
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001497}
1498
1499
1500LInstruction* LChunkBuilder::DoIsNilAndBranch(HIsNilAndBranch* instr) {
1501 ASSERT(instr->value()->representation().IsTagged());
ulan@chromium.org812308e2012-02-29 15:58:45 +00001502 return new(zone()) LIsNilAndBranch(UseRegisterAtStart(instr->value()));
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001503}
1504
1505
1506LInstruction* LChunkBuilder::DoIsObjectAndBranch(HIsObjectAndBranch* instr) {
1507 ASSERT(instr->value()->representation().IsTagged());
1508 LOperand* temp = TempRegister();
ulan@chromium.org812308e2012-02-29 15:58:45 +00001509 return new(zone()) LIsObjectAndBranch(UseRegisterAtStart(instr->value()),
1510 temp);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001511}
1512
1513
mstarzinger@chromium.orgf8c6bd52011-11-23 12:13:52 +00001514LInstruction* LChunkBuilder::DoIsStringAndBranch(HIsStringAndBranch* instr) {
1515 ASSERT(instr->value()->representation().IsTagged());
1516 LOperand* temp = TempRegister();
ulan@chromium.org812308e2012-02-29 15:58:45 +00001517 return new(zone()) LIsStringAndBranch(UseRegisterAtStart(instr->value()),
1518 temp);
mstarzinger@chromium.orgf8c6bd52011-11-23 12:13:52 +00001519}
1520
1521
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001522LInstruction* LChunkBuilder::DoIsSmiAndBranch(HIsSmiAndBranch* instr) {
1523 ASSERT(instr->value()->representation().IsTagged());
ulan@chromium.org812308e2012-02-29 15:58:45 +00001524 return new(zone()) LIsSmiAndBranch(Use(instr->value()));
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001525}
1526
1527
1528LInstruction* LChunkBuilder::DoIsUndetectableAndBranch(
1529 HIsUndetectableAndBranch* instr) {
1530 ASSERT(instr->value()->representation().IsTagged());
ulan@chromium.org812308e2012-02-29 15:58:45 +00001531 return new(zone()) LIsUndetectableAndBranch(
1532 UseRegisterAtStart(instr->value()), TempRegister());
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001533}
1534
1535
mstarzinger@chromium.orgf8c6bd52011-11-23 12:13:52 +00001536LInstruction* LChunkBuilder::DoStringCompareAndBranch(
1537 HStringCompareAndBranch* instr) {
1538 ASSERT(instr->left()->representation().IsTagged());
1539 ASSERT(instr->right()->representation().IsTagged());
1540 LOperand* left = UseFixed(instr->left(), a1);
1541 LOperand* right = UseFixed(instr->right(), a0);
ulan@chromium.org812308e2012-02-29 15:58:45 +00001542 LStringCompareAndBranch* result =
1543 new(zone()) LStringCompareAndBranch(left, right);
mstarzinger@chromium.orgf8c6bd52011-11-23 12:13:52 +00001544 return MarkAsCall(result, instr);
1545}
1546
1547
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001548LInstruction* LChunkBuilder::DoHasInstanceTypeAndBranch(
1549 HHasInstanceTypeAndBranch* instr) {
1550 ASSERT(instr->value()->representation().IsTagged());
ulan@chromium.org812308e2012-02-29 15:58:45 +00001551 LOperand* value = UseRegisterAtStart(instr->value());
1552 return new(zone()) LHasInstanceTypeAndBranch(value);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001553}
1554
1555
1556LInstruction* LChunkBuilder::DoGetCachedArrayIndex(
1557 HGetCachedArrayIndex* instr) {
1558 ASSERT(instr->value()->representation().IsTagged());
1559 LOperand* value = UseRegisterAtStart(instr->value());
1560
ulan@chromium.org812308e2012-02-29 15:58:45 +00001561 return DefineAsRegister(new(zone()) LGetCachedArrayIndex(value));
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001562}
1563
1564
1565LInstruction* LChunkBuilder::DoHasCachedArrayIndexAndBranch(
1566 HHasCachedArrayIndexAndBranch* instr) {
1567 ASSERT(instr->value()->representation().IsTagged());
ulan@chromium.org812308e2012-02-29 15:58:45 +00001568 return new(zone()) LHasCachedArrayIndexAndBranch(
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001569 UseRegisterAtStart(instr->value()));
1570}
1571
1572
1573LInstruction* LChunkBuilder::DoClassOfTestAndBranch(
1574 HClassOfTestAndBranch* instr) {
1575 ASSERT(instr->value()->representation().IsTagged());
ulan@chromium.org812308e2012-02-29 15:58:45 +00001576 return new(zone()) LClassOfTestAndBranch(UseRegister(instr->value()),
1577 TempRegister());
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001578}
1579
1580
1581LInstruction* LChunkBuilder::DoJSArrayLength(HJSArrayLength* instr) {
1582 LOperand* array = UseRegisterAtStart(instr->value());
ulan@chromium.org812308e2012-02-29 15:58:45 +00001583 return DefineAsRegister(new(zone()) LJSArrayLength(array));
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001584}
1585
1586
1587LInstruction* LChunkBuilder::DoFixedArrayBaseLength(
1588 HFixedArrayBaseLength* instr) {
1589 LOperand* array = UseRegisterAtStart(instr->value());
ulan@chromium.org812308e2012-02-29 15:58:45 +00001590 return DefineAsRegister(new(zone()) LFixedArrayBaseLength(array));
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001591}
1592
1593
1594LInstruction* LChunkBuilder::DoElementsKind(HElementsKind* instr) {
1595 LOperand* object = UseRegisterAtStart(instr->value());
ulan@chromium.org812308e2012-02-29 15:58:45 +00001596 return DefineAsRegister(new(zone()) LElementsKind(object));
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001597}
1598
1599
1600LInstruction* LChunkBuilder::DoValueOf(HValueOf* instr) {
1601 LOperand* object = UseRegister(instr->value());
ulan@chromium.org812308e2012-02-29 15:58:45 +00001602 LValueOf* result = new(zone()) LValueOf(object, TempRegister());
erik.corry@gmail.comf2038fb2012-01-16 11:42:08 +00001603 return DefineAsRegister(result);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001604}
1605
1606
1607LInstruction* LChunkBuilder::DoBoundsCheck(HBoundsCheck* instr) {
ulan@chromium.org812308e2012-02-29 15:58:45 +00001608 LOperand* value = UseRegisterAtStart(instr->index());
1609 LOperand* length = UseRegister(instr->length());
1610 return AssignEnvironment(new(zone()) LBoundsCheck(value, length));
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001611}
1612
1613
1614LInstruction* LChunkBuilder::DoAbnormalExit(HAbnormalExit* instr) {
1615 // The control instruction marking the end of a block that completed
1616 // abruptly (e.g., threw an exception). There is nothing specific to do.
1617 return NULL;
1618}
1619
1620
1621LInstruction* LChunkBuilder::DoThrow(HThrow* instr) {
1622 LOperand* value = UseFixed(instr->value(), a0);
ulan@chromium.org812308e2012-02-29 15:58:45 +00001623 return MarkAsCall(new(zone()) LThrow(value), instr);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001624}
1625
1626
1627LInstruction* LChunkBuilder::DoUseConst(HUseConst* instr) {
1628 return NULL;
1629}
1630
1631
1632LInstruction* LChunkBuilder::DoForceRepresentation(HForceRepresentation* bad) {
1633 // All HForceRepresentation instructions should be eliminated in the
1634 // representation change phase of Hydrogen.
1635 UNREACHABLE();
1636 return NULL;
1637}
1638
1639
1640LInstruction* LChunkBuilder::DoChange(HChange* instr) {
1641 Representation from = instr->from();
1642 Representation to = instr->to();
1643 if (from.IsTagged()) {
1644 if (to.IsDouble()) {
1645 LOperand* value = UseRegister(instr->value());
ulan@chromium.org812308e2012-02-29 15:58:45 +00001646 LNumberUntagD* res = new(zone()) LNumberUntagD(value);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001647 return AssignEnvironment(DefineAsRegister(res));
1648 } else {
1649 ASSERT(to.IsInteger32());
danno@chromium.orgfa458e42012-02-01 10:48:36 +00001650 LOperand* value = UseRegisterAtStart(instr->value());
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001651 bool needs_check = !instr->value()->type().IsSmi();
1652 LInstruction* res = NULL;
1653 if (!needs_check) {
ulan@chromium.org812308e2012-02-29 15:58:45 +00001654 res = DefineAsRegister(new(zone()) LSmiUntag(value, needs_check));
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001655 } else {
1656 LOperand* temp1 = TempRegister();
1657 LOperand* temp2 = instr->CanTruncateToInt32() ? TempRegister()
1658 : NULL;
1659 LOperand* temp3 = instr->CanTruncateToInt32() ? FixedTemp(f22)
1660 : NULL;
ulan@chromium.org812308e2012-02-29 15:58:45 +00001661 res = DefineSameAsFirst(new(zone()) LTaggedToI(value,
1662 temp1,
1663 temp2,
1664 temp3));
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001665 res = AssignEnvironment(res);
1666 }
1667 return res;
1668 }
1669 } else if (from.IsDouble()) {
1670 if (to.IsTagged()) {
1671 LOperand* value = UseRegister(instr->value());
1672 LOperand* temp1 = TempRegister();
1673 LOperand* temp2 = TempRegister();
1674
1675 // Make sure that the temp and result_temp registers are
1676 // different.
1677 LUnallocated* result_temp = TempRegister();
ulan@chromium.org812308e2012-02-29 15:58:45 +00001678 LNumberTagD* result = new(zone()) LNumberTagD(value, temp1, temp2);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001679 Define(result, result_temp);
1680 return AssignPointerMap(result);
1681 } else {
1682 ASSERT(to.IsInteger32());
1683 LOperand* value = UseRegister(instr->value());
ulan@chromium.org812308e2012-02-29 15:58:45 +00001684 LOperand* temp1 = TempRegister();
1685 LOperand* temp2 = instr->CanTruncateToInt32() ? TempRegister() : NULL;
1686 LDoubleToI* res = new(zone()) LDoubleToI(value, temp1, temp2);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001687 return AssignEnvironment(DefineAsRegister(res));
1688 }
1689 } else if (from.IsInteger32()) {
1690 if (to.IsTagged()) {
1691 HValue* val = instr->value();
danno@chromium.orgfa458e42012-02-01 10:48:36 +00001692 LOperand* value = UseRegisterAtStart(val);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001693 if (val->HasRange() && val->range()->IsInSmiRange()) {
ulan@chromium.org812308e2012-02-29 15:58:45 +00001694 return DefineAsRegister(new(zone()) LSmiTag(value));
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001695 } else {
ulan@chromium.org812308e2012-02-29 15:58:45 +00001696 LNumberTagI* result = new(zone()) LNumberTagI(value);
danno@chromium.orgfa458e42012-02-01 10:48:36 +00001697 return AssignEnvironment(AssignPointerMap(DefineAsRegister(result)));
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001698 }
1699 } else {
1700 ASSERT(to.IsDouble());
1701 LOperand* value = Use(instr->value());
ulan@chromium.org812308e2012-02-29 15:58:45 +00001702 return DefineAsRegister(new(zone()) LInteger32ToDouble(value));
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001703 }
1704 }
1705 UNREACHABLE();
1706 return NULL;
1707}
1708
1709
1710LInstruction* LChunkBuilder::DoCheckNonSmi(HCheckNonSmi* instr) {
1711 LOperand* value = UseRegisterAtStart(instr->value());
ulan@chromium.org812308e2012-02-29 15:58:45 +00001712 return AssignEnvironment(new(zone()) LCheckNonSmi(value));
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001713}
1714
1715
1716LInstruction* LChunkBuilder::DoCheckInstanceType(HCheckInstanceType* instr) {
1717 LOperand* value = UseRegisterAtStart(instr->value());
ulan@chromium.org812308e2012-02-29 15:58:45 +00001718 LInstruction* result = new(zone()) LCheckInstanceType(value);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001719 return AssignEnvironment(result);
1720}
1721
1722
1723LInstruction* LChunkBuilder::DoCheckPrototypeMaps(HCheckPrototypeMaps* instr) {
1724 LOperand* temp1 = TempRegister();
1725 LOperand* temp2 = TempRegister();
ulan@chromium.org812308e2012-02-29 15:58:45 +00001726 LInstruction* result = new(zone()) LCheckPrototypeMaps(temp1, temp2);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001727 return AssignEnvironment(result);
1728}
1729
1730
1731LInstruction* LChunkBuilder::DoCheckSmi(HCheckSmi* instr) {
1732 LOperand* value = UseRegisterAtStart(instr->value());
ulan@chromium.org812308e2012-02-29 15:58:45 +00001733 return AssignEnvironment(new(zone()) LCheckSmi(value));
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001734}
1735
1736
1737LInstruction* LChunkBuilder::DoCheckFunction(HCheckFunction* instr) {
1738 LOperand* value = UseRegisterAtStart(instr->value());
ulan@chromium.org812308e2012-02-29 15:58:45 +00001739 return AssignEnvironment(new(zone()) LCheckFunction(value));
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001740}
1741
1742
1743LInstruction* LChunkBuilder::DoCheckMap(HCheckMap* instr) {
1744 LOperand* value = UseRegisterAtStart(instr->value());
ulan@chromium.org812308e2012-02-29 15:58:45 +00001745 LInstruction* result = new(zone()) LCheckMap(value);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001746 return AssignEnvironment(result);
1747}
1748
1749
1750LInstruction* LChunkBuilder::DoClampToUint8(HClampToUint8* instr) {
1751 HValue* value = instr->value();
1752 Representation input_rep = value->representation();
1753 LOperand* reg = UseRegister(value);
1754 if (input_rep.IsDouble()) {
1755 // Revisit this decision, here and 8 lines below.
ulan@chromium.org812308e2012-02-29 15:58:45 +00001756 return DefineAsRegister(new(zone()) LClampDToUint8(reg, FixedTemp(f22)));
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001757 } else if (input_rep.IsInteger32()) {
ulan@chromium.org812308e2012-02-29 15:58:45 +00001758 return DefineAsRegister(new(zone()) LClampIToUint8(reg));
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001759 } else {
1760 ASSERT(input_rep.IsTagged());
1761 // Register allocator doesn't (yet) support allocation of double
1762 // temps. Reserve f22 explicitly.
ulan@chromium.org812308e2012-02-29 15:58:45 +00001763 LClampTToUint8* result = new(zone()) LClampTToUint8(reg, FixedTemp(f22));
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001764 return AssignEnvironment(DefineAsRegister(result));
1765 }
1766}
1767
1768
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001769LInstruction* LChunkBuilder::DoReturn(HReturn* instr) {
ulan@chromium.org812308e2012-02-29 15:58:45 +00001770 return new(zone()) LReturn(UseFixed(instr->value(), v0));
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001771}
1772
1773
1774LInstruction* LChunkBuilder::DoConstant(HConstant* instr) {
1775 Representation r = instr->representation();
1776 if (r.IsInteger32()) {
ulan@chromium.org812308e2012-02-29 15:58:45 +00001777 return DefineAsRegister(new(zone()) LConstantI);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001778 } else if (r.IsDouble()) {
ulan@chromium.org812308e2012-02-29 15:58:45 +00001779 return DefineAsRegister(new(zone()) LConstantD);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001780 } else if (r.IsTagged()) {
ulan@chromium.org812308e2012-02-29 15:58:45 +00001781 return DefineAsRegister(new(zone()) LConstantT);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001782 } else {
1783 UNREACHABLE();
1784 return NULL;
1785 }
1786}
1787
1788
1789LInstruction* LChunkBuilder::DoLoadGlobalCell(HLoadGlobalCell* instr) {
ulan@chromium.org812308e2012-02-29 15:58:45 +00001790 LLoadGlobalCell* result = new(zone()) LLoadGlobalCell;
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001791 return instr->RequiresHoleCheck()
1792 ? AssignEnvironment(DefineAsRegister(result))
1793 : DefineAsRegister(result);
1794}
1795
1796
1797LInstruction* LChunkBuilder::DoLoadGlobalGeneric(HLoadGlobalGeneric* instr) {
1798 LOperand* global_object = UseFixed(instr->global_object(), a0);
ulan@chromium.org812308e2012-02-29 15:58:45 +00001799 LLoadGlobalGeneric* result = new(zone()) LLoadGlobalGeneric(global_object);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001800 return MarkAsCall(DefineFixed(result, v0), instr);
1801}
1802
1803
1804LInstruction* LChunkBuilder::DoStoreGlobalCell(HStoreGlobalCell* instr) {
danno@chromium.orge78f9fc2011-12-21 08:29:34 +00001805 LOperand* value = UseRegister(instr->value());
1806 // Use a temp to check the value in the cell in the case where we perform
1807 // a hole check.
1808 return instr->RequiresHoleCheck()
ulan@chromium.org812308e2012-02-29 15:58:45 +00001809 ? AssignEnvironment(new(zone()) LStoreGlobalCell(value, TempRegister()))
1810 : new(zone()) LStoreGlobalCell(value, NULL);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001811}
1812
1813
1814LInstruction* LChunkBuilder::DoStoreGlobalGeneric(HStoreGlobalGeneric* instr) {
1815 LOperand* global_object = UseFixed(instr->global_object(), a1);
1816 LOperand* value = UseFixed(instr->value(), a0);
1817 LStoreGlobalGeneric* result =
ulan@chromium.org812308e2012-02-29 15:58:45 +00001818 new(zone()) LStoreGlobalGeneric(global_object, value);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001819 return MarkAsCall(result, instr);
1820}
1821
1822
1823LInstruction* LChunkBuilder::DoLoadContextSlot(HLoadContextSlot* instr) {
1824 LOperand* context = UseRegisterAtStart(instr->value());
ulan@chromium.org812308e2012-02-29 15:58:45 +00001825 LInstruction* result =
1826 DefineAsRegister(new(zone()) LLoadContextSlot(context));
ricow@chromium.org64e3a4b2011-12-13 08:07:27 +00001827 return instr->RequiresHoleCheck() ? AssignEnvironment(result) : result;
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001828}
1829
1830
1831LInstruction* LChunkBuilder::DoStoreContextSlot(HStoreContextSlot* instr) {
1832 LOperand* context;
1833 LOperand* value;
1834 if (instr->NeedsWriteBarrier()) {
1835 context = UseTempRegister(instr->context());
1836 value = UseTempRegister(instr->value());
1837 } else {
1838 context = UseRegister(instr->context());
1839 value = UseRegister(instr->value());
1840 }
ulan@chromium.org812308e2012-02-29 15:58:45 +00001841 LInstruction* result = new(zone()) LStoreContextSlot(context, value);
ricow@chromium.org64e3a4b2011-12-13 08:07:27 +00001842 return instr->RequiresHoleCheck() ? AssignEnvironment(result) : result;
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001843}
1844
1845
1846LInstruction* LChunkBuilder::DoLoadNamedField(HLoadNamedField* instr) {
1847 return DefineAsRegister(
ulan@chromium.org812308e2012-02-29 15:58:45 +00001848 new(zone()) LLoadNamedField(UseRegisterAtStart(instr->object())));
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001849}
1850
1851
1852LInstruction* LChunkBuilder::DoLoadNamedFieldPolymorphic(
1853 HLoadNamedFieldPolymorphic* instr) {
1854 ASSERT(instr->representation().IsTagged());
1855 if (instr->need_generic()) {
1856 LOperand* obj = UseFixed(instr->object(), a0);
ulan@chromium.org812308e2012-02-29 15:58:45 +00001857 LLoadNamedFieldPolymorphic* result =
1858 new(zone()) LLoadNamedFieldPolymorphic(obj);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001859 return MarkAsCall(DefineFixed(result, v0), instr);
1860 } else {
1861 LOperand* obj = UseRegisterAtStart(instr->object());
ulan@chromium.org812308e2012-02-29 15:58:45 +00001862 LLoadNamedFieldPolymorphic* result =
1863 new(zone()) LLoadNamedFieldPolymorphic(obj);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001864 return AssignEnvironment(DefineAsRegister(result));
1865 }
1866}
1867
1868
1869LInstruction* LChunkBuilder::DoLoadNamedGeneric(HLoadNamedGeneric* instr) {
1870 LOperand* object = UseFixed(instr->object(), a0);
ulan@chromium.org812308e2012-02-29 15:58:45 +00001871 LInstruction* result = DefineFixed(new(zone()) LLoadNamedGeneric(object), v0);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001872 return MarkAsCall(result, instr);
1873}
1874
1875
1876LInstruction* LChunkBuilder::DoLoadFunctionPrototype(
1877 HLoadFunctionPrototype* instr) {
1878 return AssignEnvironment(DefineAsRegister(
ulan@chromium.org812308e2012-02-29 15:58:45 +00001879 new(zone()) LLoadFunctionPrototype(UseRegister(instr->function()))));
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001880}
1881
1882
1883LInstruction* LChunkBuilder::DoLoadElements(HLoadElements* instr) {
1884 LOperand* input = UseRegisterAtStart(instr->value());
ulan@chromium.org812308e2012-02-29 15:58:45 +00001885 return DefineAsRegister(new(zone()) LLoadElements(input));
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001886}
1887
1888
1889LInstruction* LChunkBuilder::DoLoadExternalArrayPointer(
1890 HLoadExternalArrayPointer* instr) {
1891 LOperand* input = UseRegisterAtStart(instr->value());
ulan@chromium.org812308e2012-02-29 15:58:45 +00001892 return DefineAsRegister(new(zone()) LLoadExternalArrayPointer(input));
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001893}
1894
1895
1896LInstruction* LChunkBuilder::DoLoadKeyedFastElement(
1897 HLoadKeyedFastElement* instr) {
1898 ASSERT(instr->representation().IsTagged());
1899 ASSERT(instr->key()->representation().IsInteger32());
1900 LOperand* obj = UseRegisterAtStart(instr->object());
1901 LOperand* key = UseRegisterAtStart(instr->key());
ulan@chromium.org812308e2012-02-29 15:58:45 +00001902 LLoadKeyedFastElement* result = new(zone()) LLoadKeyedFastElement(obj, key);
erik.corry@gmail.comf2038fb2012-01-16 11:42:08 +00001903 if (instr->RequiresHoleCheck()) AssignEnvironment(result);
1904 return DefineAsRegister(result);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001905}
1906
1907
1908LInstruction* LChunkBuilder::DoLoadKeyedFastDoubleElement(
1909 HLoadKeyedFastDoubleElement* instr) {
1910 ASSERT(instr->representation().IsDouble());
1911 ASSERT(instr->key()->representation().IsInteger32());
1912 LOperand* elements = UseTempRegister(instr->elements());
1913 LOperand* key = UseRegisterOrConstantAtStart(instr->key());
1914 LLoadKeyedFastDoubleElement* result =
ulan@chromium.org812308e2012-02-29 15:58:45 +00001915 new(zone()) LLoadKeyedFastDoubleElement(elements, key);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001916 return AssignEnvironment(DefineAsRegister(result));
1917}
1918
1919
1920LInstruction* LChunkBuilder::DoLoadKeyedSpecializedArrayElement(
1921 HLoadKeyedSpecializedArrayElement* instr) {
1922 ElementsKind elements_kind = instr->elements_kind();
1923 Representation representation(instr->representation());
1924 ASSERT(
1925 (representation.IsInteger32() &&
1926 (elements_kind != EXTERNAL_FLOAT_ELEMENTS) &&
1927 (elements_kind != EXTERNAL_DOUBLE_ELEMENTS)) ||
1928 (representation.IsDouble() &&
1929 ((elements_kind == EXTERNAL_FLOAT_ELEMENTS) ||
1930 (elements_kind == EXTERNAL_DOUBLE_ELEMENTS))));
1931 ASSERT(instr->key()->representation().IsInteger32());
1932 LOperand* external_pointer = UseRegister(instr->external_pointer());
1933 LOperand* key = UseRegisterOrConstant(instr->key());
1934 LLoadKeyedSpecializedArrayElement* result =
ulan@chromium.org812308e2012-02-29 15:58:45 +00001935 new(zone()) LLoadKeyedSpecializedArrayElement(external_pointer, key);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001936 LInstruction* load_instr = DefineAsRegister(result);
1937 // An unsigned int array load might overflow and cause a deopt, make sure it
1938 // has an environment.
1939 return (elements_kind == EXTERNAL_UNSIGNED_INT_ELEMENTS) ?
1940 AssignEnvironment(load_instr) : load_instr;
1941}
1942
1943
1944LInstruction* LChunkBuilder::DoLoadKeyedGeneric(HLoadKeyedGeneric* instr) {
1945 LOperand* object = UseFixed(instr->object(), a1);
1946 LOperand* key = UseFixed(instr->key(), a0);
1947
1948 LInstruction* result =
ulan@chromium.org812308e2012-02-29 15:58:45 +00001949 DefineFixed(new(zone()) LLoadKeyedGeneric(object, key), v0);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001950 return MarkAsCall(result, instr);
1951}
1952
1953
1954LInstruction* LChunkBuilder::DoStoreKeyedFastElement(
1955 HStoreKeyedFastElement* instr) {
1956 bool needs_write_barrier = instr->NeedsWriteBarrier();
1957 ASSERT(instr->value()->representation().IsTagged());
1958 ASSERT(instr->object()->representation().IsTagged());
1959 ASSERT(instr->key()->representation().IsInteger32());
1960
1961 LOperand* obj = UseTempRegister(instr->object());
1962 LOperand* val = needs_write_barrier
1963 ? UseTempRegister(instr->value())
1964 : UseRegisterAtStart(instr->value());
1965 LOperand* key = needs_write_barrier
1966 ? UseTempRegister(instr->key())
1967 : UseRegisterOrConstantAtStart(instr->key());
ulan@chromium.org812308e2012-02-29 15:58:45 +00001968 return new(zone()) LStoreKeyedFastElement(obj, key, val);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001969}
1970
1971
1972LInstruction* LChunkBuilder::DoStoreKeyedFastDoubleElement(
1973 HStoreKeyedFastDoubleElement* instr) {
1974 ASSERT(instr->value()->representation().IsDouble());
1975 ASSERT(instr->elements()->representation().IsTagged());
1976 ASSERT(instr->key()->representation().IsInteger32());
1977
1978 LOperand* elements = UseRegisterAtStart(instr->elements());
1979 LOperand* val = UseTempRegister(instr->value());
1980 LOperand* key = UseRegisterOrConstantAtStart(instr->key());
1981
ulan@chromium.org812308e2012-02-29 15:58:45 +00001982 return new(zone()) LStoreKeyedFastDoubleElement(elements, key, val);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001983}
1984
1985
1986LInstruction* LChunkBuilder::DoStoreKeyedSpecializedArrayElement(
1987 HStoreKeyedSpecializedArrayElement* instr) {
1988 Representation representation(instr->value()->representation());
1989 ElementsKind elements_kind = instr->elements_kind();
1990 ASSERT(
1991 (representation.IsInteger32() &&
1992 (elements_kind != EXTERNAL_FLOAT_ELEMENTS) &&
1993 (elements_kind != EXTERNAL_DOUBLE_ELEMENTS)) ||
1994 (representation.IsDouble() &&
1995 ((elements_kind == EXTERNAL_FLOAT_ELEMENTS) ||
1996 (elements_kind == EXTERNAL_DOUBLE_ELEMENTS))));
1997 ASSERT(instr->external_pointer()->representation().IsExternal());
1998 ASSERT(instr->key()->representation().IsInteger32());
1999
2000 LOperand* external_pointer = UseRegister(instr->external_pointer());
2001 bool val_is_temp_register =
2002 elements_kind == EXTERNAL_PIXEL_ELEMENTS ||
2003 elements_kind == EXTERNAL_FLOAT_ELEMENTS;
2004 LOperand* val = val_is_temp_register
2005 ? UseTempRegister(instr->value())
2006 : UseRegister(instr->value());
2007 LOperand* key = UseRegisterOrConstant(instr->key());
2008
ulan@chromium.org812308e2012-02-29 15:58:45 +00002009 return new(zone()) LStoreKeyedSpecializedArrayElement(external_pointer,
2010 key,
2011 val);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002012}
2013
2014
2015LInstruction* LChunkBuilder::DoStoreKeyedGeneric(HStoreKeyedGeneric* instr) {
2016 LOperand* obj = UseFixed(instr->object(), a2);
2017 LOperand* key = UseFixed(instr->key(), a1);
2018 LOperand* val = UseFixed(instr->value(), a0);
2019
2020 ASSERT(instr->object()->representation().IsTagged());
2021 ASSERT(instr->key()->representation().IsTagged());
2022 ASSERT(instr->value()->representation().IsTagged());
2023
ulan@chromium.org812308e2012-02-29 15:58:45 +00002024 return MarkAsCall(new(zone()) LStoreKeyedGeneric(obj, key, val), instr);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002025}
2026
2027
2028LInstruction* LChunkBuilder::DoTransitionElementsKind(
2029 HTransitionElementsKind* instr) {
2030 if (instr->original_map()->elements_kind() == FAST_SMI_ONLY_ELEMENTS &&
2031 instr->transitioned_map()->elements_kind() == FAST_ELEMENTS) {
2032 LOperand* object = UseRegister(instr->object());
2033 LOperand* new_map_reg = TempRegister();
2034 LTransitionElementsKind* result =
ulan@chromium.org812308e2012-02-29 15:58:45 +00002035 new(zone()) LTransitionElementsKind(object, new_map_reg, NULL);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002036 return DefineSameAsFirst(result);
2037 } else {
2038 LOperand* object = UseFixed(instr->object(), a0);
2039 LOperand* fixed_object_reg = FixedTemp(a2);
2040 LOperand* new_map_reg = FixedTemp(a3);
2041 LTransitionElementsKind* result =
ulan@chromium.org812308e2012-02-29 15:58:45 +00002042 new(zone()) LTransitionElementsKind(object,
2043 new_map_reg,
2044 fixed_object_reg);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002045 return MarkAsCall(DefineFixed(result, v0), instr);
2046 }
2047}
2048
2049
2050LInstruction* LChunkBuilder::DoStoreNamedField(HStoreNamedField* instr) {
2051 bool needs_write_barrier = instr->NeedsWriteBarrier();
2052
2053 LOperand* obj = needs_write_barrier
2054 ? UseTempRegister(instr->object())
2055 : UseRegisterAtStart(instr->object());
2056
2057 LOperand* val = needs_write_barrier
2058 ? UseTempRegister(instr->value())
2059 : UseRegister(instr->value());
2060
ulan@chromium.org812308e2012-02-29 15:58:45 +00002061 return new(zone()) LStoreNamedField(obj, val);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002062}
2063
2064
2065LInstruction* LChunkBuilder::DoStoreNamedGeneric(HStoreNamedGeneric* instr) {
2066 LOperand* obj = UseFixed(instr->object(), a1);
2067 LOperand* val = UseFixed(instr->value(), a0);
2068
ulan@chromium.org812308e2012-02-29 15:58:45 +00002069 LInstruction* result = new(zone()) LStoreNamedGeneric(obj, val);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002070 return MarkAsCall(result, instr);
2071}
2072
2073
2074LInstruction* LChunkBuilder::DoStringAdd(HStringAdd* instr) {
2075 LOperand* left = UseRegisterAtStart(instr->left());
2076 LOperand* right = UseRegisterAtStart(instr->right());
ulan@chromium.org812308e2012-02-29 15:58:45 +00002077 return MarkAsCall(DefineFixed(new(zone()) LStringAdd(left, right), v0),
2078 instr);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002079}
2080
2081
2082LInstruction* LChunkBuilder::DoStringCharCodeAt(HStringCharCodeAt* instr) {
2083 LOperand* string = UseTempRegister(instr->string());
2084 LOperand* index = UseTempRegister(instr->index());
ulan@chromium.org812308e2012-02-29 15:58:45 +00002085 LStringCharCodeAt* result = new(zone()) LStringCharCodeAt(string, index);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002086 return AssignEnvironment(AssignPointerMap(DefineAsRegister(result)));
2087}
2088
2089
2090LInstruction* LChunkBuilder::DoStringCharFromCode(HStringCharFromCode* instr) {
2091 LOperand* char_code = UseRegister(instr->value());
ulan@chromium.org812308e2012-02-29 15:58:45 +00002092 LStringCharFromCode* result = new(zone()) LStringCharFromCode(char_code);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002093 return AssignPointerMap(DefineAsRegister(result));
2094}
2095
2096
2097LInstruction* LChunkBuilder::DoStringLength(HStringLength* instr) {
2098 LOperand* string = UseRegisterAtStart(instr->value());
ulan@chromium.org812308e2012-02-29 15:58:45 +00002099 return DefineAsRegister(new(zone()) LStringLength(string));
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002100}
2101
2102
ulan@chromium.org967e2702012-02-28 09:49:15 +00002103LInstruction* LChunkBuilder::DoAllocateObject(HAllocateObject* instr) {
fschneider@chromium.org35814e52012-03-01 15:43:35 +00002104 LAllocateObject* result = new(zone()) LAllocateObject(
2105 TempRegister(), TempRegister());
ulan@chromium.org967e2702012-02-28 09:49:15 +00002106 return AssignPointerMap(DefineAsRegister(result));
2107}
2108
2109
jkummerow@chromium.orgf7a58842012-02-21 10:08:21 +00002110LInstruction* LChunkBuilder::DoFastLiteral(HFastLiteral* instr) {
ulan@chromium.org812308e2012-02-29 15:58:45 +00002111 return MarkAsCall(DefineFixed(new(zone()) LFastLiteral, v0), instr);
jkummerow@chromium.orgf7a58842012-02-21 10:08:21 +00002112}
2113
2114
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002115LInstruction* LChunkBuilder::DoArrayLiteral(HArrayLiteral* instr) {
ulan@chromium.org812308e2012-02-29 15:58:45 +00002116 return MarkAsCall(DefineFixed(new(zone()) LArrayLiteral, v0), instr);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002117}
2118
2119
jkummerow@chromium.orgf7a58842012-02-21 10:08:21 +00002120LInstruction* LChunkBuilder::DoObjectLiteral(HObjectLiteral* instr) {
ulan@chromium.org812308e2012-02-29 15:58:45 +00002121 return MarkAsCall(DefineFixed(new(zone()) LObjectLiteral, v0), instr);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002122}
2123
2124
2125LInstruction* LChunkBuilder::DoRegExpLiteral(HRegExpLiteral* instr) {
ulan@chromium.org812308e2012-02-29 15:58:45 +00002126 return MarkAsCall(DefineFixed(new(zone()) LRegExpLiteral, v0), instr);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002127}
2128
2129
2130LInstruction* LChunkBuilder::DoFunctionLiteral(HFunctionLiteral* instr) {
ulan@chromium.org812308e2012-02-29 15:58:45 +00002131 return MarkAsCall(DefineFixed(new(zone()) LFunctionLiteral, v0), instr);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002132}
2133
2134
2135LInstruction* LChunkBuilder::DoDeleteProperty(HDeleteProperty* instr) {
2136 LOperand* object = UseFixed(instr->object(), a0);
2137 LOperand* key = UseFixed(instr->key(), a1);
ulan@chromium.org812308e2012-02-29 15:58:45 +00002138 LDeleteProperty* result = new(zone()) LDeleteProperty(object, key);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002139 return MarkAsCall(DefineFixed(result, v0), instr);
2140}
2141
2142
2143LInstruction* LChunkBuilder::DoOsrEntry(HOsrEntry* instr) {
2144 allocator_->MarkAsOsrEntry();
2145 current_block_->last_environment()->set_ast_id(instr->ast_id());
ulan@chromium.org812308e2012-02-29 15:58:45 +00002146 return AssignEnvironment(new(zone()) LOsrEntry);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002147}
2148
2149
2150LInstruction* LChunkBuilder::DoParameter(HParameter* instr) {
2151 int spill_index = chunk()->GetParameterStackSlot(instr->index());
ulan@chromium.org812308e2012-02-29 15:58:45 +00002152 return DefineAsSpilled(new(zone()) LParameter, spill_index);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002153}
2154
2155
2156LInstruction* LChunkBuilder::DoUnknownOSRValue(HUnknownOSRValue* instr) {
2157 int spill_index = chunk()->GetNextSpillIndex(false); // Not double-width.
2158 if (spill_index > LUnallocated::kMaxFixedIndex) {
2159 Abort("Too many spill slots needed for OSR");
2160 spill_index = 0;
2161 }
ulan@chromium.org812308e2012-02-29 15:58:45 +00002162 return DefineAsSpilled(new(zone()) LUnknownOSRValue, spill_index);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002163}
2164
2165
2166LInstruction* LChunkBuilder::DoCallStub(HCallStub* instr) {
2167 argument_count_ -= instr->argument_count();
ulan@chromium.org812308e2012-02-29 15:58:45 +00002168 return MarkAsCall(DefineFixed(new(zone()) LCallStub, v0), instr);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002169}
2170
2171
2172LInstruction* LChunkBuilder::DoArgumentsObject(HArgumentsObject* instr) {
2173 // There are no real uses of the arguments object.
2174 // arguments.length and element access are supported directly on
2175 // stack arguments, and any real arguments object use causes a bailout.
2176 // So this value is never used.
2177 return NULL;
2178}
2179
2180
2181LInstruction* LChunkBuilder::DoAccessArgumentsAt(HAccessArgumentsAt* instr) {
2182 LOperand* arguments = UseRegister(instr->arguments());
2183 LOperand* length = UseTempRegister(instr->length());
2184 LOperand* index = UseRegister(instr->index());
ulan@chromium.org812308e2012-02-29 15:58:45 +00002185 LAccessArgumentsAt* result =
2186 new(zone()) LAccessArgumentsAt(arguments, length, index);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002187 return AssignEnvironment(DefineAsRegister(result));
2188}
2189
2190
2191LInstruction* LChunkBuilder::DoToFastProperties(HToFastProperties* instr) {
2192 LOperand* object = UseFixed(instr->value(), a0);
ulan@chromium.org812308e2012-02-29 15:58:45 +00002193 LToFastProperties* result = new(zone()) LToFastProperties(object);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002194 return MarkAsCall(DefineFixed(result, v0), instr);
2195}
2196
2197
2198LInstruction* LChunkBuilder::DoTypeof(HTypeof* instr) {
ulan@chromium.org812308e2012-02-29 15:58:45 +00002199 LTypeof* result = new(zone()) LTypeof(UseFixed(instr->value(), a0));
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002200 return MarkAsCall(DefineFixed(result, v0), instr);
2201}
2202
2203
2204LInstruction* LChunkBuilder::DoTypeofIsAndBranch(HTypeofIsAndBranch* instr) {
ulan@chromium.org812308e2012-02-29 15:58:45 +00002205 return new(zone()) LTypeofIsAndBranch(UseTempRegister(instr->value()));
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002206}
2207
2208
2209LInstruction* LChunkBuilder::DoIsConstructCallAndBranch(
2210 HIsConstructCallAndBranch* instr) {
ulan@chromium.org812308e2012-02-29 15:58:45 +00002211 return new(zone()) LIsConstructCallAndBranch(TempRegister());
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002212}
2213
2214
2215LInstruction* LChunkBuilder::DoSimulate(HSimulate* instr) {
2216 HEnvironment* env = current_block_->last_environment();
2217 ASSERT(env != NULL);
2218
2219 env->set_ast_id(instr->ast_id());
2220
2221 env->Drop(instr->pop_count());
2222 for (int i = 0; i < instr->values()->length(); ++i) {
2223 HValue* value = instr->values()->at(i);
2224 if (instr->HasAssignedIndexAt(i)) {
2225 env->Bind(instr->GetAssignedIndexAt(i), value);
2226 } else {
2227 env->Push(value);
2228 }
2229 }
2230
2231 // If there is an instruction pending deoptimization environment create a
2232 // lazy bailout instruction to capture the environment.
2233 if (pending_deoptimization_ast_id_ == instr->ast_id()) {
ulan@chromium.org812308e2012-02-29 15:58:45 +00002234 LInstruction* result = new(zone()) LLazyBailout;
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002235 result = AssignEnvironment(result);
2236 instruction_pending_deoptimization_environment_->
2237 set_deoptimization_environment(result->environment());
2238 ClearInstructionPendingDeoptimizationEnvironment();
2239 return result;
2240 }
2241
2242 return NULL;
2243}
2244
2245
2246LInstruction* LChunkBuilder::DoStackCheck(HStackCheck* instr) {
2247 if (instr->is_function_entry()) {
ulan@chromium.org812308e2012-02-29 15:58:45 +00002248 return MarkAsCall(new(zone()) LStackCheck, instr);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002249 } else {
2250 ASSERT(instr->is_backwards_branch());
ulan@chromium.org812308e2012-02-29 15:58:45 +00002251 return AssignEnvironment(AssignPointerMap(new(zone()) LStackCheck));
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002252 }
2253}
2254
2255
2256LInstruction* LChunkBuilder::DoEnterInlined(HEnterInlined* instr) {
2257 HEnvironment* outer = current_block_->last_environment();
2258 HConstant* undefined = graph()->GetConstantUndefined();
2259 HEnvironment* inner = outer->CopyForInlining(instr->closure(),
danno@chromium.orgfa458e42012-02-01 10:48:36 +00002260 instr->arguments_count(),
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002261 instr->function(),
2262 undefined,
ulan@chromium.org812308e2012-02-29 15:58:45 +00002263 instr->call_kind(),
2264 instr->is_construct());
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002265 current_block_->UpdateEnvironment(inner);
2266 chunk_->AddInlinedClosure(instr->closure());
2267 return NULL;
2268}
2269
2270
2271LInstruction* LChunkBuilder::DoLeaveInlined(HLeaveInlined* instr) {
danno@chromium.orgfa458e42012-02-01 10:48:36 +00002272 HEnvironment* outer = current_block_->last_environment()->
2273 DiscardInlined(false);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002274 current_block_->UpdateEnvironment(outer);
2275 return NULL;
2276}
2277
2278
2279LInstruction* LChunkBuilder::DoIn(HIn* instr) {
2280 LOperand* key = UseRegisterAtStart(instr->key());
2281 LOperand* object = UseRegisterAtStart(instr->object());
ulan@chromium.org812308e2012-02-29 15:58:45 +00002282 LIn* result = new(zone()) LIn(key, object);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002283 return MarkAsCall(DefineFixed(result, v0), instr);
2284}
2285
2286
ulan@chromium.org812308e2012-02-29 15:58:45 +00002287LInstruction* LChunkBuilder::DoForInPrepareMap(HForInPrepareMap* instr) {
2288 LOperand* object = UseFixed(instr->enumerable(), a0);
fschneider@chromium.org35814e52012-03-01 15:43:35 +00002289 LForInPrepareMap* result = new(zone()) LForInPrepareMap(object);
ulan@chromium.org812308e2012-02-29 15:58:45 +00002290 return MarkAsCall(DefineFixed(result, v0), instr, CAN_DEOPTIMIZE_EAGERLY);
2291}
2292
2293
2294LInstruction* LChunkBuilder::DoForInCacheArray(HForInCacheArray* instr) {
2295 LOperand* map = UseRegister(instr->map());
2296 return AssignEnvironment(DefineAsRegister(
fschneider@chromium.org35814e52012-03-01 15:43:35 +00002297 new(zone()) LForInCacheArray(map)));
ulan@chromium.org812308e2012-02-29 15:58:45 +00002298}
2299
2300
2301LInstruction* LChunkBuilder::DoCheckMapValue(HCheckMapValue* instr) {
2302 LOperand* value = UseRegisterAtStart(instr->value());
2303 LOperand* map = UseRegisterAtStart(instr->map());
fschneider@chromium.org35814e52012-03-01 15:43:35 +00002304 return AssignEnvironment(new(zone()) LCheckMapValue(value, map));
ulan@chromium.org812308e2012-02-29 15:58:45 +00002305}
2306
2307
2308LInstruction* LChunkBuilder::DoLoadFieldByIndex(HLoadFieldByIndex* instr) {
2309 LOperand* object = UseRegister(instr->object());
2310 LOperand* index = UseRegister(instr->index());
fschneider@chromium.org35814e52012-03-01 15:43:35 +00002311 return DefineAsRegister(new(zone()) LLoadFieldByIndex(object, index));
ulan@chromium.org812308e2012-02-29 15:58:45 +00002312}
2313
2314
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002315} } // namespace v8::internal