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

Chris Lattner lattner at cs.uiuc.edu
Mon Mar 28 22:09:23 PST 2005



Changes in directory llvm/lib/Analysis/IPA:

Andersens.cpp updated: 1.16 -> 1.17
---
Log message:

Handle "known" external calls context sensitively, add support for realloc
and a couple of other functions that are important.

Handle aggregate undef values for gv initializers


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

 Andersens.cpp |   46 +++++++++++++++++++++++++++++-----------------
 1 files changed, 29 insertions(+), 17 deletions(-)


Index: llvm/lib/Analysis/IPA/Andersens.cpp
diff -u llvm/lib/Analysis/IPA/Andersens.cpp:1.16 llvm/lib/Analysis/IPA/Andersens.cpp:1.17
--- llvm/lib/Analysis/IPA/Andersens.cpp:1.16	Mon Mar 28 00:21:17 2005
+++ llvm/lib/Analysis/IPA/Andersens.cpp	Tue Mar 29 00:09:07 2005
@@ -306,8 +306,8 @@
     void AddGlobalInitializerConstraints(Node *N, Constant *C);
 
     void AddConstraintsForNonInternalLinkage(Function *F);
-    bool AddConstraintsForExternalFunction(Function *F);
     void AddConstraintsForCall(CallSite CS, Function *F);
+    bool AddConstraintsForExternalCall(CallSite CS, Function *F);
 
 
     void PrintNode(Node *N);
@@ -581,7 +581,7 @@
   } else if (C->isNullValue()) {
     N->addPointerTo(&GraphNodes[NullObject]);
     return;
-  } else {
+  } else if (!isa<UndefValue>(C)) {
     // If this is an array or struct, include constraints for each element.
     assert(isa<ConstantArray>(C) || isa<ConstantStruct>(C));
     for (unsigned i = 0, e = C->getNumOperands(); i != e; ++i)
@@ -601,32 +601,41 @@
                                        &GraphNodes[UniversalSet]));
 }
 
-/// AddConstraintsForExternalFunction - If this is a call to a "known" function,
-/// add the constraints and return false.  If this is a call to an unknown
-/// function, return true.
-bool Andersens::AddConstraintsForExternalFunction(Function *F) {
+/// AddConstraintsForCall - If this is a call to a "known" function, add the
+/// constraints and return true.  If this is a call to an unknown function,
+/// return false.
+bool Andersens::AddConstraintsForExternalCall(CallSite CS, Function *F) {
   assert(F->isExternal() && "Not an external function!");
 
   // These functions don't induce any points-to constraints.
   if (F->getName() == "printf" || F->getName() == "fprintf" ||
+      F->getName() == "fgets" ||
       F->getName() == "open" || F->getName() == "fopen" ||
-      F->getName() == "atoi" ||
+      F->getName() == "fclose" || F->getName() == "fflush" ||
+      F->getName() == "atoi" || F->getName() == "sscanf" ||
       F->getName() == "llvm.memset" || F->getName() == "memcmp" ||
       F->getName() == "read" || F->getName() == "write")
-    return false;
+    return true;
 
   // These functions do induce points-to edges.
   if (F->getName() == "llvm.memcpy" || F->getName() == "llvm.memmove") {
-    Function::arg_iterator Dst = F->arg_begin(), Src = Dst;
     // Note: this is a poor approximation, this says Dest = Src, instead of
     // *Dest = *Src.
-    ++Src;
-    Constraints.push_back(Constraint(Constraint::Copy, getNode(Dst),
-                                     getNode(Src)));
-    return false;
+    Constraints.push_back(Constraint(Constraint::Copy,
+                                     getNode(CS.getArgument(0)),
+                                     getNode(CS.getArgument(1))));
+    return true;
   }
 
-  return true;
+  if (F->getName() == "realloc") {
+    // Result = Arg
+    Constraints.push_back(Constraint(Constraint::Copy,
+                                     getNode(CS.getInstruction()),
+                                     getNode(CS.getArgument(0))));
+    return true;
+  }
+
+  return false;
 }
 
 
@@ -689,9 +698,7 @@
       // allocation in the body of the function and a node to represent all
       // pointer values defined by instructions and used as operands.
       visit(F);
-    } else if (AddConstraintsForExternalFunction(F)) {
-      // If we don't "know" about this function, assume the worst.
-
+    } else {
       // External functions that return pointers return the universal set.
       if (isa<PointerType>(F->getFunctionType()->getReturnType()))
         Constraints.push_back(Constraint(Constraint::Copy,
@@ -836,6 +843,11 @@
 /// the function pointer has been casted.  If this is the case, do something
 /// reasonable.
 void Andersens::AddConstraintsForCall(CallSite CS, Function *F) {
+  // If this is a call to an external function, handle it directly to get some
+  // taste of context sensitivity.
+  if (F->isExternal() && AddConstraintsForExternalCall(CS, F))
+    return;
+
   if (isa<PointerType>(CS.getType())) {
     Node *CSN = getNode(CS.getInstruction());
     if (isa<PointerType>(F->getFunctionType()->getReturnType())) {






More information about the llvm-commits mailing list