llvm.org GIT mirror llvm / 9ea8dfe
unique_ptrify the value in DominatorTreeBase::DomTreeNodes (noticed the need for an explicit dtor in a recent commit & figured I'd tidy that up) git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@226028 91177308-0d34-0410-b5e6-96231b3b80d8 David Blaikie 5 years ago
2 changed file(s) with 28 addition(s) and 34 deletion(s). Raw diff Collapse all Expand all
9292 DomTreeNodeBase(NodeT *BB, DomTreeNodeBase *iDom)
9393 : TheBB(BB), IDom(iDom), DFSNumIn(-1), DFSNumOut(-1) {}
9494
95 DomTreeNodeBase *addChild(DomTreeNodeBase *C) {
96 Children.push_back(C);
95 std::unique_ptr>
96 addChild(std::unique_ptr> C) {
97 Children.push_back(C.get());
9798 return C;
9899 }
99100
209210 }
210211
211212 protected:
212 typedef DenseMapDomTreeNodeBase *> DomTreeNodeMapType;
213 typedef DenseMapstd::unique_ptr>>
214 DomTreeNodeMapType;
213215 DomTreeNodeMapType DomTreeNodes;
214216 DomTreeNodeBase *RootNode;
215217
234236 DenseMap Info;
235237
236238 void reset() {
237 for (typename DomTreeNodeMapType::iterator I = this->DomTreeNodes.begin(),
238 E = DomTreeNodes.end();
239 I != E; ++I)
240 delete I->second;
241239 DomTreeNodes.clear();
242240 IDoms.clear();
243241 this->Roots.clear();
313311 public:
314312 explicit DominatorTreeBase(bool isPostDom)
315313 : DominatorBase(isPostDom), DFSInfoValid(false), SlowQueries(0) {}
316 ~DominatorTreeBase() { reset(); }
317314
318315 DominatorTreeBase(DominatorTreeBase &&Arg)
319316 : DominatorBase(
357354 if (OI == OtherDomTreeNodes.end())
358355 return true;
359356
360 DomTreeNodeBase *MyNd = I->second;
361 DomTreeNodeBase *OtherNd = OI->second;
362
363 if (MyNd->compare(OtherNd))
357 DomTreeNodeBase &MyNd = *I->second;
358 DomTreeNodeBase &OtherNd = *OI->second;
359
360 if (MyNd.compare(&OtherNd))
364361 return true;
365362 }
366363
373370 /// block. This is the same as using operator[] on this class.
374371 ///
375372 DomTreeNodeBase *getNode(NodeT *BB) const {
376 return DomTreeNodes.lookup(BB);
373 auto I = DomTreeNodes.find(BB);
374 if (I != DomTreeNodes.end())
375 return I->second.get();
376 return nullptr;
377377 }
378378
379379 DomTreeNodeBase *operator[](NodeT *BB) const { return getNode(BB); }
554554 DomTreeNodeBase *IDomNode = getNode(DomBB);
555555 assert(IDomNode && "Not immediate dominator specified for block!");
556556 DFSInfoValid = false;
557 return DomTreeNodes[BB] =
558 IDomNode->addChild(new DomTreeNodeBase(BB, IDomNode));
557 return (DomTreeNodes[BB] = IDomNode->addChild(
558 llvm::make_unique>(BB, IDomNode))).get();
559559 }
560560
561561 /// changeImmediateDominator - This method is used to update the dominator
592592 }
593593
594594 DomTreeNodes.erase(BB);
595 delete Node;
596 }
597
598 /// removeNode - Removes a node from the dominator tree. Block must not
599 /// dominate any other blocks. Invalidates any node pointing to removed
600 /// block.
601 void removeNode(NodeT *BB) {
602 assert(getNode(BB) && "Removing node that isn't in dominator tree.");
603 DomTreeNodes.erase(BB);
604595 }
605596
606597 /// splitBlock - BB is split and now it has one successor. Update dominator
702693
703694 // Add a new tree node for this NodeT, and link it as a child of
704695 // IDomNode
705 DomTreeNodeBase *C = new DomTreeNodeBase(BB, IDomNode);
706 return this->DomTreeNodes[BB] = IDomNode->addChild(C);
696 return (this->DomTreeNodes[BB] = IDomNode->addChild(
697 llvm::make_unique>(BB, IDomNode))).get();
707698 }
708699
709700 NodeT *getIDom(NodeT *BB) const { return IDoms.lookup(BB); }
250250 // an infinite loop.
251251 typename GraphT::NodeType* Root = !MultipleRoots ? DT.Roots[0] : nullptr;
252252
253 DT.DomTreeNodes[Root] = DT.RootNode =
254 new DomTreeNodeBase(Root, nullptr);
253 DT.RootNode =
254 (DT.DomTreeNodes[Root] =
255 llvm::make_unique>(
256 Root, nullptr)).get();
255257
256258 // Loop over all of the reachable blocks in the function...
257259 for (unsigned i = 2; i <= N; ++i) {
258260 typename GraphT::NodeType* W = DT.Vertex[i];
259261
260 DomTreeNodeBase *BBNode = DT.DomTreeNodes[W];
261 if (BBNode) continue; // Haven't calculated this node yet?
262 if (DT.DomTreeNodes[W])
263 continue; // Haven't calculated this node yet?
262264
263265 typename GraphT::NodeType* ImmDom = DT.getIDom(W);
264266
270272
271273 // Add a new tree node for this BasicBlock, and link it as a child of
272274 // IDomNode
273 DomTreeNodeBase *C =
274 new DomTreeNodeBase(W, IDomNode);
275 DT.DomTreeNodes[W] = IDomNode->addChild(C);
275 DT.DomTreeNodes[W] = IDomNode->addChild(
276 llvm::make_unique>(
277 W, IDomNode));
276278 }
277279
278280 // Free temporary memory used to construct idom's
279281 DT.IDoms.clear();
280282 DT.Info.clear();
281 std::vector().swap(DT.Vertex);
283 DT.Vertex.clear();
284 DT.Vertex.shrink_to_fit();
282285
283286 DT.updateDFSNumbers();
284287 }