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