Skip to content

Commit

Permalink
[SYCLomatic][NFC] Further refine DPCT file structure and remove dead …
Browse files Browse the repository at this point in the history
…code/file (#2472)
  • Loading branch information
zhimingwang36 authored Nov 8, 2024
1 parent 45c1f62 commit 063de1c
Show file tree
Hide file tree
Showing 82 changed files with 132 additions and 417 deletions.
8 changes: 4 additions & 4 deletions clang/lib/DPCT/ASTTraversal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@
#include "AnalysisInfo.h"
#include "RulesAsm/AsmMigration.h"
#include "RulesLang/BarrierFenceSpaceAnalyzer.h"
#include "CallExprRewriter.h"
#include "CallExprRewriterCommon.h"
#include "RuleInfra/CallExprRewriter.h"
#include "RuleInfra/CallExprRewriterCommon.h"
#include "RulesDNN/DNNAPIMigration.h"
#include "ExprAnalysis.h"
#include "RuleInfra/ExprAnalysis.h"
#include "RulesMathLib/FFTAPIMigration.h"
#include "CodePin/GenCodePinHeader.h"
#include "RulesLang/GroupFunctionAnalyzer.h"
#include "RulesSecurity/Homoglyph.h"
#include "RulesLangLib/LIBCUAPIMigration.h"
#include "MemberExprRewriter.h"
#include "RuleInfra/MemberExprRewriter.h"
#include "MigrationRuleManager.h"
#include "RulesSecurity/MisleadingBidirectional.h"
#include "RulesCCL/NCCLAPIMigration.h"
Expand Down
99 changes: 1 addition & 98 deletions clang/lib/DPCT/ASTTraversal.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
#include "Diagnostics/Diagnostics.h"
#include "RulesMathLib/FFTAPIMigration.h"
#include "RulesInclude/InclusionHeaders.h"
#include "MapNames.h"
#include "RuleInfra/MapNames.h"
#include "TextModification.h"
#include "Utility.h"

Expand Down Expand Up @@ -280,103 +280,6 @@ template <typename T> class NamedMigrationRule : public MigrationRule {
}
}

void addReplacementForLibraryAPI(LibraryMigrationFlags Flags,
LibraryMigrationStrings &Strings,
LibraryMigrationLocations Locations,
std::string FuncName, const CallExpr *CE) {
if (Flags.NeedUseLambda) {
if (Strings.PrefixInsertStr.empty() && Strings.SuffixInsertStr.empty()) {
// If there is one API call in the migrated code, it is unnecessary to
// use a lambda expression
Flags.NeedUseLambda = false;
}
}

if (Flags.NeedUseLambda) {
if ((Flags.MoveOutOfMacro && Flags.IsMacroArg) ||
(Flags.CanAvoidUsingLambda && !Flags.IsMacroArg)) {
std::string InsertString;
if (DpctGlobalInfo::getUsmLevel() == UsmLevel::UL_None &&
!Flags.CanAvoidBrace)
InsertString = std::string("{") + getNL() + Strings.IndentStr +
Strings.PrefixInsertStr + Strings.Repl + ";" +
Strings.SuffixInsertStr + getNL() + Strings.IndentStr +
"}" + getNL() + Strings.IndentStr;
else
InsertString = Strings.PrefixInsertStr + Strings.Repl + ";" +
Strings.SuffixInsertStr + getNL() + Strings.IndentStr;

if (Flags.MoveOutOfMacro && Flags.IsMacroArg) {
auto IT = new InsertText(Locations.OutOfMacroInsertLoc,
std::move(InsertString));
IT->setBlockLevelFormatFlag();
emplaceTransformation(std::move(IT));
report(Locations.OutOfMacroInsertLoc, Diagnostics::CODE_LOGIC_CHANGED,
true, "function-like macro");
} else {
auto IT =
new InsertText(Locations.OuterInsertLoc, std::move(InsertString));
IT->setBlockLevelFormatFlag();
emplaceTransformation(std::move(IT));
report(Locations.OuterInsertLoc, Diagnostics::CODE_LOGIC_CHANGED,
true,
Flags.OriginStmtType == "if" ? "an " + Flags.OriginStmtType
: "a " + Flags.OriginStmtType);
}
emplaceTransformation(
new ReplaceText(Locations.PrefixInsertLoc, Locations.Len, "0"));
} else {
if (Flags.IsAssigned) {
report(Locations.PrefixInsertLoc, Diagnostics::NOERROR_RETURN_LAMBDA,
false);
insertAroundRange(
Locations.PrefixInsertLoc, Locations.SuffixInsertLoc,
std::string("[&](){") + getNL() + Strings.IndentStr +
Strings.PrefixInsertStr,
std::string(";") + Strings.SuffixInsertStr + getNL() +
Strings.IndentStr + "return 0;" + getNL() +
Strings.IndentStr + std::string("}()"),
true);
} else {
insertAroundRange(
Locations.PrefixInsertLoc, Locations.SuffixInsertLoc,
std::string("[&](){") + getNL() + Strings.IndentStr +
Strings.PrefixInsertStr,
std::string(";") + Strings.SuffixInsertStr + getNL() +
Strings.IndentStr + std::string("}()"),
true);
}
emplaceTransformation(new ReplaceText(
Locations.PrefixInsertLoc, Locations.Len, std::move(Strings.Repl)));
}
} else {
if (DpctGlobalInfo::getUsmLevel() == UsmLevel::UL_None &&
!Flags.CanAvoidBrace) {
if (!Strings.PrefixInsertStr.empty() ||
!Strings.SuffixInsertStr.empty()) {
insertAroundRange(
Locations.PrefixInsertLoc, Locations.SuffixInsertLoc,
Strings.PrePrefixInsertStr + std::string("{") + getNL() +
Strings.IndentStr + Strings.PrefixInsertStr,
Strings.SuffixInsertStr + getNL() + Strings.IndentStr +
std::string("}"),
true);
}
} else {
insertAroundRange(Locations.PrefixInsertLoc, Locations.SuffixInsertLoc,
Strings.PrePrefixInsertStr + Strings.PrefixInsertStr,
std::move(Strings.SuffixInsertStr), true);
}
if (Flags.IsAssigned) {
insertAroundRange(Locations.FuncNameBegin, Locations.FuncCallEnd,
MapNames::getCheckErrorMacroName() + "(", ")");
requestFeature(HelperFeatureEnum::device_ext);
}

emplaceTransformation(new ReplaceStmt(CE, true, Strings.Repl));
}
}

