llvm.org GIT mirror llvm / 403309b
[Dominators] Clean up typedefs in GenericDomTreeConstruction. NFC. Summary: This patch cleans up GenericDomTreeConstruction by replacing typedefs with usings and replaces `typename GraphT::NodeRef` with `NodePtr` to make the file more readable. Reviewers: sanjoy, dberlin, chandlerc Reviewed By: dberlin Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D34254 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@305715 91177308-0d34-0410-b5e6-96231b3b80d8 Jakub Kuderski 3 years ago
1 changed file(s) with 24 addition(s) and 21 deletion(s). Raw diff Collapse all Expand all
3434 // converting the one argument insert calls.
3535 template struct df_iterator_dom_storage {
3636 public:
37 typedef DenseMap BaseSet;
37 using BaseSet = DenseMap;
3838 df_iterator_dom_storage(BaseSet &Storage) : Storage(Storage) {}
3939
40 typedef typename BaseSet::iterator iterator;
40 using iterator = typename BaseSet::iterator;
4141 std::pair insert(NodeRef N) {
4242 return Storage.insert({N, InfoType()});
4343 }
100100 typename GraphT::NodeRef Eval(DominatorTreeBaseByGraphTraits &DT,
101101 typename GraphT::NodeRef VIn,
102102 unsigned LastLinked) {
103 using NodePtr = typename GraphT::NodeRef;
104
103105 auto &VInInfo = DT.Info[VIn];
104106 if (VInInfo.DFSNum < LastLinked)
105107 return VIn;
106108
107 SmallVector Work;
108 SmallPtrSet Visited;
109 SmallVector Work;
110 SmallPtrSet Visited;
109111
110112 if (VInInfo.Parent >= LastLinked)
111113 Work.push_back(VIn);
112114
113115 while (!Work.empty()) {
114 typename GraphT::NodeRef V = Work.back();
116 NodePtr V = Work.back();
115117 auto &VInfo = DT.Info[V];
116 typename GraphT::NodeRef VAncestor = DT.Vertex[VInfo.Parent];
118 NodePtr VAncestor = DT.Vertex[VInfo.Parent];
117119
118120 // Process Ancestor first
119121 if (Visited.insert(VAncestor).second && VInfo.Parent >= LastLinked) {
127129 continue;
128130
129131 auto &VAInfo = DT.Info[VAncestor];
130 typename GraphT::NodeRef VAncestorLabel = VAInfo.Label;
131 typename GraphT::NodeRef VLabel = VInfo.Label;
132 NodePtr VAncestorLabel = VAInfo.Label;
133 NodePtr VLabel = VInfo.Label;
132134 if (DT.Info[VAncestorLabel].Semi < DT.Info[VLabel].Semi)
133135 VInfo.Label = VAncestorLabel;
134136 VInfo.Parent = VAInfo.Parent;
140142 template
141143 void Calculate(DominatorTreeBaseByGraphTraits> &DT,
142144 FuncT &F) {
143 typedef GraphTraits GraphT;
144 static_assert(std::is_pointer::value,
145 using GraphT = GraphTraits;
146 using NodePtr = typename GraphT::NodeRef;
147 static_assert(std::is_pointer::value,
145148 "NodeRef should be pointer type");
146 typedef typename std::remove_pointer::type NodeType;
149 using NodeType = typename std::remove_pointer::type;
147150
148151 unsigned N = 0;
149152 bool MultipleRoots = (DT.Roots.size() > 1);
185188 Buckets[i] = i;
186189
187190 for (unsigned i = N; i >= 2; --i) {
188 typename GraphT::NodeRef W = DT.Vertex[i];
191 NodePtr W = DT.Vertex[i];
189192 auto &WInfo = DT.Info[W];
190193
191194 // Step #2: Implicitly define the immediate dominator of vertices
192195 for (unsigned j = i; Buckets[j] != i; j = Buckets[j]) {
193 typename GraphT::NodeRef V = DT.Vertex[Buckets[j]];
194 typename GraphT::NodeRef U = Eval(DT, V, i + 1);
196 NodePtr V = DT.Vertex[Buckets[j]];
197 NodePtr U = Eval(DT, V, i + 1);
195198 DT.IDoms[V] = DT.Info[U].Semi < i ? U : W;
196199 }
197200
218221 }
219222
220223 if (N >= 1) {
221 typename GraphT::NodeRef Root = DT.Vertex[1];
224 NodePtr Root = DT.Vertex[1];
222225 for (unsigned j = 1; Buckets[j] != 1; j = Buckets[j]) {
223 typename GraphT::NodeRef V = DT.Vertex[Buckets[j]];
226 NodePtr V = DT.Vertex[Buckets[j]];
224227 DT.IDoms[V] = Root;
225228 }
226229 }
227230
228231 // Step #4: Explicitly define the immediate dominator of each vertex
229232 for (unsigned i = 2; i <= N; ++i) {
230 typename GraphT::NodeRef W = DT.Vertex[i];
231 typename GraphT::NodeRef &WIDom = DT.IDoms[W];
233 NodePtr W = DT.Vertex[i];
234 NodePtr &WIDom = DT.IDoms[W];
232235 if (WIDom != DT.Vertex[DT.Info[W].Semi])
233236 WIDom = DT.IDoms[WIDom];
234237 }
239242 // one exit block, or it may be the virtual exit (denoted by (BasicBlock *)0)
240243 // which postdominates all real exits if there are multiple exit blocks, or
241244 // an infinite loop.
242 typename GraphT::NodeRef Root = !MultipleRoots ? DT.Roots[0] : nullptr;
245 NodePtr Root = !MultipleRoots ? DT.Roots[0] : nullptr;
243246
244247 DT.RootNode =
245248 (DT.DomTreeNodes[Root] =
248251
249252 // Loop over all of the reachable blocks in the function...
250253 for (unsigned i = 2; i <= N; ++i) {
251 typename GraphT::NodeRef W = DT.Vertex[i];
254 NodePtr W = DT.Vertex[i];
252255
253256 // Don't replace this with 'count', the insertion side effect is important
254257 if (DT.DomTreeNodes[W])
255258 continue; // Haven't calculated this node yet?
256259
257 typename GraphT::NodeRef ImmDom = DT.getIDom(W);
260 NodePtr ImmDom = DT.getIDom(W);
258261
259262 assert(ImmDom || DT.DomTreeNodes[nullptr]);
260263