aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/IR/Value.cpp
diff options
context:
space:
mode:
authorArtur Pilipenko <apilipenko@azulsystems.com>2016-05-11 14:43:28 +0000
committerArtur Pilipenko <apilipenko@azulsystems.com>2016-05-11 14:43:28 +0000
commit7a26326442ed1feadbeef62799daba43e2912a3c (patch)
treed6b74fce250e7a1a930d6bf17da025fe8fc435a4 /llvm/lib/IR/Value.cpp
parent610a4e916e5ceb01386d8602f928c7c00f362168 (diff)
downloadllvm-7a26326442ed1feadbeef62799daba43e2912a3c.zip
llvm-7a26326442ed1feadbeef62799daba43e2912a3c.tar.gz
llvm-7a26326442ed1feadbeef62799daba43e2912a3c.tar.bz2
NFC. Introduce Value::isPointerDereferenceable
Extract a part of isDereferenceableAndAlignedPointer functionality to Value: Reviewed By: hfinkel, sanjoy Differential Revision: http://reviews.llvm.org/D17611 llvm-svn: 269190
Diffstat (limited to 'llvm/lib/IR/Value.cpp')
-rw-r--r--llvm/lib/IR/Value.cpp23
1 files changed, 23 insertions, 0 deletions
diff --git a/llvm/lib/IR/Value.cpp b/llvm/lib/IR/Value.cpp
index fb8d00f..de2c599 100644
--- a/llvm/lib/IR/Value.cpp
+++ b/llvm/lib/IR/Value.cpp
@@ -559,6 +559,29 @@ unsigned Value::getPointerDereferenceableBytes(bool &CanBeNull) const {
return DerefBytes;
}
+bool Value::isPointerDereferenceable(bool &CanBeNull) const {
+ assert(getType()->isPointerTy() && "must be pointer");
+
+ CanBeNull = false;
+
+ // These are obviously ok.
+ if (isa<AllocaInst>(this))
+ return true;
+
+ // Global variables which can't collapse to null are ok.
+ // TODO: return true for those but set CanBeNull flag
+ if (const GlobalVariable *GV = dyn_cast<GlobalVariable>(this))
+ if (!GV->hasExternalWeakLinkage())
+ return true;
+
+ // byval arguments are okay.
+ if (const Argument *A = dyn_cast<Argument>(this))
+ if (A->hasByValAttr())
+ return true;
+
+ return false;
+}
+
unsigned Value::getPointerAlignment(const DataLayout &DL) const {
assert(getType()->isPointerTy() && "must be pointer");