OSDN Git Service

Make it possible to pass an arena allocator to HLoopOptimization.
authorNicolas Geoffray <ngeoffray@google.com>
Wed, 5 Oct 2016 12:49:44 +0000 (13:49 +0100)
committerNicolas Geoffray <ngeoffray@google.com>
Wed, 5 Oct 2016 12:49:44 +0000 (13:49 +0100)
loop_optimization_test uses memory from HLoopOptimization's
allocator, which is scoped by the Run method.

Fix is to pass custom allocator.

test: m test-art-host-gtest
Change-Id: I359330e22202519f400a26da5403eeb00f0b2db4

compiler/optimizing/loop_optimization.cc
compiler/optimizing/loop_optimization.h
compiler/optimizing/loop_optimization_test.cc

index 383a027..b12a7f7 100644 (file)
@@ -126,9 +126,14 @@ static void RemoveFromCycle(HInstruction* instruction) {
 
 HLoopOptimization::HLoopOptimization(HGraph* graph,
                                      HInductionVarAnalysis* induction_analysis)
+    : HLoopOptimization(graph, induction_analysis, nullptr) {}
+
+HLoopOptimization::HLoopOptimization(HGraph* graph,
+                                     HInductionVarAnalysis* induction_analysis,
+                                     ArenaAllocator* allocator)
     : HOptimization(graph, kLoopOptimizationPassName),
       induction_range_(induction_analysis),
-      loop_allocator_(nullptr),
+      loop_allocator_(allocator),
       top_loop_(nullptr),
       last_loop_(nullptr) {
 }
@@ -141,7 +146,9 @@ void HLoopOptimization::Run() {
   }
 
   ArenaAllocator allocator(graph_->GetArena()->GetArenaPool());
-  loop_allocator_ = &allocator;
+  if (loop_allocator_ == nullptr) {
+    loop_allocator_ = &allocator;
+  }
 
   // Build the linear order. This step enables building a loop hierarchy that
   // properly reflects the outer-inner and previous-next relation.
@@ -157,7 +164,9 @@ void HLoopOptimization::Run() {
     // Traverse the loop hierarchy inner-to-outer and optimize.
     TraverseLoopsInnerToOuter(top_loop_);
   }
-  loop_allocator_ = nullptr;
+  if (loop_allocator_ == &allocator) {
+    loop_allocator_ = nullptr;
+  }
 }
 
 void HLoopOptimization::AddLoop(HLoopInformation* loop_info) {
index d12fe5e..591e45a 100644 (file)
@@ -32,6 +32,9 @@ namespace art {
 class HLoopOptimization : public HOptimization {
  public:
   HLoopOptimization(HGraph* graph, HInductionVarAnalysis* induction_analysis);
+  HLoopOptimization(HGraph* graph,
+                    HInductionVarAnalysis* induction_analysis,
+                    ArenaAllocator* allocator);
 
   void Run() OVERRIDE;
 
index 4e007d4..4d54afd 100644 (file)
@@ -31,7 +31,7 @@ class LoopOptimizationTest : public CommonCompilerTest {
         allocator_(&pool_),
         graph_(CreateGraph(&allocator_)),
         iva_(new (&allocator_) HInductionVarAnalysis(graph_)),
-        loop_opt_(new (&allocator_) HLoopOptimization(graph_, iva_)) {
+        loop_opt_(new (&allocator_) HLoopOptimization(graph_, iva_, &allocator_)) {
     BuildGraph();
   }