summaryrefslogtreecommitdiffstats
path: root/src/gallium/drivers/radeon
diff options
context:
space:
mode:
Diffstat (limited to 'src/gallium/drivers/radeon')
-rw-r--r--src/gallium/drivers/radeon/radeon_llvm_emit.c47
-rw-r--r--src/gallium/drivers/radeon/radeon_llvm_emit.h6
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 */