Nicolas Geoffray | 7dc206a | 2014-07-11 09:49:49 +0100 | [diff] [blame] | 1 | /* |
| 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 | |
Vladimir Marko | 2aaa4b5 | 2015-09-17 17:03:26 +0100 | [diff] [blame] | 20 | #include "base/arena_containers.h" |
Nicolas Geoffray | 7dc206a | 2014-07-11 09:49:49 +0100 | [diff] [blame] | 21 | #include "nodes.h" |
Nicolas Geoffray | 5e6916c | 2014-11-18 16:53:35 +0000 | [diff] [blame] | 22 | #include "optimization.h" |
Nicolas Geoffray | 7dc206a | 2014-07-11 09:49:49 +0100 | [diff] [blame] | 23 | |
| 24 | namespace art { |
| 25 | |
| 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 Geoffray | 5e6916c | 2014-11-18 16:53:35 +0000 | [diff] [blame] | 30 | class SsaDeadPhiElimination : public HOptimization { |
Nicolas Geoffray | 7dc206a | 2014-07-11 09:49:49 +0100 | [diff] [blame] | 31 | public: |
| 32 | explicit SsaDeadPhiElimination(HGraph* graph) |
David Brazdil | 69ba7b7 | 2015-06-23 18:27:30 +0100 | [diff] [blame] | 33 | : HOptimization(graph, kSsaDeadPhiEliminationPassName), |
Vladimir Marko | 2aaa4b5 | 2015-09-17 17:03:26 +0100 | [diff] [blame] | 34 | worklist_(graph->GetArena()->Adapter(kArenaAllocSsaPhiElimination)) { |
| 35 | worklist_.reserve(kDefaultWorklistSize); |
| 36 | } |
Nicolas Geoffray | 7dc206a | 2014-07-11 09:49:49 +0100 | [diff] [blame] | 37 | |
Nicolas Geoffray | 5e6916c | 2014-11-18 16:53:35 +0000 | [diff] [blame] | 38 | void Run() OVERRIDE; |
Nicolas Geoffray | 7dc206a | 2014-07-11 09:49:49 +0100 | [diff] [blame] | 39 | |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 40 | void MarkDeadPhis(); |
| 41 | void EliminateDeadPhis(); |
| 42 | |
Andreas Gampe | 7c3952f | 2015-02-19 18:21:24 -0800 | [diff] [blame] | 43 | static constexpr const char* kSsaDeadPhiEliminationPassName = "dead_phi_elimination"; |
| 44 | |
Nicolas Geoffray | 7dc206a | 2014-07-11 09:49:49 +0100 | [diff] [blame] | 45 | private: |
Vladimir Marko | 2aaa4b5 | 2015-09-17 17:03:26 +0100 | [diff] [blame] | 46 | ArenaVector<HPhi*> worklist_; |
Nicolas Geoffray | 7dc206a | 2014-07-11 09:49:49 +0100 | [diff] [blame] | 47 | |
| 48 | static constexpr size_t kDefaultWorklistSize = 8; |
| 49 | |
| 50 | DISALLOW_COPY_AND_ASSIGN(SsaDeadPhiElimination); |
| 51 | }; |
| 52 | |
| 53 | /** |
| 54 | * Removes redundant phis that may have been introduced when doing SSA conversion. |
| 55 | * For example, when entering a loop, we create phis for all live registers. These |
| 56 | * registers might be updated with the same value, or not updated at all. We can just |
| 57 | * replace the phi with the value when entering the loop. |
| 58 | */ |
Nicolas Geoffray | 5e6916c | 2014-11-18 16:53:35 +0000 | [diff] [blame] | 59 | class SsaRedundantPhiElimination : public HOptimization { |
Nicolas Geoffray | 7dc206a | 2014-07-11 09:49:49 +0100 | [diff] [blame] | 60 | public: |
| 61 | explicit SsaRedundantPhiElimination(HGraph* graph) |
David Brazdil | 69ba7b7 | 2015-06-23 18:27:30 +0100 | [diff] [blame] | 62 | : HOptimization(graph, kSsaRedundantPhiEliminationPassName), |
Vladimir Marko | 2aaa4b5 | 2015-09-17 17:03:26 +0100 | [diff] [blame] | 63 | worklist_(graph->GetArena()->Adapter(kArenaAllocSsaPhiElimination)) { |
| 64 | worklist_.reserve(kDefaultWorklistSize); |
| 65 | } |
Nicolas Geoffray | 7dc206a | 2014-07-11 09:49:49 +0100 | [diff] [blame] | 66 | |
Nicolas Geoffray | 5e6916c | 2014-11-18 16:53:35 +0000 | [diff] [blame] | 67 | void Run() OVERRIDE; |
Nicolas Geoffray | 7dc206a | 2014-07-11 09:49:49 +0100 | [diff] [blame] | 68 | |
Andreas Gampe | 7c3952f | 2015-02-19 18:21:24 -0800 | [diff] [blame] | 69 | static constexpr const char* kSsaRedundantPhiEliminationPassName = "redundant_phi_elimination"; |
| 70 | |
Nicolas Geoffray | 7dc206a | 2014-07-11 09:49:49 +0100 | [diff] [blame] | 71 | private: |
Vladimir Marko | 2aaa4b5 | 2015-09-17 17:03:26 +0100 | [diff] [blame] | 72 | ArenaVector<HPhi*> worklist_; |
Nicolas Geoffray | 7dc206a | 2014-07-11 09:49:49 +0100 | [diff] [blame] | 73 | |
| 74 | static constexpr size_t kDefaultWorklistSize = 8; |
| 75 | |
| 76 | DISALLOW_COPY_AND_ASSIGN(SsaRedundantPhiElimination); |
| 77 | }; |
| 78 | |
| 79 | } // namespace art |
| 80 | |
| 81 | #endif // ART_COMPILER_OPTIMIZING_SSA_PHI_ELIMINATION_H_ |