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