From 2005f484f6c021318848cffda2c3d97c58615bb5 Mon Sep 17 00:00:00 2001 From: Vlad Serebrennikov Date: Wed, 25 Oct 2023 17:37:56 +0400 Subject: [clang][NFC] Refactor `Selector` to use `PointerIntPair` inside (#69916) Refactor `uintptr_t` inside of `clang::Selector` that holds a pointer to `IdentifierInfo` or `MultiKeywordSelector` and `IdentifierInfoFlag` enum into `PointerIntPair`. This is a part of `PointerIntPair` migration outlined in https://github.com/llvm/llvm-project/issues/69835. Unlike `uintpt_t`, `PointerIntPair` required pointee types to be complete, so I had to shuffle definitions of `MultiKeywordSelector` and `detail::DeclarationNameExtra` around to make them complete at `Selector`. Also, there were outdated specializations of `PointerLikeTypeTraits` for `IdentifierInfo *`, which are no longer needed, because `alignof` that primary template use works just fine. Not just that, but they declared that `IdentifierInfo *` has only 1 spare lower bit, but today they are 8-byte aligned. --- clang/lib/Basic/IdentifierTable.cpp | 59 +------------------------------------ 1 file changed, 1 insertion(+), 58 deletions(-) (limited to 'clang/lib/Basic/IdentifierTable.cpp') diff --git a/clang/lib/Basic/IdentifierTable.cpp b/clang/lib/Basic/IdentifierTable.cpp index e5599d5..c4c5a6e 100644 --- a/clang/lib/Basic/IdentifierTable.cpp +++ b/clang/lib/Basic/IdentifierTable.cpp @@ -512,63 +512,6 @@ unsigned llvm::DenseMapInfo::getHashValue(clang::Selector S) { return DenseMapInfo::getHashValue(S.getAsOpaquePtr()); } -namespace clang { - -/// One of these variable length records is kept for each -/// selector containing more than one keyword. We use a folding set -/// to unique aggregate names (keyword selectors in ObjC parlance). Access to -/// this class is provided strictly through Selector. -class alignas(IdentifierInfoAlignment) MultiKeywordSelector - : public detail::DeclarationNameExtra, - public llvm::FoldingSetNode { - MultiKeywordSelector(unsigned nKeys) : DeclarationNameExtra(nKeys) {} - -public: - // Constructor for keyword selectors. - MultiKeywordSelector(unsigned nKeys, IdentifierInfo **IIV) - : DeclarationNameExtra(nKeys) { - assert((nKeys > 1) && "not a multi-keyword selector"); - - // Fill in the trailing keyword array. - IdentifierInfo **KeyInfo = reinterpret_cast(this + 1); - for (unsigned i = 0; i != nKeys; ++i) - KeyInfo[i] = IIV[i]; - } - - // getName - Derive the full selector name and return it. - std::string getName() const; - - using DeclarationNameExtra::getNumArgs; - - using keyword_iterator = IdentifierInfo *const *; - - keyword_iterator keyword_begin() const { - return reinterpret_cast(this + 1); - } - - keyword_iterator keyword_end() const { - return keyword_begin() + getNumArgs(); - } - - IdentifierInfo *getIdentifierInfoForSlot(unsigned i) const { - assert(i < getNumArgs() && "getIdentifierInfoForSlot(): illegal index"); - return keyword_begin()[i]; - } - - static void Profile(llvm::FoldingSetNodeID &ID, keyword_iterator ArgTys, - unsigned NumArgs) { - ID.AddInteger(NumArgs); - for (unsigned i = 0; i != NumArgs; ++i) - ID.AddPointer(ArgTys[i]); - } - - void Profile(llvm::FoldingSetNodeID &ID) { - Profile(ID, keyword_begin(), getNumArgs()); - } -}; - -} // namespace clang. - bool Selector::isKeywordSelector(ArrayRef Names) const { assert(!Names.empty() && "must have >= 1 selector slots"); if (getNumArgs() != Names.size()) @@ -624,7 +567,7 @@ std::string MultiKeywordSelector::getName() const { } std::string Selector::getAsString() const { - if (InfoPtr == 0) + if (isNull()) return ""; if (getIdentifierInfoFlag() < MultiArg) { -- cgit v1.1