xref: /freebsd/contrib/llvm-project/llvm/lib/Transforms/Vectorize/VPlanDominatorTree.h (revision 700637cbb5e582861067a11aaca4d053546871d2)
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/IR/Dominators.h"
22 #include "llvm/Support/GenericDomTree.h"
23 #include "llvm/Support/GenericDomTreeConstruction.h"
24 
25 namespace llvm {
26 
27 template <> struct DomTreeNodeTraits<VPBlockBase> {
28   using NodeType = VPBlockBase;
29   using NodePtr = VPBlockBase *;
30   using ParentPtr = VPlan *;
31 
32   static NodePtr getEntryNode(ParentPtr Parent) { return Parent->getEntry(); }
33   static ParentPtr getParent(NodePtr B) { return B->getPlan(); }
34 };
35 
36 /// Template specialization of the standard LLVM dominator tree utility for
37 /// VPBlockBases.
38 class VPDominatorTree : public DominatorTreeBase<VPBlockBase, false> {
39   using Base = DominatorTreeBase<VPBlockBase, false>;
40 
41 public:
42   VPDominatorTree() = default;
43   explicit VPDominatorTree(VPlan &Plan) { recalculate(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);
48 };
49 
50 using VPDomTreeNode = DomTreeNodeBase<VPBlockBase>;
51 
52 /// Template specializations of GraphTraits for VPDomTreeNode.
53 template <>
54 struct GraphTraits<VPDomTreeNode *>
55     : public DomTreeGraphTraitsBase<VPDomTreeNode,
56                                     VPDomTreeNode::const_iterator> {};
57 
58 template <>
59 struct GraphTraits<const VPDomTreeNode *>
60     : public DomTreeGraphTraitsBase<const VPDomTreeNode,
61                                     VPDomTreeNode::const_iterator> {};
62 } // namespace llvm
63 #endif // LLVM_TRANSFORMS_VECTORIZE_VPLANDOMINATORTREE_H
64