| OLD | NEW |
| 1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "src/compiler/instruction.h" | 5 #include "src/compiler/instruction.h" |
| 6 | 6 |
| 7 #include "src/compiler/common-operator.h" | 7 #include "src/compiler/common-operator.h" |
| 8 #include "src/compiler/generic-node-inl.h" |
| 8 | 9 |
| 9 namespace v8 { | 10 namespace v8 { |
| 10 namespace internal { | 11 namespace internal { |
| 11 namespace compiler { | 12 namespace compiler { |
| 12 | 13 |
| 13 OStream& operator<<(OStream& os, const InstructionOperand& op) { | 14 OStream& operator<<(OStream& os, const InstructionOperand& op) { |
| 14 switch (op.kind()) { | 15 switch (op.kind()) { |
| 15 case InstructionOperand::INVALID: | 16 case InstructionOperand::INVALID: |
| 16 return os << "(0)"; | 17 return os << "(0)"; |
| 17 case InstructionOperand::UNALLOCATED: { | 18 case InstructionOperand::UNALLOCATED: { |
| (...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 313 return os; | 314 return os; |
| 314 } | 315 } |
| 315 | 316 |
| 316 | 317 |
| 317 Label* InstructionSequence::GetLabel(BasicBlock* block) { | 318 Label* InstructionSequence::GetLabel(BasicBlock* block) { |
| 318 return GetBlockStart(block)->label(); | 319 return GetBlockStart(block)->label(); |
| 319 } | 320 } |
| 320 | 321 |
| 321 | 322 |
| 322 BlockStartInstruction* InstructionSequence::GetBlockStart(BasicBlock* block) { | 323 BlockStartInstruction* InstructionSequence::GetBlockStart(BasicBlock* block) { |
| 323 return BlockStartInstruction::cast(InstructionAt(block->code_start_)); | 324 return BlockStartInstruction::cast(InstructionAt(block->code_start())); |
| 324 } | 325 } |
| 325 | 326 |
| 326 | 327 |
| 327 void InstructionSequence::StartBlock(BasicBlock* block) { | 328 void InstructionSequence::StartBlock(BasicBlock* block) { |
| 328 block->code_start_ = static_cast<int>(instructions_.size()); | 329 block->set_code_start(static_cast<int>(instructions_.size())); |
| 329 BlockStartInstruction* block_start = | 330 BlockStartInstruction* block_start = |
| 330 BlockStartInstruction::New(zone(), block); | 331 BlockStartInstruction::New(zone(), block); |
| 331 AddInstruction(block_start, block); | 332 AddInstruction(block_start, block); |
| 332 } | 333 } |
| 333 | 334 |
| 334 | 335 |
| 335 void InstructionSequence::EndBlock(BasicBlock* block) { | 336 void InstructionSequence::EndBlock(BasicBlock* block) { |
| 336 int end = static_cast<int>(instructions_.size()); | 337 int end = static_cast<int>(instructions_.size()); |
| 337 DCHECK(block->code_start_ >= 0 && block->code_start_ < end); | 338 DCHECK(block->code_start() >= 0 && block->code_start() < end); |
| 338 block->code_end_ = end; | 339 block->set_code_end(end); |
| 339 } | 340 } |
| 340 | 341 |
| 341 | 342 |
| 342 int InstructionSequence::AddInstruction(Instruction* instr, BasicBlock* block) { | 343 int InstructionSequence::AddInstruction(Instruction* instr, BasicBlock* block) { |
| 343 // TODO(titzer): the order of these gaps is a holdover from Lithium. | 344 // TODO(titzer): the order of these gaps is a holdover from Lithium. |
| 344 GapInstruction* gap = GapInstruction::New(zone()); | 345 GapInstruction* gap = GapInstruction::New(zone()); |
| 345 if (instr->IsControl()) instructions_.push_back(gap); | 346 if (instr->IsControl()) instructions_.push_back(gap); |
| 346 int index = static_cast<int>(instructions_.size()); | 347 int index = static_cast<int>(instructions_.size()); |
| 347 instructions_.push_back(instr); | 348 instructions_.push_back(instr); |
| 348 if (!instr->IsControl()) instructions_.push_back(gap); | 349 if (!instr->IsControl()) instructions_.push_back(gap); |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 420 os << "IMM#" << i << ": " << constant << "\n"; | 421 os << "IMM#" << i << ": " << constant << "\n"; |
| 421 } | 422 } |
| 422 int i = 0; | 423 int i = 0; |
| 423 for (ConstantMap::const_iterator it = code.constants_.begin(); | 424 for (ConstantMap::const_iterator it = code.constants_.begin(); |
| 424 it != code.constants_.end(); ++i, ++it) { | 425 it != code.constants_.end(); ++i, ++it) { |
| 425 os << "CST#" << i << ": v" << it->first << " = " << it->second << "\n"; | 426 os << "CST#" << i << ": v" << it->first << " = " << it->second << "\n"; |
| 426 } | 427 } |
| 427 for (int i = 0; i < code.BasicBlockCount(); i++) { | 428 for (int i = 0; i < code.BasicBlockCount(); i++) { |
| 428 BasicBlock* block = code.BlockAt(i); | 429 BasicBlock* block = code.BlockAt(i); |
| 429 | 430 |
| 430 int bid = block->id(); | 431 os << "RPO#" << block->rpo_number() << ": B" << block->id(); |
| 431 os << "RPO#" << block->rpo_number_ << ": B" << bid; | 432 CHECK(block->rpo_number() == i); |
| 432 CHECK(block->rpo_number_ == i); | |
| 433 if (block->IsLoopHeader()) { | 433 if (block->IsLoopHeader()) { |
| 434 os << " loop blocks: [" << block->rpo_number_ << ", " << block->loop_end_ | 434 os << " loop blocks: [" << block->rpo_number() << ", " |
| 435 << ")"; | 435 << block->loop_end() << ")"; |
| 436 } | 436 } |
| 437 os << " instructions: [" << block->code_start_ << ", " << block->code_end_ | 437 os << " instructions: [" << block->code_start() << ", " |
| 438 << ")\n predecessors:"; | 438 << block->code_end() << ")\n predecessors:"; |
| 439 | 439 |
| 440 BasicBlock::Predecessors predecessors = block->predecessors(); | 440 for (BasicBlock::Predecessors::iterator iter = block->predecessors_begin(); |
| 441 for (BasicBlock::Predecessors::iterator iter = predecessors.begin(); | 441 iter != block->predecessors_end(); ++iter) { |
| 442 iter != predecessors.end(); ++iter) { | |
| 443 os << " B" << (*iter)->id(); | 442 os << " B" << (*iter)->id(); |
| 444 } | 443 } |
| 445 os << "\n"; | 444 os << "\n"; |
| 446 | 445 |
| 447 for (BasicBlock::const_iterator j = block->begin(); j != block->end(); | 446 for (BasicBlock::const_iterator j = block->begin(); j != block->end(); |
| 448 ++j) { | 447 ++j) { |
| 449 Node* phi = *j; | 448 Node* phi = *j; |
| 450 if (phi->opcode() != IrOpcode::kPhi) continue; | 449 if (phi->opcode() != IrOpcode::kPhi) continue; |
| 451 os << " phi: v" << phi->id() << " ="; | 450 os << " phi: v" << phi->id() << " ="; |
| 452 Node::Inputs inputs = phi->inputs(); | 451 Node::Inputs inputs = phi->inputs(); |
| 453 for (Node::Inputs::iterator iter(inputs.begin()); iter != inputs.end(); | 452 for (Node::Inputs::iterator iter(inputs.begin()); iter != inputs.end(); |
| 454 ++iter) { | 453 ++iter) { |
| 455 os << " v" << (*iter)->id(); | 454 os << " v" << (*iter)->id(); |
| 456 } | 455 } |
| 457 os << "\n"; | 456 os << "\n"; |
| 458 } | 457 } |
| 459 | 458 |
| 460 ScopedVector<char> buf(32); | 459 ScopedVector<char> buf(32); |
| 461 for (int j = block->first_instruction_index(); | 460 for (int j = block->first_instruction_index(); |
| 462 j <= block->last_instruction_index(); j++) { | 461 j <= block->last_instruction_index(); j++) { |
| 463 // TODO(svenpanne) Add some basic formatting to our streams. | 462 // TODO(svenpanne) Add some basic formatting to our streams. |
| 464 SNPrintF(buf, "%5d", j); | 463 SNPrintF(buf, "%5d", j); |
| 465 os << " " << buf.start() << ": " << *code.InstructionAt(j); | 464 os << " " << buf.start() << ": " << *code.InstructionAt(j); |
| 466 } | 465 } |
| 467 | 466 |
| 468 os << " " << block->control_; | 467 os << " " << block->control(); |
| 469 | 468 |
| 470 if (block->control_input_ != NULL) { | 469 if (block->control_input() != NULL) { |
| 471 os << " v" << block->control_input_->id(); | 470 os << " v" << block->control_input()->id(); |
| 472 } | 471 } |
| 473 | 472 |
| 474 BasicBlock::Successors successors = block->successors(); | 473 for (BasicBlock::Successors::iterator iter = block->successors_begin(); |
| 475 for (BasicBlock::Successors::iterator iter = successors.begin(); | 474 iter != block->successors_end(); ++iter) { |
| 476 iter != successors.end(); ++iter) { | |
| 477 os << " B" << (*iter)->id(); | 475 os << " B" << (*iter)->id(); |
| 478 } | 476 } |
| 479 os << "\n"; | 477 os << "\n"; |
| 480 } | 478 } |
| 481 return os; | 479 return os; |
| 482 } | 480 } |
| 483 | 481 |
| 484 } // namespace compiler | 482 } // namespace compiler |
| 485 } // namespace internal | 483 } // namespace internal |
| 486 } // namespace v8 | 484 } // namespace v8 |
| OLD | NEW |