aboutsummaryrefslogtreecommitdiff
path: root/lib/Analysis/DataStructure/Steensgaard.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2005-03-26 22:43:20 +0000
committerChris Lattner <sabre@nondot.org>2005-03-26 22:43:20 +0000
commitb7523418b097fddd6afae64eb057753d7e8f1166 (patch)
treeba411c70f9a9c39849e1790c1915540ee7c45bfd /lib/Analysis/DataStructure/Steensgaard.cpp
parent0772e78789124ca8b747bdc6f9756a5e944bc8f3 (diff)
Teach steens-aa two things about mod/ref information:
1. If memory never escapes the program, it cannot be mod/ref'd by external functions. 2. If memory is global never mod/ref'd in the program, it cannot be mod/ref'd by any call. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@20867 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Analysis/DataStructure/Steensgaard.cpp')
-rw-r--r--lib/Analysis/DataStructure/Steensgaard.cpp36
1 files changed, 33 insertions, 3 deletions
diff --git a/lib/Analysis/DataStructure/Steensgaard.cpp b/lib/Analysis/DataStructure/Steensgaard.cpp
index 0a62fdb486..0d63c645a0 100644
--- a/lib/Analysis/DataStructure/Steensgaard.cpp
+++ b/lib/Analysis/DataStructure/Steensgaard.cpp
@@ -62,10 +62,11 @@ namespace {
// Implement the AliasAnalysis API
//
- // alias - This is the only method here that does anything interesting...
AliasResult alias(const Value *V1, unsigned V1Size,
const Value *V2, unsigned V2Size);
-
+
+ ModRefResult getModRefInfo(CallSite CS, Value *P, unsigned Size);
+
private:
void ResolveFunctionCall(Function *F, const DSCallSite &Call,
DSNodeHandle &RetVal);
@@ -183,7 +184,6 @@ bool Steens::runOnModule(Module &M) {
return false;
}
-// alias - This is the only method here that does anything interesting...
AliasAnalysis::AliasResult Steens::alias(const Value *V1, unsigned V1Size,
const Value *V2, unsigned V2Size) {
assert(ResultGraph && "Result graph has not been computed yet!");
@@ -224,3 +224,33 @@ AliasAnalysis::AliasResult Steens::alias(const Value *V1, unsigned V1Size,
//
return AliasAnalysis::alias(V1, V1Size, V2, V2Size);
}
+
+AliasAnalysis::ModRefResult
+Steens::getModRefInfo(CallSite CS, Value *P, unsigned Size) {
+ AliasAnalysis::ModRefResult Result = ModRef;
+
+ // Find the node in question.
+ DSGraph::ScalarMapTy &GSM = ResultGraph->getScalarMap();
+ DSGraph::ScalarMapTy::iterator I = GSM.find(P);
+
+ if (I != GSM.end() && !I->second.isNull()) {
+ DSNode *N = I->second.getNode();
+ if (N->isComplete()) {
+ // If this is a direct call to an external function, and if the pointer
+ // points to a complete node, the external function cannot modify or read
+ // the value (we know it's not passed out of the program!).
+ if (Function *F = CS.getCalledFunction())
+ if (F->isExternal())
+ return NoModRef;
+
+ // Otherwise, if the node is complete, but it is only M or R, return this.
+ // This can be useful for globals that should be marked const but are not.
+ if (!N->isModified())
+ Result = (ModRefResult)(Result & ~Mod);
+ if (!N->isRead())
+ Result = (ModRefResult)(Result & ~Ref);
+ }
+ }
+
+ return (ModRefResult)(Result & AliasAnalysis::getModRefInfo(CS, P, Size));
+}