diff options
author | 2017-10-10 10:38:16 +0100 | |
---|---|---|
committer | 2017-10-11 14:42:18 +0100 | |
commit | f361267ff86e775ed146138220c5a2f70b4a4b3d (patch) | |
tree | 964329e03ad010a58124e6332e3d5d3487b8fc25 | |
parent | 69d310e0317e2fce97bf8c9c133c5c2c0332e61d (diff) |
Use ScopedArenaAllocator for Phi elimination pass.
Memory needed to compile the two most expensive methods for
aosp_angler-userdebug boot image:
BatteryStats.dumpCheckinLocked() : 20.2MiB -> 20.0MiB (-195KiB)
BatteryStats.dumpLocked(): 40.3MiB -> 39.9MiB (-458KiB)
Test: m test-art-host-gtest
Test: testrunner.py --host --optimizing
Bug: 64312607
Change-Id: Ie79b46cd42df476c2f66c6f869b1dd810ff15963
-rw-r--r-- | compiler/optimizing/ssa_phi_elimination.cc | 44 | ||||
-rw-r--r-- | compiler/optimizing/ssa_phi_elimination.h | 19 |
2 files changed, 32 insertions, 31 deletions
diff --git a/compiler/optimizing/ssa_phi_elimination.cc b/compiler/optimizing/ssa_phi_elimination.cc index 3b95b86268..cb27ded17a 100644 --- a/compiler/optimizing/ssa_phi_elimination.cc +++ b/compiler/optimizing/ssa_phi_elimination.cc @@ -17,7 +17,8 @@ #include "ssa_phi_elimination.h" #include "base/arena_bit_vector.h" -#include "base/arena_containers.h" +#include "base/scoped_arena_allocator.h" +#include "base/scoped_arena_containers.h" #include "base/bit_vector-inl.h" namespace art { @@ -28,10 +29,17 @@ void SsaDeadPhiElimination::Run() { } void SsaDeadPhiElimination::MarkDeadPhis() { + // Use local allocator for allocating memory used by this optimization. + ScopedArenaAllocator allocator(graph_->GetArenaStack()); + + static constexpr size_t kDefaultWorklistSize = 8; + ScopedArenaVector<HPhi*> worklist(allocator.Adapter(kArenaAllocSsaPhiElimination)); + worklist.reserve(kDefaultWorklistSize); + // Phis are constructed live and should not be revived if previously marked // dead. This algorithm temporarily breaks that invariant but we DCHECK that // only phis which were initially live are revived. - ArenaSet<HPhi*> initially_live(graph_->GetAllocator()->Adapter(kArenaAllocSsaPhiElimination)); + ScopedArenaSet<HPhi*> initially_live(allocator.Adapter(kArenaAllocSsaPhiElimination)); // Add to the worklist phis referenced by non-phi instructions. for (HBasicBlock* block : graph_->GetReversePostOrder()) { @@ -52,7 +60,7 @@ void SsaDeadPhiElimination::MarkDeadPhis() { } if (keep_alive) { - worklist_.push_back(phi); + worklist.push_back(phi); } else { phi->SetDead(); if (kIsDebugBuild) { @@ -63,9 +71,9 @@ void SsaDeadPhiElimination::MarkDeadPhis() { } // Process the worklist by propagating liveness to phi inputs. - while (!worklist_.empty()) { - HPhi* phi = worklist_.back(); - worklist_.pop_back(); + while (!worklist.empty()) { + HPhi* phi = worklist.back(); + worklist.pop_back(); for (HInstruction* raw_input : phi->GetInputs()) { HPhi* input = raw_input->AsPhi(); if (input != nullptr && input->IsDead()) { @@ -73,7 +81,7 @@ void SsaDeadPhiElimination::MarkDeadPhis() { // that the phi was not dead initially (see definition of `initially_live`). DCHECK(ContainsElement(initially_live, input)); input->SetLive(); - worklist_.push_back(input); + worklist.push_back(input); } } } @@ -115,23 +123,31 @@ void SsaDeadPhiElimination::EliminateDeadPhis() { } void SsaRedundantPhiElimination::Run() { + // Use local allocator for allocating memory used by this optimization. + ScopedArenaAllocator allocator(graph_->GetArenaStack()); + + static constexpr size_t kDefaultWorklistSize = 8; + ScopedArenaVector<HPhi*> worklist(allocator.Adapter(kArenaAllocSsaPhiElimination)); + worklist.reserve(kDefaultWorklistSize); + // Add all phis in the worklist. Order does not matter for correctness, and // neither will necessarily converge faster. for (HBasicBlock* block : graph_->GetReversePostOrder()) { for (HInstructionIterator inst_it(block->GetPhis()); !inst_it.Done(); inst_it.Advance()) { - worklist_.push_back(inst_it.Current()->AsPhi()); + worklist.push_back(inst_it.Current()->AsPhi()); } } - ArenaBitVector visited_phis_in_cycle(graph_->GetAllocator(), + ArenaBitVector visited_phis_in_cycle(&allocator, graph_->GetCurrentInstructionId(), /* expandable */ false, kArenaAllocSsaPhiElimination); - ArenaVector<HPhi*> cycle_worklist(graph_->GetAllocator()->Adapter(kArenaAllocSsaPhiElimination)); + visited_phis_in_cycle.ClearAllBits(); + ScopedArenaVector<HPhi*> cycle_worklist(allocator.Adapter(kArenaAllocSsaPhiElimination)); - while (!worklist_.empty()) { - HPhi* phi = worklist_.back(); - worklist_.pop_back(); + while (!worklist.empty()) { + HPhi* phi = worklist.back(); + worklist.pop_back(); // If the phi has already been processed, continue. if (!phi->IsInBlock()) { @@ -231,7 +247,7 @@ void SsaRedundantPhiElimination::Run() { for (const HUseListNode<HInstruction*>& use : current->GetUses()) { HInstruction* user = use.GetUser(); if (user->IsPhi() && !visited_phis_in_cycle.IsBitSet(user->GetId())) { - worklist_.push_back(user->AsPhi()); + worklist.push_back(user->AsPhi()); } } DCHECK(candidate->StrictlyDominates(current)); diff --git a/compiler/optimizing/ssa_phi_elimination.h b/compiler/optimizing/ssa_phi_elimination.h index e0cde074d6..11d5837eb5 100644 --- a/compiler/optimizing/ssa_phi_elimination.h +++ b/compiler/optimizing/ssa_phi_elimination.h @@ -17,7 +17,6 @@ #ifndef ART_COMPILER_OPTIMIZING_SSA_PHI_ELIMINATION_H_ #define ART_COMPILER_OPTIMIZING_SSA_PHI_ELIMINATION_H_ -#include "base/arena_containers.h" #include "nodes.h" #include "optimization.h" @@ -30,10 +29,7 @@ namespace art { class SsaDeadPhiElimination : public HOptimization { public: explicit SsaDeadPhiElimination(HGraph* graph) - : HOptimization(graph, kSsaDeadPhiEliminationPassName), - worklist_(graph->GetAllocator()->Adapter(kArenaAllocSsaPhiElimination)) { - worklist_.reserve(kDefaultWorklistSize); - } + : HOptimization(graph, kSsaDeadPhiEliminationPassName) {} void Run() OVERRIDE; @@ -43,10 +39,6 @@ class SsaDeadPhiElimination : public HOptimization { static constexpr const char* kSsaDeadPhiEliminationPassName = "dead_phi_elimination"; private: - ArenaVector<HPhi*> worklist_; - - static constexpr size_t kDefaultWorklistSize = 8; - DISALLOW_COPY_AND_ASSIGN(SsaDeadPhiElimination); }; @@ -59,20 +51,13 @@ class SsaDeadPhiElimination : public HOptimization { class SsaRedundantPhiElimination : public HOptimization { public: explicit SsaRedundantPhiElimination(HGraph* graph) - : HOptimization(graph, kSsaRedundantPhiEliminationPassName), - worklist_(graph->GetAllocator()->Adapter(kArenaAllocSsaPhiElimination)) { - worklist_.reserve(kDefaultWorklistSize); - } + : HOptimization(graph, kSsaRedundantPhiEliminationPassName) {} void Run() OVERRIDE; static constexpr const char* kSsaRedundantPhiEliminationPassName = "redundant_phi_elimination"; private: - ArenaVector<HPhi*> worklist_; - - static constexpr size_t kDefaultWorklistSize = 8; - DISALLOW_COPY_AND_ASSIGN(SsaRedundantPhiElimination); }; |