This is an archive of the discontinued LLVM Phabricator instance.

Introduce BitSet: A BitVector based class behaving like std::set/DenseSet
AbandonedPublic

Authored by MatzeB on Mar 29 2016, 2:34 PM.

Details

Diff Detail

Repository
rL LLVM

Event Timeline

MatzeB updated this revision to Diff 51985.Mar 29 2016, 2:34 PM
MatzeB retitled this revision from to BitVector: Add insert() and erase() methods..
MatzeB updated this object.
MatzeB added reviewers: dblaikie, echristo, qcolombet.
MatzeB set the repository for this revision to rL LLVM.
MatzeB added a subscriber: llvm-commits.
dblaikie edited edge metadata.Mar 29 2016, 10:25 PM
dblaikie added a subscriber: dblaikie.

Test cases?
Got a usage in mind?

MatzeB updated this revision to Diff 52120.Mar 30 2016, 1:57 PM
MatzeB edited edge metadata.

Implement insert() and erase() in SmallBitVector as well and add tests.

Test cases?
Got a usage in mind?

The concrete usage I have in mind is using a BitVector for Set type parameter of a SetVector. This is in the context of http://reviews.llvm.org/D18427.

And if you think about it: Even though the class is called a BitVector most of the time you really use it more like a set where you insert and remove elements from and not like a vector there is no BitVector::push_back() or iterators after all. So having operations compatible with std::set and DenseSet makes sense.

MatzeB updated this revision to Diff 52142.Mar 30 2016, 3:26 PM
MatzeB retitled this revision from BitVector: Add insert() and erase() methods. to BitVector: Add insert(), erase() and count() methods..

Also added the count(X) method. count(X) is another operand from std::set/DenseSet and was required to get all of SetVector<> working.

MatzeB updated this revision to Diff 52446.Apr 1 2016, 4:58 PM
MatzeB retitled this revision from BitVector: Add insert(), erase() and count() methods. to Introduce BitSet: A BitVector based class behaving like std::set/DenseSet.
MatzeB updated this object.

New revision introducing a new proxy class acting like a set but backed by a BitVector.

Also comes with more extensive unittests for set classes.

This seems to have strange behavior - returning the size/empty status of
the BitVector for the BitSets operations is probably wrong, no? (the
BitVector's length is the length of the field, not the number of set (1)
bits in it)

This seems to have strange behavior - returning the size/empty status of
the BitVector for the BitSets operations is probably wrong, no? (the
BitVector's length is the length of the field, not the number of set (1)
bits in it)

BitSet::size() should return the number of elements in the set which corresponds to the number of set bits in the bitvector which should be BitVector::count().

empty() checks BitSet::size() against 0 which should be equivalent to BitVector::count() == 0.

MatzeB updated this revision to Diff 53816.Apr 14 2016, 5:01 PM

Address review comments.

MatzeB updated this revision to Diff 53819.Apr 14 2016, 5:12 PM

Address review comments.

It is nice to have a separate BitSet instead of adding the API to the BitVector, but at the same time I wonder about some inefficiencies due the wrapping here? See inline for instance.

include/llvm/ADT/BitSet.h
58

This is requerying the Vector uselessly here (or post-increment is not good anyway but still).

65

Could the iterator be lazy and not do anything on creation? (that would solve the point above by the way)

112

Again that's 3 queries to the vector instead of one, I wonder if the compiler CSE perfectly the generated code.

MatzeB updated this revision to Diff 53826.Apr 14 2016, 5:40 PM
MatzeB marked 3 inline comments as done.

Address review comments.

include/llvm/ADT/BitSet.h
112

The new version of the code should avoid the advance() calls in the iterator. This is just the way the STL set APIs work, unfortunately this is will always be an extra load and pair<> creation even if most users don't need the return value. You can only hope the compiler inlines properly and throws the return value and extra queries away.

MatzeB abandoned this revision.Dec 15 2016, 3:47 PM

Abandoning for lack of progress and use case. The motivating pass simply uses a combination of BitVector+Set instead of a SetVector now.

unittests/ADT/CMakeLists.txt