Attributes.h revision 956f13440a4aa0297606a4412f4aa091d931592a
15f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===-- llvm/Attributes.h - Container for Attributes ------------*- C++ -*-===// 25f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// 35f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// The LLVM Compiler Infrastructure 45f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// 50bc735ffcfb223c0186419547abaa5c84482663eChris Lattner// This file is distributed under the University of Illinois Open Source 60bc735ffcfb223c0186419547abaa5c84482663eChris Lattner// License. See LICENSE.TXT for details. 75f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// 85f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===// 95f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// \file 115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// \brief This file contains the simple types necessary to represent the 125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// attributes associated with functions and their calls. 135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 14ec55c941f2846db48bce4ed6dd2ce339e1a48962Ted Kremenek//===----------------------------------------------------------------------===// 1543b628cd47ecdc3caf640d79b3ad7ecef0f2c285Chris Lattner 16ec55c941f2846db48bce4ed6dd2ce339e1a48962Ted Kremenek#ifndef LLVM_IR_ATTRIBUTES_H 17f4c839657742b823cea1a95b18422f1ba74d3dddChris Lattner#define LLVM_IR_ATTRIBUTES_H 1823e47c6b6e8ccdd8daa378ab2a879644425c72d8Daniel Dunbar 1903201fbbdeb3eb7f465610b09c281ee6aa84e3caTed Kremenek#include "llvm/ADT/ArrayRef.h" 2003201fbbdeb3eb7f465610b09c281ee6aa84e3caTed Kremenek#include "llvm/ADT/DenseSet.h" 215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#include "llvm/Support/MathExtras.h" 225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#include <cassert> 23d6471f7c1921c7802804ce3ff6fe9768310f72b9David Blaikie#include <string> 243fdf4b071dc79fae778fb5f376485480756c76a3Chris Lattner 253fdf4b071dc79fae778fb5f376485480756c76a3Chris Lattnernamespace llvm { 26d6471f7c1921c7802804ce3ff6fe9768310f72b9David Blaikie 27b54d8af9a66cc20a6a9a9219c7eaea8df7ee7fd4Chris Lattnerclass AttrBuilder; 285f9e272e632e951b1efe824cd16acb4d96077930Chris Lattnerclass AttributeImpl; 290673cb30340aadaede7b795c763b00f6b64e611cChandler Carruthclass Constant; 305f9e272e632e951b1efe824cd16acb4d96077930Chris Lattnerclass LLVMContext; 313fdf4b071dc79fae778fb5f376485480756c76a3Chris Lattnerclass Type; 3222caddc91d2f6186739c6b20ec58ed38cd68e595Chris Lattner 3322caddc91d2f6186739c6b20ec58ed38cd68e595Chris Lattner//===----------------------------------------------------------------------===// 3422caddc91d2f6186739c6b20ec58ed38cd68e595Chris Lattner/// \class 3522caddc91d2f6186739c6b20ec58ed38cd68e595Chris Lattner/// \brief Functions, function parameters, and return types can have attributes 36d6471f7c1921c7802804ce3ff6fe9768310f72b9David Blaikie/// to indicate how they should be treated by optimizations and code 37d6471f7c1921c7802804ce3ff6fe9768310f72b9David Blaikie/// generation. This class represents one of those attributes. It's light-weight 3833e4e70c8c0a17e0ccb7465d96556b077a68ecb1Argyrios Kyrtzidis/// and should be passed around by-value. 3933e4e70c8c0a17e0ccb7465d96556b077a68ecb1Argyrios Kyrtzidisclass Attribute { 4033e4e70c8c0a17e0ccb7465d96556b077a68ecb1Argyrios Kyrtzidispublic: 413fdf4b071dc79fae778fb5f376485480756c76a3Chris Lattner /// This enumeration lists the attributes that can be associated with 4292dd386e3f05d176b45a638199d51f536bd9d1c4Chris Lattner /// parameters, function results or the function itself. 431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// 44cc5888d833caf90ebda37f24da40d2cd06b4d820Douglas Gregor /// Note: uwtable is about the ABI or the user mandating an entry in the 45cc5888d833caf90ebda37f24da40d2cd06b4d820Douglas Gregor /// unwind table. The nounwind attribute is about an exception passing by the 46cc5888d833caf90ebda37f24da40d2cd06b4d820Douglas Gregor /// function. 471e473ccb0e0f6fd1954bef330f7193c1a3fb3ba1Ted Kremenek /// 48cc5888d833caf90ebda37f24da40d2cd06b4d820Douglas Gregor /// In a theoretical system that uses tables for profiling and sjlj for 49cc5888d833caf90ebda37f24da40d2cd06b4d820Douglas Gregor /// exceptions, they would be fully independent. In a normal system that uses 50cc5888d833caf90ebda37f24da40d2cd06b4d820Douglas Gregor /// tables for both, the semantics are: 51cc5888d833caf90ebda37f24da40d2cd06b4d820Douglas Gregor /// 52cc5888d833caf90ebda37f24da40d2cd06b4d820Douglas Gregor /// nil = Needs an entry because an exception might pass by. 53cc5888d833caf90ebda37f24da40d2cd06b4d820Douglas Gregor /// nounwind = No need for an entry 54cc5888d833caf90ebda37f24da40d2cd06b4d820Douglas Gregor /// uwtable = Needs an entry because the ABI says so and because 55cc5888d833caf90ebda37f24da40d2cd06b4d820Douglas Gregor /// an exception might pass by. 56cc5888d833caf90ebda37f24da40d2cd06b4d820Douglas Gregor /// uwtable + nounwind = Needs an entry because the ABI says so. 57abc563f554951259bbe0315055cad92ee14d87e4Douglas Gregor 58182745ae7892bca0842d9c023370ade5f8d1c6e8Chris Lattner enum AttrKind { 59182745ae7892bca0842d9c023370ade5f8d1c6e8Chris Lattner // IR-Level Attributes 60d6471f7c1921c7802804ce3ff6fe9768310f72b9David Blaikie None, ///< No attributes have been set 6133e4e70c8c0a17e0ccb7465d96556b077a68ecb1Argyrios Kyrtzidis AddressSafety, ///< Address safety checking is on. 6233e4e70c8c0a17e0ccb7465d96556b077a68ecb1Argyrios Kyrtzidis Alignment, ///< Alignment of parameter (5 bits) 63182745ae7892bca0842d9c023370ade5f8d1c6e8Chris Lattner ///< stored as log2 of alignment with +1 bias 64182745ae7892bca0842d9c023370ade5f8d1c6e8Chris Lattner ///< 0 means unaligned (different from align(1)) 65d6471f7c1921c7802804ce3ff6fe9768310f72b9David Blaikie AlwaysInline, ///< inline=always 66d6471f7c1921c7802804ce3ff6fe9768310f72b9David Blaikie ByVal, ///< Pass structure by value 674f5e21e24fb9e6ec473a13f83b5c9a2c41501a70Douglas Gregor InlineHint, ///< Source said inlining was desirable 684f5e21e24fb9e6ec473a13f83b5c9a2c41501a70Douglas Gregor InReg, ///< Force argument to be passed in register 694f5e21e24fb9e6ec473a13f83b5c9a2c41501a70Douglas Gregor MinSize, ///< Function must be optimized for size first 704f5e21e24fb9e6ec473a13f83b5c9a2c41501a70Douglas Gregor Naked, ///< Naked function 714f5e21e24fb9e6ec473a13f83b5c9a2c41501a70Douglas Gregor Nest, ///< Nested function static chain 724f5e21e24fb9e6ec473a13f83b5c9a2c41501a70Douglas Gregor NoAlias, ///< Considered to not alias after call 7304ae2df026b275aae5dddfc0db5ca55ff4e62179Chris Lattner NoCapture, ///< Function creates no aliases of pointer 74d6471f7c1921c7802804ce3ff6fe9768310f72b9David Blaikie NoDuplicate, ///< Call cannot be duplicated 750827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis NoImplicitFloat, ///< Disable implicit floating point insts 7604ae2df026b275aae5dddfc0db5ca55ff4e62179Chris Lattner NoInline, ///< inline=never 7704ae2df026b275aae5dddfc0db5ca55ff4e62179Chris Lattner NonLazyBind, ///< Function is called early and/or 78d6471f7c1921c7802804ce3ff6fe9768310f72b9David Blaikie ///< often, so lazy binding isn't worthwhile 790827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis NoRedZone, ///< Disable redzone 8004ae2df026b275aae5dddfc0db5ca55ff4e62179Chris Lattner NoReturn, ///< Mark the function as not returning 8104ae2df026b275aae5dddfc0db5ca55ff4e62179Chris Lattner NoUnwind, ///< Function doesn't unwind stack 820827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis OptimizeForSize, ///< opt_size 830827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis ReadNone, ///< Function does not access memory 840827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis ReadOnly, ///< Function only reads from memory 850827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis ReturnsTwice, ///< Function can return twice 860827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis SExt, ///< Sign extended before/after call 8704ae2df026b275aae5dddfc0db5ca55ff4e62179Chris Lattner StackAlignment, ///< Alignment of stack for function (3 bits) 8804ae2df026b275aae5dddfc0db5ca55ff4e62179Chris Lattner ///< stored as log2 of alignment with +1 bias 0 8904ae2df026b275aae5dddfc0db5ca55ff4e62179Chris Lattner ///< means unaligned (different from 90d6471f7c1921c7802804ce3ff6fe9768310f72b9David Blaikie ///< alignstack=(1)) 91abc563f554951259bbe0315055cad92ee14d87e4Douglas Gregor StackProtect, ///< Stack protection. 92abc563f554951259bbe0315055cad92ee14d87e4Douglas Gregor StackProtectReq, ///< Stack protection required. 9385bea9777d444ccbcc086d98f075fe666c2e865dDouglas Gregor StructRet, ///< Hidden pointer to structure to return 94abc563f554951259bbe0315055cad92ee14d87e4Douglas Gregor UWTable, ///< Function must be in a unwind table 95abc563f554951259bbe0315055cad92ee14d87e4Douglas Gregor ZExt, ///< Zero extended before/after call 96abc563f554951259bbe0315055cad92ee14d87e4Douglas Gregor 97abc563f554951259bbe0315055cad92ee14d87e4Douglas Gregor EndAttrKinds, ///< Sentinal value useful for loops 98c0a575f9b791a25c94b1c3c832dd73ec564646bbArgyrios Kyrtzidis 99c0a575f9b791a25c94b1c3c832dd73ec564646bbArgyrios Kyrtzidis AttrKindEmptyKey, ///< Empty key value for DenseMapInfo 10085bea9777d444ccbcc086d98f075fe666c2e865dDouglas Gregor AttrKindTombstoneKey ///< Tombstone key value for DenseMapInfo 101abc563f554951259bbe0315055cad92ee14d87e4Douglas Gregor }; 10233e4e70c8c0a17e0ccb7465d96556b077a68ecb1Argyrios Kyrtzidisprivate: 103d6471f7c1921c7802804ce3ff6fe9768310f72b9David Blaikie AttributeImpl *pImpl; 104d6471f7c1921c7802804ce3ff6fe9768310f72b9David Blaikie Attribute(AttributeImpl *A) : pImpl(A) {} 10533e4e70c8c0a17e0ccb7465d96556b077a68ecb1Argyrios Kyrtzidispublic: 10633e4e70c8c0a17e0ccb7465d96556b077a68ecb1Argyrios Kyrtzidis Attribute() : pImpl(0) {} 107abc563f554951259bbe0315055cad92ee14d87e4Douglas Gregor 108dc0a2da1038cc725ad23d070e6a0d03078b7300dArgyrios Kyrtzidis /// \brief Return a uniquified Attribute object. This takes the uniquified 109dc0a2da1038cc725ad23d070e6a0d03078b7300dArgyrios Kyrtzidis /// value from the Builder and wraps it in the Attribute class. 110dc0a2da1038cc725ad23d070e6a0d03078b7300dArgyrios Kyrtzidis static Attribute get(LLVMContext &Context, ArrayRef<AttrKind> Vals); 111dc0a2da1038cc725ad23d070e6a0d03078b7300dArgyrios Kyrtzidis static Attribute get(LLVMContext &Context, AttrBuilder &B); 112dc0a2da1038cc725ad23d070e6a0d03078b7300dArgyrios Kyrtzidis 113dc0a2da1038cc725ad23d070e6a0d03078b7300dArgyrios Kyrtzidis /// \brief Return true if the attribute is present. 114dc0a2da1038cc725ad23d070e6a0d03078b7300dArgyrios Kyrtzidis bool hasAttribute(AttrKind Val) const; 115dc0a2da1038cc725ad23d070e6a0d03078b7300dArgyrios Kyrtzidis 116dc0a2da1038cc725ad23d070e6a0d03078b7300dArgyrios Kyrtzidis /// \brief Return true if attributes exist 117dc0a2da1038cc725ad23d070e6a0d03078b7300dArgyrios Kyrtzidis bool hasAttributes() const; 118abc563f554951259bbe0315055cad92ee14d87e4Douglas Gregor 1195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// \brief Returns the alignment field of an attribute as a byte alignment 120d6471f7c1921c7802804ce3ff6fe9768310f72b9David Blaikie /// value. 1215f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner unsigned getAlignment() const; 12293ea5cb0edf8e509c5113e70cb05ee247c9bdf6bDouglas Gregor 12393ea5cb0edf8e509c5113e70cb05ee247c9bdf6bDouglas Gregor /// \brief Set the alignment field of an attribute. 12493ea5cb0edf8e509c5113e70cb05ee247c9bdf6bDouglas Gregor void setAlignment(unsigned Align); 12593ea5cb0edf8e509c5113e70cb05ee247c9bdf6bDouglas Gregor 1269e2dac9c9b6bc4384c816a447cca6516a03c89f2Douglas Gregor /// \brief Returns the stack alignment field of an attribute as a byte 1279e2dac9c9b6bc4384c816a447cca6516a03c89f2Douglas Gregor /// alignment value. 12893ea5cb0edf8e509c5113e70cb05ee247c9bdf6bDouglas Gregor unsigned getStackAlignment() const; 12993ea5cb0edf8e509c5113e70cb05ee247c9bdf6bDouglas Gregor 130d6471f7c1921c7802804ce3ff6fe9768310f72b9David Blaikie /// \brief Set the stack alignment field of an attribute. 13193ea5cb0edf8e509c5113e70cb05ee247c9bdf6bDouglas Gregor void setStackAlignment(unsigned Align); 13293ea5cb0edf8e509c5113e70cb05ee247c9bdf6bDouglas Gregor 13393ea5cb0edf8e509c5113e70cb05ee247c9bdf6bDouglas Gregor /// \brief Equality and non-equality query methods. 13493ea5cb0edf8e509c5113e70cb05ee247c9bdf6bDouglas Gregor bool operator==(AttrKind K) const; 13593ea5cb0edf8e509c5113e70cb05ee247c9bdf6bDouglas Gregor bool operator!=(AttrKind K) const; 13693ea5cb0edf8e509c5113e70cb05ee247c9bdf6bDouglas Gregor 137d6471f7c1921c7802804ce3ff6fe9768310f72b9David Blaikie // FIXME: Remove these 'operator' methods. 138d6471f7c1921c7802804ce3ff6fe9768310f72b9David Blaikie bool operator==(const Attribute &A) const { 1390827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis return pImpl == A.pImpl; 1400827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis } 1410827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis bool operator!=(const Attribute &A) const { 1420827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis return pImpl != A.pImpl; 1430827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis } 1440827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis 1450827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis uint64_t Raw() const; 1460827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis 1470827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis /// \brief Which attributes cannot be applied to a type. 1480827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis static Attribute typeIncompatible(Type *Ty); 1490827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis 1500827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis /// \brief This returns an integer containing an encoding of all the LLVM 1510827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis /// attributes found in the given attribute bitset. Any change to this 1520827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis /// encoding is a breaking change to bitcode compatibility. 1530827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis static uint64_t encodeLLVMAttributesForBitcode(Attribute Attrs); 1540827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis 1550827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis /// \brief This returns an attribute bitset containing the LLVM attributes 1560827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis /// that have been decoded from the given integer. This function must stay in 1570827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis /// sync with 'encodeLLVMAttributesForBitcode'. 1580827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis static Attribute decodeLLVMAttributesForBitcode(LLVMContext &C, 1590827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis uint64_t EncodedAttrs); 1600827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis 1610827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis /// \brief The Attribute is converted to a string of equivalent mnemonic. This 1620827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis /// is, presumably, for writing out the mnemonics for the assembly writer. 163d6471f7c1921c7802804ce3ff6fe9768310f72b9David Blaikie std::string getAsString() const; 1640827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis}; 1650827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis 1660827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis//===----------------------------------------------------------------------===// 1670827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis/// \class 1680827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis/// \brief Provide DenseMapInfo for Attribute::AttrKinds. This is used by 1690827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis/// AttrBuilder. 1700827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidistemplate<> struct DenseMapInfo<Attribute::AttrKind> { 1710827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis static inline Attribute::AttrKind getEmptyKey() { 1723efd52cf8f4e57c5571bd8cc3168264c3bc46a1eArgyrios Kyrtzidis return Attribute::AttrKindEmptyKey; 1730827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis } 1740827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis static inline Attribute::AttrKind getTombstoneKey() { 1750827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis return Attribute::AttrKindTombstoneKey; 1760827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis } 1770827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis static unsigned getHashValue(const Attribute::AttrKind &Val) { 1783efd52cf8f4e57c5571bd8cc3168264c3bc46a1eArgyrios Kyrtzidis return Val * 37U; 1790827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis } 1800827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis static bool isEqual(const Attribute::AttrKind &LHS, 1810827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis const Attribute::AttrKind &RHS) { 1820827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis return LHS == RHS; 1830827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis } 1840827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis}; 1850827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis 186fc8f0e14ad142ed811e90fbd9a30e419e301c717Chris Lattner//===----------------------------------------------------------------------===// 1870827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis/// \class 1880827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis/// \brief This is just a pair of values to associate a set of attributes with 1890827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis/// an index. 1900827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidisstruct AttributeWithIndex { 1913efd52cf8f4e57c5571bd8cc3168264c3bc46a1eArgyrios Kyrtzidis Attribute Attrs; ///< The attributes that are set, or'd together. 1920827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis Constant *Val; ///< Value attached to attribute, e.g. alignment. 1930827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis unsigned Index; ///< Index of the parameter for which the attributes apply. 1940827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis ///< Index 0 is used for return value attributes. 1950827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis ///< Index ~0U is used for function attributes. 1960827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis 1970827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis static AttributeWithIndex get(LLVMContext &C, unsigned Idx, 1980827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis ArrayRef<Attribute::AttrKind> Attrs) { 1990827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis return get(Idx, Attribute::get(C, Attrs)); 2000827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis } 2010827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis static AttributeWithIndex get(unsigned Idx, Attribute Attrs) { 2020827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis AttributeWithIndex P; 2030827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis P.Index = Idx; 2043efd52cf8f4e57c5571bd8cc3168264c3bc46a1eArgyrios Kyrtzidis P.Attrs = Attrs; 2050827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis P.Val = 0; 2060827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis return P; 2070827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis } 2080827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis static AttributeWithIndex get(unsigned Idx, Attribute Attrs, Constant *Val) { 2093efd52cf8f4e57c5571bd8cc3168264c3bc46a1eArgyrios Kyrtzidis AttributeWithIndex P; 2100827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis P.Index = Idx; 2110827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis P.Attrs = Attrs; 2120827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis P.Val = Val; 2130827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis return P; 2140827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis } 2150827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis}; 2160827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis 2170827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis//===----------------------------------------------------------------------===// 2183efd52cf8f4e57c5571bd8cc3168264c3bc46a1eArgyrios Kyrtzidis// AttributeSet Smart Pointer 2190827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis//===----------------------------------------------------------------------===// 2200827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis 2210827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidisclass AttrBuilder; 2220827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidisclass AttributeSetImpl; 223d6471f7c1921c7802804ce3ff6fe9768310f72b9David Blaikie 224e59abb56ce0e1c206fb80bd945a0c358b0abe1efArgyrios Kyrtzidis//===----------------------------------------------------------------------===// 225e59abb56ce0e1c206fb80bd945a0c358b0abe1efArgyrios Kyrtzidis/// \class 226e59abb56ce0e1c206fb80bd945a0c358b0abe1efArgyrios Kyrtzidis/// \brief This class manages the ref count for the opaque AttributeSetImpl 227e59abb56ce0e1c206fb80bd945a0c358b0abe1efArgyrios Kyrtzidis/// object and provides accessors for it. 228e59abb56ce0e1c206fb80bd945a0c358b0abe1efArgyrios Kyrtzidisclass AttributeSet { 229e59abb56ce0e1c206fb80bd945a0c358b0abe1efArgyrios Kyrtzidispublic: 230e59abb56ce0e1c206fb80bd945a0c358b0abe1efArgyrios Kyrtzidis enum AttrIndex { 231e59abb56ce0e1c206fb80bd945a0c358b0abe1efArgyrios Kyrtzidis ReturnIndex = 0U, 232e59abb56ce0e1c206fb80bd945a0c358b0abe1efArgyrios Kyrtzidis FunctionIndex = ~0U 233e59abb56ce0e1c206fb80bd945a0c358b0abe1efArgyrios Kyrtzidis }; 234e59abb56ce0e1c206fb80bd945a0c358b0abe1efArgyrios Kyrtzidisprivate: 235e59abb56ce0e1c206fb80bd945a0c358b0abe1efArgyrios Kyrtzidis friend class AttrBuilder; 236e59abb56ce0e1c206fb80bd945a0c358b0abe1efArgyrios Kyrtzidis 237e59abb56ce0e1c206fb80bd945a0c358b0abe1efArgyrios Kyrtzidis /// \brief The attributes that we are managing. This can be null to represent 238e59abb56ce0e1c206fb80bd945a0c358b0abe1efArgyrios Kyrtzidis /// the empty attributes list. 239e59abb56ce0e1c206fb80bd945a0c358b0abe1efArgyrios Kyrtzidis AttributeSetImpl *AttrList; 240d6471f7c1921c7802804ce3ff6fe9768310f72b9David Blaikie 241d6471f7c1921c7802804ce3ff6fe9768310f72b9David Blaikie /// \brief The attributes for the specified index are returned. Attributes 242e59abb56ce0e1c206fb80bd945a0c358b0abe1efArgyrios Kyrtzidis /// for the result are denoted with Idx = 0. 243e59abb56ce0e1c206fb80bd945a0c358b0abe1efArgyrios Kyrtzidis Attribute getAttributes(unsigned Idx) const; 244e59abb56ce0e1c206fb80bd945a0c358b0abe1efArgyrios Kyrtzidis 245e59abb56ce0e1c206fb80bd945a0c358b0abe1efArgyrios Kyrtzidis explicit AttributeSet(AttributeSetImpl *LI) : AttrList(LI) {} 246e59abb56ce0e1c206fb80bd945a0c358b0abe1efArgyrios Kyrtzidispublic: 247e59abb56ce0e1c206fb80bd945a0c358b0abe1efArgyrios Kyrtzidis AttributeSet() : AttrList(0) {} 248e59abb56ce0e1c206fb80bd945a0c358b0abe1efArgyrios Kyrtzidis AttributeSet(const AttributeSet &P) : AttrList(P.AttrList) {} 249e59abb56ce0e1c206fb80bd945a0c358b0abe1efArgyrios Kyrtzidis const AttributeSet &operator=(const AttributeSet &RHS); 250e59abb56ce0e1c206fb80bd945a0c358b0abe1efArgyrios Kyrtzidis 251e59abb56ce0e1c206fb80bd945a0c358b0abe1efArgyrios Kyrtzidis //===--------------------------------------------------------------------===// 252e59abb56ce0e1c206fb80bd945a0c358b0abe1efArgyrios Kyrtzidis // Attribute List Construction and Mutation 253d6471f7c1921c7802804ce3ff6fe9768310f72b9David Blaikie //===--------------------------------------------------------------------===// 254e59abb56ce0e1c206fb80bd945a0c358b0abe1efArgyrios Kyrtzidis 255e59abb56ce0e1c206fb80bd945a0c358b0abe1efArgyrios Kyrtzidis /// \brief Return an AttributeSet with the specified parameters in it. 256e59abb56ce0e1c206fb80bd945a0c358b0abe1efArgyrios Kyrtzidis static AttributeSet get(LLVMContext &C, ArrayRef<AttributeWithIndex> Attrs); 257e59abb56ce0e1c206fb80bd945a0c358b0abe1efArgyrios Kyrtzidis static AttributeSet get(LLVMContext &C, unsigned Idx, AttrBuilder &B); 258e59abb56ce0e1c206fb80bd945a0c358b0abe1efArgyrios Kyrtzidis 259e59abb56ce0e1c206fb80bd945a0c358b0abe1efArgyrios Kyrtzidis /// \brief Add the specified attribute at the specified index to this 260b535041ee33c5eff255832bc5541c8d52aae8254Douglas Gregor /// attribute list. Since attribute lists are immutable, this returns the new 261b535041ee33c5eff255832bc5541c8d52aae8254Douglas Gregor /// list. 262b535041ee33c5eff255832bc5541c8d52aae8254Douglas Gregor AttributeSet addAttr(LLVMContext &C, unsigned Idx, Attribute Attrs) const; 263b535041ee33c5eff255832bc5541c8d52aae8254Douglas Gregor 264b535041ee33c5eff255832bc5541c8d52aae8254Douglas Gregor /// \brief Add function attributes to this attribute set. Since attribute sets 265b535041ee33c5eff255832bc5541c8d52aae8254Douglas Gregor /// are immutable, this returns a new set. 26693ea5cb0edf8e509c5113e70cb05ee247c9bdf6bDouglas Gregor AttributeSet addFnAttributes(LLVMContext &C, AttributeSet Attrs) const; 26793ea5cb0edf8e509c5113e70cb05ee247c9bdf6bDouglas Gregor 26893ea5cb0edf8e509c5113e70cb05ee247c9bdf6bDouglas Gregor /// \brief Remove the specified attribute at the specified index from this 26993ea5cb0edf8e509c5113e70cb05ee247c9bdf6bDouglas Gregor /// attribute list. Since attribute lists are immutable, this returns the new 27093ea5cb0edf8e509c5113e70cb05ee247c9bdf6bDouglas Gregor /// list. 27193ea5cb0edf8e509c5113e70cb05ee247c9bdf6bDouglas Gregor AttributeSet removeAttr(LLVMContext &C, unsigned Idx, Attribute Attrs) const; 272d6471f7c1921c7802804ce3ff6fe9768310f72b9David Blaikie 273b535041ee33c5eff255832bc5541c8d52aae8254Douglas Gregor //===--------------------------------------------------------------------===// 27493ea5cb0edf8e509c5113e70cb05ee247c9bdf6bDouglas Gregor // Attribute List Accessors 27593ea5cb0edf8e509c5113e70cb05ee247c9bdf6bDouglas Gregor //===--------------------------------------------------------------------===// 27693ea5cb0edf8e509c5113e70cb05ee247c9bdf6bDouglas Gregor 27793ea5cb0edf8e509c5113e70cb05ee247c9bdf6bDouglas Gregor /// \brief The attributes for the specified index are returned. 27893ea5cb0edf8e509c5113e70cb05ee247c9bdf6bDouglas Gregor Attribute getParamAttributes(unsigned Idx) const { 27993ea5cb0edf8e509c5113e70cb05ee247c9bdf6bDouglas Gregor return getAttributes(Idx); 2809e2dac9c9b6bc4384c816a447cca6516a03c89f2Douglas Gregor } 28193ea5cb0edf8e509c5113e70cb05ee247c9bdf6bDouglas Gregor 28293ea5cb0edf8e509c5113e70cb05ee247c9bdf6bDouglas Gregor /// \brief The attributes for the ret value are returned. 28393ea5cb0edf8e509c5113e70cb05ee247c9bdf6bDouglas Gregor Attribute getRetAttributes() const { 2849e2dac9c9b6bc4384c816a447cca6516a03c89f2Douglas Gregor return getAttributes(ReturnIndex); 28593ea5cb0edf8e509c5113e70cb05ee247c9bdf6bDouglas Gregor } 28693ea5cb0edf8e509c5113e70cb05ee247c9bdf6bDouglas Gregor 28793ea5cb0edf8e509c5113e70cb05ee247c9bdf6bDouglas Gregor /// \brief The function attributes are returned. 28893ea5cb0edf8e509c5113e70cb05ee247c9bdf6bDouglas Gregor Attribute getFnAttributes() const { 28993ea5cb0edf8e509c5113e70cb05ee247c9bdf6bDouglas Gregor return getAttributes(FunctionIndex); 29093ea5cb0edf8e509c5113e70cb05ee247c9bdf6bDouglas Gregor } 29193ea5cb0edf8e509c5113e70cb05ee247c9bdf6bDouglas Gregor 29293ea5cb0edf8e509c5113e70cb05ee247c9bdf6bDouglas Gregor /// \brief Return the alignment for the specified function parameter. 2937bfaaaecb3113f955db31e8d8a51acffd1bc0c27Nico Weber unsigned getParamAlignment(unsigned Idx) const; 2945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 2957bfaaaecb3113f955db31e8d8a51acffd1bc0c27Nico Weber /// \brief Return true if the attribute exists at the given index. 296d6471f7c1921c7802804ce3ff6fe9768310f72b9David Blaikie bool hasAttribute(unsigned Index, Attribute::AttrKind Kind) const; 297f2224d89a6ae65a3839529e26d0f6d025d83d6bbArgyrios Kyrtzidis 298f2224d89a6ae65a3839529e26d0f6d025d83d6bbArgyrios Kyrtzidis /// \brief Return true if attribute exists at the given index. 299f2224d89a6ae65a3839529e26d0f6d025d83d6bbArgyrios Kyrtzidis bool hasAttributes(unsigned Index) const; 300f2224d89a6ae65a3839529e26d0f6d025d83d6bbArgyrios Kyrtzidis 301d6471f7c1921c7802804ce3ff6fe9768310f72b9David Blaikie /// \brief Get the stack alignment. 302f2224d89a6ae65a3839529e26d0f6d025d83d6bbArgyrios Kyrtzidis unsigned getStackAlignment(unsigned Index) const; 303d6471f7c1921c7802804ce3ff6fe9768310f72b9David Blaikie 304f2224d89a6ae65a3839529e26d0f6d025d83d6bbArgyrios Kyrtzidis /// \brief Return the attributes at the index as a string. 305f2224d89a6ae65a3839529e26d0f6d025d83d6bbArgyrios Kyrtzidis std::string getAsString(unsigned Index) const; 306f4c839657742b823cea1a95b18422f1ba74d3dddChris Lattner 307af7ae4e8160fc5c23e471f2125b3fe5911e3532aChris Lattner uint64_t Raw(unsigned Index) const; 308af7ae4e8160fc5c23e471f2125b3fe5911e3532aChris Lattner 309af7ae4e8160fc5c23e471f2125b3fe5911e3532aChris Lattner /// \brief Return true if the specified attribute is set for at least one 310af7ae4e8160fc5c23e471f2125b3fe5911e3532aChris Lattner /// parameter or for the return value. 311af7ae4e8160fc5c23e471f2125b3fe5911e3532aChris Lattner bool hasAttrSomewhere(Attribute::AttrKind Attr) const; 312af7ae4e8160fc5c23e471f2125b3fe5911e3532aChris Lattner 313af7ae4e8160fc5c23e471f2125b3fe5911e3532aChris Lattner /// operator==/!= - Provide equality predicates. 314909c182f6a0e6169475eef6a71add14555b6162cJohn McCall bool operator==(const AttributeSet &RHS) const { 315909c182f6a0e6169475eef6a71add14555b6162cJohn McCall return AttrList == RHS.AttrList; 316909c182f6a0e6169475eef6a71add14555b6162cJohn McCall } 317909c182f6a0e6169475eef6a71add14555b6162cJohn McCall bool operator!=(const AttributeSet &RHS) const { 318909c182f6a0e6169475eef6a71add14555b6162cJohn McCall return AttrList != RHS.AttrList; 319909c182f6a0e6169475eef6a71add14555b6162cJohn McCall } 320909c182f6a0e6169475eef6a71add14555b6162cJohn McCall 321909c182f6a0e6169475eef6a71add14555b6162cJohn McCall //===--------------------------------------------------------------------===// 322909c182f6a0e6169475eef6a71add14555b6162cJohn McCall // Attribute List Introspection 323909c182f6a0e6169475eef6a71add14555b6162cJohn McCall //===--------------------------------------------------------------------===// 324909c182f6a0e6169475eef6a71add14555b6162cJohn McCall 325909c182f6a0e6169475eef6a71add14555b6162cJohn McCall /// \brief Return a raw pointer that uniquely identifies this attribute list. 326909c182f6a0e6169475eef6a71add14555b6162cJohn McCall void *getRawPointer() const { 327909c182f6a0e6169475eef6a71add14555b6162cJohn McCall return AttrList; 328909c182f6a0e6169475eef6a71add14555b6162cJohn McCall } 329909c182f6a0e6169475eef6a71add14555b6162cJohn McCall 330909c182f6a0e6169475eef6a71add14555b6162cJohn McCall // Attributes are stored as a dense set of slots, where there is one slot for 331909c182f6a0e6169475eef6a71add14555b6162cJohn McCall // each argument that has an attribute. This allows walking over the dense 332909c182f6a0e6169475eef6a71add14555b6162cJohn McCall // set instead of walking the sparse list of attributes. 333909c182f6a0e6169475eef6a71add14555b6162cJohn McCall 334909c182f6a0e6169475eef6a71add14555b6162cJohn McCall /// \brief Return true if there are no attributes. 335909c182f6a0e6169475eef6a71add14555b6162cJohn McCall bool isEmpty() const { 336909c182f6a0e6169475eef6a71add14555b6162cJohn McCall return AttrList == 0; 337909c182f6a0e6169475eef6a71add14555b6162cJohn McCall } 338909c182f6a0e6169475eef6a71add14555b6162cJohn McCall 339909c182f6a0e6169475eef6a71add14555b6162cJohn McCall /// \brief Return the number of slots used in this attribute list. This is 340909c182f6a0e6169475eef6a71add14555b6162cJohn McCall /// the number of arguments that have an attribute set on them (including the 341af7ae4e8160fc5c23e471f2125b3fe5911e3532aChris Lattner /// function itself). 342af7ae4e8160fc5c23e471f2125b3fe5911e3532aChris Lattner unsigned getNumSlots() const; 343af7ae4e8160fc5c23e471f2125b3fe5911e3532aChris Lattner 344af7ae4e8160fc5c23e471f2125b3fe5911e3532aChris Lattner /// \brief Return the AttributeWithIndex at the specified slot. This holds a 345af7ae4e8160fc5c23e471f2125b3fe5911e3532aChris Lattner /// index number plus a set of attributes. 3469f28614bf1a8387000d8df57a713fcf69e198145John McCall const AttributeWithIndex &getSlot(unsigned Slot) const; 347af7ae4e8160fc5c23e471f2125b3fe5911e3532aChris Lattner 3485f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner void dump() const; 349af7ae4e8160fc5c23e471f2125b3fe5911e3532aChris Lattner}; 3501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 351af7ae4e8160fc5c23e471f2125b3fe5911e3532aChris Lattner//===----------------------------------------------------------------------===// 352af7ae4e8160fc5c23e471f2125b3fe5911e3532aChris Lattner/// \class 353909c182f6a0e6169475eef6a71add14555b6162cJohn McCall/// \brief This class is used in conjunction with the Attribute::get method to 354af7ae4e8160fc5c23e471f2125b3fe5911e3532aChris Lattner/// create an Attribute object. The object itself is uniquified. The Builder's 355af7ae4e8160fc5c23e471f2125b3fe5911e3532aChris Lattner/// value, however, is not. So this can be used as a quick way to test for 356af7ae4e8160fc5c23e471f2125b3fe5911e3532aChris Lattner/// equality, presence of attributes, etc. 357af7ae4e8160fc5c23e471f2125b3fe5911e3532aChris Lattnerclass AttrBuilder { 358af7ae4e8160fc5c23e471f2125b3fe5911e3532aChris Lattner DenseSet<Attribute::AttrKind> Attrs; 3591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump uint64_t Alignment; 360af7ae4e8160fc5c23e471f2125b3fe5911e3532aChris Lattner uint64_t StackAlignment; 361909c182f6a0e6169475eef6a71add14555b6162cJohn McCallpublic: 3629f28614bf1a8387000d8df57a713fcf69e198145John McCall AttrBuilder() : Alignment(0), StackAlignment(0) {} 3639f28614bf1a8387000d8df57a713fcf69e198145John McCall explicit AttrBuilder(uint64_t B) : Alignment(0), StackAlignment(0) { 3649f28614bf1a8387000d8df57a713fcf69e198145John McCall addRawValue(B); 365af7ae4e8160fc5c23e471f2125b3fe5911e3532aChris Lattner } 366af7ae4e8160fc5c23e471f2125b3fe5911e3532aChris Lattner AttrBuilder(const Attribute &A) : Alignment(0), StackAlignment(0) { 367af7ae4e8160fc5c23e471f2125b3fe5911e3532aChris Lattner addAttributes(A); 368af7ae4e8160fc5c23e471f2125b3fe5911e3532aChris Lattner } 369af7ae4e8160fc5c23e471f2125b3fe5911e3532aChris Lattner AttrBuilder(AttributeSet AS, unsigned Idx); 370af7ae4e8160fc5c23e471f2125b3fe5911e3532aChris Lattner 3715f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner void clear(); 372af7ae4e8160fc5c23e471f2125b3fe5911e3532aChris Lattner 373af7ae4e8160fc5c23e471f2125b3fe5911e3532aChris Lattner /// \brief Add an attribute to the builder. 374af7ae4e8160fc5c23e471f2125b3fe5911e3532aChris Lattner AttrBuilder &addAttribute(Attribute::AttrKind Val); 375af7ae4e8160fc5c23e471f2125b3fe5911e3532aChris Lattner 3763be16b7d9d0ab075461ed3498b4c01b30b517c0eJohn McCall /// \brief Remove an attribute from the builder. 3773be16b7d9d0ab075461ed3498b4c01b30b517c0eJohn McCall AttrBuilder &removeAttribute(Attribute::AttrKind Val); 3783be16b7d9d0ab075461ed3498b4c01b30b517c0eJohn McCall 3793be16b7d9d0ab075461ed3498b4c01b30b517c0eJohn McCall /// \brief Add the attributes from A to the builder. 3803be16b7d9d0ab075461ed3498b4c01b30b517c0eJohn McCall AttrBuilder &addAttributes(const Attribute &A); 3815f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner 3823be16b7d9d0ab075461ed3498b4c01b30b517c0eJohn McCall /// \brief Remove the attributes from A from the builder. 3833be16b7d9d0ab075461ed3498b4c01b30b517c0eJohn McCall AttrBuilder &removeAttributes(const Attribute &A); 3843be16b7d9d0ab075461ed3498b4c01b30b517c0eJohn McCall 3853be16b7d9d0ab075461ed3498b4c01b30b517c0eJohn McCall /// \brief Return true if the builder has the specified attribute. 3863be16b7d9d0ab075461ed3498b4c01b30b517c0eJohn McCall bool contains(Attribute::AttrKind A) const; 3873be16b7d9d0ab075461ed3498b4c01b30b517c0eJohn McCall 3883be16b7d9d0ab075461ed3498b4c01b30b517c0eJohn McCall /// \brief Return true if the builder has IR-level attributes. 3893be16b7d9d0ab075461ed3498b4c01b30b517c0eJohn McCall bool hasAttributes() const; 3903be16b7d9d0ab075461ed3498b4c01b30b517c0eJohn McCall 3913be16b7d9d0ab075461ed3498b4c01b30b517c0eJohn McCall /// \brief Return true if the builder has any attribute that's in the 3923be16b7d9d0ab075461ed3498b4c01b30b517c0eJohn McCall /// specified attribute. 3933be16b7d9d0ab075461ed3498b4c01b30b517c0eJohn McCall bool hasAttributes(const Attribute &A) const; 3943be16b7d9d0ab075461ed3498b4c01b30b517c0eJohn McCall 3953be16b7d9d0ab075461ed3498b4c01b30b517c0eJohn McCall /// \brief Return true if the builder has an alignment attribute. 3963be16b7d9d0ab075461ed3498b4c01b30b517c0eJohn McCall bool hasAlignmentAttr() const; 3973be16b7d9d0ab075461ed3498b4c01b30b517c0eJohn McCall 3983be16b7d9d0ab075461ed3498b4c01b30b517c0eJohn McCall /// \brief Retrieve the alignment attribute, if it exists. 3993be16b7d9d0ab075461ed3498b4c01b30b517c0eJohn McCall uint64_t getAlignment() const { return Alignment; } 4003be16b7d9d0ab075461ed3498b4c01b30b517c0eJohn McCall 4013be16b7d9d0ab075461ed3498b4c01b30b517c0eJohn McCall /// \brief Retrieve the stack alignment attribute, if it exists. 4023be16b7d9d0ab075461ed3498b4c01b30b517c0eJohn McCall uint64_t getStackAlignment() const { return StackAlignment; } 4033be16b7d9d0ab075461ed3498b4c01b30b517c0eJohn McCall 4043be16b7d9d0ab075461ed3498b4c01b30b517c0eJohn McCall /// \brief This turns an int alignment (which must be a power of 2) into the 4053be16b7d9d0ab075461ed3498b4c01b30b517c0eJohn McCall /// form used internally in Attribute. 4063be16b7d9d0ab075461ed3498b4c01b30b517c0eJohn McCall AttrBuilder &addAlignmentAttr(unsigned Align); 407af7ae4e8160fc5c23e471f2125b3fe5911e3532aChris Lattner 408e4c452c4c7b9124fe94a96f559ff077d59cdf996Sebastian Redl /// \brief This turns an int stack alignment (which must be a power of 2) into 409d2aa7c90e7646c509f3493fa8548635ccf4a2d0aChris Lattner /// the form used internally in Attribute. 410e4c452c4c7b9124fe94a96f559ff077d59cdf996Sebastian Redl AttrBuilder &addStackAlignmentAttr(unsigned Align); 411e4c452c4c7b9124fe94a96f559ff077d59cdf996Sebastian Redl 412e4c452c4c7b9124fe94a96f559ff077d59cdf996Sebastian Redl typedef DenseSet<Attribute::AttrKind>::iterator iterator; 413e4c452c4c7b9124fe94a96f559ff077d59cdf996Sebastian Redl typedef DenseSet<Attribute::AttrKind>::const_iterator const_iterator; 414e4c452c4c7b9124fe94a96f559ff077d59cdf996Sebastian Redl 415e4c452c4c7b9124fe94a96f559ff077d59cdf996Sebastian Redl iterator begin() { return Attrs.begin(); } 416e4c452c4c7b9124fe94a96f559ff077d59cdf996Sebastian Redl iterator end() { return Attrs.end(); } 417e4c452c4c7b9124fe94a96f559ff077d59cdf996Sebastian Redl 418e4c452c4c7b9124fe94a96f559ff077d59cdf996Sebastian Redl const_iterator begin() const { return Attrs.begin(); } 419e4c452c4c7b9124fe94a96f559ff077d59cdf996Sebastian Redl const_iterator end() const { return Attrs.end(); } 420e4c452c4c7b9124fe94a96f559ff077d59cdf996Sebastian Redl 421d2aa7c90e7646c509f3493fa8548635ccf4a2d0aChris Lattner /// \brief Add the raw value to the internal representation. 422e4c452c4c7b9124fe94a96f559ff077d59cdf996Sebastian Redl /// 423e4c452c4c7b9124fe94a96f559ff077d59cdf996Sebastian Redl /// N.B. This should be used ONLY for decoding LLVM bitcode! 424e4c452c4c7b9124fe94a96f559ff077d59cdf996Sebastian Redl AttrBuilder &addRawValue(uint64_t Val); 425e4c452c4c7b9124fe94a96f559ff077d59cdf996Sebastian Redl 426e4c452c4c7b9124fe94a96f559ff077d59cdf996Sebastian Redl /// \brief Remove attributes that are used on functions only. 427e4c452c4c7b9124fe94a96f559ff077d59cdf996Sebastian Redl void removeFunctionOnlyAttrs() { 428e4c452c4c7b9124fe94a96f559ff077d59cdf996Sebastian Redl removeAttribute(Attribute::NoReturn) 429e4c452c4c7b9124fe94a96f559ff077d59cdf996Sebastian Redl .removeAttribute(Attribute::NoUnwind) 430e4c452c4c7b9124fe94a96f559ff077d59cdf996Sebastian Redl .removeAttribute(Attribute::ReadNone) 431e4c452c4c7b9124fe94a96f559ff077d59cdf996Sebastian Redl .removeAttribute(Attribute::ReadOnly) 432e4c452c4c7b9124fe94a96f559ff077d59cdf996Sebastian Redl .removeAttribute(Attribute::NoInline) 433e4c452c4c7b9124fe94a96f559ff077d59cdf996Sebastian Redl .removeAttribute(Attribute::AlwaysInline) 434e4c452c4c7b9124fe94a96f559ff077d59cdf996Sebastian Redl .removeAttribute(Attribute::OptimizeForSize) 435e4c452c4c7b9124fe94a96f559ff077d59cdf996Sebastian Redl .removeAttribute(Attribute::StackProtect) 436e4c452c4c7b9124fe94a96f559ff077d59cdf996Sebastian Redl .removeAttribute(Attribute::StackProtectReq) 437e4c452c4c7b9124fe94a96f559ff077d59cdf996Sebastian Redl .removeAttribute(Attribute::NoRedZone) 438d2aa7c90e7646c509f3493fa8548635ccf4a2d0aChris Lattner .removeAttribute(Attribute::NoImplicitFloat) 439e4c452c4c7b9124fe94a96f559ff077d59cdf996Sebastian Redl .removeAttribute(Attribute::Naked) 440e4c452c4c7b9124fe94a96f559ff077d59cdf996Sebastian Redl .removeAttribute(Attribute::InlineHint) 441e4c452c4c7b9124fe94a96f559ff077d59cdf996Sebastian Redl .removeAttribute(Attribute::StackAlignment) 442e4c452c4c7b9124fe94a96f559ff077d59cdf996Sebastian Redl .removeAttribute(Attribute::UWTable) 443e4c452c4c7b9124fe94a96f559ff077d59cdf996Sebastian Redl .removeAttribute(Attribute::NonLazyBind) 444e4c452c4c7b9124fe94a96f559ff077d59cdf996Sebastian Redl .removeAttribute(Attribute::ReturnsTwice) 445e4c452c4c7b9124fe94a96f559ff077d59cdf996Sebastian Redl .removeAttribute(Attribute::AddressSafety) 446e4c452c4c7b9124fe94a96f559ff077d59cdf996Sebastian Redl .removeAttribute(Attribute::MinSize) 447e4c452c4c7b9124fe94a96f559ff077d59cdf996Sebastian Redl .removeAttribute(Attribute::NoDuplicate); 448e4c452c4c7b9124fe94a96f559ff077d59cdf996Sebastian Redl } 449e4c452c4c7b9124fe94a96f559ff077d59cdf996Sebastian Redl 450e4c452c4c7b9124fe94a96f559ff077d59cdf996Sebastian Redl uint64_t Raw() const; 451e4c452c4c7b9124fe94a96f559ff077d59cdf996Sebastian Redl 452e4c452c4c7b9124fe94a96f559ff077d59cdf996Sebastian Redl bool operator==(const AttrBuilder &B); 453e4c452c4c7b9124fe94a96f559ff077d59cdf996Sebastian Redl bool operator!=(const AttrBuilder &B) { 454e4c452c4c7b9124fe94a96f559ff077d59cdf996Sebastian Redl return !(*this == B); 455e20653219732b03294130999415fc3aa92d2336aSebastian Redl } 456e4c452c4c7b9124fe94a96f559ff077d59cdf996Sebastian Redl}; 457e4c452c4c7b9124fe94a96f559ff077d59cdf996Sebastian Redl 458e4c452c4c7b9124fe94a96f559ff077d59cdf996Sebastian Redl} // end llvm namespace 459e4c452c4c7b9124fe94a96f559ff077d59cdf996Sebastian Redl 460e4c452c4c7b9124fe94a96f559ff077d59cdf996Sebastian Redl#endif 461e4c452c4c7b9124fe94a96f559ff077d59cdf996Sebastian Redl