[Clang] [OpenMP] Add support for '#pragma omp stripe'. (#126927)

This patch was reviewed and approved here:
https://github.com/llvm/llvm-project/pull/119891
However it has been reverted here:
083df25dc2
due to a build issue here:
https://lab.llvm.org/buildbot/#/builders/51/builds/10694

This patch is reintroducing the support.
This commit is contained in:
Zahira Ammarguellat 2025-02-13 07:14:36 -05:00 committed by GitHub
parent 1935f84856
commit cf69b4c668
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
30 changed files with 3589 additions and 32 deletions

View File

@ -1410,6 +1410,9 @@ class CursorKind(BaseEnumeration):
# OpenMP scope directive.
OMP_SCOPE_DIRECTIVE = 306
# OpenMP stripe directive.
OMP_STRIPE_DIRECTIVE = 310
# OpenACC Compute Construct.
OPEN_ACC_COMPUTE_DIRECTIVE = 320

View File

@ -374,6 +374,8 @@ implementation.
+-------------------------------------------------------------+---------------------------+---------------------------+--------------------------------------------------------------------------+
| Loop transformation constructs | :none:`unclaimed` | :none:`unclaimed` | |
+-------------------------------------------------------------+---------------------------+---------------------------+--------------------------------------------------------------------------+
| loop stripe transformation | :good:`done` | https://github.com/llvm/llvm-project/pull/119891 |
+-------------------------------------------------------------+---------------------------+---------------------------+--------------------------------------------------------------------------+
| work distribute construct | :none:`unclaimed` | :none:`unclaimed` | |
+-------------------------------------------------------------+---------------------------+---------------------------+--------------------------------------------------------------------------+
| task_iteration | :none:`unclaimed` | :none:`unclaimed` | |

View File

@ -299,6 +299,7 @@ Python Binding Changes
OpenMP Support
--------------
- Added support 'no_openmp_constructs' assumption clause.
- Added support for 'omp stripe' directive.
Improvements
^^^^^^^^^^^^

View File

@ -2158,6 +2158,10 @@ enum CXCursorKind {
*/
CXCursor_OMPAssumeDirective = 309,
/** OpenMP assume directive.
*/
CXCursor_OMPStripeDirective = 310,
/** OpenACC Compute Construct.
*/
CXCursor_OpenACCComputeConstruct = 320,

View File

@ -3056,6 +3056,9 @@ DEF_TRAVERSE_STMT(OMPSimdDirective,
DEF_TRAVERSE_STMT(OMPTileDirective,
{ TRY_TO(TraverseOMPExecutableDirective(S)); })
DEF_TRAVERSE_STMT(OMPStripeDirective,
{ TRY_TO(TraverseOMPExecutableDirective(S)); })
DEF_TRAVERSE_STMT(OMPUnrollDirective,
{ TRY_TO(TraverseOMPExecutableDirective(S)); })

View File

@ -994,7 +994,8 @@ public:
static bool classof(const Stmt *T) {
Stmt::StmtClass C = T->getStmtClass();
return C == OMPTileDirectiveClass || C == OMPUnrollDirectiveClass ||
C == OMPReverseDirectiveClass || C == OMPInterchangeDirectiveClass;
C == OMPReverseDirectiveClass || C == OMPInterchangeDirectiveClass ||
C == OMPStripeDirectiveClass;
}
};
@ -5560,7 +5561,7 @@ class OMPTileDirective final : public OMPLoopTransformationDirective {
: OMPLoopTransformationDirective(OMPTileDirectiveClass,
llvm::omp::OMPD_tile, StartLoc, EndLoc,
NumLoops) {
setNumGeneratedLoops(3 * NumLoops);
setNumGeneratedLoops(2 * NumLoops);
}
void setPreInits(Stmt *PreInits) {
@ -5621,6 +5622,81 @@ public:
}
};
/// This represents the '#pragma omp stripe' loop transformation directive.
class OMPStripeDirective final : public OMPLoopTransformationDirective {
friend class ASTStmtReader;
friend class OMPExecutableDirective;
/// Default list of offsets.
enum {
PreInitsOffset = 0,
TransformedStmtOffset,
};
explicit OMPStripeDirective(SourceLocation StartLoc, SourceLocation EndLoc,
unsigned NumLoops)
: OMPLoopTransformationDirective(OMPStripeDirectiveClass,
llvm::omp::OMPD_stripe, StartLoc, EndLoc,
NumLoops) {
setNumGeneratedLoops(2 * NumLoops);
}
void setPreInits(Stmt *PreInits) {
Data->getChildren()[PreInitsOffset] = PreInits;
}
void setTransformedStmt(Stmt *S) {
Data->getChildren()[TransformedStmtOffset] = S;
}
public:
/// Create a new AST node representation for '#pragma omp stripe'.
///
/// \param C Context of the AST.
/// \param StartLoc Location of the introducer (e.g. the 'omp' token).
/// \param EndLoc Location of the directive's end (e.g. the tok::eod).
/// \param Clauses The directive's clauses.
/// \param NumLoops Number of associated loops (number of items in the
/// 'sizes' clause).
/// \param AssociatedStmt The outermost associated loop.
/// \param TransformedStmt The loop nest after striping, or nullptr in
/// dependent contexts.
/// \param PreInits Helper preinits statements for the loop nest.
static OMPStripeDirective *
Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc,
ArrayRef<OMPClause *> Clauses, unsigned NumLoops, Stmt *AssociatedStmt,
Stmt *TransformedStmt, Stmt *PreInits);
/// Build an empty '#pragma omp stripe' AST node for deserialization.
///
/// \param C Context of the AST.
/// \param NumClauses Number of clauses to allocate.
/// \param NumLoops Number of associated loops to allocate.
static OMPStripeDirective *
CreateEmpty(const ASTContext &C, unsigned NumClauses, unsigned NumLoops);
/// Gets/sets the associated loops after striping.
///
/// This is in de-sugared format stored as a CompoundStmt.
///
/// \code
/// for (...)
/// ...
/// \endcode
///
/// Note that if the generated loops a become associated loops of another
/// directive, they may need to be hoisted before them.
Stmt *getTransformedStmt() const {
return Data->getChildren()[TransformedStmtOffset];
}
/// Return preinits statement.
Stmt *getPreInits() const { return Data->getChildren()[PreInitsOffset]; }
static bool classof(const Stmt *T) {
return T->getStmtClass() == OMPStripeDirectiveClass;
}
};
/// This represents the '#pragma omp unroll' loop transformation directive.
///
/// \code

View File

@ -231,6 +231,7 @@ def OMPParallelDirective : StmtNode<OMPExecutableDirective>;
def OMPSimdDirective : StmtNode<OMPLoopDirective>;
def OMPLoopTransformationDirective : StmtNode<OMPLoopBasedDirective, 1>;
def OMPTileDirective : StmtNode<OMPLoopTransformationDirective>;
def OMPStripeDirective : StmtNode<OMPLoopTransformationDirective>;
def OMPUnrollDirective : StmtNode<OMPLoopTransformationDirective>;
def OMPReverseDirective : StmtNode<OMPLoopTransformationDirective>;
def OMPInterchangeDirective : StmtNode<OMPLoopTransformationDirective>;

View File

@ -440,6 +440,9 @@ public:
StmtResult ActOnOpenMPTileDirective(ArrayRef<OMPClause *> Clauses,
Stmt *AStmt, SourceLocation StartLoc,
SourceLocation EndLoc);
StmtResult ActOnOpenMPStripeDirective(ArrayRef<OMPClause *> Clauses,
Stmt *AStmt, SourceLocation StartLoc,
SourceLocation EndLoc);
/// Called on well-formed '#pragma omp unroll' after parsing of its clauses
/// and the associated statement.
StmtResult ActOnOpenMPUnrollDirective(ArrayRef<OMPClause *> Clauses,

View File

@ -1939,6 +1939,7 @@ enum StmtCode {
STMT_OMP_PARALLEL_DIRECTIVE,
STMT_OMP_SIMD_DIRECTIVE,
STMT_OMP_TILE_DIRECTIVE,
STMP_OMP_STRIPE_DIRECTIVE,
STMT_OMP_UNROLL_DIRECTIVE,
STMT_OMP_REVERSE_DIRECTIVE,
STMT_OMP_INTERCHANGE_DIRECTIVE,

View File

@ -425,6 +425,27 @@ OMPTileDirective *OMPTileDirective::CreateEmpty(const ASTContext &C,
SourceLocation(), SourceLocation(), NumLoops);
}
OMPStripeDirective *
OMPStripeDirective::Create(const ASTContext &C, SourceLocation StartLoc,
SourceLocation EndLoc, ArrayRef<OMPClause *> Clauses,
unsigned NumLoops, Stmt *AssociatedStmt,
Stmt *TransformedStmt, Stmt *PreInits) {
OMPStripeDirective *Dir = createDirective<OMPStripeDirective>(
C, Clauses, AssociatedStmt, TransformedStmtOffset + 1, StartLoc, EndLoc,
NumLoops);
Dir->setTransformedStmt(TransformedStmt);
Dir->setPreInits(PreInits);
return Dir;
}
OMPStripeDirective *OMPStripeDirective::CreateEmpty(const ASTContext &C,
unsigned NumClauses,
unsigned NumLoops) {
return createEmptyDirective<OMPStripeDirective>(
C, NumClauses, /*HasAssociatedStmt=*/true, TransformedStmtOffset + 1,
SourceLocation(), SourceLocation(), NumLoops);
}
OMPUnrollDirective *
OMPUnrollDirective::Create(const ASTContext &C, SourceLocation StartLoc,
SourceLocation EndLoc, ArrayRef<OMPClause *> Clauses,

View File

@ -764,6 +764,11 @@ void StmtPrinter::VisitOMPTileDirective(OMPTileDirective *Node) {
PrintOMPExecutableDirective(Node);
}
void StmtPrinter::VisitOMPStripeDirective(OMPStripeDirective *Node) {
Indent() << "#pragma omp stripe";
PrintOMPExecutableDirective(Node);
}
void StmtPrinter::VisitOMPUnrollDirective(OMPUnrollDirective *Node) {
Indent() << "#pragma omp unroll";
PrintOMPExecutableDirective(Node);

View File

@ -1007,6 +1007,10 @@ void StmtProfiler::VisitOMPTileDirective(const OMPTileDirective *S) {
VisitOMPLoopTransformationDirective(S);
}
void StmtProfiler::VisitOMPStripeDirective(const OMPStripeDirective *S) {
VisitOMPLoopTransformationDirective(S);
}
void StmtProfiler::VisitOMPUnrollDirective(const OMPUnrollDirective *S) {
VisitOMPLoopTransformationDirective(S);
}

View File

@ -700,7 +700,7 @@ bool clang::isOpenMPLoopBoundSharingDirective(OpenMPDirectiveKind Kind) {
bool clang::isOpenMPLoopTransformationDirective(OpenMPDirectiveKind DKind) {
return DKind == OMPD_tile || DKind == OMPD_unroll || DKind == OMPD_reverse ||
DKind == OMPD_interchange;
DKind == OMPD_interchange || DKind == OMPD_stripe;
}
bool clang::isOpenMPCombinedParallelADirective(OpenMPDirectiveKind DKind) {
@ -827,6 +827,7 @@ void clang::getOpenMPCaptureRegions(
case OMPD_single:
case OMPD_target_data:
case OMPD_taskgroup:
case OMPD_stripe:
// These directives (when standalone) use OMPD_unknown as the region,
// but when they're constituents of a compound directive, and other
// leafs from that directive have specific regions, then these directives

View File

@ -221,6 +221,9 @@ void CodeGenFunction::EmitStmt(const Stmt *S, ArrayRef<const Attr *> Attrs) {
case Stmt::OMPTileDirectiveClass:
EmitOMPTileDirective(cast<OMPTileDirective>(*S));
break;
case Stmt::OMPStripeDirectiveClass:
EmitOMPStripeDirective(cast<OMPStripeDirective>(*S));
break;
case Stmt::OMPUnrollDirectiveClass:
EmitOMPUnrollDirective(cast<OMPUnrollDirective>(*S));
break;

View File

@ -187,6 +187,8 @@ class OMPLoopScope : public CodeGenFunction::RunCleanupsScope {
PreInits = LD->getPreInits();
} else if (const auto *Tile = dyn_cast<OMPTileDirective>(&S)) {
PreInits = Tile->getPreInits();
} else if (const auto *Stripe = dyn_cast<OMPStripeDirective>(&S)) {
PreInits = Stripe->getPreInits();
} else if (const auto *Unroll = dyn_cast<OMPUnrollDirective>(&S)) {
PreInits = Unroll->getPreInits();
} else if (const auto *Reverse = dyn_cast<OMPReverseDirective>(&S)) {
@ -2896,6 +2898,12 @@ void CodeGenFunction::EmitOMPTileDirective(const OMPTileDirective &S) {
EmitStmt(S.getTransformedStmt());
}
void CodeGenFunction::EmitOMPStripeDirective(const OMPStripeDirective &S) {
// Emit the de-sugared statement.
OMPTransformDirectiveScopeRAII StripeScope(*this, &S);
EmitStmt(S.getTransformedStmt());
}
void CodeGenFunction::EmitOMPReverseDirective(const OMPReverseDirective &S) {
// Emit the de-sugared statement.
OMPTransformDirectiveScopeRAII ReverseScope(*this, &S);

View File

@ -3809,6 +3809,7 @@ public:
void EmitOMPParallelDirective(const OMPParallelDirective &S);
void EmitOMPSimdDirective(const OMPSimdDirective &S);
void EmitOMPTileDirective(const OMPTileDirective &S);
void EmitOMPStripeDirective(const OMPStripeDirective &S);
void EmitOMPUnrollDirective(const OMPUnrollDirective &S);
void EmitOMPReverseDirective(const OMPReverseDirective &S);
void EmitOMPInterchangeDirective(const OMPInterchangeDirective &S);

View File

@ -2548,9 +2548,10 @@ StmtResult Parser::ParseOpenMPExecutableDirective(
}
}
if (DKind == OMPD_tile && !SeenClauses[unsigned(OMPC_sizes)]) {
if ((DKind == OMPD_tile || DKind == OMPD_stripe) &&
!SeenClauses[unsigned(OMPC_sizes)]) {
Diag(Loc, diag::err_omp_required_clause)
<< getOpenMPDirectiveName(OMPD_tile) << "sizes";
<< getOpenMPDirectiveName(DKind) << "sizes";
}
StmtResult AssociatedStmt;

View File

@ -1488,6 +1488,7 @@ CanThrowResult Sema::canThrow(const Stmt *S) {
case Stmt::OMPSectionsDirectiveClass:
case Stmt::OMPSimdDirectiveClass:
case Stmt::OMPTileDirectiveClass:
case Stmt::OMPStripeDirectiveClass:
case Stmt::OMPUnrollDirectiveClass:
case Stmt::OMPReverseDirectiveClass:
case Stmt::OMPInterchangeDirectiveClass:

View File

@ -4386,6 +4386,7 @@ void SemaOpenMP::ActOnOpenMPRegionStart(OpenMPDirectiveKind DKind,
case OMPD_master:
case OMPD_section:
case OMPD_tile:
case OMPD_stripe:
case OMPD_unroll:
case OMPD_reverse:
case OMPD_interchange:
@ -6197,6 +6198,10 @@ StmtResult SemaOpenMP::ActOnOpenMPExecutableDirective(
Res =
ActOnOpenMPTileDirective(ClausesWithImplicit, AStmt, StartLoc, EndLoc);
break;
case OMPD_stripe:
Res = ActOnOpenMPStripeDirective(ClausesWithImplicit, AStmt, StartLoc,
EndLoc);
break;
case OMPD_unroll:
Res = ActOnOpenMPUnrollDirective(ClausesWithImplicit, AStmt, StartLoc,
EndLoc);
@ -14147,6 +14152,8 @@ bool SemaOpenMP::checkTransformableLoopNest(
Stmt *DependentPreInits;
if (auto *Dir = dyn_cast<OMPTileDirective>(Transform))
DependentPreInits = Dir->getPreInits();
else if (auto *Dir = dyn_cast<OMPStripeDirective>(Transform))
DependentPreInits = Dir->getPreInits();
else if (auto *Dir = dyn_cast<OMPUnrollDirective>(Transform))
DependentPreInits = Dir->getPreInits();
else if (auto *Dir = dyn_cast<OMPReverseDirective>(Transform))
@ -14219,6 +14226,14 @@ static void collectLoopStmts(Stmt *AStmt, MutableArrayRef<Stmt *> LoopStmts) {
"Expecting a loop statement for each affected loop");
}
/// Build and return a DeclRefExpr for the floor induction variable using the
/// SemaRef and the provided parameters.
static Expr *makeFloorIVRef(Sema &SemaRef, ArrayRef<VarDecl *> FloorIndVars,
int I, QualType IVTy, DeclRefExpr *OrigCntVar) {
return buildDeclRefExpr(SemaRef, FloorIndVars[I], IVTy,
OrigCntVar->getExprLoc());
}
StmtResult SemaOpenMP::ActOnOpenMPTileDirective(ArrayRef<OMPClause *> Clauses,
Stmt *AStmt,
SourceLocation StartLoc,
@ -14356,22 +14371,21 @@ StmtResult SemaOpenMP::ActOnOpenMPTileDirective(ArrayRef<OMPClause *> Clauses,
Stmt *LoopStmt = LoopStmts[I];
// Commonly used variables. One of the constraints of an AST is that every
// node object must appear at most once, hence we define lamdas that create
// a new AST node at every use.
// node object must appear at most once, hence we define a lambda that
// creates a new AST node at every use.
auto MakeTileIVRef = [&SemaRef = this->SemaRef, &TileIndVars, I, IVTy,
OrigCntVar]() {
return buildDeclRefExpr(SemaRef, TileIndVars[I], IVTy,
OrigCntVar->getExprLoc());
};
auto MakeFloorIVRef = [&SemaRef = this->SemaRef, &FloorIndVars, I, IVTy,
OrigCntVar]() {
return buildDeclRefExpr(SemaRef, FloorIndVars[I], IVTy,
OrigCntVar->getExprLoc());
};
// For init-statement: auto .tile.iv = .floor.iv
SemaRef.AddInitializerToDecl(
TileIndVars[I], SemaRef.DefaultLvalueConversion(MakeFloorIVRef()).get(),
TileIndVars[I],
SemaRef
.DefaultLvalueConversion(
makeFloorIVRef(SemaRef, FloorIndVars, I, IVTy, OrigCntVar))
.get(),
/*DirectInit=*/false);
Decl *CounterDecl = TileIndVars[I];
StmtResult InitStmt = new (Context)
@ -14382,9 +14396,10 @@ StmtResult SemaOpenMP::ActOnOpenMPTileDirective(ArrayRef<OMPClause *> Clauses,
// For cond-expression:
// .tile.iv < min(.floor.iv + DimTileSize, NumIterations)
ExprResult EndOfTile =
SemaRef.BuildBinOp(CurScope, LoopHelper.Cond->getExprLoc(), BO_Add,
MakeFloorIVRef(), MakeDimTileSize(I));
ExprResult EndOfTile = SemaRef.BuildBinOp(
CurScope, LoopHelper.Cond->getExprLoc(), BO_Add,
makeFloorIVRef(SemaRef, FloorIndVars, I, IVTy, OrigCntVar),
MakeDimTileSize(I));
if (!EndOfTile.isUsable())
return StmtError();
ExprResult IsPartialTile =
@ -14445,15 +14460,6 @@ StmtResult SemaOpenMP::ActOnOpenMPTileDirective(ArrayRef<OMPClause *> Clauses,
DeclRefExpr *OrigCntVar = cast<DeclRefExpr>(LoopHelper.Counters[0]);
QualType IVTy = NumIterations->getType();
// Commonly used variables. One of the constraints of an AST is that every
// node object must appear at most once, hence we define lamdas that create
// a new AST node at every use.
auto MakeFloorIVRef = [&SemaRef = this->SemaRef, &FloorIndVars, I, IVTy,
OrigCntVar]() {
return buildDeclRefExpr(SemaRef, FloorIndVars[I], IVTy,
OrigCntVar->getExprLoc());
};
// For init-statement: auto .floor.iv = 0
SemaRef.AddInitializerToDecl(
FloorIndVars[I],
@ -14467,16 +14473,18 @@ StmtResult SemaOpenMP::ActOnOpenMPTileDirective(ArrayRef<OMPClause *> Clauses,
return StmtError();
// For cond-expression: .floor.iv < NumIterations
ExprResult CondExpr =
SemaRef.BuildBinOp(CurScope, LoopHelper.Cond->getExprLoc(), BO_LT,
MakeFloorIVRef(), NumIterations);
ExprResult CondExpr = SemaRef.BuildBinOp(
CurScope, LoopHelper.Cond->getExprLoc(), BO_LT,
makeFloorIVRef(SemaRef, FloorIndVars, I, IVTy, OrigCntVar),
NumIterations);
if (!CondExpr.isUsable())
return StmtError();
// For incr-statement: .floor.iv += DimTileSize
ExprResult IncrStmt =
SemaRef.BuildBinOp(CurScope, LoopHelper.Inc->getExprLoc(), BO_AddAssign,
MakeFloorIVRef(), MakeDimTileSize(I));
ExprResult IncrStmt = SemaRef.BuildBinOp(
CurScope, LoopHelper.Inc->getExprLoc(), BO_AddAssign,
makeFloorIVRef(SemaRef, FloorIndVars, I, IVTy, OrigCntVar),
MakeDimTileSize(I));
if (!IncrStmt.isUsable())
return StmtError();
@ -14491,6 +14499,262 @@ StmtResult SemaOpenMP::ActOnOpenMPTileDirective(ArrayRef<OMPClause *> Clauses,
buildPreInits(Context, PreInits));
}
StmtResult SemaOpenMP::ActOnOpenMPStripeDirective(ArrayRef<OMPClause *> Clauses,
Stmt *AStmt,
SourceLocation StartLoc,
SourceLocation EndLoc) {
ASTContext &Context = getASTContext();
Scope *CurScope = SemaRef.getCurScope();
const auto *SizesClause =
OMPExecutableDirective::getSingleClause<OMPSizesClause>(Clauses);
if (!SizesClause || llvm::is_contained(SizesClause->getSizesRefs(), nullptr))
return StmtError();
unsigned NumLoops = SizesClause->getNumSizes();
// Empty statement should only be possible if there already was an error.
if (!AStmt)
return StmtError();
// Verify and diagnose loop nest.
SmallVector<OMPLoopBasedDirective::HelperExprs, 4> LoopHelpers(NumLoops);
Stmt *Body = nullptr;
SmallVector<SmallVector<Stmt *, 0>, 4> OriginalInits;
if (!checkTransformableLoopNest(OMPD_stripe, AStmt, NumLoops, LoopHelpers,
Body, OriginalInits))
return StmtError();
// Delay striping to when template is completely instantiated.
if (SemaRef.CurContext->isDependentContext())
return OMPStripeDirective::Create(Context, StartLoc, EndLoc, Clauses,
NumLoops, AStmt, nullptr, nullptr);
assert(LoopHelpers.size() == NumLoops &&
"Expecting loop iteration space dimensionality to match number of "
"affected loops");
assert(OriginalInits.size() == NumLoops &&
"Expecting loop iteration space dimensionality to match number of "
"affected loops");
// Collect all affected loop statements.
SmallVector<Stmt *> LoopStmts(NumLoops, nullptr);
collectLoopStmts(AStmt, LoopStmts);
SmallVector<Stmt *, 4> PreInits;
CaptureVars CopyTransformer(SemaRef);
// Create iteration variables for the generated loops.
SmallVector<VarDecl *, 4> FloorIndVars;
SmallVector<VarDecl *, 4> StripeIndVars;
FloorIndVars.resize(NumLoops);
StripeIndVars.resize(NumLoops);
for (unsigned I : llvm::seq<unsigned>(NumLoops)) {
OMPLoopBasedDirective::HelperExprs &LoopHelper = LoopHelpers[I];
assert(LoopHelper.Counters.size() == 1 &&
"Expect single-dimensional loop iteration space");
auto *OrigCntVar = cast<DeclRefExpr>(LoopHelper.Counters.front());
std::string OrigVarName = OrigCntVar->getNameInfo().getAsString();
DeclRefExpr *IterVarRef = cast<DeclRefExpr>(LoopHelper.IterationVarRef);
QualType CntTy = IterVarRef->getType();
// Iteration variable for the stripe (i.e. outer) loop.
{
std::string FloorCntName =
(Twine(".floor_") + llvm::utostr(I) + ".iv." + OrigVarName).str();
VarDecl *FloorCntDecl =
buildVarDecl(SemaRef, {}, CntTy, FloorCntName, nullptr, OrigCntVar);
FloorIndVars[I] = FloorCntDecl;
}
// Iteration variable for the stripe (i.e. inner) loop.
{
std::string StripeCntName =
(Twine(".stripe_") + llvm::utostr(I) + ".iv." + OrigVarName).str();
// Reuse the iteration variable created by checkOpenMPLoop. It is also
// used by the expressions to derive the original iteration variable's
// value from the logical iteration number.
auto *StripeCntDecl = cast<VarDecl>(IterVarRef->getDecl());
StripeCntDecl->setDeclName(
&SemaRef.PP.getIdentifierTable().get(StripeCntName));
StripeIndVars[I] = StripeCntDecl;
}
addLoopPreInits(Context, LoopHelper, LoopStmts[I], OriginalInits[I],
PreInits);
}
// Once the original iteration values are set, append the innermost body.
Stmt *Inner = Body;
auto MakeDimStripeSize = [&](int I) -> Expr * {
Expr *DimStripeSizeExpr = SizesClause->getSizesRefs()[I];
if (isa<ConstantExpr>(DimStripeSizeExpr))
return AssertSuccess(CopyTransformer.TransformExpr(DimStripeSizeExpr));
// When the stripe size is not a constant but a variable, it is possible to
// pass non-positive numbers. For instance:
// \code{c}
// int a = 0;
// #pragma omp stripe sizes(a)
// for (int i = 0; i < 42; ++i)
// body(i);
// \endcode
// Although there is no meaningful interpretation of the stripe size, the
// body should still be executed 42 times to avoid surprises. To preserve
// the invariant that every loop iteration is executed exactly once and not
// cause an infinite loop, apply a minimum stripe size of one.
// Build expr:
// \code{c}
// (TS <= 0) ? 1 : TS
// \endcode
QualType DimTy = DimStripeSizeExpr->getType();
uint64_t DimWidth = Context.getTypeSize(DimTy);
IntegerLiteral *Zero = IntegerLiteral::Create(
Context, llvm::APInt::getZero(DimWidth), DimTy, {});
IntegerLiteral *One =
IntegerLiteral::Create(Context, llvm::APInt(DimWidth, 1), DimTy, {});
Expr *Cond = AssertSuccess(SemaRef.BuildBinOp(
CurScope, {}, BO_LE,
AssertSuccess(CopyTransformer.TransformExpr(DimStripeSizeExpr)), Zero));
Expr *MinOne = new (Context) ConditionalOperator(
Cond, {}, One, {},
AssertSuccess(CopyTransformer.TransformExpr(DimStripeSizeExpr)), DimTy,
VK_PRValue, OK_Ordinary);
return MinOne;
};
// Create stripe loops from the inside to the outside.
for (int I = NumLoops - 1; I >= 0; --I) {
OMPLoopBasedDirective::HelperExprs &LoopHelper = LoopHelpers[I];
Expr *NumIterations = LoopHelper.NumIterations;
auto *OrigCntVar = cast<DeclRefExpr>(LoopHelper.Counters[0]);
QualType IVTy = NumIterations->getType();
Stmt *LoopStmt = LoopStmts[I];
// For init-statement: auto .stripe.iv = .floor.iv
SemaRef.AddInitializerToDecl(
StripeIndVars[I],
SemaRef
.DefaultLvalueConversion(
makeFloorIVRef(SemaRef, FloorIndVars, I, IVTy, OrigCntVar))
.get(),
/*DirectInit=*/false);
Decl *CounterDecl = StripeIndVars[I];
StmtResult InitStmt = new (Context)
DeclStmt(DeclGroupRef::Create(Context, &CounterDecl, 1),
OrigCntVar->getBeginLoc(), OrigCntVar->getEndLoc());
if (!InitStmt.isUsable())
return StmtError();
// For cond-expression:
// .stripe.iv < min(.floor.iv + DimStripeSize, NumIterations)
ExprResult EndOfStripe = SemaRef.BuildBinOp(
CurScope, LoopHelper.Cond->getExprLoc(), BO_Add,
makeFloorIVRef(SemaRef, FloorIndVars, I, IVTy, OrigCntVar),
MakeDimStripeSize(I));
if (!EndOfStripe.isUsable())
return StmtError();
ExprResult IsPartialStripe =
SemaRef.BuildBinOp(CurScope, LoopHelper.Cond->getExprLoc(), BO_LT,
NumIterations, EndOfStripe.get());
if (!IsPartialStripe.isUsable())
return StmtError();
ExprResult MinStripeAndIterSpace = SemaRef.ActOnConditionalOp(
LoopHelper.Cond->getBeginLoc(), LoopHelper.Cond->getEndLoc(),
IsPartialStripe.get(), NumIterations, EndOfStripe.get());
if (!MinStripeAndIterSpace.isUsable())
return StmtError();
ExprResult CondExpr = SemaRef.BuildBinOp(
CurScope, LoopHelper.Cond->getExprLoc(), BO_LT,
makeFloorIVRef(SemaRef, StripeIndVars, I, IVTy, OrigCntVar),
MinStripeAndIterSpace.get());
if (!CondExpr.isUsable())
return StmtError();
// For incr-statement: ++.stripe.iv
ExprResult IncrStmt = SemaRef.BuildUnaryOp(
CurScope, LoopHelper.Inc->getExprLoc(), UO_PreInc,
makeFloorIVRef(SemaRef, StripeIndVars, I, IVTy, OrigCntVar));
if (!IncrStmt.isUsable())
return StmtError();
// Statements to set the original iteration variable's value from the
// logical iteration number.
// Generated for loop is:
// \code
// Original_for_init;
// for (auto .stripe.iv = .floor.iv;
// .stripe.iv < min(.floor.iv + DimStripeSize, NumIterations);
// ++.stripe.iv) {
// Original_Body;
// Original_counter_update;
// }
// \endcode
// FIXME: If the innermost body is a loop itself, inserting these
// statements stops it being recognized as a perfectly nested loop (e.g.
// for applying another loop transformation). If this is the case, sink the
// expressions further into the inner loop.
SmallVector<Stmt *, 4> BodyParts;
BodyParts.append(LoopHelper.Updates.begin(), LoopHelper.Updates.end());
if (auto *SourceCXXFor = dyn_cast<CXXForRangeStmt>(LoopStmt))
BodyParts.push_back(SourceCXXFor->getLoopVarStmt());
BodyParts.push_back(Inner);
Inner = CompoundStmt::Create(Context, BodyParts, FPOptionsOverride(),
Inner->getBeginLoc(), Inner->getEndLoc());
Inner = new (Context)
ForStmt(Context, InitStmt.get(), CondExpr.get(), nullptr,
IncrStmt.get(), Inner, LoopHelper.Init->getBeginLoc(),
LoopHelper.Init->getBeginLoc(), LoopHelper.Inc->getEndLoc());
}
// Create grid loops from the inside to the outside.
for (int I = NumLoops - 1; I >= 0; --I) {
auto &LoopHelper = LoopHelpers[I];
Expr *NumIterations = LoopHelper.NumIterations;
DeclRefExpr *OrigCntVar = cast<DeclRefExpr>(LoopHelper.Counters[0]);
QualType IVTy = NumIterations->getType();
// For init-statement: auto .grid.iv = 0
SemaRef.AddInitializerToDecl(
FloorIndVars[I],
SemaRef.ActOnIntegerConstant(LoopHelper.Init->getExprLoc(), 0).get(),
/*DirectInit=*/false);
Decl *CounterDecl = FloorIndVars[I];
StmtResult InitStmt = new (Context)
DeclStmt(DeclGroupRef::Create(Context, &CounterDecl, 1),
OrigCntVar->getBeginLoc(), OrigCntVar->getEndLoc());
if (!InitStmt.isUsable())
return StmtError();
// For cond-expression: .floor.iv < NumIterations
ExprResult CondExpr = SemaRef.BuildBinOp(
CurScope, LoopHelper.Cond->getExprLoc(), BO_LT,
makeFloorIVRef(SemaRef, FloorIndVars, I, IVTy, OrigCntVar),
NumIterations);
if (!CondExpr.isUsable())
return StmtError();
// For incr-statement: .floor.iv += DimStripeSize
ExprResult IncrStmt = SemaRef.BuildBinOp(
CurScope, LoopHelper.Inc->getExprLoc(), BO_AddAssign,
makeFloorIVRef(SemaRef, FloorIndVars, I, IVTy, OrigCntVar),
MakeDimStripeSize(I));
if (!IncrStmt.isUsable())
return StmtError();
Inner = new (Context)
ForStmt(Context, InitStmt.get(), CondExpr.get(), nullptr,
IncrStmt.get(), Inner, LoopHelper.Init->getBeginLoc(),
LoopHelper.Init->getBeginLoc(), LoopHelper.Inc->getEndLoc());
}
return OMPStripeDirective::Create(Context, StartLoc, EndLoc, Clauses,
NumLoops, AStmt, Inner,
buildPreInits(Context, PreInits));
}
StmtResult SemaOpenMP::ActOnOpenMPUnrollDirective(ArrayRef<OMPClause *> Clauses,
Stmt *AStmt,
SourceLocation StartLoc,

View File

@ -9545,6 +9545,17 @@ TreeTransform<Derived>::TransformOMPTileDirective(OMPTileDirective *D) {
return Res;
}
template <typename Derived>
StmtResult
TreeTransform<Derived>::TransformOMPStripeDirective(OMPStripeDirective *D) {
DeclarationNameInfo DirName;
getDerived().getSema().OpenMP().StartOpenMPDSABlock(
D->getDirectiveKind(), DirName, nullptr, D->getBeginLoc());
StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
return Res;
}
template <typename Derived>
StmtResult
TreeTransform<Derived>::TransformOMPUnrollDirective(OMPUnrollDirective *D) {

View File

@ -2454,6 +2454,10 @@ void ASTStmtReader::VisitOMPTileDirective(OMPTileDirective *D) {
VisitOMPLoopTransformationDirective(D);
}
void ASTStmtReader::VisitOMPStripeDirective(OMPStripeDirective *D) {
VisitOMPLoopTransformationDirective(D);
}
void ASTStmtReader::VisitOMPUnrollDirective(OMPUnrollDirective *D) {
VisitOMPLoopTransformationDirective(D);
}
@ -3574,6 +3578,13 @@ Stmt *ASTReader::ReadStmtFromStream(ModuleFile &F) {
break;
}
case STMP_OMP_STRIPE_DIRECTIVE: {
unsigned NumLoops = Record[ASTStmtReader::NumStmtFields];
unsigned NumClauses = Record[ASTStmtReader::NumStmtFields + 1];
S = OMPStripeDirective::CreateEmpty(Context, NumClauses, NumLoops);
break;
}
case STMT_OMP_UNROLL_DIRECTIVE: {
assert(Record[ASTStmtReader::NumStmtFields] == 1 && "Unroll directive accepts only a single loop");
unsigned NumClauses = Record[ASTStmtReader::NumStmtFields + 1];

View File

@ -2459,6 +2459,11 @@ void ASTStmtWriter::VisitOMPTileDirective(OMPTileDirective *D) {
Code = serialization::STMT_OMP_TILE_DIRECTIVE;
}
void ASTStmtWriter::VisitOMPStripeDirective(OMPStripeDirective *D) {
VisitOMPLoopTransformationDirective(D);
Code = serialization::STMP_OMP_STRIPE_DIRECTIVE;
}
void ASTStmtWriter::VisitOMPUnrollDirective(OMPUnrollDirective *D) {
VisitOMPLoopTransformationDirective(D);
Code = serialization::STMT_OMP_UNROLL_DIRECTIVE;

View File

@ -1814,6 +1814,7 @@ void ExprEngine::Visit(const Stmt *S, ExplodedNode *Pred,
case Stmt::OMPTargetTeamsDistributeParallelForSimdDirectiveClass:
case Stmt::OMPTargetTeamsDistributeSimdDirectiveClass:
case Stmt::OMPReverseDirectiveClass:
case Stmt::OMPStripeDirectiveClass:
case Stmt::OMPTileDirectiveClass:
case Stmt::OMPInterchangeDirectiveClass:
case Stmt::OMPInteropDirectiveClass:

View File

@ -0,0 +1,11 @@
// RUN: c-index-test -test-load-source local %s -fopenmp=libomp -fopenmp-version=60 | FileCheck %s
void test() {
#pragma omp stripe sizes(5)
for (int i = 0; i < 65; i += 1)
;
}
// CHECK: openmp-stripe.c:4:1: OMPStripeDirective= Extent=[4:1 - 4:28]
// CHECK: openmp-stripe.c:4:26: IntegerLiteral= Extent=[4:26 - 4:27]
// CHECK: openmp-stripe.c:5:3: ForStmt= Extent=[5:3 - 6:6]

View File

@ -0,0 +1,202 @@
// Check no warnings/errors
// RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -fopenmp -fopenmp-version=60 -fsyntax-only -verify %s
// expected-no-diagnostics
// Check AST and unparsing
// RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -fopenmp -fopenmp-version=60 -ast-dump %s \
// RUN: | FileCheck %s --check-prefix=DUMP
// RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -fopenmp -fopenmp-version=60 -ast-print %s \
// RUN: | FileCheck %s --check-prefix=PRINT
// Check same results after serialization round-trip
// RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -fopenmp -fopenmp-version=60 -emit-pch -o %t %s
// RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -fopenmp -fopenmp-version=60 -ast-dump-all %s \
// RUN: | FileCheck %s --check-prefix=DUMP
// RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -fopenmp -fopenmp-version=60 -ast-print %s \
// RUN: | FileCheck %s --check-prefix=PRINT
// placeholder for loop body code.
extern "C" void body(...);
// PRINT-LABEL: void foo1(
// DUMP-LABEL: FunctionDecl {{.*}} foo1
void foo1() {
// PRINT: #pragma omp stripe sizes(5, 5)
// DUMP: OMPStripeDirective
// DUMP-NEXT: OMPSizesClause
// DUMP-NEXT: IntegerLiteral {{.*}} 5
// DUMP-NEXT: IntegerLiteral {{.*}} 5
#pragma omp stripe sizes(5,5)
// PRINT: for (int i = 7; i < 17; i += 3)
// DUMP-NEXT: ForStmt
for (int i = 7; i < 17; i += 3)
// PRINT: for (int j = 7; j < 17; j += 3)
// DUMP: ForStmt
for (int j = 7; j < 17; j += 3)
// PRINT: body(i, j);
// DUMP: CallExpr
body(i, j);
}
// PRINT-LABEL: void foo2(
// DUMP-LABEL: FunctionDecl {{.*}} foo2
void foo2(int start1, int start2, int end1, int end2) {
// PRINT: #pragma omp stripe sizes(5, 5)
// DUMP: OMPStripeDirective
// DUMP-NEXT: OMPSizesClause
// DUMP-NEXT: IntegerLiteral {{.*}} 5
// DUMP-NEXT: IntegerLiteral {{.*}} 5
#pragma omp stripe sizes(5,5)
// PRINT: for (int i = start1; i < end1; i += 1)
// DUMP-NEXT: ForStmt
for (int i = start1; i < end1; i += 1)
// PRINT: for (int j = start2; j < end2; j += 1)
// DUMP: ForStmt
for (int j = start2; j < end2; j += 1)
// PRINT: body(i, j);
// DUMP: CallExpr
body(i, j);
}
// PRINT-LABEL: void foo3(
// DUMP-LABEL: FunctionDecl {{.*}} foo3
void foo3() {
// PRINT: #pragma omp for
// DUMP: OMPForDirective
// DUMP-NEXT: CapturedStmt
// DUMP-NEXT: CapturedDecl
#pragma omp for
// PRINT: #pragma omp stripe sizes(5)
// DUMP-NEXT: OMPStripeDirective
// DUMP-NEXT: OMPSizesClause
// DUMP-NEXT: IntegerLiteral {{.*}} 5
#pragma omp stripe sizes(5)
for (int i = 7; i < 17; i += 3)
// PRINT: body(i);
// DUMP: CallExpr
body(i);
}
// PRINT-LABEL: void foo4(
// DUMP-LABEL: FunctionDecl {{.*}} foo4
void foo4() {
// PRINT: #pragma omp for collapse(3)
// DUMP: OMPForDirective
// DUMP-NEXT: OMPCollapseClause
// DUMP-NEXT: ConstantExpr
// DUMP-NEXT: value: Int 3
// DUMP-NEXT: IntegerLiteral {{.*}} 3
// DUMP-NEXT: CapturedStmt
// DUMP-NEXT: CapturedDecl
#pragma omp for collapse(3)
// PRINT: #pragma omp stripe sizes(5, 5)
// DUMP: OMPStripeDirective
// DUMP-NEXT: OMPSizesClause
// DUMP-NEXT: IntegerLiteral {{.*}} 5
// DUMP-NEXT: IntegerLiteral {{.*}} 5
#pragma omp stripe sizes(5, 5)
// PRINT: for (int i = 7; i < 17; i += 1)
// DUMP-NEXT: ForStmt
for (int i = 7; i < 17; i += 1)
// PRINT: for (int j = 7; j < 17; j += 1)
// DUMP: ForStmt
for (int j = 7; j < 17; j += 1)
// PRINT: body(i, j);
// DUMP: CallExpr
body(i, j);
}
// PRINT-LABEL: void foo5(
// DUMP-LABEL: FunctionDecl {{.*}} foo5
void foo5(int start, int end, int step) {
// PRINT: #pragma omp for collapse(2)
// DUMP: OMPForDirective
// DUMP-NEXT: OMPCollapseClause
// DUMP-NEXT: ConstantExpr
// DUMP-NEXT: value: Int 2
// DUMP-NEXT: IntegerLiteral {{.*}} 2
// DUMP-NEXT: CapturedStmt
// DUMP-NEXT: CapturedDecl
#pragma omp for collapse(2)
// PRINT: for (int i = 7; i < 17; i += 1)
// DUMP-NEXT: ForStmt
for (int i = 7; i < 17; i += 1)
// PRINT: #pragma omp stripe sizes(5)
// DUMP: OMPStripeDirective
// DUMP-NEXT: OMPSizesClause
// DUMP-NEXT: IntegerLiteral {{.*}} 5
#pragma omp stripe sizes(5)
// PRINT: for (int j = 7; j < 17; j += 1)
// DUMP-NEXT: ForStmt
for (int j = 7; j < 17; j += 1)
// PRINT: body(i, j);
// DUMP: CallExpr
body(i, j);
}
// PRINT-LABEL: void foo6(
// DUMP-LABEL: FunctionTemplateDecl {{.*}} foo6
template<typename T, T Step, T Stripe>
void foo6(T start, T end) {
// PRINT: #pragma omp stripe sizes(Stripe)
// DUMP: OMPStripeDirective
// DUMP-NEXT: OMPSizesClause
// DUMP-NEXT: DeclRefExpr {{.*}} 'Stripe' 'T'
#pragma omp stripe sizes(Stripe)
// PRINT-NEXT: for (T i = start; i < end; i += Step)
// DUMP-NEXT: ForStmt
for (T i = start; i < end; i += Step)
// PRINT-NEXT: body(i);
// DUMP: CallExpr
body(i);
}
// Also test instantiating the template.
void tfoo6() {
foo6<int,3,5>(0, 42);
}
// PRINT-LABEL: template <int Stripe> void foo7(int start, int stop, int step) {
// DUMP-LABEL: FunctionTemplateDecl {{.*}} foo7
template <int Stripe>
void foo7(int start, int stop, int step) {
// PRINT: #pragma omp stripe sizes(Stripe)
// DUMP: OMPStripeDirective
// DUMP-NEXT: OMPSizesClause
// DUMP-NEXT: DeclRefExpr {{.*}} 'Stripe' 'int'
#pragma omp stripe sizes(Stripe)
// PRINT-NEXT: for (int i = start; i < stop; i += step)
// DUMP-NEXT: ForStmt
for (int i = start; i < stop; i += step)
// PRINT-NEXT: body(i);
// DUMP: CallExpr
body(i);
}
void tfoo7() {
foo7<5>(0, 42, 2);
}
// PRINT-LABEL: void foo8(
// DUMP-LABEL: FunctionDecl {{.*}} foo8
void foo8(int a) {
// PRINT: #pragma omp stripe sizes(a)
// DUMP: OMPStripeDirective
// DUMP-NEXT: OMPSizesClause
// DUMP-NEXT: ImplicitCastExpr
// DUMP-NEXT: DeclRefExpr {{.*}} 'a'
#pragma omp stripe sizes(a)
// PRINT-NEXT: for (int i = 7; i < 19; i += 3)
// DUMP-NEXT: ForStmt
for (int i = 7; i < 19; i += 3)
// PRINT: body(i);
// DUMP: CallExpr
body(i);
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,163 @@
// RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -std=c++17 -fopenmp -fopenmp-version=60 -fsyntax-only -Wuninitialized -verify %s
void func() {
// expected-error@+1 {{expected '('}}
#pragma omp stripe sizes
;
// expected-error@+2 {{expected expression}}
// expected-error@+1 {{expected ')'}} expected-note@+1 {{to match this '('}}
#pragma omp stripe sizes(
;
// expected-error@+1 {{expected expression}}
#pragma omp stripe sizes()
;
// expected-error@+1 {{expected ')'}} expected-note@+1 {{to match this '('}}
#pragma omp stripe sizes(5
for (int i = 0; i < 7; ++i);
// expected-error@+2 {{expected expression}}
// expected-error@+1 {{expected ')'}} expected-note@+1 {{to match this '('}}
#pragma omp stripe sizes(5,
;
// expected-error@+1 {{expected expression}}
#pragma omp stripe sizes(5,)
;
// expected-error@+2 {{expected expression}}
// expected-error@+1 {{expected ')'}} expected-note@+1 {{to match this '('}}
#pragma omp stripe sizes(5+
;
// expected-error@+1 {{expected expression}}
#pragma omp stripe sizes(5+)
;
// expected-error@+1 {{expected expression}}
#pragma omp stripe sizes(for)
;
// expected-error@+1 {{argument to 'sizes' clause must be a strictly positive integer value}}
#pragma omp stripe sizes(0)
for (int i = 0; i < 7; ++i)
;
// expected-warning@+2 {{extra tokens at the end of '#pragma omp stripe' are ignored}}
// expected-error@+1 {{directive '#pragma omp stripe' requires the 'sizes' clause}}
#pragma omp stripe foo
;
// expected-error@+1 {{directive '#pragma omp stripe' cannot contain more than one 'sizes' clause}}
#pragma omp stripe sizes(5) sizes(5)
for (int i = 0; i < 7; ++i)
;
// expected-error@+1 {{unexpected OpenMP clause 'collapse' in directive '#pragma omp stripe'}}
#pragma omp stripe sizes(5) collapse(2)
for (int i = 0; i < 7; ++i)
;
{
// expected-error@+2 {{expected statement}}
#pragma omp stripe sizes(5)
}
// expected-error@+2 {{statement after '#pragma omp stripe' must be a for loop}}
#pragma omp stripe sizes(5)
int b = 0;
// expected-error@+3 {{statement after '#pragma omp stripe' must be a for loop}}
#pragma omp stripe sizes(5,5)
for (int i = 0; i < 7; ++i)
;
// expected-error@+2 {{statement after '#pragma omp stripe' must be a for loop}}
#pragma omp stripe sizes(5,5)
for (int i = 0; i < 7; ++i) {
int k = 3;
for (int j = 0; j < 7; ++j)
;
}
// expected-error@+3 {{expected loop invariant expression}}
#pragma omp stripe sizes(5,5)
for (int i = 0; i < 7; ++i)
for (int j = i; j < 7; ++j)
;
// expected-error@+3 {{expected loop invariant expression}}
#pragma omp stripe sizes(5,5)
for (int i = 0; i < 7; ++i)
for (int j = 0; j < i; ++j)
;
// expected-error@+3 {{expected loop invariant expression}}
#pragma omp stripe sizes(5,5)
for (int i = 0; i < 7; ++i)
for (int j = 0; j < i; ++j)
;
// expected-error@+5 {{expected 3 for loops after '#pragma omp for', but found only 2}}
// expected-note@+1 {{as specified in 'collapse' clause}}
#pragma omp for collapse(3)
#pragma omp stripe sizes(5)
for (int i = 0; i < 7; ++i)
;
// expected-error@+2 {{statement after '#pragma omp stripe' must be a for loop}}
#pragma omp stripe sizes(5)
#pragma omp for
for (int i = 0; i < 7; ++i)
;
// expected-error@+2 {{condition of OpenMP for loop must be a relational comparison ('<', '<=', '>', '>=', or '!=') of loop variable 'i'}}
#pragma omp stripe sizes(5)
for (int i = 0; i/3<7; ++i)
;
// expected-error@+2 {{expression must have integral or unscoped enumeration type, not 'struct S'}}
struct S{} s;
#pragma omp stripe sizes(s)
for (int i = 0; i < 7; ++i)
;
}
template <typename T>
static void templated_func() {
// In a template context, but expression itself not instantiation-dependent
// expected-error@+1 {{argument to 'sizes' clause must be a strictly positive integer value}}
#pragma omp stripe sizes(0)
for (int i = 0; i < 7; ++i)
;
}
template <int S>
static void templated_func_value_dependent() {
// expected-error@+1 {{argument to 'sizes' clause must be a strictly positive integer value}}
#pragma omp stripe sizes(S)
for (int i = 0; i < 7; ++i)
;
}
template <typename T>
static void templated_func_type_dependent() {
constexpr T s = 0;
// expected-error@+1 {{argument to 'sizes' clause must be a strictly positive integer value}}
#pragma omp stripe sizes(s)
for (int i = 0; i < 7; ++i)
;
}
void template_inst() {
templated_func<int>();
// expected-note@+1 {{in instantiation of function template specialization 'templated_func_value_dependent<0>' requested here}}
templated_func_value_dependent<0>();
// expected-note@+1 {{in instantiation of function template specialization 'templated_func_type_dependent<int>' requested here}}
templated_func_type_dependent<int>();
}

View File

@ -2203,6 +2203,7 @@ public:
void
VisitOMPLoopTransformationDirective(const OMPLoopTransformationDirective *D);
void VisitOMPTileDirective(const OMPTileDirective *D);
void VisitOMPStripeDirective(const OMPStripeDirective *D);
void VisitOMPUnrollDirective(const OMPUnrollDirective *D);
void VisitOMPReverseDirective(const OMPReverseDirective *D);
void VisitOMPInterchangeDirective(const OMPInterchangeDirective *D);
@ -3334,6 +3335,10 @@ void EnqueueVisitor::VisitOMPTileDirective(const OMPTileDirective *D) {
VisitOMPLoopTransformationDirective(D);
}
void EnqueueVisitor::VisitOMPStripeDirective(const OMPStripeDirective *D) {
VisitOMPLoopTransformationDirective(D);
}
void EnqueueVisitor::VisitOMPUnrollDirective(const OMPUnrollDirective *D) {
VisitOMPLoopTransformationDirective(D);
}
@ -6286,6 +6291,8 @@ CXString clang_getCursorKindSpelling(enum CXCursorKind Kind) {
return cxstring::createRef("OMPSimdDirective");
case CXCursor_OMPTileDirective:
return cxstring::createRef("OMPTileDirective");
case CXCursor_OMPStripeDirective:
return cxstring::createRef("OMPStripeDirective");
case CXCursor_OMPUnrollDirective:
return cxstring::createRef("OMPUnrollDirective");
case CXCursor_OMPReverseDirective:

View File

@ -677,6 +677,9 @@ CXCursor cxcursor::MakeCXCursor(const Stmt *S, const Decl *Parent,
case Stmt::OMPTileDirectiveClass:
K = CXCursor_OMPTileDirective;
break;
case Stmt::OMPStripeDirectiveClass:
K = CXCursor_OMPStripeDirective;
break;
case Stmt::OMPUnrollDirectiveClass:
K = CXCursor_OMPUnrollDirective;
break;
@ -684,7 +687,7 @@ CXCursor cxcursor::MakeCXCursor(const Stmt *S, const Decl *Parent,
K = CXCursor_OMPReverseDirective;
break;
case Stmt::OMPInterchangeDirectiveClass:
K = CXCursor_OMPTileDirective;
K = CXCursor_OMPInterchangeDirective;
break;
case Stmt::OMPForDirectiveClass:
K = CXCursor_OMPForDirective;

View File

@ -1195,6 +1195,13 @@ def OMP_Tile : Directive<"tile"> {
let association = AS_Loop;
let category = CA_Executable;
}
def OMP_Stripe : Directive<"stripe"> {
let allowedOnceClauses = [
VersionedClause<OMPC_Sizes, 60>,
];
let association = AS_Loop;
let category = CA_Executable;
}
def OMP_Unknown : Directive<"unknown"> {
let isDefault = true;
let association = AS_None;