diff options
Diffstat (limited to 'compiler/optimizing/dominator_test.cc')
-rw-r--r-- | compiler/optimizing/dominator_test.cc | 135 |
1 files changed, 65 insertions, 70 deletions
diff --git a/compiler/optimizing/dominator_test.cc b/compiler/optimizing/dominator_test.cc index 30f288ff54..9b68535268 100644 --- a/compiler/optimizing/dominator_test.cc +++ b/compiler/optimizing/dominator_test.cc @@ -17,17 +17,19 @@ #include "builder.h" #include "dex_instruction.h" #include "nodes.h" +#include "optimizing_unit_test.h" #include "utils/arena_allocator.h" #include "gtest/gtest.h" namespace art { -static void TestCode(const uint16_t* data, int length, const int* blocks, size_t blocks_length) { +static void TestCode(const uint16_t* data, const int* blocks, size_t blocks_length) { ArenaPool pool; ArenaAllocator allocator(&pool); HGraphBuilder builder(&allocator); - HGraph* graph = builder.BuildGraph(data, data + length); + const DexFile::CodeItem* item = reinterpret_cast<const DexFile::CodeItem*>(data); + HGraph* graph = builder.BuildGraph(*item); ASSERT_NE(graph, nullptr); graph->BuildDominatorTree(); ASSERT_EQ(graph->blocks()->Size(), blocks_length); @@ -42,9 +44,8 @@ static void TestCode(const uint16_t* data, int length, const int* blocks, size_t } TEST(OptimizerTest, ReturnVoid) { - const uint16_t data[] = { - Instruction::RETURN_VOID // Block number 1 - }; + const uint16_t data[] = ZERO_REGISTER_CODE_ITEM( + Instruction::RETURN_VOID); // Block number 1 const int dominators[] = { -1, @@ -52,14 +53,13 @@ TEST(OptimizerTest, ReturnVoid) { 1 }; - TestCode(data, sizeof(data) / sizeof(uint16_t), dominators, sizeof(dominators) / sizeof(int)); + TestCode(data, dominators, sizeof(dominators) / sizeof(int)); } TEST(OptimizerTest, CFG1) { - const uint16_t data[] = { + const uint16_t data[] = ZERO_REGISTER_CODE_ITEM( Instruction::GOTO | 0x100, // Block number 1 - Instruction::RETURN_VOID // Block number 2 - }; + Instruction::RETURN_VOID); // Block number 2 const int dominators[] = { -1, @@ -68,15 +68,14 @@ TEST(OptimizerTest, CFG1) { 2 }; - TestCode(data, sizeof(data) / sizeof(uint16_t), dominators, sizeof(dominators) / sizeof(int)); + TestCode(data, dominators, sizeof(dominators) / sizeof(int)); } TEST(OptimizerTest, CFG2) { - const uint16_t data[] = { + const uint16_t data[] = ZERO_REGISTER_CODE_ITEM( Instruction::GOTO | 0x100, // Block number 1 Instruction::GOTO | 0x100, // Block number 2 - Instruction::RETURN_VOID // Block number 3 - }; + Instruction::RETURN_VOID); // Block number 3 const int dominators[] = { -1, @@ -86,15 +85,15 @@ TEST(OptimizerTest, CFG2) { 3 }; - TestCode(data, sizeof(data) / sizeof(uint16_t), dominators, sizeof(dominators) / sizeof(int)); + TestCode(data, dominators, sizeof(dominators) / sizeof(int)); } TEST(OptimizerTest, CFG3) { - const uint16_t data1[] = { - Instruction::GOTO | 0x200, // Block number 1 - Instruction::RETURN_VOID, // Block number 2 - Instruction::GOTO | 0xFF00 // Block number 3 - }; + const uint16_t data1[] = ZERO_REGISTER_CODE_ITEM( + Instruction::GOTO | 0x200, // Block number 1 + Instruction::RETURN_VOID, // Block number 2 + Instruction::GOTO | 0xFF00); // Block number 3 + const int dominators[] = { -1, 0, @@ -103,30 +102,27 @@ TEST(OptimizerTest, CFG3) { 2 }; - TestCode(data1, sizeof(data1) / sizeof(uint16_t), dominators, sizeof(dominators) / sizeof(int)); + TestCode(data1, dominators, sizeof(dominators) / sizeof(int)); - const uint16_t data2[] = { + const uint16_t data2[] = ZERO_REGISTER_CODE_ITEM( Instruction::GOTO_16, 3, Instruction::RETURN_VOID, - Instruction::GOTO_16, 0xFFFF - }; + Instruction::GOTO_16, 0xFFFF); - TestCode(data2, sizeof(data2) / sizeof(uint16_t), dominators, sizeof(dominators) / sizeof(int)); + TestCode(data2, dominators, sizeof(dominators) / sizeof(int)); - const uint16_t data3[] = { + const uint16_t data3[] = ZERO_REGISTER_CODE_ITEM( Instruction::GOTO_32, 4, 0, Instruction::RETURN_VOID, - Instruction::GOTO_32, 0xFFFF, 0xFFFF - }; + Instruction::GOTO_32, 0xFFFF, 0xFFFF); - TestCode(data3, sizeof(data3) / sizeof(uint16_t), dominators, sizeof(dominators) / sizeof(int)); + TestCode(data3, dominators, sizeof(dominators) / sizeof(int)); } TEST(OptimizerTest, CFG4) { - const uint16_t data1[] = { + const uint16_t data1[] = ZERO_REGISTER_CODE_ITEM( Instruction::NOP, - Instruction::GOTO | 0xFF00 - }; + Instruction::GOTO | 0xFF00); const int dominators[] = { -1, @@ -134,21 +130,20 @@ TEST(OptimizerTest, CFG4) { -1 }; - TestCode(data1, sizeof(data1) / sizeof(uint16_t), dominators, sizeof(dominators) / sizeof(int)); + TestCode(data1, dominators, sizeof(dominators) / sizeof(int)); - const uint16_t data2[] = { - Instruction::GOTO_32, 0, 0 - }; + const uint16_t data2[] = ZERO_REGISTER_CODE_ITEM( + Instruction::GOTO_32, 0, 0); - TestCode(data2, sizeof(data2) / sizeof(uint16_t), dominators, sizeof(dominators) / sizeof(int)); + TestCode(data2, dominators, sizeof(dominators) / sizeof(int)); } TEST(OptimizerTest, CFG5) { - const uint16_t data[] = { - Instruction::RETURN_VOID, // Block number 1 - Instruction::GOTO | 0x100, // Dead block - Instruction::GOTO | 0xFE00 // Block number 2 - }; + const uint16_t data[] = ZERO_REGISTER_CODE_ITEM( + Instruction::RETURN_VOID, // Block number 1 + Instruction::GOTO | 0x100, // Dead block + Instruction::GOTO | 0xFE00); // Block number 2 + const int dominators[] = { -1, @@ -157,15 +152,15 @@ TEST(OptimizerTest, CFG5) { 1 }; - TestCode(data, sizeof(data) / sizeof(uint16_t), dominators, sizeof(dominators) / sizeof(int)); + TestCode(data, dominators, sizeof(dominators) / sizeof(int)); } TEST(OptimizerTest, CFG6) { - const uint16_t data[] = { + const uint16_t data[] = ONE_REGISTER_CODE_ITEM( + Instruction::CONST_4 | 0 | 0, Instruction::IF_EQ, 3, Instruction::GOTO | 0x100, - Instruction::RETURN_VOID - }; + Instruction::RETURN_VOID); const int dominators[] = { -1, @@ -175,15 +170,15 @@ TEST(OptimizerTest, CFG6) { 3 }; - TestCode(data, sizeof(data) / sizeof(uint16_t), dominators, sizeof(dominators) / sizeof(int)); + TestCode(data, dominators, sizeof(dominators) / sizeof(int)); } TEST(OptimizerTest, CFG7) { - const uint16_t data[] = { - Instruction::IF_EQ, 3, // Block number 1 - Instruction::GOTO | 0x100, // Block number 2 - Instruction::GOTO | 0xFF00 // Block number 3 - }; + const uint16_t data[] = ONE_REGISTER_CODE_ITEM( + Instruction::CONST_4 | 0 | 0, + Instruction::IF_EQ, 3, // Block number 1 + Instruction::GOTO | 0x100, // Block number 2 + Instruction::GOTO | 0xFF00); // Block number 3 const int dominators[] = { -1, @@ -193,16 +188,16 @@ TEST(OptimizerTest, CFG7) { -1 // exit block is not dominated by any block due to the spin loop. }; - TestCode(data, sizeof(data) / sizeof(uint16_t), dominators, sizeof(dominators) / sizeof(int)); + TestCode(data, dominators, sizeof(dominators) / sizeof(int)); } TEST(OptimizerTest, CFG8) { - const uint16_t data[] = { - Instruction::IF_EQ, 3, // Block number 1 - Instruction::GOTO | 0x200, // Block number 2 - Instruction::GOTO | 0x100, // Block number 3 - Instruction::GOTO | 0xFF00 // Block number 4 - }; + const uint16_t data[] = ONE_REGISTER_CODE_ITEM( + Instruction::CONST_4 | 0 | 0, + Instruction::IF_EQ, 3, // Block number 1 + Instruction::GOTO | 0x200, // Block number 2 + Instruction::GOTO | 0x100, // Block number 3 + Instruction::GOTO | 0xFF00); // Block number 4 const int dominators[] = { -1, @@ -213,16 +208,16 @@ TEST(OptimizerTest, CFG8) { -1 // exit block is not dominated by any block due to the spin loop. }; - TestCode(data, sizeof(data) / sizeof(uint16_t), dominators, sizeof(dominators) / sizeof(int)); + TestCode(data, dominators, sizeof(dominators) / sizeof(int)); } TEST(OptimizerTest, CFG9) { - const uint16_t data[] = { - Instruction::IF_EQ, 3, // Block number 1 - Instruction::GOTO | 0x200, // Block number 2 - Instruction::GOTO | 0x100, // Block number 3 - Instruction::GOTO | 0xFE00 // Block number 4 - }; + const uint16_t data[] = ONE_REGISTER_CODE_ITEM( + Instruction::CONST_4 | 0 | 0, + Instruction::IF_EQ, 3, // Block number 1 + Instruction::GOTO | 0x200, // Block number 2 + Instruction::GOTO | 0x100, // Block number 3 + Instruction::GOTO | 0xFE00); // Block number 4 const int dominators[] = { -1, @@ -233,17 +228,17 @@ TEST(OptimizerTest, CFG9) { -1 // exit block is not dominated by any block due to the spin loop. }; - TestCode(data, sizeof(data) / sizeof(uint16_t), dominators, sizeof(dominators) / sizeof(int)); + TestCode(data, dominators, sizeof(dominators) / sizeof(int)); } TEST(OptimizerTest, CFG10) { - const uint16_t data[] = { + const uint16_t data[] = ONE_REGISTER_CODE_ITEM( + Instruction::CONST_4 | 0 | 0, Instruction::IF_EQ, 6, // Block number 1 Instruction::IF_EQ, 3, // Block number 2 Instruction::GOTO | 0x100, // Block number 3 Instruction::GOTO | 0x100, // Block number 4 - Instruction::RETURN_VOID // Block number 5 - }; + Instruction::RETURN_VOID); // Block number 5 const int dominators[] = { -1, @@ -255,7 +250,7 @@ TEST(OptimizerTest, CFG10) { 5 // Block number 5 dominates exit block }; - TestCode(data, sizeof(data) / sizeof(uint16_t), dominators, sizeof(dominators) / sizeof(int)); + TestCode(data, dominators, sizeof(dominators) / sizeof(int)); } } // namespace art |