LLVM 23.0.0git
DominanceFrontierImpl.h
Go to the documentation of this file.
1//===- llvm/Analysis/DominanceFrontier.h - Dominator Frontiers --*- 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// This is the generic implementation of the DominanceFrontier class, which
10// calculate and holds the dominance frontier for a function for.
11//
12// This should be considered deprecated, don't add any more uses of this data
13// structure.
14//
15//===----------------------------------------------------------------------===//
16
17#ifndef LLVM_ANALYSIS_DOMINANCEFRONTIERIMPL_H
18#define LLVM_ANALYSIS_DOMINANCEFRONTIERIMPL_H
19
22#include "llvm/Config/llvm-config.h"
23#include "llvm/Support/Debug.h"
26#include <cassert>
27#include <vector>
28
29namespace llvm {
30
31template <class BlockT>
33public:
35
36 DFCalculateWorkObject(BlockT *B, BlockT *P, const DomTreeNodeT *N,
37 const DomTreeNodeT *PN)
38 : currentBB(B), parentBB(P), Node(N), parentNode(PN) {}
39
40 BlockT *currentBB;
41 BlockT *parentBB;
44};
45
46template <class BlockT, bool IsPostDom>
48 for (const_iterator I = begin(), E = end(); I != E; ++I) {
49 OS << " DomFrontier for BB ";
50 if (I->first)
51 I->first->printAsOperand(OS, false);
52 else
53 OS << " <<exit node>>";
54 OS << " is:\t";
55
56 const SetVector<BlockT *> &BBs = I->second;
57
58 for (const BlockT *BB : BBs) {
59 OS << ' ';
60 if (BB)
61 BB->printAsOperand(OS, false);
62 else
63 OS << "<<exit node>>";
64 }
65 OS << '\n';
66 }
67}
68
69#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
70template <class BlockT, bool IsPostDom>
74#endif
75
76template <class BlockT>
78 const DomTreeNodeT *Node) {
79 BlockT *BB = Node->getBlock();
80
81 std::vector<DFCalculateWorkObject<BlockT>> workList;
83
84 workList.push_back(DFCalculateWorkObject<BlockT>(BB, nullptr, Node, nullptr));
85 do {
86 DFCalculateWorkObject<BlockT> *currentW = &workList.back();
87 assert(currentW && "Missing work object.");
88
89 BlockT *currentBB = currentW->currentBB;
90 BlockT *parentBB = currentW->parentBB;
91 const DomTreeNodeT *currentNode = currentW->Node;
92 const DomTreeNodeT *parentNode = currentW->parentNode;
93 assert(currentBB && "Invalid work object. Missing current Basic Block");
94 assert(currentNode && "Invalid work object. Missing current Node");
95 DomSetType &S = this->Frontiers[currentBB];
96
97 // Visit each block only once.
98 if (visited.insert(currentBB).second) {
99 // Loop over CFG successors to calculate DFlocal[currentNode]
100 for (const auto Succ : children<BlockT *>(currentBB)) {
101 // Does Node immediately dominate this successor?
102 if (DT[Succ]->getIDom() != currentNode)
103 S.insert(Succ);
104 }
105 }
106
107 // At this point, S is DFlocal. Now we union in DFup's of our children...
108 // Loop through and visit the nodes that Node immediately dominates (Node's
109 // children in the IDomTree)
110 bool visitChild = false;
111 for (typename DomTreeNodeT::const_iterator NI = currentNode->begin(),
112 NE = currentNode->end();
113 NI != NE; ++NI) {
114 DomTreeNodeT *IDominee = *NI;
115 BlockT *childBB = IDominee->getBlock();
116 if (visited.count(childBB) == 0) {
117 workList.push_back(DFCalculateWorkObject<BlockT>(
118 childBB, currentBB, IDominee, currentNode));
119 visitChild = true;
120 }
121 }
122
123 // If all children are visited or there is any child then pop this block
124 // from the workList.
125 if (!visitChild) {
126 if (!parentBB) {
127 break;
128 }
129
130 typename DomSetType::const_iterator CDFI = S.begin(), CDFE = S.end();
131 DomSetType &parentSet = this->Frontiers[parentBB];
132 for (; CDFI != CDFE; ++CDFI) {
133 if (!DT.properlyDominates(parentNode, DT[*CDFI]))
134 parentSet.insert(*CDFI);
135 }
136 workList.pop_back();
137 }
138
139 } while (!workList.empty());
140}
141
142} // end namespace llvm
143
144#endif // LLVM_ANALYSIS_DOMINANCEFRONTIERIMPL_H
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
This file defines a set of templates that efficiently compute a dominator tree over a generic graph.
#define I(x, y, z)
Definition MD5.cpp:57
#define P(N)
This file defines the SmallPtrSet class.
DFCalculateWorkObject(BlockT *B, BlockT *P, const DomTreeNodeT *N, const DomTreeNodeT *PN)
DomTreeNodeBase< BlockT > DomTreeNodeT
Base class for the actual dominator tree node.
void print(raw_ostream &OS) const
print - Convert to human readable form
void dump() const
dump - Dump the dominance frontier to dbgs().
typename DomSetMapType::const_iterator const_iterator
bool properlyDominates(const DomTreeNodeBase< NodeT > *A, const DomTreeNodeBase< NodeT > *B) const
properlyDominates - Returns true iff A dominates B and A != B.
void calculate(const DomTreeT &DT, const DomTreeNodeT *Node)
DomTreeNodeBase< BlockT > DomTreeNodeT
A vector that has set insertion semantics.
Definition SetVector.h:57
iterator end()
Get an iterator to the end of the SetVector.
Definition SetVector.h:112
iterator begin()
Get an iterator to the beginning of the SetVector.
Definition SetVector.h:106
bool insert(const value_type &X)
Insert a new element into the SetVector.
Definition SetVector.h:151
size_type count(ConstPtrType Ptr) const
count - Return 1 if the specified pointer is in the set, 0 otherwise.
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition raw_ostream.h:53
This is an optimization pass for GlobalISel generic memory operations.
Definition Types.h:26
Printable print(const GCNRegPressure &RP, const GCNSubtarget *ST=nullptr, unsigned DynamicVGPRBlockSize=0)
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition Debug.cpp:207
iterator_range< typename GraphTraits< GraphType >::ChildIteratorType > children(const typename GraphTraits< GraphType >::NodeRef &G)
#define N