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 | |
buzbee | 395116c | 2013-02-27 14:30:25 -0800 | [diff] [blame^] | 17 | #ifndef ART_SRC_COMPILER_DEX_COMPILER_H_ |
| 18 | #define ART_SRC_COMPILER_DEX_COMPILER_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" |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 21 | #include "dex_instruction.h" |
Ian Rogers | 0571d35 | 2011-11-03 19:51:38 -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 { |
buzbee | 692be80 | 2012-08-29 15:52:59 -0700 | [diff] [blame] | 29 | namespace greenland { |
| 30 | class IntrinsicHelper; |
| 31 | class IRBuilder; |
| 32 | } |
Elliott Hughes | 11d1b0c | 2012-01-23 16:57:47 -0800 | [diff] [blame] | 33 | |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 34 | #define COMPILER_TRACED(X) |
| 35 | #define COMPILER_TRACEE(X) |
| 36 | |
buzbee | 44b412b | 2012-02-04 08:50:53 -0800 | [diff] [blame] | 37 | /* |
| 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 | |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 45 | /* |
| 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 | |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 52 | // Suppress optimization if corresponding bit set. |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 53 | enum opt_control_vector { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 54 | kLoadStoreElimination = 0, |
| 55 | kLoadHoisting, |
| 56 | kSuppressLoads, |
| 57 | kNullCheckElimination, |
| 58 | kPromoteRegs, |
| 59 | kTrackLiveTemps, |
| 60 | kSkipLargeMethodOptimization, |
| 61 | kSafeOptimizations, |
| 62 | kBBOpt, |
| 63 | kMatch, |
| 64 | kPromoteCompilerTemps, |
buzbee | ce30293 | 2011-10-04 14:32:18 -0700 | [diff] [blame] | 65 | }; |
| 66 | |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 67 | // Force code generation paths for testing. |
buzbee | ce30293 | 2011-10-04 14:32:18 -0700 | [diff] [blame] | 68 | enum debugControlVector { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 69 | 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, |
buzbee | d1643e4 | 2012-09-05 14:06:51 -0700 | [diff] [blame] | 83 | kDebugDumpCheckStats, |
buzbee | ad8f15e | 2012-06-18 14:49:45 -0700 | [diff] [blame] | 84 | kDebugDumpBitcodeFile, |
Bill Buzbee | c9f40dd | 2012-08-15 11:35:25 -0700 | [diff] [blame] | 85 | kDebugVerifyBitcode, |
buzbee | ce30293 | 2011-10-04 14:32:18 -0700 | [diff] [blame] | 86 | }; |
| 87 | |
Elliott Hughes | 719ace4 | 2012-03-09 18:06:03 -0800 | [diff] [blame] | 88 | enum OatMethodAttributes { |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 89 | 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 Hughes | 719ace4 | 2012-03-09 18:06:03 -0800 | [diff] [blame] | 97 | }; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 98 | |
| 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 | |
buzbee | 4df2bbd | 2012-10-11 14:46:06 -0700 | [diff] [blame] | 108 | class LLVMInfo { |
buzbee | 692be80 | 2012-08-29 15:52:59 -0700 | [diff] [blame] | 109 | public: |
buzbee | 4df2bbd | 2012-10-11 14:46:06 -0700 | [diff] [blame] | 110 | LLVMInfo(); |
| 111 | ~LLVMInfo(); |
buzbee | 692be80 | 2012-08-29 15:52:59 -0700 | [diff] [blame] | 112 | |
buzbee | 692be80 | 2012-08-29 15:52:59 -0700 | [diff] [blame] | 113 | llvm::LLVMContext* GetLLVMContext() { |
| 114 | return llvm_context_.get(); |
| 115 | } |
| 116 | |
| 117 | llvm::Module* GetLLVMModule() { |
TDYa127 | 55e5e6c | 2012-09-11 15:14:42 -0700 | [diff] [blame] | 118 | return llvm_module_; |
buzbee | 692be80 | 2012-08-29 15:52:59 -0700 | [diff] [blame] | 119 | } |
| 120 | |
| 121 | art::greenland::IntrinsicHelper* GetIntrinsicHelper() { |
| 122 | return intrinsic_helper_.get(); |
| 123 | } |
| 124 | |
| 125 | art::greenland::IRBuilder* GetIRBuilder() { |
| 126 | return ir_builder_.get(); |
| 127 | } |
| 128 | |
| 129 | private: |
buzbee | 692be80 | 2012-08-29 15:52:59 -0700 | [diff] [blame] | 130 | UniquePtr<llvm::LLVMContext> llvm_context_; |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 131 | llvm::Module* llvm_module_; // Managed by context_. |
buzbee | 692be80 | 2012-08-29 15:52:59 -0700 | [diff] [blame] | 132 | UniquePtr<art::greenland::IntrinsicHelper> intrinsic_helper_; |
| 133 | UniquePtr<art::greenland::IRBuilder> ir_builder_; |
| 134 | }; |
buzbee | 692be80 | 2012-08-29 15:52:59 -0700 | [diff] [blame] | 135 | |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 136 | struct CompilationUnit; |
| 137 | struct BasicBlock; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 138 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 139 | BasicBlock* FindBlock(CompilationUnit* cu, unsigned int code_offset); |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 140 | void ReplaceSpecialChars(std::string& str); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 141 | |
Elliott Hughes | 11d1b0c | 2012-01-23 16:57:47 -0800 | [diff] [blame] | 142 | } // namespace art |
| 143 | |
Elliott Hughes | 3fa1b7e | 2012-03-13 17:06:22 -0700 | [diff] [blame] | 144 | extern "C" art::CompiledMethod* ArtCompileMethod(art::Compiler& compiler, |
Elliott Hughes | b3bd5f0 | 2012-03-08 21:05:27 -0800 | [diff] [blame] | 145 | const art::DexFile::CodeItem* code_item, |
Ian Rogers | 08f753d | 2012-08-24 14:35:25 -0700 | [diff] [blame] | 146 | uint32_t access_flags, |
| 147 | art::InvokeType invoke_type, |
buzbee | 26f10ee | 2012-12-21 11:16:29 -0800 | [diff] [blame] | 148 | uint32_t class_dex_idx, |
Ian Rogers | 08f753d | 2012-08-24 14:35:25 -0700 | [diff] [blame] | 149 | uint32_t method_idx, |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 150 | jobject class_loader, |
Elliott Hughes | b3bd5f0 | 2012-03-08 21:05:27 -0800 | [diff] [blame] | 151 | const art::DexFile& dex_file); |
| 152 | |
buzbee | 395116c | 2013-02-27 14:30:25 -0800 | [diff] [blame^] | 153 | #endif // ART_SRC_COMPILER_DEX_COMPILER_H_ |