diff options
author | Tom Stellard <[email protected]> | 2014-10-15 12:24:30 -0400 |
---|---|---|
committer | Tom Stellard <[email protected]> | 2015-01-06 12:53:21 -0800 |
commit | 761e36b4caab4e8e09a4c2b1409a825902fc7d2c (patch) | |
tree | c8b8639b11190ebfcc43f4e22fa771f86d551bd8 /src/gallium/drivers/radeon | |
parent | 934e41c0b31cffa4efc08f61cff2389e3149b3f3 (diff) |
radeonsi: Cache LLVMTargetMachine object in si_screen
Rather than building a new one every compile. This should reduce some
of the overhead of compiling shaders.
One consequence of this change is that we lose the MachineInstrs dumps
when dumping the shaders via R600_DEBUG. The LLVM IR and assembly is
still dumped, and if you still want to see the MachineInstr dump, you
can run the dumped LLVM IR through llc.
Diffstat (limited to 'src/gallium/drivers/radeon')
-rw-r--r-- | src/gallium/drivers/radeon/radeon_llvm_emit.c | 47 | ||||
-rw-r--r-- | src/gallium/drivers/radeon/radeon_llvm_emit.h | 6 |
2 files changed, 29 insertions, 24 deletions
diff --git a/src/gallium/drivers/radeon/radeon_llvm_emit.c b/src/gallium/drivers/radeon/radeon_llvm_emit.c index dc871d79717..4f288e42b1f 100644 --- a/src/gallium/drivers/radeon/radeon_llvm_emit.c +++ b/src/gallium/drivers/radeon/radeon_llvm_emit.c @@ -98,9 +98,10 @@ static void init_r600_target() } } -static LLVMTargetRef get_r600_target() +LLVMTargetRef radeon_llvm_get_r600_target() { LLVMTargetRef target = NULL; + init_r600_target(); for (target = LLVMGetFirstTarget(); target; target = LLVMGetNextTarget(target)) { @@ -138,14 +139,13 @@ static void radeonDiagnosticHandler(LLVMDiagnosticInfoRef di, void *context) * @returns 0 for success, 1 for failure */ unsigned radeon_llvm_compile(LLVMModuleRef M, struct radeon_shader_binary *binary, - const char *gpu_family, unsigned dump) + const char *gpu_family, unsigned dump, LLVMTargetMachineRef tm) { - LLVMTargetRef target; - LLVMTargetMachineRef tm; char cpu[CPU_STRING_LEN]; char fs[FS_STRING_LEN]; char *err; + bool dispose_tm = false; LLVMContextRef llvm_ctx; unsigned rval = 0; LLVMMemoryBufferRef out_buffer; @@ -154,22 +154,23 @@ unsigned radeon_llvm_compile(LLVMModuleRef M, struct radeon_shader_binary *binar char triple[TRIPLE_STRING_LEN]; LLVMBool mem_err; - /* initialise */ - init_r600_target(); - - target = get_r600_target(); - if (!target) { - return 1; - } - - strncpy(cpu, gpu_family, CPU_STRING_LEN); - memset(fs, 0, sizeof(fs)); - if (dump) { - LLVMDumpModule(M); - strncpy(fs, "+DumpCode", FS_STRING_LEN); + if (!tm) { + LLVMTargetRef target = radeon_llvm_get_r600_target(); + if (!target) { + return 1; + } + strncpy(cpu, gpu_family, CPU_STRING_LEN); + memset(fs, 0, sizeof(fs)); + if (dump) { + LLVMDumpModule(M); + strncpy(fs, "+DumpCode", FS_STRING_LEN); + } + strncpy(triple, "r600--", TRIPLE_STRING_LEN); + tm = LLVMCreateTargetMachine(target, triple, cpu, fs, + LLVMCodeGenLevelDefault, LLVMRelocDefault, + LLVMCodeModelDefault); + dispose_tm = true; } - strncpy(triple, "r600--", TRIPLE_STRING_LEN); - /* Setup Diagnostic Handler*/ llvm_ctx = LLVMGetModuleContext(M); @@ -179,9 +180,6 @@ unsigned radeon_llvm_compile(LLVMModuleRef M, struct radeon_shader_binary *binar rval = 0; /* Compile IR*/ - tm = LLVMCreateTargetMachine(target, triple, cpu, fs, - LLVMCodeGenLevelDefault, LLVMRelocDefault, - LLVMCodeModelDefault); mem_err = LLVMTargetMachineEmitToMemoryBuffer(tm, M, LLVMObjectFile, &err, &out_buffer); @@ -205,6 +203,9 @@ unsigned radeon_llvm_compile(LLVMModuleRef M, struct radeon_shader_binary *binar /* Clean up */ LLVMDisposeMemoryBuffer(out_buffer); - LLVMDisposeTargetMachine(tm); + + if (dispose_tm) { + LLVMDisposeTargetMachine(tm); + } return rval; } diff --git a/src/gallium/drivers/radeon/radeon_llvm_emit.h b/src/gallium/drivers/radeon/radeon_llvm_emit.h index 780ff5f67f2..66217b5ce5f 100644 --- a/src/gallium/drivers/radeon/radeon_llvm_emit.h +++ b/src/gallium/drivers/radeon/radeon_llvm_emit.h @@ -28,15 +28,19 @@ #define RADEON_LLVM_EMIT_H #include <llvm-c/Core.h> +#include <llvm-c/TargetMachine.h> struct radeon_shader_binary; void radeon_llvm_shader_type(LLVMValueRef F, unsigned type); +LLVMTargetRef radeon_llvm_get_r600_target(void); + unsigned radeon_llvm_compile( LLVMModuleRef M, struct radeon_shader_binary *binary, const char * gpu_family, - unsigned dump); + unsigned dump, + LLVMTargetMachineRef tm); #endif /* RADEON_LLVM_EMIT_H */ |