[LLVMdev] Small problem in BitVector.h

Roman Levenstein romix.llvm at googlemail.com
Fri Jan 23 04:51:38 PST 2009


Hi,

Doing some profiling of llc, I noticed that some bitvector operations
took longer than usual. Then I noticed that too many copies of
BitVector obejcts are created, even when such operations like &=, ^=,
|= are performed on those bit vectors.

I looked at the BitVector ADT implementation in BitVector.h and
figured out that all assignment operations (except the usual
assignment operator) return a copy of the bit vector, instead of a
reference!
I guess it was just overlooked.

Below is the patch to fix it. Is it OK to commit?

- Roman


Index: BitVector.h
===================================================================
--- BitVector.h (revision 62258)
+++ BitVector.h (working copy)
@@ -286,7 +286,7 @@
   }

   // Intersection, union, disjoint union.
-  BitVector operator&=(const BitVector &RHS) {
+  BitVector &operator&=(const BitVector &RHS) {
     unsigned ThisWords = NumBitWords(size());
     unsigned RHSWords  = NumBitWords(RHS.size());
     unsigned i;
@@ -302,14 +302,14 @@
     return *this;
   }

-  BitVector operator|=(const BitVector &RHS) {
+  BitVector &operator|=(const BitVector &RHS) {
     assert(Size == RHS.Size && "Illegal operation!");
     for (unsigned i = 0; i < NumBitWords(size()); ++i)
       Bits[i] |= RHS.Bits[i];
     return *this;
   }

-  BitVector operator^=(const BitVector &RHS) {
+  BitVector &operator^=(const BitVector &RHS) {
     assert(Size == RHS.Size && "Illegal operation!");
     for (unsigned i = 0; i < NumBitWords(size()); ++i)
       Bits[i] ^= RHS.Bits[i];



More information about the llvm-dev mailing list