blob: 8bda3feddc012d2ed748b1c1f9b1bb1c6a6d71d7 [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:
TDYa12755e5e6c2012-09-11 15:14:42 -0700183 QuickCompiler();
buzbee692be802012-08-29 15:52:59 -0700184 ~QuickCompiler();
185
buzbee692be802012-08-29 15:52:59 -0700186 llvm::LLVMContext* GetLLVMContext() {
187 return llvm_context_.get();
188 }
189
190 llvm::Module* GetLLVMModule() {
TDYa12755e5e6c2012-09-11 15:14:42 -0700191 return llvm_module_;
buzbee692be802012-08-29 15:52:59 -0700192 }
193
194 art::greenland::IntrinsicHelper* GetIntrinsicHelper() {
195 return intrinsic_helper_.get();
196 }
197
198 art::greenland::IRBuilder* GetIRBuilder() {
199 return ir_builder_.get();
200 }
201
202 private:
buzbee692be802012-08-29 15:52:59 -0700203 UniquePtr<llvm::LLVMContext> llvm_context_;
TDYa12755e5e6c2012-09-11 15:14:42 -0700204 llvm::Module* llvm_module_; // Managed by context_
buzbee692be802012-08-29 15:52:59 -0700205 UniquePtr<art::greenland::IntrinsicHelper> intrinsic_helper_;
206 UniquePtr<art::greenland::IRBuilder> ir_builder_;
207};
208#endif
209
buzbee67bf8852011-08-17 17:51:35 -0700210struct CompilationUnit;
211struct BasicBlock;
212struct SSARepresentation;
213struct GrowableList;
214struct MIR;
215
buzbeeba938cb2012-02-03 14:47:55 -0800216void oatInit(CompilationUnit* cUnit, const Compiler& compiler);
buzbee67bf8852011-08-17 17:51:35 -0700217bool oatArchInit(void);
buzbee67bf8852011-08-17 17:51:35 -0700218bool oatStartup(void);
219void oatShutdown(void);
buzbee67bf8852011-08-17 17:51:35 -0700220void oatScanAllClassPointers(void (*callback)(void* ptr));
Elliott Hughes7b9d9962012-04-20 18:48:18 -0700221void oatInitializeSSAConversion(CompilationUnit* cUnit);
222int SRegToVReg(const CompilationUnit* cUnit, int ssaReg);
223int SRegToSubscript(const CompilationUnit* cUnit, int ssaReg);
224bool oatFindLocalLiveIn(CompilationUnit* cUnit, BasicBlock* bb);
225bool oatDoSSAConversion(CompilationUnit* cUnit, BasicBlock* bb);
226bool oatDoConstantPropagation(CompilationUnit* cUnit, BasicBlock* bb);
227bool oatFindInductionVariables(CompilationUnit* cUnit, BasicBlock* bb);
buzbee67bf8852011-08-17 17:51:35 -0700228/* Clear the visited flag for each BB */
Elliott Hughes7b9d9962012-04-20 18:48:18 -0700229bool oatClearVisitedFlag(CompilationUnit* cUnit, BasicBlock* bb);
230char* oatGetDalvikDisassembly(CompilationUnit* cUnit, const DecodedInstruction& insn,
buzbeeba938cb2012-02-03 14:47:55 -0800231 const char* note);
Elliott Hughes7b9d9962012-04-20 18:48:18 -0700232char* oatFullDisassembler(CompilationUnit* cUnit, const MIR* mir);
233char* oatGetSSAString(CompilationUnit* cUnit, SSARepresentation* ssaRep);
234void oatDataFlowAnalysisDispatcher(CompilationUnit* cUnit,
Bill Buzbeea114add2012-05-03 15:00:40 -0700235 bool (*func)(CompilationUnit* , BasicBlock*),
236 DataFlowAnalysisMode dfaMode,
237 bool isIterative);
Elliott Hughes7b9d9962012-04-20 18:48:18 -0700238void oatMethodSSATransformation(CompilationUnit* cUnit);
buzbee67bf8852011-08-17 17:51:35 -0700239u8 oatGetRegResourceMask(int reg);
Elliott Hughes7b9d9962012-04-20 18:48:18 -0700240void oatDumpCFG(CompilationUnit* cUnit, const char* dirPrefix);
buzbee67bf8852011-08-17 17:51:35 -0700241void oatProcessSwitchTables(CompilationUnit* cUnit);
buzbeee3acd072012-02-25 17:03:10 -0800242bool oatIsFpReg(int reg);
243uint32_t oatFpRegMask(void);
buzbeead8f15e2012-06-18 14:49:45 -0700244void oatReplaceSpecialChars(std::string& str);
buzbeef58c12c2012-07-03 15:06:29 -0700245BasicBlock* oatFindBlock(CompilationUnit* cUnit, unsigned int codeOffset);
buzbee67bf8852011-08-17 17:51:35 -0700246
Elliott Hughes11d1b0c2012-01-23 16:57:47 -0800247} // namespace art
248
Elliott Hughes3fa1b7e2012-03-13 17:06:22 -0700249extern "C" art::CompiledMethod* ArtCompileMethod(art::Compiler& compiler,
Elliott Hughesb3bd5f02012-03-08 21:05:27 -0800250 const art::DexFile::CodeItem* code_item,
Ian Rogers08f753d2012-08-24 14:35:25 -0700251 uint32_t access_flags,
252 art::InvokeType invoke_type,
253 uint32_t method_idx,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700254 jobject class_loader,
Elliott Hughesb3bd5f02012-03-08 21:05:27 -0800255 const art::DexFile& dex_file);
256
buzbee67bf8852011-08-17 17:51:35 -0700257#endif // ART_SRC_COMPILER_COMPILER_H_