tra created this revision. tra added reviewers: yaxunl, arsenm. Herald added subscribers: kerbowa, sanjoy.google, bixia, nhaehnle, wdng, jvesely. Herald added a project: clang. tra updated this revision to Diff 270533. tra edited the summary of this revision. tra added a comment.
Replaced another use of D.getVFS. It's useful for using clang from tools that may need need to provide SDK files from non-standard locations. Clang CLI only provides `-ivfsoverlay` for include files, but not for the driver's use in general, so there's no good way to test this yet. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D81771 Files: clang/lib/Driver/ToolChains/AMDGPU.cpp clang/lib/Driver/ToolChains/Cuda.cpp Index: clang/lib/Driver/ToolChains/Cuda.cpp =================================================================== --- clang/lib/Driver/ToolChains/Cuda.cpp +++ clang/lib/Driver/ToolChains/Cuda.cpp @@ -78,6 +78,7 @@ // In decreasing order so we prefer newer versions to older versions. std::initializer_list<const char *> Versions = {"8.0", "7.5", "7.0"}; + auto &FS = D.getVFS(); if (Args.hasArg(clang::driver::options::OPT_cuda_path_EQ)) { Candidates.emplace_back( @@ -114,7 +115,7 @@ for (const char *Ver : Versions) Candidates.emplace_back(D.SysRoot + "/usr/local/cuda-" + Ver); - Distro Dist(D.getVFS(), llvm::Triple(llvm::sys::getProcessTriple())); + Distro Dist(FS, llvm::Triple(llvm::sys::getProcessTriple())); if (Dist.IsDebian() || Dist.IsUbuntu()) // Special case for Debian to have nvidia-cuda-toolkit work // out of the box. More info on http://bugs.debian.org/882505 @@ -125,14 +126,13 @@ for (const auto &Candidate : Candidates) { InstallPath = Candidate.Path; - if (InstallPath.empty() || !D.getVFS().exists(InstallPath)) + if (InstallPath.empty() || !FS.exists(InstallPath)) continue; BinPath = InstallPath + "/bin"; IncludePath = InstallPath + "/include"; LibDevicePath = InstallPath + "/nvvm/libdevice"; - auto &FS = D.getVFS(); if (!(FS.exists(IncludePath) && FS.exists(BinPath))) continue; bool CheckLibDevice = (!NoCudaLib || Candidate.StrictChecking); @@ -177,7 +177,8 @@ } } else { std::error_code EC; - for (llvm::sys::fs::directory_iterator LI(LibDevicePath, EC), LE; + for (llvm::vfs::directory_iterator LI = FS.dir_begin(LibDevicePath, EC), + LE; !EC && LI != LE; LI = LI.increment(EC)) { StringRef FilePath = LI->path(); StringRef FileName = llvm::sys::path::filename(FilePath); Index: clang/lib/Driver/ToolChains/AMDGPU.cpp =================================================================== --- clang/lib/Driver/ToolChains/AMDGPU.cpp +++ clang/lib/Driver/ToolChains/AMDGPU.cpp @@ -27,7 +27,9 @@ const StringRef Suffix(".bc"); std::error_code EC; - for (llvm::sys::fs::directory_iterator LI(LibDevicePath, EC), LE; + for (llvm::vfs::directory_iterator + LI = D.getVFS().dir_begin(LibDevicePath, EC), + LE; !EC && LI != LE; LI = LI.increment(EC)) { StringRef FilePath = LI->path(); StringRef FileName = llvm::sys::path::filename(FilePath); @@ -137,11 +139,12 @@ LibDevicePath = LibPathEnv; } + auto &FS = D.getVFS(); if (!LibDevicePath.empty()) { // Maintain compatability with HIP flag/envvar pointing directly at the // bitcode library directory. This points directly at the library path instead // of the rocm root installation. - if (!D.getVFS().exists(LibDevicePath)) + if (!FS.exists(LibDevicePath)) return; scanLibDevicePath(); @@ -151,7 +154,7 @@ for (const auto &Candidate : Candidates) { InstallPath = Candidate.Path; - if (InstallPath.empty() || !D.getVFS().exists(InstallPath)) + if (InstallPath.empty() || !FS.exists(InstallPath)) continue; // The install path situation in old versions of ROCm is a real mess, and @@ -167,8 +170,6 @@ llvm::sys::path::append(IncludePath, InstallPath, "include"); llvm::sys::path::append(LibDevicePath, InstallPath, "amdgcn", "bitcode"); - auto &FS = D.getVFS(); - // We don't need the include path for OpenCL, since clang already ships with // the default header.
Index: clang/lib/Driver/ToolChains/Cuda.cpp =================================================================== --- clang/lib/Driver/ToolChains/Cuda.cpp +++ clang/lib/Driver/ToolChains/Cuda.cpp @@ -78,6 +78,7 @@ // In decreasing order so we prefer newer versions to older versions. std::initializer_list<const char *> Versions = {"8.0", "7.5", "7.0"}; + auto &FS = D.getVFS(); if (Args.hasArg(clang::driver::options::OPT_cuda_path_EQ)) { Candidates.emplace_back( @@ -114,7 +115,7 @@ for (const char *Ver : Versions) Candidates.emplace_back(D.SysRoot + "/usr/local/cuda-" + Ver); - Distro Dist(D.getVFS(), llvm::Triple(llvm::sys::getProcessTriple())); + Distro Dist(FS, llvm::Triple(llvm::sys::getProcessTriple())); if (Dist.IsDebian() || Dist.IsUbuntu()) // Special case for Debian to have nvidia-cuda-toolkit work // out of the box. More info on http://bugs.debian.org/882505 @@ -125,14 +126,13 @@ for (const auto &Candidate : Candidates) { InstallPath = Candidate.Path; - if (InstallPath.empty() || !D.getVFS().exists(InstallPath)) + if (InstallPath.empty() || !FS.exists(InstallPath)) continue; BinPath = InstallPath + "/bin"; IncludePath = InstallPath + "/include"; LibDevicePath = InstallPath + "/nvvm/libdevice"; - auto &FS = D.getVFS(); if (!(FS.exists(IncludePath) && FS.exists(BinPath))) continue; bool CheckLibDevice = (!NoCudaLib || Candidate.StrictChecking); @@ -177,7 +177,8 @@ } } else { std::error_code EC; - for (llvm::sys::fs::directory_iterator LI(LibDevicePath, EC), LE; + for (llvm::vfs::directory_iterator LI = FS.dir_begin(LibDevicePath, EC), + LE; !EC && LI != LE; LI = LI.increment(EC)) { StringRef FilePath = LI->path(); StringRef FileName = llvm::sys::path::filename(FilePath); Index: clang/lib/Driver/ToolChains/AMDGPU.cpp =================================================================== --- clang/lib/Driver/ToolChains/AMDGPU.cpp +++ clang/lib/Driver/ToolChains/AMDGPU.cpp @@ -27,7 +27,9 @@ const StringRef Suffix(".bc"); std::error_code EC; - for (llvm::sys::fs::directory_iterator LI(LibDevicePath, EC), LE; + for (llvm::vfs::directory_iterator + LI = D.getVFS().dir_begin(LibDevicePath, EC), + LE; !EC && LI != LE; LI = LI.increment(EC)) { StringRef FilePath = LI->path(); StringRef FileName = llvm::sys::path::filename(FilePath); @@ -137,11 +139,12 @@ LibDevicePath = LibPathEnv; } + auto &FS = D.getVFS(); if (!LibDevicePath.empty()) { // Maintain compatability with HIP flag/envvar pointing directly at the // bitcode library directory. This points directly at the library path instead // of the rocm root installation. - if (!D.getVFS().exists(LibDevicePath)) + if (!FS.exists(LibDevicePath)) return; scanLibDevicePath(); @@ -151,7 +154,7 @@ for (const auto &Candidate : Candidates) { InstallPath = Candidate.Path; - if (InstallPath.empty() || !D.getVFS().exists(InstallPath)) + if (InstallPath.empty() || !FS.exists(InstallPath)) continue; // The install path situation in old versions of ROCm is a real mess, and @@ -167,8 +170,6 @@ llvm::sys::path::append(IncludePath, InstallPath, "include"); llvm::sys::path::append(LibDevicePath, InstallPath, "amdgcn", "bitcode"); - auto &FS = D.getVFS(); - // We don't need the include path for OpenCL, since clang already ships with // the default header.
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits