amd/common: Implement ptr->int casts in ac_to_integer.
authorBas Nieuwenhuizen <bas@basnieuwenhuizen.nl>
Wed, 23 Jan 2019 00:54:39 +0000 (01:54 +0100)
committerBas Nieuwenhuizen <bas@basnieuwenhuizen.nl>
Wed, 6 Feb 2019 21:35:40 +0000 (22:35 +0100)
For the implicit casts inherent in nir.

This should probably have been done for shared memory for
VK_KHR_variable_pointers.

Reviewed-by: Samuel Pitoiset <samuel.pitoiset@gmail.com>
src/amd/common/ac_llvm_build.c

index 9aff2f8435d90bd12f5c1142bb1de374029051ef..9395bd1bbda722ccfa1b41d7d4a109925bb1fd07 100644 (file)
@@ -219,6 +219,16 @@ ac_to_integer_type(struct ac_llvm_context *ctx, LLVMTypeRef t)
                return LLVMVectorType(to_integer_type_scalar(ctx, elem_type),
                                      LLVMGetVectorSize(t));
        }
+       if (LLVMGetTypeKind(t) == LLVMPointerTypeKind) {
+               switch (LLVMGetPointerAddressSpace(t)) {
+               case AC_ADDR_SPACE_GLOBAL:
+                       return ctx->i64;
+               case AC_ADDR_SPACE_LDS:
+                       return ctx->i32;
+               default:
+                       unreachable("unhandled address space");
+               }
+       }
        return to_integer_type_scalar(ctx, t);
 }
 
@@ -226,6 +236,9 @@ LLVMValueRef
 ac_to_integer(struct ac_llvm_context *ctx, LLVMValueRef v)
 {
        LLVMTypeRef type = LLVMTypeOf(v);
+       if (LLVMGetTypeKind(type) == LLVMPointerTypeKind) {
+               return LLVMBuildPtrToInt(ctx->builder, v, ac_to_integer_type(ctx, type), "");
+       }
        return LLVMBuildBitCast(ctx->builder, v, ac_to_integer_type(ctx, type), "");
 }