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