blob: ac5e0c9b4655ba77c4425f6537cef3c76b503890 [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,
buzbeece302932011-10-04 14:32:18 -070057};
58
59extern uint32_t compilerDebugFlags;
60
61/* If non-empty, apply optimizer/debug flags only to matching methods */
62extern std::string compilerMethodMatch;
63
64/* Flips sense of compilerMethodMatch - apply flags if doesn't match */
65extern bool compilerFlipMatch;
66
buzbee67bf8852011-08-17 17:51:35 -070067typedef enum OatMethodAttributes {
68 kIsCallee = 0, /* Code is part of a callee (invoked by a hot trace) */
69 kIsHot, /* Code is part of a hot trace */
70 kIsLeaf, /* Method is leaf */
71 kIsEmpty, /* Method is empty */
72 kIsThrowFree, /* Method doesn't throw */
73 kIsGetter, /* Method fits the getter pattern */
74 kIsSetter, /* Method fits the setter pattern */
75 kCannotCompile, /* Method cannot be compiled */
76} OatMethodAttributes;
77
78#define METHOD_IS_CALLEE (1 << kIsCallee)
79#define METHOD_IS_HOT (1 << kIsHot)
80#define METHOD_IS_LEAF (1 << kIsLeaf)
81#define METHOD_IS_EMPTY (1 << kIsEmpty)
82#define METHOD_IS_THROW_FREE (1 << kIsThrowFree)
83#define METHOD_IS_GETTER (1 << kIsGetter)
84#define METHOD_IS_SETTER (1 << kIsSetter)
85#define METHOD_CANNOT_COMPILE (1 << kCannotCompile)
86
87/* Customized node traversal orders for different needs */
88typedef enum DataFlowAnalysisMode {
89 kAllNodes = 0, // All nodes
90 kReachableNodes, // All reachable nodes
91 kPreOrderDFSTraversal, // Depth-First-Search / Pre-Order
92 kPostOrderDFSTraversal, // Depth-First-Search / Post-Order
93 kPostOrderDOMTraversal, // Dominator tree / Post-Order
94} DataFlowAnalysisMode;
95
96struct CompilationUnit;
97struct BasicBlock;
98struct SSARepresentation;
99struct GrowableList;
100struct MIR;
101
Brian Carlstrom16192862011-09-12 17:50:06 -0700102void oatInit(const Compiler& compiler);
buzbee67bf8852011-08-17 17:51:35 -0700103bool oatArchInit(void);
104void oatArchDump(void);
105bool oatStartup(void);
106void oatShutdown(void);
Ian Rogers0571d352011-11-03 19:51:38 -0700107CompiledMethod* oatCompileMethod(const Compiler& compiler, bool is_direct,
Elliott Hughes11d1b0c2012-01-23 16:57:47 -0800108 uint32_t method_idx, const ClassLoader* class_loader,
109 const DexFile& dex_file, OatInstructionSetType);
buzbee67bf8852011-08-17 17:51:35 -0700110void oatDumpStats(void);
111void oatScanAllClassPointers(void (*callback)(void* ptr));
112void oatInitializeSSAConversion(struct CompilationUnit* cUnit);
113int oatConvertSSARegToDalvik(const struct CompilationUnit* cUnit, int ssaReg);
114bool oatFindLocalLiveIn(struct CompilationUnit* cUnit,
115 struct BasicBlock* bb);
116bool oatDoSSAConversion(struct CompilationUnit* cUnit,
117 struct BasicBlock* bb);
118bool oatDoConstantPropagation(struct CompilationUnit* cUnit,
119 struct BasicBlock* bb);
120bool oatFindInductionVariables(struct CompilationUnit* cUnit,
121 struct BasicBlock* bb);
122/* Clear the visited flag for each BB */
123bool oatClearVisitedFlag(struct CompilationUnit* cUnit,
124 struct BasicBlock* bb);
Elliott Hughesc1f143d2011-12-01 17:31:10 -0800125char* oatGetDalvikDisassembly(const DecodedInstruction* insn,
buzbee67bf8852011-08-17 17:51:35 -0700126 const char* note);
Elliott Hughesc1f143d2011-12-01 17:31:10 -0800127char* oatFullDisassembler(const struct CompilationUnit* cUnit,
buzbee67bf8852011-08-17 17:51:35 -0700128 const struct MIR* mir);
Elliott Hughesc1f143d2011-12-01 17:31:10 -0800129char* oatGetSSAString(struct CompilationUnit* cUnit,
buzbee67bf8852011-08-17 17:51:35 -0700130 struct SSARepresentation* ssaRep);
131void oatDataFlowAnalysisDispatcher(struct CompilationUnit* cUnit,
132 bool (*func)(struct CompilationUnit* , struct BasicBlock*),
133 DataFlowAnalysisMode dfaMode,
134 bool isIterative);
135void oatMethodSSATransformation(struct CompilationUnit* cUnit);
136u8 oatGetRegResourceMask(int reg);
137void oatDumpCFG(struct CompilationUnit* cUnit, const char* dirPrefix);
138void oatProcessSwitchTables(CompilationUnit* cUnit);
139
Elliott Hughes11d1b0c2012-01-23 16:57:47 -0800140} // namespace art
141
buzbee67bf8852011-08-17 17:51:35 -0700142#endif // ART_SRC_COMPILER_COMPILER_H_