blob: 214f6030809d4bfa569535b46459c516227135d7 [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 {
Bill Buzbeea114add2012-05-03 15:00:40 -070045 kLoadStoreElimination = 0,
46 kLoadHoisting,
47 kSuppressLoads,
48 kNullCheckElimination,
49 kPromoteRegs,
50 kTrackLiveTemps,
51 kSkipLargeMethodOptimization,
52 kSafeOptimizations,
53 kBBOpt,
54 kMatch,
55 kPromoteCompilerTemps,
buzbeece302932011-10-04 14:32:18 -070056};
57
buzbee5abfa3e2012-01-31 17:01:43 -080058/* Type of allocation for memory tuning */
59enum oatAllocKind {
Bill Buzbeea114add2012-05-03 15:00:40 -070060 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
buzbee5abfa3e2012-01-31 17:01:43 -080074};
75
76/* Type of growable list for memory tuning */
77enum oatListKind {
Bill Buzbeea114add2012-05-03 15:00:40 -070078 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
buzbee5abfa3e2012-01-31 17:01:43 -080091};
92
93/* Type of growable bitmap for memory tuning */
94enum oatBitMapKind {
Bill Buzbeea114add2012-05-03 15:00:40 -070095 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
buzbee5abfa3e2012-01-31 17:01:43 -0800112};
113
buzbeece302932011-10-04 14:32:18 -0700114/* Force code generation paths for testing */
115enum debugControlVector {
Bill Buzbeea114add2012-05-03 15:00:40 -0700116 kDebugDisplayMissingTargets,
117 kDebugVerbose,
118 kDebugDumpCFG,
119 kDebugSlowFieldPath,
120 kDebugSlowInvokePath,
121 kDebugSlowStringPath,
122 kDebugSlowTypePath,
123 kDebugSlowestFieldPath,
124 kDebugSlowestStringPath,
125 kDebugExerciseResolveMethod,
126 kDebugVerifyDataflow,
127 kDebugShowMemoryUsage,
128 kDebugShowNops,
129 kDebugCountOpcodes,
buzbeead8f15e2012-06-18 14:49:45 -0700130#if defined(ART_USE_QUICK_COMPILER)
131 kDebugDumpBitcodeFile,
Bill Buzbeec9f40dd2012-08-15 11:35:25 -0700132 kDebugVerifyBitcode,
buzbeead8f15e2012-06-18 14:49:45 -0700133#endif
buzbeece302932011-10-04 14:32:18 -0700134};
135
Elliott Hughes719ace42012-03-09 18:06:03 -0800136enum OatMethodAttributes {
Bill Buzbeea114add2012-05-03 15:00:40 -0700137 kIsCallee = 0, /* Code is part of a callee (invoked by a hot trace) */
138 kIsHot, /* Code is part of a hot trace */
139 kIsLeaf, /* Method is leaf */
140 kIsEmpty, /* Method is empty */
141 kIsThrowFree, /* Method doesn't throw */
142 kIsGetter, /* Method fits the getter pattern */
143 kIsSetter, /* Method fits the setter pattern */
144 kCannotCompile, /* Method cannot be compiled */
Elliott Hughes719ace42012-03-09 18:06:03 -0800145};
buzbee67bf8852011-08-17 17:51:35 -0700146
147#define METHOD_IS_CALLEE (1 << kIsCallee)
148#define METHOD_IS_HOT (1 << kIsHot)
149#define METHOD_IS_LEAF (1 << kIsLeaf)
150#define METHOD_IS_EMPTY (1 << kIsEmpty)
151#define METHOD_IS_THROW_FREE (1 << kIsThrowFree)
152#define METHOD_IS_GETTER (1 << kIsGetter)
153#define METHOD_IS_SETTER (1 << kIsSetter)
154#define METHOD_CANNOT_COMPILE (1 << kCannotCompile)
155
156/* Customized node traversal orders for different needs */
Elliott Hughes719ace42012-03-09 18:06:03 -0800157enum DataFlowAnalysisMode {
Bill Buzbeea114add2012-05-03 15:00:40 -0700158 kAllNodes = 0, // All nodes
159 kReachableNodes, // All reachable nodes
160 kPreOrderDFSTraversal, // Depth-First-Search / Pre-Order
161 kPostOrderDFSTraversal, // Depth-First-Search / Post-Order
162 kPostOrderDOMTraversal, // Dominator tree / Post-Order
163 kReversePostOrderTraversal, // Depth-First-Search / reverse Post-Order
Elliott Hughes719ace42012-03-09 18:06:03 -0800164};
buzbee67bf8852011-08-17 17:51:35 -0700165
166struct CompilationUnit;
167struct BasicBlock;
168struct SSARepresentation;
169struct GrowableList;
170struct MIR;
171
buzbeeba938cb2012-02-03 14:47:55 -0800172void oatInit(CompilationUnit* cUnit, const Compiler& compiler);
buzbee67bf8852011-08-17 17:51:35 -0700173bool oatArchInit(void);
buzbee67bf8852011-08-17 17:51:35 -0700174bool oatStartup(void);
175void oatShutdown(void);
buzbee67bf8852011-08-17 17:51:35 -0700176void oatScanAllClassPointers(void (*callback)(void* ptr));
Elliott Hughes7b9d9962012-04-20 18:48:18 -0700177void oatInitializeSSAConversion(CompilationUnit* cUnit);
178int SRegToVReg(const CompilationUnit* cUnit, int ssaReg);
179int SRegToSubscript(const CompilationUnit* cUnit, int ssaReg);
180bool oatFindLocalLiveIn(CompilationUnit* cUnit, BasicBlock* bb);
181bool oatDoSSAConversion(CompilationUnit* cUnit, BasicBlock* bb);
182bool oatDoConstantPropagation(CompilationUnit* cUnit, BasicBlock* bb);
183bool oatFindInductionVariables(CompilationUnit* cUnit, BasicBlock* bb);
buzbee67bf8852011-08-17 17:51:35 -0700184/* Clear the visited flag for each BB */
Elliott Hughes7b9d9962012-04-20 18:48:18 -0700185bool oatClearVisitedFlag(CompilationUnit* cUnit, BasicBlock* bb);
186char* oatGetDalvikDisassembly(CompilationUnit* cUnit, const DecodedInstruction& insn,
buzbeeba938cb2012-02-03 14:47:55 -0800187 const char* note);
Elliott Hughes7b9d9962012-04-20 18:48:18 -0700188char* oatFullDisassembler(CompilationUnit* cUnit, const MIR* mir);
189char* oatGetSSAString(CompilationUnit* cUnit, SSARepresentation* ssaRep);
190void oatDataFlowAnalysisDispatcher(CompilationUnit* cUnit,
Bill Buzbeea114add2012-05-03 15:00:40 -0700191 bool (*func)(CompilationUnit* , BasicBlock*),
192 DataFlowAnalysisMode dfaMode,
193 bool isIterative);
Elliott Hughes7b9d9962012-04-20 18:48:18 -0700194void oatMethodSSATransformation(CompilationUnit* cUnit);
buzbee67bf8852011-08-17 17:51:35 -0700195u8 oatGetRegResourceMask(int reg);
Elliott Hughes7b9d9962012-04-20 18:48:18 -0700196void oatDumpCFG(CompilationUnit* cUnit, const char* dirPrefix);
buzbee67bf8852011-08-17 17:51:35 -0700197void oatProcessSwitchTables(CompilationUnit* cUnit);
buzbeee3acd072012-02-25 17:03:10 -0800198bool oatIsFpReg(int reg);
199uint32_t oatFpRegMask(void);
buzbeead8f15e2012-06-18 14:49:45 -0700200void oatReplaceSpecialChars(std::string& str);
buzbeef58c12c2012-07-03 15:06:29 -0700201BasicBlock* oatFindBlock(CompilationUnit* cUnit, unsigned int codeOffset);
buzbee67bf8852011-08-17 17:51:35 -0700202
Elliott Hughes11d1b0c2012-01-23 16:57:47 -0800203} // namespace art
204
Elliott Hughes3fa1b7e2012-03-13 17:06:22 -0700205extern "C" art::CompiledMethod* ArtCompileMethod(art::Compiler& compiler,
Elliott Hughesb3bd5f02012-03-08 21:05:27 -0800206 const art::DexFile::CodeItem* code_item,
207 uint32_t access_flags, uint32_t method_idx,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700208 jobject class_loader,
Elliott Hughesb3bd5f02012-03-08 21:05:27 -0800209 const art::DexFile& dex_file);
210
buzbee67bf8852011-08-17 17:51:35 -0700211#endif // ART_SRC_COMPILER_COMPILER_H_