There are a few places around C2 where we inefficiently iterate over RegMasks:
RegMask rm = n->out_RegMask();// Make local copy
while( rm.is_NotEmpty() ) {
OptoReg::Name kill = rm.find_first_elem();
rm.Remove(kill);
verify_do_def( n, kill, msg );
}
This copies a RegMask, then find_first_elem + remove in a loop until all registers have been found. find_first_elem is O(n), so this is accidentally quadratic.
By implementing a simple RegMaskIterator we can speed this up and possibly make the code a bit clearer by doing so.
RegMask rm = n->out_RegMask();// Make local copy
while( rm.is_NotEmpty() ) {
OptoReg::Name kill = rm.find_first_elem();
rm.Remove(kill);
verify_do_def( n, kill, msg );
}
This copies a RegMask, then find_first_elem + remove in a loop until all registers have been found. find_first_elem is O(n), so this is accidentally quadratic.
By implementing a simple RegMaskIterator we can speed this up and possibly make the code a bit clearer by doing so.