summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Elliott Hughes <enh@google.com> 2012-03-13 21:19:01 -0700
committer Elliott Hughes <enh@google.com> 2012-03-14 11:27:16 -0700
commit6f4976c1a9fdaf108974143cd11e6b46037fd24e (patch)
treef0c21b703eab0039f5c31e1b272144c5228b8fa3
parent13b835a45f3dccff1c6d024ad82a2044831c7c41 (diff)
Replace some LLVM-specific code with something more general.
This basically gives any compiler a place to hang extra private data off art::Compiler, even though only LLVM needs it right now. Change-Id: I408778ea1010ab2ad9ec4810e5c53d468a8772c2
-rw-r--r--src/compiler.cc4
-rw-r--r--src/compiler.h21
-rw-r--r--src/compiler_llvm/compiler_llvm.cc43
3 files changed, 24 insertions, 44 deletions
diff --git a/src/compiler.cc b/src/compiler.cc
index 8e8958b15f..fe4f4fc1e1 100644
--- a/src/compiler.cc
+++ b/src/compiler.cc
@@ -282,11 +282,9 @@ Compiler::Compiler(InstructionSet instruction_set, bool image, size_t thread_cou
support_debugging_(support_debugging),
stats_(new AOTCompilationStats),
image_classes_(image_classes),
-#if defined(ART_USE_LLVM_COMPILER)
- compiler_llvm_(NULL),
-#endif
compiler_library_(NULL),
compiler_(NULL),
+ compiler_context_(NULL),
jni_compiler_(NULL),
create_invoke_stub_(NULL)
{
diff --git a/src/compiler.h b/src/compiler.h
index 55273b7971..aa32854c26 100644
--- a/src/compiler.h
+++ b/src/compiler.h
@@ -32,18 +32,11 @@
namespace art {
-#if defined(ART_USE_LLVM_COMPILER)
-namespace compiler_llvm {
-class CompilerLLVM;
-}
-#endif
-
class AOTCompilationStats;
class Context;
class OatCompilationUnit;
class TimingLogger;
-
class Compiler {
public:
// Create a compiler targeting the requested "instruction_set".
@@ -129,14 +122,15 @@ class Compiler {
void SetBitcodeFileName(std::string const& filename);
std::string const& GetElfFileName();
std::string const& GetBitcodeFileName();
+#endif
- void SetCompilerLLVM(compiler_llvm::CompilerLLVM* compiler_llvm) {
- compiler_llvm_ = compiler_llvm;
+ void SetCompilerContext(void* compiler_context) {
+ compiler_context_ = compiler_context;
}
- compiler_llvm::CompilerLLVM* GetCompilerLLVM() const {
- return compiler_llvm_;
+
+ void* GetCompilerContext() const {
+ return compiler_context_;
}
-#endif
private:
@@ -202,7 +196,6 @@ class Compiler {
const std::set<std::string>* image_classes_;
#if defined(ART_USE_LLVM_COMPILER)
- compiler_llvm::CompilerLLVM* compiler_llvm_;
std::string elf_filename_;
std::string bitcode_filename_;
typedef void (*CompilerCallbackFn)(Compiler& compiler);
@@ -217,6 +210,8 @@ class Compiler {
const DexFile& dex_file);
CompilerFn compiler_;
+ void* compiler_context_;
+
typedef CompiledMethod* (*JniCompilerFn)(Compiler& compiler,
uint32_t access_flags, uint32_t method_idx,
const ClassLoader* class_loader,
diff --git a/src/compiler_llvm/compiler_llvm.cc b/src/compiler_llvm/compiler_llvm.cc
index 5ef171088d..dc3b7cbcf2 100644
--- a/src/compiler_llvm/compiler_llvm.cc
+++ b/src/compiler_llvm/compiler_llvm.cc
@@ -206,23 +206,18 @@ CompiledInvokeStub* CompilerLLVM::CreateInvokeStub(bool is_static,
return upcall_compiler->CreateStub(is_static, shorty);
}
-
-} // 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()));
+CompilerLLVM* EnsureCompilerLLVM(art::Compiler& compiler) {
+ if (compiler.GetCompilerContext() == NULL) {
+ compiler.SetCompilerContext(new CompilerLLVM(&compiler, compiler.GetInstructionSet()));
}
- art::compiler_llvm::CompilerLLVM* compiler_llvm = compiler.GetCompilerLLVM();
+ CompilerLLVM* compiler_llvm = reinterpret_cast<CompilerLLVM*>(compiler.GetCompilerContext());
compiler_llvm->SetElfFileName(compiler.GetElfFileName());
compiler_llvm->SetBitcodeFileName(compiler.GetBitcodeFileName());
+ return compiler_llvm;
}
-} // anonymous namespace
+} // namespace compiler_llvm
+} // namespace art
extern "C" art::CompiledMethod* ArtCompileMethod(art::Compiler& compiler,
const art::DexFile::CodeItem* code_item,
@@ -230,8 +225,6 @@ extern "C" art::CompiledMethod* ArtCompileMethod(art::Compiler& compiler,
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);
@@ -239,15 +232,13 @@ extern "C" art::CompiledMethod* ArtCompileMethod(art::Compiler& compiler,
class_loader, class_linker, dex_file, *dex_cache, code_item,
method_idx, access_flags);
- return compiler.GetCompilerLLVM()->CompileDexMethod(&oat_compilation_unit);
+ return art::compiler_llvm::EnsureCompilerLLVM(compiler)->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);
@@ -255,30 +246,26 @@ extern "C" art::CompiledMethod* ArtJniCompileMethod(art::Compiler& compiler,
class_loader, class_linker, dex_file, *dex_cache, NULL,
method_idx, access_flags);
- art::CompiledMethod* result =
- compiler.GetCompilerLLVM()->CompileNativeMethod(&oat_compilation_unit);
- compiler.GetCompilerLLVM()->MaterializeIfThresholdReached();
+ art::compiler_llvm::CompilerLLVM* compiler_llvm = art::compiler_llvm::EnsureCompilerLLVM(compiler);
+ art::CompiledMethod* result = compiler_llvm->CompileNativeMethod(&oat_compilation_unit);
+ compiler_llvm->MaterializeIfThresholdReached();
return result;
}
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);
+ return art::compiler_llvm::EnsureCompilerLLVM(compiler)->CreateInvokeStub(is_static, shorty);
}
extern "C" void compilerLLVMMaterializeRemainder(art::Compiler& compiler) {
- ensureCompilerLLVM(compiler);
- compiler.GetCompilerLLVM()->MaterializeRemainder();
+ art::compiler_llvm::EnsureCompilerLLVM(compiler)->MaterializeRemainder();
}
// 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_);
+ return new art::MutexLock(art::compiler_llvm::EnsureCompilerLLVM(compiler)->compiler_lock_);
}
extern "C" void compilerLLVMDispose(art::Compiler& compiler) {
- delete compiler.GetCompilerLLVM();
+ delete art::compiler_llvm::EnsureCompilerLLVM(compiler);
}