diff options
Diffstat (limited to 'compiler/optimizing')
-rw-r--r-- | compiler/optimizing/code_generator.cc | 6 | ||||
-rw-r--r-- | compiler/optimizing/code_generator_arm.h | 2 | ||||
-rw-r--r-- | compiler/optimizing/codegen_test.cc | 34 | ||||
-rw-r--r-- | compiler/optimizing/linearize_test.cc | 5 | ||||
-rw-r--r-- | compiler/optimizing/live_ranges_test.cc | 17 | ||||
-rw-r--r-- | compiler/optimizing/liveness_test.cc | 5 | ||||
-rw-r--r-- | compiler/optimizing/register_allocator_test.cc | 47 | ||||
-rw-r--r-- | compiler/optimizing/ssa_liveness_analysis.cc | 3 |
8 files changed, 63 insertions, 56 deletions
diff --git a/compiler/optimizing/code_generator.cc b/compiler/optimizing/code_generator.cc index 7731e6e982..2547a294d4 100644 --- a/compiler/optimizing/code_generator.cc +++ b/compiler/optimizing/code_generator.cc @@ -48,11 +48,11 @@ void CodeGenerator::CompileBaseline(CodeAllocator* allocator, bool is_leaf) { + 1 /* current method */); GenerateFrameEntry(); + HGraphVisitor* location_builder = GetLocationBuilder(); + HGraphVisitor* instruction_visitor = GetInstructionVisitor(); for (size_t i = 0, e = blocks.Size(); i < e; ++i) { HBasicBlock* block = blocks.Get(i); Bind(GetLabelOf(block)); - HGraphVisitor* location_builder = GetLocationBuilder(); - HGraphVisitor* instruction_visitor = GetInstructionVisitor(); for (HInstructionIterator it(block->GetInstructions()); !it.Done(); it.Advance()) { HInstruction* current = it.Current(); current->Accept(location_builder); @@ -77,10 +77,10 @@ void CodeGenerator::CompileOptimized(CodeAllocator* allocator) { block_labels_.SetSize(blocks.Size()); GenerateFrameEntry(); + HGraphVisitor* instruction_visitor = GetInstructionVisitor(); for (size_t i = 0, e = blocks.Size(); i < e; ++i) { HBasicBlock* block = blocks.Get(i); Bind(GetLabelOf(block)); - HGraphVisitor* instruction_visitor = GetInstructionVisitor(); for (HInstructionIterator it(block->GetInstructions()); !it.Done(); it.Advance()) { HInstruction* current = it.Current(); current->Accept(instruction_visitor); diff --git a/compiler/optimizing/code_generator_arm.h b/compiler/optimizing/code_generator_arm.h index 610625c50b..660294b147 100644 --- a/compiler/optimizing/code_generator_arm.h +++ b/compiler/optimizing/code_generator_arm.h @@ -124,7 +124,7 @@ class InstructionCodeGeneratorARM : public HGraphVisitor { class CodeGeneratorARM : public CodeGenerator { public: explicit CodeGeneratorARM(HGraph* graph); - virtual ~CodeGeneratorARM() { } + virtual ~CodeGeneratorARM() {} virtual void GenerateFrameEntry() OVERRIDE; virtual void GenerateFrameExit() OVERRIDE; diff --git a/compiler/optimizing/codegen_test.cc b/compiler/optimizing/codegen_test.cc index d7ac10d164..672ff54b1d 100644 --- a/compiler/optimizing/codegen_test.cc +++ b/compiler/optimizing/codegen_test.cc @@ -15,7 +15,9 @@ */ #include "builder.h" -#include "code_generator.h" +#include "code_generator_arm.h" +#include "code_generator_x86.h" +#include "code_generator_x86_64.h" #include "common_compiler_test.h" #include "dex_file.h" #include "dex_instruction.h" @@ -75,25 +77,25 @@ static void TestCode(const uint16_t* data, bool has_result = false, int32_t expe ASSERT_NE(graph, nullptr); InternalCodeAllocator allocator; - CodeGenerator* codegen = CodeGenerator::Create(&arena, graph, kX86); + x86::CodeGeneratorX86 codegenX86(graph); // We avoid doing a stack overflow check that requires the runtime being setup, // by making sure the compiler knows the methods we are running are leaf methods. - codegen->CompileBaseline(&allocator, true); -#if defined(__i386__) - Run(allocator, *codegen, has_result, expected); -#endif + codegenX86.CompileBaseline(&allocator, true); + if (kRuntimeISA == kX86) { + Run(allocator, codegenX86, has_result, expected); + } - codegen = CodeGenerator::Create(&arena, graph, kArm); - codegen->CompileBaseline(&allocator, true); -#if defined(__arm__) - Run(allocator, *codegen, has_result, expected); -#endif + arm::CodeGeneratorARM codegenARM(graph); + codegenARM.CompileBaseline(&allocator, true); + if (kRuntimeISA == kArm || kRuntimeISA == kThumb2) { + Run(allocator, codegenARM, has_result, expected); + } - codegen = CodeGenerator::Create(&arena, graph, kX86_64); - codegen->CompileBaseline(&allocator, true); -#if defined(__x86_64__) - Run(allocator, *codegen, has_result, expected); -#endif + x86_64::CodeGeneratorX86_64 codegenX86_64(graph); + codegenX86_64.CompileBaseline(&allocator, true); + if (kRuntimeISA == kX86_64) { + Run(allocator, codegenX86_64, has_result, expected); + } } TEST(CodegenTest, ReturnVoid) { diff --git a/compiler/optimizing/linearize_test.cc b/compiler/optimizing/linearize_test.cc index e4f9371e62..6dd4207795 100644 --- a/compiler/optimizing/linearize_test.cc +++ b/compiler/optimizing/linearize_test.cc @@ -19,6 +19,7 @@ #include "base/stringprintf.h" #include "builder.h" #include "code_generator.h" +#include "code_generator_x86.h" #include "dex_file.h" #include "dex_instruction.h" #include "graph_visualizer.h" @@ -45,8 +46,8 @@ static void TestCode(const uint16_t* data, const int* expected_order, size_t num graph->TransformToSSA(); graph->FindNaturalLoops(); - CodeGenerator* codegen = CodeGenerator::Create(&allocator, graph, InstructionSet::kX86); - SsaLivenessAnalysis liveness(*graph, codegen); + x86::CodeGeneratorX86 codegen(graph); + SsaLivenessAnalysis liveness(*graph, &codegen); liveness.Analyze(); ASSERT_EQ(liveness.GetLinearPostOrder().Size(), number_of_blocks); diff --git a/compiler/optimizing/live_ranges_test.cc b/compiler/optimizing/live_ranges_test.cc index a6e5ca9e46..21e634de04 100644 --- a/compiler/optimizing/live_ranges_test.cc +++ b/compiler/optimizing/live_ranges_test.cc @@ -16,6 +16,7 @@ #include "builder.h" #include "code_generator.h" +#include "code_generator_x86.h" #include "dex_file.h" #include "dex_instruction.h" #include "nodes.h" @@ -58,8 +59,8 @@ TEST(LiveRangesTest, CFG1) { ArenaAllocator allocator(&pool); HGraph* graph = BuildGraph(data, &allocator); - CodeGenerator* codegen = CodeGenerator::Create(&allocator, graph, InstructionSet::kX86); - SsaLivenessAnalysis liveness(*graph, codegen); + x86::CodeGeneratorX86 codegen(graph); + SsaLivenessAnalysis liveness(*graph, &codegen); liveness.Analyze(); LiveInterval* interval = liveness.GetInstructionFromSsaIndex(0)->GetLiveInterval(); @@ -104,8 +105,8 @@ TEST(LiveRangesTest, CFG2) { ArenaPool pool; ArenaAllocator allocator(&pool); HGraph* graph = BuildGraph(data, &allocator); - CodeGenerator* codegen = CodeGenerator::Create(&allocator, graph, InstructionSet::kX86); - SsaLivenessAnalysis liveness(*graph, codegen); + x86::CodeGeneratorX86 codegen(graph); + SsaLivenessAnalysis liveness(*graph, &codegen); liveness.Analyze(); LiveInterval* interval = liveness.GetInstructionFromSsaIndex(0)->GetLiveInterval(); @@ -153,8 +154,8 @@ TEST(LiveRangesTest, CFG3) { ArenaPool pool; ArenaAllocator allocator(&pool); HGraph* graph = BuildGraph(data, &allocator); - CodeGenerator* codegen = CodeGenerator::Create(&allocator, graph, InstructionSet::kX86); - SsaLivenessAnalysis liveness(*graph, codegen); + x86::CodeGeneratorX86 codegen(graph); + SsaLivenessAnalysis liveness(*graph, &codegen); liveness.Analyze(); // Test for the 4 constant. @@ -229,8 +230,8 @@ TEST(LiveRangesTest, Loop) { ArenaPool pool; ArenaAllocator allocator(&pool); HGraph* graph = BuildGraph(data, &allocator); - CodeGenerator* codegen = CodeGenerator::Create(&allocator, graph, InstructionSet::kX86); - SsaLivenessAnalysis liveness(*graph, codegen); + x86::CodeGeneratorX86 codegen(graph); + SsaLivenessAnalysis liveness(*graph, &codegen); liveness.Analyze(); // Test for the 0 constant. diff --git a/compiler/optimizing/liveness_test.cc b/compiler/optimizing/liveness_test.cc index 1a4d74536b..84b2e33ee7 100644 --- a/compiler/optimizing/liveness_test.cc +++ b/compiler/optimizing/liveness_test.cc @@ -16,6 +16,7 @@ #include "builder.h" #include "code_generator.h" +#include "code_generator_x86.h" #include "dex_file.h" #include "dex_instruction.h" #include "nodes.h" @@ -49,8 +50,8 @@ static void TestCode(const uint16_t* data, const char* expected) { graph->BuildDominatorTree(); graph->TransformToSSA(); graph->FindNaturalLoops(); - CodeGenerator* codegen = CodeGenerator::Create(&allocator, graph, InstructionSet::kX86); - SsaLivenessAnalysis liveness(*graph, codegen); + x86::CodeGeneratorX86 codegen(graph); + SsaLivenessAnalysis liveness(*graph, &codegen); liveness.Analyze(); std::ostringstream buffer; diff --git a/compiler/optimizing/register_allocator_test.cc b/compiler/optimizing/register_allocator_test.cc index 7539d44d1a..dcae46b4bd 100644 --- a/compiler/optimizing/register_allocator_test.cc +++ b/compiler/optimizing/register_allocator_test.cc @@ -16,6 +16,7 @@ #include "builder.h" #include "code_generator.h" +#include "code_generator_x86.h" #include "dex_file.h" #include "dex_instruction.h" #include "nodes.h" @@ -41,10 +42,10 @@ static bool Check(const uint16_t* data) { graph->BuildDominatorTree(); graph->TransformToSSA(); graph->FindNaturalLoops(); - CodeGenerator* codegen = CodeGenerator::Create(&allocator, graph, kX86); - SsaLivenessAnalysis liveness(*graph, codegen); + x86::CodeGeneratorX86 codegen(graph); + SsaLivenessAnalysis liveness(*graph, &codegen); liveness.Analyze(); - RegisterAllocator register_allocator(&allocator, codegen, liveness); + RegisterAllocator register_allocator(&allocator, &codegen, liveness); register_allocator.AllocateRegisters(); return register_allocator.Validate(false); } @@ -57,7 +58,7 @@ TEST(RegisterAllocatorTest, ValidateIntervals) { ArenaPool pool; ArenaAllocator allocator(&pool); HGraph* graph = new (&allocator) HGraph(&allocator); - CodeGenerator* codegen = CodeGenerator::Create(&allocator, graph, kX86); + x86::CodeGeneratorX86 codegen(graph); GrowableArray<LiveInterval*> intervals(&allocator, 0); // Test with two intervals of the same range. @@ -66,11 +67,11 @@ TEST(RegisterAllocatorTest, ValidateIntervals) { intervals.Add(BuildInterval(ranges, arraysize(ranges), &allocator, 0)); intervals.Add(BuildInterval(ranges, arraysize(ranges), &allocator, 1)); ASSERT_TRUE(RegisterAllocator::ValidateIntervals( - intervals, 0, 0, *codegen, &allocator, true, false)); + intervals, 0, 0, codegen, &allocator, true, false)); intervals.Get(1)->SetRegister(0); ASSERT_FALSE(RegisterAllocator::ValidateIntervals( - intervals, 0, 0, *codegen, &allocator, true, false)); + intervals, 0, 0, codegen, &allocator, true, false)); intervals.Reset(); } @@ -81,11 +82,11 @@ TEST(RegisterAllocatorTest, ValidateIntervals) { static constexpr size_t ranges2[][2] = {{42, 43}}; intervals.Add(BuildInterval(ranges2, arraysize(ranges2), &allocator, 1)); ASSERT_TRUE(RegisterAllocator::ValidateIntervals( - intervals, 0, 0, *codegen, &allocator, true, false)); + intervals, 0, 0, codegen, &allocator, true, false)); intervals.Get(1)->SetRegister(0); ASSERT_TRUE(RegisterAllocator::ValidateIntervals( - intervals, 0, 0, *codegen, &allocator, true, false)); + intervals, 0, 0, codegen, &allocator, true, false)); intervals.Reset(); } @@ -96,11 +97,11 @@ TEST(RegisterAllocatorTest, ValidateIntervals) { static constexpr size_t ranges2[][2] = {{42, 43}}; intervals.Add(BuildInterval(ranges2, arraysize(ranges2), &allocator, 1)); ASSERT_TRUE(RegisterAllocator::ValidateIntervals( - intervals, 0, 0, *codegen, &allocator, true, false)); + intervals, 0, 0, codegen, &allocator, true, false)); intervals.Get(1)->SetRegister(0); ASSERT_TRUE(RegisterAllocator::ValidateIntervals( - intervals, 0, 0, *codegen, &allocator, true, false)); + intervals, 0, 0, codegen, &allocator, true, false)); intervals.Reset(); } @@ -111,11 +112,11 @@ TEST(RegisterAllocatorTest, ValidateIntervals) { static constexpr size_t ranges2[][2] = {{42, 47}}; intervals.Add(BuildInterval(ranges2, arraysize(ranges2), &allocator, 1)); ASSERT_TRUE(RegisterAllocator::ValidateIntervals( - intervals, 0, 0, *codegen, &allocator, true, false)); + intervals, 0, 0, codegen, &allocator, true, false)); intervals.Get(1)->SetRegister(0); ASSERT_FALSE(RegisterAllocator::ValidateIntervals( - intervals, 0, 0, *codegen, &allocator, true, false)); + intervals, 0, 0, codegen, &allocator, true, false)); intervals.Reset(); } @@ -127,16 +128,16 @@ TEST(RegisterAllocatorTest, ValidateIntervals) { static constexpr size_t ranges2[][2] = {{42, 47}}; intervals.Add(BuildInterval(ranges2, arraysize(ranges2), &allocator, 1)); ASSERT_TRUE(RegisterAllocator::ValidateIntervals( - intervals, 0, 0, *codegen, &allocator, true, false)); + intervals, 0, 0, codegen, &allocator, true, false)); intervals.Get(1)->SetRegister(0); // Sibling of the first interval has no register allocated to it. ASSERT_TRUE(RegisterAllocator::ValidateIntervals( - intervals, 0, 0, *codegen, &allocator, true, false)); + intervals, 0, 0, codegen, &allocator, true, false)); intervals.Get(0)->GetNextSibling()->SetRegister(0); ASSERT_FALSE(RegisterAllocator::ValidateIntervals( - intervals, 0, 0, *codegen, &allocator, true, false)); + intervals, 0, 0, codegen, &allocator, true, false)); } } @@ -298,10 +299,10 @@ TEST(RegisterAllocatorTest, Loop3) { ArenaPool pool; ArenaAllocator allocator(&pool); HGraph* graph = BuildSSAGraph(data, &allocator); - CodeGenerator* codegen = CodeGenerator::Create(&allocator, graph, kX86); - SsaLivenessAnalysis liveness(*graph, codegen); + x86::CodeGeneratorX86 codegen(graph); + SsaLivenessAnalysis liveness(*graph, &codegen); liveness.Analyze(); - RegisterAllocator register_allocator(&allocator, codegen, liveness); + RegisterAllocator register_allocator(&allocator, &codegen, liveness); register_allocator.AllocateRegisters(); ASSERT_TRUE(register_allocator.Validate(false)); @@ -330,8 +331,8 @@ TEST(RegisterAllocatorTest, FirstRegisterUse) { ArenaPool pool; ArenaAllocator allocator(&pool); HGraph* graph = BuildSSAGraph(data, &allocator); - CodeGenerator* codegen = CodeGenerator::Create(&allocator, graph, kArm); - SsaLivenessAnalysis liveness(*graph, codegen); + x86::CodeGeneratorX86 codegen(graph); + SsaLivenessAnalysis liveness(*graph, &codegen); liveness.Analyze(); HAdd* first_add = graph->GetBlocks().Get(1)->GetFirstInstruction()->AsAdd(); @@ -383,10 +384,10 @@ TEST(RegisterAllocatorTest, DeadPhi) { ArenaAllocator allocator(&pool); HGraph* graph = BuildSSAGraph(data, &allocator); SsaDeadPhiElimination(graph).Run(); - CodeGenerator* codegen = CodeGenerator::Create(&allocator, graph, kX86); - SsaLivenessAnalysis liveness(*graph, codegen); + x86::CodeGeneratorX86 codegen(graph); + SsaLivenessAnalysis liveness(*graph, &codegen); liveness.Analyze(); - RegisterAllocator register_allocator(&allocator, codegen, liveness); + RegisterAllocator register_allocator(&allocator, &codegen, liveness); register_allocator.AllocateRegisters(); ASSERT_TRUE(register_allocator.Validate(false)); } diff --git a/compiler/optimizing/ssa_liveness_analysis.cc b/compiler/optimizing/ssa_liveness_analysis.cc index 5de1ab9c31..680cc0a033 100644 --- a/compiler/optimizing/ssa_liveness_analysis.cc +++ b/compiler/optimizing/ssa_liveness_analysis.cc @@ -102,13 +102,14 @@ void SsaLivenessAnalysis::NumberInstructions() { // to differentiate between the start and end of an instruction. Adding 2 to // the lifetime position for each instruction ensures the start of an // instruction is different than the end of the previous instruction. + HGraphVisitor* location_builder = codegen_->GetLocationBuilder(); for (HLinearOrderIterator it(*this); !it.Done(); it.Advance()) { HBasicBlock* block = it.Current(); block->SetLifetimeStart(lifetime_position); for (HInstructionIterator it(block->GetPhis()); !it.Done(); it.Advance()) { HInstruction* current = it.Current(); - current->Accept(codegen_->GetLocationBuilder()); + current->Accept(location_builder); LocationSummary* locations = current->GetLocations(); if (locations != nullptr && locations->Out().IsValid()) { instructions_from_ssa_index_.Add(current); |