mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-01-19 04:32:19 +00:00
Use and implement API for graph traversals
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@5431 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
9e4b15b1a1
commit
5c7380e567
@ -13,7 +13,6 @@
|
|||||||
#include "Support/Statistic.h"
|
#include "Support/Statistic.h"
|
||||||
#include "Support/Timer.h"
|
#include "Support/Timer.h"
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <set>
|
|
||||||
|
|
||||||
using std::vector;
|
using std::vector;
|
||||||
|
|
||||||
@ -938,17 +937,27 @@ void DSGraph::removeTriviallyDeadNodes() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// markAlive - Simple graph walker that recursively traverses the graph, marking
|
/// markReachableNodes - This method recursively traverses the specified
|
||||||
// stuff to be alive.
|
/// DSNodes, marking any nodes which are reachable. All reachable nodes it adds
|
||||||
//
|
/// to the set, which allows it to only traverse visited nodes once.
|
||||||
static void markAlive(DSNode *N, std::set<DSNode*> &Alive) {
|
///
|
||||||
if (N == 0) return;
|
void DSNode::markReachableNodes(std::set<DSNode*> &ReachableNodes) {
|
||||||
std::set<DSNode*>::iterator I = Alive.lower_bound(N);
|
if (this == 0) return;
|
||||||
if (I != Alive.end() && *I == N) return; // Already marked alive
|
std::set<DSNode*>::iterator I = ReachableNodes.lower_bound(this);
|
||||||
Alive.insert(I, N); // Is alive now
|
if (I != ReachableNodes.end() && *I == this)
|
||||||
|
return; // Already marked reachable
|
||||||
|
ReachableNodes.insert(I, this); // Is reachable now
|
||||||
|
|
||||||
for (unsigned i = 0, e = N->getSize(); i < e; i += DS::PointerSize)
|
for (unsigned i = 0, e = getSize(); i < e; i += DS::PointerSize)
|
||||||
markAlive(N->getLink(i).getNode(), Alive);
|
getLink(i).getNode()->markReachableNodes(ReachableNodes);
|
||||||
|
}
|
||||||
|
|
||||||
|
void DSCallSite::markReachableNodes(std::set<DSNode*> &Nodes) {
|
||||||
|
getRetVal().getNode()->markReachableNodes(Nodes);
|
||||||
|
getCallee().getNode()->markReachableNodes(Nodes);
|
||||||
|
|
||||||
|
for (unsigned j = 0, e = getNumPtrArgs(); j != e; ++j)
|
||||||
|
getPtrArg(j).getNode()->markReachableNodes(Nodes);
|
||||||
}
|
}
|
||||||
|
|
||||||
// markAliveIfCanReachAlive - Simple graph walker that recursively traverses the
|
// markAliveIfCanReachAlive - Simple graph walker that recursively traverses the
|
||||||
@ -981,7 +990,7 @@ static bool markAliveIfCanReachAlive(DSNode *N, std::set<DSNode*> &Alive,
|
|||||||
ChildrenAreAlive |= markAliveIfCanReachAlive(N->getLink(i).getNode(),
|
ChildrenAreAlive |= markAliveIfCanReachAlive(N->getLink(i).getNode(),
|
||||||
Alive, Visited);
|
Alive, Visited);
|
||||||
if (ChildrenAreAlive)
|
if (ChildrenAreAlive)
|
||||||
markAlive(N, Alive);
|
N->markReachableNodes(Alive);
|
||||||
return ChildrenAreAlive;
|
return ChildrenAreAlive;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -996,14 +1005,6 @@ static bool CallSiteUsesAliveArgs(DSCallSite &CS, std::set<DSNode*> &Alive,
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void markAlive(DSCallSite &CS, std::set<DSNode*> &Alive) {
|
|
||||||
markAlive(CS.getRetVal().getNode(), Alive);
|
|
||||||
markAlive(CS.getCallee().getNode(), Alive);
|
|
||||||
|
|
||||||
for (unsigned j = 0, e = CS.getNumPtrArgs(); j != e; ++j)
|
|
||||||
markAlive(CS.getPtrArg(j).getNode(), Alive);
|
|
||||||
}
|
|
||||||
|
|
||||||
// removeDeadNodes - Use a more powerful reachability analysis to eliminate
|
// removeDeadNodes - Use a more powerful reachability analysis to eliminate
|
||||||
// subgraphs that are unreachable. This often occurs because the data
|
// subgraphs that are unreachable. This often occurs because the data
|
||||||
// structure doesn't "escape" into it's caller, and thus should be eliminated
|
// structure doesn't "escape" into it's caller, and thus should be eliminated
|
||||||
@ -1025,12 +1026,12 @@ void DSGraph::removeDeadNodes(unsigned Flags) {
|
|||||||
E = ScalarMap.end(); I != E; ++I)
|
E = ScalarMap.end(); I != E; ++I)
|
||||||
if (!(Flags & DSGraph::RemoveUnreachableGlobals) ||
|
if (!(Flags & DSGraph::RemoveUnreachableGlobals) ||
|
||||||
!isa<GlobalValue>(I->first)) // Don't mark globals!
|
!isa<GlobalValue>(I->first)) // Don't mark globals!
|
||||||
markAlive(I->second.getNode(), Alive);
|
I->second.getNode()->markReachableNodes(Alive);
|
||||||
else // Keep track of global nodes
|
else // Keep track of global nodes
|
||||||
GlobalNodes.push_back(std::make_pair(I->first, I->second.getNode()));
|
GlobalNodes.push_back(std::make_pair(I->first, I->second.getNode()));
|
||||||
|
|
||||||
// The return value is alive as well...
|
// The return value is alive as well...
|
||||||
markAlive(RetNode.getNode(), Alive);
|
RetNode.getNode()->markReachableNodes(Alive);
|
||||||
|
|
||||||
// If any global nodes points to a non-global that is "alive", the global is
|
// If any global nodes points to a non-global that is "alive", the global is
|
||||||
// "alive" as well...
|
// "alive" as well...
|
||||||
@ -1042,14 +1043,14 @@ void DSGraph::removeDeadNodes(unsigned Flags) {
|
|||||||
std::vector<bool> FCallsAlive(FunctionCalls.size());
|
std::vector<bool> FCallsAlive(FunctionCalls.size());
|
||||||
for (unsigned i = 0, e = FunctionCalls.size(); i != e; ++i)
|
for (unsigned i = 0, e = FunctionCalls.size(); i != e; ++i)
|
||||||
if (CallSiteUsesAliveArgs(FunctionCalls[i], Alive, Visited)) {
|
if (CallSiteUsesAliveArgs(FunctionCalls[i], Alive, Visited)) {
|
||||||
markAlive(FunctionCalls[i], Alive);
|
FunctionCalls[i].markReachableNodes(Alive);
|
||||||
FCallsAlive[i] = true;
|
FCallsAlive[i] = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<bool> AuxFCallsAlive(AuxFunctionCalls.size());
|
std::vector<bool> AuxFCallsAlive(AuxFunctionCalls.size());
|
||||||
for (unsigned i = 0, e = AuxFunctionCalls.size(); i != e; ++i)
|
for (unsigned i = 0, e = AuxFunctionCalls.size(); i != e; ++i)
|
||||||
if (CallSiteUsesAliveArgs(AuxFunctionCalls[i], Alive, Visited)) {
|
if (CallSiteUsesAliveArgs(AuxFunctionCalls[i], Alive, Visited)) {
|
||||||
markAlive(AuxFunctionCalls[i], Alive);
|
AuxFunctionCalls[i].markReachableNodes(Alive);
|
||||||
AuxFCallsAlive[i] = true;
|
AuxFCallsAlive[i] = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user