summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTimothy Arceri <[email protected]>2018-03-07 11:10:54 +1100
committerJuan A. Suarez Romero <[email protected]>2018-04-12 21:49:29 +0200
commitc9e2de3398edccea06b62a4d1c3d11456b97f6c3 (patch)
tree3dcb95618499395da3bcb3111881098bff1cdb60
parent7a02062da57f41fac4f056e7b93ed019997d4087 (diff)
ac: make use of if/loop build helpers
These helpers insert the basic block in the same order as they appear in NIR making it easier to follow LLVM IR dumps. The helpers also insert more useful labels onto the blocks. TGSI use the line number of the corresponding opcode in the TGSI dump as the label id, here we use the corresponding block index from NIR. Reviewed-by: Marek Olšák <[email protected]> (cherry picked from commit 99cdc019bf6fe11c135b7544ef6daf4ac964fa24)
-rw-r--r--src/amd/common/ac_nir_to_llvm.c60
1 files changed, 18 insertions, 42 deletions
diff --git a/src/amd/common/ac_nir_to_llvm.c b/src/amd/common/ac_nir_to_llvm.c
index 9589470846a..3e6bc5ec4d7 100644
--- a/src/amd/common/ac_nir_to_llvm.c
+++ b/src/amd/common/ac_nir_to_llvm.c
@@ -5190,17 +5190,15 @@ static void visit_ssa_undef(struct ac_nir_context *ctx,
_mesa_hash_table_insert(ctx->defs, &instr->def, undef);
}
-static void visit_jump(struct ac_nir_context *ctx,
+static void visit_jump(struct ac_llvm_context *ctx,
const nir_jump_instr *instr)
{
switch (instr->type) {
case nir_jump_break:
- LLVMBuildBr(ctx->ac.builder, ctx->break_block);
- LLVMClearInsertionPosition(ctx->ac.builder);
+ ac_build_break(ctx);
break;
case nir_jump_continue:
- LLVMBuildBr(ctx->ac.builder, ctx->continue_block);
- LLVMClearInsertionPosition(ctx->ac.builder);
+ ac_build_continue(ctx);
break;
default:
fprintf(stderr, "Unknown NIR jump instr: ");
@@ -5238,7 +5236,7 @@ static void visit_block(struct ac_nir_context *ctx, nir_block *block)
visit_ssa_undef(ctx, nir_instr_as_ssa_undef(instr));
break;
case nir_instr_type_jump:
- visit_jump(ctx, nir_instr_as_jump(instr));
+ visit_jump(&ctx->ac, nir_instr_as_jump(instr));
break;
default:
fprintf(stderr, "Unknown NIR instr type: ");
@@ -5255,56 +5253,34 @@ static void visit_if(struct ac_nir_context *ctx, nir_if *if_stmt)
{
LLVMValueRef value = get_src(ctx, if_stmt->condition);
- LLVMValueRef fn = LLVMGetBasicBlockParent(LLVMGetInsertBlock(ctx->ac.builder));
- LLVMBasicBlockRef merge_block =
- LLVMAppendBasicBlockInContext(ctx->ac.context, fn, "");
- LLVMBasicBlockRef if_block =
- LLVMAppendBasicBlockInContext(ctx->ac.context, fn, "");
- LLVMBasicBlockRef else_block = merge_block;
- if (!exec_list_is_empty(&if_stmt->else_list))
- else_block = LLVMAppendBasicBlockInContext(
- ctx->ac.context, fn, "");
-
- LLVMValueRef cond = LLVMBuildICmp(ctx->ac.builder, LLVMIntNE, value,
- ctx->ac.i32_0, "");
- LLVMBuildCondBr(ctx->ac.builder, cond, if_block, else_block);
-
- LLVMPositionBuilderAtEnd(ctx->ac.builder, if_block);
+ nir_block *then_block =
+ (nir_block *) exec_list_get_head(&if_stmt->then_list);
+
+ ac_build_uif(&ctx->ac, value, then_block->index);
+
visit_cf_list(ctx, &if_stmt->then_list);
- if (LLVMGetInsertBlock(ctx->ac.builder))
- LLVMBuildBr(ctx->ac.builder, merge_block);
if (!exec_list_is_empty(&if_stmt->else_list)) {
- LLVMPositionBuilderAtEnd(ctx->ac.builder, else_block);
+ nir_block *else_block =
+ (nir_block *) exec_list_get_head(&if_stmt->else_list);
+
+ ac_build_else(&ctx->ac, else_block->index);
visit_cf_list(ctx, &if_stmt->else_list);
- if (LLVMGetInsertBlock(ctx->ac.builder))
- LLVMBuildBr(ctx->ac.builder, merge_block);
}
- LLVMPositionBuilderAtEnd(ctx->ac.builder, merge_block);
+ ac_build_endif(&ctx->ac, then_block->index);
}
static void visit_loop(struct ac_nir_context *ctx, nir_loop *loop)
{
- LLVMValueRef fn = LLVMGetBasicBlockParent(LLVMGetInsertBlock(ctx->ac.builder));
- LLVMBasicBlockRef continue_parent = ctx->continue_block;
- LLVMBasicBlockRef break_parent = ctx->break_block;
+ nir_block *first_loop_block =
+ (nir_block *) exec_list_get_head(&loop->body);
- ctx->continue_block =
- LLVMAppendBasicBlockInContext(ctx->ac.context, fn, "");
- ctx->break_block =
- LLVMAppendBasicBlockInContext(ctx->ac.context, fn, "");
+ ac_build_bgnloop(&ctx->ac, first_loop_block->index);
- LLVMBuildBr(ctx->ac.builder, ctx->continue_block);
- LLVMPositionBuilderAtEnd(ctx->ac.builder, ctx->continue_block);
visit_cf_list(ctx, &loop->body);
- if (LLVMGetInsertBlock(ctx->ac.builder))
- LLVMBuildBr(ctx->ac.builder, ctx->continue_block);
- LLVMPositionBuilderAtEnd(ctx->ac.builder, ctx->break_block);
-
- ctx->continue_block = continue_parent;
- ctx->break_block = break_parent;
+ ac_build_endloop(&ctx->ac, first_loop_block->index);
}
static void visit_cf_list(struct ac_nir_context *ctx,