Skip to content

Commit 26fbbfd

Browse files
authored
[NFC][Clang] Simplify getTrailingObjects for OpenACC/OpenMP Clause (#139838)
Simplify usage of `getTrailingObjects` for OpenACC/OpenMP Clause by using either the non-templated form for single trailing types or using the single argument form that returns an ArrayRef/MutableArrayRef.
1 parent 9a0e1c7 commit 26fbbfd

File tree

3 files changed

+51
-72
lines changed

3 files changed

+51
-72
lines changed

clang/include/clang/AST/OpenACCClause.h

Lines changed: 27 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ class OpenACCDeviceTypeClause final
293293
"Only a single asterisk version is permitted, and must be the "
294294
"only one");
295295

296-
llvm::uninitialized_copy(Archs, getTrailingObjects<DeviceTypeArgument>());
296+
llvm::uninitialized_copy(Archs, getTrailingObjects());
297297
}
298298

299299
public:
@@ -307,8 +307,7 @@ class OpenACCDeviceTypeClause final
307307
}
308308

309309
ArrayRef<DeviceTypeArgument> getArchitectures() const {
310-
return ArrayRef<DeviceTypeArgument>(
311-
getTrailingObjects<DeviceTypeArgument>(), NumArchs);
310+
return getTrailingObjects<DeviceTypeArgument>(NumArchs);
312311
}
313312

314313
static OpenACCDeviceTypeClause *
@@ -421,9 +420,7 @@ class OpenACCSelfClause final
421420

422421
// Intentionally internal, meant to be an implementation detail of everything
423422
// else. All non-internal uses should go through getConditionExpr/getVarList.
424-
llvm::ArrayRef<Expr *> getExprs() const {
425-
return {getTrailingObjects<Expr *>(), NumExprs};
426-
}
423+
ArrayRef<Expr *> getExprs() const { return getTrailingObjects(NumExprs); }
427424

428425
public:
429426
static bool classof(const OpenACCClause *C) {
@@ -472,8 +469,8 @@ class OpenACCSelfClause final
472469

473470
child_range children() {
474471
return child_range(
475-
reinterpret_cast<Stmt **>(getTrailingObjects<Expr *>()),
476-
reinterpret_cast<Stmt **>(getTrailingObjects<Expr *>() + NumExprs));
472+
reinterpret_cast<Stmt **>(getTrailingObjects()),
473+
reinterpret_cast<Stmt **>(getTrailingObjects() + NumExprs));
477474
}
478475

479476
const_child_range children() const {
@@ -546,10 +543,10 @@ class OpenACCWaitClause final
546543
QueuesLoc(QueuesLoc) {
547544
// The first element of the trailing storage is always the devnum expr,
548545
// whether it is used or not.
549-
auto *Exprs = getTrailingObjects<Expr *>();
546+
auto *Exprs = getTrailingObjects();
550547
llvm::uninitialized_copy(ArrayRef(DevNumExpr), Exprs);
551548
llvm::uninitialized_copy(QueueIdExprs, Exprs + 1);
552-
setExprs(getTrailingObjects<Expr *>(QueueIdExprs.size() + 1));
549+
setExprs(getTrailingObjects(QueueIdExprs.size() + 1));
553550
}
554551

555552
public:
@@ -586,7 +583,7 @@ class OpenACCNumGangsClause final
586583
ArrayRef<Expr *> IntExprs, SourceLocation EndLoc)
587584
: OpenACCClauseWithExprs(OpenACCClauseKind::NumGangs, BeginLoc, LParenLoc,
588585
EndLoc) {
589-
setExprs(getTrailingObjects<Expr *>(IntExprs.size()), IntExprs);
586+
setExprs(getTrailingObjects(IntExprs.size()), IntExprs);
590587
}
591588

592589
public:
@@ -614,7 +611,7 @@ class OpenACCTileClause final
614611
ArrayRef<Expr *> SizeExprs, SourceLocation EndLoc)
615612
: OpenACCClauseWithExprs(OpenACCClauseKind::Tile, BeginLoc, LParenLoc,
616613
EndLoc) {
617-
setExprs(getTrailingObjects<Expr *>(SizeExprs.size()), SizeExprs);
614+
setExprs(getTrailingObjects(SizeExprs.size()), SizeExprs);
618615
}
619616

