diff options
author | Nick Lewycky <nicholas@mxc.ca> | 2014-05-20 01:23:40 +0000 |
---|---|---|
committer | Nick Lewycky <nicholas@mxc.ca> | 2014-05-20 01:23:40 +0000 |
commit | fe47ebfad39184dfca0733c5ef943a074bfcc187 (patch) | |
tree | 2f60176fb1f04022ea8a167ff280bc824f18f11a /lib/IR | |
parent | 30e58303015fe880180e3caffdd8a3264cde236a (diff) | |
download | llvm-fe47ebfad39184dfca0733c5ef943a074bfcc187.tar.gz llvm-fe47ebfad39184dfca0733c5ef943a074bfcc187.tar.bz2 llvm-fe47ebfad39184dfca0733c5ef943a074bfcc187.tar.xz |
Add 'nonnull', a new parameter and return attribute which indicates that the pointer is not null. Instcombine will elide comparisons between these and null. Patch by Luqman Aden!
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@209185 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/IR')
-rw-r--r-- | lib/IR/Attributes.cpp | 4 | ||||
-rw-r--r-- | lib/IR/Function.cpp | 8 |
2 files changed, 12 insertions, 0 deletions
diff --git a/lib/IR/Attributes.cpp b/lib/IR/Attributes.cpp index 0bbbd55978..a9074bb294 100644 --- a/lib/IR/Attributes.cpp +++ b/lib/IR/Attributes.cpp @@ -193,6 +193,8 @@ std::string Attribute::getAsString(bool InAttrGrp) const { return "noinline"; if (hasAttribute(Attribute::NonLazyBind)) return "nonlazybind"; + if (hasAttribute(Attribute::NonNull)) + return "nonnull"; if (hasAttribute(Attribute::NoRedZone)) return "noredzone"; if (hasAttribute(Attribute::NoReturn)) @@ -392,6 +394,7 @@ uint64_t AttributeImpl::getAttrMask(Attribute::AttrKind Val) { case Attribute::Builtin: return 1ULL << 41; case Attribute::OptimizeNone: return 1ULL << 42; case Attribute::InAlloca: return 1ULL << 43; + case Attribute::NonNull: return 1ULL << 44; } llvm_unreachable("Unsupported attribute type"); } @@ -1177,6 +1180,7 @@ AttributeSet AttributeFuncs::typeIncompatible(Type *Ty, uint64_t Index) { .addAttribute(Attribute::Nest) .addAttribute(Attribute::NoAlias) .addAttribute(Attribute::NoCapture) + .addAttribute(Attribute::NonNull) .addAttribute(Attribute::ReadNone) .addAttribute(Attribute::ReadOnly) .addAttribute(Attribute::StructRet) diff --git a/lib/IR/Function.cpp b/lib/IR/Function.cpp index de8e66f1bc..fe32c4613e 100644 --- a/lib/IR/Function.cpp +++ b/lib/IR/Function.cpp @@ -76,6 +76,14 @@ unsigned Argument::getArgNo() const { return ArgIdx; } +/// hasNonNullAttr - Return true if this argument has the nonnull attribute on +/// it in its containing function. +bool Argument::hasNonNullAttr() const { + if (!getType()->isPointerTy()) return false; + return getParent()->getAttributes(). + hasAttribute(getArgNo()+1, Attribute::NonNull); +} + /// hasByValAttr - Return true if this argument has the byval attribute on it /// in its containing function. bool Argument::hasByValAttr() const { |