diff options
| -rw-r--r-- | compiler/driver/compiler_options.cc | 24 | ||||
| -rw-r--r-- | compiler/driver/compiler_options.h | 11 | ||||
| -rw-r--r-- | compiler/jit/jit_compiler.cc | 4 | ||||
| -rw-r--r-- | compiler/optimizing/optimizing_compiler.cc | 9 |
4 files changed, 40 insertions, 8 deletions
diff --git a/compiler/driver/compiler_options.cc b/compiler/driver/compiler_options.cc index f20dba34a6..a522e0c7b5 100644 --- a/compiler/driver/compiler_options.cc +++ b/compiler/driver/compiler_options.cc @@ -44,7 +44,8 @@ CompilerOptions::CompilerOptions() init_failure_output_(nullptr), dump_cfg_file_name_(""), dump_cfg_append_(false), - force_determinism_(false) { + force_determinism_(false), + register_allocation_strategy_(RegisterAllocator::kRegisterAllocatorDefault) { } CompilerOptions::~CompilerOptions() { @@ -74,7 +75,8 @@ CompilerOptions::CompilerOptions(CompilerFilter::Filter compiler_filter, bool abort_on_hard_verifier_failure, const std::string& dump_cfg_file_name, bool dump_cfg_append, - bool force_determinism + bool force_determinism, + RegisterAllocator::Strategy regalloc_strategy ) : // NOLINT(whitespace/parens) compiler_filter_(compiler_filter), huge_method_threshold_(huge_method_threshold), @@ -99,7 +101,8 @@ CompilerOptions::CompilerOptions(CompilerFilter::Filter compiler_filter, init_failure_output_(init_failure_output), dump_cfg_file_name_(dump_cfg_file_name), dump_cfg_append_(dump_cfg_append), - force_determinism_(force_determinism) { + force_determinism_(force_determinism), + register_allocation_strategy_(regalloc_strategy) { } void CompilerOptions::ParseHugeMethodMax(const StringPiece& option, UsageFn Usage) { @@ -144,6 +147,19 @@ void CompilerOptions::ParseDumpInitFailures(const StringPiece& option, } } +void CompilerOptions::ParseRegisterAllocationStrategy(const StringPiece& option, + UsageFn Usage) { + DCHECK(option.starts_with("--register-allocation-strategy=")); + StringPiece choice = option.substr(strlen("--register-allocation-strategy=")).data(); + if (choice == "linear-scan") { + register_allocation_strategy_ = RegisterAllocator::Strategy::kRegisterAllocatorLinearScan; + } else if (choice == "graph-color") { + register_allocation_strategy_ = RegisterAllocator::Strategy::kRegisterAllocatorGraphColor; + } else { + Usage("Unrecognized register allocation strategy. Try linear-scan, or graph-color."); + } +} + bool CompilerOptions::ParseCompilerOption(const StringPiece& option, UsageFn Usage) { if (option.starts_with("--compiler-filter=")) { const char* compiler_filter_string = option.substr(strlen("--compiler-filter=")).data(); @@ -190,6 +206,8 @@ bool CompilerOptions::ParseCompilerOption(const StringPiece& option, UsageFn Usa dump_cfg_file_name_ = option.substr(strlen("--dump-cfg=")).data(); } else if (option.starts_with("--dump-cfg-append")) { dump_cfg_append_ = true; + } else if (option.starts_with("--register-allocation-strategy=")) { + ParseRegisterAllocationStrategy(option, Usage); } else { // Option not recognized. return false; diff --git a/compiler/driver/compiler_options.h b/compiler/driver/compiler_options.h index 60b700ad91..cc66d7a577 100644 --- a/compiler/driver/compiler_options.h +++ b/compiler/driver/compiler_options.h @@ -24,6 +24,7 @@ #include "base/macros.h" #include "compiler_filter.h" #include "globals.h" +#include "optimizing/register_allocator.h" #include "utils.h" namespace art { @@ -74,7 +75,8 @@ class CompilerOptions FINAL { bool abort_on_hard_verifier_failure, const std::string& dump_cfg_file_name, bool dump_cfg_append, - bool force_determinism); + bool force_determinism, + RegisterAllocator::Strategy regalloc_strategy); CompilerFilter::Filter GetCompilerFilter() const { return compiler_filter_; @@ -244,6 +246,10 @@ class CompilerOptions FINAL { return force_determinism_; } + RegisterAllocator::Strategy GetRegisterAllocationStrategy() const { + return register_allocation_strategy_; + } + private: void ParseDumpInitFailures(const StringPiece& option, UsageFn Usage); void ParseDumpCfgPasses(const StringPiece& option, UsageFn Usage); @@ -254,6 +260,7 @@ class CompilerOptions FINAL { void ParseSmallMethodMax(const StringPiece& option, UsageFn Usage); void ParseLargeMethodMax(const StringPiece& option, UsageFn Usage); void ParseHugeMethodMax(const StringPiece& option, UsageFn Usage); + void ParseRegisterAllocationStrategy(const StringPiece& option, UsageFn Usage); CompilerFilter::Filter compiler_filter_; size_t huge_method_threshold_; @@ -297,6 +304,8 @@ class CompilerOptions FINAL { // outcomes. bool force_determinism_; + RegisterAllocator::Strategy register_allocation_strategy_; + friend class Dex2Oat; DISALLOW_COPY_AND_ASSIGN(CompilerOptions); diff --git a/compiler/jit/jit_compiler.cc b/compiler/jit/jit_compiler.cc index 178533849b..2dd87a8483 100644 --- a/compiler/jit/jit_compiler.cc +++ b/compiler/jit/jit_compiler.cc @@ -32,6 +32,7 @@ #include "oat_file-inl.h" #include "oat_quick_method_header.h" #include "object_lock.h" +#include "optimizing/register_allocator.h" #include "thread_list.h" namespace art { @@ -110,7 +111,8 @@ JitCompiler::JitCompiler() { /* abort_on_hard_verifier_failure */ false, /* dump_cfg_file_name */ "", /* dump_cfg_append */ false, - /* force_determinism */ false)); + /* force_determinism */ false, + RegisterAllocator::kRegisterAllocatorDefault)); for (const std::string& argument : Runtime::Current()->GetCompilerOptions()) { compiler_options_->ParseCompilerOption(argument, Usage); } diff --git a/compiler/optimizing/optimizing_compiler.cc b/compiler/optimizing/optimizing_compiler.cc index d5b0d77fe5..30da69ffff 100644 --- a/compiler/optimizing/optimizing_compiler.cc +++ b/compiler/optimizing/optimizing_compiler.cc @@ -546,7 +546,8 @@ void OptimizingCompiler::RunArchOptimizations(InstructionSet instruction_set, NO_INLINE // Avoid increasing caller's frame size by large stack-allocated objects. static void AllocateRegisters(HGraph* graph, CodeGenerator* codegen, - PassObserver* pass_observer) { + PassObserver* pass_observer, + RegisterAllocator::Strategy strategy) { { PassScope scope(PrepareForRegisterAllocation::kPrepareForRegisterAllocationPassName, pass_observer); @@ -559,7 +560,7 @@ static void AllocateRegisters(HGraph* graph, } { PassScope scope(RegisterAllocator::kRegisterAllocatorPassName, pass_observer); - RegisterAllocator::Create(graph->GetArena(), codegen, liveness)->AllocateRegisters(); + RegisterAllocator::Create(graph->GetArena(), codegen, liveness, strategy)->AllocateRegisters(); } } @@ -626,7 +627,9 @@ void OptimizingCompiler::RunOptimizations(HGraph* graph, RunOptimizations(optimizations2, arraysize(optimizations2), pass_observer); RunArchOptimizations(driver->GetInstructionSet(), graph, codegen, pass_observer); - AllocateRegisters(graph, codegen, pass_observer); + RegisterAllocator::Strategy regalloc_strategy = + driver->GetCompilerOptions().GetRegisterAllocationStrategy(); + AllocateRegisters(graph, codegen, pass_observer, regalloc_strategy); } static ArenaVector<LinkerPatch> EmitAndSortLinkerPatches(CodeGenerator* codegen) { |