std::string makeDevicePolicy(const Stmt *S) {
auto UniqueName = [](const Stmt *S) {
auto &SM = DpctGlobalInfo::getSourceManager();
Expand Down
4 changes: 2 additions & 2 deletions clang/lib/DPCT/AnalysisInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@

#include "AnalysisInfo.h"
#include "Diagnostics/Diagnostics.h"
#include "ExprAnalysis.h"
#include "MapNames.h"
#include "RuleInfra/ExprAnalysis.h"
#include "RuleInfra/MapNames.h"
#include "Statics.h"
#include "TextModification.h"
#include "Utility.h"
Expand Down
5 changes: 2 additions & 3 deletions clang/lib/DPCT/AnalysisInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,15 @@
#define DPCT_ANALYSIS_INFO_H

#include "ErrorHandle/Error.h"
#include "ExprAnalysis.h"
#include "RuleInfra/ExprAnalysis.h"
#include "ExtReplacements.h"
#include "RulesInclude/InclusionHeaders.h"
#include "LibraryAPIMigration.h"
#include "UserDefinedRules/UserDefinedRules.h"
#include "FileGenerator/GenFiles.h"
#include "Statics.h"
#include "TextModification.h"
#include "Utility.h"
#include "ValidateArguments.h"
#include "CommandOption/ValidateArguments.h"
#include <bitset>
#include <memory>
#include <optional>
Expand Down
23 changes: 11 additions & 12 deletions clang/lib/DPCT/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ add_custom_target(gen_mapping_register
COMMAND "${CMAKE_COMMAND}"
-DTARGET="${API_MAPPING_REGISTER_FOLDER}APIMappingRegister.def"
-DSRC_DIRECTORY="${CMAKE_CURRENT_SOURCE_DIR}/../../examples/DPCT/"
-P ${CMAKE_CURRENT_SOURCE_DIR}/APIMapping/GenerateRegister.cmake
-P ${CMAKE_CURRENT_SOURCE_DIR}/QueryAPIMapping/GenerateRegister.cmake
DEPENDS ${SRC_FILES})
include_directories(
${API_MAPPING_REGISTER_FOLDER}
Expand Down Expand Up @@ -146,7 +146,7 @@ add_clang_library(DPCT
RulesLang/Math/RewriterCXXAPIRoutines.cpp
RulesLang/Math/RewriterOverload.cpp
RulesLang/RewriterSYCLcompat.cpp
CallExprRewriter.cpp
RuleInfra/CallExprRewriter.cpp
RulesLang/CallExprRewriterAtomic.cpp
RulesMathLib/CallExprRewriterCUFFT.cpp
RulesMathLib/CallExprRewriterCUBLAS.cpp
Expand Down Expand Up @@ -174,21 +174,20 @@ add_clang_library(DPCT
Diagnostics/Diagnostics.cpp
ErrorHandle/Error.cpp
Statics.cpp
ExprAnalysis.cpp
RuleInfra/ExprAnalysis.cpp
ExtReplacements.cpp
MapNames.cpp
RuleInfra/MapNames.cpp
FileGenerator/GenFiles.cpp
DPCT.cpp
DpctOptions.cpp
CommandOption/DpctOptions.cpp
TextModification.cpp
Utility.cpp
ValidateArguments.cpp
ExternalReplacement.cpp
CommandOption/ValidateArguments.cpp
IncMigration/ExternalReplacement.cpp
Windows/VcxprojParser.cpp
LibraryAPIMigration.cpp
MigrateScript/GenMakefile.cpp
RulesInclude/InclusionHeaders.cpp
IncrementalMigrationUtility.cpp
IncMigration/IncrementalMigrationUtility.cpp
UserDefinedRules/UserDefinedRules.cpp
UserDefinedRules/PatternRewriter.cpp
MigrateScript/MigrateBuildScript.cpp
Expand All @@ -201,18 +200,18 @@ add_clang_library(DPCT
RulesMathLib/FFTAPIMigration.cpp
RulesDNN/DNNAPIMigration.cpp
RulesCCL/NCCLAPIMigration.cpp
TypeLocRewriters.cpp
RuleInfra/TypeLocRewriters.cpp
Linux/AutoComplete.cpp
RulesAsm/AsmMigration.cpp
APIMapping/QueryAPIMapping.cpp
QueryAPIMapping/QueryAPIMapping.cpp
RulesAsm/Parser/AsmNodes.cpp
RulesAsm/Parser/AsmLexer.cpp
RulesAsm/Parser/AsmParser.cpp
RulesAsm/Parser/AsmIdentifierTable.cpp
RulesAsm/Parser/AsmTokenKinds.cpp
RulesLangLib/LIBCUAPIMigration.cpp
RulesLangLib/CUBAPIMigration.cpp
MemberExprRewriter.cpp
RuleInfra/MemberExprRewriter.cpp
MigrationRuleManager.cpp
MigrationAction.cpp
RulesLangLib/ThrustAPIMigration.cpp
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/DPCT/CodePin/GenCodePinHeader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#include "ASTTraversal.h"
#include "AnalysisInfo.h"
#include "Diagnostics/Diagnostics.h"
#include "MapNames.h"
#include "RuleInfra/MapNames.h"
#include "Statics.h"
#include "clang/AST/Expr.h"
#include "clang/ASTMatchers/ASTMatchFinder.h"
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
//
//===----------------------------------------------------------------------===//

#include "ValidateArguments.h"
#include "CommandOption/ValidateArguments.h"
#include "ErrorHandle/Error.h"
#include "Statics.h"
#include "Utility.h"
Expand Down
File renamed without changes.
14 changes: 7 additions & 7 deletions clang/lib/DPCT/DPCT.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,19 @@
//===----------------------------------------------------------------------===//

#include "clang/DPCT/DPCT.h"
#include "APIMapping/QueryAPIMapping.h"
#include "QueryAPIMapping/QueryAPIMapping.h"
#include "ASTTraversal.h"
#include "AnalysisInfo.h"
#include "Linux/AutoComplete.h"
#include "CallExprRewriter.h"
#include "RuleInfra/CallExprRewriter.h"
#include "Config.h"
#include "ErrorHandle/CrashRecovery.h"
#include "ErrorHandle/Error.h"
#include "ExternalReplacement.h"
#include "IncMigration/ExternalReplacement.h"
#include "FileGenerator/GenHelperFunction.h"
#include "MigrateScript/GenMakefile.h"
#include "IncrementalMigrationUtility.h"
#include "MemberExprRewriter.h"
#include "IncMigration/IncrementalMigrationUtility.h"
#include "RuleInfra/MemberExprRewriter.h"
#include "MigrateScript/MigrateCmakeScript.h"
#include "MigrateScript/MigratePythonBuildScript.h"
#include "MigrationAction.h"
Expand All @@ -28,9 +28,9 @@
#include "UserDefinedRules/UserDefinedRules.h"
#include "FileGenerator/GenFiles.h"
#include "Statics.h"
#include "TypeLocRewriters.h"
#include "RuleInfra/TypeLocRewriters.h"
#include "Utility.h"
#include "ValidateArguments.h"
#include "CommandOption/ValidateArguments.h"
#include "Windows/VcxprojParser.h"
#include "clang/AST/ASTConsumer.h"
#include "clang/ASTMatchers/ASTMatchFinder.h"
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 @@ -10,7 +10,7 @@
#include "AnalysisInfo.h"
#include "ErrorHandle/CrashRecovery.h"
#include "Diagnostics/Diagnostics.h"
#include "ExternalReplacement.h"
#include "IncMigration/ExternalReplacement.h"
#include "MigrateScript/GenMakefile.h"
#include "UserDefinedRules/PatternRewriter.h"
#include "Statics.h"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#include "llvm/Support/Path.h"

#include "ExternalReplacement.h"
#include "IncrementalMigrationUtility.h"
#include "IncMigration/IncrementalMigrationUtility.h"
#include "clang/Tooling/Core/Diagnostic.h"
#include "clang/Tooling/Refactoring.h"
#include "clang/Tooling/ReplacementsYaml.h"
Expand Down
File renamed without changes.
85 changes: 0 additions & 85 deletions clang/lib/DPCT/LibraryAPIMigration.cpp

This file was deleted.

Loading

0 comments on commit 063de1c

Please sign in to comment.