From 704b21cb4fa5323564779b1a39b577b2481bf677 Mon Sep 17 00:00:00 2001 From: Nathan Sidwell Date: Fri, 21 Jan 2022 11:37:01 -0800 Subject: [PATCH] [demangler] Remove StdQualifiedName The StdQualifiedName node class is used for names exactly in the std namespace. It is not used for nested names that descend further -- those use a NestedName with NameType("std") as the scope. Representing the compression scheme in the node graph is layer breaking. We can use the same structure for those exactly in std too, and reduce code size a bit. Reviewed By: ChuanqiXu Differential Revision: https://reviews.llvm.org/D118249 --- libcxxabi/src/demangle/ItaniumDemangle.h | 24 ++++++----------------- llvm/include/llvm/Demangle/ItaniumDemangle.h | 24 ++++++----------------- llvm/lib/Demangle/ItaniumDemangle.cpp | 9 --------- llvm/lib/Support/ItaniumManglingCanonicalizer.cpp | 14 ------------- 4 files changed, 12 insertions(+), 59 deletions(-) diff --git a/libcxxabi/src/demangle/ItaniumDemangle.h b/libcxxabi/src/demangle/ItaniumDemangle.h index db65c60..b835345 100644 --- a/libcxxabi/src/demangle/ItaniumDemangle.h +++ b/libcxxabi/src/demangle/ItaniumDemangle.h @@ -73,7 +73,6 @@ X(ForwardTemplateReference) \ X(NameWithTemplateArgs) \ X(GlobalQualifiedName) \ - X(StdQualifiedName) \ X(ExpandedSpecialSubstitution) \ X(SpecialSubstitution) \ X(CtorDtorName) \ @@ -1473,21 +1472,6 @@ public: } }; -struct StdQualifiedName : Node { - Node *Child; - - StdQualifiedName(Node *Child_) : Node(KStdQualifiedName), Child(Child_) {} - - template void match(Fn F) const { F(Child); } - - StringView getBaseName() const override { return Child->getBaseName(); } - - void printLeft(OutputBuffer &OB) const override { - OB += "std::"; - Child->print(OB); - } -}; - enum class SpecialSubKind { allocator, basic_string, @@ -2678,8 +2662,12 @@ AbstractManglingParser::parseUnscopedName(NameState *State) { Node *Result = getDerived().parseUnqualifiedName(State); if (Result == nullptr) return nullptr; - if (IsStd) - Result = make(Result); + if (IsStd) { + if (auto *Std = make("std")) + Result = make(Std, Result); + else + return nullptr; + } return Result; } diff --git a/llvm/include/llvm/Demangle/ItaniumDemangle.h b/llvm/include/llvm/Demangle/ItaniumDemangle.h index f6acd62..6ac7712 100644 --- a/llvm/include/llvm/Demangle/ItaniumDemangle.h +++ b/llvm/include/llvm/Demangle/ItaniumDemangle.h @@ -73,7 +73,6 @@ X(ForwardTemplateReference) \ X(NameWithTemplateArgs) \ X(GlobalQualifiedName) \ - X(StdQualifiedName) \ X(ExpandedSpecialSubstitution) \ X(SpecialSubstitution) \ X(CtorDtorName) \ @@ -1473,21 +1472,6 @@ public: } }; -struct StdQualifiedName : Node { - Node *Child; - - StdQualifiedName(Node *Child_) : Node(KStdQualifiedName), Child(Child_) {} - - template void match(Fn F) const { F(Child); } - - StringView getBaseName() const override { return Child->getBaseName(); } - - void printLeft(OutputBuffer &OB) const override { - OB += "std::"; - Child->print(OB); - } -}; - enum class SpecialSubKind { allocator, basic_string, @@ -2678,8 +2662,12 @@ AbstractManglingParser::parseUnscopedName(NameState *State) { Node *Result = getDerived().parseUnqualifiedName(State); if (Result == nullptr) return nullptr; - if (IsStd) - Result = make(Result); + if (IsStd) { + if (auto *Std = make("std")) + Result = make(Std, Result); + else + return nullptr; + } return Result; } diff --git a/llvm/lib/Demangle/ItaniumDemangle.cpp b/llvm/lib/Demangle/ItaniumDemangle.cpp index 1a5db75..06a74c1 100644 --- a/llvm/lib/Demangle/ItaniumDemangle.cpp +++ b/llvm/lib/Demangle/ItaniumDemangle.cpp @@ -404,9 +404,6 @@ char *ItaniumPartialDemangler::getFunctionBaseName(char *Buf, size_t *N) const { case Node::KAbiTagAttr: Name = static_cast(Name)->Base; continue; - case Node::KStdQualifiedName: - Name = static_cast(Name)->Child; - continue; case Node::KNestedName: Name = static_cast(Name)->Name; continue; @@ -446,9 +443,6 @@ char *ItaniumPartialDemangler::getFunctionDeclContextName(char *Buf, } switch (Name->getKind()) { - case Node::KStdQualifiedName: - OB += "std"; - break; case Node::KNestedName: static_cast(Name)->Qual->print(OB); break; @@ -550,9 +544,6 @@ bool ItaniumPartialDemangler::isCtorOrDtor() const { case Node::KNestedName: N = static_cast(N)->Name; break; - case Node::KStdQualifiedName: - N = static_cast(N)->Child; - break; } } return false; diff --git a/llvm/lib/Support/ItaniumManglingCanonicalizer.cpp b/llvm/lib/Support/ItaniumManglingCanonicalizer.cpp index e6cba26..52d5de9 100644 --- a/llvm/lib/Support/ItaniumManglingCanonicalizer.cpp +++ b/llvm/lib/Support/ItaniumManglingCanonicalizer.cpp @@ -189,20 +189,6 @@ public: bool trackedNodeIsUsed() const { return TrackedNodeIsUsed; } }; -/// Convert St3foo to NSt3fooE so that equivalences naming one also affect the -/// other. -template<> -struct CanonicalizerAllocator::MakeNodeImpl< - itanium_demangle::StdQualifiedName> { - CanonicalizerAllocator &Self; - Node *make(Node *Child) { - Node *StdNamespace = Self.makeNode("std"); - if (!StdNamespace) - return nullptr; - return Self.makeNode(StdNamespace, Child); - } -}; - // FIXME: Also expand built-in substitutions? using CanonicalizingDemangler = -- 2.7.4