[llvm] r359900 - [SelectionDAG] CreateTopologicalOrder - don't use iterator
Simon Pilgrim via llvm-commits
llvm-commits at lists.llvm.org
Fri May 3 08:50:37 PDT 2019
Author: rksimon
Date: Fri May 3 08:50:37 2019
New Revision: 359900
URL: http://llvm.org/viewvc/llvm-project?rev=359900&view=rev
Log:
[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
Modified:
llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
Modified: llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAG.cpp?rev=359900&r1=359899&r2=359900&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAG.cpp (original)
+++ llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAG.cpp Fri May 3 08:50:37 2019
@@ -8239,19 +8239,17 @@ void SelectionDAG::updateDivergence(SDNo
}
}
-
-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::CreateTopologicalOrde
}
#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
More information about the llvm-commits
mailing list