blob: fea47e66d9797ae40439f4dc9fd0199990103bbe [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
Vladimir Marko2aaa4b52015-09-17 17:03:26 +010020#include "base/arena_containers.h"
Nicolas Geoffray827eedb2015-01-26 15:18:36 +000021#include "nodes.h"
22#include "optimization.h"
23
24namespace art {
25
26class SideEffectsAnalysis : public HOptimization {
27 public:
Aart Bik92685a82017-03-06 11:13:43 -080028 SideEffectsAnalysis(HGraph* graph, const char* pass_name = kSideEffectsAnalysisPassName)
29 : HOptimization(graph, pass_name),
Nicolas Geoffray827eedb2015-01-26 15:18:36 +000030 graph_(graph),
Vladimir Marko2aaa4b52015-09-17 17:03:26 +010031 block_effects_(graph->GetBlocks().size(),
32 graph->GetArena()->Adapter(kArenaAllocSideEffectsAnalysis)),
33 loop_effects_(graph->GetBlocks().size(),
34 graph->GetArena()->Adapter(kArenaAllocSideEffectsAnalysis)) {}
Nicolas Geoffray827eedb2015-01-26 15:18:36 +000035
36 SideEffects GetLoopEffects(HBasicBlock* block) const;
37 SideEffects GetBlockEffects(HBasicBlock* block) const;
38
39 // Compute side effects of individual blocks and loops.
40 void Run();
41
42 bool HasRun() const { return has_run_; }
43
Aart Bik92685a82017-03-06 11:13:43 -080044 static constexpr const char* kSideEffectsAnalysisPassName = "side_effects";
Andreas Gampe7c3952f2015-02-19 18:21:24 -080045
Nicolas Geoffray827eedb2015-01-26 15:18:36 +000046 private:
47 void UpdateLoopEffects(HLoopInformation* info, SideEffects effects);
48
49 HGraph* graph_;
50
51 // Checked in debug build, to ensure the pass has been run prior to
52 // running a pass that depends on it.
53 bool has_run_ = false;
54
55 // Side effects of individual blocks, that is the union of the side effects
56 // of the instructions in the block.
Vladimir Marko2aaa4b52015-09-17 17:03:26 +010057 ArenaVector<SideEffects> block_effects_;
Nicolas Geoffray827eedb2015-01-26 15:18:36 +000058
59 // Side effects of loops, that is the union of the side effects of the
60 // blocks contained in that loop.
Vladimir Marko2aaa4b52015-09-17 17:03:26 +010061 ArenaVector<SideEffects> loop_effects_;
Nicolas Geoffray827eedb2015-01-26 15:18:36 +000062
63 ART_FRIEND_TEST(GVNTest, LoopSideEffects);
64 DISALLOW_COPY_AND_ASSIGN(SideEffectsAnalysis);
65};
66
67} // namespace art
68
69#endif // ART_COMPILER_OPTIMIZING_SIDE_EFFECTS_ANALYSIS_H_