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_COMPILER_IR_H_ |
| 18 | #define ART_SRC_COMPILER_COMPILER_IR_H_ |
| 19 | |
| 20 | #include "codegen/Optimizer.h" |
Ian Rogers | 1bddec3 | 2012-02-04 12:27:34 -0800 | [diff] [blame] | 21 | #include "CompilerUtility.h" |
buzbee | c143c55 | 2011-08-20 17:38:58 -0700 | [diff] [blame] | 22 | #include <vector> |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 23 | #include "oat_compilation_unit.h" |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 24 | |
Elliott Hughes | 11d1b0c | 2012-01-23 16:57:47 -0800 | [diff] [blame] | 25 | namespace art { |
| 26 | |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 27 | #define SLOW_FIELD_PATH (cUnit->enableDebug & (1 << kDebugSlowFieldPath)) |
| 28 | #define SLOW_INVOKE_PATH (cUnit->enableDebug & (1 << kDebugSlowInvokePath)) |
| 29 | #define SLOW_STRING_PATH (cUnit->enableDebug & (1 << kDebugSlowStringPath)) |
| 30 | #define SLOW_TYPE_PATH (cUnit->enableDebug & (1 << kDebugSlowTypePath)) |
| 31 | #define EXERCISE_SLOWEST_FIELD_PATH (cUnit->enableDebug & \ |
| 32 | (1 << kDebugSlowestFieldPath)) |
| 33 | #define EXERCISE_SLOWEST_STRING_PATH (cUnit->enableDebug & \ |
| 34 | (1 << kDebugSlowestStringPath)) |
| 35 | #define EXERCISE_RESOLVE_METHOD (cUnit->enableDebug & \ |
| 36 | (1 << kDebugExerciseResolveMethod)) |
| 37 | |
Elliott Hughes | 719ace4 | 2012-03-09 18:06:03 -0800 | [diff] [blame] | 38 | enum RegisterClass { |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 39 | kCoreReg, |
| 40 | kFPReg, |
| 41 | kAnyReg, |
Elliott Hughes | 719ace4 | 2012-03-09 18:06:03 -0800 | [diff] [blame] | 42 | }; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 43 | |
Elliott Hughes | 719ace4 | 2012-03-09 18:06:03 -0800 | [diff] [blame] | 44 | enum RegLocationType { |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 45 | kLocDalvikFrame = 0, // Normal Dalvik register |
| 46 | kLocPhysReg, |
buzbee | e196567 | 2012-03-11 18:39:19 -0700 | [diff] [blame] | 47 | kLocCompilerTemp, |
Elliott Hughes | 719ace4 | 2012-03-09 18:06:03 -0800 | [diff] [blame] | 48 | }; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 49 | |
Elliott Hughes | 719ace4 | 2012-03-09 18:06:03 -0800 | [diff] [blame] | 50 | struct PromotionMap { |
buzbee | 67bc236 | 2011-10-11 18:08:40 -0700 | [diff] [blame] | 51 | RegLocationType coreLocation:3; |
| 52 | u1 coreReg; |
| 53 | RegLocationType fpLocation:3; |
| 54 | u1 fpReg; |
| 55 | bool firstInPair; |
Elliott Hughes | 719ace4 | 2012-03-09 18:06:03 -0800 | [diff] [blame] | 56 | }; |
buzbee | 67bc236 | 2011-10-11 18:08:40 -0700 | [diff] [blame] | 57 | |
Elliott Hughes | 719ace4 | 2012-03-09 18:06:03 -0800 | [diff] [blame] | 58 | struct RegLocation { |
buzbee | 67bc236 | 2011-10-11 18:08:40 -0700 | [diff] [blame] | 59 | RegLocationType location:3; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 60 | unsigned wide:1; |
buzbee | 67bc236 | 2011-10-11 18:08:40 -0700 | [diff] [blame] | 61 | unsigned defined:1; // Do we know the type? |
| 62 | unsigned fp:1; // Floating point? |
| 63 | unsigned core:1; // Non-floating point? |
| 64 | unsigned highWord:1; // High word of pair? |
| 65 | unsigned home:1; // Does this represent the home location? |
| 66 | u1 lowReg; // First physical register |
| 67 | u1 highReg; // 2nd physical register (if wide) |
buzbee | e196567 | 2012-03-11 18:39:19 -0700 | [diff] [blame] | 68 | int32_t sRegLow; // SSA name for low Dalvik word |
| 69 | }; |
| 70 | |
| 71 | struct CompilerTemp { |
| 72 | int sReg; |
| 73 | ArenaBitVector* bv; |
Elliott Hughes | 719ace4 | 2012-03-09 18:06:03 -0800 | [diff] [blame] | 74 | }; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 75 | |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 76 | /* |
| 77 | * Data structure tracking the mapping between a Dalvik register (pair) and a |
| 78 | * native register (pair). The idea is to reuse the previously loaded value |
| 79 | * if possible, otherwise to keep the value in a native register as long as |
| 80 | * possible. |
| 81 | */ |
Elliott Hughes | 719ace4 | 2012-03-09 18:06:03 -0800 | [diff] [blame] | 82 | struct RegisterInfo { |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 83 | int reg; // Reg number |
| 84 | bool inUse; // Has it been allocated? |
| 85 | bool isTemp; // Can allocate as temp? |
| 86 | bool pair; // Part of a register pair? |
| 87 | int partner; // If pair, other reg of pair |
| 88 | bool live; // Is there an associated SSA name? |
| 89 | bool dirty; // If live, is it dirty? |
| 90 | int sReg; // Name of live value |
| 91 | struct LIR *defStart; // Starting inst in last def sequence |
| 92 | struct LIR *defEnd; // Ending inst in last def sequence |
Elliott Hughes | 719ace4 | 2012-03-09 18:06:03 -0800 | [diff] [blame] | 93 | }; |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 94 | |
Elliott Hughes | 719ace4 | 2012-03-09 18:06:03 -0800 | [diff] [blame] | 95 | struct RegisterPool { |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 96 | int numCoreRegs; |
| 97 | RegisterInfo *coreRegs; |
| 98 | int nextCoreReg; |
| 99 | int numFPRegs; |
| 100 | RegisterInfo *FPRegs; |
| 101 | int nextFPReg; |
Elliott Hughes | 719ace4 | 2012-03-09 18:06:03 -0800 | [diff] [blame] | 102 | }; |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 103 | |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 104 | #define INVALID_SREG (-1) |
buzbee | 3ddc0d1 | 2011-10-05 10:36:21 -0700 | [diff] [blame] | 105 | #define INVALID_VREG (0xFFFFU) |
buzbee | 67bc236 | 2011-10-11 18:08:40 -0700 | [diff] [blame] | 106 | #define INVALID_REG (0xFF) |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 107 | #define INVALID_OFFSET (-1) |
| 108 | |
buzbee | e196567 | 2012-03-11 18:39:19 -0700 | [diff] [blame] | 109 | /* SSA encodings for special registers */ |
| 110 | #define SSA_METHOD_BASEREG (-1) |
| 111 | /* First compiler temp basereg, grows smaller */ |
| 112 | #define SSA_CTEMP_BASEREG (-2) |
| 113 | |
buzbee | 99ba964 | 2012-01-25 14:23:14 -0800 | [diff] [blame] | 114 | /* |
| 115 | * Some code patterns cause the generation of excessively large |
| 116 | * methods - in particular initialization sequences. There isn't much |
| 117 | * benefit in optimizing these methods, and the cost can be very high. |
| 118 | * We attempt to identify these cases, and avoid performing most dataflow |
| 119 | * analysis. Two thresholds are used - one for known initializers and one |
buzbee | 5abfa3e | 2012-01-31 17:01:43 -0800 | [diff] [blame] | 120 | * for everything else. |
buzbee | 99ba964 | 2012-01-25 14:23:14 -0800 | [diff] [blame] | 121 | */ |
buzbee | 5abfa3e | 2012-01-31 17:01:43 -0800 | [diff] [blame] | 122 | #define MANY_BLOCKS_INITIALIZER 1000 /* Threshold for switching dataflow off */ |
| 123 | #define MANY_BLOCKS 4000 /* Non-initializer threshold */ |
buzbee | 99ba964 | 2012-01-25 14:23:14 -0800 | [diff] [blame] | 124 | |
Elliott Hughes | 719ace4 | 2012-03-09 18:06:03 -0800 | [diff] [blame] | 125 | enum BBType { |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 126 | kEntryBlock, |
| 127 | kDalvikByteCode, |
| 128 | kExitBlock, |
| 129 | kExceptionHandling, |
| 130 | kCatchEntry, |
Elliott Hughes | 719ace4 | 2012-03-09 18:06:03 -0800 | [diff] [blame] | 131 | }; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 132 | |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 133 | /* Utility macros to traverse the LIR list */ |
| 134 | #define NEXT_LIR(lir) (lir->next) |
| 135 | #define PREV_LIR(lir) (lir->prev) |
| 136 | |
| 137 | #define NEXT_LIR_LVALUE(lir) (lir)->next |
| 138 | #define PREV_LIR_LVALUE(lir) (lir)->prev |
| 139 | |
Elliott Hughes | 719ace4 | 2012-03-09 18:06:03 -0800 | [diff] [blame] | 140 | struct LIR { |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 141 | int offset; // Offset of this instruction |
| 142 | int dalvikOffset; // Offset of Dalvik opcode |
| 143 | struct LIR* next; |
| 144 | struct LIR* prev; |
| 145 | struct LIR* target; |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 146 | int opcode; |
Ian Rogers | b5d09b2 | 2012-03-06 22:14:17 -0800 | [diff] [blame] | 147 | int operands[5]; // [0..4] = [dest, src1, src2, extra, extra2] |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 148 | struct { |
| 149 | bool isNop:1; // LIR is optimized away |
| 150 | bool pcRelFixup:1; // May need pc-relative fixup |
| 151 | unsigned int age:4; // default is 0, set lazily by the optimizer |
buzbee | 71ac994 | 2012-03-01 17:23:10 -0800 | [diff] [blame] | 152 | unsigned int size:5; // in bytes |
| 153 | unsigned int unused:21; |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 154 | } flags; |
| 155 | int aliasInfo; // For Dalvik register & litpool disambiguation |
| 156 | u8 useMask; // Resource mask for use |
| 157 | u8 defMask; // Resource mask for def |
Elliott Hughes | 719ace4 | 2012-03-09 18:06:03 -0800 | [diff] [blame] | 158 | }; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 159 | |
| 160 | enum ExtendedMIROpcode { |
| 161 | kMirOpFirst = kNumPackedOpcodes, |
| 162 | kMirOpPhi = kMirOpFirst, |
| 163 | kMirOpNullNRangeUpCheck, |
| 164 | kMirOpNullNRangeDownCheck, |
| 165 | kMirOpLowerBound, |
buzbee | e196567 | 2012-03-11 18:39:19 -0700 | [diff] [blame] | 166 | kMirOpCopy, |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 167 | kMirOpLast, |
| 168 | }; |
| 169 | |
| 170 | struct SSARepresentation; |
| 171 | |
Elliott Hughes | 719ace4 | 2012-03-09 18:06:03 -0800 | [diff] [blame] | 172 | enum MIROptimizationFlagPositons { |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 173 | kMIRIgnoreNullCheck = 0, |
| 174 | kMIRNullCheckOnly, |
| 175 | kMIRIgnoreRangeCheck, |
| 176 | kMIRRangeCheckOnly, |
| 177 | kMIRInlined, // Invoke is inlined (ie dead) |
| 178 | kMIRInlinedPred, // Invoke is inlined via prediction |
| 179 | kMIRCallee, // Instruction is inlined from callee |
buzbee | c1f4504 | 2011-09-21 16:03:19 -0700 | [diff] [blame] | 180 | kMIRIgnoreSuspendCheck, |
buzbee | e196567 | 2012-03-11 18:39:19 -0700 | [diff] [blame] | 181 | kMIRDup, |
buzbee | 239c4e7 | 2012-03-16 08:42:29 -0700 | [diff] [blame] | 182 | kMIRMark, // Temporary node mark |
Elliott Hughes | 719ace4 | 2012-03-09 18:06:03 -0800 | [diff] [blame] | 183 | }; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 184 | |
| 185 | #define MIR_IGNORE_NULL_CHECK (1 << kMIRIgnoreNullCheck) |
| 186 | #define MIR_NULL_CHECK_ONLY (1 << kMIRNullCheckOnly) |
| 187 | #define MIR_IGNORE_RANGE_CHECK (1 << kMIRIgnoreRangeCheck) |
| 188 | #define MIR_RANGE_CHECK_ONLY (1 << kMIRRangeCheckOnly) |
| 189 | #define MIR_INLINED (1 << kMIRInlined) |
| 190 | #define MIR_INLINED_PRED (1 << kMIRInlinedPred) |
| 191 | #define MIR_CALLEE (1 << kMIRCallee) |
buzbee | c1f4504 | 2011-09-21 16:03:19 -0700 | [diff] [blame] | 192 | #define MIR_IGNORE_SUSPEND_CHECK (1 << kMIRIgnoreSuspendCheck) |
buzbee | e196567 | 2012-03-11 18:39:19 -0700 | [diff] [blame] | 193 | #define MIR_DUP (1 << kMIRDup) |
buzbee | 239c4e7 | 2012-03-16 08:42:29 -0700 | [diff] [blame] | 194 | #define MIR_MARK (1 << kMIRMark) |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 195 | |
Elliott Hughes | 719ace4 | 2012-03-09 18:06:03 -0800 | [diff] [blame] | 196 | struct CallsiteInfo { |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 197 | const char* classDescriptor; |
| 198 | Object* classLoader; |
| 199 | const Method* method; |
| 200 | LIR* misPredBranchOver; |
Elliott Hughes | 719ace4 | 2012-03-09 18:06:03 -0800 | [diff] [blame] | 201 | }; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 202 | |
Elliott Hughes | 719ace4 | 2012-03-09 18:06:03 -0800 | [diff] [blame] | 203 | struct MIR { |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 204 | DecodedInstruction dalvikInsn; |
| 205 | unsigned int width; |
| 206 | unsigned int offset; |
| 207 | struct MIR* prev; |
| 208 | struct MIR* next; |
| 209 | struct SSARepresentation* ssaRep; |
buzbee | 43a3642 | 2011-09-14 14:00:13 -0700 | [diff] [blame] | 210 | int optimizationFlags; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 211 | int seqNum; |
| 212 | union { |
| 213 | // Used by the inlined insn from the callee to find the mother method |
| 214 | const Method* calleeMethod; |
| 215 | // Used by the inlined invoke to find the class and method pointers |
| 216 | CallsiteInfo* callsiteInfo; |
buzbee | c0ecd65 | 2011-09-25 18:11:54 -0700 | [diff] [blame] | 217 | // Used to quickly locate all Phi opcodes |
| 218 | struct MIR* phiNext; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 219 | } meta; |
Elliott Hughes | 719ace4 | 2012-03-09 18:06:03 -0800 | [diff] [blame] | 220 | }; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 221 | |
| 222 | struct BasicBlockDataFlow; |
| 223 | |
| 224 | /* For successorBlockList */ |
Elliott Hughes | 719ace4 | 2012-03-09 18:06:03 -0800 | [diff] [blame] | 225 | enum BlockListType { |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 226 | kNotUsed = 0, |
| 227 | kCatch, |
| 228 | kPackedSwitch, |
| 229 | kSparseSwitch, |
Elliott Hughes | 719ace4 | 2012-03-09 18:06:03 -0800 | [diff] [blame] | 230 | }; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 231 | |
Elliott Hughes | 719ace4 | 2012-03-09 18:06:03 -0800 | [diff] [blame] | 232 | struct BasicBlock { |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 233 | int id; |
buzbee | 5b53710 | 2012-01-17 17:33:47 -0800 | [diff] [blame] | 234 | int dfsId; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 235 | bool visited; |
| 236 | bool hidden; |
buzbee | 43a3642 | 2011-09-14 14:00:13 -0700 | [diff] [blame] | 237 | bool catchEntry; |
buzbee | e196567 | 2012-03-11 18:39:19 -0700 | [diff] [blame] | 238 | bool fallThroughTarget; // Reached via fallthrough |
buzbee | 239c4e7 | 2012-03-16 08:42:29 -0700 | [diff] [blame] | 239 | uint16_t startOffset; |
| 240 | uint16_t nestingDepth; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 241 | const Method* containingMethod; // For blocks from the callee |
| 242 | BBType blockType; |
| 243 | bool needFallThroughBranch; // For blocks ended due to length limit |
| 244 | bool isFallThroughFromInvoke; // True means the block needs alignment |
| 245 | MIR* firstMIRInsn; |
| 246 | MIR* lastMIRInsn; |
| 247 | struct BasicBlock* fallThrough; |
| 248 | struct BasicBlock* taken; |
| 249 | struct BasicBlock* iDom; // Immediate dominator |
| 250 | struct BasicBlockDataFlow* dataFlowInfo; |
buzbee | 5abfa3e | 2012-01-31 17:01:43 -0800 | [diff] [blame] | 251 | GrowableList* predecessors; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 252 | ArenaBitVector* dominators; |
| 253 | ArenaBitVector* iDominated; // Set nodes being immediately dominated |
| 254 | ArenaBitVector* domFrontier; // Dominance frontier |
| 255 | struct { // For one-to-many successors like |
| 256 | BlockListType blockListType; // switch and exception handling |
| 257 | GrowableList blocks; |
| 258 | } successorBlockList; |
Elliott Hughes | 719ace4 | 2012-03-09 18:06:03 -0800 | [diff] [blame] | 259 | }; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 260 | |
| 261 | /* |
| 262 | * The "blocks" field in "successorBlockList" points to an array of |
| 263 | * elements with the type "SuccessorBlockInfo". |
| 264 | * For catch blocks, key is type index for the exception. |
| 265 | * For swtich blocks, key is the case value. |
| 266 | */ |
Elliott Hughes | 719ace4 | 2012-03-09 18:06:03 -0800 | [diff] [blame] | 267 | struct SuccessorBlockInfo { |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 268 | BasicBlock* block; |
| 269 | int key; |
Elliott Hughes | 719ace4 | 2012-03-09 18:06:03 -0800 | [diff] [blame] | 270 | }; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 271 | |
| 272 | struct LoopAnalysis; |
| 273 | struct RegisterPool; |
buzbee | ba938cb | 2012-02-03 14:47:55 -0800 | [diff] [blame] | 274 | struct ArenaMemBlock; |
| 275 | struct Memstats; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 276 | |
Elliott Hughes | 719ace4 | 2012-03-09 18:06:03 -0800 | [diff] [blame] | 277 | enum AssemblerStatus { |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 278 | kSuccess, |
| 279 | kRetryAll, |
| 280 | kRetryHalve |
Elliott Hughes | 719ace4 | 2012-03-09 18:06:03 -0800 | [diff] [blame] | 281 | }; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 282 | |
buzbee | 5b53710 | 2012-01-17 17:33:47 -0800 | [diff] [blame] | 283 | #define NOTVISITED (-1) |
| 284 | |
Elliott Hughes | 719ace4 | 2012-03-09 18:06:03 -0800 | [diff] [blame] | 285 | struct CompilationUnit { |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 286 | int numInsts; |
| 287 | int numBlocks; |
| 288 | GrowableList blockList; |
Ian Rogers | 996cc58 | 2012-02-14 22:23:29 -0800 | [diff] [blame] | 289 | Compiler* compiler; // Compiler driving this compiler |
Elliott Hughes | 11d1b0c | 2012-01-23 16:57:47 -0800 | [diff] [blame] | 290 | ClassLinker* class_linker; // Linker to resolve fields and methods |
| 291 | const DexFile* dex_file; // DexFile containing the method being compiled |
| 292 | DexCache* dex_cache; // DexFile's corresponding cache |
| 293 | const ClassLoader* class_loader; // compiling method's class loader |
Ian Rogers | a3760aa | 2011-11-14 14:32:37 -0800 | [diff] [blame] | 294 | uint32_t method_idx; // compiling method's index into method_ids of DexFile |
Elliott Hughes | 11d1b0c | 2012-01-23 16:57:47 -0800 | [diff] [blame] | 295 | const DexFile::CodeItem* code_item; // compiling method's DexFile code_item |
Ian Rogers | a3760aa | 2011-11-14 14:32:37 -0800 | [diff] [blame] | 296 | uint32_t access_flags; // compiling method's access flags |
| 297 | const char* shorty; // compiling method's shorty |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 298 | LIR* firstLIRInsn; |
| 299 | LIR* lastLIRInsn; |
| 300 | LIR* literalList; // Constants |
Ian Rogers | 3fa1379 | 2012-03-18 15:53:45 -0700 | [diff] [blame^] | 301 | LIR* methodLiteralList; // Method literals requiring patching |
| 302 | LIR* codeLiteralList; // Code literals requiring patching |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 303 | LIR* classPointerList; // Relocatable |
| 304 | int numClassPointers; |
| 305 | LIR* chainCellOffsetLIR; |
buzbee | ce30293 | 2011-10-04 14:32:18 -0700 | [diff] [blame] | 306 | uint32_t disableOpt; // optControlVector flags |
| 307 | uint32_t enableDebug; // debugControlVector flags |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 308 | int headerSize; // bytes before the first code ptr |
| 309 | int dataOffset; // starting offset of literal pool |
| 310 | int totalSize; // header + code size |
| 311 | AssemblerStatus assemblerStatus; // Success or fix and retry |
| 312 | int assemblerRetries; |
Ian Rogers | ab058bb | 2012-03-11 22:19:38 -0700 | [diff] [blame] | 313 | std::vector<uint8_t> codeBuffer; |
buzbee | 4ef7652 | 2011-09-08 10:00:32 -0700 | [diff] [blame] | 314 | std::vector<uint32_t> mappingTable; |
buzbee | 3ddc0d1 | 2011-10-05 10:36:21 -0700 | [diff] [blame] | 315 | std::vector<uint16_t> coreVmapTable; |
| 316 | std::vector<uint16_t> fpVmapTable; |
buzbee | 44b412b | 2012-02-04 08:50:53 -0800 | [diff] [blame] | 317 | bool genDebugger; // Generate code for debugger |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 318 | bool printMe; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 319 | bool hasClassLiterals; // Contains class ptrs used as literals |
| 320 | bool hasLoop; // Contains a loop |
| 321 | bool hasInvoke; // Contains an invoke instruction |
| 322 | bool heapMemOp; // Mark mem ops for self verification |
| 323 | bool usesLinkRegister; // For self-verification only |
| 324 | bool methodTraceSupport; // For TraceView profiling |
| 325 | struct RegisterPool* regPool; |
| 326 | int optRound; // round number to tell an LIR's age |
Elliott Hughes | b3bd5f0 | 2012-03-08 21:05:27 -0800 | [diff] [blame] | 327 | InstructionSet instructionSet; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 328 | /* Number of total regs used in the whole cUnit after SSA transformation */ |
| 329 | int numSSARegs; |
buzbee | e196567 | 2012-03-11 18:39:19 -0700 | [diff] [blame] | 330 | /* Map SSA reg i to the base virtual register/subscript */ |
| 331 | GrowableList* ssaBaseVRegs; |
| 332 | GrowableList* ssaSubscripts; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 333 | |
| 334 | /* The following are new data structures to support SSA representations */ |
buzbee | e196567 | 2012-03-11 18:39:19 -0700 | [diff] [blame] | 335 | /* Map original Dalvik virtual reg i to the current SSA name */ |
| 336 | int* vRegToSSAMap; // length == method->registersSize |
buzbee | f0cde54 | 2011-09-13 14:55:02 -0700 | [diff] [blame] | 337 | int* SSALastDefs; // length == method->registersSize |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 338 | ArenaBitVector* isConstantV; // length == numSSAReg |
| 339 | int* constantValues; // length == numSSAReg |
buzbee | c0ecd65 | 2011-09-25 18:11:54 -0700 | [diff] [blame] | 340 | int* phiAliasMap; // length == numSSAReg |
| 341 | MIR* phiList; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 342 | |
buzbee | 239c4e7 | 2012-03-16 08:42:29 -0700 | [diff] [blame] | 343 | /* Use counts of ssa names */ |
| 344 | GrowableList useCounts; |
| 345 | |
| 346 | /* Optimization support */ |
| 347 | GrowableList loopHeaders; |
| 348 | |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 349 | /* Map SSA names to location */ |
| 350 | RegLocation* regLocation; |
| 351 | int sequenceNumber; |
| 352 | |
buzbee | 67bc236 | 2011-10-11 18:08:40 -0700 | [diff] [blame] | 353 | /* Keep track of Dalvik vReg to physical register mappings */ |
| 354 | PromotionMap* promotionMap; |
| 355 | |
buzbee | e196567 | 2012-03-11 18:39:19 -0700 | [diff] [blame] | 356 | /* SSA name for Method* */ |
| 357 | int methodSReg; |
| 358 | |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 359 | /* |
| 360 | * Set to the Dalvik PC of the switch instruction if it has more than |
| 361 | * MAX_CHAINED_SWITCH_CASES cases. |
| 362 | */ |
| 363 | const u2* switchOverflowPad; |
| 364 | |
| 365 | int numReachableBlocks; |
buzbee | e196567 | 2012-03-11 18:39:19 -0700 | [diff] [blame] | 366 | int numDalvikRegisters; // method->registersSize |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 367 | BasicBlock* entryBlock; |
| 368 | BasicBlock* exitBlock; |
| 369 | BasicBlock* curBlock; |
| 370 | BasicBlock* nextCodegenBlock; // for extended trace codegen |
| 371 | GrowableList dfsOrder; |
buzbee | 5b53710 | 2012-01-17 17:33:47 -0800 | [diff] [blame] | 372 | GrowableList dfsPostOrder; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 373 | GrowableList domPostOrderTraversal; |
buzbee | 5ade1d2 | 2011-09-09 14:44:52 -0700 | [diff] [blame] | 374 | GrowableList throwLaunchpads; |
buzbee | c1f4504 | 2011-09-21 16:03:19 -0700 | [diff] [blame] | 375 | GrowableList suspendLaunchpads; |
buzbee | e196567 | 2012-03-11 18:39:19 -0700 | [diff] [blame] | 376 | GrowableList compilerTemps; |
buzbee | 5b53710 | 2012-01-17 17:33:47 -0800 | [diff] [blame] | 377 | int* iDomList; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 378 | ArenaBitVector* tryBlockAddr; |
| 379 | ArenaBitVector** defBlockMatrix; // numDalvikRegister x numBlocks |
| 380 | ArenaBitVector* tempBlockV; |
| 381 | ArenaBitVector* tempDalvikRegisterV; |
| 382 | ArenaBitVector* tempSSARegisterV; // numSSARegs |
| 383 | bool printSSANames; |
| 384 | void* blockLabelList; |
| 385 | bool quitLoopMode; // cold path/complex bytecode |
| 386 | int preservedRegsUsed; // How many callee save regs used |
| 387 | /* |
buzbee | 5ade1d2 | 2011-09-09 14:44:52 -0700 | [diff] [blame] | 388 | * Frame layout details. |
| 389 | * NOTE: for debug support it will be necessary to add a structure |
| 390 | * to map the Dalvik virtual registers to the promoted registers. |
| 391 | * NOTE: "num" fields are in 4-byte words, "Size" and "Offset" in bytes. |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 392 | */ |
| 393 | int numIns; |
| 394 | int numOuts; |
Ian Rogers | a3760aa | 2011-11-14 14:32:37 -0800 | [diff] [blame] | 395 | int numRegs; // Unlike numDalvikRegisters, does not include ins |
buzbee | bbaf894 | 2011-10-02 13:08:29 -0700 | [diff] [blame] | 396 | int numCoreSpills; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 397 | int numFPSpills; |
buzbee | efccc56 | 2012-03-11 11:19:28 -0700 | [diff] [blame] | 398 | int numCompilerTemps; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 399 | int frameSize; |
| 400 | unsigned int coreSpillMask; |
| 401 | unsigned int fpSpillMask; |
buzbee | cefd187 | 2011-09-09 09:59:52 -0700 | [diff] [blame] | 402 | unsigned int attrs; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 403 | /* |
| 404 | * CLEANUP/RESTRUCTURE: The code generation utilities don't have a built-in |
buzbee | 03fa263 | 2011-09-20 17:10:57 -0700 | [diff] [blame] | 405 | * mechanism to propagate the original Dalvik opcode address to the |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 406 | * associated generated instructions. For the trace compiler, this wasn't |
| 407 | * necessary because the interpreter handled all throws and debugging |
| 408 | * requests. For now we'll handle this by placing the Dalvik offset |
| 409 | * in the CompilationUnit struct before codegen for each instruction. |
| 410 | * The low-level LIR creation utilites will pull it from here. Should |
| 411 | * be rewritten. |
| 412 | */ |
| 413 | int currentDalvikOffset; |
| 414 | GrowableList switchTables; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 415 | GrowableList fillArrayData; |
| 416 | const u2* insns; |
| 417 | u4 insnsSize; |
buzbee | 99ba964 | 2012-01-25 14:23:14 -0800 | [diff] [blame] | 418 | bool disableDataflow; // Skip dataflow analysis if possible |
buzbee | 5b53710 | 2012-01-17 17:33:47 -0800 | [diff] [blame] | 419 | std::map<unsigned int, BasicBlock*> blockMap; // findBlock lookup cache |
buzbee | 85d8c1e | 2012-01-27 15:52:35 -0800 | [diff] [blame] | 420 | std::map<unsigned int, LIR*> boundaryMap; // boundary lookup cache |
buzbee | 5abfa3e | 2012-01-31 17:01:43 -0800 | [diff] [blame] | 421 | int defCount; // Used to estimate number of SSA names |
buzbee | ba938cb | 2012-02-03 14:47:55 -0800 | [diff] [blame] | 422 | std::string* compilerMethodMatch; |
| 423 | bool compilerFlipMatch; |
| 424 | struct ArenaMemBlock* arenaHead; |
| 425 | struct ArenaMemBlock* currentArena; |
| 426 | int numArenaBlocks; |
| 427 | struct Memstats* mstats; |
buzbee | 3d66194 | 2012-03-14 17:37:27 -0700 | [diff] [blame] | 428 | #ifndef NDEBUG |
| 429 | /* |
| 430 | * Sanity checking for the register temp tracking. The same ssa |
| 431 | * name should never be associated with one temp register per |
| 432 | * instruction compilation. |
| 433 | */ |
| 434 | int liveSReg; |
| 435 | #endif |
Elliott Hughes | 719ace4 | 2012-03-09 18:06:03 -0800 | [diff] [blame] | 436 | }; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 437 | |
Elliott Hughes | 719ace4 | 2012-03-09 18:06:03 -0800 | [diff] [blame] | 438 | enum OpSize { |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 439 | kWord, |
| 440 | kLong, |
| 441 | kSingle, |
| 442 | kDouble, |
| 443 | kUnsignedHalf, |
| 444 | kSignedHalf, |
| 445 | kUnsignedByte, |
| 446 | kSignedByte, |
Elliott Hughes | 719ace4 | 2012-03-09 18:06:03 -0800 | [diff] [blame] | 447 | }; |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 448 | |
Elliott Hughes | 719ace4 | 2012-03-09 18:06:03 -0800 | [diff] [blame] | 449 | enum OpKind { |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 450 | kOpMov, |
| 451 | kOpMvn, |
| 452 | kOpCmp, |
| 453 | kOpLsl, |
| 454 | kOpLsr, |
| 455 | kOpAsr, |
| 456 | kOpRor, |
| 457 | kOpNot, |
| 458 | kOpAnd, |
| 459 | kOpOr, |
| 460 | kOpXor, |
| 461 | kOpNeg, |
| 462 | kOpAdd, |
| 463 | kOpAdc, |
| 464 | kOpSub, |
| 465 | kOpSbc, |
| 466 | kOpRsub, |
| 467 | kOpMul, |
| 468 | kOpDiv, |
| 469 | kOpRem, |
| 470 | kOpBic, |
| 471 | kOpCmn, |
| 472 | kOpTst, |
| 473 | kOpBkpt, |
| 474 | kOpBlx, |
| 475 | kOpPush, |
| 476 | kOpPop, |
| 477 | kOp2Char, |
| 478 | kOp2Short, |
| 479 | kOp2Byte, |
| 480 | kOpCondBr, |
| 481 | kOpUncondBr, |
buzbee | 5de3494 | 2012-03-01 14:51:57 -0800 | [diff] [blame] | 482 | kOpBx, |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 483 | kOpInvalid, |
Elliott Hughes | 719ace4 | 2012-03-09 18:06:03 -0800 | [diff] [blame] | 484 | }; |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 485 | |
Ian Rogers | 680b1bd | 2012-03-07 20:18:49 -0800 | [diff] [blame] | 486 | std::ostream& operator<<(std::ostream& os, const OpKind& kind); |
| 487 | |
Elliott Hughes | 719ace4 | 2012-03-09 18:06:03 -0800 | [diff] [blame] | 488 | enum ConditionCode { |
Ian Rogers | b5d09b2 | 2012-03-06 22:14:17 -0800 | [diff] [blame] | 489 | kCondEq, // equal |
| 490 | kCondNe, // not equal |
| 491 | kCondCs, // carry set (unsigned less than) |
| 492 | kCondUlt = kCondCs, |
| 493 | kCondCc, // carry clear (unsigned greater than or same) |
| 494 | kCondUge = kCondCc, |
| 495 | kCondMi, // minus |
| 496 | kCondPl, // plus, positive or zero |
| 497 | kCondVs, // overflow |
| 498 | kCondVc, // no overflow |
| 499 | kCondHi, // unsigned greater than |
| 500 | kCondLs, // unsigned lower or same |
| 501 | kCondGe, // signed greater than or equal |
| 502 | kCondLt, // signed less than |
| 503 | kCondGt, // signed greater than |
| 504 | kCondLe, // signed less than or equal |
| 505 | kCondAl, // always |
| 506 | kCondNv, // never |
Elliott Hughes | 719ace4 | 2012-03-09 18:06:03 -0800 | [diff] [blame] | 507 | }; |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 508 | |
Elliott Hughes | 719ace4 | 2012-03-09 18:06:03 -0800 | [diff] [blame] | 509 | enum ThrowKind { |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 510 | kThrowNullPointer, |
| 511 | kThrowDivZero, |
| 512 | kThrowArrayBounds, |
| 513 | kThrowVerificationError, |
| 514 | kThrowNegArraySize, |
| 515 | kThrowNoSuchMethod, |
| 516 | kThrowStackOverflow, |
Elliott Hughes | 719ace4 | 2012-03-09 18:06:03 -0800 | [diff] [blame] | 517 | }; |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 518 | |
Elliott Hughes | 719ace4 | 2012-03-09 18:06:03 -0800 | [diff] [blame] | 519 | struct SwitchTable { |
buzbee | 5de3494 | 2012-03-01 14:51:57 -0800 | [diff] [blame] | 520 | int offset; |
| 521 | const u2* table; // Original dex table |
| 522 | int vaddr; // Dalvik offset of switch opcode |
buzbee | c5159d5 | 2012-03-03 11:48:39 -0800 | [diff] [blame] | 523 | LIR* anchor; // Reference instruction for relative offsets |
buzbee | 5de3494 | 2012-03-01 14:51:57 -0800 | [diff] [blame] | 524 | LIR** targets; // Array of case targets |
Elliott Hughes | 719ace4 | 2012-03-09 18:06:03 -0800 | [diff] [blame] | 525 | }; |
buzbee | 5de3494 | 2012-03-01 14:51:57 -0800 | [diff] [blame] | 526 | |
Elliott Hughes | 719ace4 | 2012-03-09 18:06:03 -0800 | [diff] [blame] | 527 | struct FillArrayData { |
buzbee | 5de3494 | 2012-03-01 14:51:57 -0800 | [diff] [blame] | 528 | int offset; |
| 529 | const u2* table; // Original dex table |
| 530 | int size; |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 531 | int vaddr; // Dalvik offset of FILL_ARRAY_DATA opcode |
Elliott Hughes | 719ace4 | 2012-03-09 18:06:03 -0800 | [diff] [blame] | 532 | }; |
buzbee | 5de3494 | 2012-03-01 14:51:57 -0800 | [diff] [blame] | 533 | |
| 534 | |
buzbee | 5abfa3e | 2012-01-31 17:01:43 -0800 | [diff] [blame] | 535 | BasicBlock* oatNewBB(CompilationUnit* cUnit, BBType blockType, int blockId); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 536 | |
| 537 | void oatAppendMIR(BasicBlock* bb, MIR* mir); |
| 538 | |
| 539 | void oatPrependMIR(BasicBlock* bb, MIR* mir); |
| 540 | |
| 541 | void oatInsertMIRAfter(BasicBlock* bb, MIR* currentMIR, MIR* newMIR); |
| 542 | |
| 543 | void oatAppendLIR(CompilationUnit* cUnit, LIR* lir); |
| 544 | |
| 545 | void oatInsertLIRBefore(LIR* currentLIR, LIR* newLIR); |
| 546 | |
| 547 | void oatInsertLIRAfter(LIR* currentLIR, LIR* newLIR); |
| 548 | |
| 549 | /* Debug Utilities */ |
| 550 | void oatDumpCompilationUnit(CompilationUnit* cUnit); |
| 551 | |
Elliott Hughes | 11d1b0c | 2012-01-23 16:57:47 -0800 | [diff] [blame] | 552 | } // namespace art |
| 553 | |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 554 | #endif // ART_SRC_COMPILER_COMPILER_IR_H_ |