diff options
| author | Dan Gohman <gohman@apple.com> | 2010-05-20 15:17:54 +0000 |
|---|---|---|
| committer | Dan Gohman <gohman@apple.com> | 2010-05-20 15:17:54 +0000 |
| commit | 71f3a4e026ef8cca9d8916eb979595eed62dacb0 (patch) | |
| tree | 0c834039bfc4339ff7731083a1df52572a9714f1 /lib | |
| parent | 39d40dc59fa4920a5c845b9bd6aca04621ba9c12 (diff) | |
| download | external_llvm-71f3a4e026ef8cca9d8916eb979595eed62dacb0.zip external_llvm-71f3a4e026ef8cca9d8916eb979595eed62dacb0.tar.gz external_llvm-71f3a4e026ef8cca9d8916eb979595eed62dacb0.tar.bz2 | |
Move the code for deleting BaseRegs and LSRUses into helper functions,
and fix a bug that valgrind noticed where the code would std::swap an
element with itself.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@104225 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/Transforms/Scalar/LoopStrengthReduce.cpp | 27 |
1 files changed, 22 insertions, 5 deletions
diff --git a/lib/Transforms/Scalar/LoopStrengthReduce.cpp b/lib/Transforms/Scalar/LoopStrengthReduce.cpp index 43c1d06..bca5e4f 100644 --- a/lib/Transforms/Scalar/LoopStrengthReduce.cpp +++ b/lib/Transforms/Scalar/LoopStrengthReduce.cpp @@ -207,6 +207,8 @@ struct Formula { unsigned getNumRegs() const; const Type *getType() const; + void DeleteBaseReg(const SCEV *&S); + bool referencesReg(const SCEV *S) const; bool hasRegsUsedByUsesOtherThan(size_t LUIdx, const RegUseTracker &RegUses) const; @@ -310,6 +312,13 @@ const Type *Formula::getType() const { 0; } +/// DeleteBaseReg - Delete the given base reg from the BaseRegs list. +void Formula::DeleteBaseReg(const SCEV *&S) { + if (&S != &BaseRegs.back()) + std::swap(S, BaseRegs.back()); + BaseRegs.pop_back(); +} + /// referencesReg - Test if this formula references the given register. bool Formula::referencesReg(const SCEV *S) const { return S == ScaledReg || @@ -1013,7 +1022,8 @@ bool LSRUse::InsertFormula(const Formula &F) { /// DeleteFormula - Remove the given formula from this use's list. void LSRUse::DeleteFormula(Formula &F) { - std::swap(F, Formulae.back()); + if (&F != &Formulae.back()) + std::swap(F, Formulae.back()); Formulae.pop_back(); assert(!Formulae.empty() && "LSRUse has no formulae left!"); } @@ -1279,6 +1289,8 @@ class LSRInstance { LSRUse::KindType Kind, const Type *AccessTy); + void DeleteUse(LSRUse &LU); + LSRUse *FindUseWithSimilarFormula(const Formula &F, const LSRUse &OrigLU); public: @@ -1851,6 +1863,13 @@ LSRInstance::getUse(const SCEV *&Expr, return std::make_pair(LUIdx, Offset); } +/// DeleteUse - Delete the given use from the Uses list. +void LSRInstance::DeleteUse(LSRUse &LU) { + if (&LU != &Uses.back()) + std::swap(LU, Uses.back()); + Uses.pop_back(); +} + /// FindUseWithFormula - Look for a use distinct from OrigLU which is has /// a formula that has the same registers as the given formula. LSRUse * @@ -2423,8 +2442,7 @@ void LSRInstance::GenerateScales(LSRUse &LU, unsigned LUIdx, // TODO: This could be optimized to avoid all the copying. Formula F = Base; F.ScaledReg = Quotient; - std::swap(F.BaseRegs[i], F.BaseRegs.back()); - F.BaseRegs.pop_back(); + F.DeleteBaseReg(F.BaseRegs[i]); (void)InsertFormula(LU, LUIdx, F); } } @@ -2895,8 +2913,7 @@ void LSRInstance::NarrowSearchSpaceUsingHeuristics() { } // Delete the old use. - std::swap(LU, Uses.back()); - Uses.pop_back(); + DeleteUse(LU); --LUIdx; --NumUses; break; |
