Author: Shilei Tian Date: 2022-04-22T18:07:28-04:00 New Revision: 20a9fb953e46b1d97aaee7b182b0f3d48f340bd1
URL: https://github.com/llvm/llvm-project/commit/20a9fb953e46b1d97aaee7b182b0f3d48f340bd1 DIFF: https://github.com/llvm/llvm-project/commit/20a9fb953e46b1d97aaee7b182b0f3d48f340bd1.diff LOG: [Clang][OpenMP] Fix the issue that temp cubin files are not removed after compilation when using new OpenMP driver The root cause of this is, in `NVPTX::Assembler::ConstructJob`, the output file name might not match the `Output`'s file name passed into the function because `CudaToolChain::getInputFilename` is a specialized version. That means the real output file is not added to the temp files list, which will be all removed in the d'tor of `Compilation`. In order to "fix" it, in the function `NVPTX::OpenMPLinker::ConstructJob`, before calling `clang-nvlink-wrapper`, the function calls `getToolChain().getInputFilename(II)` to get the right output file name for each input, and add it to temp file, and then they can be removed w/o any issue. However, this whole logic doesn't work when using the new OpenMP driver because `NVPTX::OpenMPLinker::ConstructJob` is not called at all, which causing the issue that the cubin file generated in each single unit compilation is out of track. In this patch, we add the real output file into temp files if its name doesn't match `Output`. We add it when the file is an output instead of doing it when it is an input, like what we did in `NVPTX::OpenMPLinker::ConstructJob`, which makes more sense. Reviewed By: jhuber6 Differential Revision: https://reviews.llvm.org/D124253 Added: Modified: clang/lib/Driver/ToolChains/Cuda.cpp Removed: ################################################################################ diff --git a/clang/lib/Driver/ToolChains/Cuda.cpp b/clang/lib/Driver/ToolChains/Cuda.cpp index f8a06a2e09ab7..6103c42bf7547 100644 --- a/clang/lib/Driver/ToolChains/Cuda.cpp +++ b/clang/lib/Driver/ToolChains/Cuda.cpp @@ -447,7 +447,10 @@ void NVPTX::Assembler::ConstructJob(Compilation &C, const JobAction &JA, CmdArgs.push_back("--gpu-name"); CmdArgs.push_back(Args.MakeArgString(CudaArchToString(gpu_arch))); CmdArgs.push_back("--output-file"); - CmdArgs.push_back(Args.MakeArgString(TC.getInputFilename(Output))); + const char *OutputFileName = Args.MakeArgString(TC.getInputFilename(Output)); + if (std::string(OutputFileName) != std::string(Output.getFilename())) + C.addTempFile(OutputFileName); + CmdArgs.push_back(OutputFileName); for (const auto& II : Inputs) CmdArgs.push_back(Args.MakeArgString(II.getFilename())); @@ -606,8 +609,8 @@ void NVPTX::OpenMPLinker::ConstructJob(Compilation &C, const JobAction &JA, if (!II.isFilename()) continue; - const char *CubinF = C.addTempFile( - C.getArgs().MakeArgString(getToolChain().getInputFilename(II))); + const char *CubinF = + C.getArgs().MakeArgString(getToolChain().getInputFilename(II)); CmdArgs.push_back(CubinF); } _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits