summaryrefslogtreecommitdiff
path: root/src/compiler
diff options
context:
space:
mode:
Diffstat (limited to 'src/compiler')
-rw-r--r--src/compiler/Compiler.h6
-rw-r--r--src/compiler/CompilerIR.h2
-rw-r--r--src/compiler/Frontend.cc39
-rw-r--r--src/compiler/codegen/MethodBitcode.cc19
4 files changed, 41 insertions, 25 deletions
diff --git a/src/compiler/Compiler.h b/src/compiler/Compiler.h
index 8bda3feddc..7eb32c2f04 100644
--- a/src/compiler/Compiler.h
+++ b/src/compiler/Compiler.h
@@ -178,10 +178,10 @@ enum DataFlowAnalysisMode {
};
#if defined(ART_USE_QUICK_COMPILER)
-class QuickCompiler {
+class LLVMInfo {
public:
- QuickCompiler();
- ~QuickCompiler();
+ LLVMInfo();
+ ~LLVMInfo();
llvm::LLVMContext* GetLLVMContext() {
return llvm_context_.get();
diff --git a/src/compiler/CompilerIR.h b/src/compiler/CompilerIR.h
index 593fce5e04..5a10831a0d 100644
--- a/src/compiler/CompilerIR.h
+++ b/src/compiler/CompilerIR.h
@@ -549,7 +549,7 @@ struct CompilationUnit {
Checkstats* checkstats;
#if defined(ART_USE_QUICK_COMPILER)
bool genBitcode;
- QuickCompiler* quick_compiler;
+ LLVMInfo* llvm_info;
llvm::LLVMContext* context;
llvm::Module* module;
llvm::Function* func;
diff --git a/src/compiler/Frontend.cc b/src/compiler/Frontend.cc
index d1259b7484..72eb8a1735 100644
--- a/src/compiler/Frontend.cc
+++ b/src/compiler/Frontend.cc
@@ -21,10 +21,24 @@
#include "object.h"
#include "runtime.h"
+#if defined(ART_USE_QUICK_COMPILER)
+#include <llvm/Support/Threading.h>
+
+namespace {
+ pthread_once_t llvm_multi_init = PTHREAD_ONCE_INIT;
+ void InitializeLLVMForQuick() {
+ llvm::llvm_start_multithreaded();
+ }
+}
+#endif
+
namespace art {
#if defined(ART_USE_QUICK_COMPILER)
-QuickCompiler::QuickCompiler() {
+LLVMInfo::LLVMInfo() {
+#if !defined(ART_USE_LLVM_COMPILER)
+ pthread_once(&llvm_multi_init, InitializeLLVMForQuick);
+#endif
// Create context, module, intrinsic helper & ir builder
llvm_context_.reset(new llvm::LLVMContext());
llvm_module_ = new llvm::Module("art", *llvm_context_);
@@ -33,17 +47,17 @@ QuickCompiler::QuickCompiler() {
ir_builder_.reset(new greenland::IRBuilder(*llvm_context_, *llvm_module_, *intrinsic_helper_));
}
-QuickCompiler::~QuickCompiler() {
+LLVMInfo::~LLVMInfo() {
}
extern "C" void ArtInitQuickCompilerContext(art::Compiler& compiler) {
CHECK(compiler.GetCompilerContext() == NULL);
- QuickCompiler* quickCompiler = new QuickCompiler();
- compiler.SetCompilerContext(quickCompiler);
+ LLVMInfo* llvmInfo = new LLVMInfo();
+ compiler.SetCompilerContext(llvmInfo);
}
extern "C" void ArtUnInitQuickCompilerContext(art::Compiler& compiler) {
- delete reinterpret_cast<QuickCompiler*>(compiler.GetCompilerContext());
+ delete reinterpret_cast<LLVMInfo*>(compiler.GetCompilerContext());
compiler.SetCompilerContext(NULL);
}
#endif
@@ -777,7 +791,7 @@ CompiledMethod* compileMethod(Compiler& compiler,
uint32_t method_idx, jobject class_loader,
const DexFile& dex_file
#if defined(ART_USE_QUICK_COMPILER)
- , QuickCompiler* quick_compiler,
+ , LLVMInfo* llvm_info,
bool gbcOnly
#endif
)
@@ -812,14 +826,7 @@ CompiledMethod* compileMethod(Compiler& compiler,
DCHECK((cUnit->instructionSet == kThumb2) ||
(cUnit->instructionSet == kX86) ||
(cUnit->instructionSet == kMips));
- if (gbcOnly) {
- cUnit->quick_compiler = quick_compiler;
- } else {
- // TODO: We need one LLVMContext per thread.
- cUnit->quick_compiler =
- reinterpret_cast<QuickCompiler*>(compiler.GetCompilerContext());
- }
- DCHECK(cUnit->quick_compiler != NULL);
+ cUnit->llvm_info = llvm_info;
if (cUnit->instructionSet == kThumb2) {
// TODO: remove this once x86 is tested
cUnit->genBitcode = true;
@@ -1257,10 +1264,10 @@ void oatCompileMethodToGBC(Compiler& compiler,
uint32_t access_flags, InvokeType invoke_type,
uint32_t method_idx, jobject class_loader,
const DexFile& dex_file,
- QuickCompiler* quick_compiler)
+ LLVMInfo* llvm_info)
{
compileMethod(compiler, code_item, access_flags, invoke_type, method_idx, class_loader,
- dex_file, quick_compiler, true);
+ dex_file, llvm_info, true);
}
#else
CompiledMethod* oatCompileMethod(Compiler& compiler,
diff --git a/src/compiler/codegen/MethodBitcode.cc b/src/compiler/codegen/MethodBitcode.cc
index 58678a0acb..cf07ea45c3 100644
--- a/src/compiler/codegen/MethodBitcode.cc
+++ b/src/compiler/codegen/MethodBitcode.cc
@@ -170,11 +170,20 @@ void createLocFromValue(CompilationUnit* cUnit, llvm::Value* val)
}
void initIR(CompilationUnit* cUnit)
{
- QuickCompiler* quick = cUnit->quick_compiler;
- cUnit->context = quick->GetLLVMContext();
- cUnit->module = quick->GetLLVMModule();
- cUnit->intrinsic_helper = quick->GetIntrinsicHelper();
- cUnit->irb = quick->GetIRBuilder();
+ LLVMInfo* llvmInfo = cUnit->llvm_info;
+ if (llvmInfo == NULL) {
+ CompilerTls* tls = cUnit->compiler->GetTls();
+ CHECK(tls != NULL);
+ llvmInfo = static_cast<LLVMInfo*>(tls->GetLLVMInfo());
+ if (llvmInfo == NULL) {
+ llvmInfo = new LLVMInfo();
+ tls->SetLLVMInfo(llvmInfo);
+ }
+ }
+ cUnit->context = llvmInfo->GetLLVMContext();
+ cUnit->module = llvmInfo->GetLLVMModule();
+ cUnit->intrinsic_helper = llvmInfo->GetIntrinsicHelper();
+ cUnit->irb = llvmInfo->GetIRBuilder();
}
const char* llvmSSAName(CompilationUnit* cUnit, int ssaReg) {