17 #include "llvm/Support/GenericDomTreeConstruction.h"
22 template class llvm::DominatorTreeBase<
Block,
false>;
23 template class llvm::DominatorTreeBase<
Block,
true>;
24 template class llvm::DomTreeNodeBase<Block>;
30 template <
bool IsPostDom>
32 for (
auto entry : dominanceInfos)
33 delete entry.second.getPointer();
36 template <
bool IsPostDom>
38 for (
auto entry : dominanceInfos)
39 delete entry.second.getPointer();
40 dominanceInfos.clear();
43 template <
bool IsPostDom>
45 auto it = dominanceInfos.find(region);
46 if (it != dominanceInfos.end()) {
47 delete it->second.getPointer();
48 dominanceInfos.erase(it);
55 template <
bool IsPostDom>
57 bool needsDomTree)
const
58 -> llvm::PointerIntPair<DomTree *, 1, bool> {
60 auto itAndInserted = dominanceInfos.insert({region, {
nullptr,
true}});
61 auto &entry = itAndInserted.first->second;
66 if (!itAndInserted.second) {
69 if (needsDomTree && !entry.getPointer() && !region->hasOneBlock()) {
70 auto *domTree =
new DomTree();
71 domTree->recalculate(*region);
72 entry.setPointer(domTree);
79 if (!region->hasOneBlock()) {
80 auto *domTree =
new DomTree();
81 domTree->recalculate(*region);
82 entry.setPointer(domTree);
89 if (!parentOp->isRegistered()) {
91 }
else if (
auto regionKindItf = dyn_cast<RegionKindInterface>(parentOp)) {
94 entry.setInt(regionKindItf.hasSSADominance(region->getRegionNumber()));
105 return ancestorOp->getBlock();
114 template <
typename FuncT>
131 if (aRegion == bRegion)
137 size_t aRegionDepth = 0;
149 size_t bRegionDepth = 0;
161 if (aRegionDepth > bRegionDepth) {
164 }
else if (aRegionDepth < bRegionDepth) {
189 template <
bool IsPostDom>
212 return getDomTree(a->
getParent()).findNearestCommonDominator(a, b);
222 static std::pair<Block *, Block::iterator>
226 return std::make_pair(b, it);
235 return std::make_pair(op->
getBlock(), op->getIterator());
245 if (a == block->
end())
247 if (b == block->
end())
249 return a->isBeforeInBlock(&*b);
252 template <
bool IsPostDom>
255 bool enclosingOk)
const {
256 assert(aBlock && bBlock &&
"expected non-null blocks");
260 if (aBlock == bBlock && aIt == bIt)
261 return !hasSSADominance(aBlock);
273 std::tie(bBlock, bIt) =
278 assert(bBlock->
getParent() == aRegion &&
"expected block in regionA");
281 if (aBlock == bBlock && aIt == bIt && enclosingOk)
286 if (aBlock == bBlock) {
290 if (!hasSSADominance(aBlock))
292 if constexpr (IsPostDom) {
300 return getDomTree(aRegion).properlyDominates(aBlock, bBlock);
305 template <
bool IsPostDom>
309 if (®ion->
front() == a)
313 return getDomTree(region).isReachableFromEntry(a);
324 bool enclosingOpOk)
const {
325 return super::properlyDominatesImpl(a->
getBlock(), a->getIterator(),
331 return super::properlyDominatesImpl(a, a->
begin(), b, b->
begin(),
341 if (
auto blockArg = dyn_cast<BlockArgument>(a))
342 return dominates(blockArg.getOwner(), b->
getBlock());
354 bool enclosingOpOk)
const {
355 return super::properlyDominatesImpl(a->
getBlock(), a->getIterator(),
361 return super::properlyDominatesImpl(a, a->
end(), b, b->
end(),
static Block * traverseAncestors(Block *block, const FuncT &func)
Walks up the list of containers of the given block and calls the user-defined traversal function for ...
static bool isBeforeInBlock(Block *block, Block::iterator a, Block::iterator b)
Given two iterators into the same block, return "true" if a is before `b.
static std::pair< Block *, Block::iterator > findAncestorIteratorInRegion(Region *r, Block *b, Block::iterator it)
Returns the given block iterator if it lies within the region region.
static bool tryGetBlocksInSameRegion(Block *&a, Block *&b)
Tries to update the given block references to live in the same region by exploring the relationship o...
static Block * getAncestorBlock(Block *block)
Return the ancestor block enclosing the specified block.
Block represents an ordered list of Operations.
OpListType::iterator iterator
Region * getParent() const
Provide a 'getParent' method for ilist_node_with_parent methods.
Operation * getParentOp()
Returns the closest surrounding operation that contains this block.
bool properlyDominates(Operation *a, Operation *b, bool enclosingOpOk=true) const
Return true if operation A properly dominates operation B, i.e.
Operation is the basic unit of execution within MLIR.
Operation * getParentOp()
Returns the closest surrounding operation that contains this operation or nullptr if this is a top-le...
Block * getBlock()
Returns the operation block that contains this operation.
bool properlyPostDominates(Operation *a, Operation *b, bool enclosingOpOk=true) const
Return true if operation A properly postdominates operation B.
This class contains a list of basic blocks and a link to the parent operation it is attached to.
Operation * findAncestorOpInRegion(Operation &op)
Returns 'op' if 'op' lies in this region, or otherwise finds the ancestor of 'op' that lies in this r...
This class represents an instance of an SSA value in the MLIR system, representing a computable value...
Operation * getDefiningOp() const
If this value is the result of an operation, return the operation that defines it.
llvm::PointerIntPair< DomTree *, 1, bool > getDominanceInfo(Region *region, bool needsDomTree) const
Return the dom tree and "hasSSADominance" bit for the given region.
bool isReachableFromEntry(Block *a) const
Return true if the specified block is reachable from the entry block of its region.
bool properlyDominatesImpl(Block *aBlock, Block::iterator aIt, Block *bBlock, Block::iterator bIt, bool enclosingOk=true) const
Return "true" if block iterator A properly (post)dominates block iterator B.
Block * findNearestCommonDominator(Block *a, Block *b) const
Finds the nearest common dominator block for the two given blocks a and b.
void invalidate()
Invalidate dominance info.
Include the generated interface declarations.