diff options
author | 2014-07-11 09:49:49 +0100 | |
---|---|---|
committer | 2014-07-14 12:35:21 +0100 | |
commit | 7dc206a53a42a658f52d5cb0b7e79b47da370c9b (patch) | |
tree | f9940f60c132795d2f5865ba84b942916f076313 /compiler/optimizing/ssa_phi_elimination.h | |
parent | 1cad41d900201422cedcbe7837935d17bbf28ed8 (diff) |
Add two phi pruning phases.
Change-Id: Ic4f05e3df96970d78a6938b27cdf9b58ef3849b9
Diffstat (limited to 'compiler/optimizing/ssa_phi_elimination.h')
-rw-r--r-- | compiler/optimizing/ssa_phi_elimination.h | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/compiler/optimizing/ssa_phi_elimination.h b/compiler/optimizing/ssa_phi_elimination.h new file mode 100644 index 0000000000..5274f09f3f --- /dev/null +++ b/compiler/optimizing/ssa_phi_elimination.h @@ -0,0 +1,68 @@ +/* + * Copyright (C) 2014 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ART_COMPILER_OPTIMIZING_SSA_PHI_ELIMINATION_H_ +#define ART_COMPILER_OPTIMIZING_SSA_PHI_ELIMINATION_H_ + +#include "nodes.h" + +namespace art { + +/** + * Optimization phase that removes dead phis from the graph. Dead phis are unused + * phis, or phis only used by other phis. + */ +class SsaDeadPhiElimination : public ValueObject { + public: + explicit SsaDeadPhiElimination(HGraph* graph) + : graph_(graph), worklist_(graph->GetArena(), kDefaultWorklistSize) {} + + void Run(); + + private: + HGraph* const graph_; + GrowableArray<HPhi*> worklist_; + + static constexpr size_t kDefaultWorklistSize = 8; + + DISALLOW_COPY_AND_ASSIGN(SsaDeadPhiElimination); +}; + +/** + * Removes redundant phis that may have been introduced when doing SSA conversion. + * For example, when entering a loop, we create phis for all live registers. These + * registers might be updated with the same value, or not updated at all. We can just + * replace the phi with the value when entering the loop. + */ +class SsaRedundantPhiElimination : public ValueObject { + public: + explicit SsaRedundantPhiElimination(HGraph* graph) + : graph_(graph), worklist_(graph->GetArena(), kDefaultWorklistSize) {} + + void Run(); + + private: + HGraph* const graph_; + GrowableArray<HPhi*> worklist_; + + static constexpr size_t kDefaultWorklistSize = 8; + + DISALLOW_COPY_AND_ASSIGN(SsaRedundantPhiElimination); +}; + +} // namespace art + +#endif // ART_COMPILER_OPTIMIZING_SSA_PHI_ELIMINATION_H_ |