[llvm-commits] CVS: llvm/lib/Analysis/DataStructure/DataStructure.cpp

Chris Lattner lattner at cs.uiuc.edu
Thu Feb 3 10:40:38 PST 2005



Changes in directory llvm/lib/Analysis/DataStructure:

DataStructure.cpp updated: 1.188 -> 1.189
---
Log message:

Refactor getFunctionArgumentsForCall out of mergeInGraph.


---
Diffs of the changes:  (+41 -29)

 DataStructure.cpp |   70 +++++++++++++++++++++++++++++++-----------------------
 1 files changed, 41 insertions(+), 29 deletions(-)


Index: llvm/lib/Analysis/DataStructure/DataStructure.cpp
diff -u llvm/lib/Analysis/DataStructure/DataStructure.cpp:1.188 llvm/lib/Analysis/DataStructure/DataStructure.cpp:1.189
--- llvm/lib/Analysis/DataStructure/DataStructure.cpp:1.188	Sun Jan 30 18:10:58 2005
+++ llvm/lib/Analysis/DataStructure/DataStructure.cpp	Thu Feb  3 12:40:25 2005
@@ -1242,6 +1242,21 @@
   return false;
 }
 
+/// getFunctionArgumentsForCall - Given a function that is currently in this
+/// graph, return the DSNodeHandles that correspond to the pointer-compatible
+/// function arguments.  The vector is filled in with the return value (or
+/// null if it is not pointer compatible), followed by all of the
+/// pointer-compatible arguments.
+void DSGraph::getFunctionArgumentsForCall(Function *F,
+                                       std::vector<DSNodeHandle> &Args) const {
+  Args.push_back(getReturnNodeFor(*F));
+  for (Function::aiterator AI = F->abegin(), E = F->aend(); AI != E; ++AI)
+    if (isPointerType(AI->getType())) {
+      Args.push_back(getNodeForValue(AI));
+      assert(!Args.back().isNull() && "Pointer argument w/o scalarmap entry!?");
+    }
+}
+
 /// mergeInGraph - The method is used for merging graphs together.  If the
 /// argument graph is not *this, it makes a clone of the specified graph, then
 /// merges the nodes specified in the call site with the formal arguments in the
@@ -1262,27 +1277,28 @@
     // nodes of the old graph.
     ReachabilityCloner RC(*this, Graph, CloneFlags);
     
-    // Set up argument bindings
-    Function::aiterator AI = F.abegin();
-    for (unsigned i = 0, e = CS.getNumPtrArgs(); i != e; ++i, ++AI) {
-      // Advance the argument iterator to the first pointer argument...
-      while (AI != F.aend() && !isPointerType(AI->getType())) {
-        ++AI;
+    // Set up argument bindings.
+    std::vector<DSNodeHandle> Args;
+    Graph.getFunctionArgumentsForCall(&F, Args);
+
+    // Map the return node pointer over.
+    if (!CS.getRetVal().isNull())
+      RC.merge(CS.getRetVal(), Args[0]);
+
+    // Map over all of the arguments.
+    for (unsigned i = 0, e = CS.getNumPtrArgs(); i != e; ++i) {
+      if (i == Args.size()-1) {
 #ifndef NDEBUG  // FIXME: We should merge vararg arguments!
-        if (AI == F.aend() && !F.getFunctionType()->isVarArg())
+        if (!F.getFunctionType()->isVarArg())
           std::cerr << "Bad call to Function: " << F.getName() << "\n";
 #endif
+        break;
       }
-      if (AI == F.aend()) break;
       
       // Add the link from the argument scalar to the provided value.
-      RC.merge(CS.getPtrArg(i), Graph.getNodeForValue(AI));
+      RC.merge(CS.getPtrArg(i), Args[i+1]);
     }
     
-    // Map the return node pointer over.
-    if (!CS.getRetVal().isNull())
-      RC.merge(CS.getRetVal(), Graph.getReturnNodeFor(F));
-
     // If requested, copy all of the calls.
     if (!(CloneFlags & DontCloneCallNodes)) {
       // Copy the function calls list.
@@ -1341,29 +1357,25 @@
     }
     
   } else {
-    DSNodeHandle RetVal = getReturnNodeFor(F);
+    // Set up argument bindings.
+    std::vector<DSNodeHandle> Args;
+    Graph.getFunctionArgumentsForCall(&F, Args);
 
-    // Merge the return value with the return value of the context...
-    RetVal.mergeWith(CS.getRetVal());
-    
-    // Resolve all of the function arguments...
-    Function::aiterator AI = F.abegin();
+    // Merge the return value with the return value of the context.
+    Args[0].mergeWith(CS.getRetVal());
     
-    for (unsigned i = 0, e = CS.getNumPtrArgs(); i != e; ++i, ++AI) {
-      // Advance the argument iterator to the first pointer argument...
-      while (AI != F.aend() && !isPointerType(AI->getType())) {
-        ++AI;
+    // Resolve all of the function arguments.
+    for (unsigned i = 0, e = CS.getNumPtrArgs(); i != e; ++i) {
+      if (i == Args.size()-1) {
 #ifndef NDEBUG // FIXME: We should merge varargs arguments!!
-        if (AI == F.aend() && !F.getFunctionType()->isVarArg())
+        if (!F.getFunctionType()->isVarArg())
           std::cerr << "Bad call to Function: " << F.getName() << "\n";
 #endif
+        break;
       }
-      if (AI == F.aend()) break;
       
-      // Add the link from the argument scalar to the provided value
-      DSNodeHandle &NH = getNodeForValue(AI);
-      assert(!NH.isNull() && "Pointer argument without scalarmap entry?");
-      NH.mergeWith(CS.getPtrArg(i));
+      // Add the link from the argument scalar to the provided value.
+      Args[i+1].mergeWith(CS.getPtrArg(i));
     }
   }
 }






More information about the llvm-commits mailing list