[Mesa-dev] [PATCH 1/5] clover: Don't use llvm's global context

Francisco Jerez currojerez at riseup.net
Thu Jun 19 04:38:07 PDT 2014


Tom Stellard <thomas.stellard at amd.com> writes:

> 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.

For this patch:
Reviewed-by: Francisco Jerez <currojerez at riseup.net>

> ---
>  src/gallium/state_trackers/clover/llvm/invocation.cpp | 15 +++++++++------
>  1 file changed, 9 insertions(+), 6 deletions(-)
>
> diff --git a/src/gallium/state_trackers/clover/llvm/invocation.cpp b/src/gallium/state_trackers/clover/llvm/invocation.cpp
> index 82e262f..48810bd 100644
> --- a/src/gallium/state_trackers/clover/llvm/invocation.cpp
> +++ b/src/gallium/state_trackers/clover/llvm/invocation.cpp
> @@ -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 + "-"
> @@ -394,10 +395,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);
>  
> -- 
> 1.8.1.4
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 229 bytes
Desc: not available
URL: <http://lists.freedesktop.org/archives/mesa-dev/attachments/20140619/6778af56/attachment.sig>


More information about the mesa-dev mailing list