| OLD | NEW |
| (Empty) |
| 1 // Copyright 2013 the V8 project authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "src/arm64/lithium-arm64.h" | |
| 6 | |
| 7 #include <sstream> | |
| 8 | |
| 9 #include "src/arm64/lithium-codegen-arm64.h" | |
| 10 #include "src/hydrogen-osr.h" | |
| 11 #include "src/lithium-inl.h" | |
| 12 | |
| 13 namespace v8 { | |
| 14 namespace internal { | |
| 15 | |
| 16 #define DEFINE_COMPILE(type) \ | |
| 17 void L##type::CompileToNative(LCodeGen* generator) { \ | |
| 18 generator->Do##type(this); \ | |
| 19 } | |
| 20 LITHIUM_CONCRETE_INSTRUCTION_LIST(DEFINE_COMPILE) | |
| 21 #undef DEFINE_COMPILE | |
| 22 | |
| 23 #ifdef DEBUG | |
| 24 void LInstruction::VerifyCall() { | |
| 25 // Call instructions can use only fixed registers as temporaries and | |
| 26 // outputs because all registers are blocked by the calling convention. | |
| 27 // Inputs operands must use a fixed register or use-at-start policy or | |
| 28 // a non-register policy. | |
| 29 DCHECK(Output() == NULL || | |
| 30 LUnallocated::cast(Output())->HasFixedPolicy() || | |
| 31 !LUnallocated::cast(Output())->HasRegisterPolicy()); | |
| 32 for (UseIterator it(this); !it.Done(); it.Advance()) { | |
| 33 LUnallocated* operand = LUnallocated::cast(it.Current()); | |
| 34 DCHECK(operand->HasFixedPolicy() || | |
| 35 operand->IsUsedAtStart()); | |
| 36 } | |
| 37 for (TempIterator it(this); !it.Done(); it.Advance()) { | |
| 38 LUnallocated* operand = LUnallocated::cast(it.Current()); | |
| 39 DCHECK(operand->HasFixedPolicy() ||!operand->HasRegisterPolicy()); | |
| 40 } | |
| 41 } | |
| 42 #endif | |
| 43 | |
| 44 | |
| 45 void LLabel::PrintDataTo(StringStream* stream) { | |
| 46 LGap::PrintDataTo(stream); | |
| 47 LLabel* rep = replacement(); | |
| 48 if (rep != NULL) { | |
| 49 stream->Add(" Dead block replaced with B%d", rep->block_id()); | |
| 50 } | |
| 51 } | |
| 52 | |
| 53 | |
| 54 void LAccessArgumentsAt::PrintDataTo(StringStream* stream) { | |
| 55 arguments()->PrintTo(stream); | |
| 56 stream->Add(" length "); | |
| 57 length()->PrintTo(stream); | |
| 58 stream->Add(" index "); | |
| 59 index()->PrintTo(stream); | |
| 60 } | |
| 61 | |
| 62 | |
| 63 void LBranch::PrintDataTo(StringStream* stream) { | |
| 64 stream->Add("B%d | B%d on ", true_block_id(), false_block_id()); | |
| 65 value()->PrintTo(stream); | |
| 66 } | |
| 67 | |
| 68 | |
| 69 void LCallJSFunction::PrintDataTo(StringStream* stream) { | |
| 70 stream->Add("= "); | |
| 71 function()->PrintTo(stream); | |
| 72 stream->Add("#%d / ", arity()); | |
| 73 } | |
| 74 | |
| 75 | |
| 76 void LCallWithDescriptor::PrintDataTo(StringStream* stream) { | |
| 77 for (int i = 0; i < InputCount(); i++) { | |
| 78 InputAt(i)->PrintTo(stream); | |
| 79 stream->Add(" "); | |
| 80 } | |
| 81 stream->Add("#%d / ", arity()); | |
| 82 } | |
| 83 | |
| 84 | |
| 85 void LCallNew::PrintDataTo(StringStream* stream) { | |
| 86 stream->Add("= "); | |
| 87 constructor()->PrintTo(stream); | |
| 88 stream->Add(" #%d / ", arity()); | |
| 89 } | |
| 90 | |
| 91 | |
| 92 void LCallNewArray::PrintDataTo(StringStream* stream) { | |
| 93 stream->Add("= "); | |
| 94 constructor()->PrintTo(stream); | |
| 95 stream->Add(" #%d / ", arity()); | |
| 96 ElementsKind kind = hydrogen()->elements_kind(); | |
| 97 stream->Add(" (%s) ", ElementsKindToString(kind)); | |
| 98 } | |
| 99 | |
| 100 | |
| 101 void LClassOfTestAndBranch::PrintDataTo(StringStream* stream) { | |
| 102 stream->Add("if class_of_test("); | |
| 103 value()->PrintTo(stream); | |
| 104 stream->Add(", \"%o\") then B%d else B%d", | |
| 105 *hydrogen()->class_name(), | |
| 106 true_block_id(), | |
| 107 false_block_id()); | |
| 108 } | |
| 109 | |
| 110 | |
| 111 void LCompareNumericAndBranch::PrintDataTo(StringStream* stream) { | |
| 112 stream->Add("if "); | |
| 113 left()->PrintTo(stream); | |
| 114 stream->Add(" %s ", Token::String(op())); | |
| 115 right()->PrintTo(stream); | |
| 116 stream->Add(" then B%d else B%d", true_block_id(), false_block_id()); | |
| 117 } | |
| 118 | |
| 119 | |
| 120 void LHasCachedArrayIndexAndBranch::PrintDataTo(StringStream* stream) { | |
| 121 stream->Add("if has_cached_array_index("); | |
| 122 value()->PrintTo(stream); | |
| 123 stream->Add(") then B%d else B%d", true_block_id(), false_block_id()); | |
| 124 } | |
| 125 | |
| 126 | |
| 127 bool LGoto::HasInterestingComment(LCodeGen* gen) const { | |
| 128 return !gen->IsNextEmittedBlock(block_id()); | |
| 129 } | |
| 130 | |
| 131 | |
| 132 void LGoto::PrintDataTo(StringStream* stream) { | |
| 133 stream->Add("B%d", block_id()); | |
| 134 } | |
| 135 | |
| 136 | |
| 137 void LInnerAllocatedObject::PrintDataTo(StringStream* stream) { | |
| 138 stream->Add(" = "); | |
| 139 base_object()->PrintTo(stream); | |
| 140 stream->Add(" + "); | |
| 141 offset()->PrintTo(stream); | |
| 142 } | |
| 143 | |
| 144 | |
| 145 void LCallFunction::PrintDataTo(StringStream* stream) { | |
| 146 context()->PrintTo(stream); | |
| 147 stream->Add(" "); | |
| 148 function()->PrintTo(stream); | |
| 149 if (hydrogen()->HasVectorAndSlot()) { | |
| 150 stream->Add(" (type-feedback-vector "); | |
| 151 temp_vector()->PrintTo(stream); | |
| 152 stream->Add(" "); | |
| 153 temp_slot()->PrintTo(stream); | |
| 154 stream->Add(")"); | |
| 155 } | |
| 156 } | |
| 157 | |
| 158 | |
| 159 void LInvokeFunction::PrintDataTo(StringStream* stream) { | |
| 160 stream->Add("= "); | |
| 161 function()->PrintTo(stream); | |
| 162 stream->Add(" #%d / ", arity()); | |
| 163 } | |
| 164 | |
| 165 | |
| 166 void LInstruction::PrintTo(StringStream* stream) { | |
| 167 stream->Add("%s ", this->Mnemonic()); | |
| 168 | |
| 169 PrintOutputOperandTo(stream); | |
| 170 | |
| 171 PrintDataTo(stream); | |
| 172 | |
| 173 if (HasEnvironment()) { | |
| 174 stream->Add(" "); | |
| 175 environment()->PrintTo(stream); | |
| 176 } | |
| 177 | |
| 178 if (HasPointerMap()) { | |
| 179 stream->Add(" "); | |
| 180 pointer_map()->PrintTo(stream); | |
| 181 } | |
| 182 } | |
| 183 | |
| 184 | |
| 185 void LInstruction::PrintDataTo(StringStream* stream) { | |
| 186 stream->Add("= "); | |
| 187 for (int i = 0; i < InputCount(); i++) { | |
| 188 if (i > 0) stream->Add(" "); | |
| 189 if (InputAt(i) == NULL) { | |
| 190 stream->Add("NULL"); | |
| 191 } else { | |
| 192 InputAt(i)->PrintTo(stream); | |
| 193 } | |
| 194 } | |
| 195 } | |
| 196 | |
| 197 | |
| 198 void LInstruction::PrintOutputOperandTo(StringStream* stream) { | |
| 199 if (HasResult()) result()->PrintTo(stream); | |
| 200 } | |
| 201 | |
| 202 | |
| 203 void LHasInstanceTypeAndBranch::PrintDataTo(StringStream* stream) { | |
| 204 stream->Add("if has_instance_type("); | |
| 205 value()->PrintTo(stream); | |
| 206 stream->Add(") then B%d else B%d", true_block_id(), false_block_id()); | |
| 207 } | |
| 208 | |
| 209 | |
| 210 void LIsStringAndBranch::PrintDataTo(StringStream* stream) { | |
| 211 stream->Add("if is_string("); | |
| 212 value()->PrintTo(stream); | |
| 213 stream->Add(") then B%d else B%d", true_block_id(), false_block_id()); | |
| 214 } | |
| 215 | |
| 216 | |
| 217 void LIsSmiAndBranch::PrintDataTo(StringStream* stream) { | |
| 218 stream->Add("if is_smi("); | |
| 219 value()->PrintTo(stream); | |
| 220 stream->Add(") then B%d else B%d", true_block_id(), false_block_id()); | |
| 221 } | |
| 222 | |
| 223 | |
| 224 void LTypeofIsAndBranch::PrintDataTo(StringStream* stream) { | |
| 225 stream->Add("if typeof "); | |
| 226 value()->PrintTo(stream); | |
| 227 stream->Add(" == \"%s\" then B%d else B%d", | |
| 228 hydrogen()->type_literal()->ToCString().get(), | |
| 229 true_block_id(), false_block_id()); | |
| 230 } | |
| 231 | |
| 232 | |
| 233 void LIsUndetectableAndBranch::PrintDataTo(StringStream* stream) { | |
| 234 stream->Add("if is_undetectable("); | |
| 235 value()->PrintTo(stream); | |
| 236 stream->Add(") then B%d else B%d", true_block_id(), false_block_id()); | |
| 237 } | |
| 238 | |
| 239 | |
| 240 bool LGap::IsRedundant() const { | |
| 241 for (int i = 0; i < 4; i++) { | |
| 242 if ((parallel_moves_[i] != NULL) && !parallel_moves_[i]->IsRedundant()) { | |
| 243 return false; | |
| 244 } | |
| 245 } | |
| 246 | |
| 247 return true; | |
| 248 } | |
| 249 | |
| 250 | |
| 251 void LGap::PrintDataTo(StringStream* stream) { | |
| 252 for (int i = 0; i < 4; i++) { | |
| 253 stream->Add("("); | |
| 254 if (parallel_moves_[i] != NULL) { | |
| 255 parallel_moves_[i]->PrintDataTo(stream); | |
| 256 } | |
| 257 stream->Add(") "); | |
| 258 } | |
| 259 } | |
| 260 | |
| 261 | |
| 262 void LLoadContextSlot::PrintDataTo(StringStream* stream) { | |
| 263 context()->PrintTo(stream); | |
| 264 stream->Add("[%d]", slot_index()); | |
| 265 } | |
| 266 | |
| 267 | |
| 268 void LStoreCodeEntry::PrintDataTo(StringStream* stream) { | |
| 269 stream->Add(" = "); | |
| 270 function()->PrintTo(stream); | |
| 271 stream->Add(".code_entry = "); | |
| 272 code_object()->PrintTo(stream); | |
| 273 } | |
| 274 | |
| 275 | |
| 276 void LStoreContextSlot::PrintDataTo(StringStream* stream) { | |
| 277 context()->PrintTo(stream); | |
| 278 stream->Add("[%d] <- ", slot_index()); | |
| 279 value()->PrintTo(stream); | |
| 280 } | |
| 281 | |
| 282 | |
| 283 void LStoreKeyedGeneric::PrintDataTo(StringStream* stream) { | |
| 284 object()->PrintTo(stream); | |
| 285 stream->Add("["); | |
| 286 key()->PrintTo(stream); | |
| 287 stream->Add("] <- "); | |
| 288 value()->PrintTo(stream); | |
| 289 } | |
| 290 | |
| 291 | |
| 292 void LLoadGlobalViaContext::PrintDataTo(StringStream* stream) { | |
| 293 stream->Add("depth:%d slot:%d", depth(), slot_index()); | |
| 294 } | |
| 295 | |
| 296 | |
| 297 void LStoreNamedField::PrintDataTo(StringStream* stream) { | |
| 298 object()->PrintTo(stream); | |
| 299 std::ostringstream os; | |
| 300 os << hydrogen()->access(); | |
| 301 stream->Add(os.str().c_str()); | |
| 302 stream->Add(" <- "); | |
| 303 value()->PrintTo(stream); | |
| 304 } | |
| 305 | |
| 306 | |
| 307 void LStoreNamedGeneric::PrintDataTo(StringStream* stream) { | |
| 308 object()->PrintTo(stream); | |
| 309 stream->Add("."); | |
| 310 stream->Add(String::cast(*name())->ToCString().get()); | |
| 311 stream->Add(" <- "); | |
| 312 value()->PrintTo(stream); | |
| 313 } | |
| 314 | |
| 315 | |
| 316 void LStoreGlobalViaContext::PrintDataTo(StringStream* stream) { | |
| 317 stream->Add("depth:%d slot:%d <- ", depth(), slot_index()); | |
| 318 value()->PrintTo(stream); | |
| 319 } | |
| 320 | |
| 321 | |
| 322 void LStringCompareAndBranch::PrintDataTo(StringStream* stream) { | |
| 323 stream->Add("if string_compare("); | |
| 324 left()->PrintTo(stream); | |
| 325 right()->PrintTo(stream); | |
| 326 stream->Add(") then B%d else B%d", true_block_id(), false_block_id()); | |
| 327 } | |
| 328 | |
| 329 | |
| 330 void LTransitionElementsKind::PrintDataTo(StringStream* stream) { | |
| 331 object()->PrintTo(stream); | |
| 332 stream->Add("%p -> %p", *original_map(), *transitioned_map()); | |
| 333 } | |
| 334 | |
| 335 | |
| 336 template<int T> | |
| 337 void LUnaryMathOperation<T>::PrintDataTo(StringStream* stream) { | |
| 338 value()->PrintTo(stream); | |
| 339 } | |
| 340 | |
| 341 | |
| 342 const char* LArithmeticD::Mnemonic() const { | |
| 343 switch (op()) { | |
| 344 case Token::ADD: return "add-d"; | |
| 345 case Token::SUB: return "sub-d"; | |
| 346 case Token::MUL: return "mul-d"; | |
| 347 case Token::DIV: return "div-d"; | |
| 348 case Token::MOD: return "mod-d"; | |
| 349 default: | |
| 350 UNREACHABLE(); | |
| 351 return NULL; | |
| 352 } | |
| 353 } | |
| 354 | |
| 355 | |
| 356 const char* LArithmeticT::Mnemonic() const { | |
| 357 switch (op()) { | |
| 358 case Token::ADD: return "add-t"; | |
| 359 case Token::SUB: return "sub-t"; | |
| 360 case Token::MUL: return "mul-t"; | |
| 361 case Token::MOD: return "mod-t"; | |
| 362 case Token::DIV: return "div-t"; | |
| 363 case Token::BIT_AND: return "bit-and-t"; | |
| 364 case Token::BIT_OR: return "bit-or-t"; | |
| 365 case Token::BIT_XOR: return "bit-xor-t"; | |
| 366 case Token::ROR: return "ror-t"; | |
| 367 case Token::SHL: return "shl-t"; | |
| 368 case Token::SAR: return "sar-t"; | |
| 369 case Token::SHR: return "shr-t"; | |
| 370 default: | |
| 371 UNREACHABLE(); | |
| 372 return NULL; | |
| 373 } | |
| 374 } | |
| 375 | |
| 376 | |
| 377 LUnallocated* LChunkBuilder::ToUnallocated(Register reg) { | |
| 378 return new (zone()) LUnallocated(LUnallocated::FIXED_REGISTER, reg.code()); | |
| 379 } | |
| 380 | |
| 381 | |
| 382 LUnallocated* LChunkBuilder::ToUnallocated(DoubleRegister reg) { | |
| 383 return new (zone()) | |
| 384 LUnallocated(LUnallocated::FIXED_DOUBLE_REGISTER, reg.code()); | |
| 385 } | |
| 386 | |
| 387 | |
| 388 LOperand* LChunkBuilder::Use(HValue* value, LUnallocated* operand) { | |
| 389 if (value->EmitAtUses()) { | |
| 390 HInstruction* instr = HInstruction::cast(value); | |
| 391 VisitInstruction(instr); | |
| 392 } | |
| 393 operand->set_virtual_register(value->id()); | |
| 394 return operand; | |
| 395 } | |
| 396 | |
| 397 | |
| 398 LOperand* LChunkBuilder::UseFixed(HValue* value, Register fixed_register) { | |
| 399 return Use(value, ToUnallocated(fixed_register)); | |
| 400 } | |
| 401 | |
| 402 | |
| 403 LOperand* LChunkBuilder::UseFixedDouble(HValue* value, | |
| 404 DoubleRegister fixed_register) { | |
| 405 return Use(value, ToUnallocated(fixed_register)); | |
| 406 } | |
| 407 | |
| 408 | |
| 409 LOperand* LChunkBuilder::UseRegister(HValue* value) { | |
| 410 return Use(value, new(zone()) LUnallocated(LUnallocated::MUST_HAVE_REGISTER)); | |
| 411 } | |
| 412 | |
| 413 | |
| 414 LOperand* LChunkBuilder::UseRegisterAndClobber(HValue* value) { | |
| 415 return Use(value, new(zone()) LUnallocated(LUnallocated::WRITABLE_REGISTER)); | |
| 416 } | |
| 417 | |
| 418 | |
| 419 LOperand* LChunkBuilder::UseRegisterAtStart(HValue* value) { | |
| 420 return Use(value, | |
| 421 new(zone()) LUnallocated(LUnallocated::MUST_HAVE_REGISTER, | |
| 422 LUnallocated::USED_AT_START)); | |
| 423 } | |
| 424 | |
| 425 | |
| 426 LOperand* LChunkBuilder::UseRegisterOrConstant(HValue* value) { | |
| 427 return value->IsConstant() ? UseConstant(value) : UseRegister(value); | |
| 428 } | |
| 429 | |
| 430 | |
| 431 LOperand* LChunkBuilder::UseRegisterOrConstantAtStart(HValue* value) { | |
| 432 return value->IsConstant() ? UseConstant(value) : UseRegisterAtStart(value); | |
| 433 } | |
| 434 | |
| 435 | |
| 436 LConstantOperand* LChunkBuilder::UseConstant(HValue* value) { | |
| 437 return chunk_->DefineConstantOperand(HConstant::cast(value)); | |
| 438 } | |
| 439 | |
| 440 | |
| 441 LOperand* LChunkBuilder::UseAny(HValue* value) { | |
| 442 return value->IsConstant() | |
| 443 ? UseConstant(value) | |
| 444 : Use(value, new(zone()) LUnallocated(LUnallocated::ANY)); | |
| 445 } | |
| 446 | |
| 447 | |
| 448 LInstruction* LChunkBuilder::Define(LTemplateResultInstruction<1>* instr, | |
| 449 LUnallocated* result) { | |
| 450 result->set_virtual_register(current_instruction_->id()); | |
| 451 instr->set_result(result); | |
| 452 return instr; | |
| 453 } | |
| 454 | |
| 455 | |
| 456 LInstruction* LChunkBuilder::DefineAsRegister( | |
| 457 LTemplateResultInstruction<1>* instr) { | |
| 458 return Define(instr, | |
| 459 new(zone()) LUnallocated(LUnallocated::MUST_HAVE_REGISTER)); | |
| 460 } | |
| 461 | |
| 462 | |
| 463 LInstruction* LChunkBuilder::DefineAsSpilled( | |
| 464 LTemplateResultInstruction<1>* instr, int index) { | |
| 465 return Define(instr, | |
| 466 new(zone()) LUnallocated(LUnallocated::FIXED_SLOT, index)); | |
| 467 } | |
| 468 | |
| 469 | |
| 470 LInstruction* LChunkBuilder::DefineSameAsFirst( | |
| 471 LTemplateResultInstruction<1>* instr) { | |
| 472 return Define(instr, | |
| 473 new(zone()) LUnallocated(LUnallocated::SAME_AS_FIRST_INPUT)); | |
| 474 } | |
| 475 | |
| 476 | |
| 477 LInstruction* LChunkBuilder::DefineFixed( | |
| 478 LTemplateResultInstruction<1>* instr, Register reg) { | |
| 479 return Define(instr, ToUnallocated(reg)); | |
| 480 } | |
| 481 | |
| 482 | |
| 483 LInstruction* LChunkBuilder::DefineFixedDouble( | |
| 484 LTemplateResultInstruction<1>* instr, DoubleRegister reg) { | |
| 485 return Define(instr, ToUnallocated(reg)); | |
| 486 } | |
| 487 | |
| 488 | |
| 489 LInstruction* LChunkBuilder::MarkAsCall(LInstruction* instr, | |
| 490 HInstruction* hinstr, | |
| 491 CanDeoptimize can_deoptimize) { | |
| 492 info()->MarkAsNonDeferredCalling(); | |
| 493 #ifdef DEBUG | |
| 494 instr->VerifyCall(); | |
| 495 #endif | |
| 496 instr->MarkAsCall(); | |
| 497 instr = AssignPointerMap(instr); | |
| 498 | |
| 499 // If instruction does not have side-effects lazy deoptimization | |
| 500 // after the call will try to deoptimize to the point before the call. | |
| 501 // Thus we still need to attach environment to this call even if | |
| 502 // call sequence can not deoptimize eagerly. | |
| 503 bool needs_environment = | |
| 504 (can_deoptimize == CAN_DEOPTIMIZE_EAGERLY) || | |
| 505 !hinstr->HasObservableSideEffects(); | |
| 506 if (needs_environment && !instr->HasEnvironment()) { | |
| 507 instr = AssignEnvironment(instr); | |
| 508 // We can't really figure out if the environment is needed or not. | |
| 509 instr->environment()->set_has_been_used(); | |
| 510 } | |
| 511 | |
| 512 return instr; | |
| 513 } | |
| 514 | |
| 515 | |
| 516 LInstruction* LChunkBuilder::AssignPointerMap(LInstruction* instr) { | |
| 517 DCHECK(!instr->HasPointerMap()); | |
| 518 instr->set_pointer_map(new(zone()) LPointerMap(zone())); | |
| 519 return instr; | |
| 520 } | |
| 521 | |
| 522 | |
| 523 LUnallocated* LChunkBuilder::TempRegister() { | |
| 524 LUnallocated* operand = | |
| 525 new(zone()) LUnallocated(LUnallocated::MUST_HAVE_REGISTER); | |
| 526 int vreg = allocator_->GetVirtualRegister(); | |
| 527 if (!allocator_->AllocationOk()) { | |
| 528 Abort(kOutOfVirtualRegistersWhileTryingToAllocateTempRegister); | |
| 529 vreg = 0; | |
| 530 } | |
| 531 operand->set_virtual_register(vreg); | |
| 532 return operand; | |
| 533 } | |
| 534 | |
| 535 | |
| 536 LUnallocated* LChunkBuilder::TempDoubleRegister() { | |
| 537 LUnallocated* operand = | |
| 538 new(zone()) LUnallocated(LUnallocated::MUST_HAVE_DOUBLE_REGISTER); | |
| 539 int vreg = allocator_->GetVirtualRegister(); | |
| 540 if (!allocator_->AllocationOk()) { | |
| 541 Abort(kOutOfVirtualRegistersWhileTryingToAllocateTempRegister); | |
| 542 vreg = 0; | |
| 543 } | |
| 544 operand->set_virtual_register(vreg); | |
| 545 return operand; | |
| 546 } | |
| 547 | |
| 548 | |
| 549 int LPlatformChunk::GetNextSpillIndex() { | |
| 550 return spill_slot_count_++; | |
| 551 } | |
| 552 | |
| 553 | |
| 554 LOperand* LPlatformChunk::GetNextSpillSlot(RegisterKind kind) { | |
| 555 int index = GetNextSpillIndex(); | |
| 556 if (kind == DOUBLE_REGISTERS) { | |
| 557 return LDoubleStackSlot::Create(index, zone()); | |
| 558 } else { | |
| 559 DCHECK(kind == GENERAL_REGISTERS); | |
| 560 return LStackSlot::Create(index, zone()); | |
| 561 } | |
| 562 } | |
| 563 | |
| 564 | |
| 565 LOperand* LChunkBuilder::FixedTemp(Register reg) { | |
| 566 LUnallocated* operand = ToUnallocated(reg); | |
| 567 DCHECK(operand->HasFixedPolicy()); | |
| 568 return operand; | |
| 569 } | |
| 570 | |
| 571 | |
| 572 LOperand* LChunkBuilder::FixedTemp(DoubleRegister reg) { | |
| 573 LUnallocated* operand = ToUnallocated(reg); | |
| 574 DCHECK(operand->HasFixedPolicy()); | |
| 575 return operand; | |
| 576 } | |
| 577 | |
| 578 | |
| 579 LPlatformChunk* LChunkBuilder::Build() { | |
| 580 DCHECK(is_unused()); | |
| 581 chunk_ = new(zone()) LPlatformChunk(info_, graph_); | |
| 582 LPhase phase("L_Building chunk", chunk_); | |
| 583 status_ = BUILDING; | |
| 584 | |
| 585 // If compiling for OSR, reserve space for the unoptimized frame, | |
| 586 // which will be subsumed into this frame. | |
| 587 if (graph()->has_osr()) { | |
| 588 // TODO(all): GetNextSpillIndex just increments a field. It has no other | |
| 589 // side effects, so we should get rid of this loop. | |
| 590 for (int i = graph()->osr()->UnoptimizedFrameSlots(); i > 0; i--) { | |
| 591 chunk_->GetNextSpillIndex(); | |
| 592 } | |
| 593 } | |
| 594 | |
| 595 const ZoneList<HBasicBlock*>* blocks = graph_->blocks(); | |
| 596 for (int i = 0; i < blocks->length(); i++) { | |
| 597 DoBasicBlock(blocks->at(i)); | |
| 598 if (is_aborted()) return NULL; | |
| 599 } | |
| 600 status_ = DONE; | |
| 601 return chunk_; | |
| 602 } | |
| 603 | |
| 604 | |
| 605 void LChunkBuilder::DoBasicBlock(HBasicBlock* block) { | |
| 606 DCHECK(is_building()); | |
| 607 current_block_ = block; | |
| 608 | |
| 609 if (block->IsStartBlock()) { | |
| 610 block->UpdateEnvironment(graph_->start_environment()); | |
| 611 argument_count_ = 0; | |
| 612 } else if (block->predecessors()->length() == 1) { | |
| 613 // We have a single predecessor => copy environment and outgoing | |
| 614 // argument count from the predecessor. | |
| 615 DCHECK(block->phis()->length() == 0); | |
| 616 HBasicBlock* pred = block->predecessors()->at(0); | |
| 617 HEnvironment* last_environment = pred->last_environment(); | |
| 618 DCHECK(last_environment != NULL); | |
| 619 | |
| 620 // Only copy the environment, if it is later used again. | |
| 621 if (pred->end()->SecondSuccessor() == NULL) { | |
| 622 DCHECK(pred->end()->FirstSuccessor() == block); | |
| 623 } else { | |
| 624 if ((pred->end()->FirstSuccessor()->block_id() > block->block_id()) || | |
| 625 (pred->end()->SecondSuccessor()->block_id() > block->block_id())) { | |
| 626 last_environment = last_environment->Copy(); | |
| 627 } | |
| 628 } | |
| 629 block->UpdateEnvironment(last_environment); | |
| 630 DCHECK(pred->argument_count() >= 0); | |
| 631 argument_count_ = pred->argument_count(); | |
| 632 } else { | |
| 633 // We are at a state join => process phis. | |
| 634 HBasicBlock* pred = block->predecessors()->at(0); | |
| 635 // No need to copy the environment, it cannot be used later. | |
| 636 HEnvironment* last_environment = pred->last_environment(); | |
| 637 for (int i = 0; i < block->phis()->length(); ++i) { | |
| 638 HPhi* phi = block->phis()->at(i); | |
| 639 if (phi->HasMergedIndex()) { | |
| 640 last_environment->SetValueAt(phi->merged_index(), phi); | |
| 641 } | |
| 642 } | |
| 643 for (int i = 0; i < block->deleted_phis()->length(); ++i) { | |
| 644 if (block->deleted_phis()->at(i) < last_environment->length()) { | |
| 645 last_environment->SetValueAt(block->deleted_phis()->at(i), | |
| 646 graph_->GetConstantUndefined()); | |
| 647 } | |
| 648 } | |
| 649 block->UpdateEnvironment(last_environment); | |
| 650 // Pick up the outgoing argument count of one of the predecessors. | |
| 651 argument_count_ = pred->argument_count(); | |
| 652 } | |
| 653 | |
| 654 // Translate hydrogen instructions to lithium ones for the current block. | |
| 655 HInstruction* current = block->first(); | |
| 656 int start = chunk_->instructions()->length(); | |
| 657 while ((current != NULL) && !is_aborted()) { | |
| 658 // Code for constants in registers is generated lazily. | |
| 659 if (!current->EmitAtUses()) { | |
| 660 VisitInstruction(current); | |
| 661 } | |
| 662 current = current->next(); | |
| 663 } | |
| 664 int end = chunk_->instructions()->length() - 1; | |
| 665 if (end >= start) { | |
| 666 block->set_first_instruction_index(start); | |
| 667 block->set_last_instruction_index(end); | |
| 668 } | |
| 669 block->set_argument_count(argument_count_); | |
| 670 current_block_ = NULL; | |
| 671 } | |
| 672 | |
| 673 | |
| 674 void LChunkBuilder::VisitInstruction(HInstruction* current) { | |
| 675 HInstruction* old_current = current_instruction_; | |
| 676 current_instruction_ = current; | |
| 677 | |
| 678 LInstruction* instr = NULL; | |
| 679 if (current->CanReplaceWithDummyUses()) { | |
| 680 if (current->OperandCount() == 0) { | |
| 681 instr = DefineAsRegister(new(zone()) LDummy()); | |
| 682 } else { | |
| 683 DCHECK(!current->OperandAt(0)->IsControlInstruction()); | |
| 684 instr = DefineAsRegister(new(zone()) | |
| 685 LDummyUse(UseAny(current->OperandAt(0)))); | |
| 686 } | |
| 687 for (int i = 1; i < current->OperandCount(); ++i) { | |
| 688 if (current->OperandAt(i)->IsControlInstruction()) continue; | |
| 689 LInstruction* dummy = | |
| 690 new(zone()) LDummyUse(UseAny(current->OperandAt(i))); | |
| 691 dummy->set_hydrogen_value(current); | |
| 692 chunk_->AddInstruction(dummy, current_block_); | |
| 693 } | |
| 694 } else { | |
| 695 HBasicBlock* successor; | |
| 696 if (current->IsControlInstruction() && | |
| 697 HControlInstruction::cast(current)->KnownSuccessorBlock(&successor) && | |
| 698 successor != NULL) { | |
| 699 instr = new(zone()) LGoto(successor); | |
| 700 } else { | |
| 701 instr = current->CompileToLithium(this); | |
| 702 } | |
| 703 } | |
| 704 | |
| 705 argument_count_ += current->argument_delta(); | |
| 706 DCHECK(argument_count_ >= 0); | |
| 707 | |
| 708 if (instr != NULL) { | |
| 709 AddInstruction(instr, current); | |
| 710 } | |
| 711 | |
| 712 current_instruction_ = old_current; | |
| 713 } | |
| 714 | |
| 715 | |
| 716 void LChunkBuilder::AddInstruction(LInstruction* instr, | |
| 717 HInstruction* hydrogen_val) { | |
| 718 // Associate the hydrogen instruction first, since we may need it for | |
| 719 // the ClobbersRegisters() or ClobbersDoubleRegisters() calls below. | |
| 720 instr->set_hydrogen_value(hydrogen_val); | |
| 721 | |
| 722 #if DEBUG | |
| 723 // Make sure that the lithium instruction has either no fixed register | |
| 724 // constraints in temps or the result OR no uses that are only used at | |
| 725 // start. If this invariant doesn't hold, the register allocator can decide | |
| 726 // to insert a split of a range immediately before the instruction due to an | |
| 727 // already allocated register needing to be used for the instruction's fixed | |
| 728 // register constraint. In this case, the register allocator won't see an | |
| 729 // interference between the split child and the use-at-start (it would if | |
| 730 // the it was just a plain use), so it is free to move the split child into | |
| 731 // the same register that is used for the use-at-start. | |
| 732 // See https://code.google.com/p/chromium/issues/detail?id=201590 | |
| 733 if (!(instr->ClobbersRegisters() && | |
| 734 instr->ClobbersDoubleRegisters(isolate()))) { | |
| 735 int fixed = 0; | |
| 736 int used_at_start = 0; | |
| 737 for (UseIterator it(instr); !it.Done(); it.Advance()) { | |
| 738 LUnallocated* operand = LUnallocated::cast(it.Current()); | |
| 739 if (operand->IsUsedAtStart()) ++used_at_start; | |
| 740 } | |
| 741 if (instr->Output() != NULL) { | |
| 742 if (LUnallocated::cast(instr->Output())->HasFixedPolicy()) ++fixed; | |
| 743 } | |
| 744 for (TempIterator it(instr); !it.Done(); it.Advance()) { | |
| 745 LUnallocated* operand = LUnallocated::cast(it.Current()); | |
| 746 if (operand->HasFixedPolicy()) ++fixed; | |
| 747 } | |
| 748 DCHECK(fixed == 0 || used_at_start == 0); | |
| 749 } | |
| 750 #endif | |
| 751 | |
| 752 if (FLAG_stress_pointer_maps && !instr->HasPointerMap()) { | |
| 753 instr = AssignPointerMap(instr); | |
| 754 } | |
| 755 if (FLAG_stress_environments && !instr->HasEnvironment()) { | |
| 756 instr = AssignEnvironment(instr); | |
| 757 } | |
| 758 chunk_->AddInstruction(instr, current_block_); | |
| 759 | |
| 760 if (instr->IsCall() || instr->IsPrologue()) { | |
| 761 HValue* hydrogen_value_for_lazy_bailout = hydrogen_val; | |
| 762 if (hydrogen_val->HasObservableSideEffects()) { | |
| 763 HSimulate* sim = HSimulate::cast(hydrogen_val->next()); | |
| 764 sim->ReplayEnvironment(current_block_->last_environment()); | |
| 765 hydrogen_value_for_lazy_bailout = sim; | |
| 766 } | |
| 767 LInstruction* bailout = AssignEnvironment(new(zone()) LLazyBailout()); | |
| 768 bailout->set_hydrogen_value(hydrogen_value_for_lazy_bailout); | |
| 769 chunk_->AddInstruction(bailout, current_block_); | |
| 770 } | |
| 771 } | |
| 772 | |
| 773 | |
| 774 LInstruction* LChunkBuilder::AssignEnvironment(LInstruction* instr) { | |
| 775 HEnvironment* hydrogen_env = current_block_->last_environment(); | |
| 776 int argument_index_accumulator = 0; | |
| 777 ZoneList<HValue*> objects_to_materialize(0, zone()); | |
| 778 instr->set_environment(CreateEnvironment(hydrogen_env, | |
| 779 &argument_index_accumulator, | |
| 780 &objects_to_materialize)); | |
| 781 return instr; | |
| 782 } | |
| 783 | |
| 784 | |
| 785 LInstruction* LChunkBuilder::DoPrologue(HPrologue* instr) { | |
| 786 return new (zone()) LPrologue(); | |
| 787 } | |
| 788 | |
| 789 | |
| 790 LInstruction* LChunkBuilder::DoAbnormalExit(HAbnormalExit* instr) { | |
| 791 // The control instruction marking the end of a block that completed | |
| 792 // abruptly (e.g., threw an exception). There is nothing specific to do. | |
| 793 return NULL; | |
| 794 } | |
| 795 | |
| 796 | |
| 797 LInstruction* LChunkBuilder::DoArithmeticD(Token::Value op, | |
| 798 HArithmeticBinaryOperation* instr) { | |
| 799 DCHECK(instr->representation().IsDouble()); | |
| 800 DCHECK(instr->left()->representation().IsDouble()); | |
| 801 DCHECK(instr->right()->representation().IsDouble()); | |
| 802 | |
| 803 if (op == Token::MOD) { | |
| 804 LOperand* left = UseFixedDouble(instr->left(), d0); | |
| 805 LOperand* right = UseFixedDouble(instr->right(), d1); | |
| 806 LArithmeticD* result = new(zone()) LArithmeticD(Token::MOD, left, right); | |
| 807 return MarkAsCall(DefineFixedDouble(result, d0), instr); | |
| 808 } else { | |
| 809 LOperand* left = UseRegisterAtStart(instr->left()); | |
| 810 LOperand* right = UseRegisterAtStart(instr->right()); | |
| 811 LArithmeticD* result = new(zone()) LArithmeticD(op, left, right); | |
| 812 return DefineAsRegister(result); | |
| 813 } | |
| 814 } | |
| 815 | |
| 816 | |
| 817 LInstruction* LChunkBuilder::DoArithmeticT(Token::Value op, | |
| 818 HBinaryOperation* instr) { | |
| 819 DCHECK((op == Token::ADD) || (op == Token::SUB) || (op == Token::MUL) || | |
| 820 (op == Token::DIV) || (op == Token::MOD) || (op == Token::SHR) || | |
| 821 (op == Token::SHL) || (op == Token::SAR) || (op == Token::ROR) || | |
| 822 (op == Token::BIT_OR) || (op == Token::BIT_AND) || | |
| 823 (op == Token::BIT_XOR)); | |
| 824 HValue* left = instr->left(); | |
| 825 HValue* right = instr->right(); | |
| 826 | |
| 827 // TODO(jbramley): Once we've implemented smi support for all arithmetic | |
| 828 // operations, these assertions should check IsTagged(). | |
| 829 DCHECK(instr->representation().IsSmiOrTagged()); | |
| 830 DCHECK(left->representation().IsSmiOrTagged()); | |
| 831 DCHECK(right->representation().IsSmiOrTagged()); | |
| 832 | |
| 833 LOperand* context = UseFixed(instr->context(), cp); | |
| 834 LOperand* left_operand = UseFixed(left, x1); | |
| 835 LOperand* right_operand = UseFixed(right, x0); | |
| 836 LArithmeticT* result = | |
| 837 new(zone()) LArithmeticT(op, context, left_operand, right_operand); | |
| 838 return MarkAsCall(DefineFixed(result, x0), instr); | |
| 839 } | |
| 840 | |
| 841 | |
| 842 LInstruction* LChunkBuilder::DoBoundsCheckBaseIndexInformation( | |
| 843 HBoundsCheckBaseIndexInformation* instr) { | |
| 844 UNREACHABLE(); | |
| 845 return NULL; | |
| 846 } | |
| 847 | |
| 848 | |
| 849 LInstruction* LChunkBuilder::DoAccessArgumentsAt(HAccessArgumentsAt* instr) { | |
| 850 info()->MarkAsRequiresFrame(); | |
| 851 LOperand* args = NULL; | |
| 852 LOperand* length = NULL; | |
| 853 LOperand* index = NULL; | |
| 854 | |
| 855 if (instr->length()->IsConstant() && instr->index()->IsConstant()) { | |
| 856 args = UseRegisterAtStart(instr->arguments()); | |
| 857 length = UseConstant(instr->length()); | |
| 858 index = UseConstant(instr->index()); | |
| 859 } else { | |
| 860 args = UseRegister(instr->arguments()); | |
| 861 length = UseRegisterAtStart(instr->length()); | |
| 862 index = UseRegisterOrConstantAtStart(instr->index()); | |
| 863 } | |
| 864 | |
| 865 return DefineAsRegister(new(zone()) LAccessArgumentsAt(args, length, index)); | |
| 866 } | |
| 867 | |
| 868 | |
| 869 LInstruction* LChunkBuilder::DoAdd(HAdd* instr) { | |
| 870 if (instr->representation().IsSmiOrInteger32()) { | |
| 871 DCHECK(instr->left()->representation().Equals(instr->representation())); | |
| 872 DCHECK(instr->right()->representation().Equals(instr->representation())); | |
| 873 | |
| 874 LInstruction* shifted_operation = TryDoOpWithShiftedRightOperand(instr); | |
| 875 if (shifted_operation != NULL) { | |
| 876 return shifted_operation; | |
| 877 } | |
| 878 | |
| 879 LOperand* left = UseRegisterAtStart(instr->BetterLeftOperand()); | |
| 880 LOperand* right = | |
| 881 UseRegisterOrConstantAtStart(instr->BetterRightOperand()); | |
| 882 LInstruction* result = instr->representation().IsSmi() ? | |
| 883 DefineAsRegister(new(zone()) LAddS(left, right)) : | |
| 884 DefineAsRegister(new(zone()) LAddI(left, right)); | |
| 885 if (instr->CheckFlag(HValue::kCanOverflow)) { | |
| 886 result = AssignEnvironment(result); | |
| 887 } | |
| 888 return result; | |
| 889 } else if (instr->representation().IsExternal()) { | |
| 890 DCHECK(instr->IsConsistentExternalRepresentation()); | |
| 891 DCHECK(!instr->CheckFlag(HValue::kCanOverflow)); | |
| 892 LOperand* left = UseRegisterAtStart(instr->left()); | |
| 893 LOperand* right = UseRegisterOrConstantAtStart(instr->right()); | |
| 894 return DefineAsRegister(new(zone()) LAddE(left, right)); | |
| 895 } else if (instr->representation().IsDouble()) { | |
| 896 return DoArithmeticD(Token::ADD, instr); | |
| 897 } else { | |
| 898 DCHECK(instr->representation().IsTagged()); | |
| 899 return DoArithmeticT(Token::ADD, instr); | |
| 900 } | |
| 901 } | |
| 902 | |
| 903 | |
| 904 LInstruction* LChunkBuilder::DoAllocate(HAllocate* instr) { | |
| 905 info()->MarkAsDeferredCalling(); | |
| 906 LOperand* context = UseAny(instr->context()); | |
| 907 LOperand* size = UseRegisterOrConstant(instr->size()); | |
| 908 LOperand* temp1 = TempRegister(); | |
| 909 LOperand* temp2 = TempRegister(); | |
| 910 LOperand* temp3 = instr->MustPrefillWithFiller() ? TempRegister() : NULL; | |
| 911 LAllocate* result = new(zone()) LAllocate(context, size, temp1, temp2, temp3); | |
| 912 return AssignPointerMap(DefineAsRegister(result)); | |
| 913 } | |
| 914 | |
| 915 | |
| 916 LInstruction* LChunkBuilder::DoApplyArguments(HApplyArguments* instr) { | |
| 917 LOperand* function = UseFixed(instr->function(), x1); | |
| 918 LOperand* receiver = UseFixed(instr->receiver(), x0); | |
| 919 LOperand* length = UseFixed(instr->length(), x2); | |
| 920 LOperand* elements = UseFixed(instr->elements(), x3); | |
| 921 LApplyArguments* result = new(zone()) LApplyArguments(function, | |
| 922 receiver, | |
| 923 length, | |
| 924 elements); | |
| 925 return MarkAsCall(DefineFixed(result, x0), instr, CAN_DEOPTIMIZE_EAGERLY); | |
| 926 } | |
| 927 | |
| 928 | |
| 929 LInstruction* LChunkBuilder::DoArgumentsElements(HArgumentsElements* instr) { | |
| 930 info()->MarkAsRequiresFrame(); | |
| 931 LOperand* temp = instr->from_inlined() ? NULL : TempRegister(); | |
| 932 return DefineAsRegister(new(zone()) LArgumentsElements(temp)); | |
| 933 } | |
| 934 | |
| 935 | |
| 936 LInstruction* LChunkBuilder::DoArgumentsLength(HArgumentsLength* instr) { | |
| 937 info()->MarkAsRequiresFrame(); | |
| 938 LOperand* value = UseRegisterAtStart(instr->value()); | |
| 939 return DefineAsRegister(new(zone()) LArgumentsLength(value)); | |
| 940 } | |
| 941 | |
| 942 | |
| 943 LInstruction* LChunkBuilder::DoArgumentsObject(HArgumentsObject* instr) { | |
| 944 // There are no real uses of the arguments object. | |
| 945 // arguments.length and element access are supported directly on | |
| 946 // stack arguments, and any real arguments object use causes a bailout. | |
| 947 // So this value is never used. | |
| 948 return NULL; | |
| 949 } | |
| 950 | |
| 951 | |
| 952 LInstruction* LChunkBuilder::DoBitwise(HBitwise* instr) { | |
| 953 if (instr->representation().IsSmiOrInteger32()) { | |
| 954 DCHECK(instr->left()->representation().Equals(instr->representation())); | |
| 955 DCHECK(instr->right()->representation().Equals(instr->representation())); | |
| 956 DCHECK(instr->CheckFlag(HValue::kTruncatingToInt32)); | |
| 957 | |
| 958 LInstruction* shifted_operation = TryDoOpWithShiftedRightOperand(instr); | |
| 959 if (shifted_operation != NULL) { | |
| 960 return shifted_operation; | |
| 961 } | |
| 962 | |
| 963 LOperand* left = UseRegisterAtStart(instr->BetterLeftOperand()); | |
| 964 LOperand* right = | |
| 965 UseRegisterOrConstantAtStart(instr->BetterRightOperand()); | |
| 966 return instr->representation().IsSmi() ? | |
| 967 DefineAsRegister(new(zone()) LBitS(left, right)) : | |
| 968 DefineAsRegister(new(zone()) LBitI(left, right)); | |
| 969 } else { | |
| 970 return DoArithmeticT(instr->op(), instr); | |
| 971 } | |
| 972 } | |
| 973 | |
| 974 | |
| 975 LInstruction* LChunkBuilder::DoBlockEntry(HBlockEntry* instr) { | |
| 976 // V8 expects a label to be generated for each basic block. | |
| 977 // This is used in some places like LAllocator::IsBlockBoundary | |
| 978 // in lithium-allocator.cc | |
| 979 return new(zone()) LLabel(instr->block()); | |
| 980 } | |
| 981 | |
| 982 | |
| 983 LInstruction* LChunkBuilder::DoBoundsCheck(HBoundsCheck* instr) { | |
| 984 if (!FLAG_debug_code && instr->skip_check()) return NULL; | |
| 985 LOperand* index = UseRegisterOrConstantAtStart(instr->index()); | |
| 986 LOperand* length = !index->IsConstantOperand() | |
| 987 ? UseRegisterOrConstantAtStart(instr->length()) | |
| 988 : UseRegisterAtStart(instr->length()); | |
| 989 LInstruction* result = new(zone()) LBoundsCheck(index, length); | |
| 990 if (!FLAG_debug_code || !instr->skip_check()) { | |
| 991 result = AssignEnvironment(result); | |
| 992 } | |
| 993 return result; | |
| 994 } | |
| 995 | |
| 996 | |
| 997 LInstruction* LChunkBuilder::DoBranch(HBranch* instr) { | |
| 998 HValue* value = instr->value(); | |
| 999 Representation r = value->representation(); | |
| 1000 HType type = value->type(); | |
| 1001 | |
| 1002 if (r.IsInteger32() || r.IsSmi() || r.IsDouble()) { | |
| 1003 // These representations have simple checks that cannot deoptimize. | |
| 1004 return new(zone()) LBranch(UseRegister(value), NULL, NULL); | |
| 1005 } else { | |
| 1006 DCHECK(r.IsTagged()); | |
| 1007 if (type.IsBoolean() || type.IsSmi() || type.IsJSArray() || | |
| 1008 type.IsHeapNumber()) { | |
| 1009 // These types have simple checks that cannot deoptimize. | |
| 1010 return new(zone()) LBranch(UseRegister(value), NULL, NULL); | |
| 1011 } | |
| 1012 | |
| 1013 if (type.IsString()) { | |
| 1014 // This type cannot deoptimize, but needs a scratch register. | |
| 1015 return new(zone()) LBranch(UseRegister(value), TempRegister(), NULL); | |
| 1016 } | |
| 1017 | |
| 1018 ToBooleanStub::Types expected = instr->expected_input_types(); | |
| 1019 bool needs_temps = expected.NeedsMap() || expected.IsEmpty(); | |
| 1020 LOperand* temp1 = needs_temps ? TempRegister() : NULL; | |
| 1021 LOperand* temp2 = needs_temps ? TempRegister() : NULL; | |
| 1022 | |
| 1023 if (expected.IsGeneric() || expected.IsEmpty()) { | |
| 1024 // The generic case cannot deoptimize because it already supports every | |
| 1025 // possible input type. | |
| 1026 DCHECK(needs_temps); | |
| 1027 return new(zone()) LBranch(UseRegister(value), temp1, temp2); | |
| 1028 } else { | |
| 1029 return AssignEnvironment( | |
| 1030 new(zone()) LBranch(UseRegister(value), temp1, temp2)); | |
| 1031 } | |
| 1032 } | |
| 1033 } | |
| 1034 | |
| 1035 | |
| 1036 LInstruction* LChunkBuilder::DoCallJSFunction( | |
| 1037 HCallJSFunction* instr) { | |
| 1038 LOperand* function = UseFixed(instr->function(), x1); | |
| 1039 | |
| 1040 LCallJSFunction* result = new(zone()) LCallJSFunction(function); | |
| 1041 | |
| 1042 return MarkAsCall(DefineFixed(result, x0), instr); | |
| 1043 } | |
| 1044 | |
| 1045 | |
| 1046 LInstruction* LChunkBuilder::DoCallWithDescriptor( | |
| 1047 HCallWithDescriptor* instr) { | |
| 1048 CallInterfaceDescriptor descriptor = instr->descriptor(); | |
| 1049 | |
| 1050 LOperand* target = UseRegisterOrConstantAtStart(instr->target()); | |
| 1051 ZoneList<LOperand*> ops(instr->OperandCount(), zone()); | |
| 1052 // Target | |
| 1053 ops.Add(target, zone()); | |
| 1054 // Context | |
| 1055 LOperand* op = UseFixed(instr->OperandAt(1), cp); | |
| 1056 ops.Add(op, zone()); | |
| 1057 // Other register parameters | |
| 1058 for (int i = LCallWithDescriptor::kImplicitRegisterParameterCount; | |
| 1059 i < instr->OperandCount(); i++) { | |
| 1060 op = | |
| 1061 UseFixed(instr->OperandAt(i), | |
| 1062 descriptor.GetRegisterParameter( | |
| 1063 i - LCallWithDescriptor::kImplicitRegisterParameterCount)); | |
| 1064 ops.Add(op, zone()); | |
| 1065 } | |
| 1066 | |
| 1067 LCallWithDescriptor* result = new(zone()) LCallWithDescriptor(descriptor, | |
| 1068 ops, | |
| 1069 zone()); | |
| 1070 return MarkAsCall(DefineFixed(result, x0), instr); | |
| 1071 } | |
| 1072 | |
| 1073 | |
| 1074 LInstruction* LChunkBuilder::DoCallFunction(HCallFunction* instr) { | |
| 1075 LOperand* context = UseFixed(instr->context(), cp); | |
| 1076 LOperand* function = UseFixed(instr->function(), x1); | |
| 1077 LOperand* slot = NULL; | |
| 1078 LOperand* vector = NULL; | |
| 1079 if (instr->HasVectorAndSlot()) { | |
| 1080 slot = FixedTemp(x3); | |
| 1081 vector = FixedTemp(x2); | |
| 1082 } | |
| 1083 | |
| 1084 LCallFunction* call = | |
| 1085 new (zone()) LCallFunction(context, function, slot, vector); | |
| 1086 return MarkAsCall(DefineFixed(call, x0), instr); | |
| 1087 } | |
| 1088 | |
| 1089 | |
| 1090 LInstruction* LChunkBuilder::DoCallNew(HCallNew* instr) { | |
| 1091 LOperand* context = UseFixed(instr->context(), cp); | |
| 1092 // The call to CallConstructStub will expect the constructor to be in x1. | |
| 1093 LOperand* constructor = UseFixed(instr->constructor(), x1); | |
| 1094 LCallNew* result = new(zone()) LCallNew(context, constructor); | |
| 1095 return MarkAsCall(DefineFixed(result, x0), instr); | |
| 1096 } | |
| 1097 | |
| 1098 | |
| 1099 LInstruction* LChunkBuilder::DoCallNewArray(HCallNewArray* instr) { | |
| 1100 LOperand* context = UseFixed(instr->context(), cp); | |
| 1101 // The call to ArrayConstructCode will expect the constructor to be in x1. | |
| 1102 LOperand* constructor = UseFixed(instr->constructor(), x1); | |
| 1103 LCallNewArray* result = new(zone()) LCallNewArray(context, constructor); | |
| 1104 return MarkAsCall(DefineFixed(result, x0), instr); | |
| 1105 } | |
| 1106 | |
| 1107 | |
| 1108 LInstruction* LChunkBuilder::DoCallRuntime(HCallRuntime* instr) { | |
| 1109 LOperand* context = UseFixed(instr->context(), cp); | |
| 1110 return MarkAsCall(DefineFixed(new(zone()) LCallRuntime(context), x0), instr); | |
| 1111 } | |
| 1112 | |
| 1113 | |
| 1114 LInstruction* LChunkBuilder::DoCallStub(HCallStub* instr) { | |
| 1115 LOperand* context = UseFixed(instr->context(), cp); | |
| 1116 return MarkAsCall(DefineFixed(new(zone()) LCallStub(context), x0), instr); | |
| 1117 } | |
| 1118 | |
| 1119 | |
| 1120 LInstruction* LChunkBuilder::DoCapturedObject(HCapturedObject* instr) { | |
| 1121 instr->ReplayEnvironment(current_block_->last_environment()); | |
| 1122 | |
| 1123 // There are no real uses of a captured object. | |
| 1124 return NULL; | |
| 1125 } | |
| 1126 | |
| 1127 | |
| 1128 LInstruction* LChunkBuilder::DoChange(HChange* instr) { | |
| 1129 Representation from = instr->from(); | |
| 1130 Representation to = instr->to(); | |
| 1131 HValue* val = instr->value(); | |
| 1132 if (from.IsSmi()) { | |
| 1133 if (to.IsTagged()) { | |
| 1134 LOperand* value = UseRegister(val); | |
| 1135 return DefineSameAsFirst(new(zone()) LDummyUse(value)); | |
| 1136 } | |
| 1137 from = Representation::Tagged(); | |
| 1138 } | |
| 1139 if (from.IsTagged()) { | |
| 1140 if (to.IsDouble()) { | |
| 1141 LOperand* value = UseRegister(val); | |
| 1142 LOperand* temp = TempRegister(); | |
| 1143 LInstruction* result = | |
| 1144 DefineAsRegister(new(zone()) LNumberUntagD(value, temp)); | |
| 1145 if (!val->representation().IsSmi()) result = AssignEnvironment(result); | |
| 1146 return result; | |
| 1147 } else if (to.IsSmi()) { | |
| 1148 LOperand* value = UseRegister(val); | |
| 1149 if (val->type().IsSmi()) { | |
| 1150 return DefineSameAsFirst(new(zone()) LDummyUse(value)); | |
| 1151 } | |
| 1152 return AssignEnvironment(DefineSameAsFirst(new(zone()) LCheckSmi(value))); | |
| 1153 } else { | |
| 1154 DCHECK(to.IsInteger32()); | |
| 1155 if (val->type().IsSmi() || val->representation().IsSmi()) { | |
| 1156 LOperand* value = UseRegisterAtStart(val); | |
| 1157 return DefineAsRegister(new(zone()) LSmiUntag(value, false)); | |
| 1158 } else { | |
| 1159 LOperand* value = UseRegister(val); | |
| 1160 LOperand* temp1 = TempRegister(); | |
| 1161 LOperand* temp2 = instr->CanTruncateToInt32() | |
| 1162 ? NULL : TempDoubleRegister(); | |
| 1163 LInstruction* result = | |
| 1164 DefineAsRegister(new(zone()) LTaggedToI(value, temp1, temp2)); | |
| 1165 if (!val->representation().IsSmi()) result = AssignEnvironment(result); | |
| 1166 return result; | |
| 1167 } | |
| 1168 } | |
| 1169 } else if (from.IsDouble()) { | |
| 1170 if (to.IsTagged()) { | |
| 1171 info()->MarkAsDeferredCalling(); | |
| 1172 LOperand* value = UseRegister(val); | |
| 1173 LOperand* temp1 = TempRegister(); | |
| 1174 LOperand* temp2 = TempRegister(); | |
| 1175 LNumberTagD* result = new(zone()) LNumberTagD(value, temp1, temp2); | |
| 1176 return AssignPointerMap(DefineAsRegister(result)); | |
| 1177 } else { | |
| 1178 DCHECK(to.IsSmi() || to.IsInteger32()); | |
| 1179 if (instr->CanTruncateToInt32()) { | |
| 1180 LOperand* value = UseRegister(val); | |
| 1181 return DefineAsRegister(new(zone()) LTruncateDoubleToIntOrSmi(value)); | |
| 1182 } else { | |
| 1183 LOperand* value = UseRegister(val); | |
| 1184 LDoubleToIntOrSmi* result = new(zone()) LDoubleToIntOrSmi(value); | |
| 1185 return AssignEnvironment(DefineAsRegister(result)); | |
| 1186 } | |
| 1187 } | |
| 1188 } else if (from.IsInteger32()) { | |
| 1189 info()->MarkAsDeferredCalling(); | |
| 1190 if (to.IsTagged()) { | |
| 1191 if (val->CheckFlag(HInstruction::kUint32)) { | |
| 1192 LOperand* value = UseRegister(val); | |
| 1193 LNumberTagU* result = | |
| 1194 new(zone()) LNumberTagU(value, TempRegister(), TempRegister()); | |
| 1195 return AssignPointerMap(DefineAsRegister(result)); | |
| 1196 } else { | |
| 1197 STATIC_ASSERT((kMinInt == Smi::kMinValue) && | |
| 1198 (kMaxInt == Smi::kMaxValue)); | |
| 1199 LOperand* value = UseRegisterAtStart(val); | |
| 1200 return DefineAsRegister(new(zone()) LSmiTag(value)); | |
| 1201 } | |
| 1202 } else if (to.IsSmi()) { | |
| 1203 LOperand* value = UseRegisterAtStart(val); | |
| 1204 LInstruction* result = DefineAsRegister(new(zone()) LSmiTag(value)); | |
| 1205 if (instr->CheckFlag(HValue::kCanOverflow)) { | |
| 1206 result = AssignEnvironment(result); | |
| 1207 } | |
| 1208 return result; | |
| 1209 } else { | |
| 1210 DCHECK(to.IsDouble()); | |
| 1211 if (val->CheckFlag(HInstruction::kUint32)) { | |
| 1212 return DefineAsRegister( | |
| 1213 new(zone()) LUint32ToDouble(UseRegisterAtStart(val))); | |
| 1214 } else { | |
| 1215 return DefineAsRegister( | |
| 1216 new(zone()) LInteger32ToDouble(UseRegisterAtStart(val))); | |
| 1217 } | |
| 1218 } | |
| 1219 } | |
| 1220 UNREACHABLE(); | |
| 1221 return NULL; | |
| 1222 } | |
| 1223 | |
| 1224 | |
| 1225 LInstruction* LChunkBuilder::DoCheckValue(HCheckValue* instr) { | |
| 1226 LOperand* value = UseRegisterAtStart(instr->value()); | |
| 1227 return AssignEnvironment(new(zone()) LCheckValue(value)); | |
| 1228 } | |
| 1229 | |
| 1230 | |
| 1231 LInstruction* LChunkBuilder::DoCheckArrayBufferNotNeutered( | |
| 1232 HCheckArrayBufferNotNeutered* instr) { | |
| 1233 LOperand* view = UseRegisterAtStart(instr->value()); | |
| 1234 LCheckArrayBufferNotNeutered* result = | |
| 1235 new (zone()) LCheckArrayBufferNotNeutered(view); | |
| 1236 return AssignEnvironment(result); | |
| 1237 } | |
| 1238 | |
| 1239 | |
| 1240 LInstruction* LChunkBuilder::DoCheckInstanceType(HCheckInstanceType* instr) { | |
| 1241 LOperand* value = UseRegisterAtStart(instr->value()); | |
| 1242 LOperand* temp = TempRegister(); | |
| 1243 LInstruction* result = new(zone()) LCheckInstanceType(value, temp); | |
| 1244 return AssignEnvironment(result); | |
| 1245 } | |
| 1246 | |
| 1247 | |
| 1248 LInstruction* LChunkBuilder::DoCheckMaps(HCheckMaps* instr) { | |
| 1249 if (instr->IsStabilityCheck()) return new(zone()) LCheckMaps; | |
| 1250 LOperand* value = UseRegisterAtStart(instr->value()); | |
| 1251 LOperand* temp = TempRegister(); | |
| 1252 LInstruction* result = AssignEnvironment(new(zone()) LCheckMaps(value, temp)); | |
| 1253 if (instr->HasMigrationTarget()) { | |
| 1254 info()->MarkAsDeferredCalling(); | |
| 1255 result = AssignPointerMap(result); | |
| 1256 } | |
| 1257 return result; | |
| 1258 } | |
| 1259 | |
| 1260 | |
| 1261 LInstruction* LChunkBuilder::DoCheckHeapObject(HCheckHeapObject* instr) { | |
| 1262 LOperand* value = UseRegisterAtStart(instr->value()); | |
| 1263 LInstruction* result = new(zone()) LCheckNonSmi(value); | |
| 1264 if (!instr->value()->type().IsHeapObject()) { | |
| 1265 result = AssignEnvironment(result); | |
| 1266 } | |
| 1267 return result; | |
| 1268 } | |
| 1269 | |
| 1270 | |
| 1271 LInstruction* LChunkBuilder::DoCheckSmi(HCheckSmi* instr) { | |
| 1272 LOperand* value = UseRegisterAtStart(instr->value()); | |
| 1273 return AssignEnvironment(new(zone()) LCheckSmi(value)); | |
| 1274 } | |
| 1275 | |
| 1276 | |
| 1277 LInstruction* LChunkBuilder::DoClampToUint8(HClampToUint8* instr) { | |
| 1278 HValue* value = instr->value(); | |
| 1279 Representation input_rep = value->representation(); | |
| 1280 LOperand* reg = UseRegister(value); | |
| 1281 if (input_rep.IsDouble()) { | |
| 1282 return DefineAsRegister(new(zone()) LClampDToUint8(reg)); | |
| 1283 } else if (input_rep.IsInteger32()) { | |
| 1284 return DefineAsRegister(new(zone()) LClampIToUint8(reg)); | |
| 1285 } else { | |
| 1286 DCHECK(input_rep.IsSmiOrTagged()); | |
| 1287 return AssignEnvironment( | |
| 1288 DefineAsRegister(new(zone()) LClampTToUint8(reg, | |
| 1289 TempDoubleRegister()))); | |
| 1290 } | |
| 1291 } | |
| 1292 | |
| 1293 | |
| 1294 LInstruction* LChunkBuilder::DoClassOfTestAndBranch( | |
| 1295 HClassOfTestAndBranch* instr) { | |
| 1296 DCHECK(instr->value()->representation().IsTagged()); | |
| 1297 LOperand* value = UseRegisterAtStart(instr->value()); | |
| 1298 return new(zone()) LClassOfTestAndBranch(value, | |
| 1299 TempRegister(), | |
| 1300 TempRegister()); | |
| 1301 } | |
| 1302 | |
| 1303 | |
| 1304 LInstruction* LChunkBuilder::DoCompareNumericAndBranch( | |
| 1305 HCompareNumericAndBranch* instr) { | |
| 1306 Representation r = instr->representation(); | |
| 1307 if (r.IsSmiOrInteger32()) { | |
| 1308 DCHECK(instr->left()->representation().Equals(r)); | |
| 1309 DCHECK(instr->right()->representation().Equals(r)); | |
| 1310 LOperand* left = UseRegisterOrConstantAtStart(instr->left()); | |
| 1311 LOperand* right = UseRegisterOrConstantAtStart(instr->right()); | |
| 1312 return new(zone()) LCompareNumericAndBranch(left, right); | |
| 1313 } else { | |
| 1314 DCHECK(r.IsDouble()); | |
| 1315 DCHECK(instr->left()->representation().IsDouble()); | |
| 1316 DCHECK(instr->right()->representation().IsDouble()); | |
| 1317 if (instr->left()->IsConstant() && instr->right()->IsConstant()) { | |
| 1318 LOperand* left = UseConstant(instr->left()); | |
| 1319 LOperand* right = UseConstant(instr->right()); | |
| 1320 return new(zone()) LCompareNumericAndBranch(left, right); | |
| 1321 } | |
| 1322 LOperand* left = UseRegisterAtStart(instr->left()); | |
| 1323 LOperand* right = UseRegisterAtStart(instr->right()); | |
| 1324 return new(zone()) LCompareNumericAndBranch(left, right); | |
| 1325 } | |
| 1326 } | |
| 1327 | |
| 1328 | |
| 1329 LInstruction* LChunkBuilder::DoCompareGeneric(HCompareGeneric* instr) { | |
| 1330 DCHECK(instr->left()->representation().IsTagged()); | |
| 1331 DCHECK(instr->right()->representation().IsTagged()); | |
| 1332 LOperand* context = UseFixed(instr->context(), cp); | |
| 1333 LOperand* left = UseFixed(instr->left(), x1); | |
| 1334 LOperand* right = UseFixed(instr->right(), x0); | |
| 1335 LCmpT* result = new(zone()) LCmpT(context, left, right); | |
| 1336 return MarkAsCall(DefineFixed(result, x0), instr); | |
| 1337 } | |
| 1338 | |
| 1339 | |
| 1340 LInstruction* LChunkBuilder::DoCompareHoleAndBranch( | |
| 1341 HCompareHoleAndBranch* instr) { | |
| 1342 LOperand* value = UseRegister(instr->value()); | |
| 1343 if (instr->representation().IsTagged()) { | |
| 1344 return new(zone()) LCmpHoleAndBranchT(value); | |
| 1345 } else { | |
| 1346 LOperand* temp = TempRegister(); | |
| 1347 return new(zone()) LCmpHoleAndBranchD(value, temp); | |
| 1348 } | |
| 1349 } | |
| 1350 | |
| 1351 | |
| 1352 LInstruction* LChunkBuilder::DoCompareObjectEqAndBranch( | |
| 1353 HCompareObjectEqAndBranch* instr) { | |
| 1354 LOperand* left = UseRegisterAtStart(instr->left()); | |
| 1355 LOperand* right = UseRegisterAtStart(instr->right()); | |
| 1356 return new(zone()) LCmpObjectEqAndBranch(left, right); | |
| 1357 } | |
| 1358 | |
| 1359 | |
| 1360 LInstruction* LChunkBuilder::DoCompareMap(HCompareMap* instr) { | |
| 1361 DCHECK(instr->value()->representation().IsTagged()); | |
| 1362 LOperand* value = UseRegisterAtStart(instr->value()); | |
| 1363 LOperand* temp = TempRegister(); | |
| 1364 return new(zone()) LCmpMapAndBranch(value, temp); | |
| 1365 } | |
| 1366 | |
| 1367 | |
| 1368 LInstruction* LChunkBuilder::DoConstant(HConstant* instr) { | |
| 1369 Representation r = instr->representation(); | |
| 1370 if (r.IsSmi()) { | |
| 1371 return DefineAsRegister(new(zone()) LConstantS); | |
| 1372 } else if (r.IsInteger32()) { | |
| 1373 return DefineAsRegister(new(zone()) LConstantI); | |
| 1374 } else if (r.IsDouble()) { | |
| 1375 return DefineAsRegister(new(zone()) LConstantD); | |
| 1376 } else if (r.IsExternal()) { | |
| 1377 return DefineAsRegister(new(zone()) LConstantE); | |
| 1378 } else if (r.IsTagged()) { | |
| 1379 return DefineAsRegister(new(zone()) LConstantT); | |
| 1380 } else { | |
| 1381 UNREACHABLE(); | |
| 1382 return NULL; | |
| 1383 } | |
| 1384 } | |
| 1385 | |
| 1386 | |
| 1387 LInstruction* LChunkBuilder::DoContext(HContext* instr) { | |
| 1388 if (instr->HasNoUses()) return NULL; | |
| 1389 | |
| 1390 if (info()->IsStub()) { | |
| 1391 return DefineFixed(new(zone()) LContext, cp); | |
| 1392 } | |
| 1393 | |
| 1394 return DefineAsRegister(new(zone()) LContext); | |
| 1395 } | |
| 1396 | |
| 1397 | |
| 1398 LInstruction* LChunkBuilder::DoDateField(HDateField* instr) { | |
| 1399 LOperand* object = UseFixed(instr->value(), x0); | |
| 1400 LDateField* result = new(zone()) LDateField(object, instr->index()); | |
| 1401 return MarkAsCall(DefineFixed(result, x0), instr, CANNOT_DEOPTIMIZE_EAGERLY); | |
| 1402 } | |
| 1403 | |
| 1404 | |
| 1405 LInstruction* LChunkBuilder::DoDebugBreak(HDebugBreak* instr) { | |
| 1406 return new(zone()) LDebugBreak(); | |
| 1407 } | |
| 1408 | |
| 1409 | |
| 1410 LInstruction* LChunkBuilder::DoDeclareGlobals(HDeclareGlobals* instr) { | |
| 1411 LOperand* context = UseFixed(instr->context(), cp); | |
| 1412 return MarkAsCall(new(zone()) LDeclareGlobals(context), instr); | |
| 1413 } | |
| 1414 | |
| 1415 | |
| 1416 LInstruction* LChunkBuilder::DoDeoptimize(HDeoptimize* instr) { | |
| 1417 return AssignEnvironment(new(zone()) LDeoptimize); | |
| 1418 } | |
| 1419 | |
| 1420 | |
| 1421 LInstruction* LChunkBuilder::DoDivByPowerOf2I(HDiv* instr) { | |
| 1422 DCHECK(instr->representation().IsInteger32()); | |
| 1423 DCHECK(instr->left()->representation().Equals(instr->representation())); | |
| 1424 DCHECK(instr->right()->representation().Equals(instr->representation())); | |
| 1425 LOperand* dividend = UseRegister(instr->left()); | |
| 1426 int32_t divisor = instr->right()->GetInteger32Constant(); | |
| 1427 LInstruction* result = DefineAsRegister(new(zone()) LDivByPowerOf2I( | |
| 1428 dividend, divisor)); | |
| 1429 if ((instr->CheckFlag(HValue::kBailoutOnMinusZero) && divisor < 0) || | |
| 1430 (instr->CheckFlag(HValue::kCanOverflow) && divisor == -1) || | |
| 1431 (!instr->CheckFlag(HInstruction::kAllUsesTruncatingToInt32) && | |
| 1432 divisor != 1 && divisor != -1)) { | |
| 1433 result = AssignEnvironment(result); | |
| 1434 } | |
| 1435 return result; | |
| 1436 } | |
| 1437 | |
| 1438 | |
| 1439 LInstruction* LChunkBuilder::DoDivByConstI(HDiv* instr) { | |
| 1440 DCHECK(instr->representation().IsInteger32()); | |
| 1441 DCHECK(instr->left()->representation().Equals(instr->representation())); | |
| 1442 DCHECK(instr->right()->representation().Equals(instr->representation())); | |
| 1443 LOperand* dividend = UseRegister(instr->left()); | |
| 1444 int32_t divisor = instr->right()->GetInteger32Constant(); | |
| 1445 LOperand* temp = instr->CheckFlag(HInstruction::kAllUsesTruncatingToInt32) | |
| 1446 ? NULL : TempRegister(); | |
| 1447 LInstruction* result = DefineAsRegister(new(zone()) LDivByConstI( | |
| 1448 dividend, divisor, temp)); | |
| 1449 if (divisor == 0 || | |
| 1450 (instr->CheckFlag(HValue::kBailoutOnMinusZero) && divisor < 0) || | |
| 1451 !instr->CheckFlag(HInstruction::kAllUsesTruncatingToInt32)) { | |
| 1452 result = AssignEnvironment(result); | |
| 1453 } | |
| 1454 return result; | |
| 1455 } | |
| 1456 | |
| 1457 | |
| 1458 LInstruction* LChunkBuilder::DoDivI(HBinaryOperation* instr) { | |
| 1459 DCHECK(instr->representation().IsSmiOrInteger32()); | |
| 1460 DCHECK(instr->left()->representation().Equals(instr->representation())); | |
| 1461 DCHECK(instr->right()->representation().Equals(instr->representation())); | |
| 1462 LOperand* dividend = UseRegister(instr->left()); | |
| 1463 LOperand* divisor = UseRegister(instr->right()); | |
| 1464 LOperand* temp = instr->CheckFlag(HInstruction::kAllUsesTruncatingToInt32) | |
| 1465 ? NULL : TempRegister(); | |
| 1466 LInstruction* result = | |
| 1467 DefineAsRegister(new(zone()) LDivI(dividend, divisor, temp)); | |
| 1468 if (!instr->CheckFlag(HValue::kAllUsesTruncatingToInt32)) { | |
| 1469 result = AssignEnvironment(result); | |
| 1470 } | |
| 1471 return result; | |
| 1472 } | |
| 1473 | |
| 1474 | |
| 1475 LInstruction* LChunkBuilder::DoDiv(HDiv* instr) { | |
| 1476 if (instr->representation().IsSmiOrInteger32()) { | |
| 1477 if (instr->RightIsPowerOf2()) { | |
| 1478 return DoDivByPowerOf2I(instr); | |
| 1479 } else if (instr->right()->IsConstant()) { | |
| 1480 return DoDivByConstI(instr); | |
| 1481 } else { | |
| 1482 return DoDivI(instr); | |
| 1483 } | |
| 1484 } else if (instr->representation().IsDouble()) { | |
| 1485 return DoArithmeticD(Token::DIV, instr); | |
| 1486 } else { | |
| 1487 return DoArithmeticT(Token::DIV, instr); | |
| 1488 } | |
| 1489 } | |
| 1490 | |
| 1491 | |
| 1492 LInstruction* LChunkBuilder::DoDummyUse(HDummyUse* instr) { | |
| 1493 return DefineAsRegister(new(zone()) LDummyUse(UseAny(instr->value()))); | |
| 1494 } | |
| 1495 | |
| 1496 | |
| 1497 LInstruction* LChunkBuilder::DoEnterInlined(HEnterInlined* instr) { | |
| 1498 HEnvironment* outer = current_block_->last_environment(); | |
| 1499 outer->set_ast_id(instr->ReturnId()); | |
| 1500 HConstant* undefined = graph()->GetConstantUndefined(); | |
| 1501 HEnvironment* inner = outer->CopyForInlining(instr->closure(), | |
| 1502 instr->arguments_count(), | |
| 1503 instr->function(), | |
| 1504 undefined, | |
| 1505 instr->inlining_kind()); | |
| 1506 // Only replay binding of arguments object if it wasn't removed from graph. | |
| 1507 if ((instr->arguments_var() != NULL) && | |
| 1508 instr->arguments_object()->IsLinked()) { | |
| 1509 inner->Bind(instr->arguments_var(), instr->arguments_object()); | |
| 1510 } | |
| 1511 inner->BindContext(instr->closure_context()); | |
| 1512 inner->set_entry(instr); | |
| 1513 current_block_->UpdateEnvironment(inner); | |
| 1514 chunk_->AddInlinedFunction(instr->shared()); | |
| 1515 return NULL; | |
| 1516 } | |
| 1517 | |
| 1518 | |
| 1519 LInstruction* LChunkBuilder::DoEnvironmentMarker(HEnvironmentMarker* instr) { | |
| 1520 UNREACHABLE(); | |
| 1521 return NULL; | |
| 1522 } | |
| 1523 | |
| 1524 | |
| 1525 LInstruction* LChunkBuilder::DoForceRepresentation( | |
| 1526 HForceRepresentation* instr) { | |
| 1527 // All HForceRepresentation instructions should be eliminated in the | |
| 1528 // representation change phase of Hydrogen. | |
| 1529 UNREACHABLE(); | |
| 1530 return NULL; | |
| 1531 } | |
| 1532 | |
| 1533 | |
| 1534 LInstruction* LChunkBuilder::DoGetCachedArrayIndex( | |
| 1535 HGetCachedArrayIndex* instr) { | |
| 1536 DCHECK(instr->value()->representation().IsTagged()); | |
| 1537 LOperand* value = UseRegisterAtStart(instr->value()); | |
| 1538 return DefineAsRegister(new(zone()) LGetCachedArrayIndex(value)); | |
| 1539 } | |
| 1540 | |
| 1541 | |
| 1542 LInstruction* LChunkBuilder::DoGoto(HGoto* instr) { | |
| 1543 return new(zone()) LGoto(instr->FirstSuccessor()); | |
| 1544 } | |
| 1545 | |
| 1546 | |
| 1547 LInstruction* LChunkBuilder::DoHasCachedArrayIndexAndBranch( | |
| 1548 HHasCachedArrayIndexAndBranch* instr) { | |
| 1549 DCHECK(instr->value()->representation().IsTagged()); | |
| 1550 return new(zone()) LHasCachedArrayIndexAndBranch( | |
| 1551 UseRegisterAtStart(instr->value()), TempRegister()); | |
| 1552 } | |
| 1553 | |
| 1554 | |
| 1555 LInstruction* LChunkBuilder::DoHasInstanceTypeAndBranch( | |
| 1556 HHasInstanceTypeAndBranch* instr) { | |
| 1557 DCHECK(instr->value()->representation().IsTagged()); | |
| 1558 LOperand* value = UseRegisterAtStart(instr->value()); | |
| 1559 return new(zone()) LHasInstanceTypeAndBranch(value, TempRegister()); | |
| 1560 } | |
| 1561 | |
| 1562 | |
| 1563 LInstruction* LChunkBuilder::DoInnerAllocatedObject( | |
| 1564 HInnerAllocatedObject* instr) { | |
| 1565 LOperand* base_object = UseRegisterAtStart(instr->base_object()); | |
| 1566 LOperand* offset = UseRegisterOrConstantAtStart(instr->offset()); | |
| 1567 return DefineAsRegister( | |
| 1568 new(zone()) LInnerAllocatedObject(base_object, offset)); | |
| 1569 } | |
| 1570 | |
| 1571 | |
| 1572 LInstruction* LChunkBuilder::DoInstanceOf(HInstanceOf* instr) { | |
| 1573 LOperand* left = | |
| 1574 UseFixed(instr->left(), InstanceOfDescriptor::LeftRegister()); | |
| 1575 LOperand* right = | |
| 1576 UseFixed(instr->right(), InstanceOfDescriptor::RightRegister()); | |
| 1577 LOperand* context = UseFixed(instr->context(), cp); | |
| 1578 LInstanceOf* result = new (zone()) LInstanceOf(context, left, right); | |
| 1579 return MarkAsCall(DefineFixed(result, x0), instr); | |
| 1580 } | |
| 1581 | |
| 1582 | |
| 1583 LInstruction* LChunkBuilder::DoHasInPrototypeChainAndBranch( | |
| 1584 HHasInPrototypeChainAndBranch* instr) { | |
| 1585 LOperand* object = UseRegister(instr->object()); | |
| 1586 LOperand* prototype = UseRegister(instr->prototype()); | |
| 1587 LOperand* scratch = TempRegister(); | |
| 1588 return new (zone()) LHasInPrototypeChainAndBranch(object, prototype, scratch); | |
| 1589 } | |
| 1590 | |
| 1591 | |
| 1592 LInstruction* LChunkBuilder::DoInvokeFunction(HInvokeFunction* instr) { | |
| 1593 LOperand* context = UseFixed(instr->context(), cp); | |
| 1594 // The function is required (by MacroAssembler::InvokeFunction) to be in x1. | |
| 1595 LOperand* function = UseFixed(instr->function(), x1); | |
| 1596 LInvokeFunction* result = new(zone()) LInvokeFunction(context, function); | |
| 1597 return MarkAsCall(DefineFixed(result, x0), instr, CANNOT_DEOPTIMIZE_EAGERLY); | |
| 1598 } | |
| 1599 | |
| 1600 | |
| 1601 LInstruction* LChunkBuilder::DoIsConstructCallAndBranch( | |
| 1602 HIsConstructCallAndBranch* instr) { | |
| 1603 return new(zone()) LIsConstructCallAndBranch(TempRegister(), TempRegister()); | |
| 1604 } | |
| 1605 | |
| 1606 | |
| 1607 LInstruction* LChunkBuilder::DoCompareMinusZeroAndBranch( | |
| 1608 HCompareMinusZeroAndBranch* instr) { | |
| 1609 LOperand* value = UseRegister(instr->value()); | |
| 1610 LOperand* scratch = TempRegister(); | |
| 1611 return new(zone()) LCompareMinusZeroAndBranch(value, scratch); | |
| 1612 } | |
| 1613 | |
| 1614 | |
| 1615 LInstruction* LChunkBuilder::DoIsStringAndBranch(HIsStringAndBranch* instr) { | |
| 1616 DCHECK(instr->value()->representation().IsTagged()); | |
| 1617 LOperand* value = UseRegisterAtStart(instr->value()); | |
| 1618 LOperand* temp = TempRegister(); | |
| 1619 return new(zone()) LIsStringAndBranch(value, temp); | |
| 1620 } | |
| 1621 | |
| 1622 | |
| 1623 LInstruction* LChunkBuilder::DoIsSmiAndBranch(HIsSmiAndBranch* instr) { | |
| 1624 DCHECK(instr->value()->representation().IsTagged()); | |
| 1625 return new(zone()) LIsSmiAndBranch(UseRegisterAtStart(instr->value())); | |
| 1626 } | |
| 1627 | |
| 1628 | |
| 1629 LInstruction* LChunkBuilder::DoIsUndetectableAndBranch( | |
| 1630 HIsUndetectableAndBranch* instr) { | |
| 1631 DCHECK(instr->value()->representation().IsTagged()); | |
| 1632 LOperand* value = UseRegisterAtStart(instr->value()); | |
| 1633 return new(zone()) LIsUndetectableAndBranch(value, TempRegister()); | |
| 1634 } | |
| 1635 | |
| 1636 | |
| 1637 LInstruction* LChunkBuilder::DoLeaveInlined(HLeaveInlined* instr) { | |
| 1638 LInstruction* pop = NULL; | |
| 1639 HEnvironment* env = current_block_->last_environment(); | |
| 1640 | |
| 1641 if (env->entry()->arguments_pushed()) { | |
| 1642 int argument_count = env->arguments_environment()->parameter_count(); | |
| 1643 pop = new(zone()) LDrop(argument_count); | |
| 1644 DCHECK(instr->argument_delta() == -argument_count); | |
| 1645 } | |
| 1646 | |
| 1647 HEnvironment* outer = | |
| 1648 current_block_->last_environment()->DiscardInlined(false); | |
| 1649 current_block_->UpdateEnvironment(outer); | |
| 1650 | |
| 1651 return pop; | |
| 1652 } | |
| 1653 | |
| 1654 | |
| 1655 LInstruction* LChunkBuilder::DoLoadContextSlot(HLoadContextSlot* instr) { | |
| 1656 LOperand* context = UseRegisterAtStart(instr->value()); | |
| 1657 LInstruction* result = | |
| 1658 DefineAsRegister(new(zone()) LLoadContextSlot(context)); | |
| 1659 if (instr->RequiresHoleCheck() && instr->DeoptimizesOnHole()) { | |
| 1660 result = AssignEnvironment(result); | |
| 1661 } | |
| 1662 return result; | |
| 1663 } | |
| 1664 | |
| 1665 | |
| 1666 LInstruction* LChunkBuilder::DoLoadFunctionPrototype( | |
| 1667 HLoadFunctionPrototype* instr) { | |
| 1668 LOperand* function = UseRegister(instr->function()); | |
| 1669 LOperand* temp = TempRegister(); | |
| 1670 return AssignEnvironment(DefineAsRegister( | |
| 1671 new(zone()) LLoadFunctionPrototype(function, temp))); | |
| 1672 } | |
| 1673 | |
| 1674 | |
| 1675 LInstruction* LChunkBuilder::DoLoadGlobalGeneric(HLoadGlobalGeneric* instr) { | |
| 1676 LOperand* context = UseFixed(instr->context(), cp); | |
| 1677 LOperand* global_object = | |
| 1678 UseFixed(instr->global_object(), LoadDescriptor::ReceiverRegister()); | |
| 1679 LOperand* vector = NULL; | |
| 1680 if (instr->HasVectorAndSlot()) { | |
| 1681 vector = FixedTemp(LoadWithVectorDescriptor::VectorRegister()); | |
| 1682 } | |
| 1683 | |
| 1684 LLoadGlobalGeneric* result = | |
| 1685 new(zone()) LLoadGlobalGeneric(context, global_object, vector); | |
| 1686 return MarkAsCall(DefineFixed(result, x0), instr); | |
| 1687 } | |
| 1688 | |
| 1689 | |
| 1690 LInstruction* LChunkBuilder::DoLoadGlobalViaContext( | |
| 1691 HLoadGlobalViaContext* instr) { | |
| 1692 LOperand* context = UseFixed(instr->context(), cp); | |
| 1693 DCHECK(instr->slot_index() > 0); | |
| 1694 LLoadGlobalViaContext* result = new (zone()) LLoadGlobalViaContext(context); | |
| 1695 return MarkAsCall(DefineFixed(result, x0), instr); | |
| 1696 } | |
| 1697 | |
| 1698 | |
| 1699 LInstruction* LChunkBuilder::DoLoadKeyed(HLoadKeyed* instr) { | |
| 1700 DCHECK(instr->key()->representation().IsSmiOrInteger32()); | |
| 1701 ElementsKind elements_kind = instr->elements_kind(); | |
| 1702 LOperand* elements = UseRegister(instr->elements()); | |
| 1703 LOperand* key = UseRegisterOrConstant(instr->key()); | |
| 1704 | |
| 1705 if (!instr->is_fixed_typed_array()) { | |
| 1706 if (instr->representation().IsDouble()) { | |
| 1707 LOperand* temp = (!instr->key()->IsConstant() || | |
| 1708 instr->RequiresHoleCheck()) | |
| 1709 ? TempRegister() | |
| 1710 : NULL; | |
| 1711 LInstruction* result = DefineAsRegister( | |
| 1712 new (zone()) LLoadKeyedFixedDouble(elements, key, temp)); | |
| 1713 if (instr->RequiresHoleCheck()) { | |
| 1714 result = AssignEnvironment(result); | |
| 1715 } | |
| 1716 return result; | |
| 1717 } else { | |
| 1718 DCHECK(instr->representation().IsSmiOrTagged() || | |
| 1719 instr->representation().IsInteger32()); | |
| 1720 LOperand* temp = instr->key()->IsConstant() ? NULL : TempRegister(); | |
| 1721 LInstruction* result = | |
| 1722 DefineAsRegister(new (zone()) LLoadKeyedFixed(elements, key, temp)); | |
| 1723 if (instr->RequiresHoleCheck() || | |
| 1724 (instr->hole_mode() == CONVERT_HOLE_TO_UNDEFINED && | |
| 1725 info()->IsStub())) { | |
| 1726 result = AssignEnvironment(result); | |
| 1727 } | |
| 1728 return result; | |
| 1729 } | |
| 1730 } else { | |
| 1731 DCHECK((instr->representation().IsInteger32() && | |
| 1732 !IsDoubleOrFloatElementsKind(instr->elements_kind())) || | |
| 1733 (instr->representation().IsDouble() && | |
| 1734 IsDoubleOrFloatElementsKind(instr->elements_kind()))); | |
| 1735 | |
| 1736 LOperand* temp = instr->key()->IsConstant() ? NULL : TempRegister(); | |
| 1737 LInstruction* result = DefineAsRegister( | |
| 1738 new(zone()) LLoadKeyedExternal(elements, key, temp)); | |
| 1739 if (elements_kind == UINT32_ELEMENTS && | |
| 1740 !instr->CheckFlag(HInstruction::kUint32)) { | |
| 1741 result = AssignEnvironment(result); | |
| 1742 } | |
| 1743 return result; | |
| 1744 } | |
| 1745 } | |
| 1746 | |
| 1747 | |
| 1748 LInstruction* LChunkBuilder::DoLoadKeyedGeneric(HLoadKeyedGeneric* instr) { | |
| 1749 LOperand* context = UseFixed(instr->context(), cp); | |
| 1750 LOperand* object = | |
| 1751 UseFixed(instr->object(), LoadDescriptor::ReceiverRegister()); | |
| 1752 LOperand* key = UseFixed(instr->key(), LoadDescriptor::NameRegister()); | |
| 1753 LOperand* vector = NULL; | |
| 1754 if (instr->HasVectorAndSlot()) { | |
| 1755 vector = FixedTemp(LoadWithVectorDescriptor::VectorRegister()); | |
| 1756 } | |
| 1757 | |
| 1758 LInstruction* result = | |
| 1759 DefineFixed(new(zone()) LLoadKeyedGeneric(context, object, key, vector), | |
| 1760 x0); | |
| 1761 return MarkAsCall(result, instr); | |
| 1762 } | |
| 1763 | |
| 1764 | |
| 1765 LInstruction* LChunkBuilder::DoLoadNamedField(HLoadNamedField* instr) { | |
| 1766 LOperand* object = UseRegisterAtStart(instr->object()); | |
| 1767 return DefineAsRegister(new(zone()) LLoadNamedField(object)); | |
| 1768 } | |
| 1769 | |
| 1770 | |
| 1771 LInstruction* LChunkBuilder::DoLoadNamedGeneric(HLoadNamedGeneric* instr) { | |
| 1772 LOperand* context = UseFixed(instr->context(), cp); | |
| 1773 LOperand* object = | |
| 1774 UseFixed(instr->object(), LoadDescriptor::ReceiverRegister()); | |
| 1775 LOperand* vector = NULL; | |
| 1776 if (instr->HasVectorAndSlot()) { | |
| 1777 vector = FixedTemp(LoadWithVectorDescriptor::VectorRegister()); | |
| 1778 } | |
| 1779 | |
| 1780 LInstruction* result = | |
| 1781 DefineFixed(new(zone()) LLoadNamedGeneric(context, object, vector), x0); | |
| 1782 return MarkAsCall(result, instr); | |
| 1783 } | |
| 1784 | |
| 1785 | |
| 1786 LInstruction* LChunkBuilder::DoLoadRoot(HLoadRoot* instr) { | |
| 1787 return DefineAsRegister(new(zone()) LLoadRoot); | |
| 1788 } | |
| 1789 | |
| 1790 | |
| 1791 LInstruction* LChunkBuilder::DoMapEnumLength(HMapEnumLength* instr) { | |
| 1792 LOperand* map = UseRegisterAtStart(instr->value()); | |
| 1793 return DefineAsRegister(new(zone()) LMapEnumLength(map)); | |
| 1794 } | |
| 1795 | |
| 1796 | |
| 1797 LInstruction* LChunkBuilder::DoFlooringDivByPowerOf2I(HMathFloorOfDiv* instr) { | |
| 1798 DCHECK(instr->representation().IsInteger32()); | |
| 1799 DCHECK(instr->left()->representation().Equals(instr->representation())); | |
| 1800 DCHECK(instr->right()->representation().Equals(instr->representation())); | |
| 1801 LOperand* dividend = UseRegisterAtStart(instr->left()); | |
| 1802 int32_t divisor = instr->right()->GetInteger32Constant(); | |
| 1803 LInstruction* result = DefineAsRegister(new(zone()) LFlooringDivByPowerOf2I( | |
| 1804 dividend, divisor)); | |
| 1805 if ((instr->CheckFlag(HValue::kBailoutOnMinusZero) && divisor < 0) || | |
| 1806 (instr->CheckFlag(HValue::kLeftCanBeMinInt) && divisor == -1)) { | |
| 1807 result = AssignEnvironment(result); | |
| 1808 } | |
| 1809 return result; | |
| 1810 } | |
| 1811 | |
| 1812 | |
| 1813 LInstruction* LChunkBuilder::DoFlooringDivByConstI(HMathFloorOfDiv* instr) { | |
| 1814 DCHECK(instr->representation().IsInteger32()); | |
| 1815 DCHECK(instr->left()->representation().Equals(instr->representation())); | |
| 1816 DCHECK(instr->right()->representation().Equals(instr->representation())); | |
| 1817 LOperand* dividend = UseRegister(instr->left()); | |
| 1818 int32_t divisor = instr->right()->GetInteger32Constant(); | |
| 1819 LOperand* temp = | |
| 1820 ((divisor > 0 && !instr->CheckFlag(HValue::kLeftCanBeNegative)) || | |
| 1821 (divisor < 0 && !instr->CheckFlag(HValue::kLeftCanBePositive))) ? | |
| 1822 NULL : TempRegister(); | |
| 1823 LInstruction* result = DefineAsRegister( | |
| 1824 new(zone()) LFlooringDivByConstI(dividend, divisor, temp)); | |
| 1825 if (divisor == 0 || | |
| 1826 (instr->CheckFlag(HValue::kBailoutOnMinusZero) && divisor < 0)) { | |
| 1827 result = AssignEnvironment(result); | |
| 1828 } | |
| 1829 return result; | |
| 1830 } | |
| 1831 | |
| 1832 | |
| 1833 LInstruction* LChunkBuilder::DoFlooringDivI(HMathFloorOfDiv* instr) { | |
| 1834 LOperand* dividend = UseRegister(instr->left()); | |
| 1835 LOperand* divisor = UseRegister(instr->right()); | |
| 1836 LOperand* remainder = TempRegister(); | |
| 1837 LInstruction* result = | |
| 1838 DefineAsRegister(new(zone()) LFlooringDivI(dividend, divisor, remainder)); | |
| 1839 return AssignEnvironment(result); | |
| 1840 } | |
| 1841 | |
| 1842 | |
| 1843 LInstruction* LChunkBuilder::DoMathFloorOfDiv(HMathFloorOfDiv* instr) { | |
| 1844 if (instr->RightIsPowerOf2()) { | |
| 1845 return DoFlooringDivByPowerOf2I(instr); | |
| 1846 } else if (instr->right()->IsConstant()) { | |
| 1847 return DoFlooringDivByConstI(instr); | |
| 1848 } else { | |
| 1849 return DoFlooringDivI(instr); | |
| 1850 } | |
| 1851 } | |
| 1852 | |
| 1853 | |
| 1854 LInstruction* LChunkBuilder::DoMathMinMax(HMathMinMax* instr) { | |
| 1855 LOperand* left = NULL; | |
| 1856 LOperand* right = NULL; | |
| 1857 if (instr->representation().IsSmiOrInteger32()) { | |
| 1858 DCHECK(instr->left()->representation().Equals(instr->representation())); | |
| 1859 DCHECK(instr->right()->representation().Equals(instr->representation())); | |
| 1860 left = UseRegisterAtStart(instr->BetterLeftOperand()); | |
| 1861 right = UseRegisterOrConstantAtStart(instr->BetterRightOperand()); | |
| 1862 } else { | |
| 1863 DCHECK(instr->representation().IsDouble()); | |
| 1864 DCHECK(instr->left()->representation().IsDouble()); | |
| 1865 DCHECK(instr->right()->representation().IsDouble()); | |
| 1866 left = UseRegisterAtStart(instr->left()); | |
| 1867 right = UseRegisterAtStart(instr->right()); | |
| 1868 } | |
| 1869 return DefineAsRegister(new(zone()) LMathMinMax(left, right)); | |
| 1870 } | |
| 1871 | |
| 1872 | |
| 1873 LInstruction* LChunkBuilder::DoModByPowerOf2I(HMod* instr) { | |
| 1874 DCHECK(instr->representation().IsInteger32()); | |
| 1875 DCHECK(instr->left()->representation().Equals(instr->representation())); | |
| 1876 DCHECK(instr->right()->representation().Equals(instr->representation())); | |
| 1877 LOperand* dividend = UseRegisterAtStart(instr->left()); | |
| 1878 int32_t divisor = instr->right()->GetInteger32Constant(); | |
| 1879 LInstruction* result = DefineSameAsFirst(new(zone()) LModByPowerOf2I( | |
| 1880 dividend, divisor)); | |
| 1881 if (instr->CheckFlag(HValue::kLeftCanBeNegative) && | |
| 1882 instr->CheckFlag(HValue::kBailoutOnMinusZero)) { | |
| 1883 result = AssignEnvironment(result); | |
| 1884 } | |
| 1885 return result; | |
| 1886 } | |
| 1887 | |
| 1888 | |
| 1889 LInstruction* LChunkBuilder::DoModByConstI(HMod* instr) { | |
| 1890 DCHECK(instr->representation().IsInteger32()); | |
| 1891 DCHECK(instr->left()->representation().Equals(instr->representation())); | |
| 1892 DCHECK(instr->right()->representation().Equals(instr->representation())); | |
| 1893 LOperand* dividend = UseRegister(instr->left()); | |
| 1894 int32_t divisor = instr->right()->GetInteger32Constant(); | |
| 1895 LOperand* temp = TempRegister(); | |
| 1896 LInstruction* result = DefineAsRegister(new(zone()) LModByConstI( | |
| 1897 dividend, divisor, temp)); | |
| 1898 if (divisor == 0 || instr->CheckFlag(HValue::kBailoutOnMinusZero)) { | |
| 1899 result = AssignEnvironment(result); | |
| 1900 } | |
| 1901 return result; | |
| 1902 } | |
| 1903 | |
| 1904 | |
| 1905 LInstruction* LChunkBuilder::DoModI(HMod* instr) { | |
| 1906 DCHECK(instr->representation().IsSmiOrInteger32()); | |
| 1907 DCHECK(instr->left()->representation().Equals(instr->representation())); | |
| 1908 DCHECK(instr->right()->representation().Equals(instr->representation())); | |
| 1909 LOperand* dividend = UseRegister(instr->left()); | |
| 1910 LOperand* divisor = UseRegister(instr->right()); | |
| 1911 LInstruction* result = DefineAsRegister(new(zone()) LModI(dividend, divisor)); | |
| 1912 if (instr->CheckFlag(HValue::kCanBeDivByZero) || | |
| 1913 instr->CheckFlag(HValue::kBailoutOnMinusZero)) { | |
| 1914 result = AssignEnvironment(result); | |
| 1915 } | |
| 1916 return result; | |
| 1917 } | |
| 1918 | |
| 1919 | |
| 1920 LInstruction* LChunkBuilder::DoMod(HMod* instr) { | |
| 1921 if (instr->representation().IsSmiOrInteger32()) { | |
| 1922 if (instr->RightIsPowerOf2()) { | |
| 1923 return DoModByPowerOf2I(instr); | |
| 1924 } else if (instr->right()->IsConstant()) { | |
| 1925 return DoModByConstI(instr); | |
| 1926 } else { | |
| 1927 return DoModI(instr); | |
| 1928 } | |
| 1929 } else if (instr->representation().IsDouble()) { | |
| 1930 return DoArithmeticD(Token::MOD, instr); | |
| 1931 } else { | |
| 1932 return DoArithmeticT(Token::MOD, instr); | |
| 1933 } | |
| 1934 } | |
| 1935 | |
| 1936 | |
| 1937 LInstruction* LChunkBuilder::DoMul(HMul* instr) { | |
| 1938 if (instr->representation().IsSmiOrInteger32()) { | |
| 1939 DCHECK(instr->left()->representation().Equals(instr->representation())); | |
| 1940 DCHECK(instr->right()->representation().Equals(instr->representation())); | |
| 1941 | |
| 1942 bool can_overflow = instr->CheckFlag(HValue::kCanOverflow); | |
| 1943 bool bailout_on_minus_zero = instr->CheckFlag(HValue::kBailoutOnMinusZero); | |
| 1944 | |
| 1945 HValue* least_const = instr->BetterLeftOperand(); | |
| 1946 HValue* most_const = instr->BetterRightOperand(); | |
| 1947 | |
| 1948 // LMulConstI can handle a subset of constants: | |
| 1949 // With support for overflow detection: | |
| 1950 // -1, 0, 1, 2 | |
| 1951 // 2^n, -(2^n) | |
| 1952 // Without support for overflow detection: | |
| 1953 // 2^n + 1, -(2^n - 1) | |
| 1954 if (most_const->IsConstant()) { | |
| 1955 int32_t constant = HConstant::cast(most_const)->Integer32Value(); | |
| 1956 bool small_constant = (constant >= -1) && (constant <= 2); | |
| 1957 bool end_range_constant = (constant <= -kMaxInt) || (constant == kMaxInt); | |
| 1958 int32_t constant_abs = Abs(constant); | |
| 1959 | |
| 1960 if (!end_range_constant && | |
| 1961 (small_constant || (base::bits::IsPowerOfTwo32(constant_abs)) || | |
| 1962 (!can_overflow && (base::bits::IsPowerOfTwo32(constant_abs + 1) || | |
| 1963 base::bits::IsPowerOfTwo32(constant_abs - 1))))) { | |
| 1964 LConstantOperand* right = UseConstant(most_const); | |
| 1965 bool need_register = | |
| 1966 base::bits::IsPowerOfTwo32(constant_abs) && !small_constant; | |
| 1967 LOperand* left = need_register ? UseRegister(least_const) | |
| 1968 : UseRegisterAtStart(least_const); | |
| 1969 LInstruction* result = | |
| 1970 DefineAsRegister(new(zone()) LMulConstIS(left, right)); | |
| 1971 if ((bailout_on_minus_zero && constant <= 0) || | |
| 1972 (can_overflow && constant != 1 && | |
| 1973 base::bits::IsPowerOfTwo32(constant_abs))) { | |
| 1974 result = AssignEnvironment(result); | |
| 1975 } | |
| 1976 return result; | |
| 1977 } | |
| 1978 } | |
| 1979 | |
| 1980 // LMulI/S can handle all cases, but it requires that a register is | |
| 1981 // allocated for the second operand. | |
| 1982 LOperand* left = UseRegisterAtStart(least_const); | |
| 1983 LOperand* right = UseRegisterAtStart(most_const); | |
| 1984 LInstruction* result = instr->representation().IsSmi() | |
| 1985 ? DefineAsRegister(new(zone()) LMulS(left, right)) | |
| 1986 : DefineAsRegister(new(zone()) LMulI(left, right)); | |
| 1987 if ((bailout_on_minus_zero && least_const != most_const) || can_overflow) { | |
| 1988 result = AssignEnvironment(result); | |
| 1989 } | |
| 1990 return result; | |
| 1991 } else if (instr->representation().IsDouble()) { | |
| 1992 return DoArithmeticD(Token::MUL, instr); | |
| 1993 } else { | |
| 1994 return DoArithmeticT(Token::MUL, instr); | |
| 1995 } | |
| 1996 } | |
| 1997 | |
| 1998 | |
| 1999 LInstruction* LChunkBuilder::DoOsrEntry(HOsrEntry* instr) { | |
| 2000 DCHECK(argument_count_ == 0); | |
| 2001 allocator_->MarkAsOsrEntry(); | |
| 2002 current_block_->last_environment()->set_ast_id(instr->ast_id()); | |
| 2003 return AssignEnvironment(new(zone()) LOsrEntry); | |
| 2004 } | |
| 2005 | |
| 2006 | |
| 2007 LInstruction* LChunkBuilder::DoParameter(HParameter* instr) { | |
| 2008 LParameter* result = new(zone()) LParameter; | |
| 2009 if (instr->kind() == HParameter::STACK_PARAMETER) { | |
| 2010 int spill_index = chunk_->GetParameterStackSlot(instr->index()); | |
| 2011 return DefineAsSpilled(result, spill_index); | |
| 2012 } else { | |
| 2013 DCHECK(info()->IsStub()); | |
| 2014 CallInterfaceDescriptor descriptor = | |
| 2015 info()->code_stub()->GetCallInterfaceDescriptor(); | |
| 2016 int index = static_cast<int>(instr->index()); | |
| 2017 Register reg = descriptor.GetRegisterParameter(index); | |
| 2018 return DefineFixed(result, reg); | |
| 2019 } | |
| 2020 } | |
| 2021 | |
| 2022 | |
| 2023 LInstruction* LChunkBuilder::DoPower(HPower* instr) { | |
| 2024 DCHECK(instr->representation().IsDouble()); | |
| 2025 // We call a C function for double power. It can't trigger a GC. | |
| 2026 // We need to use fixed result register for the call. | |
| 2027 Representation exponent_type = instr->right()->representation(); | |
| 2028 DCHECK(instr->left()->representation().IsDouble()); | |
| 2029 LOperand* left = UseFixedDouble(instr->left(), d0); | |
| 2030 LOperand* right; | |
| 2031 if (exponent_type.IsInteger32()) { | |
| 2032 right = UseFixed(instr->right(), MathPowIntegerDescriptor::exponent()); | |
| 2033 } else if (exponent_type.IsDouble()) { | |
| 2034 right = UseFixedDouble(instr->right(), d1); | |
| 2035 } else { | |
| 2036 right = UseFixed(instr->right(), MathPowTaggedDescriptor::exponent()); | |
| 2037 } | |
| 2038 LPower* result = new(zone()) LPower(left, right); | |
| 2039 return MarkAsCall(DefineFixedDouble(result, d0), | |
| 2040 instr, | |
| 2041 CAN_DEOPTIMIZE_EAGERLY); | |
| 2042 } | |
| 2043 | |
| 2044 | |
| 2045 LInstruction* LChunkBuilder::DoPushArguments(HPushArguments* instr) { | |
| 2046 int argc = instr->OperandCount(); | |
| 2047 AddInstruction(new(zone()) LPreparePushArguments(argc), instr); | |
| 2048 | |
| 2049 LPushArguments* push_args = new(zone()) LPushArguments(zone()); | |
| 2050 | |
| 2051 for (int i = 0; i < argc; ++i) { | |
| 2052 if (push_args->ShouldSplitPush()) { | |
| 2053 AddInstruction(push_args, instr); | |
| 2054 push_args = new(zone()) LPushArguments(zone()); | |
| 2055 } | |
| 2056 push_args->AddArgument(UseRegister(instr->argument(i))); | |
| 2057 } | |
| 2058 | |
| 2059 return push_args; | |
| 2060 } | |
| 2061 | |
| 2062 | |
| 2063 LInstruction* LChunkBuilder::DoRegExpLiteral(HRegExpLiteral* instr) { | |
| 2064 LOperand* context = UseFixed(instr->context(), cp); | |
| 2065 return MarkAsCall( | |
| 2066 DefineFixed(new(zone()) LRegExpLiteral(context), x0), instr); | |
| 2067 } | |
| 2068 | |
| 2069 | |
| 2070 LInstruction* LChunkBuilder::DoDoubleBits(HDoubleBits* instr) { | |
| 2071 HValue* value = instr->value(); | |
| 2072 DCHECK(value->representation().IsDouble()); | |
| 2073 return DefineAsRegister(new(zone()) LDoubleBits(UseRegister(value))); | |
| 2074 } | |
| 2075 | |
| 2076 | |
| 2077 LInstruction* LChunkBuilder::DoConstructDouble(HConstructDouble* instr) { | |
| 2078 LOperand* lo = UseRegisterAndClobber(instr->lo()); | |
| 2079 LOperand* hi = UseRegister(instr->hi()); | |
| 2080 return DefineAsRegister(new(zone()) LConstructDouble(hi, lo)); | |
| 2081 } | |
| 2082 | |
| 2083 | |
| 2084 LInstruction* LChunkBuilder::DoReturn(HReturn* instr) { | |
| 2085 LOperand* context = info()->IsStub() | |
| 2086 ? UseFixed(instr->context(), cp) | |
| 2087 : NULL; | |
| 2088 LOperand* parameter_count = UseRegisterOrConstant(instr->parameter_count()); | |
| 2089 return new(zone()) LReturn(UseFixed(instr->value(), x0), context, | |
| 2090 parameter_count); | |
| 2091 } | |
| 2092 | |
| 2093 | |
| 2094 LInstruction* LChunkBuilder::DoSeqStringGetChar(HSeqStringGetChar* instr) { | |
| 2095 LOperand* string = UseRegisterAtStart(instr->string()); | |
| 2096 LOperand* index = UseRegisterOrConstantAtStart(instr->index()); | |
| 2097 LOperand* temp = TempRegister(); | |
| 2098 LSeqStringGetChar* result = | |
| 2099 new(zone()) LSeqStringGetChar(string, index, temp); | |
| 2100 return DefineAsRegister(result); | |
| 2101 } | |
| 2102 | |
| 2103 | |
| 2104 LInstruction* LChunkBuilder::DoSeqStringSetChar(HSeqStringSetChar* instr) { | |
| 2105 LOperand* string = UseRegister(instr->string()); | |
| 2106 LOperand* index = FLAG_debug_code | |
| 2107 ? UseRegister(instr->index()) | |
| 2108 : UseRegisterOrConstant(instr->index()); | |
| 2109 LOperand* value = UseRegister(instr->value()); | |
| 2110 LOperand* context = FLAG_debug_code ? UseFixed(instr->context(), cp) : NULL; | |
| 2111 LOperand* temp = TempRegister(); | |
| 2112 LSeqStringSetChar* result = | |
| 2113 new(zone()) LSeqStringSetChar(context, string, index, value, temp); | |
| 2114 return DefineAsRegister(result); | |
| 2115 } | |
| 2116 | |
| 2117 | |
| 2118 HBitwiseBinaryOperation* LChunkBuilder::CanTransformToShiftedOp(HValue* val, | |
| 2119 HValue** left) { | |
| 2120 if (!val->representation().IsInteger32()) return NULL; | |
| 2121 if (!(val->IsBitwise() || val->IsAdd() || val->IsSub())) return NULL; | |
| 2122 | |
| 2123 HBinaryOperation* hinstr = HBinaryOperation::cast(val); | |
| 2124 HValue* hleft = hinstr->left(); | |
| 2125 HValue* hright = hinstr->right(); | |
| 2126 DCHECK(hleft->representation().Equals(hinstr->representation())); | |
| 2127 DCHECK(hright->representation().Equals(hinstr->representation())); | |
| 2128 | |
| 2129 if (hleft == hright) return NULL; | |
| 2130 | |
| 2131 if ((hright->IsConstant() && | |
| 2132 LikelyFitsImmField(hinstr, HConstant::cast(hright)->Integer32Value())) || | |
| 2133 (hinstr->IsCommutative() && hleft->IsConstant() && | |
| 2134 LikelyFitsImmField(hinstr, HConstant::cast(hleft)->Integer32Value()))) { | |
| 2135 // The constant operand will likely fit in the immediate field. We are | |
| 2136 // better off with | |
| 2137 // lsl x8, x9, #imm | |
| 2138 // add x0, x8, #imm2 | |
| 2139 // than with | |
| 2140 // mov x16, #imm2 | |
| 2141 // add x0, x16, x9 LSL #imm | |
| 2142 return NULL; | |
| 2143 } | |
| 2144 | |
| 2145 HBitwiseBinaryOperation* shift = NULL; | |
| 2146 // TODO(aleram): We will miss situations where a shift operation is used by | |
| 2147 // different instructions both as a left and right operands. | |
| 2148 if (hright->IsBitwiseBinaryShift() && | |
| 2149 HBitwiseBinaryOperation::cast(hright)->right()->IsConstant()) { | |
| 2150 shift = HBitwiseBinaryOperation::cast(hright); | |
| 2151 if (left != NULL) { | |
| 2152 *left = hleft; | |
| 2153 } | |
| 2154 } else if (hinstr->IsCommutative() && | |
| 2155 hleft->IsBitwiseBinaryShift() && | |
| 2156 HBitwiseBinaryOperation::cast(hleft)->right()->IsConstant()) { | |
| 2157 shift = HBitwiseBinaryOperation::cast(hleft); | |
| 2158 if (left != NULL) { | |
| 2159 *left = hright; | |
| 2160 } | |
| 2161 } else { | |
| 2162 return NULL; | |
| 2163 } | |
| 2164 | |
| 2165 if ((JSShiftAmountFromHConstant(shift->right()) == 0) && shift->IsShr()) { | |
| 2166 // Shifts right by zero can deoptimize. | |
| 2167 return NULL; | |
| 2168 } | |
| 2169 | |
| 2170 return shift; | |
| 2171 } | |
| 2172 | |
| 2173 | |
| 2174 bool LChunkBuilder::ShiftCanBeOptimizedAway(HBitwiseBinaryOperation* shift) { | |
| 2175 if (!shift->representation().IsInteger32()) { | |
| 2176 return false; | |
| 2177 } | |
| 2178 for (HUseIterator it(shift->uses()); !it.Done(); it.Advance()) { | |
| 2179 if (shift != CanTransformToShiftedOp(it.value())) { | |
| 2180 return false; | |
| 2181 } | |
| 2182 } | |
| 2183 return true; | |
| 2184 } | |
| 2185 | |
| 2186 | |
| 2187 LInstruction* LChunkBuilder::TryDoOpWithShiftedRightOperand( | |
| 2188 HBinaryOperation* instr) { | |
| 2189 HValue* left; | |
| 2190 HBitwiseBinaryOperation* shift = CanTransformToShiftedOp(instr, &left); | |
| 2191 | |
| 2192 if ((shift != NULL) && ShiftCanBeOptimizedAway(shift)) { | |
| 2193 return DoShiftedBinaryOp(instr, left, shift); | |
| 2194 } | |
| 2195 return NULL; | |
| 2196 } | |
| 2197 | |
| 2198 | |
| 2199 LInstruction* LChunkBuilder::DoShiftedBinaryOp( | |
| 2200 HBinaryOperation* hinstr, HValue* hleft, HBitwiseBinaryOperation* hshift) { | |
| 2201 DCHECK(hshift->IsBitwiseBinaryShift()); | |
| 2202 DCHECK(!hshift->IsShr() || (JSShiftAmountFromHConstant(hshift->right()) > 0)); | |
| 2203 | |
| 2204 LTemplateResultInstruction<1>* res; | |
| 2205 LOperand* left = UseRegisterAtStart(hleft); | |
| 2206 LOperand* right = UseRegisterAtStart(hshift->left()); | |
| 2207 LOperand* shift_amount = UseConstant(hshift->right()); | |
| 2208 Shift shift_op; | |
| 2209 switch (hshift->opcode()) { | |
| 2210 case HValue::kShl: shift_op = LSL; break; | |
| 2211 case HValue::kShr: shift_op = LSR; break; | |
| 2212 case HValue::kSar: shift_op = ASR; break; | |
| 2213 default: UNREACHABLE(); shift_op = NO_SHIFT; | |
| 2214 } | |
| 2215 | |
| 2216 if (hinstr->IsBitwise()) { | |
| 2217 res = new(zone()) LBitI(left, right, shift_op, shift_amount); | |
| 2218 } else if (hinstr->IsAdd()) { | |
| 2219 res = new(zone()) LAddI(left, right, shift_op, shift_amount); | |
| 2220 } else { | |
| 2221 DCHECK(hinstr->IsSub()); | |
| 2222 res = new(zone()) LSubI(left, right, shift_op, shift_amount); | |
| 2223 } | |
| 2224 if (hinstr->CheckFlag(HValue::kCanOverflow)) { | |
| 2225 AssignEnvironment(res); | |
| 2226 } | |
| 2227 return DefineAsRegister(res); | |
| 2228 } | |
| 2229 | |
| 2230 | |
| 2231 LInstruction* LChunkBuilder::DoShift(Token::Value op, | |
| 2232 HBitwiseBinaryOperation* instr) { | |
| 2233 if (instr->representation().IsTagged()) { | |
| 2234 return DoArithmeticT(op, instr); | |
| 2235 } | |
| 2236 | |
| 2237 DCHECK(instr->representation().IsSmiOrInteger32()); | |
| 2238 DCHECK(instr->left()->representation().Equals(instr->representation())); | |
| 2239 DCHECK(instr->right()->representation().Equals(instr->representation())); | |
| 2240 | |
| 2241 if (ShiftCanBeOptimizedAway(instr)) { | |
| 2242 return NULL; | |
| 2243 } | |
| 2244 | |
| 2245 LOperand* left = instr->representation().IsSmi() | |
| 2246 ? UseRegister(instr->left()) | |
| 2247 : UseRegisterAtStart(instr->left()); | |
| 2248 LOperand* right = UseRegisterOrConstantAtStart(instr->right()); | |
| 2249 | |
| 2250 // The only shift that can deoptimize is `left >>> 0`, where left is negative. | |
| 2251 // In these cases, the result is a uint32 that is too large for an int32. | |
| 2252 bool right_can_be_zero = !instr->right()->IsConstant() || | |
| 2253 (JSShiftAmountFromHConstant(instr->right()) == 0); | |
| 2254 bool can_deopt = false; | |
| 2255 if ((op == Token::SHR) && right_can_be_zero) { | |
| 2256 can_deopt = !instr->CheckFlag(HInstruction::kUint32); | |
| 2257 } | |
| 2258 | |
| 2259 LInstruction* result; | |
| 2260 if (instr->representation().IsInteger32()) { | |
| 2261 result = DefineAsRegister(new (zone()) LShiftI(op, left, right, can_deopt)); | |
| 2262 } else { | |
| 2263 DCHECK(instr->representation().IsSmi()); | |
| 2264 result = DefineAsRegister(new (zone()) LShiftS(op, left, right, can_deopt)); | |
| 2265 } | |
| 2266 | |
| 2267 return can_deopt ? AssignEnvironment(result) : result; | |
| 2268 } | |
| 2269 | |
| 2270 | |
| 2271 LInstruction* LChunkBuilder::DoRor(HRor* instr) { | |
| 2272 return DoShift(Token::ROR, instr); | |
| 2273 } | |
| 2274 | |
| 2275 | |
| 2276 LInstruction* LChunkBuilder::DoSar(HSar* instr) { | |
| 2277 return DoShift(Token::SAR, instr); | |
| 2278 } | |
| 2279 | |
| 2280 | |
| 2281 LInstruction* LChunkBuilder::DoShl(HShl* instr) { | |
| 2282 return DoShift(Token::SHL, instr); | |
| 2283 } | |
| 2284 | |
| 2285 | |
| 2286 LInstruction* LChunkBuilder::DoShr(HShr* instr) { | |
| 2287 return DoShift(Token::SHR, instr); | |
| 2288 } | |
| 2289 | |
| 2290 | |
| 2291 LInstruction* LChunkBuilder::DoSimulate(HSimulate* instr) { | |
| 2292 instr->ReplayEnvironment(current_block_->last_environment()); | |
| 2293 return NULL; | |
| 2294 } | |
| 2295 | |
| 2296 | |
| 2297 LInstruction* LChunkBuilder::DoStackCheck(HStackCheck* instr) { | |
| 2298 if (instr->is_function_entry()) { | |
| 2299 LOperand* context = UseFixed(instr->context(), cp); | |
| 2300 return MarkAsCall(new(zone()) LStackCheck(context), instr); | |
| 2301 } else { | |
| 2302 DCHECK(instr->is_backwards_branch()); | |
| 2303 LOperand* context = UseAny(instr->context()); | |
| 2304 return AssignEnvironment( | |
| 2305 AssignPointerMap(new(zone()) LStackCheck(context))); | |
| 2306 } | |
| 2307 } | |
| 2308 | |
| 2309 | |
| 2310 LInstruction* LChunkBuilder::DoStoreCodeEntry(HStoreCodeEntry* instr) { | |
| 2311 LOperand* function = UseRegister(instr->function()); | |
| 2312 LOperand* code_object = UseRegisterAtStart(instr->code_object()); | |
| 2313 LOperand* temp = TempRegister(); | |
| 2314 return new(zone()) LStoreCodeEntry(function, code_object, temp); | |
| 2315 } | |
| 2316 | |
| 2317 | |
| 2318 LInstruction* LChunkBuilder::DoStoreContextSlot(HStoreContextSlot* instr) { | |
| 2319 LOperand* temp = TempRegister(); | |
| 2320 LOperand* context; | |
| 2321 LOperand* value; | |
| 2322 if (instr->NeedsWriteBarrier()) { | |
| 2323 // TODO(all): Replace these constraints when RecordWriteStub has been | |
| 2324 // rewritten. | |
| 2325 context = UseRegisterAndClobber(instr->context()); | |
| 2326 value = UseRegisterAndClobber(instr->value()); | |
| 2327 } else { | |
| 2328 context = UseRegister(instr->context()); | |
| 2329 value = UseRegister(instr->value()); | |
| 2330 } | |
| 2331 LInstruction* result = new(zone()) LStoreContextSlot(context, value, temp); | |
| 2332 if (instr->RequiresHoleCheck() && instr->DeoptimizesOnHole()) { | |
| 2333 result = AssignEnvironment(result); | |
| 2334 } | |
| 2335 return result; | |
| 2336 } | |
| 2337 | |
| 2338 | |
| 2339 LInstruction* LChunkBuilder::DoStoreKeyed(HStoreKeyed* instr) { | |
| 2340 LOperand* key = UseRegisterOrConstant(instr->key()); | |
| 2341 LOperand* temp = NULL; | |
| 2342 LOperand* elements = NULL; | |
| 2343 LOperand* val = NULL; | |
| 2344 | |
| 2345 if (!instr->is_fixed_typed_array() && | |
| 2346 instr->value()->representation().IsTagged() && | |
| 2347 instr->NeedsWriteBarrier()) { | |
| 2348 // RecordWrite() will clobber all registers. | |
| 2349 elements = UseRegisterAndClobber(instr->elements()); | |
| 2350 val = UseRegisterAndClobber(instr->value()); | |
| 2351 temp = TempRegister(); | |
| 2352 } else { | |
| 2353 elements = UseRegister(instr->elements()); | |
| 2354 val = UseRegister(instr->value()); | |
| 2355 temp = instr->key()->IsConstant() ? NULL : TempRegister(); | |
| 2356 } | |
| 2357 | |
| 2358 if (instr->is_fixed_typed_array()) { | |
| 2359 DCHECK((instr->value()->representation().IsInteger32() && | |
| 2360 !IsDoubleOrFloatElementsKind(instr->elements_kind())) || | |
| 2361 (instr->value()->representation().IsDouble() && | |
| 2362 IsDoubleOrFloatElementsKind(instr->elements_kind()))); | |
| 2363 DCHECK(instr->elements()->representation().IsExternal()); | |
| 2364 return new(zone()) LStoreKeyedExternal(elements, key, val, temp); | |
| 2365 | |
| 2366 } else if (instr->value()->representation().IsDouble()) { | |
| 2367 DCHECK(instr->elements()->representation().IsTagged()); | |
| 2368 return new(zone()) LStoreKeyedFixedDouble(elements, key, val, temp); | |
| 2369 | |
| 2370 } else { | |
| 2371 DCHECK(instr->elements()->representation().IsTagged()); | |
| 2372 DCHECK(instr->value()->representation().IsSmiOrTagged() || | |
| 2373 instr->value()->representation().IsInteger32()); | |
| 2374 return new(zone()) LStoreKeyedFixed(elements, key, val, temp); | |
| 2375 } | |
| 2376 } | |
| 2377 | |
| 2378 | |
| 2379 LInstruction* LChunkBuilder::DoStoreKeyedGeneric(HStoreKeyedGeneric* instr) { | |
| 2380 LOperand* context = UseFixed(instr->context(), cp); | |
| 2381 LOperand* object = | |
| 2382 UseFixed(instr->object(), StoreDescriptor::ReceiverRegister()); | |
| 2383 LOperand* key = UseFixed(instr->key(), StoreDescriptor::NameRegister()); | |
| 2384 LOperand* value = UseFixed(instr->value(), StoreDescriptor::ValueRegister()); | |
| 2385 | |
| 2386 DCHECK(instr->object()->representation().IsTagged()); | |
| 2387 DCHECK(instr->key()->representation().IsTagged()); | |
| 2388 DCHECK(instr->value()->representation().IsTagged()); | |
| 2389 | |
| 2390 LOperand* slot = NULL; | |
| 2391 LOperand* vector = NULL; | |
| 2392 if (instr->HasVectorAndSlot()) { | |
| 2393 slot = FixedTemp(VectorStoreICDescriptor::SlotRegister()); | |
| 2394 vector = FixedTemp(VectorStoreICDescriptor::VectorRegister()); | |
| 2395 } | |
| 2396 | |
| 2397 LStoreKeyedGeneric* result = new (zone()) | |
| 2398 LStoreKeyedGeneric(context, object, key, value, slot, vector); | |
| 2399 return MarkAsCall(result, instr); | |
| 2400 } | |
| 2401 | |
| 2402 | |
| 2403 LInstruction* LChunkBuilder::DoStoreNamedField(HStoreNamedField* instr) { | |
| 2404 // TODO(jbramley): It might be beneficial to allow value to be a constant in | |
| 2405 // some cases. x64 makes use of this with FLAG_track_fields, for example. | |
| 2406 | |
| 2407 LOperand* object = UseRegister(instr->object()); | |
| 2408 LOperand* value; | |
| 2409 LOperand* temp0 = NULL; | |
| 2410 LOperand* temp1 = NULL; | |
| 2411 | |
| 2412 if (instr->access().IsExternalMemory() || | |
| 2413 (!FLAG_unbox_double_fields && instr->field_representation().IsDouble())) { | |
| 2414 value = UseRegister(instr->value()); | |
| 2415 } else if (instr->NeedsWriteBarrier()) { | |
| 2416 value = UseRegisterAndClobber(instr->value()); | |
| 2417 temp0 = TempRegister(); | |
| 2418 temp1 = TempRegister(); | |
| 2419 } else if (instr->NeedsWriteBarrierForMap()) { | |
| 2420 value = UseRegister(instr->value()); | |
| 2421 temp0 = TempRegister(); | |
| 2422 temp1 = TempRegister(); | |
| 2423 } else { | |
| 2424 value = UseRegister(instr->value()); | |
| 2425 temp0 = TempRegister(); | |
| 2426 } | |
| 2427 | |
| 2428 return new(zone()) LStoreNamedField(object, value, temp0, temp1); | |
| 2429 } | |
| 2430 | |
| 2431 | |
| 2432 LInstruction* LChunkBuilder::DoStoreNamedGeneric(HStoreNamedGeneric* instr) { | |
| 2433 LOperand* context = UseFixed(instr->context(), cp); | |
| 2434 LOperand* object = | |
| 2435 UseFixed(instr->object(), StoreDescriptor::ReceiverRegister()); | |
| 2436 LOperand* value = UseFixed(instr->value(), StoreDescriptor::ValueRegister()); | |
| 2437 | |
| 2438 LOperand* slot = NULL; | |
| 2439 LOperand* vector = NULL; | |
| 2440 if (instr->HasVectorAndSlot()) { | |
| 2441 slot = FixedTemp(VectorStoreICDescriptor::SlotRegister()); | |
| 2442 vector = FixedTemp(VectorStoreICDescriptor::VectorRegister()); | |
| 2443 } | |
| 2444 | |
| 2445 LStoreNamedGeneric* result = | |
| 2446 new (zone()) LStoreNamedGeneric(context, object, value, slot, vector); | |
| 2447 return MarkAsCall(result, instr); | |
| 2448 } | |
| 2449 | |
| 2450 | |
| 2451 LInstruction* LChunkBuilder::DoStoreGlobalViaContext( | |
| 2452 HStoreGlobalViaContext* instr) { | |
| 2453 LOperand* context = UseFixed(instr->context(), cp); | |
| 2454 LOperand* value = UseFixed(instr->value(), | |
| 2455 StoreGlobalViaContextDescriptor::ValueRegister()); | |
| 2456 DCHECK(instr->slot_index() > 0); | |
| 2457 | |
| 2458 LStoreGlobalViaContext* result = | |
| 2459 new (zone()) LStoreGlobalViaContext(context, value); | |
| 2460 return MarkAsCall(result, instr); | |
| 2461 } | |
| 2462 | |
| 2463 | |
| 2464 LInstruction* LChunkBuilder::DoStringAdd(HStringAdd* instr) { | |
| 2465 LOperand* context = UseFixed(instr->context(), cp); | |
| 2466 LOperand* left = UseFixed(instr->left(), x1); | |
| 2467 LOperand* right = UseFixed(instr->right(), x0); | |
| 2468 | |
| 2469 LStringAdd* result = new(zone()) LStringAdd(context, left, right); | |
| 2470 return MarkAsCall(DefineFixed(result, x0), instr); | |
| 2471 } | |
| 2472 | |
| 2473 | |
| 2474 LInstruction* LChunkBuilder::DoStringCharCodeAt(HStringCharCodeAt* instr) { | |
| 2475 LOperand* string = UseRegisterAndClobber(instr->string()); | |
| 2476 LOperand* index = UseRegisterAndClobber(instr->index()); | |
| 2477 LOperand* context = UseAny(instr->context()); | |
| 2478 LStringCharCodeAt* result = | |
| 2479 new(zone()) LStringCharCodeAt(context, string, index); | |
| 2480 return AssignPointerMap(DefineAsRegister(result)); | |
| 2481 } | |
| 2482 | |
| 2483 | |
| 2484 LInstruction* LChunkBuilder::DoStringCharFromCode(HStringCharFromCode* instr) { | |
| 2485 LOperand* char_code = UseRegister(instr->value()); | |
| 2486 LOperand* context = UseAny(instr->context()); | |
| 2487 LStringCharFromCode* result = | |
| 2488 new(zone()) LStringCharFromCode(context, char_code); | |
| 2489 return AssignPointerMap(DefineAsRegister(result)); | |
| 2490 } | |
| 2491 | |
| 2492 | |
| 2493 LInstruction* LChunkBuilder::DoStringCompareAndBranch( | |
| 2494 HStringCompareAndBranch* instr) { | |
| 2495 DCHECK(instr->left()->representation().IsTagged()); | |
| 2496 DCHECK(instr->right()->representation().IsTagged()); | |
| 2497 LOperand* context = UseFixed(instr->context(), cp); | |
| 2498 LOperand* left = UseFixed(instr->left(), x1); | |
| 2499 LOperand* right = UseFixed(instr->right(), x0); | |
| 2500 LStringCompareAndBranch* result = | |
| 2501 new(zone()) LStringCompareAndBranch(context, left, right); | |
| 2502 return MarkAsCall(result, instr); | |
| 2503 } | |
| 2504 | |
| 2505 | |
| 2506 LInstruction* LChunkBuilder::DoSub(HSub* instr) { | |
| 2507 if (instr->representation().IsSmiOrInteger32()) { | |
| 2508 DCHECK(instr->left()->representation().Equals(instr->representation())); | |
| 2509 DCHECK(instr->right()->representation().Equals(instr->representation())); | |
| 2510 | |
| 2511 LInstruction* shifted_operation = TryDoOpWithShiftedRightOperand(instr); | |
| 2512 if (shifted_operation != NULL) { | |
| 2513 return shifted_operation; | |
| 2514 } | |
| 2515 | |
| 2516 LOperand *left; | |
| 2517 if (instr->left()->IsConstant() && | |
| 2518 (HConstant::cast(instr->left())->Integer32Value() == 0)) { | |
| 2519 left = UseConstant(instr->left()); | |
| 2520 } else { | |
| 2521 left = UseRegisterAtStart(instr->left()); | |
| 2522 } | |
| 2523 LOperand* right = UseRegisterOrConstantAtStart(instr->right()); | |
| 2524 LInstruction* result = instr->representation().IsSmi() ? | |
| 2525 DefineAsRegister(new(zone()) LSubS(left, right)) : | |
| 2526 DefineAsRegister(new(zone()) LSubI(left, right)); | |
| 2527 if (instr->CheckFlag(HValue::kCanOverflow)) { | |
| 2528 result = AssignEnvironment(result); | |
| 2529 } | |
| 2530 return result; | |
| 2531 } else if (instr->representation().IsDouble()) { | |
| 2532 return DoArithmeticD(Token::SUB, instr); | |
| 2533 } else { | |
| 2534 return DoArithmeticT(Token::SUB, instr); | |
| 2535 } | |
| 2536 } | |
| 2537 | |
| 2538 | |
| 2539 LInstruction* LChunkBuilder::DoThisFunction(HThisFunction* instr) { | |
| 2540 if (instr->HasNoUses()) { | |
| 2541 return NULL; | |
| 2542 } else { | |
| 2543 return DefineAsRegister(new(zone()) LThisFunction); | |
| 2544 } | |
| 2545 } | |
| 2546 | |
| 2547 | |
| 2548 LInstruction* LChunkBuilder::DoToFastProperties(HToFastProperties* instr) { | |
| 2549 LOperand* object = UseFixed(instr->value(), x0); | |
| 2550 LToFastProperties* result = new(zone()) LToFastProperties(object); | |
| 2551 return MarkAsCall(DefineFixed(result, x0), instr); | |
| 2552 } | |
| 2553 | |
| 2554 | |
| 2555 LInstruction* LChunkBuilder::DoTransitionElementsKind( | |
| 2556 HTransitionElementsKind* instr) { | |
| 2557 if (IsSimpleMapChangeTransition(instr->from_kind(), instr->to_kind())) { | |
| 2558 LOperand* object = UseRegister(instr->object()); | |
| 2559 LTransitionElementsKind* result = | |
| 2560 new(zone()) LTransitionElementsKind(object, NULL, | |
| 2561 TempRegister(), TempRegister()); | |
| 2562 return result; | |
| 2563 } else { | |
| 2564 LOperand* object = UseFixed(instr->object(), x0); | |
| 2565 LOperand* context = UseFixed(instr->context(), cp); | |
| 2566 LTransitionElementsKind* result = | |
| 2567 new(zone()) LTransitionElementsKind(object, context, NULL, NULL); | |
| 2568 return MarkAsCall(result, instr); | |
| 2569 } | |
| 2570 } | |
| 2571 | |
| 2572 | |
| 2573 LInstruction* LChunkBuilder::DoTrapAllocationMemento( | |
| 2574 HTrapAllocationMemento* instr) { | |
| 2575 LOperand* object = UseRegister(instr->object()); | |
| 2576 LOperand* temp1 = TempRegister(); | |
| 2577 LOperand* temp2 = TempRegister(); | |
| 2578 LTrapAllocationMemento* result = | |
| 2579 new(zone()) LTrapAllocationMemento(object, temp1, temp2); | |
| 2580 return AssignEnvironment(result); | |
| 2581 } | |
| 2582 | |
| 2583 | |
| 2584 LInstruction* LChunkBuilder::DoMaybeGrowElements(HMaybeGrowElements* instr) { | |
| 2585 info()->MarkAsDeferredCalling(); | |
| 2586 LOperand* context = UseFixed(instr->context(), cp); | |
| 2587 LOperand* object = UseRegister(instr->object()); | |
| 2588 LOperand* elements = UseRegister(instr->elements()); | |
| 2589 LOperand* key = UseRegisterOrConstant(instr->key()); | |
| 2590 LOperand* current_capacity = UseRegisterOrConstant(instr->current_capacity()); | |
| 2591 | |
| 2592 LMaybeGrowElements* result = new (zone()) | |
| 2593 LMaybeGrowElements(context, object, elements, key, current_capacity); | |
| 2594 DefineFixed(result, x0); | |
| 2595 return AssignPointerMap(AssignEnvironment(result)); | |
| 2596 } | |
| 2597 | |
| 2598 | |
| 2599 LInstruction* LChunkBuilder::DoTypeof(HTypeof* instr) { | |
| 2600 LOperand* context = UseFixed(instr->context(), cp); | |
| 2601 LOperand* value = UseFixed(instr->value(), x3); | |
| 2602 LTypeof* result = new (zone()) LTypeof(context, value); | |
| 2603 return MarkAsCall(DefineFixed(result, x0), instr); | |
| 2604 } | |
| 2605 | |
| 2606 | |
| 2607 LInstruction* LChunkBuilder::DoTypeofIsAndBranch(HTypeofIsAndBranch* instr) { | |
| 2608 // We only need temp registers in some cases, but we can't dereference the | |
| 2609 // instr->type_literal() handle to test that here. | |
| 2610 LOperand* temp1 = TempRegister(); | |
| 2611 LOperand* temp2 = TempRegister(); | |
| 2612 | |
| 2613 return new(zone()) LTypeofIsAndBranch( | |
| 2614 UseRegister(instr->value()), temp1, temp2); | |
| 2615 } | |
| 2616 | |
| 2617 | |
| 2618 LInstruction* LChunkBuilder::DoUnaryMathOperation(HUnaryMathOperation* instr) { | |
| 2619 switch (instr->op()) { | |
| 2620 case kMathAbs: { | |
| 2621 Representation r = instr->representation(); | |
| 2622 if (r.IsTagged()) { | |
| 2623 // The tagged case might need to allocate a HeapNumber for the result, | |
| 2624 // so it is handled by a separate LInstruction. | |
| 2625 LOperand* context = UseFixed(instr->context(), cp); | |
| 2626 LOperand* input = UseRegister(instr->value()); | |
| 2627 LOperand* temp1 = TempRegister(); | |
| 2628 LOperand* temp2 = TempRegister(); | |
| 2629 LOperand* temp3 = TempRegister(); | |
| 2630 LInstruction* result = DefineAsRegister( | |
| 2631 new(zone()) LMathAbsTagged(context, input, temp1, temp2, temp3)); | |
| 2632 return AssignEnvironment(AssignPointerMap(result)); | |
| 2633 } else { | |
| 2634 LOperand* input = UseRegisterAtStart(instr->value()); | |
| 2635 LInstruction* result = DefineAsRegister(new(zone()) LMathAbs(input)); | |
| 2636 if (!r.IsDouble()) result = AssignEnvironment(result); | |
| 2637 return result; | |
| 2638 } | |
| 2639 } | |
| 2640 case kMathExp: { | |
| 2641 DCHECK(instr->representation().IsDouble()); | |
| 2642 DCHECK(instr->value()->representation().IsDouble()); | |
| 2643 LOperand* input = UseRegister(instr->value()); | |
| 2644 LOperand* double_temp1 = TempDoubleRegister(); | |
| 2645 LOperand* temp1 = TempRegister(); | |
| 2646 LOperand* temp2 = TempRegister(); | |
| 2647 LOperand* temp3 = TempRegister(); | |
| 2648 LMathExp* result = new(zone()) LMathExp(input, double_temp1, | |
| 2649 temp1, temp2, temp3); | |
| 2650 return DefineAsRegister(result); | |
| 2651 } | |
| 2652 case kMathFloor: { | |
| 2653 DCHECK(instr->value()->representation().IsDouble()); | |
| 2654 LOperand* input = UseRegisterAtStart(instr->value()); | |
| 2655 if (instr->representation().IsInteger32()) { | |
| 2656 LMathFloorI* result = new(zone()) LMathFloorI(input); | |
| 2657 return AssignEnvironment(AssignPointerMap(DefineAsRegister(result))); | |
| 2658 } else { | |
| 2659 DCHECK(instr->representation().IsDouble()); | |
| 2660 LMathFloorD* result = new(zone()) LMathFloorD(input); | |
| 2661 return DefineAsRegister(result); | |
| 2662 } | |
| 2663 } | |
| 2664 case kMathLog: { | |
| 2665 DCHECK(instr->representation().IsDouble()); | |
| 2666 DCHECK(instr->value()->representation().IsDouble()); | |
| 2667 LOperand* input = UseFixedDouble(instr->value(), d0); | |
| 2668 LMathLog* result = new(zone()) LMathLog(input); | |
| 2669 return MarkAsCall(DefineFixedDouble(result, d0), instr); | |
| 2670 } | |
| 2671 case kMathPowHalf: { | |
| 2672 DCHECK(instr->representation().IsDouble()); | |
| 2673 DCHECK(instr->value()->representation().IsDouble()); | |
| 2674 LOperand* input = UseRegister(instr->value()); | |
| 2675 return DefineAsRegister(new(zone()) LMathPowHalf(input)); | |
| 2676 } | |
| 2677 case kMathRound: { | |
| 2678 DCHECK(instr->value()->representation().IsDouble()); | |
| 2679 LOperand* input = UseRegister(instr->value()); | |
| 2680 if (instr->representation().IsInteger32()) { | |
| 2681 LOperand* temp = TempDoubleRegister(); | |
| 2682 LMathRoundI* result = new(zone()) LMathRoundI(input, temp); | |
| 2683 return AssignEnvironment(DefineAsRegister(result)); | |
| 2684 } else { | |
| 2685 DCHECK(instr->representation().IsDouble()); | |
| 2686 LMathRoundD* result = new(zone()) LMathRoundD(input); | |
| 2687 return DefineAsRegister(result); | |
| 2688 } | |
| 2689 } | |
| 2690 case kMathFround: { | |
| 2691 DCHECK(instr->value()->representation().IsDouble()); | |
| 2692 LOperand* input = UseRegister(instr->value()); | |
| 2693 LMathFround* result = new (zone()) LMathFround(input); | |
| 2694 return DefineAsRegister(result); | |
| 2695 } | |
| 2696 case kMathSqrt: { | |
| 2697 DCHECK(instr->representation().IsDouble()); | |
| 2698 DCHECK(instr->value()->representation().IsDouble()); | |
| 2699 LOperand* input = UseRegisterAtStart(instr->value()); | |
| 2700 return DefineAsRegister(new(zone()) LMathSqrt(input)); | |
| 2701 } | |
| 2702 case kMathClz32: { | |
| 2703 DCHECK(instr->representation().IsInteger32()); | |
| 2704 DCHECK(instr->value()->representation().IsInteger32()); | |
| 2705 LOperand* input = UseRegisterAtStart(instr->value()); | |
| 2706 return DefineAsRegister(new(zone()) LMathClz32(input)); | |
| 2707 } | |
| 2708 default: | |
| 2709 UNREACHABLE(); | |
| 2710 return NULL; | |
| 2711 } | |
| 2712 } | |
| 2713 | |
| 2714 | |
| 2715 LInstruction* LChunkBuilder::DoUnknownOSRValue(HUnknownOSRValue* instr) { | |
| 2716 // Use an index that corresponds to the location in the unoptimized frame, | |
| 2717 // which the optimized frame will subsume. | |
| 2718 int env_index = instr->index(); | |
| 2719 int spill_index = 0; | |
| 2720 if (instr->environment()->is_parameter_index(env_index)) { | |
| 2721 spill_index = chunk_->GetParameterStackSlot(env_index); | |
| 2722 } else { | |
| 2723 spill_index = env_index - instr->environment()->first_local_index(); | |
| 2724 if (spill_index > LUnallocated::kMaxFixedSlotIndex) { | |
| 2725 Retry(kTooManySpillSlotsNeededForOSR); | |
| 2726 spill_index = 0; | |
| 2727 } | |
| 2728 } | |
| 2729 return DefineAsSpilled(new(zone()) LUnknownOSRValue, spill_index); | |
| 2730 } | |
| 2731 | |
| 2732 | |
| 2733 LInstruction* LChunkBuilder::DoUseConst(HUseConst* instr) { | |
| 2734 return NULL; | |
| 2735 } | |
| 2736 | |
| 2737 | |
| 2738 LInstruction* LChunkBuilder::DoForInPrepareMap(HForInPrepareMap* instr) { | |
| 2739 LOperand* context = UseFixed(instr->context(), cp); | |
| 2740 // Assign object to a fixed register different from those already used in | |
| 2741 // LForInPrepareMap. | |
| 2742 LOperand* object = UseFixed(instr->enumerable(), x0); | |
| 2743 LForInPrepareMap* result = new(zone()) LForInPrepareMap(context, object); | |
| 2744 return MarkAsCall(DefineFixed(result, x0), instr, CAN_DEOPTIMIZE_EAGERLY); | |
| 2745 } | |
| 2746 | |
| 2747 | |
| 2748 LInstruction* LChunkBuilder::DoForInCacheArray(HForInCacheArray* instr) { | |
| 2749 LOperand* map = UseRegister(instr->map()); | |
| 2750 return AssignEnvironment(DefineAsRegister(new(zone()) LForInCacheArray(map))); | |
| 2751 } | |
| 2752 | |
| 2753 | |
| 2754 LInstruction* LChunkBuilder::DoCheckMapValue(HCheckMapValue* instr) { | |
| 2755 LOperand* value = UseRegisterAtStart(instr->value()); | |
| 2756 LOperand* map = UseRegister(instr->map()); | |
| 2757 LOperand* temp = TempRegister(); | |
| 2758 return AssignEnvironment(new(zone()) LCheckMapValue(value, map, temp)); | |
| 2759 } | |
| 2760 | |
| 2761 | |
| 2762 LInstruction* LChunkBuilder::DoLoadFieldByIndex(HLoadFieldByIndex* instr) { | |
| 2763 LOperand* object = UseRegisterAtStart(instr->object()); | |
| 2764 LOperand* index = UseRegisterAndClobber(instr->index()); | |
| 2765 LLoadFieldByIndex* load = new(zone()) LLoadFieldByIndex(object, index); | |
| 2766 LInstruction* result = DefineSameAsFirst(load); | |
| 2767 return AssignPointerMap(result); | |
| 2768 } | |
| 2769 | |
| 2770 | |
| 2771 LInstruction* LChunkBuilder::DoWrapReceiver(HWrapReceiver* instr) { | |
| 2772 LOperand* receiver = UseRegister(instr->receiver()); | |
| 2773 LOperand* function = UseRegister(instr->function()); | |
| 2774 LWrapReceiver* result = new(zone()) LWrapReceiver(receiver, function); | |
| 2775 return AssignEnvironment(DefineAsRegister(result)); | |
| 2776 } | |
| 2777 | |
| 2778 | |
| 2779 LInstruction* LChunkBuilder::DoStoreFrameContext(HStoreFrameContext* instr) { | |
| 2780 LOperand* context = UseRegisterAtStart(instr->context()); | |
| 2781 return new(zone()) LStoreFrameContext(context); | |
| 2782 } | |
| 2783 | |
| 2784 | |
| 2785 LInstruction* LChunkBuilder::DoAllocateBlockContext( | |
| 2786 HAllocateBlockContext* instr) { | |
| 2787 LOperand* context = UseFixed(instr->context(), cp); | |
| 2788 LOperand* function = UseRegisterAtStart(instr->function()); | |
| 2789 LAllocateBlockContext* result = | |
| 2790 new(zone()) LAllocateBlockContext(context, function); | |
| 2791 return MarkAsCall(DefineFixed(result, cp), instr); | |
| 2792 } | |
| 2793 | |
| 2794 | |
| 2795 } // namespace internal | |
| 2796 } // namespace v8 | |
| OLD | NEW |