llvm.org GIT mirror llvm / af3056c
Fix a limitation of SmallPtrSet. Before it would assert if the smallsize was not a power of two. Now it rounds up to the next power of two internally. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@33580 91177308-0d34-0410-b5e6-96231b3b80d8 Chris Lattner 13 years ago
1 changed file(s) with 31 addition(s) and 3 deletion(s). Raw diff Collapse all Expand all
160160 }
161161 };
162162
163 /// NextPowerOfTwo - This is a helper template that rounds N up to the next
164 /// power of two.
165 template
166 struct NextPowerOfTwo;
167
168 /// NextPowerOfTwoH - If N is not a power of two, increase it. This is a helper
169 /// template used to implement NextPowerOfTwo.
170 template
171 struct NextPowerOfTwoH {
172 enum { Val = N };
173 };
174 template
175 struct NextPowerOfTwoH {
176 enum {
177 // We could just use NextVal = N+1, but this converges faster. N|(N-1) sets
178 // the right-most zero bits to one all at once, e.g. 0b0011000 -> 0b0011111.
179 NextVal = (N|(N-1)) + 1,
180 Val = NextPowerOfTwo::Val
181 };
182 };
183
184 template
185 struct NextPowerOfTwo {
186 enum { Val = NextPowerOfTwoH::Val };
187 };
188
163189
164190 /// SmallPtrSet - This class implements
165191 template
166192 class SmallPtrSet : public SmallPtrSetImpl {
167 void *SmallArray[SmallSize];
168 public:
169 SmallPtrSet() : SmallPtrSetImpl(SmallSize) {}
193 // Make sure that SmallSize is a power of two, round up if not.
194 enum { SmallSizePowTwo = NextPowerOfTwo::Val };
195 void *SmallArray[SmallSizePowTwo];
196 public:
197 SmallPtrSet() : SmallPtrSetImpl(NextPowerOfTwo::Val) {}
170198
171199 typedef SmallPtrSetIterator iterator;
172200 typedef SmallPtrSetIterator const_iterator;