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 20 #include "nodes.h" 21 #include "optimization.h" 22 23 namespace 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 */ 29 class SsaDeadPhiElimination : public HOptimization { 30 public: 31 explicit SsaDeadPhiElimination(HGraph* graph) 32 : HOptimization(graph, true, kSsaDeadPhiEliminationPassName), 33 worklist_(graph->GetArena(), kDefaultWorklistSize) {} 34 35 void Run() OVERRIDE; 36 37 void MarkDeadPhis(); 38 void EliminateDeadPhis(); 39 40 static constexpr const char* kSsaDeadPhiEliminationPassName = "dead_phi_elimination"; 41 42 private: 43 GrowableArray<HPhi*> worklist_; 44 45 static constexpr size_t kDefaultWorklistSize = 8; 46 47 DISALLOW_COPY_AND_ASSIGN(SsaDeadPhiElimination); 48 }; 49 50 /** 51 * Removes redundant phis that may have been introduced when doing SSA conversion. 52 * For example, when entering a loop, we create phis for all live registers. These 53 * registers might be updated with the same value, or not updated at all. We can just 54 * replace the phi with the value when entering the loop. 55 */ 56 class SsaRedundantPhiElimination : public HOptimization { 57 public: 58 explicit SsaRedundantPhiElimination(HGraph* graph) 59 : HOptimization(graph, true, kSsaRedundantPhiEliminationPassName), 60 worklist_(graph->GetArena(), kDefaultWorklistSize) {} 61 62 void Run() OVERRIDE; 63 64 static constexpr const char* kSsaRedundantPhiEliminationPassName = "redundant_phi_elimination"; 65 66 private: 67 GrowableArray<HPhi*> worklist_; 68 69 static constexpr size_t kDefaultWorklistSize = 8; 70 71 DISALLOW_COPY_AND_ASSIGN(SsaRedundantPhiElimination); 72 }; 73 74 } // namespace art 75 76 #endif // ART_COMPILER_OPTIMIZING_SSA_PHI_ELIMINATION_H_ 77