ART: Force constants into the entry block
Optimizations such as GVN and BCE make the assumption that all
constants are located in the entry block of the CFG, but not all
passes adhere to this rule.
This patch makes constructors of constants private and only accessible
to friend classes - HGraph for int/long constants and SsaBuilder for
float/double - which ensure that they are placed correctly and not
duplicated.
Note that the ArenaAllocatorAdapter was modified to not increment
the ArenaAllocator's internal reference counter in order to allow
for use of ArenaSafeMap inside an arena-allocated objects. Because
their destructor is not called, the counter does not get decremented.
Change-Id: I36a4fa29ae34fb905cdefd482ccbf386cff14166
diff --git a/compiler/optimizing/bounds_check_elimination_test.cc b/compiler/optimizing/bounds_check_elimination_test.cc
index 24fa583..b3653fe 100644
--- a/compiler/optimizing/bounds_check_elimination_test.cc
+++ b/compiler/optimizing/bounds_check_elimination_test.cc
@@ -52,12 +52,11 @@
HParameterValue(0, Primitive::kPrimNot); // array
HInstruction* parameter2 = new (&allocator)
HParameterValue(0, Primitive::kPrimInt); // i
- HInstruction* constant_1 = new (&allocator) HIntConstant(1);
- HInstruction* constant_0 = new (&allocator) HIntConstant(0);
entry->AddInstruction(parameter1);
entry->AddInstruction(parameter2);
- entry->AddInstruction(constant_1);
- entry->AddInstruction(constant_0);
+
+ HInstruction* constant_1 = graph->GetIntConstant(1);
+ HInstruction* constant_0 = graph->GetIntConstant(0);
HBasicBlock* block1 = new (&allocator) HBasicBlock(graph);
graph->AddBlock(block1);
@@ -158,14 +157,12 @@
HParameterValue(0, Primitive::kPrimNot); // array
HInstruction* parameter2 = new (&allocator)
HParameterValue(0, Primitive::kPrimInt); // i
- HInstruction* constant_1 = new (&allocator) HIntConstant(1);
- HInstruction* constant_0 = new (&allocator) HIntConstant(0);
- HInstruction* constant_max_int = new (&allocator) HIntConstant(INT_MAX);
entry->AddInstruction(parameter1);
entry->AddInstruction(parameter2);
- entry->AddInstruction(constant_1);
- entry->AddInstruction(constant_0);
- entry->AddInstruction(constant_max_int);
+
+ HInstruction* constant_1 = graph->GetIntConstant(1);
+ HInstruction* constant_0 = graph->GetIntConstant(0);
+ HInstruction* constant_max_int = graph->GetIntConstant(INT_MAX);
HBasicBlock* block1 = new (&allocator) HBasicBlock(graph);
graph->AddBlock(block1);
@@ -232,14 +229,12 @@
HParameterValue(0, Primitive::kPrimNot); // array
HInstruction* parameter2 = new (&allocator)
HParameterValue(0, Primitive::kPrimInt); // i
- HInstruction* constant_1 = new (&allocator) HIntConstant(1);
- HInstruction* constant_0 = new (&allocator) HIntConstant(0);
- HInstruction* constant_max_int = new (&allocator) HIntConstant(INT_MAX);
entry->AddInstruction(parameter1);
entry->AddInstruction(parameter2);
- entry->AddInstruction(constant_1);
- entry->AddInstruction(constant_0);
- entry->AddInstruction(constant_max_int);
+
+ HInstruction* constant_1 = graph->GetIntConstant(1);
+ HInstruction* constant_0 = graph->GetIntConstant(0);
+ HInstruction* constant_max_int = graph->GetIntConstant(INT_MAX);
HBasicBlock* block1 = new (&allocator) HBasicBlock(graph);
graph->AddBlock(block1);
@@ -303,15 +298,12 @@
graph->AddBlock(entry);
graph->SetEntryBlock(entry);
HInstruction* parameter = new (&allocator) HParameterValue(0, Primitive::kPrimNot);
- HInstruction* constant_5 = new (&allocator) HIntConstant(5);
- HInstruction* constant_4 = new (&allocator) HIntConstant(4);
- HInstruction* constant_6 = new (&allocator) HIntConstant(6);
- HInstruction* constant_1 = new (&allocator) HIntConstant(1);
entry->AddInstruction(parameter);
- entry->AddInstruction(constant_5);
- entry->AddInstruction(constant_4);
- entry->AddInstruction(constant_6);
- entry->AddInstruction(constant_1);
+
+ HInstruction* constant_5 = graph->GetIntConstant(5);
+ HInstruction* constant_4 = graph->GetIntConstant(4);
+ HInstruction* constant_6 = graph->GetIntConstant(6);
+ HInstruction* constant_1 = graph->GetIntConstant(1);
HBasicBlock* block = new (&allocator) HBasicBlock(graph);
graph->AddBlock(block);
@@ -379,13 +371,11 @@
graph->AddBlock(entry);
graph->SetEntryBlock(entry);
HInstruction* parameter = new (allocator) HParameterValue(0, Primitive::kPrimNot);
- HInstruction* constant_initial = new (allocator) HIntConstant(initial);
- HInstruction* constant_increment = new (allocator) HIntConstant(increment);
- HInstruction* constant_10 = new (allocator) HIntConstant(10);
entry->AddInstruction(parameter);
- entry->AddInstruction(constant_initial);
- entry->AddInstruction(constant_increment);
- entry->AddInstruction(constant_10);
+
+ HInstruction* constant_initial = graph->GetIntConstant(initial);
+ HInstruction* constant_increment = graph->GetIntConstant(increment);
+ HInstruction* constant_10 = graph->GetIntConstant(10);
HBasicBlock* block = new (allocator) HBasicBlock(graph);
graph->AddBlock(block);
@@ -518,15 +508,12 @@
graph->AddBlock(entry);
graph->SetEntryBlock(entry);
HInstruction* parameter = new (allocator) HParameterValue(0, Primitive::kPrimNot);
- HInstruction* constant_initial = new (allocator) HIntConstant(initial);
- HInstruction* constant_increment = new (allocator) HIntConstant(increment);
- HInstruction* constant_minus_1 = new (allocator) HIntConstant(-1);
- HInstruction* constant_10 = new (allocator) HIntConstant(10);
entry->AddInstruction(parameter);
- entry->AddInstruction(constant_initial);
- entry->AddInstruction(constant_increment);
- entry->AddInstruction(constant_minus_1);
- entry->AddInstruction(constant_10);
+
+ HInstruction* constant_initial = graph->GetIntConstant(initial);
+ HInstruction* constant_increment = graph->GetIntConstant(increment);
+ HInstruction* constant_minus_1 = graph->GetIntConstant(-1);
+ HInstruction* constant_10 = graph->GetIntConstant(10);
HBasicBlock* block = new (allocator) HBasicBlock(graph);
graph->AddBlock(block);
@@ -651,12 +638,10 @@
HBasicBlock* entry = new (allocator) HBasicBlock(graph);
graph->AddBlock(entry);
graph->SetEntryBlock(entry);
- HInstruction* constant_10 = new (allocator) HIntConstant(10);
- HInstruction* constant_initial = new (allocator) HIntConstant(initial);
- HInstruction* constant_increment = new (allocator) HIntConstant(increment);
- entry->AddInstruction(constant_10);
- entry->AddInstruction(constant_initial);
- entry->AddInstruction(constant_increment);
+
+ HInstruction* constant_10 = graph->GetIntConstant(10);
+ HInstruction* constant_initial = graph->GetIntConstant(initial);
+ HInstruction* constant_increment = graph->GetIntConstant(increment);
HBasicBlock* block = new (allocator) HBasicBlock(graph);
graph->AddBlock(block);
@@ -765,15 +750,12 @@
graph->AddBlock(entry);
graph->SetEntryBlock(entry);
HInstruction* parameter = new (allocator) HParameterValue(0, Primitive::kPrimNot);
- HInstruction* constant_initial = new (allocator) HIntConstant(initial);
- HInstruction* constant_1 = new (allocator) HIntConstant(1);
- HInstruction* constant_10 = new (allocator) HIntConstant(10);
- HInstruction* constant_minus_1 = new (allocator) HIntConstant(-1);
entry->AddInstruction(parameter);
- entry->AddInstruction(constant_initial);
- entry->AddInstruction(constant_1);
- entry->AddInstruction(constant_10);
- entry->AddInstruction(constant_minus_1);
+
+ HInstruction* constant_initial = graph->GetIntConstant(initial);
+ HInstruction* constant_1 = graph->GetIntConstant(1);
+ HInstruction* constant_10 = graph->GetIntConstant(10);
+ HInstruction* constant_minus_1 = graph->GetIntConstant(-1);
HBasicBlock* block = new (allocator) HBasicBlock(graph);
graph->AddBlock(block);
@@ -893,13 +875,11 @@
graph->AddBlock(entry);
graph->SetEntryBlock(entry);
HInstruction* parameter = new (&allocator) HParameterValue(0, Primitive::kPrimNot);
- HInstruction* constant_0 = new (&allocator) HIntConstant(0);
- HInstruction* constant_minus_1 = new (&allocator) HIntConstant(-1);
- HInstruction* constant_1 = new (&allocator) HIntConstant(1);
entry->AddInstruction(parameter);
- entry->AddInstruction(constant_0);
- entry->AddInstruction(constant_minus_1);
- entry->AddInstruction(constant_1);
+
+ HInstruction* constant_0 = graph->GetIntConstant(0);
+ HInstruction* constant_minus_1 = graph->GetIntConstant(-1);
+ HInstruction* constant_1 = graph->GetIntConstant(1);
HBasicBlock* block = new (&allocator) HBasicBlock(graph);
graph->AddBlock(block);