[Dominators] Rewrite the dominator implementation for efficiency. NFC.
authorChris Lattner <clattner@nondot.org>
Mon, 31 May 2021 01:02:51 +0000 (18:02 -0700)
committerChris Lattner <clattner@nondot.org>
Tue, 1 Jun 2021 21:46:37 +0000 (14:46 -0700)
commit412ae15de49a227de25a695735451f8908ebf999
treee5949081b7bb4c5fed5b781e7c06c0f92ef5d844
parentc1a59fa550818c6d3c229b43918b5045d7df83e6
[Dominators] Rewrite the dominator implementation for efficiency. NFC.

The previous impl densely scanned the entire region starting with an op
when dominators were created, creating a DominatorTree for every region.

This is extremely expensive up front -- particularly for clients like
Linalg/Transforms/Fusion.cpp that construct DominanceInfo for a single
query.  It is also extremely memory wasteful for IRs that use single
block regions commonly (e.g. affine.for) because it's making a
dominator tree for a region that has trivial dominance.  The
implementation also had numerous unnecessary minor efficiencies, e.g.
doing multiple walks of the region tree or tryGetBlocksInSameRegion
building a DenseMap that it didn't need.

This patch switches to an approach where [Post]DominanceInfo is free
to construct, and which lazily constructs DominatorTree's for any
multiblock regions that it needs.  This avoids the up-front cost
entirely, making its runtime proportional to the complexity of the
region tree instead of # ops in a region.  This also avoids the memory
and time cost of creating DominatorTree's for single block regions.

Finally this rewrites the implementation for simplicity and to avoids
the constant factor problems the old implementation had.

Differential Revision: https://reviews.llvm.org/D103384
mlir/include/mlir/IR/Dominance.h
mlir/include/mlir/IR/Region.h
mlir/lib/IR/Dominance.cpp
mlir/lib/IR/Region.cpp
mlir/lib/Transforms/BufferOptimizations.cpp
mlir/lib/Transforms/CSE.cpp