blob: a1f7ffb4482c3923ad95b09032da8dac9bc63184 [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,
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);
buzbee67bf8852011-08-17 17:51:35 -0700182bool oatStartup(void);
183void oatShutdown(void);
Ian Rogers996cc582012-02-14 22:23:29 -0800184CompiledMethod* oatCompileMethod(Compiler& compiler, bool is_direct,
Elliott Hughes11d1b0c2012-01-23 16:57:47 -0800185 uint32_t method_idx, const ClassLoader* class_loader,
186 const DexFile& dex_file, OatInstructionSetType);
buzbee67bf8852011-08-17 17:51:35 -0700187void oatScanAllClassPointers(void (*callback)(void* ptr));
188void oatInitializeSSAConversion(struct CompilationUnit* cUnit);
189int oatConvertSSARegToDalvik(const struct CompilationUnit* cUnit, int ssaReg);
190bool oatFindLocalLiveIn(struct CompilationUnit* cUnit,
191 struct BasicBlock* bb);
192bool oatDoSSAConversion(struct CompilationUnit* cUnit,
193 struct BasicBlock* bb);
194bool oatDoConstantPropagation(struct CompilationUnit* cUnit,
195 struct BasicBlock* bb);
196bool oatFindInductionVariables(struct CompilationUnit* cUnit,
197 struct BasicBlock* bb);
198/* Clear the visited flag for each BB */
199bool oatClearVisitedFlag(struct CompilationUnit* cUnit,
200 struct BasicBlock* bb);
buzbeeba938cb2012-02-03 14:47:55 -0800201char* oatGetDalvikDisassembly(CompilationUnit* cUnit,
Elliott Hughesadb8c672012-03-06 16:49:32 -0800202 const DecodedInstruction& insn,
buzbeeba938cb2012-02-03 14:47:55 -0800203 const char* note);
204char* oatFullDisassembler(struct CompilationUnit* cUnit,
205 const struct MIR* mir);
Elliott Hughesc1f143d2011-12-01 17:31:10 -0800206char* oatGetSSAString(struct CompilationUnit* cUnit,
buzbee67bf8852011-08-17 17:51:35 -0700207 struct SSARepresentation* ssaRep);
208void oatDataFlowAnalysisDispatcher(struct CompilationUnit* cUnit,
209 bool (*func)(struct CompilationUnit* , struct BasicBlock*),
210 DataFlowAnalysisMode dfaMode,
211 bool isIterative);
212void oatMethodSSATransformation(struct CompilationUnit* cUnit);
213u8 oatGetRegResourceMask(int reg);
214void oatDumpCFG(struct CompilationUnit* cUnit, const char* dirPrefix);
215void oatProcessSwitchTables(CompilationUnit* cUnit);
buzbeee3acd072012-02-25 17:03:10 -0800216bool oatIsFpReg(int reg);
217uint32_t oatFpRegMask(void);
buzbee67bf8852011-08-17 17:51:35 -0700218
Elliott Hughes11d1b0c2012-01-23 16:57:47 -0800219} // namespace art
220
buzbee67bf8852011-08-17 17:51:35 -0700221#endif // ART_SRC_COMPILER_COMPILER_H_