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

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: Warning in comment. 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 711 matching lines...) Expand 10 before | Expand all | Expand 10 after
722 Inst *Branch = nullptr; 722 Inst *Branch = nullptr;
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);
jvoung (off chromium) 2015/07/23 00:01:23 Might be cleaner to "cache" OutEdges.front() as "S
ascull 2015/07/23 00:11:20 Done.
733 // Repoint all this node's in-edges to this node's successor, unless 733 // 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 734 // this node's successor is actually itself (in which case the
735 // statement "OutEdges.front()->InEdges.push_back(Pred)" could 735 // statement "OutEdges.front()->InEdges.push_back(Pred)" could
736 // invalidate the iterator over this->InEdges). 736 // invalidate the iterator over this->InEdges).
737 if (OutEdges.front() != this) { 737 if (OutEdges.front() != this) {
738 for (CfgNode *Pred : InEdges) { 738 for (CfgNode *Pred : InEdges) {
739 for (auto I = Pred->OutEdges.begin(), E = Pred->OutEdges.end(); I != E; 739 for (CfgNode *&I : Pred->OutEdges) {
740 ++I) { 740 if (I == this) {
741 if (*I == this) { 741 I = OutEdges.front();
742 *I = OutEdges.front();
743 OutEdges.front()->InEdges.push_back(Pred); 742 OutEdges.front()->InEdges.push_back(Pred);
744 } 743 }
745 } 744 }
746 for (Inst &I : Pred->getInsts()) { 745 for (Inst &I : Pred->getInsts()) {
747 if (!I.isDeleted()) 746 if (!I.isDeleted())
748 I.repointEdges(this, OutEdges.front()); 747 I.repointEdges(this, OutEdges.front());
749 } 748 }
750 } 749 }
750
751 // Remove the in-edge to the successor to allow node reordering to make
752 // better decisions. For example it's more helpful to place a node after
753 // a reachable predecessor than an unreachable one (like the one we just
754 // contracted).
755 const auto SuccInEdgesBegin = OutEdges.front()->InEdges.begin();
756 const auto SuccInEdgesEnd = OutEdges.front()->InEdges.end();
757 OutEdges.front()->InEdges.erase(
758 std::find(SuccInEdgesBegin, SuccInEdgesEnd, this));
751 } 759 }
752 InEdges.clear(); 760 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 } 761 }
757 762
758 void CfgNode::doBranchOpt(const CfgNode *NextNode) { 763 void CfgNode::doBranchOpt(const CfgNode *NextNode) {
759 TargetLowering *Target = Func->getTarget(); 764 TargetLowering *Target = Func->getTarget();
760 // Check every instruction for a branch optimization opportunity. 765 // 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 766 // instruction in the block) and stop. This is sufficient unless there is some
762 // first opportunity, unless there is some target lowering where we 767 // target lowering where we have the possibility of multiple optimizations per
763 // have the possibility of multiple such optimizations per block 768 // block. Take case with switch lowering as there are multiple unconditional
jvoung (off chromium) 2015/07/23 00:01:23 What do you mean by "Take case with switch lowerin
ascull 2015/07/23 00:11:19 I mean 'take care'. Too much switching!
764 // (currently not the case for x86 lowering). 769 // branches and only the last can be deleted.
765 for (Inst &I : Insts) { 770 for (Inst &I : reverse_range(Insts)) {
766 if (!I.isDeleted()) { 771 if (!I.isDeleted()) {
767 Target->doBranchOpt(&I, NextNode); 772 Target->doBranchOpt(&I, NextNode);
773 return;
768 } 774 }
769 } 775 }
770 } 776 }
771 777
772 // ======================== Dump routines ======================== // 778 // ======================== Dump routines ======================== //
773 779
774 namespace { 780 namespace {
775 781
776 // Helper functions for emit(). 782 // Helper functions for emit().
777 783
(...skipping 483 matching lines...) Expand 10 before | Expand all | Expand 10 after
1261 InstIntrinsicCall *Inst = InstIntrinsicCall::create( 1267 InstIntrinsicCall *Inst = InstIntrinsicCall::create(
1262 Func, 5, Func->makeVariable(IceType_i64), RMWI64Name, Info->Info); 1268 Func, 5, Func->makeVariable(IceType_i64), RMWI64Name, Info->Info);
1263 Inst->addArg(AtomicRMWOp); 1269 Inst->addArg(AtomicRMWOp);
1264 Inst->addArg(Counter); 1270 Inst->addArg(Counter);
1265 Inst->addArg(One); 1271 Inst->addArg(One);
1266 Inst->addArg(OrderAcquireRelease); 1272 Inst->addArg(OrderAcquireRelease);
1267 Insts.push_front(Inst); 1273 Insts.push_front(Inst);
1268 } 1274 }
1269 1275
1270 } // end of namespace Ice 1276 } // 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