Ben Murdoch | 086aeea | 2011-05-13 15:57:08 +0100 | [diff] [blame^] | 1 | // Copyright 2011 the V8 project authors. All rights reserved. |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 2 | // Redistribution and use in source and binary forms, with or without |
| 3 | // modification, are permitted provided that the following conditions are |
| 4 | // met: |
| 5 | // |
| 6 | // * Redistributions of source code must retain the above copyright |
| 7 | // notice, this list of conditions and the following disclaimer. |
| 8 | // * Redistributions in binary form must reproduce the above |
| 9 | // copyright notice, this list of conditions and the following |
| 10 | // disclaimer in the documentation and/or other materials provided |
| 11 | // with the distribution. |
| 12 | // * Neither the name of Google Inc. nor the names of its |
| 13 | // contributors may be used to endorse or promote products derived |
| 14 | // from this software without specific prior written permission. |
| 15 | // |
| 16 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 17 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 18 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 19 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 20 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 21 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 22 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 23 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 24 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 26 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | |
| 28 | #include "arm/lithium-arm.h" |
| 29 | #include "arm/lithium-codegen-arm.h" |
| 30 | |
| 31 | namespace v8 { |
| 32 | namespace internal { |
| 33 | |
| 34 | #define DEFINE_COMPILE(type) \ |
| 35 | void L##type::CompileToNative(LCodeGen* generator) { \ |
| 36 | generator->Do##type(this); \ |
| 37 | } |
| 38 | LITHIUM_CONCRETE_INSTRUCTION_LIST(DEFINE_COMPILE) |
| 39 | #undef DEFINE_COMPILE |
| 40 | |
| 41 | LOsrEntry::LOsrEntry() { |
| 42 | for (int i = 0; i < Register::kNumAllocatableRegisters; ++i) { |
| 43 | register_spills_[i] = NULL; |
| 44 | } |
| 45 | for (int i = 0; i < DoubleRegister::kNumAllocatableRegisters; ++i) { |
| 46 | double_register_spills_[i] = NULL; |
| 47 | } |
| 48 | } |
| 49 | |
| 50 | |
| 51 | void LOsrEntry::MarkSpilledRegister(int allocation_index, |
| 52 | LOperand* spill_operand) { |
| 53 | ASSERT(spill_operand->IsStackSlot()); |
| 54 | ASSERT(register_spills_[allocation_index] == NULL); |
| 55 | register_spills_[allocation_index] = spill_operand; |
| 56 | } |
| 57 | |
| 58 | |
| 59 | void LOsrEntry::MarkSpilledDoubleRegister(int allocation_index, |
| 60 | LOperand* spill_operand) { |
| 61 | ASSERT(spill_operand->IsDoubleStackSlot()); |
| 62 | ASSERT(double_register_spills_[allocation_index] == NULL); |
| 63 | double_register_spills_[allocation_index] = spill_operand; |
| 64 | } |
| 65 | |
| 66 | |
| 67 | void LInstruction::PrintTo(StringStream* stream) const { |
| 68 | stream->Add("%s ", this->Mnemonic()); |
| 69 | if (HasResult()) { |
| 70 | result()->PrintTo(stream); |
| 71 | stream->Add(" "); |
| 72 | } |
| 73 | PrintDataTo(stream); |
| 74 | |
| 75 | if (HasEnvironment()) { |
| 76 | stream->Add(" "); |
| 77 | environment()->PrintTo(stream); |
| 78 | } |
| 79 | |
| 80 | if (HasPointerMap()) { |
| 81 | stream->Add(" "); |
| 82 | pointer_map()->PrintTo(stream); |
| 83 | } |
| 84 | } |
| 85 | |
| 86 | |
| 87 | void LLabel::PrintDataTo(StringStream* stream) const { |
| 88 | LGap::PrintDataTo(stream); |
| 89 | LLabel* rep = replacement(); |
| 90 | if (rep != NULL) { |
| 91 | stream->Add(" Dead block replaced with B%d", rep->block_id()); |
| 92 | } |
| 93 | } |
| 94 | |
| 95 | |
| 96 | bool LParallelMove::IsRedundant() const { |
| 97 | for (int i = 0; i < move_operands_.length(); ++i) { |
| 98 | if (!move_operands_[i].IsRedundant()) return false; |
| 99 | } |
| 100 | return true; |
| 101 | } |
| 102 | |
| 103 | |
| 104 | void LParallelMove::PrintDataTo(StringStream* stream) const { |
| 105 | for (int i = move_operands_.length() - 1; i >= 0; --i) { |
| 106 | if (!move_operands_[i].IsEliminated()) { |
| 107 | LOperand* from = move_operands_[i].from(); |
| 108 | LOperand* to = move_operands_[i].to(); |
| 109 | if (from->Equals(to)) { |
| 110 | to->PrintTo(stream); |
| 111 | } else { |
| 112 | to->PrintTo(stream); |
| 113 | stream->Add(" = "); |
| 114 | from->PrintTo(stream); |
| 115 | } |
| 116 | stream->Add("; "); |
| 117 | } |
| 118 | } |
| 119 | } |
| 120 | |
| 121 | |
| 122 | bool LGap::IsRedundant() const { |
| 123 | for (int i = 0; i < 4; i++) { |
| 124 | if (parallel_moves_[i] != NULL && !parallel_moves_[i]->IsRedundant()) { |
| 125 | return false; |
| 126 | } |
| 127 | } |
| 128 | |
| 129 | return true; |
| 130 | } |
| 131 | |
| 132 | |
| 133 | void LGap::PrintDataTo(StringStream* stream) const { |
| 134 | for (int i = 0; i < 4; i++) { |
| 135 | stream->Add("("); |
| 136 | if (parallel_moves_[i] != NULL) { |
| 137 | parallel_moves_[i]->PrintDataTo(stream); |
| 138 | } |
| 139 | stream->Add(") "); |
| 140 | } |
| 141 | } |
| 142 | |
| 143 | |
| 144 | const char* LArithmeticD::Mnemonic() const { |
| 145 | switch (op()) { |
| 146 | case Token::ADD: return "add-d"; |
| 147 | case Token::SUB: return "sub-d"; |
| 148 | case Token::MUL: return "mul-d"; |
| 149 | case Token::DIV: return "div-d"; |
| 150 | case Token::MOD: return "mod-d"; |
| 151 | default: |
| 152 | UNREACHABLE(); |
| 153 | return NULL; |
| 154 | } |
| 155 | } |
| 156 | |
| 157 | |
| 158 | const char* LArithmeticT::Mnemonic() const { |
| 159 | switch (op()) { |
| 160 | case Token::ADD: return "add-t"; |
| 161 | case Token::SUB: return "sub-t"; |
| 162 | case Token::MUL: return "mul-t"; |
| 163 | case Token::MOD: return "mod-t"; |
| 164 | case Token::DIV: return "div-t"; |
| 165 | default: |
| 166 | UNREACHABLE(); |
| 167 | return NULL; |
| 168 | } |
| 169 | } |
| 170 | |
| 171 | |
| 172 | |
| 173 | void LBinaryOperation::PrintDataTo(StringStream* stream) const { |
| 174 | stream->Add("= "); |
| 175 | left()->PrintTo(stream); |
| 176 | stream->Add(" "); |
| 177 | right()->PrintTo(stream); |
| 178 | } |
| 179 | |
| 180 | |
| 181 | void LGoto::PrintDataTo(StringStream* stream) const { |
| 182 | stream->Add("B%d", block_id()); |
| 183 | } |
| 184 | |
| 185 | |
| 186 | void LBranch::PrintDataTo(StringStream* stream) const { |
| 187 | stream->Add("B%d | B%d on ", true_block_id(), false_block_id()); |
| 188 | input()->PrintTo(stream); |
| 189 | } |
| 190 | |
| 191 | |
| 192 | void LCmpIDAndBranch::PrintDataTo(StringStream* stream) const { |
| 193 | stream->Add("if "); |
| 194 | left()->PrintTo(stream); |
| 195 | stream->Add(" %s ", Token::String(op())); |
| 196 | right()->PrintTo(stream); |
| 197 | stream->Add(" then B%d else B%d", true_block_id(), false_block_id()); |
| 198 | } |
| 199 | |
| 200 | |
| 201 | void LIsNullAndBranch::PrintDataTo(StringStream* stream) const { |
| 202 | stream->Add("if "); |
| 203 | input()->PrintTo(stream); |
| 204 | stream->Add(is_strict() ? " === null" : " == null"); |
| 205 | stream->Add(" then B%d else B%d", true_block_id(), false_block_id()); |
| 206 | } |
| 207 | |
| 208 | |
| 209 | void LIsObjectAndBranch::PrintDataTo(StringStream* stream) const { |
| 210 | stream->Add("if is_object("); |
| 211 | input()->PrintTo(stream); |
| 212 | stream->Add(") then B%d else B%d", true_block_id(), false_block_id()); |
| 213 | } |
| 214 | |
| 215 | |
| 216 | void LIsSmiAndBranch::PrintDataTo(StringStream* stream) const { |
| 217 | stream->Add("if is_smi("); |
| 218 | input()->PrintTo(stream); |
| 219 | stream->Add(") then B%d else B%d", true_block_id(), false_block_id()); |
| 220 | } |
| 221 | |
| 222 | |
| 223 | void LHasInstanceTypeAndBranch::PrintDataTo(StringStream* stream) const { |
| 224 | stream->Add("if has_instance_type("); |
| 225 | input()->PrintTo(stream); |
| 226 | stream->Add(") then B%d else B%d", true_block_id(), false_block_id()); |
| 227 | } |
| 228 | |
| 229 | |
| 230 | void LHasCachedArrayIndexAndBranch::PrintDataTo(StringStream* stream) const { |
| 231 | stream->Add("if has_cached_array_index("); |
| 232 | input()->PrintTo(stream); |
| 233 | stream->Add(") then B%d else B%d", true_block_id(), false_block_id()); |
| 234 | } |
| 235 | |
| 236 | |
| 237 | void LClassOfTestAndBranch::PrintDataTo(StringStream* stream) const { |
| 238 | stream->Add("if class_of_test("); |
| 239 | input()->PrintTo(stream); |
| 240 | stream->Add(", \"%o\") then B%d else B%d", |
| 241 | *hydrogen()->class_name(), |
| 242 | true_block_id(), |
| 243 | false_block_id()); |
| 244 | } |
| 245 | |
| 246 | |
| 247 | void LTypeofIs::PrintDataTo(StringStream* stream) const { |
| 248 | input()->PrintTo(stream); |
| 249 | stream->Add(" == \"%s\"", *hydrogen()->type_literal()->ToCString()); |
| 250 | } |
| 251 | |
| 252 | |
| 253 | void LTypeofIsAndBranch::PrintDataTo(StringStream* stream) const { |
| 254 | stream->Add("if typeof "); |
| 255 | input()->PrintTo(stream); |
| 256 | stream->Add(" == \"%s\" then B%d else B%d", |
| 257 | *hydrogen()->type_literal()->ToCString(), |
| 258 | true_block_id(), false_block_id()); |
| 259 | } |
| 260 | |
| 261 | |
| 262 | void LCallConstantFunction::PrintDataTo(StringStream* stream) const { |
| 263 | stream->Add("#%d / ", arity()); |
| 264 | } |
| 265 | |
| 266 | |
| 267 | void LUnaryMathOperation::PrintDataTo(StringStream* stream) const { |
| 268 | stream->Add("/%s ", hydrogen()->OpName()); |
| 269 | input()->PrintTo(stream); |
| 270 | } |
| 271 | |
| 272 | |
| 273 | void LCallKeyed::PrintDataTo(StringStream* stream) const { |
| 274 | stream->Add("[r2] #%d / ", arity()); |
| 275 | } |
| 276 | |
| 277 | |
| 278 | void LCallNamed::PrintDataTo(StringStream* stream) const { |
| 279 | SmartPointer<char> name_string = name()->ToCString(); |
| 280 | stream->Add("%s #%d / ", *name_string, arity()); |
| 281 | } |
| 282 | |
| 283 | |
| 284 | void LCallGlobal::PrintDataTo(StringStream* stream) const { |
| 285 | SmartPointer<char> name_string = name()->ToCString(); |
| 286 | stream->Add("%s #%d / ", *name_string, arity()); |
| 287 | } |
| 288 | |
| 289 | |
| 290 | void LCallKnownGlobal::PrintDataTo(StringStream* stream) const { |
| 291 | stream->Add("#%d / ", arity()); |
| 292 | } |
| 293 | |
| 294 | |
| 295 | void LCallNew::PrintDataTo(StringStream* stream) const { |
| 296 | LUnaryOperation::PrintDataTo(stream); |
| 297 | stream->Add(" #%d / ", arity()); |
| 298 | } |
| 299 | |
| 300 | |
| 301 | void LClassOfTest::PrintDataTo(StringStream* stream) const { |
| 302 | stream->Add("= class_of_test("); |
| 303 | input()->PrintTo(stream); |
| 304 | stream->Add(", \"%o\")", *hydrogen()->class_name()); |
| 305 | } |
| 306 | |
| 307 | |
| 308 | void LUnaryOperation::PrintDataTo(StringStream* stream) const { |
| 309 | stream->Add("= "); |
| 310 | input()->PrintTo(stream); |
| 311 | } |
| 312 | |
| 313 | |
| 314 | void LAccessArgumentsAt::PrintDataTo(StringStream* stream) const { |
| 315 | arguments()->PrintTo(stream); |
| 316 | |
| 317 | stream->Add(" length "); |
| 318 | length()->PrintTo(stream); |
| 319 | |
| 320 | stream->Add(" index "); |
| 321 | index()->PrintTo(stream); |
| 322 | } |
| 323 | |
| 324 | |
| 325 | LChunk::LChunk(HGraph* graph) |
| 326 | : spill_slot_count_(0), |
| 327 | graph_(graph), |
| 328 | instructions_(32), |
| 329 | pointer_maps_(8), |
| 330 | inlined_closures_(1) { |
| 331 | } |
| 332 | |
| 333 | |
| 334 | void LChunk::Verify() const { |
| 335 | // TODO(twuerthinger): Implement verification for chunk. |
| 336 | } |
| 337 | |
| 338 | |
| 339 | int LChunk::GetNextSpillIndex(bool is_double) { |
| 340 | // Skip a slot if for a double-width slot. |
| 341 | if (is_double) spill_slot_count_++; |
| 342 | return spill_slot_count_++; |
| 343 | } |
| 344 | |
| 345 | |
| 346 | LOperand* LChunk::GetNextSpillSlot(bool is_double) { |
| 347 | int index = GetNextSpillIndex(is_double); |
| 348 | if (is_double) { |
| 349 | return LDoubleStackSlot::Create(index); |
| 350 | } else { |
| 351 | return LStackSlot::Create(index); |
| 352 | } |
| 353 | } |
| 354 | |
| 355 | |
| 356 | void LChunk::MarkEmptyBlocks() { |
| 357 | HPhase phase("Mark empty blocks", this); |
| 358 | for (int i = 0; i < graph()->blocks()->length(); ++i) { |
| 359 | HBasicBlock* block = graph()->blocks()->at(i); |
| 360 | int first = block->first_instruction_index(); |
| 361 | int last = block->last_instruction_index(); |
| 362 | LInstruction* first_instr = instructions()->at(first); |
| 363 | LInstruction* last_instr = instructions()->at(last); |
| 364 | |
| 365 | LLabel* label = LLabel::cast(first_instr); |
| 366 | if (last_instr->IsGoto()) { |
| 367 | LGoto* goto_instr = LGoto::cast(last_instr); |
| 368 | if (!goto_instr->include_stack_check() && |
| 369 | label->IsRedundant() && |
| 370 | !label->is_loop_header()) { |
| 371 | bool can_eliminate = true; |
| 372 | for (int i = first + 1; i < last && can_eliminate; ++i) { |
| 373 | LInstruction* cur = instructions()->at(i); |
| 374 | if (cur->IsGap()) { |
| 375 | LGap* gap = LGap::cast(cur); |
| 376 | if (!gap->IsRedundant()) { |
| 377 | can_eliminate = false; |
| 378 | } |
| 379 | } else { |
| 380 | can_eliminate = false; |
| 381 | } |
| 382 | } |
| 383 | |
| 384 | if (can_eliminate) { |
| 385 | label->set_replacement(GetLabel(goto_instr->block_id())); |
| 386 | } |
| 387 | } |
| 388 | } |
| 389 | } |
| 390 | } |
| 391 | |
| 392 | |
| 393 | void LStoreNamed::PrintDataTo(StringStream* stream) const { |
| 394 | object()->PrintTo(stream); |
| 395 | stream->Add("."); |
| 396 | stream->Add(*String::cast(*name())->ToCString()); |
| 397 | stream->Add(" <- "); |
| 398 | value()->PrintTo(stream); |
| 399 | } |
| 400 | |
| 401 | |
| 402 | void LStoreKeyed::PrintDataTo(StringStream* stream) const { |
| 403 | object()->PrintTo(stream); |
| 404 | stream->Add("["); |
| 405 | key()->PrintTo(stream); |
| 406 | stream->Add("] <- "); |
| 407 | value()->PrintTo(stream); |
| 408 | } |
| 409 | |
| 410 | |
| 411 | int LChunk::AddInstruction(LInstruction* instr, HBasicBlock* block) { |
| 412 | LGap* gap = new LGap(block); |
| 413 | int index = -1; |
| 414 | if (instr->IsControl()) { |
| 415 | instructions_.Add(gap); |
| 416 | index = instructions_.length(); |
| 417 | instructions_.Add(instr); |
| 418 | } else { |
| 419 | index = instructions_.length(); |
| 420 | instructions_.Add(instr); |
| 421 | instructions_.Add(gap); |
| 422 | } |
| 423 | if (instr->HasPointerMap()) { |
| 424 | pointer_maps_.Add(instr->pointer_map()); |
| 425 | instr->pointer_map()->set_lithium_position(index); |
| 426 | } |
| 427 | return index; |
| 428 | } |
| 429 | |
| 430 | |
| 431 | LConstantOperand* LChunk::DefineConstantOperand(HConstant* constant) { |
| 432 | return LConstantOperand::Create(constant->id()); |
| 433 | } |
| 434 | |
| 435 | |
| 436 | int LChunk::GetParameterStackSlot(int index) const { |
| 437 | // The receiver is at index 0, the first parameter at index 1, so we |
| 438 | // shift all parameter indexes down by the number of parameters, and |
| 439 | // make sure they end up negative so they are distinguishable from |
| 440 | // spill slots. |
| 441 | int result = index - graph()->info()->scope()->num_parameters() - 1; |
| 442 | ASSERT(result < 0); |
| 443 | return result; |
| 444 | } |
| 445 | |
| 446 | // A parameter relative to ebp in the arguments stub. |
| 447 | int LChunk::ParameterAt(int index) { |
| 448 | ASSERT(-1 <= index); // -1 is the receiver. |
| 449 | return (1 + graph()->info()->scope()->num_parameters() - index) * |
| 450 | kPointerSize; |
| 451 | } |
| 452 | |
| 453 | |
| 454 | LGap* LChunk::GetGapAt(int index) const { |
| 455 | return LGap::cast(instructions_[index]); |
| 456 | } |
| 457 | |
| 458 | |
| 459 | bool LChunk::IsGapAt(int index) const { |
| 460 | return instructions_[index]->IsGap(); |
| 461 | } |
| 462 | |
| 463 | |
| 464 | int LChunk::NearestGapPos(int index) const { |
| 465 | while (!IsGapAt(index)) index--; |
| 466 | return index; |
| 467 | } |
| 468 | |
| 469 | |
| 470 | void LChunk::AddGapMove(int index, LOperand* from, LOperand* to) { |
| 471 | GetGapAt(index)->GetOrCreateParallelMove(LGap::START)->AddMove(from, to); |
| 472 | } |
| 473 | |
| 474 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 475 | Handle<Object> LChunk::LookupLiteral(LConstantOperand* operand) const { |
| 476 | return HConstant::cast(graph_->LookupValue(operand->index()))->handle(); |
| 477 | } |
| 478 | |
| 479 | |
| 480 | Representation LChunk::LookupLiteralRepresentation( |
| 481 | LConstantOperand* operand) const { |
| 482 | return graph_->LookupValue(operand->index())->representation(); |
| 483 | } |
| 484 | |
| 485 | |
| 486 | LChunk* LChunkBuilder::Build() { |
| 487 | ASSERT(is_unused()); |
| 488 | chunk_ = new LChunk(graph()); |
| 489 | HPhase phase("Building chunk", chunk_); |
| 490 | status_ = BUILDING; |
| 491 | const ZoneList<HBasicBlock*>* blocks = graph()->blocks(); |
| 492 | for (int i = 0; i < blocks->length(); i++) { |
| 493 | HBasicBlock* next = NULL; |
| 494 | if (i < blocks->length() - 1) next = blocks->at(i + 1); |
| 495 | DoBasicBlock(blocks->at(i), next); |
| 496 | if (is_aborted()) return NULL; |
| 497 | } |
| 498 | status_ = DONE; |
| 499 | return chunk_; |
| 500 | } |
| 501 | |
| 502 | |
| 503 | void LChunkBuilder::Abort(const char* format, ...) { |
| 504 | if (FLAG_trace_bailout) { |
| 505 | SmartPointer<char> debug_name = graph()->debug_name()->ToCString(); |
| 506 | PrintF("Aborting LChunk building in @\"%s\": ", *debug_name); |
| 507 | va_list arguments; |
| 508 | va_start(arguments, format); |
| 509 | OS::VPrint(format, arguments); |
| 510 | va_end(arguments); |
| 511 | PrintF("\n"); |
| 512 | } |
| 513 | status_ = ABORTED; |
| 514 | } |
| 515 | |
| 516 | |
| 517 | LRegister* LChunkBuilder::ToOperand(Register reg) { |
| 518 | return LRegister::Create(Register::ToAllocationIndex(reg)); |
| 519 | } |
| 520 | |
| 521 | |
| 522 | LUnallocated* LChunkBuilder::ToUnallocated(Register reg) { |
| 523 | return new LUnallocated(LUnallocated::FIXED_REGISTER, |
| 524 | Register::ToAllocationIndex(reg)); |
| 525 | } |
| 526 | |
| 527 | |
| 528 | LUnallocated* LChunkBuilder::ToUnallocated(DoubleRegister reg) { |
| 529 | return new LUnallocated(LUnallocated::FIXED_DOUBLE_REGISTER, |
| 530 | DoubleRegister::ToAllocationIndex(reg)); |
| 531 | } |
| 532 | |
| 533 | |
| 534 | LOperand* LChunkBuilder::UseFixed(HValue* value, Register fixed_register) { |
| 535 | return Use(value, ToUnallocated(fixed_register)); |
| 536 | } |
| 537 | |
| 538 | |
| 539 | LOperand* LChunkBuilder::UseFixedDouble(HValue* value, DoubleRegister reg) { |
| 540 | return Use(value, ToUnallocated(reg)); |
| 541 | } |
| 542 | |
| 543 | |
| 544 | LOperand* LChunkBuilder::UseRegister(HValue* value) { |
| 545 | return Use(value, new LUnallocated(LUnallocated::MUST_HAVE_REGISTER)); |
| 546 | } |
| 547 | |
| 548 | |
| 549 | LOperand* LChunkBuilder::UseRegisterAtStart(HValue* value) { |
| 550 | return Use(value, |
| 551 | new LUnallocated(LUnallocated::MUST_HAVE_REGISTER, |
| 552 | LUnallocated::USED_AT_START)); |
| 553 | } |
| 554 | |
| 555 | |
| 556 | LOperand* LChunkBuilder::UseTempRegister(HValue* value) { |
| 557 | return Use(value, new LUnallocated(LUnallocated::WRITABLE_REGISTER)); |
| 558 | } |
| 559 | |
| 560 | |
| 561 | LOperand* LChunkBuilder::Use(HValue* value) { |
| 562 | return Use(value, new LUnallocated(LUnallocated::NONE)); |
| 563 | } |
| 564 | |
| 565 | |
| 566 | LOperand* LChunkBuilder::UseAtStart(HValue* value) { |
| 567 | return Use(value, new LUnallocated(LUnallocated::NONE, |
| 568 | LUnallocated::USED_AT_START)); |
| 569 | } |
| 570 | |
| 571 | |
| 572 | LOperand* LChunkBuilder::UseOrConstant(HValue* value) { |
| 573 | return value->IsConstant() |
| 574 | ? chunk_->DefineConstantOperand(HConstant::cast(value)) |
| 575 | : Use(value); |
| 576 | } |
| 577 | |
| 578 | |
| 579 | LOperand* LChunkBuilder::UseOrConstantAtStart(HValue* value) { |
| 580 | return value->IsConstant() |
| 581 | ? chunk_->DefineConstantOperand(HConstant::cast(value)) |
| 582 | : UseAtStart(value); |
| 583 | } |
| 584 | |
| 585 | |
| 586 | LOperand* LChunkBuilder::UseRegisterOrConstant(HValue* value) { |
| 587 | return value->IsConstant() |
| 588 | ? chunk_->DefineConstantOperand(HConstant::cast(value)) |
| 589 | : UseRegister(value); |
| 590 | } |
| 591 | |
| 592 | |
| 593 | LOperand* LChunkBuilder::UseRegisterOrConstantAtStart(HValue* value) { |
| 594 | return value->IsConstant() |
| 595 | ? chunk_->DefineConstantOperand(HConstant::cast(value)) |
| 596 | : UseRegisterAtStart(value); |
| 597 | } |
| 598 | |
| 599 | |
| 600 | LOperand* LChunkBuilder::Use(HValue* value, LUnallocated* operand) { |
| 601 | if (value->EmitAtUses()) { |
| 602 | HInstruction* instr = HInstruction::cast(value); |
| 603 | VisitInstruction(instr); |
| 604 | } |
| 605 | allocator_->RecordUse(value, operand); |
| 606 | return operand; |
| 607 | } |
| 608 | |
| 609 | |
| 610 | LInstruction* LChunkBuilder::Define(LInstruction* instr) { |
| 611 | return Define(instr, new LUnallocated(LUnallocated::NONE)); |
| 612 | } |
| 613 | |
| 614 | |
| 615 | LInstruction* LChunkBuilder::DefineAsRegister(LInstruction* instr) { |
| 616 | return Define(instr, new LUnallocated(LUnallocated::MUST_HAVE_REGISTER)); |
| 617 | } |
| 618 | |
| 619 | |
| 620 | LInstruction* LChunkBuilder::DefineAsSpilled(LInstruction* instr, int index) { |
| 621 | return Define(instr, new LUnallocated(LUnallocated::FIXED_SLOT, index)); |
| 622 | } |
| 623 | |
| 624 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 625 | LInstruction* LChunkBuilder::DefineSameAsFirst(LInstruction* instr) { |
| 626 | return Define(instr, new LUnallocated(LUnallocated::SAME_AS_FIRST_INPUT)); |
| 627 | } |
| 628 | |
| 629 | |
| 630 | LInstruction* LChunkBuilder::DefineFixed(LInstruction* instr, Register reg) { |
| 631 | return Define(instr, ToUnallocated(reg)); |
| 632 | } |
| 633 | |
| 634 | |
| 635 | LInstruction* LChunkBuilder::DefineFixedDouble(LInstruction* instr, |
| 636 | DoubleRegister reg) { |
| 637 | return Define(instr, ToUnallocated(reg)); |
| 638 | } |
| 639 | |
| 640 | |
| 641 | LInstruction* LChunkBuilder::AssignEnvironment(LInstruction* instr) { |
| 642 | HEnvironment* hydrogen_env = current_block_->last_environment(); |
| 643 | instr->set_environment(CreateEnvironment(hydrogen_env)); |
| 644 | return instr; |
| 645 | } |
| 646 | |
| 647 | |
| 648 | LInstruction* LChunkBuilder::SetInstructionPendingDeoptimizationEnvironment( |
| 649 | LInstruction* instr, int ast_id) { |
| 650 | ASSERT(instructions_pending_deoptimization_environment_ == NULL); |
| 651 | ASSERT(pending_deoptimization_ast_id_ == AstNode::kNoNumber); |
| 652 | instructions_pending_deoptimization_environment_ = instr; |
| 653 | pending_deoptimization_ast_id_ = ast_id; |
| 654 | return instr; |
| 655 | } |
| 656 | |
| 657 | |
| 658 | void LChunkBuilder::ClearInstructionPendingDeoptimizationEnvironment() { |
| 659 | instructions_pending_deoptimization_environment_ = NULL; |
| 660 | pending_deoptimization_ast_id_ = AstNode::kNoNumber; |
| 661 | } |
| 662 | |
| 663 | |
| 664 | LInstruction* LChunkBuilder::MarkAsCall(LInstruction* instr, |
| 665 | HInstruction* hinstr, |
| 666 | CanDeoptimize can_deoptimize) { |
| 667 | allocator_->MarkAsCall(); |
| 668 | instr = AssignPointerMap(instr); |
| 669 | |
| 670 | if (hinstr->HasSideEffects()) { |
| 671 | ASSERT(hinstr->next()->IsSimulate()); |
| 672 | HSimulate* sim = HSimulate::cast(hinstr->next()); |
| 673 | instr = SetInstructionPendingDeoptimizationEnvironment( |
| 674 | instr, sim->ast_id()); |
| 675 | } |
| 676 | |
| 677 | // If instruction does not have side-effects lazy deoptimization |
| 678 | // after the call will try to deoptimize to the point before the call. |
| 679 | // Thus we still need to attach environment to this call even if |
| 680 | // call sequence can not deoptimize eagerly. |
| 681 | bool needs_environment = |
| 682 | (can_deoptimize == CAN_DEOPTIMIZE_EAGERLY) || !hinstr->HasSideEffects(); |
| 683 | if (needs_environment && !instr->HasEnvironment()) { |
| 684 | instr = AssignEnvironment(instr); |
| 685 | } |
| 686 | |
| 687 | return instr; |
| 688 | } |
| 689 | |
| 690 | |
| 691 | LInstruction* LChunkBuilder::AssignPointerMap(LInstruction* instr) { |
| 692 | ASSERT(!instr->HasPointerMap()); |
| 693 | instr->set_pointer_map(new LPointerMap(position_)); |
| 694 | return instr; |
| 695 | } |
| 696 | |
| 697 | |
| 698 | LInstruction* LChunkBuilder::Define(LInstruction* instr, LUnallocated* result) { |
| 699 | allocator_->RecordDefinition(current_instruction_, result); |
| 700 | instr->set_result(result); |
| 701 | return instr; |
| 702 | } |
| 703 | |
| 704 | |
| 705 | LOperand* LChunkBuilder::Temp() { |
| 706 | LUnallocated* operand = new LUnallocated(LUnallocated::NONE); |
| 707 | allocator_->RecordTemporary(operand); |
| 708 | return operand; |
| 709 | } |
| 710 | |
| 711 | |
| 712 | LUnallocated* LChunkBuilder::TempRegister() { |
| 713 | LUnallocated* operand = new LUnallocated(LUnallocated::MUST_HAVE_REGISTER); |
| 714 | allocator_->RecordTemporary(operand); |
| 715 | return operand; |
| 716 | } |
| 717 | |
| 718 | |
| 719 | LOperand* LChunkBuilder::FixedTemp(Register reg) { |
| 720 | LUnallocated* operand = ToUnallocated(reg); |
| 721 | allocator_->RecordTemporary(operand); |
| 722 | return operand; |
| 723 | } |
| 724 | |
| 725 | |
| 726 | LOperand* LChunkBuilder::FixedTemp(DoubleRegister reg) { |
| 727 | LUnallocated* operand = ToUnallocated(reg); |
| 728 | allocator_->RecordTemporary(operand); |
| 729 | return operand; |
| 730 | } |
| 731 | |
| 732 | |
| 733 | LInstruction* LChunkBuilder::DoBlockEntry(HBlockEntry* instr) { |
| 734 | return new LLabel(instr->block()); |
| 735 | } |
| 736 | |
| 737 | |
| 738 | LInstruction* LChunkBuilder::DoDeoptimize(HDeoptimize* instr) { |
| 739 | return AssignEnvironment(new LDeoptimize); |
| 740 | } |
| 741 | |
| 742 | |
| 743 | LInstruction* LChunkBuilder::DoBit(Token::Value op, |
| 744 | HBitwiseBinaryOperation* instr) { |
| 745 | ASSERT(instr->representation().IsInteger32()); |
| 746 | ASSERT(instr->left()->representation().IsInteger32()); |
| 747 | ASSERT(instr->right()->representation().IsInteger32()); |
| 748 | |
| 749 | LOperand* left = UseRegisterAtStart(instr->LeastConstantOperand()); |
| 750 | LOperand* right = UseOrConstantAtStart(instr->MostConstantOperand()); |
| 751 | return DefineSameAsFirst(new LBitI(op, left, right)); |
| 752 | } |
| 753 | |
| 754 | |
| 755 | LInstruction* LChunkBuilder::DoShift(Token::Value op, |
| 756 | HBitwiseBinaryOperation* instr) { |
| 757 | ASSERT(instr->representation().IsInteger32()); |
| 758 | ASSERT(instr->OperandAt(0)->representation().IsInteger32()); |
| 759 | ASSERT(instr->OperandAt(1)->representation().IsInteger32()); |
| 760 | LOperand* left = UseRegisterAtStart(instr->OperandAt(0)); |
| 761 | |
| 762 | HValue* right_value = instr->OperandAt(1); |
| 763 | LOperand* right = NULL; |
| 764 | int constant_value = 0; |
| 765 | if (right_value->IsConstant()) { |
| 766 | HConstant* constant = HConstant::cast(right_value); |
| 767 | right = chunk_->DefineConstantOperand(constant); |
| 768 | constant_value = constant->Integer32Value() & 0x1f; |
| 769 | } else { |
| 770 | right = UseRegister(right_value); |
| 771 | } |
| 772 | |
| 773 | // Shift operations can only deoptimize if we do a logical shift |
| 774 | // by 0 and the result cannot be truncated to int32. |
| 775 | bool can_deopt = (op == Token::SHR && constant_value == 0); |
| 776 | if (can_deopt) { |
| 777 | bool can_truncate = true; |
| 778 | for (int i = 0; i < instr->uses()->length(); i++) { |
| 779 | if (!instr->uses()->at(i)->CheckFlag(HValue::kTruncatingToInt32)) { |
| 780 | can_truncate = false; |
| 781 | break; |
| 782 | } |
| 783 | } |
| 784 | can_deopt = !can_truncate; |
| 785 | } |
| 786 | |
| 787 | LInstruction* result = |
| 788 | DefineSameAsFirst(new LShiftI(op, left, right, can_deopt)); |
| 789 | if (can_deopt) AssignEnvironment(result); |
| 790 | return result; |
| 791 | } |
| 792 | |
| 793 | |
| 794 | LInstruction* LChunkBuilder::DoArithmeticD(Token::Value op, |
| 795 | HArithmeticBinaryOperation* instr) { |
| 796 | ASSERT(instr->representation().IsDouble()); |
| 797 | ASSERT(instr->left()->representation().IsDouble()); |
| 798 | ASSERT(instr->right()->representation().IsDouble()); |
| 799 | LOperand* left = UseRegisterAtStart(instr->left()); |
| 800 | LOperand* right = UseRegisterAtStart(instr->right()); |
| 801 | LArithmeticD* result = new LArithmeticD(op, left, right); |
| 802 | return DefineSameAsFirst(result); |
| 803 | } |
| 804 | |
| 805 | |
| 806 | LInstruction* LChunkBuilder::DoArithmeticT(Token::Value op, |
| 807 | HArithmeticBinaryOperation* instr) { |
| 808 | ASSERT(op == Token::ADD || |
| 809 | op == Token::DIV || |
| 810 | op == Token::MOD || |
| 811 | op == Token::MUL || |
| 812 | op == Token::SUB); |
| 813 | HValue* left = instr->left(); |
| 814 | HValue* right = instr->right(); |
| 815 | ASSERT(left->representation().IsTagged()); |
| 816 | ASSERT(right->representation().IsTagged()); |
| 817 | LOperand* left_operand = UseFixed(left, r1); |
| 818 | LOperand* right_operand = UseFixed(right, r0); |
| 819 | LInstruction* result = new LArithmeticT(op, left_operand, right_operand); |
| 820 | return MarkAsCall(DefineFixed(result, r0), instr); |
| 821 | } |
| 822 | |
| 823 | void LChunkBuilder::DoBasicBlock(HBasicBlock* block, HBasicBlock* next_block) { |
| 824 | ASSERT(is_building()); |
| 825 | current_block_ = block; |
| 826 | next_block_ = next_block; |
| 827 | if (block->IsStartBlock()) { |
| 828 | block->UpdateEnvironment(graph_->start_environment()); |
| 829 | argument_count_ = 0; |
| 830 | } else if (block->predecessors()->length() == 1) { |
| 831 | // We have a single predecessor => copy environment and outgoing |
| 832 | // argument count from the predecessor. |
| 833 | ASSERT(block->phis()->length() == 0); |
| 834 | HBasicBlock* pred = block->predecessors()->at(0); |
| 835 | HEnvironment* last_environment = pred->last_environment(); |
| 836 | ASSERT(last_environment != NULL); |
| 837 | // Only copy the environment, if it is later used again. |
| 838 | if (pred->end()->SecondSuccessor() == NULL) { |
| 839 | ASSERT(pred->end()->FirstSuccessor() == block); |
| 840 | } else { |
| 841 | if (pred->end()->FirstSuccessor()->block_id() > block->block_id() || |
| 842 | pred->end()->SecondSuccessor()->block_id() > block->block_id()) { |
| 843 | last_environment = last_environment->Copy(); |
| 844 | } |
| 845 | } |
| 846 | block->UpdateEnvironment(last_environment); |
| 847 | ASSERT(pred->argument_count() >= 0); |
| 848 | argument_count_ = pred->argument_count(); |
| 849 | } else { |
| 850 | // We are at a state join => process phis. |
| 851 | HBasicBlock* pred = block->predecessors()->at(0); |
| 852 | // No need to copy the environment, it cannot be used later. |
| 853 | HEnvironment* last_environment = pred->last_environment(); |
| 854 | for (int i = 0; i < block->phis()->length(); ++i) { |
| 855 | HPhi* phi = block->phis()->at(i); |
| 856 | last_environment->SetValueAt(phi->merged_index(), phi); |
| 857 | } |
| 858 | for (int i = 0; i < block->deleted_phis()->length(); ++i) { |
| 859 | last_environment->SetValueAt(block->deleted_phis()->at(i), |
| 860 | graph_->GetConstantUndefined()); |
| 861 | } |
| 862 | block->UpdateEnvironment(last_environment); |
| 863 | // Pick up the outgoing argument count of one of the predecessors. |
| 864 | argument_count_ = pred->argument_count(); |
| 865 | } |
| 866 | HInstruction* current = block->first(); |
| 867 | int start = chunk_->instructions()->length(); |
| 868 | while (current != NULL && !is_aborted()) { |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 869 | // Code for constants in registers is generated lazily. |
| 870 | if (!current->EmitAtUses()) { |
| 871 | VisitInstruction(current); |
| 872 | } |
| 873 | current = current->next(); |
| 874 | } |
| 875 | int end = chunk_->instructions()->length() - 1; |
| 876 | if (end >= start) { |
| 877 | block->set_first_instruction_index(start); |
| 878 | block->set_last_instruction_index(end); |
| 879 | } |
| 880 | block->set_argument_count(argument_count_); |
| 881 | next_block_ = NULL; |
| 882 | current_block_ = NULL; |
| 883 | } |
| 884 | |
| 885 | |
| 886 | void LChunkBuilder::VisitInstruction(HInstruction* current) { |
| 887 | HInstruction* old_current = current_instruction_; |
| 888 | current_instruction_ = current; |
| 889 | allocator_->BeginInstruction(); |
| 890 | if (current->has_position()) position_ = current->position(); |
| 891 | LInstruction* instr = current->CompileToLithium(this); |
| 892 | |
| 893 | if (instr != NULL) { |
| 894 | if (FLAG_stress_pointer_maps && !instr->HasPointerMap()) { |
| 895 | instr = AssignPointerMap(instr); |
| 896 | } |
| 897 | if (FLAG_stress_environments && !instr->HasEnvironment()) { |
| 898 | instr = AssignEnvironment(instr); |
| 899 | } |
| 900 | if (current->IsBranch()) { |
| 901 | instr->set_hydrogen_value(HBranch::cast(current)->value()); |
| 902 | } else { |
| 903 | instr->set_hydrogen_value(current); |
| 904 | } |
| 905 | |
| 906 | int index = chunk_->AddInstruction(instr, current_block_); |
| 907 | allocator_->SummarizeInstruction(index); |
| 908 | } else { |
| 909 | // This instruction should be omitted. |
| 910 | allocator_->OmitInstruction(); |
| 911 | } |
| 912 | current_instruction_ = old_current; |
| 913 | } |
| 914 | |
| 915 | |
| 916 | void LEnvironment::WriteTranslation(LCodeGen* cgen, |
| 917 | Translation* translation) const { |
| 918 | if (this == NULL) return; |
| 919 | |
| 920 | // The translation includes one command per value in the environment. |
| 921 | int translation_size = values()->length(); |
| 922 | // The output frame height does not include the parameters. |
| 923 | int height = translation_size - parameter_count(); |
| 924 | |
| 925 | outer()->WriteTranslation(cgen, translation); |
| 926 | int closure_id = cgen->DefineDeoptimizationLiteral(closure()); |
| 927 | translation->BeginFrame(ast_id(), closure_id, height); |
| 928 | for (int i = 0; i < translation_size; ++i) { |
| 929 | LOperand* value = values()->at(i); |
| 930 | // spilled_registers_ and spilled_double_registers_ are either |
| 931 | // both NULL or both set. |
| 932 | if (spilled_registers_ != NULL && value != NULL) { |
| 933 | if (value->IsRegister() && |
| 934 | spilled_registers_[value->index()] != NULL) { |
| 935 | translation->MarkDuplicate(); |
| 936 | cgen->AddToTranslation(translation, |
| 937 | spilled_registers_[value->index()], |
| 938 | HasTaggedValueAt(i)); |
| 939 | } else if (value->IsDoubleRegister() && |
| 940 | spilled_double_registers_[value->index()] != NULL) { |
| 941 | translation->MarkDuplicate(); |
| 942 | cgen->AddToTranslation(translation, |
| 943 | spilled_double_registers_[value->index()], |
| 944 | false); |
| 945 | } |
| 946 | } |
| 947 | |
| 948 | cgen->AddToTranslation(translation, value, HasTaggedValueAt(i)); |
| 949 | } |
| 950 | } |
| 951 | |
| 952 | |
| 953 | void LEnvironment::PrintTo(StringStream* stream) const { |
| 954 | stream->Add("[id=%d|", ast_id()); |
| 955 | stream->Add("[parameters=%d|", parameter_count()); |
| 956 | stream->Add("[arguments_stack_height=%d|", arguments_stack_height()); |
| 957 | for (int i = 0; i < values_.length(); ++i) { |
| 958 | if (i != 0) stream->Add(";"); |
| 959 | if (values_[i] == NULL) { |
| 960 | stream->Add("[hole]"); |
| 961 | } else { |
| 962 | values_[i]->PrintTo(stream); |
| 963 | } |
| 964 | } |
| 965 | stream->Add("]"); |
| 966 | } |
| 967 | |
| 968 | |
| 969 | LEnvironment* LChunkBuilder::CreateEnvironment(HEnvironment* hydrogen_env) { |
| 970 | if (hydrogen_env == NULL) return NULL; |
| 971 | |
| 972 | LEnvironment* outer = CreateEnvironment(hydrogen_env->outer()); |
| 973 | int ast_id = hydrogen_env->ast_id(); |
| 974 | ASSERT(ast_id != AstNode::kNoNumber); |
Steve Block | 9fac840 | 2011-05-12 15:51:54 +0100 | [diff] [blame] | 975 | int value_count = hydrogen_env->length(); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 976 | LEnvironment* result = new LEnvironment(hydrogen_env->closure(), |
| 977 | ast_id, |
| 978 | hydrogen_env->parameter_count(), |
| 979 | argument_count_, |
| 980 | value_count, |
| 981 | outer); |
| 982 | int argument_index = 0; |
| 983 | for (int i = 0; i < value_count; ++i) { |
| 984 | HValue* value = hydrogen_env->values()->at(i); |
| 985 | LOperand* op = NULL; |
| 986 | if (value->IsArgumentsObject()) { |
| 987 | op = NULL; |
| 988 | } else if (value->IsPushArgument()) { |
| 989 | op = new LArgument(argument_index++); |
| 990 | } else { |
| 991 | op = UseOrConstant(value); |
| 992 | if (op->IsUnallocated()) { |
| 993 | LUnallocated* unalloc = LUnallocated::cast(op); |
| 994 | unalloc->set_policy(LUnallocated::ANY); |
| 995 | } |
| 996 | } |
| 997 | result->AddValue(op, value->representation()); |
| 998 | } |
| 999 | |
| 1000 | return result; |
| 1001 | } |
| 1002 | |
| 1003 | |
| 1004 | LInstruction* LChunkBuilder::DoGoto(HGoto* instr) { |
| 1005 | LInstruction* result = new LGoto(instr->FirstSuccessor()->block_id(), |
| 1006 | instr->include_stack_check()); |
| 1007 | if (instr->include_stack_check()) result = AssignPointerMap(result); |
| 1008 | return result; |
| 1009 | } |
| 1010 | |
| 1011 | |
| 1012 | LInstruction* LChunkBuilder::DoBranch(HBranch* instr) { |
| 1013 | HValue* v = instr->value(); |
| 1014 | HBasicBlock* first = instr->FirstSuccessor(); |
| 1015 | HBasicBlock* second = instr->SecondSuccessor(); |
| 1016 | ASSERT(first != NULL && second != NULL); |
| 1017 | int first_id = first->block_id(); |
| 1018 | int second_id = second->block_id(); |
| 1019 | |
| 1020 | if (v->EmitAtUses()) { |
| 1021 | if (v->IsClassOfTest()) { |
| 1022 | HClassOfTest* compare = HClassOfTest::cast(v); |
| 1023 | ASSERT(compare->value()->representation().IsTagged()); |
| 1024 | |
| 1025 | return new LClassOfTestAndBranch(UseTempRegister(compare->value()), |
| 1026 | TempRegister(), |
| 1027 | TempRegister(), |
| 1028 | first_id, |
| 1029 | second_id); |
| 1030 | } else if (v->IsCompare()) { |
| 1031 | HCompare* compare = HCompare::cast(v); |
| 1032 | Token::Value op = compare->token(); |
| 1033 | HValue* left = compare->left(); |
| 1034 | HValue* right = compare->right(); |
| 1035 | if (left->representation().IsInteger32()) { |
| 1036 | ASSERT(right->representation().IsInteger32()); |
| 1037 | return new LCmpIDAndBranch(op, |
| 1038 | UseRegisterAtStart(left), |
| 1039 | UseOrConstantAtStart(right), |
| 1040 | first_id, |
| 1041 | second_id, |
| 1042 | false); |
| 1043 | } else if (left->representation().IsDouble()) { |
| 1044 | ASSERT(right->representation().IsDouble()); |
| 1045 | return new LCmpIDAndBranch(op, |
| 1046 | UseRegisterAtStart(left), |
| 1047 | UseRegisterAtStart(right), |
| 1048 | first_id, |
| 1049 | second_id, |
| 1050 | true); |
| 1051 | } else { |
| 1052 | ASSERT(left->representation().IsTagged()); |
| 1053 | ASSERT(right->representation().IsTagged()); |
| 1054 | bool reversed = op == Token::GT || op == Token::LTE; |
| 1055 | LOperand* left_operand = UseFixed(left, reversed ? r0 : r1); |
| 1056 | LOperand* right_operand = UseFixed(right, reversed ? r1 : r0); |
| 1057 | LInstruction* result = new LCmpTAndBranch(left_operand, |
| 1058 | right_operand, |
| 1059 | first_id, |
| 1060 | second_id); |
| 1061 | return MarkAsCall(result, instr); |
| 1062 | } |
| 1063 | } else if (v->IsIsSmi()) { |
| 1064 | HIsSmi* compare = HIsSmi::cast(v); |
| 1065 | ASSERT(compare->value()->representation().IsTagged()); |
| 1066 | |
| 1067 | return new LIsSmiAndBranch(Use(compare->value()), |
| 1068 | first_id, |
| 1069 | second_id); |
| 1070 | } else if (v->IsHasInstanceType()) { |
| 1071 | HHasInstanceType* compare = HHasInstanceType::cast(v); |
| 1072 | ASSERT(compare->value()->representation().IsTagged()); |
| 1073 | |
| 1074 | return new LHasInstanceTypeAndBranch(UseRegisterAtStart(compare->value()), |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1075 | first_id, |
| 1076 | second_id); |
| 1077 | } else if (v->IsHasCachedArrayIndex()) { |
| 1078 | HHasCachedArrayIndex* compare = HHasCachedArrayIndex::cast(v); |
| 1079 | ASSERT(compare->value()->representation().IsTagged()); |
| 1080 | |
| 1081 | return new LHasCachedArrayIndexAndBranch( |
| 1082 | UseRegisterAtStart(compare->value()), first_id, second_id); |
| 1083 | } else if (v->IsIsNull()) { |
| 1084 | HIsNull* compare = HIsNull::cast(v); |
| 1085 | ASSERT(compare->value()->representation().IsTagged()); |
| 1086 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1087 | return new LIsNullAndBranch(UseRegisterAtStart(compare->value()), |
| 1088 | compare->is_strict(), |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1089 | first_id, |
| 1090 | second_id); |
| 1091 | } else if (v->IsIsObject()) { |
| 1092 | HIsObject* compare = HIsObject::cast(v); |
| 1093 | ASSERT(compare->value()->representation().IsTagged()); |
| 1094 | |
| 1095 | LOperand* temp1 = TempRegister(); |
| 1096 | LOperand* temp2 = TempRegister(); |
| 1097 | return new LIsObjectAndBranch(UseRegisterAtStart(compare->value()), |
| 1098 | temp1, |
| 1099 | temp2, |
| 1100 | first_id, |
| 1101 | second_id); |
| 1102 | } else if (v->IsCompareJSObjectEq()) { |
| 1103 | HCompareJSObjectEq* compare = HCompareJSObjectEq::cast(v); |
| 1104 | return new LCmpJSObjectEqAndBranch(UseRegisterAtStart(compare->left()), |
| 1105 | UseRegisterAtStart(compare->right()), |
| 1106 | first_id, |
| 1107 | second_id); |
| 1108 | } else if (v->IsInstanceOf()) { |
| 1109 | HInstanceOf* instance_of = HInstanceOf::cast(v); |
| 1110 | LInstruction* result = |
| 1111 | new LInstanceOfAndBranch(Use(instance_of->left()), |
| 1112 | Use(instance_of->right()), |
| 1113 | first_id, |
| 1114 | second_id); |
| 1115 | return MarkAsCall(result, instr); |
| 1116 | } else if (v->IsTypeofIs()) { |
| 1117 | HTypeofIs* typeof_is = HTypeofIs::cast(v); |
| 1118 | return new LTypeofIsAndBranch(UseTempRegister(typeof_is->value()), |
| 1119 | first_id, |
| 1120 | second_id); |
| 1121 | } else { |
| 1122 | if (v->IsConstant()) { |
| 1123 | if (HConstant::cast(v)->handle()->IsTrue()) { |
| 1124 | return new LGoto(first_id); |
| 1125 | } else if (HConstant::cast(v)->handle()->IsFalse()) { |
| 1126 | return new LGoto(second_id); |
| 1127 | } |
| 1128 | } |
| 1129 | Abort("Undefined compare before branch"); |
| 1130 | return NULL; |
| 1131 | } |
| 1132 | } |
| 1133 | return new LBranch(UseRegisterAtStart(v), first_id, second_id); |
| 1134 | } |
| 1135 | |
| 1136 | |
| 1137 | LInstruction* LChunkBuilder::DoCompareMapAndBranch( |
| 1138 | HCompareMapAndBranch* instr) { |
| 1139 | ASSERT(instr->value()->representation().IsTagged()); |
| 1140 | LOperand* value = UseRegisterAtStart(instr->value()); |
Steve Block | 9fac840 | 2011-05-12 15:51:54 +0100 | [diff] [blame] | 1141 | LOperand* temp = TempRegister(); |
| 1142 | return new LCmpMapAndBranch(value, temp); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1143 | } |
| 1144 | |
| 1145 | |
| 1146 | LInstruction* LChunkBuilder::DoArgumentsLength(HArgumentsLength* length) { |
Ben Murdoch | 086aeea | 2011-05-13 15:57:08 +0100 | [diff] [blame^] | 1147 | return DefineAsRegister(new LArgumentsLength(UseRegister(length->value()))); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1148 | } |
| 1149 | |
| 1150 | |
| 1151 | LInstruction* LChunkBuilder::DoArgumentsElements(HArgumentsElements* elems) { |
| 1152 | return DefineAsRegister(new LArgumentsElements); |
| 1153 | } |
| 1154 | |
| 1155 | |
| 1156 | LInstruction* LChunkBuilder::DoInstanceOf(HInstanceOf* instr) { |
| 1157 | LInstruction* result = |
Steve Block | 9fac840 | 2011-05-12 15:51:54 +0100 | [diff] [blame] | 1158 | new LInstanceOf(UseFixed(instr->left(), r0), |
| 1159 | UseFixed(instr->right(), r1)); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1160 | return MarkAsCall(DefineFixed(result, r0), instr); |
| 1161 | } |
| 1162 | |
| 1163 | |
Ben Murdoch | 086aeea | 2011-05-13 15:57:08 +0100 | [diff] [blame^] | 1164 | LInstruction* LChunkBuilder::DoInstanceOfKnownGlobal( |
| 1165 | HInstanceOfKnownGlobal* instr) { |
| 1166 | LInstruction* result = |
| 1167 | new LInstanceOfKnownGlobal(UseFixed(instr->value(), r0)); |
| 1168 | return MarkAsCall(DefineFixed(result, r0), instr); |
| 1169 | } |
| 1170 | |
| 1171 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1172 | LInstruction* LChunkBuilder::DoApplyArguments(HApplyArguments* instr) { |
| 1173 | LOperand* function = UseFixed(instr->function(), r1); |
| 1174 | LOperand* receiver = UseFixed(instr->receiver(), r0); |
| 1175 | LOperand* length = UseRegisterAtStart(instr->length()); |
| 1176 | LOperand* elements = UseRegisterAtStart(instr->elements()); |
| 1177 | LInstruction* result = new LApplyArguments(function, |
| 1178 | receiver, |
| 1179 | length, |
| 1180 | elements); |
| 1181 | return MarkAsCall(DefineFixed(result, r0), instr, CAN_DEOPTIMIZE_EAGERLY); |
| 1182 | } |
| 1183 | |
| 1184 | |
| 1185 | LInstruction* LChunkBuilder::DoPushArgument(HPushArgument* instr) { |
| 1186 | ++argument_count_; |
| 1187 | LOperand* argument = Use(instr->argument()); |
| 1188 | return new LPushArgument(argument); |
| 1189 | } |
| 1190 | |
| 1191 | |
| 1192 | LInstruction* LChunkBuilder::DoGlobalObject(HGlobalObject* instr) { |
| 1193 | return DefineAsRegister(new LGlobalObject); |
| 1194 | } |
| 1195 | |
| 1196 | |
| 1197 | LInstruction* LChunkBuilder::DoGlobalReceiver(HGlobalReceiver* instr) { |
| 1198 | return DefineAsRegister(new LGlobalReceiver); |
| 1199 | } |
| 1200 | |
| 1201 | |
| 1202 | LInstruction* LChunkBuilder::DoCallConstantFunction( |
| 1203 | HCallConstantFunction* instr) { |
| 1204 | argument_count_ -= instr->argument_count(); |
| 1205 | return MarkAsCall(DefineFixed(new LCallConstantFunction, r0), instr); |
| 1206 | } |
| 1207 | |
| 1208 | |
| 1209 | LInstruction* LChunkBuilder::DoUnaryMathOperation(HUnaryMathOperation* instr) { |
| 1210 | BuiltinFunctionId op = instr->op(); |
| 1211 | LOperand* input = UseRegisterAtStart(instr->value()); |
| 1212 | LInstruction* result = new LUnaryMathOperation(input); |
| 1213 | switch (op) { |
| 1214 | case kMathAbs: |
| 1215 | return AssignEnvironment(AssignPointerMap(DefineSameAsFirst(result))); |
| 1216 | case kMathFloor: |
| 1217 | return AssignEnvironment(DefineAsRegister(result)); |
| 1218 | case kMathSqrt: |
| 1219 | return DefineSameAsFirst(result); |
Steve Block | 9fac840 | 2011-05-12 15:51:54 +0100 | [diff] [blame] | 1220 | case kMathRound: |
| 1221 | Abort("MathRound LUnaryMathOperation not implemented"); |
| 1222 | return NULL; |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1223 | case kMathPowHalf: |
| 1224 | Abort("MathPowHalf LUnaryMathOperation not implemented"); |
| 1225 | return NULL; |
| 1226 | case kMathLog: |
| 1227 | Abort("MathLog LUnaryMathOperation not implemented"); |
| 1228 | return NULL; |
| 1229 | case kMathCos: |
| 1230 | Abort("MathCos LUnaryMathOperation not implemented"); |
| 1231 | return NULL; |
| 1232 | case kMathSin: |
| 1233 | Abort("MathSin LUnaryMathOperation not implemented"); |
| 1234 | return NULL; |
| 1235 | default: |
| 1236 | UNREACHABLE(); |
| 1237 | return NULL; |
| 1238 | } |
| 1239 | } |
| 1240 | |
| 1241 | |
| 1242 | LInstruction* LChunkBuilder::DoCallKeyed(HCallKeyed* instr) { |
| 1243 | ASSERT(instr->key()->representation().IsTagged()); |
| 1244 | argument_count_ -= instr->argument_count(); |
| 1245 | UseFixed(instr->key(), r2); |
| 1246 | return MarkAsCall(DefineFixed(new LCallKeyed, r0), instr); |
| 1247 | } |
| 1248 | |
| 1249 | |
| 1250 | LInstruction* LChunkBuilder::DoCallNamed(HCallNamed* instr) { |
| 1251 | argument_count_ -= instr->argument_count(); |
| 1252 | return MarkAsCall(DefineFixed(new LCallNamed, r0), instr); |
| 1253 | } |
| 1254 | |
| 1255 | |
| 1256 | LInstruction* LChunkBuilder::DoCallGlobal(HCallGlobal* instr) { |
| 1257 | argument_count_ -= instr->argument_count(); |
| 1258 | return MarkAsCall(DefineFixed(new LCallGlobal, r0), instr); |
| 1259 | } |
| 1260 | |
| 1261 | |
| 1262 | LInstruction* LChunkBuilder::DoCallKnownGlobal(HCallKnownGlobal* instr) { |
| 1263 | argument_count_ -= instr->argument_count(); |
| 1264 | return MarkAsCall(DefineFixed(new LCallKnownGlobal, r0), instr); |
| 1265 | } |
| 1266 | |
| 1267 | |
| 1268 | LInstruction* LChunkBuilder::DoCallNew(HCallNew* instr) { |
| 1269 | LOperand* constructor = UseFixed(instr->constructor(), r1); |
| 1270 | argument_count_ -= instr->argument_count(); |
| 1271 | LInstruction* result = new LCallNew(constructor); |
| 1272 | return MarkAsCall(DefineFixed(result, r0), instr); |
| 1273 | } |
| 1274 | |
| 1275 | |
| 1276 | LInstruction* LChunkBuilder::DoCallFunction(HCallFunction* instr) { |
| 1277 | argument_count_ -= instr->argument_count(); |
| 1278 | return MarkAsCall(DefineFixed(new LCallFunction, r0), instr); |
| 1279 | } |
| 1280 | |
| 1281 | |
| 1282 | LInstruction* LChunkBuilder::DoCallRuntime(HCallRuntime* instr) { |
| 1283 | argument_count_ -= instr->argument_count(); |
| 1284 | return MarkAsCall(DefineFixed(new LCallRuntime, r0), instr); |
| 1285 | } |
| 1286 | |
| 1287 | |
| 1288 | LInstruction* LChunkBuilder::DoShr(HShr* instr) { |
| 1289 | return DoShift(Token::SHR, instr); |
| 1290 | } |
| 1291 | |
| 1292 | |
| 1293 | LInstruction* LChunkBuilder::DoSar(HSar* instr) { |
| 1294 | return DoShift(Token::SAR, instr); |
| 1295 | } |
| 1296 | |
| 1297 | |
| 1298 | LInstruction* LChunkBuilder::DoShl(HShl* instr) { |
| 1299 | return DoShift(Token::SHL, instr); |
| 1300 | } |
| 1301 | |
| 1302 | |
| 1303 | LInstruction* LChunkBuilder::DoBitAnd(HBitAnd* instr) { |
| 1304 | return DoBit(Token::BIT_AND, instr); |
| 1305 | } |
| 1306 | |
| 1307 | |
| 1308 | LInstruction* LChunkBuilder::DoBitNot(HBitNot* instr) { |
| 1309 | ASSERT(instr->value()->representation().IsInteger32()); |
| 1310 | ASSERT(instr->representation().IsInteger32()); |
| 1311 | return DefineSameAsFirst(new LBitNotI(UseRegisterAtStart(instr->value()))); |
| 1312 | } |
| 1313 | |
| 1314 | |
| 1315 | LInstruction* LChunkBuilder::DoBitOr(HBitOr* instr) { |
| 1316 | return DoBit(Token::BIT_OR, instr); |
| 1317 | } |
| 1318 | |
| 1319 | |
| 1320 | LInstruction* LChunkBuilder::DoBitXor(HBitXor* instr) { |
| 1321 | return DoBit(Token::BIT_XOR, instr); |
| 1322 | } |
| 1323 | |
| 1324 | |
| 1325 | LInstruction* LChunkBuilder::DoDiv(HDiv* instr) { |
| 1326 | if (instr->representation().IsDouble()) { |
| 1327 | return DoArithmeticD(Token::DIV, instr); |
| 1328 | } else if (instr->representation().IsInteger32()) { |
| 1329 | // The temporary operand is necessary to ensure that right is not allocated |
| 1330 | // into edx. |
| 1331 | FixedTemp(r1); |
| 1332 | LOperand* value = UseFixed(instr->left(), r0); |
| 1333 | LOperand* divisor = UseRegister(instr->right()); |
| 1334 | return AssignEnvironment(DefineFixed(new LDivI(value, divisor), r0)); |
| 1335 | } else { |
| 1336 | return DoArithmeticT(Token::DIV, instr); |
| 1337 | } |
| 1338 | } |
| 1339 | |
| 1340 | |
| 1341 | LInstruction* LChunkBuilder::DoMod(HMod* instr) { |
| 1342 | if (instr->representation().IsInteger32()) { |
| 1343 | ASSERT(instr->left()->representation().IsInteger32()); |
| 1344 | ASSERT(instr->right()->representation().IsInteger32()); |
| 1345 | // The temporary operand is necessary to ensure that right is not allocated |
| 1346 | // into edx. |
| 1347 | FixedTemp(r1); |
| 1348 | LOperand* value = UseFixed(instr->left(), r0); |
| 1349 | LOperand* divisor = UseRegister(instr->right()); |
| 1350 | LInstruction* result = DefineFixed(new LModI(value, divisor), r1); |
| 1351 | if (instr->CheckFlag(HValue::kBailoutOnMinusZero) || |
| 1352 | instr->CheckFlag(HValue::kCanBeDivByZero)) { |
| 1353 | result = AssignEnvironment(result); |
| 1354 | } |
| 1355 | return result; |
| 1356 | } else if (instr->representation().IsTagged()) { |
| 1357 | return DoArithmeticT(Token::MOD, instr); |
| 1358 | } else { |
| 1359 | ASSERT(instr->representation().IsDouble()); |
| 1360 | // We call a C function for double modulo. It can't trigger a GC. |
| 1361 | // We need to use fixed result register for the call. |
| 1362 | // TODO(fschneider): Allow any register as input registers. |
| 1363 | LOperand* left = UseFixedDouble(instr->left(), d1); |
| 1364 | LOperand* right = UseFixedDouble(instr->right(), d2); |
| 1365 | LArithmeticD* result = new LArithmeticD(Token::MOD, left, right); |
| 1366 | return MarkAsCall(DefineFixedDouble(result, d1), instr); |
| 1367 | } |
| 1368 | } |
| 1369 | |
| 1370 | |
| 1371 | LInstruction* LChunkBuilder::DoMul(HMul* instr) { |
| 1372 | if (instr->representation().IsInteger32()) { |
| 1373 | ASSERT(instr->left()->representation().IsInteger32()); |
| 1374 | ASSERT(instr->right()->representation().IsInteger32()); |
| 1375 | LOperand* left = UseRegisterAtStart(instr->LeastConstantOperand()); |
| 1376 | LOperand* right = UseOrConstant(instr->MostConstantOperand()); |
| 1377 | LOperand* temp = NULL; |
| 1378 | if (instr->CheckFlag(HValue::kBailoutOnMinusZero)) { |
| 1379 | temp = TempRegister(); |
| 1380 | } |
| 1381 | LMulI* mul = new LMulI(left, right, temp); |
| 1382 | return AssignEnvironment(DefineSameAsFirst(mul)); |
| 1383 | } else if (instr->representation().IsDouble()) { |
| 1384 | return DoArithmeticD(Token::MUL, instr); |
| 1385 | } else { |
| 1386 | return DoArithmeticT(Token::MUL, instr); |
| 1387 | } |
| 1388 | } |
| 1389 | |
| 1390 | |
| 1391 | LInstruction* LChunkBuilder::DoSub(HSub* instr) { |
| 1392 | if (instr->representation().IsInteger32()) { |
| 1393 | ASSERT(instr->left()->representation().IsInteger32()); |
| 1394 | ASSERT(instr->right()->representation().IsInteger32()); |
| 1395 | LOperand* left = UseRegisterAtStart(instr->LeastConstantOperand()); |
| 1396 | LOperand* right = UseOrConstantAtStart(instr->MostConstantOperand()); |
| 1397 | LSubI* sub = new LSubI(left, right); |
| 1398 | LInstruction* result = DefineSameAsFirst(sub); |
| 1399 | if (instr->CheckFlag(HValue::kCanOverflow)) { |
| 1400 | result = AssignEnvironment(result); |
| 1401 | } |
| 1402 | return result; |
| 1403 | } else if (instr->representation().IsDouble()) { |
| 1404 | return DoArithmeticD(Token::SUB, instr); |
| 1405 | } else { |
| 1406 | return DoArithmeticT(Token::SUB, instr); |
| 1407 | } |
| 1408 | } |
| 1409 | |
| 1410 | |
| 1411 | LInstruction* LChunkBuilder::DoAdd(HAdd* instr) { |
| 1412 | if (instr->representation().IsInteger32()) { |
| 1413 | ASSERT(instr->left()->representation().IsInteger32()); |
| 1414 | ASSERT(instr->right()->representation().IsInteger32()); |
| 1415 | LOperand* left = UseRegisterAtStart(instr->LeastConstantOperand()); |
| 1416 | LOperand* right = UseOrConstantAtStart(instr->MostConstantOperand()); |
| 1417 | LAddI* add = new LAddI(left, right); |
| 1418 | LInstruction* result = DefineSameAsFirst(add); |
| 1419 | if (instr->CheckFlag(HValue::kCanOverflow)) { |
| 1420 | result = AssignEnvironment(result); |
| 1421 | } |
| 1422 | return result; |
| 1423 | } else if (instr->representation().IsDouble()) { |
| 1424 | return DoArithmeticD(Token::ADD, instr); |
| 1425 | } else { |
| 1426 | ASSERT(instr->representation().IsTagged()); |
| 1427 | return DoArithmeticT(Token::ADD, instr); |
| 1428 | } |
| 1429 | } |
| 1430 | |
| 1431 | |
| 1432 | LInstruction* LChunkBuilder::DoPower(HPower* instr) { |
| 1433 | Abort("LPower instruction not implemented on ARM"); |
| 1434 | return NULL; |
| 1435 | } |
| 1436 | |
| 1437 | |
| 1438 | LInstruction* LChunkBuilder::DoCompare(HCompare* instr) { |
| 1439 | Token::Value op = instr->token(); |
| 1440 | if (instr->left()->representation().IsInteger32()) { |
| 1441 | ASSERT(instr->right()->representation().IsInteger32()); |
| 1442 | LOperand* left = UseRegisterAtStart(instr->left()); |
| 1443 | LOperand* right = UseOrConstantAtStart(instr->right()); |
| 1444 | return DefineAsRegister(new LCmpID(op, left, right, false)); |
| 1445 | } else if (instr->left()->representation().IsDouble()) { |
| 1446 | ASSERT(instr->right()->representation().IsDouble()); |
| 1447 | LOperand* left = UseRegisterAtStart(instr->left()); |
| 1448 | LOperand* right = UseRegisterAtStart(instr->right()); |
| 1449 | return DefineAsRegister(new LCmpID(op, left, right, true)); |
| 1450 | } else { |
| 1451 | bool reversed = (op == Token::GT || op == Token::LTE); |
| 1452 | LOperand* left = UseFixed(instr->left(), reversed ? r0 : r1); |
| 1453 | LOperand* right = UseFixed(instr->right(), reversed ? r1 : r0); |
| 1454 | LInstruction* result = new LCmpT(left, right); |
| 1455 | return MarkAsCall(DefineFixed(result, r0), instr); |
| 1456 | } |
| 1457 | } |
| 1458 | |
| 1459 | |
| 1460 | LInstruction* LChunkBuilder::DoCompareJSObjectEq( |
| 1461 | HCompareJSObjectEq* instr) { |
| 1462 | LOperand* left = UseRegisterAtStart(instr->left()); |
| 1463 | LOperand* right = UseRegisterAtStart(instr->right()); |
| 1464 | LInstruction* result = new LCmpJSObjectEq(left, right); |
| 1465 | return DefineAsRegister(result); |
| 1466 | } |
| 1467 | |
| 1468 | |
| 1469 | LInstruction* LChunkBuilder::DoIsNull(HIsNull* instr) { |
| 1470 | ASSERT(instr->value()->representation().IsTagged()); |
| 1471 | LOperand* value = UseRegisterAtStart(instr->value()); |
| 1472 | |
| 1473 | return DefineAsRegister(new LIsNull(value, |
| 1474 | instr->is_strict())); |
| 1475 | } |
| 1476 | |
| 1477 | |
| 1478 | LInstruction* LChunkBuilder::DoIsObject(HIsObject* instr) { |
| 1479 | ASSERT(instr->value()->representation().IsTagged()); |
| 1480 | LOperand* value = UseRegisterAtStart(instr->value()); |
| 1481 | |
| 1482 | return DefineAsRegister(new LIsObject(value, TempRegister())); |
| 1483 | } |
| 1484 | |
| 1485 | |
| 1486 | LInstruction* LChunkBuilder::DoIsSmi(HIsSmi* instr) { |
| 1487 | ASSERT(instr->value()->representation().IsTagged()); |
| 1488 | LOperand* value = UseAtStart(instr->value()); |
| 1489 | |
| 1490 | return DefineAsRegister(new LIsSmi(value)); |
| 1491 | } |
| 1492 | |
| 1493 | |
| 1494 | LInstruction* LChunkBuilder::DoHasInstanceType(HHasInstanceType* instr) { |
| 1495 | ASSERT(instr->value()->representation().IsTagged()); |
| 1496 | LOperand* value = UseRegisterAtStart(instr->value()); |
| 1497 | |
| 1498 | return DefineAsRegister(new LHasInstanceType(value)); |
| 1499 | } |
| 1500 | |
| 1501 | |
| 1502 | LInstruction* LChunkBuilder::DoHasCachedArrayIndex( |
| 1503 | HHasCachedArrayIndex* instr) { |
| 1504 | ASSERT(instr->value()->representation().IsTagged()); |
| 1505 | LOperand* value = UseRegister(instr->value()); |
| 1506 | |
| 1507 | return DefineAsRegister(new LHasCachedArrayIndex(value)); |
| 1508 | } |
| 1509 | |
| 1510 | |
| 1511 | LInstruction* LChunkBuilder::DoClassOfTest(HClassOfTest* instr) { |
| 1512 | ASSERT(instr->value()->representation().IsTagged()); |
| 1513 | LOperand* value = UseTempRegister(instr->value()); |
| 1514 | |
| 1515 | return DefineSameAsFirst(new LClassOfTest(value, TempRegister())); |
| 1516 | } |
| 1517 | |
| 1518 | |
Steve Block | 9fac840 | 2011-05-12 15:51:54 +0100 | [diff] [blame] | 1519 | LInstruction* LChunkBuilder::DoJSArrayLength(HJSArrayLength* instr) { |
| 1520 | LOperand* array = UseRegisterAtStart(instr->value()); |
| 1521 | return DefineAsRegister(new LJSArrayLength(array)); |
| 1522 | } |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1523 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1524 | |
Steve Block | 9fac840 | 2011-05-12 15:51:54 +0100 | [diff] [blame] | 1525 | LInstruction* LChunkBuilder::DoFixedArrayLength(HFixedArrayLength* instr) { |
| 1526 | LOperand* array = UseRegisterAtStart(instr->value()); |
| 1527 | return DefineAsRegister(new LFixedArrayLength(array)); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1528 | } |
| 1529 | |
| 1530 | |
| 1531 | LInstruction* LChunkBuilder::DoValueOf(HValueOf* instr) { |
| 1532 | LOperand* object = UseRegister(instr->value()); |
| 1533 | LInstruction* result = new LValueOf(object, TempRegister()); |
| 1534 | return AssignEnvironment(DefineSameAsFirst(result)); |
| 1535 | } |
| 1536 | |
| 1537 | |
| 1538 | LInstruction* LChunkBuilder::DoBoundsCheck(HBoundsCheck* instr) { |
| 1539 | return AssignEnvironment(new LBoundsCheck(UseRegisterAtStart(instr->index()), |
Ben Murdoch | 086aeea | 2011-05-13 15:57:08 +0100 | [diff] [blame^] | 1540 | UseRegister(instr->length()))); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1541 | } |
| 1542 | |
| 1543 | |
| 1544 | LInstruction* LChunkBuilder::DoThrow(HThrow* instr) { |
| 1545 | LOperand* value = UseFixed(instr->value(), r0); |
| 1546 | return MarkAsCall(new LThrow(value), instr); |
| 1547 | } |
| 1548 | |
| 1549 | |
| 1550 | LInstruction* LChunkBuilder::DoChange(HChange* instr) { |
| 1551 | Representation from = instr->from(); |
| 1552 | Representation to = instr->to(); |
| 1553 | if (from.IsTagged()) { |
| 1554 | if (to.IsDouble()) { |
| 1555 | LOperand* value = UseRegister(instr->value()); |
| 1556 | LInstruction* res = new LNumberUntagD(value); |
| 1557 | return AssignEnvironment(DefineAsRegister(res)); |
| 1558 | } else { |
| 1559 | ASSERT(to.IsInteger32()); |
| 1560 | LOperand* value = UseRegister(instr->value()); |
| 1561 | bool needs_check = !instr->value()->type().IsSmi(); |
| 1562 | LInstruction* res = NULL; |
| 1563 | if (needs_check) { |
| 1564 | res = DefineSameAsFirst(new LTaggedToI(value, FixedTemp(d1))); |
| 1565 | } else { |
| 1566 | res = DefineSameAsFirst(new LSmiUntag(value, needs_check)); |
| 1567 | } |
| 1568 | if (needs_check) { |
| 1569 | res = AssignEnvironment(res); |
| 1570 | } |
| 1571 | return res; |
| 1572 | } |
| 1573 | } else if (from.IsDouble()) { |
| 1574 | if (to.IsTagged()) { |
| 1575 | LOperand* value = UseRegister(instr->value()); |
| 1576 | LOperand* temp1 = TempRegister(); |
| 1577 | LOperand* temp2 = TempRegister(); |
| 1578 | |
| 1579 | // Make sure that the temp and result_temp registers are |
| 1580 | // different. |
| 1581 | LUnallocated* result_temp = TempRegister(); |
| 1582 | LInstruction* result = new LNumberTagD(value, temp1, temp2); |
| 1583 | Define(result, result_temp); |
| 1584 | return AssignPointerMap(result); |
| 1585 | } else { |
| 1586 | ASSERT(to.IsInteger32()); |
| 1587 | LOperand* value = UseRegister(instr->value()); |
| 1588 | LInstruction* res = new LDoubleToI(value); |
| 1589 | return AssignEnvironment(DefineAsRegister(res)); |
| 1590 | } |
| 1591 | } else if (from.IsInteger32()) { |
| 1592 | if (to.IsTagged()) { |
| 1593 | HValue* val = instr->value(); |
| 1594 | LOperand* value = UseRegister(val); |
| 1595 | if (val->HasRange() && val->range()->IsInSmiRange()) { |
| 1596 | return DefineSameAsFirst(new LSmiTag(value)); |
| 1597 | } else { |
| 1598 | LInstruction* result = new LNumberTagI(value); |
| 1599 | return AssignEnvironment(AssignPointerMap(DefineSameAsFirst(result))); |
| 1600 | } |
| 1601 | } else { |
| 1602 | ASSERT(to.IsDouble()); |
| 1603 | LOperand* value = Use(instr->value()); |
| 1604 | return DefineAsRegister(new LInteger32ToDouble(value)); |
| 1605 | } |
| 1606 | } |
| 1607 | UNREACHABLE(); |
| 1608 | return NULL; |
| 1609 | } |
| 1610 | |
| 1611 | |
| 1612 | LInstruction* LChunkBuilder::DoCheckNonSmi(HCheckNonSmi* instr) { |
| 1613 | LOperand* value = UseRegisterAtStart(instr->value()); |
| 1614 | return AssignEnvironment(new LCheckSmi(value, eq)); |
| 1615 | } |
| 1616 | |
| 1617 | |
| 1618 | LInstruction* LChunkBuilder::DoCheckInstanceType(HCheckInstanceType* instr) { |
| 1619 | LOperand* value = UseRegisterAtStart(instr->value()); |
Ben Murdoch | 086aeea | 2011-05-13 15:57:08 +0100 | [diff] [blame^] | 1620 | LInstruction* result = new LCheckInstanceType(value); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1621 | return AssignEnvironment(result); |
| 1622 | } |
| 1623 | |
| 1624 | |
| 1625 | LInstruction* LChunkBuilder::DoCheckPrototypeMaps(HCheckPrototypeMaps* instr) { |
Steve Block | 9fac840 | 2011-05-12 15:51:54 +0100 | [diff] [blame] | 1626 | LOperand* temp1 = TempRegister(); |
| 1627 | LOperand* temp2 = TempRegister(); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1628 | LInstruction* result = |
Steve Block | 9fac840 | 2011-05-12 15:51:54 +0100 | [diff] [blame] | 1629 | new LCheckPrototypeMaps(temp1, |
| 1630 | temp2, |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1631 | instr->holder(), |
| 1632 | instr->receiver_map()); |
| 1633 | return AssignEnvironment(result); |
| 1634 | } |
| 1635 | |
| 1636 | |
| 1637 | LInstruction* LChunkBuilder::DoCheckSmi(HCheckSmi* instr) { |
| 1638 | LOperand* value = UseRegisterAtStart(instr->value()); |
| 1639 | return AssignEnvironment(new LCheckSmi(value, ne)); |
| 1640 | } |
| 1641 | |
| 1642 | |
| 1643 | LInstruction* LChunkBuilder::DoCheckFunction(HCheckFunction* instr) { |
| 1644 | LOperand* value = UseRegisterAtStart(instr->value()); |
| 1645 | return AssignEnvironment(new LCheckFunction(value)); |
| 1646 | } |
| 1647 | |
| 1648 | |
| 1649 | LInstruction* LChunkBuilder::DoCheckMap(HCheckMap* instr) { |
| 1650 | LOperand* value = UseRegisterAtStart(instr->value()); |
| 1651 | LInstruction* result = new LCheckMap(value); |
| 1652 | return AssignEnvironment(result); |
| 1653 | } |
| 1654 | |
| 1655 | |
| 1656 | LInstruction* LChunkBuilder::DoReturn(HReturn* instr) { |
| 1657 | return new LReturn(UseFixed(instr->value(), r0)); |
| 1658 | } |
| 1659 | |
| 1660 | |
| 1661 | LInstruction* LChunkBuilder::DoConstant(HConstant* instr) { |
| 1662 | Representation r = instr->representation(); |
| 1663 | if (r.IsInteger32()) { |
| 1664 | int32_t value = instr->Integer32Value(); |
| 1665 | return DefineAsRegister(new LConstantI(value)); |
| 1666 | } else if (r.IsDouble()) { |
| 1667 | double value = instr->DoubleValue(); |
| 1668 | return DefineAsRegister(new LConstantD(value)); |
| 1669 | } else if (r.IsTagged()) { |
| 1670 | return DefineAsRegister(new LConstantT(instr->handle())); |
| 1671 | } else { |
| 1672 | Abort("unsupported constant of type double"); |
| 1673 | return NULL; |
| 1674 | } |
| 1675 | } |
| 1676 | |
| 1677 | |
| 1678 | LInstruction* LChunkBuilder::DoLoadGlobal(HLoadGlobal* instr) { |
| 1679 | LInstruction* result = new LLoadGlobal(); |
| 1680 | return instr->check_hole_value() |
| 1681 | ? AssignEnvironment(DefineAsRegister(result)) |
| 1682 | : DefineAsRegister(result); |
| 1683 | } |
| 1684 | |
| 1685 | |
| 1686 | LInstruction* LChunkBuilder::DoStoreGlobal(HStoreGlobal* instr) { |
| 1687 | return new LStoreGlobal(UseRegisterAtStart(instr->value())); |
| 1688 | } |
| 1689 | |
| 1690 | |
| 1691 | LInstruction* LChunkBuilder::DoLoadNamedField(HLoadNamedField* instr) { |
| 1692 | return DefineAsRegister( |
| 1693 | new LLoadNamedField(UseRegisterAtStart(instr->object()))); |
| 1694 | } |
| 1695 | |
| 1696 | |
| 1697 | LInstruction* LChunkBuilder::DoLoadNamedGeneric(HLoadNamedGeneric* instr) { |
| 1698 | LOperand* object = UseFixed(instr->object(), r0); |
| 1699 | LInstruction* result = DefineFixed(new LLoadNamedGeneric(object), r0); |
| 1700 | return MarkAsCall(result, instr); |
| 1701 | } |
| 1702 | |
| 1703 | |
Steve Block | 9fac840 | 2011-05-12 15:51:54 +0100 | [diff] [blame] | 1704 | LInstruction* LChunkBuilder::DoLoadFunctionPrototype( |
| 1705 | HLoadFunctionPrototype* instr) { |
| 1706 | return AssignEnvironment(DefineAsRegister( |
| 1707 | new LLoadFunctionPrototype(UseRegister(instr->function())))); |
| 1708 | } |
| 1709 | |
| 1710 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1711 | LInstruction* LChunkBuilder::DoLoadElements(HLoadElements* instr) { |
| 1712 | LOperand* input = UseRegisterAtStart(instr->value()); |
| 1713 | return DefineSameAsFirst(new LLoadElements(input)); |
| 1714 | } |
| 1715 | |
| 1716 | |
| 1717 | LInstruction* LChunkBuilder::DoLoadKeyedFastElement( |
| 1718 | HLoadKeyedFastElement* instr) { |
| 1719 | Representation r = instr->representation(); |
| 1720 | LOperand* obj = UseRegisterAtStart(instr->object()); |
| 1721 | ASSERT(instr->key()->representation().IsInteger32()); |
| 1722 | LOperand* key = UseRegisterAtStart(instr->key()); |
| 1723 | LOperand* load_result = NULL; |
| 1724 | // Double needs an extra temp, because the result is converted from heap |
| 1725 | // number to a double register. |
| 1726 | if (r.IsDouble()) load_result = TempRegister(); |
| 1727 | LInstruction* result = new LLoadKeyedFastElement(obj, |
| 1728 | key, |
| 1729 | load_result); |
| 1730 | if (r.IsDouble()) { |
| 1731 | result = DefineAsRegister(result); |
| 1732 | } else { |
| 1733 | result = DefineSameAsFirst(result); |
| 1734 | } |
| 1735 | return AssignEnvironment(result); |
| 1736 | } |
| 1737 | |
| 1738 | |
| 1739 | LInstruction* LChunkBuilder::DoLoadKeyedGeneric(HLoadKeyedGeneric* instr) { |
| 1740 | LOperand* object = UseFixed(instr->object(), r1); |
| 1741 | LOperand* key = UseFixed(instr->key(), r0); |
| 1742 | |
| 1743 | LInstruction* result = |
| 1744 | DefineFixed(new LLoadKeyedGeneric(object, key), r0); |
| 1745 | return MarkAsCall(result, instr); |
| 1746 | } |
| 1747 | |
| 1748 | |
| 1749 | LInstruction* LChunkBuilder::DoStoreKeyedFastElement( |
| 1750 | HStoreKeyedFastElement* instr) { |
| 1751 | bool needs_write_barrier = instr->NeedsWriteBarrier(); |
| 1752 | ASSERT(instr->value()->representation().IsTagged()); |
| 1753 | ASSERT(instr->object()->representation().IsTagged()); |
| 1754 | ASSERT(instr->key()->representation().IsInteger32()); |
| 1755 | |
| 1756 | LOperand* obj = UseTempRegister(instr->object()); |
| 1757 | LOperand* val = needs_write_barrier |
| 1758 | ? UseTempRegister(instr->value()) |
| 1759 | : UseRegisterAtStart(instr->value()); |
| 1760 | LOperand* key = needs_write_barrier |
| 1761 | ? UseTempRegister(instr->key()) |
| 1762 | : UseRegisterOrConstantAtStart(instr->key()); |
| 1763 | |
| 1764 | return AssignEnvironment(new LStoreKeyedFastElement(obj, key, val)); |
| 1765 | } |
| 1766 | |
| 1767 | |
| 1768 | LInstruction* LChunkBuilder::DoStoreKeyedGeneric(HStoreKeyedGeneric* instr) { |
| 1769 | LOperand* obj = UseFixed(instr->object(), r2); |
| 1770 | LOperand* key = UseFixed(instr->key(), r1); |
| 1771 | LOperand* val = UseFixed(instr->value(), r0); |
| 1772 | |
| 1773 | ASSERT(instr->object()->representation().IsTagged()); |
| 1774 | ASSERT(instr->key()->representation().IsTagged()); |
| 1775 | ASSERT(instr->value()->representation().IsTagged()); |
| 1776 | |
| 1777 | return MarkAsCall(new LStoreKeyedGeneric(obj, key, val), instr); |
| 1778 | } |
| 1779 | |
| 1780 | |
| 1781 | LInstruction* LChunkBuilder::DoStoreNamedField(HStoreNamedField* instr) { |
Ben Murdoch | 086aeea | 2011-05-13 15:57:08 +0100 | [diff] [blame^] | 1782 | bool needs_write_barrier = instr->NeedsWriteBarrier(); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1783 | |
| 1784 | LOperand* obj = needs_write_barrier |
| 1785 | ? UseTempRegister(instr->object()) |
| 1786 | : UseRegisterAtStart(instr->object()); |
| 1787 | |
| 1788 | LOperand* val = needs_write_barrier |
| 1789 | ? UseTempRegister(instr->value()) |
| 1790 | : UseRegister(instr->value()); |
| 1791 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1792 | return new LStoreNamedField(obj, |
| 1793 | instr->name(), |
| 1794 | val, |
| 1795 | instr->is_in_object(), |
| 1796 | instr->offset(), |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1797 | needs_write_barrier, |
| 1798 | instr->transition()); |
| 1799 | } |
| 1800 | |
| 1801 | |
| 1802 | LInstruction* LChunkBuilder::DoStoreNamedGeneric(HStoreNamedGeneric* instr) { |
| 1803 | LOperand* obj = UseFixed(instr->object(), r1); |
| 1804 | LOperand* val = UseFixed(instr->value(), r0); |
| 1805 | |
| 1806 | LInstruction* result = new LStoreNamedGeneric(obj, instr->name(), val); |
| 1807 | return MarkAsCall(result, instr); |
| 1808 | } |
| 1809 | |
| 1810 | |
| 1811 | LInstruction* LChunkBuilder::DoArrayLiteral(HArrayLiteral* instr) { |
| 1812 | return MarkAsCall(DefineFixed(new LArrayLiteral, r0), instr); |
| 1813 | } |
| 1814 | |
| 1815 | |
| 1816 | LInstruction* LChunkBuilder::DoObjectLiteral(HObjectLiteral* instr) { |
| 1817 | return MarkAsCall(DefineFixed(new LObjectLiteral, r0), instr); |
| 1818 | } |
| 1819 | |
| 1820 | |
| 1821 | LInstruction* LChunkBuilder::DoRegExpLiteral(HRegExpLiteral* instr) { |
| 1822 | return MarkAsCall(DefineFixed(new LRegExpLiteral, r0), instr); |
| 1823 | } |
| 1824 | |
| 1825 | |
| 1826 | LInstruction* LChunkBuilder::DoFunctionLiteral(HFunctionLiteral* instr) { |
| 1827 | return MarkAsCall(DefineFixed(new LFunctionLiteral, r0), instr); |
| 1828 | } |
| 1829 | |
| 1830 | |
| 1831 | LInstruction* LChunkBuilder::DoDeleteProperty(HDeleteProperty* instr) { |
| 1832 | LInstruction* result = new LDeleteProperty(Use(instr->object()), |
| 1833 | UseOrConstant(instr->key())); |
| 1834 | return MarkAsCall(DefineFixed(result, r0), instr); |
| 1835 | } |
| 1836 | |
| 1837 | |
| 1838 | LInstruction* LChunkBuilder::DoOsrEntry(HOsrEntry* instr) { |
| 1839 | allocator_->MarkAsOsrEntry(); |
| 1840 | current_block_->last_environment()->set_ast_id(instr->ast_id()); |
| 1841 | return AssignEnvironment(new LOsrEntry); |
| 1842 | } |
| 1843 | |
| 1844 | |
| 1845 | LInstruction* LChunkBuilder::DoParameter(HParameter* instr) { |
| 1846 | int spill_index = chunk()->GetParameterStackSlot(instr->index()); |
| 1847 | return DefineAsSpilled(new LParameter, spill_index); |
| 1848 | } |
| 1849 | |
| 1850 | |
| 1851 | LInstruction* LChunkBuilder::DoUnknownOSRValue(HUnknownOSRValue* instr) { |
| 1852 | int spill_index = chunk()->GetNextSpillIndex(false); // Not double-width. |
| 1853 | return DefineAsSpilled(new LUnknownOSRValue, spill_index); |
| 1854 | } |
| 1855 | |
| 1856 | |
| 1857 | LInstruction* LChunkBuilder::DoCallStub(HCallStub* instr) { |
| 1858 | argument_count_ -= instr->argument_count(); |
| 1859 | return MarkAsCall(DefineFixed(new LCallStub, r0), instr); |
| 1860 | } |
| 1861 | |
| 1862 | |
| 1863 | LInstruction* LChunkBuilder::DoArgumentsObject(HArgumentsObject* instr) { |
| 1864 | // There are no real uses of the arguments object (we bail out in all other |
| 1865 | // cases). |
| 1866 | return NULL; |
| 1867 | } |
| 1868 | |
| 1869 | |
| 1870 | LInstruction* LChunkBuilder::DoAccessArgumentsAt(HAccessArgumentsAt* instr) { |
| 1871 | LOperand* arguments = UseRegister(instr->arguments()); |
| 1872 | LOperand* length = UseTempRegister(instr->length()); |
Ben Murdoch | 086aeea | 2011-05-13 15:57:08 +0100 | [diff] [blame^] | 1873 | LOperand* index = UseRegister(instr->index()); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1874 | LInstruction* result = new LAccessArgumentsAt(arguments, length, index); |
| 1875 | return DefineAsRegister(AssignEnvironment(result)); |
| 1876 | } |
| 1877 | |
| 1878 | |
| 1879 | LInstruction* LChunkBuilder::DoTypeof(HTypeof* instr) { |
Ben Murdoch | 086aeea | 2011-05-13 15:57:08 +0100 | [diff] [blame^] | 1880 | LInstruction* result = new LTypeof(UseRegisterAtStart(instr->value())); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1881 | return MarkAsCall(DefineFixed(result, r0), instr); |
| 1882 | } |
| 1883 | |
| 1884 | |
| 1885 | LInstruction* LChunkBuilder::DoTypeofIs(HTypeofIs* instr) { |
| 1886 | return DefineSameAsFirst(new LTypeofIs(UseRegister(instr->value()))); |
| 1887 | } |
| 1888 | |
| 1889 | LInstruction* LChunkBuilder::DoSimulate(HSimulate* instr) { |
| 1890 | HEnvironment* env = current_block_->last_environment(); |
| 1891 | ASSERT(env != NULL); |
| 1892 | |
| 1893 | env->set_ast_id(instr->ast_id()); |
| 1894 | |
| 1895 | env->Drop(instr->pop_count()); |
| 1896 | for (int i = 0; i < instr->values()->length(); ++i) { |
| 1897 | HValue* value = instr->values()->at(i); |
| 1898 | if (instr->HasAssignedIndexAt(i)) { |
| 1899 | env->Bind(instr->GetAssignedIndexAt(i), value); |
| 1900 | } else { |
| 1901 | env->Push(value); |
| 1902 | } |
| 1903 | } |
| 1904 | |
Steve Block | 9fac840 | 2011-05-12 15:51:54 +0100 | [diff] [blame] | 1905 | ASSERT(env->length() == instr->environment_length()); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1906 | |
| 1907 | // If there is an instruction pending deoptimization environment create a |
| 1908 | // lazy bailout instruction to capture the environment. |
| 1909 | if (pending_deoptimization_ast_id_ == instr->ast_id()) { |
| 1910 | LInstruction* result = new LLazyBailout; |
| 1911 | result = AssignEnvironment(result); |
| 1912 | instructions_pending_deoptimization_environment_-> |
| 1913 | set_deoptimization_environment(result->environment()); |
| 1914 | ClearInstructionPendingDeoptimizationEnvironment(); |
| 1915 | return result; |
| 1916 | } |
| 1917 | |
| 1918 | return NULL; |
| 1919 | } |
| 1920 | |
| 1921 | |
| 1922 | LInstruction* LChunkBuilder::DoStackCheck(HStackCheck* instr) { |
| 1923 | return MarkAsCall(new LStackCheck, instr); |
| 1924 | } |
| 1925 | |
| 1926 | |
| 1927 | LInstruction* LChunkBuilder::DoEnterInlined(HEnterInlined* instr) { |
| 1928 | HEnvironment* outer = current_block_->last_environment(); |
| 1929 | HConstant* undefined = graph()->GetConstantUndefined(); |
| 1930 | HEnvironment* inner = outer->CopyForInlining(instr->closure(), |
| 1931 | instr->function(), |
| 1932 | false, |
| 1933 | undefined); |
| 1934 | current_block_->UpdateEnvironment(inner); |
| 1935 | chunk_->AddInlinedClosure(instr->closure()); |
| 1936 | return NULL; |
| 1937 | } |
| 1938 | |
| 1939 | |
| 1940 | LInstruction* LChunkBuilder::DoLeaveInlined(HLeaveInlined* instr) { |
| 1941 | HEnvironment* outer = current_block_->last_environment()->outer(); |
| 1942 | current_block_->UpdateEnvironment(outer); |
| 1943 | return NULL; |
| 1944 | } |
| 1945 | |
| 1946 | |
| 1947 | void LPointerMap::RecordPointer(LOperand* op) { |
| 1948 | // Do not record arguments as pointers. |
| 1949 | if (op->IsStackSlot() && op->index() < 0) return; |
| 1950 | ASSERT(!op->IsDoubleRegister() && !op->IsDoubleStackSlot()); |
| 1951 | pointer_operands_.Add(op); |
| 1952 | } |
| 1953 | |
| 1954 | |
| 1955 | void LPointerMap::PrintTo(StringStream* stream) const { |
| 1956 | stream->Add("{"); |
| 1957 | for (int i = 0; i < pointer_operands_.length(); ++i) { |
| 1958 | if (i != 0) stream->Add(";"); |
| 1959 | pointer_operands_[i]->PrintTo(stream); |
| 1960 | } |
| 1961 | stream->Add("} @%d", position()); |
| 1962 | } |
| 1963 | |
| 1964 | } } // namespace v8::internal |