summaryrefslogtreecommitdiff
path: root/lib/Transforms/IPO/FunctionAttrs.cpp
diff options
context:
space:
mode:
authorDuncan Sands <baldrick@free.fr>2010-01-06 15:37:47 +0000
committerDuncan Sands <baldrick@free.fr>2010-01-06 15:37:47 +0000
commite10920d678c4d6046619e51770de1c9de0c3fe0a (patch)
treeb546eb77c0bee59e72b6e4e4708c3a54cd522be0 /lib/Transforms/IPO/FunctionAttrs.cpp
parent0ecbdeb14f47b2391d138b7c3644e5f937ee0553 (diff)
downloadllvm-e10920d678c4d6046619e51770de1c9de0c3fe0a.tar.gz
llvm-e10920d678c4d6046619e51770de1c9de0c3fe0a.tar.bz2
llvm-e10920d678c4d6046619e51770de1c9de0c3fe0a.tar.xz
Fix a README item: have functionattrs look through selects and
phi nodes when deciding which pointers point to local memory. I actually checked long ago how useful this is, and it isn't very: it hardly ever fires in the testsuite, but since Chris wants it here it is! git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@92836 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms/IPO/FunctionAttrs.cpp')
-rw-r--r--lib/Transforms/IPO/FunctionAttrs.cpp51
1 files changed, 41 insertions, 10 deletions
diff --git a/lib/Transforms/IPO/FunctionAttrs.cpp b/lib/Transforms/IPO/FunctionAttrs.cpp
index 0bff2b94e9..f41698adc5 100644
--- a/lib/Transforms/IPO/FunctionAttrs.cpp
+++ b/lib/Transforms/IPO/FunctionAttrs.cpp
@@ -79,16 +79,47 @@ Pass *llvm::createFunctionAttrsPass() { return new FunctionAttrs(); }
/// memory that is local to the function. Global constants are considered
/// local to all functions.
bool FunctionAttrs::PointsToLocalMemory(Value *V) {
- V = V->getUnderlyingObject();
- // An alloca instruction defines local memory.
- if (isa<AllocaInst>(V))
- return true;
- // A global constant counts as local memory for our purposes.
- if (GlobalVariable *GV = dyn_cast<GlobalVariable>(V))
- return GV->isConstant();
- // Could look through phi nodes and selects here, but it doesn't seem
- // to be useful in practice.
- return false;
+ SmallVector<Value*, 8> Worklist;
+ unsigned MaxLookup = 4;
+
+ 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.