diff options
author | Darren Powell <[email protected]> | 2014-03-31 18:00:28 -0400 |
---|---|---|
committer | Tom Stellard <[email protected]> | 2014-04-17 19:37:58 -0400 |
commit | bc86690f137a71a6f1cdcc0393a4b3f181df7240 (patch) | |
tree | 00fcb3e0adebc68d28e7328d5752fae3a8690c90 /src/gallium/drivers/radeon | |
parent | 9f9ab8ec0dd9739e90de5aa5b8434d105d351f31 (diff) |
radeonsi: Added Diag Handler to receive LLVM Error messages
Reviewed-by: Tom Stellard <[email protected]>
Diffstat (limited to 'src/gallium/drivers/radeon')
-rw-r--r-- | src/gallium/drivers/radeon/radeon_llvm_emit.c | 50 |
1 files changed, 44 insertions, 6 deletions
diff --git a/src/gallium/drivers/radeon/radeon_llvm_emit.c b/src/gallium/drivers/radeon/radeon_llvm_emit.c index 7bcdc2756f0..891781f6c83 100644 --- a/src/gallium/drivers/radeon/radeon_llvm_emit.c +++ b/src/gallium/drivers/radeon/radeon_llvm_emit.c @@ -29,6 +29,7 @@ #include <llvm-c/Target.h> #include <llvm-c/TargetMachine.h> +#include <llvm-c/Core.h> #include <stdlib.h> #include <stdio.h> @@ -79,6 +80,22 @@ static LLVMTargetRef get_r600_target() { return target; } +#if HAVE_LLVM >= 0x0305 + +static void radeonDiagnosticHandler(LLVMDiagnosticInfoRef di, void *context) { + unsigned int *diagnosticflag; + char *diaginfo_message; + + diaginfo_message = LLVMGetDiagInfoDescription(di); + fprintf(stderr,"LLVM triggered Diagnostic Handler: %s\n", diaginfo_message); + LLVMDisposeMessage(diaginfo_message); + + diagnosticflag = (unsigned int *)context; + *diagnosticflag = ((LLVMDSError == LLVMGetDiagInfoSeverity(di)) ? 1 : 0); +} + +#endif + /** * Compile an LLVM module to machine code. * @@ -92,12 +109,15 @@ unsigned radeon_llvm_compile(LLVMModuleRef M, struct radeon_shader_binary *binar char cpu[CPU_STRING_LEN]; char fs[FS_STRING_LEN]; char *err; + LLVMContextRef llvm_ctx; + unsigned rval = 0; LLVMMemoryBufferRef out_buffer; unsigned buffer_size; const char *buffer_data; char triple[TRIPLE_STRING_LEN]; - LLVMBool r; + LLVMBool mem_err; + /* initialise */ init_r600_target(); target = get_r600_target(); @@ -112,24 +132,42 @@ unsigned radeon_llvm_compile(LLVMModuleRef M, struct radeon_shader_binary *binar strncpy(fs, "+DumpCode", FS_STRING_LEN); } strncpy(triple, "r600--", TRIPLE_STRING_LEN); + + /* Setup Diagnostic Handler*/ + llvm_ctx = LLVMGetModuleContext(M); + +#if HAVE_LLVM >= 0x0305 + LLVMContextSetDiagnosticHandler(llvm_ctx, radeonDiagnosticHandler, &rval); +#endif + rval = 0; + + /* Compile IR*/ tm = LLVMCreateTargetMachine(target, triple, cpu, fs, LLVMCodeGenLevelDefault, LLVMRelocDefault, LLVMCodeModelDefault); - - r = LLVMTargetMachineEmitToMemoryBuffer(tm, M, LLVMObjectFile, &err, + mem_err = LLVMTargetMachineEmitToMemoryBuffer(tm, M, LLVMObjectFile, &err, &out_buffer); - if (r) { - fprintf(stderr, "%s", err); + + /* Process Errors/Warnings */ + if (mem_err) { + fprintf(stderr, "%s: %s", __FUNCTION__, err); FREE(err); + LLVMDisposeTargetMachine(tm); return 1; } + if (0 != rval) { + fprintf(stderr, "%s: Processing Diag Flag\n", __FUNCTION__); + } + + /* Extract Shader Code*/ buffer_size = LLVMGetBufferSize(out_buffer); buffer_data = LLVMGetBufferStart(out_buffer); radeon_elf_read(buffer_data, buffer_size, binary, dump); + /* Clean up */ LLVMDisposeMemoryBuffer(out_buffer); LLVMDisposeTargetMachine(tm); - return 0; + return rval; } |