From: Nicolai Hähnle <nicolai.haeh...@amd.com> This changes the order of basic blocks to be equal to the order of code in the original TGSI, which is nice for making sense of shader dumps. --- .../drivers/radeon/radeon_setup_tgsi_llvm.c | 34 +++++++++++++++------- 1 file changed, 24 insertions(+), 10 deletions(-)
diff --git a/src/gallium/drivers/radeon/radeon_setup_tgsi_llvm.c b/src/gallium/drivers/radeon/radeon_setup_tgsi_llvm.c index 2f100bd..6a10af3 100644 --- a/src/gallium/drivers/radeon/radeon_setup_tgsi_llvm.c +++ b/src/gallium/drivers/radeon/radeon_setup_tgsi_llvm.c @@ -836,41 +836,58 @@ static void set_basicblock_name(LLVMBasicBlockRef bb, const char *base, int pc) { char buf[32]; /* Subtract 1 so that the number shown is that of the corresponding * opcode in the TGSI dump, e.g. an if block has the same suffix as * the instruction number of the corresponding TGSI IF. */ snprintf(buf, sizeof(buf), "%s%d", base, pc - 1); LLVMSetValueName(LLVMBasicBlockAsValue(bb), buf); } +/* Append a basic block at the level of the parent flow. + */ +static LLVMBasicBlockRef append_basic_block(struct radeon_llvm_context *ctx, + const char *name) +{ + struct gallivm_state *gallivm = &ctx->gallivm; + + assert(ctx->flow_depth >= 1); + + if (ctx->flow_depth >= 2) { + struct radeon_llvm_flow *flow = &ctx->flow[ctx->flow_depth - 2]; + + return LLVMInsertBasicBlockInContext(gallivm->context, + flow->next_block, name); + } + + return LLVMAppendBasicBlockInContext(gallivm->context, ctx->main_fn, name); +} + /* Emit a branch to the given default target for the current block if * applicable -- that is, if the current block does not already contain a * branch from a break or continue. */ static void emit_default_branch(LLVMBuilderRef builder, LLVMBasicBlockRef target) { if (!LLVMGetBasicBlockTerminator(LLVMGetInsertBlock(builder))) LLVMBuildBr(builder, target); } static void bgnloop_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_flow *flow = push_flow(ctx); - flow->next_block = LLVMAppendBasicBlockInContext(gallivm->context, - ctx->main_fn, "ENDLOOP"); - flow->loop_entry_block = LLVMInsertBasicBlockInContext(gallivm->context, - flow->next_block, "LOOP"); + flow->loop_entry_block = append_basic_block(ctx, "LOOP"); + flow->next_block = append_basic_block(ctx, "ENDLOOP"); set_basicblock_name(flow->loop_entry_block, "loop", bld_base->pc); LLVMBuildBr(gallivm->builder, flow->loop_entry_block); LLVMPositionBuilderAtEnd(gallivm->builder, flow->loop_entry_block); } static void brk_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); @@ -895,22 +912,21 @@ 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_flow *current_branch = get_current_flow(ctx); LLVMBasicBlockRef endif_block; assert(!current_branch->loop_entry_block); - endif_block = LLVMAppendBasicBlockInContext(gallivm->context, - ctx->main_fn, "ENDIF"); + endif_block = append_basic_block(ctx, "ENDIF"); emit_default_branch(gallivm->builder, endif_block); 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, @@ -949,24 +965,22 @@ static void endloop_emit(const struct lp_build_tgsi_action *action, 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; struct radeon_llvm_flow *flow = push_flow(ctx); LLVMBasicBlockRef if_block; - flow->next_block = LLVMAppendBasicBlockInContext(gallivm->context, - ctx->main_fn, "ELSE"); - if_block = LLVMInsertBasicBlockInContext(gallivm->context, - flow->next_block, "IF"); + if_block = append_basic_block(ctx, "IF"); + flow->next_block = append_basic_block(ctx, "ELSE"); set_basicblock_name(if_block, "if", bld_base->pc); LLVMBuildCondBr(gallivm->builder, cond, if_block, flow->next_block); LLVMPositionBuilderAtEnd(gallivm->builder, if_block); } 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; -- 2.7.4 _______________________________________________ mesa-dev mailing list mesa-dev@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/mesa-dev