From fa187e0f3bb491d369c6cb4b964727ff3f306571 Mon Sep 17 00:00:00 2001 From: River Riddle Date: Thu, 6 Jun 2019 11:54:14 -0700 Subject: [PATCH] Support constructing DominanceInfo with an Operation. This computes the dominance information for any nested regions within the operation. PiperOrigin-RevId: 251896520 --- mlir/include/mlir/Analysis/Dominance.h | 5 ++++- mlir/lib/Analysis/Dominance.cpp | 20 +++++++++++++++++++- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/mlir/include/mlir/Analysis/Dominance.h b/mlir/include/mlir/Analysis/Dominance.h index f22def7..e69756e 100644 --- a/mlir/include/mlir/Analysis/Dominance.h +++ b/mlir/include/mlir/Analysis/Dominance.h @@ -27,6 +27,7 @@ extern template class llvm::DominatorTreeBase; namespace mlir { using DominanceInfoNode = llvm::DomTreeNodeBase; class Function; +class Operation; namespace detail { template class DominanceInfoBase { @@ -34,14 +35,16 @@ template class DominanceInfoBase { public: DominanceInfoBase(Function *function) { recalculate(function); } + DominanceInfoBase(Operation *op) { recalculate(op); } DominanceInfoBase(DominanceInfoBase &&) = default; DominanceInfoBase &operator=(DominanceInfoBase &&) = default; DominanceInfoBase(const DominanceInfoBase &) = delete; DominanceInfoBase &operator=(const DominanceInfoBase &) = delete; - /// Recalculate the dominance info for the provided function. + /// Recalculate the dominance info. void recalculate(Function *function); + void recalculate(Operation *op); /// Get the root dominance node of the given region. DominanceInfoNode *getRootNode(Region *region) { diff --git a/mlir/lib/Analysis/Dominance.cpp b/mlir/lib/Analysis/Dominance.cpp index d914f36..2c9ec00 100644 --- a/mlir/lib/Analysis/Dominance.cpp +++ b/mlir/lib/Analysis/Dominance.cpp @@ -23,6 +23,7 @@ #include "mlir/Analysis/Dominance.h" #include "mlir/IR/Operation.h" #include "llvm/Support/GenericDomTreeConstruction.h" + using namespace mlir; using namespace mlir::detail; @@ -34,7 +35,7 @@ template class llvm::DomTreeNodeBase; // DominanceInfoBase //===----------------------------------------------------------------------===// -/// Recalculate the dominance info for the provided function. +/// Recalculate the dominance info. template void DominanceInfoBase::recalculate(Function *function) { dominanceInfos.clear(); @@ -58,6 +59,23 @@ void DominanceInfoBase::recalculate(Function *function) { }); } +template +void DominanceInfoBase::recalculate(Operation *op) { + dominanceInfos.clear(); + + /// Build the dominance for each of the operation regions. + op->walk([&](Operation *op) { + for (auto ®ion : op->getRegions()) { + // Don't compute dominance if the region is empty. + if (region.empty()) + continue; + auto opDominance = llvm::make_unique(); + opDominance->recalculate(region); + dominanceInfos.try_emplace(®ion, std::move(opDominance)); + } + }); +} + /// Return true if the specified block A properly dominates block B. template bool DominanceInfoBase::properlyDominates(Block *a, Block *b) { -- 2.7.4