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
5 changes: 5 additions & 0 deletions clang/include/clang/DPCT/DPCTOptions.inc
Original file line number Diff line number Diff line change
Expand Up @@ -460,4 +460,9 @@ DPCT_ENUM_OPTION(
llvm::cl::CommaSeparated, llvm::cl::value_desc("value"),
llvm::cl::cat(DPCTCat), llvm::cl::ZeroOrMore)

DPCT_NON_ENUM_OPTION(
DPCT_OPT_TYPE(static llvm::cl::opt<bool>), AnalysisMode, "analysis-mode",
llvm::cl::desc("Only generate report for porting effort. Default: off."),
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please update option conflict check as follow up of this PR.

llvm::cl::cat(DPCTCat), llvm::cl::init(false))

#endif // !DPCT_OPTIONS_IN_CLANG_DPCT
46 changes: 31 additions & 15 deletions clang/lib/DPCT/ASTTraversal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12352,6 +12352,7 @@ void RecognizeAPINameRule::processFuncCall(const CallExpr *CE) {
return;
}

recordRecognizedAPI(CE);
auto *NSD = dyn_cast<NamespaceDecl>(ND->getDeclContext());
Namespace = getNameSpace(NSD);
APIName = CE->getCalleeDecl()->getAsFunction()->getNameAsString();
Expand Down Expand Up @@ -12395,6 +12396,7 @@ void RecognizeTypeRule::registerMatcher(ast_matchers::MatchFinder &MF) {
auto TypeTable = MigrationStatistics::GetTypeTable();
std::vector<std::string> UnsupportedType;
std::vector<std::string> UnsupportedPointerType;
std::vector<std::string> AllTypes;
for (auto &Type : TypeTable) {
if (!Type.second) {
if (Type.first.find("*") != std::string::npos) {
Expand All @@ -12404,6 +12406,9 @@ void RecognizeTypeRule::registerMatcher(ast_matchers::MatchFinder &MF) {
UnsupportedType.push_back(Type.first);
}
}
if (DpctGlobalInfo::isAnalysisModeEnabled()) {
AllTypes.push_back(Type.first);
}
}
MF.addMatcher(
typeLoc(
Expand All @@ -12413,31 +12418,42 @@ void RecognizeTypeRule::registerMatcher(ast_matchers::MatchFinder &MF) {
loc(pointerType(pointee(qualType(hasDeclaration(namedDecl(
internal::Matcher<NamedDecl>(new internal::HasNameMatcher(
UnsupportedPointerType))))))))))
.bind("typeloc"),
.bind("unsupportedtypeloc"),
this);

if (DpctGlobalInfo::isAnalysisModeEnabled()) {
MF.addMatcher(typeLoc(loc(qualType(hasDeclaration(
namedDecl(internal::Matcher<NamedDecl>(
new internal::HasNameMatcher(AllTypes)))))))
.bind("alltypeloc"),
this);
}
}

void RecognizeTypeRule::runRule(
const ast_matchers::MatchFinder::MatchResult &Result) {
const TypeLoc *TL = getNodeAsType<TypeLoc>(Result, "typeloc");
if (!TL)
return;
auto &Context = DpctGlobalInfo::getContext();
QualType QTy = TL->getType();
if (QTy.isCanonical())
return;
std::string TypeName =
if (const TypeLoc* TL = getNodeAsType<TypeLoc>(Result, "unsupportedtypeloc")) {
auto& Context = DpctGlobalInfo::getContext();
QualType QTy = TL->getType();
if (QTy.isCanonical())
return;
std::string TypeName =
DpctGlobalInfo::getTypeName(QTy.getUnqualifiedType(), Context);
// process pointer type
if (!QTy->isTypedefNameType() && QTy->isPointerType()) {
std::string PointeeTy = DpctGlobalInfo::getTypeName(
// process pointer type
if (!QTy->isTypedefNameType() && QTy->isPointerType()) {
std::string PointeeTy = DpctGlobalInfo::getTypeName(
QTy->getPointeeType().getUnqualifiedType(), Context);
report(TL->getBeginLoc(), Diagnostics::KNOWN_UNSUPPORTED_TYPE, false,
PointeeTy + " *");
return;
}
report(TL->getBeginLoc(), Diagnostics::KNOWN_UNSUPPORTED_TYPE, false,
PointeeTy + " *");
TypeName);
return;
}
report(TL->getBeginLoc(), Diagnostics::KNOWN_UNSUPPORTED_TYPE, false,
TypeName);
if (const TypeLoc *TL = getNodeAsType<TypeLoc>(Result, "alltypeloc")) {
recordRecognizedType(*TL);
}
}

REGISTER_RULE(RecognizeTypeRule, PassKind::PK_Migration)
Expand Down
1 change: 1 addition & 0 deletions clang/lib/DPCT/AnalysisInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ unsigned DpctGlobalInfo::ExtensionDEFlag = static_cast<unsigned>(-1);
unsigned DpctGlobalInfo::ExtensionDDFlag = 0;
unsigned DpctGlobalInfo::ExperimentalFlag = 0;
unsigned DpctGlobalInfo::HelperFuncPreferenceFlag = 0;
bool DpctGlobalInfo::AnalysisModeFlag = false;
unsigned int DpctGlobalInfo::ColorOption = 1;
std::unordered_map<int, std::shared_ptr<DeviceFunctionInfo>>
DpctGlobalInfo::CubPlaceholderIndexMap;
Expand Down
3 changes: 3 additions & 0 deletions clang/lib/DPCT/AnalysisInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -986,6 +986,8 @@ class DpctGlobalInfo {
static unsigned getHelperFuncPreferenceFlag() {
return HelperFuncPreferenceFlag;
}
static bool isAnalysisModeEnabled() { return AnalysisModeFlag; }
static void enableAnalysisMode() { AnalysisModeFlag = true; }

inline static format::FormatRange getFormatRange() { return FmtRng; }
inline static void setFormatRange(format::FormatRange FR) { FmtRng = FR; }
Expand Down Expand Up @@ -2135,6 +2137,7 @@ class DpctGlobalInfo {
static unsigned ExtensionDDFlag;
static unsigned ExperimentalFlag;
static unsigned HelperFuncPreferenceFlag;
static bool AnalysisModeFlag;
static unsigned int ColorOption;
static std::unordered_map<int, std::shared_ptr<DeviceFunctionInfo>>
CubPlaceholderIndexMap;
Expand Down
9 changes: 9 additions & 0 deletions clang/lib/DPCT/DPCT.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -606,6 +606,10 @@ int runDPCT(int argc, const char **argv) {
clang::tooling::SetDiagnosticOutput(DpctTerm());
}

if (AnalysisMode) {
DpctGlobalInfo::enableAnalysisMode();
SuppressWarningsAllFlag = true;
}
initWarningIDs();

DpctInstallPath = getInstallPath(argv[0]);
Expand Down Expand Up @@ -1278,6 +1282,11 @@ int runDPCT(int argc, const char **argv) {
}
}

if (DpctGlobalInfo::isAnalysisModeEnabled()) {
dumpAnalysisModeStatics(llvm::outs());
return MigrationSucceeded;
}

// if run was successful
int Status = saveNewFiles(Tool, InRoot, OutRoot);
ShowStatus(Status);
Expand Down
14 changes: 9 additions & 5 deletions clang/lib/DPCT/Diagnostics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,17 @@ bool checkDuplicated(const std::string &FileAndLine,
std::unordered_map<int, DiagnosticsMessage> DiagnosticIDTable;
std::unordered_map<int, DiagnosticsMessage> CommentIDTable;

#define HIGH_LEVEL EffortLevel::EL_High
#define MEDIUM_LEVEL EffortLevel::EL_Medium
#define LOW_LEVEL EffortLevel::EL_Low

#define DEF_WARNING(NAME, ID, LEVEL, MSG) \
#define DEF_WARNING(NAME, ID, LEVEL, MSG) \
DiagnosticsMessage wg_##NAME(DiagnosticIDTable, ID, \
clang::DiagnosticIDs::Warning, MSG);
clang::DiagnosticIDs::Warning, LEVEL, MSG);

#define DEF_COMMENT(NAME, ID, LEVEL, MSG) \
#define DEF_COMMENT(NAME, ID, LEVEL, MSG) \
DiagnosticsMessage cg_##NAME(CommentIDTable, ID, clang::DiagnosticIDs::Note, \
MSG);
LEVEL, MSG);

