summaryrefslogtreecommitdiffstats
path: root/compiler/optimizing/pretty_printer_test.cc
diff options
context:
space:
mode:
authorNicolas Geoffray <ngeoffray@google.com>2014-03-04 14:46:47 +0000
committerNicolas Geoffray <ngeoffray@google.com>2014-03-10 11:41:22 +0000
commit3ff386aafefd5282bb76c8a50506a70a4321e698 (patch)
tree5f6e990553daae150a168f581bac79e659f7f712 /compiler/optimizing/pretty_printer_test.cc
parent0307b5c91c287e08cd414ecc5de32befceb7e371 (diff)
downloadart-3ff386aafefd5282bb76c8a50506a70a4321e698.zip
art-3ff386aafefd5282bb76c8a50506a70a4321e698.tar.gz
art-3ff386aafefd5282bb76c8a50506a70a4321e698.tar.bz2
Add register support to the optimizing compiler.
Also make if take an input and build the use list for instructions. Change-Id: I1938cee7dce5bd4c66b259fa2b431d2c79b3cf82
Diffstat (limited to 'compiler/optimizing/pretty_printer_test.cc')
-rw-r--r--compiler/optimizing/pretty_printer_test.cc195
1 files changed, 112 insertions, 83 deletions
diff --git a/compiler/optimizing/pretty_printer_test.cc b/compiler/optimizing/pretty_printer_test.cc
index 4c8201e..b99370d 100644
--- a/compiler/optimizing/pretty_printer_test.cc
+++ b/compiler/optimizing/pretty_printer_test.cc
@@ -16,8 +16,10 @@
#include "base/stringprintf.h"
#include "builder.h"
+#include "dex_file.h"
#include "dex_instruction.h"
#include "nodes.h"
+#include "optimizing_unit_test.h"
#include "pretty_printer.h"
#include "utils/arena_allocator.h"
@@ -52,7 +54,9 @@ class StringPrettyPrinter : public HPrettyPrinter {
}
virtual void VisitGoto(HGoto* gota) {
- str_ += " Goto ";
+ PrintString(" ");
+ PrintInt(gota->id());
+ PrintString(": Goto ");
PrintInt(current_block_->successors()->Get(0)->block_id());
PrintNewLine();
}
@@ -64,12 +68,12 @@ class StringPrettyPrinter : public HPrettyPrinter {
DISALLOW_COPY_AND_ASSIGN(StringPrettyPrinter);
};
-
-static void TestCode(const uint16_t* data, int length, const char* expected) {
+static void TestCode(const uint16_t* data, const char* expected) {
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);
StringPrettyPrinter printer(graph);
printer.VisitInsertionOrder();
@@ -77,182 +81,207 @@ static void TestCode(const uint16_t* data, int length, const char* expected) {
}
TEST(PrettyPrinterTest, ReturnVoid) {
- const uint16_t data[] = { Instruction::RETURN_VOID };
+ const uint16_t data[] = ZERO_REGISTER_CODE_ITEM(
+ Instruction::RETURN_VOID);
const char* expected =
"BasicBlock 0, succ: 1\n"
- " Goto 1\n"
+ " 2: Goto 1\n"
"BasicBlock 1, pred: 0, succ: 2\n"
- " ReturnVoid\n"
+ " 0: ReturnVoid\n"
"BasicBlock 2, pred: 1\n"
- " Exit\n";
+ " 1: Exit\n";
- TestCode(data, sizeof(data) / sizeof(uint16_t), expected);
+ TestCode(data, expected);
}
TEST(PrettyPrinterTest, CFG1) {
const char* expected =
"BasicBlock 0, succ: 1\n"
- " Goto 1\n"
+ " 3: Goto 1\n"
"BasicBlock 1, pred: 0, succ: 2\n"
- " Goto 2\n"
+ " 0: Goto 2\n"
"BasicBlock 2, pred: 1, succ: 3\n"
- " ReturnVoid\n"
+ " 1: ReturnVoid\n"
"BasicBlock 3, pred: 2\n"
- " Exit\n";
+ " 2: Exit\n";
- const uint16_t data[] = {
- Instruction::GOTO | 0x100,
- Instruction::RETURN_VOID
- };
+ const uint16_t data[] =
+ ZERO_REGISTER_CODE_ITEM(
+ Instruction::GOTO | 0x100,
+ Instruction::RETURN_VOID);
- TestCode(data, sizeof(data) / sizeof(uint16_t), expected);
+ TestCode(data, expected);
}
TEST(PrettyPrinterTest, CFG2) {
const char* expected =
"BasicBlock 0, succ: 1\n"
- " Goto 1\n"
+ " 4: Goto 1\n"
"BasicBlock 1, pred: 0, succ: 2\n"
- " Goto 2\n"
+ " 0: Goto 2\n"
"BasicBlock 2, pred: 1, succ: 3\n"
- " Goto 3\n"
+ " 1: Goto 3\n"
"BasicBlock 3, pred: 2, succ: 4\n"
- " ReturnVoid\n"
+ " 2: ReturnVoid\n"
"BasicBlock 4, pred: 3\n"
- " Exit\n";
+ " 3: Exit\n";
- const uint16_t data[] = {
+ const uint16_t data[] = ZERO_REGISTER_CODE_ITEM(
Instruction::GOTO | 0x100,
Instruction::GOTO | 0x100,
- Instruction::RETURN_VOID
- };
+ Instruction::RETURN_VOID);
- TestCode(data, sizeof(data) / sizeof(uint16_t), expected);
+ TestCode(data, expected);
}
TEST(PrettyPrinterTest, CFG3) {
const char* expected =
"BasicBlock 0, succ: 1\n"
- " Goto 1\n"
+ " 4: Goto 1\n"
"BasicBlock 1, pred: 0, succ: 3\n"
- " Goto 3\n"
+ " 0: Goto 3\n"
"BasicBlock 2, pred: 3, succ: 4\n"
- " ReturnVoid\n"
+ " 1: ReturnVoid\n"
"BasicBlock 3, pred: 1, succ: 2\n"
- " Goto 2\n"
+ " 2: Goto 2\n"
"BasicBlock 4, pred: 2\n"
- " Exit\n";
+ " 3: Exit\n";
- const uint16_t data1[] = {
+ const uint16_t data1[] = ZERO_REGISTER_CODE_ITEM(
Instruction::GOTO | 0x200,
Instruction::RETURN_VOID,
- Instruction::GOTO | 0xFF00
- };
+ Instruction::GOTO | 0xFF00);
- TestCode(data1, sizeof(data1) / sizeof(uint16_t), expected);
+ TestCode(data1, expected);
- 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), expected);
+ TestCode(data2, expected);
- 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), expected);
+ TestCode(data3, expected);
}
TEST(PrettyPrinterTest, CFG4) {
const char* expected =
"BasicBlock 0, succ: 1\n"
- " Goto 1\n"
+ " 2: Goto 1\n"
"BasicBlock 1, pred: 0, 1, succ: 1\n"
- " Goto 1\n"
+ " 0: Goto 1\n"
"BasicBlock 2\n"
- " Exit\n";
+ " 1: Exit\n";
- const uint16_t data1[] = {
+ const uint16_t data1[] = ZERO_REGISTER_CODE_ITEM(
Instruction::NOP,
- Instruction::GOTO | 0xFF00
- };
+ Instruction::GOTO | 0xFF00);
- TestCode(data1, sizeof(data1) / sizeof(uint16_t), expected);
+ TestCode(data1, expected);
- 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), expected);
+ TestCode(data2, expected);
}
TEST(PrettyPrinterTest, CFG5) {
const char* expected =
"BasicBlock 0, succ: 1\n"
- " Goto 1\n"
+ " 3: Goto 1\n"
"BasicBlock 1, pred: 0, 2, succ: 3\n"
- " ReturnVoid\n"
+ " 0: ReturnVoid\n"
"BasicBlock 2, succ: 1\n"
- " Goto 1\n"
+ " 1: Goto 1\n"
"BasicBlock 3, pred: 1\n"
- " Exit\n";
+ " 2: Exit\n";
- const uint16_t data[] = {
+ const uint16_t data[] = ZERO_REGISTER_CODE_ITEM(
Instruction::RETURN_VOID,
Instruction::GOTO | 0x100,
- Instruction::GOTO | 0xFE00
- };
+ Instruction::GOTO | 0xFE00);
- TestCode(data, sizeof(data) / sizeof(uint16_t), expected);
+ TestCode(data, expected);
}
-TEST(OptimizerTest, CFG6) {
+TEST(PrettyPrinterTest, CFG6) {
const char* expected =
"BasicBlock 0, succ: 1\n"
- " Goto 1\n"
+ " 0: Local [4, 3, 2]\n"
+ " 1: IntConstant [2]\n"
+ " 10: Goto 1\n"
"BasicBlock 1, pred: 0, succ: 3, 2\n"
- " If\n"
+ " 2: StoreLocal(0, 1)\n"
+ " 3: LoadLocal(0) [5]\n"
+ " 4: LoadLocal(0) [5]\n"
+ " 5: Equal(3, 4) [6]\n"
+ " 6: If(5)\n"
"BasicBlock 2, pred: 1, succ: 3\n"
- " Goto 3\n"
+ " 7: Goto 3\n"
"BasicBlock 3, pred: 1, 2, succ: 4\n"
- " ReturnVoid\n"
+ " 8: ReturnVoid\n"
"BasicBlock 4, pred: 3\n"
- " Exit\n";
+ " 9: Exit\n";
- 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);
- TestCode(data, sizeof(data) / sizeof(uint16_t), expected);
+ TestCode(data, expected);
}
-TEST(OptimizerTest, CFG7) {
+TEST(PrettyPrinterTest, CFG7) {
const char* expected =
"BasicBlock 0, succ: 1\n"
- " Goto 1\n"
+ " 0: Local [4, 3, 2]\n"
+ " 1: IntConstant [2]\n"
+ " 10: Goto 1\n"
"BasicBlock 1, pred: 0, succ: 3, 2\n"
- " If\n"
+ " 2: StoreLocal(0, 1)\n"
+ " 3: LoadLocal(0) [5]\n"
+ " 4: LoadLocal(0) [5]\n"
+ " 5: Equal(3, 4) [6]\n"
+ " 6: If(5)\n"
"BasicBlock 2, pred: 1, 3, succ: 3\n"
- " Goto 3\n"
+ " 7: Goto 3\n"
"BasicBlock 3, pred: 1, 2, succ: 2\n"
- " Goto 2\n"
+ " 8: Goto 2\n"
"BasicBlock 4\n"
- " Exit\n";
+ " 9: Exit\n";
- 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::GOTO | 0xFF00
- };
+ Instruction::GOTO | 0xFF00);
+
+ TestCode(data, expected);
+}
+
+TEST(PrettyPrinterTest, IntConstant) {
+ const char* expected =
+ "BasicBlock 0, succ: 1\n"
+ " 0: Local [2]\n"
+ " 1: IntConstant [2]\n"
+ " 5: Goto 1\n"
+ "BasicBlock 1, pred: 0, succ: 2\n"
+ " 2: StoreLocal(0, 1)\n"
+ " 3: ReturnVoid\n"
+ "BasicBlock 2, pred: 1\n"
+ " 4: Exit\n";
+
+ const uint16_t data[] = ONE_REGISTER_CODE_ITEM(
+ Instruction::CONST_4 | 0 | 0,
+ Instruction::RETURN_VOID);
- TestCode(data, sizeof(data) / sizeof(uint16_t), expected);
+ TestCode(data, expected);
}
} // namespace art