[clang] 9f89769 - [Clang] Add offload kind to embedded offload object
Joseph Huber via cfe-commits
cfe-commits at lists.llvm.org
Mon Mar 14 17:09:03 PDT 2022
Author: Joseph Huber
Date: 2022-03-14T20:08:27-04:00
New Revision: 9f89769cd775ce6dc27cad0fbfdd94bf94bc8f99
URL: https://github.com/llvm/llvm-project/commit/9f89769cd775ce6dc27cad0fbfdd94bf94bc8f99
DIFF: https://github.com/llvm/llvm-project/commit/9f89769cd775ce6dc27cad0fbfdd94bf94bc8f99.diff
LOG: [Clang] Add offload kind to embedded offload object
This patch adds the offload kind to the embedded section name in
preparation for offloading to different kinda like CUDA or HIP.
Depends on D120288
Reviewed By: jdoerfert
Differential Revision: https://reviews.llvm.org/D120271
Added:
Modified:
clang/lib/Driver/ToolChains/Clang.cpp
clang/test/Driver/openmp-offload-gpu.c
clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
Removed:
################################################################################
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp
index 89d8b0c4dc413..5c2b720b0872a 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -6977,7 +6977,9 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
StringRef InputName = Clang::getBaseInputStem(Args, Inputs);
CmdArgs.push_back(Args.MakeArgString(
- "-fembed-offload-object=" + File + "," + TC->getTripleString() + "." +
+ "-fembed-offload-object=" + File + "," +
+ Action::GetOffloadKindName(Action::OFK_OpenMP) + "." +
+ TC->getTripleString() + "." +
TCArgs.getLastArgValue(options::OPT_march_EQ) + "." + InputName));
}
}
@@ -8297,9 +8299,10 @@ void LinkerWrapper::ConstructJob(Compilation &C, const JobAction &JA,
TC->getTriple());
if (!BitcodeLibrary.empty())
- CmdArgs.push_back(
- Args.MakeArgString("-target-library=" + TC->getTripleString() +
- "-" + Arch + "=" + BitcodeLibrary.back()));
+ CmdArgs.push_back(Args.MakeArgString(
+ "-target-library=" +
+ Action::GetOffloadKindName(Action::OFK_OpenMP) + "-" +
+ TC->getTripleString() + "-" + Arch + "=" + BitcodeLibrary.back()));
}
// Pass in the optimization level to use for LTO.
diff --git a/clang/test/Driver/openmp-offload-gpu.c b/clang/test/Driver/openmp-offload-gpu.c
index 810f6ca2bcffa..7438d6470c795 100644
--- a/clang/test/Driver/openmp-offload-gpu.c
+++ b/clang/test/Driver/openmp-offload-gpu.c
@@ -345,4 +345,4 @@
// RUN: -fopenmp-new-driver -no-canonical-prefixes -nogpulib %s -o openmp-offload-gpu 2>&1 \
// RUN: | FileCheck -check-prefix=NEW_DRIVER_EMBEDDING %s
-// NEW_DRIVER_EMBEDDING: -fembed-offload-object=[[CUBIN:.*\.cubin]],nvptx64-nvidia-cuda.sm_70
+// NEW_DRIVER_EMBEDDING: -fembed-offload-object=[[CUBIN:.*\.cubin]],openmp.nvptx64-nvidia-cuda.sm_70
diff --git a/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp b/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
index 9ab3cedbc357f..a64648e6fe155 100644
--- a/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
+++ b/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
@@ -151,9 +151,11 @@ static codegen::RegisterCodeGenFlags CodeGenFlags;
/// Information for a device offloading file extracted from the host.
struct DeviceFile {
- DeviceFile(StringRef TheTriple, StringRef Arch, StringRef Filename)
- : TheTriple(TheTriple), Arch(Arch), Filename(Filename) {}
+ DeviceFile(StringRef Kind, StringRef TheTriple, StringRef Arch,
+ StringRef Filename)
+ : Kind(Kind), TheTriple(TheTriple), Arch(Arch), Filename(Filename) {}
+ std::string Kind;
std::string TheTriple;
std::string Arch;
std::string Filename;
@@ -164,11 +166,13 @@ namespace llvm {
template <> struct DenseMapInfo<DeviceFile> {
static DeviceFile getEmptyKey() {
return {DenseMapInfo<StringRef>::getEmptyKey(),
+ DenseMapInfo<StringRef>::getEmptyKey(),
DenseMapInfo<StringRef>::getEmptyKey(),
DenseMapInfo<StringRef>::getEmptyKey()};
}
static DeviceFile getTombstoneKey() {
return {DenseMapInfo<StringRef>::getTombstoneKey(),
+ DenseMapInfo<StringRef>::getTombstoneKey(),
DenseMapInfo<StringRef>::getTombstoneKey(),
DenseMapInfo<StringRef>::getTombstoneKey()};
}
@@ -213,12 +217,13 @@ std::string getMainExecutable(const char *Name) {
return sys::path::parent_path(COWPath).str();
}
-/// Extract the device file from the string '<triple>-<arch>=<library>.bc'.
+/// Extract the device file from the string '<kind>-<triple>-<arch>=<library>'.
DeviceFile getBitcodeLibrary(StringRef LibraryStr) {
auto DeviceAndPath = StringRef(LibraryStr).split('=');
- auto TripleAndArch = DeviceAndPath.first.rsplit('-');
- return DeviceFile(TripleAndArch.first, TripleAndArch.second,
- DeviceAndPath.second);
+ auto StringAndArch = DeviceAndPath.first.rsplit('-');
+ auto KindAndTriple = StringAndArch.first.split('-');
+ return DeviceFile(KindAndTriple.first, KindAndTriple.second,
+ StringAndArch.second, DeviceAndPath.second);
}
/// Get a temporary filename suitable for output.
@@ -299,16 +304,17 @@ extractFromBinary(const ObjectFile &Obj,
SmallVector<StringRef, 4> SectionFields;
Name->split(SectionFields, '.');
- StringRef DeviceTriple = SectionFields[3];
- StringRef Arch = SectionFields[4];
+ StringRef Kind = SectionFields[3];
+ StringRef DeviceTriple = SectionFields[4];
+ StringRef Arch = SectionFields[5];
if (Expected<StringRef> Contents = Sec.getContents()) {
SmallString<128> TempFile;
StringRef DeviceExtension = getDeviceFileExtension(
DeviceTriple, identify_magic(*Contents) == file_magic::bitcode);
- if (Error Err =
- createOutputFile(Prefix + "-device-" + DeviceTriple + "-" + Arch,
- DeviceExtension, TempFile))
+ if (Error Err = createOutputFile(Prefix + "-" + Kind + "-" +
+ DeviceTriple + "-" + Arch,
+ DeviceExtension, TempFile))
return std::move(Err);
Expected<std::unique_ptr<FileOutputBuffer>> OutputOrErr =
@@ -320,7 +326,7 @@ extractFromBinary(const ObjectFile &Obj,
if (Error E = Output->commit())
return std::move(E);
- DeviceFiles.emplace_back(DeviceTriple, Arch, TempFile);
+ DeviceFiles.emplace_back(Kind, DeviceTriple, Arch, TempFile);
ToBeStripped.push_back(*Name);
}
}
@@ -412,16 +418,17 @@ extractFromBitcode(std::unique_ptr<MemoryBuffer> Buffer,
SmallVector<StringRef, 4> SectionFields;
GV.getSection().split(SectionFields, '.');
- StringRef DeviceTriple = SectionFields[3];
- StringRef Arch = SectionFields[4];
+ StringRef Kind = SectionFields[3];
+ StringRef DeviceTriple = SectionFields[4];
+ StringRef Arch = SectionFields[5];
StringRef Contents = CDS->getAsString();
SmallString<128> TempFile;
StringRef DeviceExtension = getDeviceFileExtension(
DeviceTriple, identify_magic(Contents) == file_magic::bitcode);
- if (Error Err =
- createOutputFile(Prefix + "-device-" + DeviceTriple + "-" + Arch,
- DeviceExtension, TempFile))
+ if (Error Err = createOutputFile(Prefix + "-" + Kind + "-" + DeviceTriple +
+ "-" + Arch,
+ DeviceExtension, TempFile))
return std::move(Err);
Expected<std::unique_ptr<FileOutputBuffer>> OutputOrErr =
@@ -433,7 +440,7 @@ extractFromBitcode(std::unique_ptr<MemoryBuffer> Buffer,
if (Error E = Output->commit())
return std::move(E);
- DeviceFiles.emplace_back(DeviceTriple, Arch, TempFile);
+ DeviceFiles.emplace_back(Kind, DeviceTriple, Arch, TempFile);
ToBeDeleted.push_back(&GV);
}
More information about the cfe-commits
mailing list