17dc206a53a42a658f52d5cb0b7e79b47da370c9bNicolas Geoffray/* 27dc206a53a42a658f52d5cb0b7e79b47da370c9bNicolas Geoffray * Copyright (C) 2014 The Android Open Source Project 37dc206a53a42a658f52d5cb0b7e79b47da370c9bNicolas Geoffray * 47dc206a53a42a658f52d5cb0b7e79b47da370c9bNicolas Geoffray * Licensed under the Apache License, Version 2.0 (the "License"); 57dc206a53a42a658f52d5cb0b7e79b47da370c9bNicolas Geoffray * you may not use this file except in compliance with the License. 67dc206a53a42a658f52d5cb0b7e79b47da370c9bNicolas Geoffray * You may obtain a copy of the License at 77dc206a53a42a658f52d5cb0b7e79b47da370c9bNicolas Geoffray * 87dc206a53a42a658f52d5cb0b7e79b47da370c9bNicolas Geoffray * http://www.apache.org/licenses/LICENSE-2.0 97dc206a53a42a658f52d5cb0b7e79b47da370c9bNicolas Geoffray * 107dc206a53a42a658f52d5cb0b7e79b47da370c9bNicolas Geoffray * Unless required by applicable law or agreed to in writing, software 117dc206a53a42a658f52d5cb0b7e79b47da370c9bNicolas Geoffray * distributed under the License is distributed on an "AS IS" BASIS, 127dc206a53a42a658f52d5cb0b7e79b47da370c9bNicolas Geoffray * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 137dc206a53a42a658f52d5cb0b7e79b47da370c9bNicolas Geoffray * See the License for the specific language governing permissions and 147dc206a53a42a658f52d5cb0b7e79b47da370c9bNicolas Geoffray * limitations under the License. 157dc206a53a42a658f52d5cb0b7e79b47da370c9bNicolas Geoffray */ 167dc206a53a42a658f52d5cb0b7e79b47da370c9bNicolas Geoffray 177dc206a53a42a658f52d5cb0b7e79b47da370c9bNicolas Geoffray#ifndef ART_COMPILER_OPTIMIZING_SSA_PHI_ELIMINATION_H_ 187dc206a53a42a658f52d5cb0b7e79b47da370c9bNicolas Geoffray#define ART_COMPILER_OPTIMIZING_SSA_PHI_ELIMINATION_H_ 197dc206a53a42a658f52d5cb0b7e79b47da370c9bNicolas Geoffray 207dc206a53a42a658f52d5cb0b7e79b47da370c9bNicolas Geoffray#include "nodes.h" 215e6916cea259897baaca019c5c7a5d05746306edNicolas Geoffray#include "optimization.h" 227dc206a53a42a658f52d5cb0b7e79b47da370c9bNicolas Geoffray 237dc206a53a42a658f52d5cb0b7e79b47da370c9bNicolas Geoffraynamespace art { 247dc206a53a42a658f52d5cb0b7e79b47da370c9bNicolas Geoffray 257dc206a53a42a658f52d5cb0b7e79b47da370c9bNicolas Geoffray/** 267dc206a53a42a658f52d5cb0b7e79b47da370c9bNicolas Geoffray * Optimization phase that removes dead phis from the graph. Dead phis are unused 277dc206a53a42a658f52d5cb0b7e79b47da370c9bNicolas Geoffray * phis, or phis only used by other phis. 287dc206a53a42a658f52d5cb0b7e79b47da370c9bNicolas Geoffray */ 295e6916cea259897baaca019c5c7a5d05746306edNicolas Geoffrayclass SsaDeadPhiElimination : public HOptimization { 307dc206a53a42a658f52d5cb0b7e79b47da370c9bNicolas Geoffray public: 317dc206a53a42a658f52d5cb0b7e79b47da370c9bNicolas Geoffray explicit SsaDeadPhiElimination(HGraph* graph) 32f361267ff86e775ed146138220c5a2f70b4a4b3dVladimir Marko : HOptimization(graph, kSsaDeadPhiEliminationPassName) {} 337dc206a53a42a658f52d5cb0b7e79b47da370c9bNicolas Geoffray 345e6916cea259897baaca019c5c7a5d05746306edNicolas Geoffray void Run() OVERRIDE; 357dc206a53a42a658f52d5cb0b7e79b47da370c9bNicolas Geoffray 36d6138ef1ea13d07ae555542f8898b30d89e9ac9aNicolas Geoffray void MarkDeadPhis(); 37d6138ef1ea13d07ae555542f8898b30d89e9ac9aNicolas Geoffray void EliminateDeadPhis(); 38d6138ef1ea13d07ae555542f8898b30d89e9ac9aNicolas Geoffray 397c3952f423b8213083d60596a5f0bf4237ca3f7bAndreas Gampe static constexpr const char* kSsaDeadPhiEliminationPassName = "dead_phi_elimination"; 407c3952f423b8213083d60596a5f0bf4237ca3f7bAndreas Gampe 417dc206a53a42a658f52d5cb0b7e79b47da370c9bNicolas Geoffray private: 427dc206a53a42a658f52d5cb0b7e79b47da370c9bNicolas Geoffray DISALLOW_COPY_AND_ASSIGN(SsaDeadPhiElimination); 437dc206a53a42a658f52d5cb0b7e79b47da370c9bNicolas Geoffray}; 447dc206a53a42a658f52d5cb0b7e79b47da370c9bNicolas Geoffray 457dc206a53a42a658f52d5cb0b7e79b47da370c9bNicolas Geoffray/** 467dc206a53a42a658f52d5cb0b7e79b47da370c9bNicolas Geoffray * Removes redundant phis that may have been introduced when doing SSA conversion. 477dc206a53a42a658f52d5cb0b7e79b47da370c9bNicolas Geoffray * For example, when entering a loop, we create phis for all live registers. These 487dc206a53a42a658f52d5cb0b7e79b47da370c9bNicolas Geoffray * registers might be updated with the same value, or not updated at all. We can just 497dc206a53a42a658f52d5cb0b7e79b47da370c9bNicolas Geoffray * replace the phi with the value when entering the loop. 507dc206a53a42a658f52d5cb0b7e79b47da370c9bNicolas Geoffray */ 515e6916cea259897baaca019c5c7a5d05746306edNicolas Geoffrayclass SsaRedundantPhiElimination : public HOptimization { 527dc206a53a42a658f52d5cb0b7e79b47da370c9bNicolas Geoffray public: 537dc206a53a42a658f52d5cb0b7e79b47da370c9bNicolas Geoffray explicit SsaRedundantPhiElimination(HGraph* graph) 54f361267ff86e775ed146138220c5a2f70b4a4b3dVladimir Marko : HOptimization(graph, kSsaRedundantPhiEliminationPassName) {} 557dc206a53a42a658f52d5cb0b7e79b47da370c9bNicolas Geoffray 565e6916cea259897baaca019c5c7a5d05746306edNicolas Geoffray void Run() OVERRIDE; 577dc206a53a42a658f52d5cb0b7e79b47da370c9bNicolas Geoffray 587c3952f423b8213083d60596a5f0bf4237ca3f7bAndreas Gampe static constexpr const char* kSsaRedundantPhiEliminationPassName = "redundant_phi_elimination"; 597c3952f423b8213083d60596a5f0bf4237ca3f7bAndreas Gampe 607dc206a53a42a658f52d5cb0b7e79b47da370c9bNicolas Geoffray private: 617dc206a53a42a658f52d5cb0b7e79b47da370c9bNicolas Geoffray DISALLOW_COPY_AND_ASSIGN(SsaRedundantPhiElimination); 627dc206a53a42a658f52d5cb0b7e79b47da370c9bNicolas Geoffray}; 637dc206a53a42a658f52d5cb0b7e79b47da370c9bNicolas Geoffray 647dc206a53a42a658f52d5cb0b7e79b47da370c9bNicolas Geoffray} // namespace art 657dc206a53a42a658f52d5cb0b7e79b47da370c9bNicolas Geoffray 667dc206a53a42a658f52d5cb0b7e79b47da370c9bNicolas Geoffray#endif // ART_COMPILER_OPTIMIZING_SSA_PHI_ELIMINATION_H_ 67