blob: 05e05b676b4bd06182e2d6cf6ca536ec3e151c91 [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
44extern uint32_t compilerOptimizerDisableFlags;
45
46/* Force code generation paths for testing */
47enum debugControlVector {
48 kDebugDisplayMissingTargets,
49 kDebugVerbose,
50 kDebugDumpCFG,
51 kDebugSlowFieldPath,
52 kDebugSlowInvokePath,
53 kDebugSlowStringPath,
54 kDebugSlowTypePath,
55 kDebugSlowestFieldPath,
56 kDebugSlowestStringPath,
buzbee34c77ad2012-01-11 13:01:32 -080057 kDebugExerciseResolveMethod,
buzbee5b537102012-01-17 17:33:47 -080058 kDebugVerifyDataflow,
buzbeece302932011-10-04 14:32:18 -070059};
60
61extern uint32_t compilerDebugFlags;
62
63/* If non-empty, apply optimizer/debug flags only to matching methods */
64extern std::string compilerMethodMatch;
65
66/* Flips sense of compilerMethodMatch - apply flags if doesn't match */
67extern bool compilerFlipMatch;
68
buzbee67bf8852011-08-17 17:51:35 -070069typedef enum OatMethodAttributes {
70 kIsCallee = 0, /* Code is part of a callee (invoked by a hot trace) */
71 kIsHot, /* Code is part of a hot trace */
72 kIsLeaf, /* Method is leaf */
73 kIsEmpty, /* Method is empty */
74 kIsThrowFree, /* Method doesn't throw */
75 kIsGetter, /* Method fits the getter pattern */
76 kIsSetter, /* Method fits the setter pattern */
77 kCannotCompile, /* Method cannot be compiled */
78} OatMethodAttributes;
79
80#define METHOD_IS_CALLEE (1 << kIsCallee)
81#define METHOD_IS_HOT (1 << kIsHot)
82#define METHOD_IS_LEAF (1 << kIsLeaf)
83#define METHOD_IS_EMPTY (1 << kIsEmpty)
84#define METHOD_IS_THROW_FREE (1 << kIsThrowFree)
85#define METHOD_IS_GETTER (1 << kIsGetter)
86#define METHOD_IS_SETTER (1 << kIsSetter)
87#define METHOD_CANNOT_COMPILE (1 << kCannotCompile)
88
89/* Customized node traversal orders for different needs */
90typedef enum DataFlowAnalysisMode {
91 kAllNodes = 0, // All nodes
92 kReachableNodes, // All reachable nodes
93 kPreOrderDFSTraversal, // Depth-First-Search / Pre-Order
94 kPostOrderDFSTraversal, // Depth-First-Search / Post-Order
95 kPostOrderDOMTraversal, // Dominator tree / Post-Order
buzbee5b537102012-01-17 17:33:47 -080096 kReversePostOrderTraversal, // Depth-First-Search / reverse Post-Order
buzbee67bf8852011-08-17 17:51:35 -070097} DataFlowAnalysisMode;
98
99struct CompilationUnit;
100struct BasicBlock;
101struct SSARepresentation;
102struct GrowableList;
103struct MIR;
104
Brian Carlstrom16192862011-09-12 17:50:06 -0700105void oatInit(const Compiler& compiler);
buzbee67bf8852011-08-17 17:51:35 -0700106bool oatArchInit(void);
107void oatArchDump(void);
108bool oatStartup(void);
109void oatShutdown(void);
Ian Rogers0571d352011-11-03 19:51:38 -0700110CompiledMethod* oatCompileMethod(const Compiler& compiler, bool is_direct,
Elliott Hughes11d1b0c2012-01-23 16:57:47 -0800111 uint32_t method_idx, const ClassLoader* class_loader,
112 const DexFile& dex_file, OatInstructionSetType);
buzbee67bf8852011-08-17 17:51:35 -0700113void oatDumpStats(void);
114void oatScanAllClassPointers(void (*callback)(void* ptr));
115void oatInitializeSSAConversion(struct CompilationUnit* cUnit);
116int oatConvertSSARegToDalvik(const struct CompilationUnit* cUnit, int ssaReg);
117bool oatFindLocalLiveIn(struct CompilationUnit* cUnit,
118 struct BasicBlock* bb);
119bool oatDoSSAConversion(struct CompilationUnit* cUnit,
120 struct BasicBlock* bb);
121bool oatDoConstantPropagation(struct CompilationUnit* cUnit,
122 struct BasicBlock* bb);
123bool oatFindInductionVariables(struct CompilationUnit* cUnit,
124 struct BasicBlock* bb);
125/* Clear the visited flag for each BB */
126bool oatClearVisitedFlag(struct CompilationUnit* cUnit,
127 struct BasicBlock* bb);
Elliott Hughesc1f143d2011-12-01 17:31:10 -0800128char* oatGetDalvikDisassembly(const DecodedInstruction* insn,
buzbee67bf8852011-08-17 17:51:35 -0700129 const char* note);
Elliott Hughesc1f143d2011-12-01 17:31:10 -0800130char* oatFullDisassembler(const struct CompilationUnit* cUnit,
buzbee67bf8852011-08-17 17:51:35 -0700131 const struct MIR* mir);
Elliott Hughesc1f143d2011-12-01 17:31:10 -0800132char* oatGetSSAString(struct CompilationUnit* cUnit,
buzbee67bf8852011-08-17 17:51:35 -0700133 struct SSARepresentation* ssaRep);
134void oatDataFlowAnalysisDispatcher(struct CompilationUnit* cUnit,
135 bool (*func)(struct CompilationUnit* , struct BasicBlock*),
136 DataFlowAnalysisMode dfaMode,
137 bool isIterative);
138void oatMethodSSATransformation(struct CompilationUnit* cUnit);
139u8 oatGetRegResourceMask(int reg);
140void oatDumpCFG(struct CompilationUnit* cUnit, const char* dirPrefix);
141void oatProcessSwitchTables(CompilationUnit* cUnit);
142
Elliott Hughes11d1b0c2012-01-23 16:57:47 -0800143} // namespace art
144
buzbee67bf8852011-08-17 17:51:35 -0700145#endif // ART_SRC_COMPILER_COMPILER_H_