Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 6 additions & 0 deletions clang/lib/DPCT/ASTTraversal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@
using namespace clang;
using namespace clang::dpct;

namespace clang {
namespace dpct {

unsigned MigrationRule::PairID = 0;

void MigrationRule::print(llvm::raw_ostream &OS) {
Expand Down Expand Up @@ -179,3 +182,6 @@ REGISTER_RULE(FFTFunctionCallRule, PassKind::PK_Migration,RuleGroupKind::RK_FFT)

REGISTER_RULE(CuDNNTypeRule, PassKind::PK_Migration, RuleGroupKind::RK_DNN)
REGISTER_RULE(CuDNNAPIRule, PassKind::PK_Migration, RuleGroupKind::RK_DNN)

} // namespace dpct
} // namespace clang
18 changes: 10 additions & 8 deletions clang/lib/DPCT/FileGenerator/GenFiles.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//===--------------- GenFiles.cpp -------------------------------------===//
//===--------------- GenFiles.cpp ----------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
Expand Down Expand Up @@ -44,14 +44,17 @@ using namespace llvm;
namespace path = llvm::sys::path;
namespace fs = llvm::sys::fs;

extern DpctOption<clang::dpct::opt, bool> ProcessAll;
extern DpctOption<dpct::opt, std::string> BuildScriptFile;
extern DpctOption<dpct::opt, bool> GenBuildScript;
extern std::map<std::string, uint64_t> ErrorCnt;

namespace clang {
namespace tooling {
UnifiedPath getFormatSearchPath();
} // namespace tooling
} // namespace clang


extern std::map<std::string, uint64_t> ErrorCnt;
namespace dpct{

/// Calculate the ranges of the input \p Ranges after \p Repls is applied to
/// the files.
Expand Down Expand Up @@ -294,7 +297,6 @@ void copyFileToOutRoot(clang::tooling::UnifiedPath &InRoot,
void processallOptionAction(clang::tooling::UnifiedPath &InRoot,
clang::tooling::UnifiedPath &OutRoot,
bool IsForSYCL) {
extern DpctOption<clang::dpct::opt, bool> ProcessAll;
if (ProcessAll) {
std::error_code EC;
for (fs::recursive_directory_iterator Iter(Twine(InRoot.getPath()), EC),
Expand Down Expand Up @@ -440,8 +442,6 @@ void processAllFiles(StringRef InRoot, StringRef OutRoot,
}
}

extern DpctOption<dpct::opt, std::string> BuildScriptFile;
extern DpctOption<dpct::opt, bool> GenBuildScript;

static void getMainSrcFilesRepls(
std::vector<clang::tooling::Replacement> &MainSrcFilesRepls) {
Expand Down Expand Up @@ -938,7 +938,6 @@ int saveNewFiles(clang::tooling::RefactoringTool &Tool,
SourceManager Sources(Diagnostics, Tool.getFiles());
Rewriter Rewrite(Sources, DefaultLangOptions);
Rewriter DebugCUDARewrite(Sources, DefaultLangOptions);
extern DpctOption<clang::dpct::opt, bool> ProcessAll;

// The variable defined here assists to merge history records.
std::unordered_map<std::string /*FileName*/,
Expand Down Expand Up @@ -1234,3 +1233,6 @@ void loadYAMLIntoFileInfo(clang::tooling::UnifiedPath Path) {
}
}
}

} // namespace dpct
} // namespace clang
6 changes: 6 additions & 0 deletions clang/lib/DPCT/FileGenerator/GenFiles.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ namespace llvm {
class StringRef;
} // namespace llvm

namespace clang {
namespace dpct {
/// Apply all generated replacements, and immediately save the results to
/// files in output directory.
///
Expand Down Expand Up @@ -79,4 +81,8 @@ void rewriteFileName(std::string &FileName, const std::string &FullPathName);

// A mapping from output file path to it's corresponding input file.
extern std::map<std::string, std::string> OutFilePath2InFilePath;

} // namespace dpct
} // namespace clang

#endif // DPCT_GEN_FILES_H
4 changes: 4 additions & 0 deletions clang/lib/DPCT/IncMigration/ExternalReplacement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ namespace path = llvm::sys::path;
namespace fs = llvm::sys::fs;
using clang::tooling::Replacements;

namespace clang {
namespace dpct {
int save2Yaml(
clang::tooling::UnifiedPath &YamlFile,
clang::tooling::UnifiedPath &SrcFileName,
Expand Down Expand Up @@ -163,3 +165,5 @@ int mergeExternalReps(clang::tooling::UnifiedPath InRootSrcFilePath,
save2Yaml(YamlFile, OutRootSrcFilePath, Repls, {MsfInfo}, CompileTargets);
return 0;
}
} // namespace dpct
} // namespace clang
8 changes: 7 additions & 1 deletion clang/lib/DPCT/IncMigration/ExternalReplacement.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ class Replacements;
} // namespace tooling
} // namespace clang

namespace clang {
namespace dpct {

int mergeExternalReps(clang::tooling::UnifiedPath InRootSrcFilePath,
clang::tooling::UnifiedPath OutRootSrcFilePath,
clang::tooling::Replacements &Replaces);
Expand All @@ -43,4 +46,7 @@ void mergeAndUniqueReps(
clang::tooling::Replacements &Replaces,
const std::vector<clang::tooling::Replacement> &PreRepls);

#endif
} // namespace dpct
} // namespace clang

#endif // __EXTERNAL_REPLACEMENT_H__
4 changes: 4 additions & 0 deletions clang/lib/DPCT/MigrateScript/GenMakefile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
using namespace clang::dpct;
using namespace llvm;

namespace clang {
namespace dpct {
// Used to identify compilation commands without target
const std::string EmptyTarget = "NoLinker";

Expand Down Expand Up @@ -679,3 +681,5 @@ void genBuildScript(clang::tooling::RefactoringTool &Tool,
genMakefile(Tool, OutRoot, BuildScriptName, CompileCmdsPerTarget,
ToolPerTarget);
}
} // namespace dpct
} // namespace clang
5 changes: 4 additions & 1 deletion clang/lib/DPCT/MigrateScript/GenMakefile.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ class RefactoringTool;
}
} // namespace clang

