[Mesa-dev] [PATCH 1/2] gallivm: add no-signed-zeros-fp-math option to lp_create_builder
Brian Paul
brianp at vmware.com
Wed Feb 1 20:41:20 UTC 2017
On 01/30/2017 11:44 AM, Marek Olšák wrote:
> From: Marek Olšák <marek.olsak at amd.com>
>
> ---
> src/gallium/auxiliary/gallivm/lp_bld_misc.cpp | 15 ++++++++++++---
> src/gallium/auxiliary/gallivm/lp_bld_misc.h | 8 +++++++-
> src/gallium/drivers/radeonsi/si_shader_tgsi_setup.c | 6 +++++-
> 3 files changed, 24 insertions(+), 5 deletions(-)
>
> diff --git a/src/gallium/auxiliary/gallivm/lp_bld_misc.cpp b/src/gallium/auxiliary/gallivm/lp_bld_misc.cpp
> index 498bbd7..3063a3c 100644
> --- a/src/gallium/auxiliary/gallivm/lp_bld_misc.cpp
> +++ b/src/gallium/auxiliary/gallivm/lp_bld_misc.cpp
> @@ -735,24 +735,33 @@ extern "C" bool
> lp_is_function(LLVMValueRef v)
> {
> #if HAVE_LLVM >= 0x0309
> return LLVMGetValueKind(v) == LLVMFunctionValueKind;
> #else
> return llvm::isa<llvm::Function>(llvm::unwrap(v));
> #endif
> }
>
> extern "C" LLVMBuilderRef
> -lp_create_builder(LLVMContextRef ctx, bool unsafe_fpmath)
> +lp_create_builder(LLVMContextRef ctx, enum lp_builder_type type)
> {
> LLVMBuilderRef builder = LLVMCreateBuilderInContext(ctx);
>
> #if HAVE_LLVM >= 0x0308
> - if (unsafe_fpmath) {
> - llvm::FastMathFlags flags;
> + llvm::FastMathFlags flags;
> +
> + switch (type) {
> + case LP_BUILDER_DEFAULT:
> + break;
> + case LP_BUILDER_NO_SIGNED_ZEROS_FP_MATH:
> + flags.setNoSignedZeros();
> + llvm::unwrap(builder)->setFastMathFlags(flags);
> + break;
> + case LP_BUILDER_UNSAFE_FP_MATH:
> flags.setUnsafeAlgebra();
> llvm::unwrap(builder)->setFastMathFlags(flags);
> + break;
> }
> #endif
>
> return builder;
> }
> diff --git a/src/gallium/auxiliary/gallivm/lp_bld_misc.h b/src/gallium/auxiliary/gallivm/lp_bld_misc.h
> index c499a6f..736a916 100644
> --- a/src/gallium/auxiliary/gallivm/lp_bld_misc.h
> +++ b/src/gallium/auxiliary/gallivm/lp_bld_misc.h
> @@ -75,19 +75,25 @@ lp_free_memory_manager(LLVMMCJITMemoryManagerRef memorymgr);
>
> extern void
> lp_add_attr_dereferenceable(LLVMValueRef val, uint64_t bytes);
>
> extern LLVMValueRef
> lp_get_called_value(LLVMValueRef call);
>
> extern bool
> lp_is_function(LLVMValueRef v);
>
> +enum lp_builder_type {
> + LP_BUILDER_DEFAULT,
> + LP_BUILDER_NO_SIGNED_ZEROS_FP_MATH,
> + LP_BUILDER_UNSAFE_FP_MATH,
> +};
lp_builder_type seems a little generic. How about something like
lp_float_behavior?
-Brian
> +
> extern LLVMBuilderRef
> -lp_create_builder(LLVMContextRef ctx, bool unsafe_fpmath);
> +lp_create_builder(LLVMContextRef ctx, enum lp_builder_type type);
>
> #ifdef __cplusplus
> }
> #endif
>
>
> #endif /* !LP_BLD_MISC_H */
> diff --git a/src/gallium/drivers/radeonsi/si_shader_tgsi_setup.c b/src/gallium/drivers/radeonsi/si_shader_tgsi_setup.c
> index 4f355e5..68153af 100644
> --- a/src/gallium/drivers/radeonsi/si_shader_tgsi_setup.c
> +++ b/src/gallium/drivers/radeonsi/si_shader_tgsi_setup.c
> @@ -1267,22 +1267,26 @@ void si_llvm_context_init(struct si_shader_context *ctx,
> ctx->screen = sscreen;
> ctx->tm = tm;
> ctx->type = info ? info->processor : -1;
>
> ctx->gallivm.context = LLVMContextCreate();
> ctx->gallivm.module = LLVMModuleCreateWithNameInContext("tgsi",
> ctx->gallivm.context);
> LLVMSetTarget(ctx->gallivm.module, "amdgcn--");
>
> bool unsafe_fpmath = (sscreen->b.debug_flags & DBG_UNSAFE_MATH) != 0;
> + enum lp_builder_type builder_type =
> + unsafe_fpmath ? LP_BUILDER_UNSAFE_FP_MATH :
> + LP_BUILDER_DEFAULT;
> +
> ctx->gallivm.builder = lp_create_builder(ctx->gallivm.context,
> - unsafe_fpmath);
> + builder_type);
>
> ac_llvm_context_init(&ctx->ac, ctx->gallivm.context);
> ctx->ac.module = ctx->gallivm.module;
> ctx->ac.builder = ctx->gallivm.builder;
>
> struct lp_build_tgsi_context *bld_base = &ctx->bld_base;
>
> bld_base->info = info;
>
> if (info && info->array_max[TGSI_FILE_TEMPORARY] > 0) {
>
More information about the mesa-dev
mailing list