[llvm-commits] CVS: llvm/lib/Analysis/IPA/Andersens.cpp
Chris Lattner
lattner at cs.uiuc.edu
Sun Mar 27 20:04:08 PST 2005
Changes in directory llvm/lib/Analysis/IPA:
Andersens.cpp updated: 1.13 -> 1.14
---
Log message:
Make anders-aa much more precise by not being completely pessimistic about
external functions. Teach it about a few important ones.
---
Diffs of the changes: (+39 -1)
Andersens.cpp | 40 +++++++++++++++++++++++++++++++++++++++-
1 files changed, 39 insertions(+), 1 deletion(-)
Index: llvm/lib/Analysis/IPA/Andersens.cpp
diff -u llvm/lib/Analysis/IPA/Andersens.cpp:1.13 llvm/lib/Analysis/IPA/Andersens.cpp:1.14
--- llvm/lib/Analysis/IPA/Andersens.cpp:1.13 Sun Mar 27 16:03:46 2005
+++ llvm/lib/Analysis/IPA/Andersens.cpp Sun Mar 27 22:03:52 2005
@@ -92,6 +92,7 @@
}
/// getValue - Return the LLVM value corresponding to this node.
+ ///
Value *getValue() const { return Val; }
typedef std::vector<Node*>::const_iterator iterator;
@@ -302,7 +303,9 @@
Node *getNodeForConstantPointer(Constant *C);
Node *getNodeForConstantPointerTarget(Constant *C);
void AddGlobalInitializerConstraints(Node *N, Constant *C);
+
void AddConstraintsForNonInternalLinkage(Function *F);
+ bool AddConstraintsForExternalFunction(Function *F);
void AddConstraintsForCall(CallSite CS, Function *F);
@@ -354,6 +357,7 @@
return AliasAnalysis::alias(V1, V1Size, V2, V2Size);
}
+
/// getMustAlias - We can provide must alias information if we know that a
/// pointer can only point to a specific function or the null pointer.
/// Unfortunately we cannot determine must-alias information for global
@@ -551,6 +555,9 @@
}
}
+/// AddConstraintsForNonInternalLinkage - If this function does not have
+/// internal linkage, realize that we can't trust anything passed into or
+/// returned by this function.
void Andersens::AddConstraintsForNonInternalLinkage(Function *F) {
for (Function::arg_iterator I = F->arg_begin(), E = F->arg_end(); I != E; ++I)
if (isa<PointerType>(I->getType()))
@@ -560,6 +567,35 @@
&GraphNodes[UniversalSet]));
}
+/// AddConstraintsForExternalFunction - If this is a call to a "known" function,
+/// add the constraints an return false. If this is a call to an unknown
+/// function, return true.
+bool Andersens::AddConstraintsForExternalFunction(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() == "open" || F->getName() == "fopen" ||
+ F->getName() == "atoi" ||
+ F->getName() == "llvm.memset" || F->getName() == "memcmp" ||
+ F->getName() == "read" || F->getName() == "write")
+ return false;
+
+ // 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;
+ }
+
+ return true;
+}
+
+
/// CollectConstraints - This stage scans the program, adding a constraint to
/// the Constraints list for each instruction in the program that induces a
@@ -615,7 +651,9 @@
// 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 {
+ } else if (AddConstraintsForExternalFunction(F)) {
+ // If we don't "know" about this function, assume the worst.
+
// External functions that return pointers return the universal set.
if (isa<PointerType>(F->getFunctionType()->getReturnType()))
Constraints.push_back(Constraint(Constraint::Copy,
More information about the llvm-commits
mailing list