diff options
| author | Sanjoy Das <sanjoy@playingwithpointers.com> | 2015-05-06 17:41:54 +0000 |
|---|---|---|
| committer | Sanjoy Das <sanjoy@playingwithpointers.com> | 2015-05-06 17:41:54 +0000 |
| commit | 06cf33fbea70f2672e814d82ad9005b9f9e6c6e8 (patch) | |
| tree | 49b97516fcbd1921645bf26a225aa311b114aa23 | |
| parent | e7f46558a46878901072dc5cb452f3c2bd0ac181 (diff) | |
| download | bcm5719-llvm-06cf33fbea70f2672e814d82ad9005b9f9e6c6e8.tar.gz bcm5719-llvm-06cf33fbea70f2672e814d82ad9005b9f9e6c6e8.zip | |
Add missing dereferenceable_or_null getters
Summary: Add missing dereferenceable_or_null getters required for
http://reviews.llvm.org/D9253 change. Separated from the D9253 review.
Patch by Artur Pilipenko!
Reviewers: sanjoy
Reviewed By: sanjoy
Subscribers: llvm-commits
Differential Revision: http://reviews.llvm.org/D9499
llvm-svn: 236615
| -rw-r--r-- | llvm/include/llvm/IR/Argument.h | 5 | ||||
| -rw-r--r-- | llvm/include/llvm/IR/CallSite.h | 8 | ||||
| -rw-r--r-- | llvm/include/llvm/IR/Function.h | 8 | ||||
| -rw-r--r-- | llvm/include/llvm/IR/Instructions.h | 12 | ||||
| -rw-r--r-- | llvm/lib/IR/AttributeImpl.h | 1 | ||||
| -rw-r--r-- | llvm/lib/IR/Attributes.cpp | 12 | ||||
| -rw-r--r-- | llvm/lib/IR/Function.cpp | 6 |
7 files changed, 50 insertions, 2 deletions
diff --git a/llvm/include/llvm/IR/Argument.h b/llvm/include/llvm/IR/Argument.h index dd76a90aa5e..fc04fe71cbf 100644 --- a/llvm/include/llvm/IR/Argument.h +++ b/llvm/include/llvm/IR/Argument.h @@ -64,6 +64,11 @@ public: /// containing function, return the number of bytes known to be /// dereferenceable. Otherwise, zero is returned. uint64_t getDereferenceableBytes() const; + + /// \brief If this argument has the dereferenceable_or_null attribute on + /// it in its containing function, return the number of bytes known to be + /// dereferenceable. Otherwise, zero is returned. + uint64_t getDereferenceableOrNullBytes() const; /// \brief Return true if this argument has the byval attribute on it in its /// containing function. diff --git a/llvm/include/llvm/IR/CallSite.h b/llvm/include/llvm/IR/CallSite.h index 55fa0b5bd5e..170d263dfc7 100644 --- a/llvm/include/llvm/IR/CallSite.h +++ b/llvm/include/llvm/IR/CallSite.h @@ -231,7 +231,13 @@ public: uint64_t getDereferenceableBytes(uint16_t i) const { CALLSITE_DELEGATE_GETTER(getDereferenceableBytes(i)); } - + + /// @brief Extract the number of dereferenceable_or_null bytes for a call or + /// parameter (0=unknown). + uint64_t getDereferenceableOrNullBytes(uint16_t i) const { + CALLSITE_DELEGATE_GETTER(getDereferenceableOrNullBytes(i)); + } + /// \brief Return true if the call should not be treated as a call to a /// builtin. bool isNoBuiltin() const { diff --git a/llvm/include/llvm/IR/Function.h b/llvm/include/llvm/IR/Function.h index ae1061e9f98..b16d9f5e216 100644 --- a/llvm/include/llvm/IR/Function.h +++ b/llvm/include/llvm/IR/Function.h @@ -248,7 +248,13 @@ public: uint64_t getDereferenceableBytes(unsigned i) const { return AttributeSets.getDereferenceableBytes(i); } - + + /// @brief Extract the number of dereferenceable_or_null bytes for a call or + /// parameter (0=unknown). + uint64_t getDereferenceableOrNullBytes(unsigned i) const { + return AttributeSets.getDereferenceableOrNullBytes(i); + } + /// @brief Determine if the function does not access memory. bool doesNotAccessMemory() const { return AttributeSets.hasAttribute(AttributeSet::FunctionIndex, diff --git a/llvm/include/llvm/IR/Instructions.h b/llvm/include/llvm/IR/Instructions.h index ab1bf647dea..5b37d4b745b 100644 --- a/llvm/include/llvm/IR/Instructions.h +++ b/llvm/include/llvm/IR/Instructions.h @@ -1491,6 +1491,12 @@ public: return AttributeList.getDereferenceableBytes(i); } + /// \brief Extract the number of dereferenceable_or_null bytes for a call or + /// parameter (0=unknown). + uint64_t getDereferenceableOrNullBytes(unsigned i) const { + return AttributeList.getDereferenceableOrNullBytes(i); + } + /// \brief Return true if the call should not be treated as a call to a /// builtin. bool isNoBuiltin() const { @@ -3200,6 +3206,12 @@ public: uint64_t getDereferenceableBytes(unsigned i) const { return AttributeList.getDereferenceableBytes(i); } + + /// \brief Extract the number of dereferenceable_or_null bytes for a call or + /// parameter (0=unknown). + uint64_t getDereferenceableOrNullBytes(unsigned i) const { + return AttributeList.getDereferenceableOrNullBytes(i); + } /// \brief Return true if the call should not be treated as a call to a /// builtin. diff --git a/llvm/lib/IR/AttributeImpl.h b/llvm/lib/IR/AttributeImpl.h index d544689abec..dbd7d63a892 100644 --- a/llvm/lib/IR/AttributeImpl.h +++ b/llvm/lib/IR/AttributeImpl.h @@ -166,6 +166,7 @@ public: unsigned getAlignment() const; unsigned getStackAlignment() const; uint64_t getDereferenceableBytes() const; + uint64_t getDereferenceableOrNullBytes() const; std::string getAsString(bool InAttrGrp) const; typedef const Attribute *iterator; diff --git a/llvm/lib/IR/Attributes.cpp b/llvm/lib/IR/Attributes.cpp index be5b74f59a2..7c9468cb158 100644 --- a/llvm/lib/IR/Attributes.cpp +++ b/llvm/lib/IR/Attributes.cpp @@ -532,6 +532,13 @@ uint64_t AttributeSetNode::getDereferenceableBytes() const { return 0; } +uint64_t AttributeSetNode::getDereferenceableOrNullBytes() const { + for (iterator I = begin(), E = end(); I != E; ++I) + if (I->hasAttribute(Attribute::DereferenceableOrNull)) + return I->getDereferenceableOrNullBytes(); + return 0; +} + std::string AttributeSetNode::getAsString(bool InAttrGrp) const { std::string Str; for (iterator I = begin(), E = end(); I != E; ++I) { @@ -957,6 +964,11 @@ uint64_t AttributeSet::getDereferenceableBytes(unsigned Index) const { return ASN ? ASN->getDereferenceableBytes() : 0; } +uint64_t AttributeSet::getDereferenceableOrNullBytes(unsigned Index) const { + AttributeSetNode *ASN = getAttributes(Index); + return ASN ? ASN->getDereferenceableOrNullBytes() : 0; +} + std::string AttributeSet::getAsString(unsigned Index, bool InAttrGrp) const { AttributeSetNode *ASN = getAttributes(Index); diff --git a/llvm/lib/IR/Function.cpp b/llvm/lib/IR/Function.cpp index ced989ab11d..aea4bf52701 100644 --- a/llvm/lib/IR/Function.cpp +++ b/llvm/lib/IR/Function.cpp @@ -117,6 +117,12 @@ uint64_t Argument::getDereferenceableBytes() const { return getParent()->getDereferenceableBytes(getArgNo()+1); } +uint64_t Argument::getDereferenceableOrNullBytes() const { + assert(getType()->isPointerTy() && + "Only pointers have dereferenceable bytes"); + return getParent()->getDereferenceableOrNullBytes(getArgNo()+1); +} + /// hasNestAttr - Return true if this argument has the nest attribute on /// it in its containing function. bool Argument::hasNestAttr() const { |

