From 5ec0e9dcab9cfe0ccc3c7bcf0cd091fbbaeb4e84 Mon Sep 17 00:00:00 2001 From: Alina Sbirlea Date: Fri, 17 Aug 2018 17:39:15 +0000 Subject: [PATCH] [IDF] Teach Iterated Dominance Frontier to use a snapshot CFG based on a GraphDiff. Summary: Create the ability to compute IDF using a CFG View. For this, we'll need a new DT created using a list of Updates (to be refactored later to a GraphDiff), and the GraphTraits based on the same GraphDiff. Reviewers: kuhar, george.burgess.iv, mzolotukhin Subscribers: sanjoy, jlebar, llvm-commits Differential Revision: https://reviews.llvm.org/D50675 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@340052 91177308-0d34-0410-b5e6-96231b3b80d8 --- .../llvm/Analysis/IteratedDominanceFrontier.h | 26 ++++++++++++------- lib/Analysis/IteratedDominanceFrontier.cpp | 21 +++++++++++---- 2 files changed, 32 insertions(+), 15 deletions(-) diff --git a/include/llvm/Analysis/IteratedDominanceFrontier.h b/include/llvm/Analysis/IteratedDominanceFrontier.h index 6b195073324..6ae8d7e0da2 100644 --- a/include/llvm/Analysis/IteratedDominanceFrontier.h +++ b/include/llvm/Analysis/IteratedDominanceFrontier.h @@ -28,6 +28,7 @@ #include "llvm/ADT/SmallPtrSet.h" #include "llvm/ADT/SmallVector.h" #include "llvm/IR/BasicBlock.h" +#include "llvm/IR/CFGDiff.h" #include "llvm/IR/Dominators.h" namespace llvm { @@ -45,17 +46,21 @@ namespace llvm { template class IDFCalculator { public: - IDFCalculator(DominatorTreeBase &DT) - : DT(DT), useLiveIn(false) {} + IDFCalculator(DominatorTreeBase &DT) + : DT(DT), GD(nullptr), useLiveIn(false) {} - /// Give the IDF calculator the set of blocks in which the value is - /// defined. This is equivalent to the set of starting blocks it should be - /// calculating the IDF for (though later gets pruned based on liveness). - /// - /// Note: This set *must* live for the entire lifetime of the IDF calculator. - void setDefiningBlocks(const SmallPtrSetImpl &Blocks) { - DefBlocks = &Blocks; - } + IDFCalculator(DominatorTreeBase &DT, + GraphDiff *GD) + : DT(DT), GD(GD), useLiveIn(false) {} + + /// Give the IDF calculator the set of blocks in which the value is + /// defined. This is equivalent to the set of starting blocks it should be + /// calculating the IDF for (though later gets pruned based on liveness). + /// + /// Note: This set *must* live for the entire lifetime of the IDF calculator. + void setDefiningBlocks(const SmallPtrSetImpl &Blocks) { + DefBlocks = &Blocks; + } /// Give the IDF calculator the set of blocks in which the value is /// live on entry to the block. This is used to prune the IDF calculation to @@ -85,6 +90,7 @@ class IDFCalculator { private: DominatorTreeBase &DT; + GraphDiff *GD; bool useLiveIn; const SmallPtrSetImpl *LiveInBlocks; const SmallPtrSetImpl *DefBlocks; diff --git a/lib/Analysis/IteratedDominanceFrontier.cpp b/lib/Analysis/IteratedDominanceFrontier.cpp index e7751d32aab..000fe5ddad5 100644 --- a/lib/Analysis/IteratedDominanceFrontier.cpp +++ b/lib/Analysis/IteratedDominanceFrontier.cpp @@ -17,6 +17,7 @@ #include namespace llvm { + template void IDFCalculator::calculate( SmallVectorImpl &PHIBlocks) { @@ -61,29 +62,39 @@ void IDFCalculator::calculate( BasicBlock *BB = Node->getBlock(); // Succ is the successor in the direction we are calculating IDF, so it is // successor for IDF, and predecessor for Reverse IDF. - for (auto *Succ : children(BB)) { + auto DoWork = [&](BasicBlock *Succ) { DomTreeNode *SuccNode = DT.getNode(Succ); // Quickly skip all CFG edges that are also dominator tree edges instead // of catching them below. if (SuccNode->getIDom() == Node) - continue; + return; const unsigned SuccLevel = SuccNode->getLevel(); if (SuccLevel > RootLevel) - continue; + return; if (!VisitedPQ.insert(SuccNode).second) - continue; + return; BasicBlock *SuccBB = SuccNode->getBlock(); if (useLiveIn && !LiveInBlocks->count(SuccBB)) - continue; + return; PHIBlocks.emplace_back(SuccBB); if (!DefBlocks->count(SuccBB)) PQ.push(std::make_pair( SuccNode, std::make_pair(SuccLevel, SuccNode->getDFSNumIn()))); + }; + + if (GD) { + for (auto Pair : children< + std::pair *, NodeTy>>( + {GD, BB})) + DoWork(Pair.second); + } else { + for (auto *Succ : children(BB)) + DoWork(Succ); } for (auto DomChild : *Node) {