radv: move ac_build_if_state on top of radv_nir_to_llvm.c

Submitted by Samuel Pitoiset on May 11, 2018, 7:38 a.m.

Details

Message ID 20180511073819.12198-1-samuel.pitoiset@gmail.com
State Accepted
Headers show
Series "radv: move ac_build_if_state on top of radv_nir_to_llvm.c" ( rev: 1 ) in Mesa

Not browsing as part of any series.

Commit Message

Samuel Pitoiset May 11, 2018, 7:38 a.m.
These helpers will be needed for future work.

Signed-off-by: Samuel Pitoiset <samuel.pitoiset@gmail.com>
---
 src/amd/vulkan/radv_nir_to_llvm.c | 183 +++++++++++++++---------------
 1 file changed, 92 insertions(+), 91 deletions(-)

Patch hide | download patch | download mbox

diff --git a/src/amd/vulkan/radv_nir_to_llvm.c b/src/amd/vulkan/radv_nir_to_llvm.c
index cee3558215d..725fdb07a4d 100644
--- a/src/amd/vulkan/radv_nir_to_llvm.c
+++ b/src/amd/vulkan/radv_nir_to_llvm.c
@@ -130,6 +130,98 @@  radv_shader_context_from_abi(struct ac_shader_abi *abi)
 	return container_of(abi, ctx, abi);
 }
 
+struct ac_build_if_state
+{
+	struct radv_shader_context *ctx;
+	LLVMValueRef condition;
+	LLVMBasicBlockRef entry_block;
+	LLVMBasicBlockRef true_block;
+	LLVMBasicBlockRef false_block;
+	LLVMBasicBlockRef merge_block;
+};
+
+static LLVMBasicBlockRef
+ac_build_insert_new_block(struct radv_shader_context *ctx, const char *name)
+{
+	LLVMBasicBlockRef current_block;
+	LLVMBasicBlockRef next_block;
+	LLVMBasicBlockRef new_block;
+
+	/* get current basic block */
+	current_block = LLVMGetInsertBlock(ctx->ac.builder);
+
+	/* chqeck if there's another block after this one */
+	next_block = LLVMGetNextBasicBlock(current_block);
+	if (next_block) {
+		/* insert the new block before the next block */
+		new_block = LLVMInsertBasicBlockInContext(ctx->context, next_block, name);
+	}
+	else {
+		/* append new block after current block */
+		LLVMValueRef function = LLVMGetBasicBlockParent(current_block);
+		new_block = LLVMAppendBasicBlockInContext(ctx->context, function, name);
+	}
+	return new_block;
+}
+
+static void
+ac_nir_build_if(struct ac_build_if_state *ifthen,
+		struct radv_shader_context *ctx,
+		LLVMValueRef condition)
+{
+	LLVMBasicBlockRef block = LLVMGetInsertBlock(ctx->ac.builder);
+
+	memset(ifthen, 0, sizeof *ifthen);
+	ifthen->ctx = ctx;
+	ifthen->condition = condition;
+	ifthen->entry_block = block;
+
+	/* create endif/merge basic block for the phi functions */
+	ifthen->merge_block = ac_build_insert_new_block(ctx, "endif-block");
+
+	/* create/insert true_block before merge_block */
+	ifthen->true_block =
+		LLVMInsertBasicBlockInContext(ctx->context,
+					      ifthen->merge_block,
+					      "if-true-block");
+
+	/* successive code goes into the true block */
+	LLVMPositionBuilderAtEnd(ctx->ac.builder, ifthen->true_block);
+}
+
+/**
+ * End a conditional.
+ */
+static void
+ac_nir_build_endif(struct ac_build_if_state *ifthen)
+{
+	LLVMBuilderRef builder = ifthen->ctx->ac.builder;
+
+	/* Insert branch to the merge block from current block */
+	LLVMBuildBr(builder, ifthen->merge_block);
+
+	/*
+	 * Now patch in the various branch instructions.
+	 */
+
+	/* Insert the conditional branch instruction at the end of entry_block */
+	LLVMPositionBuilderAtEnd(builder, ifthen->entry_block);
+	if (ifthen->false_block) {
+		/* we have an else clause */
+		LLVMBuildCondBr(builder, ifthen->condition,
+				ifthen->true_block, ifthen->false_block);
+	}
+	else {
+		/* no else clause */
+		LLVMBuildCondBr(builder, ifthen->condition,
+				ifthen->true_block, ifthen->merge_block);
+	}
+
+	/* Resume building code at end of the ifthen->merge_block */
+	LLVMPositionBuilderAtEnd(builder, ifthen->merge_block);
+}
+
+
 static LLVMValueRef get_rel_patch_id(struct radv_shader_context *ctx)
 {
 	switch (ctx->stage) {
@@ -2555,97 +2647,6 @@  handle_ls_outputs_post(struct radv_shader_context *ctx)
 	}
 }
 
