buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 1 | /* |
| 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 Hughes | 11d1b0c | 2012-01-23 16:57:47 -0800 | [diff] [blame] | 23 | namespace art { |
| 24 | |
Elliott Hughes | 719ace4 | 2012-03-09 18:06:03 -0800 | [diff] [blame] | 25 | enum DataFlowAttributePos { |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 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, |
buzbee | 239c4e7 | 2012-03-16 08:42:29 -0700 | [diff] [blame^] | 40 | kNullCheckSrc0, // Null check of uses[0] |
| 41 | kNullCheckSrc1, // Null check of uses[1] |
| 42 | kNullCheckSrc2, // Null check of uses[2] |
buzbee | 43a3642 | 2011-09-14 14:00:13 -0700 | [diff] [blame] | 43 | kNullCheckOut0, // Null check out outgoing arg0 |
| 44 | kDstNonNull, // May assume dst is non-null |
| 45 | kRetNonNull, // May assume retval is non-null |
| 46 | kNullTransferSrc0, // Object copy src[0] -> dst |
| 47 | kNullTransferSrcN, // Phi null check state transfer |
buzbee | 239c4e7 | 2012-03-16 08:42:29 -0700 | [diff] [blame^] | 48 | kRangeCheckSrc1, // Range check of uses[1] |
| 49 | kRangeCheckSrc2, // Range check of uses[2] |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 50 | kFPA, |
| 51 | kFPB, |
| 52 | kFPC, |
buzbee | 67bc236 | 2011-10-11 18:08:40 -0700 | [diff] [blame] | 53 | kCoreA, |
| 54 | kCoreB, |
| 55 | kCoreC, |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 56 | kGetter, |
| 57 | kSetter, |
Elliott Hughes | 719ace4 | 2012-03-09 18:06:03 -0800 | [diff] [blame] | 58 | }; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 59 | |
| 60 | #define DF_NOP 0 |
| 61 | #define DF_UA (1 << kUA) |
| 62 | #define DF_UB (1 << kUB) |
| 63 | #define DF_UC (1 << kUC) |
| 64 | #define DF_UA_WIDE (1 << kUAWide) |
| 65 | #define DF_UB_WIDE (1 << kUBWide) |
| 66 | #define DF_UC_WIDE (1 << kUCWide) |
| 67 | #define DF_DA (1 << kDA) |
| 68 | #define DF_DA_WIDE (1 << kDAWide) |
| 69 | #define DF_IS_MOVE (1 << kIsMove) |
| 70 | #define DF_IS_LINEAR (1 << kIsLinear) |
| 71 | #define DF_SETS_CONST (1 << kSetsConst) |
| 72 | #define DF_FORMAT_35C (1 << kFormat35c) |
| 73 | #define DF_FORMAT_3RC (1 << kFormat3rc) |
| 74 | #define DF_PHI (1 << kPhi) |
buzbee | 43a3642 | 2011-09-14 14:00:13 -0700 | [diff] [blame] | 75 | #define DF_NULL_CHK_0 (1 << kNullCheckSrc0) |
| 76 | #define DF_NULL_CHK_1 (1 << kNullCheckSrc1) |
buzbee | 239c4e7 | 2012-03-16 08:42:29 -0700 | [diff] [blame^] | 77 | #define DF_NULL_CHK_2 (1 << kNullCheckSrc2) |
buzbee | 43a3642 | 2011-09-14 14:00:13 -0700 | [diff] [blame] | 78 | #define DF_NULL_CHK_OUT0 (1 << kNullCheckOut0) |
| 79 | #define DF_NON_NULL_DST (1 << kDstNonNull) |
| 80 | #define DF_NON_NULL_RET (1 << kRetNonNull) |
| 81 | #define DF_NULL_TRANSFER_0 (1 << kNullTransferSrc0) |
| 82 | #define DF_NULL_TRANSFER_N (1 << kNullTransferSrcN) |
| 83 | #define DF_RANGE_CHK_1 (1 << kRangeCheckSrc1) |
| 84 | #define DF_RANGE_CHK_2 (1 << kRangeCheckSrc2) |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 85 | #define DF_FP_A (1 << kFPA) |
| 86 | #define DF_FP_B (1 << kFPB) |
| 87 | #define DF_FP_C (1 << kFPC) |
buzbee | 67bc236 | 2011-10-11 18:08:40 -0700 | [diff] [blame] | 88 | #define DF_CORE_A (1 << kCoreA) |
| 89 | #define DF_CORE_B (1 << kCoreB) |
| 90 | #define DF_CORE_C (1 << kCoreC) |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 91 | #define DF_IS_GETTER (1 << kGetter) |
| 92 | #define DF_IS_SETTER (1 << kSetter) |
| 93 | |
| 94 | #define DF_HAS_USES (DF_UA | DF_UB | DF_UC | DF_UA_WIDE | \ |
| 95 | DF_UB_WIDE | DF_UC_WIDE) |
| 96 | |
| 97 | #define DF_HAS_DEFS (DF_DA | DF_DA_WIDE) |
| 98 | |
buzbee | 43a3642 | 2011-09-14 14:00:13 -0700 | [diff] [blame] | 99 | #define DF_HAS_NULL_CHKS (DF_NULL_CHK_0 | \ |
| 100 | DF_NULL_CHK_1 | \ |
buzbee | 239c4e7 | 2012-03-16 08:42:29 -0700 | [diff] [blame^] | 101 | DF_NULL_CHK_2 | \ |
buzbee | 43a3642 | 2011-09-14 14:00:13 -0700 | [diff] [blame] | 102 | DF_NULL_CHK_OUT0) |
| 103 | |
| 104 | #define DF_HAS_NR_CHKS (DF_HAS_NULL_CHKS | \ |
| 105 | DF_RANGE_CHK_1 | \ |
| 106 | DF_RANGE_CHK_2) |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 107 | |
| 108 | #define DF_A_IS_REG (DF_UA | DF_UA_WIDE | DF_DA | DF_DA_WIDE) |
| 109 | #define DF_B_IS_REG (DF_UB | DF_UB_WIDE) |
| 110 | #define DF_C_IS_REG (DF_UC | DF_UC_WIDE) |
| 111 | #define DF_IS_GETTER_OR_SETTER (DF_IS_GETTER | DF_IS_SETTER) |
buzbee | 99ba964 | 2012-01-25 14:23:14 -0800 | [diff] [blame] | 112 | #define DF_USES_FP (DF_FP_A | DF_FP_B | DF_FP_C) |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 113 | |
buzbee | ba938cb | 2012-02-03 14:47:55 -0800 | [diff] [blame] | 114 | extern const int oatDataFlowAttributes[kMirOpLast]; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 115 | |
Elliott Hughes | 719ace4 | 2012-03-09 18:06:03 -0800 | [diff] [blame] | 116 | struct BasicBlockDataFlow { |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 117 | ArenaBitVector* useV; |
| 118 | ArenaBitVector* defV; |
| 119 | ArenaBitVector* liveInV; |
| 120 | ArenaBitVector* phiV; |
buzbee | e196567 | 2012-03-11 18:39:19 -0700 | [diff] [blame] | 121 | int* vRegToSSAMap; |
buzbee | 43a3642 | 2011-09-14 14:00:13 -0700 | [diff] [blame] | 122 | ArenaBitVector* endingNullCheckV; |
Elliott Hughes | 719ace4 | 2012-03-09 18:06:03 -0800 | [diff] [blame] | 123 | }; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 124 | |
Elliott Hughes | 719ace4 | 2012-03-09 18:06:03 -0800 | [diff] [blame] | 125 | struct SSARepresentation { |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 126 | int numUses; |
| 127 | int* uses; |
| 128 | bool* fpUse; |
| 129 | int numDefs; |
| 130 | int* defs; |
| 131 | bool* fpDef; |
Elliott Hughes | 719ace4 | 2012-03-09 18:06:03 -0800 | [diff] [blame] | 132 | }; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 133 | |
| 134 | /* |
| 135 | * An induction variable is represented by "m*i + c", where i is a basic |
| 136 | * induction variable. |
| 137 | */ |
Elliott Hughes | 719ace4 | 2012-03-09 18:06:03 -0800 | [diff] [blame] | 138 | struct InductionVariableInfo { |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 139 | int ssaReg; |
| 140 | int basicSSAReg; |
| 141 | int m; // multiplier |
| 142 | int c; // constant |
Ian Rogers | 408f79a | 2011-08-23 18:22:33 -0700 | [diff] [blame] | 143 | int inc; // loop increment |
Elliott Hughes | 719ace4 | 2012-03-09 18:06:03 -0800 | [diff] [blame] | 144 | }; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 145 | |
Elliott Hughes | 719ace4 | 2012-03-09 18:06:03 -0800 | [diff] [blame] | 146 | struct ArrayAccessInfo { |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 147 | int arrayReg; |
| 148 | int ivReg; |
| 149 | int maxC; // For DIV - will affect upper bound checking |
| 150 | int minC; // For DIV - will affect lower bound checking |
Elliott Hughes | 719ace4 | 2012-03-09 18:06:03 -0800 | [diff] [blame] | 151 | }; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 152 | |
buzbee | 239c4e7 | 2012-03-16 08:42:29 -0700 | [diff] [blame^] | 153 | struct LoopInfo { |
| 154 | BasicBlock* header; |
| 155 | GrowableList incomingBackEdges; |
| 156 | ArenaBitVector* blocks; |
| 157 | }; |
| 158 | |
| 159 | void oatMethodLoopDetection(CompilationUnit*); |
| 160 | |
| 161 | void oatMethodUseCount(CompilationUnit*); |
| 162 | |
buzbee | 43a3642 | 2011-09-14 14:00:13 -0700 | [diff] [blame] | 163 | void oatMethodNullCheckElimination(CompilationUnit*); |
| 164 | |
buzbee | e196567 | 2012-03-11 18:39:19 -0700 | [diff] [blame] | 165 | void oatMethodBasicBlockOptimization(CompilationUnit*); |
| 166 | |
Elliott Hughes | 11d1b0c | 2012-01-23 16:57:47 -0800 | [diff] [blame] | 167 | } // namespace art |
| 168 | |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 169 | #endif // ART_SRC_COMPILER_DATAFLOW_H_ |