The two-callsite form of AliasAnalysis::getModRefInfo is documented

to return Ref if the left callsite only reads memory read or written
by the right callsite; fix BasicAliasAnalysis to implement this.

Add AliasAnalysisEvaluator support for testing the two-callsite
form of getModRefInfo.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@110270 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Dan Gohman 2010-08-04 22:56:29 +00:00
parent abf7bdffd6
commit 3dcc91ee8c
4 changed files with 50 additions and 6 deletions

View File

@ -107,6 +107,15 @@ PrintModRefResults(const char *Msg, bool P, Instruction *I, Value *Ptr,
}
}
static inline void
PrintModRefResults(const char *Msg, bool P, CallSite CSA, CallSite CSB,
Module *M) {
if (P) {
errs() << " " << Msg << ": " << *CSA.getInstruction()
<< " <-> " << *CSB.getInstruction() << '\n';
}
}
static inline bool isInterestingPointer(Value *V) {
return V->getType()->isPointerTy()
&& !isa<ConstantPointerNull>(V);
@ -209,6 +218,29 @@ bool AAEval::runOnFunction(Function &F) {
}
}
// Mod/ref alias analysis: compare all pairs of calls
for (SetVector<CallSite>::iterator C = CallSites.begin(),
Ce = CallSites.end(); C != Ce; ++C) {
for (SetVector<CallSite>::iterator D = CallSites.begin(); D != Ce; ++D) {
if (D == C)
continue;
switch (AA.getModRefInfo(*C, *D)) {
case AliasAnalysis::NoModRef:
PrintModRefResults("NoModRef", PrintNoModRef, *C, *D, F.getParent());
++NoModRef; break;
case AliasAnalysis::Mod:
PrintModRefResults(" Mod", PrintMod, *C, *D, F.getParent());
++Mod; break;
case AliasAnalysis::Ref:
PrintModRefResults(" Ref", PrintRef, *C, *D, F.getParent());
++Ref; break;
case AliasAnalysis::ModRef:
PrintModRefResults(" ModRef", PrintModRef, *C, *D, F.getParent());
++ModRef; break;
}
}
}
return false;
}

View File

@ -425,8 +425,8 @@ BasicAliasAnalysis::getModRefInfo(ImmutableCallSite CS1,
ModRefBehavior CS2B = AliasAnalysis::getModRefBehavior(CS2);
if (CS2B == DoesNotAccessMemory) return NoModRef;
// If they both only read from memory, just return ref.
if (CS1B == OnlyReadsMemory && CS2B == OnlyReadsMemory)
// If CS1 only reads from memory, just return ref.
if (CS1B == OnlyReadsMemory)
return Ref;
// Otherwise, fall back to NoAA (mod+ref).

View File

@ -302,9 +302,9 @@ define void @caller_a(double* %arg_a0,
; CHECK: 36 may alias responses (30.0%)
; CHECK: 0 must alias responses (0.0%)
; CHECK: Alias Analysis Evaluator Pointer Alias Summary: 70%/30%/0%
; CHECK: 128 Total ModRef Queries Performed
; CHECK: 44 no mod/ref responses (34.3%)
; CHECK: 184 Total ModRef Queries Performed
; CHECK: 44 no mod/ref responses (23.9%)
; CHECK: 0 mod responses (0.0%)
; CHECK: 0 ref responses (0.0%)
; CHECK: 84 mod & ref responses (65.6%)
; CHECK: Alias Analysis Evaluator Mod/Ref Summary: 34%/0%/0%/65%
; CHECK: 140 mod & ref responses (76.0%)
; CHECK: Alias Analysis Evaluator Mod/Ref Summary: 23%/0%/0%/76%

View File

@ -0,0 +1,12 @@
; RUN: opt < %s -aa-eval -print-all-alias-modref-info -disable-output |& FileCheck %s
; CHECK: {{[[:<:]]}}Ref: call void @ro() <-> call void @f0()
declare void @f0()
declare void @ro() readonly
define void @test() {
call void @f0()
call void @ro()
ret void
}