blob: e2d5a4c50a3f60ea2c96d63862d33ade0d71dbcf [file] [log] [blame]
buzbee67bf8852011-08-17 17:51:35 -07001/*
2 * Copyright (C) 2011 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_SRC_COMPILER_DATAFLOW_H_
18#define ART_SRC_COMPILER_DATAFLOW_H_
19
20#include "Dalvik.h"
21#include "CompilerInternals.h"
22
Elliott Hughes11d1b0c2012-01-23 16:57:47 -080023namespace art {
24
Elliott Hughes719ace42012-03-09 18:06:03 -080025enum DataFlowAttributePos {
Bill Buzbeea114add2012-05-03 15:00:40 -070026 kUA = 0,
27 kUB,
28 kUC,
buzbeebff24652012-05-06 16:22:05 -070029 kAWide,
30 kBWide,
31 kCWide,
Bill Buzbeea114add2012-05-03 15:00:40 -070032 kDA,
Bill Buzbeea114add2012-05-03 15:00:40 -070033 kIsMove,
Bill Buzbeea114add2012-05-03 15:00:40 -070034 kSetsConst,
35 kFormat35c,
36 kFormat3rc,
Bill Buzbeea114add2012-05-03 15:00:40 -070037 kNullCheckSrc0, // Null check of uses[0]
38 kNullCheckSrc1, // Null check of uses[1]
39 kNullCheckSrc2, // Null check of uses[2]
40 kNullCheckOut0, // Null check out outgoing arg0
41 kDstNonNull, // May assume dst is non-null
42 kRetNonNull, // May assume retval is non-null
43 kNullTransferSrc0, // Object copy src[0] -> dst
44 kNullTransferSrcN, // Phi null check state transfer
45 kRangeCheckSrc1, // Range check of uses[1]
46 kRangeCheckSrc2, // Range check of uses[2]
47 kRangeCheckSrc3, // Range check of uses[3]
48 kFPA,
49 kFPB,
50 kFPC,
51 kCoreA,
52 kCoreB,
53 kCoreC,
buzbeebff24652012-05-06 16:22:05 -070054 kRefA,
55 kRefB,
56 kRefC,
Bill Buzbeea114add2012-05-03 15:00:40 -070057 kUsesMethodStar, // Implicit use of Method*
Elliott Hughes719ace42012-03-09 18:06:03 -080058};
buzbee67bf8852011-08-17 17:51:35 -070059
60#define DF_NOP 0
61#define DF_UA (1 << kUA)
62#define DF_UB (1 << kUB)
63#define DF_UC (1 << kUC)
buzbeebff24652012-05-06 16:22:05 -070064#define DF_A_WIDE (1 << kAWide)
65#define DF_B_WIDE (1 << kBWide)
66#define DF_C_WIDE (1 << kCWide)
buzbee67bf8852011-08-17 17:51:35 -070067#define DF_DA (1 << kDA)
buzbee67bf8852011-08-17 17:51:35 -070068#define DF_IS_MOVE (1 << kIsMove)
buzbee67bf8852011-08-17 17:51:35 -070069#define DF_SETS_CONST (1 << kSetsConst)
70#define DF_FORMAT_35C (1 << kFormat35c)
71#define DF_FORMAT_3RC (1 << kFormat3rc)
buzbee43a36422011-09-14 14:00:13 -070072#define DF_NULL_CHK_0 (1 << kNullCheckSrc0)
73#define DF_NULL_CHK_1 (1 << kNullCheckSrc1)
buzbee239c4e72012-03-16 08:42:29 -070074#define DF_NULL_CHK_2 (1 << kNullCheckSrc2)
buzbee43a36422011-09-14 14:00:13 -070075#define DF_NULL_CHK_OUT0 (1 << kNullCheckOut0)
76#define DF_NON_NULL_DST (1 << kDstNonNull)
77#define DF_NON_NULL_RET (1 << kRetNonNull)
78#define DF_NULL_TRANSFER_0 (1 << kNullTransferSrc0)
79#define DF_NULL_TRANSFER_N (1 << kNullTransferSrcN)
80#define DF_RANGE_CHK_1 (1 << kRangeCheckSrc1)
81#define DF_RANGE_CHK_2 (1 << kRangeCheckSrc2)
buzbee9c044ce2012-03-18 13:24:07 -070082#define DF_RANGE_CHK_3 (1 << kRangeCheckSrc3)
buzbee67bf8852011-08-17 17:51:35 -070083#define DF_FP_A (1 << kFPA)
84#define DF_FP_B (1 << kFPB)
85#define DF_FP_C (1 << kFPC)
buzbee67bc2362011-10-11 18:08:40 -070086#define DF_CORE_A (1 << kCoreA)
87#define DF_CORE_B (1 << kCoreB)
88#define DF_CORE_C (1 << kCoreC)
buzbeebff24652012-05-06 16:22:05 -070089#define DF_REF_A (1 << kRefA)
90#define DF_REF_B (1 << kRefB)
91#define DF_REF_C (1 << kRefC)
buzbee9c044ce2012-03-18 13:24:07 -070092#define DF_UMS (1 << kUsesMethodStar)
buzbee67bf8852011-08-17 17:51:35 -070093
buzbeebff24652012-05-06 16:22:05 -070094#define DF_HAS_USES (DF_UA | DF_UB | DF_UC)
buzbee67bf8852011-08-17 17:51:35 -070095
buzbeebff24652012-05-06 16:22:05 -070096#define DF_HAS_DEFS (DF_DA)
buzbee67bf8852011-08-17 17:51:35 -070097
buzbee43a36422011-09-14 14:00:13 -070098#define DF_HAS_NULL_CHKS (DF_NULL_CHK_0 | \
99 DF_NULL_CHK_1 | \
buzbee239c4e72012-03-16 08:42:29 -0700100 DF_NULL_CHK_2 | \
buzbee43a36422011-09-14 14:00:13 -0700101 DF_NULL_CHK_OUT0)
102
buzbeed1643e42012-09-05 14:06:51 -0700103#define DF_HAS_RANGE_CHKS (DF_RANGE_CHK_1 | \
buzbeeb7574cf2012-09-10 11:04:09 -0700104 DF_RANGE_CHK_2 | \
105 DF_RANGE_CHK_3)
buzbee67bf8852011-08-17 17:51:35 -0700106
buzbeed1643e42012-09-05 14:06:51 -0700107#define DF_HAS_NR_CHKS (DF_HAS_NULL_CHKS | \
108 DF_HAS_RANGE_CHKS)
109
buzbeebff24652012-05-06 16:22:05 -0700110#define DF_A_IS_REG (DF_UA | DF_DA)
111#define DF_B_IS_REG (DF_UB)
112#define DF_C_IS_REG (DF_UC)
buzbee67bf8852011-08-17 17:51:35 -0700113#define DF_IS_GETTER_OR_SETTER (DF_IS_GETTER | DF_IS_SETTER)
buzbee99ba9642012-01-25 14:23:14 -0800114#define DF_USES_FP (DF_FP_A | DF_FP_B | DF_FP_C)
buzbee67bf8852011-08-17 17:51:35 -0700115
buzbeeba938cb2012-02-03 14:47:55 -0800116extern const int oatDataFlowAttributes[kMirOpLast];
buzbee67bf8852011-08-17 17:51:35 -0700117
Elliott Hughes719ace42012-03-09 18:06:03 -0800118struct BasicBlockDataFlow {
Bill Buzbeea114add2012-05-03 15:00:40 -0700119 ArenaBitVector* useV;
120 ArenaBitVector* defV;
121 ArenaBitVector* liveInV;
122 ArenaBitVector* phiV;
123 int* vRegToSSAMap;
124 ArenaBitVector* endingNullCheckV;
Elliott Hughes719ace42012-03-09 18:06:03 -0800125};
buzbee67bf8852011-08-17 17:51:35 -0700126
Elliott Hughes719ace42012-03-09 18:06:03 -0800127struct SSARepresentation {
Bill Buzbeea114add2012-05-03 15:00:40 -0700128 int numUses;
129 int* uses;
130 bool* fpUse;
131 int numDefs;
132 int* defs;
133 bool* fpDef;
Elliott Hughes719ace42012-03-09 18:06:03 -0800134};
buzbee67bf8852011-08-17 17:51:35 -0700135
136/*
137 * An induction variable is represented by "m*i + c", where i is a basic
138 * induction variable.
139 */
Elliott Hughes719ace42012-03-09 18:06:03 -0800140struct InductionVariableInfo {
Bill Buzbeea114add2012-05-03 15:00:40 -0700141 int ssaReg;
142 int basicSSAReg;
143 int m; // multiplier
144 int c; // constant
145 int inc; // loop increment
Elliott Hughes719ace42012-03-09 18:06:03 -0800146};
buzbee67bf8852011-08-17 17:51:35 -0700147
Elliott Hughes719ace42012-03-09 18:06:03 -0800148struct ArrayAccessInfo {
Bill Buzbeea114add2012-05-03 15:00:40 -0700149 int arrayReg;
150 int ivReg;
151 int maxC; // For DIV - will affect upper bound checking
152 int minC; // For DIV - will affect lower bound checking
Elliott Hughes719ace42012-03-09 18:06:03 -0800153};
buzbee67bf8852011-08-17 17:51:35 -0700154
buzbee239c4e72012-03-16 08:42:29 -0700155struct LoopInfo {
Bill Buzbeea114add2012-05-03 15:00:40 -0700156 BasicBlock* header;
157 GrowableList incomingBackEdges;
158 ArenaBitVector* blocks;
buzbee239c4e72012-03-16 08:42:29 -0700159};
160
161void oatMethodLoopDetection(CompilationUnit*);
162
163void oatMethodUseCount(CompilationUnit*);
164
buzbee43a36422011-09-14 14:00:13 -0700165void oatMethodNullCheckElimination(CompilationUnit*);
166
buzbeed1643e42012-09-05 14:06:51 -0700167void oatDumpCheckStats(CompilationUnit*);
168
169void oatMethodBasicBlockCombine(CompilationUnit*);
170
buzbeee1965672012-03-11 18:39:19 -0700171void oatMethodBasicBlockOptimization(CompilationUnit*);
172
Elliott Hughes11d1b0c2012-01-23 16:57:47 -0800173} // namespace art
174
buzbee67bf8852011-08-17 17:51:35 -0700175#endif // ART_SRC_COMPILER_DATAFLOW_H_