@@ -3772,16 +3772,6 @@ class OffloadingActionBuilder final {
3772
3772
for (auto SDA : SYCLDeviceActions)
3773
3773
SYCLLinkBinaryList.push_back (SDA);
3774
3774
if (WrapDeviceOnlyBinary) {
3775
- // If used without -fintelfpga, -fsycl-link is used to wrap device
3776
- // objects for future host link. Device libraries should be linked
3777
- // by default to resolve any undefined reference.
3778
- if (!Args.hasArg (options::OPT_fintelfpga)) {
3779
- const auto *TC = ToolChains.front ();
3780
- addSYCLDeviceLibs (TC, SYCLLinkBinaryList, true ,
3781
- C.getDefaultToolChain ()
3782
- .getTriple ()
3783
- .isWindowsMSVCEnvironment ());
3784
- }
3785
3775
// -fsycl-link behavior does the following to the unbundled device
3786
3776
// binaries:
3787
3777
// 1) Link them together using llvm-link
@@ -3791,8 +3781,29 @@ class OffloadingActionBuilder final {
3791
3781
// by any compilation link step.
3792
3782
auto *DeviceLinkAction = C.MakeAction <LinkJobAction>(
3793
3783
SYCLLinkBinaryList, types::TY_Image);
3784
+ ActionList FullSYCLLinkBinaryList;
3785
+ bool SYCLDeviceLibLinked = false ;
3786
+ FullSYCLLinkBinaryList.push_back (DeviceLinkAction);
3787
+ // If used without -fintelfpga, -fsycl-link is used to wrap device
3788
+ // objects for future host link. Device libraries should be linked
3789
+ // by default to resolve any undefined reference.
3790
+ if (!Args.hasArg (options::OPT_fintelfpga)) {
3791
+ const auto *TC = ToolChains.front ();
3792
+ SYCLDeviceLibLinked =
3793
+ addSYCLDeviceLibs (TC, FullSYCLLinkBinaryList, true ,
3794
+ C.getDefaultToolChain ()
3795
+ .getTriple ()
3796
+ .isWindowsMSVCEnvironment ());
3797
+ }
3798
+
3799
+ Action *FullDeviceLinkAction = nullptr ;
3800
+ if (SYCLDeviceLibLinked)
3801
+ FullDeviceLinkAction = C.MakeAction <LinkJobAction>(
3802
+ FullSYCLLinkBinaryList, types::TY_LLVM_BC);
3803
+ else
3804
+ FullDeviceLinkAction = DeviceLinkAction;
3794
3805
auto *PostLinkAction = C.MakeAction <SYCLPostLinkJobAction>(
3795
- DeviceLinkAction , types::TY_LLVM_BC);
3806
+ FullDeviceLinkAction , types::TY_LLVM_BC);
3796
3807
auto *TranslateAction = C.MakeAction <SPIRVTranslatorJobAction>(
3797
3808
PostLinkAction, types::TY_Image);
3798
3809
SYCLLinkBinary = C.MakeAction <OffloadWrapperJobAction>(
@@ -3948,7 +3959,7 @@ class OffloadingActionBuilder final {
3948
3959
SYCLDeviceActions.clear ();
3949
3960
}
3950
3961
3951
- void addSYCLDeviceLibs (const ToolChain *TC, ActionList &DeviceLinkObjects,
3962
+ bool addSYCLDeviceLibs (const ToolChain *TC, ActionList &DeviceLinkObjects,
3952
3963
bool isSpirvAOT, bool isMSVCEnv) {
3953
3964
enum SYCLDeviceLibType {
3954
3965
sycl_devicelib_wrapper,
@@ -3960,6 +3971,7 @@ class OffloadingActionBuilder final {
3960
3971
};
3961
3972
3962
3973
bool NoDeviceLibs = false ;
3974
+ int NumOfDeviceLibLinked = 0 ;
3963
3975
// Currently, libc, libm-fp32 will be linked in by default. In order
3964
3976
// to use libm-fp64, -fsycl-device-lib=libm-fp64/all should be used.
3965
3977
llvm::StringMap<bool > devicelib_link_info = {
@@ -4017,6 +4029,7 @@ class OffloadingActionBuilder final {
4017
4029
llvm::sys::path::append (LibName, Lib.devicelib_name );
4018
4030
llvm::sys::path::replace_extension (LibName, LibSuffix);
4019
4031
if (llvm::sys::fs::exists (LibName)) {
4032
+ ++NumOfDeviceLibLinked;
4020
4033
Arg *InputArg = MakeInputArg (Args, C.getDriver ().getOpts (),
4021
4034
Args.MakeArgString (LibName));
4022
4035
auto *SYCLDeviceLibsInputAction =
@@ -4032,6 +4045,7 @@ class OffloadingActionBuilder final {
4032
4045
addInputs (sycl_devicelib_wrapper);
4033
4046
if (isSpirvAOT)
4034
4047
addInputs (sycl_devicelib_fallback);
4048
+ return NumOfDeviceLibLinked != 0 ;
4035
4049
}
4036
4050
4037
4051
void appendLinkDependences (OffloadAction::DeviceDependences &DA) override {
@@ -4125,15 +4139,6 @@ class OffloadingActionBuilder final {
4125
4139
else
4126
4140
LinkObjects.push_back (Input);
4127
4141
}
4128
- // FIXME: Link all wrapper and fallback device libraries as default,
4129
- // When spv online link is supported by all backends, the fallback
4130
- // device libraries are only needed when current toolchain is using
4131
- // AOT compilation.
4132
- if (!isNVPTX) {
4133
- addSYCLDeviceLibs (
4134
- *TC, LinkObjects, true ,
4135
- C.getDefaultToolChain ().getTriple ().isWindowsMSVCEnvironment ());
4136
- }
4137
4142
// The linkage actions subgraph leading to the offload wrapper.
4138
4143
// [cond] Means incoming/outgoing dependence is created only when cond
4139
4144
// is true. A function of:
@@ -4187,6 +4192,26 @@ class OffloadingActionBuilder final {
4187
4192
//
4188
4193
Action *DeviceLinkAction =
4189
4194
C.MakeAction <LinkJobAction>(LinkObjects, types::TY_LLVM_BC);
4195
+ ActionList FullLinkObjects;
4196
+ bool SYCLDeviceLibLinked = false ;
4197
+ FullLinkObjects.push_back (DeviceLinkAction);
4198
+
4199
+ // FIXME: Link all wrapper and fallback device libraries as default,
4200
+ // When spv online link is supported by all backends, the fallback
4201
+ // device libraries are only needed when current toolchain is using
4202
+ // AOT compilation.
4203
+ if (!isNVPTX) {
4204
+ SYCLDeviceLibLinked = addSYCLDeviceLibs (
4205
+ *TC, FullLinkObjects, true ,
4206
+ C.getDefaultToolChain ().getTriple ().isWindowsMSVCEnvironment ());
4207
+ }
4208
+
4209
+ Action *FullDeviceLinkAction = nullptr ;
4210
+ if (SYCLDeviceLibLinked)
4211
+ FullDeviceLinkAction =
4212
+ C.MakeAction <LinkJobAction>(FullLinkObjects, types::TY_LLVM_BC);
4213
+ else
4214
+ FullDeviceLinkAction = DeviceLinkAction;
4190
4215
// setup some flags upfront
4191
4216
4192
4217
if (isNVPTX && DeviceCodeSplit) {
@@ -4212,7 +4237,7 @@ class OffloadingActionBuilder final {
4212
4237
? types::TY_LLVM_BC
4213
4238
: types::TY_Tempfiletable;
4214
4239
auto *PostLinkAction = C.MakeAction <SYCLPostLinkJobAction>(
4215
- DeviceLinkAction , PostLinkOutType);
4240
+ FullDeviceLinkAction , PostLinkOutType);
4216
4241
PostLinkAction->setRTSetsSpecConstants (!isAOT);
4217
4242
4218
4243
if (isNVPTX) {
0 commit comments