ac: add build_alloca with an initializer

combining alloca_undef + BuildStore.

Reviewed-by: Pierre-Eric Pelloux-Prayer <pierre-eric.pelloux-prayer@amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/7542>
This commit is contained in:
Marek Olšák
2020-11-10 08:53:02 -05:00
committed by Marge Bot
parent 025bc9e50e
commit d425d765bf
6 changed files with 19 additions and 15 deletions

View File

@@ -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));

View File

@@ -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);

View File

@@ -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? */);
{

View File

@@ -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);

View File

@@ -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);
}

View File

@@ -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;
}