From c571f1eb47417b66ab815ad4f15689d9afdc4ef8 Mon Sep 17 00:00:00 2001
From: foreman
Date: Thu, 25 Aug 2016 13:14:09 -0400
Subject: [PATCH] P4 to Git Change 1307211 by smekhano@stas-nova-hsa on
2016/08/25 13:09:04
SWDEV-101354 - HSA HLC: fix unify metadata pass
When we link multiple modules we have metadata duplicated, so after we link with our library bitcode is twice bigger than needs to be.
Besides we did not unify llvm.ident metadata since llvm 3.6 merge.
Fix that:
1. Add llvm.ident to the processing;
2. Do not duplicate strings within unified metadata;
3. Run unification pass post link, not before the link.
Now since our library is compiled for OpenCL 2.0 we will always get OCL version 2.0 as a maximum. That is not really correct, and since
the pass was not really working before that would lead to regression, as we would fail to identify correct kernel's OpenCL version and
perform simplifications for 1.2. Now the pass will pick the first version, which shall represent the kernel module. That might not be
100% correct because we may have several kernel modules, but a proper fix would require to correctly identify library as 1.2, which is
troublesome. In the current state that just keeps the status quo.
Testing: smoke, precheckin
Reviewed by Evgeny Mankov
Affected files ...
... //depot/stg/opencl/drivers/opencl/compiler/lib/backends/common/linker.cpp#152 edit
... //depot/stg/opencl/drivers/opencl/compiler/lib/linker/include/AMDFixupKernelModule.h#2 edit
... //depot/stg/opencl/drivers/opencl/compiler/lib/linker/lib/AMDFixupKernelModule.cpp#7 edit
... //depot/stg/opencl/drivers/opencl/compiler/lib/linker/tools/opencl-link/opencl-link.cpp#10 edit
... //depot/stg/opencl/drivers/opencl/compiler/llvm/lib/Transforms/Scalar/AMDUnifyMetadata.cpp#2 edit
[ROCm/clr commit: 82f13f6ba1f2885c4b4ee134356b9ff7b99c21dc]
---
.../compiler/lib/backends/common/linker.cpp | 1 +
.../rocclr/runtime/device/rocm/rocprogram.cpp | 31 ++++++++++++++++---
2 files changed, 28 insertions(+), 4 deletions(-)
diff --git a/projects/clr/rocclr/compiler/lib/backends/common/linker.cpp b/projects/clr/rocclr/compiler/lib/backends/common/linker.cpp
index 6b81c67133..1a58d41cb4 100644
--- a/projects/clr/rocclr/compiler/lib/backends/common/linker.cpp
+++ b/projects/clr/rocclr/compiler/lib/backends/common/linker.cpp
@@ -690,6 +690,7 @@ amdcl::OCLLinker::link(llvm::Module* input, std::vectoroVariables->EnableBuildTiming) {
diff --git a/projects/clr/rocclr/runtime/device/rocm/rocprogram.cpp b/projects/clr/rocclr/runtime/device/rocm/rocprogram.cpp
index 599a72b937..8955c1b21c 100644
--- a/projects/clr/rocclr/runtime/device/rocm/rocprogram.cpp
+++ b/projects/clr/rocclr/runtime/device/rocm/rocprogram.cpp
@@ -833,8 +833,32 @@ namespace roc {
return false;
}
+ // open the optimized output
+ Data* opt_bc = C->NewBuffer(DT_LLVM_BC);
+
+ if (!opt_bc) {
+ buildLog_ += "Error: Failed to open the optimized program.\n";
+ return false;
+ }
+
+ std::ostringstream optLevel;
+ optLevel << "-O" << options->oVariables->OptLevel;
+
+ std::vector optOptions;
+ optOptions.push_back(optLevel.str());
+ optOptions.push_back("-strip");
+ optOptions.push_back("-instcombine");
+ optOptions.push_back("-always-inline");
+
+ ret = C->OptimizeLLVMBitcode(linked_bc, opt_bc, optOptions);
+ buildLog_ += C->Output();
+ if (!ret) {
+ buildLog_ += "Error: Optimizing bitcode failed: linking source & IR libraries.\n";
+ return false;
+ }
+
inputs.clear();
- inputs.push_back(linked_bc);
+ inputs.push_back(opt_bc);
Buffer* out_exec = C->NewBuffer(DT_EXECUTABLE);
if (!out_exec) {
@@ -848,9 +872,8 @@ namespace roc {
optionsstr.append(" -mcpu=");
optionsstr.append(dev().deviceInfo().machineTarget_);
- std::ostringstream optLevel;
- optLevel << " -O" << options->oVariables->OptLevel;
- optionsstr.append(optLevel.str());
+ // Set the -O#
+ optionsstr.append(" ").append(optLevel.str());
// Tokenize the options string into a vector of strings
std::istringstream strstr(optionsstr);