From: Chandler Carruth Date: Fri, 18 Apr 2014 11:02:33 +0000 (+0000) Subject: [LCG] Remove all of the complexity stemming from supporting copying. X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=14def5573601bd07e8e9eea36fa41b77e1eac96e;p=oota-llvm.git [LCG] Remove all of the complexity stemming from supporting copying. Reality is that we're never going to copy one of these. Supporting this was becoming a nightmare because nothing even causes it to compile most of the time. Lots of subtle errors built up that wouldn't have been caught by any "normal" testing. Also, make the move assignment actually work rather than the bogus swap implementation that would just infloop if used. As part of that, factor out the graph pointer updates into a helper to share between move construction and move assignment. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@206583 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/llvm/Analysis/LazyCallGraph.h b/include/llvm/Analysis/LazyCallGraph.h index bcd06c2a101..66d3d505850 100644 --- a/include/llvm/Analysis/LazyCallGraph.h +++ b/include/llvm/Analysis/LazyCallGraph.h @@ -193,9 +193,6 @@ public: /// CalleeSet. Node(LazyCallGraph &G, Function &F); - /// \brief Constructor used when copying a node from one graph to another. - Node(LazyCallGraph &G, const Node &OtherN); - public: typedef LazyCallGraph::iterator iterator; @@ -291,23 +288,8 @@ public: /// requested during traversal. LazyCallGraph(Module &M); - /// \brief Copy constructor. - /// - /// This does a deep copy of the graph. It does no verification that the - /// graph remains valid for the module. It is also relatively expensive. - LazyCallGraph(const LazyCallGraph &G); - - /// \brief Move constructor. - /// - /// This is a deep move. It leaves G in an undefined but destroyable state. - /// Any other operation on G is likely to fail. LazyCallGraph(LazyCallGraph &&G); - - /// \brief Copy and move assignment. - LazyCallGraph &operator=(LazyCallGraph RHS) { - std::swap(*this, RHS); - return *this; - } + LazyCallGraph &operator=(LazyCallGraph &&RHS); iterator begin() { return iterator(*this, EntryNodes); } iterator end() { return iterator(*this, EntryNodes, iterator::IsAtEndT()); } @@ -378,8 +360,8 @@ private: /// the NodeMap. Node *insertInto(Function &F, Node *&MappedN); - /// \brief Helper to copy a node from another graph into this one. - Node *copyInto(const Node &OtherN); + /// \brief Helper to update pointers back to the graph object during moves. + void updateGraphPtrs(); /// \brief Retrieve the next node in the post-order SCC walk of the call graph. SCC *getNextSCCInPostOrder(); diff --git a/lib/Analysis/LazyCallGraph.cpp b/lib/Analysis/LazyCallGraph.cpp index dd5c7df7848..229e2c93ade 100644 --- a/lib/Analysis/LazyCallGraph.cpp +++ b/lib/Analysis/LazyCallGraph.cpp @@ -65,18 +65,6 @@ LazyCallGraph::Node::Node(LazyCallGraph &G, Function &F) findCallees(Worklist, Visited, Callees, CalleeSet); } -LazyCallGraph::Node::Node(LazyCallGraph &G, const Node &OtherN) - : G(&G), F(OtherN.F), DFSNumber(0), LowLink(0), CalleeSet(OtherN.CalleeSet) { - // Loop over the other node's callees, adding the Function*s to our list - // directly, and recursing to add the Node*s. - Callees.reserve(OtherN.Callees.size()); - for (const auto &OtherCallee : OtherN.Callees) - if (Function *Callee = OtherCallee.dyn_cast()) - Callees.push_back(Callee); - else - Callees.push_back(G.copyInto(*OtherCallee.get())); -} - LazyCallGraph::LazyCallGraph(Module &M) { for (Function &F : M) if (!F.isDeclaration() && !F.hasLocalLinkage()) @@ -100,30 +88,33 @@ LazyCallGraph::LazyCallGraph(Module &M) { SCCEntryNodes.insert(&Entry.get()->getFunction()); } -LazyCallGraph::LazyCallGraph(const LazyCallGraph &G) - : EntryNodeSet(G.EntryNodeSet) { - EntryNodes.reserve(G.EntryNodes.size()); - for (const auto &EntryNode : G.EntryNodes) - if (Function *Callee = EntryNode.dyn_cast()) - EntryNodes.push_back(Callee); - else - EntryNodes.push_back(copyInto(*EntryNode.get())); - - // Just re-populate the SCCEntryNodes structure so we recompute the SCCs if - // needed. - for (auto &Entry : EntryNodes) - if (Function *F = Entry.dyn_cast()) - SCCEntryNodes.insert(F); - else - SCCEntryNodes.insert(&Entry.get()->getFunction()); -} - LazyCallGraph::LazyCallGraph(LazyCallGraph &&G) : BPA(std::move(G.BPA)), EntryNodes(std::move(G.EntryNodes)), EntryNodeSet(std::move(G.EntryNodeSet)), SCCBPA(std::move(G.SCCBPA)), SCCMap(std::move(G.SCCMap)), LeafSCCs(std::move(G.LeafSCCs)), DFSStack(std::move(G.DFSStack)), SCCEntryNodes(std::move(G.SCCEntryNodes)) { + updateGraphPtrs(); +} + +LazyCallGraph &LazyCallGraph::operator=(LazyCallGraph &&G) { + BPA = std::move(G.BPA); + EntryNodes = std::move(G.EntryNodes); + EntryNodeSet = std::move(G.EntryNodeSet); + SCCBPA = std::move(G.SCCBPA); + SCCMap = std::move(G.SCCMap); + LeafSCCs = std::move(G.LeafSCCs); + DFSStack = std::move(G.DFSStack); + SCCEntryNodes = std::move(G.SCCEntryNodes); + updateGraphPtrs(); + return *this; +} + +LazyCallGraph::Node *LazyCallGraph::insertInto(Function &F, Node *&MappedN) { + return new (MappedN = BPA.Allocate()) Node(*this, F); +} + +void LazyCallGraph::updateGraphPtrs() { // Process all nodes updating the graph pointers. SmallVector Worklist; for (auto &Entry : EntryNodes) @@ -139,18 +130,6 @@ LazyCallGraph::LazyCallGraph(LazyCallGraph &&G) } } -LazyCallGraph::Node *LazyCallGraph::insertInto(Function &F, Node *&MappedN) { - return new (MappedN = BPA.Allocate()) Node(*this, F); -} - -LazyCallGraph::Node *LazyCallGraph::copyInto(const Node &OtherN) { - Node *&N = NodeMap[&OtherN.F]; - if (N) - return N; - - return new (N = BPA.Allocate()) Node(*this, OtherN); -} - LazyCallGraph::SCC *LazyCallGraph::getNextSCCInPostOrder() { // When the stack is empty, there are no more SCCs to walk in this graph. if (DFSStack.empty()) {