blob: 8636e11b368474249c3354053c155c71b0f0d085 [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
Elliott Hughesb3bd5f02012-03-08 21:05:27 -080043/* Suppress optimization if corresponding bit set */
buzbeece302932011-10-04 14:32:18 -070044enum optControlVector {
45 kLoadStoreElimination = 0,
46 kLoadHoisting,
47 kSuppressLoads,
48 kNullCheckElimination,
49 kPromoteRegs,
50 kTrackLiveTemps,
buzbee99ba9642012-01-25 14:23:14 -080051 kSkipLargeMethodOptimization,
buzbee86a4bce2012-03-06 18:15:00 -080052 kSafeOptimizations,
buzbeece302932011-10-04 14:32:18 -070053};
54
buzbee5abfa3e2012-01-31 17:01:43 -080055/* Type of allocation for memory tuning */
56enum oatAllocKind {
57 kAllocMisc,
58 kAllocBB,
59 kAllocLIR,
60 kAllocMIR,
61 kAllocDFInfo,
62 kAllocGrowableList,
63 kAllocGrowableBitMap,
64 kAllocDalvikToSSAMap,
65 kAllocDebugInfo,
66 kAllocSuccessor,
67 kAllocRegAlloc,
68 kAllocData,
69 kAllocPredecessors,
70 kNumAllocKinds
71};
72
73/* Type of growable list for memory tuning */
74enum oatListKind {
75 kListMisc = 0,
76 kListBlockList,
77 kListSSAtoDalvikMap,
78 kListDfsOrder,
79 kListDfsPostOrder,
80 kListDomPostOrderTraversal,
81 kListThrowLaunchPads,
82 kListSuspendLaunchPads,
83 kListSwitchTables,
84 kListFillArrayData,
85 kListSuccessorBlocks,
86 kListPredecessors,
87 kNumListKinds
88};
89
90/* Type of growable bitmap for memory tuning */
91enum oatBitMapKind {
92 kBitMapMisc = 0,
93 kBitMapUse,
94 kBitMapDef,
95 kBitMapLiveIn,
96 kBitMapBMatrix,
97 kBitMapDominators,
98 kBitMapIDominated,
99 kBitMapDomFrontier,
100 kBitMapPhi,
101 kBitMapTmpBlocks,
102 kBitMapInputBlocks,
103 kBitMapRegisterV,
104 kBitMapTempSSARegisterV,
105 kBitMapNullCheck,
106 kBitMapTmpBlockV,
107 kBitMapPredecessors,
108 kNumBitMapKinds
109};
110
buzbeece302932011-10-04 14:32:18 -0700111extern uint32_t compilerOptimizerDisableFlags;
112
113/* Force code generation paths for testing */
114enum debugControlVector {
115 kDebugDisplayMissingTargets,
116 kDebugVerbose,
117 kDebugDumpCFG,
118 kDebugSlowFieldPath,
119 kDebugSlowInvokePath,
120 kDebugSlowStringPath,
121 kDebugSlowTypePath,
122 kDebugSlowestFieldPath,
123 kDebugSlowestStringPath,
buzbee34c77ad2012-01-11 13:01:32 -0800124 kDebugExerciseResolveMethod,
buzbee5b537102012-01-17 17:33:47 -0800125 kDebugVerifyDataflow,
buzbee5abfa3e2012-01-31 17:01:43 -0800126 kDebugShowMemoryUsage,
buzbee86a4bce2012-03-06 18:15:00 -0800127 kDebugShowNops,
buzbeece302932011-10-04 14:32:18 -0700128};
129
130extern uint32_t compilerDebugFlags;
131
132/* If non-empty, apply optimizer/debug flags only to matching methods */
133extern std::string compilerMethodMatch;
134
135/* Flips sense of compilerMethodMatch - apply flags if doesn't match */
136extern bool compilerFlipMatch;
137
buzbee67bf8852011-08-17 17:51:35 -0700138typedef enum OatMethodAttributes {
139 kIsCallee = 0, /* Code is part of a callee (invoked by a hot trace) */
140 kIsHot, /* Code is part of a hot trace */
141 kIsLeaf, /* Method is leaf */
142 kIsEmpty, /* Method is empty */
143 kIsThrowFree, /* Method doesn't throw */
144 kIsGetter, /* Method fits the getter pattern */
145 kIsSetter, /* Method fits the setter pattern */
146 kCannotCompile, /* Method cannot be compiled */
147} OatMethodAttributes;
148
149#define METHOD_IS_CALLEE (1 << kIsCallee)
150#define METHOD_IS_HOT (1 << kIsHot)
151#define METHOD_IS_LEAF (1 << kIsLeaf)
152#define METHOD_IS_EMPTY (1 << kIsEmpty)
153#define METHOD_IS_THROW_FREE (1 << kIsThrowFree)
154#define METHOD_IS_GETTER (1 << kIsGetter)
155#define METHOD_IS_SETTER (1 << kIsSetter)
156#define METHOD_CANNOT_COMPILE (1 << kCannotCompile)
157
158/* Customized node traversal orders for different needs */
159typedef enum DataFlowAnalysisMode {
160 kAllNodes = 0, // All nodes
161 kReachableNodes, // All reachable nodes
162 kPreOrderDFSTraversal, // Depth-First-Search / Pre-Order
163 kPostOrderDFSTraversal, // Depth-First-Search / Post-Order
164 kPostOrderDOMTraversal, // Dominator tree / Post-Order
buzbee5b537102012-01-17 17:33:47 -0800165 kReversePostOrderTraversal, // Depth-First-Search / reverse Post-Order
buzbee67bf8852011-08-17 17:51:35 -0700166} DataFlowAnalysisMode;
167
168struct CompilationUnit;
169struct BasicBlock;
170struct SSARepresentation;
171struct GrowableList;
172struct MIR;
173
buzbeeba938cb2012-02-03 14:47:55 -0800174void oatInit(CompilationUnit* cUnit, const Compiler& compiler);
buzbee67bf8852011-08-17 17:51:35 -0700175bool oatArchInit(void);
buzbee67bf8852011-08-17 17:51:35 -0700176bool oatStartup(void);
177void oatShutdown(void);
buzbee67bf8852011-08-17 17:51:35 -0700178void oatScanAllClassPointers(void (*callback)(void* ptr));
179void oatInitializeSSAConversion(struct CompilationUnit* cUnit);
180int oatConvertSSARegToDalvik(const struct CompilationUnit* cUnit, int ssaReg);
181bool oatFindLocalLiveIn(struct CompilationUnit* cUnit,
182 struct BasicBlock* bb);
183bool oatDoSSAConversion(struct CompilationUnit* cUnit,
184 struct BasicBlock* bb);
185bool oatDoConstantPropagation(struct CompilationUnit* cUnit,
186 struct BasicBlock* bb);
187bool oatFindInductionVariables(struct CompilationUnit* cUnit,
188 struct BasicBlock* bb);
189/* Clear the visited flag for each BB */
190bool oatClearVisitedFlag(struct CompilationUnit* cUnit,
191 struct BasicBlock* bb);
buzbeeba938cb2012-02-03 14:47:55 -0800192char* oatGetDalvikDisassembly(CompilationUnit* cUnit,
Elliott Hughesadb8c672012-03-06 16:49:32 -0800193 const DecodedInstruction& insn,
buzbeeba938cb2012-02-03 14:47:55 -0800194 const char* note);
195char* oatFullDisassembler(struct CompilationUnit* cUnit,
196 const struct MIR* mir);
Elliott Hughesc1f143d2011-12-01 17:31:10 -0800197char* oatGetSSAString(struct CompilationUnit* cUnit,
buzbee67bf8852011-08-17 17:51:35 -0700198 struct SSARepresentation* ssaRep);
199void oatDataFlowAnalysisDispatcher(struct CompilationUnit* cUnit,
200 bool (*func)(struct CompilationUnit* , struct BasicBlock*),
201 DataFlowAnalysisMode dfaMode,
202 bool isIterative);
203void oatMethodSSATransformation(struct CompilationUnit* cUnit);
204u8 oatGetRegResourceMask(int reg);
205void oatDumpCFG(struct CompilationUnit* cUnit, const char* dirPrefix);
206void oatProcessSwitchTables(CompilationUnit* cUnit);
buzbeee3acd072012-02-25 17:03:10 -0800207bool oatIsFpReg(int reg);
208uint32_t oatFpRegMask(void);
buzbee67bf8852011-08-17 17:51:35 -0700209
Elliott Hughes11d1b0c2012-01-23 16:57:47 -0800210} // namespace art
211
Elliott Hughesb3bd5f02012-03-08 21:05:27 -0800212extern "C" art::CompiledMethod* oatCompileMethod(art::Compiler& compiler,
213 const art::DexFile::CodeItem* code_item,
214 uint32_t access_flags, uint32_t method_idx,
215 const art::ClassLoader* class_loader,
216 const art::DexFile& dex_file);
217
buzbee67bf8852011-08-17 17:51:35 -0700218#endif // ART_SRC_COMPILER_COMPILER_H_