14e97c539408f47145526f0062c1c06df99146a73Jean Christophe Beyler/* 24e97c539408f47145526f0062c1c06df99146a73Jean Christophe Beyler * Copyright (C) 2014 The Android Open Source Project 34e97c539408f47145526f0062c1c06df99146a73Jean Christophe Beyler * 44e97c539408f47145526f0062c1c06df99146a73Jean Christophe Beyler * Licensed under the Apache License, Version 2.0 (the "License"); 54e97c539408f47145526f0062c1c06df99146a73Jean Christophe Beyler * you may not use this file except in compliance with the License. 64e97c539408f47145526f0062c1c06df99146a73Jean Christophe Beyler * You may obtain a copy of the License at 74e97c539408f47145526f0062c1c06df99146a73Jean Christophe Beyler * 84e97c539408f47145526f0062c1c06df99146a73Jean Christophe Beyler * http://www.apache.org/licenses/LICENSE-2.0 94e97c539408f47145526f0062c1c06df99146a73Jean Christophe Beyler * 104e97c539408f47145526f0062c1c06df99146a73Jean Christophe Beyler * Unless required by applicable law or agreed to in writing, software 114e97c539408f47145526f0062c1c06df99146a73Jean Christophe Beyler * distributed under the License is distributed on an "AS IS" BASIS, 124e97c539408f47145526f0062c1c06df99146a73Jean Christophe Beyler * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 134e97c539408f47145526f0062c1c06df99146a73Jean Christophe Beyler * See the License for the specific language governing permissions and 144e97c539408f47145526f0062c1c06df99146a73Jean Christophe Beyler * limitations under the License. 154e97c539408f47145526f0062c1c06df99146a73Jean Christophe Beyler */ 164e97c539408f47145526f0062c1c06df99146a73Jean Christophe Beyler 174e97c539408f47145526f0062c1c06df99146a73Jean Christophe Beyler#ifndef ART_COMPILER_DEX_BB_OPTIMIZATIONS_H_ 184e97c539408f47145526f0062c1c06df99146a73Jean Christophe Beyler#define ART_COMPILER_DEX_BB_OPTIMIZATIONS_H_ 194e97c539408f47145526f0062c1c06df99146a73Jean Christophe Beyler 204e97c539408f47145526f0062c1c06df99146a73Jean Christophe Beyler#include "compiler_internals.h" 214f59668b3d51f63601ebe59dbd2b7e8a7c5bd093James C Scott#include "pass_me.h" 224e97c539408f47145526f0062c1c06df99146a73Jean Christophe Beyler 234e97c539408f47145526f0062c1c06df99146a73Jean Christophe Beylernamespace art { 244e97c539408f47145526f0062c1c06df99146a73Jean Christophe Beyler 254e97c539408f47145526f0062c1c06df99146a73Jean Christophe Beyler/** 26be0e546730e532ef0987cd4bde2c6f5a1b14dd2aVladimir Marko * @class CacheFieldLoweringInfo 27be0e546730e532ef0987cd4bde2c6f5a1b14dd2aVladimir Marko * @brief Cache the lowering info for fields used by IGET/IPUT/SGET/SPUT insns. 28be0e546730e532ef0987cd4bde2c6f5a1b14dd2aVladimir Marko */ 294f59668b3d51f63601ebe59dbd2b7e8a7c5bd093James C Scottclass CacheFieldLoweringInfo : public PassME { 30be0e546730e532ef0987cd4bde2c6f5a1b14dd2aVladimir Marko public: 314f59668b3d51f63601ebe59dbd2b7e8a7c5bd093James C Scott CacheFieldLoweringInfo() : PassME("CacheFieldLoweringInfo", kNoNodes) { 32be0e546730e532ef0987cd4bde2c6f5a1b14dd2aVladimir Marko } 33be0e546730e532ef0987cd4bde2c6f5a1b14dd2aVladimir Marko 34e1f65bcb957a65c6d45b319d968bc53a833f2c65Jean Christophe Beyler void Start(PassDataHolder* data) const { 354f59668b3d51f63601ebe59dbd2b7e8a7c5bd093James C Scott DCHECK(data != nullptr); 36eb1404a0b59c4a981af61852c94129507efc331aJean Christophe Beyler CompilationUnit* c_unit = down_cast<PassMEDataHolder*>(data)->c_unit; 37eb1404a0b59c4a981af61852c94129507efc331aJean Christophe Beyler DCHECK(c_unit != nullptr); 38eb1404a0b59c4a981af61852c94129507efc331aJean Christophe Beyler c_unit->mir_graph->DoCacheFieldLoweringInfo(); 39be0e546730e532ef0987cd4bde2c6f5a1b14dd2aVladimir Marko } 403d73ba2ce682edfaf41f29521bd6039c6499a1c5Vladimir Marko 414f59668b3d51f63601ebe59dbd2b7e8a7c5bd093James C Scott bool Gate(const PassDataHolder* data) const { 424f59668b3d51f63601ebe59dbd2b7e8a7c5bd093James C Scott DCHECK(data != nullptr); 43eb1404a0b59c4a981af61852c94129507efc331aJean Christophe Beyler CompilationUnit* c_unit = down_cast<const PassMEDataHolder*>(data)->c_unit; 44eb1404a0b59c4a981af61852c94129507efc331aJean Christophe Beyler DCHECK(c_unit != nullptr); 45eb1404a0b59c4a981af61852c94129507efc331aJean Christophe Beyler return c_unit->mir_graph->HasFieldAccess(); 463d73ba2ce682edfaf41f29521bd6039c6499a1c5Vladimir Marko } 47be0e546730e532ef0987cd4bde2c6f5a1b14dd2aVladimir Marko}; 48be0e546730e532ef0987cd4bde2c6f5a1b14dd2aVladimir Marko 49be0e546730e532ef0987cd4bde2c6f5a1b14dd2aVladimir Marko/** 50f096aad9203d7c50b2f9cbe1c1215a50c265a059Vladimir Marko * @class CacheMethodLoweringInfo 51f096aad9203d7c50b2f9cbe1c1215a50c265a059Vladimir Marko * @brief Cache the lowering info for methods called by INVOKEs. 52f096aad9203d7c50b2f9cbe1c1215a50c265a059Vladimir Marko */ 534f59668b3d51f63601ebe59dbd2b7e8a7c5bd093James C Scottclass CacheMethodLoweringInfo : public PassME { 54f096aad9203d7c50b2f9cbe1c1215a50c265a059Vladimir Marko public: 554f59668b3d51f63601ebe59dbd2b7e8a7c5bd093James C Scott CacheMethodLoweringInfo() : PassME("CacheMethodLoweringInfo", kNoNodes) { 56f096aad9203d7c50b2f9cbe1c1215a50c265a059Vladimir Marko } 57f096aad9203d7c50b2f9cbe1c1215a50c265a059Vladimir Marko 58e1f65bcb957a65c6d45b319d968bc53a833f2c65Jean Christophe Beyler void Start(PassDataHolder* data) const { 594f59668b3d51f63601ebe59dbd2b7e8a7c5bd093James C Scott DCHECK(data != nullptr); 60eb1404a0b59c4a981af61852c94129507efc331aJean Christophe Beyler CompilationUnit* c_unit = down_cast<PassMEDataHolder*>(data)->c_unit; 61eb1404a0b59c4a981af61852c94129507efc331aJean Christophe Beyler DCHECK(c_unit != nullptr); 62eb1404a0b59c4a981af61852c94129507efc331aJean Christophe Beyler c_unit->mir_graph->DoCacheMethodLoweringInfo(); 63f096aad9203d7c50b2f9cbe1c1215a50c265a059Vladimir Marko } 643d73ba2ce682edfaf41f29521bd6039c6499a1c5Vladimir Marko 654f59668b3d51f63601ebe59dbd2b7e8a7c5bd093James C Scott bool Gate(const PassDataHolder* data) const { 664f59668b3d51f63601ebe59dbd2b7e8a7c5bd093James C Scott DCHECK(data != nullptr); 67eb1404a0b59c4a981af61852c94129507efc331aJean Christophe Beyler CompilationUnit* c_unit = down_cast<const PassMEDataHolder*>(data)->c_unit; 68eb1404a0b59c4a981af61852c94129507efc331aJean Christophe Beyler DCHECK(c_unit != nullptr); 69eb1404a0b59c4a981af61852c94129507efc331aJean Christophe Beyler return c_unit->mir_graph->HasInvokes(); 703d73ba2ce682edfaf41f29521bd6039c6499a1c5Vladimir Marko } 71f096aad9203d7c50b2f9cbe1c1215a50c265a059Vladimir Marko}; 72f096aad9203d7c50b2f9cbe1c1215a50c265a059Vladimir Marko 73f096aad9203d7c50b2f9cbe1c1215a50c265a059Vladimir Marko/** 74cb804742f8786826286046e9c4489ef9d7ceb7ecRazvan A Lupusoru * @class SpecialMethodInliner 75cb804742f8786826286046e9c4489ef9d7ceb7ecRazvan A Lupusoru * @brief Performs method inlining pass on special kinds of methods. 76cb804742f8786826286046e9c4489ef9d7ceb7ecRazvan A Lupusoru * @details Special methods are methods that fall in one of the following categories: 77cb804742f8786826286046e9c4489ef9d7ceb7ecRazvan A Lupusoru * empty, instance getter, instance setter, argument return, and constant return. 789820b7c1dc70e75ad405b9e6e63578fa9fe94e94Vladimir Marko */ 79cb804742f8786826286046e9c4489ef9d7ceb7ecRazvan A Lupusoruclass SpecialMethodInliner : public PassME { 809820b7c1dc70e75ad405b9e6e63578fa9fe94e94Vladimir Marko public: 81cb804742f8786826286046e9c4489ef9d7ceb7ecRazvan A Lupusoru SpecialMethodInliner() : PassME("SpecialMethodInliner") { 829820b7c1dc70e75ad405b9e6e63578fa9fe94e94Vladimir Marko } 839820b7c1dc70e75ad405b9e6e63578fa9fe94e94Vladimir Marko 844f59668b3d51f63601ebe59dbd2b7e8a7c5bd093James C Scott bool Gate(const PassDataHolder* data) const { 854f59668b3d51f63601ebe59dbd2b7e8a7c5bd093James C Scott DCHECK(data != nullptr); 86eb1404a0b59c4a981af61852c94129507efc331aJean Christophe Beyler CompilationUnit* c_unit = down_cast<const PassMEDataHolder*>(data)->c_unit; 87eb1404a0b59c4a981af61852c94129507efc331aJean Christophe Beyler DCHECK(c_unit != nullptr); 88eb1404a0b59c4a981af61852c94129507efc331aJean Christophe Beyler return c_unit->mir_graph->InlineSpecialMethodsGate(); 899820b7c1dc70e75ad405b9e6e63578fa9fe94e94Vladimir Marko } 909820b7c1dc70e75ad405b9e6e63578fa9fe94e94Vladimir Marko 91e1f65bcb957a65c6d45b319d968bc53a833f2c65Jean Christophe Beyler void Start(PassDataHolder* data) const { 924f59668b3d51f63601ebe59dbd2b7e8a7c5bd093James C Scott DCHECK(data != nullptr); 93eb1404a0b59c4a981af61852c94129507efc331aJean Christophe Beyler CompilationUnit* c_unit = down_cast<PassMEDataHolder*>(data)->c_unit; 94eb1404a0b59c4a981af61852c94129507efc331aJean Christophe Beyler DCHECK(c_unit != nullptr); 95eb1404a0b59c4a981af61852c94129507efc331aJean Christophe Beyler c_unit->mir_graph->InlineSpecialMethodsStart(); 969820b7c1dc70e75ad405b9e6e63578fa9fe94e94Vladimir Marko } 979820b7c1dc70e75ad405b9e6e63578fa9fe94e94Vladimir Marko 984f59668b3d51f63601ebe59dbd2b7e8a7c5bd093James C Scott bool Worker(const PassDataHolder* data) const { 994f59668b3d51f63601ebe59dbd2b7e8a7c5bd093James C Scott DCHECK(data != nullptr); 1004f59668b3d51f63601ebe59dbd2b7e8a7c5bd093James C Scott const PassMEDataHolder* pass_me_data_holder = down_cast<const PassMEDataHolder*>(data); 101eb1404a0b59c4a981af61852c94129507efc331aJean Christophe Beyler CompilationUnit* c_unit = pass_me_data_holder->c_unit; 102eb1404a0b59c4a981af61852c94129507efc331aJean Christophe Beyler DCHECK(c_unit != nullptr); 1034f59668b3d51f63601ebe59dbd2b7e8a7c5bd093James C Scott BasicBlock* bb = pass_me_data_holder->bb; 1044f59668b3d51f63601ebe59dbd2b7e8a7c5bd093James C Scott DCHECK(bb != nullptr); 105eb1404a0b59c4a981af61852c94129507efc331aJean Christophe Beyler c_unit->mir_graph->InlineSpecialMethods(bb); 1069820b7c1dc70e75ad405b9e6e63578fa9fe94e94Vladimir Marko // No need of repeating, so just return false. 1079820b7c1dc70e75ad405b9e6e63578fa9fe94e94Vladimir Marko return false; 1089820b7c1dc70e75ad405b9e6e63578fa9fe94e94Vladimir Marko } 1099820b7c1dc70e75ad405b9e6e63578fa9fe94e94Vladimir Marko 110e1f65bcb957a65c6d45b319d968bc53a833f2c65Jean Christophe Beyler void End(PassDataHolder* data) const { 1114f59668b3d51f63601ebe59dbd2b7e8a7c5bd093James C Scott DCHECK(data != nullptr); 112eb1404a0b59c4a981af61852c94129507efc331aJean Christophe Beyler CompilationUnit* c_unit = down_cast<PassMEDataHolder*>(data)->c_unit; 113eb1404a0b59c4a981af61852c94129507efc331aJean Christophe Beyler DCHECK(c_unit != nullptr); 114eb1404a0b59c4a981af61852c94129507efc331aJean Christophe Beyler c_unit->mir_graph->InlineSpecialMethodsEnd(); 1159820b7c1dc70e75ad405b9e6e63578fa9fe94e94Vladimir Marko } 1169820b7c1dc70e75ad405b9e6e63578fa9fe94e94Vladimir Marko}; 1179820b7c1dc70e75ad405b9e6e63578fa9fe94e94Vladimir Marko 1189820b7c1dc70e75ad405b9e6e63578fa9fe94e94Vladimir Marko/** 1194e97c539408f47145526f0062c1c06df99146a73Jean Christophe Beyler * @class CodeLayout 1204e97c539408f47145526f0062c1c06df99146a73Jean Christophe Beyler * @brief Perform the code layout pass. 1214e97c539408f47145526f0062c1c06df99146a73Jean Christophe Beyler */ 1224f59668b3d51f63601ebe59dbd2b7e8a7c5bd093James C Scottclass CodeLayout : public PassME { 1234e97c539408f47145526f0062c1c06df99146a73Jean Christophe Beyler public: 1242469e60e6ff08c2a0b4cd1e209246c5d91027679Jean Christophe Beyler CodeLayout() : PassME("CodeLayout", kAllNodes, kOptimizationBasicBlockChange, "2_post_layout_cfg") { 1254e97c539408f47145526f0062c1c06df99146a73Jean Christophe Beyler } 1264e97c539408f47145526f0062c1c06df99146a73Jean Christophe Beyler 127e1f65bcb957a65c6d45b319d968bc53a833f2c65Jean Christophe Beyler void Start(PassDataHolder* data) const { 1284f59668b3d51f63601ebe59dbd2b7e8a7c5bd093James C Scott DCHECK(data != nullptr); 129eb1404a0b59c4a981af61852c94129507efc331aJean Christophe Beyler CompilationUnit* c_unit = down_cast<PassMEDataHolder*>(data)->c_unit; 130eb1404a0b59c4a981af61852c94129507efc331aJean Christophe Beyler DCHECK(c_unit != nullptr); 131eb1404a0b59c4a981af61852c94129507efc331aJean Christophe Beyler c_unit->mir_graph->VerifyDataflow(); 132eb1404a0b59c4a981af61852c94129507efc331aJean Christophe Beyler c_unit->mir_graph->ClearAllVisitedFlags(); 1334e97c539408f47145526f0062c1c06df99146a73Jean Christophe Beyler } 1344e97c539408f47145526f0062c1c06df99146a73Jean Christophe Beyler 1354f59668b3d51f63601ebe59dbd2b7e8a7c5bd093James C Scott bool Worker(const PassDataHolder* data) const; 1364e97c539408f47145526f0062c1c06df99146a73Jean Christophe Beyler}; 1374e97c539408f47145526f0062c1c06df99146a73Jean Christophe Beyler 1384e97c539408f47145526f0062c1c06df99146a73Jean Christophe Beyler/** 1394e97c539408f47145526f0062c1c06df99146a73Jean Christophe Beyler * @class NullCheckEliminationAndTypeInference 1404e97c539408f47145526f0062c1c06df99146a73Jean Christophe Beyler * @brief Null check elimination and type inference. 1414e97c539408f47145526f0062c1c06df99146a73Jean Christophe Beyler */ 1424f59668b3d51f63601ebe59dbd2b7e8a7c5bd093James C Scottclass NullCheckEliminationAndTypeInference : public PassME { 1434e97c539408f47145526f0062c1c06df99146a73Jean Christophe Beyler public: 14475ba13f244098f42584637b8fd3f6d74d2fc291aVladimir Marko NullCheckEliminationAndTypeInference() 145622bdbe6c295b08d06dfaa8d896b9ca152aa899cVladimir Marko : PassME("NCE_TypeInference", kRepeatingTopologicalSortTraversal, "4_post_nce_cfg") { 1464e97c539408f47145526f0062c1c06df99146a73Jean Christophe Beyler } 1474e97c539408f47145526f0062c1c06df99146a73Jean Christophe Beyler 148e1f65bcb957a65c6d45b319d968bc53a833f2c65Jean Christophe Beyler void Start(PassDataHolder* data) const { 1494f59668b3d51f63601ebe59dbd2b7e8a7c5bd093James C Scott DCHECK(data != nullptr); 150eb1404a0b59c4a981af61852c94129507efc331aJean Christophe Beyler CompilationUnit* c_unit = down_cast<PassMEDataHolder*>(data)->c_unit; 151eb1404a0b59c4a981af61852c94129507efc331aJean Christophe Beyler DCHECK(c_unit != nullptr); 152eb1404a0b59c4a981af61852c94129507efc331aJean Christophe Beyler c_unit->mir_graph->EliminateNullChecksAndInferTypesStart(); 153bfea9c29e809e04bde4a46591fea64c5a7b922fbVladimir Marko } 154bfea9c29e809e04bde4a46591fea64c5a7b922fbVladimir Marko 1554f59668b3d51f63601ebe59dbd2b7e8a7c5bd093James C Scott bool Worker(const PassDataHolder* data) const { 1564f59668b3d51f63601ebe59dbd2b7e8a7c5bd093James C Scott DCHECK(data != nullptr); 1574f59668b3d51f63601ebe59dbd2b7e8a7c5bd093James C Scott const PassMEDataHolder* pass_me_data_holder = down_cast<const PassMEDataHolder*>(data); 158eb1404a0b59c4a981af61852c94129507efc331aJean Christophe Beyler CompilationUnit* c_unit = pass_me_data_holder->c_unit; 159eb1404a0b59c4a981af61852c94129507efc331aJean Christophe Beyler DCHECK(c_unit != nullptr); 1604f59668b3d51f63601ebe59dbd2b7e8a7c5bd093James C Scott BasicBlock* bb = pass_me_data_holder->bb; 1614f59668b3d51f63601ebe59dbd2b7e8a7c5bd093James C Scott DCHECK(bb != nullptr); 162eb1404a0b59c4a981af61852c94129507efc331aJean Christophe Beyler return c_unit->mir_graph->EliminateNullChecksAndInferTypes(bb); 1634e97c539408f47145526f0062c1c06df99146a73Jean Christophe Beyler } 164bfea9c29e809e04bde4a46591fea64c5a7b922fbVladimir Marko 165e1f65bcb957a65c6d45b319d968bc53a833f2c65Jean Christophe Beyler void End(PassDataHolder* data) const { 1664f59668b3d51f63601ebe59dbd2b7e8a7c5bd093James C Scott DCHECK(data != nullptr); 167eb1404a0b59c4a981af61852c94129507efc331aJean Christophe Beyler CompilationUnit* c_unit = down_cast<PassMEDataHolder*>(data)->c_unit; 168eb1404a0b59c4a981af61852c94129507efc331aJean Christophe Beyler DCHECK(c_unit != nullptr); 169eb1404a0b59c4a981af61852c94129507efc331aJean Christophe Beyler c_unit->mir_graph->EliminateNullChecksAndInferTypesEnd(); 170bfea9c29e809e04bde4a46591fea64c5a7b922fbVladimir Marko } 171bfea9c29e809e04bde4a46591fea64c5a7b922fbVladimir Marko}; 172bfea9c29e809e04bde4a46591fea64c5a7b922fbVladimir Marko 1734f59668b3d51f63601ebe59dbd2b7e8a7c5bd093James C Scottclass ClassInitCheckElimination : public PassME { 174bfea9c29e809e04bde4a46591fea64c5a7b922fbVladimir Marko public: 175622bdbe6c295b08d06dfaa8d896b9ca152aa899cVladimir Marko ClassInitCheckElimination() 17655fff044d3a4f7196098e25bab1dad106d9b54a2Vladimir Marko : PassME("ClInitCheckElimination", kLoopRepeatingTopologicalSortTraversal) { 177bfea9c29e809e04bde4a46591fea64c5a7b922fbVladimir Marko } 178bfea9c29e809e04bde4a46591fea64c5a7b922fbVladimir Marko 1794f59668b3d51f63601ebe59dbd2b7e8a7c5bd093James C Scott bool Gate(const PassDataHolder* data) const { 1804f59668b3d51f63601ebe59dbd2b7e8a7c5bd093James C Scott DCHECK(data != nullptr); 181eb1404a0b59c4a981af61852c94129507efc331aJean Christophe Beyler CompilationUnit* c_unit = down_cast<const PassMEDataHolder*>(data)->c_unit; 182eb1404a0b59c4a981af61852c94129507efc331aJean Christophe Beyler DCHECK(c_unit != nullptr); 183eb1404a0b59c4a981af61852c94129507efc331aJean Christophe Beyler return c_unit->mir_graph->EliminateClassInitChecksGate(); 184bfea9c29e809e04bde4a46591fea64c5a7b922fbVladimir Marko } 185bfea9c29e809e04bde4a46591fea64c5a7b922fbVladimir Marko 1864f59668b3d51f63601ebe59dbd2b7e8a7c5bd093James C Scott bool Worker(const PassDataHolder* data) const { 1874f59668b3d51f63601ebe59dbd2b7e8a7c5bd093James C Scott DCHECK(data != nullptr); 1884f59668b3d51f63601ebe59dbd2b7e8a7c5bd093James C Scott const PassMEDataHolder* pass_me_data_holder = down_cast<const PassMEDataHolder*>(data); 189eb1404a0b59c4a981af61852c94129507efc331aJean Christophe Beyler CompilationUnit* c_unit = pass_me_data_holder->c_unit; 190eb1404a0b59c4a981af61852c94129507efc331aJean Christophe Beyler DCHECK(c_unit != nullptr); 1914f59668b3d51f63601ebe59dbd2b7e8a7c5bd093James C Scott BasicBlock* bb = pass_me_data_holder->bb; 1924f59668b3d51f63601ebe59dbd2b7e8a7c5bd093James C Scott DCHECK(bb != nullptr); 193eb1404a0b59c4a981af61852c94129507efc331aJean Christophe Beyler return c_unit->mir_graph->EliminateClassInitChecks(bb); 194bfea9c29e809e04bde4a46591fea64c5a7b922fbVladimir Marko } 195bfea9c29e809e04bde4a46591fea64c5a7b922fbVladimir Marko 196e1f65bcb957a65c6d45b319d968bc53a833f2c65Jean Christophe Beyler void End(PassDataHolder* data) const { 1974f59668b3d51f63601ebe59dbd2b7e8a7c5bd093James C Scott DCHECK(data != nullptr); 198eb1404a0b59c4a981af61852c94129507efc331aJean Christophe Beyler CompilationUnit* c_unit = down_cast<PassMEDataHolder*>(data)->c_unit; 199eb1404a0b59c4a981af61852c94129507efc331aJean Christophe Beyler DCHECK(c_unit != nullptr); 200eb1404a0b59c4a981af61852c94129507efc331aJean Christophe Beyler c_unit->mir_graph->EliminateClassInitChecksEnd(); 201bfea9c29e809e04bde4a46591fea64c5a7b922fbVladimir Marko } 2024e97c539408f47145526f0062c1c06df99146a73Jean Christophe Beyler}; 2034e97c539408f47145526f0062c1c06df99146a73Jean Christophe Beyler 2044e97c539408f47145526f0062c1c06df99146a73Jean Christophe Beyler/** 20595a059793c4c194f026afc74c713cc295d75d91aVladimir Marko * @class GlobalValueNumberingPass 20695a059793c4c194f026afc74c713cc295d75d91aVladimir Marko * @brief Performs the global value numbering pass. 20795a059793c4c194f026afc74c713cc295d75d91aVladimir Marko */ 20895a059793c4c194f026afc74c713cc295d75d91aVladimir Markoclass GlobalValueNumberingPass : public PassME { 20995a059793c4c194f026afc74c713cc295d75d91aVladimir Marko public: 21095a059793c4c194f026afc74c713cc295d75d91aVladimir Marko GlobalValueNumberingPass() 21155fff044d3a4f7196098e25bab1dad106d9b54a2Vladimir Marko : PassME("GVN", kLoopRepeatingTopologicalSortTraversal, "4_post_gvn_cfg") { 21295a059793c4c194f026afc74c713cc295d75d91aVladimir Marko } 21395a059793c4c194f026afc74c713cc295d75d91aVladimir Marko 21455fff044d3a4f7196098e25bab1dad106d9b54a2Vladimir Marko bool Gate(const PassDataHolder* data) const OVERRIDE { 21595a059793c4c194f026afc74c713cc295d75d91aVladimir Marko DCHECK(data != nullptr); 216eb1404a0b59c4a981af61852c94129507efc331aJean Christophe Beyler CompilationUnit* c_unit = down_cast<const PassMEDataHolder*>(data)->c_unit; 217eb1404a0b59c4a981af61852c94129507efc331aJean Christophe Beyler DCHECK(c_unit != nullptr); 218eb1404a0b59c4a981af61852c94129507efc331aJean Christophe Beyler return c_unit->mir_graph->ApplyGlobalValueNumberingGate(); 21995a059793c4c194f026afc74c713cc295d75d91aVladimir Marko } 22095a059793c4c194f026afc74c713cc295d75d91aVladimir Marko 22155fff044d3a4f7196098e25bab1dad106d9b54a2Vladimir Marko bool Worker(const PassDataHolder* data) const OVERRIDE { 22295a059793c4c194f026afc74c713cc295d75d91aVladimir Marko DCHECK(data != nullptr); 22395a059793c4c194f026afc74c713cc295d75d91aVladimir Marko const PassMEDataHolder* pass_me_data_holder = down_cast<const PassMEDataHolder*>(data); 224eb1404a0b59c4a981af61852c94129507efc331aJean Christophe Beyler CompilationUnit* c_unit = pass_me_data_holder->c_unit; 225eb1404a0b59c4a981af61852c94129507efc331aJean Christophe Beyler DCHECK(c_unit != nullptr); 22695a059793c4c194f026afc74c713cc295d75d91aVladimir Marko BasicBlock* bb = pass_me_data_holder->bb; 22795a059793c4c194f026afc74c713cc295d75d91aVladimir Marko DCHECK(bb != nullptr); 228eb1404a0b59c4a981af61852c94129507efc331aJean Christophe Beyler return c_unit->mir_graph->ApplyGlobalValueNumbering(bb); 22995a059793c4c194f026afc74c713cc295d75d91aVladimir Marko } 23095a059793c4c194f026afc74c713cc295d75d91aVladimir Marko 23155fff044d3a4f7196098e25bab1dad106d9b54a2Vladimir Marko void End(PassDataHolder* data) const OVERRIDE { 23295a059793c4c194f026afc74c713cc295d75d91aVladimir Marko DCHECK(data != nullptr); 233eb1404a0b59c4a981af61852c94129507efc331aJean Christophe Beyler CompilationUnit* c_unit = down_cast<PassMEDataHolder*>(data)->c_unit; 234eb1404a0b59c4a981af61852c94129507efc331aJean Christophe Beyler DCHECK(c_unit != nullptr); 235eb1404a0b59c4a981af61852c94129507efc331aJean Christophe Beyler c_unit->mir_graph->ApplyGlobalValueNumberingEnd(); 23695a059793c4c194f026afc74c713cc295d75d91aVladimir Marko } 23795a059793c4c194f026afc74c713cc295d75d91aVladimir Marko}; 23895a059793c4c194f026afc74c713cc295d75d91aVladimir Marko 23995a059793c4c194f026afc74c713cc295d75d91aVladimir Marko/** 24095a059793c4c194f026afc74c713cc295d75d91aVladimir Marko * @class BBCombine 24195a059793c4c194f026afc74c713cc295d75d91aVladimir Marko * @brief Perform the basic block combination pass. 2424e97c539408f47145526f0062c1c06df99146a73Jean Christophe Beyler */ 2434f59668b3d51f63601ebe59dbd2b7e8a7c5bd093James C Scottclass BBCombine : public PassME { 2444e97c539408f47145526f0062c1c06df99146a73Jean Christophe Beyler public: 2454f59668b3d51f63601ebe59dbd2b7e8a7c5bd093James C Scott BBCombine() : PassME("BBCombine", kPreOrderDFSTraversal, "5_post_bbcombine_cfg") { 2464e97c539408f47145526f0062c1c06df99146a73Jean Christophe Beyler } 2474e97c539408f47145526f0062c1c06df99146a73Jean Christophe Beyler 2484f59668b3d51f63601ebe59dbd2b7e8a7c5bd093James C Scott bool Gate(const PassDataHolder* data) const { 2494f59668b3d51f63601ebe59dbd2b7e8a7c5bd093James C Scott DCHECK(data != nullptr); 250eb1404a0b59c4a981af61852c94129507efc331aJean Christophe Beyler CompilationUnit* c_unit = down_cast<const PassMEDataHolder*>(data)->c_unit; 251eb1404a0b59c4a981af61852c94129507efc331aJean Christophe Beyler DCHECK(c_unit != nullptr); 252eb1404a0b59c4a981af61852c94129507efc331aJean Christophe Beyler return ((c_unit->disable_opt & (1 << kSuppressExceptionEdges)) != 0); 2534e97c539408f47145526f0062c1c06df99146a73Jean Christophe Beyler } 2544e97c539408f47145526f0062c1c06df99146a73Jean Christophe Beyler 2554f59668b3d51f63601ebe59dbd2b7e8a7c5bd093James C Scott bool Worker(const PassDataHolder* data) const; 2564e97c539408f47145526f0062c1c06df99146a73Jean Christophe Beyler}; 2574e97c539408f47145526f0062c1c06df99146a73Jean Christophe Beyler 2584e97c539408f47145526f0062c1c06df99146a73Jean Christophe Beyler/** 2594e97c539408f47145526f0062c1c06df99146a73Jean Christophe Beyler * @class BasicBlock Optimizations 2604e97c539408f47145526f0062c1c06df99146a73Jean Christophe Beyler * @brief Any simple BasicBlock optimization can be put here. 2614e97c539408f47145526f0062c1c06df99146a73Jean Christophe Beyler */ 2624f59668b3d51f63601ebe59dbd2b7e8a7c5bd093James C Scottclass BBOptimizations : public PassME { 2634e97c539408f47145526f0062c1c06df99146a73Jean Christophe Beyler public: 2644f59668b3d51f63601ebe59dbd2b7e8a7c5bd093James C Scott BBOptimizations() : PassME("BBOptimizations", kNoNodes, "5_post_bbo_cfg") { 2654e97c539408f47145526f0062c1c06df99146a73Jean Christophe Beyler } 2664e97c539408f47145526f0062c1c06df99146a73Jean Christophe Beyler 2674f59668b3d51f63601ebe59dbd2b7e8a7c5bd093James C Scott bool Gate(const PassDataHolder* data) const { 2684f59668b3d51f63601ebe59dbd2b7e8a7c5bd093James C Scott DCHECK(data != nullptr); 269eb1404a0b59c4a981af61852c94129507efc331aJean Christophe Beyler CompilationUnit* c_unit = down_cast<const PassMEDataHolder*>(data)->c_unit; 270eb1404a0b59c4a981af61852c94129507efc331aJean Christophe Beyler DCHECK(c_unit != nullptr); 271eb1404a0b59c4a981af61852c94129507efc331aJean Christophe Beyler return ((c_unit->disable_opt & (1 << kBBOpt)) == 0); 2724e97c539408f47145526f0062c1c06df99146a73Jean Christophe Beyler } 2734e97c539408f47145526f0062c1c06df99146a73Jean Christophe Beyler 274e1f65bcb957a65c6d45b319d968bc53a833f2c65Jean Christophe Beyler void Start(PassDataHolder* data) const; 2754e97c539408f47145526f0062c1c06df99146a73Jean Christophe Beyler}; 2764e97c539408f47145526f0062c1c06df99146a73Jean Christophe Beyler 2774e97c539408f47145526f0062c1c06df99146a73Jean Christophe Beyler} // namespace art 2784e97c539408f47145526f0062c1c06df99146a73Jean Christophe Beyler 2794e97c539408f47145526f0062c1c06df99146a73Jean Christophe Beyler#endif // ART_COMPILER_DEX_BB_OPTIMIZATIONS_H_ 280