summaryrefslogtreecommitdiff
path: root/compiler/optimizing/nodes_test.cc
diff options
context:
space:
mode:
author Nicolas Geoffray <ngeoffray@google.com> 2014-10-07 14:14:27 +0100
committer Nicolas Geoffray <ngeoffray@google.com> 2014-10-07 16:26:48 +0100
commit191c4b1372aef7c0272f8fa3985b55513029e728 (patch)
treeea8a2eb84a64b6f808f782ada9ea66ef69e8e764 /compiler/optimizing/nodes_test.cc
parent41abdb6ec97978df7c6d79abce4efb664c994ce8 (diff)
Inserting a node must also update its inputs users.
Change-Id: I55357564b81efcc0cf52fffdf23289696fe27dd1
Diffstat (limited to 'compiler/optimizing/nodes_test.cc')
-rw-r--r--compiler/optimizing/nodes_test.cc51
1 files changed, 51 insertions, 0 deletions
diff --git a/compiler/optimizing/nodes_test.cc b/compiler/optimizing/nodes_test.cc
index b75bacb6ea..70dd8d7f88 100644
--- a/compiler/optimizing/nodes_test.cc
+++ b/compiler/optimizing/nodes_test.cc
@@ -63,4 +63,55 @@ TEST(Node, RemoveInstruction) {
ASSERT_FALSE(parameter->HasUses());
}
+/**
+ * Test that inserting an instruction in the graph updates user lists.
+ */
+TEST(Node, InsertInstruction) {
+ ArenaPool pool;
+ ArenaAllocator allocator(&pool);
+
+ HGraph* graph = new (&allocator) HGraph(&allocator);
+ HBasicBlock* entry = new (&allocator) HBasicBlock(graph);
+ graph->AddBlock(entry);
+ graph->SetEntryBlock(entry);
+ HInstruction* parameter1 = new (&allocator) HParameterValue(0, Primitive::kPrimNot);
+ HInstruction* parameter2 = new (&allocator) HParameterValue(0, Primitive::kPrimNot);
+ entry->AddInstruction(parameter1);
+ entry->AddInstruction(parameter2);
+ entry->AddInstruction(new (&allocator) HExit());
+
+ ASSERT_FALSE(parameter1->HasUses());
+ ASSERT_EQ(parameter1->NumberOfUses(), 0u);
+
+ HInstruction* to_insert = new (&allocator) HNullCheck(parameter1, 0);
+ entry->InsertInstructionBefore(to_insert, parameter2);
+
+ ASSERT_TRUE(parameter1->HasUses());
+ ASSERT_EQ(parameter1->NumberOfUses(), 1u);
+}
+
+/**
+ * Test that adding an instruction in the graph updates user lists.
+ */
+TEST(Node, AddInstruction) {
+ ArenaPool pool;
+ ArenaAllocator allocator(&pool);
+
+ HGraph* graph = new (&allocator) HGraph(&allocator);
+ HBasicBlock* entry = new (&allocator) HBasicBlock(graph);
+ graph->AddBlock(entry);
+ graph->SetEntryBlock(entry);
+ HInstruction* parameter = new (&allocator) HParameterValue(0, Primitive::kPrimNot);
+ entry->AddInstruction(parameter);
+
+ ASSERT_FALSE(parameter->HasUses());
+ ASSERT_EQ(parameter->NumberOfUses(), 0u);
+
+ HInstruction* to_add = new (&allocator) HNullCheck(parameter, 0);
+ entry->AddInstruction(to_add);
+
+ ASSERT_TRUE(parameter->HasUses());
+ ASSERT_EQ(parameter->NumberOfUses(), 1u);
+}
+
} // namespace art