blob: 88a5279e14e7b8a40b56457e35b238871c5ce24a [file] [log] [blame]
Nicolas Geoffray7dc206a2014-07-11 09:49:49 +01001/*
2 * Copyright (C) 2014 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef ART_COMPILER_OPTIMIZING_SSA_PHI_ELIMINATION_H_
18#define ART_COMPILER_OPTIMIZING_SSA_PHI_ELIMINATION_H_
19
20#include "nodes.h"
Nicolas Geoffray5e6916c2014-11-18 16:53:35 +000021#include "optimization.h"
Nicolas Geoffray7dc206a2014-07-11 09:49:49 +010022
23namespace art {
24
25/**
26 * Optimization phase that removes dead phis from the graph. Dead phis are unused
27 * phis, or phis only used by other phis.
28 */
Nicolas Geoffray5e6916c2014-11-18 16:53:35 +000029class SsaDeadPhiElimination : public HOptimization {
Nicolas Geoffray7dc206a2014-07-11 09:49:49 +010030 public:
31 explicit SsaDeadPhiElimination(HGraph* graph)
Nicolas Geoffray5e6916c2014-11-18 16:53:35 +000032 : HOptimization(graph, true, "dead_phi_elimination"),
33 worklist_(graph->GetArena(), kDefaultWorklistSize) {}
Nicolas Geoffray7dc206a2014-07-11 09:49:49 +010034
Nicolas Geoffray5e6916c2014-11-18 16:53:35 +000035 void Run() OVERRIDE;
Nicolas Geoffray7dc206a2014-07-11 09:49:49 +010036
Nicolas Geoffrayd6138ef2015-02-18 14:48:53 +000037 void MarkDeadPhis();
38 void EliminateDeadPhis();
39
Nicolas Geoffray7dc206a2014-07-11 09:49:49 +010040 private:
Nicolas Geoffray7dc206a2014-07-11 09:49:49 +010041 GrowableArray<HPhi*> worklist_;
42
43 static constexpr size_t kDefaultWorklistSize = 8;
44
45 DISALLOW_COPY_AND_ASSIGN(SsaDeadPhiElimination);
46};
47
48/**
49 * Removes redundant phis that may have been introduced when doing SSA conversion.
50 * For example, when entering a loop, we create phis for all live registers. These
51 * registers might be updated with the same value, or not updated at all. We can just
52 * replace the phi with the value when entering the loop.
53 */
Nicolas Geoffray5e6916c2014-11-18 16:53:35 +000054class SsaRedundantPhiElimination : public HOptimization {
Nicolas Geoffray7dc206a2014-07-11 09:49:49 +010055 public:
56 explicit SsaRedundantPhiElimination(HGraph* graph)
Nicolas Geoffray5e6916c2014-11-18 16:53:35 +000057 : HOptimization(graph, true, "redundant_phi_elimination"),
58 worklist_(graph->GetArena(), kDefaultWorklistSize) {}
Nicolas Geoffray7dc206a2014-07-11 09:49:49 +010059
Nicolas Geoffray5e6916c2014-11-18 16:53:35 +000060 void Run() OVERRIDE;
Nicolas Geoffray7dc206a2014-07-11 09:49:49 +010061
62 private:
Nicolas Geoffray7dc206a2014-07-11 09:49:49 +010063 GrowableArray<HPhi*> worklist_;
64
65 static constexpr size_t kDefaultWorklistSize = 8;
66
67 DISALLOW_COPY_AND_ASSIGN(SsaRedundantPhiElimination);
68};
69
70} // namespace art
71
72#endif // ART_COMPILER_OPTIMIZING_SSA_PHI_ELIMINATION_H_