blob: 1d89c66cd1a0efbaefc115914c13ca7da2b4adfe [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"
21
Elliott Hughes11d1b0c2012-01-23 16:57:47 -080022namespace art {
23
buzbee67bf8852011-08-17 17:51:35 -070024#define COMPILER_TRACED(X)
25#define COMPILER_TRACEE(X)
26
buzbee44b412b2012-02-04 08:50:53 -080027/*
28 * Special offsets to denote method entry/exit for debugger update.
29 * NOTE: bit pattern must be loadable using 1 instruction and must
30 * not be a valid Dalvik offset.
31 */
32#define DEBUGGER_METHOD_ENTRY -1
33#define DEBUGGER_METHOD_EXIT -2
34
buzbeee3acd072012-02-25 17:03:10 -080035/*
36 * Assembly is an iterative process, and usually terminates within
37 * two or three passes. This should be high enough to handle bizarre
38 * cases, but detect an infinite loop bug.
39 */
40#define MAX_ASSEMBLER_RETRIES 50
41
buzbee67bf8852011-08-17 17:51:35 -070042typedef enum OatInstructionSetType {
43 DALVIK_OAT_NONE = 0,
44 DALVIK_OAT_ARM,
45 DALVIK_OAT_THUMB2,
buzbeee88dfbf2012-03-05 11:19:57 -080046 DALVIK_OAT_X86,
buzbeee3acd072012-02-25 17:03:10 -080047 DALVIK_OAT_MIPS32
buzbee67bf8852011-08-17 17:51:35 -070048} OatInstructionSetType;
49
buzbeece302932011-10-04 14:32:18 -070050/* Supress optimization if corresponding bit set */
51enum optControlVector {
52 kLoadStoreElimination = 0,
53 kLoadHoisting,
54 kSuppressLoads,
55 kNullCheckElimination,
56 kPromoteRegs,
57 kTrackLiveTemps,
buzbee99ba9642012-01-25 14:23:14 -080058 kSkipLargeMethodOptimization,
buzbeece302932011-10-04 14:32:18 -070059};
60
buzbee5abfa3e2012-01-31 17:01:43 -080061/* Type of allocation for memory tuning */
62enum oatAllocKind {
63 kAllocMisc,
64 kAllocBB,
65 kAllocLIR,
66 kAllocMIR,
67 kAllocDFInfo,
68 kAllocGrowableList,
69 kAllocGrowableBitMap,
70 kAllocDalvikToSSAMap,
71 kAllocDebugInfo,
72 kAllocSuccessor,
73 kAllocRegAlloc,
74 kAllocData,
75 kAllocPredecessors,
76 kNumAllocKinds
77};
78
79/* Type of growable list for memory tuning */
80enum oatListKind {
81 kListMisc = 0,
82 kListBlockList,
83 kListSSAtoDalvikMap,
84 kListDfsOrder,
85 kListDfsPostOrder,
86 kListDomPostOrderTraversal,
87 kListThrowLaunchPads,
88 kListSuspendLaunchPads,
89 kListSwitchTables,
90 kListFillArrayData,
91 kListSuccessorBlocks,
92 kListPredecessors,
93 kNumListKinds
94};
95
96/* Type of growable bitmap for memory tuning */
97enum oatBitMapKind {
98 kBitMapMisc = 0,
99 kBitMapUse,
100 kBitMapDef,
101 kBitMapLiveIn,
102 kBitMapBMatrix,
103 kBitMapDominators,
104 kBitMapIDominated,
105 kBitMapDomFrontier,
106 kBitMapPhi,
107 kBitMapTmpBlocks,
108 kBitMapInputBlocks,
109 kBitMapRegisterV,
110 kBitMapTempSSARegisterV,
111 kBitMapNullCheck,
112 kBitMapTmpBlockV,
113 kBitMapPredecessors,
114 kNumBitMapKinds
115};
116
buzbeece302932011-10-04 14:32:18 -0700117extern uint32_t compilerOptimizerDisableFlags;
118
119/* Force code generation paths for testing */
120enum debugControlVector {
121 kDebugDisplayMissingTargets,
122 kDebugVerbose,
123 kDebugDumpCFG,
124 kDebugSlowFieldPath,
125 kDebugSlowInvokePath,
126 kDebugSlowStringPath,
127 kDebugSlowTypePath,
128 kDebugSlowestFieldPath,
129 kDebugSlowestStringPath,
buzbee34c77ad2012-01-11 13:01:32 -0800130 kDebugExerciseResolveMethod,
buzbee5b537102012-01-17 17:33:47 -0800131 kDebugVerifyDataflow,
buzbee5abfa3e2012-01-31 17:01:43 -0800132 kDebugShowMemoryUsage,
buzbeece302932011-10-04 14:32:18 -0700133};
134
135extern uint32_t compilerDebugFlags;
136
137/* If non-empty, apply optimizer/debug flags only to matching methods */
138extern std::string compilerMethodMatch;
139
140/* Flips sense of compilerMethodMatch - apply flags if doesn't match */
141extern bool compilerFlipMatch;
142
buzbee67bf8852011-08-17 17:51:35 -0700143typedef enum OatMethodAttributes {
144 kIsCallee = 0, /* Code is part of a callee (invoked by a hot trace) */
145 kIsHot, /* Code is part of a hot trace */
146 kIsLeaf, /* Method is leaf */
147 kIsEmpty, /* Method is empty */
148 kIsThrowFree, /* Method doesn't throw */
149 kIsGetter, /* Method fits the getter pattern */
150 kIsSetter, /* Method fits the setter pattern */
151 kCannotCompile, /* Method cannot be compiled */
152} OatMethodAttributes;
153
154#define METHOD_IS_CALLEE (1 << kIsCallee)
155#define METHOD_IS_HOT (1 << kIsHot)
156#define METHOD_IS_LEAF (1 << kIsLeaf)
157#define METHOD_IS_EMPTY (1 << kIsEmpty)
158#define METHOD_IS_THROW_FREE (1 << kIsThrowFree)
159#define METHOD_IS_GETTER (1 << kIsGetter)
160#define METHOD_IS_SETTER (1 << kIsSetter)
161#define METHOD_CANNOT_COMPILE (1 << kCannotCompile)
162
163/* Customized node traversal orders for different needs */
164typedef enum DataFlowAnalysisMode {
165 kAllNodes = 0, // All nodes
166 kReachableNodes, // All reachable nodes
167 kPreOrderDFSTraversal, // Depth-First-Search / Pre-Order
168 kPostOrderDFSTraversal, // Depth-First-Search / Post-Order
169 kPostOrderDOMTraversal, // Dominator tree / Post-Order
buzbee5b537102012-01-17 17:33:47 -0800170 kReversePostOrderTraversal, // Depth-First-Search / reverse Post-Order
buzbee67bf8852011-08-17 17:51:35 -0700171} DataFlowAnalysisMode;
172
173struct CompilationUnit;
174struct BasicBlock;
175struct SSARepresentation;
176struct GrowableList;
177struct MIR;
178
buzbeeba938cb2012-02-03 14:47:55 -0800179void oatInit(CompilationUnit* cUnit, const Compiler& compiler);
buzbee67bf8852011-08-17 17:51:35 -0700180bool oatArchInit(void);
buzbee67bf8852011-08-17 17:51:35 -0700181bool oatStartup(void);
182void oatShutdown(void);
Ian Rogers996cc582012-02-14 22:23:29 -0800183CompiledMethod* oatCompileMethod(Compiler& compiler, bool is_direct,
Elliott Hughes11d1b0c2012-01-23 16:57:47 -0800184 uint32_t method_idx, const ClassLoader* class_loader,
185 const DexFile& dex_file, OatInstructionSetType);
buzbee67bf8852011-08-17 17:51:35 -0700186void oatScanAllClassPointers(void (*callback)(void* ptr));
187void oatInitializeSSAConversion(struct CompilationUnit* cUnit);
188int oatConvertSSARegToDalvik(const struct CompilationUnit* cUnit, int ssaReg);
189bool oatFindLocalLiveIn(struct CompilationUnit* cUnit,
190 struct BasicBlock* bb);
191bool oatDoSSAConversion(struct CompilationUnit* cUnit,
192 struct BasicBlock* bb);
193bool oatDoConstantPropagation(struct CompilationUnit* cUnit,
194 struct BasicBlock* bb);
195bool oatFindInductionVariables(struct CompilationUnit* cUnit,
196 struct BasicBlock* bb);
197/* Clear the visited flag for each BB */
198bool oatClearVisitedFlag(struct CompilationUnit* cUnit,
199 struct BasicBlock* bb);
buzbeeba938cb2012-02-03 14:47:55 -0800200char* oatGetDalvikDisassembly(CompilationUnit* cUnit,
201 const DecodedInstruction* insn,
202 const char* note);
203char* oatFullDisassembler(struct CompilationUnit* cUnit,
204 const struct MIR* mir);
Elliott Hughesc1f143d2011-12-01 17:31:10 -0800205char* oatGetSSAString(struct CompilationUnit* cUnit,
buzbee67bf8852011-08-17 17:51:35 -0700206 struct SSARepresentation* ssaRep);
207void oatDataFlowAnalysisDispatcher(struct CompilationUnit* cUnit,
208 bool (*func)(struct CompilationUnit* , struct BasicBlock*),
209 DataFlowAnalysisMode dfaMode,
210 bool isIterative);
211void oatMethodSSATransformation(struct CompilationUnit* cUnit);
212u8 oatGetRegResourceMask(int reg);
213void oatDumpCFG(struct CompilationUnit* cUnit, const char* dirPrefix);
214void oatProcessSwitchTables(CompilationUnit* cUnit);
buzbeee3acd072012-02-25 17:03:10 -0800215bool oatIsFpReg(int reg);
216uint32_t oatFpRegMask(void);
buzbee67bf8852011-08-17 17:51:35 -0700217
Elliott Hughes11d1b0c2012-01-23 16:57:47 -0800218} // namespace art
219
buzbee67bf8852011-08-17 17:51:35 -0700220#endif // ART_SRC_COMPILER_COMPILER_H_