[Mesa-dev] [PATCH 4/8] radeonsi: set the calling convention for inlined function calls
Bas Nieuwenhuizen
bas at basnieuwenhuizen.nl
Fri Jun 21 12:29:33 UTC 2019
r-b
On Thu, Jun 20, 2019 at 6:19 AM Marek Olšák <maraeo at gmail.com> wrote:
>
> From: Marek Olšák <marek.olsak at amd.com>
>
> otherwise the behavior is undefined
> ---
> src/amd/common/ac_llvm_build.c | 8 ++++++++
> src/amd/common/ac_llvm_build.h | 3 +++
> src/gallium/drivers/radeonsi/si_compute_prim_discard.c | 2 +-
> src/gallium/drivers/radeonsi/si_shader.c | 2 +-
> 4 files changed, 13 insertions(+), 2 deletions(-)
>
> diff --git a/src/amd/common/ac_llvm_build.c b/src/amd/common/ac_llvm_build.c
> index 1e6247ad72e..cdd4c36f5da 100644
> --- a/src/amd/common/ac_llvm_build.c
> +++ b/src/amd/common/ac_llvm_build.c
> @@ -4427,10 +4427,18 @@ ac_build_ddxy_interp(struct ac_llvm_context *ctx, LLVMValueRef interp_ij)
>
> LLVMValueRef
> ac_build_load_helper_invocation(struct ac_llvm_context *ctx)
> {
> LLVMValueRef result = ac_build_intrinsic(ctx, "llvm.amdgcn.ps.live",
> ctx->i1, NULL, 0,
> AC_FUNC_ATTR_READNONE);
> result = LLVMBuildNot(ctx->builder, result, "");
> return LLVMBuildSExt(ctx->builder, result, ctx->i32, "");
> }
> +
> +LLVMValueRef ac_build_call(struct ac_llvm_context *ctx, LLVMValueRef func,
> + LLVMValueRef *args, unsigned num_args)
> +{
> + LLVMValueRef ret = LLVMBuildCall(ctx->builder, func, args, num_args, "");
> + LLVMSetInstructionCallConv(ret, LLVMGetFunctionCallConv(func));
> + return ret;
> +}
> diff --git a/src/amd/common/ac_llvm_build.h b/src/amd/common/ac_llvm_build.h
> index a1654d2b2c4..1928843c78c 100644
> --- a/src/amd/common/ac_llvm_build.h
> +++ b/src/amd/common/ac_llvm_build.h
> @@ -713,20 +713,23 @@ ac_build_frexp_exp(struct ac_llvm_context *ctx, LLVMValueRef src0,
> LLVMValueRef
> ac_build_frexp_mant(struct ac_llvm_context *ctx, LLVMValueRef src0,
> unsigned bitsize);
>
> LLVMValueRef
> ac_build_ddxy_interp(struct ac_llvm_context *ctx, LLVMValueRef interp_ij);
>
> LLVMValueRef
> ac_build_load_helper_invocation(struct ac_llvm_context *ctx);
>
> +LLVMValueRef ac_build_call(struct ac_llvm_context *ctx, LLVMValueRef func,
> + LLVMValueRef *args, unsigned num_args);
> +
> LLVMValueRef ac_build_atomic_rmw(struct ac_llvm_context *ctx, LLVMAtomicRMWBinOp op,
> LLVMValueRef ptr, LLVMValueRef val,
> const char *sync_scope);
>
> LLVMValueRef ac_build_atomic_cmp_xchg(struct ac_llvm_context *ctx, LLVMValueRef ptr,
> LLVMValueRef cmp, LLVMValueRef val,
> const char *sync_scope);
>
> #ifdef __cplusplus
> }
> diff --git a/src/gallium/drivers/radeonsi/si_compute_prim_discard.c b/src/gallium/drivers/radeonsi/si_compute_prim_discard.c
> index 0f2934243a1..28da7b92250 100644
> --- a/src/gallium/drivers/radeonsi/si_compute_prim_discard.c
> +++ b/src/gallium/drivers/radeonsi/si_compute_prim_discard.c
> @@ -660,21 +660,21 @@ void si_build_prim_discard_compute_shader(struct si_shader_context *ctx)
> index[1] = LLVMBuildSelect(builder, prim_is_odd, index0, index1, "");
> }
> }
>
> /* Execute the vertex shader for each vertex to get vertex positions. */
> LLVMValueRef pos[3][4];
> for (unsigned i = 0; i < vertices_per_prim; i++) {
> vs_params[param_vertex_id] = index[i];
> vs_params[param_instance_id] = instance_id;
>
> - LLVMValueRef ret = LLVMBuildCall(builder, vs, vs_params, num_vs_params, "");
> + LLVMValueRef ret = ac_build_call(&ctx->ac, vs, vs_params, num_vs_params);
> for (unsigned chan = 0; chan < 4; chan++)
> pos[i][chan] = LLVMBuildExtractValue(builder, ret, chan, "");
> }
>
> /* Divide XYZ by W. */
> for (unsigned i = 0; i < vertices_per_prim; i++) {
> for (unsigned chan = 0; chan < 3; chan++)
> pos[i][chan] = ac_build_fdiv(&ctx->ac, pos[i][chan], pos[i][3]);
> }
>
> diff --git a/src/gallium/drivers/radeonsi/si_shader.c b/src/gallium/drivers/radeonsi/si_shader.c
> index eb75e2a77a4..54b29d0ae01 100644
> --- a/src/gallium/drivers/radeonsi/si_shader.c
> +++ b/src/gallium/drivers/radeonsi/si_shader.c
> @@ -6584,21 +6584,21 @@ static void si_build_wrapper_function(struct si_shader_context *ctx,
> }
> } else {
> arg = LLVMBuildBitCast(builder, arg, param_type, "");
> }
> }
>
> in[param_idx] = arg;
> out_idx += param_size;
> }
>
> - ret = LLVMBuildCall(builder, parts[part], in, num_params, "");
> + ret = ac_build_call(&ctx->ac, parts[part], in, num_params);
>
> if (is_merged_shader(ctx) &&
> part + 1 == next_shader_first_part) {
> lp_build_endif(&if_state);
>
> /* The second half of the merged shader should use
> * the inputs from the toplevel (wrapper) function,
> * not the return value from the last call.
> *
> * That's because the last call was executed condi-
> --
> 2.17.1
>
> _______________________________________________
> mesa-dev mailing list
> mesa-dev at lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/mesa-dev
More information about the mesa-dev
mailing list