[llvm] r190170 - avoid unnecessary direct access to LiveInterval::ranges

Matthias Braun matze at braunis.de
Fri Sep 6 09:44:32 PDT 2013


Author: matze
Date: Fri Sep  6 11:44:32 2013
New Revision: 190170

URL: http://llvm.org/viewvc/llvm-project?rev=190170&view=rev
Log:
avoid unnecessary direct access to LiveInterval::ranges

Modified:
    llvm/trunk/include/llvm/CodeGen/LiveInterval.h
    llvm/trunk/lib/CodeGen/LiveInterval.cpp
    llvm/trunk/lib/CodeGen/RegisterCoalescer.cpp
    llvm/trunk/lib/CodeGen/StrongPHIElimination.cpp

Modified: llvm/trunk/include/llvm/CodeGen/LiveInterval.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/LiveInterval.h?rev=190170&r1=190169&r2=190170&view=diff
==============================================================================
--- llvm/trunk/include/llvm/CodeGen/LiveInterval.h (original)
+++ llvm/trunk/include/llvm/CodeGen/LiveInterval.h Fri Sep  6 11:44:32 2013
@@ -194,6 +194,10 @@ namespace llvm {
       ranges.clear();
     }
 
+    size_t size() const {
+      return ranges.size();
+    }
+
     bool hasAtLeastOneValue() const { return !valnos.empty(); }
 
     bool containsOneValue() const { return valnos.size() == 1; }