-struct ac_build_if_state
-{
-	struct radv_shader_context *ctx;
-	LLVMValueRef condition;
-	LLVMBasicBlockRef entry_block;
-	LLVMBasicBlockRef true_block;
-	LLVMBasicBlockRef false_block;
-	LLVMBasicBlockRef merge_block;
-};
-
-static LLVMBasicBlockRef
-ac_build_insert_new_block(struct radv_shader_context *ctx, const char *name)
-{
-	LLVMBasicBlockRef current_block;
-	LLVMBasicBlockRef next_block;
-	LLVMBasicBlockRef new_block;
-
-	/* get current basic block */
-	current_block = LLVMGetInsertBlock(ctx->ac.builder);
-
-	/* chqeck if there's another block after this one */
-	next_block = LLVMGetNextBasicBlock(current_block);
-	if (next_block) {
-		/* insert the new block before the next block */
-		new_block = LLVMInsertBasicBlockInContext(ctx->context, next_block, name);
-	}
-	else {
-		/* append new block after current block */
-		LLVMValueRef function = LLVMGetBasicBlockParent(current_block);
-		new_block = LLVMAppendBasicBlockInContext(ctx->context, function, name);
-	}
-	return new_block;
-}
-
-static void
-ac_nir_build_if(struct ac_build_if_state *ifthen,
-		struct radv_shader_context *ctx,
-		LLVMValueRef condition)
-{
-	LLVMBasicBlockRef block = LLVMGetInsertBlock(ctx->ac.builder);
-
-	memset(ifthen, 0, sizeof *ifthen);
-	ifthen->ctx = ctx;
-	ifthen->condition = condition;
-	ifthen->entry_block = block;
-
-	/* create endif/merge basic block for the phi functions */
-	ifthen->merge_block = ac_build_insert_new_block(ctx, "endif-block");
-
-	/* create/insert true_block before merge_block */
-	ifthen->true_block =
-		LLVMInsertBasicBlockInContext(ctx->context,
-					      ifthen->merge_block,
-					      "if-true-block");
-
-	/* successive code goes into the true block */
-	LLVMPositionBuilderAtEnd(ctx->ac.builder, ifthen->true_block);
-}
-
-/**
- * End a conditional.
- */
-static void
-ac_nir_build_endif(struct ac_build_if_state *ifthen)
-{
-	LLVMBuilderRef builder = ifthen->ctx->ac.builder;
-
-	/* Insert branch to the merge block from current block */
-	LLVMBuildBr(builder, ifthen->merge_block);
-
-	/*
-	 * Now patch in the various branch instructions.
-	 */
-
-	/* Insert the conditional branch instruction at the end of entry_block */
-	LLVMPositionBuilderAtEnd(builder, ifthen->entry_block);
-	if (ifthen->false_block) {
-		/* we have an else clause */
-		LLVMBuildCondBr(builder, ifthen->condition,
-				ifthen->true_block, ifthen->false_block);
-	}
-	else {
-		/* no else clause */
-		LLVMBuildCondBr(builder, ifthen->condition,
-				ifthen->true_block, ifthen->merge_block);
-	}
-
-	/* Resume building code at end of the ifthen->merge_block */
-	LLVMPositionBuilderAtEnd(builder, ifthen->merge_block);
-}
-
 static void
 write_tess_factors(struct radv_shader_context *ctx)
 {

Comments

Reviewed-by: Timothy Arceri <tarceri@itsqueeze.com>

On 11/05/18 17:38, Samuel Pitoiset wrote:
> These helpers will be needed for future work.
> 
> Signed-off-by: Samuel Pitoiset <samuel.pitoiset@gmail.com>
> ---
>   src/amd/vulkan/radv_nir_to_llvm.c | 183 +++++++++++++++---------------
>   1 file changed, 92 insertions(+), 91 deletions(-)
> 
> diff --git a/src/amd/vulkan/radv_nir_to_llvm.c b/src/amd/vulkan/radv_nir_to_llvm.c
> index cee3558215d..725fdb07a4d 100644
> --- a/src/amd/vulkan/radv_nir_to_llvm.c
> +++ b/src/amd/vulkan/radv_nir_to_llvm.c
> @@ -130,6 +130,98 @@ radv_shader_context_from_abi(struct ac_shader_abi *abi)
>   	return container_of(abi, ctx, abi);
>   }
>   
> +struct ac_build_if_state
> +{
> +	struct radv_shader_context *ctx;
> +	LLVMValueRef condition;
> +	LLVMBasicBlockRef entry_block;
> +	LLVMBasicBlockRef true_block;
> +	LLVMBasicBlockRef false_block;
> +	LLVMBasicBlockRef merge_block;
> +};
> +
> +static LLVMBasicBlockRef
> +ac_build_insert_new_block(struct radv_shader_context *ctx, const char *name)
> +{
> +	LLVMBasicBlockRef current_block;
> +	LLVMBasicBlockRef next_block;
> +	LLVMBasicBlockRef new_block;
> +
> +	/* get current basic block */
> +	current_block = LLVMGetInsertBlock(ctx->ac.builder);
> +
> +	/* chqeck if there's another block after this one */
> +	next_block = LLVMGetNextBasicBlock(current_block);
> +	if (next_block) {
> +		/* insert the new block before the next block */
> +		new_block = LLVMInsertBasicBlockInContext(ctx->context, next_block, name);
> +	}
> +	else {
> +		/* append new block after current block */
> +		LLVMValueRef function = LLVMGetBasicBlockParent(current_block);
> +		new_block = LLVMAppendBasicBlockInContext(ctx->context, function, name);
> +	}
> +	return new_block;
> +}
> +
> +static void
> +ac_nir_build_if(struct ac_build_if_state *ifthen,
> +		struct radv_shader_context *ctx,
> +		LLVMValueRef condition)
> +{
> +	LLVMBasicBlockRef block = LLVMGetInsertBlock(ctx->ac.builder);
> +
> +	memset(ifthen, 0, sizeof *ifthen);
> +	ifthen->ctx = ctx;
> +	ifthen->condition = condition;
> +	ifthen->entry_block = block;
> +
> +	/* create endif/merge basic block for the phi functions */
> +	ifthen->merge_block = ac_build_insert_new_block(ctx, "endif-block");
> +
> +	/* create/insert true_block before merge_block */
> +	ifthen->true_block =
> +		LLVMInsertBasicBlockInContext(ctx->context,
> +					      ifthen->merge_block,
> +					      "if-true-block");
> +
> +	/* successive code goes into the true block */
> +	LLVMPositionBuilderAtEnd(ctx->ac.builder, ifthen->true_block);
> +}
> +
> +/**
> + * End a conditional.
> + */
> +static void
> +ac_nir_build_endif(struct ac_build_if_state *ifthen)
> +{
> +	LLVMBuilderRef builder = ifthen->ctx->ac.builder;
> +
> +	/* Insert branch to the merge block from current block */
> +	LLVMBuildBr(builder, ifthen->merge_block);
> +
> +	/*
> +	 * Now patch in the various branch instructions.
> +	 */
> +
> +	/* Insert the conditional branch instruction at the end of entry_block */
> +	LLVMPositionBuilderAtEnd(builder, ifthen->entry_block);
> +	if (ifthen->false_block) {
> +		/* we have an else clause */
> +		LLVMBuildCondBr(builder, ifthen->condition,
> +				ifthen->true_block, ifthen->false_block);
> +	}
> +	else {
> +		/* no else clause */
> +		LLVMBuildCondBr(builder, ifthen->condition,
> +				ifthen->true_block, ifthen->merge_block);
> +	}
> +
> +	/* Resume building code at end of the ifthen->merge_block */
> +	LLVMPositionBuilderAtEnd(builder, ifthen->merge_block);
> +}
> +
> +
>   static LLVMValueRef get_rel_patch_id(struct radv_shader_context *ctx)
>   {
>   	switch (ctx->stage) {
> @@ -2555,97 +2647,6 @@ handle_ls_outputs_post(struct radv_shader_context *ctx)
>   	}
>   }
>   
> -struct ac_build_if_state
> -{
> -	struct radv_shader_context *ctx;
> -	LLVMValueRef condition;
> -	LLVMBasicBlockRef entry_block;
> -	LLVMBasicBlockRef true_block;
> -	LLVMBasicBlockRef false_block;
> -	LLVMBasicBlockRef merge_block;
> -};
> -
> -static LLVMBasicBlockRef
> -ac_build_insert_new_block(struct radv_shader_context *ctx, const char *name)
> -{
> -	LLVMBasicBlockRef current_block;
> -	LLVMBasicBlockRef next_block;
> -	LLVMBasicBlockRef new_block;
> -
> -	/* get current basic block */
> -	current_block = LLVMGetInsertBlock(ctx->ac.builder);
> -
> -	/* chqeck if there's another block after this one */
> -	next_block = LLVMGetNextBasicBlock(current_block);
> -	if (next_block) {
> -		/* insert the new block before the next block */
> -		new_block = LLVMInsertBasicBlockInContext(ctx->context, next_block, name);
> -	}
> -	else {
> -		/* append new block after current block */
> -		LLVMValueRef function = LLVMGetBasicBlockParent(current_block);
> -		new_block = LLVMAppendBasicBlockInContext(ctx->context, function, name);
> -	}
> -	return new_block;
> -}
> -
> -static void
> -ac_nir_build_if(struct ac_build_if_state *ifthen,
> -		struct radv_shader_context *ctx,
> -		LLVMValueRef condition)
> -{
> -	LLVMBasicBlockRef block = LLVMGetInsertBlock(ctx->ac.builder);
> -
> -	memset(ifthen, 0, sizeof *ifthen);
> -	ifthen->ctx = ctx;
> -	ifthen->condition = condition;
> -	ifthen->entry_block = block;
> -
> -	/* create endif/merge basic block for the phi functions */
> -	ifthen->merge_block = ac_build_insert_new_block(ctx, "endif-block");
> -
> -	/* create/insert true_block before merge_block */
> -	ifthen->true_block =
> -		LLVMInsertBasicBlockInContext(ctx->context,
> -					      ifthen->merge_block,
> -					      "if-true-block");
> -
> -	/* successive code goes into the true block */
> -	LLVMPositionBuilderAtEnd(ctx->ac.builder, ifthen->true_block);
> -}
> -
> -/**
> - * End a conditional.
> - */
> -static void
> -ac_nir_build_endif(struct ac_build_if_state *ifthen)
> -{
> -	LLVMBuilderRef builder = ifthen->ctx->ac.builder;
> -
> -	/* Insert branch to the merge block from current block */
> -	LLVMBuildBr(builder, ifthen->merge_block);
> -
> -	/*
> -	 * Now patch in the various branch instructions.
> -	 */
> -
> -	/* Insert the conditional branch instruction at the end of entry_block */
> -	LLVMPositionBuilderAtEnd(builder, ifthen->entry_block);
> -	if (ifthen->false_block) {
> -		/* we have an else clause */
> -		LLVMBuildCondBr(builder, ifthen->condition,
> -				ifthen->true_block, ifthen->false_block);
> -	}
> -	else {
> -		/* no else clause */
> -		LLVMBuildCondBr(builder, ifthen->condition,
> -				ifthen->true_block, ifthen->merge_block);
> -	}
> -
> -	/* Resume building code at end of the ifthen->merge_block */
> -	LLVMPositionBuilderAtEnd(builder, ifthen->merge_block);
> -}
> -
>   static void
>   write_tess_factors(struct radv_shader_context *ctx)
>   {
>