@@ -4331,20 +4331,19 @@ class OffloadingActionBuilder final {
43314331
43324332 bool addSYCLDeviceLibs (const ToolChain *TC, ActionList &DeviceLinkObjects,
43334333 bool isSpirvAOT, bool isMSVCEnv) {
4334- enum SYCLDeviceLibType {
4335- sycl_devicelib_wrapper,
4336- sycl_devicelib_fallback
4337- };
43384334 struct DeviceLibOptInfo {
43394335 StringRef devicelib_name;
43404336 StringRef devicelib_option;
43414337 };
43424338
43434339 bool NoDeviceLibs = false ;
43444340 int NumOfDeviceLibLinked = 0 ;
4345- // Currently, all SYCL device libraries will be linked by default
4346- llvm::StringMap<bool > devicelib_link_info = {
4347- {" libc" , true }, {" libm-fp32" , true }, {" libm-fp64" , true }};
4341+ // Currently, all SYCL device libraries will be linked by default. Linkage
4342+ // of "internal" libraries cannot be affected via -fno-sycl-device-lib.
4343+ llvm::StringMap<bool > devicelib_link_info = {{" libc" , true },
4344+ {" libm-fp32" , true },
4345+ {" libm-fp64" , true },
4346+ {" internal" , true }};
43484347 if (Arg *A = Args.getLastArg (options::OPT_fsycl_device_lib_EQ,
43494348 options::OPT_fno_sycl_device_lib_EQ)) {
43504349 if (A->getValues ().size () == 0 )
@@ -4357,11 +4356,16 @@ class OffloadingActionBuilder final {
43574356 for (StringRef Val : A->getValues ()) {
43584357 if (Val == " all" ) {
43594358 for (const auto &K : devicelib_link_info.keys ())
4360- devicelib_link_info[K] = true && !NoDeviceLibs;
4359+ devicelib_link_info[K] =
4360+ true && (!NoDeviceLibs || K.equals (" internal" ));
43614361 break ;
43624362 }
43634363 auto LinkInfoIter = devicelib_link_info.find (Val);
4364- if (LinkInfoIter == devicelib_link_info.end ()) {
4364+ if (LinkInfoIter == devicelib_link_info.end () ||
4365+ Val.equals (" internal" )) {
4366+ // TODO: Move the diagnostic to the SYCL section of
4367+ // Driver::CreateOffloadingDeviceToolChains() to minimize code
4368+ // duplication.
43654369 C.getDriver ().Diag (diag::err_drv_unsupported_option_argument)
43664370 << A->getOption ().getName () << Val;
43674371 }
@@ -4375,30 +4379,34 @@ class OffloadingActionBuilder final {
43754379 SmallVector<SmallString<128 >, 4 > LibLocCandidates;
43764380 SYCLTC->SYCLInstallation .getSYCLDeviceLibPath (LibLocCandidates);
43774381 StringRef LibSuffix = isMSVCEnv ? " .obj" : " .o" ;
4378- SmallVector<DeviceLibOptInfo, 5 > sycl_device_wrapper_libs = {
4382+ using SYCLDeviceLibsList = SmallVector<DeviceLibOptInfo, 5 >;
4383+ const SYCLDeviceLibsList sycl_device_wrapper_libs = {
43794384 {" libsycl-crt" , " libc" },
43804385 {" libsycl-complex" , " libm-fp32" },
43814386 {" libsycl-complex-fp64" , " libm-fp64" },
43824387 {" libsycl-cmath" , " libm-fp32" },
43834388 {" libsycl-cmath-fp64" , " libm-fp64" }};
43844389 // For AOT compilation, we need to link sycl_device_fallback_libs as
43854390 // default too.
4386- SmallVector<DeviceLibOptInfo, 5 > sycl_device_fallback_libs = {
4391+ const SYCLDeviceLibsList sycl_device_fallback_libs = {
43874392 {" libsycl-fallback-cassert" , " libc" },
43884393 {" libsycl-fallback-cstring" , " libc" },
43894394 {" libsycl-fallback-complex" , " libm-fp32" },
43904395 {" libsycl-fallback-complex-fp64" , " libm-fp64" },
43914396 {" libsycl-fallback-cmath" , " libm-fp32" },
43924397 {" libsycl-fallback-cmath-fp64" , " libm-fp64" }};
4393- auto addInputs = [&](SYCLDeviceLibType t) {
4394- auto sycl_libs = (t == sycl_devicelib_wrapper)
4395- ? sycl_device_wrapper_libs
4396- : sycl_device_fallback_libs;
4398+ // ITT annotation libraries are linked in separately whenever the device
4399+ // code instrumentation is enabled.
4400+ const SYCLDeviceLibsList sycl_device_annotation_libs = {
4401+ {" libsycl-itt-user-wrappers" , " internal" },
4402+ {" libsycl-itt-compiler-wrappers" , " internal" },
4403+ {" libsycl-itt-stubs" , " internal" }};
4404+ auto addInputs = [&](const SYCLDeviceLibsList &LibsList) {
43974405 bool LibLocSelected = false ;
43984406 for (const auto &LLCandidate : LibLocCandidates) {
43994407 if (LibLocSelected)
44004408 break ;
4401- for (const DeviceLibOptInfo &Lib : sycl_libs ) {
4409+ for (const DeviceLibOptInfo &Lib : LibsList ) {
44024410 if (!devicelib_link_info[Lib.devicelib_option ])
44034411 continue ;
44044412 SmallString<128 > LibName (LLCandidate);
@@ -4421,9 +4429,11 @@ class OffloadingActionBuilder final {
44214429 }
44224430 }
44234431 };
4424- addInputs (sycl_devicelib_wrapper );
4432+ addInputs (sycl_device_wrapper_libs );
44254433 if (isSpirvAOT)
4426- addInputs (sycl_devicelib_fallback);
4434+ addInputs (sycl_device_fallback_libs);
4435+ if (Args.hasArg (options::OPT_fsycl_instrument_device_code))
4436+ addInputs (sycl_device_annotation_libs);
44274437 return NumOfDeviceLibLinked != 0 ;
44284438 }
44294439
0 commit comments