Attributes.h revision 85df6b43403d3ebf5d80023a85699c6fb254941a
1710632d07b13609444626367bebd34c0af3acb6aMikhail Glushenkov//===-- llvm/Attributes.h - Container for Attributes ------------*- C++ -*-===// 26091ebd172a16a10f1ea66061a5fa7cbf5139e56Reid Spencer// 36091ebd172a16a10f1ea66061a5fa7cbf5139e56Reid Spencer// The LLVM Compiler Infrastructure 46091ebd172a16a10f1ea66061a5fa7cbf5139e56Reid Spencer// 57ed47a13356daed2a34cd2209a31f92552e3bdd8Chris Lattner// This file is distributed under the University of Illinois Open Source 67ed47a13356daed2a34cd2209a31f92552e3bdd8Chris Lattner// License. See LICENSE.TXT for details. 76091ebd172a16a10f1ea66061a5fa7cbf5139e56Reid Spencer// 86091ebd172a16a10f1ea66061a5fa7cbf5139e56Reid Spencer//===----------------------------------------------------------------------===// 927107f6ab4627fa38bcacad6757ed6d52910f880Bill Wendling/// 1027107f6ab4627fa38bcacad6757ed6d52910f880Bill Wendling/// \file 1127107f6ab4627fa38bcacad6757ed6d52910f880Bill Wendling/// \brief This file contains the simple types necessary to represent the 1227107f6ab4627fa38bcacad6757ed6d52910f880Bill Wendling/// attributes associated with functions and their calls. 1327107f6ab4627fa38bcacad6757ed6d52910f880Bill Wendling/// 146091ebd172a16a10f1ea66061a5fa7cbf5139e56Reid Spencer//===----------------------------------------------------------------------===// 156091ebd172a16a10f1ea66061a5fa7cbf5139e56Reid Spencer 16674be02d525d4e24bc6943ed9274958c580bcfbcJakub Staszak#ifndef LLVM_IR_ATTRIBUTES_H 17674be02d525d4e24bc6943ed9274958c580bcfbcJakub Staszak#define LLVM_IR_ATTRIBUTES_H 186091ebd172a16a10f1ea66061a5fa7cbf5139e56Reid Spencer 19d509d0b532ec2358b3f341d4a4cd1411cb8b5db2Chris Lattner#include "llvm/ADT/ArrayRef.h" 200319888773b36dd61d7d2283cb9a26cac1e5abe8Bill Wendling#include "llvm/ADT/DenseSet.h" 213467e30edf63b6d8a8d446186674ba9e4b7885a9Bill Wendling#include "llvm/ADT/FoldingSet.h" 2222bd64173981bf1251c4b3bfc684207340534ba3Bill Wendling#include <cassert> 23ea59f896a672c2e1ef9f02277bce60257aa60989Bill Wendling#include <map> 2458d74910c6b82e622ecbb57d6644d48fec5a5c0fChris Lattner#include <string> 256091ebd172a16a10f1ea66061a5fa7cbf5139e56Reid Spencer 266091ebd172a16a10f1ea66061a5fa7cbf5139e56Reid Spencernamespace llvm { 27d426a642a23a234547cbc7061f5bfec157673249Bill Wendling 28702cc91aa1bd41540e8674921ae7ac89a4ff061fBill Wendlingclass AttrBuilder; 29f6670729aabc1fab85238d2b306a1c1767a807bbBill Wendlingclass AttributeImpl; 30817abdd8b055059e5930a15704b9f52da4236456Bill Wendlingclass AttributeSetImpl; 31817abdd8b055059e5930a15704b9f52da4236456Bill Wendlingclass AttributeSetNode; 326dc3781d44e56f0addf28b06232a50f3f9e6b1afBill Wendlingclass Constant; 332c79ecbd704c656178ffa43d5a58ebe3ca188b40Bill Wendlingclass LLVMContext; 34ad9a9e15595bc9d5ba1ed752caf8572957f77a3dDuncan Sandsclass Type; 35ad9a9e15595bc9d5ba1ed752caf8572957f77a3dDuncan Sands 361d3dcfe4246b4d45fa78a8dfd0a11c7fff842c15Bill Wendling//===----------------------------------------------------------------------===// 3727107f6ab4627fa38bcacad6757ed6d52910f880Bill Wendling/// \class 3827107f6ab4627fa38bcacad6757ed6d52910f880Bill Wendling/// \brief Functions, function parameters, and return types can have attributes 391d3dcfe4246b4d45fa78a8dfd0a11c7fff842c15Bill Wendling/// to indicate how they should be treated by optimizations and code 401d3dcfe4246b4d45fa78a8dfd0a11c7fff842c15Bill Wendling/// generation. This class represents one of those attributes. It's light-weight 411d3dcfe4246b4d45fa78a8dfd0a11c7fff842c15Bill Wendling/// and should be passed around by-value. 42034b94b17006f51722886b0f2283fb6fb19aca1fBill Wendlingclass Attribute { 436765834754cbb3cb0f15b4b15e98c5e73fa50066Bill Wendlingpublic: 441d3dcfe4246b4d45fa78a8dfd0a11c7fff842c15Bill Wendling /// This enumeration lists the attributes that can be associated with 4573dee180c836270644dfa7d90f9c5ba877567999Bill Wendling /// parameters, function results, or the function itself. 46f3d1500ab2c7364d3d0fb73a7e1b8c6339ab48b1Bill Wendling /// 4773dee180c836270644dfa7d90f9c5ba877567999Bill Wendling /// Note: The `uwtable' attribute is about the ABI or the user mandating an 4873dee180c836270644dfa7d90f9c5ba877567999Bill Wendling /// entry in the unwind table. The `nounwind' attribute is about an exception 4973dee180c836270644dfa7d90f9c5ba877567999Bill Wendling /// passing by the function. 50f3d1500ab2c7364d3d0fb73a7e1b8c6339ab48b1Bill Wendling /// 5173dee180c836270644dfa7d90f9c5ba877567999Bill Wendling /// In a theoretical system that uses tables for profiling and SjLj for 5211d00420e42ba88c3b48cab997965a7be79315e2Bill Wendling /// exceptions, they would be fully independent. In a normal system that uses 5311d00420e42ba88c3b48cab997965a7be79315e2Bill Wendling /// tables for both, the semantics are: 54f3d1500ab2c7364d3d0fb73a7e1b8c6339ab48b1Bill Wendling /// 5511d00420e42ba88c3b48cab997965a7be79315e2Bill Wendling /// nil = Needs an entry because an exception might pass by. 5611d00420e42ba88c3b48cab997965a7be79315e2Bill Wendling /// nounwind = No need for an entry 5711d00420e42ba88c3b48cab997965a7be79315e2Bill Wendling /// uwtable = Needs an entry because the ABI says so and because 5811d00420e42ba88c3b48cab997965a7be79315e2Bill Wendling /// an exception might pass by. 5911d00420e42ba88c3b48cab997965a7be79315e2Bill Wendling /// uwtable + nounwind = Needs an entry because the ABI says so. 6011d00420e42ba88c3b48cab997965a7be79315e2Bill Wendling 61629fb82419d9bfff6ae475363bcce66192dfcc8eBill Wendling enum AttrKind { 625a0eeb5a9d727940b1dbe8dff6e9aa292ada0f6aBill Wendling // IR-Level Attributes 63480b1b28ea6fc1bb5c78d99472df624cfd3fce47Bill Wendling None, ///< No attributes have been set 64480b1b28ea6fc1bb5c78d99472df624cfd3fce47Bill Wendling AddressSafety, ///< Address safety checking is on. 65480b1b28ea6fc1bb5c78d99472df624cfd3fce47Bill Wendling Alignment, ///< Alignment of parameter (5 bits) 666765834754cbb3cb0f15b4b15e98c5e73fa50066Bill Wendling ///< stored as log2 of alignment with +1 bias 67f6670729aabc1fab85238d2b306a1c1767a807bbBill Wendling ///< 0 means unaligned (different from align(1)) 68480b1b28ea6fc1bb5c78d99472df624cfd3fce47Bill Wendling AlwaysInline, ///< inline=always 69480b1b28ea6fc1bb5c78d99472df624cfd3fce47Bill Wendling ByVal, ///< Pass structure by value 70480b1b28ea6fc1bb5c78d99472df624cfd3fce47Bill Wendling InlineHint, ///< Source said inlining was desirable 71480b1b28ea6fc1bb5c78d99472df624cfd3fce47Bill Wendling InReg, ///< Force argument to be passed in register 729a419f656e278b96e9dfe739cd63c7bff9a4e1fdQuentin Colombet MinSize, ///< Function must be optimized for size first 73480b1b28ea6fc1bb5c78d99472df624cfd3fce47Bill Wendling Naked, ///< Naked function 74480b1b28ea6fc1bb5c78d99472df624cfd3fce47Bill Wendling Nest, ///< Nested function static chain 75480b1b28ea6fc1bb5c78d99472df624cfd3fce47Bill Wendling NoAlias, ///< Considered to not alias after call 76480b1b28ea6fc1bb5c78d99472df624cfd3fce47Bill Wendling NoCapture, ///< Function creates no aliases of pointer 7767ae13575900e8efd056672987249fd0adbf5e73James Molloy NoDuplicate, ///< Call cannot be duplicated 78480b1b28ea6fc1bb5c78d99472df624cfd3fce47Bill Wendling NoImplicitFloat, ///< Disable implicit floating point insts 79480b1b28ea6fc1bb5c78d99472df624cfd3fce47Bill Wendling NoInline, ///< inline=never 80480b1b28ea6fc1bb5c78d99472df624cfd3fce47Bill Wendling NonLazyBind, ///< Function is called early and/or 813a106e60366a51b4594ec303ff8dbbc58913227fBill Wendling ///< often, so lazy binding isn't worthwhile 82480b1b28ea6fc1bb5c78d99472df624cfd3fce47Bill Wendling NoRedZone, ///< Disable redzone 83480b1b28ea6fc1bb5c78d99472df624cfd3fce47Bill Wendling NoReturn, ///< Mark the function as not returning 84480b1b28ea6fc1bb5c78d99472df624cfd3fce47Bill Wendling NoUnwind, ///< Function doesn't unwind stack 85480b1b28ea6fc1bb5c78d99472df624cfd3fce47Bill Wendling OptimizeForSize, ///< opt_size 86480b1b28ea6fc1bb5c78d99472df624cfd3fce47Bill Wendling ReadNone, ///< Function does not access memory 87480b1b28ea6fc1bb5c78d99472df624cfd3fce47Bill Wendling ReadOnly, ///< Function only reads from memory 88480b1b28ea6fc1bb5c78d99472df624cfd3fce47Bill Wendling ReturnsTwice, ///< Function can return twice 89480b1b28ea6fc1bb5c78d99472df624cfd3fce47Bill Wendling SExt, ///< Sign extended before/after call 90480b1b28ea6fc1bb5c78d99472df624cfd3fce47Bill Wendling StackAlignment, ///< Alignment of stack for function (3 bits) 916765834754cbb3cb0f15b4b15e98c5e73fa50066Bill Wendling ///< stored as log2 of alignment with +1 bias 0 926765834754cbb3cb0f15b4b15e98c5e73fa50066Bill Wendling ///< means unaligned (different from 93f6670729aabc1fab85238d2b306a1c1767a807bbBill Wendling ///< alignstack=(1)) 94480b1b28ea6fc1bb5c78d99472df624cfd3fce47Bill Wendling StackProtect, ///< Stack protection. 95480b1b28ea6fc1bb5c78d99472df624cfd3fce47Bill Wendling StackProtectReq, ///< Stack protection required. 96114baee1fa017daefad2339c77b45b9ca3d79a41Bill Wendling StackProtectStrong, ///< Strong Stack protection. 97480b1b28ea6fc1bb5c78d99472df624cfd3fce47Bill Wendling StructRet, ///< Hidden pointer to structure to return 98480b1b28ea6fc1bb5c78d99472df624cfd3fce47Bill Wendling UWTable, ///< Function must be in a unwind table 990319888773b36dd61d7d2283cb9a26cac1e5abe8Bill Wendling ZExt, ///< Zero extended before/after call 1000319888773b36dd61d7d2283cb9a26cac1e5abe8Bill Wendling 1013a4779a9211281a1d0c27c97037342329035a185NAKAMURA Takumi EndAttrKinds, ///< Sentinal value useful for loops 1023a4779a9211281a1d0c27c97037342329035a185NAKAMURA Takumi 1036f78fbbc630d2b86fb752574f5ad74473f57dfb1Chandler Carruth AttrKindEmptyKey, ///< Empty key value for DenseMapInfo 1046f78fbbc630d2b86fb752574f5ad74473f57dfb1Chandler Carruth AttrKindTombstoneKey ///< Tombstone key value for DenseMapInfo 1056765834754cbb3cb0f15b4b15e98c5e73fa50066Bill Wendling }; 1066765834754cbb3cb0f15b4b15e98c5e73fa50066Bill Wendlingprivate: 10727107f6ab4627fa38bcacad6757ed6d52910f880Bill Wendling AttributeImpl *pImpl; 10827107f6ab4627fa38bcacad6757ed6d52910f880Bill Wendling Attribute(AttributeImpl *A) : pImpl(A) {} 109d426a642a23a234547cbc7061f5bfec157673249Bill Wendlingpublic: 11027107f6ab4627fa38bcacad6757ed6d52910f880Bill Wendling Attribute() : pImpl(0) {} 1112c79ecbd704c656178ffa43d5a58ebe3ca188b40Bill Wendling 112c22f4aa886443507f8406d30d118fdeeac6a8c6cBill Wendling //===--------------------------------------------------------------------===// 113c22f4aa886443507f8406d30d118fdeeac6a8c6cBill Wendling // Attribute Construction 114c22f4aa886443507f8406d30d118fdeeac6a8c6cBill Wendling //===--------------------------------------------------------------------===// 115c22f4aa886443507f8406d30d118fdeeac6a8c6cBill Wendling 116c08a5ef6581f2c7550e92d31f63cd65ec29c39e0Bill Wendling /// \brief Return a uniquified Attribute object. 1178c74ecfbddabe89e150abff4fdff0a27108874b9Bill Wendling static Attribute get(LLVMContext &Context, AttrKind Kind, uint64_t Val = 0); 1188c74ecfbddabe89e150abff4fdff0a27108874b9Bill Wendling static Attribute get(LLVMContext &Context, StringRef Kind, 1198c74ecfbddabe89e150abff4fdff0a27108874b9Bill Wendling StringRef Val = StringRef()); 1202c79ecbd704c656178ffa43d5a58ebe3ca188b40Bill Wendling 121c08a5ef6581f2c7550e92d31f63cd65ec29c39e0Bill Wendling /// \brief Return a uniquified Attribute object that has the specific 122c08a5ef6581f2c7550e92d31f63cd65ec29c39e0Bill Wendling /// alignment set. 123c08a5ef6581f2c7550e92d31f63cd65ec29c39e0Bill Wendling static Attribute getWithAlignment(LLVMContext &Context, uint64_t Align); 124c08a5ef6581f2c7550e92d31f63cd65ec29c39e0Bill Wendling static Attribute getWithStackAlignment(LLVMContext &Context, uint64_t Align); 125c08a5ef6581f2c7550e92d31f63cd65ec29c39e0Bill Wendling 126c22f4aa886443507f8406d30d118fdeeac6a8c6cBill Wendling //===--------------------------------------------------------------------===// 127c22f4aa886443507f8406d30d118fdeeac6a8c6cBill Wendling // Attribute Accessors 128c22f4aa886443507f8406d30d118fdeeac6a8c6cBill Wendling //===--------------------------------------------------------------------===// 129c22f4aa886443507f8406d30d118fdeeac6a8c6cBill Wendling 1308c74ecfbddabe89e150abff4fdff0a27108874b9Bill Wendling /// \brief Return true if the attribute is an Attribute::AttrKind type. 1318c74ecfbddabe89e150abff4fdff0a27108874b9Bill Wendling bool isEnumAttribute() const; 1328c74ecfbddabe89e150abff4fdff0a27108874b9Bill Wendling 1338c74ecfbddabe89e150abff4fdff0a27108874b9Bill Wendling /// \brief Return true if the attribute is an alignment attribute. 1348c74ecfbddabe89e150abff4fdff0a27108874b9Bill Wendling bool isAlignAttribute() const; 1358c74ecfbddabe89e150abff4fdff0a27108874b9Bill Wendling 1368c74ecfbddabe89e150abff4fdff0a27108874b9Bill Wendling /// \brief Return true if the attribute is a string (target-dependent) 1378c74ecfbddabe89e150abff4fdff0a27108874b9Bill Wendling /// attribute. 1388c74ecfbddabe89e150abff4fdff0a27108874b9Bill Wendling bool isStringAttribute() const; 1398c74ecfbddabe89e150abff4fdff0a27108874b9Bill Wendling 140eddab1550ee10cce3bb26a26e88529cb19451aa3NAKAMURA Takumi /// \brief Return true if the attribute is present. 141eddab1550ee10cce3bb26a26e88529cb19451aa3NAKAMURA Takumi bool hasAttribute(AttrKind Val) const; 142eddab1550ee10cce3bb26a26e88529cb19451aa3NAKAMURA Takumi 14364754f499058b5dc748ea6d06a084af0ed539ec4Bill Wendling /// \brief Return true if the target-dependent attribute is present. 14464754f499058b5dc748ea6d06a084af0ed539ec4Bill Wendling bool hasAttribute(StringRef Val) const; 14564754f499058b5dc748ea6d06a084af0ed539ec4Bill Wendling 1468c74ecfbddabe89e150abff4fdff0a27108874b9Bill Wendling /// \brief Return the attribute's kind as an enum (Attribute::AttrKind). This 1478c74ecfbddabe89e150abff4fdff0a27108874b9Bill Wendling /// requires the attribute to be an enum or alignment attribute. 1488c74ecfbddabe89e150abff4fdff0a27108874b9Bill Wendling Attribute::AttrKind getKindAsEnum() const; 1496dc3781d44e56f0addf28b06232a50f3f9e6b1afBill Wendling 1508c74ecfbddabe89e150abff4fdff0a27108874b9Bill Wendling /// \brief Return the attribute's value as an integer. This requires that the 1518c74ecfbddabe89e150abff4fdff0a27108874b9Bill Wendling /// attribute be an alignment attribute. 1528c74ecfbddabe89e150abff4fdff0a27108874b9Bill Wendling uint64_t getValueAsInt() const; 1538c74ecfbddabe89e150abff4fdff0a27108874b9Bill Wendling 1548c74ecfbddabe89e150abff4fdff0a27108874b9Bill Wendling /// \brief Return the attribute's kind as a string. This requires the 1558c74ecfbddabe89e150abff4fdff0a27108874b9Bill Wendling /// attribute to be a string attribute. 1568c74ecfbddabe89e150abff4fdff0a27108874b9Bill Wendling StringRef getKindAsString() const; 1578c74ecfbddabe89e150abff4fdff0a27108874b9Bill Wendling 1588c74ecfbddabe89e150abff4fdff0a27108874b9Bill Wendling /// \brief Return the attribute's value as a string. This requires the 1598c74ecfbddabe89e150abff4fdff0a27108874b9Bill Wendling /// attribute to be a string attribute. 1608c74ecfbddabe89e150abff4fdff0a27108874b9Bill Wendling StringRef getValueAsString() const; 1616dc3781d44e56f0addf28b06232a50f3f9e6b1afBill Wendling 1621d3dcfe4246b4d45fa78a8dfd0a11c7fff842c15Bill Wendling /// \brief Returns the alignment field of an attribute as a byte alignment 163ef99fe8efaa6cb74c66e570a6ef467debca92911Bill Wendling /// value. 164e66f3d3ba0ea9f82f65a29c47fc37e997cbf0aceBill Wendling unsigned getAlignment() const; 165ef99fe8efaa6cb74c66e570a6ef467debca92911Bill Wendling 1661d3dcfe4246b4d45fa78a8dfd0a11c7fff842c15Bill Wendling /// \brief Returns the stack alignment field of an attribute as a byte 167943c29135e03e55f9a5dab393786171a4a536482Bill Wendling /// alignment value. 168e66f3d3ba0ea9f82f65a29c47fc37e997cbf0aceBill Wendling unsigned getStackAlignment() const; 16930b483c94001927b3593ed200e823104bab51660Bill Wendling 170c22f4aa886443507f8406d30d118fdeeac6a8c6cBill Wendling /// \brief The Attribute is converted to a string of equivalent mnemonic. This 171c22f4aa886443507f8406d30d118fdeeac6a8c6cBill Wendling /// is, presumably, for writing out the mnemonics for the assembly writer. 172c22f4aa886443507f8406d30d118fdeeac6a8c6cBill Wendling std::string getAsString() const; 173c22f4aa886443507f8406d30d118fdeeac6a8c6cBill Wendling 1748c74ecfbddabe89e150abff4fdff0a27108874b9Bill Wendling /// \brief Equality and non-equality operators. 1752d5be6c313c0f9e23e56620fa8f8ae8d9b539bf0Bill Wendling bool operator==(Attribute A) const { return pImpl == A.pImpl; } 1762d5be6c313c0f9e23e56620fa8f8ae8d9b539bf0Bill Wendling bool operator!=(Attribute A) const { return pImpl != A.pImpl; } 1772d5be6c313c0f9e23e56620fa8f8ae8d9b539bf0Bill Wendling 178c08a5ef6581f2c7550e92d31f63cd65ec29c39e0Bill Wendling /// \brief Less-than operator. Useful for sorting the attributes list. 1793467e30edf63b6d8a8d446186674ba9e4b7885a9Bill Wendling bool operator<(Attribute A) const; 1803467e30edf63b6d8a8d446186674ba9e4b7885a9Bill Wendling 181bb08593980b16fbd9758da6ca4fa9c7964f2f926Bill Wendling void Profile(FoldingSetNodeID &ID) const { 182bb08593980b16fbd9758da6ca4fa9c7964f2f926Bill Wendling ID.AddPointer(pImpl); 183bb08593980b16fbd9758da6ca4fa9c7964f2f926Bill Wendling } 184827cde1c8319e51463007078a7ce3660ebc93036Duncan Sands}; 185827cde1c8319e51463007078a7ce3660ebc93036Duncan Sands 186e66f3d3ba0ea9f82f65a29c47fc37e997cbf0aceBill Wendling//===----------------------------------------------------------------------===// 18727107f6ab4627fa38bcacad6757ed6d52910f880Bill Wendling/// \class 18827107f6ab4627fa38bcacad6757ed6d52910f880Bill Wendling/// \brief This class manages the ref count for the opaque AttributeSetImpl 18918e7211068c9d2c6204512f9c468ee179818a4b6Bill Wendling/// object and provides accessors for it. 19099faa3b4ec6d03ac7808fe4ff3fbf3d04e375502Bill Wendlingclass AttributeSet { 19107aae2e7d58fe23e370e0cbb9e1a3def99434c36Bill Wendlingpublic: 19207aae2e7d58fe23e370e0cbb9e1a3def99434c36Bill Wendling enum AttrIndex { 19307aae2e7d58fe23e370e0cbb9e1a3def99434c36Bill Wendling ReturnIndex = 0U, 19407aae2e7d58fe23e370e0cbb9e1a3def99434c36Bill Wendling FunctionIndex = ~0U 19507aae2e7d58fe23e370e0cbb9e1a3def99434c36Bill Wendling }; 19607aae2e7d58fe23e370e0cbb9e1a3def99434c36Bill Wendlingprivate: 197a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling friend class AttrBuilder; 1987d38c109aab8654e63e9071c7d948661f6b58433Bill Wendling friend class AttributeSetImpl; 199a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling 20073dee180c836270644dfa7d90f9c5ba877567999Bill Wendling /// \brief The attributes that we are managing. This can be null to represent 2010976e00fd1cbf4128daeb72efd8957d00383fda9Bill Wendling /// the empty attributes list. 202ec2589863b32da169240c4fa120ef1e3798615d4Bill Wendling AttributeSetImpl *pImpl; 2030976e00fd1cbf4128daeb72efd8957d00383fda9Bill Wendling 20473dee180c836270644dfa7d90f9c5ba877567999Bill Wendling /// \brief The attributes for the specified index are returned. 205606c8e36dfdd28fc589356addd3e2cbb89a32e4dBill Wendling AttributeSetNode *getAttributes(unsigned Idx) const; 2060976e00fd1cbf4128daeb72efd8957d00383fda9Bill Wendling 20787e10dfefa94f77937c37b0eb51095540d675cbcBill Wendling /// \brief Create an AttributeSet with the specified parameters in it. 20887e10dfefa94f77937c37b0eb51095540d675cbcBill Wendling static AttributeSet get(LLVMContext &C, 2096bdbf061c353295669b6bfc271b948158602d1bcBill Wendling ArrayRef<std::pair<unsigned, Attribute> > Attrs); 21087e10dfefa94f77937c37b0eb51095540d675cbcBill Wendling static AttributeSet get(LLVMContext &C, 2116bdbf061c353295669b6bfc271b948158602d1bcBill Wendling ArrayRef<std::pair<unsigned, 21287e10dfefa94f77937c37b0eb51095540d675cbcBill Wendling AttributeSetNode*> > Attrs); 21387e10dfefa94f77937c37b0eb51095540d675cbcBill Wendling 21487e10dfefa94f77937c37b0eb51095540d675cbcBill Wendling static AttributeSet getImpl(LLVMContext &C, 2156bdbf061c353295669b6bfc271b948158602d1bcBill Wendling ArrayRef<std::pair<unsigned, 21687e10dfefa94f77937c37b0eb51095540d675cbcBill Wendling AttributeSetNode*> > Attrs); 21787e10dfefa94f77937c37b0eb51095540d675cbcBill Wendling 2187d38c109aab8654e63e9071c7d948661f6b58433Bill Wendling 219ec2589863b32da169240c4fa120ef1e3798615d4Bill Wendling explicit AttributeSet(AttributeSetImpl *LI) : pImpl(LI) {} 22058d74910c6b82e622ecbb57d6644d48fec5a5c0fChris Lattnerpublic: 221ec2589863b32da169240c4fa120ef1e3798615d4Bill Wendling AttributeSet() : pImpl(0) {} 222ec2589863b32da169240c4fa120ef1e3798615d4Bill Wendling AttributeSet(const AttributeSet &P) : pImpl(P.pImpl) {} 223d05204aea4977eaec25e96bc7605a7bb9d806fc0Bill Wendling const AttributeSet &operator=(const AttributeSet &RHS) { 224d05204aea4977eaec25e96bc7605a7bb9d806fc0Bill Wendling pImpl = RHS.pImpl; 225d05204aea4977eaec25e96bc7605a7bb9d806fc0Bill Wendling return *this; 226d05204aea4977eaec25e96bc7605a7bb9d806fc0Bill Wendling } 227710632d07b13609444626367bebd34c0af3acb6aMikhail Glushenkov 22858d74910c6b82e622ecbb57d6644d48fec5a5c0fChris Lattner //===--------------------------------------------------------------------===// 229c22f4aa886443507f8406d30d118fdeeac6a8c6cBill Wendling // AttributeSet Construction and Mutation 23058d74910c6b82e622ecbb57d6644d48fec5a5c0fChris Lattner //===--------------------------------------------------------------------===// 231710632d07b13609444626367bebd34c0af3acb6aMikhail Glushenkov 23218e7211068c9d2c6204512f9c468ee179818a4b6Bill Wendling /// \brief Return an AttributeSet with the specified parameters in it. 2338e47daf2858e980210f3e1f007036b24da342c29Bill Wendling static AttributeSet get(LLVMContext &C, ArrayRef<AttributeSet> Attrs); 23428d65722d6f283b327b5815914382077fe9c0ab4Bill Wendling static AttributeSet get(LLVMContext &C, unsigned Idx, 23532a57958226e369f964a034da2ce7083a1a34297Bill Wendling ArrayRef<Attribute::AttrKind> Kind); 2361bbd644301ed4d8a7efd4ceb15f71c56fa914f28Bill Wendling static AttributeSet get(LLVMContext &C, unsigned Idx, AttrBuilder &B); 23758d74910c6b82e622ecbb57d6644d48fec5a5c0fChris Lattner 238defaca00b8087d452df2b783250a48a32658a910Bill Wendling /// \brief Add an attribute to the attribute set at the given index. Since 239defaca00b8087d452df2b783250a48a32658a910Bill Wendling /// attribute sets are immutable, this returns a new set. 240defaca00b8087d452df2b783250a48a32658a910Bill Wendling AttributeSet addAttribute(LLVMContext &C, unsigned Idx, 241defaca00b8087d452df2b783250a48a32658a910Bill Wendling Attribute::AttrKind Attr) const; 242710632d07b13609444626367bebd34c0af3acb6aMikhail Glushenkov 243e4e85f17564c28cd571dda30146c3f310521acf0Bill Wendling /// \brief Add attributes to the attribute set at the given index. Since 244e4e85f17564c28cd571dda30146c3f310521acf0Bill Wendling /// attribute sets are immutable, this returns a new set. 245e4e85f17564c28cd571dda30146c3f310521acf0Bill Wendling AttributeSet addAttributes(LLVMContext &C, unsigned Idx, 246e4e85f17564c28cd571dda30146c3f310521acf0Bill Wendling AttributeSet Attrs) const; 247e4e85f17564c28cd571dda30146c3f310521acf0Bill Wendling 24818e7211068c9d2c6204512f9c468ee179818a4b6Bill Wendling /// \brief Remove the specified attribute at the specified index from this 2498246df61f6de716acf1f8c64fac3c19970a2c174Bill Wendling /// attribute list. Since attribute lists are immutable, this returns the new 25018e7211068c9d2c6204512f9c468ee179818a4b6Bill Wendling /// list. 2518246df61f6de716acf1f8c64fac3c19970a2c174Bill Wendling AttributeSet removeAttribute(LLVMContext &C, unsigned Idx, 2528246df61f6de716acf1f8c64fac3c19970a2c174Bill Wendling Attribute::AttrKind Attr) const; 2538246df61f6de716acf1f8c64fac3c19970a2c174Bill Wendling 2548246df61f6de716acf1f8c64fac3c19970a2c174Bill Wendling /// \brief Remove the specified attributes at the specified index from this 2558246df61f6de716acf1f8c64fac3c19970a2c174Bill Wendling /// attribute list. Since attribute lists are immutable, this returns the new 2568246df61f6de716acf1f8c64fac3c19970a2c174Bill Wendling /// list. 2578246df61f6de716acf1f8c64fac3c19970a2c174Bill Wendling AttributeSet removeAttributes(LLVMContext &C, unsigned Idx, 2588246df61f6de716acf1f8c64fac3c19970a2c174Bill Wendling AttributeSet Attrs) const; 259710632d07b13609444626367bebd34c0af3acb6aMikhail Glushenkov 26058d74910c6b82e622ecbb57d6644d48fec5a5c0fChris Lattner //===--------------------------------------------------------------------===// 261c22f4aa886443507f8406d30d118fdeeac6a8c6cBill Wendling // AttributeSet Accessors 26258d74910c6b82e622ecbb57d6644d48fec5a5c0fChris Lattner //===--------------------------------------------------------------------===// 26318e7211068c9d2c6204512f9c468ee179818a4b6Bill Wendling 26418e7211068c9d2c6204512f9c468ee179818a4b6Bill Wendling /// \brief The attributes for the specified index are returned. 26528d65722d6f283b327b5815914382077fe9c0ab4Bill Wendling AttributeSet getParamAttributes(unsigned Idx) const; 26619c874638d9478a5d5028854817a5ee72293bb2bDevang Patel 26718e7211068c9d2c6204512f9c468ee179818a4b6Bill Wendling /// \brief The attributes for the ret value are returned. 2683fc4b96b503fa202411317684a2ba02e41e43072Bill Wendling AttributeSet getRetAttributes() const; 26919c874638d9478a5d5028854817a5ee72293bb2bDevang Patel 27018e7211068c9d2c6204512f9c468ee179818a4b6Bill Wendling /// \brief The function attributes are returned. 271c5f1bc88a2eb7ad9ff924ca90cf88494e5f947b9Bill Wendling AttributeSet getFnAttributes() const; 272710632d07b13609444626367bebd34c0af3acb6aMikhail Glushenkov 273831737d329a727f53a1fb0572f7b7a8127208881Bill Wendling /// \brief Return true if the attribute exists at the given index. 27419d815c04fde6b7b53c2b542813157edfa213842Bill Wendling bool hasAttribute(unsigned Index, Attribute::AttrKind Kind) const; 275831737d329a727f53a1fb0572f7b7a8127208881Bill Wendling 276831737d329a727f53a1fb0572f7b7a8127208881Bill Wendling /// \brief Return true if attribute exists at the given index. 27719d815c04fde6b7b53c2b542813157edfa213842Bill Wendling bool hasAttributes(unsigned Index) const; 278831737d329a727f53a1fb0572f7b7a8127208881Bill Wendling 279c22f4aa886443507f8406d30d118fdeeac6a8c6cBill Wendling /// \brief Return true if the specified attribute is set for at least one 280c22f4aa886443507f8406d30d118fdeeac6a8c6cBill Wendling /// parameter or for the return value. 281c22f4aa886443507f8406d30d118fdeeac6a8c6cBill Wendling bool hasAttrSomewhere(Attribute::AttrKind Attr) const; 282c22f4aa886443507f8406d30d118fdeeac6a8c6cBill Wendling 28349f6060f16aec4024d644a6ec4ddd3de9b3e8821Bill Wendling /// \brief Return the alignment for the specified function parameter. 28419d815c04fde6b7b53c2b542813157edfa213842Bill Wendling unsigned getParamAlignment(unsigned Idx) const; 2858e47daf2858e980210f3e1f007036b24da342c29Bill Wendling 286831737d329a727f53a1fb0572f7b7a8127208881Bill Wendling /// \brief Get the stack alignment. 28719d815c04fde6b7b53c2b542813157edfa213842Bill Wendling unsigned getStackAlignment(unsigned Index) const; 288831737d329a727f53a1fb0572f7b7a8127208881Bill Wendling 289831737d329a727f53a1fb0572f7b7a8127208881Bill Wendling /// \brief Return the attributes at the index as a string. 29019d815c04fde6b7b53c2b542813157edfa213842Bill Wendling std::string getAsString(unsigned Index) const; 291831737d329a727f53a1fb0572f7b7a8127208881Bill Wendling 29216c4b3cf2943ae2327752cf3de39769d14cfceceBill Wendling typedef ArrayRef<Attribute>::iterator iterator; 29316c4b3cf2943ae2327752cf3de39769d14cfceceBill Wendling 294f715dbd263149efeb9c684dfdb0637cf84f94399Bill Wendling iterator begin(unsigned Idx) const; 295f715dbd263149efeb9c684dfdb0637cf84f94399Bill Wendling iterator end(unsigned Idx) const; 29616c4b3cf2943ae2327752cf3de39769d14cfceceBill Wendling 297041221c0972ff575b07f76808c504833d629ae1fChris Lattner /// operator==/!= - Provide equality predicates. 29818e7211068c9d2c6204512f9c468ee179818a4b6Bill Wendling bool operator==(const AttributeSet &RHS) const { 299ec2589863b32da169240c4fa120ef1e3798615d4Bill Wendling return pImpl == RHS.pImpl; 30018e7211068c9d2c6204512f9c468ee179818a4b6Bill Wendling } 30118e7211068c9d2c6204512f9c468ee179818a4b6Bill Wendling bool operator!=(const AttributeSet &RHS) const { 302ec2589863b32da169240c4fa120ef1e3798615d4Bill Wendling return pImpl != RHS.pImpl; 30318e7211068c9d2c6204512f9c468ee179818a4b6Bill Wendling } 304710632d07b13609444626367bebd34c0af3acb6aMikhail Glushenkov 30558d74910c6b82e622ecbb57d6644d48fec5a5c0fChris Lattner //===--------------------------------------------------------------------===// 306c22f4aa886443507f8406d30d118fdeeac6a8c6cBill Wendling // AttributeSet Introspection 30758d74910c6b82e622ecbb57d6644d48fec5a5c0fChris Lattner //===--------------------------------------------------------------------===// 308710632d07b13609444626367bebd34c0af3acb6aMikhail Glushenkov 309c22f4aa886443507f8406d30d118fdeeac6a8c6cBill Wendling // FIXME: Remove this. 310c22f4aa886443507f8406d30d118fdeeac6a8c6cBill Wendling uint64_t Raw(unsigned Index) const; 311c22f4aa886443507f8406d30d118fdeeac6a8c6cBill Wendling 31218e7211068c9d2c6204512f9c468ee179818a4b6Bill Wendling /// \brief Return a raw pointer that uniquely identifies this attribute list. 31358d74910c6b82e622ecbb57d6644d48fec5a5c0fChris Lattner void *getRawPointer() const { 314ec2589863b32da169240c4fa120ef1e3798615d4Bill Wendling return pImpl; 31558d74910c6b82e622ecbb57d6644d48fec5a5c0fChris Lattner } 316710632d07b13609444626367bebd34c0af3acb6aMikhail Glushenkov 31718e7211068c9d2c6204512f9c468ee179818a4b6Bill Wendling /// \brief Return true if there are no attributes. 31858d74910c6b82e622ecbb57d6644d48fec5a5c0fChris Lattner bool isEmpty() const { 319aa57893e84ba7a35948fcaa99812ba88e58f4797Bill Wendling return getNumSlots() == 0; 32058d74910c6b82e622ecbb57d6644d48fec5a5c0fChris Lattner } 321710632d07b13609444626367bebd34c0af3acb6aMikhail Glushenkov 32218e7211068c9d2c6204512f9c468ee179818a4b6Bill Wendling /// \brief Return the number of slots used in this attribute list. This is 32318e7211068c9d2c6204512f9c468ee179818a4b6Bill Wendling /// the number of arguments that have an attribute set on them (including the 32418e7211068c9d2c6204512f9c468ee179818a4b6Bill Wendling /// function itself). 32558d74910c6b82e622ecbb57d6644d48fec5a5c0fChris Lattner unsigned getNumSlots() const; 326710632d07b13609444626367bebd34c0af3acb6aMikhail Glushenkov 327e1f95db4803a48a30fc2a1d5868281a87a36fb85Bill Wendling /// \brief Return the index for the given slot. 3283e3e789aede6ec38d39c95d88ad4e8634d5a259bBill Wendling uint64_t getSlotIndex(unsigned Slot) const; 329e1f95db4803a48a30fc2a1d5868281a87a36fb85Bill Wendling 3308e47daf2858e980210f3e1f007036b24da342c29Bill Wendling /// \brief Return the attributes at the given slot. 3318e47daf2858e980210f3e1f007036b24da342c29Bill Wendling AttributeSet getSlotAttributes(unsigned Slot) const; 3328e47daf2858e980210f3e1f007036b24da342c29Bill Wendling 333f3d1500ab2c7364d3d0fb73a7e1b8c6339ab48b1Bill Wendling void dump() const; 33458d74910c6b82e622ecbb57d6644d48fec5a5c0fChris Lattner}; 3354f859aa532dbf061736f9c23e0d0882b5cdfe566Reid Spencer 336a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling//===----------------------------------------------------------------------===// 337a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling/// \class 338c22f4aa886443507f8406d30d118fdeeac6a8c6cBill Wendling/// \brief Provide DenseMapInfo for Attribute::AttrKinds. This is used by 339c22f4aa886443507f8406d30d118fdeeac6a8c6cBill Wendling/// AttrBuilder. 340c22f4aa886443507f8406d30d118fdeeac6a8c6cBill Wendlingtemplate<> struct DenseMapInfo<Attribute::AttrKind> { 341c22f4aa886443507f8406d30d118fdeeac6a8c6cBill Wendling static inline Attribute::AttrKind getEmptyKey() { 342c22f4aa886443507f8406d30d118fdeeac6a8c6cBill Wendling return Attribute::AttrKindEmptyKey; 343c22f4aa886443507f8406d30d118fdeeac6a8c6cBill Wendling } 344c22f4aa886443507f8406d30d118fdeeac6a8c6cBill Wendling static inline Attribute::AttrKind getTombstoneKey() { 345c22f4aa886443507f8406d30d118fdeeac6a8c6cBill Wendling return Attribute::AttrKindTombstoneKey; 346c22f4aa886443507f8406d30d118fdeeac6a8c6cBill Wendling } 347c22f4aa886443507f8406d30d118fdeeac6a8c6cBill Wendling static unsigned getHashValue(const Attribute::AttrKind &Val) { 348c22f4aa886443507f8406d30d118fdeeac6a8c6cBill Wendling return Val * 37U; 349c22f4aa886443507f8406d30d118fdeeac6a8c6cBill Wendling } 350c22f4aa886443507f8406d30d118fdeeac6a8c6cBill Wendling static bool isEqual(const Attribute::AttrKind &LHS, 351c22f4aa886443507f8406d30d118fdeeac6a8c6cBill Wendling const Attribute::AttrKind &RHS) { 352c22f4aa886443507f8406d30d118fdeeac6a8c6cBill Wendling return LHS == RHS; 353c22f4aa886443507f8406d30d118fdeeac6a8c6cBill Wendling } 354c22f4aa886443507f8406d30d118fdeeac6a8c6cBill Wendling}; 355c22f4aa886443507f8406d30d118fdeeac6a8c6cBill Wendling 356c22f4aa886443507f8406d30d118fdeeac6a8c6cBill Wendling//===----------------------------------------------------------------------===// 357c22f4aa886443507f8406d30d118fdeeac6a8c6cBill Wendling/// \class 358a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling/// \brief This class is used in conjunction with the Attribute::get method to 359a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling/// create an Attribute object. The object itself is uniquified. The Builder's 360a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling/// value, however, is not. So this can be used as a quick way to test for 361a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling/// equality, presence of attributes, etc. 362a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendlingclass AttrBuilder { 363a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling DenseSet<Attribute::AttrKind> Attrs; 364ea59f896a672c2e1ef9f02277bce60257aa60989Bill Wendling std::map<std::string, std::string> TargetDepAttrs; 365a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling uint64_t Alignment; 366a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling uint64_t StackAlignment; 367a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendlingpublic: 368a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling AttrBuilder() : Alignment(0), StackAlignment(0) {} 369f9271ea159b97e2febedcf095c3c4122cb24d077Bill Wendling explicit AttrBuilder(uint64_t Val) : Alignment(0), StackAlignment(0) { 370f9271ea159b97e2febedcf095c3c4122cb24d077Bill Wendling addRawValue(Val); 371a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling } 372a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling AttrBuilder(const Attribute &A) : Alignment(0), StackAlignment(0) { 37339da078977ae98b6bf1c3c76a472ed24f5f2a2d2Bill Wendling addAttribute(A); 374a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling } 375a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling AttrBuilder(AttributeSet AS, unsigned Idx); 37685df6b43403d3ebf5d80023a85699c6fb254941aBill Wendling AttrBuilder(const AttrBuilder &B) 37785df6b43403d3ebf5d80023a85699c6fb254941aBill Wendling : Attrs(B.Attrs), 37885df6b43403d3ebf5d80023a85699c6fb254941aBill Wendling TargetDepAttrs(B.TargetDepAttrs.begin(), B.TargetDepAttrs.end()), 37985df6b43403d3ebf5d80023a85699c6fb254941aBill Wendling Alignment(B.Alignment), StackAlignment(B.StackAlignment) {} 380a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling 381a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling void clear(); 382a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling 383a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling /// \brief Add an attribute to the builder. 384a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling AttrBuilder &addAttribute(Attribute::AttrKind Val); 385a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling 38639da078977ae98b6bf1c3c76a472ed24f5f2a2d2Bill Wendling /// \brief Add the Attribute object to the builder. 38739da078977ae98b6bf1c3c76a472ed24f5f2a2d2Bill Wendling AttrBuilder &addAttribute(Attribute A); 38839da078977ae98b6bf1c3c76a472ed24f5f2a2d2Bill Wendling 389ea59f896a672c2e1ef9f02277bce60257aa60989Bill Wendling /// \brief Add the target-dependent attribute to the builder. 390ea59f896a672c2e1ef9f02277bce60257aa60989Bill Wendling AttrBuilder &addAttribute(StringRef A, StringRef V); 391ea59f896a672c2e1ef9f02277bce60257aa60989Bill Wendling 392a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling /// \brief Remove an attribute from the builder. 393a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling AttrBuilder &removeAttribute(Attribute::AttrKind Val); 394a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling 39549f6060f16aec4024d644a6ec4ddd3de9b3e8821Bill Wendling /// \brief Remove the attributes from the builder. 396e74365462a39529ae48ef4d34ec76b4543b8ea29Bill Wendling AttrBuilder &removeAttributes(AttributeSet A, uint64_t Index); 397a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling 398ea59f896a672c2e1ef9f02277bce60257aa60989Bill Wendling /// \brief Remove the target-dependent attribute to the builder. 399ea59f896a672c2e1ef9f02277bce60257aa60989Bill Wendling AttrBuilder &removeAttribute(StringRef A); 400ea59f896a672c2e1ef9f02277bce60257aa60989Bill Wendling 40185df6b43403d3ebf5d80023a85699c6fb254941aBill Wendling /// \brief Add the attributes from the builder. 40285df6b43403d3ebf5d80023a85699c6fb254941aBill Wendling AttrBuilder &merge(const AttrBuilder &B); 40385df6b43403d3ebf5d80023a85699c6fb254941aBill Wendling 404a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling /// \brief Return true if the builder has the specified attribute. 405a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling bool contains(Attribute::AttrKind A) const; 406a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling 407a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling /// \brief Return true if the builder has IR-level attributes. 408a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling bool hasAttributes() const; 409a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling 410a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling /// \brief Return true if the builder has any attribute that's in the 411a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling /// specified attribute. 412e74365462a39529ae48ef4d34ec76b4543b8ea29Bill Wendling bool hasAttributes(AttributeSet A, uint64_t Index) const; 413a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling 414a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling /// \brief Return true if the builder has an alignment attribute. 415a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling bool hasAlignmentAttr() const; 416a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling 417a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling /// \brief Retrieve the alignment attribute, if it exists. 418a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling uint64_t getAlignment() const { return Alignment; } 419a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling 420a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling /// \brief Retrieve the stack alignment attribute, if it exists. 421a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling uint64_t getStackAlignment() const { return StackAlignment; } 422a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling 423a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling /// \brief This turns an int alignment (which must be a power of 2) into the 424a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling /// form used internally in Attribute. 425a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling AttrBuilder &addAlignmentAttr(unsigned Align); 426a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling 427a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling /// \brief This turns an int stack alignment (which must be a power of 2) into 428a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling /// the form used internally in Attribute. 429a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling AttrBuilder &addStackAlignmentAttr(unsigned Align); 430a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling 43164754f499058b5dc748ea6d06a084af0ed539ec4Bill Wendling // Iterators for target-independent attributes. 432a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling typedef DenseSet<Attribute::AttrKind>::iterator iterator; 433a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling typedef DenseSet<Attribute::AttrKind>::const_iterator const_iterator; 434a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling 435c22f4aa886443507f8406d30d118fdeeac6a8c6cBill Wendling iterator begin() { return Attrs.begin(); } 436c22f4aa886443507f8406d30d118fdeeac6a8c6cBill Wendling iterator end() { return Attrs.end(); } 437817abdd8b055059e5930a15704b9f52da4236456Bill Wendling 438a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling const_iterator begin() const { return Attrs.begin(); } 439a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling const_iterator end() const { return Attrs.end(); } 440a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling 44164754f499058b5dc748ea6d06a084af0ed539ec4Bill Wendling // Iterators for target-dependent attributes. 44264754f499058b5dc748ea6d06a084af0ed539ec4Bill Wendling typedef std::pair<std::string, std::string> td_type; 44364754f499058b5dc748ea6d06a084af0ed539ec4Bill Wendling typedef std::map<std::string, std::string>::iterator td_iterator; 44464754f499058b5dc748ea6d06a084af0ed539ec4Bill Wendling typedef std::map<std::string, std::string>::const_iterator td_const_iterator; 44564754f499058b5dc748ea6d06a084af0ed539ec4Bill Wendling 44664754f499058b5dc748ea6d06a084af0ed539ec4Bill Wendling td_iterator td_begin() { return TargetDepAttrs.begin(); } 44764754f499058b5dc748ea6d06a084af0ed539ec4Bill Wendling td_iterator td_end() { return TargetDepAttrs.end(); } 44864754f499058b5dc748ea6d06a084af0ed539ec4Bill Wendling 44964754f499058b5dc748ea6d06a084af0ed539ec4Bill Wendling td_const_iterator td_begin() const { return TargetDepAttrs.begin(); } 45064754f499058b5dc748ea6d06a084af0ed539ec4Bill Wendling td_const_iterator td_end() const { return TargetDepAttrs.end(); } 45164754f499058b5dc748ea6d06a084af0ed539ec4Bill Wendling 452a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling /// \brief Remove attributes that are used on functions only. 453a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling void removeFunctionOnlyAttrs() { 454a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling removeAttribute(Attribute::NoReturn) 455a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling .removeAttribute(Attribute::NoUnwind) 456a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling .removeAttribute(Attribute::ReadNone) 457a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling .removeAttribute(Attribute::ReadOnly) 458a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling .removeAttribute(Attribute::NoInline) 459a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling .removeAttribute(Attribute::AlwaysInline) 460a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling .removeAttribute(Attribute::OptimizeForSize) 461a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling .removeAttribute(Attribute::StackProtect) 462a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling .removeAttribute(Attribute::StackProtectReq) 463114baee1fa017daefad2339c77b45b9ca3d79a41Bill Wendling .removeAttribute(Attribute::StackProtectStrong) 464a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling .removeAttribute(Attribute::NoRedZone) 465a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling .removeAttribute(Attribute::NoImplicitFloat) 466a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling .removeAttribute(Attribute::Naked) 467a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling .removeAttribute(Attribute::InlineHint) 468a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling .removeAttribute(Attribute::StackAlignment) 469a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling .removeAttribute(Attribute::UWTable) 470a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling .removeAttribute(Attribute::NonLazyBind) 471a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling .removeAttribute(Attribute::ReturnsTwice) 472a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling .removeAttribute(Attribute::AddressSafety) 473a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling .removeAttribute(Attribute::MinSize) 474a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling .removeAttribute(Attribute::NoDuplicate); 475a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling } 476a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling 477a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling bool operator==(const AttrBuilder &B); 478a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling bool operator!=(const AttrBuilder &B) { 479a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling return !(*this == B); 480a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling } 481c22f4aa886443507f8406d30d118fdeeac6a8c6cBill Wendling 482f9271ea159b97e2febedcf095c3c4122cb24d077Bill Wendling // FIXME: Remove this in 4.0. 483c22f4aa886443507f8406d30d118fdeeac6a8c6cBill Wendling 484c22f4aa886443507f8406d30d118fdeeac6a8c6cBill Wendling /// \brief Add the raw value to the internal representation. 485c22f4aa886443507f8406d30d118fdeeac6a8c6cBill Wendling AttrBuilder &addRawValue(uint64_t Val); 486a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling}; 487a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling 4888e47daf2858e980210f3e1f007036b24da342c29Bill Wendlingnamespace AttributeFuncs { 4898e47daf2858e980210f3e1f007036b24da342c29Bill Wendling 4908e47daf2858e980210f3e1f007036b24da342c29Bill Wendling/// \brief Which attributes cannot be applied to a type. 491e74365462a39529ae48ef4d34ec76b4543b8ea29Bill WendlingAttributeSet typeIncompatible(Type *Ty, uint64_t Index); 4928e47daf2858e980210f3e1f007036b24da342c29Bill Wendling 4938e47daf2858e980210f3e1f007036b24da342c29Bill Wendling} // end AttributeFuncs namespace 4948e47daf2858e980210f3e1f007036b24da342c29Bill Wendling 49527107f6ab4627fa38bcacad6757ed6d52910f880Bill Wendling} // end llvm namespace 4966091ebd172a16a10f1ea66061a5fa7cbf5139e56Reid Spencer 4976091ebd172a16a10f1ea66061a5fa7cbf5139e56Reid Spencer#endif 498