Commit 4e191e78 authored by dcarney@chromium.org's avatar dcarney@chromium.org

[turbofan] remove schedule from InstructionSequence

R=bmeurer@chromium.org

BUG=

Review URL: https://codereview.chromium.org/669613002

git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@24726 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 394af55a
...@@ -29,7 +29,6 @@ class CodeGenerator FINAL : public GapResolver::Assembler { ...@@ -29,7 +29,6 @@ class CodeGenerator FINAL : public GapResolver::Assembler {
Frame* frame() const { return code()->frame(); } Frame* frame() const { return code()->frame(); }
Isolate* isolate() const { return zone()->isolate(); } Isolate* isolate() const { return zone()->isolate(); }
Linkage* linkage() const { return code()->linkage(); } Linkage* linkage() const { return code()->linkage(); }
Schedule* schedule() const { return code()->schedule(); }
private: private:
MacroAssembler* masm() { return &masm_; } MacroAssembler* masm() { return &masm_; }
......
...@@ -593,9 +593,11 @@ void GraphC1Visualizer::PrintSchedule(const char* phase, ...@@ -593,9 +593,11 @@ void GraphC1Visualizer::PrintSchedule(const char* phase,
PrintIntProperty("loop_depth", current->loop_depth()); PrintIntProperty("loop_depth", current->loop_depth());
if (instructions->code_start(current) >= 0) { const InstructionBlock* instruction_block =
int first_index = instructions->first_instruction_index(current); instructions->InstructionBlockAt(current->GetRpoNumber());
int last_index = instructions->last_instruction_index(current); if (instruction_block->code_start() >= 0) {
int first_index = instruction_block->first_instruction_index();
int last_index = instruction_block->last_instruction_index();
PrintIntProperty("first_lir_id", LifetimePosition::FromInstructionIndex( PrintIntProperty("first_lir_id", LifetimePosition::FromInstructionIndex(
first_index).Value()); first_index).Value());
PrintIntProperty("last_lir_id", LifetimePosition::FromInstructionIndex( PrintIntProperty("last_lir_id", LifetimePosition::FromInstructionIndex(
...@@ -674,8 +676,8 @@ void GraphC1Visualizer::PrintSchedule(const char* phase, ...@@ -674,8 +676,8 @@ void GraphC1Visualizer::PrintSchedule(const char* phase,
if (instructions != NULL) { if (instructions != NULL) {
Tag LIR_tag(this, "LIR"); Tag LIR_tag(this, "LIR");
for (int j = instructions->first_instruction_index(current); for (int j = instruction_block->first_instruction_index();
j <= instructions->last_instruction_index(current); j++) { j <= instruction_block->last_instruction_index(); j++) {
PrintIndent(); PrintIndent();
os_ << j << " " << *instructions->InstructionAt(j) << " <|@\n"; os_ << j << " " << *instructions->InstructionAt(j) << " <|@\n";
} }
......
...@@ -14,12 +14,14 @@ namespace internal { ...@@ -14,12 +14,14 @@ namespace internal {
namespace compiler { namespace compiler {
InstructionSelector::InstructionSelector(InstructionSequence* sequence, InstructionSelector::InstructionSelector(InstructionSequence* sequence,
Schedule* schedule,
SourcePositionTable* source_positions, SourcePositionTable* source_positions,
Features features) Features features)
: zone_(sequence->isolate()), : zone_(sequence->isolate()),
sequence_(sequence), sequence_(sequence),
source_positions_(source_positions), source_positions_(source_positions),
features_(features), features_(features),
schedule_(schedule),
current_block_(NULL), current_block_(NULL),
instructions_(zone()), instructions_(zone()),
defined_(sequence->node_count(), false, zone()), defined_(sequence->node_count(), false, zone()),
...@@ -55,8 +57,10 @@ void InstructionSelector::SelectInstructions() { ...@@ -55,8 +57,10 @@ void InstructionSelector::SelectInstructions() {
// Schedule the selected instructions. // Schedule the selected instructions.
for (BasicBlockVectorIter i = blocks->begin(); i != blocks->end(); ++i) { for (BasicBlockVectorIter i = blocks->begin(); i != blocks->end(); ++i) {
BasicBlock* block = *i; BasicBlock* block = *i;
size_t end = sequence()->code_end(block); InstructionBlock* instruction_block =
size_t start = sequence()->code_start(block); sequence()->InstructionBlockAt(block->GetRpoNumber());
size_t end = instruction_block->code_end();
size_t start = instruction_block->code_start();
sequence()->StartBlock(block); sequence()->StartBlock(block);
while (start-- > end) { while (start-- > end) {
sequence()->AddInstruction(instructions_[start]); sequence()->AddInstruction(instructions_[start]);
...@@ -383,8 +387,10 @@ void InstructionSelector::VisitBlock(BasicBlock* block) { ...@@ -383,8 +387,10 @@ void InstructionSelector::VisitBlock(BasicBlock* block) {
} }
// We're done with the block. // We're done with the block.
sequence()->set_code_start(block, static_cast<int>(instructions_.size())); InstructionBlock* instruction_block =
sequence()->set_code_end(block, current_block_end); sequence()->InstructionBlockAt(block->GetRpoNumber());
instruction_block->set_code_start(static_cast<int>(instructions_.size()));
instruction_block->set_code_end(current_block_end);
current_block_ = NULL; current_block_ = NULL;
} }
...@@ -856,14 +862,12 @@ void InstructionSelector::VisitPhi(Node* node) { ...@@ -856,14 +862,12 @@ void InstructionSelector::VisitPhi(Node* node) {
PhiInstruction* phi = new (instruction_zone()) PhiInstruction* phi = new (instruction_zone())
PhiInstruction(instruction_zone(), sequence()->GetVirtualRegister(node)); PhiInstruction(instruction_zone(), sequence()->GetVirtualRegister(node));
sequence()->InstructionBlockAt(current_block_->GetRpoNumber())->AddPhi(phi); sequence()->InstructionBlockAt(current_block_->GetRpoNumber())->AddPhi(phi);
Node::Inputs inputs = node->inputs(); const int input_count = node->op()->InputCount();
size_t j = 0; phi->operands().reserve(static_cast<size_t>(input_count));
for (Node::Inputs::iterator iter(inputs.begin()); iter != inputs.end(); for (int i = 0; i < input_count; ++i) {
++iter, ++j) { Node* const input = node->InputAt(i);
MarkAsUsed(*iter); MarkAsUsed(input);
// TODO(mstarzinger): Use a ValueInputIterator instead. phi->operands().push_back(sequence()->GetVirtualRegister(input));
if (j >= current_block_->PredecessorCount()) continue;
phi->operands().push_back(sequence()->GetVirtualRegister(*iter));
} }
} }
......
...@@ -25,7 +25,7 @@ class InstructionSelector FINAL { ...@@ -25,7 +25,7 @@ class InstructionSelector FINAL {
// Forward declarations. // Forward declarations.
class Features; class Features;
InstructionSelector(InstructionSequence* sequence, InstructionSelector(InstructionSequence* sequence, Schedule* schedule,
SourcePositionTable* source_positions, SourcePositionTable* source_positions,
Features features = SupportedFeatures()); Features features = SupportedFeatures());
...@@ -184,7 +184,7 @@ class InstructionSelector FINAL { ...@@ -184,7 +184,7 @@ class InstructionSelector FINAL {
// =========================================================================== // ===========================================================================
Linkage* linkage() const { return sequence()->linkage(); } Linkage* linkage() const { return sequence()->linkage(); }
Schedule* schedule() const { return sequence()->schedule(); } Schedule* schedule() const { return schedule_; }
InstructionSequence* sequence() const { return sequence_; } InstructionSequence* sequence() const { return sequence_; }
Zone* instruction_zone() const { return sequence()->zone(); } Zone* instruction_zone() const { return sequence()->zone(); }
Zone* zone() { return &zone_; } Zone* zone() { return &zone_; }
...@@ -195,6 +195,7 @@ class InstructionSelector FINAL { ...@@ -195,6 +195,7 @@ class InstructionSelector FINAL {
InstructionSequence* sequence_; InstructionSequence* sequence_;
SourcePositionTable* source_positions_; SourcePositionTable* source_positions_;
Features features_; Features features_;
Schedule* schedule_;
BasicBlock* current_block_; BasicBlock* current_block_;
ZoneDeque<Instruction*> instructions_; ZoneDeque<Instruction*> instructions_;
BoolVector defined_; BoolVector defined_;
......
...@@ -335,6 +335,7 @@ InstructionBlock::InstructionBlock(Zone* zone, const BasicBlock* block) ...@@ -335,6 +335,7 @@ InstructionBlock::InstructionBlock(Zone* zone, const BasicBlock* block)
predecessors_(static_cast<int>(block->PredecessorCount()), predecessors_(static_cast<int>(block->PredecessorCount()),
BasicBlock::RpoNumber::Invalid(), zone), BasicBlock::RpoNumber::Invalid(), zone),
phis_(zone), phis_(zone),
id_(block->id()),
rpo_number_(block->GetRpoNumber()), rpo_number_(block->GetRpoNumber()),
loop_header_(GetRpo(block->loop_header())), loop_header_(GetRpo(block->loop_header())),
loop_end_(GetLoopEndRpo(block)), loop_end_(GetLoopEndRpo(block)),
...@@ -379,15 +380,14 @@ static void InitializeInstructionBlocks(Zone* zone, const Schedule* schedule, ...@@ -379,15 +380,14 @@ static void InitializeInstructionBlocks(Zone* zone, const Schedule* schedule,
} }
InstructionSequence::InstructionSequence(Linkage* linkage, Graph* graph, InstructionSequence::InstructionSequence(Linkage* linkage, const Graph* graph,
Schedule* schedule) const Schedule* schedule)
: zone_(schedule->zone()), // TODO(dcarney): new zone. : zone_(graph->zone()->isolate()),
node_count_(graph->NodeCount()), node_count_(graph->NodeCount()),
node_map_(zone()->NewArray<int>(node_count_)), node_map_(zone()->NewArray<int>(node_count_)),
instruction_blocks_(static_cast<int>(schedule->rpo_order()->size()), NULL, instruction_blocks_(static_cast<int>(schedule->rpo_order()->size()), NULL,
zone()), zone()),
linkage_(linkage), linkage_(linkage),
schedule_(schedule),
constants_(ConstantMap::key_compare(), constants_(ConstantMap::key_compare(),
ConstantMap::allocator_type(zone())), ConstantMap::allocator_type(zone())),
immediates_(zone()), immediates_(zone()),
...@@ -419,25 +419,28 @@ Label* InstructionSequence::GetLabel(BasicBlock::RpoNumber rpo) { ...@@ -419,25 +419,28 @@ Label* InstructionSequence::GetLabel(BasicBlock::RpoNumber rpo) {
BlockStartInstruction* InstructionSequence::GetBlockStart( BlockStartInstruction* InstructionSequence::GetBlockStart(
BasicBlock::RpoNumber rpo) { BasicBlock::RpoNumber rpo) {
InstructionBlock* block = InstructionBlockAt(rpo);
BlockStartInstruction* block_start = BlockStartInstruction* block_start =
BlockStartInstruction::cast(InstructionAt(code_start(rpo))); BlockStartInstruction::cast(InstructionAt(block->code_start()));
DCHECK_EQ(rpo.ToInt(), block_start->rpo_number().ToInt()); DCHECK_EQ(rpo.ToInt(), block_start->rpo_number().ToInt());
return block_start; return block_start;
} }
void InstructionSequence::StartBlock(BasicBlock* block) { void InstructionSequence::StartBlock(BasicBlock* basic_block) {
set_code_start(block, static_cast<int>(instructions_.size())); InstructionBlock* block = InstructionBlockAt(basic_block->GetRpoNumber());
block->set_code_start(static_cast<int>(instructions_.size()));
BlockStartInstruction* block_start = BlockStartInstruction* block_start =
BlockStartInstruction::New(zone(), block); BlockStartInstruction::New(zone(), basic_block);
AddInstruction(block_start); AddInstruction(block_start);
} }
void InstructionSequence::EndBlock(BasicBlock* block) { void InstructionSequence::EndBlock(BasicBlock* basic_block) {
int end = static_cast<int>(instructions_.size()); int end = static_cast<int>(instructions_.size());
DCHECK(code_start(block) >= 0 && code_start(block) < end); InstructionBlock* block = InstructionBlockAt(basic_block->GetRpoNumber());
set_code_end(block, end); DCHECK(block->code_start() >= 0 && block->code_start() < end);
block->set_code_end(end);
} }
...@@ -459,19 +462,6 @@ int InstructionSequence::AddInstruction(Instruction* instr) { ...@@ -459,19 +462,6 @@ int InstructionSequence::AddInstruction(Instruction* instr) {
} }
BasicBlock* InstructionSequence::GetBasicBlock(int instruction_index) {
// TODO(turbofan): Optimize this.
for (;;) {
DCHECK_LE(0, instruction_index);
Instruction* instruction = InstructionAt(instruction_index--);
if (instruction->IsBlockStart()) {
return schedule()->rpo_order()->at(
BlockStartInstruction::cast(instruction)->rpo_number().ToSize());
}
}
}
const InstructionBlock* InstructionSequence::GetInstructionBlock( const InstructionBlock* InstructionSequence::GetInstructionBlock(
int instruction_index) const { int instruction_index) const {
// TODO(turbofan): Optimize this. // TODO(turbofan): Optimize this.
...@@ -614,53 +604,50 @@ std::ostream& operator<<(std::ostream& os, const InstructionSequence& code) { ...@@ -614,53 +604,50 @@ std::ostream& operator<<(std::ostream& os, const InstructionSequence& code) {
os << "CST#" << i << ": v" << it->first << " = " << it->second << "\n"; os << "CST#" << i << ": v" << it->first << " = " << it->second << "\n";
} }
for (int i = 0; i < code.BasicBlockCount(); i++) { for (int i = 0; i < code.BasicBlockCount(); i++) {
BasicBlock* block = code.BlockAt(i); BasicBlock::RpoNumber rpo = BasicBlock::RpoNumber::FromInt(i);
const InstructionBlock* block = code.InstructionBlockAt(rpo);
CHECK(block->rpo_number() == rpo);
os << "RPO#" << block->rpo_number() << ": B" << block->id(); os << "RPO#" << block->rpo_number() << ": B" << block->id();
CHECK(block->rpo_number() == i);
if (block->IsLoopHeader()) { if (block->IsLoopHeader()) {
os << " loop blocks: [" << block->rpo_number() << ", " os << " loop blocks: [" << block->rpo_number() << ", "
<< block->loop_end() << ")"; << block->loop_end() << ")";
} }
os << " instructions: [" << code.code_start(block) << ", " os << " instructions: [" << block->code_start() << ", "
<< code.code_end(block) << ")\n predecessors:"; << block->code_end() << ")\n predecessors:";
for (BasicBlock::Predecessors::iterator iter = block->predecessors_begin(); for (auto pred : block->predecessors()) {
iter != block->predecessors_end(); ++iter) { const InstructionBlock* pred_block = code.InstructionBlockAt(pred);
os << " B" << (*iter)->id(); os << " B" << pred_block->id();
} }
os << "\n"; os << "\n";
for (BasicBlock::const_iterator j = block->begin(); j != block->end(); for (auto phi : block->phis()) {
++j) { os << " phi: v" << phi->virtual_register() << " =";
Node* phi = *j; for (auto op_vreg : phi->operands()) {
if (phi->opcode() != IrOpcode::kPhi) continue; os << " v" << op_vreg;
os << " phi: v" << phi->id() << " =";
Node::Inputs inputs = phi->inputs();
for (Node::Inputs::iterator iter(inputs.begin()); iter != inputs.end();
++iter) {
os << " v" << (*iter)->id();
} }
os << "\n"; os << "\n";
} }
ScopedVector<char> buf(32); ScopedVector<char> buf(32);
for (int j = code.first_instruction_index(block); for (int j = block->first_instruction_index();
j <= code.last_instruction_index(block); j++) { j <= block->last_instruction_index(); j++) {
// TODO(svenpanne) Add some basic formatting to our streams. // TODO(svenpanne) Add some basic formatting to our streams.
SNPrintF(buf, "%5d", j); SNPrintF(buf, "%5d", j);
os << " " << buf.start() << ": " << *code.InstructionAt(j) << "\n"; os << " " << buf.start() << ": " << *code.InstructionAt(j) << "\n";
} }
os << " " << block->control(); // TODO(dcarney): add this back somehow?
// os << " " << block->control();
if (block->control_input() != NULL) { // if (block->control_input() != NULL) {
os << " v" << block->control_input()->id(); // os << " v" << block->control_input()->id();
} // }
for (BasicBlock::Successors::iterator iter = block->successors_begin(); for (auto succ : block->successors()) {
iter != block->successors_end(); ++iter) { const InstructionBlock* succ_block = code.InstructionBlockAt(succ);
os << " B" << (*iter)->id(); os << " B" << succ_block->id();
} }
os << "\n"; os << "\n";
} }
......
...@@ -755,7 +755,7 @@ std::ostream& operator<<(std::ostream& os, const Constant& constant); ...@@ -755,7 +755,7 @@ std::ostream& operator<<(std::ostream& os, const Constant& constant);
// TODO(dcarney): this is a temporary hack. turn into an actual instruction. // TODO(dcarney): this is a temporary hack. turn into an actual instruction.
class PhiInstruction : public ZoneObject { class PhiInstruction FINAL : public ZoneObject {
public: public:
PhiInstruction(Zone* zone, int virtual_register) PhiInstruction(Zone* zone, int virtual_register)
: virtual_register_(virtual_register), operands_(zone) {} : virtual_register_(virtual_register), operands_(zone) {}
...@@ -771,7 +771,7 @@ class PhiInstruction : public ZoneObject { ...@@ -771,7 +771,7 @@ class PhiInstruction : public ZoneObject {
// Analogue of BasicBlock for Instructions instead of Nodes. // Analogue of BasicBlock for Instructions instead of Nodes.
class InstructionBlock : public ZoneObject { class InstructionBlock FINAL : public ZoneObject {
public: public:
explicit InstructionBlock(Zone* zone, const BasicBlock* block); explicit InstructionBlock(Zone* zone, const BasicBlock* block);
...@@ -795,6 +795,7 @@ class InstructionBlock : public ZoneObject { ...@@ -795,6 +795,7 @@ class InstructionBlock : public ZoneObject {
int32_t code_end() const { return code_end_; } int32_t code_end() const { return code_end_; }
void set_code_end(int32_t end) { code_end_ = end; } void set_code_end(int32_t end) { code_end_ = end; }
BasicBlock::Id id() const { return id_; }
BasicBlock::RpoNumber rpo_number() const { return rpo_number_; } BasicBlock::RpoNumber rpo_number() const { return rpo_number_; }
BasicBlock::RpoNumber loop_header() const { return loop_header_; } BasicBlock::RpoNumber loop_header() const { return loop_header_; }
BasicBlock::RpoNumber loop_end() const { BasicBlock::RpoNumber loop_end() const {
...@@ -820,6 +821,7 @@ class InstructionBlock : public ZoneObject { ...@@ -820,6 +821,7 @@ class InstructionBlock : public ZoneObject {
Successors successors_; Successors successors_;
Predecessors predecessors_; Predecessors predecessors_;
PhiInstructions phis_; PhiInstructions phis_;
BasicBlock::Id id_;
// TODO(dcarney): probably dont't need this. // TODO(dcarney): probably dont't need this.
BasicBlock::RpoNumber rpo_number_; BasicBlock::RpoNumber rpo_number_;
BasicBlock::RpoNumber loop_header_; BasicBlock::RpoNumber loop_header_;
...@@ -842,7 +844,8 @@ typedef ZoneVector<InstructionBlock*> InstructionBlocks; ...@@ -842,7 +844,8 @@ typedef ZoneVector<InstructionBlock*> InstructionBlocks;
// TODO(titzer): s/IsDouble/IsFloat64/ // TODO(titzer): s/IsDouble/IsFloat64/
class InstructionSequence FINAL { class InstructionSequence FINAL {
public: public:
InstructionSequence(Linkage* linkage, Graph* graph, Schedule* schedule); InstructionSequence(Linkage* linkage, const Graph* graph,
const Schedule* schedule);
int NextVirtualRegister() { return next_virtual_register_++; } int NextVirtualRegister() { return next_virtual_register_++; }
int VirtualRegisterCount() const { return next_virtual_register_; } int VirtualRegisterCount() const { return next_virtual_register_; }
...@@ -853,17 +856,13 @@ class InstructionSequence FINAL { ...@@ -853,17 +856,13 @@ class InstructionSequence FINAL {
return static_cast<int>(instruction_blocks_.size()); return static_cast<int>(instruction_blocks_.size());
} }
BasicBlock* BlockAt(int rpo_number) const {
return (*schedule_->rpo_order())[rpo_number];
}
InstructionBlock* InstructionBlockAt(BasicBlock::RpoNumber rpo_number) { InstructionBlock* InstructionBlockAt(BasicBlock::RpoNumber rpo_number) {
return GetBlock(rpo_number); return instruction_blocks_[rpo_number.ToSize()];
} }
const InstructionBlock* InstructionBlockAt( const InstructionBlock* InstructionBlockAt(
BasicBlock::RpoNumber rpo_number) const { BasicBlock::RpoNumber rpo_number) const {
return GetBlock(rpo_number); return instruction_blocks_[rpo_number.ToSize()];
} }
// TODO(dcarney): move to register allocator. // TODO(dcarney): move to register allocator.
...@@ -874,7 +873,6 @@ class InstructionSequence FINAL { ...@@ -874,7 +873,6 @@ class InstructionSequence FINAL {
return instruction_blocks_[index.ToInt()]; return instruction_blocks_[index.ToInt()];
} }
BasicBlock* GetBasicBlock(int instruction_index);
const InstructionBlock* GetInstructionBlock(int instruction_index) const; const InstructionBlock* GetInstructionBlock(int instruction_index) const;
int GetVirtualRegister(const Node* node); int GetVirtualRegister(const Node* node);
...@@ -907,44 +905,15 @@ class InstructionSequence FINAL { ...@@ -907,44 +905,15 @@ class InstructionSequence FINAL {
} }
Frame* frame() { return &frame_; } Frame* frame() { return &frame_; }
Isolate* isolate() const { return zone()->isolate(); } Isolate* isolate() { return zone()->isolate(); }
Linkage* linkage() const { return linkage_; } Linkage* linkage() const { return linkage_; }
Schedule* schedule() const { return schedule_; }
const PointerMapDeque* pointer_maps() const { return &pointer_maps_; } const PointerMapDeque* pointer_maps() const { return &pointer_maps_; }
Zone* zone() const { return zone_; } Zone* zone() { return &zone_; }
// Used by the instruction selector while adding instructions. // Used by the instruction selector while adding instructions.
int AddInstruction(Instruction* instr); int AddInstruction(Instruction* instr);
void StartBlock(BasicBlock* block); void StartBlock(BasicBlock* block);
void EndBlock(BasicBlock* block); void EndBlock(BasicBlock* block);
void set_code_start(BasicBlock* block, int start) {
return GetBlock(block->GetRpoNumber())->set_code_start(start);
}
void set_code_end(BasicBlock* block, int end) {
return GetBlock(block->GetRpoNumber())->set_code_end(end);
}
// TODO(dcarney): use RpoNumber for all of the below.
int code_start(BasicBlock::RpoNumber rpo_number) const {
return GetBlock(rpo_number)->code_start();
}
int code_start(BasicBlock* block) const {
return GetBlock(block->GetRpoNumber())->code_start();
}
int code_end(BasicBlock* block) const {
return GetBlock(block->GetRpoNumber())->code_end();
}
int first_instruction_index(BasicBlock* block) const {
return GetBlock(block->GetRpoNumber())->first_instruction_index();
}
int last_instruction_index(BasicBlock* block) const {
return GetBlock(block->GetRpoNumber())->last_instruction_index();
}
int first_instruction_index(InstructionBlock* block) const {
return GetBlock(block->rpo_number())->first_instruction_index();
}
int last_instruction_index(InstructionBlock* block) const {
return GetBlock(block->rpo_number())->last_instruction_index();
}
int AddConstant(Node* node, Constant constant) { int AddConstant(Node* node, Constant constant) {
int virtual_register = GetVirtualRegister(node); int virtual_register = GetVirtualRegister(node);
...@@ -988,21 +957,16 @@ class InstructionSequence FINAL { ...@@ -988,21 +957,16 @@ class InstructionSequence FINAL {
int GetFrameStateDescriptorCount(); int GetFrameStateDescriptorCount();
private: private:
InstructionBlock* GetBlock(BasicBlock::RpoNumber rpo_number) const {
return instruction_blocks_[rpo_number.ToSize()];
}
friend std::ostream& operator<<(std::ostream& os, friend std::ostream& operator<<(std::ostream& os,
const InstructionSequence& code); const InstructionSequence& code);
typedef std::set<int, std::less<int>, ZoneIntAllocator> VirtualRegisterSet; typedef std::set<int, std::less<int>, ZoneIntAllocator> VirtualRegisterSet;
Zone* zone_; Zone zone_;
int node_count_; int node_count_;
int* node_map_; int* node_map_;
InstructionBlocks instruction_blocks_; InstructionBlocks instruction_blocks_;
Linkage* linkage_; Linkage* linkage_;
Schedule* schedule_;
ConstantMap constants_; ConstantMap constants_;
ConstantDeque immediates_; ConstantDeque immediates_;
InstructionDeque instructions_; InstructionDeque instructions_;
......
...@@ -457,7 +457,7 @@ Handle<Code> Pipeline::GenerateCode(Linkage* linkage, Graph* graph, ...@@ -457,7 +457,7 @@ Handle<Code> Pipeline::GenerateCode(Linkage* linkage, Graph* graph,
// Select and schedule instructions covering the scheduled graph. // Select and schedule instructions covering the scheduled graph.
{ {
InstructionSelector selector(&sequence, source_positions); InstructionSelector selector(&sequence, schedule, source_positions);
selector.SelectInstructions(); selector.SelectInstructions();
} }
......
...@@ -105,6 +105,11 @@ std::ostream& operator<<(std::ostream& os, const BasicBlock::Id& id) { ...@@ -105,6 +105,11 @@ std::ostream& operator<<(std::ostream& os, const BasicBlock::Id& id) {
} }
std::ostream& operator<<(std::ostream& os, const BasicBlock::RpoNumber& rpo) {
return os << rpo.ToSize();
}
Schedule::Schedule(Zone* zone, size_t node_count_hint) Schedule::Schedule(Zone* zone, size_t node_count_hint)
: zone_(zone), : zone_(zone),
all_blocks_(zone), all_blocks_(zone),
......
...@@ -182,6 +182,7 @@ class BasicBlock FINAL : public ZoneObject { ...@@ -182,6 +182,7 @@ class BasicBlock FINAL : public ZoneObject {
std::ostream& operator<<(std::ostream& os, const BasicBlock::Control& c); std::ostream& operator<<(std::ostream& os, const BasicBlock::Control& c);
std::ostream& operator<<(std::ostream& os, const BasicBlock::Id& id); std::ostream& operator<<(std::ostream& os, const BasicBlock::Id& id);
std::ostream& operator<<(std::ostream& os, const BasicBlock::RpoNumber& rpo);
typedef ZoneVector<BasicBlock*> BasicBlockVector; typedef ZoneVector<BasicBlock*> BasicBlockVector;
typedef BasicBlockVector::iterator BasicBlockVectorIter; typedef BasicBlockVector::iterator BasicBlockVectorIter;
......
...@@ -68,7 +68,7 @@ class DeoptCodegenTester { ...@@ -68,7 +68,7 @@ class DeoptCodegenTester {
code = new v8::internal::compiler::InstructionSequence(linkage, graph, code = new v8::internal::compiler::InstructionSequence(linkage, graph,
schedule); schedule);
SourcePositionTable source_positions(graph); SourcePositionTable source_positions(graph);
InstructionSelector selector(code, &source_positions); InstructionSelector selector(code, schedule, &source_positions);
selector.SelectInstructions(); selector.SelectInstructions();
if (FLAG_trace_turbo) { if (FLAG_trace_turbo) {
......
...@@ -93,6 +93,21 @@ class InstructionTester : public HandleAndZoneScope { ...@@ -93,6 +93,21 @@ class InstructionTester : public HandleAndZoneScope {
unallocated->set_virtual_register(vreg); unallocated->set_virtual_register(vreg);
return unallocated; return unallocated;
} }
InstructionBlock* BlockAt(BasicBlock* block) {
return code->InstructionBlockAt(block->GetRpoNumber());
}
BasicBlock* GetBasicBlock(int instruction_index) {
const InstructionBlock* block =
code->GetInstructionBlock(instruction_index);
return schedule.rpo_order()->at(block->rpo_number().ToSize());
}
int first_instruction_index(BasicBlock* block) {
return BlockAt(block)->first_instruction_index();
}
int last_instruction_index(BasicBlock* block) {
return BlockAt(block)->last_instruction_index();
}
}; };
...@@ -121,7 +136,8 @@ TEST(InstructionBasic) { ...@@ -121,7 +136,8 @@ TEST(InstructionBasic) {
for (BasicBlockVectorIter i = blocks->begin(); i != blocks->end(); for (BasicBlockVectorIter i = blocks->begin(); i != blocks->end();
i++, index++) { i++, index++) {
BasicBlock* block = *i; BasicBlock* block = *i;
CHECK_EQ(block, R.code->BlockAt(index)); CHECK_EQ(block->rpo_number(), R.BlockAt(block)->rpo_number().ToInt());
CHECK_EQ(block->id().ToInt(), R.BlockAt(block)->id().ToInt());
CHECK_EQ(-1, block->loop_end()); CHECK_EQ(-1, block->loop_end());
} }
} }
...@@ -159,29 +175,29 @@ TEST(InstructionGetBasicBlock) { ...@@ -159,29 +175,29 @@ TEST(InstructionGetBasicBlock) {
R.code->StartBlock(b3); R.code->StartBlock(b3);
R.code->EndBlock(b3); R.code->EndBlock(b3);
CHECK_EQ(b0, R.code->GetBasicBlock(i0)); CHECK_EQ(b0, R.GetBasicBlock(i0));
CHECK_EQ(b0, R.code->GetBasicBlock(i1)); CHECK_EQ(b0, R.GetBasicBlock(i1));
CHECK_EQ(b1, R.code->GetBasicBlock(i2)); CHECK_EQ(b1, R.GetBasicBlock(i2));
CHECK_EQ(b1, R.code->GetBasicBlock(i3)); CHECK_EQ(b1, R.GetBasicBlock(i3));
CHECK_EQ(b1, R.code->GetBasicBlock(i4)); CHECK_EQ(b1, R.GetBasicBlock(i4));
CHECK_EQ(b1, R.code->GetBasicBlock(i5)); CHECK_EQ(b1, R.GetBasicBlock(i5));
CHECK_EQ(b2, R.code->GetBasicBlock(i6)); CHECK_EQ(b2, R.GetBasicBlock(i6));
CHECK_EQ(b2, R.code->GetBasicBlock(i7)); CHECK_EQ(b2, R.GetBasicBlock(i7));
CHECK_EQ(b2, R.code->GetBasicBlock(i8)); CHECK_EQ(b2, R.GetBasicBlock(i8));
CHECK_EQ(b0, R.code->GetBasicBlock(R.code->first_instruction_index(b0))); CHECK_EQ(b0, R.GetBasicBlock(R.first_instruction_index(b0)));
CHECK_EQ(b0, R.code->GetBasicBlock(R.code->last_instruction_index(b0))); CHECK_EQ(b0, R.GetBasicBlock(R.last_instruction_index(b0)));
CHECK_EQ(b1, R.code->GetBasicBlock(R.code->first_instruction_index(b1))); CHECK_EQ(b1, R.GetBasicBlock(R.first_instruction_index(b1)));
CHECK_EQ(b1, R.code->GetBasicBlock(R.code->last_instruction_index(b1))); CHECK_EQ(b1, R.GetBasicBlock(R.last_instruction_index(b1)));
CHECK_EQ(b2, R.code->GetBasicBlock(R.code->first_instruction_index(b2))); CHECK_EQ(b2, R.GetBasicBlock(R.first_instruction_index(b2)));
CHECK_EQ(b2, R.code->GetBasicBlock(R.code->last_instruction_index(b2))); CHECK_EQ(b2, R.GetBasicBlock(R.last_instruction_index(b2)));
CHECK_EQ(b3, R.code->GetBasicBlock(R.code->first_instruction_index(b3))); CHECK_EQ(b3, R.GetBasicBlock(R.first_instruction_index(b3)));
CHECK_EQ(b3, R.code->GetBasicBlock(R.code->last_instruction_index(b3))); CHECK_EQ(b3, R.GetBasicBlock(R.last_instruction_index(b3)));
} }
......
...@@ -40,7 +40,8 @@ InstructionSelectorTest::Stream InstructionSelectorTest::StreamBuilder::Build( ...@@ -40,7 +40,8 @@ InstructionSelectorTest::Stream InstructionSelectorTest::StreamBuilder::Build(
Linkage linkage(&info, call_descriptor()); Linkage linkage(&info, call_descriptor());
InstructionSequence sequence(&linkage, graph(), schedule); InstructionSequence sequence(&linkage, graph(), schedule);
SourcePositionTable source_position_table(graph()); SourcePositionTable source_position_table(graph());
InstructionSelector selector(&sequence, &source_position_table, features); InstructionSelector selector(&sequence, schedule, &source_position_table,
features);
selector.SelectInstructions(); selector.SelectInstructions();
if (FLAG_trace_turbo) { if (FLAG_trace_turbo) {
OFStream out(stdout); OFStream out(stdout);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment