Module: Mesa
Branch: master
Commit: d425d765bfe837df66c85a02998063e91a0b97f8
URL:    
http://cgit.freedesktop.org/mesa/mesa/commit/?id=d425d765bfe837df66c85a02998063e91a0b97f8

Author: Marek Olšák <[email protected]>
Date:   Tue Nov 10 08:53:02 2020 -0500

ac: add build_alloca with an initializer

combining alloca_undef + BuildStore.

Reviewed-by: Pierre-Eric Pelloux-Prayer <[email protected]>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/7542>

---

 src/amd/llvm/ac_llvm_build.c                     |  7 +++++++
 src/amd/llvm/ac_llvm_build.h                     |  1 +
 src/amd/llvm/ac_llvm_cull.c                      |  3 +--
 src/amd/llvm/ac_nir_to_llvm.c                    |  3 +--
 src/gallium/drivers/radeonsi/gfx10_shader_ngg.c  | 13 ++++++-------
 src/gallium/drivers/radeonsi/si_shader_llvm_vs.c |  7 +++----
 6 files changed, 19 insertions(+), 15 deletions(-)

diff --git a/src/amd/llvm/ac_llvm_build.c b/src/amd/llvm/ac_llvm_build.c
index d336f3a506b..9e081f0fd17 100644
--- a/src/amd/llvm/ac_llvm_build.c
+++ b/src/amd/llvm/ac_llvm_build.c
@@ -3222,6 +3222,13 @@ LLVMValueRef ac_build_alloca(struct ac_llvm_context *ac, 
LLVMTypeRef type, const
    return ptr;
 }
 
+LLVMValueRef ac_build_alloca_init(struct ac_llvm_context *ac, LLVMValueRef 
val, const char *name)
+{
+   LLVMValueRef ptr = ac_build_alloca_undef(ac, LLVMTypeOf(val), name);
+   LLVMBuildStore(ac->builder, val, ptr);
+   return ptr;
+}
+
 LLVMValueRef ac_cast_ptr(struct ac_llvm_context *ctx, LLVMValueRef ptr, 
LLVMTypeRef type)
 {
    int addr_space = LLVMGetPointerAddressSpace(LLVMTypeOf(ptr));
diff --git a/src/amd/llvm/ac_llvm_build.h b/src/amd/llvm/ac_llvm_build.h
index 32da9ec9733..9d345cd7753 100644
--- a/src/amd/llvm/ac_llvm_build.h
+++ b/src/amd/llvm/ac_llvm_build.h
@@ -470,6 +470,7 @@ void ac_build_ifcc(struct ac_llvm_context *ctx, 
LLVMValueRef cond, int label_id)
 
 LLVMValueRef ac_build_alloca(struct ac_llvm_context *ac, LLVMTypeRef type, 
const char *name);
 LLVMValueRef ac_build_alloca_undef(struct ac_llvm_context *ac, LLVMTypeRef 
type, const char *name);
+LLVMValueRef ac_build_alloca_init(struct ac_llvm_context *ac, LLVMValueRef 
val, const char *name);
 
 LLVMValueRef ac_cast_ptr(struct ac_llvm_context *ctx, LLVMValueRef ptr, 
LLVMTypeRef type);
 
diff --git a/src/amd/llvm/ac_llvm_cull.c b/src/amd/llvm/ac_llvm_cull.c
index a6ed2680927..3c185d69650 100644
--- a/src/amd/llvm/ac_llvm_cull.c
+++ b/src/amd/llvm/ac_llvm_cull.c
@@ -132,8 +132,7 @@ static LLVMValueRef cull_bbox(struct ac_llvm_context *ctx, 
LLVMValueRef pos[3][4
     * W is negative.
     */
    LLVMValueRef cond = LLVMBuildAnd(builder, initially_accepted, 
w->all_w_positive, "");
-   LLVMValueRef accepted_var = ac_build_alloca_undef(ctx, ctx->i1, "");
-   LLVMBuildStore(builder, initially_accepted, accepted_var);
+   LLVMValueRef accepted_var = ac_build_alloca_init(ctx, initially_accepted, 
"");
 
    ac_build_ifcc(ctx, cond, 10000000 /* does this matter? */);
    {
diff --git a/src/amd/llvm/ac_nir_to_llvm.c b/src/amd/llvm/ac_nir_to_llvm.c
index d9329cde2b8..3517eaa950f 100644
--- a/src/amd/llvm/ac_nir_to_llvm.c
+++ b/src/amd/llvm/ac_nir_to_llvm.c
@@ -4877,9 +4877,8 @@ void ac_nir_translate(struct ac_llvm_context *ac, struct 
ac_shader_abi *abi,
       setup_shared(&ctx, nir);
 
    if (nir->info.stage == MESA_SHADER_FRAGMENT && nir->info.fs.uses_demote) {
-      ctx.ac.postponed_kill = ac_build_alloca_undef(&ctx.ac, ac->i1, "");
       /* true = don't kill. */
-      LLVMBuildStore(ctx.ac.builder, ctx.ac.i1true, ctx.ac.postponed_kill);
+      ctx.ac.postponed_kill = ac_build_alloca_init(&ctx.ac, ctx.ac.i1true, "");
    }
 
    visit_cf_list(&ctx, &func->impl->body);
diff --git a/src/gallium/drivers/radeonsi/gfx10_shader_ngg.c 
b/src/gallium/drivers/radeonsi/gfx10_shader_ngg.c
index 64be935e3f9..2bb18d8af01 100644
--- a/src/gallium/drivers/radeonsi/gfx10_shader_ngg.c
+++ b/src/gallium/drivers/radeonsi/gfx10_shader_ngg.c
@@ -1055,13 +1055,13 @@ void gfx10_emit_ngg_culling_epilogue(struct 
ac_shader_abi *abi, unsigned max_out
    update_thread_counts(ctx, &new_num_es_threads, &new_gs_tg_info, 9, 12, 
&new_merged_wave_info, 8,
                         0);
 
-   /* Update vertex indices in VGPR0 (same format as NGG passthrough). */
-   LLVMValueRef new_vgpr0 = ac_build_alloca_undef(&ctx->ac, ctx->ac.i32, "");
-
-   /* Set the null flag at the beginning (culled), and then
+   /* Update vertex indices in VGPR0 (same format as NGG passthrough).
+    *
+    * Set the null flag at the beginning (culled), and then
     * overwrite it for accepted primitives.
     */
-   LLVMBuildStore(builder, LLVMConstInt(ctx->ac.i32, 1u << 31, 0), new_vgpr0);
+   LLVMValueRef new_vgpr0 =
+      ac_build_alloca_init(&ctx->ac, LLVMConstInt(ctx->ac.i32, 1u << 31, 0), 
"");
 
    /* Get vertex indices after vertex compaction. */
    ac_build_ifcc(&ctx->ac, LLVMBuildTrunc(builder, gs_accepted, ctx->ac.i1, 
""), 16011);
@@ -1315,8 +1315,7 @@ void gfx10_emit_ngg_epilogue(struct ac_shader_abi *abi, 
unsigned max_outputs, LL
          tmp = LLVMBuildLoad(builder, tmp, "");
          tmp = LLVMBuildTrunc(builder, tmp, ctx->ac.i1, "");
 
-         user_edgeflags[i] = ac_build_alloca_undef(&ctx->ac, ctx->ac.i1, "");
-         LLVMBuildStore(builder, tmp, user_edgeflags[i]);
+         user_edgeflags[i] = ac_build_alloca_init(&ctx->ac, tmp, "");
       }
       ac_build_endif(&ctx->ac, 5400);
    }
diff --git a/src/gallium/drivers/radeonsi/si_shader_llvm_vs.c 
b/src/gallium/drivers/radeonsi/si_shader_llvm_vs.c
index e29c2511520..6632f54b096 100644
--- a/src/gallium/drivers/radeonsi/si_shader_llvm_vs.c
+++ b/src/gallium/drivers/radeonsi/si_shader_llvm_vs.c
@@ -495,10 +495,9 @@ static void si_vertex_color_clamping(struct 
si_shader_context *ctx,
           outputs[i].semantic != VARYING_SLOT_BFC1)
          continue;
 
-      for (unsigned j = 0; j < 4; j++) {
-         addr[i][j] = ac_build_alloca_undef(&ctx->ac, ctx->ac.f32, "");
-         LLVMBuildStore(ctx->ac.builder, outputs[i].values[j], addr[i][j]);
-      }
+      for (unsigned j = 0; j < 4; j++)
+         addr[i][j] = ac_build_alloca_init(&ctx->ac, outputs[i].values[j], "");
+
       has_colors = true;
    }
 

_______________________________________________
mesa-commit mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/mesa-commit

Reply via email to