-
Notifications
You must be signed in to change notification settings - Fork 14.9k
[clang] NFC: Provide inline definitions for {get,cast}TagDecl and friends #155051
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@llvm/pr-subscribers-clang Author: Matheus Izvekov (mizvekov) Changes…ends This is a small performance improvement: This helps recover the performance lost in #155028, reversing it into a small positive instead. Full diff: https://github.com/llvm/llvm-project/pull/155051.diff 3 Files Affected:
diff --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h
index 70510d95a67b5..ab8a3398bde94 100644
--- a/clang/include/clang/AST/Type.h
+++ b/clang/include/clang/AST/Type.h
@@ -23,6 +23,55 @@
namespace clang {
+inline CXXRecordDecl *Type::getAsCXXRecordDecl() const {
+ const auto *TT = dyn_cast<TagType>(CanonicalType);
+ if (!isa_and_present<RecordType, InjectedClassNameType>(TT))
+ return nullptr;
+ auto *TD = TT->getOriginalDecl();
+ if (!isa<InjectedClassNameType>(TT) && !isa<CXXRecordDecl>(TD))
+ return nullptr;
+ return cast<CXXRecordDecl>(TD)->getDefinitionOrSelf();
+}
+
+inline CXXRecordDecl *Type::castAsCXXRecordDecl() const {
+ const auto *TT = cast<TagType>(CanonicalType);
+ return cast<CXXRecordDecl>(TT->getOriginalDecl())->getDefinitionOrSelf();
+}
+
+inline RecordDecl *Type::getAsRecordDecl() const {
+ const auto *TT = dyn_cast<TagType>(CanonicalType);
+ if (!isa_and_present<RecordType, InjectedClassNameType>(TT))
+ return nullptr;
+ return cast<RecordDecl>(TT->getOriginalDecl())->getDefinitionOrSelf();
+}
+
+inline RecordDecl *Type::castAsRecordDecl() const {
+ const auto *TT = cast<TagType>(CanonicalType);
+ return cast<RecordDecl>(TT->getOriginalDecl())->getDefinitionOrSelf();
+}
+
+inline EnumDecl *Type::getAsEnumDecl() const {
+ if (const auto *TT = dyn_cast<EnumType>(CanonicalType))
+ return TT->getOriginalDecl()->getDefinitionOrSelf();
+ return nullptr;
+}
+
+inline EnumDecl *Type::castAsEnumDecl() const {
+ return cast<EnumType>(CanonicalType)
+ ->getOriginalDecl()
+ ->getDefinitionOrSelf();
+}
+
+inline TagDecl *Type::getAsTagDecl() const {
+ if (const auto *TT = dyn_cast<TagType>(CanonicalType))
+ return TT->getOriginalDecl()->getDefinitionOrSelf();
+ return nullptr;
+}
+
+inline TagDecl *Type::castAsTagDecl() const {
+ return cast<TagType>(CanonicalType)->getOriginalDecl()->getDefinitionOrSelf();
+}
+
inline bool QualType::hasNonTrivialToPrimitiveDefaultInitializeCUnion() const {
if (auto *RD = getTypePtr()->getBaseElementTypeUnsafe()->getAsRecordDecl())
return hasNonTrivialToPrimitiveDefaultInitializeCUnion(RD);
diff --git a/clang/include/clang/AST/TypeBase.h b/clang/include/clang/AST/TypeBase.h
index 35729b37b005f..75f1895cc79f1 100644
--- a/clang/include/clang/AST/TypeBase.h
+++ b/clang/include/clang/AST/TypeBase.h
@@ -2882,24 +2882,24 @@ class alignas(TypeAlignment) Type : public ExtQualsTypeCommonBase {
/// Retrieves the CXXRecordDecl that this type refers to, either
/// because the type is a RecordType or because it is the injected-class-name
/// type of a class template or class template partial specialization.
- CXXRecordDecl *getAsCXXRecordDecl() const;
- CXXRecordDecl *castAsCXXRecordDecl() const;
+ inline CXXRecordDecl *getAsCXXRecordDecl() const;
+ inline CXXRecordDecl *castAsCXXRecordDecl() const;
/// Retrieves the RecordDecl this type refers to.
- RecordDecl *getAsRecordDecl() const;
- RecordDecl *castAsRecordDecl() const;
+ inline RecordDecl *getAsRecordDecl() const;
+ inline RecordDecl *castAsRecordDecl() const;
/// Retrieves the TagDecl that this type refers to, either
/// because the type is a TagType or because it is the injected-class-name
/// type of a class template or class template partial specialization.
- EnumDecl *getAsEnumDecl() const;
- EnumDecl *castAsEnumDecl() const;
+ inline EnumDecl *getAsEnumDecl() const;
+ inline EnumDecl *castAsEnumDecl() const;
/// Retrieves the TagDecl that this type refers to, either
/// because the type is a TagType or because it is the injected-class-name
/// type of a class template or class template partial specialization.
- TagDecl *getAsTagDecl() const;
- TagDecl *castAsTagDecl() const;
+ inline TagDecl *getAsTagDecl() const;
+ inline TagDecl *castAsTagDecl() const;
/// If this is a pointer or reference to a RecordType, return the
/// CXXRecordDecl that the type refers to.
diff --git a/clang/lib/AST/Type.cpp b/clang/lib/AST/Type.cpp
index b34a0d556b596..9ff573f33d3cb 100644
--- a/clang/lib/AST/Type.cpp
+++ b/clang/lib/AST/Type.cpp
@@ -1917,55 +1917,6 @@ const CXXRecordDecl *Type::getPointeeCXXRecordDecl() const {
return PointeeType->getAsCXXRecordDecl();
}
-CXXRecordDecl *Type::getAsCXXRecordDecl() const {
- const auto *TT = dyn_cast<TagType>(CanonicalType);
- if (!isa_and_present<RecordType, InjectedClassNameType>(TT))
- return nullptr;
- auto *TD = TT->getOriginalDecl();
- if (!isa<InjectedClassNameType>(TT) && !isa<CXXRecordDecl>(TD))
- return nullptr;
- return cast<CXXRecordDecl>(TD)->getDefinitionOrSelf();
-}
-
-CXXRecordDecl *Type::castAsCXXRecordDecl() const {
- const auto *TT = cast<TagType>(CanonicalType);
- return cast<CXXRecordDecl>(TT->getOriginalDecl())->getDefinitionOrSelf();
-}
-
-RecordDecl *Type::getAsRecordDecl() const {
- const auto *TT = dyn_cast<TagType>(CanonicalType);
- if (!isa_and_present<RecordType, InjectedClassNameType>(TT))
- return nullptr;
- return cast<RecordDecl>(TT->getOriginalDecl())->getDefinitionOrSelf();
-}
-
-RecordDecl *Type::castAsRecordDecl() const {
- const auto *TT = cast<TagType>(CanonicalType);
- return cast<RecordDecl>(TT->getOriginalDecl())->getDefinitionOrSelf();
-}
-
-EnumDecl *Type::getAsEnumDecl() const {
- if (const auto *TT = dyn_cast<EnumType>(CanonicalType))
- return TT->getOriginalDecl()->getDefinitionOrSelf();
- return nullptr;
-}
-
-EnumDecl *Type::castAsEnumDecl() const {
- return cast<EnumType>(CanonicalType)
- ->getOriginalDecl()
- ->getDefinitionOrSelf();
-}
-
-TagDecl *Type::getAsTagDecl() const {
- if (const auto *TT = dyn_cast<TagType>(CanonicalType))
- return TT->getOriginalDecl()->getDefinitionOrSelf();
- return nullptr;
-}
-
-TagDecl *Type::castAsTagDecl() const {
- return cast<TagType>(CanonicalType)->getOriginalDecl()->getDefinitionOrSelf();
-}
-
const TemplateSpecializationType *
Type::getAsNonAliasTemplateSpecializationType() const {
const auto *TST = getAs<TemplateSpecializationType>();
|
1787600
to
324e8f3
Compare
cb3309c
to
76970a3
Compare
324e8f3
to
8978115
Compare
76970a3
to
ae2c34d
Compare
cor3ntin
approved these changes
Aug 23, 2025
Sirraide
reviewed
Aug 23, 2025
ae2c34d
to
9393676
Compare
55b388d
to
fa8712f
Compare
Sirraide
approved these changes
Aug 23, 2025
9393676
to
367b46c
Compare
fa8712f
to
199662e
Compare
erichkeane
reviewed
Aug 25, 2025
199662e
to
f724916
Compare
367b46c
to
b4178e9
Compare
f724916
to
44cad6f
Compare
b4178e9
to
3ec61b4
Compare
44cad6f
to
c3d411a
Compare
3ec61b4
to
a260168
Compare
c3d411a
to
d8a50b1
Compare
a260168
to
5245315
Compare
d8a50b1
to
c142961
Compare
5245315
to
829b1bf
Compare
…ends This is a small performance improvement: This helps recover the performance lost in #155028, reversing it into a small positive instead.
c142961
to
c5d57c5
Compare
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
clang:frontend
Language frontend issues, e.g. anything involving "Sema"
clang
Clang issues not falling into any other category
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is a small performance improvement:
This helps recover the performance lost in #155028, reversing it into a small positive instead.
