mirror of
https://github.com/capstone-engine/llvm-capstone.git
synced 2024-11-23 22:00:10 +00:00
[OpenMP] Initial parsing/sema for the 'omp loop' construct
Adds basic parsing/sema/serialization support for the #pragma omp loop directive. Differential Revision: https://reviews.llvm.org/D112499
This commit is contained in:
parent
66e03db814
commit
6f9c25167d
@ -2596,7 +2596,11 @@ enum CXCursorKind {
|
||||
*/
|
||||
CXCursor_OMPMetaDirective = 294,
|
||||
|
||||
CXCursor_LastStmt = CXCursor_OMPMetaDirective,
|
||||
/** OpenMP loop directive.
|
||||
*/
|
||||
CXCursor_OMPGenericLoopDirective = 295,
|
||||
|
||||
CXCursor_LastStmt = CXCursor_OMPGenericLoopDirective,
|
||||
|
||||
/**
|
||||
* Cursor that represents the translation unit itself.
|
||||
|
@ -3023,6 +3023,9 @@ DEF_TRAVERSE_STMT(OMPDispatchDirective,
|
||||
DEF_TRAVERSE_STMT(OMPMaskedDirective,
|
||||
{ TRY_TO(TraverseOMPExecutableDirective(S)); })
|
||||
|
||||
DEF_TRAVERSE_STMT(OMPGenericLoopDirective,
|
||||
{ TRY_TO(TraverseOMPExecutableDirective(S)); })
|
||||
|
||||
// OpenMP clauses.
|
||||
template <typename Derived>
|
||||
bool RecursiveASTVisitor<Derived>::TraverseOMPClause(OMPClause *C) {
|
||||
|
@ -1144,7 +1144,7 @@ protected:
|
||||
if (isOpenMPLoopBoundSharingDirective(Kind))
|
||||
return CombinedDistributeEnd;
|
||||
if (isOpenMPWorksharingDirective(Kind) || isOpenMPTaskLoopDirective(Kind) ||
|
||||
isOpenMPDistributeDirective(Kind))
|
||||
isOpenMPGenericLoopDirective(Kind) || isOpenMPDistributeDirective(Kind))
|
||||
return WorksharingEnd;
|
||||
return DefaultEnd;
|
||||
}
|
||||
@ -1176,6 +1176,7 @@ protected:
|
||||
}
|
||||
void setIsLastIterVariable(Expr *IL) {
|
||||
assert((isOpenMPWorksharingDirective(getDirectiveKind()) ||
|
||||
isOpenMPGenericLoopDirective(getDirectiveKind()) ||
|
||||
isOpenMPTaskLoopDirective(getDirectiveKind()) ||
|
||||
isOpenMPDistributeDirective(getDirectiveKind())) &&
|
||||
"expected worksharing loop directive");
|
||||
@ -1183,6 +1184,7 @@ protected:
|
||||
}
|
||||
void setLowerBoundVariable(Expr *LB) {
|
||||
assert((isOpenMPWorksharingDirective(getDirectiveKind()) ||
|
||||
isOpenMPGenericLoopDirective(getDirectiveKind()) ||
|
||||
isOpenMPTaskLoopDirective(getDirectiveKind()) ||
|
||||
isOpenMPDistributeDirective(getDirectiveKind())) &&
|
||||
"expected worksharing loop directive");
|
||||
@ -1190,6 +1192,7 @@ protected:
|
||||
}
|
||||
void setUpperBoundVariable(Expr *UB) {
|
||||
assert((isOpenMPWorksharingDirective(getDirectiveKind()) ||
|
||||
isOpenMPGenericLoopDirective(getDirectiveKind()) ||
|
||||
isOpenMPTaskLoopDirective(getDirectiveKind()) ||
|
||||
isOpenMPDistributeDirective(getDirectiveKind())) &&
|
||||
"expected worksharing loop directive");
|
||||
@ -1197,6 +1200,7 @@ protected:
|
||||
}
|
||||
void setStrideVariable(Expr *ST) {
|
||||
assert((isOpenMPWorksharingDirective(getDirectiveKind()) ||
|
||||
isOpenMPGenericLoopDirective(getDirectiveKind()) ||
|
||||
isOpenMPTaskLoopDirective(getDirectiveKind()) ||
|
||||
isOpenMPDistributeDirective(getDirectiveKind())) &&
|
||||
"expected worksharing loop directive");
|
||||
@ -1204,6 +1208,7 @@ protected:
|
||||
}
|
||||
void setEnsureUpperBound(Expr *EUB) {
|
||||
assert((isOpenMPWorksharingDirective(getDirectiveKind()) ||
|
||||
isOpenMPGenericLoopDirective(getDirectiveKind()) ||
|
||||
isOpenMPTaskLoopDirective(getDirectiveKind()) ||
|
||||
isOpenMPDistributeDirective(getDirectiveKind())) &&
|
||||
"expected worksharing loop directive");
|
||||
@ -1211,6 +1216,7 @@ protected:
|
||||
}
|
||||
void setNextLowerBound(Expr *NLB) {
|
||||
assert((isOpenMPWorksharingDirective(getDirectiveKind()) ||
|
||||
isOpenMPGenericLoopDirective(getDirectiveKind()) ||
|
||||
isOpenMPTaskLoopDirective(getDirectiveKind()) ||
|
||||
isOpenMPDistributeDirective(getDirectiveKind())) &&
|
||||
"expected worksharing loop directive");
|
||||
@ -1218,6 +1224,7 @@ protected:
|
||||
}
|
||||
void setNextUpperBound(Expr *NUB) {
|
||||
assert((isOpenMPWorksharingDirective(getDirectiveKind()) ||
|
||||
isOpenMPGenericLoopDirective(getDirectiveKind()) ||
|
||||
isOpenMPTaskLoopDirective(getDirectiveKind()) ||
|
||||
isOpenMPDistributeDirective(getDirectiveKind())) &&
|
||||
"expected worksharing loop directive");
|
||||
@ -1225,6 +1232,7 @@ protected:
|
||||
}
|
||||
void setNumIterations(Expr *NI) {
|
||||
assert((isOpenMPWorksharingDirective(getDirectiveKind()) ||
|
||||
isOpenMPGenericLoopDirective(getDirectiveKind()) ||
|
||||
isOpenMPTaskLoopDirective(getDirectiveKind()) ||
|
||||
isOpenMPDistributeDirective(getDirectiveKind())) &&
|
||||
"expected worksharing loop directive");
|
||||
@ -1327,6 +1335,7 @@ public:
|
||||
Stmt *getPreInits() { return Data->getChildren()[PreInitsOffset]; }
|
||||
Expr *getIsLastIterVariable() const {
|
||||
assert((isOpenMPWorksharingDirective(getDirectiveKind()) ||
|
||||
isOpenMPGenericLoopDirective(getDirectiveKind()) ||
|
||||
isOpenMPTaskLoopDirective(getDirectiveKind()) ||
|
||||
isOpenMPDistributeDirective(getDirectiveKind())) &&
|
||||
"expected worksharing loop directive");
|
||||
@ -1334,6 +1343,7 @@ public:
|
||||
}
|
||||
Expr *getLowerBoundVariable() const {
|
||||
assert((isOpenMPWorksharingDirective(getDirectiveKind()) ||
|
||||
isOpenMPGenericLoopDirective(getDirectiveKind()) ||
|
||||
isOpenMPTaskLoopDirective(getDirectiveKind()) ||
|
||||
isOpenMPDistributeDirective(getDirectiveKind())) &&
|
||||
"expected worksharing loop directive");
|
||||
@ -1341,6 +1351,7 @@ public:
|
||||
}
|
||||
Expr *getUpperBoundVariable() const {
|
||||
assert((isOpenMPWorksharingDirective(getDirectiveKind()) ||
|
||||
isOpenMPGenericLoopDirective(getDirectiveKind()) ||
|
||||
isOpenMPTaskLoopDirective(getDirectiveKind()) ||
|
||||
isOpenMPDistributeDirective(getDirectiveKind())) &&
|
||||
"expected worksharing loop directive");
|
||||
@ -1348,6 +1359,7 @@ public:
|
||||
}
|
||||
Expr *getStrideVariable() const {
|
||||
assert((isOpenMPWorksharingDirective(getDirectiveKind()) ||
|
||||
isOpenMPGenericLoopDirective(getDirectiveKind()) ||
|
||||
isOpenMPTaskLoopDirective(getDirectiveKind()) ||
|
||||
isOpenMPDistributeDirective(getDirectiveKind())) &&
|
||||
"expected worksharing loop directive");
|
||||
@ -1355,6 +1367,7 @@ public:
|
||||
}
|
||||
Expr *getEnsureUpperBound() const {
|
||||
assert((isOpenMPWorksharingDirective(getDirectiveKind()) ||
|
||||
isOpenMPGenericLoopDirective(getDirectiveKind()) ||
|
||||
isOpenMPTaskLoopDirective(getDirectiveKind()) ||
|
||||
isOpenMPDistributeDirective(getDirectiveKind())) &&
|
||||
"expected worksharing loop directive");
|
||||
@ -1362,6 +1375,7 @@ public:
|
||||
}
|
||||
Expr *getNextLowerBound() const {
|
||||
assert((isOpenMPWorksharingDirective(getDirectiveKind()) ||
|
||||
isOpenMPGenericLoopDirective(getDirectiveKind()) ||
|
||||
isOpenMPTaskLoopDirective(getDirectiveKind()) ||
|
||||
isOpenMPDistributeDirective(getDirectiveKind())) &&
|
||||
"expected worksharing loop directive");
|
||||
@ -1369,6 +1383,7 @@ public:
|
||||
}
|
||||
Expr *getNextUpperBound() const {
|
||||
assert((isOpenMPWorksharingDirective(getDirectiveKind()) ||
|
||||
isOpenMPGenericLoopDirective(getDirectiveKind()) ||
|
||||
isOpenMPTaskLoopDirective(getDirectiveKind()) ||
|
||||
isOpenMPDistributeDirective(getDirectiveKind())) &&
|
||||
"expected worksharing loop directive");
|
||||
@ -1376,6 +1391,7 @@ public:
|
||||
}
|
||||
Expr *getNumIterations() const {
|
||||
assert((isOpenMPWorksharingDirective(getDirectiveKind()) ||
|
||||
isOpenMPGenericLoopDirective(getDirectiveKind()) ||
|
||||
isOpenMPTaskLoopDirective(getDirectiveKind()) ||
|
||||
isOpenMPDistributeDirective(getDirectiveKind())) &&
|
||||
"expected worksharing loop directive");
|
||||
@ -1509,6 +1525,7 @@ public:
|
||||
T->getStmtClass() == OMPTaskLoopSimdDirectiveClass ||
|
||||
T->getStmtClass() == OMPMasterTaskLoopDirectiveClass ||
|
||||
T->getStmtClass() == OMPMasterTaskLoopSimdDirectiveClass ||
|
||||
T->getStmtClass() == OMPGenericLoopDirectiveClass ||
|
||||
T->getStmtClass() == OMPParallelMasterTaskLoopDirectiveClass ||
|
||||
T->getStmtClass() == OMPParallelMasterTaskLoopSimdDirectiveClass ||
|
||||
T->getStmtClass() == OMPDistributeDirectiveClass ||
|
||||
@ -5461,6 +5478,69 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
/// This represents '#pragma omp loop' directive.
|
||||
///
|
||||
/// \code
|
||||
/// #pragma omp loop private(a,b) binding(parallel) order(concurrent)
|
||||
/// \endcode
|
||||
/// In this example directive '#pragma omp loop' has
|
||||
/// clauses 'private' with the variables 'a' and 'b', 'binding' with
|
||||
/// modifier 'parallel' and 'order(concurrent).
|
||||
///
|
||||
class OMPGenericLoopDirective final : public OMPLoopDirective {
|
||||
friend class ASTStmtReader;
|
||||
friend class OMPExecutableDirective;
|
||||
/// Build directive with the given start and end location.
|
||||
///
|
||||
/// \param StartLoc Starting location of the directive kind.
|
||||
/// \param EndLoc Ending location of the directive.
|
||||
/// \param CollapsedNum Number of collapsed nested loops.
|
||||
///
|
||||
OMPGenericLoopDirective(SourceLocation StartLoc, SourceLocation EndLoc,
|
||||
unsigned CollapsedNum)
|
||||
: OMPLoopDirective(OMPGenericLoopDirectiveClass, llvm::omp::OMPD_loop,
|
||||
StartLoc, EndLoc, CollapsedNum) {}
|
||||
|
||||
/// Build an empty directive.
|
||||
///
|
||||
/// \param CollapsedNum Number of collapsed nested loops.
|
||||
///
|
||||
explicit OMPGenericLoopDirective(unsigned CollapsedNum)
|
||||
: OMPLoopDirective(OMPGenericLoopDirectiveClass, llvm::omp::OMPD_loop,
|
||||
SourceLocation(), SourceLocation(), CollapsedNum) {}
|
||||
|
||||
public:
|
||||
/// Creates directive with a list of \p Clauses.
|
||||
///
|
||||
/// \param C AST context.
|
||||
/// \param StartLoc Starting location of the directive kind.
|
||||
/// \param EndLoc Ending Location of the directive.
|
||||
/// \param CollapsedNum Number of collapsed loops.
|
||||
/// \param Clauses List of clauses.
|
||||
/// \param AssociatedStmt Statement, associated with the directive.
|
||||
/// \param Exprs Helper expressions for CodeGen.
|
||||
///
|
||||
static OMPGenericLoopDirective *
|
||||
Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc,
|
||||
unsigned CollapsedNum, ArrayRef<OMPClause *> Clauses,
|
||||
Stmt *AssociatedStmt, const HelperExprs &Exprs);
|
||||
|
||||
/// Creates an empty directive with a place for \a NumClauses clauses.
|
||||
///
|
||||
/// \param C AST context.
|
||||
/// \param NumClauses Number of clauses.
|
||||
/// \param CollapsedNum Number of collapsed nested loops.
|
||||
///
|
||||
static OMPGenericLoopDirective *CreateEmpty(const ASTContext &C,
|
||||
unsigned NumClauses,
|
||||
unsigned CollapsedNum,
|
||||
EmptyShell);
|
||||
|
||||
static bool classof(const Stmt *T) {
|
||||
return T->getStmtClass() == OMPGenericLoopDirectiveClass;
|
||||
}
|
||||
};
|
||||
|
||||
} // end namespace clang
|
||||
|
||||
#endif
|
||||
|
@ -10803,6 +10803,9 @@ def note_omp_protected_structured_block
|
||||
: Note<"jump bypasses OpenMP structured block">;
|
||||
def note_omp_exits_structured_block
|
||||
: Note<"jump exits scope of OpenMP structured block">;
|
||||
def err_omp_lastprivate_loop_var_non_loop_iteration : Error<
|
||||
"only loop iteration variables are allowed in 'lastprivate' clause in "
|
||||
"'omp loop' directives">;
|
||||
def err_omp_interop_variable_expected : Error<
|
||||
"expected%select{| non-const}0 variable of type 'omp_interop_t'">;
|
||||
def err_omp_interop_variable_wrong_type : Error<
|
||||
|
@ -253,6 +253,13 @@ bool isOpenMPDistributeDirective(OpenMPDirectiveKind DKind);
|
||||
/// otherwise - false.
|
||||
bool isOpenMPNestingDistributeDirective(OpenMPDirectiveKind DKind);
|
||||
|
||||
/// Checks if the specified directive constitutes a 'loop' directive in the
|
||||
/// outermost nest. For example, 'omp teams loop' or 'omp loop'.
|
||||
/// \param DKind Specified directive.
|
||||
/// \return true - the directive has loop on the outermost nest.
|
||||
/// otherwise - false.
|
||||
bool isOpenMPGenericLoopDirective(OpenMPDirectiveKind DKind);
|
||||
|
||||
/// Checks if the specified clause is one of private clauses like
|
||||
/// 'private', 'firstprivate', 'reduction' etc..
|
||||
/// \param Kind Clause kind.
|
||||
|
@ -282,3 +282,4 @@ def OMPTargetTeamsDistributeSimdDirective : StmtNode<OMPLoopDirective>;
|
||||
def OMPInteropDirective : StmtNode<OMPExecutableDirective>;
|
||||
def OMPDispatchDirective : StmtNode<OMPExecutableDirective>;
|
||||
def OMPMaskedDirective : StmtNode<OMPExecutableDirective>;
|
||||
def OMPGenericLoopDirective : StmtNode<OMPLoopDirective>;
|
||||
|
@ -10940,6 +10940,12 @@ public:
|
||||
Stmt *AStmt, SourceLocation StartLoc,
|
||||
SourceLocation EndLoc);
|
||||
|
||||
/// Called on well-formed '\#pragma omp loop' after parsing of the
|
||||
/// associated statement.
|
||||
StmtResult ActOnOpenMPGenericLoopDirective(
|
||||
ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc,
|
||||
SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA);
|
||||
|
||||
/// Checks correctness of linear modifiers.
|
||||
bool CheckOpenMPLinearModifier(OpenMPLinearClauseKind LinKind,
|
||||
SourceLocation LinLoc);
|
||||
|
@ -1957,6 +1957,7 @@ enum StmtCode {
|
||||
STMT_OMP_INTEROP_DIRECTIVE,
|
||||
STMT_OMP_DISPATCH_DIRECTIVE,
|
||||
STMT_OMP_MASKED_DIRECTIVE,
|
||||
STMT_OMP_GENERIC_LOOP_DIRECTIVE,
|
||||
EXPR_OMP_ARRAY_SECTION,
|
||||
EXPR_OMP_ARRAY_SHAPING,
|
||||
EXPR_OMP_ITERATOR,
|
||||
|
@ -2086,3 +2086,45 @@ OMPMaskedDirective *OMPMaskedDirective::CreateEmpty(const ASTContext &C,
|
||||
return createEmptyDirective<OMPMaskedDirective>(C, NumClauses,
|
||||
/*HasAssociatedStmt=*/true);
|
||||
}
|
||||
|
||||
OMPGenericLoopDirective *OMPGenericLoopDirective::Create(
|
||||
const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc,
|
||||
unsigned CollapsedNum, ArrayRef<OMPClause *> Clauses, Stmt *AssociatedStmt,
|
||||
const HelperExprs &Exprs) {
|
||||
auto *Dir = createDirective<OMPGenericLoopDirective>(
|
||||
C, Clauses, AssociatedStmt, numLoopChildren(CollapsedNum, OMPD_loop),
|
||||
StartLoc, EndLoc, CollapsedNum);
|
||||
Dir->setIterationVariable(Exprs.IterationVarRef);
|
||||
Dir->setLastIteration(Exprs.LastIteration);
|
||||
Dir->setCalcLastIteration(Exprs.CalcLastIteration);
|
||||
Dir->setPreCond(Exprs.PreCond);
|
||||
Dir->setCond(Exprs.Cond);
|
||||
Dir->setInit(Exprs.Init);
|
||||
Dir->setInc(Exprs.Inc);
|
||||
Dir->setIsLastIterVariable(Exprs.IL);
|
||||
Dir->setLowerBoundVariable(Exprs.LB);
|
||||
Dir->setUpperBoundVariable(Exprs.UB);
|
||||
Dir->setStrideVariable(Exprs.ST);
|
||||
Dir->setEnsureUpperBound(Exprs.EUB);
|
||||
Dir->setNextLowerBound(Exprs.NLB);
|
||||
Dir->setNextUpperBound(Exprs.NUB);
|
||||
Dir->setNumIterations(Exprs.NumIterations);
|
||||
Dir->setCounters(Exprs.Counters);
|
||||
Dir->setPrivateCounters(Exprs.PrivateCounters);
|
||||
Dir->setInits(Exprs.Inits);
|
||||
Dir->setUpdates(Exprs.Updates);
|
||||
Dir->setFinals(Exprs.Finals);
|
||||
Dir->setDependentCounters(Exprs.DependentCounters);
|
||||
Dir->setDependentInits(Exprs.DependentInits);
|
||||
Dir->setFinalsConditions(Exprs.FinalsConditions);
|
||||
Dir->setPreInits(Exprs.PreInits);
|
||||
return Dir;
|
||||
}
|
||||
|
||||
OMPGenericLoopDirective *
|
||||
OMPGenericLoopDirective::CreateEmpty(const ASTContext &C, unsigned NumClauses,
|
||||
unsigned CollapsedNum, EmptyShell) {
|
||||
return createEmptyDirective<OMPGenericLoopDirective>(
|
||||
C, NumClauses, /*HasAssociatedStmt=*/true,
|
||||
numLoopChildren(CollapsedNum, OMPD_loop), CollapsedNum);
|
||||
}
|
||||
|
@ -1000,6 +1000,11 @@ void StmtPrinter::VisitOMPMaskedDirective(OMPMaskedDirective *Node) {
|
||||
PrintOMPExecutableDirective(Node);
|
||||
}
|
||||
|
||||
void StmtPrinter::VisitOMPGenericLoopDirective(OMPGenericLoopDirective *Node) {
|
||||
Indent() << "#pragma omp loop";
|
||||
PrintOMPExecutableDirective(Node);
|
||||
}
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
// Expr printing methods.
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
@ -1190,6 +1190,11 @@ void StmtProfiler::VisitOMPMaskedDirective(const OMPMaskedDirective *S) {
|
||||
VisitOMPExecutableDirective(S);
|
||||
}
|
||||
|
||||
void StmtProfiler::VisitOMPGenericLoopDirective(
|
||||
const OMPGenericLoopDirective *S) {
|
||||
VisitOMPLoopDirective(S);
|
||||
}
|
||||
|
||||
void StmtProfiler::VisitExpr(const Expr *S) {
|
||||
VisitStmt(S);
|
||||
}
|
||||
|
@ -474,7 +474,7 @@ bool clang::isOpenMPLoopDirective(OpenMPDirectiveKind DKind) {
|
||||
DKind == OMPD_target_teams_distribute_parallel_for ||
|
||||
DKind == OMPD_target_teams_distribute_parallel_for_simd ||
|
||||
DKind == OMPD_target_teams_distribute_simd || DKind == OMPD_tile ||
|
||||
DKind == OMPD_unroll;
|
||||
DKind == OMPD_unroll || DKind == OMPD_loop;
|
||||
}
|
||||
|
||||
bool clang::isOpenMPWorksharingDirective(OpenMPDirectiveKind DKind) {
|
||||
@ -577,6 +577,10 @@ bool clang::isOpenMPDistributeDirective(OpenMPDirectiveKind Kind) {
|
||||
Kind == OMPD_target_teams_distribute_simd;
|
||||
}
|
||||
|
||||
bool clang::isOpenMPGenericLoopDirective(OpenMPDirectiveKind Kind) {
|
||||
return Kind == OMPD_loop;
|
||||
}
|
||||
|
||||
bool clang::isOpenMPPrivate(OpenMPClauseKind Kind) {
|
||||
return Kind == OMPC_private || Kind == OMPC_firstprivate ||
|
||||
Kind == OMPC_lastprivate || Kind == OMPC_linear ||
|
||||
@ -675,6 +679,10 @@ void clang::getOpenMPCaptureRegions(
|
||||
CaptureRegions.push_back(OMPD_teams);
|
||||
CaptureRegions.push_back(OMPD_parallel);
|
||||
break;
|
||||
case OMPD_loop:
|
||||
// TODO: 'loop' may require different capture regions depending on the bind
|
||||
// clause or the parent directive when there is no bind clause. Use
|
||||
// OMPD_unknown for now.
|
||||
case OMPD_simd:
|
||||
case OMPD_for:
|
||||
case OMPD_for_simd:
|
||||
|
@ -393,6 +393,9 @@ void CodeGenFunction::EmitStmt(const Stmt *S, ArrayRef<const Attr *> Attrs) {
|
||||
case Stmt::OMPMaskedDirectiveClass:
|
||||
EmitOMPMaskedDirective(cast<OMPMaskedDirective>(*S));
|
||||
break;
|
||||
case Stmt::OMPGenericLoopDirectiveClass:
|
||||
EmitOMPGenericLoopDirective(cast<OMPGenericLoopDirective>(*S));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -7239,6 +7239,16 @@ void CodeGenFunction::EmitOMPTargetUpdateDirective(
|
||||
CGM.getOpenMPRuntime().emitTargetDataStandAloneCall(*this, S, IfCond, Device);
|
||||
}
|
||||
|
||||
void CodeGenFunction::EmitOMPGenericLoopDirective(
|
||||
const OMPGenericLoopDirective &S) {
|
||||
// Unimplemented, just inline the underlying statement for now.
|
||||
auto &&CodeGen = [&S](CodeGenFunction &CGF, PrePostActionTy &Action) {
|
||||
CGF.EmitStmt(cast<CapturedStmt>(S.getAssociatedStmt())->getCapturedStmt());
|
||||
};
|
||||
OMPLexicalScope Scope(*this, S, OMPD_unknown);
|
||||
CGM.getOpenMPRuntime().emitInlinedDirective(*this, OMPD_loop, CodeGen);
|
||||
}
|
||||
|
||||
void CodeGenFunction::EmitSimpleOMPExecutableDirective(
|
||||
const OMPExecutableDirective &D) {
|
||||
if (const auto *SD = dyn_cast<OMPScanDirective>(&D)) {
|
||||
|
@ -3529,6 +3529,7 @@ public:
|
||||
const OMPTargetTeamsDistributeParallelForSimdDirective &S);
|
||||
void EmitOMPTargetTeamsDistributeSimdDirective(
|
||||
const OMPTargetTeamsDistributeSimdDirective &S);
|
||||
void EmitOMPGenericLoopDirective(const OMPGenericLoopDirective &S);
|
||||
|
||||
/// Emit device code for the target directive.
|
||||
static void EmitOMPTargetDeviceFunction(CodeGenModule &CGM,
|
||||
|
@ -2375,6 +2375,7 @@ Parser::DeclGroupPtrTy Parser::ParseOpenMPDeclarativeDirectiveWithExtDecl(
|
||||
case OMPD_dispatch:
|
||||
case OMPD_masked:
|
||||
case OMPD_metadirective:
|
||||
case OMPD_loop:
|
||||
Diag(Tok, diag::err_omp_unexpected_directive)
|
||||
<< 1 << getOpenMPDirectiveName(DKind);
|
||||
break;
|
||||
@ -2724,6 +2725,7 @@ Parser::ParseOpenMPDeclarativeOrExecutableDirective(ParsedStmtContext StmtCtx) {
|
||||
case OMPD_target_data:
|
||||
case OMPD_target_parallel:
|
||||
case OMPD_target_parallel_for:
|
||||
case OMPD_loop:
|
||||
case OMPD_taskloop:
|
||||
case OMPD_taskloop_simd:
|
||||
case OMPD_master_taskloop:
|
||||
|
@ -1497,6 +1497,7 @@ CanThrowResult Sema::canThrow(const Stmt *S) {
|
||||
case Stmt::OMPDispatchDirectiveClass:
|
||||
case Stmt::OMPMaskedDirectiveClass:
|
||||
case Stmt::OMPMetaDirectiveClass:
|
||||
case Stmt::OMPGenericLoopDirectiveClass:
|
||||
case Stmt::ReturnStmtClass:
|
||||
case Stmt::SEHExceptStmtClass:
|
||||
case Stmt::SEHFinallyStmtClass:
|
||||
|
@ -4013,6 +4013,9 @@ void Sema::ActOnOpenMPRegionStart(OpenMPDirectiveKind DKind, Scope *CurScope) {
|
||||
case OMPD_tile:
|
||||
case OMPD_unroll:
|
||||
break;
|
||||
case OMPD_loop:
|
||||
// TODO: 'loop' may require additional parameters depending on the binding.
|
||||
// Treat similar to OMPD_simd/OMPD_for for now.
|
||||
case OMPD_simd:
|
||||
case OMPD_for:
|
||||
case OMPD_for_simd:
|
||||
@ -4788,6 +4791,7 @@ static bool checkNestingOfRegions(Sema &SemaRef, const DSAStackTy *Stack,
|
||||
// A masked region may not be closely nested inside a worksharing, loop,
|
||||
// atomic, task, or taskloop region.
|
||||
NestingProhibited = isOpenMPWorksharingDirective(ParentRegion) ||
|
||||
isOpenMPGenericLoopDirective(ParentRegion) ||
|
||||
isOpenMPTaskingDirective(ParentRegion);
|
||||
} else if (CurrentRegion == OMPD_critical && CurrentName.getName()) {
|
||||
// OpenMP [2.16, Nesting of Regions]
|
||||
@ -4821,6 +4825,7 @@ static bool checkNestingOfRegions(Sema &SemaRef, const DSAStackTy *Stack,
|
||||
// task, taskloop, critical, ordered, atomic, or masked region.
|
||||
NestingProhibited =
|
||||
isOpenMPWorksharingDirective(ParentRegion) ||
|
||||
isOpenMPGenericLoopDirective(ParentRegion) ||
|
||||
isOpenMPTaskingDirective(ParentRegion) ||
|
||||
ParentRegion == OMPD_master || ParentRegion == OMPD_masked ||
|
||||
ParentRegion == OMPD_parallel_master ||
|
||||
@ -4834,6 +4839,7 @@ static bool checkNestingOfRegions(Sema &SemaRef, const DSAStackTy *Stack,
|
||||
// critical, ordered, atomic, or masked region.
|
||||
NestingProhibited =
|
||||
isOpenMPWorksharingDirective(ParentRegion) ||
|
||||
isOpenMPGenericLoopDirective(ParentRegion) ||
|
||||
isOpenMPTaskingDirective(ParentRegion) ||
|
||||
ParentRegion == OMPD_master || ParentRegion == OMPD_masked ||
|
||||
ParentRegion == OMPD_parallel_master ||
|
||||
@ -4879,12 +4885,16 @@ static bool checkNestingOfRegions(Sema &SemaRef, const DSAStackTy *Stack,
|
||||
!isOpenMPTargetExecutionDirective(CurrentRegion) &&
|
||||
!isOpenMPTargetDataManagementDirective(CurrentRegion) &&
|
||||
(ParentRegion == OMPD_teams || ParentRegion == OMPD_target_teams)) {
|
||||
// OpenMP [2.16, Nesting of Regions]
|
||||
// distribute, parallel, parallel sections, parallel workshare, and the
|
||||
// parallel loop and parallel loop SIMD constructs are the only OpenMP
|
||||
// constructs that can be closely nested in the teams region.
|
||||
// OpenMP [5.1, 2.22, Nesting of Regions]
|
||||
// distribute, distribute simd, distribute parallel worksharing-loop,
|
||||
// distribute parallel worksharing-loop SIMD, loop, parallel regions,
|
||||
// including any parallel regions arising from combined constructs,
|
||||
// omp_get_num_teams() regions, and omp_get_team_num() regions are the
|
||||
// only OpenMP regions that may be strictly nested inside the teams
|
||||
// region.
|
||||
NestingProhibited = !isOpenMPParallelDirective(CurrentRegion) &&
|
||||
!isOpenMPDistributeDirective(CurrentRegion);
|
||||
!isOpenMPDistributeDirective(CurrentRegion) &&
|
||||
CurrentRegion != OMPD_loop;
|
||||
Recommend = ShouldBeInParallelRegion;
|
||||
}
|
||||
if (!NestingProhibited &&
|
||||
@ -6231,6 +6241,10 @@ StmtResult Sema::ActOnOpenMPExecutableDirective(
|
||||
Res = ActOnOpenMPDispatchDirective(ClausesWithImplicit, AStmt, StartLoc,
|
||||
EndLoc);
|
||||
break;
|
||||
case OMPD_loop:
|
||||
Res = ActOnOpenMPGenericLoopDirective(ClausesWithImplicit, AStmt, StartLoc,
|
||||
EndLoc, VarsWithInheritedDSA);
|
||||
break;
|
||||
case OMPD_declare_target:
|
||||
case OMPD_end_declare_target:
|
||||
case OMPD_threadprivate:
|
||||
@ -8817,6 +8831,7 @@ static bool checkOpenMPIterationSpace(
|
||||
ResultIterSpaces[CurrentNestedLoopCount].NumIterations =
|
||||
ISC.buildNumIterations(DSA.getCurScope(), ResultIterSpaces,
|
||||
(isOpenMPWorksharingDirective(DKind) ||
|
||||
isOpenMPGenericLoopDirective(DKind) ||
|
||||
isOpenMPTaskLoopDirective(DKind) ||
|
||||
isOpenMPDistributeDirective(DKind) ||
|
||||
isOpenMPLoopTransformationDirective(DKind)),
|
||||
@ -9300,6 +9315,7 @@ checkOpenMPLoop(OpenMPDirectiveKind DKind, Expr *CollapseLoopCountExpr,
|
||||
ExprResult LB, UB, IL, ST, EUB, CombLB, CombUB, PrevLB, PrevUB, CombEUB;
|
||||
if (isOpenMPWorksharingDirective(DKind) || isOpenMPTaskLoopDirective(DKind) ||
|
||||
isOpenMPDistributeDirective(DKind) ||
|
||||
isOpenMPGenericLoopDirective(DKind) ||
|
||||
isOpenMPLoopTransformationDirective(DKind)) {
|
||||
// Lower bound variable, initialized with zero.
|
||||
VarDecl *LBDecl = buildVarDecl(SemaRef, InitLoc, VType, ".omp.lb");
|
||||
@ -9399,6 +9415,7 @@ checkOpenMPLoop(OpenMPDirectiveKind DKind, Expr *CollapseLoopCountExpr,
|
||||
VarDecl *IVDecl = buildVarDecl(SemaRef, InitLoc, RealVType, ".omp.iv");
|
||||
IV = buildDeclRefExpr(SemaRef, IVDecl, RealVType, InitLoc);
|
||||
Expr *RHS = (isOpenMPWorksharingDirective(DKind) ||
|
||||
isOpenMPGenericLoopDirective(DKind) ||
|
||||
isOpenMPTaskLoopDirective(DKind) ||
|
||||
isOpenMPDistributeDirective(DKind) ||
|
||||
isOpenMPLoopTransformationDirective(DKind))
|
||||
@ -9410,6 +9427,7 @@ checkOpenMPLoop(OpenMPDirectiveKind DKind, Expr *CollapseLoopCountExpr,
|
||||
if (isOpenMPLoopBoundSharingDirective(DKind)) {
|
||||
Expr *CombRHS =
|
||||
(isOpenMPWorksharingDirective(DKind) ||
|
||||
isOpenMPGenericLoopDirective(DKind) ||
|
||||
isOpenMPTaskLoopDirective(DKind) ||
|
||||
isOpenMPDistributeDirective(DKind))
|
||||
? CombLB.get()
|
||||
@ -9441,6 +9459,7 @@ checkOpenMPLoop(OpenMPDirectiveKind DKind, Expr *CollapseLoopCountExpr,
|
||||
}
|
||||
ExprResult Cond =
|
||||
(isOpenMPWorksharingDirective(DKind) ||
|
||||
isOpenMPGenericLoopDirective(DKind) ||
|
||||
isOpenMPTaskLoopDirective(DKind) || isOpenMPDistributeDirective(DKind) ||
|
||||
isOpenMPLoopTransformationDirective(DKind))
|
||||
? SemaRef.BuildBinOp(CurScope, CondLoc,
|
||||
@ -9490,6 +9509,7 @@ checkOpenMPLoop(OpenMPDirectiveKind DKind, Expr *CollapseLoopCountExpr,
|
||||
// base variables for the update
|
||||
ExprResult NextLB, NextUB, CombNextLB, CombNextUB;
|
||||
if (isOpenMPWorksharingDirective(DKind) || isOpenMPTaskLoopDirective(DKind) ||
|
||||
isOpenMPGenericLoopDirective(DKind) ||
|
||||
isOpenMPDistributeDirective(DKind) ||
|
||||
isOpenMPLoopTransformationDirective(DKind)) {
|
||||
// LB + ST
|
||||
@ -10044,6 +10064,57 @@ StmtResult Sema::ActOnOpenMPDispatchDirective(ArrayRef<OMPClause *> Clauses,
|
||||
TargetCallLoc);
|
||||
}
|
||||
|
||||
StmtResult Sema::ActOnOpenMPGenericLoopDirective(
|
||||
ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc,
|
||||
SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA) {
|
||||
if (!AStmt)
|
||||
return StmtError();
|
||||
|
||||
// OpenMP 5.1 [2.11.7, loop construct]
|
||||
// A list item may not appear in a lastprivate clause unless it is the
|
||||
// loop iteration variable of a loop that is associated with the construct.
|
||||
for (OMPClause *C : Clauses) {
|
||||
if (auto *LPC = dyn_cast<OMPLastprivateClause>(C)) {
|
||||
for (Expr *RefExpr : LPC->varlists()) {
|
||||
SourceLocation ELoc;
|
||||
SourceRange ERange;
|
||||
Expr *SimpleRefExpr = RefExpr;
|
||||
auto Res = getPrivateItem(*this, SimpleRefExpr, ELoc, ERange);
|
||||
if (ValueDecl *D = Res.first) {
|
||||
auto &&Info = DSAStack->isLoopControlVariable(D);
|
||||
if (!Info.first) {
|
||||
Diag(ELoc, diag::err_omp_lastprivate_loop_var_non_loop_iteration);
|
||||
return StmtError();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
auto *CS = cast<CapturedStmt>(AStmt);
|
||||
// 1.2.2 OpenMP Language Terminology
|
||||
// Structured block - An executable statement with a single entry at the
|
||||
// top and a single exit at the bottom.
|
||||
// The point of exit cannot be a branch out of the structured block.
|
||||
// longjmp() and throw() must not violate the entry/exit criteria.
|
||||
CS->getCapturedDecl()->setNothrow();
|
||||
|
||||
OMPLoopDirective::HelperExprs B;
|
||||
// In presence of clause 'collapse', it will define the nested loops number.
|
||||
unsigned NestedLoopCount = checkOpenMPLoop(
|
||||
OMPD_loop, getCollapseNumberExpr(Clauses), getOrderedNumberExpr(Clauses),
|
||||
AStmt, *this, *DSAStack, VarsWithImplicitDSA, B);
|
||||
if (NestedLoopCount == 0)
|
||||
return StmtError();
|
||||
|
||||
assert((CurContext->isDependentContext() || B.builtAll()) &&
|
||||
"omp loop exprs were not built");
|
||||
|
||||
setFunctionHasBranchProtectedScope();
|
||||
return OMPGenericLoopDirective::Create(Context, StartLoc, EndLoc,
|
||||
NestedLoopCount, Clauses, AStmt, B);
|
||||
}
|
||||
|
||||
StmtResult Sema::ActOnOpenMPSingleDirective(ArrayRef<OMPClause *> Clauses,
|
||||
Stmt *AStmt,
|
||||
SourceLocation StartLoc,
|
||||
@ -13529,6 +13600,7 @@ static OpenMPDirectiveKind getOpenMPCaptureRegionForClause(
|
||||
case OMPD_end_declare_variant:
|
||||
case OMPD_declare_target:
|
||||
case OMPD_end_declare_target:
|
||||
case OMPD_loop:
|
||||
case OMPD_teams:
|
||||
case OMPD_tile:
|
||||
case OMPD_unroll:
|
||||
@ -13608,6 +13680,7 @@ static OpenMPDirectiveKind getOpenMPCaptureRegionForClause(
|
||||
case OMPD_end_declare_variant:
|
||||
case OMPD_declare_target:
|
||||
case OMPD_end_declare_target:
|
||||
case OMPD_loop:
|
||||
case OMPD_teams:
|
||||
case OMPD_simd:
|
||||
case OMPD_tile:
|
||||
@ -13692,6 +13765,7 @@ static OpenMPDirectiveKind getOpenMPCaptureRegionForClause(
|
||||
case OMPD_end_declare_variant:
|
||||
case OMPD_declare_target:
|
||||
case OMPD_end_declare_target:
|
||||
case OMPD_loop:
|
||||
case OMPD_simd:
|
||||
case OMPD_tile:
|
||||
case OMPD_unroll:
|
||||
@ -13773,6 +13847,7 @@ static OpenMPDirectiveKind getOpenMPCaptureRegionForClause(
|
||||
case OMPD_end_declare_variant:
|
||||
case OMPD_declare_target:
|
||||
case OMPD_end_declare_target:
|
||||
case OMPD_loop:
|
||||
case OMPD_simd:
|
||||
case OMPD_tile:
|
||||
case OMPD_unroll:
|
||||
@ -13855,6 +13930,7 @@ static OpenMPDirectiveKind getOpenMPCaptureRegionForClause(
|
||||
case OMPD_end_declare_variant:
|
||||
case OMPD_declare_target:
|
||||
case OMPD_end_declare_target:
|
||||
case OMPD_loop:
|
||||
case OMPD_simd:
|
||||
case OMPD_tile:
|
||||
case OMPD_unroll:
|
||||
@ -13936,6 +14012,7 @@ static OpenMPDirectiveKind getOpenMPCaptureRegionForClause(
|
||||
case OMPD_end_declare_variant:
|
||||
case OMPD_declare_target:
|
||||
case OMPD_end_declare_target:
|
||||
case OMPD_loop:
|
||||
case OMPD_simd:
|
||||
case OMPD_tile:
|
||||
case OMPD_unroll:
|
||||
@ -14018,6 +14095,7 @@ static OpenMPDirectiveKind getOpenMPCaptureRegionForClause(
|
||||
case OMPD_end_declare_variant:
|
||||
case OMPD_declare_target:
|
||||
case OMPD_end_declare_target:
|
||||
case OMPD_loop:
|
||||
case OMPD_simd:
|
||||
case OMPD_tile:
|
||||
case OMPD_unroll:
|
||||
@ -14101,6 +14179,7 @@ static OpenMPDirectiveKind getOpenMPCaptureRegionForClause(
|
||||
case OMPD_end_declare_variant:
|
||||
case OMPD_declare_target:
|
||||
case OMPD_end_declare_target:
|
||||
case OMPD_loop:
|
||||
case OMPD_simd:
|
||||
case OMPD_tile:
|
||||
case OMPD_unroll:
|
||||
|
@ -9172,6 +9172,17 @@ TreeTransform<Derived>::TransformOMPMaskedDirective(OMPMaskedDirective *D) {
|
||||
return Res;
|
||||
}
|
||||
|
||||
template <typename Derived>
|
||||
StmtResult TreeTransform<Derived>::TransformOMPGenericLoopDirective(
|
||||
OMPGenericLoopDirective *D) {
|
||||
DeclarationNameInfo DirName;
|
||||
getDerived().getSema().StartOpenMPDSABlock(OMPD_loop, DirName, nullptr,
|
||||
D->getBeginLoc());
|
||||
StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
|
||||
getDerived().getSema().EndOpenMPDSABlock(Res.get());
|
||||
return Res;
|
||||
}
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
// OpenMP clause transformation
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
@ -2632,6 +2632,10 @@ void ASTStmtReader::VisitOMPMaskedDirective(OMPMaskedDirective *D) {
|
||||
VisitOMPExecutableDirective(D);
|
||||
}
|
||||
|
||||
void ASTStmtReader::VisitOMPGenericLoopDirective(OMPGenericLoopDirective *D) {
|
||||
VisitOMPLoopDirective(D);
|
||||
}
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
// ASTReader Implementation
|
||||
//===----------------------------------------------------------------------===//
|
||||
@ -3578,6 +3582,14 @@ Stmt *ASTReader::ReadStmtFromStream(ModuleFile &F) {
|
||||
Context, Record[ASTStmtReader::NumStmtFields], Empty);
|
||||
break;
|
||||
|
||||
case STMT_OMP_GENERIC_LOOP_DIRECTIVE: {
|
||||
unsigned CollapsedNum = Record[ASTStmtReader::NumStmtFields];
|
||||
unsigned NumClauses = Record[ASTStmtReader::NumStmtFields + 1];
|
||||
S = OMPGenericLoopDirective::CreateEmpty(Context, NumClauses,
|
||||
CollapsedNum, Empty);
|
||||
break;
|
||||
}
|
||||
|
||||
case EXPR_CXX_OPERATOR_CALL:
|
||||
S = CXXOperatorCallExpr::CreateEmpty(
|
||||
Context, /*NumArgs=*/Record[ASTStmtReader::NumExprFields],
|
||||
|
@ -2589,6 +2589,11 @@ void ASTStmtWriter::VisitOMPMaskedDirective(OMPMaskedDirective *D) {
|
||||
Code = serialization::STMT_OMP_MASKED_DIRECTIVE;
|
||||
}
|
||||
|
||||
void ASTStmtWriter::VisitOMPGenericLoopDirective(OMPGenericLoopDirective *D) {
|
||||
VisitOMPLoopDirective(D);
|
||||
Code = serialization::STMT_OMP_GENERIC_LOOP_DIRECTIVE;
|
||||
}
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
// ASTWriter Implementation
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
@ -1297,6 +1297,7 @@ void ExprEngine::Visit(const Stmt *S, ExplodedNode *Pred,
|
||||
case Stmt::OMPInteropDirectiveClass:
|
||||
case Stmt::OMPDispatchDirectiveClass:
|
||||
case Stmt::OMPMaskedDirectiveClass:
|
||||
case Stmt::OMPGenericLoopDirectiveClass:
|
||||
case Stmt::CapturedStmtClass:
|
||||
case Stmt::OMPUnrollDirectiveClass:
|
||||
case Stmt::OMPMetaDirectiveClass: {
|
||||
|
141
clang/test/OpenMP/generic_loop_ast_print.cpp
Normal file
141
clang/test/OpenMP/generic_loop_ast_print.cpp
Normal file
@ -0,0 +1,141 @@
|
||||
// RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -fopenmp -fopenmp-version=51 \
|
||||
// RUN: -fsyntax-only -verify %s
|
||||
|
||||
// expected-no-diagnostics
|
||||
|
||||
// RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -fopenmp -fopenmp-version=51 \
|
||||
// RUN: -ast-print %s | FileCheck %s --check-prefix=PRINT
|
||||
|
||||
// RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -fopenmp -fopenmp-version=51 \
|
||||
// RUN: -ast-dump %s | FileCheck %s --check-prefix=DUMP
|
||||
|
||||
// RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -fopenmp -fopenmp-version=51 \
|
||||
// RUN: -emit-pch -o %t %s
|
||||
|
||||
// RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -fopenmp -fopenmp-version=51 \
|
||||
// RUN: -include-pch %t -ast-dump-all %s | FileCheck %s --check-prefix=DUMP
|
||||
|
||||
// RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -fopenmp -fopenmp-version=51 \
|
||||
// RUN: -include-pch %t -ast-print %s | FileCheck %s --check-prefix=PRINT
|
||||
|
||||
#ifndef HEADER
|
||||
#define HEADER
|
||||
|
||||
//PRINT: template <typename T, int C> void templ_foo(T t) {
|
||||
//PRINT: T j, z;
|
||||
//PRINT: #pragma omp loop collapse(C) reduction(+: z) lastprivate(j)
|
||||
//PRINT: for (T i = 0; i < t; ++i)
|
||||
//PRINT: for (j = 0; j < t; ++j)
|
||||
//PRINT: z += i + j;
|
||||
//PRINT: }
|
||||
//DUMP: FunctionTemplateDecl{{.*}}templ_foo
|
||||
//DUMP: TemplateTypeParmDecl{{.*}}T
|
||||
//DUMP: NonTypeTemplateParmDecl{{.*}}C
|
||||
//DUMP: OMPGenericLoopDirective
|
||||
//DUMP: OMPCollapseClause
|
||||
//DUMP: DeclRefExpr{{.*}}'C' 'int'
|
||||
//DUMP: OMPReductionClause
|
||||
//DUMP: DeclRefExpr{{.*}}'z' 'T'
|
||||
//DUMP: OMPLastprivateClause
|
||||
//DUMP: DeclRefExpr{{.*}}'j' 'T'
|
||||
//DUMP: ForStmt
|
||||
//DUMP: ForStmt
|
||||
|
||||
//PRINT: template<> void templ_foo<int, 2>(int t) {
|
||||
//PRINT: int j, z;
|
||||
//PRINT: #pragma omp loop collapse(2) reduction(+: z) lastprivate(j)
|
||||
//PRINT: for (int i = 0; i < t; ++i)
|
||||
//PRINT: for (j = 0; j < t; ++j)
|
||||
//PRINT: z += i + j;
|
||||
//PRINT: }
|
||||
//DUMP: FunctionDecl{{.*}}templ_foo 'void (int)'
|
||||
//DUMP: TemplateArgument type 'int'
|
||||
//DUMP: TemplateArgument integral 2
|
||||
//DUMP: ParmVarDecl{{.*}}'int':'int'
|
||||
//DUMP: OMPGenericLoopDirective
|
||||
//DUMP: OMPCollapseClause
|
||||
//DUMP: ConstantExpr{{.*}}'int'
|
||||
//DUMP: value: Int 2
|
||||
//DUMP: OMPReductionClause
|
||||
//DUMP: DeclRefExpr{{.*}}'z' 'int':'int'
|
||||
//DUMP: OMPLastprivateClause
|
||||
//DUMP: DeclRefExpr{{.*}}'j' 'int':'int'
|
||||
//DUMP: ForStmt
|
||||
template <typename T, int C>
|
||||
void templ_foo(T t) {
|
||||
|
||||
T j,z;
|
||||
#pragma omp loop collapse(C) reduction(+:z) lastprivate(j)
|
||||
for (T i = 0; i<t; ++i)
|
||||
for (j = 0; j<t; ++j)
|
||||
z += i+j;
|
||||
}
|
||||
|
||||
|
||||
//PRINT: void test() {
|
||||
//DUMP: FunctionDecl {{.*}}test 'void ()'
|
||||
void test() {
|
||||
constexpr int N = 100;
|
||||
float MTX[N][N];
|
||||
int aaa[1000];
|
||||
|
||||
//PRINT: #pragma omp target teams distribute parallel for map(tofrom: MTX)
|
||||
//PRINT: #pragma omp loop
|
||||
//DUMP: OMPTargetTeamsDistributeParallelForDirective
|
||||
//DUMP: CapturedStmt
|
||||
//DUMP: ForStmt
|
||||
//DUMP: CompoundStmt
|
||||
//DUMP: OMPGenericLoopDirective
|
||||
#pragma omp target teams distribute parallel for map(MTX)
|
||||
for (auto i = 0; i < N; ++i) {
|
||||
#pragma omp loop
|
||||
for (auto j = 0; j < N; ++j) {
|
||||
MTX[i][j] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
//PRINT: #pragma omp target teams
|
||||
//PRINT: #pragma omp loop
|
||||
//DUMP: OMPTargetTeamsDirective
|
||||
//DUMP: CapturedStmt
|
||||
//DUMP: ForStmt
|
||||
//DUMP: OMPGenericLoopDirective
|
||||
#pragma omp target teams
|
||||
for (int i=0; i<1000; ++i) {
|
||||
#pragma omp loop
|
||||
for (int j=0; j<100; j++) {
|
||||
aaa[i] += i + j;
|
||||
}
|
||||
}
|
||||
|
||||
int j, z, z1;
|
||||
//PRINT: #pragma omp loop collapse(2) private(z) lastprivate(j) order(concurrent) reduction(+: z1)
|
||||
//DUMP: OMPGenericLoopDirective
|
||||
//DUMP: OMPCollapseClause
|
||||
//DUMP: IntegerLiteral{{.*}}2
|
||||
//DUMP: OMPPrivateClause
|
||||
//DUMP-NEXT: DeclRefExpr{{.*}}'z'
|
||||
//DUMP: OMPLastprivateClause
|
||||
//DUMP-NEXT: DeclRefExpr{{.*}}'j'
|
||||
//DUMP: OMPOrderClause
|
||||
//DUMP: OMPReductionClause
|
||||
//DUMP-NEXT: DeclRefExpr{{.*}}'z1'
|
||||
//DUMP: ForStmt
|
||||
//DUMP: ForStmt
|
||||
#pragma omp loop collapse(2) private(z) lastprivate(j) order(concurrent) \
|
||||
reduction(+:z1)
|
||||
for (auto i = 0; i < N; ++i) {
|
||||
for (j = 0; j < N; ++j) {
|
||||
z = i+j;
|
||||
MTX[i][j] = z;
|
||||
z1 += z;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void bar()
|
||||
{
|
||||
templ_foo<int,2>(8);
|
||||
}
|
||||
|
||||
#endif // HEADER
|
133
clang/test/OpenMP/generic_loop_messages.cpp
Normal file
133
clang/test/OpenMP/generic_loop_messages.cpp
Normal file
@ -0,0 +1,133 @@
|
||||
// RUN: %clang_cc1 -verify -fopenmp -fopenmp-version=51 -Wuninitialized %s
|
||||
|
||||
void foo()
|
||||
{
|
||||
int i,j,k;
|
||||
int z;
|
||||
|
||||
// expected-error@+2 {{statement after '#pragma omp loop' must be a for loop}}
|
||||
#pragma omp loop
|
||||
i = 0;
|
||||
|
||||
// OpenMP 5.1 [2.22 Nesting of regions]
|
||||
//
|
||||
// A barrier region may not be closely nested inside a worksharing, loop,
|
||||
// task, taskloop, critical, ordered, atomic, or masked region.
|
||||
|
||||
// expected-error@+3 {{region cannot be closely nested inside 'loop' region}}
|
||||
#pragma omp loop
|
||||
for (i=0; i<1000; ++i) {
|
||||
#pragma omp barrier
|
||||
}
|
||||
|
||||
// A masked region may not be closely nested inside a worksharing, loop,
|
||||
// atomic, task, or taskloop region.
|
||||
|
||||
// expected-error@+3 {{region cannot be closely nested inside 'loop' region}}
|
||||
#pragma omp loop
|
||||
for (i=0; i<1000; ++i) {
|
||||
#pragma omp masked filter(2)
|
||||
{ }
|
||||
}
|
||||
|
||||
// An ordered region that corresponds to an ordered construct without any
|
||||
// clause or with the threads or depend clause may not be closely nested
|
||||
// inside a critical, ordered, loop, atomic, task, or taskloop region.
|
||||
|
||||
// expected-error@+3 {{region cannot be closely nested inside 'loop' region; perhaps you forget to enclose 'omp ordered' directive into a for or a parallel for region with 'ordered' clause?}}
|
||||
#pragma omp loop
|
||||
for (i=0; i<1000; ++i) {
|
||||
#pragma omp ordered
|
||||
{ }
|
||||
}
|
||||
|
||||
// expected-error@+3 {{region cannot be closely nested inside 'loop' region; perhaps you forget to enclose 'omp ordered' directive into a for or a parallel for region with 'ordered' clause?}}
|
||||
#pragma omp loop
|
||||
for (i=0; i<1000; ++i) {
|
||||
#pragma omp ordered threads
|
||||
{ }
|
||||
}
|
||||
|
||||
// expected-error@+3 {{region cannot be closely nested inside 'loop' region; perhaps you forget to enclose 'omp ordered' directive into a for or a parallel for region with 'ordered' clause?}}
|
||||
#pragma omp loop
|
||||
for (i=0; i<1000; ++i) {
|
||||
#pragma omp ordered depend(source)
|
||||
}
|
||||
|
||||
// bind clause (not yet implemented)
|
||||
|
||||
// collapse clause
|
||||
|
||||
// expected-error@+4 {{expected 2 for loops after '#pragma omp loop', but found only 1}}
|
||||
// expected-note@+1 {{as specified in 'collapse' clause}}
|
||||
#pragma omp loop collapse(2)
|
||||
for (i=0; i<1000; ++i)
|
||||
z = i+11;
|
||||
|
||||
// expected-error@+1 {{directive '#pragma omp loop' cannot contain more than one 'collapse' clause}}
|
||||
#pragma omp loop collapse(2) collapse(2)
|
||||
for (i=0; i<1000; ++i)
|
||||
for (j=0; j<1000; ++j)
|
||||
z = i+j+11;
|
||||
|
||||
// order clause
|
||||
|
||||
// expected-error@+1 {{expected 'concurrent' in OpenMP clause 'order'}}
|
||||
#pragma omp loop order(foo)
|
||||
for (i=0; i<1000; ++i)
|
||||
z = i+11;
|
||||
|
||||
// private clause
|
||||
|
||||
// expected-error@+1 {{use of undeclared identifier 'undef_var'}}
|
||||
#pragma omp loop private(undef_var)
|
||||
for (i=0; i<1000; ++i)
|
||||
z = i+11;
|
||||
|
||||
// lastprivate
|
||||
|
||||
// A list item may not appear in a lastprivate clause unless it is the loop
|
||||
// iteration variable of a loop that is associated with the construct.
|
||||
|
||||
// expected-error@+1 {{only loop iteration variables are allowed in 'lastprivate' clause in 'omp loop' directives}}
|
||||
#pragma omp loop lastprivate(z)
|
||||
for (i=0; i<1000; ++i) {
|
||||
z = i+11;
|
||||
}
|
||||
|
||||
// expected-error@+1 {{only loop iteration variables are allowed in 'lastprivate' clause in 'omp loop' directives}}
|
||||
#pragma omp loop lastprivate(k) collapse(2)
|
||||
for (i=0; i<1000; ++i)
|
||||
for (j=0; j<1000; ++j)
|
||||
for (k=0; k<1000; ++k)
|
||||
z = i+j+k+11;
|
||||
|
||||
// reduction
|
||||
|
||||
// expected-error@+1 {{use of undeclared identifier 'undef_var'}}
|
||||
#pragma omp loop reduction(+:undef_var)
|
||||
for (i=0; i<1000; ++i)
|
||||
z = i+11;
|
||||
}
|
||||
|
||||
template <typename T, int C>
|
||||
void templ_test(T t) {
|
||||
T i,z;
|
||||
|
||||
// expected-error@+4 {{expected 2 for loops after '#pragma omp loop', but found only 1}}
|
||||
// expected-note@+1 {{as specified in 'collapse' clause}}
|
||||
#pragma omp loop collapse(C)
|
||||
for (i=0; i<1000; ++i)
|
||||
z = i+11;
|
||||
|
||||
// expected-error@+1 {{only loop iteration variables are allowed in 'lastprivate' clause in 'omp loop' directives}}
|
||||
#pragma omp loop lastprivate(z)
|
||||
for (i=0; i<1000; ++i) {
|
||||
z = i+11;
|
||||
}
|
||||
}
|
||||
|
||||
void bar()
|
||||
{
|
||||
templ_test<int, 2>(16); // expected-note {{in instantiation of function template specialization 'templ_test<int, 2>' requested here}}
|
||||
}
|
@ -5710,6 +5710,8 @@ CXString clang_getCursorKindSpelling(enum CXCursorKind Kind) {
|
||||
return cxstring::createRef("OMPDispatchDirective");
|
||||
case CXCursor_OMPMaskedDirective:
|
||||
return cxstring::createRef("OMPMaskedDirective");
|
||||
case CXCursor_OMPGenericLoopDirective:
|
||||
return cxstring::createRef("OMPGenericLoopDirective");
|
||||
case CXCursor_OverloadCandidate:
|
||||
return cxstring::createRef("OverloadCandidate");
|
||||
case CXCursor_TypeAliasTemplateDecl:
|
||||
|
@ -823,6 +823,9 @@ CXCursor cxcursor::MakeCXCursor(const Stmt *S, const Decl *Parent,
|
||||
case Stmt::OMPMaskedDirectiveClass:
|
||||
K = CXCursor_OMPMaskedDirective;
|
||||
break;
|
||||
case Stmt::OMPGenericLoopDirectiveClass:
|
||||
K = CXCursor_OMPGenericLoopDirective;
|
||||
break;
|
||||
case Stmt::BuiltinBitCastExprClass:
|
||||
K = CXCursor_BuiltinBitCastExpr;
|
||||
}
|
||||
|
@ -1732,6 +1732,17 @@ def OMP_masked : Directive<"masked"> {
|
||||
VersionedClause<OMPC_Filter>
|
||||
];
|
||||
}
|
||||
def OMP_loop : Directive<"loop"> {
|
||||
let allowedClauses = [
|
||||
VersionedClause<OMPC_LastPrivate>,
|
||||
VersionedClause<OMPC_Private>,
|
||||
VersionedClause<OMPC_Reduction>,
|
||||
];
|
||||
let allowedOnceClauses = [
|
||||
VersionedClause<OMPC_Collapse>,
|
||||
VersionedClause<OMPC_Order>,
|
||||
];
|
||||
}
|
||||
def OMP_Metadirective : Directive<"metadirective"> {
|
||||
let allowedClauses = [VersionedClause<OMPC_When>];
|
||||
let allowedOnceClauses = [VersionedClause<OMPC_Default>];
|
||||
|
Loading…
Reference in New Issue
Block a user