blob: 94d20e5caf4bf47de6aab4c1ee920038a6356186 [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,
buzbeee1965672012-03-11 18:39:19 -070053 kBBOpt,
buzbeece302932011-10-04 14:32:18 -070054};
55
buzbee5abfa3e2012-01-31 17:01:43 -080056/* Type of allocation for memory tuning */
57enum oatAllocKind {
58 kAllocMisc,
59 kAllocBB,
60 kAllocLIR,
61 kAllocMIR,
62 kAllocDFInfo,
63 kAllocGrowableList,
64 kAllocGrowableBitMap,
65 kAllocDalvikToSSAMap,
66 kAllocDebugInfo,
67 kAllocSuccessor,
68 kAllocRegAlloc,
69 kAllocData,
70 kAllocPredecessors,
71 kNumAllocKinds
72};
73
74/* Type of growable list for memory tuning */
75enum oatListKind {
76 kListMisc = 0,
77 kListBlockList,
78 kListSSAtoDalvikMap,
79 kListDfsOrder,
80 kListDfsPostOrder,
81 kListDomPostOrderTraversal,
82 kListThrowLaunchPads,
83 kListSuspendLaunchPads,
84 kListSwitchTables,
85 kListFillArrayData,
86 kListSuccessorBlocks,
87 kListPredecessors,
88 kNumListKinds
89};
90
91/* Type of growable bitmap for memory tuning */
92enum oatBitMapKind {
93 kBitMapMisc = 0,
94 kBitMapUse,
95 kBitMapDef,
96 kBitMapLiveIn,
97 kBitMapBMatrix,
98 kBitMapDominators,
99 kBitMapIDominated,
100 kBitMapDomFrontier,
101 kBitMapPhi,
102 kBitMapTmpBlocks,
103 kBitMapInputBlocks,
104 kBitMapRegisterV,
105 kBitMapTempSSARegisterV,
106 kBitMapNullCheck,
107 kBitMapTmpBlockV,
108 kBitMapPredecessors,
109 kNumBitMapKinds
110};
111
buzbeece302932011-10-04 14:32:18 -0700112extern uint32_t compilerOptimizerDisableFlags;
113
114/* Force code generation paths for testing */
115enum debugControlVector {
116 kDebugDisplayMissingTargets,
117 kDebugVerbose,
118 kDebugDumpCFG,
119 kDebugSlowFieldPath,
120 kDebugSlowInvokePath,
121 kDebugSlowStringPath,
122 kDebugSlowTypePath,
123 kDebugSlowestFieldPath,
124 kDebugSlowestStringPath,
buzbee34c77ad2012-01-11 13:01:32 -0800125 kDebugExerciseResolveMethod,
buzbee5b537102012-01-17 17:33:47 -0800126 kDebugVerifyDataflow,
buzbee5abfa3e2012-01-31 17:01:43 -0800127 kDebugShowMemoryUsage,
buzbee86a4bce2012-03-06 18:15:00 -0800128 kDebugShowNops,
buzbeece302932011-10-04 14:32:18 -0700129};
130
131extern uint32_t compilerDebugFlags;
132
133/* If non-empty, apply optimizer/debug flags only to matching methods */
134extern std::string compilerMethodMatch;
135
136/* Flips sense of compilerMethodMatch - apply flags if doesn't match */
137extern bool compilerFlipMatch;
138
Elliott Hughes719ace42012-03-09 18:06:03 -0800139enum OatMethodAttributes {
buzbee67bf8852011-08-17 17:51:35 -0700140 kIsCallee = 0, /* Code is part of a callee (invoked by a hot trace) */
141 kIsHot, /* Code is part of a hot trace */
142 kIsLeaf, /* Method is leaf */
143 kIsEmpty, /* Method is empty */
144 kIsThrowFree, /* Method doesn't throw */
145 kIsGetter, /* Method fits the getter pattern */
146 kIsSetter, /* Method fits the setter pattern */
147 kCannotCompile, /* Method cannot be compiled */
Elliott Hughes719ace42012-03-09 18:06:03 -0800148};
buzbee67bf8852011-08-17 17:51:35 -0700149
150#define METHOD_IS_CALLEE (1 << kIsCallee)
151#define METHOD_IS_HOT (1 << kIsHot)
152#define METHOD_IS_LEAF (1 << kIsLeaf)
153#define METHOD_IS_EMPTY (1 << kIsEmpty)
154#define METHOD_IS_THROW_FREE (1 << kIsThrowFree)
155#define METHOD_IS_GETTER (1 << kIsGetter)
156#define METHOD_IS_SETTER (1 << kIsSetter)
157#define METHOD_CANNOT_COMPILE (1 << kCannotCompile)
158
159/* Customized node traversal orders for different needs */
Elliott Hughes719ace42012-03-09 18:06:03 -0800160enum DataFlowAnalysisMode {
buzbee67bf8852011-08-17 17:51:35 -0700161 kAllNodes = 0, // All nodes
162 kReachableNodes, // All reachable nodes
163 kPreOrderDFSTraversal, // Depth-First-Search / Pre-Order
164 kPostOrderDFSTraversal, // Depth-First-Search / Post-Order
165 kPostOrderDOMTraversal, // Dominator tree / Post-Order
buzbee5b537102012-01-17 17:33:47 -0800166 kReversePostOrderTraversal, // Depth-First-Search / reverse Post-Order
Elliott Hughes719ace42012-03-09 18:06:03 -0800167};
buzbee67bf8852011-08-17 17:51:35 -0700168
169struct CompilationUnit;
170struct BasicBlock;
171struct SSARepresentation;
172struct GrowableList;
173struct MIR;
174
buzbeeba938cb2012-02-03 14:47:55 -0800175void oatInit(CompilationUnit* cUnit, const Compiler& compiler);
buzbee67bf8852011-08-17 17:51:35 -0700176bool oatArchInit(void);
buzbee67bf8852011-08-17 17:51:35 -0700177bool oatStartup(void);
178void oatShutdown(void);
buzbee67bf8852011-08-17 17:51:35 -0700179void oatScanAllClassPointers(void (*callback)(void* ptr));
180void oatInitializeSSAConversion(struct CompilationUnit* cUnit);
buzbeee1965672012-03-11 18:39:19 -0700181int SRegToVReg(const struct CompilationUnit* cUnit, int ssaReg);
182int SRegToSubscript(const struct CompilationUnit* cUnit, int ssaReg);
buzbee67bf8852011-08-17 17:51:35 -0700183bool 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,
Elliott Hughesadb8c672012-03-06 16:49:32 -0800195 const DecodedInstruction& insn,
buzbeeba938cb2012-02-03 14:47:55 -0800196 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);
buzbeee3acd072012-02-25 17:03:10 -0800209bool oatIsFpReg(int reg);
210uint32_t oatFpRegMask(void);
buzbee67bf8852011-08-17 17:51:35 -0700211
Elliott Hughes11d1b0c2012-01-23 16:57:47 -0800212} // namespace art
213
Elliott Hughes3fa1b7e2012-03-13 17:06:22 -0700214extern "C" art::CompiledMethod* ArtCompileMethod(art::Compiler& compiler,
Elliott Hughesb3bd5f02012-03-08 21:05:27 -0800215 const art::DexFile::CodeItem* code_item,
216 uint32_t access_flags, uint32_t method_idx,
217 const art::ClassLoader* class_loader,
218 const art::DexFile& dex_file);
219
buzbee67bf8852011-08-17 17:51:35 -0700220#endif // ART_SRC_COMPILER_COMPILER_H_