[llvm-commits] [llvm] r122034 - in /llvm/trunk: include/llvm/ADT/IntervalMap.h include/llvm/CodeGen/MachineLoopRanges.h lib/CodeGen/LiveIntervalUnion.cpp lib/CodeGen/LiveIntervalUnion.h lib/CodeGen/MachineLoopRanges.cpp

Jakob Stoklund Olesen stoklund at 2pi.dk
Thu Dec 16 20:09:47 PST 2010


Author: stoklund
Date: Thu Dec 16 22:09:47 2010
New Revision: 122034

URL: http://llvm.org/viewvc/llvm-project?rev=122034&view=rev
Log:
Provide LiveIntervalUnion::Query::checkLoopInterference.

This is a three-way interval list intersection between a virtual register, a
live interval union, and a loop. It will be used to identify interference-free
loops for live range splitting.

Modified:
    llvm/trunk/include/llvm/ADT/IntervalMap.h
    llvm/trunk/include/llvm/CodeGen/MachineLoopRanges.h
    llvm/trunk/lib/CodeGen/LiveIntervalUnion.cpp
    llvm/trunk/lib/CodeGen/LiveIntervalUnion.h
    llvm/trunk/lib/CodeGen/MachineLoopRanges.cpp

Modified: llvm/trunk/include/llvm/ADT/IntervalMap.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ADT/IntervalMap.h?rev=122034&r1=122033&r2=122034&view=diff
==============================================================================
--- llvm/trunk/include/llvm/ADT/IntervalMap.h (original)
+++ llvm/trunk/include/llvm/ADT/IntervalMap.h Thu Dec 16 22:09:47 2010
@@ -940,6 +940,8 @@
 
 public:
   typedef typename Sizer::Allocator Allocator;
+  typedef KeyT KeyType;
+  typedef ValT ValueType;
   typedef Traits KeyTraits;
 
 private:
@@ -2025,6 +2027,7 @@
 ///
 template <typename MapA, typename MapB>
 class IntervalMapOverlaps {
+  typedef typename MapA::KeyType KeyType;
   typedef typename MapA::KeyTraits Traits;
   typename MapA::const_iterator posA;
   typename MapB::const_iterator posB;
@@ -2065,6 +2068,20 @@
   /// b - access the right hand side in the overlap.
   const typename MapB::const_iterator &b() const { return posB; }
 
+  /// start - Beginning of the overlapping interval.
+  KeyType start() const {
+    KeyType ak = a().start();
+    KeyType bk = b().start();
+    return Traits::startLess(ak, bk) ? bk : ak;
+  }
+
+  /// stop - End of the overlaping interval.
+  KeyType stop() const {
+    KeyType ak = a().stop();
+    KeyType bk = b().stop();
+    return Traits::startLess(ak, bk) ? ak : bk;
+  }
+
   /// skipA - Move to the next overlap that doesn't involve a().
   void skipA() {
     ++posA;
@@ -2094,8 +2111,15 @@
       skipA();
     return *this;
   }
-};
 
+  /// advanceTo - Move to the first overlapping interval with
+  /// stopLess(x, stop()).
+  void advanceTo(KeyType x) {
+    posA.advanceTo(x);
+    posB.advanceTo(x);
+    advance();
+  }
+};
 
 } // namespace llvm
 

Modified: llvm/trunk/include/llvm/CodeGen/MachineLoopRanges.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/MachineLoopRanges.h?rev=122034&r1=122033&r2=122034&view=diff
==============================================================================
--- llvm/trunk/include/llvm/CodeGen/MachineLoopRanges.h (original)
+++ llvm/trunk/include/llvm/CodeGen/MachineLoopRanges.h Thu Dec 16 22:09:47 2010
@@ -29,15 +29,18 @@
 /// MachineLoopRange - Range information for a single loop.
 class MachineLoopRange {
   friend class MachineLoopRanges;
-  typedef IntervalMap<SlotIndex, unsigned, 4> RangeMap;
-  typedef RangeMap::Allocator Allocator;
 
+public:
+  typedef IntervalMap<SlotIndex, unsigned, 4> Map;
+  typedef Map::Allocator Allocator;
+
+private:
   /// The mapped loop.
   const MachineLoop *const Loop;
 
   /// Map intervals to a bit mask.
   /// Bit 0 = inside loop block.
-  RangeMap Intervals;
+  Map Intervals;
 
   /// Create a MachineLoopRange, only accessible to MachineLoopRanges.
   MachineLoopRange(const MachineLoop*, Allocator&, SlotIndexes&);
@@ -47,6 +50,9 @@
   /// inteructions.
   bool overlaps(SlotIndex Start, SlotIndex Stop);
 
+  /// getMap - Allow public read-only access for IntervalMapOverlaps.
+  const Map &getMap() { return Intervals; }
+
   /// print - Print loop ranges on OS.
   void print(raw_ostream&) const;
 };

