ac: define all address spaces properly
authorMarek Olšák <marek.olsak@amd.com>
Fri, 7 Sep 2018 22:44:54 +0000 (18:44 -0400)
committerMarek Olšák <marek.olsak@amd.com>
Sun, 7 Oct 2018 01:50:09 +0000 (21:50 -0400)
src/amd/common/ac_llvm_build.c
src/amd/common/ac_llvm_build.h
src/amd/common/ac_nir_to_llvm.c
src/amd/vulkan/radv_nir_to_llvm.c
src/gallium/drivers/radeonsi/si_shader.c

index ab0ba09c83ae607536fa7b17ce71303f30e19d80..93bd35239b28eecfa3e27b7bc97a0d54f75b2e26 100644 (file)
@@ -184,7 +184,7 @@ ac_get_type_size(LLVMTypeRef type)
        case LLVMDoubleTypeKind:
                return 8;
        case LLVMPointerTypeKind:
-               if (LLVMGetPointerAddressSpace(type) == AC_CONST_32BIT_ADDR_SPACE)
+               if (LLVMGetPointerAddressSpace(type) == AC_ADDR_SPACE_CONST_32BIT)
                        return 4;
                return 8;
        case LLVMVectorTypeKind:
@@ -891,7 +891,7 @@ ac_build_load_custom(struct ac_llvm_context *ctx, LLVMValueRef base_ptr,
        LLVMValueRef indices[2] = {ctx->i32_0, index};
 
        if (no_unsigned_wraparound &&
-           LLVMGetPointerAddressSpace(LLVMTypeOf(base_ptr)) == AC_CONST_32BIT_ADDR_SPACE)
+           LLVMGetPointerAddressSpace(LLVMTypeOf(base_ptr)) == AC_ADDR_SPACE_CONST_32BIT)
                pointer = LLVMBuildInBoundsGEP(ctx->builder, base_ptr, indices, 2, "");
        else
                pointer = LLVMBuildGEP(ctx->builder, base_ptr, indices, 2, "");
@@ -2482,7 +2482,7 @@ void ac_declare_lds_as_pointer(struct ac_llvm_context *ctx)
 {
        unsigned lds_size = ctx->chip_class >= CIK ? 65536 : 32768;
        ctx->lds = LLVMBuildIntToPtr(ctx->builder, ctx->i32_0,
-                                    LLVMPointerType(LLVMArrayType(ctx->i32, lds_size / 4), AC_LOCAL_ADDR_SPACE),
+                                    LLVMPointerType(LLVMArrayType(ctx->i32, lds_size / 4), AC_ADDR_SPACE_LDS),
                                     "lds");
 }
 
@@ -2564,7 +2564,7 @@ LLVMValueRef ac_find_lsb(struct ac_llvm_context *ctx,
 LLVMTypeRef ac_array_in_const_addr_space(LLVMTypeRef elem_type)
 {
        return LLVMPointerType(LLVMArrayType(elem_type, 0),
-                              AC_CONST_ADDR_SPACE);
+                              AC_ADDR_SPACE_CONST);
 }
 
 LLVMTypeRef ac_array_in_const32_addr_space(LLVMTypeRef elem_type)
@@ -2573,7 +2573,7 @@ LLVMTypeRef ac_array_in_const32_addr_space(LLVMTypeRef elem_type)
                return ac_array_in_const_addr_space(elem_type);
 
        return LLVMPointerType(LLVMArrayType(elem_type, 0),
-                              AC_CONST_32BIT_ADDR_SPACE);
+                              AC_ADDR_SPACE_CONST_32BIT);
 }
 
 static struct ac_llvm_flow *
