Added a first-class representation for each call site that can be
used in the DS graphs. Essentially, what was vector<DSNodeHandle>
before is now a DSCallSite with the same vector, plus pointers to the
CallInst and the caller Function. The special-purpose class
BUDataStructure::CallSite is no longer needed.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@4228 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Analysis/DataStructure/DataStructure.cpp b/lib/Analysis/DataStructure/DataStructure.cpp
index e7e4010..ecfed8d 100644
--- a/lib/Analysis/DataStructure/DataStructure.cpp
+++ b/lib/Analysis/DataStructure/DataStructure.cpp
@@ -351,6 +351,21 @@
}
}
+
+template<typename _CopierFunction>
+DSCallSite::DSCallSite(const DSCallSite& FromCall,
+ _CopierFunction nodeCopier)
+ : std::vector<DSNodeHandle>(),
+ caller(&FromCall.getCaller()),
+ callInst(&FromCall.getCallInst()) {
+
+ reserve(FromCall.size());
+ for (unsigned j = 0, ej = FromCall.size(); j != ej; ++j)
+ push_back((&nodeCopier == (_CopierFunction*) 0)? DSNodeHandle(FromCall[j])
+ : nodeCopier(&FromCall[j]));
+}
+
+
//===----------------------------------------------------------------------===//
// DSGraph Implementation
//===----------------------------------------------------------------------===//
@@ -378,23 +393,22 @@
// dump - Allow inspection of graph in a debugger.
void DSGraph::dump() const { print(std::cerr); }
-// Helper function used to clone a function list.
-//
-static void CopyFunctionCallsList(const vector<vector<DSNodeHandle> >&fromCalls,
- vector<vector<DSNodeHandle> > &toCalls,
- std::map<const DSNode*, DSNode*> &NodeMap) {
+DSNodeHandle copyHelper(const DSNodeHandle* fromNode,
+ std::map<const DSNode*, DSNode*> *NodeMap) {
+ return DSNodeHandle((*NodeMap)[fromNode->getNode()], fromNode->getOffset());
+}
+
+// Helper function used to clone a function list.
+//
+static void CopyFunctionCallsList(const vector<DSCallSite>& fromCalls,
+ vector<DSCallSite> &toCalls,
+ std::map<const DSNode*, DSNode*> &NodeMap) {
unsigned FC = toCalls.size(); // FirstCall
toCalls.reserve(FC+fromCalls.size());
- for (unsigned i = 0, ei = fromCalls.size(); i != ei; ++i) {
- toCalls.push_back(vector<DSNodeHandle>());
-
- const vector<DSNodeHandle> &CurCall = fromCalls[i];
- toCalls.back().reserve(CurCall.size());
- for (unsigned j = 0, ej = fromCalls[i].size(); j != ej; ++j)
- toCalls[FC+i].push_back(DSNodeHandle(NodeMap[CurCall[j].getNode()],
- CurCall[j].getOffset()));
- }
+ for (unsigned i = 0, ei = fromCalls.size(); i != ei; ++i)
+ toCalls.push_back(DSCallSite(fromCalls[i],
+ std::bind2nd(std::ptr_fun(©Helper), &NodeMap)));
}
/// remapLinks - Change all of the Links in the current node according to the
@@ -404,6 +418,7 @@
Links[i].setNode(OldNodeMap[Links[i].getNode()]);
}
+
// cloneInto - Clone the specified DSGraph into the current graph, returning the
// Return node of the graph. The translated ValueMap for the old function is
// filled into the OldValMap member. If StripLocals is set to true, Scalar and
@@ -532,9 +547,9 @@
// Mark stuff passed into functions calls as being incomplete...
for (unsigned i = 0, e = FunctionCalls.size(); i != e; ++i) {
- vector<DSNodeHandle> &Args = FunctionCalls[i];
+ DSCallSite &Args = FunctionCalls[i];
// Then the return value is certainly incomplete!
- markIncompleteNode(Args[0].getNode());
+ markIncompleteNode(Args.getReturnValueNode().getNode());
// The call does not make the function argument incomplete...
@@ -590,7 +605,7 @@
return false;
}
-static void removeIdenticalCalls(vector<vector<DSNodeHandle> > &Calls,
+static void removeIdenticalCalls(vector<DSCallSite> &Calls,
const std::string &where) {
// Remove trivially identical function calls
unsigned NumFns = Calls.size();
@@ -665,7 +680,7 @@
// the simple iterative loop in the first few lines below suffice.
//
static void markGlobalsIteration(std::set<DSNode*>& GlobalNodes,
- vector<vector<DSNodeHandle> > &Calls,
+ vector<DSCallSite> &Calls,
std::set<DSNode*> &Alive,
bool FilterCalls) {
@@ -723,7 +738,7 @@
GlobalNodes.insert(G.getNodes()[i]);
// Add all call nodes to the same set
- vector<vector<DSNodeHandle> > &Calls = G.getFunctionCalls();
+ vector<DSCallSite> &Calls = G.getFunctionCalls();
if (FilterCalls) {
for (unsigned i = 0, e = Calls.size(); i != e; ++i)
for (unsigned j = 0, e = Calls[i].size(); j != e; ++j)
@@ -963,15 +978,15 @@
//
void GlobalDSGraph::cloneCalls(DSGraph& Graph) {
std::map<const DSNode*, DSNode*> NodeCache;
- vector<vector<DSNodeHandle> >& FromCalls =Graph.FunctionCalls;
+ vector<DSCallSite >& FromCalls =Graph.FunctionCalls;
FunctionCalls.reserve(FunctionCalls.size() + FromCalls.size());
for (int i = 0, ei = FromCalls.size(); i < ei; ++i) {
- FunctionCalls.push_back(vector<DSNodeHandle>());
- FunctionCalls.back().reserve(FromCalls[i].size());
+ DSCallSite& callCopy = FunctionCalls.back();
+ callCopy.reserve(FromCalls[i].size());
for (unsigned j = 0, ej = FromCalls[i].size(); j != ej; ++j)
- FunctionCalls.back().push_back
+ callCopy.push_back
((FromCalls[i][j] && (FromCalls[i][j]->NodeType & ExternalTypeBits))
? cloneNodeInto(FromCalls[i][j], NodeCache, true)
: 0);