Skip to content

Commit 5f0e76d

Browse files
committedAug 1, 2016
[CFLAA] Remove modref queries from CFLAA.
As it turns out, modref queries are broken with CFLAA. Specifically, the data source we were using for determining modref behaviors explicitly ignores operations on non-pointer values. So, it wouldn't note e.g. storing an i32 to an i32* (or loading an i64 from an i64*). It also ignores external function calls, rather than acting conservatively for them. (N.B. These operations, where necessary, *are* tracked by CFLAA; we just use a different mechanism to do so. Said mechanism is relatively imprecise, so it's unlikely that we can provide reasonably good modref answers with it as implemented.) Patch by Jia Chen. Differential Revision: https://reviews.llvm.org/D22978 llvm-svn: 277366
1 parent ec133b3 commit 5f0e76d

11 files changed

+26
-227
lines changed
 

‎llvm/include/llvm/Analysis/CFLAndersAliasAnalysis.h

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -53,16 +53,6 @@ class CFLAndersAAResult : public AAResultBase<CFLAndersAAResult> {
5353
AliasResult query(const MemoryLocation &, const MemoryLocation &);
5454
AliasResult alias(const MemoryLocation &, const MemoryLocation &);
5555

56-
/// Get the location associated with a pointer argument of a callsite.
57-
ModRefInfo getArgModRefInfo(ImmutableCallSite CS, unsigned ArgIdx);
58-
59-
/// Returns the behavior when calling the given call site.
60-
FunctionModRefBehavior getModRefBehavior(ImmutableCallSite CS);
61-
62-
/// Returns the behavior when calling the given function. For use when the
63-
/// call site is not known.
64-
FunctionModRefBehavior getModRefBehavior(const Function *F);
65-
6656
private:
6757
struct FunctionHandle final : public CallbackVH {
6858
FunctionHandle(Function *Fn, CFLAndersAAResult *Result)

‎llvm/include/llvm/Analysis/CFLSteensAliasAnalysis.h

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -81,16 +81,6 @@ class CFLSteensAAResult : public AAResultBase<CFLSteensAAResult> {
8181
return QueryResult;
8282
}
8383

84-
/// Get the location associated with a pointer argument of a callsite.
85-
ModRefInfo getArgModRefInfo(ImmutableCallSite CS, unsigned ArgIdx);
86-
87-
/// Returns the behavior when calling the given call site.
88-
FunctionModRefBehavior getModRefBehavior(ImmutableCallSite CS);
89-
90-
/// Returns the behavior when calling the given function. For use when the
91-
/// call site is not known.
92-
FunctionModRefBehavior getModRefBehavior(const Function *F);
93-
9484
private:
9585
struct FunctionHandle final : public CallbackVH {
9686
FunctionHandle(Function *Fn, CFLSteensAAResult *Result)

‎llvm/lib/Analysis/CFLAndersAliasAnalysis.cpp

Lines changed: 0 additions & 106 deletions
Original file line numberDiff line numberDiff line change
@@ -862,112 +862,6 @@ AliasResult CFLAndersAAResult::alias(const MemoryLocation &LocA,
862862
return QueryResult;
863863
}
864864

865-
ModRefInfo CFLAndersAAResult::getArgModRefInfo(ImmutableCallSite CS,
866-
unsigned ArgIdx) {
867-
if (auto CalledFunc = CS.getCalledFunction()) {
868-
if (!CalledFunc->hasExactDefinition())
869-
return MRI_ModRef;
870-
871-
auto &MaybeInfo = ensureCached(*CalledFunc);
872-
if (!MaybeInfo.hasValue())
873-
return MRI_ModRef;
874-
auto &RetParamAttributes = MaybeInfo->getAliasSummary().RetParamAttributes;
875-
auto &RetParamRelations = MaybeInfo->getAliasSummary().RetParamRelations;
876-
877-
bool ArgAttributeIsWritten =
878-
any_of(RetParamAttributes, [ArgIdx](const ExternalAttribute &ExtAttr) {
879-
return ExtAttr.IValue.Index == ArgIdx + 1;
880-
});
881-
882-
// If the argument is unknown, escaped, or alias global, be conservative.
883-
// FIXME: Do we really need to be conservative for AttrGlobal?
884-
if (ArgAttributeIsWritten)
885-
return MRI_ModRef;
886-
887-
bool ArgIsRead = any_of(RetParamRelations,
888-
[ArgIdx](const ExternalRelation &ExtRelation) {
889-
return ExtRelation.From.Index == ArgIdx + 1;
890-
});
891-
892-
bool ArgIsWritten = any_of(RetParamRelations,
893-
[ArgIdx](const ExternalRelation &ExtRelation) {
894-
return ExtRelation.To.Index == ArgIdx + 1;
895-
});
896-
897-
if (ArgIsRead)
898-
return ArgIsWritten ? MRI_ModRef : MRI_Ref;
899-
return ArgIsWritten ? MRI_Mod : MRI_NoModRef;
900-
}
901-
902-
return MRI_ModRef;
903-
}
904-
905-
FunctionModRefBehavior
906-
CFLAndersAAResult::getModRefBehavior(ImmutableCallSite CS) {
907-
// If we know the callee, try analyzing it
908-
if (auto CalledFunc = CS.getCalledFunction())
909-
return getModRefBehavior(CalledFunc);
910-
911-
// Otherwise, be conservative
912-
return FMRB_UnknownModRefBehavior;
913-
}
914-
915-
FunctionModRefBehavior CFLAndersAAResult::getModRefBehavior(const Function *F) {
916-
assert(F != nullptr);
917-
918-
// We cannot process external functions
919-
if (!F->hasExactDefinition())
920-
return FMRB_UnknownModRefBehavior;
921-
922-
auto &MaybeInfo = ensureCached(*F);
923-
if (!MaybeInfo.hasValue())
924-
return FMRB_UnknownModRefBehavior;
925-
auto &RetParamAttributes = MaybeInfo->getAliasSummary().RetParamAttributes;
926-
auto &RetParamRelations = MaybeInfo->getAliasSummary().RetParamRelations;
927-
928-
// First, if any argument is marked Escpaed, Unknown or Global, anything may
929-
// happen to them and thus we can't draw any conclusion.
930-
// FIXME: Do we really need to be conservative for AttrGlobal?
931-
if (!RetParamAttributes.empty())
932-
return FMRB_UnknownModRefBehavior;
933-
934-
// Check if memory gets touched.
935-
bool MemIsRead =
936-
any_of(RetParamRelations, [](const ExternalRelation &ExtRelation) {
937-
return ExtRelation.From.DerefLevel > 0;
938-
});
939-
bool MemIsWritten =
940-
any_of(RetParamRelations, [](const ExternalRelation &ExtRelation) {
941-
return ExtRelation.To.DerefLevel > 0;
942-
});
943-
if (!MemIsRead && !MemIsWritten)
944-
return FMRB_DoesNotAccessMemory;
945-
946-
// Check if only argmem gets touched.
947-
bool ArgMemIsAccessed =
948-
all_of(RetParamRelations, [](const ExternalRelation &ExtRelation) {
949-
return ExtRelation.From.Index > 0 && ExtRelation.From.DerefLevel <= 1 &&
950-
ExtRelation.To.Index > 0 && ExtRelation.To.DerefLevel <= 1;
951-
});
952-
if (ArgMemIsAccessed)
953-
return FMRB_OnlyAccessesArgumentPointees;
954-
955-
if (!MemIsWritten) {
956-
// Check if something beyond argmem gets read.
957-
bool ArgMemReadOnly =
958-
all_of(RetParamRelations, [](const ExternalRelation &ExtRelation) {
959-
return ExtRelation.From.Index > 0 && ExtRelation.From.DerefLevel <= 1;
960-
});
961-
return ArgMemReadOnly ? FMRB_OnlyReadsArgumentPointees
962-
: FMRB_OnlyReadsMemory;
963-
}
964-
965-
if (!MemIsRead)
966-
return FMRB_DoesNotReadMemory;
967-
968-
return FMRB_UnknownModRefBehavior;
969-
}
970-
971865
char CFLAndersAA::PassID;
972866

973867
CFLAndersAAResult CFLAndersAA::run(Function &F, AnalysisManager<Function> &AM) {

‎llvm/lib/Analysis/CFLSteensAliasAnalysis.cpp

Lines changed: 0 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -341,88 +341,6 @@ AliasResult CFLSteensAAResult::query(const MemoryLocation &LocA,
341341
return NoAlias;
342342
}
343343

344-
ModRefInfo CFLSteensAAResult::getArgModRefInfo(ImmutableCallSite CS,
345-
unsigned ArgIdx) {
346-
if (auto CalledFunc = CS.getCalledFunction()) {
347-
if (!CalledFunc->hasExactDefinition())
348-
return MRI_ModRef;
349-
350-
auto &MaybeInfo = ensureCached(const_cast<Function *>(CalledFunc));
351-
if (!MaybeInfo.hasValue())
352-
return MRI_ModRef;
353-
auto &RetParamAttributes = MaybeInfo->getAliasSummary().RetParamAttributes;
354-
auto &RetParamRelations = MaybeInfo->getAliasSummary().RetParamRelations;
355-
356-
bool ArgAttributeIsWritten =
357-
std::any_of(RetParamAttributes.begin(), RetParamAttributes.end(),
358-
[ArgIdx](const ExternalAttribute &ExtAttr) {
359-
return ExtAttr.IValue.Index == ArgIdx + 1;
360-
});
361-
bool ArgIsAccessed =
362-
std::any_of(RetParamRelations.begin(), RetParamRelations.end(),
363-
[ArgIdx](const ExternalRelation &ExtRelation) {
364-
return ExtRelation.To.Index == ArgIdx + 1 ||
365-
ExtRelation.From.Index == ArgIdx + 1;
366-
});
367-
368-
return (!ArgIsAccessed && !ArgAttributeIsWritten) ? MRI_NoModRef
369-
: MRI_ModRef;
370-
}
371-
372-
return MRI_ModRef;
373-
}
374-
375-
FunctionModRefBehavior
376-
CFLSteensAAResult::getModRefBehavior(ImmutableCallSite CS) {
377-
// If we know the callee, try analyzing it
378-
if (auto CalledFunc = CS.getCalledFunction())
379-
return getModRefBehavior(CalledFunc);
380-
381-
// Otherwise, be conservative
382-
return FMRB_UnknownModRefBehavior;
383-
}
384-
385-
FunctionModRefBehavior CFLSteensAAResult::getModRefBehavior(const Function *F) {
386-
assert(F != nullptr);
387-
388-
// We cannot process external functions
389-
if (!F->hasExactDefinition())
390-
return FMRB_UnknownModRefBehavior;
391-
392-
// TODO: Remove the const_cast
393-
auto &MaybeInfo = ensureCached(const_cast<Function *>(F));
394-
if (!MaybeInfo.hasValue())
395-
return FMRB_UnknownModRefBehavior;
396-
auto &RetParamAttributes = MaybeInfo->getAliasSummary().RetParamAttributes;
397-
auto &RetParamRelations = MaybeInfo->getAliasSummary().RetParamRelations;
398-
399-
// First, if any argument is marked Escpaed, Unknown or Global, anything may
400-
// happen to them and thus we can't draw any conclusion.
401-
if (!RetParamAttributes.empty())
402-
return FMRB_UnknownModRefBehavior;
403-
404-
// Currently we don't (and can't) distinguish reads from writes in
405-
// RetParamRelations. All we can say is whether there may be memory access or
406-
// not.
407-
bool AccessNoMemory =
408-
all_of(RetParamRelations, [](const ExternalRelation &ExtRelation) {
409-
return ExtRelation.From.DerefLevel == 0 &&
410-
ExtRelation.To.DerefLevel == 0;
411-
});
412-
if (AccessNoMemory)
413-
return FMRB_DoesNotAccessMemory;
414-
415-
// Check if something beyond argmem gets touched.
416-
bool AccessArgMemoryOnly =
417-
all_of(RetParamRelations, [](const ExternalRelation &ExtRelation) {
418-
return ExtRelation.From.Index > 0 && ExtRelation.To.Index > 0 &&
419-
ExtRelation.From.DerefLevel <= 1 &&
420-
ExtRelation.To.DerefLevel <= 1;
421-
});
422-
return AccessArgMemoryOnly ? FMRB_OnlyAccessesArgumentPointees
423-
: FMRB_UnknownModRefBehavior;
424-
}
425-
426344
char CFLSteensAA::PassID;
427345

428346
CFLSteensAAResult CFLSteensAA::run(Function &F, AnalysisManager<Function> &AM) {

‎llvm/test/Analysis/CFLAliasAnalysis/Andersen/interproc-ret-arg.ll

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,10 @@ define i32* @return_arg_callee(i32* %arg1, i32* %arg2) {
1212
; CHECK: MayAlias: i32* %a, i32* %c
1313
; CHECK: NoAlias: i32* %b, i32* %c
1414

15-
; CHECK: NoModRef: Ptr: i32* %a <-> %c = call i32* @return_arg_callee(i32* %a, i32* %b)
16-
; CHECK: NoModRef: Ptr: i32* %b <-> %c = call i32* @return_arg_callee(i32* %a, i32* %b)
17-
; CHECK: NoModRef: Ptr: i32* %c <-> %c = call i32* @return_arg_callee(i32* %a, i32* %b)
15+
; Temporarily disable modref checks
16+
; NoModRef: Ptr: i32* %a <-> %c = call i32* @return_arg_callee(i32* %a, i32* %b)
17+
; NoModRef: Ptr: i32* %b <-> %c = call i32* @return_arg_callee(i32* %a, i32* %b)
18+
; NoModRef: Ptr: i32* %c <-> %c = call i32* @return_arg_callee(i32* %a, i32* %b)
1819
define void @test_return_arg() {
1920
%a = alloca i32, align 4
2021
%b = alloca i32, align 4

‎llvm/test/Analysis/CFLAliasAnalysis/Andersen/interproc-ret-deref-arg-multilevel.ll

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,10 @@ define i32* @return_deref_arg_multilevel_callee(i32*** %arg1) {
2929
; CHECK: NoAlias: i32* %lp, i32** %lpp
3030
; CHECK: MayAlias: i32* %lp, i32* %lpp_deref
3131

32-
; CHECK: Just Ref: Ptr: i32** %p <-> %c = call i32* @return_deref_arg_multilevel_callee(i32*** %pp)
33-
; CHECK: Just Ref: Ptr: i32*** %pp <-> %c = call i32* @return_deref_arg_multilevel_callee(i32*** %pp)
34-
; CHECK: Just Ref: Ptr: i32** %lpp <-> %c = call i32* @return_deref_arg_multilevel_callee(i32*** %pp)
32+
; Temporarily disable modref checks
33+
; Just Ref: Ptr: i32** %p <-> %c = call i32* @return_deref_arg_multilevel_callee(i32*** %pp)
34+
; Just Ref: Ptr: i32*** %pp <-> %c = call i32* @return_deref_arg_multilevel_callee(i32*** %pp)
35+
; Just Ref: Ptr: i32** %lpp <-> %c = call i32* @return_deref_arg_multilevel_callee(i32*** %pp)
3536

3637
define void @test_return_deref_arg_multilevel() {
3738
%a = alloca i32, align 4

‎llvm/test/Analysis/CFLAliasAnalysis/Andersen/interproc-ret-deref-arg.ll

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,12 @@ define i32* @return_deref_arg_callee(i32** %arg1) {
1717
; CHECK: NoAlias: i32* %lp, i32** %p
1818
; CHECK: MayAlias: i32* %c, i32* %lp
1919

20-
; CHECK: NoModRef: Ptr: i32* %a <-> %c = call i32* @return_deref_arg_callee(i32** %p)
21-
; CHECK: NoModRef: Ptr: i32* %b <-> %c = call i32* @return_deref_arg_callee(i32** %p)
22-
; CHECK: Just Ref: Ptr: i32** %p <-> %c = call i32* @return_deref_arg_callee(i32** %p)
23-
; CHECK: NoModRef: Ptr: i32* %c <-> %c = call i32* @return_deref_arg_callee(i32** %p)
24-
; CHECK: NoModRef: Ptr: i32* %lp <-> %c = call i32* @return_deref_arg_callee(i32** %p)
20+
; Temporarily disable modref checks
21+
; NoModRef: Ptr: i32* %a <-> %c = call i32* @return_deref_arg_callee(i32** %p)
22+
; NoModRef: Ptr: i32* %b <-> %c = call i32* @return_deref_arg_callee(i32** %p)
23+
; Just Ref: Ptr: i32** %p <-> %c = call i32* @return_deref_arg_callee(i32** %p)
24+
; NoModRef: Ptr: i32* %c <-> %c = call i32* @return_deref_arg_callee(i32** %p)
25+
; NoModRef: Ptr: i32* %lp <-> %c = call i32* @return_deref_arg_callee(i32** %p)
2526
define void @test_return_deref_arg() {
2627
%a = alloca i32, align 4
2728
%b = alloca i32, align 4

‎llvm/test/Analysis/CFLAliasAnalysis/Andersen/interproc-ret-ref-arg-multilevel.ll

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,9 @@ define i32*** @return_ref_arg_multilevel_callee(i32* %arg1) {
3131
; CHECK: NoAlias: i32* %lp, i32** %lpp
3232
; CHECK: MayAlias: i32* %lp, i32* %lpp_deref
3333

34-
; CHECK: Just Mod: Ptr: i32*** %b <-> %b = call i32*** @return_ref_arg_multilevel_callee(i32* %a)
35-
; CHECK: Just Mod: Ptr: i32** %lb <-> %b = call i32*** @return_ref_arg_multilevel_callee(i32* %a)
34+
; Temporarily disable modref checks
35+
; Just Mod: Ptr: i32*** %b <-> %b = call i32*** @return_ref_arg_multilevel_callee(i32* %a)
36+
; Just Mod: Ptr: i32** %lb <-> %b = call i32*** @return_ref_arg_multilevel_callee(i32* %a)
3637
define void @test_return_ref_arg_multilevel() {
3738
%a = alloca i32, align 4
3839
%p = alloca i32*, align 8

‎llvm/test/Analysis/CFLAliasAnalysis/Andersen/interproc-ret-ref-arg.ll

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ define i32** @return_ref_arg_callee(i32* %arg1) {
2121
; CHECK: NoAlias: i32* %lp, i32** %b
2222
; CHECK: MayAlias: i32* %lb, i32* %lp
2323

24-
; CHECK: Just Mod: Ptr: i32** %b <-> %b = call i32** @return_ref_arg_callee(i32* %a)
24+
; Temporarily disable modref checks
25+
; Just Mod: Ptr: i32** %b <-> %b = call i32** @return_ref_arg_callee(i32* %a)
2526
define void @test_return_ref_arg() {
2627
%a = alloca i32, align 4
2728
%p = alloca i32*, align 8

‎llvm/test/Analysis/CFLAliasAnalysis/Andersen/interproc-store-arg.ll

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,11 @@ define void @store_arg_callee(i32** %arg1, i32* %arg2) {
1818
; CHECK: MayAlias: i32* %b, i32* %lq
1919
; CHECK: MayAlias: i32* %lp, i32* %lq
2020

21-
; CHECK: NoModRef: Ptr: i32* %a <-> call void @store_arg_callee(i32** %p, i32* %b)
22-
; CHECK: Just Ref: Ptr: i32* %b <-> call void @store_arg_callee(i32** %p, i32* %b)
23-
; CHECK: Just Mod: Ptr: i32** %p <-> call void @store_arg_callee(i32** %p, i32* %b)
24-
; CHECK: NoModRef: Ptr: i32** %q <-> call void @store_arg_callee(i32** %p, i32* %b)
21+
; Temporarily disable modref checks
22+
; NoModRef: Ptr: i32* %a <-> call void @store_arg_callee(i32** %p, i32* %b)
23+
; Just Ref: Ptr: i32* %b <-> call void @store_arg_callee(i32** %p, i32* %b)
24+
; Just Mod: Ptr: i32** %p <-> call void @store_arg_callee(i32** %p, i32* %b)
25+
; NoModRef: Ptr: i32** %q <-> call void @store_arg_callee(i32** %p, i32* %b)
2526
define void @test_store_arg() {
2627
%a = alloca i32, align 4
2728
%b = alloca i32, align 4

‎llvm/test/Analysis/CFLAliasAnalysis/Steensgaard/interproc-ret-arg.ll

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ define i32* @return_arg_callee(i32* %arg1, i32* %arg2) {
1212
; CHECK: MayAlias: i32* %a, i32* %c
1313
; CHECK: NoAlias: i32* %b, i32* %c
1414

15-
; CHECK: NoModRef: Ptr: i32* %b <-> %c = call i32* @return_arg_callee(i32* %a, i32* %b)
15+
; Temporarily disable modref checks
16+
; NoModRef: Ptr: i32* %b <-> %c = call i32* @return_arg_callee(i32* %a, i32* %b)
1617
define void @test_return_arg() {
1718
%a = alloca i32, align 4
1819
%b = alloca i32, align 4

0 commit comments

Comments
 (0)
Please sign in to comment.