aboutsummaryrefslogtreecommitdiffstats
path: root/lib/Transforms/IPO/FunctionAttrs.cpp
diff options
context:
space:
mode:
authorDan Gohman <gohman@apple.com>2010-11-08 16:45:26 +0000
committerDan Gohman <gohman@apple.com>2010-11-08 16:45:26 +0000
commita25e5dbcc2371352386a01e3c1b8e76dd890272b (patch)
tree2d67b72b4ac69a9de510506f4182d2ac8b62edb8 /lib/Transforms/IPO/FunctionAttrs.cpp
parentc80cbf25402e4095fafbb15a2ab1b81cf6feda77 (diff)
downloadexternal_llvm-a25e5dbcc2371352386a01e3c1b8e76dd890272b.zip
external_llvm-a25e5dbcc2371352386a01e3c1b8e76dd890272b.tar.gz
external_llvm-a25e5dbcc2371352386a01e3c1b8e76dd890272b.tar.bz2
Extend the AliasAnalysis::pointsToConstantMemory interface to allow it
to optionally look for constant or local (alloca) memory. Teach BasicAliasAnalysis::pointsToConstantMemory to look through Select and Phi nodes, and to support looking for local memory. Remove FunctionAttrs' PointsToLocalOrConstantMemory function, now that AliasAnalysis knows all the tricks that it knew. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@118412 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms/IPO/FunctionAttrs.cpp')
-rw-r--r--lib/Transforms/IPO/FunctionAttrs.cpp57
1 files changed, 5 insertions, 52 deletions
diff --git a/lib/Transforms/IPO/FunctionAttrs.cpp b/lib/Transforms/IPO/FunctionAttrs.cpp
index 062e366..be5d827 100644
--- a/lib/Transforms/IPO/FunctionAttrs.cpp
+++ b/lib/Transforms/IPO/FunctionAttrs.cpp
@@ -66,8 +66,6 @@ namespace {
CallGraphSCCPass::getAnalysisUsage(AU);
}
- bool PointsToLocalOrConstantMemory(Value *V);
-
private:
AliasAnalysis *AA;
};
@@ -83,53 +81,6 @@ INITIALIZE_PASS_END(FunctionAttrs, "functionattrs",
Pass *llvm::createFunctionAttrsPass() { return new FunctionAttrs(); }
-/// PointsToLocalOrConstantMemory - Returns whether the given pointer value
-/// points to memory that is local to the function, with global constants being
-/// considered local to all functions.
-bool FunctionAttrs::PointsToLocalOrConstantMemory(Value *V) {
- SmallVector<Value*, 16> Worklist;
- unsigned MaxLookup = 8;
-
- Worklist.push_back(V);
-
- do {
- V = Worklist.pop_back_val()->getUnderlyingObject();
-
- // An alloca instruction defines local memory.
- if (isa<AllocaInst>(V))
- continue;
-
- // A global constant counts as local memory for our purposes.
- if (GlobalVariable *GV = dyn_cast<GlobalVariable>(V)) {
- if (!GV->isConstant())
- return false;
- continue;
- }
-
- // If both select values point to local memory, then so does the select.
- if (SelectInst *SI = dyn_cast<SelectInst>(V)) {
- Worklist.push_back(SI->getTrueValue());
- Worklist.push_back(SI->getFalseValue());
- continue;
- }
-
- // If all values incoming to a phi node point to local memory, then so does
- // the phi.
- if (PHINode *PN = dyn_cast<PHINode>(V)) {
- // Don't bother inspecting phi nodes with many operands.
- if (PN->getNumIncomingValues() > MaxLookup)
- return false;
- for (unsigned i = 0, e = PN->getNumIncomingValues(); i != e; ++i)
- Worklist.push_back(PN->getIncomingValue(i));
- continue;
- }
-
- return false;
- } while (!Worklist.empty() && --MaxLookup);
-
- return Worklist.empty();
-}
-
/// AddReadAttrs - Deduce readonly/readnone attributes for the SCC.
bool FunctionAttrs::AddReadAttrs(const CallGraphSCC &SCC) {
SmallPtrSet<Function*, 8> SCCNodes;
@@ -190,7 +141,7 @@ bool FunctionAttrs::AddReadAttrs(const CallGraphSCC &SCC) {
CI != CE; ++CI) {
Value *Arg = *CI;
if (Arg->getType()->isPointerTy() &&
- !PointsToLocalOrConstantMemory(Arg))
+ !AA->pointsToConstantMemory(Arg, /*OrLocal=*/true))
// Writes memory. Just give up.
return false;
}
@@ -203,12 +154,14 @@ bool FunctionAttrs::AddReadAttrs(const CallGraphSCC &SCC) {
} else if (LoadInst *LI = dyn_cast<LoadInst>(I)) {
// Ignore non-volatile loads from local memory.
if (!LI->isVolatile() &&
- PointsToLocalOrConstantMemory(LI->getPointerOperand()))
+ AA->pointsToConstantMemory(LI->getPointerOperand(),
+ /*OrLocal=*/true))
continue;
} else if (StoreInst *SI = dyn_cast<StoreInst>(I)) {
// Ignore non-volatile stores to local memory.
if (!SI->isVolatile() &&
- PointsToLocalOrConstantMemory(SI->getPointerOperand()))
+ AA->pointsToConstantMemory(SI->getPointerOperand(),
+ /*OrLocal=*/true))
continue;
}