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

Side by Side Diff: src/IceCfgNode.cpp

Issue 1246173003: Remove jumps over empty blocks. (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-subzero.git@master
Patch Set: Refactor to variable Created 5 years, 5 months 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 unified diff | Download patch
« no previous file with comments | « src/IceCfg.cpp ('k') | tests_lit/llvm2ice_tests/adv-switch-opt.ll » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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
OLDNEW
« no previous file with comments | « src/IceCfg.cpp ('k') | tests_lit/llvm2ice_tests/adv-switch-opt.ll » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698