radeonsi: fold some shader context initialization to si_llvm_context_init
authorMarek Olšák <marek.olsak@amd.com>
Sat, 12 Nov 2016 21:51:41 +0000 (22:51 +0100)
committerMarek Olšák <marek.olsak@amd.com>
Tue, 15 Nov 2016 18:17:56 +0000 (19:17 +0100)
Reviewed-by: Nicolai Hähnle <nicolai.haehnle@amd.com>
src/gallium/drivers/radeonsi/si_shader.c
src/gallium/drivers/radeonsi/si_shader_internal.h
src/gallium/drivers/radeonsi/si_shader_tgsi_setup.c

index 0410a3288d59e8e4b04342decd740685c8e0a5fe..917e148429988fdd10b0c207e4e04f66a2ef0476 100644 (file)
@@ -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;
index 55b70e6bf338da7d1612c6570bcb262e129bc189..8d6a40b1644e10cc3134960c31522ca1785eecd7 100644 (file)
@@ -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);
 
index b37f7e6401dbd9b1c40099f50c74b0ac93d0c252..624a167c7d51f3e54b29078a613a7a6bd3644f0f 100644 (file)
@@ -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,