[LLVMdev] EquivalenceClasses: findValue vs. findLeader

David A. Greene greened at obbligato.org
Fri Jun 15 15:03:24 PDT 2007


Given an object o of ElemType in an instance of EquivalenceClasses, I need
to get a list of all members of the equivalence class that o is in.  For 
various reasons, it is easiest if I could get an EquivalenceClasses::iterator
that I can pass to member_begin and member_end.

So naturally, I did something like this (pseudo-C++):

EquivalenceClasses::iterator i = equiv.findValue(o);
for(equiv.member_begin(i); member_end(i); ++i) {
   // Do stuff
}

Unfortunately, this doesn't seem to work.  findValue returns an iterator that
is not end(), but the member set of the equivalence class is empty.

Strangly, when I just iterate through the EquivalenceClasses object like this:

        for(iterator i = equiv.begin(),
                iend = equiv.end();
            i != iend;
            ++i) {
          DOUT << "### New set:\n";
          for(member_iterator j = 
                  equiv.member_begin(i),
                  jend = equiv.member_end(i);
                j != jend;
                ++j) {
            dump_member(*j);
            DOUT << "\n";
          }        
        }

I get something like this:

### New set:
### New set:
### New set:
### New set:
### New set:
### New set:
a
b
### New set:
### New set:
c
d
e
f
### New set:
g
### New set:
h
### New set:
i
j


Why all the empty sets?  Is this an artifact of the path compression?

What does findLeader do?  Does it return a member iterator that is at the
beginning of the list of equivalence class members?  The Doxygen 
documentation seems to indicate that it does not, but returns a 
member_iterator pointing to o.  But then what is a "Leader" and why do
I care?

                                               -Dave



More information about the llvm-dev mailing list