From 7a26326442ed1feadbeef62799daba43e2912a3c Mon Sep 17 00:00:00 2001 From: Artur Pilipenko Date: Wed, 11 May 2016 14:43:28 +0000 Subject: 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 --- llvm/lib/IR/Value.cpp | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'llvm/lib/IR/Value.cpp') 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(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(this)) + if (!GV->hasExternalWeakLinkage()) + return true; + + // byval arguments are okay. + if (const Argument *A = dyn_cast(this)) + if (A->hasByValAttr()) + return true; + + return false; +} + unsigned Value::getPointerAlignment(const DataLayout &DL) const { assert(getType()->isPointerTy() && "must be pointer"); -- cgit v1.1