ac/nir: remove type and num_channels args from ac_build_buffer_store_common
[mesa.git] / src / amd / llvm / ac_llvm_build.c
index ef4c95e5673a02c1dfc87f13ede5960091c79afe..5483b3146c01c284eb7153f4cb67e5f1720a319b 100644 (file)
@@ -89,6 +89,9 @@ ac_llvm_context_init(struct ac_llvm_context *ctx,
        ctx->f32 = LLVMFloatTypeInContext(ctx->context);
        ctx->f64 = LLVMDoubleTypeInContext(ctx->context);
        ctx->v2i16 = LLVMVectorType(ctx->i16, 2);
+       ctx->v4i16 = LLVMVectorType(ctx->i16, 4);
+       ctx->v2f16 = LLVMVectorType(ctx->f16, 2);
+       ctx->v4f16 = LLVMVectorType(ctx->f16, 4);
        ctx->v2i32 = LLVMVectorType(ctx->i32, 2);
        ctx->v3i32 = LLVMVectorType(ctx->i32, 3);
        ctx->v4i32 = LLVMVectorType(ctx->i32, 4);
@@ -1180,8 +1183,6 @@ ac_build_buffer_store_common(struct ac_llvm_context *ctx,
                             LLVMValueRef vindex,
                             LLVMValueRef voffset,
                             LLVMValueRef soffset,
-                            unsigned num_channels,
-                            LLVMTypeRef return_channel_type,
                             unsigned cache_policy,
                             bool use_format,
                             bool structurized)
@@ -1195,12 +1196,10 @@ ac_build_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, cache_policy, 0);
-       unsigned func = !ac_has_vec3_support(ctx->chip_class, use_format) && num_channels == 3 ? 4 : num_channels;
        const char *indexing_kind = structurized ? "struct" : "raw";
        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));
