[Mesa-dev] [PATCH 1/2] gallivm: Fix build after removal of deprecated attribute API v3
Nicolai Hähnle
nhaehnle at gmail.com
Wed Nov 9 16:05:18 UTC 2016
On 09.11.2016 16:22, Tom Stellard wrote:
> v2:
> Fix adding parameter attributes with LLVM < 4.0.
>
> v3:
> Fix typo.
> Fix parameter index.
> Add a gallivm enum for function attributes.
> ---
> src/gallium/auxiliary/draw/draw_llvm.c | 6 +-
> src/gallium/auxiliary/gallivm/lp_bld_intr.c | 70 ++++++++++++++++++++++-
> src/gallium/auxiliary/gallivm/lp_bld_intr.h | 22 ++++++-
> src/gallium/auxiliary/gallivm/lp_bld_sample_soa.c | 4 +-
> src/gallium/drivers/radeonsi/si_shader.c | 69 +++++++++++-----------
> src/gallium/drivers/radeonsi/si_shader_tgsi_alu.c | 24 ++++----
> 6 files changed, 143 insertions(+), 52 deletions(-)
>
[snip]
> diff --git a/src/gallium/auxiliary/gallivm/lp_bld_intr.h b/src/gallium/auxiliary/gallivm/lp_bld_intr.h
> index 7d80ac2..85a86c2 100644
> --- a/src/gallium/auxiliary/gallivm/lp_bld_intr.h
> +++ b/src/gallium/auxiliary/gallivm/lp_bld_intr.h
> @@ -46,6 +46,16 @@
> */
> #define LP_MAX_FUNC_ARGS 32
>
> +enum lp_func_attr {
> + LP_FUNC_ATTR_ALWAYSINLINE = (1 << 0),
> + LP_FUNC_ATTR_BYVAL = (1 << 1),
> + LP_FUNC_ATTR_INREG = (1 << 2),
> + LP_FUNC_ATTR_NOALIAS = (1 << 3),
> + LP_FUNC_ATTR_NOUNWIND = (1 << 4),
> + LP_FUNC_ATTR_READNONE = (1 << 5),
> + LP_FUNC_ATTR_READONLY = (1 << 6),
> + LP_FUNC_ATTR_LAST = (1 << 7)
> +};
>
> void
> lp_format_intrinsic(char *name,
> @@ -60,13 +70,23 @@ lp_declare_intrinsic(LLVMModuleRef module,
> LLVMTypeRef *arg_types,
> unsigned num_args);
>
> +void
> +lp_remove_attr(LLVMValueRef value,
> + const char *attr_name,
> + unsigned attr_len);
That looks like an unused left-over.
Apart from that, both patches are
Reviewed-by: Nicolai Hähnle <nicolai.haehnle at amd.com>
> +
> +void
> +lp_add_function_attr(LLVMValueRef function,
> + int attr_idx,
> + enum lp_func_attr attr);
> +
> LLVMValueRef
> lp_build_intrinsic(LLVMBuilderRef builder,
> const char *name,
> LLVMTypeRef ret_type,
> LLVMValueRef *args,
> unsigned num_args,
> - LLVMAttribute attr);
> + unsigned attr_mask);
>
>
> LLVMValueRef
> diff --git a/src/gallium/auxiliary/gallivm/lp_bld_sample_soa.c b/src/gallium/auxiliary/gallivm/lp_bld_sample_soa.c
> index 1477a72..939cd43 100644
> --- a/src/gallium/auxiliary/gallivm/lp_bld_sample_soa.c
> +++ b/src/gallium/auxiliary/gallivm/lp_bld_sample_soa.c
> @@ -60,6 +60,7 @@
> #include "lp_bld_struct.h"
> #include "lp_bld_quad.h"
> #include "lp_bld_pack.h"
> +#include "lp_bld_intr.h"
>
>
> /**
> @@ -3316,7 +3317,8 @@ lp_build_sample_soa_func(struct gallivm_state *gallivm,
>
> for (i = 0; i < num_param; ++i) {
> if(LLVMGetTypeKind(arg_types[i]) == LLVMPointerTypeKind) {
> - LLVMAddAttribute(LLVMGetParam(function, i), LLVMNoAliasAttribute);
> +
> + lp_add_function_attr(function, i + 1, LP_FUNC_ATTR_NOALIAS);
> }
> }
>
> diff --git a/src/gallium/drivers/radeonsi/si_shader.c b/src/gallium/drivers/radeonsi/si_shader.c
> index b170eb9..287b22f 100644
> --- a/src/gallium/drivers/radeonsi/si_shader.c
> +++ b/src/gallium/drivers/radeonsi/si_shader.c
> @@ -407,7 +407,7 @@ static void declare_input_vs(
> args[2] = buffer_index;
> input = lp_build_intrinsic(gallivm->builder,
> "llvm.SI.vs.load.input", ctx->v4f32, args, 3,
> - LLVMReadNoneAttribute);
> + LP_FUNC_ATTR_READNONE);
>
> /* Break up the vec4 into individual components */
> for (chan = 0; chan < 4; chan++) {
> @@ -841,7 +841,7 @@ static LLVMValueRef build_buffer_load(struct si_shader_context *ctx,
> type_names[func]);
>
> return lp_build_intrinsic(gallivm->builder, name, types[func], args,
> - ARRAY_SIZE(args), LLVMReadOnlyAttribute);
> + ARRAY_SIZE(args), LP_FUNC_ATTR_READONLY);
> } else {
> LLVMValueRef args[] = {
> LLVMBuildBitCast(gallivm->builder, rsrc, ctx->v16i8, ""),
> @@ -872,7 +872,7 @@ static LLVMValueRef build_buffer_load(struct si_shader_context *ctx,
> type_names[func], arg_type);
>
> return lp_build_intrinsic(gallivm->builder, name, types[func], args,
> - ARRAY_SIZE(args), LLVMReadOnlyAttribute);
> + ARRAY_SIZE(args), LP_FUNC_ATTR_READONLY);
> }
> }
>
> @@ -1159,14 +1159,14 @@ static LLVMValueRef fetch_input_gs(
> value = lp_build_intrinsic(gallivm->builder,
> "llvm.SI.buffer.load.dword.i32.i32",
> ctx->i32, args, 9,
> - LLVMReadOnlyAttribute);
> + LP_FUNC_ATTR_READONLY);
> if (tgsi_type_is_64bit(type)) {
> LLVMValueRef value2;
> args[2] = lp_build_const_int32(gallivm, (param * 4 + swizzle + 1) * 256);
> value2 = lp_build_intrinsic(gallivm->builder,
> "llvm.SI.buffer.load.dword.i32.i32",
> ctx->i32, args, 9,
> - LLVMReadOnlyAttribute);
> + LP_FUNC_ATTR_READONLY);
> return si_llvm_emit_fetch_64bit(bld_base, type,
> value, value2);
> }
> @@ -1279,12 +1279,12 @@ static void interp_fs_input(struct si_shader_context *ctx,
> args[1] = attr_number;
> front = lp_build_intrinsic(gallivm->builder, intr_name,
> ctx->f32, args, args[3] ? 4 : 3,
> - LLVMReadNoneAttribute);
> + LP_FUNC_ATTR_READNONE);
>
> args[1] = back_attr_number;
> back = lp_build_intrinsic(gallivm->builder, intr_name,
> ctx->f32, args, args[3] ? 4 : 3,
> - LLVMReadNoneAttribute);
> + LP_FUNC_ATTR_READNONE);
>
> result[chan] = LLVMBuildSelect(gallivm->builder,
> is_face_positive,
> @@ -1301,7 +1301,7 @@ static void interp_fs_input(struct si_shader_context *ctx,
> args[3] = interp_param;
> result[0] = lp_build_intrinsic(gallivm->builder, intr_name,
> ctx->f32, args, args[3] ? 4 : 3,
> - LLVMReadNoneAttribute);
> + LP_FUNC_ATTR_READNONE);
> result[1] =
> result[2] = lp_build_const_float(gallivm, 0.0f);
> result[3] = lp_build_const_float(gallivm, 1.0f);
> @@ -1316,7 +1316,7 @@ static void interp_fs_input(struct si_shader_context *ctx,
> args[3] = interp_param;
> result[chan] = lp_build_intrinsic(gallivm->builder, intr_name,
> ctx->f32, args, args[3] ? 4 : 3,
> - LLVMReadNoneAttribute);
> + LP_FUNC_ATTR_READNONE);
> }
> }
> }
> @@ -1404,18 +1404,18 @@ static LLVMValueRef get_thread_id(struct si_shader_context *ctx)
>
> if (HAVE_LLVM < 0x0308) {
> tid = lp_build_intrinsic(gallivm->builder, "llvm.SI.tid",
> - ctx->i32, NULL, 0, LLVMReadNoneAttribute);
> + ctx->i32, NULL, 0, LP_FUNC_ATTR_READNONE);
> } else {
> LLVMValueRef tid_args[2];
> tid_args[0] = lp_build_const_int32(gallivm, 0xffffffff);
> tid_args[1] = lp_build_const_int32(gallivm, 0);
> tid_args[1] = lp_build_intrinsic(gallivm->builder,
> "llvm.amdgcn.mbcnt.lo", ctx->i32,
> - tid_args, 2, LLVMReadNoneAttribute);
> + tid_args, 2, LP_FUNC_ATTR_READNONE);
>
> tid = lp_build_intrinsic(gallivm->builder,
> "llvm.amdgcn.mbcnt.hi", ctx->i32,
> - tid_args, 2, LLVMReadNoneAttribute);
> + tid_args, 2, LP_FUNC_ATTR_READNONE);
> }
> set_range_metadata(ctx, tid, 0, 64);
> return tid;
> @@ -1432,7 +1432,7 @@ static LLVMValueRef buffer_load_const(struct si_shader_context *ctx,
> LLVMValueRef args[2] = {resource, offset};
>
> return lp_build_intrinsic(builder, "llvm.SI.load.const", ctx->f32, args, 2,
> - LLVMReadNoneAttribute);
> + LP_FUNC_ATTR_READNONE);
> }
>
> static LLVMValueRef load_sample_position(struct si_shader_context *radeon_bld, LLVMValueRef sample_id)
> @@ -1670,7 +1670,7 @@ static void declare_system_value(
> value = lp_build_intrinsic(gallivm->builder,
> "llvm.amdgcn.ps.live",
> ctx->i1, NULL, 0,
> - LLVMReadNoneAttribute);
> + LP_FUNC_ATTR_READNONE);
> value = LLVMBuildNot(gallivm->builder, value, "");
> value = LLVMBuildSExt(gallivm->builder, value, ctx->i32, "");
> break;
> @@ -1883,7 +1883,7 @@ static void si_llvm_init_export_args(struct lp_build_tgsi_context *bld_base,
> packed = lp_build_intrinsic(base->gallivm->builder,
> "llvm.SI.packf16",
> ctx->i32, pack_args, 2,
> - LLVMReadNoneAttribute);
> + LP_FUNC_ATTR_READNONE);
> args[chan + 5] =
> LLVMBuildBitCast(base->gallivm->builder,
> packed, ctx->f32, "");
> @@ -2028,7 +2028,7 @@ static LLVMValueRef si_scale_alpha_by_sample_mask(struct lp_build_tgsi_context *
>
> coverage = lp_build_intrinsic(gallivm->builder, "llvm.ctpop.i32",
> ctx->i32,
> - &coverage, 1, LLVMReadNoneAttribute);
> + &coverage, 1, LP_FUNC_ATTR_READNONE);
>
> coverage = LLVMBuildUIToFP(gallivm->builder, coverage,
> ctx->f32, "");
> @@ -3469,7 +3469,7 @@ static void load_emit_buffer(struct si_shader_context *ctx,
> emit_data->output[emit_data->chan] = lp_build_intrinsic(
> builder, intrinsic_name, dst_type,
> emit_data->args, emit_data->arg_count,
> - LLVMReadOnlyAttribute);
> + LP_FUNC_ATTR_READONLY);
> }
>
> static LLVMValueRef get_memory_ptr(struct si_shader_context *ctx,
> @@ -3574,7 +3574,7 @@ static void load_emit(
> lp_build_intrinsic(
> builder, "llvm.amdgcn.buffer.load.format.v4f32", emit_data->dst_type,
> emit_data->args, emit_data->arg_count,
> - LLVMReadOnlyAttribute);
> + LP_FUNC_ATTR_READONLY);
> } else {
> get_image_intr_name("llvm.amdgcn.image.load",
> emit_data->dst_type, /* vdata */
> @@ -3586,7 +3586,7 @@ static void load_emit(
> lp_build_intrinsic(
> builder, intrinsic_name, emit_data->dst_type,
> emit_data->args, emit_data->arg_count,
> - LLVMReadOnlyAttribute);
> + LP_FUNC_ATTR_READONLY);
> }
> }
>
> @@ -4014,7 +4014,7 @@ static void resq_emit(
> out = lp_build_intrinsic(
> builder, "llvm.SI.getresinfo.i32", emit_data->dst_type,
> emit_data->args, emit_data->arg_count,
> - LLVMReadNoneAttribute);
> + LP_FUNC_ATTR_READNONE);
>
> /* Divide the number of layers by 6 to get the number of cubes. */
> if (inst->Memory.Texture == TGSI_TEXTURE_CUBE_ARRAY) {
> @@ -4248,7 +4248,7 @@ static void txq_emit(const struct lp_build_tgsi_action *action,
> emit_data->output[emit_data->chan] = lp_build_intrinsic(
> base->gallivm->builder, "llvm.SI.getresinfo.i32",
> emit_data->dst_type, emit_data->args, emit_data->arg_count,
> - LLVMReadNoneAttribute);
> + LP_FUNC_ATTR_READNONE);
>
> /* Divide the number of layers by 6 to get the number of cubes. */
> if (target == TGSI_TEXTURE_CUBE_ARRAY ||
> @@ -4666,7 +4666,7 @@ static void si_lower_gather4_integer(struct si_shader_context *ctx,
> emit_data->output[emit_data->chan] =
> lp_build_intrinsic(builder, intr_name, emit_data->dst_type,
> emit_data->args, emit_data->arg_count,
> - LLVMReadNoneAttribute);
> + LP_FUNC_ATTR_READNONE);
> }
>
> static void build_tex_intrinsic(const struct lp_build_tgsi_action *action,
> @@ -4690,7 +4690,7 @@ static void build_tex_intrinsic(const struct lp_build_tgsi_action *action,
> base->gallivm->builder,
> "llvm.SI.vs.load.input", emit_data->dst_type,
> emit_data->args, emit_data->arg_count,
> - LLVMReadNoneAttribute);
> + LP_FUNC_ATTR_READNONE);
> return;
> }
>
> @@ -4767,7 +4767,7 @@ static void build_tex_intrinsic(const struct lp_build_tgsi_action *action,
> emit_data->output[emit_data->chan] = lp_build_intrinsic(
> base->gallivm->builder, intr_name, emit_data->dst_type,
> emit_data->args, emit_data->arg_count,
> - LLVMReadNoneAttribute);
> + LP_FUNC_ATTR_READNONE);
> }
>
> static void si_llvm_emit_txqs(
> @@ -4865,13 +4865,13 @@ static void si_llvm_emit_ddxy(
> args[1] = val;
> tl = lp_build_intrinsic(gallivm->builder,
> "llvm.amdgcn.ds.bpermute", ctx->i32,
> - args, 2, LLVMReadNoneAttribute);
> + args, 2, LP_FUNC_ATTR_READNONE);
>
> args[0] = LLVMBuildMul(gallivm->builder, trbl_tid,
> lp_build_const_int32(gallivm, 4), "");
> trbl = lp_build_intrinsic(gallivm->builder,
> "llvm.amdgcn.ds.bpermute", ctx->i32,
> - args, 2, LLVMReadNoneAttribute);
> + args, 2, LP_FUNC_ATTR_READNONE);
> } else {
> LLVMValueRef store_ptr, load_ptr0, load_ptr1;
>
> @@ -5054,7 +5054,7 @@ static void build_interp_intrinsic(const struct lp_build_tgsi_action *action,
> emit_data->output[chan] =
> lp_build_intrinsic(gallivm->builder, intr_name,
> ctx->f32, args, args[3] ? 4 : 3,
> - LLVMReadNoneAttribute);
> + LP_FUNC_ATTR_READNONE);
> }
> }
>
> @@ -5223,10 +5223,10 @@ static void si_create_function(struct si_shader_context *ctx,
> * SGPR spilling significantly.
> */
> if (LLVMGetTypeKind(LLVMTypeOf(P)) == LLVMPointerTypeKind) {
> - LLVMAddAttribute(P, LLVMByValAttribute);
> + lp_add_function_attr(ctx->main_fn, i + 1, LP_FUNC_ATTR_BYVAL);
> lp_add_attr_dereferenceable(P, UINT64_MAX);
> } else
> - LLVMAddAttribute(P, LLVMInRegAttribute);
> + lp_add_function_attr(ctx->main_fn, i + 1, LP_FUNC_ATTR_INREG);
> }
>
> if (ctx->screen->b.debug_flags & DBG_UNSAFE_MATH) {
> @@ -6177,7 +6177,7 @@ si_generate_gs_copy_shader(struct si_screen *sscreen,
> lp_build_intrinsic(gallivm->builder,
> "llvm.SI.buffer.load.dword.i32.i32",
> ctx.i32, args, 9,
> - LLVMReadOnlyAttribute),
> + LP_FUNC_ATTR_READONLY),
> ctx.f32, "");
> }
> }
> @@ -6878,7 +6878,7 @@ static void si_build_wrapper_function(struct si_shader_context *ctx,
> unsigned gprs;
>
> for (unsigned i = 0; i < num_parts; ++i) {
> - LLVMAddFunctionAttr(parts[i], LLVMAlwaysInlineAttribute);
> + lp_add_function_attr(parts[i], -1, LP_FUNC_ATTR_ALWAYSINLINE);
> LLVMSetLinkage(parts[i], LLVMPrivateLinkage);
> }
>
> @@ -6989,8 +6989,13 @@ static void si_build_wrapper_function(struct si_shader_context *ctx,
> is_sgpr = ac_is_sgpr_param(param);
>
> if (is_sgpr) {
> +#if HAVE_LLVM < 0x0400
> LLVMRemoveAttribute(param, LLVMByValAttribute);
> - LLVMAddAttribute(param, LLVMInRegAttribute);
> +#else
> + unsigned kind_id = LLVMGetEnumAttributeKindForName("byval", 5);
> + LLVMRemoveEnumAttributeAtIndex(parts[part], param_idx + 1, kind_id);
> +#endif
> + lp_add_function_attr(parts[part], param_idx + 1, LP_FUNC_ATTR_INREG);
> }
>
> assert(out_idx + param_size <= (is_sgpr ? num_out_sgpr : num_out));
> diff --git a/src/gallium/drivers/radeonsi/si_shader_tgsi_alu.c b/src/gallium/drivers/radeonsi/si_shader_tgsi_alu.c
> index 18e905b..1966752 100644
> --- a/src/gallium/drivers/radeonsi/si_shader_tgsi_alu.c
> +++ b/src/gallium/drivers/radeonsi/si_shader_tgsi_alu.c
> @@ -399,7 +399,7 @@ static void emit_frac(const struct lp_build_tgsi_action *action,
>
> LLVMValueRef floor = lp_build_intrinsic(builder, intr, emit_data->dst_type,
> &emit_data->args[0], 1,
> - LLVMReadNoneAttribute);
> + LP_FUNC_ATTR_READNONE);
> emit_data->output[emit_data->chan] = LLVMBuildFSub(builder,
> emit_data->args[0], floor, "");
> }
> @@ -449,7 +449,7 @@ build_tgsi_intrinsic_nomem(const struct lp_build_tgsi_action *action,
> emit_data->output[emit_data->chan] =
> lp_build_intrinsic(base->gallivm->builder, action->intr_name,
> emit_data->dst_type, emit_data->args,
> - emit_data->arg_count, LLVMReadNoneAttribute);
> + emit_data->arg_count, LP_FUNC_ATTR_READNONE);
> }
>
> static void emit_bfi(const struct lp_build_tgsi_action *action,
> @@ -507,7 +507,7 @@ static void emit_bfe(const struct lp_build_tgsi_action *action,
>
> bfe_sm5 = lp_build_intrinsic(builder, action->intr_name,
> emit_data->dst_type, emit_data->args,
> - emit_data->arg_count, LLVMReadNoneAttribute);
> + emit_data->arg_count, LP_FUNC_ATTR_READNONE);
>
> /* Correct for GLSL semantics. */
> cond = LLVMBuildICmp(builder, LLVMIntUGE, emit_data->args[2],
> @@ -539,7 +539,7 @@ static void emit_lsb(const struct lp_build_tgsi_action *action,
> LLVMValueRef lsb =
> lp_build_intrinsic(gallivm->builder, "llvm.cttz.i32",
> emit_data->dst_type, args, ARRAY_SIZE(args),
> - LLVMReadNoneAttribute);
> + LP_FUNC_ATTR_READNONE);
>
> /* TODO: We need an intrinsic to skip this conditional. */
> /* Check for zero: */
> @@ -566,7 +566,7 @@ static void emit_umsb(const struct lp_build_tgsi_action *action,
> LLVMValueRef msb =
> lp_build_intrinsic(builder, "llvm.ctlz.i32",
> emit_data->dst_type, args, ARRAY_SIZE(args),
> - LLVMReadNoneAttribute);
> + LP_FUNC_ATTR_READNONE);
>
> /* The HW returns the last bit index from MSB, but TGSI wants
> * the index from LSB. Invert it by doing "31 - msb". */
> @@ -593,7 +593,7 @@ static void emit_imsb(const struct lp_build_tgsi_action *action,
> LLVMValueRef msb =
> lp_build_intrinsic(builder, "llvm.AMDGPU.flbit.i32",
> emit_data->dst_type, &arg, 1,
> - LLVMReadNoneAttribute);
> + LP_FUNC_ATTR_READNONE);
>
> /* The HW returns the last bit index from MSB, but TGSI wants
> * the index from LSB. Invert it by doing "31 - msb". */
> @@ -917,13 +917,13 @@ static LLVMValueRef build_cube_intrinsic(struct gallivm_state *gallivm,
> LLVMValueRef out[4];
>
> out[0] = lp_build_intrinsic(gallivm->builder, "llvm.amdgcn.cubetc",
> - f32, in, 3, LLVMReadNoneAttribute);
> + f32, in, 3, LP_FUNC_ATTR_READNONE);
> out[1] = lp_build_intrinsic(gallivm->builder, "llvm.amdgcn.cubesc",
> - f32, in, 3, LLVMReadNoneAttribute);
> + f32, in, 3, LP_FUNC_ATTR_READNONE);
> out[2] = lp_build_intrinsic(gallivm->builder, "llvm.amdgcn.cubema",
> - f32, in, 3, LLVMReadNoneAttribute);
> + f32, in, 3, LP_FUNC_ATTR_READNONE);
> out[3] = lp_build_intrinsic(gallivm->builder, "llvm.amdgcn.cubeid",
> - f32, in, 3, LLVMReadNoneAttribute);
> + f32, in, 3, LP_FUNC_ATTR_READNONE);
>
> return lp_build_gather_values(gallivm, out, 4);
> } else {
> @@ -937,7 +937,7 @@ static LLVMValueRef build_cube_intrinsic(struct gallivm_state *gallivm,
>
> return lp_build_intrinsic(gallivm->builder, "llvm.AMDGPU.cube",
> LLVMTypeOf(vec), &vec, 1,
> - LLVMReadNoneAttribute);
> + LP_FUNC_ATTR_READNONE);
> }
> }
>
> @@ -959,7 +959,7 @@ static void si_llvm_cube_to_2d_coords(struct lp_build_tgsi_context *bld_base,
> lp_build_const_int32(gallivm, i), "");
>
> coords[2] = lp_build_intrinsic(builder, "llvm.fabs.f32",
> - type, &coords[2], 1, LLVMReadNoneAttribute);
> + type, &coords[2], 1, LP_FUNC_ATTR_READNONE);
> coords[2] = lp_build_emit_llvm_unary(bld_base, TGSI_OPCODE_RCP, coords[2]);
>
> mad_args[1] = coords[2];
>
More information about the mesa-dev
mailing list