Commit 497c5373 authored by dcarney's avatar dcarney Committed by Commit bot

[turbofan] split register allocator into little pieces

R=titzer@chromium.org

BUG=

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

Cr-Commit-Position: refs/heads/master@{#27946}
parent f557d753
...@@ -407,7 +407,7 @@ class GraphC1Visualizer { ...@@ -407,7 +407,7 @@ class GraphC1Visualizer {
void PrintSchedule(const char* phase, const Schedule* schedule, void PrintSchedule(const char* phase, const Schedule* schedule,
const SourcePositionTable* positions, const SourcePositionTable* positions,
const InstructionSequence* instructions); const InstructionSequence* instructions);
void PrintAllocator(const char* phase, const RegisterAllocator* allocator); void PrintLiveRanges(const char* phase, const RegisterAllocationData* data);
Zone* zone() const { return zone_; } Zone* zone() const { return zone_; }
private: private:
...@@ -693,20 +693,20 @@ void GraphC1Visualizer::PrintSchedule(const char* phase, ...@@ -693,20 +693,20 @@ void GraphC1Visualizer::PrintSchedule(const char* phase,
} }
void GraphC1Visualizer::PrintAllocator(const char* phase, void GraphC1Visualizer::PrintLiveRanges(const char* phase,
const RegisterAllocator* allocator) { const RegisterAllocationData* data) {
Tag tag(this, "intervals"); Tag tag(this, "intervals");
PrintStringProperty("name", phase); PrintStringProperty("name", phase);
for (auto range : allocator->fixed_double_live_ranges()) { for (auto range : data->fixed_double_live_ranges()) {
PrintLiveRange(range, "fixed"); PrintLiveRange(range, "fixed");
} }
for (auto range : allocator->fixed_live_ranges()) { for (auto range : data->fixed_live_ranges()) {
PrintLiveRange(range, "fixed"); PrintLiveRange(range, "fixed");
} }
for (auto range : allocator->live_ranges()) { for (auto range : data->live_ranges()) {
PrintLiveRange(range, "object"); PrintLiveRange(range, "object");
} }
} }
...@@ -791,9 +791,10 @@ std::ostream& operator<<(std::ostream& os, const AsC1V& ac) { ...@@ -791,9 +791,10 @@ std::ostream& operator<<(std::ostream& os, const AsC1V& ac) {
} }
std::ostream& operator<<(std::ostream& os, const AsC1VAllocator& ac) { std::ostream& operator<<(std::ostream& os,
const AsC1VRegisterAllocationData& ac) {
Zone tmp_zone; Zone tmp_zone;
GraphC1Visualizer(os, &tmp_zone).PrintAllocator(ac.phase_, ac.allocator_); GraphC1Visualizer(os, &tmp_zone).PrintLiveRanges(ac.phase_, ac.data_);
return os; return os;
} }
......
...@@ -16,7 +16,7 @@ namespace compiler { ...@@ -16,7 +16,7 @@ namespace compiler {
class Graph; class Graph;
class InstructionSequence; class InstructionSequence;
class RegisterAllocator; class RegisterAllocationData;
class Schedule; class Schedule;
class SourcePositionTable; class SourcePositionTable;
...@@ -67,18 +67,19 @@ struct AsC1V { ...@@ -67,18 +67,19 @@ struct AsC1V {
const char* phase_; const char* phase_;
}; };
struct AsC1VAllocator { struct AsC1VRegisterAllocationData {
explicit AsC1VAllocator(const char* phase, explicit AsC1VRegisterAllocationData(
const RegisterAllocator* allocator = NULL) const char* phase, const RegisterAllocationData* data = nullptr)
: phase_(phase), allocator_(allocator) {} : phase_(phase), data_(data) {}
const char* phase_; const char* phase_;
const RegisterAllocator* allocator_; const RegisterAllocationData* data_;
}; };
std::ostream& operator<<(std::ostream& os, const AsDOT& ad); std::ostream& operator<<(std::ostream& os, const AsDOT& ad);
std::ostream& operator<<(std::ostream& os, const AsC1VCompilation& ac); std::ostream& operator<<(std::ostream& os, const AsC1VCompilation& ac);
std::ostream& operator<<(std::ostream& os, const AsC1V& ac); std::ostream& operator<<(std::ostream& os, const AsC1V& ac);
std::ostream& operator<<(std::ostream& os, const AsC1VAllocator& ac); std::ostream& operator<<(std::ostream& os,
const AsC1VRegisterAllocationData& ac);
} // namespace compiler } // namespace compiler
} // namespace internal } // namespace internal
......
...@@ -81,7 +81,9 @@ class PipelineData { ...@@ -81,7 +81,9 @@ class PipelineData {
instruction_zone_(instruction_zone_scope_.zone()), instruction_zone_(instruction_zone_scope_.zone()),
sequence_(nullptr), sequence_(nullptr),
frame_(nullptr), frame_(nullptr),
register_allocator_(nullptr) { register_allocation_zone_scope_(zone_pool_),
register_allocation_zone_(register_allocation_zone_scope_.zone()),
register_allocation_data_(nullptr) {
PhaseScope scope(pipeline_statistics, "init pipeline data"); PhaseScope scope(pipeline_statistics, "init pipeline data");
graph_ = new (graph_zone_) Graph(graph_zone_); graph_ = new (graph_zone_) Graph(graph_zone_);
source_positions_.Reset(new SourcePositionTable(graph_)); source_positions_.Reset(new SourcePositionTable(graph_));
...@@ -121,7 +123,9 @@ class PipelineData { ...@@ -121,7 +123,9 @@ class PipelineData {
instruction_zone_(instruction_zone_scope_.zone()), instruction_zone_(instruction_zone_scope_.zone()),
sequence_(nullptr), sequence_(nullptr),
frame_(nullptr), frame_(nullptr),
register_allocator_(nullptr) {} register_allocation_zone_scope_(zone_pool_),
register_allocation_zone_(register_allocation_zone_scope_.zone()),
register_allocation_data_(nullptr) {}
// For register allocation testing entry point. // For register allocation testing entry point.
PipelineData(ZonePool* zone_pool, CompilationInfo* info, PipelineData(ZonePool* zone_pool, CompilationInfo* info,
...@@ -148,9 +152,12 @@ class PipelineData { ...@@ -148,9 +152,12 @@ class PipelineData {
instruction_zone_(sequence->zone()), instruction_zone_(sequence->zone()),
sequence_(sequence), sequence_(sequence),
frame_(nullptr), frame_(nullptr),
register_allocator_(nullptr) {} register_allocation_zone_scope_(zone_pool_),
register_allocation_zone_(register_allocation_zone_scope_.zone()),
register_allocation_data_(nullptr) {}
~PipelineData() { ~PipelineData() {
DeleteRegisterAllocationZone();
DeleteInstructionZone(); DeleteInstructionZone();
DeleteGraphZone(); DeleteGraphZone();
} }
...@@ -200,7 +207,11 @@ class PipelineData { ...@@ -200,7 +207,11 @@ class PipelineData {
Zone* instruction_zone() const { return instruction_zone_; } Zone* instruction_zone() const { return instruction_zone_; }
InstructionSequence* sequence() const { return sequence_; } InstructionSequence* sequence() const { return sequence_; }
Frame* frame() const { return frame_; } Frame* frame() const { return frame_; }
RegisterAllocator* register_allocator() const { return register_allocator_; }
Zone* register_allocation_zone() const { return register_allocation_zone_; }
RegisterAllocationData* register_allocation_data() const {
return register_allocation_data_;
}
void DeleteGraphZone() { void DeleteGraphZone() {
// Destroy objects with destructors first. // Destroy objects with destructors first.
...@@ -226,11 +237,17 @@ class PipelineData { ...@@ -226,11 +237,17 @@ class PipelineData {
instruction_zone_ = nullptr; instruction_zone_ = nullptr;
sequence_ = nullptr; sequence_ = nullptr;
frame_ = nullptr; frame_ = nullptr;
register_allocator_ = nullptr; }
void DeleteRegisterAllocationZone() {
if (register_allocation_zone_ == nullptr) return;
register_allocation_zone_scope_.Destroy();
register_allocation_zone_ = nullptr;
register_allocation_data_ = nullptr;
} }
void InitializeInstructionSequence() { void InitializeInstructionSequence() {
DCHECK(!sequence_); DCHECK(sequence_ == nullptr);
InstructionBlocks* instruction_blocks = InstructionBlocks* instruction_blocks =
InstructionSequence::InstructionBlocksFor(instruction_zone(), InstructionSequence::InstructionBlocksFor(instruction_zone(),
schedule()); schedule());
...@@ -238,14 +255,14 @@ class PipelineData { ...@@ -238,14 +255,14 @@ class PipelineData {
info()->isolate(), instruction_zone(), instruction_blocks); info()->isolate(), instruction_zone(), instruction_blocks);
} }
void InitializeRegisterAllocator(Zone* local_zone, void InitializeLiveRangeBuilder(const RegisterConfiguration* config,
const RegisterConfiguration* config, const char* debug_name) {
const char* debug_name) { DCHECK(frame_ == nullptr);
DCHECK(!register_allocator_); DCHECK(register_allocation_data_ == nullptr);
DCHECK(!frame_);
frame_ = new (instruction_zone()) Frame(); frame_ = new (instruction_zone()) Frame();
register_allocator_ = new (instruction_zone()) register_allocation_data_ = new (register_allocation_zone())
RegisterAllocator(config, local_zone, frame(), sequence(), debug_name); RegisterAllocationData(config, register_allocation_zone(), frame(),
sequence(), debug_name);
} }
private: private:
...@@ -281,7 +298,13 @@ class PipelineData { ...@@ -281,7 +298,13 @@ class PipelineData {
Zone* instruction_zone_; Zone* instruction_zone_;
InstructionSequence* sequence_; InstructionSequence* sequence_;
Frame* frame_; Frame* frame_;
RegisterAllocator* register_allocator_;
// All objects in the following group of fields are allocated in
// register_allocation_zone_. They are all set to NULL when the zone is
// destroyed.
ZonePool::Scope register_allocation_zone_scope_;
Zone* register_allocation_zone_;
RegisterAllocationData* register_allocation_data_;
DISALLOW_COPY_AND_ASSIGN(PipelineData); DISALLOW_COPY_AND_ASSIGN(PipelineData);
}; };
...@@ -693,7 +716,8 @@ struct MeetRegisterConstraintsPhase { ...@@ -693,7 +716,8 @@ struct MeetRegisterConstraintsPhase {
static const char* phase_name() { return "meet register constraints"; } static const char* phase_name() { return "meet register constraints"; }
void Run(PipelineData* data, Zone* temp_zone) { void Run(PipelineData* data, Zone* temp_zone) {
data->register_allocator()->MeetRegisterConstraints(); LiveRangeBuilder builder(data->register_allocation_data());
builder.MeetRegisterConstraints();
} }
}; };
...@@ -702,7 +726,8 @@ struct ResolvePhisPhase { ...@@ -702,7 +726,8 @@ struct ResolvePhisPhase {
static const char* phase_name() { return "resolve phis"; } static const char* phase_name() { return "resolve phis"; }
void Run(PipelineData* data, Zone* temp_zone) { void Run(PipelineData* data, Zone* temp_zone) {
data->register_allocator()->ResolvePhis(); LiveRangeBuilder builder(data->register_allocation_data());
builder.ResolvePhis();
} }
}; };
...@@ -711,7 +736,8 @@ struct BuildLiveRangesPhase { ...@@ -711,7 +736,8 @@ struct BuildLiveRangesPhase {
static const char* phase_name() { return "build live ranges"; } static const char* phase_name() { return "build live ranges"; }
void Run(PipelineData* data, Zone* temp_zone) { void Run(PipelineData* data, Zone* temp_zone) {
data->register_allocator()->BuildLiveRanges(); LiveRangeBuilder builder(data->register_allocation_data());
builder.BuildLiveRanges();
} }
}; };
...@@ -720,7 +746,9 @@ struct AllocateGeneralRegistersPhase { ...@@ -720,7 +746,9 @@ struct AllocateGeneralRegistersPhase {
static const char* phase_name() { return "allocate general registers"; } static const char* phase_name() { return "allocate general registers"; }
void Run(PipelineData* data, Zone* temp_zone) { void Run(PipelineData* data, Zone* temp_zone) {
data->register_allocator()->AllocateGeneralRegisters(); LinearScanAllocator allocator(data->register_allocation_data(),
GENERAL_REGISTERS);
allocator.AllocateRegisters();
} }
}; };
...@@ -729,7 +757,9 @@ struct AllocateDoubleRegistersPhase { ...@@ -729,7 +757,9 @@ struct AllocateDoubleRegistersPhase {
static const char* phase_name() { return "allocate double registers"; } static const char* phase_name() { return "allocate double registers"; }
void Run(PipelineData* data, Zone* temp_zone) { void Run(PipelineData* data, Zone* temp_zone) {
data->register_allocator()->AllocateDoubleRegisters(); LinearScanAllocator allocator(data->register_allocation_data(),
DOUBLE_REGISTERS);
allocator.AllocateRegisters();
} }
}; };
...@@ -738,7 +768,8 @@ struct AssignSpillSlotsPhase { ...@@ -738,7 +768,8 @@ struct AssignSpillSlotsPhase {
static const char* phase_name() { return "assign spill slots"; } static const char* phase_name() { return "assign spill slots"; }
void Run(PipelineData* data, Zone* temp_zone) { void Run(PipelineData* data, Zone* temp_zone) {
data->register_allocator()->AssignSpillSlots(); OperandAssigner assigner(data->register_allocation_data());
assigner.AssignSpillSlots();
} }
}; };
...@@ -747,7 +778,8 @@ struct CommitAssignmentPhase { ...@@ -747,7 +778,8 @@ struct CommitAssignmentPhase {
static const char* phase_name() { return "commit assignment"; } static const char* phase_name() { return "commit assignment"; }
void Run(PipelineData* data, Zone* temp_zone) { void Run(PipelineData* data, Zone* temp_zone) {
data->register_allocator()->CommitAssignment(); OperandAssigner assigner(data->register_allocation_data());
assigner.CommitAssignment();
} }
}; };
...@@ -756,7 +788,8 @@ struct PopulateReferenceMapsPhase { ...@@ -756,7 +788,8 @@ struct PopulateReferenceMapsPhase {
static const char* phase_name() { return "populate pointer maps"; } static const char* phase_name() { return "populate pointer maps"; }
void Run(PipelineData* data, Zone* temp_zone) { void Run(PipelineData* data, Zone* temp_zone) {
data->register_allocator()->PopulateReferenceMaps(); ReferenceMapPopulator populator(data->register_allocation_data());
populator.PopulateReferenceMaps();
} }
}; };
...@@ -765,7 +798,8 @@ struct ConnectRangesPhase { ...@@ -765,7 +798,8 @@ struct ConnectRangesPhase {
static const char* phase_name() { return "connect ranges"; } static const char* phase_name() { return "connect ranges"; }
void Run(PipelineData* data, Zone* temp_zone) { void Run(PipelineData* data, Zone* temp_zone) {
data->register_allocator()->ConnectRanges(); LiveRangeConnector connector(data->register_allocation_data());
connector.ConnectRanges(temp_zone);
} }
}; };
...@@ -774,7 +808,8 @@ struct ResolveControlFlowPhase { ...@@ -774,7 +808,8 @@ struct ResolveControlFlowPhase {
static const char* phase_name() { return "resolve control flow"; } static const char* phase_name() { return "resolve control flow"; }
void Run(PipelineData* data, Zone* temp_zone) { void Run(PipelineData* data, Zone* temp_zone) {
data->register_allocator()->ResolveControlFlow(); LiveRangeConnector connector(data->register_allocation_data());
connector.ResolveControlFlow();
} }
}; };
...@@ -1216,9 +1251,7 @@ void Pipeline::AllocateRegisters(const RegisterConfiguration* config, ...@@ -1216,9 +1251,7 @@ void Pipeline::AllocateRegisters(const RegisterConfiguration* config,
debug_name = GetDebugName(data->info()); debug_name = GetDebugName(data->info());
#endif #endif
ZonePool::Scope zone_scope(data->zone_pool()); data->InitializeLiveRangeBuilder(config, debug_name.get());
data->InitializeRegisterAllocator(zone_scope.zone(), config,
debug_name.get());
if (info()->is_osr()) { if (info()->is_osr()) {
OsrHelper osr_helper(info()); OsrHelper osr_helper(info());
osr_helper.SetupFrame(data->frame()); osr_helper.SetupFrame(data->frame());
...@@ -1234,7 +1267,7 @@ void Pipeline::AllocateRegisters(const RegisterConfiguration* config, ...@@ -1234,7 +1267,7 @@ void Pipeline::AllocateRegisters(const RegisterConfiguration* config,
<< printable; << printable;
} }
if (verifier != nullptr) { if (verifier != nullptr) {
CHECK(!data->register_allocator()->ExistsUseWithoutDefinition()); CHECK(!data->register_allocation_data()->ExistsUseWithoutDefinition());
} }
Run<AllocateGeneralRegistersPhase>(); Run<AllocateGeneralRegistersPhase>();
Run<AllocateDoubleRegistersPhase>(); Run<AllocateDoubleRegistersPhase>();
...@@ -1262,8 +1295,11 @@ void Pipeline::AllocateRegisters(const RegisterConfiguration* config, ...@@ -1262,8 +1295,11 @@ void Pipeline::AllocateRegisters(const RegisterConfiguration* config,
if (FLAG_trace_turbo && !data->MayHaveUnverifiableGraph()) { if (FLAG_trace_turbo && !data->MayHaveUnverifiableGraph()) {
TurboCfgFile tcf(data->isolate()); TurboCfgFile tcf(data->isolate());
tcf << AsC1VAllocator("CodeGen", data->register_allocator()); tcf << AsC1VRegisterAllocationData("CodeGen",
data->register_allocation_data());
} }
data->DeleteRegisterAllocationZone();
} }
} // namespace compiler } // namespace compiler
......
This diff is collapsed.
This diff is collapsed.
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