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