blob: d16735c621f2f43dfec9f6680ed2e132d8f14838 [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
buzbee67bf8852011-08-17 17:51:35 -070022#define COMPILER_TRACED(X)
23#define COMPILER_TRACEE(X)
24
25typedef enum OatInstructionSetType {
26 DALVIK_OAT_NONE = 0,
27 DALVIK_OAT_ARM,
28 DALVIK_OAT_THUMB2,
29} OatInstructionSetType;
30
buzbeece302932011-10-04 14:32:18 -070031/* Supress optimization if corresponding bit set */
32enum optControlVector {
33 kLoadStoreElimination = 0,
34 kLoadHoisting,
35 kSuppressLoads,
36 kNullCheckElimination,
37 kPromoteRegs,
38 kTrackLiveTemps,
39};
40
41extern uint32_t compilerOptimizerDisableFlags;
42
43/* Force code generation paths for testing */
44enum debugControlVector {
45 kDebugDisplayMissingTargets,
46 kDebugVerbose,
47 kDebugDumpCFG,
48 kDebugSlowFieldPath,
49 kDebugSlowInvokePath,
50 kDebugSlowStringPath,
51 kDebugSlowTypePath,
52 kDebugSlowestFieldPath,
53 kDebugSlowestStringPath,
54};
55
56extern uint32_t compilerDebugFlags;
57
58/* If non-empty, apply optimizer/debug flags only to matching methods */
59extern std::string compilerMethodMatch;
60
61/* Flips sense of compilerMethodMatch - apply flags if doesn't match */
62extern bool compilerFlipMatch;
63
buzbee67bf8852011-08-17 17:51:35 -070064typedef enum OatMethodAttributes {
65 kIsCallee = 0, /* Code is part of a callee (invoked by a hot trace) */
66 kIsHot, /* Code is part of a hot trace */
67 kIsLeaf, /* Method is leaf */
68 kIsEmpty, /* Method is empty */
69 kIsThrowFree, /* Method doesn't throw */
70 kIsGetter, /* Method fits the getter pattern */
71 kIsSetter, /* Method fits the setter pattern */
72 kCannotCompile, /* Method cannot be compiled */
73} OatMethodAttributes;
74
75#define METHOD_IS_CALLEE (1 << kIsCallee)
76#define METHOD_IS_HOT (1 << kIsHot)
77#define METHOD_IS_LEAF (1 << kIsLeaf)
78#define METHOD_IS_EMPTY (1 << kIsEmpty)
79#define METHOD_IS_THROW_FREE (1 << kIsThrowFree)
80#define METHOD_IS_GETTER (1 << kIsGetter)
81#define METHOD_IS_SETTER (1 << kIsSetter)
82#define METHOD_CANNOT_COMPILE (1 << kCannotCompile)
83
84/* Customized node traversal orders for different needs */
85typedef enum DataFlowAnalysisMode {
86 kAllNodes = 0, // All nodes
87 kReachableNodes, // All reachable nodes
88 kPreOrderDFSTraversal, // Depth-First-Search / Pre-Order
89 kPostOrderDFSTraversal, // Depth-First-Search / Post-Order
90 kPostOrderDOMTraversal, // Dominator tree / Post-Order
91} DataFlowAnalysisMode;
92
93struct CompilationUnit;
94struct BasicBlock;
95struct SSARepresentation;
96struct GrowableList;
97struct MIR;
98
Brian Carlstrom16192862011-09-12 17:50:06 -070099void oatInit(const Compiler& compiler);
buzbee67bf8852011-08-17 17:51:35 -0700100bool oatArchInit(void);
101void oatArchDump(void);
102bool oatStartup(void);
103void oatShutdown(void);
Ian Rogers0571d352011-11-03 19:51:38 -0700104CompiledMethod* oatCompileMethod(const Compiler& compiler, bool is_direct,
105 uint32_t method_idx, const art::ClassLoader* class_loader,
106 const art::DexFile& dex_file, OatInstructionSetType);
buzbee67bf8852011-08-17 17:51:35 -0700107void oatDumpStats(void);
108void oatScanAllClassPointers(void (*callback)(void* ptr));
109void oatInitializeSSAConversion(struct CompilationUnit* cUnit);
110int oatConvertSSARegToDalvik(const struct CompilationUnit* cUnit, int ssaReg);
111bool oatFindLocalLiveIn(struct CompilationUnit* cUnit,
112 struct BasicBlock* bb);
113bool oatDoSSAConversion(struct CompilationUnit* cUnit,
114 struct BasicBlock* bb);
115bool oatDoConstantPropagation(struct CompilationUnit* cUnit,
116 struct BasicBlock* bb);
117bool oatFindInductionVariables(struct CompilationUnit* cUnit,
118 struct BasicBlock* bb);
119/* Clear the visited flag for each BB */
120bool oatClearVisitedFlag(struct CompilationUnit* cUnit,
121 struct BasicBlock* bb);
Elliott Hughesc1f143d2011-12-01 17:31:10 -0800122char* oatGetDalvikDisassembly(const DecodedInstruction* insn,
buzbee67bf8852011-08-17 17:51:35 -0700123 const char* note);
Elliott Hughesc1f143d2011-12-01 17:31:10 -0800124char* oatFullDisassembler(const struct CompilationUnit* cUnit,
buzbee67bf8852011-08-17 17:51:35 -0700125 const struct MIR* mir);
Elliott Hughesc1f143d2011-12-01 17:31:10 -0800126char* oatGetSSAString(struct CompilationUnit* cUnit,
buzbee67bf8852011-08-17 17:51:35 -0700127 struct SSARepresentation* ssaRep);
128void oatDataFlowAnalysisDispatcher(struct CompilationUnit* cUnit,
129 bool (*func)(struct CompilationUnit* , struct BasicBlock*),
130 DataFlowAnalysisMode dfaMode,
131 bool isIterative);
132void oatMethodSSATransformation(struct CompilationUnit* cUnit);
133u8 oatGetRegResourceMask(int reg);
134void oatDumpCFG(struct CompilationUnit* cUnit, const char* dirPrefix);
135void oatProcessSwitchTables(CompilationUnit* cUnit);
136
137#endif // ART_SRC_COMPILER_COMPILER_H_