[llvm-commits] [llvm] r125224 - in /llvm/trunk/lib/CodeGen: LiveIntervalUnion.cpp LiveIntervalUnion.h

Jakob Stoklund Olesen stoklund at 2pi.dk
Wed Feb 9 13:52:04 PST 2011


Author: stoklund
Date: Wed Feb  9 15:52:03 2011
New Revision: 125224

URL: http://llvm.org/viewvc/llvm-project?rev=125224&view=rev
Log:
Add tags to live interval unions to avoid using stale queries.

The tag is updated whenever the live interval union is changed, and it is tested
before using cached information.

Modified:
    llvm/trunk/lib/CodeGen/LiveIntervalUnion.cpp
    llvm/trunk/lib/CodeGen/LiveIntervalUnion.h

Modified: llvm/trunk/lib/CodeGen/LiveIntervalUnion.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/LiveIntervalUnion.cpp?rev=125224&r1=125223&r2=125224&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/LiveIntervalUnion.cpp (original)
+++ llvm/trunk/lib/CodeGen/LiveIntervalUnion.cpp Wed Feb  9 15:52:03 2011
@@ -28,6 +28,7 @@
 void LiveIntervalUnion::unify(LiveInterval &VirtReg) {
   if (VirtReg.empty())
     return;
+  ++Tag;
 
   // Insert each of the virtual register's live segments into the map.
   LiveInterval::iterator RegPos = VirtReg.begin();
@@ -46,6 +47,7 @@
 void LiveIntervalUnion::extract(LiveInterval &VirtReg) {
   if (VirtReg.empty())
     return;
+  ++Tag;
 
   // Remove each of the virtual register's live segments from the map.
   LiveInterval::iterator RegPos = VirtReg.begin();

Modified: llvm/trunk/lib/CodeGen/LiveIntervalUnion.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/LiveIntervalUnion.h?rev=125224&r1=125223&r2=125224&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/LiveIntervalUnion.h (original)
+++ llvm/trunk/lib/CodeGen/LiveIntervalUnion.h Wed Feb  9 15:52:03 2011
@@ -64,10 +64,12 @@
 
 private:
   const unsigned RepReg;  // representative register number
+  unsigned Tag;           // unique tag for current contents.
   LiveSegments Segments;  // union of virtual reg segments
 
 public:
-  LiveIntervalUnion(unsigned r, Allocator &a) : RepReg(r), Segments(a) {}
+  LiveIntervalUnion(unsigned r, Allocator &a) : RepReg(r), Tag(0), Segments(a)
+    {}
 
   // Iterate over all segments in the union of live virtual registers ordered
   // by their starting position.
@@ -81,6 +83,12 @@
   typedef LiveSegments Map;
   const Map &getMap() { return Segments; }
 
+  /// getTag - Return an opaque tag representing the current state of the union.
+  unsigned getTag() const { return Tag; }
+
+  /// changedSince - Return true if the union change since getTag returned tag.
+  bool changedSince(unsigned tag) const { return tag != Tag; }
+
   // Add a live virtual register to this union and merge its segments.
   void unify(LiveInterval &VirtReg);
 
@@ -155,6 +163,7 @@
     bool CheckedFirstInterference;
     bool SeenAllInterferences;
     bool SeenUnspillableVReg;
+    unsigned Tag;
 
   public:
     Query(): LiveUnion(), VirtReg() {}
@@ -171,17 +180,19 @@
       CheckedFirstInterference = false;
       SeenAllInterferences = false;
       SeenUnspillableVReg = false;
+      Tag = 0;
     }
 
     void init(LiveInterval *VReg, LiveIntervalUnion *LIU) {
       assert(VReg && LIU && "Invalid arguments");
-      if (VirtReg == VReg && LiveUnion == LIU) {
+      if (VirtReg == VReg && LiveUnion == LIU && !LIU->changedSince(Tag)) {
         // Retain cached results, e.g. firstInterference.
         return;
       }
       clear();
       LiveUnion = LIU;
       VirtReg = VReg;
+      Tag = LIU->getTag();
     }
 
     LiveInterval &virtReg() const {





More information about the llvm-commits mailing list