OLD | NEW |
1 //===- subzero/src/IceCfgNode.cpp - Basic block (node) implementation -----===// | 1 //===- subzero/src/IceCfgNode.cpp - Basic block (node) implementation -----===// |
2 // | 2 // |
3 // The Subzero Code Generator | 3 // The Subzero Code Generator |
4 // | 4 // |
5 // This file is distributed under the University of Illinois Open Source | 5 // This file is distributed under the University of Illinois Open Source |
6 // License. See LICENSE.TXT for details. | 6 // License. See LICENSE.TXT for details. |
7 // | 7 // |
8 //===----------------------------------------------------------------------===// | 8 //===----------------------------------------------------------------------===// |
9 // | 9 // |
10 // This file implements the CfgNode class, including the complexities | 10 // This file implements the CfgNode class, including the complexities |
(...skipping 732 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
743 i = LiveInAndOut.find_next(i)) { | 743 i = LiveInAndOut.find_next(i)) { |
744 Variable *Var = Liveness->getVariable(i, this); | 744 Variable *Var = Liveness->getVariable(i, this); |
745 Var->addLiveRange(FirstInstNum, LastInstNum + 1, 1); | 745 Var->addLiveRange(FirstInstNum, LastInstNum + 1, 1); |
746 } | 746 } |
747 } | 747 } |
748 | 748 |
749 // If this node contains only deleted instructions, and ends in an | 749 // If this node contains only deleted instructions, and ends in an |
750 // unconditional branch, contract the node by repointing all its | 750 // unconditional branch, contract the node by repointing all its |
751 // in-edges to its successor. | 751 // in-edges to its successor. |
752 void CfgNode::contractIfEmpty() { | 752 void CfgNode::contractIfEmpty() { |
753 if (InEdges.size() == 0) | 753 if (InEdges.empty()) |
754 return; | 754 return; |
755 Inst *Branch = NULL; | 755 Inst *Branch = NULL; |
756 for (Inst *I : Insts) { | 756 for (Inst *I : Insts) { |
757 if (I->isDeleted()) | 757 if (I->isDeleted()) |
758 continue; | 758 continue; |
759 if (I->isUnconditionalBranch()) | 759 if (I->isUnconditionalBranch()) |
760 Branch = I; | 760 Branch = I; |
761 else if (!I->isRedundantAssign()) | 761 else if (!I->isRedundantAssign()) |
762 return; | 762 return; |
763 } | 763 } |
764 Branch->setDeleted(); | 764 Branch->setDeleted(); |
765 assert(OutEdges.size() == 1); | 765 assert(OutEdges.size() == 1); |
766 // Repoint all this node's in-edges to this node's successor. | 766 // Repoint all this node's in-edges to this node's successor, unless |
767 for (CfgNode *Pred : InEdges) { | 767 // this node's successor is actually itself (in which case the |
768 for (auto I = Pred->OutEdges.begin(), E = Pred->OutEdges.end(); I != E; | 768 // statement "OutEdges.front()->InEdges.push_back(Pred)" could |
769 ++I) { | 769 // invalidate the iterator over this->InEdges). |
770 if (*I == this) { | 770 if (OutEdges.front() != this) { |
771 *I = OutEdges[0]; | 771 for (CfgNode *Pred : InEdges) { |
772 OutEdges[0]->InEdges.push_back(Pred); | 772 for (auto I = Pred->OutEdges.begin(), E = Pred->OutEdges.end(); I != E; |
| 773 ++I) { |
| 774 if (*I == this) { |
| 775 *I = OutEdges.front(); |
| 776 OutEdges.front()->InEdges.push_back(Pred); |
| 777 } |
773 } | 778 } |
774 } | 779 for (Inst *I : Pred->getInsts()) { |
775 for (Inst *I : Pred->getInsts()) { | 780 if (!I->isDeleted()) |
776 if (!I->isDeleted()) | 781 I->repointEdge(this, OutEdges.front()); |
777 I->repointEdge(this, OutEdges[0]); | 782 } |
778 } | 783 } |
779 } | 784 } |
780 InEdges.clear(); | 785 InEdges.clear(); |
781 // Don't bother removing the single out-edge, which would also | 786 // Don't bother removing the single out-edge, which would also |
782 // require finding the corresponding in-edge in the successor and | 787 // require finding the corresponding in-edge in the successor and |
783 // removing it. | 788 // removing it. |
784 } | 789 } |
785 | 790 |
786 void CfgNode::doBranchOpt(const CfgNode *NextNode) { | 791 void CfgNode::doBranchOpt(const CfgNode *NextNode) { |
787 TargetLowering *Target = Func->getTarget(); | 792 TargetLowering *Target = Func->getTarget(); |
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
992 if (!First) | 997 if (!First) |
993 Str << ", "; | 998 Str << ", "; |
994 First = false; | 999 First = false; |
995 Str << "%" << I->getName(); | 1000 Str << "%" << I->getName(); |
996 } | 1001 } |
997 Str << "\n"; | 1002 Str << "\n"; |
998 } | 1003 } |
999 } | 1004 } |
1000 | 1005 |
1001 } // end of namespace Ice | 1006 } // end of namespace Ice |
OLD | NEW |