ac/nir: move ac_build_alloca() to ac_llvm_build.c
authorSamuel Pitoiset <samuel.pitoiset@gmail.com>
Fri, 9 Mar 2018 15:22:44 +0000 (16:22 +0100)
committerSamuel Pitoiset <samuel.pitoiset@gmail.com>
Tue, 13 Mar 2018 13:05:06 +0000 (14:05 +0100)
As well as si_build_alloca_undef() and drop the si prefix.

Signed-off-by: Samuel Pitoiset <samuel.pitoiset@gmail.com>
Reviewed-by: Bas Nieuwenhuizen <bas@basnieuwenhuizen.nl>
src/amd/common/ac_llvm_build.c
src/amd/common/ac_llvm_build.h
src/amd/common/ac_nir_to_llvm.c

index 9851cafb7fd9504645369328a63e51813c53f430..8d4f114a65bb529e93d4e5d330e21c4d3f042127 100644 (file)
@@ -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;
+}
index c080381d21ca3586fcfd8463516ce6c02c8a6342..2587c94315c6e31e95040a13e9344a5f8be04182 100644 (file)
@@ -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
index b8cfdc3c1a47f3e73ba71665fd2d6355182d0cf8..9f2219a5467bafbafeee3e08e9b13a3938896c51 100644 (file)
@@ -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);