From 82c6c72862198bc2b5b66b9b4b3805e271d8aa6f Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Sun, 20 Mar 2005 02:41:38 +0000 Subject: [PATCH] Implement new methods for dealing with DSNode global lists, rename uses of old methods. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@20707 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Analysis/DataStructure/DataStructure.cpp | 72 +++++++++++++++----- 1 file changed, 56 insertions(+), 16 deletions(-) diff --git a/lib/Analysis/DataStructure/DataStructure.cpp b/lib/Analysis/DataStructure/DataStructure.cpp index 5f8b3bfb918..5cb6af6b194 100644 --- a/lib/Analysis/DataStructure/DataStructure.cpp +++ b/lib/Analysis/DataStructure/DataStructure.cpp @@ -212,6 +212,44 @@ bool DSNode::isNodeCompletelyFolded() const { return getSize() == 1 && Ty == Type::VoidTy && isArray(); } +/// addFullGlobalsList - Compute the full set of global values that are +/// represented by this node. Unlike getGlobalsList(), this requires fair +/// amount of work to compute, so don't treat this method call as free. +void DSNode::addFullGlobalsList(std::vector &List) const { + if (globals_begin() == globals_end()) return; + + EquivalenceClasses &EC = getParentGraph()->getGlobalECs(); + + for (globals_iterator I = globals_begin(), E = globals_end(); I != E; ++I) { + EquivalenceClasses::iterator ECI = EC.findValue(*I); + if (ECI == EC.end()) + List.push_back(*I); + else + List.insert(List.end(), EC.member_begin(ECI), EC.member_end()); + } +} + +/// addFullFunctionList - Identical to addFullGlobalsList, but only return the +/// functions in the full list. +void DSNode::addFullFunctionList(std::vector &List) const { + if (globals_begin() == globals_end()) return; + + EquivalenceClasses &EC = getParentGraph()->getGlobalECs(); + + for (globals_iterator I = globals_begin(), E = globals_end(); I != E; ++I) { + EquivalenceClasses::iterator ECI = EC.findValue(*I); + if (ECI == EC.end()) { + if (Function *F = dyn_cast(*I)) + List.push_back(F); + } else { + for (EquivalenceClasses::member_iterator MI = + EC.member_begin(ECI), E = EC.member_end(); MI != E; ++MI) + if (Function *F = dyn_cast(*MI)) + List.push_back(F); + } + } +} + namespace { /// TypeElementWalker Class - Used for implementation of physical subtyping... /// @@ -822,9 +860,9 @@ DSNodeHandle ReachabilityCloner::getClonedNH(const DSNodeHandle &SrcNH) { // If SrcNH has globals and the destination graph has one of the same globals, // merge this node with the destination node, which is much more efficient. - if (SN->global_begin() != SN->global_end()) { + if (SN->globals_begin() != SN->globals_end()) { DSScalarMap &DestSM = Dest.getScalarMap(); - for (DSNode::global_iterator I = SN->global_begin(), E = SN->global_end(); + for (DSNode::globals_iterator I = SN->globals_begin(),E = SN->globals_end(); I != E; ++I) { GlobalValue *GV = *I; DSScalarMap::iterator GI = DestSM.find(GV); @@ -867,7 +905,7 @@ DSNodeHandle ReachabilityCloner::getClonedNH(const DSNodeHandle &SrcNH) { // If this node contains any globals, make sure they end up in the scalar // map with the correct offset. - for (DSNode::global_iterator I = SN->global_begin(), E = SN->global_end(); + for (DSNode::globals_iterator I = SN->globals_begin(), E = SN->globals_end(); I != E; ++I) { GlobalValue *GV = *I; const DSNodeHandle &SrcGNH = Src.getNodeForValue(GV); @@ -879,7 +917,7 @@ DSNodeHandle ReachabilityCloner::getClonedNH(const DSNodeHandle &SrcNH) { if (CloneFlags & DSGraph::UpdateInlinedGlobals) Dest.getInlinedGlobals().insert(GV); } - NH.getNode()->mergeGlobals(SN->getGlobals()); + NH.getNode()->mergeGlobals(SN->getGlobalsList()); return DSNodeHandle(NH.getNode(), NH.getOffset()+SrcNH.getOffset()); } @@ -953,14 +991,14 @@ void ReachabilityCloner::merge(const DSNodeHandle &NH, // If the source node contains any globals, make sure they end up in the // scalar map with the correct offset. - if (SN->global_begin() != SN->global_end()) { + if (SN->globals_begin() != SN->globals_end()) { // Update the globals in the destination node itself. - DN->mergeGlobals(SN->getGlobals()); + DN->mergeGlobals(SN->getGlobalsList()); // Update the scalar map for the graph we are merging the source node // into. - for (DSNode::global_iterator I = SN->global_begin(), E = SN->global_end(); - I != E; ++I) { + for (DSNode::globals_iterator I = SN->globals_begin(), + E = SN->globals_end(); I != E; ++I) { GlobalValue *GV = *I; const DSNodeHandle &SrcGNH = Src.getNodeForValue(GV); DSNodeHandle &DestGNH = NodeMap[SrcGNH.getNode()]; @@ -971,7 +1009,7 @@ void ReachabilityCloner::merge(const DSNodeHandle &NH, if (CloneFlags & DSGraph::UpdateInlinedGlobals) Dest.getInlinedGlobals().insert(GV); } - NH.getNode()->mergeGlobals(SN->getGlobals()); + NH.getNode()->mergeGlobals(SN->getGlobalsList()); } } else { // We cannot handle this case without allocating a temporary node. Fall @@ -993,8 +1031,8 @@ void ReachabilityCloner::merge(const DSNodeHandle &NH, // If the source node contained any globals, make sure to create entries // in the scalar map for them! - for (DSNode::global_iterator I = SN->global_begin(), E = SN->global_end(); - I != E; ++I) { + for (DSNode::globals_iterator I = SN->globals_begin(), + E = SN->globals_end(); I != E; ++I) { GlobalValue *GV = *I; const DSNodeHandle &SrcGNH = Src.getNodeForValue(GV); DSNodeHandle &DestGNH = NodeMap[SrcGNH.getNode()]; @@ -1542,6 +1580,7 @@ static inline void killIfUselessEdge(DSNodeHandle &Edge) { Edge.setTo(0, 0); // Kill the edge! } +#if 0 static inline bool nodeContainsExternalFunction(const DSNode *N) { const std::vector &Globals = N->getGlobals(); for (unsigned i = 0, e = Globals.size(); i != e; ++i) @@ -1549,6 +1588,7 @@ static inline bool nodeContainsExternalFunction(const DSNode *N) { return true; return false; } +#endif static void removeIdenticalCalls(std::list &Calls) { // Remove trivially identical function calls @@ -1570,7 +1610,7 @@ static void removeIdenticalCalls(std::list &Calls) { // eliminate it. if (CS.isIndirectCall() && CS.getCalleeNode()->getNumReferrers() == 1 && CS.getCalleeNode()->isComplete() && - CS.getCalleeNode()->getGlobals().empty()) { // No useful info? + CS.getCalleeNode()->getGlobalsList().empty()) { // No useful info? #ifndef NDEBUG std::cerr << "WARNING: Useless call site found.\n"; #endif @@ -1733,8 +1773,8 @@ void DSGraph::removeTriviallyDeadNodes() { // have all of these properties and still have incoming edges, due to the // scalar map, so we check those now. // - if (Node.getNumReferrers() == Node.getGlobals().size()) { - const std::vector &Globals = Node.getGlobals(); + if (Node.getNumReferrers() == Node.getGlobalsList().size()) { + const std::vector &Globals = Node.getGlobalsList(); // Loop through and make sure all of the globals are referring directly // to the node... @@ -1996,8 +2036,8 @@ void DSGraph::removeDeadNodes(unsigned Flags) { } void DSGraph::AssertNodeContainsGlobal(const DSNode *N, GlobalValue *GV) const { - assert(std::find(N->getGlobals().begin(), N->getGlobals().end(), GV) != - N->getGlobals().end() && "Global value not in node!"); + assert(std::find(N->globals_begin(),N->globals_end(), GV) != + N->globals_end() && "Global value not in node!"); } void DSGraph::AssertCallSiteInGraph(const DSCallSite &CS) const {