From e261492fd485b51c581673530668b0da4c3f93c1 Mon Sep 17 00:00:00 2001 From: Bill Wendling Date: Wed, 6 Feb 2013 01:16:00 +0000 Subject: [PATCH] Add methods to merge an AttrBuilder into another builder. This is useful when parsing an object that references multiple attribute groups. N.B. If both builders have alignments specified, then they should match! llvm-svn: 174480 --- llvm/include/llvm/IR/Attributes.h | 7 +++++++ llvm/lib/IR/Attributes.cpp | 17 +++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/llvm/include/llvm/IR/Attributes.h b/llvm/include/llvm/IR/Attributes.h index 83396e1..d0fe2e15 100644 --- a/llvm/include/llvm/IR/Attributes.h +++ b/llvm/include/llvm/IR/Attributes.h @@ -373,6 +373,10 @@ public: addAttribute(A); } AttrBuilder(AttributeSet AS, unsigned Idx); + AttrBuilder(const AttrBuilder &B) + : Attrs(B.Attrs), + TargetDepAttrs(B.TargetDepAttrs.begin(), B.TargetDepAttrs.end()), + Alignment(B.Alignment), StackAlignment(B.StackAlignment) {} void clear(); @@ -394,6 +398,9 @@ public: /// \brief Remove the target-dependent attribute to the builder. AttrBuilder &removeAttribute(StringRef A); + /// \brief Add the attributes from the builder. + AttrBuilder &merge(const AttrBuilder &B); + /// \brief Return true if the builder has the specified attribute. bool contains(Attribute::AttrKind A) const; diff --git a/llvm/lib/IR/Attributes.cpp b/llvm/lib/IR/Attributes.cpp index dc1a657..67ab4ea 100644 --- a/llvm/lib/IR/Attributes.cpp +++ b/llvm/lib/IR/Attributes.cpp @@ -956,6 +956,23 @@ AttrBuilder &AttrBuilder::addStackAlignmentAttr(unsigned Align) { return *this; } +AttrBuilder &AttrBuilder::merge(const AttrBuilder &B) { + // FIXME: What if both have alignments, but they don't match?! + if (!Alignment) + Alignment = B.Alignment; + + if (!StackAlignment) + StackAlignment = B.StackAlignment; + + Attrs.insert(B.Attrs.begin(), B.Attrs.end()); + + for (td_const_iterator I = B.TargetDepAttrs.begin(), + E = B.TargetDepAttrs.end(); I != E; ++I) + TargetDepAttrs[I->first] = I->second; + + return *this; +} + bool AttrBuilder::contains(Attribute::AttrKind A) const { return Attrs.count(A); } -- 2.7.4