summaryrefslogtreecommitdiffstats
path: root/src/gallium
diff options
context:
space:
mode:
authorTom Stellard <[email protected]>2014-09-25 18:08:20 -0700
committerTom Stellard <[email protected]>2014-10-16 19:42:41 -0400
commit76136c29bbd78ea414c86402d4031855218dc42b (patch)
treea899ac91694d8cd6632408fb7047a7e4fbeb52ea /src/gallium
parent8e7df519bd8556591794b2de08a833a67e34d526 (diff)
clover: Register an llvm diagnostic handler v3
This will allow us to handle internal compiler errors. v2: - Code cleanups. v3: - More cleanups. Reviewed-by: Francisco Jerez <[email protected]>
Diffstat (limited to 'src/gallium')
-rw-r--r--src/gallium/state_trackers/clover/llvm/invocation.cpp25
1 files changed, 25 insertions, 0 deletions
diff --git a/src/gallium/state_trackers/clover/llvm/invocation.cpp b/src/gallium/state_trackers/clover/llvm/invocation.cpp
index 58ab8b1b98c..56607615343 100644
--- a/src/gallium/state_trackers/clover/llvm/invocation.cpp
+++ b/src/gallium/state_trackers/clover/llvm/invocation.cpp
@@ -33,6 +33,8 @@
#include <llvm/Linker.h>
#else
#include <llvm/Linker/Linker.h>
+#include <llvm/IR/DiagnosticInfo.h>
+#include <llvm/IR/DiagnosticPrinter.h>
#endif
#if HAVE_LLVM < 0x0303
#include <llvm/DerivedTypes.h>
@@ -599,6 +601,24 @@ namespace {
return m;
}
+#if HAVE_LLVM >= 0x0305
+
+ void
+ diagnostic_handler(const llvm::DiagnosticInfo &di, void *data) {
+ if (di.getSeverity() == llvm::DS_Error) {
+ std::string message = *(compat::string*)data;
+ llvm::raw_string_ostream stream(message);
+ llvm::DiagnosticPrinterRawOStream dp(stream);
+ di.print(dp);
+ stream.flush();
+ *(compat::string*)data = message;
+
+ throw build_error();
+ }
+ }
+
+#endif
+
void
init_targets() {
static bool targets_initialized = false;
@@ -630,6 +650,10 @@ clover::compile_program_llvm(const compat::string &source,
llvm::LLVMContext llvm_ctx;
unsigned optimization_level;
+#if HAVE_LLVM >= 0x0305
+ llvm_ctx.setDiagnosticHandler(diagnostic_handler, &r_log);
+#endif
+
// The input file name must have the .cl extension in order for the
// CompilerInvocation class to recognize it as an OpenCL source file.
llvm::Module *mod = compile_llvm(llvm_ctx, source, "input.cl", triple,
@@ -661,5 +685,6 @@ clover::compile_program_llvm(const compat::string &source,
// LLVM 3.6 and newer, the user takes ownership of the module.
delete mod;
#endif
+
return m;
}