blob: 1696e44f3b5ec6b577cc51687c4c9f9453e31629 [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
23typedef enum DataFlowAttributePos {
24 kUA = 0,
25 kUB,
26 kUC,
27 kUAWide,
28 kUBWide,
29 kUCWide,
30 kDA,
31 kDAWide,
32 kIsMove,
33 kIsLinear,
34 kSetsConst,
35 kFormat35c,
36 kFormat3rc,
37 kPhi,
buzbee43a36422011-09-14 14:00:13 -070038 kNullCheckSrc0, // Null check of src[0]
39 kNullCheckSrc1, // Null check of src[1]
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 src[1]
46 kRangeCheckSrc2, // Range check of src[2]
buzbee67bf8852011-08-17 17:51:35 -070047 kFPA,
48 kFPB,
49 kFPC,
buzbee67bc2362011-10-11 18:08:40 -070050 kCoreA,
51 kCoreB,
52 kCoreC,
buzbee67bf8852011-08-17 17:51:35 -070053 kGetter,
54 kSetter,
55} DataFlowAttributes;
56
57#define DF_NOP 0
58#define DF_UA (1 << kUA)
59#define DF_UB (1 << kUB)
60#define DF_UC (1 << kUC)
61#define DF_UA_WIDE (1 << kUAWide)
62#define DF_UB_WIDE (1 << kUBWide)
63#define DF_UC_WIDE (1 << kUCWide)
64#define DF_DA (1 << kDA)
65#define DF_DA_WIDE (1 << kDAWide)
66#define DF_IS_MOVE (1 << kIsMove)
67#define DF_IS_LINEAR (1 << kIsLinear)
68#define DF_SETS_CONST (1 << kSetsConst)
69#define DF_FORMAT_35C (1 << kFormat35c)
70#define DF_FORMAT_3RC (1 << kFormat3rc)
71#define DF_PHI (1 << kPhi)
buzbee43a36422011-09-14 14:00:13 -070072#define DF_NULL_CHK_0 (1 << kNullCheckSrc0)
73#define DF_NULL_CHK_1 (1 << kNullCheckSrc1)
74#define DF_NULL_CHK_OUT0 (1 << kNullCheckOut0)
75#define DF_NON_NULL_DST (1 << kDstNonNull)
76#define DF_NON_NULL_RET (1 << kRetNonNull)
77#define DF_NULL_TRANSFER_0 (1 << kNullTransferSrc0)
78#define DF_NULL_TRANSFER_N (1 << kNullTransferSrcN)
79#define DF_RANGE_CHK_1 (1 << kRangeCheckSrc1)
80#define DF_RANGE_CHK_2 (1 << kRangeCheckSrc2)
buzbee67bf8852011-08-17 17:51:35 -070081#define DF_FP_A (1 << kFPA)
82#define DF_FP_B (1 << kFPB)
83#define DF_FP_C (1 << kFPC)
buzbee67bc2362011-10-11 18:08:40 -070084#define DF_CORE_A (1 << kCoreA)
85#define DF_CORE_B (1 << kCoreB)
86#define DF_CORE_C (1 << kCoreC)
buzbee67bf8852011-08-17 17:51:35 -070087#define DF_IS_GETTER (1 << kGetter)
88#define DF_IS_SETTER (1 << kSetter)
89
90#define DF_HAS_USES (DF_UA | DF_UB | DF_UC | DF_UA_WIDE | \
91 DF_UB_WIDE | DF_UC_WIDE)
92
93#define DF_HAS_DEFS (DF_DA | DF_DA_WIDE)
94
buzbee43a36422011-09-14 14:00:13 -070095#define DF_HAS_NULL_CHKS (DF_NULL_CHK_0 | \
96 DF_NULL_CHK_1 | \
97 DF_NULL_CHK_OUT0)
98
99#define DF_HAS_NR_CHKS (DF_HAS_NULL_CHKS | \
100 DF_RANGE_CHK_1 | \
101 DF_RANGE_CHK_2)
buzbee67bf8852011-08-17 17:51:35 -0700102
103#define DF_A_IS_REG (DF_UA | DF_UA_WIDE | DF_DA | DF_DA_WIDE)
104#define DF_B_IS_REG (DF_UB | DF_UB_WIDE)
105#define DF_C_IS_REG (DF_UC | DF_UC_WIDE)
106#define DF_IS_GETTER_OR_SETTER (DF_IS_GETTER | DF_IS_SETTER)
107
108extern int oatDataFlowAttributes[kMirOpLast];
109
110typedef struct BasicBlockDataFlow {
111 ArenaBitVector* useV;
112 ArenaBitVector* defV;
113 ArenaBitVector* liveInV;
114 ArenaBitVector* phiV;
115 int* dalvikToSSAMap;
buzbee43a36422011-09-14 14:00:13 -0700116 ArenaBitVector* endingNullCheckV;
buzbee67bf8852011-08-17 17:51:35 -0700117} BasicBlockDataFlow;
118
119typedef struct SSARepresentation {
120 int numUses;
121 int* uses;
122 bool* fpUse;
123 int numDefs;
124 int* defs;
125 bool* fpDef;
126} SSARepresentation;
127
128/*
129 * An induction variable is represented by "m*i + c", where i is a basic
130 * induction variable.
131 */
132typedef struct InductionVariableInfo {
133 int ssaReg;
134 int basicSSAReg;
135 int m; // multiplier
136 int c; // constant
Ian Rogers408f79a2011-08-23 18:22:33 -0700137 int inc; // loop increment
buzbee67bf8852011-08-17 17:51:35 -0700138} InductionVariableInfo;
139
140typedef struct ArrayAccessInfo {
141 int arrayReg;
142 int ivReg;
143 int maxC; // For DIV - will affect upper bound checking
144 int minC; // For DIV - will affect lower bound checking
145} ArrayAccessInfo;
146
147#define ENCODE_REG_SUB(r,s) ((s<<16) | r)
148#define DECODE_REG(v) (v & 0xffff)
149#define DECODE_SUB(v) (((unsigned int) v) >> 16)
150
buzbee43a36422011-09-14 14:00:13 -0700151
152void oatMethodNullCheckElimination(CompilationUnit*);
153
buzbee67bf8852011-08-17 17:51:35 -0700154#endif // ART_SRC_COMPILER_DATAFLOW_H_