blob: ff15939ce0bebd9c9df927220372addd9276eac0 [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
buzbeeefc63692012-11-14 16:31:52 -080020#include "compiler_internals.h"
buzbee67bf8852011-08-17 17:51:35 -070021
Elliott Hughes11d1b0c2012-01-23 16:57:47 -080022namespace art {
23
Elliott Hughes719ace42012-03-09 18:06:03 -080024enum DataFlowAttributePos {
Bill Buzbeea114add2012-05-03 15:00:40 -070025 kUA = 0,
26 kUB,
27 kUC,
buzbeebff24652012-05-06 16:22:05 -070028 kAWide,
29 kBWide,
30 kCWide,
Bill Buzbeea114add2012-05-03 15:00:40 -070031 kDA,
Bill Buzbeea114add2012-05-03 15:00:40 -070032 kIsMove,
Bill Buzbeea114add2012-05-03 15:00:40 -070033 kSetsConst,
34 kFormat35c,
35 kFormat3rc,
Bill Buzbeea114add2012-05-03 15:00:40 -070036 kNullCheckSrc0, // Null check of uses[0]
37 kNullCheckSrc1, // Null check of uses[1]
38 kNullCheckSrc2, // Null check of uses[2]
39 kNullCheckOut0, // Null check out outgoing arg0
40 kDstNonNull, // May assume dst is non-null
41 kRetNonNull, // May assume retval is non-null
42 kNullTransferSrc0, // Object copy src[0] -> dst
43 kNullTransferSrcN, // Phi null check state transfer
44 kRangeCheckSrc1, // Range check of uses[1]
45 kRangeCheckSrc2, // Range check of uses[2]
46 kRangeCheckSrc3, // Range check of uses[3]
47 kFPA,
48 kFPB,
49 kFPC,
50 kCoreA,
51 kCoreB,
52 kCoreC,
buzbeebff24652012-05-06 16:22:05 -070053 kRefA,
54 kRefB,
55 kRefC,
Bill Buzbeea114add2012-05-03 15:00:40 -070056 kUsesMethodStar, // Implicit use of Method*
Elliott Hughes719ace42012-03-09 18:06:03 -080057};
buzbee67bf8852011-08-17 17:51:35 -070058
59#define DF_NOP 0
60#define DF_UA (1 << kUA)
61#define DF_UB (1 << kUB)
62#define DF_UC (1 << kUC)
buzbeebff24652012-05-06 16:22:05 -070063#define DF_A_WIDE (1 << kAWide)
64#define DF_B_WIDE (1 << kBWide)
65#define DF_C_WIDE (1 << kCWide)
buzbee67bf8852011-08-17 17:51:35 -070066#define DF_DA (1 << kDA)
buzbee67bf8852011-08-17 17:51:35 -070067#define DF_IS_MOVE (1 << kIsMove)
buzbee67bf8852011-08-17 17:51:35 -070068#define DF_SETS_CONST (1 << kSetsConst)
69#define DF_FORMAT_35C (1 << kFormat35c)
70#define DF_FORMAT_3RC (1 << kFormat3rc)
buzbee43a36422011-09-14 14:00:13 -070071#define DF_NULL_CHK_0 (1 << kNullCheckSrc0)
72#define DF_NULL_CHK_1 (1 << kNullCheckSrc1)
buzbee239c4e72012-03-16 08:42:29 -070073#define DF_NULL_CHK_2 (1 << kNullCheckSrc2)
buzbee43a36422011-09-14 14:00:13 -070074#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)
buzbee9c044ce2012-03-18 13:24:07 -070081#define DF_RANGE_CHK_3 (1 << kRangeCheckSrc3)
buzbee67bf8852011-08-17 17:51:35 -070082#define DF_FP_A (1 << kFPA)
83#define DF_FP_B (1 << kFPB)
84#define DF_FP_C (1 << kFPC)
buzbee67bc2362011-10-11 18:08:40 -070085#define DF_CORE_A (1 << kCoreA)
86#define DF_CORE_B (1 << kCoreB)
87#define DF_CORE_C (1 << kCoreC)
buzbeebff24652012-05-06 16:22:05 -070088#define DF_REF_A (1 << kRefA)
89#define DF_REF_B (1 << kRefB)
90#define DF_REF_C (1 << kRefC)
buzbee9c044ce2012-03-18 13:24:07 -070091#define DF_UMS (1 << kUsesMethodStar)
buzbee67bf8852011-08-17 17:51:35 -070092
buzbeebff24652012-05-06 16:22:05 -070093#define DF_HAS_USES (DF_UA | DF_UB | DF_UC)
buzbee67bf8852011-08-17 17:51:35 -070094
buzbeebff24652012-05-06 16:22:05 -070095#define DF_HAS_DEFS (DF_DA)
buzbee67bf8852011-08-17 17:51:35 -070096
buzbee43a36422011-09-14 14:00:13 -070097#define DF_HAS_NULL_CHKS (DF_NULL_CHK_0 | \
98 DF_NULL_CHK_1 | \
buzbee239c4e72012-03-16 08:42:29 -070099 DF_NULL_CHK_2 | \
buzbee43a36422011-09-14 14:00:13 -0700100 DF_NULL_CHK_OUT0)
101
buzbeed1643e42012-09-05 14:06:51 -0700102#define DF_HAS_RANGE_CHKS (DF_RANGE_CHK_1 | \
buzbeeb7574cf2012-09-10 11:04:09 -0700103 DF_RANGE_CHK_2 | \
104 DF_RANGE_CHK_3)
buzbee67bf8852011-08-17 17:51:35 -0700105
buzbeed1643e42012-09-05 14:06:51 -0700106#define DF_HAS_NR_CHKS (DF_HAS_NULL_CHKS | \
107 DF_HAS_RANGE_CHKS)
108
buzbeebff24652012-05-06 16:22:05 -0700109#define DF_A_IS_REG (DF_UA | DF_DA)
110#define DF_B_IS_REG (DF_UB)
111#define DF_C_IS_REG (DF_UC)
buzbee67bf8852011-08-17 17:51:35 -0700112#define DF_IS_GETTER_OR_SETTER (DF_IS_GETTER | DF_IS_SETTER)
buzbee99ba9642012-01-25 14:23:14 -0800113#define DF_USES_FP (DF_FP_A | DF_FP_B | DF_FP_C)
buzbee67bf8852011-08-17 17:51:35 -0700114
buzbeeba938cb2012-02-03 14:47:55 -0800115extern const int oatDataFlowAttributes[kMirOpLast];
buzbee67bf8852011-08-17 17:51:35 -0700116
Elliott Hughes719ace42012-03-09 18:06:03 -0800117struct BasicBlockDataFlow {
Bill Buzbeea114add2012-05-03 15:00:40 -0700118 ArenaBitVector* useV;
119 ArenaBitVector* defV;
120 ArenaBitVector* liveInV;
121 ArenaBitVector* phiV;
122 int* vRegToSSAMap;
123 ArenaBitVector* endingNullCheckV;
Elliott Hughes719ace42012-03-09 18:06:03 -0800124};
buzbee67bf8852011-08-17 17:51:35 -0700125
Elliott Hughes719ace42012-03-09 18:06:03 -0800126struct SSARepresentation {
Bill Buzbeea114add2012-05-03 15:00:40 -0700127 int numUses;
128 int* uses;
129 bool* fpUse;
130 int numDefs;
131 int* defs;
132 bool* fpDef;
Elliott Hughes719ace42012-03-09 18:06:03 -0800133};
buzbee67bf8852011-08-17 17:51:35 -0700134
135/*
136 * An induction variable is represented by "m*i + c", where i is a basic
137 * induction variable.
138 */
Elliott Hughes719ace42012-03-09 18:06:03 -0800139struct InductionVariableInfo {
Bill Buzbeea114add2012-05-03 15:00:40 -0700140 int ssaReg;
141 int basicSSAReg;
142 int m; // multiplier
143 int c; // constant
144 int inc; // loop increment
Elliott Hughes719ace42012-03-09 18:06:03 -0800145};
buzbee67bf8852011-08-17 17:51:35 -0700146
Elliott Hughes719ace42012-03-09 18:06:03 -0800147struct ArrayAccessInfo {
Bill Buzbeea114add2012-05-03 15:00:40 -0700148 int arrayReg;
149 int ivReg;
150 int maxC; // For DIV - will affect upper bound checking
151 int minC; // For DIV - will affect lower bound checking
Elliott Hughes719ace42012-03-09 18:06:03 -0800152};
buzbee67bf8852011-08-17 17:51:35 -0700153
buzbee239c4e72012-03-16 08:42:29 -0700154struct LoopInfo {
Bill Buzbeea114add2012-05-03 15:00:40 -0700155 BasicBlock* header;
156 GrowableList incomingBackEdges;
157 ArenaBitVector* blocks;
buzbee239c4e72012-03-16 08:42:29 -0700158};
159
buzbeeeaf09bc2012-11-15 14:51:41 -0800160int SRegToVReg(const CompilationUnit* cUnit, int ssaReg);
161char* oatGetDalvikDisassembly(CompilationUnit* cUnit, const DecodedInstruction& insn, const char* note);
162char* oatFullDisassembler(CompilationUnit* cUnit, const MIR* mir);
163char* oatGetSSAString(CompilationUnit* cUnit, SSARepresentation* ssaRep);
164bool oatFindLocalLiveIn(CompilationUnit* cUnit, BasicBlock* bb);
165bool oatDoSSAConversion(CompilationUnit* cUnit, BasicBlock* bb);
166bool oatDoConstantPropagation(CompilationUnit* cUnit, BasicBlock* bb);
167void oatInitializeSSAConversion(CompilationUnit* cUnit);
168bool oatClearVisitedFlag(struct CompilationUnit* cUnit, struct BasicBlock* bb);
169void oatDataFlowAnalysisDispatcher(CompilationUnit* cUnit, bool (*func)(CompilationUnit*, BasicBlock*), DataFlowAnalysisMode dfaMode, bool isIterative);
170MIR* oatFindMoveResult(CompilationUnit* cUnit, BasicBlock* bb, MIR* mir);
171void oatMethodNullCheckElimination(CompilationUnit *cUnit);
172void oatMethodBasicBlockCombine(CompilationUnit* cUnit);
173void oatMethodCodeLayout(CompilationUnit* cUnit);
174void oatDumpCheckStats(CompilationUnit *cUnit);
175void oatMethodBasicBlockOptimization(CompilationUnit *cUnit);
176void oatDumpLoops(CompilationUnit *cUnit);
177void oatMethodLoopDetection(CompilationUnit *cUnit);
178void oatMethodUseCount(CompilationUnit *cUnit);
buzbeee1965672012-03-11 18:39:19 -0700179
Elliott Hughes11d1b0c2012-01-23 16:57:47 -0800180} // namespace art
181
buzbee67bf8852011-08-17 17:51:35 -0700182#endif // ART_SRC_COMPILER_DATAFLOW_H_