ac: add support for more types with struct/raw LLVM intrinsics
authorSamuel Pitoiset <samuel.pitoiset@gmail.com>
Mon, 15 Apr 2019 13:23:58 +0000 (15:23 +0200)
committerSamuel Pitoiset <samuel.pitoiset@gmail.com>
Wed, 17 Apr 2019 20:10:25 +0000 (22:10 +0200)
LLVM 9+ now supports 8-bit and 16-bit types.

Signed-off-by: Samuel Pitoiset <samuel.pitoiset@gmail.com>
Reviewed-by: Bas Nieuwenhuizen <bas@basnieuwenhuizen.nl>
Reviewed-by: Marek Olšák <marek.olsak@amd.com>
src/amd/common/ac_llvm_build.c

index 8f40ddda0b578ce34852b5c3855eed8e13730dc7..c7100e52295f0b6faf360683672fc441c86f9b08 100644 (file)
@@ -1135,6 +1135,7 @@ ac_build_llvm8_buffer_store_common(struct ac_llvm_context *ctx,
                                   LLVMValueRef voffset,
                                   LLVMValueRef soffset,
                                   unsigned num_channels,
+                                  LLVMTypeRef return_channel_type,
                                   bool glc,
                                   bool slc,
                                   bool writeonly_memory,
@@ -1150,18 +1151,19 @@ ac_build_llvm8_buffer_store_common(struct ac_llvm_context *ctx,
        args[idx++] = voffset ? voffset : ctx->i32_0;
        args[idx++] = soffset ? soffset : ctx->i32_0;
        args[idx++] = LLVMConstInt(ctx->i32, (glc ? 1 : 0) + (slc ? 2 : 0), 0);
-       unsigned func = CLAMP(num_channels, 1, 3) - 1;
-
-       const char *type_names[] = {"f32", "v2f32", "v4f32"};
+       unsigned func = num_channels == 3 ? 4 : num_channels;
        const char *indexing_kind = structurized ? "struct" : "raw";
-       char name[256];
+       char name[256], type_name[8];
+
+       LLVMTypeRef type = func > 1 ? LLVMVectorType(return_channel_type, func) : return_channel_type;
+       ac_build_type_name_for_intr(type, type_name, sizeof(type_name));
 
        if (use_format) {
                snprintf(name, sizeof(name), "llvm.amdgcn.%s.buffer.store.format.%s",
-                        indexing_kind, type_names[func]);
+                        indexing_kind, type_name);
        } else {
                snprintf(name, sizeof(name), "llvm.amdgcn.%s.buffer.store.%s",
-                        indexing_kind, type_names[func]);
+                        indexing_kind, type_name);
        }
 
        ac_build_intrinsic(ctx, name, ctx->voidt, args, idx,
@@ -1181,8 +1183,8 @@ ac_build_buffer_store_format(struct ac_llvm_context *ctx,
        if (HAVE_LLVM >= 0x800) {
                ac_build_llvm8_buffer_store_common(ctx, rsrc, data, vindex,
                                                   voffset, NULL, num_channels,
-                                                  glc, false, writeonly_memory,
-                                                  true, true);
+                                                  ctx->f32, glc, false,
+                                                  writeonly_memory, true, true);
        } else {
                ac_build_buffer_store_common(ctx, rsrc, data, vindex, voffset,
                                             num_channels, glc, false,
@@ -1245,6 +1247,7 @@ ac_build_buffer_store_dword(struct ac_llvm_context *ctx,
                                                           ctx->i32_0,
                                                           voffset, offset,
                                                           num_channels,
+                                                          ctx->f32,
                                                           glc, slc,
                                                           writeonly_memory,
                                                           false, false);
@@ -1320,6 +1323,7 @@ ac_build_llvm8_buffer_load_common(struct ac_llvm_context *ctx,
                                  LLVMValueRef voffset,
                                  LLVMValueRef soffset,
                                  unsigned num_channels,
+                                 LLVMTypeRef channel_type,
                                  bool glc,
                                  bool slc,
                                  bool can_speculate,
@@ -1334,23 +1338,22 @@ ac_build_llvm8_buffer_load_common(struct ac_llvm_context *ctx,
        args[idx++] = voffset ? voffset : ctx->i32_0;
        args[idx++] = soffset ? soffset : ctx->i32_0;
        args[idx++] = LLVMConstInt(ctx->i32, (glc ? 1 : 0) + (slc ? 2 : 0), 0);
-       unsigned func = CLAMP(num_channels, 1, 3) - 1;
-
-       LLVMTypeRef types[] = {ctx->f32, ctx->v2f32, ctx->v4f32};
-       const char *type_names[] = {"f32", "v2f32", "v4f32"};
+       unsigned func = num_channels == 3 ? 4 : num_channels;
        const char *indexing_kind = structurized ? "struct" : "raw";
-       char name[256];
+       char name[256], type_name[8];
+
+       LLVMTypeRef type = func > 1 ? LLVMVectorType(channel_type, func) : channel_type;
+       ac_build_type_name_for_intr(type, type_name, sizeof(type_name));
 
        if (use_format) {
                snprintf(name, sizeof(name), "llvm.amdgcn.%s.buffer.load.format.%s",
-                        indexing_kind, type_names[func]);
+                        indexing_kind, type_name);
        } else {
                snprintf(name, sizeof(name), "llvm.amdgcn.%s.buffer.load.%s",
-                        indexing_kind, type_names[func]);
+                        indexing_kind, type_name);
        }
 
-       return ac_build_intrinsic(ctx, name, types[func], args,
-                                 idx,
+       return ac_build_intrinsic(ctx, name, type, args, idx,
                                  ac_get_load_intr_attribs(can_speculate));
 }
 
@@ -1409,7 +1412,8 @@ ac_build_buffer_load(struct ac_llvm_context *ctx,
        if (HAVE_LLVM >= 0x0800) {
                return ac_build_llvm8_buffer_load_common(ctx, rsrc, vindex,
                                                         offset, ctx->i32_0,
-                                                        num_channels, glc, slc,
+                                                        num_channels, ctx->f32,
+                                                        glc, slc,
                                                         can_speculate, false,
                                                         false);
        }
@@ -1429,7 +1433,8 @@ LLVMValueRef ac_build_buffer_load_format(struct ac_llvm_context *ctx,
 {
        if (HAVE_LLVM >= 0x800) {
                return ac_build_llvm8_buffer_load_common(ctx, rsrc, vindex, voffset, ctx->i32_0,
-                                                        num_channels, glc, false,
+                                                        num_channels, ctx->f32,
+                                                        glc, false,
                                                         can_speculate, true, true);
        }
        return ac_build_buffer_load_common(ctx, rsrc, vindex, voffset,
@@ -1447,7 +1452,8 @@ LLVMValueRef ac_build_buffer_load_format_gfx9_safe(struct ac_llvm_context *ctx,
 {
        if (HAVE_LLVM >= 0x800) {
                return ac_build_llvm8_buffer_load_common(ctx, rsrc, vindex, voffset, ctx->i32_0,
-                                                        num_channels, glc, false,
+                                                        num_channels, ctx->f32,
+                                                        glc, false,
                                                         can_speculate, true, true);
        }