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 | |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 22 | #define COMPILER_TRACED(X) |
| 23 | #define COMPILER_TRACEE(X) |
| 24 | |
| 25 | typedef enum OatInstructionSetType { |
| 26 | DALVIK_OAT_NONE = 0, |
| 27 | DALVIK_OAT_ARM, |
| 28 | DALVIK_OAT_THUMB2, |
| 29 | } OatInstructionSetType; |
| 30 | |
buzbee | ce30293 | 2011-10-04 14:32:18 -0700 | [diff] [blame] | 31 | /* Supress optimization if corresponding bit set */ |
| 32 | enum optControlVector { |
| 33 | kLoadStoreElimination = 0, |
| 34 | kLoadHoisting, |
| 35 | kSuppressLoads, |
| 36 | kNullCheckElimination, |
| 37 | kPromoteRegs, |
| 38 | kTrackLiveTemps, |
| 39 | }; |
| 40 | |
| 41 | extern uint32_t compilerOptimizerDisableFlags; |
| 42 | |
| 43 | /* Force code generation paths for testing */ |
| 44 | enum debugControlVector { |
| 45 | kDebugDisplayMissingTargets, |
| 46 | kDebugVerbose, |
| 47 | kDebugDumpCFG, |
| 48 | kDebugSlowFieldPath, |
| 49 | kDebugSlowInvokePath, |
| 50 | kDebugSlowStringPath, |
| 51 | kDebugSlowTypePath, |
| 52 | kDebugSlowestFieldPath, |
| 53 | kDebugSlowestStringPath, |
| 54 | }; |
| 55 | |
| 56 | extern uint32_t compilerDebugFlags; |
| 57 | |
| 58 | /* If non-empty, apply optimizer/debug flags only to matching methods */ |
| 59 | extern std::string compilerMethodMatch; |
| 60 | |
| 61 | /* Flips sense of compilerMethodMatch - apply flags if doesn't match */ |
| 62 | extern bool compilerFlipMatch; |
| 63 | |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 64 | typedef enum OatMethodAttributes { |
| 65 | kIsCallee = 0, /* Code is part of a callee (invoked by a hot trace) */ |
| 66 | kIsHot, /* Code is part of a hot trace */ |
| 67 | kIsLeaf, /* Method is leaf */ |
| 68 | kIsEmpty, /* Method is empty */ |
| 69 | kIsThrowFree, /* Method doesn't throw */ |
| 70 | kIsGetter, /* Method fits the getter pattern */ |
| 71 | kIsSetter, /* Method fits the setter pattern */ |
| 72 | kCannotCompile, /* Method cannot be compiled */ |
| 73 | } OatMethodAttributes; |
| 74 | |
| 75 | #define METHOD_IS_CALLEE (1 << kIsCallee) |
| 76 | #define METHOD_IS_HOT (1 << kIsHot) |
| 77 | #define METHOD_IS_LEAF (1 << kIsLeaf) |
| 78 | #define METHOD_IS_EMPTY (1 << kIsEmpty) |
| 79 | #define METHOD_IS_THROW_FREE (1 << kIsThrowFree) |
| 80 | #define METHOD_IS_GETTER (1 << kIsGetter) |
| 81 | #define METHOD_IS_SETTER (1 << kIsSetter) |
| 82 | #define METHOD_CANNOT_COMPILE (1 << kCannotCompile) |
| 83 | |
| 84 | /* Customized node traversal orders for different needs */ |
| 85 | typedef enum DataFlowAnalysisMode { |
| 86 | kAllNodes = 0, // All nodes |
| 87 | kReachableNodes, // All reachable nodes |
| 88 | kPreOrderDFSTraversal, // Depth-First-Search / Pre-Order |
| 89 | kPostOrderDFSTraversal, // Depth-First-Search / Post-Order |
| 90 | kPostOrderDOMTraversal, // Dominator tree / Post-Order |
| 91 | } DataFlowAnalysisMode; |
| 92 | |
| 93 | struct CompilationUnit; |
| 94 | struct BasicBlock; |
| 95 | struct SSARepresentation; |
| 96 | struct GrowableList; |
| 97 | struct MIR; |
| 98 | |
Brian Carlstrom | 1619286 | 2011-09-12 17:50:06 -0700 | [diff] [blame] | 99 | void oatInit(const Compiler& compiler); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 100 | bool oatArchInit(void); |
| 101 | void oatArchDump(void); |
| 102 | bool oatStartup(void); |
| 103 | void oatShutdown(void); |
Ian Rogers | 0571d35 | 2011-11-03 19:51:38 -0700 | [diff] [blame] | 104 | CompiledMethod* oatCompileMethod(const Compiler& compiler, bool is_direct, |
| 105 | uint32_t method_idx, const art::ClassLoader* class_loader, |
| 106 | const art::DexFile& dex_file, OatInstructionSetType); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 107 | void oatDumpStats(void); |
| 108 | void oatScanAllClassPointers(void (*callback)(void* ptr)); |
| 109 | void oatInitializeSSAConversion(struct CompilationUnit* cUnit); |
| 110 | int oatConvertSSARegToDalvik(const struct CompilationUnit* cUnit, int ssaReg); |
| 111 | bool oatFindLocalLiveIn(struct CompilationUnit* cUnit, |
| 112 | struct BasicBlock* bb); |
| 113 | bool oatDoSSAConversion(struct CompilationUnit* cUnit, |
| 114 | struct BasicBlock* bb); |
| 115 | bool oatDoConstantPropagation(struct CompilationUnit* cUnit, |
| 116 | struct BasicBlock* bb); |
| 117 | bool oatFindInductionVariables(struct CompilationUnit* cUnit, |
| 118 | struct BasicBlock* bb); |
| 119 | /* Clear the visited flag for each BB */ |
| 120 | bool oatClearVisitedFlag(struct CompilationUnit* cUnit, |
| 121 | struct BasicBlock* bb); |
Elliott Hughes | c1f143d | 2011-12-01 17:31:10 -0800 | [diff] [blame^] | 122 | char* oatGetDalvikDisassembly(const DecodedInstruction* insn, |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 123 | const char* note); |
Elliott Hughes | c1f143d | 2011-12-01 17:31:10 -0800 | [diff] [blame^] | 124 | char* oatFullDisassembler(const struct CompilationUnit* cUnit, |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 125 | const struct MIR* mir); |
Elliott Hughes | c1f143d | 2011-12-01 17:31:10 -0800 | [diff] [blame^] | 126 | char* oatGetSSAString(struct CompilationUnit* cUnit, |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 127 | struct SSARepresentation* ssaRep); |
| 128 | void oatDataFlowAnalysisDispatcher(struct CompilationUnit* cUnit, |
| 129 | bool (*func)(struct CompilationUnit* , struct BasicBlock*), |
| 130 | DataFlowAnalysisMode dfaMode, |
| 131 | bool isIterative); |
| 132 | void oatMethodSSATransformation(struct CompilationUnit* cUnit); |
| 133 | u8 oatGetRegResourceMask(int reg); |
| 134 | void oatDumpCFG(struct CompilationUnit* cUnit, const char* dirPrefix); |
| 135 | void oatProcessSwitchTables(CompilationUnit* cUnit); |
| 136 | |
| 137 | #endif // ART_SRC_COMPILER_COMPILER_H_ |