Skip to content

Commit ec072a0

Browse files
committed
[Offload][SYCL] Refactor OffloadKind implementation
Signed-off-by: Arvind Sudarsanam <[email protected]>
1 parent 5216633 commit ec072a0

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -923,10 +923,9 @@ Expected<SmallVector<StringRef>> linkAndWrapDeviceFiles(
923923
});
924924
auto LinkerArgs = getLinkerArgs(Input, BaseArgs);
925925

926-
DenseSet<OffloadKind> ActiveOffloadKinds;
926+
uint16_t ActiveOffloadKindMask = 0u;
927927
for (const auto &File : Input)
928-
if (File.getBinary()->getOffloadKind() != OFK_None)
929-
ActiveOffloadKinds.insert(File.getBinary()->getOffloadKind());
928+
ActiveOffloadKindMask |= File.getBinary()->getOffloadKind();
930929

931930
// Write any remaining device inputs to an output file.
932931
SmallVector<StringRef> InputFiles;
@@ -943,7 +942,10 @@ Expected<SmallVector<StringRef>> linkAndWrapDeviceFiles(
943942
return OutputOrErr.takeError();
944943

945944
// Store the offloading image for each linked output file.
946-
for (OffloadKind Kind : ActiveOffloadKinds) {
945+
for (OffloadKind Kind = OFK_FIRST; Kind != OFK_LAST;
946+
Kind = static_cast<OffloadKind>((uint16_t)(Kind) << 1)) {
947+
if ((ActiveOffloadKindMask & Kind) == 0)
948+
continue;
947949
llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> FileOrErr =
948950
llvm::MemoryBuffer::getFileOrSTDIN(*OutputOrErr);
949951
if (std::error_code EC = FileOrErr.getError()) {

llvm/include/llvm/Object/OffloadBinary.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,12 @@ namespace object {
3232
/// The producer of the associated offloading image.
3333
enum OffloadKind : uint16_t {
3434
OFK_None = 0,
35-
OFK_OpenMP,
36-
OFK_Cuda,
37-
OFK_HIP,
38-
OFK_LAST,
35+
OFK_OpenMP = (1 << 1),
36+
OFK_FIRST = OFK_OpenMP,
37+
OFK_Cuda = (1 << 2),
38+
OFK_HIP = (1 << 3),
39+
OFK_SYCL = (1 << 4),
40+
OFK_LAST = (1 << 5),
3941
};
4042

4143
/// The type of contents the offloading image contains.

0 commit comments

Comments
 (0)