diff --git a/include/llvm/IR/Attributes.h b/include/llvm/IR/Attributes.h index c726020ab80..61202eebefb 100644 --- a/include/llvm/IR/Attributes.h +++ b/include/llvm/IR/Attributes.h @@ -20,6 +20,7 @@ #include "llvm/ADT/DenseSet.h" #include "llvm/ADT/FoldingSet.h" #include +#include #include namespace llvm { @@ -341,6 +342,7 @@ template<> struct DenseMapInfo { /// equality, presence of attributes, etc. class AttrBuilder { DenseSet Attrs; + std::map TargetDepAttrs; uint64_t Alignment; uint64_t StackAlignment; public: @@ -361,12 +363,18 @@ public: /// \brief Add the Attribute object to the builder. AttrBuilder &addAttribute(Attribute A); + /// \brief Add the target-dependent attribute to the builder. + AttrBuilder &addAttribute(StringRef A, StringRef V); + /// \brief Remove an attribute from the builder. AttrBuilder &removeAttribute(Attribute::AttrKind Val); /// \brief Remove the attributes from the builder. AttrBuilder &removeAttributes(AttributeSet A, uint64_t Index); + /// \brief Remove the target-dependent attribute to the builder. + AttrBuilder &removeAttribute(StringRef A); + /// \brief Return true if the builder has the specified attribute. bool contains(Attribute::AttrKind A) const; diff --git a/lib/IR/Attributes.cpp b/lib/IR/Attributes.cpp index 909f22f1522..8a0551cbf12 100644 --- a/lib/IR/Attributes.cpp +++ b/lib/IR/Attributes.cpp @@ -46,7 +46,7 @@ Attribute Attribute::get(LLVMContext &Context, Constant *Kind, Constant *Val) { pImpl->AttrsSet.InsertNode(PA, InsertPoint); } - // Return the AttributesList that we found or created. + // Return the Attribute that we found or created. return Attribute(PA); } @@ -826,6 +826,11 @@ AttrBuilder &AttrBuilder::addAttribute(Attribute Attr) { return *this; } +AttrBuilder &AttrBuilder::addAttribute(StringRef A, StringRef V) { + TargetDepAttrs[A] = V; + return *this; +} + AttrBuilder &AttrBuilder::removeAttribute(Attribute::AttrKind Val) { Attrs.erase(Val); @@ -861,6 +866,13 @@ AttrBuilder &AttrBuilder::removeAttributes(AttributeSet A, uint64_t Index) { return *this; } +AttrBuilder &AttrBuilder::removeAttribute(StringRef A) { + std::map::iterator I = TargetDepAttrs.find(A); + if (I != TargetDepAttrs.end()) + TargetDepAttrs.erase(I); + return *this; +} + AttrBuilder &AttrBuilder::addAlignmentAttr(unsigned Align) { if (Align == 0) return *this;