Skip to content

Commit c7cbf1a

Browse files
[openmp] Accept directory for libomptarget-bc-path
The commandline flag to specify a particular openmp devicertl library currently errors like: ``` fatal error: cannot open file './runtimes/runtimes-bins/openmp/libomptarget': Is a directory ``` CommonArgs successfully appends the directory to the commandline args then mlink-builtin-bitcode rejects it. This patch is a point fix to that. If --libomptarget-amdgcn-bc-path=directory then append the expected name for the current architecture and go on as before. This is useful for test runners that don't hardcode the architecture. Reviewed By: jdoerfert Differential Revision: https://reviews.llvm.org/D109057
1 parent 7f058ce commit c7cbf1a

File tree

2 files changed

+18
-8
lines changed

2 files changed

+18
-8
lines changed

clang/lib/Driver/ToolChains/CommonArgs.cpp

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1709,22 +1709,26 @@ void tools::addOpenMPDeviceRTL(const Driver &D,
17091709
: options::OPT_libomptarget_nvptx_bc_path_EQ;
17101710

17111711
StringRef ArchPrefix = Triple.isAMDGCN() ? "amdgcn" : "nvptx";
1712+
std::string LibOmpTargetName = "libomptarget-" + BitcodeSuffix.str() + ".bc";
1713+
17121714
// First check whether user specifies bc library
17131715
if (const Arg *A = DriverArgs.getLastArg(LibomptargetBCPathOpt)) {
1714-
std::string LibOmpTargetName(A->getValue());
1715-
if (llvm::sys::fs::exists(LibOmpTargetName)) {
1716+
SmallString<128> LibOmpTargetFile(A->getValue());
1717+
if (llvm::sys::fs::exists(LibOmpTargetFile) &&
1718+
llvm::sys::fs::is_directory(LibOmpTargetFile)) {
1719+
llvm::sys::path::append(LibOmpTargetFile, LibOmpTargetName);
1720+
}
1721+
1722+
if (llvm::sys::fs::exists(LibOmpTargetFile)) {
17161723
CC1Args.push_back("-mlink-builtin-bitcode");
1717-
CC1Args.push_back(DriverArgs.MakeArgString(LibOmpTargetName));
1724+
CC1Args.push_back(DriverArgs.MakeArgString(LibOmpTargetFile));
17181725
} else {
17191726
D.Diag(diag::err_drv_omp_offload_target_bcruntime_not_found)
1720-
<< LibOmpTargetName;
1727+
<< LibOmpTargetFile;
17211728
}
17221729
} else {
17231730
bool FoundBCLibrary = false;
17241731

1725-
std::string LibOmpTargetName =
1726-
"libomptarget-" + BitcodeSuffix.str() + ".bc";
1727-
17281732
for (StringRef LibraryPath : LibraryPaths) {
17291733
SmallString<128> LibOmpTargetFile(LibraryPath);
17301734
llvm::sys::path::append(LibOmpTargetFile, LibOmpTargetName);

clang/test/Driver/openmp-offload-gpu.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,11 +165,17 @@
165165
// RUN: -Xopenmp-target -march=sm_35 --cuda-path=%S/Inputs/CUDA_102/usr/local/cuda \
166166
// RUN: -fopenmp-relocatable-target -save-temps -no-canonical-prefixes %s 2>&1 \
167167
// RUN: | FileCheck -check-prefix=CHK-BCLIB-USER %s
168+
/// The user can also pass the path to the directory containing the bitcode lib
169+
// RUN: %clang -### -fopenmp=libomp -fopenmp-targets=nvptx64-nvidia-cuda \
170+
// RUN: --libomptarget-nvptx-bc-path=%S/Inputs/libomptarget \
171+
// RUN: -Xopenmp-target -march=sm_35 --cuda-path=%S/Inputs/CUDA_102/usr/local/cuda \
172+
// RUN: -fopenmp-relocatable-target -save-temps -no-canonical-prefixes %s 2>&1 \
173+
// RUN: | FileCheck -check-prefix=CHK-BCLIB-USER-DIR %s
168174

169175
// CHK-BCLIB: clang{{.*}}-triple{{.*}}nvptx64-nvidia-cuda{{.*}}-mlink-builtin-bitcode{{.*}}libomptarget-nvptx-sm_35.bc
170176
// CHK-BCLIB-NEW: clang{{.*}}-triple{{.*}}nvptx64-nvidia-cuda{{.*}}-mlink-builtin-bitcode{{.*}}libomptarget-new-nvptx-sm_35.bc
171177
// CHK-BCLIB-USER: clang{{.*}}-triple{{.*}}nvptx64-nvidia-cuda{{.*}}-mlink-builtin-bitcode{{.*}}libomptarget-nvptx-test.bc
172-
178+
// CHK-BCLIB-USER-DIR: clang{{.*}}-triple{{.*}}nvptx64-nvidia-cuda{{.*}}-mlink-builtin-bitcode{{.*}}libomptarget{{.}}libomptarget-nvptx-sm_35.bc
173179
// CHK-BCLIB-NOT: {{error:|warning:}}
174180

175181
/// ###########################################################################

0 commit comments

Comments
 (0)