]> granicus.if.org Git - llvm/commitdiff
Add support for string attributes in the C API.
authorAmaury Sechet <deadalnix@gmail.com>
Wed, 15 Jun 2016 17:50:39 +0000 (17:50 +0000)
committerAmaury Sechet <deadalnix@gmail.com>
Wed, 15 Jun 2016 17:50:39 +0000 (17:50 +0000)
Summary: As per title. This completes the C API Attribute support.

Reviewers: Wallbraker, whitequark, echristo, rafael, jyknight

Subscribers: mehdi_amini

Differential Revision: http://reviews.llvm.org/D21365

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@272811 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm-c/Core.h
include/llvm/IR/Attributes.h
include/llvm/IR/CallSite.h
include/llvm/IR/Function.h
include/llvm/IR/Instructions.h
lib/IR/Attributes.cpp
lib/IR/Core.cpp
lib/IR/Function.cpp
lib/IR/Instructions.cpp

index 6257e758b1e8057b54d068130ca8a172c55a48de..6bdb96ac433325b6768e71db4532674b64a672ff 100644 (file)
@@ -2017,8 +2017,13 @@ void LLVMAddAttributeAtIndex(LLVMValueRef F, LLVMAttributeIndex Idx,
 LLVMAttributeRef LLVMGetEnumAttributeAtIndex(LLVMValueRef F,
                                              LLVMAttributeIndex Idx,
                                              unsigned KindID);
+LLVMAttributeRef LLVMGetStringAttributeAtIndex(LLVMValueRef F,
+                                               LLVMAttributeIndex Idx,
+                                               const char *K, unsigned KLen);
 void LLVMRemoveEnumAttributeAtIndex(LLVMValueRef F, LLVMAttributeIndex Idx,
                                     unsigned KindID);
+void LLVMRemoveStringAttributeAtIndex(LLVMValueRef F, LLVMAttributeIndex Idx,
+                                      const char *K, unsigned KLen);
 
 /**
  * Add a target-dependent attribute to a function
@@ -2598,8 +2603,13 @@ void LLVMAddCallSiteAttribute(LLVMValueRef C, LLVMAttributeIndex Idx,
 LLVMAttributeRef LLVMGetCallSiteEnumAttribute(LLVMValueRef C,
                                               LLVMAttributeIndex Idx,
                                               unsigned KindID);
+LLVMAttributeRef LLVMGetCallSiteStringAttribute(LLVMValueRef C,
+                                                LLVMAttributeIndex Idx,
+                                                const char *K, unsigned KLen);
 void LLVMRemoveCallSiteEnumAttribute(LLVMValueRef C, LLVMAttributeIndex Idx,
                                      unsigned KindID);
+void LLVMRemoveCallSiteStringAttribute(LLVMValueRef C, LLVMAttributeIndex Idx,
+                                       const char *K, unsigned KLen);
 
 /**
  * Obtain the pointer to the function invoked by this instruction.
index 8a6b568ed8dccb856d202fe93cfd9c06682f5830..52d1a46602a0418c3969c21c0830784455805478 100644 (file)
@@ -243,6 +243,8 @@ public:
   static AttributeSet get(LLVMContext &C, ArrayRef<AttributeSet> Attrs);
   static AttributeSet get(LLVMContext &C, unsigned Index,
                           ArrayRef<Attribute::AttrKind> Kinds);
+  static AttributeSet get(LLVMContext &C, unsigned Index,
+                          ArrayRef<StringRef> Kind);
   static AttributeSet get(LLVMContext &C, unsigned Index, const AttrBuilder &B);
 
   /// \brief Add an attribute to the attribute set at the given index. Because
@@ -271,6 +273,12 @@ public:
   AttributeSet removeAttribute(LLVMContext &C, unsigned Index,
                                Attribute::AttrKind Kind) const;
 
+  /// \brief Remove the specified attribute at the specified index from this
+  /// attribute list. Because attribute lists are immutable, this returns the
+  /// new list.
+  AttributeSet removeAttribute(LLVMContext &C, unsigned Index,
+                               StringRef Kind) const;
+
   /// \brief Remove the specified attributes at the specified index from this
   /// attribute list. Because attribute lists are immutable, this returns the
   /// new list.
index b423ecc66311c5fc303537d17c1a3c553c0d50d7..23f047478891952b3f0c70e827ad74fb20beed20 100644 (file)
@@ -321,6 +321,10 @@ public:
     CALLSITE_DELEGATE_SETTER(removeAttribute(i, Kind));
   }
 
+  void removeAttribute(unsigned i, StringRef Kind) {
+    CALLSITE_DELEGATE_SETTER(removeAttribute(i, Kind));
+  }
+
   void removeAttribute(unsigned i, Attribute Attr) {
     CALLSITE_DELEGATE_SETTER(removeAttribute(i, Attr));
   }
@@ -344,6 +348,10 @@ public:
     CALLSITE_DELEGATE_GETTER(getAttribute(i, Kind));
   }
 
+  Attribute getAttribute(unsigned i, StringRef Kind) const {
+    CALLSITE_DELEGATE_GETTER(getAttribute(i, Kind));
+  }
+
   /// \brief Return true if the data operand at index \p i directly or
   /// indirectly has the attribute \p A.
   ///
index 954ccd4f9e3df92ad486758ccdb7e2fd168105c8..867cfc4f1401c2adc7676b1b0476f3c1e6e94609 100644 (file)
@@ -239,6 +239,9 @@ public:
   /// @brief removes the attribute from the list of attributes.
   void removeAttribute(unsigned i, Attribute::AttrKind Kind);
 
+  /// @brief removes the attribute from the list of attributes.
+  void removeAttribute(unsigned i, StringRef Kind);
+
   /// @brief removes the attributes from the list of attributes.
   void removeAttributes(unsigned i, AttributeSet Attrs);
 
index 37f64750cd6da1723135ac47862f69b5a4de60bd..ff897e3a48aa3839d64286101c2cea3d496a98e0 100644 (file)
@@ -1629,6 +1629,9 @@ public:
   /// removeAttribute - removes the attribute from the list of attributes.
   void removeAttribute(unsigned i, Attribute::AttrKind Kind);
 
+  /// removeAttribute - removes the attribute from the list of attributes.
+  void removeAttribute(unsigned i, StringRef Kind);
+
   /// removeAttribute - removes the attribute from the list of attributes.
   void removeAttribute(unsigned i, Attribute Attr);
 
@@ -1657,6 +1660,9 @@ public:
   /// \brief Get the attribute of a given kind at a position.
   Attribute getAttribute(unsigned i, Attribute::AttrKind Kind) const;
 
+  /// \brief Get the attribute of a given kind at a position.
+  Attribute getAttribute(unsigned i, StringRef Kind) const;
+
   /// \brief Return true if the data operand at index \p i has the attribute \p
   /// A.
   ///
@@ -3576,6 +3582,9 @@ public:
   /// removeAttribute - removes the attribute from the list of attributes.
   void removeAttribute(unsigned i, Attribute::AttrKind Kind);
 
+  /// removeAttribute - removes the attribute from the list of attributes.
+  void removeAttribute(unsigned i, StringRef Kind);
+
   /// removeAttribute - removes the attribute from the list of attributes.
   void removeAttribute(unsigned i, Attribute Attr);
 
@@ -3604,6 +3613,9 @@ public:
   /// \brief Get the attribute of a given kind at a position.
   Attribute getAttribute(unsigned i, Attribute::AttrKind Kind) const;
 
+  /// \brief Get the attribute of a given kind at a position.
+  Attribute getAttribute(unsigned i, StringRef Kind) const;
+
   /// \brief Return true if the data operand at index \p i has the attribute \p
   /// A.
   ///
index 3675bad2fb0288fae6871b79251e86b116a8ce0b..b470fac5782b98cd2eb186b366357bb072e1e9bf 100644 (file)
@@ -807,6 +807,14 @@ AttributeSet AttributeSet::get(LLVMContext &C, unsigned Index,
   return get(C, Attrs);
 }
 
+AttributeSet AttributeSet::get(LLVMContext &C, unsigned Index,
+                               ArrayRef<StringRef> Kinds) {
+  SmallVector<std::pair<unsigned, Attribute>, 8> Attrs;
+  for (StringRef K : Kinds)
+    Attrs.push_back(std::make_pair(Index, Attribute::get(C, K)));
+  return get(C, Attrs);
+}
+
 AttributeSet AttributeSet::get(LLVMContext &C, ArrayRef<AttributeSet> Attrs) {
   if (Attrs.empty()) return AttributeSet();
   if (Attrs.size() == 1) return Attrs[0];
@@ -935,6 +943,12 @@ AttributeSet AttributeSet::removeAttribute(LLVMContext &C, unsigned Index,
   return removeAttributes(C, Index, AttributeSet::get(C, Index, Kind));
 }
 
+AttributeSet AttributeSet::removeAttribute(LLVMContext &C, unsigned Index,
+                                           StringRef Kind) const {
+  if (!hasAttribute(Index, Kind)) return *this;
+  return removeAttributes(C, Index, AttributeSet::get(C, Index, Kind));
+}
+
 AttributeSet AttributeSet::removeAttributes(LLVMContext &C, unsigned Index,
                                             AttributeSet Attrs) const {
   if (!pImpl) return AttributeSet();
index c965063d8c7b8ab9b908564849f059a46eb2ca2b..a1c094a758c79ed69f77c1045b2516a52030cbd5 100644 (file)
@@ -209,7 +209,6 @@ LLVMDiagnosticSeverity LLVMGetDiagInfoSeverity(LLVMDiagnosticInfoRef DI) {
     return severity;
 }
 
-
 /*===-- Operations on modules ---------------------------------------------===*/
 
 LLVMModuleRef LLVMModuleCreateWithName(const char *ModuleID) {
@@ -1852,11 +1851,22 @@ LLVMAttributeRef LLVMGetEnumAttributeAtIndex(LLVMValueRef F,
                                                 (Attribute::AttrKind)KindID));
 }
 
