From: Nicolai Hähnle <[email protected]>

---
 src/gallium/drivers/radeon/radeon_setup_tgsi_llvm.c | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/src/gallium/drivers/radeon/radeon_setup_tgsi_llvm.c 
b/src/gallium/drivers/radeon/radeon_setup_tgsi_llvm.c
index 201bed8..2f6b7e2 100644
--- a/src/gallium/drivers/radeon/radeon_setup_tgsi_llvm.c
+++ b/src/gallium/drivers/radeon/radeon_setup_tgsi_llvm.c
@@ -789,20 +789,31 @@ void radeon_llvm_emit_store(struct lp_build_tgsi_context 
*bld_base,
                                val2 = LLVMBuildExtractElement(builder, ptr,
                                                                
bld_base->uint_bld.one, "");
 
                                LLVMBuildStore(builder, bitcast(bld_base, 
TGSI_TYPE_FLOAT, value), temp_ptr);
                                LLVMBuildStore(builder, bitcast(bld_base, 
TGSI_TYPE_FLOAT, val2), temp_ptr2);
                        }
                }
        }
 }
 
+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);
+}
+
 /* 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);
 }
 
@@ -811,20 +822,21 @@ static void bgnloop_emit(const struct 
lp_build_tgsi_action *action,
                         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;
        LLVMBasicBlockRef loop_block;
        LLVMBasicBlockRef endloop_block;
        endloop_block = LLVMAppendBasicBlockInContext(gallivm->context,
                                                ctx->main_fn, "ENDLOOP");
        loop_block = LLVMInsertBasicBlockInContext(gallivm->context,
                                                endloop_block, "LOOP");
+       set_basicblock_name(loop_block, "loop", bld_base->pc);
        LLVMBuildBr(gallivm->builder, loop_block);
        LLVMPositionBuilderAtEnd(gallivm->builder, loop_block);
 
        if (++ctx->loop_depth > ctx->loop_depth_max) {
                unsigned new_max = ctx->loop_depth_max << 1;
 
                if (!new_max)
                        new_max = RADEON_LLVM_INITIAL_CF_DEPTH;
 
                ctx->loop = REALLOC(ctx->loop, ctx->loop_depth_max *
@@ -863,71 +875,76 @@ 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);
 
        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);
 }
 
 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);
 
        /* 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);
 
        emit_default_branch(gallivm->builder, current_loop->loop_block);
 
        LLVMPositionBuilderAtEnd(gallivm->builder, current_loop->endloop_block);
+       set_basicblock_name(current_loop->endloop_block, "endloop", 
bld_base->pc);
        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;
 
        endif_block = LLVMAppendBasicBlockInContext(gallivm->context,
                                                ctx->main_fn, "ENDIF");
        if_block = LLVMInsertBasicBlockInContext(gallivm->context,
                                                endif_block, "IF");
        else_block = LLVMInsertBasicBlockInContext(gallivm->context,
                                                endif_block, "ELSE");
+       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 *
-- 
2.7.4

_______________________________________________
mesa-dev mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/mesa-dev

Reply via email to