From 171e349782ab6b688c397f6bb76f105ac18a752a Mon Sep 17 00:00:00 2001 From: =?utf8?q?Marek=20Ol=C5=A1=C3=A1k?= Date: Sat, 12 Nov 2016 22:51:41 +0100 Subject: [PATCH] radeonsi: fold some shader context initialization to si_llvm_context_init MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Reviewed-by: Nicolai Hähnle --- src/gallium/drivers/radeonsi/si_shader.c | 25 +--------------- .../drivers/radeonsi/si_shader_internal.h | 4 ++- .../drivers/radeonsi/si_shader_tgsi_setup.c | 30 ++++++++++++++++--- 3 files changed, 30 insertions(+), 29 deletions(-) diff --git a/src/gallium/drivers/radeonsi/si_shader.c b/src/gallium/drivers/radeonsi/si_shader.c index 0410a3288d5..917e1484299 100644 --- a/src/gallium/drivers/radeonsi/si_shader.c +++ b/src/gallium/drivers/radeonsi/si_shader.c @@ -6285,32 +6285,9 @@ static void si_init_shader_ctx(struct si_shader_context *ctx, struct lp_build_tgsi_context *bld_base; struct lp_build_tgsi_action tmpl = {}; - memset(ctx, 0, sizeof(*ctx)); - si_llvm_context_init( - ctx, "amdgcn--", + si_llvm_context_init(ctx, sscreen, shader, tm, (shader && shader->selector) ? &shader->selector->info : NULL, (shader && shader->selector) ? shader->selector->tokens : NULL); - si_shader_context_init_alu(&ctx->soa.bld_base); - ctx->tm = tm; - ctx->screen = sscreen; - if (shader && shader->selector) - ctx->type = shader->selector->info.processor; - else - ctx->type = -1; - ctx->shader = shader; - - ctx->voidt = LLVMVoidTypeInContext(ctx->gallivm.context); - ctx->i1 = LLVMInt1TypeInContext(ctx->gallivm.context); - ctx->i8 = LLVMInt8TypeInContext(ctx->gallivm.context); - ctx->i32 = LLVMInt32TypeInContext(ctx->gallivm.context); - ctx->i64 = LLVMInt64TypeInContext(ctx->gallivm.context); - ctx->i128 = LLVMIntTypeInContext(ctx->gallivm.context, 128); - ctx->f32 = LLVMFloatTypeInContext(ctx->gallivm.context); - ctx->v16i8 = LLVMVectorType(ctx->i8, 16); - ctx->v2i32 = LLVMVectorType(ctx->i32, 2); - ctx->v4i32 = LLVMVectorType(ctx->i32, 4); - ctx->v4f32 = LLVMVectorType(ctx->f32, 4); - ctx->v8i32 = LLVMVectorType(ctx->i32, 8); bld_base = &ctx->soa.bld_base; bld_base->emit_fetch_funcs[TGSI_FILE_CONSTANT] = fetch_constant; diff --git a/src/gallium/drivers/radeonsi/si_shader_internal.h b/src/gallium/drivers/radeonsi/si_shader_internal.h index 55b70e6bf33..8d6a40b1644 100644 --- a/src/gallium/drivers/radeonsi/si_shader_internal.h +++ b/src/gallium/drivers/radeonsi/si_shader_internal.h @@ -178,7 +178,9 @@ LLVMValueRef si_llvm_bound_index(struct si_shader_context *ctx, unsigned num); void si_llvm_context_init(struct si_shader_context *ctx, - const char *triple, + struct si_screen *sscreen, + struct si_shader *shader, + LLVMTargetMachineRef tm, const struct tgsi_shader_info *info, const struct tgsi_token *tokens); diff --git a/src/gallium/drivers/radeonsi/si_shader_tgsi_setup.c b/src/gallium/drivers/radeonsi/si_shader_tgsi_setup.c index b37f7e6401d..624a167c7d5 100644 --- a/src/gallium/drivers/radeonsi/si_shader_tgsi_setup.c +++ b/src/gallium/drivers/radeonsi/si_shader_tgsi_setup.c @@ -1222,7 +1222,10 @@ static void emit_immediate(struct lp_build_tgsi_context *bld_base, ctx->soa.num_immediates++; } -void si_llvm_context_init(struct si_shader_context *ctx, const char *triple, +void si_llvm_context_init(struct si_shader_context *ctx, + struct si_screen *sscreen, + struct si_shader *shader, + LLVMTargetMachineRef tm, const struct tgsi_shader_info *info, const struct tgsi_token *tokens) { @@ -1233,12 +1236,16 @@ void si_llvm_context_init(struct si_shader_context *ctx, const char *triple, * This should be enough for us to be able to pass our gallivm struct to the * helper functions in the gallivm module. */ - memset(&ctx->gallivm, 0, sizeof (ctx->gallivm)); - memset(&ctx->soa, 0, sizeof(ctx->soa)); + memset(ctx, 0, sizeof(*ctx)); + ctx->shader = shader; + ctx->screen = sscreen; + ctx->tm = tm; + ctx->type = info ? info->processor : -1; + ctx->gallivm.context = LLVMContextCreate(); ctx->gallivm.module = LLVMModuleCreateWithNameInContext("tgsi", ctx->gallivm.context); - LLVMSetTarget(ctx->gallivm.module, triple); + LLVMSetTarget(ctx->gallivm.module, "amdgcn--"); ctx->gallivm.builder = LLVMCreateBuilderInContext(ctx->gallivm.context); struct lp_build_tgsi_context *bld_base = &ctx->soa.bld_base; @@ -1301,6 +1308,21 @@ void si_llvm_context_init(struct si_shader_context *ctx, const char *triple, bld_base->op_actions[TGSI_OPCODE_ELSE].emit = else_emit; bld_base->op_actions[TGSI_OPCODE_ENDIF].emit = endif_emit; bld_base->op_actions[TGSI_OPCODE_ENDLOOP].emit = endloop_emit; + + si_shader_context_init_alu(&ctx->soa.bld_base); + + ctx->voidt = LLVMVoidTypeInContext(ctx->gallivm.context); + ctx->i1 = LLVMInt1TypeInContext(ctx->gallivm.context); + ctx->i8 = LLVMInt8TypeInContext(ctx->gallivm.context); + ctx->i32 = LLVMInt32TypeInContext(ctx->gallivm.context); + ctx->i64 = LLVMInt64TypeInContext(ctx->gallivm.context); + ctx->i128 = LLVMIntTypeInContext(ctx->gallivm.context, 128); + ctx->f32 = LLVMFloatTypeInContext(ctx->gallivm.context); + ctx->v16i8 = LLVMVectorType(ctx->i8, 16); + ctx->v2i32 = LLVMVectorType(ctx->i32, 2); + ctx->v4i32 = LLVMVectorType(ctx->i32, 4); + ctx->v4f32 = LLVMVectorType(ctx->f32, 4); + ctx->v8i32 = LLVMVectorType(ctx->i32, 8); } void si_llvm_create_func(struct si_shader_context *ctx, -- 2.30.2