aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorDan Gohman <gohman@apple.com>2010-11-10 01:02:18 +0000
committerDan Gohman <gohman@apple.com>2010-11-10 01:02:18 +0000
commit42c31a70735e55bf82e66a9315c97d1821c9a798 (patch)
tree4a2913df4ad61547376e9facded78b679229e473 /lib
parentcc8d10e1a8a8555fa63f33e36e3c1ed2fb24389d (diff)
Make ModRefBehavior a lattice. Use this to clean up AliasAnalysis
chaining and simplify FunctionAttrs' GetModRefBehavior logic. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@118660 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r--lib/Analysis/AliasAnalysis.cpp2
-rw-r--r--lib/Analysis/BasicAliasAnalysis.cpp14
-rw-r--r--lib/Analysis/IPA/GlobalsModRef.cpp29
-rw-r--r--lib/Analysis/TypeBasedAliasAnalysis.cpp3
-rw-r--r--lib/Transforms/IPO/FunctionAttrs.cpp75
5 files changed, 60 insertions, 63 deletions
diff --git a/lib/Analysis/AliasAnalysis.cpp b/lib/Analysis/AliasAnalysis.cpp
index 7f9c9c169e..363da9fcee 100644
--- a/lib/Analysis/AliasAnalysis.cpp
+++ b/lib/Analysis/AliasAnalysis.cpp
@@ -179,7 +179,7 @@ AliasAnalysis::getModRefBehavior(ImmutableCallSite CS) {
// Otherwise, fall back to the next AA in the chain. But we can merge
// in any result we've managed to compute.
- return std::min(AA->getModRefBehavior(CS), Min);
+ return ModRefBehavior(AA->getModRefBehavior(CS) & Min);
}
AliasAnalysis::ModRefBehavior
diff --git a/lib/Analysis/BasicAliasAnalysis.cpp b/lib/Analysis/BasicAliasAnalysis.cpp
index 73114fe5aa..bf1b689587 100644
--- a/lib/Analysis/BasicAliasAnalysis.cpp
+++ b/lib/Analysis/BasicAliasAnalysis.cpp
@@ -595,7 +595,7 @@ BasicAliasAnalysis::getModRefBehavior(ImmutableCallSite CS) {
Min = OnlyReadsMemory;
// The AliasAnalysis base class has some smarts, lets use them.
- return std::min(AliasAnalysis::getModRefBehavior(CS), Min);
+ return ModRefBehavior(AliasAnalysis::getModRefBehavior(CS) & Min);
}
/// getModRefBehavior - Return the behavior when calling the given function.
@@ -613,12 +613,14 @@ BasicAliasAnalysis::getModRefBehavior(const Function *F) {
#undef GET_INTRINSIC_MODREF_BEHAVIOR
}
+ ModRefBehavior Min = UnknownModRefBehavior;
+
// If the function declares it only reads memory, go with that.
if (F->onlyReadsMemory())
- return OnlyReadsMemory;
+ Min = OnlyReadsMemory;
// Otherwise be conservative.
- return AliasAnalysis::getModRefBehavior(F);
+ return ModRefBehavior(AliasAnalysis::getModRefBehavior(F) & Min);
}
/// getModRefInfo - Check to see if the specified callsite can clobber the
@@ -671,6 +673,8 @@ BasicAliasAnalysis::getModRefInfo(ImmutableCallSite CS,
return NoModRef;
}
+ ModRefResult Min = ModRef;
+
// Finally, handle specific knowledge of intrinsics.
const IntrinsicInst *II = dyn_cast<IntrinsicInst>(CS.getInstruction());
if (II != 0)
@@ -686,7 +690,7 @@ BasicAliasAnalysis::getModRefInfo(ImmutableCallSite CS,
if (isNoAlias(Location(Dest, Len), Loc)) {
if (isNoAlias(Location(Src, Len), Loc))
return NoModRef;
- return Ref;
+ Min = Ref;
}
break;
}
@@ -745,7 +749,7 @@ BasicAliasAnalysis::getModRefInfo(ImmutableCallSite CS,
}
// The AliasAnalysis base class has some smarts, lets use them.
- return AliasAnalysis::getModRefInfo(CS, Loc);
+ return ModRefResult(AliasAnalysis::getModRefInfo(CS, Loc) & Min);
}
/// aliasGEP - Provide a bunch of ad-hoc rules to disambiguate a GEP instruction
diff --git a/lib/Analysis/IPA/GlobalsModRef.cpp b/lib/Analysis/IPA/GlobalsModRef.cpp
index 6e4fff7b52..456a80a972 100644
--- a/lib/Analysis/IPA/GlobalsModRef.cpp
+++ b/lib/Analysis/IPA/GlobalsModRef.cpp
@@ -120,28 +120,33 @@ namespace {
/// 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.
ModRefBehavior getModRefBehavior(const Function *F) {
+ ModRefBehavior Min = UnknownModRefBehavior;
+
if (FunctionRecord *FR = getFunctionInfo(F)) {
if (FR->FunctionEffect == 0)
- return DoesNotAccessMemory;
+ Min = DoesNotAccessMemory;
else if ((FR->FunctionEffect & Mod) == 0)
- return OnlyReadsMemory;
+ Min = OnlyReadsMemory;
}
- return AliasAnalysis::getModRefBehavior(F);
+
+ return ModRefBehavior(AliasAnalysis::getModRefBehavior(F) & Min);
}
/// 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.
ModRefBehavior getModRefBehavior(ImmutableCallSite CS) {
- const Function* F = CS.getCalledFunction();
- if (!F) return AliasAnalysis::getModRefBehavior(CS);
- if (FunctionRecord *FR = getFunctionInfo(F)) {
- if (FR->FunctionEffect == 0)
- return DoesNotAccessMemory;
- else if ((FR->FunctionEffect & Mod) == 0)
- return OnlyReadsMemory;
- }
- return AliasAnalysis::getModRefBehavior(CS);
+ ModRefBehavior Min = UnknownModRefBehavior;
+
+ if (const Function* F = CS.getCalledFunction())
+ if (FunctionRecord *FR = getFunctionInfo(F)) {
+ if (FR->FunctionEffect == 0)
+ Min = DoesNotAccessMemory;
+ else if ((FR->FunctionEffect & Mod) == 0)
+ Min = OnlyReadsMemory;
+ }
+
+ return ModRefBehavior(AliasAnalysis::getModRefBehavior(CS) & Min);
}
virtual void deleteValue(Value *V);
diff --git a/lib/Analysis/TypeBasedAliasAnalysis.cpp b/lib/Analysis/TypeBasedAliasAnalysis.cpp
index 16ff64e4cf..46c9aa95a9 100644
--- a/lib/Analysis/TypeBasedAliasAnalysis.cpp
+++ b/lib/Analysis/TypeBasedAliasAnalysis.cpp
@@ -256,11 +256,12 @@ TypeBasedAliasAnalysis::getModRefBehavior(ImmutableCallSite CS) {
if (TBAANode(M).TypeIsImmutable())
Min = OnlyReadsMemory;
- return std::min(AliasAnalysis::getModRefBehavior(CS), Min);
+ return ModRefBehavior(AliasAnalysis::getModRefBehavior(CS) & Min);
}
AliasAnalysis::ModRefBehavior
TypeBasedAliasAnalysis::getModRefBehavior(const Function *F) {
+ // Functions don't have metadata. Just chain to the next implementation.
return AliasAnalysis::getModRefBehavior(F);
}
diff --git a/lib/Transforms/IPO/FunctionAttrs.cpp b/lib/Transforms/IPO/FunctionAttrs.cpp
index 8bdf5d75da..3b1b13d378 100644
--- a/lib/Transforms/IPO/FunctionAttrs.cpp
+++ b/lib/Transforms/IPO/FunctionAttrs.cpp
@@ -128,54 +128,41 @@ bool FunctionAttrs::AddReadAttrs(const CallGraphSCC &SCC) {
// Ignore calls to functions in the same SCC.
if (CS.getCalledFunction() && SCCNodes.count(CS.getCalledFunction()))
continue;
- switch (AA->getModRefBehavior(CS)) {
- case AliasAnalysis::DoesNotAccessMemory:
- // Ignore calls that don't access memory.
- continue;
- case AliasAnalysis::OnlyReadsMemory:
- // Handle calls that only read from memory.
- ReadsMemory = true;
- continue;
- case AliasAnalysis::AccessesArguments:
- // Check whether all pointer arguments point to local memory, and
- // ignore calls that only access local memory.
- for (CallSite::arg_iterator CI = CS.arg_begin(), CE = CS.arg_end();
- CI != CE; ++CI) {
- Value *Arg = *CI;
- if (Arg->getType()->isPointerTy()) {
- AliasAnalysis::Location Loc(Arg,
- AliasAnalysis::UnknownSize,
- I->getMetadata(LLVMContext::MD_tbaa));
- if (!AA->pointsToConstantMemory(Loc, /*OrLocal=*/true))
- // Writes memory. Just give up.
- return false;
- }
- }
- // Only reads and writes local memory.
- continue;
- case AliasAnalysis::AccessesArgumentsReadonly:
- // Check whether all pointer arguments point to local memory, and
- // ignore calls that only access local memory.
- for (CallSite::arg_iterator CI = CS.arg_begin(), CE = CS.arg_end();
- CI != CE; ++CI) {
- Value *Arg = *CI;
- if (Arg->getType()->isPointerTy()) {
- AliasAnalysis::Location Loc(Arg,
- AliasAnalysis::UnknownSize,
- I->getMetadata(LLVMContext::MD_tbaa));
- if (!AA->pointsToConstantMemory(Loc, /*OrLocal=*/true)) {
- // Reads non-local memory.
- ReadsMemory = true;
- break;
+ AliasAnalysis::ModRefBehavior MRB = AA->getModRefBehavior(CS);
+ // If the call doesn't access arbitrary memory, we may be able to
+ // figure out something.
+ if (!(MRB & AliasAnalysis::Anywhere &
+ ~AliasAnalysis::ArgumentPointees)) {
+ // If the call accesses argument pointees, check each argument.
+ if (MRB & AliasAnalysis::AccessesArguments)
+ // Check whether all pointer arguments point to local memory, and
+ // ignore calls that only access local memory.
+ for (CallSite::arg_iterator CI = CS.arg_begin(), CE = CS.arg_end();
+ CI != CE; ++CI) {
+ Value *Arg = *CI;
+ if (Arg->getType()->isPointerTy()) {
+ AliasAnalysis::Location Loc(Arg,
+ AliasAnalysis::UnknownSize,
+ I->getMetadata(LLVMContext::MD_tbaa));
+ if (!AA->pointsToConstantMemory(Loc, /*OrLocal=*/true)) {
+ if (MRB & AliasAnalysis::Mod)
+ // Writes non-local memory. Give up.
+ return false;
+ if (MRB & AliasAnalysis::Ref)
+ // Ok, it reads non-local memory.
+ ReadsMemory = true;
+ }
}
}
- }
- // Only reads memory.
continue;
- default:
- // Otherwise, be conservative.
- break;
}
+ // The call could access any memory. If that includes writes, give up.
+ if (MRB & AliasAnalysis::Mod)
+ return false;
+ // If it reads, note it.
+ if (MRB & AliasAnalysis::Ref)
+ ReadsMemory = true;
+ continue;
} else if (LoadInst *LI = dyn_cast<LoadInst>(I)) {
// Ignore non-volatile loads from local memory.
if (!LI->isVolatile()) {