[SelectionDAG] CreateTopologicalOrder - don't use iterator

We shouldn't use an iterator to loop across a std::vector when the same loop is adding elements to that std::vector

Found by cppcheck

llvm-svn: 359900
This commit is contained in:
Simon Pilgrim 2019-05-03 15:50:37 +00:00
parent 657ef48a88
commit d857f64c31
1 changed files with 6 additions and 10 deletions

View File

@ -8239,19 +8239,17 @@ void SelectionDAG::updateDivergence(SDNode * N)
}
}
void SelectionDAG::CreateTopologicalOrder(std::vector<SDNode*>& Order) {
void SelectionDAG::CreateTopologicalOrder(std::vector<SDNode *> &Order) {
DenseMap<SDNode *, unsigned> Degree;
Order.reserve(AllNodes.size());
for (auto & N : allnodes()) {
for (auto &N : allnodes()) {
unsigned NOps = N.getNumOperands();
Degree[&N] = NOps;
if (0 == NOps)
Order.push_back(&N);
}
for (std::vector<SDNode *>::iterator I = Order.begin();
I!=Order.end();++I) {
SDNode * N = *I;
for (size_t I = 0; I != Order.size(); ++I) {
SDNode *N = Order[I];
for (auto U : N->uses()) {
unsigned &UnsortedOps = Degree[U];
if (0 == --UnsortedOps)
@ -8261,9 +8259,8 @@ void SelectionDAG::CreateTopologicalOrder(std::vector<SDNode*>& Order) {
}
#ifndef NDEBUG
void SelectionDAG::VerifyDAGDiverence()
{
std::vector<SDNode*> TopoOrder;
void SelectionDAG::VerifyDAGDiverence() {
std::vector<SDNode *> TopoOrder;
CreateTopologicalOrder(TopoOrder);
const TargetLowering &TLI = getTargetLoweringInfo();
DenseMap<const SDNode *, bool> DivergenceMap;
@ -8289,7 +8286,6 @@ void SelectionDAG::VerifyDAGDiverence()
}
#endif
/// ReplaceAllUsesOfValuesWith - Replace any uses of From with To, leaving
/// uses of other values produced by From.getNode() alone. The same value
/// may appear in both the From and To list. The Deleted vector is