| 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(); | |
| 844 | 674 |
| 845 LInstruction* instr = NULL; | 675 LInstruction* instr = NULL; |
| 846 if (current->CanReplaceWithDummyUses()) { | 676 if (current->CanReplaceWithDummyUses()) { |
| 847 if (current->OperandCount() == 0) { | 677 if (current->OperandCount() == 0) { |
| 848 instr = DefineAsRegister(new(zone()) LDummy()); | 678 instr = DefineAsRegister(new(zone()) LDummy()); |
| 849 } else { | 679 } else { |
| 680 ASSERT(!current->OperandAt(0)->IsControlInstruction()); |
| 850 instr = DefineAsRegister(new(zone()) | 681 instr = DefineAsRegister(new(zone()) |
| 851 LDummyUse(UseAny(current->OperandAt(0)))); | 682 LDummyUse(UseAny(current->OperandAt(0)))); |
| 852 } | 683 } |
| 853 for (int i = 1; i < current->OperandCount(); ++i) { | 684 for (int i = 1; i < current->OperandCount(); ++i) { |
| 685 if (current->OperandAt(i)->IsControlInstruction()) continue; |
| 854 LInstruction* dummy = | 686 LInstruction* dummy = |
| 855 new(zone()) LDummyUse(UseAny(current->OperandAt(i))); | 687 new(zone()) LDummyUse(UseAny(current->OperandAt(i))); |
| 856 dummy->set_hydrogen_value(current); | 688 dummy->set_hydrogen_value(current); |
| 857 chunk_->AddInstruction(dummy, current_block_); | 689 chunk_->AddInstruction(dummy, current_block_); |
| 858 } | 690 } |
| 859 } else { | 691 } else { |
| 860 instr = current->CompileToLithium(this); | 692 instr = current->CompileToLithium(this); |
| 861 } | 693 } |
| 862 | 694 |
| 863 argument_count_ += current->argument_delta(); | 695 argument_count_ += current->argument_delta(); |
| 864 ASSERT(argument_count_ >= 0); | 696 ASSERT(argument_count_ >= 0); |
| 865 | 697 |
| 866 if (instr != NULL) { | 698 if (instr != NULL) { |
| 867 // Associate the hydrogen instruction first, since we may need it for | 699 // Associate the hydrogen instruction first, since we may need it for |
| 868 // the ClobbersRegisters() or ClobbersDoubleRegisters() calls below. | 700 // the ClobbersRegisters() or ClobbersDoubleRegisters() calls below. |
| 869 instr->set_hydrogen_value(current); | 701 instr->set_hydrogen_value(current); |
| 870 | 702 |
| 871 #if DEBUG | 703 #if DEBUG |
| 872 // Make sure that the lithium instruction has either no fixed register | 704 // Make sure that the lithium instruction has either no fixed register |
| 873 // constraints in temps or the result OR no uses that are only used at | 705 // constraints in temps or the result OR no uses that are only used at |
| 874 // start. If this invariant doesn't hold, the register allocator can decide | 706 // start. If this invariant doesn't hold, the register allocator can decide |
| 875 // to insert a split of a range immediately before the instruction due to an | 707 // to insert a split of a range immediately before the instruction due to an |
| 876 // already allocated register needing to be used for the instruction's fixed | 708 // already allocated register needing to be used for the instruction's fixed |
| 877 // register constraint. In this case, The register allocator won't see an | 709 // register constraint. In this case, the register allocator won't see an |
| 878 // interference between the split child and the use-at-start (it would if | 710 // interference between the split child and the use-at-start (it would if |
| 879 // the it was just a plain use), so it is free to move the split child into | 711 // the it was just a plain use), so it is free to move the split child into |
| 880 // the same register that is used for the use-at-start. | 712 // the same register that is used for the use-at-start. |
| 881 // See https://code.google.com/p/chromium/issues/detail?id=201590 | 713 // See https://code.google.com/p/chromium/issues/detail?id=201590 |
| 882 if (!(instr->ClobbersRegisters() && instr->ClobbersDoubleRegisters())) { | 714 if (!(instr->ClobbersRegisters() && instr->ClobbersDoubleRegisters())) { |
| 883 int fixed = 0; | 715 int fixed = 0; |
| 884 int used_at_start = 0; | 716 int used_at_start = 0; |
| 885 for (UseIterator it(instr); !it.Done(); it.Advance()) { | 717 for (UseIterator it(instr); !it.Done(); it.Advance()) { |
| 886 LUnallocated* operand = LUnallocated::cast(it.Current()); | 718 LUnallocated* operand = LUnallocated::cast(it.Current()); |
| 887 if (operand->IsUsedAtStart()) ++used_at_start; | 719 if (operand->IsUsedAtStart()) ++used_at_start; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 902 } | 734 } |
| 903 if (FLAG_stress_environments && !instr->HasEnvironment()) { | 735 if (FLAG_stress_environments && !instr->HasEnvironment()) { |
| 904 instr = AssignEnvironment(instr); | 736 instr = AssignEnvironment(instr); |
| 905 } | 737 } |
| 906 chunk_->AddInstruction(instr, current_block_); | 738 chunk_->AddInstruction(instr, current_block_); |
| 907 } | 739 } |
| 908 current_instruction_ = old_current; | 740 current_instruction_ = old_current; |
| 909 } | 741 } |
| 910 | 742 |
| 911 | 743 |
| 912 LInstruction* LChunkBuilder::DoGoto(HGoto* instr) { | 744 LInstruction* LChunkBuilder::AssignEnvironment(LInstruction* instr) { |
| 913 return new(zone()) LGoto(instr->FirstSuccessor()); | 745 HEnvironment* hydrogen_env = current_block_->last_environment(); |
| 746 int argument_index_accumulator = 0; |
| 747 ZoneList<HValue*> objects_to_materialize(0, zone()); |
| 748 instr->set_environment(CreateEnvironment(hydrogen_env, |
| 749 &argument_index_accumulator, |
| 750 &objects_to_materialize)); |
| 751 return instr; |
| 752 } |
| 753 |
| 754 |
| 755 LInstruction* LChunkBuilder::DoAbnormalExit(HAbnormalExit* instr) { |
| 756 // The control instruction marking the end of a block that completed |
| 757 // abruptly (e.g., threw an exception). There is nothing specific to do. |
| 758 return NULL; |
| 759 } |
| 760 |
| 761 |
| 762 LInstruction* LChunkBuilder::DoArithmeticD(Token::Value op, |
| 763 HArithmeticBinaryOperation* instr) { |
| 764 ASSERT(instr->representation().IsDouble()); |
| 765 ASSERT(instr->left()->representation().IsDouble()); |
| 766 ASSERT(instr->right()->representation().IsDouble()); |
| 767 |
| 768 if (op == Token::MOD) { |
| 769 LOperand* left = UseFixedDouble(instr->left(), d0); |
| 770 LOperand* right = UseFixedDouble(instr->right(), d1); |
| 771 LArithmeticD* result = new(zone()) LArithmeticD(Token::MOD, left, right); |
| 772 return MarkAsCall(DefineFixedDouble(result, d0), instr); |
| 773 } else { |
| 774 LOperand* left = UseRegisterAtStart(instr->left()); |
| 775 LOperand* right = UseRegisterAtStart(instr->right()); |
| 776 LArithmeticD* result = new(zone()) LArithmeticD(op, left, right); |
| 777 return DefineAsRegister(result); |
| 778 } |
| 779 } |
| 780 |
| 781 |
| 782 LInstruction* LChunkBuilder::DoArithmeticT(Token::Value op, |
| 783 HBinaryOperation* instr) { |
| 784 ASSERT((op == Token::ADD) || (op == Token::SUB) || (op == Token::MUL) || |
| 785 (op == Token::DIV) || (op == Token::MOD) || (op == Token::SHR) || |
| 786 (op == Token::SHL) || (op == Token::SAR) || (op == Token::ROR) || |
| 787 (op == Token::BIT_OR) || (op == Token::BIT_AND) || |
| 788 (op == Token::BIT_XOR)); |
| 789 HValue* left = instr->left(); |
| 790 HValue* right = instr->right(); |
| 791 |
| 792 // TODO(jbramley): Once we've implemented smi support for all arithmetic |
| 793 // operations, these assertions should check IsTagged(). |
| 794 ASSERT(instr->representation().IsSmiOrTagged()); |
| 795 ASSERT(left->representation().IsSmiOrTagged()); |
| 796 ASSERT(right->representation().IsSmiOrTagged()); |
| 797 |
| 798 LOperand* context = UseFixed(instr->context(), cp); |
| 799 LOperand* left_operand = UseFixed(left, x1); |
| 800 LOperand* right_operand = UseFixed(right, x0); |
| 801 LArithmeticT* result = |
| 802 new(zone()) LArithmeticT(op, context, left_operand, right_operand); |
| 803 return MarkAsCall(DefineFixed(result, x0), instr); |
| 804 } |
| 805 |
| 806 |
| 807 LInstruction* LChunkBuilder::DoBoundsCheckBaseIndexInformation( |
| 808 HBoundsCheckBaseIndexInformation* instr) { |
| 809 UNREACHABLE(); |
| 810 return NULL; |
| 811 } |
| 812 |
| 813 |
| 814 LInstruction* LChunkBuilder::DoAccessArgumentsAt(HAccessArgumentsAt* instr) { |
| 815 info()->MarkAsRequiresFrame(); |
| 816 LOperand* args = NULL; |
| 817 LOperand* length = NULL; |
| 818 LOperand* index = NULL; |
| 819 |
| 820 if (instr->length()->IsConstant() && instr->index()->IsConstant()) { |
| 821 args = UseRegisterAtStart(instr->arguments()); |
| 822 length = UseConstant(instr->length()); |
| 823 index = UseConstant(instr->index()); |
| 824 } else { |
| 825 args = UseRegister(instr->arguments()); |
| 826 length = UseRegisterAtStart(instr->length()); |
| 827 index = UseRegisterOrConstantAtStart(instr->index()); |
| 828 } |
| 829 |
| 830 return DefineAsRegister(new(zone()) LAccessArgumentsAt(args, length, index)); |
| 831 } |
| 832 |
| 833 |
| 834 LInstruction* LChunkBuilder::DoAdd(HAdd* instr) { |
| 835 if (instr->representation().IsSmiOrInteger32()) { |
| 836 ASSERT(instr->left()->representation().Equals(instr->representation())); |
| 837 ASSERT(instr->right()->representation().Equals(instr->representation())); |
| 838 LOperand* left = UseRegisterAtStart(instr->BetterLeftOperand()); |
| 839 LOperand* right = |
| 840 UseRegisterOrConstantAtStart(instr->BetterRightOperand()); |
| 841 LInstruction* result = instr->representation().IsSmi() ? |
| 842 DefineAsRegister(new(zone()) LAddS(left, right)) : |
| 843 DefineAsRegister(new(zone()) LAddI(left, right)); |
| 844 if (instr->CheckFlag(HValue::kCanOverflow)) { |
| 845 result = AssignEnvironment(result); |
| 846 } |
| 847 return result; |
| 848 } else if (instr->representation().IsExternal()) { |
| 849 ASSERT(instr->left()->representation().IsExternal()); |
| 850 ASSERT(instr->right()->representation().IsInteger32()); |
| 851 ASSERT(!instr->CheckFlag(HValue::kCanOverflow)); |
| 852 LOperand* left = UseRegisterAtStart(instr->left()); |
| 853 LOperand* right = UseRegisterOrConstantAtStart(instr->right()); |
| 854 return DefineAsRegister(new(zone()) LAddE(left, right)); |
| 855 } else if (instr->representation().IsDouble()) { |
| 856 return DoArithmeticD(Token::ADD, instr); |
| 857 } else { |
| 858 ASSERT(instr->representation().IsTagged()); |
| 859 return DoArithmeticT(Token::ADD, instr); |
| 860 } |
| 861 } |
| 862 |
| 863 |
| 864 LInstruction* LChunkBuilder::DoAllocate(HAllocate* instr) { |
| 865 info()->MarkAsDeferredCalling(); |
| 866 LOperand* context = UseAny(instr->context()); |
| 867 LOperand* size = UseRegisterOrConstant(instr->size()); |
| 868 LOperand* temp1 = TempRegister(); |
| 869 LOperand* temp2 = TempRegister(); |
| 870 LAllocate* result = new(zone()) LAllocate(context, size, temp1, temp2); |
| 871 return AssignPointerMap(DefineAsRegister(result)); |
| 872 } |
| 873 |
| 874 |
| 875 LInstruction* LChunkBuilder::DoApplyArguments(HApplyArguments* instr) { |
| 876 LOperand* function = UseFixed(instr->function(), x1); |
| 877 LOperand* receiver = UseFixed(instr->receiver(), x0); |
| 878 LOperand* length = UseFixed(instr->length(), x2); |
| 879 LOperand* elements = UseFixed(instr->elements(), x3); |
| 880 LApplyArguments* result = new(zone()) LApplyArguments(function, |
| 881 receiver, |
| 882 length, |
| 883 elements); |
| 884 return MarkAsCall(DefineFixed(result, x0), instr, CAN_DEOPTIMIZE_EAGERLY); |
| 885 } |
| 886 |
| 887 |
| 888 LInstruction* LChunkBuilder::DoArgumentsElements(HArgumentsElements* instr) { |
| 889 info()->MarkAsRequiresFrame(); |
| 890 LOperand* temp = instr->from_inlined() ? NULL : TempRegister(); |
| 891 return DefineAsRegister(new(zone()) LArgumentsElements(temp)); |
| 892 } |
| 893 |
| 894 |
| 895 LInstruction* LChunkBuilder::DoArgumentsLength(HArgumentsLength* instr) { |
| 896 info()->MarkAsRequiresFrame(); |
| 897 LOperand* value = UseRegisterAtStart(instr->value()); |
| 898 return DefineAsRegister(new(zone()) LArgumentsLength(value)); |
| 899 } |
| 900 |
| 901 |
| 902 LInstruction* LChunkBuilder::DoArgumentsObject(HArgumentsObject* instr) { |
| 903 // There are no real uses of the arguments object. |
| 904 // arguments.length and element access are supported directly on |
| 905 // stack arguments, and any real arguments object use causes a bailout. |
| 906 // So this value is never used. |
| 907 return NULL; |
| 908 } |
| 909 |
| 910 |
| 911 LInstruction* LChunkBuilder::DoBitwise(HBitwise* instr) { |
| 912 if (instr->representation().IsSmiOrInteger32()) { |
| 913 ASSERT(instr->left()->representation().Equals(instr->representation())); |
| 914 ASSERT(instr->right()->representation().Equals(instr->representation())); |
| 915 ASSERT(instr->CheckFlag(HValue::kTruncatingToInt32)); |
| 916 |
| 917 LOperand* left = UseRegisterAtStart(instr->BetterLeftOperand()); |
| 918 LOperand* right = |
| 919 UseRegisterOrConstantAtStart(instr->BetterRightOperand()); |
| 920 return instr->representation().IsSmi() ? |
| 921 DefineAsRegister(new(zone()) LBitS(left, right)) : |
| 922 DefineAsRegister(new(zone()) LBitI(left, right)); |
| 923 } else { |
| 924 return DoArithmeticT(instr->op(), instr); |
| 925 } |
| 926 } |
| 927 |
| 928 |
| 929 LInstruction* LChunkBuilder::DoBlockEntry(HBlockEntry* instr) { |
| 930 // V8 expects a label to be generated for each basic block. |
| 931 // This is used in some places like LAllocator::IsBlockBoundary |
| 932 // in lithium-allocator.cc |
| 933 return new(zone()) LLabel(instr->block()); |
| 934 } |
| 935 |
| 936 |
| 937 LInstruction* LChunkBuilder::DoBoundsCheck(HBoundsCheck* instr) { |
| 938 LOperand* value = UseRegisterOrConstantAtStart(instr->index()); |
| 939 LOperand* length = UseRegister(instr->length()); |
| 940 return AssignEnvironment(new(zone()) LBoundsCheck(value, length)); |
| 914 } | 941 } |
| 915 | 942 |
| 916 | 943 |
| 917 LInstruction* LChunkBuilder::DoBranch(HBranch* instr) { | 944 LInstruction* LChunkBuilder::DoBranch(HBranch* instr) { |
| 918 LInstruction* goto_instr = CheckElideControlInstruction(instr); | 945 LInstruction* goto_instr = CheckElideControlInstruction(instr); |
| 919 if (goto_instr != NULL) return goto_instr; | 946 if (goto_instr != NULL) return goto_instr; |
| 920 | 947 |
| 921 HValue* value = instr->value(); | 948 HValue* value = instr->value(); |
| 922 LBranch* result = new(zone()) LBranch(UseRegister(value)); | 949 Representation r = value->representation(); |
| 923 // Tagged values that are not known smis or booleans require a | |
| 924 // deoptimization environment. If the instruction is generic no | |
| 925 // environment is needed since all cases are handled. | |
| 926 Representation rep = value->representation(); | |
| 927 HType type = value->type(); | 950 HType type = value->type(); |
| 928 ToBooleanStub::Types expected = instr->expected_input_types(); | 951 |
| 929 if (rep.IsTagged() && !type.IsSmi() && !type.IsBoolean() && | 952 if (r.IsInteger32() || r.IsSmi() || r.IsDouble()) { |
| 930 !expected.IsGeneric()) { | 953 // These representations have simple checks that cannot deoptimize. |
| 931 return AssignEnvironment(result); | 954 return new(zone()) LBranch(UseRegister(value), NULL, NULL); |
| 932 } | 955 } else { |
| 933 return result; | 956 ASSERT(r.IsTagged()); |
| 934 } | 957 if (type.IsBoolean() || type.IsSmi() || type.IsJSArray() || |
| 935 | 958 type.IsHeapNumber()) { |
| 936 | 959 // These types have simple checks that cannot deoptimize. |
| 937 LInstruction* LChunkBuilder::DoDebugBreak(HDebugBreak* instr) { | 960 return new(zone()) LBranch(UseRegister(value), NULL, NULL); |
| 938 return new(zone()) LDebugBreak(); | 961 } |
| 939 } | 962 |
| 940 | 963 if (type.IsString()) { |
| 941 | 964 // This type cannot deoptimize, but needs a scratch register. |
| 942 LInstruction* LChunkBuilder::DoCompareMap(HCompareMap* instr) { | 965 return new(zone()) LBranch(UseRegister(value), TempRegister(), NULL); |
| 943 ASSERT(instr->value()->representation().IsTagged()); | 966 } |
| 944 LOperand* value = UseRegisterAtStart(instr->value()); | 967 |
| 945 LOperand* temp = TempRegister(); | 968 ToBooleanStub::Types expected = instr->expected_input_types(); |
| 946 return new(zone()) LCmpMapAndBranch(value, temp); | 969 bool needs_temps = expected.NeedsMap() || expected.IsEmpty(); |
| 947 } | 970 LOperand* temp1 = needs_temps ? TempRegister() : NULL; |
| 948 | 971 LOperand* temp2 = needs_temps ? TempRegister() : NULL; |
| 949 | 972 |
| 950 LInstruction* LChunkBuilder::DoArgumentsLength(HArgumentsLength* instr) { | 973 if (expected.IsGeneric() || expected.IsEmpty()) { |
| 951 info()->MarkAsRequiresFrame(); | 974 // The generic case cannot deoptimize because it already supports every |
| 952 LOperand* value = UseRegister(instr->value()); | 975 // possible input type. |
| 953 return DefineAsRegister(new(zone()) LArgumentsLength(value)); | 976 ASSERT(needs_temps); |
| 954 } | 977 return new(zone()) LBranch(UseRegister(value), temp1, temp2); |
| 955 | 978 } else { |
| 956 | 979 return AssignEnvironment( |
| 957 LInstruction* LChunkBuilder::DoArgumentsElements(HArgumentsElements* elems) { | 980 new(zone()) LBranch(UseRegister(value), temp1, temp2)); |
| 958 info()->MarkAsRequiresFrame(); | 981 } |
| 959 return DefineAsRegister(new(zone()) LArgumentsElements); | 982 } |
| 960 } | |
| 961 | |
| 962 | |
| 963 LInstruction* LChunkBuilder::DoInstanceOf(HInstanceOf* instr) { | |
| 964 LOperand* context = UseFixed(instr->context(), cp); | |
| 965 LInstanceOf* result = | |
| 966 new(zone()) LInstanceOf(context, UseFixed(instr->left(), r0), | |
| 967 UseFixed(instr->right(), r1)); | |
| 968 return MarkAsCall(DefineFixed(result, r0), instr); | |
| 969 } | |
| 970 | |
| 971 | |
| 972 LInstruction* LChunkBuilder::DoInstanceOfKnownGlobal( | |
| 973 HInstanceOfKnownGlobal* instr) { | |
| 974 LInstanceOfKnownGlobal* result = | |
| 975 new(zone()) LInstanceOfKnownGlobal( | |
| 976 UseFixed(instr->context(), cp), | |
| 977 UseFixed(instr->left(), r0), | |
| 978 FixedTemp(r4)); | |
| 979 return MarkAsCall(DefineFixed(result, r0), instr); | |
| 980 } | |
| 981 | |
| 982 | |
| 983 LInstruction* LChunkBuilder::DoWrapReceiver(HWrapReceiver* instr) { | |
| 984 LOperand* receiver = UseRegisterAtStart(instr->receiver()); | |
| 985 LOperand* function = UseRegisterAtStart(instr->function()); | |
| 986 LWrapReceiver* result = new(zone()) LWrapReceiver(receiver, function); | |
| 987 return AssignEnvironment(DefineAsRegister(result)); | |
| 988 } | |
| 989 | |
| 990 | |
| 991 LInstruction* LChunkBuilder::DoApplyArguments(HApplyArguments* instr) { | |
| 992 LOperand* function = UseFixed(instr->function(), r1); | |
| 993 LOperand* receiver = UseFixed(instr->receiver(), r0); | |
| 994 LOperand* length = UseFixed(instr->length(), r2); | |
| 995 LOperand* elements = UseFixed(instr->elements(), r3); | |
| 996 LApplyArguments* result = new(zone()) LApplyArguments(function, | |
| 997 receiver, | |
| 998 length, | |
| 999 elements); | |
| 1000 return MarkAsCall(DefineFixed(result, r0), instr, CAN_DEOPTIMIZE_EAGERLY); | |
| 1001 } | |
| 1002 | |
| 1003 | |
| 1004 LInstruction* LChunkBuilder::DoPushArgument(HPushArgument* instr) { | |
| 1005 LOperand* argument = Use(instr->argument()); | |
| 1006 return new(zone()) LPushArgument(argument); | |
| 1007 } | |
| 1008 | |
| 1009 | |
| 1010 LInstruction* LChunkBuilder::DoStoreCodeEntry( | |
| 1011 HStoreCodeEntry* store_code_entry) { | |
| 1012 LOperand* function = UseRegister(store_code_entry->function()); | |
| 1013 LOperand* code_object = UseTempRegister(store_code_entry->code_object()); | |
| 1014 return new(zone()) LStoreCodeEntry(function, code_object); | |
| 1015 } | |
| 1016 | |
| 1017 | |
| 1018 LInstruction* LChunkBuilder::DoInnerAllocatedObject( | |
| 1019 HInnerAllocatedObject* instr) { | |
| 1020 LOperand* base_object = UseRegisterAtStart(instr->base_object()); | |
| 1021 LOperand* offset = UseRegisterOrConstantAtStart(instr->offset()); | |
| 1022 return DefineAsRegister( | |
| 1023 new(zone()) LInnerAllocatedObject(base_object, offset)); | |
| 1024 } | |
| 1025 | |
| 1026 | |
| 1027 LInstruction* LChunkBuilder::DoThisFunction(HThisFunction* instr) { | |
| 1028 return instr->HasNoUses() | |
| 1029 ? NULL | |
| 1030 : DefineAsRegister(new(zone()) LThisFunction); | |
| 1031 } | |
| 1032 | |
| 1033 | |
| 1034 LInstruction* LChunkBuilder::DoContext(HContext* instr) { | |
| 1035 if (instr->HasNoUses()) return NULL; | |
| 1036 | |
| 1037 if (info()->IsStub()) { | |
| 1038 return DefineFixed(new(zone()) LContext, cp); | |
| 1039 } | |
| 1040 | |
| 1041 return DefineAsRegister(new(zone()) LContext); | |
| 1042 } | |
| 1043 | |
| 1044 | |
| 1045 LInstruction* LChunkBuilder::DoOuterContext(HOuterContext* instr) { | |
| 1046 LOperand* context = UseRegisterAtStart(instr->value()); | |
| 1047 return DefineAsRegister(new(zone()) LOuterContext(context)); | |
| 1048 } | |
| 1049 | |
| 1050 | |
| 1051 LInstruction* LChunkBuilder::DoDeclareGlobals(HDeclareGlobals* instr) { | |
| 1052 LOperand* context = UseFixed(instr->context(), cp); | |
| 1053 return MarkAsCall(new(zone()) LDeclareGlobals(context), instr); | |
| 1054 } | |
| 1055 | |
| 1056 | |
| 1057 LInstruction* LChunkBuilder::DoGlobalObject(HGlobalObject* instr) { | |
| 1058 LOperand* context = UseRegisterAtStart(instr->value()); | |
| 1059 return DefineAsRegister(new(zone()) LGlobalObject(context)); | |
| 1060 } | |
| 1061 | |
| 1062 | |
| 1063 LInstruction* LChunkBuilder::DoGlobalReceiver(HGlobalReceiver* instr) { | |
| 1064 LOperand* global_object = UseRegisterAtStart(instr->value()); | |
| 1065 return DefineAsRegister(new(zone()) LGlobalReceiver(global_object)); | |
| 1066 } | 983 } |
| 1067 | 984 |
| 1068 | 985 |
| 1069 LInstruction* LChunkBuilder::DoCallJSFunction( | 986 LInstruction* LChunkBuilder::DoCallJSFunction( |
| 1070 HCallJSFunction* instr) { | 987 HCallJSFunction* instr) { |
| 1071 LOperand* function = UseFixed(instr->function(), r1); | 988 LOperand* function = UseFixed(instr->function(), x1); |
| 1072 | 989 |
| 1073 LCallJSFunction* result = new(zone()) LCallJSFunction(function); | 990 LCallJSFunction* result = new(zone()) LCallJSFunction(function); |
| 1074 | 991 |
| 1075 return MarkAsCall(DefineFixed(result, r0), instr); | 992 return MarkAsCall(DefineFixed(result, x0), instr); |
| 1076 } | 993 } |
| 1077 | 994 |
| 1078 | 995 |
| 1079 LInstruction* LChunkBuilder::DoCallWithDescriptor( | 996 LInstruction* LChunkBuilder::DoCallWithDescriptor( |
| 1080 HCallWithDescriptor* instr) { | 997 HCallWithDescriptor* instr) { |
| 1081 const CallInterfaceDescriptor* descriptor = instr->descriptor(); | 998 const CallInterfaceDescriptor* descriptor = instr->descriptor(); |
| 1082 | 999 |
| 1083 LOperand* target = UseRegisterOrConstantAtStart(instr->target()); | 1000 LOperand* target = UseRegisterOrConstantAtStart(instr->target()); |
| 1084 ZoneList<LOperand*> ops(instr->OperandCount(), zone()); | 1001 ZoneList<LOperand*> ops(instr->OperandCount(), zone()); |
| 1085 ops.Add(target, zone()); | 1002 ops.Add(target, zone()); |
| 1086 for (int i = 1; i < instr->OperandCount(); i++) { | 1003 for (int i = 1; i < instr->OperandCount(); i++) { |
| 1087 LOperand* op = UseFixed(instr->OperandAt(i), | 1004 LOperand* op = UseFixed(instr->OperandAt(i), |
| 1088 descriptor->GetParameterRegister(i - 1)); | 1005 descriptor->GetParameterRegister(i - 1)); |
| 1089 ops.Add(op, zone()); | 1006 ops.Add(op, zone()); |
| 1090 } | 1007 } |
| 1091 | 1008 |
| 1092 LCallWithDescriptor* result = new(zone()) LCallWithDescriptor( | 1009 LCallWithDescriptor* result = new(zone()) LCallWithDescriptor(descriptor, |
| 1093 descriptor, ops, zone()); | 1010 ops, |
| 1094 return MarkAsCall(DefineFixed(result, r0), instr); | 1011 zone()); |
| 1095 } | 1012 return MarkAsCall(DefineFixed(result, x0), instr); |
| 1096 | 1013 } |
| 1097 | 1014 |
| 1098 LInstruction* LChunkBuilder::DoInvokeFunction(HInvokeFunction* instr) { | 1015 |
| 1099 LOperand* context = UseFixed(instr->context(), cp); | 1016 LInstruction* LChunkBuilder::DoCallFunction(HCallFunction* instr) { |
| 1100 LOperand* function = UseFixed(instr->function(), r1); | 1017 LOperand* context = UseFixed(instr->context(), cp); |
| 1101 LInvokeFunction* result = new(zone()) LInvokeFunction(context, function); | 1018 LOperand* function = UseFixed(instr->function(), x1); |
| 1102 return MarkAsCall(DefineFixed(result, r0), instr, CANNOT_DEOPTIMIZE_EAGERLY); | 1019 LCallFunction* call = new(zone()) LCallFunction(context, function); |
| 1103 } | 1020 return MarkAsCall(DefineFixed(call, x0), instr); |
| 1104 | |
| 1105 | |
| 1106 LInstruction* LChunkBuilder::DoUnaryMathOperation(HUnaryMathOperation* instr) { | |
| 1107 switch (instr->op()) { | |
| 1108 case kMathFloor: return DoMathFloor(instr); | |
| 1109 case kMathRound: return DoMathRound(instr); | |
| 1110 case kMathAbs: return DoMathAbs(instr); | |
| 1111 case kMathLog: return DoMathLog(instr); | |
| 1112 case kMathExp: return DoMathExp(instr); | |
| 1113 case kMathSqrt: return DoMathSqrt(instr); | |
| 1114 case kMathPowHalf: return DoMathPowHalf(instr); | |
| 1115 default: | |
| 1116 UNREACHABLE(); | |
| 1117 return NULL; | |
| 1118 } | |
| 1119 } | |
| 1120 | |
| 1121 | |
| 1122 LInstruction* LChunkBuilder::DoMathFloor(HUnaryMathOperation* instr) { | |
| 1123 LOperand* input = UseRegister(instr->value()); | |
| 1124 LMathFloor* result = new(zone()) LMathFloor(input); | |
| 1125 return AssignEnvironment(AssignPointerMap(DefineAsRegister(result))); | |
| 1126 } | |
| 1127 | |
| 1128 | |
| 1129 LInstruction* LChunkBuilder::DoMathRound(HUnaryMathOperation* instr) { | |
| 1130 LOperand* input = UseRegister(instr->value()); | |
| 1131 LOperand* temp = FixedTemp(d3); | |
| 1132 LMathRound* result = new(zone()) LMathRound(input, temp); | |
| 1133 return AssignEnvironment(DefineAsRegister(result)); | |
| 1134 } | |
| 1135 | |
| 1136 | |
| 1137 LInstruction* LChunkBuilder::DoMathAbs(HUnaryMathOperation* instr) { | |
| 1138 Representation r = instr->value()->representation(); | |
| 1139 LOperand* context = (r.IsDouble() || r.IsSmiOrInteger32()) | |
| 1140 ? NULL | |
| 1141 : UseFixed(instr->context(), cp); | |
| 1142 LOperand* input = UseRegister(instr->value()); | |
| 1143 LMathAbs* result = new(zone()) LMathAbs(context, input); | |
| 1144 return AssignEnvironment(AssignPointerMap(DefineAsRegister(result))); | |
| 1145 } | |
| 1146 | |
| 1147 | |
| 1148 LInstruction* LChunkBuilder::DoMathLog(HUnaryMathOperation* instr) { | |
| 1149 ASSERT(instr->representation().IsDouble()); | |
| 1150 ASSERT(instr->value()->representation().IsDouble()); | |
| 1151 LOperand* input = UseFixedDouble(instr->value(), d0); | |
| 1152 return MarkAsCall(DefineFixedDouble(new(zone()) LMathLog(input), d0), instr); | |
| 1153 } | |
| 1154 | |
| 1155 | |
| 1156 LInstruction* LChunkBuilder::DoMathExp(HUnaryMathOperation* instr) { | |
| 1157 ASSERT(instr->representation().IsDouble()); | |
| 1158 ASSERT(instr->value()->representation().IsDouble()); | |
| 1159 LOperand* input = UseRegister(instr->value()); | |
| 1160 LOperand* temp1 = TempRegister(); | |
| 1161 LOperand* temp2 = TempRegister(); | |
| 1162 LOperand* double_temp = FixedTemp(d3); // Chosen by fair dice roll. | |
| 1163 LMathExp* result = new(zone()) LMathExp(input, double_temp, temp1, temp2); | |
| 1164 return DefineAsRegister(result); | |
| 1165 } | |
| 1166 | |
| 1167 | |
| 1168 LInstruction* LChunkBuilder::DoMathSqrt(HUnaryMathOperation* instr) { | |
| 1169 LOperand* input = UseRegisterAtStart(instr->value()); | |
| 1170 LMathSqrt* result = new(zone()) LMathSqrt(input); | |
| 1171 return DefineAsRegister(result); | |
| 1172 } | |
| 1173 | |
| 1174 | |
| 1175 LInstruction* LChunkBuilder::DoMathPowHalf(HUnaryMathOperation* instr) { | |
| 1176 LOperand* input = UseRegisterAtStart(instr->value()); | |
| 1177 LMathPowHalf* result = new(zone()) LMathPowHalf(input); | |
| 1178 return DefineAsRegister(result); | |
| 1179 } | 1021 } |
| 1180 | 1022 |
| 1181 | 1023 |
| 1182 LInstruction* LChunkBuilder::DoCallNew(HCallNew* instr) { | 1024 LInstruction* LChunkBuilder::DoCallNew(HCallNew* instr) { |
| 1183 LOperand* context = UseFixed(instr->context(), cp); | 1025 LOperand* context = UseFixed(instr->context(), cp); |
| 1184 LOperand* constructor = UseFixed(instr->constructor(), r1); | 1026 // The call to CallConstructStub will expect the constructor to be in x1. |
| 1027 LOperand* constructor = UseFixed(instr->constructor(), x1); |
| 1185 LCallNew* result = new(zone()) LCallNew(context, constructor); | 1028 LCallNew* result = new(zone()) LCallNew(context, constructor); |
| 1186 return MarkAsCall(DefineFixed(result, r0), instr); | 1029 return MarkAsCall(DefineFixed(result, x0), instr); |
| 1187 } | 1030 } |
| 1188 | 1031 |
| 1189 | 1032 |
| 1190 LInstruction* LChunkBuilder::DoCallNewArray(HCallNewArray* instr) { | 1033 LInstruction* LChunkBuilder::DoCallNewArray(HCallNewArray* instr) { |
| 1191 LOperand* context = UseFixed(instr->context(), cp); | 1034 LOperand* context = UseFixed(instr->context(), cp); |
| 1192 LOperand* constructor = UseFixed(instr->constructor(), r1); | 1035 // The call to ArrayConstructCode will expect the constructor to be in x1. |
| 1036 LOperand* constructor = UseFixed(instr->constructor(), x1); |
| 1193 LCallNewArray* result = new(zone()) LCallNewArray(context, constructor); | 1037 LCallNewArray* result = new(zone()) LCallNewArray(context, constructor); |
| 1194 return MarkAsCall(DefineFixed(result, r0), instr); | 1038 return MarkAsCall(DefineFixed(result, x0), instr); |
| 1195 } | |
| 1196 | |
| 1197 | |
| 1198 LInstruction* LChunkBuilder::DoCallFunction(HCallFunction* instr) { | |
| 1199 LOperand* context = UseFixed(instr->context(), cp); | |
| 1200 LOperand* function = UseFixed(instr->function(), r1); | |
| 1201 LCallFunction* call = new(zone()) LCallFunction(context, function); | |
| 1202 LInstruction* result = DefineFixed(call, r0); | |
| 1203 if (instr->IsTailCall()) return result; | |
| 1204 return MarkAsCall(result, instr); | |
| 1205 } | 1039 } |
| 1206 | 1040 |
| 1207 | 1041 |
| 1208 LInstruction* LChunkBuilder::DoCallRuntime(HCallRuntime* instr) { | 1042 LInstruction* LChunkBuilder::DoCallRuntime(HCallRuntime* instr) { |
| 1209 LOperand* context = UseFixed(instr->context(), cp); | 1043 LOperand* context = UseFixed(instr->context(), cp); |
| 1210 return MarkAsCall(DefineFixed(new(zone()) LCallRuntime(context), r0), instr); | 1044 return MarkAsCall(DefineFixed(new(zone()) LCallRuntime(context), x0), instr); |
| 1211 } | 1045 } |
| 1212 | 1046 |
| 1213 | 1047 |
| 1214 LInstruction* LChunkBuilder::DoRor(HRor* instr) { | 1048 LInstruction* LChunkBuilder::DoCallStub(HCallStub* instr) { |
| 1215 return DoShift(Token::ROR, instr); | 1049 LOperand* context = UseFixed(instr->context(), cp); |
| 1216 } | 1050 return MarkAsCall(DefineFixed(new(zone()) LCallStub(context), x0), instr); |
| 1217 | 1051 } |
| 1218 | 1052 |
| 1219 LInstruction* LChunkBuilder::DoShr(HShr* instr) { | 1053 |
| 1220 return DoShift(Token::SHR, instr); | 1054 LInstruction* LChunkBuilder::DoCapturedObject(HCapturedObject* instr) { |
| 1221 } | 1055 instr->ReplayEnvironment(current_block_->last_environment()); |
| 1222 | 1056 |
| 1223 | 1057 // There are no real uses of a captured object. |
| 1224 LInstruction* LChunkBuilder::DoSar(HSar* instr) { | 1058 return NULL; |
| 1225 return DoShift(Token::SAR, instr); | 1059 } |
| 1226 } | 1060 |
| 1227 | 1061 |
| 1228 | 1062 LInstruction* LChunkBuilder::DoChange(HChange* instr) { |
| 1229 LInstruction* LChunkBuilder::DoShl(HShl* instr) { | 1063 Representation from = instr->from(); |
| 1230 return DoShift(Token::SHL, instr); | 1064 Representation to = instr->to(); |
| 1231 } | 1065 |
| 1232 | 1066 if (from.IsSmi()) { |
| 1233 | 1067 if (to.IsTagged()) { |
| 1234 LInstruction* LChunkBuilder::DoBitwise(HBitwise* instr) { | 1068 LOperand* value = UseRegister(instr->value()); |
| 1235 if (instr->representation().IsSmiOrInteger32()) { | 1069 return DefineSameAsFirst(new(zone()) LDummyUse(value)); |
| 1236 ASSERT(instr->left()->representation().Equals(instr->representation())); | |
| 1237 ASSERT(instr->right()->representation().Equals(instr->representation())); | |
| 1238 ASSERT(instr->CheckFlag(HValue::kTruncatingToInt32)); | |
| 1239 | |
| 1240 LOperand* left = UseRegisterAtStart(instr->BetterLeftOperand()); | |
| 1241 LOperand* right = UseOrConstantAtStart(instr->BetterRightOperand()); | |
| 1242 return DefineAsRegister(new(zone()) LBitI(left, right)); | |
| 1243 } else { | |
| 1244 return DoArithmeticT(instr->op(), instr); | |
| 1245 } | |
| 1246 } | |
| 1247 | |
| 1248 | |
| 1249 LInstruction* LChunkBuilder::DoDiv(HDiv* instr) { | |
| 1250 if (instr->representation().IsSmiOrInteger32()) { | |
| 1251 ASSERT(instr->left()->representation().Equals(instr->representation())); | |
| 1252 ASSERT(instr->right()->representation().Equals(instr->representation())); | |
| 1253 if (instr->HasPowerOf2Divisor()) { | |
| 1254 ASSERT(!instr->CheckFlag(HValue::kCanBeDivByZero)); | |
| 1255 LOperand* value = UseRegisterAtStart(instr->left()); | |
| 1256 LDivI* div = new(zone()) LDivI(value, UseConstant(instr->right()), NULL); | |
| 1257 return AssignEnvironment(DefineAsRegister(div)); | |
| 1258 } | 1070 } |
| 1259 LOperand* dividend = UseRegister(instr->left()); | 1071 from = Representation::Tagged(); |
| 1260 LOperand* divisor = UseRegister(instr->right()); | 1072 } |
| 1261 LOperand* temp = CpuFeatures::IsSupported(SUDIV) ? NULL : FixedTemp(d4); | 1073 |
| 1262 LDivI* div = new(zone()) LDivI(dividend, divisor, temp); | 1074 if (from.IsTagged()) { |
| 1263 return AssignEnvironment(DefineAsRegister(div)); | 1075 if (to.IsDouble()) { |
| 1264 } else if (instr->representation().IsDouble()) { | 1076 LOperand* value = UseRegister(instr->value()); |
| 1265 return DoArithmeticD(Token::DIV, instr); | 1077 LOperand* temp = TempRegister(); |
| 1266 } else { | 1078 LNumberUntagD* res = new(zone()) LNumberUntagD(value, temp); |
| 1267 return DoArithmeticT(Token::DIV, instr); | 1079 return AssignEnvironment(DefineAsRegister(res)); |
| 1268 } | 1080 } else if (to.IsSmi()) { |
| 1269 } | 1081 LOperand* value = UseRegister(instr->value()); |
| 1270 | 1082 if (instr->value()->type().IsSmi()) { |
| 1271 | 1083 return DefineSameAsFirst(new(zone()) LDummyUse(value)); |
| 1272 bool LChunkBuilder::HasMagicNumberForDivisor(int32_t divisor) { | 1084 } |
| 1273 uint32_t divisor_abs = abs(divisor); | 1085 return AssignEnvironment(DefineSameAsFirst(new(zone()) LCheckSmi(value))); |
| 1274 // Dividing by 0, 1, and powers of 2 is easy. | 1086 } else { |
| 1275 // Note that IsPowerOf2(0) returns true; | 1087 ASSERT(to.IsInteger32()); |
| 1276 ASSERT(IsPowerOf2(0) == true); | 1088 LInstruction* res = NULL; |
| 1277 if (IsPowerOf2(divisor_abs)) return true; | 1089 |
| 1278 | 1090 if (instr->value()->type().IsSmi() || |
| 1279 // We have magic numbers for a few specific divisors. | 1091 instr->value()->representation().IsSmi()) { |
| 1280 // Details and proofs can be found in: | 1092 LOperand* value = UseRegisterAtStart(instr->value()); |
| 1281 // - Hacker's Delight, Henry S. Warren, Jr. | 1093 res = DefineAsRegister(new(zone()) LSmiUntag(value, false)); |
| 1282 // - The PowerPC Compiler Writer’s Guide | 1094 } else { |
| 1283 // and probably many others. | 1095 LOperand* value = UseRegister(instr->value()); |
| 1284 // | 1096 LOperand* temp1 = TempRegister(); |
| 1285 // We handle | 1097 LOperand* temp2 = |
| 1286 // <divisor with magic numbers> * <power of 2> | 1098 instr->CanTruncateToInt32() ? TempRegister() : FixedTemp(d24); |
| 1287 // but not | 1099 res = DefineAsRegister(new(zone()) LTaggedToI(value, temp1, temp2)); |
| 1288 // <divisor with magic numbers> * <other divisor with magic numbers> | 1100 res = AssignEnvironment(res); |
| 1289 int32_t power_of_2_factor = | 1101 } |
| 1290 CompilerIntrinsics::CountTrailingZeros(divisor_abs); | 1102 |
| 1291 DivMagicNumbers magic_numbers = | 1103 return res; |
| 1292 DivMagicNumberFor(divisor_abs >> power_of_2_factor); | |
| 1293 if (magic_numbers.M != InvalidDivMagicNumber.M) return true; | |
| 1294 | |
| 1295 return false; | |
| 1296 } | |
| 1297 | |
| 1298 | |
| 1299 HValue* LChunkBuilder::SimplifiedDivisorForMathFloorOfDiv(HValue* divisor) { | |
| 1300 if (CpuFeatures::IsSupported(SUDIV)) { | |
| 1301 // A value with an integer representation does not need to be transformed. | |
| 1302 if (divisor->representation().IsInteger32()) { | |
| 1303 return divisor; | |
| 1304 // A change from an integer32 can be replaced by the integer32 value. | |
| 1305 } else if (divisor->IsChange() && | |
| 1306 HChange::cast(divisor)->from().IsInteger32()) { | |
| 1307 return HChange::cast(divisor)->value(); | |
| 1308 } | 1104 } |
| 1309 } | 1105 } else if (from.IsDouble()) { |
| 1310 | 1106 if (to.IsTagged()) { |
| 1311 if (divisor->IsConstant() && HConstant::cast(divisor)->HasInteger32Value()) { | 1107 info()->MarkAsDeferredCalling(); |
| 1312 HConstant* constant_val = HConstant::cast(divisor); | 1108 LOperand* value = UseRegister(instr->value()); |
| 1313 int32_t int32_val = constant_val->Integer32Value(); | 1109 LOperand* temp1 = TempRegister(); |
| 1314 if (LChunkBuilder::HasMagicNumberForDivisor(int32_val) || | 1110 LOperand* temp2 = TempRegister(); |
| 1315 CpuFeatures::IsSupported(SUDIV)) { | 1111 |
| 1316 return constant_val->CopyToRepresentation(Representation::Integer32(), | 1112 LNumberTagD* result = new(zone()) LNumberTagD(value, temp1, temp2); |
| 1317 divisor->block()->zone()); | 1113 return AssignPointerMap(DefineAsRegister(result)); |
| 1114 } else { |
| 1115 ASSERT(to.IsSmi() || to.IsInteger32()); |
| 1116 LOperand* value = UseRegister(instr->value()); |
| 1117 |
| 1118 if (instr->CanTruncateToInt32()) { |
| 1119 LTruncateDoubleToIntOrSmi* result = |
| 1120 new(zone()) LTruncateDoubleToIntOrSmi(value); |
| 1121 return DefineAsRegister(result); |
| 1122 } else { |
| 1123 LDoubleToIntOrSmi* result = new(zone()) LDoubleToIntOrSmi(value); |
| 1124 return AssignEnvironment(DefineAsRegister(result)); |
| 1125 } |
| 1318 } | 1126 } |
| 1319 } | 1127 } else if (from.IsInteger32()) { |
| 1320 | 1128 info()->MarkAsDeferredCalling(); |
| 1321 return NULL; | 1129 if (to.IsTagged()) { |
| 1322 } | 1130 if (instr->value()->CheckFlag(HInstruction::kUint32)) { |
| 1323 | 1131 LOperand* value = UseRegister(instr->value()); |
| 1324 | 1132 LNumberTagU* result = new(zone()) LNumberTagU(value, |
| 1325 LInstruction* LChunkBuilder::DoMathFloorOfDiv(HMathFloorOfDiv* instr) { | 1133 TempRegister(), |
| 1326 HValue* right = instr->right(); | 1134 TempRegister()); |
| 1327 LOperand* dividend = UseRegister(instr->left()); | 1135 return AssignEnvironment(AssignPointerMap(DefineAsRegister(result))); |
| 1328 LOperand* divisor = CpuFeatures::IsSupported(SUDIV) | |
| 1329 ? UseRegister(right) | |
| 1330 : UseOrConstant(right); | |
| 1331 LOperand* remainder = TempRegister(); | |
| 1332 ASSERT(CpuFeatures::IsSupported(SUDIV) || | |
| 1333 (right->IsConstant() && | |
| 1334 HConstant::cast(right)->HasInteger32Value() && | |
| 1335 HasMagicNumberForDivisor(HConstant::cast(right)->Integer32Value()))); | |
| 1336 return AssignEnvironment(DefineAsRegister( | |
| 1337 new(zone()) LMathFloorOfDiv(dividend, divisor, remainder))); | |
| 1338 } | |
| 1339 | |
| 1340 | |
| 1341 LInstruction* LChunkBuilder::DoMod(HMod* instr) { | |
| 1342 HValue* left = instr->left(); | |
| 1343 HValue* right = instr->right(); | |
| 1344 if (instr->representation().IsSmiOrInteger32()) { | |
| 1345 ASSERT(instr->left()->representation().Equals(instr->representation())); | |
| 1346 ASSERT(instr->right()->representation().Equals(instr->representation())); | |
| 1347 if (instr->HasPowerOf2Divisor()) { | |
| 1348 ASSERT(!right->CanBeZero()); | |
| 1349 LModI* mod = new(zone()) LModI(UseRegisterAtStart(left), | |
| 1350 UseConstant(right)); | |
| 1351 LInstruction* result = DefineAsRegister(mod); | |
| 1352 return (left->CanBeNegative() && | |
| 1353 instr->CheckFlag(HValue::kBailoutOnMinusZero)) | |
| 1354 ? AssignEnvironment(result) | |
| 1355 : result; | |
| 1356 } else if (CpuFeatures::IsSupported(SUDIV)) { | |
| 1357 LModI* mod = new(zone()) LModI(UseRegister(left), | |
| 1358 UseRegister(right)); | |
| 1359 LInstruction* result = DefineAsRegister(mod); | |
| 1360 return (right->CanBeZero() || | |
| 1361 (left->RangeCanInclude(kMinInt) && | |
| 1362 right->RangeCanInclude(-1) && | |
| 1363 instr->CheckFlag(HValue::kBailoutOnMinusZero)) || | |
| 1364 (left->CanBeNegative() && | |
| 1365 instr->CanBeZero() && | |
| 1366 instr->CheckFlag(HValue::kBailoutOnMinusZero))) | |
| 1367 ? AssignEnvironment(result) | |
| 1368 : result; | |
| 1369 } else { | |
| 1370 LModI* mod = new(zone()) LModI(UseRegister(left), | |
| 1371 UseRegister(right), | |
| 1372 FixedTemp(d10), | |
| 1373 FixedTemp(d11)); | |
| 1374 LInstruction* result = DefineAsRegister(mod); | |
| 1375 return (right->CanBeZero() || | |
| 1376 (left->CanBeNegative() && | |
| 1377 instr->CanBeZero() && | |
| 1378 instr->CheckFlag(HValue::kBailoutOnMinusZero))) | |
| 1379 ? AssignEnvironment(result) | |
| 1380 : result; | |
| 1381 } | |
| 1382 } else if (instr->representation().IsDouble()) { | |
| 1383 return DoArithmeticD(Token::MOD, instr); | |
| 1384 } else { | |
| 1385 return DoArithmeticT(Token::MOD, instr); | |
| 1386 } | |
| 1387 } | |
| 1388 | |
| 1389 | |
| 1390 LInstruction* LChunkBuilder::DoMul(HMul* instr) { | |
| 1391 if (instr->representation().IsSmiOrInteger32()) { | |
| 1392 ASSERT(instr->left()->representation().Equals(instr->representation())); | |
| 1393 ASSERT(instr->right()->representation().Equals(instr->representation())); | |
| 1394 HValue* left = instr->BetterLeftOperand(); | |
| 1395 HValue* right = instr->BetterRightOperand(); | |
| 1396 LOperand* left_op; | |
| 1397 LOperand* right_op; | |
| 1398 bool can_overflow = instr->CheckFlag(HValue::kCanOverflow); | |
| 1399 bool bailout_on_minus_zero = instr->CheckFlag(HValue::kBailoutOnMinusZero); | |
| 1400 | |
| 1401 if (right->IsConstant()) { | |
| 1402 HConstant* constant = HConstant::cast(right); | |
| 1403 int32_t constant_value = constant->Integer32Value(); | |
| 1404 // Constants -1, 0 and 1 can be optimized if the result can overflow. | |
| 1405 // For other constants, it can be optimized only without overflow. | |
| 1406 if (!can_overflow || ((constant_value >= -1) && (constant_value <= 1))) { | |
| 1407 left_op = UseRegisterAtStart(left); | |
| 1408 right_op = UseConstant(right); | |
| 1409 } else { | 1136 } else { |
| 1410 if (bailout_on_minus_zero) { | 1137 STATIC_ASSERT((kMinInt == Smi::kMinValue) && |
| 1411 left_op = UseRegister(left); | 1138 (kMaxInt == Smi::kMaxValue)); |
| 1412 } else { | 1139 LOperand* value = UseRegisterAtStart(instr->value()); |
| 1413 left_op = UseRegisterAtStart(left); | 1140 return DefineAsRegister(new(zone()) LSmiTag(value)); |
| 1414 } | 1141 } |
| 1415 right_op = UseRegister(right); | 1142 } else if (to.IsSmi()) { |
| 1143 LOperand* value = UseRegisterAtStart(instr->value()); |
| 1144 if (instr->value()->CheckFlag(HInstruction::kUint32)) { |
| 1145 LUint32ToSmi* result = new(zone()) LUint32ToSmi(value); |
| 1146 return AssignEnvironment(DefineAsRegister(result)); |
| 1147 } else { |
| 1148 // This cannot deoptimize because an A64 smi can represent any int32. |
| 1149 return DefineAsRegister(new(zone()) LInteger32ToSmi(value)); |
| 1416 } | 1150 } |
| 1417 } else { | 1151 } else { |
| 1418 if (bailout_on_minus_zero) { | 1152 ASSERT(to.IsDouble()); |
| 1419 left_op = UseRegister(left); | 1153 if (instr->value()->CheckFlag(HInstruction::kUint32)) { |
| 1154 return DefineAsRegister( |
| 1155 new(zone()) LUint32ToDouble(UseRegisterAtStart(instr->value()))); |
| 1420 } else { | 1156 } else { |
| 1421 left_op = UseRegisterAtStart(left); | 1157 return DefineAsRegister( |
| 1422 } | 1158 new(zone()) LInteger32ToDouble(UseRegisterAtStart(instr->value()))); |
| 1423 right_op = UseRegister(right); | |
| 1424 } | |
| 1425 LMulI* mul = new(zone()) LMulI(left_op, right_op); | |
| 1426 if (can_overflow || bailout_on_minus_zero) { | |
| 1427 AssignEnvironment(mul); | |
| 1428 } | |
| 1429 return DefineAsRegister(mul); | |
| 1430 | |
| 1431 } else if (instr->representation().IsDouble()) { | |
| 1432 if (instr->UseCount() == 1 && (instr->uses().value()->IsAdd() || | |
| 1433 instr->uses().value()->IsSub())) { | |
| 1434 HBinaryOperation* use = HBinaryOperation::cast(instr->uses().value()); | |
| 1435 | |
| 1436 if (use->IsAdd() && instr == use->left()) { | |
| 1437 // This mul is the lhs of an add. The add and mul will be folded into a | |
| 1438 // multiply-add in DoAdd. | |
| 1439 return NULL; | |
| 1440 } | |
| 1441 if (instr == use->right() && use->IsAdd() && !use->left()->IsMul()) { | |
| 1442 // This mul is the rhs of an add, where the lhs is not another mul. | |
| 1443 // The add and mul will be folded into a multiply-add in DoAdd. | |
| 1444 return NULL; | |
| 1445 } | |
| 1446 if (instr == use->right() && use->IsSub()) { | |
| 1447 // This mul is the rhs of a sub. The sub and mul will be folded into a | |
| 1448 // multiply-sub in DoSub. | |
| 1449 return NULL; | |
| 1450 } | 1159 } |
| 1451 } | 1160 } |
| 1452 | 1161 } |
| 1453 return DoArithmeticD(Token::MUL, instr); | 1162 |
| 1163 UNREACHABLE(); |
| 1164 return NULL; |
| 1165 } |
| 1166 |
| 1167 |
| 1168 LInstruction* LChunkBuilder::DoCheckValue(HCheckValue* instr) { |
| 1169 // We only need a temp register if the target is in new space, but we can't |
| 1170 // dereference the handle to test that here. |
| 1171 // TODO(all): Check these constraints. The temp register is not always used. |
| 1172 LOperand* value = UseRegister(instr->value()); |
| 1173 LOperand* temp = TempRegister(); |
| 1174 return AssignEnvironment(new(zone()) LCheckValue(value, temp)); |
| 1175 } |
| 1176 |
| 1177 |
| 1178 LInstruction* LChunkBuilder::DoCheckInstanceType(HCheckInstanceType* instr) { |
| 1179 LOperand* value = UseRegisterAtStart(instr->value()); |
| 1180 LOperand* temp = TempRegister(); |
| 1181 LInstruction* result = new(zone()) LCheckInstanceType(value, temp); |
| 1182 return AssignEnvironment(result); |
| 1183 } |
| 1184 |
| 1185 |
| 1186 LInstruction* LChunkBuilder::DoCheckMaps(HCheckMaps* instr) { |
| 1187 if (instr->CanOmitMapChecks()) { |
| 1188 // LCheckMaps does nothing in this case. |
| 1189 return new(zone()) LCheckMaps(NULL); |
| 1454 } else { | 1190 } else { |
| 1455 return DoArithmeticT(Token::MUL, instr); | 1191 LOperand* value = UseRegisterAtStart(instr->value()); |
| 1456 } | 1192 LOperand* temp = TempRegister(); |
| 1457 } | 1193 |
| 1458 | 1194 if (instr->has_migration_target()) { |
| 1459 | 1195 info()->MarkAsDeferredCalling(); |
| 1460 LInstruction* LChunkBuilder::DoSub(HSub* instr) { | 1196 LInstruction* result = new(zone()) LCheckMaps(value, temp); |
| 1461 if (instr->representation().IsSmiOrInteger32()) { | 1197 return AssignPointerMap(AssignEnvironment(result)); |
| 1462 ASSERT(instr->left()->representation().Equals(instr->representation())); | 1198 } else { |
| 1463 ASSERT(instr->right()->representation().Equals(instr->representation())); | 1199 return AssignEnvironment(new(zone()) LCheckMaps(value, temp)); |
| 1464 | |
| 1465 if (instr->left()->IsConstant()) { | |
| 1466 // If lhs is constant, do reverse subtraction instead. | |
| 1467 return DoRSub(instr); | |
| 1468 } | 1200 } |
| 1469 | 1201 } |
| 1470 LOperand* left = UseRegisterAtStart(instr->left()); | 1202 } |
| 1471 LOperand* right = UseOrConstantAtStart(instr->right()); | 1203 |
| 1472 LSubI* sub = new(zone()) LSubI(left, right); | 1204 |
| 1473 LInstruction* result = DefineAsRegister(sub); | 1205 LInstruction* LChunkBuilder::DoCheckHeapObject(HCheckHeapObject* instr) { |
| 1474 if (instr->CheckFlag(HValue::kCanOverflow)) { | 1206 LOperand* value = UseRegisterAtStart(instr->value()); |
| 1475 result = AssignEnvironment(result); | 1207 return AssignEnvironment(new(zone()) LCheckNonSmi(value)); |
| 1476 } | 1208 } |
| 1477 return result; | 1209 |
| 1478 } else if (instr->representation().IsDouble()) { | 1210 |
| 1479 if (instr->right()->IsMul()) { | 1211 LInstruction* LChunkBuilder::DoCheckSmi(HCheckSmi* instr) { |
| 1480 return DoMultiplySub(instr->left(), HMul::cast(instr->right())); | 1212 LOperand* value = UseRegisterAtStart(instr->value()); |
| 1481 } | 1213 return AssignEnvironment(new(zone()) LCheckSmi(value)); |
| 1482 | 1214 } |
| 1483 return DoArithmeticD(Token::SUB, instr); | 1215 |
| 1216 |
| 1217 LInstruction* LChunkBuilder::DoClampToUint8(HClampToUint8* instr) { |
| 1218 HValue* value = instr->value(); |
| 1219 Representation input_rep = value->representation(); |
| 1220 LOperand* reg = UseRegister(value); |
| 1221 if (input_rep.IsDouble()) { |
| 1222 return DefineAsRegister(new(zone()) LClampDToUint8(reg)); |
| 1223 } else if (input_rep.IsInteger32()) { |
| 1224 return DefineAsRegister(new(zone()) LClampIToUint8(reg)); |
| 1484 } else { | 1225 } else { |
| 1485 return DoArithmeticT(Token::SUB, instr); | 1226 ASSERT(input_rep.IsSmiOrTagged()); |
| 1486 } | 1227 return AssignEnvironment( |
| 1487 } | 1228 DefineAsRegister(new(zone()) LClampTToUint8(reg, |
| 1488 | 1229 TempRegister(), |
| 1489 | 1230 FixedTemp(d24)))); |
| 1490 LInstruction* LChunkBuilder::DoRSub(HSub* instr) { | 1231 } |
| 1491 ASSERT(instr->representation().IsSmiOrInteger32()); | 1232 } |
| 1492 ASSERT(instr->left()->representation().Equals(instr->representation())); | 1233 |
| 1493 ASSERT(instr->right()->representation().Equals(instr->representation())); | 1234 |
| 1494 | 1235 LInstruction* LChunkBuilder::DoClassOfTestAndBranch( |
| 1495 // Note: The lhs of the subtraction becomes the rhs of the | 1236 HClassOfTestAndBranch* instr) { |
| 1496 // reverse-subtraction. | 1237 ASSERT(instr->value()->representation().IsTagged()); |
| 1497 LOperand* left = UseRegisterAtStart(instr->right()); | 1238 LOperand* value = UseRegisterAtStart(instr->value()); |
| 1498 LOperand* right = UseOrConstantAtStart(instr->left()); | 1239 return new(zone()) LClassOfTestAndBranch(value, |
| 1499 LRSubI* rsb = new(zone()) LRSubI(left, right); | 1240 TempRegister(), |
| 1500 LInstruction* result = DefineAsRegister(rsb); | 1241 TempRegister()); |
| 1501 if (instr->CheckFlag(HValue::kCanOverflow)) { | |
| 1502 result = AssignEnvironment(result); | |
| 1503 } | |
| 1504 return result; | |
| 1505 } | |
| 1506 | |
| 1507 | |
| 1508 LInstruction* LChunkBuilder::DoMultiplyAdd(HMul* mul, HValue* addend) { | |
| 1509 LOperand* multiplier_op = UseRegisterAtStart(mul->left()); | |
| 1510 LOperand* multiplicand_op = UseRegisterAtStart(mul->right()); | |
| 1511 LOperand* addend_op = UseRegisterAtStart(addend); | |
| 1512 return DefineSameAsFirst(new(zone()) LMultiplyAddD(addend_op, multiplier_op, | |
| 1513 multiplicand_op)); | |
| 1514 } | |
| 1515 | |
| 1516 | |
| 1517 LInstruction* LChunkBuilder::DoMultiplySub(HValue* minuend, HMul* mul) { | |
| 1518 LOperand* minuend_op = UseRegisterAtStart(minuend); | |
| 1519 LOperand* multiplier_op = UseRegisterAtStart(mul->left()); | |
| 1520 LOperand* multiplicand_op = UseRegisterAtStart(mul->right()); | |
| 1521 | |
| 1522 return DefineSameAsFirst(new(zone()) LMultiplySubD(minuend_op, | |
| 1523 multiplier_op, | |
| 1524 multiplicand_op)); | |
| 1525 } | |
| 1526 | |
| 1527 | |
| 1528 LInstruction* LChunkBuilder::DoAdd(HAdd* instr) { | |
| 1529 if (instr->representation().IsSmiOrInteger32()) { | |
| 1530 ASSERT(instr->left()->representation().Equals(instr->representation())); | |
| 1531 ASSERT(instr->right()->representation().Equals(instr->representation())); | |
| 1532 LOperand* left = UseRegisterAtStart(instr->BetterLeftOperand()); | |
| 1533 LOperand* right = UseOrConstantAtStart(instr->BetterRightOperand()); | |
| 1534 LAddI* add = new(zone()) LAddI(left, right); | |
| 1535 LInstruction* result = DefineAsRegister(add); | |
| 1536 if (instr->CheckFlag(HValue::kCanOverflow)) { | |
| 1537 result = AssignEnvironment(result); | |
| 1538 } | |
| 1539 return result; | |
| 1540 } else if (instr->representation().IsExternal()) { | |
| 1541 ASSERT(instr->left()->representation().IsExternal()); | |
| 1542 ASSERT(instr->right()->representation().IsInteger32()); | |
| 1543 ASSERT(!instr->CheckFlag(HValue::kCanOverflow)); | |
| 1544 LOperand* left = UseRegisterAtStart(instr->left()); | |
| 1545 LOperand* right = UseOrConstantAtStart(instr->right()); | |
| 1546 LAddI* add = new(zone()) LAddI(left, right); | |
| 1547 LInstruction* result = DefineAsRegister(add); | |
| 1548 return result; | |
| 1549 } else if (instr->representation().IsDouble()) { | |
| 1550 if (instr->left()->IsMul()) { | |
| 1551 return DoMultiplyAdd(HMul::cast(instr->left()), instr->right()); | |
| 1552 } | |
| 1553 | |
| 1554 if (instr->right()->IsMul()) { | |
| 1555 ASSERT(!instr->left()->IsMul()); | |
| 1556 return DoMultiplyAdd(HMul::cast(instr->right()), instr->left()); | |
| 1557 } | |
| 1558 | |
| 1559 return DoArithmeticD(Token::ADD, instr); | |
| 1560 } else { | |
| 1561 return DoArithmeticT(Token::ADD, instr); | |
| 1562 } | |
| 1563 } | |
| 1564 | |
| 1565 | |
| 1566 LInstruction* LChunkBuilder::DoMathMinMax(HMathMinMax* instr) { | |
| 1567 LOperand* left = NULL; | |
| 1568 LOperand* right = NULL; | |
| 1569 if (instr->representation().IsSmiOrInteger32()) { | |
| 1570 ASSERT(instr->left()->representation().Equals(instr->representation())); | |
| 1571 ASSERT(instr->right()->representation().Equals(instr->representation())); | |
| 1572 left = UseRegisterAtStart(instr->BetterLeftOperand()); | |
| 1573 right = UseOrConstantAtStart(instr->BetterRightOperand()); | |
| 1574 } else { | |
| 1575 ASSERT(instr->representation().IsDouble()); | |
| 1576 ASSERT(instr->left()->representation().IsDouble()); | |
| 1577 ASSERT(instr->right()->representation().IsDouble()); | |
| 1578 left = UseRegisterAtStart(instr->left()); | |
| 1579 right = UseRegisterAtStart(instr->right()); | |
| 1580 } | |
| 1581 return DefineAsRegister(new(zone()) LMathMinMax(left, right)); | |
| 1582 } | |
| 1583 | |
| 1584 | |
| 1585 LInstruction* LChunkBuilder::DoPower(HPower* instr) { | |
| 1586 ASSERT(instr->representation().IsDouble()); | |
| 1587 // We call a C function for double power. It can't trigger a GC. | |
| 1588 // We need to use fixed result register for the call. | |
| 1589 Representation exponent_type = instr->right()->representation(); | |
| 1590 ASSERT(instr->left()->representation().IsDouble()); | |
| 1591 LOperand* left = UseFixedDouble(instr->left(), d0); | |
| 1592 LOperand* right = exponent_type.IsDouble() ? | |
| 1593 UseFixedDouble(instr->right(), d1) : | |
| 1594 UseFixed(instr->right(), r2); | |
| 1595 LPower* result = new(zone()) LPower(left, right); | |
| 1596 return MarkAsCall(DefineFixedDouble(result, d2), | |
| 1597 instr, | |
| 1598 CAN_DEOPTIMIZE_EAGERLY); | |
| 1599 } | |
| 1600 | |
| 1601 | |
| 1602 LInstruction* LChunkBuilder::DoCompareGeneric(HCompareGeneric* instr) { | |
| 1603 ASSERT(instr->left()->representation().IsTagged()); | |
| 1604 ASSERT(instr->right()->representation().IsTagged()); | |
| 1605 LOperand* context = UseFixed(instr->context(), cp); | |
| 1606 LOperand* left = UseFixed(instr->left(), r1); | |
| 1607 LOperand* right = UseFixed(instr->right(), r0); | |
| 1608 LCmpT* result = new(zone()) LCmpT(context, left, right); | |
| 1609 return MarkAsCall(DefineFixed(result, r0), instr); | |
| 1610 } | 1242 } |
| 1611 | 1243 |
| 1612 | 1244 |
| 1613 LInstruction* LChunkBuilder::DoCompareNumericAndBranch( | 1245 LInstruction* LChunkBuilder::DoCompareNumericAndBranch( |
| 1614 HCompareNumericAndBranch* instr) { | 1246 HCompareNumericAndBranch* instr) { |
| 1615 Representation r = instr->representation(); | 1247 Representation r = instr->representation(); |
| 1248 |
| 1616 if (r.IsSmiOrInteger32()) { | 1249 if (r.IsSmiOrInteger32()) { |
| 1617 ASSERT(instr->left()->representation().Equals(r)); | 1250 ASSERT(instr->left()->representation().Equals(r)); |
| 1618 ASSERT(instr->right()->representation().Equals(r)); | 1251 ASSERT(instr->right()->representation().Equals(r)); |
| 1619 LOperand* left = UseRegisterOrConstantAtStart(instr->left()); | 1252 LOperand* left = UseRegisterOrConstantAtStart(instr->left()); |
| 1620 LOperand* right = UseRegisterOrConstantAtStart(instr->right()); | 1253 LOperand* right = UseRegisterOrConstantAtStart(instr->right()); |
| 1621 return new(zone()) LCompareNumericAndBranch(left, right); | 1254 return new(zone()) LCompareNumericAndBranch(left, right); |
| 1622 } else { | 1255 } else { |
| 1623 ASSERT(r.IsDouble()); | 1256 ASSERT(r.IsDouble()); |
| 1624 ASSERT(instr->left()->representation().IsDouble()); | 1257 ASSERT(instr->left()->representation().IsDouble()); |
| 1625 ASSERT(instr->right()->representation().IsDouble()); | 1258 ASSERT(instr->right()->representation().IsDouble()); |
| 1626 LOperand* left = UseRegisterAtStart(instr->left()); | 1259 // TODO(all): In fact the only case that we can handle more efficiently is |
| 1627 LOperand* right = UseRegisterAtStart(instr->right()); | 1260 // when one of the operand is the constant 0. Currently the MacroAssembler |
| 1261 // will be able to cope with any constant by loading it into an internal |
| 1262 // scratch register. This means that if the constant is used more that once, |
| 1263 // it will be loaded multiple times. Unfortunatly crankshaft already |
| 1264 // duplicates constant loads, but we should modify the code below once this |
| 1265 // issue has been addressed in crankshaft. |
| 1266 LOperand* left = UseRegisterOrConstantAtStart(instr->left()); |
| 1267 LOperand* right = UseRegisterOrConstantAtStart(instr->right()); |
| 1628 return new(zone()) LCompareNumericAndBranch(left, right); | 1268 return new(zone()) LCompareNumericAndBranch(left, right); |
| 1629 } | 1269 } |
| 1630 } | 1270 } |
| 1631 | 1271 |
| 1632 | 1272 |
| 1273 LInstruction* LChunkBuilder::DoCompareGeneric(HCompareGeneric* instr) { |
| 1274 ASSERT(instr->left()->representation().IsTagged()); |
| 1275 ASSERT(instr->right()->representation().IsTagged()); |
| 1276 LOperand* context = UseFixed(instr->context(), cp); |
| 1277 LOperand* left = UseFixed(instr->left(), x1); |
| 1278 LOperand* right = UseFixed(instr->right(), x0); |
| 1279 LCmpT* result = new(zone()) LCmpT(context, left, right); |
| 1280 return MarkAsCall(DefineFixed(result, x0), instr); |
| 1281 } |
| 1282 |
| 1283 |
| 1284 LInstruction* LChunkBuilder::DoCompareHoleAndBranch( |
| 1285 HCompareHoleAndBranch* instr) { |
| 1286 LOperand* value = UseRegister(instr->value()); |
| 1287 if (instr->representation().IsTagged()) { |
| 1288 return new(zone()) LCmpHoleAndBranchT(value); |
| 1289 } else { |
| 1290 LOperand* temp = TempRegister(); |
| 1291 return new(zone()) LCmpHoleAndBranchD(value, temp); |
| 1292 } |
| 1293 } |
| 1294 |
| 1295 |
| 1633 LInstruction* LChunkBuilder::DoCompareObjectEqAndBranch( | 1296 LInstruction* LChunkBuilder::DoCompareObjectEqAndBranch( |
| 1634 HCompareObjectEqAndBranch* instr) { | 1297 HCompareObjectEqAndBranch* instr) { |
| 1635 LInstruction* goto_instr = CheckElideControlInstruction(instr); | 1298 LInstruction* goto_instr = CheckElideControlInstruction(instr); |
| 1636 if (goto_instr != NULL) return goto_instr; | 1299 if (goto_instr != NULL) return goto_instr; |
| 1300 |
| 1637 LOperand* left = UseRegisterAtStart(instr->left()); | 1301 LOperand* left = UseRegisterAtStart(instr->left()); |
| 1638 LOperand* right = UseRegisterAtStart(instr->right()); | 1302 LOperand* right = UseRegisterAtStart(instr->right()); |
| 1639 return new(zone()) LCmpObjectEqAndBranch(left, right); | 1303 return new(zone()) LCmpObjectEqAndBranch(left, right); |
| 1640 } | 1304 } |
| 1641 | 1305 |
| 1642 | 1306 |
| 1643 LInstruction* LChunkBuilder::DoCompareHoleAndBranch( | 1307 LInstruction* LChunkBuilder::DoCompareMap(HCompareMap* instr) { |
| 1644 HCompareHoleAndBranch* instr) { | 1308 LInstruction* goto_instr = CheckElideControlInstruction(instr); |
| 1645 LOperand* value = UseRegisterAtStart(instr->value()); | 1309 if (goto_instr != NULL) return goto_instr; |
| 1646 return new(zone()) LCmpHoleAndBranch(value); | 1310 |
| 1647 } | 1311 ASSERT(instr->value()->representation().IsTagged()); |
| 1648 | 1312 LOperand* value = UseRegisterAtStart(instr->value()); |
| 1649 | 1313 LOperand* temp = TempRegister(); |
| 1314 return new(zone()) LCmpMapAndBranch(value, temp); |
| 1315 } |
| 1316 |
| 1317 |
| 1318 LInstruction* LChunkBuilder::DoConstant(HConstant* instr) { |
| 1319 Representation r = instr->representation(); |
| 1320 if (r.IsSmi()) { |
| 1321 return DefineAsRegister(new(zone()) LConstantS); |
| 1322 } else if (r.IsInteger32()) { |
| 1323 return DefineAsRegister(new(zone()) LConstantI); |
| 1324 } else if (r.IsDouble()) { |
| 1325 return DefineAsRegister(new(zone()) LConstantD); |
| 1326 } else if (r.IsExternal()) { |
| 1327 return DefineAsRegister(new(zone()) LConstantE); |
| 1328 } else if (r.IsTagged()) { |
| 1329 return DefineAsRegister(new(zone()) LConstantT); |
| 1330 } else { |
| 1331 UNREACHABLE(); |
| 1332 return NULL; |
| 1333 } |
| 1334 } |
| 1335 |
| 1336 |
| 1337 LInstruction* LChunkBuilder::DoContext(HContext* instr) { |
| 1338 if (instr->HasNoUses()) return NULL; |
| 1339 |
| 1340 if (info()->IsStub()) { |
| 1341 return DefineFixed(new(zone()) LContext, cp); |
| 1342 } |
| 1343 |
| 1344 return DefineAsRegister(new(zone()) LContext); |
| 1345 } |
| 1346 |
| 1347 |
| 1348 LInstruction* LChunkBuilder::DoDateField(HDateField* instr) { |
| 1349 LOperand* object = UseFixed(instr->value(), x0); |
| 1350 LDateField* result = new(zone()) LDateField(object, instr->index()); |
| 1351 return MarkAsCall(DefineFixed(result, x0), instr, CAN_DEOPTIMIZE_EAGERLY); |
| 1352 } |
| 1353 |
| 1354 |
| 1355 LInstruction* LChunkBuilder::DoDebugBreak(HDebugBreak* instr) { |
| 1356 return new(zone()) LDebugBreak(); |
| 1357 } |
| 1358 |
| 1359 |
| 1360 LInstruction* LChunkBuilder::DoDeclareGlobals(HDeclareGlobals* instr) { |
| 1361 LOperand* context = UseFixed(instr->context(), cp); |
| 1362 return MarkAsCall(new(zone()) LDeclareGlobals(context), instr); |
| 1363 } |
| 1364 |
| 1365 |
| 1366 LInstruction* LChunkBuilder::DoDeoptimize(HDeoptimize* instr) { |
| 1367 return AssignEnvironment(new(zone()) LDeoptimize); |
| 1368 } |
| 1369 |
| 1370 |
| 1371 LInstruction* LChunkBuilder::DoDiv(HDiv* instr) { |
| 1372 if (instr->representation().IsInteger32()) { |
| 1373 // TODO(all): Update this case to support smi inputs. |
| 1374 ASSERT(instr->left()->representation().Equals(instr->representation())); |
| 1375 ASSERT(instr->right()->representation().Equals(instr->representation())); |
| 1376 if (instr->RightIsPowerOf2()) { |
| 1377 ASSERT(!instr->CheckFlag(HValue::kCanBeDivByZero)); |
| 1378 LOperand* value = UseRegister(instr->left()); |
| 1379 LDivI* div = new(zone()) LDivI(value, UseConstant(instr->right()), NULL); |
| 1380 return AssignEnvironment(DefineAsRegister(div)); |
| 1381 } |
| 1382 LOperand* dividend = UseRegister(instr->left()); |
| 1383 LOperand* divisor = UseRegister(instr->right()); |
| 1384 LOperand* temp = instr->CheckFlag(HInstruction::kAllUsesTruncatingToInt32) |
| 1385 ? NULL : TempRegister(); |
| 1386 LDivI* div = new(zone()) LDivI(dividend, divisor, temp); |
| 1387 return AssignEnvironment(DefineAsRegister(div)); |
| 1388 } else if (instr->representation().IsDouble()) { |
| 1389 return DoArithmeticD(Token::DIV, instr); |
| 1390 } else { |
| 1391 return DoArithmeticT(Token::DIV, instr); |
| 1392 } |
| 1393 } |
| 1394 |
| 1395 |
| 1396 LInstruction* LChunkBuilder::DoDummyUse(HDummyUse* instr) { |
| 1397 return DefineAsRegister(new(zone()) LDummyUse(UseAny(instr->value()))); |
| 1398 } |
| 1399 |
| 1400 |
| 1401 LInstruction* LChunkBuilder::DoEnterInlined(HEnterInlined* instr) { |
| 1402 HEnvironment* outer = current_block_->last_environment(); |
| 1403 HConstant* undefined = graph()->GetConstantUndefined(); |
| 1404 HEnvironment* inner = outer->CopyForInlining(instr->closure(), |
| 1405 instr->arguments_count(), |
| 1406 instr->function(), |
| 1407 undefined, |
| 1408 instr->inlining_kind()); |
| 1409 // Only replay binding of arguments object if it wasn't removed from graph. |
| 1410 if ((instr->arguments_var() != NULL) && |
| 1411 instr->arguments_object()->IsLinked()) { |
| 1412 inner->Bind(instr->arguments_var(), instr->arguments_object()); |
| 1413 } |
| 1414 inner->set_entry(instr); |
| 1415 current_block_->UpdateEnvironment(inner); |
| 1416 chunk_->AddInlinedClosure(instr->closure()); |
| 1417 return NULL; |
| 1418 } |
| 1419 |
| 1420 |
| 1421 LInstruction* LChunkBuilder::DoEnvironmentMarker(HEnvironmentMarker* instr) { |
| 1422 UNREACHABLE(); |
| 1423 return NULL; |
| 1424 } |
| 1425 |
| 1426 |
| 1427 LInstruction* LChunkBuilder::DoForceRepresentation( |
| 1428 HForceRepresentation* instr) { |
| 1429 // All HForceRepresentation instructions should be eliminated in the |
| 1430 // representation change phase of Hydrogen. |
| 1431 UNREACHABLE(); |
| 1432 return NULL; |
| 1433 } |
| 1434 |
| 1435 |
| 1436 LInstruction* LChunkBuilder::DoFunctionLiteral(HFunctionLiteral* instr) { |
| 1437 LOperand* context = UseFixed(instr->context(), cp); |
| 1438 return MarkAsCall( |
| 1439 DefineFixed(new(zone()) LFunctionLiteral(context), x0), instr); |
| 1440 } |
| 1441 |
| 1442 |
| 1443 LInstruction* LChunkBuilder::DoGetCachedArrayIndex( |
| 1444 HGetCachedArrayIndex* instr) { |
| 1445 ASSERT(instr->value()->representation().IsTagged()); |
| 1446 LOperand* value = UseRegisterAtStart(instr->value()); |
| 1447 return DefineAsRegister(new(zone()) LGetCachedArrayIndex(value)); |
| 1448 } |
| 1449 |
| 1450 |
| 1451 LInstruction* LChunkBuilder::DoGoto(HGoto* instr) { |
| 1452 return new(zone()) LGoto(instr->FirstSuccessor()); |
| 1453 } |
| 1454 |
| 1455 |
| 1456 LInstruction* LChunkBuilder::DoHasCachedArrayIndexAndBranch( |
| 1457 HHasCachedArrayIndexAndBranch* instr) { |
| 1458 ASSERT(instr->value()->representation().IsTagged()); |
| 1459 return new(zone()) LHasCachedArrayIndexAndBranch( |
| 1460 UseRegisterAtStart(instr->value()), TempRegister()); |
| 1461 } |
| 1462 |
| 1463 |
| 1464 LInstruction* LChunkBuilder::DoHasInstanceTypeAndBranch( |
| 1465 HHasInstanceTypeAndBranch* instr) { |
| 1466 ASSERT(instr->value()->representation().IsTagged()); |
| 1467 LOperand* value = UseRegisterAtStart(instr->value()); |
| 1468 return new(zone()) LHasInstanceTypeAndBranch(value, TempRegister()); |
| 1469 } |
| 1470 |
| 1471 |
| 1472 LInstruction* LChunkBuilder::DoInnerAllocatedObject( |
| 1473 HInnerAllocatedObject* instr) { |
| 1474 LOperand* base_object = UseRegisterAtStart(instr->base_object()); |
| 1475 LOperand* offset = UseRegisterOrConstantAtStart(instr->offset()); |
| 1476 return DefineAsRegister( |
| 1477 new(zone()) LInnerAllocatedObject(base_object, offset)); |
| 1478 } |
| 1479 |
| 1480 |
| 1481 LInstruction* LChunkBuilder::DoInstanceOf(HInstanceOf* instr) { |
| 1482 LOperand* context = UseFixed(instr->context(), cp); |
| 1483 LInstanceOf* result = new(zone()) LInstanceOf( |
| 1484 context, |
| 1485 UseFixed(instr->left(), InstanceofStub::left()), |
| 1486 UseFixed(instr->right(), InstanceofStub::right())); |
| 1487 return MarkAsCall(DefineFixed(result, x0), instr); |
| 1488 } |
| 1489 |
| 1490 |
| 1491 LInstruction* LChunkBuilder::DoInstanceOfKnownGlobal( |
| 1492 HInstanceOfKnownGlobal* instr) { |
| 1493 LInstanceOfKnownGlobal* result = new(zone()) LInstanceOfKnownGlobal( |
| 1494 UseFixed(instr->context(), cp), |
| 1495 UseFixed(instr->left(), InstanceofStub::left())); |
| 1496 return MarkAsCall(DefineFixed(result, x0), instr); |
| 1497 } |
| 1498 |
| 1499 |
| 1500 LInstruction* LChunkBuilder::DoInvokeFunction(HInvokeFunction* instr) { |
| 1501 LOperand* context = UseFixed(instr->context(), cp); |
| 1502 // The function is required (by MacroAssembler::InvokeFunction) to be in x1. |
| 1503 LOperand* function = UseFixed(instr->function(), x1); |
| 1504 LInvokeFunction* result = new(zone()) LInvokeFunction(context, function); |
| 1505 return MarkAsCall(DefineFixed(result, x0), instr, CANNOT_DEOPTIMIZE_EAGERLY); |
| 1506 } |
| 1507 |
| 1508 |
| 1509 LInstruction* LChunkBuilder::DoIsConstructCallAndBranch( |
| 1510 HIsConstructCallAndBranch* instr) { |
| 1511 return new(zone()) LIsConstructCallAndBranch(TempRegister(), TempRegister()); |
| 1512 } |
| 1513 |
| 1514 |
| 1650 LInstruction* LChunkBuilder::DoCompareMinusZeroAndBranch( | 1515 LInstruction* LChunkBuilder::DoCompareMinusZeroAndBranch( |
| 1651 HCompareMinusZeroAndBranch* instr) { | 1516 HCompareMinusZeroAndBranch* instr) { |
| 1652 LInstruction* goto_instr = CheckElideControlInstruction(instr); | 1517 LInstruction* goto_instr = CheckElideControlInstruction(instr); |
| 1653 if (goto_instr != NULL) return goto_instr; | 1518 if (goto_instr != NULL) return goto_instr; |
| 1654 LOperand* value = UseRegister(instr->value()); | 1519 LOperand* value = UseRegister(instr->value()); |
| 1655 LOperand* scratch = TempRegister(); | 1520 LOperand* scratch = TempRegister(); |
| 1656 return new(zone()) LCompareMinusZeroAndBranch(value, scratch); | 1521 return new(zone()) LCompareMinusZeroAndBranch(value, scratch); |
| 1657 } | 1522 } |
| 1658 | 1523 |
| 1659 | 1524 |
| 1660 LInstruction* LChunkBuilder::DoIsObjectAndBranch(HIsObjectAndBranch* instr) { | 1525 LInstruction* LChunkBuilder::DoIsObjectAndBranch(HIsObjectAndBranch* instr) { |
| 1661 ASSERT(instr->value()->representation().IsTagged()); | 1526 ASSERT(instr->value()->representation().IsTagged()); |
| 1662 LOperand* value = UseRegisterAtStart(instr->value()); | 1527 LOperand* value = UseRegisterAtStart(instr->value()); |
| 1663 LOperand* temp = TempRegister(); | 1528 LOperand* temp1 = TempRegister(); |
| 1664 return new(zone()) LIsObjectAndBranch(value, temp); | 1529 LOperand* temp2 = TempRegister(); |
| 1530 return new(zone()) LIsObjectAndBranch(value, temp1, temp2); |
| 1665 } | 1531 } |
| 1666 | 1532 |
| 1667 | 1533 |
| 1668 LInstruction* LChunkBuilder::DoIsStringAndBranch(HIsStringAndBranch* instr) { | 1534 LInstruction* LChunkBuilder::DoIsStringAndBranch(HIsStringAndBranch* instr) { |
| 1669 ASSERT(instr->value()->representation().IsTagged()); | 1535 ASSERT(instr->value()->representation().IsTagged()); |
| 1670 LOperand* value = UseRegisterAtStart(instr->value()); | 1536 LOperand* value = UseRegisterAtStart(instr->value()); |
| 1671 LOperand* temp = TempRegister(); | 1537 LOperand* temp = TempRegister(); |
| 1672 return new(zone()) LIsStringAndBranch(value, temp); | 1538 return new(zone()) LIsStringAndBranch(value, temp); |
| 1673 } | 1539 } |
| 1674 | 1540 |
| 1675 | 1541 |
| 1676 LInstruction* LChunkBuilder::DoIsSmiAndBranch(HIsSmiAndBranch* instr) { | 1542 LInstruction* LChunkBuilder::DoIsSmiAndBranch(HIsSmiAndBranch* instr) { |
| 1677 ASSERT(instr->value()->representation().IsTagged()); | 1543 ASSERT(instr->value()->representation().IsTagged()); |
| 1678 return new(zone()) LIsSmiAndBranch(Use(instr->value())); | 1544 return new(zone()) LIsSmiAndBranch(UseRegisterAtStart(instr->value())); |
| 1679 } | 1545 } |
| 1680 | 1546 |
| 1681 | 1547 |
| 1682 LInstruction* LChunkBuilder::DoIsUndetectableAndBranch( | 1548 LInstruction* LChunkBuilder::DoIsUndetectableAndBranch( |
| 1683 HIsUndetectableAndBranch* instr) { | 1549 HIsUndetectableAndBranch* instr) { |
| 1684 ASSERT(instr->value()->representation().IsTagged()); | 1550 ASSERT(instr->value()->representation().IsTagged()); |
| 1685 LOperand* value = UseRegisterAtStart(instr->value()); | 1551 LOperand* value = UseRegisterAtStart(instr->value()); |
| 1686 return new(zone()) LIsUndetectableAndBranch(value, TempRegister()); | 1552 return new(zone()) LIsUndetectableAndBranch(value, TempRegister()); |
| 1687 } | 1553 } |
| 1688 | 1554 |
| 1689 | 1555 |
| 1690 LInstruction* LChunkBuilder::DoStringCompareAndBranch( | 1556 LInstruction* LChunkBuilder::DoLeaveInlined(HLeaveInlined* instr) { |
| 1691 HStringCompareAndBranch* instr) { | 1557 LInstruction* pop = NULL; |
| 1692 ASSERT(instr->left()->representation().IsTagged()); | 1558 HEnvironment* env = current_block_->last_environment(); |
| 1693 ASSERT(instr->right()->representation().IsTagged()); | 1559 |
| 1560 if (env->entry()->arguments_pushed()) { |
| 1561 int argument_count = env->arguments_environment()->parameter_count(); |
| 1562 pop = new(zone()) LDrop(argument_count); |
| 1563 ASSERT(instr->argument_delta() == -argument_count); |
| 1564 } |
| 1565 |
| 1566 HEnvironment* outer = |
| 1567 current_block_->last_environment()->DiscardInlined(false); |
| 1568 current_block_->UpdateEnvironment(outer); |
| 1569 |
| 1570 return pop; |
| 1571 } |
| 1572 |
| 1573 |
| 1574 LInstruction* LChunkBuilder::DoLoadContextSlot(HLoadContextSlot* instr) { |
| 1575 LOperand* context = UseRegisterAtStart(instr->value()); |
| 1576 LInstruction* result = |
| 1577 DefineAsRegister(new(zone()) LLoadContextSlot(context)); |
| 1578 return instr->RequiresHoleCheck() ? AssignEnvironment(result) : result; |
| 1579 } |
| 1580 |
| 1581 |
| 1582 LInstruction* LChunkBuilder::DoLoadFunctionPrototype( |
| 1583 HLoadFunctionPrototype* instr) { |
| 1584 LOperand* function = UseRegister(instr->function()); |
| 1585 LOperand* temp = TempRegister(); |
| 1586 return AssignEnvironment(DefineAsRegister( |
| 1587 new(zone()) LLoadFunctionPrototype(function, temp))); |
| 1588 } |
| 1589 |
| 1590 |
| 1591 LInstruction* LChunkBuilder::DoLoadGlobalCell(HLoadGlobalCell* instr) { |
| 1592 LLoadGlobalCell* result = new(zone()) LLoadGlobalCell(); |
| 1593 return instr->RequiresHoleCheck() |
| 1594 ? AssignEnvironment(DefineAsRegister(result)) |
| 1595 : DefineAsRegister(result); |
| 1596 } |
| 1597 |
| 1598 |
| 1599 LInstruction* LChunkBuilder::DoLoadGlobalGeneric(HLoadGlobalGeneric* instr) { |
| 1694 LOperand* context = UseFixed(instr->context(), cp); | 1600 LOperand* context = UseFixed(instr->context(), cp); |
| 1695 LOperand* left = UseFixed(instr->left(), r1); | 1601 LOperand* global_object = UseFixed(instr->global_object(), x0); |
| 1696 LOperand* right = UseFixed(instr->right(), r0); | 1602 LLoadGlobalGeneric* result = |
| 1697 LStringCompareAndBranch* result = | 1603 new(zone()) LLoadGlobalGeneric(context, global_object); |
| 1698 new(zone()) LStringCompareAndBranch(context, left, right); | 1604 return MarkAsCall(DefineFixed(result, x0), instr); |
| 1605 } |
| 1606 |
| 1607 |
| 1608 LInstruction* LChunkBuilder::DoLoadKeyed(HLoadKeyed* instr) { |
| 1609 ASSERT(instr->key()->representation().IsSmiOrInteger32()); |
| 1610 ElementsKind elements_kind = instr->elements_kind(); |
| 1611 LOperand* elements = UseRegister(instr->elements()); |
| 1612 LOperand* key = UseRegisterOrConstantAtStart(instr->key()); |
| 1613 |
| 1614 if (!instr->is_typed_elements()) { |
| 1615 if (instr->representation().IsDouble()) { |
| 1616 LOperand* temp = (!instr->key()->IsConstant() || |
| 1617 instr->RequiresHoleCheck()) |
| 1618 ? TempRegister() |
| 1619 : NULL; |
| 1620 |
| 1621 LLoadKeyedFixedDouble* result = |
| 1622 new(zone()) LLoadKeyedFixedDouble(elements, key, temp); |
| 1623 return instr->RequiresHoleCheck() |
| 1624 ? AssignEnvironment(DefineAsRegister(result)) |
| 1625 : DefineAsRegister(result); |
| 1626 } else { |
| 1627 ASSERT(instr->representation().IsSmiOrTagged() || |
| 1628 instr->representation().IsInteger32()); |
| 1629 LOperand* temp = instr->key()->IsConstant() ? NULL : TempRegister(); |
| 1630 LLoadKeyedFixed* result = |
| 1631 new(zone()) LLoadKeyedFixed(elements, key, temp); |
| 1632 return instr->RequiresHoleCheck() |
| 1633 ? AssignEnvironment(DefineAsRegister(result)) |
| 1634 : DefineAsRegister(result); |
| 1635 } |
| 1636 } else { |
| 1637 ASSERT((instr->representation().IsInteger32() && |
| 1638 !IsDoubleOrFloatElementsKind(instr->elements_kind())) || |
| 1639 (instr->representation().IsDouble() && |
| 1640 IsDoubleOrFloatElementsKind(instr->elements_kind()))); |
| 1641 |
| 1642 LOperand* temp = instr->key()->IsConstant() ? NULL : TempRegister(); |
| 1643 LLoadKeyedExternal* result = |
| 1644 new(zone()) LLoadKeyedExternal(elements, key, temp); |
| 1645 // An unsigned int array load might overflow and cause a deopt. Make sure it |
| 1646 // has an environment. |
| 1647 if (instr->RequiresHoleCheck() || |
| 1648 elements_kind == EXTERNAL_UINT32_ELEMENTS || |
| 1649 elements_kind == UINT32_ELEMENTS) { |
| 1650 return AssignEnvironment(DefineAsRegister(result)); |
| 1651 } else { |
| 1652 return DefineAsRegister(result); |
| 1653 } |
| 1654 } |
| 1655 } |
| 1656 |
| 1657 |
| 1658 LInstruction* LChunkBuilder::DoLoadKeyedGeneric(HLoadKeyedGeneric* instr) { |
| 1659 LOperand* context = UseFixed(instr->context(), cp); |
| 1660 LOperand* object = UseFixed(instr->object(), x1); |
| 1661 LOperand* key = UseFixed(instr->key(), x0); |
| 1662 |
| 1663 LInstruction* result = |
| 1664 DefineFixed(new(zone()) LLoadKeyedGeneric(context, object, key), x0); |
| 1699 return MarkAsCall(result, instr); | 1665 return MarkAsCall(result, instr); |
| 1700 } | 1666 } |
| 1701 | 1667 |
| 1702 | 1668 |
| 1703 LInstruction* LChunkBuilder::DoHasInstanceTypeAndBranch( | 1669 LInstruction* LChunkBuilder::DoLoadNamedField(HLoadNamedField* instr) { |
| 1704 HHasInstanceTypeAndBranch* instr) { | 1670 LOperand* object = UseRegisterAtStart(instr->object()); |
| 1705 ASSERT(instr->value()->representation().IsTagged()); | 1671 return DefineAsRegister(new(zone()) LLoadNamedField(object)); |
| 1706 LOperand* value = UseRegisterAtStart(instr->value()); | 1672 } |
| 1707 return new(zone()) LHasInstanceTypeAndBranch(value); | 1673 |
| 1708 } | 1674 |
| 1709 | 1675 LInstruction* LChunkBuilder::DoLoadNamedGeneric(HLoadNamedGeneric* instr) { |
| 1710 | 1676 LOperand* context = UseFixed(instr->context(), cp); |
| 1711 LInstruction* LChunkBuilder::DoGetCachedArrayIndex( | 1677 LOperand* object = UseFixed(instr->object(), x0); |
| 1712 HGetCachedArrayIndex* instr) { | 1678 LInstruction* result = |
| 1713 ASSERT(instr->value()->representation().IsTagged()); | 1679 DefineFixed(new(zone()) LLoadNamedGeneric(context, object), x0); |
| 1714 LOperand* value = UseRegisterAtStart(instr->value()); | 1680 return MarkAsCall(result, instr); |
| 1715 | 1681 } |
| 1716 return DefineAsRegister(new(zone()) LGetCachedArrayIndex(value)); | 1682 |
| 1717 } | 1683 |
| 1718 | 1684 LInstruction* LChunkBuilder::DoLoadRoot(HLoadRoot* instr) { |
| 1719 | 1685 return DefineAsRegister(new(zone()) LLoadRoot); |
| 1720 LInstruction* LChunkBuilder::DoHasCachedArrayIndexAndBranch( | |
| 1721 HHasCachedArrayIndexAndBranch* instr) { | |
| 1722 ASSERT(instr->value()->representation().IsTagged()); | |
| 1723 return new(zone()) LHasCachedArrayIndexAndBranch( | |
| 1724 UseRegisterAtStart(instr->value())); | |
| 1725 } | |
| 1726 | |
| 1727 | |
| 1728 LInstruction* LChunkBuilder::DoClassOfTestAndBranch( | |
| 1729 HClassOfTestAndBranch* instr) { | |
| 1730 ASSERT(instr->value()->representation().IsTagged()); | |
| 1731 LOperand* value = UseRegister(instr->value()); | |
| 1732 return new(zone()) LClassOfTestAndBranch(value, TempRegister()); | |
| 1733 } | 1686 } |
| 1734 | 1687 |
| 1735 | 1688 |
| 1736 LInstruction* LChunkBuilder::DoMapEnumLength(HMapEnumLength* instr) { | 1689 LInstruction* LChunkBuilder::DoMapEnumLength(HMapEnumLength* instr) { |
| 1737 LOperand* map = UseRegisterAtStart(instr->value()); | 1690 LOperand* map = UseRegisterAtStart(instr->value()); |
| 1738 return DefineAsRegister(new(zone()) LMapEnumLength(map)); | 1691 return DefineAsRegister(new(zone()) LMapEnumLength(map)); |
| 1739 } | 1692 } |
| 1740 | 1693 |
| 1741 | 1694 |
| 1742 LInstruction* LChunkBuilder::DoElementsKind(HElementsKind* instr) { | 1695 LInstruction* LChunkBuilder::DoMathFloorOfDiv(HMathFloorOfDiv* instr) { |
| 1743 LOperand* object = UseRegisterAtStart(instr->value()); | 1696 HValue* right = instr->right(); |
| 1744 return DefineAsRegister(new(zone()) LElementsKind(object)); | 1697 LOperand* dividend = UseRegister(instr->left()); |
| 1745 } | 1698 LOperand* divisor = UseRegister(right); |
| 1746 | 1699 LOperand* remainder = TempRegister(); |
| 1747 | 1700 return AssignEnvironment(DefineAsRegister( |
| 1748 LInstruction* LChunkBuilder::DoValueOf(HValueOf* instr) { | 1701 new(zone()) LMathFloorOfDiv(dividend, divisor, remainder))); |
| 1749 LOperand* object = UseRegister(instr->value()); | 1702 } |
| 1750 LValueOf* result = new(zone()) LValueOf(object, TempRegister()); | 1703 |
| 1751 return DefineAsRegister(result); | 1704 |
| 1752 } | 1705 LInstruction* LChunkBuilder::DoMathMinMax(HMathMinMax* instr) { |
| 1753 | 1706 LOperand* left = NULL; |
| 1754 | 1707 LOperand* right = NULL; |
| 1755 LInstruction* LChunkBuilder::DoDateField(HDateField* instr) { | 1708 if (instr->representation().IsSmiOrInteger32()) { |
| 1756 LOperand* object = UseFixed(instr->value(), r0); | 1709 ASSERT(instr->left()->representation().Equals(instr->representation())); |
| 1757 LDateField* result = | 1710 ASSERT(instr->right()->representation().Equals(instr->representation())); |
| 1758 new(zone()) LDateField(object, FixedTemp(r1), instr->index()); | 1711 left = UseRegisterAtStart(instr->BetterLeftOperand()); |
| 1759 return MarkAsCall(DefineFixed(result, r0), instr, CAN_DEOPTIMIZE_EAGERLY); | 1712 right = UseRegisterOrConstantAtStart(instr->BetterRightOperand()); |
| 1760 } | 1713 } else { |
| 1761 | 1714 ASSERT(instr->representation().IsDouble()); |
| 1762 | 1715 ASSERT(instr->left()->representation().IsDouble()); |
| 1763 LInstruction* LChunkBuilder::DoSeqStringGetChar(HSeqStringGetChar* instr) { | 1716 ASSERT(instr->right()->representation().IsDouble()); |
| 1764 LOperand* string = UseRegisterAtStart(instr->string()); | 1717 left = UseRegisterAtStart(instr->left()); |
| 1765 LOperand* index = UseRegisterOrConstantAtStart(instr->index()); | 1718 right = UseRegisterAtStart(instr->right()); |
| 1766 return DefineAsRegister(new(zone()) LSeqStringGetChar(string, index)); | 1719 } |
| 1767 } | 1720 return DefineAsRegister(new(zone()) LMathMinMax(left, right)); |
| 1768 | 1721 } |
| 1769 | 1722 |
| 1770 LInstruction* LChunkBuilder::DoSeqStringSetChar(HSeqStringSetChar* instr) { | 1723 |
| 1771 LOperand* string = UseRegisterAtStart(instr->string()); | 1724 LInstruction* LChunkBuilder::DoMod(HMod* hmod) { |
| 1772 LOperand* index = FLAG_debug_code | 1725 HValue* hleft = hmod->left(); |
| 1773 ? UseRegisterAtStart(instr->index()) | 1726 HValue* hright = hmod->right(); |
| 1774 : UseRegisterOrConstantAtStart(instr->index()); | 1727 |
| 1775 LOperand* value = UseRegisterAtStart(instr->value()); | 1728 // TODO(jbramley): Add smi support. |
| 1776 LOperand* context = FLAG_debug_code ? UseFixed(instr->context(), cp) : NULL; | 1729 if (hmod->representation().IsInteger32()) { |
| 1777 return new(zone()) LSeqStringSetChar(context, string, index, value); | 1730 ASSERT(hleft->representation().IsInteger32()); |
| 1778 } | 1731 ASSERT(hleft->representation().IsInteger32()); |
| 1779 | 1732 LOperand* left_op; |
| 1780 | 1733 LOperand* right_op; |
| 1781 LInstruction* LChunkBuilder::DoBoundsCheck(HBoundsCheck* instr) { | 1734 |
| 1782 LOperand* value = UseRegisterOrConstantAtStart(instr->index()); | 1735 if (hmod->RightIsPowerOf2()) { |
| 1783 LOperand* length = UseRegister(instr->length()); | 1736 left_op = UseRegisterAtStart(hleft); |
| 1784 return AssignEnvironment(new(zone()) LBoundsCheck(value, length)); | 1737 right_op = UseConstant(hright); |
| 1785 } | 1738 } else { |
| 1786 | 1739 right_op = UseRegister(hright); |
| 1787 | 1740 left_op = UseRegister(hleft); |
| 1788 LInstruction* LChunkBuilder::DoBoundsCheckBaseIndexInformation( | 1741 } |
| 1789 HBoundsCheckBaseIndexInformation* instr) { | 1742 |
| 1790 UNREACHABLE(); | 1743 LModI* lmod = new(zone()) LModI(left_op, right_op); |
| 1791 return NULL; | 1744 |
| 1792 } | 1745 if (hmod->right()->CanBeZero() || |
| 1793 | 1746 (hmod->CheckFlag(HValue::kBailoutOnMinusZero) && |
| 1794 | 1747 hmod->left()->CanBeNegative() && hmod->CanBeZero())) { |
| 1795 LInstruction* LChunkBuilder::DoAbnormalExit(HAbnormalExit* instr) { | 1748 AssignEnvironment(lmod); |
| 1796 // The control instruction marking the end of a block that completed | 1749 } |
| 1797 // abruptly (e.g., threw an exception). There is nothing specific to do. | 1750 return DefineAsRegister(lmod); |
| 1798 return NULL; | 1751 |
| 1799 } | 1752 } else if (hmod->representation().IsSmiOrTagged()) { |
| 1800 | 1753 return DoArithmeticT(Token::MOD, hmod); |
| 1801 | 1754 } else { |
| 1802 LInstruction* LChunkBuilder::DoThrow(HThrow* instr) { | 1755 return DoArithmeticD(Token::MOD, hmod); |
| 1756 } |
| 1757 } |
| 1758 |
| 1759 |
| 1760 LInstruction* LChunkBuilder::DoMul(HMul* instr) { |
| 1761 if (instr->representation().IsSmiOrInteger32()) { |
| 1762 ASSERT(instr->left()->representation().Equals(instr->representation())); |
| 1763 ASSERT(instr->right()->representation().Equals(instr->representation())); |
| 1764 |
| 1765 bool can_overflow = instr->CheckFlag(HValue::kCanOverflow); |
| 1766 bool bailout_on_minus_zero = instr->CheckFlag(HValue::kBailoutOnMinusZero); |
| 1767 bool needs_environment = can_overflow || bailout_on_minus_zero; |
| 1768 |
| 1769 HValue* least_const = instr->BetterLeftOperand(); |
| 1770 HValue* most_const = instr->BetterRightOperand(); |
| 1771 |
| 1772 LOperand* left = UseRegisterAtStart(least_const); |
| 1773 |
| 1774 // LMulConstI can handle a subset of constants: |
| 1775 // With support for overflow detection: |
| 1776 // -1, 0, 1, 2 |
| 1777 // Without support for overflow detection: |
| 1778 // 2^n, -(2^n) |
| 1779 // 2^n + 1, -(2^n - 1) |
| 1780 if (most_const->IsConstant()) { |
| 1781 int32_t constant = HConstant::cast(most_const)->Integer32Value(); |
| 1782 int32_t constant_abs = (constant >= 0) ? constant : -constant; |
| 1783 |
| 1784 if (((constant >= -1) && (constant <= 2)) || |
| 1785 (!can_overflow && (IsPowerOf2(constant_abs) || |
| 1786 IsPowerOf2(constant_abs + 1) || |
| 1787 IsPowerOf2(constant_abs - 1)))) { |
| 1788 LConstantOperand* right = UseConstant(most_const); |
| 1789 LMulConstIS* mul = new(zone()) LMulConstIS(left, right); |
| 1790 if (needs_environment) AssignEnvironment(mul); |
| 1791 return DefineAsRegister(mul); |
| 1792 } |
| 1793 } |
| 1794 |
| 1795 // LMulI/S can handle all cases, but it requires that a register is |
| 1796 // allocated for the second operand. |
| 1797 LInstruction* result; |
| 1798 if (instr->representation().IsSmi()) { |
| 1799 // TODO(jbramley/rmcilroy): Fix LMulS so we can UseRegisterAtStart here. |
| 1800 LOperand* right = UseRegister(most_const); |
| 1801 result = DefineAsRegister(new(zone()) LMulS(left, right)); |
| 1802 } else { |
| 1803 LOperand* right = UseRegisterAtStart(most_const); |
| 1804 result = DefineAsRegister(new(zone()) LMulI(left, right)); |
| 1805 } |
| 1806 if (needs_environment) AssignEnvironment(result); |
| 1807 return result; |
| 1808 } else if (instr->representation().IsDouble()) { |
| 1809 return DoArithmeticD(Token::MUL, instr); |
| 1810 } else { |
| 1811 return DoArithmeticT(Token::MUL, instr); |
| 1812 } |
| 1813 } |
| 1814 |
| 1815 |
| 1816 LInstruction* LChunkBuilder::DoOsrEntry(HOsrEntry* instr) { |
| 1817 ASSERT(argument_count_ == 0); |
| 1818 allocator_->MarkAsOsrEntry(); |
| 1819 current_block_->last_environment()->set_ast_id(instr->ast_id()); |
| 1820 return AssignEnvironment(new(zone()) LOsrEntry); |
| 1821 } |
| 1822 |
| 1823 |
| 1824 LInstruction* LChunkBuilder::DoParameter(HParameter* instr) { |
| 1825 LParameter* result = new(zone()) LParameter; |
| 1826 if (instr->kind() == HParameter::STACK_PARAMETER) { |
| 1827 int spill_index = chunk_->GetParameterStackSlot(instr->index()); |
| 1828 return DefineAsSpilled(result, spill_index); |
| 1829 } else { |
| 1830 ASSERT(info()->IsStub()); |
| 1831 CodeStubInterfaceDescriptor* descriptor = |
| 1832 info()->code_stub()->GetInterfaceDescriptor(info()->isolate()); |
| 1833 int index = static_cast<int>(instr->index()); |
| 1834 Register reg = descriptor->GetParameterRegister(index); |
| 1835 return DefineFixed(result, reg); |
| 1836 } |
| 1837 } |
| 1838 |
| 1839 |
| 1840 LInstruction* LChunkBuilder::DoPower(HPower* instr) { |
| 1841 ASSERT(instr->representation().IsDouble()); |
| 1842 // We call a C function for double power. It can't trigger a GC. |
| 1843 // We need to use fixed result register for the call. |
| 1844 Representation exponent_type = instr->right()->representation(); |
| 1845 ASSERT(instr->left()->representation().IsDouble()); |
| 1846 LOperand* left = UseFixedDouble(instr->left(), d0); |
| 1847 LOperand* right = exponent_type.IsInteger32() |
| 1848 ? UseFixed(instr->right(), x12) |
| 1849 : exponent_type.IsDouble() |
| 1850 ? UseFixedDouble(instr->right(), d1) |
| 1851 : UseFixed(instr->right(), x11); |
| 1852 LPower* result = new(zone()) LPower(left, right); |
| 1853 return MarkAsCall(DefineFixedDouble(result, d0), |
| 1854 instr, |
| 1855 CAN_DEOPTIMIZE_EAGERLY); |
| 1856 } |
| 1857 |
| 1858 |
| 1859 LInstruction* LChunkBuilder::DoPushArgument(HPushArgument* instr) { |
| 1860 LOperand* argument = UseRegister(instr->argument()); |
| 1861 return new(zone()) LPushArgument(argument); |
| 1862 } |
| 1863 |
| 1864 |
| 1865 LInstruction* LChunkBuilder::DoRegExpLiteral(HRegExpLiteral* instr) { |
| 1803 LOperand* context = UseFixed(instr->context(), cp); | 1866 LOperand* context = UseFixed(instr->context(), cp); |
| 1804 LOperand* value = UseFixed(instr->value(), r0); | 1867 return MarkAsCall( |
| 1805 return MarkAsCall(new(zone()) LThrow(context, value), instr); | 1868 DefineFixed(new(zone()) LRegExpLiteral(context), x0), instr); |
| 1806 } | 1869 } |
| 1807 | 1870 |
| 1808 | 1871 |
| 1809 LInstruction* LChunkBuilder::DoUseConst(HUseConst* instr) { | |
| 1810 return NULL; | |
| 1811 } | |
| 1812 | |
| 1813 | |
| 1814 LInstruction* LChunkBuilder::DoForceRepresentation(HForceRepresentation* bad) { | |
| 1815 // All HForceRepresentation instructions should be eliminated in the | |
| 1816 // representation change phase of Hydrogen. | |
| 1817 UNREACHABLE(); | |
| 1818 return NULL; | |
| 1819 } | |
| 1820 | |
| 1821 | |
| 1822 LInstruction* LChunkBuilder::DoChange(HChange* instr) { | |
| 1823 Representation from = instr->from(); | |
| 1824 Representation to = instr->to(); | |
| 1825 if (from.IsSmi()) { | |
| 1826 if (to.IsTagged()) { | |
| 1827 LOperand* value = UseRegister(instr->value()); | |
| 1828 return DefineSameAsFirst(new(zone()) LDummyUse(value)); | |
| 1829 } | |
| 1830 from = Representation::Tagged(); | |
| 1831 } | |
| 1832 if (from.IsTagged()) { | |
| 1833 if (to.IsDouble()) { | |
| 1834 LOperand* value = UseRegister(instr->value()); | |
| 1835 LNumberUntagD* res = new(zone()) LNumberUntagD(value); | |
| 1836 return AssignEnvironment(DefineAsRegister(res)); | |
| 1837 } else if (to.IsSmi()) { | |
| 1838 HValue* val = instr->value(); | |
| 1839 LOperand* value = UseRegister(val); | |
| 1840 if (val->type().IsSmi()) { | |
| 1841 return DefineSameAsFirst(new(zone()) LDummyUse(value)); | |
| 1842 } | |
| 1843 return AssignEnvironment(DefineSameAsFirst(new(zone()) LCheckSmi(value))); | |
| 1844 } else { | |
| 1845 ASSERT(to.IsInteger32()); | |
| 1846 LOperand* value = NULL; | |
| 1847 LInstruction* res = NULL; | |
| 1848 HValue* val = instr->value(); | |
| 1849 if (val->type().IsSmi() || val->representation().IsSmi()) { | |
| 1850 value = UseRegisterAtStart(val); | |
| 1851 res = DefineAsRegister(new(zone()) LSmiUntag(value, false)); | |
| 1852 } else { | |
| 1853 value = UseRegister(val); | |
| 1854 LOperand* temp1 = TempRegister(); | |
| 1855 LOperand* temp2 = FixedTemp(d11); | |
| 1856 res = DefineSameAsFirst(new(zone()) LTaggedToI(value, | |
| 1857 temp1, | |
| 1858 temp2)); | |
| 1859 res = AssignEnvironment(res); | |
| 1860 } | |
| 1861 return res; | |
| 1862 } | |
| 1863 } else if (from.IsDouble()) { | |
| 1864 if (to.IsTagged()) { | |
| 1865 info()->MarkAsDeferredCalling(); | |
| 1866 LOperand* value = UseRegister(instr->value()); | |
| 1867 LOperand* temp1 = TempRegister(); | |
| 1868 LOperand* temp2 = TempRegister(); | |
| 1869 | |
| 1870 // Make sure that the temp and result_temp registers are | |
| 1871 // different. | |
| 1872 LUnallocated* result_temp = TempRegister(); | |
| 1873 LNumberTagD* result = new(zone()) LNumberTagD(value, temp1, temp2); | |
| 1874 Define(result, result_temp); | |
| 1875 return AssignPointerMap(result); | |
| 1876 } else if (to.IsSmi()) { | |
| 1877 LOperand* value = UseRegister(instr->value()); | |
| 1878 return AssignEnvironment( | |
| 1879 DefineAsRegister(new(zone()) LDoubleToSmi(value))); | |
| 1880 } else { | |
| 1881 ASSERT(to.IsInteger32()); | |
| 1882 LOperand* value = UseRegister(instr->value()); | |
| 1883 LDoubleToI* res = new(zone()) LDoubleToI(value); | |
| 1884 return AssignEnvironment(DefineAsRegister(res)); | |
| 1885 } | |
| 1886 } else if (from.IsInteger32()) { | |
| 1887 info()->MarkAsDeferredCalling(); | |
| 1888 if (to.IsTagged()) { | |
| 1889 HValue* val = instr->value(); | |
| 1890 LOperand* value = UseRegisterAtStart(val); | |
| 1891 if (val->CheckFlag(HInstruction::kUint32)) { | |
| 1892 LNumberTagU* result = new(zone()) LNumberTagU(value); | |
| 1893 return AssignEnvironment(AssignPointerMap(DefineAsRegister(result))); | |
| 1894 } else if (val->HasRange() && val->range()->IsInSmiRange()) { | |
| 1895 return DefineAsRegister(new(zone()) LSmiTag(value)); | |
| 1896 } else { | |
| 1897 LNumberTagI* result = new(zone()) LNumberTagI(value); | |
| 1898 return AssignEnvironment(AssignPointerMap(DefineAsRegister(result))); | |
| 1899 } | |
| 1900 } else if (to.IsSmi()) { | |
| 1901 HValue* val = instr->value(); | |
| 1902 LOperand* value = UseRegister(val); | |
| 1903 LInstruction* result = val->CheckFlag(HInstruction::kUint32) | |
| 1904 ? DefineAsRegister(new(zone()) LUint32ToSmi(value)) | |
| 1905 : DefineAsRegister(new(zone()) LInteger32ToSmi(value)); | |
| 1906 if (val->HasRange() && val->range()->IsInSmiRange()) { | |
| 1907 return result; | |
| 1908 } | |
| 1909 return AssignEnvironment(result); | |
| 1910 } else { | |
| 1911 ASSERT(to.IsDouble()); | |
| 1912 if (instr->value()->CheckFlag(HInstruction::kUint32)) { | |
| 1913 return DefineAsRegister( | |
| 1914 new(zone()) LUint32ToDouble(UseRegister(instr->value()))); | |
| 1915 } else { | |
| 1916 return DefineAsRegister( | |
| 1917 new(zone()) LInteger32ToDouble(Use(instr->value()))); | |
| 1918 } | |
| 1919 } | |
| 1920 } | |
| 1921 UNREACHABLE(); | |
| 1922 return NULL; | |
| 1923 } | |
| 1924 | |
| 1925 | |
| 1926 LInstruction* LChunkBuilder::DoCheckHeapObject(HCheckHeapObject* instr) { | |
| 1927 LOperand* value = UseRegisterAtStart(instr->value()); | |
| 1928 return AssignEnvironment(new(zone()) LCheckNonSmi(value)); | |
| 1929 } | |
| 1930 | |
| 1931 | |
| 1932 LInstruction* LChunkBuilder::DoCheckSmi(HCheckSmi* instr) { | |
| 1933 LOperand* value = UseRegisterAtStart(instr->value()); | |
| 1934 return AssignEnvironment(new(zone()) LCheckSmi(value)); | |
| 1935 } | |
| 1936 | |
| 1937 | |
| 1938 LInstruction* LChunkBuilder::DoCheckInstanceType(HCheckInstanceType* instr) { | |
| 1939 LOperand* value = UseRegisterAtStart(instr->value()); | |
| 1940 LInstruction* result = new(zone()) LCheckInstanceType(value); | |
| 1941 return AssignEnvironment(result); | |
| 1942 } | |
| 1943 | |
| 1944 | |
| 1945 LInstruction* LChunkBuilder::DoCheckValue(HCheckValue* instr) { | |
| 1946 LOperand* value = UseRegisterAtStart(instr->value()); | |
| 1947 return AssignEnvironment(new(zone()) LCheckValue(value)); | |
| 1948 } | |
| 1949 | |
| 1950 | |
| 1951 LInstruction* LChunkBuilder::DoCheckMaps(HCheckMaps* instr) { | |
| 1952 LOperand* value = NULL; | |
| 1953 if (!instr->CanOmitMapChecks()) { | |
| 1954 value = UseRegisterAtStart(instr->value()); | |
| 1955 if (instr->has_migration_target()) info()->MarkAsDeferredCalling(); | |
| 1956 } | |
| 1957 LCheckMaps* result = new(zone()) LCheckMaps(value); | |
| 1958 if (!instr->CanOmitMapChecks()) { | |
| 1959 AssignEnvironment(result); | |
| 1960 if (instr->has_migration_target()) return AssignPointerMap(result); | |
| 1961 } | |
| 1962 return result; | |
| 1963 } | |
| 1964 | |
| 1965 | |
| 1966 LInstruction* LChunkBuilder::DoClampToUint8(HClampToUint8* instr) { | |
| 1967 HValue* value = instr->value(); | |
| 1968 Representation input_rep = value->representation(); | |
| 1969 LOperand* reg = UseRegister(value); | |
| 1970 if (input_rep.IsDouble()) { | |
| 1971 return DefineAsRegister(new(zone()) LClampDToUint8(reg)); | |
| 1972 } else if (input_rep.IsInteger32()) { | |
| 1973 return DefineAsRegister(new(zone()) LClampIToUint8(reg)); | |
| 1974 } else { | |
| 1975 ASSERT(input_rep.IsSmiOrTagged()); | |
| 1976 // Register allocator doesn't (yet) support allocation of double | |
| 1977 // temps. Reserve d1 explicitly. | |
| 1978 LClampTToUint8* result = new(zone()) LClampTToUint8(reg, FixedTemp(d11)); | |
| 1979 return AssignEnvironment(DefineAsRegister(result)); | |
| 1980 } | |
| 1981 } | |
| 1982 | |
| 1983 | |
| 1984 LInstruction* LChunkBuilder::DoReturn(HReturn* instr) { | 1872 LInstruction* LChunkBuilder::DoReturn(HReturn* instr) { |
| 1985 LOperand* context = info()->IsStub() | 1873 LOperand* context = info()->IsStub() |
| 1986 ? UseFixed(instr->context(), cp) | 1874 ? UseFixed(instr->context(), cp) |
| 1987 : NULL; | 1875 : NULL; |
| 1988 LOperand* parameter_count = UseRegisterOrConstant(instr->parameter_count()); | 1876 LOperand* parameter_count = UseRegisterOrConstant(instr->parameter_count()); |
| 1989 return new(zone()) LReturn(UseFixed(instr->value(), r0), context, | 1877 return new(zone()) LReturn(UseFixed(instr->value(), x0), context, |
| 1990 parameter_count); | 1878 parameter_count); |
| 1991 } | 1879 } |
| 1992 | 1880 |
| 1993 | 1881 |
| 1994 LInstruction* LChunkBuilder::DoConstant(HConstant* instr) { | 1882 LInstruction* LChunkBuilder::DoSeqStringGetChar(HSeqStringGetChar* instr) { |
| 1995 Representation r = instr->representation(); | 1883 // TODO(all): Use UseRegisterAtStart and UseRegisterOrConstantAtStart here. |
| 1996 if (r.IsSmi()) { | 1884 // We cannot do it now because the debug code in the implementation changes |
| 1997 return DefineAsRegister(new(zone()) LConstantS); | 1885 // temp. |
| 1998 } else if (r.IsInteger32()) { | 1886 LOperand* string = UseRegister(instr->string()); |
| 1999 return DefineAsRegister(new(zone()) LConstantI); | 1887 LOperand* index = UseRegisterOrConstant(instr->index()); |
| 2000 } else if (r.IsDouble()) { | 1888 LOperand* temp = TempRegister(); |
| 2001 return DefineAsRegister(new(zone()) LConstantD); | 1889 LSeqStringGetChar* result = |
| 2002 } else if (r.IsExternal()) { | 1890 new(zone()) LSeqStringGetChar(string, index, temp); |
| 2003 return DefineAsRegister(new(zone()) LConstantE); | 1891 return DefineAsRegister(result); |
| 2004 } else if (r.IsTagged()) { | 1892 } |
| 2005 return DefineAsRegister(new(zone()) LConstantT); | 1893 |
| 2006 } else { | 1894 |
| 2007 UNREACHABLE(); | 1895 LInstruction* LChunkBuilder::DoSeqStringSetChar(HSeqStringSetChar* instr) { |
| 2008 return NULL; | 1896 LOperand* string = UseRegister(instr->string()); |
| 2009 } | 1897 LOperand* index = FLAG_debug_code |
| 2010 } | 1898 ? UseRegister(instr->index()) |
| 2011 | 1899 : UseRegisterOrConstant(instr->index()); |
| 2012 | |
| 2013 LInstruction* LChunkBuilder::DoLoadGlobalCell(HLoadGlobalCell* instr) { | |
| 2014 LLoadGlobalCell* result = new(zone()) LLoadGlobalCell; | |
| 2015 return instr->RequiresHoleCheck() | |
| 2016 ? AssignEnvironment(DefineAsRegister(result)) | |
| 2017 : DefineAsRegister(result); | |
| 2018 } | |
| 2019 | |
| 2020 | |
| 2021 LInstruction* LChunkBuilder::DoLoadGlobalGeneric(HLoadGlobalGeneric* instr) { | |
| 2022 LOperand* context = UseFixed(instr->context(), cp); | |
| 2023 LOperand* global_object = UseFixed(instr->global_object(), r0); | |
| 2024 LLoadGlobalGeneric* result = | |
| 2025 new(zone()) LLoadGlobalGeneric(context, global_object); | |
| 2026 return MarkAsCall(DefineFixed(result, r0), instr); | |
| 2027 } | |
| 2028 | |
| 2029 | |
| 2030 LInstruction* LChunkBuilder::DoStoreGlobalCell(HStoreGlobalCell* instr) { | |
| 2031 LOperand* value = UseRegister(instr->value()); | 1900 LOperand* value = UseRegister(instr->value()); |
| 2032 // Use a temp to check the value in the cell in the case where we perform | 1901 LOperand* context = FLAG_debug_code ? UseFixed(instr->context(), cp) : NULL; |
| 2033 // a hole check. | 1902 LOperand* temp = TempRegister(); |
| 2034 return instr->RequiresHoleCheck() | 1903 LSeqStringSetChar* result = |
| 2035 ? AssignEnvironment(new(zone()) LStoreGlobalCell(value, TempRegister())) | 1904 new(zone()) LSeqStringSetChar(context, string, index, value, temp); |
| 2036 : new(zone()) LStoreGlobalCell(value, NULL); | 1905 return DefineAsRegister(result); |
| 2037 } | 1906 } |
| 2038 | 1907 |
| 2039 | 1908 |
| 2040 LInstruction* LChunkBuilder::DoLoadContextSlot(HLoadContextSlot* instr) { | 1909 LInstruction* LChunkBuilder::DoShift(Token::Value op, |
| 2041 LOperand* context = UseRegisterAtStart(instr->value()); | 1910 HBitwiseBinaryOperation* instr) { |
| 2042 LInstruction* result = | 1911 if (instr->representation().IsTagged()) { |
| 2043 DefineAsRegister(new(zone()) LLoadContextSlot(context)); | 1912 return DoArithmeticT(op, instr); |
| 2044 return instr->RequiresHoleCheck() ? AssignEnvironment(result) : result; | 1913 } |
| 1914 |
| 1915 ASSERT(instr->representation().IsInteger32() || |
| 1916 instr->representation().IsSmi()); |
| 1917 ASSERT(instr->left()->representation().Equals(instr->representation())); |
| 1918 ASSERT(instr->right()->representation().Equals(instr->representation())); |
| 1919 |
| 1920 LOperand* left = instr->representation().IsSmi() |
| 1921 ? UseRegister(instr->left()) |
| 1922 : UseRegisterAtStart(instr->left()); |
| 1923 |
| 1924 HValue* right_value = instr->right(); |
| 1925 LOperand* right = NULL; |
| 1926 LOperand* temp = NULL; |
| 1927 int constant_value = 0; |
| 1928 if (right_value->IsConstant()) { |
| 1929 right = UseConstant(right_value); |
| 1930 HConstant* constant = HConstant::cast(right_value); |
| 1931 constant_value = constant->Integer32Value() & 0x1f; |
| 1932 } else { |
| 1933 right = UseRegisterAtStart(right_value); |
| 1934 if (op == Token::ROR) { |
| 1935 temp = TempRegister(); |
| 1936 } |
| 1937 } |
| 1938 |
| 1939 // Shift operations can only deoptimize if we do a logical shift by 0 and the |
| 1940 // result cannot be truncated to int32. |
| 1941 bool does_deopt = false; |
| 1942 if ((op == Token::SHR) && (constant_value == 0)) { |
| 1943 if (FLAG_opt_safe_uint32_operations) { |
| 1944 does_deopt = !instr->CheckFlag(HInstruction::kUint32); |
| 1945 } else { |
| 1946 does_deopt = !instr->CheckUsesForFlag(HValue::kTruncatingToInt32); |
| 1947 } |
| 1948 } |
| 1949 |
| 1950 LInstruction* result; |
| 1951 if (instr->representation().IsInteger32()) { |
| 1952 result = DefineAsRegister(new(zone()) LShiftI(op, left, right, does_deopt)); |
| 1953 } else { |
| 1954 ASSERT(instr->representation().IsSmi()); |
| 1955 result = DefineAsRegister( |
| 1956 new(zone()) LShiftS(op, left, right, temp, does_deopt)); |
| 1957 } |
| 1958 |
| 1959 return does_deopt ? AssignEnvironment(result) : result; |
| 1960 } |
| 1961 |
| 1962 |
| 1963 LInstruction* LChunkBuilder::DoRor(HRor* instr) { |
| 1964 return DoShift(Token::ROR, instr); |
| 1965 } |
| 1966 |
| 1967 |
| 1968 LInstruction* LChunkBuilder::DoSar(HSar* instr) { |
| 1969 return DoShift(Token::SAR, instr); |
| 1970 } |
| 1971 |
| 1972 |
| 1973 LInstruction* LChunkBuilder::DoShl(HShl* instr) { |
| 1974 return DoShift(Token::SHL, instr); |
| 1975 } |
| 1976 |
| 1977 |
| 1978 LInstruction* LChunkBuilder::DoShr(HShr* instr) { |
| 1979 return DoShift(Token::SHR, instr); |
| 1980 } |
| 1981 |
| 1982 |
| 1983 LInstruction* LChunkBuilder::DoSimulate(HSimulate* instr) { |
| 1984 instr->ReplayEnvironment(current_block_->last_environment()); |
| 1985 |
| 1986 // If there is an instruction pending deoptimization environment create a |
| 1987 // lazy bailout instruction to capture the environment. |
| 1988 if (pending_deoptimization_ast_id_ == instr->ast_id()) { |
| 1989 LInstruction* result = new(zone()) LLazyBailout; |
| 1990 result = AssignEnvironment(result); |
| 1991 // Store the lazy deopt environment with the instruction if needed. Right |
| 1992 // now it is only used for LInstanceOfKnownGlobal. |
| 1993 instruction_pending_deoptimization_environment_-> |
| 1994 SetDeferredLazyDeoptimizationEnvironment(result->environment()); |
| 1995 instruction_pending_deoptimization_environment_ = NULL; |
| 1996 pending_deoptimization_ast_id_ = BailoutId::None(); |
| 1997 return result; |
| 1998 } |
| 1999 |
| 2000 return NULL; |
| 2001 } |
| 2002 |
| 2003 |
| 2004 LInstruction* LChunkBuilder::DoStackCheck(HStackCheck* instr) { |
| 2005 if (instr->is_function_entry()) { |
| 2006 LOperand* context = UseFixed(instr->context(), cp); |
| 2007 return MarkAsCall(new(zone()) LStackCheck(context), instr); |
| 2008 } else { |
| 2009 ASSERT(instr->is_backwards_branch()); |
| 2010 LOperand* context = UseAny(instr->context()); |
| 2011 return AssignEnvironment( |
| 2012 AssignPointerMap(new(zone()) LStackCheck(context))); |
| 2013 } |
| 2014 } |
| 2015 |
| 2016 |
| 2017 LInstruction* LChunkBuilder::DoStoreCodeEntry(HStoreCodeEntry* instr) { |
| 2018 LOperand* function = UseRegister(instr->function()); |
| 2019 LOperand* code_object = UseRegisterAtStart(instr->code_object()); |
| 2020 LOperand* temp = TempRegister(); |
| 2021 return new(zone()) LStoreCodeEntry(function, code_object, temp); |
| 2045 } | 2022 } |
| 2046 | 2023 |
| 2047 | 2024 |
| 2048 LInstruction* LChunkBuilder::DoStoreContextSlot(HStoreContextSlot* instr) { | 2025 LInstruction* LChunkBuilder::DoStoreContextSlot(HStoreContextSlot* instr) { |
| 2026 LOperand* temp = TempRegister(); |
| 2049 LOperand* context; | 2027 LOperand* context; |
| 2050 LOperand* value; | 2028 LOperand* value; |
| 2051 if (instr->NeedsWriteBarrier()) { | 2029 if (instr->NeedsWriteBarrier()) { |
| 2052 context = UseTempRegister(instr->context()); | 2030 // TODO(all): Replace these constraints when RecordWriteStub has been |
| 2053 value = UseTempRegister(instr->value()); | 2031 // rewritten. |
| 2032 context = UseRegisterAndClobber(instr->context()); |
| 2033 value = UseRegisterAndClobber(instr->value()); |
| 2054 } else { | 2034 } else { |
| 2055 context = UseRegister(instr->context()); | 2035 context = UseRegister(instr->context()); |
| 2056 value = UseRegister(instr->value()); | 2036 value = UseRegister(instr->value()); |
| 2057 } | 2037 } |
| 2058 LInstruction* result = new(zone()) LStoreContextSlot(context, value); | 2038 LInstruction* result = new(zone()) LStoreContextSlot(context, value, temp); |
| 2059 return instr->RequiresHoleCheck() ? AssignEnvironment(result) : result; | 2039 return instr->RequiresHoleCheck() ? AssignEnvironment(result) : result; |
| 2060 } | 2040 } |
| 2061 | 2041 |
| 2062 | 2042 |
| 2063 LInstruction* LChunkBuilder::DoLoadNamedField(HLoadNamedField* instr) { | 2043 LInstruction* LChunkBuilder::DoStoreGlobalCell(HStoreGlobalCell* instr) { |
| 2064 LOperand* obj = UseRegisterAtStart(instr->object()); | 2044 LOperand* value = UseRegister(instr->value()); |
| 2065 return DefineAsRegister(new(zone()) LLoadNamedField(obj)); | 2045 if (instr->RequiresHoleCheck()) { |
| 2066 } | 2046 return AssignEnvironment(new(zone()) LStoreGlobalCell(value, |
| 2067 | 2047 TempRegister(), |
| 2068 | 2048 TempRegister())); |
| 2069 LInstruction* LChunkBuilder::DoLoadNamedGeneric(HLoadNamedGeneric* instr) { | 2049 } else { |
| 2070 LOperand* context = UseFixed(instr->context(), cp); | 2050 return new(zone()) LStoreGlobalCell(value, TempRegister(), NULL); |
| 2071 LOperand* object = UseFixed(instr->object(), r0); | 2051 } |
| 2072 LInstruction* result = | |
| 2073 DefineFixed(new(zone()) LLoadNamedGeneric(context, object), r0); | |
| 2074 return MarkAsCall(result, instr); | |
| 2075 } | |
| 2076 | |
| 2077 | |
| 2078 LInstruction* LChunkBuilder::DoLoadFunctionPrototype( | |
| 2079 HLoadFunctionPrototype* instr) { | |
| 2080 return AssignEnvironment(DefineAsRegister( | |
| 2081 new(zone()) LLoadFunctionPrototype(UseRegister(instr->function())))); | |
| 2082 } | |
| 2083 | |
| 2084 | |
| 2085 LInstruction* LChunkBuilder::DoLoadRoot(HLoadRoot* instr) { | |
| 2086 return DefineAsRegister(new(zone()) LLoadRoot); | |
| 2087 } | |
| 2088 | |
| 2089 | |
| 2090 LInstruction* LChunkBuilder::DoLoadExternalArrayPointer( | |
| 2091 HLoadExternalArrayPointer* instr) { | |
| 2092 LOperand* input = UseRegisterAtStart(instr->value()); | |
| 2093 return DefineAsRegister(new(zone()) LLoadExternalArrayPointer(input)); | |
| 2094 } | |
| 2095 | |
| 2096 | |
| 2097 LInstruction* LChunkBuilder::DoLoadKeyed(HLoadKeyed* instr) { | |
| 2098 ASSERT(instr->key()->representation().IsSmiOrInteger32()); | |
| 2099 ElementsKind elements_kind = instr->elements_kind(); | |
| 2100 LOperand* key = UseRegisterOrConstantAtStart(instr->key()); | |
| 2101 LLoadKeyed* result = NULL; | |
| 2102 | |
| 2103 if (!instr->is_typed_elements()) { | |
| 2104 LOperand* obj = NULL; | |
| 2105 if (instr->representation().IsDouble()) { | |
| 2106 obj = UseRegister(instr->elements()); | |
| 2107 } else { | |
| 2108 ASSERT(instr->representation().IsSmiOrTagged()); | |
| 2109 obj = UseRegisterAtStart(instr->elements()); | |
| 2110 } | |
| 2111 result = new(zone()) LLoadKeyed(obj, key); | |
| 2112 } else { | |
| 2113 ASSERT( | |
| 2114 (instr->representation().IsInteger32() && | |
| 2115 !IsDoubleOrFloatElementsKind(instr->elements_kind())) || | |
| 2116 (instr->representation().IsDouble() && | |
| 2117 IsDoubleOrFloatElementsKind(instr->elements_kind()))); | |
| 2118 LOperand* backing_store = UseRegister(instr->elements()); | |
| 2119 result = new(zone()) LLoadKeyed(backing_store, key); | |
| 2120 } | |
| 2121 | |
| 2122 DefineAsRegister(result); | |
| 2123 // An unsigned int array load might overflow and cause a deopt, make sure it | |
| 2124 // has an environment. | |
| 2125 bool can_deoptimize = instr->RequiresHoleCheck() || | |
| 2126 elements_kind == EXTERNAL_UNSIGNED_INT_ELEMENTS || | |
| 2127 elements_kind == UINT32_ELEMENTS; | |
| 2128 return can_deoptimize ? AssignEnvironment(result) : result; | |
| 2129 } | |
| 2130 | |
| 2131 | |
| 2132 LInstruction* LChunkBuilder::DoLoadKeyedGeneric(HLoadKeyedGeneric* instr) { | |
| 2133 LOperand* context = UseFixed(instr->context(), cp); | |
| 2134 LOperand* object = UseFixed(instr->object(), r1); | |
| 2135 LOperand* key = UseFixed(instr->key(), r0); | |
| 2136 | |
| 2137 LInstruction* result = | |
| 2138 DefineFixed(new(zone()) LLoadKeyedGeneric(context, object, key), r0); | |
| 2139 return MarkAsCall(result, instr); | |
| 2140 } | 2052 } |
| 2141 | 2053 |
| 2142 | 2054 |
| 2143 LInstruction* LChunkBuilder::DoStoreKeyed(HStoreKeyed* instr) { | 2055 LInstruction* LChunkBuilder::DoStoreKeyed(HStoreKeyed* instr) { |
| 2144 if (!instr->is_typed_elements()) { | 2056 LOperand* temp = NULL; |
| 2057 LOperand* elements = NULL; |
| 2058 LOperand* val = NULL; |
| 2059 LOperand* key = NULL; |
| 2060 |
| 2061 if (!instr->is_typed_elements() && |
| 2062 instr->value()->representation().IsTagged() && |
| 2063 instr->NeedsWriteBarrier()) { |
| 2064 // RecordWrite() will clobber all registers. |
| 2065 elements = UseRegisterAndClobber(instr->elements()); |
| 2066 val = UseRegisterAndClobber(instr->value()); |
| 2067 key = UseRegisterAndClobber(instr->key()); |
| 2068 } else { |
| 2069 elements = UseRegister(instr->elements()); |
| 2070 val = UseRegister(instr->value()); |
| 2071 key = UseRegisterOrConstantAtStart(instr->key()); |
| 2072 } |
| 2073 |
| 2074 if (instr->is_typed_elements()) { |
| 2075 ASSERT((instr->value()->representation().IsInteger32() && |
| 2076 !IsDoubleOrFloatElementsKind(instr->elements_kind())) || |
| 2077 (instr->value()->representation().IsDouble() && |
| 2078 IsDoubleOrFloatElementsKind(instr->elements_kind()))); |
| 2079 ASSERT((instr->is_fixed_typed_array() && |
| 2080 instr->elements()->representation().IsTagged()) || |
| 2081 (instr->is_external() && |
| 2082 instr->elements()->representation().IsExternal())); |
| 2083 temp = instr->key()->IsConstant() ? NULL : TempRegister(); |
| 2084 return new(zone()) LStoreKeyedExternal(elements, key, val, temp); |
| 2085 |
| 2086 } else if (instr->value()->representation().IsDouble()) { |
| 2145 ASSERT(instr->elements()->representation().IsTagged()); | 2087 ASSERT(instr->elements()->representation().IsTagged()); |
| 2146 bool needs_write_barrier = instr->NeedsWriteBarrier(); | 2088 |
| 2147 LOperand* object = NULL; | 2089 // The constraint used here is UseRegister, even though the StoreKeyed |
| 2148 LOperand* key = NULL; | 2090 // instruction may canonicalize the value in the register if it is a NaN. |
| 2149 LOperand* val = NULL; | 2091 temp = TempRegister(); |
| 2150 | 2092 return new(zone()) LStoreKeyedFixedDouble(elements, key, val, temp); |
| 2151 if (instr->value()->representation().IsDouble()) { | 2093 |
| 2152 object = UseRegisterAtStart(instr->elements()); | 2094 } else { |
| 2153 val = UseRegister(instr->value()); | 2095 ASSERT(instr->elements()->representation().IsTagged()); |
| 2154 key = UseRegisterOrConstantAtStart(instr->key()); | 2096 ASSERT(instr->value()->representation().IsSmiOrTagged() || |
| 2155 } else { | 2097 instr->value()->representation().IsInteger32()); |
| 2156 ASSERT(instr->value()->representation().IsSmiOrTagged()); | 2098 |
| 2157 if (needs_write_barrier) { | 2099 temp = TempRegister(); |
| 2158 object = UseTempRegister(instr->elements()); | 2100 return new(zone()) LStoreKeyedFixed(elements, key, val, temp); |
| 2159 val = UseTempRegister(instr->value()); | 2101 } |
| 2160 key = UseTempRegister(instr->key()); | |
| 2161 } else { | |
| 2162 object = UseRegisterAtStart(instr->elements()); | |
| 2163 val = UseRegisterAtStart(instr->value()); | |
| 2164 key = UseRegisterOrConstantAtStart(instr->key()); | |
| 2165 } | |
| 2166 } | |
| 2167 | |
| 2168 return new(zone()) LStoreKeyed(object, key, val); | |
| 2169 } | |
| 2170 | |
| 2171 ASSERT( | |
| 2172 (instr->value()->representation().IsInteger32() && | |
| 2173 !IsDoubleOrFloatElementsKind(instr->elements_kind())) || | |
| 2174 (instr->value()->representation().IsDouble() && | |
| 2175 IsDoubleOrFloatElementsKind(instr->elements_kind()))); | |
| 2176 ASSERT((instr->is_fixed_typed_array() && | |
| 2177 instr->elements()->representation().IsTagged()) || | |
| 2178 (instr->is_external() && | |
| 2179 instr->elements()->representation().IsExternal())); | |
| 2180 LOperand* val = UseRegister(instr->value()); | |
| 2181 LOperand* key = UseRegisterOrConstantAtStart(instr->key()); | |
| 2182 LOperand* backing_store = UseRegister(instr->elements()); | |
| 2183 return new(zone()) LStoreKeyed(backing_store, key, val); | |
| 2184 } | 2102 } |
| 2185 | 2103 |
| 2186 | 2104 |
| 2187 LInstruction* LChunkBuilder::DoStoreKeyedGeneric(HStoreKeyedGeneric* instr) { | 2105 LInstruction* LChunkBuilder::DoStoreKeyedGeneric(HStoreKeyedGeneric* instr) { |
| 2188 LOperand* context = UseFixed(instr->context(), cp); | 2106 LOperand* context = UseFixed(instr->context(), cp); |
| 2189 LOperand* obj = UseFixed(instr->object(), r2); | 2107 LOperand* object = UseFixed(instr->object(), x2); |
| 2190 LOperand* key = UseFixed(instr->key(), r1); | 2108 LOperand* key = UseFixed(instr->key(), x1); |
| 2191 LOperand* val = UseFixed(instr->value(), r0); | 2109 LOperand* value = UseFixed(instr->value(), x0); |
| 2192 | 2110 |
| 2193 ASSERT(instr->object()->representation().IsTagged()); | 2111 ASSERT(instr->object()->representation().IsTagged()); |
| 2194 ASSERT(instr->key()->representation().IsTagged()); | 2112 ASSERT(instr->key()->representation().IsTagged()); |
| 2195 ASSERT(instr->value()->representation().IsTagged()); | 2113 ASSERT(instr->value()->representation().IsTagged()); |
| 2196 | 2114 |
| 2197 return MarkAsCall( | 2115 return MarkAsCall( |
| 2198 new(zone()) LStoreKeyedGeneric(context, obj, key, val), instr); | 2116 new(zone()) LStoreKeyedGeneric(context, object, key, value), instr); |
| 2199 } | 2117 } |
| 2200 | 2118 |
| 2201 | 2119 |
| 2202 LInstruction* LChunkBuilder::DoTransitionElementsKind( | 2120 LInstruction* LChunkBuilder::DoStoreNamedField(HStoreNamedField* instr) { |
| 2203 HTransitionElementsKind* instr) { | 2121 // TODO(jbramley): Optimize register usage in this instruction. For now, it |
| 2122 // allocates everything that it might need because it keeps changing in the |
| 2123 // merge and keeping it valid is time-consuming. |
| 2124 |
| 2125 // TODO(jbramley): It might be beneficial to allow value to be a constant in |
| 2126 // some cases. x64 makes use of this with FLAG_track_fields, for example. |
| 2127 |
| 2204 LOperand* object = UseRegister(instr->object()); | 2128 LOperand* object = UseRegister(instr->object()); |
| 2205 if (IsSimpleMapChangeTransition(instr->from_kind(), instr->to_kind())) { | 2129 LOperand* value = UseRegisterAndClobber(instr->value()); |
| 2206 LOperand* new_map_reg = TempRegister(); | 2130 LOperand* temp0 = TempRegister(); |
| 2207 LTransitionElementsKind* result = | 2131 LOperand* temp1 = TempRegister(); |
| 2208 new(zone()) LTransitionElementsKind(object, NULL, new_map_reg); | 2132 |
| 2209 return result; | 2133 LStoreNamedField* result = |
| 2210 } else { | 2134 new(zone()) LStoreNamedField(object, value, temp0, temp1); |
| 2211 LOperand* context = UseFixed(instr->context(), cp); | |
| 2212 LTransitionElementsKind* result = | |
| 2213 new(zone()) LTransitionElementsKind(object, context, NULL); | |
| 2214 return AssignPointerMap(result); | |
| 2215 } | |
| 2216 } | |
| 2217 | |
| 2218 | |
| 2219 LInstruction* LChunkBuilder::DoTrapAllocationMemento( | |
| 2220 HTrapAllocationMemento* instr) { | |
| 2221 LOperand* object = UseRegister(instr->object()); | |
| 2222 LOperand* temp = TempRegister(); | |
| 2223 LTrapAllocationMemento* result = | |
| 2224 new(zone()) LTrapAllocationMemento(object, temp); | |
| 2225 return AssignEnvironment(result); | |
| 2226 } | |
| 2227 | |
| 2228 | |
| 2229 LInstruction* LChunkBuilder::DoStoreNamedField(HStoreNamedField* instr) { | |
| 2230 bool is_in_object = instr->access().IsInobject(); | |
| 2231 bool needs_write_barrier = instr->NeedsWriteBarrier(); | |
| 2232 bool needs_write_barrier_for_map = instr->has_transition() && | |
| 2233 instr->NeedsWriteBarrierForMap(); | |
| 2234 | |
| 2235 LOperand* obj; | |
| 2236 if (needs_write_barrier) { | |
| 2237 obj = is_in_object | |
| 2238 ? UseRegister(instr->object()) | |
| 2239 : UseTempRegister(instr->object()); | |
| 2240 } else { | |
| 2241 obj = needs_write_barrier_for_map | |
| 2242 ? UseRegister(instr->object()) | |
| 2243 : UseRegisterAtStart(instr->object()); | |
| 2244 } | |
| 2245 | |
| 2246 LOperand* val; | |
| 2247 if (needs_write_barrier || | |
| 2248 (FLAG_track_fields && instr->field_representation().IsSmi())) { | |
| 2249 val = UseTempRegister(instr->value()); | |
| 2250 } else if (FLAG_track_double_fields && | |
| 2251 instr->field_representation().IsDouble()) { | |
| 2252 val = UseRegisterAtStart(instr->value()); | |
| 2253 } else { | |
| 2254 val = UseRegister(instr->value()); | |
| 2255 } | |
| 2256 | |
| 2257 // We need a temporary register for write barrier of the map field. | |
| 2258 LOperand* temp = needs_write_barrier_for_map ? TempRegister() : NULL; | |
| 2259 | |
| 2260 LStoreNamedField* result = new(zone()) LStoreNamedField(obj, val, temp); | |
| 2261 if (FLAG_track_heap_object_fields && | 2135 if (FLAG_track_heap_object_fields && |
| 2262 instr->field_representation().IsHeapObject()) { | 2136 instr->field_representation().IsHeapObject() && |
| 2263 if (!instr->value()->type().IsHeapObject()) { | 2137 !instr->value()->type().IsHeapObject()) { |
| 2264 return AssignEnvironment(result); | 2138 return AssignEnvironment(result); |
| 2265 } | |
| 2266 } | 2139 } |
| 2267 return result; | 2140 return result; |
| 2268 } | 2141 } |
| 2269 | 2142 |
| 2270 | 2143 |
| 2271 LInstruction* LChunkBuilder::DoStoreNamedGeneric(HStoreNamedGeneric* instr) { | 2144 LInstruction* LChunkBuilder::DoStoreNamedGeneric(HStoreNamedGeneric* instr) { |
| 2272 LOperand* context = UseFixed(instr->context(), cp); | 2145 LOperand* context = UseFixed(instr->context(), cp); |
| 2273 LOperand* obj = UseFixed(instr->object(), r1); | 2146 LOperand* object = UseFixed(instr->object(), x1); |
| 2274 LOperand* val = UseFixed(instr->value(), r0); | 2147 LOperand* value = UseFixed(instr->value(), x0); |
| 2275 | 2148 LInstruction* result = new(zone()) LStoreNamedGeneric(context, object, value); |
| 2276 LInstruction* result = new(zone()) LStoreNamedGeneric(context, obj, val); | |
| 2277 return MarkAsCall(result, instr); | 2149 return MarkAsCall(result, instr); |
| 2278 } | 2150 } |
| 2279 | 2151 |
| 2280 | 2152 |
| 2281 LInstruction* LChunkBuilder::DoStringAdd(HStringAdd* instr) { | 2153 LInstruction* LChunkBuilder::DoStringAdd(HStringAdd* instr) { |
| 2282 LOperand* context = UseFixed(instr->context(), cp); | 2154 LOperand* context = UseFixed(instr->context(), cp); |
| 2283 LOperand* left = FLAG_new_string_add | 2155 LOperand* left = UseFixed(instr->left(), x1); |
| 2284 ? UseFixed(instr->left(), r1) | 2156 LOperand* right = UseFixed(instr->right(), x0); |
| 2285 : UseRegisterAtStart(instr->left()); | 2157 |
| 2286 LOperand* right = FLAG_new_string_add | 2158 LStringAdd* result = new(zone()) LStringAdd(context, left, right); |
| 2287 ? UseFixed(instr->right(), r0) | 2159 return MarkAsCall(DefineFixed(result, x0), instr); |
| 2288 : UseRegisterAtStart(instr->right()); | |
| 2289 return MarkAsCall( | |
| 2290 DefineFixed(new(zone()) LStringAdd(context, left, right), r0), | |
| 2291 instr); | |
| 2292 } | 2160 } |
| 2293 | 2161 |
| 2294 | 2162 |
| 2295 LInstruction* LChunkBuilder::DoStringCharCodeAt(HStringCharCodeAt* instr) { | 2163 LInstruction* LChunkBuilder::DoStringCharCodeAt(HStringCharCodeAt* instr) { |
| 2296 LOperand* string = UseTempRegister(instr->string()); | 2164 LOperand* string = UseRegisterAndClobber(instr->string()); |
| 2297 LOperand* index = UseTempRegister(instr->index()); | 2165 LOperand* index = UseRegisterAndClobber(instr->index()); |
| 2298 LOperand* context = UseAny(instr->context()); | 2166 LOperand* context = UseAny(instr->context()); |
| 2299 LStringCharCodeAt* result = | 2167 LStringCharCodeAt* result = |
| 2300 new(zone()) LStringCharCodeAt(context, string, index); | 2168 new(zone()) LStringCharCodeAt(context, string, index); |
| 2301 return AssignEnvironment(AssignPointerMap(DefineAsRegister(result))); | 2169 return AssignEnvironment(AssignPointerMap(DefineAsRegister(result))); |
| 2302 } | 2170 } |
| 2303 | 2171 |
| 2304 | 2172 |
| 2305 LInstruction* LChunkBuilder::DoStringCharFromCode(HStringCharFromCode* instr) { | 2173 LInstruction* LChunkBuilder::DoStringCharFromCode(HStringCharFromCode* instr) { |
| 2174 // TODO(all) use at start and remove assert in codegen |
| 2306 LOperand* char_code = UseRegister(instr->value()); | 2175 LOperand* char_code = UseRegister(instr->value()); |
| 2307 LOperand* context = UseAny(instr->context()); | 2176 LOperand* context = UseAny(instr->context()); |
| 2308 LStringCharFromCode* result = | 2177 LStringCharFromCode* result = |
| 2309 new(zone()) LStringCharFromCode(context, char_code); | 2178 new(zone()) LStringCharFromCode(context, char_code); |
| 2310 return AssignPointerMap(DefineAsRegister(result)); | 2179 return AssignPointerMap(DefineAsRegister(result)); |
| 2311 } | 2180 } |
| 2312 | 2181 |
| 2313 | 2182 |
| 2314 LInstruction* LChunkBuilder::DoAllocate(HAllocate* instr) { | 2183 LInstruction* LChunkBuilder::DoStringCompareAndBranch( |
| 2315 info()->MarkAsDeferredCalling(); | 2184 HStringCompareAndBranch* instr) { |
| 2316 LOperand* context = UseAny(instr->context()); | 2185 ASSERT(instr->left()->representation().IsTagged()); |
| 2317 LOperand* size = instr->size()->IsConstant() | 2186 ASSERT(instr->right()->representation().IsTagged()); |
| 2318 ? UseConstant(instr->size()) | 2187 LOperand* context = UseFixed(instr->context(), cp); |
| 2319 : UseTempRegister(instr->size()); | 2188 LOperand* left = UseFixed(instr->left(), x1); |
| 2320 LOperand* temp1 = TempRegister(); | 2189 LOperand* right = UseFixed(instr->right(), x0); |
| 2321 LOperand* temp2 = TempRegister(); | 2190 LStringCompareAndBranch* result = |
| 2322 LAllocate* result = new(zone()) LAllocate(context, size, temp1, temp2); | 2191 new(zone()) LStringCompareAndBranch(context, left, right); |
| 2323 return AssignPointerMap(DefineAsRegister(result)); | 2192 return MarkAsCall(result, instr); |
| 2324 } | 2193 } |
| 2325 | 2194 |
| 2326 | 2195 |
| 2327 LInstruction* LChunkBuilder::DoRegExpLiteral(HRegExpLiteral* instr) { | 2196 LInstruction* LChunkBuilder::DoSub(HSub* instr) { |
| 2328 LOperand* context = UseFixed(instr->context(), cp); | 2197 if (instr->representation().IsSmiOrInteger32()) { |
| 2329 return MarkAsCall( | 2198 ASSERT(instr->left()->representation().Equals(instr->representation())); |
| 2330 DefineFixed(new(zone()) LRegExpLiteral(context), r0), instr); | 2199 ASSERT(instr->right()->representation().Equals(instr->representation())); |
| 2331 } | 2200 LOperand *left; |
| 2332 | 2201 if (instr->left()->IsConstant() && |
| 2333 | 2202 (HConstant::cast(instr->left())->Integer32Value() == 0)) { |
| 2334 LInstruction* LChunkBuilder::DoFunctionLiteral(HFunctionLiteral* instr) { | 2203 left = UseConstant(instr->left()); |
| 2335 LOperand* context = UseFixed(instr->context(), cp); | 2204 } else { |
| 2336 return MarkAsCall( | 2205 left = UseRegisterAtStart(instr->left()); |
| 2337 DefineFixed(new(zone()) LFunctionLiteral(context), r0), instr); | 2206 } |
| 2338 } | 2207 LOperand* right = UseRegisterOrConstantAtStart(instr->right()); |
| 2339 | 2208 LInstruction* result = instr->representation().IsSmi() ? |
| 2340 | 2209 DefineAsRegister(new(zone()) LSubS(left, right)) : |
| 2341 LInstruction* LChunkBuilder::DoOsrEntry(HOsrEntry* instr) { | 2210 DefineAsRegister(new(zone()) LSubI(left, right)); |
| 2342 ASSERT(argument_count_ == 0); | 2211 if (instr->CheckFlag(HValue::kCanOverflow)) { |
| 2343 allocator_->MarkAsOsrEntry(); | 2212 result = AssignEnvironment(result); |
| 2344 current_block_->last_environment()->set_ast_id(instr->ast_id()); | 2213 } |
| 2345 return AssignEnvironment(new(zone()) LOsrEntry); | 2214 return result; |
| 2346 } | 2215 } else if (instr->representation().IsDouble()) { |
| 2347 | 2216 return DoArithmeticD(Token::SUB, instr); |
| 2348 | |
| 2349 LInstruction* LChunkBuilder::DoParameter(HParameter* instr) { | |
| 2350 LParameter* result = new(zone()) LParameter; | |
| 2351 if (instr->kind() == HParameter::STACK_PARAMETER) { | |
| 2352 int spill_index = chunk()->GetParameterStackSlot(instr->index()); | |
| 2353 return DefineAsSpilled(result, spill_index); | |
| 2354 } else { | 2217 } else { |
| 2355 ASSERT(info()->IsStub()); | 2218 return DoArithmeticT(Token::SUB, instr); |
| 2356 CodeStubInterfaceDescriptor* descriptor = | |
| 2357 info()->code_stub()->GetInterfaceDescriptor(info()->isolate()); | |
| 2358 int index = static_cast<int>(instr->index()); | |
| 2359 Register reg = descriptor->GetParameterRegister(index); | |
| 2360 return DefineFixed(result, reg); | |
| 2361 } | 2219 } |
| 2362 } | 2220 } |
| 2363 | 2221 |
| 2364 | 2222 |
| 2365 LInstruction* LChunkBuilder::DoUnknownOSRValue(HUnknownOSRValue* instr) { | 2223 LInstruction* LChunkBuilder::DoThisFunction(HThisFunction* instr) { |
| 2366 // Use an index that corresponds to the location in the unoptimized frame, | 2224 if (instr->HasNoUses()) { |
| 2367 // which the optimized frame will subsume. | 2225 return NULL; |
| 2368 int env_index = instr->index(); | |
| 2369 int spill_index = 0; | |
| 2370 if (instr->environment()->is_parameter_index(env_index)) { | |
| 2371 spill_index = chunk()->GetParameterStackSlot(env_index); | |
| 2372 } else { | 2226 } else { |
| 2373 spill_index = env_index - instr->environment()->first_local_index(); | 2227 return DefineAsRegister(new(zone()) LThisFunction); |
| 2374 if (spill_index > LUnallocated::kMaxFixedSlotIndex) { | |
| 2375 Abort(kTooManySpillSlotsNeededForOSR); | |
| 2376 spill_index = 0; | |
| 2377 } | |
| 2378 } | 2228 } |
| 2379 return DefineAsSpilled(new(zone()) LUnknownOSRValue, spill_index); | |
| 2380 } | |
| 2381 | |
| 2382 | |
| 2383 LInstruction* LChunkBuilder::DoCallStub(HCallStub* instr) { | |
| 2384 LOperand* context = UseFixed(instr->context(), cp); | |
| 2385 return MarkAsCall(DefineFixed(new(zone()) LCallStub(context), r0), instr); | |
| 2386 } | |
| 2387 | |
| 2388 | |
| 2389 LInstruction* LChunkBuilder::DoArgumentsObject(HArgumentsObject* instr) { | |
| 2390 // There are no real uses of the arguments object. | |
| 2391 // arguments.length and element access are supported directly on | |
| 2392 // stack arguments, and any real arguments object use causes a bailout. | |
| 2393 // So this value is never used. | |
| 2394 return NULL; | |
| 2395 } | |
| 2396 | |
| 2397 | |
| 2398 LInstruction* LChunkBuilder::DoCapturedObject(HCapturedObject* instr) { | |
| 2399 instr->ReplayEnvironment(current_block_->last_environment()); | |
| 2400 | |
| 2401 // There are no real uses of a captured object. | |
| 2402 return NULL; | |
| 2403 } | |
| 2404 | |
| 2405 | |
| 2406 LInstruction* LChunkBuilder::DoAccessArgumentsAt(HAccessArgumentsAt* instr) { | |
| 2407 info()->MarkAsRequiresFrame(); | |
| 2408 LOperand* args = UseRegister(instr->arguments()); | |
| 2409 LOperand* length = UseRegisterOrConstantAtStart(instr->length()); | |
| 2410 LOperand* index = UseRegisterOrConstantAtStart(instr->index()); | |
| 2411 return DefineAsRegister(new(zone()) LAccessArgumentsAt(args, length, index)); | |
| 2412 } | 2229 } |
| 2413 | 2230 |
| 2414 | 2231 |
| 2415 LInstruction* LChunkBuilder::DoToFastProperties(HToFastProperties* instr) { | 2232 LInstruction* LChunkBuilder::DoToFastProperties(HToFastProperties* instr) { |
| 2416 LOperand* object = UseFixed(instr->value(), r0); | 2233 LOperand* object = UseFixed(instr->value(), x0); |
| 2417 LToFastProperties* result = new(zone()) LToFastProperties(object); | 2234 LToFastProperties* result = new(zone()) LToFastProperties(object); |
| 2418 return MarkAsCall(DefineFixed(result, r0), instr); | 2235 return MarkAsCall(DefineFixed(result, x0), instr); |
| 2236 } |
| 2237 |
| 2238 |
| 2239 LInstruction* LChunkBuilder::DoTransitionElementsKind( |
| 2240 HTransitionElementsKind* instr) { |
| 2241 LOperand* object = UseRegister(instr->object()); |
| 2242 if (IsSimpleMapChangeTransition(instr->from_kind(), instr->to_kind())) { |
| 2243 LTransitionElementsKind* result = |
| 2244 new(zone()) LTransitionElementsKind(object, NULL, |
| 2245 TempRegister(), TempRegister()); |
| 2246 return result; |
| 2247 } else { |
| 2248 LOperand* context = UseFixed(instr->context(), cp); |
| 2249 LTransitionElementsKind* result = |
| 2250 new(zone()) LTransitionElementsKind(object, context, TempRegister()); |
| 2251 return AssignPointerMap(result); |
| 2252 } |
| 2253 } |
| 2254 |
| 2255 |
| 2256 LInstruction* LChunkBuilder::DoTrapAllocationMemento( |
| 2257 HTrapAllocationMemento* instr) { |
| 2258 LOperand* object = UseRegister(instr->object()); |
| 2259 LOperand* temp1 = TempRegister(); |
| 2260 LOperand* temp2 = TempRegister(); |
| 2261 LTrapAllocationMemento* result = |
| 2262 new(zone()) LTrapAllocationMemento(object, temp1, temp2); |
| 2263 return AssignEnvironment(result); |
| 2419 } | 2264 } |
| 2420 | 2265 |
| 2421 | 2266 |
| 2422 LInstruction* LChunkBuilder::DoTypeof(HTypeof* instr) { | 2267 LInstruction* LChunkBuilder::DoTypeof(HTypeof* instr) { |
| 2423 LOperand* context = UseFixed(instr->context(), cp); | 2268 LOperand* context = UseFixed(instr->context(), cp); |
| 2424 LTypeof* result = new(zone()) LTypeof(context, UseFixed(instr->value(), r0)); | 2269 // TODO(jbramley): In ARM, this uses UseFixed to force the input to x0. |
| 2425 return MarkAsCall(DefineFixed(result, r0), instr); | 2270 // However, LCodeGen::DoTypeof just pushes it to the stack (for CallRuntime) |
| 2271 // anyway, so the input doesn't have to be in x0. We might be able to improve |
| 2272 // the ARM back-end a little by relaxing this restriction. |
| 2273 LTypeof* result = |
| 2274 new(zone()) LTypeof(context, UseRegisterAtStart(instr->value())); |
| 2275 return MarkAsCall(DefineFixed(result, x0), instr); |
| 2426 } | 2276 } |
| 2427 | 2277 |
| 2428 | 2278 |
| 2429 LInstruction* LChunkBuilder::DoTypeofIsAndBranch(HTypeofIsAndBranch* instr) { | 2279 LInstruction* LChunkBuilder::DoTypeofIsAndBranch(HTypeofIsAndBranch* instr) { |
| 2430 LInstruction* goto_instr = CheckElideControlInstruction(instr); | 2280 LInstruction* goto_instr = CheckElideControlInstruction(instr); |
| 2431 if (goto_instr != NULL) return goto_instr; | 2281 if (goto_instr != NULL) return goto_instr; |
| 2432 | 2282 |
| 2433 return new(zone()) LTypeofIsAndBranch(UseRegister(instr->value())); | 2283 // We only need temp registers in some cases, but we can't dereference the |
| 2284 // instr->type_literal() handle to test that here. |
| 2285 LOperand* temp1 = TempRegister(); |
| 2286 LOperand* temp2 = TempRegister(); |
| 2287 |
| 2288 return new(zone()) LTypeofIsAndBranch( |
| 2289 UseRegister(instr->value()), temp1, temp2); |
| 2434 } | 2290 } |
| 2435 | 2291 |
| 2436 | 2292 |
| 2437 LInstruction* LChunkBuilder::DoIsConstructCallAndBranch( | 2293 LInstruction* LChunkBuilder::DoUnaryMathOperation(HUnaryMathOperation* instr) { |
| 2438 HIsConstructCallAndBranch* instr) { | 2294 switch (instr->op()) { |
| 2439 return new(zone()) LIsConstructCallAndBranch(TempRegister()); | 2295 case kMathAbs: { |
| 2440 } | 2296 Representation r = instr->representation(); |
| 2441 | 2297 if (r.IsTagged()) { |
| 2442 | 2298 // The tagged case might need to allocate a HeapNumber for the result, |
| 2443 LInstruction* LChunkBuilder::DoSimulate(HSimulate* instr) { | 2299 // so it is handled by a separate LInstruction. |
| 2444 instr->ReplayEnvironment(current_block_->last_environment()); | 2300 LOperand* context = UseFixed(instr->context(), cp); |
| 2445 | 2301 LOperand* input = UseRegister(instr->value()); |
| 2446 // If there is an instruction pending deoptimization environment create a | 2302 LOperand* temp1 = TempRegister(); |
| 2447 // lazy bailout instruction to capture the environment. | 2303 LOperand* temp2 = TempRegister(); |
| 2448 if (pending_deoptimization_ast_id_ == instr->ast_id()) { | 2304 LOperand* temp3 = TempRegister(); |
| 2449 LInstruction* result = new(zone()) LLazyBailout; | 2305 LMathAbsTagged* result = |
| 2450 result = AssignEnvironment(result); | 2306 new(zone()) LMathAbsTagged(context, input, temp1, temp2, temp3); |
| 2451 // Store the lazy deopt environment with the instruction if needed. Right | 2307 return AssignEnvironment(AssignPointerMap(DefineAsRegister(result))); |
| 2452 // now it is only used for LInstanceOfKnownGlobal. | 2308 } else { |
| 2453 instruction_pending_deoptimization_environment_-> | 2309 LOperand* input = UseRegisterAtStart(instr->value()); |
| 2454 SetDeferredLazyDeoptimizationEnvironment(result->environment()); | 2310 LMathAbs* result = new(zone()) LMathAbs(input); |
| 2455 instruction_pending_deoptimization_environment_ = NULL; | 2311 if (r.IsDouble()) { |
| 2456 pending_deoptimization_ast_id_ = BailoutId::None(); | 2312 // The Double case can never fail so it doesn't need an environment. |
| 2457 return result; | 2313 return DefineAsRegister(result); |
| 2458 } | 2314 } else { |
| 2459 | 2315 ASSERT(r.IsInteger32() || r.IsSmi()); |
| 2460 return NULL; | 2316 // The Integer32 and Smi cases need an environment because they can |
| 2461 } | 2317 // deoptimize on minimum representable number. |
| 2462 | 2318 return AssignEnvironment(DefineAsRegister(result)); |
| 2463 | 2319 } |
| 2464 LInstruction* LChunkBuilder::DoStackCheck(HStackCheck* instr) { | 2320 } |
| 2465 if (instr->is_function_entry()) { | 2321 } |
| 2466 LOperand* context = UseFixed(instr->context(), cp); | 2322 case kMathExp: { |
| 2467 return MarkAsCall(new(zone()) LStackCheck(context), instr); | 2323 ASSERT(instr->representation().IsDouble()); |
| 2468 } else { | 2324 ASSERT(instr->value()->representation().IsDouble()); |
| 2469 ASSERT(instr->is_backwards_branch()); | 2325 LOperand* input = UseRegister(instr->value()); |
| 2470 LOperand* context = UseAny(instr->context()); | 2326 // TODO(all): Implement TempFPRegister. |
| 2471 return AssignEnvironment( | 2327 LOperand* double_temp1 = FixedTemp(d24); // This was chosen arbitrarily. |
| 2472 AssignPointerMap(new(zone()) LStackCheck(context))); | 2328 LOperand* temp1 = TempRegister(); |
| 2329 LOperand* temp2 = TempRegister(); |
| 2330 LOperand* temp3 = TempRegister(); |
| 2331 LMathExp* result = new(zone()) LMathExp(input, double_temp1, |
| 2332 temp1, temp2, temp3); |
| 2333 return DefineAsRegister(result); |
| 2334 } |
| 2335 case kMathFloor: { |
| 2336 ASSERT(instr->representation().IsInteger32()); |
| 2337 ASSERT(instr->value()->representation().IsDouble()); |
| 2338 // TODO(jbramley): A64 can easily handle a double argument with frintm, |
| 2339 // but we're never asked for it here. At the moment, we fall back to the |
| 2340 // runtime if the result doesn't fit, like the other architectures. |
| 2341 LOperand* input = UseRegisterAtStart(instr->value()); |
| 2342 LMathFloor* result = new(zone()) LMathFloor(input); |
| 2343 return AssignEnvironment(AssignPointerMap(DefineAsRegister(result))); |
| 2344 } |
| 2345 case kMathLog: { |
| 2346 ASSERT(instr->representation().IsDouble()); |
| 2347 ASSERT(instr->value()->representation().IsDouble()); |
| 2348 LOperand* input = UseFixedDouble(instr->value(), d0); |
| 2349 LMathLog* result = new(zone()) LMathLog(input); |
| 2350 return MarkAsCall(DefineFixedDouble(result, d0), instr); |
| 2351 } |
| 2352 case kMathPowHalf: { |
| 2353 ASSERT(instr->representation().IsDouble()); |
| 2354 ASSERT(instr->value()->representation().IsDouble()); |
| 2355 LOperand* input = UseRegister(instr->value()); |
| 2356 return DefineAsRegister(new(zone()) LMathPowHalf(input)); |
| 2357 } |
| 2358 case kMathRound: { |
| 2359 ASSERT(instr->representation().IsInteger32()); |
| 2360 ASSERT(instr->value()->representation().IsDouble()); |
| 2361 // TODO(jbramley): As with kMathFloor, we can probably handle double |
| 2362 // results fairly easily, but we are never asked for them. |
| 2363 LOperand* input = UseRegister(instr->value()); |
| 2364 LOperand* temp = FixedTemp(d24); // Choosen arbitrarily. |
| 2365 LMathRound* result = new(zone()) LMathRound(input, temp); |
| 2366 return AssignEnvironment(DefineAsRegister(result)); |
| 2367 } |
| 2368 case kMathSqrt: { |
| 2369 ASSERT(instr->representation().IsDouble()); |
| 2370 ASSERT(instr->value()->representation().IsDouble()); |
| 2371 LOperand* input = UseRegisterAtStart(instr->value()); |
| 2372 return DefineAsRegister(new(zone()) LMathSqrt(input)); |
| 2373 } |
| 2374 case kMathClz32: { |
| 2375 ASSERT(instr->representation().IsInteger32()); |
| 2376 ASSERT(instr->value()->representation().IsInteger32()); |
| 2377 LOperand* input = UseRegisterAtStart(instr->value()); |
| 2378 return DefineAsRegister(new(zone()) LMathClz32(input)); |
| 2379 } |
| 2380 default: |
| 2381 UNREACHABLE(); |
| 2382 return NULL; |
| 2473 } | 2383 } |
| 2474 } | 2384 } |
| 2475 | 2385 |
| 2476 | 2386 |
| 2477 LInstruction* LChunkBuilder::DoEnterInlined(HEnterInlined* instr) { | 2387 LInstruction* LChunkBuilder::DoUnknownOSRValue(HUnknownOSRValue* instr) { |
| 2478 HEnvironment* outer = current_block_->last_environment(); | 2388 // Use an index that corresponds to the location in the unoptimized frame, |
| 2479 HConstant* undefined = graph()->GetConstantUndefined(); | 2389 // which the optimized frame will subsume. |
| 2480 HEnvironment* inner = outer->CopyForInlining(instr->closure(), | 2390 int env_index = instr->index(); |
| 2481 instr->arguments_count(), | 2391 int spill_index = 0; |
| 2482 instr->function(), | 2392 if (instr->environment()->is_parameter_index(env_index)) { |
| 2483 undefined, | 2393 spill_index = chunk_->GetParameterStackSlot(env_index); |
| 2484 instr->inlining_kind()); | 2394 } else { |
| 2485 // Only replay binding of arguments object if it wasn't removed from graph. | 2395 spill_index = env_index - instr->environment()->first_local_index(); |
| 2486 if (instr->arguments_var() != NULL && instr->arguments_object()->IsLinked()) { | 2396 if (spill_index > LUnallocated::kMaxFixedSlotIndex) { |
| 2487 inner->Bind(instr->arguments_var(), instr->arguments_object()); | 2397 Abort(kTooManySpillSlotsNeededForOSR); |
| 2398 spill_index = 0; |
| 2399 } |
| 2488 } | 2400 } |
| 2489 inner->set_entry(instr); | 2401 return DefineAsSpilled(new(zone()) LUnknownOSRValue, spill_index); |
| 2490 current_block_->UpdateEnvironment(inner); | |
| 2491 chunk_->AddInlinedClosure(instr->closure()); | |
| 2492 return NULL; | |
| 2493 } | 2402 } |
| 2494 | 2403 |
| 2495 | 2404 |
| 2496 LInstruction* LChunkBuilder::DoLeaveInlined(HLeaveInlined* instr) { | 2405 LInstruction* LChunkBuilder::DoUseConst(HUseConst* instr) { |
| 2497 LInstruction* pop = NULL; | 2406 return NULL; |
| 2498 | |
| 2499 HEnvironment* env = current_block_->last_environment(); | |
| 2500 | |
| 2501 if (env->entry()->arguments_pushed()) { | |
| 2502 int argument_count = env->arguments_environment()->parameter_count(); | |
| 2503 pop = new(zone()) LDrop(argument_count); | |
| 2504 ASSERT(instr->argument_delta() == -argument_count); | |
| 2505 } | |
| 2506 | |
| 2507 HEnvironment* outer = current_block_->last_environment()-> | |
| 2508 DiscardInlined(false); | |
| 2509 current_block_->UpdateEnvironment(outer); | |
| 2510 | |
| 2511 return pop; | |
| 2512 } | 2407 } |
| 2513 | 2408 |
| 2514 | 2409 |
| 2515 LInstruction* LChunkBuilder::DoForInPrepareMap(HForInPrepareMap* instr) { | 2410 LInstruction* LChunkBuilder::DoForInPrepareMap(HForInPrepareMap* instr) { |
| 2516 LOperand* context = UseFixed(instr->context(), cp); | 2411 LOperand* context = UseFixed(instr->context(), cp); |
| 2517 LOperand* object = UseFixed(instr->enumerable(), r0); | 2412 // Assign object to a fixed register different from those already used in |
| 2413 // LForInPrepareMap. |
| 2414 LOperand* object = UseFixed(instr->enumerable(), x0); |
| 2518 LForInPrepareMap* result = new(zone()) LForInPrepareMap(context, object); | 2415 LForInPrepareMap* result = new(zone()) LForInPrepareMap(context, object); |
| 2519 return MarkAsCall(DefineFixed(result, r0), instr, CAN_DEOPTIMIZE_EAGERLY); | 2416 return MarkAsCall(DefineFixed(result, x0), instr, CAN_DEOPTIMIZE_EAGERLY); |
| 2520 } | 2417 } |
| 2521 | 2418 |
| 2522 | 2419 |
| 2523 LInstruction* LChunkBuilder::DoForInCacheArray(HForInCacheArray* instr) { | 2420 LInstruction* LChunkBuilder::DoForInCacheArray(HForInCacheArray* instr) { |
| 2524 LOperand* map = UseRegister(instr->map()); | 2421 LOperand* map = UseRegister(instr->map()); |
| 2525 return AssignEnvironment(DefineAsRegister(new(zone()) LForInCacheArray(map))); | 2422 return AssignEnvironment(DefineAsRegister(new(zone()) LForInCacheArray(map))); |
| 2526 } | 2423 } |
| 2527 | 2424 |
| 2528 | 2425 |
| 2529 LInstruction* LChunkBuilder::DoCheckMapValue(HCheckMapValue* instr) { | 2426 LInstruction* LChunkBuilder::DoCheckMapValue(HCheckMapValue* instr) { |
| 2530 LOperand* value = UseRegisterAtStart(instr->value()); | 2427 LOperand* value = UseRegisterAtStart(instr->value()); |
| 2531 LOperand* map = UseRegisterAtStart(instr->map()); | 2428 LOperand* map = UseRegister(instr->map()); |
| 2532 return AssignEnvironment(new(zone()) LCheckMapValue(value, map)); | 2429 LOperand* temp = TempRegister(); |
| 2430 return AssignEnvironment(new(zone()) LCheckMapValue(value, map, temp)); |
| 2533 } | 2431 } |
| 2534 | 2432 |
| 2535 | 2433 |
| 2536 LInstruction* LChunkBuilder::DoLoadFieldByIndex(HLoadFieldByIndex* instr) { | 2434 LInstruction* LChunkBuilder::DoLoadFieldByIndex(HLoadFieldByIndex* instr) { |
| 2537 LOperand* object = UseRegister(instr->object()); | 2435 LOperand* object = UseRegisterAtStart(instr->object()); |
| 2538 LOperand* index = UseRegister(instr->index()); | 2436 LOperand* index = UseRegister(instr->index()); |
| 2539 return DefineAsRegister(new(zone()) LLoadFieldByIndex(object, index)); | 2437 return DefineAsRegister(new(zone()) LLoadFieldByIndex(object, index)); |
| 2540 } | 2438 } |
| 2541 | 2439 |
| 2440 |
| 2441 LInstruction* LChunkBuilder::DoWrapReceiver(HWrapReceiver* instr) { |
| 2442 LOperand* receiver = UseRegister(instr->receiver()); |
| 2443 LOperand* function = UseRegister(instr->function()); |
| 2444 LWrapReceiver* result = new(zone()) LWrapReceiver(receiver, function); |
| 2445 return AssignEnvironment(DefineAsRegister(result)); |
| 2446 } |
| 2447 |
| 2448 |
| 2542 } } // namespace v8::internal | 2449 } } // namespace v8::internal |
| OLD | NEW |