620617
public:
@@ -851,7 +848,7 @@ class OpenACCPrivateClause final
851848
ArrayRef<Expr *> VarList, SourceLocation EndLoc)
852849
: OpenACCClauseWithVarList(OpenACCClauseKind::Private, BeginLoc,
853850
LParenLoc, EndLoc) {
854-
setExprs(getTrailingObjects<Expr *>(VarList.size()), VarList);
851+
setExprs(getTrailingObjects(VarList.size()), VarList);
855852
}
856853

857854
public:
@@ -872,7 +869,7 @@ class OpenACCFirstPrivateClause final
872869
ArrayRef<Expr *> VarList, SourceLocation EndLoc)
873870
: OpenACCClauseWithVarList(OpenACCClauseKind::FirstPrivate, BeginLoc,
874871
LParenLoc, EndLoc) {
875-
setExprs(getTrailingObjects<Expr *>(VarList.size()), VarList);
872+
setExprs(getTrailingObjects(VarList.size()), VarList);
876873
}
877874

878875
public:
@@ -893,7 +890,7 @@ class OpenACCDevicePtrClause final
893890
ArrayRef<Expr *> VarList, SourceLocation EndLoc)
894891
: OpenACCClauseWithVarList(OpenACCClauseKind::DevicePtr, BeginLoc,
895892
LParenLoc, EndLoc) {
896-
setExprs(getTrailingObjects<Expr *>(VarList.size()), VarList);
893+
setExprs(getTrailingObjects(VarList.size()), VarList);
897894
}
898895

899896
public:
@@ -914,7 +911,7 @@ class OpenACCAttachClause final
914911
ArrayRef<Expr *> VarList, SourceLocation EndLoc)
915912
: OpenACCClauseWithVarList(OpenACCClauseKind::Attach, BeginLoc, LParenLoc,
916913
EndLoc) {
917-
setExprs(getTrailingObjects<Expr *>(VarList.size()), VarList);
914+
setExprs(getTrailingObjects(VarList.size()), VarList);
918915
}
919916

920917
public:
@@ -935,7 +932,7 @@ class OpenACCDetachClause final
935932
ArrayRef<Expr *> VarList, SourceLocation EndLoc)
936933
: OpenACCClauseWithVarList(OpenACCClauseKind::Detach, BeginLoc, LParenLoc,
937934
EndLoc) {
938-
setExprs(getTrailingObjects<Expr *>(VarList.size()), VarList);
935+
setExprs(getTrailingObjects(VarList.size()), VarList);
939936
}
940937

941938
public:
@@ -956,7 +953,7 @@ class OpenACCDeleteClause final
956953
ArrayRef<Expr *> VarList, SourceLocation EndLoc)
957954
: OpenACCClauseWithVarList(OpenACCClauseKind::Delete, BeginLoc, LParenLoc,
958955
EndLoc) {
959-
setExprs(getTrailingObjects<Expr *>(VarList.size()), VarList);
956+
setExprs(getTrailingObjects(VarList.size()), VarList);
960957
}
961958

962959
public:
@@ -977,7 +974,7 @@ class OpenACCUseDeviceClause final
977974
ArrayRef<Expr *> VarList, SourceLocation EndLoc)
978975
: OpenACCClauseWithVarList(OpenACCClauseKind::UseDevice, BeginLoc,
979976
LParenLoc, EndLoc) {
980-
setExprs(getTrailingObjects<Expr *>(VarList.size()), VarList);
977+
setExprs(getTrailingObjects(VarList.size()), VarList);
981978
}
982979

983980
public:
@@ -998,7 +995,7 @@ class OpenACCNoCreateClause final
998995
ArrayRef<Expr *> VarList, SourceLocation EndLoc)
999996
: OpenACCClauseWithVarList(OpenACCClauseKind::NoCreate, BeginLoc,
1000997
LParenLoc, EndLoc) {
1001-
setExprs(getTrailingObjects<Expr *>(VarList.size()), VarList);
998+
setExprs(getTrailingObjects(VarList.size()), VarList);
1002999
}
10031000

10041001
public:
@@ -1019,7 +1016,7 @@ class OpenACCPresentClause final
10191016
ArrayRef<Expr *> VarList, SourceLocation EndLoc)
10201017
: OpenACCClauseWithVarList(OpenACCClauseKind::Present, BeginLoc,
10211018
LParenLoc, EndLoc) {
1022-
setExprs(getTrailingObjects<Expr *>(VarList.size()), VarList);
1019+
setExprs(getTrailingObjects(VarList.size()), VarList);
10231020
}
10241021

