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

Submitted by Manasi Navare on Aug. 19, 2015, 5:50 p.m.

Details

Message ID 87E1A67218970041879FDD2045F7145D0271159E@ORSMSX106.amr.corp.intel.com
State New
Headers show

Not browsing as part of any series.

Commit Message

Manasi Navare Aug. 19, 2015, 5:50 p.m.
Hello Ruiling/Yejun,

Did you get a chance to look at this patch?
This is the same patch that was LGTM'd by Ruiling but with the fixes for LLVM 3.4 as suggested by Yejun.  

Regards
Manasi

-----Original Message-----
From: Beignet [mailto:beignet-bounces@lists.freedesktop.org] On Behalf Of Manasi Navare

Sent: Tuesday, August 18, 2015 4:17 AM
To: beignet@lists.freedesktop.org
Cc: Navare, Manasi D
Subject: [Beignet] [PATCH 1/3] backend/src/backend: Handle -dump-opt-llvm=[PATH] in clCompileProgram and clBuildProgram OpenCL API

This is a resubmission of the patch with support for LLVM 3.4 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@intel.com>

---
 backend/src/backend/program.cpp | 61 +++++++++++++++++++++--------------------
 1 file changed, 31 insertions(+), 30 deletions(-)

--
1.9.1

_______________________________________________
Beignet mailing list
Beignet@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/beignet

Patch hide | download patch | download mbox

diff --git a/backend/src/backend/program.cpp b/backend/src/backend/program.cpp index c02096f..d9e6416 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,34 @@  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_None
+      #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_None);
+      if (!err) {
+        (*out_module)->print(ostream, 0);
+      } //Otherwise, you'll have to make do without the dump.
+    }
+#endif
     return true;
   }
 
@@ -808,7 +836,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,33 +847,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,
-        #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
-
       FILE *asmDumpStream = fopen(dumpASMFileName.c_str(), "w");  
       if (asmDumpStream)
         fclose(asmDumpStream);
@@ -891,7 +892,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) {