[llvm] r272208 - [RegisterBankInfo] Avoid code duplication in OperandsMapper for the computation of the end of range.

Quentin Colombet via llvm-commits llvm-commits at lists.llvm.org
Wed Jun 8 14:55:27 PDT 2016


Author: qcolombet
Date: Wed Jun  8 16:55:26 2016
New Revision: 272208

URL: http://llvm.org/viewvc/llvm-project?rev=272208&view=rev
Log:
[RegisterBankInfo] Avoid code duplication in OperandsMapper for the computation of the end of range.

Refactor the code so that we do not compute in two different places the
end iterator for the range of new virtual registers for a given operand.
Although this refactoring was intended as NFC, this is not the case
because it actually fixes a bug where we were returning a range off by 1
(too long). Right now, this could not result in an actual bug because we
were accessing this range via the BreakDown size of the related operand.

Modified:
    llvm/trunk/include/llvm/CodeGen/GlobalISel/RegisterBankInfo.h
    llvm/trunk/lib/CodeGen/GlobalISel/RegisterBankInfo.cpp

Modified: llvm/trunk/include/llvm/CodeGen/GlobalISel/RegisterBankInfo.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/GlobalISel/RegisterBankInfo.h?rev=272208&r1=272207&r2=272208&view=diff
==============================================================================
--- llvm/trunk/include/llvm/CodeGen/GlobalISel/RegisterBankInfo.h (original)
+++ llvm/trunk/include/llvm/CodeGen/GlobalISel/RegisterBankInfo.h Wed Jun  8 16:55:26 2016
@@ -216,6 +216,14 @@ public:
     iterator_range<SmallVectorImpl<unsigned>::iterator>
     getVRegsMem(unsigned OpIdx);
 
+    /// Get the end iterator for a range starting at \p StartIdx and
+    /// spannig \p NumVal in NewVRegs.
+    /// \pre StartIdx + NumVal <= NewVRegs.size()
+    SmallVectorImpl<unsigned>::const_iterator
+    getNewVRegsEnd(unsigned StartIdx, unsigned NumVal) const;
+    SmallVectorImpl<unsigned>::iterator getNewVRegsEnd(unsigned StartIdx,
+                                                       unsigned NumVal);
+
   public:
     /// Create an OperandsMapper that will hold the information to apply \p
     /// InstrMapping to \p MI.

Modified: llvm/trunk/lib/CodeGen/GlobalISel/RegisterBankInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/GlobalISel/RegisterBankInfo.cpp?rev=272208&r1=272207&r2=272208&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/GlobalISel/RegisterBankInfo.cpp (original)
+++ llvm/trunk/lib/CodeGen/GlobalISel/RegisterBankInfo.cpp Wed Jun  8 16:55:26 2016
@@ -538,13 +538,26 @@ RegisterBankInfo::OperandsMapper::getVRe
       NewVRegs.push_back(0);
   }
   SmallVectorImpl<unsigned>::iterator End =
-      NewVRegs.size() <= StartIdx + NumPartialVal + 1
-          ? NewVRegs.end()
-          : &NewVRegs[StartIdx + NumPartialVal + 1];
+      getNewVRegsEnd(StartIdx, NumPartialVal);
 
   return make_range(&NewVRegs[StartIdx], End);
 }
 
+SmallVectorImpl<unsigned>::const_iterator
+RegisterBankInfo::OperandsMapper::getNewVRegsEnd(unsigned StartIdx,
+                                                 unsigned NumVal) const {
+  return const_cast<OperandsMapper *>(this)->getNewVRegsEnd(StartIdx, NumVal);
+}
+SmallVectorImpl<unsigned>::iterator
+RegisterBankInfo::OperandsMapper::getNewVRegsEnd(unsigned StartIdx,
+                                                 unsigned NumVal) {
+  assert((NewVRegs.size() == StartIdx + NumVal ||
+          NewVRegs.size() > StartIdx + NumVal) &&
+         "NewVRegs too small to contain all the partial mapping");
+  return NewVRegs.size() <= StartIdx + NumVal ? NewVRegs.end()
+                                              : &NewVRegs[StartIdx + NumVal];
+}
+
 void RegisterBankInfo::OperandsMapper::createVRegs(unsigned OpIdx) {
   assert(OpIdx < getMI().getNumOperands() && "Out-of-bound access");
   iterator_range<SmallVectorImpl<unsigned>::iterator> NewVRegsForOpIdx =
@@ -588,9 +601,7 @@ RegisterBankInfo::OperandsMapper::getVRe
   unsigned PartMapSize =
       getInstrMapping().getOperandMapping(OpIdx).BreakDown.size();
   SmallVectorImpl<unsigned>::const_iterator End =
-      NewVRegs.size() <= StartIdx + PartMapSize + 1
-          ? NewVRegs.end()
-          : &NewVRegs[StartIdx + PartMapSize + 1];
+      getNewVRegsEnd(StartIdx, PartMapSize);
   iterator_range<SmallVectorImpl<unsigned>::const_iterator> Res =
       make_range(&NewVRegs[StartIdx], End);
 #ifndef NDEBUG




More information about the llvm-commits mailing list