summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorManasi Navare <manasi.d.navare@intel.com>2015-08-18 07:17:06 -0400
committerYang Rong <rong.r.yang@intel.com>2015-09-18 15:25:10 +0800
commitb7f658daff384e1a27098167a658036f3108c532 (patch)
treeecd12fbd94f7f24e9419b18d5be8ad86aff29645
parentc91a49750beea6d766b433761d14f6fe8ae098ce (diff)
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> Reviewed-by: Guo, Yejun <yejun.guo@intel.com>
-rw-r--r--backend/src/backend/program.cpp61
1 files changed, 31 insertions, 30 deletions
diff --git a/backend/src/backend/program.cpp b/backend/src/backend/program.cpp
index c02096f5..d9e64165 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) {