summaryrefslogtreecommitdiffstats
path: root/compiler/dex/bb_optimizations.h
blob: fb482bf683c622018067f2a2180eb3a527df7fbc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
/*
 * Copyright (C) 2014 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef ART_COMPILER_DEX_BB_OPTIMIZATIONS_H_
#define ART_COMPILER_DEX_BB_OPTIMIZATIONS_H_

#include "compiler_internals.h"
#include "pass.h"

namespace art {

/**
 * @class CacheFieldLoweringInfo
 * @brief Cache the lowering info for fields used by IGET/IPUT/SGET/SPUT insns.
 */
class CacheFieldLoweringInfo : public Pass {
 public:
  CacheFieldLoweringInfo() : Pass("CacheFieldLoweringInfo", kNoNodes) {
  }

  void Start(CompilationUnit* cUnit) const {
    cUnit->mir_graph->DoCacheFieldLoweringInfo();
  }

  bool Gate(const CompilationUnit *cUnit) const {
    return cUnit->mir_graph->HasFieldAccess();
  }
};

/**
 * @class CacheMethodLoweringInfo
 * @brief Cache the lowering info for methods called by INVOKEs.
 */
class CacheMethodLoweringInfo : public Pass {
 public:
  CacheMethodLoweringInfo() : Pass("CacheMethodLoweringInfo", kNoNodes) {
  }

  void Start(CompilationUnit* cUnit) const {
    cUnit->mir_graph->DoCacheMethodLoweringInfo();
  }

  bool Gate(const CompilationUnit *cUnit) const {
    return cUnit->mir_graph->HasInvokes();
  }
};

/**
 * @class CodeLayout
 * @brief Perform the code layout pass.
 */
class CodeLayout : public Pass {
 public:
  CodeLayout() : Pass("CodeLayout", "2_post_layout_cfg") {
  }

  void Start(CompilationUnit* cUnit) const {
    cUnit->mir_graph->VerifyDataflow();
  }

  bool WalkBasicBlocks(CompilationUnit* cUnit, BasicBlock* bb) const;
};

/**
 * @class SSATransformation
 * @brief Perform an SSA representation pass on the CompilationUnit.
 */
class SSATransformation : public Pass {
 public:
  SSATransformation() : Pass("SSATransformation", kPreOrderDFSTraversal, "3_post_ssa_cfg") {
  }

  bool WalkBasicBlocks(CompilationUnit* cUnit, BasicBlock* bb) const;

  void Start(CompilationUnit* cUnit) const {
    cUnit->mir_graph->InitializeSSATransformation();
  }

  void End(CompilationUnit* cUnit) const;
};

/**
 * @class ConstantPropagation
 * @brief Perform a constant propagation pass.
 */
class ConstantPropagation : public Pass {
 public:
  ConstantPropagation() : Pass("ConstantPropagation") {
  }

  bool WalkBasicBlocks(CompilationUnit* cUnit, BasicBlock* bb) const;

  void Start(CompilationUnit* cUnit) const {
    cUnit->mir_graph->InitializeConstantPropagation();
  }
};

/**
 * @class InitRegLocations
 * @brief Initialize Register Locations.
 */
class InitRegLocations : public Pass {
 public:
  InitRegLocations() : Pass("InitRegLocation", kNoNodes) {
  }

  void Start(CompilationUnit* cUnit) const {
    cUnit->mir_graph->InitRegLocations();
  }
};

/**
 * @class MethodUseCount
 * @brief Count the register uses of the method
 */
class MethodUseCount : public Pass {
 public:
  MethodUseCount() : Pass("UseCount") {
  }

  bool WalkBasicBlocks(CompilationUnit* cUnit, BasicBlock* bb) const;

  bool Gate(const CompilationUnit* cUnit) const;
};

/**
 * @class NullCheckEliminationAndTypeInference
 * @brief Null check elimination and type inference.
 */
class NullCheckEliminationAndTypeInference : public Pass {
 public:
  NullCheckEliminationAndTypeInference()
    : Pass("NCE_TypeInference", kRepeatingPreOrderDFSTraversal, "4_post_nce_cfg") {
  }

  void Start(CompilationUnit* cUnit) const {
    cUnit->mir_graph->EliminateNullChecksAndInferTypesStart();
  }

  bool WalkBasicBlocks(CompilationUnit* cUnit, BasicBlock* bb) const {
    return cUnit->mir_graph->EliminateNullChecksAndInferTypes(bb);
  }

  void End(CompilationUnit* cUnit) const {
    cUnit->mir_graph->EliminateNullChecksAndInferTypesEnd();
  }
};

class ClassInitCheckElimination : public Pass {
 public:
  ClassInitCheckElimination() : Pass("ClInitCheckElimination", kRepeatingPreOrderDFSTraversal) {
  }

  bool Gate(const CompilationUnit* cUnit) const {
    return cUnit->mir_graph->EliminateClassInitChecksGate();
  }

  bool WalkBasicBlocks(CompilationUnit* cUnit, BasicBlock* bb) const {
    return cUnit->mir_graph->EliminateClassInitChecks(bb);
  }

  void End(CompilationUnit* cUnit) const {
    cUnit->mir_graph->EliminateClassInitChecksEnd();
  }
};

/**
 * @class NullCheckEliminationAndTypeInference
 * @brief Null check elimination and type inference.
 */
class BBCombine : public Pass {
 public:
  BBCombine() : Pass("BBCombine", kPreOrderDFSTraversal, "5_post_bbcombine_cfg") {
  }

  bool Gate(const CompilationUnit* cUnit) const {
    return ((cUnit->disable_opt & (1 << kSuppressExceptionEdges)) != 0);
  }

  bool WalkBasicBlocks(CompilationUnit* cUnit, BasicBlock* bb) const;
};

/**
 * @class BasicBlock Optimizations
 * @brief Any simple BasicBlock optimization can be put here.
 */
class BBOptimizations : public Pass {
 public:
  BBOptimizations() : Pass("BBOptimizations", kNoNodes, "5_post_bbo_cfg") {
  }

  bool Gate(const CompilationUnit* cUnit) const {
    return ((cUnit->disable_opt & (1 << kBBOpt)) == 0);
  }

  void Start(CompilationUnit* cUnit) const;
};

}  // namespace art

#endif  // ART_COMPILER_DEX_BB_OPTIMIZATIONS_H_