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