blob: 9ac6016fd38f94ad4be3dc533f1431fba73ab97c [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,
buzbeead8f15e2012-06-18 14:49:45 -0700143#if defined(ART_USE_QUICK_COMPILER)
144 kDebugDumpBitcodeFile,
Bill Buzbeec9f40dd2012-08-15 11:35:25 -0700145 kDebugVerifyBitcode,
buzbeead8f15e2012-06-18 14:49:45 -0700146#endif
buzbeece302932011-10-04 14:32:18 -0700147};
148
Elliott Hughes719ace42012-03-09 18:06:03 -0800149enum OatMethodAttributes {
Bill Buzbeea114add2012-05-03 15:00:40 -0700150 kIsCallee = 0, /* Code is part of a callee (invoked by a hot trace) */
151 kIsHot, /* Code is part of a hot trace */
152 kIsLeaf, /* Method is leaf */
153 kIsEmpty, /* Method is empty */
154 kIsThrowFree, /* Method doesn't throw */
155 kIsGetter, /* Method fits the getter pattern */
156 kIsSetter, /* Method fits the setter pattern */
157 kCannotCompile, /* Method cannot be compiled */
Elliott Hughes719ace42012-03-09 18:06:03 -0800158};
buzbee67bf8852011-08-17 17:51:35 -0700159
160#define METHOD_IS_CALLEE (1 << kIsCallee)
161#define METHOD_IS_HOT (1 << kIsHot)
162#define METHOD_IS_LEAF (1 << kIsLeaf)
163#define METHOD_IS_EMPTY (1 << kIsEmpty)
164#define METHOD_IS_THROW_FREE (1 << kIsThrowFree)
165#define METHOD_IS_GETTER (1 << kIsGetter)
166#define METHOD_IS_SETTER (1 << kIsSetter)
167#define METHOD_CANNOT_COMPILE (1 << kCannotCompile)
168
169/* Customized node traversal orders for different needs */
Elliott Hughes719ace42012-03-09 18:06:03 -0800170enum DataFlowAnalysisMode {
Bill Buzbeea114add2012-05-03 15:00:40 -0700171 kAllNodes = 0, // All nodes
172 kReachableNodes, // All reachable nodes
173 kPreOrderDFSTraversal, // Depth-First-Search / Pre-Order
174 kPostOrderDFSTraversal, // Depth-First-Search / Post-Order
175 kPostOrderDOMTraversal, // Dominator tree / Post-Order
176 kReversePostOrderTraversal, // Depth-First-Search / reverse Post-Order
Elliott Hughes719ace42012-03-09 18:06:03 -0800177};
buzbee67bf8852011-08-17 17:51:35 -0700178
buzbee692be802012-08-29 15:52:59 -0700179#if defined(ART_USE_QUICK_COMPILER)
180class QuickCompiler {
181 public:
182 QuickCompiler(art::Compiler* compiler);
183 ~QuickCompiler();
184
185 const art::Compiler* GetCompiler() const {
186 return compiler_;
187 }
188
189 llvm::LLVMContext* GetLLVMContext() {
190 return llvm_context_.get();
191 }
192
193 llvm::Module* GetLLVMModule() {
194 return llvm_module_.get();
195 }
196
197 art::greenland::IntrinsicHelper* GetIntrinsicHelper() {
198 return intrinsic_helper_.get();
199 }
200
201 art::greenland::IRBuilder* GetIRBuilder() {
202 return ir_builder_.get();
203 }
204
205 private:
206 const art::Compiler* const compiler_;
207 UniquePtr<llvm::LLVMContext> llvm_context_;
208 UniquePtr<llvm::Module> llvm_module_;
209 UniquePtr<art::greenland::IntrinsicHelper> intrinsic_helper_;
210 UniquePtr<art::greenland::IRBuilder> ir_builder_;
211};
212#endif
213
buzbee67bf8852011-08-17 17:51:35 -0700214struct CompilationUnit;
215struct BasicBlock;
216struct SSARepresentation;
217struct GrowableList;
218struct MIR;
219
buzbeeba938cb2012-02-03 14:47:55 -0800220void oatInit(CompilationUnit* cUnit, const Compiler& compiler);
buzbee67bf8852011-08-17 17:51:35 -0700221bool oatArchInit(void);
buzbee67bf8852011-08-17 17:51:35 -0700222bool oatStartup(void);
223void oatShutdown(void);
buzbee67bf8852011-08-17 17:51:35 -0700224void oatScanAllClassPointers(void (*callback)(void* ptr));
Elliott Hughes7b9d9962012-04-20 18:48:18 -0700225void oatInitializeSSAConversion(CompilationUnit* cUnit);
226int SRegToVReg(const CompilationUnit* cUnit, int ssaReg);
227int SRegToSubscript(const CompilationUnit* cUnit, int ssaReg);
228bool oatFindLocalLiveIn(CompilationUnit* cUnit, BasicBlock* bb);
229bool oatDoSSAConversion(CompilationUnit* cUnit, BasicBlock* bb);
230bool oatDoConstantPropagation(CompilationUnit* cUnit, BasicBlock* bb);
231bool oatFindInductionVariables(CompilationUnit* cUnit, BasicBlock* bb);
buzbee67bf8852011-08-17 17:51:35 -0700232/* Clear the visited flag for each BB */
Elliott Hughes7b9d9962012-04-20 18:48:18 -0700233bool oatClearVisitedFlag(CompilationUnit* cUnit, BasicBlock* bb);
234char* oatGetDalvikDisassembly(CompilationUnit* cUnit, const DecodedInstruction& insn,
buzbeeba938cb2012-02-03 14:47:55 -0800235 const char* note);
Elliott Hughes7b9d9962012-04-20 18:48:18 -0700236char* oatFullDisassembler(CompilationUnit* cUnit, const MIR* mir);
237char* oatGetSSAString(CompilationUnit* cUnit, SSARepresentation* ssaRep);
238void oatDataFlowAnalysisDispatcher(CompilationUnit* cUnit,
Bill Buzbeea114add2012-05-03 15:00:40 -0700239 bool (*func)(CompilationUnit* , BasicBlock*),
240 DataFlowAnalysisMode dfaMode,
241 bool isIterative);
Elliott Hughes7b9d9962012-04-20 18:48:18 -0700242void oatMethodSSATransformation(CompilationUnit* cUnit);
buzbee67bf8852011-08-17 17:51:35 -0700243u8 oatGetRegResourceMask(int reg);
Elliott Hughes7b9d9962012-04-20 18:48:18 -0700244void oatDumpCFG(CompilationUnit* cUnit, const char* dirPrefix);
buzbee67bf8852011-08-17 17:51:35 -0700245void oatProcessSwitchTables(CompilationUnit* cUnit);
buzbeee3acd072012-02-25 17:03:10 -0800246bool oatIsFpReg(int reg);
247uint32_t oatFpRegMask(void);
buzbeead8f15e2012-06-18 14:49:45 -0700248void oatReplaceSpecialChars(std::string& str);
buzbeef58c12c2012-07-03 15:06:29 -0700249BasicBlock* oatFindBlock(CompilationUnit* cUnit, unsigned int codeOffset);
buzbee67bf8852011-08-17 17:51:35 -0700250
Elliott Hughes11d1b0c2012-01-23 16:57:47 -0800251} // namespace art
252
Elliott Hughes3fa1b7e2012-03-13 17:06:22 -0700253extern "C" art::CompiledMethod* ArtCompileMethod(art::Compiler& compiler,
Elliott Hughesb3bd5f02012-03-08 21:05:27 -0800254 const art::DexFile::CodeItem* code_item,
Ian Rogers08f753d2012-08-24 14:35:25 -0700255 uint32_t access_flags,
256 art::InvokeType invoke_type,
257 uint32_t method_idx,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700258 jobject class_loader,
Elliott Hughesb3bd5f02012-03-08 21:05:27 -0800259 const art::DexFile& dex_file);
260
buzbee67bf8852011-08-17 17:51:35 -0700261#endif // ART_SRC_COMPILER_COMPILER_H_