From 13adb33dafa002b3fb4837002183e7888600ab87 Mon Sep 17 00:00:00 2001
From: foreman
Date: Fri, 28 Aug 2015 13:36:33 -0400
Subject: [PATCH] P4 to Git Change 1185746 by emankov@em-hsa-amd on 2015/08/28
13:23:26
ECR #333753 - Compiler Lib: Bug 10985 - Print compiler options as comment in .cl file when dumping using -save-temps
Affects all targets.
Also fixes rare problem with dumping cl as a raw binary.
Testing: pre check-in
Reviewers: Brian Sumner, Nikolay Haustov, Matthew Arsenault
Affected files ...
... //depot/stg/opencl/drivers/opencl/compiler/lib/backends/common/frontend.cpp#36 edit
... //depot/stg/opencl/drivers/opencl/compiler/lib/backends/common/frontend.hpp#10 edit
... //depot/stg/opencl/drivers/opencl/compiler/lib/backends/common/frontend_clang.cpp#23 edit
[ROCm/clr commit: 243af8e61162316f803df77822070d15ae0ffd61]
---
.../rocclr/compiler/lib/backends/common/frontend.cpp | 7 +------
.../rocclr/compiler/lib/backends/common/frontend.hpp | 12 ++++++++++++
.../compiler/lib/backends/common/frontend_clang.cpp | 8 +-------
3 files changed, 14 insertions(+), 13 deletions(-)
diff --git a/projects/clr/rocclr/compiler/lib/backends/common/frontend.cpp b/projects/clr/rocclr/compiler/lib/backends/common/frontend.cpp
index ac7625d346..1e10b72962 100644
--- a/projects/clr/rocclr/compiler/lib/backends/common/frontend.cpp
+++ b/projects/clr/rocclr/compiler/lib/backends/common/frontend.cpp
@@ -4,14 +4,12 @@
#include "top.hpp"
#include "frontend.hpp"
#include "bif/bifbase.hpp"
-#include "utils/libUtils.h"
#include "utils/target_mappings.h"
#include "utils/options.hpp"
#include "os/os.hpp"
#include "llvm/ADT/StringRef.h"
#include
#include
-#include
#include
#include
#include
@@ -172,10 +170,7 @@ amdcl::OCLFrontend::getFrontendCommand(aclBinary *elf,
#endif
if (Opts && Opts->isDumpFlagSet(amd::option::DUMP_CL) && !preprocessOnly) {
- std::string clFileName = Opts->getDumpFileName(".cl");
- f.open(clFileName.c_str(), (std::fstream::out | std::fstream::binary));
- f.write(src.data(), src.length());
- f.close();
+ dumpSource(src, Opts);
}
std::string clcCmd = systemPath.str();
return clcCmd;
diff --git a/projects/clr/rocclr/compiler/lib/backends/common/frontend.hpp b/projects/clr/rocclr/compiler/lib/backends/common/frontend.hpp
index 13686329c1..f9755e6175 100644
--- a/projects/clr/rocclr/compiler/lib/backends/common/frontend.hpp
+++ b/projects/clr/rocclr/compiler/lib/backends/common/frontend.hpp
@@ -4,8 +4,10 @@
#ifndef _BE_FRONTEND_HPP_
#define _BE_FRONTEND_HPP_
#include
+#include
#include "aclTypes.h"
#include "compiler_stage.hpp"
+#include "utils/libUtils.h"
namespace amdcl
{
@@ -32,6 +34,16 @@ namespace amdcl
virtual int compileCommand(const std::string& singleSrc) = 0;
virtual std::string getClassName() = 0;
+
+ //! Dumps source CL text with compiler options in a file.
+ void dumpSource(const std::string& src, amd::option::Options* opts) {
+ std::ofstream f(opts->getDumpFileName(".cl").c_str(), std::ios::trunc);
+ if(f.is_open()) {
+ f << "/* Compiler options:\n" << opts->origOptionStr << "\n*/\n\n" << src;
+ } else {
+ appendLogToCL(CL(), "File for dumping source cl isn't opened");
+ }
+ }
}; // class Frontend
/*@}*/
diff --git a/projects/clr/rocclr/compiler/lib/backends/common/frontend_clang.cpp b/projects/clr/rocclr/compiler/lib/backends/common/frontend_clang.cpp
index 34e46b3675..71b7b0b3c6 100644
--- a/projects/clr/rocclr/compiler/lib/backends/common/frontend_clang.cpp
+++ b/projects/clr/rocclr/compiler/lib/backends/common/frontend_clang.cpp
@@ -8,7 +8,6 @@
#include "frontend.hpp"
#include "os/os.hpp"
#include "top.hpp"
-#include "utils/libUtils.h"
#include "utils/options.hpp"
#include "utils/target_mappings.h"
@@ -20,7 +19,6 @@
#include
#include
-#include
amdcl::ClangOCLFrontend::ClangOCLFrontend(aclCompiler* cl, aclBinary* elf,
aclLogFunction log)
@@ -128,11 +126,7 @@ int amdcl::ClangOCLFrontend::compileCommand(const std::string& src) {
ClangOptions.CompilerContext = &Context();
if (amdOpts && amdOpts->isDumpFlagSet(amd::option::DUMP_CL)) {
- std::string inpCLFileName = amdOpts->getDumpFileName(".cl");
- std::fstream f;
- f.open(inpCLFileName.c_str(), (std::fstream::out | std::fstream::binary));
- f.write(src.data(), src.length());
- f.close();
+ dumpSource(src, amdOpts);
}
//Start the compilation