Skip to content

Commit 09a5eae

Browse files
committed
[clang-offload-bundler] add -input/-output options
Currently, clang-offload-bundler has -inputs and -outputs options that accept values with comma as the delimiter. This causes issues with file paths containing commas, which are valid file paths on Linux. This add two new options -input and -output, which accept one single file, and allow multiple instances. This allows arbitrary file paths. The old -inputs and -outputs options will be kept for backward compatibility, but are not allowed to be used with -input and -output options for simplicity. In the future, -inputs and -outputs options will be phasing out. RFC: https://discourse.llvm.org/t/rfc-adding-input-and-output-options-to-clang-offload-bundler/60049 Patch by: Siu Chi Chan Reviewed by: Yaxun Liu Differential Revision: https://reviews.llvm.org/D120662
1 parent 012e90b commit 09a5eae

25 files changed

+280
-215
lines changed

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8028,8 +8028,10 @@ void OffloadBundler::ConstructJob(Compilation &C, const JobAction &JA,
80288028
// The bundling command looks like this:
80298029
// clang-offload-bundler -type=bc
80308030
// -targets=host-triple,openmp-triple1,openmp-triple2
8031-
// -outputs=input_file
8032-
// -inputs=unbundle_file_host,unbundle_file_tgt1,unbundle_file_tgt2"
8031+
// -output=output_file
8032+
// -input=unbundle_file_host
8033+
// -input=unbundle_file_tgt1
8034+
// -input=unbundle_file_tgt2
80338035

80348036
ArgStringList CmdArgs;
80358037

@@ -8090,14 +8092,12 @@ void OffloadBundler::ConstructJob(Compilation &C, const JobAction &JA,
80908092

80918093
// Get bundled file command.
80928094
CmdArgs.push_back(
8093-
TCArgs.MakeArgString(Twine("-outputs=") + Output.getFilename()));
8095+
TCArgs.MakeArgString(Twine("-output=") + Output.getFilename()));
80948096

80958097
// Get unbundled files command.
8096-
SmallString<128> UB;
8097-
UB += "-inputs=";
80988098
for (unsigned I = 0; I < Inputs.size(); ++I) {
8099-
if (I)
8100-
UB += ',';
8099+
SmallString<128> UB;
8100+
UB += "-input=";
81018101

81028102
// Find ToolChain for this input.
81038103
const ToolChain *CurTC = &getToolChain();
@@ -8112,9 +8112,8 @@ void OffloadBundler::ConstructJob(Compilation &C, const JobAction &JA,
81128112
} else {
81138113
UB += CurTC->getInputFilename(Inputs[I]);
81148114
}
8115+
CmdArgs.push_back(TCArgs.MakeArgString(UB));
81158116
}
8116-
CmdArgs.push_back(TCArgs.MakeArgString(UB));
8117-
81188117
// All the inputs are encoded as commands.
81198118
C.addCommand(std::make_unique<Command>(
81208119
JA, *this, ResponseFileSupport::None(),
@@ -8132,8 +8131,10 @@ void OffloadBundler::ConstructJobMultipleOutputs(
81328131
// The unbundling command looks like this:
81338132
// clang-offload-bundler -type=bc
81348133
// -targets=host-triple,openmp-triple1,openmp-triple2
8135-
// -inputs=input_file
8136-
// -outputs=unbundle_file_host,unbundle_file_tgt1,unbundle_file_tgt2"
8134+
// -input=input_file
8135+
// -output=unbundle_file_host
8136+
// -output=unbundle_file_tgt1
8137+
// -output=unbundle_file_tgt2
81378138
// -unbundle
81388139

81398140
ArgStringList CmdArgs;
@@ -8185,17 +8186,15 @@ void OffloadBundler::ConstructJobMultipleOutputs(
81858186

81868187
// Get bundled file command.
81878188
CmdArgs.push_back(
8188-
TCArgs.MakeArgString(Twine("-inputs=") + Input.getFilename()));
8189+
TCArgs.MakeArgString(Twine("-input=") + Input.getFilename()));
81898190

81908191
// Get unbundled files command.
8191-
SmallString<128> UB;
8192-
UB += "-outputs=";
81938192
for (unsigned I = 0; I < Outputs.size(); ++I) {
8194-
if (I)
8195-
UB += ',';
8193+
SmallString<128> UB;
8194+
UB += "-output=";
81968195
UB += DepInfo[I].DependentToolChain->getInputFilename(Outputs[I]);
8196+
CmdArgs.push_back(TCArgs.MakeArgString(UB));
81978197
}
8198-
CmdArgs.push_back(TCArgs.MakeArgString(UB));
81998198
CmdArgs.push_back("-unbundle");
82008199
CmdArgs.push_back("-allow-missing-bundles");
82018200

clang/lib/Driver/ToolChains/CommonArgs.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1777,9 +1777,9 @@ bool tools::GetSDLFromOffloadArchive(
17771777

17781778
std::string UnbundleArg("-unbundle");
17791779
std::string TypeArg("-type=a");
1780-
std::string InputArg("-inputs=" + ArchiveOfBundles);
1780+
std::string InputArg("-input=" + ArchiveOfBundles);
17811781
std::string OffloadArg("-targets=" + std::string(DeviceTriple));
1782-
std::string OutputArg("-outputs=" + OutputLib);
1782+
std::string OutputArg("-output=" + OutputLib);
17831783

17841784
const char *UBProgram = DriverArgs.MakeArgString(
17851785
T.getToolChain().GetProgramPath("clang-offload-bundler"));

clang/lib/Driver/ToolChains/HIPUtility.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,6 @@ void HIP::constructHIPFatbinCommand(Compilation &C, const JobAction &JA,
5353
// ToDo: Remove the dummy host binary entry which is required by
5454
// clang-offload-bundler.
5555
std::string BundlerTargetArg = "-targets=host-x86_64-unknown-linux";
56-
std::string BundlerInputArg = "-inputs=" NULL_FILE;
57-
5856
// AMDGCN:
5957
// For code object version 2 and 3, the offload kind in bundle ID is 'hip'
6058
// for backward compatibility. For code object version 4 and greater, the
@@ -70,14 +68,20 @@ void HIP::constructHIPFatbinCommand(Compilation &C, const JobAction &JA,
7068
"," + OffloadKind + "-" + normalizeForBundler(TT, !ArchStr.empty());
7169
if (!ArchStr.empty())
7270
BundlerTargetArg += "-" + ArchStr.str();
73-
BundlerInputArg = BundlerInputArg + "," + II.getFilename();
7471
}
7572
BundlerArgs.push_back(Args.MakeArgString(BundlerTargetArg));
73+
74+
// Use a NULL file as input for the dummy host binary entry
75+
std::string BundlerInputArg = "-input=" NULL_FILE;
7676
BundlerArgs.push_back(Args.MakeArgString(BundlerInputArg));
77+
for (const auto &II : Inputs) {
78+
BundlerInputArg = std::string("-input=") + II.getFilename();
79+
BundlerArgs.push_back(Args.MakeArgString(BundlerInputArg));
80+
}
7781

7882
std::string Output = std::string(OutputFileName);
7983
auto *BundlerOutputArg =
80-
Args.MakeArgString(std::string("-outputs=").append(Output));
84+
Args.MakeArgString(std::string("-output=").append(Output));
8185
BundlerArgs.push_back(BundlerOutputArg);
8286

8387
const char *Bundler = Args.MakeArgString(

clang/test/Driver/clang-offload-bundler-asserts-on.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,16 @@
1515
// Check code object compatibility for archive unbundling
1616
//
1717
// Create few code object bundles and archive them to create an input archive
18-
// RUN: clang-offload-bundler -type=o -targets=host-%itanium_abi_triple,openmp-amdgcn-amd-amdhsa-gfx906,openmp-amdgcn-amd-amdhsa--gfx908 -inputs=%t.o,%t.tgt1,%t.tgt2 -outputs=%t.simple.bundle
19-
// RUN: clang-offload-bundler -type=o -targets=host-%itanium_abi_triple,openmp-amdgcn-amd-amdhsa--gfx903 -inputs=%t.o,%t.tgt1 -outputs=%t.simple1.bundle
18+
// RUN: clang-offload-bundler -type=o -targets=host-%itanium_abi_triple,openmp-amdgcn-amd-amdhsa-gfx906,openmp-amdgcn-amd-amdhsa--gfx908 -input=%t.o -input=%t.tgt1 -input=%t.tgt2 -output=%t.simple.bundle
19+
// RUN: clang-offload-bundler -type=o -targets=host-%itanium_abi_triple,openmp-amdgcn-amd-amdhsa--gfx903 -input=%t.o -input=%t.tgt1 -output=%t.simple1.bundle
2020
// RUN: llvm-ar cr %t.input-archive.a %t.simple.bundle %t.simple1.bundle
2121

2222
// Tests to check compatibility between Bundle Entry ID formats i.e. between presence/absence of extra hyphen in case of missing environment field
23-
// RUN: clang-offload-bundler -unbundle -type=a -targets=openmp-amdgcn-amd-amdhsa--gfx906,openmp-amdgcn-amd-amdhsa-gfx908 -inputs=%t.input-archive.a -outputs=%t-archive-gfx906-simple.a,%t-archive-gfx908-simple.a -debug-only=CodeObjectCompatibility 2>&1 | FileCheck %s -check-prefix=BUNDLECOMPATIBILITY
23+
// RUN: clang-offload-bundler -unbundle -type=a -targets=openmp-amdgcn-amd-amdhsa--gfx906,openmp-amdgcn-amd-amdhsa-gfx908 -input=%t.input-archive.a -output=%t-archive-gfx906-simple.a -output=%t-archive-gfx908-simple.a -debug-only=CodeObjectCompatibility 2>&1 | FileCheck %s -check-prefix=BUNDLECOMPATIBILITY
2424
// BUNDLECOMPATIBILITY: Compatible: Exact match: [CodeObject: openmp-amdgcn-amd-amdhsa-gfx906] : [Target: openmp-amdgcn-amd-amdhsa--gfx906]
2525
// BUNDLECOMPATIBILITY: Compatible: Exact match: [CodeObject: openmp-amdgcn-amd-amdhsa--gfx908] : [Target: openmp-amdgcn-amd-amdhsa-gfx908]
2626

27-
// RUN: clang-offload-bundler -unbundle -type=a -targets=hip-amdgcn-amd-amdhsa--gfx906,hipv4-amdgcn-amd-amdhsa-gfx908 -inputs=%t.input-archive.a -outputs=%t-hip-archive-gfx906-simple.a,%t-hipv4-archive-gfx908-simple.a -hip-openmp-compatible -debug-only=CodeObjectCompatibility 2>&1 | FileCheck %s -check-prefix=HIPOpenMPCOMPATIBILITY
27+
// RUN: clang-offload-bundler -unbundle -type=a -targets=hip-amdgcn-amd-amdhsa--gfx906,hipv4-amdgcn-amd-amdhsa-gfx908 -input=%t.input-archive.a -output=%t-hip-archive-gfx906-simple.a -output=%t-hipv4-archive-gfx908-simple.a -hip-openmp-compatible -debug-only=CodeObjectCompatibility 2>&1 | FileCheck %s -check-prefix=HIPOpenMPCOMPATIBILITY
2828
// HIPOpenMPCOMPATIBILITY: Compatible: Code Objects are compatible [CodeObject: openmp-amdgcn-amd-amdhsa-gfx906] : [Target: hip-amdgcn-amd-amdhsa--gfx906]
2929
// HIPOpenMPCOMPATIBILITY: Compatible: Code Objects are compatible [CodeObject: openmp-amdgcn-amd-amdhsa--gfx908] : [Target: hipv4-amdgcn-amd-amdhsa-gfx908]
3030

0 commit comments

Comments
 (0)