Cache subregister relationships in a set in TargetRegisterInfo to allow faster lookups.
authorOwen Anderson <resistor@mac.com>
Fri, 27 Jun 2008 06:56:04 +0000 (06:56 +0000)
committerOwen Anderson <resistor@mac.com>
Fri, 27 Jun 2008 06:56:04 +0000 (06:56 +0000)
This speeds up LiveVariables from 0.6279s to 0.6165s on kimwitu++.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@52818 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/Target/TargetRegisterInfo.h
lib/Target/TargetRegisterInfo.cpp

index 2deede235f7063f0bea8954366bc305e5a695a82..68460b30cb4c1d3cbc089985327fc2a9d2415b92 100644 (file)
@@ -21,6 +21,7 @@
 #include "llvm/CodeGen/ValueTypes.h"
 #include <cassert>
 #include <functional>
+#include <set>
 
 namespace llvm {
 
@@ -285,6 +286,7 @@ private:
   regclass_iterator RegClassBegin, RegClassEnd;   // List of regclasses
 
   int CallFrameSetupOpcode, CallFrameDestroyOpcode;
+  std::set<std::pair<unsigned, unsigned> > Subregs;
 protected:
   TargetRegisterInfo(const TargetRegisterDesc *D, unsigned NR,
                      regclass_iterator RegClassBegin,
@@ -419,9 +421,7 @@ public:
   /// isSubRegister - Returns true if regB is a sub-register of regA.
   ///
   bool isSubRegister(unsigned regA, unsigned regB) const {
-    for (const unsigned *SR = getSubRegisters(regA); *SR; ++SR)
-      if (*SR == regB) return true;
-    return false;
+    return Subregs.count(std::make_pair(regA, regB));
   }
 
   /// isSuperRegister - Returns true if regB is a super-register of regA.
index 3f44a0cb5a319428b48839be1bc15e95f66fa3ef..e69496f4b287ba372c2f4871a9c1d999d07027c6 100644 (file)
@@ -29,6 +29,16 @@ TargetRegisterInfo::TargetRegisterInfo(const TargetRegisterDesc *D, unsigned NR,
 
   CallFrameSetupOpcode   = CFSO;
   CallFrameDestroyOpcode = CFDO;
+  
+  for (unsigned i = 0; i < NumRegs; ++i) {
+    const TargetRegisterDesc* CurrReg = Desc + i;
+    
+    // Initialize the Subregs set, which stores pairs (a, b) where
+    // b is a subreg of a.
+    if (CurrReg->SubRegs)
+      for (const unsigned* CurrSR = CurrReg->SubRegs; *CurrSR; ++CurrSR)
+        Subregs.insert(std::make_pair(i, *CurrSR));
+  }
 }
 
 TargetRegisterInfo::~TargetRegisterInfo() {}