Skip to content

Commit cc6d4d5

Browse files
authored
[OpenACC][NFC] Simplify Reduction Recipe Storage (#163393)
The inheritence link between the Reduction Recipe and the version with storage made it overly complicated of an implementation for near zero gain. This patch removes that link, and uses the private constructor of the non-storage version to ensure only the 'right' ones get created in the right place.
1 parent 45495b5 commit cc6d4d5

File tree

2 files changed

+11
-32
lines changed

2 files changed

+11
-32
lines changed

clang/include/clang/AST/OpenACCClause.h

Lines changed: 10 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1301,46 +1301,25 @@ struct OpenACCReductionRecipe {
13011301
// AST), or in a separate collection when being semantically analyzed.
13021302
llvm::ArrayRef<CombinerRecipe> CombinerRecipes;
13031303

1304+
bool isSet() const { return AllocaDecl; }
1305+
1306+
private:
1307+
friend class OpenACCReductionClause;
13041308
OpenACCReductionRecipe(VarDecl *A, llvm::ArrayRef<CombinerRecipe> Combiners)
13051309
: AllocaDecl(A), CombinerRecipes(Combiners) {}
1306-
1307-
bool isSet() const { return AllocaDecl; }
13081310
};
13091311

13101312
// A version of the above that is used for semantic analysis, at a time before
13111313
// the OpenACCReductionClause node has been created. This one has storage for
13121314
// the CombinerRecipe, since Trailing storage for it doesn't exist yet.
1313-
struct OpenACCReductionRecipeWithStorage : OpenACCReductionRecipe {
1314-
private:
1315-
llvm::SmallVector<CombinerRecipe, 1> CombinerRecipeStorage;
1316-
1317-
public:
1318-
OpenACCReductionRecipeWithStorage(VarDecl *A,
1319-
llvm::ArrayRef<CombinerRecipe> Combiners)
1320-
: OpenACCReductionRecipe(A, {}), CombinerRecipeStorage(Combiners) {
1321-
CombinerRecipes = CombinerRecipeStorage;
1322-
}
1315+
struct OpenACCReductionRecipeWithStorage {
1316+
VarDecl *AllocaDecl;
1317+
llvm::SmallVector<OpenACCReductionRecipe::CombinerRecipe, 1> CombinerRecipes;
13231318

13241319
OpenACCReductionRecipeWithStorage(
1325-
const OpenACCReductionRecipeWithStorage &Other)
1326-
: OpenACCReductionRecipe(Other),
1327-
CombinerRecipeStorage(Other.CombinerRecipeStorage) {
1328-
CombinerRecipes = CombinerRecipeStorage;
1329-
}
1330-
1331-
OpenACCReductionRecipeWithStorage(OpenACCReductionRecipeWithStorage &&Other)
1332-
: OpenACCReductionRecipe(std::move(Other)),
1333-
CombinerRecipeStorage(std::move(Other.CombinerRecipeStorage)) {
1334-
CombinerRecipes = CombinerRecipeStorage;
1335-
}
1336-
1337-
// There is no real problem implementing these, we just have to make sure the
1338-
// array-ref this inherits from stays in sync. But as we don't need it at the
1339-
// moment, make sure we don't accidentially call these.
1340-
OpenACCReductionRecipeWithStorage &
1341-
operator=(OpenACCReductionRecipeWithStorage &&) = delete;
1342-
OpenACCReductionRecipeWithStorage &
1343-
operator=(const OpenACCReductionRecipeWithStorage &) = delete;
1320+
VarDecl *A,
1321+
llvm::ArrayRef<OpenACCReductionRecipe::CombinerRecipe> Combiners)
1322+
: AllocaDecl(A), CombinerRecipes(Combiners) {}
13441323

13451324
static OpenACCReductionRecipeWithStorage Empty() {
13461325
return OpenACCReductionRecipeWithStorage(/*AllocaDecl=*/nullptr, {});

clang/lib/AST/OpenACCClause.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -509,7 +509,7 @@ OpenACCReductionClause *OpenACCReductionClause::Create(
509509
ArrayRef<OpenACCReductionRecipeWithStorage> Recipes,
510510
SourceLocation EndLoc) {
511511
size_t NumCombiners = llvm::accumulate(
512-
Recipes, 0, [](size_t Num, const OpenACCReductionRecipe &R) {
512+
Recipes, 0, [](size_t Num, const OpenACCReductionRecipeWithStorage &R) {
513513
return Num + R.CombinerRecipes.size();
514514
});
515515

0 commit comments

Comments
 (0)