2002-08-22 18:25:32 +00:00
|
|
|
//===- AliasAnalysis.cpp - Generic Alias Analysis Interface Implementation -==//
|
2005-04-21 21:13:18 +00:00
|
|
|
//
|
2003-10-20 19:43:21 +00:00
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2007-12-29 20:36:04 +00:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
2005-04-21 21:13:18 +00:00
|
|
|
//
|
2003-10-20 19:43:21 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
2002-08-22 18:25:32 +00:00
|
|
|
//
|
|
|
|
// This file implements the generic AliasAnalysis interface which is used as the
|
|
|
|
// common interface used by all clients and implementations of alias analysis.
|
|
|
|
//
|
|
|
|
// This file also implements the default version of the AliasAnalysis interface
|
|
|
|
// that is to be used when no other implementation is specified. This does some
|
|
|
|
// simple tests that detect obvious cases: two different global pointers cannot
|
|
|
|
// alias, a global cannot alias a malloc, two different mallocs cannot alias,
|
|
|
|
// etc.
|
|
|
|
//
|
|
|
|
// This alias analysis implementation really isn't very good for anything, but
|
|
|
|
// it is very fast, and makes a nice clean default implementation. Because it
|
|
|
|
// handles lots of little corner cases, other, more complex, alias analysis
|
|
|
|
// implementations may choose to rely on this pass to resolve these simple and
|
|
|
|
// easy cases.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2003-02-26 19:41:54 +00:00
|
|
|
#include "llvm/Analysis/AliasAnalysis.h"
|
2013-07-27 01:24:00 +00:00
|
|
|
#include "llvm/Analysis/CFG.h"
|
2014-01-07 11:48:04 +00:00
|
|
|
#include "llvm/Analysis/CaptureTracking.h"
|
2012-05-14 20:35:04 +00:00
|
|
|
#include "llvm/Analysis/ValueTracking.h"
|
2013-01-02 11:36:10 +00:00
|
|
|
#include "llvm/IR/BasicBlock.h"
|
|
|
|
#include "llvm/IR/DataLayout.h"
|
2014-01-13 09:26:24 +00:00
|
|
|
#include "llvm/IR/Dominators.h"
|
2013-01-02 11:36:10 +00:00
|
|
|
#include "llvm/IR/Function.h"
|
|
|
|
#include "llvm/IR/Instructions.h"
|
|
|
|
#include "llvm/IR/IntrinsicInst.h"
|
|
|
|
#include "llvm/IR/LLVMContext.h"
|
|
|
|
#include "llvm/IR/Type.h"
|
2012-12-03 16:50:05 +00:00
|
|
|
#include "llvm/Pass.h"
|
2012-08-29 15:32:21 +00:00
|
|
|
#include "llvm/Target/TargetLibraryInfo.h"
|
2004-03-15 04:07:29 +00:00
|
|
|
using namespace llvm;
|
2003-11-11 22:41:34 +00:00
|
|
|
|
2002-08-22 18:25:32 +00:00
|
|
|
// Register the AliasAnalysis interface, providing a nice name to refer to.
|
2010-10-19 17:21:58 +00:00
|
|
|
INITIALIZE_ANALYSIS_GROUP(AliasAnalysis, "Alias Analysis", NoAA)
|
2007-05-03 01:11:54 +00:00
|
|
|
char AliasAnalysis::ID = 0;
|
2002-08-22 18:25:32 +00:00
|
|
|
|
2004-05-23 21:15:48 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Default chaining methods
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
AliasAnalysis::AliasResult
|
2010-09-14 21:25:10 +00:00
|
|
|
AliasAnalysis::alias(const Location &LocA, const Location &LocB) {
|
2004-05-23 21:15:48 +00:00
|
|
|
assert(AA && "AA didn't call InitializeAliasAnalysis in its run method!");
|
2010-09-14 21:25:10 +00:00
|
|
|
return AA->alias(LocA, LocB);
|
2004-05-23 21:15:48 +00:00
|
|
|
}
|
|
|
|
|
2010-11-08 16:45:26 +00:00
|
|
|
bool AliasAnalysis::pointsToConstantMemory(const Location &Loc,
|
|
|
|
bool OrLocal) {
|
2004-05-23 21:15:48 +00:00
|
|
|
assert(AA && "AA didn't call InitializeAliasAnalysis in its run method!");
|
2010-11-08 16:45:26 +00:00
|
|
|
return AA->pointsToConstantMemory(Loc, OrLocal);
|
2004-05-23 21:15:48 +00:00
|
|
|
}
|
|
|
|
|
Improve BasicAA CS-CS queries (redux)
This reverts, "r213024 - Revert r212572 "improve BasicAA CS-CS queries", it
causes PR20303." with a fix for the bug in pr20303. As it turned out, the
relevant code was both wrong and over-conservative (because, as with the code
it replaced, it would return the overall ModRef mask even if just Ref had been
implied by the argument aliasing results). Hopefully, this correctly fixes both
problems.
Thanks to Nick Lewycky for reducing the test case for pr20303 (which I've
cleaned up a little and added in DSE's test directory). The BasicAA test has
also been updated to check for this error.
Original commit message:
BasicAA contains knowledge of certain intrinsics, such as memcpy and memset,
and uses that information to form more-accurate answers to CallSite vs. Loc
ModRef queries. Unfortunately, it did not use this information when answering
CallSite vs. CallSite queries.
Generically, when an intrinsic takes one or more pointers and the intrinsic is
marked only to read/write from its arguments, the offset/size is unknown. As a
result, the generic code that answers CallSite vs. CallSite (and CallSite vs.
Loc) queries in AA uses UnknownSize when forming Locs from an intrinsic's
arguments. While BasicAA's CallSite vs. Loc override could use more-accurate
size information for some intrinsics, it did not do the same for CallSite vs.
CallSite queries.
This change refactors the intrinsic-specific logic in BasicAA into a generic AA
query function: getArgLocation, which is overridden by BasicAA to supply the
intrinsic-specific knowledge, and used by AA's generic implementation. This
allows the intrinsic-specific knowledge to be used by both CallSite vs. Loc and
CallSite vs. CallSite queries, and simplifies the BasicAA implementation.
Currently, only one function, Mac's memset_pattern16, is handled by BasicAA
(all the rest are intrinsics). As a side-effect of this refactoring, BasicAA's
getModRefBehavior override now also returns OnlyAccessesArgumentPointees for
this function (which is an improvement).
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@213219 91177308-0d34-0410-b5e6-96231b3b80d8
2014-07-17 01:28:25 +00:00
|
|
|
AliasAnalysis::Location
|
|
|
|
AliasAnalysis::getArgLocation(ImmutableCallSite CS, unsigned ArgIdx,
|
|
|
|
AliasAnalysis::ModRefResult &Mask) {
|
|
|
|
assert(AA && "AA didn't call InitializeAliasAnalysis in its run method!");
|
|
|
|
return AA->getArgLocation(CS, ArgIdx, Mask);
|
|
|
|
}
|
|
|
|
|
2004-05-23 21:15:48 +00:00
|
|
|
void AliasAnalysis::deleteValue(Value *V) {
|
|
|
|
assert(AA && "AA didn't call InitializeAliasAnalysis in its run method!");
|
|
|
|
AA->deleteValue(V);
|
|
|
|
}
|
|
|
|
|
|
|
|
void AliasAnalysis::copyValue(Value *From, Value *To) {
|
|
|
|
assert(AA && "AA didn't call InitializeAliasAnalysis in its run method!");
|
|
|
|
AA->copyValue(From, To);
|
|
|
|
}
|
|
|
|
|
2011-01-03 21:38:41 +00:00
|
|
|
void AliasAnalysis::addEscapingUse(Use &U) {
|
|
|
|
assert(AA && "AA didn't call InitializeAliasAnalysis in its run method!");
|
|
|
|
AA->addEscapingUse(U);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-08-06 01:25:49 +00:00
|
|
|
AliasAnalysis::ModRefResult
|
|
|
|
AliasAnalysis::getModRefInfo(ImmutableCallSite CS,
|
2010-09-14 21:25:10 +00:00
|
|
|
const Location &Loc) {
|
2010-10-25 16:28:57 +00:00
|
|
|
assert(AA && "AA didn't call InitializeAliasAnalysis in its run method!");
|
2010-08-06 01:25:49 +00:00
|
|
|
|
|
|
|
ModRefBehavior MRB = getModRefBehavior(CS);
|
|
|
|
if (MRB == DoesNotAccessMemory)
|
|
|
|
return NoModRef;
|
|
|
|
|
|
|
|
ModRefResult Mask = ModRef;
|
2010-11-09 20:06:55 +00:00
|
|
|
if (onlyReadsMemory(MRB))
|
2010-08-06 01:25:49 +00:00
|
|
|
Mask = Ref;
|
2010-11-09 20:06:55 +00:00
|
|
|
|
2010-11-10 18:17:28 +00:00
|
|
|
if (onlyAccessesArgPointees(MRB)) {
|
2010-08-06 01:25:49 +00:00
|
|
|
bool doesAlias = false;
|
Improve BasicAA CS-CS queries (redux)
This reverts, "r213024 - Revert r212572 "improve BasicAA CS-CS queries", it
causes PR20303." with a fix for the bug in pr20303. As it turned out, the
relevant code was both wrong and over-conservative (because, as with the code
it replaced, it would return the overall ModRef mask even if just Ref had been
implied by the argument aliasing results). Hopefully, this correctly fixes both
problems.
Thanks to Nick Lewycky for reducing the test case for pr20303 (which I've
cleaned up a little and added in DSE's test directory). The BasicAA test has
also been updated to check for this error.
Original commit message:
BasicAA contains knowledge of certain intrinsics, such as memcpy and memset,
and uses that information to form more-accurate answers to CallSite vs. Loc
ModRef queries. Unfortunately, it did not use this information when answering
CallSite vs. CallSite queries.
Generically, when an intrinsic takes one or more pointers and the intrinsic is
marked only to read/write from its arguments, the offset/size is unknown. As a
result, the generic code that answers CallSite vs. CallSite (and CallSite vs.
Loc) queries in AA uses UnknownSize when forming Locs from an intrinsic's
arguments. While BasicAA's CallSite vs. Loc override could use more-accurate
size information for some intrinsics, it did not do the same for CallSite vs.
CallSite queries.
This change refactors the intrinsic-specific logic in BasicAA into a generic AA
query function: getArgLocation, which is overridden by BasicAA to supply the
intrinsic-specific knowledge, and used by AA's generic implementation. This
allows the intrinsic-specific knowledge to be used by both CallSite vs. Loc and
CallSite vs. CallSite queries, and simplifies the BasicAA implementation.
Currently, only one function, Mac's memset_pattern16, is handled by BasicAA
(all the rest are intrinsics). As a side-effect of this refactoring, BasicAA's
getModRefBehavior override now also returns OnlyAccessesArgumentPointees for
this function (which is an improvement).
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@213219 91177308-0d34-0410-b5e6-96231b3b80d8
2014-07-17 01:28:25 +00:00
|
|
|
ModRefResult AllArgsMask = NoModRef;
|
2011-04-27 18:39:03 +00:00
|
|
|
if (doesAccessArgPointees(MRB)) {
|
2010-11-10 18:17:28 +00:00
|
|
|
for (ImmutableCallSite::arg_iterator AI = CS.arg_begin(), AE = CS.arg_end();
|
2011-04-27 18:39:03 +00:00
|
|
|
AI != AE; ++AI) {
|
|
|
|
const Value *Arg = *AI;
|
|
|
|
if (!Arg->getType()->isPointerTy())
|
|
|
|
continue;
|
Improve BasicAA CS-CS queries (redux)
This reverts, "r213024 - Revert r212572 "improve BasicAA CS-CS queries", it
causes PR20303." with a fix for the bug in pr20303. As it turned out, the
relevant code was both wrong and over-conservative (because, as with the code
it replaced, it would return the overall ModRef mask even if just Ref had been
implied by the argument aliasing results). Hopefully, this correctly fixes both
problems.
Thanks to Nick Lewycky for reducing the test case for pr20303 (which I've
cleaned up a little and added in DSE's test directory). The BasicAA test has
also been updated to check for this error.
Original commit message:
BasicAA contains knowledge of certain intrinsics, such as memcpy and memset,
and uses that information to form more-accurate answers to CallSite vs. Loc
ModRef queries. Unfortunately, it did not use this information when answering
CallSite vs. CallSite queries.
Generically, when an intrinsic takes one or more pointers and the intrinsic is
marked only to read/write from its arguments, the offset/size is unknown. As a
result, the generic code that answers CallSite vs. CallSite (and CallSite vs.
Loc) queries in AA uses UnknownSize when forming Locs from an intrinsic's
arguments. While BasicAA's CallSite vs. Loc override could use more-accurate
size information for some intrinsics, it did not do the same for CallSite vs.
CallSite queries.
This change refactors the intrinsic-specific logic in BasicAA into a generic AA
query function: getArgLocation, which is overridden by BasicAA to supply the
intrinsic-specific knowledge, and used by AA's generic implementation. This
allows the intrinsic-specific knowledge to be used by both CallSite vs. Loc and
CallSite vs. CallSite queries, and simplifies the BasicAA implementation.
Currently, only one function, Mac's memset_pattern16, is handled by BasicAA
(all the rest are intrinsics). As a side-effect of this refactoring, BasicAA's
getModRefBehavior override now also returns OnlyAccessesArgumentPointees for
this function (which is an improvement).
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@213219 91177308-0d34-0410-b5e6-96231b3b80d8
2014-07-17 01:28:25 +00:00
|
|
|
ModRefResult ArgMask;
|
|
|
|
Location CSLoc =
|
|
|
|
getArgLocation(CS, (unsigned) std::distance(CS.arg_begin(), AI),
|
|
|
|
ArgMask);
|
2011-04-27 18:39:03 +00:00
|
|
|
if (!isNoAlias(CSLoc, Loc)) {
|
2010-11-10 18:17:28 +00:00
|
|
|
doesAlias = true;
|
Improve BasicAA CS-CS queries (redux)
This reverts, "r213024 - Revert r212572 "improve BasicAA CS-CS queries", it
causes PR20303." with a fix for the bug in pr20303. As it turned out, the
relevant code was both wrong and over-conservative (because, as with the code
it replaced, it would return the overall ModRef mask even if just Ref had been
implied by the argument aliasing results). Hopefully, this correctly fixes both
problems.
Thanks to Nick Lewycky for reducing the test case for pr20303 (which I've
cleaned up a little and added in DSE's test directory). The BasicAA test has
also been updated to check for this error.
Original commit message:
BasicAA contains knowledge of certain intrinsics, such as memcpy and memset,
and uses that information to form more-accurate answers to CallSite vs. Loc
ModRef queries. Unfortunately, it did not use this information when answering
CallSite vs. CallSite queries.
Generically, when an intrinsic takes one or more pointers and the intrinsic is
marked only to read/write from its arguments, the offset/size is unknown. As a
result, the generic code that answers CallSite vs. CallSite (and CallSite vs.
Loc) queries in AA uses UnknownSize when forming Locs from an intrinsic's
arguments. While BasicAA's CallSite vs. Loc override could use more-accurate
size information for some intrinsics, it did not do the same for CallSite vs.
CallSite queries.
This change refactors the intrinsic-specific logic in BasicAA into a generic AA
query function: getArgLocation, which is overridden by BasicAA to supply the
intrinsic-specific knowledge, and used by AA's generic implementation. This
allows the intrinsic-specific knowledge to be used by both CallSite vs. Loc and
CallSite vs. CallSite queries, and simplifies the BasicAA implementation.
Currently, only one function, Mac's memset_pattern16, is handled by BasicAA
(all the rest are intrinsics). As a side-effect of this refactoring, BasicAA's
getModRefBehavior override now also returns OnlyAccessesArgumentPointees for
this function (which is an improvement).
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@213219 91177308-0d34-0410-b5e6-96231b3b80d8
2014-07-17 01:28:25 +00:00
|
|
|
AllArgsMask = ModRefResult(AllArgsMask | ArgMask);
|
2010-11-10 18:17:28 +00:00
|
|
|
}
|
2011-04-27 18:39:03 +00:00
|
|
|
}
|
|
|
|
}
|
2010-08-06 01:25:49 +00:00
|
|
|
if (!doesAlias)
|
|
|
|
return NoModRef;
|
Improve BasicAA CS-CS queries (redux)
This reverts, "r213024 - Revert r212572 "improve BasicAA CS-CS queries", it
causes PR20303." with a fix for the bug in pr20303. As it turned out, the
relevant code was both wrong and over-conservative (because, as with the code
it replaced, it would return the overall ModRef mask even if just Ref had been
implied by the argument aliasing results). Hopefully, this correctly fixes both
problems.
Thanks to Nick Lewycky for reducing the test case for pr20303 (which I've
cleaned up a little and added in DSE's test directory). The BasicAA test has
also been updated to check for this error.
Original commit message:
BasicAA contains knowledge of certain intrinsics, such as memcpy and memset,
and uses that information to form more-accurate answers to CallSite vs. Loc
ModRef queries. Unfortunately, it did not use this information when answering
CallSite vs. CallSite queries.
Generically, when an intrinsic takes one or more pointers and the intrinsic is
marked only to read/write from its arguments, the offset/size is unknown. As a
result, the generic code that answers CallSite vs. CallSite (and CallSite vs.
Loc) queries in AA uses UnknownSize when forming Locs from an intrinsic's
arguments. While BasicAA's CallSite vs. Loc override could use more-accurate
size information for some intrinsics, it did not do the same for CallSite vs.
CallSite queries.
This change refactors the intrinsic-specific logic in BasicAA into a generic AA
query function: getArgLocation, which is overridden by BasicAA to supply the
intrinsic-specific knowledge, and used by AA's generic implementation. This
allows the intrinsic-specific knowledge to be used by both CallSite vs. Loc and
CallSite vs. CallSite queries, and simplifies the BasicAA implementation.
Currently, only one function, Mac's memset_pattern16, is handled by BasicAA
(all the rest are intrinsics). As a side-effect of this refactoring, BasicAA's
getModRefBehavior override now also returns OnlyAccessesArgumentPointees for
this function (which is an improvement).
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@213219 91177308-0d34-0410-b5e6-96231b3b80d8
2014-07-17 01:28:25 +00:00
|
|
|
Mask = ModRefResult(Mask & AllArgsMask);
|
2010-08-06 01:25:49 +00:00
|
|
|
}
|
|
|
|
|
2010-09-14 21:25:10 +00:00
|
|
|
// If Loc is a constant memory location, the call definitely could not
|
2010-08-06 01:25:49 +00:00
|
|
|
// modify the memory location.
|
2010-09-14 21:25:10 +00:00
|
|
|
if ((Mask & Mod) && pointsToConstantMemory(Loc))
|
2010-08-06 01:25:49 +00:00
|
|
|
Mask = ModRefResult(Mask & ~Mod);
|
|
|
|
|
2010-10-25 16:29:52 +00:00
|
|
|
// If this is the end of the chain, don't forward.
|
2010-08-06 01:25:49 +00:00
|
|
|
if (!AA) return Mask;
|
|
|
|
|
|
|
|
// Otherwise, fall back to the next AA in the chain. But we can merge
|
|
|
|
// in any mask we've managed to compute.
|
2010-09-14 21:25:10 +00:00
|
|
|
return ModRefResult(AA->getModRefInfo(CS, Loc) & Mask);
|
2010-08-06 01:25:49 +00:00
|
|
|
}
|
|
|
|
|
2004-05-23 21:15:48 +00:00
|
|
|
AliasAnalysis::ModRefResult
|
2010-08-03 21:48:53 +00:00
|
|
|
AliasAnalysis::getModRefInfo(ImmutableCallSite CS1, ImmutableCallSite CS2) {
|
2010-10-25 16:28:57 +00:00
|
|
|
assert(AA && "AA didn't call InitializeAliasAnalysis in its run method!");
|
2010-08-06 01:25:49 +00:00
|
|
|
|
|
|
|
// If CS1 or CS2 are readnone, they don't interact.
|
|
|
|
ModRefBehavior CS1B = getModRefBehavior(CS1);
|
|
|
|
if (CS1B == DoesNotAccessMemory) return NoModRef;
|
|
|
|
|
|
|
|
ModRefBehavior CS2B = getModRefBehavior(CS2);
|
|
|
|
if (CS2B == DoesNotAccessMemory) return NoModRef;
|
|
|
|
|
|
|
|
// If they both only read from memory, there is no dependence.
|
2010-11-09 20:06:55 +00:00
|
|
|
if (onlyReadsMemory(CS1B) && onlyReadsMemory(CS2B))
|
2010-08-06 01:25:49 +00:00
|
|
|
return NoModRef;
|
|
|
|
|
|
|
|
AliasAnalysis::ModRefResult Mask = ModRef;
|
|
|
|
|
|
|
|
// If CS1 only reads memory, the only dependence on CS2 can be
|
|
|
|
// from CS1 reading memory written by CS2.
|
2010-11-09 20:06:55 +00:00
|
|
|
if (onlyReadsMemory(CS1B))
|
2010-08-06 01:25:49 +00:00
|
|
|
Mask = ModRefResult(Mask & Ref);
|
|
|
|
|
|
|
|
// If CS2 only access memory through arguments, accumulate the mod/ref
|
|
|
|
// information from CS1's references to the memory referenced by
|
|
|
|
// CS2's arguments.
|
2010-11-10 18:17:28 +00:00
|
|
|
if (onlyAccessesArgPointees(CS2B)) {
|
2010-08-06 01:25:49 +00:00
|
|
|
AliasAnalysis::ModRefResult R = NoModRef;
|
2011-04-27 18:39:03 +00:00
|
|
|
if (doesAccessArgPointees(CS2B)) {
|
2010-11-10 18:17:28 +00:00
|
|
|
for (ImmutableCallSite::arg_iterator
|
|
|
|
I = CS2.arg_begin(), E = CS2.arg_end(); I != E; ++I) {
|
2011-04-27 18:39:03 +00:00
|
|
|
const Value *Arg = *I;
|
|
|
|
if (!Arg->getType()->isPointerTy())
|
|
|
|
continue;
|
Improve BasicAA CS-CS queries (redux)
This reverts, "r213024 - Revert r212572 "improve BasicAA CS-CS queries", it
causes PR20303." with a fix for the bug in pr20303. As it turned out, the
relevant code was both wrong and over-conservative (because, as with the code
it replaced, it would return the overall ModRef mask even if just Ref had been
implied by the argument aliasing results). Hopefully, this correctly fixes both
problems.
Thanks to Nick Lewycky for reducing the test case for pr20303 (which I've
cleaned up a little and added in DSE's test directory). The BasicAA test has
also been updated to check for this error.
Original commit message:
BasicAA contains knowledge of certain intrinsics, such as memcpy and memset,
and uses that information to form more-accurate answers to CallSite vs. Loc
ModRef queries. Unfortunately, it did not use this information when answering
CallSite vs. CallSite queries.
Generically, when an intrinsic takes one or more pointers and the intrinsic is
marked only to read/write from its arguments, the offset/size is unknown. As a
result, the generic code that answers CallSite vs. CallSite (and CallSite vs.
Loc) queries in AA uses UnknownSize when forming Locs from an intrinsic's
arguments. While BasicAA's CallSite vs. Loc override could use more-accurate
size information for some intrinsics, it did not do the same for CallSite vs.
CallSite queries.
This change refactors the intrinsic-specific logic in BasicAA into a generic AA
query function: getArgLocation, which is overridden by BasicAA to supply the
intrinsic-specific knowledge, and used by AA's generic implementation. This
allows the intrinsic-specific knowledge to be used by both CallSite vs. Loc and
CallSite vs. CallSite queries, and simplifies the BasicAA implementation.
Currently, only one function, Mac's memset_pattern16, is handled by BasicAA
(all the rest are intrinsics). As a side-effect of this refactoring, BasicAA's
getModRefBehavior override now also returns OnlyAccessesArgumentPointees for
this function (which is an improvement).
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@213219 91177308-0d34-0410-b5e6-96231b3b80d8
2014-07-17 01:28:25 +00:00
|
|
|
ModRefResult ArgMask;
|
|
|
|
Location CS2Loc =
|
|
|
|
getArgLocation(CS2, (unsigned) std::distance(CS2.arg_begin(), I),
|
|
|
|
ArgMask);
|
|
|
|
// ArgMask indicates what CS2 might do to CS2Loc, and the dependence of
|
|
|
|
// CS1 on that location is the inverse.
|
|
|
|
if (ArgMask == Mod)
|
|
|
|
ArgMask = ModRef;
|
|
|
|
else if (ArgMask == Ref)
|
|
|
|
ArgMask = Mod;
|
|
|
|
|
|
|
|
R = ModRefResult((R | (getModRefInfo(CS1, CS2Loc) & ArgMask)) & Mask);
|
2010-11-10 18:17:28 +00:00
|
|
|
if (R == Mask)
|
|
|
|
break;
|
|
|
|
}
|
2011-04-27 18:39:03 +00:00
|
|
|
}
|
2010-08-06 01:25:49 +00:00
|
|
|
return R;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If CS1 only accesses memory through arguments, check if CS2 references
|
|
|
|
// any of the memory referenced by CS1's arguments. If not, return NoModRef.
|
2010-11-10 18:17:28 +00:00
|
|
|
if (onlyAccessesArgPointees(CS1B)) {
|
2010-08-06 01:25:49 +00:00
|
|
|
AliasAnalysis::ModRefResult R = NoModRef;
|
2011-04-27 18:39:03 +00:00
|
|
|
if (doesAccessArgPointees(CS1B)) {
|
2010-11-10 18:17:28 +00:00
|
|
|
for (ImmutableCallSite::arg_iterator
|
2011-04-27 18:39:03 +00:00
|
|
|
I = CS1.arg_begin(), E = CS1.arg_end(); I != E; ++I) {
|
|
|
|
const Value *Arg = *I;
|
|
|
|
if (!Arg->getType()->isPointerTy())
|
|
|
|
continue;
|
Improve BasicAA CS-CS queries (redux)
This reverts, "r213024 - Revert r212572 "improve BasicAA CS-CS queries", it
causes PR20303." with a fix for the bug in pr20303. As it turned out, the
relevant code was both wrong and over-conservative (because, as with the code
it replaced, it would return the overall ModRef mask even if just Ref had been
implied by the argument aliasing results). Hopefully, this correctly fixes both
problems.
Thanks to Nick Lewycky for reducing the test case for pr20303 (which I've
cleaned up a little and added in DSE's test directory). The BasicAA test has
also been updated to check for this error.
Original commit message:
BasicAA contains knowledge of certain intrinsics, such as memcpy and memset,
and uses that information to form more-accurate answers to CallSite vs. Loc
ModRef queries. Unfortunately, it did not use this information when answering
CallSite vs. CallSite queries.
Generically, when an intrinsic takes one or more pointers and the intrinsic is
marked only to read/write from its arguments, the offset/size is unknown. As a
result, the generic code that answers CallSite vs. CallSite (and CallSite vs.
Loc) queries in AA uses UnknownSize when forming Locs from an intrinsic's
arguments. While BasicAA's CallSite vs. Loc override could use more-accurate
size information for some intrinsics, it did not do the same for CallSite vs.
CallSite queries.
This change refactors the intrinsic-specific logic in BasicAA into a generic AA
query function: getArgLocation, which is overridden by BasicAA to supply the
intrinsic-specific knowledge, and used by AA's generic implementation. This
allows the intrinsic-specific knowledge to be used by both CallSite vs. Loc and
CallSite vs. CallSite queries, and simplifies the BasicAA implementation.
Currently, only one function, Mac's memset_pattern16, is handled by BasicAA
(all the rest are intrinsics). As a side-effect of this refactoring, BasicAA's
getModRefBehavior override now also returns OnlyAccessesArgumentPointees for
this function (which is an improvement).
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@213219 91177308-0d34-0410-b5e6-96231b3b80d8
2014-07-17 01:28:25 +00:00
|
|
|
ModRefResult ArgMask;
|
2014-10-28 11:54:52 +00:00
|
|
|
Location CS1Loc = getArgLocation(
|
|
|
|
CS1, (unsigned)std::distance(CS1.arg_begin(), I), ArgMask);
|
2014-10-28 11:53:30 +00:00
|
|
|
// ArgMask indicates what CS1 might do to CS1Loc; if CS1 might Mod
|
|
|
|
// CS1Loc, then we care about either a Mod or a Ref by CS2. If CS1
|
|
|
|
// might Ref, then we care only about a Mod by CS2.
|
Improve BasicAA CS-CS queries (redux)
This reverts, "r213024 - Revert r212572 "improve BasicAA CS-CS queries", it
causes PR20303." with a fix for the bug in pr20303. As it turned out, the
relevant code was both wrong and over-conservative (because, as with the code
it replaced, it would return the overall ModRef mask even if just Ref had been
implied by the argument aliasing results). Hopefully, this correctly fixes both
problems.
Thanks to Nick Lewycky for reducing the test case for pr20303 (which I've
cleaned up a little and added in DSE's test directory). The BasicAA test has
also been updated to check for this error.
Original commit message:
BasicAA contains knowledge of certain intrinsics, such as memcpy and memset,
and uses that information to form more-accurate answers to CallSite vs. Loc
ModRef queries. Unfortunately, it did not use this information when answering
CallSite vs. CallSite queries.
Generically, when an intrinsic takes one or more pointers and the intrinsic is
marked only to read/write from its arguments, the offset/size is unknown. As a
result, the generic code that answers CallSite vs. CallSite (and CallSite vs.
Loc) queries in AA uses UnknownSize when forming Locs from an intrinsic's
arguments. While BasicAA's CallSite vs. Loc override could use more-accurate
size information for some intrinsics, it did not do the same for CallSite vs.
CallSite queries.
This change refactors the intrinsic-specific logic in BasicAA into a generic AA
query function: getArgLocation, which is overridden by BasicAA to supply the
intrinsic-specific knowledge, and used by AA's generic implementation. This
allows the intrinsic-specific knowledge to be used by both CallSite vs. Loc and
CallSite vs. CallSite queries, and simplifies the BasicAA implementation.
Currently, only one function, Mac's memset_pattern16, is handled by BasicAA
(all the rest are intrinsics). As a side-effect of this refactoring, BasicAA's
getModRefBehavior override now also returns OnlyAccessesArgumentPointees for
this function (which is an improvement).
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@213219 91177308-0d34-0410-b5e6-96231b3b80d8
2014-07-17 01:28:25 +00:00
|
|
|
ModRefResult ArgR = getModRefInfo(CS2, CS1Loc);
|
|
|
|
if (((ArgMask & Mod) != NoModRef && (ArgR & ModRef) != NoModRef) ||
|
|
|
|
((ArgMask & Ref) != NoModRef && (ArgR & Mod) != NoModRef))
|
|
|
|
R = ModRefResult((R | ArgMask) & Mask);
|
|
|
|
|
|
|
|
if (R == Mask)
|
2010-11-10 18:17:28 +00:00
|
|
|
break;
|
2011-04-27 18:39:03 +00:00
|
|
|
}
|
|
|
|
}
|
Improve BasicAA CS-CS queries (redux)
This reverts, "r213024 - Revert r212572 "improve BasicAA CS-CS queries", it
causes PR20303." with a fix for the bug in pr20303. As it turned out, the
relevant code was both wrong and over-conservative (because, as with the code
it replaced, it would return the overall ModRef mask even if just Ref had been
implied by the argument aliasing results). Hopefully, this correctly fixes both
problems.
Thanks to Nick Lewycky for reducing the test case for pr20303 (which I've
cleaned up a little and added in DSE's test directory). The BasicAA test has
also been updated to check for this error.
Original commit message:
BasicAA contains knowledge of certain intrinsics, such as memcpy and memset,
and uses that information to form more-accurate answers to CallSite vs. Loc
ModRef queries. Unfortunately, it did not use this information when answering
CallSite vs. CallSite queries.
Generically, when an intrinsic takes one or more pointers and the intrinsic is
marked only to read/write from its arguments, the offset/size is unknown. As a
result, the generic code that answers CallSite vs. CallSite (and CallSite vs.
Loc) queries in AA uses UnknownSize when forming Locs from an intrinsic's
arguments. While BasicAA's CallSite vs. Loc override could use more-accurate
size information for some intrinsics, it did not do the same for CallSite vs.
CallSite queries.
This change refactors the intrinsic-specific logic in BasicAA into a generic AA
query function: getArgLocation, which is overridden by BasicAA to supply the
intrinsic-specific knowledge, and used by AA's generic implementation. This
allows the intrinsic-specific knowledge to be used by both CallSite vs. Loc and
CallSite vs. CallSite queries, and simplifies the BasicAA implementation.
Currently, only one function, Mac's memset_pattern16, is handled by BasicAA
(all the rest are intrinsics). As a side-effect of this refactoring, BasicAA's
getModRefBehavior override now also returns OnlyAccessesArgumentPointees for
this function (which is an improvement).
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@213219 91177308-0d34-0410-b5e6-96231b3b80d8
2014-07-17 01:28:25 +00:00
|
|
|
return R;
|
2010-08-06 01:25:49 +00:00
|
|
|
}
|
|
|
|
|
2010-10-25 16:29:52 +00:00
|
|
|
// If this is the end of the chain, don't forward.
|
2010-08-06 01:25:49 +00:00
|
|
|
if (!AA) return Mask;
|
|
|
|
|
|
|
|
// Otherwise, fall back to the next AA in the chain. But we can merge
|
|
|
|
// in any mask we've managed to compute.
|
|
|
|
return ModRefResult(AA->getModRefInfo(CS1, CS2) & Mask);
|
|
|
|
}
|
|
|
|
|
|
|
|
AliasAnalysis::ModRefBehavior
|
|
|
|
AliasAnalysis::getModRefBehavior(ImmutableCallSite CS) {
|
2010-10-25 16:28:57 +00:00
|
|
|
assert(AA && "AA didn't call InitializeAliasAnalysis in its run method!");
|
2010-08-06 01:25:49 +00:00
|
|
|
|
|
|
|
ModRefBehavior Min = UnknownModRefBehavior;
|
|
|
|
|
|
|
|
// Call back into the alias analysis with the other form of getModRefBehavior
|
|
|
|
// to see if it can give a better response.
|
|
|
|
if (const Function *F = CS.getCalledFunction())
|
|
|
|
Min = getModRefBehavior(F);
|
|
|
|
|
2010-10-25 16:29:52 +00:00
|
|
|
// If this is the end of the chain, don't forward.
|
2010-08-06 01:25:49 +00:00
|
|
|
if (!AA) return Min;
|
|
|
|
|
|
|
|
// Otherwise, fall back to the next AA in the chain. But we can merge
|
|
|
|
// in any result we've managed to compute.
|
2010-11-10 01:02:18 +00:00
|
|
|
return ModRefBehavior(AA->getModRefBehavior(CS) & Min);
|
2010-08-06 01:25:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
AliasAnalysis::ModRefBehavior
|
|
|
|
AliasAnalysis::getModRefBehavior(const Function *F) {
|
2004-05-23 21:15:48 +00:00
|
|
|
assert(AA && "AA didn't call InitializeAliasAnalysis in its run method!");
|
2010-08-06 01:25:49 +00:00
|
|
|
return AA->getModRefBehavior(F);
|
2004-05-23 21:15:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// AliasAnalysis non-virtual helper method implementation
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2010-11-11 21:50:19 +00:00
|
|
|
AliasAnalysis::Location AliasAnalysis::getLocation(const LoadInst *LI) {
|
2014-07-24 12:16:19 +00:00
|
|
|
AAMDNodes AATags;
|
|
|
|
LI->getAAMetadata(AATags);
|
|
|
|
|
2010-11-11 21:50:19 +00:00
|
|
|
return Location(LI->getPointerOperand(),
|
2014-07-24 12:16:19 +00:00
|
|
|
getTypeStoreSize(LI->getType()), AATags);
|
2010-11-11 21:50:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
AliasAnalysis::Location AliasAnalysis::getLocation(const StoreInst *SI) {
|
2014-07-24 12:16:19 +00:00
|
|
|
AAMDNodes AATags;
|
|
|
|
SI->getAAMetadata(AATags);
|
|
|
|
|
2010-11-11 21:50:19 +00:00
|
|
|
return Location(SI->getPointerOperand(),
|
2014-07-24 12:16:19 +00:00
|
|
|
getTypeStoreSize(SI->getValueOperand()->getType()), AATags);
|
2010-11-11 21:50:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
AliasAnalysis::Location AliasAnalysis::getLocation(const VAArgInst *VI) {
|
2014-07-24 12:16:19 +00:00
|
|
|
AAMDNodes AATags;
|
|
|
|
VI->getAAMetadata(AATags);
|
|
|
|
|
|
|
|
return Location(VI->getPointerOperand(), UnknownSize, AATags);
|
2010-11-11 21:50:19 +00:00
|
|
|
}
|
|
|
|
|
2011-09-26 20:15:28 +00:00
|
|
|
AliasAnalysis::Location
|
|
|
|
AliasAnalysis::getLocation(const AtomicCmpXchgInst *CXI) {
|
2014-07-24 12:16:19 +00:00
|
|
|
AAMDNodes AATags;
|
|
|
|
CXI->getAAMetadata(AATags);
|
|
|
|
|
2011-09-26 20:15:28 +00:00
|
|
|
return Location(CXI->getPointerOperand(),
|
|
|
|
getTypeStoreSize(CXI->getCompareOperand()->getType()),
|
2014-07-24 12:16:19 +00:00
|
|
|
AATags);
|
2011-09-26 20:15:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
AliasAnalysis::Location
|
|
|
|
AliasAnalysis::getLocation(const AtomicRMWInst *RMWI) {
|
2014-07-24 12:16:19 +00:00
|
|
|
AAMDNodes AATags;
|
|
|
|
RMWI->getAAMetadata(AATags);
|
|
|
|
|
2011-09-26 20:15:28 +00:00
|
|
|
return Location(RMWI->getPointerOperand(),
|
2014-07-24 12:16:19 +00:00
|
|
|
getTypeStoreSize(RMWI->getValOperand()->getType()), AATags);
|
2011-09-26 20:15:28 +00:00
|
|
|
}
|
2010-11-21 07:51:27 +00:00
|
|
|
|
2014-10-28 11:53:30 +00:00
|
|
|
AliasAnalysis::Location
|
2010-11-21 07:51:27 +00:00
|
|
|
AliasAnalysis::getLocationForSource(const MemTransferInst *MTI) {
|
|
|
|
uint64_t Size = UnknownSize;
|
|
|
|
if (ConstantInt *C = dyn_cast<ConstantInt>(MTI->getLength()))
|
|
|
|
Size = C->getValue().getZExtValue();
|
|
|
|
|
2014-07-24 12:16:19 +00:00
|
|
|
// memcpy/memmove can have AA tags. For memcpy, they apply
|
2010-12-16 02:51:19 +00:00
|
|
|
// to both the source and the destination.
|
2014-07-24 12:16:19 +00:00
|
|
|
AAMDNodes AATags;
|
|
|
|
MTI->getAAMetadata(AATags);
|
2014-10-28 11:53:30 +00:00
|
|
|
|
2014-07-24 12:16:19 +00:00
|
|
|
return Location(MTI->getRawSource(), Size, AATags);
|
2010-11-21 07:51:27 +00:00
|
|
|
}
|
|
|
|
|
2014-10-28 11:53:30 +00:00
|
|
|
AliasAnalysis::Location
|
2010-11-30 01:48:20 +00:00
|
|
|
AliasAnalysis::getLocationForDest(const MemIntrinsic *MTI) {
|
2010-11-21 07:51:27 +00:00
|
|
|
uint64_t Size = UnknownSize;
|
|
|
|
if (ConstantInt *C = dyn_cast<ConstantInt>(MTI->getLength()))
|
|
|
|
Size = C->getValue().getZExtValue();
|
2010-12-16 02:51:19 +00:00
|
|
|
|
2014-07-24 12:16:19 +00:00
|
|
|
// memcpy/memmove can have AA tags. For memcpy, they apply
|
2010-12-16 02:51:19 +00:00
|
|
|
// to both the source and the destination.
|
2014-07-24 12:16:19 +00:00
|
|
|
AAMDNodes AATags;
|
2014-10-04 22:44:29 +00:00
|
|
|
MTI->getAAMetadata(AATags);
|
2014-10-28 11:53:30 +00:00
|
|
|
|
2014-07-24 12:16:19 +00:00
|
|
|
return Location(MTI->getRawDest(), Size, AATags);
|
2010-11-21 07:51:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2003-02-26 19:26:51 +00:00
|
|
|
AliasAnalysis::ModRefResult
|
2010-09-14 21:25:10 +00:00
|
|
|
AliasAnalysis::getModRefInfo(const LoadInst *L, const Location &Loc) {
|
2011-08-15 20:54:19 +00:00
|
|
|
// Be conservative in the face of volatile/atomic.
|
|
|
|
if (!L->isUnordered())
|
2010-08-06 18:11:28 +00:00
|
|
|
return ModRef;
|
|
|
|
|
2010-08-03 17:27:43 +00:00
|
|
|
// If the load address doesn't alias the given address, it doesn't read
|
|
|
|
// or write the specified memory.
|
2010-11-11 21:50:19 +00:00
|
|
|
if (!alias(getLocation(L), Loc))
|
2010-08-03 17:27:43 +00:00
|
|
|
return NoModRef;
|
|
|
|
|
|
|
|
// Otherwise, a load just reads.
|
|
|
|
return Ref;
|
2003-02-26 19:26:51 +00:00
|
|
|
}
|
2002-08-22 18:25:32 +00:00
|
|
|
|
2003-02-26 19:26:51 +00:00
|
|
|
AliasAnalysis::ModRefResult
|
2010-09-14 21:25:10 +00:00
|
|
|
AliasAnalysis::getModRefInfo(const StoreInst *S, const Location &Loc) {
|
2011-08-15 20:54:19 +00:00
|
|
|
// Be conservative in the face of volatile/atomic.
|
|
|
|
if (!S->isUnordered())
|
2010-08-06 18:11:28 +00:00
|
|
|
return ModRef;
|
|
|
|
|
2010-08-06 18:10:45 +00:00
|
|
|
// If the store address cannot alias the pointer in question, then the
|
|
|
|
// specified memory cannot be modified by the store.
|
2010-11-11 21:50:19 +00:00
|
|
|
if (!alias(getLocation(S), Loc))
|
2004-01-30 22:16:42 +00:00
|
|
|
return NoModRef;
|
|
|
|
|
|
|
|
// If the pointer is a pointer to constant memory, then it could not have been
|
|
|
|
// modified by this store.
|
2010-09-14 21:25:10 +00:00
|
|
|
if (pointsToConstantMemory(Loc))
|
2010-08-03 17:27:43 +00:00
|
|
|
return NoModRef;
|
|
|
|
|
|
|
|
// Otherwise, a store just writes.
|
|
|
|
return Mod;
|
2002-08-22 18:25:32 +00:00
|
|
|
}
|
|
|
|
|
2010-08-06 18:24:38 +00:00
|
|
|
AliasAnalysis::ModRefResult
|
2010-09-14 21:25:10 +00:00
|
|
|
AliasAnalysis::getModRefInfo(const VAArgInst *V, const Location &Loc) {
|
2010-08-06 18:24:38 +00:00
|
|
|
// If the va_arg address cannot alias the pointer in question, then the
|
|
|
|
// specified memory cannot be accessed by the va_arg.
|
2010-11-11 21:50:19 +00:00
|
|
|
if (!alias(getLocation(V), Loc))
|
2010-08-06 18:24:38 +00:00
|
|
|
return NoModRef;
|
|
|
|
|
|
|
|
// If the pointer is a pointer to constant memory, then it could not have been
|
|
|
|
// modified by this va_arg.
|
2010-09-14 21:25:10 +00:00
|
|
|
if (pointsToConstantMemory(Loc))
|
2010-08-06 18:24:38 +00:00
|
|
|
return NoModRef;
|
|
|
|
|
|
|
|
// Otherwise, a va_arg reads and writes.
|
|
|
|
return ModRef;
|
|
|
|
}
|
|
|
|
|
2011-09-26 20:15:28 +00:00
|
|
|
AliasAnalysis::ModRefResult
|
|
|
|
AliasAnalysis::getModRefInfo(const AtomicCmpXchgInst *CX, const Location &Loc) {
|
|
|
|
// Acquire/Release cmpxchg has properties that matter for arbitrary addresses.
|
2014-03-11 10:48:52 +00:00
|
|
|
if (CX->getSuccessOrdering() > Monotonic)
|
2011-09-26 20:15:28 +00:00
|
|
|
return ModRef;
|
|
|
|
|
|
|
|
// If the cmpxchg address does not alias the location, it does not access it.
|
|
|
|
if (!alias(getLocation(CX), Loc))
|
|
|
|
return NoModRef;
|
|
|
|
|
|
|
|
return ModRef;
|
|
|
|
}
|
|
|
|
|
|
|
|
AliasAnalysis::ModRefResult
|
|
|
|
AliasAnalysis::getModRefInfo(const AtomicRMWInst *RMW, const Location &Loc) {
|
|
|
|
// Acquire/Release atomicrmw has properties that matter for arbitrary addresses.
|
|
|
|
if (RMW->getOrdering() > Monotonic)
|
|
|
|
return ModRef;
|
|
|
|
|
|
|
|
// If the atomicrmw address does not alias the location, it does not access it.
|
|
|
|
if (!alias(getLocation(RMW), Loc))
|
|
|
|
return NoModRef;
|
|
|
|
|
|
|
|
return ModRef;
|
|
|
|
}
|
|
|
|
|
2012-05-14 20:35:04 +00:00
|
|
|
// FIXME: this is really just shoring-up a deficiency in alias analysis.
|
|
|
|
// BasicAA isn't willing to spend linear time determining whether an alloca
|
|
|
|
// was captured before or after this particular call, while we are. However,
|
|
|
|
// with a smarter AA in place, this test is just wasting compile time.
|
|
|
|
AliasAnalysis::ModRefResult
|
|
|
|
AliasAnalysis::callCapturesBefore(const Instruction *I,
|
|
|
|
const AliasAnalysis::Location &MemLoc,
|
|
|
|
DominatorTree *DT) {
|
2014-02-18 15:33:12 +00:00
|
|
|
if (!DT || !DL) return AliasAnalysis::ModRef;
|
2012-05-14 20:35:04 +00:00
|
|
|
|
2014-02-18 15:33:12 +00:00
|
|
|
const Value *Object = GetUnderlyingObject(MemLoc.Ptr, DL);
|
2012-05-14 20:35:04 +00:00
|
|
|
if (!isIdentifiedObject(Object) || isa<GlobalValue>(Object) ||
|
|
|
|
isa<Constant>(Object))
|
|
|
|
return AliasAnalysis::ModRef;
|
|
|
|
|
|
|
|
ImmutableCallSite CS(I);
|
|
|
|
if (!CS.getInstruction() || CS.getInstruction() == Object)
|
|
|
|
return AliasAnalysis::ModRef;
|
|
|
|
|
2014-07-21 13:15:48 +00:00
|
|
|
if (llvm::PointerMayBeCapturedBefore(Object, /* ReturnCaptures */ true,
|
2014-07-21 21:30:22 +00:00
|
|
|
/* StoreCaptures */ true, I, DT,
|
|
|
|
/* include Object */ true))
|
2012-05-14 20:35:04 +00:00
|
|
|
return AliasAnalysis::ModRef;
|
|
|
|
|
|
|
|
unsigned ArgNo = 0;
|
2013-07-07 10:15:16 +00:00
|
|
|
AliasAnalysis::ModRefResult R = AliasAnalysis::NoModRef;
|
2012-05-14 20:35:04 +00:00
|
|
|
for (ImmutableCallSite::arg_iterator CI = CS.arg_begin(), CE = CS.arg_end();
|
|
|
|
CI != CE; ++CI, ++ArgNo) {
|
|
|
|
// Only look at the no-capture or byval pointer arguments. If this
|
|
|
|
// pointer were passed to arguments that were neither of these, then it
|
|
|
|
// couldn't be no-capture.
|
|
|
|
if (!(*CI)->getType()->isPointerTy() ||
|
|
|
|
(!CS.doesNotCapture(ArgNo) && !CS.isByValArgument(ArgNo)))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
// If this is a no-capture pointer argument, see if we can tell that it
|
|
|
|
// is impossible to alias the pointer we're checking. If not, we have to
|
|
|
|
// assume that the call could touch the pointer, even though it doesn't
|
|
|
|
// escape.
|
2013-07-07 10:15:16 +00:00
|
|
|
if (isNoAlias(AliasAnalysis::Location(*CI),
|
2014-10-28 11:53:30 +00:00
|
|
|
AliasAnalysis::Location(Object)))
|
2013-07-07 10:15:16 +00:00
|
|
|
continue;
|
|
|
|
if (CS.doesNotAccessMemory(ArgNo))
|
|
|
|
continue;
|
|
|
|
if (CS.onlyReadsMemory(ArgNo)) {
|
|
|
|
R = AliasAnalysis::Ref;
|
|
|
|
continue;
|
2012-05-14 20:35:04 +00:00
|
|
|
}
|
2013-07-07 10:15:16 +00:00
|
|
|
return AliasAnalysis::ModRef;
|
2012-05-14 20:35:04 +00:00
|
|
|
}
|
2013-07-07 10:15:16 +00:00
|
|
|
return R;
|
2012-05-14 20:35:04 +00:00
|
|
|
}
|
2011-09-26 20:15:28 +00:00
|
|
|
|
2002-08-22 18:25:32 +00:00
|
|
|
// AliasAnalysis destructor: DO NOT move this to the header file for
|
|
|
|
// AliasAnalysis or else clients of the AliasAnalysis class may not depend on
|
|
|
|
// the AliasAnalysis.o file in the current .a file, causing alias analysis
|
|
|
|
// support to not be included in the tool correctly!
|
|
|
|
//
|
|
|
|
AliasAnalysis::~AliasAnalysis() {}
|
|
|
|
|
2008-05-30 00:02:02 +00:00
|
|
|
/// InitializeAliasAnalysis - Subclasses must call this method to initialize the
|
2003-02-26 19:26:51 +00:00
|
|
|
/// AliasAnalysis interface before any other methods are called.
|
2002-08-22 22:46:39 +00:00
|
|
|
///
|
2003-02-26 19:26:51 +00:00
|
|
|
void AliasAnalysis::InitializeAliasAnalysis(Pass *P) {
|
2014-02-25 17:30:31 +00:00
|
|
|
DataLayoutPass *DLP = P->getAnalysisIfAvailable<DataLayoutPass>();
|
2014-04-15 04:59:12 +00:00
|
|
|
DL = DLP ? &DLP->getDataLayout() : nullptr;
|
2012-08-29 15:32:21 +00:00
|
|
|
TLI = P->getAnalysisIfAvailable<TargetLibraryInfo>();
|
2004-05-23 21:15:48 +00:00
|
|
|
AA = &P->getAnalysis<AliasAnalysis>();
|
2003-02-26 19:26:51 +00:00
|
|
|
}
|
2002-08-22 18:25:32 +00:00
|
|
|
|
2003-02-26 19:26:51 +00:00
|
|
|
// getAnalysisUsage - All alias analysis implementations should invoke this
|
2009-07-25 00:48:42 +00:00
|
|
|
// directly (using AliasAnalysis::getAnalysisUsage(AU)).
|
2003-02-26 19:26:51 +00:00
|
|
|
void AliasAnalysis::getAnalysisUsage(AnalysisUsage &AU) const {
|
2004-05-23 21:15:48 +00:00
|
|
|
AU.addRequired<AliasAnalysis>(); // All AA's chain
|
2003-02-26 19:26:51 +00:00
|
|
|
}
|
2002-08-22 18:25:32 +00:00
|
|
|
|
2012-10-08 16:38:25 +00:00
|
|
|
/// getTypeStoreSize - Return the DataLayout store size for the given type,
|
2009-07-25 00:48:42 +00:00
|
|
|
/// if known, or a conservative value otherwise.
|
|
|
|
///
|
2011-07-18 04:54:35 +00:00
|
|
|
uint64_t AliasAnalysis::getTypeStoreSize(Type *Ty) {
|
2014-02-18 15:33:12 +00:00
|
|
|
return DL ? DL->getTypeStoreSize(Ty) : UnknownSize;
|
2009-07-25 00:48:42 +00:00
|
|
|
}
|
|
|
|
|
2003-02-26 19:26:51 +00:00
|
|
|
/// canBasicBlockModify - Return true if it is possible for execution of the
|
2014-12-15 14:09:53 +00:00
|
|
|
/// specified basic block to modify the location Loc.
|
2003-02-26 19:26:51 +00:00
|
|
|
///
|
|
|
|
bool AliasAnalysis::canBasicBlockModify(const BasicBlock &BB,
|
2010-09-14 21:25:10 +00:00
|
|
|
const Location &Loc) {
|
2014-12-15 14:09:53 +00:00
|
|
|
return canInstructionRangeModRef(BB.front(), BB.back(), Loc, Mod);
|
2002-08-22 18:25:32 +00:00
|
|
|
}
|
|
|
|
|
2014-12-15 14:09:53 +00:00
|
|
|
/// canInstructionRangeModRef - Return true if it is possible for the
|
|
|
|
/// execution of the specified instructions to mod\ref (according to the
|
|
|
|
/// mode) the location Loc. The instructions to consider are all
|
|
|
|
/// of the instructions in the range of [I1,I2] INCLUSIVE.
|
|
|
|
/// I1 and I2 must be in the same basic block.
|
|
|
|
bool AliasAnalysis::canInstructionRangeModRef(const Instruction &I1,
|
2002-08-22 18:25:32 +00:00
|
|
|
const Instruction &I2,
|
2014-12-15 14:09:53 +00:00
|
|
|
const Location &Loc,
|
|
|
|
const ModRefResult Mode) {
|
2002-08-22 18:25:32 +00:00
|
|
|
assert(I1.getParent() == I2.getParent() &&
|
|
|
|
"Instructions not in same basic block!");
|
2010-08-03 21:48:53 +00:00
|
|
|
BasicBlock::const_iterator I = &I1;
|
|
|
|
BasicBlock::const_iterator E = &I2;
|
2002-08-22 18:25:32 +00:00
|
|
|
++E; // Convert from inclusive to exclusive range.
|
|
|
|
|
2003-02-26 19:26:51 +00:00
|
|
|
for (; I != E; ++I) // Check every instruction in range
|
2014-12-15 14:09:53 +00:00
|
|
|
if (getModRefInfo(I, Loc) & Mode)
|
2002-08-22 18:25:32 +00:00
|
|
|
return true;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2009-02-03 01:28:32 +00:00
|
|
|
/// isNoAliasCall - Return true if this pointer is returned by a noalias
|
|
|
|
/// function.
|
|
|
|
bool llvm::isNoAliasCall(const Value *V) {
|
|
|
|
if (isa<CallInst>(V) || isa<InvokeInst>(V))
|
2010-08-03 21:48:53 +00:00
|
|
|
return ImmutableCallSite(cast<Instruction>(V))
|
2012-12-19 07:18:57 +00:00
|
|
|
.paramHasAttr(0, Attribute::NoAlias);
|
2009-02-03 01:28:32 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-05-28 08:17:48 +00:00
|
|
|
/// isNoAliasArgument - Return true if this is an argument with the noalias
|
|
|
|
/// attribute.
|
|
|
|
bool llvm::isNoAliasArgument(const Value *V)
|
|
|
|
{
|
|
|
|
if (const Argument *A = dyn_cast<Argument>(V))
|
|
|
|
return A->hasNoAliasAttr();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2009-02-03 01:28:32 +00:00
|
|
|
/// isIdentifiedObject - Return true if this pointer refers to a distinct and
|
|
|
|
/// identifiable object. This returns true for:
|
2009-08-27 17:52:56 +00:00
|
|
|
/// Global Variables and Functions (but not Global Aliases)
|
2009-02-03 01:28:32 +00:00
|
|
|
/// Allocas and Mallocs
|
2010-07-07 14:27:09 +00:00
|
|
|
/// ByVal and NoAlias Arguments
|
|
|
|
/// NoAlias returns
|
2009-02-03 01:28:32 +00:00
|
|
|
///
|
2010-07-07 14:27:09 +00:00
|
|
|
bool llvm::isIdentifiedObject(const Value *V) {
|
2010-06-29 00:50:39 +00:00
|
|
|
if (isa<AllocaInst>(V))
|
2009-08-27 17:52:56 +00:00
|
|
|
return true;
|
|
|
|
if (isa<GlobalValue>(V) && !isa<GlobalAlias>(V))
|
2009-02-03 01:28:32 +00:00
|
|
|
return true;
|
2010-07-07 14:27:09 +00:00
|
|
|
if (isNoAliasCall(V))
|
|
|
|
return true;
|
|
|
|
if (const Argument *A = dyn_cast<Argument>(V))
|
|
|
|
return A->hasNoAliasAttr() || A->hasByValAttr();
|
2009-02-03 01:28:32 +00:00
|
|
|
return false;
|
|
|
|
}
|
2014-07-21 12:27:23 +00:00
|
|
|
|
|
|
|
/// isIdentifiedFunctionLocal - Return true if V is umabigously identified
|
|
|
|
/// at the function-level. Different IdentifiedFunctionLocals can't alias.
|
|
|
|
/// Further, an IdentifiedFunctionLocal can not alias with any function
|
|
|
|
/// arguments other than itself, which is not necessarily true for
|
|
|
|
/// IdentifiedObjects.
|
|
|
|
bool llvm::isIdentifiedFunctionLocal(const Value *V)
|
|
|
|
{
|
|
|
|
return isa<AllocaInst>(V) || isNoAliasCall(V) || isNoAliasArgument(V);
|
|
|
|
}
|