Step 1 of 2: conditional passes.
Rationale:
The change adds a return value to Run() in preparation of
conditional pass execution. The value returned by Run() is
best effort, returning false means no optimizations were
applied or no useful information was obtained. I filled
in a few cases with more exact information, others
still just return true. In addition, it integrates inlining
as a regular pass, avoiding the ugly "break" into
optimizations1 and optimziations2.
Bug: b/78171933, b/74026074
Test: test-art-host,target
Change-Id: Ia39c5c83c01dcd79841e4b623917d61c754cf075
diff --git a/compiler/optimizing/loop_optimization.cc b/compiler/optimizing/loop_optimization.cc
index 1462404..7f1b319 100644
--- a/compiler/optimizing/loop_optimization.cc
+++ b/compiler/optimizing/loop_optimization.cc
@@ -608,11 +608,11 @@
global_allocator_)) {
}
-void HLoopOptimization::Run() {
+bool HLoopOptimization::Run() {
// Skip if there is no loop or the graph has try-catch/irreducible loops.
// TODO: make this less of a sledgehammer.
if (!graph_->HasLoops() || graph_->HasTryCatch() || graph_->HasIrreducibleLoops()) {
- return;
+ return false;
}
// Phase-local allocator.
@@ -620,7 +620,7 @@
loop_allocator_ = &allocator;
// Perform loop optimizations.
- LocalRun();
+ bool didLoopOpt = LocalRun();
if (top_loop_ == nullptr) {
graph_->SetHasLoops(false); // no more loops
}
@@ -628,13 +628,16 @@
// Detach.
loop_allocator_ = nullptr;
last_loop_ = top_loop_ = nullptr;
+
+ return didLoopOpt;
}
//
// Loop setup and traversal.
//
-void HLoopOptimization::LocalRun() {
+bool HLoopOptimization::LocalRun() {
+ bool didLoopOpt = false;
// 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.
ScopedArenaVector<HBasicBlock*> linear_order(loop_allocator_->Adapter(kArenaAllocLinearOrder));
@@ -666,7 +669,7 @@
vector_map_ = ↦
vector_permanent_map_ = &perm;
// Traverse.
- TraverseLoopsInnerToOuter(top_loop_);
+ didLoopOpt = TraverseLoopsInnerToOuter(top_loop_);
// Detach.
iset_ = nullptr;
reductions_ = nullptr;
@@ -674,6 +677,7 @@
vector_map_ = nullptr;
vector_permanent_map_ = nullptr;
}
+ return didLoopOpt;
}
void HLoopOptimization::AddLoop(HLoopInformation* loop_info) {