[Beignet] [PATCH] backend/src/backend: Handle -dump-opt-llvm=[PATH] in clCompileProgram and clBuildProgram OpenCL API

Navare, Manasi D manasi.d.navare at intel.com
Fri Aug 14 13:20:31 PDT 2015


This patch turns on llvm dump for both clCompileProgram and clBuildProgram in a way that they both share the piece of code added in buildModuleFromSource().
This patch also takes into account the llvm 3.3 fix submitted by Yejun.
Please review this patch and let me know the feedback.

Regards
Manasi

-----Original Message-----
From: Navare, Manasi D 
Sent: Friday, August 14, 2015 12:16 AM
To: Song, Ruiling; beignet at lists.freedesktop.org
Cc: Navare, Manasi D
Subject: [PATCH] backend/src/backend: Handle -dump-opt-llvm=[PATH] in clCompileProgram and clBuildProgram OpenCL API

Allows the user to request a dump of the LLVM-generated IR to the file specified in [PATH] through clCompileProgram options

Signed-off-by: Manasi Navare <manasi.d.navare at intel.com>
---
 backend/src/backend/program.cpp | 54 +++++++++++++++++++++++------------------
 1 file changed, 30 insertions(+), 24 deletions(-)

diff --git a/backend/src/backend/program.cpp b/backend/src/backend/program.cpp index 6d539a9..4066a83 100644
--- a/backend/src/backend/program.cpp
+++ b/backend/src/backend/program.cpp
@@ -519,7 +519,7 @@ namespace gbe {
   BVAR(OCL_OUTPUT_BUILD_LOG, false);
 
   static bool buildModuleFromSource(const char* input, llvm::Module** out_module, llvm::LLVMContext* llvm_ctx,
-                                    std::vector<std::string>& options, size_t stringSize, char *err,
+                                    std::string dumpLLVMFileName, 
+ std::vector<std::string>& options, size_t stringSize, char *err,
                                     size_t *errSize) {
     // Arguments to pass to the clang frontend
     vector<const char *> args;
@@ -628,6 +628,33 @@ namespace gbe {
 #endif
 
     *out_module = module;
+
+// Dump the LLVM if requested.
+#if (LLVM_VERSION_MAJOR == 3) && (LLVM_VERSION_MINOR < 6)
+    if (!dumpLLVMFileName.empty()) {
+      std::string err;
+      llvm::raw_fd_ostream ostream (dumpLLVMFileName.c_str(),
+                                    err,
+      #if LLVM_VERSION_MINOR == 3
+                                    0,
+      #else
+                                    llvm::sys::fs::F_RW
+      #endif
+
+      if (err.empty()) {
+        (*out_module)->print(ostream, 0);
+      } //Otherwise, you'll have to make do without the dump.
+    }
+#else
+    if (!dumpLLVMFileName.empty()) {
+      std::error_code err;
+      llvm::raw_fd_ostream ostream (dumpLLVMFileName.c_str(),
+                                    err, llvm::sys::fs::F_RW);
+      if (!err) {
+        (*out_module)->print(ostream, 0);
+      } //Otherwise, you'll have to make do without the dump.
+    }
+#endif
     return true;
   }
 
@@ -808,7 +835,7 @@ namespace gbe {
     if (!llvm::llvm_is_multithreaded())
       llvm_mutex.lock();
 
-    if (buildModuleFromSource(clName.c_str(), &out_module, llvm_ctx, clOpt,
+    if (buildModuleFromSource(clName.c_str(), &out_module, llvm_ctx, 
+ dumpLLVMFileName, clOpt,
                               stringSize, err, errSize)) {
     // Now build the program from llvm
       size_t clangErrSize = 0;
@@ -819,27 +846,6 @@ namespace gbe {
         clangErrSize = *errSize;
       }
 
-      // Dump the LLVM if requested.
-      #if (LLVM_VERSION_MAJOR == 3) && (LLVM_VERSION_MINOR < 6)
-      if (!dumpLLVMFileName.empty()) {
-        std::string err;
-        llvm::raw_fd_ostream ostream (dumpLLVMFileName.c_str(),
-                                      err, llvm::sys::fs::F_RW);
-        if (err.empty()) {
-          out_module->print(ostream, 0);
-        } //Otherwise, you'll have to make do without the dump.
-      }
-      #else
-      if (!dumpLLVMFileName.empty()) {
-        std::error_code err;
-        llvm::raw_fd_ostream ostream (dumpLLVMFileName.c_str(),
-                                      err, llvm::sys::fs::F_RW);
-        if (!err) {
-          out_module->print(ostream, 0);
-        } //Otherwise, you'll have to make do without the dump.
-      }
-      #endif
-
       FILE *asmDumpStream = fopen(dumpASMFileName.c_str(), "w");  
       if (asmDumpStream)
         fclose(asmDumpStream);
@@ -885,7 +891,7 @@ namespace gbe {
     //for some functions, so we use global context now, need switch to new context later.
     llvm::Module * out_module;
     llvm::LLVMContext* llvm_ctx = &llvm::getGlobalContext();
-    if (buildModuleFromSource(clName.c_str(), &out_module, llvm_ctx, clOpt,
+    if (buildModuleFromSource(clName.c_str(), &out_module, llvm_ctx, 
+ dumpLLVMFileName, clOpt,
                               stringSize, err, errSize)) {
     // Now build the program from llvm
       if (err != NULL) {
--
1.9.1



More information about the Beignet mailing list