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