From fd39fdc69485eef6638bd6ca17bc8e5d20de869b Mon Sep 17 00:00:00 2001
From: foreman
Date: Wed, 16 Dec 2015 17:27:20 -0500
Subject: [PATCH] P4 to Git Change 1221604 by yaxunl@yaxunl_stg_win50 on
2015/12/16 17:19:59
SWDEV-84089 - [SPIRV] github pull request #32 Changes for Clang integration.
Affected files ...
... //depot/stg/opencl/drivers/opencl/compiler/lib/backends/common/frontend_clang.cpp#27 edit
... //depot/stg/opencl/drivers/opencl/compiler/lib/backends/common/linker.cpp#136 edit
... //depot/stg/opencl/drivers/opencl/compiler/lib/backends/common/v0_8/if_acl.cpp#89 edit
... //depot/stg/opencl/drivers/opencl/compiler/llvm/include/llvm/Support/SPIRV.h#10 edit
... //depot/stg/opencl/drivers/opencl/compiler/llvm/lib/SPIRV/CMakeLists.txt#16 integrate
... //depot/stg/opencl/drivers/opencl/compiler/llvm/lib/SPIRV/SPIRVWriter.cpp#16 integrate
... //depot/stg/opencl/drivers/opencl/compiler/llvm/lib/SPIRV/SPIRVWriterPass.cpp#1 branch
... //depot/stg/opencl/drivers/opencl/compiler/llvm/lib/SPIRV/SPIRVWriterPass.h#1 branch
... //depot/stg/opencl/drivers/opencl/compiler/llvm/lib/SPIRV/build/Makefile.SPIRV#3 edit
... //depot/stg/opencl/drivers/opencl/compiler/llvm/lib/SPIRV/libSPIRV/SPIRVBasicBlock.cpp#2 integrate
... //depot/stg/opencl/drivers/opencl/compiler/llvm/lib/SPIRV/libSPIRV/SPIRVBasicBlock.h#2 integrate
... //depot/stg/opencl/drivers/opencl/compiler/llvm/lib/SPIRV/libSPIRV/SPIRVDebug.h#3 integrate
... //depot/stg/opencl/drivers/opencl/compiler/llvm/lib/SPIRV/libSPIRV/SPIRVDecorate.cpp#2 integrate
... //depot/stg/opencl/drivers/opencl/compiler/llvm/lib/SPIRV/libSPIRV/SPIRVDecorate.h#6 integrate
... //depot/stg/opencl/drivers/opencl/compiler/llvm/lib/SPIRV/libSPIRV/SPIRVEntry.cpp#5 integrate
... //depot/stg/opencl/drivers/opencl/compiler/llvm/lib/SPIRV/libSPIRV/SPIRVEntry.h#7 integrate
... //depot/stg/opencl/drivers/opencl/compiler/llvm/lib/SPIRV/libSPIRV/SPIRVFunction.cpp#3 integrate
... //depot/stg/opencl/drivers/opencl/compiler/llvm/lib/SPIRV/libSPIRV/SPIRVFunction.h#3 integrate
... //depot/stg/opencl/drivers/opencl/compiler/llvm/lib/SPIRV/libSPIRV/SPIRVInstruction.h#8 integrate
... //depot/stg/opencl/drivers/opencl/compiler/llvm/lib/SPIRV/libSPIRV/SPIRVModule.cpp#13 integrate
... //depot/stg/opencl/drivers/opencl/compiler/llvm/lib/SPIRV/libSPIRV/SPIRVModule.h#7 integrate
... //depot/stg/opencl/drivers/opencl/compiler/llvm/lib/SPIRV/libSPIRV/SPIRVStream.cpp#5 integrate
... //depot/stg/opencl/drivers/opencl/compiler/llvm/lib/SPIRV/libSPIRV/SPIRVStream.h#4 integrate
... //depot/stg/opencl/drivers/opencl/compiler/llvm/lib/SPIRV/libSPIRV/SPIRVUtil.h#4 integrate
... //depot/stg/opencl/drivers/opencl/compiler/llvm/lib/SPIRV/libSPIRV/SPIRVValue.h#4 integrate
... //depot/stg/opencl/drivers/opencl/compiler/llvm/tools/llvm-spirv/llvm-spirv.cpp#10 integrate
---
rocclr/compiler/lib/backends/common/frontend_clang.cpp | 3 ++-
rocclr/compiler/lib/backends/common/linker.cpp | 10 +++++++---
rocclr/compiler/lib/backends/common/v0_8/if_acl.cpp | 4 ++--
3 files changed, 11 insertions(+), 6 deletions(-)
diff --git a/rocclr/compiler/lib/backends/common/frontend_clang.cpp b/rocclr/compiler/lib/backends/common/frontend_clang.cpp
index ebe35cafb7..1c7aa02e52 100644
--- a/rocclr/compiler/lib/backends/common/frontend_clang.cpp
+++ b/rocclr/compiler/lib/backends/common/frontend_clang.cpp
@@ -197,7 +197,8 @@ int amdcl::ClangOCLFrontend::compileCommand(const std::string& src) {
}
if (Options()->oVariables->FEGenSPIRV) {
- std::ostringstream ss;
+ std::string s;
+ llvm::raw_string_ostream ss(s);
std::string err;
if (Options()->getLLVMArgc()) {
diff --git a/rocclr/compiler/lib/backends/common/linker.cpp b/rocclr/compiler/lib/backends/common/linker.cpp
index b63db511ce..58cd27eb38 100644
--- a/rocclr/compiler/lib/backends/common/linker.cpp
+++ b/rocclr/compiler/lib/backends/common/linker.cpp
@@ -504,19 +504,23 @@ checkAndFixAclBinaryTarget(llvm::Module* module, aclBinary* elf,
bool
translateSpirv(llvm::Module *&M, const std::string &DumpSpirv,
const std::string &DumpLlvm){
- std::stringstream SS;
+ std::string S;
+ llvm::raw_string_ostream RSS(S);
std::string Err;
- if (!llvm::WriteSPIRV(M, SS, Err)) {
+ if (!llvm::WriteSPIRV(M, RSS, Err)) {
llvm::errs() << "Fails to save LLVM as SPIR-V: " << Err << '\n';
return false;
}
if (!DumpSpirv.empty()) {
std::ofstream OFS(DumpSpirv, std::ios::binary);
- OFS << SS.str();
+ OFS << RSS.str();
OFS.close();
}
+ RSS.flush();
+ std::stringstream SS(S);
+
auto &Ctx = M->getContext();
delete M;
M = nullptr;
diff --git a/rocclr/compiler/lib/backends/common/v0_8/if_acl.cpp b/rocclr/compiler/lib/backends/common/v0_8/if_acl.cpp
index ea525c8289..00fdf12e09 100644
--- a/rocclr/compiler/lib/backends/common/v0_8/if_acl.cpp
+++ b/rocclr/compiler/lib/backends/common/v0_8/if_acl.cpp
@@ -504,12 +504,12 @@ LLVMToSPIRV(
}
std::string spvImg;
- std::stringstream ss(spvImg);
+ llvm::raw_string_ostream ss(spvImg);
bool success = llvm::WriteSPIRV(llMod, ss, errMsg);
if (opt->isDumpFlagSet(amd::option::DUMP_SPIRV)) {
std::ofstream ofs(opt->getDumpFileName(".spv"), std::ios::binary);
- ofs << spvImg;
+ ofs << ss.str();
ofs.close();
}