10251022
public:
@@ -1039,7 +1036,7 @@ class OpenACCHostClause final
10391036
ArrayRef<Expr *> VarList, SourceLocation EndLoc)
10401037
: OpenACCClauseWithVarList(OpenACCClauseKind::Host, BeginLoc, LParenLoc,
10411038
EndLoc) {
1042-
setExprs(getTrailingObjects<Expr *>(VarList.size()), VarList);
1039+
setExprs(getTrailingObjects(VarList.size()), VarList);
10431040
}
10441041

10451042
public:
@@ -1061,7 +1058,7 @@ class OpenACCDeviceClause final
10611058
ArrayRef<Expr *> VarList, SourceLocation EndLoc)
10621059
: OpenACCClauseWithVarList(OpenACCClauseKind::Device, BeginLoc, LParenLoc,
10631060
EndLoc) {
1064-
setExprs(getTrailingObjects<Expr *>(VarList.size()), VarList);
1061+
setExprs(getTrailingObjects(VarList.size()), VarList);
10651062
}
10661063

10671064
public:
@@ -1088,7 +1085,7 @@ class OpenACCCopyClause final
10881085
Spelling == OpenACCClauseKind::PCopy ||
10891086
Spelling == OpenACCClauseKind::PresentOrCopy) &&
10901087
"Invalid clause kind for copy-clause");
1091-
setExprs(getTrailingObjects<Expr *>(VarList.size()), VarList);
1088+
setExprs(getTrailingObjects(VarList.size()), VarList);
10921089
}
10931090

10941091
public:
@@ -1121,7 +1118,7 @@ class OpenACCCopyInClause final
11211118
Spelling == OpenACCClauseKind::PCopyIn ||
11221119
Spelling == OpenACCClauseKind::PresentOrCopyIn) &&
11231120
"Invalid clause kind for copyin-clause");
1124-
setExprs(getTrailingObjects<Expr *>(VarList.size()), VarList);
1121+
setExprs(getTrailingObjects(VarList.size()), VarList);
11251122
}
11261123

11271124
public:
@@ -1153,7 +1150,7 @@ class OpenACCCopyOutClause final
11531150
Spelling == OpenACCClauseKind::PCopyOut ||
11541151
Spelling == OpenACCClauseKind::PresentOrCopyOut) &&
11551152
"Invalid clause kind for copyout-clause");
1156-
setExprs(getTrailingObjects<Expr *>(VarList.size()), VarList);
1153+
setExprs(getTrailingObjects(VarList.size()), VarList);
11571154
}
11581155

11591156
public:
@@ -1185,7 +1182,7 @@ class OpenACCCreateClause final
11851182
Spelling == OpenACCClauseKind::PCreate ||
11861183
Spelling == OpenACCClauseKind::PresentOrCreate) &&
11871184
"Invalid clause kind for create-clause");
1188-
setExprs(getTrailingObjects<Expr *>(VarList.size()), VarList);
1185+
setExprs(getTrailingObjects(VarList.size()), VarList);
11891186
}
11901187

11911188
public:
@@ -1214,7 +1211,7 @@ class OpenACCReductionClause final
12141211
: OpenACCClauseWithVarList(OpenACCClauseKind::Reduction, BeginLoc,
12151212
LParenLoc, EndLoc),
12161213
Op(Operator) {
1217-
setExprs(getTrailingObjects<Expr *>(VarList.size()), VarList);
1214+
setExprs(getTrailingObjects(VarList.size()), VarList);
12181215
}
12191216

12201217
public:
@@ -1239,7 +1236,7 @@ class OpenACCLinkClause final
12391236
ArrayRef<Expr *> VarList, SourceLocation EndLoc)
12401237
: OpenACCClauseWithVarList(OpenACCClauseKind::Link, BeginLoc, LParenLoc,
12411238
EndLoc) {
1242-
setExprs(getTrailingObjects<Expr *>(VarList.size()), VarList);
1239+
setExprs(getTrailingObjects(VarList.size()), VarList);
12431240
}
12441241

12451242
public:
@@ -1262,7 +1259,7 @@ class OpenACCDeviceResidentClause final
12621259
ArrayRef<Expr *> VarList, SourceLocation EndLoc)
12631260
: OpenACCClauseWithVarList(OpenACCClauseKind::DeviceResident, BeginLoc,
12641261
LParenLoc, EndLoc) {
1265-
setExprs(getTrailingObjects<Expr *>(VarList.size()), VarList);
1262+
setExprs(getTrailingObjects(VarList.size()), VarList);
12661263
}
12671264

