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