blob: 415d10cd9d3c8ff0c1a5969068e17535b64ce9ef [file] [log] [blame]
Nicolas Geoffray827eedb2015-01-26 15:18:36 +00001/*
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 "nodes.h"
21#include "optimization.h"
22
23namespace art {
24
25class SideEffectsAnalysis : public HOptimization {
26 public:
27 explicit SideEffectsAnalysis(HGraph* graph)
Andreas Gampe7c3952f2015-02-19 18:21:24 -080028 : HOptimization(graph, true, kSideEffectsAnalysisPassName),
Nicolas Geoffray827eedb2015-01-26 15:18:36 +000029 graph_(graph),
30 block_effects_(graph->GetArena(), graph->GetBlocks().Size(), SideEffects::None()),
31 loop_effects_(graph->GetArena(), graph->GetBlocks().Size(), SideEffects::None()) {}
32
33 SideEffects GetLoopEffects(HBasicBlock* block) const;
34 SideEffects GetBlockEffects(HBasicBlock* block) const;
35
36 // Compute side effects of individual blocks and loops.
37 void Run();
38
39 bool HasRun() const { return has_run_; }
40
Andreas Gampe7c3952f2015-02-19 18:21:24 -080041 static constexpr const char* kSideEffectsAnalysisPassName = "SideEffects";
42
Nicolas Geoffray827eedb2015-01-26 15:18:36 +000043 private:
44 void UpdateLoopEffects(HLoopInformation* info, SideEffects effects);
45
46 HGraph* graph_;
47
48 // Checked in debug build, to ensure the pass has been run prior to
49 // running a pass that depends on it.
50 bool has_run_ = false;
51
52 // Side effects of individual blocks, that is the union of the side effects
53 // of the instructions in the block.
54 GrowableArray<SideEffects> block_effects_;
55
56 // Side effects of loops, that is the union of the side effects of the
57 // blocks contained in that loop.
58 GrowableArray<SideEffects> loop_effects_;
59
60 ART_FRIEND_TEST(GVNTest, LoopSideEffects);
61 DISALLOW_COPY_AND_ASSIGN(SideEffectsAnalysis);
62};
63
64} // namespace art
65
66#endif // ART_COMPILER_OPTIMIZING_SIDE_EFFECTS_ANALYSIS_H_