blob: b9b41788901a98707fcbf2db5dda724c169e51c7 [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"
Elliott Hughesadb8c672012-03-06 16:49:32 -080021#include "dex_instruction.h"
Ian Rogers0571d352011-11-03 19:51:38 -070022
Dragos Sbirlea7467ee02013-06-21 09:20:34 -070023
24
25
26
27
buzbee692be802012-08-29 15:52:59 -070028namespace llvm {
29 class Module;
30 class LLVMContext;
31}
buzbee692be802012-08-29 15:52:59 -070032
Elliott Hughes11d1b0c2012-01-23 16:57:47 -080033namespace art {
Ian Rogers4c1c2832013-03-04 18:30:13 -080034namespace llvm {
buzbee692be802012-08-29 15:52:59 -070035 class IntrinsicHelper;
36 class IRBuilder;
37}
Elliott Hughes11d1b0c2012-01-23 16:57:47 -080038
buzbeee3acd072012-02-25 17:03:10 -080039/*
40 * Assembly is an iterative process, and usually terminates within
41 * two or three passes. This should be high enough to handle bizarre
42 * cases, but detect an infinite loop bug.
43 */
44#define MAX_ASSEMBLER_RETRIES 50
45
buzbee02031b12012-11-23 09:41:35 -080046// Suppress optimization if corresponding bit set.
buzbeefa57c472012-11-21 12:06:18 -080047enum opt_control_vector {
Bill Buzbeea114add2012-05-03 15:00:40 -070048 kLoadStoreElimination = 0,
49 kLoadHoisting,
50 kSuppressLoads,
51 kNullCheckElimination,
52 kPromoteRegs,
53 kTrackLiveTemps,
Bill Buzbeea114add2012-05-03 15:00:40 -070054 kSafeOptimizations,
55 kBBOpt,
56 kMatch,
57 kPromoteCompilerTemps,
buzbee1fd33462013-03-25 13:40:45 -070058 kBranchFusing,
buzbee17189ac2013-11-08 11:07:02 -080059 kSuppressExceptionEdges,
buzbeece302932011-10-04 14:32:18 -070060};
61
buzbee02031b12012-11-23 09:41:35 -080062// Force code generation paths for testing.
buzbeece302932011-10-04 14:32:18 -070063enum debugControlVector {
Bill Buzbeea114add2012-05-03 15:00:40 -070064 kDebugVerbose,
65 kDebugDumpCFG,
66 kDebugSlowFieldPath,
67 kDebugSlowInvokePath,
68 kDebugSlowStringPath,
69 kDebugSlowTypePath,
70 kDebugSlowestFieldPath,
71 kDebugSlowestStringPath,
72 kDebugExerciseResolveMethod,
73 kDebugVerifyDataflow,
74 kDebugShowMemoryUsage,
75 kDebugShowNops,
76 kDebugCountOpcodes,
buzbeed1643e42012-09-05 14:06:51 -070077 kDebugDumpCheckStats,
buzbeead8f15e2012-06-18 14:49:45 -070078 kDebugDumpBitcodeFile,
Bill Buzbeec9f40dd2012-08-15 11:35:25 -070079 kDebugVerifyBitcode,
buzbeea5abf702013-04-12 14:39:29 -070080 kDebugShowSummaryMemoryUsage,
buzbeeee17e0a2013-07-31 10:47:37 -070081 kDebugShowFilterStats,
buzbeea61f4952013-08-23 14:27:06 -070082 kDebugTimings
buzbeece302932011-10-04 14:32:18 -070083};
84
buzbee4df2bbd2012-10-11 14:46:06 -070085class LLVMInfo {
buzbee692be802012-08-29 15:52:59 -070086 public:
buzbee4df2bbd2012-10-11 14:46:06 -070087 LLVMInfo();
88 ~LLVMInfo();
buzbee692be802012-08-29 15:52:59 -070089
Ian Rogers4c1c2832013-03-04 18:30:13 -080090 ::llvm::LLVMContext* GetLLVMContext() {
buzbee692be802012-08-29 15:52:59 -070091 return llvm_context_.get();
92 }
93
Ian Rogers4c1c2832013-03-04 18:30:13 -080094 ::llvm::Module* GetLLVMModule() {
TDYa12755e5e6c2012-09-11 15:14:42 -070095 return llvm_module_;
buzbee692be802012-08-29 15:52:59 -070096 }
97
Ian Rogers4c1c2832013-03-04 18:30:13 -080098 art::llvm::IntrinsicHelper* GetIntrinsicHelper() {
buzbee692be802012-08-29 15:52:59 -070099 return intrinsic_helper_.get();
100 }
101
Ian Rogers4c1c2832013-03-04 18:30:13 -0800102 art::llvm::IRBuilder* GetIRBuilder() {
buzbee692be802012-08-29 15:52:59 -0700103 return ir_builder_.get();
104 }
105
106 private:
Ian Rogers4c1c2832013-03-04 18:30:13 -0800107 UniquePtr< ::llvm::LLVMContext> llvm_context_;
Brian Carlstrom7934ac22013-07-26 10:54:15 -0700108 ::llvm::Module* llvm_module_; // Managed by context_.
Ian Rogers4c1c2832013-03-04 18:30:13 -0800109 UniquePtr<art::llvm::IntrinsicHelper> intrinsic_helper_;
110 UniquePtr<art::llvm::IRBuilder> ir_builder_;
buzbee692be802012-08-29 15:52:59 -0700111};
buzbee692be802012-08-29 15:52:59 -0700112
buzbee67bf8852011-08-17 17:51:35 -0700113struct CompilationUnit;
114struct BasicBlock;
buzbee67bf8852011-08-17 17:51:35 -0700115
Elliott Hughes11d1b0c2012-01-23 16:57:47 -0800116} // namespace art
117
Ian Rogers1212a022013-03-04 10:48:41 -0800118extern "C" art::CompiledMethod* ArtCompileMethod(art::CompilerDriver& driver,
Elliott Hughesb3bd5f02012-03-08 21:05:27 -0800119 const art::DexFile::CodeItem* code_item,
Ian Rogers08f753d2012-08-24 14:35:25 -0700120 uint32_t access_flags,
121 art::InvokeType invoke_type,
Ian Rogers8b2c0b92013-09-19 02:56:49 -0700122 uint16_t class_def_idx,
Ian Rogers08f753d2012-08-24 14:35:25 -0700123 uint32_t method_idx,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700124 jobject class_loader,
Elliott Hughesb3bd5f02012-03-08 21:05:27 -0800125 const art::DexFile& dex_file);
126
Dragos Sbirlea7467ee02013-06-21 09:20:34 -0700127
128
Brian Carlstromfc0e3212013-07-17 14:40:12 -0700129#endif // ART_COMPILER_DEX_FRONTEND_H_