blob: 77dea5b869d8fd2b68626fea85cf6cad79b87213 [file] [log] [blame]
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001// Copyright 2012 the V8 project authors. All rights reserved.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
Ben Murdoch3ef787d2012-04-12 10:51:47 +01004
Emily Bernierd0a1eb72015-03-24 16:35:39 -04005#include <sstream>
6
Ben Murdochb8a8cc12014-11-26 15:28:44 +00007#include "src/v8.h"
Ben Murdoch3ef787d2012-04-12 10:51:47 +01008
Ben Murdochb8a8cc12014-11-26 15:28:44 +00009#if V8_TARGET_ARCH_MIPS
10
11#include "src/hydrogen-osr.h"
12#include "src/lithium-inl.h"
13#include "src/mips/lithium-codegen-mips.h"
Ben Murdoch3ef787d2012-04-12 10:51:47 +010014
15namespace v8 {
16namespace internal {
17
18#define DEFINE_COMPILE(type) \
19 void L##type::CompileToNative(LCodeGen* generator) { \
20 generator->Do##type(this); \
21 }
22LITHIUM_CONCRETE_INSTRUCTION_LIST(DEFINE_COMPILE)
23#undef DEFINE_COMPILE
24
Ben Murdoch3ef787d2012-04-12 10:51:47 +010025#ifdef DEBUG
26void LInstruction::VerifyCall() {
27 // Call instructions can use only fixed registers as temporaries and
28 // outputs because all registers are blocked by the calling convention.
29 // Inputs operands must use a fixed register or use-at-start policy or
30 // a non-register policy.
Ben Murdochb8a8cc12014-11-26 15:28:44 +000031 DCHECK(Output() == NULL ||
Ben Murdoch3ef787d2012-04-12 10:51:47 +010032 LUnallocated::cast(Output())->HasFixedPolicy() ||
33 !LUnallocated::cast(Output())->HasRegisterPolicy());
34 for (UseIterator it(this); !it.Done(); it.Advance()) {
35 LUnallocated* operand = LUnallocated::cast(it.Current());
Ben Murdochb8a8cc12014-11-26 15:28:44 +000036 DCHECK(operand->HasFixedPolicy() ||
Ben Murdoch3ef787d2012-04-12 10:51:47 +010037 operand->IsUsedAtStart());
38 }
39 for (TempIterator it(this); !it.Done(); it.Advance()) {
40 LUnallocated* operand = LUnallocated::cast(it.Current());
Ben Murdochb8a8cc12014-11-26 15:28:44 +000041 DCHECK(operand->HasFixedPolicy() ||!operand->HasRegisterPolicy());
Ben Murdoch3ef787d2012-04-12 10:51:47 +010042 }
43}
44#endif
45
46
Ben Murdoch3ef787d2012-04-12 10:51:47 +010047void LInstruction::PrintTo(StringStream* stream) {
48 stream->Add("%s ", this->Mnemonic());
49
50 PrintOutputOperandTo(stream);
51
52 PrintDataTo(stream);
53
54 if (HasEnvironment()) {
55 stream->Add(" ");
56 environment()->PrintTo(stream);
57 }
58
59 if (HasPointerMap()) {
60 stream->Add(" ");
61 pointer_map()->PrintTo(stream);
62 }
63}
64
65
Ben Murdochb8a8cc12014-11-26 15:28:44 +000066void LInstruction::PrintDataTo(StringStream* stream) {
Ben Murdoch3ef787d2012-04-12 10:51:47 +010067 stream->Add("= ");
Ben Murdochb8a8cc12014-11-26 15:28:44 +000068 for (int i = 0; i < InputCount(); i++) {
Ben Murdoch3ef787d2012-04-12 10:51:47 +010069 if (i > 0) stream->Add(" ");
Ben Murdochb8a8cc12014-11-26 15:28:44 +000070 if (InputAt(i) == NULL) {
71 stream->Add("NULL");
72 } else {
73 InputAt(i)->PrintTo(stream);
74 }
Ben Murdoch3ef787d2012-04-12 10:51:47 +010075 }
76}
77
78
Ben Murdochb8a8cc12014-11-26 15:28:44 +000079void LInstruction::PrintOutputOperandTo(StringStream* stream) {
80 if (HasResult()) result()->PrintTo(stream);
Ben Murdoch3ef787d2012-04-12 10:51:47 +010081}
82
83
84void LLabel::PrintDataTo(StringStream* stream) {
85 LGap::PrintDataTo(stream);
86 LLabel* rep = replacement();
87 if (rep != NULL) {
88 stream->Add(" Dead block replaced with B%d", rep->block_id());
89 }
90}
91
92
93bool LGap::IsRedundant() const {
94 for (int i = 0; i < 4; i++) {
95 if (parallel_moves_[i] != NULL && !parallel_moves_[i]->IsRedundant()) {
96 return false;
97 }
98 }
99
100 return true;
101}
102
103
104void LGap::PrintDataTo(StringStream* stream) {
105 for (int i = 0; i < 4; i++) {
106 stream->Add("(");
107 if (parallel_moves_[i] != NULL) {
108 parallel_moves_[i]->PrintDataTo(stream);
109 }
110 stream->Add(") ");
111 }
112}
113
114
115const char* LArithmeticD::Mnemonic() const {
116 switch (op()) {
117 case Token::ADD: return "add-d";
118 case Token::SUB: return "sub-d";
119 case Token::MUL: return "mul-d";
120 case Token::DIV: return "div-d";
121 case Token::MOD: return "mod-d";
122 default:
123 UNREACHABLE();
124 return NULL;
125 }
126}
127
128
129const char* LArithmeticT::Mnemonic() const {
130 switch (op()) {
131 case Token::ADD: return "add-t";
132 case Token::SUB: return "sub-t";
133 case Token::MUL: return "mul-t";
134 case Token::MOD: return "mod-t";
135 case Token::DIV: return "div-t";
136 case Token::BIT_AND: return "bit-and-t";
137 case Token::BIT_OR: return "bit-or-t";
138 case Token::BIT_XOR: return "bit-xor-t";
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000139 case Token::ROR: return "ror-t";
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100140 case Token::SHL: return "sll-t";
141 case Token::SAR: return "sra-t";
142 case Token::SHR: return "srl-t";
143 default:
144 UNREACHABLE();
145 return NULL;
146 }
147}
148
149
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000150bool LGoto::HasInterestingComment(LCodeGen* gen) const {
151 return !gen->IsNextEmittedBlock(block_id());
152}
153
154
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100155void LGoto::PrintDataTo(StringStream* stream) {
156 stream->Add("B%d", block_id());
157}
158
159
160void LBranch::PrintDataTo(StringStream* stream) {
161 stream->Add("B%d | B%d on ", true_block_id(), false_block_id());
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000162 value()->PrintTo(stream);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100163}
164
165
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000166LInstruction* LChunkBuilder::DoDebugBreak(HDebugBreak* instr) {
167 return new(zone()) LDebugBreak();
168}
169
170
171void LCompareNumericAndBranch::PrintDataTo(StringStream* stream) {
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100172 stream->Add("if ");
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000173 left()->PrintTo(stream);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100174 stream->Add(" %s ", Token::String(op()));
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000175 right()->PrintTo(stream);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100176 stream->Add(" then B%d else B%d", true_block_id(), false_block_id());
177}
178
179
180void LIsObjectAndBranch::PrintDataTo(StringStream* stream) {
181 stream->Add("if is_object(");
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000182 value()->PrintTo(stream);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100183 stream->Add(") then B%d else B%d", true_block_id(), false_block_id());
184}
185
186
187void LIsStringAndBranch::PrintDataTo(StringStream* stream) {
188 stream->Add("if is_string(");
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000189 value()->PrintTo(stream);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100190 stream->Add(") then B%d else B%d", true_block_id(), false_block_id());
191}
192
193
194void LIsSmiAndBranch::PrintDataTo(StringStream* stream) {
195 stream->Add("if is_smi(");
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000196 value()->PrintTo(stream);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100197 stream->Add(") then B%d else B%d", true_block_id(), false_block_id());
198}
199
200
201void LIsUndetectableAndBranch::PrintDataTo(StringStream* stream) {
202 stream->Add("if is_undetectable(");
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000203 value()->PrintTo(stream);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100204 stream->Add(") then B%d else B%d", true_block_id(), false_block_id());
205}
206
207
208void LStringCompareAndBranch::PrintDataTo(StringStream* stream) {
209 stream->Add("if string_compare(");
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000210 left()->PrintTo(stream);
211 right()->PrintTo(stream);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100212 stream->Add(") then B%d else B%d", true_block_id(), false_block_id());
213}
214
215
216void LHasInstanceTypeAndBranch::PrintDataTo(StringStream* stream) {
217 stream->Add("if has_instance_type(");
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000218 value()->PrintTo(stream);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100219 stream->Add(") then B%d else B%d", true_block_id(), false_block_id());
220}
221
222
223void LHasCachedArrayIndexAndBranch::PrintDataTo(StringStream* stream) {
224 stream->Add("if has_cached_array_index(");
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000225 value()->PrintTo(stream);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100226 stream->Add(") then B%d else B%d", true_block_id(), false_block_id());
227}
228
229
230void LClassOfTestAndBranch::PrintDataTo(StringStream* stream) {
231 stream->Add("if class_of_test(");
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000232 value()->PrintTo(stream);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100233 stream->Add(", \"%o\") then B%d else B%d",
234 *hydrogen()->class_name(),
235 true_block_id(),
236 false_block_id());
237}
238
239
240void LTypeofIsAndBranch::PrintDataTo(StringStream* stream) {
241 stream->Add("if typeof ");
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000242 value()->PrintTo(stream);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100243 stream->Add(" == \"%s\" then B%d else B%d",
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000244 hydrogen()->type_literal()->ToCString().get(),
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100245 true_block_id(), false_block_id());
246}
247
248
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000249void LStoreCodeEntry::PrintDataTo(StringStream* stream) {
250 stream->Add(" = ");
251 function()->PrintTo(stream);
252 stream->Add(".code_entry = ");
253 code_object()->PrintTo(stream);
254}
255
256
257void LInnerAllocatedObject::PrintDataTo(StringStream* stream) {
258 stream->Add(" = ");
259 base_object()->PrintTo(stream);
260 stream->Add(" + ");
261 offset()->PrintTo(stream);
262}
263
264
265void LCallJSFunction::PrintDataTo(StringStream* stream) {
266 stream->Add("= ");
267 function()->PrintTo(stream);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100268 stream->Add("#%d / ", arity());
269}
270
271
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000272void LCallWithDescriptor::PrintDataTo(StringStream* stream) {
273 for (int i = 0; i < InputCount(); i++) {
274 InputAt(i)->PrintTo(stream);
275 stream->Add(" ");
276 }
277 stream->Add("#%d / ", arity());
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100278}
279
280
281void LLoadContextSlot::PrintDataTo(StringStream* stream) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000282 context()->PrintTo(stream);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100283 stream->Add("[%d]", slot_index());
284}
285
286
287void LStoreContextSlot::PrintDataTo(StringStream* stream) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000288 context()->PrintTo(stream);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100289 stream->Add("[%d] <- ", slot_index());
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000290 value()->PrintTo(stream);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100291}
292
293
294void LInvokeFunction::PrintDataTo(StringStream* stream) {
295 stream->Add("= ");
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000296 function()->PrintTo(stream);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100297 stream->Add(" #%d / ", arity());
298}
299
300
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100301void LCallNew::PrintDataTo(StringStream* stream) {
302 stream->Add("= ");
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000303 constructor()->PrintTo(stream);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100304 stream->Add(" #%d / ", arity());
305}
306
307
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000308void LCallNewArray::PrintDataTo(StringStream* stream) {
309 stream->Add("= ");
310 constructor()->PrintTo(stream);
311 stream->Add(" #%d / ", arity());
312 ElementsKind kind = hydrogen()->elements_kind();
313 stream->Add(" (%s) ", ElementsKindToString(kind));
314}
315
316
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100317void LAccessArgumentsAt::PrintDataTo(StringStream* stream) {
318 arguments()->PrintTo(stream);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100319 stream->Add(" length ");
320 length()->PrintTo(stream);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100321 stream->Add(" index ");
322 index()->PrintTo(stream);
323}
324
325
326void LStoreNamedField::PrintDataTo(StringStream* stream) {
327 object()->PrintTo(stream);
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400328 std::ostringstream os;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000329 os << hydrogen()->access() << " <- ";
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400330 stream->Add(os.str().c_str());
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100331 value()->PrintTo(stream);
332}
333
334
335void LStoreNamedGeneric::PrintDataTo(StringStream* stream) {
336 object()->PrintTo(stream);
337 stream->Add(".");
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000338 stream->Add(String::cast(*name())->ToCString().get());
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100339 stream->Add(" <- ");
340 value()->PrintTo(stream);
341}
342
343
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000344void LLoadKeyed::PrintDataTo(StringStream* stream) {
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100345 elements()->PrintTo(stream);
346 stream->Add("[");
347 key()->PrintTo(stream);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000348 if (hydrogen()->IsDehoisted()) {
349 stream->Add(" + %d]", base_offset());
350 } else {
351 stream->Add("]");
352 }
353}
354
355
356void LStoreKeyed::PrintDataTo(StringStream* stream) {
357 elements()->PrintTo(stream);
358 stream->Add("[");
359 key()->PrintTo(stream);
360 if (hydrogen()->IsDehoisted()) {
361 stream->Add(" + %d] <-", base_offset());
362 } else {
363 stream->Add("] <- ");
364 }
365
366 if (value() == NULL) {
367 DCHECK(hydrogen()->IsConstantHoleStore() &&
368 hydrogen()->value()->representation().IsDouble());
369 stream->Add("<the hole(nan)>");
370 } else {
371 value()->PrintTo(stream);
372 }
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100373}
374
375
376void LStoreKeyedGeneric::PrintDataTo(StringStream* stream) {
377 object()->PrintTo(stream);
378 stream->Add("[");
379 key()->PrintTo(stream);
380 stream->Add("] <- ");
381 value()->PrintTo(stream);
382}
383
384
385void LTransitionElementsKind::PrintDataTo(StringStream* stream) {
386 object()->PrintTo(stream);
387 stream->Add(" %p -> %p", *original_map(), *transitioned_map());
388}
389
390
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000391int LPlatformChunk::GetNextSpillIndex(RegisterKind kind) {
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100392 // Skip a slot if for a double-width slot.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000393 if (kind == DOUBLE_REGISTERS) spill_slot_count_++;
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100394 return spill_slot_count_++;
395}
396
397
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000398LOperand* LPlatformChunk::GetNextSpillSlot(RegisterKind kind) {
399 int index = GetNextSpillIndex(kind);
400 if (kind == DOUBLE_REGISTERS) {
401 return LDoubleStackSlot::Create(index, zone());
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100402 } else {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000403 DCHECK(kind == GENERAL_REGISTERS);
404 return LStackSlot::Create(index, zone());
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100405 }
406}
407
408
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000409LPlatformChunk* LChunkBuilder::Build() {
410 DCHECK(is_unused());
411 chunk_ = new(zone()) LPlatformChunk(info(), graph());
412 LPhase phase("L_Building chunk", chunk_);
413 status_ = BUILDING;
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100414
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000415 // If compiling for OSR, reserve space for the unoptimized frame,
416 // which will be subsumed into this frame.
417 if (graph()->has_osr()) {
418 for (int i = graph()->osr()->UnoptimizedFrameSlots(); i > 0; i--) {
419 chunk_->GetNextSpillIndex(GENERAL_REGISTERS);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100420 }
421 }
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100422
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100423 const ZoneList<HBasicBlock*>* blocks = graph()->blocks();
424 for (int i = 0; i < blocks->length(); i++) {
425 HBasicBlock* next = NULL;
426 if (i < blocks->length() - 1) next = blocks->at(i + 1);
427 DoBasicBlock(blocks->at(i), next);
428 if (is_aborted()) return NULL;
429 }
430 status_ = DONE;
431 return chunk_;
432}
433
434
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100435LUnallocated* LChunkBuilder::ToUnallocated(Register reg) {
436 return new(zone()) LUnallocated(LUnallocated::FIXED_REGISTER,
437 Register::ToAllocationIndex(reg));
438}
439
440
441LUnallocated* LChunkBuilder::ToUnallocated(DoubleRegister reg) {
442 return new(zone()) LUnallocated(LUnallocated::FIXED_DOUBLE_REGISTER,
443 DoubleRegister::ToAllocationIndex(reg));
444}
445
446
447LOperand* LChunkBuilder::UseFixed(HValue* value, Register fixed_register) {
448 return Use(value, ToUnallocated(fixed_register));
449}
450
451
452LOperand* LChunkBuilder::UseFixedDouble(HValue* value, DoubleRegister reg) {
453 return Use(value, ToUnallocated(reg));
454}
455
456
457LOperand* LChunkBuilder::UseRegister(HValue* value) {
458 return Use(value, new(zone()) LUnallocated(LUnallocated::MUST_HAVE_REGISTER));
459}
460
461
462LOperand* LChunkBuilder::UseRegisterAtStart(HValue* value) {
463 return Use(value,
464 new(zone()) LUnallocated(LUnallocated::MUST_HAVE_REGISTER,
465 LUnallocated::USED_AT_START));
466}
467
468
469LOperand* LChunkBuilder::UseTempRegister(HValue* value) {
470 return Use(value, new(zone()) LUnallocated(LUnallocated::WRITABLE_REGISTER));
471}
472
473
474LOperand* LChunkBuilder::Use(HValue* value) {
475 return Use(value, new(zone()) LUnallocated(LUnallocated::NONE));
476}
477
478
479LOperand* LChunkBuilder::UseAtStart(HValue* value) {
480 return Use(value, new(zone()) LUnallocated(LUnallocated::NONE,
481 LUnallocated::USED_AT_START));
482}
483
484
485LOperand* LChunkBuilder::UseOrConstant(HValue* value) {
486 return value->IsConstant()
487 ? chunk_->DefineConstantOperand(HConstant::cast(value))
488 : Use(value);
489}
490
491
492LOperand* LChunkBuilder::UseOrConstantAtStart(HValue* value) {
493 return value->IsConstant()
494 ? chunk_->DefineConstantOperand(HConstant::cast(value))
495 : UseAtStart(value);
496}
497
498
499LOperand* LChunkBuilder::UseRegisterOrConstant(HValue* value) {
500 return value->IsConstant()
501 ? chunk_->DefineConstantOperand(HConstant::cast(value))
502 : UseRegister(value);
503}
504
505
506LOperand* LChunkBuilder::UseRegisterOrConstantAtStart(HValue* value) {
507 return value->IsConstant()
508 ? chunk_->DefineConstantOperand(HConstant::cast(value))
509 : UseRegisterAtStart(value);
510}
511
512
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000513LOperand* LChunkBuilder::UseConstant(HValue* value) {
514 return chunk_->DefineConstantOperand(HConstant::cast(value));
515}
516
517
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100518LOperand* LChunkBuilder::UseAny(HValue* value) {
519 return value->IsConstant()
520 ? chunk_->DefineConstantOperand(HConstant::cast(value))
521 : Use(value, new(zone()) LUnallocated(LUnallocated::ANY));
522}
523
524
525LOperand* LChunkBuilder::Use(HValue* value, LUnallocated* operand) {
526 if (value->EmitAtUses()) {
527 HInstruction* instr = HInstruction::cast(value);
528 VisitInstruction(instr);
529 }
530 operand->set_virtual_register(value->id());
531 return operand;
532}
533
534
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000535LInstruction* LChunkBuilder::Define(LTemplateResultInstruction<1>* instr,
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100536 LUnallocated* result) {
537 result->set_virtual_register(current_instruction_->id());
538 instr->set_result(result);
539 return instr;
540}
541
542
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100543LInstruction* LChunkBuilder::DefineAsRegister(
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000544 LTemplateResultInstruction<1>* instr) {
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100545 return Define(instr,
546 new(zone()) LUnallocated(LUnallocated::MUST_HAVE_REGISTER));
547}
548
549
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100550LInstruction* LChunkBuilder::DefineAsSpilled(
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000551 LTemplateResultInstruction<1>* instr, int index) {
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100552 return Define(instr,
553 new(zone()) LUnallocated(LUnallocated::FIXED_SLOT, index));
554}
555
556
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100557LInstruction* LChunkBuilder::DefineSameAsFirst(
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000558 LTemplateResultInstruction<1>* instr) {
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100559 return Define(instr,
560 new(zone()) LUnallocated(LUnallocated::SAME_AS_FIRST_INPUT));
561}
562
563
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100564LInstruction* LChunkBuilder::DefineFixed(
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000565 LTemplateResultInstruction<1>* instr, Register reg) {
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100566 return Define(instr, ToUnallocated(reg));
567}
568
569
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100570LInstruction* LChunkBuilder::DefineFixedDouble(
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000571 LTemplateResultInstruction<1>* instr, DoubleRegister reg) {
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100572 return Define(instr, ToUnallocated(reg));
573}
574
575
576LInstruction* LChunkBuilder::AssignEnvironment(LInstruction* instr) {
577 HEnvironment* hydrogen_env = current_block_->last_environment();
578 int argument_index_accumulator = 0;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000579 ZoneList<HValue*> objects_to_materialize(0, zone());
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100580 instr->set_environment(CreateEnvironment(hydrogen_env,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000581 &argument_index_accumulator,
582 &objects_to_materialize));
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100583 return instr;
584}
585
586
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100587LInstruction* LChunkBuilder::MarkAsCall(LInstruction* instr,
588 HInstruction* hinstr,
589 CanDeoptimize can_deoptimize) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000590 info()->MarkAsNonDeferredCalling();
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100591#ifdef DEBUG
592 instr->VerifyCall();
593#endif
594 instr->MarkAsCall();
595 instr = AssignPointerMap(instr);
596
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100597 // If instruction does not have side-effects lazy deoptimization
598 // after the call will try to deoptimize to the point before the call.
599 // Thus we still need to attach environment to this call even if
600 // call sequence can not deoptimize eagerly.
601 bool needs_environment =
602 (can_deoptimize == CAN_DEOPTIMIZE_EAGERLY) ||
603 !hinstr->HasObservableSideEffects();
604 if (needs_environment && !instr->HasEnvironment()) {
605 instr = AssignEnvironment(instr);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000606 // We can't really figure out if the environment is needed or not.
607 instr->environment()->set_has_been_used();
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100608 }
609
610 return instr;
611}
612
613
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100614LInstruction* LChunkBuilder::AssignPointerMap(LInstruction* instr) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000615 DCHECK(!instr->HasPointerMap());
616 instr->set_pointer_map(new(zone()) LPointerMap(zone()));
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100617 return instr;
618}
619
620
621LUnallocated* LChunkBuilder::TempRegister() {
622 LUnallocated* operand =
623 new(zone()) LUnallocated(LUnallocated::MUST_HAVE_REGISTER);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000624 int vreg = allocator_->GetVirtualRegister();
625 if (!allocator_->AllocationOk()) {
626 Abort(kOutOfVirtualRegistersWhileTryingToAllocateTempRegister);
627 vreg = 0;
628 }
629 operand->set_virtual_register(vreg);
630 return operand;
631}
632
633
634LUnallocated* LChunkBuilder::TempDoubleRegister() {
635 LUnallocated* operand =
636 new(zone()) LUnallocated(LUnallocated::MUST_HAVE_DOUBLE_REGISTER);
637 int vreg = allocator_->GetVirtualRegister();
638 if (!allocator_->AllocationOk()) {
639 Abort(kOutOfVirtualRegistersWhileTryingToAllocateTempRegister);
640 vreg = 0;
641 }
642 operand->set_virtual_register(vreg);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100643 return operand;
644}
645
646
647LOperand* LChunkBuilder::FixedTemp(Register reg) {
648 LUnallocated* operand = ToUnallocated(reg);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000649 DCHECK(operand->HasFixedPolicy());
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100650 return operand;
651}
652
653
654LOperand* LChunkBuilder::FixedTemp(DoubleRegister reg) {
655 LUnallocated* operand = ToUnallocated(reg);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000656 DCHECK(operand->HasFixedPolicy());
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100657 return operand;
658}
659
660
661LInstruction* LChunkBuilder::DoBlockEntry(HBlockEntry* instr) {
662 return new(zone()) LLabel(instr->block());
663}
664
665
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000666LInstruction* LChunkBuilder::DoDummyUse(HDummyUse* instr) {
667 return DefineAsRegister(new(zone()) LDummyUse(UseAny(instr->value())));
668}
669
670
671LInstruction* LChunkBuilder::DoEnvironmentMarker(HEnvironmentMarker* instr) {
672 UNREACHABLE();
673 return NULL;
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100674}
675
676
677LInstruction* LChunkBuilder::DoDeoptimize(HDeoptimize* instr) {
678 return AssignEnvironment(new(zone()) LDeoptimize);
679}
680
681
682LInstruction* LChunkBuilder::DoShift(Token::Value op,
683 HBitwiseBinaryOperation* instr) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000684 if (instr->representation().IsSmiOrInteger32()) {
685 DCHECK(instr->left()->representation().Equals(instr->representation()));
686 DCHECK(instr->right()->representation().Equals(instr->representation()));
687 LOperand* left = UseRegisterAtStart(instr->left());
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100688
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000689 HValue* right_value = instr->right();
690 LOperand* right = NULL;
691 int constant_value = 0;
692 bool does_deopt = false;
693 if (right_value->IsConstant()) {
694 HConstant* constant = HConstant::cast(right_value);
695 right = chunk_->DefineConstantOperand(constant);
696 constant_value = constant->Integer32Value() & 0x1f;
697 // Left shifts can deoptimize if we shift by > 0 and the result cannot be
698 // truncated to smi.
699 if (instr->representation().IsSmi() && constant_value > 0) {
700 does_deopt = !instr->CheckUsesForFlag(HValue::kTruncatingToSmi);
701 }
702 } else {
703 right = UseRegisterAtStart(right_value);
704 }
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100705
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000706 // Shift operations can only deoptimize if we do a logical shift
707 // by 0 and the result cannot be truncated to int32.
708 if (op == Token::SHR && constant_value == 0) {
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400709 does_deopt = !instr->CheckFlag(HInstruction::kUint32);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100710 }
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100711
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000712 LInstruction* result =
713 DefineAsRegister(new(zone()) LShiftI(op, left, right, does_deopt));
714 return does_deopt ? AssignEnvironment(result) : result;
715 } else {
716 return DoArithmeticT(op, instr);
717 }
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100718}
719
720
721LInstruction* LChunkBuilder::DoArithmeticD(Token::Value op,
722 HArithmeticBinaryOperation* instr) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000723 DCHECK(instr->representation().IsDouble());
724 DCHECK(instr->left()->representation().IsDouble());
725 DCHECK(instr->right()->representation().IsDouble());
726 if (op == Token::MOD) {
727 LOperand* left = UseFixedDouble(instr->left(), f2);
728 LOperand* right = UseFixedDouble(instr->right(), f4);
729 LArithmeticD* result = new(zone()) LArithmeticD(op, left, right);
730 // We call a C function for double modulo. It can't trigger a GC. We need
731 // to use fixed result register for the call.
732 // TODO(fschneider): Allow any register as input registers.
733 return MarkAsCall(DefineFixedDouble(result, f2), instr);
734 } else {
735 LOperand* left = UseRegisterAtStart(instr->left());
736 LOperand* right = UseRegisterAtStart(instr->right());
737 LArithmeticD* result = new(zone()) LArithmeticD(op, left, right);
738 return DefineAsRegister(result);
739 }
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100740}
741
742
743LInstruction* LChunkBuilder::DoArithmeticT(Token::Value op,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000744 HBinaryOperation* instr) {
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100745 HValue* left = instr->left();
746 HValue* right = instr->right();
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000747 DCHECK(left->representation().IsTagged());
748 DCHECK(right->representation().IsTagged());
749 LOperand* context = UseFixed(instr->context(), cp);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100750 LOperand* left_operand = UseFixed(left, a1);
751 LOperand* right_operand = UseFixed(right, a0);
752 LArithmeticT* result =
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000753 new(zone()) LArithmeticT(op, context, left_operand, right_operand);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100754 return MarkAsCall(DefineFixed(result, v0), instr);
755}
756
757
758void LChunkBuilder::DoBasicBlock(HBasicBlock* block, HBasicBlock* next_block) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000759 DCHECK(is_building());
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100760 current_block_ = block;
761 next_block_ = next_block;
762 if (block->IsStartBlock()) {
763 block->UpdateEnvironment(graph_->start_environment());
764 argument_count_ = 0;
765 } else if (block->predecessors()->length() == 1) {
766 // We have a single predecessor => copy environment and outgoing
767 // argument count from the predecessor.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000768 DCHECK(block->phis()->length() == 0);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100769 HBasicBlock* pred = block->predecessors()->at(0);
770 HEnvironment* last_environment = pred->last_environment();
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000771 DCHECK(last_environment != NULL);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100772 // Only copy the environment, if it is later used again.
773 if (pred->end()->SecondSuccessor() == NULL) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000774 DCHECK(pred->end()->FirstSuccessor() == block);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100775 } else {
776 if (pred->end()->FirstSuccessor()->block_id() > block->block_id() ||
777 pred->end()->SecondSuccessor()->block_id() > block->block_id()) {
778 last_environment = last_environment->Copy();
779 }
780 }
781 block->UpdateEnvironment(last_environment);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000782 DCHECK(pred->argument_count() >= 0);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100783 argument_count_ = pred->argument_count();
784 } else {
785 // We are at a state join => process phis.
786 HBasicBlock* pred = block->predecessors()->at(0);
787 // No need to copy the environment, it cannot be used later.
788 HEnvironment* last_environment = pred->last_environment();
789 for (int i = 0; i < block->phis()->length(); ++i) {
790 HPhi* phi = block->phis()->at(i);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000791 if (phi->HasMergedIndex()) {
792 last_environment->SetValueAt(phi->merged_index(), phi);
793 }
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100794 }
795 for (int i = 0; i < block->deleted_phis()->length(); ++i) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000796 if (block->deleted_phis()->at(i) < last_environment->length()) {
797 last_environment->SetValueAt(block->deleted_phis()->at(i),
798 graph_->GetConstantUndefined());
799 }
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100800 }
801 block->UpdateEnvironment(last_environment);
802 // Pick up the outgoing argument count of one of the predecessors.
803 argument_count_ = pred->argument_count();
804 }
805 HInstruction* current = block->first();
806 int start = chunk_->instructions()->length();
807 while (current != NULL && !is_aborted()) {
808 // Code for constants in registers is generated lazily.
809 if (!current->EmitAtUses()) {
810 VisitInstruction(current);
811 }
812 current = current->next();
813 }
814 int end = chunk_->instructions()->length() - 1;
815 if (end >= start) {
816 block->set_first_instruction_index(start);
817 block->set_last_instruction_index(end);
818 }
819 block->set_argument_count(argument_count_);
820 next_block_ = NULL;
821 current_block_ = NULL;
822}
823
824
825void LChunkBuilder::VisitInstruction(HInstruction* current) {
826 HInstruction* old_current = current_instruction_;
827 current_instruction_ = current;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000828
829 LInstruction* instr = NULL;
830 if (current->CanReplaceWithDummyUses()) {
831 if (current->OperandCount() == 0) {
832 instr = DefineAsRegister(new(zone()) LDummy());
833 } else {
834 DCHECK(!current->OperandAt(0)->IsControlInstruction());
835 instr = DefineAsRegister(new(zone())
836 LDummyUse(UseAny(current->OperandAt(0))));
837 }
838 for (int i = 1; i < current->OperandCount(); ++i) {
839 if (current->OperandAt(i)->IsControlInstruction()) continue;
840 LInstruction* dummy =
841 new(zone()) LDummyUse(UseAny(current->OperandAt(i)));
842 dummy->set_hydrogen_value(current);
843 chunk_->AddInstruction(dummy, current_block_);
844 }
845 } else {
846 HBasicBlock* successor;
847 if (current->IsControlInstruction() &&
848 HControlInstruction::cast(current)->KnownSuccessorBlock(&successor) &&
849 successor != NULL) {
850 instr = new(zone()) LGoto(successor);
851 } else {
852 instr = current->CompileToLithium(this);
853 }
854 }
855
856 argument_count_ += current->argument_delta();
857 DCHECK(argument_count_ >= 0);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100858
859 if (instr != NULL) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000860 AddInstruction(instr, current);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100861 }
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000862
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100863 current_instruction_ = old_current;
864}
865
866
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000867void LChunkBuilder::AddInstruction(LInstruction* instr,
868 HInstruction* hydrogen_val) {
869// Associate the hydrogen instruction first, since we may need it for
870 // the ClobbersRegisters() or ClobbersDoubleRegisters() calls below.
871 instr->set_hydrogen_value(hydrogen_val);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100872
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000873#if DEBUG
874 // Make sure that the lithium instruction has either no fixed register
875 // constraints in temps or the result OR no uses that are only used at
876 // start. If this invariant doesn't hold, the register allocator can decide
877 // to insert a split of a range immediately before the instruction due to an
878 // already allocated register needing to be used for the instruction's fixed
879 // register constraint. In this case, The register allocator won't see an
880 // interference between the split child and the use-at-start (it would if
881 // the it was just a plain use), so it is free to move the split child into
882 // the same register that is used for the use-at-start.
883 // See https://code.google.com/p/chromium/issues/detail?id=201590
884 if (!(instr->ClobbersRegisters() &&
885 instr->ClobbersDoubleRegisters(isolate()))) {
886 int fixed = 0;
887 int used_at_start = 0;
888 for (UseIterator it(instr); !it.Done(); it.Advance()) {
889 LUnallocated* operand = LUnallocated::cast(it.Current());
890 if (operand->IsUsedAtStart()) ++used_at_start;
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100891 }
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000892 if (instr->Output() != NULL) {
893 if (LUnallocated::cast(instr->Output())->HasFixedPolicy()) ++fixed;
894 }
895 for (TempIterator it(instr); !it.Done(); it.Advance()) {
896 LUnallocated* operand = LUnallocated::cast(it.Current());
897 if (operand->HasFixedPolicy()) ++fixed;
898 }
899 DCHECK(fixed == 0 || used_at_start == 0);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100900 }
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000901#endif
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100902
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000903 if (FLAG_stress_pointer_maps && !instr->HasPointerMap()) {
904 instr = AssignPointerMap(instr);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100905 }
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000906 if (FLAG_stress_environments && !instr->HasEnvironment()) {
907 instr = AssignEnvironment(instr);
908 }
909 chunk_->AddInstruction(instr, current_block_);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100910
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000911 if (instr->IsCall()) {
912 HValue* hydrogen_value_for_lazy_bailout = hydrogen_val;
913 LInstruction* instruction_needing_environment = NULL;
914 if (hydrogen_val->HasObservableSideEffects()) {
915 HSimulate* sim = HSimulate::cast(hydrogen_val->next());
916 instruction_needing_environment = instr;
917 sim->ReplayEnvironment(current_block_->last_environment());
918 hydrogen_value_for_lazy_bailout = sim;
919 }
920 LInstruction* bailout = AssignEnvironment(new(zone()) LLazyBailout());
921 bailout->set_hydrogen_value(hydrogen_value_for_lazy_bailout);
922 chunk_->AddInstruction(bailout, current_block_);
923 if (instruction_needing_environment != NULL) {
924 // Store the lazy deopt environment with the instruction if needed.
925 // Right now it is only used for LInstanceOfKnownGlobal.
926 instruction_needing_environment->
927 SetDeferredLazyDeoptimizationEnvironment(bailout->environment());
928 }
929 }
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100930}
931
932
933LInstruction* LChunkBuilder::DoGoto(HGoto* instr) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000934 return new(zone()) LGoto(instr->FirstSuccessor());
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100935}
936
937
938LInstruction* LChunkBuilder::DoBranch(HBranch* instr) {
939 HValue* value = instr->value();
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000940 Representation r = value->representation();
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100941 HType type = value->type();
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000942 ToBooleanStub::Types expected = instr->expected_input_types();
943 if (expected.IsEmpty()) expected = ToBooleanStub::Types::Generic();
944
945 bool easy_case = !r.IsTagged() || type.IsBoolean() || type.IsSmi() ||
946 type.IsJSArray() || type.IsHeapNumber() || type.IsString();
947 LInstruction* branch = new(zone()) LBranch(UseRegister(value));
948 if (!easy_case &&
949 ((!expected.Contains(ToBooleanStub::SMI) && expected.NeedsMap()) ||
950 !expected.IsGeneric())) {
951 branch = AssignEnvironment(branch);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100952 }
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000953 return branch;
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100954}
955
956
957LInstruction* LChunkBuilder::DoCompareMap(HCompareMap* instr) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000958 DCHECK(instr->value()->representation().IsTagged());
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100959 LOperand* value = UseRegisterAtStart(instr->value());
960 LOperand* temp = TempRegister();
961 return new(zone()) LCmpMapAndBranch(value, temp);
962}
963
964
965LInstruction* LChunkBuilder::DoArgumentsLength(HArgumentsLength* length) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000966 info()->MarkAsRequiresFrame();
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100967 return DefineAsRegister(
968 new(zone()) LArgumentsLength(UseRegister(length->value())));
969}
970
971
972LInstruction* LChunkBuilder::DoArgumentsElements(HArgumentsElements* elems) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000973 info()->MarkAsRequiresFrame();
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100974 return DefineAsRegister(new(zone()) LArgumentsElements);
975}
976
977
978LInstruction* LChunkBuilder::DoInstanceOf(HInstanceOf* instr) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000979 LOperand* context = UseFixed(instr->context(), cp);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100980 LInstanceOf* result =
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000981 new(zone()) LInstanceOf(context, UseFixed(instr->left(), a0),
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100982 UseFixed(instr->right(), a1));
983 return MarkAsCall(DefineFixed(result, v0), instr);
984}
985
986
987LInstruction* LChunkBuilder::DoInstanceOfKnownGlobal(
988 HInstanceOfKnownGlobal* instr) {
989 LInstanceOfKnownGlobal* result =
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000990 new(zone()) LInstanceOfKnownGlobal(
991 UseFixed(instr->context(), cp),
992 UseFixed(instr->left(), a0),
993 FixedTemp(t0));
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100994 return MarkAsCall(DefineFixed(result, v0), instr);
995}
996
997
998LInstruction* LChunkBuilder::DoWrapReceiver(HWrapReceiver* instr) {
999 LOperand* receiver = UseRegisterAtStart(instr->receiver());
1000 LOperand* function = UseRegisterAtStart(instr->function());
1001 LWrapReceiver* result = new(zone()) LWrapReceiver(receiver, function);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001002 return AssignEnvironment(DefineAsRegister(result));
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001003}
1004
1005
1006LInstruction* LChunkBuilder::DoApplyArguments(HApplyArguments* instr) {
1007 LOperand* function = UseFixed(instr->function(), a1);
1008 LOperand* receiver = UseFixed(instr->receiver(), a0);
1009 LOperand* length = UseFixed(instr->length(), a2);
1010 LOperand* elements = UseFixed(instr->elements(), a3);
1011 LApplyArguments* result = new(zone()) LApplyArguments(function,
1012 receiver,
1013 length,
1014 elements);
1015 return MarkAsCall(DefineFixed(result, v0), instr, CAN_DEOPTIMIZE_EAGERLY);
1016}
1017
1018
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001019LInstruction* LChunkBuilder::DoPushArguments(HPushArguments* instr) {
1020 int argc = instr->OperandCount();
1021 for (int i = 0; i < argc; ++i) {
1022 LOperand* argument = Use(instr->argument(i));
1023 AddInstruction(new(zone()) LPushArgument(argument), instr);
1024 }
1025 return NULL;
1026}
1027
1028
1029LInstruction* LChunkBuilder::DoStoreCodeEntry(
1030 HStoreCodeEntry* store_code_entry) {
1031 LOperand* function = UseRegister(store_code_entry->function());
1032 LOperand* code_object = UseTempRegister(store_code_entry->code_object());
1033 return new(zone()) LStoreCodeEntry(function, code_object);
1034}
1035
1036
1037LInstruction* LChunkBuilder::DoInnerAllocatedObject(
1038 HInnerAllocatedObject* instr) {
1039 LOperand* base_object = UseRegisterAtStart(instr->base_object());
1040 LOperand* offset = UseRegisterOrConstantAtStart(instr->offset());
1041 return DefineAsRegister(
1042 new(zone()) LInnerAllocatedObject(base_object, offset));
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001043}
1044
1045
1046LInstruction* LChunkBuilder::DoThisFunction(HThisFunction* instr) {
1047 return instr->HasNoUses()
1048 ? NULL
1049 : DefineAsRegister(new(zone()) LThisFunction);
1050}
1051
1052
1053LInstruction* LChunkBuilder::DoContext(HContext* instr) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001054 if (instr->HasNoUses()) return NULL;
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001055
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001056 if (info()->IsStub()) {
1057 return DefineFixed(new(zone()) LContext, cp);
1058 }
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001059
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001060 return DefineAsRegister(new(zone()) LContext);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001061}
1062
1063
1064LInstruction* LChunkBuilder::DoDeclareGlobals(HDeclareGlobals* instr) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001065 LOperand* context = UseFixed(instr->context(), cp);
1066 return MarkAsCall(new(zone()) LDeclareGlobals(context), instr);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001067}
1068
1069
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001070LInstruction* LChunkBuilder::DoCallJSFunction(
1071 HCallJSFunction* instr) {
1072 LOperand* function = UseFixed(instr->function(), a1);
1073
1074 LCallJSFunction* result = new(zone()) LCallJSFunction(function);
1075
1076 return MarkAsCall(DefineFixed(result, v0), instr);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001077}
1078
1079
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001080LInstruction* LChunkBuilder::DoCallWithDescriptor(
1081 HCallWithDescriptor* instr) {
1082 CallInterfaceDescriptor descriptor = instr->descriptor();
1083
1084 LOperand* target = UseRegisterOrConstantAtStart(instr->target());
1085 ZoneList<LOperand*> ops(instr->OperandCount(), zone());
1086 ops.Add(target, zone());
1087 for (int i = 1; i < instr->OperandCount(); i++) {
1088 LOperand* op =
1089 UseFixed(instr->OperandAt(i), descriptor.GetParameterRegister(i - 1));
1090 ops.Add(op, zone());
1091 }
1092
1093 LCallWithDescriptor* result = new(zone()) LCallWithDescriptor(
1094 descriptor, ops, zone());
1095 return MarkAsCall(DefineFixed(result, v0), instr);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001096}
1097
1098
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001099LInstruction* LChunkBuilder::DoTailCallThroughMegamorphicCache(
1100 HTailCallThroughMegamorphicCache* instr) {
1101 LOperand* context = UseFixed(instr->context(), cp);
1102 LOperand* receiver_register =
1103 UseFixed(instr->receiver(), LoadDescriptor::ReceiverRegister());
1104 LOperand* name_register =
1105 UseFixed(instr->name(), LoadDescriptor::NameRegister());
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001106 LOperand* slot = NULL;
1107 LOperand* vector = NULL;
1108 if (FLAG_vector_ics) {
1109 slot = UseFixed(instr->slot(), VectorLoadICDescriptor::SlotRegister());
1110 vector =
1111 UseFixed(instr->vector(), VectorLoadICDescriptor::VectorRegister());
1112 }
1113
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001114 // Not marked as call. It can't deoptimize, and it never returns.
1115 return new (zone()) LTailCallThroughMegamorphicCache(
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001116 context, receiver_register, name_register, slot, vector);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001117}
1118
1119
1120LInstruction* LChunkBuilder::DoInvokeFunction(HInvokeFunction* instr) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001121 LOperand* context = UseFixed(instr->context(), cp);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001122 LOperand* function = UseFixed(instr->function(), a1);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001123 LInvokeFunction* result = new(zone()) LInvokeFunction(context, function);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001124 return MarkAsCall(DefineFixed(result, v0), instr, CANNOT_DEOPTIMIZE_EAGERLY);
1125}
1126
1127
1128LInstruction* LChunkBuilder::DoUnaryMathOperation(HUnaryMathOperation* instr) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001129 switch (instr->op()) {
1130 case kMathFloor:
1131 return DoMathFloor(instr);
1132 case kMathRound:
1133 return DoMathRound(instr);
1134 case kMathFround:
1135 return DoMathFround(instr);
1136 case kMathAbs:
1137 return DoMathAbs(instr);
1138 case kMathLog:
1139 return DoMathLog(instr);
1140 case kMathExp:
1141 return DoMathExp(instr);
1142 case kMathSqrt:
1143 return DoMathSqrt(instr);
1144 case kMathPowHalf:
1145 return DoMathPowHalf(instr);
1146 case kMathClz32:
1147 return DoMathClz32(instr);
1148 default:
1149 UNREACHABLE();
1150 return NULL;
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001151 }
1152}
1153
1154
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001155LInstruction* LChunkBuilder::DoMathLog(HUnaryMathOperation* instr) {
1156 DCHECK(instr->representation().IsDouble());
1157 DCHECK(instr->value()->representation().IsDouble());
1158 LOperand* input = UseFixedDouble(instr->value(), f4);
1159 return MarkAsCall(DefineFixedDouble(new(zone()) LMathLog(input), f4), instr);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001160}
1161
1162
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001163LInstruction* LChunkBuilder::DoMathClz32(HUnaryMathOperation* instr) {
1164 LOperand* input = UseRegisterAtStart(instr->value());
1165 LMathClz32* result = new(zone()) LMathClz32(input);
1166 return DefineAsRegister(result);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001167}
1168
1169
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001170LInstruction* LChunkBuilder::DoMathExp(HUnaryMathOperation* instr) {
1171 DCHECK(instr->representation().IsDouble());
1172 DCHECK(instr->value()->representation().IsDouble());
1173 LOperand* input = UseRegister(instr->value());
1174 LOperand* temp1 = TempRegister();
1175 LOperand* temp2 = TempRegister();
1176 LOperand* double_temp = TempDoubleRegister();
1177 LMathExp* result = new(zone()) LMathExp(input, double_temp, temp1, temp2);
1178 return DefineAsRegister(result);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001179}
1180
1181
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001182LInstruction* LChunkBuilder::DoMathPowHalf(HUnaryMathOperation* instr) {
1183 // Input cannot be the same as the result, see LCodeGen::DoMathPowHalf.
1184 LOperand* input = UseFixedDouble(instr->value(), f8);
1185 LOperand* temp = TempDoubleRegister();
1186 LMathPowHalf* result = new(zone()) LMathPowHalf(input, temp);
1187 return DefineFixedDouble(result, f4);
1188}
1189
1190
1191LInstruction* LChunkBuilder::DoMathFround(HUnaryMathOperation* instr) {
1192 LOperand* input = UseRegister(instr->value());
1193 LMathFround* result = new (zone()) LMathFround(input);
1194 return DefineAsRegister(result);
1195}
1196
1197
1198LInstruction* LChunkBuilder::DoMathAbs(HUnaryMathOperation* instr) {
1199 Representation r = instr->value()->representation();
1200 LOperand* context = (r.IsDouble() || r.IsSmiOrInteger32())
1201 ? NULL
1202 : UseFixed(instr->context(), cp);
1203 LOperand* input = UseRegister(instr->value());
1204 LInstruction* result =
1205 DefineAsRegister(new(zone()) LMathAbs(context, input));
1206 if (!r.IsDouble() && !r.IsSmiOrInteger32()) result = AssignPointerMap(result);
1207 if (!r.IsDouble()) result = AssignEnvironment(result);
1208 return result;
1209}
1210
1211
1212LInstruction* LChunkBuilder::DoMathFloor(HUnaryMathOperation* instr) {
1213 LOperand* input = UseRegister(instr->value());
1214 LOperand* temp = TempRegister();
1215 LMathFloor* result = new(zone()) LMathFloor(input, temp);
1216 return AssignEnvironment(AssignPointerMap(DefineAsRegister(result)));
1217}
1218
1219
1220LInstruction* LChunkBuilder::DoMathSqrt(HUnaryMathOperation* instr) {
1221 LOperand* input = UseRegister(instr->value());
1222 LMathSqrt* result = new(zone()) LMathSqrt(input);
1223 return DefineAsRegister(result);
1224}
1225
1226
1227LInstruction* LChunkBuilder::DoMathRound(HUnaryMathOperation* instr) {
1228 LOperand* input = UseRegister(instr->value());
1229 LOperand* temp = TempDoubleRegister();
1230 LMathRound* result = new(zone()) LMathRound(input, temp);
1231 return AssignEnvironment(DefineAsRegister(result));
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001232}
1233
1234
1235LInstruction* LChunkBuilder::DoCallNew(HCallNew* instr) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001236 LOperand* context = UseFixed(instr->context(), cp);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001237 LOperand* constructor = UseFixed(instr->constructor(), a1);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001238 LCallNew* result = new(zone()) LCallNew(context, constructor);
1239 return MarkAsCall(DefineFixed(result, v0), instr);
1240}
1241
1242
1243LInstruction* LChunkBuilder::DoCallNewArray(HCallNewArray* instr) {
1244 LOperand* context = UseFixed(instr->context(), cp);
1245 LOperand* constructor = UseFixed(instr->constructor(), a1);
1246 LCallNewArray* result = new(zone()) LCallNewArray(context, constructor);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001247 return MarkAsCall(DefineFixed(result, v0), instr);
1248}
1249
1250
1251LInstruction* LChunkBuilder::DoCallFunction(HCallFunction* instr) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001252 LOperand* context = UseFixed(instr->context(), cp);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001253 LOperand* function = UseFixed(instr->function(), a1);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001254 LCallFunction* call = new(zone()) LCallFunction(context, function);
1255 return MarkAsCall(DefineFixed(call, v0), instr);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001256}
1257
1258
1259LInstruction* LChunkBuilder::DoCallRuntime(HCallRuntime* instr) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001260 LOperand* context = UseFixed(instr->context(), cp);
1261 return MarkAsCall(DefineFixed(new(zone()) LCallRuntime(context), v0), instr);
1262}
1263
1264
1265LInstruction* LChunkBuilder::DoRor(HRor* instr) {
1266 return DoShift(Token::ROR, instr);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001267}
1268
1269
1270LInstruction* LChunkBuilder::DoShr(HShr* instr) {
1271 return DoShift(Token::SHR, instr);
1272}
1273
1274
1275LInstruction* LChunkBuilder::DoSar(HSar* instr) {
1276 return DoShift(Token::SAR, instr);
1277}
1278
1279
1280LInstruction* LChunkBuilder::DoShl(HShl* instr) {
1281 return DoShift(Token::SHL, instr);
1282}
1283
1284
1285LInstruction* LChunkBuilder::DoBitwise(HBitwise* instr) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001286 if (instr->representation().IsSmiOrInteger32()) {
1287 DCHECK(instr->left()->representation().Equals(instr->representation()));
1288 DCHECK(instr->right()->representation().Equals(instr->representation()));
1289 DCHECK(instr->CheckFlag(HValue::kTruncatingToInt32));
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001290
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001291 LOperand* left = UseRegisterAtStart(instr->BetterLeftOperand());
1292 LOperand* right = UseOrConstantAtStart(instr->BetterRightOperand());
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001293 return DefineAsRegister(new(zone()) LBitI(left, right));
1294 } else {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001295 return DoArithmeticT(instr->op(), instr);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001296 }
1297}
1298
1299
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001300LInstruction* LChunkBuilder::DoDivByPowerOf2I(HDiv* instr) {
1301 DCHECK(instr->representation().IsSmiOrInteger32());
1302 DCHECK(instr->left()->representation().Equals(instr->representation()));
1303 DCHECK(instr->right()->representation().Equals(instr->representation()));
1304 LOperand* dividend = UseRegister(instr->left());
1305 int32_t divisor = instr->right()->GetInteger32Constant();
1306 LInstruction* result = DefineAsRegister(new(zone()) LDivByPowerOf2I(
1307 dividend, divisor));
1308 if ((instr->CheckFlag(HValue::kBailoutOnMinusZero) && divisor < 0) ||
1309 (instr->CheckFlag(HValue::kCanOverflow) && divisor == -1) ||
1310 (!instr->CheckFlag(HInstruction::kAllUsesTruncatingToInt32) &&
1311 divisor != 1 && divisor != -1)) {
1312 result = AssignEnvironment(result);
1313 }
1314 return result;
1315}
1316
1317
1318LInstruction* LChunkBuilder::DoDivByConstI(HDiv* instr) {
1319 DCHECK(instr->representation().IsInteger32());
1320 DCHECK(instr->left()->representation().Equals(instr->representation()));
1321 DCHECK(instr->right()->representation().Equals(instr->representation()));
1322 LOperand* dividend = UseRegister(instr->left());
1323 int32_t divisor = instr->right()->GetInteger32Constant();
1324 LInstruction* result = DefineAsRegister(new(zone()) LDivByConstI(
1325 dividend, divisor));
1326 if (divisor == 0 ||
1327 (instr->CheckFlag(HValue::kBailoutOnMinusZero) && divisor < 0) ||
1328 !instr->CheckFlag(HInstruction::kAllUsesTruncatingToInt32)) {
1329 result = AssignEnvironment(result);
1330 }
1331 return result;
1332}
1333
1334
1335LInstruction* LChunkBuilder::DoDivI(HDiv* instr) {
1336 DCHECK(instr->representation().IsSmiOrInteger32());
1337 DCHECK(instr->left()->representation().Equals(instr->representation()));
1338 DCHECK(instr->right()->representation().Equals(instr->representation()));
1339 LOperand* dividend = UseRegister(instr->left());
1340 LOperand* divisor = UseRegister(instr->right());
1341 LOperand* temp = TempRegister();
1342 LInstruction* result =
1343 DefineAsRegister(new(zone()) LDivI(dividend, divisor, temp));
1344 if (instr->CheckFlag(HValue::kCanBeDivByZero) ||
1345 instr->CheckFlag(HValue::kBailoutOnMinusZero) ||
1346 (instr->CheckFlag(HValue::kCanOverflow) &&
1347 !instr->CheckFlag(HValue::kAllUsesTruncatingToInt32)) ||
1348 (!instr->IsMathFloorOfDiv() &&
1349 !instr->CheckFlag(HValue::kAllUsesTruncatingToInt32))) {
1350 result = AssignEnvironment(result);
1351 }
1352 return result;
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001353}
1354
1355
1356LInstruction* LChunkBuilder::DoDiv(HDiv* instr) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001357 if (instr->representation().IsSmiOrInteger32()) {
1358 if (instr->RightIsPowerOf2()) {
1359 return DoDivByPowerOf2I(instr);
1360 } else if (instr->right()->IsConstant()) {
1361 return DoDivByConstI(instr);
1362 } else {
1363 return DoDivI(instr);
1364 }
1365 } else if (instr->representation().IsDouble()) {
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001366 return DoArithmeticD(Token::DIV, instr);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001367 } else {
1368 return DoArithmeticT(Token::DIV, instr);
1369 }
1370}
1371
1372
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001373LInstruction* LChunkBuilder::DoFlooringDivByPowerOf2I(HMathFloorOfDiv* instr) {
1374 LOperand* dividend = UseRegisterAtStart(instr->left());
1375 int32_t divisor = instr->right()->GetInteger32Constant();
1376 LInstruction* result = DefineAsRegister(new(zone()) LFlooringDivByPowerOf2I(
1377 dividend, divisor));
1378 if ((instr->CheckFlag(HValue::kBailoutOnMinusZero) && divisor < 0) ||
1379 (instr->CheckFlag(HValue::kLeftCanBeMinInt) && divisor == -1)) {
1380 result = AssignEnvironment(result);
1381 }
1382 return result;
1383}
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001384
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001385
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001386LInstruction* LChunkBuilder::DoFlooringDivByConstI(HMathFloorOfDiv* instr) {
1387 DCHECK(instr->representation().IsInteger32());
1388 DCHECK(instr->left()->representation().Equals(instr->representation()));
1389 DCHECK(instr->right()->representation().Equals(instr->representation()));
1390 LOperand* dividend = UseRegister(instr->left());
1391 int32_t divisor = instr->right()->GetInteger32Constant();
1392 LOperand* temp =
1393 ((divisor > 0 && !instr->CheckFlag(HValue::kLeftCanBeNegative)) ||
1394 (divisor < 0 && !instr->CheckFlag(HValue::kLeftCanBePositive))) ?
1395 NULL : TempRegister();
1396 LInstruction* result = DefineAsRegister(
1397 new(zone()) LFlooringDivByConstI(dividend, divisor, temp));
1398 if (divisor == 0 ||
1399 (instr->CheckFlag(HValue::kBailoutOnMinusZero) && divisor < 0)) {
1400 result = AssignEnvironment(result);
1401 }
1402 return result;
1403}
1404
1405
1406LInstruction* LChunkBuilder::DoFlooringDivI(HMathFloorOfDiv* instr) {
1407 DCHECK(instr->representation().IsSmiOrInteger32());
1408 DCHECK(instr->left()->representation().Equals(instr->representation()));
1409 DCHECK(instr->right()->representation().Equals(instr->representation()));
1410 LOperand* dividend = UseRegister(instr->left());
1411 LOperand* divisor = UseRegister(instr->right());
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001412 LInstruction* result =
1413 DefineAsRegister(new (zone()) LFlooringDivI(dividend, divisor));
1414 if (instr->CheckFlag(HValue::kCanBeDivByZero) ||
1415 instr->CheckFlag(HValue::kBailoutOnMinusZero) ||
1416 (instr->CheckFlag(HValue::kCanOverflow))) {
1417 result = AssignEnvironment(result);
1418 }
1419 return result;
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001420}
1421
1422
1423LInstruction* LChunkBuilder::DoMathFloorOfDiv(HMathFloorOfDiv* instr) {
1424 if (instr->RightIsPowerOf2()) {
1425 return DoFlooringDivByPowerOf2I(instr);
1426 } else if (instr->right()->IsConstant()) {
1427 return DoFlooringDivByConstI(instr);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001428 } else {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001429 return DoFlooringDivI(instr);
1430 }
1431}
1432
1433
1434LInstruction* LChunkBuilder::DoModByPowerOf2I(HMod* instr) {
1435 DCHECK(instr->representation().IsSmiOrInteger32());
1436 DCHECK(instr->left()->representation().Equals(instr->representation()));
1437 DCHECK(instr->right()->representation().Equals(instr->representation()));
1438 LOperand* dividend = UseRegisterAtStart(instr->left());
1439 int32_t divisor = instr->right()->GetInteger32Constant();
1440 LInstruction* result = DefineSameAsFirst(new(zone()) LModByPowerOf2I(
1441 dividend, divisor));
1442 if (instr->CheckFlag(HValue::kLeftCanBeNegative) &&
1443 instr->CheckFlag(HValue::kBailoutOnMinusZero)) {
1444 result = AssignEnvironment(result);
1445 }
1446 return result;
1447}
1448
1449
1450LInstruction* LChunkBuilder::DoModByConstI(HMod* instr) {
1451 DCHECK(instr->representation().IsSmiOrInteger32());
1452 DCHECK(instr->left()->representation().Equals(instr->representation()));
1453 DCHECK(instr->right()->representation().Equals(instr->representation()));
1454 LOperand* dividend = UseRegister(instr->left());
1455 int32_t divisor = instr->right()->GetInteger32Constant();
1456 LInstruction* result = DefineAsRegister(new(zone()) LModByConstI(
1457 dividend, divisor));
1458 if (divisor == 0 || instr->CheckFlag(HValue::kBailoutOnMinusZero)) {
1459 result = AssignEnvironment(result);
1460 }
1461 return result;
1462}
1463
1464
1465LInstruction* LChunkBuilder::DoModI(HMod* instr) {
1466 DCHECK(instr->representation().IsSmiOrInteger32());
1467 DCHECK(instr->left()->representation().Equals(instr->representation()));
1468 DCHECK(instr->right()->representation().Equals(instr->representation()));
1469 LOperand* dividend = UseRegister(instr->left());
1470 LOperand* divisor = UseRegister(instr->right());
1471 LInstruction* result = DefineAsRegister(new(zone()) LModI(
1472 dividend, divisor));
1473 if (instr->CheckFlag(HValue::kCanBeDivByZero) ||
1474 instr->CheckFlag(HValue::kBailoutOnMinusZero)) {
1475 result = AssignEnvironment(result);
1476 }
1477 return result;
1478}
1479
1480
1481LInstruction* LChunkBuilder::DoMod(HMod* instr) {
1482 if (instr->representation().IsSmiOrInteger32()) {
1483 return instr->RightIsPowerOf2() ? DoModByPowerOf2I(instr) : DoModI(instr);
1484 } else if (instr->representation().IsDouble()) {
1485 return DoArithmeticD(Token::MOD, instr);
1486 } else {
1487 return DoArithmeticT(Token::MOD, instr);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001488 }
1489}
1490
1491
1492LInstruction* LChunkBuilder::DoMul(HMul* instr) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001493 if (instr->representation().IsSmiOrInteger32()) {
1494 DCHECK(instr->left()->representation().Equals(instr->representation()));
1495 DCHECK(instr->right()->representation().Equals(instr->representation()));
1496 HValue* left = instr->BetterLeftOperand();
1497 HValue* right = instr->BetterRightOperand();
1498 LOperand* left_op;
1499 LOperand* right_op;
1500 bool can_overflow = instr->CheckFlag(HValue::kCanOverflow);
1501 bool bailout_on_minus_zero = instr->CheckFlag(HValue::kBailoutOnMinusZero);
1502
1503 if (right->IsConstant()) {
1504 HConstant* constant = HConstant::cast(right);
1505 int32_t constant_value = constant->Integer32Value();
1506 // Constants -1, 0 and 1 can be optimized if the result can overflow.
1507 // For other constants, it can be optimized only without overflow.
1508 if (!can_overflow || ((constant_value >= -1) && (constant_value <= 1))) {
1509 left_op = UseRegisterAtStart(left);
1510 right_op = UseConstant(right);
1511 } else {
1512 if (bailout_on_minus_zero) {
1513 left_op = UseRegister(left);
1514 } else {
1515 left_op = UseRegisterAtStart(left);
1516 }
1517 right_op = UseRegister(right);
1518 }
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001519 } else {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001520 if (bailout_on_minus_zero) {
1521 left_op = UseRegister(left);
1522 } else {
1523 left_op = UseRegisterAtStart(left);
1524 }
1525 right_op = UseRegister(right);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001526 }
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001527 LMulI* mul = new(zone()) LMulI(left_op, right_op);
1528 if (can_overflow || bailout_on_minus_zero) {
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001529 AssignEnvironment(mul);
1530 }
1531 return DefineAsRegister(mul);
1532
1533 } else if (instr->representation().IsDouble()) {
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001534 if (IsMipsArchVariant(kMips32r2)) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001535 if (instr->HasOneUse() && instr->uses().value()->IsAdd()) {
1536 HAdd* add = HAdd::cast(instr->uses().value());
1537 if (instr == add->left()) {
1538 // This mul is the lhs of an add. The add and mul will be folded
1539 // into a multiply-add.
1540 return NULL;
1541 }
1542 if (instr == add->right() && !add->left()->IsMul()) {
1543 // This mul is the rhs of an add, where the lhs is not another mul.
1544 // The add and mul will be folded into a multiply-add.
1545 return NULL;
1546 }
1547 }
1548 }
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001549 return DoArithmeticD(Token::MUL, instr);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001550 } else {
1551 return DoArithmeticT(Token::MUL, instr);
1552 }
1553}
1554
1555
1556LInstruction* LChunkBuilder::DoSub(HSub* instr) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001557 if (instr->representation().IsSmiOrInteger32()) {
1558 DCHECK(instr->left()->representation().Equals(instr->representation()));
1559 DCHECK(instr->right()->representation().Equals(instr->representation()));
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001560 LOperand* left = UseRegisterAtStart(instr->left());
1561 LOperand* right = UseOrConstantAtStart(instr->right());
1562 LSubI* sub = new(zone()) LSubI(left, right);
1563 LInstruction* result = DefineAsRegister(sub);
1564 if (instr->CheckFlag(HValue::kCanOverflow)) {
1565 result = AssignEnvironment(result);
1566 }
1567 return result;
1568 } else if (instr->representation().IsDouble()) {
1569 return DoArithmeticD(Token::SUB, instr);
1570 } else {
1571 return DoArithmeticT(Token::SUB, instr);
1572 }
1573}
1574
1575
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001576LInstruction* LChunkBuilder::DoMultiplyAdd(HMul* mul, HValue* addend) {
1577 LOperand* multiplier_op = UseRegisterAtStart(mul->left());
1578 LOperand* multiplicand_op = UseRegisterAtStart(mul->right());
1579 LOperand* addend_op = UseRegisterAtStart(addend);
1580 return DefineSameAsFirst(new(zone()) LMultiplyAddD(addend_op, multiplier_op,
1581 multiplicand_op));
1582}
1583
1584
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001585LInstruction* LChunkBuilder::DoAdd(HAdd* instr) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001586 if (instr->representation().IsSmiOrInteger32()) {
1587 DCHECK(instr->left()->representation().Equals(instr->representation()));
1588 DCHECK(instr->right()->representation().Equals(instr->representation()));
1589 LOperand* left = UseRegisterAtStart(instr->BetterLeftOperand());
1590 LOperand* right = UseOrConstantAtStart(instr->BetterRightOperand());
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001591 LAddI* add = new(zone()) LAddI(left, right);
1592 LInstruction* result = DefineAsRegister(add);
1593 if (instr->CheckFlag(HValue::kCanOverflow)) {
1594 result = AssignEnvironment(result);
1595 }
1596 return result;
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001597 } else if (instr->representation().IsExternal()) {
1598 DCHECK(instr->left()->representation().IsExternal());
1599 DCHECK(instr->right()->representation().IsInteger32());
1600 DCHECK(!instr->CheckFlag(HValue::kCanOverflow));
1601 LOperand* left = UseRegisterAtStart(instr->left());
1602 LOperand* right = UseOrConstantAtStart(instr->right());
1603 LAddI* add = new(zone()) LAddI(left, right);
1604 LInstruction* result = DefineAsRegister(add);
1605 return result;
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001606 } else if (instr->representation().IsDouble()) {
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001607 if (IsMipsArchVariant(kMips32r2)) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001608 if (instr->left()->IsMul())
1609 return DoMultiplyAdd(HMul::cast(instr->left()), instr->right());
1610
1611 if (instr->right()->IsMul()) {
1612 DCHECK(!instr->left()->IsMul());
1613 return DoMultiplyAdd(HMul::cast(instr->right()), instr->left());
1614 }
1615 }
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001616 return DoArithmeticD(Token::ADD, instr);
1617 } else {
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001618 return DoArithmeticT(Token::ADD, instr);
1619 }
1620}
1621
1622
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001623LInstruction* LChunkBuilder::DoMathMinMax(HMathMinMax* instr) {
1624 LOperand* left = NULL;
1625 LOperand* right = NULL;
1626 if (instr->representation().IsSmiOrInteger32()) {
1627 DCHECK(instr->left()->representation().Equals(instr->representation()));
1628 DCHECK(instr->right()->representation().Equals(instr->representation()));
1629 left = UseRegisterAtStart(instr->BetterLeftOperand());
1630 right = UseOrConstantAtStart(instr->BetterRightOperand());
1631 } else {
1632 DCHECK(instr->representation().IsDouble());
1633 DCHECK(instr->left()->representation().IsDouble());
1634 DCHECK(instr->right()->representation().IsDouble());
1635 left = UseRegisterAtStart(instr->left());
1636 right = UseRegisterAtStart(instr->right());
1637 }
1638 return DefineAsRegister(new(zone()) LMathMinMax(left, right));
1639}
1640
1641
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001642LInstruction* LChunkBuilder::DoPower(HPower* instr) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001643 DCHECK(instr->representation().IsDouble());
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001644 // We call a C function for double power. It can't trigger a GC.
1645 // We need to use fixed result register for the call.
1646 Representation exponent_type = instr->right()->representation();
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001647 DCHECK(instr->left()->representation().IsDouble());
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001648 LOperand* left = UseFixedDouble(instr->left(), f2);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001649 LOperand* right =
1650 exponent_type.IsDouble()
1651 ? UseFixedDouble(instr->right(), f4)
1652 : UseFixed(instr->right(), MathPowTaggedDescriptor::exponent());
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001653 LPower* result = new(zone()) LPower(left, right);
1654 return MarkAsCall(DefineFixedDouble(result, f0),
1655 instr,
1656 CAN_DEOPTIMIZE_EAGERLY);
1657}
1658
1659
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001660LInstruction* LChunkBuilder::DoCompareGeneric(HCompareGeneric* instr) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001661 DCHECK(instr->left()->representation().IsTagged());
1662 DCHECK(instr->right()->representation().IsTagged());
1663 LOperand* context = UseFixed(instr->context(), cp);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001664 LOperand* left = UseFixed(instr->left(), a1);
1665 LOperand* right = UseFixed(instr->right(), a0);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001666 LCmpT* result = new(zone()) LCmpT(context, left, right);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001667 return MarkAsCall(DefineFixed(result, v0), instr);
1668}
1669
1670
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001671LInstruction* LChunkBuilder::DoCompareNumericAndBranch(
1672 HCompareNumericAndBranch* instr) {
1673 Representation r = instr->representation();
1674 if (r.IsSmiOrInteger32()) {
1675 DCHECK(instr->left()->representation().Equals(r));
1676 DCHECK(instr->right()->representation().Equals(r));
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001677 LOperand* left = UseRegisterOrConstantAtStart(instr->left());
1678 LOperand* right = UseRegisterOrConstantAtStart(instr->right());
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001679 return new(zone()) LCompareNumericAndBranch(left, right);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001680 } else {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001681 DCHECK(r.IsDouble());
1682 DCHECK(instr->left()->representation().IsDouble());
1683 DCHECK(instr->right()->representation().IsDouble());
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001684 LOperand* left = UseRegisterAtStart(instr->left());
1685 LOperand* right = UseRegisterAtStart(instr->right());
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001686 return new(zone()) LCompareNumericAndBranch(left, right);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001687 }
1688}
1689
1690
1691LInstruction* LChunkBuilder::DoCompareObjectEqAndBranch(
1692 HCompareObjectEqAndBranch* instr) {
1693 LOperand* left = UseRegisterAtStart(instr->left());
1694 LOperand* right = UseRegisterAtStart(instr->right());
1695 return new(zone()) LCmpObjectEqAndBranch(left, right);
1696}
1697
1698
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001699LInstruction* LChunkBuilder::DoCompareHoleAndBranch(
1700 HCompareHoleAndBranch* instr) {
1701 LOperand* value = UseRegisterAtStart(instr->value());
1702 return new(zone()) LCmpHoleAndBranch(value);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001703}
1704
1705
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001706LInstruction* LChunkBuilder::DoCompareMinusZeroAndBranch(
1707 HCompareMinusZeroAndBranch* instr) {
1708 LOperand* value = UseRegister(instr->value());
1709 LOperand* scratch = TempRegister();
1710 return new(zone()) LCompareMinusZeroAndBranch(value, scratch);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001711}
1712
1713
1714LInstruction* LChunkBuilder::DoIsObjectAndBranch(HIsObjectAndBranch* instr) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001715 DCHECK(instr->value()->representation().IsTagged());
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001716 LOperand* temp = TempRegister();
1717 return new(zone()) LIsObjectAndBranch(UseRegisterAtStart(instr->value()),
1718 temp);
1719}
1720
1721
1722LInstruction* LChunkBuilder::DoIsStringAndBranch(HIsStringAndBranch* instr) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001723 DCHECK(instr->value()->representation().IsTagged());
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001724 LOperand* temp = TempRegister();
1725 return new(zone()) LIsStringAndBranch(UseRegisterAtStart(instr->value()),
1726 temp);
1727}
1728
1729
1730LInstruction* LChunkBuilder::DoIsSmiAndBranch(HIsSmiAndBranch* instr) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001731 DCHECK(instr->value()->representation().IsTagged());
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001732 return new(zone()) LIsSmiAndBranch(Use(instr->value()));
1733}
1734
1735
1736LInstruction* LChunkBuilder::DoIsUndetectableAndBranch(
1737 HIsUndetectableAndBranch* instr) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001738 DCHECK(instr->value()->representation().IsTagged());
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001739 return new(zone()) LIsUndetectableAndBranch(
1740 UseRegisterAtStart(instr->value()), TempRegister());
1741}
1742
1743
1744LInstruction* LChunkBuilder::DoStringCompareAndBranch(
1745 HStringCompareAndBranch* instr) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001746 DCHECK(instr->left()->representation().IsTagged());
1747 DCHECK(instr->right()->representation().IsTagged());
1748 LOperand* context = UseFixed(instr->context(), cp);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001749 LOperand* left = UseFixed(instr->left(), a1);
1750 LOperand* right = UseFixed(instr->right(), a0);
1751 LStringCompareAndBranch* result =
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001752 new(zone()) LStringCompareAndBranch(context, left, right);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001753 return MarkAsCall(result, instr);
1754}
1755
1756
1757LInstruction* LChunkBuilder::DoHasInstanceTypeAndBranch(
1758 HHasInstanceTypeAndBranch* instr) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001759 DCHECK(instr->value()->representation().IsTagged());
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001760 LOperand* value = UseRegisterAtStart(instr->value());
1761 return new(zone()) LHasInstanceTypeAndBranch(value);
1762}
1763
1764
1765LInstruction* LChunkBuilder::DoGetCachedArrayIndex(
1766 HGetCachedArrayIndex* instr) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001767 DCHECK(instr->value()->representation().IsTagged());
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001768 LOperand* value = UseRegisterAtStart(instr->value());
1769
1770 return DefineAsRegister(new(zone()) LGetCachedArrayIndex(value));
1771}
1772
1773
1774LInstruction* LChunkBuilder::DoHasCachedArrayIndexAndBranch(
1775 HHasCachedArrayIndexAndBranch* instr) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001776 DCHECK(instr->value()->representation().IsTagged());
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001777 return new(zone()) LHasCachedArrayIndexAndBranch(
1778 UseRegisterAtStart(instr->value()));
1779}
1780
1781
1782LInstruction* LChunkBuilder::DoClassOfTestAndBranch(
1783 HClassOfTestAndBranch* instr) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001784 DCHECK(instr->value()->representation().IsTagged());
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001785 return new(zone()) LClassOfTestAndBranch(UseRegister(instr->value()),
1786 TempRegister());
1787}
1788
1789
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001790LInstruction* LChunkBuilder::DoMapEnumLength(HMapEnumLength* instr) {
1791 LOperand* map = UseRegisterAtStart(instr->value());
1792 return DefineAsRegister(new(zone()) LMapEnumLength(map));
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001793}
1794
1795
1796LInstruction* LChunkBuilder::DoDateField(HDateField* instr) {
1797 LOperand* object = UseFixed(instr->value(), a0);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001798 LDateField* result =
1799 new(zone()) LDateField(object, FixedTemp(a1), instr->index());
1800 return MarkAsCall(DefineFixed(result, v0), instr, CAN_DEOPTIMIZE_EAGERLY);
1801}
1802
1803
1804LInstruction* LChunkBuilder::DoSeqStringGetChar(HSeqStringGetChar* instr) {
1805 LOperand* string = UseRegisterAtStart(instr->string());
1806 LOperand* index = UseRegisterOrConstantAtStart(instr->index());
1807 return DefineAsRegister(new(zone()) LSeqStringGetChar(string, index));
1808}
1809
1810
1811LInstruction* LChunkBuilder::DoSeqStringSetChar(HSeqStringSetChar* instr) {
1812 LOperand* string = UseRegisterAtStart(instr->string());
1813 LOperand* index = FLAG_debug_code
1814 ? UseRegisterAtStart(instr->index())
1815 : UseRegisterOrConstantAtStart(instr->index());
1816 LOperand* value = UseRegisterAtStart(instr->value());
1817 LOperand* context = FLAG_debug_code ? UseFixed(instr->context(), cp) : NULL;
1818 return new(zone()) LSeqStringSetChar(context, string, index, value);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001819}
1820
1821
1822LInstruction* LChunkBuilder::DoBoundsCheck(HBoundsCheck* instr) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001823 if (!FLAG_debug_code && instr->skip_check()) return NULL;
1824 LOperand* index = UseRegisterOrConstantAtStart(instr->index());
1825 LOperand* length = !index->IsConstantOperand()
1826 ? UseRegisterOrConstantAtStart(instr->length())
1827 : UseRegisterAtStart(instr->length());
1828 LInstruction* result = new(zone()) LBoundsCheck(index, length);
1829 if (!FLAG_debug_code || !instr->skip_check()) {
1830 result = AssignEnvironment(result);
1831 }
1832 return result;
1833}
1834
1835
1836LInstruction* LChunkBuilder::DoBoundsCheckBaseIndexInformation(
1837 HBoundsCheckBaseIndexInformation* instr) {
1838 UNREACHABLE();
1839 return NULL;
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001840}
1841
1842
1843LInstruction* LChunkBuilder::DoAbnormalExit(HAbnormalExit* instr) {
1844 // The control instruction marking the end of a block that completed
1845 // abruptly (e.g., threw an exception). There is nothing specific to do.
1846 return NULL;
1847}
1848
1849
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001850LInstruction* LChunkBuilder::DoUseConst(HUseConst* instr) {
1851 return NULL;
1852}
1853
1854
1855LInstruction* LChunkBuilder::DoForceRepresentation(HForceRepresentation* bad) {
1856 // All HForceRepresentation instructions should be eliminated in the
1857 // representation change phase of Hydrogen.
1858 UNREACHABLE();
1859 return NULL;
1860}
1861
1862
1863LInstruction* LChunkBuilder::DoChange(HChange* instr) {
1864 Representation from = instr->from();
1865 Representation to = instr->to();
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001866 HValue* val = instr->value();
1867 if (from.IsSmi()) {
1868 if (to.IsTagged()) {
1869 LOperand* value = UseRegister(val);
1870 return DefineSameAsFirst(new(zone()) LDummyUse(value));
1871 }
1872 from = Representation::Tagged();
1873 }
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001874 if (from.IsTagged()) {
1875 if (to.IsDouble()) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001876 LOperand* value = UseRegister(val);
1877 LInstruction* result = DefineAsRegister(new(zone()) LNumberUntagD(value));
1878 if (!val->representation().IsSmi()) result = AssignEnvironment(result);
1879 return result;
1880 } else if (to.IsSmi()) {
1881 LOperand* value = UseRegister(val);
1882 if (val->type().IsSmi()) {
1883 return DefineSameAsFirst(new(zone()) LDummyUse(value));
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001884 }
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001885 return AssignEnvironment(DefineSameAsFirst(new(zone()) LCheckSmi(value)));
1886 } else {
1887 DCHECK(to.IsInteger32());
1888 if (val->type().IsSmi() || val->representation().IsSmi()) {
1889 LOperand* value = UseRegisterAtStart(val);
1890 return DefineAsRegister(new(zone()) LSmiUntag(value, false));
1891 } else {
1892 LOperand* value = UseRegister(val);
1893 LOperand* temp1 = TempRegister();
1894 LOperand* temp2 = TempDoubleRegister();
1895 LInstruction* result =
1896 DefineSameAsFirst(new(zone()) LTaggedToI(value, temp1, temp2));
1897 if (!val->representation().IsSmi()) result = AssignEnvironment(result);
1898 return result;
1899 }
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001900 }
1901 } else if (from.IsDouble()) {
1902 if (to.IsTagged()) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001903 info()->MarkAsDeferredCalling();
1904 LOperand* value = UseRegister(val);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001905 LOperand* temp1 = TempRegister();
1906 LOperand* temp2 = TempRegister();
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001907 LUnallocated* result_temp = TempRegister();
1908 LNumberTagD* result = new(zone()) LNumberTagD(value, temp1, temp2);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001909 return AssignPointerMap(Define(result, result_temp));
1910 } else if (to.IsSmi()) {
1911 LOperand* value = UseRegister(val);
1912 return AssignEnvironment(
1913 DefineAsRegister(new(zone()) LDoubleToSmi(value)));
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001914 } else {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001915 DCHECK(to.IsInteger32());
1916 LOperand* value = UseRegister(val);
1917 LInstruction* result = DefineAsRegister(new(zone()) LDoubleToI(value));
1918 if (!instr->CanTruncateToInt32()) result = AssignEnvironment(result);
1919 return result;
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001920 }
1921 } else if (from.IsInteger32()) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001922 info()->MarkAsDeferredCalling();
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001923 if (to.IsTagged()) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001924 if (!instr->CheckFlag(HValue::kCanOverflow)) {
1925 LOperand* value = UseRegisterAtStart(val);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001926 return DefineAsRegister(new(zone()) LSmiTag(value));
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001927 } else if (val->CheckFlag(HInstruction::kUint32)) {
1928 LOperand* value = UseRegisterAtStart(val);
1929 LOperand* temp1 = TempRegister();
1930 LOperand* temp2 = TempRegister();
1931 LNumberTagU* result = new(zone()) LNumberTagU(value, temp1, temp2);
1932 return AssignPointerMap(DefineAsRegister(result));
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001933 } else {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001934 LOperand* value = UseRegisterAtStart(val);
1935 LOperand* temp1 = TempRegister();
1936 LOperand* temp2 = TempRegister();
1937 LNumberTagI* result = new(zone()) LNumberTagI(value, temp1, temp2);
1938 return AssignPointerMap(DefineAsRegister(result));
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001939 }
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001940 } else if (to.IsSmi()) {
1941 LOperand* value = UseRegister(val);
1942 LInstruction* result = DefineAsRegister(new(zone()) LSmiTag(value));
1943 if (instr->CheckFlag(HValue::kCanOverflow)) {
1944 result = AssignEnvironment(result);
1945 }
1946 return result;
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001947 } else {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001948 DCHECK(to.IsDouble());
1949 if (val->CheckFlag(HInstruction::kUint32)) {
1950 return DefineAsRegister(new(zone()) LUint32ToDouble(UseRegister(val)));
1951 } else {
1952 return DefineAsRegister(new(zone()) LInteger32ToDouble(Use(val)));
1953 }
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001954 }
1955 }
1956 UNREACHABLE();
1957 return NULL;
1958}
1959
1960
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001961LInstruction* LChunkBuilder::DoCheckHeapObject(HCheckHeapObject* instr) {
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001962 LOperand* value = UseRegisterAtStart(instr->value());
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001963 LInstruction* result = new(zone()) LCheckNonSmi(value);
1964 if (!instr->value()->type().IsHeapObject()) {
1965 result = AssignEnvironment(result);
1966 }
1967 return result;
1968}
1969
1970
1971LInstruction* LChunkBuilder::DoCheckSmi(HCheckSmi* instr) {
1972 LOperand* value = UseRegisterAtStart(instr->value());
1973 return AssignEnvironment(new(zone()) LCheckSmi(value));
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001974}
1975
1976
1977LInstruction* LChunkBuilder::DoCheckInstanceType(HCheckInstanceType* instr) {
1978 LOperand* value = UseRegisterAtStart(instr->value());
1979 LInstruction* result = new(zone()) LCheckInstanceType(value);
1980 return AssignEnvironment(result);
1981}
1982
1983
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001984LInstruction* LChunkBuilder::DoCheckValue(HCheckValue* instr) {
1985 LOperand* value = UseRegisterAtStart(instr->value());
1986 return AssignEnvironment(new(zone()) LCheckValue(value));
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001987}
1988
1989
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001990LInstruction* LChunkBuilder::DoCheckMaps(HCheckMaps* instr) {
1991 if (instr->IsStabilityCheck()) return new(zone()) LCheckMaps;
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001992 LOperand* value = UseRegisterAtStart(instr->value());
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001993 LInstruction* result = AssignEnvironment(new(zone()) LCheckMaps(value));
1994 if (instr->HasMigrationTarget()) {
1995 info()->MarkAsDeferredCalling();
1996 result = AssignPointerMap(result);
1997 }
1998 return result;
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001999}
2000
2001
2002LInstruction* LChunkBuilder::DoClampToUint8(HClampToUint8* instr) {
2003 HValue* value = instr->value();
2004 Representation input_rep = value->representation();
2005 LOperand* reg = UseRegister(value);
2006 if (input_rep.IsDouble()) {
2007 // Revisit this decision, here and 8 lines below.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002008 return DefineAsRegister(new(zone()) LClampDToUint8(reg,
2009 TempDoubleRegister()));
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002010 } else if (input_rep.IsInteger32()) {
2011 return DefineAsRegister(new(zone()) LClampIToUint8(reg));
2012 } else {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002013 DCHECK(input_rep.IsSmiOrTagged());
2014 LClampTToUint8* result =
2015 new(zone()) LClampTToUint8(reg, TempDoubleRegister());
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002016 return AssignEnvironment(DefineAsRegister(result));
2017 }
2018}
2019
2020
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002021LInstruction* LChunkBuilder::DoDoubleBits(HDoubleBits* instr) {
2022 HValue* value = instr->value();
2023 DCHECK(value->representation().IsDouble());
2024 return DefineAsRegister(new(zone()) LDoubleBits(UseRegister(value)));
2025}
2026
2027
2028LInstruction* LChunkBuilder::DoConstructDouble(HConstructDouble* instr) {
2029 LOperand* lo = UseRegister(instr->lo());
2030 LOperand* hi = UseRegister(instr->hi());
2031 return DefineAsRegister(new(zone()) LConstructDouble(hi, lo));
2032}
2033
2034
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002035LInstruction* LChunkBuilder::DoReturn(HReturn* instr) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002036 LOperand* context = info()->IsStub()
2037 ? UseFixed(instr->context(), cp)
2038 : NULL;
2039 LOperand* parameter_count = UseRegisterOrConstant(instr->parameter_count());
2040 return new(zone()) LReturn(UseFixed(instr->value(), v0), context,
2041 parameter_count);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002042}
2043
2044
2045LInstruction* LChunkBuilder::DoConstant(HConstant* instr) {
2046 Representation r = instr->representation();
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002047 if (r.IsSmi()) {
2048 return DefineAsRegister(new(zone()) LConstantS);
2049 } else if (r.IsInteger32()) {
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002050 return DefineAsRegister(new(zone()) LConstantI);
2051 } else if (r.IsDouble()) {
2052 return DefineAsRegister(new(zone()) LConstantD);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002053 } else if (r.IsExternal()) {
2054 return DefineAsRegister(new(zone()) LConstantE);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002055 } else if (r.IsTagged()) {
2056 return DefineAsRegister(new(zone()) LConstantT);
2057 } else {
2058 UNREACHABLE();
2059 return NULL;
2060 }
2061}
2062
2063
2064LInstruction* LChunkBuilder::DoLoadGlobalCell(HLoadGlobalCell* instr) {
2065 LLoadGlobalCell* result = new(zone()) LLoadGlobalCell;
2066 return instr->RequiresHoleCheck()
2067 ? AssignEnvironment(DefineAsRegister(result))
2068 : DefineAsRegister(result);
2069}
2070
2071
2072LInstruction* LChunkBuilder::DoLoadGlobalGeneric(HLoadGlobalGeneric* instr) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002073 LOperand* context = UseFixed(instr->context(), cp);
2074 LOperand* global_object =
2075 UseFixed(instr->global_object(), LoadDescriptor::ReceiverRegister());
2076 LOperand* vector = NULL;
Emily Bernierd0a1eb72015-03-24 16:35:39 -04002077 if (instr->HasVectorAndSlot()) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002078 vector = FixedTemp(VectorLoadICDescriptor::VectorRegister());
2079 }
2080 LLoadGlobalGeneric* result =
2081 new(zone()) LLoadGlobalGeneric(context, global_object, vector);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002082 return MarkAsCall(DefineFixed(result, v0), instr);
2083}
2084
2085
2086LInstruction* LChunkBuilder::DoStoreGlobalCell(HStoreGlobalCell* instr) {
2087 LOperand* value = UseRegister(instr->value());
2088 // Use a temp to check the value in the cell in the case where we perform
2089 // a hole check.
2090 return instr->RequiresHoleCheck()
2091 ? AssignEnvironment(new(zone()) LStoreGlobalCell(value, TempRegister()))
2092 : new(zone()) LStoreGlobalCell(value, NULL);
2093}
2094
2095
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002096LInstruction* LChunkBuilder::DoLoadContextSlot(HLoadContextSlot* instr) {
2097 LOperand* context = UseRegisterAtStart(instr->value());
2098 LInstruction* result =
2099 DefineAsRegister(new(zone()) LLoadContextSlot(context));
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002100 if (instr->RequiresHoleCheck() && instr->DeoptimizesOnHole()) {
2101 result = AssignEnvironment(result);
2102 }
2103 return result;
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002104}
2105
2106
2107LInstruction* LChunkBuilder::DoStoreContextSlot(HStoreContextSlot* instr) {
2108 LOperand* context;
2109 LOperand* value;
2110 if (instr->NeedsWriteBarrier()) {
2111 context = UseTempRegister(instr->context());
2112 value = UseTempRegister(instr->value());
2113 } else {
2114 context = UseRegister(instr->context());
2115 value = UseRegister(instr->value());
2116 }
2117 LInstruction* result = new(zone()) LStoreContextSlot(context, value);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002118 if (instr->RequiresHoleCheck() && instr->DeoptimizesOnHole()) {
2119 result = AssignEnvironment(result);
2120 }
2121 return result;
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002122}
2123
2124
2125LInstruction* LChunkBuilder::DoLoadNamedField(HLoadNamedField* instr) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002126 LOperand* obj = UseRegisterAtStart(instr->object());
2127 return DefineAsRegister(new(zone()) LLoadNamedField(obj));
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002128}
2129
2130
2131LInstruction* LChunkBuilder::DoLoadNamedGeneric(HLoadNamedGeneric* instr) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002132 LOperand* context = UseFixed(instr->context(), cp);
2133 LOperand* object =
2134 UseFixed(instr->object(), LoadDescriptor::ReceiverRegister());
2135 LOperand* vector = NULL;
Emily Bernierd0a1eb72015-03-24 16:35:39 -04002136 if (instr->HasVectorAndSlot()) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002137 vector = FixedTemp(VectorLoadICDescriptor::VectorRegister());
2138 }
2139
2140 LInstruction* result =
2141 DefineFixed(new(zone()) LLoadNamedGeneric(context, object, vector), v0);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002142 return MarkAsCall(result, instr);
2143}
2144
2145
2146LInstruction* LChunkBuilder::DoLoadFunctionPrototype(
2147 HLoadFunctionPrototype* instr) {
2148 return AssignEnvironment(DefineAsRegister(
2149 new(zone()) LLoadFunctionPrototype(UseRegister(instr->function()))));
2150}
2151
2152
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002153LInstruction* LChunkBuilder::DoLoadRoot(HLoadRoot* instr) {
2154 return DefineAsRegister(new(zone()) LLoadRoot);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002155}
2156
2157
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002158LInstruction* LChunkBuilder::DoLoadKeyed(HLoadKeyed* instr) {
2159 DCHECK(instr->key()->representation().IsSmiOrInteger32());
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002160 ElementsKind elements_kind = instr->elements_kind();
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002161 LOperand* key = UseRegisterOrConstantAtStart(instr->key());
2162 LInstruction* result = NULL;
2163
2164 if (!instr->is_typed_elements()) {
2165 LOperand* obj = NULL;
2166 if (instr->representation().IsDouble()) {
2167 obj = UseRegister(instr->elements());
2168 } else {
2169 DCHECK(instr->representation().IsSmiOrTagged());
2170 obj = UseRegisterAtStart(instr->elements());
2171 }
2172 result = DefineAsRegister(new(zone()) LLoadKeyed(obj, key));
2173 } else {
2174 DCHECK(
2175 (instr->representation().IsInteger32() &&
2176 !IsDoubleOrFloatElementsKind(elements_kind)) ||
2177 (instr->representation().IsDouble() &&
2178 IsDoubleOrFloatElementsKind(elements_kind)));
2179 LOperand* backing_store = UseRegister(instr->elements());
2180 result = DefineAsRegister(new(zone()) LLoadKeyed(backing_store, key));
2181 }
2182
2183 if ((instr->is_external() || instr->is_fixed_typed_array()) ?
2184 // see LCodeGen::DoLoadKeyedExternalArray
2185 ((elements_kind == EXTERNAL_UINT32_ELEMENTS ||
2186 elements_kind == UINT32_ELEMENTS) &&
2187 !instr->CheckFlag(HInstruction::kUint32)) :
2188 // see LCodeGen::DoLoadKeyedFixedDoubleArray and
2189 // LCodeGen::DoLoadKeyedFixedArray
2190 instr->RequiresHoleCheck()) {
2191 result = AssignEnvironment(result);
2192 }
2193 return result;
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002194}
2195
2196
2197LInstruction* LChunkBuilder::DoLoadKeyedGeneric(HLoadKeyedGeneric* instr) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002198 LOperand* context = UseFixed(instr->context(), cp);
2199 LOperand* object =
2200 UseFixed(instr->object(), LoadDescriptor::ReceiverRegister());
2201 LOperand* key = UseFixed(instr->key(), LoadDescriptor::NameRegister());
2202 LOperand* vector = NULL;
Emily Bernierd0a1eb72015-03-24 16:35:39 -04002203 if (instr->HasVectorAndSlot()) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002204 vector = FixedTemp(VectorLoadICDescriptor::VectorRegister());
2205 }
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002206
2207 LInstruction* result =
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002208 DefineFixed(new(zone()) LLoadKeyedGeneric(context, object, key, vector),
2209 v0);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002210 return MarkAsCall(result, instr);
2211}
2212
2213
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002214LInstruction* LChunkBuilder::DoStoreKeyed(HStoreKeyed* instr) {
2215 if (!instr->is_typed_elements()) {
2216 DCHECK(instr->elements()->representation().IsTagged());
2217 bool needs_write_barrier = instr->NeedsWriteBarrier();
2218 LOperand* object = NULL;
2219 LOperand* val = NULL;
2220 LOperand* key = NULL;
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002221
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002222 if (instr->value()->representation().IsDouble()) {
2223 object = UseRegisterAtStart(instr->elements());
2224 key = UseRegisterOrConstantAtStart(instr->key());
2225 val = UseRegister(instr->value());
2226 } else {
2227 DCHECK(instr->value()->representation().IsSmiOrTagged());
2228 if (needs_write_barrier) {
2229 object = UseTempRegister(instr->elements());
2230 val = UseTempRegister(instr->value());
2231 key = UseTempRegister(instr->key());
2232 } else {
2233 object = UseRegisterAtStart(instr->elements());
2234 val = UseRegisterAtStart(instr->value());
2235 key = UseRegisterOrConstantAtStart(instr->key());
2236 }
2237 }
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002238
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002239 return new(zone()) LStoreKeyed(object, key, val);
2240 }
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002241
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002242 DCHECK(
2243 (instr->value()->representation().IsInteger32() &&
2244 !IsDoubleOrFloatElementsKind(instr->elements_kind())) ||
2245 (instr->value()->representation().IsDouble() &&
2246 IsDoubleOrFloatElementsKind(instr->elements_kind())));
2247 DCHECK((instr->is_fixed_typed_array() &&
2248 instr->elements()->representation().IsTagged()) ||
2249 (instr->is_external() &&
2250 instr->elements()->representation().IsExternal()));
2251 LOperand* val = UseRegister(instr->value());
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002252 LOperand* key = UseRegisterOrConstantAtStart(instr->key());
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002253 LOperand* backing_store = UseRegister(instr->elements());
2254 return new(zone()) LStoreKeyed(backing_store, key, val);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002255}
2256
2257
2258LInstruction* LChunkBuilder::DoStoreKeyedGeneric(HStoreKeyedGeneric* instr) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002259 LOperand* context = UseFixed(instr->context(), cp);
2260 LOperand* obj =
2261 UseFixed(instr->object(), StoreDescriptor::ReceiverRegister());
2262 LOperand* key = UseFixed(instr->key(), StoreDescriptor::NameRegister());
2263 LOperand* val = UseFixed(instr->value(), StoreDescriptor::ValueRegister());
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002264
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002265 DCHECK(instr->object()->representation().IsTagged());
2266 DCHECK(instr->key()->representation().IsTagged());
2267 DCHECK(instr->value()->representation().IsTagged());
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002268
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002269 return MarkAsCall(
2270 new(zone()) LStoreKeyedGeneric(context, obj, key, val), instr);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002271}
2272
2273
2274LInstruction* LChunkBuilder::DoTransitionElementsKind(
2275 HTransitionElementsKind* instr) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002276 if (IsSimpleMapChangeTransition(instr->from_kind(), instr->to_kind())) {
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002277 LOperand* object = UseRegister(instr->object());
2278 LOperand* new_map_reg = TempRegister();
2279 LTransitionElementsKind* result =
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002280 new(zone()) LTransitionElementsKind(object, NULL, new_map_reg);
2281 return result;
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002282 } else {
2283 LOperand* object = UseFixed(instr->object(), a0);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002284 LOperand* context = UseFixed(instr->context(), cp);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002285 LTransitionElementsKind* result =
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002286 new(zone()) LTransitionElementsKind(object, context, NULL);
2287 return MarkAsCall(result, instr);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002288 }
2289}
2290
2291
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002292LInstruction* LChunkBuilder::DoTrapAllocationMemento(
2293 HTrapAllocationMemento* instr) {
2294 LOperand* object = UseRegister(instr->object());
2295 LOperand* temp = TempRegister();
2296 LTrapAllocationMemento* result =
2297 new(zone()) LTrapAllocationMemento(object, temp);
2298 return AssignEnvironment(result);
2299}
2300
2301
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002302LInstruction* LChunkBuilder::DoStoreNamedField(HStoreNamedField* instr) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002303 bool is_in_object = instr->access().IsInobject();
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002304 bool needs_write_barrier = instr->NeedsWriteBarrier();
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002305 bool needs_write_barrier_for_map = instr->has_transition() &&
2306 instr->NeedsWriteBarrierForMap();
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002307
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002308 LOperand* obj;
2309 if (needs_write_barrier) {
2310 obj = is_in_object
2311 ? UseRegister(instr->object())
2312 : UseTempRegister(instr->object());
2313 } else {
2314 obj = needs_write_barrier_for_map
2315 ? UseRegister(instr->object())
2316 : UseRegisterAtStart(instr->object());
2317 }
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002318
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002319 LOperand* val;
2320 if (needs_write_barrier) {
2321 val = UseTempRegister(instr->value());
2322 } else if (instr->field_representation().IsDouble()) {
2323 val = UseRegisterAtStart(instr->value());
2324 } else {
2325 val = UseRegister(instr->value());
2326 }
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002327
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002328 // We need a temporary register for write barrier of the map field.
2329 LOperand* temp = needs_write_barrier_for_map ? TempRegister() : NULL;
2330
2331 return new(zone()) LStoreNamedField(obj, val, temp);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002332}
2333
2334
2335LInstruction* LChunkBuilder::DoStoreNamedGeneric(HStoreNamedGeneric* instr) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002336 LOperand* context = UseFixed(instr->context(), cp);
2337 LOperand* obj =
2338 UseFixed(instr->object(), StoreDescriptor::ReceiverRegister());
2339 LOperand* val = UseFixed(instr->value(), StoreDescriptor::ValueRegister());
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002340
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002341 LInstruction* result = new(zone()) LStoreNamedGeneric(context, obj, val);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002342 return MarkAsCall(result, instr);
2343}
2344
2345
2346LInstruction* LChunkBuilder::DoStringAdd(HStringAdd* instr) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002347 LOperand* context = UseFixed(instr->context(), cp);
2348 LOperand* left = UseFixed(instr->left(), a1);
2349 LOperand* right = UseFixed(instr->right(), a0);
2350 return MarkAsCall(
2351 DefineFixed(new(zone()) LStringAdd(context, left, right), v0),
2352 instr);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002353}
2354
2355
2356LInstruction* LChunkBuilder::DoStringCharCodeAt(HStringCharCodeAt* instr) {
2357 LOperand* string = UseTempRegister(instr->string());
2358 LOperand* index = UseTempRegister(instr->index());
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002359 LOperand* context = UseAny(instr->context());
2360 LStringCharCodeAt* result =
2361 new(zone()) LStringCharCodeAt(context, string, index);
2362 return AssignPointerMap(DefineAsRegister(result));
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002363}
2364
2365
2366LInstruction* LChunkBuilder::DoStringCharFromCode(HStringCharFromCode* instr) {
2367 LOperand* char_code = UseRegister(instr->value());
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002368 LOperand* context = UseAny(instr->context());
2369 LStringCharFromCode* result =
2370 new(zone()) LStringCharFromCode(context, char_code);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002371 return AssignPointerMap(DefineAsRegister(result));
2372}
2373
2374
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002375LInstruction* LChunkBuilder::DoAllocate(HAllocate* instr) {
2376 info()->MarkAsDeferredCalling();
2377 LOperand* context = UseAny(instr->context());
2378 LOperand* size = UseRegisterOrConstant(instr->size());
2379 LOperand* temp1 = TempRegister();
2380 LOperand* temp2 = TempRegister();
2381 LAllocate* result = new(zone()) LAllocate(context, size, temp1, temp2);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002382 return AssignPointerMap(DefineAsRegister(result));
2383}
2384
2385
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002386LInstruction* LChunkBuilder::DoRegExpLiteral(HRegExpLiteral* instr) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002387 LOperand* context = UseFixed(instr->context(), cp);
2388 return MarkAsCall(
2389 DefineFixed(new(zone()) LRegExpLiteral(context), v0), instr);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002390}
2391
2392
2393LInstruction* LChunkBuilder::DoFunctionLiteral(HFunctionLiteral* instr) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002394 LOperand* context = UseFixed(instr->context(), cp);
2395 return MarkAsCall(
2396 DefineFixed(new(zone()) LFunctionLiteral(context), v0), instr);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002397}
2398
2399
2400LInstruction* LChunkBuilder::DoOsrEntry(HOsrEntry* instr) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002401 DCHECK(argument_count_ == 0);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002402 allocator_->MarkAsOsrEntry();
2403 current_block_->last_environment()->set_ast_id(instr->ast_id());
2404 return AssignEnvironment(new(zone()) LOsrEntry);
2405}
2406
2407
2408LInstruction* LChunkBuilder::DoParameter(HParameter* instr) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002409 LParameter* result = new(zone()) LParameter;
2410 if (instr->kind() == HParameter::STACK_PARAMETER) {
2411 int spill_index = chunk()->GetParameterStackSlot(instr->index());
2412 return DefineAsSpilled(result, spill_index);
2413 } else {
2414 DCHECK(info()->IsStub());
2415 CallInterfaceDescriptor descriptor =
2416 info()->code_stub()->GetCallInterfaceDescriptor();
2417 int index = static_cast<int>(instr->index());
2418 Register reg = descriptor.GetEnvironmentParameterRegister(index);
2419 return DefineFixed(result, reg);
2420 }
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002421}
2422
2423
2424LInstruction* LChunkBuilder::DoUnknownOSRValue(HUnknownOSRValue* instr) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002425 // Use an index that corresponds to the location in the unoptimized frame,
2426 // which the optimized frame will subsume.
2427 int env_index = instr->index();
2428 int spill_index = 0;
2429 if (instr->environment()->is_parameter_index(env_index)) {
2430 spill_index = chunk()->GetParameterStackSlot(env_index);
2431 } else {
2432 spill_index = env_index - instr->environment()->first_local_index();
2433 if (spill_index > LUnallocated::kMaxFixedSlotIndex) {
2434 Retry(kTooManySpillSlotsNeededForOSR);
2435 spill_index = 0;
2436 }
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002437 }
2438 return DefineAsSpilled(new(zone()) LUnknownOSRValue, spill_index);
2439}
2440
2441
2442LInstruction* LChunkBuilder::DoCallStub(HCallStub* instr) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002443 LOperand* context = UseFixed(instr->context(), cp);
2444 return MarkAsCall(DefineFixed(new(zone()) LCallStub(context), v0), instr);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002445}
2446
2447
2448LInstruction* LChunkBuilder::DoArgumentsObject(HArgumentsObject* instr) {
2449 // There are no real uses of the arguments object.
2450 // arguments.length and element access are supported directly on
2451 // stack arguments, and any real arguments object use causes a bailout.
2452 // So this value is never used.
2453 return NULL;
2454}
2455
2456
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002457LInstruction* LChunkBuilder::DoCapturedObject(HCapturedObject* instr) {
2458 instr->ReplayEnvironment(current_block_->last_environment());
2459
2460 // There are no real uses of a captured object.
2461 return NULL;
2462}
2463
2464
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002465LInstruction* LChunkBuilder::DoAccessArgumentsAt(HAccessArgumentsAt* instr) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002466 info()->MarkAsRequiresFrame();
2467 LOperand* args = UseRegister(instr->arguments());
2468 LOperand* length = UseRegisterOrConstantAtStart(instr->length());
2469 LOperand* index = UseRegisterOrConstantAtStart(instr->index());
2470 return DefineAsRegister(new(zone()) LAccessArgumentsAt(args, length, index));
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002471}
2472
2473
2474LInstruction* LChunkBuilder::DoToFastProperties(HToFastProperties* instr) {
2475 LOperand* object = UseFixed(instr->value(), a0);
2476 LToFastProperties* result = new(zone()) LToFastProperties(object);
2477 return MarkAsCall(DefineFixed(result, v0), instr);
2478}
2479
2480
2481LInstruction* LChunkBuilder::DoTypeof(HTypeof* instr) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002482 LOperand* context = UseFixed(instr->context(), cp);
2483 LTypeof* result = new(zone()) LTypeof(context, UseFixed(instr->value(), a0));
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002484 return MarkAsCall(DefineFixed(result, v0), instr);
2485}
2486
2487
2488LInstruction* LChunkBuilder::DoTypeofIsAndBranch(HTypeofIsAndBranch* instr) {
2489 return new(zone()) LTypeofIsAndBranch(UseTempRegister(instr->value()));
2490}
2491
2492
2493LInstruction* LChunkBuilder::DoIsConstructCallAndBranch(
2494 HIsConstructCallAndBranch* instr) {
2495 return new(zone()) LIsConstructCallAndBranch(TempRegister());
2496}
2497
2498
2499LInstruction* LChunkBuilder::DoSimulate(HSimulate* instr) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002500 instr->ReplayEnvironment(current_block_->last_environment());
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002501 return NULL;
2502}
2503
2504
2505LInstruction* LChunkBuilder::DoStackCheck(HStackCheck* instr) {
2506 if (instr->is_function_entry()) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002507 LOperand* context = UseFixed(instr->context(), cp);
2508 return MarkAsCall(new(zone()) LStackCheck(context), instr);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002509 } else {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002510 DCHECK(instr->is_backwards_branch());
2511 LOperand* context = UseAny(instr->context());
2512 return AssignEnvironment(
2513 AssignPointerMap(new(zone()) LStackCheck(context)));
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002514 }
2515}
2516
2517
2518LInstruction* LChunkBuilder::DoEnterInlined(HEnterInlined* instr) {
2519 HEnvironment* outer = current_block_->last_environment();
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002520 outer->set_ast_id(instr->ReturnId());
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002521 HConstant* undefined = graph()->GetConstantUndefined();
2522 HEnvironment* inner = outer->CopyForInlining(instr->closure(),
2523 instr->arguments_count(),
2524 instr->function(),
2525 undefined,
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002526 instr->inlining_kind());
2527 // Only replay binding of arguments object if it wasn't removed from graph.
2528 if (instr->arguments_var() != NULL && instr->arguments_object()->IsLinked()) {
2529 inner->Bind(instr->arguments_var(), instr->arguments_object());
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002530 }
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002531 inner->BindContext(instr->closure_context());
2532 inner->set_entry(instr);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002533 current_block_->UpdateEnvironment(inner);
2534 chunk_->AddInlinedClosure(instr->closure());
2535 return NULL;
2536}
2537
2538
2539LInstruction* LChunkBuilder::DoLeaveInlined(HLeaveInlined* instr) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002540 LInstruction* pop = NULL;
2541
2542 HEnvironment* env = current_block_->last_environment();
2543
2544 if (env->entry()->arguments_pushed()) {
2545 int argument_count = env->arguments_environment()->parameter_count();
2546 pop = new(zone()) LDrop(argument_count);
2547 DCHECK(instr->argument_delta() == -argument_count);
2548 }
2549
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002550 HEnvironment* outer = current_block_->last_environment()->
2551 DiscardInlined(false);
2552 current_block_->UpdateEnvironment(outer);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002553
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002554 return pop;
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002555}
2556
2557
2558LInstruction* LChunkBuilder::DoForInPrepareMap(HForInPrepareMap* instr) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002559 LOperand* context = UseFixed(instr->context(), cp);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002560 LOperand* object = UseFixed(instr->enumerable(), a0);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002561 LForInPrepareMap* result = new(zone()) LForInPrepareMap(context, object);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002562 return MarkAsCall(DefineFixed(result, v0), instr, CAN_DEOPTIMIZE_EAGERLY);
2563}
2564
2565
2566LInstruction* LChunkBuilder::DoForInCacheArray(HForInCacheArray* instr) {
2567 LOperand* map = UseRegister(instr->map());
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002568 return AssignEnvironment(DefineAsRegister(new(zone()) LForInCacheArray(map)));
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002569}
2570
2571
2572LInstruction* LChunkBuilder::DoCheckMapValue(HCheckMapValue* instr) {
2573 LOperand* value = UseRegisterAtStart(instr->value());
2574 LOperand* map = UseRegisterAtStart(instr->map());
2575 return AssignEnvironment(new(zone()) LCheckMapValue(value, map));
2576}
2577
2578
2579LInstruction* LChunkBuilder::DoLoadFieldByIndex(HLoadFieldByIndex* instr) {
2580 LOperand* object = UseRegister(instr->object());
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002581 LOperand* index = UseTempRegister(instr->index());
2582 LLoadFieldByIndex* load = new(zone()) LLoadFieldByIndex(object, index);
2583 LInstruction* result = DefineSameAsFirst(load);
2584 return AssignPointerMap(result);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002585}
2586
2587
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002588
2589LInstruction* LChunkBuilder::DoStoreFrameContext(HStoreFrameContext* instr) {
2590 LOperand* context = UseRegisterAtStart(instr->context());
2591 return new(zone()) LStoreFrameContext(context);
2592}
2593
2594
2595LInstruction* LChunkBuilder::DoAllocateBlockContext(
2596 HAllocateBlockContext* instr) {
2597 LOperand* context = UseFixed(instr->context(), cp);
2598 LOperand* function = UseRegisterAtStart(instr->function());
2599 LAllocateBlockContext* result =
2600 new(zone()) LAllocateBlockContext(context, function);
2601 return MarkAsCall(DefineFixed(result, cp), instr);
2602}
2603
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002604} } // namespace v8::internal
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002605
2606#endif // V8_TARGET_ARCH_MIPS