Skip to content

Commit 0f01bae

Browse files
Fix LIT test
Signed-off-by: Ahmed, Daiyaan <daiyaan.ahmed@intel.com>
1 parent 1243af4 commit 0f01bae

9 files changed

Lines changed: 122 additions & 177 deletions

File tree

clang/lib/DPCT/RuleInfra/APINamesTemplateType.inc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -507,6 +507,13 @@ TYPE_REWRITE_ENTRY(
507507
WARNING_FACTORY(Diagnostics::TRY_EXPERIMENTAL_FEATURE, TYPESTR,
508508
STR("--use-experimental-features=graph"))))
509509

510+
TYPE_REWRITE_ENTRY(
511+
"cudaGraphExecUpdateResultInfo",
512+
TYPE_CONDITIONAL_FACTORY(
513+
checkEnableGraphForType(), TYPE_FACTORY(STR("int")),
514+
WARNING_FACTORY(Diagnostics::TRY_EXPERIMENTAL_FEATURE, TYPESTR,
515+
STR("--use-experimental-features=graph"))))
516+
510517
TYPE_REWRITE_ENTRY(
511518
"cudaKernelNodeParams",
512519
TYPE_CONDITIONAL_FACTORY(

clang/lib/DPCT/RuleInfra/MapNames.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -643,10 +643,6 @@ void MapNames::setExplicitNamespaceMap(
643643
DpctGlobalInfo::useExtGraph()
644644
? getClNamespace() + "ext::oneapi::experimental::node_type"
645645
: "cudaGraphNodeType")},
646-
{"cudaGraphExecUpdateResultInfo",
647-
std::make_shared<TypeNameRule>(DpctGlobalInfo::useExtGraph()
648-
? "int"
649-
: "cudaGraphExecUpdateResultInfo")},
650646
{"cudaGraphExecUpdateResult",
651647
std::make_shared<TypeNameRule>(DpctGlobalInfo::useExtGraph()
652648
? "int"

clang/lib/DPCT/RulesLang/RulesLang.cpp

Lines changed: 57 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -348,25 +348,24 @@ void TypeInDeclRule::registerMatcher(MatchFinder &MF) {
348348
"cudaGraphicsRegisterFlags", "cudaExternalMemoryHandleType",
349349
"cudaExternalSemaphoreHandleType", "CUstreamCallback",
350350
"cudaHostFn_t", "__nv_half2", "__nv_half", "cudaGraphNodeType",
351-
"CUsurfref", "CUdevice_P2PAttribute", "cudaIpcMemHandle_t",
352-
"cudaGraphExecUpdateResultInfo"))))))
351+
"CUsurfref", "CUdevice_P2PAttribute", "cudaIpcMemHandle_t"))))))
353352
.bind("cudaTypeDef"),
354353
this);
355354

