diff --git a/clang/lib/DPCT/CMakeLists.txt b/clang/lib/DPCT/CMakeLists.txt index b74c77697383..e7173decb994 100644 --- a/clang/lib/DPCT/CMakeLists.txt +++ b/clang/lib/DPCT/CMakeLists.txt @@ -212,6 +212,7 @@ add_clang_library(DPCT Diagnostics/Diagnostics.cpp ErrorHandle/Error.cpp MigrationReport/Statics.cpp + MigrationReport/RecommendLibraries.cpp RuleInfra/ExprAnalysis.cpp ExtReplacements.cpp RuleInfra/MapNames.cpp diff --git a/clang/lib/DPCT/DPCT.cpp b/clang/lib/DPCT/DPCT.cpp index 2f06c278c1ea..4174f27e72e6 100644 --- a/clang/lib/DPCT/DPCT.cpp +++ b/clang/lib/DPCT/DPCT.cpp @@ -7,6 +7,7 @@ //===----------------------------------------------------------------------===// #include "clang/DPCT/DPCT.h" +#include "MigrationReport/RecommendLibraries.h" #include "ASTTraversal.h" #include "AnalysisInfo.h" #include "CommandOption/ValidateArguments.h" @@ -1481,7 +1482,9 @@ int runDPCT(int argc, const char **argv) { return showAPIMapping(QueryAPIMappingSrc, QueryAPIMappingOpt, Tool, ReplSYCL); } - + if (!ReplSYCL.empty()) { + CollectDepLib(ReplSYCL); + } // OC_Action: Analysis mode if (DpctGlobalInfo::isAnalysisModeEnabled()) { if (AnalysisModeOutputFile.getValue().empty()) { diff --git a/clang/lib/DPCT/FileGenerator/GenFiles.cpp b/clang/lib/DPCT/FileGenerator/GenFiles.cpp index a2d95abc735b..6055d806b7c6 100644 --- a/clang/lib/DPCT/FileGenerator/GenFiles.cpp +++ b/clang/lib/DPCT/FileGenerator/GenFiles.cpp @@ -34,6 +34,8 @@ #include "llvm/Support/Path.h" #include "llvm/Support/raw_os_ostream.h" +#include "MigrationReport/RecommendLibraries.h" + #include #include #include @@ -996,6 +998,7 @@ int saveNewFiles(clang::tooling::RefactoringTool &Tool, clang::dpct::RT_CUDAWithCodePin)) return RewriteStatus; } + PrintRecommendLibs(llvm::outs()); // Print the in-root path and the number of processed files size_t ProcessedFileNumber; if (ProcessAll) { diff --git a/clang/lib/DPCT/MigrationReport/RecommendLibraries.cpp b/clang/lib/DPCT/MigrationReport/RecommendLibraries.cpp new file mode 100644 index 000000000000..c9223271c40b --- /dev/null +++ b/clang/lib/DPCT/MigrationReport/RecommendLibraries.cpp @@ -0,0 +1,98 @@ +//===--------------- RecommendLibraries.cpp ------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "RecommendLibraries.h" +#include "FileGenerator/GenFiles.h" +#include "Statics.h" +#include +#include + +namespace clang { +namespace dpct { +struct RecommendLib { + std::string Feature; + std::string SupportedVersion; + std::string ReplacementText; + LibType CompType; + std::string Description; + + RecommendLib() = default; + RecommendLib(std::unordered_map &Table, + std::string Feature, std::string SupportedVersion, LibType CT, + std::string ReplacementText, std::string Description) + : Feature(Feature), SupportedVersion(SupportedVersion), + ReplacementText(ReplacementText), CompType(CT), + Description(Description) { + Table[CT] = *this; + } +}; +static std::unordered_map + RecommendLibs; +std::vector RecommendLibList; + +#define RECOMMENDLIBRARY(NAME, Feature, VERSION, COMPTYPE, REPLACEMENT, MSG) \ + RecommendLib DepRecommend_##NAME(RecommendLibs, Feature, VERSION, COMPTYPE, \ + REPLACEMENT, MSG); +#include "RecommendLibrariesVersion.inc" + +void CollectDepLib(ReplTy &Repls) { + for (auto Entry : RecommendLibs) { + auto &Lib = Entry.second; + [&]() { + for (auto Repl : Repls) { + for (auto Item : Repl.second) { + if (Item.getReplacementText().str().find(Lib.ReplacementText) != + std::string::npos) { + RecommendLibList.push_back(Lib); + return; + } + } + } + }(); + } +} + +std::string LibTypeToString(LibType version) { + switch (version) { + case LibType::DPCPP: + return "oneAPI DPC++ compiler Open Source Version"; + case LibType::oneDPL: + return "oneAPI DPC++ Library Open Source Version"; + case LibType::oneMath: + return "oneAPI Math Library Open Source Version"; + case LibType::oneCCL: + return "oneAPI Collective Communications Library Open Source Version"; + case LibType::oneDNNL: + return "oneAPI Deep Neural Network Library Open Source Version"; + case LibType::ISHMEM: + return "oneAPI SHMEM Library Open Source Version"; + default: + return "Unknown Component Type "; + } +} + +void PrintRecommendLibs(llvm::raw_ostream &OStream) { + if (RecommendLibList.empty()) + return; + if (DpctGlobalInfo::isAnalysisModeEnabled()) + OStream << llvm::raw_ostream::Colors::BLUE; + + OStream << "Recommend Library Dependencies of SYCL Project:\n"; + + if (DpctGlobalInfo::isAnalysisModeEnabled()) + OStream << llvm::raw_ostream::Colors::RESET; + for (auto &Status : RecommendLibList) { + OStream << " - The " + Status.Feature + " is supported in " + + LibTypeToString(Status.CompType) + " and after " + + Status.SupportedVersion + ". " + Status.Description + "\n"; + } +} + + +} // namespace dpct +} // namespace clang \ No newline at end of file diff --git a/clang/lib/DPCT/MigrationReport/RecommendLibraries.h b/clang/lib/DPCT/MigrationReport/RecommendLibraries.h new file mode 100644 index 000000000000..b0bf5bec0ff5 --- /dev/null +++ b/clang/lib/DPCT/MigrationReport/RecommendLibraries.h @@ -0,0 +1,25 @@ +//===--------------- RecommendLibraries.h --------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +#ifndef RECOMMEND_LIBRARIES_H +#define RECOMMEND_LIBRARIES_H + +#include "AnalysisInfo.h" +#include "FileGenerator/GenFiles.h" +#include "llvm/Support/raw_ostream.h" +#include +#include + +namespace clang { +namespace dpct { +enum class LibType { DPCPP, oneDPL, oneMath, oneCCL, oneDNNL, ISHMEM }; + +void CollectDepLib(ReplTy &MainSrcFilesRepls); +void PrintRecommendLibs(llvm::raw_ostream &OStream); +} // namespace dpct +} // namespace clang +#endif // RECOMMEND_LIBRARIES_H diff --git a/clang/lib/DPCT/MigrationReport/RecommendLibrariesVersion.inc b/clang/lib/DPCT/MigrationReport/RecommendLibrariesVersion.inc new file mode 100644 index 000000000000..115fe99fd7fb --- /dev/null +++ b/clang/lib/DPCT/MigrationReport/RecommendLibrariesVersion.inc @@ -0,0 +1,19 @@ +//===--------------- RecommendLibrariesVersion.inc --------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +// - Name: Obj name +// Feature: Feature name +// SupportedVersion: Time stamp of component +// LibType: Component type. +// ReplacementText: The migrated Replacement Text +// Description: Details of the feature. + +#ifndef RECOMMENDLIBRARY +#define RECOMMENDLIBRARY +#endif +// Example: +// RECOMMENDLIBRARY(FreeQuery, "SYCL free function query", "2025", LibType::DPCPP, "this_work_item", "See https://github.com/intel/llvm/blob/sycl/sycl/doc/extensions/proposed/sycl_ext_oneapi_free_function_kernels.asciidoc for more details.") \ No newline at end of file diff --git a/clang/lib/DPCT/MigrationReport/Statics.cpp b/clang/lib/DPCT/MigrationReport/Statics.cpp index 321571a8810d..5a1b00a57313 100644 --- a/clang/lib/DPCT/MigrationReport/Statics.cpp +++ b/clang/lib/DPCT/MigrationReport/Statics.cpp @@ -8,6 +8,7 @@ #include "MigrationReport/Statics.h" #include "ASTTraversal.h" #include "RulesInclude/InclusionHeaders.h" +#include "MigrationReport/RecommendLibraries.h" #include #include @@ -363,6 +364,8 @@ class AnalysisModeStats { } } LineStream(OS, Indent) << LastMsg; + + PrintRecommendLibs(OS); } static void recordApisOrTypes(SourceLocation SL, StringRef Name,