Skip to content

Commit 5ae3ffe

Browse files
author
Sunil Kuravinakop
committed
Taking care of feedback comments from Alexey Bataev.
1) Changing comments from // to /// 2) Using STLExtras like llvm::is_contained(). 3) Insteading of combining function comments for 2 functions provided them separately before the function definitions.
1 parent 1703aa6 commit 5ae3ffe

File tree

2 files changed

+47
-50
lines changed

2 files changed

+47
-50
lines changed

clang/lib/Basic/OpenMPKinds.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -623,7 +623,7 @@ bool clang::isOpenMPParallelDirective(OpenMPDirectiveKind DKind) {
623623

624624
bool clang::isOpenMPDispatchDirective(OpenMPDirectiveKind DKind) {
625625
return DKind == OMPD_dispatch ||
626-
llvm::is_contained(getLeafConstructs(DKind), OMPD_target);
626+
llvm::is_contained(getLeafConstructs(DKind), OMPD_dispatch);
627627
}
628628

629629
bool clang::isOpenMPTargetExecutionDirective(OpenMPDirectiveKind DKind) {

clang/lib/Sema/SemaOpenMP.cpp

Lines changed: 46 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -5982,36 +5982,18 @@ static Expr *getInitialExprFromCapturedExpr(Expr *Cond) {
59825982
return nullptr;
59835983
}
59845984

5985-
// Next two functions, cloneAssociatedStmt() &
5986-
// replaceWithNewTraitsOrDirectCall(), are for transforming the call traits.
5987-
// e.g.
5988-
// #pragma omp declare variant(foo_variant_dispatch) match(construct={dispatch})
5989-
// #pragma omp declare variant(foo_variant_allCond) match(user={condition(1)})
5990-
// ..
5991-
// #pragma omp dispatch nocontext(cond_true)
5992-
// foo(i, j);
5993-
// is changed to:
5994-
// if (cond_true) {
5995-
// foo(i,j) // with traits: CodeGen call to foo_variant_allCond(i,j)
5996-
// } else {
5997-
// #pragma omp dispatch
5998-
// foo(i,j) // with traits: CodeGen call to foo_variant_dispatch(i,j)
5999-
// }
6000-
//
6001-
// The next 2 functions, are for:
6002-
// if (cond_true) {
6003-
// foo(i,j) // with traits: runtime call to foo_variant_allCond(i,j)
6004-
// }
6005-
//
60065985
static Expr *replaceWithNewTraitsOrDirectCall(const ASTContext &Context, Expr *,
60075986
SemaOpenMP *, bool);
60085987

5988+
/// cloneAssociatedStmt() function is for cloning the Associated Statement
5989+
/// present with a Directive and then modifying it. By this we avoid modifying
5990+
/// the original Associated Statement.
60095991
static StmtResult cloneAssociatedStmt(const ASTContext &Context, Stmt *StmtP,
60105992
SemaOpenMP *SemaPtr, bool NoContext) {
6011-
if (CapturedStmt *AssocStmt = dyn_cast<CapturedStmt>(StmtP)) {
5993+
if (auto *AssocStmt = dyn_cast<CapturedStmt>(StmtP)) {
60125994
CapturedDecl *CDecl = AssocStmt->getCapturedDecl();
60135995
Stmt *AssocExprStmt = AssocStmt->getCapturedStmt();
6014-
Expr *AssocExpr = dyn_cast<Expr>(AssocExprStmt);
5996+
auto *AssocExpr = dyn_cast<Expr>(AssocExprStmt);
60155997
Expr *NewCallOrPseudoObjOrBinExpr = replaceWithNewTraitsOrDirectCall(
60165998
Context, AssocExpr, SemaPtr, NoContext);
60175999

@@ -6021,21 +6003,21 @@ static StmtResult cloneAssociatedStmt(const ASTContext &Context, Stmt *StmtP,
60216003
CapturedDecl::Create(const_cast<ASTContext &>(Context),
60226004
CDecl->getDeclContext(), CDecl->getNumParams());
60236005
NewDecl->setBody(static_cast<Stmt *>(NewCallOrPseudoObjOrBinExpr));
6024-
for (unsigned i = 0; i < CDecl->getNumParams(); ++i) {
6025-
if (i != CDecl->getContextParamPosition())
6026-
NewDecl->setParam(i, CDecl->getParam(i));
6006+
for (unsigned I : llvm::seq<unsigned>(CDecl->getNumParams())) {
6007+
if (I != CDecl->getContextParamPosition())
6008+
NewDecl->setParam(I, CDecl->getParam(I));
60276009
else
6028-
NewDecl->setContextParam(i, CDecl->getContextParam());
6010+
NewDecl->setContextParam(I, CDecl->getContextParam());
60296011
}
60306012

60316013
// Create a New Captured Stmt containing the New Captured Decl
60326014
SmallVector<CapturedStmt::Capture, 4> Captures;
60336015
SmallVector<Expr *, 4> CaptureInits;
6034-
for (auto capture : AssocStmt->captures())
6035-
Captures.push_back(capture);
6036-
for (auto capture_init : AssocStmt->capture_inits())
6037-
CaptureInits.push_back(capture_init);
6038-
CapturedStmt *NewStmt = CapturedStmt::Create(
6016+
for (const CapturedStmt::Capture &Capture : AssocStmt->captures())
6017+
Captures.push_back(Capture);
6018+
for (Expr *CaptureInit : AssocStmt->capture_inits())
6019+
CaptureInits.push_back(CaptureInit);
6020+
auto *NewStmt = CapturedStmt::Create(
60396021
Context, AssocStmt->getCapturedStmt(),
60406022
AssocStmt->getCapturedRegionKind(), Captures, CaptureInits, NewDecl,
60416023
const_cast<RecordDecl *>(AssocStmt->getCapturedRecordDecl()));
@@ -6045,14 +6027,34 @@ static StmtResult cloneAssociatedStmt(const ASTContext &Context, Stmt *StmtP,
60456027
return static_cast<Stmt *>(nullptr);
60466028
}
60476029

6030+
/// replaceWithNewTraitsOrDirectCall() is for transforming the call traits.
6031+
/// Call traits associated with a function call are removed and replaced with
6032+
/// a direct call. For clause "nocontext" only, the direct call is then
6033+
/// modified to have call traits for a non-dispatch variant.
6034+
/// For "nocontext" an example is provided below for clear understanding.
6035+
///
6036+
/// #pragma omp declare variant(foo_variant_dispatch)
6037+
/// match(construct={dispatch}) #pragma omp declare variant(foo_variant_allCond)
6038+
/// match(user={condition(1)})
6039+
/// ...
6040+
/// #pragma omp dispatch nocontext(cond_true)
6041+
/// foo(i, j); // with traits: CodeGen call to foo_variant_dispatch(i,j)
6042+
/// dispatch construct is changed to:
6043+
/// if (cond_true) {
6044+
/// foo(i,j) // with traits: CodeGen call to foo_variant_allCond(i,j)
6045+
/// } else {
6046+
/// #pragma omp dispatch
6047+
/// foo(i,j) // with traits: CodeGen call to foo_variant_dispatch(i,j)
6048+
/// }
6049+
///
60486050
static Expr *replaceWithNewTraitsOrDirectCall(const ASTContext &Context,
60496051
Expr *AssocExpr,
60506052
SemaOpenMP *SemaPtr,
60516053
bool NoContext) {
60526054
BinaryOperator *BinaryCopyOpr = nullptr;
60536055
bool IsBinaryOp = false;
60546056
Expr *PseudoObjExprOrCall = AssocExpr;
6055-
if (BinaryOperator *BinOprExpr = dyn_cast<BinaryOperator>(AssocExpr)) {
6057+
if (auto *BinOprExpr = dyn_cast<BinaryOperator>(AssocExpr)) {
60566058
IsBinaryOp = true;
60576059
BinaryCopyOpr = BinaryOperator::Create(
60586060
Context, BinOprExpr->getLHS(), BinOprExpr->getRHS(),
@@ -6064,14 +6066,13 @@ static Expr *replaceWithNewTraitsOrDirectCall(const ASTContext &Context,
60646066

60656067
Expr *CallWithoutInvariants = PseudoObjExprOrCall;
60666068
// Change PseudoObjectExpr to a direct call
6067-
if (PseudoObjectExpr *PseudoObjExpr =
6068-
dyn_cast<PseudoObjectExpr>(PseudoObjExprOrCall))
6069+
if (auto *PseudoObjExpr = dyn_cast<PseudoObjectExpr>(PseudoObjExprOrCall))
60696070
CallWithoutInvariants = *((PseudoObjExpr->semantics_begin()) - 1);
60706071

60716072
Expr *FinalCall = CallWithoutInvariants; // For noinvariants clause
60726073
if (NoContext) {
60736074
// Convert StmtResult to a CallExpr before calling ActOnOpenMPCall()
6074-
CallExpr *CallExprWithinStmt = dyn_cast<CallExpr>(CallWithoutInvariants);
6075+
auto *CallExprWithinStmt = cast<CallExpr>(CallWithoutInvariants);
60756076
int NumArgs = CallExprWithinStmt->getNumArgs();
60766077
clang::Expr **Args = CallExprWithinStmt->getArgs();
60776078
// ActOnOpenMPCall() adds traits to a simple function call
@@ -6097,7 +6098,7 @@ static StmtResult combine2Stmts(ASTContext &Context, Stmt *FirstStmt,
60976098
llvm::SmallVector<Stmt *, 2> NewCombinedStmtVector;
60986099
NewCombinedStmtVector.push_back(FirstStmt);
60996100
NewCombinedStmtVector.push_back(SecondStmt);
6100-
CompoundStmt *CombinedStmt = CompoundStmt::Create(
6101+
auto *CombinedStmt = CompoundStmt::Create(
61016102
Context, llvm::ArrayRef<Stmt *>(NewCombinedStmtVector),
61026103
FPOptionsOverride(), SourceLocation(), SourceLocation());
61036104
StmtResult FinalStmts(CombinedStmt);
@@ -6240,14 +6241,11 @@ StmtResult SemaOpenMP::ActOnOpenMPExecutableDirective(
62406241

62416242
if ((Kind == OMPD_dispatch) && (Clauses.size() > 0)) {
62426243

6243-
bool UnSupportedClause = false;
6244-
for (OMPClause *C : Clauses) {
6245-
if (!((C->getClauseKind() == OMPC_novariants) ||
6246-
(C->getClauseKind() == OMPC_nocontext) ||
6247-
(C->getClauseKind() == OMPC_depend)))
6248-
UnSupportedClause = true;
6249-
}
6250-
if (!UnSupportedClause)
6244+
if (llvm::all_of(Clauses, [](OMPClause *C) {
6245+
return llvm::is_contained(
6246+
{OMPC_novariants, OMPC_nocontext, OMPC_depend},
6247+
C->getClauseKind());
6248+
}))
62516249
return transformDispatchDirective(Kind, DirName, CancelRegion, Clauses,
62526250
AStmt, StartLoc, EndLoc);
62536251
}
@@ -7483,7 +7481,6 @@ ExprResult SemaOpenMP::ActOnOpenMPCall(ExprResult Call, Scope *Scope,
74837481
} while (!VMIs.empty());
74847482

74857483
if (!NewCall.isUsable()) {
7486-
fprintf(stdout, "Returning Call, NewCall is not usable\n");
74877484
return Call;
74887485
}
74897486
return PseudoObjectExpr::Create(getASTContext(), CE, {NewCall.get()}, 0);
@@ -10795,11 +10792,11 @@ StmtResult SemaOpenMP::ActOnOpenMPSectionDirective(Stmt *AStmt,
1079510792
DSAStack->isCancelRegion());
1079610793
}
1079710794

10798-
// PseudoObjectExpr is a Trait for dispatch containing the
10799-
// function and its variant. Returning only the function.
10795+
/// PseudoObjectExpr is a Trait for dispatch containing the
10796+
/// function and its variant. Returning only the function.
1080010797
static Expr *RemovePseudoObjectExpr(Expr *PseudoObjExprOrDirectCall) {
1080110798
Expr *DirectCallExpr = PseudoObjExprOrDirectCall;
10802-
if (PseudoObjectExpr *PseudoObjExpr =
10799+
if (auto *PseudoObjExpr =
1080310800
dyn_cast<PseudoObjectExpr>(PseudoObjExprOrDirectCall))
1080410801
DirectCallExpr = *((PseudoObjExpr->semantics_begin()) - 1);
1080510802
return DirectCallExpr;

0 commit comments

Comments
 (0)