From: Chris Lattner Date: Thu, 28 Mar 2002 19:33:00 +0000 (+0000) Subject: Implement getEscapingAllocations & getNonEscapingAllocations X-Git-Url: http://plrg.eecs.uci.edu/git/?a=commitdiff_plain;h=4dc1f82e7e8ffe60716a8dbab2f5d8fdb288bced;p=oota-llvm.git Implement getEscapingAllocations & getNonEscapingAllocations git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@2021 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/llvm/Analysis/DataStructure.h b/include/llvm/Analysis/DataStructure.h index 6a048276f1c..3af030d3200 100644 --- a/include/llvm/Analysis/DataStructure.h +++ b/include/llvm/Analysis/DataStructure.h @@ -357,6 +357,8 @@ class FunctionDSGraph { PointerValSet cloneFunctionIntoSelf(const FunctionDSGraph &G, bool ValueMap); bool RemoveUnreachableNodes(); bool UnlinkUndistinguishableNodes(); + void MarkEscapeableNodesReachable(std::vector &RSN, + std::vector &RAN); private: // Define the interface only accessable to DataStructure @@ -375,8 +377,8 @@ public: // void getEscapingAllocations(std::vector &Allocs); - // getEscapingAllocations - Add all allocations that do not escape the current - // function to the specified vector. + // getNonEscapingAllocations - Add all allocations that do not escape the + // current function to the specified vector. // void getNonEscapingAllocations(std::vector &Allocs); diff --git a/include/llvm/Analysis/DataStructure/DataStructure.h b/include/llvm/Analysis/DataStructure/DataStructure.h index 6a048276f1c..3af030d3200 100644 --- a/include/llvm/Analysis/DataStructure/DataStructure.h +++ b/include/llvm/Analysis/DataStructure/DataStructure.h @@ -357,6 +357,8 @@ class FunctionDSGraph { PointerValSet cloneFunctionIntoSelf(const FunctionDSGraph &G, bool ValueMap); bool RemoveUnreachableNodes(); bool UnlinkUndistinguishableNodes(); + void MarkEscapeableNodesReachable(std::vector &RSN, + std::vector &RAN); private: // Define the interface only accessable to DataStructure @@ -375,8 +377,8 @@ public: // void getEscapingAllocations(std::vector &Allocs); - // getEscapingAllocations - Add all allocations that do not escape the current - // function to the specified vector. + // getNonEscapingAllocations - Add all allocations that do not escape the + // current function to the specified vector. // void getNonEscapingAllocations(std::vector &Allocs); diff --git a/lib/Analysis/DataStructure/EliminateNodes.cpp b/lib/Analysis/DataStructure/EliminateNodes.cpp index 471c6281df9..ab94c60d6d8 100644 --- a/lib/Analysis/DataStructure/EliminateNodes.cpp +++ b/lib/Analysis/DataStructure/EliminateNodes.cpp @@ -193,6 +193,34 @@ static void MarkReferredNodesReachable(DSNode *N, AllocNodes, ReachableAllocNodes); } +void FunctionDSGraph::MarkEscapeableNodesReachable( + vector &ReachableShadowNodes, + vector &ReachableAllocNodes) { + // Mark all shadow nodes that have edges from other nodes as reachable. + // Recursively mark any shadow nodes pointed to by the newly live shadow + // nodes as also alive. + // + for (unsigned i = 0, e = ArgNodes.size(); i != e; ++i) + MarkReferredNodesReachable(ArgNodes[i], + ShadowNodes, ReachableShadowNodes, + AllocNodes, ReachableAllocNodes); + + for (unsigned i = 0, e = GlobalNodes.size(); i != e; ++i) + MarkReferredNodesReachable(GlobalNodes[i], + ShadowNodes, ReachableShadowNodes, + AllocNodes, ReachableAllocNodes); + + for (unsigned i = 0, e = CallNodes.size(); i != e; ++i) + MarkReferredNodesReachable(CallNodes[i], + ShadowNodes, ReachableShadowNodes, + AllocNodes, ReachableAllocNodes); + + // Mark all nodes in the return set as being reachable... + MarkReferredNodeSetReachable(RetNode, + ShadowNodes, ReachableShadowNodes, + AllocNodes, ReachableAllocNodes); +} + bool FunctionDSGraph::RemoveUnreachableNodes() { bool Changed = false; @@ -202,30 +230,8 @@ bool FunctionDSGraph::RemoveUnreachableNodes() { // vector ReachableShadowNodes(ShadowNodes.size()); vector ReachableAllocNodes (AllocNodes.size()); - - // Mark all shadow nodes that have edges from other nodes as reachable. - // Recursively mark any shadow nodes pointed to by the newly live shadow - // nodes as also alive. - // - for (unsigned i = 0, e = ArgNodes.size(); i != e; ++i) - MarkReferredNodesReachable(ArgNodes[i], - ShadowNodes, ReachableShadowNodes, - AllocNodes, ReachableAllocNodes); - - for (unsigned i = 0, e = GlobalNodes.size(); i != e; ++i) - MarkReferredNodesReachable(GlobalNodes[i], - ShadowNodes, ReachableShadowNodes, - AllocNodes, ReachableAllocNodes); - - for (unsigned i = 0, e = CallNodes.size(); i != e; ++i) - MarkReferredNodesReachable(CallNodes[i], - ShadowNodes, ReachableShadowNodes, - AllocNodes, ReachableAllocNodes); - - // Mark all nodes in the return set as being reachable... - MarkReferredNodeSetReachable(RetNode, - ShadowNodes, ReachableShadowNodes, - AllocNodes, ReachableAllocNodes); + + MarkEscapeableNodesReachable(ReachableShadowNodes, ReachableAllocNodes); // Mark all nodes in the value map as being reachable... for (std::map::iterator I = ValueMap.begin(), @@ -280,3 +286,34 @@ bool FunctionDSGraph::RemoveUnreachableNodes() { Changed = true; } } + + + + +// getEscapingAllocations - Add all allocations that escape the current +// function to the specified vector. +// +void FunctionDSGraph::getEscapingAllocations(vector &Allocs) { + vector ReachableShadowNodes(ShadowNodes.size()); + vector ReachableAllocNodes (AllocNodes.size()); + + MarkEscapeableNodesReachable(ReachableShadowNodes, ReachableAllocNodes); + + for (unsigned i = 0, e = AllocNodes.size(); i != e; ++i) + if (ReachableAllocNodes[i]) + Allocs.push_back(AllocNodes[i]); +} + +// getNonEscapingAllocations - Add all allocations that do not escape the +// current function to the specified vector. +// +void FunctionDSGraph::getNonEscapingAllocations(vector &Allocs) { + vector ReachableShadowNodes(ShadowNodes.size()); + vector ReachableAllocNodes (AllocNodes.size()); + + MarkEscapeableNodesReachable(ReachableShadowNodes, ReachableAllocNodes); + + for (unsigned i = 0, e = AllocNodes.size(); i != e; ++i) + if (!ReachableAllocNodes[i]) + Allocs.push_back(AllocNodes[i]); +}