From 2b5edf96ff3c129f27ecb276593693085bc1cd9a Mon Sep 17 00:00:00 2001 From: =?utf8?q?Marek=20Ol=C5=A1=C3=A1k?= Date: Sun, 4 Dec 2022 06:07:32 -0500 Subject: [PATCH] ac/llvm: simplify how function attributes are set Reviewed-by: Pierre-Eric Pelloux-Prayer Part-of: --- src/amd/llvm/ac_llvm_build.c | 4 ++-- src/amd/llvm/ac_llvm_util.c | 19 ++----------------- src/amd/llvm/ac_llvm_util.h | 7 +------ src/gallium/drivers/radeonsi/si_shader_llvm.c | 4 ++-- 4 files changed, 7 insertions(+), 27 deletions(-) diff --git a/src/amd/llvm/ac_llvm_build.c b/src/amd/llvm/ac_llvm_build.c index 2adfec1..447f32e 100644 --- a/src/amd/llvm/ac_llvm_build.c +++ b/src/amd/llvm/ac_llvm_build.c @@ -4629,10 +4629,10 @@ struct ac_llvm_pointer ac_build_main(const struct ac_shader_args *args, struct a if (args->args[i].file != AC_ARG_SGPR) continue; - ac_add_function_attr(ctx->context, main_function, i + 1, AC_FUNC_ATTR_INREG); + ac_add_function_attr(ctx->context, main_function, i + 1, "inreg"); if (LLVMGetTypeKind(LLVMTypeOf(P)) == LLVMPointerTypeKind) { - ac_add_function_attr(ctx->context, main_function, i + 1, AC_FUNC_ATTR_NOALIAS); + ac_add_function_attr(ctx->context, main_function, i + 1, "noalias"); ac_add_attr_dereferenceable(P, UINT64_MAX); ac_add_attr_alignment(P, 4); } diff --git a/src/amd/llvm/ac_llvm_util.c b/src/amd/llvm/ac_llvm_util.c index 558d726..ff936af 100644 --- a/src/amd/llvm/ac_llvm_util.c +++ b/src/amd/llvm/ac_llvm_util.c @@ -248,31 +248,16 @@ static LLVMPassManagerRef ac_create_passmgr(LLVMTargetLibraryInfoRef target_libr return passmgr; } -static const char *attr_to_str(enum ac_func_attr attr) -{ - switch (attr) { - case AC_FUNC_ATTR_ALWAYSINLINE: - return "alwaysinline"; - case AC_FUNC_ATTR_INREG: - return "inreg"; - case AC_FUNC_ATTR_NOALIAS: - return "noalias"; - default: - fprintf(stderr, "Unhandled function attribute: %x\n", attr); - return 0; - } -} - LLVMAttributeRef ac_get_llvm_attribute(LLVMContextRef ctx, const char *str) { return LLVMCreateEnumAttribute(ctx, LLVMGetEnumAttributeKindForName(str, strlen(str)), 0); } void ac_add_function_attr(LLVMContextRef ctx, LLVMValueRef function, int attr_idx, - enum ac_func_attr attr) + const char *attr) { assert(LLVMIsAFunction(function)); - LLVMAddAttributeAtIndex(function, attr_idx, ac_get_llvm_attribute(ctx, attr_to_str(attr))); + LLVMAddAttributeAtIndex(function, attr_idx, ac_get_llvm_attribute(ctx, attr)); } void ac_dump_module(LLVMModuleRef module) diff --git a/src/amd/llvm/ac_llvm_util.h b/src/amd/llvm/ac_llvm_util.h index a3f1ced..efd9aa8 100644 --- a/src/amd/llvm/ac_llvm_util.h +++ b/src/amd/llvm/ac_llvm_util.h @@ -42,11 +42,6 @@ struct ac_llvm_context; enum ac_func_attr { - /* Function and parameter attributes. */ - AC_FUNC_ATTR_ALWAYSINLINE = (1 << 0), - AC_FUNC_ATTR_INREG = (1 << 1), - AC_FUNC_ATTR_NOALIAS = (1 << 2), - /* Call attributes. */ AC_FUNC_ATTR_READNONE = (1 << 3), AC_FUNC_ATTR_CONVERGENT = (1 << 4), @@ -91,7 +86,7 @@ void ac_add_attr_alignment(LLVMValueRef val, uint64_t bytes); bool ac_is_sgpr_param(LLVMValueRef param); LLVMAttributeRef ac_get_llvm_attribute(LLVMContextRef ctx, const char *str); void ac_add_function_attr(LLVMContextRef ctx, LLVMValueRef function, int attr_idx, - enum ac_func_attr attr); + const char *attr); void ac_dump_module(LLVMModuleRef module); LLVMModuleRef ac_create_module(LLVMTargetMachineRef tm, LLVMContextRef ctx); LLVMBuilderRef ac_create_builder(LLVMContextRef ctx, enum ac_float_mode float_mode); diff --git a/src/gallium/drivers/radeonsi/si_shader_llvm.c b/src/gallium/drivers/radeonsi/si_shader_llvm.c index 307662b..054f2c0 100644 --- a/src/gallium/drivers/radeonsi/si_shader_llvm.c +++ b/src/gallium/drivers/radeonsi/si_shader_llvm.c @@ -446,7 +446,7 @@ void si_build_wrapper_function(struct si_shader_context *ctx, struct ac_llvm_poi memset(ctx->args, 0, sizeof(*ctx->args)); for (unsigned i = 0; i < num_parts; ++i) { - ac_add_function_attr(ctx->ac.context, parts[i].value, -1, AC_FUNC_ATTR_ALWAYSINLINE); + ac_add_function_attr(ctx->ac.context, parts[i].value, -1, "alwaysinline"); LLVMSetLinkage(parts[i].value, LLVMPrivateLinkage); } @@ -601,7 +601,7 @@ void si_build_wrapper_function(struct si_shader_context *ctx, struct ac_llvm_poi is_sgpr = ac_is_sgpr_param(param); if (is_sgpr) { - ac_add_function_attr(ctx->ac.context, parts[part].value, param_idx + 1, AC_FUNC_ATTR_INREG); + ac_add_function_attr(ctx->ac.context, parts[part].value, param_idx + 1, "inreg"); } else if (out_idx < num_out_sgpr) { /* Skip returned SGPRs the current part doesn't * declare on the input. */ -- 2.7.4