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 bool properlyDominates(const VPRecipeBase *A, const VPRecipeBase *B) const;
48};
49
50/// Template specialization of the standard LLVM post-dominator tree utility for
51/// VPBlockBases.
52class VPPostDominatorTree : public PostDomTreeBase<VPBlockBase> {
53 using Base = PostDomTreeBase<VPBlockBase>;
54
55public:
56 explicit VPPostDominatorTree(VPlan &Plan) { recalculate(Func&: Plan); }
57};
58
59using VPDomTreeNode = DomTreeNodeBase<VPBlockBase>;
60
61/// Template specializations of GraphTraits for VPDomTreeNode.
62template <>
63struct GraphTraits<VPDomTreeNode *>
64 : public DomTreeGraphTraitsBase<VPDomTreeNode,
65 VPDomTreeNode::const_iterator> {};
66
67template <>
68struct GraphTraits<const VPDomTreeNode *>
69 : public DomTreeGraphTraitsBase<const VPDomTreeNode,
70 VPDomTreeNode::const_iterator> {};
71
72struct VPPostDominanceFrontier
73 : public DominanceFrontierBase<VPBlockBase, true> {
74 explicit VPPostDominanceFrontier(const DomTreeT &VPDT);
75};
76} // namespace llvm
77#endif // LLVM_TRANSFORMS_VECTORIZE_VPLANDOMINATORTREE_H
78