Commit e928c9d5 authored by dcarney's avatar dcarney Committed by Commit bot

[turbofan] remove dependence of InstructionBlock on BasicBlock

BUG=

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

Cr-Commit-Position: refs/heads/master@{#26859}
parent 652061ed
...@@ -740,7 +740,7 @@ void CodeGenerator::AssembleArchBranch(Instruction* instr, BranchInfo* branch) { ...@@ -740,7 +740,7 @@ void CodeGenerator::AssembleArchBranch(Instruction* instr, BranchInfo* branch) {
} }
void CodeGenerator::AssembleArchJump(BasicBlock::RpoNumber target) { void CodeGenerator::AssembleArchJump(RpoNumber target) {
if (!IsNextInAssemblyOrder(target)) __ b(GetLabel(target)); if (!IsNextInAssemblyOrder(target)) __ b(GetLabel(target));
} }
......
...@@ -841,7 +841,7 @@ void CodeGenerator::AssembleArchBranch(Instruction* instr, BranchInfo* branch) { ...@@ -841,7 +841,7 @@ void CodeGenerator::AssembleArchBranch(Instruction* instr, BranchInfo* branch) {
} }
void CodeGenerator::AssembleArchJump(BasicBlock::RpoNumber target) { void CodeGenerator::AssembleArchJump(RpoNumber target) {
if (!IsNextInAssemblyOrder(target)) __ B(GetLabel(target)); if (!IsNextInAssemblyOrder(target)) __ B(GetLabel(target));
} }
......
...@@ -63,7 +63,7 @@ class InstructionOperandConverter { ...@@ -63,7 +63,7 @@ class InstructionOperandConverter {
Label* InputLabel(size_t index) { return ToLabel(instr_->InputAt(index)); } Label* InputLabel(size_t index) { return ToLabel(instr_->InputAt(index)); }
BasicBlock::RpoNumber InputRpo(size_t index) { RpoNumber InputRpo(size_t index) {
return ToRpoNumber(instr_->InputAt(index)); return ToRpoNumber(instr_->InputAt(index));
} }
...@@ -85,7 +85,7 @@ class InstructionOperandConverter { ...@@ -85,7 +85,7 @@ class InstructionOperandConverter {
return gen_->GetLabel(ToRpoNumber(op)); return gen_->GetLabel(ToRpoNumber(op));
} }
BasicBlock::RpoNumber ToRpoNumber(InstructionOperand* op) { RpoNumber ToRpoNumber(InstructionOperand* op) {
return ToConstant(op).ToRpoNumber(); return ToConstant(op).ToRpoNumber();
} }
......
...@@ -37,7 +37,7 @@ CodeGenerator::CodeGenerator(Frame* frame, Linkage* linkage, ...@@ -37,7 +37,7 @@ CodeGenerator::CodeGenerator(Frame* frame, Linkage* linkage,
code_(code), code_(code),
info_(info), info_(info),
labels_(zone()->NewArray<Label>(code->InstructionBlockCount())), labels_(zone()->NewArray<Label>(code->InstructionBlockCount())),
current_block_(BasicBlock::RpoNumber::Invalid()), current_block_(RpoNumber::Invalid()),
current_source_position_(SourcePosition::Invalid()), current_source_position_(SourcePosition::Invalid()),
masm_(info->isolate(), NULL, 0), masm_(info->isolate(), NULL, 0),
resolver_(this), resolver_(this),
...@@ -85,7 +85,7 @@ Handle<Code> CodeGenerator::GenerateCode() { ...@@ -85,7 +85,7 @@ Handle<Code> CodeGenerator::GenerateCode() {
if (FLAG_code_comments) { if (FLAG_code_comments) {
// TODO(titzer): these code comments are a giant memory leak. // TODO(titzer): these code comments are a giant memory leak.
Vector<char> buffer = Vector<char>::New(32); Vector<char> buffer = Vector<char>::New(32);
SNPrintF(buffer, "-- B%d start --", block->id().ToInt()); SNPrintF(buffer, "-- B%d start --", block->rpo_number().ToInt());
masm()->RecordComment(buffer.start()); masm()->RecordComment(buffer.start());
} }
masm()->bind(GetLabel(current_block_)); masm()->bind(GetLabel(current_block_));
...@@ -159,7 +159,7 @@ Handle<Code> CodeGenerator::GenerateCode() { ...@@ -159,7 +159,7 @@ Handle<Code> CodeGenerator::GenerateCode() {
} }
bool CodeGenerator::IsNextInAssemblyOrder(BasicBlock::RpoNumber block) const { bool CodeGenerator::IsNextInAssemblyOrder(RpoNumber block) const {
return code()->InstructionBlockAt(current_block_)->ao_number().IsNext( return code()->InstructionBlockAt(current_block_)->ao_number().IsNext(
code()->InstructionBlockAt(block)->ao_number()); code()->InstructionBlockAt(block)->ao_number());
} }
...@@ -199,8 +199,8 @@ void CodeGenerator::AssembleInstruction(Instruction* instr) { ...@@ -199,8 +199,8 @@ void CodeGenerator::AssembleInstruction(Instruction* instr) {
if (mode == kFlags_branch) { if (mode == kFlags_branch) {
// Assemble a branch after this instruction. // Assemble a branch after this instruction.
InstructionOperandConverter i(this, instr); InstructionOperandConverter i(this, instr);
BasicBlock::RpoNumber true_rpo = i.InputRpo(instr->InputCount() - 2); RpoNumber true_rpo = i.InputRpo(instr->InputCount() - 2);
BasicBlock::RpoNumber false_rpo = i.InputRpo(instr->InputCount() - 1); RpoNumber false_rpo = i.InputRpo(instr->InputCount() - 1);
if (true_rpo == false_rpo) { if (true_rpo == false_rpo) {
// redundant branch. // redundant branch.
...@@ -343,7 +343,7 @@ void CodeGenerator::RecordCallPosition(Instruction* instr) { ...@@ -343,7 +343,7 @@ void CodeGenerator::RecordCallPosition(Instruction* instr) {
if (flags & CallDescriptor::kHasExceptionHandler) { if (flags & CallDescriptor::kHasExceptionHandler) {
InstructionOperandConverter i(this, instr); InstructionOperandConverter i(this, instr);
BasicBlock::RpoNumber handler_rpo = RpoNumber handler_rpo =
i.InputRpo(static_cast<int>(instr->InputCount()) - 1); i.InputRpo(static_cast<int>(instr->InputCount()) - 1);
handlers_.push_back({GetLabel(handler_rpo), masm()->pc_offset()}); handlers_.push_back({GetLabel(handler_rpo), masm()->pc_offset()});
} }
...@@ -592,9 +592,7 @@ void CodeGenerator::AssembleArchBoolean(Instruction* instr, ...@@ -592,9 +592,7 @@ void CodeGenerator::AssembleArchBoolean(Instruction* instr,
} }
void CodeGenerator::AssembleArchJump(BasicBlock::RpoNumber target) { void CodeGenerator::AssembleArchJump(RpoNumber target) { UNIMPLEMENTED(); }
UNIMPLEMENTED();
}
void CodeGenerator::AssembleDeoptimizerCall(int deoptimization_id) { void CodeGenerator::AssembleDeoptimizerCall(int deoptimization_id) {
......
...@@ -41,7 +41,7 @@ class CodeGenerator FINAL : public GapResolver::Assembler { ...@@ -41,7 +41,7 @@ class CodeGenerator FINAL : public GapResolver::Assembler {
Isolate* isolate() const { return info_->isolate(); } Isolate* isolate() const { return info_->isolate(); }
Linkage* linkage() const { return linkage_; } Linkage* linkage() const { return linkage_; }
Label* GetLabel(BasicBlock::RpoNumber rpo) { return &labels_[rpo.ToSize()]; } Label* GetLabel(RpoNumber rpo) { return &labels_[rpo.ToSize()]; }
private: private:
MacroAssembler* masm() { return &masm_; } MacroAssembler* masm() { return &masm_; }
...@@ -52,7 +52,7 @@ class CodeGenerator FINAL : public GapResolver::Assembler { ...@@ -52,7 +52,7 @@ class CodeGenerator FINAL : public GapResolver::Assembler {
// Checks if {block} will appear directly after {current_block_} when // Checks if {block} will appear directly after {current_block_} when
// assembling code, in which case, a fall-through can be used. // assembling code, in which case, a fall-through can be used.
bool IsNextInAssemblyOrder(BasicBlock::RpoNumber block) const; bool IsNextInAssemblyOrder(RpoNumber block) const;
// Record a safepoint with the given pointer map. // Record a safepoint with the given pointer map.
void RecordSafepoint(PointerMap* pointers, Safepoint::Kind kind, void RecordSafepoint(PointerMap* pointers, Safepoint::Kind kind,
...@@ -68,7 +68,7 @@ class CodeGenerator FINAL : public GapResolver::Assembler { ...@@ -68,7 +68,7 @@ class CodeGenerator FINAL : public GapResolver::Assembler {
// =========================================================================== // ===========================================================================
void AssembleArchInstruction(Instruction* instr); void AssembleArchInstruction(Instruction* instr);
void AssembleArchJump(BasicBlock::RpoNumber target); void AssembleArchJump(RpoNumber target);
void AssembleArchBranch(Instruction* instr, BranchInfo* branch); void AssembleArchBranch(Instruction* instr, BranchInfo* branch);
void AssembleArchBoolean(Instruction* instr, FlagsCondition condition); void AssembleArchBoolean(Instruction* instr, FlagsCondition condition);
void AssembleArchLookupSwitch(Instruction* instr); void AssembleArchLookupSwitch(Instruction* instr);
...@@ -158,7 +158,7 @@ class CodeGenerator FINAL : public GapResolver::Assembler { ...@@ -158,7 +158,7 @@ class CodeGenerator FINAL : public GapResolver::Assembler {
InstructionSequence* const code_; InstructionSequence* const code_;
CompilationInfo* const info_; CompilationInfo* const info_;
Label* const labels_; Label* const labels_;
BasicBlock::RpoNumber current_block_; RpoNumber current_block_;
SourcePosition current_source_position_; SourcePosition current_source_position_;
MacroAssembler masm_; MacroAssembler masm_;
GapResolver resolver_; GapResolver resolver_;
......
...@@ -406,7 +406,7 @@ class GraphC1Visualizer { ...@@ -406,7 +406,7 @@ class GraphC1Visualizer {
void PrintStringProperty(const char* name, const char* value); void PrintStringProperty(const char* name, const char* value);
void PrintLongProperty(const char* name, int64_t value); void PrintLongProperty(const char* name, int64_t value);
void PrintIntProperty(const char* name, int value); void PrintIntProperty(const char* name, int value);
void PrintBlockProperty(const char* name, BasicBlock::Id block_id); void PrintBlockProperty(const char* name, int rpo_number);
void PrintNodeId(Node* n); void PrintNodeId(Node* n);
void PrintNode(Node* n); void PrintNode(Node* n);
void PrintInputs(Node* n); void PrintInputs(Node* n);
...@@ -469,10 +469,9 @@ void GraphC1Visualizer::PrintLongProperty(const char* name, int64_t value) { ...@@ -469,10 +469,9 @@ void GraphC1Visualizer::PrintLongProperty(const char* name, int64_t value) {
} }
void GraphC1Visualizer::PrintBlockProperty(const char* name, void GraphC1Visualizer::PrintBlockProperty(const char* name, int rpo_number) {
BasicBlock::Id block_id) {
PrintIndent(); PrintIndent();
os_ << name << " \"B" << block_id << "\"\n"; os_ << name << " \"B" << rpo_number << "\"\n";
} }
...@@ -558,21 +557,21 @@ void GraphC1Visualizer::PrintSchedule(const char* phase, ...@@ -558,21 +557,21 @@ void GraphC1Visualizer::PrintSchedule(const char* phase,
for (size_t i = 0; i < rpo->size(); i++) { for (size_t i = 0; i < rpo->size(); i++) {
BasicBlock* current = (*rpo)[i]; BasicBlock* current = (*rpo)[i];
Tag block_tag(this, "block"); Tag block_tag(this, "block");
PrintBlockProperty("name", current->id()); PrintBlockProperty("name", current->rpo_number());
PrintIntProperty("from_bci", -1); PrintIntProperty("from_bci", -1);
PrintIntProperty("to_bci", -1); PrintIntProperty("to_bci", -1);
PrintIndent(); PrintIndent();
os_ << "predecessors"; os_ << "predecessors";
for (BasicBlock* predecessor : current->predecessors()) { for (BasicBlock* predecessor : current->predecessors()) {
os_ << " \"B" << predecessor->id() << "\""; os_ << " \"B" << predecessor->rpo_number() << "\"";
} }
os_ << "\n"; os_ << "\n";
PrintIndent(); PrintIndent();
os_ << "successors"; os_ << "successors";
for (BasicBlock* successor : current->successors()) { for (BasicBlock* successor : current->successors()) {
os_ << " \"B" << successor->id() << "\""; os_ << " \"B" << successor->rpo_number() << "\"";
} }
os_ << "\n"; os_ << "\n";
...@@ -583,13 +582,14 @@ void GraphC1Visualizer::PrintSchedule(const char* phase, ...@@ -583,13 +582,14 @@ void GraphC1Visualizer::PrintSchedule(const char* phase,
os_ << "flags\n"; os_ << "flags\n";
if (current->dominator() != NULL) { if (current->dominator() != NULL) {
PrintBlockProperty("dominator", current->dominator()->id()); PrintBlockProperty("dominator", current->dominator()->rpo_number());
} }
PrintIntProperty("loop_depth", current->loop_depth()); PrintIntProperty("loop_depth", current->loop_depth());
const InstructionBlock* instruction_block = const InstructionBlock* instruction_block =
instructions->InstructionBlockAt(current->GetRpoNumber()); instructions->InstructionBlockAt(
RpoNumber::FromInt(current->rpo_number()));
if (instruction_block->code_start() >= 0) { if (instruction_block->code_start() >= 0) {
int first_index = instruction_block->first_instruction_index(); int first_index = instruction_block->first_instruction_index();
int last_index = instruction_block->last_instruction_index(); int last_index = instruction_block->last_instruction_index();
...@@ -654,11 +654,11 @@ void GraphC1Visualizer::PrintSchedule(const char* phase, ...@@ -654,11 +654,11 @@ void GraphC1Visualizer::PrintSchedule(const char* phase,
if (current->control_input() != NULL) { if (current->control_input() != NULL) {
PrintNode(current->control_input()); PrintNode(current->control_input());
} else { } else {
os_ << -1 - current->id().ToInt() << " Goto"; os_ << -1 - current->rpo_number() << " Goto";
} }
os_ << " ->"; os_ << " ->";
for (BasicBlock* successor : current->successors()) { for (BasicBlock* successor : current->successors()) {
os_ << " B" << successor->id(); os_ << " B" << successor->rpo_number();
} }
if (FLAG_trace_turbo_types && current->control_input() != NULL) { if (FLAG_trace_turbo_types && current->control_input() != NULL) {
os_ << " "; os_ << " ";
......
...@@ -761,7 +761,7 @@ void CodeGenerator::AssembleArchBranch(Instruction* instr, BranchInfo* branch) { ...@@ -761,7 +761,7 @@ void CodeGenerator::AssembleArchBranch(Instruction* instr, BranchInfo* branch) {
} }
void CodeGenerator::AssembleArchJump(BasicBlock::RpoNumber target) { void CodeGenerator::AssembleArchJump(RpoNumber target) {
if (!IsNextInAssemblyOrder(target)) __ jmp(GetLabel(target)); if (!IsNextInAssemblyOrder(target)) __ jmp(GetLabel(target));
} }
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include "src/compiler/instruction.h" #include "src/compiler/instruction.h"
#include "src/compiler/instruction-selector.h" #include "src/compiler/instruction-selector.h"
#include "src/compiler/linkage.h" #include "src/compiler/linkage.h"
#include "src/compiler/schedule.h"
#include "src/macro-assembler.h" #include "src/macro-assembler.h"
namespace v8 { namespace v8 {
...@@ -142,7 +143,8 @@ class OperandGenerator { ...@@ -142,7 +143,8 @@ class OperandGenerator {
} }
InstructionOperand Label(BasicBlock* block) { InstructionOperand Label(BasicBlock* block) {
int index = sequence()->AddImmediate(Constant(block->GetRpoNumber())); int index = sequence()->AddImmediate(
Constant(RpoNumber::FromInt(block->rpo_number())));
return ImmediateOperand(index); return ImmediateOperand(index);
} }
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include "src/compiler/node-matchers.h" #include "src/compiler/node-matchers.h"
#include "src/compiler/node-properties.h" #include "src/compiler/node-properties.h"
#include "src/compiler/pipeline.h" #include "src/compiler/pipeline.h"
#include "src/compiler/schedule.h"
namespace v8 { namespace v8 {
namespace internal { namespace internal {
...@@ -61,15 +62,15 @@ void InstructionSelector::SelectInstructions() { ...@@ -61,15 +62,15 @@ void InstructionSelector::SelectInstructions() {
// Schedule the selected instructions. // Schedule the selected instructions.
for (auto const block : *blocks) { for (auto const block : *blocks) {
InstructionBlock* instruction_block = InstructionBlock* instruction_block =
sequence()->InstructionBlockAt(block->GetRpoNumber()); sequence()->InstructionBlockAt(RpoNumber::FromInt(block->rpo_number()));
size_t end = instruction_block->code_end(); size_t end = instruction_block->code_end();
size_t start = instruction_block->code_start(); size_t start = instruction_block->code_start();
DCHECK_LE(end, start); DCHECK_LE(end, start);
sequence()->StartBlock(block->GetRpoNumber()); sequence()->StartBlock(RpoNumber::FromInt(block->rpo_number()));
while (start-- > end) { while (start-- > end) {
sequence()->AddInstruction(instructions_[start]); sequence()->AddInstruction(instructions_[start]);
} }
sequence()->EndBlock(block->GetRpoNumber()); sequence()->EndBlock(RpoNumber::FromInt(block->rpo_number()));
} }
} }
...@@ -477,7 +478,7 @@ void InstructionSelector::VisitBlock(BasicBlock* block) { ...@@ -477,7 +478,7 @@ void InstructionSelector::VisitBlock(BasicBlock* block) {
// We're done with the block. // We're done with the block.
InstructionBlock* instruction_block = InstructionBlock* instruction_block =
sequence()->InstructionBlockAt(block->GetRpoNumber()); sequence()->InstructionBlockAt(RpoNumber::FromInt(block->rpo_number()));
instruction_block->set_code_start(static_cast<int>(instructions_.size())); instruction_block->set_code_start(static_cast<int>(instructions_.size()));
instruction_block->set_code_end(current_block_end); instruction_block->set_code_end(current_block_end);
...@@ -1032,7 +1033,9 @@ void InstructionSelector::VisitPhi(Node* node) { ...@@ -1032,7 +1033,9 @@ void InstructionSelector::VisitPhi(Node* node) {
PhiInstruction* phi = new (instruction_zone()) PhiInstruction* phi = new (instruction_zone())
PhiInstruction(instruction_zone(), GetVirtualRegister(node), PhiInstruction(instruction_zone(), GetVirtualRegister(node),
static_cast<size_t>(input_count)); static_cast<size_t>(input_count));
sequence()->InstructionBlockAt(current_block_->GetRpoNumber())->AddPhi(phi); sequence()
->InstructionBlockAt(RpoNumber::FromInt(current_block_->rpo_number()))
->AddPhi(phi);
for (int i = 0; i < input_count; ++i) { for (int i = 0; i < input_count; ++i) {
Node* const input = node->InputAt(i); Node* const input = node->InputAt(i);
MarkAsUsed(input); MarkAsUsed(input);
......
...@@ -18,11 +18,11 @@ namespace internal { ...@@ -18,11 +18,11 @@ namespace internal {
namespace compiler { namespace compiler {
// Forward declarations. // Forward declarations.
class BasicBlock;
struct CallBuffer; // TODO(bmeurer): Remove this. struct CallBuffer; // TODO(bmeurer): Remove this.
class FlagsContinuation; class FlagsContinuation;
class Linkage; class Linkage;
typedef ZoneVector<InstructionOperand> InstructionOperandVector; typedef ZoneVector<InstructionOperand> InstructionOperandVector;
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#include "src/compiler/common-operator.h" #include "src/compiler/common-operator.h"
#include "src/compiler/graph.h" #include "src/compiler/graph.h"
#include "src/compiler/instruction.h" #include "src/compiler/instruction.h"
#include "src/compiler/schedule.h"
namespace v8 { namespace v8 {
namespace internal { namespace internal {
...@@ -375,15 +376,12 @@ void PhiInstruction::SetInput(size_t offset, int virtual_register) { ...@@ -375,15 +376,12 @@ void PhiInstruction::SetInput(size_t offset, int virtual_register) {
} }
InstructionBlock::InstructionBlock(Zone* zone, BasicBlock::Id id, InstructionBlock::InstructionBlock(Zone* zone, RpoNumber rpo_number,
BasicBlock::RpoNumber rpo_number, RpoNumber loop_header, RpoNumber loop_end,
BasicBlock::RpoNumber loop_header,
BasicBlock::RpoNumber loop_end,
bool deferred) bool deferred)
: successors_(zone), : successors_(zone),
predecessors_(zone), predecessors_(zone),
phis_(zone), phis_(zone),
id_(id),
ao_number_(rpo_number), ao_number_(rpo_number),
rpo_number_(rpo_number), rpo_number_(rpo_number),
loop_header_(loop_header), loop_header_(loop_header),
...@@ -393,8 +391,7 @@ InstructionBlock::InstructionBlock(Zone* zone, BasicBlock::Id id, ...@@ -393,8 +391,7 @@ InstructionBlock::InstructionBlock(Zone* zone, BasicBlock::Id id,
deferred_(deferred) {} deferred_(deferred) {}
size_t InstructionBlock::PredecessorIndexOf( size_t InstructionBlock::PredecessorIndexOf(RpoNumber rpo_number) const {
BasicBlock::RpoNumber rpo_number) const {
size_t j = 0; size_t j = 0;
for (InstructionBlock::Predecessors::const_iterator i = predecessors_.begin(); for (InstructionBlock::Predecessors::const_iterator i = predecessors_.begin();
i != predecessors_.end(); ++i, ++j) { i != predecessors_.end(); ++i, ++j) {
...@@ -404,31 +401,31 @@ size_t InstructionBlock::PredecessorIndexOf( ...@@ -404,31 +401,31 @@ size_t InstructionBlock::PredecessorIndexOf(
} }
static BasicBlock::RpoNumber GetRpo(BasicBlock* block) { static RpoNumber GetRpo(const BasicBlock* block) {
if (block == NULL) return BasicBlock::RpoNumber::Invalid(); if (block == NULL) return RpoNumber::Invalid();
return block->GetRpoNumber(); return RpoNumber::FromInt(block->rpo_number());
} }
static BasicBlock::RpoNumber GetLoopEndRpo(const BasicBlock* block) { static RpoNumber GetLoopEndRpo(const BasicBlock* block) {
if (!block->IsLoopHeader()) return BasicBlock::RpoNumber::Invalid(); if (!block->IsLoopHeader()) return RpoNumber::Invalid();
return block->loop_end()->GetRpoNumber(); return RpoNumber::FromInt(block->loop_end()->rpo_number());
} }
static InstructionBlock* InstructionBlockFor(Zone* zone, static InstructionBlock* InstructionBlockFor(Zone* zone,
const BasicBlock* block) { const BasicBlock* block) {
InstructionBlock* instr_block = new (zone) InstructionBlock( InstructionBlock* instr_block = new (zone)
zone, block->id(), block->GetRpoNumber(), GetRpo(block->loop_header()), InstructionBlock(zone, GetRpo(block), GetRpo(block->loop_header()),
GetLoopEndRpo(block), block->deferred()); GetLoopEndRpo(block), block->deferred());
// Map successors and precessors // Map successors and precessors
instr_block->successors().reserve(block->SuccessorCount()); instr_block->successors().reserve(block->SuccessorCount());
for (BasicBlock* successor : block->successors()) { for (BasicBlock* successor : block->successors()) {
instr_block->successors().push_back(successor->GetRpoNumber()); instr_block->successors().push_back(GetRpo(successor));
} }
instr_block->predecessors().reserve(block->PredecessorCount()); instr_block->predecessors().reserve(block->PredecessorCount());
for (BasicBlock* predecessor : block->predecessors()) { for (BasicBlock* predecessor : block->predecessors()) {
instr_block->predecessors().push_back(predecessor->GetRpoNumber()); instr_block->predecessors().push_back(GetRpo(predecessor));
} }
return instr_block; return instr_block;
} }
...@@ -443,7 +440,7 @@ InstructionBlocks* InstructionSequence::InstructionBlocksFor( ...@@ -443,7 +440,7 @@ InstructionBlocks* InstructionSequence::InstructionBlocksFor(
for (BasicBlockVector::const_iterator it = schedule->rpo_order()->begin(); for (BasicBlockVector::const_iterator it = schedule->rpo_order()->begin();
it != schedule->rpo_order()->end(); ++it, ++rpo_number) { it != schedule->rpo_order()->end(); ++it, ++rpo_number) {
DCHECK(!(*blocks)[rpo_number]); DCHECK(!(*blocks)[rpo_number]);
DCHECK((*it)->GetRpoNumber().ToSize() == rpo_number); DCHECK(GetRpo(*it).ToSize() == rpo_number);
(*blocks)[rpo_number] = InstructionBlockFor(zone, *it); (*blocks)[rpo_number] = InstructionBlockFor(zone, *it);
} }
ComputeAssemblyOrder(blocks); ComputeAssemblyOrder(blocks);
...@@ -455,12 +452,12 @@ void InstructionSequence::ComputeAssemblyOrder(InstructionBlocks* blocks) { ...@@ -455,12 +452,12 @@ void InstructionSequence::ComputeAssemblyOrder(InstructionBlocks* blocks) {
int ao = 0; int ao = 0;
for (auto const block : *blocks) { for (auto const block : *blocks) {
if (!block->IsDeferred()) { if (!block->IsDeferred()) {
block->set_ao_number(BasicBlock::RpoNumber::FromInt(ao++)); block->set_ao_number(RpoNumber::FromInt(ao++));
} }
} }
for (auto const block : *blocks) { for (auto const block : *blocks) {
if (block->IsDeferred()) { if (block->IsDeferred()) {
block->set_ao_number(BasicBlock::RpoNumber::FromInt(ao++)); block->set_ao_number(RpoNumber::FromInt(ao++));
} }
} }
} }
...@@ -493,14 +490,13 @@ int InstructionSequence::NextVirtualRegister() { ...@@ -493,14 +490,13 @@ int InstructionSequence::NextVirtualRegister() {
} }
GapInstruction* InstructionSequence::GetBlockStart( GapInstruction* InstructionSequence::GetBlockStart(RpoNumber rpo) const {
BasicBlock::RpoNumber rpo) const {
const InstructionBlock* block = InstructionBlockAt(rpo); const InstructionBlock* block = InstructionBlockAt(rpo);
return GapInstruction::cast(InstructionAt(block->code_start())); return GapInstruction::cast(InstructionAt(block->code_start()));
} }
void InstructionSequence::StartBlock(BasicBlock::RpoNumber rpo) { void InstructionSequence::StartBlock(RpoNumber rpo) {
DCHECK(block_starts_.size() == rpo.ToSize()); DCHECK(block_starts_.size() == rpo.ToSize());
InstructionBlock* block = InstructionBlockAt(rpo); InstructionBlock* block = InstructionBlockAt(rpo);
int code_start = static_cast<int>(instructions_.size()); int code_start = static_cast<int>(instructions_.size());
...@@ -509,7 +505,7 @@ void InstructionSequence::StartBlock(BasicBlock::RpoNumber rpo) { ...@@ -509,7 +505,7 @@ void InstructionSequence::StartBlock(BasicBlock::RpoNumber rpo) {
} }
void InstructionSequence::EndBlock(BasicBlock::RpoNumber rpo) { void InstructionSequence::EndBlock(RpoNumber rpo) {
int end = static_cast<int>(instructions_.size()); int end = static_cast<int>(instructions_.size());
InstructionBlock* block = InstructionBlockAt(rpo); InstructionBlock* block = InstructionBlockAt(rpo);
if (block->code_start() == end) { // Empty block. Insert a nop. if (block->code_start() == end) { // Empty block. Insert a nop.
...@@ -668,6 +664,11 @@ void FrameStateDescriptor::SetType(size_t index, MachineType type) { ...@@ -668,6 +664,11 @@ void FrameStateDescriptor::SetType(size_t index, MachineType type) {
} }
std::ostream& operator<<(std::ostream& os, const RpoNumber& rpo) {
return os << rpo.ToSize();
}
std::ostream& operator<<(std::ostream& os, std::ostream& operator<<(std::ostream& os,
const PrintableInstructionSequence& printable) { const PrintableInstructionSequence& printable) {
const InstructionSequence& code = *printable.sequence_; const InstructionSequence& code = *printable.sequence_;
...@@ -681,13 +682,12 @@ std::ostream& operator<<(std::ostream& os, ...@@ -681,13 +682,12 @@ std::ostream& operator<<(std::ostream& os,
os << "CST#" << i << ": v" << it->first << " = " << it->second << "\n"; os << "CST#" << i << ": v" << it->first << " = " << it->second << "\n";
} }
for (int i = 0; i < code.InstructionBlockCount(); i++) { for (int i = 0; i < code.InstructionBlockCount(); i++) {
BasicBlock::RpoNumber rpo = BasicBlock::RpoNumber::FromInt(i); RpoNumber rpo = RpoNumber::FromInt(i);
const InstructionBlock* block = code.InstructionBlockAt(rpo); const InstructionBlock* block = code.InstructionBlockAt(rpo);
CHECK(block->rpo_number() == rpo); CHECK(block->rpo_number() == rpo);
os << "RPO#" << block->rpo_number(); os << "B" << block->rpo_number();
os << ": AO#" << block->ao_number(); os << ": AO#" << block->ao_number();
os << ": B" << block->id();
if (block->IsDeferred()) os << " (deferred)"; if (block->IsDeferred()) os << " (deferred)";
if (block->IsLoopHeader()) { if (block->IsLoopHeader()) {
os << " loop blocks: [" << block->rpo_number() << ", " os << " loop blocks: [" << block->rpo_number() << ", "
...@@ -697,8 +697,7 @@ std::ostream& operator<<(std::ostream& os, ...@@ -697,8 +697,7 @@ std::ostream& operator<<(std::ostream& os,
<< block->code_end() << ")\n predecessors:"; << block->code_end() << ")\n predecessors:";
for (auto pred : block->predecessors()) { for (auto pred : block->predecessors()) {
const InstructionBlock* pred_block = code.InstructionBlockAt(pred); os << " B" << pred.ToInt();
os << " B" << pred_block->id();
} }
os << "\n"; os << "\n";
...@@ -725,8 +724,7 @@ std::ostream& operator<<(std::ostream& os, ...@@ -725,8 +724,7 @@ std::ostream& operator<<(std::ostream& os,
} }
for (auto succ : block->successors()) { for (auto succ : block->successors()) {
const InstructionBlock* succ_block = code.InstructionBlockAt(succ); os << " B" << succ.ToInt();
os << " B" << succ_block->id();
} }
os << "\n"; os << "\n";
} }
......
...@@ -15,7 +15,6 @@ ...@@ -15,7 +15,6 @@
#include "src/compiler/instruction-codes.h" #include "src/compiler/instruction-codes.h"
#include "src/compiler/opcodes.h" #include "src/compiler/opcodes.h"
#include "src/compiler/register-configuration.h" #include "src/compiler/register-configuration.h"
#include "src/compiler/schedule.h"
#include "src/compiler/source-position.h" #include "src/compiler/source-position.h"
#include "src/zone-allocator.h" #include "src/zone-allocator.h"
...@@ -23,6 +22,8 @@ namespace v8 { ...@@ -23,6 +22,8 @@ namespace v8 {
namespace internal { namespace internal {
namespace compiler { namespace compiler {
class Schedule;
// A couple of reserved opcodes are used for internal use. // A couple of reserved opcodes are used for internal use.
const InstructionCode kGapInstruction = -1; const InstructionCode kGapInstruction = -1;
const InstructionCode kSourcePositionInstruction = -2; const InstructionCode kSourcePositionInstruction = -2;
...@@ -691,6 +692,39 @@ class SourcePositionInstruction FINAL : public Instruction { ...@@ -691,6 +692,39 @@ class SourcePositionInstruction FINAL : public Instruction {
}; };
class RpoNumber FINAL {
public:
static const int kInvalidRpoNumber = -1;
int ToInt() const {
DCHECK(IsValid());
return index_;
}
size_t ToSize() const {
DCHECK(IsValid());
return static_cast<size_t>(index_);
}
bool IsValid() const { return index_ >= 0; }
static RpoNumber FromInt(int index) { return RpoNumber(index); }
static RpoNumber Invalid() { return RpoNumber(kInvalidRpoNumber); }
bool IsNext(const RpoNumber other) const {
DCHECK(IsValid());
return other.index_ == this->index_ + 1;
}
bool operator==(RpoNumber other) const {
return this->index_ == other.index_;
}
private:
explicit RpoNumber(int32_t index) : index_(index) {}
int32_t index_;
};
std::ostream& operator<<(std::ostream&, const RpoNumber&);
class Constant FINAL { class Constant FINAL {
public: public:
enum Type { enum Type {
...@@ -711,8 +745,7 @@ class Constant FINAL { ...@@ -711,8 +745,7 @@ class Constant FINAL {
: type_(kExternalReference), value_(bit_cast<intptr_t>(ref)) {} : type_(kExternalReference), value_(bit_cast<intptr_t>(ref)) {}
explicit Constant(Handle<HeapObject> obj) explicit Constant(Handle<HeapObject> obj)
: type_(kHeapObject), value_(bit_cast<intptr_t>(obj)) {} : type_(kHeapObject), value_(bit_cast<intptr_t>(obj)) {}
explicit Constant(BasicBlock::RpoNumber rpo) explicit Constant(RpoNumber rpo) : type_(kRpoNumber), value_(rpo.ToInt()) {}
: type_(kRpoNumber), value_(rpo.ToInt()) {}
Type type() const { return type_; } Type type() const { return type_; }
...@@ -745,9 +778,9 @@ class Constant FINAL { ...@@ -745,9 +778,9 @@ class Constant FINAL {
return bit_cast<ExternalReference>(static_cast<intptr_t>(value_)); return bit_cast<ExternalReference>(static_cast<intptr_t>(value_));
} }
BasicBlock::RpoNumber ToRpoNumber() const { RpoNumber ToRpoNumber() const {
DCHECK_EQ(kRpoNumber, type()); DCHECK_EQ(kRpoNumber, type());
return BasicBlock::RpoNumber::FromInt(static_cast<int>(value_)); return RpoNumber::FromInt(static_cast<int>(value_));
} }
Handle<HeapObject> ToHeapObject() const { Handle<HeapObject> ToHeapObject() const {
...@@ -831,10 +864,8 @@ class PhiInstruction FINAL : public ZoneObject { ...@@ -831,10 +864,8 @@ class PhiInstruction FINAL : public ZoneObject {
// Analogue of BasicBlock for Instructions instead of Nodes. // Analogue of BasicBlock for Instructions instead of Nodes.
class InstructionBlock FINAL : public ZoneObject { class InstructionBlock FINAL : public ZoneObject {
public: public:
InstructionBlock(Zone* zone, BasicBlock::Id id, InstructionBlock(Zone* zone, RpoNumber rpo_number, RpoNumber loop_header,
BasicBlock::RpoNumber rpo_number, RpoNumber loop_end, bool deferred);
BasicBlock::RpoNumber loop_header,
BasicBlock::RpoNumber loop_end, bool deferred);
// Instruction indexes (used by the register allocator). // Instruction indexes (used by the register allocator).
int first_instruction_index() const { int first_instruction_index() const {
...@@ -858,23 +889,22 @@ class InstructionBlock FINAL : public ZoneObject { ...@@ -858,23 +889,22 @@ class InstructionBlock FINAL : public ZoneObject {
bool IsDeferred() const { return deferred_; } bool IsDeferred() const { return deferred_; }
BasicBlock::Id id() const { return id_; } RpoNumber ao_number() const { return ao_number_; }
BasicBlock::RpoNumber ao_number() const { return ao_number_; } RpoNumber rpo_number() const { return rpo_number_; }
BasicBlock::RpoNumber rpo_number() const { return rpo_number_; } RpoNumber loop_header() const { return loop_header_; }
BasicBlock::RpoNumber loop_header() const { return loop_header_; } RpoNumber loop_end() const {
BasicBlock::RpoNumber loop_end() const {
DCHECK(IsLoopHeader()); DCHECK(IsLoopHeader());
return loop_end_; return loop_end_;
} }
inline bool IsLoopHeader() const { return loop_end_.IsValid(); } inline bool IsLoopHeader() const { return loop_end_.IsValid(); }
typedef ZoneVector<BasicBlock::RpoNumber> Predecessors; typedef ZoneVector<RpoNumber> Predecessors;
Predecessors& predecessors() { return predecessors_; } Predecessors& predecessors() { return predecessors_; }
const Predecessors& predecessors() const { return predecessors_; } const Predecessors& predecessors() const { return predecessors_; }
size_t PredecessorCount() const { return predecessors_.size(); } size_t PredecessorCount() const { return predecessors_.size(); }
size_t PredecessorIndexOf(BasicBlock::RpoNumber rpo_number) const; size_t PredecessorIndexOf(RpoNumber rpo_number) const;
typedef ZoneVector<BasicBlock::RpoNumber> Successors; typedef ZoneVector<RpoNumber> Successors;
Successors& successors() { return successors_; } Successors& successors() { return successors_; }
const Successors& successors() const { return successors_; } const Successors& successors() const { return successors_; }
size_t SuccessorCount() const { return successors_.size(); } size_t SuccessorCount() const { return successors_.size(); }
...@@ -883,19 +913,16 @@ class InstructionBlock FINAL : public ZoneObject { ...@@ -883,19 +913,16 @@ class InstructionBlock FINAL : public ZoneObject {
const PhiInstructions& phis() const { return phis_; } const PhiInstructions& phis() const { return phis_; }
void AddPhi(PhiInstruction* phi) { phis_.push_back(phi); } void AddPhi(PhiInstruction* phi) { phis_.push_back(phi); }
void set_ao_number(BasicBlock::RpoNumber ao_number) { void set_ao_number(RpoNumber ao_number) { ao_number_ = ao_number; }
ao_number_ = ao_number;
}
private: private:
Successors successors_; Successors successors_;
Predecessors predecessors_; Predecessors predecessors_;
PhiInstructions phis_; PhiInstructions phis_;
const BasicBlock::Id id_; RpoNumber ao_number_; // Assembly order number.
BasicBlock::RpoNumber ao_number_; // Assembly order number. const RpoNumber rpo_number_;
const BasicBlock::RpoNumber rpo_number_; const RpoNumber loop_header_;
const BasicBlock::RpoNumber loop_header_; const RpoNumber loop_end_;
const BasicBlock::RpoNumber loop_end_;
int32_t code_start_; // start index of arch-specific code. int32_t code_start_; // start index of arch-specific code.
int32_t code_end_; // end index of arch-specific code. int32_t code_end_; // end index of arch-specific code.
const bool deferred_; // Block contains deferred code. const bool deferred_; // Block contains deferred code.
...@@ -937,7 +964,7 @@ class InstructionSequence FINAL : public ZoneObject { ...@@ -937,7 +964,7 @@ class InstructionSequence FINAL : public ZoneObject {
return static_cast<int>(instruction_blocks_->size()); return static_cast<int>(instruction_blocks_->size());
} }
InstructionBlock* InstructionBlockAt(BasicBlock::RpoNumber rpo_number) { InstructionBlock* InstructionBlockAt(RpoNumber rpo_number) {
return instruction_blocks_->at(rpo_number.ToSize()); return instruction_blocks_->at(rpo_number.ToSize());
} }
...@@ -946,8 +973,7 @@ class InstructionSequence FINAL : public ZoneObject { ...@@ -946,8 +973,7 @@ class InstructionSequence FINAL : public ZoneObject {
->last_instruction_index(); ->last_instruction_index();
} }
const InstructionBlock* InstructionBlockAt( const InstructionBlock* InstructionBlockAt(RpoNumber rpo_number) const {
BasicBlock::RpoNumber rpo_number) const {
return instruction_blocks_->at(rpo_number.ToSize()); return instruction_blocks_->at(rpo_number.ToSize());
} }
...@@ -961,7 +987,7 @@ class InstructionSequence FINAL : public ZoneObject { ...@@ -961,7 +987,7 @@ class InstructionSequence FINAL : public ZoneObject {
void AddGapMove(int index, InstructionOperand* from, InstructionOperand* to); void AddGapMove(int index, InstructionOperand* from, InstructionOperand* to);
GapInstruction* GetBlockStart(BasicBlock::RpoNumber rpo) const; GapInstruction* GetBlockStart(RpoNumber rpo) const;
typedef InstructionDeque::const_iterator const_iterator; typedef InstructionDeque::const_iterator const_iterator;
const_iterator begin() const { return instructions_.begin(); } const_iterator begin() const { return instructions_.begin(); }
...@@ -984,8 +1010,8 @@ class InstructionSequence FINAL : public ZoneObject { ...@@ -984,8 +1010,8 @@ class InstructionSequence FINAL : public ZoneObject {
// 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::RpoNumber rpo); void StartBlock(RpoNumber rpo);
void EndBlock(BasicBlock::RpoNumber rpo); void EndBlock(RpoNumber rpo);
int AddConstant(int virtual_register, Constant constant) { int AddConstant(int virtual_register, Constant constant) {
// TODO(titzer): allow RPO numbers as constants? // TODO(titzer): allow RPO numbers as constants?
...@@ -1030,7 +1056,7 @@ class InstructionSequence FINAL : public ZoneObject { ...@@ -1030,7 +1056,7 @@ class InstructionSequence FINAL : public ZoneObject {
FrameStateDescriptor* GetFrameStateDescriptor(StateId deoptimization_id); FrameStateDescriptor* GetFrameStateDescriptor(StateId deoptimization_id);
int GetFrameStateDescriptorCount(); int GetFrameStateDescriptorCount();
BasicBlock::RpoNumber InputRpo(Instruction* instr, size_t index) { RpoNumber InputRpo(Instruction* instr, size_t index) {
InstructionOperand* operand = instr->InputAt(index); InstructionOperand* operand = instr->InputAt(index);
Constant constant = operand->IsImmediate() ? GetImmediate(operand->index()) Constant constant = operand->IsImmediate() ? GetImmediate(operand->index())
: GetConstant(operand->index()); : GetConstant(operand->index());
......
...@@ -9,8 +9,6 @@ namespace v8 { ...@@ -9,8 +9,6 @@ namespace v8 {
namespace internal { namespace internal {
namespace compiler { namespace compiler {
typedef BasicBlock::RpoNumber RpoNumber;
#define TRACE(x) \ #define TRACE(x) \
if (FLAG_trace_turbo_jt) PrintF x if (FLAG_trace_turbo_jt) PrintF x
...@@ -70,8 +68,8 @@ bool JumpThreading::ComputeForwarding(Zone* local_zone, ...@@ -70,8 +68,8 @@ bool JumpThreading::ComputeForwarding(Zone* local_zone,
while (!state.stack.empty()) { while (!state.stack.empty()) {
InstructionBlock* block = code->InstructionBlockAt(state.stack.top()); InstructionBlock* block = code->InstructionBlockAt(state.stack.top());
// Process the instructions in a block up to a non-empty instruction. // Process the instructions in a block up to a non-empty instruction.
TRACE(("jt [%d] B%d RPO%d\n", static_cast<int>(stack.size()), TRACE(("jt [%d] B%d\n", static_cast<int>(stack.size()),
block->id().ToInt(), block->rpo_number().ToInt())); block->rpo_number().ToInt()));
bool fallthru = true; bool fallthru = true;
RpoNumber fw = block->rpo_number(); RpoNumber fw = block->rpo_number();
for (int i = block->code_start(); i < block->code_end(); ++i) { for (int i = block->code_start(); i < block->code_end(); ++i) {
...@@ -120,12 +118,10 @@ bool JumpThreading::ComputeForwarding(Zone* local_zone, ...@@ -120,12 +118,10 @@ bool JumpThreading::ComputeForwarding(Zone* local_zone,
if (FLAG_trace_turbo_jt) { if (FLAG_trace_turbo_jt) {
for (int i = 0; i < static_cast<int>(result.size()); i++) { for (int i = 0; i < static_cast<int>(result.size()); i++) {
TRACE(("RPO%d B%d ", i, TRACE(("B%d ", i));
code->InstructionBlockAt(RpoNumber::FromInt(i))->id().ToInt()));
int to = result[i].ToInt(); int to = result[i].ToInt();
if (i != to) { if (i != to) {
TRACE(("-> B%d\n", TRACE(("-> B%d\n", to));
code->InstructionBlockAt(RpoNumber::FromInt(to))->id().ToInt()));
} else { } else {
TRACE(("\n")); TRACE(("\n"));
} }
......
...@@ -17,13 +17,12 @@ class JumpThreading { ...@@ -17,13 +17,12 @@ class JumpThreading {
public: public:
// Compute the forwarding map of basic blocks to their ultimate destination. // Compute the forwarding map of basic blocks to their ultimate destination.
// Returns {true} if there is at least one block that is forwarded. // Returns {true} if there is at least one block that is forwarded.
static bool ComputeForwarding(Zone* local_zone, static bool ComputeForwarding(Zone* local_zone, ZoneVector<RpoNumber>& result,
ZoneVector<BasicBlock::RpoNumber>& result,
InstructionSequence* code); InstructionSequence* code);
// Rewrite the instructions to forward jumps and branches. // Rewrite the instructions to forward jumps and branches.
// May also negate some branches. // May also negate some branches.
static void ApplyForwarding(ZoneVector<BasicBlock::RpoNumber>& forwarding, static void ApplyForwarding(ZoneVector<RpoNumber>& forwarding,
InstructionSequence* code); InstructionSequence* code);
}; };
......
...@@ -803,7 +803,7 @@ void CodeGenerator::AssembleArchBranch(Instruction* instr, BranchInfo* branch) { ...@@ -803,7 +803,7 @@ void CodeGenerator::AssembleArchBranch(Instruction* instr, BranchInfo* branch) {
} }
void CodeGenerator::AssembleArchJump(BasicBlock::RpoNumber target) { void CodeGenerator::AssembleArchJump(RpoNumber target) {
if (!IsNextInAssemblyOrder(target)) __ Branch(GetLabel(target)); if (!IsNextInAssemblyOrder(target)) __ Branch(GetLabel(target));
} }
......
...@@ -917,7 +917,7 @@ void CodeGenerator::AssembleArchBranch(Instruction* instr, BranchInfo* branch) { ...@@ -917,7 +917,7 @@ void CodeGenerator::AssembleArchBranch(Instruction* instr, BranchInfo* branch) {
} }
void CodeGenerator::AssembleArchJump(BasicBlock::RpoNumber target) { void CodeGenerator::AssembleArchJump(RpoNumber target) {
if (!IsNextInAssemblyOrder(target)) __ Branch(GetLabel(target)); if (!IsNextInAssemblyOrder(target)) __ Branch(GetLabel(target));
} }
......
...@@ -746,7 +746,7 @@ struct JumpThreadingPhase { ...@@ -746,7 +746,7 @@ struct JumpThreadingPhase {
static const char* phase_name() { return "jump threading"; } static const char* phase_name() { return "jump threading"; }
void Run(PipelineData* data, Zone* temp_zone) { void Run(PipelineData* data, Zone* temp_zone) {
ZoneVector<BasicBlock::RpoNumber> result(temp_zone); ZoneVector<RpoNumber> result(temp_zone);
if (JumpThreading::ComputeForwarding(temp_zone, result, data->sequence())) { if (JumpThreading::ComputeForwarding(temp_zone, result, data->sequence())) {
JumpThreading::ApplyForwarding(result, data->sequence()); JumpThreading::ApplyForwarding(result, data->sequence());
} }
......
...@@ -1016,7 +1016,7 @@ void CodeGenerator::AssembleArchBranch(Instruction* instr, BranchInfo* branch) { ...@@ -1016,7 +1016,7 @@ void CodeGenerator::AssembleArchBranch(Instruction* instr, BranchInfo* branch) {
} }
void CodeGenerator::AssembleArchJump(BasicBlock::RpoNumber target) { void CodeGenerator::AssembleArchJump(RpoNumber target) {
if (!IsNextInAssemblyOrder(target)) __ b(GetLabel(target)); if (!IsNextInAssemblyOrder(target)) __ b(GetLabel(target));
} }
......
...@@ -214,7 +214,7 @@ void RegisterAllocatorVerifier::CheckConstraint( ...@@ -214,7 +214,7 @@ void RegisterAllocatorVerifier::CheckConstraint(
namespace { namespace {
typedef BasicBlock::RpoNumber Rpo; typedef RpoNumber Rpo;
static const int kInvalidVreg = InstructionOperand::kInvalidVirtualRegister; static const int kInvalidVreg = InstructionOperand::kInvalidVirtualRegister;
......
...@@ -1706,8 +1706,7 @@ void RegisterAllocator::BuildLiveRanges() { ...@@ -1706,8 +1706,7 @@ void RegisterAllocator::BuildLiveRanges() {
// Process the blocks in reverse order. // Process the blocks in reverse order.
for (int block_id = code()->InstructionBlockCount() - 1; block_id >= 0; for (int block_id = code()->InstructionBlockCount() - 1; block_id >= 0;
--block_id) { --block_id) {
auto block = auto block = code()->InstructionBlockAt(RpoNumber::FromInt(block_id));
code()->InstructionBlockAt(BasicBlock::RpoNumber::FromInt(block_id));
auto live = ComputeLiveOut(block); auto live = ComputeLiveOut(block);
// Initially consider all live_out values live for the entire block. We // Initially consider all live_out values live for the entire block. We
// will shorten these intervals if necessary. // will shorten these intervals if necessary.
......
...@@ -121,11 +121,6 @@ std::ostream& operator<<(std::ostream& os, const BasicBlock::Id& id) { ...@@ -121,11 +121,6 @@ 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),
...@@ -319,14 +314,14 @@ void Schedule::SetBlockForNode(BasicBlock* block, Node* node) { ...@@ -319,14 +314,14 @@ void Schedule::SetBlockForNode(BasicBlock* block, Node* node) {
std::ostream& operator<<(std::ostream& os, const Schedule& s) { std::ostream& operator<<(std::ostream& os, const Schedule& s) {
for (BasicBlock* block : *s.rpo_order()) { for (BasicBlock* block : *s.rpo_order()) {
os << "--- BLOCK B" << block->id(); os << "--- BLOCK B" << block->rpo_number();
if (block->deferred()) os << " (deferred)"; if (block->deferred()) os << " (deferred)";
if (block->PredecessorCount() != 0) os << " <- "; if (block->PredecessorCount() != 0) os << " <- ";
bool comma = false; bool comma = false;
for (BasicBlock const* predecessor : block->predecessors()) { for (BasicBlock const* predecessor : block->predecessors()) {
if (comma) os << ", "; if (comma) os << ", ";
comma = true; comma = true;
os << "B" << predecessor->id(); os << "B" << predecessor->rpo_number();
} }
os << " ---\n"; os << " ---\n";
for (Node* node : *block) { for (Node* node : *block) {
...@@ -355,7 +350,7 @@ std::ostream& operator<<(std::ostream& os, const Schedule& s) { ...@@ -355,7 +350,7 @@ std::ostream& operator<<(std::ostream& os, const Schedule& s) {
for (BasicBlock const* successor : block->successors()) { for (BasicBlock const* successor : block->successors()) {
if (comma) os << ", "; if (comma) os << ", ";
comma = true; comma = true;
os << "B" << successor->id(); os << "B" << successor->rpo_number();
} }
os << "\n"; os << "\n";
} }
......
...@@ -51,35 +51,6 @@ class BasicBlock FINAL : public ZoneObject { ...@@ -51,35 +51,6 @@ class BasicBlock FINAL : public ZoneObject {
size_t index_; size_t index_;
}; };
static const int kInvalidRpoNumber = -1;
class RpoNumber FINAL {
public:
int ToInt() const {
DCHECK(IsValid());
return index_;
}
size_t ToSize() const {
DCHECK(IsValid());
return static_cast<size_t>(index_);
}
bool IsValid() const { return index_ >= 0; }
static RpoNumber FromInt(int index) { return RpoNumber(index); }
static RpoNumber Invalid() { return RpoNumber(kInvalidRpoNumber); }
bool IsNext(const RpoNumber other) const {
DCHECK(IsValid());
return other.index_ == this->index_ + 1;
}
bool operator==(RpoNumber other) const {
return this->index_ == other.index_;
}
private:
explicit RpoNumber(int32_t index) : index_(index) {}
int32_t index_;
};
BasicBlock(Zone* zone, Id id); BasicBlock(Zone* zone, Id id);
Id id() const { return id_; } Id id() const { return id_; }
...@@ -160,7 +131,6 @@ class BasicBlock FINAL : public ZoneObject { ...@@ -160,7 +131,6 @@ class BasicBlock FINAL : public ZoneObject {
int32_t loop_number() const { return loop_number_; } int32_t loop_number() const { return loop_number_; }
void set_loop_number(int32_t loop_number) { loop_number_ = loop_number; } void set_loop_number(int32_t loop_number) { loop_number_ = loop_number; }
RpoNumber GetRpoNumber() const { return RpoNumber::FromInt(rpo_number_); }
int32_t rpo_number() const { return rpo_number_; } int32_t rpo_number() const { return rpo_number_; }
void set_rpo_number(int32_t rpo_number); void set_rpo_number(int32_t rpo_number);
...@@ -198,7 +168,6 @@ class BasicBlock FINAL : public ZoneObject { ...@@ -198,7 +168,6 @@ class BasicBlock FINAL : public ZoneObject {
std::ostream& operator<<(std::ostream&, const BasicBlock::Control&); std::ostream& operator<<(std::ostream&, const BasicBlock::Control&);
std::ostream& operator<<(std::ostream&, const BasicBlock::Id&); std::ostream& operator<<(std::ostream&, const BasicBlock::Id&);
std::ostream& operator<<(std::ostream&, const BasicBlock::RpoNumber&);
// A schedule represents the result of assigning nodes to basic blocks // A schedule represents the result of assigning nodes to basic blocks
......
...@@ -865,7 +865,7 @@ static void CheckInputsDominate(Schedule* schedule, BasicBlock* block, ...@@ -865,7 +865,7 @@ static void CheckInputsDominate(Schedule* schedule, BasicBlock* block,
use_pos)) { use_pos)) {
V8_Fatal(__FILE__, __LINE__, V8_Fatal(__FILE__, __LINE__,
"Node #%d:%s in B%d is not dominated by input@%d #%d:%s", "Node #%d:%s in B%d is not dominated by input@%d #%d:%s",
node->id(), node->op()->mnemonic(), block->id().ToInt(), j, node->id(), node->op()->mnemonic(), block->rpo_number(), j,
input->id(), input->op()->mnemonic()); input->id(), input->op()->mnemonic());
} }
} }
...@@ -878,8 +878,8 @@ static void CheckInputsDominate(Schedule* schedule, BasicBlock* block, ...@@ -878,8 +878,8 @@ static void CheckInputsDominate(Schedule* schedule, BasicBlock* block,
if (!Dominates(schedule, ctl, node)) { if (!Dominates(schedule, ctl, node)) {
V8_Fatal(__FILE__, __LINE__, V8_Fatal(__FILE__, __LINE__,
"Node #%d:%s in B%d is not dominated by control input #%d:%s", "Node #%d:%s in B%d is not dominated by control input #%d:%s",
node->id(), node->op()->mnemonic(), block->id(), ctl->id(), node->id(), node->op()->mnemonic(), block->rpo_number(),
ctl->op()->mnemonic()); ctl->id(), ctl->op()->mnemonic());
} }
} }
} }
...@@ -973,7 +973,7 @@ void ScheduleVerifier::Run(Schedule* schedule) { ...@@ -973,7 +973,7 @@ void ScheduleVerifier::Run(Schedule* schedule) {
BasicBlock* idom = block->dominator(); BasicBlock* idom = block->dominator();
if (idom != NULL && !block_doms->Contains(idom->id().ToInt())) { if (idom != NULL && !block_doms->Contains(idom->id().ToInt())) {
V8_Fatal(__FILE__, __LINE__, "Block B%d is not dominated by B%d", V8_Fatal(__FILE__, __LINE__, "Block B%d is not dominated by B%d",
block->id().ToInt(), idom->id().ToInt()); block->rpo_number(), idom->rpo_number());
} }
for (size_t s = 0; s < block->SuccessorCount(); s++) { for (size_t s = 0; s < block->SuccessorCount(); s++) {
BasicBlock* succ = block->SuccessorAt(s); BasicBlock* succ = block->SuccessorAt(s);
...@@ -1011,7 +1011,7 @@ void ScheduleVerifier::Run(Schedule* schedule) { ...@@ -1011,7 +1011,7 @@ void ScheduleVerifier::Run(Schedule* schedule) {
!dominators[idom->id().ToSize()]->Contains(dom->id().ToInt())) { !dominators[idom->id().ToSize()]->Contains(dom->id().ToInt())) {
V8_Fatal(__FILE__, __LINE__, V8_Fatal(__FILE__, __LINE__,
"Block B%d is not immediately dominated by B%d", "Block B%d is not immediately dominated by B%d",
block->id().ToInt(), idom->id().ToInt()); block->rpo_number(), idom->rpo_number());
} }
} }
} }
......
...@@ -1066,7 +1066,7 @@ void CodeGenerator::AssembleArchBranch(Instruction* instr, BranchInfo* branch) { ...@@ -1066,7 +1066,7 @@ void CodeGenerator::AssembleArchBranch(Instruction* instr, BranchInfo* branch) {
} }
void CodeGenerator::AssembleArchJump(BasicBlock::RpoNumber target) { void CodeGenerator::AssembleArchJump(RpoNumber target) {
if (!IsNextInAssemblyOrder(target)) __ jmp(GetLabel(target)); if (!IsNextInAssemblyOrder(target)) __ jmp(GetLabel(target));
} }
......
...@@ -93,8 +93,12 @@ class InstructionTester : public HandleAndZoneScope { ...@@ -93,8 +93,12 @@ class InstructionTester : public HandleAndZoneScope {
return UnallocatedOperand(UnallocatedOperand::ANY, vreg).Copy(zone()); return UnallocatedOperand(UnallocatedOperand::ANY, vreg).Copy(zone());
} }
RpoNumber RpoFor(BasicBlock* block) {
return RpoNumber::FromInt(block->rpo_number());
}
InstructionBlock* BlockAt(BasicBlock* block) { InstructionBlock* BlockAt(BasicBlock* block) {
return code->InstructionBlockAt(block->GetRpoNumber()); return code->InstructionBlockAt(RpoFor(block));
} }
BasicBlock* GetBasicBlock(int instruction_index) { BasicBlock* GetBasicBlock(int instruction_index) {
const InstructionBlock* block = const InstructionBlock* block =
...@@ -131,7 +135,6 @@ TEST(InstructionBasic) { ...@@ -131,7 +135,6 @@ TEST(InstructionBasic) {
for (auto block : *blocks) { for (auto block : *blocks) {
CHECK_EQ(block->rpo_number(), R.BlockAt(block)->rpo_number().ToInt()); CHECK_EQ(block->rpo_number(), R.BlockAt(block)->rpo_number().ToInt());
CHECK_EQ(block->id().ToInt(), R.BlockAt(block)->id().ToInt());
CHECK(!block->loop_end()); CHECK(!block->loop_end());
} }
} }
...@@ -151,23 +154,23 @@ TEST(InstructionGetBasicBlock) { ...@@ -151,23 +154,23 @@ TEST(InstructionGetBasicBlock) {
R.allocCode(); R.allocCode();
R.code->StartBlock(b0->GetRpoNumber()); R.code->StartBlock(R.RpoFor(b0));
int i0 = R.NewInstr(); int i0 = R.NewInstr();
int i1 = R.NewInstr(); int i1 = R.NewInstr();
R.code->EndBlock(b0->GetRpoNumber()); R.code->EndBlock(R.RpoFor(b0));
R.code->StartBlock(b1->GetRpoNumber()); R.code->StartBlock(R.RpoFor(b1));
int i2 = R.NewInstr(); int i2 = R.NewInstr();
int i3 = R.NewInstr(); int i3 = R.NewInstr();
int i4 = R.NewInstr(); int i4 = R.NewInstr();
int i5 = R.NewInstr(); int i5 = R.NewInstr();
R.code->EndBlock(b1->GetRpoNumber()); R.code->EndBlock(R.RpoFor(b1));
R.code->StartBlock(b2->GetRpoNumber()); R.code->StartBlock(R.RpoFor(b2));
int i6 = R.NewInstr(); int i6 = R.NewInstr();
int i7 = R.NewInstr(); int i7 = R.NewInstr();
int i8 = R.NewInstr(); int i8 = R.NewInstr();
R.code->EndBlock(b2->GetRpoNumber()); R.code->EndBlock(R.RpoFor(b2));
R.code->StartBlock(b3->GetRpoNumber()); R.code->StartBlock(R.RpoFor(b3));
R.code->EndBlock(b3->GetRpoNumber()); R.code->EndBlock(R.RpoFor(b3));
CHECK_EQ(b0, R.GetBasicBlock(i0)); CHECK_EQ(b0, R.GetBasicBlock(i0));
CHECK_EQ(b0, R.GetBasicBlock(i1)); CHECK_EQ(b0, R.GetBasicBlock(i1));
...@@ -204,10 +207,10 @@ TEST(InstructionIsGapAt) { ...@@ -204,10 +207,10 @@ TEST(InstructionIsGapAt) {
R.allocCode(); R.allocCode();
TestInstr* i0 = TestInstr::New(R.zone(), 100); TestInstr* i0 = TestInstr::New(R.zone(), 100);
TestInstr* g = TestInstr::New(R.zone(), 103)->MarkAsControl(); TestInstr* g = TestInstr::New(R.zone(), 103)->MarkAsControl();
R.code->StartBlock(b0->GetRpoNumber()); R.code->StartBlock(R.RpoFor(b0));
R.code->AddInstruction(i0); R.code->AddInstruction(i0);
R.code->AddInstruction(g); R.code->AddInstruction(g);
R.code->EndBlock(b0->GetRpoNumber()); R.code->EndBlock(R.RpoFor(b0));
CHECK(R.code->instructions().size() == 4); CHECK(R.code->instructions().size() == 4);
for (size_t i = 0; i < R.code->instructions().size(); ++i) { for (size_t i = 0; i < R.code->instructions().size(); ++i) {
...@@ -227,17 +230,17 @@ TEST(InstructionIsGapAt2) { ...@@ -227,17 +230,17 @@ TEST(InstructionIsGapAt2) {
R.allocCode(); R.allocCode();
TestInstr* i0 = TestInstr::New(R.zone(), 100); TestInstr* i0 = TestInstr::New(R.zone(), 100);
TestInstr* g = TestInstr::New(R.zone(), 103)->MarkAsControl(); TestInstr* g = TestInstr::New(R.zone(), 103)->MarkAsControl();
R.code->StartBlock(b0->GetRpoNumber()); R.code->StartBlock(R.RpoFor(b0));
R.code->AddInstruction(i0); R.code->AddInstruction(i0);
R.code->AddInstruction(g); R.code->AddInstruction(g);
R.code->EndBlock(b0->GetRpoNumber()); R.code->EndBlock(R.RpoFor(b0));
TestInstr* i1 = TestInstr::New(R.zone(), 102); TestInstr* i1 = TestInstr::New(R.zone(), 102);
TestInstr* g1 = TestInstr::New(R.zone(), 104)->MarkAsControl(); TestInstr* g1 = TestInstr::New(R.zone(), 104)->MarkAsControl();
R.code->StartBlock(b1->GetRpoNumber()); R.code->StartBlock(R.RpoFor(b1));
R.code->AddInstruction(i1); R.code->AddInstruction(i1);
R.code->AddInstruction(g1); R.code->AddInstruction(g1);
R.code->EndBlock(b1->GetRpoNumber()); R.code->EndBlock(R.RpoFor(b1));
CHECK(R.code->instructions().size() == 8); CHECK(R.code->instructions().size() == 8);
for (size_t i = 0; i < R.code->instructions().size(); ++i) { for (size_t i = 0; i < R.code->instructions().size(); ++i) {
...@@ -255,10 +258,10 @@ TEST(InstructionAddGapMove) { ...@@ -255,10 +258,10 @@ TEST(InstructionAddGapMove) {
R.allocCode(); R.allocCode();
TestInstr* i0 = TestInstr::New(R.zone(), 100); TestInstr* i0 = TestInstr::New(R.zone(), 100);
TestInstr* g = TestInstr::New(R.zone(), 103)->MarkAsControl(); TestInstr* g = TestInstr::New(R.zone(), 103)->MarkAsControl();
R.code->StartBlock(b0->GetRpoNumber()); R.code->StartBlock(R.RpoFor(b0));
R.code->AddInstruction(i0); R.code->AddInstruction(i0);
R.code->AddInstruction(g); R.code->AddInstruction(g);
R.code->EndBlock(b0->GetRpoNumber()); R.code->EndBlock(R.RpoFor(b0));
CHECK(R.code->instructions().size() == 4); CHECK(R.code->instructions().size() == 4);
for (size_t i = 0; i < R.code->instructions().size(); ++i) { for (size_t i = 0; i < R.code->instructions().size(); ++i) {
......
...@@ -13,8 +13,6 @@ namespace v8 { ...@@ -13,8 +13,6 @@ namespace v8 {
namespace internal { namespace internal {
namespace compiler { namespace compiler {
typedef BasicBlock::RpoNumber RpoNumber;
class TestCode : public HandleAndZoneScope { class TestCode : public HandleAndZoneScope {
public: public:
TestCode() TestCode()
...@@ -87,9 +85,9 @@ class TestCode : public HandleAndZoneScope { ...@@ -87,9 +85,9 @@ class TestCode : public HandleAndZoneScope {
} }
void Start(bool deferred = false) { void Start(bool deferred = false) {
if (current_ == NULL) { if (current_ == NULL) {
current_ = new (main_zone()) InstructionBlock( current_ = new (main_zone())
main_zone(), BasicBlock::Id::FromInt(rpo_number_.ToInt()), InstructionBlock(main_zone(), rpo_number_, RpoNumber::Invalid(),
rpo_number_, RpoNumber::Invalid(), RpoNumber::Invalid(), deferred); RpoNumber::Invalid(), deferred);
blocks_.push_back(current_); blocks_.push_back(current_);
sequence_.StartBlock(rpo_number_); sequence_.StartBlock(rpo_number_);
} }
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#include "test/unittests/compiler/instruction-selector-unittest.h" #include "test/unittests/compiler/instruction-selector-unittest.h"
#include "src/compiler/graph.h" #include "src/compiler/graph.h"
#include "src/compiler/schedule.h"
#include "src/flags.h" #include "src/flags.h"
#include "test/unittests/compiler/compiler-test-utils.h" #include "test/unittests/compiler/compiler-test-utils.h"
......
...@@ -410,15 +410,14 @@ InstructionOperand InstructionSequenceTest::ConvertOutputOp(VReg vreg, ...@@ -410,15 +410,14 @@ InstructionOperand InstructionSequenceTest::ConvertOutputOp(VReg vreg,
InstructionBlock* InstructionSequenceTest::NewBlock() { InstructionBlock* InstructionSequenceTest::NewBlock() {
CHECK(current_block_ == nullptr); CHECK(current_block_ == nullptr);
auto block_id = BasicBlock::Id::FromSize(instruction_blocks_.size()); Rpo rpo = Rpo::FromInt(static_cast<int>(instruction_blocks_.size()));
Rpo rpo = Rpo::FromInt(block_id.ToInt());
Rpo loop_header = Rpo::Invalid(); Rpo loop_header = Rpo::Invalid();
Rpo loop_end = Rpo::Invalid(); Rpo loop_end = Rpo::Invalid();
if (!loop_blocks_.empty()) { if (!loop_blocks_.empty()) {
auto& loop_data = loop_blocks_.back(); auto& loop_data = loop_blocks_.back();
// This is a loop header. // This is a loop header.
if (!loop_data.loop_header_.IsValid()) { if (!loop_data.loop_header_.IsValid()) {
loop_end = Rpo::FromInt(block_id.ToInt() + loop_data.expected_blocks_); loop_end = Rpo::FromInt(rpo.ToInt() + loop_data.expected_blocks_);
loop_data.expected_blocks_--; loop_data.expected_blocks_--;
loop_data.loop_header_ = rpo; loop_data.loop_header_ = rpo;
} else { } else {
...@@ -430,8 +429,8 @@ InstructionBlock* InstructionSequenceTest::NewBlock() { ...@@ -430,8 +429,8 @@ InstructionBlock* InstructionSequenceTest::NewBlock() {
} }
} }
// Construct instruction block. // Construct instruction block.
auto instruction_block = new (zone()) auto instruction_block =
InstructionBlock(zone(), block_id, rpo, loop_header, loop_end, false); new (zone()) InstructionBlock(zone(), rpo, loop_header, loop_end, false);
instruction_blocks_.push_back(instruction_block); instruction_blocks_.push_back(instruction_block);
current_block_ = instruction_block; current_block_ = instruction_block;
sequence()->StartBlock(rpo); sequence()->StartBlock(rpo);
......
...@@ -18,7 +18,7 @@ class InstructionSequenceTest : public TestWithIsolateAndZone { ...@@ -18,7 +18,7 @@ class InstructionSequenceTest : public TestWithIsolateAndZone {
static const int kDefaultNRegs = 4; static const int kDefaultNRegs = 4;
static const int kNoValue = kMinInt; static const int kNoValue = kMinInt;
typedef BasicBlock::RpoNumber Rpo; typedef RpoNumber Rpo;
struct VReg { struct VReg {
VReg() : value_(kNoValue) {} VReg() : value_(kNoValue) {}
......
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