Index: llvm/trunk/include/llvm/IR/Dominators.h =================================================================== --- llvm/trunk/include/llvm/IR/Dominators.h +++ llvm/trunk/include/llvm/IR/Dominators.h @@ -46,6 +46,9 @@ using BBUpdates = ArrayRef>; extern template void Calculate(BBDomTree &DT); +extern template void CalculateWithUpdates(BBDomTree &DT, + BBUpdates U); + extern template void Calculate(BBPostDomTree &DT); extern template void InsertEdge(BBDomTree &DT, BasicBlock *From, @@ -145,6 +148,9 @@ DominatorTree() = default; explicit DominatorTree(Function &F) { recalculate(F); } + explicit DominatorTree(DominatorTree &DT, DomTreeBuilder::BBUpdates U) { + recalculate(*DT.Parent, U); + } /// Handle invalidation explicitly. bool invalidate(Function &F, const PreservedAnalyses &PA, Index: llvm/trunk/include/llvm/Support/GenericDomTree.h =================================================================== --- llvm/trunk/include/llvm/Support/GenericDomTree.h +++ llvm/trunk/include/llvm/Support/GenericDomTree.h @@ -193,6 +193,10 @@ void Calculate(DomTreeT &DT); template +void CalculateWithUpdates(DomTreeT &DT, + ArrayRef Updates); + +template void InsertEdge(DomTreeT &DT, typename DomTreeT::NodePtr From, typename DomTreeT::NodePtr To); @@ -730,6 +734,11 @@ DomTreeBuilder::Calculate(*this); } + void recalculate(ParentType &Func, ArrayRef Updates) { + Parent = &Func; + DomTreeBuilder::CalculateWithUpdates(*this, Updates); + } + /// verify - checks if the tree is correct. There are 3 level of verification: /// - Full -- verifies if the tree is correct by making sure all the /// properties (including the parent and the sibling property) Index: llvm/trunk/include/llvm/Support/GenericDomTreeConstruction.h =================================================================== --- llvm/trunk/include/llvm/Support/GenericDomTreeConstruction.h +++ llvm/trunk/include/llvm/Support/GenericDomTreeConstruction.h @@ -1576,6 +1576,25 @@ SemiNCAInfo::CalculateFromScratch(DT, nullptr); } +template +void CalculateWithUpdates(DomTreeT &DT, + ArrayRef Updates) { + // TODO: Move BUI creation in common method, reuse in ApplyUpdates. + typename SemiNCAInfo::BatchUpdateInfo BUI; + LLVM_DEBUG(dbgs() << "Legalizing " << BUI.Updates.size() << " updates\n"); + cfg::LegalizeUpdates(Updates, BUI.Updates, + DomTreeT::IsPostDominator); + const size_t NumLegalized = BUI.Updates.size(); + BUI.FutureSuccessors.reserve(NumLegalized); + BUI.FuturePredecessors.reserve(NumLegalized); + for (auto &U : BUI.Updates) { + BUI.FutureSuccessors[U.getFrom()].push_back({U.getTo(), U.getKind()}); + BUI.FuturePredecessors[U.getTo()].push_back({U.getFrom(), U.getKind()}); + } + + SemiNCAInfo::CalculateFromScratch(DT, &BUI); +} + template void InsertEdge(DomTreeT &DT, typename DomTreeT::NodePtr From, typename DomTreeT::NodePtr To) { Index: llvm/trunk/lib/IR/Dominators.cpp =================================================================== --- llvm/trunk/lib/IR/Dominators.cpp +++ llvm/trunk/lib/IR/Dominators.cpp @@ -71,8 +71,13 @@ template void llvm::DomTreeBuilder::Calculate( DomTreeBuilder::BBDomTree &DT); +template void +llvm::DomTreeBuilder::CalculateWithUpdates( + DomTreeBuilder::BBDomTree &DT, BBUpdates U); + template void llvm::DomTreeBuilder::Calculate( DomTreeBuilder::BBPostDomTree &DT); +// No CalculateWithUpdates instantiation, unless a usecase arises. template void llvm::DomTreeBuilder::InsertEdge( DomTreeBuilder::BBDomTree &DT, BasicBlock *From, BasicBlock *To);