Move isKnownNonNull from private implementation detail of BasicAA to a public
[oota-llvm.git] / lib / Analysis / AliasAnalysis.cpp
index bd132c05c3279875abda6a1a11a82244898b4280..95c834b451c9dfd2187583f1cef3192f02eb5826 100644 (file)
@@ -440,3 +440,19 @@ bool llvm::isIdentifiedObject(const Value *V) {
     return A->hasNoAliasAttr() || A->hasByValAttr();
   return false;
 }
+
+/// isKnownNonNull - Return true if we know that the specified value is never
+/// null.
+bool llvm::isKnownNonNull(const Value *V) {
+  // Alloca never returns null, malloc might.
+  if (isa<AllocaInst>(V)) return true;
+
+  // A byval argument is never null.
+  if (const Argument *A = dyn_cast<Argument>(V))
+    return A->hasByValAttr();
+
+  // Global values are not null unless extern weak.
+  if (const GlobalValue *GV = dyn_cast<GlobalValue>(V))
+    return !GV->hasExternalWeakLinkage();
+  return false;
+}