Skip to content

Commit 0b0317a

Browse files
committed
Support bundles with deprecated triple
Add a workaround to clang-offload-bundler to support bundles produced by previous versions of the compiler
1 parent 464dad8 commit 0b0317a

File tree

1 file changed

+33
-4
lines changed

1 file changed

+33
-4
lines changed

clang/tools/clang-offload-bundler/ClangOffloadBundler.cpp

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1404,8 +1404,21 @@ static Error UnbundleFiles() {
14041404
auto Output = Worklist.find(CurTriple);
14051405
// The file may have more bundles for other targets, that we don't care
14061406
// about. Therefore, move on to the next triple
1407-
if (Output == Worklist.end())
1408-
continue;
1407+
if (Output == Worklist.end()) {
1408+
// FIXME: temporary solution for supporting binaries produced by old
1409+
// versions of SYCL toolchain. Old versions used triples with 'sycldevice'
1410+
// environment component of the triple, whereas new toolchain use
1411+
// 'unknown' value for that triple component. Here we assume that if we
1412+
// are looking for a bundle for sycl offload kind, for the same target
1413+
// triple there might be either one with 'sycldevice' environment or with
1414+
// 'unknown' environment, but not both. So we will look for any of these
1415+
// two variants.
1416+
Output =
1417+
Worklist.find(CurTriple.drop_back(11 /*length of "-sycldevice"*/));
1418+
if (!CurTriple.startswith("sycl-") ||
1419+
!CurTriple.endswith("-sycldevice") || Output == Worklist.end())
1420+
continue;
1421+
}
14091422

14101423
// Check if the output file can be opened and copy the bundle to it.
14111424
std::error_code EC;
@@ -1507,7 +1520,21 @@ static Expected<bool> CheckBundledSection() {
15071520
return std::move(Err);
15081521

15091522
StringRef triple = TargetNames.front();
1510-
// Read all the bundles that are in the work list. If we find no bundles we
1523+
1524+
// FIXME: temporary solution for supporting binaries produced by old versions
1525+
// of SYCL toolchain. Old versions used triples with 'sycldevice' environment
1526+
// component of the triple, whereas new toolchain use 'unknown' value for that
1527+
// triple component. Here we assume that if we are looking for a bundle for
1528+
// sycl offload kind, for the same target triple there might be either one
1529+
// with 'sycldevice' environment or with 'unknown' environment, but not both.
1530+
// So we will look for any of these two variants.
1531+
OffloadTargetInfo TI(triple);
1532+
bool checkCompatibleTriple =
1533+
(TI.OffloadKind == "sycl") &&
1534+
(TI.Triple.getEnvironment() == Triple::UnknownEnvironment);
1535+
TI.Triple.setEnvironmentName("sycldevice");
1536+
std::string compatibleTriple = Twine("sycl-" + TI.Triple.str()).str();
1537+
15111538
// assume the file is meant for the host target.
15121539
bool found = false;
15131540
while (!found) {
@@ -1519,7 +1546,9 @@ static Expected<bool> CheckBundledSection() {
15191546
if (!*CurTripleOrErr)
15201547
break;
15211548

1522-
if (*CurTripleOrErr == triple) {
1549+
if (*CurTripleOrErr == triple ||
1550+
(checkCompatibleTriple &&
1551+
*CurTripleOrErr == StringRef(compatibleTriple))) {
15231552
found = true;
15241553
break;
15251554
}

0 commit comments

Comments
 (0)