https://github.com/zhouronghua updated https://github.com/llvm/llvm-project/pull/119513
>From c767342682f67da542f1d6ad7d2146885e50f69b Mon Sep 17 00:00:00 2001 From: "ronghua.zhou" <ronghua.z...@enflame-tech.com> Date: Tue, 10 Dec 2024 06:32:24 +0000 Subject: [PATCH 1/2] [Feature](INF-2526) infra: support for the BC library file into the compile dependencies Change-Id: I0f1887f972653a48a4ea0a26768e5b729664c427 --- clang/lib/Driver/ToolChains/Clang.cpp | 45 ++++++++++++++++++++++--- clang/lib/Frontend/CompilerInstance.cpp | 10 ++++-- 2 files changed, 48 insertions(+), 7 deletions(-) diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp index d3206c3e8e25e..9a0d8f8938ba3 100644 --- a/clang/lib/Driver/ToolChains/Clang.cpp +++ b/clang/lib/Driver/ToolChains/Clang.cpp @@ -996,9 +996,9 @@ void Clang::AddPreprocessingOptions(Compilation &C, const JobAction &JA, else ArgM = ArgMD; + // Determine the output location. + const char *DepFile = nullptr; if (ArgM) { - // Determine the output location. - const char *DepFile; if (Arg *MF = Args.getLastArg(options::OPT_MF)) { DepFile = MF->getValue(); C.addFailureResultFile(DepFile, &JA); @@ -1010,8 +1010,9 @@ void Clang::AddPreprocessingOptions(Compilation &C, const JobAction &JA, DepFile = getDependencyFileName(Args, Inputs); C.addFailureResultFile(DepFile, &JA); } - CmdArgs.push_back("-dependency-file"); - CmdArgs.push_back(DepFile); + // mv to dtu select + // CmdArgs.push_back("-dependency-file"); + // CmdArgs.push_back(DepFile); bool HasTarget = false; for (const Arg *A : Args.filtered(options::OPT_MT, options::OPT_MQ)) { @@ -1100,6 +1101,41 @@ void Clang::AddPreprocessingOptions(Compilation &C, const JobAction &JA, CmdArgs.push_back("__clang_openmp_device_functions.h"); } + if (getToolChain().getTriple().isNVPTX() || + getToolChain().getTriple().isAMDGCN()) { + // When we set(CMAKE_DEPFILE_FLAGS_${lang} "-MD -MT <DEP_TARGET> -MF + // <DEP_FILE>.host") in cmake during heterogeneous compilation, + // we really gererate *.d.host (for host) and *.d (for GPU target), + // the content of *.d = *.d.host + builtin.bc (i.e. libdevice.10.bc or some + // files in --hip-device-lib) + // so when libdevice.10.bc or hip-device-lib is updated, the incremental + // build rule will be triggered. + if (DepFile) { + SmallString<128> NewDepFile(DepFile); + llvm::StringRef SubStr = ".host"; + size_t Pos = NewDepFile.find(SubStr); + CmdArgs.push_back("-dependency-file"); + // for tops target, trim .host in dep file + if (Pos != llvm::StringRef::npos) { + // erase substr + auto ndf = NewDepFile.substr(0, Pos); + CmdArgs.push_back(Args.MakeArgString(ndf)); + } else { + // if not set dep file with .host extend, remain depfile not touched + CmdArgs.push_back(Args.MakeArgString(DepFile)); + } + } + } + // Host side remain depfile not touched + else { + // for host compile, we generate orginal dep file + if (DepFile) { + CmdArgs.push_back("-dependency-file"); + CmdArgs.push_back(DepFile); + } + GenerateHostCompilationDeviceArchMacro(Args, CmdArgs); + } + if (Args.hasArg(options::OPT_foffload_via_llvm)) { // Add llvm_wrappers/* to our system include path. This lets us wrap // standard library headers and other headers. @@ -1110,7 +1146,6 @@ void Clang::AddPreprocessingOptions(Compilation &C, const JobAction &JA, CmdArgs.push_back("__llvm_offload_device.h"); else CmdArgs.push_back("__llvm_offload_host.h"); - } // Add -i* options, and automatically translate to // -include-pch/-include-pth for transparent PCH support. It's diff --git a/clang/lib/Frontend/CompilerInstance.cpp b/clang/lib/Frontend/CompilerInstance.cpp index fbfc305ca06a0..14779b0161a70 100644 --- a/clang/lib/Frontend/CompilerInstance.cpp +++ b/clang/lib/Frontend/CompilerInstance.cpp @@ -494,8 +494,14 @@ void CompilerInstance::createPreprocessor(TranslationUnitKind TUKind) { // Handle generating dependencies, if requested. const DependencyOutputOptions &DepOpts = getDependencyOutputOpts(); - if (!DepOpts.OutputFile.empty()) - addDependencyCollector(std::make_shared<DependencyFileGenerator>(DepOpts)); + if (!DepOpts.OutputFile.empty()) { + auto DFG = std::make_shared<DependencyFileGenerator>(DepOpts); + for (auto F : getCodeGenOpts().LinkBitcodeFiles) { + DFG->maybeAddDependency(F.Filename, false, false, false, false); + } + addDependencyCollector(DFG); + } + if (!DepOpts.DOTOutputFile.empty()) AttachDependencyGraphGen(*PP, DepOpts.DOTOutputFile, getHeaderSearchOpts().Sysroot); >From ada7f2139890dc9484212ca77fa07309b4903d89 Mon Sep 17 00:00:00 2001 From: "ronghua.zhou" <ronghua.z...@enflame-tech.com> Date: Tue, 10 Dec 2024 06:32:24 +0000 Subject: [PATCH 2/2] [Feature]: support for the BC library file into the compile dependencies --- clang/lib/Driver/ToolChains/Clang.cpp | 37 ++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp index 9a0d8f8938ba3..3e3caa80260f1 100644 --- a/clang/lib/Driver/ToolChains/Clang.cpp +++ b/clang/lib/Driver/ToolChains/Clang.cpp @@ -1010,10 +1010,45 @@ void Clang::AddPreprocessingOptions(Compilation &C, const JobAction &JA, DepFile = getDependencyFileName(Args, Inputs); C.addFailureResultFile(DepFile, &JA); } - // mv to dtu select + // mv to triple select // CmdArgs.push_back("-dependency-file"); // CmdArgs.push_back(DepFile); + if (getToolChain().getTriple().isNVPTX() || + getToolChain().getTriple().isAMDGCN()) { + // When we set(CMAKE_DEPFILE_FLAGS_${lang} "-MD -MT <DEP_TARGET> -MF + // <DEP_FILE>.host") in cmake during heterogeneous compilation, + // we really gererate *.d.host (for host) and *.d (for GPU target), + // the content of *.d = *.d.host + builtin.bc (i.e. libdevice.10.bc or + // some + // files in --hip-device-lib) + // so when libdevice.10.bc or hip-device-lib is updated, the incremental + // build rule will be triggered. + if (DepFile) { + SmallString<128> NewDepFile(DepFile); + llvm::StringRef SubStr = ".host"; + size_t Pos = NewDepFile.find(SubStr); + CmdArgs.push_back("-dependency-file"); + // for tops target, trim .host in dep file + if (Pos != llvm::StringRef::npos) { + // erase substr + auto ndf = NewDepFile.substr(0, Pos); + CmdArgs.push_back(Args.MakeArgString(ndf)); + } else { + // if not set dep file with .host extend, remain depfile not touched + CmdArgs.push_back(Args.MakeArgString(DepFile)); + } + } + } + // Host side remain depfile not touched + else { + // for host compile, we generate orginal dep file + if (DepFile) { + CmdArgs.push_back("-dependency-file"); + CmdArgs.push_back(DepFile); + } + } + bool HasTarget = false; for (const Arg *A : Args.filtered(options::OPT_MT, options::OPT_MQ)) { HasTarget = true; _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits