Skip to content

Commit 843cb90

Browse files
committed
Align clang-linker-wrapper flow with community flow
Signed-off-by: Arvind Sudarsanam <[email protected]>
1 parent dbdabfb commit 843cb90

File tree

2 files changed

+12
-43
lines changed

2 files changed

+12
-43
lines changed

clang/test/Driver/linker-wrapper.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ __attribute__((visibility("protected"), used)) int x;
5454
// RUN: clang-offload-packager -o %t.out \
5555
// RUN: --image=file=%t.spirv.bc,kind=sycl,triple=spirv64-unknown-unknown,arch=generic
5656
// RUN: %clang -cc1 %s -triple x86_64-unknown-linux-gnu -emit-obj -o %t.o -fembed-offload-object=%t.out
57-
// RUN: clang-linker-wrapper --host-triple=x86_64-unknown-linux-gnu --dry-run \
57+
// RUN: not clang-linker-wrapper --host-triple=x86_64-unknown-linux-gnu --dry-run \
5858
// RUN: --linker-path=/usr/bin/ld %t.o -o a.out 2>&1 | FileCheck %s --check-prefix=SPIRV-LINK
5959

6060
// SPIRV-LINK: clang{{.*}} -o {{.*}}.img --target=spirv64-unknown-unknown {{.*}}.o --sycl-link -Xlinker -triple=spirv64-unknown-unknown -Xlinker -arch=

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

Lines changed: 11 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -805,6 +805,7 @@ bundleLinkedOutput(ArrayRef<OffloadingImage> Images, const ArgList &Args,
805805
llvm::TimeTraceScope TimeScope("Bundle linked output");
806806
switch (Kind) {
807807
case OFK_OpenMP:
808+
case OFK_SYCL:
808809
return bundleOpenMP(Images);
809810
case OFK_Cuda:
810811
return bundleCuda(Images, Args);
@@ -940,6 +941,14 @@ Expected<SmallVector<StringRef>> linkAndWrapDeviceFiles(
940941
for (const auto &File : Input)
941942
ActiveOffloadKindMask |= File.getBinary()->getOffloadKind();
942943

944+
// Linking images of SYCL offload kind with images of other kind is not
945+
// supported.
946+
// TODO: Remove the above limitation.
947+
if ((ActiveOffloadKindMask & OFK_SYCL) &&
948+
((ActiveOffloadKindMask ^ OFK_SYCL) != 0))
949+
return createStringError("Linking images of SYCL offload kind with "
950+
"images of any other kind is not supported");
951+
943952
// Write any remaining device inputs to an output file.
944953
SmallVector<StringRef> InputFiles;
945954
for (const OffloadFile &File : Input) {
@@ -949,42 +958,6 @@ Expected<SmallVector<StringRef>> linkAndWrapDeviceFiles(
949958
InputFiles.emplace_back(*FileNameOrErr);
950959
}
951960

952-
// Currently, SYCL device code linking process differs from generic device
953-
// code linking.
954-
// TODO: Align SYCL device code linking with generic linking.
955-
if (ActiveOffloadKindMask & OFK_SYCL) {
956-
// Link the remaining device files using the device linker.
957-
auto OutputOrErr =
958-
linkDevice(InputFiles, LinkerArgs, ActiveOffloadKindMask);
959-
if (!OutputOrErr)
960-
return OutputOrErr.takeError();
961-
// Output is a packaged object of device images. Unpackage the images and
962-
// copy them to Images[Kind]
963-
ErrorOr<std::unique_ptr<MemoryBuffer>> BufferOrErr =
964-
MemoryBuffer::getFileOrSTDIN(*OutputOrErr);
965-
if (std::error_code EC = BufferOrErr.getError())
966-
return createFileError(*OutputOrErr, EC);
967-
968-
MemoryBufferRef Buffer = **BufferOrErr;
969-
SmallVector<OffloadFile> Binaries;
970-
if (Error Err = extractOffloadBinaries(Buffer, Binaries))
971-
return std::move(Err);
972-
for (auto &OffloadFile : Binaries) {
973-
auto TheBinary = OffloadFile.getBinary();
974-
OffloadingImage TheImage{};
975-
TheImage.TheImageKind = TheBinary->getImageKind();
976-
TheImage.TheOffloadKind = TheBinary->getOffloadKind();
977-
TheImage.StringData["triple"] = TheBinary->getTriple();
978-
TheImage.StringData["arch"] = TheBinary->getArch();
979-
TheImage.Image = MemoryBuffer::getMemBufferCopy(TheBinary->getImage());
980-
Images[OFK_SYCL].emplace_back(std::move(TheImage));
981-
}
982-
}
983-
984-
// Exit early if no other offload kind found (other than OFK_SYCL).
985-
if ((ActiveOffloadKindMask ^ OFK_SYCL) == 0)
986-
return Error::success();
987-
988961
// Link the remaining device files using the device linker.
989962
auto OutputOrErr =
990963
linkDevice(InputFiles, LinkerArgs, ActiveOffloadKindMask);
@@ -994,7 +967,7 @@ Expected<SmallVector<StringRef>> linkAndWrapDeviceFiles(
994967
// Store the offloading image for each linked output file.
995968
for (OffloadKind Kind = OFK_OpenMP; Kind != OFK_LAST;
996969
Kind = static_cast<OffloadKind>((uint16_t)(Kind) << 1)) {
997-
if (((ActiveOffloadKindMask & Kind) == 0) || (Kind == OFK_SYCL))
970+
if ((ActiveOffloadKindMask & Kind) == 0)
998971
continue;
999972
llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> FileOrErr =
1000973
llvm::MemoryBuffer::getFileOrSTDIN(*OutputOrErr);
@@ -1011,6 +984,7 @@ Expected<SmallVector<StringRef>> linkAndWrapDeviceFiles(
1011984

1012985
std::scoped_lock<decltype(ImageMtx)> Guard(ImageMtx);
1013986
OffloadingImage TheImage{};
987+
1014988
TheImage.TheImageKind =
1015989
Args.hasArg(OPT_embed_bitcode) ? IMG_Bitcode : IMG_Object;
1016990
TheImage.TheOffloadKind = Kind;
@@ -1038,11 +1012,6 @@ Expected<SmallVector<StringRef>> linkAndWrapDeviceFiles(
10381012
A.StringData["arch"] > B.StringData["arch"] ||
10391013
A.TheOffloadKind < B.TheOffloadKind;
10401014
});
1041-
if (Kind == OFK_SYCL) {
1042-
// TODO: Update once SYCL offload wrapping logic is available.
1043-
reportError(
1044-
createStringError("SYCL offload wrapping logic is not available"));
1045-
}
10461015
auto BundledImagesOrErr = bundleLinkedOutput(Input, Args, Kind);
10471016
if (!BundledImagesOrErr)
10481017
return BundledImagesOrErr.takeError();

0 commit comments

Comments
 (0)