Shih-wei Liao | d1fec81 | 2012-02-13 09:51:10 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2012 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 | |
| 17 | #include "compiler_llvm.h" |
| 18 | |
Elliott Hughes | 1aa246d | 2012-12-13 09:29:36 -0800 | [diff] [blame] | 19 | #include "base/stl_util.h" |
Shih-wei Liao | 26e9307 | 2012-05-30 19:13:08 -0700 | [diff] [blame] | 20 | #include "backend_options.h" |
Shih-wei Liao | c4c9881 | 2012-03-10 21:55:51 -0800 | [diff] [blame] | 21 | #include "class_linker.h" |
Logan Chien | f7015fd | 2012-03-18 01:19:37 +0800 | [diff] [blame] | 22 | #include "compiled_method.h" |
Shih-wei Liao | d1fec81 | 2012-02-13 09:51:10 -0800 | [diff] [blame] | 23 | #include "compiler.h" |
| 24 | #include "ir_builder.h" |
Logan Chien | 88894ee | 2012-02-13 16:42:22 +0800 | [diff] [blame] | 25 | #include "jni_compiler.h" |
Brian Carlstrom | 641ce03 | 2013-01-31 15:21:37 -0800 | [diff] [blame] | 26 | #include "llvm_compilation_unit.h" |
jeffhao | 4028312 | 2013-01-15 13:15:24 -0800 | [diff] [blame] | 27 | #include "method_compiler.h" |
Logan Chien | 4dd96f5 | 2012-02-29 01:26:58 +0800 | [diff] [blame] | 28 | #include "oat_compilation_unit.h" |
Logan Chien | 0c717dd | 2012-03-28 18:31:07 +0800 | [diff] [blame] | 29 | #include "oat_file.h" |
TDYa127 | eead4ac | 2012-06-03 07:15:25 -0700 | [diff] [blame] | 30 | #include "stub_compiler.h" |
Shih-wei Liao | 21d28f5 | 2012-06-12 05:55:00 -0700 | [diff] [blame] | 31 | #include "utils_llvm.h" |
TDYa127 | ce4cc0d | 2012-11-18 16:59:53 -0800 | [diff] [blame] | 32 | #include "verifier/method_verifier.h" |
Shih-wei Liao | d1fec81 | 2012-02-13 09:51:10 -0800 | [diff] [blame] | 33 | |
Logan Chien | dd7cf5b | 2012-03-01 12:55:19 +0800 | [diff] [blame] | 34 | #include <llvm/LinkAllPasses.h> |
| 35 | #include <llvm/LinkAllVMCore.h> |
Logan Chien | 013b6f2 | 2012-03-02 17:20:33 +0800 | [diff] [blame] | 36 | #include <llvm/Support/ManagedStatic.h> |
Logan Chien | 8b977d3 | 2012-02-21 19:14:55 +0800 | [diff] [blame] | 37 | #include <llvm/Support/TargetSelect.h> |
| 38 | #include <llvm/Support/Threading.h> |
| 39 | |
buzbee | c531cef | 2012-10-18 07:09:20 -0700 | [diff] [blame] | 40 | #if defined(ART_USE_PORTABLE_COMPILER) |
Shih-wei Liao | bb33f2f | 2012-08-23 13:20:00 -0700 | [diff] [blame] | 41 | namespace art { |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 42 | void CompileOneMethod(Compiler& compiler, |
buzbee | c531cef | 2012-10-18 07:09:20 -0700 | [diff] [blame] | 43 | const CompilerBackend compilerBackend, |
| 44 | const DexFile::CodeItem* code_item, |
| 45 | uint32_t access_flags, InvokeType invoke_type, |
TDYa127 | dc5daa0 | 2013-01-09 21:31:37 +0800 | [diff] [blame] | 46 | uint32_t class_def_idx, uint32_t method_idx, jobject class_loader, |
buzbee | c531cef | 2012-10-18 07:09:20 -0700 | [diff] [blame] | 47 | const DexFile& dex_file, |
| 48 | LLVMInfo* llvm_info); |
Shih-wei Liao | bb33f2f | 2012-08-23 13:20:00 -0700 | [diff] [blame] | 49 | } |
| 50 | #endif |
| 51 | |
Logan Chien | 013b6f2 | 2012-03-02 17:20:33 +0800 | [diff] [blame] | 52 | namespace llvm { |
| 53 | extern bool TimePassesIsEnabled; |
| 54 | } |
| 55 | |
Shih-wei Liao | fc34adb | 2012-03-07 08:51:44 -0800 | [diff] [blame] | 56 | namespace { |
Logan Chien | 8b977d3 | 2012-02-21 19:14:55 +0800 | [diff] [blame] | 57 | |
Shih-wei Liao | fc34adb | 2012-03-07 08:51:44 -0800 | [diff] [blame] | 58 | pthread_once_t llvm_initialized = PTHREAD_ONCE_INIT; |
| 59 | |
| 60 | void InitializeLLVM() { |
Logan Chien | c3f8fa5 | 2012-05-11 11:23:39 +0800 | [diff] [blame] | 61 | // Initialize LLVM internal data structure for multithreading |
| 62 | llvm::llvm_start_multithreaded(); |
| 63 | |
Logan Chien | 013b6f2 | 2012-03-02 17:20:33 +0800 | [diff] [blame] | 64 | // NOTE: Uncomment following line to show the time consumption of LLVM passes |
| 65 | //llvm::TimePassesIsEnabled = true; |
| 66 | |
Shih-wei Liao | 26e9307 | 2012-05-30 19:13:08 -0700 | [diff] [blame] | 67 | // Initialize LLVM target-specific options. |
| 68 | art::compiler_llvm::InitialBackendOptions(); |
Logan Chien | c3f8fa5 | 2012-05-11 11:23:39 +0800 | [diff] [blame] | 69 | |
Shih-wei Liao | 1335a95 | 2012-07-23 18:03:00 -0700 | [diff] [blame] | 70 | // Initialize LLVM target, MC subsystem, asm printer, and asm parser. |
| 71 | #if defined(ART_TARGET) |
| 72 | // Don't initialize all targets on device. Just initialize the device's native target |
| 73 | llvm::InitializeNativeTarget(); |
| 74 | llvm::InitializeNativeTargetAsmPrinter(); |
| 75 | llvm::InitializeNativeTargetAsmParser(); |
| 76 | #else |
Logan Chien | 8b977d3 | 2012-02-21 19:14:55 +0800 | [diff] [blame] | 77 | llvm::InitializeAllTargets(); |
| 78 | llvm::InitializeAllTargetMCs(); |
| 79 | llvm::InitializeAllAsmPrinters(); |
| 80 | llvm::InitializeAllAsmParsers(); |
Shih-wei Liao | 1335a95 | 2012-07-23 18:03:00 -0700 | [diff] [blame] | 81 | #endif |
Logan Chien | 8b977d3 | 2012-02-21 19:14:55 +0800 | [diff] [blame] | 82 | |
Logan Chien | dd7cf5b | 2012-03-01 12:55:19 +0800 | [diff] [blame] | 83 | // Initialize LLVM optimization passes |
| 84 | llvm::PassRegistry ®istry = *llvm::PassRegistry::getPassRegistry(); |
| 85 | |
| 86 | llvm::initializeCore(registry); |
| 87 | llvm::initializeScalarOpts(registry); |
| 88 | llvm::initializeIPO(registry); |
| 89 | llvm::initializeAnalysis(registry); |
| 90 | llvm::initializeIPA(registry); |
| 91 | llvm::initializeTransformUtils(registry); |
| 92 | llvm::initializeInstCombine(registry); |
| 93 | llvm::initializeInstrumentation(registry); |
| 94 | llvm::initializeTarget(registry); |
Logan Chien | 8b977d3 | 2012-02-21 19:14:55 +0800 | [diff] [blame] | 95 | } |
| 96 | |
Logan Chien | f130655 | 2012-03-16 11:17:53 +0800 | [diff] [blame] | 97 | // The Guard to Shutdown LLVM |
Logan Chien | aeb5303 | 2012-03-18 02:29:38 +0800 | [diff] [blame] | 98 | // llvm::llvm_shutdown_obj llvm_guard; |
| 99 | // TODO: We are commenting out this line because this will cause SEGV from |
| 100 | // time to time. |
| 101 | // Two reasons: (1) the order of the destruction of static objects, or |
| 102 | // (2) dlopen/dlclose side-effect on static objects. |
Shih-wei Liao | fc34adb | 2012-03-07 08:51:44 -0800 | [diff] [blame] | 103 | |
| 104 | } // anonymous namespace |
| 105 | |
| 106 | |
| 107 | namespace art { |
| 108 | namespace compiler_llvm { |
Shih-wei Liao | d1fec81 | 2012-02-13 09:51:10 -0800 | [diff] [blame] | 109 | |
| 110 | |
Logan Chien | e75a8cc | 2012-02-24 12:26:43 +0800 | [diff] [blame] | 111 | llvm::Module* makeLLVMModuleContents(llvm::Module* module); |
Logan Chien | 42e0e15 | 2012-01-13 15:42:36 +0800 | [diff] [blame] | 112 | |
| 113 | |
Shih-wei Liao | d1fec81 | 2012-02-13 09:51:10 -0800 | [diff] [blame] | 114 | CompilerLLVM::CompilerLLVM(Compiler* compiler, InstructionSet insn_set) |
Logan Chien | 971bf3f | 2012-05-01 15:47:55 +0800 | [diff] [blame] | 115 | : compiler_(compiler), insn_set_(insn_set), |
| 116 | num_cunits_lock_("compilation unit counter lock"), num_cunits_(0), |
| 117 | plt_(insn_set) { |
Shih-wei Liao | fc34adb | 2012-03-07 08:51:44 -0800 | [diff] [blame] | 118 | |
| 119 | // Initialize LLVM libraries |
| 120 | pthread_once(&llvm_initialized, InitializeLLVM); |
Shih-wei Liao | d1fec81 | 2012-02-13 09:51:10 -0800 | [diff] [blame] | 121 | } |
| 122 | |
| 123 | |
| 124 | CompilerLLVM::~CompilerLLVM() { |
| 125 | } |
| 126 | |
| 127 | |
Brian Carlstrom | 641ce03 | 2013-01-31 15:21:37 -0800 | [diff] [blame] | 128 | LlvmCompilationUnit* CompilerLLVM::AllocateCompilationUnit() { |
Ian Rogers | 50b35e2 | 2012-10-04 10:09:15 -0700 | [diff] [blame] | 129 | MutexLock GUARD(Thread::Current(), num_cunits_lock_); |
Brian Carlstrom | 641ce03 | 2013-01-31 15:21:37 -0800 | [diff] [blame] | 130 | LlvmCompilationUnit* cunit = new LlvmCompilationUnit(this, num_cunits_++); |
TDYa127 | b672d1e | 2012-06-28 21:21:45 -0700 | [diff] [blame] | 131 | if (!bitcode_filename_.empty()) { |
Brian Carlstrom | 641ce03 | 2013-01-31 15:21:37 -0800 | [diff] [blame] | 132 | cunit->SetBitcodeFileName(StringPrintf("%s-%zu", bitcode_filename_.c_str(), cunit->GetIndex())); |
TDYa127 | b672d1e | 2012-06-28 21:21:45 -0700 | [diff] [blame] | 133 | } |
| 134 | return cunit; |
Logan Chien | df57614 | 2012-03-20 17:36:32 +0800 | [diff] [blame] | 135 | } |
| 136 | |
| 137 | |
Logan Chien | 7f76761 | 2012-03-01 18:54:49 +0800 | [diff] [blame] | 138 | CompiledMethod* CompilerLLVM:: |
Shih-wei Liao | bb33f2f | 2012-08-23 13:20:00 -0700 | [diff] [blame] | 139 | CompileDexMethod(OatCompilationUnit* oat_compilation_unit, InvokeType invoke_type) { |
Brian Carlstrom | 641ce03 | 2013-01-31 15:21:37 -0800 | [diff] [blame] | 140 | UniquePtr<LlvmCompilationUnit> cunit(AllocateCompilationUnit()); |
Logan Chien | 8ba2fc5 | 2012-04-23 09:10:46 +0800 | [diff] [blame] | 141 | |
jeffhao | 4028312 | 2013-01-15 13:15:24 -0800 | [diff] [blame] | 142 | #if defined(ART_USE_PORTABLE_COMPILER) |
Shih-wei Liao | bb33f2f | 2012-08-23 13:20:00 -0700 | [diff] [blame] | 143 | std::string methodName(PrettyMethod(oat_compilation_unit->GetDexMethodIndex(), |
| 144 | *oat_compilation_unit->GetDexFile())); |
TDYa127 | 87caa7e | 2012-08-25 23:23:27 -0700 | [diff] [blame] | 145 | if (insn_set_ == kX86) { |
Shih-wei Liao | bb33f2f | 2012-08-23 13:20:00 -0700 | [diff] [blame] | 146 | // Use iceland |
| 147 | UniquePtr<MethodCompiler> method_compiler( |
| 148 | new MethodCompiler(cunit.get(), compiler_, oat_compilation_unit)); |
| 149 | |
| 150 | return method_compiler->Compile(); |
| 151 | } else { |
buzbee | 26f10ee | 2012-12-21 11:16:29 -0800 | [diff] [blame] | 152 | |
buzbee | c531cef | 2012-10-18 07:09:20 -0700 | [diff] [blame] | 153 | // TODO: consolidate ArtCompileMethods |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 154 | CompileOneMethod(*compiler_, |
buzbee | c531cef | 2012-10-18 07:09:20 -0700 | [diff] [blame] | 155 | kPortable, |
| 156 | oat_compilation_unit->GetCodeItem(), |
| 157 | oat_compilation_unit->access_flags_, |
| 158 | invoke_type, |
TDYa127 | dc5daa0 | 2013-01-09 21:31:37 +0800 | [diff] [blame] | 159 | oat_compilation_unit->GetClassDefIndex(), |
buzbee | c531cef | 2012-10-18 07:09:20 -0700 | [diff] [blame] | 160 | oat_compilation_unit->GetDexMethodIndex(), |
| 161 | oat_compilation_unit->GetClassLoader(), |
| 162 | *oat_compilation_unit->GetDexFile(), |
| 163 | cunit->GetQuickContext() |
| 164 | ); |
Shih-wei Liao | bb33f2f | 2012-08-23 13:20:00 -0700 | [diff] [blame] | 165 | |
| 166 | cunit->SetCompiler(compiler_); |
| 167 | cunit->SetOatCompilationUnit(oat_compilation_unit); |
| 168 | |
| 169 | cunit->Materialize(); |
| 170 | |
buzbee | 26f10ee | 2012-12-21 11:16:29 -0800 | [diff] [blame] | 171 | Compiler::MethodReference mref(oat_compilation_unit->GetDexFile(), |
| 172 | oat_compilation_unit->GetDexMethodIndex()); |
| 173 | return new CompiledMethod(compiler_->GetInstructionSet(), |
| 174 | cunit->GetCompiledCode(), |
TDYa127 | ce4cc0d | 2012-11-18 16:59:53 -0800 | [diff] [blame] | 175 | *verifier::MethodVerifier::GetDexGcMap(mref)); |
Shih-wei Liao | bb33f2f | 2012-08-23 13:20:00 -0700 | [diff] [blame] | 176 | } |
Shih-wei Liao | 21d28f5 | 2012-06-12 05:55:00 -0700 | [diff] [blame] | 177 | #else |
Logan Chien | 8b977d3 | 2012-02-21 19:14:55 +0800 | [diff] [blame] | 178 | UniquePtr<MethodCompiler> method_compiler( |
Logan Chien | 971bf3f | 2012-05-01 15:47:55 +0800 | [diff] [blame] | 179 | new MethodCompiler(cunit.get(), compiler_, oat_compilation_unit)); |
Logan Chien | 8b977d3 | 2012-02-21 19:14:55 +0800 | [diff] [blame] | 180 | |
Logan Chien | 7f76761 | 2012-03-01 18:54:49 +0800 | [diff] [blame] | 181 | return method_compiler->Compile(); |
Shih-wei Liao | 21d28f5 | 2012-06-12 05:55:00 -0700 | [diff] [blame] | 182 | #endif |
Shih-wei Liao | d1fec81 | 2012-02-13 09:51:10 -0800 | [diff] [blame] | 183 | } |
Logan Chien | 8342616 | 2011-12-09 09:29:50 +0800 | [diff] [blame] | 184 | |
| 185 | |
Logan Chien | 7f76761 | 2012-03-01 18:54:49 +0800 | [diff] [blame] | 186 | CompiledMethod* CompilerLLVM:: |
| 187 | CompileNativeMethod(OatCompilationUnit* oat_compilation_unit) { |
Brian Carlstrom | 641ce03 | 2013-01-31 15:21:37 -0800 | [diff] [blame] | 188 | UniquePtr<LlvmCompilationUnit> cunit(AllocateCompilationUnit()); |
Logan Chien | 8ba2fc5 | 2012-04-23 09:10:46 +0800 | [diff] [blame] | 189 | |
Logan Chien | 8b977d3 | 2012-02-21 19:14:55 +0800 | [diff] [blame] | 190 | UniquePtr<JniCompiler> jni_compiler( |
Logan Chien | 971bf3f | 2012-05-01 15:47:55 +0800 | [diff] [blame] | 191 | new JniCompiler(cunit.get(), *compiler_, oat_compilation_unit)); |
Logan Chien | 8b977d3 | 2012-02-21 19:14:55 +0800 | [diff] [blame] | 192 | |
Logan Chien | 7f76761 | 2012-03-01 18:54:49 +0800 | [diff] [blame] | 193 | return jni_compiler->Compile(); |
Logan Chien | 88894ee | 2012-02-13 16:42:22 +0800 | [diff] [blame] | 194 | } |
| 195 | |
| 196 | |
Logan Chien | f04364f | 2012-02-10 12:01:39 +0800 | [diff] [blame] | 197 | CompiledInvokeStub* CompilerLLVM::CreateInvokeStub(bool is_static, |
| 198 | char const *shorty) { |
Brian Carlstrom | 641ce03 | 2013-01-31 15:21:37 -0800 | [diff] [blame] | 199 | UniquePtr<LlvmCompilationUnit> cunit(AllocateCompilationUnit()); |
Logan Chien | 8ba2fc5 | 2012-04-23 09:10:46 +0800 | [diff] [blame] | 200 | |
TDYa127 | eead4ac | 2012-06-03 07:15:25 -0700 | [diff] [blame] | 201 | UniquePtr<StubCompiler> stub_compiler( |
Logan Chien | 971bf3f | 2012-05-01 15:47:55 +0800 | [diff] [blame] | 202 | new StubCompiler(cunit.get(), *compiler_)); |
Logan Chien | 8b977d3 | 2012-02-21 19:14:55 +0800 | [diff] [blame] | 203 | |
Logan Chien | 7a2a23a | 2012-06-06 11:01:00 +0800 | [diff] [blame] | 204 | return stub_compiler->CreateInvokeStub(is_static, shorty); |
| 205 | } |
TDYa127 | eead4ac | 2012-06-03 07:15:25 -0700 | [diff] [blame] | 206 | |
TDYa127 | eead4ac | 2012-06-03 07:15:25 -0700 | [diff] [blame] | 207 | |
Logan Chien | 7a2a23a | 2012-06-06 11:01:00 +0800 | [diff] [blame] | 208 | CompiledInvokeStub* CompilerLLVM::CreateProxyStub(char const *shorty) { |
Brian Carlstrom | 641ce03 | 2013-01-31 15:21:37 -0800 | [diff] [blame] | 209 | UniquePtr<LlvmCompilationUnit> cunit(AllocateCompilationUnit()); |
Logan Chien | 7a2a23a | 2012-06-06 11:01:00 +0800 | [diff] [blame] | 210 | |
| 211 | UniquePtr<StubCompiler> stub_compiler( |
Logan Chien | 971bf3f | 2012-05-01 15:47:55 +0800 | [diff] [blame] | 212 | new StubCompiler(cunit.get(), *compiler_)); |
Logan Chien | 7a2a23a | 2012-06-06 11:01:00 +0800 | [diff] [blame] | 213 | |
| 214 | return stub_compiler->CreateProxyStub(shorty); |
Logan Chien | f04364f | 2012-02-10 12:01:39 +0800 | [diff] [blame] | 215 | } |
| 216 | |
Logan Chien | 8342616 | 2011-12-09 09:29:50 +0800 | [diff] [blame] | 217 | } // namespace compiler_llvm |
| 218 | } // namespace art |
Shih-wei Liao | c4c9881 | 2012-03-10 21:55:51 -0800 | [diff] [blame] | 219 | |
Logan Chien | 106b2a0 | 2012-03-18 04:41:38 +0800 | [diff] [blame] | 220 | inline static art::compiler_llvm::CompilerLLVM* ContextOf(art::Compiler& compiler) { |
| 221 | void *compiler_context = compiler.GetCompilerContext(); |
| 222 | CHECK(compiler_context != NULL); |
| 223 | return reinterpret_cast<art::compiler_llvm::CompilerLLVM*>(compiler_context); |
| 224 | } |
| 225 | |
| 226 | inline static const art::compiler_llvm::CompilerLLVM* ContextOf(const art::Compiler& compiler) { |
| 227 | void *compiler_context = compiler.GetCompilerContext(); |
| 228 | CHECK(compiler_context != NULL); |
| 229 | return reinterpret_cast<const art::compiler_llvm::CompilerLLVM*>(compiler_context); |
| 230 | } |
| 231 | |
| 232 | extern "C" void ArtInitCompilerContext(art::Compiler& compiler) { |
| 233 | CHECK(compiler.GetCompilerContext() == NULL); |
| 234 | |
| 235 | art::compiler_llvm::CompilerLLVM* compiler_llvm = |
| 236 | new art::compiler_llvm::CompilerLLVM(&compiler, |
| 237 | compiler.GetInstructionSet()); |
| 238 | |
| 239 | compiler.SetCompilerContext(compiler_llvm); |
| 240 | } |
| 241 | |
Logan Chien | 971bf3f | 2012-05-01 15:47:55 +0800 | [diff] [blame] | 242 | extern "C" void ArtUnInitCompilerContext(art::Compiler& compiler) { |
| 243 | delete ContextOf(compiler); |
| 244 | compiler.SetCompilerContext(NULL); |
| 245 | } |
Elliott Hughes | 3fa1b7e | 2012-03-13 17:06:22 -0700 | [diff] [blame] | 246 | extern "C" art::CompiledMethod* ArtCompileMethod(art::Compiler& compiler, |
Shih-wei Liao | c4c9881 | 2012-03-10 21:55:51 -0800 | [diff] [blame] | 247 | const art::DexFile::CodeItem* code_item, |
Ian Rogers | 08f753d | 2012-08-24 14:35:25 -0700 | [diff] [blame] | 248 | uint32_t access_flags, |
| 249 | art::InvokeType invoke_type, |
Ian Rogers | fffdb02 | 2013-01-04 15:14:08 -0800 | [diff] [blame] | 250 | uint32_t class_def_idx, |
Ian Rogers | 08f753d | 2012-08-24 14:35:25 -0700 | [diff] [blame] | 251 | uint32_t method_idx, |
Shih-wei Liao | cd05a62 | 2012-08-15 00:02:05 -0700 | [diff] [blame] | 252 | jobject class_loader, |
Ian Rogers | 08f753d | 2012-08-24 14:35:25 -0700 | [diff] [blame] | 253 | const art::DexFile& dex_file) { |
Ian Rogers | fffdb02 | 2013-01-04 15:14:08 -0800 | [diff] [blame] | 254 | UNUSED(class_def_idx); // TODO: this is used with Compiler::RequiresConstructorBarrier. |
Shih-wei Liao | c4c9881 | 2012-03-10 21:55:51 -0800 | [diff] [blame] | 255 | art::ClassLinker *class_linker = art::Runtime::Current()->GetClassLinker(); |
Shih-wei Liao | c4c9881 | 2012-03-10 21:55:51 -0800 | [diff] [blame] | 256 | |
| 257 | art::OatCompilationUnit oat_compilation_unit( |
Shih-wei Liao | cd05a62 | 2012-08-15 00:02:05 -0700 | [diff] [blame] | 258 | class_loader, class_linker, dex_file, code_item, |
TDYa127 | dc5daa0 | 2013-01-09 21:31:37 +0800 | [diff] [blame] | 259 | class_def_idx, method_idx, access_flags); |
TDYa127 | 0200d07 | 2012-04-17 20:55:08 -0700 | [diff] [blame] | 260 | art::compiler_llvm::CompilerLLVM* compiler_llvm = ContextOf(compiler); |
Shih-wei Liao | bb33f2f | 2012-08-23 13:20:00 -0700 | [diff] [blame] | 261 | art::CompiledMethod* result = compiler_llvm->CompileDexMethod(&oat_compilation_unit, invoke_type); |
TDYa127 | 0200d07 | 2012-04-17 20:55:08 -0700 | [diff] [blame] | 262 | return result; |
Shih-wei Liao | c4c9881 | 2012-03-10 21:55:51 -0800 | [diff] [blame] | 263 | } |
| 264 | |
| 265 | extern "C" art::CompiledMethod* ArtJniCompileMethod(art::Compiler& compiler, |
| 266 | uint32_t access_flags, uint32_t method_idx, |
Shih-wei Liao | c4c9881 | 2012-03-10 21:55:51 -0800 | [diff] [blame] | 267 | const art::DexFile& dex_file) { |
Shih-wei Liao | c4c9881 | 2012-03-10 21:55:51 -0800 | [diff] [blame] | 268 | art::ClassLinker *class_linker = art::Runtime::Current()->GetClassLinker(); |
Shih-wei Liao | c4c9881 | 2012-03-10 21:55:51 -0800 | [diff] [blame] | 269 | |
| 270 | art::OatCompilationUnit oat_compilation_unit( |
Shih-wei Liao | cd05a62 | 2012-08-15 00:02:05 -0700 | [diff] [blame] | 271 | NULL, class_linker, dex_file, NULL, |
TDYa127 | dc5daa0 | 2013-01-09 21:31:37 +0800 | [diff] [blame] | 272 | 0, method_idx, access_flags); |
Shih-wei Liao | c4c9881 | 2012-03-10 21:55:51 -0800 | [diff] [blame] | 273 | |
Logan Chien | 106b2a0 | 2012-03-18 04:41:38 +0800 | [diff] [blame] | 274 | art::compiler_llvm::CompilerLLVM* compiler_llvm = ContextOf(compiler); |
Elliott Hughes | 6f4976c | 2012-03-13 21:19:01 -0700 | [diff] [blame] | 275 | art::CompiledMethod* result = compiler_llvm->CompileNativeMethod(&oat_compilation_unit); |
Elliott Hughes | 13b835a | 2012-03-13 19:45:22 -0700 | [diff] [blame] | 276 | return result; |
Shih-wei Liao | c4c9881 | 2012-03-10 21:55:51 -0800 | [diff] [blame] | 277 | } |
| 278 | |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 279 | extern "C" art::CompiledInvokeStub* ArtCreateLLVMInvokeStub(art::Compiler& compiler, |
| 280 | bool is_static, |
| 281 | const char* shorty, |
| 282 | uint32_t shorty_len) { |
TDYa127 | 0200d07 | 2012-04-17 20:55:08 -0700 | [diff] [blame] | 283 | art::compiler_llvm::CompilerLLVM* compiler_llvm = ContextOf(compiler); |
| 284 | art::CompiledInvokeStub* result = compiler_llvm->CreateInvokeStub(is_static, shorty); |
TDYa127 | 0200d07 | 2012-04-17 20:55:08 -0700 | [diff] [blame] | 285 | return result; |
Logan Chien | 106b2a0 | 2012-03-18 04:41:38 +0800 | [diff] [blame] | 286 | } |
| 287 | |
Logan Chien | 7a2a23a | 2012-06-06 11:01:00 +0800 | [diff] [blame] | 288 | extern "C" art::CompiledInvokeStub* ArtCreateProxyStub(art::Compiler& compiler, |
| 289 | const char* shorty, |
| 290 | uint32_t shorty_len) { |
| 291 | art::compiler_llvm::CompilerLLVM* compiler_llvm = ContextOf(compiler); |
| 292 | art::CompiledInvokeStub* result = compiler_llvm->CreateProxyStub(shorty); |
Logan Chien | 7a2a23a | 2012-06-06 11:01:00 +0800 | [diff] [blame] | 293 | return result; |
| 294 | } |
| 295 | |
Logan Chien | 106b2a0 | 2012-03-18 04:41:38 +0800 | [diff] [blame] | 296 | extern "C" void compilerLLVMSetBitcodeFileName(art::Compiler& compiler, |
| 297 | std::string const& filename) { |
| 298 | ContextOf(compiler)->SetBitcodeFileName(filename); |
Shih-wei Liao | c4c9881 | 2012-03-10 21:55:51 -0800 | [diff] [blame] | 299 | } |