Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(923)

Unified Diff: src/IceCfgNode.cpp

Issue 704753007: Subzero: Improve the use of NodeList objects. (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-subzero.git@master
Patch Set: Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: src/IceCfgNode.cpp
diff --git a/src/IceCfgNode.cpp b/src/IceCfgNode.cpp
index 494ab4bf4f1d28e5cffca9a7f7d02325e0c895a8..52789b94cdc3f85426ca83822d57436979401613 100644
--- a/src/IceCfgNode.cpp
+++ b/src/IceCfgNode.cpp
@@ -750,7 +750,7 @@ void CfgNode::livenessPostprocess(LivenessMode Mode, Liveness *Liveness) {
// unconditional branch, contract the node by repointing all its
// in-edges to its successor.
void CfgNode::contractIfEmpty() {
- if (InEdges.size() == 0)
+ if (InEdges.empty())
return;
Inst *Branch = NULL;
for (Inst *I : Insts) {
@@ -763,18 +763,23 @@ void CfgNode::contractIfEmpty() {
}
Branch->setDeleted();
assert(OutEdges.size() == 1);
- // Repoint all this node's in-edges to this node's successor.
- for (CfgNode *Pred : InEdges) {
- for (auto I = Pred->OutEdges.begin(), E = Pred->OutEdges.end(); I != E;
- ++I) {
- if (*I == this) {
- *I = OutEdges[0];
- OutEdges[0]->InEdges.push_back(Pred);
+ // Repoint all this node's in-edges to this node's successor, unless
+ // this node's successor is actually itself (in which case the
+ // statement "OutEdges.front()->InEdges.push_back(Pred)" could
+ // invalidate the iterator over this->InEdges).
+ if (OutEdges.front() != this) {
+ for (CfgNode *Pred : InEdges) {
+ for (auto I = Pred->OutEdges.begin(), E = Pred->OutEdges.end(); I != E;
+ ++I) {
+ if (*I == this) {
+ *I = OutEdges.front();
+ OutEdges.front()->InEdges.push_back(Pred);
+ }
+ }
+ for (Inst *I : Pred->getInsts()) {
+ if (!I->isDeleted())
+ I->repointEdge(this, OutEdges.front());
}
- }
- for (Inst *I : Pred->getInsts()) {
- if (!I->isDeleted())
- I->repointEdge(this, OutEdges[0]);
}
}
InEdges.clear();
« src/IceCfg.cpp ('K') | « src/IceCfg.cpp ('k') | src/IceTargetLoweringX8632.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698