ac: move all LLVM module initialization into ac_create_module
This removes some ugly code around module initialization. Reviewed-by: Dave Airlie <airlied@redhat.com>
This commit is contained in:
@@ -61,6 +61,16 @@ bool ac_llvm_is_function(LLVMValueRef v)
|
|||||||
return LLVMGetValueKind(v) == LLVMFunctionValueKind;
|
return LLVMGetValueKind(v) == LLVMFunctionValueKind;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
LLVMModuleRef ac_create_module(LLVMTargetMachineRef tm, LLVMContextRef ctx)
|
||||||
|
{
|
||||||
|
llvm::TargetMachine *TM = reinterpret_cast<llvm::TargetMachine*>(tm);
|
||||||
|
LLVMModuleRef module = LLVMModuleCreateWithNameInContext("mesa-shader", ctx);
|
||||||
|
|
||||||
|
llvm::unwrap(module)->setTargetTriple(TM->getTargetTriple().getTriple());
|
||||||
|
llvm::unwrap(module)->setDataLayout(TM->createDataLayout());
|
||||||
|
return module;
|
||||||
|
}
|
||||||
|
|
||||||
LLVMBuilderRef ac_create_builder(LLVMContextRef ctx,
|
LLVMBuilderRef ac_create_builder(LLVMContextRef ctx,
|
||||||
enum ac_float_mode float_mode)
|
enum ac_float_mode float_mode)
|
||||||
{
|
{
|
||||||
|
@@ -83,6 +83,7 @@ void ac_dump_module(LLVMModuleRef module);
|
|||||||
|
|
||||||
LLVMValueRef ac_llvm_get_called_value(LLVMValueRef call);
|
LLVMValueRef ac_llvm_get_called_value(LLVMValueRef call);
|
||||||
bool ac_llvm_is_function(LLVMValueRef v);
|
bool ac_llvm_is_function(LLVMValueRef v);
|
||||||
|
LLVMModuleRef ac_create_module(LLVMTargetMachineRef tm, LLVMContextRef ctx);
|
||||||
|
|
||||||
LLVMBuilderRef ac_create_builder(LLVMContextRef ctx,
|
LLVMBuilderRef ac_create_builder(LLVMContextRef ctx,
|
||||||
enum ac_float_mode float_mode);
|
enum ac_float_mode float_mode);
|
||||||
|
@@ -3165,14 +3165,7 @@ LLVMModuleRef ac_translate_nir_to_llvm(LLVMTargetMachineRef tm,
|
|||||||
|
|
||||||
ac_llvm_context_init(&ctx.ac, ctx.context, options->chip_class,
|
ac_llvm_context_init(&ctx.ac, ctx.context, options->chip_class,
|
||||||
options->family);
|
options->family);
|
||||||
ctx.ac.module = LLVMModuleCreateWithNameInContext("shader", ctx.context);
|
ctx.ac.module = ac_create_module(tm, ctx.context);
|
||||||
LLVMSetTarget(ctx.ac.module, options->supports_spill ? "amdgcn-mesa-mesa3d" : "amdgcn--");
|
|
||||||
|
|
||||||
LLVMTargetDataRef data_layout = LLVMCreateTargetDataLayout(tm);
|
|
||||||
char *data_layout_str = LLVMCopyStringRepOfTargetData(data_layout);
|
|
||||||
LLVMSetDataLayout(ctx.ac.module, data_layout_str);
|
|
||||||
LLVMDisposeTargetData(data_layout);
|
|
||||||
LLVMDisposeMessage(data_layout_str);
|
|
||||||
|
|
||||||
enum ac_float_mode float_mode =
|
enum ac_float_mode float_mode =
|
||||||
options->unsafe_math ? AC_FLOAT_MODE_UNSAFE_FP_MATH :
|
options->unsafe_math ? AC_FLOAT_MODE_UNSAFE_FP_MATH :
|
||||||
@@ -3613,10 +3606,9 @@ radv_compile_gs_copy_shader(LLVMTargetMachineRef tm,
|
|||||||
|
|
||||||
ac_llvm_context_init(&ctx.ac, ctx.context, options->chip_class,
|
ac_llvm_context_init(&ctx.ac, ctx.context, options->chip_class,
|
||||||
options->family);
|
options->family);
|
||||||
ctx.ac.module = LLVMModuleCreateWithNameInContext("shader", ctx.context);
|
ctx.ac.module = ac_create_module(tm, ctx.context);
|
||||||
|
|
||||||
ctx.is_gs_copy_shader = true;
|
ctx.is_gs_copy_shader = true;
|
||||||
LLVMSetTarget(ctx.ac.module, "amdgcn--");
|
|
||||||
|
|
||||||
enum ac_float_mode float_mode =
|
enum ac_float_mode float_mode =
|
||||||
options->unsafe_math ? AC_FLOAT_MODE_UNSAFE_FP_MATH :
|
options->unsafe_math ? AC_FLOAT_MODE_UNSAFE_FP_MATH :
|
||||||
|
@@ -119,13 +119,14 @@ static void si_init_compiler(struct si_screen *sscreen,
|
|||||||
(sscreen->info.chip_class < GFX9 ? AC_TM_FORCE_DISABLE_XNACK : 0) |
|
(sscreen->info.chip_class < GFX9 ? AC_TM_FORCE_DISABLE_XNACK : 0) |
|
||||||
(!sscreen->llvm_has_working_vgpr_indexing ? AC_TM_PROMOTE_ALLOCA_TO_SCRATCH : 0);
|
(!sscreen->llvm_has_working_vgpr_indexing ? AC_TM_PROMOTE_ALLOCA_TO_SCRATCH : 0);
|
||||||
|
|
||||||
|
const char *triple;
|
||||||
compiler->tm = ac_create_target_machine(sscreen->info.family,
|
compiler->tm = ac_create_target_machine(sscreen->info.family,
|
||||||
tm_options, &compiler->triple);
|
tm_options, &triple);
|
||||||
if (!compiler->tm)
|
if (!compiler->tm)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
compiler->target_library_info =
|
compiler->target_library_info =
|
||||||
gallivm_create_target_library_info(compiler->triple);
|
gallivm_create_target_library_info(triple);
|
||||||
if (!compiler->target_library_info)
|
if (!compiler->target_library_info)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@@ -150,19 +151,10 @@ static void si_init_compiler(struct si_screen *sscreen,
|
|||||||
/* This is recommended by the instruction combining pass. */
|
/* This is recommended by the instruction combining pass. */
|
||||||
LLVMAddEarlyCSEMemSSAPass(compiler->passmgr);
|
LLVMAddEarlyCSEMemSSAPass(compiler->passmgr);
|
||||||
LLVMAddInstructionCombiningPass(compiler->passmgr);
|
LLVMAddInstructionCombiningPass(compiler->passmgr);
|
||||||
|
|
||||||
/* Get the data layout. */
|
|
||||||
LLVMTargetDataRef data_layout = LLVMCreateTargetDataLayout(compiler->tm);
|
|
||||||
if (!data_layout)
|
|
||||||
return;
|
|
||||||
compiler->data_layout = LLVMCopyStringRepOfTargetData(data_layout);
|
|
||||||
LLVMDisposeTargetData(data_layout);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void si_destroy_compiler(struct si_compiler *compiler)
|
static void si_destroy_compiler(struct si_compiler *compiler)
|
||||||
{
|
{
|
||||||
if (compiler->data_layout)
|
|
||||||
LLVMDisposeMessage((char*)compiler->data_layout);
|
|
||||||
if (compiler->passmgr)
|
if (compiler->passmgr)
|
||||||
LLVMDisposePassManager(compiler->passmgr);
|
LLVMDisposePassManager(compiler->passmgr);
|
||||||
#if HAVE_LLVM >= 0x0700
|
#if HAVE_LLVM >= 0x0700
|
||||||
|
@@ -320,8 +320,6 @@ struct si_shader;
|
|||||||
/* Per-thread persistent LLVM objects. */
|
/* Per-thread persistent LLVM objects. */
|
||||||
struct si_compiler {
|
struct si_compiler {
|
||||||
LLVMTargetMachineRef tm;
|
LLVMTargetMachineRef tm;
|
||||||
const char *triple;
|
|
||||||
const char *data_layout;
|
|
||||||
LLVMTargetLibraryInfoRef target_library_info;
|
LLVMTargetLibraryInfoRef target_library_info;
|
||||||
LLVMPassManagerRef passmgr;
|
LLVMPassManagerRef passmgr;
|
||||||
};
|
};
|
||||||
|
@@ -986,10 +986,7 @@ void si_llvm_context_init(struct si_shader_context *ctx,
|
|||||||
ctx->compiler = compiler;
|
ctx->compiler = compiler;
|
||||||
|
|
||||||
ctx->gallivm.context = LLVMContextCreate();
|
ctx->gallivm.context = LLVMContextCreate();
|
||||||
ctx->gallivm.module = LLVMModuleCreateWithNameInContext("tgsi",
|
ctx->gallivm.module = ac_create_module(compiler->tm, ctx->gallivm.context);
|
||||||
ctx->gallivm.context);
|
|
||||||
LLVMSetTarget(ctx->gallivm.module, compiler->triple);
|
|
||||||
LLVMSetDataLayout(ctx->gallivm.module, compiler->data_layout);
|
|
||||||
|
|
||||||
bool unsafe_fpmath = (sscreen->debug_flags & DBG(UNSAFE_MATH)) != 0;
|
bool unsafe_fpmath = (sscreen->debug_flags & DBG(UNSAFE_MATH)) != 0;
|
||||||
enum ac_float_mode float_mode =
|
enum ac_float_mode float_mode =
|
||||||
|
Reference in New Issue
Block a user