Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(11)

Unified Diff: src/compiler/register-allocator.cc

Issue 688633002: [turbofan] add configuration parameters for register allocator (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: rebase Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: src/compiler/register-allocator.cc
diff --git a/src/compiler/register-allocator.cc b/src/compiler/register-allocator.cc
index e65b9fffa212daf865b8b248e05b8e5514e50e5c..644fd21923ce4776238bec10fcbf264e63da7c4c 100644
--- a/src/compiler/register-allocator.cc
+++ b/src/compiler/register-allocator.cc
@@ -5,6 +5,7 @@
#include "src/compiler/linkage.h"
#include "src/compiler/pipeline-statistics.h"
#include "src/compiler/register-allocator.h"
+#include "src/macro-assembler.h" // TODO(dcarney): remove this.
#include "src/string-stream.h"
namespace v8 {
@@ -506,17 +507,33 @@ LifetimePosition LiveRange::FirstIntersection(LiveRange* other) {
}
-RegisterAllocator::RegisterAllocator(Zone* local_zone, Frame* frame,
- InstructionSequence* code,
+RegisterAllocator::Config RegisterAllocator::PlatformConfig() {
+ DCHECK_EQ(Register::kMaxNumAllocatableRegisters,
+ Register::NumAllocatableRegisters());
+ Config config;
+ config.num_general_registers_ = Register::kMaxNumAllocatableRegisters;
+ config.num_double_registers_ = DoubleRegister::kMaxNumAllocatableRegisters;
+ config.num_aliased_double_registers_ =
+ DoubleRegister::NumAllocatableAliasedRegisters();
+ config.GeneralRegisterName = Register::AllocationIndexToString;
+ config.DoubleRegisterName = DoubleRegister::AllocationIndexToString;
+ return config;
+}
+
+
+RegisterAllocator::RegisterAllocator(const Config& config, Zone* local_zone,
+ Frame* frame, InstructionSequence* code,
const char* debug_name)
: zone_(local_zone),
frame_(frame),
code_(code),
debug_name_(debug_name),
+ config_(config),
live_in_sets_(code->InstructionBlockCount(), zone()),
live_ranges_(code->VirtualRegisterCount() * 2, zone()),
- fixed_live_ranges_(NULL),
- fixed_double_live_ranges_(NULL),
+ fixed_live_ranges_(this->config().num_general_registers_, NULL, zone()),
+ fixed_double_live_ranges_(this->config().num_double_registers_, NULL,
+ zone()),
unhandled_live_ranges_(code->VirtualRegisterCount() * 2, zone()),
active_live_ranges_(8, zone()),
inactive_live_ranges_(8, zone()),
@@ -579,7 +596,7 @@ void RegisterAllocator::AddInitialIntervals(const InstructionBlock* block,
int RegisterAllocator::FixedDoubleLiveRangeID(int index) {
- return -index - 1 - Register::kMaxNumAllocatableRegisters;
+ return -index - 1 - config().num_general_registers_;
}
@@ -611,7 +628,7 @@ InstructionOperand* RegisterAllocator::AllocateFixed(
LiveRange* RegisterAllocator::FixedLiveRangeFor(int index) {
- DCHECK(index < Register::kMaxNumAllocatableRegisters);
+ DCHECK(index < config().num_general_registers_);
LiveRange* result = fixed_live_ranges_[index];
if (result == NULL) {
// TODO(titzer): add a utility method to allocate a new LiveRange:
@@ -629,7 +646,7 @@ LiveRange* RegisterAllocator::FixedLiveRangeFor(int index) {
LiveRange* RegisterAllocator::FixedDoubleLiveRangeFor(int index) {
- DCHECK(index < DoubleRegister::NumAllocatableAliasedRegisters());
+ DCHECK(index < config().num_aliased_double_registers_);
LiveRange* result = fixed_double_live_ranges_[index];
if (result == NULL) {
result = new (zone()) LiveRange(FixedDoubleLiveRangeID(index), code_zone());
@@ -1007,7 +1024,7 @@ void RegisterAllocator::ProcessInstructions(const InstructionBlock* block,
}
if (instr->ClobbersRegisters()) {
- for (int i = 0; i < Register::kMaxNumAllocatableRegisters; ++i) {
+ for (int i = 0; i < config().num_general_registers_; ++i) {
if (!IsOutputRegisterOf(instr, i)) {
LiveRange* range = FixedLiveRangeFor(i);
range->AddUseInterval(curr_position, curr_position.InstructionEnd(),
@@ -1017,8 +1034,7 @@ void RegisterAllocator::ProcessInstructions(const InstructionBlock* block,
}
if (instr->ClobbersDoubleRegisters()) {
- for (int i = 0; i < DoubleRegister::NumAllocatableAliasedRegisters();
- ++i) {
+ for (int i = 0; i < config().num_aliased_double_registers_; ++i) {
if (!IsOutputDoubleRegisterOf(instr, i)) {
LiveRange* range = FixedDoubleLiveRangeFor(i);
range->AddUseInterval(curr_position, curr_position.InstructionEnd(),
@@ -1103,10 +1119,10 @@ void RegisterAllocator::ResolvePhis(const InstructionBlock* block) {
bool RegisterAllocator::Allocate(PipelineStatistics* stats) {
- assigned_registers_ = new (code_zone())
- BitVector(Register::NumAllocatableRegisters(), code_zone());
+ assigned_registers_ =
+ new (code_zone()) BitVector(config().num_general_registers_, code_zone());
assigned_double_registers_ = new (code_zone())
- BitVector(DoubleRegister::NumAllocatableAliasedRegisters(), code_zone());
+ BitVector(config().num_aliased_double_registers_, code_zone());
{
PhaseScope phase_scope(stats, "meet register constraints");
MeetRegisterConstraints();
@@ -1235,8 +1251,8 @@ const InstructionBlock* RegisterAllocator::GetInstructionBlock(
void RegisterAllocator::ConnectRanges() {
- for (int i = 0; i < live_ranges()->length(); ++i) {
- LiveRange* first_range = live_ranges()->at(i);
+ for (int i = 0; i < live_ranges().length(); ++i) {
+ LiveRange* first_range = live_ranges().at(i);
if (first_range == NULL || first_range->parent() != NULL) continue;
LiveRange* second_range = first_range->next();
@@ -1437,8 +1453,8 @@ void RegisterAllocator::PopulatePointerMaps() {
int last_range_start = 0;
const PointerMapDeque* pointer_maps = code()->pointer_maps();
PointerMapDeque::const_iterator first_it = pointer_maps->begin();
- for (int range_idx = 0; range_idx < live_ranges()->length(); ++range_idx) {
- LiveRange* range = live_ranges()->at(range_idx);
+ for (int range_idx = 0; range_idx < live_ranges().length(); ++range_idx) {
+ LiveRange* range = live_ranges().at(range_idx);
if (range == NULL) continue;
// Iterate over the first parts of multi-part live ranges.
if (range->parent() != NULL) continue;
@@ -1512,14 +1528,14 @@ void RegisterAllocator::PopulatePointerMaps() {
void RegisterAllocator::AllocateGeneralRegisters() {
- num_registers_ = Register::NumAllocatableRegisters();
+ num_registers_ = config().num_general_registers_;
mode_ = GENERAL_REGISTERS;
AllocateRegisters();
}
void RegisterAllocator::AllocateDoubleRegisters() {
- num_registers_ = DoubleRegister::NumAllocatableAliasedRegisters();
+ num_registers_ = config().num_aliased_double_registers_;
mode_ = DOUBLE_REGISTERS;
AllocateRegisters();
}
@@ -1543,7 +1559,7 @@ void RegisterAllocator::AllocateRegisters() {
DCHECK(inactive_live_ranges_.is_empty());
if (mode_ == DOUBLE_REGISTERS) {
- for (int i = 0; i < DoubleRegister::NumAllocatableAliasedRegisters(); ++i) {
+ for (int i = 0; i < config().num_aliased_double_registers_; ++i) {
LiveRange* current = fixed_double_live_ranges_.at(i);
if (current != NULL) {
AddToInactive(current);
@@ -1551,8 +1567,7 @@ void RegisterAllocator::AllocateRegisters() {
}
} else {
DCHECK(mode_ == GENERAL_REGISTERS);
- for (int i = 0; i < fixed_live_ranges_.length(); ++i) {
- LiveRange* current = fixed_live_ranges_.at(i);
+ for (auto current : fixed_live_ranges()) {
if (current != NULL) {
AddToInactive(current);
}
@@ -1636,9 +1651,9 @@ void RegisterAllocator::AllocateRegisters() {
const char* RegisterAllocator::RegisterName(int allocation_index) {
if (mode_ == GENERAL_REGISTERS) {
- return Register::AllocationIndexToString(allocation_index);
+ return config().GeneralRegisterName(allocation_index);
} else {
- return DoubleRegister::AllocationIndexToString(allocation_index);
+ return config().DoubleRegisterName(allocation_index);
}
}
@@ -1782,14 +1797,11 @@ void RegisterAllocator::InactiveToActive(LiveRange* range) {
}
-// TryAllocateFreeReg and AllocateBlockedReg assume this
-// when allocating local arrays.
-STATIC_ASSERT(DoubleRegister::kMaxNumAllocatableRegisters >=
- Register::kMaxNumAllocatableRegisters);
-
-
bool RegisterAllocator::TryAllocateFreeReg(LiveRange* current) {
- LifetimePosition free_until_pos[DoubleRegister::kMaxNumAllocatableRegisters];
+ DCHECK(config().num_double_registers_ >= config().num_general_registers_);
+ // TODO(dcarney): ensure this function in non recursive and allocate space for
+ // this in RegisterAllocator.
+ LifetimePosition free_until_pos[kMaxDoubleRegisters];
for (int i = 0; i < num_registers_; i++) {
free_until_pos[i] = LifetimePosition::MaxPosition();
@@ -1864,6 +1876,7 @@ bool RegisterAllocator::TryAllocateFreeReg(LiveRange* current) {
void RegisterAllocator::AllocateBlockedReg(LiveRange* current) {
+ DCHECK(config().num_double_registers_ >= config().num_general_registers_);
UsePosition* register_use = current->NextRegisterPosition(current->Start());
if (register_use == NULL) {
// There is no use in the current live range that requires a register.
@@ -1872,9 +1885,12 @@ void RegisterAllocator::AllocateBlockedReg(LiveRange* current) {
return;
}
-
- LifetimePosition use_pos[DoubleRegister::kMaxNumAllocatableRegisters];
- LifetimePosition block_pos[DoubleRegister::kMaxNumAllocatableRegisters];
+ // TODO(dcarney): ensure this function in non recursive and allocate space for
+ // this in RegisterAllocator.
Jarin 2014/10/29 17:37:43 Why would you want this to be allocated RegisterAl
+ LifetimePosition use_pos[kMaxGeneralRegisters];
+ // TODO(dcarney): ensure this function in non recursive and allocate space for
+ // this in RegisterAllocator.
+ LifetimePosition block_pos[kMaxDoubleRegisters];
for (int i = 0; i < num_registers_; i++) {
use_pos[i] = block_pos[i] = LifetimePosition::MaxPosition();
@@ -2187,8 +2203,7 @@ int RegisterAllocator::RegisterCount() const { return num_registers_; }
void RegisterAllocator::Verify() const {
- for (int i = 0; i < live_ranges()->length(); ++i) {
- LiveRange* current = live_ranges()->at(i);
+ for (auto current : live_ranges()) {
if (current != NULL) current->Verify();
}
}

Powered by Google App Engine
This is Rietveld 408576698