[Mesa-dev] [PATCH] various: Fix missing DumpModule with recent LLVM.

Roland Scheidegger sroland at vmware.com
Sat Jan 28 21:39:54 UTC 2017


Maybe should use the new version for older llvm versions too? I think it
would work back to around llvm 3.4 or 3.5. Meaning you don't need a
ifdef for the radeon drivers.
Or ist there any disadvantage of this versus the older method?

Roland

Am 28.01.2017 um 17:40 schrieb Bas Nieuwenhuizen:
> Since LLVM revision 293359 DumpModule gets only implemented when
> either a debug build or LLVM_ENABLE_DUMP is set.
> 
> This patch adds a direct replacement for the function for radv and
> radeonsi, However, as I don't know a good place to put common LLVM
> code for all three I inlined the implementation for LLVMPipe.
> 
> Signed-off-by: Bas Nieuwenhuizen <basni at google.com>
> ---
>  src/amd/common/ac_llvm_util.c            | 12 ++++++++++++
>  src/amd/common/ac_llvm_util.h            |  3 +++
>  src/amd/common/ac_nir_to_llvm.c          |  2 +-
>  src/gallium/drivers/llvmpipe/lp_jit.c    |  8 +++++++-
>  src/gallium/drivers/radeonsi/si_shader.c |  6 +++---
>  5 files changed, 26 insertions(+), 5 deletions(-)
> 
> diff --git a/src/amd/common/ac_llvm_util.c b/src/amd/common/ac_llvm_util.c
> index 770e3bd13c1..73181330b30 100644
> --- a/src/amd/common/ac_llvm_util.c
> +++ b/src/amd/common/ac_llvm_util.c
> @@ -504,3 +504,15 @@ ac_prepare_cube_coords(struct ac_llvm_context *ctx,
>  
>  	memcpy(coords_arg, coords, sizeof(coords));
>  }
> +
> +void
> +ac_dump_module(LLVMModuleRef module)
> +{
> +#if HAVE_LLVM >= 0x500
> +	char *str = LLVMPrintModuleToString(module);
> +	fprintf(stderr, "%s", str);
> +	LLVMDisposeMessage(str);
> +#else
> +	DumpModule(module);
> +#endif
> +}
> diff --git a/src/amd/common/ac_llvm_util.h b/src/amd/common/ac_llvm_util.h
> index 802c2662470..2d301c93575 100644
> --- a/src/amd/common/ac_llvm_util.h
> +++ b/src/amd/common/ac_llvm_util.h
> @@ -95,6 +95,9 @@ ac_prepare_cube_coords(struct ac_llvm_context *ctx,
>  		       LLVMValueRef *coords_arg,
>  		       LLVMValueRef *derivs_arg);
>  
> +void
> +ac_dump_module(LLVMModuleRef module);
> +
>  #ifdef __cplusplus
>  }
>  #endif
> diff --git a/src/amd/common/ac_nir_to_llvm.c b/src/amd/common/ac_nir_to_llvm.c
> index 26b87e8782b..5dc74e82da0 100644
> --- a/src/amd/common/ac_nir_to_llvm.c
> +++ b/src/amd/common/ac_nir_to_llvm.c
> @@ -4566,7 +4566,7 @@ static void ac_compile_llvm_module(LLVMTargetMachineRef tm,
>  				   bool dump_shader)
>  {
>  	if (dump_shader)
> -		LLVMDumpModule(llvm_module);
> +		ac_dump_module(llvm_module);
>  
>  	memset(binary, 0, sizeof(*binary));
>  	int v = ac_llvm_compile(llvm_module, binary, tm);
> diff --git a/src/gallium/drivers/llvmpipe/lp_jit.c b/src/gallium/drivers/llvmpipe/lp_jit.c
> index 21260369aca..b15de129557 100644
> --- a/src/gallium/drivers/llvmpipe/lp_jit.c
> +++ b/src/gallium/drivers/llvmpipe/lp_jit.c
> @@ -222,7 +222,13 @@ lp_jit_create_types(struct lp_fragment_shader_variant *lp)
>     }
>  
>     if (gallivm_debug & GALLIVM_DEBUG_IR) {
> -      LLVMDumpModule(gallivm->module);
> +#if HAVE_LLVM >= 0x500
> +		char *str = LLVMPrintModuleToString(gallivm->module);
> +		fprintf(stderr, "%s", str);
> +		LLVMDisposeMessage(str);
> +#else
> +		DumpModule(gallivm->module);
> +#endif
>     }
>  }
>  
> diff --git a/src/gallium/drivers/radeonsi/si_shader.c b/src/gallium/drivers/radeonsi/si_shader.c
> index 5ca974e48b4..cad7bf7a024 100644
> --- a/src/gallium/drivers/radeonsi/si_shader.c
> +++ b/src/gallium/drivers/radeonsi/si_shader.c
> @@ -6400,7 +6400,7 @@ int si_compile_llvm(struct si_screen *sscreen,
>  
>  		if (!(sscreen->b.debug_flags & (DBG_NO_IR | DBG_PREOPT_IR))) {
>  			fprintf(stderr, "%s LLVM IR:\n\n", name);
> -			LLVMDumpModule(mod);
> +			ac_dump_module(mod);
>  			fprintf(stderr, "\n");
>  		}
>  	}
> @@ -6599,7 +6599,7 @@ si_generate_gs_copy_shader(struct si_screen *sscreen,
>  	/* Dump LLVM IR before any optimization passes */
>  	if (sscreen->b.debug_flags & DBG_PREOPT_IR &&
>  	    r600_can_dump_shader(&sscreen->b, PIPE_SHADER_GEOMETRY))
> -		LLVMDumpModule(bld_base->base.gallivm->module);
> +		ac_dump_module(bld_base->base.gallivm->module);
>  
>  	si_llvm_finalize_module(&ctx,
>  		r600_extra_shader_checks(&sscreen->b, PIPE_SHADER_GEOMETRY));
> @@ -7603,7 +7603,7 @@ int si_compile_tgsi_shader(struct si_screen *sscreen,
>  	/* Dump LLVM IR before any optimization passes */
>  	if (sscreen->b.debug_flags & DBG_PREOPT_IR &&
>  	    r600_can_dump_shader(&sscreen->b, ctx.type))
> -		LLVMDumpModule(mod);
> +		ac_dump_module(mod);
>  
>  	si_llvm_finalize_module(&ctx,
>  				    r600_extra_shader_checks(&sscreen->b, ctx.type));
> 



More information about the mesa-dev mailing list