@@ -439,9 +443,9 @@ namespace llvm {
 
   private:
 
-    Ranges::iterator addRangeFrom(LiveRange LR, Ranges::iterator From);
-    void extendIntervalEndTo(Ranges::iterator I, SlotIndex NewEnd);
-    Ranges::iterator extendIntervalStartTo(Ranges::iterator I, SlotIndex NewStr);
+    iterator addRangeFrom(LiveRange LR, iterator From);
+    void extendIntervalEndTo(iterator I, SlotIndex NewEnd);
+    iterator extendIntervalStartTo(iterator I, SlotIndex NewStr);
     void markValNoForDeletion(VNInfo *V);
 
     LiveInterval& operator=(const LiveInterval& rhs) LLVM_DELETED_FUNCTION;

Modified: llvm/trunk/lib/CodeGen/LiveInterval.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/LiveInterval.cpp?rev=190170&r1=190169&r2=190170&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/LiveInterval.cpp (original)
+++ llvm/trunk/lib/CodeGen/LiveInterval.cpp Fri Sep  6 11:44:32 2013
@@ -38,7 +38,7 @@ LiveInterval::iterator LiveInterval::fin
   if (empty() || Pos >= endIndex())
     return end();
   iterator I = begin();
-  size_t Len = ranges.size();
+  size_t Len = size();
   do {
     size_t Mid = Len >> 1;
     if (Pos < I[Mid].end)
@@ -108,13 +108,13 @@ bool LiveInterval::overlapsFrom(const Li
 
   if (i->start < j->start) {
     i = std::upper_bound(i, ie, j->start);
-    if (i != ranges.begin()) --i;
+    if (i != begin()) --i;
   } else if (j->start < i->start) {
     ++StartPos;
     if (StartPos != other.end() && StartPos->start <= i->start) {
       assert(StartPos < other.end() && i < end());
       j = std::upper_bound(j, je, i->start);
-      if (j != other.ranges.begin()) --j;
+      if (j != other.begin()) --j;
     }
   } else {
     return true;
@@ -219,13 +219,13 @@ void LiveInterval::RenumberValues() {
 /// specified by I to end at the specified endpoint.  To do this, we should
 /// merge and eliminate all ranges that this will overlap with.  The iterator is
 /// not invalidated.
-void LiveInterval::extendIntervalEndTo(Ranges::iterator I, SlotIndex NewEnd) {
-  assert(I != ranges.end() && "Not a valid interval!");
+void LiveInterval::extendIntervalEndTo(iterator I, SlotIndex NewEnd) {
+  assert(I != end() && "Not a valid interval!");
   VNInfo *ValNo = I->valno;
 
   // Search for the first interval that we can't merge with.
-  Ranges::iterator MergeTo = llvm::next(I);
-  for (; MergeTo != ranges.end() && NewEnd >= MergeTo->end; ++MergeTo) {
+  iterator MergeTo = llvm::next(I);
+  for (; MergeTo != end() && NewEnd >= MergeTo->end; ++MergeTo) {
     assert(MergeTo->valno == ValNo && "Cannot merge with differing values!");
   }
 
@@ -234,7 +234,7 @@ void LiveInterval::extendIntervalEndTo(R
 
   // If the newly formed range now touches the range after it and if they have
   // the same value number, merge the two ranges into one range.
-  if (MergeTo != ranges.end() && MergeTo->start <= I->end &&
+  if (MergeTo != end() && MergeTo->start <= I->end &&
       MergeTo->valno == ValNo) {
     I->end = MergeTo->end;
     ++MergeTo;
@@ -248,15 +248,15 @@ void LiveInterval::extendIntervalEndTo(R
 /// extendIntervalStartTo - This method is used when we want to extend the range
 /// specified by I to start at the specified endpoint.  To do this, we should
 /// merge and eliminate all ranges that this will overlap with.
-LiveInterval::Ranges::iterator
-LiveInterval::extendIntervalStartTo(Ranges::iterator I, SlotIndex NewStart) {
-  assert(I != ranges.end() && "Not a valid interval!");
+LiveInterval::iterator
+LiveInterval::extendIntervalStartTo(iterator I, SlotIndex NewStart) {
+  assert(I != end() && "Not a valid interval!");
   VNInfo *ValNo = I->valno;
 
   // Search for the first interval that we can't merge with.
-  Ranges::iterator MergeTo = I;
+  iterator MergeTo = I;
   do {
-    if (MergeTo == ranges.begin()) {
+    if (MergeTo == begin()) {
       I->start = NewStart;
       ranges.erase(MergeTo, I);
       return I;
@@ -283,11 +283,11 @@ LiveInterval::extendIntervalStartTo(Rang
 LiveInterval::iterator
 LiveInterval::addRangeFrom(LiveRange LR, iterator From) {
   SlotIndex Start = LR.start, End = LR.end;
-  iterator it = std::upper_bound(From, ranges.end(), Start);
+  iterator it = std::upper_bound(From, end(), Start);
 
   // If the inserted interval starts in the middle or right at the end of
   // another interval, just extend that interval to contain the range of LR.
-  if (it != ranges.begin()) {
+  if (it != begin()) {
     iterator B = prior(it);
     if (LR.valno == B->valno) {
       if (B->start <= Start && B->end >= Start) {
@@ -305,7 +305,7 @@ LiveInterval::addRangeFrom(LiveRange LR,
 
   // Otherwise, if this range ends in the middle of, or right next to, another
   // interval, merge it into that interval.
-  if (it != ranges.end()) {
+  if (it != end()) {
     if (LR.valno == it->valno) {
       if (it->start <= End) {
         it = extendIntervalStartTo(it, Start);
@@ -351,8 +351,8 @@ VNInfo *LiveInterval::extendInBlock(Slot
 void LiveInterval::removeRange(SlotIndex Start, SlotIndex End,
                                bool RemoveDeadValNo) {
   // Find the LiveRange containing this span.
-  Ranges::iterator I = find(Start);
-  assert(I != ranges.end() && "Range is not in interval!");
+  iterator I = find(Start);
+  assert(I != end() && "Range is not in interval!");
   assert(I->containsRange(Start, End) && "Range is not entirely in interval!");
 
   // If the span we are removing is at the start of the LiveRange, adjust it.
@@ -398,8 +398,8 @@ void LiveInterval::removeRange(SlotIndex
 /// Also remove the value# from value# list.
 void LiveInterval::removeValNo(VNInfo *ValNo) {
   if (empty()) return;
-  Ranges::iterator I = ranges.end();
-  Ranges::iterator E = ranges.begin();
+  iterator I = end();
+  iterator E = begin();
   do {
     --I;
     if (I->valno == ValNo)
@@ -597,8 +597,7 @@ void LiveInterval::print(raw_ostream &OS
   if (empty())
     OS << "EMPTY";
   else {
-    for (LiveInterval::Ranges::const_iterator I = ranges.begin(),
-           E = ranges.end(); I != E; ++I) {
+    for (const_iterator I = begin(), E = end(); I != E; ++I) {
       OS << *I;
       assert(I->valno == getValNumInfo(I->valno->id) && "Bad VNInfo");
     }
@@ -790,7 +789,7 @@ void LiveRangeUpdater::add(LiveRange Seg
   // Finally, append to LI or Spills.
   if (WriteI == E) {
     LI->ranges.push_back(Seg);
-    WriteI = ReadI = LI->ranges.end();
+    WriteI = ReadI = LI->end();
   } else
     Spills.push_back(Seg);
 }
@@ -842,7 +841,7 @@ void LiveRangeUpdater::flush() {
     size_t WritePos = WriteI - LI->begin();
     LI->ranges.insert(ReadI, Spills.size() - GapSize, LiveRange());
     // This also invalidated ReadI, but it is recomputed below.
-    WriteI = LI->ranges.begin() + WritePos;
+    WriteI = LI->begin() + WritePos;
   } else {
     // Shrink the gap if necessary.
     LI->ranges.erase(WriteI + Spills.size(), ReadI);

Modified: llvm/trunk/lib/CodeGen/RegisterCoalescer.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/RegisterCoalescer.cpp?rev=190170&r1=190169&r2=190170&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/RegisterCoalescer.cpp (original)
+++ llvm/trunk/lib/CodeGen/RegisterCoalescer.cpp Fri Sep  6 11:44:32 2013
@@ -527,11 +527,11 @@ bool RegisterCoalescer::hasOtherReaching
   for (LiveInterval::iterator AI = IntA.begin(), AE = IntA.end();
        AI != AE; ++AI) {
     if (AI->valno != AValNo) continue;
-    LiveInterval::Ranges::iterator BI =
-      std::upper_bound(IntB.ranges.begin(), IntB.ranges.end(), AI->start);
-    if (BI != IntB.ranges.begin())
+    LiveInterval::iterator BI =
+      std::upper_bound(IntB.begin(), IntB.end(), AI->start);
+    if (BI != IntB.begin())
       --BI;
-    for (; BI != IntB.ranges.end() && AI->end >= BI->start; ++BI) {
+    for (; BI != IntB.end() && AI->end >= BI->start; ++BI) {
       if (BI->valno == BValNo)
         continue;
       if (BI->start <= AI->start && BI->end > AI->start)
@@ -1089,8 +1089,8 @@ bool RegisterCoalescer::joinCopy(Machine
     });
 
     // When possible, let DstReg be the larger interval.
-    if (!CP.isPartial() && LIS->getInterval(CP.getSrcReg()).ranges.size() >
-                           LIS->getInterval(CP.getDstReg()).ranges.size())
+    if (!CP.isPartial() && LIS->getInterval(CP.getSrcReg()).size() >
+                           LIS->getInterval(CP.getDstReg()).size())
       CP.flip();
   }
 

Modified: llvm/trunk/lib/CodeGen/StrongPHIElimination.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/StrongPHIElimination.cpp?rev=190170&r1=190169&r2=190170&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/StrongPHIElimination.cpp (original)
+++ llvm/trunk/lib/CodeGen/StrongPHIElimination.cpp Fri Sep  6 11:44:32 2013
@@ -344,7 +344,7 @@ bool StrongPHIElimination::runOnMachineF
     LiveInterval &DestLI = LI->getInterval(DestReg);
     LiveInterval &NewLI = LI->getInterval(NewReg);
 
-    assert(DestLI.ranges.size() == 1
+    assert(DestLI.size() == 1
            && "PHI destination copy's live interval should be a single live "
                "range from the beginning of the BB to the copy instruction.");
     LiveRange *DestLR = DestLI.begin();





More information about the llvm-commits mailing list