Skip to content

Commit d412cea

Browse files
authored
[OpenACC] Implement 'tile' attribute AST (#110999)
The 'tile' clause shares quite a bit of the rules with 'collapse', so a followup patch will add those tests/behaviors. This patch deals with adding the AST node. The 'tile' clause takes a series of integer constant expressions, or *. The asterisk is now represented by a new OpenACCAsteriskSizeExpr node, else this clause is very similar to others.
1 parent 66227bf commit d412cea

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+724
-53
lines changed

clang/include/clang/AST/ComputeDependence.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ class ObjCSubscriptRefExpr;
107107
class ObjCIsaExpr;
108108
class ObjCIndirectCopyRestoreExpr;
109109
class ObjCMessageExpr;
110+
class OpenACCAsteriskSizeExpr;
110111

111112
// The following functions are called from constructors of `Expr`, so they
112113
// should not access anything beyond basic
@@ -203,6 +204,7 @@ ExprDependence computeDependence(ObjCSubscriptRefExpr *E);
203204
ExprDependence computeDependence(ObjCIsaExpr *E);
204205
ExprDependence computeDependence(ObjCIndirectCopyRestoreExpr *E);
205206
ExprDependence computeDependence(ObjCMessageExpr *E);
207+
ExprDependence computeDependence(OpenACCAsteriskSizeExpr *E);
206208

207209
} // namespace clang
208210
#endif

clang/include/clang/AST/Expr.h

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2072,6 +2072,41 @@ class PredefinedExpr final
20722072
}
20732073
};
20742074

2075+
/// This expression type represents an asterisk in an OpenACC Size-Expr, used in
2076+
/// the 'tile' and 'gang' clauses. It is of 'int' type, but should not be
2077+
/// evaluated.
2078+
class OpenACCAsteriskSizeExpr final : public Expr {
2079+
friend class ASTStmtReader;
2080+
SourceLocation AsteriskLoc;
2081+
2082+
OpenACCAsteriskSizeExpr(SourceLocation AsteriskLoc, QualType IntTy)
2083+
: Expr(OpenACCAsteriskSizeExprClass, IntTy, VK_PRValue, OK_Ordinary),
2084+
AsteriskLoc(AsteriskLoc) {}
2085+
2086+
void setAsteriskLocation(SourceLocation Loc) { AsteriskLoc = Loc; }
2087+
2088+
public:
2089+
static OpenACCAsteriskSizeExpr *Create(const ASTContext &C,
2090+
SourceLocation Loc);
2091+
static OpenACCAsteriskSizeExpr *CreateEmpty(const ASTContext &C);
2092+
2093+
SourceLocation getBeginLoc() const { return AsteriskLoc; }
2094+
SourceLocation getEndLoc() const { return AsteriskLoc; }
2095+
SourceLocation getLocation() const { return AsteriskLoc; }
2096+
2097+
static bool classof(const Stmt *T) {
2098+
return T->getStmtClass() == OpenACCAsteriskSizeExprClass;
2099+
}
2100+
// Iterators
2101+
child_range children() {
2102+
return child_range(child_iterator(), child_iterator());
2103+
}
2104+
2105+
const_child_range children() const {
2106+
return const_child_range(const_child_iterator(), const_child_iterator());
2107+
}
2108+
};
2109+
20752110
// This represents a use of the __builtin_sycl_unique_stable_name, which takes a
20762111
// type-id, and at CodeGen time emits a unique string representation of the
20772112
// type in a way that permits us to properly encode information about the SYCL

clang/include/clang/AST/JSONNodeDumper.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,7 @@ class JSONNodeDumper
283283

284284
void VisitDeclRefExpr(const DeclRefExpr *DRE);
285285
void VisitSYCLUniqueStableNameExpr(const SYCLUniqueStableNameExpr *E);
286+
void VisitOpenACCAsteriskSizeExpr(const OpenACCAsteriskSizeExpr *E);
286287
void VisitPredefinedExpr(const PredefinedExpr *PE);
287288
void VisitUnaryOperator(const UnaryOperator *UO);
288289
void VisitBinaryOperator(const BinaryOperator *BO);

clang/include/clang/AST/OpenACCClause.h

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -481,6 +481,35 @@ class OpenACCNumGangsClause final
481481
}
482482
};
483483

