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_H_ |
| 18 | #define ART_SRC_COMPILER_COMPILER_H_ |
| 19 | |
Ian Rogers | 0571d35 | 2011-11-03 19:51:38 -0700 | [diff] [blame] | 20 | #include "dex_file.h" |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame^] | 21 | #include "dex_instruction.h" |
Ian Rogers | 0571d35 | 2011-11-03 19:51:38 -0700 | [diff] [blame] | 22 | |
Elliott Hughes | 11d1b0c | 2012-01-23 16:57:47 -0800 | [diff] [blame] | 23 | namespace art { |
| 24 | |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 25 | #define COMPILER_TRACED(X) |
| 26 | #define COMPILER_TRACEE(X) |
| 27 | |
buzbee | 44b412b | 2012-02-04 08:50:53 -0800 | [diff] [blame] | 28 | /* |
| 29 | * Special offsets to denote method entry/exit for debugger update. |
| 30 | * NOTE: bit pattern must be loadable using 1 instruction and must |
| 31 | * not be a valid Dalvik offset. |
| 32 | */ |
| 33 | #define DEBUGGER_METHOD_ENTRY -1 |
| 34 | #define DEBUGGER_METHOD_EXIT -2 |
| 35 | |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 36 | /* |
| 37 | * Assembly is an iterative process, and usually terminates within |
| 38 | * two or three passes. This should be high enough to handle bizarre |
| 39 | * cases, but detect an infinite loop bug. |
| 40 | */ |
| 41 | #define MAX_ASSEMBLER_RETRIES 50 |
| 42 | |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 43 | typedef enum OatInstructionSetType { |
| 44 | DALVIK_OAT_NONE = 0, |
| 45 | DALVIK_OAT_ARM, |
| 46 | DALVIK_OAT_THUMB2, |
buzbee | e88dfbf | 2012-03-05 11:19:57 -0800 | [diff] [blame] | 47 | DALVIK_OAT_X86, |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 48 | DALVIK_OAT_MIPS32 |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 49 | } OatInstructionSetType; |
| 50 | |
buzbee | ce30293 | 2011-10-04 14:32:18 -0700 | [diff] [blame] | 51 | /* Supress optimization if corresponding bit set */ |
| 52 | enum optControlVector { |
| 53 | kLoadStoreElimination = 0, |
| 54 | kLoadHoisting, |
| 55 | kSuppressLoads, |
| 56 | kNullCheckElimination, |
| 57 | kPromoteRegs, |
| 58 | kTrackLiveTemps, |
buzbee | 99ba964 | 2012-01-25 14:23:14 -0800 | [diff] [blame] | 59 | kSkipLargeMethodOptimization, |
buzbee | ce30293 | 2011-10-04 14:32:18 -0700 | [diff] [blame] | 60 | }; |
| 61 | |
buzbee | 5abfa3e | 2012-01-31 17:01:43 -0800 | [diff] [blame] | 62 | /* Type of allocation for memory tuning */ |
| 63 | enum oatAllocKind { |
| 64 | kAllocMisc, |
| 65 | kAllocBB, |
| 66 | kAllocLIR, |
| 67 | kAllocMIR, |
| 68 | kAllocDFInfo, |
| 69 | kAllocGrowableList, |
| 70 | kAllocGrowableBitMap, |
| 71 | kAllocDalvikToSSAMap, |
| 72 | kAllocDebugInfo, |
| 73 | kAllocSuccessor, |
| 74 | kAllocRegAlloc, |
| 75 | kAllocData, |
| 76 | kAllocPredecessors, |
| 77 | kNumAllocKinds |
| 78 | }; |
| 79 | |
| 80 | /* Type of growable list for memory tuning */ |
| 81 | enum oatListKind { |
| 82 | kListMisc = 0, |
| 83 | kListBlockList, |
| 84 | kListSSAtoDalvikMap, |
| 85 | kListDfsOrder, |
| 86 | kListDfsPostOrder, |
| 87 | kListDomPostOrderTraversal, |
| 88 | kListThrowLaunchPads, |
| 89 | kListSuspendLaunchPads, |
| 90 | kListSwitchTables, |
| 91 | kListFillArrayData, |
| 92 | kListSuccessorBlocks, |
| 93 | kListPredecessors, |
| 94 | kNumListKinds |
| 95 | }; |
| 96 | |
| 97 | /* Type of growable bitmap for memory tuning */ |
| 98 | enum oatBitMapKind { |
| 99 | kBitMapMisc = 0, |
| 100 | kBitMapUse, |
| 101 | kBitMapDef, |
| 102 | kBitMapLiveIn, |
| 103 | kBitMapBMatrix, |
| 104 | kBitMapDominators, |
| 105 | kBitMapIDominated, |
| 106 | kBitMapDomFrontier, |
| 107 | kBitMapPhi, |
| 108 | kBitMapTmpBlocks, |
| 109 | kBitMapInputBlocks, |
| 110 | kBitMapRegisterV, |
| 111 | kBitMapTempSSARegisterV, |
| 112 | kBitMapNullCheck, |
| 113 | kBitMapTmpBlockV, |
| 114 | kBitMapPredecessors, |
| 115 | kNumBitMapKinds |
| 116 | }; |
| 117 | |
buzbee | ce30293 | 2011-10-04 14:32:18 -0700 | [diff] [blame] | 118 | extern uint32_t compilerOptimizerDisableFlags; |
| 119 | |
| 120 | /* Force code generation paths for testing */ |
| 121 | enum debugControlVector { |
| 122 | kDebugDisplayMissingTargets, |
| 123 | kDebugVerbose, |
| 124 | kDebugDumpCFG, |
| 125 | kDebugSlowFieldPath, |
| 126 | kDebugSlowInvokePath, |
| 127 | kDebugSlowStringPath, |
| 128 | kDebugSlowTypePath, |
| 129 | kDebugSlowestFieldPath, |
| 130 | kDebugSlowestStringPath, |
buzbee | 34c77ad | 2012-01-11 13:01:32 -0800 | [diff] [blame] | 131 | kDebugExerciseResolveMethod, |
buzbee | 5b53710 | 2012-01-17 17:33:47 -0800 | [diff] [blame] | 132 | kDebugVerifyDataflow, |
buzbee | 5abfa3e | 2012-01-31 17:01:43 -0800 | [diff] [blame] | 133 | kDebugShowMemoryUsage, |
buzbee | ce30293 | 2011-10-04 14:32:18 -0700 | [diff] [blame] | 134 | }; |
| 135 | |
| 136 | extern uint32_t compilerDebugFlags; |
| 137 | |
| 138 | /* If non-empty, apply optimizer/debug flags only to matching methods */ |
| 139 | extern std::string compilerMethodMatch; |
| 140 | |
| 141 | /* Flips sense of compilerMethodMatch - apply flags if doesn't match */ |
| 142 | extern bool compilerFlipMatch; |
| 143 | |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 144 | typedef enum OatMethodAttributes { |
| 145 | kIsCallee = 0, /* Code is part of a callee (invoked by a hot trace) */ |
| 146 | kIsHot, /* Code is part of a hot trace */ |
| 147 | kIsLeaf, /* Method is leaf */ |
| 148 | kIsEmpty, /* Method is empty */ |
| 149 | kIsThrowFree, /* Method doesn't throw */ |
| 150 | kIsGetter, /* Method fits the getter pattern */ |
| 151 | kIsSetter, /* Method fits the setter pattern */ |
| 152 | kCannotCompile, /* Method cannot be compiled */ |
| 153 | } OatMethodAttributes; |
| 154 | |
| 155 | #define METHOD_IS_CALLEE (1 << kIsCallee) |
| 156 | #define METHOD_IS_HOT (1 << kIsHot) |
| 157 | #define METHOD_IS_LEAF (1 << kIsLeaf) |
| 158 | #define METHOD_IS_EMPTY (1 << kIsEmpty) |
| 159 | #define METHOD_IS_THROW_FREE (1 << kIsThrowFree) |
| 160 | #define METHOD_IS_GETTER (1 << kIsGetter) |
| 161 | #define METHOD_IS_SETTER (1 << kIsSetter) |
| 162 | #define METHOD_CANNOT_COMPILE (1 << kCannotCompile) |
| 163 | |
| 164 | /* Customized node traversal orders for different needs */ |
| 165 | typedef enum DataFlowAnalysisMode { |
| 166 | kAllNodes = 0, // All nodes |
| 167 | kReachableNodes, // All reachable nodes |
| 168 | kPreOrderDFSTraversal, // Depth-First-Search / Pre-Order |
| 169 | kPostOrderDFSTraversal, // Depth-First-Search / Post-Order |
| 170 | kPostOrderDOMTraversal, // Dominator tree / Post-Order |
buzbee | 5b53710 | 2012-01-17 17:33:47 -0800 | [diff] [blame] | 171 | kReversePostOrderTraversal, // Depth-First-Search / reverse Post-Order |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 172 | } DataFlowAnalysisMode; |
| 173 | |
| 174 | struct CompilationUnit; |
| 175 | struct BasicBlock; |
| 176 | struct SSARepresentation; |
| 177 | struct GrowableList; |
| 178 | struct MIR; |
| 179 | |
buzbee | ba938cb | 2012-02-03 14:47:55 -0800 | [diff] [blame] | 180 | void oatInit(CompilationUnit* cUnit, const Compiler& compiler); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 181 | bool oatArchInit(void); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 182 | bool oatStartup(void); |
| 183 | void oatShutdown(void); |
Ian Rogers | 996cc58 | 2012-02-14 22:23:29 -0800 | [diff] [blame] | 184 | CompiledMethod* oatCompileMethod(Compiler& compiler, bool is_direct, |
Elliott Hughes | 11d1b0c | 2012-01-23 16:57:47 -0800 | [diff] [blame] | 185 | uint32_t method_idx, const ClassLoader* class_loader, |
| 186 | const DexFile& dex_file, OatInstructionSetType); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 187 | void oatScanAllClassPointers(void (*callback)(void* ptr)); |
| 188 | void oatInitializeSSAConversion(struct CompilationUnit* cUnit); |
| 189 | int oatConvertSSARegToDalvik(const struct CompilationUnit* cUnit, int ssaReg); |
| 190 | bool oatFindLocalLiveIn(struct CompilationUnit* cUnit, |
| 191 | struct BasicBlock* bb); |
| 192 | bool oatDoSSAConversion(struct CompilationUnit* cUnit, |
| 193 | struct BasicBlock* bb); |
| 194 | bool oatDoConstantPropagation(struct CompilationUnit* cUnit, |
| 195 | struct BasicBlock* bb); |
| 196 | bool oatFindInductionVariables(struct CompilationUnit* cUnit, |
| 197 | struct BasicBlock* bb); |
| 198 | /* Clear the visited flag for each BB */ |
| 199 | bool oatClearVisitedFlag(struct CompilationUnit* cUnit, |
| 200 | struct BasicBlock* bb); |
buzbee | ba938cb | 2012-02-03 14:47:55 -0800 | [diff] [blame] | 201 | char* oatGetDalvikDisassembly(CompilationUnit* cUnit, |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame^] | 202 | const DecodedInstruction& insn, |
buzbee | ba938cb | 2012-02-03 14:47:55 -0800 | [diff] [blame] | 203 | const char* note); |
| 204 | char* oatFullDisassembler(struct CompilationUnit* cUnit, |
| 205 | const struct MIR* mir); |
Elliott Hughes | c1f143d | 2011-12-01 17:31:10 -0800 | [diff] [blame] | 206 | char* oatGetSSAString(struct CompilationUnit* cUnit, |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 207 | struct SSARepresentation* ssaRep); |
| 208 | void oatDataFlowAnalysisDispatcher(struct CompilationUnit* cUnit, |
| 209 | bool (*func)(struct CompilationUnit* , struct BasicBlock*), |
| 210 | DataFlowAnalysisMode dfaMode, |
| 211 | bool isIterative); |
| 212 | void oatMethodSSATransformation(struct CompilationUnit* cUnit); |
| 213 | u8 oatGetRegResourceMask(int reg); |
| 214 | void oatDumpCFG(struct CompilationUnit* cUnit, const char* dirPrefix); |
| 215 | void oatProcessSwitchTables(CompilationUnit* cUnit); |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 216 | bool oatIsFpReg(int reg); |
| 217 | uint32_t oatFpRegMask(void); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 218 | |
Elliott Hughes | 11d1b0c | 2012-01-23 16:57:47 -0800 | [diff] [blame] | 219 | } // namespace art |
| 220 | |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 221 | #endif // ART_SRC_COMPILER_COMPILER_H_ |