+LLVMAttributeRef LLVMGetStringAttributeAtIndex(LLVMValueRef F,
+                                               LLVMAttributeIndex Idx,
+                                               const char *K, unsigned KLen) {
+  return wrap(unwrap<Function>(F)->getAttribute(Idx, StringRef(K, KLen)));
+}
+
 void LLVMRemoveEnumAttributeAtIndex(LLVMValueRef F, LLVMAttributeIndex Idx,
                                     unsigned KindID) {
   unwrap<Function>(F)->removeAttribute(Idx, (Attribute::AttrKind)KindID);
 }
 
+void LLVMRemoveStringAttributeAtIndex(LLVMValueRef F, LLVMAttributeIndex Idx,
+                                      const char *K, unsigned KLen) {
+  unwrap<Function>(F)->removeAttribute(Idx, StringRef(K, KLen));
+}
+
 void LLVMAddTargetDependentFunctionAttr(LLVMValueRef Fn, const char *A,
                                         const char *V) {
   Function *Func = unwrap<Function>(Fn);
@@ -2213,12 +2223,24 @@ LLVMAttributeRef LLVMGetCallSiteEnumAttribute(LLVMValueRef C,
     .getAttribute(Idx, (Attribute::AttrKind)KindID));
 }
 
+LLVMAttributeRef LLVMGetCallSiteStringAttribute(LLVMValueRef C,
+                                                LLVMAttributeIndex Idx,
+                                                const char *K, unsigned KLen) {
+  return wrap(CallSite(unwrap<Instruction>(C))
+    .getAttribute(Idx, StringRef(K, KLen)));
+}
+
 void LLVMRemoveCallSiteEnumAttribute(LLVMValueRef C, LLVMAttributeIndex Idx,
                                      unsigned KindID) {
   CallSite(unwrap<Instruction>(C))
     .removeAttribute(Idx, (Attribute::AttrKind)KindID);
 }
 
