blob: e4a37265bec4f85462eedfd6522f7c319c0fed8f [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,
50 kGetter,
51 kSetter,
52} DataFlowAttributes;
53
54#define DF_NOP 0
55#define DF_UA (1 << kUA)
56#define DF_UB (1 << kUB)
57#define DF_UC (1 << kUC)
58#define DF_UA_WIDE (1 << kUAWide)
59#define DF_UB_WIDE (1 << kUBWide)
60#define DF_UC_WIDE (1 << kUCWide)
61#define DF_DA (1 << kDA)
62#define DF_DA_WIDE (1 << kDAWide)
63#define DF_IS_MOVE (1 << kIsMove)
64#define DF_IS_LINEAR (1 << kIsLinear)
65#define DF_SETS_CONST (1 << kSetsConst)
66#define DF_FORMAT_35C (1 << kFormat35c)
67#define DF_FORMAT_3RC (1 << kFormat3rc)
68#define DF_PHI (1 << kPhi)
buzbee43a36422011-09-14 14:00:13 -070069#define DF_NULL_CHK_0 (1 << kNullCheckSrc0)
70#define DF_NULL_CHK_1 (1 << kNullCheckSrc1)
71#define DF_NULL_CHK_OUT0 (1 << kNullCheckOut0)
72#define DF_NON_NULL_DST (1 << kDstNonNull)
73#define DF_NON_NULL_RET (1 << kRetNonNull)
74#define DF_NULL_TRANSFER_0 (1 << kNullTransferSrc0)
75#define DF_NULL_TRANSFER_N (1 << kNullTransferSrcN)
76#define DF_RANGE_CHK_1 (1 << kRangeCheckSrc1)
77#define DF_RANGE_CHK_2 (1 << kRangeCheckSrc2)
buzbee67bf8852011-08-17 17:51:35 -070078#define DF_FP_A (1 << kFPA)
79#define DF_FP_B (1 << kFPB)
80#define DF_FP_C (1 << kFPC)
81#define DF_IS_GETTER (1 << kGetter)
82#define DF_IS_SETTER (1 << kSetter)
83
84#define DF_HAS_USES (DF_UA | DF_UB | DF_UC | DF_UA_WIDE | \
85 DF_UB_WIDE | DF_UC_WIDE)
86
87#define DF_HAS_DEFS (DF_DA | DF_DA_WIDE)
88
buzbee43a36422011-09-14 14:00:13 -070089#define DF_HAS_NULL_CHKS (DF_NULL_CHK_0 | \
90 DF_NULL_CHK_1 | \
91 DF_NULL_CHK_OUT0)
92
93#define DF_HAS_NR_CHKS (DF_HAS_NULL_CHKS | \
94 DF_RANGE_CHK_1 | \
95 DF_RANGE_CHK_2)
buzbee67bf8852011-08-17 17:51:35 -070096
97#define DF_A_IS_REG (DF_UA | DF_UA_WIDE | DF_DA | DF_DA_WIDE)
98#define DF_B_IS_REG (DF_UB | DF_UB_WIDE)
99#define DF_C_IS_REG (DF_UC | DF_UC_WIDE)
100#define DF_IS_GETTER_OR_SETTER (DF_IS_GETTER | DF_IS_SETTER)
101
102extern int oatDataFlowAttributes[kMirOpLast];
103
104typedef struct BasicBlockDataFlow {
105 ArenaBitVector* useV;
106 ArenaBitVector* defV;
107 ArenaBitVector* liveInV;
108 ArenaBitVector* phiV;
109 int* dalvikToSSAMap;
buzbee43a36422011-09-14 14:00:13 -0700110 ArenaBitVector* endingNullCheckV;
buzbee67bf8852011-08-17 17:51:35 -0700111} BasicBlockDataFlow;
112
113typedef struct SSARepresentation {
114 int numUses;
115 int* uses;
116 bool* fpUse;
117 int numDefs;
118 int* defs;
119 bool* fpDef;
120} SSARepresentation;
121
122/*
123 * An induction variable is represented by "m*i + c", where i is a basic
124 * induction variable.
125 */
126typedef struct InductionVariableInfo {
127 int ssaReg;
128 int basicSSAReg;
129 int m; // multiplier
130 int c; // constant
Ian Rogers408f79a2011-08-23 18:22:33 -0700131 int inc; // loop increment
buzbee67bf8852011-08-17 17:51:35 -0700132} InductionVariableInfo;
133
134typedef struct ArrayAccessInfo {
135 int arrayReg;
136 int ivReg;
137 int maxC; // For DIV - will affect upper bound checking
138 int minC; // For DIV - will affect lower bound checking
139} ArrayAccessInfo;
140
141#define ENCODE_REG_SUB(r,s) ((s<<16) | r)
142#define DECODE_REG(v) (v & 0xffff)
143#define DECODE_SUB(v) (((unsigned int) v) >> 16)
144
buzbee43a36422011-09-14 14:00:13 -0700145
146void oatMethodNullCheckElimination(CompilationUnit*);
147
buzbee67bf8852011-08-17 17:51:35 -0700148#endif // ART_SRC_COMPILER_DATAFLOW_H_