blob: bd7c40ba5b1cd9e5d4ff782f6b11adf7601eafe0 [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/**
Jean Christophe Beyler4e97c532014-01-07 10:07:18 -080040 * @class CodeLayout
41 * @brief Perform the code layout pass.
42 */
43class CodeLayout : public Pass {
44 public:
Vladimir Marko75ba13f2014-01-28 12:15:24 +000045 CodeLayout() : Pass("CodeLayout", "2_post_layout_cfg") {
Jean Christophe Beyler4e97c532014-01-07 10:07:18 -080046 }
47
Vladimir Marko75ba13f2014-01-28 12:15:24 +000048 void Start(CompilationUnit* cUnit) const {
Jean Christophe Beyler4e97c532014-01-07 10:07:18 -080049 cUnit->mir_graph->VerifyDataflow();
50 }
51
Vladimir Marko75ba13f2014-01-28 12:15:24 +000052 bool WalkBasicBlocks(CompilationUnit* cUnit, BasicBlock* bb) const;
Jean Christophe Beyler4e97c532014-01-07 10:07:18 -080053};
54
55/**
56 * @class SSATransformation
57 * @brief Perform an SSA representation pass on the CompilationUnit.
58 */
59class SSATransformation : public Pass {
60 public:
Vladimir Marko75ba13f2014-01-28 12:15:24 +000061 SSATransformation() : Pass("SSATransformation", kPreOrderDFSTraversal, "3_post_ssa_cfg") {
Jean Christophe Beyler4e97c532014-01-07 10:07:18 -080062 }
63
Vladimir Marko75ba13f2014-01-28 12:15:24 +000064 bool WalkBasicBlocks(CompilationUnit* cUnit, BasicBlock* bb) const;
Jean Christophe Beyler4e97c532014-01-07 10:07:18 -080065
Vladimir Marko75ba13f2014-01-28 12:15:24 +000066 void Start(CompilationUnit* cUnit) const {
Jean Christophe Beyler4e97c532014-01-07 10:07:18 -080067 cUnit->mir_graph->InitializeSSATransformation();
68 }
69
Vladimir Marko75ba13f2014-01-28 12:15:24 +000070 void End(CompilationUnit* cUnit) const;
Jean Christophe Beyler4e97c532014-01-07 10:07:18 -080071};
72
73/**
74 * @class ConstantPropagation
75 * @brief Perform a constant propagation pass.
76 */
77class ConstantPropagation : public Pass {
78 public:
Vladimir Marko75ba13f2014-01-28 12:15:24 +000079 ConstantPropagation() : Pass("ConstantPropagation") {
Jean Christophe Beyler4e97c532014-01-07 10:07:18 -080080 }
81
Vladimir Marko75ba13f2014-01-28 12:15:24 +000082 bool WalkBasicBlocks(CompilationUnit* cUnit, BasicBlock* bb) const;
Jean Christophe Beyler4e97c532014-01-07 10:07:18 -080083
Vladimir Marko75ba13f2014-01-28 12:15:24 +000084 void Start(CompilationUnit* cUnit) const {
Jean Christophe Beyler4e97c532014-01-07 10:07:18 -080085 cUnit->mir_graph->InitializeConstantPropagation();
86 }
87};
88
89/**
90 * @class InitRegLocations
91 * @brief Initialize Register Locations.
92 */
93class InitRegLocations : public Pass {
94 public:
Vladimir Marko75ba13f2014-01-28 12:15:24 +000095 InitRegLocations() : Pass("InitRegLocation", kNoNodes) {
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->InitRegLocations();
100 }
101};
102
103/**
104 * @class MethodUseCount
105 * @brief Count the register uses of the method
106 */
107class MethodUseCount : public Pass {
108 public:
Vladimir Marko75ba13f2014-01-28 12:15:24 +0000109 MethodUseCount() : Pass("UseCount") {
Jean Christophe Beyler4e97c532014-01-07 10:07:18 -0800110 }
111
Vladimir Marko75ba13f2014-01-28 12:15:24 +0000112 bool WalkBasicBlocks(CompilationUnit* cUnit, BasicBlock* bb) const;
Jean Christophe Beyler4e97c532014-01-07 10:07:18 -0800113
Vladimir Marko75ba13f2014-01-28 12:15:24 +0000114 bool Gate(const CompilationUnit* cUnit) const;
Jean Christophe Beyler4e97c532014-01-07 10:07:18 -0800115};
116
117/**
118 * @class NullCheckEliminationAndTypeInferenceInit
119 * @brief Null check elimination and type inference initialization step.
120 */
121class NullCheckEliminationAndTypeInferenceInit : public Pass {
122 public:
Vladimir Marko75ba13f2014-01-28 12:15:24 +0000123 NullCheckEliminationAndTypeInferenceInit() : Pass("NCE_TypeInferenceInit") {
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 NullCheckEliminationAndTypeInference
133 * @brief Null check elimination and type inference.
134 */
135class NullCheckEliminationAndTypeInference : public Pass {
136 public:
Vladimir Marko75ba13f2014-01-28 12:15:24 +0000137 NullCheckEliminationAndTypeInference()
138 : Pass("NCE_TypeInference", kRepeatingPreOrderDFSTraversal, "4_post_nce_cfg") {
Jean Christophe Beyler4e97c532014-01-07 10:07:18 -0800139 }
140
Vladimir Marko75ba13f2014-01-28 12:15:24 +0000141 bool WalkBasicBlocks(CompilationUnit* cUnit, BasicBlock* bb) const {
Jean Christophe Beyler4e97c532014-01-07 10:07:18 -0800142 return cUnit->mir_graph->EliminateNullChecksAndInferTypes(bb);
143 }
144};
145
146/**
147 * @class NullCheckEliminationAndTypeInference
148 * @brief Null check elimination and type inference.
149 */
150class BBCombine : public Pass {
151 public:
Vladimir Marko75ba13f2014-01-28 12:15:24 +0000152 BBCombine() : Pass("BBCombine", kPreOrderDFSTraversal, "5_post_bbcombine_cfg") {
Jean Christophe Beyler4e97c532014-01-07 10:07:18 -0800153 }
154
Vladimir Marko75ba13f2014-01-28 12:15:24 +0000155 bool Gate(const CompilationUnit* cUnit) const {
Jean Christophe Beyler4e97c532014-01-07 10:07:18 -0800156 return ((cUnit->disable_opt & (1 << kSuppressExceptionEdges)) != 0);
157 }
158
Vladimir Marko75ba13f2014-01-28 12:15:24 +0000159 bool WalkBasicBlocks(CompilationUnit* cUnit, BasicBlock* bb) const;
Jean Christophe Beyler4e97c532014-01-07 10:07:18 -0800160};
161
162/**
163 * @class BasicBlock Optimizations
164 * @brief Any simple BasicBlock optimization can be put here.
165 */
166class BBOptimizations : public Pass {
167 public:
Vladimir Marko75ba13f2014-01-28 12:15:24 +0000168 BBOptimizations() : Pass("BBOptimizations", kNoNodes, "5_post_bbo_cfg") {
Jean Christophe Beyler4e97c532014-01-07 10:07:18 -0800169 }
170
Vladimir Marko75ba13f2014-01-28 12:15:24 +0000171 bool Gate(const CompilationUnit* cUnit) const {
Jean Christophe Beyler4e97c532014-01-07 10:07:18 -0800172 return ((cUnit->disable_opt & (1 << kBBOpt)) == 0);
173 }
174
Vladimir Marko75ba13f2014-01-28 12:15:24 +0000175 void Start(CompilationUnit* cUnit) const;
Jean Christophe Beyler4e97c532014-01-07 10:07:18 -0800176};
177
178} // namespace art
179
180#endif // ART_COMPILER_DEX_BB_OPTIMIZATIONS_H_