[PATCH] D20178: Fix PR26055 - LiveDebugValues is very slow

Daniel Berlin via llvm-commits llvm-commits at lists.llvm.org
Mon May 16 09:40:29 PDT 2016


dberlin added inline comments.

================
Comment at: lib/CodeGen/LiveDebugValues.cpp:275
@@ -230,1 +274,3 @@
+          if (VarLocIDs[ID].isDescribedByReg() == *RAI)
+            OpenRanges.reset(ID);
     } else if (MO.isRegMask()) {
----------------
dberlin wrote:
> Are you positive of the invalidation semantics of sparsebitvector iterators?
> 
> In particular, what happens if the reset call causes the current element to go away?
> I do believe that will cause the iterator to be invalidated.
> 
> (Also, this is N^2)
One way to solve the invalidation problem, other than creating a separate bitvector, would be to not use the auto loop, but instead to always move the iterator forward and erase behind the iterator.

Two, you can solve the O(N^2)-ness a few ways (it's really worse, but let's just deal with the part going over the open ranges):

A simple way -

Form a bitvector out of this:

```
   for (const MachineOperand &MO : MI.operands()) {
      if (MO.isReg() && MO.isDef() && MO.getReg() &&
          TRI->isPhysicalRegister(MO.getReg())) {
        // Remove ranges of all aliased registers.
        for (MCRegAliasIterator RAI(MO.getReg(), TRI, true); RAI.isValid(); ++RAI)
            <set bit for *RAI here>
```

Then take this loop:
  for (unsigned ID : OpenRanges)
    if (VarLocIDs[ID].isDescribedByReg() == *RAI)


and do the tests against the bitvector instead (ie test the bit VarLocIDs[ID].isDescribedByReg()) 
This will only process each range once instead of process each range for every operand :)


This is essentially splitting it into:
1. Figure out which registers the machine instruction affects
2. Test which open ranges they affect

You can do things that are more complicated if this part gets slow.


================
Comment at: lib/CodeGen/LiveDebugValues.cpp:285
@@ -242,1 +284,3 @@
+          OpenRanges.reset(ID);
+      }
     }
----------------
dberlin wrote:
> Ditto iterator invalidation here.
> 
> You have have to make a temporary sparsebitmap and subtract it (intersectwithcomplement)
> 
You could also just move the iterator ahead of doing the reset.



http://reviews.llvm.org/D20178





More information about the llvm-commits mailing list