[Beignet] [PATCH 1/3] Make -g a default option arg for clang.

junyan.he at inbox.com junyan.he at inbox.com
Mon Dec 14 01:44:07 PST 2015


From: Junyan He <junyan.he at linux.intel.com>

In order to make the compiling error readable in the
gen backend, we always need the line and column number.
Rather than just give a ASSERT, we perfer to give more
information to the kernel writer. We now append line
and column numbers to every llvm-instruction, ir-instruction,
selectio-instruction and even ASM-instruction. So when
we generate the ASSERT, we can at least give some hints
about the location in the source code.
-g opt seems do not have performance side effect for
clang front end by now.
One point needs to notice, before serialization, we need
to strip out all the debug informattion, because the bitcode
writter does not support to write the debug info.

Signed-off-by: Junyan He <junyan.he at linux.intel.com>
---
 backend/src/backend/gen_program.cpp |  2 ++
 backend/src/backend/program.cpp     | 12 +++++++++---
 2 files changed, 11 insertions(+), 3 deletions(-)

diff --git a/backend/src/backend/gen_program.cpp b/backend/src/backend/gen_program.cpp
index 1427c25..606cad2 100644
--- a/backend/src/backend/gen_program.cpp
+++ b/backend/src/backend/gen_program.cpp
@@ -41,6 +41,7 @@
 #include "llvm/Support/MemoryBuffer.h"
 #include "llvm/Support/SourceMgr.h"
 #include "llvm/IRReader/IRReader.h"
+#include "llvm/IR/DebugInfo.h"
 #endif
 
 #include "backend/program.h"
@@ -381,6 +382,7 @@ namespace gbe {
 #ifdef GBE_COMPILER_AVAILABLE
       std::string str;
       llvm::raw_string_ostream OS(str);
+      llvm::StripDebugInfo(*(llvm::Module*)prog->module);
       llvm::WriteBitcodeToFile((llvm::Module*)prog->module, OS);
       std::string& bin_str = OS.str();
       int llsz = bin_str.size();
diff --git a/backend/src/backend/program.cpp b/backend/src/backend/program.cpp
index 14b802a..047e250 100644
--- a/backend/src/backend/program.cpp
+++ b/backend/src/backend/program.cpp
@@ -76,6 +76,7 @@
 #if LLVM_VERSION_MINOR <= 2
 #include <llvm/Module.h>
 #else
+#include <llvm/IR/DebugInfo.h>
 #include <llvm/IR/Module.h>
 #endif  /* LLVM_VERSION_MINOR <= 2 */
 #include <llvm/Bitcode/ReaderWriter.h>
@@ -566,7 +567,8 @@ namespace gbe {
 #endif /* LLVM_VERSION_MINOR <= 2 */
     args.push_back("stringInput.cl");
     args.push_back("-ffp-contract=off");
-    if(OCL_DEBUGINFO) args.push_back("-g");
+    /* We always want the debug line and col. */
+    args.push_back("-g");
 
     // The compiler invocation needs a DiagnosticsEngine so it can report problems
     std::string ErrorString;
@@ -678,8 +680,10 @@ namespace gbe {
                                     llvm::sys::fs::F_None
       #endif
                                     );
-      if (err.empty())
+      if (err.empty()) {
+        llvm::StripDebugInfo(**out_module);
         llvm::WriteBitcodeToFile(*out_module, ostream);
+      }
     }
 #else
     if (!dumpLLVMFileName.empty()) {
@@ -695,8 +699,10 @@ namespace gbe {
       std::error_code err;
       llvm::raw_fd_ostream ostream (dumpSPIRBinaryName.c_str(),
                                     err, llvm::sys::fs::F_None);
-      if (!err)
+      if (!err) {
+        llvm::StripDebugInfo(**out_module);
         llvm::WriteBitcodeToFile(*out_module, ostream);
+      }
     }
 #endif
     return true;
-- 
1.9.1





More information about the Beignet mailing list