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 | |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 20 | #include "compiler_internals.h" |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 21 | |
Elliott Hughes | 11d1b0c | 2012-01-23 16:57:47 -0800 | [diff] [blame] | 22 | namespace art { |
| 23 | |
Elliott Hughes | 719ace4 | 2012-03-09 18:06:03 -0800 | [diff] [blame] | 24 | enum DataFlowAttributePos { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 25 | kUA = 0, |
| 26 | kUB, |
| 27 | kUC, |
buzbee | bff2465 | 2012-05-06 16:22:05 -0700 | [diff] [blame] | 28 | kAWide, |
| 29 | kBWide, |
| 30 | kCWide, |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 31 | kDA, |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 32 | kIsMove, |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 33 | kSetsConst, |
| 34 | kFormat35c, |
| 35 | kFormat3rc, |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 36 | 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]. |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 47 | kFPA, |
| 48 | kFPB, |
| 49 | kFPC, |
| 50 | kCoreA, |
| 51 | kCoreB, |
| 52 | kCoreC, |
buzbee | bff2465 | 2012-05-06 16:22:05 -0700 | [diff] [blame] | 53 | kRefA, |
| 54 | kRefB, |
| 55 | kRefC, |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 56 | kUsesMethodStar, // Implicit use of Method*. |
Elliott Hughes | 719ace4 | 2012-03-09 18:06:03 -0800 | [diff] [blame] | 57 | }; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 58 | |
| 59 | #define DF_NOP 0 |
| 60 | #define DF_UA (1 << kUA) |
| 61 | #define DF_UB (1 << kUB) |
| 62 | #define DF_UC (1 << kUC) |
buzbee | bff2465 | 2012-05-06 16:22:05 -0700 | [diff] [blame] | 63 | #define DF_A_WIDE (1 << kAWide) |
| 64 | #define DF_B_WIDE (1 << kBWide) |
| 65 | #define DF_C_WIDE (1 << kCWide) |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 66 | #define DF_DA (1 << kDA) |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 67 | #define DF_IS_MOVE (1 << kIsMove) |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 68 | #define DF_SETS_CONST (1 << kSetsConst) |
| 69 | #define DF_FORMAT_35C (1 << kFormat35c) |
| 70 | #define DF_FORMAT_3RC (1 << kFormat3rc) |
buzbee | 43a3642 | 2011-09-14 14:00:13 -0700 | [diff] [blame] | 71 | #define DF_NULL_CHK_0 (1 << kNullCheckSrc0) |
| 72 | #define DF_NULL_CHK_1 (1 << kNullCheckSrc1) |
buzbee | 239c4e7 | 2012-03-16 08:42:29 -0700 | [diff] [blame] | 73 | #define DF_NULL_CHK_2 (1 << kNullCheckSrc2) |
buzbee | 43a3642 | 2011-09-14 14:00:13 -0700 | [diff] [blame] | 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) |
buzbee | 9c044ce | 2012-03-18 13:24:07 -0700 | [diff] [blame] | 81 | #define DF_RANGE_CHK_3 (1 << kRangeCheckSrc3) |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 82 | #define DF_FP_A (1 << kFPA) |
| 83 | #define DF_FP_B (1 << kFPB) |
| 84 | #define DF_FP_C (1 << kFPC) |
buzbee | 67bc236 | 2011-10-11 18:08:40 -0700 | [diff] [blame] | 85 | #define DF_CORE_A (1 << kCoreA) |
| 86 | #define DF_CORE_B (1 << kCoreB) |
| 87 | #define DF_CORE_C (1 << kCoreC) |
buzbee | bff2465 | 2012-05-06 16:22:05 -0700 | [diff] [blame] | 88 | #define DF_REF_A (1 << kRefA) |
| 89 | #define DF_REF_B (1 << kRefB) |
| 90 | #define DF_REF_C (1 << kRefC) |
buzbee | 9c044ce | 2012-03-18 13:24:07 -0700 | [diff] [blame] | 91 | #define DF_UMS (1 << kUsesMethodStar) |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 92 | |
buzbee | bff2465 | 2012-05-06 16:22:05 -0700 | [diff] [blame] | 93 | #define DF_HAS_USES (DF_UA | DF_UB | DF_UC) |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 94 | |
buzbee | bff2465 | 2012-05-06 16:22:05 -0700 | [diff] [blame] | 95 | #define DF_HAS_DEFS (DF_DA) |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 96 | |
buzbee | 43a3642 | 2011-09-14 14:00:13 -0700 | [diff] [blame] | 97 | #define DF_HAS_NULL_CHKS (DF_NULL_CHK_0 | \ |
| 98 | DF_NULL_CHK_1 | \ |
buzbee | 239c4e7 | 2012-03-16 08:42:29 -0700 | [diff] [blame] | 99 | DF_NULL_CHK_2 | \ |
buzbee | 43a3642 | 2011-09-14 14:00:13 -0700 | [diff] [blame] | 100 | DF_NULL_CHK_OUT0) |
| 101 | |
buzbee | d1643e4 | 2012-09-05 14:06:51 -0700 | [diff] [blame] | 102 | #define DF_HAS_RANGE_CHKS (DF_RANGE_CHK_1 | \ |
buzbee | b7574cf | 2012-09-10 11:04:09 -0700 | [diff] [blame] | 103 | DF_RANGE_CHK_2 | \ |
| 104 | DF_RANGE_CHK_3) |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 105 | |
buzbee | d1643e4 | 2012-09-05 14:06:51 -0700 | [diff] [blame] | 106 | #define DF_HAS_NR_CHKS (DF_HAS_NULL_CHKS | \ |
| 107 | DF_HAS_RANGE_CHKS) |
| 108 | |
buzbee | bff2465 | 2012-05-06 16:22:05 -0700 | [diff] [blame] | 109 | #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) |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 112 | #define DF_IS_GETTER_OR_SETTER (DF_IS_GETTER | DF_IS_SETTER) |
buzbee | 99ba964 | 2012-01-25 14:23:14 -0800 | [diff] [blame] | 113 | #define DF_USES_FP (DF_FP_A | DF_FP_B | DF_FP_C) |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 114 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 115 | extern const int oat_data_flow_attributes[kMirOpLast]; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 116 | |
Elliott Hughes | 719ace4 | 2012-03-09 18:06:03 -0800 | [diff] [blame] | 117 | struct BasicBlockDataFlow { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 118 | ArenaBitVector* use_v; |
| 119 | ArenaBitVector* def_v; |
| 120 | ArenaBitVector* live_in_v; |
| 121 | ArenaBitVector* phi_v; |
| 122 | int* vreg_to_ssa_map; |
| 123 | ArenaBitVector* ending_null_check_v; |
Elliott Hughes | 719ace4 | 2012-03-09 18:06:03 -0800 | [diff] [blame] | 124 | }; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 125 | |
Elliott Hughes | 719ace4 | 2012-03-09 18:06:03 -0800 | [diff] [blame] | 126 | struct SSARepresentation { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 127 | int num_uses; |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 128 | int* uses; |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 129 | bool* fp_use; |
| 130 | int num_defs; |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 131 | int* defs; |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 132 | bool* fp_def; |
Elliott Hughes | 719ace4 | 2012-03-09 18:06:03 -0800 | [diff] [blame] | 133 | }; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 134 | |
| 135 | /* |
| 136 | * An induction variable is represented by "m*i + c", where i is a basic |
| 137 | * induction variable. |
| 138 | */ |
Elliott Hughes | 719ace4 | 2012-03-09 18:06:03 -0800 | [diff] [blame] | 139 | struct InductionVariableInfo { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 140 | int ssa_reg; |
| 141 | int basic_ssa_reg; |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 142 | int m; // multiplier |
| 143 | int c; // constant |
| 144 | int inc; // loop increment |
Elliott Hughes | 719ace4 | 2012-03-09 18:06:03 -0800 | [diff] [blame] | 145 | }; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 146 | |
Elliott Hughes | 719ace4 | 2012-03-09 18:06:03 -0800 | [diff] [blame] | 147 | struct ArrayAccessInfo { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 148 | int array_reg; |
| 149 | int iv_reg; |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 150 | int max_c; // For DIV - will affect upper bound checking. |
| 151 | int min_c; // For DIV - will affect lower bound checking. |
Elliott Hughes | 719ace4 | 2012-03-09 18:06:03 -0800 | [diff] [blame] | 152 | }; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 153 | |
buzbee | 239c4e7 | 2012-03-16 08:42:29 -0700 | [diff] [blame] | 154 | struct LoopInfo { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 155 | BasicBlock* header; |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 156 | GrowableList incoming_back_edges; |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 157 | ArenaBitVector* blocks; |
buzbee | 239c4e7 | 2012-03-16 08:42:29 -0700 | [diff] [blame] | 158 | }; |
| 159 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 160 | int SRegToVReg(const CompilationUnit* cu, int ssa_reg); |
buzbee | a169e1d | 2012-12-05 14:26:44 -0800 | [diff] [blame] | 161 | char* GetDalvikDisassembly(CompilationUnit* cu, const MIR* mir); |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 162 | bool FindLocalLiveIn(CompilationUnit* cu, BasicBlock* bb); |
| 163 | bool DoSSAConversion(CompilationUnit* cu, BasicBlock* bb); |
| 164 | bool DoConstantPropogation(CompilationUnit* cu, BasicBlock* bb); |
| 165 | void CompilerInitializeSSAConversion(CompilationUnit* cu); |
| 166 | bool ClearVisitedFlag(struct CompilationUnit* cu, struct BasicBlock* bb); |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 167 | void DataFlowAnalysisDispatcher(CompilationUnit* cu, bool (*func)(CompilationUnit*, BasicBlock*), |
| 168 | DataFlowAnalysisMode dfa_mode, bool is_iterative); |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 169 | MIR* FindMoveResult(CompilationUnit* cu, BasicBlock* bb, MIR* mir); |
| 170 | void NullCheckElimination(CompilationUnit *cu); |
| 171 | void BasicBlockCombine(CompilationUnit* cu); |
| 172 | void CodeLayout(CompilationUnit* cu); |
| 173 | void DumpCheckStats(CompilationUnit *cu); |
| 174 | void BasicBlockOptimization(CompilationUnit *cu); |
| 175 | void LoopDetection(CompilationUnit *cu); |
| 176 | void MethodUseCount(CompilationUnit *cu); |
buzbee | e196567 | 2012-03-11 18:39:19 -0700 | [diff] [blame] | 177 | |
Elliott Hughes | 11d1b0c | 2012-01-23 16:57:47 -0800 | [diff] [blame] | 178 | } // namespace art |
| 179 | |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 180 | #endif // ART_SRC_COMPILER_DATAFLOW_H_ |