From 5a26b30f36da7e078253efb1a1f9e4a663cd7e7f Mon Sep 17 00:00:00 2001 From: "Jiang, Zhiwei" Date: Mon, 30 Jun 2025 08:51:56 +0800 Subject: [PATCH 1/7] Fixing lit Signed-off-by: Jiang, Zhiwei --- clang/lib/DPCT/AnalysisInfo.cpp | 22 +-- clang/lib/DPCT/AnalysisInfo.h | 33 +--- clang/lib/DPCT/DPCT.cpp | 14 +- clang/lib/DPCT/ErrorHandle/Error.cpp | 5 +- clang/lib/DPCT/ErrorHandle/Error.h | 2 +- clang/lib/DPCT/FileGenerator/GenFiles.cpp | 169 +++++++----------- clang/lib/DPCT/FileGenerator/GenFiles.h | 2 +- .../DPCT/IncMigration/ExternalReplacement.cpp | 48 +---- .../DPCT/IncMigration/ExternalReplacement.h | 7 - .../IncrementalMigrationUtility.cpp | 21 +-- clang/lib/DPCT/PreProcessor.cpp | 2 +- .../RulesLang/RulesLangNoneAPIAndType.cpp | 8 +- 12 files changed, 105 insertions(+), 228 deletions(-) diff --git a/clang/lib/DPCT/AnalysisInfo.cpp b/clang/lib/DPCT/AnalysisInfo.cpp index 36cd3cfe5405..5acbc1bff8be 100644 --- a/clang/lib/DPCT/AnalysisInfo.cpp +++ b/clang/lib/DPCT/AnalysisInfo.cpp @@ -2098,21 +2098,20 @@ std::shared_ptr DpctGlobalInfo::findCudaMalloc(const Expr *E) { return findCudaMallocInfo(Src); return std::shared_ptr(); } -void DpctGlobalInfo::insertReplInfoFromYAMLToFileInfo( +void DpctGlobalInfo::insertReplVecFromYAMLToFileInfo( const clang::tooling::UnifiedPath &FilePath, - std::shared_ptr TUR) { + std::vector Vec) { auto FileInfo = insertFile(FilePath); - if (FileInfo->PreviousTUReplFromYAML == nullptr) - FileInfo->PreviousTUReplFromYAML = TUR; + FileInfo->PreviousReplVecFromYAML = Vec; } -std::shared_ptr -DpctGlobalInfo::getReplInfoFromYAMLSavedInFileInfo( +std::optional> +DpctGlobalInfo::getReplVecFromYAMLSavedInFileInfo( clang::tooling::UnifiedPath FilePath) { auto FileInfo = findObject(FileMap, FilePath); if (FileInfo) - return FileInfo->PreviousTUReplFromYAML; + return FileInfo->PreviousReplVecFromYAML; else - return nullptr; + return std::nullopt; } void DpctGlobalInfo::insertEventSyncTypeInfo( const std::shared_ptr Repl, bool NeedReport, @@ -2308,8 +2307,6 @@ void DpctGlobalInfo::resetInfo() { FunctionCallInMacroMigrateRecord.clear(); EndOfEmptyMacros.clear(); BeginOfEmptyMacros.clear(); - FileRelpsMap.clear(); - MsfInfoMap.clear(); MacroDefines.clear(); CAPPInfoMap.clear(); CurrentMaxIndex = 0; @@ -2470,11 +2467,6 @@ std::map DpctGlobalInfo::FunctionCallInMacroMigrateRecord; std::map DpctGlobalInfo::EndOfEmptyMacros; std::map DpctGlobalInfo::BeginOfEmptyMacros; -std::unordered_map> - DpctGlobalInfo::FileRelpsMap; -std::unordered_map - DpctGlobalInfo::MsfInfoMap; -const std::string DpctGlobalInfo::YamlFileName = "MainSourceFiles.yaml"; std::map DpctGlobalInfo::MacroDefines; int DpctGlobalInfo::CurrentMaxIndex = 0; int DpctGlobalInfo::CurrentIndexInRule = 0; diff --git a/clang/lib/DPCT/AnalysisInfo.h b/clang/lib/DPCT/AnalysisInfo.h index 06958a3785ec..5e1a46988877 100644 --- a/clang/lib/DPCT/AnalysisInfo.h +++ b/clang/lib/DPCT/AnalysisInfo.h @@ -507,9 +507,6 @@ class DpctFileInfo { getConstantMacroTMSet() { return ConstantMacroTMSet; } - std::vector &getReplacements() { - return PreviousTUReplFromYAML->Replacements; - } std::unordered_map> & getAtomicMap() { return AtomicMap; @@ -534,8 +531,8 @@ class DpctFileInfo { void setCCLVerValue(std::string Value) { CCLVerValue = Value; } std::string getCCLVerValue() { return CCLVerValue; } - std::shared_ptr PreviousTUReplFromYAML = - nullptr; + std::optional> PreviousReplVecFromYAML = + std::nullopt; private: std::vector> TimeStubBounds; @@ -1178,11 +1175,11 @@ class DpctGlobalInfo { return CudaArchMacroRepl; } CudaArchDefMap &getCudaArchDefinedMap() { return CudaArchDefinedMap; } - void insertReplInfoFromYAMLToFileInfo( - const clang::tooling::UnifiedPath &FilePath, - std::shared_ptr TUR); - std::shared_ptr - getReplInfoFromYAMLSavedInFileInfo(clang::tooling::UnifiedPath FilePath); + void + insertReplVecFromYAMLToFileInfo(const clang::tooling::UnifiedPath &FilePath, + std::vector Vec); + std::optional> + getReplVecFromYAMLSavedInFileInfo(clang::tooling::UnifiedPath FilePath); void insertEventSyncTypeInfo( const std::shared_ptr Repl, bool NeedReport = false, bool IsAssigned = false); @@ -1257,16 +1254,6 @@ class DpctGlobalInfo { static std::set &getFileSetInCompilationDB() { return FileSetInCompilationDB; } - static std::unordered_map> & - getFileRelpsMap() { - return FileRelpsMap; - } - static std::unordered_map & - getMsfInfoMap() { - return MsfInfoMap; - } - static std::string getYamlFileName() { return YamlFileName; } static std::set &getGlobalVarNameSet() { return GlobalVarNameSet; } @@ -1651,12 +1638,6 @@ class DpctGlobalInfo { // key: The hash string of the begin location of the macro expansion // value: The end location of the macro expansion static std::map BeginOfEmptyMacros; - static std::unordered_map> - FileRelpsMap; - static std::unordered_map - MsfInfoMap; - static const std::string YamlFileName; static std::map MacroDefines; static int CurrentMaxIndex; static int CurrentIndexInRule; diff --git a/clang/lib/DPCT/DPCT.cpp b/clang/lib/DPCT/DPCT.cpp index 2f06c278c1ea..6a674b923573 100644 --- a/clang/lib/DPCT/DPCT.cpp +++ b/clang/lib/DPCT/DPCT.cpp @@ -516,14 +516,13 @@ void updateCompatibilityVersionInfo(clang::tooling::UnifiedPath OutRoot, OutFile.close(); } -static void loadMainSrcFileInfo(clang::tooling::UnifiedPath OutRoot) { - std::string YamlFilePath = appendPath(OutRoot.getCanonicalPath().str(), - DpctGlobalInfo::getYamlFileName()); +static void loadMainSrcFileInfo(clang::tooling::UnifiedPath YamlFilePath) { auto PreTU = std::make_shared(); - if (llvm::sys::fs::exists(YamlFilePath)) { + if (llvm::sys::fs::exists(YamlFilePath.getCanonicalPath())) { if (loadFromYaml(YamlFilePath, *PreTU) != 0) { - llvm::errs() << getLoadYamlFailWarning(YamlFilePath); + llvm::errs() << getLoadYamlFailWarning(); } + DpctGlobalInfo::setMainSourceYamlTUR(PreTU); if (MigrateBuildScriptOnly && !DpctGlobalInfo::migratePythonScripts() || DpctGlobalInfo::migrateCMakeScripts()) { @@ -679,7 +678,6 @@ int migrateBuildScripts(const clang::tooling::UnifiedPath &InRoot, } void doBuildScriptMigration() { - loadMainSrcFileInfo(OutRootPath); collectBuildScripts(InRootPath, OutRootPath); migrateBuildScripts(InRootPath, OutRootPath); } @@ -817,6 +815,9 @@ int runDPCT(int argc, const char **argv) { std::string OutRootPathCUDACodepin = ""; CudaIncludePath = CudaInclude; SDKPath = SDKPathOpt; + + loadMainSrcFileInfo(OutRootPath.getCanonicalPath() + "/MainSourceFiles.yaml"); + std::transform( RuleFile.begin(), RuleFile.end(), std::back_insert_iterator>( @@ -1394,7 +1395,6 @@ int runDPCT(int argc, const char **argv) { } // OC_Action: only migrate Build scripts. if (MigrateBuildScriptOnly) { - loadMainSrcFileInfo(OutRootPath); collectBuildScriptsSpecified(OptParser, InRootPath, OutRootPath); migrateBuildScripts(InRootPath, OutRootPath); diff --git a/clang/lib/DPCT/ErrorHandle/Error.cpp b/clang/lib/DPCT/ErrorHandle/Error.cpp index ed0c0aa3ccda..add100d11df7 100644 --- a/clang/lib/DPCT/ErrorHandle/Error.cpp +++ b/clang/lib/DPCT/ErrorHandle/Error.cpp @@ -238,9 +238,8 @@ void ShowStatus(int Status, std::string Message) { return; } -std::string getLoadYamlFailWarning(const clang::tooling::UnifiedPath &YamlPath) { - return "Warning: Failed to load " + YamlPath.getCanonicalPath().str() + - ". Migration continues with incremental migration disabled. See " +std::string getLoadYamlFailWarning() { + return "Warning: Migration continues with incremental migration disabled. See " "https://www.intel.com/content/www/us/en/docs/" "dpcpp-compatibility-tool/developer-guide-reference/current/" "overview.html for more " diff --git a/clang/lib/DPCT/ErrorHandle/Error.h b/clang/lib/DPCT/ErrorHandle/Error.h index 18dad69b5c34..a84f0729ec5a 100644 --- a/clang/lib/DPCT/ErrorHandle/Error.h +++ b/clang/lib/DPCT/ErrorHandle/Error.h @@ -74,7 +74,7 @@ namespace clang { namespace dpct { void ShowStatus(int Status, std::string Message = ""); -std::string getLoadYamlFailWarning(const clang::tooling::UnifiedPath& YamlPath); +std::string getLoadYamlFailWarning(); std::string getCheckVersionFailWarning(); std::string getBuildScriptNotSpecifiedWarning(); std::string getPythonRuleFileNotProvidedWarning(); diff --git a/clang/lib/DPCT/FileGenerator/GenFiles.cpp b/clang/lib/DPCT/FileGenerator/GenFiles.cpp index a2d95abc735b..04c83d480385 100644 --- a/clang/lib/DPCT/FileGenerator/GenFiles.cpp +++ b/clang/lib/DPCT/FileGenerator/GenFiles.cpp @@ -440,48 +440,31 @@ void processAllFiles(StringRef InRoot, StringRef OutRoot, } } - -static void getMainSrcFilesRepls( - std::vector &MainSrcFilesRepls) { - auto &FileRelpsMap = DpctGlobalInfo::getFileRelpsMap(); - for (const auto &Entry : FileRelpsMap) - for (const auto &Repl : Entry.second) - MainSrcFilesRepls.push_back(Repl); -} -static void getMainSrcFilesInfo( - std::vector &MainSrcFilesInfo) { - auto &MsfInfoMap = DpctGlobalInfo::getMsfInfoMap(); - for (const auto &Entry : MsfInfoMap) - MainSrcFilesInfo.push_back(Entry.second); +static bool +updateMainSrcFilesInfo(const clang::tooling::MainSourceFileInfo &Info) { + auto &InfoVec = DpctGlobalInfo::getMainSourceYamlTUR()->MainSourceFilesDigest; + auto It = + std::find_if(InfoVec.begin(), InfoVec.end(), + [&Info](const clang::tooling::MainSourceFileInfo &Entry) { + return Entry.MainSourceFile == Info.MainSourceFile; + }); + if (It != InfoVec.end()) { + It->HasCUDASyntax |= Info.HasCUDASyntax; + if (It->Digest != Info.Digest) { + It->Digest = Info.Digest; + return true; + } + return false; + } + InfoVec.push_back(Info); + return false; } static void saveUpdatedMigrationDataIntoYAML( - std::vector &MainSrcFilesRepls, - std::vector &MainSrcFilesInfo, - clang::tooling::UnifiedPath YamlFile, clang::tooling::UnifiedPath SrcFile, + std::vector &AllFilesRepls, std::unordered_map &MainSrcFileMap) { - // Save history repls to yaml file. - auto &FileRelpsMap = DpctGlobalInfo::getFileRelpsMap(); - for (const auto &Entry : FileRelpsMap) { - if (MainSrcFileMap[Entry.first]) - continue; - for (const auto &Repl : Entry.second) { - MainSrcFilesRepls.push_back(Repl); - } - } - - // Save history main src file and its content md5 hash to yaml file. - auto &MsfInfoMap = DpctGlobalInfo::getMsfInfoMap(); - for (const auto &Entry : MsfInfoMap) { - if (!MainSrcFileMap[Entry.first]) { - MainSrcFilesInfo.push_back(Entry.second); - } - } - - if (!MainSrcFilesRepls.empty() || !MainSrcFilesInfo.empty() || - !CompileCmdsPerTarget.empty()) { - save2Yaml(YamlFile, SrcFile, MainSrcFilesRepls, MainSrcFilesInfo, - CompileCmdsPerTarget); + if (!AllFilesRepls.empty() || !CompileCmdsPerTarget.empty()) { + save2Yaml(AllFilesRepls, CompileCmdsPerTarget); } } @@ -507,12 +490,21 @@ void applyPatternRewriter(const std::string &InputString, } } +static void getReplsFromTUR(const std::string &FilePath, + std::vector &Repls) { + for (const auto &Repl : + DpctGlobalInfo::getMainSourceYamlTUR()->Replacements) { + if (Repl.getFilePath() == FilePath) { + Repls.push_back(Repl); + } + } +} + int writeReplacementsToFiles( ReplTy &Replset, Rewriter &Rewrite, const std::string &Folder, clang::tooling::UnifiedPath &InRoot, - std::vector &MainSrcFilesInfo, std::unordered_map &MainSrcFileMap, - std::vector &MainSrcFilesRepls, + std::vector &AllFilesRepls, std::unordered_map> &FileRangesMap, std::unordered_mapsecond.Digest != Digest->digest().c_str()) - IsMainSrcFileChanged = true; - - HasCUDASyntax = DigestIter->second.HasCUDASyntax || HasCUDASyntax; - } - - MainSrcFilesInfo.push_back(clang::tooling::MainSourceFileInfo( - Entry.first, Hash->digest().c_str(), HasCUDASyntax)); - - auto &FileRelpsMap = dpct::DpctGlobalInfo::getFileRelpsMap(); - auto Iter = FileRelpsMap.find(Entry.first); - if (Iter != FileRelpsMap.end() && !IsMainSrcFileChanged) { - const auto &PreRepls = Iter->second; + bool IsMainSrcFileChanged = + updateMainSrcFilesInfo(clang::tooling::MainSourceFileInfo( + Entry.first, Hash->digest().c_str(), + DpctGlobalInfo::hasCUDASyntax(Entry.first))); + + std::vector PreRepls; + getReplsFromTUR(Entry.first, PreRepls); + if (!PreRepls.empty() && !IsMainSrcFileChanged) { mergeAndUniqueReps(Entry.second, PreRepls); } // Mark current migrating main src file processed. MainSrcFileMap[Entry.first] = true; - - for (const auto &Repl : Entry.second) { - MainSrcFilesRepls.push_back(Repl); - } + } + for (const auto &Repl : Entry.second) { + AllFilesRepls.push_back(Repl); } } @@ -638,6 +616,7 @@ int writeReplacementsToFiles( *Result, clang::SrcMgr::C_User /*normal user code*/)) .write(OutStream); } else { + ///// !!!!!!!!!!!!!!!!!!! If we use remigration, we need to disable pattern rewriter. std::string OutputString; llvm::raw_string_ostream RSW(OutputString); Rewrite @@ -939,19 +918,9 @@ int saveNewFiles(clang::tooling::RefactoringTool &Tool, bool /*false:Not processed in current migration*/> MainSrcFileMap; - std::string SrcFile = "MainSrcFiles_placehold"; - std::string YamlFile = appendPath(OutRoot.getCanonicalPath().str(), - DpctGlobalInfo::getYamlFileName()); if (clang::dpct::DpctGlobalInfo::isIncMigration()) { auto PreTU = clang::dpct::DpctGlobalInfo::getMainSourceYamlTUR(); - for (const auto &Repl : PreTU->Replacements) { - auto &FileRelpsMap = DpctGlobalInfo::getFileRelpsMap(); - FileRelpsMap[Repl.getFilePath().str()].push_back(Repl); - } for (const auto &FileDigest : PreTU->MainSourceFilesDigest) { - auto &MsfInfoMap = DpctGlobalInfo::getMsfInfoMap(); - MsfInfoMap[FileDigest.MainSourceFile] = FileDigest; - // Mark all the main src files loaded from yaml file are not processed // in current migration. MainSrcFileMap[FileDigest.MainSourceFile] = false; @@ -961,16 +930,12 @@ int saveNewFiles(clang::tooling::RefactoringTool &Tool, CompileCmdsPerTarget[Entry.first] = Entry.second; } - std::vector MainSrcFilesRepls; - std::vector MainSrcFilesInfo; + std::vector AllFilesRepls; if (ReplSYCL.empty()) { // There are no rules applying on the *.cpp files, // dpct just do nothing with them. status = MigrationNoCodeChangeHappen; - - getMainSrcFilesRepls(MainSrcFilesRepls); - getMainSrcFilesInfo(MainSrcFilesInfo); } else { std::unordered_map> @@ -984,14 +949,14 @@ int saveNewFiles(clang::tooling::RefactoringTool &Tool, Rewrite.getSourceMgr().getFileManager(), ReplSYCL); if (auto RewriteStatus = writeReplacementsToFiles( ReplSYCL, Rewrite, OutRoot.getCanonicalPath().str(), InRoot, - MainSrcFilesInfo, MainSrcFileMap, MainSrcFilesRepls, FileRangesMap, + MainSrcFileMap, AllFilesRepls, FileRangesMap, FileBlockLevelFormatRangesMap, clang::dpct::RT_ForSYCLMigration)) return RewriteStatus; if (DpctGlobalInfo::isCodePinEnabled()) { if (auto RewriteStatus = writeReplacementsToFiles( ReplCUDA, DebugCUDARewrite, CUDAMigratedOutRoot.getCanonicalPath().str(), InRoot, - MainSrcFilesInfo, MainSrcFileMap, MainSrcFilesRepls, + MainSrcFileMap, AllFilesRepls, FileRangesMap, FileBlockLevelFormatRangesMap, clang::dpct::RT_CUDAWithCodePin)) return RewriteStatus; @@ -1171,8 +1136,7 @@ int saveNewFiles(clang::tooling::RefactoringTool &Tool, if (GenBuildScript) { genBuildScript(Tool, InRoot, OutRoot, ScriptFineName); } - saveUpdatedMigrationDataIntoYAML(MainSrcFilesRepls, MainSrcFilesInfo, - YamlFile, SrcFile, MainSrcFileMap); + saveUpdatedMigrationDataIntoYAML(AllFilesRepls, MainSrcFileMap); if (dpct::DpctGlobalInfo::isCodePinEnabled()) { copyFileToOutRoot(InRoot, CUDAMigratedOutRoot, "MAKEFILE"); copyFileToOutRoot(InRoot, CUDAMigratedOutRoot, "CMAKELISTS.TXT"); @@ -1198,26 +1162,15 @@ int saveNewFiles(clang::tooling::RefactoringTool &Tool, return status; } -void loadYAMLIntoFileInfo(clang::tooling::UnifiedPath Path) { - clang::tooling::UnifiedPath OriginPath = Path; - rewriteFileName(Path); - if (!rewriteCanonicalDir(Path, DpctGlobalInfo::getInRoot(), - DpctGlobalInfo::getOutRoot())) { - return; - } - - clang::tooling::UnifiedPath YamlFilePath = Path.getCanonicalPath() + ".yaml"; - auto PreTU = std::make_shared(); - if (fs::exists(YamlFilePath.getCanonicalPath())) { - if (clang::dpct::DpctGlobalInfo::isIncMigration()) { - if (loadFromYaml(YamlFilePath, *PreTU) == 0) { - DpctGlobalInfo::getInstance().insertReplInfoFromYAMLToFileInfo( - OriginPath, std::move(PreTU)); - } else { - llvm::errs() << getLoadYamlFailWarning(YamlFilePath); - } +void addReplFromYAMLIntoFileInfo(clang::tooling::UnifiedPath Path) { + std::vector Vec; + for (const auto &Entry : + DpctGlobalInfo::getMainSourceYamlTUR()->Replacements) { + if (clang::tooling::UnifiedPath(Entry.getFilePath()) == Path) { + Vec.push_back(Entry); } } + DpctGlobalInfo::getInstance().insertReplVecFromYAMLToFileInfo(Path, Vec); } } // namespace dpct diff --git a/clang/lib/DPCT/FileGenerator/GenFiles.h b/clang/lib/DPCT/FileGenerator/GenFiles.h index 92b95f580e06..828d5c439aa8 100644 --- a/clang/lib/DPCT/FileGenerator/GenFiles.h +++ b/clang/lib/DPCT/FileGenerator/GenFiles.h @@ -38,7 +38,7 @@ int saveNewFiles(clang::tooling::RefactoringTool &Tool, clang::tooling::UnifiedPath CUDAMigratedOutRoot, ReplTy &ReplCUDA, ReplTy &ReplSYCL); -void loadYAMLIntoFileInfo(clang::tooling::UnifiedPath Path); +void addReplFromYAMLIntoFileInfo(clang::tooling::UnifiedPath Path); // clang::tooling::UnifiedPath: source file name including path. // bool: false: the source file has no replacement. diff --git a/clang/lib/DPCT/IncMigration/ExternalReplacement.cpp b/clang/lib/DPCT/IncMigration/ExternalReplacement.cpp index 6ee889b28bad..e10e6f468d62 100644 --- a/clang/lib/DPCT/IncMigration/ExternalReplacement.cpp +++ b/clang/lib/DPCT/IncMigration/ExternalReplacement.cpp @@ -38,10 +38,7 @@ using clang::tooling::Replacements; namespace clang { namespace dpct { int save2Yaml( - clang::tooling::UnifiedPath &YamlFile, - clang::tooling::UnifiedPath &SrcFileName, const std::vector &Replaces, - const std::vector &MainSrcFilesDigest, const std::map> &CompileTargets) { @@ -51,11 +48,13 @@ int save2Yaml( // list all the replacement. clang::tooling::TranslationUnitReplacements TUR; - TUR.MainSourceFile = SrcFileName.getCanonicalPath(); + TUR.MainSourceFile = DpctGlobalInfo::getInRoot().getCanonicalPath().str() + + "/MainSrcFiles_placeholder"; TUR.Replacements.insert(TUR.Replacements.end(), Replaces.begin(), Replaces.end()); - TUR.MainSourceFilesDigest = MainSrcFilesDigest; + TUR.MainSourceFilesDigest = DpctGlobalInfo::getMainSourceYamlTUR() + ->MainSourceFilesDigest; for (const auto &Entry : CompileTargets) { TUR.CompileTargets[Entry.first.getCanonicalPath().str()] = Entry.second; @@ -71,7 +70,10 @@ int save2Yaml( YAMLOut << TUR; YamlContentStream.flush(); - clang::dpct::writeDataToFile(YamlFile.getCanonicalPath().str(), YamlContent); + clang::dpct::writeDataToFile( + DpctGlobalInfo::getOutRoot().getCanonicalPath().str() + + "/MainSourceFiles.yaml", + YamlContent); return 0; } @@ -139,37 +141,5 @@ void mergeAndUniqueReps( } } } - -int mergeExternalReps(clang::tooling::UnifiedPath InRootSrcFilePath, - clang::tooling::UnifiedPath OutRootSrcFilePath, - Replacements &Replaces) { - clang::tooling::UnifiedPath YamlFile = - OutRootSrcFilePath.getCanonicalPath() + ".yaml"; - - auto PreTU = - clang::dpct::DpctGlobalInfo::getInstance() - .getReplInfoFromYAMLSavedInFileInfo(std::move(InRootSrcFilePath)); - - if (PreTU) { - llvm::errs() << YamlFile << " exist, try to merge it.\n"; - - mergeAndUniqueReps(Replaces, (*PreTU).Replacements); - } - - llvm::errs() << "Saved new version of " << YamlFile << " file\n"; - - std::vector Repls(Replaces.begin(), - Replaces.end()); - - // For header file, its hash content digest and HasCUDASytax field is not - // registed. - std::vector MsfInfo(1); - - std::map> - CompileTargets; - save2Yaml(YamlFile, OutRootSrcFilePath, Repls, MsfInfo, CompileTargets); - return 0; -} } // namespace dpct -} // namespace clang \ No newline at end of file +} // namespace clang diff --git a/clang/lib/DPCT/IncMigration/ExternalReplacement.h b/clang/lib/DPCT/IncMigration/ExternalReplacement.h index 20e819d16fc1..b672ccfbe8ba 100644 --- a/clang/lib/DPCT/IncMigration/ExternalReplacement.h +++ b/clang/lib/DPCT/IncMigration/ExternalReplacement.h @@ -27,17 +27,10 @@ class Replacements; namespace clang { namespace dpct { - -int mergeExternalReps(clang::tooling::UnifiedPath InRootSrcFilePath, - clang::tooling::UnifiedPath OutRootSrcFilePath, - clang::tooling::Replacements &Replaces); int loadFromYaml(const clang::tooling::UnifiedPath &Input, clang::tooling::TranslationUnitReplacements &TU); int save2Yaml( - clang::tooling::UnifiedPath &YamlFile, - clang::tooling::UnifiedPath &SrcFileName, const std::vector &Replaces, - const std::vector &MainSrcFilesDigest, const std::map> &CompileTargets); diff --git a/clang/lib/DPCT/IncMigration/IncrementalMigrationUtility.cpp b/clang/lib/DPCT/IncMigration/IncrementalMigrationUtility.cpp index 3f578a4f284a..bc1bb126ffbc 100644 --- a/clang/lib/DPCT/IncMigration/IncrementalMigrationUtility.cpp +++ b/clang/lib/DPCT/IncMigration/IncrementalMigrationUtility.cpp @@ -368,23 +368,14 @@ bool printOptions( // return true: dpct do migration continually // return false: dpct should exit bool canContinueMigration(std::string &Msg) { - auto PreTU = std::make_shared(); - // Try to load the MainSourceFiles.yaml file - SmallString<128> YamlFilePathStr(DpctGlobalInfo::getOutRoot().getCanonicalPath()); - llvm::sys::path::append(YamlFilePathStr, "MainSourceFiles.yaml"); - clang::tooling::UnifiedPath YamlFilePath = YamlFilePathStr; - - if (!llvm::sys::fs::exists(YamlFilePath.getCanonicalPath())) - return true; - if (loadFromYaml(YamlFilePath.getCanonicalPath(), *PreTU) != 0) { - llvm::errs() << getLoadYamlFailWarning(YamlFilePath.getCanonicalPath()); + auto PreTU = DpctGlobalInfo::getMainSourceYamlTUR(); + if (!PreTU) return true; - } // check version auto VerCompRes = compareToolVersion(PreTU->DpctVersion); if (VerCompRes == VersionCmpResult::VCR_CMP_FAILED) { - llvm::errs() << getLoadYamlFailWarning(YamlFilePath.getCanonicalPath()); + llvm::errs() << getLoadYamlFailWarning(); return true; } if (VerCompRes == VersionCmpResult::VCR_CURRENT_IS_NEWER || @@ -397,7 +388,7 @@ bool canContinueMigration(std::string &Msg) { int Res = checkDpctOptionSet(DpctGlobalInfo::getCurrentOptMap(), PreTU->OptionMap); if (Res == -2) { - llvm::errs() << getLoadYamlFailWarning(YamlFilePath.getCanonicalPath()); + llvm::errs() << getLoadYamlFailWarning(); return true; } @@ -406,13 +397,11 @@ bool canContinueMigration(std::string &Msg) { bool Ret = printOptions(PreTU->OptionMap, Msg); if (!Ret) { // parsing error, skip yaml - llvm::errs() << getLoadYamlFailWarning(YamlFilePath.getCanonicalPath()); + llvm::errs() << getLoadYamlFailWarning(); return true; } return false; } - - DpctGlobalInfo::setMainSourceYamlTUR(PreTU); return true; } diff --git a/clang/lib/DPCT/PreProcessor.cpp b/clang/lib/DPCT/PreProcessor.cpp index e20c5c0dc284..1da63df48eb5 100644 --- a/clang/lib/DPCT/PreProcessor.cpp +++ b/clang/lib/DPCT/PreProcessor.cpp @@ -837,7 +837,7 @@ void IncludesCallbacks::FileChanged(SourceLocation Loc, FileChangeReason Reason, } IsFileInCmd = false; - loadYAMLIntoFileInfo(InFile.getCanonicalPath()); + addReplFromYAMLIntoFileInfo(InFile.getCanonicalPath()); } } diff --git a/clang/lib/DPCT/RulesLang/RulesLangNoneAPIAndType.cpp b/clang/lib/DPCT/RulesLang/RulesLangNoneAPIAndType.cpp index 01cb30192c66..29dbf8978cdb 100644 --- a/clang/lib/DPCT/RulesLang/RulesLangNoneAPIAndType.cpp +++ b/clang/lib/DPCT/RulesLang/RulesLangNoneAPIAndType.cpp @@ -490,8 +490,8 @@ bool ConstantMemVarMigrationRule::currentIsDevice( } // 2. if no info found, check info from yaml - if (FileInfo->PreviousTUReplFromYAML) { - auto &ReplsFromYAML = FileInfo->getReplacements(); + if (FileInfo->PreviousReplVecFromYAML) { + auto &ReplsFromYAML = FileInfo->PreviousReplVecFromYAML.value(); for (auto &R : ReplsFromYAML) { if (R.getConstantFlag() == dpct::ConstantFlagType::Host && R.getConstantOffset() == TM->getConstantOffset()) { @@ -616,8 +616,8 @@ bool ConstantMemVarMigrationRule::currentIsHost(const VarDecl *VD, } // 2. if no info found, check info from yaml - if (FileInfo->PreviousTUReplFromYAML) { - auto &ReplsFromYAML = FileInfo->getReplacements(); + if (FileInfo->PreviousReplVecFromYAML) { + auto &ReplsFromYAML = FileInfo->PreviousReplVecFromYAML.value(); for (auto &R : ReplsFromYAML) { if (R.getConstantFlag() == dpct::ConstantFlagType::Device && R.getConstantOffset() == TM->getConstantOffset()) { From 1d16c32a6f947df71621003b947401aee10fbb4a Mon Sep 17 00:00:00 2001 From: "Jiang, Zhiwei" Date: Mon, 30 Jun 2025 09:20:51 +0800 Subject: [PATCH 2/7] fix 1 lit case Signed-off-by: Jiang, Zhiwei --- .../dpct/change_file_in_incrementa_migration/output_ref1.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clang/test/dpct/change_file_in_incrementa_migration/output_ref1.txt b/clang/test/dpct/change_file_in_incrementa_migration/output_ref1.txt index d42b0085c898..ce4867d476ad 100644 --- a/clang/test/dpct/change_file_in_incrementa_migration/output_ref1.txt +++ b/clang/test/dpct/change_file_in_incrementa_migration/output_ref1.txt @@ -1,2 +1,2 @@ // CHECK: Warning: The file '{{(.+)}}test.cu' has been changed during incremental migration. -// CHECK: Warning: Failed to load {{(.+)}}.yaml. Migration continues with incremental migration disabled. See https://www.intel.com/content/www/us/en/docs/dpcpp-compatibility-tool/developer-guide-reference/current/overview.html for more details. \ No newline at end of file +// CHECK: Warning: Migration continues with incremental migration disabled. See https://www.intel.com/content/www/us/en/docs/dpcpp-compatibility-tool/developer-guide-reference/current/overview.html for more details. \ No newline at end of file From 5d478c4b5ff2f042202e997c04e19420a98d1560 Mon Sep 17 00:00:00 2001 From: "Jiang, Zhiwei" Date: Mon, 30 Jun 2025 14:20:45 +0800 Subject: [PATCH 3/7] Fix lit Signed-off-by: Jiang, Zhiwei --- clang/lib/DPCT/AnalysisInfo.cpp | 3 +- clang/lib/DPCT/DPCT.cpp | 69 ++++++++++--------- clang/lib/DPCT/FileGenerator/GenFiles.cpp | 12 ++++ .../IncrementalMigrationUtility.cpp | 39 ++--------- .../IncrementalMigrationUtility.h | 1 - clang/test/dpct/a_test_yaml.h | 3 - .../codepin/valid/vectorAdd_build_in_type.cu | 6 +- .../dpct/parse_yaml_warning/output_ref.txt | 2 +- clang/test/dpct/test_yaml.cu | 11 --- 9 files changed, 57 insertions(+), 89 deletions(-) delete mode 100644 clang/test/dpct/a_test_yaml.h delete mode 100644 clang/test/dpct/test_yaml.cu diff --git a/clang/lib/DPCT/AnalysisInfo.cpp b/clang/lib/DPCT/AnalysisInfo.cpp index 5acbc1bff8be..89fc7d8f2a50 100644 --- a/clang/lib/DPCT/AnalysisInfo.cpp +++ b/clang/lib/DPCT/AnalysisInfo.cpp @@ -2408,8 +2408,7 @@ void DpctGlobalInfo::recordTokenSplit(SourceLocation SL, unsigned Len) { /// MainSourceFiles.yaml file. This variable is valid after /// canContinueMigration() is called. std::shared_ptr - DpctGlobalInfo::MainSourceYamlTUR = - std::make_shared(); + DpctGlobalInfo::MainSourceYamlTUR = nullptr; clang::tooling::UnifiedPath DpctGlobalInfo::InRoot; clang::tooling::UnifiedPath DpctGlobalInfo::OutRoot; std::vector DpctGlobalInfo::AnalysisScope; diff --git a/clang/lib/DPCT/DPCT.cpp b/clang/lib/DPCT/DPCT.cpp index 6a674b923573..7b71c1453bf1 100644 --- a/clang/lib/DPCT/DPCT.cpp +++ b/clang/lib/DPCT/DPCT.cpp @@ -468,11 +468,6 @@ void updateCompatibilityVersionInfo(clang::tooling::UnifiedPath OutRoot, const std::string CmakeHelpFile = appendPath(OutRoot.getCanonicalPath().str(), "dpct.cmake"); std::ifstream InFile(CmakeHelpFile); - if (!InFile) { - std::string ErrMsg = "Failed to open file: " + CmakeHelpFile; - ShowStatus(MigrationErrorReadWriteCMakeHelperFile, std::move(ErrMsg)); - dpctExit(MigrationErrorReadWriteCMakeHelperFile); - } const std::string VersionStr = Major + "." + Minor; const int CompatibilityValue = std::stoi(Major) * 10 + std::stoi(Minor); @@ -517,39 +512,31 @@ void updateCompatibilityVersionInfo(clang::tooling::UnifiedPath OutRoot, } static void loadMainSrcFileInfo(clang::tooling::UnifiedPath YamlFilePath) { - auto PreTU = std::make_shared(); if (llvm::sys::fs::exists(YamlFilePath.getCanonicalPath())) { + auto PreTU = + std::make_shared(); if (loadFromYaml(YamlFilePath, *PreTU) != 0) { llvm::errs() << getLoadYamlFailWarning(); } DpctGlobalInfo::setMainSourceYamlTUR(PreTU); - if (MigrateBuildScriptOnly && !DpctGlobalInfo::migratePythonScripts() || - DpctGlobalInfo::migrateCMakeScripts()) { - std::string Major = PreTU->SDKVersionMajor; - std::string Minor = PreTU->SDKVersionMinor; - if (!Major.empty() && !Minor.empty()) { - updateCompatibilityVersionInfo(OutRoot, Major, Minor); - } + for (auto &Entry : PreTU->MainSourceFilesDigest) { + if (Entry.HasCUDASyntax) + MainSrcFilesHasCudaSyntex.insert(Entry.MainSourceFile); } - } - - for (auto &Entry : PreTU->MainSourceFilesDigest) { - if (Entry.HasCUDASyntax) - MainSrcFilesHasCudaSyntex.insert(Entry.MainSourceFile); - } - // Currently, when "--use-experimental-features=device_global" and - // "--use-experimental-features=all" are specified, the migrated code should - // be compiled with C++20 or later. - auto Iter = PreTU->OptionMap.find("ExperimentalFlag"); - if (Iter != PreTU->OptionMap.end()) { - if (Iter->second.Specified) { - const std::string Value = Iter->second.Value; - unsigned int UValue = std::stoul(Value); - if (UValue & (1 << static_cast( - ExperimentalFeatures::Exp_DeviceGlobal))) { - LANG_Cplusplus_20_Used = true; + // Currently, when "--use-experimental-features=device_global" and + // "--use-experimental-features=all" are specified, the migrated code should + // be compiled with C++20 or later. + auto Iter = PreTU->OptionMap.find("ExperimentalFlag"); + if (Iter != PreTU->OptionMap.end()) { + if (Iter->second.Specified) { + const std::string Value = Iter->second.Value; + unsigned int UValue = std::stoul(Value); + if (UValue & (1 << static_cast( + ExperimentalFeatures::Exp_DeviceGlobal))) { + LANG_Cplusplus_20_Used = true; + } } } } @@ -634,6 +621,12 @@ void showReportHeader() { } void checkIncMigrationOrExit() { + auto PreTU = DpctGlobalInfo::getMainSourceYamlTUR(); + if (!PreTU) { + PreTU = std::make_shared(); + DpctGlobalInfo::setMainSourceYamlTUR(PreTU); + return; + } if (!MigrateBuildScriptOnly && clang::dpct::DpctGlobalInfo::isIncMigration()) { std::string Msg; @@ -816,7 +809,7 @@ int runDPCT(int argc, const char **argv) { CudaIncludePath = CudaInclude; SDKPath = SDKPathOpt; - loadMainSrcFileInfo(OutRootPath.getCanonicalPath() + "/MainSourceFiles.yaml"); + loadMainSrcFileInfo(OutRootPath.getCanonicalPath() + "/MainSourceFiles.yaml"); //1 std::transform( RuleFile.begin(), RuleFile.end(), @@ -1342,8 +1335,6 @@ int runDPCT(int argc, const char **argv) { UseDPCPPExtensions.getNumOccurrences()); setValueToOptMap(clang::dpct::OPTION_NoDRYPattern, NoDRYPattern.getValue(), NoDRYPattern.getNumOccurrences()); - setValueToOptMap(clang::dpct::OPTION_CompilationsDir, CompilationsDir, - OptParser->isPSpecified()); #ifdef _WIN32 if (!VcxprojFilePath.getPath().empty()) { setValueToOptMap(clang::dpct::OPTION_VcxprojFile, @@ -1387,7 +1378,7 @@ int runDPCT(int argc, const char **argv) { setValueToOptMap(clang::dpct::OPTION_UseSYCLCompat, UseSYCLCompat.getValue(), UseSYCLCompat.getNumOccurrences()); - checkIncMigrationOrExit(); + checkIncMigrationOrExit(); //2 } if (DpctGlobalInfo::getFormatRange() != clang::format::FormatRange::none) { @@ -1395,6 +1386,16 @@ int runDPCT(int argc, const char **argv) { } // OC_Action: only migrate Build scripts. if (MigrateBuildScriptOnly) { + if (!DpctGlobalInfo::migratePythonScripts() || + DpctGlobalInfo::migrateCMakeScripts()) { + std::string Major = + DpctGlobalInfo::getMainSourceYamlTUR()->SDKVersionMajor; + std::string Minor = + DpctGlobalInfo::getMainSourceYamlTUR()->SDKVersionMinor; + if (!Major.empty() && !Minor.empty()) { + updateCompatibilityVersionInfo(OutRoot, Major, Minor); + } + } collectBuildScriptsSpecified(OptParser, InRootPath, OutRootPath); migrateBuildScripts(InRootPath, OutRootPath); diff --git a/clang/lib/DPCT/FileGenerator/GenFiles.cpp b/clang/lib/DPCT/FileGenerator/GenFiles.cpp index 04c83d480385..4f7f4eb87b6d 100644 --- a/clang/lib/DPCT/FileGenerator/GenFiles.cpp +++ b/clang/lib/DPCT/FileGenerator/GenFiles.cpp @@ -463,6 +463,18 @@ updateMainSrcFilesInfo(const clang::tooling::MainSourceFileInfo &Info) { static void saveUpdatedMigrationDataIntoYAML( std::vector &AllFilesRepls, std::unordered_map &MainSrcFileMap) { + // For files which are not in AllFilesRepls but in previous yaml file, we need + // to add them into AllFilesRepls + std::unordered_set CurrentFileSet; + for (const auto &Repl : AllFilesRepls) { + CurrentFileSet.insert(Repl.getFilePath().str()); + } + for (const auto &Repl : + DpctGlobalInfo::getMainSourceYamlTUR()->Replacements) { + if (CurrentFileSet.find(Repl.getFilePath().str()) == CurrentFileSet.end()) { + AllFilesRepls.push_back(Repl); + } + } if (!AllFilesRepls.empty() || !CompileCmdsPerTarget.empty()) { save2Yaml(AllFilesRepls, CompileCmdsPerTarget); } diff --git a/clang/lib/DPCT/IncMigration/IncrementalMigrationUtility.cpp b/clang/lib/DPCT/IncMigration/IncrementalMigrationUtility.cpp index bc1bb126ffbc..5e3cb1600b8e 100644 --- a/clang/lib/DPCT/IncMigration/IncrementalMigrationUtility.cpp +++ b/clang/lib/DPCT/IncMigration/IncrementalMigrationUtility.cpp @@ -111,38 +111,10 @@ int checkDpctOptionSet( } else if (CurrentOpt.first == OPTION_AnalysisScopePath) { if (checkListOptions(OPTION_AnalysisScopePath)) return -1; - } -#ifdef _WIN32 - else if (CurrentOpt.first == OPTION_VcxprojFile) { - if (!PreviousOpts.count(OPTION_CompilationsDir)) { - return -2; - } - if ((PreviousOpts.at(OPTION_VcxprojFile).Specified && - !CurrentOpts.at(OPTION_VcxprojFile).Specified) || - (!PreviousOpts.at(OPTION_VcxprojFile).Specified && - CurrentOpts.at(OPTION_VcxprojFile).Specified)) { - if (PreviousOpts.at(OPTION_CompilationsDir).Value != - CurrentOpts.at(OPTION_CompilationsDir).Value) { - return -1; - } - } else { - if (PreviousOpts.at(CurrentOpt.first).Value != - CurrentOpt.second.Value) { - return -1; - } - } - } else { - if (PreviousOpts.at(CurrentOpt.first).Value != - CurrentOpt.second.Value) { - return -1; - } - } -#else - else if (PreviousOpts.at(CurrentOpt.first).Value != - CurrentOpt.second.Value) { + } else if (PreviousOpts.at(CurrentOpt.first).Value != + CurrentOpt.second.Value) { return -1; } -#endif } else { return -2; } @@ -245,8 +217,9 @@ bool printOptions( if ("true" == Value) Opts.emplace_back("--no-dry-pattern"); } - if (Key == clang::dpct::OPTION_CompilationsDir && Specified) { - Opts.emplace_back("--compilation-database=\"" + Value + "\""); + if (Key == clang::dpct::OPTION_CodePinEnabled && Specified) { + if ("true" == Value) + Opts.emplace_back("--enable-codepin"); } #ifdef _WIN32 if (Key == clang::dpct::OPTION_VcxprojFile && Specified) { @@ -369,8 +342,6 @@ bool printOptions( // return false: dpct should exit bool canContinueMigration(std::string &Msg) { auto PreTU = DpctGlobalInfo::getMainSourceYamlTUR(); - if (!PreTU) - return true; // check version auto VerCompRes = compareToolVersion(PreTU->DpctVersion); diff --git a/clang/lib/DPCT/IncMigration/IncrementalMigrationUtility.h b/clang/lib/DPCT/IncMigration/IncrementalMigrationUtility.h index 084771e12f10..0829ea94b441 100644 --- a/clang/lib/DPCT/IncMigration/IncrementalMigrationUtility.h +++ b/clang/lib/DPCT/IncMigration/IncrementalMigrationUtility.h @@ -24,7 +24,6 @@ const std::string OPTION_CodePinEnabled = "CodePinEnabled"; const std::string OPTION_ExtensionDEFlag = "ExtensionDEFlag"; const std::string OPTION_ExtensionDDFlag = "ExtensionDDFlag"; const std::string OPTION_NoDRYPattern = "NoDRYPattern"; -const std::string OPTION_CompilationsDir = "CompilationsDir"; #ifdef _WIN32 const std::string OPTION_VcxprojFile = "VcxprojFile"; #endif diff --git a/clang/test/dpct/a_test_yaml.h b/clang/test/dpct/a_test_yaml.h deleted file mode 100644 index 660426dcc0d2..000000000000 --- a/clang/test/dpct/a_test_yaml.h +++ /dev/null @@ -1,3 +0,0 @@ -// CHECK:#include -// CHECK-NEXT:#include -#include diff --git a/clang/test/dpct/codepin/valid/vectorAdd_build_in_type.cu b/clang/test/dpct/codepin/valid/vectorAdd_build_in_type.cu index 6e4d041cbe29..70a6ef8f2fa5 100644 --- a/clang/test/dpct/codepin/valid/vectorAdd_build_in_type.cu +++ b/clang/test/dpct/codepin/valid/vectorAdd_build_in_type.cu @@ -1,10 +1,10 @@ -// RUN: dpct --format-range=none -out-root %T/vector_add %s --cuda-include-path="%cuda-path/include" -- -std=c++17 -x cuda --cuda-host-only +// RUN: dpct --format-range=none -out-root %T/out %s --cuda-include-path="%cuda-path/include" -- -std=c++17 -x cuda --cuda-host-only // RUN: dpct --format-range=none --enable-codepin -out-root %T/vector_add %s --cuda-include-path="%cuda-path/include" -- -std=c++17 -x cuda --cuda-host-only -// RUN: cat %S/dpct_output_ref/vectorAdd_build_in_type.dp.cpp >> %T/vector_add/vectorAdd_build_in_type.dp.cpp +// RUN: cat %S/dpct_output_ref/vectorAdd_build_in_type.dp.cpp >> %T/out/vectorAdd_build_in_type.dp.cpp // RUN: cat %S/dpct_output_codepin_cuda_ref/vectorAdd_build_in_type.cu >> %T/vector_add_codepin_cuda/vectorAdd_build_in_type.cu // RUN: cat %S/dpct_output_codepin_sycl_ref/vectorAdd_build_in_type.dp.cpp >> %T/vector_add_codepin_sycl/vectorAdd_build_in_type.dp.cpp // RUN: FileCheck --match-full-lines --input-file %T/vector_add_codepin_cuda/vectorAdd_build_in_type.cu %T/vector_add_codepin_cuda/vectorAdd_build_in_type.cu -// RUN: FileCheck --match-full-lines --input-file %T/vector_add/vectorAdd_build_in_type.dp.cpp %T/vector_add/vectorAdd_build_in_type.dp.cpp +// RUN: FileCheck --match-full-lines --input-file %T/out/vectorAdd_build_in_type.dp.cpp %T/out/vectorAdd_build_in_type.dp.cpp // RUN: FileCheck --match-full-lines --input-file %T/vector_add_codepin_sycl/vectorAdd_build_in_type.dp.cpp %T/vector_add_codepin_sycl/vectorAdd_build_in_type.dp.cpp //============================================================== diff --git a/clang/test/dpct/parse_yaml_warning/output_ref.txt b/clang/test/dpct/parse_yaml_warning/output_ref.txt index 16e4fb714901..39cddfd7c9d8 100644 --- a/clang/test/dpct/parse_yaml_warning/output_ref.txt +++ b/clang/test/dpct/parse_yaml_warning/output_ref.txt @@ -1 +1 @@ -// CHECK: Warning: Failed to load {{(.+)}}.yaml. Migration continues with incremental migration disabled. See https://www.intel.com/content/www/us/en/docs/dpcpp-compatibility-tool/developer-guide-reference/current/overview.html for more details. \ No newline at end of file +// CHECK: Warning: Migration continues with incremental migration disabled. See https://www.intel.com/content/www/us/en/docs/dpcpp-compatibility-tool/developer-guide-reference/current/overview.html for more details. \ No newline at end of file diff --git a/clang/test/dpct/test_yaml.cu b/clang/test/dpct/test_yaml.cu deleted file mode 100644 index 1b4531533812..000000000000 --- a/clang/test/dpct/test_yaml.cu +++ /dev/null @@ -1,11 +0,0 @@ -// RUN: cd %T -// RUN: cat %s > test_yaml.cu -// RUN: cat %S/a_test_yaml.h > a_test_yaml.h -// RUN: dpct --out-root=test_yaml_out %s --cuda-include-path="%cuda-path/include" -- -x cuda --cuda-host-only -// RUN: FileCheck --input-file %T/test_yaml_out/a_test_yaml.h.yaml --match-full-lines %s -// RUN: FileCheck --input-file %T/test_yaml_out/a_test_yaml.h --match-full-lines %S/a_test_yaml.h -// RUN: rm -rf ./test_yaml_out - -// CHECK: --- -#include "a_test_yaml.h" - From 3168fb7332ecfdb7b4f5df6aeeaa0cac7e175620 Mon Sep 17 00:00:00 2001 From: "Jiang, Zhiwei" Date: Mon, 30 Jun 2025 14:22:29 +0800 Subject: [PATCH 4/7] Update Signed-off-by: Jiang, Zhiwei --- clang/lib/DPCT/DPCT.cpp | 4 ++-- clang/lib/DPCT/FileGenerator/GenFiles.cpp | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/clang/lib/DPCT/DPCT.cpp b/clang/lib/DPCT/DPCT.cpp index 7b71c1453bf1..840d565326df 100644 --- a/clang/lib/DPCT/DPCT.cpp +++ b/clang/lib/DPCT/DPCT.cpp @@ -809,7 +809,7 @@ int runDPCT(int argc, const char **argv) { CudaIncludePath = CudaInclude; SDKPath = SDKPathOpt; - loadMainSrcFileInfo(OutRootPath.getCanonicalPath() + "/MainSourceFiles.yaml"); //1 + loadMainSrcFileInfo(OutRootPath.getCanonicalPath() + "/MainSourceFiles.yaml"); std::transform( RuleFile.begin(), RuleFile.end(), @@ -1378,7 +1378,7 @@ int runDPCT(int argc, const char **argv) { setValueToOptMap(clang::dpct::OPTION_UseSYCLCompat, UseSYCLCompat.getValue(), UseSYCLCompat.getNumOccurrences()); - checkIncMigrationOrExit(); //2 + checkIncMigrationOrExit(); } if (DpctGlobalInfo::getFormatRange() != clang::format::FormatRange::none) { diff --git a/clang/lib/DPCT/FileGenerator/GenFiles.cpp b/clang/lib/DPCT/FileGenerator/GenFiles.cpp index 4f7f4eb87b6d..22d2e58dec12 100644 --- a/clang/lib/DPCT/FileGenerator/GenFiles.cpp +++ b/clang/lib/DPCT/FileGenerator/GenFiles.cpp @@ -628,7 +628,7 @@ int writeReplacementsToFiles( *Result, clang::SrcMgr::C_User /*normal user code*/)) .write(OutStream); } else { - ///// !!!!!!!!!!!!!!!!!!! If we use remigration, we need to disable pattern rewriter. + // TODO: If we use remigration, we need to disable pattern rewriter. std::string OutputString; llvm::raw_string_ostream RSW(OutputString); Rewrite From 337f9d4bd6e1de585597dde6edbfa7af3687d89b Mon Sep 17 00:00:00 2001 From: "Jiang, Zhiwei" Date: Tue, 1 Jul 2025 10:43:10 +0800 Subject: [PATCH 5/7] Update Signed-off-by: Jiang, Zhiwei --- clang/lib/DPCT/DPCT.cpp | 11 ----------- .../DPCT/IncMigration/IncrementalMigrationUtility.cpp | 5 ----- .../DPCT/IncMigration/IncrementalMigrationUtility.h | 3 --- 3 files changed, 19 deletions(-) diff --git a/clang/lib/DPCT/DPCT.cpp b/clang/lib/DPCT/DPCT.cpp index 840d565326df..965058eb9e73 100644 --- a/clang/lib/DPCT/DPCT.cpp +++ b/clang/lib/DPCT/DPCT.cpp @@ -1335,17 +1335,6 @@ int runDPCT(int argc, const char **argv) { UseDPCPPExtensions.getNumOccurrences()); setValueToOptMap(clang::dpct::OPTION_NoDRYPattern, NoDRYPattern.getValue(), NoDRYPattern.getNumOccurrences()); -#ifdef _WIN32 - if (!VcxprojFilePath.getPath().empty()) { - setValueToOptMap(clang::dpct::OPTION_VcxprojFile, - VcxprojFilePath.getCanonicalPath().str(), - OptParser->isVcxprojfileSpecified()); - } else { - setValueToOptMap(clang::dpct::OPTION_VcxprojFile, - VcxprojFilePath.getPath().str(), - OptParser->isVcxprojfileSpecified()); - } -#endif setValueToOptMap(clang::dpct::OPTION_ProcessAll, ProcessAll.getValue(), ProcessAll.getNumOccurrences()); setValueToOptMap(clang::dpct::OPTION_SyclNamedLambda, SyclNamedLambda.getValue(), diff --git a/clang/lib/DPCT/IncMigration/IncrementalMigrationUtility.cpp b/clang/lib/DPCT/IncMigration/IncrementalMigrationUtility.cpp index 5e3cb1600b8e..469c4529affb 100644 --- a/clang/lib/DPCT/IncMigration/IncrementalMigrationUtility.cpp +++ b/clang/lib/DPCT/IncMigration/IncrementalMigrationUtility.cpp @@ -221,11 +221,6 @@ bool printOptions( if ("true" == Value) Opts.emplace_back("--enable-codepin"); } -#ifdef _WIN32 - if (Key == clang::dpct::OPTION_VcxprojFile && Specified) { - Opts.emplace_back("--vcxprojfile=\"" + Value + "\""); - } -#endif if (Key == clang::dpct::OPTION_ProcessAll) { if ("true" == Value) Opts.emplace_back("--process-all"); diff --git a/clang/lib/DPCT/IncMigration/IncrementalMigrationUtility.h b/clang/lib/DPCT/IncMigration/IncrementalMigrationUtility.h index 0829ea94b441..3b31c1bf7702 100644 --- a/clang/lib/DPCT/IncMigration/IncrementalMigrationUtility.h +++ b/clang/lib/DPCT/IncMigration/IncrementalMigrationUtility.h @@ -24,9 +24,6 @@ const std::string OPTION_CodePinEnabled = "CodePinEnabled"; const std::string OPTION_ExtensionDEFlag = "ExtensionDEFlag"; const std::string OPTION_ExtensionDDFlag = "ExtensionDDFlag"; const std::string OPTION_NoDRYPattern = "NoDRYPattern"; -#ifdef _WIN32 -const std::string OPTION_VcxprojFile = "VcxprojFile"; -#endif const std::string OPTION_ProcessAll = "ProcessAll"; const std::string OPTION_SyclNamedLambda = "SyclNamedLambda"; const std::string OPTION_ExperimentalFlag = "ExperimentalFlag"; From c86de024865baea807b88b31ca1026d5ffe89c2e Mon Sep 17 00:00:00 2001 From: "Jiang, Zhiwei" Date: Tue, 1 Jul 2025 11:41:32 +0800 Subject: [PATCH 6/7] update Signed-off-by: Jiang, Zhiwei --- clang/lib/DPCT/IncMigration/ExternalReplacement.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/clang/lib/DPCT/IncMigration/ExternalReplacement.cpp b/clang/lib/DPCT/IncMigration/ExternalReplacement.cpp index e10e6f468d62..4d84c58a6169 100644 --- a/clang/lib/DPCT/IncMigration/ExternalReplacement.cpp +++ b/clang/lib/DPCT/IncMigration/ExternalReplacement.cpp @@ -112,6 +112,8 @@ int loadFromYaml(const clang::tooling::UnifiedPath &Input, void mergeAndUniqueReps( Replacements &Replaces, const std::vector &PreRepls) { + if (!DpctGlobalInfo::isIncMigration()) + return; bool DupFlag = false; for (const auto &OldR : PreRepls) { From 2dcfe280688da26b8175eb4d0954181a0f5e8b15 Mon Sep 17 00:00:00 2001 From: "Jiang, Zhiwei" Date: Fri, 4 Jul 2025 10:35:22 +0800 Subject: [PATCH 7/7] Update Signed-off-by: Jiang, Zhiwei --- clang/lib/DPCT/DPCT.cpp | 64 +++++++++++++++++++---------------------- 1 file changed, 30 insertions(+), 34 deletions(-) diff --git a/clang/lib/DPCT/DPCT.cpp b/clang/lib/DPCT/DPCT.cpp index 965058eb9e73..fd1d1b067db7 100644 --- a/clang/lib/DPCT/DPCT.cpp +++ b/clang/lib/DPCT/DPCT.cpp @@ -512,31 +512,30 @@ void updateCompatibilityVersionInfo(clang::tooling::UnifiedPath OutRoot, } static void loadMainSrcFileInfo(clang::tooling::UnifiedPath YamlFilePath) { - if (llvm::sys::fs::exists(YamlFilePath.getCanonicalPath())) { - auto PreTU = - std::make_shared(); - if (loadFromYaml(YamlFilePath, *PreTU) != 0) { - llvm::errs() << getLoadYamlFailWarning(); - } - DpctGlobalInfo::setMainSourceYamlTUR(PreTU); + if (!llvm::sys::fs::exists(YamlFilePath.getCanonicalPath())) + return; + auto PreTU = std::make_shared(); + if (loadFromYaml(YamlFilePath, *PreTU) != 0) { + llvm::errs() << getLoadYamlFailWarning(); + } + DpctGlobalInfo::setMainSourceYamlTUR(PreTU); - for (auto &Entry : PreTU->MainSourceFilesDigest) { - if (Entry.HasCUDASyntax) - MainSrcFilesHasCudaSyntex.insert(Entry.MainSourceFile); - } + for (auto &Entry : PreTU->MainSourceFilesDigest) { + if (Entry.HasCUDASyntax) + MainSrcFilesHasCudaSyntex.insert(Entry.MainSourceFile); + } - // Currently, when "--use-experimental-features=device_global" and - // "--use-experimental-features=all" are specified, the migrated code should - // be compiled with C++20 or later. - auto Iter = PreTU->OptionMap.find("ExperimentalFlag"); - if (Iter != PreTU->OptionMap.end()) { - if (Iter->second.Specified) { - const std::string Value = Iter->second.Value; - unsigned int UValue = std::stoul(Value); - if (UValue & (1 << static_cast( - ExperimentalFeatures::Exp_DeviceGlobal))) { - LANG_Cplusplus_20_Used = true; - } + // Currently, when "--use-experimental-features=device_global" and + // "--use-experimental-features=all" are specified, the migrated code should + // be compiled with C++20 or later. + auto Iter = PreTU->OptionMap.find("ExperimentalFlag"); + if (Iter != PreTU->OptionMap.end()) { + if (Iter->second.Specified) { + const std::string Value = Iter->second.Value; + unsigned int UValue = std::stoul(Value); + if (UValue & (1 << static_cast( + ExperimentalFeatures::Exp_DeviceGlobal))) { + LANG_Cplusplus_20_Used = true; } } } @@ -1374,20 +1373,17 @@ int runDPCT(int argc, const char **argv) { parseFormatStyle(); } // OC_Action: only migrate Build scripts. - if (MigrateBuildScriptOnly) { - if (!DpctGlobalInfo::migratePythonScripts() || - DpctGlobalInfo::migrateCMakeScripts()) { - std::string Major = - DpctGlobalInfo::getMainSourceYamlTUR()->SDKVersionMajor; - std::string Minor = - DpctGlobalInfo::getMainSourceYamlTUR()->SDKVersionMinor; - if (!Major.empty() && !Minor.empty()) { - updateCompatibilityVersionInfo(OutRoot, Major, Minor); - } + if (MigrateBuildScriptOnly && !DpctGlobalInfo::migratePythonScripts() || + DpctGlobalInfo::migrateCMakeScripts()) { + std::string Major = DpctGlobalInfo::getMainSourceYamlTUR()->SDKVersionMajor; + std::string Minor = DpctGlobalInfo::getMainSourceYamlTUR()->SDKVersionMinor; + if (!Major.empty() && !Minor.empty()) { + updateCompatibilityVersionInfo(OutRoot, Major, Minor); } + } + if (MigrateBuildScriptOnly) { collectBuildScriptsSpecified(OptParser, InRootPath, OutRootPath); migrateBuildScripts(InRootPath, OutRootPath); - ShowStatus(MigrationBuildScriptCompleted); dpctExit(MigrationSucceeded, false); }