blob: 4e65d12e50af03900fd62bacac68d49722552d26 [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
buzbee395116c2013-02-27 14:30:25 -080017#ifndef ART_SRC_COMPILER_DEX_COMPILER_H_
18#define ART_SRC_COMPILER_DEX_COMPILER_H_
buzbee67bf8852011-08-17 17:51:35 -070019
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 {
Ian Rogers76ae4fe2013-02-27 16:03:41 -080029namespace compiler_llvm {
buzbee692be802012-08-29 15:52:59 -070030 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
buzbee02031b12012-11-23 09:41:35 -080052// Suppress optimization if corresponding bit set.
buzbeefa57c472012-11-21 12:06:18 -080053enum opt_control_vector {
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
buzbee02031b12012-11-23 09:41:35 -080067// Force code generation paths for testing.
buzbeece302932011-10-04 14:32:18 -070068enum 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 {
buzbee02031b12012-11-23 09:41:35 -080089 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
buzbee4df2bbd2012-10-11 14:46:06 -0700108class LLVMInfo {
buzbee692be802012-08-29 15:52:59 -0700109 public:
buzbee4df2bbd2012-10-11 14:46:06 -0700110 LLVMInfo();
111 ~LLVMInfo();
buzbee692be802012-08-29 15:52:59 -0700112
buzbee692be802012-08-29 15:52:59 -0700113 llvm::LLVMContext* GetLLVMContext() {
114 return llvm_context_.get();
115 }
116
117 llvm::Module* GetLLVMModule() {
TDYa12755e5e6c2012-09-11 15:14:42 -0700118 return llvm_module_;
buzbee692be802012-08-29 15:52:59 -0700119 }
120
Ian Rogers76ae4fe2013-02-27 16:03:41 -0800121 art::compiler_llvm::IntrinsicHelper* GetIntrinsicHelper() {
buzbee692be802012-08-29 15:52:59 -0700122 return intrinsic_helper_.get();
123 }
124
Ian Rogers76ae4fe2013-02-27 16:03:41 -0800125 art::compiler_llvm::IRBuilder* GetIRBuilder() {
buzbee692be802012-08-29 15:52:59 -0700126 return ir_builder_.get();
127 }
128
129 private:
buzbee692be802012-08-29 15:52:59 -0700130 UniquePtr<llvm::LLVMContext> llvm_context_;
buzbee02031b12012-11-23 09:41:35 -0800131 llvm::Module* llvm_module_; // Managed by context_.
Ian Rogers76ae4fe2013-02-27 16:03:41 -0800132 UniquePtr<art::compiler_llvm::IntrinsicHelper> intrinsic_helper_;
133 UniquePtr<art::compiler_llvm::IRBuilder> ir_builder_;
buzbee692be802012-08-29 15:52:59 -0700134};
buzbee692be802012-08-29 15:52:59 -0700135
buzbee67bf8852011-08-17 17:51:35 -0700136struct CompilationUnit;
137struct BasicBlock;
buzbee67bf8852011-08-17 17:51:35 -0700138
buzbeefa57c472012-11-21 12:06:18 -0800139BasicBlock* FindBlock(CompilationUnit* cu, unsigned int code_offset);
buzbee52a77fc2012-11-20 19:50:46 -0800140void ReplaceSpecialChars(std::string& str);
buzbee67bf8852011-08-17 17:51:35 -0700141
Elliott Hughes11d1b0c2012-01-23 16:57:47 -0800142} // namespace art
143
Ian Rogers1212a022013-03-04 10:48:41 -0800144extern "C" art::CompiledMethod* ArtCompileMethod(art::CompilerDriver& driver,
Elliott Hughesb3bd5f02012-03-08 21:05:27 -0800145 const art::DexFile::CodeItem* code_item,
Ian Rogers08f753d2012-08-24 14:35:25 -0700146 uint32_t access_flags,
147 art::InvokeType invoke_type,
buzbee26f10ee2012-12-21 11:16:29 -0800148 uint32_t class_dex_idx,
Ian Rogers08f753d2012-08-24 14:35:25 -0700149 uint32_t method_idx,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700150 jobject class_loader,
Elliott Hughesb3bd5f02012-03-08 21:05:27 -0800151 const art::DexFile& dex_file);
152
buzbee395116c2013-02-27 14:30:25 -0800153#endif // ART_SRC_COMPILER_DEX_COMPILER_H_