namespace mlir {
using DominanceInfoNode = llvm::DomTreeNodeBase<Block>;
class Function;
+class Operation;
namespace detail {
template <bool IsPostDom> 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) {
#include "mlir/Analysis/Dominance.h"
#include "mlir/IR/Operation.h"
#include "llvm/Support/GenericDomTreeConstruction.h"
+
using namespace mlir;
using namespace mlir::detail;
// DominanceInfoBase
//===----------------------------------------------------------------------===//
-/// Recalculate the dominance info for the provided function.
+/// Recalculate the dominance info.
template <bool IsPostDom>
void DominanceInfoBase<IsPostDom>::recalculate(Function *function) {
dominanceInfos.clear();
});
}
+template <bool IsPostDom>
+void DominanceInfoBase<IsPostDom>::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<base>();
+ opDominance->recalculate(region);
+ dominanceInfos.try_emplace(®ion, std::move(opDominance));
+ }
+ });
+}
+
/// Return true if the specified block A properly dominates block B.
template <bool IsPostDom>
bool DominanceInfoBase<IsPostDom>::properlyDominates(Block *a, Block *b) {