ac/llvm: simplify how function attributes are set
authorMarek Olšák <marek.olsak@amd.com>
Sun, 4 Dec 2022 11:07:32 +0000 (06:07 -0500)
committerMarge Bot <emma+marge@anholt.net>
Tue, 6 Dec 2022 13:27:16 +0000 (13:27 +0000)
Reviewed-by: Pierre-Eric Pelloux-Prayer <pierre-eric.pelloux-prayer@amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/20146>

src/amd/llvm/ac_llvm_build.c
src/amd/llvm/ac_llvm_util.c
src/amd/llvm/ac_llvm_util.h
src/gallium/drivers/radeonsi/si_shader_llvm.c

index 2adfec1..447f32e 100644 (file)
@@ -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);
       }
index 558d726..ff936af 100644 (file)
@@ -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)
index a3f1ced..efd9aa8 100644 (file)
@@ -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);
index 307662b..054f2c0 100644 (file)
@@ -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. */