@@ -156,19 +156,6 @@ Expected<std::string> findProgram(const ArgList &Args, StringRef Name,
156156 return *Path;
157157}
158158
159- std::optional<std::string> findFile (StringRef Dir, StringRef Root,
160- const Twine &Name) {
161- SmallString<128 > Path;
162- if (Dir.starts_with (" =" ))
163- sys::path::append (Path, Root, Dir.substr (1 ), Name);
164- else
165- sys::path::append (Path, Dir, Name);
166-
167- if (sys::fs::exists (Path))
168- return static_cast <std::string>(Path);
169- return std::nullopt ;
170- }
171-
172159void printCommands (ArrayRef<StringRef> CmdArgs) {
173160 if (CmdArgs.empty ())
174161 return ;
@@ -238,43 +225,31 @@ Expected<StringRef> linkDeviceInputFiles(ArrayRef<std::string> InputFiles,
238225 return *OutFileOrErr;
239226}
240227
241- const SmallVector<std::string> SYCLDeviceLibNames = {
242- " libsycl-crt.bc" ,
243- " libsycl-complex.bc" ,
244- " libsycl-complex-fp64.bc" ,
245- " libsycl-cmath.bc" ,
246- " libsycl-cmath-fp64.bc" ,
247- " libsycl-imf.bc" ,
248- " libsycl-imf-fp64.bc" ,
249- " libsycl-imf-bf16.bc" ,
250- " libsycl-fallback-cassert.bc" ,
251- " libsycl-fallback-cstring.bc" ,
252- " libsycl-fallback-complex.bc" ,
253- " libsycl-fallback-complex-fp64.bc" ,
254- " libsycl-fallback-cmath.bc" ,
255- " libsycl-fallback-cmath-fp64.bc" ,
256- " libsycl-fallback-imf.bc" ,
257- " libsycl-fallback-imf-fp64.bc" ,
258- " libsycl-fallback-imf-bf16.bc" ,
259- " libsycl-fallback-bfloat16.bc" ,
260- " libsycl-native-bfloat16.bc" ,
261- " libsycl-itt-user-wrappers.bc" ,
262- " libsycl-itt-compiler-wrappers.bc" ,
263- " libsycl-itt-stubs.bc" ,
264- " libsycl-sanitizer.bc" };
265-
266- Expected<SmallVector<std::string>> getSYCLDeviceLibFiles (const ArgList &Args) {
228+ // This utility function is used to gather all SYCL device library files that
229+ // will be linked with input device files.
230+ // The list of files and its location are passed from driver.
231+ Expected<SmallVector<std::string>> getSYCLDeviceLibs (const ArgList &Args) {
267232 SmallVector<std::string> DeviceLibFiles;
268233 StringRef LibraryPath;
269234 if (Arg *A = Args.getLastArg (OPT_library_path_EQ))
270235 LibraryPath = A->getValue ();
271236 if (LibraryPath.empty ())
272237 return DeviceLibFiles;
273- for (auto &DeviceLibName : SYCLDeviceLibNames) {
274- std::optional<std::string> Filename =
275- findFile (LibraryPath, /* Root=*/ " " , DeviceLibName);
276- if (Filename)
277- DeviceLibFiles.push_back (*Filename);
238+ if (Arg *A = Args.getLastArg (OPT_device_libs_EQ)) {
239+ if (A->getValues ().size () == 0 )
240+ return createStringError (
241+ inconvertibleErrorCode (),
242+ " Number of device library files cannot be zero." );
243+ for (StringRef Val : A->getValues ()) {
244+ SmallString<128 > LibName (LibraryPath);
245+ llvm::sys::path::append (LibName, Val);
246+ if (llvm::sys::fs::exists (LibName))
247+ DeviceLibFiles.push_back (std::string (LibName));
248+ else
249+ return createStringError (inconvertibleErrorCode (),
250+ std::string (LibName) +
251+ " SYCL device library file is not found." );
252+ }
278253 }
279254 return DeviceLibFiles;
280255}
@@ -288,7 +263,7 @@ static Expected<StringRef> linkDeviceLibFiles(StringRef InputFile,
288263 const ArgList &Args) {
289264 llvm::TimeTraceScope TimeScope (" LinkDeviceLibraryFiles" );
290265
291- auto SYCLDeviceLibFiles = getSYCLDeviceLibFiles (Args);
266+ auto SYCLDeviceLibFiles = getSYCLDeviceLibs (Args);
292267 if (!SYCLDeviceLibFiles)
293268 return SYCLDeviceLibFiles.takeError ();
294269 if ((*SYCLDeviceLibFiles).empty ())
@@ -472,8 +447,7 @@ int main(int argc, char **argv) {
472447
473448 if (Args.hasArg (OPT_help) || Args.hasArg (OPT_help_hidden)) {
474449 Tbl.printHelp (
475- outs (),
476- " clang-sycl-linker [options] <options to sycl link steps>" ,
450+ outs (), " clang-sycl-linker [options] <options to sycl link steps>" ,
477451 " A utility that wraps around several steps required to link SYCL "
478452 " device files.\n "
479453 " This enables LLVM IR linking, post-linking and code generation for "
0 commit comments