356355
MF.addMatcher(
357-
typeLoc(
358-
loc(qualType(hasDeclaration(namedDecl(hasAnyName(
359-
"cooperative_groups::__v1::coalesced_group",
360-
"cooperative_groups::__v1::grid_group",
361-
"cooperative_groups::__v1::thread_block_tile", "cudaGraph_t",
362-
"cudaGraphExec_t", "cudaGraphNode_t", "cudaGraphicsResource",
363-
"cudaGraphicsResource_t", "CUgraphicsResource",
364-
"cudaExternalMemory_t", "cudaExternalMemoryHandleDesc",
365-
"cudaExternalMemoryMipmappedArrayDesc",
366-
"cudaExternalMemoryBufferDesc", "cudaExternalSemaphore_t",
367-
"cudaExternalSemaphoreHandleDesc",
368-
"cudaExternalSemaphoreSignalParams",
369-
"cudaExternalSemaphoreWaitParams", "cudaKernelNodeParams"))))))
356+
typeLoc(loc(qualType(hasDeclaration(namedDecl(hasAnyName(
357+
"cooperative_groups::__v1::coalesced_group",
358+
"cooperative_groups::__v1::grid_group",
359+
"cooperative_groups::__v1::thread_block_tile", "cudaGraph_t",
360+
"cudaGraphExec_t", "cudaGraphNode_t", "cudaGraphicsResource",
361+
"cudaGraphicsResource_t", "CUgraphicsResource",
362+
"cudaExternalMemory_t", "cudaExternalMemoryHandleDesc",
363+
"cudaExternalMemoryMipmappedArrayDesc",
364+
"cudaExternalMemoryBufferDesc", "cudaExternalSemaphore_t",
365+
"cudaExternalSemaphoreHandleDesc",
366+
"cudaExternalSemaphoreSignalParams",
367+
"cudaExternalSemaphoreWaitParams", "cudaKernelNodeParams",
368+
"cudaGraphExecUpdateResultInfo"))))))
370369
.bind("cudaTypeDefEA"),
371370
this);
372371
MF.addMatcher(varDecl(hasType(classTemplateSpecializationDecl(
@@ -945,7 +944,7 @@ void TypeInDeclRule::runRule(const MatchFinder::MatchResult &Result) {
945944
"--use-experimental-features=graph");
946945
}
947946
}
948-
947+
949948
if (CanonicalTypeStr == "cudaGraphicsRegisterFlags" ||
950949
CanonicalTypeStr == "cudaGraphicsMapFlags") {
951950
if (!DpctGlobalInfo::useExtBindlessImages()) {
@@ -2738,6 +2737,48 @@ const VarDecl *getAssignTargetDecl(const Stmt *E) {
27382737
return nullptr;
27392738
}
27402739

2740+
const Expr *getParentAsAssignedBO(const Expr *E,
2741+
ASTContext &Context, MigrationRule *Rule) {
2742+
auto Parents = Context.getParents(*E);
2743+
if (Parents.size() > 0)
2744+
return getAssignedBO(Parents[0].get<Expr>(), Context, Rule);
2745+
return nullptr;
2746+
}
2747+
2748+
// Return the binary operator if E is the lhs of an assign expression,
2749+
// otherwise nullptr.
2750+
const Expr *getAssignedBO(const Expr *E, ASTContext &Context, MigrationRule *Rule) {
2751+
if (dyn_cast<MemberExpr>(E)) {
2752+
// Continue finding parents when E is MemberExpr.
2753+
return getParentAsAssignedBO(E, Context, Rule);
2754+
} else if (auto ICE = dyn_cast<ImplicitCastExpr>(E)) {
2755+
// Stop finding parents and return nullptr when E is ImplicitCastExpr,
2756+
// except for ArrayToPointerDecay cast.
2757+
if (ICE->getCastKind() == CK_ArrayToPointerDecay) {
2758+
return getParentAsAssignedBO(E, Context, Rule);
2759+
}
2760+
} else if (auto ASE = dyn_cast<ArraySubscriptExpr>(E)) {
2761+
// Continue finding parents when E is ArraySubscriptExpr, and remove
2762+
// subscript operator anyway for texture object's member.
2763+
Rule->emplaceTransformation(new ReplaceToken(
2764+
Lexer::getLocForEndOfToken(ASE->getLHS()->getEndLoc(), 0,
2765+
Context.getSourceManager(),
2766+
Context.getLangOpts()),
2767+
ASE->getRBracketLoc(), ""));
2768+
return getParentAsAssignedBO(E, Context, Rule);
2769+
} else if (auto BO = dyn_cast<BinaryOperator>(E)) {
2770+
// If E is BinaryOperator, return E only when it is assign expression,
2771+
// otherwise return nullptr.
2772+
if (BO->getOpcode() == BO_Assign)
2773+
return BO;
2774+
} else if (auto COCE = dyn_cast<CXXOperatorCallExpr>(E)) {
2775+
if (COCE->getOperator() == OO_Equal) {
2776+
return COCE;
2777+
}
2778+
}
2779+
return nullptr;
2780+
}
2781+
27412782
const VarDecl *EventQueryTraversal::getAssignTarget(const CallExpr *Call) {
27422783
auto ParentMap = Context.getParents(*Call);
27432784
if (ParentMap.size() == 0)

clang/lib/DPCT/RulesLang/RulesLang.h

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ TextModification *ReplaceMemberAssignAsSetMethod(const Expr *E,
4040
StringRef ExtraArg = "",
4141
StringRef ExtraFeild = "");
4242

43+
const Expr *getAssignedBO(const Expr *E, ASTContext &Context, MigrationRule *Rule);
44+
const Expr *getParentAsAssignedBO(const Expr *E, ASTContext &Context, MigrationRule *Rule);
45+
4346
/// Migration rule for iteration space built-in variables (threadIdx, etc).
4447
class IterationSpaceBuiltinRule
4548
: public NamedMigrationRule<IterationSpaceBuiltinRule> {
@@ -852,9 +855,6 @@ class TextureMemberSetRule : public NamedMigrationRule<TextureMemberSetRule> {
852855

853856
/// Texture migration rule
854857
class TextureRule : public NamedMigrationRule<TextureRule> {
855-
// Get the binary operator if E is lhs of an assign expression.
856-
const Expr *getAssignedBO(const Expr *E, ASTContext &Context);
857-
const Expr *getParentAsAssignedBO(const Expr *E, ASTContext &Context);
858858
bool removeExtraMemberAccess(const MemberExpr *ME);
859859
void replaceTextureMember(const MemberExpr *ME, ASTContext &Context,
860860
SourceManager &SM);
@@ -1006,8 +1006,6 @@ class GraphAnalysisRule : public NamedMigrationRule<GraphAnalysisRule> {
10061006

10071007
class GraphRule : public NamedMigrationRule<GraphRule> {
10081008
static MapNames::MapTy KernelNodeParamNames;
1009-
const Expr *getAssignedBO(const Expr *E, ASTContext &Context);
1010-
const Expr *getParentAsAssignedBO(const Expr *E, ASTContext &Context);
10111009

10121010
public:
10131011
void registerMatcher(ast_matchers::MatchFinder &MF) override;
@@ -1023,8 +1021,6 @@ class AssertRule : public NamedMigrationRule<AssertRule> {
10231021
class GraphicsInteropRule : public NamedMigrationRule<GraphicsInteropRule> {
10241022
static MapNames::MapTy ExtResMemHandleDescNames, ExtResSemParamsNames;
10251023

1026-
const Expr *getAssignedBO(const Expr *E, ASTContext &Context);
1027-
const Expr *getParentAsAssignedBO(const Expr *E, ASTContext &Context);
10281024
void replaceExtResMemHandleDataExpr(const MemberExpr *ME,
10291025
ASTContext &Context);
10301026
void replaceExtResSemParamsDataExpr(const MemberExpr *ME,

clang/lib/DPCT/RulesLang/RulesLangGraph.cpp

Lines changed: 18 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,12 @@ void GraphRule::registerMatcher(MatchFinder &MF) {
7070
.bind("Type"),
7171
this);
7272

73-
MF.addMatcher(memberExpr(hasObjectExpression(hasType(
74-
asString("cudaGraphExecUpdateResultInfo"))),
75-
member(hasName("result")))
76-
.bind("execUpdateResult"),
77-
this);
73+
MF.addMatcher(
74+
memberExpr(hasObjectExpression(
75+
hasType(asString("cudaGraphExecUpdateResultInfo"))),
76+
member(hasAnyName("result", "errorNode", "errorFromNode")))
77+
.bind("execUpdateResult"),
78+
this);
7879
}
7980

8081
void GraphRule::runRule(const MatchFinder::MatchResult &Result) {
@@ -92,8 +93,13 @@ void GraphRule::runRule(const MatchFinder::MatchResult &Result) {
9293
return;
9394
}
9495
if (FieldName == "func") {
95-
auto BO = dyn_cast<BinaryOperator>(
96-
getParentAsAssignedBO(ME, *Result.Context));
96+
auto BinaryOp = getParentAsAssignedBO(ME, *Result.Context, this);
97+
if (!BinaryOp) {
98+
emplaceTransformation(new RenameFieldInMemberExpr(
99+
ME, buildString("get_", FieldName, "()")));
100+
return;
101+
}
102+
auto BO = dyn_cast<BinaryOperator>(BinaryOp);
97103
if (!BO) {
98104
return;
99105
}
@@ -138,7 +144,7 @@ void GraphRule::runRule(const MatchFinder::MatchResult &Result) {
138144
BO->getBeginLoc(), BO->getEndLoc(), std::move(ReplacementStr)));
139145
emplaceTransformation(new InsertAfterStmt(BO, ")"));
140146
}
141-
if (auto BO = getParentAsAssignedBO(ME, *Result.Context)) {
147+
if (auto BO = getParentAsAssignedBO(ME, *Result.Context, this)) {
142148
StringRef ReplacedArg = "";
143149
emplaceTransformation(
144150
ReplaceMemberAssignAsSetMethod(BO, ME, FieldName, ReplacedArg));
@@ -152,7 +158,9 @@ void GraphRule::runRule(const MatchFinder::MatchResult &Result) {
152158
if (auto ME = getNodeAsType<MemberExpr>(Result, "execUpdateResult")) {
153159
auto MD = ME->getMemberDecl();
154160
const Expr *Base = ME->getBase();
155-
if (MD->getNameAsString() == "result") {
161+
std::string MemberName = MD->getNameAsString();
162+
if (MemberName == "result" || MemberName == "errorNode" ||
163+
MemberName == "errorFromNode") {
156164
if (auto *DRE = dyn_cast<DeclRefExpr>(Base)) {
157165
SourceLocation StartLoc = Base->getBeginLoc();
158166
SourceLocation EndLoc = ME->getEndLoc();
@@ -163,8 +171,8 @@ void GraphRule::runRule(const MatchFinder::MatchResult &Result) {
163171
emplaceTransformation(
164172
new ReplaceToken(StartLoc, EndLoc, std::move(VarNameStr)));
165173
}
174+
return;
166175
}
167-
return;
168176
}
169177
const CallExpr *CE = getNodeAsType<CallExpr>(Result, "FunctionCall");
170178
if (!CE) {
@@ -175,46 +183,5 @@ void GraphRule::runRule(const MatchFinder::MatchResult &Result) {
175183
EA.applyAllSubExprRepl();
176184
}
177185

178-
const Expr *GraphRule::getParentAsAssignedBO(const Expr *E,
179-
ASTContext &Context) {
180-
auto Parents = Context.getParents(*E);
181-
if (Parents.size() > 0)
182-
return getAssignedBO(Parents[0].get<Expr>(), Context);
183-
return nullptr;
184-
}
185-
186-
// Return the binary operator if E is the lhs of an assign expression,
187-
// otherwise nullptr.
188-
const Expr *GraphRule::getAssignedBO(const Expr *E, ASTContext &Context) {
189-
if (dyn_cast<MemberExpr>(E)) {
190-
// Continue finding parents when E is MemberExpr.
191-
return getParentAsAssignedBO(E, Context);
192-
} else if (auto ICE = dyn_cast<ImplicitCastExpr>(E)) {
193-
// Stop finding parents and return nullptr when E is ImplicitCastExpr,
194-
// except for ArrayToPointerDecay cast.
195-
if (ICE->getCastKind() == CK_ArrayToPointerDecay) {
196-
return getParentAsAssignedBO(E, Context);
197-
}
198-
} else if (auto ASE = dyn_cast<ArraySubscriptExpr>(E)) {
199-
// Continue finding parents when E is ArraySubscriptExpr, and remove
200-
// subscript operator anyway for texture object's member.
201-
emplaceTransformation(new ReplaceToken(
202-
Lexer::getLocForEndOfToken(ASE->getLHS()->getEndLoc(), 0,
203-
Context.getSourceManager(),
204-
Context.getLangOpts()),
205-
ASE->getRBracketLoc(), ""));
206-
return getParentAsAssignedBO(E, Context);
207-
} else if (auto BO = dyn_cast<BinaryOperator>(E)) {
208-
// If E is BinaryOperator, return E only when it is assign expression,
209-
// otherwise return nullptr.
210-
if (BO->getOpcode() == BO_Assign)
211-
return BO;
212-
} else if (auto COCE = dyn_cast<CXXOperatorCallExpr>(E)) {
213-
if (COCE->getOperator() == OO_Equal) {
214-
return COCE;
215-
}
216-
}
217-
return nullptr;
218-
}
219186
} // namespace dpct
220187
} // namespace clang

clang/lib/DPCT/RulesLang/RulesLangGraphicsInterop.cpp

Lines changed: 5 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ void GraphicsInteropRule::runRule(
104104
}
105105

106106
requestFeature(HelperFeatureEnum::device_ext);
107-
if (auto BO = getParentAsAssignedBO(ME, *Result.Context)) {
107+
if (auto BO = getParentAsAssignedBO(ME, *Result.Context, this)) {
108108
StringRef ReplacedArg = "";
109109

110110
if (FieldName == "flags") {
@@ -150,7 +150,7 @@ void GraphicsInteropRule::runRule(
150150
}
151151

152152
requestFeature(HelperFeatureEnum::device_ext);
153-
if (auto BO = getParentAsAssignedBO(ME, *Result.Context)) {
153+
if (auto BO = getParentAsAssignedBO(ME, *Result.Context, this)) {
154154
StringRef ReplacedArg = "";
155155

156156
if (FieldName == "image_type") {
@@ -196,7 +196,7 @@ void GraphicsInteropRule::runRule(
196196
}
197197

198198
requestFeature(HelperFeatureEnum::device_ext);
199-
if (auto BO = getParentAsAssignedBO(ME, *Result.Context)) {
199+
if (auto BO = getParentAsAssignedBO(ME, *Result.Context, this)) {
200200
emplaceTransformation(
201201
ReplaceMemberAssignAsSetMethod(BO, ME, FieldName));
202202
} else {
@@ -273,7 +273,7 @@ void GraphicsInteropRule::replaceExtResMemHandleDataExpr(const MemberExpr *ME,
273273
}
274274

275275
requestFeature(HelperFeatureEnum::device_ext);
276-
auto AssignedBO = getParentAsAssignedBO(ME, Context);
276+
auto AssignedBO = getParentAsAssignedBO(ME, Context, this);
277277
if (AssignedBO) {
278278
emplaceTransformation(
279279
ReplaceMemberAssignAsSetMethod(AssignedBO, ME, FieldName));
@@ -328,7 +328,7 @@ void GraphicsInteropRule::replaceExtResSemParamsDataExpr(const MemberExpr *ME,
328328
}
329329

330330
requestFeature(HelperFeatureEnum::device_ext);
331-
auto AssignedBO = getParentAsAssignedBO(ME, Context);
331+
auto AssignedBO = getParentAsAssignedBO(ME, Context, this);
332332
if (AssignedBO) {
333333
emplaceTransformation(
334334
ReplaceMemberAssignAsSetMethod(AssignedBO, ME, FieldName));
@@ -338,48 +338,5 @@ void GraphicsInteropRule::replaceExtResSemParamsDataExpr(const MemberExpr *ME,
338338
}
339339
}
340340

341-
const Expr *GraphicsInteropRule::getParentAsAssignedBO(const Expr *E,
342-
ASTContext &Context) {
343-
auto Parents = Context.getParents(*E);
344-
if (Parents.size() > 0)
345-
return getAssignedBO(Parents[0].get<Expr>(), Context);
346-
return nullptr;
347-
}
348-
349-
// Return the binary operator if E is the lhs of an assign expression, otherwise
350-
// nullptr.
351-
const Expr *GraphicsInteropRule::getAssignedBO(const Expr *E,
352-
ASTContext &Context) {
353-
if (dyn_cast<MemberExpr>(E)) {
354-
// Continue finding parents when E is MemberExpr.
355-
return getParentAsAssignedBO(E, Context);
356-
} else if (auto ICE = dyn_cast<ImplicitCastExpr>(E)) {
357-
// Stop finding parents and return nullptr when E is ImplicitCastExpr,
358-
// except for ArrayToPointerDecay cast.
359-
if (ICE->getCastKind() == CK_ArrayToPointerDecay) {
360-
return getParentAsAssignedBO(E, Context);
361-
}
362-
} else if (auto ASE = dyn_cast<ArraySubscriptExpr>(E)) {
363-
// Continue finding parents when E is ArraySubscriptExpr, and remove
364-
// subscript operator anyway for texture object's member.
365-
emplaceTransformation(new ReplaceToken(
366-
Lexer::getLocForEndOfToken(ASE->getLHS()->getEndLoc(), 0,
367-
Context.getSourceManager(),
368-
Context.getLangOpts()),
369-
ASE->getRBracketLoc(), ""));
370-
return getParentAsAssignedBO(E, Context);
371-
} else if (auto BO = dyn_cast<BinaryOperator>(E)) {
372-
// If E is BinaryOperator, return E only when it is assign expression,
373-
// otherwise return nullptr.
374-
if (BO->getOpcode() == BO_Assign)
375-
return BO;
376-
} else if (auto COCE = dyn_cast<CXXOperatorCallExpr>(E)) {
377-
if (COCE->getOperator() == OO_Equal) {
378-
return COCE;
379-
}
380-
}
381-
return nullptr;
382-
}
383-
384341
} // namespace dpct
385342
} // namespace clang

0 commit comments

Comments
 (0)