namespace clang {
namespace dpct {
/// Generates makefile for migrated file(s) in -out-root directory.
/// The name of generated makefile is specified by \p BuildScriptName
void genBuildScript(clang::tooling::RefactoringTool &Tool,
Expand All @@ -39,5 +41,6 @@ extern std::vector<
std::pair<clang::tooling::UnifiedPath /*target*/,
std::vector<std::string> /*orginal compile command*/>>
CompileTargetsMap;

} // namespace dpct
} // namespace clang
#endif // DPCT_GEN_MAKEFILE_H
5 changes: 5 additions & 0 deletions clang/lib/DPCT/MigrateScript/MigrateCmakeScript.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ using namespace llvm::cl;
namespace path = llvm::sys::path;
namespace fs = llvm::sys::fs;

namespace clang {
namespace dpct {
std::map<std::string /*CMake command*/,
std::tuple<bool /*ProcessedOrNot*/, bool /*CUDASpecificOrNot*/>>
cmake_commands{
Expand Down Expand Up @@ -576,3 +578,6 @@ void registerCmakeMigrationRule(MetaRuleObject &R) {
CmakeBuildInRules[PR.BuildScriptSyntax] = PR;
}
}

} // namespace dpct
} // namespace clang
7 changes: 6 additions & 1 deletion clang/lib/DPCT/MigrateScript/MigrateCmakeScript.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
#include "MigrateBuildScript.h"
#include "UserDefinedRules/UserDefinedRules.h"

namespace clang {
namespace dpct {
void collectCmakeScripts(const clang::tooling::UnifiedPath &InRoot,
const clang::tooling::UnifiedPath &OutRoot);
void collectCmakeScriptsSpecified(
Expand All @@ -23,4 +25,7 @@ void registerCmakeMigrationRule(MetaRuleObject &R);
bool cmakeScriptNotFound();
void addCmakeWarningMsg(const std::string &WarningMsg,
const std::string FileName);
#endif

} // namespace dpct
} // namespace clang
#endif //DPCT_MIGRATE_CMAKE_SCRIPT_H
5 changes: 5 additions & 0 deletions clang/lib/DPCT/MigrateScript/MigratePythonBuildScript.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ using namespace llvm::cl;
namespace path = llvm::sys::path;
namespace fs = llvm::sys::fs;

namespace clang {
namespace dpct {
static std::vector<clang::tooling::UnifiedPath /*file path*/>
PythonBuildScriptFilesSet;
static std::map<clang::tooling::UnifiedPath /*file path*/,
Expand Down Expand Up @@ -125,3 +127,6 @@ void registerPythonMigrationRule(MetaRuleObject &R) {
PythonBuildInRules[PR.BuildScriptSyntax] = PR;
}
}

} // namespace dpct
} // namespace clang
6 changes: 5 additions & 1 deletion clang/lib/DPCT/MigrateScript/MigratePythonBuildScript.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
#include "MigrateBuildScript.h"
#include "UserDefinedRules/UserDefinedRules.h"

namespace clang {
namespace dpct {
void collectPythonBuildScripts(const clang::tooling::UnifiedPath &InRoot,
const clang::tooling::UnifiedPath &OutRoot);
void collectPythonBuildScriptsSpecified(
Expand All @@ -23,4 +25,6 @@ void registerPythonMigrationRule(MetaRuleObject &R);
bool pythonBuildScriptNotFound();
void addPythonWarningMsg(const std::string &WarningMsg,
const std::string FileName);
#endif
} // namespace dpct
} // namespace clang
#endif //DPCT_MIGRATE_PYTHON_BUILD_SCRIPT_H
9 changes: 8 additions & 1 deletion clang/lib/DPCT/PreProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ using namespace clang::dpct;
using namespace clang::tooling;

extern DpctOption<opt, bool> ProcessAll;
namespace clang {
namespace dpct {



std::shared_ptr<clang::dpct::ReplaceToken>
generateReplacement(SourceLocation SL, MacroMigrationRule &Rule) {
Expand Down Expand Up @@ -815,4 +819,7 @@ void IncludesCallbacks::FileChanged(SourceLocation Loc, FileChangeReason Reason,

loadYAMLIntoFileInfo(InFile.getCanonicalPath());
}
}
}

} // namespace dpct
} // namespace clang
36 changes: 36 additions & 0 deletions clang/lib/DPCT/RuleInfra/ASTmatcherCommon.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
//===--------------- ASTmatcherCommon.h ----------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#ifndef DPCT_AST_MATCHER_COMMON_H
#define DPCT_AST_MATCHER_COMMON_H
#include "clang/ASTMatchers/ASTMatchersInternal.h"

using namespace clang::ast_matchers;
namespace clang {
namespace dpct {

inline auto parentStmtCub = []() {
return anyOf(hasParent(compoundStmt()), hasParent(forStmt()),
hasParent(whileStmt()), hasParent(doStmt()),
hasParent(ifStmt()));
};

inline auto parentStmt = []() {
return anyOf(
hasParent(compoundStmt()), hasParent(forStmt()), hasParent(whileStmt()),
hasParent(doStmt()), hasParent(ifStmt()),
hasParent(exprWithCleanups(anyOf(
hasParent(compoundStmt()), hasParent(forStmt()),
hasParent(whileStmt()), hasParent(doStmt()), hasParent(ifStmt())))));
};


} //namespace dpct
} //namespace clang

#endif //!DPCT_AST_MATCHER_COMMON_H
6 changes: 3 additions & 3 deletions clang/lib/DPCT/RuleInfra/CallExprRewriterCommon.h
Original file line number Diff line number Diff line change
Expand Up @@ -958,9 +958,9 @@ inline std::function<bool(const CallExpr *C)> checkArgSpelling(size_t index,

inline std::function<bool(const CallExpr *C)> checkIsCallExprOnly() {
return [=](const CallExpr *C) -> bool {
auto parentStmt = getParentStmt(C);
if (parentStmt != nullptr && (dyn_cast<CompoundStmt>(parentStmt) ||
dyn_cast<ExprWithCleanups>(parentStmt)))
auto ParentStmt = getParentStmt(C);
if (ParentStmt != nullptr && (dyn_cast<CompoundStmt>(ParentStmt) ||
dyn_cast<ExprWithCleanups>(ParentStmt)))
return true;
return false;
};
Expand Down
25 changes: 15 additions & 10 deletions clang/lib/DPCT/RulesLang/RulesLang.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "RulesLang/BarrierFenceSpaceAnalyzer.h"
#include "RuleInfra/CallExprRewriter.h"
#include "RuleInfra/CallExprRewriterCommon.h"
#include "RuleInfra/ASTmatcherCommon.h"
#include "RulesDNN/DNNAPIMigration.h"
#include "RuleInfra/ExprAnalysis.h"
#include "RulesMathLib/FFTAPIMigration.h"
Expand Down Expand Up @@ -66,15 +67,12 @@ using namespace clang::tooling;

extern clang::tooling::UnifiedPath DpctInstallPath; // Installation directory for this tool
extern DpctOption<opt, bool> ProcessAll;
extern DpctOption<opt, bool> AsyncHandler;

namespace clang{
namespace dpct{


auto parentStmt = []() {
return anyOf(
hasParent(compoundStmt()), hasParent(forStmt()), hasParent(whileStmt()),
hasParent(doStmt()), hasParent(ifStmt()),
hasParent(exprWithCleanups(anyOf(
hasParent(compoundStmt()), hasParent(forStmt()),
hasParent(whileStmt()), hasParent(doStmt()), hasParent(ifStmt())))));
};

static const CXXConstructorDecl *getIfConstructorDecl(const Decl *ND) {
if (const auto *Tmpl = dyn_cast<FunctionTemplateDecl>(ND))
Expand Down Expand Up @@ -2012,6 +2010,8 @@ void VectorTypeMemberAccessRule::runRule(
}
}

} //namespace clang
} //namespace dpct

namespace clang {
namespace ast_matchers {
Expand Down Expand Up @@ -2071,6 +2071,9 @@ AST_MATCHER(FunctionDecl, overloadedVectorOperator) {
} // namespace ast_matchers
} // namespace clang

namespace clang {
namespace dpct {

void VectorTypeOperatorRule::registerMatcher(MatchFinder &MF) {
auto vectorTypeOverLoadedOperator = [&]() {
return functionDecl(overloadedVectorOperator(),
Expand Down Expand Up @@ -4679,7 +4682,6 @@ void StreamAPICallRule::registerMatcher(MatchFinder &MF) {
}

std::string getNewQueue(int Index) {
extern DpctOption<opt, bool> AsyncHandler;
std::string Result;
llvm::raw_string_ostream OS(Result);
printPartialArguments(OS << "{{NEEDREPLACED" << std::to_string(Index)
Expand Down Expand Up @@ -6502,7 +6504,7 @@ void MemoryMigrationRule::mallocMigrationWithTransformation(

/// e.g., for int *a and cudaMalloc(&a, size), print "a = ".
/// If \p DerefType is not null, assign a string "int *".
void clang::dpct::printDerefOp(std::ostream &OS, const Expr *E, std::string *DerefType) {
void printDerefOp(std::ostream &OS, const Expr *E, std::string *DerefType) {
E = E->IgnoreImplicitAsWritten();
bool NeedDerefOp = true;
if (auto UO = dyn_cast<UnaryOperator>(E)) {
Expand Down Expand Up @@ -11803,3 +11805,6 @@ void GraphicsInteropRule::runRule(
emplaceTransformation(EA.getReplacement());
EA.applyAllSubExprRepl();
}

} //namespace clang
} //namespace dpct
Loading