+void LLVMRemoveCallSiteStringAttribute(LLVMValueRef C, LLVMAttributeIndex Idx,
+                                       const char *K, unsigned KLen) {
+  CallSite(unwrap<Instruction>(C)).removeAttribute(Idx, StringRef(K, KLen));
+}
+
 LLVMValueRef LLVMGetCalledValue(LLVMValueRef Instr) {
   return wrap(CallSite(unwrap<Instruction>(Instr)).getCalledValue());
 }
index b71e1baf1e9931f4403e964972236f0de353f4cb..07b21151e605341962690c8d936b8901839ccd0e 100644 (file)
@@ -390,6 +390,12 @@ void Function::removeAttribute(unsigned i, Attribute::AttrKind Kind) {
   setAttributes(PAL);
 }
 
+void Function::removeAttribute(unsigned i, StringRef Kind) {
+  AttributeSet PAL = getAttributes();
+  PAL = PAL.removeAttribute(getContext(), i, Kind);
+  setAttributes(PAL);
+}
+
 void Function::removeAttributes(unsigned i, AttributeSet Attrs) {
   AttributeSet PAL = getAttributes();
   PAL = PAL.removeAttributes(getContext(), i, Attrs);
index 98d37074b4ac944e442fcf1c538f2efa14030d39..6f60d15c52c43acff89137e1457852ac265f85a4 100644 (file)
@@ -355,6 +355,12 @@ void CallInst::removeAttribute(unsigned i, Attribute::AttrKind Kind) {
   setAttributes(PAL);
 }
 
+void CallInst::removeAttribute(unsigned i, StringRef Kind) {
+  AttributeSet PAL = getAttributes();
+  PAL = PAL.removeAttribute(getContext(), i, Kind);
+  setAttributes(PAL);
+}
+
 void CallInst::removeAttribute(unsigned i, Attribute Attr) {
   AttributeSet PAL = getAttributes();
   AttrBuilder B(Attr);
@@ -390,6 +396,10 @@ Attribute CallInst::getAttribute(unsigned i, Attribute::AttrKind Kind) const {
   return getAttributes().getAttribute(i, Kind);
 }
 
+Attribute CallInst::getAttribute(unsigned i, StringRef Kind) const {
+  return getAttributes().getAttribute(i, Kind);
+}
+
 bool CallInst::dataOperandHasImpliedAttr(unsigned i,
                                          Attribute::AttrKind Kind) const {
   // There are getNumOperands() - 1 data operands.  The last operand is the
@@ -724,6 +734,12 @@ void InvokeInst::removeAttribute(unsigned i, Attribute::AttrKind Kind) {
   setAttributes(PAL);
 }
 
+void InvokeInst::removeAttribute(unsigned i, StringRef Kind) {
+  AttributeSet PAL = getAttributes();
+  PAL = PAL.removeAttribute(getContext(), i, Kind);
+  setAttributes(PAL);
+}
+
 void InvokeInst::removeAttribute(unsigned i, Attribute Attr) {
   AttributeSet PAL = getAttributes();
   AttrBuilder B(Attr);
@@ -737,6 +753,10 @@ Attribute InvokeInst::getAttribute(unsigned i,
   return getAttributes().getAttribute(i, Kind);
 }
 
+Attribute InvokeInst::getAttribute(unsigned i, StringRef Kind) const {
+  return getAttributes().getAttribute(i, Kind);
+}
+
 void InvokeInst::addDereferenceableAttr(unsigned i, uint64_t Bytes) {
   AttributeSet PAL = getAttributes();
   PAL = PAL.addDereferenceableAttr(getContext(), i, Bytes);