ac: rework typed buffers loads for LLVM 7
authorSamuel Pitoiset <samuel.pitoiset@gmail.com>
Tue, 26 Feb 2019 12:42:26 +0000 (13:42 +0100)
committerSamuel Pitoiset <samuel.pitoiset@gmail.com>
Wed, 13 Mar 2019 12:31:06 +0000 (13:31 +0100)
Be more generic, this will be used by an upcoming series.

Signed-off-by: Samuel Pitoiset <samuel.pitoiset@gmail.com>
Reviewed-by: Bas Nieuwenhuizen <bas@basnieuwenhuizen.nl>
src/amd/common/ac_llvm_build.c
src/amd/common/ac_llvm_build.h
src/amd/common/ac_nir_to_llvm.c

index bc64f0bb7e3e9fe1e32a61f2c6561e7f27f9d4f5..b9eaf26f60330f455b80c0c4cd8fed3386aff49c 100644 (file)
@@ -1369,46 +1369,7 @@ LLVMValueRef ac_build_buffer_load_format_gfx9_safe(struct ac_llvm_context *ctx,
                                           can_speculate, true);
 }
 
-LLVMValueRef
-ac_build_tbuffer_load_short(struct ac_llvm_context *ctx,
-                           LLVMValueRef rsrc,
-                           LLVMValueRef vindex,
-                           LLVMValueRef voffset,
-                               LLVMValueRef soffset,
-                               LLVMValueRef immoffset,
-                               LLVMValueRef glc)
-{
-       unsigned dfmt = V_008F0C_BUF_DATA_FORMAT_16;
-       unsigned nfmt = V_008F0C_BUF_NUM_FORMAT_UINT;
-       LLVMValueRef res;
-
-       if (HAVE_LLVM >= 0x0800) {
-               voffset = LLVMBuildAdd(ctx->builder, voffset, immoffset, "");
-
-               res = ac_build_llvm8_tbuffer_load(ctx, rsrc, vindex, voffset,
-                                                 soffset, 1, dfmt, nfmt, glc,
-                                                 false, true, true);
-       } else {
-               const char *name = "llvm.amdgcn.tbuffer.load.i32";
-               LLVMTypeRef type = ctx->i32;
-               LLVMValueRef params[] = {
-                                       rsrc,
-                                       vindex,
-                                       voffset,
-                                       soffset,
-                                       immoffset,
-                                       LLVMConstInt(ctx->i32, dfmt, false),
-                                       LLVMConstInt(ctx->i32, nfmt, false),
-                                       glc,
-                                       ctx->i1false,
-               };
-               res = ac_build_intrinsic(ctx, name, type, params, 9, 0);
-       }
-
-       return LLVMBuildTrunc(ctx->builder, res, ctx->i16, "");
-}
-
-LLVMValueRef
+static LLVMValueRef
 ac_build_llvm8_tbuffer_load(struct ac_llvm_context *ctx,
                            LLVMValueRef rsrc,
                            LLVMValueRef vindex,
@@ -1446,6 +1407,71 @@ ac_build_llvm8_tbuffer_load(struct ac_llvm_context *ctx,
                                  ac_get_load_intr_attribs(can_speculate));
 }
 
