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