diff options
author | Nicolas Geoffray <ngeoffray@google.com> | 2014-03-13 09:24:22 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2014-03-13 09:24:22 +0000 |
commit | af7ec0e4efd43aaa58094d036c85736059d9f18d (patch) | |
tree | a9ad45cd9979880f7eec3952590c114c55a37f65 /compiler/optimizing/codegen_test.cc | |
parent | 9dd077cc71c12576a52c51ae19fe15306ce12eaa (diff) | |
parent | bab4ed7057799a4fadc6283108ab56f389d117d4 (diff) |
Merge "More code generation for the optimizing compiler."
Diffstat (limited to 'compiler/optimizing/codegen_test.cc')
-rw-r--r-- | compiler/optimizing/codegen_test.cc | 85 |
1 files changed, 77 insertions, 8 deletions
diff --git a/compiler/optimizing/codegen_test.cc b/compiler/optimizing/codegen_test.cc index 6d4588dd3d..a6ecdfbe21 100644 --- a/compiler/optimizing/codegen_test.cc +++ b/compiler/optimizing/codegen_test.cc @@ -45,7 +45,7 @@ class ExecutableMemoryAllocator : public CodeAllocator { DISALLOW_COPY_AND_ASSIGN(ExecutableMemoryAllocator); }; -static void TestCode(const uint16_t* data) { +static void TestCode(const uint16_t* data, bool has_result = false, int32_t expected = 0) { ArenaPool pool; ArenaAllocator arena(&pool); HGraphBuilder builder(&arena); @@ -54,14 +54,17 @@ static void TestCode(const uint16_t* data) { ASSERT_NE(graph, nullptr); ExecutableMemoryAllocator allocator; CHECK(CodeGenerator::CompileGraph(graph, kX86, &allocator)); - typedef void (*fptr)(); + typedef int32_t (*fptr)(); #if defined(__i386__) - reinterpret_cast<fptr>(allocator.memory())(); + int32_t result = reinterpret_cast<fptr>(allocator.memory())(); #endif CHECK(CodeGenerator::CompileGraph(graph, kArm, &allocator)); #if defined(__arm__) - reinterpret_cast<fptr>(allocator.memory())(); + int32_t result = reinterpret_cast<fptr>(allocator.memory())(); #endif + if (has_result) { + CHECK_EQ(result, expected); + } } TEST(CodegenTest, ReturnVoid) { @@ -69,7 +72,7 @@ TEST(CodegenTest, ReturnVoid) { TestCode(data); } -TEST(PrettyPrinterTest, CFG1) { +TEST(CodegenTest, CFG1) { const uint16_t data[] = ZERO_REGISTER_CODE_ITEM( Instruction::GOTO | 0x100, Instruction::RETURN_VOID); @@ -77,7 +80,7 @@ TEST(PrettyPrinterTest, CFG1) { TestCode(data); } -TEST(PrettyPrinterTest, CFG2) { +TEST(CodegenTest, CFG2) { const uint16_t data[] = ZERO_REGISTER_CODE_ITEM( Instruction::GOTO | 0x100, Instruction::GOTO | 0x100, @@ -86,7 +89,7 @@ TEST(PrettyPrinterTest, CFG2) { TestCode(data); } -TEST(PrettyPrinterTest, CFG3) { +TEST(CodegenTest, CFG3) { const uint16_t data1[] = ZERO_REGISTER_CODE_ITEM( Instruction::GOTO | 0x200, Instruction::RETURN_VOID, @@ -109,7 +112,7 @@ TEST(PrettyPrinterTest, CFG3) { TestCode(data3); } -TEST(PrettyPrinterTest, CFG4) { +TEST(CodegenTest, CFG4) { const uint16_t data[] = ZERO_REGISTER_CODE_ITEM( Instruction::RETURN_VOID, Instruction::GOTO | 0x100, @@ -118,4 +121,70 @@ TEST(PrettyPrinterTest, CFG4) { TestCode(data); } +TEST(CodegenTest, CFG5) { + const uint16_t data[] = ONE_REGISTER_CODE_ITEM( + Instruction::CONST_4 | 0 | 0, + Instruction::IF_EQ, 3, + Instruction::GOTO | 0x100, + Instruction::RETURN_VOID); + + TestCode(data); +} + +TEST(CodegenTest, IntConstant) { + const uint16_t data[] = ONE_REGISTER_CODE_ITEM( + Instruction::CONST_4 | 0 | 0, + Instruction::RETURN_VOID); + + TestCode(data); +} + +TEST(CodegenTest, Return1) { + const uint16_t data[] = ONE_REGISTER_CODE_ITEM( + Instruction::CONST_4 | 0 | 0, + Instruction::RETURN | 0); + + TestCode(data, true, 0); +} + +TEST(CodegenTest, Return2) { + const uint16_t data[] = TWO_REGISTERS_CODE_ITEM( + Instruction::CONST_4 | 0 | 0, + Instruction::CONST_4 | 0 | 1 << 8, + Instruction::RETURN | 1 << 8); + + TestCode(data, true, 0); +} + +TEST(CodegenTest, Return3) { + const uint16_t data[] = TWO_REGISTERS_CODE_ITEM( + Instruction::CONST_4 | 0 | 0, + Instruction::CONST_4 | 1 << 8 | 1 << 12, + Instruction::RETURN | 1 << 8); + + TestCode(data, true, 1); +} + +TEST(CodegenTest, ReturnIf1) { + const uint16_t data[] = TWO_REGISTERS_CODE_ITEM( + Instruction::CONST_4 | 0 | 0, + Instruction::CONST_4 | 1 << 8 | 1 << 12, + Instruction::IF_EQ, 3, + Instruction::RETURN | 0 << 8, + Instruction::RETURN | 1 << 8); + + TestCode(data, true, 1); +} + +TEST(CodegenTest, ReturnIf2) { + const uint16_t data[] = TWO_REGISTERS_CODE_ITEM( + Instruction::CONST_4 | 0 | 0, + Instruction::CONST_4 | 1 << 8 | 1 << 12, + Instruction::IF_EQ | 0 << 4 | 1 << 8, 3, + Instruction::RETURN | 0 << 8, + Instruction::RETURN | 1 << 8); + + TestCode(data, true, 0); +} + } // namespace art |