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: 243af8e611]
This commit is contained in:
foreman
2015-08-28 13:36:33 -04:00
parent 1510baa3c2
commit 13adb33daf
3 changed files with 14 additions and 13 deletions
@@ -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 <cassert>
#include <cstdlib>
#include <fstream>
#include <iostream>
#include <sstream>
#include <string>
@@ -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;
@@ -4,8 +4,10 @@
#ifndef _BE_FRONTEND_HPP_
#define _BE_FRONTEND_HPP_
#include <string>
#include <fstream>
#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
/*@}*/
@@ -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 <string>
#include <sstream>
#include <fstream>
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