diff options
author | Dan Gohman <gohman@apple.com> | 2010-11-10 01:02:18 +0000 |
---|---|---|
committer | Dan Gohman <gohman@apple.com> | 2010-11-10 01:02:18 +0000 |
commit | 42c31a70735e55bf82e66a9315c97d1821c9a798 (patch) | |
tree | 4a2913df4ad61547376e9facded78b679229e473 /lib/Transforms/IPO/FunctionAttrs.cpp | |
parent | cc8d10e1a8a8555fa63f33e36e3c1ed2fb24389d (diff) |
Make ModRefBehavior a lattice. Use this to clean up AliasAnalysis
chaining and simplify FunctionAttrs' GetModRefBehavior logic.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@118660 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms/IPO/FunctionAttrs.cpp')
-rw-r--r-- | lib/Transforms/IPO/FunctionAttrs.cpp | 75 |
1 files changed, 31 insertions, 44 deletions
diff --git a/lib/Transforms/IPO/FunctionAttrs.cpp b/lib/Transforms/IPO/FunctionAttrs.cpp index 8bdf5d75da..3b1b13d378 100644 --- a/lib/Transforms/IPO/FunctionAttrs.cpp +++ b/lib/Transforms/IPO/FunctionAttrs.cpp @@ -128,54 +128,41 @@ bool FunctionAttrs::AddReadAttrs(const CallGraphSCC &SCC) { // Ignore calls to functions in the same SCC. if (CS.getCalledFunction() && SCCNodes.count(CS.getCalledFunction())) continue; - switch (AA->getModRefBehavior(CS)) { - case AliasAnalysis::DoesNotAccessMemory: - // Ignore calls that don't access memory. - continue; - case AliasAnalysis::OnlyReadsMemory: - // Handle calls that only read from memory. - ReadsMemory = true; - continue; - case AliasAnalysis::AccessesArguments: - // Check whether all pointer arguments point to local memory, and - // ignore calls that only access local memory. - for (CallSite::arg_iterator CI = CS.arg_begin(), CE = CS.arg_end(); - CI != CE; ++CI) { - Value *Arg = *CI; - if (Arg->getType()->isPointerTy()) { - AliasAnalysis::Location Loc(Arg, - AliasAnalysis::UnknownSize, - I->getMetadata(LLVMContext::MD_tbaa)); - if (!AA->pointsToConstantMemory(Loc, /*OrLocal=*/true)) - // Writes memory. Just give up. - return false; - } - } - // Only reads and writes local memory. - continue; - case AliasAnalysis::AccessesArgumentsReadonly: - // Check whether all pointer arguments point to local memory, and - // ignore calls that only access local memory. - for (CallSite::arg_iterator CI = CS.arg_begin(), CE = CS.arg_end(); - CI != CE; ++CI) { - Value *Arg = *CI; - if (Arg->getType()->isPointerTy()) { - AliasAnalysis::Location Loc(Arg, - AliasAnalysis::UnknownSize, - I->getMetadata(LLVMContext::MD_tbaa)); - if (!AA->pointsToConstantMemory(Loc, /*OrLocal=*/true)) { - // Reads non-local memory. - ReadsMemory = true; - break; + AliasAnalysis::ModRefBehavior MRB = AA->getModRefBehavior(CS); + // If the call doesn't access arbitrary memory, we may be able to + // figure out something. + if (!(MRB & AliasAnalysis::Anywhere & + ~AliasAnalysis::ArgumentPointees)) { + // If the call accesses argument pointees, check each argument. + if (MRB & AliasAnalysis::AccessesArguments) + // Check whether all pointer arguments point to local memory, and + // ignore calls that only access local memory. + for (CallSite::arg_iterator CI = CS.arg_begin(), CE = CS.arg_end(); + CI != CE; ++CI) { + Value *Arg = *CI; + if (Arg->getType()->isPointerTy()) { + AliasAnalysis::Location Loc(Arg, + AliasAnalysis::UnknownSize, + I->getMetadata(LLVMContext::MD_tbaa)); + if (!AA->pointsToConstantMemory(Loc, /*OrLocal=*/true)) { + if (MRB & AliasAnalysis::Mod) + // Writes non-local memory. Give up. + return false; + if (MRB & AliasAnalysis::Ref) + // Ok, it reads non-local memory. + ReadsMemory = true; + } } } - } - // Only reads memory. continue; - default: - // Otherwise, be conservative. - break; } + // The call could access any memory. If that includes writes, give up. + if (MRB & AliasAnalysis::Mod) + return false; + // If it reads, note it. + if (MRB & AliasAnalysis::Ref) + ReadsMemory = true; + continue; } else if (LoadInst *LI = dyn_cast<LoadInst>(I)) { // Ignore non-volatile loads from local memory. if (!LI->isVolatile()) { |