[clang] 33c9d03 - Upgrade SmallSets of pointer-like types to SmallPtrSet
Benjamin Kramer via cfe-commits
cfe-commits at lists.llvm.org
Mon Jul 20 07:58:42 PDT 2020
Author: Benjamin Kramer
Date: 2020-07-20T16:54:29+02:00
New Revision: 33c9d0320e96ba17a3c7e84e04e22536f4b0a9e8
URL: https://github.com/llvm/llvm-project/commit/33c9d0320e96ba17a3c7e84e04e22536f4b0a9e8
DIFF: https://github.com/llvm/llvm-project/commit/33c9d0320e96ba17a3c7e84e04e22536f4b0a9e8.diff
LOG: Upgrade SmallSets of pointer-like types to SmallPtrSet
This is slightly more efficient. NFC.
Added:
Modified:
clang/include/clang/AST/DeclarationName.h
clang/include/clang/AST/Redeclarable.h
clang/lib/Sema/Sema.cpp
clang/lib/Sema/SemaExprCXX.cpp
clang/lib/Sema/SemaOpenMP.cpp
clang/lib/Serialization/ASTWriter.cpp
clang/lib/StaticAnalyzer/Checkers/ObjCMissingSuperCallChecker.cpp
Removed:
################################################################################
diff --git a/clang/include/clang/AST/DeclarationName.h b/clang/include/clang/AST/DeclarationName.h
index 82f6868e3a7e..a037e8b197bc 100644
--- a/clang/include/clang/AST/DeclarationName.h
+++ b/clang/include/clang/AST/DeclarationName.h
@@ -857,6 +857,16 @@ struct DenseMapInfo<clang::DeclarationName> {
}
};
+template <> struct PointerLikeTypeTraits<clang::DeclarationName> {
+ static inline void *getAsVoidPointer(clang::DeclarationName P) {
+ return P.getAsOpaquePtr();
+ }
+ static inline clang::DeclarationName getFromVoidPointer(void *P) {
+ return clang::DeclarationName::getFromOpaquePtr(P);
+ }
+ static constexpr int NumLowBitsAvailable = 0;
+};
+
} // namespace llvm
// The definition of AssumedTemplateStorage is factored out of TemplateName to
diff --git a/clang/include/clang/AST/Redeclarable.h b/clang/include/clang/AST/Redeclarable.h
index 0975773dd2cb..87252337a0f4 100644
--- a/clang/include/clang/AST/Redeclarable.h
+++ b/clang/include/clang/AST/Redeclarable.h
@@ -370,6 +370,7 @@ template <typename decl_type> class CanonicalDeclPtr {
private:
friend struct llvm::DenseMapInfo<CanonicalDeclPtr<decl_type>>;
+ friend struct llvm::PointerLikeTypeTraits<CanonicalDeclPtr<decl_type>>;
decl_type *Ptr = nullptr;
};
@@ -407,6 +408,20 @@ struct DenseMapInfo<clang::CanonicalDeclPtr<decl_type>> {
}
};
+template <typename decl_type>
+struct PointerLikeTypeTraits<clang::CanonicalDeclPtr<decl_type>> {
+ static inline void *getAsVoidPointer(clang::CanonicalDeclPtr<decl_type> P) {
+ return P.Ptr;
+ }
+ static inline clang::CanonicalDeclPtr<decl_type> getFromVoidPointer(void *P) {
+ clang::CanonicalDeclPtr<decl_type> C;
+ C.Ptr = PointerLikeTypeTraits<decl_type *>::getFromVoidPtr(P);
+ return C;
+ }
+ static constexpr int NumLowBitsAvailable =
+ PointerLikeTypeTraits<decl_type *>::NumLowBitsAvailable;
+};
+
} // namespace llvm
#endif // LLVM_CLANG_AST_REDECLARABLE_H
diff --git a/clang/lib/Sema/Sema.cpp b/clang/lib/Sema/Sema.cpp
index 2f2b52106f3d..735349c3de62 100644
--- a/clang/lib/Sema/Sema.cpp
+++ b/clang/lib/Sema/Sema.cpp
@@ -42,7 +42,7 @@
#include "clang/Sema/TemplateInstCallback.h"
#include "clang/Sema/TypoCorrection.h"
#include "llvm/ADT/DenseMap.h"
-#include "llvm/ADT/SmallSet.h"
+#include "llvm/ADT/SmallPtrSet.h"
#include "llvm/Support/TimeProfiler.h"
using namespace clang;
@@ -1490,7 +1490,7 @@ class DeferredDiagnosticsEmitter
typedef UsedDeclVisitor<DeferredDiagnosticsEmitter> Inherited;
// Whether the function is already in the current use-path.
- llvm::SmallSet<CanonicalDeclPtr<Decl>, 4> InUsePath;
+ llvm::SmallPtrSet<CanonicalDeclPtr<Decl>, 4> InUsePath;
// The current use-path.
llvm::SmallVector<CanonicalDeclPtr<FunctionDecl>, 4> UsePath;
@@ -1499,7 +1499,7 @@ class DeferredDiagnosticsEmitter
// case not in OpenMP device context. Done[1] is for the case in OpenMP
// device context. We need two sets because diagnostics emission may be
//
diff erent depending on whether it is in OpenMP device context.
- llvm::SmallSet<CanonicalDeclPtr<Decl>, 4> DoneMap[2];
+ llvm::SmallPtrSet<CanonicalDeclPtr<Decl>, 4> DoneMap[2];
// Emission state of the root node of the current use graph.
bool ShouldEmitRootNode;
diff --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp
index 212f5e4746d6..001fabff96ff 100644
--- a/clang/lib/Sema/SemaExprCXX.cpp
+++ b/clang/lib/Sema/SemaExprCXX.cpp
@@ -172,7 +172,7 @@ ParsedType Sema::getDestructorName(SourceLocation TildeLoc,
bool Failed = false;
llvm::SmallVector<NamedDecl*, 8> FoundDecls;
- llvm::SmallSet<CanonicalDeclPtr<Decl>, 8> FoundDeclSet;
+ llvm::SmallPtrSet<CanonicalDeclPtr<Decl>, 8> FoundDeclSet;
// If we have an object type, it's because we are in a
// pseudo-destructor-expression or a member access expression, and
diff --git a/clang/lib/Sema/SemaOpenMP.cpp b/clang/lib/Sema/SemaOpenMP.cpp
index 8bf605e5e76b..1e7d432217d5 100644
--- a/clang/lib/Sema/SemaOpenMP.cpp
+++ b/clang/lib/Sema/SemaOpenMP.cpp
@@ -19028,7 +19028,7 @@ OMPClause *Sema::ActOnOpenMPUsesAllocatorClause(
[](const UsesAllocatorsData &D) { return D.AllocatorTraits; }) &&
!findOMPAlloctraitT(*this, StartLoc, DSAStack))
return nullptr;
- llvm::SmallSet<CanonicalDeclPtr<Decl>, 4> PredefinedAllocators;
+ llvm::SmallPtrSet<CanonicalDeclPtr<Decl>, 4> PredefinedAllocators;
for (int I = 0; I < OMPAllocateDeclAttr::OMPUserDefinedMemAlloc; ++I) {
auto AllocatorKind = static_cast<OMPAllocateDeclAttr::AllocatorTypeTy>(I);
StringRef Allocator =
diff --git a/clang/lib/Serialization/ASTWriter.cpp b/clang/lib/Serialization/ASTWriter.cpp
index 2345a12caeb2..a8803aeb1b8a 100644
--- a/clang/lib/Serialization/ASTWriter.cpp
+++ b/clang/lib/Serialization/ASTWriter.cpp
@@ -81,7 +81,7 @@
#include "llvm/ADT/PointerIntPair.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/ScopeExit.h"
-#include "llvm/ADT/SmallSet.h"
+#include "llvm/ADT/SmallPtrSet.h"
#include "llvm/ADT/SmallString.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringMap.h"
@@ -3690,7 +3690,7 @@ ASTWriter::GenerateNameLookupTable(const DeclContext *ConstDC,
// We also build up small sets of the constructor and conversion function
// names which are visible.
- llvm::SmallSet<DeclarationName, 8> ConstructorNameSet, ConversionNameSet;
+ llvm::SmallPtrSet<DeclarationName, 8> ConstructorNameSet, ConversionNameSet;
for (auto &Lookup : *DC->buildLookup()) {
auto &Name = Lookup.first;
diff --git a/clang/lib/StaticAnalyzer/Checkers/ObjCMissingSuperCallChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/ObjCMissingSuperCallChecker.cpp
index 24e2a4dea922..35a600f2d7b8 100644
--- a/clang/lib/StaticAnalyzer/Checkers/ObjCMissingSuperCallChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/ObjCMissingSuperCallChecker.cpp
@@ -21,7 +21,7 @@
#include "clang/StaticAnalyzer/Core/BugReporter/BugReporter.h"
#include "clang/StaticAnalyzer/Core/Checker.h"
#include "clang/StaticAnalyzer/Core/PathSensitive/AnalysisManager.h"
-#include "llvm/ADT/SmallSet.h"
+#include "llvm/ADT/SmallPtrSet.h"
#include "llvm/ADT/SmallString.h"
#include "llvm/Support/raw_ostream.h"
@@ -74,7 +74,7 @@ class ObjCSuperCallChecker : public Checker<
void initializeSelectors(ASTContext &Ctx) const;
void fillSelectors(ASTContext &Ctx, ArrayRef<SelectorDescriptor> Sel,
StringRef ClassName) const;
- mutable llvm::StringMap<llvm::SmallSet<Selector, 16> > SelectorsForClass;
+ mutable llvm::StringMap<llvm::SmallPtrSet<Selector, 16>> SelectorsForClass;
mutable bool IsInitialized;
};
@@ -100,7 +100,8 @@ bool ObjCSuperCallChecker::isCheckableClass(const ObjCImplementationDecl *D,
void ObjCSuperCallChecker::fillSelectors(ASTContext &Ctx,
ArrayRef<SelectorDescriptor> Sel,
StringRef ClassName) const {
- llvm::SmallSet<Selector, 16> &ClassSelectors = SelectorsForClass[ClassName];
+ llvm::SmallPtrSet<Selector, 16> &ClassSelectors =
+ SelectorsForClass[ClassName];
// Fill the Selectors SmallSet with all selectors we want to check.
for (ArrayRef<SelectorDescriptor>::iterator I = Sel.begin(), E = Sel.end();
I != E; ++I) {
More information about the cfe-commits
mailing list