2010-10-19 23:09:08 +00:00
|
|
|
//===- NoAliasAnalysis.cpp - Minimal Alias Analysis Impl ------------------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file defines the default implementation of the Alias Analysis interface
|
|
|
|
// that simply returns "I don't know" for all queries.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "llvm/Analysis/Passes.h"
|
2012-12-03 16:50:05 +00:00
|
|
|
#include "llvm/Analysis/AliasAnalysis.h"
|
2013-01-02 11:36:10 +00:00
|
|
|
#include "llvm/IR/DataLayout.h"
|
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
|
|
|
#include "llvm/IR/LLVMContext.h"
|
2015-03-04 18:43:29 +00:00
|
|
|
#include "llvm/IR/Module.h"
|
2012-12-03 16:50:05 +00:00
|
|
|
#include "llvm/Pass.h"
|
2010-10-19 23:09:08 +00:00
|
|
|
using namespace llvm;
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
/// NoAA - This class implements the -no-aa pass, which always returns "I
|
|
|
|
/// don't know" for alias queries. NoAA is unlike other alias analysis
|
|
|
|
/// implementations, in that it does not chain to a previous analysis. As
|
|
|
|
/// such it doesn't follow many of the rules that other alias analyses must.
|
|
|
|
///
|
|
|
|
struct NoAA : public ImmutablePass, public AliasAnalysis {
|
|
|
|
static char ID; // Class identification, replacement for typeinfo
|
|
|
|
NoAA() : ImmutablePass(ID) {
|
|
|
|
initializeNoAAPass(*PassRegistry::getPassRegistry());
|
|
|
|
}
|
|
|
|
|
2014-03-05 07:30:04 +00:00
|
|
|
void getAnalysisUsage(AnalysisUsage &AU) const override {}
|
2010-10-19 23:09:08 +00:00
|
|
|
|
2015-03-04 18:43:29 +00:00
|
|
|
bool doInitialization(Module &M) override {
|
2010-10-19 23:09:08 +00:00
|
|
|
// Note: NoAA does not call InitializeAliasAnalysis because it's
|
|
|
|
// special and does not support chaining.
|
2015-03-04 18:43:29 +00:00
|
|
|
DL = &M.getDataLayout();
|
|
|
|
return true;
|
2010-10-19 23:09:08 +00:00
|
|
|
}
|
|
|
|
|
2014-03-05 07:30:04 +00:00
|
|
|
AliasResult alias(const Location &LocA, const Location &LocB) override {
|
2010-10-19 23:09:08 +00:00
|
|
|
return MayAlias;
|
|
|
|
}
|
|
|
|
|
2014-03-05 07:30:04 +00:00
|
|
|
ModRefBehavior getModRefBehavior(ImmutableCallSite CS) override {
|
2010-10-19 23:09:08 +00:00
|
|
|
return UnknownModRefBehavior;
|
|
|
|
}
|
2014-03-05 07:30:04 +00:00
|
|
|
ModRefBehavior getModRefBehavior(const Function *F) override {
|
2010-10-19 23:09:08 +00:00
|
|
|
return UnknownModRefBehavior;
|
|
|
|
}
|
|
|
|
|
2014-03-05 07:30:04 +00:00
|
|
|
bool pointsToConstantMemory(const Location &Loc, bool OrLocal) override {
|
2010-11-08 16:45:26 +00:00
|
|
|
return 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
|
|
|
Location getArgLocation(ImmutableCallSite CS, unsigned ArgIdx,
|
|
|
|
ModRefResult &Mask) override {
|
|
|
|
Mask = ModRef;
|
2014-10-05 12:21:57 +00:00
|
|
|
AAMDNodes AATags;
|
|
|
|
CS->getAAMetadata(AATags);
|
2014-10-04 22:44:29 +00:00
|
|
|
return Location(CS.getArgument(ArgIdx), UnknownSize, AATags);
|
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
|
|
|
}
|
|
|
|
|
2014-03-05 07:30:04 +00:00
|
|
|
ModRefResult getModRefInfo(ImmutableCallSite CS,
|
|
|
|
const Location &Loc) override {
|
2010-10-19 23:09:08 +00:00
|
|
|
return ModRef;
|
|
|
|
}
|
2014-03-05 07:30:04 +00:00
|
|
|
ModRefResult getModRefInfo(ImmutableCallSite CS1,
|
|
|
|
ImmutableCallSite CS2) override {
|
2010-10-19 23:09:08 +00:00
|
|
|
return ModRef;
|
|
|
|
}
|
|
|
|
|
2014-03-05 07:30:04 +00:00
|
|
|
void deleteValue(Value *V) override {}
|
|
|
|
void copyValue(Value *From, Value *To) override {}
|
|
|
|
void addEscapingUse(Use &U) override {}
|
|
|
|
|
2010-10-19 23:09:08 +00:00
|
|
|
/// getAdjustedAnalysisPointer - This method is used when a pass implements
|
|
|
|
/// an analysis interface through multiple inheritance. If needed, it
|
|
|
|
/// should override this to adjust the this pointer as needed for the
|
|
|
|
/// specified pass info.
|
2014-03-05 07:30:04 +00:00
|
|
|
void *getAdjustedAnalysisPointer(const void *ID) override {
|
2010-10-19 23:09:08 +00:00
|
|
|
if (ID == &AliasAnalysis::ID)
|
|
|
|
return (AliasAnalysis*)this;
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
} // End of anonymous namespace
|
|
|
|
|
|
|
|
// Register this pass...
|
|
|
|
char NoAA::ID = 0;
|
|
|
|
INITIALIZE_AG_PASS(NoAA, AliasAnalysis, "no-aa",
|
|
|
|
"No Alias Analysis (always returns 'may' alias)",
|
|
|
|
true, true, true)
|
|
|
|
|
|
|
|
ImmutablePass *llvm::createNoAAPass() { return new NoAA(); }
|