[clang] [Clang][NFC] Remove TemplateArgumentList::OnStack (PR #79760)
https://github.com/sdkrystian closed https://github.com/llvm/llvm-project/pull/79760 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][NFC] Remove TemplateArgumentList::OnStack (PR #79760)
https://github.com/erichkeane approved this pull request. https://github.com/llvm/llvm-project/pull/79760 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][NFC] Remove TemplateArgumentList::OnStack (PR #79760)
https://github.com/sdkrystian updated https://github.com/llvm/llvm-project/pull/79760 >From 2ea817f2103cf146e21128358c1064871a309664 Mon Sep 17 00:00:00 2001 From: Krystian Stasiowski Date: Sun, 28 Jan 2024 11:03:52 -0500 Subject: [PATCH] [Clang][NFC] Remove TemplateArgumentList::OnStack --- clang/docs/ReleaseNotes.rst | 4 ++ clang/include/clang/AST/DeclTemplate.h| 26 +-- clang/include/clang/Sema/Sema.h | 8 +-- clang/lib/AST/DeclTemplate.cpp| 3 +- clang/lib/Sema/SemaConcept.cpp| 20 +++--- clang/lib/Sema/SemaExprCXX.cpp| 4 +- clang/lib/Sema/SemaTemplate.cpp | 20 +++--- clang/lib/Sema/SemaTemplateDeduction.cpp | 70 --- clang/lib/Sema/SemaTemplateInstantiate.cpp| 11 +-- .../lib/Sema/SemaTemplateInstantiateDecl.cpp | 27 +++ 10 files changed, 81 insertions(+), 112 deletions(-) diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index ec9e3ef07057f..f9a78ece381c0 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -51,6 +51,10 @@ AST Dumping Potentially Breaking Changes Clang Frontend Potentially Breaking Changes --- +- Removed support for constructing on-stack ``TemplateArgumentList``s; interfaces should instead + use ``ArrayRef`` to pass template arguments. Transitioning internal uses to + ``ArrayRef`` reduces AST memory usage by 0.4% when compiling clang, and is + expected to show similar improvements on other workloads. Target OS macros extension ^^ diff --git a/clang/include/clang/AST/DeclTemplate.h b/clang/include/clang/AST/DeclTemplate.h index 832ad2de6b08a..baf71145d99dc 100644 --- a/clang/include/clang/AST/DeclTemplate.h +++ b/clang/include/clang/AST/DeclTemplate.h @@ -241,9 +241,6 @@ class FixedSizeTemplateParameterListStorage /// A template argument list. class TemplateArgumentList final : private llvm::TrailingObjects { - /// The template argument list. - const TemplateArgument *Arguments; - /// The number of template arguments in this template /// argument list. unsigned NumArguments; @@ -258,30 +255,11 @@ class TemplateArgumentList final TemplateArgumentList(const TemplateArgumentList &) = delete; TemplateArgumentList =(const TemplateArgumentList &) = delete; - /// Type used to indicate that the template argument list itself is a - /// stack object. It does not own its template arguments. - enum OnStackType { OnStack }; - /// Create a new template argument list that copies the given set of /// template arguments. static TemplateArgumentList *CreateCopy(ASTContext , ArrayRef Args); - /// Construct a new, temporary template argument list on the stack. - /// - /// The template argument list does not own the template arguments - /// provided. - explicit TemplateArgumentList(OnStackType, ArrayRef Args) - : Arguments(Args.data()), NumArguments(Args.size()) {} - - /// Produces a shallow copy of the given template argument list. - /// - /// This operation assumes that the input argument list outlives it. - /// This takes the list as a pointer to avoid looking like a copy - /// constructor, since this really isn't safe to use that way. - explicit TemplateArgumentList(const TemplateArgumentList *Other) - : Arguments(Other->data()), NumArguments(Other->size()) {} - /// Retrieve the template argument at a given index. const TemplateArgument (unsigned Idx) const { assert(Idx < NumArguments && "Invalid template argument index"); @@ -301,7 +279,9 @@ class TemplateArgumentList final unsigned size() const { return NumArguments; } /// Retrieve a pointer to the template argument list. - const TemplateArgument *data() const { return Arguments; } + const TemplateArgument *data() const { +return getTrailingObjects(); + } }; void *allocateDefaultArgStorageChain(const ASTContext ); diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h index b780cee86c3c3..780a2f2d8ce27 100644 --- a/clang/include/clang/Sema/Sema.h +++ b/clang/include/clang/Sema/Sema.h @@ -9329,12 +9329,12 @@ class Sema final { TemplateDeductionResult DeduceTemplateArguments(ClassTemplatePartialSpecializationDecl *Partial, - const TemplateArgumentList , + ArrayRef TemplateArgs, sema::TemplateDeductionInfo ); TemplateDeductionResult DeduceTemplateArguments(VarTemplatePartialSpecializationDecl *Partial, - const TemplateArgumentList , + ArrayRef TemplateArgs, sema::TemplateDeductionInfo ); TemplateDeductionResult SubstituteExplicitTemplateArguments( @@ -9507,7 +9507,7 @@ class Sema final { MultiLevelTemplateArgumentList getTemplateInstantiationArgs(
[clang] [Clang][NFC] Remove TemplateArgumentList::OnStack (PR #79760)
erichkeane wrote: > @erichkeane How does this sound? > > > Removed support for constructing on-stack `TemplateArgumentList`s; > > interfaces should instead use `ArrayRef` to pass template > > arguments. Transitioning internal uses to `ArrayRef` > > reduces AST memory usage by 0.4% when compiling clang, and is expected to > > show similar improvements on other workloads. See edited quote^ https://github.com/llvm/llvm-project/pull/79760 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][NFC] Remove TemplateArgumentList::OnStack (PR #79760)
sdkrystian wrote: @erichkeane How does this sound? > Removed support for constructing on-stack `TemplateArgumentList`s; interfaces > should instead use `ArrayRef` to pass template arguments. > This reduces AST memory usage by 0.4% when compiling clang. https://github.com/llvm/llvm-project/pull/79760 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][NFC] Remove TemplateArgumentList::OnStack (PR #79760)
https://github.com/sdkrystian updated https://github.com/llvm/llvm-project/pull/79760 >From 2e3e1a1dcaf1a6483e326c0d537af50e264098bb Mon Sep 17 00:00:00 2001 From: Krystian Stasiowski Date: Sun, 28 Jan 2024 11:03:52 -0500 Subject: [PATCH] [Clang][NFC] Remove TemplateArgumentList::OnStack --- clang/docs/ReleaseNotes.rst | 3 + clang/include/clang/AST/DeclTemplate.h| 26 +-- clang/include/clang/Sema/Sema.h | 8 +-- clang/lib/AST/DeclTemplate.cpp| 3 +- clang/lib/Sema/SemaConcept.cpp| 20 +++--- clang/lib/Sema/SemaExprCXX.cpp| 4 +- clang/lib/Sema/SemaTemplate.cpp | 20 +++--- clang/lib/Sema/SemaTemplateDeduction.cpp | 70 --- clang/lib/Sema/SemaTemplateInstantiate.cpp| 11 +-- .../lib/Sema/SemaTemplateInstantiateDecl.cpp | 27 +++ 10 files changed, 80 insertions(+), 112 deletions(-) diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index ec9e3ef07057f..823565723e139 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -51,6 +51,9 @@ AST Dumping Potentially Breaking Changes Clang Frontend Potentially Breaking Changes --- +- Removed support for constructing on-stack ``TemplateArgumentList``s; interfaces should + instead use ``ArrayRef`` to pass template arguments. This reduces + AST memory usage by 0.4% when compiling clang. Target OS macros extension ^^ diff --git a/clang/include/clang/AST/DeclTemplate.h b/clang/include/clang/AST/DeclTemplate.h index 832ad2de6b08a..baf71145d99dc 100644 --- a/clang/include/clang/AST/DeclTemplate.h +++ b/clang/include/clang/AST/DeclTemplate.h @@ -241,9 +241,6 @@ class FixedSizeTemplateParameterListStorage /// A template argument list. class TemplateArgumentList final : private llvm::TrailingObjects { - /// The template argument list. - const TemplateArgument *Arguments; - /// The number of template arguments in this template /// argument list. unsigned NumArguments; @@ -258,30 +255,11 @@ class TemplateArgumentList final TemplateArgumentList(const TemplateArgumentList &) = delete; TemplateArgumentList =(const TemplateArgumentList &) = delete; - /// Type used to indicate that the template argument list itself is a - /// stack object. It does not own its template arguments. - enum OnStackType { OnStack }; - /// Create a new template argument list that copies the given set of /// template arguments. static TemplateArgumentList *CreateCopy(ASTContext , ArrayRef Args); - /// Construct a new, temporary template argument list on the stack. - /// - /// The template argument list does not own the template arguments - /// provided. - explicit TemplateArgumentList(OnStackType, ArrayRef Args) - : Arguments(Args.data()), NumArguments(Args.size()) {} - - /// Produces a shallow copy of the given template argument list. - /// - /// This operation assumes that the input argument list outlives it. - /// This takes the list as a pointer to avoid looking like a copy - /// constructor, since this really isn't safe to use that way. - explicit TemplateArgumentList(const TemplateArgumentList *Other) - : Arguments(Other->data()), NumArguments(Other->size()) {} - /// Retrieve the template argument at a given index. const TemplateArgument (unsigned Idx) const { assert(Idx < NumArguments && "Invalid template argument index"); @@ -301,7 +279,9 @@ class TemplateArgumentList final unsigned size() const { return NumArguments; } /// Retrieve a pointer to the template argument list. - const TemplateArgument *data() const { return Arguments; } + const TemplateArgument *data() const { +return getTrailingObjects(); + } }; void *allocateDefaultArgStorageChain(const ASTContext ); diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h index b780cee86c3c3..780a2f2d8ce27 100644 --- a/clang/include/clang/Sema/Sema.h +++ b/clang/include/clang/Sema/Sema.h @@ -9329,12 +9329,12 @@ class Sema final { TemplateDeductionResult DeduceTemplateArguments(ClassTemplatePartialSpecializationDecl *Partial, - const TemplateArgumentList , + ArrayRef TemplateArgs, sema::TemplateDeductionInfo ); TemplateDeductionResult DeduceTemplateArguments(VarTemplatePartialSpecializationDecl *Partial, - const TemplateArgumentList , + ArrayRef TemplateArgs, sema::TemplateDeductionInfo ); TemplateDeductionResult SubstituteExplicitTemplateArguments( @@ -9507,7 +9507,7 @@ class Sema final { MultiLevelTemplateArgumentList getTemplateInstantiationArgs( const NamedDecl *D, const DeclContext *DC = nullptr, bool Final = false, - const
[clang] [Clang][NFC] Remove TemplateArgumentList::OnStack (PR #79760)
erichkeane wrote: > @erichkeane I ended up writing a python script that compiles the TUs in > `clang/lib` with `-print-stats` and then sums up the total bytes allocated by > `ASTContext`. Ended up with a 0.4% decrease in memory usage. > > This does however rely on `compile_commands.json`, and boost does not have a > great way to generate this for every subproject... Do you think the results > from compiling clang are sufficient? Yeah, I think that is sufficient, find a way to write that as prose in the release note, and i'm happy with it. https://github.com/llvm/llvm-project/pull/79760 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][NFC] Remove TemplateArgumentList::OnStack (PR #79760)
sdkrystian wrote: @erichkeane I ended up writing a python script that compiles the TUs in `clang/lib` with `-print-stats` and then sums up the total bytes allocated by `ASTContext`. Ended up with a 0.4% decrease in memory usage. This does however rely on `compile_commands.json`, and boost does not have a great way to generate this for every subproject... Do you think the results from compiling clang are sufficient? https://github.com/llvm/llvm-project/pull/79760 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][NFC] Remove TemplateArgumentList::OnStack (PR #79760)
erichkeane wrote: > @erichkeane I added the following release note: > > > Removed support for constructing on-stack `TemplateArgumentList`s. > > Interfaces should instead use `ArrayRef` to pass template > > arguments. > > I'm not entirely sure how to benchmark these changes. Perhaps I could > determine the difference in AST memory usage compiling something like Boost > or LLVM? Boost is a great one I think, a memory profile of that would be great. Even a 'rough' number (this decreased the memory pressure of compiling boost by 1.1%!) would be something good to 'show off'. I think that is the good 'first half' of a release note, the second half giving justification for it (again, this both simplifies the code and decreases memory pressure by X% sorta thing).. https://github.com/llvm/llvm-project/pull/79760 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][NFC] Remove TemplateArgumentList::OnStack (PR #79760)
sdkrystian wrote: @erichkeane I added the following release note: > Removed support for constructing on-stack `TemplateArgumentList`s. Interfaces > should instead use `ArrayRef` to pass template arguments. I'm not entirely sure how to benchmark these changes. Perhaps I could determine the difference in AST memory usage compiling something like Boost or LLVM? https://github.com/llvm/llvm-project/pull/79760 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][NFC] Remove TemplateArgumentList::OnStack (PR #79760)
https://github.com/sdkrystian updated https://github.com/llvm/llvm-project/pull/79760 >From 87b8ab6b6d7f70ae27c766f4038683f9237cc65a Mon Sep 17 00:00:00 2001 From: Krystian Stasiowski Date: Sun, 28 Jan 2024 11:03:52 -0500 Subject: [PATCH] [Clang][NFC] Remove TemplateArgumentList::OnStack --- clang/docs/ReleaseNotes.rst | 2 + clang/include/clang/AST/DeclTemplate.h| 26 +-- clang/include/clang/Sema/Sema.h | 8 +-- clang/lib/AST/DeclTemplate.cpp| 3 +- clang/lib/Sema/SemaConcept.cpp| 20 +++--- clang/lib/Sema/SemaExprCXX.cpp| 4 +- clang/lib/Sema/SemaTemplate.cpp | 20 +++--- clang/lib/Sema/SemaTemplateDeduction.cpp | 70 --- clang/lib/Sema/SemaTemplateInstantiate.cpp| 11 +-- .../lib/Sema/SemaTemplateInstantiateDecl.cpp | 27 +++ 10 files changed, 79 insertions(+), 112 deletions(-) diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index ec9e3ef07057f..8ff3386bc59d5 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -51,6 +51,8 @@ AST Dumping Potentially Breaking Changes Clang Frontend Potentially Breaking Changes --- +- Removed support for constructing on-stack ``TemplateArgumentList``s. + Interfaces should instead use ``ArrayRef`` to pass template arguments. Target OS macros extension ^^ diff --git a/clang/include/clang/AST/DeclTemplate.h b/clang/include/clang/AST/DeclTemplate.h index 832ad2de6b08a..baf71145d99dc 100644 --- a/clang/include/clang/AST/DeclTemplate.h +++ b/clang/include/clang/AST/DeclTemplate.h @@ -241,9 +241,6 @@ class FixedSizeTemplateParameterListStorage /// A template argument list. class TemplateArgumentList final : private llvm::TrailingObjects { - /// The template argument list. - const TemplateArgument *Arguments; - /// The number of template arguments in this template /// argument list. unsigned NumArguments; @@ -258,30 +255,11 @@ class TemplateArgumentList final TemplateArgumentList(const TemplateArgumentList &) = delete; TemplateArgumentList =(const TemplateArgumentList &) = delete; - /// Type used to indicate that the template argument list itself is a - /// stack object. It does not own its template arguments. - enum OnStackType { OnStack }; - /// Create a new template argument list that copies the given set of /// template arguments. static TemplateArgumentList *CreateCopy(ASTContext , ArrayRef Args); - /// Construct a new, temporary template argument list on the stack. - /// - /// The template argument list does not own the template arguments - /// provided. - explicit TemplateArgumentList(OnStackType, ArrayRef Args) - : Arguments(Args.data()), NumArguments(Args.size()) {} - - /// Produces a shallow copy of the given template argument list. - /// - /// This operation assumes that the input argument list outlives it. - /// This takes the list as a pointer to avoid looking like a copy - /// constructor, since this really isn't safe to use that way. - explicit TemplateArgumentList(const TemplateArgumentList *Other) - : Arguments(Other->data()), NumArguments(Other->size()) {} - /// Retrieve the template argument at a given index. const TemplateArgument (unsigned Idx) const { assert(Idx < NumArguments && "Invalid template argument index"); @@ -301,7 +279,9 @@ class TemplateArgumentList final unsigned size() const { return NumArguments; } /// Retrieve a pointer to the template argument list. - const TemplateArgument *data() const { return Arguments; } + const TemplateArgument *data() const { +return getTrailingObjects(); + } }; void *allocateDefaultArgStorageChain(const ASTContext ); diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h index b780cee86c3c3..780a2f2d8ce27 100644 --- a/clang/include/clang/Sema/Sema.h +++ b/clang/include/clang/Sema/Sema.h @@ -9329,12 +9329,12 @@ class Sema final { TemplateDeductionResult DeduceTemplateArguments(ClassTemplatePartialSpecializationDecl *Partial, - const TemplateArgumentList , + ArrayRef TemplateArgs, sema::TemplateDeductionInfo ); TemplateDeductionResult DeduceTemplateArguments(VarTemplatePartialSpecializationDecl *Partial, - const TemplateArgumentList , + ArrayRef TemplateArgs, sema::TemplateDeductionInfo ); TemplateDeductionResult SubstituteExplicitTemplateArguments( @@ -9507,7 +9507,7 @@ class Sema final { MultiLevelTemplateArgumentList getTemplateInstantiationArgs( const NamedDecl *D, const DeclContext *DC = nullptr, bool Final = false, - const TemplateArgumentList *Innermost = nullptr, + std::optional> Innermost =
[clang] [Clang][NFC] Remove TemplateArgumentList::OnStack (PR #79760)
https://github.com/sdkrystian edited https://github.com/llvm/llvm-project/pull/79760 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][NFC] Remove TemplateArgumentList::OnStack (PR #79760)
https://github.com/sdkrystian edited https://github.com/llvm/llvm-project/pull/79760 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][NFC] Remove TemplateArgumentList::OnStack (PR #79760)
@@ -301,7 +279,9 @@ class TemplateArgumentList final unsigned size() const { return NumArguments; } /// Retrieve a pointer to the template argument list. - const TemplateArgument *data() const { return Arguments; } + const TemplateArgument *data() const { +return getTrailingObjects(); + } sdkrystian wrote: We definitely could, but perhaps that is outside the scope of this PR? That being said, It would be good to unify the interfaces of `TemplateArgumentList`, `TemplateArgumentListInfo`, and `ASTTemplateArgumentListInfo` by perhaps giving them all the following members: - `begin()` and `end()` - `operator[]` - `operator ArrayRef`/`operator ArrayRef` https://github.com/llvm/llvm-project/pull/79760 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][NFC] Remove TemplateArgumentList::OnStack (PR #79760)
https://github.com/sdkrystian updated https://github.com/llvm/llvm-project/pull/79760 >From 1f6d9f32e21032b11f6e6a4fd6186ccaee88e2e2 Mon Sep 17 00:00:00 2001 From: Krystian Stasiowski Date: Sun, 28 Jan 2024 11:03:52 -0500 Subject: [PATCH] [Clang][NFC] Remove TemplateArgumentList::OnStack --- clang/include/clang/AST/DeclTemplate.h| 26 +-- clang/include/clang/Sema/Sema.h | 8 +-- clang/lib/AST/DeclTemplate.cpp| 3 +- clang/lib/Sema/SemaConcept.cpp| 20 +++--- clang/lib/Sema/SemaExprCXX.cpp| 4 +- clang/lib/Sema/SemaTemplate.cpp | 20 +++--- clang/lib/Sema/SemaTemplateDeduction.cpp | 70 --- clang/lib/Sema/SemaTemplateInstantiate.cpp| 15 ++-- .../lib/Sema/SemaTemplateInstantiateDecl.cpp | 27 +++ 9 files changed, 80 insertions(+), 113 deletions(-) diff --git a/clang/include/clang/AST/DeclTemplate.h b/clang/include/clang/AST/DeclTemplate.h index 832ad2de6b08a..baf71145d99dc 100644 --- a/clang/include/clang/AST/DeclTemplate.h +++ b/clang/include/clang/AST/DeclTemplate.h @@ -241,9 +241,6 @@ class FixedSizeTemplateParameterListStorage /// A template argument list. class TemplateArgumentList final : private llvm::TrailingObjects { - /// The template argument list. - const TemplateArgument *Arguments; - /// The number of template arguments in this template /// argument list. unsigned NumArguments; @@ -258,30 +255,11 @@ class TemplateArgumentList final TemplateArgumentList(const TemplateArgumentList &) = delete; TemplateArgumentList =(const TemplateArgumentList &) = delete; - /// Type used to indicate that the template argument list itself is a - /// stack object. It does not own its template arguments. - enum OnStackType { OnStack }; - /// Create a new template argument list that copies the given set of /// template arguments. static TemplateArgumentList *CreateCopy(ASTContext , ArrayRef Args); - /// Construct a new, temporary template argument list on the stack. - /// - /// The template argument list does not own the template arguments - /// provided. - explicit TemplateArgumentList(OnStackType, ArrayRef Args) - : Arguments(Args.data()), NumArguments(Args.size()) {} - - /// Produces a shallow copy of the given template argument list. - /// - /// This operation assumes that the input argument list outlives it. - /// This takes the list as a pointer to avoid looking like a copy - /// constructor, since this really isn't safe to use that way. - explicit TemplateArgumentList(const TemplateArgumentList *Other) - : Arguments(Other->data()), NumArguments(Other->size()) {} - /// Retrieve the template argument at a given index. const TemplateArgument (unsigned Idx) const { assert(Idx < NumArguments && "Invalid template argument index"); @@ -301,7 +279,9 @@ class TemplateArgumentList final unsigned size() const { return NumArguments; } /// Retrieve a pointer to the template argument list. - const TemplateArgument *data() const { return Arguments; } + const TemplateArgument *data() const { +return getTrailingObjects(); + } }; void *allocateDefaultArgStorageChain(const ASTContext ); diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h index 59eab0185ae63..813e6fd827877 100644 --- a/clang/include/clang/Sema/Sema.h +++ b/clang/include/clang/Sema/Sema.h @@ -9331,12 +9331,12 @@ class Sema final { TemplateDeductionResult DeduceTemplateArguments(ClassTemplatePartialSpecializationDecl *Partial, - const TemplateArgumentList , + ArrayRef TemplateArgs, sema::TemplateDeductionInfo ); TemplateDeductionResult DeduceTemplateArguments(VarTemplatePartialSpecializationDecl *Partial, - const TemplateArgumentList , + ArrayRef TemplateArgs, sema::TemplateDeductionInfo ); TemplateDeductionResult SubstituteExplicitTemplateArguments( @@ -9509,7 +9509,7 @@ class Sema final { MultiLevelTemplateArgumentList getTemplateInstantiationArgs( const NamedDecl *D, const DeclContext *DC = nullptr, bool Final = false, - const TemplateArgumentList *Innermost = nullptr, + std::optional> Innermost = std::nullopt, bool RelativeToPrimary = false, const FunctionDecl *Pattern = nullptr, bool ForConstraintInstantiation = false, bool SkipForSpecialization = false); @@ -10539,7 +10539,7 @@ class Sema final { bool AtEndOfTU = false); VarTemplateSpecializationDecl *BuildVarTemplateInstantiation( VarTemplateDecl *VarTemplate, VarDecl *FromVar, - const TemplateArgumentList , + const TemplateArgumentList *PartialSpecArgs, const TemplateArgumentListInfo , SmallVectorImpl , SourceLocation
[clang] [Clang][NFC] Remove TemplateArgumentList::OnStack (PR #79760)
https://github.com/cor3ntin edited https://github.com/llvm/llvm-project/pull/79760 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][NFC] Remove TemplateArgumentList::OnStack (PR #79760)
@@ -301,7 +279,9 @@ class TemplateArgumentList final unsigned size() const { return NumArguments; } /// Retrieve a pointer to the template argument list. - const TemplateArgument *data() const { return Arguments; } + const TemplateArgument *data() const { +return getTrailingObjects(); + } cor3ntin wrote: I wonder if we could get rid of that entirely in the public interface https://github.com/llvm/llvm-project/pull/79760 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][NFC] Remove TemplateArgumentList::OnStack (PR #79760)
https://github.com/erichkeane commented: So I like this! I think it is a good change. I WOULD like to see a release note. I know this isn't particularly 'user visible', but I think, paired with some sort of benchmark, that this would be useful to brag about. We often run out of stack space while instantiating templates that are particularly large/deep despite our best efforts, and I have a feeling that both saving space in the TAL plus not storing anythign on the stack would improve that. @cor3ntin : FYI, this would be interesting to be aware of. Comments on how a release note could go are also appreciated. https://github.com/llvm/llvm-project/pull/79760 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][NFC] Remove TemplateArgumentList::OnStack (PR #79760)
llvmbot wrote: @llvm/pr-subscribers-clang Author: Krystian Stasiowski (sdkrystian) Changes This removes on-stack `TemplateArgumentList`'s. They were primary used to pass an `ArrayRefTemplateArgument` to `Sema::getTemplateInstantiationArgs`, which had a `const TemplateArgumentList*` parameter for the innermost template argument list. Changing this parameter to an `std::optionalArrayRefTemplateArgument` eliminates the need for on-stack `TemplateArgumentList`'s, which in turn eliminates the need for `TemplateArgumentList` to store a pointer to its template argument storage (which is redundant in almost all cases, as it is an AST allocated type). --- Patch is 27.64 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/79760.diff 9 Files Affected: - (modified) clang/include/clang/AST/DeclTemplate.h (+3-23) - (modified) clang/include/clang/Sema/Sema.h (+4-4) - (modified) clang/lib/AST/DeclTemplate.cpp (+1-2) - (modified) clang/lib/Sema/SemaConcept.cpp (+10-10) - (modified) clang/lib/Sema/SemaExprCXX.cpp (+1-3) - (modified) clang/lib/Sema/SemaTemplate.cpp (+8-12) - (modified) clang/lib/Sema/SemaTemplateDeduction.cpp (+29-41) - (modified) clang/lib/Sema/SemaTemplateInstantiate.cpp (+9-6) - (modified) clang/lib/Sema/SemaTemplateInstantiateDecl.cpp (+15-12) ``diff diff --git a/clang/include/clang/AST/DeclTemplate.h b/clang/include/clang/AST/DeclTemplate.h index 832ad2de6b08a82..baf71145d99dc6a 100644 --- a/clang/include/clang/AST/DeclTemplate.h +++ b/clang/include/clang/AST/DeclTemplate.h @@ -241,9 +241,6 @@ class FixedSizeTemplateParameterListStorage /// A template argument list. class TemplateArgumentList final : private llvm::TrailingObjects { - /// The template argument list. - const TemplateArgument *Arguments; - /// The number of template arguments in this template /// argument list. unsigned NumArguments; @@ -258,30 +255,11 @@ class TemplateArgumentList final TemplateArgumentList(const TemplateArgumentList &) = delete; TemplateArgumentList =(const TemplateArgumentList &) = delete; - /// Type used to indicate that the template argument list itself is a - /// stack object. It does not own its template arguments. - enum OnStackType { OnStack }; - /// Create a new template argument list that copies the given set of /// template arguments. static TemplateArgumentList *CreateCopy(ASTContext , ArrayRef Args); - /// Construct a new, temporary template argument list on the stack. - /// - /// The template argument list does not own the template arguments - /// provided. - explicit TemplateArgumentList(OnStackType, ArrayRef Args) - : Arguments(Args.data()), NumArguments(Args.size()) {} - - /// Produces a shallow copy of the given template argument list. - /// - /// This operation assumes that the input argument list outlives it. - /// This takes the list as a pointer to avoid looking like a copy - /// constructor, since this really isn't safe to use that way. - explicit TemplateArgumentList(const TemplateArgumentList *Other) - : Arguments(Other->data()), NumArguments(Other->size()) {} - /// Retrieve the template argument at a given index. const TemplateArgument (unsigned Idx) const { assert(Idx < NumArguments && "Invalid template argument index"); @@ -301,7 +279,9 @@ class TemplateArgumentList final unsigned size() const { return NumArguments; } /// Retrieve a pointer to the template argument list. - const TemplateArgument *data() const { return Arguments; } + const TemplateArgument *data() const { +return getTrailingObjects(); + } }; void *allocateDefaultArgStorageChain(const ASTContext ); diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h index b5946e3f3178ff2..d730c60a406e98f 100644 --- a/clang/include/clang/Sema/Sema.h +++ b/clang/include/clang/Sema/Sema.h @@ -9297,12 +9297,12 @@ class Sema final { TemplateDeductionResult DeduceTemplateArguments(ClassTemplatePartialSpecializationDecl *Partial, - const TemplateArgumentList , + ArrayRef TemplateArgs, sema::TemplateDeductionInfo ); TemplateDeductionResult DeduceTemplateArguments(VarTemplatePartialSpecializationDecl *Partial, - const TemplateArgumentList , + ArrayRef TemplateArgs, sema::TemplateDeductionInfo ); TemplateDeductionResult SubstituteExplicitTemplateArguments( @@ -9475,7 +9475,7 @@ class Sema final { MultiLevelTemplateArgumentList getTemplateInstantiationArgs( const NamedDecl *D, const DeclContext *DC = nullptr, bool Final = false, - const TemplateArgumentList *Innermost = nullptr, + std::optional> Innermost = std::nullopt, bool RelativeToPrimary = false, const FunctionDecl *Pattern = nullptr, bool
[clang] [Clang][NFC] Remove TemplateArgumentList::OnStack (PR #79760)
https://github.com/sdkrystian created https://github.com/llvm/llvm-project/pull/79760 This removes on-stack `TemplateArgumentList`'s. They were primary used to pass an `ArrayRef` to `Sema::getTemplateInstantiationArgs`, which had a `const TemplateArgumentList*` parameter for the innermost template argument list. Changing this parameter to an `std::optional>` eliminates the need for on-stack `TemplateArgumentList`'s, which in turn eliminates the need for `TemplateArgumentList` to store a pointer to its template argument storage (which is redundant in almost all cases, as it is an AST allocated type). >From 58f43c76409cd0406d045fa07ab26eff84890e52 Mon Sep 17 00:00:00 2001 From: Krystian Stasiowski Date: Sun, 28 Jan 2024 11:03:52 -0500 Subject: [PATCH] [Clang][NFC] Remove TemplateArgumentList::OnStack --- clang/include/clang/AST/DeclTemplate.h| 26 +-- clang/include/clang/Sema/Sema.h | 8 +-- clang/lib/AST/DeclTemplate.cpp| 3 +- clang/lib/Sema/SemaConcept.cpp| 20 +++--- clang/lib/Sema/SemaExprCXX.cpp| 4 +- clang/lib/Sema/SemaTemplate.cpp | 20 +++--- clang/lib/Sema/SemaTemplateDeduction.cpp | 70 --- clang/lib/Sema/SemaTemplateInstantiate.cpp| 15 ++-- .../lib/Sema/SemaTemplateInstantiateDecl.cpp | 27 +++ 9 files changed, 80 insertions(+), 113 deletions(-) diff --git a/clang/include/clang/AST/DeclTemplate.h b/clang/include/clang/AST/DeclTemplate.h index 832ad2de6b08a82..baf71145d99dc6a 100644 --- a/clang/include/clang/AST/DeclTemplate.h +++ b/clang/include/clang/AST/DeclTemplate.h @@ -241,9 +241,6 @@ class FixedSizeTemplateParameterListStorage /// A template argument list. class TemplateArgumentList final : private llvm::TrailingObjects { - /// The template argument list. - const TemplateArgument *Arguments; - /// The number of template arguments in this template /// argument list. unsigned NumArguments; @@ -258,30 +255,11 @@ class TemplateArgumentList final TemplateArgumentList(const TemplateArgumentList &) = delete; TemplateArgumentList =(const TemplateArgumentList &) = delete; - /// Type used to indicate that the template argument list itself is a - /// stack object. It does not own its template arguments. - enum OnStackType { OnStack }; - /// Create a new template argument list that copies the given set of /// template arguments. static TemplateArgumentList *CreateCopy(ASTContext , ArrayRef Args); - /// Construct a new, temporary template argument list on the stack. - /// - /// The template argument list does not own the template arguments - /// provided. - explicit TemplateArgumentList(OnStackType, ArrayRef Args) - : Arguments(Args.data()), NumArguments(Args.size()) {} - - /// Produces a shallow copy of the given template argument list. - /// - /// This operation assumes that the input argument list outlives it. - /// This takes the list as a pointer to avoid looking like a copy - /// constructor, since this really isn't safe to use that way. - explicit TemplateArgumentList(const TemplateArgumentList *Other) - : Arguments(Other->data()), NumArguments(Other->size()) {} - /// Retrieve the template argument at a given index. const TemplateArgument (unsigned Idx) const { assert(Idx < NumArguments && "Invalid template argument index"); @@ -301,7 +279,9 @@ class TemplateArgumentList final unsigned size() const { return NumArguments; } /// Retrieve a pointer to the template argument list. - const TemplateArgument *data() const { return Arguments; } + const TemplateArgument *data() const { +return getTrailingObjects(); + } }; void *allocateDefaultArgStorageChain(const ASTContext ); diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h index b5946e3f3178ff2..d730c60a406e98f 100644 --- a/clang/include/clang/Sema/Sema.h +++ b/clang/include/clang/Sema/Sema.h @@ -9297,12 +9297,12 @@ class Sema final { TemplateDeductionResult DeduceTemplateArguments(ClassTemplatePartialSpecializationDecl *Partial, - const TemplateArgumentList , + ArrayRef TemplateArgs, sema::TemplateDeductionInfo ); TemplateDeductionResult DeduceTemplateArguments(VarTemplatePartialSpecializationDecl *Partial, - const TemplateArgumentList , + ArrayRef TemplateArgs, sema::TemplateDeductionInfo ); TemplateDeductionResult SubstituteExplicitTemplateArguments( @@ -9475,7 +9475,7 @@ class Sema final { MultiLevelTemplateArgumentList getTemplateInstantiationArgs( const NamedDecl *D, const DeclContext *DC = nullptr, bool Final = false, - const TemplateArgumentList *Innermost = nullptr, + std::optional> Innermost = std::nullopt, bool RelativeToPrimary = false,