blob: f4cbdfbe6c798b5aae7796ef53efea25c2b3eebe [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
Brian Carlstromfc0e3212013-07-17 14:40:12 -070017#ifndef ART_COMPILER_DEX_FRONTEND_H_
18#define ART_COMPILER_DEX_FRONTEND_H_
buzbee67bf8852011-08-17 17:51:35 -070019
Ian Rogers0571d352011-11-03 19:51:38 -070020#include "dex_file.h"
Vladimir Marko05bded22014-01-21 11:38:17 +000021#include "invoke_type.h"
Dragos Sbirlea7467ee02013-06-21 09:20:34 -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,
Vladimir Markobfea9c22014-01-17 17:49:33 +000047 kClassInitCheckElimination,
Vladimir Marko95a05972014-05-30 10:01:32 +010048 kGlobalValueNumbering,
Bill Buzbeea114add2012-05-03 15:00:40 -070049 kPromoteRegs,
50 kTrackLiveTemps,
Bill Buzbeea114add2012-05-03 15:00:40 -070051 kSafeOptimizations,
52 kBBOpt,
53 kMatch,
54 kPromoteCompilerTemps,
buzbee1fd33462013-03-25 13:40:45 -070055 kBranchFusing,
buzbee17189ac2013-11-08 11:07:02 -080056 kSuppressExceptionEdges,
Vladimir Marko9820b7c2014-01-02 16:40:37 +000057 kSuppressMethodInlining,
buzbeece302932011-10-04 14:32:18 -070058};
59
buzbee02031b12012-11-23 09:41:35 -080060// Force code generation paths for testing.
buzbeece302932011-10-04 14:32:18 -070061enum debugControlVector {
Bill Buzbeea114add2012-05-03 15:00:40 -070062 kDebugVerbose,
63 kDebugDumpCFG,
64 kDebugSlowFieldPath,
65 kDebugSlowInvokePath,
66 kDebugSlowStringPath,
67 kDebugSlowTypePath,
68 kDebugSlowestFieldPath,
69 kDebugSlowestStringPath,
70 kDebugExerciseResolveMethod,
71 kDebugVerifyDataflow,
72 kDebugShowMemoryUsage,
73 kDebugShowNops,
74 kDebugCountOpcodes,
buzbeed1643e42012-09-05 14:06:51 -070075 kDebugDumpCheckStats,
buzbeead8f15e2012-06-18 14:49:45 -070076 kDebugDumpBitcodeFile,
Bill Buzbeec9f40dd2012-08-15 11:35:25 -070077 kDebugVerifyBitcode,
buzbeea5abf702013-04-12 14:39:29 -070078 kDebugShowSummaryMemoryUsage,
buzbeeee17e0a2013-07-31 10:47:37 -070079 kDebugShowFilterStats,
buzbeeb01bf152014-05-13 15:59:07 -070080 kDebugTimings,
81 kDebugCodegenDump
buzbeece302932011-10-04 14:32:18 -070082};
83
buzbee4df2bbd2012-10-11 14:46:06 -070084class LLVMInfo {
buzbee692be802012-08-29 15:52:59 -070085 public:
buzbee4df2bbd2012-10-11 14:46:06 -070086 LLVMInfo();
87 ~LLVMInfo();
buzbee692be802012-08-29 15:52:59 -070088
Ian Rogers4c1c2832013-03-04 18:30:13 -080089 ::llvm::LLVMContext* GetLLVMContext() {
buzbee692be802012-08-29 15:52:59 -070090 return llvm_context_.get();
91 }
92
Ian Rogers4c1c2832013-03-04 18:30:13 -080093 ::llvm::Module* GetLLVMModule() {
TDYa12755e5e6c2012-09-11 15:14:42 -070094 return llvm_module_;
buzbee692be802012-08-29 15:52:59 -070095 }
96
Ian Rogers4c1c2832013-03-04 18:30:13 -080097 art::llvm::IntrinsicHelper* GetIntrinsicHelper() {
buzbee692be802012-08-29 15:52:59 -070098 return intrinsic_helper_.get();
99 }
100
Ian Rogers4c1c2832013-03-04 18:30:13 -0800101 art::llvm::IRBuilder* GetIRBuilder() {
buzbee692be802012-08-29 15:52:59 -0700102 return ir_builder_.get();
103 }
104
105 private:
Ian Rogers700a4022014-05-19 16:49:03 -0700106 std::unique_ptr< ::llvm::LLVMContext> llvm_context_;
Brian Carlstrom7934ac22013-07-26 10:54:15 -0700107 ::llvm::Module* llvm_module_; // Managed by context_.
Ian Rogers700a4022014-05-19 16:49:03 -0700108 std::unique_ptr<art::llvm::IntrinsicHelper> intrinsic_helper_;
109 std::unique_ptr<art::llvm::IRBuilder> ir_builder_;
buzbee692be802012-08-29 15:52:59 -0700110};
buzbee692be802012-08-29 15:52:59 -0700111
Ian Rogersb48b9eb2014-02-28 16:20:21 -0800112class CompiledMethod;
Vladimir Marko05bded22014-01-21 11:38:17 +0000113class CompilerDriver;
buzbee67bf8852011-08-17 17:51:35 -0700114
Elliott Hughes11d1b0c2012-01-23 16:57:47 -0800115} // namespace art
116
Ian Rogers1212a022013-03-04 10:48:41 -0800117extern "C" art::CompiledMethod* ArtCompileMethod(art::CompilerDriver& driver,
Elliott Hughesb3bd5f02012-03-08 21:05:27 -0800118 const art::DexFile::CodeItem* code_item,
Ian Rogers08f753d2012-08-24 14:35:25 -0700119 uint32_t access_flags,
120 art::InvokeType invoke_type,
Ian Rogers8b2c0b92013-09-19 02:56:49 -0700121 uint16_t class_def_idx,
Ian Rogers08f753d2012-08-24 14:35:25 -0700122 uint32_t method_idx,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700123 jobject class_loader,
Elliott Hughesb3bd5f02012-03-08 21:05:27 -0800124 const art::DexFile& dex_file);
125
Dragos Sbirlea7467ee02013-06-21 09:20:34 -0700126
127
Brian Carlstromfc0e3212013-07-17 14:40:12 -0700128#endif // ART_COMPILER_DEX_FRONTEND_H_