clover: Don't use llvm's global context
authorTom Stellard <thomas.stellard@amd.com>
Tue, 17 Jun 2014 15:12:06 +0000 (08:12 -0700)
committerTom Stellard <thomas.stellard@amd.com>
Thu, 19 Jun 2014 14:41:10 +0000 (10:41 -0400)
An LLVMContext should only be accessed by a single and using the global
context was causing crashes in multi-threaded environments.  Now we use
a separate context for each compile.

Reviewed-by: Francisco Jerez <currojerez@riseup.net>
CC: "10.1 10.2" <mesa-stable@lists.freedesktop.org>
src/gallium/state_trackers/clover/llvm/invocation.cpp

index 0148721921ab624a476e38b3da9bbc3f1391743b..c3daa81793862758a952e383b42aa8df2e797521 100644 (file)
@@ -117,12 +117,13 @@ namespace {
 #endif
 
    llvm::Module *
-   compile(const std::string &source, const std::string &name,
-           const std::string &triple, const std::string &processor,
-           const std::string &opts, clang::LangAS::Map& address_spaces) {
+   compile(llvm::LLVMContext &llvm_ctx, const std::string &source,
+           const std::string &name, const std::string &triple,
+           const std::string &processor, const std::string &opts,
+           clang::LangAS::Map& address_spaces) {
 
       clang::CompilerInstance c;
-      clang::EmitLLVMOnlyAction act(&llvm::getGlobalContext());
+      clang::EmitLLVMOnlyAction act(&llvm_ctx);
       std::string log;
       llvm::raw_string_ostream s_log(log);
       std::string libclc_path = LIBCLC_LIBEXECDIR + processor + "-"
@@ -399,10 +400,12 @@ clover::compile_program_llvm(const compat::string &source,
                       target.size() - processor_str_len - 1);
    clang::LangAS::Map address_spaces;
 
+   llvm::LLVMContext llvm_ctx;
+
    // The input file name must have the .cl extension in order for the
    // CompilerInvocation class to recognize it as an OpenCL source file.
-   llvm::Module *mod = compile(source, "input.cl", triple, processor, opts,
-                                                                address_spaces);
+   llvm::Module *mod = compile(llvm_ctx, source, "input.cl", triple, processor,
+                               opts, address_spaces);
 
    find_kernels(mod, kernels);