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