1827eedbfa882496407375f22b08243a38a5bd53bNicolas Geoffray/* 2827eedbfa882496407375f22b08243a38a5bd53bNicolas Geoffray * Copyright (C) 2014 The Android Open Source Project 3827eedbfa882496407375f22b08243a38a5bd53bNicolas Geoffray * 4827eedbfa882496407375f22b08243a38a5bd53bNicolas Geoffray * Licensed under the Apache License, Version 2.0 (the "License"); 5827eedbfa882496407375f22b08243a38a5bd53bNicolas Geoffray * you may not use this file except in compliance with the License. 6827eedbfa882496407375f22b08243a38a5bd53bNicolas Geoffray * You may obtain a copy of the License at 7827eedbfa882496407375f22b08243a38a5bd53bNicolas Geoffray * 8827eedbfa882496407375f22b08243a38a5bd53bNicolas Geoffray * http://www.apache.org/licenses/LICENSE-2.0 9827eedbfa882496407375f22b08243a38a5bd53bNicolas Geoffray * 10827eedbfa882496407375f22b08243a38a5bd53bNicolas Geoffray * Unless required by applicable law or agreed to in writing, software 11827eedbfa882496407375f22b08243a38a5bd53bNicolas Geoffray * distributed under the License is distributed on an "AS IS" BASIS, 12827eedbfa882496407375f22b08243a38a5bd53bNicolas Geoffray * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13827eedbfa882496407375f22b08243a38a5bd53bNicolas Geoffray * See the License for the specific language governing permissions and 14827eedbfa882496407375f22b08243a38a5bd53bNicolas Geoffray * limitations under the License. 15827eedbfa882496407375f22b08243a38a5bd53bNicolas Geoffray */ 16827eedbfa882496407375f22b08243a38a5bd53bNicolas Geoffray 17827eedbfa882496407375f22b08243a38a5bd53bNicolas Geoffray#ifndef ART_COMPILER_OPTIMIZING_SIDE_EFFECTS_ANALYSIS_H_ 18827eedbfa882496407375f22b08243a38a5bd53bNicolas Geoffray#define ART_COMPILER_OPTIMIZING_SIDE_EFFECTS_ANALYSIS_H_ 19827eedbfa882496407375f22b08243a38a5bd53bNicolas Geoffray 202aaa4b5532d30c4e65d8892b556400bb61f9dc8cVladimir Marko#include "base/arena_containers.h" 21827eedbfa882496407375f22b08243a38a5bd53bNicolas Geoffray#include "nodes.h" 22827eedbfa882496407375f22b08243a38a5bd53bNicolas Geoffray#include "optimization.h" 23827eedbfa882496407375f22b08243a38a5bd53bNicolas Geoffray 24827eedbfa882496407375f22b08243a38a5bd53bNicolas Geoffraynamespace art { 25827eedbfa882496407375f22b08243a38a5bd53bNicolas Geoffray 26827eedbfa882496407375f22b08243a38a5bd53bNicolas Geoffrayclass SideEffectsAnalysis : public HOptimization { 27827eedbfa882496407375f22b08243a38a5bd53bNicolas Geoffray public: 28827eedbfa882496407375f22b08243a38a5bd53bNicolas Geoffray explicit SideEffectsAnalysis(HGraph* graph) 2969ba7b7112c2277ac225615b37e6df74c055740dDavid Brazdil : HOptimization(graph, kSideEffectsAnalysisPassName), 30827eedbfa882496407375f22b08243a38a5bd53bNicolas Geoffray graph_(graph), 312aaa4b5532d30c4e65d8892b556400bb61f9dc8cVladimir Marko block_effects_(graph->GetBlocks().size(), 322aaa4b5532d30c4e65d8892b556400bb61f9dc8cVladimir Marko graph->GetArena()->Adapter(kArenaAllocSideEffectsAnalysis)), 332aaa4b5532d30c4e65d8892b556400bb61f9dc8cVladimir Marko loop_effects_(graph->GetBlocks().size(), 342aaa4b5532d30c4e65d8892b556400bb61f9dc8cVladimir Marko graph->GetArena()->Adapter(kArenaAllocSideEffectsAnalysis)) {} 35827eedbfa882496407375f22b08243a38a5bd53bNicolas Geoffray 36827eedbfa882496407375f22b08243a38a5bd53bNicolas Geoffray SideEffects GetLoopEffects(HBasicBlock* block) const; 37827eedbfa882496407375f22b08243a38a5bd53bNicolas Geoffray SideEffects GetBlockEffects(HBasicBlock* block) const; 38827eedbfa882496407375f22b08243a38a5bd53bNicolas Geoffray 39827eedbfa882496407375f22b08243a38a5bd53bNicolas Geoffray // Compute side effects of individual blocks and loops. 40827eedbfa882496407375f22b08243a38a5bd53bNicolas Geoffray void Run(); 41827eedbfa882496407375f22b08243a38a5bd53bNicolas Geoffray 42827eedbfa882496407375f22b08243a38a5bd53bNicolas Geoffray bool HasRun() const { return has_run_; } 43827eedbfa882496407375f22b08243a38a5bd53bNicolas Geoffray 447c3952f423b8213083d60596a5f0bf4237ca3f7bAndreas Gampe static constexpr const char* kSideEffectsAnalysisPassName = "SideEffects"; 457c3952f423b8213083d60596a5f0bf4237ca3f7bAndreas Gampe 46827eedbfa882496407375f22b08243a38a5bd53bNicolas Geoffray private: 47827eedbfa882496407375f22b08243a38a5bd53bNicolas Geoffray void UpdateLoopEffects(HLoopInformation* info, SideEffects effects); 48827eedbfa882496407375f22b08243a38a5bd53bNicolas Geoffray 49827eedbfa882496407375f22b08243a38a5bd53bNicolas Geoffray HGraph* graph_; 50827eedbfa882496407375f22b08243a38a5bd53bNicolas Geoffray 51827eedbfa882496407375f22b08243a38a5bd53bNicolas Geoffray // Checked in debug build, to ensure the pass has been run prior to 52827eedbfa882496407375f22b08243a38a5bd53bNicolas Geoffray // running a pass that depends on it. 53827eedbfa882496407375f22b08243a38a5bd53bNicolas Geoffray bool has_run_ = false; 54827eedbfa882496407375f22b08243a38a5bd53bNicolas Geoffray 55827eedbfa882496407375f22b08243a38a5bd53bNicolas Geoffray // Side effects of individual blocks, that is the union of the side effects 56827eedbfa882496407375f22b08243a38a5bd53bNicolas Geoffray // of the instructions in the block. 572aaa4b5532d30c4e65d8892b556400bb61f9dc8cVladimir Marko ArenaVector<SideEffects> block_effects_; 58827eedbfa882496407375f22b08243a38a5bd53bNicolas Geoffray 59827eedbfa882496407375f22b08243a38a5bd53bNicolas Geoffray // Side effects of loops, that is the union of the side effects of the 60827eedbfa882496407375f22b08243a38a5bd53bNicolas Geoffray // blocks contained in that loop. 612aaa4b5532d30c4e65d8892b556400bb61f9dc8cVladimir Marko ArenaVector<SideEffects> loop_effects_; 62827eedbfa882496407375f22b08243a38a5bd53bNicolas Geoffray 63827eedbfa882496407375f22b08243a38a5bd53bNicolas Geoffray ART_FRIEND_TEST(GVNTest, LoopSideEffects); 64827eedbfa882496407375f22b08243a38a5bd53bNicolas Geoffray DISALLOW_COPY_AND_ASSIGN(SideEffectsAnalysis); 65827eedbfa882496407375f22b08243a38a5bd53bNicolas Geoffray}; 66827eedbfa882496407375f22b08243a38a5bd53bNicolas Geoffray 67827eedbfa882496407375f22b08243a38a5bd53bNicolas Geoffray} // namespace art 68827eedbfa882496407375f22b08243a38a5bd53bNicolas Geoffray 69827eedbfa882496407375f22b08243a38a5bd53bNicolas Geoffray#endif // ART_COMPILER_OPTIMIZING_SIDE_EFFECTS_ANALYSIS_H_ 70