| 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 /// \file | 10 /// \file |
| (...skipping 712 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 723 for (Inst &I : Insts) { | 723 for (Inst &I : Insts) { |
| 724 if (I.isDeleted()) | 724 if (I.isDeleted()) |
| 725 continue; | 725 continue; |
| 726 if (I.isUnconditionalBranch()) | 726 if (I.isUnconditionalBranch()) |
| 727 Branch = &I; | 727 Branch = &I; |
| 728 else if (!I.isRedundantAssign()) | 728 else if (!I.isRedundantAssign()) |
| 729 return; | 729 return; |
| 730 } | 730 } |
| 731 Branch->setDeleted(); | 731 Branch->setDeleted(); |
| 732 assert(OutEdges.size() == 1); | 732 assert(OutEdges.size() == 1); |
| 733 CfgNode *Successor = OutEdges.front(); |
| 733 // Repoint all this node's in-edges to this node's successor, unless | 734 // Repoint all this node's in-edges to this node's successor, unless |
| 734 // this node's successor is actually itself (in which case the | 735 // this node's successor is actually itself (in which case the |
| 735 // statement "OutEdges.front()->InEdges.push_back(Pred)" could | 736 // statement "OutEdges.front()->InEdges.push_back(Pred)" could |
| 736 // invalidate the iterator over this->InEdges). | 737 // invalidate the iterator over this->InEdges). |
| 737 if (OutEdges.front() != this) { | 738 if (Successor != this) { |
| 738 for (CfgNode *Pred : InEdges) { | 739 for (CfgNode *Pred : InEdges) { |
| 739 for (auto I = Pred->OutEdges.begin(), E = Pred->OutEdges.end(); I != E; | 740 for (CfgNode *&I : Pred->OutEdges) { |
| 740 ++I) { | 741 if (I == this) { |
| 741 if (*I == this) { | 742 I = Successor; |
| 742 *I = OutEdges.front(); | 743 Successor->InEdges.push_back(Pred); |
| 743 OutEdges.front()->InEdges.push_back(Pred); | |
| 744 } | 744 } |
| 745 } | 745 } |
| 746 for (Inst &I : Pred->getInsts()) { | 746 for (Inst &I : Pred->getInsts()) { |
| 747 if (!I.isDeleted()) | 747 if (!I.isDeleted()) |
| 748 I.repointEdges(this, OutEdges.front()); | 748 I.repointEdges(this, Successor); |
| 749 } | 749 } |
| 750 } | 750 } |
| 751 |
| 752 // Remove the in-edge to the successor to allow node reordering to make |
| 753 // better decisions. For example it's more helpful to place a node after |
| 754 // a reachable predecessor than an unreachable one (like the one we just |
| 755 // contracted). |
| 756 Successor->InEdges.erase( |
| 757 std::find(Successor->InEdges.begin(), Successor->InEdges.end(), this)); |
| 751 } | 758 } |
| 752 InEdges.clear(); | 759 InEdges.clear(); |
| 753 // Don't bother removing the single out-edge, which would also | |
| 754 // require finding the corresponding in-edge in the successor and | |
| 755 // removing it. | |
| 756 } | 760 } |
| 757 | 761 |
| 758 void CfgNode::doBranchOpt(const CfgNode *NextNode) { | 762 void CfgNode::doBranchOpt(const CfgNode *NextNode) { |
| 759 TargetLowering *Target = Func->getTarget(); | 763 TargetLowering *Target = Func->getTarget(); |
| 760 // Check every instruction for a branch optimization opportunity. | 764 // Find the first opportunity for branch optimization (which will be the last |
| 761 // It may be more efficient to iterate in reverse and stop after the | 765 // instruction in the block) and stop. This is sufficient unless there is some |
| 762 // first opportunity, unless there is some target lowering where we | 766 // target lowering where we have the possibility of multiple optimizations per |
| 763 // have the possibility of multiple such optimizations per block | 767 // block. Take care with switch lowering as there are multiple unconditional |
| 764 // (currently not the case for x86 lowering). | 768 // branches and only the last can be deleted. |
| 765 for (Inst &I : Insts) { | 769 for (Inst &I : reverse_range(Insts)) { |
| 766 if (!I.isDeleted()) { | 770 if (!I.isDeleted()) { |
| 767 Target->doBranchOpt(&I, NextNode); | 771 Target->doBranchOpt(&I, NextNode); |
| 772 return; |
| 768 } | 773 } |
| 769 } | 774 } |
| 770 } | 775 } |
| 771 | 776 |
| 772 // ======================== Dump routines ======================== // | 777 // ======================== Dump routines ======================== // |
| 773 | 778 |
| 774 namespace { | 779 namespace { |
| 775 | 780 |
| 776 // Helper functions for emit(). | 781 // Helper functions for emit(). |
| 777 | 782 |
| (...skipping 483 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1261 InstIntrinsicCall *Inst = InstIntrinsicCall::create( | 1266 InstIntrinsicCall *Inst = InstIntrinsicCall::create( |
| 1262 Func, 5, Func->makeVariable(IceType_i64), RMWI64Name, Info->Info); | 1267 Func, 5, Func->makeVariable(IceType_i64), RMWI64Name, Info->Info); |
| 1263 Inst->addArg(AtomicRMWOp); | 1268 Inst->addArg(AtomicRMWOp); |
| 1264 Inst->addArg(Counter); | 1269 Inst->addArg(Counter); |
| 1265 Inst->addArg(One); | 1270 Inst->addArg(One); |
| 1266 Inst->addArg(OrderAcquireRelease); | 1271 Inst->addArg(OrderAcquireRelease); |
| 1267 Insts.push_front(Inst); | 1272 Insts.push_front(Inst); |
| 1268 } | 1273 } |
| 1269 | 1274 |
| 1270 } // end of namespace Ice | 1275 } // end of namespace Ice |
| OLD | NEW |