//===- Dominance.cpp - Dominator analysis for CFGs ------------------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // // Implementation of dominance related classes and instantiations of extern // templates. // //===----------------------------------------------------------------------===// #include "mlir/IR/Dominance.h" #include "mlir/IR/Operation.h" #include "mlir/IR/RegionKindInterface.h" #include "llvm/ADT/DenseMap.h" #include "llvm/Support/GenericDomTreeConstruction.h" usingnamespacemlir; usingnamespacemlir::detail; template class llvm::DominatorTreeBase<Block, /*IsPostDom=*/false>; template class llvm::DominatorTreeBase<Block, /*IsPostDom=*/true>; template class llvm::DomTreeNodeBase<Block>; //===----------------------------------------------------------------------===// // DominanceInfoBase //===----------------------------------------------------------------------===// template <bool IsPostDom> DominanceInfoBase<IsPostDom>::~DominanceInfoBase() { … } template <bool IsPostDom> void DominanceInfoBase<IsPostDom>::invalidate() { … } template <bool IsPostDom> void DominanceInfoBase<IsPostDom>::invalidate(Region *region) { … } /// Return the dom tree and "hasSSADominance" bit for the given region. The /// DomTree will be null for single-block regions. This lazily constructs the /// DomTree on demand when needsDomTree=true. template <bool IsPostDom> auto DominanceInfoBase<IsPostDom>::getDominanceInfo(Region *region, bool needsDomTree) const -> llvm::PointerIntPair<DomTree *, 1, bool> { … } /// Return the ancestor block enclosing the specified block. This returns null /// if we reach the top of the hierarchy. static Block *getAncestorBlock(Block *block) { … } /// Walks up the list of containers of the given block and calls the /// user-defined traversal function for every pair of a region and block that /// could be found during traversal. If the user-defined function returns true /// for a given pair, traverseAncestors will return the current block. Nullptr /// otherwise. template <typename FuncT> static Block *traverseAncestors(Block *block, const FuncT &func) { … } /// Tries to update the given block references to live in the same region by /// exploring the relationship of both blocks with respect to their regions. static bool tryGetBlocksInSameRegion(Block *&a, Block *&b) { … } template <bool IsPostDom> Block * DominanceInfoBase<IsPostDom>::findNearestCommonDominator(Block *a, Block *b) const { … } /// Return true if the specified block A properly dominates block B. template <bool IsPostDom> bool DominanceInfoBase<IsPostDom>::properlyDominates(Block *a, Block *b) const { … } /// Return true if the specified block is reachable from the entry block of /// its region. template <bool IsPostDom> bool DominanceInfoBase<IsPostDom>::isReachableFromEntry(Block *a) const { … } template class detail::DominanceInfoBase</*IsPostDom=*/true>; template class detail::DominanceInfoBase</*IsPostDom=*/false>; //===----------------------------------------------------------------------===// // DominanceInfo //===----------------------------------------------------------------------===// /// Return true if operation `a` properly dominates operation `b`. The /// 'enclosingOpOk' flag says whether we should return true if the `b` op is /// enclosed by a region on 'a'. bool DominanceInfo::properlyDominatesImpl(Operation *a, Operation *b, bool enclosingOpOk) const { … } /// Return true if the `a` value properly dominates operation `b`, i.e if the /// operation that defines `a` properlyDominates `b` and the operation that /// defines `a` does not contain `b`. bool DominanceInfo::properlyDominates(Value a, Operation *b) const { … } //===----------------------------------------------------------------------===// // PostDominanceInfo //===----------------------------------------------------------------------===// /// Returns true if statement 'a' properly postdominates statement b. bool PostDominanceInfo::properlyPostDominates(Operation *a, Operation *b) { … }