#include "llvm/DerivedTypes.h"
#include "llvm/Target/TargetData.h"
#include "llvm/Assembly/Writer.h"
+#include "Support/Debug.h"
#include "Support/STLExtras.h"
#include "Support/Statistic.h"
#include "Support/Timer.h"
// Define here to avoid including iOther.h and BasicBlock.h in DSGraph.h
Function &DSCallSite::getCaller() const {
- return *Inst->getParent()->getParent();
+ return *Site.getInstruction()->getParent()->getParent();
}
}
if (!(CloneFlags & DontCloneAuxCallNodes)) {
- // Copy the auxillary function calls list...
+ // Copy the auxiliary function calls list...
unsigned FC = AuxFunctionCalls.size(); // FirstCall
AuxFunctionCalls.reserve(FC+G.AuxFunctionCalls.size());
for (unsigned i = 0, ei = G.AuxFunctionCalls.size(); i != ei; ++i)
if (isPointerType(I->getType()))
Args.push_back(getScalarMap().find(I)->second);
- return DSCallSite(*(CallInst*)0, getReturnNodeFor(F), &F, Args);
+ return DSCallSite(CallSite(), getReturnNodeFor(F), &F, Args);
}
// Actually mark the node
N->setIncompleteMarker();
- // Recusively process children...
+ // Recursively process children...
for (unsigned i = 0, e = N->getSize(); i < e; i += DS::PointerSize)
if (DSNode *DSN = N->getLink(i).getNode())
markIncompleteNode(DSN);
// merging...
removeTriviallyDeadNodes();
- // FIXME: Merge nontrivially identical call nodes...
+ // FIXME: Merge non-trivially identical call nodes...
// Alive - a set that holds all nodes found to be reachable/alive.
hash_set<DSNode*> Alive;
GlobalNodeMap.clear();
GlobalsGraph->removeTriviallyDeadNodes();
- // At this point, any nodes which are visited, but not alive, are nodes which
- // should be moved to the globals graph. Loop over all nodes, eliminating
- // completely unreachable nodes, and moving visited nodes to the globals graph
+ // At this point, any nodes which are visited, but not alive, are nodes
+ // which can be removed. Loop over all nodes, eliminating completely
+ // unreachable nodes.
//
std::vector<DSNode*> DeadNodes;
DeadNodes.reserve(Nodes.size());
AssertAuxCallNodesInGraph();
}
+/// mergeInGlobalsGraph - This method is useful for clients to incorporate the
+/// globals graph into the DS, BU or TD graph for a function. This code retains
+/// all globals, i.e., does not delete unreachable globals after they are
+/// inlined.
+///
+void DSGraph::mergeInGlobalsGraph() {
+ NodeMapTy GlobalNodeMap;
+ ScalarMapTy OldValMap;
+ ReturnNodesTy OldRetNodes;
+ cloneInto(*GlobalsGraph, OldValMap, OldRetNodes, GlobalNodeMap,
+ DSGraph::KeepAllocaBit | DSGraph::DontCloneCallNodes |
+ DSGraph::DontCloneAuxCallNodes);
+
+ // Now merge existing global nodes in the GlobalsGraph with their copies
+ for (ScalarMapTy::iterator I = ScalarMap.begin(), E = ScalarMap.end();
+ I != E; ++I)
+ if (isa<GlobalValue>(I->first)) { // Found a global node
+ DSNodeHandle &GH = I->second;
+ DSNodeHandle &GGNodeH = GlobalsGraph->getScalarMap()[I->first];
+ GH.mergeWith(GlobalNodeMap[GGNodeH.getNode()]);
+ }
+
+ // Merging leaves behind unused nodes: get rid of them now.
+ GlobalNodeMap.clear();
+ OldValMap.clear();
+ OldRetNodes.clear();
+ removeTriviallyDeadNodes();
+}