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