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 | |
buzbee | 692be80 | 2012-08-29 15:52:59 -0700 | [diff] [blame] | 23 | #if defined(ART_USE_QUICK_COMPILER) |
| 24 | namespace llvm { |
| 25 | class Module; |
| 26 | class LLVMContext; |
| 27 | } |
| 28 | #endif |
| 29 | |
Elliott Hughes | 11d1b0c | 2012-01-23 16:57:47 -0800 | [diff] [blame] | 30 | namespace art { |
buzbee | 692be80 | 2012-08-29 15:52:59 -0700 | [diff] [blame] | 31 | #if defined(ART_USE_QUICK_COMPILER) |
| 32 | namespace greenland { |
| 33 | class IntrinsicHelper; |
| 34 | class IRBuilder; |
| 35 | } |
| 36 | #endif |
Elliott Hughes | 11d1b0c | 2012-01-23 16:57:47 -0800 | [diff] [blame] | 37 | |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 38 | #define COMPILER_TRACED(X) |
| 39 | #define COMPILER_TRACEE(X) |
| 40 | |
buzbee | 44b412b | 2012-02-04 08:50:53 -0800 | [diff] [blame] | 41 | /* |
| 42 | * Special offsets to denote method entry/exit for debugger update. |
| 43 | * NOTE: bit pattern must be loadable using 1 instruction and must |
| 44 | * not be a valid Dalvik offset. |
| 45 | */ |
| 46 | #define DEBUGGER_METHOD_ENTRY -1 |
| 47 | #define DEBUGGER_METHOD_EXIT -2 |
| 48 | |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 49 | /* |
| 50 | * Assembly is an iterative process, and usually terminates within |
| 51 | * two or three passes. This should be high enough to handle bizarre |
| 52 | * cases, but detect an infinite loop bug. |
| 53 | */ |
| 54 | #define MAX_ASSEMBLER_RETRIES 50 |
| 55 | |
Elliott Hughes | b3bd5f0 | 2012-03-08 21:05:27 -0800 | [diff] [blame] | 56 | /* Suppress optimization if corresponding bit set */ |
buzbee | ce30293 | 2011-10-04 14:32:18 -0700 | [diff] [blame] | 57 | enum optControlVector { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 58 | kLoadStoreElimination = 0, |
| 59 | kLoadHoisting, |
| 60 | kSuppressLoads, |
| 61 | kNullCheckElimination, |
| 62 | kPromoteRegs, |
| 63 | kTrackLiveTemps, |
| 64 | kSkipLargeMethodOptimization, |
| 65 | kSafeOptimizations, |
| 66 | kBBOpt, |
| 67 | kMatch, |
| 68 | kPromoteCompilerTemps, |
buzbee | ce30293 | 2011-10-04 14:32:18 -0700 | [diff] [blame] | 69 | }; |
| 70 | |
buzbee | 5abfa3e | 2012-01-31 17:01:43 -0800 | [diff] [blame] | 71 | /* Type of allocation for memory tuning */ |
| 72 | enum oatAllocKind { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 73 | kAllocMisc, |
| 74 | kAllocBB, |
| 75 | kAllocLIR, |
| 76 | kAllocMIR, |
| 77 | kAllocDFInfo, |
| 78 | kAllocGrowableList, |
| 79 | kAllocGrowableBitMap, |
| 80 | kAllocDalvikToSSAMap, |
| 81 | kAllocDebugInfo, |
| 82 | kAllocSuccessor, |
| 83 | kAllocRegAlloc, |
| 84 | kAllocData, |
| 85 | kAllocPredecessors, |
| 86 | kNumAllocKinds |
buzbee | 5abfa3e | 2012-01-31 17:01:43 -0800 | [diff] [blame] | 87 | }; |
| 88 | |
| 89 | /* Type of growable list for memory tuning */ |
| 90 | enum oatListKind { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 91 | kListMisc = 0, |
| 92 | kListBlockList, |
| 93 | kListSSAtoDalvikMap, |
| 94 | kListDfsOrder, |
| 95 | kListDfsPostOrder, |
| 96 | kListDomPostOrderTraversal, |
| 97 | kListThrowLaunchPads, |
| 98 | kListSuspendLaunchPads, |
| 99 | kListSwitchTables, |
| 100 | kListFillArrayData, |
| 101 | kListSuccessorBlocks, |
| 102 | kListPredecessors, |
| 103 | kNumListKinds |
buzbee | 5abfa3e | 2012-01-31 17:01:43 -0800 | [diff] [blame] | 104 | }; |
| 105 | |
| 106 | /* Type of growable bitmap for memory tuning */ |
| 107 | enum oatBitMapKind { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 108 | kBitMapMisc = 0, |
| 109 | kBitMapUse, |
| 110 | kBitMapDef, |
| 111 | kBitMapLiveIn, |
| 112 | kBitMapBMatrix, |
| 113 | kBitMapDominators, |
| 114 | kBitMapIDominated, |
| 115 | kBitMapDomFrontier, |
| 116 | kBitMapPhi, |
| 117 | kBitMapTmpBlocks, |
| 118 | kBitMapInputBlocks, |
| 119 | kBitMapRegisterV, |
| 120 | kBitMapTempSSARegisterV, |
| 121 | kBitMapNullCheck, |
| 122 | kBitMapTmpBlockV, |
| 123 | kBitMapPredecessors, |
| 124 | kNumBitMapKinds |
buzbee | 5abfa3e | 2012-01-31 17:01:43 -0800 | [diff] [blame] | 125 | }; |
| 126 | |
buzbee | ce30293 | 2011-10-04 14:32:18 -0700 | [diff] [blame] | 127 | /* Force code generation paths for testing */ |
| 128 | enum debugControlVector { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 129 | kDebugDisplayMissingTargets, |
| 130 | kDebugVerbose, |
| 131 | kDebugDumpCFG, |
| 132 | kDebugSlowFieldPath, |
| 133 | kDebugSlowInvokePath, |
| 134 | kDebugSlowStringPath, |
| 135 | kDebugSlowTypePath, |
| 136 | kDebugSlowestFieldPath, |
| 137 | kDebugSlowestStringPath, |
| 138 | kDebugExerciseResolveMethod, |
| 139 | kDebugVerifyDataflow, |
| 140 | kDebugShowMemoryUsage, |
| 141 | kDebugShowNops, |
| 142 | kDebugCountOpcodes, |
buzbee | d1643e4 | 2012-09-05 14:06:51 -0700 | [diff] [blame^] | 143 | kDebugDumpCheckStats, |
buzbee | ad8f15e | 2012-06-18 14:49:45 -0700 | [diff] [blame] | 144 | #if defined(ART_USE_QUICK_COMPILER) |
| 145 | kDebugDumpBitcodeFile, |
Bill Buzbee | c9f40dd | 2012-08-15 11:35:25 -0700 | [diff] [blame] | 146 | kDebugVerifyBitcode, |
buzbee | ad8f15e | 2012-06-18 14:49:45 -0700 | [diff] [blame] | 147 | #endif |
buzbee | ce30293 | 2011-10-04 14:32:18 -0700 | [diff] [blame] | 148 | }; |
| 149 | |
Elliott Hughes | 719ace4 | 2012-03-09 18:06:03 -0800 | [diff] [blame] | 150 | enum OatMethodAttributes { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 151 | kIsCallee = 0, /* Code is part of a callee (invoked by a hot trace) */ |
| 152 | kIsHot, /* Code is part of a hot trace */ |
| 153 | kIsLeaf, /* Method is leaf */ |
| 154 | kIsEmpty, /* Method is empty */ |
| 155 | kIsThrowFree, /* Method doesn't throw */ |
| 156 | kIsGetter, /* Method fits the getter pattern */ |
| 157 | kIsSetter, /* Method fits the setter pattern */ |
| 158 | kCannotCompile, /* Method cannot be compiled */ |
Elliott Hughes | 719ace4 | 2012-03-09 18:06:03 -0800 | [diff] [blame] | 159 | }; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 160 | |
| 161 | #define METHOD_IS_CALLEE (1 << kIsCallee) |
| 162 | #define METHOD_IS_HOT (1 << kIsHot) |
| 163 | #define METHOD_IS_LEAF (1 << kIsLeaf) |
| 164 | #define METHOD_IS_EMPTY (1 << kIsEmpty) |
| 165 | #define METHOD_IS_THROW_FREE (1 << kIsThrowFree) |
| 166 | #define METHOD_IS_GETTER (1 << kIsGetter) |
| 167 | #define METHOD_IS_SETTER (1 << kIsSetter) |
| 168 | #define METHOD_CANNOT_COMPILE (1 << kCannotCompile) |
| 169 | |
| 170 | /* Customized node traversal orders for different needs */ |
Elliott Hughes | 719ace4 | 2012-03-09 18:06:03 -0800 | [diff] [blame] | 171 | enum DataFlowAnalysisMode { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 172 | kAllNodes = 0, // All nodes |
| 173 | kReachableNodes, // All reachable nodes |
| 174 | kPreOrderDFSTraversal, // Depth-First-Search / Pre-Order |
| 175 | kPostOrderDFSTraversal, // Depth-First-Search / Post-Order |
| 176 | kPostOrderDOMTraversal, // Dominator tree / Post-Order |
| 177 | kReversePostOrderTraversal, // Depth-First-Search / reverse Post-Order |
Elliott Hughes | 719ace4 | 2012-03-09 18:06:03 -0800 | [diff] [blame] | 178 | }; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 179 | |
buzbee | 692be80 | 2012-08-29 15:52:59 -0700 | [diff] [blame] | 180 | #if defined(ART_USE_QUICK_COMPILER) |
| 181 | class QuickCompiler { |
| 182 | public: |
| 183 | QuickCompiler(art::Compiler* compiler); |
| 184 | ~QuickCompiler(); |
| 185 | |
| 186 | const art::Compiler* GetCompiler() const { |
| 187 | return compiler_; |
| 188 | } |
| 189 | |
| 190 | llvm::LLVMContext* GetLLVMContext() { |
| 191 | return llvm_context_.get(); |
| 192 | } |
| 193 | |
| 194 | llvm::Module* GetLLVMModule() { |
| 195 | return llvm_module_.get(); |
| 196 | } |
| 197 | |
| 198 | art::greenland::IntrinsicHelper* GetIntrinsicHelper() { |
| 199 | return intrinsic_helper_.get(); |
| 200 | } |
| 201 | |
| 202 | art::greenland::IRBuilder* GetIRBuilder() { |
| 203 | return ir_builder_.get(); |
| 204 | } |
| 205 | |
| 206 | private: |
| 207 | const art::Compiler* const compiler_; |
| 208 | UniquePtr<llvm::LLVMContext> llvm_context_; |
| 209 | UniquePtr<llvm::Module> llvm_module_; |
| 210 | UniquePtr<art::greenland::IntrinsicHelper> intrinsic_helper_; |
| 211 | UniquePtr<art::greenland::IRBuilder> ir_builder_; |
| 212 | }; |
| 213 | #endif |
| 214 | |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 215 | struct CompilationUnit; |
| 216 | struct BasicBlock; |
| 217 | struct SSARepresentation; |
| 218 | struct GrowableList; |
| 219 | struct MIR; |
| 220 | |
buzbee | ba938cb | 2012-02-03 14:47:55 -0800 | [diff] [blame] | 221 | void oatInit(CompilationUnit* cUnit, const Compiler& compiler); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 222 | bool oatArchInit(void); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 223 | bool oatStartup(void); |
| 224 | void oatShutdown(void); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 225 | void oatScanAllClassPointers(void (*callback)(void* ptr)); |
Elliott Hughes | 7b9d996 | 2012-04-20 18:48:18 -0700 | [diff] [blame] | 226 | void oatInitializeSSAConversion(CompilationUnit* cUnit); |
| 227 | int SRegToVReg(const CompilationUnit* cUnit, int ssaReg); |
| 228 | int SRegToSubscript(const CompilationUnit* cUnit, int ssaReg); |
| 229 | bool oatFindLocalLiveIn(CompilationUnit* cUnit, BasicBlock* bb); |
| 230 | bool oatDoSSAConversion(CompilationUnit* cUnit, BasicBlock* bb); |
| 231 | bool oatDoConstantPropagation(CompilationUnit* cUnit, BasicBlock* bb); |
| 232 | bool oatFindInductionVariables(CompilationUnit* cUnit, BasicBlock* bb); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 233 | /* Clear the visited flag for each BB */ |
Elliott Hughes | 7b9d996 | 2012-04-20 18:48:18 -0700 | [diff] [blame] | 234 | bool oatClearVisitedFlag(CompilationUnit* cUnit, BasicBlock* bb); |
| 235 | char* oatGetDalvikDisassembly(CompilationUnit* cUnit, const DecodedInstruction& insn, |
buzbee | ba938cb | 2012-02-03 14:47:55 -0800 | [diff] [blame] | 236 | const char* note); |
Elliott Hughes | 7b9d996 | 2012-04-20 18:48:18 -0700 | [diff] [blame] | 237 | char* oatFullDisassembler(CompilationUnit* cUnit, const MIR* mir); |
| 238 | char* oatGetSSAString(CompilationUnit* cUnit, SSARepresentation* ssaRep); |
| 239 | void oatDataFlowAnalysisDispatcher(CompilationUnit* cUnit, |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 240 | bool (*func)(CompilationUnit* , BasicBlock*), |
| 241 | DataFlowAnalysisMode dfaMode, |
| 242 | bool isIterative); |
Elliott Hughes | 7b9d996 | 2012-04-20 18:48:18 -0700 | [diff] [blame] | 243 | void oatMethodSSATransformation(CompilationUnit* cUnit); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 244 | u8 oatGetRegResourceMask(int reg); |
Elliott Hughes | 7b9d996 | 2012-04-20 18:48:18 -0700 | [diff] [blame] | 245 | void oatDumpCFG(CompilationUnit* cUnit, const char* dirPrefix); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 246 | void oatProcessSwitchTables(CompilationUnit* cUnit); |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 247 | bool oatIsFpReg(int reg); |
| 248 | uint32_t oatFpRegMask(void); |
buzbee | ad8f15e | 2012-06-18 14:49:45 -0700 | [diff] [blame] | 249 | void oatReplaceSpecialChars(std::string& str); |
buzbee | f58c12c | 2012-07-03 15:06:29 -0700 | [diff] [blame] | 250 | BasicBlock* oatFindBlock(CompilationUnit* cUnit, unsigned int codeOffset); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 251 | |
Elliott Hughes | 11d1b0c | 2012-01-23 16:57:47 -0800 | [diff] [blame] | 252 | } // namespace art |
| 253 | |
Elliott Hughes | 3fa1b7e | 2012-03-13 17:06:22 -0700 | [diff] [blame] | 254 | extern "C" art::CompiledMethod* ArtCompileMethod(art::Compiler& compiler, |
Elliott Hughes | b3bd5f0 | 2012-03-08 21:05:27 -0800 | [diff] [blame] | 255 | const art::DexFile::CodeItem* code_item, |
Ian Rogers | 08f753d | 2012-08-24 14:35:25 -0700 | [diff] [blame] | 256 | uint32_t access_flags, |
| 257 | art::InvokeType invoke_type, |
| 258 | uint32_t method_idx, |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 259 | jobject class_loader, |
Elliott Hughes | b3bd5f0 | 2012-03-08 21:05:27 -0800 | [diff] [blame] | 260 | const art::DexFile& dex_file); |
| 261 | |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 262 | #endif // ART_SRC_COMPILER_COMPILER_H_ |