[PATCH] D16706: SmallSet/SmallPtrSet: Refuse huge SmallSize/N numbers

Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Feb 1 14:09:36 PST 2016


This revision was automatically updated to reflect the committed changes.
Closed by commit rL259419: SmallSet/SmallPtrSet: Refuse huge Small numbers (authored by matze).

Changed prior to commit:
  http://reviews.llvm.org/D16706?vs=46339&id=46579#toc

Repository:
  rL LLVM

http://reviews.llvm.org/D16706

Files:
  llvm/trunk/include/llvm/ADT/SmallPtrSet.h
  llvm/trunk/include/llvm/ADT/SmallSet.h
  llvm/trunk/lib/Target/CppBackend/CPPBackend.cpp

Index: llvm/trunk/lib/Target/CppBackend/CPPBackend.cpp
===================================================================
--- llvm/trunk/lib/Target/CppBackend/CPPBackend.cpp
+++ llvm/trunk/lib/Target/CppBackend/CPPBackend.cpp
@@ -1651,8 +1651,8 @@
 
   // 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();
Index: llvm/trunk/include/llvm/ADT/SmallPtrSet.h
===================================================================
--- llvm/trunk/include/llvm/ADT/SmallPtrSet.h
+++ llvm/trunk/include/llvm/ADT/SmallPtrSet.h
@@ -329,6 +329,11 @@
 /// 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.
Index: llvm/trunk/include/llvm/ADT/SmallSet.h
===================================================================
--- llvm/trunk/include/llvm/ADT/SmallSet.h
+++ llvm/trunk/include/llvm/ADT/SmallSet.h
@@ -38,6 +38,11 @@
   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() {}


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D16706.46579.patch
Type: text/x-patch
Size: 2169 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160201/ef101ff6/attachment.bin>


More information about the llvm-commits mailing list