blob: 1286a8e52e7c1b56bc91f5abdf0db3bcca5099b3 [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:
Vladimir Marko75ba13f2014-01-28 12:15:24 +000031 CodeLayout() : Pass("CodeLayout", "2_post_layout_cfg") {
Jean Christophe Beyler4e97c532014-01-07 10:07:18 -080032 }
33
Vladimir Marko75ba13f2014-01-28 12:15:24 +000034 void Start(CompilationUnit* cUnit) const {
Jean Christophe Beyler4e97c532014-01-07 10:07:18 -080035 cUnit->mir_graph->VerifyDataflow();
36 }
37
Vladimir Marko75ba13f2014-01-28 12:15:24 +000038 bool WalkBasicBlocks(CompilationUnit* cUnit, BasicBlock* bb) const;
Jean Christophe Beyler4e97c532014-01-07 10:07:18 -080039};
40
41/**
42 * @class SSATransformation
43 * @brief Perform an SSA representation pass on the CompilationUnit.
44 */
45class SSATransformation : public Pass {
46 public:
Vladimir Marko75ba13f2014-01-28 12:15:24 +000047 SSATransformation() : Pass("SSATransformation", kPreOrderDFSTraversal, "3_post_ssa_cfg") {
Jean Christophe Beyler4e97c532014-01-07 10:07:18 -080048 }
49
Vladimir Marko75ba13f2014-01-28 12:15:24 +000050 bool WalkBasicBlocks(CompilationUnit* cUnit, BasicBlock* bb) const;
Jean Christophe Beyler4e97c532014-01-07 10:07:18 -080051
Vladimir Marko75ba13f2014-01-28 12:15:24 +000052 void Start(CompilationUnit* cUnit) const {
Jean Christophe Beyler4e97c532014-01-07 10:07:18 -080053 cUnit->mir_graph->InitializeSSATransformation();
54 }
55
Vladimir Marko75ba13f2014-01-28 12:15:24 +000056 void End(CompilationUnit* cUnit) const;
Jean Christophe Beyler4e97c532014-01-07 10:07:18 -080057};
58
59/**
60 * @class ConstantPropagation
61 * @brief Perform a constant propagation pass.
62 */
63class ConstantPropagation : public Pass {
64 public:
Vladimir Marko75ba13f2014-01-28 12:15:24 +000065 ConstantPropagation() : Pass("ConstantPropagation") {
Jean Christophe Beyler4e97c532014-01-07 10:07:18 -080066 }
67
Vladimir Marko75ba13f2014-01-28 12:15:24 +000068 bool WalkBasicBlocks(CompilationUnit* cUnit, BasicBlock* bb) const;
Jean Christophe Beyler4e97c532014-01-07 10:07:18 -080069
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->InitializeConstantPropagation();
72 }
73};
74
75/**
76 * @class InitRegLocations
77 * @brief Initialize Register Locations.
78 */
79class InitRegLocations : public Pass {
80 public:
Vladimir Marko75ba13f2014-01-28 12:15:24 +000081 InitRegLocations() : Pass("InitRegLocation", kNoNodes) {
Jean Christophe Beyler4e97c532014-01-07 10:07:18 -080082 }
83
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->InitRegLocations();
86 }
87};
88
89/**
90 * @class MethodUseCount
91 * @brief Count the register uses of the method
92 */
93class MethodUseCount : public Pass {
94 public:
Vladimir Marko75ba13f2014-01-28 12:15:24 +000095 MethodUseCount() : Pass("UseCount") {
Jean Christophe Beyler4e97c532014-01-07 10:07:18 -080096 }
97
Vladimir Marko75ba13f2014-01-28 12:15:24 +000098 bool WalkBasicBlocks(CompilationUnit* cUnit, BasicBlock* bb) const;
Jean Christophe Beyler4e97c532014-01-07 10:07:18 -080099
Vladimir Marko75ba13f2014-01-28 12:15:24 +0000100 bool Gate(const CompilationUnit* cUnit) const;
Jean Christophe Beyler4e97c532014-01-07 10:07:18 -0800101};
102
103/**
104 * @class NullCheckEliminationAndTypeInferenceInit
105 * @brief Null check elimination and type inference initialization step.
106 */
107class NullCheckEliminationAndTypeInferenceInit : public Pass {
108 public:
Vladimir Marko75ba13f2014-01-28 12:15:24 +0000109 NullCheckEliminationAndTypeInferenceInit() : Pass("NCE_TypeInferenceInit") {
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 NullCheckEliminationAndTypeInference
119 * @brief Null check elimination and type inference.
120 */
121class NullCheckEliminationAndTypeInference : public Pass {
122 public:
Vladimir Marko75ba13f2014-01-28 12:15:24 +0000123 NullCheckEliminationAndTypeInference()
124 : Pass("NCE_TypeInference", kRepeatingPreOrderDFSTraversal, "4_post_nce_cfg") {
Jean Christophe Beyler4e97c532014-01-07 10:07:18 -0800125 }
126
Vladimir Marko75ba13f2014-01-28 12:15:24 +0000127 bool WalkBasicBlocks(CompilationUnit* cUnit, BasicBlock* bb) const {
Jean Christophe Beyler4e97c532014-01-07 10:07:18 -0800128 return cUnit->mir_graph->EliminateNullChecksAndInferTypes(bb);
129 }
130};
131
132/**
133 * @class NullCheckEliminationAndTypeInference
134 * @brief Null check elimination and type inference.
135 */
136class BBCombine : public Pass {
137 public:
Vladimir Marko75ba13f2014-01-28 12:15:24 +0000138 BBCombine() : Pass("BBCombine", kPreOrderDFSTraversal, "5_post_bbcombine_cfg") {
Jean Christophe Beyler4e97c532014-01-07 10:07:18 -0800139 }
140
Vladimir Marko75ba13f2014-01-28 12:15:24 +0000141 bool Gate(const CompilationUnit* cUnit) const {
Jean Christophe Beyler4e97c532014-01-07 10:07:18 -0800142 return ((cUnit->disable_opt & (1 << kSuppressExceptionEdges)) != 0);
143 }
144
Vladimir Marko75ba13f2014-01-28 12:15:24 +0000145 bool WalkBasicBlocks(CompilationUnit* cUnit, BasicBlock* bb) const;
Jean Christophe Beyler4e97c532014-01-07 10:07:18 -0800146};
147
148/**
149 * @class BasicBlock Optimizations
150 * @brief Any simple BasicBlock optimization can be put here.
151 */
152class BBOptimizations : public Pass {
153 public:
Vladimir Marko75ba13f2014-01-28 12:15:24 +0000154 BBOptimizations() : Pass("BBOptimizations", kNoNodes, "5_post_bbo_cfg") {
Jean Christophe Beyler4e97c532014-01-07 10:07:18 -0800155 }
156
Vladimir Marko75ba13f2014-01-28 12:15:24 +0000157 bool Gate(const CompilationUnit* cUnit) const {
Jean Christophe Beyler4e97c532014-01-07 10:07:18 -0800158 return ((cUnit->disable_opt & (1 << kBBOpt)) == 0);
159 }
160
Vladimir Marko75ba13f2014-01-28 12:15:24 +0000161 void Start(CompilationUnit* cUnit) const;
Jean Christophe Beyler4e97c532014-01-07 10:07:18 -0800162};
163
164} // namespace art
165
166#endif // ART_COMPILER_DEX_BB_OPTIMIZATIONS_H_