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
This commit is contained in:
Dan Gohman
2010-11-10 01:02:18 +00:00
parent cc8d10e1a8
commit 42c31a7073
8 changed files with 71 additions and 74 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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);

View File

@@ -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);
}