This is an archive of the discontinued LLVM Phabricator instance.

[BitVector] Add find_last() and find_last_unset()
ClosedPublic

Authored by zturner on Apr 20 2017, 10:53 AM.

Details

Summary

BitVector currently provides find_first() and find_first_unset(), this adds methods to search in reverse.

Diff Detail

Repository
rL LLVM

Event Timeline

zturner created this revision.Apr 20 2017, 10:53 AM
chandlerc added inline comments.Apr 20 2017, 5:48 PM
llvm/include/llvm/ADT/BitVector.h
170–173 ↗(On Diff #95984)

The for loop above seems simpler?

If you really want, you can use:

for (unsigned i : llvm::reverse(llvm::seq(0, NumBitWords(size())))
196–202 ↗(On Diff #95984)

Rather than this, what about just handling the last word outside the loop?

zturner updated this revision to Diff 96162.Apr 21 2017, 9:53 AM

Updated based on feedback from chandlerc.

zturner updated this revision to Diff 96163.Apr 21 2017, 9:56 AM

Fix an inverted conditional / break statement.

chandlerc accepted this revision.Apr 21 2017, 10:35 AM

LGTM with some loop simplifications.

llvm/include/llvm/ADT/BitVector.h
175–179 ↗(On Diff #96163)

I this can be written as:

while (i > 0 && Bits[i] != Bitword(0))
  --i;
213–218 ↗(On Diff #96163)

I think this is the same as:

while (W == ~BitWord(0) && --i > 0)
  W = Bits[i];
This revision is now accepted and ready to land.Apr 21 2017, 10:35 AM
This revision was automatically updated to reflect the committed changes.