Skip to content

[DO NOT MERGE][SYCLomatic] reMigration #2857

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 49 commits into
base: SYCLomatic
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
f737620
[SYCLomatic] gitdiff2yaml
zhiweij1 May 26, 2025
900b2ab
Add tests
zhiweij1 May 26, 2025
60fcdaf
Merge remote-tracking branch 'origin/SYCLomatic' into git_to_yaml
zhiweij1 May 26, 2025
22e4cf4
refine repl
zhiweij1 May 27, 2025
59227ff
format
zhiweij1 May 27, 2025
2154ad5
Update
zhiweij1 May 27, 2025
6601a02
Fix
zhiweij1 May 27, 2025
9bbe00a
Fix build
zhiweij1 May 28, 2025
5a6147d
Fix load
zhiweij1 May 28, 2025
92b1399
Update
zhiweij1 May 28, 2025
8d4a783
Update
zhiweij1 May 28, 2025
63f6f8e
Update
zhiweij1 May 28, 2025
81ac3b6
Fix
zhiweij1 May 28, 2025
4577dd0
Merge remote-tracking branch 'origin/SYCLomatic' into git_to_yaml
zhiweij1 May 28, 2025
1303478
Merge remote-tracking branch 'origin/SYCLomatic' into repl
zhiweij1 May 28, 2025
c1f1834
Fix build
zhiweij1 May 28, 2025
ce62ba8
Update
zhiweij1 May 29, 2025
b4dc41d
Save yaml into globalinfo
zhiweij1 May 29, 2025
94b7268
Fix path
zhiweij1 May 29, 2025
f31055b
Format
zhiweij1 May 29, 2025
8f4f284
Merge branch 'git_to_yaml' into repl
zhiweij1 May 29, 2025
63e6fbc
Format
zhiweij1 May 29, 2025
89edb93
WIP
zhiweij1 Jun 3, 2025
8eb1e47
1
zhiweij1 Jun 4, 2025
c4397d0
remove unused changes
zhiweij1 Jun 4, 2025
989a1a3
Update
zhiweij1 Jun 4, 2025
ba244bc
1
zhiweij1 Jun 4, 2025
4e2dca3
Update
zhiweij1 Jun 4, 2025
023a3bb
1
zhiweij1 Jun 4, 2025
1a80e3d
Merge branch 'repl_WIP' into repl
zhiweij1 Jun 4, 2025
4752c67
WIP
zhiweij1 Jun 4, 2025
a1fe561
add merge
zhiweij1 Jun 4, 2025
00d66d7
fix build
zhiweij1 Jun 4, 2025
574f529
Merge remote-tracking branch 'origin/SYCLomatic' into repl
zhiweij1 Jun 10, 2025
f4a7e1c
Merge remote-tracking branch 'origin/SYCLomatic' into repl
zhiweij1 Jun 11, 2025
bcd7e6e
Merge remote-tracking branch 'origin/SYCLomatic' into repl
zhiweij1 Jun 12, 2025
95db140
Merge remote-tracking branch 'origin/SYCLomatic' into repl
zhiweij1 Jun 13, 2025
fd108b8
Merge remote-tracking branch 'origin/SYCLomatic' into repl
zhiweij1 Jun 16, 2025
b80321e
Merge remote-tracking branch 'origin/SYCLomatic' into repl
zhiweij1 Jun 17, 2025
f4e07f9
Add test for calculateUpdatedRanges
zhiweij1 Jun 17, 2025
005db06
Add test for groupReplcementsByFile and convertReplcementsLineString
zhiweij1 Jun 18, 2025
cd62439
add test for splitReplInOrderToNotCrossLines
zhiweij1 Jun 19, 2025
9dfe19b
add test for mergeMapsByLine
zhiweij1 Jun 19, 2025
6774b83
Merge remote-tracking branch 'origin/SYCLomatic' into repl
zhiweij1 Jun 19, 2025
82ca75f
Update test
zhiweij1 Jun 19, 2025
882661f
Small fix
zhiweij1 Jun 19, 2025
2873a73
Add test for mergeC1AndC2
zhiweij1 Jun 20, 2025
50bca90
Update
zhiweij1 Jun 20, 2025
c700ece
Update
zhiweij1 Jun 20, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions clang/lib/DPCT/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ add_clang_library(DPCT
MigrateScript/GenMakefile.cpp
RulesInclude/InclusionHeaders.cpp
IncMigration/IncrementalMigrationUtility.cpp
IncMigration/ReMigration.cpp
UserDefinedRules/UserDefinedRules.cpp
UserDefinedRules/PatternRewriter.cpp
MigrateScript/MigrateBuildScript.cpp
Expand Down
4 changes: 3 additions & 1 deletion clang/lib/DPCT/DPCT.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,7 @@ static void loadMainSrcFileInfo(clang::tooling::UnifiedPath OutRoot) {
DpctGlobalInfo::getYamlFileName());
auto PreTU = std::make_shared<clang::tooling::TranslationUnitReplacements>();
if (llvm::sys::fs::exists(YamlFilePath)) {
if (loadFromYaml(YamlFilePath, *PreTU) != 0) {
if (loadTUFromYaml(YamlFilePath, *PreTU) != 0) {
llvm::errs() << getLoadYamlFailWarning(YamlFilePath);
}

Expand Down Expand Up @@ -1400,6 +1400,8 @@ int runDPCT(int argc, const char **argv) {
dpctExit(MigrationSucceeded, false);
}

tryLoadingUpstreamChangesAndUserChanges();

ReplTy ReplCUDA, ReplSYCL;
volatile int RunCount = 0;
do {
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/DPCT/FileGenerator/GenFiles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1210,7 +1210,7 @@ void loadYAMLIntoFileInfo(clang::tooling::UnifiedPath Path) {
auto PreTU = std::make_shared<clang::tooling::TranslationUnitReplacements>();
if (fs::exists(YamlFilePath.getCanonicalPath())) {
if (clang::dpct::DpctGlobalInfo::isIncMigration()) {
if (loadFromYaml(YamlFilePath, *PreTU) == 0) {
if (loadTUFromYaml(YamlFilePath, *PreTU) == 0) {
DpctGlobalInfo::getInstance().insertReplInfoFromYAMLToFileInfo(
OriginPath, std::move(PreTU));
} else {
Expand Down
43 changes: 32 additions & 11 deletions clang/lib/DPCT/IncMigration/ExternalReplacement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,19 @@
// -Load replacement from external (disk file)
// -Merge replacement in current migration with previous migration.

#include "ExternalReplacement.h"
#include "AnalysisInfo.h"
#include "IncMigration/IncrementalMigrationUtility.h"
#include "Utility.h"

#include "clang/Tooling/Core/Diagnostic.h"
#include "clang/Tooling/Core/Replacement.h"
#include "clang/Tooling/Refactoring.h"
#include "clang/Tooling/ReplacementsYaml.h"
#include "llvm/ADT/SmallString.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/Path.h"

#include "ExternalReplacement.h"
#include "IncMigration/IncrementalMigrationUtility.h"
#include "clang/Tooling/Core/Diagnostic.h"
#include "clang/Tooling/Refactoring.h"
#include "clang/Tooling/ReplacementsYaml.h"
#include "llvm/Support/YAMLTraits.h"
#include "llvm/Support/raw_os_ostream.h"

Expand Down Expand Up @@ -75,18 +75,29 @@ int save2Yaml(
return 0;
}

int loadFromYaml(const clang::tooling::UnifiedPath &Input,
clang::tooling::TranslationUnitReplacements &TU) {
template <class T>
static int loadFromYaml(const clang::tooling::UnifiedPath &Input, T &Content) {
llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> Buffer =
llvm::MemoryBuffer::getFile(Input.getCanonicalPath());
if (!Buffer) {
llvm::errs() << "error: failed to read " << Input.getCanonicalPath() << ": "
<< Buffer.getError().message() << "\n";
return -1;
}

llvm::yaml::Input YAMLIn(Buffer.get()->getBuffer());
YAMLIn >> TU;
YAMLIn >> Content;
if (YAMLIn.error()) {
Content = T();
return -1;
}
return 0;
}

int loadTUFromYaml(const clang::tooling::UnifiedPath &Input,
clang::tooling::TranslationUnitReplacements &TU) {
int Status = loadFromYaml(Input, TU);
if (Status)
return Status;

bool IsSrcFileChanged = false;
for (const auto &digest : TU.MainSourceFilesDigest) {
Expand All @@ -98,7 +109,7 @@ int loadFromYaml(const clang::tooling::UnifiedPath &Input,
}
}

if (IsSrcFileChanged || YAMLIn.error()) {
if (IsSrcFileChanged) {
// File doesn't appear to be a header change description. Ignore it.
TU = clang::tooling::TranslationUnitReplacements();
return -1;
Expand All @@ -107,6 +118,16 @@ int loadFromYaml(const clang::tooling::UnifiedPath &Input,
return 0;
}

void loadGDCFromYaml(const clang::tooling::UnifiedPath &Input,
clang::dpct::GitDiffChanges &GDC) {
int status = loadFromYaml(Input, GDC);
if (status) {
llvm::errs() << "Failed to load git diff Changes from "
<< Input.getCanonicalPath() << "\n";
GDC = clang::dpct::GitDiffChanges();
}
}

void mergeAndUniqueReps(
Replacements &Replaces,
const std::vector<clang::tooling::Replacement> &PreRepls) {
Expand Down
11 changes: 7 additions & 4 deletions clang/lib/DPCT/IncMigration/ExternalReplacement.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
#ifndef __EXTERNAL_REPLACEMENT_H__
#define __EXTERNAL_REPLACEMENT_H__

#include "clang/Tooling/Core/Replacement.h"
#include "llvm/ADT/StringRef.h"
#include "IncMigration/ReMigration.h"

#include <map>
#include <vector>

Expand All @@ -31,8 +31,10 @@ 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 loadTUFromYaml(const clang::tooling::UnifiedPath &Input,
clang::tooling::TranslationUnitReplacements &TU);
void loadGDCFromYaml(const clang::tooling::UnifiedPath &Input,
clang::dpct::GitDiffChanges &GDC);
int save2Yaml(
clang::tooling::UnifiedPath &YamlFile,
clang::tooling::UnifiedPath &SrcFileName,
Expand All @@ -46,6 +48,7 @@ void mergeAndUniqueReps(
clang::tooling::Replacements &Replaces,
const std::vector<clang::tooling::Replacement> &PreRepls);

void tryLoadingUpstreamChangesAndUserChanges();
} // namespace dpct
} // namespace clang

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ bool canContinueMigration(std::string &Msg) {

if (!llvm::sys::fs::exists(YamlFilePath.getCanonicalPath()))
return true;
if (loadFromYaml(YamlFilePath.getCanonicalPath(), *PreTU) != 0) {
if (loadTUFromYaml(YamlFilePath.getCanonicalPath(), *PreTU) != 0) {
llvm::errs() << getLoadYamlFailWarning(YamlFilePath.getCanonicalPath());
return true;
}
Expand Down
Loading