blob: 768b27351082bf5977093f41216ab484656bcf77 [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/**
26 * @class CodeLayout
27 * @brief Perform the code layout pass.
28 */
29class CodeLayout : public Pass {
30 public:
31 CodeLayout():Pass("CodeLayout", "2_post_layout_cfg") {
32 }
33
34 void Start(CompilationUnit *cUnit) const {
35 cUnit->mir_graph->VerifyDataflow();
36 }
37
38 bool WalkBasicBlocks(CompilationUnit *cUnit, BasicBlock *bb) const;
39};
40
41/**
42 * @class SSATransformation
43 * @brief Perform an SSA representation pass on the CompilationUnit.
44 */
45class SSATransformation : public Pass {
46 public:
47 SSATransformation():Pass("SSATransformation", kPreOrderDFSTraversal, "3_post_ssa_cfg") {
48 }
49
50 bool WalkBasicBlocks(CompilationUnit *cUnit, BasicBlock *bb) const;
51
52 void Start(CompilationUnit *cUnit) const {
53 cUnit->mir_graph->InitializeSSATransformation();
54 }
55
56 void End(CompilationUnit *cUnit) const;
57};
58
59/**
60 * @class ConstantPropagation
61 * @brief Perform a constant propagation pass.
62 */
63class ConstantPropagation : public Pass {
64 public:
65 ConstantPropagation():Pass("ConstantPropagation") {
66 }
67
68 bool WalkBasicBlocks(CompilationUnit *cUnit, BasicBlock *bb) const;
69
70 void Start(CompilationUnit *cUnit) const {
71 cUnit->mir_graph->InitializeConstantPropagation();
72 }
73};
74
75/**
76 * @class InitRegLocations
77 * @brief Initialize Register Locations.
78 */
79class InitRegLocations : public Pass {
80 public:
81 InitRegLocations():Pass("InitRegLocation") {
82 }
83
84 void Start(CompilationUnit *cUnit) const {
85 cUnit->mir_graph->InitRegLocations();
86 }
87};
88
89/**
90 * @class MethodUseCount
91 * @brief Count the register uses of the method
92 */
93class MethodUseCount : public Pass {
94 public:
95 MethodUseCount():Pass("UseCount") {
96 }
97
98 bool WalkBasicBlocks(CompilationUnit *cUnit, BasicBlock *bb) const;
99
100 bool Gate(const CompilationUnit *cUnit) const;
101};
102
103/**
104 * @class NullCheckEliminationAndTypeInferenceInit
105 * @brief Null check elimination and type inference initialization step.
106 */
107class NullCheckEliminationAndTypeInferenceInit : public Pass {
108 public:
109 NullCheckEliminationAndTypeInferenceInit():Pass("NCE_TypeInferenceInit") {
110 }
111
112 bool WalkBasicBlocks(CompilationUnit *cUnit, BasicBlock *bb) const;
113
114 bool Gate(const CompilationUnit *cUnit) const;
115};
116
117/**
118 * @class NullCheckEliminationAndTypeInference
119 * @brief Null check elimination and type inference.
120 */
121class NullCheckEliminationAndTypeInference : public Pass {
122 public:
123 NullCheckEliminationAndTypeInference():Pass("NCE_TypeInference", kRepeatingPreOrderDFSTraversal, "4_post_nce_cfg") {
124 }
125
126 bool WalkBasicBlocks(CompilationUnit *cUnit, BasicBlock *bb) const {
127 return cUnit->mir_graph->EliminateNullChecksAndInferTypes(bb);
128 }
129};
130
131/**
132 * @class NullCheckEliminationAndTypeInference
133 * @brief Null check elimination and type inference.
134 */
135class BBCombine : public Pass {
136 public:
137 BBCombine():Pass("BBCombine", kPreOrderDFSTraversal, "5_post_bbcombine_cfg") {
138 }
139
140 bool Gate(const CompilationUnit *cUnit) const {
141 return ((cUnit->disable_opt & (1 << kSuppressExceptionEdges)) != 0);
142 }
143
144 bool WalkBasicBlocks(CompilationUnit *cUnit, BasicBlock *bb) const;
145};
146
147/**
148 * @class BasicBlock Optimizations
149 * @brief Any simple BasicBlock optimization can be put here.
150 */
151class BBOptimizations : public Pass {
152 public:
153 BBOptimizations():Pass("BBOptimizations", "5_post_bbo_cfg") {
154 }
155
156 bool Gate(const CompilationUnit *cUnit) const {
157 return ((cUnit->disable_opt & (1 << kBBOpt)) == 0);
158 }
159
160 void Start(CompilationUnit *cUnit) const;
161};
162
163} // namespace art
164
165#endif // ART_COMPILER_DEX_BB_OPTIMIZATIONS_H_