ac/nir: Use correct cast for readfirstlane and ptrs.
[mesa.git] / src / amd / common / ac_llvm_build.c
index 250bfc5229ec55e0560eacc6f4462504a7af65a1..0943d0364ddabc33bd041be5f5a049551f00c873 100644 (file)
@@ -127,14 +127,15 @@ ac_llvm_context_init(struct ac_llvm_context *ctx,
                                                        "amdgpu.uniform", 14);
 
        ctx->empty_md = LLVMMDNodeInContext(ctx->context, NULL, 0);
+       ctx->flow = calloc(1, sizeof(*ctx->flow));
 }
 
 void
 ac_llvm_context_dispose(struct ac_llvm_context *ctx)
 {
+       free(ctx->flow->stack);
        free(ctx->flow);
        ctx->flow = NULL;
-       ctx->flow_depth_max = 0;
 }
 
 int
@@ -350,6 +351,7 @@ void ac_build_type_name_for_intr(LLVMTypeRef type, char *buf, unsigned bufsize)
                        char *type_name = LLVMPrintTypeToString(type);
                        fprintf(stderr, "Error building type name for: %s\n",
                                type_name);
+                       LLVMDisposeMessage(type_name);
                        return;
                }
                elem_type = LLVMGetElementType(type);
@@ -1508,6 +1510,7 @@ ac_get_tbuffer_format(struct ac_llvm_context *ctx,
                unsigned format;
                switch (dfmt) {
                default: unreachable("bad dfmt");
+               case V_008F0C_BUF_DATA_FORMAT_INVALID: format = V_008F0C_IMG_FORMAT_INVALID; break;
                case V_008F0C_BUF_DATA_FORMAT_8: format = V_008F0C_IMG_FORMAT_8_UINT; break;
                case V_008F0C_BUF_DATA_FORMAT_8_8: format = V_008F0C_IMG_FORMAT_8_8_UINT; break;
                case V_008F0C_BUF_DATA_FORMAT_8_8_8_8: format = V_008F0C_IMG_FORMAT_8_8_8_8_UINT; break;
@@ -3494,17 +3497,17 @@ LLVMTypeRef ac_array_in_const32_addr_space(LLVMTypeRef elem_type)
 static struct ac_llvm_flow *
 get_current_flow(struct ac_llvm_context *ctx)
 {
-       if (ctx->flow_depth > 0)
-               return &ctx->flow[ctx->flow_depth - 1];
+       if (ctx->flow->depth > 0)
+               return &ctx->flow->stack[ctx->flow->depth - 1];
        return NULL;
 }
 
 static struct ac_llvm_flow *
 get_innermost_loop(struct ac_llvm_context *ctx)
 {
-       for (unsigned i = ctx->flow_depth; i > 0; --i) {
-               if (ctx->flow[i - 1].loop_entry_block)
-                       return &ctx->flow[i - 1];
+       for (unsigned i = ctx->flow->depth; i > 0; --i) {
+               if (ctx->flow->stack[i - 1].loop_entry_block)
+                       return &ctx->flow->stack[i - 1];
        }
        return NULL;
 }
@@ -3514,16 +3517,16 @@ push_flow(struct ac_llvm_context *ctx)
 {
        struct ac_llvm_flow *flow;
 
-       if (ctx->flow_depth >= ctx->flow_depth_max) {
-               unsigned new_max = MAX2(ctx->flow_depth << 1,
+       if (ctx->flow->depth >= ctx->flow->depth_max) {
+               unsigned new_max = MAX2(ctx->flow->depth << 1,
                                        AC_LLVM_INITIAL_CF_DEPTH);
 
-               ctx->flow = realloc(ctx->flow, new_max * sizeof(*ctx->flow));
-               ctx->flow_depth_max = new_max;
+               ctx->flow->stack = realloc(ctx->flow->stack, new_max * sizeof(*ctx->flow->stack));
+               ctx->flow->depth_max = new_max;
        }
 
-       flow = &ctx->flow[ctx->flow_depth];
-       ctx->flow_depth++;
+       flow = &ctx->flow->stack[ctx->flow->depth];
+       ctx->flow->depth++;
 
        flow->next_block = NULL;
        flow->loop_entry_block = NULL;
@@ -3543,10 +3546,10 @@ static void set_basicblock_name(LLVMBasicBlockRef bb, const char *base,
 static LLVMBasicBlockRef append_basic_block(struct ac_llvm_context *ctx,
                                            const char *name)
 {
-       assert(ctx->flow_depth >= 1);
+       assert(ctx->flow->depth >= 1);
 
-       if (ctx->flow_depth >= 2) {
-               struct ac_llvm_flow *flow = &ctx->flow[ctx->flow_depth - 2];
+       if (ctx->flow->depth >= 2) {
+               struct ac_llvm_flow *flow = &ctx->flow->stack[ctx->flow->depth - 2];
 
                return LLVMInsertBasicBlockInContext(ctx->context,
                                                     flow->next_block, name);
@@ -3616,7 +3619,7 @@ void ac_build_endif(struct ac_llvm_context *ctx, int label_id)
        LLVMPositionBuilderAtEnd(ctx->builder, current_branch->next_block);
        set_basicblock_name(current_branch->next_block, "endif", label_id);
 
-       ctx->flow_depth--;
+       ctx->flow->depth--;
 }
 
 void ac_build_endloop(struct ac_llvm_context *ctx, int label_id)
@@ -3629,7 +3632,7 @@ void ac_build_endloop(struct ac_llvm_context *ctx, int label_id)
 
        LLVMPositionBuilderAtEnd(ctx->builder, current_loop->next_block);
        set_basicblock_name(current_loop->next_block, "endloop", label_id);
-       ctx->flow_depth--;
+       ctx->flow->depth--;
 }
 
 void ac_build_ifcc(struct ac_llvm_context *ctx, LLVMValueRef cond, int label_id)
@@ -3837,6 +3840,8 @@ ac_build_readlane(struct ac_llvm_context *ctx, LLVMValueRef src, LLVMValueRef la
                                                LLVMConstInt(ctx->i32, i, 0), "");
                }
        }
+       if (LLVMGetTypeKind(src_type) == LLVMPointerTypeKind)
+               return LLVMBuildIntToPtr(ctx->builder, ret, src_type, "");
        return LLVMBuildBitCast(ctx->builder, ret, src_type, "");
 }