From 96e411b90c5896119e3479b25dba939e799773d9 Mon Sep 17 00:00:00 2001 From: Matthias Braun Date: Sat, 17 Oct 2015 00:08:48 +0000 Subject: [PATCH] RegisterPressure: Hide non-const iterators of PressureDiff It is too easy to accidentally violate the ordering requirements when modifying the PressureDiff entries through iterators. llvm-svn: 250590 --- llvm/include/llvm/CodeGen/RegisterPressure.h | 8 +++++--- llvm/lib/CodeGen/RegisterPressure.cpp | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/llvm/include/llvm/CodeGen/RegisterPressure.h b/llvm/include/llvm/CodeGen/RegisterPressure.h index c64087c5965e..dd549da02c61 100644 --- a/llvm/include/llvm/CodeGen/RegisterPressure.h +++ b/llvm/include/llvm/CodeGen/RegisterPressure.h @@ -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]; } diff --git a/llvm/lib/CodeGen/RegisterPressure.cpp b/llvm/lib/CodeGen/RegisterPressure.cpp index 87c3d46866e8..88566d88732a 100644 --- a/llvm/lib/CodeGen/RegisterPressure.cpp +++ b/llvm/lib/CodeGen/RegisterPressure.cpp @@ -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;