RegisterPressure: Hide non-const iterators of PressureDiff
authorMatthias Braun <matze@braunis.de>
Sat, 17 Oct 2015 00:08:48 +0000 (00:08 +0000)
committerMatthias Braun <matze@braunis.de>
Sat, 17 Oct 2015 00:08:48 +0000 (00:08 +0000)
It is too easy to accidentally violate the ordering requirements when
modifying the PressureDiff entries through iterators.

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

include/llvm/CodeGen/RegisterPressure.h
lib/CodeGen/RegisterPressure.cpp

index c64087c5965ece45d623dbf83de75d3000054af2..dd549da02c61bf24cf90a08709b82278debadb51 100644 (file)
@@ -125,11 +125,13 @@ class PressureDiff {
   enum { MaxPSets = 16 };
 
   PressureChange PressureChanges[MaxPSets];
-public:
+
   typedef PressureChange* iterator;
+  iterator nonconst_begin() { return &PressureChanges[0]; }
+  iterator nonconst_end() { return &PressureChanges[MaxPSets]; }
+
+public:
   typedef const PressureChange* const_iterator;
-  iterator begin() { return &PressureChanges[0]; }
-  iterator end() { return &PressureChanges[MaxPSets]; }
   const_iterator begin() const { return &PressureChanges[0]; }
   const_iterator end() const { return &PressureChanges[MaxPSets]; }
 
index 87c3d46866e8274f26890f2769eed74547dcbd52..88566d88732abfa7d97eb08cbb79a35fae4cffff 100644 (file)
@@ -389,7 +389,7 @@ void PressureDiff::addPressureChange(unsigned RegUnit, bool IsDec,
   int Weight = IsDec ? -PSetI.getWeight() : PSetI.getWeight();
   for (; PSetI.isValid(); ++PSetI) {
     // Find an existing entry in the pressure diff for this PSet.
-    PressureDiff::iterator I = begin(), E = end();
+    PressureDiff::iterator I = nonconst_begin(), E = nonconst_end();
     for (; I != E && I->isValid(); ++I) {
       if (I->getPSet() >= *PSetI)
         break;