+LLVMValueRef
+ac_build_tbuffer_load(struct ac_llvm_context *ctx,
+                           LLVMValueRef rsrc,
+                           LLVMValueRef vindex,
+                           LLVMValueRef voffset,
+                           LLVMValueRef soffset,
+                           LLVMValueRef immoffset,
+                           unsigned num_channels,
+                           unsigned dfmt,
+                           unsigned nfmt,
+                           bool glc,
+                           bool slc,
+                           bool can_speculate)
+{
+       if (HAVE_LLVM >= 0x800) {
+               voffset = LLVMBuildAdd(ctx->builder, voffset, immoffset, "");
+
+               return ac_build_llvm8_tbuffer_load(ctx, rsrc, vindex, voffset,
+                                                  soffset, num_channels,
+                                                  dfmt, nfmt, glc, slc,
+                                                  can_speculate, true);
+       }
+
+       LLVMValueRef args[] = {
+               rsrc,
+               vindex,
+               voffset,
+               soffset,
+               immoffset,
+               LLVMConstInt(ctx->i32, dfmt, false),
+               LLVMConstInt(ctx->i32, nfmt, false),
+               LLVMConstInt(ctx->i32, glc, false),
+               LLVMConstInt(ctx->i32, slc, false),
+       };
+       unsigned func = CLAMP(num_channels, 1, 3) - 1;
+       LLVMTypeRef types[] = {ctx->i32, ctx->v2i32, ctx->v4i32};
+       const char *type_names[] = {"i32", "v2i32", "v4i32"};
+       char name[256];
+
+       snprintf(name, sizeof(name), "llvm.amdgcn.tbuffer.load.%s",
+                type_names[func]);
+
+       return ac_build_intrinsic(ctx, name, types[func], args, 9,
+                                 ac_get_load_intr_attribs(can_speculate));
+}
+
+LLVMValueRef
+ac_build_tbuffer_load_short(struct ac_llvm_context *ctx,
+                           LLVMValueRef rsrc,
+                           LLVMValueRef vindex,
+                           LLVMValueRef voffset,
+                           LLVMValueRef soffset,
+                           LLVMValueRef immoffset,
+                           bool glc)
+{
+       unsigned dfmt = V_008F0C_BUF_DATA_FORMAT_16;
+       unsigned nfmt = V_008F0C_BUF_NUM_FORMAT_UINT;
+       LLVMValueRef res;
+
+       res = ac_build_tbuffer_load(ctx, rsrc, vindex, voffset, soffset,
+                                   immoffset, 1, dfmt, nfmt, glc, false, false);
+
+       return LLVMBuildTrunc(ctx->builder, res, ctx->i16, "");
+}
+
 /**
  * Set range metadata on an instruction.  This can only be used on load and
  * call instructions.  If you know an instruction can only produce the values
index fd5c4295abf487e2dcbd911be0ac59cdf89b0c41..d746c864229cc82b62081c0e05847d94aff9807e 100644 (file)
@@ -302,23 +302,23 @@ ac_build_tbuffer_load_short(struct ac_llvm_context *ctx,
                            LLVMValueRef rsrc,
                            LLVMValueRef vindex,
                            LLVMValueRef voffset,
-                               LLVMValueRef soffset,
-                               LLVMValueRef immoffset,
-                               LLVMValueRef glc);
+                           LLVMValueRef soffset,
+                           LLVMValueRef immoffset,
+                           bool glc);
 
 LLVMValueRef
-ac_build_llvm8_tbuffer_load(struct ac_llvm_context *ctx,
-                           LLVMValueRef rsrc,
-                           LLVMValueRef vindex,
-                           LLVMValueRef voffset,
-                           LLVMValueRef soffset,
-                           unsigned num_channels,
-                           unsigned dfmt,
-                           unsigned nfmt,
-                           bool glc,
-                           bool slc,
-                           bool can_speculate,
-                           bool structurized);
+ac_build_tbuffer_load(struct ac_llvm_context *ctx,
+                     LLVMValueRef rsrc,
+                     LLVMValueRef vindex,
+                     LLVMValueRef voffset,
+                     LLVMValueRef soffset,
+                     LLVMValueRef immoffset,
+                     unsigned num_channels,
+                     unsigned dfmt,
+                     unsigned nfmt,
+                     bool glc,
+                     bool slc,
+                     bool can_speculate);
 
 LLVMValueRef
 ac_get_thread_id(struct ac_llvm_context *ctx);
index 5fb5c8da6094d6c9565db3021c5135bf06b31cb9..a7b3fdf64aa6ef53e37b80fae52fd8b9badd34fa 100644 (file)
@@ -1716,7 +1716,7 @@ static LLVMValueRef visit_load_buffer(struct ac_nir_context *ctx,
                                                          offset,
                                                          ctx->ac.i32_0,
                                                          immoffset,
-                                                         glc);
+                                                         cache_policy & ac_glc);
                } else {
                        const char *load_name;
                        LLVMTypeRef data_type;
@@ -1787,7 +1787,7 @@ static LLVMValueRef visit_load_ubo_buffer(struct ac_nir_context *ctx,
                                                                 offset,
                                                                 ctx->ac.i32_0,
                                                                 LLVMConstInt(ctx->ac.i32, 2 * i, 0),
-                                                                ctx->ac.i1false);
+                                                                false);
                }
                ret = ac_build_gather_values(&ctx->ac, results, num_components);
        } else {