Skip to content

Commit 5f41928

Browse files
authored
[NFC][Clang] Add setExprs overload to reduce some code duplication (#139749)
Add a `setExprs` overload to `OpenACCClauseWithExprs` that allows initializing the trailing storage to help eliminate some code duplication in various subclass constructors.
1 parent f965996 commit 5f41928

File tree

2 files changed

+29
-42
lines changed

2 files changed

+29
-42
lines changed

clang/include/clang/AST/OpenACCClause.h

Lines changed: 28 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -506,6 +506,14 @@ class OpenACCClauseWithExprs : public OpenACCClauseWithParams {
506506
Exprs = NewExprs;
507507
}
508508

509+
/// Used only for initialization, the leaf class can initialize this to
510+
/// trailing storage, and initialize the data in the trailing storage as well.
511+
void setExprs(MutableArrayRef<Expr *> NewStorage, ArrayRef<Expr *> Exprs) {
512+
assert(NewStorage.size() == Exprs.size());
513+
llvm::uninitialized_copy(Exprs, NewStorage.begin());
514+
setExprs(NewStorage);
515+
}
516+
509517
/// Gets the entire list of expressions, but leave it to the
510518
/// individual clauses to expose this how they'd like.
511519
llvm::ArrayRef<Expr *> getExprs() const { return Exprs; }
@@ -578,8 +586,7 @@ class OpenACCNumGangsClause final
578586
ArrayRef<Expr *> IntExprs, SourceLocation EndLoc)
579587
: OpenACCClauseWithExprs(OpenACCClauseKind::NumGangs, BeginLoc, LParenLoc,
580588
EndLoc) {
581-
llvm::uninitialized_copy(IntExprs, getTrailingObjects<Expr *>());
582-
setExprs(getTrailingObjects<Expr *>(IntExprs.size()));
589+
setExprs(getTrailingObjects<Expr *>(IntExprs.size()), IntExprs);
583590
}
584591

585592
public:
@@ -607,8 +614,7 @@ class OpenACCTileClause final
607614
ArrayRef<Expr *> SizeExprs, SourceLocation EndLoc)
608615
: OpenACCClauseWithExprs(OpenACCClauseKind::Tile, BeginLoc, LParenLoc,
609616
EndLoc) {
610-
llvm::uninitialized_copy(SizeExprs, getTrailingObjects<Expr *>());
611-
setExprs(getTrailingObjects<Expr *>(SizeExprs.size()));
617+
setExprs(getTrailingObjects<Expr *>(SizeExprs.size()), SizeExprs);
612618
}
613619

614620
public:
@@ -845,8 +851,7 @@ class OpenACCPrivateClause final
845851
ArrayRef<Expr *> VarList, SourceLocation EndLoc)
846852
: OpenACCClauseWithVarList(OpenACCClauseKind::Private, BeginLoc,
847853
LParenLoc, EndLoc) {
848-
llvm::uninitialized_copy(VarList, getTrailingObjects<Expr *>());
849-
setExprs(getTrailingObjects<Expr *>(VarList.size()));
854+
setExprs(getTrailingObjects<Expr *>(VarList.size()), VarList);
850855
}
851856

852857
public:
@@ -867,8 +872,7 @@ class OpenACCFirstPrivateClause final
867872
ArrayRef<Expr *> VarList, SourceLocation EndLoc)
868873
: OpenACCClauseWithVarList(OpenACCClauseKind::FirstPrivate, BeginLoc,
869874
LParenLoc, EndLoc) {
870-
llvm::uninitialized_copy(VarList, getTrailingObjects<Expr *>());
871-
setExprs(getTrailingObjects<Expr *>(VarList.size()));
875+
setExprs(getTrailingObjects<Expr *>(VarList.size()), VarList);
872876
}
873877

874878
public:
@@ -889,8 +893,7 @@ class OpenACCDevicePtrClause final
889893
ArrayRef<Expr *> VarList, SourceLocation EndLoc)
890894
: OpenACCClauseWithVarList(OpenACCClauseKind::DevicePtr, BeginLoc,
891895
LParenLoc, EndLoc) {
892-
llvm::uninitialized_copy(VarList, getTrailingObjects<Expr *>());
893-
setExprs(getTrailingObjects<Expr *>(VarList.size()));
896+
setExprs(getTrailingObjects<Expr *>(VarList.size()), VarList);
894897
}
895898

896899
public:
@@ -911,8 +914,7 @@ class OpenACCAttachClause final
911914
ArrayRef<Expr *> VarList, SourceLocation EndLoc)
912915
: OpenACCClauseWithVarList(OpenACCClauseKind::Attach, BeginLoc, LParenLoc,
913916
EndLoc) {
914-
llvm::uninitialized_copy(VarList, getTrailingObjects<Expr *>());
915-
setExprs(getTrailingObjects<Expr *>(VarList.size()));
917+
setExprs(getTrailingObjects<Expr *>(VarList.size()), VarList);
916918
}
917919

