blob: ccef1d6c2b37d499ccc9d25a86f0453d9f04719a [file] [log] [blame]
kmillikin@chromium.orgd2c22f02011-01-10 08:15:37 +00001// Copyright 2011 the V8 project authors. All rights reserved.
kasperl@chromium.orga5551262010-12-07 12:49:48 +00002// Redistribution and use in source and binary forms, with or without
3// modification, are permitted provided that the following conditions are
4// met:
5//
6// * Redistributions of source code must retain the above copyright
7// notice, this list of conditions and the following disclaimer.
8// * Redistributions in binary form must reproduce the above
9// copyright notice, this list of conditions and the following
10// disclaimer in the documentation and/or other materials provided
11// with the distribution.
12// * Neither the name of Google Inc. nor the names of its
13// contributors may be used to endorse or promote products derived
14// from this software without specific prior written permission.
15//
16// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
sgjesse@chromium.orgc6c57182011-01-17 12:24:25 +000028#include "v8.h"
29
30#if defined(V8_TARGET_ARCH_IA32)
31
ricow@chromium.org83aa5492011-02-07 12:42:56 +000032#include "lithium-allocator-inl.h"
kasperl@chromium.orga5551262010-12-07 12:49:48 +000033#include "ia32/lithium-ia32.h"
34#include "ia32/lithium-codegen-ia32.h"
35
36namespace v8 {
37namespace internal {
38
39#define DEFINE_COMPILE(type) \
40 void L##type::CompileToNative(LCodeGen* generator) { \
41 generator->Do##type(this); \
42 }
43LITHIUM_CONCRETE_INSTRUCTION_LIST(DEFINE_COMPILE)
44#undef DEFINE_COMPILE
45
46LOsrEntry::LOsrEntry() {
47 for (int i = 0; i < Register::kNumAllocatableRegisters; ++i) {
48 register_spills_[i] = NULL;
49 }
50 for (int i = 0; i < DoubleRegister::kNumAllocatableRegisters; ++i) {
51 double_register_spills_[i] = NULL;
52 }
53}
54
55
56void LOsrEntry::MarkSpilledRegister(int allocation_index,
57 LOperand* spill_operand) {
58 ASSERT(spill_operand->IsStackSlot());
59 ASSERT(register_spills_[allocation_index] == NULL);
60 register_spills_[allocation_index] = spill_operand;
61}
62
63
64void LOsrEntry::MarkSpilledDoubleRegister(int allocation_index,
65 LOperand* spill_operand) {
66 ASSERT(spill_operand->IsDoubleStackSlot());
67 ASSERT(double_register_spills_[allocation_index] == NULL);
68 double_register_spills_[allocation_index] = spill_operand;
69}
70
71
ricow@chromium.org83aa5492011-02-07 12:42:56 +000072#ifdef DEBUG
73void LInstruction::VerifyCall() {
danno@chromium.org160a7b02011-04-18 15:51:38 +000074 // Call instructions can use only fixed registers as temporaries and
75 // outputs because all registers are blocked by the calling convention.
76 // Inputs operands must use a fixed register or use-at-start policy or
77 // a non-register policy.
ricow@chromium.org83aa5492011-02-07 12:42:56 +000078 ASSERT(Output() == NULL ||
79 LUnallocated::cast(Output())->HasFixedPolicy() ||
80 !LUnallocated::cast(Output())->HasRegisterPolicy());
jkummerow@chromium.orge297f592011-06-08 10:05:15 +000081 for (UseIterator it(this); !it.Done(); it.Advance()) {
82 LUnallocated* operand = LUnallocated::cast(it.Current());
danno@chromium.org160a7b02011-04-18 15:51:38 +000083 ASSERT(operand->HasFixedPolicy() ||
84 operand->IsUsedAtStart());
ricow@chromium.org83aa5492011-02-07 12:42:56 +000085 }
jkummerow@chromium.orge297f592011-06-08 10:05:15 +000086 for (TempIterator it(this); !it.Done(); it.Advance()) {
87 LUnallocated* operand = LUnallocated::cast(it.Current());
danno@chromium.org160a7b02011-04-18 15:51:38 +000088 ASSERT(operand->HasFixedPolicy() ||!operand->HasRegisterPolicy());
ricow@chromium.org83aa5492011-02-07 12:42:56 +000089 }
90}
91#endif
92
93
sgjesse@chromium.orgc6c57182011-01-17 12:24:25 +000094void LInstruction::PrintTo(StringStream* stream) {
kasperl@chromium.orga5551262010-12-07 12:49:48 +000095 stream->Add("%s ", this->Mnemonic());
ricow@chromium.org83aa5492011-02-07 12:42:56 +000096
97 PrintOutputOperandTo(stream);
sgjesse@chromium.orgc6c57182011-01-17 12:24:25 +000098
kasperl@chromium.orga5551262010-12-07 12:49:48 +000099 PrintDataTo(stream);
100
101 if (HasEnvironment()) {
102 stream->Add(" ");
103 environment()->PrintTo(stream);
104 }
105
106 if (HasPointerMap()) {
107 stream->Add(" ");
108 pointer_map()->PrintTo(stream);
109 }
110}
111
112
sgjesse@chromium.orgc6c57182011-01-17 12:24:25 +0000113template<int R, int I, int T>
114void LTemplateInstruction<R, I, T>::PrintDataTo(StringStream* stream) {
erik.corry@gmail.com0511e242011-01-19 11:11:08 +0000115 stream->Add("= ");
svenpanne@chromium.org6d786c92011-06-15 10:58:27 +0000116 for (int i = 0; i < inputs_.length(); i++) {
117 if (i > 0) stream->Add(" ");
118 inputs_[i]->PrintTo(stream);
119 }
sgjesse@chromium.orgc6c57182011-01-17 12:24:25 +0000120}
121
122
123template<int R, int I, int T>
124void LTemplateInstruction<R, I, T>::PrintOutputOperandTo(StringStream* stream) {
svenpanne@chromium.org6d786c92011-06-15 10:58:27 +0000125 for (int i = 0; i < results_.length(); i++) {
erik.corry@gmail.com0511e242011-01-19 11:11:08 +0000126 if (i > 0) stream->Add(" ");
svenpanne@chromium.org6d786c92011-06-15 10:58:27 +0000127 results_[i]->PrintTo(stream);
sgjesse@chromium.orgc6c57182011-01-17 12:24:25 +0000128 }
129}
130
131
132void LLabel::PrintDataTo(StringStream* stream) {
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000133 LGap::PrintDataTo(stream);
134 LLabel* rep = replacement();
135 if (rep != NULL) {
136 stream->Add(" Dead block replaced with B%d", rep->block_id());
137 }
138}
139
140
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000141bool LGap::IsRedundant() const {
142 for (int i = 0; i < 4; i++) {
143 if (parallel_moves_[i] != NULL && !parallel_moves_[i]->IsRedundant()) {
144 return false;
145 }
146 }
147
148 return true;
149}
150
151
sgjesse@chromium.orgc6c57182011-01-17 12:24:25 +0000152void LGap::PrintDataTo(StringStream* stream) {
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000153 for (int i = 0; i < 4; i++) {
154 stream->Add("(");
155 if (parallel_moves_[i] != NULL) {
156 parallel_moves_[i]->PrintDataTo(stream);
157 }
158 stream->Add(") ");
159 }
160}
161
162
163const char* LArithmeticD::Mnemonic() const {
164 switch (op()) {
165 case Token::ADD: return "add-d";
166 case Token::SUB: return "sub-d";
167 case Token::MUL: return "mul-d";
168 case Token::DIV: return "div-d";
169 case Token::MOD: return "mod-d";
170 default:
171 UNREACHABLE();
172 return NULL;
173 }
174}
175
176
177const char* LArithmeticT::Mnemonic() const {
178 switch (op()) {
179 case Token::ADD: return "add-t";
180 case Token::SUB: return "sub-t";
181 case Token::MUL: return "mul-t";
182 case Token::MOD: return "mod-t";
183 case Token::DIV: return "div-t";
vegorov@chromium.org0a4e9012011-01-24 12:33:13 +0000184 case Token::BIT_AND: return "bit-and-t";
185 case Token::BIT_OR: return "bit-or-t";
186 case Token::BIT_XOR: return "bit-xor-t";
187 case Token::SHL: return "sal-t";
188 case Token::SAR: return "sar-t";
189 case Token::SHR: return "shr-t";
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000190 default:
191 UNREACHABLE();
192 return NULL;
193 }
194}
195
196
sgjesse@chromium.orgc6c57182011-01-17 12:24:25 +0000197void LGoto::PrintDataTo(StringStream* stream) {
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000198 stream->Add("B%d", block_id());
199}
200
201
sgjesse@chromium.orgc6c57182011-01-17 12:24:25 +0000202void LBranch::PrintDataTo(StringStream* stream) {
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000203 stream->Add("B%d | B%d on ", true_block_id(), false_block_id());
erik.corry@gmail.com0511e242011-01-19 11:11:08 +0000204 InputAt(0)->PrintTo(stream);
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000205}
206
207
sgjesse@chromium.orgc6c57182011-01-17 12:24:25 +0000208void LCmpIDAndBranch::PrintDataTo(StringStream* stream) {
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000209 stream->Add("if ");
erik.corry@gmail.com0511e242011-01-19 11:11:08 +0000210 InputAt(0)->PrintTo(stream);
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000211 stream->Add(" %s ", Token::String(op()));
erik.corry@gmail.com0511e242011-01-19 11:11:08 +0000212 InputAt(1)->PrintTo(stream);
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000213 stream->Add(" then B%d else B%d", true_block_id(), false_block_id());
214}
215
216
sgjesse@chromium.orgc6c57182011-01-17 12:24:25 +0000217void LIsNullAndBranch::PrintDataTo(StringStream* stream) {
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000218 stream->Add("if ");
erik.corry@gmail.com0511e242011-01-19 11:11:08 +0000219 InputAt(0)->PrintTo(stream);
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000220 stream->Add(is_strict() ? " === null" : " == null");
221 stream->Add(" then B%d else B%d", true_block_id(), false_block_id());
222}
223
224
sgjesse@chromium.orgc6c57182011-01-17 12:24:25 +0000225void LIsObjectAndBranch::PrintDataTo(StringStream* stream) {
ager@chromium.org5f0c45f2010-12-17 08:51:21 +0000226 stream->Add("if is_object(");
erik.corry@gmail.com0511e242011-01-19 11:11:08 +0000227 InputAt(0)->PrintTo(stream);
ager@chromium.org5f0c45f2010-12-17 08:51:21 +0000228 stream->Add(") then B%d else B%d", true_block_id(), false_block_id());
229}
230
231
sgjesse@chromium.orgc6c57182011-01-17 12:24:25 +0000232void LIsSmiAndBranch::PrintDataTo(StringStream* stream) {
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000233 stream->Add("if is_smi(");
erik.corry@gmail.com0511e242011-01-19 11:11:08 +0000234 InputAt(0)->PrintTo(stream);
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000235 stream->Add(") then B%d else B%d", true_block_id(), false_block_id());
236}
237
238
vegorov@chromium.org7304bca2011-05-16 12:14:13 +0000239void LIsUndetectableAndBranch::PrintDataTo(StringStream* stream) {
240 stream->Add("if is_undetectable(");
241 InputAt(0)->PrintTo(stream);
242 stream->Add(") then B%d else B%d", true_block_id(), false_block_id());
243}
244
245
sgjesse@chromium.orgc6c57182011-01-17 12:24:25 +0000246void LHasInstanceTypeAndBranch::PrintDataTo(StringStream* stream) {
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000247 stream->Add("if has_instance_type(");
erik.corry@gmail.com0511e242011-01-19 11:11:08 +0000248 InputAt(0)->PrintTo(stream);
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000249 stream->Add(") then B%d else B%d", true_block_id(), false_block_id());
250}
251
252
sgjesse@chromium.orgc6c57182011-01-17 12:24:25 +0000253void LHasCachedArrayIndexAndBranch::PrintDataTo(StringStream* stream) {
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000254 stream->Add("if has_cached_array_index(");
erik.corry@gmail.com0511e242011-01-19 11:11:08 +0000255 InputAt(0)->PrintTo(stream);
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000256 stream->Add(") then B%d else B%d", true_block_id(), false_block_id());
257}
258
259
sgjesse@chromium.orgc6c57182011-01-17 12:24:25 +0000260void LClassOfTestAndBranch::PrintDataTo(StringStream* stream) {
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000261 stream->Add("if class_of_test(");
erik.corry@gmail.com0511e242011-01-19 11:11:08 +0000262 InputAt(0)->PrintTo(stream);
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000263 stream->Add(", \"%o\") then B%d else B%d",
264 *hydrogen()->class_name(),
265 true_block_id(),
266 false_block_id());
267}
268
269
sgjesse@chromium.orgc6c57182011-01-17 12:24:25 +0000270void LTypeofIs::PrintDataTo(StringStream* stream) {
erik.corry@gmail.com0511e242011-01-19 11:11:08 +0000271 InputAt(0)->PrintTo(stream);
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000272 stream->Add(" == \"%s\"", *hydrogen()->type_literal()->ToCString());
273}
274
275
sgjesse@chromium.orgc6c57182011-01-17 12:24:25 +0000276void LTypeofIsAndBranch::PrintDataTo(StringStream* stream) {
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000277 stream->Add("if typeof ");
erik.corry@gmail.com0511e242011-01-19 11:11:08 +0000278 InputAt(0)->PrintTo(stream);
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000279 stream->Add(" == \"%s\" then B%d else B%d",
280 *hydrogen()->type_literal()->ToCString(),
281 true_block_id(), false_block_id());
282}
283
284
sgjesse@chromium.orgc6c57182011-01-17 12:24:25 +0000285void LCallConstantFunction::PrintDataTo(StringStream* stream) {
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000286 stream->Add("#%d / ", arity());
287}
288
289
sgjesse@chromium.orgc6c57182011-01-17 12:24:25 +0000290void LUnaryMathOperation::PrintDataTo(StringStream* stream) {
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000291 stream->Add("/%s ", hydrogen()->OpName());
erik.corry@gmail.com0511e242011-01-19 11:11:08 +0000292 InputAt(0)->PrintTo(stream);
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000293}
294
295
sgjesse@chromium.orgc6c57182011-01-17 12:24:25 +0000296void LLoadContextSlot::PrintDataTo(StringStream* stream) {
ricow@chromium.org83aa5492011-02-07 12:42:56 +0000297 InputAt(0)->PrintTo(stream);
298 stream->Add("[%d]", slot_index());
299}
300
301
302void LStoreContextSlot::PrintDataTo(StringStream* stream) {
303 InputAt(0)->PrintTo(stream);
304 stream->Add("[%d] <- ", slot_index());
305 InputAt(1)->PrintTo(stream);
sgjesse@chromium.orgc6c57182011-01-17 12:24:25 +0000306}
307
308
danno@chromium.org160a7b02011-04-18 15:51:38 +0000309void LInvokeFunction::PrintDataTo(StringStream* stream) {
310 stream->Add("= ");
311 InputAt(0)->PrintTo(stream);
312 stream->Add(" ");
313 InputAt(1)->PrintTo(stream);
314 stream->Add(" #%d / ", arity());
315}
316
317
sgjesse@chromium.orgc6c57182011-01-17 12:24:25 +0000318void LCallKeyed::PrintDataTo(StringStream* stream) {
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000319 stream->Add("[ecx] #%d / ", arity());
320}
321
322
sgjesse@chromium.orgc6c57182011-01-17 12:24:25 +0000323void LCallNamed::PrintDataTo(StringStream* stream) {
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000324 SmartPointer<char> name_string = name()->ToCString();
325 stream->Add("%s #%d / ", *name_string, arity());
326}
327
328
sgjesse@chromium.orgc6c57182011-01-17 12:24:25 +0000329void LCallGlobal::PrintDataTo(StringStream* stream) {
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000330 SmartPointer<char> name_string = name()->ToCString();
331 stream->Add("%s #%d / ", *name_string, arity());
332}
333
334
sgjesse@chromium.orgc6c57182011-01-17 12:24:25 +0000335void LCallKnownGlobal::PrintDataTo(StringStream* stream) {
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000336 stream->Add("#%d / ", arity());
337}
338
339
sgjesse@chromium.orgc6c57182011-01-17 12:24:25 +0000340void LCallNew::PrintDataTo(StringStream* stream) {
341 stream->Add("= ");
erik.corry@gmail.com0511e242011-01-19 11:11:08 +0000342 InputAt(0)->PrintTo(stream);
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000343 stream->Add(" #%d / ", arity());
344}
345
346
sgjesse@chromium.orgc6c57182011-01-17 12:24:25 +0000347void LClassOfTest::PrintDataTo(StringStream* stream) {
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000348 stream->Add("= class_of_test(");
erik.corry@gmail.com0511e242011-01-19 11:11:08 +0000349 InputAt(0)->PrintTo(stream);
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000350 stream->Add(", \"%o\")", *hydrogen()->class_name());
351}
352
353
sgjesse@chromium.orgc6c57182011-01-17 12:24:25 +0000354void LAccessArgumentsAt::PrintDataTo(StringStream* stream) {
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000355 arguments()->PrintTo(stream);
356
357 stream->Add(" length ");
358 length()->PrintTo(stream);
359
360 stream->Add(" index ");
361 index()->PrintTo(stream);
362}
363
364
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000365int LChunk::GetNextSpillIndex(bool is_double) {
366 // Skip a slot if for a double-width slot.
367 if (is_double) spill_slot_count_++;
368 return spill_slot_count_++;
369}
370
371
erik.corry@gmail.com0511e242011-01-19 11:11:08 +0000372LOperand* LChunk::GetNextSpillSlot(bool is_double) {
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000373 int index = GetNextSpillIndex(is_double);
374 if (is_double) {
375 return LDoubleStackSlot::Create(index);
376 } else {
377 return LStackSlot::Create(index);
378 }
379}
380
381
382void LChunk::MarkEmptyBlocks() {
383 HPhase phase("Mark empty blocks", this);
384 for (int i = 0; i < graph()->blocks()->length(); ++i) {
385 HBasicBlock* block = graph()->blocks()->at(i);
386 int first = block->first_instruction_index();
387 int last = block->last_instruction_index();
388 LInstruction* first_instr = instructions()->at(first);
389 LInstruction* last_instr = instructions()->at(last);
390
391 LLabel* label = LLabel::cast(first_instr);
392 if (last_instr->IsGoto()) {
393 LGoto* goto_instr = LGoto::cast(last_instr);
394 if (!goto_instr->include_stack_check() &&
395 label->IsRedundant() &&
396 !label->is_loop_header()) {
397 bool can_eliminate = true;
398 for (int i = first + 1; i < last && can_eliminate; ++i) {
399 LInstruction* cur = instructions()->at(i);
400 if (cur->IsGap()) {
401 LGap* gap = LGap::cast(cur);
402 if (!gap->IsRedundant()) {
403 can_eliminate = false;
404 }
405 } else {
406 can_eliminate = false;
407 }
408 }
409
410 if (can_eliminate) {
411 label->set_replacement(GetLabel(goto_instr->block_id()));
412 }
413 }
414 }
415 }
416}
417
418
fschneider@chromium.org3a5fd782011-02-24 10:10:44 +0000419void LStoreNamedField::PrintDataTo(StringStream* stream) {
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000420 object()->PrintTo(stream);
421 stream->Add(".");
422 stream->Add(*String::cast(*name())->ToCString());
423 stream->Add(" <- ");
424 value()->PrintTo(stream);
425}
426
427
fschneider@chromium.org3a5fd782011-02-24 10:10:44 +0000428void LStoreNamedGeneric::PrintDataTo(StringStream* stream) {
429 object()->PrintTo(stream);
430 stream->Add(".");
431 stream->Add(*String::cast(*name())->ToCString());
432 stream->Add(" <- ");
433 value()->PrintTo(stream);
434}
435
436
437void LStoreKeyedFastElement::PrintDataTo(StringStream* stream) {
438 object()->PrintTo(stream);
439 stream->Add("[");
440 key()->PrintTo(stream);
441 stream->Add("] <- ");
442 value()->PrintTo(stream);
443}
444
445
446void LStoreKeyedGeneric::PrintDataTo(StringStream* stream) {
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000447 object()->PrintTo(stream);
448 stream->Add("[");
449 key()->PrintTo(stream);
450 stream->Add("] <- ");
451 value()->PrintTo(stream);
452}
453
454
ricow@chromium.org83aa5492011-02-07 12:42:56 +0000455void LChunk::AddInstruction(LInstruction* instr, HBasicBlock* block) {
sgjesse@chromium.org8e8294a2011-05-02 14:30:53 +0000456 LInstructionGap* gap = new LInstructionGap(block);
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000457 int index = -1;
458 if (instr->IsControl()) {
459 instructions_.Add(gap);
460 index = instructions_.length();
461 instructions_.Add(instr);
462 } else {
463 index = instructions_.length();
464 instructions_.Add(instr);
465 instructions_.Add(gap);
466 }
467 if (instr->HasPointerMap()) {
468 pointer_maps_.Add(instr->pointer_map());
469 instr->pointer_map()->set_lithium_position(index);
470 }
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000471}
472
473
474LConstantOperand* LChunk::DefineConstantOperand(HConstant* constant) {
475 return LConstantOperand::Create(constant->id());
476}
477
478
479int LChunk::GetParameterStackSlot(int index) const {
480 // The receiver is at index 0, the first parameter at index 1, so we
481 // shift all parameter indexes down by the number of parameters, and
482 // make sure they end up negative so they are distinguishable from
483 // spill slots.
karlklose@chromium.org8f806e82011-03-07 14:06:08 +0000484 int result = index - info()->scope()->num_parameters() - 1;
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000485 ASSERT(result < 0);
486 return result;
487}
488
489// A parameter relative to ebp in the arguments stub.
490int LChunk::ParameterAt(int index) {
491 ASSERT(-1 <= index); // -1 is the receiver.
karlklose@chromium.org8f806e82011-03-07 14:06:08 +0000492 return (1 + info()->scope()->num_parameters() - index) *
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000493 kPointerSize;
494}
495
496
497LGap* LChunk::GetGapAt(int index) const {
498 return LGap::cast(instructions_[index]);
499}
500
501
502bool LChunk::IsGapAt(int index) const {
503 return instructions_[index]->IsGap();
504}
505
506
507int LChunk::NearestGapPos(int index) const {
508 while (!IsGapAt(index)) index--;
509 return index;
510}
511
512
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000513void LChunk::AddGapMove(int index, LOperand* from, LOperand* to) {
514 GetGapAt(index)->GetOrCreateParallelMove(LGap::START)->AddMove(from, to);
515}
516
517
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000518Handle<Object> LChunk::LookupLiteral(LConstantOperand* operand) const {
519 return HConstant::cast(graph_->LookupValue(operand->index()))->handle();
520}
521
522
523Representation LChunk::LookupLiteralRepresentation(
524 LConstantOperand* operand) const {
525 return graph_->LookupValue(operand->index())->representation();
526}
527
528
529LChunk* LChunkBuilder::Build() {
530 ASSERT(is_unused());
karlklose@chromium.org8f806e82011-03-07 14:06:08 +0000531 chunk_ = new LChunk(info(), graph());
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000532 HPhase phase("Building chunk", chunk_);
533 status_ = BUILDING;
534 const ZoneList<HBasicBlock*>* blocks = graph()->blocks();
535 for (int i = 0; i < blocks->length(); i++) {
536 HBasicBlock* next = NULL;
537 if (i < blocks->length() - 1) next = blocks->at(i + 1);
538 DoBasicBlock(blocks->at(i), next);
539 if (is_aborted()) return NULL;
540 }
541 status_ = DONE;
542 return chunk_;
543}
544
545
546void LChunkBuilder::Abort(const char* format, ...) {
547 if (FLAG_trace_bailout) {
karlklose@chromium.org8f806e82011-03-07 14:06:08 +0000548 SmartPointer<char> name(info()->shared_info()->DebugName()->ToCString());
549 PrintF("Aborting LChunk building in @\"%s\": ", *name);
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000550 va_list arguments;
551 va_start(arguments, format);
552 OS::VPrint(format, arguments);
553 va_end(arguments);
554 PrintF("\n");
555 }
556 status_ = ABORTED;
557}
558
559
560LRegister* LChunkBuilder::ToOperand(Register reg) {
561 return LRegister::Create(Register::ToAllocationIndex(reg));
562}
563
564
565LUnallocated* LChunkBuilder::ToUnallocated(Register reg) {
566 return new LUnallocated(LUnallocated::FIXED_REGISTER,
567 Register::ToAllocationIndex(reg));
568}
569
570
571LUnallocated* LChunkBuilder::ToUnallocated(XMMRegister reg) {
572 return new LUnallocated(LUnallocated::FIXED_DOUBLE_REGISTER,
573 XMMRegister::ToAllocationIndex(reg));
574}
575
576
577LOperand* LChunkBuilder::UseFixed(HValue* value, Register fixed_register) {
578 return Use(value, ToUnallocated(fixed_register));
579}
580
581
582LOperand* LChunkBuilder::UseFixedDouble(HValue* value, XMMRegister reg) {
583 return Use(value, ToUnallocated(reg));
584}
585
586
587LOperand* LChunkBuilder::UseRegister(HValue* value) {
588 return Use(value, new LUnallocated(LUnallocated::MUST_HAVE_REGISTER));
589}
590
591
592LOperand* LChunkBuilder::UseRegisterAtStart(HValue* value) {
593 return Use(value,
594 new LUnallocated(LUnallocated::MUST_HAVE_REGISTER,
595 LUnallocated::USED_AT_START));
596}
597
598
599LOperand* LChunkBuilder::UseTempRegister(HValue* value) {
600 return Use(value, new LUnallocated(LUnallocated::WRITABLE_REGISTER));
601}
602
603
604LOperand* LChunkBuilder::Use(HValue* value) {
605 return Use(value, new LUnallocated(LUnallocated::NONE));
606}
607
608
609LOperand* LChunkBuilder::UseAtStart(HValue* value) {
610 return Use(value, new LUnallocated(LUnallocated::NONE,
611 LUnallocated::USED_AT_START));
612}
613
614
615LOperand* LChunkBuilder::UseOrConstant(HValue* value) {
616 return value->IsConstant()
617 ? chunk_->DefineConstantOperand(HConstant::cast(value))
618 : Use(value);
619}
620
621
622LOperand* LChunkBuilder::UseOrConstantAtStart(HValue* value) {
623 return value->IsConstant()
624 ? chunk_->DefineConstantOperand(HConstant::cast(value))
625 : UseAtStart(value);
626}
627
628
629LOperand* LChunkBuilder::UseRegisterOrConstant(HValue* value) {
630 return value->IsConstant()
631 ? chunk_->DefineConstantOperand(HConstant::cast(value))
632 : UseRegister(value);
633}
634
635
636LOperand* LChunkBuilder::UseRegisterOrConstantAtStart(HValue* value) {
637 return value->IsConstant()
638 ? chunk_->DefineConstantOperand(HConstant::cast(value))
639 : UseRegisterAtStart(value);
640}
641
642
erik.corry@gmail.com0511e242011-01-19 11:11:08 +0000643LOperand* LChunkBuilder::UseAny(HValue* value) {
644 return value->IsConstant()
645 ? chunk_->DefineConstantOperand(HConstant::cast(value))
646 : Use(value, new LUnallocated(LUnallocated::ANY));
647}
648
649
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000650LOperand* LChunkBuilder::Use(HValue* value, LUnallocated* operand) {
651 if (value->EmitAtUses()) {
652 HInstruction* instr = HInstruction::cast(value);
653 VisitInstruction(instr);
654 }
655 allocator_->RecordUse(value, operand);
656 return operand;
657}
658
659
sgjesse@chromium.orgc6c57182011-01-17 12:24:25 +0000660template<int I, int T>
661LInstruction* LChunkBuilder::Define(LTemplateInstruction<1, I, T>* instr,
662 LUnallocated* result) {
663 allocator_->RecordDefinition(current_instruction_, result);
664 instr->set_result(result);
665 return instr;
666}
667
668
669template<int I, int T>
670LInstruction* LChunkBuilder::Define(LTemplateInstruction<1, I, T>* instr) {
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000671 return Define(instr, new LUnallocated(LUnallocated::NONE));
672}
673
674
sgjesse@chromium.orgc6c57182011-01-17 12:24:25 +0000675template<int I, int T>
676LInstruction* LChunkBuilder::DefineAsRegister(
677 LTemplateInstruction<1, I, T>* instr) {
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000678 return Define(instr, new LUnallocated(LUnallocated::MUST_HAVE_REGISTER));
679}
680
681
sgjesse@chromium.orgc6c57182011-01-17 12:24:25 +0000682template<int I, int T>
683LInstruction* LChunkBuilder::DefineAsSpilled(
684 LTemplateInstruction<1, I, T>* instr,
685 int index) {
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000686 return Define(instr, new LUnallocated(LUnallocated::FIXED_SLOT, index));
687}
688
689
sgjesse@chromium.orgc6c57182011-01-17 12:24:25 +0000690template<int I, int T>
691LInstruction* LChunkBuilder::DefineSameAsFirst(
692 LTemplateInstruction<1, I, T>* instr) {
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000693 return Define(instr, new LUnallocated(LUnallocated::SAME_AS_FIRST_INPUT));
694}
695
696
sgjesse@chromium.orgc6c57182011-01-17 12:24:25 +0000697template<int I, int T>
698LInstruction* LChunkBuilder::DefineFixed(LTemplateInstruction<1, I, T>* instr,
699 Register reg) {
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000700 return Define(instr, ToUnallocated(reg));
701}
702
703
sgjesse@chromium.orgc6c57182011-01-17 12:24:25 +0000704template<int I, int T>
705LInstruction* LChunkBuilder::DefineFixedDouble(
706 LTemplateInstruction<1, I, T>* instr,
707 XMMRegister reg) {
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000708 return Define(instr, ToUnallocated(reg));
709}
710
711
712LInstruction* LChunkBuilder::AssignEnvironment(LInstruction* instr) {
713 HEnvironment* hydrogen_env = current_block_->last_environment();
714 instr->set_environment(CreateEnvironment(hydrogen_env));
715 return instr;
716}
717
718
fschneider@chromium.org1df6b472011-01-26 08:23:03 +0000719LInstruction* LChunkBuilder::SetInstructionPendingDeoptimizationEnvironment(
720 LInstruction* instr, int ast_id) {
kmillikin@chromium.org31b12772011-02-02 16:08:26 +0000721 ASSERT(instruction_pending_deoptimization_environment_ == NULL);
fschneider@chromium.org1df6b472011-01-26 08:23:03 +0000722 ASSERT(pending_deoptimization_ast_id_ == AstNode::kNoNumber);
kmillikin@chromium.org31b12772011-02-02 16:08:26 +0000723 instruction_pending_deoptimization_environment_ = instr;
fschneider@chromium.org1df6b472011-01-26 08:23:03 +0000724 pending_deoptimization_ast_id_ = ast_id;
725 return instr;
726}
727
728
729void LChunkBuilder::ClearInstructionPendingDeoptimizationEnvironment() {
kmillikin@chromium.org31b12772011-02-02 16:08:26 +0000730 instruction_pending_deoptimization_environment_ = NULL;
fschneider@chromium.org1df6b472011-01-26 08:23:03 +0000731 pending_deoptimization_ast_id_ = AstNode::kNoNumber;
732}
733
734
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000735LInstruction* LChunkBuilder::MarkAsCall(LInstruction* instr,
736 HInstruction* hinstr,
737 CanDeoptimize can_deoptimize) {
ricow@chromium.org83aa5492011-02-07 12:42:56 +0000738#ifdef DEBUG
739 instr->VerifyCall();
740#endif
741 instr->MarkAsCall();
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000742 instr = AssignPointerMap(instr);
743
744 if (hinstr->HasSideEffects()) {
745 ASSERT(hinstr->next()->IsSimulate());
746 HSimulate* sim = HSimulate::cast(hinstr->next());
fschneider@chromium.org1df6b472011-01-26 08:23:03 +0000747 instr = SetInstructionPendingDeoptimizationEnvironment(
748 instr, sim->ast_id());
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000749 }
750
751 // If instruction does not have side-effects lazy deoptimization
752 // after the call will try to deoptimize to the point before the call.
753 // Thus we still need to attach environment to this call even if
754 // call sequence can not deoptimize eagerly.
755 bool needs_environment =
756 (can_deoptimize == CAN_DEOPTIMIZE_EAGERLY) || !hinstr->HasSideEffects();
757 if (needs_environment && !instr->HasEnvironment()) {
758 instr = AssignEnvironment(instr);
759 }
760
761 return instr;
762}
763
764
kmillikin@chromium.orgd2c22f02011-01-10 08:15:37 +0000765LInstruction* LChunkBuilder::MarkAsSaveDoubles(LInstruction* instr) {
ricow@chromium.org83aa5492011-02-07 12:42:56 +0000766 instr->MarkAsSaveDoubles();
kmillikin@chromium.orgd2c22f02011-01-10 08:15:37 +0000767 return instr;
768}
769
770
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000771LInstruction* LChunkBuilder::AssignPointerMap(LInstruction* instr) {
772 ASSERT(!instr->HasPointerMap());
773 instr->set_pointer_map(new LPointerMap(position_));
774 return instr;
775}
776
777
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000778LUnallocated* LChunkBuilder::TempRegister() {
779 LUnallocated* operand = new LUnallocated(LUnallocated::MUST_HAVE_REGISTER);
780 allocator_->RecordTemporary(operand);
781 return operand;
782}
783
784
785LOperand* LChunkBuilder::FixedTemp(Register reg) {
786 LUnallocated* operand = ToUnallocated(reg);
787 allocator_->RecordTemporary(operand);
788 return operand;
789}
790
791
792LOperand* LChunkBuilder::FixedTemp(XMMRegister reg) {
793 LUnallocated* operand = ToUnallocated(reg);
794 allocator_->RecordTemporary(operand);
795 return operand;
796}
797
798
799LInstruction* LChunkBuilder::DoBlockEntry(HBlockEntry* instr) {
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000800 return new LLabel(instr->block());
801}
802
803
jkummerow@chromium.orge297f592011-06-08 10:05:15 +0000804LInstruction* LChunkBuilder::DoSoftDeoptimize(HSoftDeoptimize* instr) {
805 return AssignEnvironment(new LDeoptimize);
806}
807
808
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000809LInstruction* LChunkBuilder::DoDeoptimize(HDeoptimize* instr) {
810 return AssignEnvironment(new LDeoptimize);
811}
812
813
814LInstruction* LChunkBuilder::DoBit(Token::Value op,
815 HBitwiseBinaryOperation* instr) {
vegorov@chromium.org0a4e9012011-01-24 12:33:13 +0000816 if (instr->representation().IsInteger32()) {
817 ASSERT(instr->left()->representation().IsInteger32());
818 ASSERT(instr->right()->representation().IsInteger32());
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000819
vegorov@chromium.org0a4e9012011-01-24 12:33:13 +0000820 LOperand* left = UseRegisterAtStart(instr->LeastConstantOperand());
821 LOperand* right = UseOrConstantAtStart(instr->MostConstantOperand());
822 return DefineSameAsFirst(new LBitI(op, left, right));
823 } else {
824 ASSERT(instr->representation().IsTagged());
825 ASSERT(instr->left()->representation().IsTagged());
826 ASSERT(instr->right()->representation().IsTagged());
827
828 LOperand* left = UseFixed(instr->left(), edx);
829 LOperand* right = UseFixed(instr->right(), eax);
830 LArithmeticT* result = new LArithmeticT(op, left, right);
831 return MarkAsCall(DefineFixed(result, eax), instr);
832 }
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000833}
834
835
836LInstruction* LChunkBuilder::DoShift(Token::Value op,
837 HBitwiseBinaryOperation* instr) {
vegorov@chromium.org0a4e9012011-01-24 12:33:13 +0000838 if (instr->representation().IsTagged()) {
839 ASSERT(instr->left()->representation().IsTagged());
840 ASSERT(instr->right()->representation().IsTagged());
841
842 LOperand* left = UseFixed(instr->left(), edx);
843 LOperand* right = UseFixed(instr->right(), eax);
844 LArithmeticT* result = new LArithmeticT(op, left, right);
845 return MarkAsCall(DefineFixed(result, eax), instr);
846 }
847
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000848 ASSERT(instr->representation().IsInteger32());
849 ASSERT(instr->OperandAt(0)->representation().IsInteger32());
850 ASSERT(instr->OperandAt(1)->representation().IsInteger32());
851 LOperand* left = UseRegisterAtStart(instr->OperandAt(0));
852
853 HValue* right_value = instr->OperandAt(1);
854 LOperand* right = NULL;
855 int constant_value = 0;
856 if (right_value->IsConstant()) {
857 HConstant* constant = HConstant::cast(right_value);
858 right = chunk_->DefineConstantOperand(constant);
859 constant_value = constant->Integer32Value() & 0x1f;
860 } else {
861 right = UseFixed(right_value, ecx);
862 }
863
erik.corry@gmail.com3847bd52011-04-27 10:38:56 +0000864 // Shift operations can only deoptimize if we do a logical shift by 0 and
865 // the result cannot be truncated to int32.
866 bool may_deopt = (op == Token::SHR && constant_value == 0);
867 bool does_deopt = false;
868 if (may_deopt) {
869 for (HUseIterator it(instr->uses()); !it.Done(); it.Advance()) {
870 if (!it.value()->CheckFlag(HValue::kTruncatingToInt32)) {
871 does_deopt = true;
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000872 break;
873 }
874 }
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000875 }
876
erik.corry@gmail.com3847bd52011-04-27 10:38:56 +0000877 LInstruction* result =
878 DefineSameAsFirst(new LShiftI(op, left, right, does_deopt));
879 return does_deopt ? AssignEnvironment(result) : result;
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000880}
881
882
883LInstruction* LChunkBuilder::DoArithmeticD(Token::Value op,
884 HArithmeticBinaryOperation* instr) {
885 ASSERT(instr->representation().IsDouble());
886 ASSERT(instr->left()->representation().IsDouble());
887 ASSERT(instr->right()->representation().IsDouble());
karlklose@chromium.org8f806e82011-03-07 14:06:08 +0000888 ASSERT(op != Token::MOD);
889 LOperand* left = UseRegisterAtStart(instr->left());
890 LOperand* right = UseRegisterAtStart(instr->right());
891 LArithmeticD* result = new LArithmeticD(op, left, right);
892 return DefineSameAsFirst(result);
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000893}
894
895
896LInstruction* LChunkBuilder::DoArithmeticT(Token::Value op,
897 HArithmeticBinaryOperation* instr) {
898 ASSERT(op == Token::ADD ||
899 op == Token::DIV ||
900 op == Token::MOD ||
901 op == Token::MUL ||
902 op == Token::SUB);
903 HValue* left = instr->left();
904 HValue* right = instr->right();
905 ASSERT(left->representation().IsTagged());
906 ASSERT(right->representation().IsTagged());
907 LOperand* left_operand = UseFixed(left, edx);
908 LOperand* right_operand = UseFixed(right, eax);
sgjesse@chromium.orgc6c57182011-01-17 12:24:25 +0000909 LArithmeticT* result = new LArithmeticT(op, left_operand, right_operand);
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000910 return MarkAsCall(DefineFixed(result, eax), instr);
911}
912
913void LChunkBuilder::DoBasicBlock(HBasicBlock* block, HBasicBlock* next_block) {
914 ASSERT(is_building());
915 current_block_ = block;
916 next_block_ = next_block;
917 if (block->IsStartBlock()) {
918 block->UpdateEnvironment(graph_->start_environment());
919 argument_count_ = 0;
920 } else if (block->predecessors()->length() == 1) {
921 // We have a single predecessor => copy environment and outgoing
922 // argument count from the predecessor.
923 ASSERT(block->phis()->length() == 0);
924 HBasicBlock* pred = block->predecessors()->at(0);
925 HEnvironment* last_environment = pred->last_environment();
926 ASSERT(last_environment != NULL);
927 // Only copy the environment, if it is later used again.
928 if (pred->end()->SecondSuccessor() == NULL) {
929 ASSERT(pred->end()->FirstSuccessor() == block);
930 } else {
931 if (pred->end()->FirstSuccessor()->block_id() > block->block_id() ||
932 pred->end()->SecondSuccessor()->block_id() > block->block_id()) {
933 last_environment = last_environment->Copy();
934 }
935 }
936 block->UpdateEnvironment(last_environment);
937 ASSERT(pred->argument_count() >= 0);
938 argument_count_ = pred->argument_count();
939 } else {
940 // We are at a state join => process phis.
941 HBasicBlock* pred = block->predecessors()->at(0);
942 // No need to copy the environment, it cannot be used later.
943 HEnvironment* last_environment = pred->last_environment();
944 for (int i = 0; i < block->phis()->length(); ++i) {
945 HPhi* phi = block->phis()->at(i);
946 last_environment->SetValueAt(phi->merged_index(), phi);
947 }
948 for (int i = 0; i < block->deleted_phis()->length(); ++i) {
949 last_environment->SetValueAt(block->deleted_phis()->at(i),
950 graph_->GetConstantUndefined());
951 }
952 block->UpdateEnvironment(last_environment);
953 // Pick up the outgoing argument count of one of the predecessors.
954 argument_count_ = pred->argument_count();
955 }
956 HInstruction* current = block->first();
957 int start = chunk_->instructions()->length();
958 while (current != NULL && !is_aborted()) {
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000959 // Code for constants in registers is generated lazily.
960 if (!current->EmitAtUses()) {
961 VisitInstruction(current);
962 }
963 current = current->next();
964 }
965 int end = chunk_->instructions()->length() - 1;
966 if (end >= start) {
967 block->set_first_instruction_index(start);
968 block->set_last_instruction_index(end);
969 }
970 block->set_argument_count(argument_count_);
971 next_block_ = NULL;
972 current_block_ = NULL;
973}
974
975
976void LChunkBuilder::VisitInstruction(HInstruction* current) {
977 HInstruction* old_current = current_instruction_;
978 current_instruction_ = current;
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000979 if (current->has_position()) position_ = current->position();
980 LInstruction* instr = current->CompileToLithium(this);
981
982 if (instr != NULL) {
983 if (FLAG_stress_pointer_maps && !instr->HasPointerMap()) {
984 instr = AssignPointerMap(instr);
985 }
986 if (FLAG_stress_environments && !instr->HasEnvironment()) {
987 instr = AssignEnvironment(instr);
988 }
vegorov@chromium.org0a4e9012011-01-24 12:33:13 +0000989 if (current->IsTest() && !instr->IsGoto()) {
erik.corry@gmail.com0511e242011-01-19 11:11:08 +0000990 ASSERT(instr->IsControl());
vegorov@chromium.org0a4e9012011-01-24 12:33:13 +0000991 HTest* test = HTest::cast(current);
992 instr->set_hydrogen_value(test->value());
993 HBasicBlock* first = test->FirstSuccessor();
994 HBasicBlock* second = test->SecondSuccessor();
erik.corry@gmail.com0511e242011-01-19 11:11:08 +0000995 ASSERT(first != NULL && second != NULL);
996 instr->SetBranchTargets(first->block_id(), second->block_id());
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000997 } else {
998 instr->set_hydrogen_value(current);
999 }
1000
ricow@chromium.org83aa5492011-02-07 12:42:56 +00001001 chunk_->AddInstruction(instr, current_block_);
kasperl@chromium.orga5551262010-12-07 12:49:48 +00001002 }
1003 current_instruction_ = old_current;
1004}
1005
1006
kasperl@chromium.orga5551262010-12-07 12:49:48 +00001007LEnvironment* LChunkBuilder::CreateEnvironment(HEnvironment* hydrogen_env) {
1008 if (hydrogen_env == NULL) return NULL;
1009
1010 LEnvironment* outer = CreateEnvironment(hydrogen_env->outer());
1011 int ast_id = hydrogen_env->ast_id();
1012 ASSERT(ast_id != AstNode::kNoNumber);
lrn@chromium.org5d00b602011-01-05 09:51:43 +00001013 int value_count = hydrogen_env->length();
kasperl@chromium.orga5551262010-12-07 12:49:48 +00001014 LEnvironment* result = new LEnvironment(hydrogen_env->closure(),
1015 ast_id,
1016 hydrogen_env->parameter_count(),
1017 argument_count_,
1018 value_count,
1019 outer);
1020 int argument_index = 0;
1021 for (int i = 0; i < value_count; ++i) {
karlklose@chromium.org83a47282011-05-11 11:54:09 +00001022 if (hydrogen_env->is_special_index(i)) continue;
1023
kasperl@chromium.orga5551262010-12-07 12:49:48 +00001024 HValue* value = hydrogen_env->values()->at(i);
1025 LOperand* op = NULL;
1026 if (value->IsArgumentsObject()) {
1027 op = NULL;
1028 } else if (value->IsPushArgument()) {
1029 op = new LArgument(argument_index++);
1030 } else {
erik.corry@gmail.com0511e242011-01-19 11:11:08 +00001031 op = UseAny(value);
kasperl@chromium.orga5551262010-12-07 12:49:48 +00001032 }
1033 result->AddValue(op, value->representation());
1034 }
1035
1036 return result;
1037}
1038
1039
1040LInstruction* LChunkBuilder::DoGoto(HGoto* instr) {
sgjesse@chromium.orgc6c57182011-01-17 12:24:25 +00001041 LGoto* result = new LGoto(instr->FirstSuccessor()->block_id(),
1042 instr->include_stack_check());
1043 return (instr->include_stack_check())
1044 ? AssignPointerMap(result)
1045 : result;
kasperl@chromium.orga5551262010-12-07 12:49:48 +00001046}
1047
1048
vegorov@chromium.org0a4e9012011-01-24 12:33:13 +00001049LInstruction* LChunkBuilder::DoTest(HTest* instr) {
kasperl@chromium.orga5551262010-12-07 12:49:48 +00001050 HValue* v = instr->value();
svenpanne@chromium.org6d786c92011-06-15 10:58:27 +00001051 if (!v->EmitAtUses()) return new LBranch(UseRegisterAtStart(v));
1052 ASSERT(!v->HasSideEffects());
1053 if (v->IsClassOfTest()) {
ager@chromium.orgea91cc52011-05-23 06:06:11 +00001054 HClassOfTest* compare = HClassOfTest::cast(v);
1055 ASSERT(compare->value()->representation().IsTagged());
1056 return new LClassOfTestAndBranch(UseTempRegister(compare->value()),
1057 TempRegister(),
1058 TempRegister());
1059 } else if (v->IsCompare()) {
1060 HCompare* compare = HCompare::cast(v);
ager@chromium.orgea91cc52011-05-23 06:06:11 +00001061 HValue* left = compare->left();
1062 HValue* right = compare->right();
1063 Representation r = compare->GetInputRepresentation();
1064 if (r.IsInteger32()) {
1065 ASSERT(left->representation().IsInteger32());
1066 ASSERT(right->representation().IsInteger32());
1067 return new LCmpIDAndBranch(UseRegisterAtStart(left),
1068 UseOrConstantAtStart(right));
svenpanne@chromium.org6d786c92011-06-15 10:58:27 +00001069 } else {
1070 ASSERT(r.IsDouble());
ager@chromium.orgea91cc52011-05-23 06:06:11 +00001071 ASSERT(left->representation().IsDouble());
1072 ASSERT(right->representation().IsDouble());
1073 return new LCmpIDAndBranch(UseRegisterAtStart(left),
1074 UseRegisterAtStart(right));
kasperl@chromium.orga5551262010-12-07 12:49:48 +00001075 }
ager@chromium.orgea91cc52011-05-23 06:06:11 +00001076 } else if (v->IsIsSmi()) {
1077 HIsSmi* compare = HIsSmi::cast(v);
1078 ASSERT(compare->value()->representation().IsTagged());
1079 return new LIsSmiAndBranch(Use(compare->value()));
1080 } else if (v->IsIsUndetectable()) {
1081 HIsUndetectable* compare = HIsUndetectable::cast(v);
1082 ASSERT(compare->value()->representation().IsTagged());
1083 return new LIsUndetectableAndBranch(UseRegisterAtStart(compare->value()),
1084 TempRegister());
1085 } else if (v->IsHasInstanceType()) {
1086 HHasInstanceType* compare = HHasInstanceType::cast(v);
1087 ASSERT(compare->value()->representation().IsTagged());
1088 return new LHasInstanceTypeAndBranch(UseRegisterAtStart(compare->value()),
1089 TempRegister());
1090 } else if (v->IsHasCachedArrayIndex()) {
1091 HHasCachedArrayIndex* compare = HHasCachedArrayIndex::cast(v);
1092 ASSERT(compare->value()->representation().IsTagged());
1093 return new LHasCachedArrayIndexAndBranch(
1094 UseRegisterAtStart(compare->value()));
1095 } else if (v->IsIsNull()) {
1096 HIsNull* compare = HIsNull::cast(v);
1097 ASSERT(compare->value()->representation().IsTagged());
1098 // We only need a temp register for non-strict compare.
1099 LOperand* temp = compare->is_strict() ? NULL : TempRegister();
1100 return new LIsNullAndBranch(UseRegisterAtStart(compare->value()), temp);
1101 } else if (v->IsIsObject()) {
1102 HIsObject* compare = HIsObject::cast(v);
1103 ASSERT(compare->value()->representation().IsTagged());
1104 LOperand* temp1 = TempRegister();
1105 LOperand* temp2 = TempRegister();
1106 return new LIsObjectAndBranch(UseRegisterAtStart(compare->value()),
1107 temp1,
1108 temp2);
1109 } else if (v->IsCompareJSObjectEq()) {
1110 HCompareJSObjectEq* compare = HCompareJSObjectEq::cast(v);
1111 return new LCmpJSObjectEqAndBranch(UseRegisterAtStart(compare->left()),
1112 UseRegisterAtStart(compare->right()));
1113 } else if (v->IsCompareSymbolEq()) {
1114 HCompareSymbolEq* compare = HCompareSymbolEq::cast(v);
1115 return new LCmpSymbolEqAndBranch(UseRegisterAtStart(compare->left()),
1116 UseRegisterAtStart(compare->right()));
ager@chromium.orgea91cc52011-05-23 06:06:11 +00001117 } else if (v->IsTypeofIs()) {
1118 HTypeofIs* typeof_is = HTypeofIs::cast(v);
1119 return new LTypeofIsAndBranch(UseTempRegister(typeof_is->value()));
1120 } else if (v->IsIsConstructCall()) {
1121 return new LIsConstructCallAndBranch(TempRegister());
1122 } else if (v->IsConstant()) {
1123 HBasicBlock* successor = HConstant::cast(v)->ToBoolean()
1124 ? instr->FirstSuccessor()
1125 : instr->SecondSuccessor();
1126 return new LGoto(successor->block_id());
1127 } else {
1128 Abort("Undefined compare before branch");
1129 return NULL;
kasperl@chromium.orga5551262010-12-07 12:49:48 +00001130 }
kasperl@chromium.orga5551262010-12-07 12:49:48 +00001131}
1132
1133
vegorov@chromium.org0a4e9012011-01-24 12:33:13 +00001134LInstruction* LChunkBuilder::DoCompareMap(HCompareMap* instr) {
kasperl@chromium.orga5551262010-12-07 12:49:48 +00001135 ASSERT(instr->value()->representation().IsTagged());
1136 LOperand* value = UseRegisterAtStart(instr->value());
kmillikin@chromium.orgd2c22f02011-01-10 08:15:37 +00001137 return new LCmpMapAndBranch(value);
kasperl@chromium.orga5551262010-12-07 12:49:48 +00001138}
1139
1140
1141LInstruction* LChunkBuilder::DoArgumentsLength(HArgumentsLength* length) {
1142 return DefineAsRegister(new LArgumentsLength(Use(length->value())));
1143}
1144
1145
1146LInstruction* LChunkBuilder::DoArgumentsElements(HArgumentsElements* elems) {
1147 return DefineAsRegister(new LArgumentsElements);
1148}
1149
1150
1151LInstruction* LChunkBuilder::DoInstanceOf(HInstanceOf* instr) {
sgjesse@chromium.org496c03a2011-02-14 12:05:43 +00001152 LOperand* left = UseFixed(instr->left(), InstanceofStub::left());
1153 LOperand* right = UseFixed(instr->right(), InstanceofStub::right());
1154 LOperand* context = UseFixed(instr->context(), esi);
1155 LInstanceOf* result = new LInstanceOf(context, left, right);
kasperl@chromium.orga5551262010-12-07 12:49:48 +00001156 return MarkAsCall(DefineFixed(result, eax), instr);
1157}
1158
1159
kmillikin@chromium.orgd2c22f02011-01-10 08:15:37 +00001160LInstruction* LChunkBuilder::DoInstanceOfKnownGlobal(
1161 HInstanceOfKnownGlobal* instr) {
sgjesse@chromium.orgc6c57182011-01-17 12:24:25 +00001162 LInstanceOfKnownGlobal* result =
kmillikin@chromium.orgd2c22f02011-01-10 08:15:37 +00001163 new LInstanceOfKnownGlobal(
1164 UseFixed(instr->value(), InstanceofStub::left()),
1165 FixedTemp(edi));
ager@chromium.org9ee27ae2011-03-02 13:43:26 +00001166 return MarkAsCall(DefineFixed(result, eax), instr);
kmillikin@chromium.orgd2c22f02011-01-10 08:15:37 +00001167}
1168
1169
kasperl@chromium.orga5551262010-12-07 12:49:48 +00001170LInstruction* LChunkBuilder::DoApplyArguments(HApplyArguments* instr) {
1171 LOperand* function = UseFixed(instr->function(), edi);
1172 LOperand* receiver = UseFixed(instr->receiver(), eax);
sgjesse@chromium.org496c03a2011-02-14 12:05:43 +00001173 LOperand* length = UseFixed(instr->length(), ebx);
1174 LOperand* elements = UseFixed(instr->elements(), ecx);
1175 LOperand* temp = FixedTemp(edx);
sgjesse@chromium.orgc6c57182011-01-17 12:24:25 +00001176 LApplyArguments* result = new LApplyArguments(function,
1177 receiver,
1178 length,
sgjesse@chromium.org496c03a2011-02-14 12:05:43 +00001179 elements,
1180 temp);
kasperl@chromium.orga5551262010-12-07 12:49:48 +00001181 return MarkAsCall(DefineFixed(result, eax), instr, CAN_DEOPTIMIZE_EAGERLY);
1182}
1183
1184
1185LInstruction* LChunkBuilder::DoPushArgument(HPushArgument* instr) {
1186 ++argument_count_;
kmillikin@chromium.orgc36ce6e2011-04-04 08:25:31 +00001187 LOperand* argument = UseAny(instr->argument());
kasperl@chromium.orga5551262010-12-07 12:49:48 +00001188 return new LPushArgument(argument);
1189}
1190
1191
ricow@chromium.orgd2be9012011-06-01 06:00:58 +00001192LInstruction* LChunkBuilder::DoThisFunction(HThisFunction* instr) {
1193 return instr->HasNoUses() ? NULL : DefineAsRegister(new LThisFunction);
1194}
1195
1196
ricow@chromium.org83aa5492011-02-07 12:42:56 +00001197LInstruction* LChunkBuilder::DoContext(HContext* instr) {
vegorov@chromium.org7304bca2011-05-16 12:14:13 +00001198 return instr->HasNoUses() ? NULL : DefineAsRegister(new LContext);
ricow@chromium.org83aa5492011-02-07 12:42:56 +00001199}
1200
1201
1202LInstruction* LChunkBuilder::DoOuterContext(HOuterContext* instr) {
1203 LOperand* context = UseRegisterAtStart(instr->value());
1204 return DefineAsRegister(new LOuterContext(context));
1205}
1206
1207
kasperl@chromium.orga5551262010-12-07 12:49:48 +00001208LInstruction* LChunkBuilder::DoGlobalObject(HGlobalObject* instr) {
ricow@chromium.org83aa5492011-02-07 12:42:56 +00001209 LOperand* context = UseRegisterAtStart(instr->value());
1210 return DefineAsRegister(new LGlobalObject(context));
kasperl@chromium.orga5551262010-12-07 12:49:48 +00001211}
1212
1213
1214LInstruction* LChunkBuilder::DoGlobalReceiver(HGlobalReceiver* instr) {
ricow@chromium.org83aa5492011-02-07 12:42:56 +00001215 LOperand* global_object = UseRegisterAtStart(instr->value());
1216 return DefineAsRegister(new LGlobalReceiver(global_object));
kasperl@chromium.orga5551262010-12-07 12:49:48 +00001217}
1218
1219
1220LInstruction* LChunkBuilder::DoCallConstantFunction(
1221 HCallConstantFunction* instr) {
1222 argument_count_ -= instr->argument_count();
1223 return MarkAsCall(DefineFixed(new LCallConstantFunction, eax), instr);
1224}
1225
1226
danno@chromium.org160a7b02011-04-18 15:51:38 +00001227LInstruction* LChunkBuilder::DoInvokeFunction(HInvokeFunction* instr) {
1228 LOperand* context = UseFixed(instr->context(), esi);
1229 LOperand* function = UseFixed(instr->function(), edi);
1230 argument_count_ -= instr->argument_count();
1231 LInvokeFunction* result = new LInvokeFunction(context, function);
1232 return MarkAsCall(DefineFixed(result, eax), instr, CANNOT_DEOPTIMIZE_EAGERLY);
1233}
1234
1235
kasperl@chromium.orga5551262010-12-07 12:49:48 +00001236LInstruction* LChunkBuilder::DoUnaryMathOperation(HUnaryMathOperation* instr) {
ager@chromium.org5f0c45f2010-12-17 08:51:21 +00001237 BuiltinFunctionId op = instr->op();
vegorov@chromium.org74f333b2011-04-06 11:17:46 +00001238 if (op == kMathLog) {
1239 ASSERT(instr->representation().IsDouble());
1240 ASSERT(instr->value()->representation().IsDouble());
1241 LOperand* input = UseRegisterAtStart(instr->value());
1242 LUnaryMathOperation* result = new LUnaryMathOperation(input);
1243 return DefineSameAsFirst(result);
1244 } else if (op == kMathSin || op == kMathCos) {
ager@chromium.org5f0c45f2010-12-17 08:51:21 +00001245 LOperand* input = UseFixedDouble(instr->value(), xmm1);
sgjesse@chromium.orgc6c57182011-01-17 12:24:25 +00001246 LUnaryMathOperation* result = new LUnaryMathOperation(input);
ager@chromium.org5f0c45f2010-12-17 08:51:21 +00001247 return MarkAsCall(DefineFixedDouble(result, xmm1), instr);
1248 } else {
1249 LOperand* input = UseRegisterAtStart(instr->value());
sgjesse@chromium.orgc6c57182011-01-17 12:24:25 +00001250 LUnaryMathOperation* result = new LUnaryMathOperation(input);
ager@chromium.org5f0c45f2010-12-17 08:51:21 +00001251 switch (op) {
1252 case kMathAbs:
1253 return AssignEnvironment(AssignPointerMap(DefineSameAsFirst(result)));
1254 case kMathFloor:
1255 return AssignEnvironment(DefineAsRegister(result));
1256 case kMathRound:
1257 return AssignEnvironment(DefineAsRegister(result));
1258 case kMathSqrt:
1259 return DefineSameAsFirst(result);
1260 case kMathPowHalf:
fschneider@chromium.org3a5fd782011-02-24 10:10:44 +00001261 return DefineSameAsFirst(result);
ager@chromium.org5f0c45f2010-12-17 08:51:21 +00001262 default:
1263 UNREACHABLE();
1264 return NULL;
1265 }
kasperl@chromium.orga5551262010-12-07 12:49:48 +00001266 }
1267}
1268
1269
1270LInstruction* LChunkBuilder::DoCallKeyed(HCallKeyed* instr) {
1271 ASSERT(instr->key()->representation().IsTagged());
sgjesse@chromium.org496c03a2011-02-14 12:05:43 +00001272 LOperand* context = UseFixed(instr->context(), esi);
erik.corry@gmail.com0511e242011-01-19 11:11:08 +00001273 LOperand* key = UseFixed(instr->key(), ecx);
sgjesse@chromium.org496c03a2011-02-14 12:05:43 +00001274 argument_count_ -= instr->argument_count();
1275 LCallKeyed* result = new LCallKeyed(context, key);
1276 return MarkAsCall(DefineFixed(result, eax), instr);
kasperl@chromium.orga5551262010-12-07 12:49:48 +00001277}
1278
1279
1280LInstruction* LChunkBuilder::DoCallNamed(HCallNamed* instr) {
sgjesse@chromium.org496c03a2011-02-14 12:05:43 +00001281 LOperand* context = UseFixed(instr->context(), esi);
kasperl@chromium.orga5551262010-12-07 12:49:48 +00001282 argument_count_ -= instr->argument_count();
sgjesse@chromium.org496c03a2011-02-14 12:05:43 +00001283 LCallNamed* result = new LCallNamed(context);
1284 return MarkAsCall(DefineFixed(result, eax), instr);
kasperl@chromium.orga5551262010-12-07 12:49:48 +00001285}
1286
1287
1288LInstruction* LChunkBuilder::DoCallGlobal(HCallGlobal* instr) {
sgjesse@chromium.org496c03a2011-02-14 12:05:43 +00001289 LOperand* context = UseFixed(instr->context(), esi);
kasperl@chromium.orga5551262010-12-07 12:49:48 +00001290 argument_count_ -= instr->argument_count();
sgjesse@chromium.org496c03a2011-02-14 12:05:43 +00001291 LCallGlobal* result = new LCallGlobal(context);
1292 return MarkAsCall(DefineFixed(result, eax), instr);
kasperl@chromium.orga5551262010-12-07 12:49:48 +00001293}
1294
1295
1296LInstruction* LChunkBuilder::DoCallKnownGlobal(HCallKnownGlobal* instr) {
1297 argument_count_ -= instr->argument_count();
1298 return MarkAsCall(DefineFixed(new LCallKnownGlobal, eax), instr);
1299}
1300
1301
1302LInstruction* LChunkBuilder::DoCallNew(HCallNew* instr) {
sgjesse@chromium.org496c03a2011-02-14 12:05:43 +00001303 LOperand* context = UseFixed(instr->context(), esi);
kasperl@chromium.orga5551262010-12-07 12:49:48 +00001304 LOperand* constructor = UseFixed(instr->constructor(), edi);
1305 argument_count_ -= instr->argument_count();
sgjesse@chromium.org496c03a2011-02-14 12:05:43 +00001306 LCallNew* result = new LCallNew(context, constructor);
kasperl@chromium.orga5551262010-12-07 12:49:48 +00001307 return MarkAsCall(DefineFixed(result, eax), instr);
1308}
1309
1310
1311LInstruction* LChunkBuilder::DoCallFunction(HCallFunction* instr) {
sgjesse@chromium.org496c03a2011-02-14 12:05:43 +00001312 LOperand* context = UseFixed(instr->context(), esi);
kasperl@chromium.orga5551262010-12-07 12:49:48 +00001313 argument_count_ -= instr->argument_count();
sgjesse@chromium.org496c03a2011-02-14 12:05:43 +00001314 LCallFunction* result = new LCallFunction(context);
1315 return MarkAsCall(DefineFixed(result, eax), instr);
kasperl@chromium.orga5551262010-12-07 12:49:48 +00001316}
1317
1318
1319LInstruction* LChunkBuilder::DoCallRuntime(HCallRuntime* instr) {
1320 argument_count_ -= instr->argument_count();
1321 return MarkAsCall(DefineFixed(new LCallRuntime, eax), instr);
1322}
1323
1324
1325LInstruction* LChunkBuilder::DoShr(HShr* instr) {
1326 return DoShift(Token::SHR, instr);
1327}
1328
1329
1330LInstruction* LChunkBuilder::DoSar(HSar* instr) {
1331 return DoShift(Token::SAR, instr);
1332}
1333
1334
1335LInstruction* LChunkBuilder::DoShl(HShl* instr) {
1336 return DoShift(Token::SHL, instr);
1337}
1338
1339
1340LInstruction* LChunkBuilder::DoBitAnd(HBitAnd* instr) {
1341 return DoBit(Token::BIT_AND, instr);
1342}
1343
1344
1345LInstruction* LChunkBuilder::DoBitNot(HBitNot* instr) {
1346 ASSERT(instr->value()->representation().IsInteger32());
1347 ASSERT(instr->representation().IsInteger32());
sgjesse@chromium.orgc6c57182011-01-17 12:24:25 +00001348 LOperand* input = UseRegisterAtStart(instr->value());
1349 LBitNotI* result = new LBitNotI(input);
1350 return DefineSameAsFirst(result);
kasperl@chromium.orga5551262010-12-07 12:49:48 +00001351}
1352
1353
1354LInstruction* LChunkBuilder::DoBitOr(HBitOr* instr) {
1355 return DoBit(Token::BIT_OR, instr);
1356}
1357
1358
1359LInstruction* LChunkBuilder::DoBitXor(HBitXor* instr) {
1360 return DoBit(Token::BIT_XOR, instr);
1361}
1362
1363
1364LInstruction* LChunkBuilder::DoDiv(HDiv* instr) {
1365 if (instr->representation().IsDouble()) {
1366 return DoArithmeticD(Token::DIV, instr);
1367 } else if (instr->representation().IsInteger32()) {
1368 // The temporary operand is necessary to ensure that right is not allocated
1369 // into edx.
erik.corry@gmail.com0511e242011-01-19 11:11:08 +00001370 LOperand* temp = FixedTemp(edx);
erik.corry@gmail.comd91075f2011-02-10 07:45:38 +00001371 LOperand* dividend = UseFixed(instr->left(), eax);
kasperl@chromium.orga5551262010-12-07 12:49:48 +00001372 LOperand* divisor = UseRegister(instr->right());
erik.corry@gmail.comd91075f2011-02-10 07:45:38 +00001373 LDivI* result = new LDivI(dividend, divisor, temp);
erik.corry@gmail.com0511e242011-01-19 11:11:08 +00001374 return AssignEnvironment(DefineFixed(result, eax));
kasperl@chromium.orga5551262010-12-07 12:49:48 +00001375 } else {
1376 ASSERT(instr->representation().IsTagged());
1377 return DoArithmeticT(Token::DIV, instr);
1378 }
1379}
1380
1381
1382LInstruction* LChunkBuilder::DoMod(HMod* instr) {
1383 if (instr->representation().IsInteger32()) {
1384 ASSERT(instr->left()->representation().IsInteger32());
1385 ASSERT(instr->right()->representation().IsInteger32());
whesse@chromium.orgb08986c2011-03-14 16:13:42 +00001386
1387 LInstruction* result;
1388 if (instr->HasPowerOf2Divisor()) {
1389 ASSERT(!instr->CheckFlag(HValue::kCanBeDivByZero));
1390 LOperand* value = UseRegisterAtStart(instr->left());
1391 LModI* mod = new LModI(value, UseOrConstant(instr->right()), NULL);
1392 result = DefineSameAsFirst(mod);
1393 } else {
1394 // The temporary operand is necessary to ensure that right is
1395 // not allocated into edx.
1396 LOperand* temp = FixedTemp(edx);
1397 LOperand* value = UseFixed(instr->left(), eax);
1398 LOperand* divisor = UseRegister(instr->right());
1399 LModI* mod = new LModI(value, divisor, temp);
1400 result = DefineFixed(mod, edx);
1401 }
1402
sgjesse@chromium.orgc6c57182011-01-17 12:24:25 +00001403 return (instr->CheckFlag(HValue::kBailoutOnMinusZero) ||
1404 instr->CheckFlag(HValue::kCanBeDivByZero))
1405 ? AssignEnvironment(result)
1406 : result;
kasperl@chromium.orga5551262010-12-07 12:49:48 +00001407 } else if (instr->representation().IsTagged()) {
1408 return DoArithmeticT(Token::MOD, instr);
1409 } else {
1410 ASSERT(instr->representation().IsDouble());
1411 // We call a C function for double modulo. It can't trigger a GC.
1412 // We need to use fixed result register for the call.
1413 // TODO(fschneider): Allow any register as input registers.
karlklose@chromium.org8f806e82011-03-07 14:06:08 +00001414 LOperand* left = UseFixedDouble(instr->left(), xmm2);
1415 LOperand* right = UseFixedDouble(instr->right(), xmm1);
kasperl@chromium.orga5551262010-12-07 12:49:48 +00001416 LArithmeticD* result = new LArithmeticD(Token::MOD, left, right);
1417 return MarkAsCall(DefineFixedDouble(result, xmm1), instr);
1418 }
1419}
1420
1421
1422LInstruction* LChunkBuilder::DoMul(HMul* instr) {
1423 if (instr->representation().IsInteger32()) {
1424 ASSERT(instr->left()->representation().IsInteger32());
1425 ASSERT(instr->right()->representation().IsInteger32());
1426 LOperand* left = UseRegisterAtStart(instr->LeastConstantOperand());
1427 LOperand* right = UseOrConstant(instr->MostConstantOperand());
1428 LOperand* temp = NULL;
1429 if (instr->CheckFlag(HValue::kBailoutOnMinusZero)) {
1430 temp = TempRegister();
1431 }
1432 LMulI* mul = new LMulI(left, right, temp);
1433 return AssignEnvironment(DefineSameAsFirst(mul));
1434 } else if (instr->representation().IsDouble()) {
1435 return DoArithmeticD(Token::MUL, instr);
1436 } else {
1437 ASSERT(instr->representation().IsTagged());
1438 return DoArithmeticT(Token::MUL, instr);
1439 }
1440}
1441
1442
1443LInstruction* LChunkBuilder::DoSub(HSub* instr) {
1444 if (instr->representation().IsInteger32()) {
1445 ASSERT(instr->left()->representation().IsInteger32());
1446 ASSERT(instr->right()->representation().IsInteger32());
ager@chromium.org0ee099b2011-01-25 14:06:47 +00001447 LOperand* left = UseRegisterAtStart(instr->left());
1448 LOperand* right = UseOrConstantAtStart(instr->right());
kasperl@chromium.orga5551262010-12-07 12:49:48 +00001449 LSubI* sub = new LSubI(left, right);
1450 LInstruction* result = DefineSameAsFirst(sub);
1451 if (instr->CheckFlag(HValue::kCanOverflow)) {
1452 result = AssignEnvironment(result);
1453 }
1454 return result;
1455 } else if (instr->representation().IsDouble()) {
1456 return DoArithmeticD(Token::SUB, instr);
1457 } else {
1458 ASSERT(instr->representation().IsTagged());
1459 return DoArithmeticT(Token::SUB, instr);
1460 }
1461}
1462
1463
1464LInstruction* LChunkBuilder::DoAdd(HAdd* instr) {
1465 if (instr->representation().IsInteger32()) {
1466 ASSERT(instr->left()->representation().IsInteger32());
1467 ASSERT(instr->right()->representation().IsInteger32());
1468 LOperand* left = UseRegisterAtStart(instr->LeastConstantOperand());
1469 LOperand* right = UseOrConstantAtStart(instr->MostConstantOperand());
1470 LAddI* add = new LAddI(left, right);
1471 LInstruction* result = DefineSameAsFirst(add);
1472 if (instr->CheckFlag(HValue::kCanOverflow)) {
1473 result = AssignEnvironment(result);
1474 }
1475 return result;
1476 } else if (instr->representation().IsDouble()) {
1477 return DoArithmeticD(Token::ADD, instr);
1478 } else {
1479 ASSERT(instr->representation().IsTagged());
1480 return DoArithmeticT(Token::ADD, instr);
1481 }
1482}
1483
1484
ager@chromium.org5f0c45f2010-12-17 08:51:21 +00001485LInstruction* LChunkBuilder::DoPower(HPower* instr) {
1486 ASSERT(instr->representation().IsDouble());
1487 // We call a C function for double power. It can't trigger a GC.
1488 // We need to use fixed result register for the call.
1489 Representation exponent_type = instr->right()->representation();
1490 ASSERT(instr->left()->representation().IsDouble());
1491 LOperand* left = UseFixedDouble(instr->left(), xmm1);
1492 LOperand* right = exponent_type.IsDouble() ?
1493 UseFixedDouble(instr->right(), xmm2) :
1494 UseFixed(instr->right(), eax);
1495 LPower* result = new LPower(left, right);
1496 return MarkAsCall(DefineFixedDouble(result, xmm3), instr,
1497 CAN_DEOPTIMIZE_EAGERLY);
1498}
1499
1500
kasperl@chromium.orga5551262010-12-07 12:49:48 +00001501LInstruction* LChunkBuilder::DoCompare(HCompare* instr) {
1502 Token::Value op = instr->token();
sgjesse@chromium.orgc6c57182011-01-17 12:24:25 +00001503 Representation r = instr->GetInputRepresentation();
1504 if (r.IsInteger32()) {
1505 ASSERT(instr->left()->representation().IsInteger32());
kasperl@chromium.orga5551262010-12-07 12:49:48 +00001506 ASSERT(instr->right()->representation().IsInteger32());
1507 LOperand* left = UseRegisterAtStart(instr->left());
1508 LOperand* right = UseOrConstantAtStart(instr->right());
sgjesse@chromium.orgc6c57182011-01-17 12:24:25 +00001509 return DefineAsRegister(new LCmpID(left, right));
1510 } else if (r.IsDouble()) {
1511 ASSERT(instr->left()->representation().IsDouble());
kasperl@chromium.orga5551262010-12-07 12:49:48 +00001512 ASSERT(instr->right()->representation().IsDouble());
1513 LOperand* left = UseRegisterAtStart(instr->left());
1514 LOperand* right = UseRegisterAtStart(instr->right());
sgjesse@chromium.orgc6c57182011-01-17 12:24:25 +00001515 return DefineAsRegister(new LCmpID(left, right));
kasperl@chromium.orga5551262010-12-07 12:49:48 +00001516 } else {
sgjesse@chromium.orgc6c57182011-01-17 12:24:25 +00001517 ASSERT(instr->left()->representation().IsTagged());
1518 ASSERT(instr->right()->representation().IsTagged());
kasperl@chromium.orga5551262010-12-07 12:49:48 +00001519 bool reversed = (op == Token::GT || op == Token::LTE);
1520 LOperand* left = UseFixed(instr->left(), reversed ? eax : edx);
1521 LOperand* right = UseFixed(instr->right(), reversed ? edx : eax);
sgjesse@chromium.orgc6c57182011-01-17 12:24:25 +00001522 LCmpT* result = new LCmpT(left, right);
kasperl@chromium.orga5551262010-12-07 12:49:48 +00001523 return MarkAsCall(DefineFixed(result, eax), instr);
1524 }
1525}
1526
1527
1528LInstruction* LChunkBuilder::DoCompareJSObjectEq(
1529 HCompareJSObjectEq* instr) {
1530 LOperand* left = UseRegisterAtStart(instr->left());
1531 LOperand* right = UseRegisterAtStart(instr->right());
sgjesse@chromium.orgc6c57182011-01-17 12:24:25 +00001532 LCmpJSObjectEq* result = new LCmpJSObjectEq(left, right);
kasperl@chromium.orga5551262010-12-07 12:49:48 +00001533 return DefineAsRegister(result);
1534}
1535
1536
vegorov@chromium.org7304bca2011-05-16 12:14:13 +00001537LInstruction* LChunkBuilder::DoCompareSymbolEq(
1538 HCompareSymbolEq* instr) {
1539 LOperand* left = UseRegisterAtStart(instr->left());
1540 LOperand* right = UseRegisterAtStart(instr->right());
1541 LCmpSymbolEq* result = new LCmpSymbolEq(left, right);
1542 return DefineAsRegister(result);
1543}
1544
1545
kasperl@chromium.orga5551262010-12-07 12:49:48 +00001546LInstruction* LChunkBuilder::DoIsNull(HIsNull* instr) {
1547 ASSERT(instr->value()->representation().IsTagged());
1548 LOperand* value = UseRegisterAtStart(instr->value());
1549
sgjesse@chromium.orgc6c57182011-01-17 12:24:25 +00001550 return DefineAsRegister(new LIsNull(value));
kasperl@chromium.orga5551262010-12-07 12:49:48 +00001551}
1552
1553
ager@chromium.org5f0c45f2010-12-17 08:51:21 +00001554LInstruction* LChunkBuilder::DoIsObject(HIsObject* instr) {
1555 ASSERT(instr->value()->representation().IsTagged());
1556 LOperand* value = UseRegister(instr->value());
1557
1558 return DefineAsRegister(new LIsObject(value, TempRegister()));
1559}
1560
1561
kasperl@chromium.orga5551262010-12-07 12:49:48 +00001562LInstruction* LChunkBuilder::DoIsSmi(HIsSmi* instr) {
1563 ASSERT(instr->value()->representation().IsTagged());
1564 LOperand* value = UseAtStart(instr->value());
1565
1566 return DefineAsRegister(new LIsSmi(value));
1567}
1568
1569
vegorov@chromium.org7304bca2011-05-16 12:14:13 +00001570LInstruction* LChunkBuilder::DoIsUndetectable(HIsUndetectable* instr) {
1571 ASSERT(instr->value()->representation().IsTagged());
1572 LOperand* value = UseRegisterAtStart(instr->value());
1573
1574 return DefineAsRegister(new LIsUndetectable(value));
1575}
1576
1577
kasperl@chromium.orga5551262010-12-07 12:49:48 +00001578LInstruction* LChunkBuilder::DoHasInstanceType(HHasInstanceType* instr) {
1579 ASSERT(instr->value()->representation().IsTagged());
1580 LOperand* value = UseRegisterAtStart(instr->value());
1581
1582 return DefineAsRegister(new LHasInstanceType(value));
1583}
1584
1585
kmillikin@chromium.org49edbdf2011-02-16 12:32:18 +00001586LInstruction* LChunkBuilder::DoGetCachedArrayIndex(
1587 HGetCachedArrayIndex* instr) {
karlklose@chromium.org8f806e82011-03-07 14:06:08 +00001588 ASSERT(instr->value()->representation().IsTagged());
1589 LOperand* value = UseRegisterAtStart(instr->value());
1590
1591 return DefineAsRegister(new LGetCachedArrayIndex(value));
kmillikin@chromium.org49edbdf2011-02-16 12:32:18 +00001592}
1593
1594
kasperl@chromium.orga5551262010-12-07 12:49:48 +00001595LInstruction* LChunkBuilder::DoHasCachedArrayIndex(
1596 HHasCachedArrayIndex* instr) {
1597 ASSERT(instr->value()->representation().IsTagged());
1598 LOperand* value = UseRegister(instr->value());
1599
1600 return DefineAsRegister(new LHasCachedArrayIndex(value));
1601}
1602
1603
1604LInstruction* LChunkBuilder::DoClassOfTest(HClassOfTest* instr) {
1605 ASSERT(instr->value()->representation().IsTagged());
1606 LOperand* value = UseTempRegister(instr->value());
1607
1608 return DefineSameAsFirst(new LClassOfTest(value, TempRegister()));
1609}
1610
1611
fschneider@chromium.org9e3e0b62011-01-03 10:16:46 +00001612LInstruction* LChunkBuilder::DoJSArrayLength(HJSArrayLength* instr) {
1613 LOperand* array = UseRegisterAtStart(instr->value());
1614 return DefineAsRegister(new LJSArrayLength(array));
1615}
kasperl@chromium.orga5551262010-12-07 12:49:48 +00001616
kasperl@chromium.orga5551262010-12-07 12:49:48 +00001617
fschneider@chromium.org9e3e0b62011-01-03 10:16:46 +00001618LInstruction* LChunkBuilder::DoFixedArrayLength(HFixedArrayLength* instr) {
1619 LOperand* array = UseRegisterAtStart(instr->value());
1620 return DefineAsRegister(new LFixedArrayLength(array));
kasperl@chromium.orga5551262010-12-07 12:49:48 +00001621}
1622
1623
danno@chromium.org4d3fe4e2011-03-10 10:14:28 +00001624LInstruction* LChunkBuilder::DoExternalArrayLength(
1625 HExternalArrayLength* instr) {
sgjesse@chromium.org496c03a2011-02-14 12:05:43 +00001626 LOperand* array = UseRegisterAtStart(instr->value());
danno@chromium.org4d3fe4e2011-03-10 10:14:28 +00001627 return DefineAsRegister(new LExternalArrayLength(array));
sgjesse@chromium.org496c03a2011-02-14 12:05:43 +00001628}
1629
1630
kasperl@chromium.orga5551262010-12-07 12:49:48 +00001631LInstruction* LChunkBuilder::DoValueOf(HValueOf* instr) {
1632 LOperand* object = UseRegister(instr->value());
sgjesse@chromium.orgc6c57182011-01-17 12:24:25 +00001633 LValueOf* result = new LValueOf(object, TempRegister());
kasperl@chromium.orga5551262010-12-07 12:49:48 +00001634 return AssignEnvironment(DefineSameAsFirst(result));
1635}
1636
1637
1638LInstruction* LChunkBuilder::DoBoundsCheck(HBoundsCheck* instr) {
1639 return AssignEnvironment(new LBoundsCheck(UseRegisterAtStart(instr->index()),
1640 Use(instr->length())));
1641}
1642
1643
kmillikin@chromium.org31b12772011-02-02 16:08:26 +00001644LInstruction* LChunkBuilder::DoAbnormalExit(HAbnormalExit* instr) {
1645 // The control instruction marking the end of a block that completed
1646 // abruptly (e.g., threw an exception). There is nothing specific to do.
1647 return NULL;
1648}
1649
1650
kasperl@chromium.orga5551262010-12-07 12:49:48 +00001651LInstruction* LChunkBuilder::DoThrow(HThrow* instr) {
1652 LOperand* value = UseFixed(instr->value(), eax);
1653 return MarkAsCall(new LThrow(value), instr);
1654}
1655
1656
ricow@chromium.orgd2be9012011-06-01 06:00:58 +00001657LInstruction* LChunkBuilder::DoUseConst(HUseConst* instr) {
1658 return NULL;
1659}
1660
1661
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001662LInstruction* LChunkBuilder::DoForceRepresentation(HForceRepresentation* bad) {
1663 // All HForceRepresentation instructions should be eliminated in the
1664 // representation change phase of Hydrogen.
1665 UNREACHABLE();
1666 return NULL;
1667}
1668
1669
kasperl@chromium.orga5551262010-12-07 12:49:48 +00001670LInstruction* LChunkBuilder::DoChange(HChange* instr) {
1671 Representation from = instr->from();
1672 Representation to = instr->to();
1673 if (from.IsTagged()) {
1674 if (to.IsDouble()) {
1675 LOperand* value = UseRegister(instr->value());
sgjesse@chromium.orgc6c57182011-01-17 12:24:25 +00001676 LNumberUntagD* res = new LNumberUntagD(value);
kasperl@chromium.orga5551262010-12-07 12:49:48 +00001677 return AssignEnvironment(DefineAsRegister(res));
1678 } else {
1679 ASSERT(to.IsInteger32());
1680 LOperand* value = UseRegister(instr->value());
1681 bool needs_check = !instr->value()->type().IsSmi();
1682 if (needs_check) {
ricow@chromium.orgc54d3652011-05-30 09:20:16 +00001683 bool truncating = instr->CanTruncateToInt32();
kasperl@chromium.orga5551262010-12-07 12:49:48 +00001684 LOperand* xmm_temp =
ricow@chromium.orgc54d3652011-05-30 09:20:16 +00001685 (truncating && CpuFeatures::IsSupported(SSE3))
kasperl@chromium.orga5551262010-12-07 12:49:48 +00001686 ? NULL
1687 : FixedTemp(xmm1);
sgjesse@chromium.orgc6c57182011-01-17 12:24:25 +00001688 LTaggedToI* res = new LTaggedToI(value, xmm_temp);
kasperl@chromium.orga5551262010-12-07 12:49:48 +00001689 return AssignEnvironment(DefineSameAsFirst(res));
1690 } else {
1691 return DefineSameAsFirst(new LSmiUntag(value, needs_check));
1692 }
1693 }
1694 } else if (from.IsDouble()) {
1695 if (to.IsTagged()) {
1696 LOperand* value = UseRegister(instr->value());
1697 LOperand* temp = TempRegister();
1698
1699 // Make sure that temp and result_temp are different registers.
1700 LUnallocated* result_temp = TempRegister();
sgjesse@chromium.orgc6c57182011-01-17 12:24:25 +00001701 LNumberTagD* result = new LNumberTagD(value, temp);
kasperl@chromium.orga5551262010-12-07 12:49:48 +00001702 return AssignPointerMap(Define(result, result_temp));
1703 } else {
1704 ASSERT(to.IsInteger32());
ricow@chromium.orgc54d3652011-05-30 09:20:16 +00001705 bool truncating = instr->CanTruncateToInt32();
1706 bool needs_temp = truncating && !CpuFeatures::IsSupported(SSE3);
sgjesse@chromium.orgc6c57182011-01-17 12:24:25 +00001707 LOperand* value = needs_temp ?
1708 UseTempRegister(instr->value()) : UseRegister(instr->value());
1709 LOperand* temp = needs_temp ? TempRegister() : NULL;
1710 return AssignEnvironment(DefineAsRegister(new LDoubleToI(value, temp)));
kasperl@chromium.orga5551262010-12-07 12:49:48 +00001711 }
1712 } else if (from.IsInteger32()) {
1713 if (to.IsTagged()) {
1714 HValue* val = instr->value();
1715 LOperand* value = UseRegister(val);
1716 if (val->HasRange() && val->range()->IsInSmiRange()) {
1717 return DefineSameAsFirst(new LSmiTag(value));
1718 } else {
sgjesse@chromium.orgc6c57182011-01-17 12:24:25 +00001719 LNumberTagI* result = new LNumberTagI(value);
kasperl@chromium.orga5551262010-12-07 12:49:48 +00001720 return AssignEnvironment(AssignPointerMap(DefineSameAsFirst(result)));
1721 }
1722 } else {
1723 ASSERT(to.IsDouble());
1724 return DefineAsRegister(new LInteger32ToDouble(Use(instr->value())));
1725 }
1726 }
1727 UNREACHABLE();
1728 return NULL;
1729}
1730
1731
1732LInstruction* LChunkBuilder::DoCheckNonSmi(HCheckNonSmi* instr) {
1733 LOperand* value = UseRegisterAtStart(instr->value());
ricow@chromium.orgbadaffc2011-03-17 12:15:27 +00001734 return AssignEnvironment(new LCheckNonSmi(value));
kasperl@chromium.orga5551262010-12-07 12:49:48 +00001735}
1736
1737
1738LInstruction* LChunkBuilder::DoCheckInstanceType(HCheckInstanceType* instr) {
1739 LOperand* value = UseRegisterAtStart(instr->value());
1740 LOperand* temp = TempRegister();
sgjesse@chromium.orgc6c57182011-01-17 12:24:25 +00001741 LCheckInstanceType* result = new LCheckInstanceType(value, temp);
kasperl@chromium.orga5551262010-12-07 12:49:48 +00001742 return AssignEnvironment(result);
1743}
1744
1745
1746LInstruction* LChunkBuilder::DoCheckPrototypeMaps(HCheckPrototypeMaps* instr) {
1747 LOperand* temp = TempRegister();
sgjesse@chromium.orgc6c57182011-01-17 12:24:25 +00001748 LCheckPrototypeMaps* result = new LCheckPrototypeMaps(temp);
kasperl@chromium.orga5551262010-12-07 12:49:48 +00001749 return AssignEnvironment(result);
1750}
1751
1752
1753LInstruction* LChunkBuilder::DoCheckSmi(HCheckSmi* instr) {
1754 LOperand* value = UseRegisterAtStart(instr->value());
ricow@chromium.orgbadaffc2011-03-17 12:15:27 +00001755 return AssignEnvironment(new LCheckSmi(value));
kasperl@chromium.orga5551262010-12-07 12:49:48 +00001756}
1757
1758
1759LInstruction* LChunkBuilder::DoCheckFunction(HCheckFunction* instr) {
1760 LOperand* value = UseRegisterAtStart(instr->value());
1761 return AssignEnvironment(new LCheckFunction(value));
1762}
1763
1764
1765LInstruction* LChunkBuilder::DoCheckMap(HCheckMap* instr) {
1766 LOperand* value = UseRegisterAtStart(instr->value());
sgjesse@chromium.orgc6c57182011-01-17 12:24:25 +00001767 LCheckMap* result = new LCheckMap(value);
kasperl@chromium.orga5551262010-12-07 12:49:48 +00001768 return AssignEnvironment(result);
1769}
1770
1771
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001772LInstruction* LChunkBuilder::DoClampToUint8(HClampToUint8* instr) {
1773 HValue* value = instr->value();
1774 Representation input_rep = value->representation();
1775 if (input_rep.IsDouble()) {
1776 LOperand* reg = UseRegister(value);
1777 return DefineAsRegister(new LClampDToUint8(reg));
1778 } else if (input_rep.IsInteger32()) {
1779 LOperand* reg = UseFixed(value, eax);
1780 return DefineFixed(new LClampIToUint8(reg), eax);
1781 } else {
1782 ASSERT(input_rep.IsTagged());
1783 LOperand* reg = UseFixed(value, eax);
1784 // Register allocator doesn't (yet) support allocation of double
1785 // temps. Reserve xmm1 explicitly.
1786 LOperand* temp = FixedTemp(xmm1);
1787 LClampTToUint8* result = new LClampTToUint8(reg, temp);
1788 return AssignEnvironment(DefineFixed(result, eax));
1789 }
1790}
1791
1792
ricow@chromium.orgc54d3652011-05-30 09:20:16 +00001793LInstruction* LChunkBuilder::DoToInt32(HToInt32* instr) {
1794 HValue* value = instr->value();
1795 Representation input_rep = value->representation();
1796
1797 LInstruction* result;
1798 if (input_rep.IsDouble()) {
1799 LOperand* reg = UseRegister(value);
1800 LOperand* temp_reg =
1801 CpuFeatures::IsSupported(SSE3) ? NULL : TempRegister();
1802 result = DefineAsRegister(new LDoubleToI(reg, temp_reg));
1803 } else if (input_rep.IsInteger32()) {
1804 // Canonicalization should already have removed the hydrogen instruction in
1805 // this case, since it is a noop.
1806 UNREACHABLE();
1807 return NULL;
1808 } else {
1809 ASSERT(input_rep.IsTagged());
1810 LOperand* reg = UseRegister(value);
1811 // Register allocator doesn't (yet) support allocation of double
1812 // temps. Reserve xmm1 explicitly.
1813 LOperand* xmm_temp =
1814 CpuFeatures::IsSupported(SSE3) ? NULL : FixedTemp(xmm1);
1815 result = DefineSameAsFirst(new LTaggedToI(reg, xmm_temp));
1816 }
1817 return AssignEnvironment(result);
1818}
1819
1820
kasperl@chromium.orga5551262010-12-07 12:49:48 +00001821LInstruction* LChunkBuilder::DoReturn(HReturn* instr) {
1822 return new LReturn(UseFixed(instr->value(), eax));
1823}
1824
1825
1826LInstruction* LChunkBuilder::DoConstant(HConstant* instr) {
1827 Representation r = instr->representation();
1828 if (r.IsInteger32()) {
erik.corry@gmail.comd91075f2011-02-10 07:45:38 +00001829 return DefineAsRegister(new LConstantI);
kasperl@chromium.orga5551262010-12-07 12:49:48 +00001830 } else if (r.IsDouble()) {
1831 double value = instr->DoubleValue();
erik.corry@gmail.comd91075f2011-02-10 07:45:38 +00001832 LOperand* temp = (BitCast<uint64_t, double>(value) != 0)
1833 ? TempRegister()
1834 : NULL;
1835 return DefineAsRegister(new LConstantD(temp));
kasperl@chromium.orga5551262010-12-07 12:49:48 +00001836 } else if (r.IsTagged()) {
erik.corry@gmail.comd91075f2011-02-10 07:45:38 +00001837 return DefineAsRegister(new LConstantT);
kasperl@chromium.orga5551262010-12-07 12:49:48 +00001838 } else {
sgjesse@chromium.orgc6c57182011-01-17 12:24:25 +00001839 UNREACHABLE();
kasperl@chromium.orga5551262010-12-07 12:49:48 +00001840 return NULL;
1841 }
1842}
1843
1844
kmillikin@chromium.orgc36ce6e2011-04-04 08:25:31 +00001845LInstruction* LChunkBuilder::DoLoadGlobalCell(HLoadGlobalCell* instr) {
1846 LLoadGlobalCell* result = new LLoadGlobalCell;
kasperl@chromium.orga5551262010-12-07 12:49:48 +00001847 return instr->check_hole_value()
1848 ? AssignEnvironment(DefineAsRegister(result))
1849 : DefineAsRegister(result);
1850}
1851
1852
kmillikin@chromium.orgc36ce6e2011-04-04 08:25:31 +00001853LInstruction* LChunkBuilder::DoLoadGlobalGeneric(HLoadGlobalGeneric* instr) {
1854 LOperand* context = UseFixed(instr->context(), esi);
1855 LOperand* global_object = UseFixed(instr->global_object(), eax);
1856 LLoadGlobalGeneric* result = new LLoadGlobalGeneric(context, global_object);
1857 return MarkAsCall(DefineFixed(result, eax), instr);
1858}
1859
1860
vegorov@chromium.org74f333b2011-04-06 11:17:46 +00001861LInstruction* LChunkBuilder::DoStoreGlobalCell(HStoreGlobalCell* instr) {
1862 LStoreGlobalCell* result =
1863 new LStoreGlobalCell(UseRegisterAtStart(instr->value()));
ager@chromium.org378b34e2011-01-28 08:04:38 +00001864 return instr->check_hole_value() ? AssignEnvironment(result) : result;
kasperl@chromium.orga5551262010-12-07 12:49:48 +00001865}
1866
1867
vegorov@chromium.org74f333b2011-04-06 11:17:46 +00001868LInstruction* LChunkBuilder::DoStoreGlobalGeneric(HStoreGlobalGeneric* instr) {
1869 LOperand* context = UseFixed(instr->context(), esi);
1870 LOperand* global_object = UseFixed(instr->global_object(), edx);
1871 LOperand* value = UseFixed(instr->value(), eax);
1872 LStoreGlobalGeneric* result =
1873 new LStoreGlobalGeneric(context, global_object, value);
1874 return MarkAsCall(result, instr);
1875}
1876
1877
sgjesse@chromium.orgc6c57182011-01-17 12:24:25 +00001878LInstruction* LChunkBuilder::DoLoadContextSlot(HLoadContextSlot* instr) {
ricow@chromium.org83aa5492011-02-07 12:42:56 +00001879 LOperand* context = UseRegisterAtStart(instr->value());
1880 return DefineAsRegister(new LLoadContextSlot(context));
1881}
1882
1883
1884LInstruction* LChunkBuilder::DoStoreContextSlot(HStoreContextSlot* instr) {
1885 LOperand* context;
1886 LOperand* value;
1887 LOperand* temp;
1888 if (instr->NeedsWriteBarrier()) {
1889 context = UseTempRegister(instr->context());
1890 value = UseTempRegister(instr->value());
1891 temp = TempRegister();
1892 } else {
1893 context = UseRegister(instr->context());
1894 value = UseRegister(instr->value());
1895 temp = NULL;
1896 }
1897 return new LStoreContextSlot(context, value, temp);
sgjesse@chromium.orgc6c57182011-01-17 12:24:25 +00001898}
1899
1900
kasperl@chromium.orga5551262010-12-07 12:49:48 +00001901LInstruction* LChunkBuilder::DoLoadNamedField(HLoadNamedField* instr) {
sgjesse@chromium.orgc6c57182011-01-17 12:24:25 +00001902 ASSERT(instr->representation().IsTagged());
1903 LOperand* obj = UseRegisterAtStart(instr->object());
1904 return DefineAsRegister(new LLoadNamedField(obj));
kasperl@chromium.orga5551262010-12-07 12:49:48 +00001905}
1906
1907
fschneider@chromium.org7979bbb2011-03-28 10:47:03 +00001908LInstruction* LChunkBuilder::DoLoadNamedFieldPolymorphic(
1909 HLoadNamedFieldPolymorphic* instr) {
1910 ASSERT(instr->representation().IsTagged());
1911 if (instr->need_generic()) {
1912 LOperand* obj = UseFixed(instr->object(), eax);
1913 LLoadNamedFieldPolymorphic* result = new LLoadNamedFieldPolymorphic(obj);
1914 return MarkAsCall(DefineFixed(result, eax), instr);
1915 } else {
1916 LOperand* obj = UseRegisterAtStart(instr->object());
1917 LLoadNamedFieldPolymorphic* result = new LLoadNamedFieldPolymorphic(obj);
1918 return AssignEnvironment(DefineAsRegister(result));
1919 }
1920}
1921
1922
kasperl@chromium.orga5551262010-12-07 12:49:48 +00001923LInstruction* LChunkBuilder::DoLoadNamedGeneric(HLoadNamedGeneric* instr) {
sgjesse@chromium.org496c03a2011-02-14 12:05:43 +00001924 LOperand* context = UseFixed(instr->context(), esi);
kasperl@chromium.orga5551262010-12-07 12:49:48 +00001925 LOperand* object = UseFixed(instr->object(), eax);
sgjesse@chromium.org496c03a2011-02-14 12:05:43 +00001926 LLoadNamedGeneric* result = new LLoadNamedGeneric(context, object);
sgjesse@chromium.orgc6c57182011-01-17 12:24:25 +00001927 return MarkAsCall(DefineFixed(result, eax), instr);
kasperl@chromium.orga5551262010-12-07 12:49:48 +00001928}
1929
1930
fschneider@chromium.org9e3e0b62011-01-03 10:16:46 +00001931LInstruction* LChunkBuilder::DoLoadFunctionPrototype(
1932 HLoadFunctionPrototype* instr) {
1933 return AssignEnvironment(DefineAsRegister(
1934 new LLoadFunctionPrototype(UseRegister(instr->function()),
1935 TempRegister())));
1936}
1937
1938
kasperl@chromium.orga5551262010-12-07 12:49:48 +00001939LInstruction* LChunkBuilder::DoLoadElements(HLoadElements* instr) {
1940 LOperand* input = UseRegisterAtStart(instr->value());
sgjesse@chromium.org496c03a2011-02-14 12:05:43 +00001941 return DefineAsRegister(new LLoadElements(input));
1942}
1943
1944
danno@chromium.org4d3fe4e2011-03-10 10:14:28 +00001945LInstruction* LChunkBuilder::DoLoadExternalArrayPointer(
1946 HLoadExternalArrayPointer* instr) {
sgjesse@chromium.org496c03a2011-02-14 12:05:43 +00001947 LOperand* input = UseRegisterAtStart(instr->value());
danno@chromium.org4d3fe4e2011-03-10 10:14:28 +00001948 return DefineAsRegister(new LLoadExternalArrayPointer(input));
kasperl@chromium.orga5551262010-12-07 12:49:48 +00001949}
1950
1951
1952LInstruction* LChunkBuilder::DoLoadKeyedFastElement(
1953 HLoadKeyedFastElement* instr) {
sgjesse@chromium.orgc6c57182011-01-17 12:24:25 +00001954 ASSERT(instr->representation().IsTagged());
kasperl@chromium.orga5551262010-12-07 12:49:48 +00001955 ASSERT(instr->key()->representation().IsInteger32());
sgjesse@chromium.orgc6c57182011-01-17 12:24:25 +00001956 LOperand* obj = UseRegisterAtStart(instr->object());
kasperl@chromium.orga5551262010-12-07 12:49:48 +00001957 LOperand* key = UseRegisterAtStart(instr->key());
sgjesse@chromium.orgc6c57182011-01-17 12:24:25 +00001958 LLoadKeyedFastElement* result = new LLoadKeyedFastElement(obj, key);
1959 return AssignEnvironment(DefineSameAsFirst(result));
kasperl@chromium.orga5551262010-12-07 12:49:48 +00001960}
1961
1962
fschneider@chromium.org7979bbb2011-03-28 10:47:03 +00001963LInstruction* LChunkBuilder::DoLoadKeyedSpecializedArrayElement(
1964 HLoadKeyedSpecializedArrayElement* instr) {
svenpanne@chromium.org6d786c92011-06-15 10:58:27 +00001965 JSObject::ElementsKind elements_kind = instr->elements_kind();
fschneider@chromium.org7979bbb2011-03-28 10:47:03 +00001966 Representation representation(instr->representation());
erik.corry@gmail.com3847bd52011-04-27 10:38:56 +00001967 ASSERT(
svenpanne@chromium.org6d786c92011-06-15 10:58:27 +00001968 (representation.IsInteger32() &&
1969 (elements_kind != JSObject::EXTERNAL_FLOAT_ELEMENTS) &&
1970 (elements_kind != JSObject::EXTERNAL_DOUBLE_ELEMENTS)) ||
1971 (representation.IsDouble() &&
1972 ((elements_kind == JSObject::EXTERNAL_FLOAT_ELEMENTS) ||
1973 (elements_kind == JSObject::EXTERNAL_DOUBLE_ELEMENTS))));
sgjesse@chromium.org496c03a2011-02-14 12:05:43 +00001974 ASSERT(instr->key()->representation().IsInteger32());
fschneider@chromium.org7979bbb2011-03-28 10:47:03 +00001975 LOperand* external_pointer = UseRegister(instr->external_pointer());
karlklose@chromium.org83a47282011-05-11 11:54:09 +00001976 LOperand* key = UseRegisterOrConstant(instr->key());
fschneider@chromium.org7979bbb2011-03-28 10:47:03 +00001977 LLoadKeyedSpecializedArrayElement* result =
1978 new LLoadKeyedSpecializedArrayElement(external_pointer,
1979 key);
1980 LInstruction* load_instr = DefineAsRegister(result);
1981 // An unsigned int array load might overflow and cause a deopt, make sure it
1982 // has an environment.
svenpanne@chromium.org6d786c92011-06-15 10:58:27 +00001983 return (elements_kind == JSObject::EXTERNAL_UNSIGNED_INT_ELEMENTS)
fschneider@chromium.org7979bbb2011-03-28 10:47:03 +00001984 ? AssignEnvironment(load_instr)
1985 : load_instr;
sgjesse@chromium.org496c03a2011-02-14 12:05:43 +00001986}
1987
1988
kasperl@chromium.orga5551262010-12-07 12:49:48 +00001989LInstruction* LChunkBuilder::DoLoadKeyedGeneric(HLoadKeyedGeneric* instr) {
sgjesse@chromium.org496c03a2011-02-14 12:05:43 +00001990 LOperand* context = UseFixed(instr->context(), esi);
kasperl@chromium.orga5551262010-12-07 12:49:48 +00001991 LOperand* object = UseFixed(instr->object(), edx);
1992 LOperand* key = UseFixed(instr->key(), eax);
1993
sgjesse@chromium.org496c03a2011-02-14 12:05:43 +00001994 LLoadKeyedGeneric* result = new LLoadKeyedGeneric(context, object, key);
sgjesse@chromium.orgc6c57182011-01-17 12:24:25 +00001995 return MarkAsCall(DefineFixed(result, eax), instr);
kasperl@chromium.orga5551262010-12-07 12:49:48 +00001996}
1997
1998
1999LInstruction* LChunkBuilder::DoStoreKeyedFastElement(
2000 HStoreKeyedFastElement* instr) {
2001 bool needs_write_barrier = instr->NeedsWriteBarrier();
2002 ASSERT(instr->value()->representation().IsTagged());
2003 ASSERT(instr->object()->representation().IsTagged());
2004 ASSERT(instr->key()->representation().IsInteger32());
2005
2006 LOperand* obj = UseTempRegister(instr->object());
2007 LOperand* val = needs_write_barrier
2008 ? UseTempRegister(instr->value())
2009 : UseRegisterAtStart(instr->value());
2010 LOperand* key = needs_write_barrier
2011 ? UseTempRegister(instr->key())
2012 : UseRegisterOrConstantAtStart(instr->key());
2013
2014 return AssignEnvironment(new LStoreKeyedFastElement(obj, key, val));
2015}
2016
2017
fschneider@chromium.org7979bbb2011-03-28 10:47:03 +00002018LInstruction* LChunkBuilder::DoStoreKeyedSpecializedArrayElement(
2019 HStoreKeyedSpecializedArrayElement* instr) {
2020 Representation representation(instr->value()->representation());
svenpanne@chromium.org6d786c92011-06-15 10:58:27 +00002021 JSObject::ElementsKind elements_kind = instr->elements_kind();
2022 ASSERT(
2023 (representation.IsInteger32() &&
2024 (elements_kind != JSObject::EXTERNAL_FLOAT_ELEMENTS) &&
2025 (elements_kind != JSObject::EXTERNAL_DOUBLE_ELEMENTS)) ||
2026 (representation.IsDouble() &&
2027 ((elements_kind == JSObject::EXTERNAL_FLOAT_ELEMENTS) ||
2028 (elements_kind == JSObject::EXTERNAL_DOUBLE_ELEMENTS))));
fschneider@chromium.org3a5fd782011-02-24 10:10:44 +00002029 ASSERT(instr->external_pointer()->representation().IsExternal());
2030 ASSERT(instr->key()->representation().IsInteger32());
2031
2032 LOperand* external_pointer = UseRegister(instr->external_pointer());
karlklose@chromium.org83a47282011-05-11 11:54:09 +00002033 LOperand* key = UseRegisterOrConstant(instr->key());
lrn@chromium.org7516f052011-03-30 08:52:27 +00002034 LOperand* val = NULL;
svenpanne@chromium.org6d786c92011-06-15 10:58:27 +00002035 if (elements_kind == JSObject::EXTERNAL_BYTE_ELEMENTS ||
2036 elements_kind == JSObject::EXTERNAL_UNSIGNED_BYTE_ELEMENTS ||
2037 elements_kind == JSObject::EXTERNAL_PIXEL_ELEMENTS) {
lrn@chromium.org7516f052011-03-30 08:52:27 +00002038 // We need a byte register in this case for the value.
2039 val = UseFixed(instr->value(), eax);
2040 } else {
2041 val = UseRegister(instr->value());
2042 }
2043
fschneider@chromium.org7979bbb2011-03-28 10:47:03 +00002044 return new LStoreKeyedSpecializedArrayElement(external_pointer,
2045 key,
ager@chromium.orgea91cc52011-05-23 06:06:11 +00002046 val);
fschneider@chromium.org3a5fd782011-02-24 10:10:44 +00002047}
2048
2049
kasperl@chromium.orga5551262010-12-07 12:49:48 +00002050LInstruction* LChunkBuilder::DoStoreKeyedGeneric(HStoreKeyedGeneric* instr) {
sgjesse@chromium.org496c03a2011-02-14 12:05:43 +00002051 LOperand* context = UseFixed(instr->context(), esi);
2052 LOperand* object = UseFixed(instr->object(), edx);
kasperl@chromium.orga5551262010-12-07 12:49:48 +00002053 LOperand* key = UseFixed(instr->key(), ecx);
sgjesse@chromium.org496c03a2011-02-14 12:05:43 +00002054 LOperand* value = UseFixed(instr->value(), eax);
kasperl@chromium.orga5551262010-12-07 12:49:48 +00002055
2056 ASSERT(instr->object()->representation().IsTagged());
2057 ASSERT(instr->key()->representation().IsTagged());
2058 ASSERT(instr->value()->representation().IsTagged());
2059
sgjesse@chromium.org496c03a2011-02-14 12:05:43 +00002060 LStoreKeyedGeneric* result =
2061 new LStoreKeyedGeneric(context, object, key, value);
2062 return MarkAsCall(result, instr);
kasperl@chromium.orga5551262010-12-07 12:49:48 +00002063}
2064
2065
2066LInstruction* LChunkBuilder::DoStoreNamedField(HStoreNamedField* instr) {
fschneider@chromium.org9e3e0b62011-01-03 10:16:46 +00002067 bool needs_write_barrier = instr->NeedsWriteBarrier();
kasperl@chromium.orga5551262010-12-07 12:49:48 +00002068
2069 LOperand* obj = needs_write_barrier
2070 ? UseTempRegister(instr->object())
2071 : UseRegisterAtStart(instr->object());
2072
2073 LOperand* val = needs_write_barrier
2074 ? UseTempRegister(instr->value())
2075 : UseRegister(instr->value());
2076
2077 // We only need a scratch register if we have a write barrier or we
2078 // have a store into the properties array (not in-object-property).
2079 LOperand* temp = (!instr->is_in_object() || needs_write_barrier)
ricow@chromium.org83aa5492011-02-07 12:42:56 +00002080 ? TempRegister()
2081 : NULL;
kasperl@chromium.orga5551262010-12-07 12:49:48 +00002082
sgjesse@chromium.orgc6c57182011-01-17 12:24:25 +00002083 return new LStoreNamedField(obj, val, temp);
kasperl@chromium.orga5551262010-12-07 12:49:48 +00002084}
2085
2086
2087LInstruction* LChunkBuilder::DoStoreNamedGeneric(HStoreNamedGeneric* instr) {
sgjesse@chromium.org496c03a2011-02-14 12:05:43 +00002088 LOperand* context = UseFixed(instr->context(), esi);
2089 LOperand* object = UseFixed(instr->object(), edx);
2090 LOperand* value = UseFixed(instr->value(), eax);
kasperl@chromium.orga5551262010-12-07 12:49:48 +00002091
sgjesse@chromium.org496c03a2011-02-14 12:05:43 +00002092 LStoreNamedGeneric* result = new LStoreNamedGeneric(context, object, value);
kasperl@chromium.orga5551262010-12-07 12:49:48 +00002093 return MarkAsCall(result, instr);
2094}
2095
2096
danno@chromium.org160a7b02011-04-18 15:51:38 +00002097LInstruction* LChunkBuilder::DoStringAdd(HStringAdd* instr) {
2098 LOperand* left = UseOrConstantAtStart(instr->left());
2099 LOperand* right = UseOrConstantAtStart(instr->right());
2100 return MarkAsCall(DefineFixed(new LStringAdd(left, right), eax), instr);
2101}
2102
2103
vegorov@chromium.org0a4e9012011-01-24 12:33:13 +00002104LInstruction* LChunkBuilder::DoStringCharCodeAt(HStringCharCodeAt* instr) {
2105 LOperand* string = UseRegister(instr->string());
2106 LOperand* index = UseRegisterOrConstant(instr->index());
2107 LStringCharCodeAt* result = new LStringCharCodeAt(string, index);
2108 return AssignEnvironment(AssignPointerMap(DefineAsRegister(result)));
2109}
2110
2111
whesse@chromium.orgb08986c2011-03-14 16:13:42 +00002112LInstruction* LChunkBuilder::DoStringCharFromCode(HStringCharFromCode* instr) {
2113 LOperand* char_code = UseRegister(instr->value());
2114 LStringCharFromCode* result = new LStringCharFromCode(char_code);
2115 return AssignPointerMap(DefineAsRegister(result));
2116}
2117
2118
vegorov@chromium.org0a4e9012011-01-24 12:33:13 +00002119LInstruction* LChunkBuilder::DoStringLength(HStringLength* instr) {
2120 LOperand* string = UseRegisterAtStart(instr->value());
2121 return DefineAsRegister(new LStringLength(string));
2122}
2123
2124
kasperl@chromium.orga5551262010-12-07 12:49:48 +00002125LInstruction* LChunkBuilder::DoArrayLiteral(HArrayLiteral* instr) {
2126 return MarkAsCall(DefineFixed(new LArrayLiteral, eax), instr);
2127}
2128
2129
2130LInstruction* LChunkBuilder::DoObjectLiteral(HObjectLiteral* instr) {
sgjesse@chromium.org496c03a2011-02-14 12:05:43 +00002131 LOperand* context = UseFixed(instr->context(), esi);
2132 return MarkAsCall(DefineFixed(new LObjectLiteral(context), eax), instr);
kasperl@chromium.orga5551262010-12-07 12:49:48 +00002133}
2134
2135
2136LInstruction* LChunkBuilder::DoRegExpLiteral(HRegExpLiteral* instr) {
2137 return MarkAsCall(DefineFixed(new LRegExpLiteral, eax), instr);
2138}
2139
2140
2141LInstruction* LChunkBuilder::DoFunctionLiteral(HFunctionLiteral* instr) {
2142 return MarkAsCall(DefineFixed(new LFunctionLiteral, eax), instr);
2143}
2144
2145
2146LInstruction* LChunkBuilder::DoDeleteProperty(HDeleteProperty* instr) {
fschneider@chromium.org3a5fd782011-02-24 10:10:44 +00002147 LDeleteProperty* result =
danno@chromium.org160a7b02011-04-18 15:51:38 +00002148 new LDeleteProperty(UseAtStart(instr->object()),
2149 UseOrConstantAtStart(instr->key()));
kasperl@chromium.orga5551262010-12-07 12:49:48 +00002150 return MarkAsCall(DefineFixed(result, eax), instr);
2151}
2152
2153
2154LInstruction* LChunkBuilder::DoOsrEntry(HOsrEntry* instr) {
2155 allocator_->MarkAsOsrEntry();
2156 current_block_->last_environment()->set_ast_id(instr->ast_id());
2157 return AssignEnvironment(new LOsrEntry);
2158}
2159
2160
2161LInstruction* LChunkBuilder::DoParameter(HParameter* instr) {
2162 int spill_index = chunk()->GetParameterStackSlot(instr->index());
2163 return DefineAsSpilled(new LParameter, spill_index);
2164}
2165
2166
2167LInstruction* LChunkBuilder::DoUnknownOSRValue(HUnknownOSRValue* instr) {
2168 int spill_index = chunk()->GetNextSpillIndex(false); // Not double-width.
2169 return DefineAsSpilled(new LUnknownOSRValue, spill_index);
2170}
2171
2172
2173LInstruction* LChunkBuilder::DoCallStub(HCallStub* instr) {
sgjesse@chromium.org496c03a2011-02-14 12:05:43 +00002174 LOperand* context = UseFixed(instr->context(), esi);
kasperl@chromium.orga5551262010-12-07 12:49:48 +00002175 argument_count_ -= instr->argument_count();
sgjesse@chromium.org496c03a2011-02-14 12:05:43 +00002176 LCallStub* result = new LCallStub(context);
2177 return MarkAsCall(DefineFixed(result, eax), instr);
kasperl@chromium.orga5551262010-12-07 12:49:48 +00002178}
2179
2180
2181LInstruction* LChunkBuilder::DoArgumentsObject(HArgumentsObject* instr) {
fschneider@chromium.org3a5fd782011-02-24 10:10:44 +00002182 // There are no real uses of the arguments object.
2183 // arguments.length and element access are supported directly on
2184 // stack arguments, and any real arguments object use causes a bailout.
2185 // So this value is never used.
kasperl@chromium.orga5551262010-12-07 12:49:48 +00002186 return NULL;
2187}
2188
2189
2190LInstruction* LChunkBuilder::DoAccessArgumentsAt(HAccessArgumentsAt* instr) {
2191 LOperand* arguments = UseRegister(instr->arguments());
2192 LOperand* length = UseTempRegister(instr->length());
2193 LOperand* index = Use(instr->index());
sgjesse@chromium.orgc6c57182011-01-17 12:24:25 +00002194 LAccessArgumentsAt* result = new LAccessArgumentsAt(arguments, length, index);
2195 return AssignEnvironment(DefineAsRegister(result));
kasperl@chromium.orga5551262010-12-07 12:49:48 +00002196}
2197
2198
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +00002199LInstruction* LChunkBuilder::DoToFastProperties(HToFastProperties* instr) {
2200 LOperand* object = UseFixed(instr->value(), eax);
2201 LToFastProperties* result = new LToFastProperties(object);
2202 return MarkAsCall(DefineFixed(result, eax), instr);
2203}
2204
2205
kasperl@chromium.orga5551262010-12-07 12:49:48 +00002206LInstruction* LChunkBuilder::DoTypeof(HTypeof* instr) {
sgjesse@chromium.orgc6c57182011-01-17 12:24:25 +00002207 LTypeof* result = new LTypeof(UseAtStart(instr->value()));
kasperl@chromium.orga5551262010-12-07 12:49:48 +00002208 return MarkAsCall(DefineFixed(result, eax), instr);
2209}
2210
2211
2212LInstruction* LChunkBuilder::DoTypeofIs(HTypeofIs* instr) {
2213 return DefineSameAsFirst(new LTypeofIs(UseRegister(instr->value())));
2214}
2215
erik.corry@gmail.comd91075f2011-02-10 07:45:38 +00002216
2217LInstruction* LChunkBuilder::DoIsConstructCall(HIsConstructCall* instr) {
2218 return DefineAsRegister(new LIsConstructCall);
2219}
2220
2221
kasperl@chromium.orga5551262010-12-07 12:49:48 +00002222LInstruction* LChunkBuilder::DoSimulate(HSimulate* instr) {
2223 HEnvironment* env = current_block_->last_environment();
2224 ASSERT(env != NULL);
2225
2226 env->set_ast_id(instr->ast_id());
2227
2228 env->Drop(instr->pop_count());
2229 for (int i = 0; i < instr->values()->length(); ++i) {
2230 HValue* value = instr->values()->at(i);
2231 if (instr->HasAssignedIndexAt(i)) {
2232 env->Bind(instr->GetAssignedIndexAt(i), value);
2233 } else {
2234 env->Push(value);
2235 }
2236 }
kasperl@chromium.orga5551262010-12-07 12:49:48 +00002237
2238 // If there is an instruction pending deoptimization environment create a
2239 // lazy bailout instruction to capture the environment.
kmillikin@chromium.org31b12772011-02-02 16:08:26 +00002240 if (pending_deoptimization_ast_id_ != AstNode::kNoNumber) {
2241 ASSERT(pending_deoptimization_ast_id_ == instr->ast_id());
sgjesse@chromium.orgc6c57182011-01-17 12:24:25 +00002242 LLazyBailout* lazy_bailout = new LLazyBailout;
2243 LInstruction* result = AssignEnvironment(lazy_bailout);
kmillikin@chromium.org31b12772011-02-02 16:08:26 +00002244 instruction_pending_deoptimization_environment_->
fschneider@chromium.org1df6b472011-01-26 08:23:03 +00002245 set_deoptimization_environment(result->environment());
2246 ClearInstructionPendingDeoptimizationEnvironment();
kasperl@chromium.orga5551262010-12-07 12:49:48 +00002247 return result;
2248 }
2249
2250 return NULL;
2251}
2252
2253
2254LInstruction* LChunkBuilder::DoStackCheck(HStackCheck* instr) {
2255 return MarkAsCall(new LStackCheck, instr);
2256}
2257
2258
2259LInstruction* LChunkBuilder::DoEnterInlined(HEnterInlined* instr) {
2260 HEnvironment* outer = current_block_->last_environment();
2261 HConstant* undefined = graph()->GetConstantUndefined();
2262 HEnvironment* inner = outer->CopyForInlining(instr->closure(),
2263 instr->function(),
lrn@chromium.org1c092762011-05-09 09:42:16 +00002264 HEnvironment::LITHIUM,
danno@chromium.org40cb8782011-05-25 07:58:50 +00002265 undefined,
2266 instr->call_kind());
kasperl@chromium.orga5551262010-12-07 12:49:48 +00002267 current_block_->UpdateEnvironment(inner);
2268 chunk_->AddInlinedClosure(instr->closure());
2269 return NULL;
2270}
2271
2272
2273LInstruction* LChunkBuilder::DoLeaveInlined(HLeaveInlined* instr) {
2274 HEnvironment* outer = current_block_->last_environment()->outer();
2275 current_block_->UpdateEnvironment(outer);
2276 return NULL;
2277}
2278
2279
erik.corry@gmail.com3847bd52011-04-27 10:38:56 +00002280LInstruction* LChunkBuilder::DoIn(HIn* instr) {
2281 LOperand* key = UseOrConstantAtStart(instr->key());
2282 LOperand* object = UseOrConstantAtStart(instr->object());
2283 LIn* result = new LIn(key, object);
2284 return MarkAsCall(DefineFixed(result, eax), instr);
2285}
2286
2287
kasperl@chromium.orga5551262010-12-07 12:49:48 +00002288} } // namespace v8::internal
sgjesse@chromium.orgc6c57182011-01-17 12:24:25 +00002289
2290#endif // V8_TARGET_ARCH_IA32