484+
class OpenACCTileClause final
485+
: public OpenACCClauseWithExprs,
486+
public llvm::TrailingObjects<OpenACCTileClause, Expr *> {
487+
OpenACCTileClause(SourceLocation BeginLoc, SourceLocation LParenLoc,
488+
ArrayRef<Expr *> SizeExprs, SourceLocation EndLoc)
489+
: OpenACCClauseWithExprs(OpenACCClauseKind::Tile, BeginLoc, LParenLoc,
490+
EndLoc) {
491+
std::uninitialized_copy(SizeExprs.begin(), SizeExprs.end(),
492+
getTrailingObjects<Expr *>());
493+
setExprs(MutableArrayRef(getTrailingObjects<Expr *>(), SizeExprs.size()));
494+
}
495+
496+
public:
497+
static bool classof(const OpenACCClause *C) {
498+
return C->getClauseKind() == OpenACCClauseKind::Tile;
499+
}
500+
static OpenACCTileClause *Create(const ASTContext &C, SourceLocation BeginLoc,
501+
SourceLocation LParenLoc,
502+
ArrayRef<Expr *> SizeExprs,
503+
SourceLocation EndLoc);
504+
llvm::ArrayRef<Expr *> getSizeExprs() {
505+
return OpenACCClauseWithExprs::getExprs();
506+
}
507+
508+
llvm::ArrayRef<Expr *> getSizeExprs() const {
509+
return OpenACCClauseWithExprs::getExprs();
510+
}
511+
};
512+
484513
/// Represents one of a handful of clauses that have a single integer
485514
/// expression.
486515
class OpenACCClauseWithSingleIntExpr : public OpenACCClauseWithExprs {

clang/include/clang/AST/RecursiveASTVisitor.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2867,6 +2867,7 @@ DEF_TRAVERSE_STMT(ParenListExpr, {})
28672867
DEF_TRAVERSE_STMT(SYCLUniqueStableNameExpr, {
28682868
TRY_TO(TraverseTypeLoc(S->getTypeSourceInfo()->getTypeLoc()));
28692869
})
2870+
DEF_TRAVERSE_STMT(OpenACCAsteriskSizeExpr, {})
28702871
DEF_TRAVERSE_STMT(PredefinedExpr, {})
28712872
DEF_TRAVERSE_STMT(ShuffleVectorExpr, {})
28722873
DEF_TRAVERSE_STMT(ConvertVectorExpr, {})

clang/include/clang/AST/TextNodeDumper.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,7 @@ class TextNodeDumper
410410
void VisitHLSLOutArgExpr(const HLSLOutArgExpr *E);
411411
void VisitOpenACCConstructStmt(const OpenACCConstructStmt *S);
412412
void VisitOpenACCLoopConstruct(const OpenACCLoopConstruct *S);
413+
void VisitOpenACCAsteriskSizeExpr(const OpenACCAsteriskSizeExpr *S);
413414
void VisitEmbedExpr(const EmbedExpr *S);
414415
void VisitAtomicExpr(const AtomicExpr *AE);
415416
};

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12666,6 +12666,10 @@ def err_acc_loop_spec_conflict
1266612666
def err_acc_collapse_loop_count
1266712667
: Error<"OpenACC 'collapse' clause loop count must be a %select{constant "
1266812668
"expression|positive integer value, evaluated to %1}0">;
12669+
def err_acc_size_expr_value
12670+
: Error<
12671+
"OpenACC 'tile' clause size expression must be %select{an asterisk "
12672+
"or a constant expression|positive integer value, evaluated to %1}0">;
1266912673
def err_acc_invalid_in_collapse_loop
1267012674
: Error<"%select{OpenACC '%1' construct|while loop|do loop}0 cannot appear "
1267112675
"in intervening code of a 'loop' with a 'collapse' clause">;

clang/include/clang/Basic/OpenACCClauses.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ VISIT_CLAUSE(Private)
5252
VISIT_CLAUSE(Reduction)
5353
VISIT_CLAUSE(Self)
5454
VISIT_CLAUSE(Seq)
55+
VISIT_CLAUSE(Tile)
5556
VISIT_CLAUSE(VectorLength)
5657
VISIT_CLAUSE(Wait)
5758

clang/include/clang/Basic/StmtNodes.td

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,5 +308,8 @@ def OpenACCAssociatedStmtConstruct
308308
def OpenACCComputeConstruct : StmtNode<OpenACCAssociatedStmtConstruct>;
309309
def OpenACCLoopConstruct : StmtNode<OpenACCAssociatedStmtConstruct>;
310310

311+
// OpenACC Additional Expressions.
312+
def OpenACCAsteriskSizeExpr : StmtNode<Expr>;
313+
311314
// HLSL Constructs.
312315
def HLSLOutArgExpr : StmtNode<Expr>;

clang/include/clang/Parse/Parser.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3786,10 +3786,13 @@ class Parser : public CodeCompletionHandler {
37863786
OpenACCIntExprParseResult ParseOpenACCAsyncArgument(OpenACCDirectiveKind DK,
37873787
OpenACCClauseKind CK,
37883788
SourceLocation Loc);
3789+
37893790
/// Parses the 'size-expr', which is an integral value, or an asterisk.
3790-
bool ParseOpenACCSizeExpr();
3791+
/// Asterisk is represented by a OpenACCAsteriskSizeExpr
3792+
ExprResult ParseOpenACCSizeExpr(OpenACCClauseKind CK);
37913793
/// Parses a comma delimited list of 'size-expr's.
3792-
bool ParseOpenACCSizeExprList();
3794+
bool ParseOpenACCSizeExprList(OpenACCClauseKind CK,
3795+
llvm::SmallVectorImpl<Expr *> &SizeExprs);
37933796
/// Parses a 'gang-arg-list', used for the 'gang' clause.
37943797
bool ParseOpenACCGangArgList(SourceLocation GangLoc);
37953798
/// Parses a 'gang-arg', used for the 'gang' clause.

0 commit comments

Comments
 (0)