blob: 49e085270c0ba1b6f6ad1e85ceba43b20967e12b [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 Rogers4c1c2832013-03-04 18:30:13 -080029namespace llvm {
buzbee692be802012-08-29 15:52:59 -070030 class IntrinsicHelper;
31 class IRBuilder;
32}
Elliott Hughes11d1b0c2012-01-23 16:57:47 -080033
buzbeee3acd072012-02-25 17:03:10 -080034/*
35 * Assembly is an iterative process, and usually terminates within
36 * two or three passes. This should be high enough to handle bizarre
37 * cases, but detect an infinite loop bug.
38 */
39#define MAX_ASSEMBLER_RETRIES 50
40
buzbee02031b12012-11-23 09:41:35 -080041// Suppress optimization if corresponding bit set.
buzbeefa57c472012-11-21 12:06:18 -080042enum opt_control_vector {
Bill Buzbeea114add2012-05-03 15:00:40 -070043 kLoadStoreElimination = 0,
44 kLoadHoisting,
45 kSuppressLoads,
46 kNullCheckElimination,
47 kPromoteRegs,
48 kTrackLiveTemps,
Bill Buzbeea114add2012-05-03 15:00:40 -070049 kSafeOptimizations,
50 kBBOpt,
51 kMatch,
52 kPromoteCompilerTemps,
buzbee1fd33462013-03-25 13:40:45 -070053 kBranchFusing,
buzbeece302932011-10-04 14:32:18 -070054};
55
buzbee02031b12012-11-23 09:41:35 -080056// Force code generation paths for testing.
buzbeece302932011-10-04 14:32:18 -070057enum debugControlVector {
Bill Buzbeea114add2012-05-03 15:00:40 -070058 kDebugVerbose,
59 kDebugDumpCFG,
60 kDebugSlowFieldPath,
61 kDebugSlowInvokePath,
62 kDebugSlowStringPath,
63 kDebugSlowTypePath,
64 kDebugSlowestFieldPath,
65 kDebugSlowestStringPath,
66 kDebugExerciseResolveMethod,
67 kDebugVerifyDataflow,
68 kDebugShowMemoryUsage,
69 kDebugShowNops,
70 kDebugCountOpcodes,
buzbeed1643e42012-09-05 14:06:51 -070071 kDebugDumpCheckStats,
buzbeead8f15e2012-06-18 14:49:45 -070072 kDebugDumpBitcodeFile,
Bill Buzbeec9f40dd2012-08-15 11:35:25 -070073 kDebugVerifyBitcode,
buzbeece302932011-10-04 14:32:18 -070074};
75
buzbee4df2bbd2012-10-11 14:46:06 -070076class LLVMInfo {
buzbee692be802012-08-29 15:52:59 -070077 public:
buzbee4df2bbd2012-10-11 14:46:06 -070078 LLVMInfo();
79 ~LLVMInfo();
buzbee692be802012-08-29 15:52:59 -070080
Ian Rogers4c1c2832013-03-04 18:30:13 -080081 ::llvm::LLVMContext* GetLLVMContext() {
buzbee692be802012-08-29 15:52:59 -070082 return llvm_context_.get();
83 }
84
Ian Rogers4c1c2832013-03-04 18:30:13 -080085 ::llvm::Module* GetLLVMModule() {
TDYa12755e5e6c2012-09-11 15:14:42 -070086 return llvm_module_;
buzbee692be802012-08-29 15:52:59 -070087 }
88
Ian Rogers4c1c2832013-03-04 18:30:13 -080089 art::llvm::IntrinsicHelper* GetIntrinsicHelper() {
buzbee692be802012-08-29 15:52:59 -070090 return intrinsic_helper_.get();
91 }
92
Ian Rogers4c1c2832013-03-04 18:30:13 -080093 art::llvm::IRBuilder* GetIRBuilder() {
buzbee692be802012-08-29 15:52:59 -070094 return ir_builder_.get();
95 }
96
97 private:
Ian Rogers4c1c2832013-03-04 18:30:13 -080098 UniquePtr< ::llvm::LLVMContext> llvm_context_;
99 ::llvm::Module* llvm_module_; // Managed by context_.
100 UniquePtr<art::llvm::IntrinsicHelper> intrinsic_helper_;
101 UniquePtr<art::llvm::IRBuilder> ir_builder_;
buzbee692be802012-08-29 15:52:59 -0700102};
buzbee692be802012-08-29 15:52:59 -0700103
buzbee67bf8852011-08-17 17:51:35 -0700104struct CompilationUnit;
105struct BasicBlock;
buzbee67bf8852011-08-17 17:51:35 -0700106
Elliott Hughes11d1b0c2012-01-23 16:57:47 -0800107} // namespace art
108
Ian Rogers1212a022013-03-04 10:48:41 -0800109extern "C" art::CompiledMethod* ArtCompileMethod(art::CompilerDriver& driver,
Elliott Hughesb3bd5f02012-03-08 21:05:27 -0800110 const art::DexFile::CodeItem* code_item,
Ian Rogers08f753d2012-08-24 14:35:25 -0700111 uint32_t access_flags,
112 art::InvokeType invoke_type,
buzbee26f10ee2012-12-21 11:16:29 -0800113 uint32_t class_dex_idx,
Ian Rogers08f753d2012-08-24 14:35:25 -0700114 uint32_t method_idx,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700115 jobject class_loader,
Elliott Hughesb3bd5f02012-03-08 21:05:27 -0800116 const art::DexFile& dex_file);
117
buzbee395116c2013-02-27 14:30:25 -0800118#endif // ART_SRC_COMPILER_DEX_COMPILER_H_