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