summaryrefslogtreecommitdiff
path: root/compiler/optimizing/loop_optimization.cc
diff options
context:
space:
mode:
authorAart Bik <ajcbik@google.com>2016-10-04 17:33:56 -0700
committerAart Bik <ajcbik@google.com>2016-10-05 11:50:42 -0700
commit9620230700d4b451097c2163faa70627c9d8088a (patch)
tree695b96b9efeaa4c2cb3816e51904e19540fe3883 /compiler/optimizing/loop_optimization.cc
parent4aa6a93c46a959df1ab71ee7a68ad345338046ef (diff)
Refactoring of graph linearization and linear order.
Rationale: Ownership of graph's linear order and iterators was a bit unclear now that other phases are using it. New approach allows phases to compute their own order, while ssa_liveness is sole owner for graph (since it is not mutated afterwards). Also shortens lifetime of loop's arena. Test: test-art-host Change-Id: Ib7137d1203a1e0a12db49868f4117d48a4277f30
Diffstat (limited to 'compiler/optimizing/loop_optimization.cc')
-rw-r--r--compiler/optimizing/loop_optimization.cc51
1 files changed, 25 insertions, 26 deletions
diff --git a/compiler/optimizing/loop_optimization.cc b/compiler/optimizing/loop_optimization.cc
index b12a7f76c6..4acf3ac682 100644
--- a/compiler/optimizing/loop_optimization.cc
+++ b/compiler/optimizing/loop_optimization.cc
@@ -16,10 +16,7 @@
#include "loop_optimization.h"
-#include "base/arena_containers.h"
-#include "induction_var_range.h"
-#include "ssa_liveness_analysis.h"
-#include "nodes.h"
+#include "linear_order.h"
namespace art {
@@ -126,14 +123,9 @@ 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_(allocator),
+ loop_allocator_(nullptr),
top_loop_(nullptr),
last_loop_(nullptr) {
}
@@ -141,32 +133,39 @@ HLoopOptimization::HLoopOptimization(HGraph* graph,
void HLoopOptimization::Run() {
// Well-behaved loops only.
// TODO: make this less of a sledgehammer.
- if (graph_-> HasTryCatch() || graph_->HasIrreducibleLoops()) {
+ if (graph_->HasTryCatch() || graph_->HasIrreducibleLoops()) {
return;
}
+ // Phase-local allocator that draws from the global pool. Since the allocator
+ // itself resides on the stack, it is destructed on exiting Run(), which
+ // implies its underlying memory is released immediately.
ArenaAllocator allocator(graph_->GetArena()->GetArenaPool());
- if (loop_allocator_ == nullptr) {
- loop_allocator_ = &allocator;
- }
+ loop_allocator_ = &allocator;
+
+ // Perform loop optimizations.
+ LocalRun();
+
+ // Detach.
+ loop_allocator_ = nullptr;
+ last_loop_ = top_loop_ = nullptr;
+}
+
+void HLoopOptimization::LocalRun() {
+ // Build the linear order using the phase-local allocator. This step enables building
+ // a loop hierarchy that properly reflects the outer-inner and previous-next relation.
+ ArenaVector<HBasicBlock*> linear_order(loop_allocator_->Adapter(kArenaAllocLinearOrder));
+ LinearizeGraph(graph_, loop_allocator_, &linear_order);
- // Build the linear order. This step enables building a loop hierarchy that
- // properly reflects the outer-inner and previous-next relation.
- graph_->Linearize();
// Build the loop hierarchy.
- for (HLinearOrderIterator it_graph(*graph_); !it_graph.Done(); it_graph.Advance()) {
- HBasicBlock* block = it_graph.Current();
+ for (HBasicBlock* block : linear_order) {
if (block->IsLoopHeader()) {
AddLoop(block->GetLoopInformation());
}
}
- if (top_loop_ != nullptr) {
- // Traverse the loop hierarchy inner-to-outer and optimize.
- TraverseLoopsInnerToOuter(top_loop_);
- }
- if (loop_allocator_ == &allocator) {
- loop_allocator_ = nullptr;
- }
+
+ // Traverse the loop hierarchy inner-to-outer and optimize.
+ TraverseLoopsInnerToOuter(top_loop_);
}
void HLoopOptimization::AddLoop(HLoopInformation* loop_info) {