blob: fb482bf683c622018067f2a2180eb3a527df7fbc [file] [log] [blame]
Jean Christophe Beyler4e97c532014-01-07 10:07:18 -08001/*
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_DEX_BB_OPTIMIZATIONS_H_
18#define ART_COMPILER_DEX_BB_OPTIMIZATIONS_H_
19
20#include "compiler_internals.h"
21#include "pass.h"
22
23namespace art {
24
25/**
Vladimir Markobe0e5462014-02-26 11:24:15 +000026 * @class CacheFieldLoweringInfo
27 * @brief Cache the lowering info for fields used by IGET/IPUT/SGET/SPUT insns.
28 */
29class CacheFieldLoweringInfo : public Pass {
30 public:
31 CacheFieldLoweringInfo() : Pass("CacheFieldLoweringInfo", kNoNodes) {
32 }
33
34 void Start(CompilationUnit* cUnit) const {
35 cUnit->mir_graph->DoCacheFieldLoweringInfo();
36 }
Vladimir Marko3d73ba22014-03-06 15:18:04 +000037
38 bool Gate(const CompilationUnit *cUnit) const {
39 return cUnit->mir_graph->HasFieldAccess();
40 }
Vladimir Markobe0e5462014-02-26 11:24:15 +000041};
42
43/**
Vladimir Markof096aad2014-01-23 15:51:58 +000044 * @class CacheMethodLoweringInfo
45 * @brief Cache the lowering info for methods called by INVOKEs.
46 */
47class CacheMethodLoweringInfo : public Pass {
48 public:
49 CacheMethodLoweringInfo() : Pass("CacheMethodLoweringInfo", kNoNodes) {
50 }
51
52 void Start(CompilationUnit* cUnit) const {
53 cUnit->mir_graph->DoCacheMethodLoweringInfo();
54 }
Vladimir Marko3d73ba22014-03-06 15:18:04 +000055
56 bool Gate(const CompilationUnit *cUnit) const {
57 return cUnit->mir_graph->HasInvokes();
58 }
Vladimir Markof096aad2014-01-23 15:51:58 +000059};
60
61/**
Jean Christophe Beyler4e97c532014-01-07 10:07:18 -080062 * @class CodeLayout
63 * @brief Perform the code layout pass.
64 */
65class CodeLayout : public Pass {
66 public:
Vladimir Marko75ba13f2014-01-28 12:15:24 +000067 CodeLayout() : Pass("CodeLayout", "2_post_layout_cfg") {
Jean Christophe Beyler4e97c532014-01-07 10:07:18 -080068 }
69
Vladimir Marko75ba13f2014-01-28 12:15:24 +000070 void Start(CompilationUnit* cUnit) const {
Jean Christophe Beyler4e97c532014-01-07 10:07:18 -080071 cUnit->mir_graph->VerifyDataflow();
72 }
73
Vladimir Marko75ba13f2014-01-28 12:15:24 +000074 bool WalkBasicBlocks(CompilationUnit* cUnit, BasicBlock* bb) const;
Jean Christophe Beyler4e97c532014-01-07 10:07:18 -080075};
76
77/**
78 * @class SSATransformation
79 * @brief Perform an SSA representation pass on the CompilationUnit.
80 */
81class SSATransformation : public Pass {
82 public:
Vladimir Marko75ba13f2014-01-28 12:15:24 +000083 SSATransformation() : Pass("SSATransformation", kPreOrderDFSTraversal, "3_post_ssa_cfg") {
Jean Christophe Beyler4e97c532014-01-07 10:07:18 -080084 }
85
Vladimir Marko75ba13f2014-01-28 12:15:24 +000086 bool WalkBasicBlocks(CompilationUnit* cUnit, BasicBlock* bb) const;
Jean Christophe Beyler4e97c532014-01-07 10:07:18 -080087
Vladimir Marko75ba13f2014-01-28 12:15:24 +000088 void Start(CompilationUnit* cUnit) const {
Jean Christophe Beyler4e97c532014-01-07 10:07:18 -080089 cUnit->mir_graph->InitializeSSATransformation();
90 }
91
Vladimir Marko75ba13f2014-01-28 12:15:24 +000092 void End(CompilationUnit* cUnit) const;
Jean Christophe Beyler4e97c532014-01-07 10:07:18 -080093};
94
95/**
96 * @class ConstantPropagation
97 * @brief Perform a constant propagation pass.
98 */
99class ConstantPropagation : public Pass {
100 public:
Vladimir Marko75ba13f2014-01-28 12:15:24 +0000101 ConstantPropagation() : Pass("ConstantPropagation") {
Jean Christophe Beyler4e97c532014-01-07 10:07:18 -0800102 }
103
Vladimir Marko75ba13f2014-01-28 12:15:24 +0000104 bool WalkBasicBlocks(CompilationUnit* cUnit, BasicBlock* bb) const;
Jean Christophe Beyler4e97c532014-01-07 10:07:18 -0800105
Vladimir Marko75ba13f2014-01-28 12:15:24 +0000106 void Start(CompilationUnit* cUnit) const {
Jean Christophe Beyler4e97c532014-01-07 10:07:18 -0800107 cUnit->mir_graph->InitializeConstantPropagation();
108 }
109};
110
111/**
112 * @class InitRegLocations
113 * @brief Initialize Register Locations.
114 */
115class InitRegLocations : public Pass {
116 public:
Vladimir Marko75ba13f2014-01-28 12:15:24 +0000117 InitRegLocations() : Pass("InitRegLocation", kNoNodes) {
Jean Christophe Beyler4e97c532014-01-07 10:07:18 -0800118 }
119
Vladimir Marko75ba13f2014-01-28 12:15:24 +0000120 void Start(CompilationUnit* cUnit) const {
Jean Christophe Beyler4e97c532014-01-07 10:07:18 -0800121 cUnit->mir_graph->InitRegLocations();
122 }
123};
124
125/**
126 * @class MethodUseCount
127 * @brief Count the register uses of the method
128 */
129class MethodUseCount : public Pass {
130 public:
Vladimir Marko75ba13f2014-01-28 12:15:24 +0000131 MethodUseCount() : Pass("UseCount") {
Jean Christophe Beyler4e97c532014-01-07 10:07:18 -0800132 }
133
Vladimir Marko75ba13f2014-01-28 12:15:24 +0000134 bool WalkBasicBlocks(CompilationUnit* cUnit, BasicBlock* bb) const;
Jean Christophe Beyler4e97c532014-01-07 10:07:18 -0800135
Vladimir Marko75ba13f2014-01-28 12:15:24 +0000136 bool Gate(const CompilationUnit* cUnit) const;
Jean Christophe Beyler4e97c532014-01-07 10:07:18 -0800137};
138
139/**
Jean Christophe Beyler4e97c532014-01-07 10:07:18 -0800140 * @class NullCheckEliminationAndTypeInference
141 * @brief Null check elimination and type inference.
142 */
143class NullCheckEliminationAndTypeInference : public Pass {
144 public:
Vladimir Marko75ba13f2014-01-28 12:15:24 +0000145 NullCheckEliminationAndTypeInference()
146 : Pass("NCE_TypeInference", kRepeatingPreOrderDFSTraversal, "4_post_nce_cfg") {
Jean Christophe Beyler4e97c532014-01-07 10:07:18 -0800147 }
148
Vladimir Markobfea9c22014-01-17 17:49:33 +0000149 void Start(CompilationUnit* cUnit) const {
150 cUnit->mir_graph->EliminateNullChecksAndInferTypesStart();
151 }
152
Vladimir Marko75ba13f2014-01-28 12:15:24 +0000153 bool WalkBasicBlocks(CompilationUnit* cUnit, BasicBlock* bb) const {
Jean Christophe Beyler4e97c532014-01-07 10:07:18 -0800154 return cUnit->mir_graph->EliminateNullChecksAndInferTypes(bb);
155 }
Vladimir Markobfea9c22014-01-17 17:49:33 +0000156
157 void End(CompilationUnit* cUnit) const {
158 cUnit->mir_graph->EliminateNullChecksAndInferTypesEnd();
159 }
160};
161
162class ClassInitCheckElimination : public Pass {
163 public:
164 ClassInitCheckElimination() : Pass("ClInitCheckElimination", kRepeatingPreOrderDFSTraversal) {
165 }
166
167 bool Gate(const CompilationUnit* cUnit) const {
168 return cUnit->mir_graph->EliminateClassInitChecksGate();
169 }
170
171 bool WalkBasicBlocks(CompilationUnit* cUnit, BasicBlock* bb) const {
172 return cUnit->mir_graph->EliminateClassInitChecks(bb);
173 }
174
175 void End(CompilationUnit* cUnit) const {
176 cUnit->mir_graph->EliminateClassInitChecksEnd();
177 }
Jean Christophe Beyler4e97c532014-01-07 10:07:18 -0800178};
179
180/**
181 * @class NullCheckEliminationAndTypeInference
182 * @brief Null check elimination and type inference.
183 */
184class BBCombine : public Pass {
185 public:
Vladimir Marko75ba13f2014-01-28 12:15:24 +0000186 BBCombine() : Pass("BBCombine", kPreOrderDFSTraversal, "5_post_bbcombine_cfg") {
Jean Christophe Beyler4e97c532014-01-07 10:07:18 -0800187 }
188
Vladimir Marko75ba13f2014-01-28 12:15:24 +0000189 bool Gate(const CompilationUnit* cUnit) const {
Jean Christophe Beyler4e97c532014-01-07 10:07:18 -0800190 return ((cUnit->disable_opt & (1 << kSuppressExceptionEdges)) != 0);
191 }
192
Vladimir Marko75ba13f2014-01-28 12:15:24 +0000193 bool WalkBasicBlocks(CompilationUnit* cUnit, BasicBlock* bb) const;
Jean Christophe Beyler4e97c532014-01-07 10:07:18 -0800194};
195
196/**
197 * @class BasicBlock Optimizations
198 * @brief Any simple BasicBlock optimization can be put here.
199 */
200class BBOptimizations : public Pass {
201 public:
Vladimir Marko75ba13f2014-01-28 12:15:24 +0000202 BBOptimizations() : Pass("BBOptimizations", kNoNodes, "5_post_bbo_cfg") {
Jean Christophe Beyler4e97c532014-01-07 10:07:18 -0800203 }
204
Vladimir Marko75ba13f2014-01-28 12:15:24 +0000205 bool Gate(const CompilationUnit* cUnit) const {
Jean Christophe Beyler4e97c532014-01-07 10:07:18 -0800206 return ((cUnit->disable_opt & (1 << kBBOpt)) == 0);
207 }
208
Vladimir Marko75ba13f2014-01-28 12:15:24 +0000209 void Start(CompilationUnit* cUnit) const;
Jean Christophe Beyler4e97c532014-01-07 10:07:18 -0800210};
211
212} // namespace art
213
214#endif // ART_COMPILER_DEX_BB_OPTIMIZATIONS_H_