10 #ifndef LLVM_ANALYSIS_DOMINATOR_INTERNALS_H
11 #define LLVM_ANALYSIS_DOMINATOR_INTERNALS_H
33 template<
class GraphT>
41 VInfo.DFSNum = VInfo.Semi = ++
N;
47 InfoRec &SuccVInfo = DT.
Info[*SI];
48 if (SuccVInfo.Semi == 0) {
50 N = DTDFSPass(DT, *SI, N);
54 bool IsChildOfArtificialExit = (N != 0);
57 typename GraphT::ChildIteratorType>, 32> Worklist;
58 Worklist.push_back(std::make_pair(V, GraphT::child_begin(V)));
59 while (!Worklist.empty()) {
60 typename GraphT::NodeType* BB = Worklist.back().first;
61 typename GraphT::ChildIteratorType NextSucc = Worklist.back().second;
67 if (NextSucc == GraphT::child_begin(BB)) {
73 if (IsChildOfArtificialExit)
76 IsChildOfArtificialExit =
false;
81 unsigned BBDFSNum = BBInfo.
DFSNum;
84 if (NextSucc == GraphT::child_end(BB)) {
90 ++Worklist.back().second;
93 typename GraphT::NodeType* Succ = *NextSucc;
97 if (SuccVInfo.
Semi == 0) {
98 SuccVInfo.
Parent = BBDFSNum;
99 Worklist.push_back(std::make_pair(Succ, GraphT::child_begin(Succ)));
106 template<
class GraphT>
112 if (VInInfo.
DFSNum < LastLinked)
118 if (VInInfo.
Parent >= LastLinked)
121 while (!Work.
empty()) {
128 if (Visited.
insert(VAncestor) && VInfo.
Parent >= LastLinked) {
135 if (VInfo.
Parent < LastLinked)
142 if (DT.
Info[VAncestorLabel].Semi < DT.
Info[VLabel].Semi)
143 VInfo.
Label = VAncestorLabel;
147 return VInInfo.
Label;
150 template<
class FuncT,
class NodeT>
156 bool MultipleRoots = (DT.Roots.size() > 1);
163 DT.Vertex.push_back(NULL);
168 for (
unsigned i = 0, e = static_cast<unsigned>(DT.Roots.size());
170 N = DFSPass<GraphT>(DT, DT.Roots[i], N);
188 for (
unsigned i = 1; i <=
N; ++i)
191 for (
unsigned i = N; i >= 2; --i) {
197 for (
unsigned j = i; Buckets[j] != i; j = Buckets[j]) {
200 DT.IDoms[V] = DT.Info[U].Semi < i ? U : W;
208 for (
typename InvTraits::ChildIteratorType CI =
209 InvTraits::child_begin(W),
210 E = InvTraits::child_end(W); CI != E; ++CI) {
212 if (DT.Info.count(N)) {
213 unsigned SemiU = DT.Info[Eval<GraphT>(DT,
N, i + 1)].Semi;
214 if (SemiU < WInfo.
Semi)
223 DT.IDoms[W] = DT.Vertex[WInfo.
Parent];
225 Buckets[i] = Buckets[WInfo.
Semi];
226 Buckets[WInfo.
Semi] = i;
232 for (
unsigned j = 1; Buckets[j] != 1; j = Buckets[j]) {
239 for (
unsigned i = 2; i <=
N; ++i) {
242 if (WIDom != DT.Vertex[DT.Info[W].Semi])
243 WIDom = DT.IDoms[WIDom];
246 if (DT.Roots.empty())
return;
254 DT.DomTreeNodes[Root] = DT.RootNode =
258 for (
unsigned i = 2; i <=
N; ++i) {
262 if (BBNode)
continue;
266 assert(ImmDom || DT.DomTreeNodes[NULL]);
270 DT.getNodeForBlock(ImmDom);
276 DT.DomTreeNodes[W] = IDomNode->
addChild(C);
282 std::vector<typename GraphT::NodeType*>().
swap(DT.Vertex);
284 DT.updateDFSNumbers();
void push_back(const T &Elt)
DenseMap< NodeT *, InfoRec > Info
unsigned DFSPass(DominatorTreeBase< typename GraphT::NodeType > &DT, typename GraphT::NodeType *V, unsigned N)
std::vector< NodeT * > Roots
std::vector< NodeT * > Vertex
void swap(OwningPtr< T > &a, OwningPtr< T > &b)
Interval::succ_iterator succ_begin(Interval *I)
bool LLVM_ATTRIBUTE_UNUSED_RESULT empty() const
Interval::succ_iterator succ_end(Interval *I)
void Calculate(DominatorTreeBase< typename GraphTraits< NodeT >::NodeType > &DT, FuncT &F)
GraphType::UnknownGraphTypeError NodeType
DomTreeNodeBase< NodeT > * addChild(DomTreeNodeBase< NodeT > *C)
GraphT::NodeType * Eval(DominatorTreeBase< typename GraphT::NodeType > &DT, typename GraphT::NodeType *VIn, unsigned LastLinked)