Modified: llvm/trunk/lib/CodeGen/LiveIntervalUnion.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/LiveIntervalUnion.cpp?rev=122034&r1=122033&r2=122034&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/LiveIntervalUnion.cpp (original)
+++ llvm/trunk/lib/CodeGen/LiveIntervalUnion.cpp Thu Dec 16 22:09:47 2010
@@ -16,6 +16,7 @@
 #define DEBUG_TYPE "regalloc"
 #include "LiveIntervalUnion.h"
 #include "llvm/ADT/SparseBitVector.h"
+#include "llvm/CodeGen/MachineLoopRanges.h"
 #include "llvm/Support/Debug.h"
 #include "llvm/Support/raw_ostream.h"
 #include "llvm/Target/TargetRegisterInfo.h"
@@ -284,3 +285,30 @@
   SeenAllInterferences = true;
   return InterferingVRegs.size();
 }
+
+bool LiveIntervalUnion::Query::checkLoopInterference(MachineLoopRange *Loop) {
+  // VirtReg is likely live throughout the loop, so start by checking LIU-Loop
+  // overlaps.
+  IntervalMapOverlaps<LiveIntervalUnion::Map, MachineLoopRange::Map>
+    Overlaps(LiveUnion->getMap(), Loop->getMap());
+  if (!Overlaps.valid())
+    return false;
+
+  // The loop is overlapping an LIU assignment. Check VirtReg as well.
+  LiveInterval::iterator VRI = VirtReg->find(Overlaps.start());
+
+  for (;;) {
+    if (VRI == VirtReg->end())
+      return false;
+    if (VRI->start < Overlaps.stop())
+      return true;
+
+    Overlaps.advanceTo(VRI->start);
+    if (!Overlaps.valid())
+      return false;
+    if (Overlaps.start() < VRI->end)
+      return true;
+
+    VRI = VirtReg->advanceTo(VRI, Overlaps.start());
+  }
+}

Modified: llvm/trunk/lib/CodeGen/LiveIntervalUnion.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/LiveIntervalUnion.h?rev=122034&r1=122033&r2=122034&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/LiveIntervalUnion.h (original)
+++ llvm/trunk/lib/CodeGen/LiveIntervalUnion.h Thu Dec 16 22:09:47 2010
@@ -24,6 +24,7 @@
 
 namespace llvm {
 
+class MachineLoopRange;
 class TargetRegisterInfo;
 
 #ifndef NDEBUG
@@ -76,6 +77,10 @@
   bool empty() const { return Segments.empty(); }
   SlotIndex startIndex() const { return Segments.start(); }
 
+  // Provide public access to the underlying map to allow overlap iteration.
+  typedef LiveSegments Map;
+  const Map &getMap() { return Segments; }
+
   // Add a live virtual register to this union and merge its segments.
   void unify(LiveInterval &VirtReg);
 
@@ -223,6 +228,10 @@
       return InterferingVRegs;
     }
 
+    /// checkLoopInterference - Return true if there is interference overlapping
+    /// Loop.
+    bool checkLoopInterference(MachineLoopRange*);
+
     void print(raw_ostream &OS, const TargetRegisterInfo *TRI);
   private:
     Query(const Query&);          // DO NOT IMPLEMENT

Modified: llvm/trunk/lib/CodeGen/MachineLoopRanges.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/MachineLoopRanges.cpp?rev=122034&r1=122033&r2=122034&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/MachineLoopRanges.cpp (original)
+++ llvm/trunk/lib/CodeGen/MachineLoopRanges.cpp Thu Dec 16 22:09:47 2010
@@ -69,13 +69,13 @@
 /// overlaps - Return true if this loop overlaps the given range of machine
 /// instructions.
 bool MachineLoopRange::overlaps(SlotIndex Start, SlotIndex Stop) {
-  RangeMap::const_iterator I = Intervals.find(Start);
+  Map::const_iterator I = Intervals.find(Start);
   return I.valid() && Stop > I.start();
 }
 
 void MachineLoopRange::print(raw_ostream &OS) const {
   OS << "Loop#" << Loop->getHeader()->getNumber() << " =";
-  for (RangeMap::const_iterator I = Intervals.begin(); I.valid(); ++I)
+  for (Map::const_iterator I = Intervals.begin(); I.valid(); ++I)
     OS << " [" << I.start() << ';' << I.stop() << ')';
 }
 





More information about the llvm-commits mailing list