1//===-- VPlanDominatorTree.h ------------------------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8///
9/// \file
10/// This file implements dominator tree analysis for a single level of a VPlan's
11/// H-CFG.
12///
13//===----------------------------------------------------------------------===//
14
15#ifndef LLVM_TRANSFORMS_VECTORIZE_VPLANDOMINATORTREE_H
16#define LLVM_TRANSFORMS_VECTORIZE_VPLANDOMINATORTREE_H
17
18#include "VPlan.h"
19#include "VPlanCFG.h"
20#include "llvm/ADT/GraphTraits.h"
21#include "llvm/Analysis/DominanceFrontier.h"
22#include "llvm/IR/Dominators.h"
23#include "llvm/Support/GenericDomTree.h"
24#include "llvm/Support/GenericDomTreeConstruction.h"
25
26namespace llvm {
27
28template <> struct DomTreeNodeTraits<VPBlockBase> {
29 using NodeType = VPBlockBase;
30 using NodePtr = VPBlockBase *;
31 using ParentPtr = VPlan *;
32
33 static NodePtr getEntryNode(ParentPtr Parent) { return Parent->getEntry(); }
34 static ParentPtr getParent(NodePtr B) { return B->getPlan(); }
35};
36
37/// Template specialization of the standard LLVM dominator tree utility for
38/// VPBlockBases.
39class VPDominatorTree : public DominatorTreeBase<VPBlockBase, false> {
40 using Base = DominatorTreeBase<VPBlockBase, false>;
41
42public:
43 explicit VPDominatorTree(VPlan &Plan) { recalculate(Func&: Plan); }
44
45 /// Returns true if \p A properly dominates \p B.
46 using Base::properlyDominates;
47 LLVM_ABI_FOR_TEST bool properlyDominates(const VPRecipeBase *A,
48 const VPRecipeBase *B) const;
49};
50
51/// Template specialization of the standard LLVM post-dominator tree utility for
52/// VPBlockBases.
53class VPPostDominatorTree : public PostDomTreeBase<VPBlockBase> {
54 using Base = PostDomTreeBase<VPBlockBase>;
55
56public:
57 explicit VPPostDominatorTree(VPlan &Plan) { recalculate(Func&: Plan); }
58};
59
60using VPDomTreeNode = DomTreeNodeBase<VPBlockBase>;
61
62/// Template specializations of GraphTraits for VPDomTreeNode.
63template <>
64struct GraphTraits<VPDomTreeNode *>
65 : public DomTreeGraphTraitsBase<VPDomTreeNode,
66 VPDomTreeNode::const_iterator> {};
67
68template <>
69struct GraphTraits<const VPDomTreeNode *>
70 : public DomTreeGraphTraitsBase<const VPDomTreeNode,
71 VPDomTreeNode::const_iterator> {};
72
73struct VPPostDominanceFrontier
74 : public DominanceFrontierBase<VPBlockBase, true> {
75 explicit VPPostDominanceFrontier(const DomTreeT &VPDT);
76};
77} // namespace llvm
78#endif // LLVM_TRANSFORMS_VECTORIZE_VPLANDOMINATORTREE_H
79