blob: e810e528c1b6bf055e4cfbe6aed42c31ed5a869b [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
buzbee67bf8852011-08-17 17:51:35 -070025typedef enum DataFlowAttributePos {
26 kUA = 0,
27 kUB,
28 kUC,
29 kUAWide,
30 kUBWide,
31 kUCWide,
32 kDA,
33 kDAWide,
34 kIsMove,
35 kIsLinear,
36 kSetsConst,
37 kFormat35c,
38 kFormat3rc,
39 kPhi,
buzbee43a36422011-09-14 14:00:13 -070040 kNullCheckSrc0, // Null check of src[0]
41 kNullCheckSrc1, // Null check of src[1]
42 kNullCheckOut0, // Null check out outgoing arg0
43 kDstNonNull, // May assume dst is non-null
44 kRetNonNull, // May assume retval is non-null
45 kNullTransferSrc0, // Object copy src[0] -> dst
46 kNullTransferSrcN, // Phi null check state transfer
47 kRangeCheckSrc1, // Range check of src[1]
48 kRangeCheckSrc2, // Range check of src[2]
buzbee67bf8852011-08-17 17:51:35 -070049 kFPA,
50 kFPB,
51 kFPC,
buzbee67bc2362011-10-11 18:08:40 -070052 kCoreA,
53 kCoreB,
54 kCoreC,
buzbee67bf8852011-08-17 17:51:35 -070055 kGetter,
56 kSetter,
57} DataFlowAttributes;
58
59#define DF_NOP 0
60#define DF_UA (1 << kUA)
61#define DF_UB (1 << kUB)
62#define DF_UC (1 << kUC)
63#define DF_UA_WIDE (1 << kUAWide)
64#define DF_UB_WIDE (1 << kUBWide)
65#define DF_UC_WIDE (1 << kUCWide)
66#define DF_DA (1 << kDA)
67#define DF_DA_WIDE (1 << kDAWide)
68#define DF_IS_MOVE (1 << kIsMove)
69#define DF_IS_LINEAR (1 << kIsLinear)
70#define DF_SETS_CONST (1 << kSetsConst)
71#define DF_FORMAT_35C (1 << kFormat35c)
72#define DF_FORMAT_3RC (1 << kFormat3rc)
73#define DF_PHI (1 << kPhi)
buzbee43a36422011-09-14 14:00:13 -070074#define DF_NULL_CHK_0 (1 << kNullCheckSrc0)
75#define DF_NULL_CHK_1 (1 << kNullCheckSrc1)
76#define DF_NULL_CHK_OUT0 (1 << kNullCheckOut0)
77#define DF_NON_NULL_DST (1 << kDstNonNull)
78#define DF_NON_NULL_RET (1 << kRetNonNull)
79#define DF_NULL_TRANSFER_0 (1 << kNullTransferSrc0)
80#define DF_NULL_TRANSFER_N (1 << kNullTransferSrcN)
81#define DF_RANGE_CHK_1 (1 << kRangeCheckSrc1)
82#define DF_RANGE_CHK_2 (1 << kRangeCheckSrc2)
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)
buzbee67bf8852011-08-17 17:51:35 -070089#define DF_IS_GETTER (1 << kGetter)
90#define DF_IS_SETTER (1 << kSetter)
91
92#define DF_HAS_USES (DF_UA | DF_UB | DF_UC | DF_UA_WIDE | \
93 DF_UB_WIDE | DF_UC_WIDE)
94
95#define DF_HAS_DEFS (DF_DA | DF_DA_WIDE)
96
buzbee43a36422011-09-14 14:00:13 -070097#define DF_HAS_NULL_CHKS (DF_NULL_CHK_0 | \
98 DF_NULL_CHK_1 | \
99 DF_NULL_CHK_OUT0)
100
101#define DF_HAS_NR_CHKS (DF_HAS_NULL_CHKS | \
102 DF_RANGE_CHK_1 | \
103 DF_RANGE_CHK_2)
buzbee67bf8852011-08-17 17:51:35 -0700104
105#define DF_A_IS_REG (DF_UA | DF_UA_WIDE | DF_DA | DF_DA_WIDE)
106#define DF_B_IS_REG (DF_UB | DF_UB_WIDE)
107#define DF_C_IS_REG (DF_UC | DF_UC_WIDE)
108#define DF_IS_GETTER_OR_SETTER (DF_IS_GETTER | DF_IS_SETTER)
109
110extern int oatDataFlowAttributes[kMirOpLast];
111
112typedef struct BasicBlockDataFlow {
113 ArenaBitVector* useV;
114 ArenaBitVector* defV;
115 ArenaBitVector* liveInV;
116 ArenaBitVector* phiV;
117 int* dalvikToSSAMap;
buzbee43a36422011-09-14 14:00:13 -0700118 ArenaBitVector* endingNullCheckV;
buzbee67bf8852011-08-17 17:51:35 -0700119} BasicBlockDataFlow;
120
121typedef struct SSARepresentation {
122 int numUses;
123 int* uses;
124 bool* fpUse;
125 int numDefs;
126 int* defs;
127 bool* fpDef;
128} SSARepresentation;
129
130/*
131 * An induction variable is represented by "m*i + c", where i is a basic
132 * induction variable.
133 */
134typedef struct InductionVariableInfo {
135 int ssaReg;
136 int basicSSAReg;
137 int m; // multiplier
138 int c; // constant
Ian Rogers408f79a2011-08-23 18:22:33 -0700139 int inc; // loop increment
buzbee67bf8852011-08-17 17:51:35 -0700140} InductionVariableInfo;
141
142typedef struct ArrayAccessInfo {
143 int arrayReg;
144 int ivReg;
145 int maxC; // For DIV - will affect upper bound checking
146 int minC; // For DIV - will affect lower bound checking
147} ArrayAccessInfo;
148
149#define ENCODE_REG_SUB(r,s) ((s<<16) | r)
150#define DECODE_REG(v) (v & 0xffff)
151#define DECODE_SUB(v) (((unsigned int) v) >> 16)
152
buzbee43a36422011-09-14 14:00:13 -0700153
154void oatMethodNullCheckElimination(CompilationUnit*);
155
Elliott Hughes11d1b0c2012-01-23 16:57:47 -0800156} // namespace art
157
buzbee67bf8852011-08-17 17:51:35 -0700158#endif // ART_SRC_COMPILER_DATAFLOW_H_