summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Transforms
diff options
context:
space:
mode:
authorChandler Carruth <chandlerc@gmail.com>2015-09-13 08:17:14 +0000
committerChandler Carruth <chandlerc@gmail.com>2015-09-13 08:17:14 +0000
commit8874b78697cf09fde54c95df6de43c1acd7e9b75 (patch)
tree2c25dbe409b26697d6bc49d5f5766d8b3ce21bb1 /llvm/lib/Transforms
parent8671fcbbd65f64947477b29fd0498523230eb1ee (diff)
downloadbcm5719-llvm-8874b78697cf09fde54c95df6de43c1acd7e9b75.tar.gz
bcm5719-llvm-8874b78697cf09fde54c95df6de43c1acd7e9b75.zip
[FunctionAttrs] Factor the logic to test for a known non-null return out
of a method and into a re-usable static helper. We can potentially use this function from the implementation of a new pass manager oriented version of the pass. Also add some better documentation of exactly what the semantic model of this routine is (it isn't trivial) and use a more modern naming convention for it. llvm-svn: 247524
Diffstat (limited to 'llvm/lib/Transforms')
-rw-r--r--llvm/lib/Transforms/IPO/FunctionAttrs.cpp17
1 files changed, 10 insertions, 7 deletions
diff --git a/llvm/lib/Transforms/IPO/FunctionAttrs.cpp b/llvm/lib/Transforms/IPO/FunctionAttrs.cpp
index 3ea54687365..cfeedf6d1db 100644
--- a/llvm/lib/Transforms/IPO/FunctionAttrs.cpp
+++ b/llvm/lib/Transforms/IPO/FunctionAttrs.cpp
@@ -74,8 +74,6 @@ private:
bool AddArgumentAttrs(const CallGraphSCC &SCC);
bool IsFunctionMallocLike(Function *F, SmallPtrSet<Function *, 8> &) const;
bool AddNoAliasAttrs(const CallGraphSCC &SCC);
- bool ReturnsNonNull(Function *F, SmallPtrSet<Function *, 8> &,
- bool &Speculative) const;
bool AddNonNullAttrs(const CallGraphSCC &SCC);
bool annotateLibraryCalls(const CallGraphSCC &SCC);
};
@@ -798,9 +796,14 @@ bool FunctionAttrs::AddNoAliasAttrs(const CallGraphSCC &SCC) {
}
/// Tests whether this function is known to not return null.
-bool FunctionAttrs::ReturnsNonNull(Function *F,
- SmallPtrSet<Function *, 8> &SCCNodes,
- bool &Speculative) const {
+///
+/// Requires that the function returns a pointer.
+///
+/// Returns true if it believes the function will not return a null, and sets
+/// \p Speculative based on whether the returned conclusion is a speculative
+/// conclusion due to SCC calls.
+static bool isReturnNonNull(Function *F, SmallPtrSet<Function *, 8> &SCCNodes,
+ const TargetLibraryInfo &TLI, bool &Speculative) {
assert(F->getReturnType()->isPointerTy() &&
"nonnull only meaningful on pointer types");
Speculative = false;
@@ -814,7 +817,7 @@ bool FunctionAttrs::ReturnsNonNull(Function *F,
Value *RetVal = FlowsToReturn[i];
// If this value is locally known to be non-null, we're good
- if (isKnownNonNull(RetVal, TLI))
+ if (isKnownNonNull(RetVal, &TLI))
continue;
// Otherwise, we need to look upwards since we can't make any local
@@ -902,7 +905,7 @@ bool FunctionAttrs::AddNonNullAttrs(const CallGraphSCC &SCC) {
continue;
bool Speculative = false;
- if (ReturnsNonNull(F, SCCNodes, Speculative)) {
+ if (isReturnNonNull(F, SCCNodes, *TLI, Speculative)) {
if (!Speculative) {
// Mark the function eagerly since we may discover a function
// which prevents us from speculating about the entire SCC
OpenPOWER on IntegriCloud