+       ac_build_type_name_for_intr(LLVMTypeOf(data), type_name, sizeof(type_name));
 
        if (use_format) {
                snprintf(name, sizeof(name), "llvm.amdgcn.%s.buffer.store.format.%s",
@@ -1220,13 +1219,10 @@ ac_build_buffer_store_format(struct ac_llvm_context *ctx,
                             LLVMValueRef data,
                             LLVMValueRef vindex,
                             LLVMValueRef voffset,
-                            unsigned num_channels,
                             unsigned cache_policy)
 {
-       ac_build_buffer_store_common(ctx, rsrc, data, vindex,
-                                    voffset, NULL, num_channels,
-                                    ctx->f32, cache_policy,
-                                    true, true);
+       ac_build_buffer_store_common(ctx, rsrc, data, vindex, voffset, NULL,
+                                    cache_policy, true, true);
 }
 
 /* TBUFFER_STORE_FORMAT_{X,XY,XYZ,XYZW} <- the suffix is selected by num_channels=1..4.
@@ -1275,7 +1271,6 @@ ac_build_buffer_store_dword(struct ac_llvm_context *ctx,
 
                ac_build_buffer_store_common(ctx, rsrc, ac_to_float(ctx, vdata),
                                             ctx->i32_0, voffset, offset,
-                                            num_channels, ctx->f32,
                                             cache_policy, false, false);
                return;
        }
@@ -1933,8 +1928,7 @@ ac_build_tbuffer_store_short(struct ac_llvm_context *ctx,
        if (LLVM_VERSION_MAJOR >= 9) {
                /* LLVM 9+ supports i8/i16 with struct/raw intrinsics. */
                ac_build_buffer_store_common(ctx, rsrc, vdata, NULL,
-                                            voffset, soffset, 1,
-                                            ctx->i16, cache_policy,
+                                            voffset, soffset, cache_policy,
                                             false, false);
        } else {
                unsigned dfmt = V_008F0C_BUF_DATA_FORMAT_16;
@@ -1960,8 +1954,7 @@ ac_build_tbuffer_store_byte(struct ac_llvm_context *ctx,
        if (LLVM_VERSION_MAJOR >= 9) {
                /* LLVM 9+ supports i8/i16 with struct/raw intrinsics. */
                ac_build_buffer_store_common(ctx, rsrc, vdata, NULL,
-                                            voffset, soffset, 1,
-                                            ctx->i8, cache_policy,
+                                            voffset, soffset, cache_policy,
                                             false, false);
        } else {
                unsigned dfmt = V_008F0C_BUF_DATA_FORMAT_8;
@@ -2189,8 +2182,10 @@ ac_build_umsb(struct ac_llvm_context *ctx,
 LLVMValueRef ac_build_fmin(struct ac_llvm_context *ctx, LLVMValueRef a,
                           LLVMValueRef b)
 {
-       char name[64];
-       snprintf(name, sizeof(name), "llvm.minnum.f%d", ac_get_elem_bits(ctx, LLVMTypeOf(a)));
+       char name[64], type[64];
+
+       ac_build_type_name_for_intr(LLVMTypeOf(a), type, sizeof(type));
+       snprintf(name, sizeof(name), "llvm.minnum.%s", type);
        LLVMValueRef args[2] = {a, b};
        return ac_build_intrinsic(ctx, name, LLVMTypeOf(a), args, 2,
                                  AC_FUNC_ATTR_READNONE);
@@ -2199,8 +2194,10 @@ LLVMValueRef ac_build_fmin(struct ac_llvm_context *ctx, LLVMValueRef a,
 LLVMValueRef ac_build_fmax(struct ac_llvm_context *ctx, LLVMValueRef a,
                           LLVMValueRef b)
 {
-       char name[64];
-       snprintf(name, sizeof(name), "llvm.maxnum.f%d", ac_get_elem_bits(ctx, LLVMTypeOf(a)));
+       char name[64], type[64];
+
+       ac_build_type_name_for_intr(LLVMTypeOf(a), type, sizeof(type));
+       snprintf(name, sizeof(name), "llvm.maxnum.%s", type);
        LLVMValueRef args[2] = {a, b};
        return ac_build_intrinsic(ctx, name, LLVMTypeOf(a), args, 2,
                                  AC_FUNC_ATTR_READNONE);
@@ -2249,13 +2246,10 @@ void ac_build_export(struct ac_llvm_context *ctx, struct ac_export_args *a)
        args[1] = LLVMConstInt(ctx->i32, a->enabled_channels, 0);
 
        if (a->compr) {
-               LLVMTypeRef i16 = LLVMInt16TypeInContext(ctx->context);
-               LLVMTypeRef v2i16 = LLVMVectorType(i16, 2);
-
                args[2] = LLVMBuildBitCast(ctx->builder, a->out[0],
-                               v2i16, "");
+                               ctx->v2i16, "");
                args[3] = LLVMBuildBitCast(ctx->builder, a->out[1],
-                               v2i16, "");
+                               ctx->v2i16, "");
                args[4] = LLVMConstInt(ctx->i1, a->done, 0);
                args[5] = LLVMConstInt(ctx->i1, a->valid_mask, 0);
 
@@ -2540,10 +2534,7 @@ LLVMValueRef ac_build_image_get_sample_count(struct ac_llvm_context *ctx,
 LLVMValueRef ac_build_cvt_pkrtz_f16(struct ac_llvm_context *ctx,
                                    LLVMValueRef args[2])
 {
-       LLVMTypeRef v2f16 =
-               LLVMVectorType(LLVMHalfTypeInContext(ctx->context), 2);
-
-       return ac_build_intrinsic(ctx, "llvm.amdgcn.cvt.pkrtz", v2f16,
+       return ac_build_intrinsic(ctx, "llvm.amdgcn.cvt.pkrtz", ctx->v2f16,
                                  args, 2, AC_FUNC_ATTR_READNONE);
 }
 
@@ -3712,9 +3703,7 @@ ac_build_mbcnt(struct ac_llvm_context *ctx, LLVMValueRef mask)
                                          (LLVMValueRef []) { mask, ctx->i32_0 },
                                          2, AC_FUNC_ATTR_READNONE);
        }
-       LLVMValueRef mask_vec = LLVMBuildBitCast(ctx->builder, mask,
-                                                LLVMVectorType(ctx->i32, 2),
-                                                "");
+       LLVMValueRef mask_vec = LLVMBuildBitCast(ctx->builder, mask, ctx->v2i32, "");
        LLVMValueRef mask_lo = LLVMBuildExtractElement(ctx->builder, mask_vec,
                                                       ctx->i32_0, "");
        LLVMValueRef mask_hi = LLVMBuildExtractElement(ctx->builder, mask_vec,