Skip to content

Commit 5e10875

Browse files
authored
[SYCLomatic] Merge all YAML files into the MainSourceFiles.yaml (#2921)
Signed-off-by: Jiang, Zhiwei <zhiwei.jiang@intel.com>
1 parent cc5c93a commit 5e10875

File tree

18 files changed

+142
-318
lines changed

18 files changed

+142
-318
lines changed

clang/lib/DPCT/AnalysisInfo.cpp

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2101,21 +2101,20 @@ std::shared_ptr<CudaMallocInfo> DpctGlobalInfo::findCudaMalloc(const Expr *E) {
21012101
return findCudaMallocInfo(Src);
21022102
return std::shared_ptr<CudaMallocInfo>();
21032103
}
2104-
void DpctGlobalInfo::insertReplInfoFromYAMLToFileInfo(
2104+
void DpctGlobalInfo::insertReplVecFromYAMLToFileInfo(
21052105
const clang::tooling::UnifiedPath &FilePath,
2106-
std::shared_ptr<tooling::TranslationUnitReplacements> TUR) {
2106+
std::vector<tooling::Replacement> Vec) {
21072107
auto FileInfo = insertFile(FilePath);
2108-
if (FileInfo->PreviousTUReplFromYAML == nullptr)
2109-
FileInfo->PreviousTUReplFromYAML = TUR;
2108+
FileInfo->PreviousReplVecFromYAML = Vec;
21102109
}
2111-
std::shared_ptr<tooling::TranslationUnitReplacements>
2112-
DpctGlobalInfo::getReplInfoFromYAMLSavedInFileInfo(
2110+
std::optional<std::vector<tooling::Replacement>>
2111+
DpctGlobalInfo::getReplVecFromYAMLSavedInFileInfo(
21132112
clang::tooling::UnifiedPath FilePath) {
21142113
auto FileInfo = findObject(FileMap, FilePath);
21152114
if (FileInfo)
2116-
return FileInfo->PreviousTUReplFromYAML;
2115+
return FileInfo->PreviousReplVecFromYAML;
21172116
else
2118-
return nullptr;
2117+
return std::nullopt;
21192118
}
21202119
void DpctGlobalInfo::insertEventSyncTypeInfo(
21212120
const std::shared_ptr<clang::dpct::ExtReplacement> Repl, bool NeedReport,
@@ -2311,8 +2310,6 @@ void DpctGlobalInfo::resetInfo() {
23112310
FunctionCallInMacroMigrateRecord.clear();
23122311
EndOfEmptyMacros.clear();
23132312
BeginOfEmptyMacros.clear();
2314-
FileRelpsMap.clear();
2315-
MsfInfoMap.clear();
23162313
MacroDefines.clear();
23172314
CAPPInfoMap.clear();
23182315
CurrentMaxIndex = 0;
@@ -2414,8 +2411,7 @@ void DpctGlobalInfo::recordTokenSplit(SourceLocation SL, unsigned Len) {
24142411
/// MainSourceFiles.yaml file. This variable is valid after
24152412
/// canContinueMigration() is called.
24162413
std::shared_ptr<clang::tooling::TranslationUnitReplacements>
2417-
DpctGlobalInfo::MainSourceYamlTUR =
2418-
std::make_shared<clang::tooling::TranslationUnitReplacements>();
2414+
DpctGlobalInfo::MainSourceYamlTUR = nullptr;
24192415
clang::tooling::UnifiedPath DpctGlobalInfo::InRoot;
24202416
clang::tooling::UnifiedPath DpctGlobalInfo::OutRoot;
24212417
std::vector<clang::tooling::UnifiedPath> DpctGlobalInfo::AnalysisScope;
@@ -2473,11 +2469,6 @@ std::map<std::string, std::string>
24732469
DpctGlobalInfo::FunctionCallInMacroMigrateRecord;
24742470
std::map<std::string, SourceLocation> DpctGlobalInfo::EndOfEmptyMacros;
24752471
std::map<std::string, unsigned int> DpctGlobalInfo::BeginOfEmptyMacros;
2476-
std::unordered_map<std::string, std::vector<clang::tooling::Replacement>>
2477-
DpctGlobalInfo::FileRelpsMap;
2478-
std::unordered_map<std::string, clang::tooling::MainSourceFileInfo>
2479-
DpctGlobalInfo::MsfInfoMap;
2480-
const std::string DpctGlobalInfo::YamlFileName = "MainSourceFiles.yaml";
24812472
std::map<std::string, bool> DpctGlobalInfo::MacroDefines;
24822473
int DpctGlobalInfo::CurrentMaxIndex = 0;
24832474
int DpctGlobalInfo::CurrentIndexInRule = 0;

clang/lib/DPCT/AnalysisInfo.h

Lines changed: 7 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -507,9 +507,6 @@ class DpctFileInfo {
507507
getConstantMacroTMSet() {
508508
return ConstantMacroTMSet;
509509
}
510-
std::vector<tooling::Replacement> &getReplacements() {
511-
return PreviousTUReplFromYAML->Replacements;
512-
}
513510
std::unordered_map<std::string, std::tuple<unsigned int, std::string, bool>> &
514511
getAtomicMap() {
515512
return AtomicMap;
@@ -534,8 +531,8 @@ class DpctFileInfo {
534531
void setCCLVerValue(std::string Value) { CCLVerValue = Value; }
535532
std::string getCCLVerValue() { return CCLVerValue; }
536533

537-
std::shared_ptr<tooling::TranslationUnitReplacements> PreviousTUReplFromYAML =
538-
nullptr;
534+
std::optional<std::vector<tooling::Replacement>> PreviousReplVecFromYAML =
535+
std::nullopt;
539536

540537
private:
541538
std::vector<std::pair<unsigned int, unsigned int>> TimeStubBounds;
@@ -1178,11 +1175,11 @@ class DpctGlobalInfo {
11781175
return CudaArchMacroRepl;
11791176
}
11801177
CudaArchDefMap &getCudaArchDefinedMap() { return CudaArchDefinedMap; }
1181-
void insertReplInfoFromYAMLToFileInfo(
1182-
const clang::tooling::UnifiedPath &FilePath,
1183-
std::shared_ptr<tooling::TranslationUnitReplacements> TUR);
1184-
std::shared_ptr<tooling::TranslationUnitReplacements>
1185-
getReplInfoFromYAMLSavedInFileInfo(clang::tooling::UnifiedPath FilePath);
1178+
void
1179+
insertReplVecFromYAMLToFileInfo(const clang::tooling::UnifiedPath &FilePath,
1180+
std::vector<tooling::Replacement> Vec);
1181+
std::optional<std::vector<tooling::Replacement>>
1182+
getReplVecFromYAMLSavedInFileInfo(clang::tooling::UnifiedPath FilePath);
11861183
void insertEventSyncTypeInfo(
11871184
const std::shared_ptr<clang::dpct::ExtReplacement> Repl,
11881185
bool NeedReport = false, bool IsAssigned = false);
@@ -1257,16 +1254,6 @@ class DpctGlobalInfo {
12571254
static std::set<std::string> &getFileSetInCompilationDB() {
12581255
return FileSetInCompilationDB;
12591256
}
1260-
static std::unordered_map<std::string,
1261-
std::vector<clang::tooling::Replacement>> &
1262-
getFileRelpsMap() {
1263-
return FileRelpsMap;
1264-
}
1265-
static std::unordered_map<std::string, clang::tooling::MainSourceFileInfo> &
1266-
getMsfInfoMap() {
1267-
return MsfInfoMap;
1268-
}
1269-
static std::string getYamlFileName() { return YamlFileName; }
12701257
static std::set<std::string> &getGlobalVarNameSet() {
12711258
return GlobalVarNameSet;
12721259
}
@@ -1653,12 +1640,6 @@ class DpctGlobalInfo {
16531640
// key: The hash string of the begin location of the macro expansion
16541641
// value: The end location of the macro expansion
16551642
static std::map<std::string, unsigned int> BeginOfEmptyMacros;
1656-
static std::unordered_map<std::string,
1657-
std::vector<clang::tooling::Replacement>>
1658-
FileRelpsMap;
1659-
static std::unordered_map<std::string, clang::tooling::MainSourceFileInfo>
1660-
MsfInfoMap;
1661-
static const std::string YamlFileName;
16621643
static std::map<std::string, bool> MacroDefines;
16631644
static int CurrentMaxIndex;
16641645
static int CurrentIndexInRule;

clang/lib/DPCT/DPCT.cpp

Lines changed: 23 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -468,11 +468,6 @@ void updateCompatibilityVersionInfo(clang::tooling::UnifiedPath OutRoot,
468468
const std::string CmakeHelpFile =
469469
appendPath(OutRoot.getCanonicalPath().str(), "dpct.cmake");
470470
std::ifstream InFile(CmakeHelpFile);
471-
if (!InFile) {
472-
std::string ErrMsg = "Failed to open file: " + CmakeHelpFile;
473-
ShowStatus(MigrationErrorReadWriteCMakeHelperFile, std::move(ErrMsg));
474-
dpctExit(MigrationErrorReadWriteCMakeHelperFile);
475-
}
476471

477472
const std::string VersionStr = Major + "." + Minor;
478473
const int CompatibilityValue = std::stoi(Major) * 10 + std::stoi(Minor);
@@ -516,24 +511,14 @@ void updateCompatibilityVersionInfo(clang::tooling::UnifiedPath OutRoot,
516511
OutFile.close();
517512
}
518513

519-
static void loadMainSrcFileInfo(clang::tooling::UnifiedPath OutRoot) {
520-
std::string YamlFilePath = appendPath(OutRoot.getCanonicalPath().str(),
521-
DpctGlobalInfo::getYamlFileName());
514+
static void loadMainSrcFileInfo(clang::tooling::UnifiedPath YamlFilePath) {
515+
if (!llvm::sys::fs::exists(YamlFilePath.getCanonicalPath()))
516+
return;
522517
auto PreTU = std::make_shared<clang::tooling::TranslationUnitReplacements>();
523-
if (llvm::sys::fs::exists(YamlFilePath)) {
524-
if (loadFromYaml(YamlFilePath, *PreTU) != 0) {
525-
llvm::errs() << getLoadYamlFailWarning(YamlFilePath);
526-
}
527-
528-
if (MigrateBuildScriptOnly && !DpctGlobalInfo::migratePythonScripts() ||
529-
DpctGlobalInfo::migrateCMakeScripts()) {
530-
std::string Major = PreTU->SDKVersionMajor;
531-
std::string Minor = PreTU->SDKVersionMinor;
532-
if (!Major.empty() && !Minor.empty()) {
533-
updateCompatibilityVersionInfo(OutRoot, Major, Minor);
534-
}
535-
}
518+
if (loadFromYaml(YamlFilePath, *PreTU) != 0) {
519+
llvm::errs() << getLoadYamlFailWarning();
536520
}
521+
DpctGlobalInfo::setMainSourceYamlTUR(PreTU);
537522

538523
for (auto &Entry : PreTU->MainSourceFilesDigest) {
539524
if (Entry.HasCUDASyntax)
@@ -635,6 +620,12 @@ void showReportHeader() {
635620
}
636621

637622
void checkIncMigrationOrExit() {
623+
auto PreTU = DpctGlobalInfo::getMainSourceYamlTUR();
624+
if (!PreTU) {
625+
PreTU = std::make_shared<clang::tooling::TranslationUnitReplacements>();
626+
DpctGlobalInfo::setMainSourceYamlTUR(PreTU);
627+
return;
628+
}
638629
if (!MigrateBuildScriptOnly &&
639630
clang::dpct::DpctGlobalInfo::isIncMigration()) {
640631
std::string Msg;
@@ -679,7 +670,6 @@ int migrateBuildScripts(const clang::tooling::UnifiedPath &InRoot,
679670
}
680671

681672
void doBuildScriptMigration() {
682-
loadMainSrcFileInfo(OutRootPath);
683673
collectBuildScripts(InRootPath, OutRootPath);
684674
migrateBuildScripts(InRootPath, OutRootPath);
685675
}
@@ -817,6 +807,9 @@ int runDPCT(int argc, const char **argv) {
817807
std::string OutRootPathCUDACodepin = "";
818808
CudaIncludePath = CudaInclude;
819809
SDKPath = SDKPathOpt;
810+
811+
loadMainSrcFileInfo(OutRootPath.getCanonicalPath() + "/MainSourceFiles.yaml");
812+
820813
std::transform(
821814
RuleFile.begin(), RuleFile.end(),
822815
std::back_insert_iterator<std::vector<clang::tooling::UnifiedPath>>(
@@ -1343,19 +1336,6 @@ int runDPCT(int argc, const char **argv) {
13431336
UseDPCPPExtensions.getNumOccurrences());
13441337
setValueToOptMap(clang::dpct::OPTION_NoDRYPattern, NoDRYPattern.getValue(),
13451338
NoDRYPattern.getNumOccurrences());
1346-
setValueToOptMap(clang::dpct::OPTION_CompilationsDir, CompilationsDir,
1347-
OptParser->isPSpecified());
1348-
#ifdef _WIN32
1349-
if (!VcxprojFilePath.getPath().empty()) {
1350-
setValueToOptMap(clang::dpct::OPTION_VcxprojFile,
1351-
VcxprojFilePath.getCanonicalPath().str(),
1352-
OptParser->isVcxprojfileSpecified());
1353-
} else {
1354-
setValueToOptMap(clang::dpct::OPTION_VcxprojFile,
1355-
VcxprojFilePath.getPath().str(),
1356-
OptParser->isVcxprojfileSpecified());
1357-
}
1358-
#endif
13591339
setValueToOptMap(clang::dpct::OPTION_ProcessAll, ProcessAll.getValue(),
13601340
ProcessAll.getNumOccurrences());
13611341
setValueToOptMap(clang::dpct::OPTION_SyclNamedLambda, SyclNamedLambda.getValue(),
@@ -1395,11 +1375,17 @@ int runDPCT(int argc, const char **argv) {
13951375
parseFormatStyle();
13961376
}
13971377
// OC_Action: only migrate Build scripts.
1378+
if (MigrateBuildScriptOnly && !DpctGlobalInfo::migratePythonScripts() ||
1379+
DpctGlobalInfo::migrateCMakeScripts()) {
1380+
std::string Major = DpctGlobalInfo::getMainSourceYamlTUR()->SDKVersionMajor;
1381+
std::string Minor = DpctGlobalInfo::getMainSourceYamlTUR()->SDKVersionMinor;
1382+
if (!Major.empty() && !Minor.empty()) {
1383+
updateCompatibilityVersionInfo(OutRoot, Major, Minor);
1384+
}
1385+
}
13981386
if (MigrateBuildScriptOnly) {
1399-
loadMainSrcFileInfo(OutRootPath);
14001387
collectBuildScriptsSpecified(OptParser, InRootPath, OutRootPath);
14011388
migrateBuildScripts(InRootPath, OutRootPath);
1402-
14031389
ShowStatus(MigrationBuildScriptCompleted);
14041390
dpctExit(MigrationSucceeded, false);
14051391
}

clang/lib/DPCT/ErrorHandle/Error.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -238,9 +238,8 @@ void ShowStatus(int Status, std::string Message) {
238238
return;
239239
}
240240

241-
std::string getLoadYamlFailWarning(const clang::tooling::UnifiedPath &YamlPath) {
242-
return "Warning: Failed to load " + YamlPath.getCanonicalPath().str() +
243-
". Migration continues with incremental migration disabled. See "
241+
std::string getLoadYamlFailWarning() {
242+
return "Warning: Migration continues with incremental migration disabled. See "
244243
"https://www.intel.com/content/www/us/en/docs/"
245244
"dpcpp-compatibility-tool/developer-guide-reference/current/"
246245
"overview.html for more "

clang/lib/DPCT/ErrorHandle/Error.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ namespace clang {
7474
namespace dpct {
7575

7676
void ShowStatus(int Status, std::string Message = "");
77-
std::string getLoadYamlFailWarning(const clang::tooling::UnifiedPath& YamlPath);
77+
std::string getLoadYamlFailWarning();
7878
std::string getCheckVersionFailWarning();
7979
std::string getBuildScriptNotSpecifiedWarning();
8080
std::string getPythonRuleFileNotProvidedWarning();

0 commit comments

Comments
 (0)