@@ -509,6 +509,22 @@ void tools::addLinkerCompressDebugSectionsOption(
509509 }
510510}
511511
512+ void tools::addGPULibraries (const ToolChain &TC, const llvm::opt::ArgList &Args,
513+ llvm::opt::ArgStringList &CmdArgs) {
514+ if (Args.hasArg (options::OPT_nostdlib, options::OPT_r,
515+ options::OPT_nodefaultlibs, options::OPT_nolibc,
516+ options::OPT_nogpulibc))
517+ return ;
518+
519+ // If the user's toolchain has the 'include/<triple>/` path, we assume it
520+ // supports the standard C libraries for the GPU and include them.
521+ bool HasLibC = TC.getStdlibIncludePath ().has_value ();
522+ if (HasLibC) {
523+ CmdArgs.push_back (" -lc" );
524+ CmdArgs.push_back (" -lm" );
525+ }
526+ }
527+
512528void tools::AddTargetFeature (const ArgList &Args,
513529 std::vector<StringRef> &Features,
514530 OptSpecifier OnOpt, OptSpecifier OffOpt,
@@ -1145,42 +1161,6 @@ void tools::addLTOOptions(const ToolChain &ToolChain, const ArgList &Args,
11451161 }
11461162}
11471163
1148- // / Adds the '-lcgpu' and '-lmgpu' libraries to the compilation to include the
1149- // / LLVM C library for GPUs.
1150- static void addOpenMPDeviceLibC (const Compilation &C, const ArgList &Args,
1151- ArgStringList &CmdArgs) {
1152- if (Args.hasArg (options::OPT_nogpulib) || Args.hasArg (options::OPT_nolibc))
1153- return ;
1154-
1155- // Check the resource directory for the LLVM libc GPU declarations. If it's
1156- // found we can assume that LLVM was built with support for the GPU libc.
1157- SmallString<256 > LibCDecls (C.getDriver ().ResourceDir );
1158- llvm::sys::path::append (LibCDecls, " include" , " llvm_libc_wrappers" ,
1159- " llvm-libc-decls" );
1160- bool HasLibC = llvm::sys::fs::exists (LibCDecls) &&
1161- llvm::sys::fs::is_directory (LibCDecls);
1162- if (!Args.hasFlag (options::OPT_gpulibc, options::OPT_nogpulibc, HasLibC))
1163- return ;
1164-
1165- SmallVector<const ToolChain *> ToolChains;
1166- auto TCRange = C.getOffloadToolChains (Action::OFK_OpenMP);
1167- for (auto TI = TCRange.first , TE = TCRange.second ; TI != TE; ++TI)
1168- ToolChains.push_back (TI->second );
1169-
1170- if (llvm::any_of (ToolChains, [](const ToolChain *TC) {
1171- return TC->getTriple ().isAMDGPU ();
1172- })) {
1173- CmdArgs.push_back (" -lcgpu-amdgpu" );
1174- CmdArgs.push_back (" -lmgpu-amdgpu" );
1175- }
1176- if (llvm::any_of (ToolChains, [](const ToolChain *TC) {
1177- return TC->getTriple ().isNVPTX ();
1178- })) {
1179- CmdArgs.push_back (" -lcgpu-nvptx" );
1180- CmdArgs.push_back (" -lmgpu-nvptx" );
1181- }
1182- }
1183-
11841164void tools::addOpenMPRuntimeLibraryPath (const ToolChain &TC,
11851165 const ArgList &Args,
11861166 ArgStringList &CmdArgs) {
@@ -1253,10 +1233,8 @@ bool tools::addOpenMPRuntime(const Compilation &C, ArgStringList &CmdArgs,
12531233 if (IsOffloadingHost && !Args.hasArg (options::OPT_nogpulib))
12541234 CmdArgs.push_back (" -lomptarget.devicertl" );
12551235
1256- if (IsOffloadingHost)
1257- addOpenMPDeviceLibC (C, Args, CmdArgs);
1258-
12591236 addArchSpecificRPath (TC, Args, CmdArgs);
1237+
12601238 addOpenMPRuntimeLibraryPath (TC, Args, CmdArgs);
12611239
12621240 return true ;
0 commit comments