Skip to content

Commit 5d478c4

Browse files
committed
Fix lit
Signed-off-by: Jiang, Zhiwei <[email protected]>
1 parent 1d16c32 commit 5d478c4

File tree

9 files changed

+57
-89
lines changed

9 files changed

+57
-89
lines changed

clang/lib/DPCT/AnalysisInfo.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2408,8 +2408,7 @@ void DpctGlobalInfo::recordTokenSplit(SourceLocation SL, unsigned Len) {
24082408
/// MainSourceFiles.yaml file. This variable is valid after
24092409
/// canContinueMigration() is called.
24102410
std::shared_ptr<clang::tooling::TranslationUnitReplacements>
2411-
DpctGlobalInfo::MainSourceYamlTUR =
2412-
std::make_shared<clang::tooling::TranslationUnitReplacements>();
2411+
DpctGlobalInfo::MainSourceYamlTUR = nullptr;
24132412
clang::tooling::UnifiedPath DpctGlobalInfo::InRoot;
24142413
clang::tooling::UnifiedPath DpctGlobalInfo::OutRoot;
24152414
std::vector<clang::tooling::UnifiedPath> DpctGlobalInfo::AnalysisScope;

clang/lib/DPCT/DPCT.cpp

Lines changed: 35 additions & 34 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);
@@ -517,39 +512,31 @@ void updateCompatibilityVersionInfo(clang::tooling::UnifiedPath OutRoot,
517512
}
518513

