From 7c1e9dbba48a1eacae4e9740edf8aa3a8de3acad Mon Sep 17 00:00:00 2001 From: erichkeane Date: Tue, 14 Oct 2025 06:37:54 -0700 Subject: [PATCH] [OpenACC][NFC] Simplify Reduction Recipe Storage 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. --- clang/include/clang/AST/OpenACCClause.h | 41 ++++++------------------- clang/lib/AST/OpenACCClause.cpp | 2 +- 2 files changed, 11 insertions(+), 32 deletions(-) diff --git a/clang/include/clang/AST/OpenACCClause.h b/clang/include/clang/AST/OpenACCClause.h index 1e351f31f4b92..83f2b18435633 100644 --- a/clang/include/clang/AST/OpenACCClause.h +++ b/clang/include/clang/AST/OpenACCClause.h @@ -1301,46 +1301,25 @@ struct OpenACCReductionRecipe { // AST), or in a separate collection when being semantically analyzed. llvm::ArrayRef CombinerRecipes; + bool isSet() const { return AllocaDecl; } + +private: + friend class OpenACCReductionClause; OpenACCReductionRecipe(VarDecl *A, llvm::ArrayRef Combiners) : AllocaDecl(A), CombinerRecipes(Combiners) {} - - bool isSet() const { return AllocaDecl; } }; // A version of the above that is used for semantic analysis, at a time before // the OpenACCReductionClause node has been created. This one has storage for // the CombinerRecipe, since Trailing storage for it doesn't exist yet. -struct OpenACCReductionRecipeWithStorage : OpenACCReductionRecipe { -private: - llvm::SmallVector CombinerRecipeStorage; - -public: - OpenACCReductionRecipeWithStorage(VarDecl *A, - llvm::ArrayRef Combiners) - : OpenACCReductionRecipe(A, {}), CombinerRecipeStorage(Combiners) { - CombinerRecipes = CombinerRecipeStorage; - } +struct OpenACCReductionRecipeWithStorage { + VarDecl *AllocaDecl; + llvm::SmallVector CombinerRecipes; OpenACCReductionRecipeWithStorage( - const OpenACCReductionRecipeWithStorage &Other) - : OpenACCReductionRecipe(Other), - CombinerRecipeStorage(Other.CombinerRecipeStorage) { - CombinerRecipes = CombinerRecipeStorage; - } - - OpenACCReductionRecipeWithStorage(OpenACCReductionRecipeWithStorage &&Other) - : OpenACCReductionRecipe(std::move(Other)), - CombinerRecipeStorage(std::move(Other.CombinerRecipeStorage)) { - CombinerRecipes = CombinerRecipeStorage; - } - - // There is no real problem implementing these, we just have to make sure the - // array-ref this inherits from stays in sync. But as we don't need it at the - // moment, make sure we don't accidentially call these. - OpenACCReductionRecipeWithStorage & - operator=(OpenACCReductionRecipeWithStorage &&) = delete; - OpenACCReductionRecipeWithStorage & - operator=(const OpenACCReductionRecipeWithStorage &) = delete; + VarDecl *A, + llvm::ArrayRef Combiners) + : AllocaDecl(A), CombinerRecipes(Combiners) {} static OpenACCReductionRecipeWithStorage Empty() { return OpenACCReductionRecipeWithStorage(/*AllocaDecl=*/nullptr, {}); diff --git a/clang/lib/AST/OpenACCClause.cpp b/clang/lib/AST/OpenACCClause.cpp index 17c6bece44c82..142c9329141a9 100644 --- a/clang/lib/AST/OpenACCClause.cpp +++ b/clang/lib/AST/OpenACCClause.cpp @@ -509,7 +509,7 @@ OpenACCReductionClause *OpenACCReductionClause::Create( ArrayRef Recipes, SourceLocation EndLoc) { size_t NumCombiners = llvm::accumulate( - Recipes, 0, [](size_t Num, const OpenACCReductionRecipe &R) { + Recipes, 0, [](size_t Num, const OpenACCReductionRecipeWithStorage &R) { return Num + R.CombinerRecipes.size(); });