Skip to content

Commit 8bdaca9

Browse files
[SYCLomatic][NFC] Move fft rules into FFTAPIMigration.cpp/h files. (#2480)
1 parent 170a47b commit 8bdaca9

File tree

5 files changed

+129
-125
lines changed

5 files changed

+129
-125
lines changed

clang/lib/DPCT/ASTTraversal.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
#include "AnalysisInfo.h"
1313
#include "ErrorHandle/CrashRecovery.h"
1414
#include "Diagnostics/Diagnostics.h"
15-
#include "RulesMathLib/FFTAPIMigration.h"
1615
#include "RulesInclude/InclusionHeaders.h"
1716
#include "RuleInfra/MapNames.h"
1817
#include "TextModification.h"

clang/lib/DPCT/RulesLang/RulesLang.cpp

Lines changed: 0 additions & 108 deletions
Original file line numberDiff line numberDiff line change
@@ -2581,32 +2581,6 @@ void LinkageSpecDeclRule::runRule(const MatchFinder::MatchResult &Result) {
25812581
std::make_pair(BeginLocInfo.second, EndLocInfo.second));
25822582
}
25832583

2584-
2585-
// Rule for FFT enums.
2586-
void FFTEnumsRule::registerMatcher(MatchFinder &MF) {
2587-
MF.addMatcher(
2588-
declRefExpr(
2589-
to(enumConstantDecl(matchesName(
2590-
"(CUFFT_SUCCESS|CUFFT_INVALID_PLAN|CUFFT_ALLOC_FAILED|CUFFT_"
2591-
"INVALID_TYPE|CUFFT_INVALID_VALUE|CUFFT_INTERNAL_ERROR|CUFFT_"
2592-
"EXEC_FAILED|CUFFT_SETUP_FAILED|CUFFT_INVALID_SIZE|CUFFT_"
2593-
"UNALIGNED_DATA|CUFFT_INCOMPLETE_PARAMETER_LIST|CUFFT_INVALID_"
2594-
"DEVICE|CUFFT_PARSE_ERROR|CUFFT_NO_WORKSPACE|CUFFT_NOT_"
2595-
"IMPLEMENTED|CUFFT_LICENSE_ERROR|CUFFT_NOT_SUPPORTED)"))))
2596-
.bind("FFTConstants"),
2597-
this);
2598-
}
2599-
2600-
void FFTEnumsRule::runRule(const MatchFinder::MatchResult &Result) {
2601-
if (const DeclRefExpr *DE =
2602-
getNodeAsType<DeclRefExpr>(Result, "FFTConstants")) {
2603-
auto *EC = cast<EnumConstantDecl>(DE->getDecl());
2604-
emplaceTransformation(new ReplaceStmt(DE, toString(EC->getInitVal(), 10)));
2605-
return;
2606-
}
2607-
}
2608-
2609-
26102584
// Rule for CU_JIT enums.
26112585
void CU_JITEnumsRule::registerMatcher(MatchFinder &MF) {
26122586
MF.addMatcher(
@@ -13066,88 +13040,6 @@ void RemoveBaseClassRule::runRule(const MatchFinder::MatchResult &Result) {
1306613040
}
1306713041
}
1306813042

13069-
13070-
// Rule for FFT function calls.
13071-
void FFTFunctionCallRule::registerMatcher(MatchFinder &MF) {
13072-
auto functionName = [&]() {
13073-
return hasAnyName("cufftPlan1d", "cufftPlan2d", "cufftPlan3d",
13074-
"cufftPlanMany", "cufftMakePlan1d", "cufftMakePlan2d",
13075-
"cufftMakePlan3d", "cufftMakePlanMany",
13076-
"cufftMakePlanMany64", "cufftExecC2C", "cufftExecR2C",
13077-
"cufftExecC2R", "cufftExecZ2Z", "cufftExecZ2D",
13078-
"cufftExecD2Z", "cufftCreate", "cufftDestroy",
13079-
"cufftSetStream", "cufftGetVersion", "cufftGetProperty",
13080-
"cufftXtMakePlanMany", "cufftXtExec", "cufftGetSize1d",
13081-
"cufftGetSize2d", "cufftGetSize3d", "cufftGetSizeMany",
13082-
"cufftGetSize", "cufftEstimate1d", "cufftEstimate2d",
13083-
"cufftEstimate3d", "cufftEstimateMany",
13084-
"cufftSetAutoAllocation", "cufftGetSizeMany64",
13085-
"cufftSetWorkArea");
13086-
};
13087-
MF.addMatcher(callExpr(callee(functionDecl(functionName()))).bind("FuncCall"),
13088-
this);
13089-
13090-
// Currently, only exec functions support function pointer migration
13091-
auto execFunctionName = [&]() {
13092-
return hasAnyName("cufftExecC2C", "cufftExecR2C", "cufftExecC2R",
13093-
"cufftExecZ2Z", "cufftExecZ2D", "cufftExecD2Z");
13094-
};
13095-
MF.addMatcher(unaryOperator(hasOperatorName("&"),
13096-
hasUnaryOperand(declRefExpr(hasDeclaration(
13097-
functionDecl(execFunctionName())))))
13098-
.bind("FuncPtr"),
13099-
this);
13100-
}
13101-
13102-
void FFTFunctionCallRule::runRule(const MatchFinder::MatchResult &Result) {
13103-
const CallExpr *CE = getNodeAsType<CallExpr>(Result, "FuncCall");
13104-
const UnaryOperator *UO = getNodeAsType<UnaryOperator>(Result, "FuncPtr");
13105-
13106-
if (!CE) {
13107-
auto TM = processFunctionPointer(UO);
13108-
if (TM) {
13109-
emplaceTransformation(TM);
13110-
}
13111-
return;
13112-
}
13113-
13114-
auto &SM = DpctGlobalInfo::getSourceManager();
13115-
if (!CE->getDirectCallee())
13116-
return;
13117-
std::string FuncName =
13118-
CE->getDirectCallee()->getNameInfo().getName().getAsString();
13119-
13120-
if (FuncName == "cufftGetVersion" || FuncName == "cufftGetProperty") {
13121-
DpctGlobalInfo::getInstance().insertHeader(
13122-
SM.getExpansionLoc(CE->getBeginLoc()), HT_DPCT_COMMON_Utils);
13123-
ExprAnalysis EA(CE);
13124-
emplaceTransformation(EA.getReplacement());
13125-
EA.applyAllSubExprRepl();
13126-
return;
13127-
} else if (FuncName == "cufftSetStream" ||
13128-
FuncName == "cufftCreate" || FuncName == "cufftDestroy" ||
13129-
FuncName == "cufftPlan1d" || FuncName == "cufftMakePlan1d" ||
13130-
FuncName == "cufftPlan2d" || FuncName == "cufftMakePlan2d" ||
13131-
FuncName == "cufftPlan3d" || FuncName == "cufftMakePlan3d" ||
13132-
FuncName == "cufftPlanMany" || FuncName == "cufftMakePlanMany" ||
13133-
FuncName == "cufftMakePlanMany64" || FuncName == "cufftXtMakePlanMany" ||
13134-
FuncName == "cufftExecC2C" || FuncName == "cufftExecZ2Z" ||
13135-
FuncName == "cufftExecC2R" || FuncName == "cufftExecR2C" ||
13136-
FuncName == "cufftExecZ2D" || FuncName == "cufftExecD2Z" ||
13137-
FuncName == "cufftXtExec" || FuncName == "cufftGetSize1d" ||
13138-
FuncName == "cufftGetSize2d" || FuncName == "cufftGetSize3d" ||
13139-
FuncName == "cufftGetSizeMany" || FuncName == "cufftGetSize" ||
13140-
FuncName == "cufftEstimate1d" || FuncName == "cufftEstimate2d" ||
13141-
FuncName == "cufftEstimate3d" || FuncName == "cufftEstimateMany" ||
13142-
FuncName == "cufftSetAutoAllocation" || FuncName == "cufftGetSizeMany64" ||
13143-
FuncName == "cufftSetWorkArea") {
13144-
ExprAnalysis EA(CE);
13145-
emplaceTransformation(EA.getReplacement());
13146-
EA.applyAllSubExprRepl();
13147-
return;
13148-
}
13149-
}
13150-
1315113043
void VirtualMemRule::registerMatcher(ast_matchers::MatchFinder &MF) {
1315213044
auto virtualmemoryAPI = [&]() {
1315313045
return hasAnyName("cuMemCreate", "cuMemAddressReserve", "cuMemMap",

clang/lib/DPCT/RulesLang/RulesLang.h

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -282,12 +282,6 @@ class LinkageSpecDeclRule : public NamedMigrationRule<LinkageSpecDeclRule> {
282282
void runRule(const ast_matchers::MatchFinder::MatchResult &Result);
283283
};
284284

285-
/// Migration rule for FFT enums.
286-
class FFTEnumsRule : public NamedMigrationRule<FFTEnumsRule> {
287-
public:
288-
void registerMatcher(ast_matchers::MatchFinder &MF) override;
289-
void runRule(const ast_matchers::MatchFinder::MatchResult &Result);
290-
};
291285

292286
/// Migration rule for CU_JIT enums.
293287
class CU_JITEnumsRule : public NamedMigrationRule<CU_JITEnumsRule> {
@@ -997,11 +991,6 @@ class PreDefinedStreamHandleRule
997991
void runRule(const ast_matchers::MatchFinder::MatchResult &Result);
998992
};
999993

1000-
class FFTFunctionCallRule : public NamedMigrationRule<FFTFunctionCallRule> {
1001-
public:
1002-
void registerMatcher(ast_matchers::MatchFinder &MF) override;
1003-
void runRule(const ast_matchers::MatchFinder::MatchResult &Result);
1004-
};
1005994

1006995
class DriverModuleAPIRule : public NamedMigrationRule<DriverModuleAPIRule> {
1007996
public:

clang/lib/DPCT/RulesMathLib/FFTAPIMigration.cpp

Lines changed: 109 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,11 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9-
#include "RulesMathLib/FFTAPIMigration.h"
9+
#include "ASTTraversal.h"
10+
#include "FFTAPIMigration.h"
11+
#include "RuleInfra/ExprAnalysis.h"
12+
13+
using namespace clang::ast_matchers;
1014

1115
namespace clang {
1216
namespace dpct {
@@ -73,6 +77,110 @@ TextModification* processFunctionPointer(const UnaryOperator *UO) {
7377
return TM;
7478
}
7579

80+
// Rule for FFT function calls.
81+
void FFTFunctionCallRule::registerMatcher(MatchFinder &MF) {
82+
auto functionName = [&]() {
83+
return hasAnyName("cufftPlan1d", "cufftPlan2d", "cufftPlan3d",
84+
"cufftPlanMany", "cufftMakePlan1d", "cufftMakePlan2d",
85+
"cufftMakePlan3d", "cufftMakePlanMany",
86+
"cufftMakePlanMany64", "cufftExecC2C", "cufftExecR2C",
87+
"cufftExecC2R", "cufftExecZ2Z", "cufftExecZ2D",
88+
"cufftExecD2Z", "cufftCreate", "cufftDestroy",
89+
"cufftSetStream", "cufftGetVersion", "cufftGetProperty",
90+
"cufftXtMakePlanMany", "cufftXtExec", "cufftGetSize1d",
91+
"cufftGetSize2d", "cufftGetSize3d", "cufftGetSizeMany",
92+
"cufftGetSize", "cufftEstimate1d", "cufftEstimate2d",
93+
"cufftEstimate3d", "cufftEstimateMany",
94+
"cufftSetAutoAllocation", "cufftGetSizeMany64",
95+
"cufftSetWorkArea");
96+
};
97+
MF.addMatcher(callExpr(callee(functionDecl(functionName()))).bind("FuncCall"),
98+
this);
99+
100+
// Currently, only exec functions support function pointer migration
101+
auto execFunctionName = [&]() {
102+
return hasAnyName("cufftExecC2C", "cufftExecR2C", "cufftExecC2R",
103+
"cufftExecZ2Z", "cufftExecZ2D", "cufftExecD2Z");
104+
};
105+
MF.addMatcher(unaryOperator(hasOperatorName("&"),
106+
hasUnaryOperand(declRefExpr(hasDeclaration(
107+
functionDecl(execFunctionName())))))
108+
.bind("FuncPtr"),
109+
this);
110+
}
111+
112+
void FFTFunctionCallRule::runRule(const MatchFinder::MatchResult &Result) {
113+
const CallExpr *CE = getNodeAsType<CallExpr>(Result, "FuncCall");
114+
const UnaryOperator *UO = getNodeAsType<UnaryOperator>(Result, "FuncPtr");
115+
116+
if (!CE) {
117+
auto TM = processFunctionPointer(UO);
118+
if (TM) {
119+
emplaceTransformation(TM);
120+
}
121+
return;
122+
}
123+
124+
auto &SM = DpctGlobalInfo::getSourceManager();
125+
if (!CE->getDirectCallee())
126+
return;
127+
std::string FuncName =
128+
CE->getDirectCallee()->getNameInfo().getName().getAsString();
129+
130+
if (FuncName == "cufftGetVersion" || FuncName == "cufftGetProperty") {
131+
DpctGlobalInfo::getInstance().insertHeader(
132+
SM.getExpansionLoc(CE->getBeginLoc()), HT_DPCT_COMMON_Utils);
133+
ExprAnalysis EA(CE);
134+
emplaceTransformation(EA.getReplacement());
135+
EA.applyAllSubExprRepl();
136+
return;
137+
} else if (FuncName == "cufftSetStream" ||
138+
FuncName == "cufftCreate" || FuncName == "cufftDestroy" ||
139+
FuncName == "cufftPlan1d" || FuncName == "cufftMakePlan1d" ||
140+
FuncName == "cufftPlan2d" || FuncName == "cufftMakePlan2d" ||
141+
FuncName == "cufftPlan3d" || FuncName == "cufftMakePlan3d" ||
142+
FuncName == "cufftPlanMany" || FuncName == "cufftMakePlanMany" ||
143+
FuncName == "cufftMakePlanMany64" || FuncName == "cufftXtMakePlanMany" ||
144+
FuncName == "cufftExecC2C" || FuncName == "cufftExecZ2Z" ||
145+
FuncName == "cufftExecC2R" || FuncName == "cufftExecR2C" ||
146+
FuncName == "cufftExecZ2D" || FuncName == "cufftExecD2Z" ||
147+
FuncName == "cufftXtExec" || FuncName == "cufftGetSize1d" ||
148+
FuncName == "cufftGetSize2d" || FuncName == "cufftGetSize3d" ||
149+
FuncName == "cufftGetSizeMany" || FuncName == "cufftGetSize" ||
150+
FuncName == "cufftEstimate1d" || FuncName == "cufftEstimate2d" ||
151+
FuncName == "cufftEstimate3d" || FuncName == "cufftEstimateMany" ||
152+
FuncName == "cufftSetAutoAllocation" || FuncName == "cufftGetSizeMany64" ||
153+
FuncName == "cufftSetWorkArea") {
154+
ExprAnalysis EA(CE);
155+
emplaceTransformation(EA.getReplacement());
156+
EA.applyAllSubExprRepl();
157+
return;
158+
}
159+
}
160+
161+
// Rule for FFT enums.
162+
void FFTEnumsRule::registerMatcher(MatchFinder &MF) {
163+
MF.addMatcher(
164+
declRefExpr(
165+
to(enumConstantDecl(matchesName(
166+
"(CUFFT_SUCCESS|CUFFT_INVALID_PLAN|CUFFT_ALLOC_FAILED|CUFFT_"
167+
"INVALID_TYPE|CUFFT_INVALID_VALUE|CUFFT_INTERNAL_ERROR|CUFFT_"
168+
"EXEC_FAILED|CUFFT_SETUP_FAILED|CUFFT_INVALID_SIZE|CUFFT_"
169+
"UNALIGNED_DATA|CUFFT_INCOMPLETE_PARAMETER_LIST|CUFFT_INVALID_"
170+
"DEVICE|CUFFT_PARSE_ERROR|CUFFT_NO_WORKSPACE|CUFFT_NOT_"
171+
"IMPLEMENTED|CUFFT_LICENSE_ERROR|CUFFT_NOT_SUPPORTED)"))))
172+
.bind("FFTConstants"),
173+
this);
174+
}
175+
176+
void FFTEnumsRule::runRule(const MatchFinder::MatchResult &Result) {
177+
if (const DeclRefExpr *DE =
178+
getNodeAsType<DeclRefExpr>(Result, "FFTConstants")) {
179+
auto *EC = cast<EnumConstantDecl>(DE->getDecl());
180+
emplaceTransformation(new ReplaceStmt(DE, toString(EC->getInitVal(), 10)));
181+
return;
182+
}
183+
}
76184

77185
} // namespace dpct
78186
} // namespace clang

clang/lib/DPCT/RulesMathLib/FFTAPIMigration.h

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,30 @@
99
#ifndef DPCT_FFT_API_MIGRATION_H
1010
#define DPCT_FFT_API_MIGRATION_H
1111

12-
#include "RuleInfra/MapNames.h"
13-
#include "TextModification.h"
14-
#include "clang/AST/Decl.h"
15-
#include "clang/AST/Stmt.h"
12+
#include "ASTTraversal.h"
13+
#include "clang/ASTMatchers/ASTMatchFinder.h"
14+
#include "clang/AST/Expr.h"
1615

1716
namespace clang {
1817
namespace dpct {
18+
1919
TextModification *processFunctionPointer(const UnaryOperator *UO);
20+
21+
class FFTFunctionCallRule : public NamedMigrationRule<FFTFunctionCallRule> {
22+
public:
23+
void registerMatcher(ast_matchers::MatchFinder &MF) override;
24+
void runRule(const ast_matchers::MatchFinder::MatchResult &Result);
25+
};
26+
27+
28+
/// Migration rule for FFT enums.
29+
class FFTEnumsRule : public NamedMigrationRule<FFTEnumsRule> {
30+
public:
31+
void registerMatcher(ast_matchers::MatchFinder &MF) override;
32+
void runRule(const ast_matchers::MatchFinder::MatchResult &Result);
33+
};
34+
35+
2036
} // namespace dpct
2137
} // namespace clang
2238

0 commit comments

Comments
 (0)