blob: 6d500a56ec45f8db0a79167c24f66f11ab556c42 [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/**
Vladimir Marko9820b7c2014-01-02 16:40:37 +000062 * @class CallInlining
63 * @brief Perform method inlining pass.
64 */
65class CallInlining : public Pass {
66 public:
67 CallInlining() : Pass("CallInlining") {
68 }
69
70 bool Gate(const CompilationUnit* cUnit) const {
71 return cUnit->mir_graph->InlineCallsGate();
72 }
73
74 void Start(CompilationUnit* cUnit) const {
75 cUnit->mir_graph->InlineCallsStart();
76 }
77
78 bool WalkBasicBlocks(CompilationUnit* cUnit, BasicBlock* bb) const {
79 cUnit->mir_graph->InlineCalls(bb);
80 // No need of repeating, so just return false.
81 return false;
82 }
83
84 void End(CompilationUnit* cUnit) const {
85 cUnit->mir_graph->InlineCallsEnd();
86 }
87};
88
89/**
Jean Christophe Beyler4e97c532014-01-07 10:07:18 -080090 * @class CodeLayout
91 * @brief Perform the code layout pass.
92 */
93class CodeLayout : public Pass {
94 public:
Vladimir Marko75ba13f2014-01-28 12:15:24 +000095 CodeLayout() : Pass("CodeLayout", "2_post_layout_cfg") {
Jean Christophe Beyler4e97c532014-01-07 10:07:18 -080096 }
97
Vladimir Marko75ba13f2014-01-28 12:15:24 +000098 void Start(CompilationUnit* cUnit) const {
Jean Christophe Beyler4e97c532014-01-07 10:07:18 -080099 cUnit->mir_graph->VerifyDataflow();
100 }
101
Vladimir Marko75ba13f2014-01-28 12:15:24 +0000102 bool WalkBasicBlocks(CompilationUnit* cUnit, BasicBlock* bb) const;
Jean Christophe Beyler4e97c532014-01-07 10:07:18 -0800103};
104
105/**
106 * @class SSATransformation
107 * @brief Perform an SSA representation pass on the CompilationUnit.
108 */
109class SSATransformation : public Pass {
110 public:
Vladimir Marko75ba13f2014-01-28 12:15:24 +0000111 SSATransformation() : Pass("SSATransformation", kPreOrderDFSTraversal, "3_post_ssa_cfg") {
Jean Christophe Beyler4e97c532014-01-07 10:07:18 -0800112 }
113
Vladimir Marko75ba13f2014-01-28 12:15:24 +0000114 bool WalkBasicBlocks(CompilationUnit* cUnit, BasicBlock* bb) const;
Jean Christophe Beyler4e97c532014-01-07 10:07:18 -0800115
Vladimir Marko75ba13f2014-01-28 12:15:24 +0000116 void Start(CompilationUnit* cUnit) const {
Jean Christophe Beyler4e97c532014-01-07 10:07:18 -0800117 cUnit->mir_graph->InitializeSSATransformation();
118 }
119
Vladimir Marko75ba13f2014-01-28 12:15:24 +0000120 void End(CompilationUnit* cUnit) const;
Jean Christophe Beyler4e97c532014-01-07 10:07:18 -0800121};
122
123/**
124 * @class ConstantPropagation
125 * @brief Perform a constant propagation pass.
126 */
127class ConstantPropagation : public Pass {
128 public:
Vladimir Marko75ba13f2014-01-28 12:15:24 +0000129 ConstantPropagation() : Pass("ConstantPropagation") {
Jean Christophe Beyler4e97c532014-01-07 10:07:18 -0800130 }
131
Vladimir Marko75ba13f2014-01-28 12:15:24 +0000132 bool WalkBasicBlocks(CompilationUnit* cUnit, BasicBlock* bb) const;
Jean Christophe Beyler4e97c532014-01-07 10:07:18 -0800133
Vladimir Marko75ba13f2014-01-28 12:15:24 +0000134 void Start(CompilationUnit* cUnit) const {
Jean Christophe Beyler4e97c532014-01-07 10:07:18 -0800135 cUnit->mir_graph->InitializeConstantPropagation();
136 }
137};
138
139/**
140 * @class InitRegLocations
141 * @brief Initialize Register Locations.
142 */
143class InitRegLocations : public Pass {
144 public:
Vladimir Marko75ba13f2014-01-28 12:15:24 +0000145 InitRegLocations() : Pass("InitRegLocation", kNoNodes) {
Jean Christophe Beyler4e97c532014-01-07 10:07:18 -0800146 }
147
Vladimir Marko75ba13f2014-01-28 12:15:24 +0000148 void Start(CompilationUnit* cUnit) const {
Jean Christophe Beyler4e97c532014-01-07 10:07:18 -0800149 cUnit->mir_graph->InitRegLocations();
150 }
151};
152
153/**
154 * @class MethodUseCount
155 * @brief Count the register uses of the method
156 */
157class MethodUseCount : public Pass {
158 public:
Vladimir Marko75ba13f2014-01-28 12:15:24 +0000159 MethodUseCount() : Pass("UseCount") {
Jean Christophe Beyler4e97c532014-01-07 10:07:18 -0800160 }
161
Vladimir Marko75ba13f2014-01-28 12:15:24 +0000162 bool WalkBasicBlocks(CompilationUnit* cUnit, BasicBlock* bb) const;
Jean Christophe Beyler4e97c532014-01-07 10:07:18 -0800163
Vladimir Marko75ba13f2014-01-28 12:15:24 +0000164 bool Gate(const CompilationUnit* cUnit) const;
Jean Christophe Beyler4e97c532014-01-07 10:07:18 -0800165};
166
167/**
Jean Christophe Beyler4e97c532014-01-07 10:07:18 -0800168 * @class NullCheckEliminationAndTypeInference
169 * @brief Null check elimination and type inference.
170 */
171class NullCheckEliminationAndTypeInference : public Pass {
172 public:
Vladimir Marko75ba13f2014-01-28 12:15:24 +0000173 NullCheckEliminationAndTypeInference()
174 : Pass("NCE_TypeInference", kRepeatingPreOrderDFSTraversal, "4_post_nce_cfg") {
Jean Christophe Beyler4e97c532014-01-07 10:07:18 -0800175 }
176
Vladimir Markobfea9c22014-01-17 17:49:33 +0000177 void Start(CompilationUnit* cUnit) const {
178 cUnit->mir_graph->EliminateNullChecksAndInferTypesStart();
179 }
180
Vladimir Marko75ba13f2014-01-28 12:15:24 +0000181 bool WalkBasicBlocks(CompilationUnit* cUnit, BasicBlock* bb) const {
Jean Christophe Beyler4e97c532014-01-07 10:07:18 -0800182 return cUnit->mir_graph->EliminateNullChecksAndInferTypes(bb);
183 }
Vladimir Markobfea9c22014-01-17 17:49:33 +0000184
185 void End(CompilationUnit* cUnit) const {
186 cUnit->mir_graph->EliminateNullChecksAndInferTypesEnd();
187 }
188};
189
190class ClassInitCheckElimination : public Pass {
191 public:
192 ClassInitCheckElimination() : Pass("ClInitCheckElimination", kRepeatingPreOrderDFSTraversal) {
193 }
194
195 bool Gate(const CompilationUnit* cUnit) const {
196 return cUnit->mir_graph->EliminateClassInitChecksGate();
197 }
198
199 bool WalkBasicBlocks(CompilationUnit* cUnit, BasicBlock* bb) const {
200 return cUnit->mir_graph->EliminateClassInitChecks(bb);
201 }
202
203 void End(CompilationUnit* cUnit) const {
204 cUnit->mir_graph->EliminateClassInitChecksEnd();
205 }
Jean Christophe Beyler4e97c532014-01-07 10:07:18 -0800206};
207
208/**
209 * @class NullCheckEliminationAndTypeInference
210 * @brief Null check elimination and type inference.
211 */
212class BBCombine : public Pass {
213 public:
Vladimir Marko75ba13f2014-01-28 12:15:24 +0000214 BBCombine() : Pass("BBCombine", kPreOrderDFSTraversal, "5_post_bbcombine_cfg") {
Jean Christophe Beyler4e97c532014-01-07 10:07:18 -0800215 }
216
Vladimir Marko75ba13f2014-01-28 12:15:24 +0000217 bool Gate(const CompilationUnit* cUnit) const {
Jean Christophe Beyler4e97c532014-01-07 10:07:18 -0800218 return ((cUnit->disable_opt & (1 << kSuppressExceptionEdges)) != 0);
219 }
220
Vladimir Marko75ba13f2014-01-28 12:15:24 +0000221 bool WalkBasicBlocks(CompilationUnit* cUnit, BasicBlock* bb) const;
Jean Christophe Beyler4e97c532014-01-07 10:07:18 -0800222};
223
224/**
225 * @class BasicBlock Optimizations
226 * @brief Any simple BasicBlock optimization can be put here.
227 */
228class BBOptimizations : public Pass {
229 public:
Vladimir Marko75ba13f2014-01-28 12:15:24 +0000230 BBOptimizations() : Pass("BBOptimizations", kNoNodes, "5_post_bbo_cfg") {
Jean Christophe Beyler4e97c532014-01-07 10:07:18 -0800231 }
232
Vladimir Marko75ba13f2014-01-28 12:15:24 +0000233 bool Gate(const CompilationUnit* cUnit) const {
Jean Christophe Beyler4e97c532014-01-07 10:07:18 -0800234 return ((cUnit->disable_opt & (1 << kBBOpt)) == 0);
235 }
236
Vladimir Marko75ba13f2014-01-28 12:15:24 +0000237 void Start(CompilationUnit* cUnit) const;
Jean Christophe Beyler4e97c532014-01-07 10:07:18 -0800238};
239
240} // namespace art
241
242#endif // ART_COMPILER_DEX_BB_OPTIMIZATIONS_H_