diff options
Diffstat (limited to 'compiler/optimizing/graph_test.cc')
-rw-r--r-- | compiler/optimizing/graph_test.cc | 150 |
1 files changed, 69 insertions, 81 deletions
diff --git a/compiler/optimizing/graph_test.cc b/compiler/optimizing/graph_test.cc index 28ee3a5e8b..29af808731 100644 --- a/compiler/optimizing/graph_test.cc +++ b/compiler/optimizing/graph_test.cc @@ -24,43 +24,52 @@ namespace art { -static HBasicBlock* createIfBlock(HGraph* graph, ArenaAllocator* allocator) { - HBasicBlock* if_block = new (allocator) HBasicBlock(graph); +class GraphTest : public OptimizingUnitTest { + protected: + HBasicBlock* CreateIfBlock(HGraph* graph); + HBasicBlock* CreateGotoBlock(HGraph* graph); + HBasicBlock* CreateEntryBlock(HGraph* graph); + HBasicBlock* CreateReturnBlock(HGraph* graph); + HBasicBlock* CreateExitBlock(HGraph* graph); +}; + +HBasicBlock* GraphTest::CreateIfBlock(HGraph* graph) { + HBasicBlock* if_block = new (GetAllocator()) HBasicBlock(graph); graph->AddBlock(if_block); HInstruction* instr = graph->GetIntConstant(4); - HInstruction* equal = new (allocator) HEqual(instr, instr); + HInstruction* equal = new (GetAllocator()) HEqual(instr, instr); if_block->AddInstruction(equal); - instr = new (allocator) HIf(equal); + instr = new (GetAllocator()) HIf(equal); if_block->AddInstruction(instr); return if_block; } -static HBasicBlock* createGotoBlock(HGraph* graph, ArenaAllocator* allocator) { - HBasicBlock* block = new (allocator) HBasicBlock(graph); +HBasicBlock* GraphTest::CreateGotoBlock(HGraph* graph) { + HBasicBlock* block = new (GetAllocator()) HBasicBlock(graph); graph->AddBlock(block); - HInstruction* got = new (allocator) HGoto(); + HInstruction* got = new (GetAllocator()) HGoto(); block->AddInstruction(got); return block; } -static HBasicBlock* createEntryBlock(HGraph* graph, ArenaAllocator* allocator) { - HBasicBlock* block = createGotoBlock(graph, allocator); +HBasicBlock* GraphTest::CreateEntryBlock(HGraph* graph) { + HBasicBlock* block = CreateGotoBlock(graph); graph->SetEntryBlock(block); return block; } -static HBasicBlock* createReturnBlock(HGraph* graph, ArenaAllocator* allocator) { - HBasicBlock* block = new (allocator) HBasicBlock(graph); +HBasicBlock* GraphTest::CreateReturnBlock(HGraph* graph) { + HBasicBlock* block = new (GetAllocator()) HBasicBlock(graph); graph->AddBlock(block); - HInstruction* return_instr = new (allocator) HReturnVoid(); + HInstruction* return_instr = new (GetAllocator()) HReturnVoid(); block->AddInstruction(return_instr); return block; } -static HBasicBlock* createExitBlock(HGraph* graph, ArenaAllocator* allocator) { - HBasicBlock* block = new (allocator) HBasicBlock(graph); +HBasicBlock* GraphTest::CreateExitBlock(HGraph* graph) { + HBasicBlock* block = new (GetAllocator()) HBasicBlock(graph); graph->AddBlock(block); - HInstruction* exit_instr = new (allocator) HExit(); + HInstruction* exit_instr = new (GetAllocator()) HExit(); block->AddInstruction(exit_instr); return block; } @@ -68,16 +77,13 @@ static HBasicBlock* createExitBlock(HGraph* graph, ArenaAllocator* allocator) { // Test that the successors of an if block stay consistent after a SimplifyCFG. // This test sets the false block to be the return block. -TEST(GraphTest, IfSuccessorSimpleJoinBlock1) { - ArenaPool pool; - ArenaAllocator allocator(&pool); - - HGraph* graph = CreateGraph(&allocator); - HBasicBlock* entry_block = createEntryBlock(graph, &allocator); - HBasicBlock* if_block = createIfBlock(graph, &allocator); - HBasicBlock* if_true = createGotoBlock(graph, &allocator); - HBasicBlock* return_block = createReturnBlock(graph, &allocator); - HBasicBlock* exit_block = createExitBlock(graph, &allocator); +TEST_F(GraphTest, IfSuccessorSimpleJoinBlock1) { + HGraph* graph = CreateGraph(); + HBasicBlock* entry_block = CreateEntryBlock(graph); + HBasicBlock* if_block = CreateIfBlock(graph); + HBasicBlock* if_true = CreateGotoBlock(graph); + HBasicBlock* return_block = CreateReturnBlock(graph); + HBasicBlock* exit_block = CreateExitBlock(graph); entry_block->AddSuccessor(if_block); if_block->AddSuccessor(if_true); @@ -103,16 +109,13 @@ TEST(GraphTest, IfSuccessorSimpleJoinBlock1) { // Test that the successors of an if block stay consistent after a SimplifyCFG. // This test sets the true block to be the return block. -TEST(GraphTest, IfSuccessorSimpleJoinBlock2) { - ArenaPool pool; - ArenaAllocator allocator(&pool); - - HGraph* graph = CreateGraph(&allocator); - HBasicBlock* entry_block = createEntryBlock(graph, &allocator); - HBasicBlock* if_block = createIfBlock(graph, &allocator); - HBasicBlock* if_false = createGotoBlock(graph, &allocator); - HBasicBlock* return_block = createReturnBlock(graph, &allocator); - HBasicBlock* exit_block = createExitBlock(graph, &allocator); +TEST_F(GraphTest, IfSuccessorSimpleJoinBlock2) { + HGraph* graph = CreateGraph(); + HBasicBlock* entry_block = CreateEntryBlock(graph); + HBasicBlock* if_block = CreateIfBlock(graph); + HBasicBlock* if_false = CreateGotoBlock(graph); + HBasicBlock* return_block = CreateReturnBlock(graph); + HBasicBlock* exit_block = CreateExitBlock(graph); entry_block->AddSuccessor(if_block); if_block->AddSuccessor(return_block); @@ -138,15 +141,12 @@ TEST(GraphTest, IfSuccessorSimpleJoinBlock2) { // Test that the successors of an if block stay consistent after a SimplifyCFG. // This test sets the true block to be the loop header. -TEST(GraphTest, IfSuccessorMultipleBackEdges1) { - ArenaPool pool; - ArenaAllocator allocator(&pool); - - HGraph* graph = CreateGraph(&allocator); - HBasicBlock* entry_block = createEntryBlock(graph, &allocator); - HBasicBlock* if_block = createIfBlock(graph, &allocator); - HBasicBlock* return_block = createReturnBlock(graph, &allocator); - HBasicBlock* exit_block = createExitBlock(graph, &allocator); +TEST_F(GraphTest, IfSuccessorMultipleBackEdges1) { + HGraph* graph = CreateGraph(); + HBasicBlock* entry_block = CreateEntryBlock(graph); + HBasicBlock* if_block = CreateIfBlock(graph); + HBasicBlock* return_block = CreateReturnBlock(graph); + HBasicBlock* exit_block = CreateExitBlock(graph); entry_block->AddSuccessor(if_block); if_block->AddSuccessor(if_block); @@ -173,15 +173,12 @@ TEST(GraphTest, IfSuccessorMultipleBackEdges1) { // Test that the successors of an if block stay consistent after a SimplifyCFG. // This test sets the false block to be the loop header. -TEST(GraphTest, IfSuccessorMultipleBackEdges2) { - ArenaPool pool; - ArenaAllocator allocator(&pool); - - HGraph* graph = CreateGraph(&allocator); - HBasicBlock* entry_block = createEntryBlock(graph, &allocator); - HBasicBlock* if_block = createIfBlock(graph, &allocator); - HBasicBlock* return_block = createReturnBlock(graph, &allocator); - HBasicBlock* exit_block = createExitBlock(graph, &allocator); +TEST_F(GraphTest, IfSuccessorMultipleBackEdges2) { + HGraph* graph = CreateGraph(); + HBasicBlock* entry_block = CreateEntryBlock(graph); + HBasicBlock* if_block = CreateIfBlock(graph); + HBasicBlock* return_block = CreateReturnBlock(graph); + HBasicBlock* exit_block = CreateExitBlock(graph); entry_block->AddSuccessor(if_block); if_block->AddSuccessor(return_block); @@ -208,16 +205,13 @@ TEST(GraphTest, IfSuccessorMultipleBackEdges2) { // Test that the successors of an if block stay consistent after a SimplifyCFG. // This test sets the true block to be a loop header with multiple pre headers. -TEST(GraphTest, IfSuccessorMultiplePreHeaders1) { - ArenaPool pool; - ArenaAllocator allocator(&pool); - - HGraph* graph = CreateGraph(&allocator); - HBasicBlock* entry_block = createEntryBlock(graph, &allocator); - HBasicBlock* first_if_block = createIfBlock(graph, &allocator); - HBasicBlock* if_block = createIfBlock(graph, &allocator); - HBasicBlock* loop_block = createGotoBlock(graph, &allocator); - HBasicBlock* return_block = createReturnBlock(graph, &allocator); +TEST_F(GraphTest, IfSuccessorMultiplePreHeaders1) { + HGraph* graph = CreateGraph(); + HBasicBlock* entry_block = CreateEntryBlock(graph); + HBasicBlock* first_if_block = CreateIfBlock(graph); + HBasicBlock* if_block = CreateIfBlock(graph); + HBasicBlock* loop_block = CreateGotoBlock(graph); + HBasicBlock* return_block = CreateReturnBlock(graph); entry_block->AddSuccessor(first_if_block); first_if_block->AddSuccessor(if_block); @@ -247,16 +241,13 @@ TEST(GraphTest, IfSuccessorMultiplePreHeaders1) { // Test that the successors of an if block stay consistent after a SimplifyCFG. // This test sets the false block to be a loop header with multiple pre headers. -TEST(GraphTest, IfSuccessorMultiplePreHeaders2) { - ArenaPool pool; - ArenaAllocator allocator(&pool); - - HGraph* graph = CreateGraph(&allocator); - HBasicBlock* entry_block = createEntryBlock(graph, &allocator); - HBasicBlock* first_if_block = createIfBlock(graph, &allocator); - HBasicBlock* if_block = createIfBlock(graph, &allocator); - HBasicBlock* loop_block = createGotoBlock(graph, &allocator); - HBasicBlock* return_block = createReturnBlock(graph, &allocator); +TEST_F(GraphTest, IfSuccessorMultiplePreHeaders2) { + HGraph* graph = CreateGraph(); + HBasicBlock* entry_block = CreateEntryBlock(graph); + HBasicBlock* first_if_block = CreateIfBlock(graph); + HBasicBlock* if_block = CreateIfBlock(graph); + HBasicBlock* loop_block = CreateGotoBlock(graph); + HBasicBlock* return_block = CreateReturnBlock(graph); entry_block->AddSuccessor(first_if_block); first_if_block->AddSuccessor(if_block); @@ -283,17 +274,14 @@ TEST(GraphTest, IfSuccessorMultiplePreHeaders2) { loop_block->GetLoopInformation()->GetPreHeader()); } -TEST(GraphTest, InsertInstructionBefore) { - ArenaPool pool; - ArenaAllocator allocator(&pool); - - HGraph* graph = CreateGraph(&allocator); - HBasicBlock* block = createGotoBlock(graph, &allocator); +TEST_F(GraphTest, InsertInstructionBefore) { + HGraph* graph = CreateGraph(); + HBasicBlock* block = CreateGotoBlock(graph); HInstruction* got = block->GetLastInstruction(); ASSERT_TRUE(got->IsControlFlow()); // Test at the beginning of the block. - HInstruction* first_instruction = new (&allocator) HIntConstant(4); + HInstruction* first_instruction = new (GetAllocator()) HIntConstant(4); block->InsertInstructionBefore(first_instruction, got); ASSERT_NE(first_instruction->GetId(), -1); @@ -306,7 +294,7 @@ TEST(GraphTest, InsertInstructionBefore) { ASSERT_EQ(got->GetPrevious(), first_instruction); // Test in the middle of the block. - HInstruction* second_instruction = new (&allocator) HIntConstant(4); + HInstruction* second_instruction = new (GetAllocator()) HIntConstant(4); block->InsertInstructionBefore(second_instruction, got); ASSERT_NE(second_instruction->GetId(), -1); |