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