918920
public:
@@ -933,8 +935,7 @@ class OpenACCDetachClause final
933935
ArrayRef<Expr *> VarList, SourceLocation EndLoc)
934936
: OpenACCClauseWithVarList(OpenACCClauseKind::Detach, BeginLoc, LParenLoc,
935937
EndLoc) {
936-
llvm::uninitialized_copy(VarList, getTrailingObjects<Expr *>());
937-
setExprs(getTrailingObjects<Expr *>(VarList.size()));
938+
setExprs(getTrailingObjects<Expr *>(VarList.size()), VarList);
938939
}
939940

940941
public:
@@ -955,8 +956,7 @@ class OpenACCDeleteClause final
955956
ArrayRef<Expr *> VarList, SourceLocation EndLoc)
956957
: OpenACCClauseWithVarList(OpenACCClauseKind::Delete, BeginLoc, LParenLoc,
957958
EndLoc) {
958-
llvm::uninitialized_copy(VarList, getTrailingObjects<Expr *>());
959-
setExprs(getTrailingObjects<Expr *>(VarList.size()));
959+
setExprs(getTrailingObjects<Expr *>(VarList.size()), VarList);
960960
}
961961

962962
public:
@@ -977,8 +977,7 @@ class OpenACCUseDeviceClause final
977977
ArrayRef<Expr *> VarList, SourceLocation EndLoc)
978978
: OpenACCClauseWithVarList(OpenACCClauseKind::UseDevice, BeginLoc,
979979
LParenLoc, EndLoc) {
980-
llvm::uninitialized_copy(VarList, getTrailingObjects<Expr *>());
981-
setExprs(getTrailingObjects<Expr *>(VarList.size()));
980+
setExprs(getTrailingObjects<Expr *>(VarList.size()), VarList);
982981
}
983982

984983
public:
@@ -999,8 +998,7 @@ class OpenACCNoCreateClause final
999998
ArrayRef<Expr *> VarList, SourceLocation EndLoc)
1000999
: OpenACCClauseWithVarList(OpenACCClauseKind::NoCreate, BeginLoc,
10011000
LParenLoc, EndLoc) {
1002-
llvm::uninitialized_copy(VarList, getTrailingObjects<Expr *>());
1003-
setExprs(getTrailingObjects<Expr *>(VarList.size()));
1001+
setExprs(getTrailingObjects<Expr *>(VarList.size()), VarList);
10041002
}
10051003

10061004
public:
@@ -1021,8 +1019,7 @@ class OpenACCPresentClause final
10211019
ArrayRef<Expr *> VarList, SourceLocation EndLoc)
10221020
: OpenACCClauseWithVarList(OpenACCClauseKind::Present, BeginLoc,
10231021
LParenLoc, EndLoc) {
1024-
llvm::uninitialized_copy(VarList, getTrailingObjects<Expr *>());
1025-
setExprs(getTrailingObjects<Expr *>(VarList.size()));
1022+
setExprs(getTrailingObjects<Expr *>(VarList.size()), VarList);
10261023
}
10271024

10281025
public:
@@ -1042,8 +1039,7 @@ class OpenACCHostClause final
10421039
ArrayRef<Expr *> VarList, SourceLocation EndLoc)
10431040
: OpenACCClauseWithVarList(OpenACCClauseKind::Host, BeginLoc, LParenLoc,
10441041
EndLoc) {
1045-
llvm::uninitialized_copy(VarList, getTrailingObjects<Expr *>());
1046-
setExprs(getTrailingObjects<Expr *>(VarList.size()));
1042+
setExprs(getTrailingObjects<Expr *>(VarList.size()), VarList);
10471043
}
10481044

10491045
public:
@@ -1065,8 +1061,7 @@ class OpenACCDeviceClause final
10651061
ArrayRef<Expr *> VarList, SourceLocation EndLoc)
10661062
: OpenACCClauseWithVarList(OpenACCClauseKind::Device, BeginLoc, LParenLoc,
10671063
EndLoc) {
1068-
llvm::uninitialized_copy(VarList, getTrailingObjects<Expr *>());
1069-
setExprs(getTrailingObjects<Expr *>(VarList.size()));
1064+
setExprs(getTrailingObjects<Expr *>(VarList.size()), VarList);
10701065
}
10711066

10721067
public:
@@ -1093,8 +1088,7 @@ class OpenACCCopyClause final
10931088
Spelling == OpenACCClauseKind::PCopy ||
10941089
Spelling == OpenACCClauseKind::PresentOrCopy) &&
10951090
"Invalid clause kind for copy-clause");
1096-
llvm::uninitialized_copy(VarList, getTrailingObjects<Expr *>());
1097-
setExprs(getTrailingObjects<Expr *>(VarList.size()));
1091+
setExprs(getTrailingObjects<Expr *>(VarList.size()), VarList);
10981092
}
10991093

