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