blob: a7dc7989d4f016721bdbfbed5bec746300799ad7 [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,
buzbeee3acd072012-02-25 17:03:10 -080046 DALVIK_OAT_IA32,
47 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,
buzbee44b412b2012-02-04 08:50:53 -080059 kGenCodeForDebugger,
buzbeece302932011-10-04 14:32:18 -070060};
61
buzbee5abfa3e2012-01-31 17:01:43 -080062/* Type of allocation for memory tuning */
63enum oatAllocKind {
64 kAllocMisc,
65 kAllocBB,
66 kAllocLIR,
67 kAllocMIR,
68 kAllocDFInfo,
69 kAllocGrowableList,
70 kAllocGrowableBitMap,
71 kAllocDalvikToSSAMap,
72 kAllocDebugInfo,
73 kAllocSuccessor,
74 kAllocRegAlloc,
75 kAllocData,
76 kAllocPredecessors,
77 kNumAllocKinds
78};
79
80/* Type of growable list for memory tuning */
81enum oatListKind {
82 kListMisc = 0,
83 kListBlockList,
84 kListSSAtoDalvikMap,
85 kListDfsOrder,
86 kListDfsPostOrder,
87 kListDomPostOrderTraversal,
88 kListThrowLaunchPads,
89 kListSuspendLaunchPads,
90 kListSwitchTables,
91 kListFillArrayData,
92 kListSuccessorBlocks,
93 kListPredecessors,
94 kNumListKinds
95};
96
97/* Type of growable bitmap for memory tuning */
98enum oatBitMapKind {
99 kBitMapMisc = 0,
100 kBitMapUse,
101 kBitMapDef,
102 kBitMapLiveIn,
103 kBitMapBMatrix,
104 kBitMapDominators,
105 kBitMapIDominated,
106 kBitMapDomFrontier,
107 kBitMapPhi,
108 kBitMapTmpBlocks,
109 kBitMapInputBlocks,
110 kBitMapRegisterV,
111 kBitMapTempSSARegisterV,
112 kBitMapNullCheck,
113 kBitMapTmpBlockV,
114 kBitMapPredecessors,
115 kNumBitMapKinds
116};
117
buzbeece302932011-10-04 14:32:18 -0700118extern uint32_t compilerOptimizerDisableFlags;
119
120/* Force code generation paths for testing */
121enum debugControlVector {
122 kDebugDisplayMissingTargets,
123 kDebugVerbose,
124 kDebugDumpCFG,
125 kDebugSlowFieldPath,
126 kDebugSlowInvokePath,
127 kDebugSlowStringPath,
128 kDebugSlowTypePath,
129 kDebugSlowestFieldPath,
130 kDebugSlowestStringPath,
buzbee34c77ad2012-01-11 13:01:32 -0800131 kDebugExerciseResolveMethod,
buzbee5b537102012-01-17 17:33:47 -0800132 kDebugVerifyDataflow,
buzbee5abfa3e2012-01-31 17:01:43 -0800133 kDebugShowMemoryUsage,
buzbeece302932011-10-04 14:32:18 -0700134};
135
136extern uint32_t compilerDebugFlags;
137
138/* If non-empty, apply optimizer/debug flags only to matching methods */
139extern std::string compilerMethodMatch;
140
141/* Flips sense of compilerMethodMatch - apply flags if doesn't match */
142extern bool compilerFlipMatch;
143
buzbee67bf8852011-08-17 17:51:35 -0700144typedef enum OatMethodAttributes {
145 kIsCallee = 0, /* Code is part of a callee (invoked by a hot trace) */
146 kIsHot, /* Code is part of a hot trace */
147 kIsLeaf, /* Method is leaf */
148 kIsEmpty, /* Method is empty */
149 kIsThrowFree, /* Method doesn't throw */
150 kIsGetter, /* Method fits the getter pattern */
151 kIsSetter, /* Method fits the setter pattern */
152 kCannotCompile, /* Method cannot be compiled */
153} OatMethodAttributes;
154
155#define METHOD_IS_CALLEE (1 << kIsCallee)
156#define METHOD_IS_HOT (1 << kIsHot)
157#define METHOD_IS_LEAF (1 << kIsLeaf)
158#define METHOD_IS_EMPTY (1 << kIsEmpty)
159#define METHOD_IS_THROW_FREE (1 << kIsThrowFree)
160#define METHOD_IS_GETTER (1 << kIsGetter)
161#define METHOD_IS_SETTER (1 << kIsSetter)
162#define METHOD_CANNOT_COMPILE (1 << kCannotCompile)
163
164/* Customized node traversal orders for different needs */
165typedef enum DataFlowAnalysisMode {
166 kAllNodes = 0, // All nodes
167 kReachableNodes, // All reachable nodes
168 kPreOrderDFSTraversal, // Depth-First-Search / Pre-Order
169 kPostOrderDFSTraversal, // Depth-First-Search / Post-Order
170 kPostOrderDOMTraversal, // Dominator tree / Post-Order
buzbee5b537102012-01-17 17:33:47 -0800171 kReversePostOrderTraversal, // Depth-First-Search / reverse Post-Order
buzbee67bf8852011-08-17 17:51:35 -0700172} DataFlowAnalysisMode;
173
174struct CompilationUnit;
175struct BasicBlock;
176struct SSARepresentation;
177struct GrowableList;
178struct MIR;
179
buzbeeba938cb2012-02-03 14:47:55 -0800180void oatInit(CompilationUnit* cUnit, const Compiler& compiler);
buzbee67bf8852011-08-17 17:51:35 -0700181bool oatArchInit(void);
182void oatArchDump(void);
183bool oatStartup(void);
184void oatShutdown(void);
Ian Rogers996cc582012-02-14 22:23:29 -0800185CompiledMethod* oatCompileMethod(Compiler& compiler, bool is_direct,
Elliott Hughes11d1b0c2012-01-23 16:57:47 -0800186 uint32_t method_idx, const ClassLoader* class_loader,
187 const DexFile& dex_file, OatInstructionSetType);
buzbee67bf8852011-08-17 17:51:35 -0700188void oatDumpStats(void);
189void oatScanAllClassPointers(void (*callback)(void* ptr));
190void oatInitializeSSAConversion(struct CompilationUnit* cUnit);
191int oatConvertSSARegToDalvik(const struct CompilationUnit* cUnit, int ssaReg);
192bool oatFindLocalLiveIn(struct CompilationUnit* cUnit,
193 struct BasicBlock* bb);
194bool oatDoSSAConversion(struct CompilationUnit* cUnit,
195 struct BasicBlock* bb);
196bool oatDoConstantPropagation(struct CompilationUnit* cUnit,
197 struct BasicBlock* bb);
198bool oatFindInductionVariables(struct CompilationUnit* cUnit,
199 struct BasicBlock* bb);
200/* Clear the visited flag for each BB */
201bool oatClearVisitedFlag(struct CompilationUnit* cUnit,
202 struct BasicBlock* bb);
buzbeeba938cb2012-02-03 14:47:55 -0800203char* oatGetDalvikDisassembly(CompilationUnit* cUnit,
204 const DecodedInstruction* insn,
205 const char* note);
206char* oatFullDisassembler(struct CompilationUnit* cUnit,
207 const struct MIR* mir);
Elliott Hughesc1f143d2011-12-01 17:31:10 -0800208char* oatGetSSAString(struct CompilationUnit* cUnit,
buzbee67bf8852011-08-17 17:51:35 -0700209 struct SSARepresentation* ssaRep);
210void oatDataFlowAnalysisDispatcher(struct CompilationUnit* cUnit,
211 bool (*func)(struct CompilationUnit* , struct BasicBlock*),
212 DataFlowAnalysisMode dfaMode,
213 bool isIterative);
214void oatMethodSSATransformation(struct CompilationUnit* cUnit);
215u8 oatGetRegResourceMask(int reg);
216void oatDumpCFG(struct CompilationUnit* cUnit, const char* dirPrefix);
217void oatProcessSwitchTables(CompilationUnit* cUnit);
buzbeee3acd072012-02-25 17:03:10 -0800218bool oatIsFpReg(int reg);
219uint32_t oatFpRegMask(void);
buzbee67bf8852011-08-17 17:51:35 -0700220
Elliott Hughes11d1b0c2012-01-23 16:57:47 -0800221} // namespace art
222
buzbee67bf8852011-08-17 17:51:35 -0700223#endif // ART_SRC_COMPILER_COMPILER_H_