11001094
public:
@@ -1127,8 +1121,7 @@ class OpenACCCopyInClause final
11271121
Spelling == OpenACCClauseKind::PCopyIn ||
11281122
Spelling == OpenACCClauseKind::PresentOrCopyIn) &&
11291123
"Invalid clause kind for copyin-clause");
1130-
llvm::uninitialized_copy(VarList, getTrailingObjects<Expr *>());
1131-
setExprs(getTrailingObjects<Expr *>(VarList.size()));
1124+
setExprs(getTrailingObjects<Expr *>(VarList.size()), VarList);
11321125
}
11331126

11341127
public:
@@ -1160,8 +1153,7 @@ class OpenACCCopyOutClause final
11601153
Spelling == OpenACCClauseKind::PCopyOut ||
11611154
Spelling == OpenACCClauseKind::PresentOrCopyOut) &&
11621155
"Invalid clause kind for copyout-clause");
1163-
llvm::uninitialized_copy(VarList, getTrailingObjects<Expr *>());
1164-
setExprs(getTrailingObjects<Expr *>(VarList.size()));
1156+
setExprs(getTrailingObjects<Expr *>(VarList.size()), VarList);
11651157
}
11661158

11671159
public:
@@ -1193,8 +1185,7 @@ class OpenACCCreateClause final
11931185
Spelling == OpenACCClauseKind::PCreate ||
11941186
Spelling == OpenACCClauseKind::PresentOrCreate) &&
11951187
"Invalid clause kind for create-clause");
1196-
llvm::uninitialized_copy(VarList, getTrailingObjects<Expr *>());
1197-
setExprs(getTrailingObjects<Expr *>(VarList.size()));
1188+
setExprs(getTrailingObjects<Expr *>(VarList.size()), VarList);
11981189
}
11991190

12001191
public:
@@ -1223,8 +1214,7 @@ class OpenACCReductionClause final
12231214
: OpenACCClauseWithVarList(OpenACCClauseKind::Reduction, BeginLoc,
12241215
LParenLoc, EndLoc),
12251216
Op(Operator) {
1226-
llvm::uninitialized_copy(VarList, getTrailingObjects<Expr *>());
1227-
setExprs(getTrailingObjects<Expr *>(VarList.size()));
1217+
setExprs(getTrailingObjects<Expr *>(VarList.size()), VarList);
12281218
}
12291219

12301220
public:
@@ -1249,8 +1239,7 @@ class OpenACCLinkClause final
12491239
ArrayRef<Expr *> VarList, SourceLocation EndLoc)
12501240
: OpenACCClauseWithVarList(OpenACCClauseKind::Link, BeginLoc, LParenLoc,
12511241
EndLoc) {
1252-
llvm::uninitialized_copy(VarList, getTrailingObjects<Expr *>());
1253-
setExprs(getTrailingObjects<Expr *>(VarList.size()));
1242+
setExprs(getTrailingObjects<Expr *>(VarList.size()), VarList);
12541243
}
12551244

12561245
public:
@@ -1273,8 +1262,7 @@ class OpenACCDeviceResidentClause final
12731262
ArrayRef<Expr *> VarList, SourceLocation EndLoc)
12741263
: OpenACCClauseWithVarList(OpenACCClauseKind::DeviceResident, BeginLoc,
12751264
LParenLoc, EndLoc) {
1276-
llvm::uninitialized_copy(VarList, getTrailingObjects<Expr *>());
1277-
setExprs(getTrailingObjects<Expr *>(VarList.size()));
1265+
setExprs(getTrailingObjects<Expr *>(VarList.size()), VarList);
12781266
}
12791267

12801268
public:

clang/lib/AST/OpenACCClause.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,8 +166,7 @@ OpenACCGangClause::OpenACCGangClause(SourceLocation BeginLoc,
166166
: OpenACCClauseWithExprs(OpenACCClauseKind::Gang, BeginLoc, LParenLoc,
167167
EndLoc) {
168168
assert(GangKinds.size() == IntExprs.size() && "Mismatch exprs/kind?");
169-
llvm::uninitialized_copy(IntExprs, getTrailingObjects<Expr *>());
170-
setExprs(getTrailingObjects<Expr *>(IntExprs.size()));
169+
setExprs(getTrailingObjects<Expr *>(IntExprs.size()), IntExprs);
171170
llvm::uninitialized_copy(GangKinds, getTrailingObjects<OpenACCGangKind>());
172171
}
173172

0 commit comments

Comments
 (0)