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
20827eedbfa882496407375f22b08243a38a5bd53bNicolas Geoffray#include "nodes.h"
21827eedbfa882496407375f22b08243a38a5bd53bNicolas Geoffray#include "optimization.h"
22827eedbfa882496407375f22b08243a38a5bd53bNicolas Geoffray
23827eedbfa882496407375f22b08243a38a5bd53bNicolas Geoffraynamespace art {
24827eedbfa882496407375f22b08243a38a5bd53bNicolas Geoffray
25827eedbfa882496407375f22b08243a38a5bd53bNicolas Geoffrayclass SideEffectsAnalysis : public HOptimization {
26827eedbfa882496407375f22b08243a38a5bd53bNicolas Geoffray public:
27827eedbfa882496407375f22b08243a38a5bd53bNicolas Geoffray  explicit SideEffectsAnalysis(HGraph* graph)
287c3952f423b8213083d60596a5f0bf4237ca3f7bAndreas Gampe      : HOptimization(graph, true, kSideEffectsAnalysisPassName),
29827eedbfa882496407375f22b08243a38a5bd53bNicolas Geoffray        graph_(graph),
30827eedbfa882496407375f22b08243a38a5bd53bNicolas Geoffray        block_effects_(graph->GetArena(), graph->GetBlocks().Size(), SideEffects::None()),
31827eedbfa882496407375f22b08243a38a5bd53bNicolas Geoffray        loop_effects_(graph->GetArena(), graph->GetBlocks().Size(), SideEffects::None()) {}
32827eedbfa882496407375f22b08243a38a5bd53bNicolas Geoffray
33827eedbfa882496407375f22b08243a38a5bd53bNicolas Geoffray  SideEffects GetLoopEffects(HBasicBlock* block) const;
34827eedbfa882496407375f22b08243a38a5bd53bNicolas Geoffray  SideEffects GetBlockEffects(HBasicBlock* block) const;
35827eedbfa882496407375f22b08243a38a5bd53bNicolas Geoffray
36827eedbfa882496407375f22b08243a38a5bd53bNicolas Geoffray  // Compute side effects of individual blocks and loops.
37827eedbfa882496407375f22b08243a38a5bd53bNicolas Geoffray  void Run();
38827eedbfa882496407375f22b08243a38a5bd53bNicolas Geoffray
39827eedbfa882496407375f22b08243a38a5bd53bNicolas Geoffray  bool HasRun() const { return has_run_; }
40827eedbfa882496407375f22b08243a38a5bd53bNicolas Geoffray
417c3952f423b8213083d60596a5f0bf4237ca3f7bAndreas Gampe  static constexpr const char* kSideEffectsAnalysisPassName = "SideEffects";
427c3952f423b8213083d60596a5f0bf4237ca3f7bAndreas Gampe
43827eedbfa882496407375f22b08243a38a5bd53bNicolas Geoffray private:
44827eedbfa882496407375f22b08243a38a5bd53bNicolas Geoffray  void UpdateLoopEffects(HLoopInformation* info, SideEffects effects);
45827eedbfa882496407375f22b08243a38a5bd53bNicolas Geoffray
46827eedbfa882496407375f22b08243a38a5bd53bNicolas Geoffray  HGraph* graph_;
47827eedbfa882496407375f22b08243a38a5bd53bNicolas Geoffray
48827eedbfa882496407375f22b08243a38a5bd53bNicolas Geoffray  // Checked in debug build, to ensure the pass has been run prior to
49827eedbfa882496407375f22b08243a38a5bd53bNicolas Geoffray  // running a pass that depends on it.
50827eedbfa882496407375f22b08243a38a5bd53bNicolas Geoffray  bool has_run_ = false;
51827eedbfa882496407375f22b08243a38a5bd53bNicolas Geoffray
52827eedbfa882496407375f22b08243a38a5bd53bNicolas Geoffray  // Side effects of individual blocks, that is the union of the side effects
53827eedbfa882496407375f22b08243a38a5bd53bNicolas Geoffray  // of the instructions in the block.
54827eedbfa882496407375f22b08243a38a5bd53bNicolas Geoffray  GrowableArray<SideEffects> block_effects_;
55827eedbfa882496407375f22b08243a38a5bd53bNicolas Geoffray
56827eedbfa882496407375f22b08243a38a5bd53bNicolas Geoffray  // Side effects of loops, that is the union of the side effects of the
57827eedbfa882496407375f22b08243a38a5bd53bNicolas Geoffray  // blocks contained in that loop.
58827eedbfa882496407375f22b08243a38a5bd53bNicolas Geoffray  GrowableArray<SideEffects> loop_effects_;
59827eedbfa882496407375f22b08243a38a5bd53bNicolas Geoffray
60827eedbfa882496407375f22b08243a38a5bd53bNicolas Geoffray  ART_FRIEND_TEST(GVNTest, LoopSideEffects);
61827eedbfa882496407375f22b08243a38a5bd53bNicolas Geoffray  DISALLOW_COPY_AND_ASSIGN(SideEffectsAnalysis);
62827eedbfa882496407375f22b08243a38a5bd53bNicolas Geoffray};
63827eedbfa882496407375f22b08243a38a5bd53bNicolas Geoffray
64827eedbfa882496407375f22b08243a38a5bd53bNicolas Geoffray}  // namespace art
65827eedbfa882496407375f22b08243a38a5bd53bNicolas Geoffray
66827eedbfa882496407375f22b08243a38a5bd53bNicolas Geoffray#endif  // ART_COMPILER_OPTIMIZING_SIDE_EFFECTS_ANALYSIS_H_
67