Fix the LLVM build. Separate out libart-compiler-llvm.so.
After this refactoring:
If (!USE_LLVM_COMPILER), I pass the test-art and boot the phone alright.
The behavior is the same for non-LLVM builds as before. Multi-target
art-compiler shared libraries are generated as before.
If (USE_LLVM_COMPILER), I generate libart-compiler-llvm.so successfully.
Note that the ideal refactoring for the next step will be to always build
art-compiler and LLVM-[arm|mips|x86] shared libraries. Currently, we
haven't removed all the ifdefs for libart.so yet, so this is not ideal yet.
Reason for not-done-yet is that the next step requires discussions.
I can remove all the ifdefs today, but then the (!USE_LLVM_COMPILER)
build will incur extra fields and overhead.
This refactoring allows us to restore the LLVM build situation to be before
the breakage yesterday, so we can continue making forward progress again.
One difficulty in the refactoring is that LLVM is not a method compiler
in default, unlike (!USE_LLVM_COMPILER). LLVM actually compiles an LLVM module
at a time normally. So we need to do more call backs and tell
libart-compiler-llvm.so in each invocation where we are in terms of
OatCompilationUnit.
Another difficulty is that currently our LLVM compiler is not
multithreaded and requires locking, unlike (!USE_LLVM_COMPILER). So more
callbacks are needed. This will be fixed when we fix the multithreading
issue.
Change-Id: I93bce21b6d673254188f2a60b1a7f91b508e497f
diff --git a/src/compiler_llvm/compiler_llvm.cc b/src/compiler_llvm/compiler_llvm.cc
index 67b3f4d..5a3725e 100644
--- a/src/compiler_llvm/compiler_llvm.cc
+++ b/src/compiler_llvm/compiler_llvm.cc
@@ -16,8 +16,10 @@
#include "compiler_llvm.h"
+#include "class_linker.h"
#include "compilation_unit.h"
#include "compiler.h"
+#include "dex_cache.h"
#include "ir_builder.h"
#include "jni_compiler.h"
#include "method_compiler.h"
@@ -207,3 +209,78 @@
} // namespace compiler_llvm
} // namespace art
+
+namespace {
+
+void ensureCompilerLLVM(art::Compiler& compiler) {
+ if (compiler.GetCompilerLLVM() == NULL) {
+ compiler.SetCompilerLLVM(new art::compiler_llvm::CompilerLLVM(&compiler,
+ compiler.GetInstructionSet()));
+ }
+ art::compiler_llvm::CompilerLLVM* compiler_llvm = compiler.GetCompilerLLVM();
+ compiler_llvm->SetElfFileName(compiler.GetElfFileName());
+ compiler_llvm->SetBitcodeFileName(compiler.GetBitcodeFileName());
+}
+
+} // anonymous namespace
+
+extern "C" art::CompiledMethod* oatCompileMethod(art::Compiler& compiler,
+ const art::DexFile::CodeItem* code_item,
+ uint32_t access_flags, uint32_t method_idx,
+ const art::ClassLoader* class_loader,
+ const art::DexFile& dex_file)
+{
+ ensureCompilerLLVM(compiler);
+
+ art::ClassLinker *class_linker = art::Runtime::Current()->GetClassLinker();
+ art::DexCache *dex_cache = class_linker->FindDexCache(dex_file);
+
+ art::OatCompilationUnit oat_compilation_unit(
+ class_loader, class_linker, dex_file, *dex_cache, code_item,
+ method_idx, access_flags);
+
+ return compiler.GetCompilerLLVM()->CompileDexMethod(&oat_compilation_unit);
+}
+
+extern "C" art::CompiledMethod* ArtJniCompileMethod(art::Compiler& compiler,
+ uint32_t access_flags, uint32_t method_idx,
+ const art::ClassLoader* class_loader,
+ const art::DexFile& dex_file) {
+ ensureCompilerLLVM(compiler);
+
+ art::ClassLinker *class_linker = art::Runtime::Current()->GetClassLinker();
+ art::DexCache *dex_cache = class_linker->FindDexCache(dex_file);
+
+ art::OatCompilationUnit oat_compilation_unit(
+ class_loader, class_linker, dex_file, *dex_cache, NULL,
+ method_idx, access_flags);
+
+ return compiler.GetCompilerLLVM()->CompileNativeMethod(&oat_compilation_unit);
+}
+
+extern "C" art::CompiledInvokeStub* ArtCreateInvokeStub(art::Compiler& compiler, bool is_static,
+ const char* shorty, uint32_t shorty_len) {
+ ensureCompilerLLVM(compiler);
+ //shorty_len = 0; // To make the compiler happy
+ return compiler.GetCompilerLLVM()->CreateInvokeStub(is_static, shorty);
+}
+
+extern "C" void compilerLLVMMaterializeRemainder(art::Compiler& compiler) {
+ ensureCompilerLLVM(compiler);
+ compiler.GetCompilerLLVM()->MaterializeRemainder();
+}
+
+extern "C" void compilerLLVMMaterializeIfThresholdReached(art::Compiler& compiler) {
+ ensureCompilerLLVM(compiler);
+ compiler.GetCompilerLLVM()->MaterializeIfThresholdReached();
+}
+
+// Note: Using this function carefully!!! This is temporary solution, we will remove it.
+extern "C" art::MutexLock* compilerLLVMMutexLock(art::Compiler& compiler) {
+ ensureCompilerLLVM(compiler);
+ return new art::MutexLock(compiler.GetCompilerLLVM()->compiler_lock_);
+}
+
+extern "C" void compilerLLVMDispose(art::Compiler& compiler) {
+ delete compiler.GetCompilerLLVM();
+}