+public:
+ /// Function parameters and results can have attributes to indicate how they
+ /// should be treated by optimizations and code generation. This enumeration
+ /// lists the attributes that can be associated with parameters, function
+ /// results or the function itself.
+ ///
+ /// Note that uwtable is about the ABI or the user mandating an entry in the
+ /// unwind table. The nounwind attribute is about an exception passing by the
+ /// function.
+ ///
+ /// In a theoretical system that uses tables for profiling and sjlj for
+ /// exceptions, they would be fully independent. In a normal system that uses
+ /// tables for both, the semantics are:
+ ///
+ /// nil = Needs an entry because an exception might pass by.
+ /// nounwind = No need for an entry
+ /// uwtable = Needs an entry because the ABI says so and because
+ /// an exception might pass by.
+ /// uwtable + nounwind = Needs an entry because the ABI says so.
+
+ enum AttrVal {
+ None = 0, ///< No attributes have been set
+ AddressSafety = 1, ///< Address safety checking is on.
+ Alignment = 2, ///< Alignment of parameter (5 bits)
+ ///< stored as log2 of alignment with +1 bias
+ ///< 0 means unaligned different from align 1
+ AlwaysInline = 3, ///< inline=always
+ ByVal = 4, ///< Pass structure by value
+ InlineHint = 5, ///< Source said inlining was desirable
+ InReg = 6, ///< Force argument to be passed in register
+ Naked = 7, ///< Naked function
+ Nest = 8, ///< Nested function static chain
+ NoAlias = 9, ///< Considered to not alias after call
+ NoCapture = 10, ///< Function creates no aliases of pointer
+ NoImplicitFloat = 11, ///< Disable implicit floating point insts
+ NoInline = 12, ///< inline=never
+ NonLazyBind = 13, ///< Function is called early and/or
+ ///< often, so lazy binding isn't worthwhile
+ NoRedZone = 14, ///< Disable redzone
+ NoReturn = 15, ///< Mark the function as not returning
+ NoUnwind = 16, ///< Function doesn't unwind stack
+ OptimizeForSize = 17, ///< opt_size
+ ReadNone = 18, ///< Function does not access memory
+ ReadOnly = 19, ///< Function only reads from memory
+ ReturnsTwice = 20, ///< Function can return twice
+ SExt = 21, ///< Sign extended before/after call
+ StackAlignment = 22, ///< Alignment of stack for function (3 bits)
+ ///< stored as log2 of alignment with +1 bias 0
+ ///< means unaligned (different from
+ ///< alignstack={1))
+ StackProtect = 23, ///< Stack protection.
+ StackProtectReq = 24, ///< Stack protection required.
+ StructRet = 25, ///< Hidden pointer to structure to return
+ UWTable = 26, ///< Function must be in a unwind table
+ ZExt = 27 ///< Zero extended before/after call
+ };
+private:
+ AttributesImpl Attrs;
+
+ explicit Attributes(AttributesImpl *A);
+public:
+ Attributes() : Attrs(0) {}
+ explicit Attributes(uint64_t Val);
+ explicit Attributes(LLVMContext &C, AttrVal Val);
+ Attributes(const Attributes &A);
+
+ class Builder {
+ friend class Attributes;
+ uint64_t Bits;
+ public:
+ Builder() : Bits(0) {}
+ explicit Builder(uint64_t B) : Bits(B) {}
+ Builder(const Attributes &A) : Bits(A.Raw()) {}
+
+ void clear() { Bits = 0; }
+
+ bool hasAttribute(Attributes::AttrVal A) const;
+ bool hasAttributes() const;
+ bool hasAttributes(const Attributes &A) const;
+ bool hasAlignmentAttr() const;
+
+ uint64_t getAlignment() const;
+ uint64_t getStackAlignment() const;
+
+ Builder &addAttribute(Attributes::AttrVal Val);
+ Builder &removeAttribute(Attributes::AttrVal Val);
+
+ /// addRawValue - Add the raw value to the internal representation. This
+ /// should be used ONLY for decoding bitcode!
+ Builder &addRawValue(uint64_t Val);
+
+ /// addAlignmentAttr - This turns an int alignment (which must be a power of
+ /// 2) into the form used internally in Attributes.
+ Builder &addAlignmentAttr(unsigned Align);
+
+ /// addStackAlignmentAttr - This turns an int stack alignment (which must be
+ /// a power of 2) into the form used internally in Attributes.
+ Builder &addStackAlignmentAttr(unsigned Align);
+
+ Builder &removeAttributes(const Attributes &A);
+
+ /// @brief Remove attributes that are used on functions only.
+ void removeFunctionOnlyAttrs() {
+ removeAttribute(Attributes::NoReturn)
+ .removeAttribute(Attributes::NoUnwind)
+ .removeAttribute(Attributes::ReadNone)
+ .removeAttribute(Attributes::ReadOnly)
+ .removeAttribute(Attributes::NoInline)
+ .removeAttribute(Attributes::AlwaysInline)
+ .removeAttribute(Attributes::OptimizeForSize)
+ .removeAttribute(Attributes::StackProtect)
+ .removeAttribute(Attributes::StackProtectReq)
+ .removeAttribute(Attributes::NoRedZone)
+ .removeAttribute(Attributes::NoImplicitFloat)
+ .removeAttribute(Attributes::Naked)
+ .removeAttribute(Attributes::InlineHint)
+ .removeAttribute(Attributes::StackAlignment)
+ .removeAttribute(Attributes::UWTable)
+ .removeAttribute(Attributes::NonLazyBind)
+ .removeAttribute(Attributes::ReturnsTwice)
+ .removeAttribute(Attributes::AddressSafety);
+ }
+
+ bool operator==(const Builder &B) {
+ return Bits == B.Bits;
+ }
+ bool operator!=(const Builder &B) {
+ return Bits != B.Bits;
+ }
+ };
+
+ /// get - Return a uniquified Attributes object. This takes the uniquified
+ /// value from the Builder and wraps it in the Attributes class.
+ static Attributes get(Builder &B);
+ static Attributes get(LLVMContext &Context, Builder &B);
+
+ /// @brief Return true if the attribute is present.
+ bool hasAttribute(AttrVal Val) const;
+
+ /// @brief Return true if attributes exist
+ bool hasAttributes() const {
+ return Attrs.hasAttributes();