12681265
public:

clang/include/clang/AST/OpenMPClause.h

Lines changed: 22 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -295,8 +295,7 @@ template <class T> class OMPVarListClause : public OMPClause {
295295

296296
/// Fetches list of variables associated with this clause.
297297
MutableArrayRef<Expr *> getVarRefs() {
298-
return MutableArrayRef<Expr *>(
299-
static_cast<T *>(this)->template getTrailingObjects<Expr *>(), NumVars);
298+
return static_cast<T *>(this)->template getTrailingObjects<Expr *>(NumVars);
300299
}
301300

302301
/// Sets the list of variables for this clause.
@@ -336,8 +335,7 @@ template <class T> class OMPVarListClause : public OMPClause {
336335

337336
/// Fetches list of all variables in the clause.
338337
ArrayRef<const Expr *> getVarRefs() const {
339-
return llvm::ArrayRef(
340-
static_cast<const T *>(this)->template getTrailingObjects<Expr *>(),
338+
return static_cast<const T *>(this)->template getTrailingObjects<Expr *>(
341339
NumVars);
342340
}
343341
};
@@ -382,10 +380,8 @@ template <class T> class OMPDirectiveListClause : public OMPClause {
382380
}
383381

384382
MutableArrayRef<OpenMPDirectiveKind> getDirectiveKinds() {
385-
return MutableArrayRef<OpenMPDirectiveKind>(
386-
static_cast<T *>(this)
387-
->template getTrailingObjects<OpenMPDirectiveKind>(),
388-
NumKinds);
383+
return static_cast<T *>(this)
384+
->template getTrailingObjects<OpenMPDirectiveKind>(NumKinds);
389385
}
390386

391387
void setDirectiveKinds(ArrayRef<OpenMPDirectiveKind> DK) {
@@ -984,14 +980,12 @@ class OMPSizesClause final
984980

985981
/// Returns the tile size expressions.
986982
MutableArrayRef<Expr *> getSizesRefs() {
987-
return MutableArrayRef<Expr *>(static_cast<OMPSizesClause *>(this)
988-
->template getTrailingObjects<Expr *>(),
989-
NumSizes);
983+
return static_cast<OMPSizesClause *>(this)
984+
->template getTrailingObjects<Expr *>(NumSizes);
990985
}
991986
ArrayRef<Expr *> getSizesRefs() const {
992-
return ArrayRef<Expr *>(static_cast<const OMPSizesClause *>(this)
993-
->template getTrailingObjects<Expr *>(),
994-
NumSizes);
987+
return static_cast<const OMPSizesClause *>(this)
988+
->template getTrailingObjects<Expr *>(NumSizes);
995989
}
996990

997991
/// Sets the tile size expressions.
@@ -1090,14 +1084,12 @@ class OMPPermutationClause final
10901084
/// Returns the permutation index expressions.
10911085
///@{
10921086
MutableArrayRef<Expr *> getArgsRefs() {
1093-
return MutableArrayRef<Expr *>(static_cast<OMPPermutationClause *>(this)
1094-
->template getTrailingObjects<Expr *>(),
1095-
NumLoops);
1087+
return static_cast<OMPPermutationClause *>(this)
1088+
->template getTrailingObjects<Expr *>(NumLoops);
10961089
}
10971090
ArrayRef<Expr *> getArgsRefs() const {
1098-
return ArrayRef<Expr *>(static_cast<const OMPPermutationClause *>(this)
1099-
->template getTrailingObjects<Expr *>(),
1100-
NumLoops);
1091+
return static_cast<const OMPPermutationClause *>(this)
1092+
->template getTrailingObjects<Expr *>(NumLoops);
11011093
}
11021094
///@}
11031095

@@ -3841,7 +3833,7 @@ class OMPReductionClause final
38413833
return MutableArrayRef<Expr *>(getLHSExprs().end(), varlist_size());
38423834
}
38433835
ArrayRef<const Expr *> getRHSExprs() const {
3844-
return llvm::ArrayRef(getLHSExprs().end(), varlist_size());
3836+
return ArrayRef(getLHSExprs().end(), varlist_size());
38453837
}
38463838

38473839
/// Set list of helper reduction expressions, required for proper
@@ -5925,18 +5917,15 @@ class OMPMappableExprListClause : public OMPVarListClause<T>,
59255917
/// Get the unique declarations that are in the trailing objects of the
59265918
/// class.
59275919
MutableArrayRef<ValueDecl *> getUniqueDeclsRef() {
5928-
return MutableArrayRef<ValueDecl *>(
5929-
static_cast<T *>(this)->template getTrailingObjects<ValueDecl *>(),
5920+
return static_cast<T *>(this)->template getTrailingObjects<ValueDecl *>(
59305921
NumUniqueDeclarations);
59315922
}
59325923

59335924
/// Get the unique declarations that are in the trailing objects of the
59345925
/// class.
59355926
ArrayRef<ValueDecl *> getUniqueDeclsRef() const {
5936-
return ArrayRef<ValueDecl *>(
5937-
static_cast<const T *>(this)
5938-
->template getTrailingObjects<ValueDecl *>(),
5939-
NumUniqueDeclarations);
5927+
return static_cast<const T *>(this)
5928+
->template getTrailingObjects<ValueDecl *>(NumUniqueDeclarations);
59405929
}
59415930

59425931
/// Set the unique declarations that are in the trailing objects of the
@@ -5950,16 +5939,14 @@ class OMPMappableExprListClause : public OMPVarListClause<T>,
59505939
/// Get the number of lists per declaration that are in the trailing
59515940
/// objects of the class.
59525941
MutableArrayRef<unsigned> getDeclNumListsRef() {
5953-
return MutableArrayRef<unsigned>(
5954-
static_cast<T *>(this)->template getTrailingObjects<unsigned>(),
5942+
return static_cast<T *>(this)->template getTrailingObjects<unsigned>(
59555943
NumUniqueDeclarations);
59565944
}
59575945

59585946
/// Get the number of lists per declaration that are in the trailing
59595947
/// objects of the class.
59605948
ArrayRef<unsigned> getDeclNumListsRef() const {
5961-
return ArrayRef<unsigned>(
5962-
static_cast<const T *>(this)->template getTrailingObjects<unsigned>(),
5949+
return static_cast<const T *>(this)->template getTrailingObjects<unsigned>(
59635950
NumUniqueDeclarations);
59645951
}
59655952

@@ -5999,18 +5986,14 @@ class OMPMappableExprListClause : public OMPVarListClause<T>,
59995986

60005987
/// Get the components that are in the trailing objects of the class.
60015988
MutableArrayRef<MappableComponent> getComponentsRef() {
6002-
return MutableArrayRef<MappableComponent>(
6003-
static_cast<T *>(this)
6004-
->template getTrailingObjects<MappableComponent>(),
6005-
NumComponents);
5989+
return static_cast<T *>(this)
5990+
->template getTrailingObjects<MappableComponent>(NumComponents);
60065991
}
60075992

60085993
/// Get the components that are in the trailing objects of the class.
60095994
ArrayRef<MappableComponent> getComponentsRef() const {
6010-
return ArrayRef<MappableComponent>(
6011-
static_cast<const T *>(this)
6012-
->template getTrailingObjects<MappableComponent>(),
6013-
NumComponents);
5995+
return static_cast<const T *>(this)
5996+
->template getTrailingObjects<MappableComponent>(NumComponents);
60145997
}
60155998

60165999
/// Set the components that are in the trailing objects of the class.

clang/lib/AST/OpenACCClause.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ OpenACCSelfClause::OpenACCSelfClause(SourceLocation BeginLoc,
114114
: OpenACCClauseWithParams(OpenACCClauseKind::Self, BeginLoc, LParenLoc,
115115
EndLoc),
116116
HasConditionExpr(std::nullopt), NumExprs(VarList.size()) {
117-
llvm::uninitialized_copy(VarList, getTrailingObjects<Expr *>());
117+
llvm::uninitialized_copy(VarList, getTrailingObjects());
118118
}
119119

120120
OpenACCSelfClause::OpenACCSelfClause(SourceLocation BeginLoc,
@@ -126,8 +126,7 @@ OpenACCSelfClause::OpenACCSelfClause(SourceLocation BeginLoc,
126126
assert((!ConditionExpr || ConditionExpr->isInstantiationDependent() ||
127127
ConditionExpr->getType()->isScalarType()) &&
128128
"Condition expression type not scalar/dependent");
129-
llvm::uninitialized_copy(ArrayRef(ConditionExpr),
130-
getTrailingObjects<Expr *>());
129+
llvm::uninitialized_copy(ArrayRef(ConditionExpr), getTrailingObjects());
131130
}
132131

133132
OpenACCClause::child_range OpenACCClause::children() {

0 commit comments

Comments
 (0)