From bf6368297b5dba11d2d3dfbc4486ac98112f4a6d Mon Sep 17 00:00:00 2001 From: Samuel Pitoiset Date: Fri, 9 Mar 2018 16:22:44 +0100 Subject: [PATCH] ac/nir: move ac_build_alloca() to ac_llvm_build.c As well as si_build_alloca_undef() and drop the si prefix. Signed-off-by: Samuel Pitoiset Reviewed-by: Bas Nieuwenhuizen --- src/amd/common/ac_llvm_build.c | 33 ++++++++++++++++++++++++++ src/amd/common/ac_llvm_build.h | 5 ++++ src/amd/common/ac_nir_to_llvm.c | 42 +++------------------------------ 3 files changed, 41 insertions(+), 39 deletions(-) diff --git a/src/amd/common/ac_llvm_build.c b/src/amd/common/ac_llvm_build.c index 9851cafb7fd..8d4f114a65b 100644 --- a/src/amd/common/ac_llvm_build.c +++ b/src/amd/common/ac_llvm_build.c @@ -2335,3 +2335,36 @@ void ac_build_uif(struct ac_llvm_context *ctx, LLVMValueRef value, ctx->i32_0, ""); if_cond_emit(ctx, cond, label_id); } + +LLVMValueRef ac_build_alloca(struct ac_llvm_context *ac, LLVMTypeRef type, + const char *name) +{ + LLVMBuilderRef builder = ac->builder; + LLVMBasicBlockRef current_block = LLVMGetInsertBlock(builder); + LLVMValueRef function = LLVMGetBasicBlockParent(current_block); + LLVMBasicBlockRef first_block = LLVMGetEntryBasicBlock(function); + LLVMValueRef first_instr = LLVMGetFirstInstruction(first_block); + LLVMBuilderRef first_builder = LLVMCreateBuilderInContext(ac->context); + LLVMValueRef res; + + if (first_instr) { + LLVMPositionBuilderBefore(first_builder, first_instr); + } else { + LLVMPositionBuilderAtEnd(first_builder, first_block); + } + + res = LLVMBuildAlloca(first_builder, type, name); + LLVMBuildStore(builder, LLVMConstNull(type), res); + + LLVMDisposeBuilder(first_builder); + + return res; +} + +LLVMValueRef ac_build_alloca_undef(struct ac_llvm_context *ac, + LLVMTypeRef type, const char *name) +{ + LLVMValueRef ptr = ac_build_alloca(ac, type, name); + LLVMBuildStore(ac->builder, LLVMGetUndef(type), ptr); + return ptr; +} diff --git a/src/amd/common/ac_llvm_build.h b/src/amd/common/ac_llvm_build.h index c080381d21c..2587c94315c 100644 --- a/src/amd/common/ac_llvm_build.h +++ b/src/amd/common/ac_llvm_build.h @@ -390,6 +390,11 @@ void ac_build_if(struct ac_llvm_context *ctx, LLVMValueRef value, void ac_build_uif(struct ac_llvm_context *ctx, LLVMValueRef value, int lable_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); + #ifdef __cplusplus } #endif diff --git a/src/amd/common/ac_nir_to_llvm.c b/src/amd/common/ac_nir_to_llvm.c index b8cfdc3c1a4..9f2219a5467 100644 --- a/src/amd/common/ac_nir_to_llvm.c +++ b/src/amd/common/ac_nir_to_llvm.c @@ -5635,42 +5635,6 @@ handle_fs_inputs(struct radv_shader_context *ctx, ctx->abi.view_index = ctx->inputs[radeon_llvm_reg_index_soa(VARYING_SLOT_LAYER, 0)]; } -static LLVMValueRef -ac_build_alloca(struct ac_llvm_context *ac, - LLVMTypeRef type, - const char *name) -{ - LLVMBuilderRef builder = ac->builder; - LLVMBasicBlockRef current_block = LLVMGetInsertBlock(builder); - LLVMValueRef function = LLVMGetBasicBlockParent(current_block); - LLVMBasicBlockRef first_block = LLVMGetEntryBasicBlock(function); - LLVMValueRef first_instr = LLVMGetFirstInstruction(first_block); - LLVMBuilderRef first_builder = LLVMCreateBuilderInContext(ac->context); - LLVMValueRef res; - - if (first_instr) { - LLVMPositionBuilderBefore(first_builder, first_instr); - } else { - LLVMPositionBuilderAtEnd(first_builder, first_block); - } - - res = LLVMBuildAlloca(first_builder, type, name); - LLVMBuildStore(builder, LLVMConstNull(type), res); - - LLVMDisposeBuilder(first_builder); - - return res; -} - -static LLVMValueRef si_build_alloca_undef(struct ac_llvm_context *ac, - LLVMTypeRef type, - const char *name) -{ - LLVMValueRef ptr = ac_build_alloca(ac, type, name); - LLVMBuildStore(ac->builder, LLVMGetUndef(type), ptr); - return ptr; -} - static void scan_shader_output_decl(struct radv_shader_context *ctx, struct nir_variable *variable, @@ -5744,7 +5708,7 @@ handle_shader_output_decl(struct ac_nir_context *ctx, for (unsigned i = 0; i < attrib_count; ++i) { for (unsigned chan = 0; chan < 4; chan++) { ctx->abi->outputs[radeon_llvm_reg_index_soa(output_loc + i, chan)] = - si_build_alloca_undef(&ctx->ac, ctx->ac.f32, ""); + ac_build_alloca_undef(&ctx->ac, ctx->ac.f32, ""); } } } @@ -5830,7 +5794,7 @@ setup_locals(struct ac_nir_context *ctx, for (i = 0; i < ctx->num_locals; i++) { for (j = 0; j < 4; j++) { ctx->locals[i * 4 + j] = - si_build_alloca_undef(&ctx->ac, ctx->ac.f32, "temp"); + ac_build_alloca_undef(&ctx->ac, ctx->ac.f32, "temp"); } } } @@ -6021,7 +5985,7 @@ handle_vs_outputs_post(struct radv_shader_context *ctx, if(!*tmp_out) { for(unsigned i = 0; i < 4; ++i) ctx->abi.outputs[radeon_llvm_reg_index_soa(VARYING_SLOT_LAYER, i)] = - si_build_alloca_undef(&ctx->ac, ctx->ac.f32, ""); + ac_build_alloca_undef(&ctx->ac, ctx->ac.f32, ""); } LLVMBuildStore(ctx->ac.builder, ac_to_float(&ctx->ac, ctx->abi.view_index), *tmp_out); -- 2.30.2