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