Skip to content

Commit 61b4f8a

Browse files
mdtoguchijsji
authored andcommitted
[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 2c1d416 commit 61b4f8a

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

@@ -2527,7 +2557,10 @@ Error OffloadBundler::UnbundleArchive() {
25272557
bool clang::checkOffloadBundleID(const llvm::StringRef Str) {
25282558
// <kind>-<triple>[-<target id>[:target features]]
25292559
// <triple> := <arch>-<vendor>-<os>-<env>
2530-
SmallVector<StringRef, 6> Components;
2531-
Str.split(Components, '-', /*MaxSplit=*/5);
2532-
return Components.size() == 5 || Components.size() == 6;
2560+
// FIXME: The Intel Compiler does not currently adhere to the strict
2561+
// component size. Consider all checks valid.
2562+
// SmallVector<StringRef, 6> Components;
2563+
// Str.split(Components, '-', /*MaxSplit=*/5);
2564+
// return Components.size() == 5 || Components.size() == 6;
2565+
return true;
25332566
}

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9954,7 +9954,15 @@ void OffloadBundler::ConstructJob(Compilation &C, const JobAction &JA,
99549954
T.setArchName(ArchName);
99559955
Triples += T.normalize();
99569956
} else {
9957-
Triples += CurTC->getTriple().normalize(llvm::Triple::CanonicalForm::FOUR_IDENT);
9957+
// Use of the 4-field triple will be done for HIP only, with other
9958+
// offload targets not being modified.
9959+
// TODO: All targets should use the 4-field triple, which can be done
9960+
// during an ABI breaking juncture.
9961+
if (CurKind == Action::OFK_HIP)
9962+
Triples += CurTC->getTriple().normalize(
9963+
llvm::Triple::CanonicalForm::FOUR_IDENT);
9964+
else
9965+
Triples += CurTC->getTriple().normalize();
99589966
}
99599967
if ((CurKind == Action::OFK_HIP || CurKind == Action::OFK_OpenMP ||
99609968
CurKind == Action::OFK_Cuda || CurKind == Action::OFK_SYCL) &&
@@ -10183,11 +10191,18 @@ void OffloadBundler::ConstructJobMultipleOutputs(
1018310191
StringRef Val(
1018410192
TCArgs.getLastArg(options::OPT_fsycl_force_target_EQ)->getValue());
1018510193
llvm::Triple TT(C.getDriver().getSYCLDeviceTriple(Val));
10186-
Triples += TT.normalize(
10187-
llvm::Triple::CanonicalForm::FOUR_IDENT);
10188-
} else
10189-
Triples += Dep.DependentToolChain->getTriple().normalize(
10190-
llvm::Triple::CanonicalForm::FOUR_IDENT);
10194+
Triples += TT.normalize();
10195+
} else {
10196+
// Use of the 4-field triple will be done for HIP only, with other
10197+
// offload targets not being modified.
10198+
// TODO: All targets should use the 4-field triple, which can be done
10199+
// during an ABI breaking juncture.
10200+
if (Dep.DependentOffloadKind == Action::OFK_HIP)
10201+
Triples += Dep.DependentToolChain->getTriple().normalize(
10202+
llvm::Triple::CanonicalForm::FOUR_IDENT);
10203+
else
10204+
Triples += Dep.DependentToolChain->getTriple().normalize();
10205+
}
1019110206
if ((Dep.DependentOffloadKind == Action::OFK_HIP ||
1019210207
Dep.DependentOffloadKind == Action::OFK_OpenMP ||
1019310208
Dep.DependentOffloadKind == Action::OFK_Cuda ||

0 commit comments

Comments
 (0)