[llvm] r227562 - Change a very hot piece of code in TableGen's register unit computations to use bit vectors rather than arrays.

Owen Anderson resistor at mac.com
Fri Jan 30 01:05:49 PST 2015


Author: resistor
Date: Fri Jan 30 03:05:49 2015
New Revision: 227562

URL: http://llvm.org/viewvc/llvm-project?rev=227562&view=rev
Log:
Change a very hot piece of code in TableGen's register unit computations to use bit vectors rather than arrays.

For target descriptions with very large and very dense register files, TableGen
can take an extremely long time to run.  This change makes a dent in that (~15%
in my measurements) by accelerating the single hottest operation with better data
structures.

I believe there's still a lot of room to make this even faster with more global
changes that require replacing some of the existing datastructures in this area
with bit vectors, but that's a more involved change and I wanted to get this
simpler improvement in first.

Modified:
    llvm/trunk/utils/TableGen/CodeGenRegisters.cpp

Modified: llvm/trunk/utils/TableGen/CodeGenRegisters.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/TableGen/CodeGenRegisters.cpp?rev=227562&r1=227561&r2=227562&view=diff
==============================================================================
--- llvm/trunk/utils/TableGen/CodeGenRegisters.cpp (original)
+++ llvm/trunk/utils/TableGen/CodeGenRegisters.cpp Fri Jan 30 03:05:49 2015
@@ -17,6 +17,7 @@
 #include "llvm/ADT/IntEqClasses.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/SmallVector.h"
+#include "llvm/ADT/SparseBitVector.h"
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/ADT/Twine.h"
 #include "llvm/Support/Debug.h"
@@ -211,12 +212,24 @@ static bool hasRegUnit(CodeGenRegister::
 // Return true if the RegUnits changed.
 bool CodeGenRegister::inheritRegUnits(CodeGenRegBank &RegBank) {
   unsigned OldNumUnits = RegUnits.size();
+
+  SparseBitVector<> NewUnits;
+  for (unsigned RU : RegUnits)
+    NewUnits.set(RU);
+
   for (SubRegMap::const_iterator I = SubRegs.begin(), E = SubRegs.end();
        I != E; ++I) {
     CodeGenRegister *SR = I->second;
     // Merge the subregister's units into this register's RegUnits.
-    mergeRegUnits(RegUnits, SR->RegUnits);
+    for (unsigned RU : SR->RegUnits)
+      NewUnits.set(RU);
   }
+
+  RegUnits.clear();
+  RegUnits.reserve(NewUnits.count());
+  for (unsigned RU : NewUnits)
+    RegUnits.push_back(RU);
+
   return OldNumUnits != RegUnits.size();
 }
 





More information about the llvm-commits mailing list