blob: 16a48dfc21b31f4a4fcb935b5e1eb670acf33f3b [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
buzbee67bf8852011-08-17 17:51:35 -070035typedef enum OatInstructionSetType {
36 DALVIK_OAT_NONE = 0,
37 DALVIK_OAT_ARM,
38 DALVIK_OAT_THUMB2,
39} OatInstructionSetType;
40
buzbeece302932011-10-04 14:32:18 -070041/* Supress optimization if corresponding bit set */
42enum optControlVector {
43 kLoadStoreElimination = 0,
44 kLoadHoisting,
45 kSuppressLoads,
46 kNullCheckElimination,
47 kPromoteRegs,
48 kTrackLiveTemps,
buzbee99ba9642012-01-25 14:23:14 -080049 kSkipLargeMethodOptimization,
buzbee44b412b2012-02-04 08:50:53 -080050 kGenCodeForDebugger,
buzbeece302932011-10-04 14:32:18 -070051};
52
buzbee5abfa3e2012-01-31 17:01:43 -080053/* Type of allocation for memory tuning */
54enum oatAllocKind {
55 kAllocMisc,
56 kAllocBB,
57 kAllocLIR,
58 kAllocMIR,
59 kAllocDFInfo,
60 kAllocGrowableList,
61 kAllocGrowableBitMap,
62 kAllocDalvikToSSAMap,
63 kAllocDebugInfo,
64 kAllocSuccessor,
65 kAllocRegAlloc,
66 kAllocData,
67 kAllocPredecessors,
68 kNumAllocKinds
69};
70
71/* Type of growable list for memory tuning */
72enum oatListKind {
73 kListMisc = 0,
74 kListBlockList,
75 kListSSAtoDalvikMap,
76 kListDfsOrder,
77 kListDfsPostOrder,
78 kListDomPostOrderTraversal,
79 kListThrowLaunchPads,
80 kListSuspendLaunchPads,
81 kListSwitchTables,
82 kListFillArrayData,
83 kListSuccessorBlocks,
84 kListPredecessors,
85 kNumListKinds
86};
87
88/* Type of growable bitmap for memory tuning */
89enum oatBitMapKind {
90 kBitMapMisc = 0,
91 kBitMapUse,
92 kBitMapDef,
93 kBitMapLiveIn,
94 kBitMapBMatrix,
95 kBitMapDominators,
96 kBitMapIDominated,
97 kBitMapDomFrontier,
98 kBitMapPhi,
99 kBitMapTmpBlocks,
100 kBitMapInputBlocks,
101 kBitMapRegisterV,
102 kBitMapTempSSARegisterV,
103 kBitMapNullCheck,
104 kBitMapTmpBlockV,
105 kBitMapPredecessors,
106 kNumBitMapKinds
107};
108
buzbeece302932011-10-04 14:32:18 -0700109extern uint32_t compilerOptimizerDisableFlags;
110
111/* Force code generation paths for testing */
112enum debugControlVector {
113 kDebugDisplayMissingTargets,
114 kDebugVerbose,
115 kDebugDumpCFG,
116 kDebugSlowFieldPath,
117 kDebugSlowInvokePath,
118 kDebugSlowStringPath,
119 kDebugSlowTypePath,
120 kDebugSlowestFieldPath,
121 kDebugSlowestStringPath,
buzbee34c77ad2012-01-11 13:01:32 -0800122 kDebugExerciseResolveMethod,
buzbee5b537102012-01-17 17:33:47 -0800123 kDebugVerifyDataflow,
buzbee5abfa3e2012-01-31 17:01:43 -0800124 kDebugShowMemoryUsage,
buzbeece302932011-10-04 14:32:18 -0700125};
126
127extern uint32_t compilerDebugFlags;
128
129/* If non-empty, apply optimizer/debug flags only to matching methods */
130extern std::string compilerMethodMatch;
131
132/* Flips sense of compilerMethodMatch - apply flags if doesn't match */
133extern bool compilerFlipMatch;
134
buzbee67bf8852011-08-17 17:51:35 -0700135typedef enum OatMethodAttributes {
136 kIsCallee = 0, /* Code is part of a callee (invoked by a hot trace) */
137 kIsHot, /* Code is part of a hot trace */
138 kIsLeaf, /* Method is leaf */
139 kIsEmpty, /* Method is empty */
140 kIsThrowFree, /* Method doesn't throw */
141 kIsGetter, /* Method fits the getter pattern */
142 kIsSetter, /* Method fits the setter pattern */
143 kCannotCompile, /* Method cannot be compiled */
144} OatMethodAttributes;
145
146#define METHOD_IS_CALLEE (1 << kIsCallee)
147#define METHOD_IS_HOT (1 << kIsHot)
148#define METHOD_IS_LEAF (1 << kIsLeaf)
149#define METHOD_IS_EMPTY (1 << kIsEmpty)
150#define METHOD_IS_THROW_FREE (1 << kIsThrowFree)
151#define METHOD_IS_GETTER (1 << kIsGetter)
152#define METHOD_IS_SETTER (1 << kIsSetter)
153#define METHOD_CANNOT_COMPILE (1 << kCannotCompile)
154
155/* Customized node traversal orders for different needs */
156typedef enum DataFlowAnalysisMode {
157 kAllNodes = 0, // All nodes
158 kReachableNodes, // All reachable nodes
159 kPreOrderDFSTraversal, // Depth-First-Search / Pre-Order
160 kPostOrderDFSTraversal, // Depth-First-Search / Post-Order
161 kPostOrderDOMTraversal, // Dominator tree / Post-Order
buzbee5b537102012-01-17 17:33:47 -0800162 kReversePostOrderTraversal, // Depth-First-Search / reverse Post-Order
buzbee67bf8852011-08-17 17:51:35 -0700163} DataFlowAnalysisMode;
164
165struct CompilationUnit;
166struct BasicBlock;
167struct SSARepresentation;
168struct GrowableList;
169struct MIR;
170
buzbeeba938cb2012-02-03 14:47:55 -0800171void oatInit(CompilationUnit* cUnit, const Compiler& compiler);
buzbee67bf8852011-08-17 17:51:35 -0700172bool oatArchInit(void);
173void oatArchDump(void);
174bool oatStartup(void);
175void oatShutdown(void);
Ian Rogers996cc582012-02-14 22:23:29 -0800176CompiledMethod* oatCompileMethod(Compiler& compiler, bool is_direct,
Elliott Hughes11d1b0c2012-01-23 16:57:47 -0800177 uint32_t method_idx, const ClassLoader* class_loader,
178 const DexFile& dex_file, OatInstructionSetType);
buzbee67bf8852011-08-17 17:51:35 -0700179void oatDumpStats(void);
180void oatScanAllClassPointers(void (*callback)(void* ptr));
181void oatInitializeSSAConversion(struct CompilationUnit* cUnit);
182int oatConvertSSARegToDalvik(const struct CompilationUnit* cUnit, int ssaReg);
183bool oatFindLocalLiveIn(struct CompilationUnit* cUnit,
184 struct BasicBlock* bb);
185bool oatDoSSAConversion(struct CompilationUnit* cUnit,
186 struct BasicBlock* bb);
187bool oatDoConstantPropagation(struct CompilationUnit* cUnit,
188 struct BasicBlock* bb);
189bool oatFindInductionVariables(struct CompilationUnit* cUnit,
190 struct BasicBlock* bb);
191/* Clear the visited flag for each BB */
192bool oatClearVisitedFlag(struct CompilationUnit* cUnit,
193 struct BasicBlock* bb);
buzbeeba938cb2012-02-03 14:47:55 -0800194char* oatGetDalvikDisassembly(CompilationUnit* cUnit,
195 const DecodedInstruction* insn,
196 const char* note);
197char* oatFullDisassembler(struct CompilationUnit* cUnit,
198 const struct MIR* mir);
Elliott Hughesc1f143d2011-12-01 17:31:10 -0800199char* oatGetSSAString(struct CompilationUnit* cUnit,
buzbee67bf8852011-08-17 17:51:35 -0700200 struct SSARepresentation* ssaRep);
201void oatDataFlowAnalysisDispatcher(struct CompilationUnit* cUnit,
202 bool (*func)(struct CompilationUnit* , struct BasicBlock*),
203 DataFlowAnalysisMode dfaMode,
204 bool isIterative);
205void oatMethodSSATransformation(struct CompilationUnit* cUnit);
206u8 oatGetRegResourceMask(int reg);
207void oatDumpCFG(struct CompilationUnit* cUnit, const char* dirPrefix);
208void oatProcessSwitchTables(CompilationUnit* cUnit);
209
Elliott Hughes11d1b0c2012-01-23 16:57:47 -0800210} // namespace art
211
buzbee67bf8852011-08-17 17:51:35 -0700212#endif // ART_SRC_COMPILER_COMPILER_H_