}
}
-static LLVMTargetRef get_r600_target()
+LLVMTargetRef radeon_llvm_get_r600_target()
{
LLVMTargetRef target = NULL;
+ init_r600_target();
for (target = LLVMGetFirstTarget(); target;
target = LLVMGetNextTarget(target)) {
* @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;
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);
rval = 0;
/* Compile IR*/
- tm = LLVMCreateTargetMachine(target, triple, cpu, fs,
- LLVMCodeGenLevelDefault, LLVMRelocDefault,
- LLVMCodeModelDefault);
mem_err = LLVMTargetMachineEmitToMemoryBuffer(tm, M, LLVMObjectFile, &err,
&out_buffer);
/* Clean up */
LLVMDisposeMemoryBuffer(out_buffer);
- LLVMDisposeTargetMachine(tm);
+
+ if (dispose_tm) {
+ LLVMDisposeTargetMachine(tm);
+ }
return rval;
}
#include "si_public.h"
#include "sid.h"
+#include "radeon/radeon_llvm_emit.h"
#include "radeon/radeon_uvd.h"
#include "util/u_memory.h"
#include "vl/vl_decoder.h"
+#include <llvm-c/Target.h>
+#include <llvm-c/TargetMachine.h>
+
/*
* pipe_context
*/
return;
r600_destroy_common_screen(&sscreen->b);
+
+#if HAVE_LLVM >= 0x0306
+ LLVMDisposeTargetMachine(sscreen->tm);
+#endif
}
#define SI_TILE_MODE_COLOR_2D_8BPP 14
struct pipe_screen *radeonsi_screen_create(struct radeon_winsys *ws)
{
struct si_screen *sscreen = CALLOC_STRUCT(si_screen);
+ LLVMTargetRef r600_target;
if (sscreen == NULL) {
return NULL;
}
/* Create the auxiliary context. This must be done last. */
sscreen->b.aux_context = sscreen->b.b.context_create(&sscreen->b.b, NULL);
+#if HAVE_LLVM >= 0x0306
+ /* Initialize LLVM TargetMachine */
+ r600_target = radeon_llvm_get_r600_target();
+ sscreen->tm = LLVMCreateTargetMachine(r600_target, "r600--",
+ r600_get_llvm_processor_name(sscreen->b.family),
+ "+DumpCode", LLVMCodeGenLevelDefault, LLVMRelocDefault,
+ LLVMCodeModelDefault);
+#endif
return &sscreen->b.b;
}