blob: 6d62f29bcffce2730d75100f0ea64e0d3dc7d385 [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,
buzbee16da88c2012-03-20 10:38:17 -070054 kMatch,
buzbee9c044ce2012-03-18 13:24:07 -070055 kPromoteCompilerTemps,
buzbeece302932011-10-04 14:32:18 -070056};
57
buzbee5abfa3e2012-01-31 17:01:43 -080058/* Type of allocation for memory tuning */
59enum oatAllocKind {
60 kAllocMisc,
61 kAllocBB,
62 kAllocLIR,
63 kAllocMIR,
64 kAllocDFInfo,
65 kAllocGrowableList,
66 kAllocGrowableBitMap,
67 kAllocDalvikToSSAMap,
68 kAllocDebugInfo,
69 kAllocSuccessor,
70 kAllocRegAlloc,
71 kAllocData,
72 kAllocPredecessors,
73 kNumAllocKinds
74};
75
76/* Type of growable list for memory tuning */
77enum oatListKind {
78 kListMisc = 0,
79 kListBlockList,
80 kListSSAtoDalvikMap,
81 kListDfsOrder,
82 kListDfsPostOrder,
83 kListDomPostOrderTraversal,
84 kListThrowLaunchPads,
85 kListSuspendLaunchPads,
86 kListSwitchTables,
87 kListFillArrayData,
88 kListSuccessorBlocks,
89 kListPredecessors,
90 kNumListKinds
91};
92
93/* Type of growable bitmap for memory tuning */
94enum oatBitMapKind {
95 kBitMapMisc = 0,
96 kBitMapUse,
97 kBitMapDef,
98 kBitMapLiveIn,
99 kBitMapBMatrix,
100 kBitMapDominators,
101 kBitMapIDominated,
102 kBitMapDomFrontier,
103 kBitMapPhi,
104 kBitMapTmpBlocks,
105 kBitMapInputBlocks,
106 kBitMapRegisterV,
107 kBitMapTempSSARegisterV,
108 kBitMapNullCheck,
109 kBitMapTmpBlockV,
110 kBitMapPredecessors,
111 kNumBitMapKinds
112};
113
buzbeece302932011-10-04 14:32:18 -0700114/* 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,
buzbeea7c12682012-03-19 13:13:53 -0700129 kDebugCountOpcodes,
buzbeece302932011-10-04 14:32:18 -0700130};
131
Elliott Hughes719ace42012-03-09 18:06:03 -0800132enum OatMethodAttributes {
buzbee67bf8852011-08-17 17:51:35 -0700133 kIsCallee = 0, /* Code is part of a callee (invoked by a hot trace) */
134 kIsHot, /* Code is part of a hot trace */
135 kIsLeaf, /* Method is leaf */
136 kIsEmpty, /* Method is empty */
137 kIsThrowFree, /* Method doesn't throw */
138 kIsGetter, /* Method fits the getter pattern */
139 kIsSetter, /* Method fits the setter pattern */
140 kCannotCompile, /* Method cannot be compiled */
Elliott Hughes719ace42012-03-09 18:06:03 -0800141};
buzbee67bf8852011-08-17 17:51:35 -0700142
143#define METHOD_IS_CALLEE (1 << kIsCallee)
144#define METHOD_IS_HOT (1 << kIsHot)
145#define METHOD_IS_LEAF (1 << kIsLeaf)
146#define METHOD_IS_EMPTY (1 << kIsEmpty)
147#define METHOD_IS_THROW_FREE (1 << kIsThrowFree)
148#define METHOD_IS_GETTER (1 << kIsGetter)
149#define METHOD_IS_SETTER (1 << kIsSetter)
150#define METHOD_CANNOT_COMPILE (1 << kCannotCompile)
151
152/* Customized node traversal orders for different needs */
Elliott Hughes719ace42012-03-09 18:06:03 -0800153enum DataFlowAnalysisMode {
buzbee67bf8852011-08-17 17:51:35 -0700154 kAllNodes = 0, // All nodes
155 kReachableNodes, // All reachable nodes
156 kPreOrderDFSTraversal, // Depth-First-Search / Pre-Order
157 kPostOrderDFSTraversal, // Depth-First-Search / Post-Order
158 kPostOrderDOMTraversal, // Dominator tree / Post-Order
buzbee5b537102012-01-17 17:33:47 -0800159 kReversePostOrderTraversal, // Depth-First-Search / reverse Post-Order
Elliott Hughes719ace42012-03-09 18:06:03 -0800160};
buzbee67bf8852011-08-17 17:51:35 -0700161
162struct CompilationUnit;
163struct BasicBlock;
164struct SSARepresentation;
165struct GrowableList;
166struct MIR;
167
buzbeeba938cb2012-02-03 14:47:55 -0800168void oatInit(CompilationUnit* cUnit, const Compiler& compiler);
buzbee67bf8852011-08-17 17:51:35 -0700169bool oatArchInit(void);
buzbee67bf8852011-08-17 17:51:35 -0700170bool oatStartup(void);
171void oatShutdown(void);
buzbee67bf8852011-08-17 17:51:35 -0700172void oatScanAllClassPointers(void (*callback)(void* ptr));
173void oatInitializeSSAConversion(struct CompilationUnit* cUnit);
buzbeee1965672012-03-11 18:39:19 -0700174int SRegToVReg(const struct CompilationUnit* cUnit, int ssaReg);
175int SRegToSubscript(const struct CompilationUnit* cUnit, int ssaReg);
buzbee67bf8852011-08-17 17:51:35 -0700176bool oatFindLocalLiveIn(struct CompilationUnit* cUnit,
177 struct BasicBlock* bb);
178bool oatDoSSAConversion(struct CompilationUnit* cUnit,
179 struct BasicBlock* bb);
180bool oatDoConstantPropagation(struct CompilationUnit* cUnit,
181 struct BasicBlock* bb);
182bool oatFindInductionVariables(struct CompilationUnit* cUnit,
183 struct BasicBlock* bb);
184/* Clear the visited flag for each BB */
185bool oatClearVisitedFlag(struct CompilationUnit* cUnit,
186 struct BasicBlock* bb);
buzbeeba938cb2012-02-03 14:47:55 -0800187char* oatGetDalvikDisassembly(CompilationUnit* cUnit,
Elliott Hughesadb8c672012-03-06 16:49:32 -0800188 const DecodedInstruction& insn,
buzbeeba938cb2012-02-03 14:47:55 -0800189 const char* note);
190char* oatFullDisassembler(struct CompilationUnit* cUnit,
191 const struct MIR* mir);
Elliott Hughesc1f143d2011-12-01 17:31:10 -0800192char* oatGetSSAString(struct CompilationUnit* cUnit,
buzbee67bf8852011-08-17 17:51:35 -0700193 struct SSARepresentation* ssaRep);
194void oatDataFlowAnalysisDispatcher(struct CompilationUnit* cUnit,
195 bool (*func)(struct CompilationUnit* , struct BasicBlock*),
196 DataFlowAnalysisMode dfaMode,
197 bool isIterative);
198void oatMethodSSATransformation(struct CompilationUnit* cUnit);
199u8 oatGetRegResourceMask(int reg);
200void oatDumpCFG(struct CompilationUnit* cUnit, const char* dirPrefix);
201void oatProcessSwitchTables(CompilationUnit* cUnit);
buzbeee3acd072012-02-25 17:03:10 -0800202bool oatIsFpReg(int reg);
203uint32_t oatFpRegMask(void);
buzbee67bf8852011-08-17 17:51:35 -0700204
Elliott Hughes11d1b0c2012-01-23 16:57:47 -0800205} // namespace art
206
Elliott Hughes3fa1b7e2012-03-13 17:06:22 -0700207extern "C" art::CompiledMethod* ArtCompileMethod(art::Compiler& compiler,
Elliott Hughesb3bd5f02012-03-08 21:05:27 -0800208 const art::DexFile::CodeItem* code_item,
209 uint32_t access_flags, uint32_t method_idx,
210 const art::ClassLoader* class_loader,
211 const art::DexFile& dex_file);
212
buzbee67bf8852011-08-17 17:51:35 -0700213#endif // ART_SRC_COMPILER_COMPILER_H_