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

Unified Diff: src/IceCfg.cpp

Issue 2149803005: Subzero: Improve LoopAnalyzer Interface (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-subzero.git@master
Patch Set: Created 4 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 side-by-side diff with in-line comments
Download patch
Index: src/IceCfg.cpp
diff --git a/src/IceCfg.cpp b/src/IceCfg.cpp
index 3a5aa1e646528bcdce303de81a324ad367633c77..5fbd89829b251e540b132ebb3e164fcc0eb35475 100644
--- a/src/IceCfg.cpp
+++ b/src/IceCfg.cpp
@@ -643,41 +643,29 @@ void Cfg::localCSE() {
void Cfg::loopInvariantCodeMotion() {
TimerMarker T(TimerStack::TT_loopInvariantCodeMotion, this);
// Does not introduce new nodes as of now.
- for (auto &Pair : LoopInfo) {
- CfgNode *Header = Nodes[Pair.first];
+ Loops.forEachLoop([&](SizeT HeaderIndex, const CfgUnorderedSet<SizeT> &Body) {
John 2016/07/15 21:13:30 no default capture by ref. also, can you do somet
manasijm 2016/07/18 22:27:46 Done.
+ CfgNode *Header = Nodes[HeaderIndex];
assert(Header);
if (Header->getLoopNestDepth() < 1)
- continue;
- CfgNode *PreHeader = nullptr;
- for (auto *Pred : Header->getInEdges()) {
- if (Pred->getLoopNestDepth() == Header->getLoopNestDepth() - 1) {
- if (PreHeader == nullptr) {
- PreHeader = Pred;
- } else {
- PreHeader = nullptr;
- break;
- // Do not consider cases with two incoming edges.
- // Will require insertion of nodes.
- }
- }
- }
+ return;
+ CfgNode *PreHeader = Loops.getPreHeader(Header);
if (PreHeader == nullptr || PreHeader->getInsts().size() == 0) {
- continue; // to next loop
+ return; // try next loop
}
auto &Insts = PreHeader->getInsts();
auto &LastInst = Insts.back();
Insts.pop_back();
- for (auto *Inst : findLoopInvariantInstructions(Pair.first)) {
+ for (auto *Inst : findLoopInvariantInstructions(Body)) {
PreHeader->appendInst(Inst);
}
PreHeader->appendInst(&LastInst);
- }
+ });
}
-Ice::CfgVector<Inst *>
-Cfg::findLoopInvariantInstructions(Ice::SizeT LoopHeaderIndex) {
+CfgVector<Inst *>
+Cfg::findLoopInvariantInstructions(const CfgUnorderedSet<SizeT> &Body) {
CfgUnorderedSet<Inst *> InvariantInsts;
CfgUnorderedSet<Variable *> InvariantVars;
for (auto *Var : getArgs()) {
@@ -686,7 +674,7 @@ Cfg::findLoopInvariantInstructions(Ice::SizeT LoopHeaderIndex) {
bool Changed = false;
do {
Changed = false;
- for (auto NodeIndex : LoopInfo[LoopHeaderIndex]) {
+ for (auto NodeIndex : Body) {
auto *Node = Nodes[NodeIndex];
CfgVector<std::reference_wrapper<Inst>> Insts(Node->getInsts().begin(),
Node->getInsts().end());
@@ -1437,7 +1425,7 @@ void Cfg::genFrame() {
void Cfg::generateLoopInfo() {
TimerMarker T(TimerStack::TT_computeLoopNestDepth, this);
- LoopInfo = LoopAnalyzer(this).getLoopInfo();
+ Loops = LoopAnalyzer(this).getLoopInfo();
}
// This is a lightweight version of live-range-end calculation. Marks the last

Powered by Google App Engine
This is Rietveld 408576698