ac: unify build_type_name_for_intr functions
authorMarek Olšák <marek.olsak@amd.com>
Thu, 23 Feb 2017 21:58:49 +0000 (22:58 +0100)
committerMarek Olšák <marek.olsak@amd.com>
Fri, 3 Mar 2017 14:29:30 +0000 (15:29 +0100)
Reviewed-by: Dave Airlie <airlied@redhat.com>
src/amd/common/ac_llvm_build.c
src/amd/common/ac_llvm_build.h
src/amd/common/ac_nir_to_llvm.c
src/gallium/drivers/radeonsi/si_shader.c

index a0b74a5de45b710894bcd189716d8bea87f1ea08..114cb0c1ffffe509c4f529b8d840137da4abd7cd 100644 (file)
@@ -114,6 +114,43 @@ ac_emit_llvm_intrinsic(struct ac_llvm_context *ctx, const char *name,
        return call;
 }
 
+/**
+ * Given the i32 or vNi32 \p type, generate the textual name (e.g. for use with
+ * intrinsic names).
+ */
+void ac_build_type_name_for_intr(LLVMTypeRef type, char *buf, unsigned bufsize)
+{
+       LLVMTypeRef elem_type = type;
+
+       assert(bufsize >= 8);
+
+       if (LLVMGetTypeKind(type) == LLVMVectorTypeKind) {
+               int ret = snprintf(buf, bufsize, "v%u",
+                                       LLVMGetVectorSize(type));
+               if (ret < 0) {
+                       char *type_name = LLVMPrintTypeToString(type);
+                       fprintf(stderr, "Error building type name for: %s\n",
+                               type_name);
+                       return;
+               }
+               elem_type = LLVMGetElementType(type);
+               buf += ret;
+               bufsize -= ret;
+       }
+       switch (LLVMGetTypeKind(elem_type)) {
+       default: break;
+       case LLVMIntegerTypeKind:
+               snprintf(buf, bufsize, "i%d", LLVMGetIntTypeWidth(elem_type));
+               break;
+       case LLVMFloatTypeKind:
+               snprintf(buf, bufsize, "f32");
+               break;
+       case LLVMDoubleTypeKind:
+               snprintf(buf, bufsize, "f64");
+               break;
+       }
+}
+
 LLVMValueRef
 ac_build_gather_values_extended(struct ac_llvm_context *ctx,
                                LLVMValueRef *values,
index 57bfdbdecd652f765bbb8f37eb6d0aea5b419c02..46da79e4c17c71834d34cc25fe4dcccbc32c9f11 100644 (file)
@@ -62,6 +62,8 @@ ac_emit_llvm_intrinsic(struct ac_llvm_context *ctx, const char *name,
                       LLVMTypeRef return_type, LLVMValueRef *params,
                       unsigned param_count, unsigned attrib_mask);
 
+void ac_build_type_name_for_intr(LLVMTypeRef type, char *buf, unsigned bufsize);
+
 LLVMValueRef
 ac_build_gather_values_extended(struct ac_llvm_context *ctx,
                                LLVMValueRef *values,
index 2228dd81599d6edeaa76fed4d563bfa52d45b6e0..47b95e40b2982d7f268e7149ae8255aefd4b50bf 100644 (file)
@@ -2396,41 +2396,6 @@ static int image_type_to_components_count(enum glsl_sampler_dim dim, bool array)
 }
 
 
-static void build_type_name_for_intr(
-        LLVMTypeRef type,
-        char *buf, unsigned bufsize)
-{
-        LLVMTypeRef elem_type = type;
-
-        assert(bufsize >= 8);
-
-        if (LLVMGetTypeKind(type) == LLVMVectorTypeKind) {
-                int ret = snprintf(buf, bufsize, "v%u",
-                                        LLVMGetVectorSize(type));
-                if (ret < 0) {
-                        char *type_name = LLVMPrintTypeToString(type);
-                        fprintf(stderr, "Error building type name for: %s\n",
-                                type_name);
-                        return;
-                }
-                elem_type = LLVMGetElementType(type);
-                buf += ret;
-                bufsize -= ret;
-        }
-        switch (LLVMGetTypeKind(elem_type)) {
-        default: break;
-        case LLVMIntegerTypeKind:
-                snprintf(buf, bufsize, "i%d", LLVMGetIntTypeWidth(elem_type));
-                break;
-        case LLVMFloatTypeKind:
-                snprintf(buf, bufsize, "f32");
-                break;
-        case LLVMDoubleTypeKind:
-                snprintf(buf, bufsize, "f64");
-                break;
-        }
-}
-
 static void get_image_intr_name(const char *base_name,
                                 LLVMTypeRef data_type,
                                 LLVMTypeRef coords_type,
@@ -2439,7 +2404,7 @@ static void get_image_intr_name(const char *base_name,
 {
         char coords_type_name[8];
 
-        build_type_name_for_intr(coords_type, coords_type_name,
+        ac_build_type_name_for_intr(coords_type, coords_type_name,
                             sizeof(coords_type_name));
 
         if (HAVE_LLVM <= 0x0309) {
@@ -2448,9 +2413,9 @@ static void get_image_intr_name(const char *base_name,
                 char data_type_name[8];
                 char rsrc_type_name[8];
 
-                build_type_name_for_intr(data_type, data_type_name,
+                ac_build_type_name_for_intr(data_type, data_type_name,
                                         sizeof(data_type_name));
-                build_type_name_for_intr(rsrc_type, rsrc_type_name,
+                ac_build_type_name_for_intr(rsrc_type, rsrc_type_name,
                                         sizeof(rsrc_type_name));
                 snprintf(out_name, out_len, "%s.%s.%s.%s", base_name,
                          data_type_name, coords_type_name, rsrc_type_name);
index 5fe3eef38fcd75af7b57f71fd15fcee8fcfe3415..460660cb32eed25e1941c9a6392d8f6017b14719 100644 (file)
@@ -3137,45 +3137,6 @@ static LLVMValueRef get_buffer_size(
        return size;
 }
 
-/**
- * Given the i32 or vNi32 \p type, generate the textual name (e.g. for use with
- * intrinsic names).
- */
-static void build_type_name_for_intr(
-       LLVMTypeRef type,
-       char *buf, unsigned bufsize)
-{
-       LLVMTypeRef elem_type = type;
-
-       assert(bufsize >= 8);
-
-       if (LLVMGetTypeKind(type) == LLVMVectorTypeKind) {
-               int ret = snprintf(buf, bufsize, "v%u",
-                                       LLVMGetVectorSize(type));
-               if (ret < 0) {
-                       char *type_name = LLVMPrintTypeToString(type);
-                       fprintf(stderr, "Error building type name for: %s\n",
-                               type_name);
-                       return;
-               }
-               elem_type = LLVMGetElementType(type);
-               buf += ret;
-               bufsize -= ret;
-       }
-       switch (LLVMGetTypeKind(elem_type)) {
-       default: break;
-       case LLVMIntegerTypeKind:
-               snprintf(buf, bufsize, "i%d", LLVMGetIntTypeWidth(elem_type));
-               break;
-       case LLVMFloatTypeKind:
-               snprintf(buf, bufsize, "f32");
-               break;
-       case LLVMDoubleTypeKind:
-               snprintf(buf, bufsize, "f64");
-               break;
-       }
-}
-
 static void build_tex_intrinsic(const struct lp_build_tgsi_action *action,
                                struct lp_build_tgsi_context *bld_base,
                                struct lp_build_emit_data *emit_data);
@@ -3603,7 +3564,7 @@ static void get_image_intr_name(const char *base_name,
 {
        char coords_type_name[8];
 
-       build_type_name_for_intr(coords_type, coords_type_name,
+       ac_build_type_name_for_intr(coords_type, coords_type_name,
                            sizeof(coords_type_name));
 
        if (HAVE_LLVM <= 0x0309) {
@@ -3612,9 +3573,9 @@ static void get_image_intr_name(const char *base_name,
                char data_type_name[8];
                char rsrc_type_name[8];
 
-               build_type_name_for_intr(data_type, data_type_name,
+               ac_build_type_name_for_intr(data_type, data_type_name,
                                        sizeof(data_type_name));
-               build_type_name_for_intr(rsrc_type, rsrc_type_name,
+               ac_build_type_name_for_intr(rsrc_type, rsrc_type_name,
                                        sizeof(rsrc_type_name));
                snprintf(out_name, out_len, "%s.%s.%s.%s", base_name,
                         data_type_name, coords_type_name, rsrc_type_name);
@@ -4030,7 +3991,7 @@ static void atomic_emit(
                else
                        coords = emit_data->args[1];
 
-               build_type_name_for_intr(LLVMTypeOf(coords), coords_type, sizeof(coords_type));
+               ac_build_type_name_for_intr(LLVMTypeOf(coords), coords_type, sizeof(coords_type));
                snprintf(intrinsic_name, sizeof(intrinsic_name),
                         "llvm.amdgcn.image.atomic.%s.%s",
                         action->intr_name, coords_type);
@@ -4814,7 +4775,7 @@ static void build_tex_intrinsic(const struct lp_build_tgsi_action *action,
        }
 
        /* Add the type and suffixes .c, .o if needed. */
-       build_type_name_for_intr(LLVMTypeOf(emit_data->args[0]), type, sizeof(type));
+       ac_build_type_name_for_intr(LLVMTypeOf(emit_data->args[0]), type, sizeof(type));
        sprintf(intr_name, "%s%s%s%s.%s",
                name, is_shadow ? ".c" : "", infix,
                has_offset ? ".o" : "", type);