blob: f606f928fab80138460dadd02a4f916b729cae0c [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
Vladimír Marko434d9682022-11-04 14:04:17 +000020#include "base/macros.h"
Nicolas Geoffray7dc206a2014-07-11 09:49:49 +010021#include "nodes.h"
Nicolas Geoffray5e6916c2014-11-18 16:53:35 +000022#include "optimization.h"
Nicolas Geoffray7dc206a2014-07-11 09:49:49 +010023
Vladimír Marko434d9682022-11-04 14:04:17 +000024namespace art HIDDEN {
Nicolas Geoffray7dc206a2014-07-11 09:49:49 +010025
26/**
27 * Optimization phase that removes dead phis from the graph. Dead phis are unused
28 * phis, or phis only used by other phis.
29 */
Nicolas Geoffray5e6916c2014-11-18 16:53:35 +000030class SsaDeadPhiElimination : public HOptimization {
Nicolas Geoffray7dc206a2014-07-11 09:49:49 +010031 public:
32 explicit SsaDeadPhiElimination(HGraph* graph)
Vladimir Markof3612672017-10-10 10:38:16 +010033 : HOptimization(graph, kSsaDeadPhiEliminationPassName) {}
Nicolas Geoffray7dc206a2014-07-11 09:49:49 +010034
Roland Levillainbbc6e7e2018-08-24 16:58:47 +010035 bool Run() override;
Nicolas Geoffray7dc206a2014-07-11 09:49:49 +010036
Nicolas Geoffrayd6138ef2015-02-18 14:48:53 +000037 void MarkDeadPhis();
38 void EliminateDeadPhis();
39
Andreas Gampe7c3952f2015-02-19 18:21:24 -080040 static constexpr const char* kSsaDeadPhiEliminationPassName = "dead_phi_elimination";
41
Nicolas Geoffray7dc206a2014-07-11 09:49:49 +010042 private:
Nicolas Geoffray7dc206a2014-07-11 09:49:49 +010043 DISALLOW_COPY_AND_ASSIGN(SsaDeadPhiElimination);
44};
45
46/**
47 * Removes redundant phis that may have been introduced when doing SSA conversion.
48 * For example, when entering a loop, we create phis for all live registers. These
49 * registers might be updated with the same value, or not updated at all. We can just
50 * replace the phi with the value when entering the loop.
51 */
Nicolas Geoffray5e6916c2014-11-18 16:53:35 +000052class SsaRedundantPhiElimination : public HOptimization {
Nicolas Geoffray7dc206a2014-07-11 09:49:49 +010053 public:
54 explicit SsaRedundantPhiElimination(HGraph* graph)
Vladimir Markof3612672017-10-10 10:38:16 +010055 : HOptimization(graph, kSsaRedundantPhiEliminationPassName) {}
Nicolas Geoffray7dc206a2014-07-11 09:49:49 +010056
Roland Levillainbbc6e7e2018-08-24 16:58:47 +010057 bool Run() override;
Nicolas Geoffray7dc206a2014-07-11 09:49:49 +010058
Andreas Gampe7c3952f2015-02-19 18:21:24 -080059 static constexpr const char* kSsaRedundantPhiEliminationPassName = "redundant_phi_elimination";
60
Nicolas Geoffray7dc206a2014-07-11 09:49:49 +010061 private:
Nicolas Geoffray7dc206a2014-07-11 09:49:49 +010062 DISALLOW_COPY_AND_ASSIGN(SsaRedundantPhiElimination);
63};
64
65} // namespace art
66
67#endif // ART_COMPILER_OPTIMIZING_SSA_PHI_ELIMINATION_H_