aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorNicolai Hähnle <[email protected]>2016-09-28 18:59:42 +0200
committerNicolai Hähnle <[email protected]>2016-10-04 16:39:18 +0200
commitb0d50e157de1093ddc5b7a9939a04b17a669073d (patch)
treef72708f1e6e091bb826568055af70c024cda6ec6 /src
parent89e9de2ea69c9b4c0022471d314c2a4aa6c89c7a (diff)
gallium/radeon: simplify if/else/endif blocks
In particular, we no longer emit an else block when there is no ELSE instruction. Reviewed-by: Marek Olšák <[email protected]>
Diffstat (limited to 'src')
-rw-r--r--src/gallium/drivers/radeon/radeon_llvm.h4
-rw-r--r--src/gallium/drivers/radeon/radeon_setup_tgsi_llvm.c39
2 files changed, 18 insertions, 25 deletions
diff --git a/src/gallium/drivers/radeon/radeon_llvm.h b/src/gallium/drivers/radeon/radeon_llvm.h
index f508d3230cc..58193dbcc24 100644
--- a/src/gallium/drivers/radeon/radeon_llvm.h
+++ b/src/gallium/drivers/radeon/radeon_llvm.h
@@ -41,9 +41,7 @@
#define RADEON_LLVM_MAX_SYSTEM_VALUES 4
struct radeon_llvm_branch {
- LLVMBasicBlockRef endif_block;
- LLVMBasicBlockRef if_block;
- LLVMBasicBlockRef else_block;
+ LLVMBasicBlockRef next_block;
unsigned has_else;
};
diff --git a/src/gallium/drivers/radeon/radeon_setup_tgsi_llvm.c b/src/gallium/drivers/radeon/radeon_setup_tgsi_llvm.c
index 2f6b7e27971..6cae858d50e 100644
--- a/src/gallium/drivers/radeon/radeon_setup_tgsi_llvm.c
+++ b/src/gallium/drivers/radeon/radeon_setup_tgsi_llvm.c
@@ -878,11 +878,17 @@ static void else_emit(const struct lp_build_tgsi_action *action,
struct radeon_llvm_context *ctx = radeon_llvm_context(bld_base);
struct gallivm_state *gallivm = bld_base->base.gallivm;
struct radeon_llvm_branch *current_branch = get_current_branch(ctx);
+ LLVMBasicBlockRef endif_block;
+
+ endif_block = LLVMAppendBasicBlockInContext(gallivm->context,
+ ctx->main_fn, "ENDIF");
+ emit_default_branch(gallivm->builder, endif_block);
- emit_default_branch(gallivm->builder, current_branch->endif_block);
current_branch->has_else = 1;
- LLVMPositionBuilderAtEnd(gallivm->builder, current_branch->else_block);
- set_basicblock_name(current_branch->else_block, "else", bld_base->pc);
+ LLVMPositionBuilderAtEnd(gallivm->builder, current_branch->next_block);
+ set_basicblock_name(current_branch->next_block, "else", bld_base->pc);
+
+ current_branch->next_block = endif_block;
}
static void endif_emit(const struct lp_build_tgsi_action *action,
@@ -893,17 +899,10 @@ static void endif_emit(const struct lp_build_tgsi_action *action,
struct gallivm_state *gallivm = bld_base->base.gallivm;
struct radeon_llvm_branch *current_branch = get_current_branch(ctx);
- emit_default_branch(gallivm->builder, current_branch->endif_block);
+ emit_default_branch(gallivm->builder, current_branch->next_block);
+ LLVMPositionBuilderAtEnd(gallivm->builder, current_branch->next_block);
+ set_basicblock_name(current_branch->next_block, "endif", bld_base->pc);
- /* Need to fixup an empty else block if there was no ELSE opcode. */
- if (!LLVMGetBasicBlockTerminator(current_branch->else_block)) {
- LLVMPositionBuilderAtEnd(gallivm->builder, current_branch->else_block);
- LLVMBuildBr(gallivm->builder, current_branch->endif_block);
- set_basicblock_name(current_branch->else_block, "empty_else", bld_base->pc);
- }
-
- LLVMPositionBuilderAtEnd(gallivm->builder, current_branch->endif_block);
- set_basicblock_name(current_branch->endif_block, "endif", bld_base->pc);
ctx->branch_depth--;
}
@@ -929,14 +928,12 @@ static void if_cond_emit(const struct lp_build_tgsi_action *action,
{
struct radeon_llvm_context *ctx = radeon_llvm_context(bld_base);
struct gallivm_state *gallivm = bld_base->base.gallivm;
- LLVMBasicBlockRef if_block, else_block, endif_block;
+ LLVMBasicBlockRef if_block, else_block;
- endif_block = LLVMAppendBasicBlockInContext(gallivm->context,
- ctx->main_fn, "ENDIF");
+ else_block = LLVMAppendBasicBlockInContext(gallivm->context,
+ ctx->main_fn, "ELSE");
if_block = LLVMInsertBasicBlockInContext(gallivm->context,
- endif_block, "IF");
- else_block = LLVMInsertBasicBlockInContext(gallivm->context,
- endif_block, "ELSE");
+ else_block, "IF");
set_basicblock_name(if_block, "if", bld_base->pc);
LLVMBuildCondBr(gallivm->builder, cond, if_block, else_block);
LLVMPositionBuilderAtEnd(gallivm->builder, if_block);
@@ -953,9 +950,7 @@ static void if_cond_emit(const struct lp_build_tgsi_action *action,
ctx->branch_depth_max = new_max;
}
- ctx->branch[ctx->branch_depth - 1].endif_block = endif_block;
- ctx->branch[ctx->branch_depth - 1].if_block = if_block;
- ctx->branch[ctx->branch_depth - 1].else_block = else_block;
+ ctx->branch[ctx->branch_depth - 1].next_block = else_block;
ctx->branch[ctx->branch_depth - 1].has_else = 0;
}