summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Braun <matze@braunis.de>2016-02-01 22:05:16 +0000
committerMatthias Braun <matze@braunis.de>2016-02-01 22:05:16 +0000
commit3f88eabe9396624efd391ce6fa543e6ce4b5ec5c (patch)
treed908e0c28644eed672bc759b6c7cea5bc971eb26
parentd8da15f8a9b6fa0097d9ec88432886ef7b7709fb (diff)
downloadbcm5719-llvm-3f88eabe9396624efd391ce6fa543e6ce4b5ec5c.tar.gz
bcm5719-llvm-3f88eabe9396624efd391ce6fa543e6ce4b5ec5c.zip
SmallSet/SmallPtrSet: Refuse huge Small numbers
These sets do linear searching in small mode; It is not a good idea to use huge numbers as the small value here, save people from themselves by adding a static_assert. Differential Revision: http://reviews.llvm.org/D16706 llvm-svn: 259419
-rw-r--r--llvm/include/llvm/ADT/SmallPtrSet.h5
-rw-r--r--llvm/include/llvm/ADT/SmallSet.h5
-rw-r--r--llvm/lib/Target/CppBackend/CPPBackend.cpp4
3 files changed, 12 insertions, 2 deletions
diff --git a/llvm/include/llvm/ADT/SmallPtrSet.h b/llvm/include/llvm/ADT/SmallPtrSet.h
index 36ff413d85b..849659d1745 100644
--- a/llvm/include/llvm/ADT/SmallPtrSet.h
+++ b/llvm/include/llvm/ADT/SmallPtrSet.h
@@ -329,6 +329,11 @@ public:
/// SmallPtrSetImplBase for details of the algorithm.
template<class PtrType, unsigned SmallSize>
class SmallPtrSet : public SmallPtrSetImpl<PtrType> {
+ // In small mode SmallPtrSet uses linear search for the elements, so it is
+ // not a good idea to choose this value too high. You may consider using a
+ // DenseSet<> instead if you expect many elements in the set.
+ static_assert(SmallSize <= 32, "SmallSize should be small");
+
typedef SmallPtrSetImpl<PtrType> BaseT;
// Make sure that SmallSize is a power of two, round up if not.
diff --git a/llvm/include/llvm/ADT/SmallSet.h b/llvm/include/llvm/ADT/SmallSet.h
index 39a57b87b2a..aaa5ff0ae93 100644
--- a/llvm/include/llvm/ADT/SmallSet.h
+++ b/llvm/include/llvm/ADT/SmallSet.h
@@ -38,6 +38,11 @@ class SmallSet {
typedef typename SmallVector<T, N>::const_iterator VIterator;
typedef typename SmallVector<T, N>::iterator mutable_iterator;
+ // In small mode SmallPtrSet uses linear search for the elements, so it is
+ // not a good idea to choose this value too high. You may consider using a
+ // DenseSet<> instead if you expect many elements in the set.
+ static_assert(N <= 32, "N should be small");
+
public:
typedef size_t size_type;
SmallSet() {}
diff --git a/llvm/lib/Target/CppBackend/CPPBackend.cpp b/llvm/lib/Target/CppBackend/CPPBackend.cpp
index dd5590307ee..cfa1f2ce619 100644
--- a/llvm/lib/Target/CppBackend/CPPBackend.cpp
+++ b/llvm/lib/Target/CppBackend/CPPBackend.cpp
@@ -1651,8 +1651,8 @@ void CppWriter::printFunctionUses(const Function* F) {
// Print type definitions for every type referenced by an instruction and
// make a note of any global values or constants that are referenced
- SmallPtrSet<GlobalValue*,64> gvs;
- SmallPtrSet<Constant*,64> consts;
+ SmallPtrSet<GlobalValue*,32> gvs;
+ SmallPtrSet<Constant*,32> consts;
for (Function::const_iterator BB = F->begin(), BE = F->end();
BB != BE; ++BB){
for (BasicBlock::const_iterator I = BB->begin(), E = BB->end();
OpenPOWER on IntegriCloud