519514
static void loadMainSrcFileInfo(clang::tooling::UnifiedPath YamlFilePath) {
520-
auto PreTU = std::make_shared<clang::tooling::TranslationUnitReplacements>();
521515
if (llvm::sys::fs::exists(YamlFilePath.getCanonicalPath())) {
516+
auto PreTU =
517+
std::make_shared<clang::tooling::TranslationUnitReplacements>();
522518
if (loadFromYaml(YamlFilePath, *PreTU) != 0) {
523519
llvm::errs() << getLoadYamlFailWarning();
524520
}
525521
DpctGlobalInfo::setMainSourceYamlTUR(PreTU);
526522

527-
if (MigrateBuildScriptOnly && !DpctGlobalInfo::migratePythonScripts() ||
528-
DpctGlobalInfo::migrateCMakeScripts()) {
529-
std::string Major = PreTU->SDKVersionMajor;
530-
std::string Minor = PreTU->SDKVersionMinor;
531-
if (!Major.empty() && !Minor.empty()) {
532-
updateCompatibilityVersionInfo(OutRoot, Major, Minor);
533-
}
523+
for (auto &Entry : PreTU->MainSourceFilesDigest) {
524+
if (Entry.HasCUDASyntax)
525+
MainSrcFilesHasCudaSyntex.insert(Entry.MainSourceFile);
534526
}
535-
}
536-
537-
for (auto &Entry : PreTU->MainSourceFilesDigest) {
538-
if (Entry.HasCUDASyntax)
539-
MainSrcFilesHasCudaSyntex.insert(Entry.MainSourceFile);
540-
}
541527

542-
// Currently, when "--use-experimental-features=device_global" and
543-
// "--use-experimental-features=all" are specified, the migrated code should
544-
// be compiled with C++20 or later.
545-
auto Iter = PreTU->OptionMap.find("ExperimentalFlag");
546-
if (Iter != PreTU->OptionMap.end()) {
547-
if (Iter->second.Specified) {
548-
const std::string Value = Iter->second.Value;
549-
unsigned int UValue = std::stoul(Value);
550-
if (UValue & (1 << static_cast<unsigned>(
551-
ExperimentalFeatures::Exp_DeviceGlobal))) {
552-
LANG_Cplusplus_20_Used = true;
528+
// Currently, when "--use-experimental-features=device_global" and
529+
// "--use-experimental-features=all" are specified, the migrated code should
530+
// be compiled with C++20 or later.
531+
auto Iter = PreTU->OptionMap.find("ExperimentalFlag");
532+
if (Iter != PreTU->OptionMap.end()) {
533+
if (Iter->second.Specified) {
534+
const std::string Value = Iter->second.Value;
535+
unsigned int UValue = std::stoul(Value);
536+
if (UValue & (1 << static_cast<unsigned>(
537+
ExperimentalFeatures::Exp_DeviceGlobal))) {
538+
LANG_Cplusplus_20_Used = true;
539+
}
553540
}
554541
}
555542
}
@@ -634,6 +621,12 @@ void showReportHeader() {
634621
}
635622

636623
void checkIncMigrationOrExit() {
624+
auto PreTU = DpctGlobalInfo::getMainSourceYamlTUR();
625+
if (!PreTU) {
626+
PreTU = std::make_shared<clang::tooling::TranslationUnitReplacements>();
627+
DpctGlobalInfo::setMainSourceYamlTUR(PreTU);
628+
return;
629+
}
637630
if (!MigrateBuildScriptOnly &&
638631
clang::dpct::DpctGlobalInfo::isIncMigration()) {
639632
std::string Msg;
@@ -816,7 +809,7 @@ int runDPCT(int argc, const char **argv) {
816809
CudaIncludePath = CudaInclude;
817810
SDKPath = SDKPathOpt;
818811

819-
loadMainSrcFileInfo(OutRootPath.getCanonicalPath() + "/MainSourceFiles.yaml");
812+
loadMainSrcFileInfo(OutRootPath.getCanonicalPath() + "/MainSourceFiles.yaml"); //1
820813

821814
std::transform(
822815
RuleFile.begin(), RuleFile.end(),
@@ -1342,8 +1335,6 @@ int runDPCT(int argc, const char **argv) {
13421335
UseDPCPPExtensions.getNumOccurrences());
13431336
setValueToOptMap(clang::dpct::OPTION_NoDRYPattern, NoDRYPattern.getValue(),
13441337
NoDRYPattern.getNumOccurrences());
1345-
setValueToOptMap(clang::dpct::OPTION_CompilationsDir, CompilationsDir,
1346-
OptParser->isPSpecified());
13471338
#ifdef _WIN32
13481339
if (!VcxprojFilePath.getPath().empty()) {
13491340
setValueToOptMap(clang::dpct::OPTION_VcxprojFile,
@@ -1387,14 +1378,24 @@ int runDPCT(int argc, const char **argv) {
13871378
setValueToOptMap(clang::dpct::OPTION_UseSYCLCompat, UseSYCLCompat.getValue(),
13881379
UseSYCLCompat.getNumOccurrences());
13891380

1390-
checkIncMigrationOrExit();
1381+
checkIncMigrationOrExit(); //2
13911382
}
13921383

13931384
if (DpctGlobalInfo::getFormatRange() != clang::format::FormatRange::none) {
13941385
parseFormatStyle();
13951386
}
13961387
// OC_Action: only migrate Build scripts.
13971388
if (MigrateBuildScriptOnly) {
1389+
if (!DpctGlobalInfo::migratePythonScripts() ||
1390+
DpctGlobalInfo::migrateCMakeScripts()) {
1391+
std::string Major =
1392+
DpctGlobalInfo::getMainSourceYamlTUR()->SDKVersionMajor;
1393+
std::string Minor =
1394+
DpctGlobalInfo::getMainSourceYamlTUR()->SDKVersionMinor;
1395+
if (!Major.empty() && !Minor.empty()) {
1396+
updateCompatibilityVersionInfo(OutRoot, Major, Minor);
1397+
}
1398+
}
13981399
collectBuildScriptsSpecified(OptParser, InRootPath, OutRootPath);
13991400
migrateBuildScripts(InRootPath, OutRootPath);
14001401

clang/lib/DPCT/FileGenerator/GenFiles.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -463,6 +463,18 @@ updateMainSrcFilesInfo(const clang::tooling::MainSourceFileInfo &Info) {
463463
static void saveUpdatedMigrationDataIntoYAML(
464464
std::vector<clang::tooling::Replacement> &AllFilesRepls,
465465
std::unordered_map<std::string, bool> &MainSrcFileMap) {
466+
// For files which are not in AllFilesRepls but in previous yaml file, we need
467+
// to add them into AllFilesRepls
468+
std::unordered_set<std::string> CurrentFileSet;
469+
for (const auto &Repl : AllFilesRepls) {
470+
CurrentFileSet.insert(Repl.getFilePath().str());
471+
}
472+
for (const auto &Repl :
473+
DpctGlobalInfo::getMainSourceYamlTUR()->Replacements) {
474+
if (CurrentFileSet.find(Repl.getFilePath().str()) == CurrentFileSet.end()) {
475+
AllFilesRepls.push_back(Repl);
476+
}
477+
}
466478
if (!AllFilesRepls.empty() || !CompileCmdsPerTarget.empty()) {
467479
save2Yaml(AllFilesRepls, CompileCmdsPerTarget);
468480
}

clang/lib/DPCT/IncMigration/IncrementalMigrationUtility.cpp

Lines changed: 5 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -111,38 +111,10 @@ int checkDpctOptionSet(
111111
} else if (CurrentOpt.first == OPTION_AnalysisScopePath) {
112112
if (checkListOptions(OPTION_AnalysisScopePath))
113113
return -1;
114-
}
115-
#ifdef _WIN32
116-
else if (CurrentOpt.first == OPTION_VcxprojFile) {
117-
if (!PreviousOpts.count(OPTION_CompilationsDir)) {
118-
return -2;
119-
}
120-
if ((PreviousOpts.at(OPTION_VcxprojFile).Specified &&
121-
!CurrentOpts.at(OPTION_VcxprojFile).Specified) ||
122-
(!PreviousOpts.at(OPTION_VcxprojFile).Specified &&
123-
CurrentOpts.at(OPTION_VcxprojFile).Specified)) {
124-
if (PreviousOpts.at(OPTION_CompilationsDir).Value !=
125-
CurrentOpts.at(OPTION_CompilationsDir).Value) {
126-
return -1;
127-
}
128-
} else {
129-
if (PreviousOpts.at(CurrentOpt.first).Value !=
130-
CurrentOpt.second.Value) {
131-
return -1;
132-
}
133-
}
134-
} else {
135-
if (PreviousOpts.at(CurrentOpt.first).Value !=
136-
CurrentOpt.second.Value) {
137-
return -1;
138-
}
139-
}
140-
#else
141-
else if (PreviousOpts.at(CurrentOpt.first).Value !=
142-
CurrentOpt.second.Value) {
114+
} else if (PreviousOpts.at(CurrentOpt.first).Value !=
115+
CurrentOpt.second.Value) {
143116
return -1;
144117
}
145-
#endif
146118
} else {
147119
return -2;
148120
}
@@ -245,8 +217,9 @@ bool printOptions(
245217
if ("true" == Value)
246218
Opts.emplace_back("--no-dry-pattern");
247219
}
248-
if (Key == clang::dpct::OPTION_CompilationsDir && Specified) {
249-
Opts.emplace_back("--compilation-database=\"" + Value + "\"");
220+
if (Key == clang::dpct::OPTION_CodePinEnabled && Specified) {
221+
if ("true" == Value)
222+
Opts.emplace_back("--enable-codepin");
250223
}
251224
#ifdef _WIN32
252225
if (Key == clang::dpct::OPTION_VcxprojFile && Specified) {
@@ -369,8 +342,6 @@ bool printOptions(
369342
// return false: dpct should exit
370343
bool canContinueMigration(std::string &Msg) {
371344
auto PreTU = DpctGlobalInfo::getMainSourceYamlTUR();
372-
if (!PreTU)
373-
return true;
374345

375346
// check version
376347
auto VerCompRes = compareToolVersion(PreTU->DpctVersion);

clang/lib/DPCT/IncMigration/IncrementalMigrationUtility.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ const std::string OPTION_CodePinEnabled = "CodePinEnabled";
2424
const std::string OPTION_ExtensionDEFlag = "ExtensionDEFlag";
2525
const std::string OPTION_ExtensionDDFlag = "ExtensionDDFlag";
2626
const std::string OPTION_NoDRYPattern = "NoDRYPattern";
27-
const std::string OPTION_CompilationsDir = "CompilationsDir";
2827
#ifdef _WIN32
2928
const std::string OPTION_VcxprojFile = "VcxprojFile";
3029
#endif

clang/test/dpct/a_test_yaml.h

Lines changed: 0 additions & 3 deletions
This file was deleted.

clang/test/dpct/codepin/valid/vectorAdd_build_in_type.cu

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
// 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
1+
// RUN: dpct --format-range=none -out-root %T/out %s --cuda-include-path="%cuda-path/include" -- -std=c++17 -x cuda --cuda-host-only
22
// 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
3-
// RUN: cat %S/dpct_output_ref/vectorAdd_build_in_type.dp.cpp >> %T/vector_add/vectorAdd_build_in_type.dp.cpp
3+
// RUN: cat %S/dpct_output_ref/vectorAdd_build_in_type.dp.cpp >> %T/out/vectorAdd_build_in_type.dp.cpp
44
// RUN: cat %S/dpct_output_codepin_cuda_ref/vectorAdd_build_in_type.cu >> %T/vector_add_codepin_cuda/vectorAdd_build_in_type.cu
55
// 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
66
// 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
7-
// 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
7+
// RUN: FileCheck --match-full-lines --input-file %T/out/vectorAdd_build_in_type.dp.cpp %T/out/vectorAdd_build_in_type.dp.cpp
88
// 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
99

1010
//==============================================================
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +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.
1+
// 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.

clang/test/dpct/test_yaml.cu

Lines changed: 0 additions & 11 deletions
This file was deleted.

0 commit comments

Comments
 (0)