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_SIDE_EFFECTS_ANALYSIS_H_
18 #define ART_COMPILER_OPTIMIZING_SIDE_EFFECTS_ANALYSIS_H_
19 
20 #include "base/arena_containers.h"
21 #include "base/macros.h"
22 #include "nodes.h"
23 #include "optimization.h"
24 
25 namespace art HIDDEN {
26 
27 class SideEffectsAnalysis : public HOptimization {
28  public:
29   explicit SideEffectsAnalysis(HGraph* graph, const char* pass_name = kSideEffectsAnalysisPassName)
HOptimization(graph,pass_name)30       : HOptimization(graph, pass_name),
31         graph_(graph),
32         block_effects_(graph->GetAllocator()->Adapter(kArenaAllocSideEffectsAnalysis)),
33         loop_effects_(graph->GetAllocator()->Adapter(kArenaAllocSideEffectsAnalysis)) {}
34 
35   SideEffects GetLoopEffects(HBasicBlock* block) const;
36   SideEffects GetBlockEffects(HBasicBlock* block) const;
37 
38   // Compute side effects of individual blocks and loops.
39   bool Run();
40 
HasRun()41   bool HasRun() const { return has_run_; }
42 
43   static constexpr const char* kSideEffectsAnalysisPassName = "side_effects";
44 
45  private:
46   void UpdateLoopEffects(HLoopInformation* info, SideEffects effects);
47 
48   HGraph* graph_;
49 
50   // Checked in debug build, to ensure the pass has been run prior to
51   // running a pass that depends on it.
52   bool has_run_ = false;
53 
54   // Side effects of individual blocks, that is the union of the side effects
55   // of the instructions in the block.
56   ArenaVector<SideEffects> block_effects_;
57 
58   // Side effects of loops, that is the union of the side effects of the
59   // blocks contained in that loop.
60   ArenaVector<SideEffects> loop_effects_;
61 
62   ART_FRIEND_TEST(GVNTest, LoopSideEffects);
63   DISALLOW_COPY_AND_ASSIGN(SideEffectsAnalysis);
64 };
65 
66 }  // namespace art
67 
68 #endif  // ART_COMPILER_OPTIMIZING_SIDE_EFFECTS_ANALYSIS_H_
69