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