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