summaryrefslogtreecommitdiff
path: root/lib/Analysis
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2004-12-15 07:22:13 +0000
committerChris Lattner <sabre@nondot.org>2004-12-15 07:22:13 +0000
commit0af024c5d00c2a2d0e35ba33f4aaf4ed3fadfae2 (patch)
tree183ccfd2f3d2d48c09beecabf4615b8302797493 /lib/Analysis
parent248e8ebeff834db9b78917b1531eeee7035eb113 (diff)
downloadllvm-0af024c5d00c2a2d0e35ba33f4aaf4ed3fadfae2.tar.gz
llvm-0af024c5d00c2a2d0e35ba33f4aaf4ed3fadfae2.tar.bz2
llvm-0af024c5d00c2a2d0e35ba33f4aaf4ed3fadfae2.tar.xz
Adjust to new alias analysis interfaces
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@18957 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Analysis')
-rw-r--r--lib/Analysis/AliasAnalysis.cpp11
-rw-r--r--lib/Analysis/AliasSetTracker.cpp5
-rw-r--r--lib/Analysis/BasicAliasAnalysis.cpp71
-rw-r--r--lib/Analysis/IPA/GlobalsModRef.cpp18
4 files changed, 48 insertions, 57 deletions
diff --git a/lib/Analysis/AliasAnalysis.cpp b/lib/Analysis/AliasAnalysis.cpp
index a90d80aed5..0f1ce7afb5 100644
--- a/lib/Analysis/AliasAnalysis.cpp
+++ b/lib/Analysis/AliasAnalysis.cpp
@@ -57,14 +57,11 @@ bool AliasAnalysis::pointsToConstantMemory(const Value *P) {
return AA->pointsToConstantMemory(P);
}
-bool AliasAnalysis::doesNotAccessMemory(Function *F) {
+AliasAnalysis::ModRefBehavior
+AliasAnalysis::getModRefBehavior(Function *F, CallSite CS,
+ std::vector<PointerAccessInfo> *Info) {
assert(AA && "AA didn't call InitializeAliasAnalysis in its run method!");
- return AA->doesNotAccessMemory(F);
-}
-
-bool AliasAnalysis::onlyReadsMemory(Function *F) {
- assert(AA && "AA didn't call InitializeAliasAnalysis in its run method!");
- return doesNotAccessMemory(F) || AA->onlyReadsMemory(F);
+ return AA->getModRefBehavior(F, CS, Info);
}
bool AliasAnalysis::hasNoModRefInfoForCalls() const {
diff --git a/lib/Analysis/AliasSetTracker.cpp b/lib/Analysis/AliasSetTracker.cpp
index 85937adb38..8863297b31 100644
--- a/lib/Analysis/AliasSetTracker.cpp
+++ b/lib/Analysis/AliasSetTracker.cpp
@@ -113,9 +113,10 @@ void AliasSet::addCallSite(CallSite CS, AliasAnalysis &AA) {
CallSites.push_back(CS);
if (Function *F = CS.getCalledFunction()) {
- if (AA.doesNotAccessMemory(F))
+ AliasAnalysis::ModRefBehavior Behavior = AA.getModRefBehavior(F, CS);
+ if (Behavior == AliasAnalysis::DoesNotAccessMemory)
return;
- else if (AA.onlyReadsMemory(F)) {
+ else if (Behavior == AliasAnalysis::OnlyReadsMemory) {
AliasTy = MayAlias;
AccessTy |= Refs;
return;
diff --git a/lib/Analysis/BasicAliasAnalysis.cpp b/lib/Analysis/BasicAliasAnalysis.cpp
index c355f59ed0..d11aa7b680 100644
--- a/lib/Analysis/BasicAliasAnalysis.cpp
+++ b/lib/Analysis/BasicAliasAnalysis.cpp
@@ -48,10 +48,17 @@ namespace {
return MayAlias;
}
+ virtual ModRefBehavior getModRefBehavior(Function *F, CallSite CS) {
+ return UnknownModRefBehavior;
+ }
+
+ virtual void getArgumentAccesses(Function *F, CallSite CS,
+ std::vector<PointerAccessInfo> &Info) {
+ assert(0 && "This method may not be called on this function!");
+ }
+
virtual void getMustAliases(Value *P, std::vector<Value*> &RetVals) { }
virtual bool pointsToConstantMemory(const Value *P) { return false; }
- virtual bool doesNotAccessMemory(Function *F) { return false; }
- virtual bool onlyReadsMemory(Function *F) { return false; }
virtual ModRefResult getModRefInfo(CallSite CS, Value *P, unsigned Size) {
return ModRef;
}
@@ -94,9 +101,9 @@ namespace {
/// global) or not.
bool pointsToConstantMemory(const Value *P);
- virtual bool doesNotAccessMemory(Function *F);
- virtual bool onlyReadsMemory(Function *F);
-
+ virtual ModRefBehavior getModRefBehavior(Function *F, CallSite CS,
+ std::vector<PointerAccessInfo> *Info);
+
private:
// CheckGEPInstructions - Check two GEP instructions with known
// must-aliasing base pointers. This checks to see if the index expressions
@@ -683,7 +690,8 @@ namespace {
// that set errno on a domain or other error.
static const char *DoesntAccessMemoryTable[] = {
// LLVM intrinsics:
- "llvm.frameaddress", "llvm.returnaddress", "llvm.readport", "llvm.isunordered",
+ "llvm.frameaddress", "llvm.returnaddress", "llvm.readport",
+ "llvm.isunordered",
"abs", "labs", "llabs", "imaxabs", "fabs", "fabsf", "fabsl",
"trunc", "truncf", "truncl", "ldexp",
@@ -723,29 +731,6 @@ static const char *DoesntAccessMemoryTable[] = {
static const unsigned DAMTableSize =
sizeof(DoesntAccessMemoryTable)/sizeof(DoesntAccessMemoryTable[0]);
-/// doesNotAccessMemory - Return true if we know that the function does not
-/// access memory at all. Since basicaa does no analysis, we can only do simple
-/// things here. In particular, if we have an external function with the name
-/// of a standard C library function, we are allowed to assume it will be
-/// resolved by libc, so we can hardcode some entries in here.
-bool BasicAliasAnalysis::doesNotAccessMemory(Function *F) {
- if (!F->isExternal()) return false;
-
- static bool Initialized = false;
- if (!Initialized) {
- // Sort the table the first time through.
- std::sort(DoesntAccessMemoryTable, DoesntAccessMemoryTable+DAMTableSize,
- StringCompare());
- Initialized = true;
- }
-
- const char **Ptr = std::lower_bound(DoesntAccessMemoryTable,
- DoesntAccessMemoryTable+DAMTableSize,
- F->getName().c_str(), StringCompare());
- return Ptr != DoesntAccessMemoryTable+DAMTableSize && *Ptr == F->getName();
-}
-
-
static const char *OnlyReadsMemoryTable[] = {
"atoi", "atol", "atof", "atoll", "atoq", "a64l",
"bcmp", "memcmp", "memchr", "memrchr", "wmemcmp", "wmemchr",
@@ -772,23 +757,33 @@ static const char *OnlyReadsMemoryTable[] = {
static const unsigned ORMTableSize =
sizeof(OnlyReadsMemoryTable)/sizeof(OnlyReadsMemoryTable[0]);
-
-bool BasicAliasAnalysis::onlyReadsMemory(Function *F) {
- if (doesNotAccessMemory(F)) return true;
- if (!F->isExternal()) return false;
+
+AliasAnalysis::ModRefBehavior
+BasicAliasAnalysis::getModRefBehavior(Function *F, CallSite CS,
+ std::vector<PointerAccessInfo> *Info) {
+ if (!F->isExternal()) return UnknownModRefBehavior;
static bool Initialized = false;
if (!Initialized) {
// Sort the table the first time through.
+ std::sort(DoesntAccessMemoryTable, DoesntAccessMemoryTable+DAMTableSize,
+ StringCompare());
std::sort(OnlyReadsMemoryTable, OnlyReadsMemoryTable+ORMTableSize,
StringCompare());
Initialized = true;
}
- const char **Ptr = std::lower_bound(OnlyReadsMemoryTable,
- OnlyReadsMemoryTable+ORMTableSize,
+ const char **Ptr = std::lower_bound(DoesntAccessMemoryTable,
+ DoesntAccessMemoryTable+DAMTableSize,
F->getName().c_str(), StringCompare());
- return Ptr != OnlyReadsMemoryTable+ORMTableSize && *Ptr == F->getName();
-}
-
+ if (Ptr != DoesntAccessMemoryTable+DAMTableSize && *Ptr == F->getName())
+ return DoesNotAccessMemory;
+
+ Ptr = std::lower_bound(OnlyReadsMemoryTable,
+ OnlyReadsMemoryTable+ORMTableSize,
+ F->getName().c_str(), StringCompare());
+ if (Ptr != OnlyReadsMemoryTable+ORMTableSize && *Ptr == F->getName())
+ return OnlyReadsMemory;
+ return UnknownModRefBehavior;
+}
diff --git a/lib/Analysis/IPA/GlobalsModRef.cpp b/lib/Analysis/IPA/GlobalsModRef.cpp
index dd8bb35419..cde80eec78 100644
--- a/lib/Analysis/IPA/GlobalsModRef.cpp
+++ b/lib/Analysis/IPA/GlobalsModRef.cpp
@@ -101,19 +101,17 @@ namespace {
}
bool hasNoModRefInfoForCalls() const { return false; }
- bool doesNotAccessMemory(Function *F) {
+ /// getModRefBehavior - Return the behavior of the specified function if
+ /// called from the specified call site. The call site may be null in which
+ /// case the most generic behavior of this function should be returned.
+ virtual ModRefBehavior getModRefBehavior(Function *F, CallSite CS) {
if (FunctionRecord *FR = getFunctionInfo(F))
if (FR->FunctionEffect == 0)
- return true;
- return AliasAnalysis::doesNotAccessMemory(F);
+ return DoesNotAccessMemory;
+ else if ((FR->FunctionEffect & Mod) == 0)
+ return OnlyReadsMemory;
+ return AliasAnalysis::getModRefBehavior(F, CS);
}
- bool onlyReadsMemory(Function *F) {
- if (FunctionRecord *FR = getFunctionInfo(F))
- if ((FR->FunctionEffect & Mod) == 0)
- return true;
- return AliasAnalysis::onlyReadsMemory(F);
- }
-
virtual void deleteValue(Value *V);
virtual void copyValue(Value *From, Value *To);