Skip to content

Commit 3e474e0

Browse files
authored
[New offload model] Cleanup the way sycl-post-link options are generated (#14177)
In an earlier PR (#14101), we added support to generate sycl-post-link options (that partly depend on target triple) in clang Driver and then update the options using target triple information in the clang-linker-wrapper. This PR cleans up that implementation by fully generating these options inside the clang-linker-wrapper. This requires some more user-specified options to be passed into the clang-linker-wrapper. Thanks ------ Signed-off-by: Arvind Sudarsanam <[email protected]>
1 parent 877e5fa commit 3e474e0

File tree

8 files changed

+145
-116
lines changed

8 files changed

+145
-116
lines changed

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 29 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -10648,31 +10648,34 @@ static void getNonTripleBasedSYCLPostLinkOpts(const ToolChain &TC,
1064810648
addArgs(PostLinkArgs, TCArgs, {"-lower-esimd-force-stateless-mem=false"});
1064910649
}
1065010650

10651-
// Add any sycl-post-link options that rely on a specific Triple.
10652-
static void
10653-
getTripleBasedSYCLPostLinkOpts(const ToolChain &TC, const JobAction &JA,
10654-
const llvm::opt::ArgList &TCArgs,
10655-
llvm::Triple Triple, ArgStringList &PostLinkArgs,
10656-
bool SpecConsts, types::ID OutputType) {
10657-
bool NewOffloadDriver = TC.getDriver().getUseNewOffloadingDriver();
10658-
// Note: Do not use Triple when NewOffloadDriver is 'true'.
10659-
if (!NewOffloadDriver && (OutputType == types::TY_LLVM_BC)) {
10651+
// Add any sycl-post-link options that rely on a specific Triple in addition
10652+
// to user supplied options. This function is invoked only for the old
10653+
// offloading model. For the new offloading model, a slightly modified version
10654+
// of this function is called inside clang-linker-wrapper.
10655+
// NOTE: Any changes made here should be reflected in the similarly named
10656+
// function in clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp.
10657+
static void getTripleBasedSYCLPostLinkOpts(const ToolChain &TC,
10658+
const llvm::opt::ArgList &TCArgs,
10659+
ArgStringList &PostLinkArgs,
10660+
llvm::Triple Triple,
10661+
bool SpecConstsSupported,
10662+
types::ID OutputType) {
10663+
if (OutputType == types::TY_LLVM_BC) {
1066010664
// single file output requested - this means only perform necessary IR
1066110665
// transformations (like specialization constant intrinsic lowering) and
1066210666
// output LLVMIR
1066310667
addArgs(PostLinkArgs, TCArgs, {"-ir-output-only"});
1066410668
}
10665-
// specialization constants processing is mandatory
10666-
if (SpecConsts)
10669+
if (SpecConstsSupported)
1066710670
addArgs(PostLinkArgs, TCArgs, {"-spec-const=native"});
1066810671
else
1066910672
addArgs(PostLinkArgs, TCArgs, {"-spec-const=emulation"});
1067010673

1067110674
// See if device code splitting is requested. The logic here works along side
10672-
// the behavior in setOtherSYCLPostLinkOpts, where the option is added based
10673-
// on the user setting of-fsycl-device-code-split.
10675+
// the behavior in getNonTripleBasedSYCLPostLinkOpts, where the option is
10676+
// added based on the user setting of -fsycl-device-code-split.
1067410677
if (!TCArgs.hasArg(options::OPT_fsycl_device_code_split_EQ) &&
10675-
(NewOffloadDriver || !(Triple.getArchName() == "spir64_fpga")))
10678+
(Triple.getArchName() != "spir64_fpga"))
1067610679
addArgs(PostLinkArgs, TCArgs, {"-split=auto"});
1067710680

1067810681
// On Intel targets we don't need non-kernel functions as entry points,
@@ -10683,18 +10686,17 @@ getTripleBasedSYCLPostLinkOpts(const ToolChain &TC, const JobAction &JA,
1068310686
options::OPT_fsycl_remove_unused_external_funcs,
1068410687
false) &&
1068510688
!isSYCLNativeCPU(TC)) &&
10686-
(NewOffloadDriver || (!Triple.isNVPTX() && !Triple.isAMDGPU())))
10689+
!Triple.isNVPTX() && !Triple.isAMDGPU())
1068710690
addArgs(PostLinkArgs, TCArgs, {"-emit-only-kernels-as-entry-points"});
1068810691

10689-
if (!NewOffloadDriver && !Triple.isAMDGCN())
10692+
if (!Triple.isAMDGCN())
1069010693
addArgs(PostLinkArgs, TCArgs, {"-emit-param-info"});
1069110694
// Enable program metadata
10692-
if ((!NewOffloadDriver && (Triple.isNVPTX() || Triple.isAMDGCN())) ||
10693-
isSYCLNativeCPU(TC))
10695+
if (Triple.isNVPTX() || Triple.isAMDGCN() || isSYCLNativeCPU(TC))
1069410696
addArgs(PostLinkArgs, TCArgs, {"-emit-program-metadata"});
1069510697
if (OutputType != types::TY_LLVM_BC) {
1069610698
assert(OutputType == types::TY_Tempfiletable);
10697-
bool SplitEsimdByDefault = !NewOffloadDriver && Triple.isSPIROrSPIRV();
10699+
bool SplitEsimdByDefault = Triple.isSPIROrSPIRV();
1069810700
bool SplitEsimd = TCArgs.hasFlag(
1069910701
options::OPT_fsycl_device_code_split_esimd,
1070010702
options::OPT_fno_sycl_device_code_split_esimd, SplitEsimdByDefault);
@@ -10714,7 +10716,7 @@ getTripleBasedSYCLPostLinkOpts(const ToolChain &TC, const JobAction &JA,
1071410716
if (TCArgs.hasFlag(options::OPT_fsycl_add_default_spec_consts_image,
1071510717
options::OPT_fno_sycl_add_default_spec_consts_image,
1071610718
false) &&
10717-
(IsAOT || NewOffloadDriver))
10719+
IsAOT)
1071810720
addArgs(PostLinkArgs, TCArgs,
1071910721
{"-generate-device-image-default-spec-consts"});
1072010722
}
@@ -10738,7 +10740,7 @@ void SYCLPostLink::ConstructJob(Compilation &C, const JobAction &JA,
1073810740

1073910741
llvm::Triple T = getToolChain().getTriple();
1074010742
getNonTripleBasedSYCLPostLinkOpts(getToolChain(), JA, TCArgs, CmdArgs);
10741-
getTripleBasedSYCLPostLinkOpts(getToolChain(), JA, TCArgs, T, CmdArgs,
10743+
getTripleBasedSYCLPostLinkOpts(getToolChain(), TCArgs, CmdArgs, T,
1074210744
SYCLPostLink->getRTSetsSpecConstants(),
1074310745
SYCLPostLink->getTrueType());
1074410746

@@ -10749,8 +10751,6 @@ void SYCLPostLink::ConstructJob(Compilation &C, const JobAction &JA,
1074910751
if (T.getSubArch() == llvm::Triple::SPIRSubArch_gen && Device.data())
1075010752
OutputArg = ("intel_gpu_" + Device + "," + OutputArg).str();
1075110753

10752-
addArgs(CmdArgs, TCArgs, {"-o", OutputArg});
10753-
1075410754
const toolchains::SYCLToolChain &TC =
1075510755
static_cast<const toolchains::SYCLToolChain &>(getToolChain());
1075610756

@@ -10759,6 +10759,8 @@ void SYCLPostLink::ConstructJob(Compilation &C, const JobAction &JA,
1075910759
options::OPT_Xdevice_post_link_EQ,
1076010760
JA.getOffloadingArch());
1076110761

10762+
addArgs(CmdArgs, TCArgs, {"-o", OutputArg});
10763+
1076210764
// Add input file
1076310765
assert(Inputs.size() == 1 && Inputs.front().isFilename() &&
1076410766
"single input file expected");
@@ -11111,24 +11113,14 @@ void LinkerWrapper::ConstructJob(Compilation &C, const JobAction &JA,
1111111113
// --sycl-post-link-options="options" provides a string of options to be
1111211114
// passed along to the sycl-post-link tool during device link.
1111311115
SmallString<128> PostLinkOptString;
11114-
if (Args.hasArg(options::OPT_Xdevice_post_link)) {
11115-
for (const auto &A : Args.getAllArgValues(options::OPT_Xdevice_post_link))
11116-
appendOption(PostLinkOptString, A);
11117-
}
1111811116
ArgStringList PostLinkArgs;
11119-
bool IsSYCLNativeCPU = driver::isSYCLNativeCPU(Args);
11120-
types::ID OutputType = TargetTriple.isSPIROrSPIRV() || IsSYCLNativeCPU
11121-
? types::TY_Tempfiletable
11122-
: types::TY_LLVM_BC;
11123-
bool SpecConsts = TargetTriple.isSPIROrSPIRV();
1112411117
getNonTripleBasedSYCLPostLinkOpts(getToolChain(), JA, Args, PostLinkArgs);
11125-
// Some options like -spec-consts=* depend on target triple as well as some
11126-
// user options. So, these options are partly computed here and then
11127-
// updated inside the clang-linker-wrapper.
11128-
getTripleBasedSYCLPostLinkOpts(getToolChain(), JA, Args, TargetTriple,
11129-
PostLinkArgs, SpecConsts, OutputType);
1113011118
for (const auto &A : PostLinkArgs)
1113111119
appendOption(PostLinkOptString, A);
11120+
if (Args.hasArg(options::OPT_Xdevice_post_link)) {
11121+
for (const auto &A : Args.getAllArgValues(options::OPT_Xdevice_post_link))
11122+
appendOption(PostLinkOptString, A);
11123+
}
1113211124
if (!PostLinkOptString.empty())
1113311125
CmdArgs.push_back(
1113411126
Args.MakeArgString("--sycl-post-link-options=" + PostLinkOptString));

clang/test/Driver/linker-wrapper-sycl-win.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
// CHK-CMDS: "{{.*}}spirv-to-ir-wrapper.exe" {{.*}} -o [[FIRSTLLVMLINKIN:.*]].bc --llvm-spirv-opts=--spirv-preserve-auxdata --llvm-spirv-opts=--spirv-target-env=SPV-IR --llvm-spirv-opts=--spirv-builtin-format=global
66
// CHK-CMDS-NEXT: "{{.*}}llvm-link.exe" [[FIRSTLLVMLINKIN:.*]].bc -o [[FIRSTLLVMLINKOUT:.*]].bc --suppress-warnings
77
// CHK-CMDS-NEXT: "{{.*}}llvm-link.exe" -only-needed [[FIRSTLLVMLINKOUT]].bc {{.*}}.bc {{.*}}.bc -o [[SECONDLLVMLINKOUT:.*]].bc --suppress-warnings
8-
// CHK-CMDS-NEXT: "{{.*}}sycl-post-link.exe" SYCL_POST_LINK_OPTIONS{{.*}} -o [[SYCLPOSTLINKOUT:.*]].table [[SECONDLLVMLINKOUT]].bc
8+
// CHK-CMDS-NEXT: "{{.*}}sycl-post-link.exe"{{.*}} SYCL_POST_LINK_OPTIONS -o [[SYCLPOSTLINKOUT:.*]].table [[SECONDLLVMLINKOUT]].bc
99
// LLVM-SPIRV is not called in dry-run
1010
// CHK-CMDS-NEXT: offload-wrapper: input: [[LLVMSPIRVOUT:.*]].table, output: [[WRAPPEROUT:.*]].bc
1111
// CHK-CMDS-NEXT: "{{.*}}llc.exe" -filetype=obj -o [[LLCOUT:.*]].o [[WRAPPEROUT]].bc

clang/test/Driver/linker-wrapper-sycl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
// CHK-CMDS: "{{.*}}spirv-to-ir-wrapper" {{.*}} -o [[FIRSTLLVMLINKIN:.*]].bc --llvm-spirv-opts=--spirv-preserve-auxdata --llvm-spirv-opts=--spirv-target-env=SPV-IR --llvm-spirv-opts=--spirv-builtin-format=global
66
// CHK-CMDS-NEXT: "{{.*}}llvm-link" [[FIRSTLLVMLINKIN:.*]].bc -o [[FIRSTLLVMLINKOUT:.*]].bc --suppress-warnings
77
// CHK-CMDS-NEXT: "{{.*}}llvm-link" -only-needed [[FIRSTLLVMLINKOUT]].bc {{.*}}.bc {{.*}}.bc -o [[SECONDLLVMLINKOUT:.*]].bc --suppress-warnings
8-
// CHK-CMDS-NEXT: "{{.*}}sycl-post-link" SYCL_POST_LINK_OPTIONS {{.*}} -o [[SYCLPOSTLINKOUT:.*]].table [[SECONDLLVMLINKOUT]].bc
8+
// CHK-CMDS-NEXT: "{{.*}}sycl-post-link"{{.*}} SYCL_POST_LINK_OPTIONS -o [[SYCLPOSTLINKOUT:.*]].table [[SECONDLLVMLINKOUT]].bc
99
// LLVM-SPIRV is not called in dry-run
1010
// CHK-CMDS-NEXT: offload-wrapper: input: [[LLVMSPIRVOUT:.*]].table, output: [[WRAPPEROUT:.*]].bc
1111
// CHK-CMDS-NEXT: "{{.*}}llc" -filetype=obj -o [[LLCOUT:.*]].o [[WRAPPEROUT]].bc

clang/test/Driver/sycl-offload-new-driver.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
// RUN: %clangxx --target=x86_64-unknown-linux-gnu -fsycl --offload-new-driver \
6161
// RUN: -Xdevice-post-link -post-link-opt -### %s 2>&1 \
6262
// RUN: | FileCheck -check-prefix WRAPPER_OPTIONS_POSTLINK %s
63-
// WRAPPER_OPTIONS_POSTLINK: clang-linker-wrapper{{.*}} "--sycl-post-link-options=-post-link-opt -O2 -device-globals -spec-const=native -split=auto -emit-only-kernels-as-entry-points -symbols -emit-exported-symbols -emit-imported-symbols -lower-esimd"
63+
// WRAPPER_OPTIONS_POSTLINK: clang-linker-wrapper{{.*}} "--sycl-post-link-options=-O2 -device-globals -post-link-opt"
6464

6565
// -fsycl-device-only behavior
6666
// RUN: %clangxx --target=x86_64-unknown-linux-gnu -fsycl --offload-new-driver \
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// REQUIRES: system-windows
2+
/// Verify same set of sycl-post-link options generated for old and new offloading model
3+
// RUN: %clangxx -### --target=x86_64-pc-windows-msvc -fsycl \
4+
// RUN: -Xdevice-post-link -O0 %s 2>&1 \
5+
// RUN: | FileCheck -check-prefix OPTIONS_POSTLINK_JIT_OLD %s
6+
// OPTIONS_POSTLINK_JIT_OLD: sycl-post-link{{.*}} "-O2" "-device-globals" "-spec-const=native" "-split=auto" "-emit-only-kernels-as-entry-points" "-emit-param-info" "-symbols" "-emit-exported-symbols" "-emit-imported-symbols" "-split-esimd" "-lower-esimd" "-O0"
7+
8+
// RUN: %clang -cc1 %s -triple x86_64-pc-windows-msvc -emit-obj -o %t.elf.o
9+
// RUN: clang-offload-packager -o %t.out --image=file=%t.elf.o,kind=sycl,triple=spir64
10+
// RUN: %clang -cc1 %s -triple x86_64-pc-windows-msvc -emit-obj -o %t.o \
11+
// RUN: -fembed-offload-object=%t.out
12+
// RUN: clang-linker-wrapper --dry-run --host-triple=x86_64-pc-windows-msvc \
13+
// RUN: -sycl-device-library-location=%S/Inputs -sycl-device-libraries=libsycl-crt.new.obj \
14+
// RUN: --sycl-post-link-options="-O2 -device-globals -O0" \
15+
// RUN: --linker-path=/usr/bin/ld %t.o -o a.out 2>&1 | FileCheck --check-prefix OPTIONS_POSTLINK_JIT_NEW %s
16+
// OPTIONS_POSTLINK_JIT_NEW: sycl-post-link{{.*}} -spec-const=native -split=auto -emit-only-kernels-as-entry-points -emit-param-info -symbols -emit-exported-symbols -emit-imported-symbols -split-esimd -lower-esimd -O2 -device-globals -O0
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// REQUIRES: system-linux
2+
/// Verify same set of sycl-post-link options generated for old and new offloading model
3+
// RUN: %clangxx --target=x86_64-unknown-linux-gnu -fsycl -### \
4+
// RUN: -Xdevice-post-link -O0 %s 2>&1 \
5+
// RUN: | FileCheck -check-prefix OPTIONS_POSTLINK_JIT_OLD %s
6+
// OPTIONS_POSTLINK_JIT_OLD: sycl-post-link{{.*}} "-O2" "-device-globals" "-spec-const=native" "-split=auto" "-emit-only-kernels-as-entry-points" "-emit-param-info" "-symbols" "-emit-exported-symbols" "-emit-imported-symbols" "-split-esimd" "-lower-esimd" "-O0"
7+
8+
// RUN: %clang -cc1 %s -triple x86_64-unknown-linux-gnu -emit-obj -o %t.elf.o
9+
// RUN: clang-offload-packager -o %t.out --image=file=%t.elf.o,kind=sycl,triple=spir64
10+
// RUN: %clang -cc1 %s -triple x86_64-unknown-linux-gnu -emit-obj -o %t.o \
11+
// RUN: -fembed-offload-object=%t.out
12+
// RUN: clang-linker-wrapper --dry-run --host-triple=x86_64-unknown-linux-gnu \
13+
// RUN: -sycl-device-library-location=%S/Inputs -sycl-device-libraries=libsycl-crt.new.o \
14+
// RUN: --sycl-post-link-options="-O2 -device-globals -O0" \
15+
// RUN: --linker-path=/usr/bin/ld %t.o -o a.out 2>&1 | FileCheck --check-prefix OPTIONS_POSTLINK_JIT_NEW %s
16+
// OPTIONS_POSTLINK_JIT_NEW: sycl-post-link{{.*}} -spec-const=native -split=auto -emit-only-kernels-as-entry-points -emit-param-info -symbols -emit-exported-symbols -emit-imported-symbols -split-esimd -lower-esimd -O2 -device-globals -O0

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

Lines changed: 66 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -522,78 +522,69 @@ static Expected<StringRef> convertSPIRVToIR(StringRef Filename,
522522
return *TempFileOrErr;
523523
}
524524

525-
// Update sycl-post-link options based on target triple.
526-
static void updateCmdArgs(SmallVector<StringRef, 8> &CmdArgs,
527-
llvm::Triple Triple) {
528-
// Get an argument in CmdArgs that contains Str. If there is no such
529-
// argument, an empty argument is returned
530-
auto getArg = [&](const StringRef &Str) {
531-
for (auto Arg : CmdArgs)
532-
if (Arg.contains(Str))
533-
return Arg;
534-
return StringRef("");
535-
};
536-
// Add a new argument Arg to CmdArgs if not present already.
537-
auto addArg = [&](const StringRef &Arg) {
538-
if (getArg(Arg).empty())
539-
CmdArgs.push_back(Arg);
540-
};
541-
// Replace an argument in CmdArgs that contains Str with NewArg. If no such
542-
// argument is present, add the NewArg to CmdArgs.
543-
auto replaceOrAddArg = [&](const StringRef &NewArg, const StringRef &Str) {
544-
for (auto &Arg : CmdArgs)
545-
if (Arg.contains(Str)) {
546-
Arg = NewArg;
547-
return;
548-
}
549-
CmdArgs.push_back(NewArg);
550-
};
551-
// Remove argument containing Str from CmdArgs.
552-
auto removeArg = [&](const StringRef &Str) {
553-
CmdArgs.erase(
554-
std::remove_if(CmdArgs.begin(), CmdArgs.end(),
555-
[&](StringRef Arg) { return Arg.contains(Str); }),
556-
CmdArgs.end());
557-
};
558-
559-
// specialization constants processing.
560-
bool IsAOTGPU = Triple.isNVPTX() || Triple.isAMDGCN() || Triple.isSPIRAOT();
561-
if (!IsAOTGPU)
562-
replaceOrAddArg("-spec-const=native", "-spec-const");
563-
else
564-
replaceOrAddArg("-spec-const=emulation", "-spec-const");
565-
566-
// -emit-only-kernels-as-entry-points is set by the user and is enabled only
567-
// for Intel targets.
568-
auto EmitOnlyKernelsAsEntryPointsArg =
569-
getArg("-emit-only-kernels-as-entry-points");
570-
if ((!EmitOnlyKernelsAsEntryPointsArg.empty()) && !Triple.isNVPTX() &&
571-
!Triple.isAMDGPU())
572-
addArg("-emit-only-kernels-as-entry-points");
573-
else
574-
removeArg("-emit-only-kernels-as-entry-points");
575-
576-
if (!(Triple.isAMDGCN()))
577-
addArg("-emit-param-info");
578-
579-
if (Triple.isNVPTX() || Triple.isAMDGCN())
580-
addArg("-emit-program-metadata");
581-
582-
if (Triple.isSPIROrSPIRV()) {
583-
addArg("-symbols");
584-
addArg("-emit-exported-symbols");
585-
addArg("-split-esimd");
586-
addArg("-lower-esimd");
587-
}
588-
589-
// Here, IsAOT includes x86_64 device as well.
590-
bool IsAOT =
591-
IsAOTGPU || Triple.getSubArch() == llvm::Triple::SPIRSubArch_x86_64;
592-
auto GenDeviceImageArg = getArg("-generate-device-image-default-spec-consts");
593-
if ((!GenDeviceImageArg.empty()) && IsAOT)
594-
addArg("-generate-device-image-default-spec-consts");
525+
// Add any sycl-post-link options that rely on a specific Triple in addition
526+
// to user supplied options.
527+
// NOTE: Any changes made here should be reflected in the similarly named
528+
// function in clang/lib/Driver/ToolChains/Clang.cpp.
529+
static void
530+
getTripleBasedSYCLPostLinkOpts(const ArgList &Args,
531+
SmallVector<StringRef, 8> &PostLinkArgs,
532+
const llvm::Triple Triple) {
533+
const llvm::Triple HostTriple(Args.getLastArgValue(OPT_host_triple_EQ));
534+
bool SYCLNativeCPU = (HostTriple == Triple);
535+
bool SpecConstsSupported = (!Triple.isNVPTX() && !Triple.isAMDGCN() ||
536+
!Triple.isSPIRAOT() && !SYCLNativeCPU);
537+
if (SpecConstsSupported)
538+
PostLinkArgs.push_back("-spec-const=native");
595539
else
596-
removeArg("-generate-device-image-default-spec-consts");
540+
PostLinkArgs.push_back("-spec-const=emulation");
541+
542+
// See if device code splitting is already requested. If not requested, then
543+
// set -split=auto for non-FPGA targets.
544+
bool NoSplit = true;
545+
for (auto Arg : PostLinkArgs)
546+
if (Arg.contains("-split=")) {
547+
NoSplit = false;
548+
break;
549+
}
550+
if (NoSplit && (Triple.getSubArch() != llvm::Triple::SPIRSubArch_fpga))
551+
PostLinkArgs.push_back("-split=auto");
552+
553+
// On Intel targets we don't need non-kernel functions as entry points,
554+
// because it only increases amount of code for device compiler to handle,
555+
// without any actual benefits.
556+
// TODO: Try to extend this feature for non-Intel GPUs.
557+
if ((!Args.hasFlag(OPT_no_sycl_remove_unused_external_funcs,
558+
OPT_sycl_remove_unused_external_funcs, false) &&
559+
!SYCLNativeCPU) &&
560+
!Triple.isNVPTX() && !Triple.isAMDGPU())
561+
PostLinkArgs.push_back("-emit-only-kernels-as-entry-points");
562+
563+
if (!Triple.isAMDGCN())
564+
PostLinkArgs.push_back("-emit-param-info");
565+
// Enable program metadata
566+
if (Triple.isNVPTX() || Triple.isAMDGCN() || SYCLNativeCPU)
567+
PostLinkArgs.push_back("-emit-program-metadata");
568+
569+
bool SplitEsimdByDefault = Triple.isSPIROrSPIRV();
570+
bool SplitEsimd =
571+
Args.hasFlag(OPT_sycl_device_code_split_esimd,
572+
OPT_no_sycl_device_code_split_esimd, SplitEsimdByDefault);
573+
574+
// Symbol file and specialization constant info generation is mandatory -
575+
// add options unconditionally
576+
PostLinkArgs.push_back("-symbols");
577+
PostLinkArgs.push_back("-emit-exported-symbols");
578+
PostLinkArgs.push_back("-emit-imported-symbols");
579+
if (SplitEsimd)
580+
PostLinkArgs.push_back("-split-esimd");
581+
PostLinkArgs.push_back("-lower-esimd");
582+
583+
bool IsAOT = Triple.isNVPTX() || Triple.isAMDGCN() || Triple.isSPIRAOT();
584+
if (Args.hasFlag(OPT_sycl_add_default_spec_consts_image,
585+
OPT_no_sycl_add_default_spec_consts_image, false) &&
586+
IsAOT)
587+
PostLinkArgs.push_back("-generate-device-image-default-spec-consts");
597588
}
598589

599590
// Run sycl-post-link tool
@@ -610,16 +601,15 @@ static Expected<StringRef> runSYCLPostLink(ArrayRef<StringRef> InputFiles,
610601
if (!TempFileOrErr)
611602
return TempFileOrErr.takeError();
612603

604+
SmallVector<StringRef, 8> CmdArgs;
605+
CmdArgs.push_back(*SYCLPostLinkPath);
606+
const llvm::Triple Triple(Args.getLastArgValue(OPT_triple_EQ));
607+
getTripleBasedSYCLPostLinkOpts(Args, CmdArgs, Triple);
613608
StringRef SYCLPostLinkOptions;
614609
if (Arg *A = Args.getLastArg(OPT_sycl_post_link_options_EQ))
615610
SYCLPostLinkOptions = A->getValue();
616-
617-
SmallVector<StringRef, 8> CmdArgs;
618-
CmdArgs.push_back(*SYCLPostLinkPath);
619611
SYCLPostLinkOptions.split(CmdArgs, " ", /* MaxSplit = */ -1,
620612
/* KeepEmpty = */ false);
621-
const llvm::Triple Triple(Args.getLastArgValue(OPT_triple_EQ));
622-
updateCmdArgs(CmdArgs, Triple);
623613
CmdArgs.push_back("-o");
624614
CmdArgs.push_back(*TempFileOrErr);
625615
for (auto &File : InputFiles)

0 commit comments

Comments
 (0)