Attributes.h revision 8ed701da9aa388c078cc6aecac2fe355974c90d2
158537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)//===-- llvm/Attributes.h - Container for Attributes ------------*- C++ -*-===//
258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)//
358537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)//                     The LLVM Compiler Infrastructure
458537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)//
558537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)// This file is distributed under the University of Illinois Open Source
658537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)// License. See LICENSE.TXT for details.
758537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)//
858537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)//===----------------------------------------------------------------------===//
958537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)///
1058537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)/// \file
1158537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)/// \brief This file contains the simple types necessary to represent the
1258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)/// attributes associated with functions and their calls.
1358537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)///
1458537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)//===----------------------------------------------------------------------===//
1558537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)
1658537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)#ifndef LLVM_IR_ATTRIBUTES_H
1758537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)#define LLVM_IR_ATTRIBUTES_H
1858537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)
1958537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)#include "llvm/ADT/ArrayRef.h"
2058537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)#include "llvm/ADT/DenseSet.h"
2158537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)#include "llvm/ADT/FoldingSet.h"
2258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)#include <cassert>
2358537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)#include <string>
2458537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)
2558537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)namespace llvm {
2658537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)
2758537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)class AttrBuilder;
2858537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)class AttributeImpl;
2958537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)class AttributeSetImpl;
3058537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)class AttributeSetNode;
3158537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)class Constant;
3258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)class LLVMContext;
3358537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)class Type;
3458537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)
3558537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)//===----------------------------------------------------------------------===//
3658537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)/// \class
3758537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)/// \brief Functions, function parameters, and return types can have attributes
3858537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)/// to indicate how they should be treated by optimizations and code
3958537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)/// generation. This class represents one of those attributes. It's light-weight
4058537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)/// and should be passed around by-value.
4158537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)class Attribute {
4258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)public:
4358537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  /// This enumeration lists the attributes that can be associated with
4458537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  /// parameters, function results, or the function itself.
4558537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  ///
4658537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  /// Note: The `uwtable' attribute is about the ABI or the user mandating an
4758537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  /// entry in the unwind table. The `nounwind' attribute is about an exception
4858537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  /// passing by the function.
4958537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  ///
5058537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  /// In a theoretical system that uses tables for profiling and SjLj for
5158537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  /// exceptions, they would be fully independent. In a normal system that uses
5258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  /// tables for both, the semantics are:
5358537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  ///
5458537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  /// nil                = Needs an entry because an exception might pass by.
5558537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  /// nounwind           = No need for an entry
5658537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  /// uwtable            = Needs an entry because the ABI says so and because
5758537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  ///                      an exception might pass by.
5858537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  /// uwtable + nounwind = Needs an entry because the ABI says so.
5958537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)
6058537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  enum AttrKind {
614e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)    // IR-Level Attributes
624e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)    None,                  ///< No attributes have been set
634e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)    AddressSafety,         ///< Address safety checking is on.
644e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)    Alignment,             ///< Alignment of parameter (5 bits)
654e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)                           ///< stored as log2 of alignment with +1 bias
664e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)                           ///< 0 means unaligned (different from align(1))
674e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)    AlwaysInline,          ///< inline=always
684e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)    ByVal,                 ///< Pass structure by value
694e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)    InlineHint,            ///< Source said inlining was desirable
704e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)    InReg,                 ///< Force argument to be passed in register
7168043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)    MinSize,               ///< Function must be optimized for size first
7258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)    Naked,                 ///< Naked function
7358537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)    Nest,                  ///< Nested function static chain
744e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)    NoAlias,               ///< Considered to not alias after call
754e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)    NoCapture,             ///< Function creates no aliases of pointer
7658537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)    NoDuplicate,           ///< Call cannot be duplicated
7758537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)    NoImplicitFloat,       ///< Disable implicit floating point insts
7858537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)    NoInline,              ///< inline=never
7958537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)    NonLazyBind,           ///< Function is called early and/or
8058537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)                           ///< often, so lazy binding isn't worthwhile
8158537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)    NoRedZone,             ///< Disable redzone
824e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)    NoReturn,              ///< Mark the function as not returning
834e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)    NoUnwind,              ///< Function doesn't unwind stack
844e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)    OptimizeForSize,       ///< opt_size
8558537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)    ReadNone,              ///< Function does not access memory
864e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)    ReadOnly,              ///< Function only reads from memory
874e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)    ReturnsTwice,          ///< Function can return twice
884e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)    SExt,                  ///< Sign extended before/after call
8958537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)    StackAlignment,        ///< Alignment of stack for function (3 bits)
9058537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)                           ///< stored as log2 of alignment with +1 bias 0
91010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)                           ///< means unaligned (different from
9258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)                           ///< alignstack=(1))
9358537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)    StackProtect,          ///< Stack protection.
9458537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)    StackProtectReq,       ///< Stack protection required.
9558537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)    StackProtectStrong,    ///< Strong Stack protection.
9658537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)    StructRet,             ///< Hidden pointer to structure to return
9758537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)    UWTable,               ///< Function must be in a unwind table
9858537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)    ZExt,                  ///< Zero extended before/after call
9958537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)
1004e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)    EndAttrKinds,          ///< Sentinal value useful for loops
1014e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
10258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)    AttrKindEmptyKey,      ///< Empty key value for DenseMapInfo
1034e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)    AttrKindTombstoneKey   ///< Tombstone key value for DenseMapInfo
1044e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  };
1054e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)private:
1064e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  AttributeImpl *pImpl;
1074e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  Attribute(AttributeImpl *A) : pImpl(A) {}
1084e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
1094e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  static Attribute get(LLVMContext &Context, AttrBuilder &B);
1104e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)public:
11158537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  Attribute() : pImpl(0) {}
1124e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
11358537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  //===--------------------------------------------------------------------===//
11458537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  // Attribute Construction
1154e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  //===--------------------------------------------------------------------===//
1164e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
1174e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  /// \brief Return a uniquified Attribute object.
1184e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  static Attribute get(LLVMContext &Context, AttrKind Kind);
1194e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
1204e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  /// \brief Return a uniquified Attribute object that has the specific
1214e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  /// alignment set.
1224e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  static Attribute getWithAlignment(LLVMContext &Context, uint64_t Align);
123effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch  static Attribute getWithStackAlignment(LLVMContext &Context, uint64_t Align);
124effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch
125effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch  //===--------------------------------------------------------------------===//
126effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch  // Attribute Accessors
127effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch  //===--------------------------------------------------------------------===//
128effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch
129effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch  /// \brief Return true if the attribute is present.
130effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch  bool hasAttribute(AttrKind Val) const;
131effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch
132effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch  /// \brief Return true if attributes exist
133effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch  bool hasAttributes() const;
134effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch
135effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch  /// \brief Return the kind of this attribute.
136effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch  Constant *getAttributeKind() const;
137effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch
138effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch  /// \brief Return the value (if present) of the non-target-specific attribute.
1394e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  ArrayRef<Constant*> getAttributeValues() const;
1404e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
1414e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  /// \brief Returns the alignment field of an attribute as a byte alignment
1424e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  /// value.
1434e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  unsigned getAlignment() const;
1444e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
1454e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  /// \brief Returns the stack alignment field of an attribute as a byte
1464e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  /// alignment value.
1474e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  unsigned getStackAlignment() const;
1484e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
1494e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  /// \brief The Attribute is converted to a string of equivalent mnemonic. This
1504e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  /// is, presumably, for writing out the mnemonics for the assembly writer.
1514e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  std::string getAsString() const;
1524e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
1534e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  /// \brief Equality and non-equality query methods.
154effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch  bool operator==(AttrKind K) const;
155effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch  bool operator!=(AttrKind K) const;
156effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch
157effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch  bool operator==(Attribute A) const { return pImpl == A.pImpl; }
1584e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  bool operator!=(Attribute A) const { return pImpl != A.pImpl; }
1594e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
1604e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  /// \brief Less-than operator. Useful for sorting the attributes list.
1614e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  bool operator<(Attribute A) const;
1624e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
1634e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  void Profile(FoldingSetNodeID &ID) const {
1644e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)    ID.AddPointer(pImpl);
1654e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  }
1664e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
1674e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  // FIXME: Remove this.
1684e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  uint64_t Raw() const;
1694e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)};
1704e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
1714e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)//===----------------------------------------------------------------------===//
1724e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)/// \class
1734e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)/// \brief This class manages the ref count for the opaque AttributeSetImpl
1744e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)/// object and provides accessors for it.
1754e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)class AttributeSet {
1764e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)public:
1774e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  enum AttrIndex {
1784e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)    ReturnIndex = 0U,
1794e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)    FunctionIndex = ~0U
18058537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  };
18158537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)private:
18258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  friend class AttrBuilder;
18358537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  friend class AttributeSetImpl;
18458537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)
18558537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  /// \brief The attributes that we are managing. This can be null to represent
18658537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  /// the empty attributes list.
18758537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  AttributeSetImpl *pImpl;
18858537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)
18958537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  /// \brief The attributes for the specified index are returned.
19058537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  AttributeSetNode *getAttributes(unsigned Idx) const;
19158537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)
19258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  /// \brief Create an AttributeSet with the specified parameters in it.
19358537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  static AttributeSet get(LLVMContext &C,
19458537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)                          ArrayRef<std::pair<unsigned, Attribute> > Attrs);
19558537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  static AttributeSet get(LLVMContext &C,
19658537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)                          ArrayRef<std::pair<unsigned,
19758537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)                                             AttributeSetNode*> > Attrs);
19868043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)
19958537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  static AttributeSet getImpl(LLVMContext &C,
20058537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)                              ArrayRef<std::pair<unsigned,
20158537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)                                                 AttributeSetNode*> > Attrs);
20258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)
20358537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)
20458537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  explicit AttributeSet(AttributeSetImpl *LI) : pImpl(LI) {}
20558537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)public:
20658537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  AttributeSet() : pImpl(0) {}
20758537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  AttributeSet(const AttributeSet &P) : pImpl(P.pImpl) {}
20858537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  const AttributeSet &operator=(const AttributeSet &RHS) {
20958537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)    pImpl = RHS.pImpl;
21058537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)    return *this;
21158537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  }
21258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)
21358537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  //===--------------------------------------------------------------------===//
21458537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  // AttributeSet Construction and Mutation
21558537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  //===--------------------------------------------------------------------===//
21668043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)
21758537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  /// \brief Return an AttributeSet with the specified parameters in it.
21858537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  static AttributeSet get(LLVMContext &C, ArrayRef<AttributeSet> Attrs);
21958537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  static AttributeSet get(LLVMContext &C, unsigned Idx,
22058537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)                          ArrayRef<Attribute::AttrKind> Kind);
22158537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  static AttributeSet get(LLVMContext &C, unsigned Idx, AttrBuilder &B);
22258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)
22358537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  /// \brief Add an attribute to the attribute set at the given index. Since
22458537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  /// attribute sets are immutable, this returns a new set.
22568043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)  AttributeSet addAttribute(LLVMContext &C, unsigned Idx,
22658537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)                            Attribute::AttrKind Attr) const;
22758537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)
22868043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)  /// \brief Add attributes to the attribute set at the given index. Since
22958537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  /// attribute sets are immutable, this returns a new set.
23068043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)  AttributeSet addAttributes(LLVMContext &C, unsigned Idx,
23168043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)                             AttributeSet Attrs) const;
23258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)
23368043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)  /// \brief Remove the specified attribute at the specified index from this
2344e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  /// attribute list. Since attribute lists are immutable, this returns the new
2354e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  /// list.
23658537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  AttributeSet removeAttribute(LLVMContext &C, unsigned Idx,
23768043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)                               Attribute::AttrKind Attr) const;
23868043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)
23958537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  /// \brief Remove the specified attributes at the specified index from this
24068043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)  /// attribute list. Since attribute lists are immutable, this returns the new
24158537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  /// list.
24258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  AttributeSet removeAttributes(LLVMContext &C, unsigned Idx,
24358537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)                                AttributeSet Attrs) const;
24458537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)
245effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch  //===--------------------------------------------------------------------===//
246effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch  // AttributeSet Accessors
247effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch  //===--------------------------------------------------------------------===//
24858537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)
24958537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  /// \brief The attributes for the specified index are returned.
25058537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  AttributeSet getParamAttributes(unsigned Idx) const;
25168043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)
25258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  /// \brief The attributes for the ret value are returned.
25358537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  AttributeSet getRetAttributes() const;
25468043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)
25558537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  /// \brief The function attributes are returned.
25658537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  AttributeSet getFnAttributes() const;
25758537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)
25868043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)  /// \brief Return true if the attribute exists at the given index.
25958537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  bool hasAttribute(unsigned Index, Attribute::AttrKind Kind) const;
26058537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)
26168043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)  /// \brief Return true if attribute exists at the given index.
26258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  bool hasAttributes(unsigned Index) const;
26368043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)
26458537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  /// \brief Return true if the specified attribute is set for at least one
26558537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  /// parameter or for the return value.
26658537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  bool hasAttrSomewhere(Attribute::AttrKind Attr) const;
26758537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)
26858537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  /// \brief Return the alignment for the specified function parameter.
26958537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  unsigned getParamAlignment(unsigned Idx) const;
270effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch
271effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch  /// \brief Get the stack alignment.
272effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch  unsigned getStackAlignment(unsigned Index) const;
273effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch
27458537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  /// \brief Return the attributes at the index as a string.
27558537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  std::string getAsString(unsigned Index) const;
27658537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)
277f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  /// operator==/!= - Provide equality predicates.
278f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  bool operator==(const AttributeSet &RHS) const {
279f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)    return pImpl == RHS.pImpl;
280f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  }
281f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  bool operator!=(const AttributeSet &RHS) const {
282f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)    return pImpl != RHS.pImpl;
283f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  }
284f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
285f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  //===--------------------------------------------------------------------===//
286f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  // AttributeSet Introspection
287f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  //===--------------------------------------------------------------------===//
288f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
289effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch  // FIXME: Remove this.
290effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch  uint64_t Raw(unsigned Index) const;
291effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch
292effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch  /// \brief Return a raw pointer that uniquely identifies this attribute list.
293effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch  void *getRawPointer() const {
294effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch    return pImpl;
295effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch  }
296effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch
297effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch  /// \brief Return true if there are no attributes.
298effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch  bool isEmpty() const {
299effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch    return getNumSlots() == 0;
300effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch  }
301effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch
302effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch  /// \brief Return the number of slots used in this attribute list.  This is
30358537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  /// the number of arguments that have an attribute set on them (including the
30458537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  /// function itself).
30558537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  unsigned getNumSlots() const;
30658537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)
30758537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  /// \brief Return the index for the given slot.
30858537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  uint64_t getSlotIndex(unsigned Slot) const;
30958537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)
31058537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  /// \brief Return the attributes at the given slot.
31158537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  AttributeSet getSlotAttributes(unsigned Slot) const;
31258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)
31358537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  void dump() const;
31458537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)};
31558537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)
31658537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)//===----------------------------------------------------------------------===//
31758537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)/// \class
31858537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)/// \brief Provide DenseMapInfo for Attribute::AttrKinds. This is used by
31958537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)/// AttrBuilder.
3205d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)template<> struct DenseMapInfo<Attribute::AttrKind> {
3215d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  static inline Attribute::AttrKind getEmptyKey() {
32258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)    return Attribute::AttrKindEmptyKey;
32358537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  }
32458537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  static inline Attribute::AttrKind getTombstoneKey() {
32558537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)    return Attribute::AttrKindTombstoneKey;
32658537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  }
32758537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  static unsigned getHashValue(const Attribute::AttrKind &Val) {
32868043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)    return Val * 37U;
32958537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  }
33068043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)  static bool isEqual(const Attribute::AttrKind &LHS,
33168043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)                      const Attribute::AttrKind &RHS) {
33268043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)    return LHS == RHS;
3335d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  }
3345d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)};
33558537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)
33658537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)//===----------------------------------------------------------------------===//
33758537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)/// \class
33858537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)/// \brief This class is used in conjunction with the Attribute::get method to
33958537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)/// create an Attribute object. The object itself is uniquified. The Builder's
34058537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)/// value, however, is not. So this can be used as a quick way to test for
34158537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)/// equality, presence of attributes, etc.
34258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)class AttrBuilder {
34358537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  DenseSet<Attribute::AttrKind> Attrs;
34458537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  uint64_t Alignment;
34558537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  uint64_t StackAlignment;
34658537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)public:
34758537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  AttrBuilder() : Alignment(0), StackAlignment(0) {}
34858537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  explicit AttrBuilder(uint64_t B) : Alignment(0), StackAlignment(0) {
34958537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)    addRawValue(B);
35058537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  }
35158537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  AttrBuilder(const Attribute &A) : Alignment(0), StackAlignment(0) {
35258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)    addAttributes(A);
35358537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  }
35458537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  AttrBuilder(AttributeSet AS, unsigned Idx);
35558537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)
35658537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  void clear();
35758537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)
35858537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  /// \brief Add an attribute to the builder.
35958537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  AttrBuilder &addAttribute(Attribute::AttrKind Val);
36058537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)
36158537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  /// \brief Remove an attribute from the builder.
36258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  AttrBuilder &removeAttribute(Attribute::AttrKind Val);
36358537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)
36458537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  /// \brief Add the attributes to the builder.
36558537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  AttrBuilder &addAttributes(Attribute A);
36658537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)
36758537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  /// \brief Remove the attributes from the builder.
36858537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  AttrBuilder &removeAttributes(AttributeSet A, uint64_t Index);
36958537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)
37058537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  /// \brief Return true if the builder has the specified attribute.
37158537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  bool contains(Attribute::AttrKind A) const;
37258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)
37358537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  /// \brief Return true if the builder has IR-level attributes.
37458537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  bool hasAttributes() const;
37558537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)
37658537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  /// \brief Return true if the builder has any attribute that's in the
37758537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  /// specified attribute.
37858537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  bool hasAttributes(AttributeSet A, uint64_t Index) const;
37958537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)
38058537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  /// \brief Return true if the builder has an alignment attribute.
38158537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  bool hasAlignmentAttr() const;
38258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)
38358537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  /// \brief Retrieve the alignment attribute, if it exists.
38458537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  uint64_t getAlignment() const { return Alignment; }
38558537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)
38658537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  /// \brief Retrieve the stack alignment attribute, if it exists.
38758537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  uint64_t getStackAlignment() const { return StackAlignment; }
38858537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)
38958537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  /// \brief This turns an int alignment (which must be a power of 2) into the
39058537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  /// form used internally in Attribute.
39158537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  AttrBuilder &addAlignmentAttr(unsigned Align);
39258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)
39358537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  /// \brief This turns an int stack alignment (which must be a power of 2) into
39458537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  /// the form used internally in Attribute.
39558537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  AttrBuilder &addStackAlignmentAttr(unsigned Align);
39658537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)
39758537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  typedef DenseSet<Attribute::AttrKind>::iterator       iterator;
39858537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  typedef DenseSet<Attribute::AttrKind>::const_iterator const_iterator;
39958537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)
40058537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  iterator begin()             { return Attrs.begin(); }
40158537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  iterator end()               { return Attrs.end(); }
40258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)
40358537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  const_iterator begin() const { return Attrs.begin(); }
40458537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  const_iterator end() const   { return Attrs.end(); }
40558537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)
40658537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  /// \brief Remove attributes that are used on functions only.
40758537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  void removeFunctionOnlyAttrs() {
40858537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)    removeAttribute(Attribute::NoReturn)
40958537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)      .removeAttribute(Attribute::NoUnwind)
41058537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)      .removeAttribute(Attribute::ReadNone)
41158537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)      .removeAttribute(Attribute::ReadOnly)
41258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)      .removeAttribute(Attribute::NoInline)
41358537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)      .removeAttribute(Attribute::AlwaysInline)
41458537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)      .removeAttribute(Attribute::OptimizeForSize)
41558537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)      .removeAttribute(Attribute::StackProtect)
41658537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)      .removeAttribute(Attribute::StackProtectReq)
41758537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)      .removeAttribute(Attribute::StackProtectStrong)
41858537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)      .removeAttribute(Attribute::NoRedZone)
41958537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)      .removeAttribute(Attribute::NoImplicitFloat)
42058537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)      .removeAttribute(Attribute::Naked)
42158537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)      .removeAttribute(Attribute::InlineHint)
42258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)      .removeAttribute(Attribute::StackAlignment)
42358537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)      .removeAttribute(Attribute::UWTable)
42458537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)      .removeAttribute(Attribute::NonLazyBind)
42558537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)      .removeAttribute(Attribute::ReturnsTwice)
42658537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)      .removeAttribute(Attribute::AddressSafety)
42758537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)      .removeAttribute(Attribute::MinSize)
42858537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)      .removeAttribute(Attribute::NoDuplicate);
42958537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  }
43058537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)
43158537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  bool operator==(const AttrBuilder &B);
43258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  bool operator!=(const AttrBuilder &B) {
43358537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)    return !(*this == B);
43458537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  }
43558537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)
43658537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  // FIXME: Remove these.
43758537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)
43858537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  /// \brief Add the raw value to the internal representation.
43958537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  ///
44058537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  /// N.B. This should be used ONLY for decoding LLVM bitcode!
44158537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  AttrBuilder &addRawValue(uint64_t Val);
44258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)
443  uint64_t Raw() const;
444};
445
446namespace AttributeFuncs {
447
448/// \brief Which attributes cannot be applied to a type.
449AttributeSet typeIncompatible(Type *Ty, uint64_t Index);
450
451/// \brief This returns an integer containing an encoding of all the LLVM
452/// attributes found in the given attribute bitset.  Any change to this encoding
453/// is a breaking change to bitcode compatibility.
454uint64_t encodeLLVMAttributesForBitcode(AttributeSet Attrs, unsigned Index);
455
456/// \brief This fills an AttrBuilder object with the LLVM attributes that have
457/// been decoded from the given integer. This function must stay in sync with
458/// 'encodeLLVMAttributesForBitcode'.
459/// N.B. This should be used only by the bitcode reader!
460void decodeLLVMAttributesForBitcode(LLVMContext &C, AttrBuilder &B,
461                                    uint64_t EncodedAttrs);
462
463} // end AttributeFuncs namespace
464
465} // end llvm namespace
466
467#endif
468