blob: 049d9d4df0716ab4d882e2121b1009fb5db2313f [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"
Elliott Hughesadb8c672012-03-06 16:49:32 -080021#include "dex_instruction.h"
Ian Rogers0571d352011-11-03 19:51:38 -070022
buzbee692be802012-08-29 15:52:59 -070023namespace llvm {
24 class Module;
25 class LLVMContext;
26}
buzbee692be802012-08-29 15:52:59 -070027
Elliott Hughes11d1b0c2012-01-23 16:57:47 -080028namespace art {
buzbee692be802012-08-29 15:52:59 -070029namespace greenland {
30 class IntrinsicHelper;
31 class IRBuilder;
32}
Elliott Hughes11d1b0c2012-01-23 16:57:47 -080033
buzbee67bf8852011-08-17 17:51:35 -070034#define COMPILER_TRACED(X)
35#define COMPILER_TRACEE(X)
36
buzbee44b412b2012-02-04 08:50:53 -080037/*
38 * Special offsets to denote method entry/exit for debugger update.
39 * NOTE: bit pattern must be loadable using 1 instruction and must
40 * not be a valid Dalvik offset.
41 */
42#define DEBUGGER_METHOD_ENTRY -1
43#define DEBUGGER_METHOD_EXIT -2
44
buzbeee3acd072012-02-25 17:03:10 -080045/*
46 * Assembly is an iterative process, and usually terminates within
47 * two or three passes. This should be high enough to handle bizarre
48 * cases, but detect an infinite loop bug.
49 */
50#define MAX_ASSEMBLER_RETRIES 50
51
Elliott Hughesb3bd5f02012-03-08 21:05:27 -080052/* Suppress optimization if corresponding bit set */
buzbeece302932011-10-04 14:32:18 -070053enum optControlVector {
Bill Buzbeea114add2012-05-03 15:00:40 -070054 kLoadStoreElimination = 0,
55 kLoadHoisting,
56 kSuppressLoads,
57 kNullCheckElimination,
58 kPromoteRegs,
59 kTrackLiveTemps,
60 kSkipLargeMethodOptimization,
61 kSafeOptimizations,
62 kBBOpt,
63 kMatch,
64 kPromoteCompilerTemps,
buzbeece302932011-10-04 14:32:18 -070065};
66
buzbeece302932011-10-04 14:32:18 -070067/* Force code generation paths for testing */
68enum debugControlVector {
Bill Buzbeea114add2012-05-03 15:00:40 -070069 kDebugDisplayMissingTargets,
70 kDebugVerbose,
71 kDebugDumpCFG,
72 kDebugSlowFieldPath,
73 kDebugSlowInvokePath,
74 kDebugSlowStringPath,
75 kDebugSlowTypePath,
76 kDebugSlowestFieldPath,
77 kDebugSlowestStringPath,
78 kDebugExerciseResolveMethod,
79 kDebugVerifyDataflow,
80 kDebugShowMemoryUsage,
81 kDebugShowNops,
82 kDebugCountOpcodes,
buzbeed1643e42012-09-05 14:06:51 -070083 kDebugDumpCheckStats,
buzbeead8f15e2012-06-18 14:49:45 -070084 kDebugDumpBitcodeFile,
Bill Buzbeec9f40dd2012-08-15 11:35:25 -070085 kDebugVerifyBitcode,
buzbeece302932011-10-04 14:32:18 -070086};
87
Elliott Hughes719ace42012-03-09 18:06:03 -080088enum OatMethodAttributes {
Bill Buzbeea114add2012-05-03 15:00:40 -070089 kIsCallee = 0, /* Code is part of a callee (invoked by a hot trace) */
90 kIsHot, /* Code is part of a hot trace */
91 kIsLeaf, /* Method is leaf */
92 kIsEmpty, /* Method is empty */
93 kIsThrowFree, /* Method doesn't throw */
94 kIsGetter, /* Method fits the getter pattern */
95 kIsSetter, /* Method fits the setter pattern */
96 kCannotCompile, /* Method cannot be compiled */
Elliott Hughes719ace42012-03-09 18:06:03 -080097};
buzbee67bf8852011-08-17 17:51:35 -070098
99#define METHOD_IS_CALLEE (1 << kIsCallee)
100#define METHOD_IS_HOT (1 << kIsHot)
101#define METHOD_IS_LEAF (1 << kIsLeaf)
102#define METHOD_IS_EMPTY (1 << kIsEmpty)
103#define METHOD_IS_THROW_FREE (1 << kIsThrowFree)
104#define METHOD_IS_GETTER (1 << kIsGetter)
105#define METHOD_IS_SETTER (1 << kIsSetter)
106#define METHOD_CANNOT_COMPILE (1 << kCannotCompile)
107
108/* Customized node traversal orders for different needs */
Elliott Hughes719ace42012-03-09 18:06:03 -0800109enum DataFlowAnalysisMode {
Bill Buzbeea114add2012-05-03 15:00:40 -0700110 kAllNodes = 0, // All nodes
111 kReachableNodes, // All reachable nodes
112 kPreOrderDFSTraversal, // Depth-First-Search / Pre-Order
113 kPostOrderDFSTraversal, // Depth-First-Search / Post-Order
114 kPostOrderDOMTraversal, // Dominator tree / Post-Order
115 kReversePostOrderTraversal, // Depth-First-Search / reverse Post-Order
Elliott Hughes719ace42012-03-09 18:06:03 -0800116};
buzbee67bf8852011-08-17 17:51:35 -0700117
buzbee4df2bbd2012-10-11 14:46:06 -0700118class LLVMInfo {
buzbee692be802012-08-29 15:52:59 -0700119 public:
buzbee4df2bbd2012-10-11 14:46:06 -0700120 LLVMInfo();
121 ~LLVMInfo();
buzbee692be802012-08-29 15:52:59 -0700122
buzbee692be802012-08-29 15:52:59 -0700123 llvm::LLVMContext* GetLLVMContext() {
124 return llvm_context_.get();
125 }
126
127 llvm::Module* GetLLVMModule() {
TDYa12755e5e6c2012-09-11 15:14:42 -0700128 return llvm_module_;
buzbee692be802012-08-29 15:52:59 -0700129 }
130
131 art::greenland::IntrinsicHelper* GetIntrinsicHelper() {
132 return intrinsic_helper_.get();
133 }
134
135 art::greenland::IRBuilder* GetIRBuilder() {
136 return ir_builder_.get();
137 }
138
139 private:
buzbee692be802012-08-29 15:52:59 -0700140 UniquePtr<llvm::LLVMContext> llvm_context_;
TDYa12755e5e6c2012-09-11 15:14:42 -0700141 llvm::Module* llvm_module_; // Managed by context_
buzbee692be802012-08-29 15:52:59 -0700142 UniquePtr<art::greenland::IntrinsicHelper> intrinsic_helper_;
143 UniquePtr<art::greenland::IRBuilder> ir_builder_;
144};
buzbee692be802012-08-29 15:52:59 -0700145
buzbee67bf8852011-08-17 17:51:35 -0700146struct CompilationUnit;
147struct BasicBlock;
buzbee67bf8852011-08-17 17:51:35 -0700148
buzbeef58c12c2012-07-03 15:06:29 -0700149BasicBlock* oatFindBlock(CompilationUnit* cUnit, unsigned int codeOffset);
buzbeeeaf09bc2012-11-15 14:51:41 -0800150void oatReplaceSpecialChars(std::string& str);
buzbee67bf8852011-08-17 17:51:35 -0700151
Elliott Hughes11d1b0c2012-01-23 16:57:47 -0800152} // namespace art
153
Elliott Hughes3fa1b7e2012-03-13 17:06:22 -0700154extern "C" art::CompiledMethod* ArtCompileMethod(art::Compiler& compiler,
Elliott Hughesb3bd5f02012-03-08 21:05:27 -0800155 const art::DexFile::CodeItem* code_item,
Ian Rogers08f753d2012-08-24 14:35:25 -0700156 uint32_t access_flags,
157 art::InvokeType invoke_type,
158 uint32_t method_idx,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700159 jobject class_loader,
Elliott Hughesb3bd5f02012-03-08 21:05:27 -0800160 const art::DexFile& dex_file);
161
buzbee67bf8852011-08-17 17:51:35 -0700162#endif // ART_SRC_COMPILER_COMPILER_H_