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
unsigned getNumRegs() const;
const Type *getType() const;
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;
bool referencesReg(const SCEV *S) const;
bool hasRegsUsedByUsesOtherThan(size_t LUIdx,
const RegUseTracker &RegUses) const;
+/// 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 ||
/// referencesReg - Test if this formula references the given register.
bool Formula::referencesReg(const SCEV *S) const {
return S == ScaledReg ||
/// DeleteFormula - Remove the given formula from this use's list.
void LSRUse::DeleteFormula(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!");
}
Formulae.pop_back();
assert(!Formulae.empty() && "LSRUse has no formulae left!");
}
LSRUse::KindType Kind,
const Type *AccessTy);
LSRUse::KindType Kind,
const Type *AccessTy);
+ void DeleteUse(LSRUse &LU);
+
LSRUse *FindUseWithSimilarFormula(const Formula &F, const LSRUse &OrigLU);
public:
LSRUse *FindUseWithSimilarFormula(const Formula &F, const LSRUse &OrigLU);
public:
return std::make_pair(LUIdx, Offset);
}
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 *
/// FindUseWithFormula - Look for a use distinct from OrigLU which is has
/// a formula that has the same registers as the given formula.
LSRUse *
// TODO: This could be optimized to avoid all the copying.
Formula F = Base;
F.ScaledReg = Quotient;
// 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);
}
}
(void)InsertFormula(LU, LUIdx, F);
}
}
- std::swap(LU, Uses.back());
- Uses.pop_back();
--LUIdx;
--NumUses;
break;
--LUIdx;
--NumUses;
break;