blob: 1e0439be36f350653c054c549056d93d61a7cc8d [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
Elliott Hughes11d1b0c2012-01-23 16:57:47 -080023namespace art {
24
buzbee67bf8852011-08-17 17:51:35 -070025#define COMPILER_TRACED(X)
26#define COMPILER_TRACEE(X)
27
buzbee44b412b2012-02-04 08:50:53 -080028/*
29 * Special offsets to denote method entry/exit for debugger update.
30 * NOTE: bit pattern must be loadable using 1 instruction and must
31 * not be a valid Dalvik offset.
32 */
33#define DEBUGGER_METHOD_ENTRY -1
34#define DEBUGGER_METHOD_EXIT -2
35
buzbeee3acd072012-02-25 17:03:10 -080036/*
37 * Assembly is an iterative process, and usually terminates within
38 * two or three passes. This should be high enough to handle bizarre
39 * cases, but detect an infinite loop bug.
40 */
41#define MAX_ASSEMBLER_RETRIES 50
42
buzbee67bf8852011-08-17 17:51:35 -070043typedef enum OatInstructionSetType {
44 DALVIK_OAT_NONE = 0,
45 DALVIK_OAT_ARM,
46 DALVIK_OAT_THUMB2,
buzbeee88dfbf2012-03-05 11:19:57 -080047 DALVIK_OAT_X86,
buzbeee3acd072012-02-25 17:03:10 -080048 DALVIK_OAT_MIPS32
buzbee67bf8852011-08-17 17:51:35 -070049} OatInstructionSetType;
50
buzbeece302932011-10-04 14:32:18 -070051/* Supress optimization if corresponding bit set */
52enum optControlVector {
53 kLoadStoreElimination = 0,
54 kLoadHoisting,
55 kSuppressLoads,
56 kNullCheckElimination,
57 kPromoteRegs,
58 kTrackLiveTemps,
buzbee99ba9642012-01-25 14:23:14 -080059 kSkipLargeMethodOptimization,
buzbee86a4bce2012-03-06 18:15:00 -080060 kSafeOptimizations,
buzbeece302932011-10-04 14:32:18 -070061};
62
buzbee5abfa3e2012-01-31 17:01:43 -080063/* Type of allocation for memory tuning */
64enum oatAllocKind {
65 kAllocMisc,
66 kAllocBB,
67 kAllocLIR,
68 kAllocMIR,
69 kAllocDFInfo,
70 kAllocGrowableList,
71 kAllocGrowableBitMap,
72 kAllocDalvikToSSAMap,
73 kAllocDebugInfo,
74 kAllocSuccessor,
75 kAllocRegAlloc,
76 kAllocData,
77 kAllocPredecessors,
78 kNumAllocKinds
79};
80
81/* Type of growable list for memory tuning */
82enum oatListKind {
83 kListMisc = 0,
84 kListBlockList,
85 kListSSAtoDalvikMap,
86 kListDfsOrder,
87 kListDfsPostOrder,
88 kListDomPostOrderTraversal,
89 kListThrowLaunchPads,
90 kListSuspendLaunchPads,
91 kListSwitchTables,
92 kListFillArrayData,
93 kListSuccessorBlocks,
94 kListPredecessors,
95 kNumListKinds
96};
97
98/* Type of growable bitmap for memory tuning */
99enum oatBitMapKind {
100 kBitMapMisc = 0,
101 kBitMapUse,
102 kBitMapDef,
103 kBitMapLiveIn,
104 kBitMapBMatrix,
105 kBitMapDominators,
106 kBitMapIDominated,
107 kBitMapDomFrontier,
108 kBitMapPhi,
109 kBitMapTmpBlocks,
110 kBitMapInputBlocks,
111 kBitMapRegisterV,
112 kBitMapTempSSARegisterV,
113 kBitMapNullCheck,
114 kBitMapTmpBlockV,
115 kBitMapPredecessors,
116 kNumBitMapKinds
117};
118
buzbeece302932011-10-04 14:32:18 -0700119extern uint32_t compilerOptimizerDisableFlags;
120
121/* Force code generation paths for testing */
122enum debugControlVector {
123 kDebugDisplayMissingTargets,
124 kDebugVerbose,
125 kDebugDumpCFG,
126 kDebugSlowFieldPath,
127 kDebugSlowInvokePath,
128 kDebugSlowStringPath,
129 kDebugSlowTypePath,
130 kDebugSlowestFieldPath,
131 kDebugSlowestStringPath,
buzbee34c77ad2012-01-11 13:01:32 -0800132 kDebugExerciseResolveMethod,
buzbee5b537102012-01-17 17:33:47 -0800133 kDebugVerifyDataflow,
buzbee5abfa3e2012-01-31 17:01:43 -0800134 kDebugShowMemoryUsage,
buzbee86a4bce2012-03-06 18:15:00 -0800135 kDebugShowNops,
buzbeece302932011-10-04 14:32:18 -0700136};
137
138extern uint32_t compilerDebugFlags;
139
140/* If non-empty, apply optimizer/debug flags only to matching methods */
141extern std::string compilerMethodMatch;
142
143/* Flips sense of compilerMethodMatch - apply flags if doesn't match */
144extern bool compilerFlipMatch;
145
buzbee67bf8852011-08-17 17:51:35 -0700146typedef enum OatMethodAttributes {
147 kIsCallee = 0, /* Code is part of a callee (invoked by a hot trace) */
148 kIsHot, /* Code is part of a hot trace */
149 kIsLeaf, /* Method is leaf */
150 kIsEmpty, /* Method is empty */
151 kIsThrowFree, /* Method doesn't throw */
152 kIsGetter, /* Method fits the getter pattern */
153 kIsSetter, /* Method fits the setter pattern */
154 kCannotCompile, /* Method cannot be compiled */
155} OatMethodAttributes;
156
157#define METHOD_IS_CALLEE (1 << kIsCallee)
158#define METHOD_IS_HOT (1 << kIsHot)
159#define METHOD_IS_LEAF (1 << kIsLeaf)
160#define METHOD_IS_EMPTY (1 << kIsEmpty)
161#define METHOD_IS_THROW_FREE (1 << kIsThrowFree)
162#define METHOD_IS_GETTER (1 << kIsGetter)
163#define METHOD_IS_SETTER (1 << kIsSetter)
164#define METHOD_CANNOT_COMPILE (1 << kCannotCompile)
165
166/* Customized node traversal orders for different needs */
167typedef enum DataFlowAnalysisMode {
168 kAllNodes = 0, // All nodes
169 kReachableNodes, // All reachable nodes
170 kPreOrderDFSTraversal, // Depth-First-Search / Pre-Order
171 kPostOrderDFSTraversal, // Depth-First-Search / Post-Order
172 kPostOrderDOMTraversal, // Dominator tree / Post-Order
buzbee5b537102012-01-17 17:33:47 -0800173 kReversePostOrderTraversal, // Depth-First-Search / reverse Post-Order
buzbee67bf8852011-08-17 17:51:35 -0700174} DataFlowAnalysisMode;
175
176struct CompilationUnit;
177struct BasicBlock;
178struct SSARepresentation;
179struct GrowableList;
180struct MIR;
181
buzbeeba938cb2012-02-03 14:47:55 -0800182void oatInit(CompilationUnit* cUnit, const Compiler& compiler);
buzbee67bf8852011-08-17 17:51:35 -0700183bool oatArchInit(void);
buzbee67bf8852011-08-17 17:51:35 -0700184bool oatStartup(void);
185void oatShutdown(void);
Ian Rogers996cc582012-02-14 22:23:29 -0800186CompiledMethod* oatCompileMethod(Compiler& compiler, bool is_direct,
Elliott Hughes11d1b0c2012-01-23 16:57:47 -0800187 uint32_t method_idx, const ClassLoader* class_loader,
188 const DexFile& dex_file, OatInstructionSetType);
buzbee67bf8852011-08-17 17:51:35 -0700189void 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,
Elliott Hughesadb8c672012-03-06 16:49:32 -0800204 const DecodedInstruction& insn,
buzbeeba938cb2012-02-03 14:47:55 -0800205 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_