[Mesa-dev] [PATCH 3/7] gallium/radeon: simplify if/else/endif blocks
Nicolai Hähnle
nhaehnle at gmail.com
Thu Sep 29 13:15:53 UTC 2016
From: Nicolai Hähnle <nicolai.haehnle at amd.com>
In particular, we no longer emit an else block when there is no ELSE
instruction.
---
src/gallium/drivers/radeon/radeon_llvm.h | 4 +--
.../drivers/radeon/radeon_setup_tgsi_llvm.c | 39 ++++++++++------------
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 f508d32..58193db 100644
--- a/src/gallium/drivers/radeon/radeon_llvm.h
+++ b/src/gallium/drivers/radeon/radeon_llvm.h
@@ -34,23 +34,21 @@
#define RADEON_LLVM_MAX_INPUT_SLOTS 32
#define RADEON_LLVM_MAX_INPUTS 32 * 4
#define RADEON_LLVM_MAX_OUTPUTS 32 * 4
#define RADEON_LLVM_INITIAL_CF_DEPTH 4
#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;
};
struct radeon_llvm_loop {
LLVMBasicBlockRef loop_block;
LLVMBasicBlockRef endloop_block;
};
struct radeon_llvm_context {
struct lp_build_tgsi_soa_context soa;
diff --git a/src/gallium/drivers/radeon/radeon_setup_tgsi_llvm.c b/src/gallium/drivers/radeon/radeon_setup_tgsi_llvm.c
index 2f6b7e2..6cae858 100644
--- a/src/gallium/drivers/radeon/radeon_setup_tgsi_llvm.c
+++ b/src/gallium/drivers/radeon/radeon_setup_tgsi_llvm.c
@@ -871,46 +871,45 @@ static void cont_emit(const struct lp_build_tgsi_action *action,
LLVMBuildBr(gallivm->builder, current_loop->loop_block);
}
static void else_emit(const struct lp_build_tgsi_action *action,
struct lp_build_tgsi_context *bld_base,
struct lp_build_emit_data *emit_data)
{
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,
struct lp_build_tgsi_context *bld_base,
struct lp_build_emit_data *emit_data)
{
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);
- 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--;
}
static void endloop_emit(const struct lp_build_tgsi_action *action,
struct lp_build_tgsi_context *bld_base,
struct lp_build_emit_data *emit_data)
{
struct radeon_llvm_context *ctx = radeon_llvm_context(bld_base);
struct gallivm_state *gallivm = bld_base->base.gallivm;
struct radeon_llvm_loop *current_loop = get_current_loop(ctx);
@@ -922,47 +921,43 @@ static void endloop_emit(const struct lp_build_tgsi_action *action,
ctx->loop_depth--;
}
static void if_cond_emit(const struct lp_build_tgsi_action *action,
struct lp_build_tgsi_context *bld_base,
struct lp_build_emit_data *emit_data,
LLVMValueRef cond)
{
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);
if (++ctx->branch_depth > ctx->branch_depth_max) {
unsigned new_max = ctx->branch_depth_max << 1;
if (!new_max)
new_max = RADEON_LLVM_INITIAL_CF_DEPTH;
ctx->branch = REALLOC(ctx->branch, ctx->branch_depth_max *
sizeof(ctx->branch[0]),
new_max * sizeof(ctx->branch[0]));
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;
}
static void if_emit(const struct lp_build_tgsi_action *action,
struct lp_build_tgsi_context *bld_base,
struct lp_build_emit_data *emit_data)
{
struct gallivm_state *gallivm = bld_base->base.gallivm;
LLVMValueRef cond;
--
2.7.4
More information about the mesa-dev
mailing list