2002-08-23 02:25:32 +08:00
|
|
|
//===- AliasAnalysis.cpp - Generic Alias Analysis Interface Implementation -==//
|
2005-04-22 05:13:18 +08:00
|
|
|
//
|
2003-10-21 03:43:21 +08:00
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2007-12-30 04:36:04 +08:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
2005-04-22 05:13:18 +08:00
|
|
|
//
|
2003-10-21 03:43:21 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
2002-08-23 02:25:32 +08: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-27 03:41:54 +08:00
|
|
|
#include "llvm/Analysis/AliasAnalysis.h"
|
2013-07-27 09:24:00 +08:00
|
|
|
#include "llvm/Analysis/CFG.h"
|
2014-01-07 19:48:04 +08:00
|
|
|
#include "llvm/Analysis/CaptureTracking.h"
|
2015-01-15 10:16:27 +08:00
|
|
|
#include "llvm/Analysis/TargetLibraryInfo.h"
|
2012-05-15 04:35:04 +08:00
|
|
|
#include "llvm/Analysis/ValueTracking.h"
|
2013-01-02 19:36:10 +08:00
|
|
|
#include "llvm/IR/BasicBlock.h"
|
|
|
|
#include "llvm/IR/DataLayout.h"
|
2014-01-13 17:26:24 +08:00
|
|
|
#include "llvm/IR/Dominators.h"
|
2013-01-02 19:36:10 +08: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-04 00:50:05 +08:00
|
|
|
#include "llvm/Pass.h"
|
2004-03-15 12:07:29 +08:00
|
|
|
using namespace llvm;
|
2003-11-12 06:41:34 +08:00
|
|
|
|
2002-08-23 02:25:32 +08:00
|
|
|
// Register the AliasAnalysis interface, providing a nice name to refer to.
|
2010-10-20 01:21:58 +08:00
|
|
|
INITIALIZE_ANALYSIS_GROUP(AliasAnalysis, "Alias Analysis", NoAA)
|
2007-05-03 09:11:54 +08:00
|
|
|
char AliasAnalysis::ID = 0;
|
2002-08-23 02:25:32 +08:00
|
|
|
|
2004-05-24 05:15:48 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Default chaining methods
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2015-06-22 10:16:51 +08:00
|
|
|
AliasResult AliasAnalysis::alias(const MemoryLocation &LocA,
|
|
|
|
const MemoryLocation &LocB) {
|
2004-05-24 05:15:48 +08:00
|
|
|
assert(AA && "AA didn't call InitializeAliasAnalysis in its run method!");
|
2010-09-15 05:25:10 +08:00
|
|
|
return AA->alias(LocA, LocB);
|
2004-05-24 05:15:48 +08:00
|
|
|
}
|
|
|
|
|
2015-06-17 15:18:54 +08:00
|
|
|
bool AliasAnalysis::pointsToConstantMemory(const MemoryLocation &Loc,
|
2010-11-09 00:45:26 +08:00
|
|
|
bool OrLocal) {
|
2004-05-24 05:15:48 +08:00
|
|
|
assert(AA && "AA didn't call InitializeAliasAnalysis in its run method!");
|
2010-11-09 00:45:26 +08:00
|
|
|
return AA->pointsToConstantMemory(Loc, OrLocal);
|
2004-05-24 05:15:48 +08:00
|
|
|
}
|
|
|
|
|
2015-07-23 07:15:57 +08:00
|
|
|
ModRefInfo AliasAnalysis::getArgModRefInfo(ImmutableCallSite CS,
|
|
|
|
unsigned ArgIdx) {
|
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).
llvm-svn: 213219
2014-07-17 09:28:25 +08:00
|
|
|
assert(AA && "AA didn't call InitializeAliasAnalysis in its run method!");
|
2015-06-17 15:12:40 +08:00
|
|
|
return AA->getArgModRefInfo(CS, ArgIdx);
|
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).
llvm-svn: 213219
2014-07-17 09:28:25 +08:00
|
|
|
}
|
|
|
|
|
2015-07-23 07:15:57 +08:00
|
|
|
ModRefInfo AliasAnalysis::getModRefInfo(Instruction *I,
|
|
|
|
ImmutableCallSite Call) {
|
2015-04-14 07:25:41 +08:00
|
|
|
// We may have two calls
|
|
|
|
if (auto CS = ImmutableCallSite(I)) {
|
|
|
|
// Check if the two calls modify the same memory
|
|
|
|
return getModRefInfo(Call, CS);
|
|
|
|
} else {
|
|
|
|
// Otherwise, check if the call modifies or references the
|
|
|
|
// location this memory access defines. The best we can say
|
|
|
|
// is that if the call references what this instruction
|
|
|
|
// defines, it must be clobbered by this location.
|
2015-06-17 15:18:54 +08:00
|
|
|
const MemoryLocation DefLoc = MemoryLocation::get(I);
|
2015-07-23 07:15:57 +08:00
|
|
|
if (getModRefInfo(Call, DefLoc) != MRI_NoModRef)
|
|
|
|
return MRI_ModRef;
|
2015-04-14 07:25:41 +08:00
|
|
|
}
|
2015-07-23 07:15:57 +08:00
|
|
|
return MRI_NoModRef;
|
2015-04-14 07:25:41 +08:00
|
|
|
}
|
2011-01-04 05:38:41 +08:00
|
|
|
|
2015-07-23 07:15:57 +08:00
|
|
|
ModRefInfo AliasAnalysis::getModRefInfo(ImmutableCallSite CS,
|
|
|
|
const MemoryLocation &Loc) {
|
2010-10-26 00:28:57 +08:00
|
|
|
assert(AA && "AA didn't call InitializeAliasAnalysis in its run method!");
|
2010-08-06 09:25:49 +08:00
|
|
|
|
2015-07-23 07:15:57 +08:00
|
|
|
auto MRB = getModRefBehavior(CS);
|
|
|
|
if (MRB == FMRB_DoesNotAccessMemory)
|
|
|
|
return MRI_NoModRef;
|
2010-08-06 09:25:49 +08:00
|
|
|
|
2015-07-23 07:15:57 +08:00
|
|
|
ModRefInfo Mask = MRI_ModRef;
|
2010-11-10 04:06:55 +08:00
|
|
|
if (onlyReadsMemory(MRB))
|
2015-07-23 07:15:57 +08:00
|
|
|
Mask = MRI_Ref;
|
2010-11-10 04:06:55 +08:00
|
|
|
|
2010-11-11 02:17:28 +08:00
|
|
|
if (onlyAccessesArgPointees(MRB)) {
|
2010-08-06 09:25:49 +08:00
|
|
|
bool doesAlias = false;
|
2015-07-23 07:15:57 +08:00
|
|
|
ModRefInfo AllArgsMask = MRI_NoModRef;
|
2011-04-28 02:39:03 +08:00
|
|
|
if (doesAccessArgPointees(MRB)) {
|
2010-11-11 02:17:28 +08:00
|
|
|
for (ImmutableCallSite::arg_iterator AI = CS.arg_begin(), AE = CS.arg_end();
|
2011-04-28 02:39:03 +08:00
|
|
|
AI != AE; ++AI) {
|
|
|
|
const Value *Arg = *AI;
|
|
|
|
if (!Arg->getType()->isPointerTy())
|
|
|
|
continue;
|
2015-06-17 15:12:40 +08:00
|
|
|
unsigned ArgIdx = std::distance(CS.arg_begin(), AI);
|
2015-06-17 15:18:54 +08:00
|
|
|
MemoryLocation ArgLoc =
|
|
|
|
MemoryLocation::getForArgument(CS, ArgIdx, *TLI);
|
2015-06-17 15:12:40 +08:00
|
|
|
if (!isNoAlias(ArgLoc, Loc)) {
|
2015-07-23 07:15:57 +08:00
|
|
|
ModRefInfo ArgMask = getArgModRefInfo(CS, ArgIdx);
|
2010-11-11 02:17:28 +08:00
|
|
|
doesAlias = true;
|
2015-07-23 07:15:57 +08:00
|
|
|
AllArgsMask = ModRefInfo(AllArgsMask | ArgMask);
|
2010-11-11 02:17:28 +08:00
|
|
|
}
|
2011-04-28 02:39:03 +08:00
|
|
|
}
|
|
|
|
}
|
2010-08-06 09:25:49 +08:00
|
|
|
if (!doesAlias)
|
2015-07-23 07:15:57 +08:00
|
|
|
return MRI_NoModRef;
|
|
|
|
Mask = ModRefInfo(Mask & AllArgsMask);
|
2010-08-06 09:25:49 +08:00
|
|
|
}
|
|
|
|
|
2010-09-15 05:25:10 +08:00
|
|
|
// If Loc is a constant memory location, the call definitely could not
|
2010-08-06 09:25:49 +08:00
|
|
|
// modify the memory location.
|
2015-07-23 07:15:57 +08:00
|
|
|
if ((Mask & MRI_Mod) && pointsToConstantMemory(Loc))
|
|
|
|
Mask = ModRefInfo(Mask & ~MRI_Mod);
|
2010-08-06 09:25:49 +08:00
|
|
|
|
2010-10-26 00:29:52 +08:00
|
|
|
// If this is the end of the chain, don't forward.
|
2010-08-06 09:25:49 +08: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.
|
2015-07-23 07:15:57 +08:00
|
|
|
return ModRefInfo(AA->getModRefInfo(CS, Loc) & Mask);
|
2010-08-06 09:25:49 +08:00
|
|
|
}
|
|
|
|
|
2015-07-23 07:15:57 +08:00
|
|
|
ModRefInfo AliasAnalysis::getModRefInfo(ImmutableCallSite CS1,
|
|
|
|
ImmutableCallSite CS2) {
|
2010-10-26 00:28:57 +08:00
|
|
|
assert(AA && "AA didn't call InitializeAliasAnalysis in its run method!");
|
2010-08-06 09:25:49 +08:00
|
|
|
|
|
|
|
// If CS1 or CS2 are readnone, they don't interact.
|
2015-07-23 07:15:57 +08:00
|
|
|
auto CS1B = getModRefBehavior(CS1);
|
|
|
|
if (CS1B == FMRB_DoesNotAccessMemory)
|
|
|
|
return MRI_NoModRef;
|
2010-08-06 09:25:49 +08:00
|
|
|
|
2015-07-23 07:15:57 +08:00
|
|
|
auto CS2B = getModRefBehavior(CS2);
|
|
|
|
if (CS2B == FMRB_DoesNotAccessMemory)
|
|
|
|
return MRI_NoModRef;
|
2010-08-06 09:25:49 +08:00
|
|
|
|
|
|
|
// If they both only read from memory, there is no dependence.
|
2010-11-10 04:06:55 +08:00
|
|
|
if (onlyReadsMemory(CS1B) && onlyReadsMemory(CS2B))
|
2015-07-23 07:15:57 +08:00
|
|
|
return MRI_NoModRef;
|
2010-08-06 09:25:49 +08:00
|
|
|
|
2015-07-23 07:15:57 +08:00
|
|
|
ModRefInfo Mask = MRI_ModRef;
|
2010-08-06 09:25:49 +08:00
|
|
|
|
|
|
|
// If CS1 only reads memory, the only dependence on CS2 can be
|
|
|
|
// from CS1 reading memory written by CS2.
|
2010-11-10 04:06:55 +08:00
|
|
|
if (onlyReadsMemory(CS1B))
|
2015-07-23 07:15:57 +08:00
|
|
|
Mask = ModRefInfo(Mask & MRI_Ref);
|
2010-08-06 09:25:49 +08:00
|
|
|
|
|
|
|
// 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-11 02:17:28 +08:00
|
|
|
if (onlyAccessesArgPointees(CS2B)) {
|
2015-07-23 07:15:57 +08:00
|
|
|
ModRefInfo R = MRI_NoModRef;
|
2011-04-28 02:39:03 +08:00
|
|
|
if (doesAccessArgPointees(CS2B)) {
|
2010-11-11 02:17:28 +08:00
|
|
|
for (ImmutableCallSite::arg_iterator
|
|
|
|
I = CS2.arg_begin(), E = CS2.arg_end(); I != E; ++I) {
|
2011-04-28 02:39:03 +08:00
|
|
|
const Value *Arg = *I;
|
|
|
|
if (!Arg->getType()->isPointerTy())
|
|
|
|
continue;
|
2015-06-17 15:12:40 +08:00
|
|
|
unsigned CS2ArgIdx = std::distance(CS2.arg_begin(), I);
|
2015-06-17 15:18:54 +08:00
|
|
|
auto CS2ArgLoc = MemoryLocation::getForArgument(CS2, CS2ArgIdx, *TLI);
|
2015-06-17 15:12:40 +08:00
|
|
|
|
|
|
|
// ArgMask indicates what CS2 might do to CS2ArgLoc, and the dependence of
|
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).
llvm-svn: 213219
2014-07-17 09:28:25 +08:00
|
|
|
// CS1 on that location is the inverse.
|
2015-07-23 07:15:57 +08:00
|
|
|
ModRefInfo ArgMask = getArgModRefInfo(CS2, CS2ArgIdx);
|
|
|
|
if (ArgMask == MRI_Mod)
|
|
|
|
ArgMask = MRI_ModRef;
|
|
|
|
else if (ArgMask == MRI_Ref)
|
|
|
|
ArgMask = MRI_Mod;
|
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).
llvm-svn: 213219
2014-07-17 09:28:25 +08:00
|
|
|
|
2015-07-23 07:15:57 +08:00
|
|
|
R = ModRefInfo((R | (getModRefInfo(CS1, CS2ArgLoc) & ArgMask)) & Mask);
|
2010-11-11 02:17:28 +08:00
|
|
|
if (R == Mask)
|
|
|
|
break;
|
|
|
|
}
|
2011-04-28 02:39:03 +08:00
|
|
|
}
|
2010-08-06 09:25:49 +08: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-11 02:17:28 +08:00
|
|
|
if (onlyAccessesArgPointees(CS1B)) {
|
2015-07-23 07:15:57 +08:00
|
|
|
ModRefInfo R = MRI_NoModRef;
|
2011-04-28 02:39:03 +08:00
|
|
|
if (doesAccessArgPointees(CS1B)) {
|
2010-11-11 02:17:28 +08:00
|
|
|
for (ImmutableCallSite::arg_iterator
|
2011-04-28 02:39:03 +08:00
|
|
|
I = CS1.arg_begin(), E = CS1.arg_end(); I != E; ++I) {
|
|
|
|
const Value *Arg = *I;
|
|
|
|
if (!Arg->getType()->isPointerTy())
|
|
|
|
continue;
|
2015-06-17 15:12:40 +08:00
|
|
|
unsigned CS1ArgIdx = std::distance(CS1.arg_begin(), I);
|
2015-06-17 15:18:54 +08:00
|
|
|
auto CS1ArgLoc = MemoryLocation::getForArgument(CS1, CS1ArgIdx, *TLI);
|
2015-06-17 15:12:40 +08:00
|
|
|
|
|
|
|
// ArgMask indicates what CS1 might do to CS1ArgLoc; if CS1 might Mod
|
|
|
|
// CS1ArgLoc, then we care about either a Mod or a Ref by CS2. If CS1
|
2014-10-28 19:53:30 +08:00
|
|
|
// might Ref, then we care only about a Mod by CS2.
|
2015-07-23 07:15:57 +08:00
|
|
|
ModRefInfo ArgMask = getArgModRefInfo(CS1, CS1ArgIdx);
|
|
|
|
ModRefInfo ArgR = getModRefInfo(CS2, CS1ArgLoc);
|
|
|
|
if (((ArgMask & MRI_Mod) != MRI_NoModRef &&
|
|
|
|
(ArgR & MRI_ModRef) != MRI_NoModRef) ||
|
|
|
|
((ArgMask & MRI_Ref) != MRI_NoModRef &&
|
|
|
|
(ArgR & MRI_Mod) != MRI_NoModRef))
|
|
|
|
R = ModRefInfo((R | ArgMask) & Mask);
|
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).
llvm-svn: 213219
2014-07-17 09:28:25 +08:00
|
|
|
|
|
|
|
if (R == Mask)
|
2010-11-11 02:17:28 +08:00
|
|
|
break;
|
2011-04-28 02:39:03 +08: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).
llvm-svn: 213219
2014-07-17 09:28:25 +08:00
|
|
|
return R;
|
2010-08-06 09:25:49 +08:00
|
|
|
}
|
|
|
|
|
2010-10-26 00:29:52 +08:00
|
|
|
// If this is the end of the chain, don't forward.
|
2010-08-06 09:25:49 +08: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.
|
2015-07-23 07:15:57 +08:00
|
|
|
return ModRefInfo(AA->getModRefInfo(CS1, CS2) & Mask);
|
2010-08-06 09:25:49 +08:00
|
|
|
}
|
|
|
|
|
2015-07-23 07:15:57 +08:00
|
|
|
FunctionModRefBehavior AliasAnalysis::getModRefBehavior(ImmutableCallSite CS) {
|
2010-10-26 00:28:57 +08:00
|
|
|
assert(AA && "AA didn't call InitializeAliasAnalysis in its run method!");
|
2010-08-06 09:25:49 +08:00
|
|
|
|
2015-07-23 07:15:57 +08:00
|
|
|
auto Min = FMRB_UnknownModRefBehavior;
|
2010-08-06 09:25:49 +08:00
|
|
|
|
|
|
|
// 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-26 00:29:52 +08:00
|
|
|
// If this is the end of the chain, don't forward.
|
2010-08-06 09:25:49 +08: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.
|
2015-07-23 07:15:57 +08:00
|
|
|
return FunctionModRefBehavior(AA->getModRefBehavior(CS) & Min);
|
2010-08-06 09:25:49 +08:00
|
|
|
}
|
|
|
|
|
2015-07-23 07:15:57 +08:00
|
|
|
FunctionModRefBehavior AliasAnalysis::getModRefBehavior(const Function *F) {
|
2004-05-24 05:15:48 +08:00
|
|
|
assert(AA && "AA didn't call InitializeAliasAnalysis in its run method!");
|
2010-08-06 09:25:49 +08:00
|
|
|
return AA->getModRefBehavior(F);
|
2004-05-24 05:15:48 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// AliasAnalysis non-virtual helper method implementation
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2015-07-23 07:15:57 +08:00
|
|
|
ModRefInfo AliasAnalysis::getModRefInfo(const LoadInst *L,
|
|
|
|
const MemoryLocation &Loc) {
|
2011-08-16 04:54:19 +08:00
|
|
|
// Be conservative in the face of volatile/atomic.
|
|
|
|
if (!L->isUnordered())
|
2015-07-23 07:15:57 +08:00
|
|
|
return MRI_ModRef;
|
2010-08-07 02:11:28 +08:00
|
|
|
|
2010-08-04 01:27:43 +08:00
|
|
|
// If the load address doesn't alias the given address, it doesn't read
|
|
|
|
// or write the specified memory.
|
2015-06-04 10:03:15 +08:00
|
|
|
if (Loc.Ptr && !alias(MemoryLocation::get(L), Loc))
|
2015-07-23 07:15:57 +08:00
|
|
|
return MRI_NoModRef;
|
2010-08-04 01:27:43 +08:00
|
|
|
|
|
|
|
// Otherwise, a load just reads.
|
2015-07-23 07:15:57 +08:00
|
|
|
return MRI_Ref;
|
2003-02-27 03:26:51 +08:00
|
|
|
}
|
2002-08-23 02:25:32 +08:00
|
|
|
|
2015-07-23 07:15:57 +08:00
|
|
|
ModRefInfo AliasAnalysis::getModRefInfo(const StoreInst *S,
|
|
|
|
const MemoryLocation &Loc) {
|
2011-08-16 04:54:19 +08:00
|
|
|
// Be conservative in the face of volatile/atomic.
|
|
|
|
if (!S->isUnordered())
|
2015-07-23 07:15:57 +08:00
|
|
|
return MRI_ModRef;
|
2010-08-07 02:11:28 +08:00
|
|
|
|
2015-04-14 07:05:45 +08:00
|
|
|
if (Loc.Ptr) {
|
|
|
|
// If the store address cannot alias the pointer in question, then the
|
|
|
|
// specified memory cannot be modified by the store.
|
2015-06-04 10:03:15 +08:00
|
|
|
if (!alias(MemoryLocation::get(S), Loc))
|
2015-07-23 07:15:57 +08:00
|
|
|
return MRI_NoModRef;
|
2004-01-31 06:16:42 +08:00
|
|
|
|
2015-04-14 07:05:45 +08:00
|
|
|
// If the pointer is a pointer to constant memory, then it could not have
|
|
|
|
// been modified by this store.
|
|
|
|
if (pointsToConstantMemory(Loc))
|
2015-07-23 07:15:57 +08:00
|
|
|
return MRI_NoModRef;
|
2015-04-14 07:05:45 +08:00
|
|
|
}
|
2010-08-04 01:27:43 +08:00
|
|
|
|
|
|
|
// Otherwise, a store just writes.
|
2015-07-23 07:15:57 +08:00
|
|
|
return MRI_Mod;
|
2002-08-23 02:25:32 +08:00
|
|
|
}
|
|
|
|
|
2015-07-23 07:15:57 +08:00
|
|
|
ModRefInfo AliasAnalysis::getModRefInfo(const VAArgInst *V,
|
|
|
|
const MemoryLocation &Loc) {
|
2010-08-07 02:24:38 +08:00
|
|
|
|
2015-04-29 03:19:14 +08:00
|
|
|
if (Loc.Ptr) {
|
|
|
|
// If the va_arg address cannot alias the pointer in question, then the
|
|
|
|
// specified memory cannot be accessed by the va_arg.
|
2015-06-04 10:03:15 +08:00
|
|
|
if (!alias(MemoryLocation::get(V), Loc))
|
2015-07-23 07:15:57 +08:00
|
|
|
return MRI_NoModRef;
|
2015-04-29 03:19:14 +08:00
|
|
|
|
|
|
|
// If the pointer is a pointer to constant memory, then it could not have
|
|
|
|
// been modified by this va_arg.
|
|
|
|
if (pointsToConstantMemory(Loc))
|
2015-07-23 07:15:57 +08:00
|
|
|
return MRI_NoModRef;
|
2015-04-29 03:19:14 +08:00
|
|
|
}
|
2010-08-07 02:24:38 +08:00
|
|
|
|
|
|
|
// Otherwise, a va_arg reads and writes.
|
2015-07-23 07:15:57 +08:00
|
|
|
return MRI_ModRef;
|
2010-08-07 02:24:38 +08:00
|
|
|
}
|
|
|
|
|
2015-07-23 07:15:57 +08:00
|
|
|
ModRefInfo AliasAnalysis::getModRefInfo(const AtomicCmpXchgInst *CX,
|
|
|
|
const MemoryLocation &Loc) {
|
2011-09-27 04:15:28 +08:00
|
|
|
// Acquire/Release cmpxchg has properties that matter for arbitrary addresses.
|
2014-03-11 18:48:52 +08:00
|
|
|
if (CX->getSuccessOrdering() > Monotonic)
|
2015-07-23 07:15:57 +08:00
|
|
|
return MRI_ModRef;
|
2011-09-27 04:15:28 +08:00
|
|
|
|
|
|
|
// If the cmpxchg address does not alias the location, it does not access it.
|
2015-06-04 10:03:15 +08:00
|
|
|
if (Loc.Ptr && !alias(MemoryLocation::get(CX), Loc))
|
2015-07-23 07:15:57 +08:00
|
|
|
return MRI_NoModRef;
|
2011-09-27 04:15:28 +08:00
|
|
|
|
2015-07-23 07:15:57 +08:00
|
|
|
return MRI_ModRef;
|
2011-09-27 04:15:28 +08:00
|
|
|
}
|
|
|
|
|
2015-07-23 07:15:57 +08:00
|
|
|
ModRefInfo AliasAnalysis::getModRefInfo(const AtomicRMWInst *RMW,
|
|
|
|
const MemoryLocation &Loc) {
|
2011-09-27 04:15:28 +08:00
|
|
|
// Acquire/Release atomicrmw has properties that matter for arbitrary addresses.
|
|
|
|
if (RMW->getOrdering() > Monotonic)
|
2015-07-23 07:15:57 +08:00
|
|
|
return MRI_ModRef;
|
2011-09-27 04:15:28 +08:00
|
|
|
|
|
|
|
// If the atomicrmw address does not alias the location, it does not access it.
|
2015-06-04 10:03:15 +08:00
|
|
|
if (Loc.Ptr && !alias(MemoryLocation::get(RMW), Loc))
|
2015-07-23 07:15:57 +08:00
|
|
|
return MRI_NoModRef;
|
2011-09-27 04:15:28 +08:00
|
|
|
|
2015-07-23 07:15:57 +08:00
|
|
|
return MRI_ModRef;
|
2011-09-27 04:15:28 +08:00
|
|
|
}
|
|
|
|
|
2012-05-15 04:35:04 +08: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.
|
2015-07-23 07:15:57 +08:00
|
|
|
ModRefInfo AliasAnalysis::callCapturesBefore(const Instruction *I,
|
|
|
|
const MemoryLocation &MemLoc,
|
|
|
|
DominatorTree *DT) {
|
2015-03-10 10:37:25 +08:00
|
|
|
if (!DT)
|
2015-07-23 07:15:57 +08:00
|
|
|
return MRI_ModRef;
|
2012-05-15 04:35:04 +08:00
|
|
|
|
2015-03-10 10:37:25 +08:00
|
|
|
const Value *Object = GetUnderlyingObject(MemLoc.Ptr, *DL);
|
2012-05-15 04:35:04 +08:00
|
|
|
if (!isIdentifiedObject(Object) || isa<GlobalValue>(Object) ||
|
|
|
|
isa<Constant>(Object))
|
2015-07-23 07:15:57 +08:00
|
|
|
return MRI_ModRef;
|
2012-05-15 04:35:04 +08:00
|
|
|
|
|
|
|
ImmutableCallSite CS(I);
|
|
|
|
if (!CS.getInstruction() || CS.getInstruction() == Object)
|
2015-07-23 07:15:57 +08:00
|
|
|
return MRI_ModRef;
|
2012-05-15 04:35:04 +08:00
|
|
|
|
2014-07-21 21:15:48 +08:00
|
|
|
if (llvm::PointerMayBeCapturedBefore(Object, /* ReturnCaptures */ true,
|
2014-07-22 05:30:22 +08:00
|
|
|
/* StoreCaptures */ true, I, DT,
|
|
|
|
/* include Object */ true))
|
2015-07-23 07:15:57 +08:00
|
|
|
return MRI_ModRef;
|
2012-05-15 04:35:04 +08:00
|
|
|
|
|
|
|
unsigned ArgNo = 0;
|
2015-07-23 07:15:57 +08:00
|
|
|
ModRefInfo R = MRI_NoModRef;
|
2012-05-15 04:35:04 +08: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.
|
2015-06-17 15:18:54 +08:00
|
|
|
if (isNoAlias(MemoryLocation(*CI), MemoryLocation(Object)))
|
2013-07-07 18:15:16 +08:00
|
|
|
continue;
|
|
|
|
if (CS.doesNotAccessMemory(ArgNo))
|
|
|
|
continue;
|
|
|
|
if (CS.onlyReadsMemory(ArgNo)) {
|
2015-07-23 07:15:57 +08:00
|
|
|
R = MRI_Ref;
|
2013-07-07 18:15:16 +08:00
|
|
|
continue;
|
2012-05-15 04:35:04 +08:00
|
|
|
}
|
2015-07-23 07:15:57 +08:00
|
|
|
return MRI_ModRef;
|
2012-05-15 04:35:04 +08:00
|
|
|
}
|
2013-07-07 18:15:16 +08:00
|
|
|
return R;
|
2012-05-15 04:35:04 +08:00
|
|
|
}
|
2011-09-27 04:15:28 +08:00
|
|
|
|
2002-08-23 02:25:32 +08: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 08:02:02 +08:00
|
|
|
/// InitializeAliasAnalysis - Subclasses must call this method to initialize the
|
2003-02-27 03:26:51 +08:00
|
|
|
/// AliasAnalysis interface before any other methods are called.
|
2002-08-23 06:46:39 +08:00
|
|
|
///
|
2015-03-05 02:43:29 +08:00
|
|
|
void AliasAnalysis::InitializeAliasAnalysis(Pass *P, const DataLayout *NewDL) {
|
|
|
|
DL = NewDL;
|
2015-01-15 18:41:28 +08:00
|
|
|
auto *TLIP = P->getAnalysisIfAvailable<TargetLibraryInfoWrapperPass>();
|
|
|
|
TLI = TLIP ? &TLIP->getTLI() : nullptr;
|
2004-05-24 05:15:48 +08:00
|
|
|
AA = &P->getAnalysis<AliasAnalysis>();
|
2003-02-27 03:26:51 +08:00
|
|
|
}
|
2002-08-23 02:25:32 +08:00
|
|
|
|
2003-02-27 03:26:51 +08:00
|
|
|
// getAnalysisUsage - All alias analysis implementations should invoke this
|
2009-07-25 08:48:42 +08:00
|
|
|
// directly (using AliasAnalysis::getAnalysisUsage(AU)).
|
2003-02-27 03:26:51 +08:00
|
|
|
void AliasAnalysis::getAnalysisUsage(AnalysisUsage &AU) const {
|
2004-05-24 05:15:48 +08:00
|
|
|
AU.addRequired<AliasAnalysis>(); // All AA's chain
|
2003-02-27 03:26:51 +08:00
|
|
|
}
|
2002-08-23 02:25:32 +08:00
|
|
|
|
2012-10-09 00:38:25 +08:00
|
|
|
/// getTypeStoreSize - Return the DataLayout store size for the given type,
|
2009-07-25 08:48:42 +08:00
|
|
|
/// if known, or a conservative value otherwise.
|
|
|
|
///
|
2011-07-18 12:54:35 +08:00
|
|
|
uint64_t AliasAnalysis::getTypeStoreSize(Type *Ty) {
|
2015-06-17 15:21:38 +08:00
|
|
|
return DL ? DL->getTypeStoreSize(Ty) : MemoryLocation::UnknownSize;
|
2009-07-25 08:48:42 +08:00
|
|
|
}
|
|
|
|
|
2003-02-27 03:26:51 +08:00
|
|
|
/// canBasicBlockModify - Return true if it is possible for execution of the
|
2014-12-15 22:09:53 +08:00
|
|
|
/// specified basic block to modify the location Loc.
|
2003-02-27 03:26:51 +08:00
|
|
|
///
|
|
|
|
bool AliasAnalysis::canBasicBlockModify(const BasicBlock &BB,
|
2015-06-17 15:18:54 +08:00
|
|
|
const MemoryLocation &Loc) {
|
2015-07-23 07:15:57 +08:00
|
|
|
return canInstructionRangeModRef(BB.front(), BB.back(), Loc, MRI_Mod);
|
2002-08-23 02:25:32 +08:00
|
|
|
}
|
|
|
|
|
2014-12-15 22:09:53 +08: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.
|
2015-05-13 23:04:14 +08:00
|
|
|
/// I1 and I2 must be in the same basic block.
|
2014-12-15 22:09:53 +08:00
|
|
|
bool AliasAnalysis::canInstructionRangeModRef(const Instruction &I1,
|
2002-08-23 02:25:32 +08:00
|
|
|
const Instruction &I2,
|
2015-06-17 15:18:54 +08:00
|
|
|
const MemoryLocation &Loc,
|
2015-07-23 07:15:57 +08:00
|
|
|
const ModRefInfo Mode) {
|
2002-08-23 02:25:32 +08:00
|
|
|
assert(I1.getParent() == I2.getParent() &&
|
|
|
|
"Instructions not in same basic block!");
|
2010-08-04 05:48:53 +08:00
|
|
|
BasicBlock::const_iterator I = &I1;
|
|
|
|
BasicBlock::const_iterator E = &I2;
|
2002-08-23 02:25:32 +08:00
|
|
|
++E; // Convert from inclusive to exclusive range.
|
|
|
|
|
2003-02-27 03:26:51 +08:00
|
|
|
for (; I != E; ++I) // Check every instruction in range
|
2014-12-15 22:09:53 +08:00
|
|
|
if (getModRefInfo(I, Loc) & Mode)
|
2002-08-23 02:25:32 +08:00
|
|
|
return true;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2009-02-03 09:28:32 +08: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-04 05:48:53 +08:00
|
|
|
return ImmutableCallSite(cast<Instruction>(V))
|
2012-12-19 15:18:57 +08:00
|
|
|
.paramHasAttr(0, Attribute::NoAlias);
|
2009-02-03 09:28:32 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-05-28 16:17:48 +08: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 09:28:32 +08:00
|
|
|
/// isIdentifiedObject - Return true if this pointer refers to a distinct and
|
|
|
|
/// identifiable object. This returns true for:
|
2009-08-28 01:52:56 +08:00
|
|
|
/// Global Variables and Functions (but not Global Aliases)
|
2009-02-03 09:28:32 +08:00
|
|
|
/// Allocas and Mallocs
|
2010-07-07 22:27:09 +08:00
|
|
|
/// ByVal and NoAlias Arguments
|
|
|
|
/// NoAlias returns
|
2009-02-03 09:28:32 +08:00
|
|
|
///
|
2010-07-07 22:27:09 +08:00
|
|
|
bool llvm::isIdentifiedObject(const Value *V) {
|
2010-06-29 08:50:39 +08:00
|
|
|
if (isa<AllocaInst>(V))
|
2009-08-28 01:52:56 +08:00
|
|
|
return true;
|
|
|
|
if (isa<GlobalValue>(V) && !isa<GlobalAlias>(V))
|
2009-02-03 09:28:32 +08:00
|
|
|
return true;
|
2010-07-07 22:27:09 +08:00
|
|
|
if (isNoAliasCall(V))
|
|
|
|
return true;
|
|
|
|
if (const Argument *A = dyn_cast<Argument>(V))
|
|
|
|
return A->hasNoAliasAttr() || A->hasByValAttr();
|
2009-02-03 09:28:32 +08:00
|
|
|
return false;
|
|
|
|
}
|
2014-07-21 20:27:23 +08: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);
|
|
|
|
}
|