summaryrefslogtreecommitdiff
path: root/lib/Transforms/IPO/FunctionAttrs.cpp
diff options
context:
space:
mode:
authorDan Gohman <gohman@apple.com>2010-11-08 16:10:15 +0000
committerDan Gohman <gohman@apple.com>2010-11-08 16:10:15 +0000
commit3c97f7af9e75507f12a3977bced6b91c7e2ffb2a (patch)
tree07498b732ffa281fea4480b3aaab0dae3db16de5 /lib/Transforms/IPO/FunctionAttrs.cpp
parent431c794ade88f5da17ba06436f781b009c745dde (diff)
downloadllvm-3c97f7af9e75507f12a3977bced6b91c7e2ffb2a.tar.gz
llvm-3c97f7af9e75507f12a3977bced6b91c7e2ffb2a.tar.bz2
llvm-3c97f7af9e75507f12a3977bced6b91c7e2ffb2a.tar.xz
Make FunctionAttrs use AliasAnalysis::getModRefBehavior, now that it
knows about intrinsic functions. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@118410 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms/IPO/FunctionAttrs.cpp')
-rw-r--r--lib/Transforms/IPO/FunctionAttrs.cpp51
1 files changed, 33 insertions, 18 deletions
diff --git a/lib/Transforms/IPO/FunctionAttrs.cpp b/lib/Transforms/IPO/FunctionAttrs.cpp
index d464e2ee82..062e366158 100644
--- a/lib/Transforms/IPO/FunctionAttrs.cpp
+++ b/lib/Transforms/IPO/FunctionAttrs.cpp
@@ -40,7 +40,7 @@ STATISTIC(NumNoAlias, "Number of function returns marked noalias");
namespace {
struct FunctionAttrs : public CallGraphSCCPass {
static char ID; // Pass identification, replacement for typeid
- FunctionAttrs() : CallGraphSCCPass(ID) {
+ FunctionAttrs() : CallGraphSCCPass(ID), AA(0) {
initializeFunctionAttrsPass(*PassRegistry::getPassRegistry());
}
@@ -62,10 +62,14 @@ namespace {
virtual void getAnalysisUsage(AnalysisUsage &AU) const {
AU.setPreservesCFG();
+ AU.addRequired<AliasAnalysis>();
CallGraphSCCPass::getAnalysisUsage(AU);
}
bool PointsToLocalOrConstantMemory(Value *V);
+
+ private:
+ AliasAnalysis *AA;
};
}
@@ -167,26 +171,35 @@ bool FunctionAttrs::AddReadAttrs(const CallGraphSCC &SCC) {
// Some instructions can be ignored even if they read or write memory.
// Detect these now, skipping to the next instruction if one is found.
CallSite CS(cast<Value>(I));
- if (CS && CS.getCalledFunction()) {
+ if (CS) {
// Ignore calls to functions in the same SCC.
- if (SCCNodes.count(CS.getCalledFunction()))
+ if (CS.getCalledFunction() && SCCNodes.count(CS.getCalledFunction()))
+ continue;
+ switch (AA->getModRefBehavior(CS)) {
+ case AliasAnalysis::DoesNotAccessMemory:
+ // Ignore calls that don't access memory.
continue;
- // Ignore intrinsics that only access local memory.
- if (unsigned id = CS.getCalledFunction()->getIntrinsicID())
- if (AliasAnalysis::getIntrinsicModRefBehavior(id) ==
- AliasAnalysis::AccessesArguments) {
- // Check that all pointer arguments point to local memory.
- for (CallSite::arg_iterator CI = CS.arg_begin(), CE = CS.arg_end();
- CI != CE; ++CI) {
- Value *Arg = *CI;
- if (Arg->getType()->isPointerTy() &&
- !PointsToLocalOrConstantMemory(Arg))
- // Writes memory. Just give up.
- return false;
- }
- // Only reads and writes local 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() &&
+ !PointsToLocalOrConstantMemory(Arg))
+ // Writes memory. Just give up.
+ return false;
}
+ // Only reads and writes local memory.
+ continue;
+ default:
+ // Otherwise, be conservative.
+ break;
+ }
} else if (LoadInst *LI = dyn_cast<LoadInst>(I)) {
// Ignore non-volatile loads from local memory.
if (!LI->isVolatile() &&
@@ -387,6 +400,8 @@ bool FunctionAttrs::AddNoAliasAttrs(const CallGraphSCC &SCC) {
}
bool FunctionAttrs::runOnSCC(CallGraphSCC &SCC) {
+ AA = &getAnalysis<AliasAnalysis>();
+
bool Changed = AddReadAttrs(SCC);
Changed |= AddNoCaptureAttrs(SCC);
Changed |= AddNoAliasAttrs(SCC);