diff options
Diffstat (limited to 'lib/IR/Attributes.cpp')
| -rw-r--r-- | lib/IR/Attributes.cpp | 72 | 
1 files changed, 70 insertions, 2 deletions
diff --git a/lib/IR/Attributes.cpp b/lib/IR/Attributes.cpp index 3b1140ab542c8..ce60367a6c8bb 100644 --- a/lib/IR/Attributes.cpp +++ b/lib/IR/Attributes.cpp @@ -34,6 +34,8 @@  #include "llvm/Support/raw_ostream.h"  #include <algorithm>  #include <cassert> +#include <climits> +#include <cstddef>  #include <cstdint>  #include <limits>  #include <map> @@ -504,16 +506,74 @@ AttributeSet AttributeSet::get(LLVMContext &C, ArrayRef<Attribute> Attrs) {    return AttributeSet(AttributeSetNode::get(C, Attrs));  } +AttributeSet AttributeSet::addAttribute(LLVMContext &C, +                          Attribute::AttrKind Kind) const { +  if (hasAttribute(Kind)) return *this; +  AttrBuilder B; +  B.addAttribute(Kind); +  return addAttributes(C, AttributeSet::get(C, B)); +} + +AttributeSet AttributeSet::addAttribute(LLVMContext &C, StringRef Kind, +                          StringRef Value) const { +  AttrBuilder B; +  B.addAttribute(Kind, Value); +  return addAttributes(C, AttributeSet::get(C, B)); +} + +AttributeSet AttributeSet::addAttributes(LLVMContext &C, +                                         const AttributeSet AS) const { +  if (!hasAttributes()) +    return AS; + +  if (!AS.hasAttributes()) +    return *this; + +  AttrBuilder B(AS); +  for (Attribute I : *this) +    B.addAttribute(I); + + return get(C, B); +} + +AttributeSet AttributeSet::removeAttribute(LLVMContext &C, +                                             Attribute::AttrKind Kind) const { +  if (!hasAttribute(Kind)) return *this; +  AttrBuilder B; +  B.addAttribute(Kind); +  return removeAttributes(C, B); +} + +AttributeSet AttributeSet::removeAttribute(LLVMContext &C, +                                             StringRef Kind) const { +  if (!hasAttribute(Kind)) return *this; +  AttrBuilder B; +  B.addAttribute(Kind); +  return removeAttributes(C, B); +} + +AttributeSet AttributeSet::removeAttributes(LLVMContext &C, +                                              const AttrBuilder &Attrs) const { + +  // FIXME it is not obvious how this should work for alignment. +  // For now, say we can't pass in alignment, which no current use does. +  assert(!Attrs.hasAlignmentAttr() && "Attempt to change alignment!"); + +  AttrBuilder B(*this); +  B.remove(Attrs); +  return get(C, B); +} +  unsigned AttributeSet::getNumAttributes() const {    return SetNode ? SetNode->getNumAttributes() : 0;  }  bool AttributeSet::hasAttribute(Attribute::AttrKind Kind) const { -  return SetNode ? SetNode->hasAttribute(Kind) : 0; +  return SetNode ? SetNode->hasAttribute(Kind) : false;  }  bool AttributeSet::hasAttribute(StringRef Kind) const { -  return SetNode ? SetNode->hasAttribute(Kind) : 0; +  return SetNode ? SetNode->hasAttribute(Kind) : false;  }  Attribute AttributeSet::getAttribute(Attribute::AttrKind Kind) const { @@ -557,6 +617,14 @@ AttributeSet::iterator AttributeSet::end() const {    return SetNode ? SetNode->end() : nullptr;  } +#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP) +LLVM_DUMP_METHOD void AttributeSet::dump() const { +  dbgs() << "AS =\n"; +    dbgs() << "  { "; +    dbgs() << getAsString(true) << " }\n"; +} +#endif +  //===----------------------------------------------------------------------===//  // AttributeSetNode Definition  //===----------------------------------------------------------------------===//  | 