index 0df9234c664d95b863fc541160b53f30586ffc8a..73f8a6b70cdca932af386a5b5ff7b73b012dd26b 100644 (file)
@@ -37,10 +37,12 @@ extern "C" {
 #define HAVE_32BIT_POINTERS (HAVE_LLVM >= 0x0700)
 
 enum {
-       /* CONST is the only address space that selects SMEM loads */
-       AC_CONST_ADDR_SPACE = HAVE_LLVM >= 0x700 ? 4 : 2,
-       AC_LOCAL_ADDR_SPACE = 3,
-       AC_CONST_32BIT_ADDR_SPACE = 6, /* same as CONST, but the pointer type has 32 bits */
+       AC_ADDR_SPACE_FLAT = HAVE_LLVM >= 0x0700 ? 0 : 4, /* Slower than global. */
+       AC_ADDR_SPACE_GLOBAL = 1,
+       AC_ADDR_SPACE_GDS = HAVE_LLVM >= 0x0700 ? 2 : 5,
+       AC_ADDR_SPACE_LDS = 3,
+       AC_ADDR_SPACE_CONST = HAVE_LLVM >= 0x0700 ? 4 : 2, /* Global allowing SMEM. */
+       AC_ADDR_SPACE_CONST_32BIT = 6, /* same as CONST, but the pointer type has 32 bits */
 };
 
 /* Combine these with & instead of |. */
index b01309cc2a9fcdd5f04af07506f55c0513ed398f..312383db36cc25bd413985f06a36a97fb6e741b5 100644 (file)
@@ -3928,7 +3928,7 @@ setup_shared(struct ac_nir_context *ctx,
                        LLVMAddGlobalInAddressSpace(
                           ctx->ac.module, glsl_to_llvm_type(&ctx->ac, variable->type),
                           variable->name ? variable->name : "",
-                          AC_LOCAL_ADDR_SPACE);
+                          AC_ADDR_SPACE_LDS);
                _mesa_hash_table_insert(ctx->vars, variable, shared);
        }
 }
index 32d347ebd0fc4c7211a5771d11c2b2fdfada74ce..b2f04d029b73a686e3b8e0530e0cc3155d0a7cec 100644 (file)
@@ -1136,7 +1136,7 @@ static void create_function(struct radv_shader_context *ctx,
                                   &user_sgpr_idx);
                if (ctx->options->supports_spill) {
                        ctx->ring_offsets = ac_build_intrinsic(&ctx->ac, "llvm.amdgcn.implicit.buffer.ptr",
-                                                              LLVMPointerType(ctx->ac.i8, AC_CONST_ADDR_SPACE),
+                                                              LLVMPointerType(ctx->ac.i8, AC_ADDR_SPACE_CONST),
                                                               NULL, 0, AC_FUNC_ATTR_READNONE);
                        ctx->ring_offsets = LLVMBuildBitCast(ctx->ac.builder, ctx->ring_offsets,
                                                             ac_array_in_const_addr_space(ctx->ac.v4i32), "");
index fedc616ebf6139c3785b328f27aee29f8658009b..acd4d34f89946e42e07cd0e75d500c8fa87ef047 100644 (file)
@@ -2287,7 +2287,7 @@ void si_declare_compute_memory(struct si_shader_context *ctx)
        struct si_shader_selector *sel = ctx->shader->selector;
        unsigned lds_size = sel->info.properties[TGSI_PROPERTY_CS_LOCAL_SIZE];
 
-       LLVMTypeRef i8p = LLVMPointerType(ctx->i8, AC_LOCAL_ADDR_SPACE);
+       LLVMTypeRef i8p = LLVMPointerType(ctx->i8, AC_ADDR_SPACE_LDS);
        LLVMValueRef var;
 
        assert(!ctx->ac.lds);
@@ -2295,7 +2295,7 @@ void si_declare_compute_memory(struct si_shader_context *ctx)
        var = LLVMAddGlobalInAddressSpace(ctx->ac.module,
                                          LLVMArrayType(ctx->i8, lds_size),
                                          "compute_lds",
-                                         AC_LOCAL_ADDR_SPACE);
+                                         AC_ADDR_SPACE_LDS);
        LLVMSetAlignment(var, 4);
 
        ctx->ac.lds = LLVMBuildBitCast(ctx->ac.builder, var, i8p, "");
@@ -6669,7 +6669,7 @@ static void si_build_wrapper_function(struct si_shader_context *ctx,
                        if (LLVMTypeOf(arg) != param_type) {
                                if (LLVMGetTypeKind(param_type) == LLVMPointerTypeKind) {
                                        if (LLVMGetPointerAddressSpace(param_type) ==
-                                           AC_CONST_32BIT_ADDR_SPACE) {
+                                           AC_ADDR_SPACE_CONST_32BIT) {
                                                arg = LLVMBuildBitCast(builder, arg, ctx->i32, "");
                                                arg = LLVMBuildIntToPtr(builder, arg, param_type, "");
                                        } else {