buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 1 | /* |
| 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 Carlstrom | fc0e321 | 2013-07-17 14:40:12 -0700 | [diff] [blame] | 17 | #ifndef ART_COMPILER_DEX_FRONTEND_H_ |
| 18 | #define ART_COMPILER_DEX_FRONTEND_H_ |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 19 | |
Ian Rogers | 0571d35 | 2011-11-03 19:51:38 -0700 | [diff] [blame] | 20 | #include "dex_file.h" |
Vladimir Marko | 05bded2 | 2014-01-21 11:38:17 +0000 | [diff] [blame^] | 21 | #include "invoke_type.h" |
Dragos Sbirlea | 7467ee0 | 2013-06-21 09:20:34 -0700 | [diff] [blame] | 22 | |
buzbee | 692be80 | 2012-08-29 15:52:59 -0700 | [diff] [blame] | 23 | namespace llvm { |
| 24 | class Module; |
| 25 | class LLVMContext; |
| 26 | } |
buzbee | 692be80 | 2012-08-29 15:52:59 -0700 | [diff] [blame] | 27 | |
Elliott Hughes | 11d1b0c | 2012-01-23 16:57:47 -0800 | [diff] [blame] | 28 | namespace art { |
Ian Rogers | 4c1c283 | 2013-03-04 18:30:13 -0800 | [diff] [blame] | 29 | namespace llvm { |
buzbee | 692be80 | 2012-08-29 15:52:59 -0700 | [diff] [blame] | 30 | class IntrinsicHelper; |
| 31 | class IRBuilder; |
| 32 | } |
Elliott Hughes | 11d1b0c | 2012-01-23 16:57:47 -0800 | [diff] [blame] | 33 | |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 34 | /* |
| 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 | |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 41 | // Suppress optimization if corresponding bit set. |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 42 | enum opt_control_vector { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 43 | kLoadStoreElimination = 0, |
| 44 | kLoadHoisting, |
| 45 | kSuppressLoads, |
| 46 | kNullCheckElimination, |
| 47 | kPromoteRegs, |
| 48 | kTrackLiveTemps, |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 49 | kSafeOptimizations, |
| 50 | kBBOpt, |
| 51 | kMatch, |
| 52 | kPromoteCompilerTemps, |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 53 | kBranchFusing, |
buzbee | 17189ac | 2013-11-08 11:07:02 -0800 | [diff] [blame] | 54 | kSuppressExceptionEdges, |
buzbee | ce30293 | 2011-10-04 14:32:18 -0700 | [diff] [blame] | 55 | }; |
| 56 | |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 57 | // Force code generation paths for testing. |
buzbee | ce30293 | 2011-10-04 14:32:18 -0700 | [diff] [blame] | 58 | enum debugControlVector { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 59 | kDebugVerbose, |
| 60 | kDebugDumpCFG, |
| 61 | kDebugSlowFieldPath, |
| 62 | kDebugSlowInvokePath, |
| 63 | kDebugSlowStringPath, |
| 64 | kDebugSlowTypePath, |
| 65 | kDebugSlowestFieldPath, |
| 66 | kDebugSlowestStringPath, |
| 67 | kDebugExerciseResolveMethod, |
| 68 | kDebugVerifyDataflow, |
| 69 | kDebugShowMemoryUsage, |
| 70 | kDebugShowNops, |
| 71 | kDebugCountOpcodes, |
buzbee | d1643e4 | 2012-09-05 14:06:51 -0700 | [diff] [blame] | 72 | kDebugDumpCheckStats, |
buzbee | ad8f15e | 2012-06-18 14:49:45 -0700 | [diff] [blame] | 73 | kDebugDumpBitcodeFile, |
Bill Buzbee | c9f40dd | 2012-08-15 11:35:25 -0700 | [diff] [blame] | 74 | kDebugVerifyBitcode, |
buzbee | a5abf70 | 2013-04-12 14:39:29 -0700 | [diff] [blame] | 75 | kDebugShowSummaryMemoryUsage, |
buzbee | ee17e0a | 2013-07-31 10:47:37 -0700 | [diff] [blame] | 76 | kDebugShowFilterStats, |
buzbee | a61f495 | 2013-08-23 14:27:06 -0700 | [diff] [blame] | 77 | kDebugTimings |
buzbee | ce30293 | 2011-10-04 14:32:18 -0700 | [diff] [blame] | 78 | }; |
| 79 | |
buzbee | 4df2bbd | 2012-10-11 14:46:06 -0700 | [diff] [blame] | 80 | class LLVMInfo { |
buzbee | 692be80 | 2012-08-29 15:52:59 -0700 | [diff] [blame] | 81 | public: |
buzbee | 4df2bbd | 2012-10-11 14:46:06 -0700 | [diff] [blame] | 82 | LLVMInfo(); |
| 83 | ~LLVMInfo(); |
buzbee | 692be80 | 2012-08-29 15:52:59 -0700 | [diff] [blame] | 84 | |
Ian Rogers | 4c1c283 | 2013-03-04 18:30:13 -0800 | [diff] [blame] | 85 | ::llvm::LLVMContext* GetLLVMContext() { |
buzbee | 692be80 | 2012-08-29 15:52:59 -0700 | [diff] [blame] | 86 | return llvm_context_.get(); |
| 87 | } |
| 88 | |
Ian Rogers | 4c1c283 | 2013-03-04 18:30:13 -0800 | [diff] [blame] | 89 | ::llvm::Module* GetLLVMModule() { |
TDYa127 | 55e5e6c | 2012-09-11 15:14:42 -0700 | [diff] [blame] | 90 | return llvm_module_; |
buzbee | 692be80 | 2012-08-29 15:52:59 -0700 | [diff] [blame] | 91 | } |
| 92 | |
Ian Rogers | 4c1c283 | 2013-03-04 18:30:13 -0800 | [diff] [blame] | 93 | art::llvm::IntrinsicHelper* GetIntrinsicHelper() { |
buzbee | 692be80 | 2012-08-29 15:52:59 -0700 | [diff] [blame] | 94 | return intrinsic_helper_.get(); |
| 95 | } |
| 96 | |
Ian Rogers | 4c1c283 | 2013-03-04 18:30:13 -0800 | [diff] [blame] | 97 | art::llvm::IRBuilder* GetIRBuilder() { |
buzbee | 692be80 | 2012-08-29 15:52:59 -0700 | [diff] [blame] | 98 | return ir_builder_.get(); |
| 99 | } |
| 100 | |
| 101 | private: |
Ian Rogers | 4c1c283 | 2013-03-04 18:30:13 -0800 | [diff] [blame] | 102 | UniquePtr< ::llvm::LLVMContext> llvm_context_; |
Brian Carlstrom | 7934ac2 | 2013-07-26 10:54:15 -0700 | [diff] [blame] | 103 | ::llvm::Module* llvm_module_; // Managed by context_. |
Ian Rogers | 4c1c283 | 2013-03-04 18:30:13 -0800 | [diff] [blame] | 104 | UniquePtr<art::llvm::IntrinsicHelper> intrinsic_helper_; |
| 105 | UniquePtr<art::llvm::IRBuilder> ir_builder_; |
buzbee | 692be80 | 2012-08-29 15:52:59 -0700 | [diff] [blame] | 106 | }; |
buzbee | 692be80 | 2012-08-29 15:52:59 -0700 | [diff] [blame] | 107 | |
Vladimir Marko | 05bded2 | 2014-01-21 11:38:17 +0000 | [diff] [blame^] | 108 | struct CompiledMethod; |
| 109 | class CompilerDriver; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 110 | |
Elliott Hughes | 11d1b0c | 2012-01-23 16:57:47 -0800 | [diff] [blame] | 111 | } // namespace art |
| 112 | |
Ian Rogers | 1212a02 | 2013-03-04 10:48:41 -0800 | [diff] [blame] | 113 | extern "C" art::CompiledMethod* ArtCompileMethod(art::CompilerDriver& driver, |
Elliott Hughes | b3bd5f0 | 2012-03-08 21:05:27 -0800 | [diff] [blame] | 114 | const art::DexFile::CodeItem* code_item, |
Ian Rogers | 08f753d | 2012-08-24 14:35:25 -0700 | [diff] [blame] | 115 | uint32_t access_flags, |
| 116 | art::InvokeType invoke_type, |
Ian Rogers | 8b2c0b9 | 2013-09-19 02:56:49 -0700 | [diff] [blame] | 117 | uint16_t class_def_idx, |
Ian Rogers | 08f753d | 2012-08-24 14:35:25 -0700 | [diff] [blame] | 118 | uint32_t method_idx, |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 119 | jobject class_loader, |
Elliott Hughes | b3bd5f0 | 2012-03-08 21:05:27 -0800 | [diff] [blame] | 120 | const art::DexFile& dex_file); |
| 121 | |
Dragos Sbirlea | 7467ee0 | 2013-06-21 09:20:34 -0700 | [diff] [blame] | 122 | |
| 123 | |
Brian Carlstrom | fc0e321 | 2013-07-17 14:40:12 -0700 | [diff] [blame] | 124 | #endif // ART_COMPILER_DEX_FRONTEND_H_ |