Add function for testing string attributes to InvokeInst and CallSite. NFC.
authorManuel Jacob <me@manueljacob.de>
Tue, 5 Jan 2016 19:08:33 +0000 (19:08 +0000)
committerManuel Jacob <me@manueljacob.de>
Tue, 5 Jan 2016 19:08:33 +0000 (19:08 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@256856 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/IR/CallSite.h
include/llvm/IR/Instructions.h
lib/IR/Instructions.cpp

index f4b8a8a5a1c93b33edf22359c8de96ed577c5ea4..f7bfb47a5b4446edbd495b979f6350cf40a03df5 100644 (file)
@@ -310,6 +310,11 @@ public:
     CALLSITE_DELEGATE_GETTER(hasFnAttr(A));
   }
 
+  /// \brief Return true if this function has the given attribute.
+  bool hasFnAttr(StringRef A) const {
+    CALLSITE_DELEGATE_GETTER(hasFnAttr(A));
+  }
+
   /// \brief Return true if the call or the callee has the given attribute.
   bool paramHasAttr(unsigned i, Attribute::AttrKind A) const {
     CALLSITE_DELEGATE_GETTER(paramHasAttr(i, A));
index 1659ebf9d7c866f3fafcd78b4cd3edcc5483ad89..aba48ca6fa9e09f7fb95cd50ca92753ac6bed13c 100644 (file)
@@ -3550,6 +3550,11 @@ public:
     return hasFnAttrImpl(A);
   }
 
+  /// \brief Determine whether this call has the given attribute.
+  bool hasFnAttr(StringRef A) const {
+    return hasFnAttrImpl(A);
+  }
+
   /// \brief Determine whether the call or the callee has the given attributes.
   bool paramHasAttr(unsigned i, Attribute::AttrKind A) const;
 
@@ -3734,7 +3739,19 @@ private:
   unsigned getNumSuccessorsV() const override;
   void setSuccessorV(unsigned idx, BasicBlock *B) override;
 
-  bool hasFnAttrImpl(Attribute::AttrKind A) const;
+  template <typename AttrKind> bool hasFnAttrImpl(AttrKind A) const {
+    if (AttributeList.hasAttribute(AttributeSet::FunctionIndex, A))
+      return true;
+
+    // Operand bundles override attributes on the called function, but don't
+    // override attributes directly present on the invoke instruction.
+    if (isFnAttrDisallowedByOpBundle(A))
+      return false;
+
+    if (const Function *F = getCalledFunction())
+      return F->getAttributes().hasAttribute(AttributeSet::FunctionIndex, A);
+    return false;
+  }
 
   // Shadow Instruction::setInstructionSubclassData with a private forwarding
   // method so that subclasses cannot accidentally use it.
index 0d6d23bb45db8275775747c7931af7a3e3dffabe..7c64ca7b72753590f20089afe50a770018c3af42 100644 (file)
@@ -609,20 +609,6 @@ void InvokeInst::setSuccessorV(unsigned idx, BasicBlock *B) {
   return setSuccessor(idx, B);
 }
 
-bool InvokeInst::hasFnAttrImpl(Attribute::AttrKind A) const {
-  if (AttributeList.hasAttribute(AttributeSet::FunctionIndex, A))
-    return true;
-
-  // Operand bundles override attributes on the called function, but don't
-  // override attributes directly present on the invoke instruction.
-  if (isFnAttrDisallowedByOpBundle(A))
-    return false;
-
-  if (const Function *F = getCalledFunction())
-    return F->getAttributes().hasAttribute(AttributeSet::FunctionIndex, A);
-  return false;
-}
-
 bool InvokeInst::paramHasAttr(unsigned i, Attribute::AttrKind A) const {
   assert(i < (getNumArgOperands() + 1) && "Param index out of bounds!");