Skip to content

Commit 5e289cc

Browse files
committed
[AA] Support callCapturesBefore() on BatchAA (NFCI)
This is not expected to have any practical compile-time effect, as the alias() calls inside callCapturesBefore() are rare. This should still be supported for API completeness, and might be useful for reachability caching.
1 parent 20e2b4f commit 5e289cc

File tree

3 files changed

+19
-5
lines changed

3 files changed

+19
-5
lines changed

llvm/include/llvm/Analysis/AliasAnalysis.h

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -795,7 +795,11 @@ class AAResults {
795795
/// Early exits in callCapturesBefore may lead to ModRefInfo::Must not being
796796
/// set.
797797
ModRefInfo callCapturesBefore(const Instruction *I,
798-
const MemoryLocation &MemLoc, DominatorTree *DT);
798+
const MemoryLocation &MemLoc,
799+
DominatorTree *DT) {
800+
AAQueryInfo AAQIP;
801+
return callCapturesBefore(I, MemLoc, DT, AAQIP);
802+
}
799803

800804
/// A convenience wrapper to synthesize a memory location.
801805
ModRefInfo callCapturesBefore(const Instruction *I, const Value *P,
@@ -864,6 +868,9 @@ class AAResults {
864868
ModRefInfo getModRefInfo(const Instruction *I,
865869
const Optional<MemoryLocation> &OptLoc,
866870
AAQueryInfo &AAQIP);
871+
ModRefInfo callCapturesBefore(const Instruction *I,
872+
const MemoryLocation &MemLoc, DominatorTree *DT,
873+
AAQueryInfo &AAQIP);
867874

868875
class Concept;
869876

@@ -925,6 +932,11 @@ class BatchAAResults {
925932
MemoryLocation(V2, LocationSize::precise(1))) ==
926933
AliasResult::MustAlias;
927934
}
935+
ModRefInfo callCapturesBefore(const Instruction *I,
936+
const MemoryLocation &MemLoc,
937+
DominatorTree *DT) {
938+
return AA.callCapturesBefore(I, MemLoc, DT, AAQI);
939+
}
928940
};
929941

930942
/// Temporary typedef for legacy code that uses a generic \c AliasAnalysis

llvm/lib/Analysis/AliasAnalysis.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -718,7 +718,8 @@ ModRefInfo AAResults::getModRefInfo(const Instruction *I,
718718
/// with a smarter AA in place, this test is just wasting compile time.
719719
ModRefInfo AAResults::callCapturesBefore(const Instruction *I,
720720
const MemoryLocation &MemLoc,
721-
DominatorTree *DT) {
721+
DominatorTree *DT,
722+
AAQueryInfo &AAQI) {
722723
if (!DT)
723724
return ModRefInfo::ModRef;
724725

@@ -749,7 +750,9 @@ ModRefInfo AAResults::callCapturesBefore(const Instruction *I,
749750
!Call->isByValArgument(ArgNo)))
750751
continue;
751752

752-
AliasResult AR = alias(*CI, Object);
753+
AliasResult AR = alias(
754+
MemoryLocation::getBeforeOrAfter(*CI),
755+
MemoryLocation::getBeforeOrAfter(Object), AAQI);
753756
// If this is a no-capture pointer argument, see if we can tell that it
754757
// is impossible to alias the pointer we're checking. If not, we have to
755758
// assume that the call could touch the pointer, even though it doesn't

llvm/lib/Analysis/MemoryDependenceAnalysis.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -608,8 +608,7 @@ MemDepResult MemoryDependenceResults::getSimplePointerDependencyFrom(
608608
ModRefInfo MR = BatchAA.getModRefInfo(Inst, MemLoc);
609609
// If necessary, perform additional analysis.
610610
if (isModAndRefSet(MR))
611-
// TODO: Support callCapturesBefore() on BatchAAResults.
612-
MR = AA.callCapturesBefore(Inst, MemLoc, &DT);
611+
MR = BatchAA.callCapturesBefore(Inst, MemLoc, &DT);
613612
switch (clearMust(MR)) {
614613
case ModRefInfo::NoModRef:
615614
// If the call has no effect on the queried pointer, just ignore it.

0 commit comments

Comments
 (0)