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