#include "Diagnostics.inc"

Expand All @@ -52,7 +55,8 @@ std::unordered_set<int> APIQueryNeedReportWarningIDSet = {1086};

std::unordered_map<int, DiagnosticsMessage> MsgIDTable;
#define DEF_COMMENT(NAME, ID, MSG) \
DiagnosticsMessage cg_##NAME(MsgIDTable, ID, clang::DiagnosticIDs::Note, MSG);
DiagnosticsMessage cg_##NAME(MsgIDTable, ID, clang::DiagnosticIDs::Note, \
EffortLevel::EL_Low, MSG);
#include "DiagnosticsBuildScript.inc"
#undef DEF_COMMENT

Expand Down
31 changes: 21 additions & 10 deletions clang/lib/DPCT/Diagnostics.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ extern std::set<int> WarningIDs;
struct DiagnosticsMessage {
int ID;
int Category;
EffortLevel EL;
const char *Msg;

#define DEF_WARNING(NAME, ID, LEVEL, MSG) ID,
Expand All @@ -58,8 +59,8 @@ struct DiagnosticsMessage {
#undef DEF_COMMENT
DiagnosticsMessage() = default;
DiagnosticsMessage(std::unordered_map<int, DiagnosticsMessage> &Table, int ID,
int Category, const char *Msg)
: ID(ID), Category(Category), Msg(Msg) {
int Category, EffortLevel EL, const char *Msg)
: ID(ID), Category(Category), EL(EL), Msg(Msg) {
assert(Table.find(ID) == Table.end() && "[DPCT Internal error] Two "
"messages with the same ID "
"are being registered");
Expand Down Expand Up @@ -317,12 +318,17 @@ inline bool report(SourceLocation SL, IDTy MsgID,
if (checkDuplicated(FileAndLine, WarningIDAndMsg))
return false;

auto Diag = DiagnosticIDTable.find((int)MsgID);
if (Diag == DiagnosticIDTable.end())
return true;
if (DpctGlobalInfo::isAnalysisModeEnabled()) {
recordAnalysisModeEffort(SL, Diag->second.EL);
return true;
}
if (!SuppressWarningsAllFlag) {
// Only report warnings that are not suppressed
if (WarningIDs.find((int)MsgID) == WarningIDs.end() &&
DiagnosticIDTable.find((int)MsgID) != DiagnosticIDTable.end()) {
reportWarning(SL, DiagnosticIDTable[(int)MsgID], SM.getDiagnostics(),
Vals...);
if (WarningIDs.find((int)MsgID) == WarningIDs.end()) {
reportWarning(SL, Diag->second, SM.getDiagnostics(), Vals...);
}
}
if (TS && CommentIDTable.find((int)MsgID) != CommentIDTable.end()) {
Expand Down Expand Up @@ -402,12 +408,17 @@ bool report(const clang::tooling::UnifiedPath &FileAbsPath, unsigned int Offset,
unsigned int ColNum = Offset - Fileinfo->getLineInfo(LineNum).Offset + 1;
SourceLocation SL = SM.translateLineCol(FID, LineNum, ColNum);

auto Diag = DiagnosticIDTable.find((int)MsgID);
if (Diag == DiagnosticIDTable.end())
return true;
if (DpctGlobalInfo::isAnalysisModeEnabled()) {
recordAnalysisModeEffort(FileAbsPath, Offset, Diag->second.EL);
return true;
}
if (!SuppressWarningsAllFlag) {
// Only report warnings that are not suppressed
if (WarningIDs.find((int)MsgID) == WarningIDs.end() &&
DiagnosticIDTable.find((int)MsgID) != DiagnosticIDTable.end()) {
reportWarning(SL, DiagnosticIDTable[(int)MsgID], SM.getDiagnostics(),
Vals...);
if (WarningIDs.find((int)MsgID) == WarningIDs.end()) {
reportWarning(SL, Diag->second, SM.getDiagnostics(), Vals...);
}
}

Expand Down
1 change: 1 addition & 0 deletions clang/lib/DPCT/MigrationAction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ std::shared_ptr<TranslationUnitInfo> DpctToolAction::createTranslationUnitInfo(

std::shared_ptr<TranslationUnitInfo> DpctToolAction::createTranslationUnitInfoImpl(
std::shared_ptr<CompilerInvocation> Invocation, bool &Success) {
Invocation->getDiagnosticOpts().IgnoreWarnings = true;
auto DiagConsumer = new TextDiagnosticPrinter(
DiagnosticStream, &Invocation->getDiagnosticOpts());
auto Info = std::make_shared<TranslationUnitInfo>();
Expand Down
Loading