blob: 4a7683b10b106279bb481593dd85481e12969f13 [file] [log] [blame]
buzbee67bf8852011-08-17 17:51:35 -07001/*
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 Rogers0571d352011-11-03 19:51:38 -070020#include "dex_file.h"
Elliott Hughesadb8c672012-03-06 16:49:32 -080021#include "dex_instruction.h"
Ian Rogers0571d352011-11-03 19:51:38 -070022
buzbee692be802012-08-29 15:52:59 -070023#if defined(ART_USE_QUICK_COMPILER)
24namespace llvm {
25 class Module;
26 class LLVMContext;
27}
28#endif
29
Elliott Hughes11d1b0c2012-01-23 16:57:47 -080030namespace art {
buzbee692be802012-08-29 15:52:59 -070031#if defined(ART_USE_QUICK_COMPILER)
32namespace greenland {
33 class IntrinsicHelper;
34 class IRBuilder;
35}
36#endif
Elliott Hughes11d1b0c2012-01-23 16:57:47 -080037
buzbee67bf8852011-08-17 17:51:35 -070038#define COMPILER_TRACED(X)
39#define COMPILER_TRACEE(X)
40
buzbee44b412b2012-02-04 08:50:53 -080041/*
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
buzbeee3acd072012-02-25 17:03:10 -080049/*
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 Hughesb3bd5f02012-03-08 21:05:27 -080056/* Suppress optimization if corresponding bit set */
buzbeece302932011-10-04 14:32:18 -070057enum optControlVector {
Bill Buzbeea114add2012-05-03 15:00:40 -070058 kLoadStoreElimination = 0,
59 kLoadHoisting,
60 kSuppressLoads,
61 kNullCheckElimination,
62 kPromoteRegs,
63 kTrackLiveTemps,
64 kSkipLargeMethodOptimization,
65 kSafeOptimizations,
66 kBBOpt,
67 kMatch,
68 kPromoteCompilerTemps,
buzbeece302932011-10-04 14:32:18 -070069};
70
buzbee5abfa3e2012-01-31 17:01:43 -080071/* Type of allocation for memory tuning */
72enum oatAllocKind {
Bill Buzbeea114add2012-05-03 15:00:40 -070073 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
buzbee5abfa3e2012-01-31 17:01:43 -080087};
88
89/* Type of growable list for memory tuning */
90enum oatListKind {
Bill Buzbeea114add2012-05-03 15:00:40 -070091 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
buzbee5abfa3e2012-01-31 17:01:43 -0800104};
105
106/* Type of growable bitmap for memory tuning */
107enum oatBitMapKind {
Bill Buzbeea114add2012-05-03 15:00:40 -0700108 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
buzbee5abfa3e2012-01-31 17:01:43 -0800125};
126
buzbeece302932011-10-04 14:32:18 -0700127/* Force code generation paths for testing */
128enum debugControlVector {
Bill Buzbeea114add2012-05-03 15:00:40 -0700129 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,
buzbeed1643e42012-09-05 14:06:51 -0700143 kDebugDumpCheckStats,
buzbeead8f15e2012-06-18 14:49:45 -0700144#if defined(ART_USE_QUICK_COMPILER)
145 kDebugDumpBitcodeFile,
Bill Buzbeec9f40dd2012-08-15 11:35:25 -0700146 kDebugVerifyBitcode,
buzbeead8f15e2012-06-18 14:49:45 -0700147#endif
buzbeece302932011-10-04 14:32:18 -0700148};
149
Elliott Hughes719ace42012-03-09 18:06:03 -0800150enum OatMethodAttributes {
Bill Buzbeea114add2012-05-03 15:00:40 -0700151 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 Hughes719ace42012-03-09 18:06:03 -0800159};
buzbee67bf8852011-08-17 17:51:35 -0700160
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 Hughes719ace42012-03-09 18:06:03 -0800171enum DataFlowAnalysisMode {
Bill Buzbeea114add2012-05-03 15:00:40 -0700172 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 Hughes719ace42012-03-09 18:06:03 -0800178};
buzbee67bf8852011-08-17 17:51:35 -0700179
buzbee692be802012-08-29 15:52:59 -0700180#if defined(ART_USE_QUICK_COMPILER)
181class 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
buzbee67bf8852011-08-17 17:51:35 -0700215struct CompilationUnit;
216struct BasicBlock;
217struct SSARepresentation;
218struct GrowableList;
219struct MIR;
220
buzbeeba938cb2012-02-03 14:47:55 -0800221void oatInit(CompilationUnit* cUnit, const Compiler& compiler);
buzbee67bf8852011-08-17 17:51:35 -0700222bool oatArchInit(void);
buzbee67bf8852011-08-17 17:51:35 -0700223bool oatStartup(void);
224void oatShutdown(void);
buzbee67bf8852011-08-17 17:51:35 -0700225void oatScanAllClassPointers(void (*callback)(void* ptr));
Elliott Hughes7b9d9962012-04-20 18:48:18 -0700226void oatInitializeSSAConversion(CompilationUnit* cUnit);
227int SRegToVReg(const CompilationUnit* cUnit, int ssaReg);
228int SRegToSubscript(const CompilationUnit* cUnit, int ssaReg);
229bool oatFindLocalLiveIn(CompilationUnit* cUnit, BasicBlock* bb);
230bool oatDoSSAConversion(CompilationUnit* cUnit, BasicBlock* bb);
231bool oatDoConstantPropagation(CompilationUnit* cUnit, BasicBlock* bb);
232bool oatFindInductionVariables(CompilationUnit* cUnit, BasicBlock* bb);
buzbee67bf8852011-08-17 17:51:35 -0700233/* Clear the visited flag for each BB */
Elliott Hughes7b9d9962012-04-20 18:48:18 -0700234bool oatClearVisitedFlag(CompilationUnit* cUnit, BasicBlock* bb);
235char* oatGetDalvikDisassembly(CompilationUnit* cUnit, const DecodedInstruction& insn,
buzbeeba938cb2012-02-03 14:47:55 -0800236 const char* note);
Elliott Hughes7b9d9962012-04-20 18:48:18 -0700237char* oatFullDisassembler(CompilationUnit* cUnit, const MIR* mir);
238char* oatGetSSAString(CompilationUnit* cUnit, SSARepresentation* ssaRep);
239void oatDataFlowAnalysisDispatcher(CompilationUnit* cUnit,
Bill Buzbeea114add2012-05-03 15:00:40 -0700240 bool (*func)(CompilationUnit* , BasicBlock*),
241 DataFlowAnalysisMode dfaMode,
242 bool isIterative);
Elliott Hughes7b9d9962012-04-20 18:48:18 -0700243void oatMethodSSATransformation(CompilationUnit* cUnit);
buzbee67bf8852011-08-17 17:51:35 -0700244u8 oatGetRegResourceMask(int reg);
Elliott Hughes7b9d9962012-04-20 18:48:18 -0700245void oatDumpCFG(CompilationUnit* cUnit, const char* dirPrefix);
buzbee67bf8852011-08-17 17:51:35 -0700246void oatProcessSwitchTables(CompilationUnit* cUnit);
buzbeee3acd072012-02-25 17:03:10 -0800247bool oatIsFpReg(int reg);
248uint32_t oatFpRegMask(void);
buzbeead8f15e2012-06-18 14:49:45 -0700249void oatReplaceSpecialChars(std::string& str);
buzbeef58c12c2012-07-03 15:06:29 -0700250BasicBlock* oatFindBlock(CompilationUnit* cUnit, unsigned int codeOffset);
buzbee67bf8852011-08-17 17:51:35 -0700251
Elliott Hughes11d1b0c2012-01-23 16:57:47 -0800252} // namespace art
253
Elliott Hughes3fa1b7e2012-03-13 17:06:22 -0700254extern "C" art::CompiledMethod* ArtCompileMethod(art::Compiler& compiler,
Elliott Hughesb3bd5f02012-03-08 21:05:27 -0800255 const art::DexFile::CodeItem* code_item,
Ian Rogers08f753d2012-08-24 14:35:25 -0700256 uint32_t access_flags,
257 art::InvokeType invoke_type,
258 uint32_t method_idx,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700259 jobject class_loader,
Elliott Hughesb3bd5f02012-03-08 21:05:27 -0800260 const art::DexFile& dex_file);
261
buzbee67bf8852011-08-17 17:51:35 -0700262#endif // ART_SRC_COMPILER_COMPILER_H_