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 | |
| 20 | #include "codegen/Optimizer.h" |
Ian Rogers | 1bddec3 | 2012-02-04 12:27:34 -0800 | [diff] [blame] | 21 | #include "CompilerUtility.h" |
buzbee | c143c55 | 2011-08-20 17:38:58 -0700 | [diff] [blame] | 22 | #include <vector> |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 23 | #include "oat_compilation_unit.h" |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 24 | |
Elliott Hughes | 11d1b0c | 2012-01-23 16:57:47 -0800 | [diff] [blame] | 25 | namespace art { |
| 26 | |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 27 | #define SLOW_FIELD_PATH (cUnit->enableDebug & (1 << kDebugSlowFieldPath)) |
| 28 | #define SLOW_INVOKE_PATH (cUnit->enableDebug & (1 << kDebugSlowInvokePath)) |
| 29 | #define SLOW_STRING_PATH (cUnit->enableDebug & (1 << kDebugSlowStringPath)) |
| 30 | #define SLOW_TYPE_PATH (cUnit->enableDebug & (1 << kDebugSlowTypePath)) |
| 31 | #define EXERCISE_SLOWEST_FIELD_PATH (cUnit->enableDebug & \ |
| 32 | (1 << kDebugSlowestFieldPath)) |
| 33 | #define EXERCISE_SLOWEST_STRING_PATH (cUnit->enableDebug & \ |
| 34 | (1 << kDebugSlowestStringPath)) |
| 35 | #define EXERCISE_RESOLVE_METHOD (cUnit->enableDebug & \ |
| 36 | (1 << kDebugExerciseResolveMethod)) |
| 37 | |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 38 | typedef enum RegisterClass { |
| 39 | kCoreReg, |
| 40 | kFPReg, |
| 41 | kAnyReg, |
| 42 | } RegisterClass; |
| 43 | |
| 44 | typedef enum RegLocationType { |
| 45 | kLocDalvikFrame = 0, // Normal Dalvik register |
| 46 | kLocPhysReg, |
| 47 | kLocSpill, |
| 48 | } RegLocationType; |
| 49 | |
buzbee | 67bc236 | 2011-10-11 18:08:40 -0700 | [diff] [blame] | 50 | typedef struct PromotionMap { |
| 51 | RegLocationType coreLocation:3; |
| 52 | u1 coreReg; |
| 53 | RegLocationType fpLocation:3; |
| 54 | u1 fpReg; |
| 55 | bool firstInPair; |
| 56 | } PromotionMap; |
| 57 | |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 58 | typedef struct RegLocation { |
buzbee | 67bc236 | 2011-10-11 18:08:40 -0700 | [diff] [blame] | 59 | RegLocationType location:3; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 60 | unsigned wide:1; |
buzbee | 67bc236 | 2011-10-11 18:08:40 -0700 | [diff] [blame] | 61 | unsigned defined:1; // Do we know the type? |
| 62 | unsigned fp:1; // Floating point? |
| 63 | unsigned core:1; // Non-floating point? |
| 64 | unsigned highWord:1; // High word of pair? |
| 65 | unsigned home:1; // Does this represent the home location? |
| 66 | u1 lowReg; // First physical register |
| 67 | u1 highReg; // 2nd physical register (if wide) |
| 68 | s2 sRegLow; // SSA name for low Dalvik word |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 69 | } RegLocation; |
| 70 | |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 71 | /* |
| 72 | * Data structure tracking the mapping between a Dalvik register (pair) and a |
| 73 | * native register (pair). The idea is to reuse the previously loaded value |
| 74 | * if possible, otherwise to keep the value in a native register as long as |
| 75 | * possible. |
| 76 | */ |
| 77 | typedef struct RegisterInfo { |
| 78 | int reg; // Reg number |
| 79 | bool inUse; // Has it been allocated? |
| 80 | bool isTemp; // Can allocate as temp? |
| 81 | bool pair; // Part of a register pair? |
| 82 | int partner; // If pair, other reg of pair |
| 83 | bool live; // Is there an associated SSA name? |
| 84 | bool dirty; // If live, is it dirty? |
| 85 | int sReg; // Name of live value |
| 86 | struct LIR *defStart; // Starting inst in last def sequence |
| 87 | struct LIR *defEnd; // Ending inst in last def sequence |
| 88 | } RegisterInfo; |
| 89 | |
| 90 | typedef struct RegisterPool { |
| 91 | int numCoreRegs; |
| 92 | RegisterInfo *coreRegs; |
| 93 | int nextCoreReg; |
| 94 | int numFPRegs; |
| 95 | RegisterInfo *FPRegs; |
| 96 | int nextFPReg; |
| 97 | } RegisterPool; |
| 98 | |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 99 | #define INVALID_SREG (-1) |
buzbee | 3ddc0d1 | 2011-10-05 10:36:21 -0700 | [diff] [blame] | 100 | #define INVALID_VREG (0xFFFFU) |
buzbee | 67bc236 | 2011-10-11 18:08:40 -0700 | [diff] [blame] | 101 | #define INVALID_REG (0xFF) |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 102 | #define INVALID_OFFSET (-1) |
| 103 | |
buzbee | 99ba964 | 2012-01-25 14:23:14 -0800 | [diff] [blame] | 104 | /* |
| 105 | * Some code patterns cause the generation of excessively large |
| 106 | * methods - in particular initialization sequences. There isn't much |
| 107 | * benefit in optimizing these methods, and the cost can be very high. |
| 108 | * We attempt to identify these cases, and avoid performing most dataflow |
| 109 | * analysis. Two thresholds are used - one for known initializers and one |
buzbee | 5abfa3e | 2012-01-31 17:01:43 -0800 | [diff] [blame] | 110 | * for everything else. |
buzbee | 99ba964 | 2012-01-25 14:23:14 -0800 | [diff] [blame] | 111 | */ |
buzbee | 5abfa3e | 2012-01-31 17:01:43 -0800 | [diff] [blame] | 112 | #define MANY_BLOCKS_INITIALIZER 1000 /* Threshold for switching dataflow off */ |
| 113 | #define MANY_BLOCKS 4000 /* Non-initializer threshold */ |
buzbee | 99ba964 | 2012-01-25 14:23:14 -0800 | [diff] [blame] | 114 | |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 115 | typedef enum BBType { |
| 116 | kEntryBlock, |
| 117 | kDalvikByteCode, |
| 118 | kExitBlock, |
| 119 | kExceptionHandling, |
| 120 | kCatchEntry, |
| 121 | } BBType; |
| 122 | |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 123 | /* Utility macros to traverse the LIR list */ |
| 124 | #define NEXT_LIR(lir) (lir->next) |
| 125 | #define PREV_LIR(lir) (lir->prev) |
| 126 | |
| 127 | #define NEXT_LIR_LVALUE(lir) (lir)->next |
| 128 | #define PREV_LIR_LVALUE(lir) (lir)->prev |
| 129 | |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 130 | typedef struct LIR { |
| 131 | int offset; // Offset of this instruction |
| 132 | int dalvikOffset; // Offset of Dalvik opcode |
| 133 | struct LIR* next; |
| 134 | struct LIR* prev; |
| 135 | struct LIR* target; |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 136 | int opcode; |
| 137 | int operands[4]; // [0..3] = [dest, src1, src2, extra] |
| 138 | struct { |
| 139 | bool isNop:1; // LIR is optimized away |
| 140 | bool pcRelFixup:1; // May need pc-relative fixup |
| 141 | unsigned int age:4; // default is 0, set lazily by the optimizer |
buzbee | 71ac994 | 2012-03-01 17:23:10 -0800 | [diff] [blame^] | 142 | unsigned int size:5; // in bytes |
| 143 | unsigned int unused:21; |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 144 | } flags; |
| 145 | int aliasInfo; // For Dalvik register & litpool disambiguation |
| 146 | u8 useMask; // Resource mask for use |
| 147 | u8 defMask; // Resource mask for def |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 148 | } LIR; |
| 149 | |
| 150 | enum ExtendedMIROpcode { |
| 151 | kMirOpFirst = kNumPackedOpcodes, |
| 152 | kMirOpPhi = kMirOpFirst, |
| 153 | kMirOpNullNRangeUpCheck, |
| 154 | kMirOpNullNRangeDownCheck, |
| 155 | kMirOpLowerBound, |
| 156 | kMirOpPunt, |
| 157 | kMirOpCheckInlinePrediction, // Gen checks for predicted inlining |
| 158 | kMirOpLast, |
| 159 | }; |
| 160 | |
| 161 | struct SSARepresentation; |
| 162 | |
| 163 | typedef enum { |
| 164 | kMIRIgnoreNullCheck = 0, |
| 165 | kMIRNullCheckOnly, |
| 166 | kMIRIgnoreRangeCheck, |
| 167 | kMIRRangeCheckOnly, |
| 168 | kMIRInlined, // Invoke is inlined (ie dead) |
| 169 | kMIRInlinedPred, // Invoke is inlined via prediction |
| 170 | kMIRCallee, // Instruction is inlined from callee |
buzbee | c1f4504 | 2011-09-21 16:03:19 -0700 | [diff] [blame] | 171 | kMIRIgnoreSuspendCheck, |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 172 | } MIROptimizationFlagPositons; |
| 173 | |
| 174 | #define MIR_IGNORE_NULL_CHECK (1 << kMIRIgnoreNullCheck) |
| 175 | #define MIR_NULL_CHECK_ONLY (1 << kMIRNullCheckOnly) |
| 176 | #define MIR_IGNORE_RANGE_CHECK (1 << kMIRIgnoreRangeCheck) |
| 177 | #define MIR_RANGE_CHECK_ONLY (1 << kMIRRangeCheckOnly) |
| 178 | #define MIR_INLINED (1 << kMIRInlined) |
| 179 | #define MIR_INLINED_PRED (1 << kMIRInlinedPred) |
| 180 | #define MIR_CALLEE (1 << kMIRCallee) |
buzbee | c1f4504 | 2011-09-21 16:03:19 -0700 | [diff] [blame] | 181 | #define MIR_IGNORE_SUSPEND_CHECK (1 << kMIRIgnoreSuspendCheck) |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 182 | |
| 183 | typedef struct CallsiteInfo { |
| 184 | const char* classDescriptor; |
| 185 | Object* classLoader; |
| 186 | const Method* method; |
| 187 | LIR* misPredBranchOver; |
| 188 | } CallsiteInfo; |
| 189 | |
| 190 | typedef struct MIR { |
| 191 | DecodedInstruction dalvikInsn; |
| 192 | unsigned int width; |
| 193 | unsigned int offset; |
| 194 | struct MIR* prev; |
| 195 | struct MIR* next; |
| 196 | struct SSARepresentation* ssaRep; |
buzbee | 43a3642 | 2011-09-14 14:00:13 -0700 | [diff] [blame] | 197 | int optimizationFlags; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 198 | int seqNum; |
| 199 | union { |
| 200 | // Used by the inlined insn from the callee to find the mother method |
| 201 | const Method* calleeMethod; |
| 202 | // Used by the inlined invoke to find the class and method pointers |
| 203 | CallsiteInfo* callsiteInfo; |
buzbee | c0ecd65 | 2011-09-25 18:11:54 -0700 | [diff] [blame] | 204 | // Used to quickly locate all Phi opcodes |
| 205 | struct MIR* phiNext; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 206 | } meta; |
| 207 | } MIR; |
| 208 | |
| 209 | struct BasicBlockDataFlow; |
| 210 | |
| 211 | /* For successorBlockList */ |
| 212 | typedef enum BlockListType { |
| 213 | kNotUsed = 0, |
| 214 | kCatch, |
| 215 | kPackedSwitch, |
| 216 | kSparseSwitch, |
| 217 | } BlockListType; |
| 218 | |
| 219 | typedef struct BasicBlock { |
| 220 | int id; |
buzbee | 5b53710 | 2012-01-17 17:33:47 -0800 | [diff] [blame] | 221 | int dfsId; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 222 | bool visited; |
| 223 | bool hidden; |
buzbee | 43a3642 | 2011-09-14 14:00:13 -0700 | [diff] [blame] | 224 | bool catchEntry; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 225 | unsigned int startOffset; |
| 226 | const Method* containingMethod; // For blocks from the callee |
| 227 | BBType blockType; |
| 228 | bool needFallThroughBranch; // For blocks ended due to length limit |
| 229 | bool isFallThroughFromInvoke; // True means the block needs alignment |
| 230 | MIR* firstMIRInsn; |
| 231 | MIR* lastMIRInsn; |
| 232 | struct BasicBlock* fallThrough; |
| 233 | struct BasicBlock* taken; |
| 234 | struct BasicBlock* iDom; // Immediate dominator |
| 235 | struct BasicBlockDataFlow* dataFlowInfo; |
buzbee | 5abfa3e | 2012-01-31 17:01:43 -0800 | [diff] [blame] | 236 | GrowableList* predecessors; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 237 | ArenaBitVector* dominators; |
| 238 | ArenaBitVector* iDominated; // Set nodes being immediately dominated |
| 239 | ArenaBitVector* domFrontier; // Dominance frontier |
| 240 | struct { // For one-to-many successors like |
| 241 | BlockListType blockListType; // switch and exception handling |
| 242 | GrowableList blocks; |
| 243 | } successorBlockList; |
| 244 | } BasicBlock; |
| 245 | |
| 246 | /* |
| 247 | * The "blocks" field in "successorBlockList" points to an array of |
| 248 | * elements with the type "SuccessorBlockInfo". |
| 249 | * For catch blocks, key is type index for the exception. |
| 250 | * For swtich blocks, key is the case value. |
| 251 | */ |
| 252 | typedef struct SuccessorBlockInfo { |
| 253 | BasicBlock* block; |
| 254 | int key; |
| 255 | } SuccessorBlockInfo; |
| 256 | |
| 257 | struct LoopAnalysis; |
| 258 | struct RegisterPool; |
buzbee | ba938cb | 2012-02-03 14:47:55 -0800 | [diff] [blame] | 259 | struct ArenaMemBlock; |
| 260 | struct Memstats; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 261 | |
| 262 | typedef enum AssemblerStatus { |
| 263 | kSuccess, |
| 264 | kRetryAll, |
| 265 | kRetryHalve |
| 266 | } AssemblerStatus; |
| 267 | |
buzbee | 5b53710 | 2012-01-17 17:33:47 -0800 | [diff] [blame] | 268 | #define NOTVISITED (-1) |
| 269 | |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 270 | typedef struct CompilationUnit { |
| 271 | int numInsts; |
| 272 | int numBlocks; |
| 273 | GrowableList blockList; |
Ian Rogers | 996cc58 | 2012-02-14 22:23:29 -0800 | [diff] [blame] | 274 | Compiler* compiler; // Compiler driving this compiler |
Elliott Hughes | 11d1b0c | 2012-01-23 16:57:47 -0800 | [diff] [blame] | 275 | ClassLinker* class_linker; // Linker to resolve fields and methods |
| 276 | const DexFile* dex_file; // DexFile containing the method being compiled |
| 277 | DexCache* dex_cache; // DexFile's corresponding cache |
| 278 | const ClassLoader* class_loader; // compiling method's class loader |
Ian Rogers | a3760aa | 2011-11-14 14:32:37 -0800 | [diff] [blame] | 279 | uint32_t method_idx; // compiling method's index into method_ids of DexFile |
Elliott Hughes | 11d1b0c | 2012-01-23 16:57:47 -0800 | [diff] [blame] | 280 | const DexFile::CodeItem* code_item; // compiling method's DexFile code_item |
Ian Rogers | a3760aa | 2011-11-14 14:32:37 -0800 | [diff] [blame] | 281 | uint32_t access_flags; // compiling method's access flags |
| 282 | const char* shorty; // compiling method's shorty |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 283 | LIR* firstLIRInsn; |
| 284 | LIR* lastLIRInsn; |
| 285 | LIR* literalList; // Constants |
| 286 | LIR* classPointerList; // Relocatable |
| 287 | int numClassPointers; |
| 288 | LIR* chainCellOffsetLIR; |
buzbee | ce30293 | 2011-10-04 14:32:18 -0700 | [diff] [blame] | 289 | uint32_t disableOpt; // optControlVector flags |
| 290 | uint32_t enableDebug; // debugControlVector flags |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 291 | int headerSize; // bytes before the first code ptr |
| 292 | int dataOffset; // starting offset of literal pool |
| 293 | int totalSize; // header + code size |
| 294 | AssemblerStatus assemblerStatus; // Success or fix and retry |
| 295 | int assemblerRetries; |
Brian Carlstrom | e7d856b | 2012-01-11 18:10:55 -0800 | [diff] [blame] | 296 | std::vector<uint16_t> codeBuffer; |
buzbee | 4ef7652 | 2011-09-08 10:00:32 -0700 | [diff] [blame] | 297 | std::vector<uint32_t> mappingTable; |
buzbee | 3ddc0d1 | 2011-10-05 10:36:21 -0700 | [diff] [blame] | 298 | std::vector<uint16_t> coreVmapTable; |
| 299 | std::vector<uint16_t> fpVmapTable; |
buzbee | 44b412b | 2012-02-04 08:50:53 -0800 | [diff] [blame] | 300 | bool genDebugger; // Generate code for debugger |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 301 | bool printMe; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 302 | bool hasClassLiterals; // Contains class ptrs used as literals |
| 303 | bool hasLoop; // Contains a loop |
| 304 | bool hasInvoke; // Contains an invoke instruction |
| 305 | bool heapMemOp; // Mark mem ops for self verification |
| 306 | bool usesLinkRegister; // For self-verification only |
| 307 | bool methodTraceSupport; // For TraceView profiling |
| 308 | struct RegisterPool* regPool; |
| 309 | int optRound; // round number to tell an LIR's age |
| 310 | OatInstructionSetType instructionSet; |
| 311 | /* Number of total regs used in the whole cUnit after SSA transformation */ |
| 312 | int numSSARegs; |
| 313 | /* Map SSA reg i to the Dalvik[15..0]/Sub[31..16] pair. */ |
| 314 | GrowableList* ssaToDalvikMap; |
| 315 | |
| 316 | /* The following are new data structures to support SSA representations */ |
| 317 | /* Map original Dalvik reg i to the SSA[15..0]/Sub[31..16] pair */ |
| 318 | int* dalvikToSSAMap; // length == method->registersSize |
buzbee | f0cde54 | 2011-09-13 14:55:02 -0700 | [diff] [blame] | 319 | int* SSALastDefs; // length == method->registersSize |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 320 | ArenaBitVector* isConstantV; // length == numSSAReg |
| 321 | int* constantValues; // length == numSSAReg |
buzbee | c0ecd65 | 2011-09-25 18:11:54 -0700 | [diff] [blame] | 322 | int* phiAliasMap; // length == numSSAReg |
| 323 | MIR* phiList; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 324 | |
| 325 | /* Map SSA names to location */ |
| 326 | RegLocation* regLocation; |
| 327 | int sequenceNumber; |
| 328 | |
buzbee | 67bc236 | 2011-10-11 18:08:40 -0700 | [diff] [blame] | 329 | /* Keep track of Dalvik vReg to physical register mappings */ |
| 330 | PromotionMap* promotionMap; |
| 331 | |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 332 | /* |
| 333 | * Set to the Dalvik PC of the switch instruction if it has more than |
| 334 | * MAX_CHAINED_SWITCH_CASES cases. |
| 335 | */ |
| 336 | const u2* switchOverflowPad; |
| 337 | |
| 338 | int numReachableBlocks; |
| 339 | int numDalvikRegisters; // method->registersSize + inlined |
| 340 | BasicBlock* entryBlock; |
| 341 | BasicBlock* exitBlock; |
| 342 | BasicBlock* curBlock; |
| 343 | BasicBlock* nextCodegenBlock; // for extended trace codegen |
| 344 | GrowableList dfsOrder; |
buzbee | 5b53710 | 2012-01-17 17:33:47 -0800 | [diff] [blame] | 345 | GrowableList dfsPostOrder; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 346 | GrowableList domPostOrderTraversal; |
buzbee | 5ade1d2 | 2011-09-09 14:44:52 -0700 | [diff] [blame] | 347 | GrowableList throwLaunchpads; |
buzbee | c1f4504 | 2011-09-21 16:03:19 -0700 | [diff] [blame] | 348 | GrowableList suspendLaunchpads; |
buzbee | 5b53710 | 2012-01-17 17:33:47 -0800 | [diff] [blame] | 349 | int* iDomList; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 350 | ArenaBitVector* tryBlockAddr; |
| 351 | ArenaBitVector** defBlockMatrix; // numDalvikRegister x numBlocks |
| 352 | ArenaBitVector* tempBlockV; |
| 353 | ArenaBitVector* tempDalvikRegisterV; |
| 354 | ArenaBitVector* tempSSARegisterV; // numSSARegs |
| 355 | bool printSSANames; |
| 356 | void* blockLabelList; |
| 357 | bool quitLoopMode; // cold path/complex bytecode |
| 358 | int preservedRegsUsed; // How many callee save regs used |
| 359 | /* |
buzbee | 5ade1d2 | 2011-09-09 14:44:52 -0700 | [diff] [blame] | 360 | * Frame layout details. |
| 361 | * NOTE: for debug support it will be necessary to add a structure |
| 362 | * to map the Dalvik virtual registers to the promoted registers. |
| 363 | * NOTE: "num" fields are in 4-byte words, "Size" and "Offset" in bytes. |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 364 | */ |
| 365 | int numIns; |
| 366 | int numOuts; |
Ian Rogers | a3760aa | 2011-11-14 14:32:37 -0800 | [diff] [blame] | 367 | int numRegs; // Unlike numDalvikRegisters, does not include ins |
buzbee | bbaf894 | 2011-10-02 13:08:29 -0700 | [diff] [blame] | 368 | int numCoreSpills; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 369 | int numFPSpills; |
| 370 | int numPadding; // # of 4-byte padding cells |
| 371 | int regsOffset; // sp-relative offset to beginning of Dalvik regs |
| 372 | int insOffset; // sp-relative offset to beginning of Dalvik ins |
| 373 | int frameSize; |
| 374 | unsigned int coreSpillMask; |
| 375 | unsigned int fpSpillMask; |
buzbee | cefd187 | 2011-09-09 09:59:52 -0700 | [diff] [blame] | 376 | unsigned int attrs; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 377 | /* |
| 378 | * CLEANUP/RESTRUCTURE: The code generation utilities don't have a built-in |
buzbee | 03fa263 | 2011-09-20 17:10:57 -0700 | [diff] [blame] | 379 | * mechanism to propagate the original Dalvik opcode address to the |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 380 | * associated generated instructions. For the trace compiler, this wasn't |
| 381 | * necessary because the interpreter handled all throws and debugging |
| 382 | * requests. For now we'll handle this by placing the Dalvik offset |
| 383 | * in the CompilationUnit struct before codegen for each instruction. |
| 384 | * The low-level LIR creation utilites will pull it from here. Should |
| 385 | * be rewritten. |
| 386 | */ |
| 387 | int currentDalvikOffset; |
| 388 | GrowableList switchTables; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 389 | GrowableList fillArrayData; |
| 390 | const u2* insns; |
| 391 | u4 insnsSize; |
buzbee | 99ba964 | 2012-01-25 14:23:14 -0800 | [diff] [blame] | 392 | bool disableDataflow; // Skip dataflow analysis if possible |
buzbee | 5b53710 | 2012-01-17 17:33:47 -0800 | [diff] [blame] | 393 | std::map<unsigned int, BasicBlock*> blockMap; // findBlock lookup cache |
buzbee | 85d8c1e | 2012-01-27 15:52:35 -0800 | [diff] [blame] | 394 | std::map<unsigned int, LIR*> boundaryMap; // boundary lookup cache |
buzbee | 5abfa3e | 2012-01-31 17:01:43 -0800 | [diff] [blame] | 395 | int defCount; // Used to estimate number of SSA names |
buzbee | ba938cb | 2012-02-03 14:47:55 -0800 | [diff] [blame] | 396 | std::string* compilerMethodMatch; |
| 397 | bool compilerFlipMatch; |
| 398 | struct ArenaMemBlock* arenaHead; |
| 399 | struct ArenaMemBlock* currentArena; |
| 400 | int numArenaBlocks; |
| 401 | struct Memstats* mstats; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 402 | } CompilationUnit; |
| 403 | |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 404 | typedef enum OpSize { |
| 405 | kWord, |
| 406 | kLong, |
| 407 | kSingle, |
| 408 | kDouble, |
| 409 | kUnsignedHalf, |
| 410 | kSignedHalf, |
| 411 | kUnsignedByte, |
| 412 | kSignedByte, |
| 413 | } OpSize; |
| 414 | |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 415 | typedef enum OpKind { |
| 416 | kOpMov, |
| 417 | kOpMvn, |
| 418 | kOpCmp, |
| 419 | kOpLsl, |
| 420 | kOpLsr, |
| 421 | kOpAsr, |
| 422 | kOpRor, |
| 423 | kOpNot, |
| 424 | kOpAnd, |
| 425 | kOpOr, |
| 426 | kOpXor, |
| 427 | kOpNeg, |
| 428 | kOpAdd, |
| 429 | kOpAdc, |
| 430 | kOpSub, |
| 431 | kOpSbc, |
| 432 | kOpRsub, |
| 433 | kOpMul, |
| 434 | kOpDiv, |
| 435 | kOpRem, |
| 436 | kOpBic, |
| 437 | kOpCmn, |
| 438 | kOpTst, |
| 439 | kOpBkpt, |
| 440 | kOpBlx, |
| 441 | kOpPush, |
| 442 | kOpPop, |
| 443 | kOp2Char, |
| 444 | kOp2Short, |
| 445 | kOp2Byte, |
| 446 | kOpCondBr, |
| 447 | kOpUncondBr, |
buzbee | 5de3494 | 2012-03-01 14:51:57 -0800 | [diff] [blame] | 448 | kOpBx, |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 449 | kOpInvalid, |
| 450 | } OpKind; |
| 451 | |
| 452 | typedef enum ConditionCode { |
| 453 | kCondEq, |
| 454 | kCondNe, |
| 455 | kCondCs, |
| 456 | kCondCc, |
| 457 | kCondMi, |
| 458 | kCondPl, |
| 459 | kCondVs, |
| 460 | kCondVc, |
| 461 | kCondHi, |
| 462 | kCondLs, |
| 463 | kCondGe, |
| 464 | kCondLt, |
| 465 | kCondGt, |
| 466 | kCondLe, |
| 467 | kCondAl, |
| 468 | kCondNv, |
| 469 | } ConditionCode; |
| 470 | |
| 471 | typedef enum ThrowKind { |
| 472 | kThrowNullPointer, |
| 473 | kThrowDivZero, |
| 474 | kThrowArrayBounds, |
| 475 | kThrowVerificationError, |
| 476 | kThrowNegArraySize, |
| 477 | kThrowNoSuchMethod, |
| 478 | kThrowStackOverflow, |
| 479 | } ThrowKind; |
| 480 | |
buzbee | 5de3494 | 2012-03-01 14:51:57 -0800 | [diff] [blame] | 481 | typedef struct SwitchTable { |
| 482 | int offset; |
| 483 | const u2* table; // Original dex table |
| 484 | int vaddr; // Dalvik offset of switch opcode |
| 485 | LIR* bxInst; // Switch indirect branch instruction |
| 486 | LIR** targets; // Array of case targets |
| 487 | } SwitchTable; |
| 488 | |
| 489 | typedef struct FillArrayData { |
| 490 | int offset; |
| 491 | const u2* table; // Original dex table |
| 492 | int size; |
| 493 | int vaddr; // Dalvik offset of OP_FILL_ARRAY_DATA opcode |
| 494 | } FillArrayData; |
| 495 | |
| 496 | |
buzbee | 5abfa3e | 2012-01-31 17:01:43 -0800 | [diff] [blame] | 497 | BasicBlock* oatNewBB(CompilationUnit* cUnit, BBType blockType, int blockId); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 498 | |
| 499 | void oatAppendMIR(BasicBlock* bb, MIR* mir); |
| 500 | |
| 501 | void oatPrependMIR(BasicBlock* bb, MIR* mir); |
| 502 | |
| 503 | void oatInsertMIRAfter(BasicBlock* bb, MIR* currentMIR, MIR* newMIR); |
| 504 | |
| 505 | void oatAppendLIR(CompilationUnit* cUnit, LIR* lir); |
| 506 | |
| 507 | void oatInsertLIRBefore(LIR* currentLIR, LIR* newLIR); |
| 508 | |
| 509 | void oatInsertLIRAfter(LIR* currentLIR, LIR* newLIR); |
| 510 | |
| 511 | /* Debug Utilities */ |
| 512 | void oatDumpCompilationUnit(CompilationUnit* cUnit); |
| 513 | |
Elliott Hughes | 11d1b0c | 2012-01-23 16:57:47 -0800 | [diff] [blame] | 514 | } // namespace art |
| 515 | |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 516 | #endif // ART_SRC_COMPILER_COMPILER_IR_H_ |