blob: 1a90ca849f198b5d60d509dd72c5e473ec3af377 [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 }
37};
38
39/**
Vladimir Markof096aad2014-01-23 15:51:58 +000040 * @class CacheMethodLoweringInfo
41 * @brief Cache the lowering info for methods called by INVOKEs.
42 */
43class CacheMethodLoweringInfo : public Pass {
44 public:
45 CacheMethodLoweringInfo() : Pass("CacheMethodLoweringInfo", kNoNodes) {
46 }
47
48 void Start(CompilationUnit* cUnit) const {
49 cUnit->mir_graph->DoCacheMethodLoweringInfo();
50 }
51};
52
53/**
Jean Christophe Beyler4e97c532014-01-07 10:07:18 -080054 * @class CodeLayout
55 * @brief Perform the code layout pass.
56 */
57class CodeLayout : public Pass {
58 public:
Vladimir Marko75ba13f2014-01-28 12:15:24 +000059 CodeLayout() : Pass("CodeLayout", "2_post_layout_cfg") {
Jean Christophe Beyler4e97c532014-01-07 10:07:18 -080060 }
61
Vladimir Marko75ba13f2014-01-28 12:15:24 +000062 void Start(CompilationUnit* cUnit) const {
Jean Christophe Beyler4e97c532014-01-07 10:07:18 -080063 cUnit->mir_graph->VerifyDataflow();
64 }
65
Vladimir Marko75ba13f2014-01-28 12:15:24 +000066 bool WalkBasicBlocks(CompilationUnit* cUnit, BasicBlock* bb) const;
Jean Christophe Beyler4e97c532014-01-07 10:07:18 -080067};
68
69/**
70 * @class SSATransformation
71 * @brief Perform an SSA representation pass on the CompilationUnit.
72 */
73class SSATransformation : public Pass {
74 public:
Vladimir Marko75ba13f2014-01-28 12:15:24 +000075 SSATransformation() : Pass("SSATransformation", kPreOrderDFSTraversal, "3_post_ssa_cfg") {
Jean Christophe Beyler4e97c532014-01-07 10:07:18 -080076 }
77
Vladimir Marko75ba13f2014-01-28 12:15:24 +000078 bool WalkBasicBlocks(CompilationUnit* cUnit, BasicBlock* bb) const;
Jean Christophe Beyler4e97c532014-01-07 10:07:18 -080079
Vladimir Marko75ba13f2014-01-28 12:15:24 +000080 void Start(CompilationUnit* cUnit) const {
Jean Christophe Beyler4e97c532014-01-07 10:07:18 -080081 cUnit->mir_graph->InitializeSSATransformation();
82 }
83
Vladimir Marko75ba13f2014-01-28 12:15:24 +000084 void End(CompilationUnit* cUnit) const;
Jean Christophe Beyler4e97c532014-01-07 10:07:18 -080085};
86
87/**
88 * @class ConstantPropagation
89 * @brief Perform a constant propagation pass.
90 */
91class ConstantPropagation : public Pass {
92 public:
Vladimir Marko75ba13f2014-01-28 12:15:24 +000093 ConstantPropagation() : Pass("ConstantPropagation") {
Jean Christophe Beyler4e97c532014-01-07 10:07:18 -080094 }
95
Vladimir Marko75ba13f2014-01-28 12:15:24 +000096 bool WalkBasicBlocks(CompilationUnit* cUnit, BasicBlock* bb) const;
Jean Christophe Beyler4e97c532014-01-07 10:07:18 -080097
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->InitializeConstantPropagation();
100 }
101};
102
103/**
104 * @class InitRegLocations
105 * @brief Initialize Register Locations.
106 */
107class InitRegLocations : public Pass {
108 public:
Vladimir Marko75ba13f2014-01-28 12:15:24 +0000109 InitRegLocations() : Pass("InitRegLocation", kNoNodes) {
Jean Christophe Beyler4e97c532014-01-07 10:07:18 -0800110 }
111
Vladimir Marko75ba13f2014-01-28 12:15:24 +0000112 void Start(CompilationUnit* cUnit) const {
Jean Christophe Beyler4e97c532014-01-07 10:07:18 -0800113 cUnit->mir_graph->InitRegLocations();
114 }
115};
116
117/**
118 * @class MethodUseCount
119 * @brief Count the register uses of the method
120 */
121class MethodUseCount : public Pass {
122 public:
Vladimir Marko75ba13f2014-01-28 12:15:24 +0000123 MethodUseCount() : Pass("UseCount") {
Jean Christophe Beyler4e97c532014-01-07 10:07:18 -0800124 }
125
Vladimir Marko75ba13f2014-01-28 12:15:24 +0000126 bool WalkBasicBlocks(CompilationUnit* cUnit, BasicBlock* bb) const;
Jean Christophe Beyler4e97c532014-01-07 10:07:18 -0800127
Vladimir Marko75ba13f2014-01-28 12:15:24 +0000128 bool Gate(const CompilationUnit* cUnit) const;
Jean Christophe Beyler4e97c532014-01-07 10:07:18 -0800129};
130
131/**
132 * @class NullCheckEliminationAndTypeInferenceInit
133 * @brief Null check elimination and type inference initialization step.
134 */
135class NullCheckEliminationAndTypeInferenceInit : public Pass {
136 public:
Vladimir Marko75ba13f2014-01-28 12:15:24 +0000137 NullCheckEliminationAndTypeInferenceInit() : Pass("NCE_TypeInferenceInit") {
Jean Christophe Beyler4e97c532014-01-07 10:07:18 -0800138 }
139
Vladimir Marko75ba13f2014-01-28 12:15:24 +0000140 bool WalkBasicBlocks(CompilationUnit* cUnit, BasicBlock* bb) const;
Jean Christophe Beyler4e97c532014-01-07 10:07:18 -0800141
Vladimir Marko75ba13f2014-01-28 12:15:24 +0000142 bool Gate(const CompilationUnit* cUnit) const;
Jean Christophe Beyler4e97c532014-01-07 10:07:18 -0800143};
144
145/**
146 * @class NullCheckEliminationAndTypeInference
147 * @brief Null check elimination and type inference.
148 */
149class NullCheckEliminationAndTypeInference : public Pass {
150 public:
Vladimir Marko75ba13f2014-01-28 12:15:24 +0000151 NullCheckEliminationAndTypeInference()
152 : Pass("NCE_TypeInference", kRepeatingPreOrderDFSTraversal, "4_post_nce_cfg") {
Jean Christophe Beyler4e97c532014-01-07 10:07:18 -0800153 }
154
Vladimir Marko75ba13f2014-01-28 12:15:24 +0000155 bool WalkBasicBlocks(CompilationUnit* cUnit, BasicBlock* bb) const {
Jean Christophe Beyler4e97c532014-01-07 10:07:18 -0800156 return cUnit->mir_graph->EliminateNullChecksAndInferTypes(bb);
157 }
158};
159
160/**
161 * @class NullCheckEliminationAndTypeInference
162 * @brief Null check elimination and type inference.
163 */
164class BBCombine : public Pass {
165 public:
Vladimir Marko75ba13f2014-01-28 12:15:24 +0000166 BBCombine() : Pass("BBCombine", kPreOrderDFSTraversal, "5_post_bbcombine_cfg") {
Jean Christophe Beyler4e97c532014-01-07 10:07:18 -0800167 }
168
Vladimir Marko75ba13f2014-01-28 12:15:24 +0000169 bool Gate(const CompilationUnit* cUnit) const {
Jean Christophe Beyler4e97c532014-01-07 10:07:18 -0800170 return ((cUnit->disable_opt & (1 << kSuppressExceptionEdges)) != 0);
171 }
172
Vladimir Marko75ba13f2014-01-28 12:15:24 +0000173 bool WalkBasicBlocks(CompilationUnit* cUnit, BasicBlock* bb) const;
Jean Christophe Beyler4e97c532014-01-07 10:07:18 -0800174};
175
176/**
177 * @class BasicBlock Optimizations
178 * @brief Any simple BasicBlock optimization can be put here.
179 */
180class BBOptimizations : public Pass {
181 public:
Vladimir Marko75ba13f2014-01-28 12:15:24 +0000182 BBOptimizations() : Pass("BBOptimizations", kNoNodes, "5_post_bbo_cfg") {
Jean Christophe Beyler4e97c532014-01-07 10:07:18 -0800183 }
184
Vladimir Marko75ba13f2014-01-28 12:15:24 +0000185 bool Gate(const CompilationUnit* cUnit) const {
Jean Christophe Beyler4e97c532014-01-07 10:07:18 -0800186 return ((cUnit->disable_opt & (1 << kBBOpt)) == 0);
187 }
188
Vladimir Marko75ba13f2014-01-28 12:15:24 +0000189 void Start(CompilationUnit* cUnit) const;
Jean Christophe Beyler4e97c532014-01-07 10:07:18 -0800190};
191
192} // namespace art
193
194#endif // ART_COMPILER_DEX_BB_OPTIMIZATIONS_H_