Skip to content

Commit 674bb8c

Browse files
authored
[Driver] Allow for usage of old triple behavior in bundler (#17557)
Recent upstreamed changes force the triple usage with the bundler to use a 4-field triple value. The Intel compiler does not take well to these changes. We are not in a position to move our triple usage when bundling and unbundling (not in a breaking change period). Here, we are updating bundler behavior to allow for the older behavior of accepting triple formats that are 'incomplete'. We can move to using the forced triple value usage when we are ready or if we even need to when we move to the new offloading model.
1 parent 61356e3 commit 674bb8c

File tree

2 files changed

+57
-9
lines changed

2 files changed

+57
-9
lines changed

clang/lib/Driver/OffloadBundler.cpp

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,36 @@ OffloadTargetInfo::OffloadTargetInfo(const StringRef Target,
100100
// <triple> := <arch>-<vendor>-<os>-<env>
101101
SmallVector<StringRef, 6> Components;
102102
Target.split(Components, '-', /*MaxSplit=*/5);
103+
if (Components.size() < 5) {
104+
// Handle target inputs that do not fit the <arch>-<vendor>-<os>-<env>
105+
// triple format.
106+
auto TargetFeatures = Target.split(':');
107+
auto TripleOrGPU = TargetFeatures.first.rsplit('-');
108+
109+
if (clang::StringToOffloadArch(TripleOrGPU.second) !=
110+
clang::OffloadArch::UNKNOWN) {
111+
auto KindTriple = TripleOrGPU.first.split('-');
112+
this->OffloadKind = KindTriple.first;
113+
114+
// Enforce optional env field to standardize bundles
115+
llvm::Triple t = llvm::Triple(KindTriple.second);
116+
this->Triple = llvm::Triple(t.getArchName(), t.getVendorName(),
117+
t.getOSName(), t.getEnvironmentName());
118+
119+
this->TargetID = Target.substr(Target.find(TripleOrGPU.second));
120+
} else {
121+
auto KindTriple = TargetFeatures.first.split('-');
122+
this->OffloadKind = KindTriple.first;
123+
124+
// Enforce optional env field to standardize bundles
125+
llvm::Triple t = llvm::Triple(KindTriple.second);
126+
this->Triple = llvm::Triple(t.getArchName(), t.getVendorName(),
127+
t.getOSName(), t.getEnvironmentName());
128+
129+
this->TargetID = "";
130+
}
131+
return;
132+
}
103133
assert((Components.size() == 5 || Components.size() == 6) &&
104134
"malformed target string");
105135

@@ -2580,7 +2610,10 @@ Error OffloadBundler::UnbundleArchive() {
25802610
bool clang::checkOffloadBundleID(const llvm::StringRef Str) {
25812611
// <kind>-<triple>[-<target id>[:target features]]
25822612
// <triple> := <arch>-<vendor>-<os>-<env>
2583-
SmallVector<StringRef, 6> Components;
2584-
Str.split(Components, '-', /*MaxSplit=*/5);
2585-
return Components.size() == 5 || Components.size() == 6;
2613+
// FIXME: The Intel Compiler does not currently adhere to the strict
2614+
// component size. Consider all checks valid.
2615+
// SmallVector<StringRef, 6> Components;
2616+
// Str.split(Components, '-', /*MaxSplit=*/5);
2617+
// return Components.size() == 5 || Components.size() == 6;
2618+
return true;
25862619
}

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9959,7 +9959,15 @@ void OffloadBundler::ConstructJob(Compilation &C, const JobAction &JA,
99599959
T.setArchName(ArchName);
99609960
Triples += T.normalize();
99619961
} else {
9962-
Triples += CurTC->getTriple().normalize(llvm::Triple::CanonicalForm::FOUR_IDENT);
9962+
// Use of the 4-field triple will be done for HIP only, with other
9963+
// offload targets not being modified.
9964+
// TODO: All targets should use the 4-field triple, which can be done
9965+
// during an ABI breaking juncture.
9966+
if (CurKind == Action::OFK_HIP)
9967+
Triples += CurTC->getTriple().normalize(
9968+
llvm::Triple::CanonicalForm::FOUR_IDENT);
9969+
else
9970+
Triples += CurTC->getTriple().normalize();
99639971
}
99649972
if ((CurKind == Action::OFK_HIP || CurKind == Action::OFK_OpenMP ||
99659973
CurKind == Action::OFK_Cuda || CurKind == Action::OFK_SYCL) &&
@@ -10188,11 +10196,18 @@ void OffloadBundler::ConstructJobMultipleOutputs(
1018810196
StringRef Val(
1018910197
TCArgs.getLastArg(options::OPT_fsycl_force_target_EQ)->getValue());
1019010198
llvm::Triple TT(C.getDriver().getSYCLDeviceTriple(Val));
10191-
Triples += TT.normalize(
10192-
llvm::Triple::CanonicalForm::FOUR_IDENT);
10193-
} else
10194-
Triples += Dep.DependentToolChain->getTriple().normalize(
10195-
llvm::Triple::CanonicalForm::FOUR_IDENT);
10199+
Triples += TT.normalize();
10200+
} else {
10201+
// Use of the 4-field triple will be done for HIP only, with other
10202+
// offload targets not being modified.
10203+
// TODO: All targets should use the 4-field triple, which can be done
10204+
// during an ABI breaking juncture.
10205+
if (Dep.DependentOffloadKind == Action::OFK_HIP)
10206+
Triples += Dep.DependentToolChain->getTriple().normalize(
10207+
llvm::Triple::CanonicalForm::FOUR_IDENT);
10208+
else
10209+
Triples += Dep.DependentToolChain->getTriple().normalize();
10210+
}
1019610211
if ((Dep.DependentOffloadKind == Action::OFK_HIP ||
1019710212
Dep.DependentOffloadKind == Action::OFK_OpenMP ||
1019810213
Dep.DependentOffloadKind == Action::OFK_Cuda ||

0 commit comments

Comments
 (0)